tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / video / sprdfb / lcd / lcd_nt35502_mipi.c
1 \r
2 #include <config.h>\r
3 #include <common.h> //huyue added \r
4 #include <asm/arch/sprd_lcd.h>\r
5 #include "../sprdfb.h"\r
6 #define printk printf\r
7 \r
8 #define  LCD_DEBUG\r
9 #ifdef LCD_DEBUG\r
10 #define LCD_PRINT printk\r
11 #else\r
12 #define LCD_PRINT(...)\r
13 #endif\r
14 \r
15 #define MAX_DATA   100\r
16 \r
17 typedef struct LCM_Init_Code_tag {\r
18         unsigned int tag;\r
19         unsigned char data[MAX_DATA];\r
20 }LCM_Init_Code;\r
21 \r
22 typedef struct LCM_force_cmd_code_tag{\r
23         unsigned int datatype;\r
24         LCM_Init_Code real_cmd_code;\r
25 }LCM_Force_Cmd_Code;\r
26 \r
27 #define LCM_TAG_SHIFT 24\r
28 #define LCM_TAG_MASK  ((1 << 24) -1)\r
29 #define LCM_SEND(len) ((1 << LCM_TAG_SHIFT)| len)\r
30 #define LCM_SLEEP(ms) ((2 << LCM_TAG_SHIFT)| ms)\r
31 //#define ARRAY_SIZE(array) ( sizeof(array) / sizeof(array[0]))\r
32 \r
33 #define LCM_TAG_SEND  (1<< 0)\r
34 #define LCM_TAG_SLEEP (1 << 1)\r
35 \r
36 static LCM_Init_Code init_data[] = {\r
37     //Power setting Sequence\r
38         {LCM_SEND(8),{6,0,0xF0,0x55,0xAA,0x52,0x08,0x01}},\r
39          {LCM_SEND(4),{2,0,0xB0,0x08}},\r
40          {LCM_SEND(4),{2,0,0xB2,0x40}},\r
41          {LCM_SEND(4),{2,0,0xB3,0x28}},\r
42          {LCM_SEND(4),{2,0,0xB4,0x19}},\r
43          {LCM_SEND(4),{2,0,0xB5,0x54}},\r
44          {LCM_SEND(4),{2,0,0xB9,0x36}},\r
45          {LCM_SEND(4),{2,0,0xBA,0x024}},\r
46          {LCM_SEND(5),{3,0,0xBC,0xA0,0x00}},\r
47          {LCM_SEND(5),{3,0,0xBD,0xA0,0x00}},\r
48     \r
49         //gamma setting\r
50         {LCM_SEND(19),{17,0,0xD1,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},\r
51         {LCM_SEND(19),{17,0,0xD2,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},\r
52         {LCM_SEND(19),{17,0,0xD3,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},\r
53         {LCM_SEND(7),{5,0,0xD4,0x03,0x5A,0x03,0x9A}},\r
54         {LCM_SEND(19),{17,0,0xD5,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},\r
55         {LCM_SEND(19),{17,0,0xD6,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},\r
56         {LCM_SEND(19),{17,0,0xD7,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},\r
57     {LCM_SEND(7),{5,0,0xD8,0x03,0x5A,0x03,0x9A}},\r
58         {LCM_SEND(19),{17,0,0xD9,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},\r
59         {LCM_SEND(19),{17,0,0xDD,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},\r
60         {LCM_SEND(19),{17,0,0xDE,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},\r
61     {LCM_SEND(7),{5,0,0xDF,0x03,0x5A,0x03,0x9A}},\r
62         {LCM_SEND(19),{17,0,0xE0,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},\r
63         {LCM_SEND(19),{17,0,0xE1,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},\r
64         {LCM_SEND(19),{17,0,0xE2,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},\r
65     {LCM_SEND(7),{5,0,0xE3,0x03,0x5A,0x03,0x9A}},\r
66         {LCM_SEND(19),{17,0,0xE4,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},\r
67         {LCM_SEND(19),{17,0,0xE5,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},\r
68         {LCM_SEND(19),{17,0,0xE6,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},\r
69     {LCM_SEND(7),{5,0,0xE7,0x03,0x5A,0x03,0x9A}},\r
70         {LCM_SEND(19),{17,0,0xE8,0x00,0x3D,0x00,0x67,0x00,0x97,0x00,0xBE,0x00,0xE4,0x01,0x1B,0x01,0x45,0x01,0x80}},\r
71         {LCM_SEND(19),{17,0,0xE9,0x01,0xA8,0x01,0xDF,0x02,0x06,0x02,0x3C,0x02,0x65,0x02,0x66,0x02,0x89,0x02,0xAC}},\r
72         {LCM_SEND(19),{17,0,0xEA,0x02,0xC0,0x02,0xD8,0x02,0xE6,0x02,0xF8,0x03,0x04,0x03,0x14,0x03,0x1E,0x03,0x2B}},\r
73     {LCM_SEND(7),{5,0,0xEB,0x03,0x5A,0x03,0x9A}},\r
74         \r
75         //initializing sequence\r
76         {LCM_SEND(8),{6,0,0xF0,0x55,0xAA,0x52,0x08,0x00}},\r
77         {LCM_SEND(5),{3,0,0xB1,0x16,0x08}},\r
78         {LCM_SEND(5),{3,0,0xB4,0x08,0x50}},\r
79         {LCM_SEND(4),{2,0,0xB6,0x03}},\r
80         {LCM_SEND(5),{3,0,0xB7,0x70,0x70}},\r
81         {LCM_SEND(5),{3,0,0xB8,0x61,0x66}},\r
82         {LCM_SEND(4),{2,0,0xBC,0x02}},\r
83         \r
84         {LCM_SEND(21),{19,0,0xC8,0x80,0x00,0x46,0x64,0x46,0x64,0x46,0x64,0x46,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64}},\r
85         {LCM_SEND(8),{6,0,0xF0,0x55,0xAA,0x52,0x00,0x00}},\r
86         {LCM_SEND(7),{5,0,0xFF,0xAA,0x55,0x25,0x01}},\r
87         {LCM_SEND(4),{2,0,0x6F,0x02}},\r
88         {LCM_SEND(4),{2,0,0xF4,0x57}},\r
89         {LCM_SEND(6),{4,0,0xAA,0x55,0x25,0x00}},\r
90         {LCM_SEND(4),{2,0,0x36,0x00}},\r
91         {LCM_SEND(4),{2,0,0x35,0x00}},\r
92         {LCM_SEND(4),{2,0,0x0B,0xD8}},\r
93         \r
94         //Display on\r
95         {LCM_SEND(1),{0x11}},\r
96         {LCM_SLEEP(120)},\r
97         {LCM_SEND(1),{0x29}},\r
98         {LCM_SLEEP(100)},\r
99 };\r
100 \r
101 static LCM_Init_Code disp_on[] =  {  \r
102         {LCM_SEND(1),{0x11}},\r
103         {LCM_SLEEP(120)},\r
104         {LCM_SEND(1),{0x29}},\r
105         {LCM_SLEEP(100)},\r
106 };\r
107 \r
108 static LCM_Init_Code sleep_in[] =  {\r
109         {LCM_SEND(1), {0x28}},\r
110         {LCM_SLEEP(150)},       //>150ms\r
111         {LCM_SEND(1), {0x10}},\r
112         {LCM_SLEEP(150)},       //>150ms\r
113 };\r
114 \r
115 static LCM_Init_Code sleep_out[] =  {\r
116         {LCM_SEND(1), {0x11}},\r
117         {LCM_SLEEP(120)},//>120ms\r
118         {LCM_SEND(1), {0x29}},\r
119         {LCM_SLEEP(20)}, //>20ms\r
120 };\r
121 \r
122 static int32_t nt35502_mipi_init(struct panel_spec *self)\r
123 {\r
124         int32_t i;\r
125         LCM_Init_Code *init = init_data;\r
126         unsigned int tag;\r
127 \r
128         mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;\r
129         mipi_dcs_write_t mipi_dcs_write = self->info.mipi->ops->mipi_dcs_write;         \r
130         mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;\r
131 \r
132         LCD_PRINT("lcd_nt35502_init\n");\r
133 \r
134         mipi_set_cmd_mode();\r
135         mipi_eotp_set(0,0);\r
136 \r
137         for(i = 0; i < ARRAY_SIZE(init_data); i++){\r
138                 tag = (init->tag >>24);\r
139                 if(tag & LCM_TAG_SEND){\r
140                         mipi_dcs_write(init->data, (init->tag & LCM_TAG_MASK));\r
141                         udelay(20);\r
142                 }else if(tag & LCM_TAG_SLEEP){\r
143                         mdelay(init->tag & LCM_TAG_MASK);//udelay((init->tag & LCM_TAG_MASK) * 1000);\r
144                 }\r
145                 init++;\r
146         }\r
147 \r
148         mipi_eotp_set(0,0);\r
149 \r
150         return 0;\r
151 }\r
152 \r
153 static uint32_t nt35502_readid(struct panel_spec *self)\r
154 {\r
155         uint32 j =0;\r
156         uint8_t read_data[4] = {0};\r
157         int32_t read_rtn = 0;\r
158         uint8_t param[2] = {0};\r
159         mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;\r
160         mipi_force_write_t mipi_force_write = self->info.mipi->ops->mipi_force_write;\r
161         mipi_force_read_t mipi_force_read = self->info.mipi->ops->mipi_force_read;\r
162         mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;\r
163 \r
164         LCD_PRINT("lcd_nt35502_mipi read id!\n");\r
165 \r
166         mipi_set_cmd_mode();\r
167         mipi_eotp_set(0,0);\r
168 \r
169         for(j = 0; j < 4; j++){\r
170                 param[0] = 0x01;\r
171                 param[1] = 0x00;\r
172                 \r
173                 mipi_force_write(0x04, param, 2);\r
174 \r
175                 read_rtn = mipi_force_read(0xda,1,&read_data[0]);\r
176                 LCD_PRINT("lcd_nt35502_mipi read id 0xda value is 0x%x!\n",read_data[0]);\r
177 \r
178                 read_rtn = mipi_force_read(0xdb,1,&read_data[1]);\r
179                 LCD_PRINT("lcd_nt35502_mipi read id 0xdb value is 0x%x!\n",read_data[1]);\r
180 \r
181                 read_rtn = mipi_force_read(0xdc,1,&read_data[2]);\r
182                 LCD_PRINT("lcd_nt35502_mipi read id 0xdc value is 0x%x!\n",read_data[2]);\r
183 \r
184                 if((0x55 == read_data[0])&&(0x4c == read_data[1])&&(0xc0 == read_data[2])){\r
185                                 printk("lcd_nt35502_mipi read id success!\n");\r
186                                 return 0x8370;\r
187                         }\r
188         }\r
189 \r
190         mipi_eotp_set(0,0);\r
191 \r
192         return 0;\r
193 }\r
194 \r
195 static struct panel_operations lcd_nt35502_mipi_operations = {\r
196         .panel_init = nt35502_mipi_init,\r
197         .panel_readid = nt35502_readid,\r
198 };\r
199 \r
200 static struct timing_rgb lcd_nt35502_mipi_timing = {\r
201         .hfp = 160,  /* unit: pixel */\r
202         .hbp = 20,\r
203         .hsync = 20,\r
204         .vfp = 6, /*unit: line*/\r
205         .vbp = 6,\r
206         .vsync = 4,\r
207 };\r
208 \r
209 \r
210 static struct info_mipi lcd_nt35502_mipi_info = {\r
211         .work_mode  = SPRDFB_MIPI_MODE_VIDEO,\r
212         .video_bus_width = 24, /*18,16*/\r
213         .lan_number =   2,\r
214         .phy_feq =500*1000,\r
215         .h_sync_pol = SPRDFB_POLARITY_POS,\r
216         .v_sync_pol = SPRDFB_POLARITY_POS,\r
217         .de_pol = SPRDFB_POLARITY_POS,\r
218         .te_pol = SPRDFB_POLARITY_POS,\r
219         .color_mode_pol = SPRDFB_POLARITY_NEG,\r
220         .shut_down_pol = SPRDFB_POLARITY_NEG,\r
221         .timing = &lcd_nt35502_mipi_timing,\r
222         .ops = NULL,\r
223 };\r
224 \r
225 struct panel_spec lcd_nt35502_mipi_spec = {\r
226         .width = 480,\r
227         .height = 800,\r
228         .fps = 62,\r
229         .type = LCD_MODE_DSI,\r
230         .direction = LCD_DIRECT_NORMAL,\r
231         .info = {\r
232                 .mipi = &lcd_nt35502_mipi_info\r
233         },\r
234         .ops = &lcd_nt35502_mipi_operations,\r
235 };\r
236 \r