dsi.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 int dsi_get_phy(struct msm_dsi *msm_dsi)
  23. {
  24. struct platform_device *pdev = msm_dsi->pdev;
  25. struct platform_device *phy_pdev;
  26. struct device_node *phy_node;
  27. phy_node = of_parse_phandle(pdev->dev.of_node, "qcom,dsi-phy", 0);
  28. if (!phy_node) {
  29. dev_err(&pdev->dev, "cannot find phy device\n");
  30. return -ENXIO;
  31. }
  32. phy_pdev = of_find_device_by_node(phy_node);
  33. if (phy_pdev)
  34. msm_dsi->phy = platform_get_drvdata(phy_pdev);
  35. of_node_put(phy_node);
  36. if (!phy_pdev || !msm_dsi->phy) {
  37. dev_err(&pdev->dev, "%s: phy driver is not ready\n", __func__);
  38. return -EPROBE_DEFER;
  39. }
  40. msm_dsi->phy_dev = get_device(&phy_pdev->dev);
  41. return 0;
  42. }
  43. static void dsi_destroy(struct msm_dsi *msm_dsi)
  44. {
  45. if (!msm_dsi)
  46. return;
  47. msm_dsi_manager_unregister(msm_dsi);
  48. if (msm_dsi->phy_dev) {
  49. put_device(msm_dsi->phy_dev);
  50. msm_dsi->phy = NULL;
  51. msm_dsi->phy_dev = NULL;
  52. }
  53. if (msm_dsi->host) {
  54. msm_dsi_host_destroy(msm_dsi->host);
  55. msm_dsi->host = NULL;
  56. }
  57. platform_set_drvdata(msm_dsi->pdev, NULL);
  58. }
  59. static struct msm_dsi *dsi_init(struct platform_device *pdev)
  60. {
  61. struct msm_dsi *msm_dsi = NULL;
  62. int ret;
  63. if (!pdev) {
  64. ret = -ENXIO;
  65. goto fail;
  66. }
  67. msm_dsi = devm_kzalloc(&pdev->dev, sizeof(*msm_dsi), GFP_KERNEL);
  68. if (!msm_dsi) {
  69. ret = -ENOMEM;
  70. goto fail;
  71. }
  72. DBG("dsi probed=%p", msm_dsi);
  73. msm_dsi->pdev = pdev;
  74. platform_set_drvdata(pdev, msm_dsi);
  75. /* Init dsi host */
  76. ret = msm_dsi_host_init(msm_dsi);
  77. if (ret)
  78. goto fail;
  79. /* GET dsi PHY */
  80. ret = dsi_get_phy(msm_dsi);
  81. if (ret)
  82. goto fail;
  83. /* Register to dsi manager */
  84. ret = msm_dsi_manager_register(msm_dsi);
  85. if (ret)
  86. goto fail;
  87. return msm_dsi;
  88. fail:
  89. if (msm_dsi)
  90. dsi_destroy(msm_dsi);
  91. return ERR_PTR(ret);
  92. }
  93. static int dsi_bind(struct device *dev, struct device *master, void *data)
  94. {
  95. struct drm_device *drm = dev_get_drvdata(master);
  96. struct msm_drm_private *priv = drm->dev_private;
  97. struct platform_device *pdev = to_platform_device(dev);
  98. struct msm_dsi *msm_dsi;
  99. DBG("");
  100. msm_dsi = dsi_init(pdev);
  101. if (IS_ERR(msm_dsi))
  102. return PTR_ERR(msm_dsi);
  103. priv->dsi[msm_dsi->id] = msm_dsi;
  104. return 0;
  105. }
  106. static void dsi_unbind(struct device *dev, struct device *master,
  107. void *data)
  108. {
  109. struct drm_device *drm = dev_get_drvdata(master);
  110. struct msm_drm_private *priv = drm->dev_private;
  111. struct msm_dsi *msm_dsi = dev_get_drvdata(dev);
  112. int id = msm_dsi->id;
  113. if (priv->dsi[id]) {
  114. dsi_destroy(msm_dsi);
  115. priv->dsi[id] = NULL;
  116. }
  117. }
  118. static const struct component_ops dsi_ops = {
  119. .bind = dsi_bind,
  120. .unbind = dsi_unbind,
  121. };
  122. static int dsi_dev_probe(struct platform_device *pdev)
  123. {
  124. return component_add(&pdev->dev, &dsi_ops);
  125. }
  126. static int dsi_dev_remove(struct platform_device *pdev)
  127. {
  128. DBG("");
  129. component_del(&pdev->dev, &dsi_ops);
  130. return 0;
  131. }
  132. static const struct of_device_id dt_match[] = {
  133. { .compatible = "qcom,mdss-dsi-ctrl" },
  134. {}
  135. };
  136. static struct platform_driver dsi_driver = {
  137. .probe = dsi_dev_probe,
  138. .remove = dsi_dev_remove,
  139. .driver = {
  140. .name = "msm_dsi",
  141. .of_match_table = dt_match,
  142. },
  143. };
  144. void __init msm_dsi_register(void)
  145. {
  146. DBG("");
  147. msm_dsi_phy_driver_register();
  148. platform_driver_register(&dsi_driver);
  149. }
  150. void __exit msm_dsi_unregister(void)
  151. {
  152. DBG("");
  153. msm_dsi_phy_driver_unregister();
  154. platform_driver_unregister(&dsi_driver);
  155. }
  156. int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,
  157. struct drm_encoder *encoders[MSM_DSI_ENCODER_NUM])
  158. {
  159. struct msm_drm_private *priv = dev->dev_private;
  160. int ret, i;
  161. if (WARN_ON(!encoders[MSM_DSI_VIDEO_ENCODER_ID] ||
  162. !encoders[MSM_DSI_CMD_ENCODER_ID]))
  163. return -EINVAL;
  164. msm_dsi->dev = dev;
  165. ret = msm_dsi_host_modeset_init(msm_dsi->host, dev);
  166. if (ret) {
  167. dev_err(dev->dev, "failed to modeset init host: %d\n", ret);
  168. goto fail;
  169. }
  170. msm_dsi->bridge = msm_dsi_manager_bridge_init(msm_dsi->id);
  171. if (IS_ERR(msm_dsi->bridge)) {
  172. ret = PTR_ERR(msm_dsi->bridge);
  173. dev_err(dev->dev, "failed to create dsi bridge: %d\n", ret);
  174. msm_dsi->bridge = NULL;
  175. goto fail;
  176. }
  177. for (i = 0; i < MSM_DSI_ENCODER_NUM; i++) {
  178. encoders[i]->bridge = msm_dsi->bridge;
  179. msm_dsi->encoders[i] = encoders[i];
  180. }
  181. msm_dsi->connector = msm_dsi_manager_connector_init(msm_dsi->id);
  182. if (IS_ERR(msm_dsi->connector)) {
  183. ret = PTR_ERR(msm_dsi->connector);
  184. dev_err(dev->dev, "failed to create dsi connector: %d\n", ret);
  185. msm_dsi->connector = NULL;
  186. goto fail;
  187. }
  188. priv->bridges[priv->num_bridges++] = msm_dsi->bridge;
  189. priv->connectors[priv->num_connectors++] = msm_dsi->connector;
  190. return 0;
  191. fail:
  192. if (msm_dsi) {
  193. /* bridge/connector are normally destroyed by drm: */
  194. if (msm_dsi->bridge) {
  195. msm_dsi_manager_bridge_destroy(msm_dsi->bridge);
  196. msm_dsi->bridge = NULL;
  197. }
  198. if (msm_dsi->connector) {
  199. msm_dsi->connector->funcs->destroy(msm_dsi->connector);
  200. msm_dsi->connector = NULL;
  201. }
  202. }
  203. return ret;
  204. }