connector-analog-tv.c 6.7 KB

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