Bhupesh Sharma | fe6b5cc | 2024-04-03 14:07:37 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2023 Bhupesh Sharma <bhupesh.sharma@linaro.org> |
| 4 | * |
| 5 | * Based on Linux driver |
| 6 | */ |
| 7 | |
| 8 | #include <dm.h> |
| 9 | #include <generic-phy.h> |
| 10 | #include <linux/bitops.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <reset.h> |
| 13 | #include <clk.h> |
| 14 | #include <linux/delay.h> |
| 15 | |
| 16 | #include <dt-bindings/phy/phy-qcom-qusb2.h> |
| 17 | |
| 18 | #define QUSB2PHY_PLL 0x0 |
| 19 | #define QUSB2PHY_PLL_TEST 0x04 |
| 20 | #define CLK_REF_SEL BIT(7) |
| 21 | |
| 22 | #define QUSB2PHY_PLL_TUNE 0x08 |
| 23 | #define QUSB2PHY_PLL_USER_CTL1 0x0c |
| 24 | #define QUSB2PHY_PLL_USER_CTL2 0x10 |
| 25 | #define QUSB2PHY_PLL_AUTOPGM_CTL1 0x1c |
| 26 | #define QUSB2PHY_PLL_PWR_CTRL 0x18 |
| 27 | |
| 28 | /* QUSB2PHY_PLL_STATUS register bits */ |
| 29 | #define PLL_LOCKED BIT(5) |
| 30 | |
| 31 | /* QUSB2PHY_PLL_COMMON_STATUS_ONE register bits */ |
| 32 | #define CORE_READY_STATUS BIT(0) |
| 33 | |
| 34 | /* QUSB2PHY_PORT_POWERDOWN register bits */ |
| 35 | #define CLAMP_N_EN BIT(5) |
| 36 | #define FREEZIO_N BIT(1) |
| 37 | #define POWER_DOWN BIT(0) |
| 38 | |
| 39 | /* QUSB2PHY_PWR_CTRL1 register bits */ |
| 40 | #define PWR_CTRL1_VREF_SUPPLY_TRIM BIT(5) |
| 41 | #define PWR_CTRL1_CLAMP_N_EN BIT(1) |
| 42 | |
| 43 | #define QUSB2PHY_REFCLK_ENABLE BIT(0) |
| 44 | |
| 45 | #define PHY_CLK_SCHEME_SEL BIT(0) |
| 46 | |
| 47 | /* QUSB2PHY_INTR_CTRL register bits */ |
| 48 | #define DMSE_INTR_HIGH_SEL BIT(4) |
| 49 | #define DPSE_INTR_HIGH_SEL BIT(3) |
| 50 | #define CHG_DET_INTR_EN BIT(2) |
| 51 | #define DMSE_INTR_EN BIT(1) |
| 52 | #define DPSE_INTR_EN BIT(0) |
| 53 | |
| 54 | /* QUSB2PHY_PLL_CORE_INPUT_OVERRIDE register bits */ |
| 55 | #define CORE_PLL_EN_FROM_RESET BIT(4) |
| 56 | #define CORE_RESET BIT(5) |
| 57 | #define CORE_RESET_MUX BIT(6) |
| 58 | |
| 59 | /* QUSB2PHY_IMP_CTRL1 register bits */ |
| 60 | #define IMP_RES_OFFSET_MASK GENMASK(5, 0) |
| 61 | #define IMP_RES_OFFSET_SHIFT 0x0 |
| 62 | |
| 63 | /* QUSB2PHY_PLL_BIAS_CONTROL_2 register bits */ |
| 64 | #define BIAS_CTRL2_RES_OFFSET_MASK GENMASK(5, 0) |
| 65 | #define BIAS_CTRL2_RES_OFFSET_SHIFT 0x0 |
| 66 | |
| 67 | /* QUSB2PHY_CHG_CONTROL_2 register bits */ |
| 68 | #define CHG_CTRL2_OFFSET_MASK GENMASK(5, 4) |
| 69 | #define CHG_CTRL2_OFFSET_SHIFT 0x4 |
| 70 | |
| 71 | /* QUSB2PHY_PORT_TUNE1 register bits */ |
| 72 | #define HSTX_TRIM_MASK GENMASK(7, 4) |
| 73 | #define HSTX_TRIM_SHIFT 0x4 |
| 74 | #define PREEMPH_WIDTH_HALF_BIT BIT(2) |
| 75 | #define PREEMPHASIS_EN_MASK GENMASK(1, 0) |
| 76 | #define PREEMPHASIS_EN_SHIFT 0x0 |
| 77 | |
| 78 | /* QUSB2PHY_PORT_TUNE2 register bits */ |
| 79 | #define HSDISC_TRIM_MASK GENMASK(1, 0) |
| 80 | #define HSDISC_TRIM_SHIFT 0x0 |
| 81 | |
| 82 | #define QUSB2PHY_PLL_ANALOG_CONTROLS_TWO 0x04 |
| 83 | #define QUSB2PHY_PLL_CLOCK_INVERTERS 0x18c |
| 84 | #define QUSB2PHY_PLL_CMODE 0x2c |
| 85 | #define QUSB2PHY_PLL_LOCK_DELAY 0x184 |
| 86 | #define QUSB2PHY_PLL_DIGITAL_TIMERS_TWO 0xb4 |
| 87 | #define QUSB2PHY_PLL_BIAS_CONTROL_1 0x194 |
| 88 | #define QUSB2PHY_PLL_BIAS_CONTROL_2 0x198 |
| 89 | #define QUSB2PHY_PWR_CTRL2 0x214 |
| 90 | #define QUSB2PHY_IMP_CTRL1 0x220 |
| 91 | #define QUSB2PHY_IMP_CTRL2 0x224 |
| 92 | #define QUSB2PHY_CHG_CTRL2 0x23c |
| 93 | |
| 94 | struct qusb2_phy_init_tbl { |
| 95 | unsigned int offset; |
| 96 | unsigned int val; |
| 97 | /* |
| 98 | * register part of layout ? |
| 99 | * if yes, then offset gives index in the reg-layout |
| 100 | */ |
| 101 | int in_layout; |
| 102 | }; |
| 103 | |
| 104 | struct qusb2_phy_cfg { |
| 105 | const struct qusb2_phy_init_tbl *tbl; |
| 106 | /* number of entries in the table */ |
| 107 | unsigned int tbl_num; |
| 108 | /* offset to PHY_CLK_SCHEME register in TCSR map */ |
| 109 | unsigned int clk_scheme_offset; |
| 110 | |
| 111 | /* array of registers with different offsets */ |
| 112 | const unsigned int *regs; |
| 113 | unsigned int mask_core_ready; |
| 114 | unsigned int disable_ctrl; |
| 115 | unsigned int autoresume_en; |
| 116 | |
| 117 | /* true if PHY has PLL_TEST register to select clk_scheme */ |
| 118 | bool has_pll_test; |
| 119 | |
| 120 | /* true if TUNE1 register must be updated by fused value, else TUNE2 */ |
| 121 | bool update_tune1_with_efuse; |
| 122 | |
| 123 | /* true if PHY has PLL_CORE_INPUT_OVERRIDE register to reset PLL */ |
| 124 | bool has_pll_override; |
Alexey Minnekhanov | c7ac32d | 2025-03-25 11:37:13 +0300 | [diff] [blame] | 125 | |
| 126 | /* true if PHY default clk scheme is single-ended */ |
| 127 | bool se_clk_scheme_default; |
Bhupesh Sharma | fe6b5cc | 2024-04-03 14:07:37 +0200 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | /* set of registers with offsets different per-PHY */ |
| 131 | enum qusb2phy_reg_layout { |
| 132 | QUSB2PHY_PLL_CORE_INPUT_OVERRIDE, |
| 133 | QUSB2PHY_PLL_STATUS, |
| 134 | QUSB2PHY_PORT_TUNE1, |
| 135 | QUSB2PHY_PORT_TUNE2, |
| 136 | QUSB2PHY_PORT_TUNE3, |
| 137 | QUSB2PHY_PORT_TUNE4, |
| 138 | QUSB2PHY_PORT_TUNE5, |
| 139 | QUSB2PHY_PORT_TEST1, |
| 140 | QUSB2PHY_PORT_TEST2, |
| 141 | QUSB2PHY_PORT_POWERDOWN, |
| 142 | QUSB2PHY_INTR_CTRL, |
| 143 | }; |
| 144 | |
| 145 | #define QUSB2_PHY_INIT_CFG(o, v) \ |
| 146 | { \ |
| 147 | .offset = o, .val = v, \ |
| 148 | } |
| 149 | |
| 150 | #define QUSB2_PHY_INIT_CFG_L(o, v) \ |
| 151 | { \ |
| 152 | .offset = o, .val = v, .in_layout = 1, \ |
| 153 | } |
| 154 | |
| 155 | static const struct qusb2_phy_init_tbl sm6115_init_tbl[] = { |
| 156 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE1, 0xf8), |
| 157 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE2, 0x53), |
| 158 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE3, 0x81), |
| 159 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE4, 0x17), |
| 160 | |
| 161 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_TUNE, 0x30), |
| 162 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL1, 0x79), |
| 163 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL2, 0x21), |
| 164 | |
| 165 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TEST2, 0x14), |
| 166 | |
| 167 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_AUTOPGM_CTL1, 0x9f), |
| 168 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_PWR_CTRL, 0x00), |
| 169 | }; |
| 170 | |
| 171 | static const unsigned int sm6115_regs_layout[] = { |
| 172 | [QUSB2PHY_PLL_STATUS] = 0x38, [QUSB2PHY_PORT_TUNE1] = 0x80, |
| 173 | [QUSB2PHY_PORT_TUNE2] = 0x84, [QUSB2PHY_PORT_TUNE3] = 0x88, |
| 174 | [QUSB2PHY_PORT_TUNE4] = 0x8c, [QUSB2PHY_PORT_TUNE5] = 0x90, |
| 175 | [QUSB2PHY_PORT_TEST1] = 0xb8, [QUSB2PHY_PORT_TEST2] = 0x9c, |
| 176 | [QUSB2PHY_PORT_POWERDOWN] = 0xb4, [QUSB2PHY_INTR_CTRL] = 0xbc, |
| 177 | }; |
| 178 | |
Alexey Minnekhanov | c7ac32d | 2025-03-25 11:37:13 +0300 | [diff] [blame] | 179 | static const struct qusb2_phy_init_tbl msm8996_init_tbl[] = { |
| 180 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE1, 0xf8), |
| 181 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE2, 0xb3), |
| 182 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE3, 0x83), |
| 183 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE4, 0xc0), |
| 184 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_TUNE, 0x30), |
| 185 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL1, 0x79), |
| 186 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_USER_CTL2, 0x21), |
| 187 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TEST2, 0x14), |
| 188 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_AUTOPGM_CTL1, 0x9f), |
| 189 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_PWR_CTRL, 0x00), |
| 190 | }; |
| 191 | |
Bhupesh Sharma | fe6b5cc | 2024-04-03 14:07:37 +0200 | [diff] [blame] | 192 | static const struct qusb2_phy_init_tbl qusb2_v2_init_tbl[] = { |
| 193 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_ANALOG_CONTROLS_TWO, 0x03), |
| 194 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_CLOCK_INVERTERS, 0x7c), |
| 195 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_CMODE, 0x80), |
| 196 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_LOCK_DELAY, 0x0a), |
| 197 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_DIGITAL_TIMERS_TWO, 0x19), |
| 198 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_BIAS_CONTROL_1, 0x40), |
| 199 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PLL_BIAS_CONTROL_2, 0x20), |
| 200 | QUSB2_PHY_INIT_CFG(QUSB2PHY_PWR_CTRL2, 0x21), |
| 201 | QUSB2_PHY_INIT_CFG(QUSB2PHY_IMP_CTRL1, 0x0), |
| 202 | QUSB2_PHY_INIT_CFG(QUSB2PHY_IMP_CTRL2, 0x58), |
| 203 | |
| 204 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE1, 0x30), |
| 205 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE2, 0x29), |
| 206 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE3, 0xca), |
| 207 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE4, 0x04), |
| 208 | QUSB2_PHY_INIT_CFG_L(QUSB2PHY_PORT_TUNE5, 0x03), |
| 209 | |
| 210 | QUSB2_PHY_INIT_CFG(QUSB2PHY_CHG_CTRL2, 0x0), |
| 211 | }; |
| 212 | |
| 213 | static const unsigned int qusb2_v2_regs_layout[] = { |
| 214 | [QUSB2PHY_PLL_CORE_INPUT_OVERRIDE] = 0xa8, |
| 215 | [QUSB2PHY_PLL_STATUS] = 0x1a0, |
| 216 | [QUSB2PHY_PORT_TUNE1] = 0x240, |
| 217 | [QUSB2PHY_PORT_TUNE2] = 0x244, |
| 218 | [QUSB2PHY_PORT_TUNE3] = 0x248, |
| 219 | [QUSB2PHY_PORT_TUNE4] = 0x24c, |
| 220 | [QUSB2PHY_PORT_TUNE5] = 0x250, |
| 221 | [QUSB2PHY_PORT_TEST1] = 0x254, |
| 222 | [QUSB2PHY_PORT_TEST2] = 0x258, |
| 223 | [QUSB2PHY_PORT_POWERDOWN] = 0x210, |
| 224 | [QUSB2PHY_INTR_CTRL] = 0x230, |
| 225 | }; |
| 226 | |
| 227 | static const struct qusb2_phy_cfg sm6115_phy_cfg = { |
| 228 | .tbl = sm6115_init_tbl, |
| 229 | .tbl_num = ARRAY_SIZE(sm6115_init_tbl), |
| 230 | .regs = sm6115_regs_layout, |
| 231 | |
| 232 | .has_pll_test = true, |
Sumit Garg | 8dfafa9 | 2025-04-10 13:30:27 +0530 | [diff] [blame] | 233 | .se_clk_scheme_default = true, |
Bhupesh Sharma | fe6b5cc | 2024-04-03 14:07:37 +0200 | [diff] [blame] | 234 | .disable_ctrl = (CLAMP_N_EN | FREEZIO_N | POWER_DOWN), |
| 235 | .mask_core_ready = PLL_LOCKED, |
| 236 | .autoresume_en = BIT(3), |
| 237 | }; |
| 238 | |
Alexey Minnekhanov | c7ac32d | 2025-03-25 11:37:13 +0300 | [diff] [blame] | 239 | static const struct qusb2_phy_cfg sdm660_phy_cfg = { |
| 240 | .tbl = msm8996_init_tbl, |
| 241 | .tbl_num = ARRAY_SIZE(msm8996_init_tbl), |
| 242 | .regs = sm6115_regs_layout, |
| 243 | |
| 244 | .has_pll_test = true, |
| 245 | .se_clk_scheme_default = false, |
| 246 | .disable_ctrl = (CLAMP_N_EN | FREEZIO_N | POWER_DOWN), |
| 247 | .mask_core_ready = PLL_LOCKED, |
| 248 | .autoresume_en = BIT(3), |
| 249 | }; |
| 250 | |
Bhupesh Sharma | fe6b5cc | 2024-04-03 14:07:37 +0200 | [diff] [blame] | 251 | static const struct qusb2_phy_cfg qusb2_v2_phy_cfg = { |
| 252 | .tbl = qusb2_v2_init_tbl, |
| 253 | .tbl_num = ARRAY_SIZE(qusb2_v2_init_tbl), |
| 254 | .regs = qusb2_v2_regs_layout, |
| 255 | |
| 256 | .disable_ctrl = (PWR_CTRL1_VREF_SUPPLY_TRIM | PWR_CTRL1_CLAMP_N_EN | |
| 257 | POWER_DOWN), |
| 258 | .mask_core_ready = CORE_READY_STATUS, |
| 259 | .has_pll_override = true, |
Sumit Garg | 8dfafa9 | 2025-04-10 13:30:27 +0530 | [diff] [blame] | 260 | .se_clk_scheme_default = true, |
Bhupesh Sharma | fe6b5cc | 2024-04-03 14:07:37 +0200 | [diff] [blame] | 261 | .autoresume_en = BIT(0), |
| 262 | .update_tune1_with_efuse = true, |
| 263 | }; |
| 264 | |
| 265 | /** |
| 266 | * struct qusb2_phy - structure holding qusb2 phy attributes |
| 267 | * |
| 268 | * @phy: generic phy |
| 269 | * @base: iomapped memory space for qubs2 phy |
| 270 | * |
| 271 | * @cfg_ahb_clk: AHB2PHY interface clock |
| 272 | * @phy_rst: phy reset control |
| 273 | * |
| 274 | * @cfg: phy config data |
| 275 | * @has_se_clk_scheme: indicate if PHY has single-ended ref clock scheme |
| 276 | */ |
| 277 | struct qusb2_phy { |
| 278 | struct phy *phy; |
| 279 | void __iomem *base; |
| 280 | |
| 281 | struct clk cfg_ahb_clk; |
| 282 | struct reset_ctl phy_rst; |
| 283 | |
| 284 | const struct qusb2_phy_cfg *cfg; |
| 285 | bool has_se_clk_scheme; |
| 286 | }; |
| 287 | |
| 288 | static inline void qusb2_phy_configure(void __iomem *base, |
| 289 | const unsigned int *regs, |
| 290 | const struct qusb2_phy_init_tbl tbl[], |
| 291 | int num) |
| 292 | { |
| 293 | int i; |
| 294 | |
| 295 | for (i = 0; i < num; i++) { |
| 296 | if (tbl[i].in_layout) |
| 297 | writel(tbl[i].val, base + regs[tbl[i].offset]); |
| 298 | else |
| 299 | writel(tbl[i].val, base + tbl[i].offset); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | static int qusb2phy_do_reset(struct qusb2_phy *qphy) |
| 304 | { |
| 305 | int ret; |
| 306 | |
| 307 | ret = reset_assert(&qphy->phy_rst); |
| 308 | if (ret) |
| 309 | return ret; |
| 310 | |
| 311 | udelay(500); |
| 312 | |
| 313 | ret = reset_deassert(&qphy->phy_rst); |
| 314 | if (ret) |
| 315 | return ret; |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | static int qusb2phy_power_on(struct phy *phy) |
| 321 | { |
| 322 | struct qusb2_phy *qphy = dev_get_priv(phy->dev); |
| 323 | const struct qusb2_phy_cfg *cfg = qphy->cfg; |
| 324 | int ret; |
| 325 | u32 val; |
| 326 | |
| 327 | ret = qusb2phy_do_reset(qphy); |
| 328 | if (ret) |
| 329 | return ret; |
| 330 | |
| 331 | /* Disable the PHY */ |
| 332 | setbits_le32(qphy->base + cfg->regs[QUSB2PHY_PORT_POWERDOWN], |
| 333 | qphy->cfg->disable_ctrl); |
| 334 | |
| 335 | if (cfg->has_pll_test) { |
| 336 | /* save reset value to override reference clock scheme later */ |
| 337 | val = readl(qphy->base + QUSB2PHY_PLL_TEST); |
| 338 | } |
| 339 | |
| 340 | qusb2_phy_configure(qphy->base, cfg->regs, cfg->tbl, cfg->tbl_num); |
| 341 | |
| 342 | /* Enable the PHY */ |
| 343 | clrbits_le32(qphy->base + cfg->regs[QUSB2PHY_PORT_POWERDOWN], |
| 344 | POWER_DOWN); |
| 345 | |
| 346 | /* Required to get phy pll lock successfully */ |
| 347 | udelay(150); |
| 348 | |
Alexey Minnekhanov | c7ac32d | 2025-03-25 11:37:13 +0300 | [diff] [blame] | 349 | /* |
| 350 | * Not all the SoCs have got a readable TCSR_PHY_CLK_SCHEME |
| 351 | * register in the TCSR so, if there's none, use the default |
| 352 | * value hardcoded in the configuration. |
| 353 | */ |
| 354 | qphy->has_se_clk_scheme = cfg->se_clk_scheme_default; |
| 355 | |
Bhupesh Sharma | fe6b5cc | 2024-04-03 14:07:37 +0200 | [diff] [blame] | 356 | if (cfg->has_pll_test) { |
Alexey Minnekhanov | c7ac32d | 2025-03-25 11:37:13 +0300 | [diff] [blame] | 357 | if (!qphy->has_se_clk_scheme) |
| 358 | val &= ~CLK_REF_SEL; |
| 359 | else |
| 360 | val |= CLK_REF_SEL; |
Bhupesh Sharma | fe6b5cc | 2024-04-03 14:07:37 +0200 | [diff] [blame] | 361 | |
| 362 | writel(val, qphy->base + QUSB2PHY_PLL_TEST); |
| 363 | |
| 364 | /* ensure above write is through */ |
| 365 | readl(qphy->base + QUSB2PHY_PLL_TEST); |
| 366 | } |
| 367 | |
| 368 | /* Required to get phy pll lock successfully */ |
| 369 | udelay(100); |
| 370 | |
| 371 | val = readb(qphy->base + cfg->regs[QUSB2PHY_PLL_STATUS]); |
| 372 | if (!(val & cfg->mask_core_ready)) { |
| 373 | pr_err("QUSB2PHY pll lock failed: status reg = %x\n", val); |
| 374 | ret = -EBUSY; |
| 375 | return ret; |
| 376 | } |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | static int qusb2phy_power_off(struct phy *phy) |
| 382 | { |
| 383 | struct qusb2_phy *qphy = dev_get_priv(phy->dev); |
| 384 | |
| 385 | /* Disable the PHY */ |
| 386 | setbits_le32(qphy->base + qphy->cfg->regs[QUSB2PHY_PORT_POWERDOWN], |
| 387 | qphy->cfg->disable_ctrl); |
| 388 | |
| 389 | reset_assert(&qphy->phy_rst); |
| 390 | |
| 391 | clk_disable(&qphy->cfg_ahb_clk); |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static int qusb2phy_clk_init(struct udevice *dev, struct qusb2_phy *qphy) |
| 397 | { |
| 398 | int ret; |
| 399 | |
| 400 | /* We ignore the ref clock as we currently lack a driver for rpmcc/rpmhcc where |
| 401 | * it usually comes from - we assume it's always on. |
| 402 | */ |
| 403 | ret = clk_get_by_name(dev, "cfg_ahb", &qphy->cfg_ahb_clk); |
| 404 | if (ret == -ENOSYS || ret == -ENOENT) |
| 405 | return 0; |
| 406 | if (ret) |
| 407 | return ret; |
| 408 | |
| 409 | ret = clk_enable(&qphy->cfg_ahb_clk); |
| 410 | if (ret) |
| 411 | return ret; |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | static int qusb2phy_probe(struct udevice *dev) |
| 417 | { |
| 418 | struct qusb2_phy *qphy = dev_get_priv(dev); |
| 419 | int ret; |
| 420 | |
| 421 | qphy->base = (void __iomem *)dev_read_addr(dev); |
| 422 | if (IS_ERR(qphy->base)) |
| 423 | return PTR_ERR(qphy->base); |
| 424 | |
| 425 | ret = qusb2phy_clk_init(dev, qphy); |
| 426 | if (ret) { |
| 427 | printf("%s: Couldn't get clocks: %d\n", __func__, ret); |
| 428 | return ret; |
| 429 | } |
| 430 | |
| 431 | ret = reset_get_by_index(dev, 0, &qphy->phy_rst); |
| 432 | if (ret) { |
| 433 | printf("%s: Couldn't get resets: %d\n", __func__, ret); |
| 434 | return ret; |
| 435 | } |
| 436 | |
| 437 | qphy->cfg = (const struct qusb2_phy_cfg *)dev_get_driver_data(dev); |
| 438 | if (!qphy->cfg) { |
| 439 | printf("%s: Couldn't get driver data\n", __func__); |
| 440 | return -EINVAL; |
| 441 | } |
| 442 | |
| 443 | debug("%s success qusb phy cfg %p\n", __func__, qphy->cfg); |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | static struct phy_ops qusb2phy_ops = { |
| 448 | .power_on = qusb2phy_power_on, |
| 449 | .power_off = qusb2phy_power_off, |
| 450 | }; |
| 451 | |
| 452 | static const struct udevice_id qusb2phy_ids[] = { |
| 453 | { .compatible = "qcom,qusb2-phy" }, |
| 454 | { .compatible = "qcom,qcm2290-qusb2-phy", |
| 455 | .data = (ulong)&sm6115_phy_cfg }, |
Alexey Minnekhanov | c7ac32d | 2025-03-25 11:37:13 +0300 | [diff] [blame] | 456 | { .compatible = "qcom,sdm660-qusb2-phy", |
| 457 | .data = (ulong)&sdm660_phy_cfg }, |
Bhupesh Sharma | fe6b5cc | 2024-04-03 14:07:37 +0200 | [diff] [blame] | 458 | { .compatible = "qcom,sm6115-qusb2-phy", |
| 459 | .data = (ulong)&sm6115_phy_cfg }, |
| 460 | { .compatible = "qcom,qusb2-v2-phy", .data = (ulong)&qusb2_v2_phy_cfg }, |
| 461 | {} |
| 462 | }; |
| 463 | |
| 464 | U_BOOT_DRIVER(qcom_qusb2_phy) = { |
| 465 | .name = "qcom-qusb2-phy", |
| 466 | .id = UCLASS_PHY, |
| 467 | .of_match = qusb2phy_ids, |
| 468 | .ops = &qusb2phy_ops, |
| 469 | .probe = qusb2phy_probe, |
| 470 | .priv_auto = sizeof(struct qusb2_phy), |
| 471 | }; |