Remove svn:executable from firmware
[kugel-rb.git] / firmware / target / arm / philips / sa9200 / lcd-sa9200.c
blob51a3cf0f71aa1d2046bd01460f135dfc769aa79c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 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 "config.h"
22 #include "cpu.h"
23 #include "lcd.h"
24 #include "kernel.h"
25 #include "system.h"
27 /* Settings to remember when display is turned off */
28 static bool invert;
29 static bool flip;
30 static int contrast;
32 static bool power_on;
33 static bool display_on;
35 /* Forward declarations */
36 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
37 static void lcd_display_off(void);
38 #endif
40 /* The SA9200 controller closely matches the register defines for the
41 Samsung S6D0151 */
42 #define R_START_OSC 0x00
43 #define R_DRV_OUTPUT_CONTROL 0x01
44 #define R_INVERSION_CONTROL 0x02
45 #define R_ENTRY_MODE 0x03
46 #define R_DISP_CONTROL 0x07
47 #define R_BLANK_PERIOD_CONTROL 0x08
48 #define R_FRAME_CYCLE_CONTROL 0x0b
49 #define R_EXT_INTERFACE_CONTROL 0x0c
50 #define R_POWER_CONTROL1 0x10
51 #define R_GAMMA_CONTROL1 0x11
52 #define R_POWER_CONTROL2 0x12
53 #define R_POWER_CONTROL3 0x13
54 #define R_POWER_CONTROL4 0x14
55 #define R_RAM_ADDR_SET 0x21
56 #define R_WRITE_DATA_2_GRAM 0x22
57 #define R_RAM_READ_DATA 0x22
58 #define R_GAMMA_FINE_ADJ_POS1 0x30
59 #define R_GAMMA_FINE_ADJ_POS2 0x31
60 #define R_GAMMA_FINE_ADJ_POS3 0x32
61 #define R_GAMMA_GRAD_ADJ_POS 0x33
62 #define R_GAMMA_FINE_ADJ_NEG1 0x34
63 #define R_GAMMA_FINE_ADJ_NEG2 0x35
64 #define R_GAMMA_FINE_ADJ_NEG3 0x36
65 #define R_GAMMA_GRAD_ADJ_NEG 0x37
66 #define R_GAMMA_CONTROL3 0x38
67 #define R_GATE_SCAN_START_POS 0x40
68 #define R_1ST_SCR_DRV_POS 0x42
69 #define R_2ND_SCR_DRV_POS 0x43
70 #define R_HORIZ_RAM_ADDR_POS 0x44
71 #define R_VERT_RAM_ADDR_POS 0x45
72 #define R_OSC_CONTROL 0x61
73 #define R_LOW_POWER_MODE 0x69
74 #define R_PRE_DRIVING_PERIOD 0x70
75 #define R_GATE_OUT_PERIOD_CTRL 0x71
76 #define R_SOFTWARE_RESET 0x72
78 /* Display status */
79 static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
81 /* wait for LCD */
82 static inline void lcd_wait_write(void)
84 while (LCD1_CONTROL & LCD1_BUSY_MASK);
87 /* send LCD data */
88 static void lcd_send_data(unsigned data)
90 lcd_wait_write();
91 LCD1_DATA = data >> 8;
92 lcd_wait_write();
93 LCD1_DATA = data & 0xff;
96 /* send LCD command */
97 static void lcd_send_command(unsigned cmd)
99 lcd_wait_write();
100 LCD1_CMD = cmd >> 8;
101 lcd_wait_write();
102 LCD1_CMD = cmd & 0xff;
105 static void lcd_write_reg(unsigned reg, unsigned data)
107 lcd_send_command(reg);
108 lcd_send_data(data);
111 /* LCD init */
112 void lcd_init_device(void)
114 #if 0
115 /* This is done by the OF bootloader, no need to redo */
116 DEV_INIT1 &= ~0x3000;
117 DEV_INIT1 = DEV_INIT1;
118 DEV_INIT2 &= ~0x400;
120 LCD1_CONTROL = 0x4680;
121 udelay(1500);
122 LCD1_CONTROL = 0x4684;
124 outl(1, 0x70003018);
126 LCD1_CONTROL &= ~0x200;
127 LCD1_CONTROL &= ~0x800;
128 LCD1_CONTROL &= ~0x400;
129 udelay(30000);
130 #endif
132 power_on = true;
133 display_on = true;
134 invert = false;
135 flip = false;
136 contrast = DEFAULT_CONTRAST_SETTING;
139 #ifdef HAVE_LCD_SLEEP
140 static void lcd_power_on(void)
142 LCD1_CONTROL |= 0x1;
144 /** Power ON Sequence **/
146 /* Start Oscillation */
147 lcd_write_reg(R_START_OSC, 0x0001);
149 sleep(HZ/20); /* 50ms or more */
151 /* DSTB=0, SAP2-0=001, BT2-0=101, DC2-0=000, AP2-0=001, SLP=0, STB=0 */
152 lcd_write_reg(R_POWER_CONTROL1, 0x0d04);
154 /* VR1C=0, VRN14-10=10111, VRP14-10=11111 */
155 lcd_write_reg(R_GAMMA_CONTROL1, 0x171f);
157 /* SVC3-0=0000, VRH5-4=01 */
158 lcd_write_reg(R_POWER_CONTROL2, 0x0001);
160 /* VCMR=1, PON=0, VRH3-0=1101 */
161 lcd_write_reg(R_POWER_CONTROL3, 0x080d);
163 /* VDV6-0=0000100, VCOMG=0, VCM6-0=xxxxxxx */
164 lcd_write_reg(R_POWER_CONTROL4, 0x0400 | contrast);
166 /* DSTB=0, SAP2-0=010, BT2-0=010, DC2-0=000, AP2-0=010, SLP=0, STB=0 */
167 lcd_write_reg(R_POWER_CONTROL1, 0x1208);
169 sleep(HZ/20); /* 50ms or more */
171 /* VCMR=1, PON=1, VRH3-0=1100 */
172 lcd_write_reg(R_POWER_CONTROL3, 0x081c);
174 sleep(HZ/20); /* OF bootlaoder uses 200ms, no delay in OF firmware */
176 /* Instructions for other mode settings (in register order). */
178 lcd_write_reg(R_DRV_OUTPUT_CONTROL, flip ? 0x090c : 0x0a0c);
180 /* FL1-0=10, FDL=0 */
181 lcd_write_reg(R_INVERSION_CONTROL, 0x0200);
183 /* BGR=1, MDT1-0=00, I/D1-0=11, AM=0 */
184 lcd_write_reg(R_ENTRY_MODE, 0x1030);
186 /* PT1-0=00, SPT=0, GON=0, DTE=0, CL=0, REV=1, D1-0=01 */
187 lcd_write_reg(R_DISP_CONTROL, 0x0005);
189 /* FP3-0=0011, BT3-0=1010 */
190 lcd_write_reg(R_BLANK_PERIOD_CONTROL, 0x030a);
192 /* DIV1-0=00, RTN3-0=0000 */
193 lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x0000);
195 /* RM=0, DM1-0=00, RIM1-0=00 */
196 lcd_write_reg(R_EXT_INTERFACE_CONTROL, 0x0000);
198 /* PKP1=0x0, PKP0=0x0 */
199 lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0000);
201 /* PKP3=0x2, PKP2=0x4 */
202 lcd_write_reg(R_GAMMA_FINE_ADJ_POS2, 0x0204);
204 /* PKP5=0x0, PKP4=0x1 */
205 lcd_write_reg(R_GAMMA_FINE_ADJ_POS3, 0x0001);
207 /* PRP1=0x6, PRP0=0x0 */
208 lcd_write_reg(R_GAMMA_GRAD_ADJ_POS, 0x0600);
210 /* PKN1=0x6, PKN0=0x7 */
211 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG1, 0x0607);
213 /* PKN3=0x3, PKN2=0x5 */
214 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG2, 0x0305);
216 /* PKN5=0x7, PKN4=0x7 */
217 lcd_write_reg(R_GAMMA_FINE_ADJ_NEG3, 0x0707);
219 /* PRN1=0x0, PRN0=0x6 */
220 lcd_write_reg(R_GAMMA_GRAD_ADJ_NEG, 0x0006);
222 /* VRN0=0x4, VRP=0x0 */
223 lcd_write_reg(R_GAMMA_CONTROL3, 0x0400);
225 /* SCN=0x0 */
226 lcd_write_reg(R_GATE_SCAN_START_POS, 0x0000);
228 /* SE1=LCD_HEIGHT-1, SS1=0x0 */
229 lcd_write_reg(R_1ST_SCR_DRV_POS, 0x9f00);
231 /* SE2=0x0, SS2=0x0 */
232 lcd_write_reg(R_2ND_SCR_DRV_POS, 0x0000);
234 /* HEA=LCD_WIDTH-1, HSA=0x0 */
235 lcd_write_reg(R_HORIZ_RAM_ADDR_POS, 0x7f00);
237 /* VEA=LCD_HEIGHT-1, VSA=0x0 */
238 lcd_write_reg(R_VERT_RAM_ADDR_POS, 0x9f00);
240 /* Unknown registers */
241 lcd_write_reg(0x00a8, 0x0125);
242 lcd_write_reg(0x00a9, 0x0014);
243 lcd_write_reg(0x00a7, 0x0022);
245 power_on = true;
248 static void lcd_power_off(void)
250 /* Display must be off first */
251 if (display_on)
252 lcd_display_off();
254 power_on = false;
256 /** Power OFF sequence **/
258 /* DSTB=0, SAP2-0=000, BT2-0=001, DC2-0=000, AP2-0=000, SLP=0, STB=0 */
259 lcd_write_reg(R_POWER_CONTROL1, 0x0100);
261 /* VCMR=1, PON=0, VRH3-0=1101 */
262 lcd_write_reg(R_POWER_CONTROL3, 0x080d);
265 void lcd_sleep(void)
267 if (power_on)
268 lcd_power_off();
270 /* Set standby mode */
272 /* PT1-0=00, SPT=0, GON=1, DTE=1, CL=0, REV=1, D1-0=10 */
273 lcd_write_reg(R_DISP_CONTROL, 0x0036);
275 /* DSTB=0, SAP2-0=000, BT2-0=101, DC2-0=000, AP2-0=000, SLP=0, STB=1 */
276 lcd_write_reg(R_POWER_CONTROL1, 0x0501);
278 LCD1_CONTROL &= ~0xffff0001;
280 #endif
282 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
283 static void lcd_display_off(void)
285 display_on = false;
287 /** Display OFF sequence **/
289 /* PT1-0=10, SPT=0, GON=1, DTE=1, CL=0, REV=1, D1-0=10 */
290 lcd_write_reg(R_DISP_CONTROL, 0x1036);
292 sleep(HZ/25); /* 2 or more frames */
294 /* PT1-0=10, SPT=0, GON=1, DTE=0, CL=0, REV=1, D1-0=00 */
295 lcd_write_reg(R_DISP_CONTROL, 0x1034);
297 sleep(HZ/500); /* 1ms or more */
299 /* PT1-0=10, SPT=0, GON=0, DTE=0, CL=0, REV=1, D1-0=00 */
300 lcd_write_reg(R_DISP_CONTROL, 0x1004);
302 sleep(HZ/25); /* 2 or more frames */
304 #endif
306 #if defined(HAVE_LCD_ENABLE)
307 static void lcd_display_on(void)
309 /* Be sure power is on first */
310 if (!power_on)
311 lcd_power_on();
313 /** Display ON Sequence **/
315 /* PT1-0=00, SPT=0, GON=1, DTE=0, CL=0, REV=0, D1-0=01 */
316 lcd_write_reg(R_DISP_CONTROL, 0x0021);
318 sleep(HZ/500); /* 1ms or more */
320 /* PT1-0=00, SPT=0, GON=1, DTE=0, CL=0, REV=0, D1-0=11 */
321 lcd_write_reg(R_DISP_CONTROL, 0x0023);
323 sleep(HZ/25); /* 2 or more frames */
325 /* PT1-0=10, SPT=0, GON=1, DTE=1, CL=0, REV=x, D1-0=11 */
326 lcd_write_reg(R_DISP_CONTROL, invert ? 0x1033 : 0x1037);
328 display_on = true;
331 void lcd_enable(bool on)
333 if (on == display_on)
334 return;
336 if (on)
338 lcd_display_on();
339 /* Probably out of sync and we don't wanna pepper the code with
340 lcd_update() calls for this. */
341 lcd_update();
342 send_event(LCD_EVENT_ACTIVATION, NULL);
344 else
346 lcd_display_off();
349 #endif
351 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
352 bool lcd_active(void)
354 return display_on;
356 #endif
358 /*** hardware configuration ***/
359 int lcd_default_contrast(void)
361 return DEFAULT_CONTRAST_SETTING;
364 void lcd_set_contrast(int val)
366 contrast = val & 0x7f;
368 if (!display_on)
369 return;
371 /* VDV6-0=0000100, VCOMG=0, VCM6-0=xxxxxxx */
372 lcd_write_reg(R_POWER_CONTROL4, 0x0400 | contrast);
375 void lcd_set_invert_display(bool yesno)
377 invert = yesno;
379 if (!display_on)
380 return;
382 /* PT1-0=10, SPT=0, GON=1, DTE=1, CL=0, REV=x, D1-0=11 */
383 lcd_write_reg(R_DISP_CONTROL, invert ? 0x1033 : 0x1037);
386 /* turn the display upside down (call lcd_update() afterwards) */
387 void lcd_set_flip(bool yesno)
389 flip = yesno;
391 if (!display_on)
392 return;
394 /* DPL=0, EPL=1, SM=0, GS=x, SS=x, NL4-0=01100 */
395 lcd_write_reg(R_DRV_OUTPUT_CONTROL, flip ? 0x090c : 0x0a0c);
398 void lcd_yuv_set_options(unsigned options)
400 lcd_yuv_options = options;
403 /* Performance function to blit a YUV bitmap directly to the LCD */
404 void lcd_blit_yuv(unsigned char * const src[3],
405 int src_x, int src_y, int stride,
406 int x, int y, int width, int height)
408 (void)src;
409 (void)src_x;
410 (void)src_y;
411 (void)stride;
412 (void)x;
413 (void)y;
414 (void)width;
415 (void)height;
418 /* Update the display.
419 This must be called after all other LCD functions that change the display. */
420 void lcd_update(void)
422 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
425 /* Update a fraction of the display. */
426 void lcd_update_rect(int x, int y, int width, int height)
428 const fb_data *addr;
430 if (!display_on)
431 return;
433 if (x + width > LCD_WIDTH)
434 width = LCD_WIDTH - x;
436 if (y + height > LCD_HEIGHT)
437 height = LCD_HEIGHT - y;
439 if ((width <= 0) || (height <= 0))
440 return; /* Nothing left to do. */
442 addr = &lcd_framebuffer[y][x];
444 lcd_write_reg(R_HORIZ_RAM_ADDR_POS, ((x + width - 1) << 8) | x);
445 lcd_write_reg(R_VERT_RAM_ADDR_POS, ((y + height -1) << 8) | y);
446 lcd_write_reg(R_RAM_ADDR_SET, ((y & 0xff) << 8) | (x & 0xff));
447 lcd_send_command(R_WRITE_DATA_2_GRAM);
449 do {
450 int w = width;
451 do {
452 lcd_send_data(*addr++);
453 } while (--w > 0);
454 addr += LCD_WIDTH - width;
455 } while (--height > 0);