ufs-qcom.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #ifndef UFS_QCOM_H_
  14. #define UFS_QCOM_H_
  15. #define MAX_UFS_QCOM_HOSTS 1
  16. #define MAX_U32 (~(u32)0)
  17. #define MPHY_TX_FSM_STATE 0x41
  18. #define TX_FSM_HIBERN8 0x1
  19. #define HBRN8_POLL_TOUT_MS 100
  20. #define DEFAULT_CLK_RATE_HZ 1000000
  21. #define BUS_VECTOR_NAME_LEN 32
  22. #define UFS_HW_VER_MAJOR_SHFT (28)
  23. #define UFS_HW_VER_MAJOR_MASK (0x000F << UFS_HW_VER_MAJOR_SHFT)
  24. #define UFS_HW_VER_MINOR_SHFT (16)
  25. #define UFS_HW_VER_MINOR_MASK (0x0FFF << UFS_HW_VER_MINOR_SHFT)
  26. #define UFS_HW_VER_STEP_SHFT (0)
  27. #define UFS_HW_VER_STEP_MASK (0xFFFF << UFS_HW_VER_STEP_SHFT)
  28. /* vendor specific pre-defined parameters */
  29. #define SLOW 1
  30. #define FAST 2
  31. #define UFS_QCOM_LIMIT_NUM_LANES_RX 2
  32. #define UFS_QCOM_LIMIT_NUM_LANES_TX 2
  33. #define UFS_QCOM_LIMIT_HSGEAR_RX UFS_HS_G3
  34. #define UFS_QCOM_LIMIT_HSGEAR_TX UFS_HS_G3
  35. #define UFS_QCOM_LIMIT_PWMGEAR_RX UFS_PWM_G4
  36. #define UFS_QCOM_LIMIT_PWMGEAR_TX UFS_PWM_G4
  37. #define UFS_QCOM_LIMIT_RX_PWR_PWM SLOW_MODE
  38. #define UFS_QCOM_LIMIT_TX_PWR_PWM SLOW_MODE
  39. #define UFS_QCOM_LIMIT_RX_PWR_HS FAST_MODE
  40. #define UFS_QCOM_LIMIT_TX_PWR_HS FAST_MODE
  41. #define UFS_QCOM_LIMIT_HS_RATE PA_HS_MODE_B
  42. #define UFS_QCOM_LIMIT_DESIRED_MODE FAST
  43. /* QCOM UFS host controller vendor specific registers */
  44. enum {
  45. REG_UFS_SYS1CLK_1US = 0xC0,
  46. REG_UFS_TX_SYMBOL_CLK_NS_US = 0xC4,
  47. REG_UFS_LOCAL_PORT_ID_REG = 0xC8,
  48. REG_UFS_PA_ERR_CODE = 0xCC,
  49. REG_UFS_RETRY_TIMER_REG = 0xD0,
  50. REG_UFS_PA_LINK_STARTUP_TIMER = 0xD8,
  51. REG_UFS_CFG1 = 0xDC,
  52. REG_UFS_CFG2 = 0xE0,
  53. REG_UFS_HW_VERSION = 0xE4,
  54. UFS_TEST_BUS = 0xE8,
  55. UFS_TEST_BUS_CTRL_0 = 0xEC,
  56. UFS_TEST_BUS_CTRL_1 = 0xF0,
  57. UFS_TEST_BUS_CTRL_2 = 0xF4,
  58. UFS_UNIPRO_CFG = 0xF8,
  59. /*
  60. * QCOM UFS host controller vendor specific registers
  61. * added in HW Version 3.0.0
  62. */
  63. UFS_AH8_CFG = 0xFC,
  64. };
  65. /* QCOM UFS host controller vendor specific debug registers */
  66. enum {
  67. UFS_DBG_RD_REG_UAWM = 0x100,
  68. UFS_DBG_RD_REG_UARM = 0x200,
  69. UFS_DBG_RD_REG_TXUC = 0x300,
  70. UFS_DBG_RD_REG_RXUC = 0x400,
  71. UFS_DBG_RD_REG_DFC = 0x500,
  72. UFS_DBG_RD_REG_TRLUT = 0x600,
  73. UFS_DBG_RD_REG_TMRLUT = 0x700,
  74. UFS_UFS_DBG_RD_REG_OCSC = 0x800,
  75. UFS_UFS_DBG_RD_DESC_RAM = 0x1500,
  76. UFS_UFS_DBG_RD_PRDT_RAM = 0x1700,
  77. UFS_UFS_DBG_RD_RESP_RAM = 0x1800,
  78. UFS_UFS_DBG_RD_EDTL_RAM = 0x1900,
  79. };
  80. #define UFS_CNTLR_2_x_x_VEN_REGS_OFFSET(x) (0x000 + x)
  81. #define UFS_CNTLR_3_x_x_VEN_REGS_OFFSET(x) (0x400 + x)
  82. /* bit definitions for REG_UFS_CFG1 register */
  83. #define QUNIPRO_SEL UFS_BIT(0)
  84. #define TEST_BUS_EN BIT(18)
  85. #define TEST_BUS_SEL GENMASK(22, 19)
  86. /* bit definitions for REG_UFS_CFG2 register */
  87. #define UAWM_HW_CGC_EN (1 << 0)
  88. #define UARM_HW_CGC_EN (1 << 1)
  89. #define TXUC_HW_CGC_EN (1 << 2)
  90. #define RXUC_HW_CGC_EN (1 << 3)
  91. #define DFC_HW_CGC_EN (1 << 4)
  92. #define TRLUT_HW_CGC_EN (1 << 5)
  93. #define TMRLUT_HW_CGC_EN (1 << 6)
  94. #define OCSC_HW_CGC_EN (1 << 7)
  95. /* bit definition for UFS_UFS_TEST_BUS_CTRL_n */
  96. #define TEST_BUS_SUB_SEL_MASK 0x1F /* All XXX_SEL fields are 5 bits wide */
  97. #define REG_UFS_CFG2_CGC_EN_ALL (UAWM_HW_CGC_EN | UARM_HW_CGC_EN |\
  98. TXUC_HW_CGC_EN | RXUC_HW_CGC_EN |\
  99. DFC_HW_CGC_EN | TRLUT_HW_CGC_EN |\
  100. TMRLUT_HW_CGC_EN | OCSC_HW_CGC_EN)
  101. /* bit offset */
  102. enum {
  103. OFFSET_UFS_PHY_SOFT_RESET = 1,
  104. OFFSET_CLK_NS_REG = 10,
  105. };
  106. /* bit masks */
  107. enum {
  108. MASK_UFS_PHY_SOFT_RESET = 0x2,
  109. MASK_TX_SYMBOL_CLK_1US_REG = 0x3FF,
  110. MASK_CLK_NS_REG = 0xFFFC00,
  111. };
  112. enum ufs_qcom_phy_init_type {
  113. UFS_PHY_INIT_FULL,
  114. UFS_PHY_INIT_CFG_RESTORE,
  115. };
  116. /* QCOM UFS debug print bit mask */
  117. #define UFS_QCOM_DBG_PRINT_REGS_EN BIT(0)
  118. #define UFS_QCOM_DBG_PRINT_ICE_REGS_EN BIT(1)
  119. #define UFS_QCOM_DBG_PRINT_TEST_BUS_EN BIT(2)
  120. #define UFS_QCOM_DBG_PRINT_ALL \
  121. (UFS_QCOM_DBG_PRINT_REGS_EN | UFS_QCOM_DBG_PRINT_ICE_REGS_EN | \
  122. UFS_QCOM_DBG_PRINT_TEST_BUS_EN)
  123. /* QUniPro Vendor specific attributes */
  124. #define DME_VS_CORE_CLK_CTRL 0xD002
  125. /* bit and mask definitions for DME_VS_CORE_CLK_CTRL attribute */
  126. #define DME_VS_CORE_CLK_CTRL_CORE_CLK_DIV_EN_BIT BIT(8)
  127. #define DME_VS_CORE_CLK_CTRL_MAX_CORE_CLK_1US_CYCLES_MASK 0xFF
  128. static inline void
  129. ufs_qcom_get_controller_revision(struct ufs_hba *hba,
  130. u8 *major, u16 *minor, u16 *step)
  131. {
  132. u32 ver = ufshcd_readl(hba, REG_UFS_HW_VERSION);
  133. *major = (ver & UFS_HW_VER_MAJOR_MASK) >> UFS_HW_VER_MAJOR_SHFT;
  134. *minor = (ver & UFS_HW_VER_MINOR_MASK) >> UFS_HW_VER_MINOR_SHFT;
  135. *step = (ver & UFS_HW_VER_STEP_MASK) >> UFS_HW_VER_STEP_SHFT;
  136. };
  137. static inline void ufs_qcom_assert_reset(struct ufs_hba *hba)
  138. {
  139. ufshcd_rmwl(hba, MASK_UFS_PHY_SOFT_RESET,
  140. 1 << OFFSET_UFS_PHY_SOFT_RESET, REG_UFS_CFG1);
  141. /*
  142. * Make sure assertion of ufs phy reset is written to
  143. * register before returning
  144. */
  145. mb();
  146. }
  147. static inline void ufs_qcom_deassert_reset(struct ufs_hba *hba)
  148. {
  149. ufshcd_rmwl(hba, MASK_UFS_PHY_SOFT_RESET,
  150. 0 << OFFSET_UFS_PHY_SOFT_RESET, REG_UFS_CFG1);
  151. /*
  152. * Make sure de-assertion of ufs phy reset is written to
  153. * register before returning
  154. */
  155. mb();
  156. }
  157. struct ufs_qcom_bus_vote {
  158. uint32_t client_handle;
  159. uint32_t curr_vote;
  160. int min_bw_vote;
  161. int max_bw_vote;
  162. int saved_vote;
  163. bool is_max_bw_needed;
  164. struct device_attribute max_bus_bw;
  165. };
  166. /* Host controller hardware version: major.minor.step */
  167. struct ufs_hw_version {
  168. u16 step;
  169. u16 minor;
  170. u8 major;
  171. };
  172. struct ufs_qcom_testbus {
  173. u8 select_major;
  174. u8 select_minor;
  175. };
  176. struct ufs_qcom_host {
  177. /*
  178. * Set this capability if host controller supports the QUniPro mode
  179. * and if driver wants the Host controller to operate in QUniPro mode.
  180. * Note: By default this capability will be kept enabled if host
  181. * controller supports the QUniPro mode.
  182. */
  183. #define UFS_QCOM_CAP_QUNIPRO UFS_BIT(0)
  184. /*
  185. * Set this capability if host controller can retain the secure
  186. * configuration even after UFS controller core power collapse.
  187. */
  188. #define UFS_QCOM_CAP_RETAIN_SEC_CFG_AFTER_PWR_COLLAPSE UFS_BIT(1)
  189. u32 caps;
  190. struct phy *generic_phy;
  191. struct ufs_hba *hba;
  192. struct ufs_qcom_bus_vote bus_vote;
  193. struct ufs_pa_layer_attr dev_req_params;
  194. struct clk *rx_l0_sync_clk;
  195. struct clk *tx_l0_sync_clk;
  196. struct clk *rx_l1_sync_clk;
  197. struct clk *tx_l1_sync_clk;
  198. bool is_lane_clks_enabled;
  199. void __iomem *dev_ref_clk_ctrl_mmio;
  200. bool is_dev_ref_clk_enabled;
  201. struct ufs_hw_version hw_ver;
  202. u32 dev_ref_clk_en_mask;
  203. /* Bitmask for enabling debug prints */
  204. u32 dbg_print_en;
  205. struct ufs_qcom_testbus testbus;
  206. };
  207. #define ufs_qcom_is_link_off(hba) ufshcd_is_link_off(hba)
  208. #define ufs_qcom_is_link_active(hba) ufshcd_is_link_active(hba)
  209. #define ufs_qcom_is_link_hibern8(hba) ufshcd_is_link_hibern8(hba)
  210. int ufs_qcom_testbus_config(struct ufs_qcom_host *host);
  211. static inline bool ufs_qcom_cap_qunipro(struct ufs_qcom_host *host)
  212. {
  213. if (host->caps & UFS_QCOM_CAP_QUNIPRO)
  214. return true;
  215. else
  216. return false;
  217. }
  218. #endif /* UFS_QCOM_H_ */