tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / video / sprdfb / lcd / lcd_s6d0139.c
1 /* drivers/video/sc8800g/sc8800g_lcd_s6d0139.c
2  *
3  * Support for s6d0139 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/sprd_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
29
30 static int32_t s6d0139_init(struct panel_spec *self)
31 {
32         send_cmd_data_t send_cmd_data = self->info.mcu->ops->send_cmd_data;
33         send_data_t send_cmd = self->info.mcu->ops->send_cmd;
34         send_data_t send_data = self->info.mcu->ops->send_data;
35         LCD_PRINT("s6d0139_init\n");
36
37         /* reset the lcd */
38         self->ops->panel_reset(self);
39         udelay(100*1000);
40         /* start init sequence */
41         send_cmd_data(0x0000, 0x0001);
42         udelay(10*1000);
43
44         send_cmd_data(0x0007, 0x0000);
45         send_cmd_data(0x0013, 0x0000);
46         send_cmd_data(0x0011, 0x2604);
47         send_cmd_data(0x0014, 0x1212);
48         send_cmd_data(0x0010, 0x3C00);
49         send_cmd_data(0x0013, 0x0040);
50         udelay(10*1000);
51         send_cmd_data(0x0013, 0x0060);
52         udelay(50*1000);
53         send_cmd_data(0x0013, 0x0070);
54         udelay(40*1000);
55         send_cmd_data(0x0001, 0x0127);
56         send_cmd_data(0x0002, 0x0700);
57         send_cmd_data(0x0003, 0x1030);
58         send_cmd_data(0x0007, 0x0000);
59         send_cmd_data(0x0008, 0x0404);
60         send_cmd_data(0x000B, 0x0200);
61         send_cmd_data(0x000C, 0x0000);
62         send_cmd_data(0x0015, 0x0000);
63
64         //gamma setting
65         send_cmd_data(0x0030, 0x0000);
66         send_cmd_data(0x0031, 0x0606);
67         send_cmd_data(0x0032, 0x0006);
68         send_cmd_data(0x0033, 0x0403);
69         send_cmd_data(0x0034, 0x0107);
70         send_cmd_data(0x0035, 0x0101);
71         send_cmd_data(0x0036, 0x0707);
72         send_cmd_data(0x0037, 0x0304);
73         send_cmd_data(0x0038, 0x0A00);
74         send_cmd_data(0x0039, 0x0706);
75         send_cmd_data(0x0040, 0x0000);
76         send_cmd_data(0x0041, 0x0000);
77         send_cmd_data(0x0042, 0x013F);
78         send_cmd_data(0x0043, 0x0000);
79         send_cmd_data(0x0044, 0x0000);
80         send_cmd_data(0x0045, 0x0000);
81         send_cmd_data(0x0046, 0xEF00);
82         send_cmd_data(0x0047, 0x013F);
83         send_cmd_data(0x0048, 0x0000);
84         send_cmd_data(0x0007, 0x0011);
85         udelay(40 *1000);
86         send_cmd_data(0x0007, 0x0017);
87         send_cmd_data(0x0020, 0x0000);
88         send_cmd_data(0x0021, 0x0000);
89         udelay(40*1000);
90
91         send_cmd(0x0022);
92
93
94         if(1){
95                 int i;
96                 for (i=0; i<320*240/3; i++)
97                         send_data(0xf800);
98                 for (i=0; i< 320*240/3; i++)
99                         send_data(0x07e0);
100                 for (i=0; i< 320*240/3; i++)
101                         send_data(0x001f);
102         }
103
104         return 0;
105 }
106
107 static int32_t s6d0139_set_window(struct panel_spec *self,
108                 uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
109 {
110         send_cmd_data_t send_cmd_data = self->info.mcu->ops->send_cmd_data;
111         send_data_t send_cmd = self->info.mcu->ops->send_cmd;
112         LCD_PRINT("s6d0139_set_window\n");
113
114         send_cmd_data(0x46, ((right << 8) & 0xff00)|(left&0xff));
115         send_cmd_data(0x47, bottom);
116         send_cmd_data(0x48, top);
117
118         switch (self->direction) {
119         case LCD_DIRECT_NORMAL:
120         case LCD_DIRECT_ROT_270:
121                 send_cmd_data(0x0020, left);
122                 send_cmd_data(0x0021, top);
123                 break;
124         case LCD_DIRECT_ROT_90:
125         case LCD_DIRECT_MIR_H:
126                 send_cmd_data(0x0020, right);
127                 send_cmd_data(0x0021, top);
128                 break;
129         case LCD_DIRECT_ROT_180:
130         case LCD_DIRECT_MIR_HV:
131                 send_cmd_data(0x0020, right);
132                 send_cmd_data(0x0021, bottom);
133                 break;
134         case LCD_DIRECT_MIR_V:
135                 send_cmd_data(0x0020, left);
136                 send_cmd_data(0x0021, bottom);
137                 break;
138         default:
139                 LCD_PRINT("unknown lcd direction!\n");
140                 break;
141         }
142
143         send_cmd(0x0022);
144
145         return 0;
146 }
147
148 static int32_t s6d0139_invalidate(struct panel_spec *self)
149 {
150         LCD_PRINT("s6d0139_invalidate\n");
151
152         return self->ops->panel_set_window(self, 0, 0,
153                         self->width-1, self->height-1);
154
155 }
156
157 static int32_t s6d0139_set_direction(struct panel_spec *self, uint16_t direction)
158 {
159         send_cmd_data_t send_cmd_data = self->info.mcu->ops->send_cmd_data;
160         LCD_PRINT("s6d0139_set_direction\n");
161
162         switch (direction) {
163         case LCD_DIRECT_NORMAL:
164                 send_cmd_data(0x0003, 0x1030);
165                 break;
166         case LCD_DIRECT_ROT_90:
167                 send_cmd_data(0x0003, 0x1028);
168                 break;
169         case LCD_DIRECT_ROT_180:
170         case LCD_DIRECT_MIR_HV:
171                 send_cmd_data(0x0003, 0x1000);
172                 break;
173         case LCD_DIRECT_ROT_270:
174                 send_cmd_data(0x0003, 0x1018);
175                 break;
176         case LCD_DIRECT_MIR_H:
177                 send_cmd_data(0x0003, 0x1020);
178                 break;
179         case LCD_DIRECT_MIR_V:
180                 send_cmd_data(0x0003, 0x1010);
181                 break;
182         default:
183                 LCD_PRINT("unknown lcd direction!\n");
184                 send_cmd_data(0x0003, 0x1030);
185                 direction = LCD_DIRECT_NORMAL;
186                 break;
187         }
188
189         self->direction = direction;
190
191         return 0;
192 }
193
194 static struct panel_operations lcd_s6d0139_operations = {
195         .panel_init = s6d0139_init,
196         .panel_set_window = s6d0139_set_window,
197         .panel_invalidate = s6d0139_invalidate,
198         .panel_set_direction = s6d0139_set_direction,
199 };
200
201
202 static struct timing_mcu lcd_s6d0139_timing[] = {
203 [0] = {    /* read/write register timing (ns) */
204         .rcss = 15,
205         .rlpw = 250,
206         .rhpw = 250,
207         .wcss = 10,
208         .wlpw = 28,
209         .whpw = 28,
210         },
211 [1] = {        /* read/write gram timing (ns) */
212                 .rcss = 25,  /* 25 ns */
213                 .rlpw = 70,
214                 .rhpw = 70,
215                 .wcss = 10,
216                 .wlpw = 50,
217                 .whpw = 50,
218         }
219 };
220
221 static struct info_mcu lcd_s6d0139_info = {
222         .bus_mode = LCD_BUS_8080,
223         .bus_width = 16,
224         .bpp = 16, /*RGB565*/
225         .timing = lcd_s6d0139_timing,
226         .ops = NULL,
227 };
228
229 struct panel_spec lcd_s6d0139_spec = {
230         .width = 240,
231         .height = 320,
232         .type = LCD_MODE_MCU,
233         .direction = LCD_DIRECT_NORMAL,
234         .info = {
235                 .mcu = &lcd_s6d0139_info
236         },
237         .ops = &lcd_s6d0139_operations,
238 };
239
240