Trim down peak calculation a bit.
[kugel-rb.git] / firmware / target / arm / tcc77x / c100 / lcd-S6B33B2.c
blob4abd17741bdadffb64b9e00690d4e4c9488e8fd6
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 "config.h"
22 #include "cpu.h"
23 #include "lcd.h"
24 #include "kernel.h"
25 #include "system.h"
27 /* Display status */
28 static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
30 /* LCD command set for Samsung S6B33B2 */
31 #define R_NOP 0x00
32 #define R_OSCILLATION_MODE 0x02
33 #define R_DRIVER_OUTPUT_MODE 0x10
34 #define R_DCDC_SET 0x20
35 #define R_BIAS_SET 0x22
36 #define R_DCDC_CLOCK_DIV 0x24
37 #define R_DCDC_AMP_ONOFF 0x26
38 #define R_TEMP_COMPENSATION 0x28
39 #define R_CONTRAST_CONTROL1 0x2a
40 #define R_CONTRAST_CONTROL2 0x2b
41 #define R_STANDBY_OFF 0x2c
42 #define R_STANDBY_ON 0x2d
43 #define R_DDRAM_BURST_OFF 0x2e
44 #define R_DDRAM_BURST_ON 0x2f
45 #define R_ADDRESSING_MODE 0x30
46 #define R_ROW_VECTOR_MODE 0x32
47 #define R_N_LINE_INVERSION 0x34
48 #define R_FRAME_FREQ_CONTROL 0x36
49 #define R_RED_PALETTE 0x38
50 #define R_GREEN_PALETTE 0x3a
51 #define R_BLUE_PALETTE 0x3c
52 #define R_ENTRY_MODE 0x40
53 #define R_X_ADDR_AREA 0x42
54 #define R_Y_ADDR_AREA 0x43
55 #define R_RAM_SKIP_AREA 0x45
56 #define R_DISPLAY_OFF 0x50
57 #define R_DISPLAY_ON 0x51
58 #define R_SPEC_DISPLAY_PATTERN 0x53
59 #define R_PARTIAL_DISPLAY_MODE 0x55
60 #define R_PARTIAL_START_LINE 0x56
61 #define R_PARTIAL_END_LINE 0x57
62 #define R_AREA_SCROLL_MODE 0x59
63 #define R_SCROLL_START_LINE 0x5a
64 #define R_DATA_FORMAT_SELECT 0x60
66 /* TCC77x specific defines */
67 #define LCD_BASE 0x50000000
68 #define LCD_CMD *(volatile unsigned char*)(LCD_BASE)
69 #define LCD_DATA *(volatile unsigned char*)(LCD_BASE+1)
71 static void lcd_send_command(unsigned cmd)
73 LCD_CMD = cmd;
75 asm volatile (
76 "nop \n\t"
77 "nop \n\t"
78 "nop \n\t"
82 static void lcd_send_data(unsigned data)
84 LCD_DATA = (data & 0xff00) >> 8;
85 LCD_DATA = (data & 0x00ff);
88 /* End of TCC77x specific defines */
90 /* LCD init */
91 void lcd_init_device(void)
93 uint32_t bus_width;
95 /* Telechips init the same as the original firmware */
96 bus_width = ((MCFG >> 11) & 0x3) ^ 3;
98 CSCFG1 = (bus_width << 28) |
99 (3 << 26) | /* MTYPE = 3 */
100 ((LCD_BASE >> 28) << 22) | /* CSBASE = 0x5 */
101 (1 << 20) | /* Unknown */
102 (2 << 11) | /* Setup time = 2 cycles */
103 (2 << 3) | /* Pulse width = 2+1 cycles */
104 (2 << 0); /* Hold time = 2 cycle */
106 GPIOE &= ~0x8;
107 sleep(HZ/100); /* 10ms */
109 GPIOE |= 0x08;
110 sleep(HZ/100); /* 10ms */
112 lcd_send_command(R_STANDBY_OFF);
113 sleep(HZ/20); /* 50ms */
115 lcd_send_command(R_OSCILLATION_MODE);
116 lcd_send_command(0x01);
117 sleep(HZ/100); /* 10ms */
119 lcd_send_command(R_DCDC_AMP_ONOFF);
120 lcd_send_command(0x01);
121 sleep(HZ/100); /* 10ms */
123 lcd_send_command(R_DCDC_AMP_ONOFF);
124 lcd_send_command(0x09);
125 sleep(HZ/100); /* 10ms */
127 lcd_send_command(R_DCDC_AMP_ONOFF);
128 lcd_send_command(0x0b);
129 sleep(HZ/100); /* 10ms */
131 lcd_send_command(R_DCDC_AMP_ONOFF);
132 lcd_send_command(0x0f);
133 sleep(HZ/100); /* 10ms */
135 lcd_send_command(R_DCDC_SET);
136 lcd_send_command(0x01);
137 sleep(HZ/100); /* 10ms */
138 sleep(HZ/10); /* 100ms */
140 lcd_send_command(R_TEMP_COMPENSATION);
141 lcd_send_command(0x01);
142 sleep(HZ/100); /* 10ms */
144 lcd_send_command(R_DRIVER_OUTPUT_MODE);
145 lcd_send_command(0x03);
147 lcd_send_command(R_ENTRY_MODE);
148 lcd_send_command(0x81);
150 lcd_send_command(R_N_LINE_INVERSION);
151 lcd_send_command(0x04);
152 lcd_send_command(0xfa);
153 lcd_send_command(0x5f);
155 lcd_set_contrast(0x28);
157 lcd_send_command(R_SPEC_DISPLAY_PATTERN);
158 lcd_send_command(0x0);
159 sleep(HZ/100); /* 10ms */
161 lcd_send_command(R_ADDRESSING_MODE);
162 lcd_send_command(0x0);
163 sleep(HZ/100); /* 10ms */
165 lcd_send_command(R_PARTIAL_DISPLAY_MODE);
166 lcd_send_command(0x0);
167 sleep(HZ/100); /* 10ms */
169 lcd_send_command(R_X_ADDR_AREA);
170 lcd_send_command(0);
171 lcd_send_command(0x80);
173 lcd_send_command(R_Y_ADDR_AREA);
174 lcd_send_command(0x0);
175 lcd_send_command(0x80);
177 lcd_send_command(R_DISPLAY_ON);
179 lcd_send_command(R_SPEC_DISPLAY_PATTERN);
180 lcd_send_command(0x0);
182 /* Rockbox init */
183 lcd_clear_display();
184 lcd_update();
187 /*** hardware configuration ***/
188 int lcd_default_contrast(void)
190 return 0x28;
193 void lcd_set_contrast(int val)
195 //val &= 0xFF;
196 lcd_send_command(R_CONTRAST_CONTROL1);
197 lcd_send_command(val);
200 void lcd_set_invert_display(bool yesno)
202 /* TODO: Implement lcd_set_invert_display() */
203 (void)yesno;
206 /* turn the display upside down (call lcd_update() afterwards) */
207 void lcd_set_flip(bool yesno)
209 lcd_send_command(R_DRIVER_OUTPUT_MODE);
210 lcd_send_command(yesno ? 0x02 : 0x07);
213 /*** update functions ***/
214 void lcd_yuv_set_options(unsigned options)
216 lcd_yuv_options = options;
219 /* TODO: implement me */
220 void lcd_blit_yuv(unsigned char *const src[3],
221 int src_x, int src_y, int stride,
222 int x, int y, int width, int height)
224 (void) src;
225 (void) src_x;
226 (void) src_y;
227 (void) stride;
228 (void) x;
229 (void) y;
231 return;
235 /* Update the display.
236 This must be called after all other LCD functions that change the display. */
237 void lcd_update(void)
239 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
242 /* Update a fraction of the display. */
243 void lcd_update_rect(int x, int y, int width, int height)
245 const fb_data *addr;
247 if (x + width >= LCD_WIDTH)
248 width = LCD_WIDTH - x;
249 if (y + height >= LCD_HEIGHT)
250 height = LCD_HEIGHT - y;
252 if ((width <= 0) || (height <= 0))
253 return; /* Nothing left to do. */
255 addr = &lcd_framebuffer[y][x];
257 if (width <= 1) {
258 lcd_send_command(R_ENTRY_MODE); /* The X end address must be larger */
259 lcd_send_command(0x80); /* that the X start address, so we */
260 lcd_send_command(R_X_ADDR_AREA); /* switch to vertical mode for */
261 lcd_send_command(x); /* single column updates and set */
262 lcd_send_command(x + 1); /* the window width to 2 */
263 } else {
264 lcd_send_command(R_ENTRY_MODE);
265 lcd_send_command(0x82);
266 lcd_send_command(R_X_ADDR_AREA);
267 lcd_send_command(x);
268 lcd_send_command(x + width - 1);
271 lcd_send_command(R_Y_ADDR_AREA);
272 lcd_send_command(y);
273 lcd_send_command(y + height - 1);
275 /* NOP needed because on some c200s, the previous lcd_send_command is
276 interpreted as a separate command instead of part of R_Y_ADDR_AREA. */
277 lcd_send_command(R_NOP);
279 do {
280 int w = width;
281 do {
282 lcd_send_data(*addr++);
283 } while (--w > 0);
284 addr += LCD_WIDTH - width;
285 } while (--height > 0);