sdi.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * linux/drivers/video/omap2/dss/sdi.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define DSS_SUBSYS_NAME "SDI"
  20. #include <linux/kernel.h>
  21. #include <linux/delay.h>
  22. #include <linux/err.h>
  23. #include <linux/regulator/consumer.h>
  24. #include <linux/export.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/string.h>
  27. #include <video/omapdss.h>
  28. #include "dss.h"
  29. static struct {
  30. bool update_enabled;
  31. struct regulator *vdds_sdi_reg;
  32. struct dss_lcd_mgr_config mgr_config;
  33. struct omap_video_timings timings;
  34. int datapairs;
  35. struct omap_dss_output output;
  36. } sdi;
  37. static void sdi_config_lcd_manager(struct omap_dss_device *dssdev)
  38. {
  39. struct omap_overlay_manager *mgr = dssdev->output->manager;
  40. sdi.mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
  41. sdi.mgr_config.stallmode = false;
  42. sdi.mgr_config.fifohandcheck = false;
  43. sdi.mgr_config.video_port_width = 24;
  44. sdi.mgr_config.lcden_sig_polarity = 1;
  45. dss_mgr_set_lcd_config(mgr, &sdi.mgr_config);
  46. }
  47. int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
  48. {
  49. struct omap_dss_output *out = dssdev->output;
  50. struct omap_video_timings *t = &sdi.timings;
  51. struct dss_clock_info dss_cinfo;
  52. struct dispc_clock_info dispc_cinfo;
  53. unsigned long pck;
  54. int r;
  55. if (out == NULL || out->manager == NULL) {
  56. DSSERR("failed to enable display: no output/manager\n");
  57. return -ENODEV;
  58. }
  59. r = omap_dss_start_device(dssdev);
  60. if (r) {
  61. DSSERR("failed to start device\n");
  62. goto err_start_dev;
  63. }
  64. r = regulator_enable(sdi.vdds_sdi_reg);
  65. if (r)
  66. goto err_reg_enable;
  67. r = dispc_runtime_get();
  68. if (r)
  69. goto err_get_dispc;
  70. /* 15.5.9.1.2 */
  71. t->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  72. t->sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  73. r = dss_calc_clock_div(t->pixel_clock * 1000, &dss_cinfo, &dispc_cinfo);
  74. if (r)
  75. goto err_calc_clock_div;
  76. sdi.mgr_config.clock_info = dispc_cinfo;
  77. pck = dss_cinfo.fck / dispc_cinfo.lck_div / dispc_cinfo.pck_div / 1000;
  78. if (pck != t->pixel_clock) {
  79. DSSWARN("Could not find exact pixel clock. Requested %d kHz, "
  80. "got %lu kHz\n",
  81. t->pixel_clock, pck);
  82. t->pixel_clock = pck;
  83. }
  84. dss_mgr_set_timings(out->manager, t);
  85. r = dss_set_clock_div(&dss_cinfo);
  86. if (r)
  87. goto err_set_dss_clock_div;
  88. sdi_config_lcd_manager(dssdev);
  89. /*
  90. * LCLK and PCLK divisors are located in shadow registers, and we
  91. * normally write them to DISPC registers when enabling the output.
  92. * However, SDI uses pck-free as source clock for its PLL, and pck-free
  93. * is affected by the divisors. And as we need the PLL before enabling
  94. * the output, we need to write the divisors early.
  95. *
  96. * It seems just writing to the DISPC register is enough, and we don't
  97. * need to care about the shadow register mechanism for pck-free. The
  98. * exact reason for this is unknown.
  99. */
  100. dispc_mgr_set_clock_div(out->manager->id, &sdi.mgr_config.clock_info);
  101. dss_sdi_init(sdi.datapairs);
  102. r = dss_sdi_enable();
  103. if (r)
  104. goto err_sdi_enable;
  105. mdelay(2);
  106. r = dss_mgr_enable(out->manager);
  107. if (r)
  108. goto err_mgr_enable;
  109. return 0;
  110. err_mgr_enable:
  111. dss_sdi_disable();
  112. err_sdi_enable:
  113. err_set_dss_clock_div:
  114. err_calc_clock_div:
  115. dispc_runtime_put();
  116. err_get_dispc:
  117. regulator_disable(sdi.vdds_sdi_reg);
  118. err_reg_enable:
  119. omap_dss_stop_device(dssdev);
  120. err_start_dev:
  121. return r;
  122. }
  123. EXPORT_SYMBOL(omapdss_sdi_display_enable);
  124. void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
  125. {
  126. struct omap_overlay_manager *mgr = dssdev->output->manager;
  127. dss_mgr_disable(mgr);
  128. dss_sdi_disable();
  129. dispc_runtime_put();
  130. regulator_disable(sdi.vdds_sdi_reg);
  131. omap_dss_stop_device(dssdev);
  132. }
  133. EXPORT_SYMBOL(omapdss_sdi_display_disable);
  134. void omapdss_sdi_set_timings(struct omap_dss_device *dssdev,
  135. struct omap_video_timings *timings)
  136. {
  137. sdi.timings = *timings;
  138. }
  139. EXPORT_SYMBOL(omapdss_sdi_set_timings);
  140. void omapdss_sdi_set_datapairs(struct omap_dss_device *dssdev, int datapairs)
  141. {
  142. sdi.datapairs = datapairs;
  143. }
  144. EXPORT_SYMBOL(omapdss_sdi_set_datapairs);
  145. static int __init sdi_init_display(struct omap_dss_device *dssdev)
  146. {
  147. DSSDBG("SDI init\n");
  148. if (sdi.vdds_sdi_reg == NULL) {
  149. struct regulator *vdds_sdi;
  150. vdds_sdi = dss_get_vdds_sdi();
  151. if (IS_ERR(vdds_sdi)) {
  152. DSSERR("can't get VDDS_SDI regulator\n");
  153. return PTR_ERR(vdds_sdi);
  154. }
  155. sdi.vdds_sdi_reg = vdds_sdi;
  156. }
  157. return 0;
  158. }
  159. static struct omap_dss_device * __init sdi_find_dssdev(struct platform_device *pdev)
  160. {
  161. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  162. const char *def_disp_name = omapdss_get_default_display_name();
  163. struct omap_dss_device *def_dssdev;
  164. int i;
  165. def_dssdev = NULL;
  166. for (i = 0; i < pdata->num_devices; ++i) {
  167. struct omap_dss_device *dssdev = pdata->devices[i];
  168. if (dssdev->type != OMAP_DISPLAY_TYPE_SDI)
  169. continue;
  170. if (def_dssdev == NULL)
  171. def_dssdev = dssdev;
  172. if (def_disp_name != NULL &&
  173. strcmp(dssdev->name, def_disp_name) == 0) {
  174. def_dssdev = dssdev;
  175. break;
  176. }
  177. }
  178. return def_dssdev;
  179. }
  180. static void __init sdi_probe_pdata(struct platform_device *sdidev)
  181. {
  182. struct omap_dss_device *plat_dssdev;
  183. struct omap_dss_device *dssdev;
  184. int r;
  185. plat_dssdev = sdi_find_dssdev(sdidev);
  186. if (!plat_dssdev)
  187. return;
  188. dssdev = dss_alloc_and_init_device(&sdidev->dev);
  189. if (!dssdev)
  190. return;
  191. dss_copy_device_pdata(dssdev, plat_dssdev);
  192. r = sdi_init_display(dssdev);
  193. if (r) {
  194. DSSERR("device %s init failed: %d\n", dssdev->name, r);
  195. dss_put_device(dssdev);
  196. return;
  197. }
  198. r = omapdss_output_set_device(&sdi.output, dssdev);
  199. if (r) {
  200. DSSERR("failed to connect output to new device: %s\n",
  201. dssdev->name);
  202. dss_put_device(dssdev);
  203. return;
  204. }
  205. r = dss_add_device(dssdev);
  206. if (r) {
  207. DSSERR("device %s register failed: %d\n", dssdev->name, r);
  208. omapdss_output_unset_device(&sdi.output);
  209. dss_put_device(dssdev);
  210. return;
  211. }
  212. }
  213. static void __init sdi_init_output(struct platform_device *pdev)
  214. {
  215. struct omap_dss_output *out = &sdi.output;
  216. out->pdev = pdev;
  217. out->id = OMAP_DSS_OUTPUT_SDI;
  218. out->type = OMAP_DISPLAY_TYPE_SDI;
  219. dss_register_output(out);
  220. }
  221. static void __exit sdi_uninit_output(struct platform_device *pdev)
  222. {
  223. struct omap_dss_output *out = &sdi.output;
  224. dss_unregister_output(out);
  225. }
  226. static int __init omap_sdi_probe(struct platform_device *pdev)
  227. {
  228. sdi_init_output(pdev);
  229. sdi_probe_pdata(pdev);
  230. return 0;
  231. }
  232. static int __exit omap_sdi_remove(struct platform_device *pdev)
  233. {
  234. dss_unregister_child_devices(&pdev->dev);
  235. sdi_uninit_output(pdev);
  236. return 0;
  237. }
  238. static struct platform_driver omap_sdi_driver = {
  239. .remove = __exit_p(omap_sdi_remove),
  240. .driver = {
  241. .name = "omapdss_sdi",
  242. .owner = THIS_MODULE,
  243. },
  244. };
  245. int __init sdi_init_platform_driver(void)
  246. {
  247. return platform_driver_probe(&omap_sdi_driver, omap_sdi_probe);
  248. }
  249. void __exit sdi_uninit_platform_driver(void)
  250. {
  251. platform_driver_unregister(&omap_sdi_driver);
  252. }