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/upmu_common.h> | |
9 | #elif defined(BUILD_UBOOT) | |
10 | #include <asm/arch/mt_gpio.h> | |
11 | #else | |
12 | #include <mach/mt_gpio.h> | |
13 | #include <mach/mt_pm_ldo.h> | |
14 | #include <mach/upmu_common.h> | |
15 | #endif | |
16 | // --------------------------------------------------------------------------- | |
17 | // Local Constants | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
20 | #define FRAME_WIDTH (1024) | |
21 | #define FRAME_HEIGHT (600) | |
22 | ||
23 | #define REGFLAG_DELAY 0XFE | |
24 | #define REGFLAG_END_OF_TABLE 0xFFF // END OF REGISTERS MARKER | |
25 | ||
26 | #define LCM_ID_79007 0x00 | |
27 | #define LCM_DSI_CMD_MODE 0 | |
28 | ||
29 | #define GPIO_RESET_PIN GPIO83 | |
30 | #define GPIO_STBYB_PIN GPIO117 | |
31 | #define GPIO_AVDD_PIN GPIO119 | |
32 | #define GPIO_LCM_PWR_EN GPIO89 | |
33 | #ifndef TRUE | |
34 | #define TRUE 1 | |
35 | #endif | |
36 | ||
37 | #ifndef FALSE | |
38 | #define FALSE 0 | |
39 | #endif | |
40 | ||
41 | // --------------------------------------------------------------------------- | |
42 | // Local Variables | |
43 | // --------------------------------------------------------------------------- | |
44 | ||
45 | static LCM_UTIL_FUNCS lcm_util = {0}; | |
46 | ||
47 | #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v))) | |
48 | ||
49 | #define UDELAY(n) (lcm_util.udelay(n)) | |
50 | #define MDELAY(n) (lcm_util.mdelay(n)) | |
51 | ||
52 | ||
53 | // --------------------------------------------------------------------------- | |
54 | // Local Functions | |
55 | // --------------------------------------------------------------------------- | |
56 | ||
57 | #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update) | |
58 | #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update) | |
59 | #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd) | |
60 | #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums) | |
61 | #define read_reg lcm_util.dsi_read_reg() | |
62 | #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size) | |
63 | ||
64 | #ifndef BUILD_LK | |
65 | static unsigned int lcm_esd_test = FALSE; ///only for ESD test | |
66 | #endif | |
67 | ||
68 | ||
69 | ||
70 | static void lcm_gpio_set(int num, int enable) | |
71 | { | |
72 | #ifdef BUILD_LK | |
73 | printf("\n\n\n===================== %s %d: num:%d => %d =======================\n\n\n", __func__, __LINE__, num, enable); | |
74 | #endif | |
75 | lcm_util.set_gpio_mode(num, GPIO_MODE_00); | |
76 | lcm_util.set_gpio_dir(num, GPIO_DIR_OUT); | |
77 | ||
78 | if (enable) | |
79 | lcm_util.set_gpio_out(num, GPIO_OUT_ONE); | |
80 | else | |
81 | lcm_util.set_gpio_out(num, GPIO_OUT_ZERO); | |
82 | } | |
83 | ||
84 | static void lcd_reset(unsigned char enabled) | |
85 | { | |
86 | if (enabled) | |
87 | { | |
88 | mt_set_gpio_mode(GPIO_RESET_PIN, GPIO_MODE_00); | |
89 | mt_set_gpio_dir(GPIO_RESET_PIN, GPIO_DIR_OUT); | |
90 | mt_set_gpio_out(GPIO_RESET_PIN, GPIO_OUT_ONE); | |
91 | } | |
92 | else | |
93 | { | |
94 | mt_set_gpio_mode(GPIO_RESET_PIN, GPIO_MODE_00); | |
95 | mt_set_gpio_dir(GPIO_RESET_PIN, GPIO_DIR_OUT); | |
96 | mt_set_gpio_out(GPIO_RESET_PIN, GPIO_OUT_ZERO); | |
97 | } | |
98 | } | |
99 | ||
100 | static void lcd_stbyb(unsigned char enabled) | |
101 | { | |
102 | if (enabled) | |
103 | { | |
104 | mt_set_gpio_mode(GPIO_STBYB_PIN, GPIO_MODE_00); | |
105 | mt_set_gpio_dir(GPIO_STBYB_PIN, GPIO_DIR_OUT); | |
106 | mt_set_gpio_out(GPIO_STBYB_PIN, GPIO_OUT_ONE); | |
107 | } | |
108 | else | |
109 | { | |
110 | mt_set_gpio_mode(GPIO_STBYB_PIN, GPIO_MODE_00); | |
111 | mt_set_gpio_dir(GPIO_STBYB_PIN, GPIO_DIR_OUT); | |
112 | mt_set_gpio_out(GPIO_STBYB_PIN, GPIO_OUT_ZERO); | |
113 | } | |
114 | } | |
115 | ||
116 | static void lcd_DVDD_power_en(unsigned char enabled) | |
117 | { | |
118 | if (enabled) | |
119 | { | |
120 | upmu_set_rg_vgp1_vosel(0x3); //1.8V | |
121 | upmu_set_rg_vgp1_en(0x1); | |
122 | } | |
123 | else | |
124 | { | |
125 | upmu_set_rg_vgp1_en(0x0); | |
126 | } | |
127 | } | |
128 | static void lcd_AVDD_power_en(unsigned char enabled) | |
129 | { | |
130 | //lcm_gpio_set(GPIO_LCM_PWR_EN, enabled); | |
131 | mt_set_gpio_mode(GPIO_LCM_PWR_EN, GPIO_MODE_00); | |
132 | mt_set_gpio_dir(GPIO_LCM_PWR_EN, GPIO_DIR_OUT); | |
133 | mt_set_gpio_out(GPIO_LCM_PWR_EN, enabled); | |
134 | } | |
135 | ||
136 | ||
137 | static void init_lcm_registers(void) | |
138 | { | |
139 | unsigned int data_array[16]; | |
140 | #ifdef BUILD_LK | |
141 | //printf("[IND][K] y_____0%s\n", __func__); | |
142 | #else | |
143 | //printk("[IND][K] y_____1%s\n", __func__); | |
144 | #endif | |
4b9e9796 S |
145 | |
146 | data_array[0] = 0x47801500; | |
6fa3eb70 S |
147 | dsi_set_cmdq(&data_array, 1, 1); |
148 | MDELAY(1); | |
4b9e9796 | 149 | data_array[0] = 0x40811500; |
6fa3eb70 S |
150 | dsi_set_cmdq(&data_array, 1, 1); |
151 | MDELAY(1); | |
4b9e9796 | 152 | data_array[0] = 0x04821500; |
6fa3eb70 S |
153 | dsi_set_cmdq(&data_array, 1, 1); |
154 | MDELAY(1); | |
4b9e9796 | 155 | data_array[0] = 0x77831500; |
6fa3eb70 S |
156 | dsi_set_cmdq(&data_array, 1, 1); |
157 | MDELAY(1); | |
4b9e9796 | 158 | data_array[0] = 0x0F841500; |
6fa3eb70 S |
159 | dsi_set_cmdq(&data_array, 1, 1); |
160 | MDELAY(1); | |
4b9e9796 | 161 | data_array[0] = 0x70851500; |
6fa3eb70 S |
162 | dsi_set_cmdq(&data_array, 1, 1); |
163 | MDELAY(1); | |
4b9e9796 | 164 | data_array[0] = 0x70861500; |
6fa3eb70 S |
165 | dsi_set_cmdq(&data_array, 1, 1); |
166 | MDELAY(1); | |
6fa3eb70 S |
167 | |
168 | } | |
169 | ||
170 | ||
171 | // --------------------------------------------------------------------------- | |
172 | // LCM Driver Implementations | |
173 | // --------------------------------------------------------------------------- | |
174 | ||
175 | static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util) | |
176 | { | |
177 | memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS)); | |
178 | } | |
179 | ||
180 | ||
181 | static void lcm_get_params(LCM_PARAMS *params) | |
182 | { | |
183 | //[BUGFIX]-Mod-BEGIN by SCDTABLET.jinghuang@tcl.com,28/4/2015, | |
184 | //improve dsi config and power on/off sequence | |
185 | memset(params, 0, sizeof(LCM_PARAMS)); | |
186 | ||
187 | params->type = LCM_TYPE_DSI; | |
188 | ||
189 | params->width = FRAME_WIDTH; | |
190 | params->height = FRAME_HEIGHT; | |
191 | ||
192 | #if (LCM_DSI_CMD_MODE) | |
193 | params->dsi.mode = CMD_MODE; | |
194 | #else | |
195 | params->dsi.mode = BURST_VDO_MODE; //SYNC_PULSE_VDO_MODE;//BURST_VDO_MODE; | |
196 | #endif | |
197 | ||
198 | // DSI | |
199 | /* Command mode setting */ | |
200 | //1 Three lane or Four lane | |
201 | params->dsi.LANE_NUM = LCM_FOUR_LANE; | |
202 | //The following defined the fomat for data coming from LCD engine. | |
203 | params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888; | |
204 | ||
205 | // Video mode setting | |
206 | params->dsi.PS=LCM_PACKED_PS_24BIT_RGB888; | |
207 | ||
208 | params->dsi.vertical_sync_active = 0x05;// 3 2 | |
209 | params->dsi.vertical_backporch = 23;// 20 1 | |
210 | params->dsi.vertical_frontporch = 12; // 1 12 | |
211 | params->dsi.vertical_active_line = FRAME_HEIGHT; | |
212 | ||
213 | params->dsi.horizontal_sync_active = 0x16;// 50 2 | |
214 | params->dsi.horizontal_backporch = 160; | |
215 | params->dsi.horizontal_frontporch = 160; | |
216 | params->dsi.horizontal_active_pixel = FRAME_WIDTH; | |
217 | params->dsi.PLL_CLOCK=175; | |
218 | params->dsi.ssc_disable = TRUE; | |
219 | //[BUGFIX]-Mod-END by SCDTABLET.jinghuang@tcl.com | |
220 | ||
221 | } | |
222 | ||
223 | ||
224 | ||
225 | static void lcm_init(void) | |
226 | { | |
227 | //[BUGFIX]-Mod-BEGIN by SCDTABLET.jinghuang@tcl.com,28/4/2015, | |
228 | //improve dsi config and power on/off sequence | |
229 | ||
230 | lcd_DVDD_power_en(0); | |
231 | lcd_stbyb(0); | |
232 | lcd_reset(0); | |
233 | lcd_AVDD_power_en(0); | |
234 | MDELAY(30); | |
235 | ||
236 | lcd_DVDD_power_en(1); | |
237 | MDELAY(10); | |
238 | ||
239 | lcd_stbyb(1); | |
240 | MDELAY(10); | |
241 | ||
242 | lcd_reset(1); | |
243 | MDELAY(20); | |
244 | lcd_reset(0); | |
245 | MDELAY(10); | |
246 | lcd_reset(1); | |
247 | ||
248 | lcd_AVDD_power_en(1); | |
249 | ||
250 | init_lcm_registers(); | |
251 | MDELAY(50); | |
252 | //[BUGFIX]-Mod-END by SCDTABLET.jinghuang@tcl.com | |
253 | ||
254 | } | |
255 | ||
256 | ||
257 | static void lcm_suspend(void) | |
258 | { | |
259 | //[BUGFIX]-Mod-BEGIN by SCDTABLET.jinghuang@tcl.com,28/4/2015, | |
260 | //improve dsi config and power on/off sequence | |
261 | lcd_stbyb(0); | |
262 | MDELAY(80); | |
263 | ||
264 | lcd_AVDD_power_en(0); | |
265 | MDELAY(50); | |
266 | ||
267 | lcd_DVDD_power_en(0); | |
268 | MDELAY(10); | |
269 | ||
270 | lcd_reset(0); | |
271 | //[BUGFIX]-Mod-END by SCDTABLET.jinghuang@tcl.com | |
272 | } | |
273 | ||
274 | ||
275 | static void lcm_resume(void) | |
276 | { | |
277 | lcm_init(); | |
278 | } | |
279 | ||
280 | static unsigned int lcm_compare_id(void) | |
281 | { | |
282 | return 1; | |
283 | } | |
284 | ||
285 | static unsigned int lcm_esd_check(void) | |
286 | { | |
287 | #ifndef BUILD_LK | |
288 | char buffer[3]; | |
289 | int array[4]; | |
290 | int ret = 0; | |
291 | ||
292 | if(lcm_esd_test) | |
293 | { | |
294 | lcm_esd_test = FALSE; | |
295 | return TRUE; | |
296 | } | |
297 | ||
298 | array[0] = 0x5A871500; | |
299 | dsi_set_cmdq(array, 1, 1); | |
300 | ||
301 | array[0] = 0x125B1500; | |
302 | dsi_set_cmdq(array, 1, 1); | |
303 | ||
304 | array[0] = 0x55871500; | |
305 | dsi_set_cmdq(array, 1, 1); | |
306 | ||
307 | array[0] = 0x125B1500; | |
308 | dsi_set_cmdq(array, 1, 1); | |
309 | ||
310 | //array[0] = 0x08B11500; | |
311 | //dsi_set_cmdq(array, 1, 1); | |
312 | ||
313 | //MDELAY(2000); | |
314 | ||
315 | array[0] = 0x00013700; | |
316 | dsi_set_cmdq(array, 1, 1); | |
317 | ||
318 | read_reg_v2(0x81, buffer, 1); | |
319 | //printk("\n ZERO] [0x81]=0x%02x\n", buffer[0]); | |
320 | ||
4b9e9796 | 321 | if(buffer[0] != 0x40) |
6fa3eb70 S |
322 | { |
323 | printk("[LCM ERROR] [0x81]=0x%02x\n", buffer[0]); | |
324 | return TRUE; | |
325 | } | |
326 | else | |
327 | { | |
328 | printk("[LCM ESD OK] [0x81]=0x%02x\n", buffer[0]); | |
329 | array[0] = 0x925B1500; | |
330 | dsi_set_cmdq(array, 1, 1); | |
331 | ||
332 | array[0] = 0x5A871500; | |
333 | dsi_set_cmdq(array, 1, 1); | |
334 | ||
335 | array[0] = 0x925B1500; | |
336 | dsi_set_cmdq(array, 1, 1); | |
337 | ||
338 | array[0] = 0x00871500; | |
339 | dsi_set_cmdq(array, 1, 1); | |
340 | return FALSE; | |
341 | } | |
342 | ||
343 | // return TRUE: need recovery | |
344 | // return FALSE: No need recovery | |
345 | #else | |
346 | return FALSE; | |
347 | #endif | |
348 | } | |
349 | static unsigned int lcm_esd_recover(void) | |
350 | { | |
351 | #ifndef BUILD_LK | |
352 | printk("\n [LCM ERROR] lcm_esd_recover \n"); | |
353 | #endif | |
354 | lcd_DVDD_power_en(0); | |
355 | MDELAY(30); | |
356 | lcm_init(); | |
357 | return TRUE; | |
358 | } | |
359 | ||
360 | LCM_DRIVER kr076_ek79007_wsvga_dsi_vdo_lcm_drv = | |
361 | { | |
362 | .name = "kr076_ek79007_wsvga_dsi_vdo", | |
363 | .set_util_funcs = lcm_set_util_funcs, | |
364 | .get_params = lcm_get_params, | |
365 | .init = lcm_init, | |
366 | .suspend = lcm_suspend, | |
367 | .resume = lcm_resume, | |
368 | .compare_id = lcm_compare_id, | |
369 | .esd_check = lcm_esd_check, | |
370 | .esd_recover = lcm_esd_recover, | |
371 | #if (LCM_DSI_CMD_MODE) | |
372 | .set_backlight = lcm_setbacklight, | |
373 | .update = lcm_update, | |
374 | #endif | |
375 | }; | |
376 | ||
377 | ||
378 | ||
379 |