sdi.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. } sdi;
  33. static void sdi_config_lcd_manager(struct omap_dss_device *dssdev)
  34. {
  35. sdi.mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
  36. sdi.mgr_config.stallmode = false;
  37. sdi.mgr_config.fifohandcheck = false;
  38. sdi.mgr_config.video_port_width = 24;
  39. sdi.mgr_config.lcden_sig_polarity = 1;
  40. dss_mgr_set_lcd_config(dssdev->manager, &sdi.mgr_config);
  41. }
  42. int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
  43. {
  44. struct omap_video_timings *t = &dssdev->panel.timings;
  45. struct dss_clock_info dss_cinfo;
  46. struct dispc_clock_info dispc_cinfo;
  47. unsigned long pck;
  48. int r;
  49. if (dssdev->manager == NULL) {
  50. DSSERR("failed to enable display: no manager\n");
  51. return -ENODEV;
  52. }
  53. r = omap_dss_start_device(dssdev);
  54. if (r) {
  55. DSSERR("failed to start device\n");
  56. goto err_start_dev;
  57. }
  58. r = regulator_enable(sdi.vdds_sdi_reg);
  59. if (r)
  60. goto err_reg_enable;
  61. r = dispc_runtime_get();
  62. if (r)
  63. goto err_get_dispc;
  64. /* 15.5.9.1.2 */
  65. dssdev->panel.timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  66. dssdev->panel.timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  67. r = dss_calc_clock_div(t->pixel_clock * 1000, &dss_cinfo, &dispc_cinfo);
  68. if (r)
  69. goto err_calc_clock_div;
  70. sdi.mgr_config.clock_info = dispc_cinfo;
  71. pck = dss_cinfo.fck / dispc_cinfo.lck_div / dispc_cinfo.pck_div / 1000;
  72. if (pck != t->pixel_clock) {
  73. DSSWARN("Could not find exact pixel clock. Requested %d kHz, "
  74. "got %lu kHz\n",
  75. t->pixel_clock, pck);
  76. t->pixel_clock = pck;
  77. }
  78. dss_mgr_set_timings(dssdev->manager, t);
  79. r = dss_set_clock_div(&dss_cinfo);
  80. if (r)
  81. goto err_set_dss_clock_div;
  82. sdi_config_lcd_manager(dssdev);
  83. dss_sdi_init(dssdev->phy.sdi.datapairs);
  84. r = dss_sdi_enable();
  85. if (r)
  86. goto err_sdi_enable;
  87. mdelay(2);
  88. r = dss_mgr_enable(dssdev->manager);
  89. if (r)
  90. goto err_mgr_enable;
  91. return 0;
  92. err_mgr_enable:
  93. dss_sdi_disable();
  94. err_sdi_enable:
  95. err_set_dss_clock_div:
  96. err_calc_clock_div:
  97. dispc_runtime_put();
  98. err_get_dispc:
  99. regulator_disable(sdi.vdds_sdi_reg);
  100. err_reg_enable:
  101. omap_dss_stop_device(dssdev);
  102. err_start_dev:
  103. return r;
  104. }
  105. EXPORT_SYMBOL(omapdss_sdi_display_enable);
  106. void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
  107. {
  108. dss_mgr_disable(dssdev->manager);
  109. dss_sdi_disable();
  110. dispc_runtime_put();
  111. regulator_disable(sdi.vdds_sdi_reg);
  112. omap_dss_stop_device(dssdev);
  113. }
  114. EXPORT_SYMBOL(omapdss_sdi_display_disable);
  115. static int __init sdi_init_display(struct omap_dss_device *dssdev)
  116. {
  117. DSSDBG("SDI init\n");
  118. if (sdi.vdds_sdi_reg == NULL) {
  119. struct regulator *vdds_sdi;
  120. vdds_sdi = dss_get_vdds_sdi();
  121. if (IS_ERR(vdds_sdi)) {
  122. DSSERR("can't get VDDS_SDI regulator\n");
  123. return PTR_ERR(vdds_sdi);
  124. }
  125. sdi.vdds_sdi_reg = vdds_sdi;
  126. }
  127. return 0;
  128. }
  129. static void __init sdi_probe_pdata(struct platform_device *pdev)
  130. {
  131. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  132. int i, r;
  133. for (i = 0; i < pdata->num_devices; ++i) {
  134. struct omap_dss_device *dssdev = pdata->devices[i];
  135. if (dssdev->type != OMAP_DISPLAY_TYPE_SDI)
  136. continue;
  137. r = sdi_init_display(dssdev);
  138. if (r) {
  139. DSSERR("device %s init failed: %d\n", dssdev->name, r);
  140. continue;
  141. }
  142. r = omap_dss_register_device(dssdev, &pdev->dev, i);
  143. if (r)
  144. DSSERR("device %s register failed: %d\n",
  145. dssdev->name, r);
  146. }
  147. }
  148. static int __init omap_sdi_probe(struct platform_device *pdev)
  149. {
  150. sdi_probe_pdata(pdev);
  151. return 0;
  152. }
  153. static int __exit omap_sdi_remove(struct platform_device *pdev)
  154. {
  155. omap_dss_unregister_child_devices(&pdev->dev);
  156. return 0;
  157. }
  158. static struct platform_driver omap_sdi_driver = {
  159. .remove = __exit_p(omap_sdi_remove),
  160. .driver = {
  161. .name = "omapdss_sdi",
  162. .owner = THIS_MODULE,
  163. },
  164. };
  165. int __init sdi_init_platform_driver(void)
  166. {
  167. return platform_driver_probe(&omap_sdi_driver, omap_sdi_probe);
  168. }
  169. void __exit sdi_uninit_platform_driver(void)
  170. {
  171. platform_driver_unregister(&omap_sdi_driver);
  172. }