sdi.c 6.9 KB

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