hx8389c_dsi_vdo.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2015. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #include "lcm_drv.h"
  32. #include <debug.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. // ---------------------------------------------------------------------------
  36. // Local Constants
  37. // ---------------------------------------------------------------------------
  38. #define FRAME_WIDTH (540)
  39. #define FRAME_HEIGHT (960)
  40. #define REGFLAG_DELAY 0xFE
  41. #define REGFLAG_END_OF_TABLE 0xFF /* END OF REGISTERS MARKER */
  42. // ---------------------------------------------------------------------------
  43. // Local Variables
  44. // ---------------------------------------------------------------------------
  45. static LCM_UTIL_FUNCS lcm_util = { 0 };
  46. #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
  47. #define UDELAY(n) (lcm_util.udelay(n))
  48. #define MDELAY(n) (lcm_util.mdelay(n))
  49. // ---------------------------------------------------------------------------
  50. // Local Functions
  51. // ---------------------------------------------------------------------------
  52. #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
  53. #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
  54. #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
  55. #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
  56. #define read_reg lcm_util.dsi_read_reg()
  57. #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
  58. static struct LCM_setting_table {
  59. unsigned cmd;
  60. unsigned char count;
  61. unsigned char para_list[64];
  62. };
  63. static struct LCM_setting_table lcm_initialization_setting[] = {
  64. /*
  65. Note :
  66. Data ID will depends on the following rule.
  67. count of parameters > 1 => Data ID = 0x39
  68. count of parameters = 1 => Data ID = 0x15
  69. count of parameters = 0 => Data ID = 0x05
  70. Structure Format :
  71. {DCS command, count of parameters, {parameter list}}
  72. {REGFLAG_DELAY, milliseconds of time, {}},
  73. ...
  74. Setting ending by predefined flag
  75. {REGFLAG_END_OF_TABLE, 0x00, {}}
  76. */
  77. /* SET PASSWORD//10//F2//58 */
  78. { 0xB9, 03, {0xFF, 0x83, 0x89} },
  79. /* SET POWER HI */
  80. { 0xB1, 20, {0x7F, 0x10, 0x10, 0x32, 0x32, 0x50, 0x10, 0xF2, 0x58, 0x80,
  81. 0x20, 0x20, 0xF8, 0xAA, 0xAA, 0xA0, 0x00, 0x80, 0x30, 0x00} },
  82. { 0xB2, 10, {0x80, 0x50, 0x05, 0x07, 0x40, 0x38, 0x11, 0x64, 0x5D, 0x09} },
  83. /* SET CYC HI */
  84. { 0xB4, 11, {0x70, 0x70, 0x70, 0x70, 0x00, 0x00, 0x10, 0x76, 0x10, 0x76,
  85. 0xB0} },
  86. /* SET GAMMA */
  87. { 0xD3, 35, {0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x32, 0x10, 0x00,
  88. 0x00, 0x00, 0x03, 0xC6, 0x03, 0xC6, 0x00, 0x00, 0x00, 0x00,
  89. 0x35, 0x33, 0x04, 0x04, 0x37, 0x00, 0x00, 0x00, 0x05, 0x08,
  90. 0x00, 0x00, 0x0A, 0x00, 0x01} },
  91. { 0xD5, 38, {0x18, 0x18, 0x18, 0x18, 0x19, 0x19, 0x18, 0x18, 0x20, 0x21,
  92. 0x24, 0x25, 0x18, 0x18, 0x18, 0x18, 0x00, 0x01, 0x04, 0x05,
  93. 0x02, 0x03, 0x06, 0x07, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
  94. 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18} },
  95. { 0xD6, 38, {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x19, 0x19, 0x25, 0x24,
  96. 0x21, 0x20, 0x18, 0x18, 0x18, 0x18, 0x07, 0x06, 0x03, 0x02,
  97. 0x05, 0x04, 0x01, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
  98. 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18} },
  99. { 0xCC, 01, {0x02} },
  100. { 0xC7, 04, {0x00, 0x80, 0x00, 0xC0} },
  101. { 0xD2, 01, {0x33} },
  102. { 0xE0, 42, {0x00, 0x0F, 0x16, 0x35, 0x3B, 0x3F, 0x21, 0x43, 0x07, 0x0B,
  103. 0x0D, 0x18, 0x0E, 0x10, 0x12, 0x11, 0x13, 0x06, 0x10, 0x13,
  104. 0x18, 0x00, 0x0F, 0x15, 0x35, 0x3B, 0x3F, 0x21, 0x42, 0x07,
  105. 0x0B, 0x0D, 0x18, 0x0D, 0x11, 0x13, 0x11, 0x12, 0x07, 0x11,
  106. 0x12, 0x17} },
  107. { 0xB6, 03, {0x88, 0x88, 0x00} },
  108. { 0x35, 01, {0x00} },
  109. { 0x11, 00, {} },
  110. /* DISPLAY ON */
  111. { 0x29, 00, {} },
  112. /* stop loop */
  113. { REGFLAG_END_OF_TABLE, 0, {0x00} }
  114. };
  115. static struct LCM_setting_table lcm_set_window[] = {
  116. { 0x2A, 4, {0x00, 0x00, (FRAME_WIDTH>>8), (FRAME_WIDTH&0xFF)} },
  117. { 0x2B, 4, {0x00, 0x00, (FRAME_HEIGHT>>8), (FRAME_HEIGHT&0xFF)} },
  118. { REGFLAG_END_OF_TABLE, 0x00, {} }
  119. };
  120. static struct LCM_setting_table lcm_sleep_out_setting[] = {
  121. // Sleep Out
  122. { 0x10, 0, {} },
  123. { REGFLAG_DELAY, 120, {} },
  124. // Display ON
  125. { 0x29, 0, {} },
  126. { REGFLAG_END_OF_TABLE, 0x00, {} }
  127. };
  128. static struct LCM_setting_table lcm_deep_sleep_mode_in_setting[] = {
  129. // Sleep Mode On
  130. { 0x10, 0, {} },
  131. { REGFLAG_DELAY, 120, {} },
  132. { REGFLAG_END_OF_TABLE, 0x00, {} }
  133. };
  134. static struct LCM_setting_table lcm_backlight_level_setting[] = {
  135. { 0x51, 1, {0xFF} },
  136. { REGFLAG_END_OF_TABLE, 0x00, {} }
  137. };
  138. static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
  139. {
  140. unsigned int i;
  141. for (i = 0; i < count; i++) {
  142. unsigned cmd;
  143. cmd = table[i].cmd;
  144. switch (cmd) {
  145. case REGFLAG_DELAY:
  146. MDELAY(table[i].count);
  147. break;
  148. case REGFLAG_END_OF_TABLE:
  149. break;
  150. default:
  151. dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
  152. }
  153. }
  154. }
  155. // ---------------------------------------------------------------------------
  156. // LCM Driver Implementations
  157. // ---------------------------------------------------------------------------
  158. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  159. {
  160. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  161. }
  162. static void lcm_get_params(LCM_PARAMS *params)
  163. {
  164. memset(params, 0, sizeof(LCM_PARAMS));
  165. params->type = LCM_TYPE_DSI;
  166. params->width = FRAME_WIDTH;
  167. params->height = FRAME_HEIGHT;
  168. // enable tearing-free
  169. params->dbi.te_mode = LCM_DBI_TE_MODE_VSYNC_ONLY;
  170. params->dbi.te_edge_polarity = LCM_POLARITY_RISING;
  171. params->dsi.mode = SYNC_PULSE_VDO_MODE;
  172. // DSI
  173. /* Command mode setting */
  174. params->dsi.LANE_NUM = LCM_TWO_LANE;
  175. //The following defined the fomat for data coming from LCD engine.
  176. params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
  177. params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
  178. params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
  179. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  180. // Highly depends on LCD driver capability.
  181. // Not support in MT6573
  182. params->dsi.packet_size = 256;
  183. params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;
  184. params->dsi.vertical_sync_active = 2;
  185. params->dsi.vertical_backporch = 5;
  186. params->dsi.vertical_frontporch = 9;
  187. params->dsi.vertical_active_line = FRAME_HEIGHT;
  188. params->dsi.horizontal_sync_active = 40;
  189. params->dsi.horizontal_backporch = 41;
  190. params->dsi.horizontal_frontporch = 60;
  191. params->dsi.horizontal_active_pixel = FRAME_WIDTH;
  192. #ifndef CONFIG_FPGA_EARLY_PORTING
  193. params->dsi.PLL_CLOCK = 230; /* this value must be in MTK suggested table */
  194. #else
  195. params->dsi.pll_div1 = 0;
  196. params->dsi.pll_div2 = 0;
  197. params->dsi.fbk_div = 0x1;
  198. #endif
  199. params->dsi.cont_clock = 1;
  200. params->dsi.clk_lp_per_line_enable = 0;
  201. params->dsi.esd_check_enable = 0;
  202. params->dsi.customization_esd_check_enable = 0;
  203. params->dsi.lcm_esd_check_table[0].cmd = 0x53;
  204. params->dsi.lcm_esd_check_table[0].count = 1;
  205. params->dsi.lcm_esd_check_table[0].para_list[0] = 0x24;
  206. }
  207. static unsigned int lcm_compare_id(void)
  208. {
  209. int array[4];
  210. char buffer[3];
  211. char id0 = 0;
  212. char id1 = 0;
  213. char id2 = 0;
  214. SET_RESET_PIN(0);
  215. MDELAY(200);
  216. SET_RESET_PIN(1);
  217. MDELAY(200);
  218. array[0] = 0x00033700; /* read id return two byte,version and id */
  219. dsi_set_cmdq(array, 1, 1);
  220. read_reg_v2(0xDA, buffer, 1);
  221. array[0] = 0x00033700; /* read id return two byte,version and id */
  222. dsi_set_cmdq(array, 1, 1);
  223. read_reg_v2(0xDB, buffer + 1, 1);
  224. array[0] = 0x00033700; /* read id return two byte,version and id */
  225. dsi_set_cmdq(array, 1, 1);
  226. read_reg_v2(0xDC, buffer + 2, 1);
  227. id0 = buffer[0]; /* should be 0x00 */
  228. id1 = buffer[1]; /* should be 0xaa */
  229. id2 = buffer[2]; /* should be 0x55 */
  230. #ifdef BUILD_LK
  231. dprintf(0, "%s, id0 = 0x%08x\n", __func__, id0); /* should be 0x00 */
  232. dprintf(0, "%s, id1 = 0x%08x\n", __func__, id1); /* should be 0xaa */
  233. dprintf(0, "%s, id2 = 0x%08x\n", __func__, id2); /* should be 0x55 */
  234. #endif
  235. if ((id0 == 0x83) && (id1 == 0x89) && (id2 == 0x0C)) {
  236. dprintf(0, "[LK] Compare HX8389C LCM ID Success: 0x%x, 0x%x, 0x%x\n", id0, id1, id2);
  237. return 1;
  238. } else {
  239. dprintf(0, "[LK] Compare HX8389C LCM ID Failed: 0x%x, 0x%x, 0x%x\n", id0, id1, id2);
  240. return 0;
  241. }
  242. }
  243. static void lcm_init(void)
  244. {
  245. SET_RESET_PIN(1);
  246. SET_RESET_PIN(0);
  247. MDELAY(10);
  248. SET_RESET_PIN(1);
  249. MDELAY(20);
  250. push_table(lcm_initialization_setting,
  251. sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
  252. }
  253. static void lcm_suspend(void)
  254. {
  255. push_table(lcm_deep_sleep_mode_in_setting,
  256. sizeof(lcm_deep_sleep_mode_in_setting) / sizeof(struct LCM_setting_table), 1);
  257. }
  258. static void lcm_resume(void)
  259. {
  260. lcm_init();
  261. }
  262. static void lcm_update(unsigned int x, unsigned int y,
  263. unsigned int width, unsigned int height)
  264. {
  265. unsigned int x0 = x;
  266. unsigned int y0 = y;
  267. unsigned int x1 = x0 + width - 1;
  268. unsigned int y1 = y0 + height - 1;
  269. unsigned char x0_MSB = ((x0>>8)&0xFF);
  270. unsigned char x0_LSB = (x0&0xFF);
  271. unsigned char x1_MSB = ((x1>>8)&0xFF);
  272. unsigned char x1_LSB = (x1&0xFF);
  273. unsigned char y0_MSB = ((y0>>8)&0xFF);
  274. unsigned char y0_LSB = (y0&0xFF);
  275. unsigned char y1_MSB = ((y1>>8)&0xFF);
  276. unsigned char y1_LSB = (y1&0xFF);
  277. unsigned int data_array[16];
  278. data_array[0]= 0x00053902;
  279. data_array[1]= (x1_MSB<<24)|(x0_LSB<<16)|(x0_MSB<<8)|0x2a;
  280. data_array[2]= (x1_LSB);
  281. data_array[3]= 0x00053902;
  282. data_array[4]= (y1_MSB<<24)|(y0_LSB<<16)|(y0_MSB<<8)|0x2b;
  283. data_array[5]= (y1_LSB);
  284. data_array[6]= 0x002c3909;
  285. dsi_set_cmdq(&data_array, 7, 0);
  286. }
  287. static void lcm_setbacklight(unsigned int level)
  288. {
  289. unsigned int default_level = 145;
  290. unsigned int mapped_level = 0;
  291. //for LGE backlight IC mapping table
  292. if (level > 255)
  293. level = 255;
  294. if (level >0)
  295. mapped_level = default_level+(level)*(255-default_level)/(255);
  296. else
  297. mapped_level=0;
  298. // Refresh value of backlight level.
  299. lcm_backlight_level_setting[0].para_list[0] = mapped_level;
  300. push_table(lcm_backlight_level_setting, sizeof(lcm_backlight_level_setting) / sizeof(struct LCM_setting_table), 1);
  301. }
  302. static void lcm_setpwm(unsigned int divider)
  303. {
  304. // TBD
  305. }
  306. static unsigned int lcm_getpwm(unsigned int divider)
  307. {
  308. // ref freq = 15MHz, B0h setting 0x80, so 80.6% * freq is pwm_clk;
  309. // pwm_clk / 255 / 2(lcm_setpwm() 6th params) = pwm_duration = 23706
  310. unsigned int pwm_clk = 23706 / (1<<divider);
  311. return pwm_clk;
  312. }
  313. LCM_DRIVER hx8389c_dsi_vdo_lcm_drv = {
  314. .name = "hx8389c_dsi_vdo",
  315. .set_util_funcs = lcm_set_util_funcs,
  316. .compare_id = lcm_compare_id,
  317. .get_params = lcm_get_params,
  318. .init = lcm_init,
  319. .suspend = lcm_suspend,
  320. .resume = lcm_resume,
  321. };