tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / video / lcd_rm6158_truly.c
1 /* drivers/video/sc8800g/sc8800g_lcd_eR6158_truly.c
2  *
3  * Support for HX8357 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 #include <asm/arch/sc8810_lcd.h>
19 #define mdelay(a) udelay(a * 1000)
20 #define printk printf
21
22 //#define  LCD_DEBUG
23 #ifdef LCD_DEBUG
24 #define LCD_PRINT printk
25 #else
26 #define LCD_PRINT(...)
27 #endif
28
29 //#define CONFIG_FB_LCD_NOFMARK
30
31 static int32_t eR6158_truly_init(struct lcd_spec *self)
32 {
33         Send_data send_cmd = self->info.mcu->ops->send_cmd;
34         Send_data send_data = self->info.mcu->ops->send_data;
35
36         LCD_PRINT("eR6158_truly_init\n");
37     printk("[tong][uboot]eR6158_truly_init~~~~~~~~~~~~~~~~~~~~~\n");//tong test
38
39 /*
40   HW reset
41 */
42       send_cmd(0x01);//soft reset
43       mdelay(120);
44
45       send_cmd(0xFF);
46         send_cmd(0xFF);
47         mdelay(5);
48         send_cmd(0xFF);
49         send_cmd(0xFF);
50         send_cmd(0xFF);
51         send_cmd(0xFF);
52         mdelay(10);
53
54         send_cmd(0xB0);//{setc, [107], W, 0x000B0}
55         send_data(0x00);//{setp, [104], W, 0x00000}
56
57         send_cmd(0xB3);
58         send_data(0x02);
59         send_data(0x00);
60         send_data(0x00);
61         send_data(0x00);
62
63         send_cmd(0xB4);
64         send_data(0x00);
65
66         send_cmd(0xC0);
67         send_data(0x17);
68         send_data(0x3B);//480
69         send_data(0x00);
70         send_data(0x00);//BLV=0,PTL=0
71         send_data(0x00);
72         send_data(0x01);
73         send_data(0x00);//
74         send_data(0x77);
75
76         send_cmd(0xC1);
77         send_data(0x08);// BC=1 //div=0
78         send_data(0x16);//CLOCK
79         send_data(0x08);
80         send_data(0x08);
81
82         send_cmd(0xC4);
83         send_data(0x11);
84         send_data(0x07);
85         send_data(0x03);
86         send_data(0x03);
87
88         send_cmd(0xC8);//GAMMA
89         send_data(0x04);
90         send_data(0x0C);
91         send_data(0x0A);
92         send_data(0x59);
93         send_data(0x06);
94         send_data(0x08);
95         send_data(0x0f);
96         send_data(0x07);
97
98         send_data(0x00);
99         send_data(0x32);
100
101         send_data(0x07);
102         send_data(0x0f);
103         send_data(0x08);
104         send_data(0x56);//43/55
105         send_data(0x09);
106         send_data(0x0A);
107         send_data(0x0C);
108         send_data(0x04);
109
110         send_data(0x32);
111         send_data(0x00);
112
113         send_cmd(0x2A);
114         send_data(0x00);
115         send_data(0x00);
116         send_data(0x01);
117         send_data(0x3F);//320
118
119         send_cmd(0x2B);
120         send_data(0x00);
121         send_data(0x00);
122         send_data(0x01);
123         send_data(0xDF);//480
124
125 #ifndef CONFIG_FB_LCD_NOFMARK
126         send_cmd(0x35);
127         send_data(0x00);
128 #endif
129
130         send_cmd(0x36);
131         //send_data(0x80);
132         send_data(0x40);//tong test
133
134         send_cmd(0x3A);
135         send_data(0x66);
136
137         send_cmd(0x44);
138         send_data(0x00);
139         send_data(0x01);
140
141         send_cmd(0x11);
142         mdelay(150);
143
144         send_cmd(0xD0);
145         send_data(0x07);
146         send_data(0x07);
147         send_data(0x1E); //
148         send_data(0x33);
149
150
151         send_cmd(0xD1);
152         send_data(0x03);
153         send_data(0x4B);//VCM40
154         send_data(0x10);//VDV
155
156         send_cmd(0xD2);
157         send_data(0x03);
158         send_data(0x04);//0X24
159         send_data(0x04);
160
161         send_cmd(0x29);
162         mdelay(10);  
163
164         send_cmd(0xB4);
165         send_data(0x00);
166         send_cmd(0x2C);
167         mdelay(20);  
168
169         return 0;
170 }
171
172 static int32_t eR6158_truly_set_window(struct lcd_spec *self,
173                 uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
174 {
175         Send_data send_cmd = self->info.mcu->ops->send_cmd;
176         Send_data send_data = self->info.mcu->ops->send_data;
177
178         LCD_PRINT("eR6158_truly_set_window: %d, %d, %d, %d\n",left, top, right, bottom);
179     
180         /* set window size  */
181
182         send_cmd(0x2A);
183         send_data(left  >> 8);
184         send_data(left  & 0xff);
185         send_data(right  >> 8);
186         send_data(right  & 0xff);
187         
188         
189         send_cmd(0x2B);
190         send_data(top  >> 8);
191         send_data(top  & 0xff);
192         send_data(bottom  >> 8);
193         send_data(bottom  & 0xff);
194         
195         send_cmd(0x2C);
196
197
198         return 0;
199 }
200
201 static int32_t eR6158_truly_invalidate(struct lcd_spec *self)
202 {
203         LCD_PRINT("eR6158_truly_invalidate\n");
204
205         return self->ops->lcd_set_window(self, 0, 0, 
206                         self->width - 1, self->height - 1);
207         
208 }
209
210 static int32_t eR6158_truly_invalidate_rect(struct lcd_spec *self,
211                                 uint16_t left, uint16_t top,
212                                 uint16_t right, uint16_t bottom)
213 {
214         //Send_cmd_data send_cmd_data = self->info.mcu->ops->send_cmd_data;
215
216         LCD_PRINT("eR6158_truly_invalidate_rect \n");
217
218         return self->ops->lcd_set_window(self, left, top, 
219                         right, bottom);
220 }
221
222 static int32_t eR6158_truly_set_direction(struct lcd_spec *self, uint16_t direction)
223 {
224         //Send_cmd_data send_cmd_data = self->info.mcu->ops->send_cmd_data;
225
226         LCD_PRINT("eR6158_truly_set_direction\n");
227
228         self->direction = direction;
229         
230         return 0;
231 }
232
233 static int32_t eR6158_truly_enter_sleep(struct lcd_spec *self, uint8_t is_sleep)
234 {
235         //Send_cmd_data send_cmd_data = self->info.mcu->ops->send_cmd_data;
236         Send_data send_cmd = self->info.mcu->ops->send_cmd;
237         //Send_data send_data = self->info.mcu->ops->send_data;
238
239       if(is_sleep) 
240         {
241                 send_cmd(0x28);
242                 LCD_DelayMS(50);
243              send_cmd(0x10);
244                 LCD_DelayMS(200);
245         }
246         else
247         {
248                 send_cmd(0x11); // SLPOUT
249                 LCD_DelayMS(120);
250                 send_cmd(0x29);         
251                 LCD_DelayMS(50);                
252         }
253     
254         return 0;
255 }
256
257 static uint32_t eR6158_truly_read_id(struct lcd_spec *self)
258 {
259
260       Send_data send_cmd = self->info.mcu->ops->send_cmd;
261         Read_data read_data = self->info.mcu->ops->read_data;
262       Send_data send_data = self->info.mcu->ops->send_data;
263       uint32_t uID = 0;
264       uint32_t uICID[5] = {0};
265       uint32_t i;
266
267
268       send_cmd(0x01);//soft reset
269       mdelay(120);
270 #if 0
271       send_cmd(0xB0);
272       send_data(0x00);
273       
274       send_cmd(0xBF);
275       for(i = 0; i < 5; i++)
276       {
277           uICID[i] = read_data();
278           printk("[tong][uboot]eR6158_truly_read_id: uICID[%d] = 0x%x\n", i, uICID[i]);
279       }
280
281       if((uICID[1] == 0x01) && (uICID[2] == 0x22) && (uICID[3] == 0x15) && (uICID[4] == 0x81))
282       {
283           printk("[tong][uboot]LCD driver IC: r61581\n");          
284       }
285       else
286       {
287           printk("[tong][uboot]LCD driver IC: hx8357c\n");
288           return -1;
289       }
290 #else
291       send_cmd(0xB9);
292       send_data(0xFF);
293       send_data(0x83);
294       send_data(0x57);
295
296       send_cmd(0xD0);
297       for(i = 0; i < 2; i++)
298       {
299           uICID[i] = read_data();
300           printk("[tong][uboot]eR6158_truly_read_id: uICID[%d] = 0x%x\n", i, uICID[i]);        
301       }
302       
303       if((uICID[1] == 0x90))
304       {
305           printk("[tong][uboot]LCD driver IC: hx8357c\n");
306           return -1;
307       }
308       else
309       {  
310           printk("[tong][uboot]LCD driver IC: r61581\n");
311           
312       }
313      
314       
315 #endif         
316       send_cmd(0xA1);
317       uID = read_data();
318       printk("[tong][uboot]eR6158_truly_read_id: 0x%x from addr:0xA1\n", uID);
319      
320         return (0x6158|uID); 
321 }
322
323 static struct lcd_operations lcd_eR6158_truly_operations = {
324         .lcd_init = eR6158_truly_init,
325         .lcd_set_window = eR6158_truly_set_window,
326         .lcd_invalidate_rect= eR6158_truly_invalidate_rect,
327         .lcd_invalidate = eR6158_truly_invalidate,
328         .lcd_set_direction = eR6158_truly_set_direction,
329         .lcd_enter_sleep = eR6158_truly_enter_sleep,
330         .lcd_readid          = eR6158_truly_read_id,
331 };
332
333 static struct timing_mcu lcd_eR6158_truly_timing[] = {
334     
335     [LCD_REGISTER_TIMING] = {                    // read/write register timing
336                 .rcss = 170,  
337                 .rlpw = 190,
338                 .rhpw = 260,
339                 .wcss = 30,
340                 .wlpw = 30,
341                 .whpw = 30,
342     },
343     [LCD_GRAM_TIMING] = {                    // read/write gram timing
344         .rcss = 170,
345         .rlpw = 170,
346         .rhpw = 250,
347         .wcss = 30,
348         .wlpw = 30,
349         .whpw = 30,
350         },
351 };
352
353 static struct info_mcu lcd_eR6158_truly_info = {
354         .bus_mode = LCD_BUS_8080,
355         .bus_width = 18,
356         .timing = lcd_eR6158_truly_timing,
357         .ops = NULL,
358 };
359
360 struct lcd_spec lcd_panel_eR6158_truly = {
361         .width = 320,
362         .height = 480,
363         .mode = LCD_MODE_MCU,
364         .direction = LCD_DIRECT_NORMAL,
365         .info = {.mcu = &lcd_eR6158_truly_info},
366         .ops = &lcd_eR6158_truly_operations,
367 };