connector-analog-tv.c 5.8 KB

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