phy-qcom-ufs-i.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2013-2015, 2019-2021, Linux Foundation. All rights reserved.
  4. * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef UFS_QCOM_PHY_I_H_
  7. #define UFS_QCOM_PHY_I_H_
  8. #include <linux/module.h>
  9. #include <linux/clk.h>
  10. #include <linux/phy/phy.h>
  11. #include <linux/regulator/consumer.h>
  12. #include <linux/reset.h>
  13. #include <linux/slab.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/io.h>
  16. #include <linux/delay.h>
  17. #include <linux/iopoll.h>
  18. #include <linux/phy/phy-qcom-ufs.h>
  19. #define UFS_QCOM_PHY_CAL_ENTRY(reg, val) \
  20. { \
  21. .reg_offset = reg, \
  22. .cfg_value = val, \
  23. }
  24. #define UFS_QCOM_PHY_NAME_LEN 30
  25. enum {
  26. MASK_SERDES_START = 0x1,
  27. MASK_PCS_READY = 0x1,
  28. };
  29. enum {
  30. OFFSET_SERDES_START = 0x0,
  31. };
  32. enum ufs_qcom_phy_submode {
  33. UFS_QCOM_PHY_SUBMODE_NON_G4,
  34. UFS_QCOM_PHY_SUBMODE_G4,
  35. UFS_QCOM_PHY_SUBMODE_G5,
  36. };
  37. struct ufs_qcom_phy_stored_attributes {
  38. u32 att;
  39. u32 value;
  40. };
  41. struct ufs_qcom_phy_calibration {
  42. u32 reg_offset;
  43. u32 cfg_value;
  44. };
  45. struct ufs_qcom_phy_vreg {
  46. const char *name;
  47. struct regulator *reg;
  48. int max_uA;
  49. int min_uV;
  50. int max_uV;
  51. bool enabled;
  52. };
  53. struct ufs_qcom_phy {
  54. struct list_head list;
  55. struct device *dev;
  56. void __iomem *mmio;
  57. void __iomem *dev_ref_clk_ctrl_mmio;
  58. struct clk *tx_iface_clk;
  59. struct clk *rx_iface_clk;
  60. bool is_iface_clk_enabled;
  61. struct clk *ref_clk_src;
  62. struct clk *ref_clk_parent;
  63. struct clk *ref_clk_pad_en;
  64. struct clk *ref_clk;
  65. struct clk *ref_aux_clk;
  66. struct clk *qref_clk;
  67. struct clk *rx_sym0_mux_clk;
  68. struct clk *rx_sym1_mux_clk;
  69. struct clk *tx_sym0_mux_clk;
  70. struct clk *rx_sym0_phy_clk;
  71. struct clk *rx_sym1_phy_clk;
  72. struct clk *tx_sym0_phy_clk;
  73. bool is_ref_clk_enabled;
  74. bool is_dev_ref_clk_enabled;
  75. struct ufs_qcom_phy_vreg vdda_pll;
  76. struct ufs_qcom_phy_vreg vdda_phy;
  77. struct ufs_qcom_phy_vreg vddp_ref_clk;
  78. struct ufs_qcom_phy_vreg vdd_phy_gdsc;
  79. struct ufs_qcom_phy_vreg vdda_qref;
  80. /* Number of lanes available (1 or 2) for Rx/Tx */
  81. u32 lanes_per_direction;
  82. unsigned int quirks;
  83. /**
  84. * If UFS link is put into Hibern8 and if UFS PHY analog hardware is
  85. * power collapsed (by clearing UFS_PHY_POWER_DOWN_CONTROL), Hibern8
  86. * exit might fail even after powering on UFS PHY analog hardware.
  87. * Enabling this quirk will help to solve above issue by doing
  88. * custom PHY settings just before PHY analog power collapse.
  89. */
  90. #define UFS_QCOM_PHY_QUIRK_HIBERN8_EXIT_AFTER_PHY_PWR_COLLAPSE BIT(0)
  91. u8 host_ctrl_rev_major;
  92. u16 host_ctrl_rev_minor;
  93. u16 host_ctrl_rev_step;
  94. char name[UFS_QCOM_PHY_NAME_LEN];
  95. struct ufs_qcom_phy_calibration *cached_regs;
  96. int cached_regs_table_size;
  97. struct ufs_qcom_phy_specific_ops *phy_spec_ops;
  98. enum phy_mode mode;
  99. int submode;
  100. struct reset_control *ufs_reset;
  101. struct list_head regs_list_head;
  102. };
  103. /**
  104. * struct ufs_qcom_phy_specific_ops - set of pointers to functions which have a
  105. * specific implementation per phy. Each UFS phy, should implement
  106. * those functions according to its spec and requirements
  107. * @start_serdes: pointer to a function that starts the serdes
  108. * @is_physical_coding_sublayer_ready: pointer to a function that
  109. * checks pcs readiness. returns 0 for success and non-zero for error.
  110. * @set_tx_lane_enable: pointer to a function that enable tx lanes
  111. * @power_control: pointer to a function that controls analog rail of phy
  112. * and writes to QSERDES_RX_SIGDET_CNTRL attribute
  113. * @ctrl_rx_linecfg: pointer to a function that controls the enable/disable of
  114. * Rx line config
  115. * @get_tx_hs_equalizer: pointer to a function retrieving the tx hs equalizer setting
  116. * @dbg_register_dump: pointer to a function that dumps phy registers for debug.
  117. * @dbg_register_save: pointer to a function that save phy registers to memory.
  118. */
  119. struct ufs_qcom_phy_specific_ops {
  120. int (*calibrate)(struct ufs_qcom_phy *ufs_qcom_phy, bool is_rate_B,
  121. bool is_g4);
  122. void (*start_serdes)(struct ufs_qcom_phy *phy);
  123. int (*is_physical_coding_sublayer_ready)(struct ufs_qcom_phy *phy);
  124. void (*set_tx_lane_enable)(struct ufs_qcom_phy *phy, u32 val);
  125. void (*power_control)(struct ufs_qcom_phy *phy, bool val);
  126. void (*ctrl_rx_linecfg)(struct ufs_qcom_phy *phy, bool ctrl);
  127. u32 (*get_tx_hs_equalizer)(struct ufs_qcom_phy *phy, u32 gear);
  128. void (*dbg_register_dump)(struct ufs_qcom_phy *phy);
  129. void (*dbg_register_save)(struct ufs_qcom_phy *phy);
  130. };
  131. struct ufs_qcom_phy *get_ufs_qcom_phy(struct phy *generic_phy);
  132. int ufs_qcom_phy_power_on(struct phy *generic_phy);
  133. int ufs_qcom_phy_power_off(struct phy *generic_phy);
  134. int ufs_qcom_phy_init_clks(struct ufs_qcom_phy *phy_common);
  135. int ufs_qcom_phy_init_vregulators(struct ufs_qcom_phy *phy_common);
  136. int ufs_qcom_phy_remove(struct phy *generic_phy,
  137. struct ufs_qcom_phy *ufs_qcom_phy);
  138. struct phy *ufs_qcom_phy_generic_probe(struct platform_device *pdev,
  139. struct ufs_qcom_phy *common_cfg,
  140. const struct phy_ops *ufs_qcom_phy_gen_ops,
  141. struct ufs_qcom_phy_specific_ops *phy_spec_ops);
  142. int ufs_qcom_phy_get_reset(struct ufs_qcom_phy *phy_common);
  143. int ufs_qcom_phy_calibrate(struct ufs_qcom_phy *ufs_qcom_phy,
  144. struct ufs_qcom_phy_calibration *tbl_A, int tbl_size_A,
  145. struct ufs_qcom_phy_calibration *tbl_B, int tbl_size_B,
  146. bool is_rate_B);
  147. void ufs_qcom_phy_write_tbl(struct ufs_qcom_phy *ufs_qcom_phy,
  148. struct ufs_qcom_phy_calibration *tbl,
  149. int tbl_size);
  150. int ufs_qcom_phy_dump_regs(struct ufs_qcom_phy *phy,
  151. int offset, int len, char *prefix);
  152. int ufs_qcom_phy_save_regs(struct ufs_qcom_phy *phy,
  153. int offset, int len, char *prefix);
  154. #endif