sdi.c 5.3 KB

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