sdi.c 5.8 KB

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