lcd drivers: Convert lcd_[remote_]framebuffer to a pointer
[maemo-rb.git] / firmware / target / arm / s5l8700 / meizu-m3 / lcd-m3.c
blob5ed6c752b71fe8abb6237b928bec31f970a05140
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Denes Balatoni
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"
28 #include "inttypes.h"
29 #include "s5l8700.h"
31 /*** definitions ***/
32 #define STAT_BUS_IDLE (1<<8) /* Data bus idle */
33 #define STAT_FULL (1<<4) /* FIFO full */
34 #define STAT_READON (1<<0) /* Read operation done */
36 /** globals **/
37 static uint8_t lcd_type;
38 static int xoffset; /* needed for flip */
40 /*** hardware configuration ***/
42 int lcd_default_contrast(void)
44 return 0x1f;
47 void lcd_set_contrast(int val)
51 void lcd_set_invert_display(bool yesno)
55 /* turn the display upside down (call lcd_update() afterwards) */
56 void lcd_set_flip(bool yesno)
58 /* TODO: flip mode isn't working. The commands in the else part of
59 this function are how the original firmware inits the LCD */
61 if (yesno)
63 xoffset = 132 - LCD_WIDTH; /* 132 colums minus the 128 we have */
65 else
67 xoffset = 0;
71 static void lcd_sleep(uint32_t t)
73 volatile uint32_t i;
74 for(i=0;i<t;++i);
77 static uint8_t lcd_readdata(void)
79 LCD_RDATA = 0;
80 lcd_sleep(64);
81 return (LCD_DBUFF/* & 0xff*/);
84 static void lcd_writereg(uint32_t reg, uint32_t data)
86 while (LCD_STATUS & STAT_FULL);
87 LCD_WCMD = reg >> 8;
88 while (LCD_STATUS & STAT_FULL);
89 LCD_WCMD = reg & 0xff;
90 while (LCD_STATUS & STAT_FULL);
91 LCD_WDATA = data >> 8;
92 while (LCD_STATUS & STAT_FULL);
93 LCD_WDATA = data & 0xff;
96 void lcd_on(void) {
97 if (lcd_type == 1) {
98 LCD_WCMD = 0x29;
99 } else {
100 lcd_writereg(0x7, 0x21);
101 lcd_writereg(0x12, 0x137);
102 lcd_sleep(70000);
103 lcd_writereg(0x7, 0x21);
104 lcd_writereg(0x12, 0x1137);
105 lcd_sleep(700000);
106 lcd_writereg(0x7, 0x233);
110 void lcd_off(void) {
111 /* FIXME wait for DMA to finnish */
112 if (lcd_type == 1) {
113 LCD_WCMD = 0x28;
114 LCD_WDATA = 0;
115 } else {
120 /* LCD init */
121 void lcd_init_device(void)
123 uint8_t data[5];
124 int i;
126 /* init basic things */
127 PWRCON &= ~0x800;
128 PCON_ASRAM = 0x2;
129 PCON7 = 0x12222233;
131 LCD_CON = 0xca0;
132 LCD_PHTIME = 0;
133 LCD_INTCON = 0;
134 LCD_RST_TIME = 0x7ff;
136 /* detect lcd type, it's not detected the first time for some reason */
137 for(i=0;i<3;++i) {
138 LCD_WCMD = 0x1;
139 lcd_sleep(166670);
140 LCD_WCMD = 0x11;
141 lcd_sleep(2000040);
142 lcd_readdata();
143 LCD_WCMD = 0x4;
144 lcd_sleep(100);
145 data[0]=lcd_readdata();
146 data[1]=lcd_readdata();
147 data[2]=lcd_readdata();
148 data[3]=lcd_readdata();
149 data[4]=lcd_readdata();
151 lcd_type=0;
152 if (((data[1]==0x38) && ((data[2] & 0xf0) == 0x80)) ||
153 ((data[2]==0x38) && ((data[3] & 0xf0) == 0x80)))
154 lcd_type=1;
156 /* init lcd */
157 if (lcd_type == 1) {
158 LCD_WCMD = 0x3a;
159 LCD_WDATA = 0x6;
160 LCD_WCMD = 0xab;
161 LCD_WCMD = 0x35;
162 LCD_WDATA = 0;
163 LCD_WCMD=0x13;
164 LCD_WCMD = 0x2a;
165 LCD_WDATA = 0;
166 LCD_WDATA = 0;
167 LCD_WCMD = 0x2b;
168 LCD_WDATA = 0;
169 LCD_WDATA = 0;
170 LCD_WCMD = 0x29;
171 } else {
172 LCD_WCMD = 0x0;
173 LCD_WCMD = 0x0;
174 LCD_WCMD = 0x0;
175 LCD_WCMD = 0x0;
176 lcd_sleep(700000);
177 lcd_writereg(0xa4, 0x1);
178 lcd_sleep(1100000);
179 lcd_writereg(0x1, 0x100);
180 lcd_writereg(0x2, 0x300);
181 lcd_writereg(0x3, 0x9230);
182 lcd_writereg(0x8, 0x404);
183 lcd_writereg(0xe, 0x10);
184 lcd_writereg(0x70, 0x1000);
185 lcd_writereg(0x71, 0x1);
186 lcd_writereg(0x30, 0x2);
187 lcd_writereg(0x31, 0x400);
188 lcd_writereg(0x32, 0x7);
189 lcd_writereg(0x33, 0x500);
190 lcd_writereg(0x34, 0x7);
191 lcd_writereg(0x35, 0x703);
192 lcd_writereg(0x36, 0x507);
193 lcd_writereg(0x37, 0x5);
194 lcd_writereg(0x38, 0x1404);
195 lcd_writereg(0x39, 0xe);
196 lcd_writereg(0x40, 0x202);
197 lcd_writereg(0x41, 0x3);
198 lcd_writereg(0x42, 0x0);
199 lcd_writereg(0x43, 0x200);
200 lcd_writereg(0x44, 0x707);
201 lcd_writereg(0x45, 0x407);
202 lcd_writereg(0x46, 0x505);
203 lcd_writereg(0x47, 0x2);
204 lcd_writereg(0x48, 0x4);
205 lcd_writereg(0x49, 0x4);
206 lcd_writereg(0x60, 0x202);
207 lcd_writereg(0x61, 0x3);
208 lcd_writereg(0x62, 0x0);
209 lcd_writereg(0x63, 0x200);
210 lcd_writereg(0x64, 0x707);
211 lcd_writereg(0x65, 0x407);
212 lcd_writereg(0x66, 0x505);
213 lcd_writereg(0x67, 0x2);
214 lcd_writereg(0x68, 0x4);
215 lcd_writereg(0x69, 0x4);
216 lcd_writereg(0x7, 0x1);
217 lcd_writereg(0x18, 0x1);
218 lcd_writereg(0x10, 0x1690);
219 lcd_writereg(0x11, 0x100);
220 lcd_writereg(0x12, 0x117);
221 lcd_writereg(0x13, 0xf80);
222 lcd_writereg(0x12, 0x137);
223 lcd_writereg(0x20, 0x0);
224 lcd_writereg(0x21, 0x0);
225 lcd_writereg(0x50, 0x0);
226 lcd_writereg(0x51, 0xaf);
227 lcd_writereg(0x52, 0x0);
228 lcd_writereg(0x53, 0x83);
229 lcd_writereg(0x90, 0x0);
230 lcd_writereg(0x91, 0x0);
231 lcd_writereg(0x92, 0x0);
232 lcd_writereg(0x98, 0x0);
233 lcd_writereg(0x99, 0x903);
234 lcd_writereg(0x9a, 0x502);
235 lcd_writereg(0x9b, 0x300);
236 LCD_WCMD = 0x0;
237 LCD_WCMD = 0x22;
238 lcd_sleep(700000);
239 lcd_on();
243 /*** Update functions ***/
245 /* Performance function that works with an external buffer
246 note that by and bheight are in 8-pixel units! */
247 void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
248 int bheight, int stride)
250 /* Copy display bitmap to hardware */
251 while (bheight--)
257 /* Performance function that works with an external buffer
258 note that by and bheight are in 8-pixel units! */
259 void lcd_blit_grey_phase_blit(unsigned char *values, unsigned char *phases,
260 int x, int by, int width, int bheight, int stride)
262 (void)values;
263 (void)phases;
264 (void)x;
265 (void)by;
266 (void)width;
267 (void)bheight;
268 (void)stride;
271 /* Update the display.
272 This must be called after all other LCD functions that change the display. */
273 void lcd_update(void) ICODE_ATTR;
274 void lcd_update(void)
276 int i;
277 fb_data *p;
279 /* Copy display bitmap to hardware */
280 if (lcd_type == 1) {
281 LCD_WCMD = 0x2a;
282 LCD_WDATA = 0;
283 LCD_WDATA = 0;
284 LCD_WDATA = 0;
285 LCD_WDATA = 0xaf;
286 LCD_WCMD = 0x2b;
287 LCD_WDATA = 0;
288 LCD_WDATA = 0;
289 LCD_WDATA = 0;
290 LCD_WDATA = 0x83;
291 LCD_WCMD = 0x2c;
292 } else {
293 lcd_writereg(0x20, 0x0);
294 lcd_writereg(0x21, 0x0);
295 LCD_WCMD = 0;
296 LCD_WCMD = 0x22;
298 for(p=FBADDR(0,0), i=0;i<LCD_WIDTH*LCD_FBHEIGHT;++i, ++p) {
299 while (LCD_STATUS & STAT_FULL);
300 LCD_WDATA = RGB_UNPACK_RED(*p);
301 while (LCD_STATUS & STAT_FULL);
302 LCD_WDATA = RGB_UNPACK_GREEN(*p);
303 while (LCD_STATUS & STAT_FULL);
304 LCD_WDATA = RGB_UNPACK_BLUE(*p);
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 lcd_update();
315 void lcd_blit_yuv(unsigned char * const src[3],
316 int src_x, int src_y, int stride,
317 int x, int y, int width, int height)
319 /* stub */