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>
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 #elif defined(SANSA_C200V2)
130 void lcd_write_data(const fb_data
*data
, int width
)
133 DBOP_DOUT
= *data
<< 8 | *data
>> 8;
136 /* Wait if push fifo is full */
137 while ((DBOP_STAT
& (1<<6)) != 0);
140 /* While push fifo is not empty */
141 while ((DBOP_STAT
& (1<<10)) == 0);
144 /* send LCD command */
145 static void lcd_send_command(unsigned char cmd
, unsigned char val
)
147 DBOP_TIMPOL_23
= 0xa167006e;
149 DBOP_DOUT
= cmd
| val
<< 8;
151 while ((DBOP_STAT
& (1<<10)) == 0);
153 DBOP_TIMPOL_23
= 0xa167e06f;
156 static inline void as3525_dbop_init(void)
158 CGU_DBOP
= (1<<3) | AS3525_DBOP_DIV
;
160 DBOP_TIMPOL_01
= 0xe167e167;
161 DBOP_TIMPOL_23
= 0xe167006e;
167 DBOP_TIMPOL_23
= 0x6006e;
169 DBOP_TIMPOL_01
= 0x6e167;
170 DBOP_TIMPOL_23
= 0xa167e06f;
177 static void lcd_reset(void)
179 #if defined(SANSA_C200V2)
182 GPIOB_PIN(6) = 0; /* pull reset low */
184 GPIOB_PIN(6) = 1<<6; /* release reset */
187 lcd_send_command(R_STANDBY_OFF
, 0);
190 lcd_send_command(R_OSCILLATION_MODE
, 0x01);
193 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x01);
196 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x09);
199 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x0b);
202 lcd_send_command(R_DCDC_AMP_ONOFF
, 0x0f);
205 lcd_send_command(R_DRIVER_OUTPUT_MODE
, 0x07);
207 lcd_send_command(R_DCDC_SET
, 0x03);
209 lcd_send_command(R_DCDC_CLOCK_DIV
, 0x03);
211 lcd_send_command(R_TEMP_COMPENSATION
, 0x01);
213 lcd_send_command(R_CONTRAST_CONTROL1
, 0x55);
215 lcd_send_command(R_ADDRESSING_MODE
, 0x10);
217 lcd_send_command(R_ROW_VECTOR_MODE
, 0x0e);
219 lcd_send_command(R_N_LINE_INVERSION
, 0x0d);
221 lcd_send_command(R_FRAME_FREQ_CONTROL
, 0);
223 lcd_send_command(R_ENTRY_MODE
, 0x82);
225 /* vertical dimensions */
226 lcd_send_command(R_Y_ADDR_AREA
, 0x1a); /* y1 + 0x1a */
227 lcd_send_command(LCD_HEIGHT
- 1 + 0x1a, 0); /* y2 + 0x1a */
229 /* horizontal dimensions */
230 lcd_send_command(R_X_ADDR_AREA
, 0); /* x1 */
231 lcd_send_command(LCD_WIDTH
- 1, 0); /* x2 */
235 lcd_send_command(R_DISPLAY_ON
, 0);
239 void lcd_init_device(void)
241 #if defined(SANSA_C200)
243 #elif defined(SANSA_C200V2)
249 /*** hardware configuration ***/
250 int lcd_default_contrast(void)
252 return DEFAULT_CONTRAST_SETTING
;
255 void lcd_set_contrast(int val
)
257 lcd_send_command(R_CONTRAST_CONTROL1
, val
);
260 void lcd_set_invert_display(bool yesno
)
262 #ifdef HAVE_LCD_INVERT
263 lcd_send_command(R_SPEC_DISPLAY_PATTERN
, yesno
? 1 : 0);
269 #if defined(HAVE_LCD_ENABLE)
270 void lcd_enable(bool yesno
)
272 if (yesno
== is_lcd_enabled
)
275 if ((is_lcd_enabled
= yesno
))
278 /* lcd sometimes gets stuck, do full init here */
281 lcd_send_command(R_STANDBY_OFF
, 0);
282 lcd_send_command(R_DISPLAY_ON
, 0);
284 send_event(LCD_EVENT_ACTIVATION
, NULL
);
288 lcd_send_command(R_STANDBY_ON
, 0);
293 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
294 bool lcd_active(void)
296 return is_lcd_enabled
;
301 /* turn the display upside down (call lcd_update() afterwards) */
302 void lcd_set_flip(bool yesno
)
304 lcd_send_command(R_DRIVER_OUTPUT_MODE
, yesno
? 0x02 : 0x07);
307 /*** update functions ***/
309 #if MEMORYSIZE > 2 /* not for C200V2 */
310 void lcd_yuv_set_options(unsigned options
)
312 lcd_yuv_options
= options
;
315 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
316 extern void lcd_write_yuv420_lines(unsigned char const * const src
[3],
319 extern void lcd_write_yuv420_lines_odither(unsigned char const * const src
[3],
322 int x_screen
, /* To align dither pattern */
324 /* Performance function to blit a YUV bitmap directly to the LCD */
325 void lcd_blit_yuv(unsigned char * const src
[3],
326 int src_x
, int src_y
, int stride
,
327 int x
, int y
, int width
, int height
)
329 unsigned char const * yuv_src
[3];
332 /* Sorry, but width and height must be >= 2 or else */
339 yuv_src
[0] = src
[0] + z
+ src_x
;
340 yuv_src
[1] = src
[1] + (z
>> 2) + (src_x
>> 1);
341 yuv_src
[2] = src
[2] + (yuv_src
[1] - src
[1]);
343 lcd_send_command(R_ENTRY_MODE
, 0x80);
345 lcd_send_command(R_X_ADDR_AREA
, x
);
346 lcd_send_command(x
+ width
- 1, 0);
348 if (lcd_yuv_options
& LCD_YUV_DITHER
)
352 lcd_send_command(R_Y_ADDR_AREA
, y
);
353 lcd_send_command(y
+ 1, 0);
355 lcd_write_yuv420_lines_odither(yuv_src
, width
, stride
, x
, y
);
357 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
358 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
359 yuv_src
[2] += stride
>> 1;
362 while (--height
> 0);
368 lcd_send_command(R_Y_ADDR_AREA
, y
);
369 lcd_send_command(y
+ 1, 0);
371 lcd_write_yuv420_lines(yuv_src
, width
, stride
);
373 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
374 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
375 yuv_src
[2] += stride
>> 1;
378 while (--height
> 0);
381 #endif /* MEMORYSIZE > 2 */
383 /* Update the display.
384 This must be called after all other LCD functions that change the display. */
385 void lcd_update(void)
387 lcd_update_rect(0, 0, LCD_WIDTH
, LCD_HEIGHT
);
390 /* Update a fraction of the display. */
391 void lcd_update_rect(int x
, int y
, int width
, int height
)
395 if (x
+ width
>= LCD_WIDTH
)
396 width
= LCD_WIDTH
- x
;
397 if (y
+ height
>= LCD_HEIGHT
)
398 height
= LCD_HEIGHT
- y
;
400 if ((width
<= 0) || (height
<= 0))
401 return; /* Nothing left to do. */
403 addr
= &lcd_framebuffer
[y
][x
];
406 /* The X end address must be larger than the X start address, so we
407 * switch to vertical mode for single column updates and set the
408 * window width to 2 */
409 lcd_send_command(R_ENTRY_MODE
, 0x80);
410 lcd_send_command(R_X_ADDR_AREA
, x
);
411 lcd_send_command(x
+ 1, 0);
413 lcd_send_command(R_ENTRY_MODE
, 0x82);
414 lcd_send_command(R_X_ADDR_AREA
, x
);
415 lcd_send_command(x
+ width
- 1, 0);
418 lcd_send_command(R_Y_ADDR_AREA
, y
+ 0x1a);
419 lcd_send_command(y
+ height
- 1 + 0x1a, 0);
422 lcd_write_data(addr
, width
);
424 } while (--height
> 0);