hx8392a_dsi_cmd_fwvgap.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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 (480)
  40. #define FRAME_HEIGHT (960)
  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 4 lane
  87. {
  88. 0xBA, 17, {
  89. 0x11, 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. {0xB7, 3, {0x00, 0x00, 0x30}},
  127. {0xBF, 4, {0x05, 0x60, 0x02, 0x00}},
  128. // VCOM//64
  129. {0xB6, 1, {0x6A}},
  130. //SET RGB OR BGR
  131. {0x36, 1, {0x08}},
  132. //SET RGB OR BGR
  133. {0xC0, 2, {0x03, 0x94}},
  134. //SET DSI COMMAND MODE
  135. {0xC2, 1, {0x08}},
  136. //SET DSI COMMAND MODE
  137. {0xC6, 4, {0x35, 0x00, 0x20, 0x04}},
  138. //SET PANEL
  139. {0xCC, 1, {0x09}},
  140. {0xD4, 1, {0x00}},
  141. {
  142. 0xD5, 23, {
  143. 0x00, 0x01, 0x04, 0x00,
  144. 0x01, 0x67, 0x89, 0xAB,
  145. 0x45, 0xCC, 0xCC, 0xCC,
  146. 0x00, 0x10, 0x54, 0xBA,
  147. 0x98, 0x76, 0xCC, 0xCC,
  148. 0xCC, 0x00, 0x00
  149. }
  150. },
  151. {
  152. 0xD8, 23, {
  153. 0x00, 0x00, 0x05, 0x00,
  154. 0x9A, 0x00, 0x02, 0x95,
  155. 0x01, 0x07, 0x06, 0x00,
  156. 0x08, 0x08, 0x00, 0x1D,
  157. 0x08, 0x08, 0x08, 0x00,
  158. 0x00, 0x00, 0x77
  159. }
  160. },
  161. {
  162. 0xE0, 34, {
  163. 0x00, 0x12, 0x19, 0x33,
  164. 0x36, 0x3F, 0x28, 0x47,
  165. 0x06, 0x0C, 0x0E, 0x12,
  166. 0x14, 0x12, 0x14, 0x12,
  167. 0x1A, 0x00, 0x12, 0x19,
  168. 0x33, 0x36, 0x3F, 0x28,
  169. 0x47, 0x06, 0x0C, 0x0E,
  170. 0x12, 0x14, 0x12, 0x14,
  171. 0x12, 0x1A
  172. }
  173. },
  174. {
  175. 0xE1, 34, {
  176. 0x00, 0x12, 0x19, 0x33,
  177. 0x36, 0x3F, 0x28, 0x47,
  178. 0x06, 0x0C, 0x0E, 0x12,
  179. 0x14, 0x12, 0x14, 0x12,
  180. 0x1A, 0x00, 0x12, 0x19,
  181. 0x33, 0x36, 0x3F, 0x28,
  182. 0x47, 0x06, 0x0C, 0x0E,
  183. 0x12, 0x14, 0x12, 0x14,
  184. 0x12, 0x1A
  185. }
  186. },
  187. {
  188. 0xE2, 34, {
  189. 0x00, 0x12, 0x19, 0x33,
  190. 0x36, 0x3F, 0x28, 0x47,
  191. 0x06, 0x0C, 0x0E, 0x12,
  192. 0x14, 0x12, 0x14, 0x12,
  193. 0x1A, 0x00, 0x12, 0x19,
  194. 0x33, 0x36, 0x3F, 0x28,
  195. 0x47, 0x06, 0x0C, 0x0E,
  196. 0x12, 0x14, 0x12, 0x14,
  197. 0x12, 0x1A
  198. }
  199. },
  200. //SET PIXEL FORMAT
  201. {0x3A, 1, {0x77}},
  202. //sleep out
  203. {0x29, 0, {}},
  204. };
  205. static struct LCM_setting_table lcm_set_window[] = {
  206. {0x2A, 4, {0x00, 0x00, (FRAME_WIDTH>>8), (FRAME_WIDTH&0xFF)}},
  207. {0x2B, 4, {0x00, 0x00, (FRAME_HEIGHT>>8), (FRAME_HEIGHT&0xFF)}},
  208. {REGFLAG_END_OF_TABLE, 0x00, {}}
  209. };
  210. static struct LCM_setting_table lcm_sleep_out_setting[] = {
  211. // Sleep Out
  212. {0x11, 0, {}},
  213. {REGFLAG_DELAY, 120, {}},
  214. // Display ON
  215. {0x29, 0, {}},
  216. {REGFLAG_END_OF_TABLE, 0x00, {}}
  217. };
  218. static struct LCM_setting_table lcm_deep_sleep_mode_in_setting[] = {
  219. // Sleep Mode On
  220. {0x10, 0, {}},
  221. {REGFLAG_DELAY, 120, {}},
  222. {REGFLAG_END_OF_TABLE, 0x00, {}}
  223. };
  224. static struct LCM_setting_table lcm_backlight_level_setting[] = {
  225. {0x51, 1, {0xFF}},
  226. {REGFLAG_END_OF_TABLE, 0x00, {}}
  227. };
  228. static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
  229. {
  230. unsigned int i;
  231. for (i = 0; i < count; i++) {
  232. unsigned cmd;
  233. cmd = table[i].cmd;
  234. switch (cmd) {
  235. case REGFLAG_DELAY :
  236. MDELAY(table[i].count);
  237. break;
  238. case REGFLAG_END_OF_TABLE :
  239. break;
  240. default:
  241. dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
  242. }
  243. }
  244. }
  245. // ---------------------------------------------------------------------------
  246. // LCM Driver Implementations
  247. // ---------------------------------------------------------------------------
  248. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  249. {
  250. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  251. }
  252. static void lcm_get_params(LCM_PARAMS *params)
  253. {
  254. memset(params, 0, sizeof(LCM_PARAMS));
  255. params->type = LCM_TYPE_DSI;
  256. params->width = FRAME_WIDTH;
  257. params->height = FRAME_HEIGHT;
  258. // enable tearing-free
  259. params->dbi.te_mode = LCM_DBI_TE_MODE_VSYNC_ONLY;
  260. params->dbi.te_edge_polarity = LCM_POLARITY_RISING;
  261. #if (LCM_DSI_CMD_MODE)
  262. params->dsi.mode = CMD_MODE;
  263. params->dsi.switch_mode = SYNC_PULSE_VDO_MODE;
  264. #else
  265. params->dsi.mode = SYNC_PULSE_VDO_MODE;
  266. #endif
  267. // DSI
  268. /* Command mode setting */
  269. params->dsi.LANE_NUM = LCM_TWO_LANE;
  270. //The following defined the fomat for data coming from LCD engine.
  271. params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
  272. params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
  273. params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
  274. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  275. // Highly depends on LCD driver capability.
  276. // Not support in MT6573
  277. params->dsi.packet_size=256;
  278. params->dsi.PS=LCM_PACKED_PS_24BIT_RGB888;
  279. #ifndef CONFIG_FPGA_EARLY_PORTING
  280. #if (LCM_DSI_CMD_MODE)
  281. params->dsi.PLL_CLOCK = 180; //this value must be in MTK suggested table
  282. #else
  283. params->dsi.PLL_CLOCK = 180; //this value must be in MTK suggested table
  284. #endif
  285. #else
  286. params->dsi.pll_div1 = 0;
  287. params->dsi.pll_div2 = 0;
  288. params->dsi.fbk_div = 0x1;
  289. #endif
  290. params->dsi.cont_clock=1;
  291. params->dsi.clk_lp_per_line_enable = 0;
  292. params->dsi.esd_check_enable = 1;
  293. params->dsi.customization_esd_check_enable = 0;
  294. params->dsi.lcm_esd_check_table[0].cmd = 0x53;
  295. params->dsi.lcm_esd_check_table[0].count = 1;
  296. params->dsi.lcm_esd_check_table[0].para_list[0] = 0x24;
  297. }
  298. static void lcm_init(void)
  299. {
  300. SET_RESET_PIN(1);
  301. SET_RESET_PIN(0);
  302. MDELAY(10);
  303. SET_RESET_PIN(1);
  304. MDELAY(20);
  305. push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
  306. }
  307. static void lcm_suspend(void)
  308. {
  309. push_table(lcm_deep_sleep_mode_in_setting, sizeof(lcm_deep_sleep_mode_in_setting) / sizeof(struct LCM_setting_table), 1);
  310. }
  311. static void lcm_resume(void)
  312. {
  313. MDELAY(10);
  314. lcm_init();
  315. MDELAY(10);
  316. }
  317. static void lcm_update(unsigned int x, unsigned int y,
  318. unsigned int width, unsigned int height)
  319. {
  320. unsigned int x0 = x;
  321. unsigned int y0 = y;
  322. unsigned int x1 = x0 + width - 1;
  323. unsigned int y1 = y0 + height - 1;
  324. unsigned char x0_MSB = ((x0>>8)&0xFF);
  325. unsigned char x0_LSB = (x0&0xFF);
  326. unsigned char x1_MSB = ((x1>>8)&0xFF);
  327. unsigned char x1_LSB = (x1&0xFF);
  328. unsigned char y0_MSB = ((y0>>8)&0xFF);
  329. unsigned char y0_LSB = (y0&0xFF);
  330. unsigned char y1_MSB = ((y1>>8)&0xFF);
  331. unsigned char y1_LSB = (y1&0xFF);
  332. unsigned int data_array[16];
  333. data_array[0]= 0x00053902;
  334. data_array[1]= (x1_MSB<<24)|(x0_LSB<<16)|(x0_MSB<<8)|0x2a;
  335. data_array[2]= (x1_LSB);
  336. data_array[3]= 0x00053902;
  337. data_array[4]= (y1_MSB<<24)|(y0_LSB<<16)|(y0_MSB<<8)|0x2b;
  338. data_array[5]= (y1_LSB);
  339. data_array[6]= 0x002c3909;
  340. dsi_set_cmdq(&data_array, 7, 0);
  341. }
  342. static void lcm_setbacklight(unsigned int level)
  343. {
  344. unsigned int default_level = 145;
  345. unsigned int mapped_level = 0;
  346. //for LGE backlight IC mapping table
  347. if (level > 255)
  348. level = 255;
  349. if (level >0)
  350. mapped_level = default_level+(level)*(255-default_level)/(255);
  351. else
  352. mapped_level=0;
  353. // Refresh value of backlight level.
  354. lcm_backlight_level_setting[0].para_list[0] = mapped_level;
  355. push_table(lcm_backlight_level_setting, sizeof(lcm_backlight_level_setting) / sizeof(struct LCM_setting_table), 1);
  356. }
  357. static void lcm_setpwm(unsigned int divider)
  358. {
  359. // TBD
  360. }
  361. static unsigned int lcm_getpwm(unsigned int divider)
  362. {
  363. // ref freq = 15MHz, B0h setting 0x80, so 80.6% * freq is pwm_clk;
  364. // pwm_clk / 255 / 2(lcm_setpwm() 6th params) = pwm_duration = 23706
  365. unsigned int pwm_clk = 23706 / (1<<divider);
  366. return pwm_clk;
  367. }
  368. LCM_DRIVER hx8392a_dsi_cmd_fwvgap_lcm_drv = {
  369. .name = "hx8392a_dsi_cmd_fwvgap",
  370. .set_util_funcs = lcm_set_util_funcs,
  371. .get_params = lcm_get_params,
  372. .init = lcm_init,
  373. .suspend = lcm_suspend,
  374. .resume = lcm_resume,
  375. #if (LCM_DSI_CMD_MODE)
  376. .set_backlight = lcm_setbacklight,
  377. //.set_pwm = lcm_setpwm,
  378. //.get_pwm = lcm_getpwm,
  379. .update = lcm_update
  380. #endif
  381. };