2 #include <linux/string.h>
7 #include <platform/mt_gpio.h>
9 #elif defined(BUILD_UBOOT)
10 #include <asm/arch/mt_gpio.h>
12 #include <mach/mt_gpio.h>
15 // ---------------------------------------------------------------------------
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
22 #define MIN_VOLTAGE (0) // zhoulidong add for lcm detect
23 #define MAX_VOLTAGE (100) // zhoulidong add for lcm detect
24 // ---------------------------------------------------------------------------
26 // ---------------------------------------------------------------------------
28 #define FRAME_WIDTH (480)
29 #define FRAME_HEIGHT (800)
31 #define LCM_ID_OTM8018B 0x8009
41 unsigned static int lcm_esd_test
= FALSE
; ///only for ESD test
43 // ---------------------------------------------------------------------------
45 // ---------------------------------------------------------------------------
47 static LCM_UTIL_FUNCS lcm_util
;
49 #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
51 #define UDELAY(n) (lcm_util.udelay(n))
52 #define MDELAY(n) (lcm_util.mdelay(n))
55 // ---------------------------------------------------------------------------
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)
66 #define LCM_DSI_CMD_MODE 0
68 // zhoulidong add for lcm detect ,read adc voltage
69 extern int IMM_GetOneChannelValue(int dwChannel
, int data
[4], int* rawdata
);
72 static LCM_setting_table_V3 lcm_initialization_setting
[] = {
74 {0x15, 0x00,1,{0x00}},
75 {0x39, 0xFF,3,{0x80,0x09,0x01}},
77 {0x15, 0x00,1,{0x80}},
78 {0x39, 0xFF,2,{0x80,0x09}}, // enable Orise mode
80 {0x15, 0x00,1,{0x03}},
81 {0x15, 0xff,1,{0x01}},// enable SPI+I2C cmd2 read
83 {0x15, 0x00,1,{0xB4}},
84 {0x15, 0xc0,1,{0x10}},//1+2dot inversion
86 {0x15, 0x00,1,{0x82}},
87 {0x15, 0xc5,1,{0xa3}},
89 {0x15, 0x00,1,{0x90}},
90 {0x39, 0xc5,2,{0x96,0x76}},//Pump setting (3x=D6)-->(2x=96)//v02 01/11 d5 87
92 {0x15, 0x00,1,{0x00}},
93 {0x39, 0xd8,2,{0x72,0x75}},//GVDD=4.5V
95 {0x15, 0x00,1,{0x00}},
96 {0x15, 0xd9,1,{0x69}},// VCOMDC=
98 {0x15, 0x00,1,{0x81}},
99 {0x15, 0xc1,1,{0x77}}, //Frame rate 65Hz//V02///66
101 {0x15, 0x00,1,{0x89}},
102 {0x15, 0xc4,1,{0x08}},
104 {0x15, 0x00,1,{0xa2}},
105 {0x39, 0xc0,3,{0x04,0x00,0x02}},
107 {0x15, 0x00,1,{0x80}},
108 {0x15, 0xc4,1,{0x30}},
110 {0x15, 0x00,1,{0xa6}},
111 {0x15, 0xc1,1,{0x01}},
113 {0x15, 0x00,1,{0xc0}},
114 {0x15, 0xc5,1,{0x00}},
116 {0x15, 0x00,1,{0x8b}},
117 {0x15, 0xb0,1,{0x40}},
119 {0x15, 0x00,1,{0xb2}},
120 {0x39, 0xf5,4,{0x15,0x00,0x15,0x00}},
122 {0x15, 0x00,1,{0x93}},
123 {0x15, 0xc5,1,{0x03}},
125 {0x15, 0x00,1,{0x81}},
126 {0x15, 0xc4,1,{0x83}},
128 {0x15, 0x00,1,{0x92}},
129 {0x15, 0xc5,1,{0x01}},
131 {0x15, 0x00,1,{0xb1}},
132 {0x15, 0xc5,1,{0xa9}},
134 {0x15, 0x00,1,{0x90}},
135 {0x39, 0xc0,6,{0x00,0x44,0x00,0x00,0x00,0x03}},
137 {0x15, 0x00,1,{0xa6}},
138 {0x39, 0xc1,3,{0x00,0x00,0x00}},
143 {0x15, 0x00,1,{0x80}},
144 {0x39, 0xce,12,{0x87,0x03,0x00,0x85,0x03,0x00,0x86,0x03,0x00,0x84,0x03,0x00}},
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}},
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}},
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}},
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}},
163 {0x15, 0x00,1,{0xc7}},
164 {0x15, 0xcf,1,{0x00}},
166 {0x15, 0x00,1,{0xc9}},
167 {0x15, 0xcf,1,{0x00}},
169 {0x15, 0x00,1,{0xc4}},
170 {0x39, 0xcb,6,{0x04,0x04,0x04,0x04,0x04,0x04}},
172 {0x15, 0x00,1,{0xd9}},
173 {0x39, 0xcb,6,{0x04,0x04,0x04,0x04,0x04,0x04}},
175 {0x15, 0x00,1,{0x84}},
176 {0x39, 0xcc,6,{0x0c,0x0a,0x10,0x0e,0x03,0x04}},
178 {0x15, 0x00,1,{0x9e}},
179 {0x15, 0xcc,1,{0x0b}},
181 {0x15, 0x00,1,{0xa0}},
182 {0x39, 0xcc,5,{0x09,0x0f,0x0d,0x01,0x02}},
184 {0x15, 0x00,1,{0xb4}},
185 {0x39, 0xcc,6,{0x0d,0x0f,0x09,0x0b,0x02,0x01}},
187 {0x15, 0x00,1,{0xce}},
188 {0x15, 0xcc,1,{0x0e}},
190 {0x15, 0x00,1,{0xd0}},
191 {0x39, 0xcc,5,{0x10,0x0a,0x0c,0x04,0x03}},
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}},
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}},
201 //{0xE1,16,{0x09,0x0B,0x0F,0x0E,0x0A,0x1B,0x0A,0x0A,0x00,0x03,0x03,0x05,0x0F,0x24,0x1E,0x03}},
204 //{0xE2,16,{0x09,0x0B,0x0F,0x11,0x0E,0x1F,0x0A,0x0A,0x00,0x03,0x03,0x05,0x0F,0x22,0x1E,0x03}},
206 {0x15, 0x00,1,{0x00}},
207 {0x39, 0xff,3,{0xff,0xff,0xff,}},
210 {0x15, 0x35,1,{0x00}}, //open the TE zzf add
212 {0x15, 0x3A,1,{0x77}},
214 {REGFLAG_ESCAPE_ID
,REGFLAG_DELAY_MS_V3
, 120, {}},
216 {REGFLAG_ESCAPE_ID
,REGFLAG_DELAY_MS_V3
, 10, {}},
220 // ---------------------------------------------------------------------------
221 // LCM Driver Implementations
222 // ---------------------------------------------------------------------------
224 static void lcm_set_util_funcs(const LCM_UTIL_FUNCS
*util
)
226 memcpy(&lcm_util
, util
, sizeof(LCM_UTIL_FUNCS
));
230 static void lcm_get_params(LCM_PARAMS
*params
)
233 memset(params
, 0, sizeof(LCM_PARAMS
));
235 params
->type
= LCM_TYPE_DSI
;
237 params
->width
= FRAME_WIDTH
;
238 params
->height
= FRAME_HEIGHT
;
240 #if (LCM_DSI_CMD_MODE)
241 params
->dsi
.mode
= CMD_MODE
;
243 params
->dsi
.mode
= SYNC_PULSE_VDO_MODE
; //SYNC_PULSE_VDO_MODE;//BURST_VDO_MODE;
247 /* Command mode setting */
248 //1 Three lane or Four lane
249 params
->dsi
.LANE_NUM
= LCM_TWO_LANE
;
251 //The following defined the fomat for data coming from LCD engine.
252 params
->dsi
.data_format
.format
= LCM_DSI_FORMAT_RGB888
;
254 // Video mode setting
255 params
->dsi
.PS
=LCM_PACKED_PS_24BIT_RGB888
;
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
;
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
;
269 // Bit rate calculation
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;
279 params
->dsi
.fbk_div
=7; // fref=26MHz, fvco=fref*(fbk_div+1)*2/(div1_real*div2_real)
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
286 static void lcm_init(void)
294 dsi_set_cmdq_V3(lcm_initialization_setting
,sizeof(lcm_initialization_setting
)/sizeof(lcm_initialization_setting
[0]),1);
299 static LCM_setting_table_V3 lcm_deep_sleep_mode_in_setting
[] = {
300 // Display off sequence
302 {REGFLAG_ESCAPE_ID
,REGFLAG_DELAY_MS_V3
, 10, {}},
306 {REGFLAG_ESCAPE_ID
,REGFLAG_DELAY_MS_V3
, 120, {}},
308 static void lcm_suspend(void)
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);
321 static void lcm_resume(void)
327 #if (LCM_DSI_CMD_MODE)
328 static void lcm_update(unsigned int x
, unsigned int y
,
329 unsigned int width
, unsigned int height
)
333 unsigned int x1
= x0
+ width
- 1;
334 unsigned int y1
= y0
+ height
- 1;
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);
345 unsigned int data_array
[16];
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);
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);
357 data_array
[0]= 0x002c3909;
358 dsi_set_cmdq(data_array
, 1, 0);
367 // zhoulidong add for lcm detect (start)
369 static unsigned int lcm_compare_id(void)
383 array
[0] = 0x00053700;
384 dsi_set_cmdq(array
, 1, 1);
385 read_reg_v2(0xa1, buffer
, 5);
389 id
= (id_high
<<8) | id_low
;
395 #if defined(BUILD_UBOOT)
396 printf("OTM8018B uboot %s \n", __func__
);
397 printf("%s id = 0x%08x \n", __func__
, id
);
399 printk("OTM8018B kernel %s \n", __func__
);
400 printk("%s id = 0x%08x \n", __func__
, id
);
407 // zhoulidong add for lcm detect (start)
408 static unsigned int rgk_lcm_compare_id(void)
410 int data
[4] = {0,0,0,0};
414 #ifdef AUXADC_LCM_VOLTAGE_CHANNEL
415 res
= IMM_GetOneChannelValue(AUXADC_LCM_VOLTAGE_CHANNEL
,data
,&rawdata
);
419 printf("[adc_uboot]: get data error\n");
426 lcm_vol
= data
[0]*1000+data
[1]*10;
429 printf("[adc_uboot]: lcm_vol= %d\n",lcm_vol
);
432 if (lcm_vol
>=MIN_VOLTAGE
&&lcm_vol
<= MAX_VOLTAGE
)
442 // zhoulidong add for lcm detect (end)
444 // zhoulidong add for eds(start)
445 static unsigned int lcm_esd_check(void)
448 //printf("lcm_esd_check()\n");
450 //printk("lcm_esd_check()\n");
458 lcm_esd_test
= FALSE
;
462 array
[0] = 0x00013700;
463 dsi_set_cmdq(array
, 1, 1);
465 read_reg_v2(0x0a, buffer
, 1);
469 //printf("%s %d\n FALSE", __func__, __LINE__);
471 //printk("%s %d\n FALSE", __func__, __LINE__);
478 //printf("%s %d\n FALSE", __func__, __LINE__);
480 //printk("%s %d\n FALSE", __func__, __LINE__);
488 static unsigned int lcm_esd_recover(void)
492 printf("lcm_esd_recover()\n");
494 printk("lcm_esd_recover()\n");
501 // zhoulidong add for eds(end)
502 LCM_DRIVER otm8018b_dsi_vdo_trust_lcm_drv
=
504 .name
= "otm8018b_dsi_vdo_trust",
505 .set_util_funcs
= lcm_set_util_funcs
,
506 .get_params
= lcm_get_params
,
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
,