s6d7aa0_wxga_dsi_vdo.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. #endif
  38. #include "lcm_drv.h"
  39. #ifdef BUILD_LK
  40. #include <platform/mt_gpio.h>
  41. #include <platform/mt_pmic.h>
  42. #elif defined(BUILD_UBOOT)
  43. #include <asm/arch/mt_gpio.h>
  44. #else
  45. #include <mach/mt_gpio.h>
  46. #include <linux/xlog.h>
  47. #include <mach/mt_pm_ldo.h>
  48. #endif
  49. #define FRAME_WIDTH (800)
  50. #define FRAME_HEIGHT (1280)
  51. #define REGFLAG_DELAY 0xFE
  52. #define REGFLAG_END_OF_TABLE 0xFF // END OF REGISTERS MARKER
  53. #define LCM_DSI_CMD_MODE 0
  54. #define LCM_ID 0x06
  55. //#define GPIO_LCD_RST_EN GPIO131
  56. #ifdef GPIO_LCM_PWR_EN
  57. #define GPIO_LCD_PWR_EN GPIO_LCM_PWR_EN
  58. #else
  59. #define GPIO_LCD_PWR_EN 0xFFFFFFFF
  60. #endif
  61. #ifdef GPIO_LCM_RST
  62. #define GPIO_LCD_RST GPIO_LCM_RST
  63. #else
  64. #define GPIO_LCD_RST 0xFFFFFFFF
  65. #endif
  66. #ifndef BUILD_LK
  67. static bool fgisFirst = TRUE;
  68. #endif
  69. static unsigned int lcm_esd_test = FALSE; ///only for ESD test
  70. // ---------------------------------------------------------------------------
  71. // Local Variables
  72. // ---------------------------------------------------------------------------
  73. static LCM_UTIL_FUNCS lcm_util = {0};
  74. #define SET_RESET_PIN(v) lcm_set_gpio_output(GPIO_LCD_RST, v) //(lcm_util.set_reset_pin((v)))
  75. #define UDELAY(n) (lcm_util.udelay(n))
  76. #define MDELAY(n) (lcm_util.mdelay(n))
  77. // ---------------------------------------------------------------------------
  78. // Local Functions
  79. // ---------------------------------------------------------------------------
  80. #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
  81. #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
  82. #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
  83. #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
  84. #define read_reg lcm_util.dsi_read_reg()
  85. #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
  86. static void lcm_init_register(void)
  87. {
  88. unsigned int data_array[16];
  89. #ifdef BUILD_LK
  90. printf("%s, LK \n", __func__);
  91. #else
  92. printk("%s, kernel", __func__);
  93. #endif
  94. //DSI_Continuous_HS();
  95. //DSI_clk_HS_mode(1);
  96. /* 0xF0, 0x5A, 0x5A */
  97. data_array[0] = 0x00033902;
  98. data_array[1] = 0x005A5AF0;
  99. dsi_set_cmdq(data_array, 2, 1);
  100. /* 0xF1, 0x5A, 0x5A */
  101. data_array[0] = 0x00033902;
  102. data_array[1] = 0x005A5AF1;
  103. dsi_set_cmdq(data_array, 2, 1);
  104. /* 0xFC, 0xA5, 0xA5 */
  105. data_array[0] = 0x00033902;
  106. data_array[1] = 0x00A5A5FC;
  107. dsi_set_cmdq(data_array, 2, 1);
  108. /* 0xD0, 0x00, 0x10 */
  109. data_array[0] = 0x00033902;
  110. data_array[1] = 0x001000D0;
  111. dsi_set_cmdq(data_array, 2, 1);
  112. /* 0x35. TE */
  113. data_array[0] = 0x00350500;
  114. dsi_set_cmdq(data_array, 1, 1);
  115. /*0xC3, 0x40, 0x00, 0x28*/
  116. data_array[0] = 0x00043902;
  117. data_array[1] = 0x280040C3;
  118. dsi_set_cmdq(data_array, 2, 1);
  119. MDELAY(20);
  120. /*0xF6, 0x63, 0x20, 0x86, 0x00, 0x00, 0x10*/
  121. data_array[0] = 0x00073902;
  122. data_array[1] = 0x862063F6;
  123. data_array[2] = 0x00100000;
  124. dsi_set_cmdq(data_array, 3, 1);
  125. /* MIPI Video on, no need care about it */
  126. /* 0x11. Sleep out */
  127. data_array[0] = 0x00110500;
  128. dsi_set_cmdq(data_array, 1, 1);
  129. MDELAY(50);
  130. /*0x36, 0x00*/
  131. data_array[0] = 0x00361500;
  132. dsi_set_cmdq(data_array, 1, 1);
  133. MDELAY(50);
  134. /* 0x29. Display on */
  135. data_array[0] = 0x00290500;
  136. dsi_set_cmdq(data_array, 1, 1);
  137. MDELAY(200);
  138. /* Backlight turn on, no need to control it */
  139. }
  140. static void lcm_set_gpio_output(unsigned int GPIO, unsigned int output)
  141. {
  142. mt_set_gpio_mode(GPIO, GPIO_MODE_00);
  143. mt_set_gpio_dir(GPIO, GPIO_DIR_OUT);
  144. mt_set_gpio_out(GPIO, (output>0)? GPIO_OUT_ONE: GPIO_OUT_ZERO);
  145. }
  146. static void lcd_poweron(unsigned char enabled)
  147. {
  148. if (enabled > 0)
  149. {
  150. #ifdef BUILD_LK
  151. printf("[LK/LCM] lcm_resume_power() enter\n");
  152. lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ONE);
  153. MDELAY(5);
  154. lcm_Enable_HW(1800);
  155. MDELAY(20);
  156. #else
  157. printk("[Kernel/LCM] lcm_resume_power() enter\n");
  158. lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ONE);
  159. MDELAY(5);
  160. hwPowerOn(MT6328_POWER_LDO_VCAMA, VOL_1800, "LCM");
  161. MDELAY(20);
  162. #endif
  163. }
  164. else
  165. {
  166. #ifdef BUILD_LK
  167. printf("[LK/LCM] lcm_suspend_power() enter\n");
  168. lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ZERO);
  169. MDELAY(20);
  170. lcm_Disable_HW();
  171. #else
  172. printk("[Kernel/LCM] lcm_suspend_power() enter\n");
  173. lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ZERO);
  174. MDELAY(20);
  175. if(fgisFirst == TRUE) {
  176. fgisFirst = FALSE;
  177. hwPowerOn(MT6328_POWER_LDO_VCAMA, VOL_1800, "LCM");
  178. }
  179. hwPowerDown(MT6328_POWER_LDO_VCAMA, "LCM");
  180. #endif
  181. }
  182. }
  183. static void lcd_reset(unsigned char enabled)
  184. {
  185. if (enabled > 0)
  186. {
  187. SET_RESET_PIN(1);
  188. }
  189. else
  190. {
  191. SET_RESET_PIN(0);
  192. }
  193. }
  194. // ---------------------------------------------------------------------------
  195. // LCM Driver Implementations
  196. // ---------------------------------------------------------------------------
  197. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  198. {
  199. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  200. }
  201. static void lcm_get_params(LCM_PARAMS *params)
  202. {
  203. memset(params, 0, sizeof(LCM_PARAMS));
  204. params->type = LCM_TYPE_DSI;
  205. params->width = FRAME_WIDTH;
  206. params->height = FRAME_HEIGHT;
  207. params->dsi.mode = SYNC_EVENT_VDO_MODE;
  208. // DSI
  209. /* Command mode setting */
  210. params->dsi.LANE_NUM = LCM_FOUR_LANE;
  211. //The following defined the fomat for data coming from LCD engine.
  212. params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
  213. params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
  214. params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
  215. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  216. // Highly depends on LCD driver capability.
  217. params->dsi.word_count=FRAME_WIDTH*3;
  218. params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;
  219. params->dsi.vertical_sync_active = 4;
  220. params->dsi.vertical_backporch = 4;
  221. params->dsi.vertical_frontporch = 8;
  222. params->dsi.vertical_active_line = FRAME_HEIGHT;
  223. params->dsi.horizontal_sync_active = 14;
  224. params->dsi.horizontal_backporch = 140;
  225. params->dsi.horizontal_frontporch = 16;
  226. params->dsi.horizontal_active_pixel = FRAME_WIDTH;
  227. params->dsi.PLL_CLOCK = 245;
  228. }
  229. static void lcm_init_power(void)
  230. {
  231. lcd_reset(0);
  232. /* Power supply(VDD=1.8V) */
  233. MDELAY(10);
  234. lcd_poweron(0);
  235. MDELAY(20);
  236. lcd_poweron(1);
  237. MDELAY(5);
  238. lcd_reset(1);
  239. MDELAY(20);
  240. lcd_reset(0);
  241. MDELAY(25);
  242. lcd_reset(1);
  243. MDELAY(10);
  244. }
  245. static void lcm_suspend_power(void)
  246. {
  247. lcd_reset(0);
  248. MDELAY(10);
  249. lcd_poweron(0);
  250. MDELAY(10);
  251. }
  252. static void lcm_resume_power(void)
  253. {
  254. MDELAY(20);
  255. lcm_init_power();
  256. }
  257. static void lcm_init(void)
  258. {
  259. MDELAY(20);
  260. lcm_init_register();
  261. MDELAY(20);
  262. }
  263. static void lcm_suspend(void)
  264. {
  265. unsigned int data_array[16];
  266. data_array[0] = 0x00280500; //display off
  267. dsi_set_cmdq(data_array, 1, 1);
  268. MDELAY(200);
  269. }
  270. static void lcm_resume(void)
  271. {
  272. lcm_init();
  273. }
  274. LCM_DRIVER s6d7aa0_wxga_dsi_vdo_lcm_drv =
  275. {
  276. .name = "s6d7aa0_wxga_dsi_vdo",
  277. .set_util_funcs = lcm_set_util_funcs,
  278. .get_params = lcm_get_params,
  279. .init = lcm_init,
  280. .init_power = lcm_init_power,
  281. .suspend = lcm_suspend,
  282. .suspend_power = lcm_suspend_power,
  283. .resume = lcm_resume,
  284. .resume_power = lcm_resume_power,
  285. };