sdi.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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 <video/omapdss.h>
  27. #include "dss.h"
  28. static struct {
  29. bool update_enabled;
  30. struct regulator *vdds_sdi_reg;
  31. struct dss_lcd_mgr_config mgr_config;
  32. struct omap_video_timings timings;
  33. int datapairs;
  34. struct omap_dss_output output;
  35. } sdi;
  36. static void sdi_config_lcd_manager(struct omap_dss_device *dssdev)
  37. {
  38. struct omap_overlay_manager *mgr = dssdev->output->manager;
  39. sdi.mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
  40. sdi.mgr_config.stallmode = false;
  41. sdi.mgr_config.fifohandcheck = false;
  42. sdi.mgr_config.video_port_width = 24;
  43. sdi.mgr_config.lcden_sig_polarity = 1;
  44. dss_mgr_set_lcd_config(mgr, &sdi.mgr_config);
  45. }
  46. int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
  47. {
  48. struct omap_dss_output *out = dssdev->output;
  49. struct omap_video_timings *t = &sdi.timings;
  50. struct dss_clock_info dss_cinfo;
  51. struct dispc_clock_info dispc_cinfo;
  52. unsigned long pck;
  53. int r;
  54. if (out == NULL || out->manager == NULL) {
  55. DSSERR("failed to enable display: no output/manager\n");
  56. return -ENODEV;
  57. }
  58. r = omap_dss_start_device(dssdev);
  59. if (r) {
  60. DSSERR("failed to start device\n");
  61. goto err_start_dev;
  62. }
  63. r = regulator_enable(sdi.vdds_sdi_reg);
  64. if (r)
  65. goto err_reg_enable;
  66. r = dispc_runtime_get();
  67. if (r)
  68. goto err_get_dispc;
  69. /* 15.5.9.1.2 */
  70. t->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  71. t->sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  72. r = dss_calc_clock_div(t->pixel_clock * 1000, &dss_cinfo, &dispc_cinfo);
  73. if (r)
  74. goto err_calc_clock_div;
  75. sdi.mgr_config.clock_info = dispc_cinfo;
  76. pck = dss_cinfo.fck / dispc_cinfo.lck_div / dispc_cinfo.pck_div / 1000;
  77. if (pck != t->pixel_clock) {
  78. DSSWARN("Could not find exact pixel clock. Requested %d kHz, "
  79. "got %lu kHz\n",
  80. t->pixel_clock, pck);
  81. t->pixel_clock = pck;
  82. }
  83. dss_mgr_set_timings(out->manager, t);
  84. r = dss_set_clock_div(&dss_cinfo);
  85. if (r)
  86. goto err_set_dss_clock_div;
  87. sdi_config_lcd_manager(dssdev);
  88. /*
  89. * LCLK and PCLK divisors are located in shadow registers, and we
  90. * normally write them to DISPC registers when enabling the output.
  91. * However, SDI uses pck-free as source clock for its PLL, and pck-free
  92. * is affected by the divisors. And as we need the PLL before enabling
  93. * the output, we need to write the divisors early.
  94. *
  95. * It seems just writing to the DISPC register is enough, and we don't
  96. * need to care about the shadow register mechanism for pck-free. The
  97. * exact reason for this is unknown.
  98. */
  99. dispc_mgr_set_clock_div(out->manager->id, &sdi.mgr_config.clock_info);
  100. dss_sdi_init(sdi.datapairs);
  101. r = dss_sdi_enable();
  102. if (r)
  103. goto err_sdi_enable;
  104. mdelay(2);
  105. r = dss_mgr_enable(out->manager);
  106. if (r)
  107. goto err_mgr_enable;
  108. return 0;
  109. err_mgr_enable:
  110. dss_sdi_disable();
  111. err_sdi_enable:
  112. err_set_dss_clock_div:
  113. err_calc_clock_div:
  114. dispc_runtime_put();
  115. err_get_dispc:
  116. regulator_disable(sdi.vdds_sdi_reg);
  117. err_reg_enable:
  118. omap_dss_stop_device(dssdev);
  119. err_start_dev:
  120. return r;
  121. }
  122. EXPORT_SYMBOL(omapdss_sdi_display_enable);
  123. void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
  124. {
  125. struct omap_overlay_manager *mgr = dssdev->output->manager;
  126. dss_mgr_disable(mgr);
  127. dss_sdi_disable();
  128. dispc_runtime_put();
  129. regulator_disable(sdi.vdds_sdi_reg);
  130. omap_dss_stop_device(dssdev);
  131. }
  132. EXPORT_SYMBOL(omapdss_sdi_display_disable);
  133. void omapdss_sdi_set_timings(struct omap_dss_device *dssdev,
  134. struct omap_video_timings *timings)
  135. {
  136. sdi.timings = *timings;
  137. }
  138. EXPORT_SYMBOL(omapdss_sdi_set_timings);
  139. void omapdss_sdi_set_datapairs(struct omap_dss_device *dssdev, int datapairs)
  140. {
  141. sdi.datapairs = datapairs;
  142. }
  143. EXPORT_SYMBOL(omapdss_sdi_set_datapairs);
  144. static int __init sdi_init_display(struct omap_dss_device *dssdev)
  145. {
  146. DSSDBG("SDI init\n");
  147. if (sdi.vdds_sdi_reg == NULL) {
  148. struct regulator *vdds_sdi;
  149. vdds_sdi = dss_get_vdds_sdi();
  150. if (IS_ERR(vdds_sdi)) {
  151. DSSERR("can't get VDDS_SDI regulator\n");
  152. return PTR_ERR(vdds_sdi);
  153. }
  154. sdi.vdds_sdi_reg = vdds_sdi;
  155. }
  156. return 0;
  157. }
  158. static struct omap_dss_device * __init sdi_find_dssdev(struct platform_device *pdev)
  159. {
  160. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  161. const char *def_disp_name = dss_get_default_display_name();
  162. struct omap_dss_device *def_dssdev;
  163. int i;
  164. def_dssdev = NULL;
  165. for (i = 0; i < pdata->num_devices; ++i) {
  166. struct omap_dss_device *dssdev = pdata->devices[i];
  167. if (dssdev->type != OMAP_DISPLAY_TYPE_SDI)
  168. continue;
  169. if (def_dssdev == NULL)
  170. def_dssdev = dssdev;
  171. if (def_disp_name != NULL &&
  172. strcmp(dssdev->name, def_disp_name) == 0) {
  173. def_dssdev = dssdev;
  174. break;
  175. }
  176. }
  177. return def_dssdev;
  178. }
  179. static void __init sdi_probe_pdata(struct platform_device *sdidev)
  180. {
  181. struct omap_dss_device *plat_dssdev;
  182. struct omap_dss_device *dssdev;
  183. int r;
  184. plat_dssdev = sdi_find_dssdev(sdidev);
  185. if (!plat_dssdev)
  186. return;
  187. dssdev = dss_alloc_and_init_device(&sdidev->dev);
  188. if (!dssdev)
  189. return;
  190. dss_copy_device_pdata(dssdev, plat_dssdev);
  191. r = sdi_init_display(dssdev);
  192. if (r) {
  193. DSSERR("device %s init failed: %d\n", dssdev->name, r);
  194. dss_put_device(dssdev);
  195. return;
  196. }
  197. r = dss_add_device(dssdev);
  198. if (r) {
  199. DSSERR("device %s register failed: %d\n", dssdev->name, r);
  200. dss_put_device(dssdev);
  201. return;
  202. }
  203. }
  204. static void __init sdi_init_output(struct platform_device *pdev)
  205. {
  206. struct omap_dss_output *out = &sdi.output;
  207. out->pdev = pdev;
  208. out->id = OMAP_DSS_OUTPUT_SDI;
  209. out->type = OMAP_DISPLAY_TYPE_SDI;
  210. dss_register_output(out);
  211. }
  212. static void __exit sdi_uninit_output(struct platform_device *pdev)
  213. {
  214. struct omap_dss_output *out = &sdi.output;
  215. dss_unregister_output(out);
  216. }
  217. static int __init omap_sdi_probe(struct platform_device *pdev)
  218. {
  219. sdi_init_output(pdev);
  220. sdi_probe_pdata(pdev);
  221. return 0;
  222. }
  223. static int __exit omap_sdi_remove(struct platform_device *pdev)
  224. {
  225. dss_unregister_child_devices(&pdev->dev);
  226. sdi_uninit_output(pdev);
  227. return 0;
  228. }
  229. static struct platform_driver omap_sdi_driver = {
  230. .remove = __exit_p(omap_sdi_remove),
  231. .driver = {
  232. .name = "omapdss_sdi",
  233. .owner = THIS_MODULE,
  234. },
  235. };
  236. int __init sdi_init_platform_driver(void)
  237. {
  238. return platform_driver_probe(&omap_sdi_driver, omap_sdi_probe);
  239. }
  240. void __exit sdi_uninit_platform_driver(void)
  241. {
  242. platform_driver_unregister(&omap_sdi_driver);
  243. }