Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / firmware / target / arm / samsung / yh820 / lcd-yh820.c
blob4773e27185b8b7c66d1fa518df15812c294e106a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Mark Arigo
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 */
23 #include "config.h"
24 #include "cpu.h"
25 #include "lcd.h"
26 #include "kernel.h"
27 #include "system.h"
29 /* Display status */
30 static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
32 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
33 static bool is_lcd_enabled = true;
34 #endif
36 /* NOTE: the LCD is rotated 90 degrees */
38 /* LCD command set for Samsung S6B33B2 */
40 #define R_NOP 0x00
41 #define R_OSCILLATION_MODE 0x02
42 #define R_DRIVER_OUTPUT_MODE 0x10
43 #define R_DCDC_SET 0x20
44 #define R_BIAS_SET 0x22
45 #define R_DCDC_CLOCK_DIV 0x24
46 #define R_DCDC_AMP_ONOFF 0x26
47 #define R_TEMP_COMPENSATION 0x28
48 #define R_CONTRAST_CONTROL1 0x2a
49 #define R_CONTRAST_CONTROL2 0x2b
50 #define R_STANDBY_OFF 0x2c
51 #define R_STANDBY_ON 0x2d
52 #define R_DDRAM_BURST_OFF 0x2e
53 #define R_DDRAM_BURST_ON 0x2f
54 #define R_ADDRESSING_MODE 0x30
55 #define R_ROW_VECTOR_MODE 0x32
56 #define R_N_LINE_INVERSION 0x34
57 #define R_FRAME_FREQ_CONTROL 0x36
58 #define R_RED_PALETTE 0x38
59 #define R_GREEN_PALETTE 0x3a
60 #define R_BLUE_PALETTE 0x3c
61 #define R_ENTRY_MODE 0x40
62 #define R_X_ADDR_AREA 0x42
63 #define R_Y_ADDR_AREA 0x43
64 #define R_RAM_SKIP_AREA 0x45
65 #define R_DISPLAY_OFF 0x50
66 #define R_DISPLAY_ON 0x51
67 #define R_SPEC_DISPLAY_PATTERN 0x53
68 #define R_PARTIAL_DISPLAY_MODE 0x55
69 #define R_PARTIAL_START_LINE 0x56
70 #define R_PARTIAL_END_LINE 0x57
71 #define R_AREA_SCROLL_MODE 0x59
72 #define R_SCROLL_START_LINE 0x5a
73 #define R_DATA_FORMAT_SELECT 0x60
76 /* wait for LCD */
77 static inline void lcd_wait_write(void)
79 while (LCD1_CONTROL & LCD1_BUSY_MASK);
82 /* send LCD data */
83 static void lcd_send_data(unsigned data)
85 lcd_wait_write();
86 LCD1_DATA = data >> 8;
87 lcd_wait_write();
88 LCD1_DATA = data & 0xff;
91 /* send LCD command */
92 static void lcd_send_command(unsigned cmd)
94 lcd_wait_write();
95 LCD1_CMD = cmd;
98 /* LCD init */
99 void lcd_init_device(void)
101 #if 0
102 /* This is the init sequence from the yh820 OF bootloader */
103 unsigned long tmp;
105 DEV_INIT1 &= ~0x3000;
106 tmp = DEV_INIT1;
107 DEV_INIT1 = tmp;
108 DEV_INIT2 &= ~0x400;
110 LCD1_CONTROL &= ~0x4;
111 udelay(15);
112 LCD1_CONTROL |= 0x4;
114 LCD1_CONTROL = 0x680;
115 LCD1_CONTROL = 0x684;
117 LCD1_CONTROL |= 0x1;
118 udelay(200);
120 lcd_send_command(R_STANDBY_OFF);
121 udelay(100000);
123 lcd_send_command(R_DISPLAY_OFF);
124 udelay(10000);
126 lcd_send_command(R_OSCILLATION_MODE);
127 lcd_send_command(0x01);
128 udelay(30000);
130 lcd_send_command(R_DCDC_SET);
131 lcd_send_command(0x01);
132 udelay(30000);
134 lcd_send_command(R_DCDC_AMP_ONOFF);
135 lcd_send_command(0x01);
136 udelay(30000);
138 lcd_send_command(R_DCDC_AMP_ONOFF);
139 lcd_send_command(0x09);
140 udelay(30000);
142 lcd_send_command(R_DCDC_AMP_ONOFF);
143 lcd_send_command(0x0b);
144 udelay(30000);
146 lcd_send_command(R_DCDC_AMP_ONOFF);
147 lcd_send_command(0x0f);
148 udelay(30000);
150 lcd_send_command(R_DCDC_CLOCK_DIV);
151 lcd_send_command(0x03);
152 udelay(10000);
154 lcd_send_command(R_CONTRAST_CONTROL1);
155 lcd_send_command(0x89);
156 udelay(10000);
158 lcd_send_command(R_TEMP_COMPENSATION);
159 lcd_send_command(0x01);
160 udelay(10000);
162 lcd_send_command(R_ADDRESSING_MODE);
163 lcd_send_command(0x19);
164 udelay(10000);
166 lcd_send_command(R_ROW_VECTOR_MODE);
167 lcd_send_command(0x00);
168 udelay(10000);
170 lcd_send_command(R_N_LINE_INVERSION);
171 lcd_send_command(0x8b);
172 udelay(10000);
174 lcd_send_command(R_ENTRY_MODE);
175 lcd_send_command(0x01);
177 lcd_send_command(R_DRIVER_OUTPUT_MODE);
178 lcd_send_command(0x34);
179 udelay(10000);
181 lcd_send_command(R_X_ADDR_AREA); /* vertical dimensions */
182 lcd_send_command(0x00); /* y1 */
183 lcd_send_command(LCD_HEIGHT - 1); /* y2 */
185 lcd_send_command(R_Y_ADDR_AREA); /* horizontal dimensions */
186 lcd_send_command(0x04); /* x1 + 4 */
187 lcd_send_command(LCD_WIDTH - 1 + 4); /* x2 + 4 */
188 udelay(100);
190 lcd_send_command(R_BIAS_SET);
191 lcd_send_command(0x01);
193 lcd_send_command(R_DDRAM_BURST_OFF);
194 udelay(100);
196 lcd_send_command(R_DISPLAY_ON);
197 udelay(30000);
198 #endif
201 /*** hardware configuration ***/
202 int lcd_default_contrast(void)
204 return DEFAULT_CONTRAST_SETTING;
207 void lcd_set_contrast(int val)
209 lcd_send_command(R_CONTRAST_CONTROL1);
210 lcd_send_command(val);
213 void lcd_set_invert_display(bool yesno)
215 /* TODO: Implement lcd_set_invert_display() */
216 (void)yesno;
219 #if defined(HAVE_LCD_ENABLE)
220 void lcd_enable(bool yesno)
222 if (yesno == is_lcd_enabled)
223 return;
225 if ((is_lcd_enabled = yesno))
227 lcd_send_command(R_STANDBY_OFF);
228 lcd_send_command(R_DISPLAY_ON);
229 send_event(LCD_EVENT_ACTIVATION, NULL);
231 else
233 lcd_send_command(R_STANDBY_ON);
236 #endif
238 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
239 bool lcd_active(void)
241 return is_lcd_enabled;
243 #endif
245 #ifdef HAVE_LCD_FLIP
246 /* turn the display upside down (call lcd_update() afterwards) */
247 /* Note: since the lcd is rotated, this will flip horiz instead of vert */
248 void lcd_set_flip(bool yesno)
250 lcd_send_command(R_DRIVER_OUTPUT_MODE);
251 lcd_send_command(yesno ? 0x30 : 0x34);
253 #endif
256 /*** update functions ***/
258 void lcd_yuv_set_options(unsigned options)
260 lcd_yuv_options = options;
263 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
264 extern void lcd_write_yuv420_lines(unsigned char const * const src[3],
265 int width,
266 int stride);
267 extern void lcd_write_yuv420_lines_odither(unsigned char const * const src[3],
268 int width,
269 int stride,
270 int x_screen, /* To align dither pattern */
271 int y_screen);
272 /* Performance function to blit a YUV bitmap directly to the LCD */
273 void lcd_blit_yuv(unsigned char * const src[3],
274 int src_x, int src_y, int stride,
275 int x, int y, int width, int height)
277 unsigned char const * yuv_src[3];
278 off_t z;
280 /* Sorry, but width and height must be >= 2 or else */
281 width &= ~1;
282 height >>= 1;
284 z = stride*src_y;
285 yuv_src[0] = src[0] + z + src_x;
286 yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
287 yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
289 lcd_send_command(R_ENTRY_MODE);
290 lcd_send_command(0x03);
292 lcd_send_command(R_Y_ADDR_AREA);
293 lcd_send_command(x + 4);
294 lcd_send_command(x + width - 1 + 4);
296 if (lcd_yuv_options & LCD_YUV_DITHER)
300 lcd_send_command(R_X_ADDR_AREA);
301 lcd_send_command(y);
302 lcd_send_command(y + 1);
304 lcd_write_yuv420_lines_odither(yuv_src, width, stride, x, y);
305 yuv_src[0] += stride << 1; /* Skip down two luma lines */
306 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
307 yuv_src[2] += stride >> 1;
308 y += 2;
310 while (--height > 0);
312 else
316 lcd_send_command(R_X_ADDR_AREA);
317 lcd_send_command(y);
318 lcd_send_command(y + 1);
320 lcd_write_yuv420_lines(yuv_src, width, stride);
321 yuv_src[0] += stride << 1; /* Skip down two luma lines */
322 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
323 yuv_src[2] += stride >> 1;
324 y += 2;
326 while (--height > 0);
330 /* Update the display.
331 This must be called after all other LCD functions that change the display. */
332 void lcd_update(void)
334 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
337 /* Update a fraction of the display. */
338 void lcd_update_rect(int x, int y, int width, int height)
340 const fb_data *addr;
342 if (x + width >= LCD_WIDTH)
343 width = LCD_WIDTH - x;
344 if (y + height >= LCD_HEIGHT)
345 height = LCD_HEIGHT - y;
347 if ((width <= 0) || (height <= 0))
348 return; /* Nothing left to do. */
350 addr = &lcd_framebuffer[y][x];
352 if (width <= 1) {
353 lcd_send_command(R_ENTRY_MODE); /* The X end address must be larger */
354 lcd_send_command(0x03); /* that the X start address, so we */
355 lcd_send_command(R_Y_ADDR_AREA); /* switch to vertical mode for */
356 lcd_send_command(x + 4); /* single column updates and set */
357 lcd_send_command(x + 1 + 4); /* the window width to 2 */
358 } else {
359 lcd_send_command(R_ENTRY_MODE);
360 lcd_send_command(0x01);
361 lcd_send_command(R_Y_ADDR_AREA);
362 lcd_send_command(x + 4);
363 lcd_send_command(x + width - 1 + 4);
366 lcd_send_command(R_X_ADDR_AREA);
367 lcd_send_command(y);
368 lcd_send_command(y + height - 1);
370 do {
371 int w = width;
372 do {
373 lcd_send_data(*addr++);
374 } while (--w > 0);
375 addr += LCD_WIDTH - width;
376 } while (--height > 0);