tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / drivers / video / lcd_hx8369.c
1 /* drivers/video/sc8810/lcd_hx8369.c
2  *
3  * Support for hx8369 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 <asm/arch/sc8810_lcd.h>
18
19 #define printk printf
20
21 //#define  LCD_DEBUG
22 #ifdef LCD_DEBUG
23 #define LCD_PRINT printk
24 #else
25 #define LCD_PRINT(...)
26 #endif
27
28 static int32_t hx8369_init(struct lcd_spec *self)
29 {
30         Send_data send_cmd = self->info.mcu->ops->send_cmd;
31         Send_data send_data = self->info.mcu->ops->send_data;
32
33         LCD_PRINT("hx8369_init\n");
34
35         send_cmd(0xB9); // SET password
36         send_data(0xFF);
37         send_data(0x83);
38         send_data(0x69);
39
40         send_cmd(0xB1);  //Set Power
41         send_data(0x9D);  //9D
42         send_data(0x00); //00
43         send_data(0x34); //34
44         send_data(0x07); //07
45         send_data(0x00); //00
46         send_data(0x0B); //0B
47         send_data(0x0B); //0B
48         send_data(0x1A); //1A
49         send_data(0x22); //22
50         send_data(0x3F); //3F
51         send_data(0x3F); //3F
52         send_data(0x01); //01
53         send_data(0x23); //23
54         send_data(0x01); //01
55         send_data(0xE6); //E6
56         send_data(0xE6); //E6
57         send_data(0xE6); //E6
58         send_data(0xE6); //E6
59         send_data(0xE6); //E6
60
61         send_cmd(0xB2);  // SET Display  480x800
62         send_data(0x00); //00
63         send_data(0x20);
64         send_data(0x03); //03
65         send_data(0x03); //03
66         send_data(0x70);
67         send_data(0x00);
68         send_data(0xFF);
69         send_data(0x00);
70         send_data(0x00);
71         send_data(0x00);
72         send_data(0x00);
73         send_data(0x03);
74         send_data(0x03);
75         send_data(0x00);
76         send_data(0x01);
77
78         send_cmd(0xB4);  // SET Display 480x800
79         send_data(0x00);
80         send_data(0x18);
81         send_data(0x80);
82         send_data(0x06);
83         send_data(0x02);
84
85         send_cmd(0xB0);//OSC
86         send_data(0x01);
87         send_data(0x09);//05   42HZ  07 50HZ  0B 100% 67HZ
88
89
90         send_cmd(0xB6);  // SET VCOM
91         send_data(0x4A);
92         send_data(0x4A);
93
94         send_cmd(0xD5);  // SET GIP
95         send_data(0x00);
96         send_data(0x03);
97         send_data(0x03);
98         send_data(0x00);
99         send_data(0x01);
100         send_data(0x02); //04
101
102         send_data(0x28);
103         send_data(0x70);
104         send_data(0x11);
105         send_data(0x13);
106         send_data(0x00);
107         send_data(0x00);
108         send_data(0x40);
109         send_data(0x06);
110         send_data(0x51);
111         send_data(0x07);
112         send_data(0x00);
113         send_data(0x00);
114         send_data(0x41);
115         send_data(0x06);
116         send_data(0x50);
117         send_data(0x07);
118         send_data(0x07);
119         send_data(0x0F);
120         send_data(0x04);
121         send_data(0x00);
122
123         send_cmd(0xE0);  // Set Gamma
124         send_data(0x00);
125         send_data(0x01);
126         send_data(0x04);
127         send_data(0x23);
128         send_data(0x22);
129         send_data(0x3F);
130         send_data(0x13);
131         send_data(0x39);
132         send_data(0x06);
133         send_data(0x0B);
134         send_data(0x0E);
135         send_data(0x12);
136         send_data(0x15);
137         send_data(0x13);
138         send_data(0x15);
139         send_data(0x13);
140         send_data(0x1B);
141         send_data(0x00);
142         send_data(0x01);
143         send_data(0x04);
144         send_data(0x23);
145         send_data(0x22);
146         send_data(0x3F);
147         send_data(0x13);
148         send_data(0x39);
149         send_data(0x06);
150         send_data(0x0B);
151         send_data(0x0E);
152         send_data(0x12);
153         send_data(0x15);
154         send_data(0x13);
155         send_data(0x15);
156         send_data(0x13);
157         send_data(0x1B);
158         send_cmd(0x35);   // TE on
159         send_data(0x00);
160         //send_cmd(0x34); // TE off
161
162         send_cmd(0x3A);   // set CSEL
163         send_data(0x07);  // CSEL=0x06, 16bit-color CSEL=0x06, 18bit-color CSEL=0x07, 24bit-color
164
165         /*
166         //16bit 65K
167                 send_cmd(0x2D);        //Look up table//
168         for(i=0;i<64;i++)
169                         send_data(8*i);//RED
170         for(i=0;i<64;i++)
171                         send_data(4*i);//Green
172         for(i=0;i<64;i++)
173                         send_data(8*i);//Blue
174         */
175
176         /*
177         //18bit 262K
178                 send_cmd(0x2D);        //Look up table//
179         for(i=0;i<64;i++)
180                         send_data(4*i);//RED
181         for(i=0;i<64;i++)
182                         send_data(4*i);//Green
183         for(i=0;i<64;i++)
184                         send_data(4*i);//Blue
185         */
186         //24 bit don't need to set 2DH
187
188         send_cmd(0x11); //Sleep Out
189         LCD_DelayMS(120); //120ms
190
191         if (0) { //  for test the lcd
192                 int i;
193                 send_cmd(0x2C); //Write data
194                 for (i = 0; i < 480*800/3; i++)
195                         send_data(0xff);
196                 for (i = 0; i < 480*800/3; i++)
197                         send_data(0xff00);
198         for (i = 0; i < 480*800/3; i++)
199                         send_data(0xff0000);
200         }
201         send_cmd(0x29); //Display On
202         LCD_DelayMS(120); //120ms
203         send_cmd(0x2C); //Write data
204         //LCD_DelayMS(120); //120ms
205         LCD_PRINT("hx8369_init: end\n");
206
207
208         return 0;
209 }
210
211 static int32_t hx8369_set_window(struct lcd_spec *self,
212                 uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
213 {
214         Send_data send_cmd = self->info.mcu->ops->send_cmd;
215         Send_data send_data = self->info.mcu->ops->send_data;
216
217         LCD_PRINT("hx8369_set_window\n");
218
219         send_cmd(0x2A); // col
220         send_data((left >> 8));
221         send_data((left & 0xFF));
222         send_data((right >> 8));
223         send_data((right & 0xFF));
224
225         send_cmd(0x2B); // row
226         send_data((top >> 8));
227         send_data((top & 0xFF));
228         send_data((bottom >> 8));
229         send_data((bottom & 0xFF));
230
231         send_cmd(0x2C); //Write data
232
233         return 0;
234 }
235
236
237 static int32_t hx8369_invalidate(struct lcd_spec *self)
238 {
239         LCD_PRINT("hx8369_invalidate\n");
240
241         return self->ops->lcd_set_window(self, 0, 0,
242                         self->width-1, self->height-1);
243
244 }
245
246 static int32_t hx8369_invalidate_rect(struct lcd_spec *self,
247                                 uint16_t left, uint16_t top,
248                                 uint16_t right, uint16_t bottom)
249 {
250         LCD_PRINT("hx8369_invalidate_rect \n");
251
252         return self->ops->lcd_set_window(self, left, top,
253                         right, bottom);
254 }
255
256 static int32_t hx8369_set_direction(struct lcd_spec *self, uint16_t direction)
257 {
258         Send_data send_cmd = self->info.mcu->ops->send_cmd;
259         Send_data send_data = self->info.mcu->ops->send_data;
260
261         LCD_PRINT("hx8369_set_direction\n");
262         send_cmd(0x36);
263
264         switch (direction) {
265         case LCD_DIRECT_NORMAL:
266                 send_data(0);
267                 break;
268         case LCD_DIRECT_ROT_90:
269                 send_data(0xA0);
270                 break;
271         case LCD_DIRECT_ROT_180:
272                 send_data(0x60);
273                 break;
274         case LCD_DIRECT_ROT_270:
275                 send_data(0xB0);
276                 break;
277         case LCD_DIRECT_MIR_H:
278                 send_data(0x40);
279                 break;
280         case LCD_DIRECT_MIR_V:
281                 send_data(0x10);
282                 break;
283         case LCD_DIRECT_MIR_HV:
284                 send_data(0xE0);
285                 break;
286         default:
287                 LCD_PRINT("unknown lcd direction!\n");
288                 send_data(0x0);
289                 direction = LCD_DIRECT_NORMAL;
290                 break;
291         }
292
293         self->direction = direction;
294
295         return 0;
296 }
297
298 static int32_t hx8369_enter_sleep(struct lcd_spec *self, uint8_t is_sleep)
299 {
300         Send_data send_cmd = self->info.mcu->ops->send_cmd;
301         Send_data send_data = self->info.mcu->ops->send_data;
302
303         if(is_sleep) {
304                 //Sleep In
305                 send_cmd(0x28);
306                 LCD_DelayMS(120);
307                 send_cmd(0x10);
308                 LCD_DelayMS(120);
309         }
310         else {
311                 //Sleep Out
312                 send_cmd(0x11);
313                 LCD_DelayMS(120);
314                 send_cmd(0x29);
315                 LCD_DelayMS(120);
316         }
317         return 0;
318 }
319
320 static int32_t hx8369_read_id(struct lcd_spec *self)
321 {
322         Send_data send_cmd = self->info.mcu->ops->send_cmd;
323         Send_data send_data = self->info.mcu->ops->send_data;
324         Read_data read_data = self->info.mcu->ops->read_data;
325
326         send_cmd(0xB9);
327         send_data(0xFF);
328         send_data(0x83);
329         send_data(0x69);
330
331         send_cmd(0xF4);
332         read_data();
333         return read_data();
334 }
335
336 static struct lcd_operations lcd_hx8369_operations = {
337         .lcd_init            = hx8369_init,
338         .lcd_set_window      = hx8369_set_window,
339         .lcd_invalidate      = hx8369_invalidate,
340         .lcd_invalidate_rect = hx8369_invalidate_rect,
341         .lcd_set_direction   = hx8369_set_direction,
342         .lcd_enter_sleep     = hx8369_enter_sleep,
343         .lcd_readid          = hx8369_read_id,
344 };
345
346 static struct timing_mcu lcd_hx8369_timing[] = {
347 [LCD_REGISTER_TIMING] = {                // read/write register timing
348                 .rcss = 25,  // 25 ns
349                 .rlpw = 70,
350                 .rhpw = 70,
351                 .wcss = 10,
352                 .wlpw = 50,
353                 .whpw = 50,
354         },
355 [LCD_GRAM_TIMING] = {                // read/write gram timing
356                 .rcss = 25,  // 25 ns
357                 .rlpw = 70,
358                 .rhpw = 70,
359                 .wcss = 0,
360                 .wlpw = 15,
361                 .whpw = 24,
362         }
363 };
364
365
366 static struct info_mcu lcd_hx8369_info = {
367         .bus_mode = LCD_BUS_8080,
368         .bus_width = 24,
369         .timing = lcd_hx8369_timing,
370         .ops = NULL,
371 };
372
373 struct lcd_spec lcd_panel_hx8369 = {
374         .width = 480,
375         .height = 800,
376         .mode = LCD_MODE_MCU,
377         .direction = LCD_DIRECT_NORMAL,
378         .info = {.mcu = &lcd_hx8369_info},
379         .ops = &lcd_hx8369_operations,
380 };
381