add sansa m200v2 support to mkamsboot.
[kugel-rb.git] / firmware / target / arm / lcd-ssd1815.c
blob2acfa791cb3b3bb72bfbe1a81e913f686536b609
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Alan Korr
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"
23 #include "hwcompat.h"
24 #include "kernel.h"
25 #include "lcd.h"
26 #include "system.h"
27 #include "cpu.h"
29 /*** definitions ***/
31 #define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00)
32 #define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10)
33 #define LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO ((char)0x20)
34 #define LCD_SET_POWER_CONTROL_REGISTER ((char)0x28)
35 #define LCD_SET_DISPLAY_START_LINE ((char)0x40)
36 #define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81)
37 #define LCD_SET_SEGMENT_REMAP ((char)0xA0)
38 #define LCD_SET_LCD_BIAS ((char)0xA2)
39 #define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4)
40 #define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5)
41 #define LCD_SET_NORMAL_DISPLAY ((char)0xA6)
42 #define LCD_SET_REVERSE_DISPLAY ((char)0xA7)
43 #define LCD_SET_MULTIPLEX_RATIO ((char)0xA8)
44 #define LCD_SET_BIAS_TC_OSC ((char)0xA9)
45 #define LCD_SET_1OVER4_BIAS_RATIO ((char)0xAA)
46 #define LCD_SET_INDICATOR_OFF ((char)0xAC)
47 #define LCD_SET_INDICATOR_ON ((char)0xAD)
48 #define LCD_SET_DISPLAY_OFF ((char)0xAE)
49 #define LCD_SET_DISPLAY_ON ((char)0xAF)
50 #define LCD_SET_PAGE_ADDRESS ((char)0xB0)
51 #define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0)
52 #define LCD_SET_TOTAL_FRAME_PHASES ((char)0xD2)
53 #define LCD_SET_DISPLAY_OFFSET ((char)0xD3)
54 #define LCD_SET_READ_MODIFY_WRITE_MODE ((char)0xE0)
55 #define LCD_SOFTWARE_RESET ((char)0xE2)
56 #define LCD_NOP ((char)0xE3)
57 #define LCD_SET_END_OF_READ_MODIFY_WRITE_MODE ((char)0xEE)
59 /* LCD command codes */
60 #define LCD_CNTL_RESET 0xe2 /* Software reset */
61 #define LCD_CNTL_POWER 0x2f /* Power control */
62 #define LCD_CNTL_CONTRAST 0x81 /* Contrast */
63 #define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */
64 #define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */
65 #define LCD_CNTL_DISPON 0xaf /* Display on */
67 #define LCD_CNTL_PAGE 0xb0 /* Page address */
68 #define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */
69 #define LCD_CNTL_LOWCOL 0x00 /* Lower column address */
72 #if CONFIG_CPU == AS3525
73 #include "as3525.h"
75 void lcd_write_command(int byte)
77 DBOP_TIMPOL_23 = 0x6006E;
78 DBOP_DOUT = byte;
80 /* While push fifo is not empty */
81 while ((DBOP_STAT & (1<<10)) == 0)
84 DBOP_TIMPOL_23 = 0x6E06F;
87 void lcd_write_data(const fb_data* p_bytes, int count)
89 while (count--)
91 /* Write pixels */
92 DBOP_DOUT = *p_bytes++;
94 /* While push fifo is not empty */
95 while ((DBOP_STAT & (1<<10)) == 0)
100 static inline void ams3525_dbop_init(void)
102 int clkdiv = 4 - 1;
104 CGU_DBOP |= (1<<3) /* clk enable */ | clkdiv /* clkdiv: 3 bits */ ;
106 GPIOB_AFSEL = 0x0f; /* DBOP on pin 3:0 */
107 GPIOC_AFSEL = 0xff; /* DBOP on pins 7:0 */
109 DBOP_CTRL = 0x50008;
110 DBOP_TIMPOL_01 = 0xA167E167;
111 DBOP_TIMPOL_23 = 0x6E06F; /* this value is used for data (pixels) write */
115 /* LCD init, largely based on what OF does */
116 void lcd_init_device(void)
118 int delay;
120 ams3525_dbop_init();
122 GPIOB_DIR |= (1<<4);
123 GPIOD_DIR |= (1<<1)|(1<<3);
125 GPIOD_PIN(1) = (1<<1); /* backlight on */
127 GPIOD_PIN(3) = (1<<3);
128 delay = 10; while(delay--) ;
130 GPIOB_PIN(4) = (1<<4);
131 delay = 10; while(delay--) ;
133 lcd_write_command(LCD_SET_LCD_BIAS);
134 lcd_write_command(LCD_SET_SEGMENT_REMAP);
135 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION);
136 lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO|0x5);
137 lcd_set_contrast(lcd_default_contrast());
138 lcd_write_command(LCD_SET_REVERSE_DISPLAY);
139 lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER|0x7);
140 lcd_write_command(LCD_SET_DISPLAY_ON);
141 lcd_write_command(LCD_SET_DISPLAY_START_LINE);
142 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
146 #elif defined(CPU_TCC77X)
148 /* TCC77x specific defines */
149 #define LCD_BASE 0x50000000
150 #define LCD_CMD *(volatile unsigned char*)(LCD_BASE)
151 #define LCD_DATA *(volatile unsigned char*)(LCD_BASE+1)
153 void lcd_write_command(int byte)
155 LCD_CMD = byte;
157 asm volatile (
158 "nop \n\t"
159 "nop \n\t"
160 "nop \n\t"
164 void lcd_write_data(const fb_data* p_bytes, int count)
166 while (count--)
168 LCD_DATA = *(p_bytes++);
170 asm volatile (
171 "nop \n\t"
172 "nop \n\t"
173 "nop \n\t"
178 /* LCD init */
179 void lcd_init_device(void)
181 uint32_t bus_width;
183 /* Telechips init the same as the original firmware */
184 CSCFG1 &= 0xc3ffc000;
185 CSCFG1 |= 0x3400101a;
186 CSCFG1 |= (1 << 21);
187 CSCFG1 &= ~(1 << 21);
189 bus_width = ((MCFG >> 11) & 0x3) ^ 3;
191 CSCFG1 = (bus_width << 28) |
192 (3 << 26) | /* MTYPE = 3 */
193 ((LCD_BASE >> 28) << 22) | /* CSBASE = 0x5 */
194 (1 << 20) | /* Unknown */
195 (3 << 11) | /* Setup time = 3 cycles */
196 (3 << 3) | /* Pulse width = 3+1 cycles */
197 (1 << 0); /* Hold time = 1 cycle */
199 /* SSD1815 inits like the original firmware */
200 lcd_write_command(LCD_SET_DISPLAY_OFF);
201 lcd_set_flip(false);
202 lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO | 5);
203 lcd_set_contrast(lcd_default_contrast());
204 lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER | 7);
205 /* power control register: op-amp=1, regulator=1, booster=1 */
206 lcd_write_command(LCD_SET_BIAS_TC_OSC);
208 /* 0xc2 = 110 000 10: Osc. Freq 110 - ???
209 TC value 000 - "-0.01%/C (TC0, POR)"
210 Bias ratio 10 - "1/9, 1/7 (POR)"
212 lcd_write_command(0xc2);
213 lcd_write_command(LCD_SET_DISPLAY_ON);
215 lcd_clear_display();
216 lcd_update();
219 /* End of TCC77x specific defines */
220 #endif
223 /** globals **/
225 static int xoffset; /* needed for flip */
227 /*** hardware configuration ***/
229 int lcd_default_contrast(void)
231 return 0x1f;
234 void lcd_set_contrast(int val)
236 lcd_write_command(LCD_CNTL_CONTRAST);
237 lcd_write_command(val);
240 void lcd_set_invert_display(bool yesno)
242 if (yesno)
243 lcd_write_command(LCD_SET_REVERSE_DISPLAY);
244 else
245 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
248 /* turn the display upside down (call lcd_update() afterwards) */
249 void lcd_set_flip(bool yesno)
251 (void)yesno;
252 /* TODO */
256 /*** Update functions ***/
258 /* Performance function that works with an external buffer
259 note that by and bheight are in 8-pixel units! */
260 void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
261 int bheight, int stride)
263 /* Copy display bitmap to hardware */
264 while (bheight--)
266 lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf));
267 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset)>>4) & 0xf));
268 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
270 lcd_write_data(data, width);
271 data += stride;
276 /* Performance function that works with an external buffer
277 note that by and bheight are in 8-pixel units! */
278 void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
279 int x, int by, int width, int bheight, int stride)
281 (void)values;
282 (void)phases;
283 (void)x;
284 (void)by;
285 (void)width;
286 (void)bheight;
287 (void)stride;
290 /* Update the display.
291 This must be called after all other LCD functions that change the display. */
292 void lcd_update(void) ICODE_ATTR;
293 void lcd_update(void)
295 int y;
297 /* Copy display bitmap to hardware */
298 for (y = 0; y < LCD_FBHEIGHT; y++)
300 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
301 lcd_write_command (LCD_CNTL_HIGHCOL | ((xoffset >> 4) & 0xf));
302 lcd_write_command (LCD_CNTL_LOWCOL | (xoffset & 0xf));
304 lcd_write_data (lcd_framebuffer[y], LCD_WIDTH);
308 /* Update a fraction of the display. */
309 void lcd_update_rect(int, int, int, int) ICODE_ATTR;
310 void lcd_update_rect(int x, int y, int width, int height)
312 int ymax;
314 /* The Y coordinates have to work on even 8 pixel rows */
315 ymax = (y + height-1) >> 3;
316 y >>= 3;
318 if(x + width > LCD_WIDTH)
319 width = LCD_WIDTH - x;
320 if (width <= 0)
321 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
322 if(ymax >= LCD_FBHEIGHT)
323 ymax = LCD_FBHEIGHT-1;
325 /* Copy specified rectange bitmap to hardware */
326 for (; y <= ymax; y++)
328 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
329 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset) >> 4) & 0xf));
330 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
332 lcd_write_data (&lcd_framebuffer[y][x], width);