hdmi_phy.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/of.h>
  6. #include <linux/platform_device.h>
  7. #include "hdmi.h"
  8. static int msm_hdmi_phy_resource_init(struct hdmi_phy *phy)
  9. {
  10. struct hdmi_phy_cfg *cfg = phy->cfg;
  11. struct device *dev = &phy->pdev->dev;
  12. int i, ret;
  13. phy->regs = devm_kcalloc(dev, cfg->num_regs, sizeof(phy->regs[0]),
  14. GFP_KERNEL);
  15. if (!phy->regs)
  16. return -ENOMEM;
  17. phy->clks = devm_kcalloc(dev, cfg->num_clks, sizeof(phy->clks[0]),
  18. GFP_KERNEL);
  19. if (!phy->clks)
  20. return -ENOMEM;
  21. for (i = 0; i < cfg->num_regs; i++)
  22. phy->regs[i].supply = cfg->reg_names[i];
  23. ret = devm_regulator_bulk_get(dev, cfg->num_regs, phy->regs);
  24. if (ret) {
  25. if (ret != -EPROBE_DEFER)
  26. DRM_DEV_ERROR(dev, "failed to get phy regulators: %d\n", ret);
  27. return ret;
  28. }
  29. for (i = 0; i < cfg->num_clks; i++) {
  30. struct clk *clk;
  31. clk = msm_clk_get(phy->pdev, cfg->clk_names[i]);
  32. if (IS_ERR(clk)) {
  33. ret = PTR_ERR(clk);
  34. DRM_DEV_ERROR(dev, "failed to get phy clock: %s (%d)\n",
  35. cfg->clk_names[i], ret);
  36. return ret;
  37. }
  38. phy->clks[i] = clk;
  39. }
  40. return 0;
  41. }
  42. int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy)
  43. {
  44. struct hdmi_phy_cfg *cfg = phy->cfg;
  45. struct device *dev = &phy->pdev->dev;
  46. int i, ret = 0;
  47. ret = pm_runtime_resume_and_get(dev);
  48. if (ret) {
  49. DRM_DEV_ERROR(dev, "runtime resume failed: %d\n", ret);
  50. return ret;
  51. }
  52. ret = regulator_bulk_enable(cfg->num_regs, phy->regs);
  53. if (ret) {
  54. DRM_DEV_ERROR(dev, "failed to enable regulators: (%d)\n", ret);
  55. return ret;
  56. }
  57. for (i = 0; i < cfg->num_clks; i++) {
  58. ret = clk_prepare_enable(phy->clks[i]);
  59. if (ret)
  60. DRM_DEV_ERROR(dev, "failed to enable clock: %s (%d)\n",
  61. cfg->clk_names[i], ret);
  62. }
  63. return ret;
  64. }
  65. void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy)
  66. {
  67. struct hdmi_phy_cfg *cfg = phy->cfg;
  68. struct device *dev = &phy->pdev->dev;
  69. int i;
  70. for (i = cfg->num_clks - 1; i >= 0; i--)
  71. clk_disable_unprepare(phy->clks[i]);
  72. regulator_bulk_disable(cfg->num_regs, phy->regs);
  73. pm_runtime_put_sync(dev);
  74. }
  75. void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock)
  76. {
  77. if (!phy || !phy->cfg->powerup)
  78. return;
  79. phy->cfg->powerup(phy, pixclock);
  80. }
  81. void msm_hdmi_phy_powerdown(struct hdmi_phy *phy)
  82. {
  83. if (!phy || !phy->cfg->powerdown)
  84. return;
  85. phy->cfg->powerdown(phy);
  86. }
  87. static int msm_hdmi_phy_pll_init(struct platform_device *pdev,
  88. enum hdmi_phy_type type)
  89. {
  90. int ret;
  91. switch (type) {
  92. case MSM_HDMI_PHY_8960:
  93. ret = msm_hdmi_pll_8960_init(pdev);
  94. break;
  95. case MSM_HDMI_PHY_8996:
  96. ret = msm_hdmi_pll_8996_init(pdev);
  97. break;
  98. case MSM_HDMI_PHY_8998:
  99. ret = msm_hdmi_pll_8998_init(pdev);
  100. break;
  101. /*
  102. * we don't have PLL support for these, don't report an error for now
  103. */
  104. case MSM_HDMI_PHY_8x60:
  105. case MSM_HDMI_PHY_8x74:
  106. default:
  107. ret = 0;
  108. break;
  109. }
  110. return ret;
  111. }
  112. static int msm_hdmi_phy_probe(struct platform_device *pdev)
  113. {
  114. struct device *dev = &pdev->dev;
  115. struct hdmi_phy *phy;
  116. int ret;
  117. phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
  118. if (!phy)
  119. return -ENODEV;
  120. phy->cfg = (struct hdmi_phy_cfg *)of_device_get_match_data(dev);
  121. if (!phy->cfg)
  122. return -ENODEV;
  123. phy->mmio = msm_ioremap(pdev, "hdmi_phy");
  124. if (IS_ERR(phy->mmio)) {
  125. DRM_DEV_ERROR(dev, "%s: failed to map phy base\n", __func__);
  126. return -ENOMEM;
  127. }
  128. phy->pdev = pdev;
  129. ret = msm_hdmi_phy_resource_init(phy);
  130. if (ret)
  131. return ret;
  132. pm_runtime_enable(&pdev->dev);
  133. ret = msm_hdmi_phy_resource_enable(phy);
  134. if (ret)
  135. return ret;
  136. ret = msm_hdmi_phy_pll_init(pdev, phy->cfg->type);
  137. if (ret) {
  138. DRM_DEV_ERROR(dev, "couldn't init PLL\n");
  139. msm_hdmi_phy_resource_disable(phy);
  140. return ret;
  141. }
  142. msm_hdmi_phy_resource_disable(phy);
  143. platform_set_drvdata(pdev, phy);
  144. return 0;
  145. }
  146. static void msm_hdmi_phy_remove(struct platform_device *pdev)
  147. {
  148. pm_runtime_disable(&pdev->dev);
  149. }
  150. static const struct of_device_id msm_hdmi_phy_dt_match[] = {
  151. { .compatible = "qcom,hdmi-phy-8660",
  152. .data = &msm_hdmi_phy_8x60_cfg },
  153. { .compatible = "qcom,hdmi-phy-8960",
  154. .data = &msm_hdmi_phy_8960_cfg },
  155. { .compatible = "qcom,hdmi-phy-8974",
  156. .data = &msm_hdmi_phy_8x74_cfg },
  157. { .compatible = "qcom,hdmi-phy-8084",
  158. .data = &msm_hdmi_phy_8x74_cfg },
  159. { .compatible = "qcom,hdmi-phy-8996",
  160. .data = &msm_hdmi_phy_8996_cfg },
  161. { .compatible = "qcom,hdmi-phy-8998",
  162. .data = &msm_hdmi_phy_8998_cfg },
  163. {}
  164. };
  165. static struct platform_driver msm_hdmi_phy_platform_driver = {
  166. .probe = msm_hdmi_phy_probe,
  167. .remove = msm_hdmi_phy_remove,
  168. .driver = {
  169. .name = "msm_hdmi_phy",
  170. .of_match_table = msm_hdmi_phy_dt_match,
  171. },
  172. };
  173. void __init msm_hdmi_phy_driver_register(void)
  174. {
  175. platform_driver_register(&msm_hdmi_phy_platform_driver);
  176. }
  177. void __exit msm_hdmi_phy_driver_unregister(void)
  178. {
  179. platform_driver_unregister(&msm_hdmi_phy_platform_driver);
  180. }