connector-hdmi.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * HDMI 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/gpio/consumer.h>
  12. #include <linux/module.h>
  13. #include <linux/mutex.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/slab.h>
  16. #include "../dss/omapdss.h"
  17. struct panel_drv_data {
  18. struct omap_dss_device dssdev;
  19. void (*hpd_cb)(void *cb_data, enum drm_connector_status status);
  20. void *hpd_cb_data;
  21. struct mutex hpd_lock;
  22. struct device *dev;
  23. struct gpio_desc *hpd_gpio;
  24. };
  25. #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
  26. static int hdmic_connect(struct omap_dss_device *src,
  27. struct omap_dss_device *dst)
  28. {
  29. return 0;
  30. }
  31. static void hdmic_disconnect(struct omap_dss_device *src,
  32. struct omap_dss_device *dst)
  33. {
  34. }
  35. static int hdmic_enable(struct omap_dss_device *dssdev)
  36. {
  37. struct panel_drv_data *ddata = to_panel_data(dssdev);
  38. struct omap_dss_device *src = dssdev->src;
  39. int r;
  40. dev_dbg(ddata->dev, "enable\n");
  41. if (!omapdss_device_is_connected(dssdev))
  42. return -ENODEV;
  43. if (omapdss_device_is_enabled(dssdev))
  44. return 0;
  45. r = src->ops->enable(src);
  46. if (r)
  47. return r;
  48. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  49. return r;
  50. }
  51. static void hdmic_disable(struct omap_dss_device *dssdev)
  52. {
  53. struct panel_drv_data *ddata = to_panel_data(dssdev);
  54. struct omap_dss_device *src = dssdev->src;
  55. dev_dbg(ddata->dev, "disable\n");
  56. if (!omapdss_device_is_enabled(dssdev))
  57. return;
  58. src->ops->disable(src);
  59. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  60. }
  61. static bool hdmic_detect(struct omap_dss_device *dssdev)
  62. {
  63. struct panel_drv_data *ddata = to_panel_data(dssdev);
  64. return gpiod_get_value_cansleep(ddata->hpd_gpio);
  65. }
  66. static void hdmic_register_hpd_cb(struct omap_dss_device *dssdev,
  67. void (*cb)(void *cb_data,
  68. enum drm_connector_status status),
  69. void *cb_data)
  70. {
  71. struct panel_drv_data *ddata = to_panel_data(dssdev);
  72. mutex_lock(&ddata->hpd_lock);
  73. ddata->hpd_cb = cb;
  74. ddata->hpd_cb_data = cb_data;
  75. mutex_unlock(&ddata->hpd_lock);
  76. }
  77. static void hdmic_unregister_hpd_cb(struct omap_dss_device *dssdev)
  78. {
  79. struct panel_drv_data *ddata = to_panel_data(dssdev);
  80. mutex_lock(&ddata->hpd_lock);
  81. ddata->hpd_cb = NULL;
  82. ddata->hpd_cb_data = NULL;
  83. mutex_unlock(&ddata->hpd_lock);
  84. }
  85. static const struct omap_dss_device_ops hdmic_ops = {
  86. .connect = hdmic_connect,
  87. .disconnect = hdmic_disconnect,
  88. .enable = hdmic_enable,
  89. .disable = hdmic_disable,
  90. .detect = hdmic_detect,
  91. .register_hpd_cb = hdmic_register_hpd_cb,
  92. .unregister_hpd_cb = hdmic_unregister_hpd_cb,
  93. };
  94. static irqreturn_t hdmic_hpd_isr(int irq, void *data)
  95. {
  96. struct panel_drv_data *ddata = data;
  97. mutex_lock(&ddata->hpd_lock);
  98. if (ddata->hpd_cb) {
  99. enum drm_connector_status status;
  100. if (hdmic_detect(&ddata->dssdev))
  101. status = connector_status_connected;
  102. else
  103. status = connector_status_disconnected;
  104. ddata->hpd_cb(ddata->hpd_cb_data, status);
  105. }
  106. mutex_unlock(&ddata->hpd_lock);
  107. return IRQ_HANDLED;
  108. }
  109. static int hdmic_probe(struct platform_device *pdev)
  110. {
  111. struct panel_drv_data *ddata;
  112. struct omap_dss_device *dssdev;
  113. struct gpio_desc *gpio;
  114. int r;
  115. ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
  116. if (!ddata)
  117. return -ENOMEM;
  118. platform_set_drvdata(pdev, ddata);
  119. ddata->dev = &pdev->dev;
  120. mutex_init(&ddata->hpd_lock);
  121. /* HPD GPIO */
  122. gpio = devm_gpiod_get_optional(&pdev->dev, "hpd", GPIOD_IN);
  123. if (IS_ERR(gpio)) {
  124. dev_err(&pdev->dev, "failed to parse HPD gpio\n");
  125. return PTR_ERR(gpio);
  126. }
  127. ddata->hpd_gpio = gpio;
  128. if (ddata->hpd_gpio) {
  129. r = devm_request_threaded_irq(&pdev->dev,
  130. gpiod_to_irq(ddata->hpd_gpio),
  131. NULL, hdmic_hpd_isr,
  132. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
  133. IRQF_ONESHOT,
  134. "hdmic hpd", ddata);
  135. if (r)
  136. return r;
  137. }
  138. dssdev = &ddata->dssdev;
  139. dssdev->ops = &hdmic_ops;
  140. dssdev->dev = &pdev->dev;
  141. dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
  142. dssdev->owner = THIS_MODULE;
  143. dssdev->of_ports = BIT(0);
  144. dssdev->ops_flags = ddata->hpd_gpio
  145. ? OMAP_DSS_DEVICE_OP_DETECT | OMAP_DSS_DEVICE_OP_HPD
  146. : 0;
  147. omapdss_display_init(dssdev);
  148. omapdss_device_register(dssdev);
  149. return 0;
  150. }
  151. static int __exit hdmic_remove(struct platform_device *pdev)
  152. {
  153. struct panel_drv_data *ddata = platform_get_drvdata(pdev);
  154. struct omap_dss_device *dssdev = &ddata->dssdev;
  155. omapdss_device_unregister(&ddata->dssdev);
  156. hdmic_disable(dssdev);
  157. return 0;
  158. }
  159. static const struct of_device_id hdmic_of_match[] = {
  160. { .compatible = "omapdss,hdmi-connector", },
  161. {},
  162. };
  163. MODULE_DEVICE_TABLE(of, hdmic_of_match);
  164. static struct platform_driver hdmi_connector_driver = {
  165. .probe = hdmic_probe,
  166. .remove = __exit_p(hdmic_remove),
  167. .driver = {
  168. .name = "connector-hdmi",
  169. .of_match_table = hdmic_of_match,
  170. .suppress_bind_attrs = true,
  171. },
  172. };
  173. module_platform_driver(hdmi_connector_driver);
  174. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  175. MODULE_DESCRIPTION("HDMI Connector driver");
  176. MODULE_LICENSE("GPL");