Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Cadence Sierra PHY Driver |
| 4 | * |
| 5 | * Based on the linux driver provided by Cadence |
| 6 | * |
| 7 | * Copyright (c) 2018 Cadence Design Systems |
| 8 | * Author: Alan Douglas <adouglas@cadence.com> |
| 9 | * |
| 10 | * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ |
| 11 | * Jean-Jacques Hiblot <jjhiblot@ti.com> |
| 12 | * |
| 13 | */ |
| 14 | #include <common.h> |
| 15 | #include <clk.h> |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 16 | #include <linux/clk-provider.h> |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 17 | #include <generic-phy.h> |
| 18 | #include <reset.h> |
| 19 | #include <dm/device.h> |
| 20 | #include <dm/device-internal.h> |
| 21 | #include <dm/device_compat.h> |
| 22 | #include <dm/lists.h> |
| 23 | #include <dm/read.h> |
| 24 | #include <dm/uclass.h> |
| 25 | #include <dm/devres.h> |
| 26 | #include <linux/io.h> |
| 27 | #include <dt-bindings/phy/phy.h> |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 28 | #include <dt-bindings/phy/phy-cadence.h> |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 29 | #include <regmap.h> |
| 30 | |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 31 | #define NUM_SSC_MODE 3 |
| 32 | #define NUM_PHY_TYPE 3 |
| 33 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 34 | /* PHY register offsets */ |
| 35 | #define SIERRA_COMMON_CDB_OFFSET 0x0 |
| 36 | #define SIERRA_MACRO_ID_REG 0x0 |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 37 | #define SIERRA_CMN_PLLLC_GEN_PREG 0x42 |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 38 | #define SIERRA_CMN_PLLLC_MODE_PREG 0x48 |
| 39 | #define SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG 0x49 |
| 40 | #define SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG 0x4A |
| 41 | #define SIERRA_CMN_PLLLC_LOCK_CNTSTART_PREG 0x4B |
| 42 | #define SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG 0x4F |
| 43 | #define SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG 0x50 |
| 44 | #define SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG 0x62 |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 45 | #define SIERRA_CMN_REFRCV_PREG 0x98 |
| 46 | #define SIERRA_CMN_REFRCV1_PREG 0xB8 |
| 47 | #define SIERRA_CMN_PLLLC1_GEN_PREG 0xC2 |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 48 | |
| 49 | #define SIERRA_LANE_CDB_OFFSET(ln, offset) \ |
| 50 | (0x4000 + ((ln) * (0x800 >> (2 - (offset))))) |
| 51 | |
| 52 | #define SIERRA_DET_STANDEC_A_PREG 0x000 |
| 53 | #define SIERRA_DET_STANDEC_B_PREG 0x001 |
| 54 | #define SIERRA_DET_STANDEC_C_PREG 0x002 |
| 55 | #define SIERRA_DET_STANDEC_D_PREG 0x003 |
| 56 | #define SIERRA_DET_STANDEC_E_PREG 0x004 |
| 57 | #define SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG 0x008 |
| 58 | #define SIERRA_PSM_A0IN_TMR_PREG 0x009 |
| 59 | #define SIERRA_PSM_DIAG_PREG 0x015 |
| 60 | #define SIERRA_PSC_TX_A0_PREG 0x028 |
| 61 | #define SIERRA_PSC_TX_A1_PREG 0x029 |
| 62 | #define SIERRA_PSC_TX_A2_PREG 0x02A |
| 63 | #define SIERRA_PSC_TX_A3_PREG 0x02B |
| 64 | #define SIERRA_PSC_RX_A0_PREG 0x030 |
| 65 | #define SIERRA_PSC_RX_A1_PREG 0x031 |
| 66 | #define SIERRA_PSC_RX_A2_PREG 0x032 |
| 67 | #define SIERRA_PSC_RX_A3_PREG 0x033 |
| 68 | #define SIERRA_PLLCTRL_SUBRATE_PREG 0x03A |
| 69 | #define SIERRA_PLLCTRL_GEN_D_PREG 0x03E |
| 70 | #define SIERRA_PLLCTRL_CPGAIN_MODE_PREG 0x03F |
| 71 | #define SIERRA_PLLCTRL_STATUS_PREG 0x044 |
| 72 | #define SIERRA_CLKPATH_BIASTRIM_PREG 0x04B |
| 73 | #define SIERRA_DFE_BIASTRIM_PREG 0x04C |
| 74 | #define SIERRA_DRVCTRL_ATTEN_PREG 0x06A |
| 75 | #define SIERRA_CLKPATHCTRL_TMR_PREG 0x081 |
| 76 | #define SIERRA_RX_CREQ_FLTR_A_MODE3_PREG 0x085 |
| 77 | #define SIERRA_RX_CREQ_FLTR_A_MODE2_PREG 0x086 |
| 78 | #define SIERRA_RX_CREQ_FLTR_A_MODE1_PREG 0x087 |
| 79 | #define SIERRA_RX_CREQ_FLTR_A_MODE0_PREG 0x088 |
| 80 | #define SIERRA_CREQ_CCLKDET_MODE01_PREG 0x08E |
| 81 | #define SIERRA_RX_CTLE_MAINTENANCE_PREG 0x091 |
| 82 | #define SIERRA_CREQ_FSMCLK_SEL_PREG 0x092 |
| 83 | #define SIERRA_CREQ_EQ_CTRL_PREG 0x093 |
| 84 | #define SIERRA_CREQ_SPARE_PREG 0x096 |
| 85 | #define SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG 0x097 |
| 86 | #define SIERRA_CTLELUT_CTRL_PREG 0x098 |
| 87 | #define SIERRA_DFE_ECMP_RATESEL_PREG 0x0C0 |
| 88 | #define SIERRA_DFE_SMP_RATESEL_PREG 0x0C1 |
| 89 | #define SIERRA_DEQ_PHALIGN_CTRL 0x0C4 |
| 90 | #define SIERRA_DEQ_CONCUR_CTRL1_PREG 0x0C8 |
| 91 | #define SIERRA_DEQ_CONCUR_CTRL2_PREG 0x0C9 |
| 92 | #define SIERRA_DEQ_EPIPWR_CTRL2_PREG 0x0CD |
| 93 | #define SIERRA_DEQ_FAST_MAINT_CYCLES_PREG 0x0CE |
| 94 | #define SIERRA_DEQ_ERRCMP_CTRL_PREG 0x0D0 |
| 95 | #define SIERRA_DEQ_OFFSET_CTRL_PREG 0x0D8 |
| 96 | #define SIERRA_DEQ_GAIN_CTRL_PREG 0x0E0 |
| 97 | #define SIERRA_DEQ_VGATUNE_CTRL_PREG 0x0E1 |
| 98 | #define SIERRA_DEQ_GLUT0 0x0E8 |
| 99 | #define SIERRA_DEQ_GLUT1 0x0E9 |
| 100 | #define SIERRA_DEQ_GLUT2 0x0EA |
| 101 | #define SIERRA_DEQ_GLUT3 0x0EB |
| 102 | #define SIERRA_DEQ_GLUT4 0x0EC |
| 103 | #define SIERRA_DEQ_GLUT5 0x0ED |
| 104 | #define SIERRA_DEQ_GLUT6 0x0EE |
| 105 | #define SIERRA_DEQ_GLUT7 0x0EF |
| 106 | #define SIERRA_DEQ_GLUT8 0x0F0 |
| 107 | #define SIERRA_DEQ_GLUT9 0x0F1 |
| 108 | #define SIERRA_DEQ_GLUT10 0x0F2 |
| 109 | #define SIERRA_DEQ_GLUT11 0x0F3 |
| 110 | #define SIERRA_DEQ_GLUT12 0x0F4 |
| 111 | #define SIERRA_DEQ_GLUT13 0x0F5 |
| 112 | #define SIERRA_DEQ_GLUT14 0x0F6 |
| 113 | #define SIERRA_DEQ_GLUT15 0x0F7 |
| 114 | #define SIERRA_DEQ_GLUT16 0x0F8 |
| 115 | #define SIERRA_DEQ_ALUT0 0x108 |
| 116 | #define SIERRA_DEQ_ALUT1 0x109 |
| 117 | #define SIERRA_DEQ_ALUT2 0x10A |
| 118 | #define SIERRA_DEQ_ALUT3 0x10B |
| 119 | #define SIERRA_DEQ_ALUT4 0x10C |
| 120 | #define SIERRA_DEQ_ALUT5 0x10D |
| 121 | #define SIERRA_DEQ_ALUT6 0x10E |
| 122 | #define SIERRA_DEQ_ALUT7 0x10F |
| 123 | #define SIERRA_DEQ_ALUT8 0x110 |
| 124 | #define SIERRA_DEQ_ALUT9 0x111 |
| 125 | #define SIERRA_DEQ_ALUT10 0x112 |
| 126 | #define SIERRA_DEQ_ALUT11 0x113 |
| 127 | #define SIERRA_DEQ_ALUT12 0x114 |
| 128 | #define SIERRA_DEQ_ALUT13 0x115 |
| 129 | #define SIERRA_DEQ_DFETAP_CTRL_PREG 0x128 |
| 130 | #define SIERRA_DFE_EN_1010_IGNORE_PREG 0x134 |
| 131 | #define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150 |
| 132 | #define SIERRA_DEQ_TAU_CTRL2_PREG 0x151 |
| 133 | #define SIERRA_DEQ_PICTRL_PREG 0x161 |
| 134 | #define SIERRA_CPICAL_TMRVAL_MODE1_PREG 0x170 |
| 135 | #define SIERRA_CPICAL_TMRVAL_MODE0_PREG 0x171 |
| 136 | #define SIERRA_CPICAL_PICNT_MODE1_PREG 0x174 |
| 137 | #define SIERRA_CPI_OUTBUF_RATESEL_PREG 0x17C |
| 138 | #define SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG 0x183 |
| 139 | #define SIERRA_LFPSDET_SUPPORT_PREG 0x188 |
| 140 | #define SIERRA_LFPSFILT_NS_PREG 0x18A |
| 141 | #define SIERRA_LFPSFILT_RD_PREG 0x18B |
| 142 | #define SIERRA_LFPSFILT_MP_PREG 0x18C |
| 143 | #define SIERRA_SIGDET_SUPPORT_PREG 0x190 |
| 144 | #define SIERRA_SDFILT_H2L_A_PREG 0x191 |
| 145 | #define SIERRA_SDFILT_L2H_PREG 0x193 |
| 146 | #define SIERRA_RXBUFFER_CTLECTRL_PREG 0x19E |
| 147 | #define SIERRA_RXBUFFER_RCDFECTRL_PREG 0x19F |
| 148 | #define SIERRA_RXBUFFER_DFECTRL_PREG 0x1A0 |
| 149 | #define SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG 0x14F |
| 150 | #define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150 |
| 151 | |
Swapnil Jakhade | 5b6b3dc | 2022-01-28 13:41:43 +0530 | [diff] [blame] | 152 | #define SIERRA_PHY_PCS_COMMON_OFFSET 0xc000 |
Swapnil Jakhade | aa20b30 | 2022-01-28 13:41:44 +0530 | [diff] [blame] | 153 | #define SIERRA_PHY_PIPE_CMN_CTRL1 0x0 |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 154 | #define SIERRA_PHY_PLL_CFG 0xe |
| 155 | |
Swapnil Jakhade | 13a6208 | 2022-01-28 13:41:45 +0530 | [diff] [blame^] | 156 | /* PHY PMA common registers */ |
| 157 | #define SIERRA_PHY_PMA_COMMON_OFFSET 0xe000 |
| 158 | #define SIERRA_PHY_PMA_CMN_CTRL 0x0 |
| 159 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 160 | #define SIERRA_MACRO_ID 0x00007364 |
| 161 | #define SIERRA_MAX_LANES 16 |
| 162 | #define PLL_LOCK_TIME 100 |
| 163 | |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 164 | #define CDNS_SIERRA_INPUT_CLOCKS 5 |
Kishon Vijay Abraham I | d604252 | 2022-01-28 13:41:33 +0530 | [diff] [blame] | 165 | enum cdns_sierra_clock_input { |
| 166 | PHY_CLK, |
| 167 | CMN_REFCLK_DIG_DIV, |
| 168 | CMN_REFCLK1_DIG_DIV, |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 169 | PLL0_REFCLK, |
| 170 | PLL1_REFCLK, |
Kishon Vijay Abraham I | d604252 | 2022-01-28 13:41:33 +0530 | [diff] [blame] | 171 | }; |
| 172 | |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 173 | #define SIERRA_NUM_CMN_PLLC 2 |
| 174 | #define SIERRA_NUM_CMN_PLLC_PARENTS 2 |
| 175 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 176 | static const struct reg_field macro_id_type = |
| 177 | REG_FIELD(SIERRA_MACRO_ID_REG, 0, 15); |
| 178 | static const struct reg_field phy_pll_cfg_1 = |
| 179 | REG_FIELD(SIERRA_PHY_PLL_CFG, 1, 1); |
Swapnil Jakhade | 13a6208 | 2022-01-28 13:41:45 +0530 | [diff] [blame^] | 180 | static const struct reg_field pma_cmn_ready = |
| 181 | REG_FIELD(SIERRA_PHY_PMA_CMN_CTRL, 0, 0); |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 182 | static const struct reg_field pllctrl_lock = |
| 183 | REG_FIELD(SIERRA_PLLCTRL_STATUS_PREG, 0, 0); |
| 184 | |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 185 | static const char * const clk_names[] = { |
| 186 | [CDNS_SIERRA_PLL_CMNLC] = "pll_cmnlc", |
| 187 | [CDNS_SIERRA_PLL_CMNLC1] = "pll_cmnlc1", |
| 188 | }; |
| 189 | |
| 190 | enum cdns_sierra_cmn_plllc { |
| 191 | CMN_PLLLC, |
| 192 | CMN_PLLLC1, |
| 193 | }; |
| 194 | |
| 195 | struct cdns_sierra_pll_mux_reg_fields { |
| 196 | struct reg_field pfdclk_sel_preg; |
| 197 | struct reg_field plllc1en_field; |
| 198 | struct reg_field termen_field; |
| 199 | }; |
| 200 | |
| 201 | static const struct cdns_sierra_pll_mux_reg_fields cmn_plllc_pfdclk1_sel_preg[] = { |
| 202 | [CMN_PLLLC] = { |
| 203 | .pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC_GEN_PREG, 1, 1), |
| 204 | .plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 8, 8), |
| 205 | .termen_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 0, 0), |
| 206 | }, |
| 207 | [CMN_PLLLC1] = { |
| 208 | .pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC1_GEN_PREG, 1, 1), |
| 209 | .plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 8, 8), |
| 210 | .termen_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 0, 0), |
| 211 | }, |
| 212 | }; |
| 213 | |
| 214 | struct cdns_sierra_pll_mux { |
| 215 | struct cdns_sierra_phy *sp; |
| 216 | struct clk *clk; |
| 217 | struct clk *parent_clks[2]; |
| 218 | struct regmap_field *pfdclk_sel_preg; |
| 219 | struct regmap_field *plllc1en_field; |
| 220 | struct regmap_field *termen_field; |
| 221 | }; |
| 222 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 223 | #define reset_control_assert(rst) cdns_reset_assert(rst) |
| 224 | #define reset_control_deassert(rst) cdns_reset_deassert(rst) |
| 225 | #define reset_control reset_ctl |
| 226 | |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 227 | enum cdns_sierra_phy_type { |
| 228 | TYPE_NONE, |
| 229 | TYPE_PCIE, |
| 230 | TYPE_USB |
| 231 | }; |
| 232 | |
| 233 | enum cdns_sierra_ssc_mode { |
| 234 | NO_SSC, |
| 235 | EXTERNAL_SSC, |
| 236 | INTERNAL_SSC |
| 237 | }; |
| 238 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 239 | struct cdns_sierra_inst { |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 240 | enum cdns_sierra_phy_type phy_type; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 241 | u32 num_lanes; |
| 242 | u32 mlane; |
| 243 | struct reset_ctl_bulk *lnk_rst; |
Swapnil Jakhade | 0d372ea | 2022-01-28 13:41:42 +0530 | [diff] [blame] | 244 | enum cdns_sierra_ssc_mode ssc_mode; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | struct cdns_reg_pairs { |
| 248 | u16 val; |
| 249 | u32 off; |
| 250 | }; |
| 251 | |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 252 | struct cdns_sierra_vals { |
| 253 | const struct cdns_reg_pairs *reg_pairs; |
| 254 | u32 num_regs; |
| 255 | }; |
| 256 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 257 | struct cdns_sierra_data { |
| 258 | u32 id_value; |
| 259 | u8 block_offset_shift; |
| 260 | u8 reg_offset_shift; |
Swapnil Jakhade | aa20b30 | 2022-01-28 13:41:44 +0530 | [diff] [blame] | 261 | struct cdns_sierra_vals *pcs_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE] |
| 262 | [NUM_SSC_MODE]; |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 263 | struct cdns_sierra_vals *pma_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE] |
| 264 | [NUM_SSC_MODE]; |
| 265 | struct cdns_sierra_vals *pma_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE] |
| 266 | [NUM_SSC_MODE]; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 267 | }; |
| 268 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 269 | struct cdns_sierra_phy { |
| 270 | struct udevice *dev; |
| 271 | void *base; |
| 272 | size_t size; |
| 273 | struct regmap *regmap; |
| 274 | struct cdns_sierra_data *init_data; |
Aswath Govindraju | 11fcd0e | 2022-01-28 13:41:35 +0530 | [diff] [blame] | 275 | struct cdns_sierra_inst *phys[SIERRA_MAX_LANES]; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 276 | struct reset_control *phy_rst; |
| 277 | struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES]; |
Swapnil Jakhade | 5b6b3dc | 2022-01-28 13:41:43 +0530 | [diff] [blame] | 278 | struct regmap *regmap_phy_pcs_common_cdb; |
Swapnil Jakhade | 13a6208 | 2022-01-28 13:41:45 +0530 | [diff] [blame^] | 279 | struct regmap *regmap_phy_pma_common_cdb; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 280 | struct regmap *regmap_common_cdb; |
| 281 | struct regmap_field *macro_id_type; |
| 282 | struct regmap_field *phy_pll_cfg_1; |
Swapnil Jakhade | 13a6208 | 2022-01-28 13:41:45 +0530 | [diff] [blame^] | 283 | struct regmap_field *pma_cmn_ready; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 284 | struct regmap_field *pllctrl_lock[SIERRA_MAX_LANES]; |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 285 | struct regmap_field *cmn_refrcv_refclk_plllc1en_preg[SIERRA_NUM_CMN_PLLC]; |
| 286 | struct regmap_field *cmn_refrcv_refclk_termen_preg[SIERRA_NUM_CMN_PLLC]; |
| 287 | struct regmap_field *cmn_plllc_pfdclk1_sel_preg[SIERRA_NUM_CMN_PLLC]; |
Kishon Vijay Abraham I | d604252 | 2022-01-28 13:41:33 +0530 | [diff] [blame] | 288 | struct clk *input_clks[CDNS_SIERRA_INPUT_CLOCKS]; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 289 | int nsubnodes; |
| 290 | u32 num_lanes; |
| 291 | bool autoconf; |
| 292 | }; |
| 293 | |
| 294 | static inline int cdns_reset_assert(struct reset_control *rst) |
| 295 | { |
| 296 | if (rst) |
| 297 | return reset_assert(rst); |
| 298 | else |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static inline int cdns_reset_deassert(struct reset_control *rst) |
| 303 | { |
| 304 | if (rst) |
| 305 | return reset_deassert(rst); |
| 306 | else |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static inline struct cdns_sierra_inst *phy_get_drvdata(struct phy *phy) |
| 311 | { |
| 312 | struct cdns_sierra_phy *sp = dev_get_priv(phy->dev); |
| 313 | int index; |
| 314 | |
| 315 | if (phy->id >= SIERRA_MAX_LANES) |
| 316 | return NULL; |
| 317 | |
| 318 | for (index = 0; index < sp->nsubnodes; index++) { |
Aswath Govindraju | 11fcd0e | 2022-01-28 13:41:35 +0530 | [diff] [blame] | 319 | if (phy->id == sp->phys[index]->mlane) |
| 320 | return sp->phys[index]; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | static int cdns_sierra_phy_init(struct phy *gphy) |
| 327 | { |
| 328 | struct cdns_sierra_inst *ins = phy_get_drvdata(gphy); |
| 329 | struct cdns_sierra_phy *phy = dev_get_priv(gphy->dev); |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 330 | struct cdns_sierra_data *init_data = phy->init_data; |
| 331 | struct cdns_sierra_vals *pma_cmn_vals, *pma_ln_vals; |
| 332 | enum cdns_sierra_phy_type phy_type = ins->phy_type; |
Swapnil Jakhade | 0d372ea | 2022-01-28 13:41:42 +0530 | [diff] [blame] | 333 | enum cdns_sierra_ssc_mode ssc = ins->ssc_mode; |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 334 | const struct cdns_reg_pairs *reg_pairs; |
Swapnil Jakhade | aa20b30 | 2022-01-28 13:41:44 +0530 | [diff] [blame] | 335 | struct cdns_sierra_vals *pcs_cmn_vals; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 336 | struct regmap *regmap = phy->regmap; |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 337 | u32 num_regs; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 338 | int i, j; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 339 | |
| 340 | /* Initialise the PHY registers, unless auto configured */ |
| 341 | if (phy->autoconf) |
| 342 | return 0; |
| 343 | |
Kishon Vijay Abraham I | d604252 | 2022-01-28 13:41:33 +0530 | [diff] [blame] | 344 | clk_set_rate(phy->input_clks[CMN_REFCLK_DIG_DIV], 25000000); |
| 345 | clk_set_rate(phy->input_clks[CMN_REFCLK1_DIG_DIV], 25000000); |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 346 | |
Swapnil Jakhade | aa20b30 | 2022-01-28 13:41:44 +0530 | [diff] [blame] | 347 | /* PHY PCS common registers configurations */ |
| 348 | pcs_cmn_vals = init_data->pcs_cmn_vals[phy_type][TYPE_NONE][ssc]; |
| 349 | if (pcs_cmn_vals) { |
| 350 | reg_pairs = pcs_cmn_vals->reg_pairs; |
| 351 | num_regs = pcs_cmn_vals->num_regs; |
| 352 | regmap = phy->regmap_phy_pcs_common_cdb; |
| 353 | for (i = 0; i < num_regs; i++) |
| 354 | regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val); |
| 355 | } |
| 356 | |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 357 | /* PMA common registers configurations */ |
| 358 | pma_cmn_vals = init_data->pma_cmn_vals[phy_type][TYPE_NONE][ssc]; |
| 359 | if (pma_cmn_vals) { |
| 360 | reg_pairs = pma_cmn_vals->reg_pairs; |
| 361 | num_regs = pma_cmn_vals->num_regs; |
| 362 | regmap = phy->regmap_common_cdb; |
| 363 | for (i = 0; i < num_regs; i++) |
| 364 | regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val); |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 365 | } |
| 366 | |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 367 | /* PMA TX lane registers configurations */ |
| 368 | pma_ln_vals = init_data->pma_ln_vals[phy_type][TYPE_NONE][ssc]; |
| 369 | if (pma_ln_vals) { |
| 370 | reg_pairs = pma_ln_vals->reg_pairs; |
| 371 | num_regs = pma_ln_vals->num_regs; |
| 372 | for (i = 0; i < ins->num_lanes; i++) { |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 373 | regmap = phy->regmap_lane_cdb[i + ins->mlane]; |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 374 | for (j = 0; j < num_regs; j++) |
| 375 | regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val); |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | static int cdns_sierra_phy_on(struct phy *gphy) |
| 383 | { |
| 384 | struct cdns_sierra_inst *ins = phy_get_drvdata(gphy); |
| 385 | struct cdns_sierra_phy *sp = dev_get_priv(gphy->dev); |
| 386 | struct udevice *dev = gphy->dev; |
| 387 | u32 val; |
| 388 | int ret; |
| 389 | |
Kishon Vijay Abraham I | 1ff2b71 | 2022-01-28 13:41:29 +0530 | [diff] [blame] | 390 | ret = reset_control_deassert(sp->phy_rst); |
| 391 | if (ret) { |
| 392 | dev_err(dev, "Failed to take the PHY out of reset\n"); |
| 393 | return ret; |
| 394 | } |
| 395 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 396 | /* Take the PHY lane group out of reset */ |
| 397 | ret = reset_deassert_bulk(ins->lnk_rst); |
| 398 | if (ret) { |
| 399 | dev_err(dev, "Failed to take the PHY lane out of reset\n"); |
| 400 | return ret; |
| 401 | } |
| 402 | |
Swapnil Jakhade | 13a6208 | 2022-01-28 13:41:45 +0530 | [diff] [blame^] | 403 | /* |
| 404 | * Wait for cmn_ready assertion |
| 405 | * PHY_PMA_CMN_CTRL[0] == 1 |
| 406 | */ |
| 407 | ret = regmap_field_read_poll_timeout(sp->pma_cmn_ready, val, val, |
| 408 | 1000, PLL_LOCK_TIME); |
| 409 | if (ret) { |
| 410 | dev_err(dev, "Timeout waiting for CMN ready\n"); |
| 411 | return ret; |
| 412 | } |
| 413 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 414 | ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane], |
| 415 | val, val, 1000, PLL_LOCK_TIME); |
| 416 | if (ret < 0) |
| 417 | dev_err(dev, "PLL lock of lane failed\n"); |
| 418 | |
| 419 | reset_control_assert(sp->phy_rst); |
| 420 | reset_control_deassert(sp->phy_rst); |
| 421 | |
| 422 | return ret; |
| 423 | } |
| 424 | |
| 425 | static int cdns_sierra_phy_off(struct phy *gphy) |
| 426 | { |
| 427 | struct cdns_sierra_inst *ins = phy_get_drvdata(gphy); |
| 428 | |
| 429 | return reset_assert_bulk(ins->lnk_rst); |
| 430 | } |
| 431 | |
| 432 | static int cdns_sierra_phy_reset(struct phy *gphy) |
| 433 | { |
| 434 | struct cdns_sierra_phy *sp = dev_get_priv(gphy->dev); |
| 435 | |
| 436 | reset_control_assert(sp->phy_rst); |
| 437 | reset_control_deassert(sp->phy_rst); |
| 438 | return 0; |
| 439 | }; |
| 440 | |
| 441 | static const struct phy_ops ops = { |
| 442 | .init = cdns_sierra_phy_init, |
| 443 | .power_on = cdns_sierra_phy_on, |
| 444 | .power_off = cdns_sierra_phy_off, |
| 445 | .reset = cdns_sierra_phy_reset, |
| 446 | }; |
| 447 | |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 448 | struct cdns_sierra_pll_mux_sel { |
| 449 | enum cdns_sierra_cmn_plllc mux_sel; |
| 450 | u32 table[2]; |
| 451 | const char *node_name; |
| 452 | u32 num_parents; |
| 453 | u32 parents[2]; |
| 454 | }; |
| 455 | |
| 456 | static struct cdns_sierra_pll_mux_sel pll_clk_mux_sel[] = { |
| 457 | { |
| 458 | .num_parents = 2, |
| 459 | .parents = { PLL0_REFCLK, PLL1_REFCLK }, |
| 460 | .mux_sel = CMN_PLLLC, |
| 461 | .table = { 0, 1 }, |
| 462 | .node_name = "pll_cmnlc", |
| 463 | }, |
| 464 | { |
| 465 | .num_parents = 2, |
| 466 | .parents = { PLL1_REFCLK, PLL0_REFCLK }, |
| 467 | .mux_sel = CMN_PLLLC1, |
| 468 | .table = { 1, 0 }, |
| 469 | .node_name = "pll_cmnlc1", |
| 470 | }, |
| 471 | }; |
| 472 | |
| 473 | static int cdns_sierra_pll_mux_set_parent(struct clk *clk, struct clk *parent) |
| 474 | { |
| 475 | struct udevice *dev = clk->dev; |
| 476 | struct cdns_sierra_pll_mux *priv = dev_get_priv(dev); |
| 477 | struct cdns_sierra_pll_mux_sel *data = dev_get_plat(dev); |
| 478 | struct cdns_sierra_phy *sp = priv->sp; |
| 479 | int ret; |
| 480 | int i; |
| 481 | |
| 482 | for (i = 0; i < ARRAY_SIZE(priv->parent_clks); i++) { |
| 483 | if (parent->dev == priv->parent_clks[i]->dev) |
| 484 | break; |
| 485 | } |
| 486 | |
| 487 | if (i == ARRAY_SIZE(priv->parent_clks)) |
| 488 | return -EINVAL; |
| 489 | |
| 490 | ret = regmap_field_write(sp->cmn_refrcv_refclk_plllc1en_preg[data[clk->id].mux_sel], i); |
| 491 | ret |= regmap_field_write(sp->cmn_refrcv_refclk_termen_preg[data[clk->id].mux_sel], i); |
| 492 | ret |= regmap_field_write(sp->cmn_plllc_pfdclk1_sel_preg[data[clk->id].mux_sel], |
| 493 | data[clk->id].table[i]); |
| 494 | |
| 495 | return ret; |
| 496 | } |
| 497 | |
| 498 | static const struct clk_ops cdns_sierra_pll_mux_ops = { |
| 499 | .set_parent = cdns_sierra_pll_mux_set_parent, |
| 500 | }; |
| 501 | |
| 502 | int cdns_sierra_pll_mux_probe(struct udevice *dev) |
| 503 | { |
| 504 | struct cdns_sierra_pll_mux *priv = dev_get_priv(dev); |
| 505 | struct cdns_sierra_phy *sp = dev_get_priv(dev->parent); |
| 506 | struct cdns_sierra_pll_mux_sel *data = dev_get_plat(dev); |
| 507 | struct clk *clk; |
| 508 | int i, j; |
| 509 | |
| 510 | for (j = 0; j < SIERRA_NUM_CMN_PLLC; j++) { |
| 511 | for (i = 0; i < ARRAY_SIZE(priv->parent_clks); i++) { |
| 512 | clk = sp->input_clks[data[j].parents[i]]; |
| 513 | if (IS_ERR_OR_NULL(clk)) { |
| 514 | dev_err(dev, "No parent clock for PLL mux clocks\n"); |
| 515 | return IS_ERR(clk) ? PTR_ERR(clk) : -ENOENT; |
| 516 | } |
| 517 | priv->parent_clks[i] = clk; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | priv->sp = dev_get_priv(dev->parent); |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | U_BOOT_DRIVER(cdns_sierra_pll_mux_clk) = { |
| 527 | .name = "cdns_sierra_mux_clk", |
| 528 | .id = UCLASS_CLK, |
| 529 | .priv_auto = sizeof(struct cdns_sierra_pll_mux), |
| 530 | .ops = &cdns_sierra_pll_mux_ops, |
| 531 | .probe = cdns_sierra_pll_mux_probe, |
| 532 | .plat_auto = sizeof(struct cdns_sierra_pll_mux_sel) * SIERRA_NUM_CMN_PLLC, |
| 533 | }; |
| 534 | |
| 535 | static int cdns_sierra_pll_bind_of_clocks(struct cdns_sierra_phy *sp) |
| 536 | { |
| 537 | struct udevice *dev = sp->dev; |
| 538 | struct driver *cdns_sierra_clk_drv; |
| 539 | struct cdns_sierra_pll_mux_sel *data = pll_clk_mux_sel; |
| 540 | int i, rc; |
| 541 | |
| 542 | cdns_sierra_clk_drv = lists_driver_lookup_name("cdns_sierra_mux_clk"); |
| 543 | if (!cdns_sierra_clk_drv) { |
| 544 | dev_err(dev, "Can not find driver 'cdns_sierra_mux_clk'\n"); |
| 545 | return -ENOENT; |
| 546 | } |
| 547 | |
| 548 | rc = device_bind(dev, cdns_sierra_clk_drv, "pll_mux_clk", |
| 549 | data, dev_ofnode(dev), NULL); |
| 550 | if (rc) { |
| 551 | dev_err(dev, "cannot bind driver for clock %s\n", |
| 552 | clk_names[i]); |
| 553 | } |
| 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 558 | static int cdns_sierra_get_optional(struct cdns_sierra_inst *inst, |
| 559 | ofnode child) |
| 560 | { |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 561 | u32 phy_type; |
| 562 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 563 | if (ofnode_read_u32(child, "reg", &inst->mlane)) |
| 564 | return -EINVAL; |
| 565 | |
| 566 | if (ofnode_read_u32(child, "cdns,num-lanes", &inst->num_lanes)) |
| 567 | return -EINVAL; |
| 568 | |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 569 | if (ofnode_read_u32(child, "cdns,phy-type", &phy_type)) |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 570 | return -EINVAL; |
| 571 | |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 572 | switch (phy_type) { |
| 573 | case PHY_TYPE_PCIE: |
| 574 | inst->phy_type = TYPE_PCIE; |
| 575 | break; |
| 576 | case PHY_TYPE_USB3: |
| 577 | inst->phy_type = TYPE_USB; |
| 578 | break; |
| 579 | default: |
| 580 | return -EINVAL; |
| 581 | } |
| 582 | |
Swapnil Jakhade | 0d372ea | 2022-01-28 13:41:42 +0530 | [diff] [blame] | 583 | inst->ssc_mode = EXTERNAL_SSC; |
| 584 | ofnode_read_u32(child, "cdns,ssc-mode", &inst->ssc_mode); |
| 585 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | static struct regmap *cdns_regmap_init(struct udevice *dev, void __iomem *base, |
| 590 | u32 block_offset, u8 block_offset_shift, |
| 591 | u8 reg_offset_shift) |
| 592 | { |
| 593 | struct cdns_sierra_phy *sp = dev_get_priv(dev); |
| 594 | struct regmap_config config; |
| 595 | |
| 596 | config.r_start = (ulong)(base + (block_offset << block_offset_shift)); |
| 597 | config.r_size = sp->size - (block_offset << block_offset_shift); |
| 598 | config.reg_offset_shift = reg_offset_shift; |
| 599 | config.width = REGMAP_SIZE_16; |
| 600 | |
| 601 | return devm_regmap_init(dev, NULL, NULL, &config); |
| 602 | } |
| 603 | |
| 604 | static int cdns_regfield_init(struct cdns_sierra_phy *sp) |
| 605 | { |
| 606 | struct udevice *dev = sp->dev; |
| 607 | struct regmap_field *field; |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 608 | struct reg_field reg_field; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 609 | struct regmap *regmap; |
| 610 | int i; |
| 611 | |
| 612 | regmap = sp->regmap_common_cdb; |
| 613 | field = devm_regmap_field_alloc(dev, regmap, macro_id_type); |
| 614 | if (IS_ERR(field)) { |
| 615 | dev_err(dev, "MACRO_ID_TYPE reg field init failed\n"); |
| 616 | return PTR_ERR(field); |
| 617 | } |
| 618 | sp->macro_id_type = field; |
| 619 | |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 620 | for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++) { |
| 621 | reg_field = cmn_plllc_pfdclk1_sel_preg[i].pfdclk_sel_preg; |
| 622 | field = devm_regmap_field_alloc(dev, regmap, reg_field); |
| 623 | if (IS_ERR(field)) { |
| 624 | dev_err(dev, "PLLLC%d_PFDCLK1_SEL failed\n", i); |
| 625 | return PTR_ERR(field); |
| 626 | } |
| 627 | sp->cmn_plllc_pfdclk1_sel_preg[i] = field; |
| 628 | |
| 629 | reg_field = cmn_plllc_pfdclk1_sel_preg[i].plllc1en_field; |
| 630 | field = devm_regmap_field_alloc(dev, regmap, reg_field); |
| 631 | if (IS_ERR(field)) { |
| 632 | dev_err(dev, "REFRCV%d_REFCLK_PLLLC1EN failed\n", i); |
| 633 | return PTR_ERR(field); |
| 634 | } |
| 635 | sp->cmn_refrcv_refclk_plllc1en_preg[i] = field; |
| 636 | |
| 637 | reg_field = cmn_plllc_pfdclk1_sel_preg[i].termen_field; |
| 638 | field = devm_regmap_field_alloc(dev, regmap, reg_field); |
| 639 | if (IS_ERR(field)) { |
| 640 | dev_err(dev, "REFRCV%d_REFCLK_TERMEN failed\n", i); |
| 641 | return PTR_ERR(field); |
| 642 | } |
| 643 | sp->cmn_refrcv_refclk_termen_preg[i] = field; |
| 644 | } |
| 645 | |
Swapnil Jakhade | 5b6b3dc | 2022-01-28 13:41:43 +0530 | [diff] [blame] | 646 | regmap = sp->regmap_phy_pcs_common_cdb; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 647 | field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1); |
| 648 | if (IS_ERR(field)) { |
| 649 | dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n"); |
| 650 | return PTR_ERR(field); |
| 651 | } |
| 652 | sp->phy_pll_cfg_1 = field; |
| 653 | |
Swapnil Jakhade | 13a6208 | 2022-01-28 13:41:45 +0530 | [diff] [blame^] | 654 | regmap = sp->regmap_phy_pma_common_cdb; |
| 655 | field = devm_regmap_field_alloc(dev, regmap, pma_cmn_ready); |
| 656 | if (IS_ERR(field)) { |
| 657 | dev_err(dev, "PHY_PMA_CMN_CTRL reg field init failed\n"); |
| 658 | return PTR_ERR(field); |
| 659 | } |
| 660 | sp->pma_cmn_ready = field; |
| 661 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 662 | for (i = 0; i < SIERRA_MAX_LANES; i++) { |
| 663 | regmap = sp->regmap_lane_cdb[i]; |
| 664 | field = devm_regmap_field_alloc(dev, regmap, pllctrl_lock); |
| 665 | if (IS_ERR(field)) { |
| 666 | dev_err(dev, "P%d_ENABLE reg field init failed\n", i); |
| 667 | return PTR_ERR(field); |
| 668 | } |
| 669 | sp->pllctrl_lock[i] = field; |
| 670 | } |
| 671 | |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | static int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp, |
| 676 | void __iomem *base, u8 block_offset_shift, |
| 677 | u8 reg_offset_shift) |
| 678 | { |
| 679 | struct udevice *dev = sp->dev; |
| 680 | struct regmap *regmap; |
| 681 | u32 block_offset; |
| 682 | int i; |
| 683 | |
| 684 | for (i = 0; i < SIERRA_MAX_LANES; i++) { |
| 685 | block_offset = SIERRA_LANE_CDB_OFFSET(i, reg_offset_shift); |
| 686 | regmap = cdns_regmap_init(dev, base, block_offset, |
| 687 | block_offset_shift, reg_offset_shift); |
| 688 | if (IS_ERR(regmap)) { |
| 689 | dev_err(dev, "Failed to init lane CDB regmap\n"); |
| 690 | return PTR_ERR(regmap); |
| 691 | } |
| 692 | sp->regmap_lane_cdb[i] = regmap; |
| 693 | } |
| 694 | |
| 695 | regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET, |
| 696 | block_offset_shift, reg_offset_shift); |
| 697 | if (IS_ERR(regmap)) { |
| 698 | dev_err(dev, "Failed to init common CDB regmap\n"); |
| 699 | return PTR_ERR(regmap); |
| 700 | } |
| 701 | sp->regmap_common_cdb = regmap; |
| 702 | |
Swapnil Jakhade | 5b6b3dc | 2022-01-28 13:41:43 +0530 | [diff] [blame] | 703 | regmap = cdns_regmap_init(dev, base, SIERRA_PHY_PCS_COMMON_OFFSET, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 704 | block_offset_shift, reg_offset_shift); |
| 705 | if (IS_ERR(regmap)) { |
Swapnil Jakhade | 5b6b3dc | 2022-01-28 13:41:43 +0530 | [diff] [blame] | 706 | dev_err(dev, "Failed to init PHY PCS common CDB regmap\n"); |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 707 | return PTR_ERR(regmap); |
| 708 | } |
Swapnil Jakhade | 5b6b3dc | 2022-01-28 13:41:43 +0530 | [diff] [blame] | 709 | sp->regmap_phy_pcs_common_cdb = regmap; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 710 | |
Swapnil Jakhade | 13a6208 | 2022-01-28 13:41:45 +0530 | [diff] [blame^] | 711 | regmap = cdns_regmap_init(dev, base, SIERRA_PHY_PMA_COMMON_OFFSET, |
| 712 | block_offset_shift, reg_offset_shift); |
| 713 | if (IS_ERR(regmap)) { |
| 714 | dev_err(dev, "Failed to init PHY PMA common CDB regmap\n"); |
| 715 | return PTR_ERR(regmap); |
| 716 | } |
| 717 | sp->regmap_phy_pma_common_cdb = regmap; |
| 718 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 719 | return 0; |
| 720 | } |
| 721 | |
Kishon Vijay Abraham I | 47d0bcb | 2022-01-28 13:41:31 +0530 | [diff] [blame] | 722 | static int cdns_sierra_phy_get_clocks(struct cdns_sierra_phy *sp, |
| 723 | struct udevice *dev) |
| 724 | { |
| 725 | struct clk *clk; |
| 726 | int ret; |
| 727 | |
| 728 | clk = devm_clk_get_optional(dev, "phy_clk"); |
| 729 | if (IS_ERR(clk)) { |
| 730 | dev_err(dev, "failed to get clock phy_clk\n"); |
| 731 | return PTR_ERR(clk); |
| 732 | } |
Kishon Vijay Abraham I | d604252 | 2022-01-28 13:41:33 +0530 | [diff] [blame] | 733 | sp->input_clks[PHY_CLK] = clk; |
Kishon Vijay Abraham I | 47d0bcb | 2022-01-28 13:41:31 +0530 | [diff] [blame] | 734 | |
| 735 | clk = devm_clk_get_optional(dev, "cmn_refclk_dig_div"); |
| 736 | if (IS_ERR(clk)) { |
| 737 | dev_err(dev, "cmn_refclk_dig_div clock not found\n"); |
| 738 | ret = PTR_ERR(clk); |
| 739 | return ret; |
| 740 | } |
Kishon Vijay Abraham I | d604252 | 2022-01-28 13:41:33 +0530 | [diff] [blame] | 741 | sp->input_clks[CMN_REFCLK_DIG_DIV] = clk; |
Kishon Vijay Abraham I | 47d0bcb | 2022-01-28 13:41:31 +0530 | [diff] [blame] | 742 | |
| 743 | clk = devm_clk_get_optional(dev, "cmn_refclk1_dig_div"); |
| 744 | if (IS_ERR(clk)) { |
| 745 | dev_err(dev, "cmn_refclk1_dig_div clock not found\n"); |
| 746 | ret = PTR_ERR(clk); |
| 747 | return ret; |
| 748 | } |
Kishon Vijay Abraham I | d604252 | 2022-01-28 13:41:33 +0530 | [diff] [blame] | 749 | sp->input_clks[CMN_REFCLK1_DIG_DIV] = clk; |
Kishon Vijay Abraham I | 47d0bcb | 2022-01-28 13:41:31 +0530 | [diff] [blame] | 750 | |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 751 | clk = devm_clk_get_optional(dev, "pll0_refclk"); |
| 752 | if (IS_ERR(clk)) { |
| 753 | dev_err(dev, "pll0_refclk clock not found\n"); |
| 754 | ret = PTR_ERR(clk); |
| 755 | return ret; |
| 756 | } |
| 757 | sp->input_clks[PLL0_REFCLK] = clk; |
| 758 | |
| 759 | clk = devm_clk_get_optional(dev, "pll1_refclk"); |
| 760 | if (IS_ERR(clk)) { |
| 761 | dev_err(dev, "pll1_refclk clock not found\n"); |
| 762 | ret = PTR_ERR(clk); |
| 763 | return ret; |
| 764 | } |
| 765 | sp->input_clks[PLL1_REFCLK] = clk; |
| 766 | |
Kishon Vijay Abraham I | 47d0bcb | 2022-01-28 13:41:31 +0530 | [diff] [blame] | 767 | return 0; |
| 768 | } |
| 769 | |
Kishon Vijay Abraham I | 12fbc5c | 2022-01-28 13:41:32 +0530 | [diff] [blame] | 770 | static int cdns_sierra_phy_get_resets(struct cdns_sierra_phy *sp, |
| 771 | struct udevice *dev) |
| 772 | { |
| 773 | struct reset_control *rst; |
| 774 | |
| 775 | rst = devm_reset_control_get(dev, "sierra_reset"); |
| 776 | if (IS_ERR(rst)) { |
| 777 | dev_err(dev, "failed to get reset\n"); |
| 778 | return PTR_ERR(rst); |
| 779 | } |
| 780 | sp->phy_rst = rst; |
| 781 | |
| 782 | return 0; |
| 783 | } |
| 784 | |
Aswath Govindraju | 11fcd0e | 2022-01-28 13:41:35 +0530 | [diff] [blame] | 785 | static int cdns_sierra_bind_link_nodes(struct cdns_sierra_phy *sp) |
| 786 | { |
| 787 | struct udevice *dev = sp->dev; |
| 788 | struct driver *link_drv; |
| 789 | ofnode child; |
| 790 | int rc; |
| 791 | |
| 792 | link_drv = lists_driver_lookup_name("sierra_phy_link"); |
| 793 | if (!link_drv) { |
| 794 | dev_err(dev, "Cannot find driver 'sierra_phy_link'\n"); |
| 795 | return -ENOENT; |
| 796 | } |
| 797 | |
| 798 | ofnode_for_each_subnode(child, dev_ofnode(dev)) { |
| 799 | if (!(ofnode_name_eq(child, "phy") || |
| 800 | ofnode_name_eq(child, "link"))) |
| 801 | continue; |
| 802 | |
| 803 | rc = device_bind(dev, link_drv, "link", NULL, child, NULL); |
| 804 | if (rc) { |
| 805 | dev_err(dev, "cannot bind driver for link\n"); |
| 806 | return rc; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | static int cdns_sierra_link_probe(struct udevice *dev) |
| 814 | { |
| 815 | struct cdns_sierra_inst *inst = dev_get_priv(dev); |
| 816 | struct cdns_sierra_phy *sp = dev_get_priv(dev->parent); |
| 817 | struct reset_ctl_bulk *rst; |
| 818 | int ret, node; |
| 819 | |
| 820 | rst = devm_reset_bulk_get_by_node(dev, dev_ofnode(dev)); |
| 821 | if (IS_ERR(rst)) { |
| 822 | ret = PTR_ERR(rst); |
| 823 | dev_err(dev, "failed to get reset\n"); |
| 824 | return ret; |
| 825 | } |
| 826 | inst->lnk_rst = rst; |
| 827 | |
| 828 | ret = cdns_sierra_get_optional(inst, dev_ofnode(dev)); |
| 829 | if (ret) { |
| 830 | dev_err(dev, "missing property in node\n"); |
| 831 | return ret; |
| 832 | } |
| 833 | node = sp->nsubnodes; |
| 834 | sp->phys[node] = inst; |
| 835 | sp->nsubnodes += 1; |
| 836 | sp->num_lanes += inst->num_lanes; |
| 837 | |
| 838 | /* If more than one subnode, configure the PHY as multilink */ |
| 839 | if (!sp->autoconf && sp->nsubnodes > 1) |
| 840 | regmap_field_write(sp->phy_pll_cfg_1, 0x1); |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | U_BOOT_DRIVER(sierra_phy_link) = { |
| 846 | .name = "sierra_phy_link", |
| 847 | .id = UCLASS_PHY, |
| 848 | .probe = cdns_sierra_link_probe, |
| 849 | .priv_auto = sizeof(struct cdns_sierra_inst), |
| 850 | }; |
| 851 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 852 | static int cdns_sierra_phy_probe(struct udevice *dev) |
| 853 | { |
| 854 | struct cdns_sierra_phy *sp = dev_get_priv(dev); |
| 855 | struct cdns_sierra_data *data; |
| 856 | unsigned int id_value; |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 857 | int ret; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 858 | |
| 859 | sp->dev = dev; |
| 860 | |
| 861 | sp->base = devfdt_remap_addr_index(dev, 0); |
| 862 | if (!sp->base) { |
| 863 | dev_err(dev, "unable to map regs\n"); |
| 864 | return -ENOMEM; |
| 865 | } |
| 866 | devfdt_get_addr_size_index(dev, 0, (fdt_size_t *)&sp->size); |
| 867 | |
| 868 | /* Get init data for this PHY */ |
| 869 | data = (struct cdns_sierra_data *)dev_get_driver_data(dev); |
| 870 | sp->init_data = data; |
| 871 | |
| 872 | ret = cdns_regmap_init_blocks(sp, sp->base, data->block_offset_shift, |
| 873 | data->reg_offset_shift); |
| 874 | if (ret) |
| 875 | return ret; |
| 876 | |
| 877 | ret = cdns_regfield_init(sp); |
| 878 | if (ret) |
| 879 | return ret; |
| 880 | |
Kishon Vijay Abraham I | 47d0bcb | 2022-01-28 13:41:31 +0530 | [diff] [blame] | 881 | ret = cdns_sierra_phy_get_clocks(sp, dev); |
| 882 | if (ret) |
| 883 | return ret; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 884 | |
Aswath Govindraju | 304341f | 2022-01-28 13:41:36 +0530 | [diff] [blame] | 885 | ret = cdns_sierra_pll_bind_of_clocks(sp); |
| 886 | if (ret) |
| 887 | return ret; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 888 | |
Kishon Vijay Abraham I | 12fbc5c | 2022-01-28 13:41:32 +0530 | [diff] [blame] | 889 | ret = cdns_sierra_phy_get_resets(sp, dev); |
| 890 | if (ret) |
| 891 | return ret; |
| 892 | |
Kishon Vijay Abraham I | d604252 | 2022-01-28 13:41:33 +0530 | [diff] [blame] | 893 | ret = clk_prepare_enable(sp->input_clks[PHY_CLK]); |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 894 | if (ret) |
| 895 | return ret; |
| 896 | |
| 897 | /* Check that PHY is present */ |
| 898 | regmap_field_read(sp->macro_id_type, &id_value); |
| 899 | if (sp->init_data->id_value != id_value) { |
| 900 | dev_err(dev, "PHY not found 0x%x vs 0x%x\n", |
| 901 | sp->init_data->id_value, id_value); |
| 902 | ret = -EINVAL; |
| 903 | goto clk_disable; |
| 904 | } |
| 905 | |
| 906 | sp->autoconf = dev_read_bool(dev, "cdns,autoconf"); |
Aswath Govindraju | 11fcd0e | 2022-01-28 13:41:35 +0530 | [diff] [blame] | 907 | /* Binding link nodes as children to serdes */ |
| 908 | ret = cdns_sierra_bind_link_nodes(sp); |
| 909 | if (ret) |
| 910 | goto clk_disable; |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 911 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 912 | dev_info(dev, "sierra probed\n"); |
| 913 | return 0; |
| 914 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 915 | clk_disable: |
Kishon Vijay Abraham I | d604252 | 2022-01-28 13:41:33 +0530 | [diff] [blame] | 916 | clk_disable_unprepare(sp->input_clks[PHY_CLK]); |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 917 | return ret; |
| 918 | } |
| 919 | |
| 920 | static int cdns_sierra_phy_remove(struct udevice *dev) |
| 921 | { |
| 922 | struct cdns_sierra_phy *phy = dev_get_priv(dev); |
| 923 | int i; |
| 924 | |
| 925 | reset_control_assert(phy->phy_rst); |
| 926 | |
| 927 | /* |
| 928 | * The device level resets will be put automatically. |
| 929 | * Need to put the subnode resets here though. |
| 930 | */ |
| 931 | for (i = 0; i < phy->nsubnodes; i++) |
Aswath Govindraju | 11fcd0e | 2022-01-28 13:41:35 +0530 | [diff] [blame] | 932 | reset_assert_bulk(phy->phys[i]->lnk_rst); |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 933 | |
Kishon Vijay Abraham I | 25f8b37 | 2022-01-28 13:41:34 +0530 | [diff] [blame] | 934 | clk_disable_unprepare(phy->input_clks[PHY_CLK]); |
| 935 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 936 | return 0; |
| 937 | } |
| 938 | |
Swapnil Jakhade | aa20b30 | 2022-01-28 13:41:44 +0530 | [diff] [blame] | 939 | /* PCIE PHY PCS common configuration */ |
| 940 | static struct cdns_reg_pairs pcie_phy_pcs_cmn_regs[] = { |
| 941 | {0x0430, SIERRA_PHY_PIPE_CMN_CTRL1} |
| 942 | }; |
| 943 | |
| 944 | static struct cdns_sierra_vals pcie_phy_pcs_cmn_vals = { |
| 945 | .reg_pairs = pcie_phy_pcs_cmn_regs, |
| 946 | .num_regs = ARRAY_SIZE(pcie_phy_pcs_cmn_regs), |
| 947 | }; |
| 948 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 949 | /* refclk100MHz_32b_PCIe_cmn_pll_ext_ssc */ |
| 950 | static struct cdns_reg_pairs cdns_pcie_cmn_regs_ext_ssc[] = { |
| 951 | {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG}, |
| 952 | {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG}, |
| 953 | {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG}, |
| 954 | {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG}, |
| 955 | {0x1B1B, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG} |
| 956 | }; |
| 957 | |
| 958 | /* refclk100MHz_32b_PCIe_ln_ext_ssc */ |
| 959 | static struct cdns_reg_pairs cdns_pcie_ln_regs_ext_ssc[] = { |
| 960 | {0x813E, SIERRA_CLKPATHCTRL_TMR_PREG}, |
| 961 | {0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG}, |
| 962 | {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG}, |
| 963 | {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG}, |
| 964 | {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG}, |
| 965 | {0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG}, |
| 966 | {0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG} |
| 967 | }; |
| 968 | |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 969 | static struct cdns_sierra_vals pcie_100_ext_ssc_cmn_vals = { |
| 970 | .reg_pairs = cdns_pcie_cmn_regs_ext_ssc, |
| 971 | .num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc), |
| 972 | }; |
| 973 | |
| 974 | static struct cdns_sierra_vals pcie_100_ext_ssc_ln_vals = { |
| 975 | .reg_pairs = cdns_pcie_ln_regs_ext_ssc, |
| 976 | .num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc), |
| 977 | }; |
| 978 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 979 | /* refclk100MHz_20b_USB_cmn_pll_ext_ssc */ |
| 980 | static struct cdns_reg_pairs cdns_usb_cmn_regs_ext_ssc[] = { |
| 981 | {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG}, |
| 982 | {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG}, |
| 983 | {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG}, |
| 984 | {0x0000, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG} |
| 985 | }; |
| 986 | |
| 987 | /* refclk100MHz_20b_USB_ln_ext_ssc */ |
| 988 | static struct cdns_reg_pairs cdns_usb_ln_regs_ext_ssc[] = { |
| 989 | {0xFE0A, SIERRA_DET_STANDEC_A_PREG}, |
| 990 | {0x000F, SIERRA_DET_STANDEC_B_PREG}, |
Sanket Parmar | a366626 | 2022-01-28 13:41:28 +0530 | [diff] [blame] | 991 | {0x55A5, SIERRA_DET_STANDEC_C_PREG}, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 992 | {0x69ad, SIERRA_DET_STANDEC_D_PREG}, |
| 993 | {0x0241, SIERRA_DET_STANDEC_E_PREG}, |
Sanket Parmar | a366626 | 2022-01-28 13:41:28 +0530 | [diff] [blame] | 994 | {0x0110, SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG}, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 995 | {0x0014, SIERRA_PSM_A0IN_TMR_PREG}, |
| 996 | {0xCF00, SIERRA_PSM_DIAG_PREG}, |
| 997 | {0x001F, SIERRA_PSC_TX_A0_PREG}, |
| 998 | {0x0007, SIERRA_PSC_TX_A1_PREG}, |
| 999 | {0x0003, SIERRA_PSC_TX_A2_PREG}, |
| 1000 | {0x0003, SIERRA_PSC_TX_A3_PREG}, |
| 1001 | {0x0FFF, SIERRA_PSC_RX_A0_PREG}, |
Sanket Parmar | a366626 | 2022-01-28 13:41:28 +0530 | [diff] [blame] | 1002 | {0x0003, SIERRA_PSC_RX_A1_PREG}, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1003 | {0x0003, SIERRA_PSC_RX_A2_PREG}, |
| 1004 | {0x0001, SIERRA_PSC_RX_A3_PREG}, |
| 1005 | {0x0001, SIERRA_PLLCTRL_SUBRATE_PREG}, |
| 1006 | {0x0406, SIERRA_PLLCTRL_GEN_D_PREG}, |
| 1007 | {0x5233, SIERRA_PLLCTRL_CPGAIN_MODE_PREG}, |
| 1008 | {0x00CA, SIERRA_CLKPATH_BIASTRIM_PREG}, |
| 1009 | {0x2512, SIERRA_DFE_BIASTRIM_PREG}, |
| 1010 | {0x0000, SIERRA_DRVCTRL_ATTEN_PREG}, |
Sanket Parmar | a366626 | 2022-01-28 13:41:28 +0530 | [diff] [blame] | 1011 | {0x823E, SIERRA_CLKPATHCTRL_TMR_PREG}, |
| 1012 | {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG}, |
| 1013 | {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG}, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1014 | {0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG}, |
Sanket Parmar | a366626 | 2022-01-28 13:41:28 +0530 | [diff] [blame] | 1015 | {0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG}, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1016 | {0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG}, |
| 1017 | {0x0000, SIERRA_CREQ_EQ_CTRL_PREG}, |
Sanket Parmar | a366626 | 2022-01-28 13:41:28 +0530 | [diff] [blame] | 1018 | {0x0000, SIERRA_CREQ_SPARE_PREG}, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1019 | {0xCC44, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG}, |
Sanket Parmar | a366626 | 2022-01-28 13:41:28 +0530 | [diff] [blame] | 1020 | {0x8452, SIERRA_CTLELUT_CTRL_PREG}, |
| 1021 | {0x4121, SIERRA_DFE_ECMP_RATESEL_PREG}, |
| 1022 | {0x4121, SIERRA_DFE_SMP_RATESEL_PREG}, |
| 1023 | {0x0003, SIERRA_DEQ_PHALIGN_CTRL}, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1024 | {0x3200, SIERRA_DEQ_CONCUR_CTRL1_PREG}, |
| 1025 | {0x5064, SIERRA_DEQ_CONCUR_CTRL2_PREG}, |
| 1026 | {0x0030, SIERRA_DEQ_EPIPWR_CTRL2_PREG}, |
| 1027 | {0x0048, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG}, |
| 1028 | {0x5A5A, SIERRA_DEQ_ERRCMP_CTRL_PREG}, |
| 1029 | {0x02F5, SIERRA_DEQ_OFFSET_CTRL_PREG}, |
| 1030 | {0x02F5, SIERRA_DEQ_GAIN_CTRL_PREG}, |
Sanket Parmar | a366626 | 2022-01-28 13:41:28 +0530 | [diff] [blame] | 1031 | {0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG}, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1032 | {0x0014, SIERRA_DEQ_GLUT0}, |
| 1033 | {0x0014, SIERRA_DEQ_GLUT1}, |
| 1034 | {0x0014, SIERRA_DEQ_GLUT2}, |
| 1035 | {0x0014, SIERRA_DEQ_GLUT3}, |
| 1036 | {0x0014, SIERRA_DEQ_GLUT4}, |
| 1037 | {0x0014, SIERRA_DEQ_GLUT5}, |
| 1038 | {0x0014, SIERRA_DEQ_GLUT6}, |
| 1039 | {0x0014, SIERRA_DEQ_GLUT7}, |
| 1040 | {0x0014, SIERRA_DEQ_GLUT8}, |
| 1041 | {0x0014, SIERRA_DEQ_GLUT9}, |
| 1042 | {0x0014, SIERRA_DEQ_GLUT10}, |
| 1043 | {0x0014, SIERRA_DEQ_GLUT11}, |
| 1044 | {0x0014, SIERRA_DEQ_GLUT12}, |
| 1045 | {0x0014, SIERRA_DEQ_GLUT13}, |
| 1046 | {0x0014, SIERRA_DEQ_GLUT14}, |
| 1047 | {0x0014, SIERRA_DEQ_GLUT15}, |
| 1048 | {0x0014, SIERRA_DEQ_GLUT16}, |
| 1049 | {0x0BAE, SIERRA_DEQ_ALUT0}, |
| 1050 | {0x0AEB, SIERRA_DEQ_ALUT1}, |
| 1051 | {0x0A28, SIERRA_DEQ_ALUT2}, |
| 1052 | {0x0965, SIERRA_DEQ_ALUT3}, |
| 1053 | {0x08A2, SIERRA_DEQ_ALUT4}, |
| 1054 | {0x07DF, SIERRA_DEQ_ALUT5}, |
| 1055 | {0x071C, SIERRA_DEQ_ALUT6}, |
| 1056 | {0x0659, SIERRA_DEQ_ALUT7}, |
| 1057 | {0x0596, SIERRA_DEQ_ALUT8}, |
| 1058 | {0x0514, SIERRA_DEQ_ALUT9}, |
| 1059 | {0x0492, SIERRA_DEQ_ALUT10}, |
| 1060 | {0x0410, SIERRA_DEQ_ALUT11}, |
| 1061 | {0x038E, SIERRA_DEQ_ALUT12}, |
| 1062 | {0x030C, SIERRA_DEQ_ALUT13}, |
| 1063 | {0x03F4, SIERRA_DEQ_DFETAP_CTRL_PREG}, |
| 1064 | {0x0001, SIERRA_DFE_EN_1010_IGNORE_PREG}, |
| 1065 | {0x3C01, SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG}, |
| 1066 | {0x3C40, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG}, |
| 1067 | {0x1C08, SIERRA_DEQ_TAU_CTRL2_PREG}, |
| 1068 | {0x0033, SIERRA_DEQ_PICTRL_PREG}, |
| 1069 | {0x0400, SIERRA_CPICAL_TMRVAL_MODE1_PREG}, |
| 1070 | {0x0330, SIERRA_CPICAL_TMRVAL_MODE0_PREG}, |
| 1071 | {0x01FF, SIERRA_CPICAL_PICNT_MODE1_PREG}, |
| 1072 | {0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG}, |
| 1073 | {0x3232, SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG}, |
| 1074 | {0x0005, SIERRA_LFPSDET_SUPPORT_PREG}, |
| 1075 | {0x000F, SIERRA_LFPSFILT_NS_PREG}, |
| 1076 | {0x0009, SIERRA_LFPSFILT_RD_PREG}, |
| 1077 | {0x0001, SIERRA_LFPSFILT_MP_PREG}, |
Sanket Parmar | a366626 | 2022-01-28 13:41:28 +0530 | [diff] [blame] | 1078 | {0x6013, SIERRA_SIGDET_SUPPORT_PREG}, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1079 | {0x8013, SIERRA_SDFILT_H2L_A_PREG}, |
| 1080 | {0x8009, SIERRA_SDFILT_L2H_PREG}, |
| 1081 | {0x0024, SIERRA_RXBUFFER_CTLECTRL_PREG}, |
| 1082 | {0x0020, SIERRA_RXBUFFER_RCDFECTRL_PREG}, |
| 1083 | {0x4243, SIERRA_RXBUFFER_DFECTRL_PREG} |
| 1084 | }; |
| 1085 | |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 1086 | static struct cdns_sierra_vals usb_100_ext_ssc_cmn_vals = { |
| 1087 | .reg_pairs = cdns_usb_cmn_regs_ext_ssc, |
| 1088 | .num_regs = ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc), |
| 1089 | }; |
| 1090 | |
| 1091 | static struct cdns_sierra_vals usb_100_ext_ssc_ln_vals = { |
| 1092 | .reg_pairs = cdns_usb_ln_regs_ext_ssc, |
| 1093 | .num_regs = ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc), |
| 1094 | }; |
| 1095 | |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1096 | static const struct cdns_sierra_data cdns_map_sierra = { |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 1097 | .id_value = SIERRA_MACRO_ID, |
| 1098 | .block_offset_shift = 0x2, |
| 1099 | .reg_offset_shift = 0x2, |
Swapnil Jakhade | aa20b30 | 2022-01-28 13:41:44 +0530 | [diff] [blame] | 1100 | .pcs_cmn_vals = { |
| 1101 | [TYPE_PCIE] = { |
| 1102 | [TYPE_NONE] = { |
| 1103 | [EXTERNAL_SSC] = &pcie_phy_pcs_cmn_vals, |
| 1104 | }, |
| 1105 | }, |
| 1106 | }, |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 1107 | .pma_cmn_vals = { |
| 1108 | [TYPE_PCIE] = { |
| 1109 | [TYPE_NONE] = { |
| 1110 | [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals, |
| 1111 | }, |
| 1112 | }, |
| 1113 | [TYPE_USB] = { |
| 1114 | [TYPE_NONE] = { |
| 1115 | [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals, |
| 1116 | }, |
| 1117 | }, |
| 1118 | }, |
| 1119 | .pma_ln_vals = { |
| 1120 | [TYPE_PCIE] = { |
| 1121 | [TYPE_NONE] = { |
| 1122 | [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals, |
| 1123 | }, |
| 1124 | }, |
| 1125 | [TYPE_USB] = { |
| 1126 | [TYPE_NONE] = { |
| 1127 | [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals, |
| 1128 | }, |
| 1129 | }, |
| 1130 | }, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1131 | }; |
| 1132 | |
| 1133 | static const struct cdns_sierra_data cdns_ti_map_sierra = { |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 1134 | .id_value = SIERRA_MACRO_ID, |
| 1135 | .block_offset_shift = 0x0, |
| 1136 | .reg_offset_shift = 0x1, |
Swapnil Jakhade | aa20b30 | 2022-01-28 13:41:44 +0530 | [diff] [blame] | 1137 | .pcs_cmn_vals = { |
| 1138 | [TYPE_PCIE] = { |
| 1139 | [TYPE_NONE] = { |
| 1140 | [EXTERNAL_SSC] = &pcie_phy_pcs_cmn_vals, |
| 1141 | }, |
| 1142 | }, |
| 1143 | }, |
Swapnil Jakhade | e42a847 | 2022-01-28 13:41:40 +0530 | [diff] [blame] | 1144 | .pma_cmn_vals = { |
| 1145 | [TYPE_PCIE] = { |
| 1146 | [TYPE_NONE] = { |
| 1147 | [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals, |
| 1148 | }, |
| 1149 | }, |
| 1150 | [TYPE_USB] = { |
| 1151 | [TYPE_NONE] = { |
| 1152 | [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals, |
| 1153 | }, |
| 1154 | }, |
| 1155 | }, |
| 1156 | .pma_ln_vals = { |
| 1157 | [TYPE_PCIE] = { |
| 1158 | [TYPE_NONE] = { |
| 1159 | [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals, |
| 1160 | }, |
| 1161 | }, |
| 1162 | [TYPE_USB] = { |
| 1163 | [TYPE_NONE] = { |
| 1164 | [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals, |
| 1165 | }, |
| 1166 | }, |
| 1167 | }, |
Alan Douglas | fda76da | 2021-07-21 21:28:36 +0530 | [diff] [blame] | 1168 | }; |
| 1169 | |
| 1170 | static const struct udevice_id cdns_sierra_id_table[] = { |
| 1171 | { |
| 1172 | .compatible = "cdns,sierra-phy-t0", |
| 1173 | .data = (ulong)&cdns_map_sierra, |
| 1174 | }, |
| 1175 | { |
| 1176 | .compatible = "ti,sierra-phy-t0", |
| 1177 | .data = (ulong)&cdns_ti_map_sierra, |
| 1178 | }, |
| 1179 | {} |
| 1180 | }; |
| 1181 | |
| 1182 | U_BOOT_DRIVER(sierra_phy_provider) = { |
| 1183 | .name = "cdns,sierra", |
| 1184 | .id = UCLASS_PHY, |
| 1185 | .of_match = cdns_sierra_id_table, |
| 1186 | .probe = cdns_sierra_phy_probe, |
| 1187 | .remove = cdns_sierra_phy_remove, |
| 1188 | .ops = &ops, |
| 1189 | .priv_auto = sizeof(struct cdns_sierra_phy), |
| 1190 | }; |