tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / video / sprdfb / lcd / lcd_hx8369b_mipi_vivaltoVE.c
1 /* drivers/video/sprdfb/lcd_hx8369b_mipi.c
2  *
3  * Support for hx8369b mipi 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 <linux/kernel.h>
18 #include <linux/bug.h>
19 #include <linux/delay.h>
20 #include "../sprdfb_panel.h"
21 #include <mach/gpio.h>
22
23 #define  LCD_DEBUG
24 #ifdef LCD_DEBUG
25 #define LCD_PRINT printk
26 #else
27 #define LCD_PRINT(...)
28 #endif
29
30 #define MAX_DATA   150
31
32 typedef struct LCM_Init_Code_tag {
33         unsigned int tag;
34         unsigned char data[MAX_DATA];
35 }LCM_Init_Code;
36
37 typedef struct LCM_force_cmd_code_tag{
38         unsigned int datatype;
39         LCM_Init_Code real_cmd_code;
40 }LCM_Force_Cmd_Code;
41
42 #define LCM_TAG_SHIFT 24
43 #define LCM_TAG_MASK  ((1 << 24) -1)
44 #define LCM_SEND(len) ((1 << LCM_TAG_SHIFT)| len)
45 #define LCM_SLEEP(ms) ((2 << LCM_TAG_SHIFT)| ms)
46 //#define ARRAY_SIZE(array) ( sizeof(array) / sizeof(array[0]))
47
48 #define LCM_TAG_SEND  (1<< 0)
49 #define LCM_TAG_SLEEP (1 << 1)
50
51 static LCM_Init_Code init_data[] = {
52         {LCM_SEND(6),{4,0,0xB9,0xFF,0x83,0x69}},
53         //{LCM_SLEEP(10)},
54         {LCM_SEND(13),{11,0,0xB1,0x0B,0x83,0x77,0x00,0x11,0x11,0x08,0x08,0x0C,0x12}},
55         {LCM_SEND(7),{5,0,0xC6,0x41,0xFF,0x7A,0xFF}},
56         {LCM_SEND(7),{5,0,0xE3,0x00,0x00,0x00,0x00}},
57         {LCM_SEND(9),{7,0,0xC0,0x73,0x50,0x00,0x34,0xC4,0x00}},
58         {LCM_SEND(18),{16,0,0xBA,0x31,0x00,0x16,0xCA,0xB0,0x0A,0x00,0x10,0x28,0x02,0x21,0x21,0x9A,0x1A,0x8F}},
59         {LCM_SEND(2),{0x3A,0x70}},
60         {LCM_SEND(10),{8,0,0xB3,0x83,0x00,0x31,0x03,0x01,0x13,0x06}},
61         {LCM_SEND(2),{0xB4,0x00}},
62         {LCM_SEND(2),{0xCC,0x0C}},
63         {LCM_SEND(2),{0xEA,0x72}},
64         {LCM_SEND(2),{0xB2,0x03}},
65         //set GIP timing control
66         {LCM_SEND(95),{93,0,0xD5,0x00,0x00,0x0D,0x00,0x00,0x00,0x00,0x12,0x40,0x00,0x00,0x00,0x01,0x60,0x37,0x00,0x00,0x0F,
67                                                 0x01,0x02,0x47,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x18,
68                                                 0x00,0x00,0x89,0x00,0x11,0x33,0x55,0x77,0x31,0x00,0x00,0x98,0x00,0x66,0x44,0x22,0x00,0x02,
69                                                 0x00,0x00,0x89,0x00,0x00,0x22,0x44,0x66,0x20,0x00,0x00,0x98,0x00,0x77,0x55,0x33,0x11,0x13,
70                                                 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0xCF,0xFF,0xFF,0x03,0x00,0xCF,0xFF,0xFF,0x20,0x8C,0x5A}},
71         //gamma setting
72         {LCM_SEND(38),{36,0,0xE0,0x00,0x00,0x00,0x0D,0x0C,0x3F,0x18,0x2C,0x04,0x0F,0x0E,0x14,0x17,0x15,0x16,0x10,
73                                                 0x13,0x00,0x00,0x00,0x0C,0x12,0x3F,0x17,0x2C,0x05,0x08,0x0E,0x12,0x16,0x14,0x15,
74                                                 0x11,0x13,0x01}},
75         {LCM_SEND(130),{128,0,0xC1,0x01,0x00,0x08,0x10,0x18,0x1F,0x27,0x2E,0x34,0x3E,0x48,0x50,0x58,0x60,0x68,0x70,0x78,
76                                                         0x80,0x88,0x90,0x98,0xA0,0xA8,0xB0,0xB8,0xC0,0xC8,0xD0,0xD8,0xE0,0xE8,0xF0,0xF7,0xFF,
77                                                         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x18,0x1F,0x27,0x2E,0x34,
78                                                         0x3E,0x48,0x50,0x58,0x60,0x68,0x70,0x78,0x80,0x88,0x90,0x98,0xA0,0xA8,0xB0,0xB8,0xC0,
79                                                         0xC8,0xD0,0xD8,0xE0,0xE8,0xF0,0xF7,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
80                                                         0x00,0x08,0x10,0x18,0x1F,0x27,0x2E,0x34,0x3E,0x48,0x50,0x58,0x60,0x68,0x70,0x78,0x80,
81                                                         0x88,0x90,0x98,0xA0,0xA8,0xB0,0xB8,0xC0,0xC8,0xD0,0xD8,0xE0,0xE8,0xF0,0xF7,0xFF,0x00,
82                                                         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
83         {LCM_SEND(1),{0x11}},
84         {LCM_SLEEP(120)},
85         {LCM_SEND(1),{0x29}},
86         {LCM_SLEEP(10)}, //40
87
88 };
89
90 static LCM_Init_Code disp_on =  {LCM_SEND(1), {0x29}};
91
92 static LCM_Init_Code sleep_in[] =  {
93         {LCM_SEND(1), {0x28}},
94         {LCM_SLEEP(150)},       //>150ms
95         {LCM_SEND(1), {0x10}},
96         {LCM_SLEEP(150)},       //>150ms
97 };
98
99 static LCM_Init_Code sleep_out[] =  {
100         {LCM_SEND(1), {0x11}},
101         {LCM_SLEEP(120)},//>120ms
102         {LCM_SEND(1), {0x29}},
103         {LCM_SLEEP(20)}, //>20ms
104 };
105 static int32_t hx8369b_mipi_init(struct panel_spec *self)
106 {
107         int32_t i = 0;
108         LCM_Init_Code *init = init_data;
109         unsigned int tag;
110
111         mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
112         mipi_dcs_write_t mipi_dcs_write = self->info.mipi->ops->mipi_dcs_write;
113         mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
114
115         printk("kernel hx8369b_mipi_init\n");
116
117         mipi_set_cmd_mode();
118         mipi_eotp_set(0,0);
119
120         for(i = 0; i < ARRAY_SIZE(init_data); i++){
121                 tag = (init->tag >>24);
122                 if(tag & LCM_TAG_SEND){
123                         mipi_dcs_write(init->data, (init->tag & LCM_TAG_MASK));
124                         udelay(20);
125                 }else if(tag & LCM_TAG_SLEEP){
126                         msleep(init->tag & LCM_TAG_MASK);
127                 }
128                 init++;
129         }
130         mipi_eotp_set(0,0);
131
132         return 0;
133 }
134
135 static uint32_t hx8369b_readid(struct panel_spec *self)
136         {
137                 int32_t j =0;
138                 uint8_t read_data[4] = {0};
139                 int32_t read_rtn = 0;
140                 uint8_t param[2] = {0};
141                 mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
142                 mipi_force_write_t mipi_force_write = self->info.mipi->ops->mipi_force_write;
143                 mipi_force_read_t mipi_force_read = self->info.mipi->ops->mipi_force_read;
144                 mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
145
146                 LCD_PRINT("kernel lcd_hx8369b_mipi read id!\n");
147
148                 mipi_set_cmd_mode();
149                 mipi_eotp_set(0,0);
150
151                 for(j = 0; j < 4; j++){
152                         param[0] = 0x01;
153                         param[1] = 0x00;
154                         mipi_force_write(0x37, param, 2);
155                         read_rtn = mipi_force_read(0xda,1,&read_data[0]);
156                         LCD_PRINT("lcd_hx8369b_mipi read id 0xda value is 0x%x!\n",read_data[0]);
157
158                         read_rtn = mipi_force_read(0xdb,1,&read_data[1]);
159                         LCD_PRINT("lcd_hx8369b_mipi read id 0xdb value is 0x%x!\n",read_data[1]);
160
161                         read_rtn = mipi_force_read(0xdc,1,&read_data[2]);
162                         LCD_PRINT("lcd_hx8369b_mipi read id 0xdc value is 0x%x!\n",read_data[2]);
163
164                         if((0x55 == read_data[0])&&(0x0c == read_data[1])&&(0x90 == read_data[2])){
165                                         printk("lcd_hx8369b_mipi read id success!\n");
166                                         return 0x8369;
167                                 }
168                         }
169
170                 mipi_eotp_set(0,0);
171
172                 return 0;
173 }
174
175
176 static int32_t hx8369b_enter_sleep(struct panel_spec *self, uint8_t is_sleep)
177 {
178         int32_t i = 0;
179         LCM_Init_Code *sleep_in_out = NULL;
180         unsigned int tag;
181         int32_t size = 0;
182
183         mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
184         mipi_dcs_write_t mipi_dcs_write = self->info.mipi->ops->mipi_dcs_write;
185         mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
186
187         printk("kernel hx8369b_enter_sleep, is_sleep = %d\n", is_sleep);
188
189         if(is_sleep){
190                 sleep_in_out = sleep_in;
191                 size = ARRAY_SIZE(sleep_in);
192         }else{
193                 sleep_in_out = sleep_out;
194                 size = ARRAY_SIZE(sleep_out);
195         }
196
197         mipi_set_cmd_mode();
198         mipi_eotp_set(0,0);
199
200         for(i = 0; i <size ; i++){
201                 tag = (sleep_in_out->tag >>24);
202                 if(tag & LCM_TAG_SEND){
203                         mipi_dcs_write(sleep_in_out->data, (sleep_in_out->tag & LCM_TAG_MASK));
204                 }else if(tag & LCM_TAG_SLEEP){
205                         msleep(sleep_in_out->tag & LCM_TAG_MASK);
206                 }
207                 sleep_in_out++;
208         }
209         mipi_eotp_set(0,0);
210
211         return 0;
212 }
213
214 static struct panel_operations lcd_hx8369b_mipi_operations = {
215         .panel_init = hx8369b_mipi_init,
216         .panel_readid = hx8369b_readid,
217         .panel_enter_sleep = hx8369b_enter_sleep,
218 };
219
220 static struct timing_rgb lcd_hx8369b_mipi_timing = {
221         .hfp = 115,  /* unit: pixel */
222         .hbp = 55,
223         .hsync = 50,
224         .vfp = 6, /*unit: line*/
225         .vbp = 19,
226         .vsync = 4,
227 };
228
229
230 static struct info_mipi lcd_hx8369b_mipi_info = {
231         .work_mode  = SPRDFB_MIPI_MODE_VIDEO,
232         .video_bus_width = 24, /*18,16*/
233         .lan_number =   2,
234         .phy_feq =481*1000,
235         .h_sync_pol = SPRDFB_POLARITY_POS,
236         .v_sync_pol = SPRDFB_POLARITY_POS,
237         .de_pol = SPRDFB_POLARITY_POS,
238         .te_pol = SPRDFB_POLARITY_POS,
239         .color_mode_pol = SPRDFB_POLARITY_NEG,
240         .shut_down_pol = SPRDFB_POLARITY_NEG,
241         .timing = &lcd_hx8369b_mipi_timing,
242         .ops = NULL,
243 };
244
245 struct panel_spec lcd_hx8369b_mipi_spec = {
246         .width = 480,
247         .height = 800,
248         .fps    = 60,
249         .type = LCD_MODE_DSI,
250         .direction = LCD_DIRECT_NORMAL,
251         .info = {
252                 .mipi = &lcd_hx8369b_mipi_info
253         },
254         .ops = &lcd_hx8369b_mipi_operations,
255 };
256 struct panel_cfg lcd_hx8369b_mipi = {
257         /* this panel can only be main lcd */
258         .dev_id = SPRDFB_MAINLCD_ID,
259         .lcd_id = 0x8369,
260         .lcd_name = "lcd_hx8369b_mipi",
261         .panel = &lcd_hx8369b_mipi_spec,
262 };
263
264 //temp code
265 static int __init lcd_hx8369b_mipi_init(void)
266 {
267 /*
268         printk("hx8369b_mipi_init: set lcd backlight.\n");
269
270                  if (gpio_request(214, "LCD_BL")) {
271                            printk("Failed ro request LCD_BL GPIO_%d \n",
272                                            214);
273                            return -ENODEV;
274                  }
275                  gpio_direction_output(214, 1);
276                  gpio_set_value(214, 1);
277 */
278
279         return sprdfb_panel_register(&lcd_hx8369b_mipi);
280 }
281
282 subsys_initcall(lcd_hx8369b_mipi_init);
283