connector-analog-tv.c 6.7 KB

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