CPT_CLAP070WP03XG_LVDS.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. #ifdef BUILD_LK
  39. #include <platform/mt_gpio.h>
  40. #include <platform/mt_pmic.h>
  41. #include <debug.h>
  42. #include <platform/upmu_common.h>
  43. #elif (defined BUILD_UBOOT)
  44. #include <asm/arch/mt6577_gpio.h>
  45. #else
  46. #include <mach/mt_gpio.h>
  47. #include <linux/xlog.h>
  48. #include <mach/mt_pm_ldo.h>
  49. #endif
  50. #include "lcm_drv.h"
  51. #include "mt8193_lvds.h"
  52. // ---------------------------------------------------------------------------
  53. // Local Constants
  54. // ---------------------------------------------------------------------------
  55. #if defined(MTK_ALPS_BOX_SUPPORT)
  56. /*for 8127 box hdmi main path */
  57. #define FRAME_WIDTH (1920)
  58. #define FRAME_HEIGHT (1080)
  59. #else
  60. #define FRAME_WIDTH (800)
  61. #define FRAME_HEIGHT (1280)
  62. #endif
  63. //#define GPIO_LCD_RST_EN GPIO90
  64. //#define GPIO_LCD_STB_EN GPIO89
  65. #ifdef GPIO_LCM_PWR
  66. #define GPIO_LCD_PWR GPIO_LCM_PWR
  67. #else
  68. #define GPIO_LCD_PWR 0xFFFFFFFF
  69. #endif
  70. #ifdef GPIO_LCM_PWR_EN
  71. #define GPIO_LCD_PWR_EN GPIO_LCM_PWR_EN
  72. #else
  73. #define GPIO_LCD_PWR_EN 0xFFFFFFFF
  74. #endif
  75. #ifdef GPIO_LCM_PWR2_EN
  76. #define GPIO_LCD_PWR2_EN GPIO_LCM_PWR2_EN
  77. #else
  78. #define GPIO_LCD_PWR2_EN 0xFFFFFFFF
  79. #endif
  80. #ifdef GPIO_LCM_RST
  81. #define GPIO_LCD_RST_EN GPIO_LCM_RST
  82. #else
  83. #define GPIO_LCD_RST_EN 0xFFFFFFFF
  84. #endif
  85. #ifdef GPIO_LCM_STB
  86. #define GPIO_LCD_STB_EN GPIO_LCM_STB
  87. #else
  88. #define GPIO_LCD_STB_EN 0xFFFFFFFF
  89. #endif
  90. #ifdef GPIO_LCM_LVL_SHIFT_EN
  91. #define GPIO_SHIFT_EN GPIO_LCM_LVL_SHIFT_EN
  92. #else
  93. #define GPIO_SHIFT_EN 0xFFFFFFFF
  94. #endif
  95. #ifdef GPIO_LCM_BL_EN
  96. #define GPIO_LCD_BL_EN GPIO_LCM_BL_EN
  97. #else
  98. #define GPIO_LCD_BL_EN 0xFFFFFFFF
  99. #endif
  100. #ifdef GPIO_LCM_BRIDGE_EN
  101. #define GPIO_LCD_BRIDGE_EN GPIO_LCM_BRIDGE_EN
  102. #else
  103. #define GPIO_LCD_BRIDGE_EN 0xFFFFFFFF
  104. #endif
  105. #define HSYNC_PULSE_WIDTH 16
  106. #define HSYNC_BACK_PORCH 16
  107. #define HSYNC_FRONT_PORCH 32
  108. #define VSYNC_PULSE_WIDTH 2
  109. #define VSYNC_BACK_PORCH 2
  110. #define VSYNC_FRONT_PORCH 4
  111. // ---------------------------------------------------------------------------
  112. // Local Variables
  113. // ---------------------------------------------------------------------------
  114. static LCM_UTIL_FUNCS lcm_util = {0};
  115. #define SET_RESET_PIN(v) (mt_set_reset_pin((v)))
  116. #define UDELAY(n)
  117. #define MDELAY(n)
  118. // ---------------------------------------------------------------------------
  119. // Local Functions
  120. // ---------------------------------------------------------------------------
  121. static __inline void send_ctrl_cmd(unsigned int cmd)
  122. {
  123. }
  124. static __inline void send_data_cmd(unsigned int data)
  125. {
  126. }
  127. static __inline void set_lcm_register(unsigned int regIndex,
  128. unsigned int regData)
  129. {
  130. }
  131. static void lcm_set_gpio_output(unsigned int GPIO, unsigned int output)
  132. {
  133. if(GPIO == 0xFFFFFFFF)
  134. {
  135. #ifdef BUILD_LK
  136. printf("[LK/LCM] GPIO_LCD_PWR = 0x%x \n",GPIO_LCD_PWR);
  137. printf("[LK/LCM] GPIO_LCD_PWR_EN = 0x%x\n",GPIO_LCD_PWR_EN);
  138. printf("[LK/LCM] GPIO_LCD_PWR2_EN = 0x%x \n",GPIO_LCD_PWR2_EN);
  139. printf("[LK/LCM] GPIO_LCD_RST_EN = 0x%x \n",GPIO_LCD_RST_EN);
  140. printf("[LK/LCM] GPIO_LCD_STB_EN = 0x%x\n",GPIO_LCD_STB_EN);
  141. printf("[LK/LCM] GPIO_SHIFT_EN = 0x%x\n",GPIO_SHIFT_EN);
  142. printf("[LK/LCM] GPIO_LCD_BL_EN = 0x%x\n",GPIO_LCD_BL_EN);
  143. printf("[LK/LCM] GPIO_LCD_BRIDGE_EN = 0x%x \n",GPIO_LCD_BRIDGE_EN);
  144. #elif (defined BUILD_UBOOT)
  145. // do nothing in uboot
  146. #else
  147. //printf("kernel] lcm_set gpio() \n");
  148. #endif
  149. return;
  150. }
  151. mt_set_gpio_mode(GPIO, GPIO_MODE_00);
  152. mt_set_gpio_dir(GPIO, GPIO_DIR_OUT);
  153. mt_set_gpio_out(GPIO, (output>0)? GPIO_OUT_ONE: GPIO_OUT_ZERO);
  154. }
  155. #ifndef BUILD_LK
  156. static bool fgisFirst = TRUE;
  157. #endif
  158. // ---------------------------------------------------------------------------
  159. // LCM Driver Implementations
  160. // ---------------------------------------------------------------------------
  161. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  162. {
  163. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  164. }
  165. static void lcm_get_params(LCM_PARAMS *params)
  166. {
  167. memset(params, 0, sizeof(LCM_PARAMS));
  168. params->type = LCM_TYPE_DPI;
  169. params->ctrl = LCM_CTRL_SERIAL_DBI;
  170. params->width = FRAME_WIDTH;
  171. params->height = FRAME_HEIGHT;
  172. params->io_select_mode = 0;
  173. params->dpi.PLL_CLOCK = 67; //67MHz
  174. /* RGB interface configurations */
  175. params->dpi.mipi_pll_clk_ref = 0;
  176. params->dpi.mipi_pll_clk_div1 = 0x80000101; //lvds pll 65M
  177. params->dpi.mipi_pll_clk_div2 = 0x800a0000;
  178. //params->dpi.dpi_clk_div = 2;
  179. //params->dpi.dpi_clk_duty = 1;
  180. params->dpi.clk_pol = LCM_POLARITY_FALLING;
  181. params->dpi.de_pol = LCM_POLARITY_RISING;
  182. params->dpi.vsync_pol = LCM_POLARITY_FALLING;
  183. params->dpi.hsync_pol = LCM_POLARITY_FALLING;
  184. params->dpi.hsync_pulse_width = HSYNC_PULSE_WIDTH;
  185. params->dpi.hsync_back_porch = HSYNC_BACK_PORCH;
  186. params->dpi.hsync_front_porch = HSYNC_FRONT_PORCH;
  187. params->dpi.vsync_pulse_width = VSYNC_PULSE_WIDTH;
  188. params->dpi.vsync_back_porch = VSYNC_BACK_PORCH;
  189. params->dpi.vsync_front_porch = VSYNC_FRONT_PORCH;
  190. //params->dpi.i2x_en = 1;
  191. params->dpi.lvds_tx_en = 1;
  192. params->dpi.ssc_disable = 1;
  193. params->dpi.format = LCM_DPI_FORMAT_RGB888; // format is 24 bit
  194. params->dpi.rgb_order = LCM_COLOR_ORDER_RGB;
  195. params->dpi.is_serial_output = 0;
  196. params->dpi.intermediat_buffer_num = 0;
  197. params->dpi.io_driving_current = LCM_DRIVING_CURRENT_2MA;
  198. }
  199. static void lcm_init(void)
  200. {
  201. #ifdef BUILD_LK
  202. printf("[LK/LCM] lcm_init() enter\n");
  203. lcm_set_gpio_output(GPIO_LCD_PWR, 1);
  204. lcm_set_gpio_output(GPIO_LCD_PWR_EN, 0);
  205. lcm_set_gpio_output(GPIO_LCD_PWR2_EN, 1);
  206. //VGP6 3.3V
  207. //pmic_config_interface(0x424, 0x1, 0x1, 15);
  208. //pmic_config_interface(0x45a, 0x07, 0x07, 5);
  209. #ifdef MTK_PMIC_MT6397
  210. upmu_set_rg_vgp6_vosel(0x7);
  211. upmu_set_rg_vgp6_sw_en(0x1);
  212. #else
  213. upmu_set_rg_vgp1_vosel(0x7);
  214. upmu_set_rg_vgp1_en(0x1);
  215. #endif
  216. //hwPowerOn(MT65XX_POWER_LDO_VGP6, VOL_3300, "LCM");
  217. lcm_set_gpio_output(GPIO_LCD_RST_EN,GPIO_OUT_ONE);
  218. MDELAY(20);
  219. lcm_set_gpio_output(GPIO_LCD_STB_EN,GPIO_OUT_ONE);
  220. MDELAY(20);
  221. lcm_set_gpio_output(GPIO_LCD_BL_EN, GPIO_OUT_ONE);
  222. #elif (defined BUILD_UBOOT)
  223. // do nothing in uboot
  224. #else
  225. printk("[LCM] lcm_init() enter\n");
  226. lcm_set_gpio_output(GPIO_LCD_RST_EN,GPIO_OUT_ONE);
  227. MDELAY(20);
  228. lcm_set_gpio_output(GPIO_LCD_STB_EN,GPIO_OUT_ONE);
  229. MDELAY(20);
  230. lcm_set_gpio_output(GPIO_LCD_BL_EN, GPIO_OUT_ONE);
  231. #endif
  232. }
  233. static void lcm_suspend(void)
  234. {
  235. #ifdef BUILD_LK
  236. printf("[LK/LCM] lcm_suspend() enter\n");
  237. lcm_set_gpio_output(GPIO_LCD_BL_EN, 0);
  238. MDELAY(20);
  239. lcm_set_gpio_output(GPIO_LCD_RST_EN,GPIO_OUT_ZERO);
  240. lcm_set_gpio_output(GPIO_LCD_STB_EN,GPIO_OUT_ZERO);
  241. lcm_set_gpio_output(GPIO_LCD_PWR, 0);
  242. lcm_set_gpio_output(GPIO_LCD_PWR_EN, 0);
  243. lcm_set_gpio_output(GPIO_LCD_PWR2_EN, 0);
  244. MDELAY(20);
  245. #elif (defined BUILD_UBOOT)
  246. // do nothing in uboot
  247. #else
  248. printk("[LCM] lcm_suspend() enter\n");
  249. lcm_set_gpio_output(GPIO_LCD_BL_EN, 0);
  250. MDELAY(20);
  251. lcm_set_gpio_output(GPIO_LCD_RST_EN,GPIO_OUT_ZERO);
  252. lcm_set_gpio_output(GPIO_LCD_STB_EN,GPIO_OUT_ZERO);
  253. lcm_set_gpio_output(GPIO_LCD_PWR, 0);
  254. lcm_set_gpio_output(GPIO_LCD_PWR_EN, 0);
  255. lcm_set_gpio_output(GPIO_LCD_PWR2_EN, 0);
  256. if(fgisFirst == TRUE)
  257. {
  258. fgisFirst = FALSE;
  259. #ifdef MTK_PMIC_MT6397
  260. hwPowerOn(MT65XX_POWER_LDO_VGP6, VOL_3300, "LCM");
  261. #else
  262. hwPowerOn(MT6323_POWER_LDO_VGP1, VOL_3300, "LCM");
  263. #endif
  264. }
  265. MDELAY(20);
  266. #ifdef MTK_PMIC_MT6397
  267. hwPowerDown(MT65XX_POWER_LDO_VGP6, "LCM");//
  268. #else
  269. hwPowerDown(MT6323_POWER_LDO_VGP1, "LCM");//
  270. #endif
  271. MDELAY(20);
  272. #endif
  273. }
  274. static void lcm_resume(void)
  275. {
  276. #ifdef BUILD_LK
  277. printf("[LK/LCM] lcm_resume() enter\n");
  278. //VGP6 3.3V
  279. #ifdef MTK_PMIC_MT6397
  280. upmu_set_rg_vgp6_vosel(0x7);
  281. upmu_set_rg_vgp6_sw_en(0x1);
  282. #else
  283. upmu_set_rg_vgp1_vosel(0x7);
  284. upmu_set_rg_vgp1_en(0x1);
  285. #endif
  286. //pmic_config_interface(0x424, 0x1, 0x1, 15);
  287. //pmic_config_interface(0x45a, 0x07, 0x07, 5);
  288. // hwPowerOn(MT65XX_POWER_LDO_VGP6, VOL_3300, "LCM");
  289. lcm_set_gpio_output(GPIO_LCD_STB_EN,GPIO_OUT_ONE);
  290. MDELAY(20);
  291. lcm_set_gpio_output(GPIO_LCD_PWR, 1);
  292. lcm_set_gpio_output(GPIO_LCD_PWR_EN, 1);
  293. lcm_set_gpio_output(GPIO_LCD_PWR2_EN, 1);
  294. MDELAY(5);
  295. lcm_set_gpio_output(GPIO_LCD_RST_EN,GPIO_OUT_ONE);
  296. MDELAY(20);
  297. lcm_set_gpio_output(GPIO_LCD_BL_EN, 1);
  298. #elif (defined BUILD_UBOOT)
  299. // do nothing in uboot
  300. #else
  301. printk("[LCM] lcm_resume() enter\n");
  302. #ifdef MTK_PMIC_MT6397
  303. hwPowerOn(MT65XX_POWER_LDO_VGP6, VOL_3300, "LCM");
  304. #else
  305. hwPowerOn(MT6323_POWER_LDO_VGP1, VOL_3300, "LCM");
  306. #endif
  307. MDELAY(30);
  308. lcm_set_gpio_output(GPIO_LCD_PWR, 1);
  309. lcm_set_gpio_output(GPIO_LCD_PWR_EN, 1);
  310. lcm_set_gpio_output(GPIO_LCD_PWR2_EN, 1);
  311. MDELAY(5);
  312. lcm_set_gpio_output(GPIO_LCD_STB_EN, 1);
  313. MDELAY(5);
  314. lcm_set_gpio_output(GPIO_LCD_RST_EN, 1);
  315. MDELAY(5);
  316. lcm_set_gpio_output(GPIO_LCD_BL_EN, 1);
  317. #endif
  318. }
  319. LCM_DRIVER cpt_clap070wp03xg_lvds_lcm_drv =
  320. {
  321. .name = "cpt_clap070wp03xg_lvds",
  322. .set_util_funcs = lcm_set_util_funcs,
  323. .get_params = lcm_get_params,
  324. .init = lcm_init,
  325. .suspend = lcm_suspend,
  326. .resume = lcm_resume,
  327. };