phy-qcom-ufs-qrbtc-sdm845.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016, 2019-2021, Linux Foundation. All rights reserved.
  4. * All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include "phy-qcom-ufs-qrbtc-sdm845.h"
  17. #define UFS_PHY_NAME "ufs_phy_qrbtc_sdm845"
  18. static
  19. int ufs_qcom_phy_qrbtc_sdm845_phy_calibrate(struct phy *generic_phy)
  20. {
  21. int err;
  22. int tbl_size_A, tbl_size_B;
  23. struct ufs_qcom_phy_calibration *tbl_A, *tbl_B;
  24. struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(generic_phy);
  25. bool is_rate_B;
  26. tbl_A = phy_cal_table_rate_A;
  27. tbl_size_A = ARRAY_SIZE(phy_cal_table_rate_A);
  28. tbl_size_B = ARRAY_SIZE(phy_cal_table_rate_B);
  29. tbl_B = phy_cal_table_rate_B;
  30. is_rate_B = (ufs_qcom_phy->mode == PHY_MODE_UFS_HS_B) ? true : false;
  31. err = ufs_qcom_phy_calibrate(ufs_qcom_phy,
  32. tbl_A, tbl_size_A,
  33. tbl_B, tbl_size_B,
  34. is_rate_B);
  35. if (err)
  36. dev_err(ufs_qcom_phy->dev,
  37. "%s: ufs_qcom_phy_calibrate() failed %d\n",
  38. __func__, err);
  39. return err;
  40. }
  41. static int
  42. ufs_qcom_phy_qrbtc_sdm845_is_pcs_ready(struct ufs_qcom_phy *phy_common)
  43. {
  44. int err = 0;
  45. u32 val;
  46. /*
  47. * The value we are polling for is 0x3D which represents the
  48. * following masks:
  49. * RESET_SM field: 0x5
  50. * RESTRIMDONE bit: BIT(3)
  51. * PLLLOCK bit: BIT(4)
  52. * READY bit: BIT(5)
  53. */
  54. #define QSERDES_COM_RESET_SM_REG_POLL_VAL 0x3D
  55. err = readl_poll_timeout(phy_common->mmio + QSERDES_COM_RESET_SM,
  56. val, (val == QSERDES_COM_RESET_SM_REG_POLL_VAL), 10, 1000000);
  57. if (err)
  58. dev_err(phy_common->dev, "%s: poll for pcs failed err = %d\n",
  59. __func__, err);
  60. return err;
  61. }
  62. static void ufs_qcom_phy_qrbtc_sdm845_start_serdes(struct ufs_qcom_phy *phy)
  63. {
  64. u32 temp;
  65. writel_relaxed(0x01, phy->mmio + UFS_PHY_POWER_DOWN_CONTROL);
  66. temp = readl_relaxed(phy->mmio + UFS_PHY_PHY_START);
  67. temp |= 0x1;
  68. writel_relaxed(temp, phy->mmio + UFS_PHY_PHY_START);
  69. /* Ensure register value is committed */
  70. mb();
  71. }
  72. static int ufs_qcom_phy_qrbtc_sdm845_init(struct phy *generic_phy)
  73. {
  74. struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy);
  75. int ret;
  76. ret = ufs_qcom_phy_get_reset(phy_common);
  77. if (ret)
  78. dev_err(phy_common->dev, "Failed to get reset control %d\n", ret);
  79. return ret;
  80. }
  81. static int ufs_qcom_phy_qrbtc_sdm845_exit(struct phy *generic_phy)
  82. {
  83. return 0;
  84. }
  85. static
  86. int ufs_qcom_phy_qrbtc_sdm845_set_mode(struct phy *generic_phy,
  87. enum phy_mode mode, int submode)
  88. {
  89. struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy);
  90. phy_common->mode = PHY_MODE_INVALID;
  91. if (mode > 0)
  92. phy_common->mode = mode;
  93. phy_common->submode = submode;
  94. return 0;
  95. }
  96. static const struct phy_ops ufs_qcom_phy_qrbtc_sdm845_phy_ops = {
  97. .init = ufs_qcom_phy_qrbtc_sdm845_init,
  98. .exit = ufs_qcom_phy_qrbtc_sdm845_exit,
  99. .set_mode = ufs_qcom_phy_qrbtc_sdm845_set_mode,
  100. .calibrate = ufs_qcom_phy_qrbtc_sdm845_phy_calibrate,
  101. .owner = THIS_MODULE,
  102. };
  103. static struct ufs_qcom_phy_specific_ops phy_qrbtc_sdm845_ops = {
  104. .start_serdes = ufs_qcom_phy_qrbtc_sdm845_start_serdes,
  105. .is_physical_coding_sublayer_ready =
  106. ufs_qcom_phy_qrbtc_sdm845_is_pcs_ready,
  107. };
  108. static int ufs_qcom_phy_qrbtc_sdm845_probe(struct platform_device *pdev)
  109. {
  110. struct device *dev = &pdev->dev;
  111. struct phy *generic_phy;
  112. struct ufs_qcom_phy_qrbtc_sdm845 *phy;
  113. int err = 0;
  114. phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
  115. if (!phy) {
  116. err = -ENOMEM;
  117. goto out;
  118. }
  119. generic_phy = ufs_qcom_phy_generic_probe(pdev, &phy->common_cfg,
  120. &ufs_qcom_phy_qrbtc_sdm845_phy_ops, &phy_qrbtc_sdm845_ops);
  121. if (!generic_phy) {
  122. dev_err(dev, "%s: ufs_qcom_phy_generic_probe() failed\n",
  123. __func__);
  124. err = -EIO;
  125. goto out;
  126. }
  127. phy_set_drvdata(generic_phy, phy);
  128. strscpy(phy->common_cfg.name, UFS_PHY_NAME,
  129. sizeof(phy->common_cfg.name));
  130. out:
  131. return err;
  132. }
  133. static const struct of_device_id ufs_qcom_phy_qrbtc_sdm845_of_match[] = {
  134. {.compatible = "qcom,ufs-phy-qrbtc-sdm845"},
  135. {},
  136. };
  137. MODULE_DEVICE_TABLE(of, ufs_qcom_phy_qrbtc_sdm845_of_match);
  138. static struct platform_driver ufs_qcom_phy_qrbtc_sdm845_driver = {
  139. .probe = ufs_qcom_phy_qrbtc_sdm845_probe,
  140. .driver = {
  141. .of_match_table = ufs_qcom_phy_qrbtc_sdm845_of_match,
  142. .name = "ufs_qcom_phy_qrbtc_sdm845",
  143. },
  144. };
  145. module_platform_driver(ufs_qcom_phy_qrbtc_sdm845_driver);
  146. MODULE_DESCRIPTION("Universal Flash Storage (UFS) QCOM PHY QRBTC SDM845");
  147. MODULE_LICENSE("GPL v2");