tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / video / sprdfb / lcd / lcd_hx8363_mcu.c
1 /*
2  * Copyright (C) 2012 Spreadtrum Communications Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/delay.h>
16 #include "../sprdfb_panel.h"
17
18
19 static int32_t hx8363_init(struct panel_spec *self)
20 {
21         send_data_t send_cmd = self->info.mcu->ops->send_cmd;
22         send_data_t send_data = self->info.mcu->ops->send_data;
23
24         printk("hx8363_init\n");
25
26         send_cmd(0xB9); // SET password
27         send_data(0xFF); // 
28         send_data(0x83); // 
29         send_data(0x63); // 
30
31         send_cmd(0xB0);//Enable internal oscillator
32         send_data(0x01);
33         send_data(0x0B);
34
35         send_cmd(0xB1);
36         send_data(0x01);
37         send_data(0x00);
38         send_data(0x44);
39         send_data(0x08);
40         send_data(0x01);
41         send_data(0x11);
42         send_data(0x11);
43         send_data(0x36);
44         send_data(0x3E);
45         send_data(0x3F);
46         send_data(0x3F);
47         send_data(0x40);
48         send_data(0x32);
49         send_data(0x00);
50         send_data(0xE6);
51         send_data(0xE6);
52         send_data(0xE6);
53         send_data(0xE6);
54         send_data(0xE6);
55
56         send_cmd(0xB2); // SET DISP
57         send_data(0x08); // 
58         send_data(0x00); // 
59
60         send_cmd(0xB4);
61         send_data(0x00);//Column inversion
62         send_data(0x18); 
63         send_data(0x9C);
64         send_data(0x08);
65         send_data(0x18);
66         send_data(0x04);
67         send_data(0x72);//72
68
69         send_cmd(0xB6);//Set_VCOM 
70         send_data(0x1B); 
71
72         send_cmd(0xCC);// SET Panel
73         send_data(0x01); //
74
75         LCD_DelayMS(5);
76
77         send_cmd(0xE0); // SET Gamma
78         send_data(0x00);
79         send_data(0x05);
80         send_data(0x07);
81         send_data(0x0C);
82         send_data(0x13);
83         send_data(0x2F);
84         send_data(0x0B);
85         send_data(0x1D);
86         send_data(0x86);
87         send_data(0x0D);
88         send_data(0x91);
89         send_data(0x16);
90         send_data(0x99);
91         send_data(0x16);
92         send_data(0x16);
93         send_data(0x09);
94         send_data(0x05);
95         send_data(0x00);
96         send_data(0x05);
97         send_data(0x07);
98         send_data(0x0C);
99         send_data(0x13);
100         send_data(0x2F);
101         send_data(0x0B);
102         send_data(0x1D);
103         send_data(0x86);
104         send_data(0x0D);
105         send_data(0x91);
106         send_data(0x16);
107         send_data(0x99);
108         send_data(0x16);
109         send_data(0x16);
110         send_data(0x09);
111         send_data(0x05);
112
113         send_cmd(0xC1); //COLMOD 
114         send_data(0x01); // 
115         //R
116         send_data(0x07 );
117         send_data(0x0A );
118         send_data(0x1A );
119         send_data(0x2F );
120         send_data(0x3E );
121         send_data(0x4A );
122         send_data(0x52 );
123         send_data(0x5A );
124         send_data(0x62 );
125         send_data(0x69 );
126         send_data(0x70 );
127         send_data(0x76 );
128         send_data(0x7D );
129         send_data(0x82 );
130         send_data(0x86 );
131         send_data(0x8C );
132         send_data(0x93 );
133         send_data(0x9A );
134         send_data(0x9F );
135         send_data(0xA4 );
136         send_data(0xA9 );
137         send_data(0xB0 );
138         send_data(0xB6 );
139         send_data(0xBB );
140         send_data(0xC2 );
141         send_data(0xC9 );
142         send_data(0xCF );
143         send_data(0xD7 );
144         send_data(0xE0 );
145         send_data(0xE7 );
146         send_data(0xEF );
147         send_data(0xF8 );
148         send_data(0xFF );
149         send_data(0x34 );
150         send_data(0x1E );
151         send_data(0x92 );
152         send_data(0x9E );
153         send_data(0x01 );
154         send_data(0xE6 );
155         send_data(0x08 );
156         send_data(0x6F );
157         send_data(0x02 );
158         //G
159         send_data(0x07 );
160         send_data(0x0A );
161         send_data(0x1A );
162         send_data(0x2F );
163         send_data(0x3E );
164         send_data(0x4A );
165         send_data(0x52 );
166         send_data(0x5A );
167         send_data(0x62 );
168         send_data(0x69 );
169         send_data(0x70 );
170         send_data(0x76 );
171         send_data(0x7D );
172         send_data(0x82 );
173         send_data(0x86 );
174         send_data(0x8C );
175         send_data(0x93 );
176         send_data(0x9A );
177         send_data(0x9F );
178         send_data(0xA4 );
179         send_data(0xA9 );
180         send_data(0xB0 );
181         send_data(0xB6 );
182         send_data(0xBB );
183         send_data(0xC2 );
184         send_data(0xC9 );
185         send_data(0xCF );
186         send_data(0xD7 );
187         send_data(0xE0 );
188         send_data(0xE7 );
189         send_data(0xEF );
190         send_data(0xF8 );
191         send_data(0xFF );
192         send_data(0x34 );
193         send_data(0x1E );
194         send_data(0x92 );
195         send_data(0x9E );
196         send_data(0x01 );
197         send_data(0xE6 );
198         send_data(0x08 );
199         send_data(0x6F );
200         send_data(0x02 );
201         //B
202         send_data(0x07 );
203         send_data(0x0A );
204         send_data(0x1A );
205         send_data(0x2F );
206         send_data(0x3E );
207         send_data(0x4A );
208         send_data(0x52 );
209         send_data(0x5A );
210         send_data(0x62 );
211         send_data(0x69 );
212         send_data(0x70 );
213         send_data(0x76 );
214         send_data(0x7D );
215         send_data(0x82 );
216         send_data(0x86 );
217         send_data(0x8C );
218         send_data(0x93 );
219         send_data(0x9A );
220         send_data(0x9F );
221         send_data(0xA4 );
222         send_data(0xA9 );
223         send_data(0xB0 );
224         send_data(0xB6 );
225         send_data(0xBB );
226         send_data(0xC2 );
227         send_data(0xC9 );
228         send_data(0xCF );
229         send_data(0xD7 );
230         send_data(0xE0 );
231         send_data(0xE7 );
232         send_data(0xEF );
233         send_data(0xF8 );
234         send_data(0xFF );
235         send_data(0x34 );
236         send_data(0x1E );
237         send_data(0x92 );
238         send_data(0x9E );
239         send_data(0x01 );
240         send_data(0xE6 );
241         send_data(0x08 );
242         send_data(0x6F );
243         send_data(0x02 );
244
245         send_cmd(0x3A); //COLMOD 
246         send_data(0x07); // 
247
248         send_cmd(0x11);//Sleep Out 
249         LCD_DelayMS(120);
250
251         send_cmd(0xC2);// SET DISPIF 
252         send_data(0x04); //24bit 
253         send_cmd(0x35); //Tearing Effect 
254         send_data(0x00); // 
255         send_cmd(0x36);
256         send_data(0x02); // 
257         send_cmd(0x29); 
258         LCD_DelayMS(10);
259         send_cmd(0x2c);
260
261     return 0; 
262 }
263
264 static int32_t hx8363_enter_sleep(struct panel_spec *self, uint8_t is_sleep)
265 {
266         send_data_t send_cmd = self->info.mcu->ops->send_cmd;
267         send_data_t send_data = self->info.mcu->ops->send_data;
268
269         if(is_sleep==1){
270                 //Sleep In
271                 send_cmd(0x28);
272                 LCD_DelayMS(120); 
273                 send_cmd(0x10);
274                 LCD_DelayMS(120); 
275         }else{
276                 //Sleep Out
277                 send_cmd(0x11);
278                 LCD_DelayMS(120); 
279                 send_cmd(0x29);
280                 LCD_DelayMS(120); 
281         }
282
283         return 0;
284 }
285
286
287
288
289 static int32_t hx8363_set_window(struct panel_spec *self,
290                 uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
291 {
292         send_data_t send_cmd = self->info.mcu->ops->send_cmd;
293         send_data_t send_data = self->info.mcu->ops->send_data;
294         
295         pr_debug("hx8363_set_window: %d, %d, %d, %d\n",left, top, right, bottom);
296
297         send_cmd(0x2A); // col
298         send_data((left >> 8));
299         send_data((left & 0xFF));
300         send_data((right >> 8));
301         send_data((right & 0xFF));
302
303         send_cmd(0x2B); // row
304         send_data((top >> 8));
305         send_data((top & 0xFF));
306         send_data((bottom >> 8));
307         send_data((bottom & 0xFF));
308
309         send_cmd(0x2C); //Write data
310
311         return 0;
312 }
313 static int32_t hx8363_invalidate(struct panel_spec *self)
314 {
315         pr_debug("hx8363_invalidate\n");
316
317         return self->ops->panel_set_window(self, 0, 0,
318                 self->width - 1, self->height - 1);
319 }
320
321
322
323 static int32_t hx8363_invalidate_rect(struct panel_spec *self,
324                                 uint16_t left, uint16_t top,
325                                 uint16_t right, uint16_t bottom)
326 {
327         pr_debug("hx8363_invalidate_rect \n");
328
329         return self->ops->panel_set_window(self, left, top,
330                         right, bottom);
331 }
332
333 static int32_t hx8363_read_id(struct panel_spec *self)
334 {
335         int32_t id  = 0;
336         send_data_t send_cmd = self->info.mcu->ops->send_cmd;
337         read_data_t read_data = self->info.mcu->ops->read_data;
338         send_data_t send_data = self->info.mcu->ops->send_data;
339
340         //Get ID
341
342         
343         return 0x18; // id;
344 }
345
346 static struct panel_operations lcd_hx8363_mcu_operations = {
347         .panel_init = hx8363_init,
348         .panel_set_window = hx8363_set_window,
349         .panel_invalidate_rect= hx8363_invalidate_rect,
350         .panel_invalidate = hx8363_invalidate,
351         .panel_enter_sleep = hx8363_enter_sleep,
352         .panel_readid          = hx8363_read_id
353 };
354
355 static struct timing_mcu lcd_hx8363_mcu_timing[] = {
356 [MCU_LCD_REGISTER_TIMING] = {                    // read/write register timing
357                 .rcss = 15,  // 15ns
358                 .rlpw = 60,
359                 .rhpw = 60,
360                 .wcss = 10,
361                 .wlpw = 35,
362                 .whpw = 35,
363         },
364 [MCU_LCD_GRAM_TIMING] = {                    // read/write gram timing
365                 .rcss = 15,  // 15ns
366                 .rlpw = 60,
367                 .rhpw = 60,
368                 .wcss = 0,
369                 .wlpw = 16,
370                 .whpw = 16,
371         },
372 };
373
374 static struct info_mcu lcd_hx8363_mcu_info = {
375         .bus_mode = LCD_BUS_8080,
376         .bus_width = 24,
377         .bpp = 24,
378         .timing =lcd_hx8363_mcu_timing,
379         .ops = NULL,
380 };
381
382 struct panel_spec lcd_hx8363_mcu_spec = {
383         .width = 480,
384         .height = 854,
385         .type = LCD_MODE_MCU,
386         .direction = LCD_DIRECT_NORMAL,
387         .info = {
388                 .mcu = &lcd_hx8363_mcu_info
389         },
390         .ops = &lcd_hx8363_mcu_operations,
391 };
392
393 struct panel_cfg lcd_hx8363_mcu = {
394         /* this panel may on both CS0/1 */
395         .dev_id = SPRDFB_UNDEFINELCD_ID,
396         .lcd_id = 0x18,
397         .lcd_name = "lcd_hx8363_mcu",
398         .panel = &lcd_hx8363_mcu_spec,
399 };
400
401 static int __init lcd_hx8363_mcu_init(void)
402 {
403         return sprdfb_panel_register(&lcd_hx8363_mcu);
404 }
405
406 subsys_initcall(lcd_hx8363_mcu_init);