connector-analog-tv.c 5.4 KB

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