hx8392a_dsi_cmd.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. * The following software/firmware and/or related documentation ("MediaTek Software")
  32. * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
  33. * applicable license agreements with MediaTek Inc.
  34. */
  35. #include <string.h>
  36. #include "lcm_drv.h"
  37. /* --------------------------------------------------------------------------- */
  38. /* Local Constants */
  39. /* --------------------------------------------------------------------------- */
  40. #define FRAME_WIDTH (720)
  41. #define FRAME_HEIGHT (1280)
  42. #define REGFLAG_DELAY 0xFE
  43. #define REGFLAG_END_OF_TABLE 0xFF /* END OF REGISTERS MARKER */
  44. #define LCM_DSI_CMD_MODE 1
  45. /* --------------------------------------------------------------------------- */
  46. /* Local Variables */
  47. /* --------------------------------------------------------------------------- */
  48. static LCM_UTIL_FUNCS lcm_util = { 0 };
  49. #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
  50. #define UDELAY(n) (lcm_util.udelay(n))
  51. #define MDELAY(n) (lcm_util.mdelay(n))
  52. /* --------------------------------------------------------------------------- */
  53. /* Local Functions */
  54. /* --------------------------------------------------------------------------- */
  55. #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
  56. #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
  57. #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
  58. #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
  59. #define read_reg lcm_util.dsi_read_reg()
  60. #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
  61. struct LCM_setting_table {
  62. unsigned cmd;
  63. unsigned char count;
  64. unsigned char para_list[64];
  65. };
  66. static struct LCM_setting_table lcm_initialization_setting[] = {
  67. /*
  68. Note :
  69. Data ID will depends on the following rule.
  70. count of parameters > 1 => Data ID = 0x39
  71. count of parameters = 1 => Data ID = 0x15
  72. count of parameters = 0 => Data ID = 0x05
  73. Structure Format :
  74. {DCS command, count of parameters, {parameter list}}
  75. {REGFLAG_DELAY, milliseconds of time, {}},
  76. ...
  77. Setting ending by predefined flag
  78. {REGFLAG_END_OF_TABLE, 0x00, {}}
  79. */
  80. /* sleep out */
  81. {0x11, 0, {} },
  82. {REGFLAG_DELAY, 120, {} },
  83. /* SET PASSWORD */
  84. {0xB9, 3, {0xFF, 0x83, 0x92} },
  85. {REGFLAG_DELAY, 10, {} },
  86. /* Set internal oscillator */
  87. {0xB0, 2, {0x01, 0x08} },
  88. /* set mipi 4 lane */
  89. {
  90. 0xBA, 17, {
  91. 0x13, 0x83, 0x00, 0xD6,
  92. 0xC5, 0x10, 0x09, 0xFF,
  93. 0x0F, 0x27, 0x03, 0x21,
  94. 0x27, 0x25, 0x20, 0x00,
  95. 0x10
  96. }
  97. },
  98. /* SET POWER */
  99. {
  100. 0xB1, 13, {
  101. 0x7C, 0x00, 0x43, 0xBB,
  102. 0x00, 0x1A, 0x1A, 0x2F,
  103. 0x36, 0x3F, 0x3F, 0x42,
  104. 0x7A
  105. }
  106. },
  107. /* SET DISPLAY RELATED REGISTER */
  108. {
  109. 0xB2, 12, {
  110. 0x08, 0xC8, 0x06, 0x18,
  111. 0x04, 0x84, 0x00, 0xFF,
  112. 0x06, 0x06, 0x04, 0x20
  113. }
  114. },
  115. /* SET CYC */
  116. {
  117. 0xB4, 23, {
  118. 0x00, 0x00, 0x05, 0x0A,
  119. 0x8F, 0x06, 0x0A, 0x95,
  120. 0x01, 0x07, 0x06, 0x0C,
  121. 0x02, 0x08, 0x08, 0x21,
  122. 0x04, 0x02, 0x08, 0x01,
  123. 0x04, 0x1A, 0x95
  124. }
  125. },
  126. /* set TE on */
  127. {0x35, 1, {0x00} },
  128. {0xBF, 4, {0x05, 0x60, 0x02, 0x00} },
  129. /* VCOM//64 */
  130. {0xB6, 1, {0x6A} },
  131. /* SET RGB OR BGR */
  132. {0x36, 1, {0x08} },
  133. /* SET RGB OR BGR */
  134. {0xC0, 2, {0x03, 0x94} },
  135. /* SET DSI COMMAND MODE */
  136. {0xC2, 1, {0x08} },
  137. /* SET DSI COMMAND MODE */
  138. {0xC6, 4, {0x35, 0x00, 0x20, 0x04} },
  139. /* SET PANEL */
  140. {0xCC, 1, {0x09} },
  141. {0xD4, 1, {0x00} },
  142. {
  143. 0xD5, 23, {
  144. 0x00, 0x01, 0x04, 0x00,
  145. 0x01, 0x67, 0x89, 0xAB,
  146. 0x45, 0xCC, 0xCC, 0xCC,
  147. 0x00, 0x10, 0x54, 0xBA,
  148. 0x98, 0x76, 0xCC, 0xCC,
  149. 0xCC, 0x00, 0x00
  150. }
  151. },
  152. {
  153. 0xD8, 23, {
  154. 0x00, 0x00, 0x05, 0x00,
  155. 0x9A, 0x00, 0x02, 0x95,
  156. 0x01, 0x07, 0x06, 0x00,
  157. 0x08, 0x08, 0x00, 0x1D,
  158. 0x08, 0x08, 0x08, 0x00,
  159. 0x00, 0x00, 0x77
  160. }
  161. },
  162. {
  163. 0xE0, 34, {
  164. 0x00, 0x12, 0x19, 0x33,
  165. 0x36, 0x3F, 0x28, 0x47,
  166. 0x06, 0x0C, 0x0E, 0x12,
  167. 0x14, 0x12, 0x14, 0x12,
  168. 0x1A, 0x00, 0x12, 0x19,
  169. 0x33, 0x36, 0x3F, 0x28,
  170. 0x47, 0x06, 0x0C, 0x0E,
  171. 0x12, 0x14, 0x12, 0x14,
  172. 0x12, 0x1A
  173. }
  174. },
  175. {
  176. 0xE1, 34, {
  177. 0x00, 0x12, 0x19, 0x33,
  178. 0x36, 0x3F, 0x28, 0x47,
  179. 0x06, 0x0C, 0x0E, 0x12,
  180. 0x14, 0x12, 0x14, 0x12,
  181. 0x1A, 0x00, 0x12, 0x19,
  182. 0x33, 0x36, 0x3F, 0x28,
  183. 0x47, 0x06, 0x0C, 0x0E,
  184. 0x12, 0x14, 0x12, 0x14,
  185. 0x12, 0x1A
  186. }
  187. },
  188. {
  189. 0xE2, 34, {
  190. 0x00, 0x12, 0x19, 0x33,
  191. 0x36, 0x3F, 0x28, 0x47,
  192. 0x06, 0x0C, 0x0E, 0x12,
  193. 0x14, 0x12, 0x14, 0x12,
  194. 0x1A, 0x00, 0x12, 0x19,
  195. 0x33, 0x36, 0x3F, 0x28,
  196. 0x47, 0x06, 0x0C, 0x0E,
  197. 0x12, 0x14, 0x12, 0x14,
  198. 0x12, 0x1A
  199. }
  200. },
  201. /* SET PIXEL FORMAT */
  202. {0x3A, 1, {0x77} },
  203. /* sleep out */
  204. {0x29, 0, {} },
  205. };
  206. static struct LCM_setting_table lcm_deep_sleep_mode_in_setting[] = {
  207. /* Sleep Mode On */
  208. {0x10, 0, {} },
  209. {REGFLAG_DELAY, 120, {} },
  210. {REGFLAG_END_OF_TABLE, 0x00, {} }
  211. };
  212. static struct LCM_setting_table lcm_backlight_level_setting[] = {
  213. {0x51, 1, {0xFF} },
  214. {REGFLAG_END_OF_TABLE, 0x00, {} }
  215. };
  216. static void push_table(struct LCM_setting_table *table, unsigned int count,
  217. unsigned char force_update)
  218. {
  219. unsigned int i;
  220. for (i = 0; i < count; i++) {
  221. unsigned cmd;
  222. cmd = table[i].cmd;
  223. switch (cmd) {
  224. case REGFLAG_DELAY:
  225. MDELAY(table[i].count);
  226. break;
  227. case REGFLAG_END_OF_TABLE:
  228. break;
  229. default:
  230. dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
  231. }
  232. }
  233. }
  234. /* --------------------------------------------------------------------------- */
  235. /* LCM Driver Implementations */
  236. /* --------------------------------------------------------------------------- */
  237. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  238. {
  239. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  240. }
  241. static void lcm_get_params(LCM_PARAMS *params)
  242. {
  243. memset(params, 0, sizeof(LCM_PARAMS));
  244. params->type = LCM_TYPE_DSI;
  245. params->width = FRAME_WIDTH;
  246. params->height = FRAME_HEIGHT;
  247. /* enable tearing-free */
  248. params->dbi.te_mode = LCM_DBI_TE_MODE_VSYNC_ONLY;
  249. params->dbi.te_edge_polarity = LCM_POLARITY_RISING;
  250. #if (LCM_DSI_CMD_MODE)
  251. params->dsi.mode = CMD_MODE;
  252. params->dsi.switch_mode = SYNC_PULSE_VDO_MODE;
  253. #else
  254. params->dsi.mode = SYNC_PULSE_VDO_MODE;
  255. #endif
  256. /* DSI */
  257. /* Command mode setting */
  258. params->dsi.LANE_NUM = LCM_FOUR_LANE;
  259. /* The following defined the fomat for data coming from LCD engine. */
  260. params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
  261. params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
  262. params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
  263. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  264. /* Highly depends on LCD driver capability. */
  265. /* Not support in MT6573 */
  266. params->dsi.packet_size = 256;
  267. params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;
  268. #ifndef CONFIG_FPGA_EARLY_PORTING
  269. #if (LCM_DSI_CMD_MODE)
  270. params->dsi.PLL_CLOCK = 200; /* this value must be in MTK suggested table */
  271. #else
  272. params->dsi.PLL_CLOCK = 200; /* this value must be in MTK suggested table */
  273. #endif
  274. #else
  275. params->dsi.pll_div1 = 0;
  276. params->dsi.pll_div2 = 0;
  277. params->dsi.fbk_div = 0x1;
  278. #endif
  279. params->dsi.clk_lp_per_line_enable = 0;
  280. params->dsi.esd_check_enable = 0;
  281. params->dsi.customization_esd_check_enable = 0;
  282. params->dsi.lcm_esd_check_table[0].cmd = 0x53;
  283. params->dsi.lcm_esd_check_table[0].count = 1;
  284. params->dsi.lcm_esd_check_table[0].para_list[0] = 0x24;
  285. }
  286. static void lcm_init(void)
  287. {
  288. SET_RESET_PIN(1);
  289. SET_RESET_PIN(0);
  290. MDELAY(10);
  291. SET_RESET_PIN(1);
  292. MDELAY(20);
  293. push_table(lcm_initialization_setting,
  294. sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table),
  295. 1);
  296. }
  297. static void lcm_suspend(void)
  298. {
  299. push_table(lcm_deep_sleep_mode_in_setting,
  300. sizeof(lcm_deep_sleep_mode_in_setting) / sizeof(struct LCM_setting_table), 1);
  301. }
  302. static void lcm_resume(void)
  303. {
  304. MDELAY(10);
  305. lcm_init();
  306. }
  307. static void lcm_update(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
  308. {
  309. unsigned int x0 = x;
  310. unsigned int y0 = y;
  311. unsigned int x1 = x0 + width - 1;
  312. unsigned int y1 = y0 + height - 1;
  313. unsigned char x0_MSB = ((x0 >> 8) & 0xFF);
  314. unsigned char x0_LSB = (x0 & 0xFF);
  315. unsigned char x1_MSB = ((x1 >> 8) & 0xFF);
  316. unsigned char x1_LSB = (x1 & 0xFF);
  317. unsigned char y0_MSB = ((y0 >> 8) & 0xFF);
  318. unsigned char y0_LSB = (y0 & 0xFF);
  319. unsigned char y1_MSB = ((y1 >> 8) & 0xFF);
  320. unsigned char y1_LSB = (y1 & 0xFF);
  321. unsigned int data_array[16];
  322. data_array[0] = 0x00053902;
  323. data_array[1] = (x1_MSB << 24) | (x0_LSB << 16) | (x0_MSB << 8) | 0x2a;
  324. data_array[2] = (x1_LSB);
  325. data_array[3] = 0x00053902;
  326. data_array[4] = (y1_MSB << 24) | (y0_LSB << 16) | (y0_MSB << 8) | 0x2b;
  327. data_array[5] = (y1_LSB);
  328. data_array[6] = 0x002c3909;
  329. dsi_set_cmdq(data_array, 7, 0);
  330. }
  331. static void lcm_setbacklight(unsigned int level)
  332. {
  333. unsigned int default_level = 145;
  334. unsigned int mapped_level = 0;
  335. /* for LGE backlight IC mapping table */
  336. if (level > 255)
  337. level = 255;
  338. if (level > 0)
  339. mapped_level = default_level + (level) * (255 - default_level) / (255);
  340. else
  341. mapped_level = 0;
  342. /* Refresh value of backlight level. */
  343. lcm_backlight_level_setting[0].para_list[0] = mapped_level;
  344. push_table(lcm_backlight_level_setting,
  345. sizeof(lcm_backlight_level_setting) / sizeof(struct LCM_setting_table), 1);
  346. }
  347. static void lcm_setpwm(unsigned int divider)
  348. {
  349. /* TBD */
  350. }
  351. static unsigned int lcm_getpwm(unsigned int divider)
  352. {
  353. /* ref freq = 15MHz, B0h setting 0x80, so 80.6% * freq is pwm_clk; */
  354. /* pwm_clk / 255 / 2(lcm_setpwm() 6th params) = pwm_duration = 23706 */
  355. unsigned int pwm_clk = 23706 / (1 << divider);
  356. return pwm_clk;
  357. }
  358. LCM_DRIVER hx8392a_dsi_cmd_lcm_drv = {
  359. .name = "hx8392a_dsi_cmd",
  360. .set_util_funcs = lcm_set_util_funcs,
  361. .get_params = lcm_get_params,
  362. .init = lcm_init,
  363. .suspend = lcm_suspend,
  364. .resume = lcm_resume,
  365. #if (LCM_DSI_CMD_MODE)
  366. .set_backlight = lcm_setbacklight,
  367. /* .set_pwm = lcm_setpwm, */
  368. /* .get_pwm = lcm_getpwm, */
  369. .update = lcm_update
  370. #endif
  371. };