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 <platform/mt_pmic.h> | |
9 | #elif defined(BUILD_UBOOT) | |
10 | #else | |
11 | #include <mach/mt_gpio.h> | |
12 | #include <mach/mt_pm_ldo.h> | |
13 | #endif | |
14 | ||
15 | // --------------------------------------------------------------------------- | |
16 | // Local Constants | |
17 | // --------------------------------------------------------------------------- | |
18 | ||
19 | #define FRAME_WIDTH (800) | |
20 | #define FRAME_HEIGHT (1280) | |
21 | ||
22 | #define LCM_ID_NT51012 (0x90) | |
23 | // TODO. This LCM ID is NT51012 not 35590. | |
24 | ||
25 | #define GPIO_LCD_RST_EN GPIO65 | |
26 | #define GPIO_LCD_STB_EN GPIO66 | |
27 | #define GPIO_LCD_BL_EN GPIO76 | |
28 | #define GPIO_LCD_LED_EN GPIO110 | |
29 | // --------------------------------------------------------------------------- | |
30 | // Local Variables | |
31 | // --------------------------------------------------------------------------- | |
32 | ||
33 | static LCM_UTIL_FUNCS lcm_util = {0}; | |
34 | ||
35 | #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v))) | |
36 | ||
37 | #define UDELAY(n) (lcm_util.udelay(n)) | |
38 | #define MDELAY(n) (lcm_util.mdelay(n)) | |
39 | ||
40 | ||
41 | // --------------------------------------------------------------------------- | |
42 | // Local Functions | |
43 | // --------------------------------------------------------------------------- | |
44 | ||
45 | #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update) | |
46 | #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update) | |
47 | #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd) | |
48 | #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums) | |
49 | #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd) | |
50 | #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size) | |
51 | ||
52 | ||
53 | #define LCM_DSI_CMD_MODE 0 | |
54 | ||
55 | ||
56 | static void init_lcm_registers(void) | |
57 | { | |
58 | unsigned int data_array[16]; | |
59 | ||
60 | #if 1 | |
61 | ||
62 | data_array[0] = 0x00011500; //software reset | |
63 | dsi_set_cmdq(data_array, 1, 1); | |
64 | ||
65 | MDELAY(20); | |
66 | ||
67 | data_array[0]=0x0bae1500; | |
68 | data_array[1]=0xeaee1500; | |
69 | data_array[2]=0x5fef1500; | |
70 | data_array[3]=0x68f21500; | |
71 | data_array[4]=0x00ee1500; | |
72 | data_array[5]=0x00ef1500; | |
73 | dsi_set_cmdq(data_array, 6, 1); | |
74 | ||
75 | #if 0 | |
76 | ||
77 | data_array[0] = 0x7DB21500; | |
78 | dsi_set_cmdq(data_array, 1, 1); | |
79 | ||
80 | data_array[0] = 0x0BAE1500; | |
81 | dsi_set_cmdq(data_array, 1, 1); | |
82 | ||
83 | data_array[0] = 0x18B61500; | |
84 | dsi_set_cmdq(data_array, 1, 1); | |
85 | ||
86 | data_array[0] = 0xEAEE1500; | |
87 | dsi_set_cmdq(data_array, 1, 1); | |
88 | ||
89 | data_array[0] = 0x5FEF1500; | |
90 | dsi_set_cmdq(data_array, 1, 1); | |
91 | ||
92 | data_array[0] = 0x68F21500; | |
93 | dsi_set_cmdq(data_array, 1, 1); | |
94 | ||
95 | data_array[0] = 0x00EE1500; | |
96 | dsi_set_cmdq(data_array, 1, 1); | |
97 | ||
98 | data_array[0] = 0x00EF1500; | |
99 | dsi_set_cmdq(data_array, 1, 1); | |
100 | ||
101 | data_array[0] = 0x64D21500; | |
102 | dsi_set_cmdq(data_array, 1, 1); | |
103 | ||
104 | data_array[0] = 0x00101500; //sleep out | |
105 | dsi_set_cmdq(data_array, 1, 1); | |
106 | MDELAY(20); | |
107 | #endif | |
108 | ||
109 | //data_array[0] = 0xEFB11500; | |
110 | //dsi_set_cmdq(data_array, 1, 1); | |
111 | //MDELAY(1); | |
112 | ||
113 | //data_array[0] = 0x00290500; //display on | |
114 | //dsi_set_cmdq(data_array, 1, 1); | |
115 | #endif | |
116 | ||
117 | #if 0 | |
118 | data_array[0] = 0x00010500; //software reset | |
119 | dsi_set_cmdq(data_array, 1, 1); | |
120 | ||
121 | MDELAY(20); | |
122 | ||
123 | data_array[0] = 0x00023902; | |
124 | data_array[1] = 0x00000BAE; | |
125 | dsi_set_cmdq(data_array, 2, 1); | |
126 | MDELAY(1); | |
127 | ||
128 | data_array[0] = 0x00023902; | |
129 | data_array[1] = 0x0000EAEE; | |
130 | dsi_set_cmdq(data_array, 2, 1); | |
131 | MDELAY(1); | |
132 | ||
133 | data_array[0] = 0x00023902; | |
134 | data_array[1] = 0x00005FEF; | |
135 | dsi_set_cmdq(data_array, 2, 1); | |
136 | MDELAY(1); | |
137 | ||
138 | data_array[0] = 0x00023902; | |
139 | data_array[1] = 0x000068F2; | |
140 | dsi_set_cmdq(data_array, 2, 1); | |
141 | MDELAY(1); | |
142 | ||
143 | data_array[0] = 0x00023902; | |
144 | data_array[1] = 0x000000EE; | |
145 | dsi_set_cmdq(data_array, 2, 1); | |
146 | MDELAY(1); | |
147 | ||
148 | data_array[0] = 0x00023902; | |
149 | data_array[1] = 0x000000EF; | |
150 | dsi_set_cmdq(data_array, 2, 1); | |
151 | MDELAY(1); | |
152 | ||
153 | data_array[0] = 0x00100500; //sleep out | |
154 | dsi_set_cmdq(data_array, 1, 1); | |
155 | MDELAY(20); | |
156 | ||
157 | data_array[0] = 0x00290500; //display on | |
158 | dsi_set_cmdq(data_array, 1, 1); | |
159 | #endif | |
160 | //MDELAY(5); | |
161 | } | |
162 | ||
163 | // --------------------------------------------------------------------------- | |
164 | // LCM Driver Implementations | |
165 | // --------------------------------------------------------------------------- | |
166 | ||
167 | static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util) | |
168 | { | |
169 | memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS)); | |
170 | } | |
171 | ||
172 | ||
173 | static void lcm_get_params(LCM_PARAMS *params) | |
174 | { | |
175 | ||
176 | memset(params, 0, sizeof(LCM_PARAMS)); | |
177 | ||
178 | params->type = LCM_TYPE_DSI; | |
179 | ||
180 | params->width = FRAME_WIDTH; | |
181 | params->height = FRAME_HEIGHT; | |
182 | ||
183 | #if 0 | |
184 | // enable tearing-free | |
185 | params->dbi.te_mode = LCM_DBI_TE_MODE_VSYNC_ONLY; | |
186 | params->dbi.te_edge_polarity = LCM_POLARITY_RISING; | |
187 | #endif | |
188 | ||
189 | #if (LCM_DSI_CMD_MODE) | |
190 | params->dsi.mode = CMD_MODE; | |
191 | #else | |
192 | params->dsi.mode = SYNC_EVENT_VDO_MODE; | |
193 | #endif | |
194 | ||
195 | // DSI | |
196 | /* Command mode setting */ | |
197 | //1 Three lane or Four lane | |
198 | params->dsi.LANE_NUM = LCM_FOUR_LANE; | |
199 | //The following defined the fomat for data coming from LCD engine. | |
200 | params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB; | |
201 | params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST; | |
202 | params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB; | |
203 | params->dsi.data_format.format = LCM_DSI_FORMAT_RGB666; | |
204 | ||
205 | // Highly depends on LCD driver capability. | |
206 | // Not support in MT6573 | |
207 | params->dsi.packet_size=256; | |
208 | ||
209 | // Video mode setting | |
210 | params->dsi.intermediat_buffer_num = 0;//because DSI/DPI HW design change, this parameters should be 0 when video mode in MT658X; or memory leakage | |
211 | ||
212 | params->dsi.PS=LCM_PACKED_PS_24BIT_RGB888; | |
213 | params->dsi.word_count=720*3; | |
214 | ||
215 | ||
216 | params->dsi.vertical_sync_active = 1; | |
217 | params->dsi.vertical_backporch = 10; | |
218 | params->dsi.vertical_frontporch = 10; | |
219 | params->dsi.vertical_active_line = FRAME_HEIGHT; | |
220 | ||
221 | params->dsi.horizontal_sync_active = 1; | |
222 | params->dsi.horizontal_backporch = 57; | |
223 | params->dsi.horizontal_frontporch = 32; | |
224 | params->dsi.horizontal_active_pixel = FRAME_WIDTH; | |
225 | ||
226 | // Bit rate calculation | |
227 | //1 Every lane speed | |
228 | //params->dsi.pll_div1=0; // div1=0,1,2,3;div1_real=1,2,4,4 ----0: 546Mbps 1:273Mbps | |
229 | //params->dsi.pll_div2=1; // div2=0,1,2,3;div1_real=1,2,4,4 | |
230 | //params->dsi.fbk_div =31; // fref=26MHz, fvco=fref*(fbk_div+1)*2/(div1_real*div2_real) | |
231 | params->dsi.PLL_CLOCK =LCM_DSI_6589_PLL_CLOCK_221; | |
232 | ||
233 | params->dsi.CLK_ZERO = 47; | |
234 | params->dsi.HS_ZERO = 36; | |
235 | ||
236 | } | |
237 | ||
238 | static void lcm_init(void) | |
239 | { | |
240 | #ifdef BUILD_LK | |
241 | printf("[LK/LCM] lcm_init() enter\n"); | |
242 | //VGP6 3.3V | |
243 | pmic_config_interface(0x424, 0x1, 0x1, 15); | |
244 | pmic_config_interface(0x45a, 0x07, 0x07, 5); | |
245 | ||
246 | mt_set_gpio_mode(GPIO_LCD_RST_EN, GPIO_MODE_00); | |
247 | mt_set_gpio_dir(GPIO_LCD_RST_EN, GPIO_DIR_OUT); | |
248 | mt_set_gpio_out(GPIO_LCD_RST_EN, GPIO_OUT_ONE); | |
249 | MDELAY(20); | |
250 | ||
251 | mt_set_gpio_mode(GPIO_LCD_STB_EN, GPIO_MODE_00); | |
252 | mt_set_gpio_dir(GPIO_LCD_STB_EN, GPIO_DIR_OUT); | |
253 | mt_set_gpio_out(GPIO_LCD_STB_EN, GPIO_OUT_ONE); | |
254 | MDELAY(20); | |
255 | #endif | |
256 | ||
257 | ||
258 | ||
259 | MDELAY(50); | |
260 | ||
261 | SET_RESET_PIN(1); | |
262 | SET_RESET_PIN(0); | |
263 | MDELAY(1); | |
264 | SET_RESET_PIN(1); | |
265 | ||
266 | init_lcm_registers(); | |
267 | ||
268 | mt_set_gpio_mode(GPIO_LCD_BL_EN, GPIO_MODE_00); | |
269 | mt_set_gpio_dir(GPIO_LCD_BL_EN, GPIO_DIR_OUT); | |
270 | mt_set_gpio_out(GPIO_LCD_BL_EN, GPIO_OUT_ONE); | |
271 | ||
272 | mt_set_gpio_mode(GPIO_LCD_LED_EN, GPIO_MODE_00); | |
273 | mt_set_gpio_dir(GPIO_LCD_LED_EN, GPIO_DIR_OUT); | |
274 | mt_set_gpio_out(GPIO_LCD_LED_EN, GPIO_OUT_ONE); | |
275 | ||
276 | ||
277 | } | |
278 | ||
279 | ||
280 | ||
281 | static void lcm_suspend(void) | |
282 | { | |
283 | unsigned int data_array[16]; | |
284 | ||
285 | ||
286 | ||
287 | data_array[0]=0x00280500; // Display Off | |
288 | dsi_set_cmdq(data_array, 1, 1); | |
289 | MDELAY(20); | |
290 | ||
291 | data_array[0] = 0x00111500; // Sleep In | |
292 | dsi_set_cmdq(data_array, 1, 1); | |
293 | ||
294 | mt_set_gpio_mode(GPIO_LCD_LED_EN, GPIO_MODE_00); | |
295 | mt_set_gpio_dir(GPIO_LCD_LED_EN, GPIO_DIR_OUT); | |
296 | mt_set_gpio_out(GPIO_LCD_LED_EN, GPIO_OUT_ZERO); | |
297 | ||
298 | ||
299 | mt_set_gpio_mode(GPIO_LCD_BL_EN, GPIO_MODE_00); | |
300 | mt_set_gpio_dir(GPIO_LCD_BL_EN, GPIO_DIR_OUT); | |
301 | mt_set_gpio_out(GPIO_LCD_BL_EN, GPIO_OUT_ZERO); | |
302 | ||
303 | ||
304 | MDELAY(160); | |
305 | ||
306 | ||
307 | ||
308 | } | |
309 | ||
310 | ||
311 | static void lcm_resume(void) | |
312 | { | |
313 | #ifdef BUILD_LK | |
314 | printf("[LK/LCM] lcm_resume() enter\n"); | |
315 | //VGP6 3.3V | |
316 | pmic_config_interface(0x424, 0x1, 0x1, 15); | |
317 | pmic_config_interface(0x45a, 0x07, 0x07, 5); | |
318 | ||
319 | mt_set_gpio_mode(GPIO_LCD_RST_EN, GPIO_MODE_00); | |
320 | mt_set_gpio_dir(GPIO_LCD_RST_EN, GPIO_DIR_OUT); | |
321 | mt_set_gpio_out(GPIO_LCD_RST_EN, GPIO_OUT_ONE); | |
322 | MDELAY(20); | |
323 | ||
324 | mt_set_gpio_mode(GPIO_LCD_STB_EN, GPIO_MODE_00); | |
325 | mt_set_gpio_dir(GPIO_LCD_STB_EN, GPIO_DIR_OUT); | |
326 | mt_set_gpio_out(GPIO_LCD_STB_EN, GPIO_OUT_ONE); | |
327 | MDELAY(20); | |
328 | #endif | |
329 | ||
330 | unsigned int data_array[16]; | |
331 | lcm_init(); | |
332 | ||
333 | data_array[0] = 0x00101500; // Sleep Out | |
334 | dsi_set_cmdq(data_array, 1, 1); | |
335 | MDELAY(20); | |
336 | ||
337 | data_array[0] = 0x00290500; // Display On | |
338 | dsi_set_cmdq(data_array, 1, 1); | |
339 | ||
340 | MDELAY(30); | |
341 | ||
342 | mt_set_gpio_mode(GPIO_LCD_BL_EN, GPIO_MODE_00); | |
343 | mt_set_gpio_dir(GPIO_LCD_BL_EN, GPIO_DIR_OUT); | |
344 | mt_set_gpio_out(GPIO_LCD_BL_EN, GPIO_OUT_ONE); | |
345 | ||
346 | mt_set_gpio_mode(GPIO_LCD_LED_EN, GPIO_MODE_00); | |
347 | mt_set_gpio_dir(GPIO_LCD_LED_EN, GPIO_DIR_OUT); | |
348 | mt_set_gpio_out(GPIO_LCD_LED_EN, GPIO_OUT_ONE); | |
349 | ||
350 | } | |
351 | ||
352 | #if (LCM_DSI_CMD_MODE) | |
353 | static void lcm_update(unsigned int x, unsigned int y, | |
354 | unsigned int width, unsigned int height) | |
355 | { | |
356 | unsigned int x0 = x; | |
357 | unsigned int y0 = y; | |
358 | unsigned int x1 = x0 + width - 1; | |
359 | unsigned int y1 = y0 + height - 1; | |
360 | ||
361 | unsigned char x0_MSB = ((x0>>8)&0xFF); | |
362 | unsigned char x0_LSB = (x0&0xFF); | |
363 | unsigned char x1_MSB = ((x1>>8)&0xFF); | |
364 | unsigned char x1_LSB = (x1&0xFF); | |
365 | unsigned char y0_MSB = ((y0>>8)&0xFF); | |
366 | unsigned char y0_LSB = (y0&0xFF); | |
367 | unsigned char y1_MSB = ((y1>>8)&0xFF); | |
368 | unsigned char y1_LSB = (y1&0xFF); | |
369 | ||
370 | unsigned int data_array[16]; | |
371 | ||
372 | data_array[0]= 0x00053902; | |
373 | data_array[1]= (x1_MSB<<24)|(x0_LSB<<16)|(x0_MSB<<8)|0x2a; | |
374 | data_array[2]= (x1_LSB); | |
375 | dsi_set_cmdq(data_array, 3, 1); | |
376 | ||
377 | data_array[0]= 0x00053902; | |
378 | data_array[1]= (y1_MSB<<24)|(y0_LSB<<16)|(y0_MSB<<8)|0x2b; | |
379 | data_array[2]= (y1_LSB); | |
380 | dsi_set_cmdq(data_array, 3, 1); | |
381 | ||
382 | data_array[0]= 0x00290508; //HW bug, so need send one HS packet | |
383 | dsi_set_cmdq(data_array, 1, 1); | |
384 | ||
385 | data_array[0]= 0x002c3909; | |
386 | dsi_set_cmdq(data_array, 1, 0); | |
387 | ||
388 | } | |
389 | #endif | |
390 | #if 0 | |
391 | static unsigned int lcm_compare_id(void) | |
392 | { | |
393 | unsigned int id=0; | |
394 | unsigned char buffer[2]; | |
395 | unsigned int array[16]; | |
396 | ||
397 | SET_RESET_PIN(1); | |
398 | SET_RESET_PIN(0); | |
399 | MDELAY(1); | |
400 | ||
401 | SET_RESET_PIN(1); | |
402 | MDELAY(20); | |
403 | ||
404 | array[0] = 0x00023700;// read id return two byte,version and id | |
405 | dsi_set_cmdq(array, 1, 1); | |
406 | ||
407 | read_reg_v2(0xF4, buffer, 2); | |
408 | id = buffer[0]; //we only need ID | |
409 | #ifdef BUILD_LK | |
410 | printf("%s, LK nt35590 debug: nt35590 id = 0x%08x\n", __func__, id); | |
411 | #else | |
412 | printk("%s, kernel nt35590 horse debug: nt35590 id = 0x%08x\n", __func__, id); | |
413 | #endif | |
414 | ||
415 | if(id == LCM_ID_NT35590) | |
416 | return 1; | |
417 | else | |
418 | return 0; | |
419 | ||
420 | ||
421 | } | |
422 | #endif | |
423 | ||
424 | LCM_DRIVER nt51012_hd720_dsi_vdo_lcm_drv = | |
425 | { | |
426 | .name = "nt51012_hd720_dsi_vdo", | |
427 | .set_util_funcs = lcm_set_util_funcs, | |
428 | .get_params = lcm_get_params, | |
429 | .init = lcm_init, | |
430 | .suspend = lcm_suspend, | |
431 | .resume = lcm_resume, | |
432 | //.compare_id = lcm_compare_id, | |
433 | #if (LCM_DSI_CMD_MODE) | |
434 | .update = lcm_update, | |
435 | #endif | |
436 | }; |