import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / lcm / hx8389b_qhd_dsi_vdo_tianma / hx8389b_qhd_dsi_vdo_tianma.c
CommitLineData
6fa3eb70
S
1#ifndef BUILD_LK
2#include <linux/string.h>
3#endif
4#include "lcm_drv.h"
5
6#ifdef BUILD_LK
7 #include <platform/mt_gpio.h>
8 #include <string.h>
9#elif defined(BUILD_UBOOT)
10 #include <asm/arch/mt_gpio.h>
11#else
12 #include <mach/mt_gpio.h>
13#endif
14// ---------------------------------------------------------------------------
15// Local Constants
16// ---------------------------------------------------------------------------
17
18#define FRAME_WIDTH (540)
19#define FRAME_HEIGHT (960)
20
21#define LCM_ID_HX8389B 0x89
22
23
24#ifndef TRUE
25 #define TRUE 1
26#endif
27
28#ifndef FALSE
29 #define FALSE 0
30#endif
31
32 unsigned int lcm_esd_test = FALSE; ///only for ESD test
33
34// ---------------------------------------------------------------------------
35// Local Variables
36// ---------------------------------------------------------------------------
37
38static LCM_UTIL_FUNCS lcm_util ;
39
40#define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
41
42#define UDELAY(n) (lcm_util.udelay(n))
43#define MDELAY(n) (lcm_util.mdelay(n))
44
45
46// ---------------------------------------------------------------------------
47// Local Functions
48// ---------------------------------------------------------------------------
49#define dsi_set_cmdq_V3(para_tbl,size,force_update) lcm_util.dsi_set_cmdq_V3(para_tbl,size,force_update)
50#define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
51#define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
52#define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
53#define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
54#define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
55#define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
56
57#define LCM_DSI_CMD_MODE 0
58
59static LCM_setting_table_V3 lcm_initialization_setting[] = {
60
61 /*
62 Note :
63
64 Data ID will depends on the following rule.
65
66 count of parameters > 1 => Data ID = 0x39
67 count of parameters = 1 => Data ID = 0x15
68 count of parameters = 0 => Data ID = 0x05
69
70 Structure Format :
71
72 {DCS command, count of parameters, {parameter list}}
73 {REGFLAG_DELAY, milliseconds of time, {}},
74
75 ...
76
77 Setting ending by predefined flag
78
79 {REGFLAG_END_OF_TABLE, 0x00, {}}
80 */
81
82 {0x39,0xB9,3,{0xFF,0x83,0x89}},
83 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 1, {}},
84
85 {0x39,0xBA,7,{0x41,0x93,0x00,0x16,0xA4,0x10,0x18}},
86 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 1, {}},
87
88 {0x15,0xC6,1,{0xE8}},
89//------------ HX5186 set power-------------------------------//
90
91 {0x39,0xB1,19,{0x00,0x00,0x04,0xE8,0x99,0x10,0x11,0xD1,0xf1,0x36,
92 0x3e,0x2A,0x2A,0x43,0x01,0x5a,0xF2,0x20,0x80}},
93 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 10, {}},
94
95//------------------------------------------------------
96 {0x39,0xDE,3,{0x05,0x58,0x12}},
97
98 {0x39,0xB2,7,{0x00,0x00,0x78,0x0E,0x05,0x3F,0x80}},
99 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 1, {}},
100
101 {0x39,0xB4,23,{0x80,0x08,0x00,0x32,0x10,0x07,0x32,0x10,0x02,0x32,
102 0x10,0x00,0x37,0x05,0x40,0x0B,0x37,0x05,0x48,0x14,
103 0x50,0x53,0x0a}},
104 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 10, {}},
105 {0x39,0xD5,48,{0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0x60,0x00,
106 0x99,0x88,0x88,0x88,0x88,0x23,0x88,0x01,0x88,0x67,
107 0x88,0x45,0x01,0x23,0x23,0x45,0x88,0x88,0x88,0x88,
108 0x99,0x88,0x88,0x88,0x54,0x88,0x76,0x88,0x10,0x88,
109 0x32,0x32,0x10,0x88,0x54,0x88,0x88,0x88}},
110 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 10, {}},
111 {0x39,0xC1,32,{0x01,0x00,0x08,0x10,0x18,0x21,0x28,0x30,0x38,0x41,
112 0x49,0x51,0x59,0x61,0x68,0x70,0x78,0x81,0x89,0x90,
113 0x98,0xA0,0xA8,0xB0,0xB8,0xC1,0xC9,0xD1,0xD7,0xE2,
114 0xEA,0xF2}},
115 {0x29,0xc1,32,{0xF8,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
116 0x00,0x00,0x08,0x10,0x18,0x20,0x28,0x30,0x38,0x40,
117 0x48,0x50,0x58,0x60,0x68,0x70,0x78,0x80,0x88,0x90,
118 0x98,0xA0}},
119
120
121 {0x29,0xc1,32,{0xA8,0xB0,0xB8,0xC0,0xC8,0xD0,0xD8,0xE0,0xE8,0xF0,
122 0xF8,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
123 0x00,0x00,0x08,0x10,0x18,0x22,0x2A,0x32,0x3B,0x43,
124 0x4B,0x54}},
125 {0x29,0xc1,31,{0x5C,0x64,0x6C,0x74,0x7D,0x85,0x8E,0x96,0x9E,0xA6,
126 0xAE,0xB6,0xBE,0xC6,0xCE,0xD6,0xDE,0xE5,0xED,0xF5,
127 0xF8,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
128 0x00}},
129 {0x39,0xE0,34,{0x16,0x2C,0x32,0x30,0x35,0x3F,0x3D,0x52,0x08,0x0E,
130 0x0F,0x13,0x15,0x13,0x14,0x19,0x1C,0x16,0x2C,0x32,
131 0x30,0x35,0x3F,0x3D,0x52,0x07,0x0D,0x0F,0x13,0x15,
132 0x13,0x14,0x19,0x1C}},
133
134 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 5, {}},
135
136 {0x39,0xB6,4,{0x00,0x88,0x00,0x88}},
137 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 1, {}},
138
139
140 {0x15,0xCC,1,{0x02}},
141
142
143 {0x39,0xB7,3,{0x00,0x00,0x50}},
144
145
146 {0x15,0x51,1,{0xFF}},
147 {0x15,0x53,1,{0x2C}},
148 {0x15,0x55,1,{0x02}},
149
150
151 {0x05,0x11,0,{}},
152 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 120, {}},
153 {0x05,0x29,0,{}},
154 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 10, {}},
155
156
157
158};
159
160
161// ---------------------------------------------------------------------------
162// LCM Driver Implementations
163// ---------------------------------------------------------------------------
164
165static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
166{
167 memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
168}
169
170
171static void lcm_get_params(LCM_PARAMS *params)
172{
173 memset(params, 0, sizeof(LCM_PARAMS));
174
175 params->type = LCM_TYPE_DSI;
176
177 params->width = FRAME_WIDTH;
178 params->height = FRAME_HEIGHT;
179
180 #if (LCM_DSI_CMD_MODE)
181 params->dsi.mode = CMD_MODE;
182 #else
183 params->dsi.mode = SYNC_PULSE_VDO_MODE; //SYNC_PULSE_VDO_MODE;//BURST_VDO_MODE;
184 #endif
185
186 // DSI
187 /* Command mode setting */
188 //1 Three lane or Four lane
189 params->dsi.LANE_NUM = LCM_TWO_LANE;
190 //The following defined the fomat for data coming from LCD engine.
191 params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
192
193 // Video mode setting
194 params->dsi.PS=LCM_PACKED_PS_24BIT_RGB888;
195
196 params->dsi.vertical_sync_active = 0x05;// 3 2
197 params->dsi.vertical_backporch = 14;// 20 1
198 params->dsi.vertical_frontporch = 12; // 1 12
199 params->dsi.vertical_active_line = FRAME_HEIGHT;
200
201 params->dsi.horizontal_sync_active = 0x16;// 50 2
202 params->dsi.horizontal_backporch = 0x38;
203 params->dsi.horizontal_frontporch = 0x18;
204 params->dsi.horizontal_active_pixel = FRAME_WIDTH;
205
206 //params->dsi.LPX=8;
207
208 // Bit rate calculation
209 //1 Every lane speed
210 //params->dsi.pll_select=1;
211 //params->dsi.PLL_CLOCK = LCM_DSI_6589_PLL_CLOCK_377;
212 params->dsi.PLL_CLOCK=250;
213 //params->dsi.pll_div1=0; // div1=0,1,2,3;div1_real=1,2,4,4 ----0: 546Mbps 1:273Mbps
214 //params->dsi.pll_div2=0; // div2=0,1,2,3;div1_real=1,2,4,4
215#if (LCM_DSI_CMD_MODE)
216 //params->dsi.fbk_div =9;
217#else
218 //params->dsi.fbk_div =9; // fref=26MHz, fvco=fref*(fbk_div+1)*2/(div1_real*div2_real)
219#endif
220 //params->dsi.compatibility_for_nvk = 1; // this parameter would be set to 1 if DriverIC is NTK's and when force match DSI clock for NTK's
221}
222
223static void lcm_init(void)
224{
225
226
227 SET_RESET_PIN(0);
228 MDELAY(20);
229 SET_RESET_PIN(1);
230 MDELAY(20);
231 dsi_set_cmdq_V3(lcm_initialization_setting,sizeof(lcm_initialization_setting)/sizeof(lcm_initialization_setting[0]),1);
232
233
234
235}
236
237
238
239static void lcm_suspend(void)
240{
241 unsigned int data_array[16];
242
243 //data_array[0]=0x00280500; // Display Off
244 //dsi_set_cmdq(data_array, 1, 1);
245
246 data_array[0] = 0x00100500; // Sleep In
247 dsi_set_cmdq(data_array, 1, 1);
248 MDELAY(120);
249
250
251 SET_RESET_PIN(1);
252 SET_RESET_PIN(0);
253 MDELAY(20); // 1ms
254
255 SET_RESET_PIN(1);
256 MDELAY(120);
257}
258
259
260static void lcm_resume(void)
261{
262 lcm_init();
263
264 #ifdef BUILD_LK
265 printf("[LK]------hx8389b----%s------\n",__func__);
266 #else
267 printk("[KERNEL]------hx8389b----%s------\n",__func__);
268 #endif
269}
270
271#if (LCM_DSI_CMD_MODE)
272static void lcm_update(unsigned int x, unsigned int y,
273 unsigned int width, unsigned int height)
274{
275 unsigned int x0 = x;
276 unsigned int y0 = y;
277 unsigned int x1 = x0 + width - 1;
278 unsigned int y1 = y0 + height - 1;
279
280 unsigned char x0_MSB = ((x0>>8)&0xFF);
281 unsigned char x0_LSB = (x0&0xFF);
282 unsigned char x1_MSB = ((x1>>8)&0xFF);
283 unsigned char x1_LSB = (x1&0xFF);
284 unsigned char y0_MSB = ((y0>>8)&0xFF);
285 unsigned char y0_LSB = (y0&0xFF);
286 unsigned char y1_MSB = ((y1>>8)&0xFF);
287 unsigned char y1_LSB = (y1&0xFF);
288
289 unsigned int data_array[16];
290
291 data_array[0]= 0x00053902;
292 data_array[1]= (x1_MSB<<24)|(x0_LSB<<16)|(x0_MSB<<8)|0x2a;
293 data_array[2]= (x1_LSB);
294 dsi_set_cmdq(data_array, 3, 1);
295
296 data_array[0]= 0x00053902;
297 data_array[1]= (y1_MSB<<24)|(y0_LSB<<16)|(y0_MSB<<8)|0x2b;
298 data_array[2]= (y1_LSB);
299 dsi_set_cmdq(data_array, 3, 1);
300
301 data_array[0]= 0x002c3909;
302 dsi_set_cmdq(data_array, 1, 0);
303
304}
305#endif
306
307static unsigned int lcm_compare_id(void)
308{
309 unsigned int id,id1=0;
310 unsigned char buffer[2];
311 unsigned int array[16];
312
313 SET_RESET_PIN(0);
314 MDELAY(20);
315 SET_RESET_PIN(1);
316 MDELAY(20);
317
318
319 array[0]=0x00043902;
320 array[1]=0x8983FFB9;// page enable
321 dsi_set_cmdq(array, 2, 1);
322 //MDELAY(10);
323//{0x39,0xBA,7,{0x41,0x93,0x00,0x16,0xA4,0x10,0x18}},
324 array[0]=0x00083902;
325 array[1]=0x009341BA;// page enable
326 array[2]=0x1810a416;
327 dsi_set_cmdq(array, 3, 1);
328
329 array[0] = 0x00043700;// return byte number
330 dsi_set_cmdq(array, 1, 1);
331 MDELAY(10);
332
333 read_reg_v2(0xF4, buffer, 3);
334 id = buffer[1];
335 id1 = buffer[0];
336
337#ifdef BUILD_LK
338 printf("%s, id = 0x%08x id1=%x \n", __func__, id,id1);
339#else
340 printk("%s, id = 0x%08x id1=%x \n",__func__, id,id1);
341#endif
342
343 return (LCM_ID_HX8389B == id)?1:0;
344
345}
346
347
348
349static unsigned int lcm_esd_check(void)
350{
351 unsigned int ret=FALSE;
352 #ifndef BUILD_LK
353 char buffer[6];
354 int array[4];
355
356#if 1
357 if(lcm_esd_test)
358 {
359 lcm_esd_test = FALSE;
360 return TRUE;
361 }
362#endif
363 array[0] = 0x00083700;
364 dsi_set_cmdq(array, 1, 1);
365
366 read_reg_v2(0x0A, buffer, 2);
367 //printk(" esd buffer0 =%x,buffer1 =%x \n",buffer[0],buffer[1]);
368 //read_reg_v2(0x09,buffer,5);
369 //printk(" esd buffer0=%x, buffer1 =%x buffer2=%x,buffer3=%x,buffer4=%x \n",buffer[0],buffer[1],buffer[2],buffer[3],buffer[4]);
370#if 1
371 if(buffer[0]==0x1C)
372 {
373 ret=FALSE;
374 }
375 else
376 {
377 ret=TRUE;
378 }
379#endif
380 #endif
381 return ret;
382
383}
384
385static unsigned int lcm_esd_recover(void)
386{
387 lcm_init();
388
389 #ifndef BUILD_LK
390 printk("lcm_esd_recover hx8389b_video_tianma \n");
391 #endif
392 return TRUE;
393}
394
395
396
397
398LCM_DRIVER hx8389b_qhd_dsi_vdo_tianma_lcm_drv =
399{
400 .name = "hx8389b_qhd_dsi_vdo_tianma",
401 .set_util_funcs = lcm_set_util_funcs,
402 .get_params = lcm_get_params,
403 .init = lcm_init,
404 .suspend = lcm_suspend,
405 .resume = lcm_resume,
406 .compare_id = lcm_compare_id,
407 .esd_check = lcm_esd_check,
408 .esd_recover = lcm_esd_recover,
409#if (LCM_DSI_CMD_MODE)
410 .update = lcm_update,
411#endif
412 };