summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/rk27xx/lcd-hifiman.c
blob: 8360a84cff3f0e0ddf4be3f1c7eacfa0ee7349b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C)  2011 Andrew Ryabinin
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/


#include "config.h"
#include "kernel.h"
#include "lcd.h"
#include "system.h"
#include "cpu.h"
#include "lcdif-rk27xx.h"
#include "lcd-target.h"

static bool display_on = false;

static void reset_lcd(void)
{
    GPIO_PCCON |= (1<<7);
    GPIO_PCDR &= ~(1<<7);
    udelay(10);
    GPIO_PCDR |= (1<<7);
    udelay(5000);
}

void lcd_v1_display_init(void)
{
    unsigned int x, y;

    /* Driving ability setting */
    lcd_write_reg(0x60, 0x00);
    lcd_write_reg(0x61, 0x06);
    lcd_write_reg(0x62, 0x00);
    lcd_write_reg(0x63, 0xC8);

    /* Gamma 2.2 Setting */
    lcd_write_reg(0x40, 0x00);
    lcd_write_reg(0x41, 0x40);
    lcd_write_reg(0x42, 0x45);
    lcd_write_reg(0x43, 0x01);
    lcd_write_reg(0x44, 0x60);
    lcd_write_reg(0x45, 0x05);
    lcd_write_reg(0x46, 0x0C);
    lcd_write_reg(0x47, 0xD1);
    lcd_write_reg(0x48, 0x05);

    lcd_write_reg(0x50, 0x75);
    lcd_write_reg(0x51, 0x01);
    lcd_write_reg(0x52, 0x67);
    lcd_write_reg(0x53, 0x14);
    lcd_write_reg(0x54, 0xF2);
    lcd_write_reg(0x55, 0x07);
    lcd_write_reg(0x56, 0x03);
    lcd_write_reg(0x57, 0x49);

    /* Power voltage setting */
    lcd_write_reg(0x1F, 0x03);
    lcd_write_reg(0x20, 0x00);
    lcd_write_reg(0x24, 0x28);
    lcd_write_reg(0x25, 0x45);

    lcd_write_reg(0x23, 0x2F);

    /* Power on setting */
    lcd_write_reg(0x18, 0x44);
    lcd_write_reg(0x21, 0x01);
    lcd_write_reg(0x01, 0x00);
    lcd_write_reg(0x1C, 0x03);
    lcd_write_reg(0x19, 0x06);
    udelay(5);

    /* Display on setting */
    lcd_write_reg(0x26, 0x84);
    udelay(40);
    lcd_write_reg(0x26, 0xB8);
    udelay(40);
    lcd_write_reg(0x26, 0xBC);
    udelay(40);

    /* Memmory access setting */
    lcd_write_reg(0x16, 0x68);
    /* Setup 16bit mode */
    lcd_write_reg(0x17, 0x05);

    /* Set GRAM area */
    lcd_write_reg(0x02, 0x00);
    lcd_write_reg(0x03, 0x00);
    lcd_write_reg(0x04, 0x00);
    lcd_write_reg(0x05, LCD_WIDTH - 1);
    lcd_write_reg(0x06, 0x00);
    lcd_write_reg(0x07, 0x00);
    lcd_write_reg(0x08, 0x00);
    lcd_write_reg(0x09, LCD_HEIGHT - 1);

    /* Start GRAM write */
    lcd_cmd(0x22);

    for (x=0; x<LCD_WIDTH; x++)
        for(y=0; y<LCD_HEIGHT; y++)
            lcd_data(0x00);

    display_on = true;
}

static void lcd_v1_enable (bool on)
{
    if (on == display_on)
        return;

    lcdctrl_bypass(1);
    LCDC_CTRL |= RGB24B;

    if (on)
    {
        lcd_write_reg(0x18, 0x44);
        lcd_write_reg(0x21, 0x01);
        lcd_write_reg(0x01, 0x00);
        lcd_write_reg(0x1C, 0x03);
        lcd_write_reg(0x19, 0x06);
        udelay(5);
        lcd_write_reg(0x26, 0x84);
        udelay(40);
        lcd_write_reg(0x26, 0xB8);
        udelay(40);
        lcd_write_reg(0x26, 0xBC);
    }
    else
    {
        lcd_write_reg(0x26, 0xB8);
        udelay(40);
        lcd_write_reg(0x19, 0x01);
        udelay(40);
        lcd_write_reg(0x26, 0xA4);
        udelay(40);
        lcd_write_reg(0x26, 0x84);
        udelay(40);
        lcd_write_reg(0x1C, 0x00);
        lcd_write_reg(0x01, 0x02);
        lcd_write_reg(0x21, 0x00);
    }
    display_on = on;

    LCDC_CTRL &= ~RGB24B;
}
static void lcd_v1_set_gram_area(int x, int y, int width, int height)
{
    lcdctrl_bypass(1);
    LCDC_CTRL |= RGB24B;
    
    lcd_write_reg(0x03, x);
    lcd_write_reg(0x05, width-1);
    lcd_write_reg(0x07, y);
    lcd_write_reg(0x09, height-1);
    
    lcd_cmd(0x22);
    LCDC_CTRL &= ~RGB24B;
}

static void lcd_v1_update_rect(int x, int y, int width, int height)
{
    int px = x, py = y;
    int pxmax = x + width, pymax = y + height;

    lcd_v1_set_gram_area(x, y, pxmax, pymax);

    for (py=y; py<pymax; py++)
        for (px=x; px<pxmax; px++)     
            LCD_DATA = (*FBADDR(px, py));
}


#ifdef HM60X

enum lcd_type_t lcd_type;

static void identify_lcd(void)
{
    SCU_IOMUXB_CON &= ~(1<<2);

    if (GPIO_PCDR & (1<<4))
    {
        lcd_type = LCD_V1;
    }
    else
    {
        lcd_type = LCD_v2;
    }
}

static void lcd_v2_display_init(void)
{
    unsigned int x, y;

    lcd_write_reg(0xD0, 0x0003);
    lcd_write_reg(0xEB, 0x0B00);
    lcd_write_reg(0xEC, 0x00CF);
    lcd_write_reg(0xC7, 0x030F);

    lcd_write_reg(0x01, 0x001C);
    lcd_write_reg(0x02, 0x0100);
    lcd_write_reg(0x03, 0x1038);
    lcd_write_reg(0x07, 0x0000);
    lcd_write_reg(0x08, 0x0808);
    lcd_write_reg(0x0F, 0x0901);
    lcd_write_reg(0x10, 0x0000);
    lcd_write_reg(0x11, 0x1B41);
    lcd_write_reg(0x12, 0x2010);
    lcd_write_reg(0x13, 0x0009);
    lcd_write_reg(0x14, 0x4C65);

    lcd_write_reg(0x30, 0x0000);
    lcd_write_reg(0x31, 0x00DB);
    lcd_write_reg(0x32, 0x0000);
    lcd_write_reg(0x33, 0x0000);
    lcd_write_reg(0x34, 0x00DB);
    lcd_write_reg(0x35, 0x0000);
    lcd_write_reg(0x36, 0x00AF);
    lcd_write_reg(0x37, 0x0000);
    lcd_write_reg(0x38, 0x00DB);
    lcd_write_reg(0x39, 0x0000);

    lcd_write_reg(0x50, 0x0000);
    lcd_write_reg(0x51, 0x0705);
    lcd_write_reg(0x52, 0x0C0A);
    lcd_write_reg(0x53, 0x0401);
    lcd_write_reg(0x54, 0x040C);
    lcd_write_reg(0x55, 0x0608);
    lcd_write_reg(0x56, 0x0000);
    lcd_write_reg(0x57, 0x0104);
    lcd_write_reg(0x58, 0x0E06);
    lcd_write_reg(0x59, 0x060E);

    lcd_write_reg(0x20, 0x0000);
    lcd_write_reg(0x21, 0x0000);

    lcd_write_reg(0x07, 0x1017);

    lcd_cmd(0x22);

    for (x=0; x<LCD_WIDTH; x++)
        for(y=0; y<LCD_HEIGHT; y++)
            lcd_data(0x00);

    display_on = true;
}

static void lcd_v2_enable (bool on)
{
    display_on = on;
}

static void lcd_v2_set_gram_area(int x, int y, int width, int height)
{
    lcdctrl_bypass(1);
    LCDC_CTRL |= RGB24B;

    lcd_write_reg(0x36, height-1);
    lcd_write_reg(0x37, y);
    lcd_write_reg(0x38, width-1);
    lcd_write_reg(0x39, x);

    /* set GRAM address */
    lcd_write_reg(0x20, y);
    lcd_write_reg(0x21, x);

    lcd_cmd(0x22);
    LCDC_CTRL &= ~RGB24B;
}

static void lcd_v2_update_rect(int x, int y, int width, int height)
{
    int px = x, py = y;
    int pxmax = x + width, pymax = y + height;

    lcd_v2_set_gram_area(x, y, pxmax, pymax);

    for (py=y; py<pymax; py++)
        for (px=x; px<pxmax; px++)
            LCD_DATA = (*FBADDR(px, py));

}

void lcd_display_init(void)
{
    reset_lcd();
    identify_lcd();
    if (lcd_type == LCD_V1)
        lcd_v1_display_init();
    else
        lcd_v2_display_init();
}

void lcd_enable (bool on)
{
    if (lcd_type == LCD_V1)
        lcd_v1_enable(on);
    else
        lcd_v2_enable(on);
}

void lcd_set_gram_area(int x, int y, int width, int height)
{
   if (lcd_type == LCD_V1)
        lcd_v1_set_gram_area(x, y, width, height);
    else
        lcd_v2_set_gram_area(x, y, width, height);
}

void lcd_update_rect(int x, int y, int width, int height)
{
    if (lcd_type == LCD_V1)
        lcd_v1_update_rect(x, y, width, height);
    else
        lcd_v2_update_rect(x, y, width, height);
}



#else /* HM801 */

void lcd_display_init(void)
{
    reset_lcd();
    lcd_v1_display_init();
}

void lcd_enable (bool on)
{
    lcd_v1_enable(on);
}

void lcd_set_gram_area(int x, int y, int width, int height)
{
    lcd_v1_set_gram_area(x, y, width, height);
}

void lcd_update_rect(int x, int y, int width, int height)
{
    lcd_v1_update_rect(x, y, width, height);
}

#endif



bool lcd_active()
{
    return display_on;
}

/* Blit a YUV bitmap directly to the LCD
 * provided by generic fallback in lcd-16bit-common.c
 */
#if 0
void lcd_blit_yuv(unsigned char * const src[3],
                  int src_x, int src_y, int stride,
                  int x, int y, int width, int height)
{
    (void)src;
    (void)src_x;
    (void)src_y;
    (void)stride;
    (void)x;
    (void)y;
    (void)width;
    (void)height;
}
#endif