connector-hdmi.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * HDMI 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/gpio/consumer.h>
  12. #include <linux/slab.h>
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/of.h>
  16. #include <linux/of_gpio.h>
  17. #include <drm/drm_edid.h>
  18. #include <video/omap-panel-data.h>
  19. #include "../dss/omapdss.h"
  20. static const struct videomode hdmic_default_vm = {
  21. .hactive = 640,
  22. .vactive = 480,
  23. .pixelclock = 25175000,
  24. .hsync_len = 96,
  25. .hfront_porch = 16,
  26. .hback_porch = 48,
  27. .vsync_len = 2,
  28. .vfront_porch = 11,
  29. .vback_porch = 31,
  30. .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
  31. };
  32. struct panel_drv_data {
  33. struct omap_dss_device dssdev;
  34. struct omap_dss_device *in;
  35. struct device *dev;
  36. struct videomode vm;
  37. int hpd_gpio;
  38. };
  39. #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
  40. static int hdmic_connect(struct omap_dss_device *dssdev)
  41. {
  42. struct panel_drv_data *ddata = to_panel_data(dssdev);
  43. struct omap_dss_device *in = ddata->in;
  44. int r;
  45. dev_dbg(ddata->dev, "connect\n");
  46. if (omapdss_device_is_connected(dssdev))
  47. return 0;
  48. r = in->ops.hdmi->connect(in, dssdev);
  49. if (r)
  50. return r;
  51. return 0;
  52. }
  53. static void hdmic_disconnect(struct omap_dss_device *dssdev)
  54. {
  55. struct panel_drv_data *ddata = to_panel_data(dssdev);
  56. struct omap_dss_device *in = ddata->in;
  57. dev_dbg(ddata->dev, "disconnect\n");
  58. if (!omapdss_device_is_connected(dssdev))
  59. return;
  60. in->ops.hdmi->disconnect(in, dssdev);
  61. }
  62. static int hdmic_enable(struct omap_dss_device *dssdev)
  63. {
  64. struct panel_drv_data *ddata = to_panel_data(dssdev);
  65. struct omap_dss_device *in = ddata->in;
  66. int r;
  67. dev_dbg(ddata->dev, "enable\n");
  68. if (!omapdss_device_is_connected(dssdev))
  69. return -ENODEV;
  70. if (omapdss_device_is_enabled(dssdev))
  71. return 0;
  72. in->ops.hdmi->set_timings(in, &ddata->vm);
  73. r = in->ops.hdmi->enable(in);
  74. if (r)
  75. return r;
  76. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  77. return r;
  78. }
  79. static void hdmic_disable(struct omap_dss_device *dssdev)
  80. {
  81. struct panel_drv_data *ddata = to_panel_data(dssdev);
  82. struct omap_dss_device *in = ddata->in;
  83. dev_dbg(ddata->dev, "disable\n");
  84. if (!omapdss_device_is_enabled(dssdev))
  85. return;
  86. in->ops.hdmi->disable(in);
  87. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  88. }
  89. static void hdmic_set_timings(struct omap_dss_device *dssdev,
  90. struct videomode *vm)
  91. {
  92. struct panel_drv_data *ddata = to_panel_data(dssdev);
  93. struct omap_dss_device *in = ddata->in;
  94. ddata->vm = *vm;
  95. dssdev->panel.vm = *vm;
  96. in->ops.hdmi->set_timings(in, vm);
  97. }
  98. static void hdmic_get_timings(struct omap_dss_device *dssdev,
  99. struct videomode *vm)
  100. {
  101. struct panel_drv_data *ddata = to_panel_data(dssdev);
  102. *vm = ddata->vm;
  103. }
  104. static int hdmic_check_timings(struct omap_dss_device *dssdev,
  105. struct videomode *vm)
  106. {
  107. struct panel_drv_data *ddata = to_panel_data(dssdev);
  108. struct omap_dss_device *in = ddata->in;
  109. return in->ops.hdmi->check_timings(in, vm);
  110. }
  111. static int hdmic_read_edid(struct omap_dss_device *dssdev,
  112. u8 *edid, int len)
  113. {
  114. struct panel_drv_data *ddata = to_panel_data(dssdev);
  115. struct omap_dss_device *in = ddata->in;
  116. return in->ops.hdmi->read_edid(in, edid, len);
  117. }
  118. static bool hdmic_detect(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. if (gpio_is_valid(ddata->hpd_gpio))
  123. return gpio_get_value_cansleep(ddata->hpd_gpio);
  124. else
  125. return in->ops.hdmi->detect(in);
  126. }
  127. static int hdmic_set_hdmi_mode(struct omap_dss_device *dssdev, bool hdmi_mode)
  128. {
  129. struct panel_drv_data *ddata = to_panel_data(dssdev);
  130. struct omap_dss_device *in = ddata->in;
  131. return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
  132. }
  133. static int hdmic_set_infoframe(struct omap_dss_device *dssdev,
  134. const struct hdmi_avi_infoframe *avi)
  135. {
  136. struct panel_drv_data *ddata = to_panel_data(dssdev);
  137. struct omap_dss_device *in = ddata->in;
  138. return in->ops.hdmi->set_infoframe(in, avi);
  139. }
  140. static struct omap_dss_driver hdmic_driver = {
  141. .connect = hdmic_connect,
  142. .disconnect = hdmic_disconnect,
  143. .enable = hdmic_enable,
  144. .disable = hdmic_disable,
  145. .set_timings = hdmic_set_timings,
  146. .get_timings = hdmic_get_timings,
  147. .check_timings = hdmic_check_timings,
  148. .get_resolution = omapdss_default_get_resolution,
  149. .read_edid = hdmic_read_edid,
  150. .detect = hdmic_detect,
  151. .set_hdmi_mode = hdmic_set_hdmi_mode,
  152. .set_hdmi_infoframe = hdmic_set_infoframe,
  153. };
  154. static int hdmic_probe_of(struct platform_device *pdev)
  155. {
  156. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  157. struct device_node *node = pdev->dev.of_node;
  158. struct omap_dss_device *in;
  159. int gpio;
  160. /* HPD GPIO */
  161. gpio = of_get_named_gpio(node, "hpd-gpios", 0);
  162. if (gpio_is_valid(gpio))
  163. ddata->hpd_gpio = gpio;
  164. else
  165. ddata->hpd_gpio = -ENODEV;
  166. in = omapdss_of_find_source_for_first_ep(node);
  167. if (IS_ERR(in)) {
  168. dev_err(&pdev->dev, "failed to find video source\n");
  169. return PTR_ERR(in);
  170. }
  171. ddata->in = in;
  172. return 0;
  173. }
  174. static int hdmic_probe(struct platform_device *pdev)
  175. {
  176. struct panel_drv_data *ddata;
  177. struct omap_dss_device *dssdev;
  178. int r;
  179. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  180. if (!ddata)
  181. return -ENOMEM;
  182. platform_set_drvdata(pdev, ddata);
  183. ddata->dev = &pdev->dev;
  184. if (!pdev->dev.of_node)
  185. return -ENODEV;
  186. r = hdmic_probe_of(pdev);
  187. if (r)
  188. return r;
  189. if (gpio_is_valid(ddata->hpd_gpio)) {
  190. r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio,
  191. GPIOF_DIR_IN, "hdmi_hpd");
  192. if (r)
  193. goto err_reg;
  194. }
  195. ddata->vm = hdmic_default_vm;
  196. dssdev = &ddata->dssdev;
  197. dssdev->driver = &hdmic_driver;
  198. dssdev->dev = &pdev->dev;
  199. dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
  200. dssdev->owner = THIS_MODULE;
  201. dssdev->panel.vm = hdmic_default_vm;
  202. r = omapdss_register_display(dssdev);
  203. if (r) {
  204. dev_err(&pdev->dev, "Failed to register panel\n");
  205. goto err_reg;
  206. }
  207. return 0;
  208. err_reg:
  209. omap_dss_put_device(ddata->in);
  210. return r;
  211. }
  212. static int __exit hdmic_remove(struct platform_device *pdev)
  213. {
  214. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  215. struct omap_dss_device *dssdev = &ddata->dssdev;
  216. struct omap_dss_device *in = ddata->in;
  217. omapdss_unregister_display(&ddata->dssdev);
  218. hdmic_disable(dssdev);
  219. hdmic_disconnect(dssdev);
  220. omap_dss_put_device(in);
  221. return 0;
  222. }
  223. static const struct of_device_id hdmic_of_match[] = {
  224. { .compatible = "omapdss,hdmi-connector", },
  225. {},
  226. };
  227. MODULE_DEVICE_TABLE(of, hdmic_of_match);
  228. static struct platform_driver hdmi_connector_driver = {
  229. .probe = hdmic_probe,
  230. .remove = __exit_p(hdmic_remove),
  231. .driver = {
  232. .name = "connector-hdmi",
  233. .of_match_table = hdmic_of_match,
  234. .suppress_bind_attrs = true,
  235. },
  236. };
  237. module_platform_driver(hdmi_connector_driver);
  238. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  239. MODULE_DESCRIPTION("HDMI Connector driver");
  240. MODULE_LICENSE("GPL");