hm60x: Fix white screen bug.
[maemo-rb.git] / firmware / target / arm / rk27xx / lcd-hifiman.c
blob58f957b61303f906b9e019e54ba7a5debef45e6d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2011 Andrew Ryabinin
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
24 #include "config.h"
25 #include "kernel.h"
26 #include "lcd.h"
27 #include "system.h"
28 #include "cpu.h"
29 #include "lcdif-rk27xx.h"
31 static bool display_on = false;
33 static void reset_lcd(void)
35 GPIO_PCCON |= (1<<7);
36 GPIO_PCDR &= ~(1<<7);
37 udelay(10);
38 GPIO_PCDR |= (1<<7);
39 udelay(5000);
42 void lcd_v1_display_init(void)
44 unsigned int x, y;
46 /* Driving ability setting */
47 lcd_write_reg(0x60, 0x00);
48 lcd_write_reg(0x61, 0x06);
49 lcd_write_reg(0x62, 0x00);
50 lcd_write_reg(0x63, 0xC8);
52 /* Gamma 2.2 Setting */
53 lcd_write_reg(0x40, 0x00);
54 lcd_write_reg(0x41, 0x40);
55 lcd_write_reg(0x42, 0x45);
56 lcd_write_reg(0x43, 0x01);
57 lcd_write_reg(0x44, 0x60);
58 lcd_write_reg(0x45, 0x05);
59 lcd_write_reg(0x46, 0x0C);
60 lcd_write_reg(0x47, 0xD1);
61 lcd_write_reg(0x48, 0x05);
63 lcd_write_reg(0x50, 0x75);
64 lcd_write_reg(0x51, 0x01);
65 lcd_write_reg(0x52, 0x67);
66 lcd_write_reg(0x53, 0x14);
67 lcd_write_reg(0x54, 0xF2);
68 lcd_write_reg(0x55, 0x07);
69 lcd_write_reg(0x56, 0x03);
70 lcd_write_reg(0x57, 0x49);
72 /* Power voltage setting */
73 lcd_write_reg(0x1F, 0x03);
74 lcd_write_reg(0x20, 0x00);
75 lcd_write_reg(0x24, 0x28);
76 lcd_write_reg(0x25, 0x45);
78 lcd_write_reg(0x23, 0x2F);
80 /* Power on setting */
81 lcd_write_reg(0x18, 0x44);
82 lcd_write_reg(0x21, 0x01);
83 lcd_write_reg(0x01, 0x00);
84 lcd_write_reg(0x1C, 0x03);
85 lcd_write_reg(0x19, 0x06);
86 udelay(5);
88 /* Display on setting */
89 lcd_write_reg(0x26, 0x84);
90 udelay(40);
91 lcd_write_reg(0x26, 0xB8);
92 udelay(40);
93 lcd_write_reg(0x26, 0xBC);
94 udelay(40);
96 /* Memmory access setting */
97 lcd_write_reg(0x16, 0x68);
98 /* Setup 16bit mode */
99 lcd_write_reg(0x17, 0x05);
101 /* Set GRAM area */
102 lcd_write_reg(0x02, 0x00);
103 lcd_write_reg(0x03, 0x00);
104 lcd_write_reg(0x04, 0x00);
105 lcd_write_reg(0x05, LCD_WIDTH - 1);
106 lcd_write_reg(0x06, 0x00);
107 lcd_write_reg(0x07, 0x00);
108 lcd_write_reg(0x08, 0x00);
109 lcd_write_reg(0x09, LCD_HEIGHT - 1);
111 /* Start GRAM write */
112 lcd_cmd(0x22);
114 for (x=0; x<LCD_WIDTH; x++)
115 for(y=0; y<LCD_HEIGHT; y++)
116 lcd_data(0x00);
118 display_on = true;
121 static void lcd_v1_enable (bool on)
123 if (on == display_on)
124 return;
126 lcdctrl_bypass(1);
127 LCDC_CTRL |= RGB24B;
129 if (on)
131 lcd_write_reg(0x18, 0x44);
132 lcd_write_reg(0x21, 0x01);
133 lcd_write_reg(0x01, 0x00);
134 lcd_write_reg(0x1C, 0x03);
135 lcd_write_reg(0x19, 0x06);
136 udelay(5);
137 lcd_write_reg(0x26, 0x84);
138 udelay(40);
139 lcd_write_reg(0x26, 0xB8);
140 udelay(40);
141 lcd_write_reg(0x26, 0xBC);
143 else
145 lcd_write_reg(0x26, 0xB8);
146 udelay(40);
147 lcd_write_reg(0x19, 0x01);
148 udelay(40);
149 lcd_write_reg(0x26, 0xA4);
150 udelay(40);
151 lcd_write_reg(0x26, 0x84);
152 udelay(40);
153 lcd_write_reg(0x1C, 0x00);
154 lcd_write_reg(0x01, 0x02);
155 lcd_write_reg(0x21, 0x00);
157 display_on = on;
159 LCDC_CTRL &= ~RGB24B;
161 static void lcd_v1_set_gram_area(int x, int y, int width, int height)
163 lcdctrl_bypass(1);
164 LCDC_CTRL |= RGB24B;
166 lcd_write_reg(0x03, x);
167 lcd_write_reg(0x05, width-1);
168 lcd_write_reg(0x07, y);
169 lcd_write_reg(0x09, height-1);
171 lcd_cmd(0x22);
172 LCDC_CTRL &= ~RGB24B;
175 static void lcd_v1_update_rect(int x, int y, int width, int height)
177 int px = x, py = y;
178 int pxmax = x + width, pymax = y + height;
180 lcd_v1_set_gram_area(x, y, pxmax, pymax);
182 for (py=y; py<pymax; py++)
183 for (px=x; px<pxmax; px++)
184 LCD_DATA = (*FBADDR(px, py));
188 #ifdef HM60X
190 enum lcd_type_t
192 LCD_V1,
193 LCD_v2
194 } lcd_type;
196 static void identify_lcd(void)
198 SCU_IOMUXB_CON &= ~(1<<2);
200 if (GPIO_PCDR & (1<<4))
202 lcd_type = LCD_V1;
204 else
206 lcd_type = LCD_v2;
210 static void lcd_v2_display_init(void)
212 unsigned int x, y;
214 lcd_write_reg(0xD0, 0x0003);
215 lcd_write_reg(0xEB, 0x0B00);
216 lcd_write_reg(0xEC, 0x00CF);
217 lcd_write_reg(0xC7, 0x030F);
219 lcd_write_reg(0x01, 0x001C);
220 lcd_write_reg(0x02, 0x0100);
221 lcd_write_reg(0x03, 0x1038);
222 lcd_write_reg(0x07, 0x0000);
223 lcd_write_reg(0x08, 0x0808);
224 lcd_write_reg(0x0F, 0x0901);
225 lcd_write_reg(0x10, 0x0000);
226 lcd_write_reg(0x11, 0x1B41);
227 lcd_write_reg(0x12, 0x2010);
228 lcd_write_reg(0x13, 0x0009);
229 lcd_write_reg(0x14, 0x4C65);
231 lcd_write_reg(0x30, 0x0000);
232 lcd_write_reg(0x31, 0x00DB);
233 lcd_write_reg(0x32, 0x0000);
234 lcd_write_reg(0x33, 0x0000);
235 lcd_write_reg(0x34, 0x00DB);
236 lcd_write_reg(0x35, 0x0000);
237 lcd_write_reg(0x36, 0x00AF);
238 lcd_write_reg(0x37, 0x0000);
239 lcd_write_reg(0x38, 0x00DB);
240 lcd_write_reg(0x39, 0x0000);
242 lcd_write_reg(0x50, 0x0000);
243 lcd_write_reg(0x51, 0x0705);
244 lcd_write_reg(0x52, 0x0C0A);
245 lcd_write_reg(0x53, 0x0401);
246 lcd_write_reg(0x54, 0x040C);
247 lcd_write_reg(0x55, 0x0608);
248 lcd_write_reg(0x56, 0x0000);
249 lcd_write_reg(0x57, 0x0104);
250 lcd_write_reg(0x58, 0x0E06);
251 lcd_write_reg(0x59, 0x060E);
253 lcd_write_reg(0x20, 0x0000);
254 lcd_write_reg(0x21, 0x0000);
256 lcd_write_reg(0x07, 0x1017);
258 lcd_write_reg(0x20, 0x00AF);
259 lcd_write_reg(0x21, 0x0000);
261 lcd_cmd(0x22);
263 for (x=0; x<LCD_WIDTH; x++)
264 for(y=0; y<LCD_HEIGHT; y++)
265 lcd_data(0x00);
267 display_on = true;
270 static void lcd_v2_enable (bool on)
272 display_on = on;
275 static void lcd_v2_set_gram_area(int x, int y, int width, int height)
277 (void) x;
278 (void) y;
279 (void) width;
280 (void) height;
281 lcdctrl_bypass(1);
282 LCDC_CTRL |= RGB24B;
283 lcd_cmd(0x22);
284 LCDC_CTRL &= ~RGB24B;
287 static void lcd_v2_update_rect(int x, int y, int width, int height)
289 (void) x;
290 (void) y;
291 (void) width;
292 (void) height;
293 lcd_update();
296 void lcd_display_init(void)
298 reset_lcd();
299 identify_lcd();
300 if (lcd_type == LCD_V1)
301 lcd_v1_display_init();
302 else
303 lcd_v2_display_init();
306 void lcd_enable (bool on)
308 if (lcd_type == LCD_V1)
309 lcd_v1_enable(on);
310 else
311 lcd_v2_enable(on);
314 void lcd_set_gram_area(int x, int y, int width, int height)
316 if (lcd_type == LCD_V1)
317 lcd_v1_set_gram_area(x, y, width, height);
318 else
319 lcd_v2_set_gram_area(x, y, width, height);
322 void lcd_update_rect(int x, int y, int width, int height)
324 if (lcd_type == LCD_V1)
325 lcd_v1_update_rect(x, y, width, height);
326 else
327 lcd_v2_update_rect(x, y, width, height);
332 #else /* HM801 */
334 void lcd_display_init(void)
336 reset_lcd();
337 lcd_v1_display_init();
340 void lcd_enable (bool on)
342 lcd_v1_enable(on);
345 void lcd_set_gram_area(int x, int y, int width, int height)
347 lcd_v1_set_gram_area(x, y, width, height);
350 void lcd_update_rect(int x, int y, int width, int height)
352 lcd_v1_update_rect(x, y, width, height);
355 #endif
359 bool lcd_active()
361 return display_on;
364 /* Blit a YUV bitmap directly to the LCD
365 * provided by generic fallback in lcd-16bit-common.c
367 #if 0
368 void lcd_blit_yuv(unsigned char * const src[3],
369 int src_x, int src_y, int stride,
370 int x, int y, int width, int height)
372 (void)src;
373 (void)src_x;
374 (void)src_y;
375 (void)stride;
376 (void)x;
377 (void)y;
378 (void)width;
379 (void)height;
381 #endif