xref: /linux/drivers/phy/cadence/phy-cadence-sierra.c (revision fa10517211f72f9480677796b97cbe5a8f3a298f)
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))
151*fa105172SSwapnil Jakhade #define SIERRA_PHY_PIPE_CMN_CTRL1			0x0
152380f5708SKishon Vijay Abraham I #define SIERRA_PHY_PLL_CFG				0xe
15344d30d62SAlan Douglas 
15444d30d62SAlan Douglas #define SIERRA_MACRO_ID					0x00007364
155a43f72aeSKishon Vijay Abraham I #define SIERRA_MAX_LANES				16
156adc4bd6fSKishon Vijay Abraham I #define PLL_LOCK_TIME					100000
15744d30d62SAlan Douglas 
15828081b72SKishon Vijay Abraham I #define CDNS_SIERRA_OUTPUT_CLOCKS			2
15928081b72SKishon Vijay Abraham I #define CDNS_SIERRA_INPUT_CLOCKS			5
160a0c30cd7SKishon Vijay Abraham I enum cdns_sierra_clock_input {
161a0c30cd7SKishon Vijay Abraham I 	PHY_CLK,
162a0c30cd7SKishon Vijay Abraham I 	CMN_REFCLK_DIG_DIV,
163a0c30cd7SKishon Vijay Abraham I 	CMN_REFCLK1_DIG_DIV,
16428081b72SKishon Vijay Abraham I 	PLL0_REFCLK,
16528081b72SKishon Vijay Abraham I 	PLL1_REFCLK,
166a0c30cd7SKishon Vijay Abraham I };
167a0c30cd7SKishon Vijay Abraham I 
16828081b72SKishon Vijay Abraham I #define SIERRA_NUM_CMN_PLLC				2
16928081b72SKishon Vijay Abraham I #define SIERRA_NUM_CMN_PLLC_PARENTS			2
17028081b72SKishon Vijay Abraham I 
171380f5708SKishon Vijay Abraham I static const struct reg_field macro_id_type =
172380f5708SKishon Vijay Abraham I 				REG_FIELD(SIERRA_MACRO_ID_REG, 0, 15);
173380f5708SKishon Vijay Abraham I static const struct reg_field phy_pll_cfg_1 =
174380f5708SKishon Vijay Abraham I 				REG_FIELD(SIERRA_PHY_PLL_CFG, 1, 1);
175adc4bd6fSKishon Vijay Abraham I static const struct reg_field pllctrl_lock =
176adc4bd6fSKishon Vijay Abraham I 				REG_FIELD(SIERRA_PLLCTRL_STATUS_PREG, 0, 0);
177380f5708SKishon Vijay Abraham I 
17828081b72SKishon Vijay Abraham I static const char * const clk_names[] = {
17928081b72SKishon Vijay Abraham I 	[CDNS_SIERRA_PLL_CMNLC] = "pll_cmnlc",
18028081b72SKishon Vijay Abraham I 	[CDNS_SIERRA_PLL_CMNLC1] = "pll_cmnlc1",
18128081b72SKishon Vijay Abraham I };
18228081b72SKishon Vijay Abraham I 
18328081b72SKishon Vijay Abraham I enum cdns_sierra_cmn_plllc {
18428081b72SKishon Vijay Abraham I 	CMN_PLLLC,
18528081b72SKishon Vijay Abraham I 	CMN_PLLLC1,
18628081b72SKishon Vijay Abraham I };
18728081b72SKishon Vijay Abraham I 
18828081b72SKishon Vijay Abraham I struct cdns_sierra_pll_mux_reg_fields {
18928081b72SKishon Vijay Abraham I 	struct reg_field	pfdclk_sel_preg;
19028081b72SKishon Vijay Abraham I 	struct reg_field	plllc1en_field;
19128081b72SKishon Vijay Abraham I 	struct reg_field	termen_field;
19228081b72SKishon Vijay Abraham I };
19328081b72SKishon Vijay Abraham I 
19428081b72SKishon Vijay Abraham I static const struct cdns_sierra_pll_mux_reg_fields cmn_plllc_pfdclk1_sel_preg[] = {
19528081b72SKishon Vijay Abraham I 	[CMN_PLLLC] = {
19628081b72SKishon Vijay Abraham I 		.pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC_GEN_PREG, 1, 1),
19728081b72SKishon Vijay Abraham I 		.plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 8, 8),
19828081b72SKishon Vijay Abraham I 		.termen_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 0, 0),
19928081b72SKishon Vijay Abraham I 	},
20028081b72SKishon Vijay Abraham I 	[CMN_PLLLC1] = {
20128081b72SKishon Vijay Abraham I 		.pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC1_GEN_PREG, 1, 1),
20228081b72SKishon Vijay Abraham I 		.plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 8, 8),
20328081b72SKishon Vijay Abraham I 		.termen_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 0, 0),
20428081b72SKishon Vijay Abraham I 	},
20528081b72SKishon Vijay Abraham I };
20628081b72SKishon Vijay Abraham I 
20728081b72SKishon Vijay Abraham I struct cdns_sierra_pll_mux {
20828081b72SKishon Vijay Abraham I 	struct clk_hw		hw;
20928081b72SKishon Vijay Abraham I 	struct regmap_field	*pfdclk_sel_preg;
21028081b72SKishon Vijay Abraham I 	struct regmap_field	*plllc1en_field;
21128081b72SKishon Vijay Abraham I 	struct regmap_field	*termen_field;
21228081b72SKishon Vijay Abraham I 	struct clk_init_data	clk_data;
21328081b72SKishon Vijay Abraham I };
21428081b72SKishon Vijay Abraham I 
21528081b72SKishon Vijay Abraham I #define to_cdns_sierra_pll_mux(_hw)	\
21628081b72SKishon Vijay Abraham I 			container_of(_hw, struct cdns_sierra_pll_mux, hw)
21728081b72SKishon Vijay Abraham I 
21828081b72SKishon Vijay Abraham I static const int pll_mux_parent_index[][SIERRA_NUM_CMN_PLLC_PARENTS] = {
21928081b72SKishon Vijay Abraham I 	[CMN_PLLLC] = { PLL0_REFCLK, PLL1_REFCLK },
22028081b72SKishon Vijay Abraham I 	[CMN_PLLLC1] = { PLL1_REFCLK, PLL0_REFCLK },
22128081b72SKishon Vijay Abraham I };
22228081b72SKishon Vijay Abraham I 
22328081b72SKishon Vijay Abraham I static u32 cdns_sierra_pll_mux_table[] = { 0, 1 };
22428081b72SKishon Vijay Abraham I 
225078e9e92SSwapnil Jakhade enum cdns_sierra_phy_type {
226078e9e92SSwapnil Jakhade 	TYPE_NONE,
227078e9e92SSwapnil Jakhade 	TYPE_PCIE,
228078e9e92SSwapnil Jakhade 	TYPE_USB
229078e9e92SSwapnil Jakhade };
230078e9e92SSwapnil Jakhade 
231078e9e92SSwapnil Jakhade enum cdns_sierra_ssc_mode {
232078e9e92SSwapnil Jakhade 	NO_SSC,
233078e9e92SSwapnil Jakhade 	EXTERNAL_SSC,
234078e9e92SSwapnil Jakhade 	INTERNAL_SSC
235078e9e92SSwapnil Jakhade };
236078e9e92SSwapnil Jakhade 
23744d30d62SAlan Douglas struct cdns_sierra_inst {
23844d30d62SAlan Douglas 	struct phy *phy;
239078e9e92SSwapnil Jakhade 	enum cdns_sierra_phy_type phy_type;
24044d30d62SAlan Douglas 	u32 num_lanes;
24144d30d62SAlan Douglas 	u32 mlane;
24244d30d62SAlan Douglas 	struct reset_control *lnk_rst;
2431e902b2aSSwapnil Jakhade 	enum cdns_sierra_ssc_mode ssc_mode;
24444d30d62SAlan Douglas };
24544d30d62SAlan Douglas 
24644d30d62SAlan Douglas struct cdns_reg_pairs {
24744d30d62SAlan Douglas 	u16 val;
24844d30d62SAlan Douglas 	u32 off;
24944d30d62SAlan Douglas };
25044d30d62SAlan Douglas 
251078e9e92SSwapnil Jakhade struct cdns_sierra_vals {
252078e9e92SSwapnil Jakhade 	const struct cdns_reg_pairs *reg_pairs;
253078e9e92SSwapnil Jakhade 	u32 num_regs;
254078e9e92SSwapnil Jakhade };
255078e9e92SSwapnil Jakhade 
25644d30d62SAlan Douglas struct cdns_sierra_data {
25744d30d62SAlan Douglas 	u32 id_value;
258380f5708SKishon Vijay Abraham I 	u8 block_offset_shift;
259380f5708SKishon Vijay Abraham I 	u8 reg_offset_shift;
260*fa105172SSwapnil Jakhade 	struct cdns_sierra_vals *pcs_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
261*fa105172SSwapnil Jakhade 					     [NUM_SSC_MODE];
262078e9e92SSwapnil Jakhade 	struct cdns_sierra_vals *pma_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
263078e9e92SSwapnil Jakhade 					     [NUM_SSC_MODE];
264078e9e92SSwapnil Jakhade 	struct cdns_sierra_vals *pma_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
265078e9e92SSwapnil Jakhade 					    [NUM_SSC_MODE];
26644d30d62SAlan Douglas };
26744d30d62SAlan Douglas 
268380f5708SKishon Vijay Abraham I struct cdns_regmap_cdb_context {
26944d30d62SAlan Douglas 	struct device *dev;
27044d30d62SAlan Douglas 	void __iomem *base;
271380f5708SKishon Vijay Abraham I 	u8 reg_offset_shift;
272380f5708SKishon Vijay Abraham I };
273380f5708SKishon Vijay Abraham I 
274380f5708SKishon Vijay Abraham I struct cdns_sierra_phy {
275380f5708SKishon Vijay Abraham I 	struct device *dev;
276380f5708SKishon Vijay Abraham I 	struct regmap *regmap;
277c3c11d55SSwapnil Jakhade 	const struct cdns_sierra_data *init_data;
27844d30d62SAlan Douglas 	struct cdns_sierra_inst phys[SIERRA_MAX_LANES];
27944d30d62SAlan Douglas 	struct reset_control *phy_rst;
28044d30d62SAlan Douglas 	struct reset_control *apb_rst;
281380f5708SKishon Vijay Abraham I 	struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES];
2828c95e172SSwapnil Jakhade 	struct regmap *regmap_phy_pcs_common_cdb;
283380f5708SKishon Vijay Abraham I 	struct regmap *regmap_common_cdb;
284380f5708SKishon Vijay Abraham I 	struct regmap_field *macro_id_type;
285380f5708SKishon Vijay Abraham I 	struct regmap_field *phy_pll_cfg_1;
286adc4bd6fSKishon Vijay Abraham I 	struct regmap_field *pllctrl_lock[SIERRA_MAX_LANES];
28728081b72SKishon Vijay Abraham I 	struct regmap_field *cmn_refrcv_refclk_plllc1en_preg[SIERRA_NUM_CMN_PLLC];
28828081b72SKishon Vijay Abraham I 	struct regmap_field *cmn_refrcv_refclk_termen_preg[SIERRA_NUM_CMN_PLLC];
28928081b72SKishon Vijay Abraham I 	struct regmap_field *cmn_plllc_pfdclk1_sel_preg[SIERRA_NUM_CMN_PLLC];
290a0c30cd7SKishon Vijay Abraham I 	struct clk *input_clks[CDNS_SIERRA_INPUT_CLOCKS];
29144d30d62SAlan Douglas 	int nsubnodes;
292a43f72aeSKishon Vijay Abraham I 	u32 num_lanes;
29344d30d62SAlan Douglas 	bool autoconf;
29428081b72SKishon Vijay Abraham I 	struct clk_onecell_data clk_data;
29528081b72SKishon Vijay Abraham I 	struct clk *output_clks[CDNS_SIERRA_OUTPUT_CLOCKS];
29644d30d62SAlan Douglas };
29744d30d62SAlan Douglas 
298380f5708SKishon Vijay Abraham I static int cdns_regmap_write(void *context, unsigned int reg, unsigned int val)
299380f5708SKishon Vijay Abraham I {
300380f5708SKishon Vijay Abraham I 	struct cdns_regmap_cdb_context *ctx = context;
301380f5708SKishon Vijay Abraham I 	u32 offset = reg << ctx->reg_offset_shift;
302380f5708SKishon Vijay Abraham I 
303380f5708SKishon Vijay Abraham I 	writew(val, ctx->base + offset);
304380f5708SKishon Vijay Abraham I 
305380f5708SKishon Vijay Abraham I 	return 0;
306380f5708SKishon Vijay Abraham I }
307380f5708SKishon Vijay Abraham I 
308380f5708SKishon Vijay Abraham I static int cdns_regmap_read(void *context, unsigned int reg, unsigned int *val)
309380f5708SKishon Vijay Abraham I {
310380f5708SKishon Vijay Abraham I 	struct cdns_regmap_cdb_context *ctx = context;
311380f5708SKishon Vijay Abraham I 	u32 offset = reg << ctx->reg_offset_shift;
312380f5708SKishon Vijay Abraham I 
313380f5708SKishon Vijay Abraham I 	*val = readw(ctx->base + offset);
314380f5708SKishon Vijay Abraham I 	return 0;
315380f5708SKishon Vijay Abraham I }
316380f5708SKishon Vijay Abraham I 
317380f5708SKishon Vijay Abraham I #define SIERRA_LANE_CDB_REGMAP_CONF(n) \
318380f5708SKishon Vijay Abraham I { \
319380f5708SKishon Vijay Abraham I 	.name = "sierra_lane" n "_cdb", \
320380f5708SKishon Vijay Abraham I 	.reg_stride = 1, \
321380f5708SKishon Vijay Abraham I 	.fast_io = true, \
322380f5708SKishon Vijay Abraham I 	.reg_write = cdns_regmap_write, \
323380f5708SKishon Vijay Abraham I 	.reg_read = cdns_regmap_read, \
324380f5708SKishon Vijay Abraham I }
325380f5708SKishon Vijay Abraham I 
3263cfb0e8eSRikard Falkeborn static const struct regmap_config cdns_sierra_lane_cdb_config[] = {
327380f5708SKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("0"),
328380f5708SKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("1"),
329380f5708SKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("2"),
330380f5708SKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("3"),
331a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("4"),
332a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("5"),
333a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("6"),
334a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("7"),
335a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("8"),
336a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("9"),
337a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("10"),
338a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("11"),
339a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("12"),
340a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("13"),
341a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("14"),
342a43f72aeSKishon Vijay Abraham I 	SIERRA_LANE_CDB_REGMAP_CONF("15"),
343380f5708SKishon Vijay Abraham I };
344380f5708SKishon Vijay Abraham I 
3453cfb0e8eSRikard Falkeborn static const struct regmap_config cdns_sierra_common_cdb_config = {
346380f5708SKishon Vijay Abraham I 	.name = "sierra_common_cdb",
347380f5708SKishon Vijay Abraham I 	.reg_stride = 1,
348380f5708SKishon Vijay Abraham I 	.fast_io = true,
349380f5708SKishon Vijay Abraham I 	.reg_write = cdns_regmap_write,
350380f5708SKishon Vijay Abraham I 	.reg_read = cdns_regmap_read,
351380f5708SKishon Vijay Abraham I };
352380f5708SKishon Vijay Abraham I 
3538c95e172SSwapnil Jakhade static const struct regmap_config cdns_sierra_phy_pcs_cmn_cdb_config = {
3548c95e172SSwapnil Jakhade 	.name = "sierra_phy_pcs_cmn_cdb",
355380f5708SKishon Vijay Abraham I 	.reg_stride = 1,
356380f5708SKishon Vijay Abraham I 	.fast_io = true,
357380f5708SKishon Vijay Abraham I 	.reg_write = cdns_regmap_write,
358380f5708SKishon Vijay Abraham I 	.reg_read = cdns_regmap_read,
359380f5708SKishon Vijay Abraham I };
360380f5708SKishon Vijay Abraham I 
361cedcc2e2SKishon Vijay Abraham I static int cdns_sierra_phy_init(struct phy *gphy)
36244d30d62SAlan Douglas {
36344d30d62SAlan Douglas 	struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
36444d30d62SAlan Douglas 	struct cdns_sierra_phy *phy = dev_get_drvdata(gphy->dev.parent);
365078e9e92SSwapnil Jakhade 	const struct cdns_sierra_data *init_data = phy->init_data;
366078e9e92SSwapnil Jakhade 	struct cdns_sierra_vals *pma_cmn_vals, *pma_ln_vals;
367078e9e92SSwapnil Jakhade 	enum cdns_sierra_phy_type phy_type = ins->phy_type;
3681e902b2aSSwapnil Jakhade 	enum cdns_sierra_ssc_mode ssc = ins->ssc_mode;
369078e9e92SSwapnil Jakhade 	const struct cdns_reg_pairs *reg_pairs;
370*fa105172SSwapnil Jakhade 	struct cdns_sierra_vals *pcs_cmn_vals;
37180f96fb1SColin Ian King 	struct regmap *regmap;
372078e9e92SSwapnil Jakhade 	u32 num_regs;
37344d30d62SAlan Douglas 	int i, j;
37444d30d62SAlan Douglas 
375cedcc2e2SKishon Vijay Abraham I 	/* Initialise the PHY registers, unless auto configured */
376cedcc2e2SKishon Vijay Abraham I 	if (phy->autoconf)
377cedcc2e2SKishon Vijay Abraham I 		return 0;
378cedcc2e2SKishon Vijay Abraham I 
379a0c30cd7SKishon Vijay Abraham I 	clk_set_rate(phy->input_clks[CMN_REFCLK_DIG_DIV], 25000000);
380a0c30cd7SKishon Vijay Abraham I 	clk_set_rate(phy->input_clks[CMN_REFCLK1_DIG_DIV], 25000000);
381078e9e92SSwapnil Jakhade 
382*fa105172SSwapnil Jakhade 	/* PHY PCS common registers configurations */
383*fa105172SSwapnil Jakhade 	pcs_cmn_vals = init_data->pcs_cmn_vals[phy_type][TYPE_NONE][ssc];
384*fa105172SSwapnil Jakhade 	if (pcs_cmn_vals) {
385*fa105172SSwapnil Jakhade 		reg_pairs = pcs_cmn_vals->reg_pairs;
386*fa105172SSwapnil Jakhade 		num_regs = pcs_cmn_vals->num_regs;
387*fa105172SSwapnil Jakhade 		regmap = phy->regmap_phy_pcs_common_cdb;
388*fa105172SSwapnil Jakhade 		for (i = 0; i < num_regs; i++)
389*fa105172SSwapnil Jakhade 			regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
390*fa105172SSwapnil Jakhade 	}
391*fa105172SSwapnil Jakhade 
392078e9e92SSwapnil Jakhade 	/* PMA common registers configurations */
393078e9e92SSwapnil Jakhade 	pma_cmn_vals = init_data->pma_cmn_vals[phy_type][TYPE_NONE][ssc];
394078e9e92SSwapnil Jakhade 	if (pma_cmn_vals) {
395078e9e92SSwapnil Jakhade 		reg_pairs = pma_cmn_vals->reg_pairs;
396078e9e92SSwapnil Jakhade 		num_regs = pma_cmn_vals->num_regs;
397078e9e92SSwapnil Jakhade 		regmap = phy->regmap_common_cdb;
398078e9e92SSwapnil Jakhade 		for (i = 0; i < num_regs; i++)
399078e9e92SSwapnil Jakhade 			regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
40044d30d62SAlan Douglas 	}
401871002d7SAnil Varughese 
402078e9e92SSwapnil Jakhade 	/* PMA lane registers configurations */
403078e9e92SSwapnil Jakhade 	pma_ln_vals = init_data->pma_ln_vals[phy_type][TYPE_NONE][ssc];
404078e9e92SSwapnil Jakhade 	if (pma_ln_vals) {
405078e9e92SSwapnil Jakhade 		reg_pairs = pma_ln_vals->reg_pairs;
406078e9e92SSwapnil Jakhade 		num_regs = pma_ln_vals->num_regs;
407380f5708SKishon Vijay Abraham I 		for (i = 0; i < ins->num_lanes; i++) {
408380f5708SKishon Vijay Abraham I 			regmap = phy->regmap_lane_cdb[i + ins->mlane];
409078e9e92SSwapnil Jakhade 			for (j = 0; j < num_regs; j++)
410078e9e92SSwapnil Jakhade 				regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val);
411380f5708SKishon Vijay Abraham I 		}
412380f5708SKishon Vijay Abraham I 	}
413cedcc2e2SKishon Vijay Abraham I 
414cedcc2e2SKishon Vijay Abraham I 	return 0;
41544d30d62SAlan Douglas }
41644d30d62SAlan Douglas 
41744d30d62SAlan Douglas static int cdns_sierra_phy_on(struct phy *gphy)
41844d30d62SAlan Douglas {
419adc4bd6fSKishon Vijay Abraham I 	struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent);
42044d30d62SAlan Douglas 	struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
421adc4bd6fSKishon Vijay Abraham I 	struct device *dev = sp->dev;
422adc4bd6fSKishon Vijay Abraham I 	u32 val;
423adc4bd6fSKishon Vijay Abraham I 	int ret;
42444d30d62SAlan Douglas 
4255b4f5757SKishon Vijay Abraham I 	ret = reset_control_deassert(sp->phy_rst);
4265b4f5757SKishon Vijay Abraham I 	if (ret) {
4275b4f5757SKishon Vijay Abraham I 		dev_err(dev, "Failed to take the PHY out of reset\n");
4285b4f5757SKishon Vijay Abraham I 		return ret;
4295b4f5757SKishon Vijay Abraham I 	}
4305b4f5757SKishon Vijay Abraham I 
43144d30d62SAlan Douglas 	/* Take the PHY lane group out of reset */
432adc4bd6fSKishon Vijay Abraham I 	ret = reset_control_deassert(ins->lnk_rst);
433adc4bd6fSKishon Vijay Abraham I 	if (ret) {
434adc4bd6fSKishon Vijay Abraham I 		dev_err(dev, "Failed to take the PHY lane out of reset\n");
435adc4bd6fSKishon Vijay Abraham I 		return ret;
436adc4bd6fSKishon Vijay Abraham I 	}
437adc4bd6fSKishon Vijay Abraham I 
438adc4bd6fSKishon Vijay Abraham I 	ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane],
439adc4bd6fSKishon Vijay Abraham I 					     val, val, 1000, PLL_LOCK_TIME);
440adc4bd6fSKishon Vijay Abraham I 	if (ret < 0)
441adc4bd6fSKishon Vijay Abraham I 		dev_err(dev, "PLL lock of lane failed\n");
442adc4bd6fSKishon Vijay Abraham I 
443adc4bd6fSKishon Vijay Abraham I 	return ret;
44444d30d62SAlan Douglas }
44544d30d62SAlan Douglas 
44644d30d62SAlan Douglas static int cdns_sierra_phy_off(struct phy *gphy)
44744d30d62SAlan Douglas {
44844d30d62SAlan Douglas 	struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
44944d30d62SAlan Douglas 
45044d30d62SAlan Douglas 	return reset_control_assert(ins->lnk_rst);
45144d30d62SAlan Douglas }
45244d30d62SAlan Douglas 
4537904e15bSRoger Quadros static int cdns_sierra_phy_reset(struct phy *gphy)
4547904e15bSRoger Quadros {
4557904e15bSRoger Quadros 	struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent);
4567904e15bSRoger Quadros 
4577904e15bSRoger Quadros 	reset_control_assert(sp->phy_rst);
4587904e15bSRoger Quadros 	reset_control_deassert(sp->phy_rst);
4597904e15bSRoger Quadros 	return 0;
4607904e15bSRoger Quadros };
4617904e15bSRoger Quadros 
46244d30d62SAlan Douglas static const struct phy_ops ops = {
463cedcc2e2SKishon Vijay Abraham I 	.init		= cdns_sierra_phy_init,
46444d30d62SAlan Douglas 	.power_on	= cdns_sierra_phy_on,
46544d30d62SAlan Douglas 	.power_off	= cdns_sierra_phy_off,
4667904e15bSRoger Quadros 	.reset		= cdns_sierra_phy_reset,
46744d30d62SAlan Douglas 	.owner		= THIS_MODULE,
46844d30d62SAlan Douglas };
46944d30d62SAlan Douglas 
47028081b72SKishon Vijay Abraham I static u8 cdns_sierra_pll_mux_get_parent(struct clk_hw *hw)
47128081b72SKishon Vijay Abraham I {
47228081b72SKishon Vijay Abraham I 	struct cdns_sierra_pll_mux *mux = to_cdns_sierra_pll_mux(hw);
47328081b72SKishon Vijay Abraham I 	struct regmap_field *field = mux->pfdclk_sel_preg;
47428081b72SKishon Vijay Abraham I 	unsigned int val;
47528081b72SKishon Vijay Abraham I 
47628081b72SKishon Vijay Abraham I 	regmap_field_read(field, &val);
47728081b72SKishon Vijay Abraham I 	return clk_mux_val_to_index(hw, cdns_sierra_pll_mux_table, 0, val);
47828081b72SKishon Vijay Abraham I }
47928081b72SKishon Vijay Abraham I 
48028081b72SKishon Vijay Abraham I static int cdns_sierra_pll_mux_set_parent(struct clk_hw *hw, u8 index)
48128081b72SKishon Vijay Abraham I {
48228081b72SKishon Vijay Abraham I 	struct cdns_sierra_pll_mux *mux = to_cdns_sierra_pll_mux(hw);
48328081b72SKishon Vijay Abraham I 	struct regmap_field *plllc1en_field = mux->plllc1en_field;
48428081b72SKishon Vijay Abraham I 	struct regmap_field *termen_field = mux->termen_field;
48528081b72SKishon Vijay Abraham I 	struct regmap_field *field = mux->pfdclk_sel_preg;
48628081b72SKishon Vijay Abraham I 	int val, ret;
48728081b72SKishon Vijay Abraham I 
48828081b72SKishon Vijay Abraham I 	ret = regmap_field_write(plllc1en_field, 0);
48928081b72SKishon Vijay Abraham I 	ret |= regmap_field_write(termen_field, 0);
49028081b72SKishon Vijay Abraham I 	if (index == 1) {
49128081b72SKishon Vijay Abraham I 		ret |= regmap_field_write(plllc1en_field, 1);
49228081b72SKishon Vijay Abraham I 		ret |= regmap_field_write(termen_field, 1);
49328081b72SKishon Vijay Abraham I 	}
49428081b72SKishon Vijay Abraham I 
49528081b72SKishon Vijay Abraham I 	val = cdns_sierra_pll_mux_table[index];
49628081b72SKishon Vijay Abraham I 	ret |= regmap_field_write(field, val);
49728081b72SKishon Vijay Abraham I 
49828081b72SKishon Vijay Abraham I 	return ret;
49928081b72SKishon Vijay Abraham I }
50028081b72SKishon Vijay Abraham I 
50128081b72SKishon Vijay Abraham I static const struct clk_ops cdns_sierra_pll_mux_ops = {
50228081b72SKishon Vijay Abraham I 	.set_parent = cdns_sierra_pll_mux_set_parent,
50328081b72SKishon Vijay Abraham I 	.get_parent = cdns_sierra_pll_mux_get_parent,
50428081b72SKishon Vijay Abraham I };
50528081b72SKishon Vijay Abraham I 
50628081b72SKishon Vijay Abraham I static int cdns_sierra_pll_mux_register(struct cdns_sierra_phy *sp,
50728081b72SKishon Vijay Abraham I 					struct regmap_field *pfdclk1_sel_field,
50828081b72SKishon Vijay Abraham I 					struct regmap_field *plllc1en_field,
50928081b72SKishon Vijay Abraham I 					struct regmap_field *termen_field,
51028081b72SKishon Vijay Abraham I 					int clk_index)
51128081b72SKishon Vijay Abraham I {
51228081b72SKishon Vijay Abraham I 	struct cdns_sierra_pll_mux *mux;
51328081b72SKishon Vijay Abraham I 	struct device *dev = sp->dev;
51428081b72SKishon Vijay Abraham I 	struct clk_init_data *init;
51528081b72SKishon Vijay Abraham I 	const char **parent_names;
51628081b72SKishon Vijay Abraham I 	unsigned int num_parents;
51728081b72SKishon Vijay Abraham I 	char clk_name[100];
51828081b72SKishon Vijay Abraham I 	struct clk *clk;
51928081b72SKishon Vijay Abraham I 	int i;
52028081b72SKishon Vijay Abraham I 
52128081b72SKishon Vijay Abraham I 	mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
52228081b72SKishon Vijay Abraham I 	if (!mux)
52328081b72SKishon Vijay Abraham I 		return -ENOMEM;
52428081b72SKishon Vijay Abraham I 
52528081b72SKishon Vijay Abraham I 	num_parents = SIERRA_NUM_CMN_PLLC_PARENTS;
52628081b72SKishon Vijay Abraham I 	parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), GFP_KERNEL);
52728081b72SKishon Vijay Abraham I 	if (!parent_names)
52828081b72SKishon Vijay Abraham I 		return -ENOMEM;
52928081b72SKishon Vijay Abraham I 
53028081b72SKishon Vijay Abraham I 	for (i = 0; i < num_parents; i++) {
53128081b72SKishon Vijay Abraham I 		clk = sp->input_clks[pll_mux_parent_index[clk_index][i]];
53228081b72SKishon Vijay Abraham I 		if (IS_ERR_OR_NULL(clk)) {
53328081b72SKishon Vijay Abraham I 			dev_err(dev, "No parent clock for derived_refclk\n");
53428081b72SKishon Vijay Abraham I 			return PTR_ERR(clk);
53528081b72SKishon Vijay Abraham I 		}
53628081b72SKishon Vijay Abraham I 		parent_names[i] = __clk_get_name(clk);
53728081b72SKishon Vijay Abraham I 	}
53828081b72SKishon Vijay Abraham I 
53928081b72SKishon Vijay Abraham I 	snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), clk_names[clk_index]);
54028081b72SKishon Vijay Abraham I 
54128081b72SKishon Vijay Abraham I 	init = &mux->clk_data;
54228081b72SKishon Vijay Abraham I 
54328081b72SKishon Vijay Abraham I 	init->ops = &cdns_sierra_pll_mux_ops;
54428081b72SKishon Vijay Abraham I 	init->flags = CLK_SET_RATE_NO_REPARENT;
54528081b72SKishon Vijay Abraham I 	init->parent_names = parent_names;
54628081b72SKishon Vijay Abraham I 	init->num_parents = num_parents;
54728081b72SKishon Vijay Abraham I 	init->name = clk_name;
54828081b72SKishon Vijay Abraham I 
54928081b72SKishon Vijay Abraham I 	mux->pfdclk_sel_preg = pfdclk1_sel_field;
55028081b72SKishon Vijay Abraham I 	mux->plllc1en_field = plllc1en_field;
55128081b72SKishon Vijay Abraham I 	mux->termen_field = termen_field;
55228081b72SKishon Vijay Abraham I 	mux->hw.init = init;
55328081b72SKishon Vijay Abraham I 
55428081b72SKishon Vijay Abraham I 	clk = devm_clk_register(dev, &mux->hw);
55528081b72SKishon Vijay Abraham I 	if (IS_ERR(clk))
55628081b72SKishon Vijay Abraham I 		return PTR_ERR(clk);
55728081b72SKishon Vijay Abraham I 
55828081b72SKishon Vijay Abraham I 	sp->output_clks[clk_index] = clk;
55928081b72SKishon Vijay Abraham I 
56028081b72SKishon Vijay Abraham I 	return 0;
56128081b72SKishon Vijay Abraham I }
56228081b72SKishon Vijay Abraham I 
56328081b72SKishon Vijay Abraham I static int cdns_sierra_phy_register_pll_mux(struct cdns_sierra_phy *sp)
56428081b72SKishon Vijay Abraham I {
56528081b72SKishon Vijay Abraham I 	struct regmap_field *pfdclk1_sel_field;
56628081b72SKishon Vijay Abraham I 	struct regmap_field *plllc1en_field;
56728081b72SKishon Vijay Abraham I 	struct regmap_field *termen_field;
56828081b72SKishon Vijay Abraham I 	struct device *dev = sp->dev;
56928081b72SKishon Vijay Abraham I 	int ret = 0, i, clk_index;
57028081b72SKishon Vijay Abraham I 
57128081b72SKishon Vijay Abraham I 	clk_index = CDNS_SIERRA_PLL_CMNLC;
57228081b72SKishon Vijay Abraham I 	for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++, clk_index++) {
57328081b72SKishon Vijay Abraham I 		pfdclk1_sel_field = sp->cmn_plllc_pfdclk1_sel_preg[i];
57428081b72SKishon Vijay Abraham I 		plllc1en_field = sp->cmn_refrcv_refclk_plllc1en_preg[i];
57528081b72SKishon Vijay Abraham I 		termen_field = sp->cmn_refrcv_refclk_termen_preg[i];
57628081b72SKishon Vijay Abraham I 
57728081b72SKishon Vijay Abraham I 		ret = cdns_sierra_pll_mux_register(sp, pfdclk1_sel_field, plllc1en_field,
57828081b72SKishon Vijay Abraham I 						   termen_field, clk_index);
57928081b72SKishon Vijay Abraham I 		if (ret) {
58028081b72SKishon Vijay Abraham I 			dev_err(dev, "Fail to register cmn plllc mux\n");
58128081b72SKishon Vijay Abraham I 			return ret;
58228081b72SKishon Vijay Abraham I 		}
58328081b72SKishon Vijay Abraham I 	}
58428081b72SKishon Vijay Abraham I 
58528081b72SKishon Vijay Abraham I 	return 0;
58628081b72SKishon Vijay Abraham I }
58728081b72SKishon Vijay Abraham I 
58828081b72SKishon Vijay Abraham I static void cdns_sierra_clk_unregister(struct cdns_sierra_phy *sp)
58928081b72SKishon Vijay Abraham I {
59028081b72SKishon Vijay Abraham I 	struct device *dev = sp->dev;
59128081b72SKishon Vijay Abraham I 	struct device_node *node = dev->of_node;
59228081b72SKishon Vijay Abraham I 
59328081b72SKishon Vijay Abraham I 	of_clk_del_provider(node);
59428081b72SKishon Vijay Abraham I }
59528081b72SKishon Vijay Abraham I 
59628081b72SKishon Vijay Abraham I static int cdns_sierra_clk_register(struct cdns_sierra_phy *sp)
59728081b72SKishon Vijay Abraham I {
59828081b72SKishon Vijay Abraham I 	struct device *dev = sp->dev;
59928081b72SKishon Vijay Abraham I 	struct device_node *node = dev->of_node;
60028081b72SKishon Vijay Abraham I 	int ret;
60128081b72SKishon Vijay Abraham I 
60228081b72SKishon Vijay Abraham I 	ret = cdns_sierra_phy_register_pll_mux(sp);
60328081b72SKishon Vijay Abraham I 	if (ret) {
60428081b72SKishon Vijay Abraham I 		dev_err(dev, "Failed to pll mux clocks\n");
60528081b72SKishon Vijay Abraham I 		return ret;
60628081b72SKishon Vijay Abraham I 	}
60728081b72SKishon Vijay Abraham I 
60828081b72SKishon Vijay Abraham I 	sp->clk_data.clks = sp->output_clks;
60928081b72SKishon Vijay Abraham I 	sp->clk_data.clk_num = CDNS_SIERRA_OUTPUT_CLOCKS;
61028081b72SKishon Vijay Abraham I 	ret = of_clk_add_provider(node, of_clk_src_onecell_get, &sp->clk_data);
61128081b72SKishon Vijay Abraham I 	if (ret)
61228081b72SKishon Vijay Abraham I 		dev_err(dev, "Failed to add clock provider: %s\n", node->name);
61328081b72SKishon Vijay Abraham I 
61428081b72SKishon Vijay Abraham I 	return ret;
61528081b72SKishon Vijay Abraham I }
61628081b72SKishon Vijay Abraham I 
61744d30d62SAlan Douglas static int cdns_sierra_get_optional(struct cdns_sierra_inst *inst,
61844d30d62SAlan Douglas 				    struct device_node *child)
61944d30d62SAlan Douglas {
620078e9e92SSwapnil Jakhade 	u32 phy_type;
621078e9e92SSwapnil Jakhade 
62244d30d62SAlan Douglas 	if (of_property_read_u32(child, "reg", &inst->mlane))
62344d30d62SAlan Douglas 		return -EINVAL;
62444d30d62SAlan Douglas 
62544d30d62SAlan Douglas 	if (of_property_read_u32(child, "cdns,num-lanes", &inst->num_lanes))
62644d30d62SAlan Douglas 		return -EINVAL;
62744d30d62SAlan Douglas 
628078e9e92SSwapnil Jakhade 	if (of_property_read_u32(child, "cdns,phy-type", &phy_type))
62944d30d62SAlan Douglas 		return -EINVAL;
63044d30d62SAlan Douglas 
631078e9e92SSwapnil Jakhade 	switch (phy_type) {
632078e9e92SSwapnil Jakhade 	case PHY_TYPE_PCIE:
633078e9e92SSwapnil Jakhade 		inst->phy_type = TYPE_PCIE;
634078e9e92SSwapnil Jakhade 		break;
635078e9e92SSwapnil Jakhade 	case PHY_TYPE_USB3:
636078e9e92SSwapnil Jakhade 		inst->phy_type = TYPE_USB;
637078e9e92SSwapnil Jakhade 		break;
638078e9e92SSwapnil Jakhade 	default:
639078e9e92SSwapnil Jakhade 		return -EINVAL;
640078e9e92SSwapnil Jakhade 	}
641078e9e92SSwapnil Jakhade 
6421e902b2aSSwapnil Jakhade 	inst->ssc_mode = EXTERNAL_SSC;
6431e902b2aSSwapnil Jakhade 	of_property_read_u32(child, "cdns,ssc-mode", &inst->ssc_mode);
6441e902b2aSSwapnil Jakhade 
64544d30d62SAlan Douglas 	return 0;
64644d30d62SAlan Douglas }
64744d30d62SAlan Douglas 
648380f5708SKishon Vijay Abraham I static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base,
649380f5708SKishon Vijay Abraham I 				       u32 block_offset, u8 reg_offset_shift,
650380f5708SKishon Vijay Abraham I 				       const struct regmap_config *config)
651380f5708SKishon Vijay Abraham I {
652380f5708SKishon Vijay Abraham I 	struct cdns_regmap_cdb_context *ctx;
653380f5708SKishon Vijay Abraham I 
654380f5708SKishon Vijay Abraham I 	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
655380f5708SKishon Vijay Abraham I 	if (!ctx)
656380f5708SKishon Vijay Abraham I 		return ERR_PTR(-ENOMEM);
657380f5708SKishon Vijay Abraham I 
658380f5708SKishon Vijay Abraham I 	ctx->dev = dev;
659380f5708SKishon Vijay Abraham I 	ctx->base = base + block_offset;
660380f5708SKishon Vijay Abraham I 	ctx->reg_offset_shift = reg_offset_shift;
661380f5708SKishon Vijay Abraham I 
662380f5708SKishon Vijay Abraham I 	return devm_regmap_init(dev, NULL, ctx, config);
663380f5708SKishon Vijay Abraham I }
664380f5708SKishon Vijay Abraham I 
665380f5708SKishon Vijay Abraham I static int cdns_regfield_init(struct cdns_sierra_phy *sp)
666380f5708SKishon Vijay Abraham I {
667380f5708SKishon Vijay Abraham I 	struct device *dev = sp->dev;
668380f5708SKishon Vijay Abraham I 	struct regmap_field *field;
66928081b72SKishon Vijay Abraham I 	struct reg_field reg_field;
670380f5708SKishon Vijay Abraham I 	struct regmap *regmap;
671adc4bd6fSKishon Vijay Abraham I 	int i;
672380f5708SKishon Vijay Abraham I 
673380f5708SKishon Vijay Abraham I 	regmap = sp->regmap_common_cdb;
674380f5708SKishon Vijay Abraham I 	field = devm_regmap_field_alloc(dev, regmap, macro_id_type);
675380f5708SKishon Vijay Abraham I 	if (IS_ERR(field)) {
676380f5708SKishon Vijay Abraham I 		dev_err(dev, "MACRO_ID_TYPE reg field init failed\n");
677380f5708SKishon Vijay Abraham I 		return PTR_ERR(field);
678380f5708SKishon Vijay Abraham I 	}
679380f5708SKishon Vijay Abraham I 	sp->macro_id_type = field;
680380f5708SKishon Vijay Abraham I 
68128081b72SKishon Vijay Abraham I 	for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++) {
68228081b72SKishon Vijay Abraham I 		reg_field = cmn_plllc_pfdclk1_sel_preg[i].pfdclk_sel_preg;
68328081b72SKishon Vijay Abraham I 		field = devm_regmap_field_alloc(dev, regmap, reg_field);
68428081b72SKishon Vijay Abraham I 		if (IS_ERR(field)) {
68528081b72SKishon Vijay Abraham I 			dev_err(dev, "PLLLC%d_PFDCLK1_SEL failed\n", i);
68628081b72SKishon Vijay Abraham I 			return PTR_ERR(field);
68728081b72SKishon Vijay Abraham I 		}
68828081b72SKishon Vijay Abraham I 		sp->cmn_plllc_pfdclk1_sel_preg[i] = field;
68928081b72SKishon Vijay Abraham I 
69028081b72SKishon Vijay Abraham I 		reg_field = cmn_plllc_pfdclk1_sel_preg[i].plllc1en_field;
69128081b72SKishon Vijay Abraham I 		field = devm_regmap_field_alloc(dev, regmap, reg_field);
69228081b72SKishon Vijay Abraham I 		if (IS_ERR(field)) {
69328081b72SKishon Vijay Abraham I 			dev_err(dev, "REFRCV%d_REFCLK_PLLLC1EN failed\n", i);
69428081b72SKishon Vijay Abraham I 			return PTR_ERR(field);
69528081b72SKishon Vijay Abraham I 		}
69628081b72SKishon Vijay Abraham I 		sp->cmn_refrcv_refclk_plllc1en_preg[i] = field;
69728081b72SKishon Vijay Abraham I 
69828081b72SKishon Vijay Abraham I 		reg_field = cmn_plllc_pfdclk1_sel_preg[i].termen_field;
69928081b72SKishon Vijay Abraham I 		field = devm_regmap_field_alloc(dev, regmap, reg_field);
70028081b72SKishon Vijay Abraham I 		if (IS_ERR(field)) {
70128081b72SKishon Vijay Abraham I 			dev_err(dev, "REFRCV%d_REFCLK_TERMEN failed\n", i);
70228081b72SKishon Vijay Abraham I 			return PTR_ERR(field);
70328081b72SKishon Vijay Abraham I 		}
70428081b72SKishon Vijay Abraham I 		sp->cmn_refrcv_refclk_termen_preg[i] = field;
70528081b72SKishon Vijay Abraham I 	}
70628081b72SKishon Vijay Abraham I 
7078c95e172SSwapnil Jakhade 	regmap = sp->regmap_phy_pcs_common_cdb;
708380f5708SKishon Vijay Abraham I 	field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1);
709380f5708SKishon Vijay Abraham I 	if (IS_ERR(field)) {
710380f5708SKishon Vijay Abraham I 		dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n");
711380f5708SKishon Vijay Abraham I 		return PTR_ERR(field);
712380f5708SKishon Vijay Abraham I 	}
713380f5708SKishon Vijay Abraham I 	sp->phy_pll_cfg_1 = field;
714380f5708SKishon Vijay Abraham I 
715adc4bd6fSKishon Vijay Abraham I 	for (i = 0; i < SIERRA_MAX_LANES; i++) {
716adc4bd6fSKishon Vijay Abraham I 		regmap = sp->regmap_lane_cdb[i];
717adc4bd6fSKishon Vijay Abraham I 		field = devm_regmap_field_alloc(dev, regmap, pllctrl_lock);
718adc4bd6fSKishon Vijay Abraham I 		if (IS_ERR(field)) {
719adc4bd6fSKishon Vijay Abraham I 			dev_err(dev, "P%d_ENABLE reg field init failed\n", i);
720adc4bd6fSKishon Vijay Abraham I 			return PTR_ERR(field);
721adc4bd6fSKishon Vijay Abraham I 		}
722adc4bd6fSKishon Vijay Abraham I 		sp->pllctrl_lock[i] =  field;
723adc4bd6fSKishon Vijay Abraham I 	}
724adc4bd6fSKishon Vijay Abraham I 
725380f5708SKishon Vijay Abraham I 	return 0;
726380f5708SKishon Vijay Abraham I }
727380f5708SKishon Vijay Abraham I 
728380f5708SKishon Vijay Abraham I static int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp,
729380f5708SKishon Vijay Abraham I 				   void __iomem *base, u8 block_offset_shift,
730380f5708SKishon Vijay Abraham I 				   u8 reg_offset_shift)
731380f5708SKishon Vijay Abraham I {
732380f5708SKishon Vijay Abraham I 	struct device *dev = sp->dev;
733380f5708SKishon Vijay Abraham I 	struct regmap *regmap;
734380f5708SKishon Vijay Abraham I 	u32 block_offset;
735380f5708SKishon Vijay Abraham I 	int i;
736380f5708SKishon Vijay Abraham I 
737380f5708SKishon Vijay Abraham I 	for (i = 0; i < SIERRA_MAX_LANES; i++) {
738380f5708SKishon Vijay Abraham I 		block_offset = SIERRA_LANE_CDB_OFFSET(i, block_offset_shift,
739380f5708SKishon Vijay Abraham I 						      reg_offset_shift);
740380f5708SKishon Vijay Abraham I 		regmap = cdns_regmap_init(dev, base, block_offset,
741380f5708SKishon Vijay Abraham I 					  reg_offset_shift,
742380f5708SKishon Vijay Abraham I 					  &cdns_sierra_lane_cdb_config[i]);
743380f5708SKishon Vijay Abraham I 		if (IS_ERR(regmap)) {
744380f5708SKishon Vijay Abraham I 			dev_err(dev, "Failed to init lane CDB regmap\n");
745380f5708SKishon Vijay Abraham I 			return PTR_ERR(regmap);
746380f5708SKishon Vijay Abraham I 		}
747380f5708SKishon Vijay Abraham I 		sp->regmap_lane_cdb[i] = regmap;
748380f5708SKishon Vijay Abraham I 	}
749380f5708SKishon Vijay Abraham I 
750380f5708SKishon Vijay Abraham I 	regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET,
751380f5708SKishon Vijay Abraham I 				  reg_offset_shift,
752380f5708SKishon Vijay Abraham I 				  &cdns_sierra_common_cdb_config);
753380f5708SKishon Vijay Abraham I 	if (IS_ERR(regmap)) {
754380f5708SKishon Vijay Abraham I 		dev_err(dev, "Failed to init common CDB regmap\n");
755380f5708SKishon Vijay Abraham I 		return PTR_ERR(regmap);
756380f5708SKishon Vijay Abraham I 	}
757380f5708SKishon Vijay Abraham I 	sp->regmap_common_cdb = regmap;
758380f5708SKishon Vijay Abraham I 
7598c95e172SSwapnil Jakhade 	block_offset = SIERRA_PHY_PCS_COMMON_OFFSET(block_offset_shift);
760380f5708SKishon Vijay Abraham I 	regmap = cdns_regmap_init(dev, base, block_offset, reg_offset_shift,
7618c95e172SSwapnil Jakhade 				  &cdns_sierra_phy_pcs_cmn_cdb_config);
762380f5708SKishon Vijay Abraham I 	if (IS_ERR(regmap)) {
7638c95e172SSwapnil Jakhade 		dev_err(dev, "Failed to init PHY PCS common CDB regmap\n");
764380f5708SKishon Vijay Abraham I 		return PTR_ERR(regmap);
765380f5708SKishon Vijay Abraham I 	}
7668c95e172SSwapnil Jakhade 	sp->regmap_phy_pcs_common_cdb = regmap;
767380f5708SKishon Vijay Abraham I 
768380f5708SKishon Vijay Abraham I 	return 0;
769380f5708SKishon Vijay Abraham I }
770380f5708SKishon Vijay Abraham I 
7717e016cbcSKishon Vijay Abraham I static int cdns_sierra_phy_get_clocks(struct cdns_sierra_phy *sp,
7727e016cbcSKishon Vijay Abraham I 				      struct device *dev)
7737e016cbcSKishon Vijay Abraham I {
7747e016cbcSKishon Vijay Abraham I 	struct clk *clk;
7757e016cbcSKishon Vijay Abraham I 	int ret;
7767e016cbcSKishon Vijay Abraham I 
7777e016cbcSKishon Vijay Abraham I 	clk = devm_clk_get_optional(dev, "phy_clk");
7787e016cbcSKishon Vijay Abraham I 	if (IS_ERR(clk)) {
7797e016cbcSKishon Vijay Abraham I 		dev_err(dev, "failed to get clock phy_clk\n");
7807e016cbcSKishon Vijay Abraham I 		return PTR_ERR(clk);
7817e016cbcSKishon Vijay Abraham I 	}
782a0c30cd7SKishon Vijay Abraham I 	sp->input_clks[PHY_CLK] = clk;
7837e016cbcSKishon Vijay Abraham I 
7847e016cbcSKishon Vijay Abraham I 	clk = devm_clk_get_optional(dev, "cmn_refclk_dig_div");
7857e016cbcSKishon Vijay Abraham I 	if (IS_ERR(clk)) {
7867e016cbcSKishon Vijay Abraham I 		dev_err(dev, "cmn_refclk_dig_div clock not found\n");
7877e016cbcSKishon Vijay Abraham I 		ret = PTR_ERR(clk);
7887e016cbcSKishon Vijay Abraham I 		return ret;
7897e016cbcSKishon Vijay Abraham I 	}
790a0c30cd7SKishon Vijay Abraham I 	sp->input_clks[CMN_REFCLK_DIG_DIV] = clk;
7917e016cbcSKishon Vijay Abraham I 
7927e016cbcSKishon Vijay Abraham I 	clk = devm_clk_get_optional(dev, "cmn_refclk1_dig_div");
7937e016cbcSKishon Vijay Abraham I 	if (IS_ERR(clk)) {
7947e016cbcSKishon Vijay Abraham I 		dev_err(dev, "cmn_refclk1_dig_div clock not found\n");
7957e016cbcSKishon Vijay Abraham I 		ret = PTR_ERR(clk);
7967e016cbcSKishon Vijay Abraham I 		return ret;
7977e016cbcSKishon Vijay Abraham I 	}
798a0c30cd7SKishon Vijay Abraham I 	sp->input_clks[CMN_REFCLK1_DIG_DIV] = clk;
7997e016cbcSKishon Vijay Abraham I 
80028081b72SKishon Vijay Abraham I 	clk = devm_clk_get_optional(dev, "pll0_refclk");
80128081b72SKishon Vijay Abraham I 	if (IS_ERR(clk)) {
80228081b72SKishon Vijay Abraham I 		dev_err(dev, "pll0_refclk clock not found\n");
80328081b72SKishon Vijay Abraham I 		ret = PTR_ERR(clk);
80428081b72SKishon Vijay Abraham I 		return ret;
80528081b72SKishon Vijay Abraham I 	}
80628081b72SKishon Vijay Abraham I 	sp->input_clks[PLL0_REFCLK] = clk;
80728081b72SKishon Vijay Abraham I 
80828081b72SKishon Vijay Abraham I 	clk = devm_clk_get_optional(dev, "pll1_refclk");
80928081b72SKishon Vijay Abraham I 	if (IS_ERR(clk)) {
81028081b72SKishon Vijay Abraham I 		dev_err(dev, "pll1_refclk clock not found\n");
81128081b72SKishon Vijay Abraham I 		ret = PTR_ERR(clk);
81228081b72SKishon Vijay Abraham I 		return ret;
81328081b72SKishon Vijay Abraham I 	}
81428081b72SKishon Vijay Abraham I 	sp->input_clks[PLL1_REFCLK] = clk;
81528081b72SKishon Vijay Abraham I 
8167e016cbcSKishon Vijay Abraham I 	return 0;
8177e016cbcSKishon Vijay Abraham I }
8187e016cbcSKishon Vijay Abraham I 
8191436ec30SKishon Vijay Abraham I static int cdns_sierra_phy_enable_clocks(struct cdns_sierra_phy *sp)
8201436ec30SKishon Vijay Abraham I {
8211436ec30SKishon Vijay Abraham I 	int ret;
8221436ec30SKishon Vijay Abraham I 
8231436ec30SKishon Vijay Abraham I 	ret = clk_prepare_enable(sp->input_clks[PHY_CLK]);
8241436ec30SKishon Vijay Abraham I 	if (ret)
8251436ec30SKishon Vijay Abraham I 		return ret;
8261436ec30SKishon Vijay Abraham I 
8271436ec30SKishon Vijay Abraham I 	ret = clk_prepare_enable(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]);
8281436ec30SKishon Vijay Abraham I 	if (ret)
8291436ec30SKishon Vijay Abraham I 		goto err_pll_cmnlc;
8301436ec30SKishon Vijay Abraham I 
8311436ec30SKishon Vijay Abraham I 	ret = clk_prepare_enable(sp->output_clks[CDNS_SIERRA_PLL_CMNLC1]);
8321436ec30SKishon Vijay Abraham I 	if (ret)
8331436ec30SKishon Vijay Abraham I 		goto err_pll_cmnlc1;
8341436ec30SKishon Vijay Abraham I 
8351436ec30SKishon Vijay Abraham I 	return 0;
8361436ec30SKishon Vijay Abraham I 
8371436ec30SKishon Vijay Abraham I err_pll_cmnlc1:
8381436ec30SKishon Vijay Abraham I 	clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]);
8391436ec30SKishon Vijay Abraham I 
8401436ec30SKishon Vijay Abraham I err_pll_cmnlc:
8411436ec30SKishon Vijay Abraham I 	clk_disable_unprepare(sp->input_clks[PHY_CLK]);
8421436ec30SKishon Vijay Abraham I 
8431436ec30SKishon Vijay Abraham I 	return ret;
8441436ec30SKishon Vijay Abraham I }
8451436ec30SKishon Vijay Abraham I 
8461436ec30SKishon Vijay Abraham I static void cdns_sierra_phy_disable_clocks(struct cdns_sierra_phy *sp)
8471436ec30SKishon Vijay Abraham I {
8481436ec30SKishon Vijay Abraham I 	clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC1]);
8491436ec30SKishon Vijay Abraham I 	clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]);
8501436ec30SKishon Vijay Abraham I 	clk_disable_unprepare(sp->input_clks[PHY_CLK]);
8511436ec30SKishon Vijay Abraham I }
8521436ec30SKishon Vijay Abraham I 
8531d5f40e0SKishon Vijay Abraham I static int cdns_sierra_phy_get_resets(struct cdns_sierra_phy *sp,
8541d5f40e0SKishon Vijay Abraham I 				      struct device *dev)
8551d5f40e0SKishon Vijay Abraham I {
8561d5f40e0SKishon Vijay Abraham I 	struct reset_control *rst;
8571d5f40e0SKishon Vijay Abraham I 
85815b0b82dSKishon Vijay Abraham I 	rst = devm_reset_control_get_exclusive(dev, "sierra_reset");
8591d5f40e0SKishon Vijay Abraham I 	if (IS_ERR(rst)) {
8601d5f40e0SKishon Vijay Abraham I 		dev_err(dev, "failed to get reset\n");
8611d5f40e0SKishon Vijay Abraham I 		return PTR_ERR(rst);
8621d5f40e0SKishon Vijay Abraham I 	}
8631d5f40e0SKishon Vijay Abraham I 	sp->phy_rst = rst;
8641d5f40e0SKishon Vijay Abraham I 
86515b0b82dSKishon Vijay Abraham I 	rst = devm_reset_control_get_optional_exclusive(dev, "sierra_apb");
8661d5f40e0SKishon Vijay Abraham I 	if (IS_ERR(rst)) {
8671d5f40e0SKishon Vijay Abraham I 		dev_err(dev, "failed to get apb reset\n");
8681d5f40e0SKishon Vijay Abraham I 		return PTR_ERR(rst);
8691d5f40e0SKishon Vijay Abraham I 	}
8701d5f40e0SKishon Vijay Abraham I 	sp->apb_rst = rst;
8711d5f40e0SKishon Vijay Abraham I 
8721d5f40e0SKishon Vijay Abraham I 	return 0;
8731d5f40e0SKishon Vijay Abraham I }
8741d5f40e0SKishon Vijay Abraham I 
87544d30d62SAlan Douglas static int cdns_sierra_phy_probe(struct platform_device *pdev)
87644d30d62SAlan Douglas {
87744d30d62SAlan Douglas 	struct cdns_sierra_phy *sp;
87844d30d62SAlan Douglas 	struct phy_provider *phy_provider;
87944d30d62SAlan Douglas 	struct device *dev = &pdev->dev;
880c3c11d55SSwapnil Jakhade 	const struct cdns_sierra_data *data;
881380f5708SKishon Vijay Abraham I 	unsigned int id_value;
88244d30d62SAlan Douglas 	int i, ret, node = 0;
883380f5708SKishon Vijay Abraham I 	void __iomem *base;
88444d30d62SAlan Douglas 	struct device_node *dn = dev->of_node, *child;
88544d30d62SAlan Douglas 
88644d30d62SAlan Douglas 	if (of_get_child_count(dn) == 0)
88744d30d62SAlan Douglas 		return -ENODEV;
88844d30d62SAlan Douglas 
889380f5708SKishon Vijay Abraham I 	/* Get init data for this PHY */
890c3c11d55SSwapnil Jakhade 	data = of_device_get_match_data(dev);
891c3c11d55SSwapnil Jakhade 	if (!data)
892380f5708SKishon Vijay Abraham I 		return -EINVAL;
893380f5708SKishon Vijay Abraham I 
89444d30d62SAlan Douglas 	sp = devm_kzalloc(dev, sizeof(*sp), GFP_KERNEL);
89544d30d62SAlan Douglas 	if (!sp)
89644d30d62SAlan Douglas 		return -ENOMEM;
89744d30d62SAlan Douglas 	dev_set_drvdata(dev, sp);
89844d30d62SAlan Douglas 	sp->dev = dev;
899380f5708SKishon Vijay Abraham I 	sp->init_data = data;
90044d30d62SAlan Douglas 
901fa629094SChunfeng Yun 	base = devm_platform_ioremap_resource(pdev, 0);
902380f5708SKishon Vijay Abraham I 	if (IS_ERR(base)) {
90344d30d62SAlan Douglas 		dev_err(dev, "missing \"reg\"\n");
904380f5708SKishon Vijay Abraham I 		return PTR_ERR(base);
90544d30d62SAlan Douglas 	}
90644d30d62SAlan Douglas 
907380f5708SKishon Vijay Abraham I 	ret = cdns_regmap_init_blocks(sp, base, data->block_offset_shift,
908380f5708SKishon Vijay Abraham I 				      data->reg_offset_shift);
909380f5708SKishon Vijay Abraham I 	if (ret)
910380f5708SKishon Vijay Abraham I 		return ret;
911380f5708SKishon Vijay Abraham I 
912380f5708SKishon Vijay Abraham I 	ret = cdns_regfield_init(sp);
913380f5708SKishon Vijay Abraham I 	if (ret)
914380f5708SKishon Vijay Abraham I 		return ret;
91544d30d62SAlan Douglas 
91644d30d62SAlan Douglas 	platform_set_drvdata(pdev, sp);
91744d30d62SAlan Douglas 
9187e016cbcSKishon Vijay Abraham I 	ret = cdns_sierra_phy_get_clocks(sp, dev);
9197e016cbcSKishon Vijay Abraham I 	if (ret)
9207e016cbcSKishon Vijay Abraham I 		return ret;
92144d30d62SAlan Douglas 
92228081b72SKishon Vijay Abraham I 	ret = cdns_sierra_clk_register(sp);
9231d5f40e0SKishon Vijay Abraham I 	if (ret)
9241d5f40e0SKishon Vijay Abraham I 		return ret;
92544d30d62SAlan Douglas 
92628081b72SKishon Vijay Abraham I 	ret = cdns_sierra_phy_get_resets(sp, dev);
92728081b72SKishon Vijay Abraham I 	if (ret)
92828081b72SKishon Vijay Abraham I 		goto unregister_clk;
92928081b72SKishon Vijay Abraham I 
9301436ec30SKishon Vijay Abraham I 	ret = cdns_sierra_phy_enable_clocks(sp);
93144d30d62SAlan Douglas 	if (ret)
93228081b72SKishon Vijay Abraham I 		goto unregister_clk;
93344d30d62SAlan Douglas 
93444d30d62SAlan Douglas 	/* Enable APB */
93544d30d62SAlan Douglas 	reset_control_deassert(sp->apb_rst);
93644d30d62SAlan Douglas 
93744d30d62SAlan Douglas 	/* Check that PHY is present */
938380f5708SKishon Vijay Abraham I 	regmap_field_read(sp->macro_id_type, &id_value);
939380f5708SKishon Vijay Abraham I 	if  (sp->init_data->id_value != id_value) {
94044d30d62SAlan Douglas 		ret = -EINVAL;
94144d30d62SAlan Douglas 		goto clk_disable;
94244d30d62SAlan Douglas 	}
94344d30d62SAlan Douglas 
94444d30d62SAlan Douglas 	sp->autoconf = of_property_read_bool(dn, "cdns,autoconf");
94544d30d62SAlan Douglas 
94644d30d62SAlan Douglas 	for_each_available_child_of_node(dn, child) {
94744d30d62SAlan Douglas 		struct phy *gphy;
94844d30d62SAlan Douglas 
94903ada5a3SKishon Vijay Abraham I 		if (!(of_node_name_eq(child, "phy") ||
95003ada5a3SKishon Vijay Abraham I 		      of_node_name_eq(child, "link")))
95103ada5a3SKishon Vijay Abraham I 			continue;
95203ada5a3SKishon Vijay Abraham I 
95344d30d62SAlan Douglas 		sp->phys[node].lnk_rst =
954b872936fSKishon Vijay Abraham I 			of_reset_control_array_get_exclusive(child);
95544d30d62SAlan Douglas 
95644d30d62SAlan Douglas 		if (IS_ERR(sp->phys[node].lnk_rst)) {
95744d30d62SAlan Douglas 			dev_err(dev, "failed to get reset %s\n",
95844d30d62SAlan Douglas 				child->full_name);
95944d30d62SAlan Douglas 			ret = PTR_ERR(sp->phys[node].lnk_rst);
96044d30d62SAlan Douglas 			goto put_child2;
96144d30d62SAlan Douglas 		}
96244d30d62SAlan Douglas 
96344d30d62SAlan Douglas 		if (!sp->autoconf) {
96444d30d62SAlan Douglas 			ret = cdns_sierra_get_optional(&sp->phys[node], child);
96544d30d62SAlan Douglas 			if (ret) {
96644d30d62SAlan Douglas 				dev_err(dev, "missing property in node %s\n",
96744d30d62SAlan Douglas 					child->name);
96844d30d62SAlan Douglas 				goto put_child;
96944d30d62SAlan Douglas 			}
97044d30d62SAlan Douglas 		}
97144d30d62SAlan Douglas 
972a43f72aeSKishon Vijay Abraham I 		sp->num_lanes += sp->phys[node].num_lanes;
973a43f72aeSKishon Vijay Abraham I 
97444d30d62SAlan Douglas 		gphy = devm_phy_create(dev, child, &ops);
97544d30d62SAlan Douglas 
97644d30d62SAlan Douglas 		if (IS_ERR(gphy)) {
97744d30d62SAlan Douglas 			ret = PTR_ERR(gphy);
97844d30d62SAlan Douglas 			goto put_child;
97944d30d62SAlan Douglas 		}
98044d30d62SAlan Douglas 		sp->phys[node].phy = gphy;
98144d30d62SAlan Douglas 		phy_set_drvdata(gphy, &sp->phys[node]);
98244d30d62SAlan Douglas 
98344d30d62SAlan Douglas 		node++;
98444d30d62SAlan Douglas 	}
98544d30d62SAlan Douglas 	sp->nsubnodes = node;
98644d30d62SAlan Douglas 
987a43f72aeSKishon Vijay Abraham I 	if (sp->num_lanes > SIERRA_MAX_LANES) {
9886411e386SWang Wensheng 		ret = -EINVAL;
989a43f72aeSKishon Vijay Abraham I 		dev_err(dev, "Invalid lane configuration\n");
990a43f72aeSKishon Vijay Abraham I 		goto put_child2;
991a43f72aeSKishon Vijay Abraham I 	}
992a43f72aeSKishon Vijay Abraham I 
99344d30d62SAlan Douglas 	/* If more than one subnode, configure the PHY as multilink */
99444d30d62SAlan Douglas 	if (!sp->autoconf && sp->nsubnodes > 1)
995380f5708SKishon Vijay Abraham I 		regmap_field_write(sp->phy_pll_cfg_1, 0x1);
99644d30d62SAlan Douglas 
99744d30d62SAlan Douglas 	pm_runtime_enable(dev);
99844d30d62SAlan Douglas 	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
99944d30d62SAlan Douglas 	return PTR_ERR_OR_ZERO(phy_provider);
100044d30d62SAlan Douglas 
100144d30d62SAlan Douglas put_child:
100244d30d62SAlan Douglas 	node++;
100344d30d62SAlan Douglas put_child2:
100444d30d62SAlan Douglas 	for (i = 0; i < node; i++)
100544d30d62SAlan Douglas 		reset_control_put(sp->phys[i].lnk_rst);
100644d30d62SAlan Douglas 	of_node_put(child);
100744d30d62SAlan Douglas clk_disable:
10081436ec30SKishon Vijay Abraham I 	cdns_sierra_phy_disable_clocks(sp);
100944d30d62SAlan Douglas 	reset_control_assert(sp->apb_rst);
101028081b72SKishon Vijay Abraham I unregister_clk:
101128081b72SKishon Vijay Abraham I 	cdns_sierra_clk_unregister(sp);
101244d30d62SAlan Douglas 	return ret;
101344d30d62SAlan Douglas }
101444d30d62SAlan Douglas 
101544d30d62SAlan Douglas static int cdns_sierra_phy_remove(struct platform_device *pdev)
101644d30d62SAlan Douglas {
1017748e3456SKishon Vijay Abraham I 	struct cdns_sierra_phy *phy = platform_get_drvdata(pdev);
101844d30d62SAlan Douglas 	int i;
101944d30d62SAlan Douglas 
102044d30d62SAlan Douglas 	reset_control_assert(phy->phy_rst);
102144d30d62SAlan Douglas 	reset_control_assert(phy->apb_rst);
102244d30d62SAlan Douglas 	pm_runtime_disable(&pdev->dev);
102344d30d62SAlan Douglas 
10241436ec30SKishon Vijay Abraham I 	cdns_sierra_phy_disable_clocks(phy);
102544d30d62SAlan Douglas 	/*
102644d30d62SAlan Douglas 	 * The device level resets will be put automatically.
102744d30d62SAlan Douglas 	 * Need to put the subnode resets here though.
102844d30d62SAlan Douglas 	 */
102944d30d62SAlan Douglas 	for (i = 0; i < phy->nsubnodes; i++) {
103044d30d62SAlan Douglas 		reset_control_assert(phy->phys[i].lnk_rst);
103144d30d62SAlan Douglas 		reset_control_put(phy->phys[i].lnk_rst);
103244d30d62SAlan Douglas 	}
103329c2d02aSKishon Vijay Abraham I 
103428081b72SKishon Vijay Abraham I 	cdns_sierra_clk_unregister(phy);
103529c2d02aSKishon Vijay Abraham I 
103644d30d62SAlan Douglas 	return 0;
103744d30d62SAlan Douglas }
103844d30d62SAlan Douglas 
1039*fa105172SSwapnil Jakhade /* PCIE PHY PCS common configuration */
1040*fa105172SSwapnil Jakhade static struct cdns_reg_pairs pcie_phy_pcs_cmn_regs[] = {
1041*fa105172SSwapnil Jakhade 	{0x0430, SIERRA_PHY_PIPE_CMN_CTRL1}
1042*fa105172SSwapnil Jakhade };
1043*fa105172SSwapnil Jakhade 
1044*fa105172SSwapnil Jakhade static struct cdns_sierra_vals pcie_phy_pcs_cmn_vals = {
1045*fa105172SSwapnil Jakhade 	.reg_pairs = pcie_phy_pcs_cmn_regs,
1046*fa105172SSwapnil Jakhade 	.num_regs = ARRAY_SIZE(pcie_phy_pcs_cmn_regs),
1047*fa105172SSwapnil Jakhade };
1048*fa105172SSwapnil Jakhade 
1049871002d7SAnil Varughese /* refclk100MHz_32b_PCIe_cmn_pll_ext_ssc */
10503cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_pcie_cmn_regs_ext_ssc[] = {
1051871002d7SAnil Varughese 	{0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1052871002d7SAnil Varughese 	{0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1053871002d7SAnil Varughese 	{0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
1054871002d7SAnil Varughese 	{0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
1055871002d7SAnil Varughese 	{0x1B1B, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
1056871002d7SAnil Varughese };
1057871002d7SAnil Varughese 
1058871002d7SAnil Varughese /* refclk100MHz_32b_PCIe_ln_ext_ssc */
10593cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_pcie_ln_regs_ext_ssc[] = {
1060871002d7SAnil Varughese 	{0x813E, SIERRA_CLKPATHCTRL_TMR_PREG},
1061871002d7SAnil Varughese 	{0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
1062871002d7SAnil Varughese 	{0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
1063871002d7SAnil Varughese 	{0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
1064871002d7SAnil Varughese 	{0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
1065871002d7SAnil Varughese 	{0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
1066871002d7SAnil Varughese 	{0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG}
1067871002d7SAnil Varughese };
1068871002d7SAnil Varughese 
1069078e9e92SSwapnil Jakhade static struct cdns_sierra_vals pcie_100_ext_ssc_cmn_vals = {
1070078e9e92SSwapnil Jakhade 	.reg_pairs = cdns_pcie_cmn_regs_ext_ssc,
1071078e9e92SSwapnil Jakhade 	.num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc),
1072078e9e92SSwapnil Jakhade };
1073078e9e92SSwapnil Jakhade 
1074078e9e92SSwapnil Jakhade static struct cdns_sierra_vals pcie_100_ext_ssc_ln_vals = {
1075078e9e92SSwapnil Jakhade 	.reg_pairs = cdns_pcie_ln_regs_ext_ssc,
1076078e9e92SSwapnil Jakhade 	.num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc),
1077078e9e92SSwapnil Jakhade };
1078078e9e92SSwapnil Jakhade 
1079871002d7SAnil Varughese /* refclk100MHz_20b_USB_cmn_pll_ext_ssc */
10803cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_usb_cmn_regs_ext_ssc[] = {
1081871002d7SAnil Varughese 	{0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1082871002d7SAnil Varughese 	{0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1083871002d7SAnil Varughese 	{0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
1084871002d7SAnil Varughese 	{0x0000, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
1085871002d7SAnil Varughese };
1086871002d7SAnil Varughese 
1087871002d7SAnil Varughese /* refclk100MHz_20b_USB_ln_ext_ssc */
10883cfb0e8eSRikard Falkeborn static const struct cdns_reg_pairs cdns_usb_ln_regs_ext_ssc[] = {
1089aead5fd6SKishon Vijay Abraham I 	{0xFE0A, SIERRA_DET_STANDEC_A_PREG},
1090aead5fd6SKishon Vijay Abraham I 	{0x000F, SIERRA_DET_STANDEC_B_PREG},
10912bcf14caSSanket Parmar 	{0x55A5, SIERRA_DET_STANDEC_C_PREG},
1092871002d7SAnil Varughese 	{0x69ad, SIERRA_DET_STANDEC_D_PREG},
1093aead5fd6SKishon Vijay Abraham I 	{0x0241, SIERRA_DET_STANDEC_E_PREG},
10942bcf14caSSanket Parmar 	{0x0110, SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG},
1095871002d7SAnil Varughese 	{0x0014, SIERRA_PSM_A0IN_TMR_PREG},
1096aead5fd6SKishon Vijay Abraham I 	{0xCF00, SIERRA_PSM_DIAG_PREG},
1097aead5fd6SKishon Vijay Abraham I 	{0x001F, SIERRA_PSC_TX_A0_PREG},
1098aead5fd6SKishon Vijay Abraham I 	{0x0007, SIERRA_PSC_TX_A1_PREG},
1099aead5fd6SKishon Vijay Abraham I 	{0x0003, SIERRA_PSC_TX_A2_PREG},
1100aead5fd6SKishon Vijay Abraham I 	{0x0003, SIERRA_PSC_TX_A3_PREG},
1101aead5fd6SKishon Vijay Abraham I 	{0x0FFF, SIERRA_PSC_RX_A0_PREG},
11022bcf14caSSanket Parmar 	{0x0003, SIERRA_PSC_RX_A1_PREG},
1103aead5fd6SKishon Vijay Abraham I 	{0x0003, SIERRA_PSC_RX_A2_PREG},
1104aead5fd6SKishon Vijay Abraham I 	{0x0001, SIERRA_PSC_RX_A3_PREG},
1105aead5fd6SKishon Vijay Abraham I 	{0x0001, SIERRA_PLLCTRL_SUBRATE_PREG},
1106aead5fd6SKishon Vijay Abraham I 	{0x0406, SIERRA_PLLCTRL_GEN_D_PREG},
1107871002d7SAnil Varughese 	{0x5233, SIERRA_PLLCTRL_CPGAIN_MODE_PREG},
1108871002d7SAnil Varughese 	{0x00CA, SIERRA_CLKPATH_BIASTRIM_PREG},
1109871002d7SAnil Varughese 	{0x2512, SIERRA_DFE_BIASTRIM_PREG},
1110aead5fd6SKishon Vijay Abraham I 	{0x0000, SIERRA_DRVCTRL_ATTEN_PREG},
11112bcf14caSSanket Parmar 	{0x823E, SIERRA_CLKPATHCTRL_TMR_PREG},
11122bcf14caSSanket Parmar 	{0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
11132bcf14caSSanket Parmar 	{0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
1114aead5fd6SKishon Vijay Abraham I 	{0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG},
11152bcf14caSSanket Parmar 	{0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
1116aead5fd6SKishon Vijay Abraham I 	{0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG},
1117871002d7SAnil Varughese 	{0x0000, SIERRA_CREQ_EQ_CTRL_PREG},
11182bcf14caSSanket Parmar 	{0x0000, SIERRA_CREQ_SPARE_PREG},
1119871002d7SAnil Varughese 	{0xCC44, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
11202bcf14caSSanket Parmar 	{0x8452, SIERRA_CTLELUT_CTRL_PREG},
11212bcf14caSSanket Parmar 	{0x4121, SIERRA_DFE_ECMP_RATESEL_PREG},
11222bcf14caSSanket Parmar 	{0x4121, SIERRA_DFE_SMP_RATESEL_PREG},
11232bcf14caSSanket Parmar 	{0x0003, SIERRA_DEQ_PHALIGN_CTRL},
1124871002d7SAnil Varughese 	{0x3200, SIERRA_DEQ_CONCUR_CTRL1_PREG},
1125871002d7SAnil Varughese 	{0x5064, SIERRA_DEQ_CONCUR_CTRL2_PREG},
1126871002d7SAnil Varughese 	{0x0030, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
1127871002d7SAnil Varughese 	{0x0048, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
1128871002d7SAnil Varughese 	{0x5A5A, SIERRA_DEQ_ERRCMP_CTRL_PREG},
1129871002d7SAnil Varughese 	{0x02F5, SIERRA_DEQ_OFFSET_CTRL_PREG},
1130871002d7SAnil Varughese 	{0x02F5, SIERRA_DEQ_GAIN_CTRL_PREG},
11312bcf14caSSanket Parmar 	{0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG},
1132871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT0},
1133871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT1},
1134871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT2},
1135871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT3},
1136871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT4},
1137871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT5},
1138871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT6},
1139871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT7},
1140871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT8},
1141871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT9},
1142871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT10},
1143871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT11},
1144871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT12},
1145871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT13},
1146871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT14},
1147871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT15},
1148871002d7SAnil Varughese 	{0x0014, SIERRA_DEQ_GLUT16},
1149871002d7SAnil Varughese 	{0x0BAE, SIERRA_DEQ_ALUT0},
1150871002d7SAnil Varughese 	{0x0AEB, SIERRA_DEQ_ALUT1},
1151871002d7SAnil Varughese 	{0x0A28, SIERRA_DEQ_ALUT2},
1152871002d7SAnil Varughese 	{0x0965, SIERRA_DEQ_ALUT3},
1153871002d7SAnil Varughese 	{0x08A2, SIERRA_DEQ_ALUT4},
1154871002d7SAnil Varughese 	{0x07DF, SIERRA_DEQ_ALUT5},
1155871002d7SAnil Varughese 	{0x071C, SIERRA_DEQ_ALUT6},
1156871002d7SAnil Varughese 	{0x0659, SIERRA_DEQ_ALUT7},
1157871002d7SAnil Varughese 	{0x0596, SIERRA_DEQ_ALUT8},
1158871002d7SAnil Varughese 	{0x0514, SIERRA_DEQ_ALUT9},
1159871002d7SAnil Varughese 	{0x0492, SIERRA_DEQ_ALUT10},
1160871002d7SAnil Varughese 	{0x0410, SIERRA_DEQ_ALUT11},
1161871002d7SAnil Varughese 	{0x038E, SIERRA_DEQ_ALUT12},
1162871002d7SAnil Varughese 	{0x030C, SIERRA_DEQ_ALUT13},
1163871002d7SAnil Varughese 	{0x03F4, SIERRA_DEQ_DFETAP_CTRL_PREG},
1164871002d7SAnil Varughese 	{0x0001, SIERRA_DFE_EN_1010_IGNORE_PREG},
1165871002d7SAnil Varughese 	{0x3C01, SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG},
1166871002d7SAnil Varughese 	{0x3C40, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1167871002d7SAnil Varughese 	{0x1C08, SIERRA_DEQ_TAU_CTRL2_PREG},
1168871002d7SAnil Varughese 	{0x0033, SIERRA_DEQ_PICTRL_PREG},
1169871002d7SAnil Varughese 	{0x0400, SIERRA_CPICAL_TMRVAL_MODE1_PREG},
1170871002d7SAnil Varughese 	{0x0330, SIERRA_CPICAL_TMRVAL_MODE0_PREG},
1171871002d7SAnil Varughese 	{0x01FF, SIERRA_CPICAL_PICNT_MODE1_PREG},
1172aead5fd6SKishon Vijay Abraham I 	{0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG},
1173871002d7SAnil Varughese 	{0x3232, SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG},
1174871002d7SAnil Varughese 	{0x0005, SIERRA_LFPSDET_SUPPORT_PREG},
1175aead5fd6SKishon Vijay Abraham I 	{0x000F, SIERRA_LFPSFILT_NS_PREG},
1176aead5fd6SKishon Vijay Abraham I 	{0x0009, SIERRA_LFPSFILT_RD_PREG},
1177aead5fd6SKishon Vijay Abraham I 	{0x0001, SIERRA_LFPSFILT_MP_PREG},
11782bcf14caSSanket Parmar 	{0x6013, SIERRA_SIGDET_SUPPORT_PREG},
1179aead5fd6SKishon Vijay Abraham I 	{0x8013, SIERRA_SDFILT_H2L_A_PREG},
1180871002d7SAnil Varughese 	{0x8009, SIERRA_SDFILT_L2H_PREG},
1181871002d7SAnil Varughese 	{0x0024, SIERRA_RXBUFFER_CTLECTRL_PREG},
1182871002d7SAnil Varughese 	{0x0020, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1183871002d7SAnil Varughese 	{0x4243, SIERRA_RXBUFFER_DFECTRL_PREG}
118444d30d62SAlan Douglas };
118544d30d62SAlan Douglas 
1186078e9e92SSwapnil Jakhade static struct cdns_sierra_vals usb_100_ext_ssc_cmn_vals = {
1187078e9e92SSwapnil Jakhade 	.reg_pairs = cdns_usb_cmn_regs_ext_ssc,
1188078e9e92SSwapnil Jakhade 	.num_regs = ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc),
1189078e9e92SSwapnil Jakhade };
1190078e9e92SSwapnil Jakhade 
1191078e9e92SSwapnil Jakhade static struct cdns_sierra_vals usb_100_ext_ssc_ln_vals = {
1192078e9e92SSwapnil Jakhade 	.reg_pairs = cdns_usb_ln_regs_ext_ssc,
1193078e9e92SSwapnil Jakhade 	.num_regs = ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc),
1194078e9e92SSwapnil Jakhade };
1195078e9e92SSwapnil Jakhade 
119644d30d62SAlan Douglas static const struct cdns_sierra_data cdns_map_sierra = {
1197078e9e92SSwapnil Jakhade 	.id_value = SIERRA_MACRO_ID,
1198078e9e92SSwapnil Jakhade 	.block_offset_shift = 0x2,
1199078e9e92SSwapnil Jakhade 	.reg_offset_shift = 0x2,
1200*fa105172SSwapnil Jakhade 	.pcs_cmn_vals = {
1201*fa105172SSwapnil Jakhade 		[TYPE_PCIE] = {
1202*fa105172SSwapnil Jakhade 			[TYPE_NONE] = {
1203*fa105172SSwapnil Jakhade 				[EXTERNAL_SSC] = &pcie_phy_pcs_cmn_vals,
1204*fa105172SSwapnil Jakhade 			},
1205*fa105172SSwapnil Jakhade 		},
1206*fa105172SSwapnil Jakhade 	},
1207078e9e92SSwapnil Jakhade 	.pma_cmn_vals = {
1208078e9e92SSwapnil Jakhade 		[TYPE_PCIE] = {
1209078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1210078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
1211078e9e92SSwapnil Jakhade 			},
1212078e9e92SSwapnil Jakhade 		},
1213078e9e92SSwapnil Jakhade 		[TYPE_USB] = {
1214078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1215078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1216078e9e92SSwapnil Jakhade 			},
1217078e9e92SSwapnil Jakhade 		},
1218078e9e92SSwapnil Jakhade 	},
1219078e9e92SSwapnil Jakhade 	.pma_ln_vals = {
1220078e9e92SSwapnil Jakhade 		[TYPE_PCIE] = {
1221078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1222078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
1223078e9e92SSwapnil Jakhade 			},
1224078e9e92SSwapnil Jakhade 		},
1225078e9e92SSwapnil Jakhade 		[TYPE_USB] = {
1226078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1227078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1228078e9e92SSwapnil Jakhade 			},
1229078e9e92SSwapnil Jakhade 		},
1230078e9e92SSwapnil Jakhade 	},
123144d30d62SAlan Douglas };
123244d30d62SAlan Douglas 
1233367da978SKishon Vijay Abraham I static const struct cdns_sierra_data cdns_ti_map_sierra = {
1234078e9e92SSwapnil Jakhade 	.id_value = SIERRA_MACRO_ID,
1235078e9e92SSwapnil Jakhade 	.block_offset_shift = 0x0,
1236078e9e92SSwapnil Jakhade 	.reg_offset_shift = 0x1,
1237*fa105172SSwapnil Jakhade 	.pcs_cmn_vals = {
1238*fa105172SSwapnil Jakhade 		[TYPE_PCIE] = {
1239*fa105172SSwapnil Jakhade 			[TYPE_NONE] = {
1240*fa105172SSwapnil Jakhade 				[EXTERNAL_SSC] = &pcie_phy_pcs_cmn_vals,
1241*fa105172SSwapnil Jakhade 			},
1242*fa105172SSwapnil Jakhade 		},
1243*fa105172SSwapnil Jakhade 	},
1244078e9e92SSwapnil Jakhade 	.pma_cmn_vals = {
1245078e9e92SSwapnil Jakhade 		[TYPE_PCIE] = {
1246078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1247078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
1248078e9e92SSwapnil Jakhade 			},
1249078e9e92SSwapnil Jakhade 		},
1250078e9e92SSwapnil Jakhade 		[TYPE_USB] = {
1251078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1252078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1253078e9e92SSwapnil Jakhade 			},
1254078e9e92SSwapnil Jakhade 		},
1255078e9e92SSwapnil Jakhade 	},
1256078e9e92SSwapnil Jakhade 	.pma_ln_vals = {
1257078e9e92SSwapnil Jakhade 		[TYPE_PCIE] = {
1258078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1259078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
1260078e9e92SSwapnil Jakhade 			},
1261078e9e92SSwapnil Jakhade 		},
1262078e9e92SSwapnil Jakhade 		[TYPE_USB] = {
1263078e9e92SSwapnil Jakhade 			[TYPE_NONE] = {
1264078e9e92SSwapnil Jakhade 				[EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1265078e9e92SSwapnil Jakhade 			},
1266078e9e92SSwapnil Jakhade 		},
1267078e9e92SSwapnil Jakhade 	},
1268367da978SKishon Vijay Abraham I };
1269367da978SKishon Vijay Abraham I 
127044d30d62SAlan Douglas static const struct of_device_id cdns_sierra_id_table[] = {
127144d30d62SAlan Douglas 	{
127244d30d62SAlan Douglas 		.compatible = "cdns,sierra-phy-t0",
127344d30d62SAlan Douglas 		.data = &cdns_map_sierra,
127444d30d62SAlan Douglas 	},
1275367da978SKishon Vijay Abraham I 	{
1276367da978SKishon Vijay Abraham I 		.compatible = "ti,sierra-phy-t0",
1277367da978SKishon Vijay Abraham I 		.data = &cdns_ti_map_sierra,
1278367da978SKishon Vijay Abraham I 	},
127944d30d62SAlan Douglas 	{}
128044d30d62SAlan Douglas };
128144d30d62SAlan Douglas MODULE_DEVICE_TABLE(of, cdns_sierra_id_table);
128244d30d62SAlan Douglas 
128344d30d62SAlan Douglas static struct platform_driver cdns_sierra_driver = {
128444d30d62SAlan Douglas 	.probe		= cdns_sierra_phy_probe,
128544d30d62SAlan Douglas 	.remove		= cdns_sierra_phy_remove,
128644d30d62SAlan Douglas 	.driver		= {
128744d30d62SAlan Douglas 		.name	= "cdns-sierra-phy",
128844d30d62SAlan Douglas 		.of_match_table = cdns_sierra_id_table,
128944d30d62SAlan Douglas 	},
129044d30d62SAlan Douglas };
129144d30d62SAlan Douglas module_platform_driver(cdns_sierra_driver);
129244d30d62SAlan Douglas 
129344d30d62SAlan Douglas MODULE_ALIAS("platform:cdns_sierra");
129444d30d62SAlan Douglas MODULE_AUTHOR("Cadence Design Systems");
129544d30d62SAlan Douglas MODULE_DESCRIPTION("CDNS sierra phy driver");
129644d30d62SAlan Douglas MODULE_LICENSE("GPL v2");
1297