tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / video / lcd_ili9341_boe.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 ili9341boe_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("ili9341boe_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         send_data( 0xD8);
90
91         send_cmd( 0x3A); 
92         send_data( 0x05);//66
93
94         send_cmd( 0xB1);
95         send_data( 0x00);
96         send_data( 0x16);
97         
98         send_cmd( 0xB5);
99         send_data( 0x04);
100         send_data( 0x04);
101         send_data( 0x0A);
102         send_data( 0x14);
103
104         send_cmd( 0xB6); 
105         send_data( 0x0A);
106         send_data( 0xC2); 
107
108         send_cmd( 0xF6); 
109         send_data( 0x01);
110         send_data( 0x30); 
111         send_data( 0x00); 
112
113         send_cmd( 0xF2); 
114         send_data( 0x03);
115         
116         send_cmd( 0xE0); 
117         send_data( 0x0F);
118         send_data( 0x24);         
119         send_data( 0x20);
120         send_data( 0x0F);         
121         send_data( 0x0F);
122
123         send_data( 0x0B);         
124         send_data( 0x50);
125         send_data( 0xA4);         
126         send_data( 0x3E);
127         send_data( 0x06);
128
129         send_data( 0x10);
130         send_data( 0x01);
131         send_data( 0x1A);
132         send_data( 0x19);
133         send_data( 0x0F);
134
135         send_cmd( 0xE1); 
136         send_data(  0x00);
137         send_data(  0x18);        
138         send_data(  0x19);
139         send_data(  0x03);        
140         send_data(  0x0F);
141
142         send_data(  0x04);        
143         send_data(  0x31);
144         send_data(  0x53);        
145         send_data(  0x46);
146         send_data(  0x09);
147
148         send_data(  0x12);
149         send_data(  0x0F);
150         send_data(  0x26);
151         send_data(  0x2A);
152         send_data(  0x03);
153
154         send_cmd( 0xE2 ); 
155         send_data(  0x08);
156         send_data(  0x09);        
157         send_data(  0x09);
158         send_data(  0x09);        
159         send_data(  0x09);
160
161         send_data(  0x09);        
162         send_data(  0x09);
163         send_data(  0x09);        
164         send_data(  0x09);
165         send_data(  0x09);
166
167         send_data(  0x09);
168         send_data(  0x09);
169         send_data(  0x09);
170         send_data(  0x09);
171         send_data(  0x88);
172
173         send_data(  0x88);
174
175         send_cmd( 0xE3 ); 
176         send_data(  0x00);
177         send_data(  0x00);        
178         send_data(  0x00);
179         send_data(  0x00);        
180         send_data(  0x06);
181
182         send_data(  0x06);        
183         send_data(  0x07);
184         send_data(  0x03);        
185         send_data(  0x05);
186         send_data(  0x04);
187
188         send_data(  0x04);
189         send_data(  0x04);
190         send_data(  0x04);
191         send_data(  0x04);
192         send_data(  0x02);
193
194         send_data(  0x02);
195         send_data(  0x01);
196         send_data(  0x01);
197         send_data(  0x01);
198         send_data(  0x01);
199
200         send_data(  0x00);
201         send_data(  0x00);
202         send_data(  0x00);
203         send_data(  0x00);
204         send_data(  0x00);        
205
206         send_data(  0x00);
207         send_data(  0x00);
208         send_data(  0x00);
209         send_data(  0x00);
210         send_data(  0x00);
211
212         send_data(  0x00);
213         send_data(  0x00);
214         send_data(  0x00);
215         send_data(  0x00);
216         send_data(  0x00);
217
218         send_data(  0x00);
219         send_data(  0x00);
220         send_data(  0x00);
221         send_data(  0x00);
222         send_data(  0x00);
223
224         send_data(  0x00);
225         send_data(  0x00);
226         send_data(  0x00);
227         send_data(  0x00);
228         send_data(  0x00);
229
230         send_data(  0x00);
231         send_data(  0x00);
232         send_data(  0x00);
233         send_data(  0x00);
234         send_data(  0x00);
235
236         send_data(  0x00);
237         send_data(  0x00);
238         send_data(  0x00);
239         send_data(  0x00);
240         send_data(  0x00);
241
242         send_data(  0x00);
243         send_data(  0x80);
244         send_data(  0x80);
245         send_data(  0x80);
246         send_data(  0x80);
247
248         send_data(  0x82);
249         send_data(  0x82);
250         send_data(  0x82);
251         send_data(  0x82);
252
253        //Display on
254
255         send_cmd(0x11); // (SLPOUT)
256
257         mdelay(120); // 100ms
258
259         send_cmd(0x29); // (DISPON)
260
261         mdelay(100); // 100ms
262         
263         LCD_PRINT("ili9341boe_init: end\n");
264
265         return 0;
266 }
267
268 static int32_t ili9341boe_set_window(struct lcd_spec *self,
269                 uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
270 {
271         Send_data send_cmd = self->info.mcu->ops->send_cmd;
272         Send_data send_data = self->info.mcu->ops->send_data;
273
274         LCD_PRINT("ili9341boe_set_window\n");
275     
276         send_cmd(0x2A); // col
277         send_data((left >> 8));
278         send_data((left & 0xFF));
279         send_data((right >> 8));
280         send_data((right & 0xFF));
281
282         send_cmd(0x2B); // row
283         send_data((top >> 8));
284         send_data((top & 0xFF));
285         send_data((bottom >> 8));
286         send_data((bottom & 0xFF));
287         
288         send_cmd(0x2C); //Write data
289
290         return 0;
291 }
292
293
294 static int32_t ili9341boe_invalidate(struct lcd_spec *self)
295 {
296         LCD_PRINT("ili9341boe_invalidate\n");
297
298         return self->ops->lcd_set_window(self, 0, 0, 
299                         self->width-1, self->height-1);
300         
301 }
302
303 static int32_t ili9341boe_invalidate_rect(struct lcd_spec *self,
304                                 uint16_t left, uint16_t top,
305                                 uint16_t right, uint16_t bottom)
306 {
307         Send_data send_cmd = self->info.mcu->ops->send_cmd;
308         Send_data send_data = self->info.mcu->ops->send_data;
309
310         LCD_PRINT("ili9341boe_invalidate_rect : (%d, %d, %d, %d)\n",left, top, right, bottom);
311
312         //send_cmd(0x44); // TE scanline
313         //send_data((top >> 8));
314         //send_data((top & 0xFF));
315
316         return self->ops->lcd_set_window(self, left, top, 
317                         right, bottom);
318 }
319
320 static int32_t ili9341boe_set_direction(struct lcd_spec *self, uint16_t direction)
321 {
322
323         LCD_PRINT("ili9341boe_set_direction\n");
324         return 0;
325 }
326
327 static int32_t ili9341boe_enter_sleep(struct lcd_spec *self, uint8_t is_sleep)
328 {
329         Send_data send_cmd = self->info.mcu->ops->send_cmd;
330
331         if(is_sleep) {
332                 //send_cmd(0x10);
333                 mdelay(120); 
334         }
335         else {
336                 //send_cmd(0x11);
337                 mdelay(120); 
338         }
339         return 0;
340 }
341
342 static uint32_t ili9341boe_read_id(struct lcd_spec *self)
343 {
344         uint32_t read_value = 0;
345         Send_data send_cmd = self->info.mcu->ops->send_cmd;
346
347         Read_data read_data = self->info.mcu->ops->read_data;
348
349         send_cmd(0x04);
350
351         read_data(); 
352         read_value += read_data()<< 16;
353         read_value += read_data()<< 8;
354         read_value += read_data();
355   
356         return read_value; 
357 }
358
359 static struct lcd_operations lcd_ili9341boe_operations = {
360         .lcd_init            = ili9341boe_init,
361         .lcd_set_window      = ili9341boe_set_window,
362         .lcd_invalidate      = ili9341boe_invalidate,
363         .lcd_invalidate_rect = ili9341boe_invalidate_rect,
364         .lcd_set_direction   = ili9341boe_set_direction,
365         .lcd_enter_sleep     = ili9341boe_enter_sleep,
366         .lcd_readid          = ili9341boe_read_id,
367 };
368 #if 0
369 static struct timing_mcu lcd_ili9341s_timing = {
370         .rcss = 170,  // 25 ns
371         .rlpw = 50,
372         .rhpw = 100,
373         .wcss = 70,
374         .wlpw = 20,
375         .whpw = 20,
376 };
377 #endif
378 #if 0
379 static struct timing_mcu lcd_ili9341boe_timing[] = {
380 [LCD_REGISTER_TIMING] = {        
381         .rcss = 25,  // 25 ns
382         .rlpw = 45,
383         .rhpw = 90,
384         .wcss = 30,
385         .wlpw = 15,
386         .whpw = 15,
387 },
388 [LCD_GRAM_TIMING] = {        
389         .rcss = 25,  // 25 ns
390         .rlpw = 45,
391         .rhpw = 90,
392                 .wcss = 30,
393         .wlpw = 15,
394         .whpw = 15,
395 }
396
397 };
398 #endif
399 static struct timing_mcu lcd_ili9341boe_timing[] = {
400 [LCD_REGISTER_TIMING] = {        
401         .rcss = 50,  // 25 ns
402         .rlpw = 90,
403         .rhpw = 180,
404         .wcss = 60,
405         .wlpw = 30,
406         .whpw = 30,
407 },
408 [LCD_GRAM_TIMING] = {        
409         .rcss = 50,  // 25 ns
410         .rlpw = 90,
411         .rhpw = 180,
412         .wcss = 60,
413         .wlpw = 30,
414         .whpw = 30,
415 }
416
417 };
418
419 static struct info_mcu lcd_ili9341boe_info = {
420         .bus_mode = LCD_BUS_8080,
421         .bus_width = 16,
422         .timing = &lcd_ili9341boe_timing,
423         .ops = NULL,
424 };
425
426 struct lcd_spec lcd_panel_ili9341boe = {
427         .width = 240,
428         .height = 320,
429         .mode = LCD_MODE_MCU,
430         .direction = LCD_DIRECT_NORMAL,
431         .info = {.mcu = &lcd_ili9341boe_info},
432         .ops = &lcd_ili9341boe_operations,
433 };
434