phy-qcom-ufs-i.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #ifndef UFS_QCOM_PHY_I_H_
  15. #define UFS_QCOM_PHY_I_H_
  16. #include <linux/module.h>
  17. #include <linux/clk.h>
  18. #include <linux/regulator/consumer.h>
  19. #include <linux/slab.h>
  20. #include <linux/phy/phy-qcom-ufs.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/io.h>
  23. #include <linux/delay.h>
  24. #define readl_poll_timeout(addr, val, cond, sleep_us, timeout_us) \
  25. ({ \
  26. ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); \
  27. might_sleep_if(timeout_us); \
  28. for (;;) { \
  29. (val) = readl(addr); \
  30. if (cond) \
  31. break; \
  32. if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
  33. (val) = readl(addr); \
  34. break; \
  35. } \
  36. if (sleep_us) \
  37. usleep_range(DIV_ROUND_UP(sleep_us, 4), sleep_us); \
  38. } \
  39. (cond) ? 0 : -ETIMEDOUT; \
  40. })
  41. #define UFS_QCOM_PHY_CAL_ENTRY(reg, val) \
  42. { \
  43. .reg_offset = reg, \
  44. .cfg_value = val, \
  45. }
  46. #define UFS_QCOM_PHY_NAME_LEN 30
  47. enum {
  48. MASK_SERDES_START = 0x1,
  49. MASK_PCS_READY = 0x1,
  50. };
  51. enum {
  52. OFFSET_SERDES_START = 0x0,
  53. };
  54. struct ufs_qcom_phy_stored_attributes {
  55. u32 att;
  56. u32 value;
  57. };
  58. struct ufs_qcom_phy_calibration {
  59. u32 reg_offset;
  60. u32 cfg_value;
  61. };
  62. struct ufs_qcom_phy_vreg {
  63. const char *name;
  64. struct regulator *reg;
  65. int max_uA;
  66. int min_uV;
  67. int max_uV;
  68. bool enabled;
  69. bool is_always_on;
  70. };
  71. struct ufs_qcom_phy {
  72. struct list_head list;
  73. struct device *dev;
  74. void __iomem *mmio;
  75. void __iomem *dev_ref_clk_ctrl_mmio;
  76. struct clk *tx_iface_clk;
  77. struct clk *rx_iface_clk;
  78. bool is_iface_clk_enabled;
  79. struct clk *ref_clk_src;
  80. struct clk *ref_clk_parent;
  81. struct clk *ref_clk;
  82. bool is_ref_clk_enabled;
  83. bool is_dev_ref_clk_enabled;
  84. struct ufs_qcom_phy_vreg vdda_pll;
  85. struct ufs_qcom_phy_vreg vdda_phy;
  86. struct ufs_qcom_phy_vreg vddp_ref_clk;
  87. unsigned int quirks;
  88. /*
  89. * If UFS link is put into Hibern8 and if UFS PHY analog hardware is
  90. * power collapsed (by clearing UFS_PHY_POWER_DOWN_CONTROL), Hibern8
  91. * exit might fail even after powering on UFS PHY analog hardware.
  92. * Enabling this quirk will help to solve above issue by doing
  93. * custom PHY settings just before PHY analog power collapse.
  94. */
  95. #define UFS_QCOM_PHY_QUIRK_HIBERN8_EXIT_AFTER_PHY_PWR_COLLAPSE BIT(0)
  96. u8 host_ctrl_rev_major;
  97. u16 host_ctrl_rev_minor;
  98. u16 host_ctrl_rev_step;
  99. char name[UFS_QCOM_PHY_NAME_LEN];
  100. struct ufs_qcom_phy_calibration *cached_regs;
  101. int cached_regs_table_size;
  102. bool is_powered_on;
  103. struct ufs_qcom_phy_specific_ops *phy_spec_ops;
  104. };
  105. /**
  106. * struct ufs_qcom_phy_specific_ops - set of pointers to functions which have a
  107. * specific implementation per phy. Each UFS phy, should implement
  108. * those functions according to its spec and requirements
  109. * @calibrate_phy: pointer to a function that calibrate the phy
  110. * @start_serdes: pointer to a function that starts the serdes
  111. * @is_physical_coding_sublayer_ready: pointer to a function that
  112. * checks pcs readiness. returns 0 for success and non-zero for error.
  113. * @set_tx_lane_enable: pointer to a function that enable tx lanes
  114. * @power_control: pointer to a function that controls analog rail of phy
  115. * and writes to QSERDES_RX_SIGDET_CNTRL attribute
  116. */
  117. struct ufs_qcom_phy_specific_ops {
  118. int (*calibrate_phy)(struct ufs_qcom_phy *phy, bool is_rate_B);
  119. void (*start_serdes)(struct ufs_qcom_phy *phy);
  120. int (*is_physical_coding_sublayer_ready)(struct ufs_qcom_phy *phy);
  121. void (*set_tx_lane_enable)(struct ufs_qcom_phy *phy, u32 val);
  122. void (*power_control)(struct ufs_qcom_phy *phy, bool val);
  123. };
  124. struct ufs_qcom_phy *get_ufs_qcom_phy(struct phy *generic_phy);
  125. int ufs_qcom_phy_power_on(struct phy *generic_phy);
  126. int ufs_qcom_phy_power_off(struct phy *generic_phy);
  127. int ufs_qcom_phy_exit(struct phy *generic_phy);
  128. int ufs_qcom_phy_init_clks(struct phy *generic_phy,
  129. struct ufs_qcom_phy *phy_common);
  130. int ufs_qcom_phy_init_vregulators(struct phy *generic_phy,
  131. struct ufs_qcom_phy *phy_common);
  132. int ufs_qcom_phy_remove(struct phy *generic_phy,
  133. struct ufs_qcom_phy *ufs_qcom_phy);
  134. struct phy *ufs_qcom_phy_generic_probe(struct platform_device *pdev,
  135. struct ufs_qcom_phy *common_cfg,
  136. const struct phy_ops *ufs_qcom_phy_gen_ops,
  137. struct ufs_qcom_phy_specific_ops *phy_spec_ops);
  138. int ufs_qcom_phy_calibrate(struct ufs_qcom_phy *ufs_qcom_phy,
  139. struct ufs_qcom_phy_calibration *tbl_A, int tbl_size_A,
  140. struct ufs_qcom_phy_calibration *tbl_B, int tbl_size_B,
  141. bool is_rate_B);
  142. #endif