phy-qcom-ufs-qmp-v3-660.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Copyright (c) 2013-2017, 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. */
  14. #include "phy-qcom-ufs-qmp-v3-660.h"
  15. #define UFS_PHY_NAME "ufs_phy_qmp_v3_660"
  16. static
  17. int ufs_qcom_phy_qmp_v3_660_phy_calibrate(struct ufs_qcom_phy *ufs_qcom_phy,
  18. bool is_rate_B)
  19. {
  20. int err;
  21. int tbl_size_A, tbl_size_B;
  22. struct ufs_qcom_phy_calibration *tbl_A, *tbl_B;
  23. u8 major = ufs_qcom_phy->host_ctrl_rev_major;
  24. u16 minor = ufs_qcom_phy->host_ctrl_rev_minor;
  25. u16 step = ufs_qcom_phy->host_ctrl_rev_step;
  26. tbl_size_B = ARRAY_SIZE(phy_cal_table_rate_B);
  27. tbl_B = phy_cal_table_rate_B;
  28. if ((major == 0x3) && (minor == 0x001) && (step == 0x001)) {
  29. tbl_A = phy_cal_table_rate_A_3_1_1;
  30. tbl_size_A = ARRAY_SIZE(phy_cal_table_rate_A_3_1_1);
  31. } else {
  32. dev_err(ufs_qcom_phy->dev,
  33. "%s: Unknown UFS-PHY version (major 0x%x minor 0x%x step 0x%x), no calibration values\n",
  34. __func__, major, minor, step);
  35. err = -ENODEV;
  36. goto out;
  37. }
  38. err = ufs_qcom_phy_calibrate(ufs_qcom_phy,
  39. tbl_A, tbl_size_A,
  40. tbl_B, tbl_size_B,
  41. is_rate_B);
  42. if (err)
  43. dev_err(ufs_qcom_phy->dev,
  44. "%s: ufs_qcom_phy_calibrate() failed %d\n",
  45. __func__, err);
  46. out:
  47. return err;
  48. }
  49. static int ufs_qcom_phy_qmp_v3_660_init(struct phy *generic_phy)
  50. {
  51. struct ufs_qcom_phy_qmp_v3_660 *phy = phy_get_drvdata(generic_phy);
  52. struct ufs_qcom_phy *phy_common = &phy->common_cfg;
  53. int err;
  54. err = ufs_qcom_phy_init_clks(generic_phy, phy_common);
  55. if (err) {
  56. dev_err(phy_common->dev, "%s: ufs_qcom_phy_init_clks() failed %d\n",
  57. __func__, err);
  58. goto out;
  59. }
  60. err = ufs_qcom_phy_init_vregulators(generic_phy, phy_common);
  61. if (err) {
  62. dev_err(phy_common->dev, "%s: ufs_qcom_phy_init_vregulators() failed %d\n",
  63. __func__, err);
  64. goto out;
  65. }
  66. out:
  67. return err;
  68. }
  69. static
  70. void ufs_qcom_phy_qmp_v3_660_power_control(struct ufs_qcom_phy *phy,
  71. bool power_ctrl)
  72. {
  73. if (!power_ctrl) {
  74. /* apply analog power collapse */
  75. writel_relaxed(0x0, phy->mmio + UFS_PHY_POWER_DOWN_CONTROL);
  76. /*
  77. * Make sure that PHY knows its analog rail is going to be
  78. * powered OFF.
  79. */
  80. mb();
  81. } else {
  82. /* bring PHY out of analog power collapse */
  83. writel_relaxed(0x1, phy->mmio + UFS_PHY_POWER_DOWN_CONTROL);
  84. /*
  85. * Before any transactions involving PHY, ensure PHY knows
  86. * that it's analog rail is powered ON.
  87. */
  88. mb();
  89. }
  90. }
  91. static inline
  92. void ufs_qcom_phy_qmp_v3_660_set_tx_lane_enable(struct ufs_qcom_phy *phy,
  93. u32 val)
  94. {
  95. /*
  96. * v3 PHY does not have TX_LANE_ENABLE register.
  97. * Implement this function so as not to propagate error to caller.
  98. */
  99. }
  100. static
  101. void ufs_qcom_phy_qmp_v3_660_ctrl_rx_linecfg(struct ufs_qcom_phy *phy,
  102. bool ctrl)
  103. {
  104. u32 temp;
  105. temp = readl_relaxed(phy->mmio + UFS_PHY_LINECFG_DISABLE);
  106. if (ctrl) /* enable RX LineCfg */
  107. temp &= ~UFS_PHY_RX_LINECFG_DISABLE_BIT;
  108. else /* disable RX LineCfg */
  109. temp |= UFS_PHY_RX_LINECFG_DISABLE_BIT;
  110. writel_relaxed(temp, phy->mmio + UFS_PHY_LINECFG_DISABLE);
  111. /* Make sure that RX LineCfg config applied before we return */
  112. mb();
  113. }
  114. static inline void ufs_qcom_phy_qmp_v3_660_start_serdes(
  115. struct ufs_qcom_phy *phy)
  116. {
  117. u32 tmp;
  118. tmp = readl_relaxed(phy->mmio + UFS_PHY_PHY_START);
  119. tmp &= ~MASK_SERDES_START;
  120. tmp |= (1 << OFFSET_SERDES_START);
  121. writel_relaxed(tmp, phy->mmio + UFS_PHY_PHY_START);
  122. /* Ensure register value is committed */
  123. mb();
  124. }
  125. static int ufs_qcom_phy_qmp_v3_660_is_pcs_ready(
  126. struct ufs_qcom_phy *phy_common)
  127. {
  128. int err = 0;
  129. u32 val;
  130. err = readl_poll_timeout(phy_common->mmio + UFS_PHY_PCS_READY_STATUS,
  131. val, (val & MASK_PCS_READY), 10, 1000000);
  132. if (err)
  133. dev_err(phy_common->dev, "%s: poll for pcs failed err = %d\n",
  134. __func__, err);
  135. return err;
  136. }
  137. static void ufs_qcom_phy_qmp_v3_660_dbg_register_dump(
  138. struct ufs_qcom_phy *phy)
  139. {
  140. ufs_qcom_phy_dump_regs(phy, COM_BASE, COM_SIZE,
  141. "PHY QSERDES COM Registers ");
  142. ufs_qcom_phy_dump_regs(phy, PHY_BASE, PHY_SIZE,
  143. "PHY Registers ");
  144. ufs_qcom_phy_dump_regs(phy, RX_BASE, RX_SIZE,
  145. "PHY RX0 Registers ");
  146. ufs_qcom_phy_dump_regs(phy, TX_BASE, TX_SIZE,
  147. "PHY TX0 Registers ");
  148. }
  149. struct phy_ops ufs_qcom_phy_qmp_v3_660_phy_ops = {
  150. .init = ufs_qcom_phy_qmp_v3_660_init,
  151. .exit = ufs_qcom_phy_exit,
  152. .power_on = ufs_qcom_phy_power_on,
  153. .power_off = ufs_qcom_phy_power_off,
  154. .owner = THIS_MODULE,
  155. };
  156. struct ufs_qcom_phy_specific_ops phy_v3_660_ops = {
  157. .calibrate_phy = ufs_qcom_phy_qmp_v3_660_phy_calibrate,
  158. .start_serdes = ufs_qcom_phy_qmp_v3_660_start_serdes,
  159. .is_physical_coding_sublayer_ready =
  160. ufs_qcom_phy_qmp_v3_660_is_pcs_ready,
  161. .set_tx_lane_enable = ufs_qcom_phy_qmp_v3_660_set_tx_lane_enable,
  162. .ctrl_rx_linecfg = ufs_qcom_phy_qmp_v3_660_ctrl_rx_linecfg,
  163. .power_control = ufs_qcom_phy_qmp_v3_660_power_control,
  164. .dbg_register_dump = ufs_qcom_phy_qmp_v3_660_dbg_register_dump,
  165. };
  166. static int ufs_qcom_phy_qmp_v3_660_probe(struct platform_device *pdev)
  167. {
  168. struct device *dev = &pdev->dev;
  169. struct phy *generic_phy;
  170. struct ufs_qcom_phy_qmp_v3_660 *phy;
  171. int err = 0;
  172. phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
  173. if (!phy) {
  174. err = -ENOMEM;
  175. goto out;
  176. }
  177. generic_phy = ufs_qcom_phy_generic_probe(pdev, &phy->common_cfg,
  178. &ufs_qcom_phy_qmp_v3_660_phy_ops,
  179. &phy_v3_660_ops);
  180. if (!generic_phy) {
  181. dev_err(dev, "%s: ufs_qcom_phy_generic_probe() failed\n",
  182. __func__);
  183. err = -EIO;
  184. goto out;
  185. }
  186. phy_set_drvdata(generic_phy, phy);
  187. strlcpy(phy->common_cfg.name, UFS_PHY_NAME,
  188. sizeof(phy->common_cfg.name));
  189. out:
  190. return err;
  191. }
  192. static int ufs_qcom_phy_qmp_v3_660_remove(struct platform_device *pdev)
  193. {
  194. struct device *dev = &pdev->dev;
  195. struct phy *generic_phy = to_phy(dev);
  196. struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(generic_phy);
  197. int err = 0;
  198. err = ufs_qcom_phy_remove(generic_phy, ufs_qcom_phy);
  199. if (err)
  200. dev_err(dev, "%s: ufs_qcom_phy_remove failed = %d\n",
  201. __func__, err);
  202. return err;
  203. }
  204. static const struct of_device_id ufs_qcom_phy_qmp_v3_660_of_match[] = {
  205. {.compatible = "qcom,ufs-phy-qmp-v3-660"},
  206. {},
  207. };
  208. MODULE_DEVICE_TABLE(of, ufs_qcom_phy_qmp_v3_660_of_match);
  209. static struct platform_driver ufs_qcom_phy_qmp_v3_660_driver = {
  210. .probe = ufs_qcom_phy_qmp_v3_660_probe,
  211. .remove = ufs_qcom_phy_qmp_v3_660_remove,
  212. .driver = {
  213. .of_match_table = ufs_qcom_phy_qmp_v3_660_of_match,
  214. .name = "ufs_qcom_phy_qmp_v3_660",
  215. .owner = THIS_MODULE,
  216. },
  217. };
  218. module_platform_driver(ufs_qcom_phy_qmp_v3_660_driver);
  219. MODULE_DESCRIPTION("Universal Flash Storage (UFS) QCOM PHY QMP v3 660");
  220. MODULE_LICENSE("GPL v2");