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 ****************************************************************************/
29 #include "dbop-as3525.h"
34 static unsigned lcd_yuv_options SHAREDBSS_ATTR
= 0;
36 static bool is_lcd_enabled
= true;
38 /* LCD command set for Samsung S6B33B2 */
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
75 #if defined(SANSA_C200)
77 static inline void lcd_wait_write(void)
79 while (LCD1_CONTROL
& LCD1_BUSY_MASK
);
83 static void lcd_send_pixel(const fb_data data
)
86 LCD1_DATA
= data
>> 8;
88 LCD1_DATA
= data
& 0xff;
91 inline void lcd_write_data(const fb_data
*data
, int width
)
94 lcd_send_pixel(*data
++);
98 /* send LCD command */
99 static void lcd_send_command(unsigned char cmd
, unsigned char arg
)
103 /* if the argument is 0, we send a NOP (= 0) command */
108 static inline void c200v1_lcd_init(void)
110 /* This is from the c200 of bootloader beginning at offset 0xbbf4 */
111 outl(inl(0x70000010) & ~0xfc000000, 0x70000010);
112 outl(inl(0x70000010), 0x70000010);
117 LCD1_CONTROL
&= ~0x4;
123 LCD1_CONTROL
= 0x0084; /* bits (9,10) = 00 -> fastest setting */
127 #define lcd_delay(delay) udelay((delay) * 1000)
129 #elif defined(SANSA_C200V2)
131 static inline void lcd_delay(int delay
)
132 { //TUNEME : delay is in milliseconds
138 void lcd_write_data(const fb_data
*data
, int width
)
141 DBOP_DOUT
= *data
<< 8 | *data
>> 8;
144 /* Wait if push fifo is full */
145 while ((DBOP_STAT
& (1<<6)) != 0);
148 /* While push fifo is not empty */
149 while ((DBOP_STAT
& (1<<10)) == 0);
152 /* send LCD command */
153 static void lcd_send_command(unsigned char cmd
, unsigned char val
)
155 DBOP_TIMPOL_23
= 0xa167006e;
157 DBOP_DOUT
= cmd
| val
<< 8;
159 while ((DBOP_STAT
& (1<<10)) == 0);
161 DBOP_TIMPOL_23
= 0xa167e06f;
164 static inline void as3525_dbop_init(void)
166 CGU_DBOP
= (1<<3) | AS3525_DBOP_DIV
;
168 DBOP_TIMPOL_01
= 0xe167e167;
169 DBOP_TIMPOL_23
= 0xe167006e;
175 DBOP_TIMPOL_23
= 0x6006e;
177 DBOP_TIMPOL_01
= 0x6e167;
178 DBOP_TIMPOL_23
= 0xa167e06f;
186 void lcd_init_device(void)
188 #if defined(SANSA_C200)
190 #elif defined(SANSA_C200V2)
194 lcd_send_command(R_STANDBY_OFF
, 0);
197 lcd_send_command(R_OSCILLATION_MODE
, 0x01);
200 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x01);
203 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x09);
206 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x0b);
209 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x0f);
212 lcd_send_command(R_DRIVER_OUTPUT_MODE
, 0x07);
214 lcd_send_command(R_DCDC_SET
, 0x03);
216 lcd_send_command(R_DCDC_CLOCK_DIV
, 0x03);
218 lcd_send_command(R_TEMP_COMPENSATION
, 0x01);
220 lcd_send_command(R_CONTRAST_CONTROL1
, 0x55);
222 lcd_send_command(R_ADDRESSING_MODE
, 0x10);
224 lcd_send_command(R_ROW_VECTOR_MODE
, 0x0e);
226 lcd_send_command(R_N_LINE_INVERSION
, 0x0d);
228 lcd_send_command(R_FRAME_FREQ_CONTROL
, 0);
230 lcd_send_command(R_ENTRY_MODE
, 0x82);
232 /* vertical dimensions */
233 lcd_send_command(R_Y_ADDR_AREA
, 0x1a); /* y1 + 0x1a */
234 lcd_send_command(LCD_HEIGHT
- 1 + 0x1a, 0); /* y2 + 0x1a */
236 /* horizontal dimensions */
237 lcd_send_command(R_X_ADDR_AREA
, 0); /* x1 */
238 lcd_send_command(LCD_WIDTH
- 1, 0); /* x2 */
242 lcd_send_command(R_DISPLAY_ON
, 0);
245 /*** hardware configuration ***/
246 int lcd_default_contrast(void)
248 return DEFAULT_CONTRAST_SETTING
;
251 void lcd_set_contrast(int val
)
253 lcd_send_command(R_CONTRAST_CONTROL1
, val
);
256 void lcd_set_invert_display(bool yesno
)
258 /* TODO: Implement lcd_set_invert_display() */
262 #if defined(HAVE_LCD_ENABLE)
263 void lcd_enable(bool yesno
)
265 if (yesno
== is_lcd_enabled
)
268 if ((is_lcd_enabled
= yesno
))
270 lcd_send_command(R_STANDBY_OFF
, 0);
271 lcd_send_command(R_DISPLAY_ON
, 0);
272 send_event(LCD_EVENT_ACTIVATION
, NULL
);
276 lcd_send_command(R_STANDBY_ON
, 0);
281 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
282 bool lcd_active(void)
284 return is_lcd_enabled
;
289 /* turn the display upside down (call lcd_update() afterwards) */
290 void lcd_set_flip(bool yesno
)
292 lcd_send_command(R_DRIVER_OUTPUT_MODE
, yesno
? 0x02 : 0x07);
295 /*** update functions ***/
297 #if MEMORYSIZE > 2 /* not for C200V2 */
298 void lcd_yuv_set_options(unsigned options
)
300 lcd_yuv_options
= options
;
303 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
304 extern void lcd_write_yuv420_lines(unsigned char const * const src
[3],
307 extern void lcd_write_yuv420_lines_odither(unsigned char const * const src
[3],
310 int x_screen
, /* To align dither pattern */
312 /* Performance function to blit a YUV bitmap directly to the LCD */
313 void lcd_blit_yuv(unsigned char * const src
[3],
314 int src_x
, int src_y
, int stride
,
315 int x
, int y
, int width
, int height
)
317 unsigned char const * yuv_src
[3];
320 /* Sorry, but width and height must be >= 2 or else */
327 yuv_src
[0] = src
[0] + z
+ src_x
;
328 yuv_src
[1] = src
[1] + (z
>> 2) + (src_x
>> 1);
329 yuv_src
[2] = src
[2] + (yuv_src
[1] - src
[1]);
331 lcd_send_command(R_ENTRY_MODE
, 0x80);
333 lcd_send_command(R_X_ADDR_AREA
, x
);
334 lcd_send_command(x
+ width
- 1, 0);
336 if (lcd_yuv_options
& LCD_YUV_DITHER
)
340 lcd_send_command(R_Y_ADDR_AREA
, y
);
341 lcd_send_command(y
+ 1, 0);
343 lcd_write_yuv420_lines_odither(yuv_src
, width
, stride
, x
, y
);
345 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
346 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
347 yuv_src
[2] += stride
>> 1;
350 while (--height
> 0);
356 lcd_send_command(R_Y_ADDR_AREA
, y
);
357 lcd_send_command(y
+ 1, 0);
359 lcd_write_yuv420_lines(yuv_src
, width
, stride
);
361 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
362 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
363 yuv_src
[2] += stride
>> 1;
366 while (--height
> 0);
369 #endif /* MEMORYSIZE > 2 */
371 /* Update the display.
372 This must be called after all other LCD functions that change the display. */
373 void lcd_update(void)
375 lcd_update_rect(0, 0, LCD_WIDTH
, LCD_HEIGHT
);
378 /* Update a fraction of the display. */
379 void lcd_update_rect(int x
, int y
, int width
, int height
)
383 if (x
+ width
>= LCD_WIDTH
)
384 width
= LCD_WIDTH
- x
;
385 if (y
+ height
>= LCD_HEIGHT
)
386 height
= LCD_HEIGHT
- y
;
388 if ((width
<= 0) || (height
<= 0))
389 return; /* Nothing left to do. */
391 addr
= &lcd_framebuffer
[y
][x
];
394 /* The X end address must be larger than the X start address, so we
395 * switch to vertical mode for single column updates and set the
396 * window width to 2 */
397 lcd_send_command(R_ENTRY_MODE
, 0x80);
398 lcd_send_command(R_X_ADDR_AREA
, x
);
399 lcd_send_command(x
+ 1, 0);
401 lcd_send_command(R_ENTRY_MODE
, 0x82);
402 lcd_send_command(R_X_ADDR_AREA
, x
);
403 lcd_send_command(x
+ width
- 1, 0);
406 lcd_send_command(R_Y_ADDR_AREA
, y
+ 0x1a);
407 lcd_send_command(y
+ height
- 1 + 0x1a, 0);
410 lcd_write_data(addr
, width
);
412 } while (--height
> 0);