phy-qcom-ufs-i.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. };
  70. struct ufs_qcom_phy {
  71. struct list_head list;
  72. struct device *dev;
  73. void __iomem *mmio;
  74. void __iomem *dev_ref_clk_ctrl_mmio;
  75. struct clk *tx_iface_clk;
  76. struct clk *rx_iface_clk;
  77. bool is_iface_clk_enabled;
  78. struct clk *ref_clk_src;
  79. struct clk *ref_clk_parent;
  80. struct clk *ref_clk;
  81. bool is_ref_clk_enabled;
  82. bool is_dev_ref_clk_enabled;
  83. struct ufs_qcom_phy_vreg vdda_pll;
  84. struct ufs_qcom_phy_vreg vdda_phy;
  85. struct ufs_qcom_phy_vreg vddp_ref_clk;
  86. unsigned int quirks;
  87. /*
  88. * If UFS link is put into Hibern8 and if UFS PHY analog hardware is
  89. * power collapsed (by clearing UFS_PHY_POWER_DOWN_CONTROL), Hibern8
  90. * exit might fail even after powering on UFS PHY analog hardware.
  91. * Enabling this quirk will help to solve above issue by doing
  92. * custom PHY settings just before PHY analog power collapse.
  93. */
  94. #define UFS_QCOM_PHY_QUIRK_HIBERN8_EXIT_AFTER_PHY_PWR_COLLAPSE BIT(0)
  95. u8 host_ctrl_rev_major;
  96. u16 host_ctrl_rev_minor;
  97. u16 host_ctrl_rev_step;
  98. char name[UFS_QCOM_PHY_NAME_LEN];
  99. struct ufs_qcom_phy_calibration *cached_regs;
  100. int cached_regs_table_size;
  101. bool is_powered_on;
  102. bool is_started;
  103. struct ufs_qcom_phy_specific_ops *phy_spec_ops;
  104. enum phy_mode mode;
  105. };
  106. /**
  107. * struct ufs_qcom_phy_specific_ops - set of pointers to functions which have a
  108. * specific implementation per phy. Each UFS phy, should implement
  109. * those functions according to its spec and requirements
  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. void (*start_serdes)(struct ufs_qcom_phy *phy);
  119. int (*is_physical_coding_sublayer_ready)(struct ufs_qcom_phy *phy);
  120. void (*set_tx_lane_enable)(struct ufs_qcom_phy *phy, u32 val);
  121. void (*power_control)(struct ufs_qcom_phy *phy, bool val);
  122. };
  123. struct ufs_qcom_phy *get_ufs_qcom_phy(struct phy *generic_phy);
  124. int ufs_qcom_phy_power_on(struct phy *generic_phy);
  125. int ufs_qcom_phy_power_off(struct phy *generic_phy);
  126. int ufs_qcom_phy_init_clks(struct ufs_qcom_phy *phy_common);
  127. int ufs_qcom_phy_init_vregulators(struct ufs_qcom_phy *phy_common);
  128. int ufs_qcom_phy_remove(struct phy *generic_phy,
  129. struct ufs_qcom_phy *ufs_qcom_phy);
  130. struct phy *ufs_qcom_phy_generic_probe(struct platform_device *pdev,
  131. struct ufs_qcom_phy *common_cfg,
  132. const struct phy_ops *ufs_qcom_phy_gen_ops,
  133. struct ufs_qcom_phy_specific_ops *phy_spec_ops);
  134. int ufs_qcom_phy_calibrate(struct ufs_qcom_phy *ufs_qcom_phy,
  135. struct ufs_qcom_phy_calibration *tbl_A, int tbl_size_A,
  136. struct ufs_qcom_phy_calibration *tbl_B, int tbl_size_B,
  137. bool is_rate_B);
  138. #endif