ili9881d_hdplus_vdo_jingtai.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. #ifndef BUILD_LK
  2. #include <linux/string.h>
  3. #include <linux/wait.h>
  4. #endif
  5. #include "lcm_drv.h"
  6. #ifdef MTK_ROUND_CORNER_SUPPORT
  7. #include "data_rgba4444_roundedpattern.h"
  8. #endif
  9. // ---------------------------------------------------------------------------
  10. // Local Constantsq
  11. // ---------------------------------------------------------------------------
  12. #define FRAME_WIDTH (720)
  13. #define FRAME_HEIGHT (1560)
  14. #define LCM_DSI_CMD_MODE 0
  15. #ifndef TRUE
  16. #define TRUE 1
  17. #endif
  18. #ifndef FALSE
  19. #define FALSE 0
  20. #endif
  21. #define REGFLAG_DELAY 0XFE
  22. #define REGFLAG_END_OF_TABLE 0xFFF // END OF REGISTERS MARKER
  23. // static unsigned int lcm_esd_test = FALSE; ///only for ESD test
  24. // ---------------------------------------------------------------------------
  25. // Local Variables
  26. // ---------------------------------------------------------------------------
  27. static LCM_UTIL_FUNCS lcm_util = {0};
  28. #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
  29. #define UDELAY(n) (lcm_util.udelay(n))
  30. #define MDELAY(n) (lcm_util.mdelay(n))
  31. // ---------------------------------------------------------------------------
  32. // Local Functions
  33. // ---------------------------------------------------------------------------
  34. #define dsi_set_cmdq_V3(para_tbl,size,force_update) lcm_util.dsi_set_cmdq_V3(para_tbl,size,force_update)
  35. #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
  36. #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
  37. #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
  38. #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
  39. #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
  40. #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
  41. struct LCM_setting_table {
  42. unsigned char cmd;
  43. unsigned char count;
  44. unsigned char para_list[100];
  45. };
  46. static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
  47. {
  48. unsigned int i;
  49. for(i = 0; i < count; i++)
  50. {
  51. unsigned cmd;
  52. cmd = table[i].cmd;
  53. switch (cmd)
  54. {
  55. case REGFLAG_DELAY :
  56. MDELAY(table[i].count);
  57. break;
  58. case REGFLAG_END_OF_TABLE :
  59. break;
  60. default:
  61. dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
  62. }
  63. }
  64. }
  65. static struct LCM_setting_table lcm_initialization_setting[] = {
  66. {0xFF,03,{0x98,0x81,0x01}},
  67. {0x91,01,{0x00}},
  68. {0x92,01,{0x00}},
  69. {0x93,01,{0x73}},
  70. {0x94,01,{0x00}},
  71. {0x95,01,{0x00}},
  72. {0x96,01,{0x08}},
  73. {0x97,01,{0x00}},
  74. {0x98,01,{0x00}},
  75. {0x09,01,{0x00}},
  76. {0x0a,01,{0x00}},
  77. {0x0b,01,{0x00}},
  78. {0x0c,01,{0x00}},
  79. {0x0d,01,{0x00}},
  80. {0x0e,01,{0x00}},
  81. {0x0f,01,{0x20}},
  82. {0x10,01,{0x20}},
  83. {0x11,01,{0x00}},
  84. {0x12,01,{0x00}},
  85. {0x13,01,{0x02}},
  86. {0x14,01,{0x00}},
  87. {0x15,01,{0x08}},
  88. {0x16,01,{0x10}},
  89. {0x17,01,{0x00}},
  90. {0x18,01,{0x00}},
  91. {0x19,01,{0x00}},
  92. {0x1a,01,{0x00}},
  93. {0x1b,01,{0x00}},
  94. {0x1c,01,{0x00}},
  95. {0x1d,01,{0x00}},
  96. {0x1e,01,{0xC0}},
  97. {0x1f,01,{0x00}},
  98. {0x20,01,{0x06}},
  99. {0x21,01,{0x01}},
  100. {0x22,01,{0x00}},
  101. {0x23,01,{0x00}},
  102. {0x24,01,{0x00}},
  103. {0x25,01,{0x00}},
  104. {0x26,01,{0x00}},
  105. {0x27,01,{0x00}},
  106. {0x28,01,{0x33}},
  107. {0x29,01,{0x33}},
  108. {0x2a,01,{0x00}},
  109. {0x2b,01,{0x00}},
  110. {0x2c,01,{0x09}},
  111. {0x2d,01,{0x09}},
  112. {0x2e,01,{0x09}},
  113. {0x2f,01,{0x09}},
  114. {0x30,01,{0x00}},
  115. {0x31,01,{0x00}},
  116. {0x32,01,{0x02}},
  117. {0x33,01,{0x00}},
  118. {0x34,01,{0x00}},
  119. {0x35,01,{0x0A}},
  120. {0x36,01,{0x00}},
  121. {0x37,01,{0x08}},
  122. {0x38,01,{0x00}},
  123. {0x39,01,{0x07}},
  124. {0x3a,01,{0x00}},
  125. {0x3b,01,{0x00}},
  126. {0x3c,01,{0x00}},
  127. {0x40,01,{0x03}},
  128. {0x41,01,{0x20}},
  129. {0x42,01,{0x00}},
  130. {0x43,01,{0x40}},
  131. {0x44,01,{0x03}},
  132. {0x45,01,{0x00}},
  133. {0x46,01,{0x01}},
  134. {0x47,01,{0x08}},
  135. {0x48,01,{0x00}},
  136. {0x49,01,{0x00}},
  137. {0x4a,01,{0x00}},
  138. {0x4b,01,{0x00}},
  139. {0x4c,01,{0x28}},
  140. {0x4d,01,{0x22}},
  141. {0x4e,01,{0x8A}},
  142. {0x4f,01,{0x46}},
  143. {0x50,01,{0x70}},
  144. {0x51,01,{0x26}},
  145. {0x52,01,{0x22}},
  146. {0x53,01,{0x22}},
  147. {0x54,01,{0x22}},
  148. {0x55,01,{0x22}},
  149. {0x56,01,{0x16}},
  150. {0x57,01,{0x29}},
  151. {0x58,01,{0x22}},
  152. {0x59,01,{0x9B}},
  153. {0x5a,01,{0x57}},
  154. {0x5b,01,{0x70}},
  155. {0x5c,01,{0x27}},
  156. {0x5d,01,{0x22}},
  157. {0x5e,01,{0x22}},
  158. {0x5f,01,{0x22}},
  159. {0x60,01,{0x22}},
  160. {0x61,01,{0x16}},
  161. {0x62,01,{0x06}},
  162. {0x63,01,{0x07}},
  163. {0x64,01,{0x02}},
  164. {0x65,01,{0x02}},
  165. {0x66,01,{0x02}},
  166. {0x67,01,{0x55}},
  167. {0x68,01,{0x57}},
  168. {0x69,01,{0x59}},
  169. {0x6a,01,{0x5B}},
  170. {0x6b,01,{0x00}},
  171. {0x6c,01,{0xA7}},
  172. {0x6d,01,{0x09}},
  173. {0x6e,01,{0x02}},
  174. {0x6f,01,{0x02}},
  175. {0x70,01,{0x02}},
  176. {0x71,01,{0x02}},
  177. {0x72,01,{0x02}},
  178. {0x73,01,{0x02}},
  179. {0x74,01,{0x02}},
  180. {0x75,01,{0x02}},
  181. {0x76,01,{0x02}},
  182. {0x77,01,{0xA6}},
  183. {0x78,01,{0x01}},
  184. {0x79,01,{0x06}},
  185. {0x7a,01,{0x02}},
  186. {0x7b,01,{0x02}},
  187. {0x7c,01,{0x02}},
  188. {0x7d,01,{0x54}},
  189. {0x7e,01,{0x56}},
  190. {0x7f,01,{0x58}},
  191. {0x80,01,{0x5A}},
  192. {0x81,01,{0x00}},
  193. {0x82,01,{0xA7}},
  194. {0x83,01,{0x08}},
  195. {0x84,01,{0x02}},
  196. {0x85,01,{0x02}},
  197. {0x86,01,{0x02}},
  198. {0x87,01,{0x02}},
  199. {0x88,01,{0x02}},
  200. {0x89,01,{0x02}},
  201. {0x8a,01,{0x02}},
  202. {0x8b,01,{0x02}},
  203. {0x8c,01,{0x02}},
  204. {0x8d,01,{0xA6}},
  205. {0x8e,01,{0x01}},
  206. {0xa0,01,{0x35}},
  207. {0xa1,01,{0x00}},
  208. {0xa2,01,{0x00}},
  209. {0xa3,01,{0x00}},
  210. {0xa4,01,{0x00}},
  211. {0xa5,01,{0x10}},
  212. {0xa6,01,{0x08}},
  213. {0xa7,01,{0x00}},
  214. {0xa8,01,{0x00}},
  215. {0xa9,01,{0x00}},
  216. {0xaa,01,{0x00}},
  217. {0xab,01,{0x00}},
  218. {0xac,01,{0x00}},
  219. {0xad,01,{0x00}},
  220. {0xae,01,{0xff}},
  221. {0xaf,01,{0x00}},
  222. {0xb0,01,{0x00}},
  223. {0xFF,03,{0x98,0x81,0x02}},
  224. {0x42,01,{0x29}},
  225. {0xA0,20,{0x00,0x0A,0x13,0x10,0x10,0x22,0x16,0x19,0x53,0x1A,0x26,0x54,0x1F,0x1F,0x53,0x26,0x29,0x4D,0x5D,0x3F}},
  226. {0xC0,20,{0x00,0x0A,0x13,0x10,0x10,0x22,0x16,0x19,0x53,0x1A,0x26,0x54,0x1F,0x1F,0x53,0x26,0x29,0x4D,0x5D,0x3F}},
  227. {0x18,01,{0xF4}},
  228. {0xFF,03,{0x98,0x81,0x04}},
  229. {0x00,01,{0x00}},
  230. {0x5D,01,{0x6B}},
  231. {0x5E,01,{0x6B}},
  232. {0x60,01,{0x92}},
  233. {0x62,01,{0x88}},
  234. {0x82,01,{0x20}},
  235. {0x84,01,{0x20}},
  236. {0x86,01,{0x38}},
  237. {0x66,01,{0x04}},
  238. {0xC1,01,{0x70}},
  239. {0x70,01,{0x60}},
  240. {0x71,01,{0x00}},
  241. {0x5B,01,{0x33}},
  242. {0x6C,01,{0x10}},
  243. {0x77,01,{0x03}},
  244. {0x7B,01,{0x02}},
  245. {0xFF,03,{0x98,0x81,0x01}},
  246. {0xF0,01,{0x01}},
  247. {0xF1,01,{0x0E}},
  248. {0xFF,03,{0x98,0x81,0x05}},
  249. {0x22,01,{0x3A}},
  250. {0xFF,03,{0x98,0x81,0x00}},
  251. {0x35,01,{0x00}},
  252. {0x11, 1, {0x00}},
  253. {REGFLAG_DELAY, 100, {}},
  254. // Display ON
  255. {0x29, 1, {0x00}},
  256. {REGFLAG_DELAY, 100, {}},
  257. };
  258. static void init_lcm_registers(void)
  259. {
  260. #if 1
  261. push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
  262. #else
  263. #endif
  264. }
  265. /*
  266. static struct LCM_setting_table lcm_sleep_out_setting[] = {
  267. // Sleep Out
  268. {0x11, 0, {0x00}},
  269. {REGFLAG_DELAY, 120, {}},
  270. // Display ON
  271. {0x29, 0, {0x00}},
  272. {REGFLAG_DELAY, 100, {}},
  273. {REGFLAG_END_OF_TABLE, 0x00, {}}
  274. };
  275. static struct LCM_setting_table lcm_deep_sleep_mode_in_setting[] = {
  276. // Display off sequence
  277. {0x28, 0, {0x00}},
  278. // Sleep Mode On
  279. {0x10, 0, {0x00}},
  280. {REGFLAG_END_OF_TABLE, 0x00, {}}
  281. };
  282. */
  283. // ---------------------------------------------------------------------------
  284. // LCM Driver Implementations
  285. // ---------------------------------------------------------------------------
  286. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  287. {
  288. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  289. }
  290. static void lcm_get_params(LCM_PARAMS *params)
  291. {
  292. memset(params, 0, sizeof(LCM_PARAMS));
  293. params->type = LCM_TYPE_DSI;
  294. params->physical_width = 64;
  295. params->physical_height = 139;
  296. params->width = FRAME_WIDTH;
  297. params->height = FRAME_HEIGHT;
  298. //params->physical_width = 71;
  299. //params->physical_height = 129;
  300. #if (LCM_DSI_CMD_MODE)
  301. params->dsi.mode = CMD_MODE;
  302. #else
  303. params->dsi.mode = SYNC_PULSE_VDO_MODE; //SYNC_PULSE_VDO_MODE;//BURST_VDO_MODE;
  304. #endif
  305. // DSI
  306. /* Command mode setting */
  307. //1 Three lane or Four lane
  308. params->dsi.LANE_NUM = LCM_THREE_LANE;
  309. //The following defined the fomat for data coming from LCD engine.
  310. params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
  311. params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
  312. params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
  313. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  314. // Highly depends on LCD driver capability.
  315. // Not support in MT6573
  316. params->dsi.packet_size=256;
  317. // Video mode setting
  318. 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
  319. params->dsi.PS=LCM_PACKED_PS_24BIT_RGB888;
  320. //params->dsi.word_count=720*3;
  321. params->dsi.vertical_sync_active = 16;
  322. params->dsi.vertical_backporch = 40;
  323. params->dsi.vertical_frontporch = 30;
  324. params->dsi.vertical_active_line = FRAME_HEIGHT;
  325. params->dsi.horizontal_sync_active = 30;
  326. params->dsi.horizontal_backporch = 30;
  327. params->dsi.horizontal_frontporch = 50;
  328. params->dsi.horizontal_active_pixel = FRAME_WIDTH;
  329. // params->dsi.compatibility_for_nvk = 0;
  330. params->dsi.ssc_disable = 1;
  331. params->dsi.esd_check_enable = 1;
  332. params->dsi.customization_esd_check_enable = 1;
  333. params->dsi.lcm_esd_check_table[0].cmd = 0x0a;
  334. params->dsi.lcm_esd_check_table[0].count = 1;
  335. params->dsi.lcm_esd_check_table[0].para_list[0] = 0x9C;
  336. params->dsi.HS_TRAIL=20;
  337. params->dsi.PLL_CLOCK = 320;//183 212 195 200 205 180 230
  338. #ifdef MTK_ROUND_CORNER_SUPPORT
  339. params->round_corner_params.round_corner_en = 1;
  340. params->round_corner_params.full_content = 0;
  341. params->round_corner_params.w = ROUND_CORNER_W;
  342. params->round_corner_params.h = ROUND_CORNER_H;
  343. params->round_corner_params.lt_addr = left_top;
  344. params->round_corner_params.lb_addr = left_bottom;
  345. params->round_corner_params.rt_addr = right_top;
  346. params->round_corner_params.rb_addr = right_bottom;
  347. #endif
  348. }
  349. static unsigned int lcm_compare_id(void);
  350. static void lcm_suspend(void)
  351. {
  352. unsigned int data_array[16];
  353. data_array[0] = 0x00280500;
  354. dsi_set_cmdq(data_array, 1, 1);
  355. MDELAY(50);
  356. data_array[0]= 0x00100500;
  357. dsi_set_cmdq(data_array, 1, 1);
  358. MDELAY(120);
  359. // push_table(lcm_deep_sleep_mode_in_setting, sizeof(lcm_deep_sleep_mode_in_setting) / sizeof(struct LCM_setting_table), 1);
  360. }
  361. #if (LCM_DSI_CMD_MODE)
  362. static void lcm_update(unsigned int x, unsigned int y,
  363. unsigned int width, unsigned int height)
  364. {
  365. unsigned int x0 = x;
  366. unsigned int y0 = y;
  367. unsigned int x1 = x0 + width - 1;
  368. unsigned int y1 = y0 + height - 1;
  369. unsigned char x0_MSB = ((x0>>8)&0xFF);
  370. unsigned char x0_LSB = (x0&0xFF);
  371. unsigned char x1_MSB = ((x1>>8)&0xFF);
  372. unsigned char x1_LSB = (x1&0xFF);
  373. unsigned char y0_MSB = ((y0>>8)&0xFF);
  374. unsigned char y0_LSB = (y0&0xFF);
  375. unsigned char y1_MSB = ((y1>>8)&0xFF);
  376. unsigned char y1_LSB = (y1&0xFF);
  377. unsigned int data_array[16];
  378. data_array[0]= 0x00053902;
  379. data_array[1]= (x1_MSB<<24)|(x0_LSB<<16)|(x0_MSB<<8)|0x2a;
  380. data_array[2]= (x1_LSB);
  381. dsi_set_cmdq(data_array, 3, 1);
  382. data_array[0]= 0x00053902;
  383. data_array[1]= (y1_MSB<<24)|(y0_LSB<<16)|(y0_MSB<<8)|0x2b;
  384. data_array[2]= (y1_LSB);
  385. dsi_set_cmdq(data_array, 3, 1);
  386. data_array[0]= 0x002c3909;
  387. dsi_set_cmdq(data_array, 1, 0);
  388. }
  389. #endif
  390. static unsigned int lcm_compare_id(void)
  391. {
  392. int array[4];
  393. char buffer[5];
  394. char id_high=0;
  395. char id_low=0;
  396. int id=0;
  397. SET_RESET_PIN(1);
  398. MDELAY(20);
  399. SET_RESET_PIN(0);
  400. MDELAY(20);
  401. SET_RESET_PIN(1);
  402. MDELAY(120);
  403. array[0]=0x00043902;
  404. array[1]=0x068198FF;
  405. dsi_set_cmdq(array, 2, 1);
  406. MDELAY(10);
  407. array[0]=0x00023700;
  408. dsi_set_cmdq(array, 1, 1);
  409. read_reg_v2(0xF0, buffer,1);
  410. id_high = buffer[0]; //0x98
  411. array[0]=0x00023700;
  412. dsi_set_cmdq(array, 1, 1);
  413. read_reg_v2(0xF1, buffer,1);
  414. id_low = buffer[0]; //0x81
  415. id =(id_high << 8) | id_low;
  416. #ifdef BUILD_LK
  417. printf("zrl_lk -- ili9881 0x%x , 0x%x, 0x%x \n", id_high, id_low, id);
  418. #else
  419. printk("zrl_lk -- ili9881 0x%x , 0x%x, 0x%x \n", id_high, id_low, id);
  420. #endif
  421. return (id ==0x9881)?1:0;
  422. }
  423. static void lcm_init(void)
  424. {
  425. SET_RESET_PIN(1);
  426. MDELAY(10); //20130924 add
  427. SET_RESET_PIN(0);
  428. MDELAY(50);//Must > 5ms //6 20130924 changed
  429. SET_RESET_PIN(1);
  430. MDELAY(100);//Must > 50ms //50 20130924 changed
  431. init_lcm_registers();
  432. // lcm_compare_id();
  433. }
  434. static void lcm_resume(void)
  435. {
  436. lcm_init();
  437. // push_table(lcm_sleep_out_setting, sizeof(lcm_sleep_out_setting) / sizeof(struct LCM_setting_table), 1);
  438. }
  439. LCM_DRIVER ili9881d_hdplus_vdo_jingtai_lcm_drv =
  440. {
  441. .name = "ili9881d_hdplus_vdo_jingtai",
  442. .set_util_funcs = lcm_set_util_funcs,
  443. .get_params = lcm_get_params,
  444. .init = lcm_init,
  445. .suspend = lcm_suspend,
  446. .resume = lcm_resume,
  447. .compare_id = lcm_compare_id,
  448. #if (LCM_DSI_CMD_MODE)
  449. .update = lcm_update,
  450. #endif
  451. };