connector-analog-tv.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. * Analog TV Connector driver
  3. *
  4. * Copyright (C) 2013 Texas Instruments
  5. * Author: Tomi Valkeinen <tomi.valkeinen@ti.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. #include <linux/slab.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/of.h>
  15. #include <video/omapdss.h>
  16. #include <video/omap-panel-data.h>
  17. struct panel_drv_data {
  18. struct omap_dss_device dssdev;
  19. struct omap_dss_device *in;
  20. struct device *dev;
  21. struct omap_video_timings timings;
  22. enum omap_dss_venc_type connector_type;
  23. bool invert_polarity;
  24. };
  25. static const struct omap_video_timings tvc_pal_timings = {
  26. .x_res = 720,
  27. .y_res = 574,
  28. .pixelclock = 13500000,
  29. .hsw = 64,
  30. .hfp = 12,
  31. .hbp = 68,
  32. .vsw = 5,
  33. .vfp = 5,
  34. .vbp = 41,
  35. .interlace = true,
  36. };
  37. static const struct of_device_id tvc_of_match[];
  38. struct tvc_of_data {
  39. enum omap_dss_venc_type connector_type;
  40. };
  41. #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
  42. static int tvc_connect(struct omap_dss_device *dssdev)
  43. {
  44. struct panel_drv_data *ddata = to_panel_data(dssdev);
  45. struct omap_dss_device *in = ddata->in;
  46. int r;
  47. dev_dbg(ddata->dev, "connect\n");
  48. if (omapdss_device_is_connected(dssdev))
  49. return 0;
  50. r = in->ops.atv->connect(in, dssdev);
  51. if (r)
  52. return r;
  53. return 0;
  54. }
  55. static void tvc_disconnect(struct omap_dss_device *dssdev)
  56. {
  57. struct panel_drv_data *ddata = to_panel_data(dssdev);
  58. struct omap_dss_device *in = ddata->in;
  59. dev_dbg(ddata->dev, "disconnect\n");
  60. if (!omapdss_device_is_connected(dssdev))
  61. return;
  62. in->ops.atv->disconnect(in, dssdev);
  63. }
  64. static int tvc_enable(struct omap_dss_device *dssdev)
  65. {
  66. struct panel_drv_data *ddata = to_panel_data(dssdev);
  67. struct omap_dss_device *in = ddata->in;
  68. int r;
  69. dev_dbg(ddata->dev, "enable\n");
  70. if (!omapdss_device_is_connected(dssdev))
  71. return -ENODEV;
  72. if (omapdss_device_is_enabled(dssdev))
  73. return 0;
  74. in->ops.atv->set_timings(in, &ddata->timings);
  75. if (!ddata->dev->of_node) {
  76. in->ops.atv->set_type(in, ddata->connector_type);
  77. in->ops.atv->invert_vid_out_polarity(in,
  78. ddata->invert_polarity);
  79. }
  80. r = in->ops.atv->enable(in);
  81. if (r)
  82. return r;
  83. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  84. return r;
  85. }
  86. static void tvc_disable(struct omap_dss_device *dssdev)
  87. {
  88. struct panel_drv_data *ddata = to_panel_data(dssdev);
  89. struct omap_dss_device *in = ddata->in;
  90. dev_dbg(ddata->dev, "disable\n");
  91. if (!omapdss_device_is_enabled(dssdev))
  92. return;
  93. in->ops.atv->disable(in);
  94. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  95. }
  96. static void tvc_set_timings(struct omap_dss_device *dssdev,
  97. struct omap_video_timings *timings)
  98. {
  99. struct panel_drv_data *ddata = to_panel_data(dssdev);
  100. struct omap_dss_device *in = ddata->in;
  101. ddata->timings = *timings;
  102. dssdev->panel.timings = *timings;
  103. in->ops.atv->set_timings(in, timings);
  104. }
  105. static void tvc_get_timings(struct omap_dss_device *dssdev,
  106. struct omap_video_timings *timings)
  107. {
  108. struct panel_drv_data *ddata = to_panel_data(dssdev);
  109. *timings = ddata->timings;
  110. }
  111. static int tvc_check_timings(struct omap_dss_device *dssdev,
  112. struct omap_video_timings *timings)
  113. {
  114. struct panel_drv_data *ddata = to_panel_data(dssdev);
  115. struct omap_dss_device *in = ddata->in;
  116. return in->ops.atv->check_timings(in, timings);
  117. }
  118. static u32 tvc_get_wss(struct omap_dss_device *dssdev)
  119. {
  120. struct panel_drv_data *ddata = to_panel_data(dssdev);
  121. struct omap_dss_device *in = ddata->in;
  122. return in->ops.atv->get_wss(in);
  123. }
  124. static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
  125. {
  126. struct panel_drv_data *ddata = to_panel_data(dssdev);
  127. struct omap_dss_device *in = ddata->in;
  128. return in->ops.atv->set_wss(in, wss);
  129. }
  130. static struct omap_dss_driver tvc_driver = {
  131. .connect = tvc_connect,
  132. .disconnect = tvc_disconnect,
  133. .enable = tvc_enable,
  134. .disable = tvc_disable,
  135. .set_timings = tvc_set_timings,
  136. .get_timings = tvc_get_timings,
  137. .check_timings = tvc_check_timings,
  138. .get_resolution = omapdss_default_get_resolution,
  139. .get_wss = tvc_get_wss,
  140. .set_wss = tvc_set_wss,
  141. };
  142. static int tvc_probe_pdata(struct platform_device *pdev)
  143. {
  144. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  145. struct connector_atv_platform_data *pdata;
  146. struct omap_dss_device *in, *dssdev;
  147. pdata = dev_get_platdata(&pdev->dev);
  148. in = omap_dss_find_output(pdata->source);
  149. if (in == NULL) {
  150. dev_err(&pdev->dev, "Failed to find video source\n");
  151. return -EPROBE_DEFER;
  152. }
  153. ddata->in = in;
  154. ddata->connector_type = pdata->connector_type;
  155. ddata->invert_polarity = pdata->invert_polarity;
  156. dssdev = &ddata->dssdev;
  157. dssdev->name = pdata->name;
  158. return 0;
  159. }
  160. static int tvc_probe_of(struct platform_device *pdev)
  161. {
  162. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  163. struct device_node *node = pdev->dev.of_node;
  164. struct omap_dss_device *in;
  165. in = omapdss_of_find_source_for_first_ep(node);
  166. if (IS_ERR(in)) {
  167. dev_err(&pdev->dev, "failed to find video source\n");
  168. return PTR_ERR(in);
  169. }
  170. ddata->in = in;
  171. return 0;
  172. }
  173. static int tvc_probe(struct platform_device *pdev)
  174. {
  175. struct panel_drv_data *ddata;
  176. struct omap_dss_device *dssdev;
  177. int r;
  178. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  179. if (!ddata)
  180. return -ENOMEM;
  181. platform_set_drvdata(pdev, ddata);
  182. ddata->dev = &pdev->dev;
  183. if (dev_get_platdata(&pdev->dev)) {
  184. r = tvc_probe_pdata(pdev);
  185. if (r)
  186. return r;
  187. } else if (pdev->dev.of_node) {
  188. r = tvc_probe_of(pdev);
  189. if (r)
  190. return r;
  191. } else {
  192. return -ENODEV;
  193. }
  194. ddata->timings = tvc_pal_timings;
  195. dssdev = &ddata->dssdev;
  196. dssdev->driver = &tvc_driver;
  197. dssdev->dev = &pdev->dev;
  198. dssdev->type = OMAP_DISPLAY_TYPE_VENC;
  199. dssdev->owner = THIS_MODULE;
  200. dssdev->panel.timings = tvc_pal_timings;
  201. r = omapdss_register_display(dssdev);
  202. if (r) {
  203. dev_err(&pdev->dev, "Failed to register panel\n");
  204. goto err_reg;
  205. }
  206. return 0;
  207. err_reg:
  208. omap_dss_put_device(ddata->in);
  209. return r;
  210. }
  211. static int __exit tvc_remove(struct platform_device *pdev)
  212. {
  213. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  214. struct omap_dss_device *dssdev = &ddata->dssdev;
  215. struct omap_dss_device *in = ddata->in;
  216. omapdss_unregister_display(&ddata->dssdev);
  217. tvc_disable(dssdev);
  218. tvc_disconnect(dssdev);
  219. omap_dss_put_device(in);
  220. return 0;
  221. }
  222. static const struct of_device_id tvc_of_match[] = {
  223. { .compatible = "omapdss,svideo-connector", },
  224. { .compatible = "omapdss,composite-video-connector", },
  225. {},
  226. };
  227. MODULE_DEVICE_TABLE(of, tvc_of_match);
  228. static struct platform_driver tvc_connector_driver = {
  229. .probe = tvc_probe,
  230. .remove = __exit_p(tvc_remove),
  231. .driver = {
  232. .name = "connector-analog-tv",
  233. .of_match_table = tvc_of_match,
  234. .suppress_bind_attrs = true,
  235. },
  236. };
  237. module_platform_driver(tvc_connector_driver);
  238. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  239. MODULE_DESCRIPTION("Analog TV Connector driver");
  240. MODULE_LICENSE("GPL");