sdi.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. void omapdss_sdi_set_timings(struct omap_dss_device *dssdev,
  116. struct omap_video_timings *timings)
  117. {
  118. int r;
  119. dssdev->panel.timings = *timings;
  120. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  121. omapdss_sdi_display_disable(dssdev);
  122. r = omapdss_sdi_display_enable(dssdev);
  123. if (r)
  124. DSSERR("failed to set new timings\n");
  125. }
  126. }
  127. EXPORT_SYMBOL(omapdss_sdi_set_timings);
  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. }