cpt_clap070wp03xg_sn65dsi83.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. #ifndef BUILD_LK
  2. #include <linux/string.h>
  3. #include <linux/regulator/consumer.h>
  4. #include <linux/device.h>
  5. #include <linux/platform_device.h>
  6. #include <linux/slab.h>
  7. #include <linux/pinctrl/consumer.h>
  8. #include <linux/fs.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/io.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/syscore_ops.h>
  16. #include <linux/timer.h>
  17. #include <linux/types.h>
  18. #include <linux/sched.h>
  19. #include <linux/of.h>
  20. #include <linux/of_device.h>
  21. #include <linux/regulator/consumer.h>
  22. #include <linux/gpio.h>
  23. #else
  24. #include <string.h>
  25. #endif
  26. #ifdef BUILD_LK
  27. #include <platform/mt_gpio.h>
  28. #include <platform/mt_i2c.h>
  29. #include <platform/mt_pmic.h>
  30. #include "ddp_hal.h"
  31. #else
  32. #include "sn65dsi83_i2c.h"
  33. #endif
  34. #include "lcm_drv.h"
  35. #include "cpt_clap070wp03xg_sn65dsi83.h"
  36. #define LVDS_PANEL_8BITS_SUPPORT
  37. /* --------------------------------------------------------------------------- */
  38. /* Local Constants */
  39. /* --------------------------------------------------------------------------- */
  40. #define FRAME_WIDTH (800)
  41. #define FRAME_HEIGHT (1280)
  42. #define GPIO_OUT_ONE 1
  43. #define GPIO_OUT_ZERO 0
  44. #define SN65DSI_DEBUG /* for check system(bb dsi and ti chip) status */
  45. /* --------------------------------------------------------------------------- */
  46. /* Local Variables */
  47. /* --------------------------------------------------------------------------- */
  48. static LCM_UTIL_FUNCS lcm_util = {
  49. .set_reset_pin = NULL,
  50. .udelay = NULL,
  51. .mdelay = NULL,
  52. };
  53. unsigned int GPIO_LCD_PWR_EN;
  54. unsigned int GPIO_LCD_PWR2_EN;
  55. unsigned int GPIO_LCD_RST_EN;
  56. unsigned int GPIO_LCD_STB_EN;
  57. unsigned int GPIO_LCD_BRIDGE_EN;
  58. #define SET_RESET_PIN(v) (mt_set_reset_pin((v)))
  59. #define UDELAY(n) (lcm_util.udelay(n))
  60. #define MDELAY(n) (lcm_util.mdelay(n))
  61. #define REGFLAG_DELAY 0xAB
  62. /* --------------------------------------------------------------------------- */
  63. /* Local Functions */
  64. /* --------------------------------------------------------------------------- */
  65. /* sn65dis83 chip init table */
  66. static sn65dsi8x_setting_table sn65dis83_init_table[] = {
  67. #if defined(LVDS_PANEL_8BITS_SUPPORT)
  68. {0x09, 0x00},
  69. {0x0A, 0x05},
  70. {0x0B, 0x10},
  71. {0x0D, 0x00},
  72. {0x10, 0x26},
  73. {0x11, 0x00},
  74. {0x12, 0x2c},
  75. {0x13, 0x00},
  76. {0x18, 0x78},
  77. {0x19, 0x00},
  78. {0x1A, 0x03},
  79. {0x1B, 0x00},
  80. {0x20, 0x20},
  81. {0x21, 0x03},
  82. {0x22, 0x00},
  83. {0x23, 0x00},
  84. {0x24, 0x00},
  85. {0x25, 0x00}, /* 0x00 */
  86. {0x26, 0x00},
  87. {0x27, 0x00},
  88. {0x28, 0x21},
  89. {0x29, 0x00},
  90. {0x2A, 0x00},
  91. {0x2B, 0x00},
  92. {0x2C, 0x0a},
  93. {0x2D, 0x00},
  94. {0x2E, 0x00},
  95. {0x2F, 0x00},
  96. {0x30, 0x02},
  97. {0x31, 0x00},
  98. {0x32, 0x00},
  99. {0x33, 0x00},
  100. {0x34, 0x18},
  101. {0x35, 0x00},
  102. {0x36, 0x00}, /* 0x00 */
  103. {0x37, 0x00},
  104. {0x38, 0x00}, /* 0x00 */
  105. {0x39, 0x00},
  106. {0x3A, 0x00}, /* 0x00 */
  107. {0x3B, 0x00},
  108. {0x3C, 0x00}, /* 0x00 */
  109. {0x3D, 0x00},
  110. {0x3E, 0x00},
  111. {0x0D, 0x01},
  112. {REGFLAG_DELAY, 0x0a},
  113. {0x09, 0x01},
  114. {0xFF, 0x00},
  115. #endif
  116. };
  117. static void push_table(sn65dsi8x_setting_table *table, unsigned int count)
  118. {
  119. unsigned int i;
  120. for (i = 0; i < count; i++) {
  121. unsigned cmd;
  122. cmd = table[i].cmd;
  123. switch (cmd) {
  124. case REGFLAG_DELAY:
  125. MDELAY(table[i].data);
  126. break;
  127. case 0xFF:
  128. break;
  129. default:
  130. #ifdef BUILD_LK
  131. sn65dsi83_write_byte(cmd, table[i].data);
  132. #else
  133. sn65dsi83_write_byte(cmd, table[i].data);
  134. #endif
  135. }
  136. }
  137. }
  138. #ifdef SN65DSI_DEBUG
  139. static void dump_reg_table(sn65dsi8x_setting_table *table, unsigned int count)
  140. {
  141. unsigned int i;
  142. unsigned char data;
  143. for (i = 0; i < count; i++) {
  144. unsigned cmd;
  145. cmd = table[i].cmd;
  146. switch (cmd) {
  147. case REGFLAG_DELAY:
  148. MDELAY(table[i].data);
  149. break;
  150. case 0xFF:
  151. break;
  152. default:
  153. #ifdef BUILD_LK
  154. sn65dsi83_read_byte(cmd, &data);
  155. printf("dump cmd=0x%x data=0x%x\n", cmd, data);
  156. #else
  157. sn65dsi83_read_byte(cmd, &data);
  158. pr_debug("dump cmd=0x%x data=0x%x\n", cmd, data);
  159. #endif
  160. }
  161. }
  162. }
  163. #endif
  164. void init_sn65dsi8x(void)
  165. {
  166. #ifdef SN65DSI_DEBUG
  167. unsigned char data;
  168. #endif
  169. push_table(sn65dis83_init_table,
  170. sizeof(sn65dis83_init_table) / sizeof(sn65dsi8x_setting_table));
  171. #ifdef SN65DSI_DEBUG
  172. sn65dsi83_write_byte(0xe0, 1);
  173. sn65dsi83_write_byte(0xe1, 0xff);
  174. MDELAY(5);
  175. sn65dsi83_read_byte(0xe5, &data);
  176. #ifdef BUILD_LK
  177. printf("dump cmd=0xe5 data=0x%x\n", data);
  178. #else
  179. pr_debug("dump cmd=0xe5 data=0x%x\n", data);
  180. #endif
  181. dump_reg_table(sn65dis83_init_table,
  182. sizeof(sn65dis83_init_table) / sizeof(sn65dsi8x_setting_table));
  183. #endif
  184. }
  185. /* --------------------------------------------------------------------------- */
  186. /* LCM Driver Implementations */
  187. /* --------------------------------------------------------------------------- */
  188. static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
  189. {
  190. memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
  191. }
  192. static void lcm_get_params(LCM_PARAMS *params)
  193. {
  194. memset(params, 0, sizeof(LCM_PARAMS));
  195. params->type = LCM_TYPE_DSI;
  196. params->width = FRAME_WIDTH;
  197. params->height = FRAME_HEIGHT;
  198. params->dsi.mode = SYNC_EVENT_VDO_MODE;
  199. /* DSI */
  200. /* Command mode setting */
  201. params->dsi.LANE_NUM = LCM_FOUR_LANE;
  202. /* The following defined the fomat for data coming from LCD engine. */
  203. #if defined(LVDS_PANEL_8BITS_SUPPORT)
  204. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
  205. #else
  206. params->dsi.data_format.format = LCM_DSI_FORMAT_RGB666;
  207. #endif
  208. params->dsi.word_count = FRAME_WIDTH * 3;
  209. params->dsi.vertical_sync_active = 2;
  210. params->dsi.vertical_backporch = 2;
  211. params->dsi.vertical_frontporch = 4;
  212. params->dsi.vertical_active_line = FRAME_HEIGHT;
  213. params->dsi.horizontal_sync_active = 10;
  214. params->dsi.horizontal_backporch = 24;
  215. params->dsi.horizontal_frontporch = 30;
  216. params->dsi.horizontal_active_pixel = FRAME_WIDTH;
  217. #if defined(LVDS_PANEL_8BITS_SUPPORT)
  218. params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;
  219. #else
  220. params->dsi.PS = LCM_PACKED_PS_18BIT_RGB666;
  221. #endif
  222. params->dsi.pll_select = 0; /* 0: MIPI_PLL; 1: LVDS_PLL */
  223. params->dsi.PLL_CLOCK = 224;
  224. params->dsi.cont_clock = 1;
  225. }
  226. static void lcm_set_gpio_output(unsigned int GPIO, unsigned int output)
  227. {
  228. if (GPIO == 0xFFFFFFFF) {
  229. #ifdef BUILD_LK
  230. printf("[LK/LCM] GPIO_LCD_PWR_EN = 0x%x\n", GPIO_LCD_PWR_EN);
  231. printf("[LK/LCM] GPIO_LCD_PWR2_EN = 0x%x\n", GPIO_LCD_PWR2_EN);
  232. printf("[LK/LCM] GPIO_LCD_RST_EN = 0x%x\n", GPIO_LCD_RST_EN);
  233. printf("[LK/LCM] GPIO_LCD_STB_EN = 0x%x\n", GPIO_LCD_STB_EN);
  234. printf("[LK/LCM] GPIO_LCD_BRIDGE_EN = 0x%x\n", GPIO_LCD_BRIDGE_EN);
  235. #endif
  236. return;
  237. }
  238. #ifdef BUILD_LK
  239. mt_set_gpio_mode(GPIO, GPIO_MODE_00);
  240. mt_set_gpio_dir(GPIO, GPIO_DIR_OUT);
  241. mt_set_gpio_out(GPIO, (output > 0) ? GPIO_OUT_ONE : GPIO_OUT_ZERO);
  242. #else
  243. gpio_set_value(GPIO, (output > 0) ? GPIO_OUT_ONE : GPIO_OUT_ZERO);
  244. #endif
  245. }
  246. static void lcm_init(void)
  247. {
  248. #ifdef BUILD_LK
  249. printf("[LK/LCM]lcm_init\n");
  250. /* step1: sn65dsi8x enbable and init */
  251. /* GPIO42 VDD18_LVDS for SN65DSI83 power */
  252. lcm_set_gpio_output(GPIO_LCD_PWR2_EN, GPIO_OUT_ONE);
  253. MDELAY(20);
  254. /* GPIO127 LVDS_EN_R for SN65DSI83 */
  255. lcm_set_gpio_output(GPIO_LCD_BRIDGE_EN, GPIO_OUT_ONE);
  256. MDELAY(5);
  257. lcm_set_gpio_output(GPIO_LCD_BRIDGE_EN, GPIO_OUT_ZERO);
  258. MDELAY(20);
  259. lcm_set_gpio_output(GPIO_LCD_BRIDGE_EN, GPIO_OUT_ONE);
  260. MDELAY(50);
  261. DSI_clk_HS_mode(0, NULL, 1);
  262. MDELAY(5);
  263. init_sn65dsi8x();
  264. MDELAY(10);
  265. /* step 2 :lvds lcd init */
  266. /* GPIO131 VDD33_LCD */
  267. lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ONE);
  268. MDELAY(50);
  269. /* VGP6_PMU AVDDVGH/VGL/VCOM for panel power */
  270. upmu_set_rg_vgp6_vosel(0x7);
  271. upmu_set_rg_vgp6_sw_en(0x1);
  272. /* GPIO103 LCM_RST for panel */
  273. lcm_set_gpio_output(GPIO_LCD_RST_EN, GPIO_OUT_ZERO);
  274. MDELAY(50);
  275. /* GPIO102 LCM_STBY_2V8 for panel */
  276. lcm_set_gpio_output(GPIO_LCD_STB_EN, GPIO_OUT_ONE);
  277. #elif (defined BUILD_UBOOT)
  278. #else
  279. pr_debug("[Kernel/LCM]lcm_init\n");
  280. DSI_clk_HS_mode(0, NULL, 1);
  281. #endif
  282. }
  283. static void lcm_suspend(void)
  284. {
  285. #ifdef BUILD_LK
  286. printf("[LK/LCM]lcm_suspend enter\n");
  287. #else
  288. unsigned char temp;
  289. pr_debug("[Kernel/LCM]lcm_suspend enter\n");
  290. lcm_set_gpio_output(GPIO_LCD_PWR2_EN, GPIO_OUT_ZERO);
  291. MDELAY(30); /* avoid LCD resume transint */
  292. /* step 1 power down lvds lcd */
  293. lcm_set_gpio_output(GPIO_LCD_BRIDGE_EN, GPIO_OUT_ZERO);
  294. MDELAY(10);
  295. /* LCMBIASON :VGH VHL */
  296. lcm_vgp_supply_enable();
  297. MDELAY(20);
  298. lcm_vgp_supply_disable();
  299. MDELAY(20);
  300. lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ZERO); /* LCM VCC :enable LCD VCC */
  301. MDELAY(20);
  302. lcm_set_gpio_output(GPIO_LCD_STB_EN, GPIO_OUT_ZERO);
  303. MDELAY(20);
  304. lcm_set_gpio_output(GPIO_LCD_RST_EN, GPIO_OUT_ZERO); /* LCM_STBY */
  305. MDELAY(50);
  306. /* step 2 suspend sn65dsi8x */
  307. sn65dsi83_read_byte(0x0a, &temp); /* for test wether ti lock the pll clok */
  308. pr_debug("lcm_suspend 0x0a value=0x%x\n", temp);
  309. sn65dsi83_read_byte(0x0d, &temp);
  310. pr_debug("lcm_suspend 0x0d value=0x%x\n", temp);
  311. sn65dsi83_write_byte(0x0d, (temp & 0xfe)); /* set bit0: 0 */
  312. /* step 3 set dsi LP mode */
  313. DSI_clk_HS_mode(0, NULL, 0);
  314. #endif
  315. }
  316. static void lcm_resume(void)
  317. {
  318. #ifdef BUILD_LK
  319. printf("[LK/LCM]lcm_resume enter\n");
  320. #else
  321. #ifdef SN65DSI_DEBUG
  322. unsigned char temp;
  323. #endif
  324. pr_debug("[Kernel/LCM]lcm_resume enter\n");
  325. DSI_clk_HS_mode(0, NULL, 1);
  326. MDELAY(50);
  327. /* step 1 resume sn65dsi8x */
  328. lcm_set_gpio_output(GPIO_LCD_PWR2_EN, GPIO_OUT_ONE);
  329. MDELAY(10);
  330. lcm_set_gpio_output(GPIO_LCD_BRIDGE_EN, GPIO_OUT_ONE);
  331. MDELAY(5);
  332. lcm_set_gpio_output(GPIO_LCD_BRIDGE_EN, GPIO_OUT_ZERO);
  333. MDELAY(20);
  334. lcm_set_gpio_output(GPIO_LCD_BRIDGE_EN, GPIO_OUT_ONE);
  335. MDELAY(10);
  336. init_sn65dsi8x();
  337. MDELAY(10);
  338. #ifdef SN65DSI_DEBUG
  339. sn65dsi83_read_byte(0x0a, &temp);
  340. pr_debug("lcm_resume cmd-- 0x0a=0x%x\n", temp);
  341. sn65dsi83_read_byte(0x0d, &temp);
  342. pr_debug("lcm_resume cmd-- 0x0d=0x%x\n", temp);
  343. sn65dsi83_read_byte(0x09, &temp);
  344. pr_debug("lcm_resume cmd-- 0x09=0x%x\n", temp);
  345. #endif
  346. /* step 2 resume lvds */
  347. lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ONE);
  348. MDELAY(50);
  349. /* hwPowerOn(MT65XX_POWER_LDO_VGP6, VOL_3300, "LCM"); */
  350. lcm_vgp_supply_enable();
  351. MDELAY(30);
  352. lcm_set_gpio_output(GPIO_LCD_RST_EN, GPIO_OUT_ONE);
  353. MDELAY(5);
  354. lcm_set_gpio_output(GPIO_LCD_STB_EN, GPIO_OUT_ONE);
  355. MDELAY(5);
  356. #endif
  357. }
  358. static unsigned int lcm_compare_id(void)
  359. {
  360. #if defined(BUILD_LK)
  361. printf("Sn65dsi83 lcm_compare_id enter\n");
  362. #endif
  363. return 1;
  364. }
  365. LCM_DRIVER cpt_clap070wp03xg_sn65dsi83_lcm_drv = {
  366. .name = "cpt_clap070wp03xg_sn65dsi83",
  367. .set_util_funcs = lcm_set_util_funcs,
  368. .get_params = lcm_get_params,
  369. .init = lcm_init,
  370. .suspend = lcm_suspend,
  371. .resume = lcm_resume,
  372. .compare_id = lcm_compare_id,
  373. };