hx8392a_dsi_vdo.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #ifndef BUILD_LK
  2. #include <linux/string.h>
  3. #endif
  4. #include "lcm_drv.h"
  5. /* --------------------------------------------------------------------------- */
  6. /* Local Constants */
  7. /* --------------------------------------------------------------------------- */
  8. #define FRAME_WIDTH (720)
  9. #define FRAME_HEIGHT (1280)
  10. #define REGFLAG_DELAY 0xFE
  11. #define REGFLAG_END_OF_TABLE 0xFF /* END OF REGISTERS MARKER */
  12. /* --------------------------------------------------------------------------- */
  13. /* Local Variables */
  14. /* --------------------------------------------------------------------------- */
  15. static LCM_UTIL_FUNCS lcm_util = { 0 };
  16. #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
  17. #define UDELAY(n) (lcm_util.udelay(n))
  18. #define MDELAY(n) (lcm_util.mdelay(n))
  19. /* --------------------------------------------------------------------------- */
  20. /* Local Functions */
  21. /* --------------------------------------------------------------------------- */
  22. #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
  23. #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
  24. #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
  25. #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
  26. #define read_reg lcm_util.dsi_read_reg()
  27. struct LCM_setting_table {
  28. unsigned cmd;
  29. unsigned char count;
  30. unsigned char para_list[64];
  31. };
  32. static struct LCM_setting_table lcm_initialization_setting[] = {
  33. /*
  34. Note :
  35. Data ID will depends on the following rule.
  36. count of parameters > 1 => Data ID = 0x39
  37. count of parameters = 1 => Data ID = 0x15
  38. count of parameters = 0 => Data ID = 0x05
  39. Structure Format :
  40. {DCS command, count of parameters, {parameter list}}
  41. {REGFLAG_DELAY, milliseconds of time, {}},
  42. ...
  43. Setting ending by predefined flag
  44. {REGFLAG_END_OF_TABLE, 0x00, {}}
  45. */
  46. /* sleep out */
  47. { 0x11, 0, {} },
  48. { REGFLAG_DELAY, 120, {} },
  49. /* SET PASSWORD */
  50. { 0xB9, 3, {0xFF, 0x83, 0x92} },
  51. { REGFLAG_DELAY, 10, {} },
  52. /* set mipi 4 lane */
  53. { 0xBA, 17, {0x13, 0x83, 0x00, 0xD6,
  54. 0xC5, 0x10, 0x09, 0xFF,
  55. 0x0F, 0x27, 0x03, 0x21,
  56. 0x27, 0x25, 0x20, 0x00,
  57. 0x10} },
  58. /* SET POWER */
  59. { 0xB1, 13, {0x7C, 0x00, 0x43, 0xBB,
  60. 0x00, 0x1A, 0x1A, 0x2F,
  61. 0x36, 0x3F, 0x3F, 0x42,
  62. 0x7A} },
  63. /* SET DISPLAY RELATED REGISTER */
  64. { 0xB2, 12, {0x08, 0xC8, 0x06, 0x06,
  65. 0x04, 0x84, 0x00, 0xFF,
  66. 0x06, 0x06, 0x04, 0x20} },
  67. /* SET CYC */
  68. { 0xB4, 23, {0x00, 0x00, 0x05, 0x0A,
  69. 0x8F, 0x06, 0x0A, 0x95,
  70. 0x01, 0x07, 0x06, 0x0C,
  71. 0x02, 0x08, 0x08, 0x21,
  72. 0x04, 0x02, 0x08, 0x01,
  73. 0x04, 0x1A, 0x95} },
  74. /* set TE on */
  75. { 0x35, 1, {0x00} },
  76. { 0xBF, 4, {0x05, 0x60, 0x02, 0x00} },
  77. /* VCOM//64 */
  78. { 0xB6, 1, {0x6A} },
  79. /* SET RGB OR BGR */
  80. { 0x36, 1, {0x08} },
  81. /* SET RGB OR BGR */
  82. { 0xC0, 2, {0x03, 0x94} },
  83. /* SET DSI VIDEO MODE */
  84. { 0xC2, 1, {0x03} },
  85. { 0xC6, 4, {0x35, 0x08, 0x20, 0x04} },
  86. /* SET PANEL */
  87. { 0xCC, 1, {0x09} },
  88. { 0xD4, 1, {0x00} },
  89. { 0xD5, 23, {0x00, 0x01, 0x04, 0x00,
  90. 0x01, 0x67, 0x89, 0xAB,
  91. 0x45, 0xCC, 0xCC, 0xCC,
  92. 0x00, 0x10, 0x54, 0xBA,
  93. 0x98, 0x76, 0xCC, 0xCC,
  94. 0xCC, 0x00, 0x00} },
  95. { 0xD8, 23, {0x00, 0x00, 0x05, 0x00,
  96. 0x9A, 0x00, 0x02, 0x95,
  97. 0x01, 0x07, 0x06, 0x00,
  98. 0x08, 0x08, 0x00, 0x1D,
  99. 0x08, 0x08, 0x08, 0x00,
  100. 0x00, 0x00, 0x77} },
  101. { 0xE0, 34, {0x00, 0x12, 0x19, 0x33,
  102. 0x36, 0x3F, 0x28, 0x47,
  103. 0x06, 0x0C, 0x0E, 0x12,
  104. 0x14, 0x12, 0x14, 0x12,
  105. 0x1A, 0x00, 0x12, 0x19,
  106. 0x33, 0x36, 0x3F, 0x28,
  107. 0x47, 0x06, 0x0C, 0x0E,
  108. 0x12, 0x14, 0x12, 0x14,
  109. 0x12, 0x1A} },
  110. { 0xE1, 34, {0x00, 0x12, 0x19, 0x33,
  111. 0x36, 0x3F, 0x28, 0x47,
  112. 0x06, 0x0C, 0x0E, 0x12,
  113. 0x14, 0x12, 0x14, 0x12,
  114. 0x1A, 0x00, 0x12, 0x19,
  115. 0x33, 0x36, 0x3F, 0x28,
  116. 0x47, 0x06, 0x0C, 0x0E,
  117. 0x12, 0x14, 0x12, 0x14,
  118. 0x12, 0x1A} },
  119. { 0xE2, 34, {0x00, 0x12, 0x19, 0x33,
  120. 0x36, 0x3F, 0x28, 0x47,
  121. 0x06, 0x0C, 0x0E, 0x12,
  122. 0x14, 0x12, 0x14, 0x12,
  123. 0x1A, 0x00, 0x12, 0x19,
  124. 0x33, 0x36, 0x3F, 0x28,
  125. 0x47, 0x06, 0x0C, 0x0E,
  126. 0x12, 0x14, 0x12, 0x14,
  127. 0x12, 0x1A} },
  128. /* SET PIXEL FORMAT */
  129. { 0x3A, 1, {0x77} },
  130. /* sleep out */
  131. { 0x29, 0, {} },
  132. };
  133. static struct LCM_setting_table lcm_deep_sleep_mode_in_setting[] = {
  134. /* Sleep Mode On */
  135. { 0x10, 0, {} },
  136. { REGFLAG_DELAY, 120, {} },
  137. { REGFLAG_END_OF_TABLE, 0x00, {} }
  138. };
  139. static void push_table(struct LCM_setting_table *table, unsigned int count,
  140. unsigned char force_update)
  141. {
  142. unsigned int i;
  143. for (i = 0; i < count; i++) {
  144. unsigned cmd;
  145. cmd = table[i].cmd;
  146. switch (cmd) {
  147. case REGFLAG_DELAY:
  148. MDELAY(table[i].count);
  149. break;
  150. case REGFLAG_END_OF_TABLE:
  151. break;
  152. default:
  153. dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
  154. }
  155. }
  156. }
  157. /* --------------------------------------------------------------------------- */
  158. /* LCM Driver Implementations */
  159. /* --------------------------------------------------------------------------- */
  160. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  161. {
  162. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  163. }
  164. static void lcm_get_params(LCM_PARAMS *params)
  165. {
  166. memset(params, 0, sizeof(LCM_PARAMS));
  167. params->type = LCM_TYPE_DSI;
  168. params->width = FRAME_WIDTH;
  169. params->height = FRAME_HEIGHT;
  170. /* enable tearing-free */
  171. params->dbi.te_mode = LCM_DBI_TE_MODE_VSYNC_ONLY;
  172. params->dbi.te_edge_polarity = LCM_POLARITY_RISING;
  173. params->dsi.mode = SYNC_PULSE_VDO_MODE;
  174. /* DSI */
  175. /* Command mode setting */
  176. params->dsi.LANE_NUM = LCM_FOUR_LANE;
  177. /* The following defined the fomat for data coming from LCD engine. */
  178. params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
  179. params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
  180. params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
  181. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  182. /* Highly depends on LCD driver capability. */
  183. /* Not support in MT6573 */
  184. params->dsi.packet_size = 256;
  185. params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;
  186. params->dsi.vertical_sync_active = 2;
  187. params->dsi.vertical_backporch = 6;
  188. params->dsi.vertical_frontporch = 17;
  189. params->dsi.vertical_active_line = FRAME_HEIGHT;
  190. params->dsi.horizontal_sync_active = 50;
  191. params->dsi.horizontal_backporch = 50;
  192. params->dsi.horizontal_frontporch = 50;
  193. params->dsi.horizontal_active_pixel = FRAME_WIDTH;
  194. #ifndef CONFIG_FPGA_EARLY_PORTING
  195. params->dsi.PLL_CLOCK = 218; /* this value must be in MTK suggested table */
  196. #else
  197. params->dsi.pll_div1 = 0;
  198. params->dsi.pll_div2 = 0;
  199. params->dsi.fbk_div = 0x1;
  200. #endif
  201. params->dsi.cont_clock = 1;
  202. params->dsi.clk_lp_per_line_enable = 0;
  203. params->dsi.esd_check_enable = 1;
  204. params->dsi.customization_esd_check_enable = 0;
  205. params->dsi.lcm_esd_check_table[0].cmd = 0x53;
  206. params->dsi.lcm_esd_check_table[0].count = 1;
  207. params->dsi.lcm_esd_check_table[0].para_list[0] = 0x24;
  208. }
  209. static void lcm_init(void)
  210. {
  211. SET_RESET_PIN(1);
  212. SET_RESET_PIN(0);
  213. MDELAY(10);
  214. SET_RESET_PIN(1);
  215. MDELAY(20);
  216. push_table(lcm_initialization_setting,
  217. sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
  218. }
  219. static void lcm_suspend(void)
  220. {
  221. push_table(lcm_deep_sleep_mode_in_setting,
  222. sizeof(lcm_deep_sleep_mode_in_setting) / sizeof(struct LCM_setting_table), 1);
  223. }
  224. static void lcm_resume(void)
  225. {
  226. lcm_init();
  227. }
  228. LCM_DRIVER hx8392a_dsi_vdo_lcm_drv = {
  229. .name = "hx8392a_vdo_cmd",
  230. .set_util_funcs = lcm_set_util_funcs,
  231. .get_params = lcm_get_params,
  232. .init = lcm_init,
  233. .suspend = lcm_suspend,
  234. .resume = lcm_resume,
  235. };