CLAA101FP01_DSI_VDO.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. #ifdef BUILD_LK
  32. #include <platform/mt_gpio.h>
  33. #include <platform/mt_i2c.h>
  34. #include <platform/mt_pmic.h>
  35. #include <string.h>
  36. #else
  37. #include <linux/string.h>
  38. #include <linux/wait.h>
  39. #include <linux/platform_device.h>
  40. #include <linux/gpio.h>
  41. #include <linux/pinctrl/consumer.h>
  42. #include <linux/of_gpio.h>
  43. #include <asm-generic/gpio.h>
  44. #include <linux/kernel.h>
  45. #include <linux/mm.h>
  46. #include <linux/mm_types.h>
  47. #include <linux/module.h>
  48. #include <linux/types.h>
  49. #include <linux/slab.h>
  50. #include <linux/vmalloc.h>
  51. #ifdef CONFIG_OF
  52. #include <linux/of.h>
  53. #include <linux/of_irq.h>
  54. #include <linux/of_address.h>
  55. #include <linux/of_device.h>
  56. #include <linux/regulator/consumer.h>
  57. #include <linux/clk.h>
  58. #endif
  59. #endif
  60. #include "lcm_drv.h"
  61. /* --------------------------------------------------------------------------- */
  62. /* Local Constants */
  63. /* --------------------------------------------------------------------------- */
  64. #define FRAME_WIDTH (1920)
  65. #define FRAME_HEIGHT (1200)
  66. /* --------------------------------------------------------------------------- */
  67. /* Local Variables */
  68. /* --------------------------------------------------------------------------- */
  69. static LCM_UTIL_FUNCS lcm_util = { 0 };
  70. #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
  71. #define UDELAY(n) (lcm_util.udelay(n))
  72. #define MDELAY(n) (lcm_util.mdelay(n))
  73. /* --------------------------------------------------------------------------- */
  74. /* Local Functions */
  75. /* --------------------------------------------------------------------------- */
  76. #define dsi_set_cmdq_V2(cmd, count, ppara, force_update)lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
  77. #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
  78. #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
  79. #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
  80. #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
  81. #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
  82. #define LCM_DSI_CMD_MODE 0
  83. static void lcm_init_power(void)
  84. {
  85. }
  86. static void lcm_suspend_power(void)
  87. {
  88. }
  89. static void lcm_resume_power(void)
  90. {
  91. }
  92. /* --------------------------------------------------------------------------- */
  93. /* LCM Driver Implementations */
  94. /* --------------------------------------------------------------------------- */
  95. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  96. {
  97. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  98. }
  99. static void lcm_get_params(LCM_PARAMS *params)
  100. {
  101. memset(params, 0, sizeof(LCM_PARAMS));
  102. params->type = LCM_TYPE_DSI;
  103. params->width = FRAME_WIDTH;
  104. params->height = FRAME_HEIGHT;
  105. #if (LCM_DSI_CMD_MODE)
  106. params->dsi.mode = CMD_MODE;
  107. #else
  108. params->dsi.mode = SYNC_EVENT_VDO_MODE;
  109. #endif
  110. params->dsi.LANE_NUM = LCM_FOUR_LANE;
  111. params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
  112. params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
  113. params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
  114. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  115. params->dsi.packet_size = 256;
  116. params->dsi.intermediat_buffer_num = 0;
  117. params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;
  118. params->dsi.word_count = FRAME_WIDTH*3;
  119. params->dsi.vertical_sync_active = 4;
  120. params->dsi.vertical_backporch = 20;
  121. params->dsi.vertical_frontporch = 15;
  122. params->dsi.vertical_active_line = FRAME_HEIGHT;
  123. params->dsi.horizontal_sync_active = 40;
  124. params->dsi.horizontal_backporch = 80;
  125. params->dsi.horizontal_frontporch = 80;
  126. params->dsi.horizontal_active_pixel = FRAME_WIDTH;
  127. params->dsi.PLL_CLOCK = 481;
  128. params->dsi.null_packet_en = TRUE;
  129. params->dsi.lane_swap_en = 1;
  130. params->dsi.lane_swap[MIPITX_PHY_PORT_0][MIPITX_PHY_LANE_CK] = MIPITX_PHY_LANE_CK;
  131. params->dsi.lane_swap[MIPITX_PHY_PORT_0][MIPITX_PHY_LANE_0] = MIPITX_PHY_LANE_0;
  132. params->dsi.lane_swap[MIPITX_PHY_PORT_0][MIPITX_PHY_LANE_1] = MIPITX_PHY_LANE_1;
  133. params->dsi.lane_swap[MIPITX_PHY_PORT_0][MIPITX_PHY_LANE_2] = MIPITX_PHY_LANE_2;
  134. params->dsi.lane_swap[MIPITX_PHY_PORT_0][MIPITX_PHY_LANE_3] = MIPITX_PHY_LANE_3;
  135. params->dsi.lane_swap[MIPITX_PHY_PORT_0][MIPITX_PHY_LANE_RX] = MIPITX_PHY_LANE_0;
  136. }
  137. static void lcm_init(void)
  138. {
  139. #ifdef BUILD_LK
  140. printf("[LK/LCM] lcm_init() enter\n");
  141. SET_RESET_PIN(1);
  142. MDELAY(20);
  143. SET_RESET_PIN(0);
  144. MDELAY(20);
  145. SET_RESET_PIN(1);
  146. MDELAY(20);
  147. #else
  148. pr_debug("[Kernel/LCM] lcm_init() enter\n");
  149. #endif
  150. }
  151. void lcm_suspend(void)
  152. {
  153. #ifdef BUILD_LK
  154. printf("[LK/LCM] lcm_suspend() enter\n");
  155. SET_RESET_PIN(1);
  156. MDELAY(10);
  157. SET_RESET_PIN(0);
  158. MDELAY(10);
  159. #else
  160. pr_debug("[Kernel/LCM] lcm_suspend() enter\n");
  161. SET_RESET_PIN(1);
  162. MDELAY(10);
  163. SET_RESET_PIN(0);
  164. MDELAY(10);
  165. #endif
  166. }
  167. void lcm_resume(void)
  168. {
  169. #ifdef BUILD_LK
  170. printf("[LK/LCM] lcm_resume() enter\n");
  171. SET_RESET_PIN(1);
  172. MDELAY(20);
  173. SET_RESET_PIN(0);
  174. MDELAY(20);
  175. SET_RESET_PIN(1);
  176. MDELAY(20);
  177. #else
  178. pr_debug("[Kernel/LCM] lcm_resume() enter\n");
  179. SET_RESET_PIN(1);
  180. MDELAY(20);
  181. SET_RESET_PIN(0);
  182. MDELAY(20);
  183. SET_RESET_PIN(1);
  184. MDELAY(20);
  185. #endif
  186. }
  187. #if (LCM_DSI_CMD_MODE)
  188. static void lcm_update(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
  189. {
  190. unsigned int x0 = x;
  191. unsigned int y0 = y;
  192. unsigned int x1 = x0 + width - 1;
  193. unsigned int y1 = y0 + height - 1;
  194. unsigned char x0_MSB = ((x0 >> 8) & 0xFF);
  195. unsigned char x0_LSB = (x0 & 0xFF);
  196. unsigned char x1_MSB = ((x1 >> 8) & 0xFF);
  197. unsigned char x1_LSB = (x1 & 0xFF);
  198. unsigned char y0_MSB = ((y0 >> 8) & 0xFF);
  199. unsigned char y0_LSB = (y0 & 0xFF);
  200. unsigned char y1_MSB = ((y1 >> 8) & 0xFF);
  201. unsigned char y1_LSB = (y1 & 0xFF);
  202. unsigned int data_array[16];
  203. data_array[0] = 0x00053902;
  204. data_array[1] = (x1_MSB << 24) | (x0_LSB << 16) | (x0_MSB << 8) | 0x2a;
  205. data_array[2] = (x1_LSB);
  206. dsi_set_cmdq(data_array, 3, 1);
  207. data_array[0] = 0x00053902;
  208. data_array[1] = (y1_MSB << 24) | (y0_LSB << 16) | (y0_MSB << 8) | 0x2b;
  209. data_array[2] = (y1_LSB);
  210. dsi_set_cmdq(data_array, 3, 1);
  211. data_array[0] = 0x00290508;
  212. dsi_set_cmdq(data_array, 1, 1);
  213. data_array[0] = 0x002c3909;
  214. dsi_set_cmdq(data_array, 1, 0);
  215. }
  216. #endif
  217. LCM_DRIVER claa101fp01_dsi_vdo_lcm_drv = {
  218. .name = "CLAA101FP01_DSI_VDO",
  219. .set_util_funcs = lcm_set_util_funcs,
  220. .get_params = lcm_get_params,
  221. .init = lcm_init,
  222. .suspend = lcm_suspend,
  223. .resume = lcm_resume,
  224. .init_power = lcm_init_power,
  225. .resume_power = lcm_resume_power,
  226. .suspend_power = lcm_suspend_power,
  227. #if (LCM_DSI_CMD_MODE)
  228. .update = lcm_update,
  229. #endif
  230. };