Commit | Line | Data |
---|---|---|
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 | // --------------------------------------------------------------------------- | |
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 (400) // zhoulidong add for lcm detect | |
23 | #define MAX_VOLTAGE (700) // zhoulidong add for lcm detect | |
24 | ||
25 | // --------------------------------------------------------------------------- | |
26 | // Local Constants | |
27 | // --------------------------------------------------------------------------- | |
28 | ||
29 | #define FRAME_WIDTH (480) | |
30 | #define FRAME_HEIGHT (800) | |
31 | ||
32 | #define LCM_ID_ILI9806 0x9816 | |
33 | ||
34 | ||
35 | #ifndef TRUE | |
36 | #define TRUE 1 | |
37 | #endif | |
38 | ||
39 | #ifndef FALSE | |
40 | #define FALSE 0 | |
41 | #endif | |
42 | ||
43 | unsigned static int lcm_esd_test = FALSE; ///only for ESD test | |
44 | ||
45 | // --------------------------------------------------------------------------- | |
46 | // Local Variables | |
47 | // --------------------------------------------------------------------------- | |
48 | ||
49 | static LCM_UTIL_FUNCS lcm_util ; | |
50 | ||
51 | #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v))) | |
52 | ||
53 | #define UDELAY(n) (lcm_util.udelay(n)) | |
54 | #define MDELAY(n) (lcm_util.mdelay(n)) | |
55 | ||
56 | ||
57 | // --------------------------------------------------------------------------- | |
58 | // Local Functions | |
59 | // --------------------------------------------------------------------------- | |
60 | #define dsi_set_cmdq_V3(para_tbl,size,force_update) lcm_util.dsi_set_cmdq_V3(para_tbl,size,force_update) | |
61 | #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update) | |
62 | #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update) | |
63 | #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd) | |
64 | #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums) | |
65 | #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd) | |
66 | #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size) | |
67 | ||
68 | #define LCM_DSI_CMD_MODE 0 | |
69 | ||
70 | // zhoulidong add for lcm detect ,read adc voltage | |
71 | extern int IMM_GetOneChannelValue(int dwChannel, int data[4], int* rawdata); | |
72 | ||
73 | ||
74 | static LCM_setting_table_V3 lcm_initialization_setting[] = { | |
75 | ||
76 | ||
77 | ||
78 | {0x39,0xFF, 3,{0xFF,0x98,0x16}}, | |
79 | {0x15,0xBA, 1,{0x60}}, | |
80 | {0x15,0xB0, 1,{0x01}}, | |
81 | {0x39, 0xBC,18,{0x01,0x0D,0x61,0xFF,0x01,0x01,0x0B,0x0F,0x32,0x63,0xFF,0xFF,0x01,0x01,0x08,0x00,0x55,0x53}}, | |
82 | {0x39, 0xBD, 8,{0x01,0x23,0x45,0x67,0x01,0x23,0x45,0x67}}, | |
83 | {0x39, 0xBE,17,{0x02,0x22,0x11,0xAA,0xBB,0x66,0x00,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22}}, | |
84 | {0x39, 0xED, 2,{0x7F,0x0F}}, | |
85 | {0x15, 0xF3, 1,{0x70}}, | |
86 | {0x15, 0x3A, 1,{0x60}}, | |
87 | {0x15, 0xB9, 1,{0x08}}, | |
88 | {0x15, 0xB4, 1,{0x02}}, | |
89 | {0x39, 0xC1, 4,{0x17,0x8A,0x83,0x10}}, | |
90 | {0x15, 0xD8, 1,{0x50}}, | |
91 | {0x15, 0xFC, 1,{0x07}}, | |
92 | {0x39, 0xE0,16,{0x00,0x16,0x19,0x0C,0x0E,0x00,0XC7,0x07,0x04,0x08,0x10,0x0F,0x10,0x1C,0x15,0x00}}, | |
93 | {0x39, 0xE1,16,{0x00,0x01,0x0F,0x0D,0x0F,0x18,0X79,0x06,0x07,0x0D,0x0C,0x0E,0x0B,0x10,0x0B,0x00}}, | |
94 | {0x39, 0xD5, 8,{0x0C,0x09,0x09,0x07,0xCB,0XA5,0x01,0x04}}, | |
95 | {0x39,0xC0, 13,{0x0F,0x0B,0x0A,0x00,0x00,0x88,0x2c,0X50,0x00,0x00,0x00,0X00,0x55}}, | |
96 | {0x15, 0xF7, 1,{0x8A}}, | |
97 | {0x15, 0xC7, 1,{0x47}},//55 5a 4b 47 | |
98 | {0x15, 0x36, 1,{0x08}}, | |
99 | {0x15, 0x35, 1,{0x00}}, | |
100 | ||
101 | {0x05, 0x11,0,{}}, | |
102 | {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 120, {}}, | |
103 | ||
104 | {0x05, 0x29,0,{}}, | |
105 | {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 10, {}}, | |
106 | }; | |
107 | ||
108 | ||
109 | ||
110 | // --------------------------------------------------------------------------- | |
111 | // LCM Driver Implementations | |
112 | // --------------------------------------------------------------------------- | |
113 | ||
114 | static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util) | |
115 | { | |
116 | memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS)); | |
117 | } | |
118 | ||
119 | ||
120 | static void lcm_get_params(LCM_PARAMS *params) | |
121 | { | |
122 | ||
123 | memset(params, 0, sizeof(LCM_PARAMS)); | |
124 | ||
125 | params->type = LCM_TYPE_DSI; | |
126 | ||
127 | params->width = FRAME_WIDTH; | |
128 | params->height = FRAME_HEIGHT; | |
129 | ||
130 | #if (LCM_DSI_CMD_MODE) | |
131 | params->dsi.mode = CMD_MODE; | |
132 | #else | |
133 | params->dsi.mode = SYNC_PULSE_VDO_MODE; //SYNC_PULSE_VDO_MODE;//BURST_VDO_MODE; | |
134 | #endif | |
135 | ||
136 | // DSI | |
137 | /* Command mode setting */ | |
138 | //1 Three lane or Four lane | |
139 | params->dsi.LANE_NUM = LCM_TWO_LANE; | |
140 | //The following defined the fomat for data coming from LCD engine. | |
141 | params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888; | |
142 | ||
143 | // Video mode setting | |
144 | params->dsi.PS=LCM_PACKED_PS_24BIT_RGB888; | |
145 | ||
146 | params->dsi.vertical_sync_active =4; | |
147 | params->dsi.vertical_backporch = 16; | |
148 | params->dsi.vertical_frontporch = 20; | |
149 | params->dsi.vertical_active_line = FRAME_HEIGHT; | |
150 | ||
151 | ||
152 | params->dsi.horizontal_sync_active = 10;///////////////20 20 4 20 14 6 | |
153 | params->dsi.horizontal_backporch = 80; | |
154 | params->dsi.horizontal_frontporch = 80; | |
155 | params->dsi.horizontal_active_pixel = FRAME_WIDTH; | |
156 | ||
157 | //params->dsi.LPX=8; | |
158 | ||
159 | // Bit rate calculation | |
160 | //1 Every lane speed | |
161 | //params->dsi.pll_select=1; | |
162 | //params->dsi.PLL_CLOCK = LCM_DSI_6589_PLL_CLOCK_377; | |
163 | params->dsi.PLL_CLOCK=234; | |
164 | params->dsi.pll_div1=0; // div1=0,1,2,3;div1_real=1,2,4,4 ----0: 546Mbps 1:273Mbps | |
165 | params->dsi.pll_div2=0; // div2=0,1,2,3;div1_real=1,2,4,4 | |
166 | #if (LCM_DSI_CMD_MODE) | |
167 | params->dsi.fbk_div =7; | |
168 | #else | |
169 | params->dsi.fbk_div =7; // fref=26MHz, fvco=fref*(fbk_div+1)*2/(div1_real*div2_real) | |
170 | #endif | |
171 | //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 | |
172 | ||
173 | } | |
174 | ||
175 | ||
176 | static void lcm_init(void) | |
177 | { | |
178 | SET_RESET_PIN(1); | |
179 | SET_RESET_PIN(0); | |
180 | MDELAY(10); | |
181 | SET_RESET_PIN(1); | |
182 | MDELAY(120); | |
183 | ||
184 | dsi_set_cmdq_V3(lcm_initialization_setting,sizeof(lcm_initialization_setting)/sizeof(lcm_initialization_setting[0]),1); | |
185 | ||
186 | } | |
187 | ||
188 | ||
189 | static LCM_setting_table_V3 lcm_deep_sleep_mode_in_setting[] = { | |
190 | // Display off sequence | |
191 | {0x05, 0x28, 0, {}}, | |
192 | {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 10, {}}, | |
193 | ||
194 | // Sleep Mode On | |
195 | {0x05, 0x10, 0, {}}, | |
196 | {REGFLAG_ESCAPE_ID,REGFLAG_DELAY_MS_V3, 120, {}}, | |
197 | }; | |
198 | static void lcm_suspend(void) | |
199 | { | |
200 | ||
201 | 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); | |
202 | SET_RESET_PIN(1); | |
203 | SET_RESET_PIN(0); | |
204 | MDELAY(20); // 1ms | |
205 | ||
206 | SET_RESET_PIN(1); | |
207 | MDELAY(120); | |
208 | } | |
209 | ||
210 | ||
211 | static void lcm_resume(void) | |
212 | { | |
213 | lcm_init(); | |
214 | ||
215 | } | |
216 | ||
217 | #if (LCM_DSI_CMD_MODE) | |
218 | static void lcm_update(unsigned int x, unsigned int y, | |
219 | unsigned int width, unsigned int height) | |
220 | { | |
221 | unsigned int x0 = x; | |
222 | unsigned int y0 = y; | |
223 | unsigned int x1 = x0 + width - 1; | |
224 | unsigned int y1 = y0 + height - 1; | |
225 | ||
226 | unsigned char x0_MSB = ((x0>>8)&0xFF); | |
227 | unsigned char x0_LSB = (x0&0xFF); | |
228 | unsigned char x1_MSB = ((x1>>8)&0xFF); | |
229 | unsigned char x1_LSB = (x1&0xFF); | |
230 | unsigned char y0_MSB = ((y0>>8)&0xFF); | |
231 | unsigned char y0_LSB = (y0&0xFF); | |
232 | unsigned char y1_MSB = ((y1>>8)&0xFF); | |
233 | unsigned char y1_LSB = (y1&0xFF); | |
234 | ||
235 | unsigned int data_array[16]; | |
236 | ||
237 | data_array[0]= 0x00053902; | |
238 | data_array[1]= (x1_MSB<<24)|(x0_LSB<<16)|(x0_MSB<<8)|0x2a; | |
239 | data_array[2]= (x1_LSB); | |
240 | dsi_set_cmdq(data_array, 3, 1); | |
241 | ||
242 | data_array[0]= 0x00053902; | |
243 | data_array[1]= (y1_MSB<<24)|(y0_LSB<<16)|(y0_MSB<<8)|0x2b; | |
244 | data_array[2]= (y1_LSB); | |
245 | dsi_set_cmdq(data_array, 3, 1); | |
246 | ||
247 | data_array[0]= 0x002c3909; | |
248 | dsi_set_cmdq(data_array, 1, 0); | |
249 | ||
250 | } | |
251 | #endif | |
252 | ||
253 | ||
254 | ||
255 | ||
256 | ||
257 | static unsigned int lcm_compare_id(void) | |
258 | { | |
259 | int array[4]; | |
260 | char buffer[4]={0,0,0,0}; | |
261 | char id_high=0; | |
262 | char id_low=0; | |
263 | int id=0; | |
264 | ||
265 | SET_RESET_PIN(1); | |
266 | SET_RESET_PIN(0); | |
267 | MDELAY(10); | |
268 | SET_RESET_PIN(1); | |
269 | MDELAY(200); | |
270 | ||
271 | array[0]=0x00043902; | |
272 | array[1]=0x0698ffff; | |
273 | dsi_set_cmdq(array, 2, 1); | |
274 | ||
275 | MDELAY(10); | |
276 | array[0] = 0x00083700; | |
277 | dsi_set_cmdq(array, 1, 1); | |
278 | ||
279 | MDELAY(10); | |
280 | read_reg_v2(0xD3, buffer, 4);// NC 0x00 0x98 0x16 | |
281 | ||
282 | id_high = buffer[1]; | |
283 | id_low = buffer[2]; | |
284 | id = (id_high<<8) | id_low; | |
285 | ||
286 | #ifdef BUILD_LK | |
287 | ||
288 | printf("ILI9806 uboot %s \n", __func__); | |
289 | printf("%s id = 0x%08x \n", __func__, id); | |
290 | ||
291 | #else | |
292 | printk("ILI9806 kernel %s \n", __func__); | |
293 | printk("%s id = 0x%08x \n", __func__, id); | |
294 | ||
295 | #endif | |
296 | ||
297 | ||
298 | return (LCM_ID_ILI9806 == id)?1:0; | |
299 | ||
300 | } | |
301 | ||
302 | // zhoulidong add for lcm detect (start) | |
303 | static unsigned int rgk_lcm_compare_id(void) | |
304 | { | |
305 | int data[4] = {0,0,0,0}; | |
306 | int res = 0; | |
307 | int rawdata = 0; | |
308 | int lcm_vol = 0; | |
309 | ||
310 | #ifdef AUXADC_LCM_VOLTAGE_CHANNEL | |
311 | res = IMM_GetOneChannelValue(AUXADC_LCM_VOLTAGE_CHANNEL,data,&rawdata); | |
312 | if(res < 0) | |
313 | ||
314 | { | |
315 | #ifdef BUILD_LK | |
316 | printf("[adc_uboot]: get data error\n"); | |
317 | #endif | |
318 | return 0; | |
319 | ||
320 | } | |
321 | #endif | |
322 | lcm_vol = data[0]*1000+data[1]*10; | |
323 | ||
324 | ||
325 | #ifdef BUILD_LK | |
326 | printf("[adc_uboot]: lcm_vol= %d\n",lcm_vol); | |
327 | #endif | |
328 | ||
329 | if (lcm_vol>=MIN_VOLTAGE &&lcm_vol <= MAX_VOLTAGE &&lcm_compare_id()) | |
330 | { | |
331 | return 1; | |
332 | } | |
333 | ||
334 | return 0; | |
335 | ||
336 | } | |
337 | // zhoulidong add for eds(start) | |
338 | static unsigned int lcm_esd_check(void) | |
339 | { | |
340 | #ifdef BUILD_LK | |
341 | //printf("lcm_esd_check()\n"); | |
342 | #else | |
343 | //printk("lcm_esd_check()\n"); | |
344 | #endif | |
345 | #ifndef BUILD_LK | |
346 | char buffer[3]; | |
347 | int array[4]; | |
348 | ||
349 | if(lcm_esd_test) | |
350 | { | |
351 | lcm_esd_test = FALSE; | |
352 | return TRUE; | |
353 | } | |
354 | ||
355 | array[0] = 0x00013700; | |
356 | dsi_set_cmdq(array, 1, 1); | |
357 | ||
358 | read_reg_v2(0x0a, buffer, 1); | |
359 | if(buffer[0]==0x9c) | |
360 | { | |
361 | //#ifdef BUILD_LK | |
362 | //printf("%s %d\n FALSE", __func__, __LINE__); | |
363 | //#else | |
364 | //printk("%s %d\n FALSE", __func__, __LINE__); | |
365 | //#endif | |
366 | return FALSE; | |
367 | } | |
368 | else | |
369 | { | |
370 | //#ifdef BUILD_LK | |
371 | //printf("%s %d\n FALSE", __func__, __LINE__); | |
372 | //#else | |
373 | //printk("%s %d\n FALSE", __func__, __LINE__); | |
374 | //#endif | |
375 | return TRUE; | |
376 | } | |
377 | #endif | |
378 | ||
379 | } | |
380 | ||
381 | static unsigned int lcm_esd_recover(void) | |
382 | { | |
383 | ||
384 | #ifdef BUILD_LK | |
385 | printf("lcm_esd_recover()\n"); | |
386 | #else | |
387 | printk("lcm_esd_recover()\n"); | |
388 | #endif | |
389 | ||
390 | lcm_init(); | |
391 | ||
392 | return TRUE; | |
393 | } | |
394 | // zhoulidong add for eds(end) | |
395 | LCM_DRIVER ili9806c_dsi_vdo_txd_ips_lcm_drv = | |
396 | { | |
397 | .name = "ili9806c_dsi_vdo_txd_ips", | |
398 | .set_util_funcs = lcm_set_util_funcs, | |
399 | .get_params = lcm_get_params, | |
400 | .init = lcm_init, | |
401 | .suspend = lcm_suspend, | |
402 | .resume = lcm_resume, | |
403 | .compare_id = rgk_lcm_compare_id, | |
404 | // .esd_check = lcm_esd_check, | |
405 | // .esd_recover = lcm_esd_recover, | |
406 | #if (LCM_DSI_CMD_MODE) | |
407 | .update = lcm_update, | |
408 | #endif | |
409 | }; | |
410 |