mipi_toshiba.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /* Copyright (c) 2008-2012, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include "msm_fb.h"
  14. #include "mipi_dsi.h"
  15. #include "mipi_toshiba.h"
  16. static struct pwm_device *bl_lpm;
  17. static struct mipi_dsi_panel_platform_data *mipi_toshiba_pdata;
  18. #define TM_GET_PID(id) (((id) & 0xff00)>>8)
  19. static struct dsi_buf toshiba_tx_buf;
  20. static struct dsi_buf toshiba_rx_buf;
  21. static int mipi_toshiba_lcd_init(void);
  22. #ifdef TOSHIBA_CMDS_UNUSED
  23. static char one_lane[3] = {0xEF, 0x60, 0x62};
  24. static char dmode_wqvga[2] = {0xB3, 0x01};
  25. static char intern_wr_clk1_wqvga[3] = {0xef, 0x2f, 0x22};
  26. static char intern_wr_clk2_wqvga[3] = {0xef, 0x6e, 0x33};
  27. static char hor_addr_2A_wqvga[5] = {0x2A, 0x00, 0x00, 0x00, 0xef};
  28. static char hor_addr_2B_wqvga[5] = {0x2B, 0x00, 0x00, 0x01, 0xaa};
  29. static char if_sel_cmd[2] = {0x53, 0x00};
  30. #endif
  31. static char exit_sleep[2] = {0x11, 0x00};
  32. static char display_on[2] = {0x29, 0x00};
  33. static char display_off[2] = {0x28, 0x00};
  34. static char enter_sleep[2] = {0x10, 0x00};
  35. static char mcap_off[2] = {0xb2, 0x00};
  36. static char ena_test_reg[3] = {0xEF, 0x01, 0x01};
  37. static char two_lane[3] = {0xEF, 0x60, 0x63};
  38. static char non_burst_sync_pulse[3] = {0xef, 0x61, 0x09};
  39. static char dmode_wvga[2] = {0xB3, 0x00};
  40. static char intern_wr_clk1_wvga[3] = {0xef, 0x2f, 0xcc};
  41. static char intern_wr_clk2_wvga[3] = {0xef, 0x6e, 0xdd};
  42. static char hor_addr_2A_wvga[5] = {0x2A, 0x00, 0x00, 0x01, 0xdf};
  43. static char hor_addr_2B_wvga[5] = {0x2B, 0x00, 0x00, 0x03, 0x55};
  44. static char if_sel_video[2] = {0x53, 0x01};
  45. static struct dsi_cmd_desc toshiba_wvga_display_on_cmds[] = {
  46. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(mcap_off), mcap_off},
  47. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(ena_test_reg), ena_test_reg},
  48. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(two_lane), two_lane},
  49. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(non_burst_sync_pulse),
  50. non_burst_sync_pulse},
  51. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(dmode_wvga), dmode_wvga},
  52. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(intern_wr_clk1_wvga),
  53. intern_wr_clk1_wvga},
  54. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(intern_wr_clk2_wvga),
  55. intern_wr_clk2_wvga},
  56. {DTYPE_DCS_LWRITE, 1, 0, 0, 0, sizeof(hor_addr_2A_wvga),
  57. hor_addr_2A_wvga},
  58. {DTYPE_DCS_LWRITE, 1, 0, 0, 0, sizeof(hor_addr_2B_wvga),
  59. hor_addr_2B_wvga},
  60. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(if_sel_video), if_sel_video},
  61. {DTYPE_DCS_WRITE, 1, 0, 0, 0, sizeof(exit_sleep), exit_sleep},
  62. {DTYPE_DCS_WRITE, 1, 0, 0, 0, sizeof(display_on), display_on}
  63. };
  64. static char mcap_start[2] = {0xb0, 0x04};
  65. static char num_out_pixelform[3] = {0xb3, 0x00, 0x87};
  66. static char dsi_ctrl[3] = {0xb6, 0x30, 0x83};
  67. static char panel_driving[7] = {0xc0, 0x01, 0x00, 0x85, 0x00, 0x00, 0x00};
  68. static char dispV_timing[5] = {0xc1, 0x00, 0x10, 0x00, 0x01};
  69. static char dispCtrl[3] = {0xc3, 0x00, 0x19};
  70. static char test_mode_c4[2] = {0xc4, 0x03};
  71. static char dispH_timing[15] = {
  72. /* TYPE_DCS_LWRITE */
  73. 0xc5, 0x00, 0x01, 0x05,
  74. 0x04, 0x5e, 0x00, 0x00,
  75. 0x00, 0x00, 0x0b, 0x17,
  76. 0x05, 0x00, 0x00
  77. };
  78. static char test_mode_c6[2] = {0xc6, 0x00};
  79. static char gamma_setA[13] = {
  80. 0xc8, 0x0a, 0x15, 0x18,
  81. 0x1b, 0x1c, 0x0d, 0x00,
  82. 0x00, 0x00, 0x00, 0x00,
  83. 0x00
  84. };
  85. static char gamma_setB[13] = {
  86. 0xc9, 0x0d, 0x1d, 0x1f,
  87. 0x1f, 0x1f, 0x10, 0x00,
  88. 0x00, 0x00, 0x00, 0x00,
  89. 0x00
  90. };
  91. static char gamma_setC[13] = {
  92. 0xca, 0x1e, 0x1f, 0x1e,
  93. 0x1d, 0x1d, 0x10, 0x00,
  94. 0x00, 0x00, 0x00, 0x00,
  95. 0x00
  96. };
  97. static char powerSet_ChrgPmp[5] = {0xd0, 0x02, 0x00, 0xa3, 0xb8};
  98. static char testMode_d1[6] = {0xd1, 0x10, 0x14, 0x53, 0x64, 0x00};
  99. static char powerSet_SrcAmp[3] = {0xd2, 0xb3, 0x00};
  100. static char powerInt_PS[3] = {0xd3, 0x33, 0x03};
  101. static char vreg[2] = {0xd5, 0x00};
  102. static char test_mode_d6[2] = {0xd6, 0x01};
  103. static char timingCtrl_d7[9] = {
  104. 0xd7, 0x09, 0x00, 0x84,
  105. 0x81, 0x61, 0xbc, 0xb5,
  106. 0x05
  107. };
  108. static char timingCtrl_d8[7] = {
  109. 0xd8, 0x04, 0x25, 0x90,
  110. 0x4c, 0x92, 0x00
  111. };
  112. static char timingCtrl_d9[4] = {0xd9, 0x5b, 0x7f, 0x05};
  113. static char white_balance[6] = {0xcb, 0x00, 0x00, 0x00, 0x1c, 0x00};
  114. static char vcs_settings[2] = {0xdd, 0x53};
  115. static char vcom_dc_settings[2] = {0xde, 0x43};
  116. static char testMode_e3[5] = {0xe3, 0x00, 0x00, 0x00, 0x00};
  117. static char testMode_e4[6] = {0xe4, 0x00, 0x00, 0x22, 0xaa, 0x00};
  118. static char testMode_e5[2] = {0xe5, 0x00};
  119. static char testMode_fa[4] = {0xfa, 0x00, 0x00, 0x00};
  120. static char testMode_fd[5] = {0xfd, 0x00, 0x00, 0x00, 0x00};
  121. static char testMode_fe[5] = {0xfe, 0x00, 0x00, 0x00, 0x00};
  122. static char mcap_end[2] = {0xb0, 0x03};
  123. static char set_add_mode[2] = {0x36, 0x0};
  124. static char set_pixel_format[2] = {0x3a, 0x70};
  125. static struct dsi_cmd_desc toshiba_wsvga_display_on_cmds[] = {
  126. {DTYPE_GEN_WRITE2, 1, 0, 0, 10, sizeof(mcap_start), mcap_start},
  127. {DTYPE_GEN_LWRITE, 1, 0, 0, 10, sizeof(num_out_pixelform),
  128. num_out_pixelform},
  129. {DTYPE_GEN_LWRITE, 1, 0, 0, 10, sizeof(dsi_ctrl), dsi_ctrl},
  130. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(panel_driving), panel_driving},
  131. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(dispV_timing), dispV_timing},
  132. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(dispCtrl), dispCtrl},
  133. {DTYPE_GEN_WRITE2, 1, 0, 0, 0, sizeof(test_mode_c4), test_mode_c4},
  134. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(dispH_timing), dispH_timing},
  135. {DTYPE_GEN_WRITE2, 1, 0, 0, 0, sizeof(test_mode_c6), test_mode_c6},
  136. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(gamma_setA), gamma_setA},
  137. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(gamma_setB), gamma_setB},
  138. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(gamma_setC), gamma_setC},
  139. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(powerSet_ChrgPmp),
  140. powerSet_ChrgPmp},
  141. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(testMode_d1), testMode_d1},
  142. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(powerSet_SrcAmp),
  143. powerSet_SrcAmp},
  144. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(powerInt_PS), powerInt_PS},
  145. {DTYPE_GEN_WRITE2, 1, 0, 0, 0, sizeof(vreg), vreg},
  146. {DTYPE_GEN_WRITE2, 1, 0, 0, 0, sizeof(test_mode_d6), test_mode_d6},
  147. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(timingCtrl_d7), timingCtrl_d7},
  148. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(timingCtrl_d8), timingCtrl_d8},
  149. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(timingCtrl_d9), timingCtrl_d9},
  150. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(white_balance), white_balance},
  151. {DTYPE_GEN_WRITE2, 1, 0, 0, 0, sizeof(vcs_settings), vcs_settings},
  152. {DTYPE_GEN_WRITE2, 1, 0, 0, 0, sizeof(vcom_dc_settings),
  153. vcom_dc_settings},
  154. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(testMode_e3), testMode_e3},
  155. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(testMode_e4), testMode_e4},
  156. {DTYPE_GEN_WRITE2, 1, 0, 0, 0, sizeof(testMode_e5), testMode_e5},
  157. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(testMode_fa), testMode_fa},
  158. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(testMode_fd), testMode_fd},
  159. {DTYPE_GEN_LWRITE, 1, 0, 0, 0, sizeof(testMode_fe), testMode_fe},
  160. {DTYPE_GEN_WRITE2, 1, 0, 0, 0, sizeof(mcap_end), mcap_end},
  161. {DTYPE_DCS_WRITE1, 1, 0, 0, 0, sizeof(set_add_mode), set_add_mode},
  162. {DTYPE_DCS_WRITE1, 1, 0, 0, 0, sizeof(set_pixel_format),
  163. set_pixel_format},
  164. {DTYPE_DCS_WRITE, 1, 0, 0, 120, sizeof(exit_sleep), exit_sleep},
  165. {DTYPE_DCS_WRITE, 1, 0, 0, 50, sizeof(display_on), display_on}
  166. };
  167. static struct dsi_cmd_desc toshiba_display_off_cmds[] = {
  168. {DTYPE_DCS_WRITE, 1, 0, 0, 50, sizeof(display_off), display_off},
  169. {DTYPE_DCS_WRITE, 1, 0, 0, 120, sizeof(enter_sleep), enter_sleep}
  170. };
  171. static int mipi_toshiba_lcd_on(struct platform_device *pdev)
  172. {
  173. struct msm_fb_data_type *mfd;
  174. struct dcs_cmd_req cmdreq;
  175. mfd = platform_get_drvdata(pdev);
  176. if (!mfd)
  177. return -ENODEV;
  178. if (mfd->key != MFD_KEY)
  179. return -EINVAL;
  180. memset(&cmdreq, 0, sizeof(cmdreq));
  181. if (TM_GET_PID(mfd->panel.id) == MIPI_DSI_PANEL_WVGA_PT) {
  182. cmdreq.cmds = toshiba_wvga_display_on_cmds;
  183. cmdreq.cmds_cnt = ARRAY_SIZE(toshiba_wvga_display_on_cmds);
  184. cmdreq.flags = CMD_REQ_COMMIT;
  185. cmdreq.rlen = 0;
  186. cmdreq.cb = NULL;
  187. mipi_dsi_cmdlist_put(&cmdreq);
  188. } else if (TM_GET_PID(mfd->panel.id) == MIPI_DSI_PANEL_WSVGA_PT ||
  189. TM_GET_PID(mfd->panel.id) == MIPI_DSI_PANEL_WUXGA) {
  190. cmdreq.cmds = toshiba_wsvga_display_on_cmds;
  191. cmdreq.cmds_cnt = ARRAY_SIZE(toshiba_wsvga_display_on_cmds);
  192. cmdreq.flags = CMD_REQ_COMMIT;
  193. cmdreq.rlen = 0;
  194. cmdreq.cb = NULL;
  195. mipi_dsi_cmdlist_put(&cmdreq);
  196. } else
  197. return -EINVAL;
  198. return 0;
  199. }
  200. static int mipi_toshiba_lcd_off(struct platform_device *pdev)
  201. {
  202. struct msm_fb_data_type *mfd;
  203. struct dcs_cmd_req cmdreq;
  204. mfd = platform_get_drvdata(pdev);
  205. if (!mfd)
  206. return -ENODEV;
  207. if (mfd->key != MFD_KEY)
  208. return -EINVAL;
  209. memset(&cmdreq, 0, sizeof(cmdreq));
  210. cmdreq.cmds = toshiba_display_off_cmds;
  211. cmdreq.cmds_cnt = ARRAY_SIZE(toshiba_display_off_cmds);
  212. cmdreq.flags = CMD_REQ_COMMIT;
  213. cmdreq.rlen = 0;
  214. cmdreq.cb = NULL;
  215. mipi_dsi_cmdlist_put(&cmdreq);
  216. return 0;
  217. }
  218. static int mipi_toshiba_lcd_late_init(struct platform_device *pdev)
  219. {
  220. return 0;
  221. }
  222. void mipi_bklight_pwm_cfg(void)
  223. {
  224. if (mipi_toshiba_pdata && mipi_toshiba_pdata->dsi_pwm_cfg)
  225. mipi_toshiba_pdata->dsi_pwm_cfg();
  226. }
  227. static void mipi_toshiba_set_backlight(struct msm_fb_data_type *mfd)
  228. {
  229. int ret;
  230. static int bklight_pwm_cfg;
  231. if (bklight_pwm_cfg == 0) {
  232. mipi_bklight_pwm_cfg();
  233. bklight_pwm_cfg++;
  234. }
  235. if (bl_lpm) {
  236. ret = pwm_config(bl_lpm, MIPI_TOSHIBA_PWM_DUTY_LEVEL *
  237. mfd->bl_level, MIPI_TOSHIBA_PWM_PERIOD_USEC);
  238. if (ret) {
  239. pr_err("pwm_config on lpm failed %d\n", ret);
  240. return;
  241. }
  242. if (mfd->bl_level) {
  243. ret = pwm_enable(bl_lpm);
  244. if (ret)
  245. pr_err("pwm enable/disable on lpm failed"
  246. "for bl %d\n", mfd->bl_level);
  247. } else {
  248. pwm_disable(bl_lpm);
  249. }
  250. }
  251. }
  252. static int __devinit mipi_toshiba_lcd_probe(struct platform_device *pdev)
  253. {
  254. if (pdev->id == 0) {
  255. mipi_toshiba_pdata = pdev->dev.platform_data;
  256. return 0;
  257. }
  258. if (mipi_toshiba_pdata == NULL) {
  259. pr_err("%s.invalid platform data.\n", __func__);
  260. return -ENODEV;
  261. }
  262. if (mipi_toshiba_pdata != NULL)
  263. bl_lpm = pwm_request(mipi_toshiba_pdata->gpio[0],
  264. "backlight");
  265. if (bl_lpm == NULL || IS_ERR(bl_lpm)) {
  266. pr_err("%s pwm_request() failed\n", __func__);
  267. bl_lpm = NULL;
  268. }
  269. pr_debug("bl_lpm = %p lpm = %d\n", bl_lpm,
  270. mipi_toshiba_pdata->gpio[0]);
  271. msm_fb_add_device(pdev);
  272. return 0;
  273. }
  274. static struct platform_driver this_driver = {
  275. .probe = mipi_toshiba_lcd_probe,
  276. .driver = {
  277. .name = "mipi_toshiba",
  278. },
  279. };
  280. static struct msm_fb_panel_data toshiba_panel_data = {
  281. .on = mipi_toshiba_lcd_on,
  282. .off = mipi_toshiba_lcd_off,
  283. .late_init = mipi_toshiba_lcd_late_init,
  284. .set_backlight = mipi_toshiba_set_backlight,
  285. };
  286. static int ch_used[3];
  287. int mipi_toshiba_device_register(struct msm_panel_info *pinfo,
  288. u32 channel, u32 panel)
  289. {
  290. struct platform_device *pdev = NULL;
  291. int ret;
  292. if ((channel >= 3) || ch_used[channel])
  293. return -ENODEV;
  294. ch_used[channel] = TRUE;
  295. ret = mipi_toshiba_lcd_init();
  296. if (ret) {
  297. pr_err("mipi_toshiba_lcd_init() failed with ret %u\n", ret);
  298. return ret;
  299. }
  300. pdev = platform_device_alloc("mipi_toshiba", (panel << 8)|channel);
  301. if (!pdev)
  302. return -ENOMEM;
  303. toshiba_panel_data.panel_info = *pinfo;
  304. ret = platform_device_add_data(pdev, &toshiba_panel_data,
  305. sizeof(toshiba_panel_data));
  306. if (ret) {
  307. printk(KERN_ERR
  308. "%s: platform_device_add_data failed!\n", __func__);
  309. goto err_device_put;
  310. }
  311. ret = platform_device_add(pdev);
  312. if (ret) {
  313. printk(KERN_ERR
  314. "%s: platform_device_register failed!\n", __func__);
  315. goto err_device_put;
  316. }
  317. return 0;
  318. err_device_put:
  319. platform_device_put(pdev);
  320. return ret;
  321. }
  322. static int mipi_toshiba_lcd_init(void)
  323. {
  324. mipi_dsi_buf_alloc(&toshiba_tx_buf, DSI_BUF_SIZE);
  325. mipi_dsi_buf_alloc(&toshiba_rx_buf, DSI_BUF_SIZE);
  326. return platform_driver_register(&this_driver);
  327. }