Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Meson G12A USB2 PHY driver |
| 4 | * |
| 5 | * Copyright (C) 2017 Martin Blumenstingl <martin.blumenstingl@googlemail.com> |
| 6 | * Copyright (C) 2019 BayLibre, SAS |
| 7 | * Author: Neil Armstrong <narmstron@baylibre.com> |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | #include <bitfield.h> |
| 15 | #include <dm.h> |
| 16 | #include <errno.h> |
| 17 | #include <generic-phy.h> |
| 18 | #include <regmap.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 19 | #include <linux/delay.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 20 | #include <linux/printk.h> |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 21 | #include <power/regulator.h> |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 22 | #include <power-domain.h> |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 23 | #include <reset.h> |
| 24 | #include <clk.h> |
| 25 | |
| 26 | #include <linux/bitops.h> |
| 27 | #include <linux/compat.h> |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 28 | #include <linux/bitfield.h> |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 29 | |
| 30 | #define PHY_CTRL_R0 0x0 |
| 31 | #define PHY_CTRL_R1 0x4 |
| 32 | #define PHY_CTRL_R2 0x8 |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 33 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 34 | #define PHY_CTRL_R3 0xc |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 35 | #define PHY_CTRL_R3_SQUELCH_REF GENMASK(1, 0) |
| 36 | #define PHY_CTRL_R3_HSDIC_REF GENMASK(3, 2) |
| 37 | #define PHY_CTRL_R3_DISC_THRESH GENMASK(7, 4) |
| 38 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 39 | #define PHY_CTRL_R4 0x10 |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 40 | #define PHY_CTRL_R4_CALIB_CODE_7_0 GENMASK(7, 0) |
| 41 | #define PHY_CTRL_R4_CALIB_CODE_15_8 GENMASK(15, 8) |
| 42 | #define PHY_CTRL_R4_CALIB_CODE_23_16 GENMASK(23, 16) |
| 43 | #define PHY_CTRL_R4_I_C2L_CAL_EN BIT(24) |
| 44 | #define PHY_CTRL_R4_I_C2L_CAL_RESET_N BIT(25) |
| 45 | #define PHY_CTRL_R4_I_C2L_CAL_DONE BIT(26) |
| 46 | #define PHY_CTRL_R4_TEST_BYPASS_MODE_EN BIT(27) |
| 47 | #define PHY_CTRL_R4_I_C2L_BIAS_TRIM_1_0 GENMASK(29, 28) |
| 48 | #define PHY_CTRL_R4_I_C2L_BIAS_TRIM_3_2 GENMASK(31, 30) |
| 49 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 50 | #define PHY_CTRL_R5 0x14 |
| 51 | #define PHY_CTRL_R6 0x18 |
| 52 | #define PHY_CTRL_R7 0x1c |
| 53 | #define PHY_CTRL_R8 0x20 |
| 54 | #define PHY_CTRL_R9 0x24 |
| 55 | #define PHY_CTRL_R10 0x28 |
| 56 | #define PHY_CTRL_R11 0x2c |
| 57 | #define PHY_CTRL_R12 0x30 |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 58 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 59 | #define PHY_CTRL_R13 0x34 |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 60 | #define PHY_CTRL_R13_CUSTOM_PATTERN_19 GENMASK(7, 0) |
| 61 | #define PHY_CTRL_R13_LOAD_STAT BIT(14) |
| 62 | #define PHY_CTRL_R13_UPDATE_PMA_SIGNALS BIT(15) |
| 63 | #define PHY_CTRL_R13_MIN_COUNT_FOR_SYNC_DET GENMASK(20, 16) |
| 64 | #define PHY_CTRL_R13_CLEAR_HOLD_HS_DISCONNECT BIT(21) |
| 65 | #define PHY_CTRL_R13_BYPASS_HOST_DISCONNECT_VAL BIT(22) |
| 66 | #define PHY_CTRL_R13_BYPASS_HOST_DISCONNECT_EN BIT(23) |
| 67 | #define PHY_CTRL_R13_I_C2L_HS_EN BIT(24) |
| 68 | #define PHY_CTRL_R13_I_C2L_FS_EN BIT(25) |
| 69 | #define PHY_CTRL_R13_I_C2L_LS_EN BIT(26) |
| 70 | #define PHY_CTRL_R13_I_C2L_HS_OE BIT(27) |
| 71 | #define PHY_CTRL_R13_I_C2L_FS_OE BIT(28) |
| 72 | #define PHY_CTRL_R13_I_C2L_HS_RX_EN BIT(29) |
| 73 | #define PHY_CTRL_R13_I_C2L_FSLS_RX_EN BIT(30) |
| 74 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 75 | #define PHY_CTRL_R14 0x38 |
| 76 | #define PHY_CTRL_R15 0x3c |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 77 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 78 | #define PHY_CTRL_R16 0x40 |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 79 | #define PHY_CTRL_R16_MPLL_M GENMASK(8, 0) |
| 80 | #define PHY_CTRL_R16_MPLL_N GENMASK(14, 10) |
| 81 | #define PHY_CTRL_R16_MPLL_TDC_MODE BIT(20) |
| 82 | #define PHY_CTRL_R16_MPLL_SDM_EN BIT(21) |
| 83 | #define PHY_CTRL_R16_MPLL_LOAD BIT(22) |
| 84 | #define PHY_CTRL_R16_MPLL_DCO_SDM_EN BIT(23) |
| 85 | #define PHY_CTRL_R16_MPLL_LOCK_LONG GENMASK(25, 24) |
| 86 | #define PHY_CTRL_R16_MPLL_LOCK_F BIT(26) |
| 87 | #define PHY_CTRL_R16_MPLL_FAST_LOCK BIT(27) |
| 88 | #define PHY_CTRL_R16_MPLL_EN BIT(28) |
| 89 | #define PHY_CTRL_R16_MPLL_RESET BIT(29) |
| 90 | #define PHY_CTRL_R16_MPLL_LOCK BIT(30) |
| 91 | #define PHY_CTRL_R16_MPLL_LOCK_DIG BIT(31) |
| 92 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 93 | #define PHY_CTRL_R17 0x44 |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 94 | #define PHY_CTRL_R17_MPLL_FRAC_IN GENMASK(13, 0) |
| 95 | #define PHY_CTRL_R17_MPLL_FIX_EN BIT(16) |
| 96 | #define PHY_CTRL_R17_MPLL_LAMBDA1 GENMASK(19, 17) |
| 97 | #define PHY_CTRL_R17_MPLL_LAMBDA0 GENMASK(22, 20) |
| 98 | #define PHY_CTRL_R17_MPLL_FILTER_MODE BIT(23) |
| 99 | #define PHY_CTRL_R17_MPLL_FILTER_PVT2 GENMASK(27, 24) |
| 100 | #define PHY_CTRL_R17_MPLL_FILTER_PVT1 GENMASK(31, 28) |
| 101 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 102 | #define PHY_CTRL_R18 0x48 |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 103 | #define PHY_CTRL_R18_MPLL_LKW_SEL GENMASK(1, 0) |
| 104 | #define PHY_CTRL_R18_MPLL_LK_W GENMASK(5, 2) |
| 105 | #define PHY_CTRL_R18_MPLL_LK_S GENMASK(11, 6) |
| 106 | #define PHY_CTRL_R18_MPLL_DCO_M_EN BIT(12) |
| 107 | #define PHY_CTRL_R18_MPLL_DCO_CLK_SEL BIT(13) |
| 108 | #define PHY_CTRL_R18_MPLL_PFD_GAIN GENMASK(15, 14) |
| 109 | #define PHY_CTRL_R18_MPLL_ROU GENMASK(18, 16) |
| 110 | #define PHY_CTRL_R18_MPLL_DATA_SEL GENMASK(21, 19) |
| 111 | #define PHY_CTRL_R18_MPLL_BIAS_ADJ GENMASK(23, 22) |
| 112 | #define PHY_CTRL_R18_MPLL_BB_MODE GENMASK(25, 24) |
| 113 | #define PHY_CTRL_R18_MPLL_ALPHA GENMASK(28, 26) |
| 114 | #define PHY_CTRL_R18_MPLL_ADJ_LDO GENMASK(30, 29) |
| 115 | #define PHY_CTRL_R18_MPLL_ACG_RANGE BIT(31) |
| 116 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 117 | #define PHY_CTRL_R19 0x4c |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 118 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 119 | #define PHY_CTRL_R20 0x50 |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 120 | #define PHY_CTRL_R20_USB2_IDDET_EN BIT(0) |
| 121 | #define PHY_CTRL_R20_USB2_OTG_VBUS_TRIM_2_0 GENMASK(3, 1) |
| 122 | #define PHY_CTRL_R20_USB2_OTG_VBUSDET_EN BIT(4) |
| 123 | #define PHY_CTRL_R20_USB2_AMON_EN BIT(5) |
| 124 | #define PHY_CTRL_R20_USB2_CAL_CODE_R5 BIT(6) |
| 125 | #define PHY_CTRL_R20_BYPASS_OTG_DET BIT(7) |
| 126 | #define PHY_CTRL_R20_USB2_DMON_EN BIT(8) |
| 127 | #define PHY_CTRL_R20_USB2_DMON_SEL_3_0 GENMASK(12, 9) |
| 128 | #define PHY_CTRL_R20_USB2_EDGE_DRV_EN BIT(13) |
| 129 | #define PHY_CTRL_R20_USB2_EDGE_DRV_TRIM_1_0 GENMASK(15, 14) |
| 130 | #define PHY_CTRL_R20_USB2_BGR_ADJ_4_0 GENMASK(20, 16) |
| 131 | #define PHY_CTRL_R20_USB2_BGR_START BIT(21) |
| 132 | #define PHY_CTRL_R20_USB2_BGR_VREF_4_0 GENMASK(28, 24) |
| 133 | #define PHY_CTRL_R20_USB2_BGR_DBG_1_0 GENMASK(30, 29) |
| 134 | #define PHY_CTRL_R20_BYPASS_CAL_DONE_R5 BIT(31) |
| 135 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 136 | #define PHY_CTRL_R21 0x54 |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 137 | #define PHY_CTRL_R21_USB2_BGR_FORCE BIT(0) |
| 138 | #define PHY_CTRL_R21_USB2_CAL_ACK_EN BIT(1) |
| 139 | #define PHY_CTRL_R21_USB2_OTG_ACA_EN BIT(2) |
| 140 | #define PHY_CTRL_R21_USB2_TX_STRG_PD BIT(3) |
| 141 | #define PHY_CTRL_R21_USB2_OTG_ACA_TRIM_1_0 GENMASK(5, 4) |
| 142 | #define PHY_CTRL_R21_BYPASS_UTMI_CNTR GENMASK(15, 6) |
| 143 | #define PHY_CTRL_R21_BYPASS_UTMI_REG GENMASK(25, 20) |
| 144 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 145 | #define PHY_CTRL_R22 0x58 |
| 146 | #define PHY_CTRL_R23 0x5c |
| 147 | |
| 148 | #define RESET_COMPLETE_TIME 1000 |
| 149 | #define PLL_RESET_COMPLETE_TIME 100 |
| 150 | |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 151 | enum meson_soc_id { |
| 152 | MESON_SOC_A1, |
| 153 | MESON_SOC_G12A, |
| 154 | }; |
| 155 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 156 | struct phy_meson_g12a_usb2_priv { |
| 157 | struct regmap *regmap; |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 158 | #if CONFIG_IS_ENABLED(CLK) |
| 159 | struct clk clk; |
| 160 | #endif |
| 161 | struct reset_ctl reset; |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 162 | #if CONFIG_IS_ENABLED(POWER_DOMAIN) |
| 163 | struct power_domain pwrdm; |
| 164 | #endif |
| 165 | int soc_id; |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 166 | }; |
| 167 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 168 | static int phy_meson_g12a_usb2_init(struct phy *phy) |
| 169 | { |
| 170 | struct udevice *dev = phy->dev; |
| 171 | struct phy_meson_g12a_usb2_priv *priv = dev_get_priv(dev); |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 172 | u32 value; |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 173 | int ret; |
| 174 | |
Alexey Romanov | 80f45c3 | 2023-10-05 11:54:25 +0300 | [diff] [blame] | 175 | #if CONFIG_IS_ENABLED(CLK) |
| 176 | ret = clk_enable(&priv->clk); |
| 177 | if (ret && ret != -ENOSYS && ret != -ENOTSUPP) { |
| 178 | pr_err("failed to enable PHY clock\n"); |
| 179 | return ret; |
| 180 | } |
| 181 | #endif |
| 182 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 183 | ret = reset_assert(&priv->reset); |
| 184 | udelay(1); |
| 185 | ret |= reset_deassert(&priv->reset); |
| 186 | if (ret) |
| 187 | return ret; |
| 188 | |
| 189 | udelay(RESET_COMPLETE_TIME); |
| 190 | |
| 191 | /* usb2_otg_aca_en == 0 */ |
| 192 | regmap_update_bits(priv->regmap, PHY_CTRL_R21, BIT(2), 0); |
| 193 | |
| 194 | /* PLL Setup : 24MHz * 20 / 1 = 480MHz */ |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 195 | regmap_write(priv->regmap, PHY_CTRL_R16, |
| 196 | FIELD_PREP(PHY_CTRL_R16_MPLL_M, 20) | |
| 197 | FIELD_PREP(PHY_CTRL_R16_MPLL_N, 1) | |
| 198 | PHY_CTRL_R16_MPLL_LOAD | |
| 199 | FIELD_PREP(PHY_CTRL_R16_MPLL_LOCK_LONG, 1) | |
| 200 | PHY_CTRL_R16_MPLL_FAST_LOCK | |
| 201 | PHY_CTRL_R16_MPLL_EN | |
| 202 | PHY_CTRL_R16_MPLL_RESET); |
| 203 | |
| 204 | regmap_write(priv->regmap, PHY_CTRL_R17, |
| 205 | FIELD_PREP(PHY_CTRL_R17_MPLL_FRAC_IN, 0) | |
| 206 | FIELD_PREP(PHY_CTRL_R17_MPLL_LAMBDA1, 7) | |
| 207 | FIELD_PREP(PHY_CTRL_R17_MPLL_LAMBDA0, 7) | |
| 208 | FIELD_PREP(PHY_CTRL_R17_MPLL_FILTER_PVT2, 2) | |
| 209 | FIELD_PREP(PHY_CTRL_R17_MPLL_FILTER_PVT1, 9)); |
| 210 | |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 211 | value = FIELD_PREP(PHY_CTRL_R18_MPLL_LKW_SEL, 1) | |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 212 | FIELD_PREP(PHY_CTRL_R18_MPLL_LK_W, 9) | |
| 213 | FIELD_PREP(PHY_CTRL_R18_MPLL_LK_S, 0x27) | |
| 214 | FIELD_PREP(PHY_CTRL_R18_MPLL_PFD_GAIN, 1) | |
| 215 | FIELD_PREP(PHY_CTRL_R18_MPLL_ROU, 7) | |
| 216 | FIELD_PREP(PHY_CTRL_R18_MPLL_DATA_SEL, 3) | |
| 217 | FIELD_PREP(PHY_CTRL_R18_MPLL_BIAS_ADJ, 1) | |
| 218 | FIELD_PREP(PHY_CTRL_R18_MPLL_BB_MODE, 0) | |
| 219 | FIELD_PREP(PHY_CTRL_R18_MPLL_ALPHA, 3) | |
| 220 | FIELD_PREP(PHY_CTRL_R18_MPLL_ADJ_LDO, 1) | |
| 221 | PHY_CTRL_R18_MPLL_ACG_RANGE; |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 222 | |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 223 | if (priv->soc_id == MESON_SOC_A1) |
| 224 | value |= PHY_CTRL_R18_MPLL_DCO_CLK_SEL; |
| 225 | |
| 226 | regmap_write(priv->regmap, PHY_CTRL_R18, value); |
| 227 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 228 | udelay(PLL_RESET_COMPLETE_TIME); |
| 229 | |
| 230 | /* UnReset PLL */ |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 231 | regmap_write(priv->regmap, PHY_CTRL_R16, |
| 232 | FIELD_PREP(PHY_CTRL_R16_MPLL_M, 20) | |
| 233 | FIELD_PREP(PHY_CTRL_R16_MPLL_N, 1) | |
| 234 | PHY_CTRL_R16_MPLL_LOAD | |
| 235 | FIELD_PREP(PHY_CTRL_R16_MPLL_LOCK_LONG, 1) | |
| 236 | PHY_CTRL_R16_MPLL_FAST_LOCK | |
| 237 | PHY_CTRL_R16_MPLL_EN); |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 238 | |
| 239 | /* PHY Tuning */ |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 240 | regmap_write(priv->regmap, PHY_CTRL_R20, |
| 241 | FIELD_PREP(PHY_CTRL_R20_USB2_OTG_VBUS_TRIM_2_0, 4) | |
| 242 | PHY_CTRL_R20_USB2_OTG_VBUSDET_EN | |
| 243 | FIELD_PREP(PHY_CTRL_R20_USB2_DMON_SEL_3_0, 15) | |
| 244 | PHY_CTRL_R20_USB2_EDGE_DRV_EN | |
| 245 | FIELD_PREP(PHY_CTRL_R20_USB2_EDGE_DRV_TRIM_1_0, 3) | |
| 246 | FIELD_PREP(PHY_CTRL_R20_USB2_BGR_ADJ_4_0, 0) | |
| 247 | FIELD_PREP(PHY_CTRL_R20_USB2_BGR_VREF_4_0, 0) | |
| 248 | FIELD_PREP(PHY_CTRL_R20_USB2_BGR_DBG_1_0, 0)); |
| 249 | |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 250 | if (priv->soc_id == MESON_SOC_G12A) |
| 251 | regmap_write(priv->regmap, PHY_CTRL_R4, |
| 252 | FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_7_0, 0xf) | |
| 253 | FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_15_8, 0xf) | |
| 254 | FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_23_16, 0xf) | |
| 255 | PHY_CTRL_R4_TEST_BYPASS_MODE_EN | |
| 256 | FIELD_PREP(PHY_CTRL_R4_I_C2L_BIAS_TRIM_1_0, 0) | |
| 257 | FIELD_PREP(PHY_CTRL_R4_I_C2L_BIAS_TRIM_3_2, 0)); |
| 258 | else if (priv->soc_id == MESON_SOC_A1) |
| 259 | regmap_write(priv->regmap, PHY_CTRL_R21, |
| 260 | PHY_CTRL_R21_USB2_CAL_ACK_EN | |
| 261 | PHY_CTRL_R21_USB2_TX_STRG_PD | |
| 262 | FIELD_PREP(PHY_CTRL_R21_USB2_OTG_ACA_TRIM_1_0, 2)); |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 263 | |
| 264 | /* Tuning Disconnect Threshold */ |
Alexey Romanov | 8817149 | 2023-10-05 11:54:24 +0300 | [diff] [blame] | 265 | regmap_write(priv->regmap, PHY_CTRL_R3, |
| 266 | FIELD_PREP(PHY_CTRL_R3_SQUELCH_REF, 0) | |
| 267 | FIELD_PREP(PHY_CTRL_R3_HSDIC_REF, 1) | |
| 268 | FIELD_PREP(PHY_CTRL_R3_DISC_THRESH, 3)); |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 269 | |
| 270 | /* Analog Settings */ |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 271 | if (priv->soc_id == MESON_SOC_G12A) { |
| 272 | regmap_write(priv->regmap, PHY_CTRL_R14, 0); |
| 273 | regmap_write(priv->regmap, PHY_CTRL_R13, |
| 274 | PHY_CTRL_R13_UPDATE_PMA_SIGNALS | |
| 275 | FIELD_PREP(PHY_CTRL_R13_MIN_COUNT_FOR_SYNC_DET, 7)); |
| 276 | } else if (priv->soc_id == MESON_SOC_A1) { |
| 277 | regmap_write(priv->regmap, PHY_CTRL_R13, |
| 278 | FIELD_PREP(PHY_CTRL_R13_MIN_COUNT_FOR_SYNC_DET, 7)); |
| 279 | } |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static int phy_meson_g12a_usb2_exit(struct phy *phy) |
| 285 | { |
| 286 | struct udevice *dev = phy->dev; |
| 287 | struct phy_meson_g12a_usb2_priv *priv = dev_get_priv(dev); |
| 288 | int ret; |
| 289 | |
Alexey Romanov | 80f45c3 | 2023-10-05 11:54:25 +0300 | [diff] [blame] | 290 | #if CONFIG_IS_ENABLED(CLK) |
| 291 | clk_disable(&priv->clk); |
| 292 | #endif |
| 293 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 294 | ret = reset_assert(&priv->reset); |
| 295 | if (ret) |
| 296 | return ret; |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | struct phy_ops meson_g12a_usb2_phy_ops = { |
| 302 | .init = phy_meson_g12a_usb2_init, |
| 303 | .exit = phy_meson_g12a_usb2_exit, |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | int meson_g12a_usb2_phy_probe(struct udevice *dev) |
| 307 | { |
| 308 | struct phy_meson_g12a_usb2_priv *priv = dev_get_priv(dev); |
| 309 | int ret; |
| 310 | |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 311 | priv->soc_id = (enum meson_soc_id)dev_get_driver_data(dev); |
| 312 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 313 | ret = regmap_init_mem(dev_ofnode(dev), &priv->regmap); |
| 314 | if (ret) |
| 315 | return ret; |
| 316 | |
| 317 | ret = reset_get_by_index(dev, 0, &priv->reset); |
| 318 | if (ret == -ENOTSUPP) |
| 319 | return 0; |
| 320 | else if (ret) |
| 321 | return ret; |
| 322 | |
| 323 | ret = reset_deassert(&priv->reset); |
| 324 | if (ret) { |
| 325 | reset_release_all(&priv->reset, 1); |
| 326 | return ret; |
| 327 | } |
| 328 | |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 329 | #if CONFIG_IS_ENABLED(POWER_DOMAIN) |
| 330 | ret = power_domain_get(dev, &priv->pwrdm); |
Guillaume La Roque | f699cb1d | 2023-10-17 20:57:25 +0200 | [diff] [blame] | 331 | if (ret < 0 && ret != -ENODEV && ret != -ENOENT) { |
| 332 | pr_err("failed to get power domain : %d\n", ret); |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 333 | return ret; |
| 334 | } |
| 335 | |
Guillaume La Roque | f699cb1d | 2023-10-17 20:57:25 +0200 | [diff] [blame] | 336 | if (ret != -ENODEV && ret != -ENOENT) { |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 337 | ret = power_domain_on(&priv->pwrdm); |
| 338 | if (ret < 0) { |
| 339 | pr_err("failed to enable power domain\n"); |
| 340 | return ret; |
| 341 | } |
| 342 | } |
| 343 | #endif |
| 344 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 345 | #if CONFIG_IS_ENABLED(CLK) |
| 346 | ret = clk_get_by_index(dev, 0, &priv->clk); |
| 347 | if (ret < 0) |
| 348 | return ret; |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 349 | #endif |
| 350 | |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | static const struct udevice_id meson_g12a_usb2_phy_ids[] = { |
Alexey Romanov | 5533c88 | 2023-10-05 11:54:26 +0300 | [diff] [blame] | 355 | { |
| 356 | .compatible = "amlogic,g12a-usb2-phy", |
| 357 | .data = (ulong)MESON_SOC_G12A, |
| 358 | }, |
| 359 | { |
| 360 | .compatible = "amlogic,a1-usb2-phy", |
| 361 | .data = (ulong)MESON_SOC_A1, |
| 362 | }, |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 363 | { } |
| 364 | }; |
| 365 | |
| 366 | U_BOOT_DRIVER(meson_g12a_usb2_phy) = { |
| 367 | .name = "meson_g12a_usb2_phy", |
| 368 | .id = UCLASS_PHY, |
| 369 | .of_match = meson_g12a_usb2_phy_ids, |
| 370 | .probe = meson_g12a_usb2_phy_probe, |
| 371 | .ops = &meson_g12a_usb2_phy_ops, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 372 | .priv_auto = sizeof(struct phy_meson_g12a_usb2_priv), |
Neil Armstrong | 277d916 | 2019-02-19 15:17:29 +0100 | [diff] [blame] | 373 | }; |