panel-generic-dpi.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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. /* Generic Panel */
  54. {
  55. {
  56. .x_res = 640,
  57. .y_res = 480,
  58. .pixel_clock = 23500,
  59. .hfp = 48,
  60. .hsw = 32,
  61. .hbp = 80,
  62. .vfp = 3,
  63. .vsw = 4,
  64. .vbp = 7,
  65. },
  66. .acbi = 0x0,
  67. .acb = 0x0,
  68. .config = OMAP_DSS_LCD_TFT,
  69. .power_on_delay = 0,
  70. .power_off_delay = 0,
  71. .name = "generic",
  72. },
  73. /* Sharp LQ043T1DG01 */
  74. {
  75. {
  76. .x_res = 480,
  77. .y_res = 272,
  78. .pixel_clock = 9000,
  79. .hsw = 42,
  80. .hfp = 3,
  81. .hbp = 2,
  82. .vsw = 11,
  83. .vfp = 3,
  84. .vbp = 2,
  85. },
  86. .acbi = 0x0,
  87. .acb = 0x0,
  88. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  89. OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IEO,
  90. .power_on_delay = 50,
  91. .power_off_delay = 100,
  92. .name = "sharp_lq",
  93. },
  94. /* Sharp LS037V7DW01 */
  95. {
  96. {
  97. .x_res = 480,
  98. .y_res = 640,
  99. .pixel_clock = 19200,
  100. .hsw = 2,
  101. .hfp = 1,
  102. .hbp = 28,
  103. .vsw = 1,
  104. .vfp = 1,
  105. .vbp = 1,
  106. },
  107. .acbi = 0x0,
  108. .acb = 0x28,
  109. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  110. OMAP_DSS_LCD_IHS,
  111. .power_on_delay = 50,
  112. .power_off_delay = 100,
  113. .name = "sharp_ls",
  114. },
  115. /* Toppoly TDO35S */
  116. {
  117. {
  118. .x_res = 480,
  119. .y_res = 640,
  120. .pixel_clock = 26000,
  121. .hfp = 104,
  122. .hsw = 8,
  123. .hbp = 8,
  124. .vfp = 4,
  125. .vsw = 2,
  126. .vbp = 2,
  127. },
  128. .acbi = 0x0,
  129. .acb = 0x0,
  130. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  131. OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IPC |
  132. OMAP_DSS_LCD_ONOFF,
  133. .power_on_delay = 0,
  134. .power_off_delay = 0,
  135. .name = "toppoly_tdo35s",
  136. },
  137. /* Samsung LTE430WQ-F0C */
  138. {
  139. {
  140. .x_res = 480,
  141. .y_res = 272,
  142. .pixel_clock = 9200,
  143. .hfp = 8,
  144. .hsw = 41,
  145. .hbp = 45 - 41,
  146. .vfp = 4,
  147. .vsw = 10,
  148. .vbp = 12 - 10,
  149. },
  150. .acbi = 0x0,
  151. .acb = 0x0,
  152. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  153. OMAP_DSS_LCD_IHS,
  154. .power_on_delay = 0,
  155. .power_off_delay = 0,
  156. .name = "samsung_lte430wq_f0c",
  157. },
  158. /* Seiko 70WVW1TZ3Z3 */
  159. {
  160. {
  161. .x_res = 800,
  162. .y_res = 480,
  163. .pixel_clock = 33000,
  164. .hsw = 128,
  165. .hfp = 10,
  166. .hbp = 10,
  167. .vsw = 2,
  168. .vfp = 4,
  169. .vbp = 11,
  170. },
  171. .acbi = 0x0,
  172. .acb = 0x0,
  173. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  174. OMAP_DSS_LCD_IHS,
  175. .power_on_delay = 0,
  176. .power_off_delay = 0,
  177. .name = "seiko_70wvw1tz3",
  178. },
  179. /* Powertip PH480272T */
  180. {
  181. {
  182. .x_res = 480,
  183. .y_res = 272,
  184. .pixel_clock = 9000,
  185. .hsw = 40,
  186. .hfp = 2,
  187. .hbp = 2,
  188. .vsw = 10,
  189. .vfp = 2,
  190. .vbp = 2,
  191. },
  192. .acbi = 0x0,
  193. .acb = 0x0,
  194. .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  195. OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IEO,
  196. .power_on_delay = 0,
  197. .power_off_delay = 0,
  198. .name = "powertip_ph480272t",
  199. },
  200. };
  201. struct panel_drv_data {
  202. struct omap_dss_device *dssdev;
  203. struct panel_config *panel_config;
  204. };
  205. static inline struct panel_generic_dpi_data
  206. *get_panel_data(const struct omap_dss_device *dssdev)
  207. {
  208. return (struct panel_generic_dpi_data *) dssdev->data;
  209. }
  210. static int generic_dpi_panel_power_on(struct omap_dss_device *dssdev)
  211. {
  212. int r;
  213. struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
  214. struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
  215. struct panel_config *panel_config = drv_data->panel_config;
  216. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  217. return 0;
  218. r = omapdss_dpi_display_enable(dssdev);
  219. if (r)
  220. goto err0;
  221. /* wait couple of vsyncs until enabling the LCD */
  222. if (panel_config->power_on_delay)
  223. msleep(panel_config->power_on_delay);
  224. if (panel_data->platform_enable) {
  225. r = panel_data->platform_enable(dssdev);
  226. if (r)
  227. goto err1;
  228. }
  229. return 0;
  230. err1:
  231. omapdss_dpi_display_disable(dssdev);
  232. err0:
  233. return r;
  234. }
  235. static void generic_dpi_panel_power_off(struct omap_dss_device *dssdev)
  236. {
  237. struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
  238. struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
  239. struct panel_config *panel_config = drv_data->panel_config;
  240. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  241. return;
  242. if (panel_data->platform_disable)
  243. panel_data->platform_disable(dssdev);
  244. /* wait couple of vsyncs after disabling the LCD */
  245. if (panel_config->power_off_delay)
  246. msleep(panel_config->power_off_delay);
  247. omapdss_dpi_display_disable(dssdev);
  248. }
  249. static int generic_dpi_panel_probe(struct omap_dss_device *dssdev)
  250. {
  251. struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
  252. struct panel_config *panel_config = NULL;
  253. struct panel_drv_data *drv_data = NULL;
  254. int i;
  255. dev_dbg(&dssdev->dev, "probe\n");
  256. if (!panel_data || !panel_data->name)
  257. return -EINVAL;
  258. for (i = 0; i < ARRAY_SIZE(generic_dpi_panels); i++) {
  259. if (strcmp(panel_data->name, generic_dpi_panels[i].name) == 0) {
  260. panel_config = &generic_dpi_panels[i];
  261. break;
  262. }
  263. }
  264. if (!panel_config)
  265. return -EINVAL;
  266. dssdev->panel.config = panel_config->config;
  267. dssdev->panel.timings = panel_config->timings;
  268. dssdev->panel.acb = panel_config->acb;
  269. dssdev->panel.acbi = panel_config->acbi;
  270. drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
  271. if (!drv_data)
  272. return -ENOMEM;
  273. drv_data->dssdev = dssdev;
  274. drv_data->panel_config = panel_config;
  275. dev_set_drvdata(&dssdev->dev, drv_data);
  276. return 0;
  277. }
  278. static void __exit generic_dpi_panel_remove(struct omap_dss_device *dssdev)
  279. {
  280. struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
  281. dev_dbg(&dssdev->dev, "remove\n");
  282. kfree(drv_data);
  283. dev_set_drvdata(&dssdev->dev, NULL);
  284. }
  285. static int generic_dpi_panel_enable(struct omap_dss_device *dssdev)
  286. {
  287. int r = 0;
  288. r = generic_dpi_panel_power_on(dssdev);
  289. if (r)
  290. return r;
  291. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  292. return 0;
  293. }
  294. static void generic_dpi_panel_disable(struct omap_dss_device *dssdev)
  295. {
  296. generic_dpi_panel_power_off(dssdev);
  297. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  298. }
  299. static int generic_dpi_panel_suspend(struct omap_dss_device *dssdev)
  300. {
  301. generic_dpi_panel_power_off(dssdev);
  302. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  303. return 0;
  304. }
  305. static int generic_dpi_panel_resume(struct omap_dss_device *dssdev)
  306. {
  307. int r = 0;
  308. r = generic_dpi_panel_power_on(dssdev);
  309. if (r)
  310. return r;
  311. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  312. return 0;
  313. }
  314. static void generic_dpi_panel_set_timings(struct omap_dss_device *dssdev,
  315. struct omap_video_timings *timings)
  316. {
  317. dpi_set_timings(dssdev, timings);
  318. }
  319. static void generic_dpi_panel_get_timings(struct omap_dss_device *dssdev,
  320. struct omap_video_timings *timings)
  321. {
  322. *timings = dssdev->panel.timings;
  323. }
  324. static int generic_dpi_panel_check_timings(struct omap_dss_device *dssdev,
  325. struct omap_video_timings *timings)
  326. {
  327. return dpi_check_timings(dssdev, timings);
  328. }
  329. static struct omap_dss_driver dpi_driver = {
  330. .probe = generic_dpi_panel_probe,
  331. .remove = __exit_p(generic_dpi_panel_remove),
  332. .enable = generic_dpi_panel_enable,
  333. .disable = generic_dpi_panel_disable,
  334. .suspend = generic_dpi_panel_suspend,
  335. .resume = generic_dpi_panel_resume,
  336. .set_timings = generic_dpi_panel_set_timings,
  337. .get_timings = generic_dpi_panel_get_timings,
  338. .check_timings = generic_dpi_panel_check_timings,
  339. .driver = {
  340. .name = "generic_dpi_panel",
  341. .owner = THIS_MODULE,
  342. },
  343. };
  344. static int __init generic_dpi_panel_drv_init(void)
  345. {
  346. return omap_dss_register_driver(&dpi_driver);
  347. }
  348. static void __exit generic_dpi_panel_drv_exit(void)
  349. {
  350. omap_dss_unregister_driver(&dpi_driver);
  351. }
  352. module_init(generic_dpi_panel_drv_init);
  353. module_exit(generic_dpi_panel_drv_exit);
  354. MODULE_LICENSE("GPL");