hx8392a_dsi_cmd_3lane.c 12 KB

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