connector-hdmi.c 6.8 KB

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