dsi.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (c) 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 "dsi.h"
  14. struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi)
  15. {
  16. if (!msm_dsi || !msm_dsi->panel)
  17. return NULL;
  18. return (msm_dsi->panel_flags & MIPI_DSI_MODE_VIDEO) ?
  19. msm_dsi->encoders[MSM_DSI_VIDEO_ENCODER_ID] :
  20. msm_dsi->encoders[MSM_DSI_CMD_ENCODER_ID];
  21. }
  22. static void dsi_destroy(struct msm_dsi *msm_dsi)
  23. {
  24. if (!msm_dsi)
  25. return;
  26. msm_dsi_manager_unregister(msm_dsi);
  27. if (msm_dsi->host) {
  28. msm_dsi_host_destroy(msm_dsi->host);
  29. msm_dsi->host = NULL;
  30. }
  31. platform_set_drvdata(msm_dsi->pdev, NULL);
  32. }
  33. static struct msm_dsi *dsi_init(struct platform_device *pdev)
  34. {
  35. struct msm_dsi *msm_dsi = NULL;
  36. int ret;
  37. if (!pdev) {
  38. dev_err(&pdev->dev, "no dsi device\n");
  39. ret = -ENXIO;
  40. goto fail;
  41. }
  42. msm_dsi = devm_kzalloc(&pdev->dev, sizeof(*msm_dsi), GFP_KERNEL);
  43. if (!msm_dsi) {
  44. ret = -ENOMEM;
  45. goto fail;
  46. }
  47. DBG("dsi probed=%p", msm_dsi);
  48. msm_dsi->pdev = pdev;
  49. platform_set_drvdata(pdev, msm_dsi);
  50. /* Init dsi host */
  51. ret = msm_dsi_host_init(msm_dsi);
  52. if (ret)
  53. goto fail;
  54. /* Register to dsi manager */
  55. ret = msm_dsi_manager_register(msm_dsi);
  56. if (ret)
  57. goto fail;
  58. return msm_dsi;
  59. fail:
  60. if (msm_dsi)
  61. dsi_destroy(msm_dsi);
  62. return ERR_PTR(ret);
  63. }
  64. static int dsi_bind(struct device *dev, struct device *master, void *data)
  65. {
  66. struct drm_device *drm = dev_get_drvdata(master);
  67. struct msm_drm_private *priv = drm->dev_private;
  68. struct platform_device *pdev = to_platform_device(dev);
  69. struct msm_dsi *msm_dsi;
  70. DBG("");
  71. msm_dsi = dsi_init(pdev);
  72. if (IS_ERR(msm_dsi))
  73. return PTR_ERR(msm_dsi);
  74. priv->dsi[msm_dsi->id] = msm_dsi;
  75. return 0;
  76. }
  77. static void dsi_unbind(struct device *dev, struct device *master,
  78. void *data)
  79. {
  80. struct drm_device *drm = dev_get_drvdata(master);
  81. struct msm_drm_private *priv = drm->dev_private;
  82. struct msm_dsi *msm_dsi = dev_get_drvdata(dev);
  83. int id = msm_dsi->id;
  84. if (priv->dsi[id]) {
  85. dsi_destroy(msm_dsi);
  86. priv->dsi[id] = NULL;
  87. }
  88. }
  89. static const struct component_ops dsi_ops = {
  90. .bind = dsi_bind,
  91. .unbind = dsi_unbind,
  92. };
  93. static int dsi_dev_probe(struct platform_device *pdev)
  94. {
  95. return component_add(&pdev->dev, &dsi_ops);
  96. }
  97. static int dsi_dev_remove(struct platform_device *pdev)
  98. {
  99. DBG("");
  100. component_del(&pdev->dev, &dsi_ops);
  101. return 0;
  102. }
  103. static const struct of_device_id dt_match[] = {
  104. { .compatible = "qcom,mdss-dsi-ctrl" },
  105. {}
  106. };
  107. static struct platform_driver dsi_driver = {
  108. .probe = dsi_dev_probe,
  109. .remove = dsi_dev_remove,
  110. .driver = {
  111. .name = "msm_dsi",
  112. .of_match_table = dt_match,
  113. },
  114. };
  115. void __init msm_dsi_register(void)
  116. {
  117. DBG("");
  118. platform_driver_register(&dsi_driver);
  119. }
  120. void __exit msm_dsi_unregister(void)
  121. {
  122. DBG("");
  123. platform_driver_unregister(&dsi_driver);
  124. }
  125. int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,
  126. struct drm_encoder *encoders[MSM_DSI_ENCODER_NUM])
  127. {
  128. struct msm_drm_private *priv = dev->dev_private;
  129. int ret, i;
  130. if (WARN_ON(!encoders[MSM_DSI_VIDEO_ENCODER_ID] ||
  131. !encoders[MSM_DSI_CMD_ENCODER_ID]))
  132. return -EINVAL;
  133. msm_dsi->dev = dev;
  134. ret = msm_dsi_host_modeset_init(msm_dsi->host, dev);
  135. if (ret) {
  136. dev_err(dev->dev, "failed to modeset init host: %d\n", ret);
  137. goto fail;
  138. }
  139. msm_dsi->bridge = msm_dsi_manager_bridge_init(msm_dsi->id);
  140. if (IS_ERR(msm_dsi->bridge)) {
  141. ret = PTR_ERR(msm_dsi->bridge);
  142. dev_err(dev->dev, "failed to create dsi bridge: %d\n", ret);
  143. msm_dsi->bridge = NULL;
  144. goto fail;
  145. }
  146. for (i = 0; i < MSM_DSI_ENCODER_NUM; i++) {
  147. encoders[i]->bridge = msm_dsi->bridge;
  148. msm_dsi->encoders[i] = encoders[i];
  149. }
  150. msm_dsi->connector = msm_dsi_manager_connector_init(msm_dsi->id);
  151. if (IS_ERR(msm_dsi->connector)) {
  152. ret = PTR_ERR(msm_dsi->connector);
  153. dev_err(dev->dev, "failed to create dsi connector: %d\n", ret);
  154. msm_dsi->connector = NULL;
  155. goto fail;
  156. }
  157. priv->bridges[priv->num_bridges++] = msm_dsi->bridge;
  158. priv->connectors[priv->num_connectors++] = msm_dsi->connector;
  159. return 0;
  160. fail:
  161. if (msm_dsi) {
  162. /* bridge/connector are normally destroyed by drm: */
  163. if (msm_dsi->bridge) {
  164. msm_dsi_manager_bridge_destroy(msm_dsi->bridge);
  165. msm_dsi->bridge = NULL;
  166. }
  167. if (msm_dsi->connector) {
  168. msm_dsi->connector->funcs->destroy(msm_dsi->connector);
  169. msm_dsi->connector = NULL;
  170. }
  171. }
  172. return ret;
  173. }