lcd now shows things on the old-style Meizu M3.
[kugel-rb.git] / firmware / target / arm / s5l8700 / meizu-m3 / lcd-m3.c
blob88147e9b16c13c55ee2328b89c9d89ce09d68c51
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 ***/
34 /** globals **/
35 static uint8_t lcd_type;
36 static int xoffset; /* needed for flip */
38 /*** hardware configuration ***/
40 int lcd_default_contrast(void)
42 return 0x1f;
45 void lcd_set_contrast(int val)
49 void lcd_set_invert_display(bool yesno)
53 /* turn the display upside down (call lcd_update() afterwards) */
54 void lcd_set_flip(bool yesno)
56 /* TODO: flip mode isn't working. The commands in the else part of
57 this function are how the original firmware inits the LCD */
59 if (yesno)
61 xoffset = 132 - LCD_WIDTH; /* 132 colums minus the 128 we have */
63 else
65 xoffset = 0;
69 static void lcd_sleep(uint32_t t)
71 volatile uint32_t i;
72 for(i=0;i<t;++i) t=t;
75 static uint8_t lcd_readdata()
77 LCD_RDATA = 0;
78 lcd_sleep(64);
79 return (LCD_DBUFF/* & 0xff*/);
82 static void lcd_writereg(uint32_t reg, uint32_t data)
84 LCD_WCMD = reg >> 8;
85 LCD_WCMD = reg & 0xff;
86 LCD_WDATA = data >> 8;
87 LCD_WDATA = data & 0xff;
90 void lcd_on() {
91 if (lcd_type == 1) {
92 LCD_WCMD = 0x29;
93 } else {
94 lcd_writereg(0x7, 0x21);
95 lcd_writereg(0x12, 0x137);
96 lcd_sleep(70000);
97 lcd_writereg(0x7, 0x21);
98 lcd_writereg(0x12, 0x1137);
99 lcd_sleep(70000);
100 lcd_writereg(0x7, 0x233);
104 void lcd_off() {
105 /* FIXME wait for DMA to finnish */
106 if (lcd_type == 1) {
107 LCD_WCMD = 0x28;
108 LCD_WDATA = 0;
109 } else {
114 /* LCD init */
115 void lcd_init_device(void)
117 uint8_t data[5];
119 /* init basic things */
120 PWRCON &= ~0x800;
121 PCON_ASRAM = 0x2;
122 PCON7 = 0x12222233;
124 LCD_CON = 0xca0;
125 LCD_PHTIME = 0;
126 LCD_INTCON = 0;
127 LCD_RST_TIME = 0x7ff;
129 /* detect lcd type */
130 LCD_WCMD = 0x1;
131 lcd_sleep(16667);
132 LCD_WCMD = 0x11;
133 lcd_sleep(20000);
134 lcd_readdata();
135 LCD_WCMD = 0x4;
136 lcd_sleep(100);
137 data[0]=lcd_readdata();
138 data[1]=lcd_readdata();
139 data[2]=lcd_readdata();
140 data[3]=lcd_readdata();
141 data[4]=lcd_readdata();
143 lcd_type=0;
144 if (((data[1]==0x38) && ((data[2] & 0xf0) == 0x80)) ||
145 ((data[2]==0x38) && ((data[3] & 0xf0) == 0x80)))
146 lcd_type=1;
148 /* init lcd */
149 if (lcd_type == 1) {
150 LCD_WCMD = 0x3a;
151 LCD_WDATA = 0x6;
152 LCD_WCMD = 0xab;
153 LCD_WCMD = 0x35;
154 LCD_WDATA = 0;
155 LCD_WCMD=0x13;
156 LCD_WCMD = 0x2a;
157 LCD_WDATA = 0;
158 LCD_WDATA = 0;
159 LCD_WCMD = 0x2b;
160 LCD_WDATA = 0;
161 LCD_WDATA = 0;
162 LCD_WCMD = 0x29;
163 } else {
164 LCD_WCMD = 0x0;
165 LCD_WCMD = 0x0;
166 LCD_WCMD = 0x0;
167 LCD_WCMD = 0x0;
168 lcd_sleep(7000);
169 lcd_writereg(0xa4, 0x1);
170 lcd_sleep(11000);
171 lcd_writereg(0x1, 0x100);
172 lcd_writereg(0x2, 0x300);
173 lcd_writereg(0x3, 0x9230);
174 lcd_writereg(0x8, 0x404);
175 lcd_writereg(0xe, 0x10);
176 lcd_writereg(0x70, 0x1000);
177 lcd_writereg(0x71, 0x1);
178 lcd_writereg(0x30, 0x2);
179 lcd_writereg(0x31, 0x400);
180 lcd_writereg(0x32, 0x7);
181 lcd_writereg(0x33, 0x500);
182 lcd_writereg(0x34, 0x7);
183 lcd_writereg(0x35, 0x703);
184 lcd_writereg(0x36, 0x507);
185 lcd_writereg(0x37, 0x5);
186 lcd_writereg(0x38, 0x1404);
187 lcd_writereg(0x39, 0xe);
188 lcd_writereg(0x40, 0x202);
189 lcd_writereg(0x41, 0x3);
190 lcd_writereg(0x42, 0x0);
191 lcd_writereg(0x43, 0x200);
192 lcd_writereg(0x44, 0x707);
193 lcd_writereg(0x45, 0x407);
194 lcd_writereg(0x46, 0x505);
195 lcd_writereg(0x47, 0x2);
196 lcd_writereg(0x48, 0x4);
197 lcd_writereg(0x49, 0x4);
198 lcd_writereg(0x60, 0x202);
199 lcd_writereg(0x61, 0x3);
200 lcd_writereg(0x62, 0x0);
201 lcd_writereg(0x63, 0x200);
202 lcd_writereg(0x64, 0x707);
203 lcd_writereg(0x65, 0x407);
204 lcd_writereg(0x66, 0x505);
205 lcd_writereg(0x67, 0x2);
206 lcd_writereg(0x68, 0x4);
207 lcd_writereg(0x69, 0x4);
208 lcd_writereg(0x7, 0x1);
209 lcd_writereg(0x18, 0x1);
210 lcd_writereg(0x10, 0x1690);
211 lcd_writereg(0x11, 0x100);
212 lcd_writereg(0x12, 0x117);
213 lcd_writereg(0x13, 0xf80);
214 lcd_writereg(0x12, 0x137);
215 lcd_writereg(0x20, 0x0);
216 lcd_writereg(0x21, 0x0);
217 lcd_writereg(0x50, 0x0);
218 lcd_writereg(0x51, 0xaf);
219 lcd_writereg(0x52, 0x0);
220 lcd_writereg(0x53, 0x83);
221 lcd_writereg(0x90, 0x0);
222 lcd_writereg(0x91, 0x0);
223 lcd_writereg(0x92, 0x0);
224 lcd_writereg(0x98, 0x0);
225 lcd_writereg(0x99, 0x903);
226 lcd_writereg(0x9a, 0x502);
227 lcd_writereg(0x9b, 0x300);
228 LCD_WCMD = 0x0;
229 LCD_WCMD = 0x22;
230 lcd_sleep(7000);
231 lcd_on();
235 /*** Update functions ***/
237 /* Performance function that works with an external buffer
238 note that by and bheight are in 8-pixel units! */
239 void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
240 int bheight, int stride)
242 /* Copy display bitmap to hardware */
243 while (bheight--)
249 /* Performance function that works with an external buffer
250 note that by and bheight are in 8-pixel units! */
251 void lcd_blit_grey_phase_blit(unsigned char *values, unsigned char *phases,
252 int x, int by, int width, int bheight, int stride)
254 (void)values;
255 (void)phases;
256 (void)x;
257 (void)by;
258 (void)width;
259 (void)bheight;
260 (void)stride;
263 /* Update the display.
264 This must be called after all other LCD functions that change the display. */
265 void lcd_update(void) ICODE_ATTR;
266 void lcd_update(void)
268 int i;
269 fb_data *p;
271 /* Copy display bitmap to hardware */
272 if (lcd_type == 1) {
273 LCD_WCMD = 0x2a;
274 LCD_WDATA = 0;
275 LCD_WDATA = 0;
276 LCD_WDATA = 0;
277 LCD_WDATA = 0xaf;
278 LCD_WCMD = 0x2b;
279 LCD_WDATA = 0;
280 LCD_WDATA = 0;
281 LCD_WDATA = 0;
282 LCD_WDATA = 0x83;
283 LCD_WCMD = 0x2c;
284 } else {
285 lcd_writereg(0x20, 0x0);
286 lcd_writereg(0x21, 0x0);
287 LCD_WCMD = 0;
288 LCD_WCMD = 0x22;
290 for(p=&lcd_framebuffer[0][0], i=0;i<LCD_WIDTH*LCD_FBHEIGHT;++i, ++p) {
291 LCD_WDATA = RGB_UNPACK_RED(*p)<<3;
292 LCD_WDATA = RGB_UNPACK_GREEN(*p)<<2;
293 LCD_WDATA = RGB_UNPACK_BLUE(*p)<<3;
294 lcd_sleep(1); /* if data is sent too fast to lcdif, machine freezes */
298 /* Update a fraction of the display. */
299 void lcd_update_rect(int, int, int, int) ICODE_ATTR;
300 void lcd_update_rect(int x, int y, int width, int height)
302 lcd_update();