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