edp.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/of_irq.h>
  14. #include "edp.h"
  15. static irqreturn_t edp_irq(int irq, void *dev_id)
  16. {
  17. struct msm_edp *edp = dev_id;
  18. /* Process eDP irq */
  19. return msm_edp_ctrl_irq(edp->ctrl);
  20. }
  21. static void edp_destroy(struct platform_device *pdev)
  22. {
  23. struct msm_edp *edp = platform_get_drvdata(pdev);
  24. if (!edp)
  25. return;
  26. if (edp->ctrl) {
  27. msm_edp_ctrl_destroy(edp->ctrl);
  28. edp->ctrl = NULL;
  29. }
  30. platform_set_drvdata(pdev, NULL);
  31. }
  32. /* construct eDP at bind/probe time, grab all the resources. */
  33. static struct msm_edp *edp_init(struct platform_device *pdev)
  34. {
  35. struct msm_edp *edp = NULL;
  36. int ret;
  37. if (!pdev) {
  38. pr_err("no eDP device\n");
  39. ret = -ENXIO;
  40. goto fail;
  41. }
  42. edp = devm_kzalloc(&pdev->dev, sizeof(*edp), GFP_KERNEL);
  43. if (!edp) {
  44. ret = -ENOMEM;
  45. goto fail;
  46. }
  47. DBG("eDP probed=%p", edp);
  48. edp->pdev = pdev;
  49. platform_set_drvdata(pdev, edp);
  50. ret = msm_edp_ctrl_init(edp);
  51. if (ret)
  52. goto fail;
  53. return edp;
  54. fail:
  55. if (edp)
  56. edp_destroy(pdev);
  57. return ERR_PTR(ret);
  58. }
  59. static int edp_bind(struct device *dev, struct device *master, void *data)
  60. {
  61. struct drm_device *drm = dev_get_drvdata(master);
  62. struct msm_drm_private *priv = drm->dev_private;
  63. struct msm_edp *edp;
  64. DBG("");
  65. edp = edp_init(to_platform_device(dev));
  66. if (IS_ERR(edp))
  67. return PTR_ERR(edp);
  68. priv->edp = edp;
  69. return 0;
  70. }
  71. static void edp_unbind(struct device *dev, struct device *master, void *data)
  72. {
  73. struct drm_device *drm = dev_get_drvdata(master);
  74. struct msm_drm_private *priv = drm->dev_private;
  75. DBG("");
  76. if (priv->edp) {
  77. edp_destroy(to_platform_device(dev));
  78. priv->edp = NULL;
  79. }
  80. }
  81. static const struct component_ops edp_ops = {
  82. .bind = edp_bind,
  83. .unbind = edp_unbind,
  84. };
  85. static int edp_dev_probe(struct platform_device *pdev)
  86. {
  87. DBG("");
  88. return component_add(&pdev->dev, &edp_ops);
  89. }
  90. static int edp_dev_remove(struct platform_device *pdev)
  91. {
  92. DBG("");
  93. component_del(&pdev->dev, &edp_ops);
  94. return 0;
  95. }
  96. static const struct of_device_id dt_match[] = {
  97. { .compatible = "qcom,mdss-edp" },
  98. {}
  99. };
  100. static struct platform_driver edp_driver = {
  101. .probe = edp_dev_probe,
  102. .remove = edp_dev_remove,
  103. .driver = {
  104. .name = "msm_edp",
  105. .of_match_table = dt_match,
  106. },
  107. };
  108. void __init msm_edp_register(void)
  109. {
  110. DBG("");
  111. platform_driver_register(&edp_driver);
  112. }
  113. void __exit msm_edp_unregister(void)
  114. {
  115. DBG("");
  116. platform_driver_unregister(&edp_driver);
  117. }
  118. /* Second part of initialization, the drm/kms level modeset_init */
  119. int msm_edp_modeset_init(struct msm_edp *edp, struct drm_device *dev,
  120. struct drm_encoder *encoder)
  121. {
  122. struct platform_device *pdev = edp->pdev;
  123. struct msm_drm_private *priv = dev->dev_private;
  124. int ret;
  125. edp->encoder = encoder;
  126. edp->dev = dev;
  127. edp->bridge = msm_edp_bridge_init(edp);
  128. if (IS_ERR(edp->bridge)) {
  129. ret = PTR_ERR(edp->bridge);
  130. dev_err(dev->dev, "failed to create eDP bridge: %d\n", ret);
  131. edp->bridge = NULL;
  132. goto fail;
  133. }
  134. edp->connector = msm_edp_connector_init(edp);
  135. if (IS_ERR(edp->connector)) {
  136. ret = PTR_ERR(edp->connector);
  137. dev_err(dev->dev, "failed to create eDP connector: %d\n", ret);
  138. edp->connector = NULL;
  139. goto fail;
  140. }
  141. edp->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
  142. if (edp->irq < 0) {
  143. ret = edp->irq;
  144. dev_err(dev->dev, "failed to get IRQ: %d\n", ret);
  145. goto fail;
  146. }
  147. ret = devm_request_irq(&pdev->dev, edp->irq,
  148. edp_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
  149. "edp_isr", edp);
  150. if (ret < 0) {
  151. dev_err(dev->dev, "failed to request IRQ%u: %d\n",
  152. edp->irq, ret);
  153. goto fail;
  154. }
  155. encoder->bridge = edp->bridge;
  156. priv->bridges[priv->num_bridges++] = edp->bridge;
  157. priv->connectors[priv->num_connectors++] = edp->connector;
  158. return 0;
  159. fail:
  160. /* bridge/connector are normally destroyed by drm */
  161. if (edp->bridge) {
  162. edp_bridge_destroy(edp->bridge);
  163. edp->bridge = NULL;
  164. }
  165. if (edp->connector) {
  166. edp->connector->funcs->destroy(edp->connector);
  167. edp->connector = NULL;
  168. }
  169. return ret;
  170. }