xref: /linux/drivers/phy/cadence/phy-cadence-sierra.c (revision 1e902b2ae3e9c0873d38b415b2af0811b4897ad4)
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 
148380f5708SKishon Vijay Abraham I #define SIERRA_PHY_CONFIG_CTRL_OFFSET(block_offset)	\
149380f5708SKishon Vijay Abraham I 				      (0xc000 << (block_offset))
150380f5708SKishon Vijay Abraham I #define SIERRA_PHY_PLL_CFG				0xe
15144d30d62SAlan Douglas 
15244d30d62SAlan Douglas #define SIERRA_MACRO_ID					0x00007364
153a43f72aeSKishon Vijay Abraham I #define SIERRA_MAX_LANES				16
154adc4bd6fSKishon Vijay Abraham I #define PLL_LOCK_TIME					100000
15544d30d62SAlan Douglas 
15628081b72SKishon Vijay Abraham I #define CDNS_SIERRA_OUTPUT_CLOCKS			2
15728081b72SKishon Vijay Abraham I #define CDNS_SIERRA_INPUT_CLOCKS			5
158a0c30cd7SKishon Vijay Abraham I enum cdns_sierra_clock_input {
159a0c30cd7SKishon Vijay Abraham I 	PHY_CLK,
160a0c30cd7SKishon Vijay Abraham I 	CMN_REFCLK_DIG_DIV,
161a0c30cd7SKishon Vijay Abraham I 	CMN_REFCLK1_DIG_DIV,
16228081b72SKishon Vijay Abraham I 	PLL0_REFCLK,
16328081b72SKishon Vijay Abraham I 	PLL1_REFCLK,
164a0c30cd7SKishon Vijay Abraham I };
165a0c30cd7SKishon Vijay Abraham I 
16628081b72SKishon Vijay Abraham I #define SIERRA_NUM_CMN_PLLC				2
16728081b72SKishon Vijay Abraham I #define SIERRA_NUM_CMN_PLLC_PARENTS			2
16828081b72SKishon Vijay Abraham I 
169380f5708SKishon Vijay Abraham I static const struct reg_field macro_id_type =
170380f5708SKishon Vijay Abraham I 				REG_FIELD(SIERRA_MACRO_ID_REG, 0, 15);
171380f5708SKishon Vijay Abraham I static const struct reg_field phy_pll_cfg_1 =
172380f5708SKishon Vijay Abraham I 				REG_FIELD(SIERRA_PHY_PLL_CFG, 1, 1);
173adc4bd6fSKishon Vijay Abraham I static const struct reg_field pllctrl_lock =
174adc4bd6fSKishon Vijay Abraham I 				REG_FIELD(SIERRA_PLLCTRL_STATUS_PREG, 0, 0);
175380f5708SKishon Vijay Abraham I 
17628081b72SKishon Vijay Abraham I static const char * const clk_names[] = {
17728081b72SKishon Vijay Abraham I 	[CDNS_SIERRA_PLL_CMNLC] = "pll_cmnlc",
17828081b72SKishon Vijay Abraham I 	[CDNS_SIERRA_PLL_CMNLC1] = "pll_cmnlc1",
17928081b72SKishon Vijay Abraham I };
18028081b72SKishon Vijay Abraham I 
18128081b72SKishon Vijay Abraham I enum cdns_sierra_cmn_plllc {
18228081b72SKishon Vijay Abraham I 	CMN_PLLLC,
18328081b72SKishon Vijay Abraham I 	CMN_PLLLC1,
18428081b72SKishon Vijay Abraham I };
18528081b72SKishon Vijay Abraham I 
18628081b72SKishon Vijay Abraham I struct cdns_sierra_pll_mux_reg_fields {
18728081b72SKishon Vijay Abraham I 	struct reg_field	pfdclk_sel_preg;
18828081b72SKishon Vijay Abraham I 	struct reg_field	plllc1en_field;
18928081b72SKishon Vijay Abraham I 	struct reg_field	termen_field;
19028081b72SKishon Vijay Abraham I };
19128081b72SKishon Vijay Abraham I 
19228081b72SKishon Vijay Abraham I static const struct cdns_sierra_pll_mux_reg_fields cmn_plllc_pfdclk1_sel_preg[] = {
19328081b72SKishon Vijay Abraham I 	[CMN_PLLLC] = {
19428081b72SKishon Vijay Abraham I 		.pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC_GEN_PREG, 1, 1),
19528081b72SKishon Vijay Abraham I 		.plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 8, 8),
19628081b72SKishon Vijay Abraham I 		.termen_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 0, 0),
19728081b72SKishon Vijay Abraham I 	},
19828081b72SKishon Vijay Abraham I 	[CMN_PLLLC1] = {
19928081b72SKishon Vijay Abraham I 		.pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC1_GEN_PREG, 1, 1),
20028081b72SKishon Vijay Abraham I 		.plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 8, 8),
20128081b72SKishon Vijay Abraham I 		.termen_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 0, 0),
20228081b72SKishon Vijay Abraham I 	},
20328081b72SKishon Vijay Abraham I };
20428081b72SKishon Vijay Abraham I 
20528081b72SKishon Vijay Abraham I struct cdns_sierra_pll_mux {
20628081b72SKishon Vijay Abraham I 	struct clk_hw		hw;
20728081b72SKishon Vijay Abraham I 	struct regmap_field	*pfdclk_sel_preg;
20828081b72SKishon Vijay Abraham I 	struct regmap_field	*plllc1en_field;
20928081b72SKishon Vijay Abraham I 	struct regmap_field	*termen_field;
21028081b72SKishon Vijay Abraham I 	struct clk_init_data	clk_data;
21128081b72SKishon Vijay Abraham I };
21228081b72SKishon Vijay Abraham I 
21328081b72SKishon Vijay Abraham I #define to_cdns_sierra_pll_mux(_hw)	\
21428081b72SKishon Vijay Abraham I 			container_of(_hw, struct cdns_sierra_pll_mux, hw)
21528081b72SKishon Vijay Abraham I 
21628081b72SKishon Vijay Abraham I static const int pll_mux_parent_index[][SIERRA_NUM_CMN_PLLC_PARENTS] = {
21728081b72SKishon Vijay Abraham I 	[CMN_PLLLC] = { PLL0_REFCLK, PLL1_REFCLK },
21828081b72SKishon Vijay Abraham I 	[CMN_PLLLC1] = { PLL1_REFCLK, PLL0_REFCLK },
21928081b72SKishon Vijay Abraham I };
22028081b72SKishon Vijay Abraham I 
22128081b72SKishon Vijay Abraham I static u32 cdns_sierra_pll_mux_table[] = { 0, 1 };
22228081b72SKishon Vijay Abraham I 
223078e9e92SSwapnil Jakhade enum cdns_sierra_phy_type {
224078e9e92SSwapnil Jakhade 	TYPE_NONE,
225078e9e92SSwapnil Jakhade 	TYPE_PCIE,
226078e9e92SSwapnil Jakhade 	TYPE_USB
227078e9e92SSwapnil Jakhade };
228078e9e92SSwapnil Jakhade 
229078e9e92SSwapnil Jakhade enum cdns_sierra_ssc_mode {
230078e9e92SSwapnil Jakhade 	NO_SSC,
231078e9e92SSwapnil Jakhade 	EXTERNAL_SSC,
232078e9e92SSwapnil Jakhade 	INTERNAL_SSC
233078e9e92SSwapnil Jakhade };
234078e9e92SSwapnil Jakhade 
23544d30d62SAlan Douglas struct cdns_sierra_inst {
23644d30d62SAlan Douglas 	struct phy *phy;
237078e9e92SSwapnil Jakhade 	enum cdns_sierra_phy_type phy_type;
23844d30d62SAlan Douglas 	u32 num_lanes;
23944d30d62SAlan Douglas 	u32 mlane;
24044d30d62SAlan Douglas 	struct reset_control *lnk_rst;
241*1e902b2aSSwapnil Jakhade 	enum cdns_sierra_ssc_mode ssc_mode;
24244d30d62SAlan Douglas };
24344d30d62SAlan Douglas 
24444d30d62SAlan Douglas struct cdns_reg_pairs {
24544d30d62SAlan Douglas 	u16 val;
24644d30d62SAlan Douglas 	u32 off;
24744d30d62SAlan Douglas };
24844d30d62SAlan Douglas 
249078e9e92SSwapnil Jakhade struct cdns_sierra_vals {
250078e9e92SSwapnil Jakhade 	const struct cdns_reg_pairs *reg_pairs;
251078e9e92SSwapnil Jakhade 	u32 num_regs;
252078e9e92SSwapnil Jakhade };
253078e9e92SSwapnil Jakhade 
25444d30d62SAlan Douglas struct cdns_sierra_data {
25544d30d62SAlan Douglas 	u32 id_value;
256380f5708SKishon Vijay Abraham I 	u8 block_offset_shift;
257380f5708SKishon Vijay Abraham I 	u8 reg_offset_shift;
258078e9e92SSwapnil Jakhade 	struct cdns_sierra_vals *pma_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
259078e9e92SSwapnil Jakhade 					     [NUM_SSC_MODE];
260078e9e92SSwapnil Jakhade 	struct cdns_sierra_vals *pma_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
261078e9e92SSwapnil Jakhade 					    [NUM_SSC_MODE];
26244d30d62SAlan Douglas };
26344d30d62SAlan Douglas 
264380f5708SKishon Vijay Abraham I struct cdns_regmap_cdb_context {
26544d30d62SAlan Douglas 	struct device *dev;
26644d30d62SAlan Douglas 	void __iomem *base;
267380f5708SKishon Vijay Abraham I 	u8 reg_offset_shift;
268380f5708SKishon Vijay Abraham I };
269380f5708SKishon Vijay Abraham I 
270380f5708SKishon Vijay Abraham I struct cdns_sierra_phy {
271380f5708SKishon Vijay Abraham I 	struct device *dev;
272380f5708SKishon Vijay Abraham I 	struct regmap *regmap;
273c3c11d55SSwapnil Jakhade 	const struct cdns_sierra_data *init_data;
27444d30d62SAlan Douglas 	struct cdns_sierra_inst phys[SIERRA_MAX_LANES];
27544d30d62SAlan Douglas 	struct reset_control *phy_rst;
27644d30d62SAlan Douglas 	struct reset_control *apb_rst;
277380f5708SKishon Vijay Abraham I 	struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES];
278380f5708SKishon Vijay Abraham I 	struct regmap *regmap_phy_config_ctrl;
279380f5708SKishon Vijay Abraham I 	struct regmap *regmap_common_cdb;
280380f5708SKishon Vijay Abraham I 	struct regmap_field *macro_id_type;
281380f5708SKishon Vijay Abraham I 	struct regmap_field *phy_pll_cfg_1;
282adc4bd6fSKishon Vijay Abraham I 	struct regmap_field *pllctrl_lock[SIERRA_MAX_LANES];
28328081b72SKishon Vijay Abraham I 	struct regmap_field *cmn_refrcv_refclk_plllc1en_preg[SIERRA_NUM_CMN_PLLC];
28428081b72SKishon Vijay Abraham I 	struct regmap_field *cmn_refrcv_refclk_termen_preg[SIERRA_NUM_CMN_PLLC];
28528081b72SKishon Vijay Abraham I 	struct regmap_field *cmn_plllc_pfdclk1_sel_preg[SIERRA_NUM_CMN_PLLC];
286a0c30cd7SKishon Vijay Abraham I 	struct clk *input_clks[CDNS_SIERRA_INPUT_CLOCKS];
28744d30d62SAlan Douglas 	int nsubnodes;
288a43f72aeSKishon Vijay Abraham I 	u32 num_lanes;
28944d30d62SAlan Douglas 	bool autoconf;
29028081b72SKishon Vijay Abraham I 	struct clk_onecell_data clk_data;
29128081b72SKishon Vijay Abraham I 	struct clk *output_clks[CDNS_SIERRA_OUTPUT_CLOCKS];
29244d30d62SAlan Douglas };
29344d30d62SAlan Douglas 
294380f5708SKishon Vijay Abraham I static int cdns_regmap_write(void *context, unsigned int reg, unsigned int val)
295380f5708SKishon Vijay Abraham I {
296380f5708SKishon Vijay Abraham I 	struct cdns_regmap_cdb_context *ctx = context;
297380f5708SKishon Vijay Abraham I 	u32 offset = reg << ctx->reg_offset_shift;
298380f5708SKishon Vijay Abraham I 
299380f5708SKishon Vijay Abraham I 	writew(val, ctx->base + offset);
300380f5708SKishon Vijay Abraham I 
301380f5708SKishon Vijay Abraham I 	return 0;
302380f5708SKishon Vijay Abraham I }
303380f5708SKishon Vijay Abraham I 
304380f5708SKishon Vijay Abraham I static int cdns_regmap_read(void *context, unsigned int reg, unsigned int *val)
305380f5708SKishon Vijay Abraham I {
306380f5708SKishon Vijay Abraham I 	struct cdns_regmap_cdb_context *ctx = context;
307380f5708SKishon Vijay Abraham I 	u32 offset = reg << ctx->reg_offset_shift;
308380f5708SKishon Vijay Abraham I 
309380f5708SKishon Vijay Abraham I 	*val = readw(ctx->base + offset);
310380f5708SKishon Vijay Abraham I 	return 0;
311380f5708SKishon Vijay Abraham I }
312380f5708SKishon Vijay Abraham I 
313380f5708SKishon Vijay Abraham I #define SIERRA_LANE_CDB_REGMAP_CONF(n) \
314380f5708SKishon Vijay Abraham I { \
315380f5708SKishon Vijay Abraham I 	.name = "sierra_lane" n "_cdb", \
316380f5708SKishon Vijay Abraham I 	.reg_stride = 1, \
317380f5708SKishon Vijay Abraham I 	.fast_io = true, \
318380f5708SKishon Vijay Abraham I 	.reg_write = cdns_regmap_write, \
319380f5708SKishon Vijay Abraham I 	.reg_read = cdns_regmap_read, \
320380f5708SKishon Vijay Abraham I }
321380f5708SKishon Vijay Abraham I 
3223cfb0e8eSRikard Falkeborn static const struct regmap_config cdns_sierra_lane_cdb_config[] = {
323380f5708SKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("0"),
324380f5708SKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("1"),
325380f5708SKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("2"),
326380f5708SKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("3"),
327a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("4"),
328a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("5"),
329a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("6"),
330a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("7"),
331a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("8"),
332a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("9"),
333a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("10"),
334a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("11"),
335a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("12"),
336a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("13"),
337a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("14"),
338a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("15"),
339380f5708SKishon Vijay Abraham I };
340380f5708SKishon Vijay Abraham I 
3413cfb0e8eSRikard Falkeborn static const struct regmap_config cdns_sierra_common_cdb_config = {
342380f5708SKishon Vijay Abraham I 	.name = "sierra_common_cdb",
343380f5708SKishon Vijay Abraham I 	.reg_stride = 1,
344380f5708SKishon Vijay Abraham I 	.fast_io = true,
345380f5708SKishon Vijay Abraham I 	.reg_write = cdns_regmap_write,
346380f5708SKishon Vijay Abraham I 	.reg_read = cdns_regmap_read,
347380f5708SKishon Vijay Abraham I };
348380f5708SKishon Vijay Abraham I 
3493cfb0e8eSRikard Falkeborn static const struct regmap_config cdns_sierra_phy_config_ctrl_config = {
350380f5708SKishon Vijay Abraham I 	.name = "sierra_phy_config_ctrl",
351380f5708SKishon Vijay Abraham I 	.reg_stride = 1,
352380f5708SKishon Vijay Abraham I 	.fast_io = true,
353380f5708SKishon Vijay Abraham I 	.reg_write = cdns_regmap_write,
354380f5708SKishon Vijay Abraham I 	.reg_read = cdns_regmap_read,
355380f5708SKishon Vijay Abraham I };
356380f5708SKishon Vijay Abraham I 
357cedcc2e2SKishon Vijay Abraham I static int cdns_sierra_phy_init(struct phy *gphy)
35844d30d62SAlan Douglas {
35944d30d62SAlan Douglas 	struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
36044d30d62SAlan Douglas 	struct cdns_sierra_phy *phy = dev_get_drvdata(gphy->dev.parent);
361078e9e92SSwapnil Jakhade 	const struct cdns_sierra_data *init_data = phy->init_data;
362078e9e92SSwapnil Jakhade 	struct cdns_sierra_vals *pma_cmn_vals, *pma_ln_vals;
363078e9e92SSwapnil Jakhade 	enum cdns_sierra_phy_type phy_type = ins->phy_type;
364*1e902b2aSSwapnil Jakhade 	enum cdns_sierra_ssc_mode ssc = ins->ssc_mode;
365078e9e92SSwapnil Jakhade 	const struct cdns_reg_pairs *reg_pairs;
36680f96fb1SColin Ian King 	struct regmap *regmap;
367078e9e92SSwapnil Jakhade 	u32 num_regs;
36844d30d62SAlan Douglas 	int i, j;
36944d30d62SAlan Douglas 
370cedcc2e2SKishon Vijay Abraham I 	/* Initialise the PHY registers, unless auto configured */
371cedcc2e2SKishon Vijay Abraham I 	if (phy->autoconf)
372cedcc2e2SKishon Vijay Abraham I 		return 0;
373cedcc2e2SKishon Vijay Abraham I 
374a0c30cd7SKishon Vijay Abraham I 	clk_set_rate(phy->input_clks[CMN_REFCLK_DIG_DIV], 25000000);
375a0c30cd7SKishon Vijay Abraham I 	clk_set_rate(phy->input_clks[CMN_REFCLK1_DIG_DIV], 25000000);
376078e9e92SSwapnil Jakhade 
377078e9e92SSwapnil Jakhade 	/* PMA common registers configurations */
378078e9e92SSwapnil Jakhade 	pma_cmn_vals = init_data->pma_cmn_vals[phy_type][TYPE_NONE][ssc];
379078e9e92SSwapnil Jakhade 	if (pma_cmn_vals) {
380078e9e92SSwapnil Jakhade 		reg_pairs = pma_cmn_vals->reg_pairs;
381078e9e92SSwapnil Jakhade 		num_regs = pma_cmn_vals->num_regs;
382078e9e92SSwapnil Jakhade 		regmap = phy->regmap_common_cdb;
383078e9e92SSwapnil Jakhade 		for (i = 0; i < num_regs; i++)
384078e9e92SSwapnil Jakhade 			regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
38544d30d62SAlan Douglas 	}
386871002d7SAnil Varughese 
387078e9e92SSwapnil Jakhade 	/* PMA lane registers configurations */
388078e9e92SSwapnil Jakhade 	pma_ln_vals = init_data->pma_ln_vals[phy_type][TYPE_NONE][ssc];
389078e9e92SSwapnil Jakhade 	if (pma_ln_vals) {
390078e9e92SSwapnil Jakhade 		reg_pairs = pma_ln_vals->reg_pairs;
391078e9e92SSwapnil Jakhade 		num_regs = pma_ln_vals->num_regs;
392380f5708SKishon Vijay Abraham I 		for (i = 0; i < ins->num_lanes; i++) {
393380f5708SKishon Vijay Abraham I 			regmap = phy->regmap_lane_cdb[i + ins->mlane];
394078e9e92SSwapnil Jakhade 			for (j = 0; j < num_regs; j++)
395078e9e92SSwapnil Jakhade 				regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val);
396380f5708SKishon Vijay Abraham I 		}
397380f5708SKishon Vijay Abraham I 	}
398cedcc2e2SKishon Vijay Abraham I 
399cedcc2e2SKishon Vijay Abraham I 	return 0;
40044d30d62SAlan Douglas }
40144d30d62SAlan Douglas 
40244d30d62SAlan Douglas static int cdns_sierra_phy_on(struct phy *gphy)
40344d30d62SAlan Douglas {
404adc4bd6fSKishon Vijay Abraham I 	struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent);
40544d30d62SAlan Douglas 	struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
406adc4bd6fSKishon Vijay Abraham I 	struct device *dev = sp->dev;
407adc4bd6fSKishon Vijay Abraham I 	u32 val;
408adc4bd6fSKishon Vijay Abraham I 	int ret;
40944d30d62SAlan Douglas 
4105b4f5757SKishon Vijay Abraham I 	ret = reset_control_deassert(sp->phy_rst);
4115b4f5757SKishon Vijay Abraham I 	if (ret) {
4125b4f5757SKishon Vijay Abraham I 		dev_err(dev, "Failed to take the PHY out of reset\n");
4135b4f5757SKishon Vijay Abraham I 		return ret;
4145b4f5757SKishon Vijay Abraham I 	}
4155b4f5757SKishon Vijay Abraham I 
41644d30d62SAlan Douglas 	/* Take the PHY lane group out of reset */
417adc4bd6fSKishon Vijay Abraham I 	ret = reset_control_deassert(ins->lnk_rst);
418adc4bd6fSKishon Vijay Abraham I 	if (ret) {
419adc4bd6fSKishon Vijay Abraham I 		dev_err(dev, "Failed to take the PHY lane out of reset\n");
420adc4bd6fSKishon Vijay Abraham I 		return ret;
421adc4bd6fSKishon Vijay Abraham I 	}
422adc4bd6fSKishon Vijay Abraham I 
423adc4bd6fSKishon Vijay Abraham I 	ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane],
424adc4bd6fSKishon Vijay Abraham I 					     val, val, 1000, PLL_LOCK_TIME);
425adc4bd6fSKishon Vijay Abraham I 	if (ret < 0)
426adc4bd6fSKishon Vijay Abraham I 		dev_err(dev, "PLL lock of lane failed\n");
427adc4bd6fSKishon Vijay Abraham I 
428adc4bd6fSKishon Vijay Abraham I 	return ret;
42944d30d62SAlan Douglas }
43044d30d62SAlan Douglas 
43144d30d62SAlan Douglas static int cdns_sierra_phy_off(struct phy *gphy)
43244d30d62SAlan Douglas {
43344d30d62SAlan Douglas 	struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
43444d30d62SAlan Douglas 
43544d30d62SAlan Douglas 	return reset_control_assert(ins->lnk_rst);
43644d30d62SAlan Douglas }
43744d30d62SAlan Douglas 
4387904e15bSRoger Quadros static int cdns_sierra_phy_reset(struct phy *gphy)
4397904e15bSRoger Quadros {
4407904e15bSRoger Quadros 	struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent);
4417904e15bSRoger Quadros 
4427904e15bSRoger Quadros 	reset_control_assert(sp->phy_rst);
4437904e15bSRoger Quadros 	reset_control_deassert(sp->phy_rst);
4447904e15bSRoger Quadros 	return 0;
4457904e15bSRoger Quadros };
4467904e15bSRoger Quadros 
44744d30d62SAlan Douglas static const struct phy_ops ops = {
448cedcc2e2SKishon Vijay Abraham I 	.init		= cdns_sierra_phy_init,
44944d30d62SAlan Douglas 	.power_on	= cdns_sierra_phy_on,
45044d30d62SAlan Douglas 	.power_off	= cdns_sierra_phy_off,
4517904e15bSRoger Quadros 	.reset		= cdns_sierra_phy_reset,
45244d30d62SAlan Douglas 	.owner		= THIS_MODULE,
45344d30d62SAlan Douglas };
45444d30d62SAlan Douglas 
45528081b72SKishon Vijay Abraham I static u8 cdns_sierra_pll_mux_get_parent(struct clk_hw *hw)
45628081b72SKishon Vijay Abraham I {
45728081b72SKishon Vijay Abraham I 	struct cdns_sierra_pll_mux *mux = to_cdns_sierra_pll_mux(hw);
45828081b72SKishon Vijay Abraham I 	struct regmap_field *field = mux->pfdclk_sel_preg;
45928081b72SKishon Vijay Abraham I 	unsigned int val;
46028081b72SKishon Vijay Abraham I 
46128081b72SKishon Vijay Abraham I 	regmap_field_read(field, &val);
46228081b72SKishon Vijay Abraham I 	return clk_mux_val_to_index(hw, cdns_sierra_pll_mux_table, 0, val);
46328081b72SKishon Vijay Abraham I }
46428081b72SKishon Vijay Abraham I 
46528081b72SKishon Vijay Abraham I static int cdns_sierra_pll_mux_set_parent(struct clk_hw *hw, u8 index)
46628081b72SKishon Vijay Abraham I {
46728081b72SKishon Vijay Abraham I 	struct cdns_sierra_pll_mux *mux = to_cdns_sierra_pll_mux(hw);
46828081b72SKishon Vijay Abraham I 	struct regmap_field *plllc1en_field = mux->plllc1en_field;
46928081b72SKishon Vijay Abraham I 	struct regmap_field *termen_field = mux->termen_field;
47028081b72SKishon Vijay Abraham I 	struct regmap_field *field = mux->pfdclk_sel_preg;
47128081b72SKishon Vijay Abraham I 	int val, ret;
47228081b72SKishon Vijay Abraham I 
47328081b72SKishon Vijay Abraham I 	ret = regmap_field_write(plllc1en_field, 0);
47428081b72SKishon Vijay Abraham I 	ret |= regmap_field_write(termen_field, 0);
47528081b72SKishon Vijay Abraham I 	if (index == 1) {
47628081b72SKishon Vijay Abraham I 		ret |= regmap_field_write(plllc1en_field, 1);
47728081b72SKishon Vijay Abraham I 		ret |= regmap_field_write(termen_field, 1);
47828081b72SKishon Vijay Abraham I 	}
47928081b72SKishon Vijay Abraham I 
48028081b72SKishon Vijay Abraham I 	val = cdns_sierra_pll_mux_table[index];
48128081b72SKishon Vijay Abraham I 	ret |= regmap_field_write(field, val);
48228081b72SKishon Vijay Abraham I 
48328081b72SKishon Vijay Abraham I 	return ret;
48428081b72SKishon Vijay Abraham I }
48528081b72SKishon Vijay Abraham I 
48628081b72SKishon Vijay Abraham I static const struct clk_ops cdns_sierra_pll_mux_ops = {
48728081b72SKishon Vijay Abraham I 	.set_parent = cdns_sierra_pll_mux_set_parent,
48828081b72SKishon Vijay Abraham I 	.get_parent = cdns_sierra_pll_mux_get_parent,
48928081b72SKishon Vijay Abraham I };
49028081b72SKishon Vijay Abraham I 
49128081b72SKishon Vijay Abraham I static int cdns_sierra_pll_mux_register(struct cdns_sierra_phy *sp,
49228081b72SKishon Vijay Abraham I 					struct regmap_field *pfdclk1_sel_field,
49328081b72SKishon Vijay Abraham I 					struct regmap_field *plllc1en_field,
49428081b72SKishon Vijay Abraham I 					struct regmap_field *termen_field,
49528081b72SKishon Vijay Abraham I 					int clk_index)
49628081b72SKishon Vijay Abraham I {
49728081b72SKishon Vijay Abraham I 	struct cdns_sierra_pll_mux *mux;
49828081b72SKishon Vijay Abraham I 	struct device *dev = sp->dev;
49928081b72SKishon Vijay Abraham I 	struct clk_init_data *init;
50028081b72SKishon Vijay Abraham I 	const char **parent_names;
50128081b72SKishon Vijay Abraham I 	unsigned int num_parents;
50228081b72SKishon Vijay Abraham I 	char clk_name[100];
50328081b72SKishon Vijay Abraham I 	struct clk *clk;
50428081b72SKishon Vijay Abraham I 	int i;
50528081b72SKishon Vijay Abraham I 
50628081b72SKishon Vijay Abraham I 	mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
50728081b72SKishon Vijay Abraham I 	if (!mux)
50828081b72SKishon Vijay Abraham I 		return -ENOMEM;
50928081b72SKishon Vijay Abraham I 
51028081b72SKishon Vijay Abraham I 	num_parents = SIERRA_NUM_CMN_PLLC_PARENTS;
51128081b72SKishon Vijay Abraham I 	parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), GFP_KERNEL);
51228081b72SKishon Vijay Abraham I 	if (!parent_names)
51328081b72SKishon Vijay Abraham I 		return -ENOMEM;
51428081b72SKishon Vijay Abraham I 
51528081b72SKishon Vijay Abraham I 	for (i = 0; i < num_parents; i++) {
51628081b72SKishon Vijay Abraham I 		clk = sp->input_clks[pll_mux_parent_index[clk_index][i]];
51728081b72SKishon Vijay Abraham I 		if (IS_ERR_OR_NULL(clk)) {
51828081b72SKishon Vijay Abraham I 			dev_err(dev, "No parent clock for derived_refclk\n");
51928081b72SKishon Vijay Abraham I 			return PTR_ERR(clk);
52028081b72SKishon Vijay Abraham I 		}
52128081b72SKishon Vijay Abraham I 		parent_names[i] = __clk_get_name(clk);
52228081b72SKishon Vijay Abraham I 	}
52328081b72SKishon Vijay Abraham I 
52428081b72SKishon Vijay Abraham I 	snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), clk_names[clk_index]);
52528081b72SKishon Vijay Abraham I 
52628081b72SKishon Vijay Abraham I 	init = &mux->clk_data;
52728081b72SKishon Vijay Abraham I 
52828081b72SKishon Vijay Abraham I 	init->ops = &cdns_sierra_pll_mux_ops;
52928081b72SKishon Vijay Abraham I 	init->flags = CLK_SET_RATE_NO_REPARENT;
53028081b72SKishon Vijay Abraham I 	init->parent_names = parent_names;
53128081b72SKishon Vijay Abraham I 	init->num_parents = num_parents;
53228081b72SKishon Vijay Abraham I 	init->name = clk_name;
53328081b72SKishon Vijay Abraham I 
53428081b72SKishon Vijay Abraham I 	mux->pfdclk_sel_preg = pfdclk1_sel_field;
53528081b72SKishon Vijay Abraham I 	mux->plllc1en_field = plllc1en_field;
53628081b72SKishon Vijay Abraham I 	mux->termen_field = termen_field;
53728081b72SKishon Vijay Abraham I 	mux->hw.init = init;
53828081b72SKishon Vijay Abraham I 
53928081b72SKishon Vijay Abraham I 	clk = devm_clk_register(dev, &mux->hw);
54028081b72SKishon Vijay Abraham I 	if (IS_ERR(clk))
54128081b72SKishon Vijay Abraham I 		return PTR_ERR(clk);
54228081b72SKishon Vijay Abraham I 
54328081b72SKishon Vijay Abraham I 	sp->output_clks[clk_index] = clk;
54428081b72SKishon Vijay Abraham I 
54528081b72SKishon Vijay Abraham I 	return 0;
54628081b72SKishon Vijay Abraham I }
54728081b72SKishon Vijay Abraham I 
54828081b72SKishon Vijay Abraham I static int cdns_sierra_phy_register_pll_mux(struct cdns_sierra_phy *sp)
54928081b72SKishon Vijay Abraham I {
55028081b72SKishon Vijay Abraham I 	struct regmap_field *pfdclk1_sel_field;
55128081b72SKishon Vijay Abraham I 	struct regmap_field *plllc1en_field;
55228081b72SKishon Vijay Abraham I 	struct regmap_field *termen_field;
55328081b72SKishon Vijay Abraham I 	struct device *dev = sp->dev;
55428081b72SKishon Vijay Abraham I 	int ret = 0, i, clk_index;
55528081b72SKishon Vijay Abraham I 
55628081b72SKishon Vijay Abraham I 	clk_index = CDNS_SIERRA_PLL_CMNLC;
55728081b72SKishon Vijay Abraham I 	for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++, clk_index++) {
55828081b72SKishon Vijay Abraham I 		pfdclk1_sel_field = sp->cmn_plllc_pfdclk1_sel_preg[i];
55928081b72SKishon Vijay Abraham I 		plllc1en_field = sp->cmn_refrcv_refclk_plllc1en_preg[i];
56028081b72SKishon Vijay Abraham I 		termen_field = sp->cmn_refrcv_refclk_termen_preg[i];
56128081b72SKishon Vijay Abraham I 
56228081b72SKishon Vijay Abraham I 		ret = cdns_sierra_pll_mux_register(sp, pfdclk1_sel_field, plllc1en_field,
56328081b72SKishon Vijay Abraham I 						   termen_field, clk_index);
56428081b72SKishon Vijay Abraham I 		if (ret) {
56528081b72SKishon Vijay Abraham I 			dev_err(dev, "Fail to register cmn plllc mux\n");
56628081b72SKishon Vijay Abraham I 			return ret;
56728081b72SKishon Vijay Abraham I 		}
56828081b72SKishon Vijay Abraham I 	}
56928081b72SKishon Vijay Abraham I 
57028081b72SKishon Vijay Abraham I 	return 0;
57128081b72SKishon Vijay Abraham I }
57228081b72SKishon Vijay Abraham I 
57328081b72SKishon Vijay Abraham I static void cdns_sierra_clk_unregister(struct cdns_sierra_phy *sp)
57428081b72SKishon Vijay Abraham I {
57528081b72SKishon Vijay Abraham I 	struct device *dev = sp->dev;
57628081b72SKishon Vijay Abraham I 	struct device_node *node = dev->of_node;
57728081b72SKishon Vijay Abraham I 
57828081b72SKishon Vijay Abraham I 	of_clk_del_provider(node);
57928081b72SKishon Vijay Abraham I }
58028081b72SKishon Vijay Abraham I 
58128081b72SKishon Vijay Abraham I static int cdns_sierra_clk_register(struct cdns_sierra_phy *sp)
58228081b72SKishon Vijay Abraham I {
58328081b72SKishon Vijay Abraham I 	struct device *dev = sp->dev;
58428081b72SKishon Vijay Abraham I 	struct device_node *node = dev->of_node;
58528081b72SKishon Vijay Abraham I 	int ret;
58628081b72SKishon Vijay Abraham I 
58728081b72SKishon Vijay Abraham I 	ret = cdns_sierra_phy_register_pll_mux(sp);
58828081b72SKishon Vijay Abraham I 	if (ret) {
58928081b72SKishon Vijay Abraham I 		dev_err(dev, "Failed to pll mux clocks\n");
59028081b72SKishon Vijay Abraham I 		return ret;
59128081b72SKishon Vijay Abraham I 	}
59228081b72SKishon Vijay Abraham I 
59328081b72SKishon Vijay Abraham I 	sp->clk_data.clks = sp->output_clks;
59428081b72SKishon Vijay Abraham I 	sp->clk_data.clk_num = CDNS_SIERRA_OUTPUT_CLOCKS;
59528081b72SKishon Vijay Abraham I 	ret = of_clk_add_provider(node, of_clk_src_onecell_get, &sp->clk_data);
59628081b72SKishon Vijay Abraham I 	if (ret)
59728081b72SKishon Vijay Abraham I 		dev_err(dev, "Failed to add clock provider: %s\n", node->name);
59828081b72SKishon Vijay Abraham I 
59928081b72SKishon Vijay Abraham I 	return ret;
60028081b72SKishon Vijay Abraham I }
60128081b72SKishon Vijay Abraham I 
60244d30d62SAlan Douglas static int cdns_sierra_get_optional(struct cdns_sierra_inst *inst,
60344d30d62SAlan Douglas 				    struct device_node *child)
60444d30d62SAlan Douglas {
605078e9e92SSwapnil Jakhade 	u32 phy_type;
606078e9e92SSwapnil Jakhade 
60744d30d62SAlan Douglas 	if (of_property_read_u32(child, "reg", &inst->mlane))
60844d30d62SAlan Douglas 		return -EINVAL;
60944d30d62SAlan Douglas 
61044d30d62SAlan Douglas 	if (of_property_read_u32(child, "cdns,num-lanes", &inst->num_lanes))
61144d30d62SAlan Douglas 		return -EINVAL;
61244d30d62SAlan Douglas 
613078e9e92SSwapnil Jakhade 	if (of_property_read_u32(child, "cdns,phy-type", &phy_type))
61444d30d62SAlan Douglas 		return -EINVAL;
61544d30d62SAlan Douglas 
616078e9e92SSwapnil Jakhade 	switch (phy_type) {
617078e9e92SSwapnil Jakhade 	case PHY_TYPE_PCIE:
618078e9e92SSwapnil Jakhade 		inst->phy_type = TYPE_PCIE;
619078e9e92SSwapnil Jakhade 		break;
620078e9e92SSwapnil Jakhade 	case PHY_TYPE_USB3:
621078e9e92SSwapnil Jakhade 		inst->phy_type = TYPE_USB;
622078e9e92SSwapnil Jakhade 		break;
623078e9e92SSwapnil Jakhade 	default:
624078e9e92SSwapnil Jakhade 		return -EINVAL;
625078e9e92SSwapnil Jakhade 	}
626078e9e92SSwapnil Jakhade 
627*1e902b2aSSwapnil Jakhade 	inst->ssc_mode = EXTERNAL_SSC;
628*1e902b2aSSwapnil Jakhade 	of_property_read_u32(child, "cdns,ssc-mode", &inst->ssc_mode);
629*1e902b2aSSwapnil Jakhade 
63044d30d62SAlan Douglas 	return 0;
63144d30d62SAlan Douglas }
63244d30d62SAlan Douglas 
633380f5708SKishon Vijay Abraham I static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base,
634380f5708SKishon Vijay Abraham I 				       u32 block_offset, u8 reg_offset_shift,
635380f5708SKishon Vijay Abraham I 				       const struct regmap_config *config)
636380f5708SKishon Vijay Abraham I {
637380f5708SKishon Vijay Abraham I 	struct cdns_regmap_cdb_context *ctx;
638380f5708SKishon Vijay Abraham I 
639380f5708SKishon Vijay Abraham I 	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
640380f5708SKishon Vijay Abraham I 	if (!ctx)
641380f5708SKishon Vijay Abraham I 		return ERR_PTR(-ENOMEM);
642380f5708SKishon Vijay Abraham I 
643380f5708SKishon Vijay Abraham I 	ctx->dev = dev;
644380f5708SKishon Vijay Abraham I 	ctx->base = base + block_offset;
645380f5708SKishon Vijay Abraham I 	ctx->reg_offset_shift = reg_offset_shift;
646380f5708SKishon Vijay Abraham I 
647380f5708SKishon Vijay Abraham I 	return devm_regmap_init(dev, NULL, ctx, config);
648380f5708SKishon Vijay Abraham I }
649380f5708SKishon Vijay Abraham I 
650380f5708SKishon Vijay Abraham I static int cdns_regfield_init(struct cdns_sierra_phy *sp)
651380f5708SKishon Vijay Abraham I {
652380f5708SKishon Vijay Abraham I 	struct device *dev = sp->dev;
653380f5708SKishon Vijay Abraham I 	struct regmap_field *field;
65428081b72SKishon Vijay Abraham I 	struct reg_field reg_field;
655380f5708SKishon Vijay Abraham I 	struct regmap *regmap;
656adc4bd6fSKishon Vijay Abraham I 	int i;
657380f5708SKishon Vijay Abraham I 
658380f5708SKishon Vijay Abraham I 	regmap = sp->regmap_common_cdb;
659380f5708SKishon Vijay Abraham I 	field = devm_regmap_field_alloc(dev, regmap, macro_id_type);
660380f5708SKishon Vijay Abraham I 	if (IS_ERR(field)) {
661380f5708SKishon Vijay Abraham I 		dev_err(dev, "MACRO_ID_TYPE reg field init failed\n");
662380f5708SKishon Vijay Abraham I 		return PTR_ERR(field);
663380f5708SKishon Vijay Abraham I 	}
664380f5708SKishon Vijay Abraham I 	sp->macro_id_type = field;
665380f5708SKishon Vijay Abraham I 
66628081b72SKishon Vijay Abraham I 	for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++) {
66728081b72SKishon Vijay Abraham I 		reg_field = cmn_plllc_pfdclk1_sel_preg[i].pfdclk_sel_preg;
66828081b72SKishon Vijay Abraham I 		field = devm_regmap_field_alloc(dev, regmap, reg_field);
66928081b72SKishon Vijay Abraham I 		if (IS_ERR(field)) {
67028081b72SKishon Vijay Abraham I 			dev_err(dev, "PLLLC%d_PFDCLK1_SEL failed\n", i);
67128081b72SKishon Vijay Abraham I 			return PTR_ERR(field);
67228081b72SKishon Vijay Abraham I 		}
67328081b72SKishon Vijay Abraham I 		sp->cmn_plllc_pfdclk1_sel_preg[i] = field;
67428081b72SKishon Vijay Abraham I 
67528081b72SKishon Vijay Abraham I 		reg_field = cmn_plllc_pfdclk1_sel_preg[i].plllc1en_field;
67628081b72SKishon Vijay Abraham I 		field = devm_regmap_field_alloc(dev, regmap, reg_field);
67728081b72SKishon Vijay Abraham I 		if (IS_ERR(field)) {
67828081b72SKishon Vijay Abraham I 			dev_err(dev, "REFRCV%d_REFCLK_PLLLC1EN failed\n", i);
67928081b72SKishon Vijay Abraham I 			return PTR_ERR(field);
68028081b72SKishon Vijay Abraham I 		}
68128081b72SKishon Vijay Abraham I 		sp->cmn_refrcv_refclk_plllc1en_preg[i] = field;
68228081b72SKishon Vijay Abraham I 
68328081b72SKishon Vijay Abraham I 		reg_field = cmn_plllc_pfdclk1_sel_preg[i].termen_field;
68428081b72SKishon Vijay Abraham I 		field = devm_regmap_field_alloc(dev, regmap, reg_field);
68528081b72SKishon Vijay Abraham I 		if (IS_ERR(field)) {
68628081b72SKishon Vijay Abraham I 			dev_err(dev, "REFRCV%d_REFCLK_TERMEN failed\n", i);
68728081b72SKishon Vijay Abraham I 			return PTR_ERR(field);
68828081b72SKishon Vijay Abraham I 		}
68928081b72SKishon Vijay Abraham I 		sp->cmn_refrcv_refclk_termen_preg[i] = field;
69028081b72SKishon Vijay Abraham I 	}
69128081b72SKishon Vijay Abraham I 
692380f5708SKishon Vijay Abraham I 	regmap = sp->regmap_phy_config_ctrl;
693380f5708SKishon Vijay Abraham I 	field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1);
694380f5708SKishon Vijay Abraham I 	if (IS_ERR(field)) {
695380f5708SKishon Vijay Abraham I 		dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n");
696380f5708SKishon Vijay Abraham I 		return PTR_ERR(field);
697380f5708SKishon Vijay Abraham I 	}
698380f5708SKishon Vijay Abraham I 	sp->phy_pll_cfg_1 = field;
699380f5708SKishon Vijay Abraham I 
700adc4bd6fSKishon Vijay Abraham I 	for (i = 0; i < SIERRA_MAX_LANES; i++) {
701adc4bd6fSKishon Vijay Abraham I 		regmap = sp->regmap_lane_cdb[i];
702adc4bd6fSKishon Vijay Abraham I 		field = devm_regmap_field_alloc(dev, regmap, pllctrl_lock);
703adc4bd6fSKishon Vijay Abraham I 		if (IS_ERR(field)) {
704adc4bd6fSKishon Vijay Abraham I 			dev_err(dev, "P%d_ENABLE reg field init failed\n", i);
705adc4bd6fSKishon Vijay Abraham I 			return PTR_ERR(field);
706adc4bd6fSKishon Vijay Abraham I 		}
707adc4bd6fSKishon Vijay Abraham I 		sp->pllctrl_lock[i] =  field;
708adc4bd6fSKishon Vijay Abraham I 	}
709adc4bd6fSKishon Vijay Abraham I 
710380f5708SKishon Vijay Abraham I 	return 0;
711380f5708SKishon Vijay Abraham I }
712380f5708SKishon Vijay Abraham I 
713380f5708SKishon Vijay Abraham I static int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp,
714380f5708SKishon Vijay Abraham I 				   void __iomem *base, u8 block_offset_shift,
715380f5708SKishon Vijay Abraham I 				   u8 reg_offset_shift)
716380f5708SKishon Vijay Abraham I {
717380f5708SKishon Vijay Abraham I 	struct device *dev = sp->dev;
718380f5708SKishon Vijay Abraham I 	struct regmap *regmap;
719380f5708SKishon Vijay Abraham I 	u32 block_offset;
720380f5708SKishon Vijay Abraham I 	int i;
721380f5708SKishon Vijay Abraham I 
722380f5708SKishon Vijay Abraham I 	for (i = 0; i < SIERRA_MAX_LANES; i++) {
723380f5708SKishon Vijay Abraham I 		block_offset = SIERRA_LANE_CDB_OFFSET(i, block_offset_shift,
724380f5708SKishon Vijay Abraham I 						      reg_offset_shift);
725380f5708SKishon Vijay Abraham I 		regmap = cdns_regmap_init(dev, base, block_offset,
726380f5708SKishon Vijay Abraham I 					  reg_offset_shift,
727380f5708SKishon Vijay Abraham I 					  &cdns_sierra_lane_cdb_config[i]);
728380f5708SKishon Vijay Abraham I 		if (IS_ERR(regmap)) {
729380f5708SKishon Vijay Abraham I 			dev_err(dev, "Failed to init lane CDB regmap\n");
730380f5708SKishon Vijay Abraham I 			return PTR_ERR(regmap);
731380f5708SKishon Vijay Abraham I 		}
732380f5708SKishon Vijay Abraham I 		sp->regmap_lane_cdb[i] = regmap;
733380f5708SKishon Vijay Abraham I 	}
734380f5708SKishon Vijay Abraham I 
735380f5708SKishon Vijay Abraham I 	regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET,
736380f5708SKishon Vijay Abraham I 				  reg_offset_shift,
737380f5708SKishon Vijay Abraham I 				  &cdns_sierra_common_cdb_config);
738380f5708SKishon Vijay Abraham I 	if (IS_ERR(regmap)) {
739380f5708SKishon Vijay Abraham I 		dev_err(dev, "Failed to init common CDB regmap\n");
740380f5708SKishon Vijay Abraham I 		return PTR_ERR(regmap);
741380f5708SKishon Vijay Abraham I 	}
742380f5708SKishon Vijay Abraham I 	sp->regmap_common_cdb = regmap;
743380f5708SKishon Vijay Abraham I 
744380f5708SKishon Vijay Abraham I 	block_offset = SIERRA_PHY_CONFIG_CTRL_OFFSET(block_offset_shift);
745380f5708SKishon Vijay Abraham I 	regmap = cdns_regmap_init(dev, base, block_offset, reg_offset_shift,
746380f5708SKishon Vijay Abraham I 				  &cdns_sierra_phy_config_ctrl_config);
747380f5708SKishon Vijay Abraham I 	if (IS_ERR(regmap)) {
748380f5708SKishon Vijay Abraham I 		dev_err(dev, "Failed to init PHY config and control regmap\n");
749380f5708SKishon Vijay Abraham I 		return PTR_ERR(regmap);
750380f5708SKishon Vijay Abraham I 	}
751380f5708SKishon Vijay Abraham I 	sp->regmap_phy_config_ctrl = regmap;
752380f5708SKishon Vijay Abraham I 
753380f5708SKishon Vijay Abraham I 	return 0;
754380f5708SKishon Vijay Abraham I }
755380f5708SKishon Vijay Abraham I 
7567e016cbcSKishon Vijay Abraham I static int cdns_sierra_phy_get_clocks(struct cdns_sierra_phy *sp,
7577e016cbcSKishon Vijay Abraham I 				      struct device *dev)
7587e016cbcSKishon Vijay Abraham I {
7597e016cbcSKishon Vijay Abraham I 	struct clk *clk;
7607e016cbcSKishon Vijay Abraham I 	int ret;
7617e016cbcSKishon Vijay Abraham I 
7627e016cbcSKishon Vijay Abraham I 	clk = devm_clk_get_optional(dev, "phy_clk");
7637e016cbcSKishon Vijay Abraham I 	if (IS_ERR(clk)) {
7647e016cbcSKishon Vijay Abraham I 		dev_err(dev, "failed to get clock phy_clk\n");
7657e016cbcSKishon Vijay Abraham I 		return PTR_ERR(clk);
7667e016cbcSKishon Vijay Abraham I 	}
767a0c30cd7SKishon Vijay Abraham I 	sp->input_clks[PHY_CLK] = clk;
7687e016cbcSKishon Vijay Abraham I 
7697e016cbcSKishon Vijay Abraham I 	clk = devm_clk_get_optional(dev, "cmn_refclk_dig_div");
7707e016cbcSKishon Vijay Abraham I 	if (IS_ERR(clk)) {
7717e016cbcSKishon Vijay Abraham I 		dev_err(dev, "cmn_refclk_dig_div clock not found\n");
7727e016cbcSKishon Vijay Abraham I 		ret = PTR_ERR(clk);
7737e016cbcSKishon Vijay Abraham I 		return ret;
7747e016cbcSKishon Vijay Abraham I 	}
775a0c30cd7SKishon Vijay Abraham I 	sp->input_clks[CMN_REFCLK_DIG_DIV] = clk;
7767e016cbcSKishon Vijay Abraham I 
7777e016cbcSKishon Vijay Abraham I 	clk = devm_clk_get_optional(dev, "cmn_refclk1_dig_div");
7787e016cbcSKishon Vijay Abraham I 	if (IS_ERR(clk)) {
7797e016cbcSKishon Vijay Abraham I 		dev_err(dev, "cmn_refclk1_dig_div clock not found\n");
7807e016cbcSKishon Vijay Abraham I 		ret = PTR_ERR(clk);
7817e016cbcSKishon Vijay Abraham I 		return ret;
7827e016cbcSKishon Vijay Abraham I 	}
783a0c30cd7SKishon Vijay Abraham I 	sp->input_clks[CMN_REFCLK1_DIG_DIV] = clk;
7847e016cbcSKishon Vijay Abraham I 
78528081b72SKishon Vijay Abraham I 	clk = devm_clk_get_optional(dev, "pll0_refclk");
78628081b72SKishon Vijay Abraham I 	if (IS_ERR(clk)) {
78728081b72SKishon Vijay Abraham I 		dev_err(dev, "pll0_refclk clock not found\n");
78828081b72SKishon Vijay Abraham I 		ret = PTR_ERR(clk);
78928081b72SKishon Vijay Abraham I 		return ret;
79028081b72SKishon Vijay Abraham I 	}
79128081b72SKishon Vijay Abraham I 	sp->input_clks[PLL0_REFCLK] = clk;
79228081b72SKishon Vijay Abraham I 
79328081b72SKishon Vijay Abraham I 	clk = devm_clk_get_optional(dev, "pll1_refclk");
79428081b72SKishon Vijay Abraham I 	if (IS_ERR(clk)) {
79528081b72SKishon Vijay Abraham I 		dev_err(dev, "pll1_refclk clock not found\n");
79628081b72SKishon Vijay Abraham I 		ret = PTR_ERR(clk);
79728081b72SKishon Vijay Abraham I 		return ret;
79828081b72SKishon Vijay Abraham I 	}
79928081b72SKishon Vijay Abraham I 	sp->input_clks[PLL1_REFCLK] = clk;
80028081b72SKishon Vijay Abraham I 
8017e016cbcSKishon Vijay Abraham I 	return 0;
8027e016cbcSKishon Vijay Abraham I }
8037e016cbcSKishon Vijay Abraham I 
8041436ec30SKishon Vijay Abraham I static int cdns_sierra_phy_enable_clocks(struct cdns_sierra_phy *sp)
8051436ec30SKishon Vijay Abraham I {
8061436ec30SKishon Vijay Abraham I 	int ret;
8071436ec30SKishon Vijay Abraham I 
8081436ec30SKishon Vijay Abraham I 	ret = clk_prepare_enable(sp->input_clks[PHY_CLK]);
8091436ec30SKishon Vijay Abraham I 	if (ret)
8101436ec30SKishon Vijay Abraham I 		return ret;
8111436ec30SKishon Vijay Abraham I 
8121436ec30SKishon Vijay Abraham I 	ret = clk_prepare_enable(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]);
8131436ec30SKishon Vijay Abraham I 	if (ret)
8141436ec30SKishon Vijay Abraham I 		goto err_pll_cmnlc;
8151436ec30SKishon Vijay Abraham I 
8161436ec30SKishon Vijay Abraham I 	ret = clk_prepare_enable(sp->output_clks[CDNS_SIERRA_PLL_CMNLC1]);
8171436ec30SKishon Vijay Abraham I 	if (ret)
8181436ec30SKishon Vijay Abraham I 		goto err_pll_cmnlc1;
8191436ec30SKishon Vijay Abraham I 
8201436ec30SKishon Vijay Abraham I 	return 0;
8211436ec30SKishon Vijay Abraham I 
8221436ec30SKishon Vijay Abraham I err_pll_cmnlc1:
8231436ec30SKishon Vijay Abraham I 	clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]);
8241436ec30SKishon Vijay Abraham I 
8251436ec30SKishon Vijay Abraham I err_pll_cmnlc:
8261436ec30SKishon Vijay Abraham I 	clk_disable_unprepare(sp->input_clks[PHY_CLK]);
8271436ec30SKishon Vijay Abraham I 
8281436ec30SKishon Vijay Abraham I 	return ret;
8291436ec30SKishon Vijay Abraham I }
8301436ec30SKishon Vijay Abraham I 
8311436ec30SKishon Vijay Abraham I static void cdns_sierra_phy_disable_clocks(struct cdns_sierra_phy *sp)
8321436ec30SKishon Vijay Abraham I {
8331436ec30SKishon Vijay Abraham I 	clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC1]);
8341436ec30SKishon Vijay Abraham I 	clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]);
8351436ec30SKishon Vijay Abraham I 	clk_disable_unprepare(sp->input_clks[PHY_CLK]);
8361436ec30SKishon Vijay Abraham I }
8371436ec30SKishon Vijay Abraham I 
8381d5f40e0SKishon Vijay Abraham I static int cdns_sierra_phy_get_resets(struct cdns_sierra_phy *sp,
8391d5f40e0SKishon Vijay Abraham I 				      struct device *dev)
8401d5f40e0SKishon Vijay Abraham I {
8411d5f40e0SKishon Vijay Abraham I 	struct reset_control *rst;
8421d5f40e0SKishon Vijay Abraham I 
84315b0b82dSKishon Vijay Abraham I 	rst = devm_reset_control_get_exclusive(dev, "sierra_reset");
8441d5f40e0SKishon Vijay Abraham I 	if (IS_ERR(rst)) {
8451d5f40e0SKishon Vijay Abraham I 		dev_err(dev, "failed to get reset\n");
8461d5f40e0SKishon Vijay Abraham I 		return PTR_ERR(rst);
8471d5f40e0SKishon Vijay Abraham I 	}
8481d5f40e0SKishon Vijay Abraham I 	sp->phy_rst = rst;
8491d5f40e0SKishon Vijay Abraham I 
85015b0b82dSKishon Vijay Abraham I 	rst = devm_reset_control_get_optional_exclusive(dev, "sierra_apb");
8511d5f40e0SKishon Vijay Abraham I 	if (IS_ERR(rst)) {
8521d5f40e0SKishon Vijay Abraham I 		dev_err(dev, "failed to get apb reset\n");
8531d5f40e0SKishon Vijay Abraham I 		return PTR_ERR(rst);
8541d5f40e0SKishon Vijay Abraham I 	}
8551d5f40e0SKishon Vijay Abraham I 	sp->apb_rst = rst;
8561d5f40e0SKishon Vijay Abraham I 
8571d5f40e0SKishon Vijay Abraham I 	return 0;
8581d5f40e0SKishon Vijay Abraham I }
8591d5f40e0SKishon Vijay Abraham I 
86044d30d62SAlan Douglas static int cdns_sierra_phy_probe(struct platform_device *pdev)
86144d30d62SAlan Douglas {
86244d30d62SAlan Douglas 	struct cdns_sierra_phy *sp;
86344d30d62SAlan Douglas 	struct phy_provider *phy_provider;
86444d30d62SAlan Douglas 	struct device *dev = &pdev->dev;
865c3c11d55SSwapnil Jakhade 	const struct cdns_sierra_data *data;
866380f5708SKishon Vijay Abraham I 	unsigned int id_value;
86744d30d62SAlan Douglas 	int i, ret, node = 0;
868380f5708SKishon Vijay Abraham I 	void __iomem *base;
86944d30d62SAlan Douglas 	struct device_node *dn = dev->of_node, *child;
87044d30d62SAlan Douglas 
87144d30d62SAlan Douglas 	if (of_get_child_count(dn) == 0)
87244d30d62SAlan Douglas 		return -ENODEV;
87344d30d62SAlan Douglas 
874380f5708SKishon Vijay Abraham I 	/* Get init data for this PHY */
875c3c11d55SSwapnil Jakhade 	data = of_device_get_match_data(dev);
876c3c11d55SSwapnil Jakhade 	if (!data)
877380f5708SKishon Vijay Abraham I 		return -EINVAL;
878380f5708SKishon Vijay Abraham I 
87944d30d62SAlan Douglas 	sp = devm_kzalloc(dev, sizeof(*sp), GFP_KERNEL);
88044d30d62SAlan Douglas 	if (!sp)
88144d30d62SAlan Douglas 		return -ENOMEM;
88244d30d62SAlan Douglas 	dev_set_drvdata(dev, sp);
88344d30d62SAlan Douglas 	sp->dev = dev;
884380f5708SKishon Vijay Abraham I 	sp->init_data = data;
88544d30d62SAlan Douglas 
886fa629094SChunfeng Yun 	base = devm_platform_ioremap_resource(pdev, 0);
887380f5708SKishon Vijay Abraham I 	if (IS_ERR(base)) {
88844d30d62SAlan Douglas 		dev_err(dev, "missing \"reg\"\n");
889380f5708SKishon Vijay Abraham I 		return PTR_ERR(base);
89044d30d62SAlan Douglas 	}
89144d30d62SAlan Douglas 
892380f5708SKishon Vijay Abraham I 	ret = cdns_regmap_init_blocks(sp, base, data->block_offset_shift,
893380f5708SKishon Vijay Abraham I 				      data->reg_offset_shift);
894380f5708SKishon Vijay Abraham I 	if (ret)
895380f5708SKishon Vijay Abraham I 		return ret;
896380f5708SKishon Vijay Abraham I 
897380f5708SKishon Vijay Abraham I 	ret = cdns_regfield_init(sp);
898380f5708SKishon Vijay Abraham I 	if (ret)
899380f5708SKishon Vijay Abraham I 		return ret;
90044d30d62SAlan Douglas 
90144d30d62SAlan Douglas 	platform_set_drvdata(pdev, sp);
90244d30d62SAlan Douglas 
9037e016cbcSKishon Vijay Abraham I 	ret = cdns_sierra_phy_get_clocks(sp, dev);
9047e016cbcSKishon Vijay Abraham I 	if (ret)
9057e016cbcSKishon Vijay Abraham I 		return ret;
90644d30d62SAlan Douglas 
90728081b72SKishon Vijay Abraham I 	ret = cdns_sierra_clk_register(sp);
9081d5f40e0SKishon Vijay Abraham I 	if (ret)
9091d5f40e0SKishon Vijay Abraham I 		return ret;
91044d30d62SAlan Douglas 
91128081b72SKishon Vijay Abraham I 	ret = cdns_sierra_phy_get_resets(sp, dev);
91228081b72SKishon Vijay Abraham I 	if (ret)
91328081b72SKishon Vijay Abraham I 		goto unregister_clk;
91428081b72SKishon Vijay Abraham I 
9151436ec30SKishon Vijay Abraham I 	ret = cdns_sierra_phy_enable_clocks(sp);
91644d30d62SAlan Douglas 	if (ret)
91728081b72SKishon Vijay Abraham I 		goto unregister_clk;
91844d30d62SAlan Douglas 
91944d30d62SAlan Douglas 	/* Enable APB */
92044d30d62SAlan Douglas 	reset_control_deassert(sp->apb_rst);
92144d30d62SAlan Douglas 
92244d30d62SAlan Douglas 	/* Check that PHY is present */
923380f5708SKishon Vijay Abraham I 	regmap_field_read(sp->macro_id_type, &id_value);
924380f5708SKishon Vijay Abraham I 	if  (sp->init_data->id_value != id_value) {
92544d30d62SAlan Douglas 		ret = -EINVAL;
92644d30d62SAlan Douglas 		goto clk_disable;
92744d30d62SAlan Douglas 	}
92844d30d62SAlan Douglas 
92944d30d62SAlan Douglas 	sp->autoconf = of_property_read_bool(dn, "cdns,autoconf");
93044d30d62SAlan Douglas 
93144d30d62SAlan Douglas 	for_each_available_child_of_node(dn, child) {
93244d30d62SAlan Douglas 		struct phy *gphy;
93344d30d62SAlan Douglas 
93403ada5a3SKishon Vijay Abraham I 		if (!(of_node_name_eq(child, "phy") ||
93503ada5a3SKishon Vijay Abraham I 		      of_node_name_eq(child, "link")))
93603ada5a3SKishon Vijay Abraham I 			continue;
93703ada5a3SKishon Vijay Abraham I 
93844d30d62SAlan Douglas 		sp->phys[node].lnk_rst =
939b872936fSKishon Vijay Abraham I 			of_reset_control_array_get_exclusive(child);
94044d30d62SAlan Douglas 
94144d30d62SAlan Douglas 		if (IS_ERR(sp->phys[node].lnk_rst)) {
94244d30d62SAlan Douglas 			dev_err(dev, "failed to get reset %s\n",
94344d30d62SAlan Douglas 				child->full_name);
94444d30d62SAlan Douglas 			ret = PTR_ERR(sp->phys[node].lnk_rst);
94544d30d62SAlan Douglas 			goto put_child2;
94644d30d62SAlan Douglas 		}
94744d30d62SAlan Douglas 
94844d30d62SAlan Douglas 		if (!sp->autoconf) {
94944d30d62SAlan Douglas 			ret = cdns_sierra_get_optional(&sp->phys[node], child);
95044d30d62SAlan Douglas 			if (ret) {
95144d30d62SAlan Douglas 				dev_err(dev, "missing property in node %s\n",
95244d30d62SAlan Douglas 					child->name);
95344d30d62SAlan Douglas 				goto put_child;
95444d30d62SAlan Douglas 			}
95544d30d62SAlan Douglas 		}
95644d30d62SAlan Douglas 
957a43f72aeSKishon Vijay Abraham I 		sp->num_lanes += sp->phys[node].num_lanes;
958a43f72aeSKishon Vijay Abraham I 
95944d30d62SAlan Douglas 		gphy = devm_phy_create(dev, child, &ops);
96044d30d62SAlan Douglas 
96144d30d62SAlan Douglas 		if (IS_ERR(gphy)) {
96244d30d62SAlan Douglas 			ret = PTR_ERR(gphy);
96344d30d62SAlan Douglas 			goto put_child;
96444d30d62SAlan Douglas 		}
96544d30d62SAlan Douglas 		sp->phys[node].phy = gphy;
96644d30d62SAlan Douglas 		phy_set_drvdata(gphy, &sp->phys[node]);
96744d30d62SAlan Douglas 
96844d30d62SAlan Douglas 		node++;
96944d30d62SAlan Douglas 	}
97044d30d62SAlan Douglas 	sp->nsubnodes = node;
97144d30d62SAlan Douglas 
972a43f72aeSKishon Vijay Abraham I 	if (sp->num_lanes > SIERRA_MAX_LANES) {
9736411e386SWang Wensheng 		ret = -EINVAL;
974a43f72aeSKishon Vijay Abraham I 		dev_err(dev, "Invalid lane configuration\n");
975a43f72aeSKishon Vijay Abraham I 		goto put_child2;
976a43f72aeSKishon Vijay Abraham I 	}
977a43f72aeSKishon Vijay Abraham I 
97844d30d62SAlan Douglas 	/* If more than one subnode, configure the PHY as multilink */
97944d30d62SAlan Douglas 	if (!sp->autoconf && sp->nsubnodes > 1)
980380f5708SKishon Vijay Abraham I 		regmap_field_write(sp->phy_pll_cfg_1, 0x1);
98144d30d62SAlan Douglas 
98244d30d62SAlan Douglas 	pm_runtime_enable(dev);
98344d30d62SAlan Douglas 	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
98444d30d62SAlan Douglas 	return PTR_ERR_OR_ZERO(phy_provider);
98544d30d62SAlan Douglas 
98644d30d62SAlan Douglas put_child:
98744d30d62SAlan Douglas 	node++;
98844d30d62SAlan Douglas put_child2:
98944d30d62SAlan Douglas 	for (i = 0; i < node; i++)
99044d30d62SAlan Douglas 		reset_control_put(sp->phys[i].lnk_rst);
99144d30d62SAlan Douglas 	of_node_put(child);
99244d30d62SAlan Douglas clk_disable:
9931436ec30SKishon Vijay Abraham I 	cdns_sierra_phy_disable_clocks(sp);
99444d30d62SAlan Douglas 	reset_control_assert(sp->apb_rst);
99528081b72SKishon Vijay Abraham I unregister_clk:
99628081b72SKishon Vijay Abraham I 	cdns_sierra_clk_unregister(sp);
99744d30d62SAlan Douglas 	return ret;
99844d30d62SAlan Douglas }
99944d30d62SAlan Douglas 
100044d30d62SAlan Douglas static int cdns_sierra_phy_remove(struct platform_device *pdev)
100144d30d62SAlan Douglas {
1002748e3456SKishon Vijay Abraham I 	struct cdns_sierra_phy *phy = platform_get_drvdata(pdev);
100344d30d62SAlan Douglas 	int i;
100444d30d62SAlan Douglas 
100544d30d62SAlan Douglas 	reset_control_assert(phy->phy_rst);
100644d30d62SAlan Douglas 	reset_control_assert(phy->apb_rst);
100744d30d62SAlan Douglas 	pm_runtime_disable(&pdev->dev);
100844d30d62SAlan Douglas 
10091436ec30SKishon Vijay Abraham I 	cdns_sierra_phy_disable_clocks(phy);
101044d30d62SAlan Douglas 	/*
101144d30d62SAlan Douglas 	 * The device level resets will be put automatically.
101244d30d62SAlan Douglas 	 * Need to put the subnode resets here though.
101344d30d62SAlan Douglas 	 */
101444d30d62SAlan Douglas 	for (i = 0; i < phy->nsubnodes; i++) {
101544d30d62SAlan Douglas 		reset_control_assert(phy->phys[i].lnk_rst);
101644d30d62SAlan Douglas 		reset_control_put(phy->phys[i].lnk_rst);
101744d30d62SAlan Douglas 	}
101829c2d02aSKishon Vijay Abraham I 
101928081b72SKishon Vijay Abraham I 	cdns_sierra_clk_unregister(phy);
102029c2d02aSKishon Vijay Abraham I 
102144d30d62SAlan Douglas 	return 0;
102244d30d62SAlan Douglas }
102344d30d62SAlan Douglas 
1024871002d7SAnil Varughese /* refclk100MHz_32b_PCIe_cmn_pll_ext_ssc */
10253cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_pcie_cmn_regs_ext_ssc[] = {
1026871002d7SAnil Varughese 	{0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1027871002d7SAnil Varughese 	{0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1028871002d7SAnil Varughese 	{0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
1029871002d7SAnil Varughese 	{0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
1030871002d7SAnil Varughese 	{0x1B1B, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
1031871002d7SAnil Varughese };
1032871002d7SAnil Varughese 
1033871002d7SAnil Varughese /* refclk100MHz_32b_PCIe_ln_ext_ssc */
10343cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_pcie_ln_regs_ext_ssc[] = {
1035871002d7SAnil Varughese 	{0x813E, SIERRA_CLKPATHCTRL_TMR_PREG},
1036871002d7SAnil Varughese 	{0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
1037871002d7SAnil Varughese 	{0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
1038871002d7SAnil Varughese 	{0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
1039871002d7SAnil Varughese 	{0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
1040871002d7SAnil Varughese 	{0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
1041871002d7SAnil Varughese 	{0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG}
1042871002d7SAnil Varughese };
1043871002d7SAnil Varughese 
1044078e9e92SSwapnil Jakhade static struct cdns_sierra_vals pcie_100_ext_ssc_cmn_vals = {
1045078e9e92SSwapnil Jakhade 	.reg_pairs = cdns_pcie_cmn_regs_ext_ssc,
1046078e9e92SSwapnil Jakhade 	.num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc),
1047078e9e92SSwapnil Jakhade };
1048078e9e92SSwapnil Jakhade 
1049078e9e92SSwapnil Jakhade static struct cdns_sierra_vals pcie_100_ext_ssc_ln_vals = {
1050078e9e92SSwapnil Jakhade 	.reg_pairs = cdns_pcie_ln_regs_ext_ssc,
1051078e9e92SSwapnil Jakhade 	.num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc),
1052078e9e92SSwapnil Jakhade };
1053078e9e92SSwapnil Jakhade 
1054871002d7SAnil Varughese /* refclk100MHz_20b_USB_cmn_pll_ext_ssc */
10553cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_usb_cmn_regs_ext_ssc[] = {
1056871002d7SAnil Varughese 	{0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1057871002d7SAnil Varughese 	{0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1058871002d7SAnil Varughese 	{0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
1059871002d7SAnil Varughese 	{0x0000, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
1060871002d7SAnil Varughese };
1061871002d7SAnil Varughese 
1062871002d7SAnil Varughese /* refclk100MHz_20b_USB_ln_ext_ssc */
10633cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_usb_ln_regs_ext_ssc[] = {
1064aead5fd6SKishon Vijay Abraham I 	{0xFE0A, SIERRA_DET_STANDEC_A_PREG},
1065aead5fd6SKishon Vijay Abraham I 	{0x000F, SIERRA_DET_STANDEC_B_PREG},
10662bcf14caSSanket Parmar 	{0x55A5, SIERRA_DET_STANDEC_C_PREG},
1067871002d7SAnil Varughese 	{0x69ad, SIERRA_DET_STANDEC_D_PREG},
1068aead5fd6SKishon Vijay Abraham I 	{0x0241, SIERRA_DET_STANDEC_E_PREG},
10692bcf14caSSanket Parmar 	{0x0110, SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG},
1070871002d7SAnil Varughese 	{0x0014, SIERRA_PSM_A0IN_TMR_PREG},
1071aead5fd6SKishon Vijay Abraham I 	{0xCF00, SIERRA_PSM_DIAG_PREG},
1072aead5fd6SKishon Vijay Abraham I 	{0x001F, SIERRA_PSC_TX_A0_PREG},
1073aead5fd6SKishon Vijay Abraham I 	{0x0007, SIERRA_PSC_TX_A1_PREG},
1074aead5fd6SKishon Vijay Abraham I 	{0x0003, SIERRA_PSC_TX_A2_PREG},
1075aead5fd6SKishon Vijay Abraham I 	{0x0003, SIERRA_PSC_TX_A3_PREG},
1076aead5fd6SKishon Vijay Abraham I 	{0x0FFF, SIERRA_PSC_RX_A0_PREG},
10772bcf14caSSanket Parmar 	{0x0003, SIERRA_PSC_RX_A1_PREG},
1078aead5fd6SKishon Vijay Abraham I 	{0x0003, SIERRA_PSC_RX_A2_PREG},
1079aead5fd6SKishon Vijay Abraham I 	{0x0001, SIERRA_PSC_RX_A3_PREG},
1080aead5fd6SKishon Vijay Abraham I 	{0x0001, SIERRA_PLLCTRL_SUBRATE_PREG},
1081aead5fd6SKishon Vijay Abraham I 	{0x0406, SIERRA_PLLCTRL_GEN_D_PREG},
1082871002d7SAnil Varughese 	{0x5233, SIERRA_PLLCTRL_CPGAIN_MODE_PREG},
1083871002d7SAnil Varughese 	{0x00CA, SIERRA_CLKPATH_BIASTRIM_PREG},
1084871002d7SAnil Varughese 	{0x2512, SIERRA_DFE_BIASTRIM_PREG},
1085aead5fd6SKishon Vijay Abraham I 	{0x0000, SIERRA_DRVCTRL_ATTEN_PREG},
10862bcf14caSSanket Parmar 	{0x823E, SIERRA_CLKPATHCTRL_TMR_PREG},
10872bcf14caSSanket Parmar 	{0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
10882bcf14caSSanket Parmar 	{0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
1089aead5fd6SKishon Vijay Abraham I 	{0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG},
10902bcf14caSSanket Parmar 	{0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
1091aead5fd6SKishon Vijay Abraham I 	{0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG},
1092871002d7SAnil Varughese 	{0x0000, SIERRA_CREQ_EQ_CTRL_PREG},
10932bcf14caSSanket Parmar 	{0x0000, SIERRA_CREQ_SPARE_PREG},
1094871002d7SAnil Varughese 	{0xCC44, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
10952bcf14caSSanket Parmar 	{0x8452, SIERRA_CTLELUT_CTRL_PREG},
10962bcf14caSSanket Parmar 	{0x4121, SIERRA_DFE_ECMP_RATESEL_PREG},
10972bcf14caSSanket Parmar 	{0x4121, SIERRA_DFE_SMP_RATESEL_PREG},
10982bcf14caSSanket Parmar 	{0x0003, SIERRA_DEQ_PHALIGN_CTRL},
1099871002d7SAnil Varughese 	{0x3200, SIERRA_DEQ_CONCUR_CTRL1_PREG},
1100871002d7SAnil Varughese 	{0x5064, SIERRA_DEQ_CONCUR_CTRL2_PREG},
1101871002d7SAnil Varughese 	{0x0030, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
1102871002d7SAnil Varughese 	{0x0048, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
1103871002d7SAnil Varughese 	{0x5A5A, SIERRA_DEQ_ERRCMP_CTRL_PREG},
1104871002d7SAnil Varughese 	{0x02F5, SIERRA_DEQ_OFFSET_CTRL_PREG},
1105871002d7SAnil Varughese 	{0x02F5, SIERRA_DEQ_GAIN_CTRL_PREG},
11062bcf14caSSanket Parmar 	{0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG},
1107871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT0},
1108871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT1},
1109871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT2},
1110871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT3},
1111871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT4},
1112871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT5},
1113871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT6},
1114871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT7},
1115871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT8},
1116871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT9},
1117871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT10},
1118871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT11},
1119871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT12},
1120871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT13},
1121871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT14},
1122871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT15},
1123871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT16},
1124871002d7SAnil Varughese 	{0x0BAE, SIERRA_DEQ_ALUT0},
1125871002d7SAnil Varughese 	{0x0AEB, SIERRA_DEQ_ALUT1},
1126871002d7SAnil Varughese 	{0x0A28, SIERRA_DEQ_ALUT2},
1127871002d7SAnil Varughese 	{0x0965, SIERRA_DEQ_ALUT3},
1128871002d7SAnil Varughese 	{0x08A2, SIERRA_DEQ_ALUT4},
1129871002d7SAnil Varughese 	{0x07DF, SIERRA_DEQ_ALUT5},
1130871002d7SAnil Varughese 	{0x071C, SIERRA_DEQ_ALUT6},
1131871002d7SAnil Varughese 	{0x0659, SIERRA_DEQ_ALUT7},
1132871002d7SAnil Varughese 	{0x0596, SIERRA_DEQ_ALUT8},
1133871002d7SAnil Varughese 	{0x0514, SIERRA_DEQ_ALUT9},
1134871002d7SAnil Varughese 	{0x0492, SIERRA_DEQ_ALUT10},
1135871002d7SAnil Varughese 	{0x0410, SIERRA_DEQ_ALUT11},
1136871002d7SAnil Varughese 	{0x038E, SIERRA_DEQ_ALUT12},
1137871002d7SAnil Varughese 	{0x030C, SIERRA_DEQ_ALUT13},
1138871002d7SAnil Varughese 	{0x03F4, SIERRA_DEQ_DFETAP_CTRL_PREG},
1139871002d7SAnil Varughese 	{0x0001, SIERRA_DFE_EN_1010_IGNORE_PREG},
1140871002d7SAnil Varughese 	{0x3C01, SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG},
1141871002d7SAnil Varughese 	{0x3C40, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1142871002d7SAnil Varughese 	{0x1C08, SIERRA_DEQ_TAU_CTRL2_PREG},
1143871002d7SAnil Varughese 	{0x0033, SIERRA_DEQ_PICTRL_PREG},
1144871002d7SAnil Varughese 	{0x0400, SIERRA_CPICAL_TMRVAL_MODE1_PREG},
1145871002d7SAnil Varughese 	{0x0330, SIERRA_CPICAL_TMRVAL_MODE0_PREG},
1146871002d7SAnil Varughese 	{0x01FF, SIERRA_CPICAL_PICNT_MODE1_PREG},
1147aead5fd6SKishon Vijay Abraham I 	{0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG},
1148871002d7SAnil Varughese 	{0x3232, SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG},
1149871002d7SAnil Varughese 	{0x0005, SIERRA_LFPSDET_SUPPORT_PREG},
1150aead5fd6SKishon Vijay Abraham I 	{0x000F, SIERRA_LFPSFILT_NS_PREG},
1151aead5fd6SKishon Vijay Abraham I 	{0x0009, SIERRA_LFPSFILT_RD_PREG},
1152aead5fd6SKishon Vijay Abraham I 	{0x0001, SIERRA_LFPSFILT_MP_PREG},
11532bcf14caSSanket Parmar 	{0x6013, SIERRA_SIGDET_SUPPORT_PREG},
1154aead5fd6SKishon Vijay Abraham I 	{0x8013, SIERRA_SDFILT_H2L_A_PREG},
1155871002d7SAnil Varughese 	{0x8009, SIERRA_SDFILT_L2H_PREG},
1156871002d7SAnil Varughese 	{0x0024, SIERRA_RXBUFFER_CTLECTRL_PREG},
1157871002d7SAnil Varughese 	{0x0020, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1158871002d7SAnil Varughese 	{0x4243, SIERRA_RXBUFFER_DFECTRL_PREG}
115944d30d62SAlan Douglas };
116044d30d62SAlan Douglas 
1161078e9e92SSwapnil Jakhade static struct cdns_sierra_vals usb_100_ext_ssc_cmn_vals = {
1162078e9e92SSwapnil Jakhade 	.reg_pairs = cdns_usb_cmn_regs_ext_ssc,
1163078e9e92SSwapnil Jakhade 	.num_regs = ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc),
1164078e9e92SSwapnil Jakhade };
1165078e9e92SSwapnil Jakhade 
1166078e9e92SSwapnil Jakhade static struct cdns_sierra_vals usb_100_ext_ssc_ln_vals = {
1167078e9e92SSwapnil Jakhade 	.reg_pairs = cdns_usb_ln_regs_ext_ssc,
1168078e9e92SSwapnil Jakhade 	.num_regs = ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc),
1169078e9e92SSwapnil Jakhade };
1170078e9e92SSwapnil Jakhade 
117144d30d62SAlan Douglas static const struct cdns_sierra_data cdns_map_sierra = {
1172078e9e92SSwapnil Jakhade 	.id_value = SIERRA_MACRO_ID,
1173078e9e92SSwapnil Jakhade 	.block_offset_shift = 0x2,
1174078e9e92SSwapnil Jakhade 	.reg_offset_shift = 0x2,
1175078e9e92SSwapnil Jakhade 	.pma_cmn_vals = {
1176078e9e92SSwapnil Jakhade 		[TYPE_PCIE] = {
1177078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1178078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
1179078e9e92SSwapnil Jakhade 			},
1180078e9e92SSwapnil Jakhade 		},
1181078e9e92SSwapnil Jakhade 		[TYPE_USB] = {
1182078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1183078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1184078e9e92SSwapnil Jakhade 			},
1185078e9e92SSwapnil Jakhade 		},
1186078e9e92SSwapnil Jakhade 	},
1187078e9e92SSwapnil Jakhade 	.pma_ln_vals = {
1188078e9e92SSwapnil Jakhade 		[TYPE_PCIE] = {
1189078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1190078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
1191078e9e92SSwapnil Jakhade 			},
1192078e9e92SSwapnil Jakhade 		},
1193078e9e92SSwapnil Jakhade 		[TYPE_USB] = {
1194078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1195078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1196078e9e92SSwapnil Jakhade 			},
1197078e9e92SSwapnil Jakhade 		},
1198078e9e92SSwapnil Jakhade 	},
119944d30d62SAlan Douglas };
120044d30d62SAlan Douglas 
1201367da978SKishon Vijay Abraham I static const struct cdns_sierra_data cdns_ti_map_sierra = {
1202078e9e92SSwapnil Jakhade 	.id_value = SIERRA_MACRO_ID,
1203078e9e92SSwapnil Jakhade 	.block_offset_shift = 0x0,
1204078e9e92SSwapnil Jakhade 	.reg_offset_shift = 0x1,
1205078e9e92SSwapnil Jakhade 	.pma_cmn_vals = {
1206078e9e92SSwapnil Jakhade 		[TYPE_PCIE] = {
1207078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1208078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
1209078e9e92SSwapnil Jakhade 			},
1210078e9e92SSwapnil Jakhade 		},
1211078e9e92SSwapnil Jakhade 		[TYPE_USB] = {
1212078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1213078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1214078e9e92SSwapnil Jakhade 			},
1215078e9e92SSwapnil Jakhade 		},
1216078e9e92SSwapnil Jakhade 	},
1217078e9e92SSwapnil Jakhade 	.pma_ln_vals = {
1218078e9e92SSwapnil Jakhade 		[TYPE_PCIE] = {
1219078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1220078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
1221078e9e92SSwapnil Jakhade 			},
1222078e9e92SSwapnil Jakhade 		},
1223078e9e92SSwapnil Jakhade 		[TYPE_USB] = {
1224078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1225078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1226078e9e92SSwapnil Jakhade 			},
1227078e9e92SSwapnil Jakhade 		},
1228078e9e92SSwapnil Jakhade 	},
1229367da978SKishon Vijay Abraham I };
1230367da978SKishon Vijay Abraham I 
123144d30d62SAlan Douglas static const struct of_device_id cdns_sierra_id_table[] = {
123244d30d62SAlan Douglas 	{
123344d30d62SAlan Douglas 		.compatible = "cdns,sierra-phy-t0",
123444d30d62SAlan Douglas 		.data = &cdns_map_sierra,
123544d30d62SAlan Douglas 	},
1236367da978SKishon Vijay Abraham I 	{
1237367da978SKishon Vijay Abraham I 		.compatible = "ti,sierra-phy-t0",
1238367da978SKishon Vijay Abraham I 		.data = &cdns_ti_map_sierra,
1239367da978SKishon Vijay Abraham I 	},
124044d30d62SAlan Douglas 	{}
124144d30d62SAlan Douglas };
124244d30d62SAlan Douglas MODULE_DEVICE_TABLE(of, cdns_sierra_id_table);
124344d30d62SAlan Douglas 
124444d30d62SAlan Douglas static struct platform_driver cdns_sierra_driver = {
124544d30d62SAlan Douglas 	.probe		= cdns_sierra_phy_probe,
124644d30d62SAlan Douglas 	.remove		= cdns_sierra_phy_remove,
124744d30d62SAlan Douglas 	.driver		= {
124844d30d62SAlan Douglas 		.name	= "cdns-sierra-phy",
124944d30d62SAlan Douglas 		.of_match_table = cdns_sierra_id_table,
125044d30d62SAlan Douglas 	},
125144d30d62SAlan Douglas };
125244d30d62SAlan Douglas module_platform_driver(cdns_sierra_driver);
125344d30d62SAlan Douglas 
125444d30d62SAlan Douglas MODULE_ALIAS("platform:cdns_sierra");
125544d30d62SAlan Douglas MODULE_AUTHOR("Cadence Design Systems");
125644d30d62SAlan Douglas MODULE_DESCRIPTION("CDNS sierra phy driver");
125744d30d62SAlan Douglas MODULE_LICENSE("GPL v2");
1258