sdi.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. dss_sdi_init(sdi.datapairs);
  86. r = dss_sdi_enable();
  87. if (r)
  88. goto err_sdi_enable;
  89. mdelay(2);
  90. r = dss_mgr_enable(dssdev->manager);
  91. if (r)
  92. goto err_mgr_enable;
  93. return 0;
  94. err_mgr_enable:
  95. dss_sdi_disable();
  96. err_sdi_enable:
  97. err_set_dss_clock_div:
  98. err_calc_clock_div:
  99. dispc_runtime_put();
  100. err_get_dispc:
  101. regulator_disable(sdi.vdds_sdi_reg);
  102. err_reg_enable:
  103. omap_dss_stop_device(dssdev);
  104. err_start_dev:
  105. return r;
  106. }
  107. EXPORT_SYMBOL(omapdss_sdi_display_enable);
  108. void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
  109. {
  110. dss_mgr_disable(dssdev->manager);
  111. dss_sdi_disable();
  112. dispc_runtime_put();
  113. regulator_disable(sdi.vdds_sdi_reg);
  114. omap_dss_stop_device(dssdev);
  115. }
  116. EXPORT_SYMBOL(omapdss_sdi_display_disable);
  117. void omapdss_sdi_set_timings(struct omap_dss_device *dssdev,
  118. struct omap_video_timings *timings)
  119. {
  120. sdi.timings = *timings;
  121. }
  122. EXPORT_SYMBOL(omapdss_sdi_set_timings);
  123. void omapdss_sdi_set_datapairs(struct omap_dss_device *dssdev, int datapairs)
  124. {
  125. sdi.datapairs = datapairs;
  126. }
  127. EXPORT_SYMBOL(omapdss_sdi_set_datapairs);
  128. static int __init sdi_init_display(struct omap_dss_device *dssdev)
  129. {
  130. DSSDBG("SDI init\n");
  131. if (sdi.vdds_sdi_reg == NULL) {
  132. struct regulator *vdds_sdi;
  133. vdds_sdi = dss_get_vdds_sdi();
  134. if (IS_ERR(vdds_sdi)) {
  135. DSSERR("can't get VDDS_SDI regulator\n");
  136. return PTR_ERR(vdds_sdi);
  137. }
  138. sdi.vdds_sdi_reg = vdds_sdi;
  139. }
  140. return 0;
  141. }
  142. static void __init sdi_probe_pdata(struct platform_device *pdev)
  143. {
  144. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  145. int i, r;
  146. for (i = 0; i < pdata->num_devices; ++i) {
  147. struct omap_dss_device *dssdev = pdata->devices[i];
  148. if (dssdev->type != OMAP_DISPLAY_TYPE_SDI)
  149. continue;
  150. r = sdi_init_display(dssdev);
  151. if (r) {
  152. DSSERR("device %s init failed: %d\n", dssdev->name, r);
  153. continue;
  154. }
  155. r = omap_dss_register_device(dssdev, &pdev->dev, i);
  156. if (r)
  157. DSSERR("device %s register failed: %d\n",
  158. dssdev->name, r);
  159. }
  160. }
  161. static int __init omap_sdi_probe(struct platform_device *pdev)
  162. {
  163. sdi_probe_pdata(pdev);
  164. return 0;
  165. }
  166. static int __exit omap_sdi_remove(struct platform_device *pdev)
  167. {
  168. omap_dss_unregister_child_devices(&pdev->dev);
  169. return 0;
  170. }
  171. static struct platform_driver omap_sdi_driver = {
  172. .remove = __exit_p(omap_sdi_remove),
  173. .driver = {
  174. .name = "omapdss_sdi",
  175. .owner = THIS_MODULE,
  176. },
  177. };
  178. int __init sdi_init_platform_driver(void)
  179. {
  180. return platform_driver_probe(&omap_sdi_driver, omap_sdi_probe);
  181. }
  182. void __exit sdi_uninit_platform_driver(void)
  183. {
  184. platform_driver_unregister(&omap_sdi_driver);
  185. }