import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / lcm / otm8018b_dsi_vdo_trust / otm8018b_dsi_vdo_trust.c
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 // ---------------------------------------------------------------------------
16 //RGK add
17 // ---------------------------------------------------------------------------
18 //#include <cust_adc.h> // zhoulidong add for lcm detect
19 #define AUXADC_LCM_VOLTAGE_CHANNEL 0
20 #define AUXADC_ADC_FDD_RF_PARAMS_DYNAMIC_CUSTOM_CH_CHANNEL 1
21
22 #define MIN_VOLTAGE (0) // zhoulidong add for lcm detect
23 #define MAX_VOLTAGE (100) // zhoulidong add for lcm detect
24 // ---------------------------------------------------------------------------
25 // Local Constants
26 // ---------------------------------------------------------------------------
27
28 #define FRAME_WIDTH (480)
29 #define FRAME_HEIGHT (800)
30
31 #define LCM_ID_OTM8018B 0x8009
32
33 #ifndef TRUE
34 #define TRUE 1
35 #endif
36
37 #ifndef FALSE
38 #define FALSE 0
39 #endif
40
41 unsigned static int lcm_esd_test = FALSE; ///only for ESD test
42
43 // ---------------------------------------------------------------------------
44 // Local Variables
45 // ---------------------------------------------------------------------------
46
47 static LCM_UTIL_FUNCS lcm_util ;
48
49 #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
50
51 #define UDELAY(n) (lcm_util.udelay(n))
52 #define MDELAY(n) (lcm_util.mdelay(n))
53
54
55 // ---------------------------------------------------------------------------
56 // Local Functions
57 // ---------------------------------------------------------------------------
58 #define dsi_set_cmdq_V3(para_tbl,size,force_update) lcm_util.dsi_set_cmdq_V3(para_tbl,size,force_update)
59 #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
60 #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
61 #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
62 #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
63 #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
64 #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
65
66 #define LCM_DSI_CMD_MODE 0
67
68 // zhoulidong add for lcm detect ,read adc voltage
69 extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int* rawdata);
70
71
72 static LCM_setting_table_V3 lcm_initialization_setting[] = {
73
74 {0x15, 0x00,1,{0x00}},
75 {0x39, 0xFF,3,{0x80,0x09,0x01}},
76
77 {0x15, 0x00,1,{0x80}},
78 {0x39, 0xFF,2,{0x80,0x09}}, // enable Orise mode
79
80 {0x15, 0x00,1,{0x03}},
81 {0x15, 0xff,1,{0x01}},// enable SPI+I2C cmd2 read
82
83 {0x15, 0x00,1,{0xB4}},
84 {0x15, 0xc0,1,{0x10}},//1+2dot inversion
85
86 {0x15, 0x00,1,{0x82}},
87 {0x15, 0xc5,1,{0xa3}},
88
89 {0x15, 0x00,1,{0x90}},
90 {0x39, 0xc5,2,{0x96,0x76}},//Pump setting (3x=D6)-->(2x=96)//v02 01/11 d5 87
91
92 {0x15, 0x00,1,{0x00}},
93 {0x39, 0xd8,2,{0x72,0x75}},//GVDD=4.5V
94
95 {0x15, 0x00,1,{0x00}},
96 {0x15, 0xd9,1,{0x69}},// VCOMDC=
97
98 {0x15, 0x00,1,{0x81}},
99 {0x15, 0xc1,1,{0x77}}, //Frame rate 65Hz//V02///66
100
101 {0x15, 0x00,1,{0x89}},
102 {0x15, 0xc4,1,{0x08}},
103
104 {0x15, 0x00,1,{0xa2}},
105 {0x39, 0xc0,3,{0x04,0x00,0x02}},
106
107 {0x15, 0x00,1,{0x80}},
108 {0x15, 0xc4,1,{0x30}},
109
110 {0x15, 0x00,1,{0xa6}},
111 {0x15, 0xc1,1,{0x01}},
112
113 {0x15, 0x00,1,{0xc0}},
114 {0x15, 0xc5,1,{0x00}},
115
116 {0x15, 0x00,1,{0x8b}},
117 {0x15, 0xb0,1,{0x40}},
118
119 {0x15, 0x00,1,{0xb2}},
120 {0x39, 0xf5,4,{0x15,0x00,0x15,0x00}},
121
122 {0x15, 0x00,1,{0x93}},
123 {0x15, 0xc5,1,{0x03}},
124
125 {0x15, 0x00,1,{0x81}},
126 {0x15, 0xc4,1,{0x83}},
127
128 {0x15, 0x00,1,{0x92}},
129 {0x15, 0xc5,1,{0x01}},
130
131 {0x15, 0x00,1,{0xb1}},
132 {0x15, 0xc5,1,{0xa9}},
133
134 {0x15, 0x00,1,{0x90}},
135 {0x39, 0xc0,6,{0x00,0x44,0x00,0x00,0x00,0x03}},
136
137 {0x15, 0x00,1,{0xa6}},
138 {0x39, 0xc1,3,{0x00,0x00,0x00}},
139
140 //{0x00,1,{0xa0}},
141 //{0xc1,1,{0xea}},
142
143 {0x15, 0x00,1,{0x80}},
144 {0x39, 0xce,12,{0x87,0x03,0x00,0x85,0x03,0x00,0x86,0x03,0x00,0x84,0x03,0x00}},
145
146 //CEAx : clka1, clka2
147 {0x15, 0x00,1,{0xa0}},
148 {0x39, 0xce,14,{0x38,0x03,0x03,0x20,0x00,0x00,0x00,0x38,0x02,0x03,0x21,0x00,0x00,0x00}},
149
150 //CEBx : clka3, clka4
151 {0x15, 0x00,1,{0xb0}},
152 {0x39, 0xce,14,{0x38,0x01,0x03,0x22,0x00,0x00,0x00,0x38,0x00,0x03,0x23,0x00,0x00,0x00}},
153
154 //CECx : clkb1, clkb2
155 {0x15, 0x00,1,{0xc0}},
156 {0x39, 0xce,14,{0x30,0x00,0x03,0x24,0x00,0x00,0x00,0x30,0x01,0x03,0x25,0x00,0x00,0x00}},
157
158 //CEDx : clkb3, clkb4
159 {0x15, 0x00,1,{0xd0}},
160 {0x39, 0xce,14,{0x30,0x02,0x03,0x26,0x00,0x00,0x00,0x30,0x03,0x03,0x27,0x00,0x00,0x00}},
161
162 //CFDx :
163 {0x15, 0x00,1,{0xc7}},
164 {0x15, 0xcf,1,{0x00}},
165
166 {0x15, 0x00,1,{0xc9}},
167 {0x15, 0xcf,1,{0x00}},
168
169 {0x15, 0x00,1,{0xc4}},
170 {0x39, 0xcb,6,{0x04,0x04,0x04,0x04,0x04,0x04}},
171
172 {0x15, 0x00,1,{0xd9}},
173 {0x39, 0xcb,6,{0x04,0x04,0x04,0x04,0x04,0x04}},
174
175 {0x15, 0x00,1,{0x84}},
176 {0x39, 0xcc,6,{0x0c,0x0a,0x10,0x0e,0x03,0x04}},
177
178 {0x15, 0x00,1,{0x9e}},
179 {0x15, 0xcc,1,{0x0b}},
180
181 {0x15, 0x00,1,{0xa0}},
182 {0x39, 0xcc,5,{0x09,0x0f,0x0d,0x01,0x02}},
183
184 {0x15, 0x00,1,{0xb4}},
185 {0x39, 0xcc,6,{0x0d,0x0f,0x09,0x0b,0x02,0x01}},
186
187 {0x15, 0x00,1,{0xce}},
188 {0x15, 0xcc,1,{0x0e}},
189
190 {0x15, 0x00,1,{0xd0}},
191 {0x39, 0xcc,5,{0x10,0x0a,0x0c,0x04,0x03}},
192
193 {0x15, 0x00,1,{0x00}},
194 {0x39, 0xe1,16,{0x00,0x02,0x04,0x0c,0x06,0x1c,0x0f,0x0f,0x00,0x04,0x01,0x07,0x0e,0x23,0x20,0x14}},
195
196 {0x15, 0x00,1,{0x00}},
197 {0x39, 0xe2,16,{0x00,0x02,0x04,0x0c,0x06,0x1c,0x0f,0x0f,0x00,0x04,0x02,0x07,0x0e,0x24,0x20,0x14}},
198
199
200 //{0x00,1,{0x00}},
201 //{0xE1,16,{0x09,0x0B,0x0F,0x0E,0x0A,0x1B,0x0A,0x0A,0x00,0x03,0x03,0x05,0x0F,0x24,0x1E,0x03}},
202
203 //{0x00,1,{0x00}},
204 //{0xE2,16,{0x09,0x0B,0x0F,0x11,0x0E,0x1F,0x0A,0x0A,0x00,0x03,0x03,0x05,0x0F,0x22,0x1E,0x03}},
205
206 {0x15, 0x00,1,{0x00}},
207 {0x39, 0xff,3,{0xff,0xff,0xff,}},
208
209
210 {0x15, 0x35,1,{0x00}}, //open the TE zzf add
211
212 {0x15, 0x3A,1,{0x77}},
213 {0x05,0x11,0,{}},
214 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 120, {}},
215 {0x05, 0x29,0,{}},
216 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 10, {}},
217
218 };
219
220 // ---------------------------------------------------------------------------
221 // LCM Driver Implementations
222 // ---------------------------------------------------------------------------
223
224 static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
225 {
226 memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
227 }
228
229
230 static void lcm_get_params(LCM_PARAMS *params)
231 {
232
233 memset(params, 0, sizeof(LCM_PARAMS));
234
235 params->type = LCM_TYPE_DSI;
236
237 params->width = FRAME_WIDTH;
238 params->height = FRAME_HEIGHT;
239
240 #if (LCM_DSI_CMD_MODE)
241 params->dsi.mode = CMD_MODE;
242 #else
243 params->dsi.mode = SYNC_PULSE_VDO_MODE; //SYNC_PULSE_VDO_MODE;//BURST_VDO_MODE;
244 #endif
245
246 // DSI
247 /* Command mode setting */
248 //1 Three lane or Four lane
249 params->dsi.LANE_NUM = LCM_TWO_LANE;
250
251 //The following defined the fomat for data coming from LCD engine.
252 params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
253
254 // Video mode setting
255 params->dsi.PS=LCM_PACKED_PS_24BIT_RGB888;
256
257 params->dsi.vertical_sync_active = 4;
258 params->dsi.vertical_backporch = 16;
259 params->dsi.vertical_frontporch = 15;
260 params->dsi.vertical_active_line = FRAME_HEIGHT;
261
262 params->dsi.horizontal_sync_active = 6;
263 params->dsi.horizontal_backporch = 37;
264 params->dsi.horizontal_frontporch = 37;
265 params->dsi.horizontal_active_pixel = FRAME_WIDTH;
266
267 //params->dsi.LPX=8;
268
269 // Bit rate calculation
270 //1 Every lane speed
271 //params->dsi.pll_select=1;
272 //params->dsi.PLL_CLOCK = LCM_DSI_6589_PLL_CLOCK_377;
273 params->dsi.PLL_CLOCK=169;
274 params->dsi.pll_div1=0; // div1=0,1,2,3;div1_real=1,2,4,4 ----0: 546Mbps 1:273Mbps
275 params->dsi.pll_div2=0; // div2=0,1,2,3;div1_real=1,2,4,4
276 #if (LCM_DSI_CMD_MODE)
277 params->dsi.fbk_div =7;
278 #else
279 params->dsi.fbk_div =7; // fref=26MHz, fvco=fref*(fbk_div+1)*2/(div1_real*div2_real)
280 #endif
281 //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
282
283 }
284
285
286 static void lcm_init(void)
287 {
288 SET_RESET_PIN(1);
289 SET_RESET_PIN(0);
290 MDELAY(10);
291 SET_RESET_PIN(1);
292 MDELAY(120);
293
294 dsi_set_cmdq_V3(lcm_initialization_setting,sizeof(lcm_initialization_setting)/sizeof(lcm_initialization_setting[0]),1);
295
296 }
297
298
299 static LCM_setting_table_V3 lcm_deep_sleep_mode_in_setting[] = {
300 // Display off sequence
301 {0x05, 0x28, 0, {}},
302 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 10, {}},
303
304 // Sleep Mode On
305 {0x05, 0x10, 0, {}},
306 {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 120, {}},
307 };
308 static void lcm_suspend(void)
309 {
310 dsi_set_cmdq_V3(lcm_deep_sleep_mode_in_setting, sizeof(lcm_deep_sleep_mode_in_setting)/sizeof(lcm_deep_sleep_mode_in_setting[0]), 1);
311
312 SET_RESET_PIN(1);
313 SET_RESET_PIN(0);
314 MDELAY(20); // 1ms
315
316 SET_RESET_PIN(1);
317 MDELAY(120);
318 }
319
320
321 static void lcm_resume(void)
322 {
323 lcm_init();
324
325 }
326
327 #if (LCM_DSI_CMD_MODE)
328 static void lcm_update(unsigned int x, unsigned int y,
329 unsigned int width, unsigned int height)
330 {
331 unsigned int x0 = x;
332 unsigned int y0 = y;
333 unsigned int x1 = x0 + width - 1;
334 unsigned int y1 = y0 + height - 1;
335
336 unsigned char x0_MSB = ((x0>>8)&0xFF);
337 unsigned char x0_LSB = (x0&0xFF);
338 unsigned char x1_MSB = ((x1>>8)&0xFF);
339 unsigned char x1_LSB = (x1&0xFF);
340 unsigned char y0_MSB = ((y0>>8)&0xFF);
341 unsigned char y0_LSB = (y0&0xFF);
342 unsigned char y1_MSB = ((y1>>8)&0xFF);
343 unsigned char y1_LSB = (y1&0xFF);
344
345 unsigned int data_array[16];
346
347 data_array[0]= 0x00053902;
348 data_array[1]= (x1_MSB<<24)|(x0_LSB<<16)|(x0_MSB<<8)|0x2a;
349 data_array[2]= (x1_LSB);
350 dsi_set_cmdq(data_array, 3, 1);
351
352 data_array[0]= 0x00053902;
353 data_array[1]= (y1_MSB<<24)|(y0_LSB<<16)|(y0_MSB<<8)|0x2b;
354 data_array[2]= (y1_LSB);
355 dsi_set_cmdq(data_array, 3, 1);
356
357 data_array[0]= 0x002c3909;
358 dsi_set_cmdq(data_array, 1, 0);
359
360 }
361 #endif
362
363
364
365
366
367 // zhoulidong add for lcm detect (start)
368
369 static unsigned int lcm_compare_id(void)
370 {
371 int array[4];
372 char buffer[5];
373 char id_high=0;
374 char id_low=0;
375 int id=0;
376
377 SET_RESET_PIN(1);
378 SET_RESET_PIN(0);
379 MDELAY(10);
380 SET_RESET_PIN(1);
381 MDELAY(200);
382
383 array[0] = 0x00053700;
384 dsi_set_cmdq(array, 1, 1);
385 read_reg_v2(0xa1, buffer, 5);
386
387 id_high = buffer[2];
388 id_low = buffer[3];
389 id = (id_high<<8) | id_low;
390
391
392 #ifdef BUILD_LK
393 #else
394
395 #if defined(BUILD_UBOOT)
396 printf("OTM8018B uboot %s \n", __func__);
397 printf("%s id = 0x%08x \n", __func__, id);
398 #else
399 printk("OTM8018B kernel %s \n", __func__);
400 printk("%s id = 0x%08x \n", __func__, id);
401 #endif
402 #endif
403
404 return 1;
405 }
406
407 // zhoulidong add for lcm detect (start)
408 static unsigned int rgk_lcm_compare_id(void)
409 {
410 int data[4] = {0,0,0,0};
411 int res = 0;
412 int rawdata = 0;
413 int lcm_vol = 0;
414 #ifdef AUXADC_LCM_VOLTAGE_CHANNEL
415 res = IMM_GetOneChannelValue(AUXADC_LCM_VOLTAGE_CHANNEL,data,&rawdata);
416 if(res < 0)
417 {
418 #ifdef BUILD_LK
419 printf("[adc_uboot]: get data error\n");
420 #endif
421 return 0;
422
423 }
424 #endif
425
426 lcm_vol = data[0]*1000+data[1]*10;
427
428 #ifdef BUILD_LK
429 printf("[adc_uboot]: lcm_vol= %d\n",lcm_vol);
430 #endif
431
432 if (lcm_vol>=MIN_VOLTAGE &&lcm_vol <= MAX_VOLTAGE)
433 {
434 return 1;
435 }
436
437 return 0;
438
439 }
440
441
442 // zhoulidong add for lcm detect (end)
443
444 // zhoulidong add for eds(start)
445 static unsigned int lcm_esd_check(void)
446 {
447 #ifdef BUILD_LK
448 //printf("lcm_esd_check()\n");
449 #else
450 //printk("lcm_esd_check()\n");
451 #endif
452 #ifndef BUILD_LK
453 char buffer[3];
454 int array[4];
455
456 if(lcm_esd_test)
457 {
458 lcm_esd_test = FALSE;
459 return TRUE;
460 }
461
462 array[0] = 0x00013700;
463 dsi_set_cmdq(array, 1, 1);
464
465 read_reg_v2(0x0a, buffer, 1);
466 if(buffer[0]==0x9c)
467 {
468 //#ifdef BUILD_LK
469 //printf("%s %d\n FALSE", __func__, __LINE__);
470 //#else
471 //printk("%s %d\n FALSE", __func__, __LINE__);
472 //#endif
473 return FALSE;
474 }
475 else
476 {
477 //#ifdef BUILD_LK
478 //printf("%s %d\n FALSE", __func__, __LINE__);
479 //#else
480 //printk("%s %d\n FALSE", __func__, __LINE__);
481 //#endif
482 return TRUE;
483 }
484 #endif
485
486 }
487
488 static unsigned int lcm_esd_recover(void)
489 {
490
491 #ifdef BUILD_LK
492 printf("lcm_esd_recover()\n");
493 #else
494 printk("lcm_esd_recover()\n");
495 #endif
496
497 lcm_init();
498
499 return TRUE;
500 }
501 // zhoulidong add for eds(end)
502 LCM_DRIVER otm8018b_dsi_vdo_trust_lcm_drv =
503 {
504 .name = "otm8018b_dsi_vdo_trust",
505 .set_util_funcs = lcm_set_util_funcs,
506 .get_params = lcm_get_params,
507 .init = lcm_init,
508 .suspend = lcm_suspend,
509 .resume = lcm_resume,
510 .compare_id = rgk_lcm_compare_id,
511 // .esd_check = lcm_esd_check,
512 // .esd_recover = lcm_esd_recover,
513 #if (LCM_DSI_CMD_MODE)
514 .update = lcm_update,
515 #endif
516 };
517