tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / video / sprdfb / lcd / lcd_hx8363_rgb_spi_viva.c
1 /* drivers/video/sc8810/lcd_hx8363_rgb_spi.c
2  *
3  *
4  *
5  *
6  * Copyright (C) 2010 Spreadtrum
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  */
17
18 #include <asm/arch/sprd_lcd.h>
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 #define HX8363_SpiWriteCmd(cmd) \
29 { \
30         spi_send_cmd((cmd & 0xFF));\
31 }
32
33 #define  HX8363_SpiWriteData(data)\
34 { \
35         spi_send_data((data & 0xFF));\
36 }
37
38
39 static int32_t hx8363_init(struct panel_spec *self)
40 {
41         uint32_t test_data[8] = {0};
42         uint32_t left = 0;
43         uint32_t top = 0;       
44         uint32_t right = 480;
45         uint32_t bottom = 800;          
46         uint32_t data = 0;
47         spi_send_cmd_t spi_send_cmd = self->info.rgb->bus_info.spi->ops->spi_send_cmd; 
48         spi_send_data_t spi_send_data = self->info.rgb->bus_info.spi->ops->spi_send_data; 
49         spi_read_t spi_read = self->info.rgb->bus_info.spi->ops->spi_read; 
50
51
52         LCD_PRINT("VIVA_init\n");
53
54         HX8363_SpiWriteCmd(0xB9); // SET password
55         HX8363_SpiWriteData(0xFF); // 
56         HX8363_SpiWriteData(0x83); // 
57         HX8363_SpiWriteData(0x69); // 
58
59         HX8363_SpiWriteCmd(0xB1);
60         HX8363_SpiWriteData(0x0B);
61         HX8363_SpiWriteData(0x83);
62         HX8363_SpiWriteData(0xA7);
63         HX8363_SpiWriteData(0x00);
64         HX8363_SpiWriteData(0x11);
65         HX8363_SpiWriteData(0x11); //
66         HX8363_SpiWriteData(0x08); //
67         HX8363_SpiWriteData(0x08); //the lower ,Saturation is better
68         HX8363_SpiWriteData(0x0C); //the lower ,Saturation is better
69         HX8363_SpiWriteData(0x22);
70
71
72         HX8363_SpiWriteCmd(0xC6); // SET DISP
73         HX8363_SpiWriteData(0x41); // 
74         HX8363_SpiWriteData(0xFF); // 
75         HX8363_SpiWriteData(0x7A); // 
76         HX8363_SpiWriteData(0xFF); // 
77
78         HX8363_SpiWriteCmd(0xE3);
79         HX8363_SpiWriteData(0x00);//Column inversion
80         HX8363_SpiWriteData(0x00); 
81         HX8363_SpiWriteData(0x00);
82         HX8363_SpiWriteData(0x00);
83
84
85         HX8363_SpiWriteCmd(0xC0); //Set_VCOM 
86         HX8363_SpiWriteData(0x73);
87         HX8363_SpiWriteData(0x50); //0x10
88         HX8363_SpiWriteData(0x00); //0x10
89         HX8363_SpiWriteData(0x34); //0x10
90         HX8363_SpiWriteData(0xC4); //0x10
91         HX8363_SpiWriteData(0x00); //0x10
92
93 // STEP 2
94
95
96         HX8363_SpiWriteCmd(0x3A); // SET Panel
97         HX8363_SpiWriteData(0x70); //
98
99         HX8363_SpiWriteCmd(0xB3); // SET Panel
100         HX8363_SpiWriteData(0x83); //
101         HX8363_SpiWriteData(0x00); //
102         HX8363_SpiWriteData(0x31); //
103         HX8363_SpiWriteData(0x03); //
104         HX8363_SpiWriteData(0x01); //
105         HX8363_SpiWriteData(0x13); //
106         HX8363_SpiWriteData(0x06); //
107
108         HX8363_SpiWriteCmd(0xB4); // SET Panel
109         HX8363_SpiWriteData(0x00); //
110
111         HX8363_SpiWriteCmd(0xCC); // SET Panel
112         HX8363_SpiWriteData(0x0C); //
113
114         HX8363_SpiWriteCmd(0xEA); // SET Panel
115         HX8363_SpiWriteData(0x72); //
116
117         HX8363_SpiWriteCmd(0xB2); // SET Panel
118         HX8363_SpiWriteData(0x03); //
119
120
121
122         HX8363_SpiWriteCmd(0xD5);  // SET Gamma
123         HX8363_SpiWriteData(0x00);
124         HX8363_SpiWriteData(0x00);
125         HX8363_SpiWriteData(0x0D);
126         HX8363_SpiWriteData(0x00);
127         HX8363_SpiWriteData(0x00);
128         HX8363_SpiWriteData(0x00);
129         HX8363_SpiWriteData(0x00);
130         HX8363_SpiWriteData(0x12);
131         HX8363_SpiWriteData(0x40);
132         HX8363_SpiWriteData(0x00);
133         HX8363_SpiWriteData(0x00);
134         HX8363_SpiWriteData(0x00);
135         HX8363_SpiWriteData(0x01);
136         HX8363_SpiWriteData(0x60);
137         HX8363_SpiWriteData(0x37);
138         HX8363_SpiWriteData(0x00);
139         HX8363_SpiWriteData(0x00);
140         HX8363_SpiWriteData(0x0F);
141         HX8363_SpiWriteData(0x01);
142         HX8363_SpiWriteData(0x05);
143         HX8363_SpiWriteData(0x47);
144         HX8363_SpiWriteData(0x03);
145         HX8363_SpiWriteData(0x00);
146         HX8363_SpiWriteData(0x03);
147         HX8363_SpiWriteData(0x00);
148         HX8363_SpiWriteData(0x00);
149         HX8363_SpiWriteData(0x00);
150         HX8363_SpiWriteData(0x00);
151         HX8363_SpiWriteData(0x00);
152         HX8363_SpiWriteData(0x00);
153         HX8363_SpiWriteData(0x00);
154         HX8363_SpiWriteData(0x00);
155         HX8363_SpiWriteData(0x03);
156         HX8363_SpiWriteData(0x00);
157         HX8363_SpiWriteData(0x00); // 
158         HX8363_SpiWriteData(0x18);
159         HX8363_SpiWriteData(0x00);
160         HX8363_SpiWriteData(0x00);
161         HX8363_SpiWriteData(0x89);
162         HX8363_SpiWriteData(0x00);
163         HX8363_SpiWriteData(0x11 );
164         HX8363_SpiWriteData(0x33 );
165         HX8363_SpiWriteData(0x55 );
166         HX8363_SpiWriteData(0x77 );
167         HX8363_SpiWriteData(0x31 );
168         HX8363_SpiWriteData(0x00 );
169         HX8363_SpiWriteData(0x00 );
170         HX8363_SpiWriteData(0x98 );
171         HX8363_SpiWriteData(0x00 );
172         HX8363_SpiWriteData(0x66 );
173         HX8363_SpiWriteData(0x44 );
174         HX8363_SpiWriteData(0x22 );
175         HX8363_SpiWriteData(0x00 );
176         HX8363_SpiWriteData(0x02 );
177         HX8363_SpiWriteData(0x00 );
178         HX8363_SpiWriteData(0x00 );
179         HX8363_SpiWriteData(0x89 );
180         HX8363_SpiWriteData(0x00 );
181         HX8363_SpiWriteData(0x00 );
182         HX8363_SpiWriteData(0x22 );
183         HX8363_SpiWriteData(0x44 );
184         HX8363_SpiWriteData(0x66 );
185         HX8363_SpiWriteData(0x20 );
186         HX8363_SpiWriteData(0x00 );
187         HX8363_SpiWriteData(0x00 );
188         HX8363_SpiWriteData(0x98 );
189         HX8363_SpiWriteData(0x00 );
190         HX8363_SpiWriteData(0x77 );
191         HX8363_SpiWriteData(0x55 );
192         HX8363_SpiWriteData(0x33 );
193         HX8363_SpiWriteData(0x11 );
194         HX8363_SpiWriteData(0x13 );
195         HX8363_SpiWriteData(0x00 );
196         HX8363_SpiWriteData(0x00 );
197         HX8363_SpiWriteData(0x00 );
198         HX8363_SpiWriteData(0x01 );
199         HX8363_SpiWriteData(0x00 );
200         //G
201         HX8363_SpiWriteData(0x00 );
202         HX8363_SpiWriteData(0x00 );
203         HX8363_SpiWriteData(0x03 );
204         HX8363_SpiWriteData(0x00 );
205         HX8363_SpiWriteData(0xCF );
206         HX8363_SpiWriteData(0xFF );
207         HX8363_SpiWriteData(0xFF );
208         HX8363_SpiWriteData(0x03 );
209         HX8363_SpiWriteData(0x00 );
210         HX8363_SpiWriteData(0xCF );
211         HX8363_SpiWriteData(0xFF );
212         HX8363_SpiWriteData(0xFF );
213         HX8363_SpiWriteData(0x20 );
214         HX8363_SpiWriteData(0x8C );
215         HX8363_SpiWriteData(0x5A );
216
217
218
219
220         HX8363_SpiWriteCmd(0xE0); //COLMOD 
221         HX8363_SpiWriteData(0x00 );
222         HX8363_SpiWriteData(0x00 );
223         HX8363_SpiWriteData(0x02 );
224         HX8363_SpiWriteData(0x0D );
225         HX8363_SpiWriteData(0x0C );
226         HX8363_SpiWriteData(0x3F );
227         HX8363_SpiWriteData(0x19 );
228         HX8363_SpiWriteData(0x2D );
229         HX8363_SpiWriteData(0x04 );
230         HX8363_SpiWriteData(0x0F );
231         HX8363_SpiWriteData(0x0E );
232         HX8363_SpiWriteData(0x14 );
233         HX8363_SpiWriteData(0x17 );
234         HX8363_SpiWriteData(0x15 );
235         HX8363_SpiWriteData(0x16 );
236         HX8363_SpiWriteData(0x10 );
237         HX8363_SpiWriteData(0x11 );
238         HX8363_SpiWriteData(0x00 );
239         HX8363_SpiWriteData(0x00 );
240         HX8363_SpiWriteData(0x02 );
241         HX8363_SpiWriteData(0x0c );
242         HX8363_SpiWriteData(0x12 );
243         HX8363_SpiWriteData(0x3F );
244         HX8363_SpiWriteData(0x19 );
245         HX8363_SpiWriteData(0x2C );
246         HX8363_SpiWriteData(0x05 );
247         HX8363_SpiWriteData(0x08 );
248         HX8363_SpiWriteData(0x0E );
249         HX8363_SpiWriteData(0x12 );
250         HX8363_SpiWriteData(0x16 );
251         HX8363_SpiWriteData(0x14 );
252         HX8363_SpiWriteData(0x15 );
253         HX8363_SpiWriteData(0x10 );
254         HX8363_SpiWriteData(0x12 );
255         HX8363_SpiWriteData(0x01 );
256
257
258         HX8363_SpiWriteCmd(0x11); //COLMOD 
259         udelay(120000); 
260         HX8363_SpiWriteCmd(0x29); //COLMOD 
261
262
263
264
265
266 }
267
268 static int32_t hx8363_enter_sleep(struct panel_spec *self, uint8_t is_sleep)
269 {
270         spi_send_cmd_t spi_send_cmd = self->info.rgb->bus_info.spi->ops->spi_send_cmd; 
271         spi_send_data_t spi_send_data = self->info.rgb->bus_info.spi->ops->spi_send_data; 
272         
273         if(is_sleep==1){
274                 //Sleep In
275                 HX8363_SpiWriteCmd(0x28);
276                 udelay(120000); 
277                 HX8363_SpiWriteCmd(0x10);
278                 udelay(10000); 
279         }else{
280                 //Sleep Out
281                 HX8363_SpiWriteCmd(0x11);
282                 udelay(120000); 
283                 HX8363_SpiWriteCmd(0x29);
284                 udelay(10000); 
285         }
286
287         return 0;
288 }
289
290
291
292
293 static int32_t hx8363_set_window(struct panel_spec *self,
294                 uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
295 {
296         uint32_t *test_data[4] = {0};
297         spi_send_cmd_t spi_send_cmd = self->info.rgb->bus_info.spi->ops->spi_send_cmd; 
298         spi_send_data_t spi_send_data = self->info.rgb->bus_info.spi->ops->spi_send_data; 
299         spi_read_t spi_read = self->info.rgb->bus_info.spi->ops->spi_read;
300 #if 0
301
302         LCD_PRINT("zxdbg add -hx8363_set_window: %d, %d, %d, %d\n",left, top, right, bottom);
303
304         HX8363_SpiWriteCmd(0x2A00); 
305         HX8363_SpiWriteData((left>>8));// set left address
306         HX8363_SpiWriteData((left&0xff));
307         HX8363_SpiWriteData((right>>8));// set right address
308         HX8363_SpiWriteData((right&0xff));
309
310         HX8363_SpiWriteCmd(0x2B00); 
311         HX8363_SpiWriteData((top>>8));// set left address
312         HX8363_SpiWriteData((top&0xff));
313         HX8363_SpiWriteData((bottom>>8));// set bottom address
314         HX8363_SpiWriteData((bottom&0xff));
315
316 //      HX8363_SpiWriteCmd(0x2C00);
317
318         HX8363_SpiWriteCmd(0x2A00); 
319         spi_read(test_data);
320         spi_read(test_data+1);
321         HX8363_SpiWriteCmd(0x2B00); 
322         spi_read(test_data+2);
323         spi_read(test_data+3);
324 #endif
325         LCD_PRINT("zxdbg add -hx8363_read read: %x, %x, %x, %x\n",test_data[0], test_data[1], test_data[2], test_data[3]);
326
327         return 0;
328 }
329 static int32_t hx8363_invalidate(struct panel_spec *self)
330 {
331         LCD_PRINT("hx8363_invalidate\n");
332
333         return self->ops->panel_set_window(self, 0, 0,
334                 self->width - 1, self->height - 1);
335 }
336
337
338
339 static int32_t hx8363_invalidate_rect(struct panel_spec *self,
340                                 uint16_t left, uint16_t top,
341                                 uint16_t right, uint16_t bottom)
342 {
343         LCD_PRINT("hx8363_invalidate_rect \n");
344
345         return self->ops->panel_set_window(self, left, top,
346                         right, bottom);
347 }
348
349 static int32_t hx8363_read_id(struct panel_spec *self)
350 {
351         int32_t id  = 0x62;
352         spi_send_cmd_t spi_send_cmd = self->info.rgb->bus_info.spi->ops->spi_send_cmd;
353         spi_send_data_t spi_send_data = self->info.rgb->bus_info.spi->ops->spi_send_data;
354         spi_read_t spi_read = self->info.rgb->bus_info.spi->ops->spi_read;
355 /*
356         HX8363_SpiWriteCmd(0xB9); // SET password
357         HX8363_SpiWriteData(0xFF); //
358         HX8363_SpiWriteData(0x83); //
359         HX8363_SpiWriteData(0x63); //
360
361         HX8363_SpiWriteCmd(0xFE); // SET SPI READ INDEX
362         HX8363_SpiWriteData(0xF4); // GETHXID
363         HX8363_SpiWriteCmd(0xFF); // GET SPI READ
364
365         spi_read(&id);
366
367         id &= 0xff;
368 */
369         LCD_PRINT(" hx8363_read_id u-boot id = %x\n",id);
370 #ifndef CONFIG_SPX15
371         return id;
372 #else
373         return 0x63;
374 #endif
375 }
376
377 static struct panel_operations lcd_hx8363_rgb_spi_operations = {
378         .panel_init = hx8363_init,
379         .panel_set_window = hx8363_set_window,
380         .panel_invalidate_rect= hx8363_invalidate_rect,
381         .panel_invalidate = hx8363_invalidate,
382         .panel_enter_sleep = hx8363_enter_sleep,
383         .panel_readid          = hx8363_read_id
384 };
385
386 static struct timing_rgb lcd_hx8363_rgb_timing = {
387 #if 1
388         .hfp = 30,//10,  /* unit: pixel */
389         .hbp = 55, //6,
390         .hsync = 10, //8,
391         .vfp = 6, // 3, /*unit: line*/
392         .vbp = 19, // 3,
393         .vsync = 6, // 4,
394 #else
395         .hfp = 15,//10,  /* unit: pixel */
396         .hbp = 15,//6,
397         .hsync = 10, //8,
398         .vfp = 8, // 3, /*unit: line*/
399         .vbp = 8, // 3,
400         .vsync = 6, // 4,
401 #endif  
402 };
403
404 static struct spi_info lcd_hx8363_rgb_spi_info = {
405         .ops = NULL,
406 };
407
408 static struct info_rgb lcd_hx8363_rgb_info = {
409         .cmd_bus_mode  = SPRDFB_RGB_BUS_TYPE_SPI,
410         .video_bus_width = 24, /*18,16*/
411         .h_sync_pol = SPRDFB_POLARITY_NEG,
412         .v_sync_pol = SPRDFB_POLARITY_NEG,
413         .de_pol = SPRDFB_POLARITY_POS,
414         .timing = &lcd_hx8363_rgb_timing,
415         .bus_info = {
416                 .spi = &lcd_hx8363_rgb_spi_info,
417         }
418 };
419
420 struct panel_spec lcd_panel_hx8363_rgb_spi_spec_viva = {
421         .width = 480,
422         .height = 800,
423         .fps = 60,
424         .type = LCD_MODE_RGB,
425         .direction = LCD_DIRECT_NORMAL,
426         .info = {
427                 .rgb = &lcd_hx8363_rgb_info
428         },
429         .ops = &lcd_hx8363_rgb_spi_operations,
430 };