ufs-qcom.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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_G2
  34. #define UFS_QCOM_LIMIT_HSGEAR_TX UFS_HS_G2
  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_DBG_RD_REG_UAWM = 0x100,
  55. UFS_DBG_RD_REG_UARM = 0x200,
  56. UFS_DBG_RD_REG_TXUC = 0x300,
  57. UFS_DBG_RD_REG_RXUC = 0x400,
  58. UFS_DBG_RD_REG_DFC = 0x500,
  59. UFS_DBG_RD_REG_TRLUT = 0x600,
  60. UFS_DBG_RD_REG_TMRLUT = 0x700,
  61. UFS_UFS_DBG_RD_REG_OCSC = 0x800,
  62. UFS_UFS_DBG_RD_DESC_RAM = 0x1500,
  63. UFS_UFS_DBG_RD_PRDT_RAM = 0x1700,
  64. UFS_UFS_DBG_RD_RESP_RAM = 0x1800,
  65. UFS_UFS_DBG_RD_EDTL_RAM = 0x1900,
  66. };
  67. /* bit definitions for REG_UFS_CFG2 register */
  68. #define UAWM_HW_CGC_EN (1 << 0)
  69. #define UARM_HW_CGC_EN (1 << 1)
  70. #define TXUC_HW_CGC_EN (1 << 2)
  71. #define RXUC_HW_CGC_EN (1 << 3)
  72. #define DFC_HW_CGC_EN (1 << 4)
  73. #define TRLUT_HW_CGC_EN (1 << 5)
  74. #define TMRLUT_HW_CGC_EN (1 << 6)
  75. #define OCSC_HW_CGC_EN (1 << 7)
  76. #define REG_UFS_CFG2_CGC_EN_ALL (UAWM_HW_CGC_EN | UARM_HW_CGC_EN |\
  77. TXUC_HW_CGC_EN | RXUC_HW_CGC_EN |\
  78. DFC_HW_CGC_EN | TRLUT_HW_CGC_EN |\
  79. TMRLUT_HW_CGC_EN | OCSC_HW_CGC_EN)
  80. /* bit offset */
  81. enum {
  82. OFFSET_UFS_PHY_SOFT_RESET = 1,
  83. OFFSET_CLK_NS_REG = 10,
  84. };
  85. /* bit masks */
  86. enum {
  87. MASK_UFS_PHY_SOFT_RESET = 0x2,
  88. MASK_TX_SYMBOL_CLK_1US_REG = 0x3FF,
  89. MASK_CLK_NS_REG = 0xFFFC00,
  90. };
  91. enum ufs_qcom_phy_init_type {
  92. UFS_PHY_INIT_FULL,
  93. UFS_PHY_INIT_CFG_RESTORE,
  94. };
  95. static inline void
  96. ufs_qcom_get_controller_revision(struct ufs_hba *hba,
  97. u8 *major, u16 *minor, u16 *step)
  98. {
  99. u32 ver = ufshcd_readl(hba, REG_UFS_HW_VERSION);
  100. *major = (ver & UFS_HW_VER_MAJOR_MASK) >> UFS_HW_VER_MAJOR_SHFT;
  101. *minor = (ver & UFS_HW_VER_MINOR_MASK) >> UFS_HW_VER_MINOR_SHFT;
  102. *step = (ver & UFS_HW_VER_STEP_MASK) >> UFS_HW_VER_STEP_SHFT;
  103. };
  104. static inline void ufs_qcom_assert_reset(struct ufs_hba *hba)
  105. {
  106. ufshcd_rmwl(hba, MASK_UFS_PHY_SOFT_RESET,
  107. 1 << OFFSET_UFS_PHY_SOFT_RESET, REG_UFS_CFG1);
  108. /*
  109. * Make sure assertion of ufs phy reset is written to
  110. * register before returning
  111. */
  112. mb();
  113. }
  114. static inline void ufs_qcom_deassert_reset(struct ufs_hba *hba)
  115. {
  116. ufshcd_rmwl(hba, MASK_UFS_PHY_SOFT_RESET,
  117. 0 << OFFSET_UFS_PHY_SOFT_RESET, REG_UFS_CFG1);
  118. /*
  119. * Make sure de-assertion of ufs phy reset is written to
  120. * register before returning
  121. */
  122. mb();
  123. }
  124. struct ufs_qcom_bus_vote {
  125. uint32_t client_handle;
  126. uint32_t curr_vote;
  127. int min_bw_vote;
  128. int max_bw_vote;
  129. int saved_vote;
  130. bool is_max_bw_needed;
  131. struct device_attribute max_bus_bw;
  132. };
  133. /* Host controller hardware version: major.minor.step */
  134. struct ufs_hw_version {
  135. u16 step;
  136. u16 minor;
  137. u8 major;
  138. };
  139. struct ufs_qcom_host {
  140. /*
  141. * Set this capability if host controller supports the QUniPro mode
  142. * and if driver wants the Host controller to operate in QUniPro mode.
  143. * Note: By default this capability will be kept enabled if host
  144. * controller supports the QUniPro mode.
  145. */
  146. #define UFS_QCOM_CAP_QUNIPRO UFS_BIT(0)
  147. u32 caps;
  148. struct phy *generic_phy;
  149. struct ufs_hba *hba;
  150. struct ufs_qcom_bus_vote bus_vote;
  151. struct ufs_pa_layer_attr dev_req_params;
  152. struct clk *rx_l0_sync_clk;
  153. struct clk *tx_l0_sync_clk;
  154. struct clk *rx_l1_sync_clk;
  155. struct clk *tx_l1_sync_clk;
  156. bool is_lane_clks_enabled;
  157. struct ufs_hw_version hw_ver;
  158. };
  159. #define ufs_qcom_is_link_off(hba) ufshcd_is_link_off(hba)
  160. #define ufs_qcom_is_link_active(hba) ufshcd_is_link_active(hba)
  161. #define ufs_qcom_is_link_hibern8(hba) ufshcd_is_link_hibern8(hba)
  162. static inline bool ufs_qcom_cap_qunipro(struct ufs_qcom_host *host)
  163. {
  164. if (host->caps & UFS_QCOM_CAP_QUNIPRO)
  165. return true;
  166. else
  167. return false;
  168. }
  169. #endif /* UFS_QCOM_H_ */