lcd drivers: Convert lcd_[remote_]framebuffer to a pointer
[maemo-rb.git] / firmware / target / arm / lcd-ssd1815.c
blob891d4ef64d912406b736726e0be003f27284da60
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"
74 #include "clock-target.h"
76 void lcd_write_command(int byte)
78 DBOP_TIMPOL_23 = 0x6006E;
79 DBOP_DOUT = byte;
81 /* While push fifo is not empty */
82 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)
97 /* delay a bit. value arbitrary */
98 int i = 0;
99 while(i < 15)
100 i++;
104 static inline void ams3525_dbop_init(void)
106 CGU_DBOP |= (1<<3) | CLK_DIV(AS3525_PCLK_FREQ, AS3525_DBOP_FREQ);
108 GPIOB_AFSEL = 0x0f; /* DBOP on pin 3:0 */
109 GPIOC_AFSEL = 0xff; /* DBOP on pins 7:0 */
111 DBOP_CTRL = 0x50008;
112 DBOP_TIMPOL_01 = 0xA167E167;
113 DBOP_TIMPOL_23 = 0x6E06F; /* this value is used for data (pixels) write */
117 /* LCD init, largely based on what OF does */
118 void lcd_init_device(void)
120 int delay;
122 ams3525_dbop_init();
124 GPIOB_DIR |= (1<<4);
125 GPIOD_DIR |= (1<<1)|(1<<3);
127 GPIOD_PIN(1) = (1<<1); /* backlight on */
129 GPIOD_PIN(3) = (1<<3);
130 delay = 10; while(delay--) ;
132 GPIOB_PIN(4) = (1<<4);
133 delay = 10; while(delay--) ;
135 lcd_write_command(LCD_SET_LCD_BIAS);
136 lcd_write_command(LCD_SET_SEGMENT_REMAP);
137 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION);
138 lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO|0x5);
139 lcd_set_contrast(lcd_default_contrast());
140 lcd_write_command(LCD_SET_REVERSE_DISPLAY);
141 lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER|0x7);
142 lcd_write_command(LCD_SET_DISPLAY_ON);
143 lcd_write_command(LCD_SET_DISPLAY_START_LINE);
144 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
148 #elif defined(CPU_TCC77X)
150 /* TCC77x specific defines */
151 #define LCD_BASE 0x50000000
152 #define LCD_CMD *(volatile unsigned char*)(LCD_BASE)
153 #define LCD_DATA *(volatile unsigned char*)(LCD_BASE+1)
155 void lcd_write_command(int byte)
157 LCD_CMD = byte;
159 asm volatile (
160 "nop \n\t"
161 "nop \n\t"
162 "nop \n\t"
166 void lcd_write_data(const fb_data* p_bytes, int count)
168 while (count--)
170 LCD_DATA = *(p_bytes++);
172 asm volatile (
173 "nop \n\t"
174 "nop \n\t"
175 "nop \n\t"
180 /* LCD init */
181 void lcd_init_device(void)
183 uint32_t bus_width;
185 /* Telechips init the same as the original firmware */
186 CSCFG1 &= 0xc3ffc000;
187 CSCFG1 |= 0x3400101a;
188 CSCFG1 |= (1 << 21);
189 CSCFG1 &= ~(1 << 21);
191 bus_width = ((MCFG >> 11) & 0x3) ^ 3;
193 CSCFG1 = (bus_width << 28) |
194 (3 << 26) | /* MTYPE = 3 */
195 ((LCD_BASE >> 28) << 22) | /* CSBASE = 0x5 */
196 (1 << 20) | /* Unknown */
197 (3 << 11) | /* Setup time = 3 cycles */
198 (3 << 3) | /* Pulse width = 3+1 cycles */
199 (1 << 0); /* Hold time = 1 cycle */
201 /* SSD1815 inits like the original firmware */
202 lcd_write_command(LCD_SET_DISPLAY_OFF);
203 lcd_set_flip(false);
204 lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO | 5);
205 lcd_set_contrast(lcd_default_contrast());
206 lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER | 7);
207 /* power control register: op-amp=1, regulator=1, booster=1 */
208 lcd_write_command(LCD_SET_BIAS_TC_OSC);
210 /* 0xc2 = 110 000 10: Osc. Freq 110 - ???
211 TC value 000 - "-0.01%/C (TC0, POR)"
212 Bias ratio 10 - "1/9, 1/7 (POR)"
214 lcd_write_command(0xc2);
215 lcd_write_command(LCD_SET_DISPLAY_ON);
217 lcd_clear_display();
218 lcd_update();
221 /* End of TCC77x specific defines */
222 #endif
225 /** globals **/
227 static int xoffset; /* needed for flip */
229 /*** hardware configuration ***/
231 int lcd_default_contrast(void)
233 return 0x1f;
236 void lcd_set_contrast(int val)
238 lcd_write_command(LCD_CNTL_CONTRAST);
239 lcd_write_command(val);
242 void lcd_set_invert_display(bool yesno)
244 if (yesno)
245 lcd_write_command(LCD_SET_REVERSE_DISPLAY);
246 else
247 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
250 /* turn the display upside down (call lcd_update() afterwards) */
251 void lcd_set_flip(bool yesno)
253 (void)yesno;
254 /* TODO */
258 /*** Update functions ***/
260 /* Performance function that works with an external buffer
261 note that by and bheight are in 8-pixel units! */
262 void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
263 int bheight, int stride)
265 /* Copy display bitmap to hardware */
266 while (bheight--)
268 lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf));
269 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset)>>4) & 0xf));
270 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
272 lcd_write_data(data, width);
273 data += stride;
278 /* Performance function that works with an external buffer
279 note that by and bheight are in 8-pixel units! */
280 void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
281 int x, int by, int width, int bheight, int stride)
283 (void)values;
284 (void)phases;
285 (void)x;
286 (void)by;
287 (void)width;
288 (void)bheight;
289 (void)stride;
292 /* Update the display.
293 This must be called after all other LCD functions that change the display. */
294 void lcd_update(void) ICODE_ATTR;
295 void lcd_update(void)
297 int y;
299 /* Copy display bitmap to hardware */
300 for (y = 0; y < LCD_FBHEIGHT; y++)
302 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
303 lcd_write_command (LCD_CNTL_HIGHCOL | ((xoffset >> 4) & 0xf));
304 lcd_write_command (LCD_CNTL_LOWCOL | (xoffset & 0xf));
306 lcd_write_data (FBADDR(0, y), LCD_WIDTH);
310 /* Update a fraction of the display. */
311 void lcd_update_rect(int, int, int, int) ICODE_ATTR;
312 void lcd_update_rect(int x, int y, int width, int height)
314 int ymax;
316 /* The Y coordinates have to work on even 8 pixel rows */
317 ymax = (y + height-1) >> 3;
318 y >>= 3;
320 if(x + width > LCD_WIDTH)
321 width = LCD_WIDTH - x;
322 if (width <= 0)
323 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
324 if(ymax >= LCD_FBHEIGHT)
325 ymax = LCD_FBHEIGHT-1;
327 /* Copy specified rectange bitmap to hardware */
328 for (; y <= ymax; y++)
330 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
331 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset) >> 4) & 0xf));
332 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
334 lcd_write_data (FBADDR(x,y), width);