diff options
Diffstat (limited to 'firmware/target/arm/samsung/yh820/lcd-yh820.c')
-rw-r--r-- | firmware/target/arm/samsung/yh820/lcd-yh820.c | 375 |
1 files changed, 375 insertions, 0 deletions
diff --git a/firmware/target/arm/samsung/yh820/lcd-yh820.c b/firmware/target/arm/samsung/yh820/lcd-yh820.c new file mode 100644 index 0000000000..d21f6c2854 --- /dev/null +++ b/firmware/target/arm/samsung/yh820/lcd-yh820.c | |||
@@ -0,0 +1,375 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2007 by Mark Arigo | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "config.h" | ||
22 | #include "cpu.h" | ||
23 | #include "lcd.h" | ||
24 | #include "kernel.h" | ||
25 | #include "system.h" | ||
26 | |||
27 | /* Display status */ | ||
28 | static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0; | ||
29 | |||
30 | #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP) | ||
31 | static bool is_lcd_enabled = true; | ||
32 | #endif | ||
33 | |||
34 | /* NOTE: the LCD is rotated 90 degrees */ | ||
35 | |||
36 | /* LCD command set for Samsung S6B33B2 */ | ||
37 | |||
38 | #define R_NOP 0x00 | ||
39 | #define R_OSCILLATION_MODE 0x02 | ||
40 | #define R_DRIVER_OUTPUT_MODE 0x10 | ||
41 | #define R_DCDC_SET 0x20 | ||
42 | #define R_BIAS_SET 0x22 | ||
43 | #define R_DCDC_CLOCK_DIV 0x24 | ||
44 | #define R_DCDC_AMP_ONOFF 0x26 | ||
45 | #define R_TEMP_COMPENSATION 0x28 | ||
46 | #define R_CONTRAST_CONTROL1 0x2a | ||
47 | #define R_CONTRAST_CONTROL2 0x2b | ||
48 | #define R_STANDBY_OFF 0x2c | ||
49 | #define R_STANDBY_ON 0x2d | ||
50 | #define R_DDRAM_BURST_OFF 0x2e | ||
51 | #define R_DDRAM_BURST_ON 0x2f | ||
52 | #define R_ADDRESSING_MODE 0x30 | ||
53 | #define R_ROW_VECTOR_MODE 0x32 | ||
54 | #define R_N_LINE_INVERSION 0x34 | ||
55 | #define R_FRAME_FREQ_CONTROL 0x36 | ||
56 | #define R_RED_PALETTE 0x38 | ||
57 | #define R_GREEN_PALETTE 0x3a | ||
58 | #define R_BLUE_PALETTE 0x3c | ||
59 | #define R_ENTRY_MODE 0x40 | ||
60 | #define R_X_ADDR_AREA 0x42 | ||
61 | #define R_Y_ADDR_AREA 0x43 | ||
62 | #define R_RAM_SKIP_AREA 0x45 | ||
63 | #define R_DISPLAY_OFF 0x50 | ||
64 | #define R_DISPLAY_ON 0x51 | ||
65 | #define R_SPEC_DISPLAY_PATTERN 0x53 | ||
66 | #define R_PARTIAL_DISPLAY_MODE 0x55 | ||
67 | #define R_PARTIAL_START_LINE 0x56 | ||
68 | #define R_PARTIAL_END_LINE 0x57 | ||
69 | #define R_AREA_SCROLL_MODE 0x59 | ||
70 | #define R_SCROLL_START_LINE 0x5a | ||
71 | #define R_DATA_FORMAT_SELECT 0x60 | ||
72 | |||
73 | |||
74 | /* wait for LCD */ | ||
75 | static inline void lcd_wait_write(void) | ||
76 | { | ||
77 | while (LCD1_CONTROL & LCD1_BUSY_MASK); | ||
78 | } | ||
79 | |||
80 | /* send LCD data */ | ||
81 | static void lcd_send_data(unsigned data) | ||
82 | { | ||
83 | lcd_wait_write(); | ||
84 | LCD1_DATA = data >> 8; | ||
85 | lcd_wait_write(); | ||
86 | LCD1_DATA = data & 0xff; | ||
87 | } | ||
88 | |||
89 | /* send LCD command */ | ||
90 | static void lcd_send_command(unsigned cmd) | ||
91 | { | ||
92 | lcd_wait_write(); | ||
93 | LCD1_CMD = cmd; | ||
94 | } | ||
95 | |||
96 | /* LCD init */ | ||
97 | void lcd_init_device(void) | ||
98 | { | ||
99 | #if 0 | ||
100 | /* This is the init sequence from the yh820 OF bootloader */ | ||
101 | unsigned long tmp; | ||
102 | |||
103 | DEV_INIT1 &= ~0x3000; | ||
104 | tmp = DEV_INIT1; | ||
105 | DEV_INIT1 = tmp; | ||
106 | DEV_INIT2 &= ~0x400; | ||
107 | |||
108 | LCD1_CONTROL &= ~0x4; | ||
109 | udelay(15); | ||
110 | LCD1_CONTROL |= 0x4; | ||
111 | |||
112 | LCD1_CONTROL = 0x680; | ||
113 | LCD1_CONTROL = 0x684; | ||
114 | |||
115 | LCD1_CONTROL |= 0x1; | ||
116 | udelay(200); | ||
117 | |||
118 | lcd_send_command(R_STANDBY_OFF); | ||
119 | udelay(100000); | ||
120 | |||
121 | lcd_send_command(R_DISPLAY_OFF); | ||
122 | udelay(10000); | ||
123 | |||
124 | lcd_send_command(R_OSCILLATION_MODE); | ||
125 | lcd_send_command(0x01); | ||
126 | udelay(30000); | ||
127 | |||
128 | lcd_send_command(R_DCDC_SET); | ||
129 | lcd_send_command(0x01); | ||
130 | udelay(30000); | ||
131 | |||
132 | lcd_send_command(R_DCDC_AMP_ONOFF); | ||
133 | lcd_send_command(0x01); | ||
134 | udelay(30000); | ||
135 | |||
136 | lcd_send_command(R_DCDC_AMP_ONOFF); | ||
137 | lcd_send_command(0x09); | ||
138 | udelay(30000); | ||
139 | |||
140 | lcd_send_command(R_DCDC_AMP_ONOFF); | ||
141 | lcd_send_command(0x0b); | ||
142 | udelay(30000); | ||
143 | |||
144 | lcd_send_command(R_DCDC_AMP_ONOFF); | ||
145 | lcd_send_command(0x0f); | ||
146 | udelay(30000); | ||
147 | |||
148 | lcd_send_command(R_DCDC_CLOCK_DIV); | ||
149 | lcd_send_command(0x03); | ||
150 | udelay(10000); | ||
151 | |||
152 | lcd_send_command(R_CONTRAST_CONTROL1); | ||
153 | lcd_send_command(0x89); | ||
154 | udelay(10000); | ||
155 | |||
156 | lcd_send_command(R_TEMP_COMPENSATION); | ||
157 | lcd_send_command(0x01); | ||
158 | udelay(10000); | ||
159 | |||
160 | lcd_send_command(R_ADDRESSING_MODE); | ||
161 | lcd_send_command(0x19); | ||
162 | udelay(10000); | ||
163 | |||
164 | lcd_send_command(R_ROW_VECTOR_MODE); | ||
165 | lcd_send_command(0x00); | ||
166 | udelay(10000); | ||
167 | |||
168 | lcd_send_command(R_N_LINE_INVERSION); | ||
169 | lcd_send_command(0x8b); | ||
170 | udelay(10000); | ||
171 | |||
172 | lcd_send_command(R_ENTRY_MODE); | ||
173 | lcd_send_command(0x01); | ||
174 | |||
175 | lcd_send_command(R_DRIVER_OUTPUT_MODE); | ||
176 | lcd_send_command(0x34); | ||
177 | udelay(10000); | ||
178 | |||
179 | lcd_send_command(R_X_ADDR_AREA); /* vertical dimensions */ | ||
180 | lcd_send_command(0x00); /* y1 */ | ||
181 | lcd_send_command(LCD_HEIGHT - 1); /* y2 */ | ||
182 | |||
183 | lcd_send_command(R_Y_ADDR_AREA); /* horizontal dimensions */ | ||
184 | lcd_send_command(0x04); /* x1 + 4 */ | ||
185 | lcd_send_command(LCD_WIDTH - 1 + 4); /* x2 + 4 */ | ||
186 | udelay(100); | ||
187 | |||
188 | lcd_send_command(R_BIAS_SET); | ||
189 | lcd_send_command(0x01); | ||
190 | |||
191 | lcd_send_command(R_DDRAM_BURST_OFF); | ||
192 | udelay(100); | ||
193 | |||
194 | lcd_send_command(R_DISPLAY_ON); | ||
195 | udelay(30000); | ||
196 | #endif | ||
197 | } | ||
198 | |||
199 | /*** hardware configuration ***/ | ||
200 | int lcd_default_contrast(void) | ||
201 | { | ||
202 | return DEFAULT_CONTRAST_SETTING; | ||
203 | } | ||
204 | |||
205 | void lcd_set_contrast(int val) | ||
206 | { | ||
207 | lcd_send_command(R_CONTRAST_CONTROL1); | ||
208 | lcd_send_command(val); | ||
209 | } | ||
210 | |||
211 | void lcd_set_invert_display(bool yesno) | ||
212 | { | ||
213 | /* TODO: Implement lcd_set_invert_display() */ | ||
214 | (void)yesno; | ||
215 | } | ||
216 | |||
217 | #if defined(HAVE_LCD_ENABLE) | ||
218 | void lcd_enable(bool yesno) | ||
219 | { | ||
220 | if (yesno == is_lcd_enabled) | ||
221 | return; | ||
222 | |||
223 | if ((is_lcd_enabled = yesno)) | ||
224 | { | ||
225 | lcd_send_command(R_STANDBY_OFF); | ||
226 | lcd_send_command(R_DISPLAY_ON); | ||
227 | lcd_activation_call_hook(); | ||
228 | } | ||
229 | else | ||
230 | { | ||
231 | lcd_send_command(R_STANDBY_ON); | ||
232 | } | ||
233 | } | ||
234 | #endif | ||
235 | |||
236 | #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP) | ||
237 | bool lcd_active(void) | ||
238 | { | ||
239 | return is_lcd_enabled; | ||
240 | } | ||
241 | #endif | ||
242 | |||
243 | #ifdef HAVE_LCD_FLIP | ||
244 | /* turn the display upside down (call lcd_update() afterwards) */ | ||
245 | /* Note: since the lcd is rotated, this will flip horiz instead of vert */ | ||
246 | void lcd_set_flip(bool yesno) | ||
247 | { | ||
248 | lcd_send_command(R_DRIVER_OUTPUT_MODE); | ||
249 | lcd_send_command(yesno ? 0x30 : 0x34); | ||
250 | } | ||
251 | #endif | ||
252 | |||
253 | |||
254 | /*** update functions ***/ | ||
255 | |||
256 | void lcd_yuv_set_options(unsigned options) | ||
257 | { | ||
258 | lcd_yuv_options = options; | ||
259 | } | ||
260 | |||
261 | /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */ | ||
262 | extern void lcd_write_yuv420_lines(unsigned char const * const src[3], | ||
263 | int width, | ||
264 | int stride); | ||
265 | extern void lcd_write_yuv420_lines_odither(unsigned char const * const src[3], | ||
266 | int width, | ||
267 | int stride, | ||
268 | int x_screen, /* To align dither pattern */ | ||
269 | int y_screen); | ||
270 | /* Performance function to blit a YUV bitmap directly to the LCD */ | ||
271 | void lcd_blit_yuv(unsigned char * const src[3], | ||
272 | int src_x, int src_y, int stride, | ||
273 | int x, int y, int width, int height) | ||
274 | { | ||
275 | unsigned char const * yuv_src[3]; | ||
276 | off_t z; | ||
277 | |||
278 | /* Sorry, but width and height must be >= 2 or else */ | ||
279 | width &= ~1; | ||
280 | height >>= 1; | ||
281 | |||
282 | z = stride*src_y; | ||
283 | yuv_src[0] = src[0] + z + src_x; | ||
284 | yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); | ||
285 | yuv_src[2] = src[2] + (yuv_src[1] - src[1]); | ||
286 | |||
287 | lcd_send_command(R_ENTRY_MODE); | ||
288 | lcd_send_command(0x03); | ||
289 | |||
290 | lcd_send_command(R_Y_ADDR_AREA); | ||
291 | lcd_send_command(x + 4); | ||
292 | lcd_send_command(x + width - 1 + 4); | ||
293 | |||
294 | if (lcd_yuv_options & LCD_YUV_DITHER) | ||
295 | { | ||
296 | do | ||
297 | { | ||
298 | lcd_send_command(R_X_ADDR_AREA); | ||
299 | lcd_send_command(y); | ||
300 | lcd_send_command(y + 1); | ||
301 | |||
302 | lcd_write_yuv420_lines_odither(yuv_src, width, stride, x, y); | ||
303 | yuv_src[0] += stride << 1; /* Skip down two luma lines */ | ||
304 | yuv_src[1] += stride >> 1; /* Skip down one chroma line */ | ||
305 | yuv_src[2] += stride >> 1; | ||
306 | y += 2; | ||
307 | } | ||
308 | while (--height > 0); | ||
309 | } | ||
310 | else | ||
311 | { | ||
312 | do | ||
313 | { | ||
314 | lcd_send_command(R_X_ADDR_AREA); | ||
315 | lcd_send_command(y); | ||
316 | lcd_send_command(y + 1); | ||
317 | |||
318 | lcd_write_yuv420_lines(yuv_src, width, stride); | ||
319 | yuv_src[0] += stride << 1; /* Skip down two luma lines */ | ||
320 | yuv_src[1] += stride >> 1; /* Skip down one chroma line */ | ||
321 | yuv_src[2] += stride >> 1; | ||
322 | y += 2; | ||
323 | } | ||
324 | while (--height > 0); | ||
325 | } | ||
326 | } | ||
327 | |||
328 | /* Update the display. | ||
329 | This must be called after all other LCD functions that change the display. */ | ||
330 | void lcd_update(void) | ||
331 | { | ||
332 | lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); | ||
333 | } | ||
334 | |||
335 | /* Update a fraction of the display. */ | ||
336 | void lcd_update_rect(int x, int y, int width, int height) | ||
337 | { | ||
338 | const fb_data *addr; | ||
339 | |||
340 | if (x + width >= LCD_WIDTH) | ||
341 | width = LCD_WIDTH - x; | ||
342 | if (y + height >= LCD_HEIGHT) | ||
343 | height = LCD_HEIGHT - y; | ||
344 | |||
345 | if ((width <= 0) || (height <= 0)) | ||
346 | return; /* Nothing left to do. */ | ||
347 | |||
348 | addr = &lcd_framebuffer[y][x]; | ||
349 | |||
350 | if (width <= 1) { | ||
351 | lcd_send_command(R_ENTRY_MODE); /* The X end address must be larger */ | ||
352 | lcd_send_command(0x03); /* that the X start address, so we */ | ||
353 | lcd_send_command(R_Y_ADDR_AREA); /* switch to vertical mode for */ | ||
354 | lcd_send_command(x + 4); /* single column updates and set */ | ||
355 | lcd_send_command(x + 1 + 4); /* the window width to 2 */ | ||
356 | } else { | ||
357 | lcd_send_command(R_ENTRY_MODE); | ||
358 | lcd_send_command(0x01); | ||
359 | lcd_send_command(R_Y_ADDR_AREA); | ||
360 | lcd_send_command(x + 4); | ||
361 | lcd_send_command(x + width - 1 + 4); | ||
362 | } | ||
363 | |||
364 | lcd_send_command(R_X_ADDR_AREA); | ||
365 | lcd_send_command(y); | ||
366 | lcd_send_command(y + height - 1); | ||
367 | |||
368 | do { | ||
369 | int w = width; | ||
370 | do { | ||
371 | lcd_send_data(*addr++); | ||
372 | } while (--w > 0); | ||
373 | addr += LCD_WIDTH - width; | ||
374 | } while (--height > 0); | ||
375 | } | ||