144d30d62SAlan Douglas // SPDX-License-Identifier: GPL-2.0 244d30d62SAlan Douglas /* 344d30d62SAlan Douglas * Cadence Sierra PHY Driver 444d30d62SAlan Douglas * 544d30d62SAlan Douglas * Copyright (c) 2018 Cadence Design Systems 644d30d62SAlan Douglas * Author: Alan Douglas <adouglas@cadence.com> 744d30d62SAlan Douglas * 844d30d62SAlan Douglas */ 944d30d62SAlan Douglas #include <linux/clk.h> 1028081b72SKishon Vijay Abraham I #include <linux/clk-provider.h> 1144d30d62SAlan Douglas #include <linux/delay.h> 1244d30d62SAlan Douglas #include <linux/err.h> 1344d30d62SAlan Douglas #include <linux/io.h> 1444d30d62SAlan Douglas #include <linux/module.h> 1544d30d62SAlan Douglas #include <linux/phy/phy.h> 1644d30d62SAlan Douglas #include <linux/platform_device.h> 1744d30d62SAlan Douglas #include <linux/pm_runtime.h> 1844d30d62SAlan Douglas #include <linux/regmap.h> 1944d30d62SAlan Douglas #include <linux/reset.h> 2044d30d62SAlan Douglas #include <linux/slab.h> 2144d30d62SAlan Douglas #include <linux/of.h> 2244d30d62SAlan Douglas #include <linux/of_platform.h> 2344d30d62SAlan Douglas #include <dt-bindings/phy/phy.h> 2428081b72SKishon Vijay Abraham I #include <dt-bindings/phy/phy-cadence.h> 2544d30d62SAlan Douglas 26078e9e92SSwapnil Jakhade #define NUM_SSC_MODE 3 27078e9e92SSwapnil Jakhade #define NUM_PHY_TYPE 3 28078e9e92SSwapnil Jakhade 2944d30d62SAlan Douglas /* PHY register offsets */ 30380f5708SKishon Vijay Abraham I #define SIERRA_COMMON_CDB_OFFSET 0x0 31380f5708SKishon Vijay Abraham I #define SIERRA_MACRO_ID_REG 0x0 3228081b72SKishon Vijay Abraham I #define SIERRA_CMN_PLLLC_GEN_PREG 0x42 33871002d7SAnil Varughese #define SIERRA_CMN_PLLLC_MODE_PREG 0x48 34871002d7SAnil Varughese #define SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG 0x49 35871002d7SAnil Varughese #define SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG 0x4A 36871002d7SAnil Varughese #define SIERRA_CMN_PLLLC_LOCK_CNTSTART_PREG 0x4B 37871002d7SAnil Varughese #define SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG 0x4F 38871002d7SAnil Varughese #define SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG 0x50 39871002d7SAnil Varughese #define SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG 0x62 4028081b72SKishon Vijay Abraham I #define SIERRA_CMN_REFRCV_PREG 0x98 4128081b72SKishon Vijay Abraham I #define SIERRA_CMN_REFRCV1_PREG 0xB8 4228081b72SKishon Vijay Abraham I #define SIERRA_CMN_PLLLC1_GEN_PREG 0xC2 43380f5708SKishon Vijay Abraham I 44380f5708SKishon Vijay Abraham I #define SIERRA_LANE_CDB_OFFSET(ln, block_offset, reg_offset) \ 45380f5708SKishon Vijay Abraham I ((0x4000 << (block_offset)) + \ 46380f5708SKishon Vijay Abraham I (((ln) << 9) << (reg_offset))) 47aead5fd6SKishon Vijay Abraham I 48aead5fd6SKishon Vijay Abraham I #define SIERRA_DET_STANDEC_A_PREG 0x000 49aead5fd6SKishon Vijay Abraham I #define SIERRA_DET_STANDEC_B_PREG 0x001 50aead5fd6SKishon Vijay Abraham I #define SIERRA_DET_STANDEC_C_PREG 0x002 51aead5fd6SKishon Vijay Abraham I #define SIERRA_DET_STANDEC_D_PREG 0x003 52aead5fd6SKishon Vijay Abraham I #define SIERRA_DET_STANDEC_E_PREG 0x004 53871002d7SAnil Varughese #define SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG 0x008 54871002d7SAnil Varughese #define SIERRA_PSM_A0IN_TMR_PREG 0x009 55aead5fd6SKishon Vijay Abraham I #define SIERRA_PSM_DIAG_PREG 0x015 56aead5fd6SKishon Vijay Abraham I #define SIERRA_PSC_TX_A0_PREG 0x028 57aead5fd6SKishon Vijay Abraham I #define SIERRA_PSC_TX_A1_PREG 0x029 58aead5fd6SKishon Vijay Abraham I #define SIERRA_PSC_TX_A2_PREG 0x02A 59aead5fd6SKishon Vijay Abraham I #define SIERRA_PSC_TX_A3_PREG 0x02B 60aead5fd6SKishon Vijay Abraham I #define SIERRA_PSC_RX_A0_PREG 0x030 61aead5fd6SKishon Vijay Abraham I #define SIERRA_PSC_RX_A1_PREG 0x031 62aead5fd6SKishon Vijay Abraham I #define SIERRA_PSC_RX_A2_PREG 0x032 63aead5fd6SKishon Vijay Abraham I #define SIERRA_PSC_RX_A3_PREG 0x033 64aead5fd6SKishon Vijay Abraham I #define SIERRA_PLLCTRL_SUBRATE_PREG 0x03A 65aead5fd6SKishon Vijay Abraham I #define SIERRA_PLLCTRL_GEN_D_PREG 0x03E 66871002d7SAnil Varughese #define SIERRA_PLLCTRL_CPGAIN_MODE_PREG 0x03F 67adc4bd6fSKishon Vijay Abraham I #define SIERRA_PLLCTRL_STATUS_PREG 0x044 68871002d7SAnil Varughese #define SIERRA_CLKPATH_BIASTRIM_PREG 0x04B 69871002d7SAnil Varughese #define SIERRA_DFE_BIASTRIM_PREG 0x04C 70aead5fd6SKishon Vijay Abraham I #define SIERRA_DRVCTRL_ATTEN_PREG 0x06A 71aead5fd6SKishon Vijay Abraham I #define SIERRA_CLKPATHCTRL_TMR_PREG 0x081 72871002d7SAnil Varughese #define SIERRA_RX_CREQ_FLTR_A_MODE3_PREG 0x085 73871002d7SAnil Varughese #define SIERRA_RX_CREQ_FLTR_A_MODE2_PREG 0x086 74aead5fd6SKishon Vijay Abraham I #define SIERRA_RX_CREQ_FLTR_A_MODE1_PREG 0x087 75aead5fd6SKishon Vijay Abraham I #define SIERRA_RX_CREQ_FLTR_A_MODE0_PREG 0x088 76aead5fd6SKishon Vijay Abraham I #define SIERRA_CREQ_CCLKDET_MODE01_PREG 0x08E 77aead5fd6SKishon Vijay Abraham I #define SIERRA_RX_CTLE_MAINTENANCE_PREG 0x091 78aead5fd6SKishon Vijay Abraham I #define SIERRA_CREQ_FSMCLK_SEL_PREG 0x092 79871002d7SAnil Varughese #define SIERRA_CREQ_EQ_CTRL_PREG 0x093 80871002d7SAnil Varughese #define SIERRA_CREQ_SPARE_PREG 0x096 81871002d7SAnil Varughese #define SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG 0x097 82aead5fd6SKishon Vijay Abraham I #define SIERRA_CTLELUT_CTRL_PREG 0x098 83aead5fd6SKishon Vijay Abraham I #define SIERRA_DFE_ECMP_RATESEL_PREG 0x0C0 84aead5fd6SKishon Vijay Abraham I #define SIERRA_DFE_SMP_RATESEL_PREG 0x0C1 85871002d7SAnil Varughese #define SIERRA_DEQ_PHALIGN_CTRL 0x0C4 86871002d7SAnil Varughese #define SIERRA_DEQ_CONCUR_CTRL1_PREG 0x0C8 87871002d7SAnil Varughese #define SIERRA_DEQ_CONCUR_CTRL2_PREG 0x0C9 88871002d7SAnil Varughese #define SIERRA_DEQ_EPIPWR_CTRL2_PREG 0x0CD 89871002d7SAnil Varughese #define SIERRA_DEQ_FAST_MAINT_CYCLES_PREG 0x0CE 90871002d7SAnil Varughese #define SIERRA_DEQ_ERRCMP_CTRL_PREG 0x0D0 91871002d7SAnil Varughese #define SIERRA_DEQ_OFFSET_CTRL_PREG 0x0D8 92871002d7SAnil Varughese #define SIERRA_DEQ_GAIN_CTRL_PREG 0x0E0 93aead5fd6SKishon Vijay Abraham I #define SIERRA_DEQ_VGATUNE_CTRL_PREG 0x0E1 94871002d7SAnil Varughese #define SIERRA_DEQ_GLUT0 0x0E8 95871002d7SAnil Varughese #define SIERRA_DEQ_GLUT1 0x0E9 96871002d7SAnil Varughese #define SIERRA_DEQ_GLUT2 0x0EA 97871002d7SAnil Varughese #define SIERRA_DEQ_GLUT3 0x0EB 98871002d7SAnil Varughese #define SIERRA_DEQ_GLUT4 0x0EC 99871002d7SAnil Varughese #define SIERRA_DEQ_GLUT5 0x0ED 100871002d7SAnil Varughese #define SIERRA_DEQ_GLUT6 0x0EE 101871002d7SAnil Varughese #define SIERRA_DEQ_GLUT7 0x0EF 102871002d7SAnil Varughese #define SIERRA_DEQ_GLUT8 0x0F0 103871002d7SAnil Varughese #define SIERRA_DEQ_GLUT9 0x0F1 104871002d7SAnil Varughese #define SIERRA_DEQ_GLUT10 0x0F2 105871002d7SAnil Varughese #define SIERRA_DEQ_GLUT11 0x0F3 106871002d7SAnil Varughese #define SIERRA_DEQ_GLUT12 0x0F4 107871002d7SAnil Varughese #define SIERRA_DEQ_GLUT13 0x0F5 108871002d7SAnil Varughese #define SIERRA_DEQ_GLUT14 0x0F6 109871002d7SAnil Varughese #define SIERRA_DEQ_GLUT15 0x0F7 110871002d7SAnil Varughese #define SIERRA_DEQ_GLUT16 0x0F8 111871002d7SAnil Varughese #define SIERRA_DEQ_ALUT0 0x108 112871002d7SAnil Varughese #define SIERRA_DEQ_ALUT1 0x109 113871002d7SAnil Varughese #define SIERRA_DEQ_ALUT2 0x10A 114871002d7SAnil Varughese #define SIERRA_DEQ_ALUT3 0x10B 115871002d7SAnil Varughese #define SIERRA_DEQ_ALUT4 0x10C 116871002d7SAnil Varughese #define SIERRA_DEQ_ALUT5 0x10D 117871002d7SAnil Varughese #define SIERRA_DEQ_ALUT6 0x10E 118871002d7SAnil Varughese #define SIERRA_DEQ_ALUT7 0x10F 119871002d7SAnil Varughese #define SIERRA_DEQ_ALUT8 0x110 120871002d7SAnil Varughese #define SIERRA_DEQ_ALUT9 0x111 121871002d7SAnil Varughese #define SIERRA_DEQ_ALUT10 0x112 122871002d7SAnil Varughese #define SIERRA_DEQ_ALUT11 0x113 123871002d7SAnil Varughese #define SIERRA_DEQ_ALUT12 0x114 124871002d7SAnil Varughese #define SIERRA_DEQ_ALUT13 0x115 125871002d7SAnil Varughese #define SIERRA_DEQ_DFETAP_CTRL_PREG 0x128 126871002d7SAnil Varughese #define SIERRA_DFE_EN_1010_IGNORE_PREG 0x134 127871002d7SAnil Varughese #define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150 128871002d7SAnil Varughese #define SIERRA_DEQ_TAU_CTRL2_PREG 0x151 129871002d7SAnil Varughese #define SIERRA_DEQ_PICTRL_PREG 0x161 130871002d7SAnil Varughese #define SIERRA_CPICAL_TMRVAL_MODE1_PREG 0x170 131871002d7SAnil Varughese #define SIERRA_CPICAL_TMRVAL_MODE0_PREG 0x171 132871002d7SAnil Varughese #define SIERRA_CPICAL_PICNT_MODE1_PREG 0x174 133aead5fd6SKishon Vijay Abraham I #define SIERRA_CPI_OUTBUF_RATESEL_PREG 0x17C 134871002d7SAnil Varughese #define SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG 0x183 135871002d7SAnil Varughese #define SIERRA_LFPSDET_SUPPORT_PREG 0x188 136aead5fd6SKishon Vijay Abraham I #define SIERRA_LFPSFILT_NS_PREG 0x18A 137aead5fd6SKishon Vijay Abraham I #define SIERRA_LFPSFILT_RD_PREG 0x18B 138aead5fd6SKishon Vijay Abraham I #define SIERRA_LFPSFILT_MP_PREG 0x18C 139871002d7SAnil Varughese #define SIERRA_SIGDET_SUPPORT_PREG 0x190 140aead5fd6SKishon Vijay Abraham I #define SIERRA_SDFILT_H2L_A_PREG 0x191 141871002d7SAnil Varughese #define SIERRA_SDFILT_L2H_PREG 0x193 142871002d7SAnil Varughese #define SIERRA_RXBUFFER_CTLECTRL_PREG 0x19E 143871002d7SAnil Varughese #define SIERRA_RXBUFFER_RCDFECTRL_PREG 0x19F 144871002d7SAnil Varughese #define SIERRA_RXBUFFER_DFECTRL_PREG 0x1A0 145871002d7SAnil Varughese #define SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG 0x14F 146871002d7SAnil Varughese #define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150 147380f5708SKishon Vijay Abraham I 1488c95e172SSwapnil Jakhade /* PHY PCS common registers */ 1498c95e172SSwapnil Jakhade #define SIERRA_PHY_PCS_COMMON_OFFSET(block_offset) \ 150380f5708SKishon Vijay Abraham I (0xc000 << (block_offset)) 151fa105172SSwapnil Jakhade #define SIERRA_PHY_PIPE_CMN_CTRL1 0x0 152380f5708SKishon Vijay Abraham I #define SIERRA_PHY_PLL_CFG 0xe 15344d30d62SAlan Douglas 154*f1cc6c3fSSwapnil Jakhade /* PHY PMA common registers */ 155*f1cc6c3fSSwapnil Jakhade #define SIERRA_PHY_PMA_COMMON_OFFSET(block_offset) \ 156*f1cc6c3fSSwapnil Jakhade (0xE000 << (block_offset)) 157*f1cc6c3fSSwapnil Jakhade #define SIERRA_PHY_PMA_CMN_CTRL 0x000 158*f1cc6c3fSSwapnil Jakhade 15944d30d62SAlan Douglas #define SIERRA_MACRO_ID 0x00007364 160a43f72aeSKishon Vijay Abraham I #define SIERRA_MAX_LANES 16 161adc4bd6fSKishon Vijay Abraham I #define PLL_LOCK_TIME 100000 16244d30d62SAlan Douglas 16328081b72SKishon Vijay Abraham I #define CDNS_SIERRA_OUTPUT_CLOCKS 2 16428081b72SKishon Vijay Abraham I #define CDNS_SIERRA_INPUT_CLOCKS 5 165a0c30cd7SKishon Vijay Abraham I enum cdns_sierra_clock_input { 166a0c30cd7SKishon Vijay Abraham I PHY_CLK, 167a0c30cd7SKishon Vijay Abraham I CMN_REFCLK_DIG_DIV, 168a0c30cd7SKishon Vijay Abraham I CMN_REFCLK1_DIG_DIV, 16928081b72SKishon Vijay Abraham I PLL0_REFCLK, 17028081b72SKishon Vijay Abraham I PLL1_REFCLK, 171a0c30cd7SKishon Vijay Abraham I }; 172a0c30cd7SKishon Vijay Abraham I 17328081b72SKishon Vijay Abraham I #define SIERRA_NUM_CMN_PLLC 2 17428081b72SKishon Vijay Abraham I #define SIERRA_NUM_CMN_PLLC_PARENTS 2 17528081b72SKishon Vijay Abraham I 176380f5708SKishon Vijay Abraham I static const struct reg_field macro_id_type = 177380f5708SKishon Vijay Abraham I REG_FIELD(SIERRA_MACRO_ID_REG, 0, 15); 178380f5708SKishon Vijay Abraham I static const struct reg_field phy_pll_cfg_1 = 179380f5708SKishon Vijay Abraham I REG_FIELD(SIERRA_PHY_PLL_CFG, 1, 1); 180*f1cc6c3fSSwapnil Jakhade static const struct reg_field pma_cmn_ready = 181*f1cc6c3fSSwapnil Jakhade REG_FIELD(SIERRA_PHY_PMA_CMN_CTRL, 0, 0); 182adc4bd6fSKishon Vijay Abraham I static const struct reg_field pllctrl_lock = 183adc4bd6fSKishon Vijay Abraham I REG_FIELD(SIERRA_PLLCTRL_STATUS_PREG, 0, 0); 184380f5708SKishon Vijay Abraham I 18528081b72SKishon Vijay Abraham I static const char * const clk_names[] = { 18628081b72SKishon Vijay Abraham I [CDNS_SIERRA_PLL_CMNLC] = "pll_cmnlc", 18728081b72SKishon Vijay Abraham I [CDNS_SIERRA_PLL_CMNLC1] = "pll_cmnlc1", 18828081b72SKishon Vijay Abraham I }; 18928081b72SKishon Vijay Abraham I 19028081b72SKishon Vijay Abraham I enum cdns_sierra_cmn_plllc { 19128081b72SKishon Vijay Abraham I CMN_PLLLC, 19228081b72SKishon Vijay Abraham I CMN_PLLLC1, 19328081b72SKishon Vijay Abraham I }; 19428081b72SKishon Vijay Abraham I 19528081b72SKishon Vijay Abraham I struct cdns_sierra_pll_mux_reg_fields { 19628081b72SKishon Vijay Abraham I struct reg_field pfdclk_sel_preg; 19728081b72SKishon Vijay Abraham I struct reg_field plllc1en_field; 19828081b72SKishon Vijay Abraham I struct reg_field termen_field; 19928081b72SKishon Vijay Abraham I }; 20028081b72SKishon Vijay Abraham I 20128081b72SKishon Vijay Abraham I static const struct cdns_sierra_pll_mux_reg_fields cmn_plllc_pfdclk1_sel_preg[] = { 20228081b72SKishon Vijay Abraham I [CMN_PLLLC] = { 20328081b72SKishon Vijay Abraham I .pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC_GEN_PREG, 1, 1), 20428081b72SKishon Vijay Abraham I .plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 8, 8), 20528081b72SKishon Vijay Abraham I .termen_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 0, 0), 20628081b72SKishon Vijay Abraham I }, 20728081b72SKishon Vijay Abraham I [CMN_PLLLC1] = { 20828081b72SKishon Vijay Abraham I .pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC1_GEN_PREG, 1, 1), 20928081b72SKishon Vijay Abraham I .plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 8, 8), 21028081b72SKishon Vijay Abraham I .termen_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 0, 0), 21128081b72SKishon Vijay Abraham I }, 21228081b72SKishon Vijay Abraham I }; 21328081b72SKishon Vijay Abraham I 21428081b72SKishon Vijay Abraham I struct cdns_sierra_pll_mux { 21528081b72SKishon Vijay Abraham I struct clk_hw hw; 21628081b72SKishon Vijay Abraham I struct regmap_field *pfdclk_sel_preg; 21728081b72SKishon Vijay Abraham I struct regmap_field *plllc1en_field; 21828081b72SKishon Vijay Abraham I struct regmap_field *termen_field; 21928081b72SKishon Vijay Abraham I struct clk_init_data clk_data; 22028081b72SKishon Vijay Abraham I }; 22128081b72SKishon Vijay Abraham I 22228081b72SKishon Vijay Abraham I #define to_cdns_sierra_pll_mux(_hw) \ 22328081b72SKishon Vijay Abraham I container_of(_hw, struct cdns_sierra_pll_mux, hw) 22428081b72SKishon Vijay Abraham I 22528081b72SKishon Vijay Abraham I static const int pll_mux_parent_index[][SIERRA_NUM_CMN_PLLC_PARENTS] = { 22628081b72SKishon Vijay Abraham I [CMN_PLLLC] = { PLL0_REFCLK, PLL1_REFCLK }, 22728081b72SKishon Vijay Abraham I [CMN_PLLLC1] = { PLL1_REFCLK, PLL0_REFCLK }, 22828081b72SKishon Vijay Abraham I }; 22928081b72SKishon Vijay Abraham I 23028081b72SKishon Vijay Abraham I static u32 cdns_sierra_pll_mux_table[] = { 0, 1 }; 23128081b72SKishon Vijay Abraham I 232078e9e92SSwapnil Jakhade enum cdns_sierra_phy_type { 233078e9e92SSwapnil Jakhade TYPE_NONE, 234078e9e92SSwapnil Jakhade TYPE_PCIE, 235078e9e92SSwapnil Jakhade TYPE_USB 236078e9e92SSwapnil Jakhade }; 237078e9e92SSwapnil Jakhade 238078e9e92SSwapnil Jakhade enum cdns_sierra_ssc_mode { 239078e9e92SSwapnil Jakhade NO_SSC, 240078e9e92SSwapnil Jakhade EXTERNAL_SSC, 241078e9e92SSwapnil Jakhade INTERNAL_SSC 242078e9e92SSwapnil Jakhade }; 243078e9e92SSwapnil Jakhade 24444d30d62SAlan Douglas struct cdns_sierra_inst { 24544d30d62SAlan Douglas struct phy *phy; 246078e9e92SSwapnil Jakhade enum cdns_sierra_phy_type phy_type; 24744d30d62SAlan Douglas u32 num_lanes; 24844d30d62SAlan Douglas u32 mlane; 24944d30d62SAlan Douglas struct reset_control *lnk_rst; 2501e902b2aSSwapnil Jakhade enum cdns_sierra_ssc_mode ssc_mode; 25144d30d62SAlan Douglas }; 25244d30d62SAlan Douglas 25344d30d62SAlan Douglas struct cdns_reg_pairs { 25444d30d62SAlan Douglas u16 val; 25544d30d62SAlan Douglas u32 off; 25644d30d62SAlan Douglas }; 25744d30d62SAlan Douglas 258078e9e92SSwapnil Jakhade struct cdns_sierra_vals { 259078e9e92SSwapnil Jakhade const struct cdns_reg_pairs *reg_pairs; 260078e9e92SSwapnil Jakhade u32 num_regs; 261078e9e92SSwapnil Jakhade }; 262078e9e92SSwapnil Jakhade 26344d30d62SAlan Douglas struct cdns_sierra_data { 26444d30d62SAlan Douglas u32 id_value; 265380f5708SKishon Vijay Abraham I u8 block_offset_shift; 266380f5708SKishon Vijay Abraham I u8 reg_offset_shift; 267fa105172SSwapnil Jakhade struct cdns_sierra_vals *pcs_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE] 268fa105172SSwapnil Jakhade [NUM_SSC_MODE]; 269078e9e92SSwapnil Jakhade struct cdns_sierra_vals *pma_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE] 270078e9e92SSwapnil Jakhade [NUM_SSC_MODE]; 271078e9e92SSwapnil Jakhade struct cdns_sierra_vals *pma_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE] 272078e9e92SSwapnil Jakhade [NUM_SSC_MODE]; 27344d30d62SAlan Douglas }; 27444d30d62SAlan Douglas 275380f5708SKishon Vijay Abraham I struct cdns_regmap_cdb_context { 27644d30d62SAlan Douglas struct device *dev; 27744d30d62SAlan Douglas void __iomem *base; 278380f5708SKishon Vijay Abraham I u8 reg_offset_shift; 279380f5708SKishon Vijay Abraham I }; 280380f5708SKishon Vijay Abraham I 281380f5708SKishon Vijay Abraham I struct cdns_sierra_phy { 282380f5708SKishon Vijay Abraham I struct device *dev; 283380f5708SKishon Vijay Abraham I struct regmap *regmap; 284c3c11d55SSwapnil Jakhade const struct cdns_sierra_data *init_data; 28544d30d62SAlan Douglas struct cdns_sierra_inst phys[SIERRA_MAX_LANES]; 28644d30d62SAlan Douglas struct reset_control *phy_rst; 28744d30d62SAlan Douglas struct reset_control *apb_rst; 288380f5708SKishon Vijay Abraham I struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES]; 2898c95e172SSwapnil Jakhade struct regmap *regmap_phy_pcs_common_cdb; 290*f1cc6c3fSSwapnil Jakhade struct regmap *regmap_phy_pma_common_cdb; 291380f5708SKishon Vijay Abraham I struct regmap *regmap_common_cdb; 292380f5708SKishon Vijay Abraham I struct regmap_field *macro_id_type; 293380f5708SKishon Vijay Abraham I struct regmap_field *phy_pll_cfg_1; 294*f1cc6c3fSSwapnil Jakhade struct regmap_field *pma_cmn_ready; 295adc4bd6fSKishon Vijay Abraham I struct regmap_field *pllctrl_lock[SIERRA_MAX_LANES]; 29628081b72SKishon Vijay Abraham I struct regmap_field *cmn_refrcv_refclk_plllc1en_preg[SIERRA_NUM_CMN_PLLC]; 29728081b72SKishon Vijay Abraham I struct regmap_field *cmn_refrcv_refclk_termen_preg[SIERRA_NUM_CMN_PLLC]; 29828081b72SKishon Vijay Abraham I struct regmap_field *cmn_plllc_pfdclk1_sel_preg[SIERRA_NUM_CMN_PLLC]; 299a0c30cd7SKishon Vijay Abraham I struct clk *input_clks[CDNS_SIERRA_INPUT_CLOCKS]; 30044d30d62SAlan Douglas int nsubnodes; 301a43f72aeSKishon Vijay Abraham I u32 num_lanes; 30244d30d62SAlan Douglas bool autoconf; 30328081b72SKishon Vijay Abraham I struct clk_onecell_data clk_data; 30428081b72SKishon Vijay Abraham I struct clk *output_clks[CDNS_SIERRA_OUTPUT_CLOCKS]; 30544d30d62SAlan Douglas }; 30644d30d62SAlan Douglas 307380f5708SKishon Vijay Abraham I static int cdns_regmap_write(void *context, unsigned int reg, unsigned int val) 308380f5708SKishon Vijay Abraham I { 309380f5708SKishon Vijay Abraham I struct cdns_regmap_cdb_context *ctx = context; 310380f5708SKishon Vijay Abraham I u32 offset = reg << ctx->reg_offset_shift; 311380f5708SKishon Vijay Abraham I 312380f5708SKishon Vijay Abraham I writew(val, ctx->base + offset); 313380f5708SKishon Vijay Abraham I 314380f5708SKishon Vijay Abraham I return 0; 315380f5708SKishon Vijay Abraham I } 316380f5708SKishon Vijay Abraham I 317380f5708SKishon Vijay Abraham I static int cdns_regmap_read(void *context, unsigned int reg, unsigned int *val) 318380f5708SKishon Vijay Abraham I { 319380f5708SKishon Vijay Abraham I struct cdns_regmap_cdb_context *ctx = context; 320380f5708SKishon Vijay Abraham I u32 offset = reg << ctx->reg_offset_shift; 321380f5708SKishon Vijay Abraham I 322380f5708SKishon Vijay Abraham I *val = readw(ctx->base + offset); 323380f5708SKishon Vijay Abraham I return 0; 324380f5708SKishon Vijay Abraham I } 325380f5708SKishon Vijay Abraham I 326380f5708SKishon Vijay Abraham I #define SIERRA_LANE_CDB_REGMAP_CONF(n) \ 327380f5708SKishon Vijay Abraham I { \ 328380f5708SKishon Vijay Abraham I .name = "sierra_lane" n "_cdb", \ 329380f5708SKishon Vijay Abraham I .reg_stride = 1, \ 330380f5708SKishon Vijay Abraham I .fast_io = true, \ 331380f5708SKishon Vijay Abraham I .reg_write = cdns_regmap_write, \ 332380f5708SKishon Vijay Abraham I .reg_read = cdns_regmap_read, \ 333380f5708SKishon Vijay Abraham I } 334380f5708SKishon Vijay Abraham I 3353cfb0e8eSRikard Falkeborn static const struct regmap_config cdns_sierra_lane_cdb_config[] = { 336380f5708SKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("0"), 337380f5708SKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("1"), 338380f5708SKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("2"), 339380f5708SKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("3"), 340a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("4"), 341a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("5"), 342a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("6"), 343a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("7"), 344a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("8"), 345a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("9"), 346a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("10"), 347a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("11"), 348a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("12"), 349a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("13"), 350a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("14"), 351a43f72aeSKishon Vijay Abraham I SIERRA_LANE_CDB_REGMAP_CONF("15"), 352380f5708SKishon Vijay Abraham I }; 353380f5708SKishon Vijay Abraham I 3543cfb0e8eSRikard Falkeborn static const struct regmap_config cdns_sierra_common_cdb_config = { 355380f5708SKishon Vijay Abraham I .name = "sierra_common_cdb", 356380f5708SKishon Vijay Abraham I .reg_stride = 1, 357380f5708SKishon Vijay Abraham I .fast_io = true, 358380f5708SKishon Vijay Abraham I .reg_write = cdns_regmap_write, 359380f5708SKishon Vijay Abraham I .reg_read = cdns_regmap_read, 360380f5708SKishon Vijay Abraham I }; 361380f5708SKishon Vijay Abraham I 3628c95e172SSwapnil Jakhade static const struct regmap_config cdns_sierra_phy_pcs_cmn_cdb_config = { 3638c95e172SSwapnil Jakhade .name = "sierra_phy_pcs_cmn_cdb", 364380f5708SKishon Vijay Abraham I .reg_stride = 1, 365380f5708SKishon Vijay Abraham I .fast_io = true, 366380f5708SKishon Vijay Abraham I .reg_write = cdns_regmap_write, 367380f5708SKishon Vijay Abraham I .reg_read = cdns_regmap_read, 368380f5708SKishon Vijay Abraham I }; 369380f5708SKishon Vijay Abraham I 370*f1cc6c3fSSwapnil Jakhade static const struct regmap_config cdns_sierra_phy_pma_cmn_cdb_config = { 371*f1cc6c3fSSwapnil Jakhade .name = "sierra_phy_pma_cmn_cdb", 372*f1cc6c3fSSwapnil Jakhade .reg_stride = 1, 373*f1cc6c3fSSwapnil Jakhade .fast_io = true, 374*f1cc6c3fSSwapnil Jakhade .reg_write = cdns_regmap_write, 375*f1cc6c3fSSwapnil Jakhade .reg_read = cdns_regmap_read, 376*f1cc6c3fSSwapnil Jakhade }; 377*f1cc6c3fSSwapnil Jakhade 378cedcc2e2SKishon Vijay Abraham I static int cdns_sierra_phy_init(struct phy *gphy) 37944d30d62SAlan Douglas { 38044d30d62SAlan Douglas struct cdns_sierra_inst *ins = phy_get_drvdata(gphy); 38144d30d62SAlan Douglas struct cdns_sierra_phy *phy = dev_get_drvdata(gphy->dev.parent); 382078e9e92SSwapnil Jakhade const struct cdns_sierra_data *init_data = phy->init_data; 383078e9e92SSwapnil Jakhade struct cdns_sierra_vals *pma_cmn_vals, *pma_ln_vals; 384078e9e92SSwapnil Jakhade enum cdns_sierra_phy_type phy_type = ins->phy_type; 3851e902b2aSSwapnil Jakhade enum cdns_sierra_ssc_mode ssc = ins->ssc_mode; 386078e9e92SSwapnil Jakhade const struct cdns_reg_pairs *reg_pairs; 387fa105172SSwapnil Jakhade struct cdns_sierra_vals *pcs_cmn_vals; 38880f96fb1SColin Ian King struct regmap *regmap; 389078e9e92SSwapnil Jakhade u32 num_regs; 39044d30d62SAlan Douglas int i, j; 39144d30d62SAlan Douglas 392cedcc2e2SKishon Vijay Abraham I /* Initialise the PHY registers, unless auto configured */ 393cedcc2e2SKishon Vijay Abraham I if (phy->autoconf) 394cedcc2e2SKishon Vijay Abraham I return 0; 395cedcc2e2SKishon Vijay Abraham I 396a0c30cd7SKishon Vijay Abraham I clk_set_rate(phy->input_clks[CMN_REFCLK_DIG_DIV], 25000000); 397a0c30cd7SKishon Vijay Abraham I clk_set_rate(phy->input_clks[CMN_REFCLK1_DIG_DIV], 25000000); 398078e9e92SSwapnil Jakhade 399fa105172SSwapnil Jakhade /* PHY PCS common registers configurations */ 400fa105172SSwapnil Jakhade pcs_cmn_vals = init_data->pcs_cmn_vals[phy_type][TYPE_NONE][ssc]; 401fa105172SSwapnil Jakhade if (pcs_cmn_vals) { 402fa105172SSwapnil Jakhade reg_pairs = pcs_cmn_vals->reg_pairs; 403fa105172SSwapnil Jakhade num_regs = pcs_cmn_vals->num_regs; 404fa105172SSwapnil Jakhade regmap = phy->regmap_phy_pcs_common_cdb; 405fa105172SSwapnil Jakhade for (i = 0; i < num_regs; i++) 406fa105172SSwapnil Jakhade regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val); 407fa105172SSwapnil Jakhade } 408fa105172SSwapnil Jakhade 409078e9e92SSwapnil Jakhade /* PMA common registers configurations */ 410078e9e92SSwapnil Jakhade pma_cmn_vals = init_data->pma_cmn_vals[phy_type][TYPE_NONE][ssc]; 411078e9e92SSwapnil Jakhade if (pma_cmn_vals) { 412078e9e92SSwapnil Jakhade reg_pairs = pma_cmn_vals->reg_pairs; 413078e9e92SSwapnil Jakhade num_regs = pma_cmn_vals->num_regs; 414078e9e92SSwapnil Jakhade regmap = phy->regmap_common_cdb; 415078e9e92SSwapnil Jakhade for (i = 0; i < num_regs; i++) 416078e9e92SSwapnil Jakhade regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val); 41744d30d62SAlan Douglas } 418871002d7SAnil Varughese 419078e9e92SSwapnil Jakhade /* PMA lane registers configurations */ 420078e9e92SSwapnil Jakhade pma_ln_vals = init_data->pma_ln_vals[phy_type][TYPE_NONE][ssc]; 421078e9e92SSwapnil Jakhade if (pma_ln_vals) { 422078e9e92SSwapnil Jakhade reg_pairs = pma_ln_vals->reg_pairs; 423078e9e92SSwapnil Jakhade num_regs = pma_ln_vals->num_regs; 424380f5708SKishon Vijay Abraham I for (i = 0; i < ins->num_lanes; i++) { 425380f5708SKishon Vijay Abraham I regmap = phy->regmap_lane_cdb[i + ins->mlane]; 426078e9e92SSwapnil Jakhade for (j = 0; j < num_regs; j++) 427078e9e92SSwapnil Jakhade regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val); 428380f5708SKishon Vijay Abraham I } 429380f5708SKishon Vijay Abraham I } 430cedcc2e2SKishon Vijay Abraham I 431cedcc2e2SKishon Vijay Abraham I return 0; 43244d30d62SAlan Douglas } 43344d30d62SAlan Douglas 43444d30d62SAlan Douglas static int cdns_sierra_phy_on(struct phy *gphy) 43544d30d62SAlan Douglas { 436adc4bd6fSKishon Vijay Abraham I struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent); 43744d30d62SAlan Douglas struct cdns_sierra_inst *ins = phy_get_drvdata(gphy); 438adc4bd6fSKishon Vijay Abraham I struct device *dev = sp->dev; 439adc4bd6fSKishon Vijay Abraham I u32 val; 440adc4bd6fSKishon Vijay Abraham I int ret; 44144d30d62SAlan Douglas 4425b4f5757SKishon Vijay Abraham I ret = reset_control_deassert(sp->phy_rst); 4435b4f5757SKishon Vijay Abraham I if (ret) { 4445b4f5757SKishon Vijay Abraham I dev_err(dev, "Failed to take the PHY out of reset\n"); 4455b4f5757SKishon Vijay Abraham I return ret; 4465b4f5757SKishon Vijay Abraham I } 4475b4f5757SKishon Vijay Abraham I 44844d30d62SAlan Douglas /* Take the PHY lane group out of reset */ 449adc4bd6fSKishon Vijay Abraham I ret = reset_control_deassert(ins->lnk_rst); 450adc4bd6fSKishon Vijay Abraham I if (ret) { 451adc4bd6fSKishon Vijay Abraham I dev_err(dev, "Failed to take the PHY lane out of reset\n"); 452adc4bd6fSKishon Vijay Abraham I return ret; 453adc4bd6fSKishon Vijay Abraham I } 454adc4bd6fSKishon Vijay Abraham I 455*f1cc6c3fSSwapnil Jakhade /* 456*f1cc6c3fSSwapnil Jakhade * Wait for cmn_ready assertion 457*f1cc6c3fSSwapnil Jakhade * PHY_PMA_CMN_CTRL[0] == 1 458*f1cc6c3fSSwapnil Jakhade */ 459*f1cc6c3fSSwapnil Jakhade ret = regmap_field_read_poll_timeout(sp->pma_cmn_ready, val, val, 460*f1cc6c3fSSwapnil Jakhade 1000, PLL_LOCK_TIME); 461*f1cc6c3fSSwapnil Jakhade if (ret) { 462*f1cc6c3fSSwapnil Jakhade dev_err(dev, "Timeout waiting for CMN ready\n"); 463*f1cc6c3fSSwapnil Jakhade return ret; 464*f1cc6c3fSSwapnil Jakhade } 465*f1cc6c3fSSwapnil Jakhade 466adc4bd6fSKishon Vijay Abraham I ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane], 467adc4bd6fSKishon Vijay Abraham I val, val, 1000, PLL_LOCK_TIME); 468adc4bd6fSKishon Vijay Abraham I if (ret < 0) 469adc4bd6fSKishon Vijay Abraham I dev_err(dev, "PLL lock of lane failed\n"); 470adc4bd6fSKishon Vijay Abraham I 471adc4bd6fSKishon Vijay Abraham I return ret; 47244d30d62SAlan Douglas } 47344d30d62SAlan Douglas 47444d30d62SAlan Douglas static int cdns_sierra_phy_off(struct phy *gphy) 47544d30d62SAlan Douglas { 47644d30d62SAlan Douglas struct cdns_sierra_inst *ins = phy_get_drvdata(gphy); 47744d30d62SAlan Douglas 47844d30d62SAlan Douglas return reset_control_assert(ins->lnk_rst); 47944d30d62SAlan Douglas } 48044d30d62SAlan Douglas 4817904e15bSRoger Quadros static int cdns_sierra_phy_reset(struct phy *gphy) 4827904e15bSRoger Quadros { 4837904e15bSRoger Quadros struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent); 4847904e15bSRoger Quadros 4857904e15bSRoger Quadros reset_control_assert(sp->phy_rst); 4867904e15bSRoger Quadros reset_control_deassert(sp->phy_rst); 4877904e15bSRoger Quadros return 0; 4887904e15bSRoger Quadros }; 4897904e15bSRoger Quadros 49044d30d62SAlan Douglas static const struct phy_ops ops = { 491cedcc2e2SKishon Vijay Abraham I .init = cdns_sierra_phy_init, 49244d30d62SAlan Douglas .power_on = cdns_sierra_phy_on, 49344d30d62SAlan Douglas .power_off = cdns_sierra_phy_off, 4947904e15bSRoger Quadros .reset = cdns_sierra_phy_reset, 49544d30d62SAlan Douglas .owner = THIS_MODULE, 49644d30d62SAlan Douglas }; 49744d30d62SAlan Douglas 49828081b72SKishon Vijay Abraham I static u8 cdns_sierra_pll_mux_get_parent(struct clk_hw *hw) 49928081b72SKishon Vijay Abraham I { 50028081b72SKishon Vijay Abraham I struct cdns_sierra_pll_mux *mux = to_cdns_sierra_pll_mux(hw); 50128081b72SKishon Vijay Abraham I struct regmap_field *field = mux->pfdclk_sel_preg; 50228081b72SKishon Vijay Abraham I unsigned int val; 50328081b72SKishon Vijay Abraham I 50428081b72SKishon Vijay Abraham I regmap_field_read(field, &val); 50528081b72SKishon Vijay Abraham I return clk_mux_val_to_index(hw, cdns_sierra_pll_mux_table, 0, val); 50628081b72SKishon Vijay Abraham I } 50728081b72SKishon Vijay Abraham I 50828081b72SKishon Vijay Abraham I static int cdns_sierra_pll_mux_set_parent(struct clk_hw *hw, u8 index) 50928081b72SKishon Vijay Abraham I { 51028081b72SKishon Vijay Abraham I struct cdns_sierra_pll_mux *mux = to_cdns_sierra_pll_mux(hw); 51128081b72SKishon Vijay Abraham I struct regmap_field *plllc1en_field = mux->plllc1en_field; 51228081b72SKishon Vijay Abraham I struct regmap_field *termen_field = mux->termen_field; 51328081b72SKishon Vijay Abraham I struct regmap_field *field = mux->pfdclk_sel_preg; 51428081b72SKishon Vijay Abraham I int val, ret; 51528081b72SKishon Vijay Abraham I 51628081b72SKishon Vijay Abraham I ret = regmap_field_write(plllc1en_field, 0); 51728081b72SKishon Vijay Abraham I ret |= regmap_field_write(termen_field, 0); 51828081b72SKishon Vijay Abraham I if (index == 1) { 51928081b72SKishon Vijay Abraham I ret |= regmap_field_write(plllc1en_field, 1); 52028081b72SKishon Vijay Abraham I ret |= regmap_field_write(termen_field, 1); 52128081b72SKishon Vijay Abraham I } 52228081b72SKishon Vijay Abraham I 52328081b72SKishon Vijay Abraham I val = cdns_sierra_pll_mux_table[index]; 52428081b72SKishon Vijay Abraham I ret |= regmap_field_write(field, val); 52528081b72SKishon Vijay Abraham I 52628081b72SKishon Vijay Abraham I return ret; 52728081b72SKishon Vijay Abraham I } 52828081b72SKishon Vijay Abraham I 52928081b72SKishon Vijay Abraham I static const struct clk_ops cdns_sierra_pll_mux_ops = { 53028081b72SKishon Vijay Abraham I .set_parent = cdns_sierra_pll_mux_set_parent, 53128081b72SKishon Vijay Abraham I .get_parent = cdns_sierra_pll_mux_get_parent, 53228081b72SKishon Vijay Abraham I }; 53328081b72SKishon Vijay Abraham I 53428081b72SKishon Vijay Abraham I static int cdns_sierra_pll_mux_register(struct cdns_sierra_phy *sp, 53528081b72SKishon Vijay Abraham I struct regmap_field *pfdclk1_sel_field, 53628081b72SKishon Vijay Abraham I struct regmap_field *plllc1en_field, 53728081b72SKishon Vijay Abraham I struct regmap_field *termen_field, 53828081b72SKishon Vijay Abraham I int clk_index) 53928081b72SKishon Vijay Abraham I { 54028081b72SKishon Vijay Abraham I struct cdns_sierra_pll_mux *mux; 54128081b72SKishon Vijay Abraham I struct device *dev = sp->dev; 54228081b72SKishon Vijay Abraham I struct clk_init_data *init; 54328081b72SKishon Vijay Abraham I const char **parent_names; 54428081b72SKishon Vijay Abraham I unsigned int num_parents; 54528081b72SKishon Vijay Abraham I char clk_name[100]; 54628081b72SKishon Vijay Abraham I struct clk *clk; 54728081b72SKishon Vijay Abraham I int i; 54828081b72SKishon Vijay Abraham I 54928081b72SKishon Vijay Abraham I mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); 55028081b72SKishon Vijay Abraham I if (!mux) 55128081b72SKishon Vijay Abraham I return -ENOMEM; 55228081b72SKishon Vijay Abraham I 55328081b72SKishon Vijay Abraham I num_parents = SIERRA_NUM_CMN_PLLC_PARENTS; 55428081b72SKishon Vijay Abraham I parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), GFP_KERNEL); 55528081b72SKishon Vijay Abraham I if (!parent_names) 55628081b72SKishon Vijay Abraham I return -ENOMEM; 55728081b72SKishon Vijay Abraham I 55828081b72SKishon Vijay Abraham I for (i = 0; i < num_parents; i++) { 55928081b72SKishon Vijay Abraham I clk = sp->input_clks[pll_mux_parent_index[clk_index][i]]; 56028081b72SKishon Vijay Abraham I if (IS_ERR_OR_NULL(clk)) { 56128081b72SKishon Vijay Abraham I dev_err(dev, "No parent clock for derived_refclk\n"); 56228081b72SKishon Vijay Abraham I return PTR_ERR(clk); 56328081b72SKishon Vijay Abraham I } 56428081b72SKishon Vijay Abraham I parent_names[i] = __clk_get_name(clk); 56528081b72SKishon Vijay Abraham I } 56628081b72SKishon Vijay Abraham I 56728081b72SKishon Vijay Abraham I snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), clk_names[clk_index]); 56828081b72SKishon Vijay Abraham I 56928081b72SKishon Vijay Abraham I init = &mux->clk_data; 57028081b72SKishon Vijay Abraham I 57128081b72SKishon Vijay Abraham I init->ops = &cdns_sierra_pll_mux_ops; 57228081b72SKishon Vijay Abraham I init->flags = CLK_SET_RATE_NO_REPARENT; 57328081b72SKishon Vijay Abraham I init->parent_names = parent_names; 57428081b72SKishon Vijay Abraham I init->num_parents = num_parents; 57528081b72SKishon Vijay Abraham I init->name = clk_name; 57628081b72SKishon Vijay Abraham I 57728081b72SKishon Vijay Abraham I mux->pfdclk_sel_preg = pfdclk1_sel_field; 57828081b72SKishon Vijay Abraham I mux->plllc1en_field = plllc1en_field; 57928081b72SKishon Vijay Abraham I mux->termen_field = termen_field; 58028081b72SKishon Vijay Abraham I mux->hw.init = init; 58128081b72SKishon Vijay Abraham I 58228081b72SKishon Vijay Abraham I clk = devm_clk_register(dev, &mux->hw); 58328081b72SKishon Vijay Abraham I if (IS_ERR(clk)) 58428081b72SKishon Vijay Abraham I return PTR_ERR(clk); 58528081b72SKishon Vijay Abraham I 58628081b72SKishon Vijay Abraham I sp->output_clks[clk_index] = clk; 58728081b72SKishon Vijay Abraham I 58828081b72SKishon Vijay Abraham I return 0; 58928081b72SKishon Vijay Abraham I } 59028081b72SKishon Vijay Abraham I 59128081b72SKishon Vijay Abraham I static int cdns_sierra_phy_register_pll_mux(struct cdns_sierra_phy *sp) 59228081b72SKishon Vijay Abraham I { 59328081b72SKishon Vijay Abraham I struct regmap_field *pfdclk1_sel_field; 59428081b72SKishon Vijay Abraham I struct regmap_field *plllc1en_field; 59528081b72SKishon Vijay Abraham I struct regmap_field *termen_field; 59628081b72SKishon Vijay Abraham I struct device *dev = sp->dev; 59728081b72SKishon Vijay Abraham I int ret = 0, i, clk_index; 59828081b72SKishon Vijay Abraham I 59928081b72SKishon Vijay Abraham I clk_index = CDNS_SIERRA_PLL_CMNLC; 60028081b72SKishon Vijay Abraham I for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++, clk_index++) { 60128081b72SKishon Vijay Abraham I pfdclk1_sel_field = sp->cmn_plllc_pfdclk1_sel_preg[i]; 60228081b72SKishon Vijay Abraham I plllc1en_field = sp->cmn_refrcv_refclk_plllc1en_preg[i]; 60328081b72SKishon Vijay Abraham I termen_field = sp->cmn_refrcv_refclk_termen_preg[i]; 60428081b72SKishon Vijay Abraham I 60528081b72SKishon Vijay Abraham I ret = cdns_sierra_pll_mux_register(sp, pfdclk1_sel_field, plllc1en_field, 60628081b72SKishon Vijay Abraham I termen_field, clk_index); 60728081b72SKishon Vijay Abraham I if (ret) { 60828081b72SKishon Vijay Abraham I dev_err(dev, "Fail to register cmn plllc mux\n"); 60928081b72SKishon Vijay Abraham I return ret; 61028081b72SKishon Vijay Abraham I } 61128081b72SKishon Vijay Abraham I } 61228081b72SKishon Vijay Abraham I 61328081b72SKishon Vijay Abraham I return 0; 61428081b72SKishon Vijay Abraham I } 61528081b72SKishon Vijay Abraham I 61628081b72SKishon Vijay Abraham I static void cdns_sierra_clk_unregister(struct cdns_sierra_phy *sp) 61728081b72SKishon Vijay Abraham I { 61828081b72SKishon Vijay Abraham I struct device *dev = sp->dev; 61928081b72SKishon Vijay Abraham I struct device_node *node = dev->of_node; 62028081b72SKishon Vijay Abraham I 62128081b72SKishon Vijay Abraham I of_clk_del_provider(node); 62228081b72SKishon Vijay Abraham I } 62328081b72SKishon Vijay Abraham I 62428081b72SKishon Vijay Abraham I static int cdns_sierra_clk_register(struct cdns_sierra_phy *sp) 62528081b72SKishon Vijay Abraham I { 62628081b72SKishon Vijay Abraham I struct device *dev = sp->dev; 62728081b72SKishon Vijay Abraham I struct device_node *node = dev->of_node; 62828081b72SKishon Vijay Abraham I int ret; 62928081b72SKishon Vijay Abraham I 63028081b72SKishon Vijay Abraham I ret = cdns_sierra_phy_register_pll_mux(sp); 63128081b72SKishon Vijay Abraham I if (ret) { 63228081b72SKishon Vijay Abraham I dev_err(dev, "Failed to pll mux clocks\n"); 63328081b72SKishon Vijay Abraham I return ret; 63428081b72SKishon Vijay Abraham I } 63528081b72SKishon Vijay Abraham I 63628081b72SKishon Vijay Abraham I sp->clk_data.clks = sp->output_clks; 63728081b72SKishon Vijay Abraham I sp->clk_data.clk_num = CDNS_SIERRA_OUTPUT_CLOCKS; 63828081b72SKishon Vijay Abraham I ret = of_clk_add_provider(node, of_clk_src_onecell_get, &sp->clk_data); 63928081b72SKishon Vijay Abraham I if (ret) 64028081b72SKishon Vijay Abraham I dev_err(dev, "Failed to add clock provider: %s\n", node->name); 64128081b72SKishon Vijay Abraham I 64228081b72SKishon Vijay Abraham I return ret; 64328081b72SKishon Vijay Abraham I } 64428081b72SKishon Vijay Abraham I 64544d30d62SAlan Douglas static int cdns_sierra_get_optional(struct cdns_sierra_inst *inst, 64644d30d62SAlan Douglas struct device_node *child) 64744d30d62SAlan Douglas { 648078e9e92SSwapnil Jakhade u32 phy_type; 649078e9e92SSwapnil Jakhade 65044d30d62SAlan Douglas if (of_property_read_u32(child, "reg", &inst->mlane)) 65144d30d62SAlan Douglas return -EINVAL; 65244d30d62SAlan Douglas 65344d30d62SAlan Douglas if (of_property_read_u32(child, "cdns,num-lanes", &inst->num_lanes)) 65444d30d62SAlan Douglas return -EINVAL; 65544d30d62SAlan Douglas 656078e9e92SSwapnil Jakhade if (of_property_read_u32(child, "cdns,phy-type", &phy_type)) 65744d30d62SAlan Douglas return -EINVAL; 65844d30d62SAlan Douglas 659078e9e92SSwapnil Jakhade switch (phy_type) { 660078e9e92SSwapnil Jakhade case PHY_TYPE_PCIE: 661078e9e92SSwapnil Jakhade inst->phy_type = TYPE_PCIE; 662078e9e92SSwapnil Jakhade break; 663078e9e92SSwapnil Jakhade case PHY_TYPE_USB3: 664078e9e92SSwapnil Jakhade inst->phy_type = TYPE_USB; 665078e9e92SSwapnil Jakhade break; 666078e9e92SSwapnil Jakhade default: 667078e9e92SSwapnil Jakhade return -EINVAL; 668078e9e92SSwapnil Jakhade } 669078e9e92SSwapnil Jakhade 6701e902b2aSSwapnil Jakhade inst->ssc_mode = EXTERNAL_SSC; 6711e902b2aSSwapnil Jakhade of_property_read_u32(child, "cdns,ssc-mode", &inst->ssc_mode); 6721e902b2aSSwapnil Jakhade 67344d30d62SAlan Douglas return 0; 67444d30d62SAlan Douglas } 67544d30d62SAlan Douglas 676380f5708SKishon Vijay Abraham I static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base, 677380f5708SKishon Vijay Abraham I u32 block_offset, u8 reg_offset_shift, 678380f5708SKishon Vijay Abraham I const struct regmap_config *config) 679380f5708SKishon Vijay Abraham I { 680380f5708SKishon Vijay Abraham I struct cdns_regmap_cdb_context *ctx; 681380f5708SKishon Vijay Abraham I 682380f5708SKishon Vijay Abraham I ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); 683380f5708SKishon Vijay Abraham I if (!ctx) 684380f5708SKishon Vijay Abraham I return ERR_PTR(-ENOMEM); 685380f5708SKishon Vijay Abraham I 686380f5708SKishon Vijay Abraham I ctx->dev = dev; 687380f5708SKishon Vijay Abraham I ctx->base = base + block_offset; 688380f5708SKishon Vijay Abraham I ctx->reg_offset_shift = reg_offset_shift; 689380f5708SKishon Vijay Abraham I 690380f5708SKishon Vijay Abraham I return devm_regmap_init(dev, NULL, ctx, config); 691380f5708SKishon Vijay Abraham I } 692380f5708SKishon Vijay Abraham I 693380f5708SKishon Vijay Abraham I static int cdns_regfield_init(struct cdns_sierra_phy *sp) 694380f5708SKishon Vijay Abraham I { 695380f5708SKishon Vijay Abraham I struct device *dev = sp->dev; 696380f5708SKishon Vijay Abraham I struct regmap_field *field; 69728081b72SKishon Vijay Abraham I struct reg_field reg_field; 698380f5708SKishon Vijay Abraham I struct regmap *regmap; 699adc4bd6fSKishon Vijay Abraham I int i; 700380f5708SKishon Vijay Abraham I 701380f5708SKishon Vijay Abraham I regmap = sp->regmap_common_cdb; 702380f5708SKishon Vijay Abraham I field = devm_regmap_field_alloc(dev, regmap, macro_id_type); 703380f5708SKishon Vijay Abraham I if (IS_ERR(field)) { 704380f5708SKishon Vijay Abraham I dev_err(dev, "MACRO_ID_TYPE reg field init failed\n"); 705380f5708SKishon Vijay Abraham I return PTR_ERR(field); 706380f5708SKishon Vijay Abraham I } 707380f5708SKishon Vijay Abraham I sp->macro_id_type = field; 708380f5708SKishon Vijay Abraham I 70928081b72SKishon Vijay Abraham I for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++) { 71028081b72SKishon Vijay Abraham I reg_field = cmn_plllc_pfdclk1_sel_preg[i].pfdclk_sel_preg; 71128081b72SKishon Vijay Abraham I field = devm_regmap_field_alloc(dev, regmap, reg_field); 71228081b72SKishon Vijay Abraham I if (IS_ERR(field)) { 71328081b72SKishon Vijay Abraham I dev_err(dev, "PLLLC%d_PFDCLK1_SEL failed\n", i); 71428081b72SKishon Vijay Abraham I return PTR_ERR(field); 71528081b72SKishon Vijay Abraham I } 71628081b72SKishon Vijay Abraham I sp->cmn_plllc_pfdclk1_sel_preg[i] = field; 71728081b72SKishon Vijay Abraham I 71828081b72SKishon Vijay Abraham I reg_field = cmn_plllc_pfdclk1_sel_preg[i].plllc1en_field; 71928081b72SKishon Vijay Abraham I field = devm_regmap_field_alloc(dev, regmap, reg_field); 72028081b72SKishon Vijay Abraham I if (IS_ERR(field)) { 72128081b72SKishon Vijay Abraham I dev_err(dev, "REFRCV%d_REFCLK_PLLLC1EN failed\n", i); 72228081b72SKishon Vijay Abraham I return PTR_ERR(field); 72328081b72SKishon Vijay Abraham I } 72428081b72SKishon Vijay Abraham I sp->cmn_refrcv_refclk_plllc1en_preg[i] = field; 72528081b72SKishon Vijay Abraham I 72628081b72SKishon Vijay Abraham I reg_field = cmn_plllc_pfdclk1_sel_preg[i].termen_field; 72728081b72SKishon Vijay Abraham I field = devm_regmap_field_alloc(dev, regmap, reg_field); 72828081b72SKishon Vijay Abraham I if (IS_ERR(field)) { 72928081b72SKishon Vijay Abraham I dev_err(dev, "REFRCV%d_REFCLK_TERMEN failed\n", i); 73028081b72SKishon Vijay Abraham I return PTR_ERR(field); 73128081b72SKishon Vijay Abraham I } 73228081b72SKishon Vijay Abraham I sp->cmn_refrcv_refclk_termen_preg[i] = field; 73328081b72SKishon Vijay Abraham I } 73428081b72SKishon Vijay Abraham I 7358c95e172SSwapnil Jakhade regmap = sp->regmap_phy_pcs_common_cdb; 736380f5708SKishon Vijay Abraham I field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1); 737380f5708SKishon Vijay Abraham I if (IS_ERR(field)) { 738380f5708SKishon Vijay Abraham I dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n"); 739380f5708SKishon Vijay Abraham I return PTR_ERR(field); 740380f5708SKishon Vijay Abraham I } 741380f5708SKishon Vijay Abraham I sp->phy_pll_cfg_1 = field; 742380f5708SKishon Vijay Abraham I 743*f1cc6c3fSSwapnil Jakhade regmap = sp->regmap_phy_pma_common_cdb; 744*f1cc6c3fSSwapnil Jakhade field = devm_regmap_field_alloc(dev, regmap, pma_cmn_ready); 745*f1cc6c3fSSwapnil Jakhade if (IS_ERR(field)) { 746*f1cc6c3fSSwapnil Jakhade dev_err(dev, "PHY_PMA_CMN_CTRL reg field init failed\n"); 747*f1cc6c3fSSwapnil Jakhade return PTR_ERR(field); 748*f1cc6c3fSSwapnil Jakhade } 749*f1cc6c3fSSwapnil Jakhade sp->pma_cmn_ready = field; 750*f1cc6c3fSSwapnil Jakhade 751adc4bd6fSKishon Vijay Abraham I for (i = 0; i < SIERRA_MAX_LANES; i++) { 752adc4bd6fSKishon Vijay Abraham I regmap = sp->regmap_lane_cdb[i]; 753adc4bd6fSKishon Vijay Abraham I field = devm_regmap_field_alloc(dev, regmap, pllctrl_lock); 754adc4bd6fSKishon Vijay Abraham I if (IS_ERR(field)) { 755adc4bd6fSKishon Vijay Abraham I dev_err(dev, "P%d_ENABLE reg field init failed\n", i); 756adc4bd6fSKishon Vijay Abraham I return PTR_ERR(field); 757adc4bd6fSKishon Vijay Abraham I } 758adc4bd6fSKishon Vijay Abraham I sp->pllctrl_lock[i] = field; 759adc4bd6fSKishon Vijay Abraham I } 760adc4bd6fSKishon Vijay Abraham I 761380f5708SKishon Vijay Abraham I return 0; 762380f5708SKishon Vijay Abraham I } 763380f5708SKishon Vijay Abraham I 764380f5708SKishon Vijay Abraham I static int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp, 765380f5708SKishon Vijay Abraham I void __iomem *base, u8 block_offset_shift, 766380f5708SKishon Vijay Abraham I u8 reg_offset_shift) 767380f5708SKishon Vijay Abraham I { 768380f5708SKishon Vijay Abraham I struct device *dev = sp->dev; 769380f5708SKishon Vijay Abraham I struct regmap *regmap; 770380f5708SKishon Vijay Abraham I u32 block_offset; 771380f5708SKishon Vijay Abraham I int i; 772380f5708SKishon Vijay Abraham I 773380f5708SKishon Vijay Abraham I for (i = 0; i < SIERRA_MAX_LANES; i++) { 774380f5708SKishon Vijay Abraham I block_offset = SIERRA_LANE_CDB_OFFSET(i, block_offset_shift, 775380f5708SKishon Vijay Abraham I reg_offset_shift); 776380f5708SKishon Vijay Abraham I regmap = cdns_regmap_init(dev, base, block_offset, 777380f5708SKishon Vijay Abraham I reg_offset_shift, 778380f5708SKishon Vijay Abraham I &cdns_sierra_lane_cdb_config[i]); 779380f5708SKishon Vijay Abraham I if (IS_ERR(regmap)) { 780380f5708SKishon Vijay Abraham I dev_err(dev, "Failed to init lane CDB regmap\n"); 781380f5708SKishon Vijay Abraham I return PTR_ERR(regmap); 782380f5708SKishon Vijay Abraham I } 783380f5708SKishon Vijay Abraham I sp->regmap_lane_cdb[i] = regmap; 784380f5708SKishon Vijay Abraham I } 785380f5708SKishon Vijay Abraham I 786380f5708SKishon Vijay Abraham I regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET, 787380f5708SKishon Vijay Abraham I reg_offset_shift, 788380f5708SKishon Vijay Abraham I &cdns_sierra_common_cdb_config); 789380f5708SKishon Vijay Abraham I if (IS_ERR(regmap)) { 790380f5708SKishon Vijay Abraham I dev_err(dev, "Failed to init common CDB regmap\n"); 791380f5708SKishon Vijay Abraham I return PTR_ERR(regmap); 792380f5708SKishon Vijay Abraham I } 793380f5708SKishon Vijay Abraham I sp->regmap_common_cdb = regmap; 794380f5708SKishon Vijay Abraham I 7958c95e172SSwapnil Jakhade block_offset = SIERRA_PHY_PCS_COMMON_OFFSET(block_offset_shift); 796380f5708SKishon Vijay Abraham I regmap = cdns_regmap_init(dev, base, block_offset, reg_offset_shift, 7978c95e172SSwapnil Jakhade &cdns_sierra_phy_pcs_cmn_cdb_config); 798380f5708SKishon Vijay Abraham I if (IS_ERR(regmap)) { 7998c95e172SSwapnil Jakhade dev_err(dev, "Failed to init PHY PCS common CDB regmap\n"); 800380f5708SKishon Vijay Abraham I return PTR_ERR(regmap); 801380f5708SKishon Vijay Abraham I } 8028c95e172SSwapnil Jakhade sp->regmap_phy_pcs_common_cdb = regmap; 803380f5708SKishon Vijay Abraham I 804*f1cc6c3fSSwapnil Jakhade block_offset = SIERRA_PHY_PMA_COMMON_OFFSET(block_offset_shift); 805*f1cc6c3fSSwapnil Jakhade regmap = cdns_regmap_init(dev, base, block_offset, reg_offset_shift, 806*f1cc6c3fSSwapnil Jakhade &cdns_sierra_phy_pma_cmn_cdb_config); 807*f1cc6c3fSSwapnil Jakhade if (IS_ERR(regmap)) { 808*f1cc6c3fSSwapnil Jakhade dev_err(dev, "Failed to init PHY PMA common CDB regmap\n"); 809*f1cc6c3fSSwapnil Jakhade return PTR_ERR(regmap); 810*f1cc6c3fSSwapnil Jakhade } 811*f1cc6c3fSSwapnil Jakhade sp->regmap_phy_pma_common_cdb = regmap; 812*f1cc6c3fSSwapnil Jakhade 813380f5708SKishon Vijay Abraham I return 0; 814380f5708SKishon Vijay Abraham I } 815380f5708SKishon Vijay Abraham I 8167e016cbcSKishon Vijay Abraham I static int cdns_sierra_phy_get_clocks(struct cdns_sierra_phy *sp, 8177e016cbcSKishon Vijay Abraham I struct device *dev) 8187e016cbcSKishon Vijay Abraham I { 8197e016cbcSKishon Vijay Abraham I struct clk *clk; 8207e016cbcSKishon Vijay Abraham I int ret; 8217e016cbcSKishon Vijay Abraham I 8227e016cbcSKishon Vijay Abraham I clk = devm_clk_get_optional(dev, "phy_clk"); 8237e016cbcSKishon Vijay Abraham I if (IS_ERR(clk)) { 8247e016cbcSKishon Vijay Abraham I dev_err(dev, "failed to get clock phy_clk\n"); 8257e016cbcSKishon Vijay Abraham I return PTR_ERR(clk); 8267e016cbcSKishon Vijay Abraham I } 827a0c30cd7SKishon Vijay Abraham I sp->input_clks[PHY_CLK] = clk; 8287e016cbcSKishon Vijay Abraham I 8297e016cbcSKishon Vijay Abraham I clk = devm_clk_get_optional(dev, "cmn_refclk_dig_div"); 8307e016cbcSKishon Vijay Abraham I if (IS_ERR(clk)) { 8317e016cbcSKishon Vijay Abraham I dev_err(dev, "cmn_refclk_dig_div clock not found\n"); 8327e016cbcSKishon Vijay Abraham I ret = PTR_ERR(clk); 8337e016cbcSKishon Vijay Abraham I return ret; 8347e016cbcSKishon Vijay Abraham I } 835a0c30cd7SKishon Vijay Abraham I sp->input_clks[CMN_REFCLK_DIG_DIV] = clk; 8367e016cbcSKishon Vijay Abraham I 8377e016cbcSKishon Vijay Abraham I clk = devm_clk_get_optional(dev, "cmn_refclk1_dig_div"); 8387e016cbcSKishon Vijay Abraham I if (IS_ERR(clk)) { 8397e016cbcSKishon Vijay Abraham I dev_err(dev, "cmn_refclk1_dig_div clock not found\n"); 8407e016cbcSKishon Vijay Abraham I ret = PTR_ERR(clk); 8417e016cbcSKishon Vijay Abraham I return ret; 8427e016cbcSKishon Vijay Abraham I } 843a0c30cd7SKishon Vijay Abraham I sp->input_clks[CMN_REFCLK1_DIG_DIV] = clk; 8447e016cbcSKishon Vijay Abraham I 84528081b72SKishon Vijay Abraham I clk = devm_clk_get_optional(dev, "pll0_refclk"); 84628081b72SKishon Vijay Abraham I if (IS_ERR(clk)) { 84728081b72SKishon Vijay Abraham I dev_err(dev, "pll0_refclk clock not found\n"); 84828081b72SKishon Vijay Abraham I ret = PTR_ERR(clk); 84928081b72SKishon Vijay Abraham I return ret; 85028081b72SKishon Vijay Abraham I } 85128081b72SKishon Vijay Abraham I sp->input_clks[PLL0_REFCLK] = clk; 85228081b72SKishon Vijay Abraham I 85328081b72SKishon Vijay Abraham I clk = devm_clk_get_optional(dev, "pll1_refclk"); 85428081b72SKishon Vijay Abraham I if (IS_ERR(clk)) { 85528081b72SKishon Vijay Abraham I dev_err(dev, "pll1_refclk clock not found\n"); 85628081b72SKishon Vijay Abraham I ret = PTR_ERR(clk); 85728081b72SKishon Vijay Abraham I return ret; 85828081b72SKishon Vijay Abraham I } 85928081b72SKishon Vijay Abraham I sp->input_clks[PLL1_REFCLK] = clk; 86028081b72SKishon Vijay Abraham I 8617e016cbcSKishon Vijay Abraham I return 0; 8627e016cbcSKishon Vijay Abraham I } 8637e016cbcSKishon Vijay Abraham I 8641436ec30SKishon Vijay Abraham I static int cdns_sierra_phy_enable_clocks(struct cdns_sierra_phy *sp) 8651436ec30SKishon Vijay Abraham I { 8661436ec30SKishon Vijay Abraham I int ret; 8671436ec30SKishon Vijay Abraham I 8681436ec30SKishon Vijay Abraham I ret = clk_prepare_enable(sp->input_clks[PHY_CLK]); 8691436ec30SKishon Vijay Abraham I if (ret) 8701436ec30SKishon Vijay Abraham I return ret; 8711436ec30SKishon Vijay Abraham I 8721436ec30SKishon Vijay Abraham I ret = clk_prepare_enable(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]); 8731436ec30SKishon Vijay Abraham I if (ret) 8741436ec30SKishon Vijay Abraham I goto err_pll_cmnlc; 8751436ec30SKishon Vijay Abraham I 8761436ec30SKishon Vijay Abraham I ret = clk_prepare_enable(sp->output_clks[CDNS_SIERRA_PLL_CMNLC1]); 8771436ec30SKishon Vijay Abraham I if (ret) 8781436ec30SKishon Vijay Abraham I goto err_pll_cmnlc1; 8791436ec30SKishon Vijay Abraham I 8801436ec30SKishon Vijay Abraham I return 0; 8811436ec30SKishon Vijay Abraham I 8821436ec30SKishon Vijay Abraham I err_pll_cmnlc1: 8831436ec30SKishon Vijay Abraham I clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]); 8841436ec30SKishon Vijay Abraham I 8851436ec30SKishon Vijay Abraham I err_pll_cmnlc: 8861436ec30SKishon Vijay Abraham I clk_disable_unprepare(sp->input_clks[PHY_CLK]); 8871436ec30SKishon Vijay Abraham I 8881436ec30SKishon Vijay Abraham I return ret; 8891436ec30SKishon Vijay Abraham I } 8901436ec30SKishon Vijay Abraham I 8911436ec30SKishon Vijay Abraham I static void cdns_sierra_phy_disable_clocks(struct cdns_sierra_phy *sp) 8921436ec30SKishon Vijay Abraham I { 8931436ec30SKishon Vijay Abraham I clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC1]); 8941436ec30SKishon Vijay Abraham I clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]); 8951436ec30SKishon Vijay Abraham I clk_disable_unprepare(sp->input_clks[PHY_CLK]); 8961436ec30SKishon Vijay Abraham I } 8971436ec30SKishon Vijay Abraham I 8981d5f40e0SKishon Vijay Abraham I static int cdns_sierra_phy_get_resets(struct cdns_sierra_phy *sp, 8991d5f40e0SKishon Vijay Abraham I struct device *dev) 9001d5f40e0SKishon Vijay Abraham I { 9011d5f40e0SKishon Vijay Abraham I struct reset_control *rst; 9021d5f40e0SKishon Vijay Abraham I 90315b0b82dSKishon Vijay Abraham I rst = devm_reset_control_get_exclusive(dev, "sierra_reset"); 9041d5f40e0SKishon Vijay Abraham I if (IS_ERR(rst)) { 9051d5f40e0SKishon Vijay Abraham I dev_err(dev, "failed to get reset\n"); 9061d5f40e0SKishon Vijay Abraham I return PTR_ERR(rst); 9071d5f40e0SKishon Vijay Abraham I } 9081d5f40e0SKishon Vijay Abraham I sp->phy_rst = rst; 9091d5f40e0SKishon Vijay Abraham I 91015b0b82dSKishon Vijay Abraham I rst = devm_reset_control_get_optional_exclusive(dev, "sierra_apb"); 9111d5f40e0SKishon Vijay Abraham I if (IS_ERR(rst)) { 9121d5f40e0SKishon Vijay Abraham I dev_err(dev, "failed to get apb reset\n"); 9131d5f40e0SKishon Vijay Abraham I return PTR_ERR(rst); 9141d5f40e0SKishon Vijay Abraham I } 9151d5f40e0SKishon Vijay Abraham I sp->apb_rst = rst; 9161d5f40e0SKishon Vijay Abraham I 9171d5f40e0SKishon Vijay Abraham I return 0; 9181d5f40e0SKishon Vijay Abraham I } 9191d5f40e0SKishon Vijay Abraham I 92044d30d62SAlan Douglas static int cdns_sierra_phy_probe(struct platform_device *pdev) 92144d30d62SAlan Douglas { 92244d30d62SAlan Douglas struct cdns_sierra_phy *sp; 92344d30d62SAlan Douglas struct phy_provider *phy_provider; 92444d30d62SAlan Douglas struct device *dev = &pdev->dev; 925c3c11d55SSwapnil Jakhade const struct cdns_sierra_data *data; 926380f5708SKishon Vijay Abraham I unsigned int id_value; 92744d30d62SAlan Douglas int i, ret, node = 0; 928380f5708SKishon Vijay Abraham I void __iomem *base; 92944d30d62SAlan Douglas struct device_node *dn = dev->of_node, *child; 93044d30d62SAlan Douglas 93144d30d62SAlan Douglas if (of_get_child_count(dn) == 0) 93244d30d62SAlan Douglas return -ENODEV; 93344d30d62SAlan Douglas 934380f5708SKishon Vijay Abraham I /* Get init data for this PHY */ 935c3c11d55SSwapnil Jakhade data = of_device_get_match_data(dev); 936c3c11d55SSwapnil Jakhade if (!data) 937380f5708SKishon Vijay Abraham I return -EINVAL; 938380f5708SKishon Vijay Abraham I 93944d30d62SAlan Douglas sp = devm_kzalloc(dev, sizeof(*sp), GFP_KERNEL); 94044d30d62SAlan Douglas if (!sp) 94144d30d62SAlan Douglas return -ENOMEM; 94244d30d62SAlan Douglas dev_set_drvdata(dev, sp); 94344d30d62SAlan Douglas sp->dev = dev; 944380f5708SKishon Vijay Abraham I sp->init_data = data; 94544d30d62SAlan Douglas 946fa629094SChunfeng Yun base = devm_platform_ioremap_resource(pdev, 0); 947380f5708SKishon Vijay Abraham I if (IS_ERR(base)) { 94844d30d62SAlan Douglas dev_err(dev, "missing \"reg\"\n"); 949380f5708SKishon Vijay Abraham I return PTR_ERR(base); 95044d30d62SAlan Douglas } 95144d30d62SAlan Douglas 952380f5708SKishon Vijay Abraham I ret = cdns_regmap_init_blocks(sp, base, data->block_offset_shift, 953380f5708SKishon Vijay Abraham I data->reg_offset_shift); 954380f5708SKishon Vijay Abraham I if (ret) 955380f5708SKishon Vijay Abraham I return ret; 956380f5708SKishon Vijay Abraham I 957380f5708SKishon Vijay Abraham I ret = cdns_regfield_init(sp); 958380f5708SKishon Vijay Abraham I if (ret) 959380f5708SKishon Vijay Abraham I return ret; 96044d30d62SAlan Douglas 96144d30d62SAlan Douglas platform_set_drvdata(pdev, sp); 96244d30d62SAlan Douglas 9637e016cbcSKishon Vijay Abraham I ret = cdns_sierra_phy_get_clocks(sp, dev); 9647e016cbcSKishon Vijay Abraham I if (ret) 9657e016cbcSKishon Vijay Abraham I return ret; 96644d30d62SAlan Douglas 96728081b72SKishon Vijay Abraham I ret = cdns_sierra_clk_register(sp); 9681d5f40e0SKishon Vijay Abraham I if (ret) 9691d5f40e0SKishon Vijay Abraham I return ret; 97044d30d62SAlan Douglas 97128081b72SKishon Vijay Abraham I ret = cdns_sierra_phy_get_resets(sp, dev); 97228081b72SKishon Vijay Abraham I if (ret) 97328081b72SKishon Vijay Abraham I goto unregister_clk; 97428081b72SKishon Vijay Abraham I 9751436ec30SKishon Vijay Abraham I ret = cdns_sierra_phy_enable_clocks(sp); 97644d30d62SAlan Douglas if (ret) 97728081b72SKishon Vijay Abraham I goto unregister_clk; 97844d30d62SAlan Douglas 97944d30d62SAlan Douglas /* Enable APB */ 98044d30d62SAlan Douglas reset_control_deassert(sp->apb_rst); 98144d30d62SAlan Douglas 98244d30d62SAlan Douglas /* Check that PHY is present */ 983380f5708SKishon Vijay Abraham I regmap_field_read(sp->macro_id_type, &id_value); 984380f5708SKishon Vijay Abraham I if (sp->init_data->id_value != id_value) { 98544d30d62SAlan Douglas ret = -EINVAL; 98644d30d62SAlan Douglas goto clk_disable; 98744d30d62SAlan Douglas } 98844d30d62SAlan Douglas 98944d30d62SAlan Douglas sp->autoconf = of_property_read_bool(dn, "cdns,autoconf"); 99044d30d62SAlan Douglas 99144d30d62SAlan Douglas for_each_available_child_of_node(dn, child) { 99244d30d62SAlan Douglas struct phy *gphy; 99344d30d62SAlan Douglas 99403ada5a3SKishon Vijay Abraham I if (!(of_node_name_eq(child, "phy") || 99503ada5a3SKishon Vijay Abraham I of_node_name_eq(child, "link"))) 99603ada5a3SKishon Vijay Abraham I continue; 99703ada5a3SKishon Vijay Abraham I 99844d30d62SAlan Douglas sp->phys[node].lnk_rst = 999b872936fSKishon Vijay Abraham I of_reset_control_array_get_exclusive(child); 100044d30d62SAlan Douglas 100144d30d62SAlan Douglas if (IS_ERR(sp->phys[node].lnk_rst)) { 100244d30d62SAlan Douglas dev_err(dev, "failed to get reset %s\n", 100344d30d62SAlan Douglas child->full_name); 100444d30d62SAlan Douglas ret = PTR_ERR(sp->phys[node].lnk_rst); 100544d30d62SAlan Douglas goto put_child2; 100644d30d62SAlan Douglas } 100744d30d62SAlan Douglas 100844d30d62SAlan Douglas if (!sp->autoconf) { 100944d30d62SAlan Douglas ret = cdns_sierra_get_optional(&sp->phys[node], child); 101044d30d62SAlan Douglas if (ret) { 101144d30d62SAlan Douglas dev_err(dev, "missing property in node %s\n", 101244d30d62SAlan Douglas child->name); 101344d30d62SAlan Douglas goto put_child; 101444d30d62SAlan Douglas } 101544d30d62SAlan Douglas } 101644d30d62SAlan Douglas 1017a43f72aeSKishon Vijay Abraham I sp->num_lanes += sp->phys[node].num_lanes; 1018a43f72aeSKishon Vijay Abraham I 101944d30d62SAlan Douglas gphy = devm_phy_create(dev, child, &ops); 102044d30d62SAlan Douglas 102144d30d62SAlan Douglas if (IS_ERR(gphy)) { 102244d30d62SAlan Douglas ret = PTR_ERR(gphy); 102344d30d62SAlan Douglas goto put_child; 102444d30d62SAlan Douglas } 102544d30d62SAlan Douglas sp->phys[node].phy = gphy; 102644d30d62SAlan Douglas phy_set_drvdata(gphy, &sp->phys[node]); 102744d30d62SAlan Douglas 102844d30d62SAlan Douglas node++; 102944d30d62SAlan Douglas } 103044d30d62SAlan Douglas sp->nsubnodes = node; 103144d30d62SAlan Douglas 1032a43f72aeSKishon Vijay Abraham I if (sp->num_lanes > SIERRA_MAX_LANES) { 10336411e386SWang Wensheng ret = -EINVAL; 1034a43f72aeSKishon Vijay Abraham I dev_err(dev, "Invalid lane configuration\n"); 1035a43f72aeSKishon Vijay Abraham I goto put_child2; 1036a43f72aeSKishon Vijay Abraham I } 1037a43f72aeSKishon Vijay Abraham I 103844d30d62SAlan Douglas /* If more than one subnode, configure the PHY as multilink */ 103944d30d62SAlan Douglas if (!sp->autoconf && sp->nsubnodes > 1) 1040380f5708SKishon Vijay Abraham I regmap_field_write(sp->phy_pll_cfg_1, 0x1); 104144d30d62SAlan Douglas 104244d30d62SAlan Douglas pm_runtime_enable(dev); 104344d30d62SAlan Douglas phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 104444d30d62SAlan Douglas return PTR_ERR_OR_ZERO(phy_provider); 104544d30d62SAlan Douglas 104644d30d62SAlan Douglas put_child: 104744d30d62SAlan Douglas node++; 104844d30d62SAlan Douglas put_child2: 104944d30d62SAlan Douglas for (i = 0; i < node; i++) 105044d30d62SAlan Douglas reset_control_put(sp->phys[i].lnk_rst); 105144d30d62SAlan Douglas of_node_put(child); 105244d30d62SAlan Douglas clk_disable: 10531436ec30SKishon Vijay Abraham I cdns_sierra_phy_disable_clocks(sp); 105444d30d62SAlan Douglas reset_control_assert(sp->apb_rst); 105528081b72SKishon Vijay Abraham I unregister_clk: 105628081b72SKishon Vijay Abraham I cdns_sierra_clk_unregister(sp); 105744d30d62SAlan Douglas return ret; 105844d30d62SAlan Douglas } 105944d30d62SAlan Douglas 106044d30d62SAlan Douglas static int cdns_sierra_phy_remove(struct platform_device *pdev) 106144d30d62SAlan Douglas { 1062748e3456SKishon Vijay Abraham I struct cdns_sierra_phy *phy = platform_get_drvdata(pdev); 106344d30d62SAlan Douglas int i; 106444d30d62SAlan Douglas 106544d30d62SAlan Douglas reset_control_assert(phy->phy_rst); 106644d30d62SAlan Douglas reset_control_assert(phy->apb_rst); 106744d30d62SAlan Douglas pm_runtime_disable(&pdev->dev); 106844d30d62SAlan Douglas 10691436ec30SKishon Vijay Abraham I cdns_sierra_phy_disable_clocks(phy); 107044d30d62SAlan Douglas /* 107144d30d62SAlan Douglas * The device level resets will be put automatically. 107244d30d62SAlan Douglas * Need to put the subnode resets here though. 107344d30d62SAlan Douglas */ 107444d30d62SAlan Douglas for (i = 0; i < phy->nsubnodes; i++) { 107544d30d62SAlan Douglas reset_control_assert(phy->phys[i].lnk_rst); 107644d30d62SAlan Douglas reset_control_put(phy->phys[i].lnk_rst); 107744d30d62SAlan Douglas } 107829c2d02aSKishon Vijay Abraham I 107928081b72SKishon Vijay Abraham I cdns_sierra_clk_unregister(phy); 108029c2d02aSKishon Vijay Abraham I 108144d30d62SAlan Douglas return 0; 108244d30d62SAlan Douglas } 108344d30d62SAlan Douglas 1084fa105172SSwapnil Jakhade /* PCIE PHY PCS common configuration */ 1085fa105172SSwapnil Jakhade static struct cdns_reg_pairs pcie_phy_pcs_cmn_regs[] = { 1086fa105172SSwapnil Jakhade {0x0430, SIERRA_PHY_PIPE_CMN_CTRL1} 1087fa105172SSwapnil Jakhade }; 1088fa105172SSwapnil Jakhade 1089fa105172SSwapnil Jakhade static struct cdns_sierra_vals pcie_phy_pcs_cmn_vals = { 1090fa105172SSwapnil Jakhade .reg_pairs = pcie_phy_pcs_cmn_regs, 1091fa105172SSwapnil Jakhade .num_regs = ARRAY_SIZE(pcie_phy_pcs_cmn_regs), 1092fa105172SSwapnil Jakhade }; 1093fa105172SSwapnil Jakhade 1094871002d7SAnil Varughese /* refclk100MHz_32b_PCIe_cmn_pll_ext_ssc */ 10953cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_pcie_cmn_regs_ext_ssc[] = { 1096871002d7SAnil Varughese {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG}, 1097871002d7SAnil Varughese {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG}, 1098871002d7SAnil Varughese {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG}, 1099871002d7SAnil Varughese {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG}, 1100871002d7SAnil Varughese {0x1B1B, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG} 1101871002d7SAnil Varughese }; 1102871002d7SAnil Varughese 1103871002d7SAnil Varughese /* refclk100MHz_32b_PCIe_ln_ext_ssc */ 11043cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_pcie_ln_regs_ext_ssc[] = { 1105871002d7SAnil Varughese {0x813E, SIERRA_CLKPATHCTRL_TMR_PREG}, 1106871002d7SAnil Varughese {0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG}, 1107871002d7SAnil Varughese {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG}, 1108871002d7SAnil Varughese {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG}, 1109871002d7SAnil Varughese {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG}, 1110871002d7SAnil Varughese {0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG}, 1111871002d7SAnil Varughese {0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG} 1112871002d7SAnil Varughese }; 1113871002d7SAnil Varughese 1114078e9e92SSwapnil Jakhade static struct cdns_sierra_vals pcie_100_ext_ssc_cmn_vals = { 1115078e9e92SSwapnil Jakhade .reg_pairs = cdns_pcie_cmn_regs_ext_ssc, 1116078e9e92SSwapnil Jakhade .num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc), 1117078e9e92SSwapnil Jakhade }; 1118078e9e92SSwapnil Jakhade 1119078e9e92SSwapnil Jakhade static struct cdns_sierra_vals pcie_100_ext_ssc_ln_vals = { 1120078e9e92SSwapnil Jakhade .reg_pairs = cdns_pcie_ln_regs_ext_ssc, 1121078e9e92SSwapnil Jakhade .num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc), 1122078e9e92SSwapnil Jakhade }; 1123078e9e92SSwapnil Jakhade 1124871002d7SAnil Varughese /* refclk100MHz_20b_USB_cmn_pll_ext_ssc */ 11253cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_usb_cmn_regs_ext_ssc[] = { 1126871002d7SAnil Varughese {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG}, 1127871002d7SAnil Varughese {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG}, 1128871002d7SAnil Varughese {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG}, 1129871002d7SAnil Varughese {0x0000, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG} 1130871002d7SAnil Varughese }; 1131871002d7SAnil Varughese 1132871002d7SAnil Varughese /* refclk100MHz_20b_USB_ln_ext_ssc */ 11333cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_usb_ln_regs_ext_ssc[] = { 1134aead5fd6SKishon Vijay Abraham I {0xFE0A, SIERRA_DET_STANDEC_A_PREG}, 1135aead5fd6SKishon Vijay Abraham I {0x000F, SIERRA_DET_STANDEC_B_PREG}, 11362bcf14caSSanket Parmar {0x55A5, SIERRA_DET_STANDEC_C_PREG}, 1137871002d7SAnil Varughese {0x69ad, SIERRA_DET_STANDEC_D_PREG}, 1138aead5fd6SKishon Vijay Abraham I {0x0241, SIERRA_DET_STANDEC_E_PREG}, 11392bcf14caSSanket Parmar {0x0110, SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG}, 1140871002d7SAnil Varughese {0x0014, SIERRA_PSM_A0IN_TMR_PREG}, 1141aead5fd6SKishon Vijay Abraham I {0xCF00, SIERRA_PSM_DIAG_PREG}, 1142aead5fd6SKishon Vijay Abraham I {0x001F, SIERRA_PSC_TX_A0_PREG}, 1143aead5fd6SKishon Vijay Abraham I {0x0007, SIERRA_PSC_TX_A1_PREG}, 1144aead5fd6SKishon Vijay Abraham I {0x0003, SIERRA_PSC_TX_A2_PREG}, 1145aead5fd6SKishon Vijay Abraham I {0x0003, SIERRA_PSC_TX_A3_PREG}, 1146aead5fd6SKishon Vijay Abraham I {0x0FFF, SIERRA_PSC_RX_A0_PREG}, 11472bcf14caSSanket Parmar {0x0003, SIERRA_PSC_RX_A1_PREG}, 1148aead5fd6SKishon Vijay Abraham I {0x0003, SIERRA_PSC_RX_A2_PREG}, 1149aead5fd6SKishon Vijay Abraham I {0x0001, SIERRA_PSC_RX_A3_PREG}, 1150aead5fd6SKishon Vijay Abraham I {0x0001, SIERRA_PLLCTRL_SUBRATE_PREG}, 1151aead5fd6SKishon Vijay Abraham I {0x0406, SIERRA_PLLCTRL_GEN_D_PREG}, 1152871002d7SAnil Varughese {0x5233, SIERRA_PLLCTRL_CPGAIN_MODE_PREG}, 1153871002d7SAnil Varughese {0x00CA, SIERRA_CLKPATH_BIASTRIM_PREG}, 1154871002d7SAnil Varughese {0x2512, SIERRA_DFE_BIASTRIM_PREG}, 1155aead5fd6SKishon Vijay Abraham I {0x0000, SIERRA_DRVCTRL_ATTEN_PREG}, 11562bcf14caSSanket Parmar {0x823E, SIERRA_CLKPATHCTRL_TMR_PREG}, 11572bcf14caSSanket Parmar {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG}, 11582bcf14caSSanket Parmar {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG}, 1159aead5fd6SKishon Vijay Abraham I {0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG}, 11602bcf14caSSanket Parmar {0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG}, 1161aead5fd6SKishon Vijay Abraham I {0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG}, 1162871002d7SAnil Varughese {0x0000, SIERRA_CREQ_EQ_CTRL_PREG}, 11632bcf14caSSanket Parmar {0x0000, SIERRA_CREQ_SPARE_PREG}, 1164871002d7SAnil Varughese {0xCC44, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG}, 11652bcf14caSSanket Parmar {0x8452, SIERRA_CTLELUT_CTRL_PREG}, 11662bcf14caSSanket Parmar {0x4121, SIERRA_DFE_ECMP_RATESEL_PREG}, 11672bcf14caSSanket Parmar {0x4121, SIERRA_DFE_SMP_RATESEL_PREG}, 11682bcf14caSSanket Parmar {0x0003, SIERRA_DEQ_PHALIGN_CTRL}, 1169871002d7SAnil Varughese {0x3200, SIERRA_DEQ_CONCUR_CTRL1_PREG}, 1170871002d7SAnil Varughese {0x5064, SIERRA_DEQ_CONCUR_CTRL2_PREG}, 1171871002d7SAnil Varughese {0x0030, SIERRA_DEQ_EPIPWR_CTRL2_PREG}, 1172871002d7SAnil Varughese {0x0048, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG}, 1173871002d7SAnil Varughese {0x5A5A, SIERRA_DEQ_ERRCMP_CTRL_PREG}, 1174871002d7SAnil Varughese {0x02F5, SIERRA_DEQ_OFFSET_CTRL_PREG}, 1175871002d7SAnil Varughese {0x02F5, SIERRA_DEQ_GAIN_CTRL_PREG}, 11762bcf14caSSanket Parmar {0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG}, 1177871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT0}, 1178871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT1}, 1179871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT2}, 1180871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT3}, 1181871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT4}, 1182871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT5}, 1183871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT6}, 1184871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT7}, 1185871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT8}, 1186871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT9}, 1187871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT10}, 1188871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT11}, 1189871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT12}, 1190871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT13}, 1191871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT14}, 1192871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT15}, 1193871002d7SAnil Varughese {0x0014, SIERRA_DEQ_GLUT16}, 1194871002d7SAnil Varughese {0x0BAE, SIERRA_DEQ_ALUT0}, 1195871002d7SAnil Varughese {0x0AEB, SIERRA_DEQ_ALUT1}, 1196871002d7SAnil Varughese {0x0A28, SIERRA_DEQ_ALUT2}, 1197871002d7SAnil Varughese {0x0965, SIERRA_DEQ_ALUT3}, 1198871002d7SAnil Varughese {0x08A2, SIERRA_DEQ_ALUT4}, 1199871002d7SAnil Varughese {0x07DF, SIERRA_DEQ_ALUT5}, 1200871002d7SAnil Varughese {0x071C, SIERRA_DEQ_ALUT6}, 1201871002d7SAnil Varughese {0x0659, SIERRA_DEQ_ALUT7}, 1202871002d7SAnil Varughese {0x0596, SIERRA_DEQ_ALUT8}, 1203871002d7SAnil Varughese {0x0514, SIERRA_DEQ_ALUT9}, 1204871002d7SAnil Varughese {0x0492, SIERRA_DEQ_ALUT10}, 1205871002d7SAnil Varughese {0x0410, SIERRA_DEQ_ALUT11}, 1206871002d7SAnil Varughese {0x038E, SIERRA_DEQ_ALUT12}, 1207871002d7SAnil Varughese {0x030C, SIERRA_DEQ_ALUT13}, 1208871002d7SAnil Varughese {0x03F4, SIERRA_DEQ_DFETAP_CTRL_PREG}, 1209871002d7SAnil Varughese {0x0001, SIERRA_DFE_EN_1010_IGNORE_PREG}, 1210871002d7SAnil Varughese {0x3C01, SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG}, 1211871002d7SAnil Varughese {0x3C40, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG}, 1212871002d7SAnil Varughese {0x1C08, SIERRA_DEQ_TAU_CTRL2_PREG}, 1213871002d7SAnil Varughese {0x0033, SIERRA_DEQ_PICTRL_PREG}, 1214871002d7SAnil Varughese {0x0400, SIERRA_CPICAL_TMRVAL_MODE1_PREG}, 1215871002d7SAnil Varughese {0x0330, SIERRA_CPICAL_TMRVAL_MODE0_PREG}, 1216871002d7SAnil Varughese {0x01FF, SIERRA_CPICAL_PICNT_MODE1_PREG}, 1217aead5fd6SKishon Vijay Abraham I {0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG}, 1218871002d7SAnil Varughese {0x3232, SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG}, 1219871002d7SAnil Varughese {0x0005, SIERRA_LFPSDET_SUPPORT_PREG}, 1220aead5fd6SKishon Vijay Abraham I {0x000F, SIERRA_LFPSFILT_NS_PREG}, 1221aead5fd6SKishon Vijay Abraham I {0x0009, SIERRA_LFPSFILT_RD_PREG}, 1222aead5fd6SKishon Vijay Abraham I {0x0001, SIERRA_LFPSFILT_MP_PREG}, 12232bcf14caSSanket Parmar {0x6013, SIERRA_SIGDET_SUPPORT_PREG}, 1224aead5fd6SKishon Vijay Abraham I {0x8013, SIERRA_SDFILT_H2L_A_PREG}, 1225871002d7SAnil Varughese {0x8009, SIERRA_SDFILT_L2H_PREG}, 1226871002d7SAnil Varughese {0x0024, SIERRA_RXBUFFER_CTLECTRL_PREG}, 1227871002d7SAnil Varughese {0x0020, SIERRA_RXBUFFER_RCDFECTRL_PREG}, 1228871002d7SAnil Varughese {0x4243, SIERRA_RXBUFFER_DFECTRL_PREG} 122944d30d62SAlan Douglas }; 123044d30d62SAlan Douglas 1231078e9e92SSwapnil Jakhade static struct cdns_sierra_vals usb_100_ext_ssc_cmn_vals = { 1232078e9e92SSwapnil Jakhade .reg_pairs = cdns_usb_cmn_regs_ext_ssc, 1233078e9e92SSwapnil Jakhade .num_regs = ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc), 1234078e9e92SSwapnil Jakhade }; 1235078e9e92SSwapnil Jakhade 1236078e9e92SSwapnil Jakhade static struct cdns_sierra_vals usb_100_ext_ssc_ln_vals = { 1237078e9e92SSwapnil Jakhade .reg_pairs = cdns_usb_ln_regs_ext_ssc, 1238078e9e92SSwapnil Jakhade .num_regs = ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc), 1239078e9e92SSwapnil Jakhade }; 1240078e9e92SSwapnil Jakhade 124144d30d62SAlan Douglas static const struct cdns_sierra_data cdns_map_sierra = { 1242078e9e92SSwapnil Jakhade .id_value = SIERRA_MACRO_ID, 1243078e9e92SSwapnil Jakhade .block_offset_shift = 0x2, 1244078e9e92SSwapnil Jakhade .reg_offset_shift = 0x2, 1245fa105172SSwapnil Jakhade .pcs_cmn_vals = { 1246fa105172SSwapnil Jakhade [TYPE_PCIE] = { 1247fa105172SSwapnil Jakhade [TYPE_NONE] = { 1248fa105172SSwapnil Jakhade [EXTERNAL_SSC] = &pcie_phy_pcs_cmn_vals, 1249fa105172SSwapnil Jakhade }, 1250fa105172SSwapnil Jakhade }, 1251fa105172SSwapnil Jakhade }, 1252078e9e92SSwapnil Jakhade .pma_cmn_vals = { 1253078e9e92SSwapnil Jakhade [TYPE_PCIE] = { 1254078e9e92SSwapnil Jakhade [TYPE_NONE] = { 1255078e9e92SSwapnil Jakhade [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals, 1256078e9e92SSwapnil Jakhade }, 1257078e9e92SSwapnil Jakhade }, 1258078e9e92SSwapnil Jakhade [TYPE_USB] = { 1259078e9e92SSwapnil Jakhade [TYPE_NONE] = { 1260078e9e92SSwapnil Jakhade [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals, 1261078e9e92SSwapnil Jakhade }, 1262078e9e92SSwapnil Jakhade }, 1263078e9e92SSwapnil Jakhade }, 1264078e9e92SSwapnil Jakhade .pma_ln_vals = { 1265078e9e92SSwapnil Jakhade [TYPE_PCIE] = { 1266078e9e92SSwapnil Jakhade [TYPE_NONE] = { 1267078e9e92SSwapnil Jakhade [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals, 1268078e9e92SSwapnil Jakhade }, 1269078e9e92SSwapnil Jakhade }, 1270078e9e92SSwapnil Jakhade [TYPE_USB] = { 1271078e9e92SSwapnil Jakhade [TYPE_NONE] = { 1272078e9e92SSwapnil Jakhade [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals, 1273078e9e92SSwapnil Jakhade }, 1274078e9e92SSwapnil Jakhade }, 1275078e9e92SSwapnil Jakhade }, 127644d30d62SAlan Douglas }; 127744d30d62SAlan Douglas 1278367da978SKishon Vijay Abraham I static const struct cdns_sierra_data cdns_ti_map_sierra = { 1279078e9e92SSwapnil Jakhade .id_value = SIERRA_MACRO_ID, 1280078e9e92SSwapnil Jakhade .block_offset_shift = 0x0, 1281078e9e92SSwapnil Jakhade .reg_offset_shift = 0x1, 1282fa105172SSwapnil Jakhade .pcs_cmn_vals = { 1283fa105172SSwapnil Jakhade [TYPE_PCIE] = { 1284fa105172SSwapnil Jakhade [TYPE_NONE] = { 1285fa105172SSwapnil Jakhade [EXTERNAL_SSC] = &pcie_phy_pcs_cmn_vals, 1286fa105172SSwapnil Jakhade }, 1287fa105172SSwapnil Jakhade }, 1288fa105172SSwapnil Jakhade }, 1289078e9e92SSwapnil Jakhade .pma_cmn_vals = { 1290078e9e92SSwapnil Jakhade [TYPE_PCIE] = { 1291078e9e92SSwapnil Jakhade [TYPE_NONE] = { 1292078e9e92SSwapnil Jakhade [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals, 1293078e9e92SSwapnil Jakhade }, 1294078e9e92SSwapnil Jakhade }, 1295078e9e92SSwapnil Jakhade [TYPE_USB] = { 1296078e9e92SSwapnil Jakhade [TYPE_NONE] = { 1297078e9e92SSwapnil Jakhade [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals, 1298078e9e92SSwapnil Jakhade }, 1299078e9e92SSwapnil Jakhade }, 1300078e9e92SSwapnil Jakhade }, 1301078e9e92SSwapnil Jakhade .pma_ln_vals = { 1302078e9e92SSwapnil Jakhade [TYPE_PCIE] = { 1303078e9e92SSwapnil Jakhade [TYPE_NONE] = { 1304078e9e92SSwapnil Jakhade [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals, 1305078e9e92SSwapnil Jakhade }, 1306078e9e92SSwapnil Jakhade }, 1307078e9e92SSwapnil Jakhade [TYPE_USB] = { 1308078e9e92SSwapnil Jakhade [TYPE_NONE] = { 1309078e9e92SSwapnil Jakhade [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals, 1310078e9e92SSwapnil Jakhade }, 1311078e9e92SSwapnil Jakhade }, 1312078e9e92SSwapnil Jakhade }, 1313367da978SKishon Vijay Abraham I }; 1314367da978SKishon Vijay Abraham I 131544d30d62SAlan Douglas static const struct of_device_id cdns_sierra_id_table[] = { 131644d30d62SAlan Douglas { 131744d30d62SAlan Douglas .compatible = "cdns,sierra-phy-t0", 131844d30d62SAlan Douglas .data = &cdns_map_sierra, 131944d30d62SAlan Douglas }, 1320367da978SKishon Vijay Abraham I { 1321367da978SKishon Vijay Abraham I .compatible = "ti,sierra-phy-t0", 1322367da978SKishon Vijay Abraham I .data = &cdns_ti_map_sierra, 1323367da978SKishon Vijay Abraham I }, 132444d30d62SAlan Douglas {} 132544d30d62SAlan Douglas }; 132644d30d62SAlan Douglas MODULE_DEVICE_TABLE(of, cdns_sierra_id_table); 132744d30d62SAlan Douglas 132844d30d62SAlan Douglas static struct platform_driver cdns_sierra_driver = { 132944d30d62SAlan Douglas .probe = cdns_sierra_phy_probe, 133044d30d62SAlan Douglas .remove = cdns_sierra_phy_remove, 133144d30d62SAlan Douglas .driver = { 133244d30d62SAlan Douglas .name = "cdns-sierra-phy", 133344d30d62SAlan Douglas .of_match_table = cdns_sierra_id_table, 133444d30d62SAlan Douglas }, 133544d30d62SAlan Douglas }; 133644d30d62SAlan Douglas module_platform_driver(cdns_sierra_driver); 133744d30d62SAlan Douglas 133844d30d62SAlan Douglas MODULE_ALIAS("platform:cdns_sierra"); 133944d30d62SAlan Douglas MODULE_AUTHOR("Cadence Design Systems"); 134044d30d62SAlan Douglas MODULE_DESCRIPTION("CDNS sierra phy driver"); 134144d30d62SAlan Douglas MODULE_LICENSE("GPL v2"); 1342