panel-generic-dpi.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /*
  2. * Generic DPI Panels support
  3. *
  4. * Copyright (C) 2010 Canonical Ltd.
  5. * Author: Bryan Wu <bryan.wu@canonical.com>
  6. *
  7. * LCD panel driver for Sharp LQ043T1DG01
  8. *
  9. * Copyright (C) 2009 Texas Instruments Inc
  10. * Author: Vaibhav Hiremath <hvaibhav@ti.com>
  11. *
  12. * LCD panel driver for Toppoly TDO35S
  13. *
  14. * Copyright (C) 2009 CompuLab, Ltd.
  15. * Author: Mike Rapoport <mike@compulab.co.il>
  16. *
  17. * Copyright (C) 2008 Nokia Corporation
  18. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  19. *
  20. * This program is free software; you can redistribute it and/or modify it
  21. * under the terms of the GNU General Public License version 2 as published by
  22. * the Free Software Foundation.
  23. *
  24. * This program is distributed in the hope that it will be useful, but WITHOUT
  25. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  26. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  27. * more details.
  28. *
  29. * You should have received a copy of the GNU General Public License along with
  30. * this program. If not, see <http://www.gnu.org/licenses/>.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/delay.h>
  34. #include <linux/slab.h>
  35. #include <video/omapdss.h>
  36. #include <video/omap-panel-generic-dpi.h>
  37. struct panel_config {
  38. struct omap_video_timings timings;
  39. int acbi; /* ac-bias pin transitions per interrupt */
  40. /* Unit: line clocks */
  41. int acb; /* ac-bias pin frequency */
  42. enum omap_panel_config config;
  43. int power_on_delay;
  44. int power_off_delay;
  45. /*
  46. * Used to match device to panel configuration
  47. * when use generic panel driver
  48. */
  49. const char *name;
  50. };
  51. /* Panel configurations */
  52. static struct panel_config generic_dpi_panels[] = {
  53. /* Sharp LQ043T1DG01 */
  54. {
  55. {
  56. .x_res = 480,
  57. .y_res = 272,
  58. .pixel_clock = 9000,
  59. .hsw = 42,
  60. .hfp = 3,
  61. .hbp = 2,
  62. .vsw = 11,
  63. .vfp = 3,
  64. .vbp = 2,
  65. },
  66. .acbi = 0x0,
  67. .acb = 0x0,
  68. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  69. OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IEO,
  70. .power_on_delay = 50,
  71. .power_off_delay = 100,
  72. .name = "sharp_lq",
  73. },
  74. /* Sharp LS037V7DW01 */
  75. {
  76. {
  77. .x_res = 480,
  78. .y_res = 640,
  79. .pixel_clock = 19200,
  80. .hsw = 2,
  81. .hfp = 1,
  82. .hbp = 28,
  83. .vsw = 1,
  84. .vfp = 1,
  85. .vbp = 1,
  86. },
  87. .acbi = 0x0,
  88. .acb = 0x28,
  89. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  90. OMAP_DSS_LCD_IHS,
  91. .power_on_delay = 50,
  92. .power_off_delay = 100,
  93. .name = "sharp_ls",
  94. },
  95. /* Toppoly TDO35S */
  96. {
  97. {
  98. .x_res = 480,
  99. .y_res = 640,
  100. .pixel_clock = 26000,
  101. .hfp = 104,
  102. .hsw = 8,
  103. .hbp = 8,
  104. .vfp = 4,
  105. .vsw = 2,
  106. .vbp = 2,
  107. },
  108. .acbi = 0x0,
  109. .acb = 0x0,
  110. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  111. OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IPC |
  112. OMAP_DSS_LCD_ONOFF,
  113. .power_on_delay = 0,
  114. .power_off_delay = 0,
  115. .name = "toppoly_tdo35s",
  116. },
  117. /* Samsung LTE430WQ-F0C */
  118. {
  119. {
  120. .x_res = 480,
  121. .y_res = 272,
  122. .pixel_clock = 9200,
  123. .hfp = 8,
  124. .hsw = 41,
  125. .hbp = 45 - 41,
  126. .vfp = 4,
  127. .vsw = 10,
  128. .vbp = 12 - 10,
  129. },
  130. .acbi = 0x0,
  131. .acb = 0x0,
  132. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  133. OMAP_DSS_LCD_IHS,
  134. .power_on_delay = 0,
  135. .power_off_delay = 0,
  136. .name = "samsung_lte430wq_f0c",
  137. },
  138. /* Seiko 70WVW1TZ3Z3 */
  139. {
  140. {
  141. .x_res = 800,
  142. .y_res = 480,
  143. .pixel_clock = 33000,
  144. .hsw = 128,
  145. .hfp = 10,
  146. .hbp = 10,
  147. .vsw = 2,
  148. .vfp = 4,
  149. .vbp = 11,
  150. },
  151. .acbi = 0x0,
  152. .acb = 0x0,
  153. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  154. OMAP_DSS_LCD_IHS,
  155. .power_on_delay = 0,
  156. .power_off_delay = 0,
  157. .name = "seiko_70wvw1tz3",
  158. },
  159. /* Powertip PH480272T */
  160. {
  161. {
  162. .x_res = 480,
  163. .y_res = 272,
  164. .pixel_clock = 9000,
  165. .hsw = 40,
  166. .hfp = 2,
  167. .hbp = 2,
  168. .vsw = 10,
  169. .vfp = 2,
  170. .vbp = 2,
  171. },
  172. .acbi = 0x0,
  173. .acb = 0x0,
  174. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  175. OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IEO,
  176. .power_on_delay = 0,
  177. .power_off_delay = 0,
  178. .name = "powertip_ph480272t",
  179. },
  180. /* Innolux AT070TN83 */
  181. {
  182. {
  183. .x_res = 800,
  184. .y_res = 480,
  185. .pixel_clock = 40000,
  186. .hsw = 48,
  187. .hfp = 1,
  188. .hbp = 1,
  189. .vsw = 3,
  190. .vfp = 12,
  191. .vbp = 25,
  192. },
  193. .acbi = 0x0,
  194. .acb = 0x28,
  195. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  196. OMAP_DSS_LCD_IHS,
  197. .power_on_delay = 0,
  198. .power_off_delay = 0,
  199. .name = "innolux_at070tn83",
  200. },
  201. /* NEC NL2432DR22-11B */
  202. {
  203. {
  204. .x_res = 240,
  205. .y_res = 320,
  206. .pixel_clock = 5400,
  207. .hsw = 3,
  208. .hfp = 3,
  209. .hbp = 39,
  210. .vsw = 1,
  211. .vfp = 2,
  212. .vbp = 7,
  213. },
  214. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  215. OMAP_DSS_LCD_IHS,
  216. .name = "nec_nl2432dr22-11b",
  217. },
  218. /* Unknown panel used in OMAP H4 */
  219. {
  220. {
  221. .x_res = 240,
  222. .y_res = 320,
  223. .pixel_clock = 6250,
  224. .hsw = 15,
  225. .hfp = 15,
  226. .hbp = 60,
  227. .vsw = 1,
  228. .vfp = 1,
  229. .vbp = 1,
  230. },
  231. .config = OMAP_DSS_LCD_TFT,
  232. .name = "h4",
  233. },
  234. /* Unknown panel used in Samsung OMAP2 Apollon */
  235. {
  236. {
  237. .x_res = 480,
  238. .y_res = 272,
  239. .pixel_clock = 6250,
  240. .hsw = 41,
  241. .hfp = 2,
  242. .hbp = 2,
  243. .vsw = 10,
  244. .vfp = 2,
  245. .vbp = 2,
  246. },
  247. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  248. OMAP_DSS_LCD_IHS,
  249. .name = "apollon",
  250. },
  251. };
  252. struct panel_drv_data {
  253. struct omap_dss_device *dssdev;
  254. struct panel_config *panel_config;
  255. };
  256. static inline struct panel_generic_dpi_data
  257. *get_panel_data(const struct omap_dss_device *dssdev)
  258. {
  259. return (struct panel_generic_dpi_data *) dssdev->data;
  260. }
  261. static int generic_dpi_panel_power_on(struct omap_dss_device *dssdev)
  262. {
  263. int r;
  264. struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
  265. struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
  266. struct panel_config *panel_config = drv_data->panel_config;
  267. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  268. return 0;
  269. r = omapdss_dpi_display_enable(dssdev);
  270. if (r)
  271. goto err0;
  272. /* wait couple of vsyncs until enabling the LCD */
  273. if (panel_config->power_on_delay)
  274. msleep(panel_config->power_on_delay);
  275. if (panel_data->platform_enable) {
  276. r = panel_data->platform_enable(dssdev);
  277. if (r)
  278. goto err1;
  279. }
  280. return 0;
  281. err1:
  282. omapdss_dpi_display_disable(dssdev);
  283. err0:
  284. return r;
  285. }
  286. static void generic_dpi_panel_power_off(struct omap_dss_device *dssdev)
  287. {
  288. struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
  289. struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
  290. struct panel_config *panel_config = drv_data->panel_config;
  291. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  292. return;
  293. if (panel_data->platform_disable)
  294. panel_data->platform_disable(dssdev);
  295. /* wait couple of vsyncs after disabling the LCD */
  296. if (panel_config->power_off_delay)
  297. msleep(panel_config->power_off_delay);
  298. omapdss_dpi_display_disable(dssdev);
  299. }
  300. static int generic_dpi_panel_probe(struct omap_dss_device *dssdev)
  301. {
  302. struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
  303. struct panel_config *panel_config = NULL;
  304. struct panel_drv_data *drv_data = NULL;
  305. int i;
  306. dev_dbg(&dssdev->dev, "probe\n");
  307. if (!panel_data || !panel_data->name)
  308. return -EINVAL;
  309. for (i = 0; i < ARRAY_SIZE(generic_dpi_panels); i++) {
  310. if (strcmp(panel_data->name, generic_dpi_panels[i].name) == 0) {
  311. panel_config = &generic_dpi_panels[i];
  312. break;
  313. }
  314. }
  315. if (!panel_config)
  316. return -EINVAL;
  317. dssdev->panel.config = panel_config->config;
  318. dssdev->panel.timings = panel_config->timings;
  319. dssdev->panel.acb = panel_config->acb;
  320. dssdev->panel.acbi = panel_config->acbi;
  321. drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
  322. if (!drv_data)
  323. return -ENOMEM;
  324. drv_data->dssdev = dssdev;
  325. drv_data->panel_config = panel_config;
  326. dev_set_drvdata(&dssdev->dev, drv_data);
  327. return 0;
  328. }
  329. static void __exit generic_dpi_panel_remove(struct omap_dss_device *dssdev)
  330. {
  331. struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
  332. dev_dbg(&dssdev->dev, "remove\n");
  333. kfree(drv_data);
  334. dev_set_drvdata(&dssdev->dev, NULL);
  335. }
  336. static int generic_dpi_panel_enable(struct omap_dss_device *dssdev)
  337. {
  338. int r = 0;
  339. r = generic_dpi_panel_power_on(dssdev);
  340. if (r)
  341. return r;
  342. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  343. return 0;
  344. }
  345. static void generic_dpi_panel_disable(struct omap_dss_device *dssdev)
  346. {
  347. generic_dpi_panel_power_off(dssdev);
  348. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  349. }
  350. static int generic_dpi_panel_suspend(struct omap_dss_device *dssdev)
  351. {
  352. generic_dpi_panel_power_off(dssdev);
  353. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  354. return 0;
  355. }
  356. static int generic_dpi_panel_resume(struct omap_dss_device *dssdev)
  357. {
  358. int r = 0;
  359. r = generic_dpi_panel_power_on(dssdev);
  360. if (r)
  361. return r;
  362. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  363. return 0;
  364. }
  365. static void generic_dpi_panel_set_timings(struct omap_dss_device *dssdev,
  366. struct omap_video_timings *timings)
  367. {
  368. dpi_set_timings(dssdev, timings);
  369. }
  370. static void generic_dpi_panel_get_timings(struct omap_dss_device *dssdev,
  371. struct omap_video_timings *timings)
  372. {
  373. *timings = dssdev->panel.timings;
  374. }
  375. static int generic_dpi_panel_check_timings(struct omap_dss_device *dssdev,
  376. struct omap_video_timings *timings)
  377. {
  378. return dpi_check_timings(dssdev, timings);
  379. }
  380. static struct omap_dss_driver dpi_driver = {
  381. .probe = generic_dpi_panel_probe,
  382. .remove = __exit_p(generic_dpi_panel_remove),
  383. .enable = generic_dpi_panel_enable,
  384. .disable = generic_dpi_panel_disable,
  385. .suspend = generic_dpi_panel_suspend,
  386. .resume = generic_dpi_panel_resume,
  387. .set_timings = generic_dpi_panel_set_timings,
  388. .get_timings = generic_dpi_panel_get_timings,
  389. .check_timings = generic_dpi_panel_check_timings,
  390. .driver = {
  391. .name = "generic_dpi_panel",
  392. .owner = THIS_MODULE,
  393. },
  394. };
  395. static int __init generic_dpi_panel_drv_init(void)
  396. {
  397. return omap_dss_register_driver(&dpi_driver);
  398. }
  399. static void __exit generic_dpi_panel_drv_exit(void)
  400. {
  401. omap_dss_unregister_driver(&dpi_driver);
  402. }
  403. module_init(generic_dpi_panel_drv_init);
  404. module_exit(generic_dpi_panel_drv_exit);
  405. MODULE_LICENSE("GPL");