cm_n070ice_dsi_vdo.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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. #ifndef BUILD_LK
  36. #include <linux/string.h>
  37. #else
  38. #include <string.h>
  39. #endif
  40. #include "lcm_drv.h"
  41. #ifdef BUILD_LK
  42. #include <platform/mt_gpio.h>
  43. #include <platform/mt_pmic.h>
  44. #elif defined(BUILD_UBOOT)
  45. #else
  46. #include <mach/mt_gpio.h>
  47. #include <mach/mt_pm_ldo.h>
  48. #endif
  49. // ---------------------------------------------------------------------------
  50. // Local Constants
  51. // ---------------------------------------------------------------------------
  52. #define FRAME_WIDTH (800)
  53. #define FRAME_HEIGHT (1280)
  54. #define LCM_ID_NT35590 (0x90)
  55. // TODO. This LCM ID is NT51012 not 35590.
  56. #define GPIO_LCD_RST_EN GPIO65
  57. #define GPIO_LCD_STB_EN GPIO66
  58. #define GPIO_LCD_LED_EN GPIO_LCM_LED_EN
  59. // ---------------------------------------------------------------------------
  60. // Local Variables
  61. // ---------------------------------------------------------------------------
  62. static LCM_UTIL_FUNCS lcm_util =
  63. {
  64. .set_reset_pin = NULL,
  65. .udelay = NULL,
  66. .mdelay = NULL,
  67. };
  68. #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
  69. #define UDELAY(n) (lcm_util.udelay(n))
  70. #define MDELAY(n) (lcm_util.mdelay(n))
  71. // ---------------------------------------------------------------------------
  72. // Local Functions
  73. // ---------------------------------------------------------------------------
  74. #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
  75. #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
  76. #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
  77. #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
  78. #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
  79. #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
  80. #define LCM_DSI_CMD_MODE 0
  81. static void init_lcm_registers(void)
  82. {
  83. unsigned int data_array[16];
  84. #ifdef BUILD_LK
  85. printf("%s, LK \n", __func__);
  86. #else
  87. printk("%s, kernel\n", __func__);
  88. #endif
  89. #if 1
  90. data_array[0] = 0x00011500; //software reset
  91. dsi_set_cmdq(data_array, 1, 1);
  92. MDELAY(20);
  93. data_array[0]=0x0bae1500;
  94. data_array[1]=0xeaee1500;
  95. data_array[2]=0x5fef1500;
  96. data_array[3]=0x68f21500;
  97. data_array[4]=0x00ee1500;
  98. data_array[5]=0x00ef1500;
  99. dsi_set_cmdq(data_array, 6, 1);
  100. #if 0
  101. data_array[0] = 0x7DB21500;
  102. dsi_set_cmdq(data_array, 1, 1);
  103. data_array[0] = 0x0BAE1500;
  104. dsi_set_cmdq(data_array, 1, 1);
  105. data_array[0] = 0x18B61500;
  106. dsi_set_cmdq(data_array, 1, 1);
  107. data_array[0] = 0xEAEE1500;
  108. dsi_set_cmdq(data_array, 1, 1);
  109. data_array[0] = 0x5FEF1500;
  110. dsi_set_cmdq(data_array, 1, 1);
  111. data_array[0] = 0x68F21500;
  112. dsi_set_cmdq(data_array, 1, 1);
  113. data_array[0] = 0x00EE1500;
  114. dsi_set_cmdq(data_array, 1, 1);
  115. data_array[0] = 0x00EF1500;
  116. dsi_set_cmdq(data_array, 1, 1);
  117. data_array[0] = 0x64D21500;
  118. dsi_set_cmdq(data_array, 1, 1);
  119. data_array[0] = 0x00101500; //sleep out
  120. dsi_set_cmdq(data_array, 1, 1);
  121. MDELAY(20);
  122. #endif
  123. //data_array[0] = 0xEFB11500;
  124. //dsi_set_cmdq(data_array, 1, 1);
  125. //MDELAY(1);
  126. //data_array[0] = 0x00290500; //display on
  127. //dsi_set_cmdq(data_array, 1, 1);
  128. #endif
  129. #if 0
  130. data_array[0] = 0x00010500; //software reset
  131. dsi_set_cmdq(data_array, 1, 1);
  132. MDELAY(20);
  133. data_array[0] = 0x00023902;
  134. data_array[1] = 0x00000BAE;
  135. dsi_set_cmdq(data_array, 2, 1);
  136. MDELAY(1);
  137. data_array[0] = 0x00023902;
  138. data_array[1] = 0x0000EAEE;
  139. dsi_set_cmdq(data_array, 2, 1);
  140. MDELAY(1);
  141. data_array[0] = 0x00023902;
  142. data_array[1] = 0x00005FEF;
  143. dsi_set_cmdq(data_array, 2, 1);
  144. MDELAY(1);
  145. data_array[0] = 0x00023902;
  146. data_array[1] = 0x000068F2;
  147. dsi_set_cmdq(data_array, 2, 1);
  148. MDELAY(1);
  149. data_array[0] = 0x00023902;
  150. data_array[1] = 0x000000EE;
  151. dsi_set_cmdq(data_array, 2, 1);
  152. MDELAY(1);
  153. data_array[0] = 0x00023902;
  154. data_array[1] = 0x000000EF;
  155. dsi_set_cmdq(data_array, 2, 1);
  156. MDELAY(1);
  157. data_array[0] = 0x00100500; //sleep out
  158. dsi_set_cmdq(data_array, 1, 1);
  159. MDELAY(20);
  160. data_array[0] = 0x00290500; //display on
  161. dsi_set_cmdq(data_array, 1, 1);
  162. #endif
  163. //MDELAY(5);
  164. }
  165. // ---------------------------------------------------------------------------
  166. // LCM Driver Implementations
  167. // ---------------------------------------------------------------------------
  168. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  169. {
  170. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  171. }
  172. static void lcm_get_params(LCM_PARAMS *params)
  173. {
  174. memset(params, 0, sizeof(LCM_PARAMS));
  175. params->type = LCM_TYPE_DSI;
  176. params->width = FRAME_WIDTH;
  177. params->height = FRAME_HEIGHT;
  178. params->physical_width = 94;
  179. params->physical_height = 150;
  180. #if 0
  181. // enable tearing-free
  182. params->dbi.te_mode = LCM_DBI_TE_MODE_VSYNC_ONLY;
  183. params->dbi.te_edge_polarity = LCM_POLARITY_RISING;
  184. #endif
  185. #if (LCM_DSI_CMD_MODE)
  186. params->dsi.mode = CMD_MODE;
  187. #else
  188. params->dsi.mode = SYNC_EVENT_VDO_MODE;
  189. #endif
  190. // DSI
  191. /* Command mode setting */
  192. //1 Three lane or Four lane
  193. params->dsi.LANE_NUM = LCM_FOUR_LANE;
  194. //The following defined the fomat for data coming from LCD engine.
  195. params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
  196. params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
  197. params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
  198. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  199. // Highly depends on LCD driver capability.
  200. // Not support in MT6573
  201. params->dsi.packet_size=256;
  202. // Video mode setting
  203. params->dsi.intermediat_buffer_num = 0;//because DSI/DPI HW design change, this parameters should be 0 when video mode in MT658X; or memory leakage
  204. params->dsi.PS=LCM_PACKED_PS_24BIT_RGB888;
  205. params->dsi.word_count=720*3;
  206. params->dsi.vertical_sync_active = 1;
  207. params->dsi.vertical_backporch = 10;
  208. params->dsi.vertical_frontporch = 10;
  209. params->dsi.vertical_active_line = FRAME_HEIGHT;
  210. params->dsi.horizontal_sync_active = 1;
  211. params->dsi.horizontal_backporch = 57;
  212. params->dsi.horizontal_frontporch = 32;
  213. params->dsi.horizontal_active_pixel = FRAME_WIDTH;
  214. // Bit rate calculation
  215. //1 Every lane speed
  216. //params->dsi.pll_div1=0; // div1=0,1,2,3;div1_real=1,2,4,4 ----0: 546Mbps 1:273Mbps
  217. //params->dsi.pll_div2=1; // div2=0,1,2,3;div1_real=1,2,4,4
  218. //params->dsi.fbk_div =31; // fref=26MHz, fvco=fref*(fbk_div+1)*2/(div1_real*div2_real)
  219. params->dsi.PLL_CLOCK =LCM_DSI_6589_PLL_CLOCK_201_5;
  220. params->dsi.CLK_ZERO = 47;
  221. params->dsi.HS_ZERO = 36;
  222. }
  223. static void lcm_init(void)
  224. {
  225. #ifdef BUILD_LK
  226. printf("%s, LK \n", __func__);
  227. #else
  228. printk("%s, kernel", __func__);
  229. #endif
  230. #ifdef BUILD_LK
  231. //printf("[LK/LCM] lcm_init() enter\n");
  232. //VGP6 3.3V
  233. pmic_config_interface(0x424, 0x1, 0x1, 15);
  234. pmic_config_interface(0x45a, 0x07, 0x07, 5);
  235. //vgp4 1.8V
  236. pmic_config_interface(0x420, 0x1, 0x1, 15);
  237. pmic_config_interface(0x43c, 0x03, 0x07, 5);
  238. mt_set_gpio_mode(GPIO_LCD_RST_EN, GPIO_MODE_00);
  239. mt_set_gpio_dir(GPIO_LCD_RST_EN, GPIO_DIR_OUT);
  240. mt_set_gpio_out(GPIO_LCD_RST_EN, GPIO_OUT_ONE);
  241. MDELAY(20);
  242. mt_set_gpio_mode(GPIO_LCD_STB_EN, GPIO_MODE_00);
  243. mt_set_gpio_dir(GPIO_LCD_STB_EN, GPIO_DIR_OUT);
  244. mt_set_gpio_out(GPIO_LCD_STB_EN, GPIO_OUT_ONE);
  245. MDELAY(20);
  246. /*MDELAY(50);
  247. SET_RESET_PIN(1);
  248. SET_RESET_PIN(0);
  249. MDELAY(1);
  250. SET_RESET_PIN(1);
  251. init_lcm_registers();*/
  252. #else
  253. hwPowerOn(MT65XX_POWER_LDO_VGP6, VOL_3300, "LCM");
  254. hwPowerOn(MT65XX_POWER_LDO_VGP4, VOL_1800, "LCM");
  255. #endif
  256. MDELAY(50);
  257. SET_RESET_PIN(1);
  258. SET_RESET_PIN(0);
  259. MDELAY(1);
  260. SET_RESET_PIN(1);
  261. init_lcm_registers();
  262. }
  263. static void lcm_suspend(void)
  264. {
  265. unsigned int data_array[16];
  266. #ifdef BUILD_LK
  267. printf("%s, LK \n", __func__);
  268. #else
  269. printk("%s, kernel", __func__);
  270. #endif
  271. #ifdef BUILD_LK
  272. //printf("[LK/LCM] lcm_resume() enter\n");
  273. //VGP6 3.3V
  274. pmic_config_interface(0x424, 0x0, 0x1, 15);
  275. pmic_config_interface(0x45a, 0x0, 0x07, 5);
  276. //vgp4 1.8V
  277. pmic_config_interface(0x420, 0x0, 0x1, 15);
  278. pmic_config_interface(0x43c, 0x0, 0x07, 5);
  279. #else
  280. hwPowerDown(MT65XX_POWER_LDO_VGP6, "LCM");//hwPowerOn(MT65XX_POWER_LDO_VGP6, VOL_3300, "LCM");
  281. hwPowerDown(MT65XX_POWER_LDO_VGP4, "LCM");
  282. #endif
  283. mt_set_gpio_mode(GPIO_LCD_RST_EN, GPIO_MODE_00);
  284. mt_set_gpio_dir(GPIO_LCD_RST_EN, GPIO_DIR_OUT);
  285. mt_set_gpio_out(GPIO_LCD_RST_EN, GPIO_OUT_ZERO);
  286. MDELAY(20);
  287. mt_set_gpio_mode(GPIO_LCD_STB_EN, GPIO_MODE_00);
  288. mt_set_gpio_dir(GPIO_LCD_STB_EN, GPIO_DIR_OUT);
  289. mt_set_gpio_out(GPIO_LCD_STB_EN, GPIO_OUT_ZERO);
  290. MDELAY(20);
  291. data_array[0]=0x00280500; // Display Off
  292. dsi_set_cmdq(data_array, 1, 1);
  293. MDELAY(20);
  294. data_array[0] = 0x00111500; // Sleep In
  295. dsi_set_cmdq(data_array, 1, 1);
  296. MDELAY(160);
  297. //SET_RESET_PIN(0);
  298. }
  299. static void lcm_resume(void)
  300. {
  301. unsigned int data_array[16];
  302. #ifdef BUILD_LK
  303. printf("%s, LK \n", __func__);
  304. #else
  305. printk("%s, kernel", __func__);
  306. #endif
  307. #ifdef BUILD_LK
  308. //printf("[LK/LCM] lcm_resume() enter\n");
  309. //VGP6 3.3V
  310. pmic_config_interface(0x424, 0x1, 0x1, 15);
  311. pmic_config_interface(0x45a, 0x07, 0x07, 5);
  312. //vgp4 1.8V
  313. pmic_config_interface(0x420, 0x1, 0x1, 15);
  314. pmic_config_interface(0x43c, 0x03, 0x07, 5);
  315. #else
  316. hwPowerOn(MT65XX_POWER_LDO_VGP6, VOL_3300, "LCM");
  317. hwPowerOn(MT65XX_POWER_LDO_VGP4, VOL_1800, "LCM");
  318. #endif
  319. mt_set_gpio_mode(GPIO_LCD_RST_EN, GPIO_MODE_00);
  320. mt_set_gpio_dir(GPIO_LCD_RST_EN, GPIO_DIR_OUT);
  321. mt_set_gpio_out(GPIO_LCD_RST_EN, GPIO_OUT_ONE);
  322. MDELAY(20);
  323. mt_set_gpio_mode(GPIO_LCD_STB_EN, GPIO_MODE_00);
  324. mt_set_gpio_dir(GPIO_LCD_STB_EN, GPIO_DIR_OUT);
  325. mt_set_gpio_out(GPIO_LCD_STB_EN, GPIO_OUT_ONE);
  326. MDELAY(20);
  327. //#endif
  328. //unsigned int data_array[16];
  329. //lcm_init();
  330. MDELAY(50);
  331. SET_RESET_PIN(1);
  332. SET_RESET_PIN(0);
  333. MDELAY(1);
  334. SET_RESET_PIN(1);
  335. init_lcm_registers();
  336. data_array[0] = 0x00101500; // Sleep Out
  337. dsi_set_cmdq(data_array, 1, 1);
  338. MDELAY(20);
  339. data_array[0] = 0x00290500; // Display On
  340. dsi_set_cmdq(data_array, 1, 1);
  341. }
  342. #if (LCM_DSI_CMD_MODE)
  343. static void lcm_update(unsigned int x, unsigned int y,
  344. unsigned int width, unsigned int height)
  345. {
  346. unsigned int x0 = x;
  347. unsigned int y0 = y;
  348. unsigned int x1 = x0 + width - 1;
  349. unsigned int y1 = y0 + height - 1;
  350. unsigned char x0_MSB = ((x0>>8)&0xFF);
  351. unsigned char x0_LSB = (x0&0xFF);
  352. unsigned char x1_MSB = ((x1>>8)&0xFF);
  353. unsigned char x1_LSB = (x1&0xFF);
  354. unsigned char y0_MSB = ((y0>>8)&0xFF);
  355. unsigned char y0_LSB = (y0&0xFF);
  356. unsigned char y1_MSB = ((y1>>8)&0xFF);
  357. unsigned char y1_LSB = (y1&0xFF);
  358. unsigned int data_array[16];
  359. data_array[0]= 0x00053902;
  360. data_array[1]= (x1_MSB<<24)|(x0_LSB<<16)|(x0_MSB<<8)|0x2a;
  361. data_array[2]= (x1_LSB);
  362. dsi_set_cmdq(data_array, 3, 1);
  363. data_array[0]= 0x00053902;
  364. data_array[1]= (y1_MSB<<24)|(y0_LSB<<16)|(y0_MSB<<8)|0x2b;
  365. data_array[2]= (y1_LSB);
  366. dsi_set_cmdq(data_array, 3, 1);
  367. data_array[0]= 0x00290508; //HW bug, so need send one HS packet
  368. dsi_set_cmdq(data_array, 1, 1);
  369. data_array[0]= 0x002c3909;
  370. dsi_set_cmdq(data_array, 1, 0);
  371. }
  372. #endif
  373. LCM_DRIVER cm_n070ice_dsi_vdo_lcm_drv =
  374. {
  375. .name = "cm_n070ice_dsi_vdo",
  376. .set_util_funcs = lcm_set_util_funcs,
  377. .get_params = lcm_get_params,
  378. .init = lcm_init,
  379. .suspend = lcm_suspend,
  380. .resume = lcm_resume,
  381. //.compare_id = lcm_compare_id,
  382. #if (LCM_DSI_CMD_MODE)
  383. .update = lcm_update,
  384. #endif
  385. };