phy-gs101-ufs.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * UFS PHY driver data for Google Tensor gs101 SoC
  4. *
  5. * Copyright (C) 2024 Linaro Ltd
  6. * Author: Peter Griffin <peter.griffin@linaro.org>
  7. */
  8. #include "phy-samsung-ufs.h"
  9. #define TENSOR_GS101_PHY_CTRL 0x3ec8
  10. #define TENSOR_GS101_PHY_CTRL_MASK 0x1
  11. #define TENSOR_GS101_PHY_CTRL_EN BIT(0)
  12. #define PHY_GS101_LANE_OFFSET 0x200
  13. #define TRSV_REG338 0x338
  14. #define LN0_MON_RX_CAL_DONE BIT(3)
  15. #define TRSV_REG339 0x339
  16. #define LN0_MON_RX_CDR_FLD_CK_MODE_DONE BIT(3)
  17. #define TRSV_REG222 0x222
  18. #define LN0_OVRD_RX_CDR_EN BIT(4)
  19. #define LN0_RX_CDR_EN BIT(3)
  20. #define PHY_PMA_TRSV_ADDR(reg, lane) (PHY_APB_ADDR((reg) + \
  21. ((lane) * PHY_GS101_LANE_OFFSET)))
  22. #define PHY_TRSV_REG_CFG_GS101(o, v, d) \
  23. PHY_TRSV_REG_CFG_OFFSET(o, v, d, PHY_GS101_LANE_OFFSET)
  24. /* Calibration for phy initialization */
  25. static const struct samsung_ufs_phy_cfg tensor_gs101_pre_init_cfg[] = {
  26. PHY_COMN_REG_CFG(0x43, 0x10, PWR_MODE_ANY),
  27. PHY_COMN_REG_CFG(0x3C, 0x14, PWR_MODE_ANY),
  28. PHY_COMN_REG_CFG(0x46, 0x48, PWR_MODE_ANY),
  29. PHY_TRSV_REG_CFG_GS101(0x200, 0x00, PWR_MODE_ANY),
  30. PHY_TRSV_REG_CFG_GS101(0x201, 0x06, PWR_MODE_ANY),
  31. PHY_TRSV_REG_CFG_GS101(0x202, 0x06, PWR_MODE_ANY),
  32. PHY_TRSV_REG_CFG_GS101(0x203, 0x0a, PWR_MODE_ANY),
  33. PHY_TRSV_REG_CFG_GS101(0x204, 0x00, PWR_MODE_ANY),
  34. PHY_TRSV_REG_CFG_GS101(0x205, 0x11, PWR_MODE_ANY),
  35. PHY_TRSV_REG_CFG_GS101(0x207, 0x0c, PWR_MODE_ANY),
  36. PHY_TRSV_REG_CFG_GS101(0x2E1, 0xc0, PWR_MODE_ANY),
  37. PHY_TRSV_REG_CFG_GS101(0x22D, 0xb8, PWR_MODE_ANY),
  38. PHY_TRSV_REG_CFG_GS101(0x234, 0x60, PWR_MODE_ANY),
  39. PHY_TRSV_REG_CFG_GS101(0x238, 0x13, PWR_MODE_ANY),
  40. PHY_TRSV_REG_CFG_GS101(0x239, 0x48, PWR_MODE_ANY),
  41. PHY_TRSV_REG_CFG_GS101(0x23A, 0x01, PWR_MODE_ANY),
  42. PHY_TRSV_REG_CFG_GS101(0x23B, 0x25, PWR_MODE_ANY),
  43. PHY_TRSV_REG_CFG_GS101(0x23C, 0x2a, PWR_MODE_ANY),
  44. PHY_TRSV_REG_CFG_GS101(0x23D, 0x01, PWR_MODE_ANY),
  45. PHY_TRSV_REG_CFG_GS101(0x23E, 0x13, PWR_MODE_ANY),
  46. PHY_TRSV_REG_CFG_GS101(0x23F, 0x13, PWR_MODE_ANY),
  47. PHY_TRSV_REG_CFG_GS101(0x240, 0x4a, PWR_MODE_ANY),
  48. PHY_TRSV_REG_CFG_GS101(0x243, 0x40, PWR_MODE_ANY),
  49. PHY_TRSV_REG_CFG_GS101(0x244, 0x02, PWR_MODE_ANY),
  50. PHY_TRSV_REG_CFG_GS101(0x25D, 0x00, PWR_MODE_ANY),
  51. PHY_TRSV_REG_CFG_GS101(0x25E, 0x3f, PWR_MODE_ANY),
  52. PHY_TRSV_REG_CFG_GS101(0x25F, 0xff, PWR_MODE_ANY),
  53. PHY_TRSV_REG_CFG_GS101(0x273, 0x33, PWR_MODE_ANY),
  54. PHY_TRSV_REG_CFG_GS101(0x274, 0x50, PWR_MODE_ANY),
  55. PHY_TRSV_REG_CFG_GS101(0x284, 0x02, PWR_MODE_ANY),
  56. PHY_TRSV_REG_CFG_GS101(0x285, 0x02, PWR_MODE_ANY),
  57. PHY_TRSV_REG_CFG_GS101(0x2A2, 0x04, PWR_MODE_ANY),
  58. PHY_TRSV_REG_CFG_GS101(0x25D, 0x01, PWR_MODE_ANY),
  59. PHY_TRSV_REG_CFG_GS101(0x2FA, 0x01, PWR_MODE_ANY),
  60. PHY_TRSV_REG_CFG_GS101(0x286, 0x03, PWR_MODE_ANY),
  61. PHY_TRSV_REG_CFG_GS101(0x287, 0x03, PWR_MODE_ANY),
  62. PHY_TRSV_REG_CFG_GS101(0x288, 0x03, PWR_MODE_ANY),
  63. PHY_TRSV_REG_CFG_GS101(0x289, 0x03, PWR_MODE_ANY),
  64. PHY_TRSV_REG_CFG_GS101(0x2B3, 0x04, PWR_MODE_ANY),
  65. PHY_TRSV_REG_CFG_GS101(0x2B6, 0x0b, PWR_MODE_ANY),
  66. PHY_TRSV_REG_CFG_GS101(0x2B7, 0x0b, PWR_MODE_ANY),
  67. PHY_TRSV_REG_CFG_GS101(0x2B8, 0x0b, PWR_MODE_ANY),
  68. PHY_TRSV_REG_CFG_GS101(0x2B9, 0x0b, PWR_MODE_ANY),
  69. PHY_TRSV_REG_CFG_GS101(0x2BA, 0x0b, PWR_MODE_ANY),
  70. PHY_TRSV_REG_CFG_GS101(0x2BB, 0x06, PWR_MODE_ANY),
  71. PHY_TRSV_REG_CFG_GS101(0x2BC, 0x06, PWR_MODE_ANY),
  72. PHY_TRSV_REG_CFG_GS101(0x2BD, 0x06, PWR_MODE_ANY),
  73. PHY_TRSV_REG_CFG_GS101(0x29E, 0x06, PWR_MODE_ANY),
  74. PHY_TRSV_REG_CFG_GS101(0x2E4, 0x1a, PWR_MODE_ANY),
  75. PHY_TRSV_REG_CFG_GS101(0x2ED, 0x25, PWR_MODE_ANY),
  76. PHY_TRSV_REG_CFG_GS101(0x269, 0x1a, PWR_MODE_ANY),
  77. PHY_TRSV_REG_CFG_GS101(0x2F4, 0x2f, PWR_MODE_ANY),
  78. PHY_TRSV_REG_CFG_GS101(0x34B, 0x01, PWR_MODE_ANY),
  79. PHY_TRSV_REG_CFG_GS101(0x34C, 0x23, PWR_MODE_ANY),
  80. PHY_TRSV_REG_CFG_GS101(0x34D, 0x23, PWR_MODE_ANY),
  81. PHY_TRSV_REG_CFG_GS101(0x34E, 0x45, PWR_MODE_ANY),
  82. PHY_TRSV_REG_CFG_GS101(0x34F, 0x00, PWR_MODE_ANY),
  83. PHY_TRSV_REG_CFG_GS101(0x350, 0x31, PWR_MODE_ANY),
  84. PHY_TRSV_REG_CFG_GS101(0x351, 0x00, PWR_MODE_ANY),
  85. PHY_TRSV_REG_CFG_GS101(0x352, 0x02, PWR_MODE_ANY),
  86. PHY_TRSV_REG_CFG_GS101(0x353, 0x00, PWR_MODE_ANY),
  87. PHY_TRSV_REG_CFG_GS101(0x354, 0x01, PWR_MODE_ANY),
  88. PHY_COMN_REG_CFG(0x43, 0x18, PWR_MODE_ANY),
  89. PHY_COMN_REG_CFG(0x43, 0x00, PWR_MODE_ANY),
  90. END_UFS_PHY_CFG,
  91. };
  92. static const struct samsung_ufs_phy_cfg tensor_gs101_pre_pwr_hs_config[] = {
  93. PHY_TRSV_REG_CFG_GS101(0x369, 0x11, PWR_MODE_ANY),
  94. PHY_TRSV_REG_CFG_GS101(0x246, 0x03, PWR_MODE_ANY),
  95. };
  96. /* Calibration for HS mode series A/B */
  97. static const struct samsung_ufs_phy_cfg tensor_gs101_post_pwr_hs_config[] = {
  98. PHY_COMN_REG_CFG(0x8, 0x60, PWR_MODE_PWM_ANY),
  99. PHY_TRSV_REG_CFG_GS101(0x222, 0x08, PWR_MODE_PWM_ANY),
  100. PHY_TRSV_REG_CFG_GS101(0x246, 0x01, PWR_MODE_ANY),
  101. END_UFS_PHY_CFG,
  102. };
  103. static const struct samsung_ufs_phy_cfg *tensor_gs101_ufs_phy_cfgs[CFG_TAG_MAX] = {
  104. [CFG_PRE_INIT] = tensor_gs101_pre_init_cfg,
  105. [CFG_PRE_PWR_HS] = tensor_gs101_pre_pwr_hs_config,
  106. [CFG_POST_PWR_HS] = tensor_gs101_post_pwr_hs_config,
  107. };
  108. static const char * const tensor_gs101_ufs_phy_clks[] = {
  109. "ref_clk",
  110. };
  111. static int gs101_phy_wait_for_calibration(struct phy *phy, u8 lane)
  112. {
  113. struct samsung_ufs_phy *ufs_phy = get_samsung_ufs_phy(phy);
  114. const unsigned int timeout_us = 40000;
  115. const unsigned int sleep_us = 40;
  116. u32 val;
  117. u32 off;
  118. int err;
  119. off = PHY_PMA_TRSV_ADDR(TRSV_REG338, lane);
  120. err = readl_poll_timeout(ufs_phy->reg_pma + off,
  121. val, (val & LN0_MON_RX_CAL_DONE),
  122. sleep_us, timeout_us);
  123. if (err) {
  124. dev_err(ufs_phy->dev,
  125. "failed to get phy cal done %d\n", err);
  126. }
  127. return err;
  128. }
  129. #define DELAY_IN_US 40
  130. #define RETRY_CNT 100
  131. static int gs101_phy_wait_for_cdr_lock(struct phy *phy, u8 lane)
  132. {
  133. struct samsung_ufs_phy *ufs_phy = get_samsung_ufs_phy(phy);
  134. u32 val;
  135. int i;
  136. for (i = 0; i < RETRY_CNT; i++) {
  137. udelay(DELAY_IN_US);
  138. val = readl(ufs_phy->reg_pma +
  139. PHY_PMA_TRSV_ADDR(TRSV_REG339, lane));
  140. if (val & LN0_MON_RX_CDR_FLD_CK_MODE_DONE)
  141. return 0;
  142. udelay(DELAY_IN_US);
  143. /* Override and enable clock data recovery */
  144. writel(LN0_OVRD_RX_CDR_EN, ufs_phy->reg_pma +
  145. PHY_PMA_TRSV_ADDR(TRSV_REG222, lane));
  146. writel(LN0_OVRD_RX_CDR_EN | LN0_RX_CDR_EN,
  147. ufs_phy->reg_pma + PHY_PMA_TRSV_ADDR(TRSV_REG222, lane));
  148. }
  149. dev_err(ufs_phy->dev, "failed to get cdr lock\n");
  150. return -ETIMEDOUT;
  151. }
  152. const struct samsung_ufs_phy_drvdata tensor_gs101_ufs_phy = {
  153. .cfgs = tensor_gs101_ufs_phy_cfgs,
  154. .isol = {
  155. .offset = TENSOR_GS101_PHY_CTRL,
  156. .mask = TENSOR_GS101_PHY_CTRL_MASK,
  157. .en = TENSOR_GS101_PHY_CTRL_EN,
  158. },
  159. .clk_list = tensor_gs101_ufs_phy_clks,
  160. .num_clks = ARRAY_SIZE(tensor_gs101_ufs_phy_clks),
  161. .wait_for_cal = gs101_phy_wait_for_calibration,
  162. .wait_for_cdr = gs101_phy_wait_for_cdr_lock,
  163. };