summaryrefslogtreecommitdiff
path: root/firmware/target/arm/lcd-ssd1815.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2008-10-19 14:11:01 +0000
committerDave Chapman <dave@dchapman.com>2008-10-19 14:11:01 +0000
commit08c41d42bb699a1be99c9696b4d4fb7b40e8723a (patch)
tree2834231979d52b81a7860fd4a5e19ed79b3ffee7 /firmware/target/arm/lcd-ssd1815.c
parent14ee31865e366dc19fb87caf4877a8d93305a01b (diff)
downloadrockbox-08c41d42bb699a1be99c9696b4d4fb7b40e8723a.tar.gz
rockbox-08c41d42bb699a1be99c9696b4d4fb7b40e8723a.zip
Add e200v2 and m200v2 targets. Move the telechips lcd-ssd1815.c (currently used by Logik DAX and m200v1 ports) driver up in the target tree and share with the m200v2 - as2525 parts contributed by Rafael Carre. Includes the start (but is still very incomplete) of an LCD driver for the e200v2. m200v2 is not yet fully supported by mkamsboot - that will come soon. Also some minor cleanups for the Clip.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18836 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/lcd-ssd1815.c')
-rw-r--r--firmware/target/arm/lcd-ssd1815.c333
1 files changed, 333 insertions, 0 deletions
diff --git a/firmware/target/arm/lcd-ssd1815.c b/firmware/target/arm/lcd-ssd1815.c
new file mode 100644
index 0000000000..fc3db940ba
--- /dev/null
+++ b/firmware/target/arm/lcd-ssd1815.c
@@ -0,0 +1,333 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22
23#include "hwcompat.h"
24#include "kernel.h"
25#include "lcd.h"
26#include "system.h"
27#include "cpu.h"
28
29/*** definitions ***/
30
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)
58
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 */
66
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 */
70
71
72#if CONFIG_CPU == AS3525
73#include "as3525.h"
74
75void lcd_write_command(int byte)
76{
77 DBOP_TIMPOL_23 = 0x6006E;
78 DBOP_DOUT = byte;
79
80 /* While push fifo is not empty */
81 while ((DBOP_STAT & (1<<10)) == 0)
82 ;
83
84 DBOP_TIMPOL_23 = 0x6E06F;
85}
86
87void lcd_write_data(const fb_data* p_bytes, int count)
88{
89 while (count--)
90 {
91 /* Write pixels */
92 DBOP_DOUT = *p_bytes++;
93
94 /* While push fifo is not empty */
95 while ((DBOP_STAT & (1<<10)) == 0)
96 ;
97 }
98}
99
100static inline void ams3525_dbop_init(void)
101{
102 int clkdiv = 4 - 1;
103
104 CGU_DBOP |= (1<<3) /* clk enable */ | clkdiv /* clkdiv: 3 bits */ ;
105
106 GPIOB_AFSEL = 0x0f; /* DBOP on pin 3:0 */
107 GPIOC_AFSEL = 0xff; /* DBOP on pins 7:0 */
108
109 DBOP_CTRL = 0x50008;
110 DBOP_TIMPOL_01 = 0xA167E167;
111 DBOP_TIMPOL_23 = 0x6E06F; /* this value is used for data (pixels) write */
112}
113
114
115/* LCD init, largely based on what OF does */
116void lcd_init_device(void)
117{
118 int delay;
119
120 ams3525_dbop_init();
121
122 GPIOB_DIR |= (1<<4);
123 GPIOD_DIR |= (1<<1)|(1<<3);
124
125 GPIOD_PIN(1) = (1<<1); /* backlight on */
126
127 GPIOD_PIN(3) = (1<<3);
128 delay = 10; while(delay--) ;
129
130 GPIOB_PIN(4) = (1<<4);
131 delay = 10; while(delay--) ;
132
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}
143
144
145#elif defined(CPU_TCC77X)
146
147/* TCC77x specific defines */
148#define LCD_BASE 0x50000000
149#define LCD_CMD *(volatile unsigned char*)(LCD_BASE)
150#define LCD_DATA *(volatile unsigned char*)(LCD_BASE+1)
151
152void lcd_write_command(int byte)
153{
154 LCD_CMD = byte;
155
156 asm volatile (
157 "nop \n\t"
158 "nop \n\t"
159 "nop \n\t"
160 );
161}
162
163void lcd_write_data(const fb_data* p_bytes, int count)
164{
165 while (count--)
166 {
167 LCD_DATA = *(p_bytes++);
168
169 asm volatile (
170 "nop \n\t"
171 "nop \n\t"
172 "nop \n\t"
173 );
174 }
175}
176
177/* LCD init */
178void lcd_init_device(void)
179{
180 uint32_t bus_width;
181
182 /* Telechips init the same as the original firmware */
183 CSCFG1 &= 0xc3ffc000;
184 CSCFG1 |= 0x3400101a;
185 CSCFG1 |= (1 << 21);
186 CSCFG1 &= ~(1 << 21);
187
188 bus_width = ((MCFG >> 11) & 0x3) ^ 3;
189
190 CSCFG1 = (bus_width << 28) |
191 (3 << 26) | /* MTYPE = 3 */
192 ((LCD_BASE >> 28) << 22) | /* CSBASE = 0x5 */
193 (1 << 20) | /* Unknown */
194 (3 << 11) | /* Setup time = 3 cycles */
195 (3 << 3) | /* Pulse width = 3+1 cycles */
196 (1 << 0); /* Hold time = 1 cycle */
197
198 /* SSD1815 inits like the original firmware */
199 lcd_write_command(LCD_SET_DISPLAY_OFF);
200 lcd_set_flip(false);
201 lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO | 5);
202 lcd_set_contrast(lcd_default_contrast());
203 lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER | 7);
204 /* power control register: op-amp=1, regulator=1, booster=1 */
205 lcd_write_command(LCD_SET_BIAS_TC_OSC);
206
207 /* 0xc2 = 110 000 10: Osc. Freq 110 - ???
208 TC value 000 - "-0.01%/C (TC0, POR)"
209 Bias ratio 10 - "1/9, 1/7 (POR)"
210 */
211 lcd_write_command(0xc2);
212 lcd_write_command(LCD_SET_DISPLAY_ON);
213
214 lcd_clear_display();
215 lcd_update();
216}
217
218/* End of TCC77x specific defines */
219#endif
220
221
222/** globals **/
223
224static int xoffset; /* needed for flip */
225
226/*** hardware configuration ***/
227
228int lcd_default_contrast(void)
229{
230 return 0x1f;
231}
232
233void lcd_set_contrast(int val)
234{
235 lcd_write_command(LCD_CNTL_CONTRAST);
236 lcd_write_command(val);
237}
238
239void lcd_set_invert_display(bool yesno)
240{
241 if (yesno)
242 lcd_write_command(LCD_SET_REVERSE_DISPLAY);
243 else
244 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
245}
246
247/* turn the display upside down (call lcd_update() afterwards) */
248void lcd_set_flip(bool yesno)
249{
250 (void)yesno;
251 /* TODO */
252}
253
254
255/*** Update functions ***/
256
257/* Performance function that works with an external buffer
258 note that by and bheight are in 8-pixel units! */
259void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
260 int bheight, int stride)
261{
262 /* Copy display bitmap to hardware */
263 while (bheight--)
264 {
265 lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf));
266 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset)>>4) & 0xf));
267 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
268
269 lcd_write_data(data, width);
270 data += stride;
271 }
272}
273
274
275/* Performance function that works with an external buffer
276 note that by and bheight are in 8-pixel units! */
277void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
278 int x, int by, int width, int bheight, int stride)
279{
280 (void)values;
281 (void)phases;
282 (void)x;
283 (void)by;
284 (void)width;
285 (void)bheight;
286 (void)stride;
287}
288
289/* Update the display.
290 This must be called after all other LCD functions that change the display. */
291void lcd_update(void) ICODE_ATTR;
292void lcd_update(void)
293{
294 int y;
295
296 /* Copy display bitmap to hardware */
297 for (y = 0; y < LCD_FBHEIGHT; y++)
298 {
299 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
300 lcd_write_command (LCD_CNTL_HIGHCOL | ((xoffset >> 4) & 0xf));
301 lcd_write_command (LCD_CNTL_LOWCOL | (xoffset & 0xf));
302
303 lcd_write_data (lcd_framebuffer[y], LCD_WIDTH);
304 }
305}
306
307/* Update a fraction of the display. */
308void lcd_update_rect(int, int, int, int) ICODE_ATTR;
309void lcd_update_rect(int x, int y, int width, int height)
310{
311 int ymax;
312
313 /* The Y coordinates have to work on even 8 pixel rows */
314 ymax = (y + height-1) >> 3;
315 y >>= 3;
316
317 if(x + width > LCD_WIDTH)
318 width = LCD_WIDTH - x;
319 if (width <= 0)
320 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
321 if(ymax >= LCD_FBHEIGHT)
322 ymax = LCD_FBHEIGHT-1;
323
324 /* Copy specified rectange bitmap to hardware */
325 for (; y <= ymax; y++)
326 {
327 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
328 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset) >> 4) & 0xf));
329 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
330
331 lcd_write_data (&lcd_framebuffer[y][x], width);
332 }
333}