phy-qcom-ufs-qmp-14nm.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Copyright (c) 2013-2015, 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. */
  14. #include "phy-qcom-ufs-qmp-14nm.h"
  15. #define UFS_PHY_NAME "ufs_phy_qmp_14nm"
  16. #define UFS_PHY_VDDA_PHY_UV (925000)
  17. static
  18. int ufs_qcom_phy_qmp_14nm_phy_calibrate(struct ufs_qcom_phy *ufs_qcom_phy,
  19. bool is_rate_B)
  20. {
  21. int tbl_size_A = ARRAY_SIZE(phy_cal_table_rate_A);
  22. int tbl_size_B = ARRAY_SIZE(phy_cal_table_rate_B);
  23. int err;
  24. err = ufs_qcom_phy_calibrate(ufs_qcom_phy, phy_cal_table_rate_A,
  25. tbl_size_A, phy_cal_table_rate_B, tbl_size_B, is_rate_B);
  26. if (err)
  27. dev_err(ufs_qcom_phy->dev,
  28. "%s: ufs_qcom_phy_calibrate() failed %d\n",
  29. __func__, err);
  30. return err;
  31. }
  32. static
  33. void ufs_qcom_phy_qmp_14nm_advertise_quirks(struct ufs_qcom_phy *phy_common)
  34. {
  35. phy_common->quirks =
  36. UFS_QCOM_PHY_QUIRK_HIBERN8_EXIT_AFTER_PHY_PWR_COLLAPSE;
  37. }
  38. static int ufs_qcom_phy_qmp_14nm_init(struct phy *generic_phy)
  39. {
  40. struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy);
  41. bool is_rate_B = false;
  42. int ret;
  43. if (phy_common->mode == PHY_MODE_UFS_HS_B)
  44. is_rate_B = true;
  45. ret = ufs_qcom_phy_qmp_14nm_phy_calibrate(phy_common, is_rate_B);
  46. if (!ret)
  47. /* phy calibrated, but yet to be started */
  48. phy_common->is_started = false;
  49. return ret;
  50. }
  51. static int ufs_qcom_phy_qmp_14nm_exit(struct phy *generic_phy)
  52. {
  53. return 0;
  54. }
  55. static
  56. int ufs_qcom_phy_qmp_14nm_set_mode(struct phy *generic_phy, enum phy_mode mode)
  57. {
  58. struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy);
  59. phy_common->mode = PHY_MODE_INVALID;
  60. if (mode > 0)
  61. phy_common->mode = mode;
  62. return 0;
  63. }
  64. static
  65. void ufs_qcom_phy_qmp_14nm_power_control(struct ufs_qcom_phy *phy, bool val)
  66. {
  67. writel_relaxed(val ? 0x1 : 0x0, phy->mmio + UFS_PHY_POWER_DOWN_CONTROL);
  68. /*
  69. * Before any transactions involving PHY, ensure PHY knows
  70. * that it's analog rail is powered ON (or OFF).
  71. */
  72. mb();
  73. }
  74. static inline
  75. void ufs_qcom_phy_qmp_14nm_set_tx_lane_enable(struct ufs_qcom_phy *phy, u32 val)
  76. {
  77. /*
  78. * 14nm PHY does not have TX_LANE_ENABLE register.
  79. * Implement this function so as not to propagate error to caller.
  80. */
  81. }
  82. static inline void ufs_qcom_phy_qmp_14nm_start_serdes(struct ufs_qcom_phy *phy)
  83. {
  84. u32 tmp;
  85. tmp = readl_relaxed(phy->mmio + UFS_PHY_PHY_START);
  86. tmp &= ~MASK_SERDES_START;
  87. tmp |= (1 << OFFSET_SERDES_START);
  88. writel_relaxed(tmp, phy->mmio + UFS_PHY_PHY_START);
  89. /* Ensure register value is committed */
  90. mb();
  91. }
  92. static int ufs_qcom_phy_qmp_14nm_is_pcs_ready(struct ufs_qcom_phy *phy_common)
  93. {
  94. int err = 0;
  95. u32 val;
  96. err = readl_poll_timeout(phy_common->mmio + UFS_PHY_PCS_READY_STATUS,
  97. val, (val & MASK_PCS_READY), 10, 1000000);
  98. if (err)
  99. dev_err(phy_common->dev, "%s: poll for pcs failed err = %d\n",
  100. __func__, err);
  101. return err;
  102. }
  103. static const struct phy_ops ufs_qcom_phy_qmp_14nm_phy_ops = {
  104. .init = ufs_qcom_phy_qmp_14nm_init,
  105. .exit = ufs_qcom_phy_qmp_14nm_exit,
  106. .power_on = ufs_qcom_phy_power_on,
  107. .power_off = ufs_qcom_phy_power_off,
  108. .set_mode = ufs_qcom_phy_qmp_14nm_set_mode,
  109. .owner = THIS_MODULE,
  110. };
  111. static struct ufs_qcom_phy_specific_ops phy_14nm_ops = {
  112. .start_serdes = ufs_qcom_phy_qmp_14nm_start_serdes,
  113. .is_physical_coding_sublayer_ready = ufs_qcom_phy_qmp_14nm_is_pcs_ready,
  114. .set_tx_lane_enable = ufs_qcom_phy_qmp_14nm_set_tx_lane_enable,
  115. .power_control = ufs_qcom_phy_qmp_14nm_power_control,
  116. };
  117. static int ufs_qcom_phy_qmp_14nm_probe(struct platform_device *pdev)
  118. {
  119. struct device *dev = &pdev->dev;
  120. struct phy *generic_phy;
  121. struct ufs_qcom_phy_qmp_14nm *phy;
  122. struct ufs_qcom_phy *phy_common;
  123. int err = 0;
  124. phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
  125. if (!phy) {
  126. err = -ENOMEM;
  127. goto out;
  128. }
  129. phy_common = &phy->common_cfg;
  130. generic_phy = ufs_qcom_phy_generic_probe(pdev, phy_common,
  131. &ufs_qcom_phy_qmp_14nm_phy_ops, &phy_14nm_ops);
  132. if (!generic_phy) {
  133. err = -EIO;
  134. goto out;
  135. }
  136. err = ufs_qcom_phy_init_clks(phy_common);
  137. if (err)
  138. goto out;
  139. err = ufs_qcom_phy_init_vregulators(phy_common);
  140. if (err)
  141. goto out;
  142. phy_common->vdda_phy.max_uV = UFS_PHY_VDDA_PHY_UV;
  143. phy_common->vdda_phy.min_uV = UFS_PHY_VDDA_PHY_UV;
  144. ufs_qcom_phy_qmp_14nm_advertise_quirks(phy_common);
  145. phy_set_drvdata(generic_phy, phy);
  146. strlcpy(phy_common->name, UFS_PHY_NAME, sizeof(phy_common->name));
  147. out:
  148. return err;
  149. }
  150. static const struct of_device_id ufs_qcom_phy_qmp_14nm_of_match[] = {
  151. {.compatible = "qcom,ufs-phy-qmp-14nm"},
  152. {.compatible = "qcom,msm8996-ufs-phy-qmp-14nm"},
  153. {},
  154. };
  155. MODULE_DEVICE_TABLE(of, ufs_qcom_phy_qmp_14nm_of_match);
  156. static struct platform_driver ufs_qcom_phy_qmp_14nm_driver = {
  157. .probe = ufs_qcom_phy_qmp_14nm_probe,
  158. .driver = {
  159. .of_match_table = ufs_qcom_phy_qmp_14nm_of_match,
  160. .name = "ufs_qcom_phy_qmp_14nm",
  161. },
  162. };
  163. module_platform_driver(ufs_qcom_phy_qmp_14nm_driver);
  164. MODULE_DESCRIPTION("Universal Flash Storage (UFS) QCOM PHY QMP 14nm");
  165. MODULE_LICENSE("GPL v2");