db7436_dsi_vdo_fwvga.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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) 2013. 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. /*****************************************************************************
  36. * Copyright Statement:
  37. * --------------------
  38. * This software is protected by Copyright and the information contained
  39. * herein is confidential. The software may not be copied and the information
  40. * contained herein may not be used or disclosed except with the written
  41. * permission of MediaTek Inc. (C) 2008
  42. *
  43. * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  44. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  45. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  46. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  47. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  48. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  49. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  50. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  51. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  52. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  53. * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  54. * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  55. *
  56. * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  57. * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  58. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  59. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  60. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  61. *
  62. * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  63. * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  64. * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  65. * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  66. * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  67. *
  68. *****************************************************************************/
  69. #ifdef BUILD_LK
  70. #include <string.h>
  71. #include <mt_gpio.h>
  72. #include <platform/mt_pmic.h>
  73. //#include <lge_bootmode.h>
  74. #include <platform/boot_mode.h>
  75. #elif defined(BUILD_UBOOT)
  76. #include <asm/arch/mt_gpio.h>
  77. #else
  78. #include <linux/string.h>
  79. #include <mach/mt_gpio.h>
  80. #include <mach/mt_pm_ldo.h>
  81. #endif
  82. #include "lcm_drv.h"
  83. #include <cust_gpio_usage.h>
  84. #ifndef BUILD_LK
  85. #include <mach/mt_pwm.h>
  86. #endif
  87. #if defined(BUILD_LK)
  88. #define LCM_PRINT printf
  89. #elif defined(BUILD_UBOOT)
  90. #define LCM_PRINT printf
  91. #else
  92. #define LCM_PRINT printk
  93. #endif
  94. extern void chargepump_DSV_on();
  95. extern void chargepump_DSV_off();
  96. // ---------------------------------------------------------------------------
  97. // Local Constants
  98. // ---------------------------------------------------------------------------
  99. // pixel
  100. #define FRAME_WIDTH (480)
  101. #define FRAME_HEIGHT (854)
  102. // physical dimension
  103. #define PHYSICAL_WIDTH (68)
  104. #define PHYSICAL_HIGHT (121)
  105. #define LCM_ID (0x40)
  106. #define LCM_DSI_CMD_MODE 0
  107. #define REGFLAG_DELAY 0xAB
  108. #define REGFLAG_END_OF_TABLE 0xAA // END OF REGISTERS MARKER
  109. /*
  110. DSV power +5V,-5v
  111. */
  112. #ifndef GPIO_DSV_AVDD_EN
  113. #define GPIO_DSV_AVDD_EN (GPIO107 | 0x80000000)
  114. #define GPIO_DSV_AVDD_EN_M_GPIO GPIO_MODE_00
  115. #define GPIO_DSV_AVDD_EN_M_KROW GPIO_MODE_06
  116. #define GPIO_DSV_AVDD_EN_M_PWM GPIO_MODE_05
  117. #endif
  118. #ifndef GPIO_DSV_AVEE_EN
  119. #define GPIO_DSV_AVEE_EN (GPIO106 | 0x80000000)
  120. #define GPIO_DSV_AVEE_EN_M_GPIO GPIO_MODE_00
  121. #define GPIO_DSV_AVEE_EN_M_KROW GPIO_MODE_06
  122. #define GPIO_DSV_AVEE_EN_M_PWM GPIO_MODE_05
  123. #endif
  124. #ifndef GPIO_LCM_PWR
  125. #define GPIO_LCM_PWR (GPIO75 | 0x80000000)
  126. #define GPIO_LCM_PWR_M_GPIO GPIO_MODE_00
  127. #define GPIO_LCM_PWR_M_KCOL GPIO_MODE_01
  128. #endif
  129. // ---------------------------------------------------------------------------
  130. // Local Variables
  131. // ---------------------------------------------------------------------------
  132. static LCM_UTIL_FUNCS lcm_util = {0};
  133. #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
  134. #define UDELAY(n) (lcm_util.udelay(n))
  135. #define MDELAY(n) (lcm_util.mdelay(n))
  136. // ---------------------------------------------------------------------------
  137. // Local Functions
  138. // ---------------------------------------------------------------------------
  139. #define dsi_set_cmdq_V3(para_tbl, size, force_update) lcm_util.dsi_set_cmdq_V3(para_tbl, size, force_update)
  140. #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
  141. #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
  142. #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
  143. #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
  144. #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
  145. #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
  146. static unsigned int need_set_lcm_addr = 1;
  147. struct LCM_setting_table {
  148. unsigned char cmd;
  149. unsigned char count;
  150. unsigned char para_list[64];
  151. };
  152. static struct LCM_setting_table lcm_initialization_setting[] = {
  153. {0xB7, 7, {0x00, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B}},
  154. {0xB6, 6, {0x06, 0x0A, 0x34, 0x23, 0x41, 0x0A}},
  155. {0xB8, 4, {0x00, 0x42, 0x12, 0xF7}},
  156. {0xB0, 1, {0x00}},
  157. {0xB5, 10, {0x43, 0xA0, 0x01, 0x12, 0x06, 0x00, 0x00, 0x00, 0x00, 0x48}},
  158. {0xB4, 6, {0x01, 0x09, 0x02, 0x02, 0x02, 0x02}}, // 2nd 0d->09
  159. {0xB3, 3, {0x8B, 0x7F, 0x30}},
  160. {0xB2, 2, {0x00, 0x03}},
  161. {0xB1, 4, {0xC6, 0x1E, 0x0F, 0x00}},
  162. {0xB9, 3, {0x00, 0x03, 0x04}},
  163. {0xBB, 1, {0x30}},
  164. {0x36, 1, {0x00}},
  165. {0xD9, 1, {0xA0}},
  166. {0xF8, 2, {0x00, 0x06}},
  167. {0xD7, 2, {0x00, 0xB6}},
  168. {0xBD, 2, {0x00, 0x23}},
  169. {0xC5, 3, {0x3F, 0x00, 0x50}},
  170. {0xC4, 1, {0x00}},
  171. {0xD0, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  172. {0xD1, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  173. {0xD2, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  174. {0xD3, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  175. {0xD4, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  176. {0xD5, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  177. {REGFLAG_END_OF_TABLE, 0x00, {}},
  178. };
  179. static struct LCM_setting_table lcm_initialization_setting_ext[] = {
  180. {0xFE, 1, {0x00}},
  181. {0x11, 0, {}},
  182. {REGFLAG_DELAY, 120, {}}, //MDELAY(120)
  183. {0x29, 0, {}},
  184. {REGFLAG_END_OF_TABLE, 0x00, {}},
  185. };
  186. static LCM_setting_table_V3 lcm_EXTC_set_enable_V3[] = {
  187. {0x15, 0xFE, 1, {0x00}},
  188. };
  189. static LCM_setting_table_V3 lcm_initialization_setting_V3[] = {
  190. {0x39, 0xB7, 7, {0x00, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B}},
  191. {0x39, 0xB6, 6, {0x06, 0x0A, 0x34, 0x23, 0x41, 0x0A}},
  192. {0x39, 0xB8, 4, {0x00, 0x42, 0x12, 0xF7}},
  193. {0x15, 0xB0, 1, {0x00}},
  194. {0x39, 0xB5, 10, {0x43, 0xA0, 0x01, 0x12, 0x06, 0x00, 0x00, 0x00, 0x00, 0x48}},
  195. {0x39, 0xB4, 6, {0x01, 0x0D, 0x02, 0x02, 0x02, 0x02}},
  196. {0x39, 0xB3, 3, {0x8B, 0x7F, 0x30}},
  197. {0x15, 0xB2, 2, {0x00, 0x03}},
  198. {0x39, 0xB1, 4, {0xC6, 0x1E, 0x0F, 0x00}},
  199. {0x39, 0xB9, 3, {0x00, 0x03, 0x04}},
  200. {0x15, 0xBB, 1, {0x30}},
  201. {0x15, 0x36, 1, {0x00}},
  202. {0x15, 0xD9, 1, {0xA0}},
  203. {0x15, 0xF8, 2, {0x00, 0x06}},
  204. {0x15, 0xD7, 2, {0x00, 0xB6}},
  205. {0x15, 0xBD, 2, {0x00, 0x23}},
  206. {0x39, 0xC5, 3, {0x3F, 0x00, 0x50}},
  207. {0x15, 0xC4, 1, {0x00}},
  208. {0x39, 0xD0, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  209. {0x39, 0xD1, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  210. {0x39, 0xD2, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  211. {0x39, 0xD3, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  212. {0x39, 0xD4, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  213. {0x39, 0xD5, 9, {0x00, 0x26, 0x74, 0x14, 0x00, 0x00, 0x32, 0x03, 0x03}},
  214. };
  215. static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
  216. {
  217. unsigned int i;
  218. for(i = 0; i < count; i++) {
  219. unsigned cmd;
  220. cmd = table[i].cmd;
  221. switch (cmd) {
  222. case REGFLAG_DELAY:
  223. MDELAY(table[i].count);
  224. break;
  225. case REGFLAG_END_OF_TABLE:
  226. break;
  227. default:
  228. dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
  229. }
  230. }
  231. LCM_PRINT("[LCD] push_table \n");
  232. }
  233. // ---------------------------------------------------------------------------
  234. // LCM Driver Implementations
  235. // ---------------------------------------------------------------------------
  236. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  237. {
  238. memcpy((void*)&lcm_util, (void*)util, sizeof(LCM_UTIL_FUNCS));
  239. }
  240. static void lcm_get_params(LCM_PARAMS * params)
  241. {
  242. memset(params, 0, sizeof(LCM_PARAMS));
  243. params->type = LCM_TYPE_DSI;
  244. params->width = FRAME_WIDTH;
  245. params->height = FRAME_HEIGHT;
  246. params->physical_width=PHYSICAL_WIDTH;
  247. params->physical_height=PHYSICAL_HIGHT;
  248. // enable tearing-free
  249. params->dbi.te_mode = LCM_DBI_TE_MODE_DISABLED;
  250. params->dbi.te_edge_polarity = LCM_POLARITY_RISING;
  251. #if (LCM_DSI_CMD_MODE)
  252. params->dsi.mode = CMD_MODE;
  253. #else
  254. params->dsi.mode = SYNC_EVENT_VDO_MODE;//SYNC_PULSE_VDO_MODE;
  255. #endif
  256. // DSI
  257. /* Command mode setting */
  258. params->dsi.LANE_NUM = LCM_TWO_LANE;
  259. //The following defined the fomat for data coming from LCD engine.
  260. params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
  261. params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
  262. params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
  263. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  264. // Highly depends on LCD driver capability.
  265. params->dsi.packet_size = 256;
  266. // Video mode setting
  267. params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;
  268. params->dsi.vertical_sync_active = 4;
  269. params->dsi.vertical_backporch = 12;
  270. params->dsi.vertical_frontporch = 50;//127;
  271. params->dsi.vertical_active_line = FRAME_HEIGHT;
  272. params->dsi.horizontal_sync_active = 8;
  273. params->dsi.horizontal_backporch = 72;
  274. params->dsi.horizontal_frontporch = 16;
  275. params->dsi.horizontal_active_pixel = FRAME_WIDTH;
  276. // Bit rate calculation
  277. //params->dsi.pll_div1=35; // fref=26MHz, fvco=fref*(div1+1) (div1=0~63, fvco=500MHZ~1GHz)
  278. //params->dsi.pll_div2=1; // div2=0~15: fout=fvo/(2*div2)
  279. /* ESD or noise interference recovery For video mode LCM only. */
  280. // Send TE packet to LCM in a period of n frames and check the response.
  281. //params->dsi.lcm_int_te_monitor = FALSE;
  282. //params->dsi.lcm_int_te_period = 1; // Unit : frames
  283. // Need longer FP for more opportunity to do int. TE monitor applicably.
  284. //if(params->dsi.lcm_int_te_monitor)
  285. // params->dsi.vertical_frontporch *= 2;
  286. // Monitor external TE (or named VSYNC) from LCM once per 2 sec. (LCM VSYNC must be wired to baseband TE pin.)
  287. //params->dsi.lcm_ext_te_monitor = FALSE;
  288. // Non-continuous clock
  289. //params->dsi.noncont_clock = TRUE;
  290. //params->dsi.noncont_clock_period = 2; // Unit : frames
  291. params->dsi.null_packet_en = FALSE;
  292. params->dsi.mixmode_enable = TRUE;
  293. params->dsi.pwm_fps = 60;
  294. params->dsi.mixmode_mipi_clock = 425; // 7.75ms
  295. params->dsi.send_frame_enable = TRUE;
  296. // DSI MIPI Spec parameters setting
  297. params->dsi.HS_TRAIL = 14;
  298. params->dsi.HS_ZERO = 6;
  299. params->dsi.HS_PRPR = 8;
  300. params->dsi.LPX = 6;
  301. params->dsi.TA_SACK = 1;
  302. params->dsi.TA_GET = 30;
  303. params->dsi.TA_SURE = 9;
  304. params->dsi.TA_GO = 24;
  305. params->dsi.CLK_TRAIL = 7;
  306. params->dsi.CLK_ZERO = 28;
  307. params->dsi.LPX_WAIT = 1;
  308. params->dsi.CONT_DET = 0;
  309. params->dsi.CLK_HS_PRPR = 8;
  310. // Bit rate calculation
  311. //params->dsi.PLL_CLOCK = 416;
  312. params->dsi.PLL_CLOCK = 260;
  313. LCM_PRINT("[LCD] lcm_get_params \n");
  314. }
  315. static void init_lcm_registers(void)
  316. {
  317. push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
  318. LCM_PRINT("[LCD] init_lcm_registers \n");
  319. }
  320. static void init_lcm_registers_added(void)
  321. {
  322. push_table(lcm_initialization_setting_ext, sizeof(lcm_initialization_setting_ext) / sizeof(struct LCM_setting_table), 1);
  323. LCM_PRINT("[LCD] init_lcm_registers_added \n");
  324. }
  325. static void init_lcm_registers_sleep(void)
  326. {
  327. unsigned int data_array[2];
  328. data_array[0] = 0x00100500; //Seep In
  329. dsi_set_cmdq(data_array, 1, 1);
  330. MDELAY(100);
  331. data_array[0] = 0x05FE1500;
  332. dsi_set_cmdq(data_array, 1, 1);
  333. data_array[0] = 0x00033902;
  334. data_array[1] = 0x000010D8;
  335. dsi_set_cmdq(data_array, 2, 1);
  336. LCM_PRINT("[LCD] init_lcm_registers_sleep \n");
  337. }
  338. /* 1.8v LDO enable */
  339. static void ldo_1v8io_on(void)
  340. {
  341. #ifdef BUILD_UBOOT
  342. #error "not implemeted"
  343. #elif defined(BUILD_LK)
  344. // IOVCC 1.8v LDO on
  345. upmu_set_rg_vcamd_vosel(3);
  346. upmu_set_rg_vcamd_en(1);
  347. #else
  348. hwPowerOn(MT6323_POWER_LDO_VCAMD, VOL_1800, "1V8_LCD_VIO_MTK_S");
  349. #endif
  350. }
  351. /* vgp2 1.8v LDO disable */
  352. static void ldo_1v8io_off(void)
  353. {
  354. #ifdef BUILD_UBOOT
  355. #error "not implemeted"
  356. #elif defined(BUILD_LK)
  357. upmu_set_rg_vcamd_en(0);
  358. #else
  359. hwPowerDown(MT6323_POWER_LDO_VCAMD, "1V8_LCD_VIO_MTK_S");
  360. #endif
  361. }
  362. static void ldo_ext_3v0_on(void)
  363. {
  364. #ifdef BUILD_UBOOT
  365. #error "not implemeted"
  366. #elif defined(BUILD_LK)
  367. mt_set_gpio_mode(GPIO_LCM_PWR, GPIO_LCM_PWR_M_GPIO);
  368. mt_set_gpio_pull_enable(GPIO_LCM_PWR, GPIO_PULL_ENABLE);
  369. mt_set_gpio_dir(GPIO_LCM_PWR, GPIO_DIR_OUT);
  370. mt_set_gpio_out(GPIO_LCM_PWR, GPIO_OUT_ONE);
  371. #else
  372. mt_set_gpio_mode(GPIO_LCM_PWR, GPIO_LCM_PWR_M_GPIO);
  373. mt_set_gpio_pull_enable(GPIO_LCM_PWR, GPIO_PULL_ENABLE);
  374. mt_set_gpio_dir(GPIO_LCM_PWR, GPIO_DIR_OUT);
  375. mt_set_gpio_out(GPIO_LCM_PWR, GPIO_OUT_ONE);
  376. #endif
  377. }
  378. static void ldo_ext_3v0_off(void)
  379. {
  380. #ifdef BUILD_UBOOT
  381. #error "not implemeted"
  382. #elif defined(BUILD_LK)
  383. mt_set_gpio_mode(GPIO_LCM_PWR, GPIO_LCM_PWR_M_GPIO);
  384. mt_set_gpio_pull_enable(GPIO_LCM_PWR, GPIO_PULL_ENABLE);
  385. mt_set_gpio_dir(GPIO_LCM_PWR, GPIO_DIR_OUT);
  386. mt_set_gpio_out(GPIO_LCM_PWR, GPIO_OUT_ZERO);
  387. #else
  388. mt_set_gpio_mode(GPIO_LCM_PWR, GPIO_LCM_PWR_M_GPIO);
  389. mt_set_gpio_pull_enable(GPIO_LCM_PWR, GPIO_PULL_ENABLE);
  390. mt_set_gpio_dir(GPIO_LCM_PWR, GPIO_DIR_OUT);
  391. mt_set_gpio_out(GPIO_LCM_PWR, GPIO_OUT_ZERO);
  392. #endif
  393. }
  394. /*
  395. DSV power +5V,-5v
  396. */
  397. static void ldo_p5m5_dsv_on(void)
  398. {
  399. #if defined(CONFIG_LEDS_LM3632)
  400. chargepump_DSV_on();
  401. #else
  402. mt_set_gpio_mode(GPIO_DSV_AVDD_EN, GPIO_DSV_AVDD_EN_M_GPIO);
  403. mt_set_gpio_pull_enable(GPIO_DSV_AVDD_EN, GPIO_PULL_ENABLE);
  404. mt_set_gpio_dir(GPIO_DSV_AVDD_EN, GPIO_DIR_OUT);
  405. mt_set_gpio_mode(GPIO_DSV_AVEE_EN, GPIO_DSV_AVEE_EN_M_GPIO);
  406. mt_set_gpio_pull_enable(GPIO_DSV_AVEE_EN, GPIO_PULL_ENABLE);
  407. mt_set_gpio_dir(GPIO_DSV_AVEE_EN, GPIO_DIR_OUT);
  408. mt_set_gpio_out(GPIO_DSV_AVDD_EN, GPIO_OUT_ONE);
  409. MDELAY(1);
  410. mt_set_gpio_out(GPIO_DSV_AVEE_EN, GPIO_OUT_ONE);
  411. #endif
  412. }
  413. static void ldo_p5m5_dsv_off(void)
  414. {
  415. #if defined(CONFIG_LEDS_LM3632)
  416. chargepump_DSV_off();
  417. #else
  418. mt_set_gpio_mode(GPIO_DSV_AVDD_EN, GPIO_DSV_AVDD_EN_M_GPIO);
  419. mt_set_gpio_pull_enable(GPIO_DSV_AVDD_EN, GPIO_PULL_ENABLE);
  420. mt_set_gpio_dir(GPIO_DSV_AVDD_EN, GPIO_DIR_OUT);
  421. mt_set_gpio_mode(GPIO_DSV_AVEE_EN, GPIO_DSV_AVEE_EN_M_GPIO);
  422. mt_set_gpio_pull_enable(GPIO_DSV_AVEE_EN, GPIO_PULL_ENABLE);
  423. mt_set_gpio_dir(GPIO_DSV_AVEE_EN, GPIO_DIR_OUT);
  424. mt_set_gpio_out(GPIO_DSV_AVDD_EN, GPIO_OUT_ZERO);
  425. MDELAY(1);
  426. mt_set_gpio_out(GPIO_DSV_AVEE_EN, GPIO_OUT_ZERO);
  427. #endif
  428. }
  429. static void lcm_init(void)
  430. {
  431. #if defined(BUILD_LK)
  432. ldo_p5m5_dsv_off();
  433. #endif
  434. SET_RESET_PIN(0);
  435. ldo_1v8io_on();
  436. ldo_ext_3v0_on();
  437. MDELAY(10);
  438. ldo_p5m5_dsv_on();
  439. SET_RESET_PIN(1);
  440. MDELAY(20);
  441. init_lcm_registers();
  442. init_lcm_registers_added(); //Display On
  443. MDELAY(10);
  444. need_set_lcm_addr = 1;
  445. LCM_PRINT("[LCD] lcm_init \n");
  446. }
  447. static void lcm_suspend(void)
  448. {
  449. init_lcm_registers_sleep(); // Display off
  450. LCM_PRINT("[LCD] lcm_suspend \n");
  451. }
  452. static void lcm_suspend_power(void)
  453. {
  454. MDELAY(120);
  455. ldo_p5m5_dsv_off(); // DSV +-5V power off
  456. MDELAY(20);
  457. //VCI/IOVCC off
  458. ldo_1v8io_off();
  459. ldo_ext_3v0_off();
  460. LCM_PRINT("[LCD] lcm_suspend_power \n");
  461. }
  462. static void lcm_resume(void)
  463. {
  464. lcm_init();
  465. need_set_lcm_addr = 1;
  466. LCM_PRINT("[LCD] lcm_resume \n");
  467. }
  468. static void lcm_esd_recover(void)
  469. {
  470. lcm_suspend();
  471. lcm_resume();
  472. LCM_PRINT("[LCD] lcm_esd_recover \n");
  473. }
  474. static void lcm_update(unsigned int x, unsigned int y,
  475. unsigned int width, unsigned int height)
  476. {
  477. unsigned int x0 = x;
  478. unsigned int y0 = y;
  479. unsigned int x1 = x0 + width - 1;
  480. unsigned int y1 = y0 + height - 1;
  481. unsigned char x0_MSB = ((x0>>8)&0xFF);
  482. unsigned char x0_LSB = (x0&0xFF);
  483. unsigned char x1_MSB = ((x1>>8)&0xFF);
  484. unsigned char x1_LSB = (x1&0xFF);
  485. unsigned char y0_MSB = ((y0>>8)&0xFF);
  486. unsigned char y0_LSB = (y0&0xFF);
  487. unsigned char y1_MSB = ((y1>>8)&0xFF);
  488. unsigned char y1_LSB = (y1&0xFF);
  489. unsigned int data_array[16];
  490. // need update at the first time
  491. if(need_set_lcm_addr)
  492. {
  493. data_array[0]= 0x00053902;
  494. data_array[1]= (x1_MSB<<24)|(x0_LSB<<16)|(x0_MSB<<8)|0x2a;
  495. data_array[2]= (x1_LSB);
  496. dsi_set_cmdq(data_array, 3, 1);
  497. data_array[0]= 0x00053902;
  498. data_array[1]= (y1_MSB<<24)|(y0_LSB<<16)|(y0_MSB<<8)|0x2b;
  499. data_array[2]= (y1_LSB);
  500. dsi_set_cmdq(data_array, 3, 1);
  501. need_set_lcm_addr = 0;
  502. }
  503. data_array[0]= 0x002c3909;
  504. dsi_set_cmdq(data_array, 1, 0);
  505. LCM_PRINT("[LCD] lcm_update \n");
  506. }
  507. static unsigned int lcm_compare_id(void)
  508. {
  509. return 1;
  510. }
  511. #if defined(BUILD_LK)
  512. static void lcm_set_pwm_for_mix(int enable)
  513. {
  514. return;
  515. }
  516. #else
  517. //#define GPIO_INCELL_DISP_TE_PWM (GPIO47 | 0x80000000) // Rev A
  518. #define GPIO_INCELL_DISP_TE_PWM (GPIO90 | 0x80000000) // Rev B
  519. #define GPIO_INCELL_DISP_TE_M_GPIO GPIO_MODE_00
  520. #define GPIO_INCELL_DISP_TE_M_PWM GPIO_MODE_02
  521. static struct pwm_spec_config pwm_setting = {
  522. // .pwm_no = PWM1, // Rev A
  523. .pwm_no = PWM2, // Rev B
  524. .mode = PWM_MODE_OLD,
  525. .clk_src = PWM_CLK_OLD_MODE_32K,
  526. .pmic_pad = false,
  527. .PWM_MODE_OLD_REGS.IDLE_VALUE = IDLE_FALSE,
  528. .PWM_MODE_OLD_REGS.GUARD_VALUE = 0, /* in old mode, this value is invalid */
  529. .PWM_MODE_OLD_REGS.GDURATION = 0,
  530. .PWM_MODE_OLD_REGS.WAVE_NUM = 0, /* 0 == none stop until the PWM is disable */
  531. /* 135 : 60.24HZ, margin btw touch_en & pwm_falling_edge=740uS */
  532. .clk_div = CLK_DIV4,
  533. .PWM_MODE_OLD_REGS.DATA_WIDTH = 135,//58.2fps //135 //60.2fps
  534. .PWM_MODE_OLD_REGS.THRESH =135/2,
  535. };
  536. static void set_enable_te_framesync(void)
  537. {
  538. LCM_PRINT("=============mt_pmic_pwm2_test===============\n");
  539. mt_set_gpio_mode(GPIO_INCELL_DISP_TE_PWM,GPIO_INCELL_DISP_TE_M_PWM);
  540. LCM_PRINT("PWM: clk_div = %x, clk_src = %x, pwm_no = %x\n", pwm_setting.clk_div, pwm_setting.clk_src, pwm_setting.pwm_no);
  541. pwm_set_spec_config(&pwm_setting);
  542. }
  543. void lcm_set_fps(int fps)
  544. {
  545. unsigned int width = 32 * 1024 / (4 * fps) - 1;
  546. LCM_PRINT("DSI_set_fps_for_PWM fps (%d), widht (%d)\n", fps, width);
  547. pwm_setting.PWM_MODE_OLD_REGS.DATA_WIDTH = width;
  548. pwm_setting.PWM_MODE_OLD_REGS.THRESH = width/2;
  549. }
  550. static void lcm_set_pwm_for_mix(int enable)
  551. {
  552. LCM_PARAMS params;
  553. lcm_get_params(&params);
  554. if (params.dsi.pwm_fps == 0)
  555. {
  556. LCM_PRINT("Please set PWM fps \n");
  557. return;
  558. }
  559. if (enable)
  560. {
  561. lcm_set_fps(params.dsi.pwm_fps);
  562. set_enable_te_framesync();
  563. }
  564. else
  565. {
  566. mt_pwm_disable(pwm_setting.pwm_no, pwm_setting.pmic_pad);
  567. }
  568. LCM_PRINT("[LCD] lcm_set_pwm (%d)\n", enable);
  569. return;
  570. }
  571. #endif
  572. // ---------------------------------------------------------------------------
  573. // Get LCM Driver Hooks
  574. // ---------------------------------------------------------------------------
  575. LCM_DRIVER db7436_dsi_vdo_fwvga_drv = {
  576. .name = "db7436_dsi_vdo_fwvga",
  577. .set_util_funcs = lcm_set_util_funcs,
  578. .get_params = lcm_get_params,
  579. .init = lcm_init,
  580. .suspend = lcm_suspend,
  581. .suspend_power = lcm_suspend_power,
  582. .resume = lcm_resume,
  583. .compare_id = lcm_compare_id,
  584. .update = lcm_update,
  585. #if (!defined(BUILD_UBOOT) && !defined(BUILD_LK))
  586. .esd_recover = lcm_esd_recover,
  587. #endif
  588. .set_pwm_for_mix = lcm_set_pwm_for_mix,
  589. };