s6e3ha3_wqhd_2k_cmd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. #define LOG_TAG "LCM"
  36. #ifndef BUILD_LK
  37. #include <linux/string.h>
  38. #include <linux/kernel.h>
  39. #endif
  40. #include "lcm_drv.h"
  41. #ifdef BUILD_LK
  42. #include <platform/upmu_common.h>
  43. #include <platform/mt_gpio.h>
  44. #include <platform/mt_i2c.h>
  45. #include <platform/mt_pmic.h>
  46. #include <string.h>
  47. #elif defined(BUILD_UBOOT)
  48. #include <asm/arch/mt_gpio.h>
  49. #else
  50. #ifdef CONFIG_MTK_LEGACY
  51. #include <mach/mt_gpio.h>
  52. #endif
  53. #endif
  54. #ifdef CONFIG_MTK_LEGACY
  55. #include <cust_gpio_usage.h>
  56. #endif
  57. #ifndef CONFIG_FPGA_EARLY_PORTING
  58. #if defined(CONFIG_MTK_LEGACY)
  59. #include <cust_i2c.h>
  60. #endif
  61. #endif
  62. #ifdef BUILD_LK
  63. #define LCD_DEBUG(fmt) dprintf(CRITICAL, fmt)
  64. #else
  65. #define LCD_DEBUG(fmt) pr_debug(fmt)
  66. #endif
  67. /**
  68. * Local Constants
  69. */
  70. #define LCM_DSI_CMD_MODE 1
  71. #define FRAME_WIDTH (1440)
  72. #define FRAME_HEIGHT (2560)
  73. #ifndef TRUE
  74. #define TRUE 1
  75. #endif
  76. #ifndef FALSE
  77. #define FALSE 0
  78. #endif
  79. /**
  80. * Local Variables
  81. */
  82. static LCM_UTIL_FUNCS lcm_util = {0};
  83. #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
  84. #define UDELAY(n) (lcm_util.udelay(n))
  85. #define MDELAY(n) (lcm_util.mdelay(n))
  86. /**
  87. * Local Functions
  88. */
  89. #define dsi_set_cmd_by_cmdq_dual(handle, cmd, count, ppara, force_update) \
  90. lcm_util.dsi_set_cmdq_V23(handle, cmd, (unsigned char)(count),\
  91. (unsigned char *)(ppara), (unsigned char)(force_update))
  92. #define dsi_set_cmdq_V3(para_tbl, size, force_update) \
  93. lcm_util.dsi_set_cmdq_V3(para_tbl, size, force_update)
  94. #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
  95. #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
  96. #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
  97. #define write_regs(addr, pdata, byte_nums) \
  98. lcm_util.dsi_write_regs(addr, pdata, byte_nums)
  99. #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
  100. #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
  101. #define REGFLAG_DELAY 0xFE
  102. #define REGFLAG_END_OF_TABLE 0xFF /* END OF REGISTERS MARKER */
  103. struct LCM_setting_table {
  104. unsigned cmd;
  105. unsigned char count;
  106. unsigned char para_list[64];
  107. };
  108. static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
  109. {
  110. unsigned int i;
  111. for (i = 0; i < count; i++) {
  112. unsigned cmd;
  113. cmd = table[i].cmd;
  114. switch (cmd) {
  115. case REGFLAG_DELAY:
  116. #ifdef BUILD_LK
  117. dprintf(0, "[LK]REGFLAG_DELAY\n");
  118. #endif
  119. MDELAY(table[i].count);
  120. break;
  121. case REGFLAG_END_OF_TABLE:
  122. #ifdef BUILD_LK
  123. dprintf(0, "[LK]push_table end\n");
  124. #endif
  125. break;
  126. default:
  127. dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
  128. }
  129. }
  130. }
  131. static struct LCM_setting_table lcm_initialization_setting[] = {
  132. /* Sleep Out */
  133. {0x11, 0, {} },
  134. {REGFLAG_DELAY, 20, {} }, /* 20ms */
  135. /* Interface Setting */
  136. {0xF0, 2, {0x5A, 0x5A} }, /* TEST KEY Enable */
  137. {REGFLAG_DELAY, 20, {} }, /* 20ms */
  138. #if (!LCM_DSI_CMD_MODE)
  139. {0xB0, 1, {0x01} }, /* global para */
  140. {0xF2, 1, {0x4E} }, /* Need to transfer from Command mode to video mode
  141. if The module's default is commmand mode. */
  142. #endif
  143. {0xC4, 1, {0x00} }, /* DUAL Control */
  144. {0xF9, 1, {0x00} }, /* DUAL Control */
  145. {0xC4, 1, {0x03} }, /* DUAL Control */
  146. {0xF9, 1, {0x03} }, /* DUAL Control */
  147. /* MBGR */
  148. {0x36, 1, {0x08} },
  149. {
  150. 0xC2, 19, {
  151. 0x00, 0x00, 0xD8, 0xD8, 0x00, 0x80, 0x2B, 0x05,
  152. 0x08, 0x0E, 0x07, 0x0B, 0x05, 0x0D, 0x0A, 0x15,
  153. 0x13, 0x20, 0x1E
  154. }
  155. }, /* PENTILE Setting */
  156. {0xF0, 2, {0xA5, 0xA5} }, /* TEST KEY Disable */
  157. {REGFLAG_DELAY, 120, {} }, /* 120ms */
  158. /* Common Setting */
  159. {0x35, 1, {0x00} }, /* TE ON */
  160. /* Brightness Control */
  161. {0x53, 1, {0x20} }, /* Dimming Control */
  162. {0x51, 1, {0xFF} }, /* Luminance Setting */
  163. /* ACL ON/OFF */
  164. {0x55, 1, {0x00} },
  165. /* memory access */
  166. {0x2C, 0, {} },
  167. {0x3C, 0, {} },
  168. /* display on */
  169. {0x29, 0, {} },
  170. };
  171. static struct LCM_setting_table lcm_suspend_setting[] = {
  172. {0x00, 0, {} }, /* NOP */
  173. {0x28, 0, {} },
  174. {0x10, 0, {} },
  175. {REGFLAG_DELAY, 150, {} }
  176. };
  177. /**
  178. * LCM Driver Implementations
  179. */
  180. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  181. {
  182. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  183. }
  184. static void lcm_get_params(LCM_PARAMS *params)
  185. {
  186. memset(params, 0, sizeof(LCM_PARAMS));
  187. params->type = LCM_TYPE_DSI;
  188. params->width = FRAME_WIDTH;
  189. params->height = FRAME_HEIGHT;
  190. params->lcm_if = LCM_INTERFACE_DSI_DUAL;
  191. params->lcm_cmd_if = LCM_INTERFACE_DSI0;
  192. #if (LCM_DSI_CMD_MODE)
  193. params->dsi.mode = CMD_MODE;
  194. #else
  195. params->dsi.mode = BURST_VDO_MODE;
  196. #endif
  197. params->dsi.dual_dsi_type = DUAL_DSI_CMD;
  198. /* DSI */
  199. /* Command mode setting */
  200. params->dsi.LANE_NUM = LCM_FOUR_LANE;
  201. /* The following defined the fomat for data coming from LCD engine. */
  202. params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
  203. params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
  204. params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
  205. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  206. /* Video mode setting */
  207. params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;
  208. params->dsi.packet_size = 256;
  209. params->dsi.ssc_disable = 1;
  210. /* params->dsi.ssc_range = 3; */
  211. params->dsi.vertical_sync_active = 2;
  212. params->dsi.vertical_backporch = 4;
  213. params->dsi.vertical_frontporch = 20;
  214. params->dsi.vertical_active_line = FRAME_HEIGHT;
  215. params->dsi.horizontal_sync_active = 30;
  216. params->dsi.horizontal_backporch = 40;
  217. params->dsi.horizontal_frontporch = 90;
  218. params->dsi.horizontal_active_pixel = FRAME_WIDTH;
  219. /* Bit rate calculation */
  220. params->dsi.PLL_CLOCK = 450;
  221. params->dsi.ufoe_enable = 1;
  222. params->dsi.ufoe_params.lr_mode_en = 1;
  223. }
  224. static void lcm_init(void)
  225. {
  226. SET_RESET_PIN(1);
  227. MDELAY(20);
  228. SET_RESET_PIN(0);
  229. MDELAY(20);
  230. SET_RESET_PIN(1);
  231. MDELAY(150);
  232. push_table(lcm_initialization_setting, ARRAY_SIZE(lcm_initialization_setting), 1);
  233. #ifdef BUILD_LK
  234. dprintf(0, "[LK]push_table end\n");
  235. #endif
  236. }
  237. static void lcm_suspend(void)
  238. {
  239. push_table(lcm_suspend_setting, ARRAY_SIZE(lcm_suspend_setting), 1);
  240. SET_RESET_PIN(0);
  241. }
  242. static void lcm_resume(void)
  243. {
  244. lcm_init();
  245. }
  246. #if (LCM_DSI_CMD_MODE)
  247. static void lcm_update(unsigned int x, unsigned int y,
  248. unsigned int width, unsigned int height)
  249. {
  250. unsigned int x0 = x;
  251. unsigned int y0 = y;
  252. unsigned int x1 = x0 + width - 1;
  253. unsigned int y1 = y0 + height - 1;
  254. unsigned char x0_MSB = ((x0>>8)&0xFF);
  255. unsigned char x0_LSB = (x0&0xFF);
  256. unsigned char x1_MSB = ((x1>>8)&0xFF);
  257. unsigned char x1_LSB = (x1&0xFF);
  258. unsigned char y0_MSB = ((y0>>8)&0xFF);
  259. unsigned char y0_LSB = (y0&0xFF);
  260. unsigned char y1_MSB = ((y1>>8)&0xFF);
  261. unsigned char y1_LSB = (y1&0xFF);
  262. unsigned int data_array[16];
  263. data_array[0] = 0x00053902;
  264. data_array[1] = (x1_MSB<<24)|(x0_LSB<<16)|(x0_MSB<<8)|0x2a;
  265. data_array[2] = (x1_LSB);
  266. dsi_set_cmdq(data_array, 3, 1);
  267. data_array[0] = 0x00053902;
  268. data_array[1] = (y1_MSB<<24)|(y0_LSB<<16)|(y0_MSB<<8)|0x2b;
  269. data_array[2] = (y1_LSB);
  270. dsi_set_cmdq(data_array, 3, 1);
  271. data_array[0] = 0x002c3909;
  272. dsi_set_cmdq(data_array, 1, 0);
  273. }
  274. #endif
  275. #define LCM_ID_S6E3FA2_ID (0x030000) /* ID1:0x03 ID2: 0x00 ID3:0x00 */
  276. static unsigned int lcm_compare_id(void)
  277. {
  278. unsigned char buffer[3] = {0};
  279. unsigned int array[16];
  280. unsigned int lcd_id = 0;
  281. SET_RESET_PIN(1);
  282. MDELAY(20);
  283. SET_RESET_PIN(0);
  284. MDELAY(20);
  285. SET_RESET_PIN(1);
  286. MDELAY(150);
  287. array[0] = 0x00033700; /*read id return two byte, version and id */
  288. dsi_set_cmdq(array, 1, 1);
  289. read_reg_v2(0x04, buffer, 3);
  290. MDELAY(20);
  291. lcd_id = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
  292. #ifdef BUILD_LK
  293. dprintf(0, "%s, LK s6e3ha3 debug: s6e3ha3 id = 0x%08x\n", __func__, lcd_id);
  294. #else
  295. pr_debug("%s, kernel s6e3ha3 horse debug: s6e3ha3 id = 0x%08x\n", __func__, lcd_id);
  296. #endif
  297. if (lcd_id == LCM_ID_S6E3FA2_ID)
  298. return 1;
  299. else
  300. return 0;
  301. }
  302. static void lcm_setbacklight_cmdq(void *handle, unsigned int level)
  303. {
  304. /* Refresh value of backlight level. */
  305. unsigned int cmd_1 = 0x51;
  306. unsigned int count_1 = 1;
  307. unsigned int value_1 = level;
  308. #if (LCM_DSI_CMD_MODE) /* NOP */
  309. unsigned int cmd = 0x00;
  310. unsigned int count = 0;
  311. unsigned int value = 0x00;
  312. dsi_set_cmd_by_cmdq_dual(handle, cmd, count, &value, 1);
  313. #endif
  314. #ifdef BUILD_LK
  315. dprintf(0, "%s,lk s6e3ha3 brightness: level = %d\n", __func__, level);
  316. #else
  317. pr_debug("%s, kernel s6e3ha3 brightness: level = %d\n", __func__, level);
  318. #endif
  319. dsi_set_cmd_by_cmdq_dual(handle, cmd_1, count_1, &value_1, 1);
  320. }
  321. LCM_DRIVER s6e3ha3_wqhd_2k_cmd_lcm_drv = {
  322. .name = "s6e3ha3_wqhd_2k_cmd",
  323. .set_util_funcs = lcm_set_util_funcs,
  324. .get_params = lcm_get_params,
  325. .init = lcm_init,
  326. .suspend = lcm_suspend,
  327. .resume = lcm_resume,
  328. .set_backlight_cmdq = lcm_setbacklight_cmdq,
  329. .compare_id = lcm_compare_id,
  330. #if (LCM_DSI_CMD_MODE)
  331. .update = lcm_update,
  332. #endif
  333. };