1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Rob Purchase
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include <sys/types.h> /* off_t */
30 /* GPIO A pins for LCD panel SDI interface */
32 #define LTV250QV_CS (1<<24)
33 #define LTV250QV_SCL (1<<25)
34 #define LTV250QV_SDI (1<<26)
36 /* LCD Controller registers */
38 #define LCDC_CTRL (*(volatile unsigned long *)0xF0000000)
39 #define LCDC_CLKDIV (*(volatile unsigned long *)0xF0000008)
40 #define LCDC_HTIME1 (*(volatile unsigned long *)0xF000000C)
41 #define LCDC_HTIME2 (*(volatile unsigned long *)0xF0000010)
42 #define LCDC_VTIME1 (*(volatile unsigned long *)0xF0000014)
43 #define LCDC_VTIME2 (*(volatile unsigned long *)0xF0000018)
44 #define LCDC_VTIME3 (*(volatile unsigned long *)0xF000001C)
45 #define LCDC_VTIME4 (*(volatile unsigned long *)0xF0000020)
46 #define LCDC_DS (*(volatile unsigned long *)0xF000005C)
47 #define LCDC_I1CTRL (*(volatile unsigned long *)0xF000008C)
48 #define LCDC_I1POS (*(volatile unsigned long *)0xF0000090)
49 #define LCDC_I1SIZE (*(volatile unsigned long *)0xF0000094)
50 #define LCDC_I1BASE (*(volatile unsigned long *)0xF0000098)
51 #define LCDC_I1OFF (*(volatile unsigned long *)0xF00000A8)
52 #define LCDC_I1SCALE (*(volatile unsigned long *)0xF00000AC)
54 /* Power and display status */
55 static bool display_on
= false; /* Is the display turned on? */
57 static unsigned lcd_yuv_options
= 0;
59 /* Framebuffer copy as seen by the hardware */
60 fb_data lcd_driver_framebuffer
[LCD_FBHEIGHT
][LCD_FBWIDTH
];
62 int lcd_default_contrast(void)
67 void lcd_set_contrast(int val
)
69 /* TODO: This won't be implemented until the S6F2002 controller
70 is better understood (nb: registers 16-23 control gamma). */
75 /* LTV250QV panel functions */
77 /* Delay loop based on CPU frequency (FREQ>>23 is 3..22 for 32MHz..192MHz) */
78 static void delay_loop(void)
81 for (x
= (unsigned)(FREQ
>>23); x
; x
--);
83 #define DELAY delay_loop()
85 static void ltv250qv_write(unsigned int command
)
89 GPIOA_CLEAR
= LTV250QV_CS
;
92 for (i
= 23; i
>= 0; i
--)
94 GPIOA_CLEAR
= LTV250QV_SCL
;
98 GPIOA_SET
= LTV250QV_SDI
;
100 GPIOA_CLEAR
= LTV250QV_SDI
;
103 GPIOA_SET
= LTV250QV_SCL
;
107 GPIOA_SET
= LTV250QV_CS
;
110 static void lcd_write_reg(unsigned char reg
, unsigned short val
)
112 int level
= disable_irq_save();
114 ltv250qv_write(0x740000 | reg
);
115 ltv250qv_write(0x760000 | val
);
120 static void lcd_display_on(void)
122 /* power on sequence as per the D2 firmware */
126 lcd_write_reg(1, 0x1D);
127 lcd_write_reg(2, 0x0);
128 lcd_write_reg(3, 0x0);
129 lcd_write_reg(4, 0x0);
130 lcd_write_reg(5, 0x40A3);
131 lcd_write_reg(6, 0x0);
132 lcd_write_reg(7, 0x0);
133 lcd_write_reg(8, 0x0);
134 lcd_write_reg(9, 0x0);
135 lcd_write_reg(10, 0x0);
136 lcd_write_reg(16, 0x0);
137 lcd_write_reg(17, 0x0);
138 lcd_write_reg(18, 0x0);
139 lcd_write_reg(19, 0x0);
140 lcd_write_reg(20, 0x0);
141 lcd_write_reg(21, 0x0);
142 lcd_write_reg(22, 0x0);
143 lcd_write_reg(23, 0x0);
144 lcd_write_reg(24, 0x0);
145 lcd_write_reg(25, 0x0);
148 lcd_write_reg(9, 0x4055);
149 lcd_write_reg(10, 0x0);
152 lcd_write_reg(10, 0x2000);
155 lcd_write_reg(1, 0xC01D);
156 lcd_write_reg(2, 0x204);
157 lcd_write_reg(3, 0xE100);
158 lcd_write_reg(4, 0x1000);
159 lcd_write_reg(5, 0x5033);
160 lcd_write_reg(6, 0x2); /* vertical back porch adjusted from 0x4 in OF */
161 lcd_write_reg(7, 0x30);
162 lcd_write_reg(8, 0x41C);
163 lcd_write_reg(16, 0x207);
164 lcd_write_reg(17, 0x702);
165 lcd_write_reg(18, 0xB05);
166 lcd_write_reg(19, 0xB05);
167 lcd_write_reg(20, 0x707);
168 lcd_write_reg(21, 0x507);
169 lcd_write_reg(22, 0x103);
170 lcd_write_reg(23, 0x406);
171 lcd_write_reg(24, 0x2);
172 lcd_write_reg(25, 0x0);
175 lcd_write_reg(9, 0xA55);
176 lcd_write_reg(10, 0x111F);
179 /* tell that we're on now */
183 static void lcd_display_off(void)
185 /* block drawing operations and changing of first */
188 /* LQV shutdown sequence */
189 lcd_write_reg(9, 0x55);
190 lcd_write_reg(10, 0x1417);
191 lcd_write_reg(5, 0x4003);
194 lcd_write_reg(9, 0x0);
197 /* kill power to LCD panel (unconfirmed) */
198 GPIOA_CLEAR
= (1<<16);
202 void lcd_enable(bool on
)
204 if (on
== display_on
)
210 LCDC_CTRL
|= 1; /* controller enable */
211 lcd_update(); /* Resync display */
212 send_event(LCD_EVENT_ACTIVATION
, NULL
);
216 LCDC_CTRL
&= ~1; /* controller disable */
221 bool lcd_active(void)
226 /* TODO: implement lcd_sleep() and separate out the power on/off functions */
228 void lcd_init_device(void)
230 BCLKCTR
|= 4; /* enable LCD bus clock */
232 /* set PCK_LCD to 108Mhz */
234 PCLK_LCD
= PCK_EN
| (CKSEL_PLL1
<<24) | 1; /* source = PLL1, divided by 2 */
236 /* reset the LCD controller */
240 /* set port configuration */
241 PORTCFG1
&= ~0xC0000000;
245 /* set physical display size */
246 LCDC_DS
= (LCD_HEIGHT
<<16) | LCD_WIDTH
;
248 LCDC_HTIME1
= (0x2d<<16) | 0x3bf;
249 LCDC_HTIME2
= (1<<16) | 1;
250 LCDC_VTIME1
= LCDC_VTIME3
= (0<<16) | 239;
251 LCDC_VTIME2
= LCDC_VTIME4
= (1<<16) | 3;
253 LCDC_I1BASE
= (unsigned int)lcd_driver_framebuffer
;
254 LCDC_I1SIZE
= (LCD_HEIGHT
<<16) | LCD_WIDTH
; /* image 1 size */
255 LCDC_I1POS
= (0<<16) | 0; /* position */
256 LCDC_I1OFF
= 0; /* address offset */
257 LCDC_I1SCALE
= 0; /* scaling */
258 LCDC_I1CTRL
= 5; /* 565bpp (7 = 888bpp) */
259 LCDC_CTRL
&= ~(1<<28);
261 LCDC_CLKDIV
= (LCDC_CLKDIV
&~ 0xFF00FF) | (1<<16) | 2; /* and this means? */
263 /* set and clear various flags - not investigated yet */
264 LCDC_CTRL
&~ 0x090006AA; /* clear bits 1,3,5,7,9,10,24,27 */
265 LCDC_CTRL
|= 0x02800144; /* set bits 2,6,8,25,23 */
266 LCDC_CTRL
= (LCDC_CTRL
&~ 0xF0000) | 0x20000;
267 LCDC_CTRL
= (LCDC_CTRL
&~ 0x700000) | 0x700000;
269 /* enable LCD controller */
272 /* enable LTV250QV panel */
277 /*** Update functions ***/
280 /* Copies a rectangle from one framebuffer to another. Can be used in
281 single transfer mode with width = num pixels, and height = 1 which
282 allows a full-width rectangle to be copied more efficiently. */
283 extern void lcd_copy_buffer_rect(fb_data
*dst
, const fb_data
*src
,
284 int width
, int height
);
286 /* Update the display.
287 This must be called after all other LCD functions that change the display. */
288 void lcd_update(void) ICODE_ATTR
;
289 void lcd_update(void)
294 lcd_copy_buffer_rect(&lcd_driver_framebuffer
[0][0],
295 &lcd_framebuffer
[0][0], LCD_WIDTH
*LCD_HEIGHT
, 1);
298 /* Update a fraction of the display. */
299 void lcd_update_rect(int, int, int, int) ICODE_ATTR
;
300 void lcd_update_rect(int x
, int y
, int width
, int height
)
307 if (x
+ width
> LCD_WIDTH
)
308 width
= LCD_WIDTH
- x
; /* Clip right */
310 width
+= x
, x
= 0; /* Clip left */
312 return; /* nothing left to do */
314 if (y
+ height
> LCD_HEIGHT
)
315 height
= LCD_HEIGHT
- y
; /* Clip bottom */
317 height
+= y
, y
= 0; /* Clip top */
319 return; /* nothing left to do */
321 /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer
322 * and lcd_framebuffer */
323 dst
= &lcd_driver_framebuffer
[y
][x
];
324 src
= &lcd_framebuffer
[y
][x
];
326 /* Copy part of the Rockbox framebuffer to the second framebuffer */
327 if (width
< LCD_WIDTH
)
329 /* Not full width - do line-by-line */
330 lcd_copy_buffer_rect(dst
, src
, width
, height
);
334 /* Full width - copy as one line */
335 lcd_copy_buffer_rect(dst
, src
, LCD_WIDTH
*height
, 1);
339 void lcd_set_flip(bool yesno
)
345 void lcd_set_invert_display(bool yesno
)
351 void lcd_yuv_set_options(unsigned options
)
353 lcd_yuv_options
= options
;
356 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
357 extern void lcd_write_yuv420_lines(fb_data
*dst
,
358 unsigned char const * const src
[3],
362 extern void lcd_write_yuv420_lines_odither(fb_data
*dst
,
363 unsigned char const * const src
[3],
366 int x_screen
, /* To align dither pattern */
369 /* Performance function to blit a YUV bitmap directly to the LCD */
370 void lcd_blit_yuv(unsigned char * const src
[3],
371 int src_x
, int src_y
, int stride
,
372 int x
, int y
, int width
, int height
)
374 unsigned char const * yuv_src
[3];
380 /* Sorry, but width and height must be >= 2 or else */
384 fb_data
*dst
= &lcd_driver_framebuffer
[y
][x
];
387 yuv_src
[0] = src
[0] + z
+ src_x
;
388 yuv_src
[1] = src
[1] + (z
>> 2) + (src_x
>> 1);
389 yuv_src
[2] = src
[2] + (yuv_src
[1] - src
[1]);
391 if (lcd_yuv_options
& LCD_YUV_DITHER
)
395 lcd_write_yuv420_lines_odither(dst
, yuv_src
, width
, stride
, y
, x
);
396 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
397 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
398 yuv_src
[2] += stride
>> 1;
399 dst
+= 2*LCD_FBWIDTH
;
402 while (--height
> 0);
408 lcd_write_yuv420_lines(dst
, yuv_src
, width
, stride
);
409 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
410 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
411 yuv_src
[2] += stride
>> 1;
412 dst
+= 2*LCD_FBWIDTH
;
414 while (--height
> 0);