1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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>
30 /* button driver needs to know if a lcd operation is in progress */
31 static bool lcd_busy
= false;
32 static unsigned short dbop_input
= 0xFFFF;
37 static unsigned lcd_yuv_options SHAREDBSS_ATTR
= 0;
39 static bool is_lcd_enabled
= true;
41 /* LCD command set for Samsung S6B33B2 */
44 #define R_OSCILLATION_MODE 0x02
45 #define R_DRIVER_OUTPUT_MODE 0x10
46 #define R_DCDC_SET 0x20
47 #define R_BIAS_SET 0x22
48 #define R_DCDC_CLOCK_DIV 0x24
49 #define R_DCDC_AMP_ONOFF 0x26
50 #define R_TEMP_COMPENSATION 0x28
51 #define R_CONTRAST_CONTROL1 0x2a
52 #define R_CONTRAST_CONTROL2 0x2b
53 #define R_STANDBY_OFF 0x2c
54 #define R_STANDBY_ON 0x2d
55 #define R_DDRAM_BURST_OFF 0x2e
56 #define R_DDRAM_BURST_ON 0x2f
57 #define R_ADDRESSING_MODE 0x30
58 #define R_ROW_VECTOR_MODE 0x32
59 #define R_N_LINE_INVERSION 0x34
60 #define R_FRAME_FREQ_CONTROL 0x36
61 #define R_RED_PALETTE 0x38
62 #define R_GREEN_PALETTE 0x3a
63 #define R_BLUE_PALETTE 0x3c
64 #define R_ENTRY_MODE 0x40
65 #define R_X_ADDR_AREA 0x42
66 #define R_Y_ADDR_AREA 0x43
67 #define R_RAM_SKIP_AREA 0x45
68 #define R_DISPLAY_OFF 0x50
69 #define R_DISPLAY_ON 0x51
70 #define R_SPEC_DISPLAY_PATTERN 0x53
71 #define R_PARTIAL_DISPLAY_MODE 0x55
72 #define R_PARTIAL_START_LINE 0x56
73 #define R_PARTIAL_END_LINE 0x57
74 #define R_AREA_SCROLL_MODE 0x59
75 #define R_SCROLL_START_LINE 0x5a
76 #define R_DATA_FORMAT_SELECT 0x60
78 #if defined(SANSA_C200)
80 static inline void lcd_wait_write(void)
82 while (LCD1_CONTROL
& LCD1_BUSY_MASK
);
86 static void lcd_send_pixel(const fb_data data
)
89 LCD1_DATA
= data
>> 8;
91 LCD1_DATA
= data
& 0xff;
94 inline void lcd_write_data(const fb_data
*data
, int width
)
97 lcd_send_pixel(*data
++);
101 /* send LCD command */
102 static void lcd_send_command(unsigned char cmd
, unsigned char arg
)
106 /* if the argument is 0, we send a NOP (= 0) command */
111 static inline void c200v1_lcd_init(void)
113 /* This is from the c200 of bootloader beginning at offset 0xbbf4 */
114 outl(inl(0x70000010) & ~0xfc000000, 0x70000010);
115 outl(inl(0x70000010), 0x70000010);
120 LCD1_CONTROL
&= ~0x4;
126 LCD1_CONTROL
= 0x0084; /* bits (9,10) = 00 -> fastest setting */
130 #define lcd_delay(delay) udelay((delay) * 1000)
132 #elif defined(SANSA_C200V2)
134 static inline void lcd_delay(int delay
)
135 { //TUNEME : delay is in milliseconds
141 void lcd_write_data(const fb_data
*data
, int width
)
144 DBOP_DOUT
= *data
<< 8 | *data
>> 8;
147 /* Wait if push fifo is full */
148 while ((DBOP_STAT
& (1<<6)) != 0);
151 /* While push fifo is not empty */
152 while ((DBOP_STAT
& (1<<10)) == 0);
155 /* send LCD command */
156 static void lcd_send_command(unsigned char cmd
, unsigned char val
)
158 DBOP_TIMPOL_23
= 0xa167006e;
160 DBOP_DOUT
= cmd
| val
<< 8;
162 while ((DBOP_STAT
& (1<<10)) == 0);
164 DBOP_TIMPOL_23
= 0xa167e06f;
167 static inline void as3525_dbop_init(void)
169 CGU_DBOP
= (1<<3) | AS3525_DBOP_DIV
;
171 DBOP_TIMPOL_01
= 0xe167e167;
172 DBOP_TIMPOL_23
= 0xe167006e;
178 DBOP_TIMPOL_23
= 0x6006e;
180 DBOP_TIMPOL_01
= 0x6e167;
181 DBOP_TIMPOL_23
= 0xa167e06f;
186 static unsigned short lcd_dbop_read(void)
188 unsigned int dbop_ctrl_old
= DBOP_CTRL
;
189 unsigned int dbop_timpol23_old
= DBOP_TIMPOL_23
;
192 /* make sure that the DBOP FIFO is empty */
193 while ((DBOP_STAT
& (1<<10)) == 0);
195 /* write DBOP_DOUT to pre-charge DBOP data lines with a high level */
196 DBOP_TIMPOL_23
= 0xe167e167; /* no strobe towards lcd */
197 DBOP_CTRL
= (1 << 16) | /* enw=1 (enable write) */
198 (1 << 12); /* ow=1 (16-bit data width) */
199 DBOP_DOUT
= 0xFFFF; /* all pins high */
200 while ((DBOP_STAT
& (1<<10)) == 0);
202 /* perform a DBOP read */
203 DBOP_CTRL
= (1 << 15) | /* strd=1 (start read) */
204 (1 << 12) | /* ow=1 (16-bit data width) */
205 (31 << 0); /* rs_t=31 (read DBOP at end of cycle) */
206 while ((DBOP_STAT
& (1<<16)) == 0);
209 /* restore previous values */
210 DBOP_TIMPOL_23
= dbop_timpol23_old
;
211 DBOP_CTRL
= dbop_ctrl_old
;
216 /* get the DBOP input value, either directly or cached if DBOP is busy */
217 unsigned short int lcd_dbop_input(void)
220 dbop_input
= lcd_dbop_read();
228 void lcd_init_device(void)
230 #if defined(SANSA_C200)
232 #elif defined(SANSA_C200V2)
236 lcd_send_command(R_STANDBY_OFF
, 0);
239 lcd_send_command(R_OSCILLATION_MODE
, 0x01);
242 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x01);
245 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x09);
248 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x0b);
251 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x0f);
254 lcd_send_command(R_DRIVER_OUTPUT_MODE
, 0x07);
256 lcd_send_command(R_DCDC_SET
, 0x03);
258 lcd_send_command(R_DCDC_CLOCK_DIV
, 0x03);
260 lcd_send_command(R_TEMP_COMPENSATION
, 0x01);
262 lcd_send_command(R_CONTRAST_CONTROL1
, 0x55);
264 lcd_send_command(R_ADDRESSING_MODE
, 0x10);
266 lcd_send_command(R_ROW_VECTOR_MODE
, 0x0e);
268 lcd_send_command(R_N_LINE_INVERSION
, 0x0d);
270 lcd_send_command(R_FRAME_FREQ_CONTROL
, 0);
272 lcd_send_command(R_ENTRY_MODE
, 0x82);
274 /* vertical dimensions */
275 lcd_send_command(R_Y_ADDR_AREA
, 0x1a); /* y1 + 0x1a */
276 lcd_send_command(LCD_HEIGHT
- 1 + 0x1a, 0); /* y2 + 0x1a */
278 /* horizontal dimensions */
279 lcd_send_command(R_X_ADDR_AREA
, 0); /* x1 */
280 lcd_send_command(LCD_WIDTH
- 1, 0); /* x2 */
284 lcd_send_command(R_DISPLAY_ON
, 0);
287 /*** hardware configuration ***/
288 int lcd_default_contrast(void)
290 return DEFAULT_CONTRAST_SETTING
;
293 void lcd_set_contrast(int val
)
298 lcd_send_command(R_CONTRAST_CONTROL1
, val
);
304 void lcd_set_invert_display(bool yesno
)
306 /* TODO: Implement lcd_set_invert_display() */
310 #if defined(HAVE_LCD_ENABLE)
311 void lcd_enable(bool yesno
)
313 if (yesno
== is_lcd_enabled
)
319 if ((is_lcd_enabled
= yesno
))
321 lcd_send_command(R_STANDBY_OFF
, 0);
322 lcd_send_command(R_DISPLAY_ON
, 0);
323 send_event(LCD_EVENT_ACTIVATION
, NULL
);
327 lcd_send_command(R_STANDBY_ON
, 0);
335 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
336 bool lcd_active(void)
338 return is_lcd_enabled
;
343 /* turn the display upside down (call lcd_update() afterwards) */
344 void lcd_set_flip(bool yesno
)
349 lcd_send_command(R_DRIVER_OUTPUT_MODE
, yesno
? 0x02 : 0x07);
355 /*** update functions ***/
358 void lcd_yuv_set_options(unsigned options
)
360 lcd_yuv_options
= options
;
363 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
364 extern void lcd_write_yuv420_lines(unsigned char const * const src
[3],
367 extern void lcd_write_yuv420_lines_odither(unsigned char const * const src
[3],
370 int x_screen
, /* To align dither pattern */
372 /* Performance function to blit a YUV bitmap directly to the LCD */
373 void lcd_blit_yuv(unsigned char * const src
[3],
374 int src_x
, int src_y
, int stride
,
375 int x
, int y
, int width
, int height
)
377 unsigned char const * yuv_src
[3];
380 /* Sorry, but width and height must be >= 2 or else */
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 lcd_send_command(R_ENTRY_MODE
, 0x80);
393 lcd_send_command(R_X_ADDR_AREA
, x
);
394 lcd_send_command(x
+ width
- 1, 0);
396 if (lcd_yuv_options
& LCD_YUV_DITHER
)
400 lcd_send_command(R_Y_ADDR_AREA
, y
);
401 lcd_send_command(y
+ 1, 0);
403 lcd_write_yuv420_lines_odither(yuv_src
, width
, stride
, x
, y
);
405 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
406 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
407 yuv_src
[2] += stride
>> 1;
410 while (--height
> 0);
416 lcd_send_command(R_Y_ADDR_AREA
, y
);
417 lcd_send_command(y
+ 1, 0);
419 lcd_write_yuv420_lines(yuv_src
, width
, stride
);
421 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
422 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
423 yuv_src
[2] += stride
>> 1;
426 while (--height
> 0);
429 #endif /* MEMORYSIZE > 2 */
431 /* Update the display.
432 This must be called after all other LCD functions that change the display. */
433 void lcd_update(void)
435 lcd_update_rect(0, 0, LCD_WIDTH
, LCD_HEIGHT
);
438 /* Update a fraction of the display. */
439 void lcd_update_rect(int x
, int y
, int width
, int height
)
443 if (x
+ width
>= LCD_WIDTH
)
444 width
= LCD_WIDTH
- x
;
445 if (y
+ height
>= LCD_HEIGHT
)
446 height
= LCD_HEIGHT
- y
;
448 if ((width
<= 0) || (height
<= 0))
449 return; /* Nothing left to do. */
451 addr
= &lcd_framebuffer
[y
][x
];
455 /* perform a dbop read before doing a potentially lengthy lcd update */
456 dbop_input
= lcd_dbop_read();
460 /* The X end address must be larger than the X start address, so we
461 * switch to vertical mode for single column updates and set the
462 * window width to 2 */
463 lcd_send_command(R_ENTRY_MODE
, 0x80);
464 lcd_send_command(R_X_ADDR_AREA
, x
);
465 lcd_send_command(x
+ 1, 0);
467 lcd_send_command(R_ENTRY_MODE
, 0x82);
468 lcd_send_command(R_X_ADDR_AREA
, x
);
469 lcd_send_command(x
+ width
- 1, 0);
472 lcd_send_command(R_Y_ADDR_AREA
, y
+ 0x1a);
473 lcd_send_command(y
+ height
- 1 + 0x1a, 0);
476 lcd_write_data(addr
, width
);
478 } while (--height
> 0);