tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / video / lcd_ili9341_boe_mint.c
1 /* drivers/video/sc8810/lcd_ili9341s.c
2  *
3  * Support for ili9341s LCD device
4  *
5  * Copyright (C) 2010 Spreadtrum
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  */
16
17 #include <common.h>
18
19 #include <asm/arch/sc8810_lcd.h>
20 #define mdelay(a) udelay(a * 1000)
21 #define printk printf
22
23 #define  LCD_DEBUG
24 #ifdef LCD_DEBUG
25 #define LCD_PRINT printk
26 #else
27 #define LCD_PRINT(...)
28 #endif
29
30 static void __raw_bits_or(unsigned int v, unsigned int a)
31 {
32         __raw_writel((__raw_readl(a) | v), a);
33 }
34
35 static int32_t ili9486_init(struct lcd_spec *self)
36 {
37         Send_data send_cmd = self->info.mcu->ops->send_cmd;
38         Send_data send_data = self->info.mcu->ops->send_data;
39
40         LCD_PRINT("ili9486_init\n");
41
42         send_cmd(0xCF); 
43         send_data(0x00); 
44         send_data(0xF9); 
45         send_data(0x30); 
46
47         send_cmd(0xED); 
48         send_data(0x64); 
49         send_data(0x03); 
50         send_data(0x12); 
51         send_data(0x81); 
52
53         send_cmd(0xCB); 
54         send_data(0x39); 
55         send_data(0x2C); 
56         send_data(0x00); 
57         send_data(0x34); 
58         send_data(0x02); 
59
60         send_cmd(0xF7); 
61         send_data(0x20); 
62         
63         send_cmd(0xEA); 
64         send_data(0x00);  
65         send_data(0x00); 
66
67         send_cmd(0xC0); 
68         send_data(0x1D);  
69
70         send_cmd(0xC1); 
71         send_data(0x10);  
72
73         send_cmd(0xC5);
74         send_data(0x3C);//14
75         send_data(0x2A);//44
76
77         send_cmd( 0xC7); 
78         send_data(0x00);
79
80         send_cmd( 0xE8);
81         send_data( 0x85);
82         send_data( 0x00);       
83         send_data( 0x78);
84
85         send_cmd( 0x35);
86         send_data( 0x00);
87
88         send_cmd( 0x36); 
89 #ifdef CONFIG_MACH_MINT
90         send_data(0x08);
91 #else   
92         send_data( 0xD8);
93 #endif  
94
95         send_cmd( 0x3A); 
96         send_data( 0x05);//66
97
98         send_cmd( 0xB1);
99         send_data( 0x00);
100         send_data( 0x16);
101         
102         send_cmd( 0xB5);
103         send_data( 0x04);
104         send_data( 0x04);
105         send_data( 0x0A);
106         send_data( 0x14);
107
108         send_cmd( 0xB6); 
109         send_data( 0x0A);
110         send_data( 0xC2); 
111
112         send_cmd( 0xF6); 
113         send_data( 0x01);
114         send_data( 0x30); 
115         send_data( 0x00); 
116
117         send_cmd( 0xF2); 
118         send_data( 0x03);
119         
120         send_cmd( 0xE0); 
121         send_data( 0x0F);
122         send_data( 0x24);         
123         send_data( 0x20);
124         send_data( 0x0F);         
125         send_data( 0x0F);
126
127         send_data( 0x0B);         
128         send_data( 0x50);
129         send_data( 0xA4);         
130         send_data( 0x3E);
131         send_data( 0x06);
132
133         send_data( 0x10);
134         send_data( 0x01);
135         send_data( 0x1A);
136         send_data( 0x19);
137         send_data( 0x0F);
138
139         send_cmd( 0xE1); 
140         send_data(  0x00);
141         send_data(  0x18);        
142         send_data(  0x19);
143         send_data(  0x03);        
144         send_data(  0x0F);
145
146         send_data(  0x04);        
147         send_data(  0x31);
148         send_data(  0x53);        
149         send_data(  0x46);
150         send_data(  0x09);
151
152         send_data(  0x12);
153         send_data(  0x0F);
154         send_data(  0x26);
155         send_data(  0x2A);
156         send_data(  0x03);
157
158         send_cmd( 0xE2 ); 
159         send_data(  0x08);
160         send_data(  0x09);        
161         send_data(  0x09);
162         send_data(  0x09);        
163         send_data(  0x09);
164
165         send_data(  0x09);        
166         send_data(  0x09);
167         send_data(  0x09);        
168         send_data(  0x09);
169         send_data(  0x09);
170
171         send_data(  0x09);
172         send_data(  0x09);
173         send_data(  0x09);
174         send_data(  0x09);
175         send_data(  0x88);
176
177         send_data(  0x88);
178
179         send_cmd( 0xE3 ); 
180         send_data(  0x00);
181         send_data(  0x00);        
182         send_data(  0x00);
183         send_data(  0x00);        
184         send_data(  0x06);
185
186         send_data(  0x06);        
187         send_data(  0x07);
188         send_data(  0x03);        
189         send_data(  0x05);
190         send_data(  0x04);
191
192         send_data(  0x04);
193         send_data(  0x04);
194         send_data(  0x04);
195         send_data(  0x04);
196         send_data(  0x02);
197
198         send_data(  0x02);
199         send_data(  0x01);
200         send_data(  0x01);
201         send_data(  0x01);
202         send_data(  0x01);
203
204         send_data(  0x00);
205         send_data(  0x00);
206         send_data(  0x00);
207         send_data(  0x00);
208         send_data(  0x00);        
209
210         send_data(  0x00);
211         send_data(  0x00);
212         send_data(  0x00);
213         send_data(  0x00);
214         send_data(  0x00);
215
216         send_data(  0x00);
217         send_data(  0x00);
218         send_data(  0x00);
219         send_data(  0x00);
220         send_data(  0x00);
221
222         send_data(  0x00);
223         send_data(  0x00);
224         send_data(  0x00);
225         send_data(  0x00);
226         send_data(  0x00);
227
228         send_data(  0x00);
229         send_data(  0x00);
230         send_data(  0x00);
231         send_data(  0x00);
232         send_data(  0x00);
233
234         send_data(  0x00);
235         send_data(  0x00);
236         send_data(  0x00);
237         send_data(  0x00);
238         send_data(  0x00);
239
240         send_data(  0x00);
241         send_data(  0x00);
242         send_data(  0x00);
243         send_data(  0x00);
244         send_data(  0x00);
245
246         send_data(  0x00);
247         send_data(  0x80);
248         send_data(  0x80);
249         send_data(  0x80);
250         send_data(  0x80);
251
252         send_data(  0x82);
253         send_data(  0x82);
254         send_data(  0x82);
255         send_data(  0x82);
256
257        //Display on
258
259         send_cmd(0x11); // (SLPOUT)
260
261         mdelay(120); // 100ms
262
263         send_cmd(0x29); // (DISPON)
264
265         mdelay(100); // 100ms
266         
267         LCD_PRINT("ili9486_init: end\n");
268
269         return 0;
270 }
271
272 static int32_t ili9486_set_window(struct lcd_spec *self,
273                 uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
274 {
275         Send_data send_cmd = self->info.mcu->ops->send_cmd;
276         Send_data send_data = self->info.mcu->ops->send_data;
277
278         LCD_PRINT("ili9486_set_window\n");
279     
280         send_cmd(0x2A); // col
281         send_data((left >> 8));
282         send_data((left & 0xFF));
283         send_data((right >> 8));
284         send_data((right & 0xFF));
285
286         send_cmd(0x2B); // row
287         send_data((top >> 8));
288         send_data((top & 0xFF));
289         send_data((bottom >> 8));
290         send_data((bottom & 0xFF));
291         
292         send_cmd(0x2C); //Write data
293
294         return 0;
295 }
296
297
298 static int32_t ili9486_invalidate(struct lcd_spec *self)
299 {
300         LCD_PRINT("ili9486_invalidate\n");
301
302         return self->ops->lcd_set_window(self, 0, 0, 
303                         self->width-1, self->height-1);
304         
305 }
306
307 static int32_t ili9486_invalidate_rect(struct lcd_spec *self,
308                                 uint16_t left, uint16_t top,
309                                 uint16_t right, uint16_t bottom)
310 {
311         Send_data send_cmd = self->info.mcu->ops->send_cmd;
312         Send_data send_data = self->info.mcu->ops->send_data;
313
314         LCD_PRINT("ili9486_invalidate_rect : (%d, %d, %d, %d)\n",left, top, right, bottom);
315
316         //send_cmd(0x44); // TE scanline
317         //send_data((top >> 8));
318         //send_data((top & 0xFF));
319
320         return self->ops->lcd_set_window(self, left, top, 
321                         right, bottom);
322 }
323
324 static int32_t ili9486_set_direction(struct lcd_spec *self, uint16_t direction)
325 {
326
327         LCD_PRINT("ili9486_set_direction\n");
328         return 0;
329 }
330
331 static int32_t ili9486_enter_sleep(struct lcd_spec *self, uint8_t is_sleep)
332 {
333         Send_data send_cmd = self->info.mcu->ops->send_cmd;
334
335         if(is_sleep) {
336                 //send_cmd(0x10);
337                 mdelay(120); 
338         }
339         else {
340                 //send_cmd(0x11);
341                 mdelay(120); 
342         }
343         return 0;
344 }
345
346 static uint32_t ili9486_read_id(struct lcd_spec *self)
347 {
348         uint32_t read_value = 0;
349         Send_data send_cmd = self->info.mcu->ops->send_cmd;
350
351         Read_data read_data = self->info.mcu->ops->read_data;
352
353         return 0x60b4;
354         
355         send_cmd(0x04);
356
357         read_data(); 
358         read_value += read_data()<< 16;
359         read_value += read_data()<< 8;
360         read_value += read_data();
361   
362         return read_value; 
363 }
364
365 static struct lcd_operations lcd_ili9486_operations = {
366         .lcd_init            = ili9486_init,
367         .lcd_set_window      = ili9486_set_window,
368         .lcd_invalidate      = ili9486_invalidate,
369         .lcd_invalidate_rect = ili9486_invalidate_rect,
370         .lcd_set_direction   = ili9486_set_direction,
371         .lcd_enter_sleep     = ili9486_enter_sleep,
372         .lcd_readid          = ili9486_read_id,
373 };
374 #if 0
375 static struct timing_mcu lcd_ili9341s_timing = {
376         .rcss = 170,  // 25 ns
377         .rlpw = 50,
378         .rhpw = 100,
379         .wcss = 70,
380         .wlpw = 20,
381         .whpw = 20,
382 };
383 #endif
384 #ifdef CONFIG_MACH_MINT
385 static struct timing_mcu lcd_ili9486_timing[] = {
386 [LCD_REGISTER_TIMING] = {        
387         .rcss = 25,  // 25 ns
388         .rlpw = 45,
389         .rhpw = 90,
390         .wcss = 30,
391         .wlpw = 15,
392         .whpw = 15,
393 },
394 [LCD_GRAM_TIMING] = {        
395         .rcss = 25,  // 25 ns
396         .rlpw = 45,
397         .rhpw = 90,
398                 .wcss = 30,
399         .wlpw = 15,
400         .whpw = 15,
401 }
402
403 };
404 #else
405 static struct timing_mcu lcd_ili9486_timing[] = {
406 [LCD_REGISTER_TIMING] = {        
407         .rcss = 50,  // 25 ns
408         .rlpw = 90,
409         .rhpw = 180,
410         .wcss = 60,
411         .wlpw = 30,
412         .whpw = 30,
413 },
414 [LCD_GRAM_TIMING] = {        
415         .rcss = 50,  // 25 ns
416         .rlpw = 90,
417         .rhpw = 180,
418         .wcss = 60,
419         .wlpw = 30,
420         .whpw = 30,
421 }
422
423 };
424 #endif
425
426 static struct info_mcu lcd_ili9486_info = {
427         .bus_mode = LCD_BUS_8080,
428         .bus_width = 16,
429         .timing = &lcd_ili9486_timing,
430         .ops = NULL,
431 };
432
433 struct lcd_spec lcd_panel_ili9486 = {
434         .width = 240,
435         .height = 320,
436         .mode = LCD_MODE_MCU,
437         .direction = LCD_DIRECT_NORMAL,
438         .info = {.mcu = &lcd_ili9486_info},
439         .ops = &lcd_ili9486_operations,
440 };
441