Yaniv Gardi | 81c0fc5 | 2015-01-15 16:32:37 +0200 | [diff] [blame] | 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 | |
| 14 | #ifndef UFS_QCOM_H_ |
| 15 | #define UFS_QCOM_H_ |
| 16 | |
| 17 | #define MAX_UFS_QCOM_HOSTS 1 |
| 18 | #define MAX_U32 (~(u32)0) |
| 19 | #define MPHY_TX_FSM_STATE 0x41 |
| 20 | #define TX_FSM_HIBERN8 0x1 |
| 21 | #define HBRN8_POLL_TOUT_MS 100 |
| 22 | #define DEFAULT_CLK_RATE_HZ 1000000 |
| 23 | #define BUS_VECTOR_NAME_LEN 32 |
| 24 | |
| 25 | #define UFS_HW_VER_MAJOR_SHFT (28) |
| 26 | #define UFS_HW_VER_MAJOR_MASK (0x000F << UFS_HW_VER_MAJOR_SHFT) |
| 27 | #define UFS_HW_VER_MINOR_SHFT (16) |
| 28 | #define UFS_HW_VER_MINOR_MASK (0x0FFF << UFS_HW_VER_MINOR_SHFT) |
| 29 | #define UFS_HW_VER_STEP_SHFT (0) |
| 30 | #define UFS_HW_VER_STEP_MASK (0xFFFF << UFS_HW_VER_STEP_SHFT) |
| 31 | |
| 32 | /* vendor specific pre-defined parameters */ |
| 33 | #define SLOW 1 |
| 34 | #define FAST 2 |
| 35 | |
| 36 | #define UFS_QCOM_LIMIT_NUM_LANES_RX 2 |
| 37 | #define UFS_QCOM_LIMIT_NUM_LANES_TX 2 |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 38 | #define UFS_QCOM_LIMIT_HSGEAR_RX UFS_HS_G3 |
| 39 | #define UFS_QCOM_LIMIT_HSGEAR_TX UFS_HS_G3 |
Yaniv Gardi | 81c0fc5 | 2015-01-15 16:32:37 +0200 | [diff] [blame] | 40 | #define UFS_QCOM_LIMIT_PWMGEAR_RX UFS_PWM_G4 |
| 41 | #define UFS_QCOM_LIMIT_PWMGEAR_TX UFS_PWM_G4 |
| 42 | #define UFS_QCOM_LIMIT_RX_PWR_PWM SLOW_MODE |
| 43 | #define UFS_QCOM_LIMIT_TX_PWR_PWM SLOW_MODE |
| 44 | #define UFS_QCOM_LIMIT_RX_PWR_HS FAST_MODE |
| 45 | #define UFS_QCOM_LIMIT_TX_PWR_HS FAST_MODE |
| 46 | #define UFS_QCOM_LIMIT_HS_RATE PA_HS_MODE_B |
| 47 | #define UFS_QCOM_LIMIT_DESIRED_MODE FAST |
| 48 | |
| 49 | /* QCOM UFS host controller vendor specific registers */ |
| 50 | enum { |
| 51 | REG_UFS_SYS1CLK_1US = 0xC0, |
| 52 | REG_UFS_TX_SYMBOL_CLK_NS_US = 0xC4, |
| 53 | REG_UFS_LOCAL_PORT_ID_REG = 0xC8, |
| 54 | REG_UFS_PA_ERR_CODE = 0xCC, |
| 55 | REG_UFS_RETRY_TIMER_REG = 0xD0, |
| 56 | REG_UFS_PA_LINK_STARTUP_TIMER = 0xD8, |
| 57 | REG_UFS_CFG1 = 0xDC, |
| 58 | REG_UFS_CFG2 = 0xE0, |
| 59 | REG_UFS_HW_VERSION = 0xE4, |
| 60 | |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 61 | UFS_TEST_BUS = 0xE8, |
| 62 | UFS_TEST_BUS_CTRL_0 = 0xEC, |
| 63 | UFS_TEST_BUS_CTRL_1 = 0xF0, |
| 64 | UFS_TEST_BUS_CTRL_2 = 0xF4, |
| 65 | UFS_UNIPRO_CFG = 0xF8, |
| 66 | |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 67 | /* |
| 68 | * QCOM UFS host controller vendor specific registers |
| 69 | * added in HW Version 3.0.0 |
| 70 | */ |
| 71 | UFS_AH8_CFG = 0xFC, |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /* QCOM UFS host controller vendor specific debug registers */ |
| 75 | enum { |
Yaniv Gardi | 81c0fc5 | 2015-01-15 16:32:37 +0200 | [diff] [blame] | 76 | UFS_DBG_RD_REG_UAWM = 0x100, |
| 77 | UFS_DBG_RD_REG_UARM = 0x200, |
| 78 | UFS_DBG_RD_REG_TXUC = 0x300, |
| 79 | UFS_DBG_RD_REG_RXUC = 0x400, |
| 80 | UFS_DBG_RD_REG_DFC = 0x500, |
| 81 | UFS_DBG_RD_REG_TRLUT = 0x600, |
| 82 | UFS_DBG_RD_REG_TMRLUT = 0x700, |
| 83 | UFS_UFS_DBG_RD_REG_OCSC = 0x800, |
| 84 | |
| 85 | UFS_UFS_DBG_RD_DESC_RAM = 0x1500, |
| 86 | UFS_UFS_DBG_RD_PRDT_RAM = 0x1700, |
| 87 | UFS_UFS_DBG_RD_RESP_RAM = 0x1800, |
| 88 | UFS_UFS_DBG_RD_EDTL_RAM = 0x1900, |
| 89 | }; |
| 90 | |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 91 | #define UFS_CNTLR_2_x_x_VEN_REGS_OFFSET(x) (0x000 + x) |
| 92 | #define UFS_CNTLR_3_x_x_VEN_REGS_OFFSET(x) (0x400 + x) |
| 93 | |
| 94 | /* bit definitions for REG_UFS_CFG1 register */ |
| 95 | #define QUNIPRO_SEL UFS_BIT(0) |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 96 | #define TEST_BUS_EN BIT(18) |
| 97 | #define TEST_BUS_SEL GENMASK(22, 19) |
Venkat Gopalakrishnan | 9c46b86 | 2017-02-03 16:58:12 -0800 | [diff] [blame] | 98 | #define UFS_REG_TEST_BUS_EN BIT(30) |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 99 | |
Yaniv Gardi | 81c0fc5 | 2015-01-15 16:32:37 +0200 | [diff] [blame] | 100 | /* bit definitions for REG_UFS_CFG2 register */ |
| 101 | #define UAWM_HW_CGC_EN (1 << 0) |
| 102 | #define UARM_HW_CGC_EN (1 << 1) |
| 103 | #define TXUC_HW_CGC_EN (1 << 2) |
| 104 | #define RXUC_HW_CGC_EN (1 << 3) |
| 105 | #define DFC_HW_CGC_EN (1 << 4) |
| 106 | #define TRLUT_HW_CGC_EN (1 << 5) |
| 107 | #define TMRLUT_HW_CGC_EN (1 << 6) |
| 108 | #define OCSC_HW_CGC_EN (1 << 7) |
| 109 | |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 110 | /* bit definition for UFS_UFS_TEST_BUS_CTRL_n */ |
| 111 | #define TEST_BUS_SUB_SEL_MASK 0x1F /* All XXX_SEL fields are 5 bits wide */ |
| 112 | |
Yaniv Gardi | 81c0fc5 | 2015-01-15 16:32:37 +0200 | [diff] [blame] | 113 | #define REG_UFS_CFG2_CGC_EN_ALL (UAWM_HW_CGC_EN | UARM_HW_CGC_EN |\ |
| 114 | TXUC_HW_CGC_EN | RXUC_HW_CGC_EN |\ |
| 115 | DFC_HW_CGC_EN | TRLUT_HW_CGC_EN |\ |
| 116 | TMRLUT_HW_CGC_EN | OCSC_HW_CGC_EN) |
| 117 | |
| 118 | /* bit offset */ |
| 119 | enum { |
| 120 | OFFSET_UFS_PHY_SOFT_RESET = 1, |
| 121 | OFFSET_CLK_NS_REG = 10, |
| 122 | }; |
| 123 | |
| 124 | /* bit masks */ |
| 125 | enum { |
| 126 | MASK_UFS_PHY_SOFT_RESET = 0x2, |
| 127 | MASK_TX_SYMBOL_CLK_1US_REG = 0x3FF, |
| 128 | MASK_CLK_NS_REG = 0xFFFC00, |
| 129 | }; |
| 130 | |
| 131 | enum ufs_qcom_phy_init_type { |
| 132 | UFS_PHY_INIT_FULL, |
| 133 | UFS_PHY_INIT_CFG_RESTORE, |
| 134 | }; |
| 135 | |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 136 | /* QCOM UFS debug print bit mask */ |
| 137 | #define UFS_QCOM_DBG_PRINT_REGS_EN BIT(0) |
| 138 | #define UFS_QCOM_DBG_PRINT_ICE_REGS_EN BIT(1) |
| 139 | #define UFS_QCOM_DBG_PRINT_TEST_BUS_EN BIT(2) |
| 140 | |
| 141 | #define UFS_QCOM_DBG_PRINT_ALL \ |
| 142 | (UFS_QCOM_DBG_PRINT_REGS_EN | UFS_QCOM_DBG_PRINT_ICE_REGS_EN | \ |
| 143 | UFS_QCOM_DBG_PRINT_TEST_BUS_EN) |
| 144 | |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 145 | /* QUniPro Vendor specific attributes */ |
Subhash Jadavani | 56d4a18 | 2016-12-05 19:25:32 -0800 | [diff] [blame] | 146 | #define PA_VS_CONFIG_REG1 0x9000 |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 147 | #define DME_VS_CORE_CLK_CTRL 0xD002 |
| 148 | /* bit and mask definitions for DME_VS_CORE_CLK_CTRL attribute */ |
| 149 | #define DME_VS_CORE_CLK_CTRL_CORE_CLK_DIV_EN_BIT BIT(8) |
| 150 | #define DME_VS_CORE_CLK_CTRL_MAX_CORE_CLK_1US_CYCLES_MASK 0xFF |
| 151 | |
Yaniv Gardi | 81c0fc5 | 2015-01-15 16:32:37 +0200 | [diff] [blame] | 152 | static inline void |
| 153 | ufs_qcom_get_controller_revision(struct ufs_hba *hba, |
| 154 | u8 *major, u16 *minor, u16 *step) |
| 155 | { |
| 156 | u32 ver = ufshcd_readl(hba, REG_UFS_HW_VERSION); |
| 157 | |
| 158 | *major = (ver & UFS_HW_VER_MAJOR_MASK) >> UFS_HW_VER_MAJOR_SHFT; |
| 159 | *minor = (ver & UFS_HW_VER_MINOR_MASK) >> UFS_HW_VER_MINOR_SHFT; |
| 160 | *step = (ver & UFS_HW_VER_STEP_MASK) >> UFS_HW_VER_STEP_SHFT; |
| 161 | }; |
| 162 | |
| 163 | static inline void ufs_qcom_assert_reset(struct ufs_hba *hba) |
| 164 | { |
| 165 | ufshcd_rmwl(hba, MASK_UFS_PHY_SOFT_RESET, |
| 166 | 1 << OFFSET_UFS_PHY_SOFT_RESET, REG_UFS_CFG1); |
| 167 | |
| 168 | /* |
| 169 | * Make sure assertion of ufs phy reset is written to |
| 170 | * register before returning |
| 171 | */ |
| 172 | mb(); |
| 173 | } |
| 174 | |
| 175 | static inline void ufs_qcom_deassert_reset(struct ufs_hba *hba) |
| 176 | { |
| 177 | ufshcd_rmwl(hba, MASK_UFS_PHY_SOFT_RESET, |
| 178 | 0 << OFFSET_UFS_PHY_SOFT_RESET, REG_UFS_CFG1); |
| 179 | |
| 180 | /* |
| 181 | * Make sure de-assertion of ufs phy reset is written to |
| 182 | * register before returning |
| 183 | */ |
| 184 | mb(); |
| 185 | } |
| 186 | |
| 187 | struct ufs_qcom_bus_vote { |
| 188 | uint32_t client_handle; |
| 189 | uint32_t curr_vote; |
| 190 | int min_bw_vote; |
| 191 | int max_bw_vote; |
| 192 | int saved_vote; |
| 193 | bool is_max_bw_needed; |
| 194 | struct device_attribute max_bus_bw; |
| 195 | }; |
| 196 | |
Yaniv Gardi | bfdbe8b | 2015-03-31 17:37:13 +0300 | [diff] [blame] | 197 | /* Host controller hardware version: major.minor.step */ |
| 198 | struct ufs_hw_version { |
| 199 | u16 step; |
| 200 | u16 minor; |
| 201 | u8 major; |
| 202 | }; |
Yaniv Gardi | cad2e03 | 2015-03-31 17:37:14 +0300 | [diff] [blame] | 203 | |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 204 | struct ufs_qcom_testbus { |
| 205 | u8 select_major; |
| 206 | u8 select_minor; |
| 207 | }; |
| 208 | |
| 209 | struct ufs_qcom_host { |
Yaniv Gardi | cad2e03 | 2015-03-31 17:37:14 +0300 | [diff] [blame] | 210 | /* |
| 211 | * Set this capability if host controller supports the QUniPro mode |
| 212 | * and if driver wants the Host controller to operate in QUniPro mode. |
| 213 | * Note: By default this capability will be kept enabled if host |
| 214 | * controller supports the QUniPro mode. |
| 215 | */ |
| 216 | #define UFS_QCOM_CAP_QUNIPRO UFS_BIT(0) |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 217 | |
| 218 | /* |
| 219 | * Set this capability if host controller can retain the secure |
| 220 | * configuration even after UFS controller core power collapse. |
| 221 | */ |
| 222 | #define UFS_QCOM_CAP_RETAIN_SEC_CFG_AFTER_PWR_COLLAPSE UFS_BIT(1) |
Yaniv Gardi | cad2e03 | 2015-03-31 17:37:14 +0300 | [diff] [blame] | 223 | u32 caps; |
| 224 | |
Yaniv Gardi | 81c0fc5 | 2015-01-15 16:32:37 +0200 | [diff] [blame] | 225 | struct phy *generic_phy; |
| 226 | struct ufs_hba *hba; |
| 227 | struct ufs_qcom_bus_vote bus_vote; |
| 228 | struct ufs_pa_layer_attr dev_req_params; |
| 229 | struct clk *rx_l0_sync_clk; |
| 230 | struct clk *tx_l0_sync_clk; |
| 231 | struct clk *rx_l1_sync_clk; |
| 232 | struct clk *tx_l1_sync_clk; |
| 233 | bool is_lane_clks_enabled; |
Yaniv Gardi | bfdbe8b | 2015-03-31 17:37:13 +0300 | [diff] [blame] | 234 | |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 235 | void __iomem *dev_ref_clk_ctrl_mmio; |
| 236 | bool is_dev_ref_clk_enabled; |
Yaniv Gardi | bfdbe8b | 2015-03-31 17:37:13 +0300 | [diff] [blame] | 237 | struct ufs_hw_version hw_ver; |
Yaniv Gardi | f06fcc7 | 2015-10-28 13:15:51 +0200 | [diff] [blame] | 238 | |
| 239 | u32 dev_ref_clk_en_mask; |
| 240 | |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 241 | /* Bitmask for enabling debug prints */ |
| 242 | u32 dbg_print_en; |
| 243 | struct ufs_qcom_testbus testbus; |
Yaniv Gardi | 81c0fc5 | 2015-01-15 16:32:37 +0200 | [diff] [blame] | 244 | }; |
| 245 | |
Yaniv Gardi | eba5ed3 | 2016-03-10 17:37:21 +0200 | [diff] [blame] | 246 | static inline u32 |
| 247 | ufs_qcom_get_debug_reg_offset(struct ufs_qcom_host *host, u32 reg) |
| 248 | { |
| 249 | if (host->hw_ver.major <= 0x02) |
| 250 | return UFS_CNTLR_2_x_x_VEN_REGS_OFFSET(reg); |
| 251 | |
| 252 | return UFS_CNTLR_3_x_x_VEN_REGS_OFFSET(reg); |
| 253 | }; |
| 254 | |
Yaniv Gardi | 81c0fc5 | 2015-01-15 16:32:37 +0200 | [diff] [blame] | 255 | #define ufs_qcom_is_link_off(hba) ufshcd_is_link_off(hba) |
| 256 | #define ufs_qcom_is_link_active(hba) ufshcd_is_link_active(hba) |
| 257 | #define ufs_qcom_is_link_hibern8(hba) ufshcd_is_link_hibern8(hba) |
| 258 | |
Yaniv Gardi | 6e3fd44 | 2015-10-28 13:15:50 +0200 | [diff] [blame] | 259 | int ufs_qcom_testbus_config(struct ufs_qcom_host *host); |
| 260 | |
Yaniv Gardi | cad2e03 | 2015-03-31 17:37:14 +0300 | [diff] [blame] | 261 | static inline bool ufs_qcom_cap_qunipro(struct ufs_qcom_host *host) |
| 262 | { |
| 263 | if (host->caps & UFS_QCOM_CAP_QUNIPRO) |
| 264 | return true; |
| 265 | else |
| 266 | return false; |
| 267 | } |
| 268 | |
Yaniv Gardi | 81c0fc5 | 2015-01-15 16:32:37 +0200 | [diff] [blame] | 269 | #endif /* UFS_QCOM_H_ */ |