1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Cadence Torrent SD0801 PHY driver.
4  *
5  * Copyright 2018 Cadence Design Systems, Inc.
6  *
7  */
8 
9 #include <dt-bindings/phy/phy.h>
10 #include <linux/clk.h>
11 #include <linux/delay.h>
12 #include <linux/err.h>
13 #include <linux/io.h>
14 #include <linux/iopoll.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/of.h>
18 #include <linux/of_address.h>
19 #include <linux/of_device.h>
20 #include <linux/phy/phy.h>
21 #include <linux/platform_device.h>
22 #include <linux/reset.h>
23 #include <linux/regmap.h>
24 
25 #define REF_CLK_19_2MHz		19200000
26 #define REF_CLK_25MHz		25000000
27 
28 #define MAX_NUM_LANES		4
29 #define DEFAULT_MAX_BIT_RATE	8100 /* in Mbps */
30 
31 #define NUM_SSC_MODE		3
32 #define NUM_PHY_TYPE		6
33 
34 #define POLL_TIMEOUT_US		5000
35 #define PLL_LOCK_TIMEOUT	100000
36 
37 #define TORRENT_COMMON_CDB_OFFSET	0x0
38 
39 #define TORRENT_TX_LANE_CDB_OFFSET(ln, block_offset, reg_offset)	\
40 				((0x4000 << (block_offset)) +		\
41 				(((ln) << 9) << (reg_offset)))
42 
43 #define TORRENT_RX_LANE_CDB_OFFSET(ln, block_offset, reg_offset)	\
44 				((0x8000 << (block_offset)) +		\
45 				(((ln) << 9) << (reg_offset)))
46 
47 #define TORRENT_PHY_PCS_COMMON_OFFSET(block_offset)	\
48 				(0xC000 << (block_offset))
49 
50 #define TORRENT_PHY_PMA_COMMON_OFFSET(block_offset)	\
51 				(0xE000 << (block_offset))
52 
53 #define TORRENT_DPTX_PHY_OFFSET		0x0
54 
55 /*
56  * register offsets from DPTX PHY register block base (i.e MHDP
57  * register base + 0x30a00)
58  */
59 #define PHY_AUX_CTRL			0x04
60 #define PHY_RESET			0x20
61 #define PMA_TX_ELEC_IDLE_MASK		0xF0U
62 #define PMA_TX_ELEC_IDLE_SHIFT		4
63 #define PHY_L00_RESET_N_MASK		0x01U
64 #define PHY_PMA_XCVR_PLLCLK_EN		0x24
65 #define PHY_PMA_XCVR_PLLCLK_EN_ACK	0x28
66 #define PHY_PMA_XCVR_POWER_STATE_REQ	0x2c
67 #define PHY_POWER_STATE_LN_0	0x0000
68 #define PHY_POWER_STATE_LN_1	0x0008
69 #define PHY_POWER_STATE_LN_2	0x0010
70 #define PHY_POWER_STATE_LN_3	0x0018
71 #define PMA_XCVR_POWER_STATE_REQ_LN_MASK	0x3FU
72 #define PHY_PMA_XCVR_POWER_STATE_ACK	0x30
73 #define PHY_PMA_CMN_READY		0x34
74 
75 /*
76  * register offsets from SD0801 PHY register block base (i.e MHDP
77  * register base + 0x500000)
78  */
79 #define CMN_SSM_BANDGAP_TMR		0x0021U
80 #define CMN_SSM_BIAS_TMR		0x0022U
81 #define CMN_PLLSM0_PLLPRE_TMR		0x002AU
82 #define CMN_PLLSM0_PLLLOCK_TMR		0x002CU
83 #define CMN_PLLSM1_PLLPRE_TMR		0x0032U
84 #define CMN_PLLSM1_PLLLOCK_TMR		0x0034U
85 #define CMN_CDIAG_CDB_PWRI_OVRD		0x0041U
86 #define CMN_CDIAG_XCVRC_PWRI_OVRD	0x0047U
87 #define CMN_BGCAL_INIT_TMR		0x0064U
88 #define CMN_BGCAL_ITER_TMR		0x0065U
89 #define CMN_IBCAL_INIT_TMR		0x0074U
90 #define CMN_PLL0_VCOCAL_TCTRL		0x0082U
91 #define CMN_PLL0_VCOCAL_INIT_TMR	0x0084U
92 #define CMN_PLL0_VCOCAL_ITER_TMR	0x0085U
93 #define CMN_PLL0_VCOCAL_REFTIM_START	0x0086U
94 #define CMN_PLL0_VCOCAL_PLLCNT_START	0x0088U
95 #define CMN_PLL0_INTDIV_M0		0x0090U
96 #define CMN_PLL0_FRACDIVL_M0		0x0091U
97 #define CMN_PLL0_FRACDIVH_M0		0x0092U
98 #define CMN_PLL0_HIGH_THR_M0		0x0093U
99 #define CMN_PLL0_DSM_DIAG_M0		0x0094U
100 #define CMN_PLL0_SS_CTRL1_M0		0x0098U
101 #define CMN_PLL0_SS_CTRL2_M0            0x0099U
102 #define CMN_PLL0_SS_CTRL3_M0            0x009AU
103 #define CMN_PLL0_SS_CTRL4_M0            0x009BU
104 #define CMN_PLL0_LOCK_REFCNT_START      0x009CU
105 #define CMN_PLL0_LOCK_PLLCNT_START	0x009EU
106 #define CMN_PLL0_LOCK_PLLCNT_THR        0x009FU
107 #define CMN_PLL0_INTDIV_M1		0x00A0U
108 #define CMN_PLL0_FRACDIVH_M1		0x00A2U
109 #define CMN_PLL0_HIGH_THR_M1		0x00A3U
110 #define CMN_PLL0_DSM_DIAG_M1		0x00A4U
111 #define CMN_PLL0_SS_CTRL1_M1		0x00A8U
112 #define CMN_PLL0_SS_CTRL2_M1		0x00A9U
113 #define CMN_PLL0_SS_CTRL3_M1		0x00AAU
114 #define CMN_PLL0_SS_CTRL4_M1		0x00ABU
115 #define CMN_PLL1_VCOCAL_TCTRL		0x00C2U
116 #define CMN_PLL1_VCOCAL_INIT_TMR	0x00C4U
117 #define CMN_PLL1_VCOCAL_ITER_TMR	0x00C5U
118 #define CMN_PLL1_VCOCAL_REFTIM_START	0x00C6U
119 #define CMN_PLL1_VCOCAL_PLLCNT_START	0x00C8U
120 #define CMN_PLL1_INTDIV_M0		0x00D0U
121 #define CMN_PLL1_FRACDIVL_M0		0x00D1U
122 #define CMN_PLL1_FRACDIVH_M0		0x00D2U
123 #define CMN_PLL1_HIGH_THR_M0		0x00D3U
124 #define CMN_PLL1_DSM_DIAG_M0		0x00D4U
125 #define CMN_PLL1_SS_CTRL1_M0		0x00D8U
126 #define CMN_PLL1_SS_CTRL2_M0            0x00D9U
127 #define CMN_PLL1_SS_CTRL3_M0            0x00DAU
128 #define CMN_PLL1_SS_CTRL4_M0            0x00DBU
129 #define CMN_PLL1_LOCK_REFCNT_START      0x00DCU
130 #define CMN_PLL1_LOCK_PLLCNT_START	0x00DEU
131 #define CMN_PLL1_LOCK_PLLCNT_THR        0x00DFU
132 #define CMN_TXPUCAL_TUNE		0x0103U
133 #define CMN_TXPUCAL_INIT_TMR		0x0104U
134 #define CMN_TXPUCAL_ITER_TMR		0x0105U
135 #define CMN_TXPDCAL_TUNE		0x010BU
136 #define CMN_TXPDCAL_INIT_TMR		0x010CU
137 #define CMN_TXPDCAL_ITER_TMR		0x010DU
138 #define CMN_RXCAL_INIT_TMR		0x0114U
139 #define CMN_RXCAL_ITER_TMR		0x0115U
140 #define CMN_SD_CAL_INIT_TMR		0x0124U
141 #define CMN_SD_CAL_ITER_TMR		0x0125U
142 #define CMN_SD_CAL_REFTIM_START		0x0126U
143 #define CMN_SD_CAL_PLLCNT_START		0x0128U
144 #define CMN_PDIAG_PLL0_CTRL_M0		0x01A0U
145 #define CMN_PDIAG_PLL0_CLK_SEL_M0	0x01A1U
146 #define CMN_PDIAG_PLL0_CP_PADJ_M0	0x01A4U
147 #define CMN_PDIAG_PLL0_CP_IADJ_M0	0x01A5U
148 #define CMN_PDIAG_PLL0_FILT_PADJ_M0	0x01A6U
149 #define CMN_PDIAG_PLL0_CTRL_M1		0x01B0U
150 #define CMN_PDIAG_PLL0_CLK_SEL_M1	0x01B1U
151 #define CMN_PDIAG_PLL0_CP_PADJ_M1	0x01B4U
152 #define CMN_PDIAG_PLL0_CP_IADJ_M1	0x01B5U
153 #define CMN_PDIAG_PLL0_FILT_PADJ_M1	0x01B6U
154 #define CMN_PDIAG_PLL1_CTRL_M0		0x01C0U
155 #define CMN_PDIAG_PLL1_CLK_SEL_M0	0x01C1U
156 #define CMN_PDIAG_PLL1_CP_PADJ_M0	0x01C4U
157 #define CMN_PDIAG_PLL1_CP_IADJ_M0	0x01C5U
158 #define CMN_PDIAG_PLL1_FILT_PADJ_M0	0x01C6U
159 #define CMN_DIAG_BIAS_OVRD1		0x01E1U
160 
161 /* PMA TX Lane registers */
162 #define TX_TXCC_CTRL			0x0040U
163 #define TX_TXCC_CPOST_MULT_00		0x004CU
164 #define TX_TXCC_CPOST_MULT_01		0x004DU
165 #define TX_TXCC_MGNFS_MULT_000		0x0050U
166 #define DRV_DIAG_TX_DRV			0x00C6U
167 #define XCVR_DIAG_PLLDRC_CTRL		0x00E5U
168 #define XCVR_DIAG_HSCLK_SEL		0x00E6U
169 #define XCVR_DIAG_HSCLK_DIV		0x00E7U
170 #define XCVR_DIAG_BIDI_CTRL		0x00EAU
171 #define XCVR_DIAG_PSC_OVRD		0x00EBU
172 #define TX_PSC_A0			0x0100U
173 #define TX_PSC_A1			0x0101U
174 #define TX_PSC_A2			0x0102U
175 #define TX_PSC_A3			0x0103U
176 #define TX_RCVDET_ST_TMR		0x0123U
177 #define TX_DIAG_ACYA			0x01E7U
178 #define TX_DIAG_ACYA_HBDC_MASK		0x0001U
179 
180 /* PMA RX Lane registers */
181 #define RX_PSC_A0			0x0000U
182 #define RX_PSC_A1			0x0001U
183 #define RX_PSC_A2			0x0002U
184 #define RX_PSC_A3			0x0003U
185 #define RX_PSC_CAL			0x0006U
186 #define RX_CDRLF_CNFG			0x0080U
187 #define RX_CDRLF_CNFG3			0x0082U
188 #define RX_SIGDET_HL_FILT_TMR		0x0090U
189 #define RX_REE_GCSM1_CTRL		0x0108U
190 #define RX_REE_GCSM1_EQENM_PH1		0x0109U
191 #define RX_REE_GCSM1_EQENM_PH2		0x010AU
192 #define RX_REE_GCSM2_CTRL		0x0110U
193 #define RX_REE_PERGCSM_CTRL		0x0118U
194 #define RX_REE_ATTEN_THR		0x0149U
195 #define RX_REE_TAP1_CLIP		0x0171U
196 #define RX_REE_TAP2TON_CLIP		0x0172U
197 #define RX_REE_SMGM_CTRL1		0x0177U
198 #define RX_REE_SMGM_CTRL2		0x0178U
199 #define RX_DIAG_DFE_CTRL		0x01E0U
200 #define RX_DIAG_DFE_AMP_TUNE_2		0x01E2U
201 #define RX_DIAG_DFE_AMP_TUNE_3		0x01E3U
202 #define RX_DIAG_NQST_CTRL		0x01E5U
203 #define RX_DIAG_SIGDET_TUNE		0x01E8U
204 #define RX_DIAG_PI_RATE			0x01F4U
205 #define RX_DIAG_PI_CAP			0x01F5U
206 #define RX_DIAG_ACYA			0x01FFU
207 
208 /* PHY PCS common registers */
209 #define PHY_PLL_CFG			0x000EU
210 #define PHY_PIPE_USB3_GEN2_PRE_CFG0	0x0020U
211 #define PHY_PIPE_USB3_GEN2_POST_CFG0	0x0022U
212 #define PHY_PIPE_USB3_GEN2_POST_CFG1	0x0023U
213 
214 /* PHY PMA common registers */
215 #define PHY_PMA_CMN_CTRL1		0x0000U
216 #define PHY_PMA_CMN_CTRL2		0x0001U
217 #define PHY_PMA_PLL_RAW_CTRL		0x0003U
218 
219 static const struct reg_field phy_pll_cfg =
220 				REG_FIELD(PHY_PLL_CFG, 0, 1);
221 
222 static const struct reg_field phy_pma_cmn_ctrl_1 =
223 				REG_FIELD(PHY_PMA_CMN_CTRL1, 0, 0);
224 
225 static const struct reg_field phy_pma_cmn_ctrl_2 =
226 				REG_FIELD(PHY_PMA_CMN_CTRL2, 0, 7);
227 
228 static const struct reg_field phy_pma_pll_raw_ctrl =
229 				REG_FIELD(PHY_PMA_PLL_RAW_CTRL, 0, 1);
230 
231 static const struct reg_field phy_reset_ctrl =
232 				REG_FIELD(PHY_RESET, 8, 8);
233 
234 enum cdns_torrent_phy_type {
235 	TYPE_NONE,
236 	TYPE_DP,
237 	TYPE_PCIE,
238 	TYPE_SGMII,
239 	TYPE_QSGMII,
240 	TYPE_USB,
241 };
242 
243 enum cdns_torrent_ssc_mode {
244 	NO_SSC,
245 	EXTERNAL_SSC,
246 	INTERNAL_SSC
247 };
248 
249 struct cdns_torrent_inst {
250 	struct phy *phy;
251 	u32 mlane;
252 	enum cdns_torrent_phy_type phy_type;
253 	u32 num_lanes;
254 	struct reset_control *lnk_rst;
255 	enum cdns_torrent_ssc_mode ssc_mode;
256 };
257 
258 struct cdns_torrent_phy {
259 	void __iomem *base;	/* DPTX registers base */
260 	void __iomem *sd_base; /* SD0801 registers base */
261 	u32 max_bit_rate; /* Maximum link bit rate to use (in Mbps) */
262 	struct reset_control *phy_rst;
263 	struct reset_control *apb_rst;
264 	struct device *dev;
265 	struct clk *clk;
266 	unsigned long ref_clk_rate;
267 	struct cdns_torrent_inst phys[MAX_NUM_LANES];
268 	int nsubnodes;
269 	const struct cdns_torrent_data *init_data;
270 	struct regmap *regmap;
271 	struct regmap *regmap_common_cdb;
272 	struct regmap *regmap_phy_pcs_common_cdb;
273 	struct regmap *regmap_phy_pma_common_cdb;
274 	struct regmap *regmap_tx_lane_cdb[MAX_NUM_LANES];
275 	struct regmap *regmap_rx_lane_cdb[MAX_NUM_LANES];
276 	struct regmap *regmap_dptx_phy_reg;
277 	struct regmap_field *phy_pll_cfg;
278 	struct regmap_field *phy_pma_cmn_ctrl_1;
279 	struct regmap_field *phy_pma_cmn_ctrl_2;
280 	struct regmap_field *phy_pma_pll_raw_ctrl;
281 	struct regmap_field *phy_reset_ctrl;
282 };
283 
284 enum phy_powerstate {
285 	POWERSTATE_A0 = 0,
286 	/* Powerstate A1 is unused */
287 	POWERSTATE_A2 = 2,
288 	POWERSTATE_A3 = 3,
289 };
290 
291 static int cdns_torrent_phy_init(struct phy *phy);
292 static int cdns_torrent_dp_init(struct phy *phy);
293 static int cdns_torrent_dp_run(struct cdns_torrent_phy *cdns_phy,
294 			       u32 num_lanes);
295 static
296 int cdns_torrent_dp_wait_pma_cmn_ready(struct cdns_torrent_phy *cdns_phy);
297 static void cdns_torrent_dp_pma_cfg(struct cdns_torrent_phy *cdns_phy,
298 				    struct cdns_torrent_inst *inst);
299 static
300 void cdns_torrent_dp_pma_cmn_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy);
301 static
302 void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy,
303 					     u32 rate, bool ssc);
304 static
305 void cdns_torrent_dp_pma_cmn_cfg_25mhz(struct cdns_torrent_phy *cdns_phy);
306 static
307 void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy,
308 					   u32 rate, bool ssc);
309 static void cdns_torrent_dp_pma_lane_cfg(struct cdns_torrent_phy *cdns_phy,
310 					 unsigned int lane);
311 static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy *cdns_phy,
312 					 u32 rate, u32 num_lanes);
313 static int cdns_torrent_dp_configure(struct phy *phy,
314 				     union phy_configure_opts *opts);
315 static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy *cdns_phy,
316 					   u32 num_lanes,
317 					   enum phy_powerstate powerstate);
318 static int cdns_torrent_phy_on(struct phy *phy);
319 static int cdns_torrent_phy_off(struct phy *phy);
320 
321 static const struct phy_ops cdns_torrent_phy_ops = {
322 	.init		= cdns_torrent_phy_init,
323 	.configure	= cdns_torrent_dp_configure,
324 	.power_on	= cdns_torrent_phy_on,
325 	.power_off	= cdns_torrent_phy_off,
326 	.owner		= THIS_MODULE,
327 };
328 
329 struct cdns_reg_pairs {
330 	u32 val;
331 	u32 off;
332 };
333 
334 struct cdns_torrent_vals {
335 	struct cdns_reg_pairs *reg_pairs;
336 	u32 num_regs;
337 };
338 
339 struct cdns_torrent_data {
340 	u8 block_offset_shift;
341 	u8 reg_offset_shift;
342 	struct cdns_torrent_vals *link_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
343 					       [NUM_SSC_MODE];
344 	struct cdns_torrent_vals *xcvr_diag_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
345 						[NUM_SSC_MODE];
346 	struct cdns_torrent_vals *pcs_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
347 					      [NUM_SSC_MODE];
348 	struct cdns_torrent_vals *cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
349 					  [NUM_SSC_MODE];
350 	struct cdns_torrent_vals *tx_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
351 					    [NUM_SSC_MODE];
352 	struct cdns_torrent_vals *rx_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
353 					    [NUM_SSC_MODE];
354 };
355 
356 struct cdns_regmap_cdb_context {
357 	struct device *dev;
358 	void __iomem *base;
359 	u8 reg_offset_shift;
360 };
361 
362 static int cdns_regmap_write(void *context, unsigned int reg, unsigned int val)
363 {
364 	struct cdns_regmap_cdb_context *ctx = context;
365 	u32 offset = reg << ctx->reg_offset_shift;
366 
367 	writew(val, ctx->base + offset);
368 
369 	return 0;
370 }
371 
372 static int cdns_regmap_read(void *context, unsigned int reg, unsigned int *val)
373 {
374 	struct cdns_regmap_cdb_context *ctx = context;
375 	u32 offset = reg << ctx->reg_offset_shift;
376 
377 	*val = readw(ctx->base + offset);
378 	return 0;
379 }
380 
381 static int cdns_regmap_dptx_write(void *context, unsigned int reg,
382 				  unsigned int val)
383 {
384 	struct cdns_regmap_cdb_context *ctx = context;
385 	u32 offset = reg;
386 
387 	writel(val, ctx->base + offset);
388 
389 	return 0;
390 }
391 
392 static int cdns_regmap_dptx_read(void *context, unsigned int reg,
393 				 unsigned int *val)
394 {
395 	struct cdns_regmap_cdb_context *ctx = context;
396 	u32 offset = reg;
397 
398 	*val = readl(ctx->base + offset);
399 	return 0;
400 }
401 
402 #define TORRENT_TX_LANE_CDB_REGMAP_CONF(n) \
403 { \
404 	.name = "torrent_tx_lane" n "_cdb", \
405 	.reg_stride = 1, \
406 	.fast_io = true, \
407 	.reg_write = cdns_regmap_write, \
408 	.reg_read = cdns_regmap_read, \
409 }
410 
411 #define TORRENT_RX_LANE_CDB_REGMAP_CONF(n) \
412 { \
413 	.name = "torrent_rx_lane" n "_cdb", \
414 	.reg_stride = 1, \
415 	.fast_io = true, \
416 	.reg_write = cdns_regmap_write, \
417 	.reg_read = cdns_regmap_read, \
418 }
419 
420 static const struct regmap_config cdns_torrent_tx_lane_cdb_config[] = {
421 	TORRENT_TX_LANE_CDB_REGMAP_CONF("0"),
422 	TORRENT_TX_LANE_CDB_REGMAP_CONF("1"),
423 	TORRENT_TX_LANE_CDB_REGMAP_CONF("2"),
424 	TORRENT_TX_LANE_CDB_REGMAP_CONF("3"),
425 };
426 
427 static const struct regmap_config cdns_torrent_rx_lane_cdb_config[] = {
428 	TORRENT_RX_LANE_CDB_REGMAP_CONF("0"),
429 	TORRENT_RX_LANE_CDB_REGMAP_CONF("1"),
430 	TORRENT_RX_LANE_CDB_REGMAP_CONF("2"),
431 	TORRENT_RX_LANE_CDB_REGMAP_CONF("3"),
432 };
433 
434 static const struct regmap_config cdns_torrent_common_cdb_config = {
435 	.name = "torrent_common_cdb",
436 	.reg_stride = 1,
437 	.fast_io = true,
438 	.reg_write = cdns_regmap_write,
439 	.reg_read = cdns_regmap_read,
440 };
441 
442 static const struct regmap_config cdns_torrent_phy_pcs_cmn_cdb_config = {
443 	.name = "torrent_phy_pcs_cmn_cdb",
444 	.reg_stride = 1,
445 	.fast_io = true,
446 	.reg_write = cdns_regmap_write,
447 	.reg_read = cdns_regmap_read,
448 };
449 
450 static const struct regmap_config cdns_torrent_phy_pma_cmn_cdb_config = {
451 	.name = "torrent_phy_pma_cmn_cdb",
452 	.reg_stride = 1,
453 	.fast_io = true,
454 	.reg_write = cdns_regmap_write,
455 	.reg_read = cdns_regmap_read,
456 };
457 
458 static const struct regmap_config cdns_torrent_dptx_phy_config = {
459 	.name = "torrent_dptx_phy",
460 	.reg_stride = 1,
461 	.fast_io = true,
462 	.reg_write = cdns_regmap_dptx_write,
463 	.reg_read = cdns_regmap_dptx_read,
464 };
465 
466 /* PHY mmr access functions */
467 
468 static void cdns_torrent_phy_write(struct regmap *regmap, u32 offset, u32 val)
469 {
470 	regmap_write(regmap, offset, val);
471 }
472 
473 static u32 cdns_torrent_phy_read(struct regmap *regmap, u32 offset)
474 {
475 	unsigned int val;
476 
477 	regmap_read(regmap, offset, &val);
478 	return val;
479 }
480 
481 /* DPTX mmr access functions */
482 
483 static void cdns_torrent_dp_write(struct regmap *regmap, u32 offset, u32 val)
484 {
485 	regmap_write(regmap, offset, val);
486 }
487 
488 static u32 cdns_torrent_dp_read(struct regmap *regmap, u32 offset)
489 {
490 	u32 val;
491 
492 	regmap_read(regmap, offset, &val);
493 	return val;
494 }
495 
496 /*
497  * Structure used to store values of PHY registers for voltage-related
498  * coefficients, for particular voltage swing and pre-emphasis level. Values
499  * are shared across all physical lanes.
500  */
501 struct coefficients {
502 	/* Value of DRV_DIAG_TX_DRV register to use */
503 	u16 diag_tx_drv;
504 	/* Value of TX_TXCC_MGNFS_MULT_000 register to use */
505 	u16 mgnfs_mult;
506 	/* Value of TX_TXCC_CPOST_MULT_00 register to use */
507 	u16 cpost_mult;
508 };
509 
510 /*
511  * Array consists of values of voltage-related registers for sd0801 PHY. A value
512  * of 0xFFFF is a placeholder for invalid combination, and will never be used.
513  */
514 static const struct coefficients vltg_coeff[4][4] = {
515 	/* voltage swing 0, pre-emphasis 0->3 */
516 	{	{.diag_tx_drv = 0x0003, .mgnfs_mult = 0x002A,
517 		 .cpost_mult = 0x0000},
518 		{.diag_tx_drv = 0x0003, .mgnfs_mult = 0x001F,
519 		 .cpost_mult = 0x0014},
520 		{.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0012,
521 		 .cpost_mult = 0x0020},
522 		{.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0000,
523 		 .cpost_mult = 0x002A}
524 	},
525 
526 	/* voltage swing 1, pre-emphasis 0->3 */
527 	{	{.diag_tx_drv = 0x0003, .mgnfs_mult = 0x001F,
528 		 .cpost_mult = 0x0000},
529 		{.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0013,
530 		 .cpost_mult = 0x0012},
531 		{.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0000,
532 		 .cpost_mult = 0x001F},
533 		{.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
534 		 .cpost_mult = 0xFFFF}
535 	},
536 
537 	/* voltage swing 2, pre-emphasis 0->3 */
538 	{	{.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0013,
539 		 .cpost_mult = 0x0000},
540 		{.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0000,
541 		 .cpost_mult = 0x0013},
542 		{.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
543 		 .cpost_mult = 0xFFFF},
544 		{.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
545 		 .cpost_mult = 0xFFFF}
546 	},
547 
548 	/* voltage swing 3, pre-emphasis 0->3 */
549 	{	{.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0000,
550 		 .cpost_mult = 0x0000},
551 		{.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
552 		 .cpost_mult = 0xFFFF},
553 		{.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
554 		 .cpost_mult = 0xFFFF},
555 		{.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
556 		 .cpost_mult = 0xFFFF}
557 	}
558 };
559 
560 /*
561  * Enable or disable PLL for selected lanes.
562  */
563 static int cdns_torrent_dp_set_pll_en(struct cdns_torrent_phy *cdns_phy,
564 				      struct phy_configure_opts_dp *dp,
565 				      bool enable)
566 {
567 	u32 rd_val;
568 	u32 ret;
569 	struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
570 
571 	/*
572 	 * Used to determine, which bits to check for or enable in
573 	 * PHY_PMA_XCVR_PLLCLK_EN register.
574 	 */
575 	u32 pll_bits;
576 	/* Used to enable or disable lanes. */
577 	u32 pll_val;
578 
579 	/* Select values of registers and mask, depending on enabled lane
580 	 * count.
581 	 */
582 	switch (dp->lanes) {
583 	/* lane 0 */
584 	case (1):
585 		pll_bits = 0x00000001;
586 		break;
587 	/* lanes 0-1 */
588 	case (2):
589 		pll_bits = 0x00000003;
590 		break;
591 	/* lanes 0-3, all */
592 	default:
593 		pll_bits = 0x0000000F;
594 		break;
595 	}
596 
597 	if (enable)
598 		pll_val = pll_bits;
599 	else
600 		pll_val = 0x00000000;
601 
602 	cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_PLLCLK_EN, pll_val);
603 
604 	/* Wait for acknowledgment from PHY. */
605 	ret = regmap_read_poll_timeout(regmap,
606 				       PHY_PMA_XCVR_PLLCLK_EN_ACK,
607 				       rd_val,
608 				       (rd_val & pll_bits) == pll_val,
609 				       0, POLL_TIMEOUT_US);
610 	ndelay(100);
611 	return ret;
612 }
613 
614 /*
615  * Perform register operations related to setting link rate, once powerstate is
616  * set and PLL disable request was processed.
617  */
618 static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy,
619 					  struct phy_configure_opts_dp *dp)
620 {
621 	u32 ret;
622 	u32 read_val;
623 
624 	/* Disable the cmn_pll0_en before re-programming the new data rate. */
625 	regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, 0x0);
626 
627 	/*
628 	 * Wait for PLL ready de-assertion.
629 	 * For PLL0 - PHY_PMA_CMN_CTRL2[2] == 1
630 	 */
631 	ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2,
632 					     read_val,
633 					     ((read_val >> 2) & 0x01) != 0,
634 					     0, POLL_TIMEOUT_US);
635 	if (ret)
636 		return ret;
637 	ndelay(200);
638 
639 	/* DP Rate Change - VCO Output settings. */
640 	if (cdns_phy->ref_clk_rate == REF_CLK_19_2MHz) {
641 		/* PMA common configuration 19.2MHz */
642 		cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy, dp->link_rate,
643 							dp->ssc);
644 		cdns_torrent_dp_pma_cmn_cfg_19_2mhz(cdns_phy);
645 	} else if (cdns_phy->ref_clk_rate == REF_CLK_25MHz) {
646 		/* PMA common configuration 25MHz */
647 		cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy, dp->link_rate,
648 						      dp->ssc);
649 		cdns_torrent_dp_pma_cmn_cfg_25mhz(cdns_phy);
650 	}
651 	cdns_torrent_dp_pma_cmn_rate(cdns_phy, dp->link_rate, dp->lanes);
652 
653 	/* Enable the cmn_pll0_en. */
654 	regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, 0x3);
655 
656 	/*
657 	 * Wait for PLL ready assertion.
658 	 * For PLL0 - PHY_PMA_CMN_CTRL2[0] == 1
659 	 */
660 	ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2,
661 					     read_val,
662 					     (read_val & 0x01) != 0,
663 					     0, POLL_TIMEOUT_US);
664 	return ret;
665 }
666 
667 /*
668  * Verify, that parameters to configure PHY with are correct.
669  */
670 static int cdns_torrent_dp_verify_config(struct cdns_torrent_inst *inst,
671 					 struct phy_configure_opts_dp *dp)
672 {
673 	u8 i;
674 
675 	/* If changing link rate was required, verify it's supported. */
676 	if (dp->set_rate) {
677 		switch (dp->link_rate) {
678 		case 1620:
679 		case 2160:
680 		case 2430:
681 		case 2700:
682 		case 3240:
683 		case 4320:
684 		case 5400:
685 		case 8100:
686 			/* valid bit rate */
687 			break;
688 		default:
689 			return -EINVAL;
690 		}
691 	}
692 
693 	/* Verify lane count. */
694 	switch (dp->lanes) {
695 	case 1:
696 	case 2:
697 	case 4:
698 		/* valid lane count. */
699 		break;
700 	default:
701 		return -EINVAL;
702 	}
703 
704 	/* Check against actual number of PHY's lanes. */
705 	if (dp->lanes > inst->num_lanes)
706 		return -EINVAL;
707 
708 	/*
709 	 * If changing voltages is required, check swing and pre-emphasis
710 	 * levels, per-lane.
711 	 */
712 	if (dp->set_voltages) {
713 		/* Lane count verified previously. */
714 		for (i = 0; i < dp->lanes; i++) {
715 			if (dp->voltage[i] > 3 || dp->pre[i] > 3)
716 				return -EINVAL;
717 
718 			/* Sum of voltage swing and pre-emphasis levels cannot
719 			 * exceed 3.
720 			 */
721 			if (dp->voltage[i] + dp->pre[i] > 3)
722 				return -EINVAL;
723 		}
724 	}
725 
726 	return 0;
727 }
728 
729 /* Set power state A0 and PLL clock enable to 0 on enabled lanes. */
730 static void cdns_torrent_dp_set_a0_pll(struct cdns_torrent_phy *cdns_phy,
731 				       u32 num_lanes)
732 {
733 	struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
734 	u32 pwr_state = cdns_torrent_dp_read(regmap,
735 					     PHY_PMA_XCVR_POWER_STATE_REQ);
736 	u32 pll_clk_en = cdns_torrent_dp_read(regmap,
737 					      PHY_PMA_XCVR_PLLCLK_EN);
738 
739 	/* Lane 0 is always enabled. */
740 	pwr_state &= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK <<
741 		       PHY_POWER_STATE_LN_0);
742 	pll_clk_en &= ~0x01U;
743 
744 	if (num_lanes > 1) {
745 		/* lane 1 */
746 		pwr_state &= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK <<
747 			       PHY_POWER_STATE_LN_1);
748 		pll_clk_en &= ~(0x01U << 1);
749 	}
750 
751 	if (num_lanes > 2) {
752 		/* lanes 2 and 3 */
753 		pwr_state &= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK <<
754 			       PHY_POWER_STATE_LN_2);
755 		pwr_state &= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK <<
756 			       PHY_POWER_STATE_LN_3);
757 		pll_clk_en &= ~(0x01U << 2);
758 		pll_clk_en &= ~(0x01U << 3);
759 	}
760 
761 	cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_POWER_STATE_REQ, pwr_state);
762 	cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_PLLCLK_EN, pll_clk_en);
763 }
764 
765 /* Configure lane count as required. */
766 static int cdns_torrent_dp_set_lanes(struct cdns_torrent_phy *cdns_phy,
767 				     struct phy_configure_opts_dp *dp)
768 {
769 	u32 value;
770 	u32 ret;
771 	struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
772 	u8 lane_mask = (1 << dp->lanes) - 1;
773 
774 	value = cdns_torrent_dp_read(regmap, PHY_RESET);
775 	/* clear pma_tx_elec_idle_ln_* bits. */
776 	value &= ~PMA_TX_ELEC_IDLE_MASK;
777 	/* Assert pma_tx_elec_idle_ln_* for disabled lanes. */
778 	value |= ((~lane_mask) << PMA_TX_ELEC_IDLE_SHIFT) &
779 		 PMA_TX_ELEC_IDLE_MASK;
780 	cdns_torrent_dp_write(regmap, PHY_RESET, value);
781 
782 	/* reset the link by asserting phy_l00_reset_n low */
783 	cdns_torrent_dp_write(regmap, PHY_RESET,
784 			      value & (~PHY_L00_RESET_N_MASK));
785 
786 	/*
787 	 * Assert lane reset on unused lanes and lane 0 so they remain in reset
788 	 * and powered down when re-enabling the link
789 	 */
790 	value = (value & 0x0000FFF0) | (0x0000000E & lane_mask);
791 	cdns_torrent_dp_write(regmap, PHY_RESET, value);
792 
793 	cdns_torrent_dp_set_a0_pll(cdns_phy, dp->lanes);
794 
795 	/* release phy_l0*_reset_n based on used laneCount */
796 	value = (value & 0x0000FFF0) | (0x0000000F & lane_mask);
797 	cdns_torrent_dp_write(regmap, PHY_RESET, value);
798 
799 	/* Wait, until PHY gets ready after releasing PHY reset signal. */
800 	ret = cdns_torrent_dp_wait_pma_cmn_ready(cdns_phy);
801 	if (ret)
802 		return ret;
803 
804 	ndelay(100);
805 
806 	/* release pma_xcvr_pllclk_en_ln_*, only for the master lane */
807 	cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_PLLCLK_EN, 0x0001);
808 
809 	ret = cdns_torrent_dp_run(cdns_phy, dp->lanes);
810 
811 	return ret;
812 }
813 
814 /* Configure link rate as required. */
815 static int cdns_torrent_dp_set_rate(struct cdns_torrent_phy *cdns_phy,
816 				    struct phy_configure_opts_dp *dp)
817 {
818 	u32 ret;
819 
820 	ret = cdns_torrent_dp_set_power_state(cdns_phy, dp->lanes,
821 					      POWERSTATE_A3);
822 	if (ret)
823 		return ret;
824 	ret = cdns_torrent_dp_set_pll_en(cdns_phy, dp, false);
825 	if (ret)
826 		return ret;
827 	ndelay(200);
828 
829 	ret = cdns_torrent_dp_configure_rate(cdns_phy, dp);
830 	if (ret)
831 		return ret;
832 	ndelay(200);
833 
834 	ret = cdns_torrent_dp_set_pll_en(cdns_phy, dp, true);
835 	if (ret)
836 		return ret;
837 	ret = cdns_torrent_dp_set_power_state(cdns_phy, dp->lanes,
838 					      POWERSTATE_A2);
839 	if (ret)
840 		return ret;
841 	ret = cdns_torrent_dp_set_power_state(cdns_phy, dp->lanes,
842 					      POWERSTATE_A0);
843 	if (ret)
844 		return ret;
845 	ndelay(900);
846 
847 	return ret;
848 }
849 
850 /* Configure voltage swing and pre-emphasis for all enabled lanes. */
851 static void cdns_torrent_dp_set_voltages(struct cdns_torrent_phy *cdns_phy,
852 					 struct phy_configure_opts_dp *dp)
853 {
854 	u8 lane;
855 	u16 val;
856 
857 	for (lane = 0; lane < dp->lanes; lane++) {
858 		val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[lane],
859 					    TX_DIAG_ACYA);
860 		/*
861 		 * Write 1 to register bit TX_DIAG_ACYA[0] to freeze the
862 		 * current state of the analog TX driver.
863 		 */
864 		val |= TX_DIAG_ACYA_HBDC_MASK;
865 		cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
866 				       TX_DIAG_ACYA, val);
867 
868 		cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
869 				       TX_TXCC_CTRL, 0x08A4);
870 		val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].diag_tx_drv;
871 		cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
872 				       DRV_DIAG_TX_DRV, val);
873 		val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].mgnfs_mult;
874 		cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
875 				       TX_TXCC_MGNFS_MULT_000,
876 				       val);
877 		val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].cpost_mult;
878 		cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
879 				       TX_TXCC_CPOST_MULT_00,
880 				       val);
881 
882 		val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[lane],
883 					    TX_DIAG_ACYA);
884 		/*
885 		 * Write 0 to register bit TX_DIAG_ACYA[0] to allow the state of
886 		 * analog TX driver to reflect the new programmed one.
887 		 */
888 		val &= ~TX_DIAG_ACYA_HBDC_MASK;
889 		cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
890 				       TX_DIAG_ACYA, val);
891 	}
892 };
893 
894 static int cdns_torrent_dp_configure(struct phy *phy,
895 				     union phy_configure_opts *opts)
896 {
897 	struct cdns_torrent_inst *inst = phy_get_drvdata(phy);
898 	struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
899 	int ret;
900 
901 	ret = cdns_torrent_dp_verify_config(inst, &opts->dp);
902 	if (ret) {
903 		dev_err(&phy->dev, "invalid params for phy configure\n");
904 		return ret;
905 	}
906 
907 	if (opts->dp.set_lanes) {
908 		ret = cdns_torrent_dp_set_lanes(cdns_phy, &opts->dp);
909 		if (ret) {
910 			dev_err(&phy->dev, "cdns_torrent_dp_set_lanes failed\n");
911 			return ret;
912 		}
913 	}
914 
915 	if (opts->dp.set_rate) {
916 		ret = cdns_torrent_dp_set_rate(cdns_phy, &opts->dp);
917 		if (ret) {
918 			dev_err(&phy->dev, "cdns_torrent_dp_set_rate failed\n");
919 			return ret;
920 		}
921 	}
922 
923 	if (opts->dp.set_voltages)
924 		cdns_torrent_dp_set_voltages(cdns_phy, &opts->dp);
925 
926 	return ret;
927 }
928 
929 static int cdns_torrent_dp_init(struct phy *phy)
930 {
931 	unsigned char lane_bits;
932 	int ret;
933 	struct cdns_torrent_inst *inst = phy_get_drvdata(phy);
934 	struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
935 	struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
936 
937 	switch (cdns_phy->ref_clk_rate) {
938 	case REF_CLK_19_2MHz:
939 	case REF_CLK_25MHz:
940 		/* Valid Ref Clock Rate */
941 		break;
942 	default:
943 		dev_err(cdns_phy->dev, "Unsupported Ref Clock Rate\n");
944 		return -EINVAL;
945 	}
946 
947 	cdns_torrent_dp_write(regmap, PHY_AUX_CTRL, 0x0003); /* enable AUX */
948 
949 	/* PHY PMA registers configuration function */
950 	cdns_torrent_dp_pma_cfg(cdns_phy, inst);
951 
952 	/*
953 	 * Set lines power state to A0
954 	 * Set lines pll clk enable to 0
955 	 */
956 	cdns_torrent_dp_set_a0_pll(cdns_phy, inst->num_lanes);
957 
958 	/*
959 	 * release phy_l0*_reset_n and pma_tx_elec_idle_ln_* based on
960 	 * used lanes
961 	 */
962 	lane_bits = (1 << inst->num_lanes) - 1;
963 	cdns_torrent_dp_write(regmap, PHY_RESET,
964 			      ((0xF & ~lane_bits) << 4) | (0xF & lane_bits));
965 
966 	/* release pma_xcvr_pllclk_en_ln_*, only for the master lane */
967 	cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_PLLCLK_EN, 0x0001);
968 
969 	/* PHY PMA registers configuration functions */
970 	/* Initialize PHY with max supported link rate, without SSC. */
971 	if (cdns_phy->ref_clk_rate == REF_CLK_19_2MHz)
972 		cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy,
973 							cdns_phy->max_bit_rate,
974 							false);
975 	else if (cdns_phy->ref_clk_rate == REF_CLK_25MHz)
976 		cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy,
977 						      cdns_phy->max_bit_rate,
978 						      false);
979 	cdns_torrent_dp_pma_cmn_rate(cdns_phy, cdns_phy->max_bit_rate,
980 				     inst->num_lanes);
981 
982 	/* take out of reset */
983 	regmap_field_write(cdns_phy->phy_reset_ctrl, 0x1);
984 
985 	cdns_torrent_phy_on(phy);
986 
987 	ret = cdns_torrent_dp_wait_pma_cmn_ready(cdns_phy);
988 	if (ret)
989 		return ret;
990 
991 	ret = cdns_torrent_dp_run(cdns_phy, inst->num_lanes);
992 
993 	return ret;
994 }
995 
996 static
997 int cdns_torrent_dp_wait_pma_cmn_ready(struct cdns_torrent_phy *cdns_phy)
998 {
999 	unsigned int reg;
1000 	int ret;
1001 	struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
1002 
1003 	ret = regmap_read_poll_timeout(regmap, PHY_PMA_CMN_READY, reg,
1004 				       reg & 1, 0, POLL_TIMEOUT_US);
1005 	if (ret == -ETIMEDOUT) {
1006 		dev_err(cdns_phy->dev,
1007 			"timeout waiting for PMA common ready\n");
1008 		return -ETIMEDOUT;
1009 	}
1010 
1011 	return 0;
1012 }
1013 
1014 static void cdns_torrent_dp_pma_cfg(struct cdns_torrent_phy *cdns_phy,
1015 				    struct cdns_torrent_inst *inst)
1016 {
1017 	unsigned int i;
1018 
1019 	if (cdns_phy->ref_clk_rate == REF_CLK_19_2MHz)
1020 		/* PMA common configuration 19.2MHz */
1021 		cdns_torrent_dp_pma_cmn_cfg_19_2mhz(cdns_phy);
1022 	else if (cdns_phy->ref_clk_rate == REF_CLK_25MHz)
1023 		/* PMA common configuration 25MHz */
1024 		cdns_torrent_dp_pma_cmn_cfg_25mhz(cdns_phy);
1025 
1026 	/* PMA lane configuration to deal with multi-link operation */
1027 	for (i = 0; i < inst->num_lanes; i++)
1028 		cdns_torrent_dp_pma_lane_cfg(cdns_phy, i);
1029 }
1030 
1031 static
1032 void cdns_torrent_dp_pma_cmn_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy)
1033 {
1034 	struct regmap *regmap = cdns_phy->regmap_common_cdb;
1035 
1036 	/* refclock registers - assumes 19.2 MHz refclock */
1037 	cdns_torrent_phy_write(regmap, CMN_SSM_BIAS_TMR, 0x0014);
1038 	cdns_torrent_phy_write(regmap, CMN_PLLSM0_PLLPRE_TMR, 0x0027);
1039 	cdns_torrent_phy_write(regmap, CMN_PLLSM0_PLLLOCK_TMR, 0x00A1);
1040 	cdns_torrent_phy_write(regmap, CMN_PLLSM1_PLLPRE_TMR, 0x0027);
1041 	cdns_torrent_phy_write(regmap, CMN_PLLSM1_PLLLOCK_TMR, 0x00A1);
1042 	cdns_torrent_phy_write(regmap, CMN_BGCAL_INIT_TMR, 0x0060);
1043 	cdns_torrent_phy_write(regmap, CMN_BGCAL_ITER_TMR, 0x0060);
1044 	cdns_torrent_phy_write(regmap, CMN_IBCAL_INIT_TMR, 0x0014);
1045 	cdns_torrent_phy_write(regmap, CMN_TXPUCAL_INIT_TMR, 0x0018);
1046 	cdns_torrent_phy_write(regmap, CMN_TXPUCAL_ITER_TMR, 0x0005);
1047 	cdns_torrent_phy_write(regmap, CMN_TXPDCAL_INIT_TMR, 0x0018);
1048 	cdns_torrent_phy_write(regmap, CMN_TXPDCAL_ITER_TMR, 0x0005);
1049 	cdns_torrent_phy_write(regmap, CMN_RXCAL_INIT_TMR, 0x0240);
1050 	cdns_torrent_phy_write(regmap, CMN_RXCAL_ITER_TMR, 0x0005);
1051 	cdns_torrent_phy_write(regmap, CMN_SD_CAL_INIT_TMR, 0x0002);
1052 	cdns_torrent_phy_write(regmap, CMN_SD_CAL_ITER_TMR, 0x0002);
1053 	cdns_torrent_phy_write(regmap, CMN_SD_CAL_REFTIM_START, 0x000B);
1054 	cdns_torrent_phy_write(regmap, CMN_SD_CAL_PLLCNT_START, 0x0137);
1055 
1056 	/* PLL registers */
1057 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
1058 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
1059 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_FILT_PADJ_M0, 0x0F08);
1060 	cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004);
1061 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
1062 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
1063 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_FILT_PADJ_M0, 0x0F08);
1064 	cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004);
1065 	cdns_torrent_phy_write(regmap, CMN_PLL0_VCOCAL_INIT_TMR, 0x00C0);
1066 	cdns_torrent_phy_write(regmap, CMN_PLL0_VCOCAL_ITER_TMR, 0x0004);
1067 	cdns_torrent_phy_write(regmap, CMN_PLL1_VCOCAL_INIT_TMR, 0x00C0);
1068 	cdns_torrent_phy_write(regmap, CMN_PLL1_VCOCAL_ITER_TMR, 0x0004);
1069 	cdns_torrent_phy_write(regmap, CMN_PLL0_VCOCAL_REFTIM_START, 0x0260);
1070 	cdns_torrent_phy_write(regmap, CMN_PLL0_VCOCAL_TCTRL, 0x0003);
1071 	cdns_torrent_phy_write(regmap, CMN_PLL1_VCOCAL_REFTIM_START, 0x0260);
1072 	cdns_torrent_phy_write(regmap, CMN_PLL1_VCOCAL_TCTRL, 0x0003);
1073 }
1074 
1075 /*
1076  * Set registers responsible for enabling and configuring SSC, with second and
1077  * third register values provided by parameters.
1078  */
1079 static
1080 void cdns_torrent_dp_enable_ssc_19_2mhz(struct cdns_torrent_phy *cdns_phy,
1081 					u32 ctrl2_val, u32 ctrl3_val)
1082 {
1083 	struct regmap *regmap = cdns_phy->regmap_common_cdb;
1084 
1085 	cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0001);
1086 	cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, ctrl2_val);
1087 	cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, ctrl3_val);
1088 	cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL4_M0, 0x0003);
1089 	cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, 0x0001);
1090 	cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, ctrl2_val);
1091 	cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, ctrl3_val);
1092 	cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL4_M0, 0x0003);
1093 }
1094 
1095 static
1096 void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy,
1097 					     u32 rate, bool ssc)
1098 {
1099 	struct regmap *regmap = cdns_phy->regmap_common_cdb;
1100 
1101 	/* Assumes 19.2 MHz refclock */
1102 	switch (rate) {
1103 	/* Setting VCO for 10.8GHz */
1104 	case 2700:
1105 	case 5400:
1106 		cdns_torrent_phy_write(regmap,
1107 				       CMN_PLL0_INTDIV_M0, 0x0119);
1108 		cdns_torrent_phy_write(regmap,
1109 				       CMN_PLL0_FRACDIVL_M0, 0x4000);
1110 		cdns_torrent_phy_write(regmap,
1111 				       CMN_PLL0_FRACDIVH_M0, 0x0002);
1112 		cdns_torrent_phy_write(regmap,
1113 				       CMN_PLL0_HIGH_THR_M0, 0x00BC);
1114 		cdns_torrent_phy_write(regmap,
1115 				       CMN_PDIAG_PLL0_CTRL_M0, 0x0012);
1116 		cdns_torrent_phy_write(regmap,
1117 				       CMN_PLL1_INTDIV_M0, 0x0119);
1118 		cdns_torrent_phy_write(regmap,
1119 				       CMN_PLL1_FRACDIVL_M0, 0x4000);
1120 		cdns_torrent_phy_write(regmap,
1121 				       CMN_PLL1_FRACDIVH_M0, 0x0002);
1122 		cdns_torrent_phy_write(regmap,
1123 				       CMN_PLL1_HIGH_THR_M0, 0x00BC);
1124 		cdns_torrent_phy_write(regmap,
1125 				       CMN_PDIAG_PLL1_CTRL_M0, 0x0012);
1126 		if (ssc)
1127 			cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x033A,
1128 							   0x006A);
1129 		break;
1130 	/* Setting VCO for 9.72GHz */
1131 	case 1620:
1132 	case 2430:
1133 	case 3240:
1134 		cdns_torrent_phy_write(regmap,
1135 				       CMN_PLL0_INTDIV_M0, 0x01FA);
1136 		cdns_torrent_phy_write(regmap,
1137 				       CMN_PLL0_FRACDIVL_M0, 0x4000);
1138 		cdns_torrent_phy_write(regmap,
1139 				       CMN_PLL0_FRACDIVH_M0, 0x0002);
1140 		cdns_torrent_phy_write(regmap,
1141 				       CMN_PLL0_HIGH_THR_M0, 0x0152);
1142 		cdns_torrent_phy_write(regmap,
1143 				       CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
1144 		cdns_torrent_phy_write(regmap,
1145 				       CMN_PLL1_INTDIV_M0, 0x01FA);
1146 		cdns_torrent_phy_write(regmap,
1147 				       CMN_PLL1_FRACDIVL_M0, 0x4000);
1148 		cdns_torrent_phy_write(regmap,
1149 				       CMN_PLL1_FRACDIVH_M0, 0x0002);
1150 		cdns_torrent_phy_write(regmap,
1151 				       CMN_PLL1_HIGH_THR_M0, 0x0152);
1152 		cdns_torrent_phy_write(regmap,
1153 				       CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
1154 		if (ssc)
1155 			cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x05DD,
1156 							   0x0069);
1157 		break;
1158 	/* Setting VCO for 8.64GHz */
1159 	case 2160:
1160 	case 4320:
1161 		cdns_torrent_phy_write(regmap,
1162 				       CMN_PLL0_INTDIV_M0, 0x01C2);
1163 		cdns_torrent_phy_write(regmap,
1164 				       CMN_PLL0_FRACDIVL_M0, 0x0000);
1165 		cdns_torrent_phy_write(regmap,
1166 				       CMN_PLL0_FRACDIVH_M0, 0x0002);
1167 		cdns_torrent_phy_write(regmap,
1168 				       CMN_PLL0_HIGH_THR_M0, 0x012C);
1169 		cdns_torrent_phy_write(regmap,
1170 				       CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
1171 		cdns_torrent_phy_write(regmap,
1172 				       CMN_PLL1_INTDIV_M0, 0x01C2);
1173 		cdns_torrent_phy_write(regmap,
1174 				       CMN_PLL1_FRACDIVL_M0, 0x0000);
1175 		cdns_torrent_phy_write(regmap,
1176 				       CMN_PLL1_FRACDIVH_M0, 0x0002);
1177 		cdns_torrent_phy_write(regmap,
1178 				       CMN_PLL1_HIGH_THR_M0, 0x012C);
1179 		cdns_torrent_phy_write(regmap,
1180 				       CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
1181 		if (ssc)
1182 			cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x0536,
1183 							   0x0069);
1184 		break;
1185 	/* Setting VCO for 8.1GHz */
1186 	case 8100:
1187 		cdns_torrent_phy_write(regmap,
1188 				       CMN_PLL0_INTDIV_M0, 0x01A5);
1189 		cdns_torrent_phy_write(regmap,
1190 				       CMN_PLL0_FRACDIVL_M0, 0xE000);
1191 		cdns_torrent_phy_write(regmap,
1192 				       CMN_PLL0_FRACDIVH_M0, 0x0002);
1193 		cdns_torrent_phy_write(regmap,
1194 				       CMN_PLL0_HIGH_THR_M0, 0x011A);
1195 		cdns_torrent_phy_write(regmap,
1196 				       CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
1197 		cdns_torrent_phy_write(regmap,
1198 				       CMN_PLL1_INTDIV_M0, 0x01A5);
1199 		cdns_torrent_phy_write(regmap,
1200 				       CMN_PLL1_FRACDIVL_M0, 0xE000);
1201 		cdns_torrent_phy_write(regmap,
1202 				       CMN_PLL1_FRACDIVH_M0, 0x0002);
1203 		cdns_torrent_phy_write(regmap,
1204 				       CMN_PLL1_HIGH_THR_M0, 0x011A);
1205 		cdns_torrent_phy_write(regmap,
1206 				       CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
1207 		if (ssc)
1208 			cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x04D7,
1209 							   0x006A);
1210 		break;
1211 	}
1212 
1213 	if (ssc) {
1214 		cdns_torrent_phy_write(regmap,
1215 				       CMN_PLL0_VCOCAL_PLLCNT_START, 0x025E);
1216 		cdns_torrent_phy_write(regmap,
1217 				       CMN_PLL0_LOCK_PLLCNT_THR, 0x0005);
1218 		cdns_torrent_phy_write(regmap,
1219 				       CMN_PLL1_VCOCAL_PLLCNT_START, 0x025E);
1220 		cdns_torrent_phy_write(regmap,
1221 				       CMN_PLL1_LOCK_PLLCNT_THR, 0x0005);
1222 	} else {
1223 		cdns_torrent_phy_write(regmap,
1224 				       CMN_PLL0_VCOCAL_PLLCNT_START, 0x0260);
1225 		cdns_torrent_phy_write(regmap,
1226 				       CMN_PLL1_VCOCAL_PLLCNT_START, 0x0260);
1227 		/* Set reset register values to disable SSC */
1228 		cdns_torrent_phy_write(regmap,
1229 				       CMN_PLL0_SS_CTRL1_M0, 0x0002);
1230 		cdns_torrent_phy_write(regmap,
1231 				       CMN_PLL0_SS_CTRL2_M0, 0x0000);
1232 		cdns_torrent_phy_write(regmap,
1233 				       CMN_PLL0_SS_CTRL3_M0, 0x0000);
1234 		cdns_torrent_phy_write(regmap,
1235 				       CMN_PLL0_SS_CTRL4_M0, 0x0000);
1236 		cdns_torrent_phy_write(regmap,
1237 				       CMN_PLL0_LOCK_PLLCNT_THR, 0x0003);
1238 		cdns_torrent_phy_write(regmap,
1239 				       CMN_PLL1_SS_CTRL1_M0, 0x0002);
1240 		cdns_torrent_phy_write(regmap,
1241 				       CMN_PLL1_SS_CTRL2_M0, 0x0000);
1242 		cdns_torrent_phy_write(regmap,
1243 				       CMN_PLL1_SS_CTRL3_M0, 0x0000);
1244 		cdns_torrent_phy_write(regmap,
1245 				       CMN_PLL1_SS_CTRL4_M0, 0x0000);
1246 		cdns_torrent_phy_write(regmap,
1247 				       CMN_PLL1_LOCK_PLLCNT_THR, 0x0003);
1248 	}
1249 
1250 	cdns_torrent_phy_write(regmap, CMN_PLL0_LOCK_REFCNT_START, 0x0099);
1251 	cdns_torrent_phy_write(regmap, CMN_PLL0_LOCK_PLLCNT_START, 0x0099);
1252 	cdns_torrent_phy_write(regmap, CMN_PLL1_LOCK_REFCNT_START, 0x0099);
1253 	cdns_torrent_phy_write(regmap, CMN_PLL1_LOCK_PLLCNT_START, 0x0099);
1254 }
1255 
1256 static
1257 void cdns_torrent_dp_pma_cmn_cfg_25mhz(struct cdns_torrent_phy *cdns_phy)
1258 {
1259 	struct regmap *regmap = cdns_phy->regmap_common_cdb;
1260 
1261 	/* refclock registers - assumes 25 MHz refclock */
1262 	cdns_torrent_phy_write(regmap, CMN_SSM_BIAS_TMR, 0x0019);
1263 	cdns_torrent_phy_write(regmap, CMN_PLLSM0_PLLPRE_TMR, 0x0032);
1264 	cdns_torrent_phy_write(regmap, CMN_PLLSM0_PLLLOCK_TMR, 0x00D1);
1265 	cdns_torrent_phy_write(regmap, CMN_PLLSM1_PLLPRE_TMR, 0x0032);
1266 	cdns_torrent_phy_write(regmap, CMN_PLLSM1_PLLLOCK_TMR, 0x00D1);
1267 	cdns_torrent_phy_write(regmap, CMN_BGCAL_INIT_TMR, 0x007D);
1268 	cdns_torrent_phy_write(regmap, CMN_BGCAL_ITER_TMR, 0x007D);
1269 	cdns_torrent_phy_write(regmap, CMN_IBCAL_INIT_TMR, 0x0019);
1270 	cdns_torrent_phy_write(regmap, CMN_TXPUCAL_INIT_TMR, 0x001E);
1271 	cdns_torrent_phy_write(regmap, CMN_TXPUCAL_ITER_TMR, 0x0006);
1272 	cdns_torrent_phy_write(regmap, CMN_TXPDCAL_INIT_TMR, 0x001E);
1273 	cdns_torrent_phy_write(regmap, CMN_TXPDCAL_ITER_TMR, 0x0006);
1274 	cdns_torrent_phy_write(regmap, CMN_RXCAL_INIT_TMR, 0x02EE);
1275 	cdns_torrent_phy_write(regmap, CMN_RXCAL_ITER_TMR, 0x0006);
1276 	cdns_torrent_phy_write(regmap, CMN_SD_CAL_INIT_TMR, 0x0002);
1277 	cdns_torrent_phy_write(regmap, CMN_SD_CAL_ITER_TMR, 0x0002);
1278 	cdns_torrent_phy_write(regmap, CMN_SD_CAL_REFTIM_START, 0x000E);
1279 	cdns_torrent_phy_write(regmap, CMN_SD_CAL_PLLCNT_START, 0x012B);
1280 
1281 	/* PLL registers */
1282 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
1283 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
1284 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_FILT_PADJ_M0, 0x0F08);
1285 	cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004);
1286 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
1287 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
1288 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_FILT_PADJ_M0, 0x0F08);
1289 	cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004);
1290 	cdns_torrent_phy_write(regmap, CMN_PLL0_VCOCAL_INIT_TMR, 0x00FA);
1291 	cdns_torrent_phy_write(regmap, CMN_PLL0_VCOCAL_ITER_TMR, 0x0004);
1292 	cdns_torrent_phy_write(regmap, CMN_PLL1_VCOCAL_INIT_TMR, 0x00FA);
1293 	cdns_torrent_phy_write(regmap, CMN_PLL1_VCOCAL_ITER_TMR, 0x0004);
1294 	cdns_torrent_phy_write(regmap, CMN_PLL0_VCOCAL_REFTIM_START, 0x0317);
1295 	cdns_torrent_phy_write(regmap, CMN_PLL0_VCOCAL_TCTRL, 0x0003);
1296 	cdns_torrent_phy_write(regmap, CMN_PLL1_VCOCAL_REFTIM_START, 0x0317);
1297 	cdns_torrent_phy_write(regmap, CMN_PLL1_VCOCAL_TCTRL, 0x0003);
1298 }
1299 
1300 /*
1301  * Set registers responsible for enabling and configuring SSC, with second
1302  * register value provided by a parameter.
1303  */
1304 static void cdns_torrent_dp_enable_ssc_25mhz(struct cdns_torrent_phy *cdns_phy,
1305 					     u32 ctrl2_val)
1306 {
1307 	struct regmap *regmap = cdns_phy->regmap_common_cdb;
1308 
1309 	cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0001);
1310 	cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, ctrl2_val);
1311 	cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x007F);
1312 	cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL4_M0, 0x0003);
1313 	cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, 0x0001);
1314 	cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, ctrl2_val);
1315 	cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, 0x007F);
1316 	cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL4_M0, 0x0003);
1317 }
1318 
1319 static
1320 void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy,
1321 					   u32 rate, bool ssc)
1322 {
1323 	struct regmap *regmap = cdns_phy->regmap_common_cdb;
1324 
1325 	/* Assumes 25 MHz refclock */
1326 	switch (rate) {
1327 	/* Setting VCO for 10.8GHz */
1328 	case 2700:
1329 	case 5400:
1330 		cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x01B0);
1331 		cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x0000);
1332 		cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
1333 		cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0120);
1334 		cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x01B0);
1335 		cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x0000);
1336 		cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
1337 		cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0120);
1338 		if (ssc)
1339 			cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x0423);
1340 		break;
1341 	/* Setting VCO for 9.72GHz */
1342 	case 1620:
1343 	case 2430:
1344 	case 3240:
1345 		cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x0184);
1346 		cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0xCCCD);
1347 		cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
1348 		cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0104);
1349 		cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x0184);
1350 		cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0xCCCD);
1351 		cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
1352 		cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0104);
1353 		if (ssc)
1354 			cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x03B9);
1355 		break;
1356 	/* Setting VCO for 8.64GHz */
1357 	case 2160:
1358 	case 4320:
1359 		cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x0159);
1360 		cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x999A);
1361 		cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
1362 		cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x00E7);
1363 		cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x0159);
1364 		cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x999A);
1365 		cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
1366 		cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00E7);
1367 		if (ssc)
1368 			cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x034F);
1369 		break;
1370 	/* Setting VCO for 8.1GHz */
1371 	case 8100:
1372 		cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x0144);
1373 		cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x0000);
1374 		cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
1375 		cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x00D8);
1376 		cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x0144);
1377 		cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x0000);
1378 		cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
1379 		cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00D8);
1380 		if (ssc)
1381 			cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x031A);
1382 		break;
1383 	}
1384 
1385 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
1386 	cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
1387 
1388 	if (ssc) {
1389 		cdns_torrent_phy_write(regmap,
1390 				       CMN_PLL0_VCOCAL_PLLCNT_START, 0x0315);
1391 		cdns_torrent_phy_write(regmap,
1392 				       CMN_PLL0_LOCK_PLLCNT_THR, 0x0005);
1393 		cdns_torrent_phy_write(regmap,
1394 				       CMN_PLL1_VCOCAL_PLLCNT_START, 0x0315);
1395 		cdns_torrent_phy_write(regmap,
1396 				       CMN_PLL1_LOCK_PLLCNT_THR, 0x0005);
1397 	} else {
1398 		cdns_torrent_phy_write(regmap,
1399 				       CMN_PLL0_VCOCAL_PLLCNT_START, 0x0317);
1400 		cdns_torrent_phy_write(regmap,
1401 				       CMN_PLL1_VCOCAL_PLLCNT_START, 0x0317);
1402 		/* Set reset register values to disable SSC */
1403 		cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0002);
1404 		cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL2_M0, 0x0000);
1405 		cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL3_M0, 0x0000);
1406 		cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL4_M0, 0x0000);
1407 		cdns_torrent_phy_write(regmap,
1408 				       CMN_PLL0_LOCK_PLLCNT_THR, 0x0003);
1409 		cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, 0x0002);
1410 		cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL2_M0, 0x0000);
1411 		cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL3_M0, 0x0000);
1412 		cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL4_M0, 0x0000);
1413 		cdns_torrent_phy_write(regmap,
1414 				       CMN_PLL1_LOCK_PLLCNT_THR, 0x0003);
1415 	}
1416 
1417 	cdns_torrent_phy_write(regmap, CMN_PLL0_LOCK_REFCNT_START, 0x00C7);
1418 	cdns_torrent_phy_write(regmap, CMN_PLL0_LOCK_PLLCNT_START, 0x00C7);
1419 	cdns_torrent_phy_write(regmap, CMN_PLL1_LOCK_REFCNT_START, 0x00C7);
1420 	cdns_torrent_phy_write(regmap, CMN_PLL1_LOCK_PLLCNT_START, 0x00C7);
1421 }
1422 
1423 static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy *cdns_phy,
1424 					 u32 rate, u32 num_lanes)
1425 {
1426 	unsigned int clk_sel_val = 0;
1427 	unsigned int hsclk_div_val = 0;
1428 	unsigned int i;
1429 
1430 	/* 16'h0000 for single DP link configuration */
1431 	regmap_field_write(cdns_phy->phy_pll_cfg, 0x0);
1432 
1433 	switch (rate) {
1434 	case 1620:
1435 		clk_sel_val = 0x0f01;
1436 		hsclk_div_val = 2;
1437 		break;
1438 	case 2160:
1439 	case 2430:
1440 	case 2700:
1441 		clk_sel_val = 0x0701;
1442 		hsclk_div_val = 1;
1443 		break;
1444 	case 3240:
1445 		clk_sel_val = 0x0b00;
1446 		hsclk_div_val = 2;
1447 		break;
1448 	case 4320:
1449 	case 5400:
1450 		clk_sel_val = 0x0301;
1451 		hsclk_div_val = 0;
1452 		break;
1453 	case 8100:
1454 		clk_sel_val = 0x0200;
1455 		hsclk_div_val = 0;
1456 		break;
1457 	}
1458 
1459 	cdns_torrent_phy_write(cdns_phy->regmap_common_cdb,
1460 			       CMN_PDIAG_PLL0_CLK_SEL_M0, clk_sel_val);
1461 	cdns_torrent_phy_write(cdns_phy->regmap_common_cdb,
1462 			       CMN_PDIAG_PLL1_CLK_SEL_M0, clk_sel_val);
1463 
1464 	/* PMA lane configuration to deal with multi-link operation */
1465 	for (i = 0; i < num_lanes; i++)
1466 		cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[i],
1467 				       XCVR_DIAG_HSCLK_DIV, hsclk_div_val);
1468 }
1469 
1470 static void cdns_torrent_dp_pma_lane_cfg(struct cdns_torrent_phy *cdns_phy,
1471 					 unsigned int lane)
1472 {
1473 	/* Per lane, refclock-dependent receiver detection setting */
1474 	if (cdns_phy->ref_clk_rate == REF_CLK_19_2MHz)
1475 		cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1476 				       TX_RCVDET_ST_TMR, 0x0780);
1477 	else if (cdns_phy->ref_clk_rate == REF_CLK_25MHz)
1478 		cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1479 				       TX_RCVDET_ST_TMR, 0x09C4);
1480 
1481 	/* Writing Tx/Rx Power State Controllers registers */
1482 	cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1483 			       TX_PSC_A0, 0x00FB);
1484 	cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1485 			       TX_PSC_A2, 0x04AA);
1486 	cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1487 			       TX_PSC_A3, 0x04AA);
1488 	cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1489 			       RX_PSC_A0, 0x0000);
1490 	cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1491 			       RX_PSC_A2, 0x0000);
1492 	cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1493 			       RX_PSC_A3, 0x0000);
1494 
1495 	cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1496 			       RX_PSC_CAL, 0x0000);
1497 
1498 	cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1499 			       RX_REE_GCSM1_CTRL, 0x0000);
1500 	cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1501 			       RX_REE_GCSM2_CTRL, 0x0000);
1502 	cdns_torrent_phy_write(cdns_phy->regmap_rx_lane_cdb[lane],
1503 			       RX_REE_PERGCSM_CTRL, 0x0000);
1504 
1505 	cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1506 			       XCVR_DIAG_BIDI_CTRL, 0x000F);
1507 	cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1508 			       XCVR_DIAG_PLLDRC_CTRL, 0x0001);
1509 	cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[lane],
1510 			       XCVR_DIAG_HSCLK_SEL, 0x0000);
1511 }
1512 
1513 static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy *cdns_phy,
1514 					   u32 num_lanes,
1515 					   enum phy_powerstate powerstate)
1516 {
1517 	/* Register value for power state for a single byte. */
1518 	u32 value_part;
1519 	u32 value;
1520 	u32 mask;
1521 	u32 read_val;
1522 	u32 ret;
1523 	struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
1524 
1525 	switch (powerstate) {
1526 	case (POWERSTATE_A0):
1527 		value_part = 0x01U;
1528 		break;
1529 	case (POWERSTATE_A2):
1530 		value_part = 0x04U;
1531 		break;
1532 	default:
1533 		/* Powerstate A3 */
1534 		value_part = 0x08U;
1535 		break;
1536 	}
1537 
1538 	/* Select values of registers and mask, depending on enabled
1539 	 * lane count.
1540 	 */
1541 	switch (num_lanes) {
1542 	/* lane 0 */
1543 	case (1):
1544 		value = value_part;
1545 		mask = 0x0000003FU;
1546 		break;
1547 	/* lanes 0-1 */
1548 	case (2):
1549 		value = (value_part
1550 			 | (value_part << 8));
1551 		mask = 0x00003F3FU;
1552 		break;
1553 	/* lanes 0-3, all */
1554 	default:
1555 		value = (value_part
1556 			 | (value_part << 8)
1557 			 | (value_part << 16)
1558 			 | (value_part << 24));
1559 		mask = 0x3F3F3F3FU;
1560 		break;
1561 	}
1562 
1563 	/* Set power state A<n>. */
1564 	cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_POWER_STATE_REQ, value);
1565 	/* Wait, until PHY acknowledges power state completion. */
1566 	ret = regmap_read_poll_timeout(regmap, PHY_PMA_XCVR_POWER_STATE_ACK,
1567 				       read_val, (read_val & mask) == value, 0,
1568 				       POLL_TIMEOUT_US);
1569 	cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_POWER_STATE_REQ, 0x00000000);
1570 	ndelay(100);
1571 
1572 	return ret;
1573 }
1574 
1575 static int cdns_torrent_dp_run(struct cdns_torrent_phy *cdns_phy, u32 num_lanes)
1576 {
1577 	unsigned int read_val;
1578 	int ret;
1579 	struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
1580 
1581 	/*
1582 	 * waiting for ACK of pma_xcvr_pllclk_en_ln_*, only for the
1583 	 * master lane
1584 	 */
1585 	ret = regmap_read_poll_timeout(regmap, PHY_PMA_XCVR_PLLCLK_EN_ACK,
1586 				       read_val, read_val & 1,
1587 				       0, POLL_TIMEOUT_US);
1588 	if (ret == -ETIMEDOUT) {
1589 		dev_err(cdns_phy->dev,
1590 			"timeout waiting for link PLL clock enable ack\n");
1591 		return ret;
1592 	}
1593 
1594 	ndelay(100);
1595 
1596 	ret = cdns_torrent_dp_set_power_state(cdns_phy, num_lanes,
1597 					      POWERSTATE_A2);
1598 	if (ret)
1599 		return ret;
1600 
1601 	ret = cdns_torrent_dp_set_power_state(cdns_phy, num_lanes,
1602 					      POWERSTATE_A0);
1603 
1604 	return ret;
1605 }
1606 
1607 static int cdns_torrent_phy_on(struct phy *phy)
1608 {
1609 	struct cdns_torrent_inst *inst = phy_get_drvdata(phy);
1610 	struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
1611 	u32 read_val;
1612 	int ret;
1613 
1614 	if (cdns_phy->nsubnodes == 1) {
1615 		/* Take the PHY lane group out of reset */
1616 		reset_control_deassert(inst->lnk_rst);
1617 
1618 		/* Take the PHY out of reset */
1619 		ret = reset_control_deassert(cdns_phy->phy_rst);
1620 		if (ret)
1621 			return ret;
1622 	}
1623 
1624 	/*
1625 	 * Wait for cmn_ready assertion
1626 	 * PHY_PMA_CMN_CTRL1[0] == 1
1627 	 */
1628 	ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_1,
1629 					     read_val, read_val, 1000,
1630 					     PLL_LOCK_TIMEOUT);
1631 	if (ret) {
1632 		dev_err(cdns_phy->dev, "Timeout waiting for CMN ready\n");
1633 		return ret;
1634 	}
1635 
1636 	mdelay(10);
1637 
1638 	return 0;
1639 }
1640 
1641 static int cdns_torrent_phy_off(struct phy *phy)
1642 {
1643 	struct cdns_torrent_inst *inst = phy_get_drvdata(phy);
1644 	struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
1645 	int ret;
1646 
1647 	if (cdns_phy->nsubnodes != 1)
1648 		return 0;
1649 
1650 	ret = reset_control_assert(cdns_phy->phy_rst);
1651 	if (ret)
1652 		return ret;
1653 
1654 	return reset_control_assert(inst->lnk_rst);
1655 }
1656 
1657 static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base,
1658 				       u32 block_offset,
1659 				       u8 reg_offset_shift,
1660 				       const struct regmap_config *config)
1661 {
1662 	struct cdns_regmap_cdb_context *ctx;
1663 
1664 	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
1665 	if (!ctx)
1666 		return ERR_PTR(-ENOMEM);
1667 
1668 	ctx->dev = dev;
1669 	ctx->base = base + block_offset;
1670 	ctx->reg_offset_shift = reg_offset_shift;
1671 
1672 	return devm_regmap_init(dev, NULL, ctx, config);
1673 }
1674 
1675 static int cdns_torrent_dp_regfield_init(struct cdns_torrent_phy *cdns_phy)
1676 {
1677 	struct device *dev = cdns_phy->dev;
1678 	struct regmap_field *field;
1679 	struct regmap *regmap;
1680 
1681 	regmap = cdns_phy->regmap_dptx_phy_reg;
1682 	field = devm_regmap_field_alloc(dev, regmap, phy_reset_ctrl);
1683 	if (IS_ERR(field)) {
1684 		dev_err(dev, "PHY_RESET reg field init failed\n");
1685 		return PTR_ERR(field);
1686 	}
1687 	cdns_phy->phy_reset_ctrl = field;
1688 
1689 	return 0;
1690 }
1691 
1692 static int cdns_torrent_regfield_init(struct cdns_torrent_phy *cdns_phy)
1693 {
1694 	struct device *dev = cdns_phy->dev;
1695 	struct regmap_field *field;
1696 	struct regmap *regmap;
1697 
1698 	regmap = cdns_phy->regmap_phy_pcs_common_cdb;
1699 	field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg);
1700 	if (IS_ERR(field)) {
1701 		dev_err(dev, "PHY_PLL_CFG reg field init failed\n");
1702 		return PTR_ERR(field);
1703 	}
1704 	cdns_phy->phy_pll_cfg = field;
1705 
1706 	regmap = cdns_phy->regmap_phy_pma_common_cdb;
1707 	field = devm_regmap_field_alloc(dev, regmap, phy_pma_cmn_ctrl_1);
1708 	if (IS_ERR(field)) {
1709 		dev_err(dev, "PHY_PMA_CMN_CTRL1 reg field init failed\n");
1710 		return PTR_ERR(field);
1711 	}
1712 	cdns_phy->phy_pma_cmn_ctrl_1 = field;
1713 
1714 	regmap = cdns_phy->regmap_phy_pma_common_cdb;
1715 	field = devm_regmap_field_alloc(dev, regmap, phy_pma_cmn_ctrl_2);
1716 	if (IS_ERR(field)) {
1717 		dev_err(dev, "PHY_PMA_CMN_CTRL2 reg field init failed\n");
1718 		return PTR_ERR(field);
1719 	}
1720 	cdns_phy->phy_pma_cmn_ctrl_2 = field;
1721 
1722 	regmap = cdns_phy->regmap_phy_pma_common_cdb;
1723 	field = devm_regmap_field_alloc(dev, regmap, phy_pma_pll_raw_ctrl);
1724 	if (IS_ERR(field)) {
1725 		dev_err(dev, "PHY_PMA_PLL_RAW_CTRL reg field init failed\n");
1726 		return PTR_ERR(field);
1727 	}
1728 	cdns_phy->phy_pma_pll_raw_ctrl = field;
1729 
1730 	return 0;
1731 }
1732 
1733 static int cdns_torrent_dp_regmap_init(struct cdns_torrent_phy *cdns_phy)
1734 {
1735 	void __iomem *base = cdns_phy->base;
1736 	struct device *dev = cdns_phy->dev;
1737 	struct regmap *regmap;
1738 	u8 reg_offset_shift;
1739 	u32 block_offset;
1740 
1741 	reg_offset_shift = cdns_phy->init_data->reg_offset_shift;
1742 
1743 	block_offset = TORRENT_DPTX_PHY_OFFSET;
1744 	regmap = cdns_regmap_init(dev, base, block_offset,
1745 				  reg_offset_shift,
1746 				  &cdns_torrent_dptx_phy_config);
1747 	if (IS_ERR(regmap)) {
1748 		dev_err(dev, "Failed to init DPTX PHY regmap\n");
1749 		return PTR_ERR(regmap);
1750 	}
1751 	cdns_phy->regmap_dptx_phy_reg = regmap;
1752 
1753 	return 0;
1754 }
1755 
1756 static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy)
1757 {
1758 	void __iomem *sd_base = cdns_phy->sd_base;
1759 	u8 block_offset_shift, reg_offset_shift;
1760 	struct device *dev = cdns_phy->dev;
1761 	struct regmap *regmap;
1762 	u32 block_offset;
1763 	int i;
1764 
1765 	block_offset_shift = cdns_phy->init_data->block_offset_shift;
1766 	reg_offset_shift = cdns_phy->init_data->reg_offset_shift;
1767 
1768 	for (i = 0; i < MAX_NUM_LANES; i++) {
1769 		block_offset = TORRENT_TX_LANE_CDB_OFFSET(i, block_offset_shift,
1770 							  reg_offset_shift);
1771 		regmap = cdns_regmap_init(dev, sd_base, block_offset,
1772 					  reg_offset_shift,
1773 					  &cdns_torrent_tx_lane_cdb_config[i]);
1774 		if (IS_ERR(regmap)) {
1775 			dev_err(dev, "Failed to init tx lane CDB regmap\n");
1776 			return PTR_ERR(regmap);
1777 		}
1778 		cdns_phy->regmap_tx_lane_cdb[i] = regmap;
1779 
1780 		block_offset = TORRENT_RX_LANE_CDB_OFFSET(i, block_offset_shift,
1781 							  reg_offset_shift);
1782 		regmap = cdns_regmap_init(dev, sd_base, block_offset,
1783 					  reg_offset_shift,
1784 					  &cdns_torrent_rx_lane_cdb_config[i]);
1785 		if (IS_ERR(regmap)) {
1786 			dev_err(dev, "Failed to init rx lane CDB regmap\n");
1787 			return PTR_ERR(regmap);
1788 		}
1789 		cdns_phy->regmap_rx_lane_cdb[i] = regmap;
1790 	}
1791 
1792 	block_offset = TORRENT_COMMON_CDB_OFFSET;
1793 	regmap = cdns_regmap_init(dev, sd_base, block_offset,
1794 				  reg_offset_shift,
1795 				  &cdns_torrent_common_cdb_config);
1796 	if (IS_ERR(regmap)) {
1797 		dev_err(dev, "Failed to init common CDB regmap\n");
1798 		return PTR_ERR(regmap);
1799 	}
1800 	cdns_phy->regmap_common_cdb = regmap;
1801 
1802 	block_offset = TORRENT_PHY_PCS_COMMON_OFFSET(block_offset_shift);
1803 	regmap = cdns_regmap_init(dev, sd_base, block_offset,
1804 				  reg_offset_shift,
1805 				  &cdns_torrent_phy_pcs_cmn_cdb_config);
1806 	if (IS_ERR(regmap)) {
1807 		dev_err(dev, "Failed to init PHY PCS common CDB regmap\n");
1808 		return PTR_ERR(regmap);
1809 	}
1810 	cdns_phy->regmap_phy_pcs_common_cdb = regmap;
1811 
1812 	block_offset = TORRENT_PHY_PMA_COMMON_OFFSET(block_offset_shift);
1813 	regmap = cdns_regmap_init(dev, sd_base, block_offset,
1814 				  reg_offset_shift,
1815 				  &cdns_torrent_phy_pma_cmn_cdb_config);
1816 	if (IS_ERR(regmap)) {
1817 		dev_err(dev, "Failed to init PHY PMA common CDB regmap\n");
1818 		return PTR_ERR(regmap);
1819 	}
1820 	cdns_phy->regmap_phy_pma_common_cdb = regmap;
1821 
1822 	return 0;
1823 }
1824 
1825 static int cdns_torrent_phy_init(struct phy *phy)
1826 {
1827 	struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
1828 	const struct cdns_torrent_data *init_data = cdns_phy->init_data;
1829 	struct cdns_torrent_vals *cmn_vals, *tx_ln_vals, *rx_ln_vals;
1830 	struct cdns_torrent_vals *link_cmn_vals, *xcvr_diag_vals;
1831 	struct cdns_torrent_inst *inst = phy_get_drvdata(phy);
1832 	enum cdns_torrent_phy_type phy_type = inst->phy_type;
1833 	enum cdns_torrent_ssc_mode ssc = inst->ssc_mode;
1834 	struct cdns_torrent_vals *pcs_cmn_vals;
1835 	struct cdns_reg_pairs *reg_pairs;
1836 	struct regmap *regmap;
1837 	u32 num_regs;
1838 	int i, j;
1839 
1840 	if (cdns_phy->nsubnodes > 1)
1841 		return 0;
1842 
1843 	if (phy_type == TYPE_DP)
1844 		return cdns_torrent_dp_init(phy);
1845 
1846 	/**
1847 	 * Spread spectrum generation is not required or supported
1848 	 * for SGMII/QSGMII
1849 	 */
1850 	if (phy_type == TYPE_SGMII || phy_type == TYPE_QSGMII)
1851 		ssc = NO_SSC;
1852 
1853 	/* PHY configuration specific registers for single link */
1854 	link_cmn_vals = init_data->link_cmn_vals[phy_type][TYPE_NONE][ssc];
1855 	if (link_cmn_vals) {
1856 		reg_pairs = link_cmn_vals->reg_pairs;
1857 		num_regs = link_cmn_vals->num_regs;
1858 		regmap = cdns_phy->regmap_common_cdb;
1859 
1860 		/**
1861 		 * First array value in link_cmn_vals must be of
1862 		 * PHY_PLL_CFG register
1863 		 */
1864 		regmap_field_write(cdns_phy->phy_pll_cfg, reg_pairs[0].val);
1865 
1866 		for (i = 1; i < num_regs; i++)
1867 			regmap_write(regmap, reg_pairs[i].off,
1868 				     reg_pairs[i].val);
1869 	}
1870 
1871 	xcvr_diag_vals = init_data->xcvr_diag_vals[phy_type][TYPE_NONE][ssc];
1872 	if (xcvr_diag_vals) {
1873 		reg_pairs = xcvr_diag_vals->reg_pairs;
1874 		num_regs = xcvr_diag_vals->num_regs;
1875 		for (i = 0; i < inst->num_lanes; i++) {
1876 			regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane];
1877 			for (j = 0; j < num_regs; j++)
1878 				regmap_write(regmap, reg_pairs[j].off,
1879 					     reg_pairs[j].val);
1880 		}
1881 	}
1882 
1883 	/* PHY PCS common registers configurations */
1884 	pcs_cmn_vals = init_data->pcs_cmn_vals[phy_type][TYPE_NONE][ssc];
1885 	if (pcs_cmn_vals) {
1886 		reg_pairs = pcs_cmn_vals->reg_pairs;
1887 		num_regs = pcs_cmn_vals->num_regs;
1888 		regmap = cdns_phy->regmap_phy_pcs_common_cdb;
1889 		for (i = 0; i < num_regs; i++)
1890 			regmap_write(regmap, reg_pairs[i].off,
1891 				     reg_pairs[i].val);
1892 	}
1893 
1894 	/* PMA common registers configurations */
1895 	cmn_vals = init_data->cmn_vals[phy_type][TYPE_NONE][ssc];
1896 	if (cmn_vals) {
1897 		reg_pairs = cmn_vals->reg_pairs;
1898 		num_regs = cmn_vals->num_regs;
1899 		regmap = cdns_phy->regmap_common_cdb;
1900 		for (i = 0; i < num_regs; i++)
1901 			regmap_write(regmap, reg_pairs[i].off,
1902 				     reg_pairs[i].val);
1903 	}
1904 
1905 	/* PMA TX lane registers configurations */
1906 	tx_ln_vals = init_data->tx_ln_vals[phy_type][TYPE_NONE][ssc];
1907 	if (tx_ln_vals) {
1908 		reg_pairs = tx_ln_vals->reg_pairs;
1909 		num_regs = tx_ln_vals->num_regs;
1910 		for (i = 0; i < inst->num_lanes; i++) {
1911 			regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane];
1912 			for (j = 0; j < num_regs; j++)
1913 				regmap_write(regmap, reg_pairs[j].off,
1914 					     reg_pairs[j].val);
1915 		}
1916 	}
1917 
1918 	/* PMA RX lane registers configurations */
1919 	rx_ln_vals = init_data->rx_ln_vals[phy_type][TYPE_NONE][ssc];
1920 	if (rx_ln_vals) {
1921 		reg_pairs = rx_ln_vals->reg_pairs;
1922 		num_regs = rx_ln_vals->num_regs;
1923 		for (i = 0; i < inst->num_lanes; i++) {
1924 			regmap = cdns_phy->regmap_rx_lane_cdb[i + inst->mlane];
1925 			for (j = 0; j < num_regs; j++)
1926 				regmap_write(regmap, reg_pairs[j].off,
1927 					     reg_pairs[j].val);
1928 		}
1929 	}
1930 
1931 	return 0;
1932 }
1933 
1934 static
1935 int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
1936 {
1937 	const struct cdns_torrent_data *init_data = cdns_phy->init_data;
1938 	struct cdns_torrent_vals *cmn_vals, *tx_ln_vals, *rx_ln_vals;
1939 	struct cdns_torrent_vals *link_cmn_vals, *xcvr_diag_vals;
1940 	enum cdns_torrent_phy_type phy_t1, phy_t2, tmp_phy_type;
1941 	struct cdns_torrent_vals *pcs_cmn_vals;
1942 	int i, j, node, mlane, num_lanes, ret;
1943 	struct cdns_reg_pairs *reg_pairs;
1944 	enum cdns_torrent_ssc_mode ssc;
1945 	struct regmap *regmap;
1946 	u32 num_regs;
1947 
1948 	/* Maximum 2 links (subnodes) are supported */
1949 	if (cdns_phy->nsubnodes != 2)
1950 		return -EINVAL;
1951 
1952 	phy_t1 = cdns_phy->phys[0].phy_type;
1953 	phy_t2 = cdns_phy->phys[1].phy_type;
1954 
1955 	/**
1956 	 * First configure the PHY for first link with phy_t1. Get the array
1957 	 * values as [phy_t1][phy_t2][ssc].
1958 	 */
1959 	for (node = 0; node < cdns_phy->nsubnodes; node++) {
1960 		if (node == 1) {
1961 			/**
1962 			 * If first link with phy_t1 is configured, then
1963 			 * configure the PHY for second link with phy_t2.
1964 			 * Get the array values as [phy_t2][phy_t1][ssc].
1965 			 */
1966 			tmp_phy_type = phy_t1;
1967 			phy_t1 = phy_t2;
1968 			phy_t2 = tmp_phy_type;
1969 		}
1970 
1971 		mlane = cdns_phy->phys[node].mlane;
1972 		ssc = cdns_phy->phys[node].ssc_mode;
1973 		num_lanes = cdns_phy->phys[node].num_lanes;
1974 
1975 		/**
1976 		 * PHY configuration specific registers:
1977 		 * link_cmn_vals depend on combination of PHY types being
1978 		 * configured and are common for both PHY types, so array
1979 		 * values should be same for [phy_t1][phy_t2][ssc] and
1980 		 * [phy_t2][phy_t1][ssc].
1981 		 * xcvr_diag_vals also depend on combination of PHY types
1982 		 * being configured, but these can be different for particular
1983 		 * PHY type and are per lane.
1984 		 */
1985 		link_cmn_vals = init_data->link_cmn_vals[phy_t1][phy_t2][ssc];
1986 		if (link_cmn_vals) {
1987 			reg_pairs = link_cmn_vals->reg_pairs;
1988 			num_regs = link_cmn_vals->num_regs;
1989 			regmap = cdns_phy->regmap_common_cdb;
1990 
1991 			/**
1992 			 * First array value in link_cmn_vals must be of
1993 			 * PHY_PLL_CFG register
1994 			 */
1995 			regmap_field_write(cdns_phy->phy_pll_cfg,
1996 					   reg_pairs[0].val);
1997 
1998 			for (i = 1; i < num_regs; i++)
1999 				regmap_write(regmap, reg_pairs[i].off,
2000 					     reg_pairs[i].val);
2001 		}
2002 
2003 		xcvr_diag_vals = init_data->xcvr_diag_vals[phy_t1][phy_t2][ssc];
2004 		if (xcvr_diag_vals) {
2005 			reg_pairs = xcvr_diag_vals->reg_pairs;
2006 			num_regs = xcvr_diag_vals->num_regs;
2007 			for (i = 0; i < num_lanes; i++) {
2008 				regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane];
2009 				for (j = 0; j < num_regs; j++)
2010 					regmap_write(regmap, reg_pairs[j].off,
2011 						     reg_pairs[j].val);
2012 			}
2013 		}
2014 
2015 		/* PHY PCS common registers configurations */
2016 		pcs_cmn_vals = init_data->pcs_cmn_vals[phy_t1][phy_t2][ssc];
2017 		if (pcs_cmn_vals) {
2018 			reg_pairs = pcs_cmn_vals->reg_pairs;
2019 			num_regs = pcs_cmn_vals->num_regs;
2020 			regmap = cdns_phy->regmap_phy_pcs_common_cdb;
2021 			for (i = 0; i < num_regs; i++)
2022 				regmap_write(regmap, reg_pairs[i].off,
2023 					     reg_pairs[i].val);
2024 		}
2025 
2026 		/* PMA common registers configurations */
2027 		cmn_vals = init_data->cmn_vals[phy_t1][phy_t2][ssc];
2028 		if (cmn_vals) {
2029 			reg_pairs = cmn_vals->reg_pairs;
2030 			num_regs = cmn_vals->num_regs;
2031 			regmap = cdns_phy->regmap_common_cdb;
2032 			for (i = 0; i < num_regs; i++)
2033 				regmap_write(regmap, reg_pairs[i].off,
2034 					     reg_pairs[i].val);
2035 		}
2036 
2037 		/* PMA TX lane registers configurations */
2038 		tx_ln_vals = init_data->tx_ln_vals[phy_t1][phy_t2][ssc];
2039 		if (tx_ln_vals) {
2040 			reg_pairs = tx_ln_vals->reg_pairs;
2041 			num_regs = tx_ln_vals->num_regs;
2042 			for (i = 0; i < num_lanes; i++) {
2043 				regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane];
2044 				for (j = 0; j < num_regs; j++)
2045 					regmap_write(regmap, reg_pairs[j].off,
2046 						     reg_pairs[j].val);
2047 			}
2048 		}
2049 
2050 		/* PMA RX lane registers configurations */
2051 		rx_ln_vals = init_data->rx_ln_vals[phy_t1][phy_t2][ssc];
2052 		if (rx_ln_vals) {
2053 			reg_pairs = rx_ln_vals->reg_pairs;
2054 			num_regs = rx_ln_vals->num_regs;
2055 			for (i = 0; i < num_lanes; i++) {
2056 				regmap = cdns_phy->regmap_rx_lane_cdb[i + mlane];
2057 				for (j = 0; j < num_regs; j++)
2058 					regmap_write(regmap, reg_pairs[j].off,
2059 						     reg_pairs[j].val);
2060 			}
2061 		}
2062 
2063 		reset_control_deassert(cdns_phy->phys[node].lnk_rst);
2064 	}
2065 
2066 	/* Take the PHY out of reset */
2067 	ret = reset_control_deassert(cdns_phy->phy_rst);
2068 	if (ret)
2069 		return ret;
2070 
2071 	return 0;
2072 }
2073 
2074 static int cdns_torrent_phy_probe(struct platform_device *pdev)
2075 {
2076 	struct cdns_torrent_phy *cdns_phy;
2077 	struct device *dev = &pdev->dev;
2078 	struct phy_provider *phy_provider;
2079 	const struct cdns_torrent_data *data;
2080 	struct device_node *child;
2081 	int ret, subnodes, node = 0, i;
2082 	u32 total_num_lanes = 0;
2083 	u8 init_dp_regmap = 0;
2084 	u32 phy_type;
2085 
2086 	/* Get init data for this PHY */
2087 	data = of_device_get_match_data(dev);
2088 	if (!data)
2089 		return -EINVAL;
2090 
2091 	cdns_phy = devm_kzalloc(dev, sizeof(*cdns_phy), GFP_KERNEL);
2092 	if (!cdns_phy)
2093 		return -ENOMEM;
2094 
2095 	dev_set_drvdata(dev, cdns_phy);
2096 	cdns_phy->dev = dev;
2097 	cdns_phy->init_data = data;
2098 
2099 	cdns_phy->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0);
2100 	if (IS_ERR(cdns_phy->phy_rst)) {
2101 		dev_err(dev, "%s: failed to get reset\n",
2102 			dev->of_node->full_name);
2103 		return PTR_ERR(cdns_phy->phy_rst);
2104 	}
2105 
2106 	cdns_phy->apb_rst = devm_reset_control_get_optional(dev, "torrent_apb");
2107 	if (IS_ERR(cdns_phy->apb_rst)) {
2108 		dev_err(dev, "%s: failed to get apb reset\n",
2109 			dev->of_node->full_name);
2110 		return PTR_ERR(cdns_phy->apb_rst);
2111 	}
2112 
2113 	cdns_phy->clk = devm_clk_get(dev, "refclk");
2114 	if (IS_ERR(cdns_phy->clk)) {
2115 		dev_err(dev, "phy ref clock not found\n");
2116 		return PTR_ERR(cdns_phy->clk);
2117 	}
2118 
2119 	cdns_phy->sd_base = devm_platform_ioremap_resource(pdev, 0);
2120 	if (IS_ERR(cdns_phy->sd_base))
2121 		return PTR_ERR(cdns_phy->sd_base);
2122 
2123 	subnodes = of_get_available_child_count(dev->of_node);
2124 	if (subnodes == 0) {
2125 		dev_err(dev, "No available link subnodes found\n");
2126 		return -EINVAL;
2127 	}
2128 
2129 	ret = cdns_torrent_regmap_init(cdns_phy);
2130 	if (ret)
2131 		return ret;
2132 
2133 	ret = cdns_torrent_regfield_init(cdns_phy);
2134 	if (ret)
2135 		return ret;
2136 
2137 	ret = clk_prepare_enable(cdns_phy->clk);
2138 	if (ret) {
2139 		dev_err(cdns_phy->dev, "Failed to prepare ref clock\n");
2140 		return ret;
2141 	}
2142 
2143 	cdns_phy->ref_clk_rate = clk_get_rate(cdns_phy->clk);
2144 	if (!(cdns_phy->ref_clk_rate)) {
2145 		dev_err(cdns_phy->dev, "Failed to get ref clock rate\n");
2146 		clk_disable_unprepare(cdns_phy->clk);
2147 		return -EINVAL;
2148 	}
2149 
2150 	/* Enable APB */
2151 	reset_control_deassert(cdns_phy->apb_rst);
2152 
2153 	for_each_available_child_of_node(dev->of_node, child) {
2154 		struct phy *gphy;
2155 
2156 		/* PHY subnode name must be 'phy'. */
2157 		if (!(of_node_name_eq(child, "phy")))
2158 			continue;
2159 
2160 		cdns_phy->phys[node].lnk_rst =
2161 				of_reset_control_array_get_exclusive(child);
2162 		if (IS_ERR(cdns_phy->phys[node].lnk_rst)) {
2163 			dev_err(dev, "%s: failed to get reset\n",
2164 				child->full_name);
2165 			ret = PTR_ERR(cdns_phy->phys[node].lnk_rst);
2166 			goto put_lnk_rst;
2167 		}
2168 
2169 		if (of_property_read_u32(child, "reg",
2170 					 &cdns_phy->phys[node].mlane)) {
2171 			dev_err(dev, "%s: No \"reg\"-property.\n",
2172 				child->full_name);
2173 			ret = -EINVAL;
2174 			goto put_child;
2175 		}
2176 
2177 		if (of_property_read_u32(child, "cdns,phy-type", &phy_type)) {
2178 			dev_err(dev, "%s: No \"cdns,phy-type\"-property.\n",
2179 				child->full_name);
2180 			ret = -EINVAL;
2181 			goto put_child;
2182 		}
2183 
2184 		switch (phy_type) {
2185 		case PHY_TYPE_PCIE:
2186 			cdns_phy->phys[node].phy_type = TYPE_PCIE;
2187 			break;
2188 		case PHY_TYPE_DP:
2189 			cdns_phy->phys[node].phy_type = TYPE_DP;
2190 			break;
2191 		case PHY_TYPE_SGMII:
2192 			cdns_phy->phys[node].phy_type = TYPE_SGMII;
2193 			break;
2194 		case PHY_TYPE_QSGMII:
2195 			cdns_phy->phys[node].phy_type = TYPE_QSGMII;
2196 			break;
2197 		case PHY_TYPE_USB3:
2198 			cdns_phy->phys[node].phy_type = TYPE_USB;
2199 			break;
2200 		default:
2201 			dev_err(dev, "Unsupported protocol\n");
2202 			ret = -EINVAL;
2203 			goto put_child;
2204 		}
2205 
2206 		if (of_property_read_u32(child, "cdns,num-lanes",
2207 					 &cdns_phy->phys[node].num_lanes)) {
2208 			dev_err(dev, "%s: No \"cdns,num-lanes\"-property.\n",
2209 				child->full_name);
2210 			ret = -EINVAL;
2211 			goto put_child;
2212 		}
2213 
2214 		total_num_lanes += cdns_phy->phys[node].num_lanes;
2215 
2216 		/* Get SSC mode */
2217 		cdns_phy->phys[node].ssc_mode = NO_SSC;
2218 		of_property_read_u32(child, "cdns,ssc-mode",
2219 				     &cdns_phy->phys[node].ssc_mode);
2220 
2221 		gphy = devm_phy_create(dev, child, &cdns_torrent_phy_ops);
2222 		if (IS_ERR(gphy)) {
2223 			ret = PTR_ERR(gphy);
2224 			goto put_child;
2225 		}
2226 
2227 		if (cdns_phy->phys[node].phy_type == TYPE_DP) {
2228 			switch (cdns_phy->phys[node].num_lanes) {
2229 			case 1:
2230 			case 2:
2231 			case 4:
2232 			/* valid number of lanes */
2233 				break;
2234 			default:
2235 				dev_err(dev, "unsupported number of lanes: %d\n",
2236 					cdns_phy->phys[node].num_lanes);
2237 				ret = -EINVAL;
2238 				goto put_child;
2239 			}
2240 
2241 			cdns_phy->max_bit_rate = DEFAULT_MAX_BIT_RATE;
2242 			of_property_read_u32(child, "cdns,max-bit-rate",
2243 					     &cdns_phy->max_bit_rate);
2244 
2245 			switch (cdns_phy->max_bit_rate) {
2246 			case 1620:
2247 			case 2160:
2248 			case 2430:
2249 			case 2700:
2250 			case 3240:
2251 			case 4320:
2252 			case 5400:
2253 			case 8100:
2254 			/* valid bit rate */
2255 				break;
2256 			default:
2257 				dev_err(dev, "unsupported max bit rate: %dMbps\n",
2258 					cdns_phy->max_bit_rate);
2259 				ret = -EINVAL;
2260 				goto put_child;
2261 			}
2262 
2263 			/* DPTX registers */
2264 			cdns_phy->base = devm_platform_ioremap_resource(pdev, 1);
2265 			if (IS_ERR(cdns_phy->base)) {
2266 				ret = PTR_ERR(cdns_phy->base);
2267 				goto put_child;
2268 			}
2269 
2270 			if (!init_dp_regmap) {
2271 				ret = cdns_torrent_dp_regmap_init(cdns_phy);
2272 				if (ret)
2273 					goto put_child;
2274 
2275 				ret = cdns_torrent_dp_regfield_init(cdns_phy);
2276 				if (ret)
2277 					goto put_child;
2278 
2279 				init_dp_regmap++;
2280 			}
2281 
2282 			dev_info(dev, "%d lanes, max bit rate %d.%03d Gbps\n",
2283 				 cdns_phy->phys[node].num_lanes,
2284 				 cdns_phy->max_bit_rate / 1000,
2285 				 cdns_phy->max_bit_rate % 1000);
2286 
2287 			gphy->attrs.bus_width = cdns_phy->phys[node].num_lanes;
2288 			gphy->attrs.max_link_rate = cdns_phy->max_bit_rate;
2289 			gphy->attrs.mode = PHY_MODE_DP;
2290 		}
2291 
2292 		cdns_phy->phys[node].phy = gphy;
2293 		phy_set_drvdata(gphy, &cdns_phy->phys[node]);
2294 
2295 		node++;
2296 	}
2297 	cdns_phy->nsubnodes = node;
2298 
2299 	if (total_num_lanes > MAX_NUM_LANES) {
2300 		dev_err(dev, "Invalid lane configuration\n");
2301 		ret = -EINVAL;
2302 		goto put_lnk_rst;
2303 	}
2304 
2305 	if (cdns_phy->nsubnodes > 1) {
2306 		ret = cdns_torrent_phy_configure_multilink(cdns_phy);
2307 		if (ret)
2308 			goto put_lnk_rst;
2309 	}
2310 
2311 	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
2312 	if (IS_ERR(phy_provider)) {
2313 		ret = PTR_ERR(phy_provider);
2314 		goto put_lnk_rst;
2315 	}
2316 
2317 	return 0;
2318 
2319 put_child:
2320 	node++;
2321 put_lnk_rst:
2322 	for (i = 0; i < node; i++)
2323 		reset_control_put(cdns_phy->phys[i].lnk_rst);
2324 	of_node_put(child);
2325 	reset_control_assert(cdns_phy->apb_rst);
2326 	clk_disable_unprepare(cdns_phy->clk);
2327 	return ret;
2328 }
2329 
2330 static int cdns_torrent_phy_remove(struct platform_device *pdev)
2331 {
2332 	struct cdns_torrent_phy *cdns_phy = platform_get_drvdata(pdev);
2333 	int i;
2334 
2335 	reset_control_assert(cdns_phy->phy_rst);
2336 	reset_control_assert(cdns_phy->apb_rst);
2337 	for (i = 0; i < cdns_phy->nsubnodes; i++) {
2338 		reset_control_assert(cdns_phy->phys[i].lnk_rst);
2339 		reset_control_put(cdns_phy->phys[i].lnk_rst);
2340 	}
2341 
2342 	clk_disable_unprepare(cdns_phy->clk);
2343 
2344 	return 0;
2345 }
2346 
2347 /* USB and SGMII/QSGMII link configuration */
2348 static struct cdns_reg_pairs usb_sgmii_link_cmn_regs[] = {
2349 	{0x0002, PHY_PLL_CFG},
2350 	{0x8600, CMN_PDIAG_PLL0_CLK_SEL_M0},
2351 	{0x0601, CMN_PDIAG_PLL1_CLK_SEL_M0}
2352 };
2353 
2354 static struct cdns_reg_pairs usb_sgmii_xcvr_diag_ln_regs[] = {
2355 	{0x0000, XCVR_DIAG_HSCLK_SEL},
2356 	{0x0001, XCVR_DIAG_HSCLK_DIV},
2357 	{0x0041, XCVR_DIAG_PLLDRC_CTRL}
2358 };
2359 
2360 static struct cdns_reg_pairs sgmii_usb_xcvr_diag_ln_regs[] = {
2361 	{0x0011, XCVR_DIAG_HSCLK_SEL},
2362 	{0x0003, XCVR_DIAG_HSCLK_DIV},
2363 	{0x009B, XCVR_DIAG_PLLDRC_CTRL}
2364 };
2365 
2366 static struct cdns_torrent_vals usb_sgmii_link_cmn_vals = {
2367 	.reg_pairs = usb_sgmii_link_cmn_regs,
2368 	.num_regs = ARRAY_SIZE(usb_sgmii_link_cmn_regs),
2369 };
2370 
2371 static struct cdns_torrent_vals usb_sgmii_xcvr_diag_ln_vals = {
2372 	.reg_pairs = usb_sgmii_xcvr_diag_ln_regs,
2373 	.num_regs = ARRAY_SIZE(usb_sgmii_xcvr_diag_ln_regs),
2374 };
2375 
2376 static struct cdns_torrent_vals sgmii_usb_xcvr_diag_ln_vals = {
2377 	.reg_pairs = sgmii_usb_xcvr_diag_ln_regs,
2378 	.num_regs = ARRAY_SIZE(sgmii_usb_xcvr_diag_ln_regs),
2379 };
2380 
2381 /* PCIe and USB Unique SSC link configuration */
2382 static struct cdns_reg_pairs pcie_usb_link_cmn_regs[] = {
2383 	{0x0003, PHY_PLL_CFG},
2384 	{0x0601, CMN_PDIAG_PLL0_CLK_SEL_M0},
2385 	{0x0400, CMN_PDIAG_PLL0_CLK_SEL_M1},
2386 	{0x8600, CMN_PDIAG_PLL1_CLK_SEL_M0}
2387 };
2388 
2389 static struct cdns_reg_pairs pcie_usb_xcvr_diag_ln_regs[] = {
2390 	{0x0000, XCVR_DIAG_HSCLK_SEL},
2391 	{0x0001, XCVR_DIAG_HSCLK_DIV},
2392 	{0x0012, XCVR_DIAG_PLLDRC_CTRL}
2393 };
2394 
2395 static struct cdns_reg_pairs usb_pcie_xcvr_diag_ln_regs[] = {
2396 	{0x0011, XCVR_DIAG_HSCLK_SEL},
2397 	{0x0001, XCVR_DIAG_HSCLK_DIV},
2398 	{0x00C9, XCVR_DIAG_PLLDRC_CTRL}
2399 };
2400 
2401 static struct cdns_torrent_vals pcie_usb_link_cmn_vals = {
2402 	.reg_pairs = pcie_usb_link_cmn_regs,
2403 	.num_regs = ARRAY_SIZE(pcie_usb_link_cmn_regs),
2404 };
2405 
2406 static struct cdns_torrent_vals pcie_usb_xcvr_diag_ln_vals = {
2407 	.reg_pairs = pcie_usb_xcvr_diag_ln_regs,
2408 	.num_regs = ARRAY_SIZE(pcie_usb_xcvr_diag_ln_regs),
2409 };
2410 
2411 static struct cdns_torrent_vals usb_pcie_xcvr_diag_ln_vals = {
2412 	.reg_pairs = usb_pcie_xcvr_diag_ln_regs,
2413 	.num_regs = ARRAY_SIZE(usb_pcie_xcvr_diag_ln_regs),
2414 };
2415 
2416 /* USB 100 MHz Ref clk, internal SSC */
2417 static struct cdns_reg_pairs usb_100_int_ssc_cmn_regs[] = {
2418 	{0x0004, CMN_PLL0_DSM_DIAG_M0},
2419 	{0x0004, CMN_PLL0_DSM_DIAG_M1},
2420 	{0x0004, CMN_PLL1_DSM_DIAG_M0},
2421 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M0},
2422 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M1},
2423 	{0x0509, CMN_PDIAG_PLL1_CP_PADJ_M0},
2424 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M0},
2425 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M1},
2426 	{0x0F00, CMN_PDIAG_PLL1_CP_IADJ_M0},
2427 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M0},
2428 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M1},
2429 	{0x0F08, CMN_PDIAG_PLL1_FILT_PADJ_M0},
2430 	{0x0064, CMN_PLL0_INTDIV_M0},
2431 	{0x0050, CMN_PLL0_INTDIV_M1},
2432 	{0x0064, CMN_PLL1_INTDIV_M0},
2433 	{0x0002, CMN_PLL0_FRACDIVH_M0},
2434 	{0x0002, CMN_PLL0_FRACDIVH_M1},
2435 	{0x0002, CMN_PLL1_FRACDIVH_M0},
2436 	{0x0044, CMN_PLL0_HIGH_THR_M0},
2437 	{0x0036, CMN_PLL0_HIGH_THR_M1},
2438 	{0x0044, CMN_PLL1_HIGH_THR_M0},
2439 	{0x0002, CMN_PDIAG_PLL0_CTRL_M0},
2440 	{0x0002, CMN_PDIAG_PLL0_CTRL_M1},
2441 	{0x0002, CMN_PDIAG_PLL1_CTRL_M0},
2442 	{0x0001, CMN_PLL0_SS_CTRL1_M0},
2443 	{0x0001, CMN_PLL0_SS_CTRL1_M1},
2444 	{0x0001, CMN_PLL1_SS_CTRL1_M0},
2445 	{0x011B, CMN_PLL0_SS_CTRL2_M0},
2446 	{0x011B, CMN_PLL0_SS_CTRL2_M1},
2447 	{0x011B, CMN_PLL1_SS_CTRL2_M0},
2448 	{0x006E, CMN_PLL0_SS_CTRL3_M0},
2449 	{0x0058, CMN_PLL0_SS_CTRL3_M1},
2450 	{0x006E, CMN_PLL1_SS_CTRL3_M0},
2451 	{0x000E, CMN_PLL0_SS_CTRL4_M0},
2452 	{0x0012, CMN_PLL0_SS_CTRL4_M1},
2453 	{0x000E, CMN_PLL1_SS_CTRL4_M0},
2454 	{0x0C5E, CMN_PLL0_VCOCAL_REFTIM_START},
2455 	{0x0C5E, CMN_PLL1_VCOCAL_REFTIM_START},
2456 	{0x0C56, CMN_PLL0_VCOCAL_PLLCNT_START},
2457 	{0x0C56, CMN_PLL1_VCOCAL_PLLCNT_START},
2458 	{0x0003, CMN_PLL0_VCOCAL_TCTRL},
2459 	{0x0003, CMN_PLL1_VCOCAL_TCTRL},
2460 	{0x00C7, CMN_PLL0_LOCK_REFCNT_START},
2461 	{0x00C7, CMN_PLL1_LOCK_REFCNT_START},
2462 	{0x00C7, CMN_PLL0_LOCK_PLLCNT_START},
2463 	{0x00C7, CMN_PLL1_LOCK_PLLCNT_START},
2464 	{0x0005, CMN_PLL0_LOCK_PLLCNT_THR},
2465 	{0x0005, CMN_PLL1_LOCK_PLLCNT_THR},
2466 	{0x8200, CMN_CDIAG_CDB_PWRI_OVRD},
2467 	{0x8200, CMN_CDIAG_XCVRC_PWRI_OVRD}
2468 };
2469 
2470 static struct cdns_torrent_vals usb_100_int_ssc_cmn_vals = {
2471 	.reg_pairs = usb_100_int_ssc_cmn_regs,
2472 	.num_regs = ARRAY_SIZE(usb_100_int_ssc_cmn_regs),
2473 };
2474 
2475 /* Single USB link configuration */
2476 static struct cdns_reg_pairs sl_usb_link_cmn_regs[] = {
2477 	{0x0000, PHY_PLL_CFG},
2478 	{0x8600, CMN_PDIAG_PLL0_CLK_SEL_M0}
2479 };
2480 
2481 static struct cdns_reg_pairs sl_usb_xcvr_diag_ln_regs[] = {
2482 	{0x0000, XCVR_DIAG_HSCLK_SEL},
2483 	{0x0001, XCVR_DIAG_HSCLK_DIV},
2484 	{0x0041, XCVR_DIAG_PLLDRC_CTRL}
2485 };
2486 
2487 static struct cdns_torrent_vals sl_usb_link_cmn_vals = {
2488 	.reg_pairs = sl_usb_link_cmn_regs,
2489 	.num_regs = ARRAY_SIZE(sl_usb_link_cmn_regs),
2490 };
2491 
2492 static struct cdns_torrent_vals sl_usb_xcvr_diag_ln_vals = {
2493 	.reg_pairs = sl_usb_xcvr_diag_ln_regs,
2494 	.num_regs = ARRAY_SIZE(sl_usb_xcvr_diag_ln_regs),
2495 };
2496 
2497 /* USB PHY PCS common configuration */
2498 static struct cdns_reg_pairs usb_phy_pcs_cmn_regs[] = {
2499 	{0x0A0A, PHY_PIPE_USB3_GEN2_PRE_CFG0},
2500 	{0x1000, PHY_PIPE_USB3_GEN2_POST_CFG0},
2501 	{0x0010, PHY_PIPE_USB3_GEN2_POST_CFG1}
2502 };
2503 
2504 static struct cdns_torrent_vals usb_phy_pcs_cmn_vals = {
2505 	.reg_pairs = usb_phy_pcs_cmn_regs,
2506 	.num_regs = ARRAY_SIZE(usb_phy_pcs_cmn_regs),
2507 };
2508 
2509 /* USB 100 MHz Ref clk, no SSC */
2510 static struct cdns_reg_pairs usb_100_no_ssc_cmn_regs[] = {
2511 	{0x0003, CMN_PLL0_VCOCAL_TCTRL},
2512 	{0x0003, CMN_PLL1_VCOCAL_TCTRL},
2513 	{0x8200, CMN_CDIAG_CDB_PWRI_OVRD},
2514 	{0x8200, CMN_CDIAG_XCVRC_PWRI_OVRD}
2515 };
2516 
2517 static struct cdns_reg_pairs usb_100_no_ssc_tx_ln_regs[] = {
2518 	{0x02FF, TX_PSC_A0},
2519 	{0x06AF, TX_PSC_A1},
2520 	{0x06AE, TX_PSC_A2},
2521 	{0x06AE, TX_PSC_A3},
2522 	{0x2A82, TX_TXCC_CTRL},
2523 	{0x0014, TX_TXCC_CPOST_MULT_01},
2524 	{0x0003, XCVR_DIAG_PSC_OVRD}
2525 };
2526 
2527 static struct cdns_reg_pairs usb_100_no_ssc_rx_ln_regs[] = {
2528 	{0x0D1D, RX_PSC_A0},
2529 	{0x0D1D, RX_PSC_A1},
2530 	{0x0D00, RX_PSC_A2},
2531 	{0x0500, RX_PSC_A3},
2532 	{0x0013, RX_SIGDET_HL_FILT_TMR},
2533 	{0x0000, RX_REE_GCSM1_CTRL},
2534 	{0x0C02, RX_REE_ATTEN_THR},
2535 	{0x0330, RX_REE_SMGM_CTRL1},
2536 	{0x0300, RX_REE_SMGM_CTRL2},
2537 	{0x0019, RX_REE_TAP1_CLIP},
2538 	{0x0019, RX_REE_TAP2TON_CLIP},
2539 	{0x1004, RX_DIAG_SIGDET_TUNE},
2540 	{0x00F9, RX_DIAG_NQST_CTRL},
2541 	{0x0C01, RX_DIAG_DFE_AMP_TUNE_2},
2542 	{0x0002, RX_DIAG_DFE_AMP_TUNE_3},
2543 	{0x0000, RX_DIAG_PI_CAP},
2544 	{0x0031, RX_DIAG_PI_RATE},
2545 	{0x0001, RX_DIAG_ACYA},
2546 	{0x018C, RX_CDRLF_CNFG},
2547 	{0x0003, RX_CDRLF_CNFG3}
2548 };
2549 
2550 static struct cdns_torrent_vals usb_100_no_ssc_cmn_vals = {
2551 	.reg_pairs = usb_100_no_ssc_cmn_regs,
2552 	.num_regs = ARRAY_SIZE(usb_100_no_ssc_cmn_regs),
2553 };
2554 
2555 static struct cdns_torrent_vals usb_100_no_ssc_tx_ln_vals = {
2556 	.reg_pairs = usb_100_no_ssc_tx_ln_regs,
2557 	.num_regs = ARRAY_SIZE(usb_100_no_ssc_tx_ln_regs),
2558 };
2559 
2560 static struct cdns_torrent_vals usb_100_no_ssc_rx_ln_vals = {
2561 	.reg_pairs = usb_100_no_ssc_rx_ln_regs,
2562 	.num_regs = ARRAY_SIZE(usb_100_no_ssc_rx_ln_regs),
2563 };
2564 
2565 /* Single link USB, 100 MHz Ref clk, internal SSC */
2566 static struct cdns_reg_pairs sl_usb_100_int_ssc_cmn_regs[] = {
2567 	{0x0004, CMN_PLL0_DSM_DIAG_M0},
2568 	{0x0004, CMN_PLL1_DSM_DIAG_M0},
2569 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M0},
2570 	{0x0509, CMN_PDIAG_PLL1_CP_PADJ_M0},
2571 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M0},
2572 	{0x0F00, CMN_PDIAG_PLL1_CP_IADJ_M0},
2573 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M0},
2574 	{0x0F08, CMN_PDIAG_PLL1_FILT_PADJ_M0},
2575 	{0x0064, CMN_PLL0_INTDIV_M0},
2576 	{0x0064, CMN_PLL1_INTDIV_M0},
2577 	{0x0002, CMN_PLL0_FRACDIVH_M0},
2578 	{0x0002, CMN_PLL1_FRACDIVH_M0},
2579 	{0x0044, CMN_PLL0_HIGH_THR_M0},
2580 	{0x0044, CMN_PLL1_HIGH_THR_M0},
2581 	{0x0002, CMN_PDIAG_PLL0_CTRL_M0},
2582 	{0x0002, CMN_PDIAG_PLL1_CTRL_M0},
2583 	{0x0001, CMN_PLL0_SS_CTRL1_M0},
2584 	{0x0001, CMN_PLL1_SS_CTRL1_M0},
2585 	{0x011B, CMN_PLL0_SS_CTRL2_M0},
2586 	{0x011B, CMN_PLL1_SS_CTRL2_M0},
2587 	{0x006E, CMN_PLL0_SS_CTRL3_M0},
2588 	{0x006E, CMN_PLL1_SS_CTRL3_M0},
2589 	{0x000E, CMN_PLL0_SS_CTRL4_M0},
2590 	{0x000E, CMN_PLL1_SS_CTRL4_M0},
2591 	{0x0C5E, CMN_PLL0_VCOCAL_REFTIM_START},
2592 	{0x0C5E, CMN_PLL1_VCOCAL_REFTIM_START},
2593 	{0x0C56, CMN_PLL0_VCOCAL_PLLCNT_START},
2594 	{0x0C56, CMN_PLL1_VCOCAL_PLLCNT_START},
2595 	{0x0003, CMN_PLL0_VCOCAL_TCTRL},
2596 	{0x0003, CMN_PLL1_VCOCAL_TCTRL},
2597 	{0x00C7, CMN_PLL0_LOCK_REFCNT_START},
2598 	{0x00C7, CMN_PLL1_LOCK_REFCNT_START},
2599 	{0x00C7, CMN_PLL0_LOCK_PLLCNT_START},
2600 	{0x00C7, CMN_PLL1_LOCK_PLLCNT_START},
2601 	{0x0005, CMN_PLL0_LOCK_PLLCNT_THR},
2602 	{0x0005, CMN_PLL1_LOCK_PLLCNT_THR},
2603 	{0x8200, CMN_CDIAG_CDB_PWRI_OVRD},
2604 	{0x8200, CMN_CDIAG_XCVRC_PWRI_OVRD}
2605 };
2606 
2607 static struct cdns_torrent_vals sl_usb_100_int_ssc_cmn_vals = {
2608 	.reg_pairs = sl_usb_100_int_ssc_cmn_regs,
2609 	.num_regs = ARRAY_SIZE(sl_usb_100_int_ssc_cmn_regs),
2610 };
2611 
2612 /* PCIe and SGMII/QSGMII Unique SSC link configuration */
2613 static struct cdns_reg_pairs pcie_sgmii_link_cmn_regs[] = {
2614 	{0x0003, PHY_PLL_CFG},
2615 	{0x0601, CMN_PDIAG_PLL0_CLK_SEL_M0},
2616 	{0x0400, CMN_PDIAG_PLL0_CLK_SEL_M1},
2617 	{0x0601, CMN_PDIAG_PLL1_CLK_SEL_M0}
2618 };
2619 
2620 static struct cdns_reg_pairs pcie_sgmii_xcvr_diag_ln_regs[] = {
2621 	{0x0000, XCVR_DIAG_HSCLK_SEL},
2622 	{0x0001, XCVR_DIAG_HSCLK_DIV},
2623 	{0x0012, XCVR_DIAG_PLLDRC_CTRL}
2624 };
2625 
2626 static struct cdns_reg_pairs sgmii_pcie_xcvr_diag_ln_regs[] = {
2627 	{0x0011, XCVR_DIAG_HSCLK_SEL},
2628 	{0x0003, XCVR_DIAG_HSCLK_DIV},
2629 	{0x009B, XCVR_DIAG_PLLDRC_CTRL}
2630 };
2631 
2632 static struct cdns_torrent_vals pcie_sgmii_link_cmn_vals = {
2633 	.reg_pairs = pcie_sgmii_link_cmn_regs,
2634 	.num_regs = ARRAY_SIZE(pcie_sgmii_link_cmn_regs),
2635 };
2636 
2637 static struct cdns_torrent_vals pcie_sgmii_xcvr_diag_ln_vals = {
2638 	.reg_pairs = pcie_sgmii_xcvr_diag_ln_regs,
2639 	.num_regs = ARRAY_SIZE(pcie_sgmii_xcvr_diag_ln_regs),
2640 };
2641 
2642 static struct cdns_torrent_vals sgmii_pcie_xcvr_diag_ln_vals = {
2643 	.reg_pairs = sgmii_pcie_xcvr_diag_ln_regs,
2644 	.num_regs = ARRAY_SIZE(sgmii_pcie_xcvr_diag_ln_regs),
2645 };
2646 
2647 /* SGMII 100 MHz Ref clk, no SSC */
2648 static struct cdns_reg_pairs sgmii_100_no_ssc_cmn_regs[] = {
2649 	{0x0003, CMN_PLL0_VCOCAL_TCTRL},
2650 	{0x0003, CMN_PLL1_VCOCAL_TCTRL},
2651 	{0x3700, CMN_DIAG_BIAS_OVRD1},
2652 	{0x0008, CMN_TXPUCAL_TUNE},
2653 	{0x0008, CMN_TXPDCAL_TUNE}
2654 };
2655 
2656 static struct cdns_reg_pairs sgmii_100_no_ssc_tx_ln_regs[] = {
2657 	{0x00F3, TX_PSC_A0},
2658 	{0x04A2, TX_PSC_A2},
2659 	{0x04A2, TX_PSC_A3},
2660 	{0x0000, TX_TXCC_CPOST_MULT_00},
2661 	{0x00B3, DRV_DIAG_TX_DRV}
2662 };
2663 
2664 static struct cdns_reg_pairs sgmii_100_no_ssc_rx_ln_regs[] = {
2665 	{0x091D, RX_PSC_A0},
2666 	{0x0900, RX_PSC_A2},
2667 	{0x0100, RX_PSC_A3},
2668 	{0x03C7, RX_REE_GCSM1_EQENM_PH1},
2669 	{0x01C7, RX_REE_GCSM1_EQENM_PH2},
2670 	{0x0000, RX_DIAG_DFE_CTRL},
2671 	{0x0019, RX_REE_TAP1_CLIP},
2672 	{0x0019, RX_REE_TAP2TON_CLIP},
2673 	{0x0098, RX_DIAG_NQST_CTRL},
2674 	{0x0C01, RX_DIAG_DFE_AMP_TUNE_2},
2675 	{0x0000, RX_DIAG_DFE_AMP_TUNE_3},
2676 	{0x0000, RX_DIAG_PI_CAP},
2677 	{0x0010, RX_DIAG_PI_RATE},
2678 	{0x0001, RX_DIAG_ACYA},
2679 	{0x018C, RX_CDRLF_CNFG},
2680 };
2681 
2682 static struct cdns_torrent_vals sgmii_100_no_ssc_cmn_vals = {
2683 	.reg_pairs = sgmii_100_no_ssc_cmn_regs,
2684 	.num_regs = ARRAY_SIZE(sgmii_100_no_ssc_cmn_regs),
2685 };
2686 
2687 static struct cdns_torrent_vals sgmii_100_no_ssc_tx_ln_vals = {
2688 	.reg_pairs = sgmii_100_no_ssc_tx_ln_regs,
2689 	.num_regs = ARRAY_SIZE(sgmii_100_no_ssc_tx_ln_regs),
2690 };
2691 
2692 static struct cdns_torrent_vals sgmii_100_no_ssc_rx_ln_vals = {
2693 	.reg_pairs = sgmii_100_no_ssc_rx_ln_regs,
2694 	.num_regs = ARRAY_SIZE(sgmii_100_no_ssc_rx_ln_regs),
2695 };
2696 
2697 /* SGMII 100 MHz Ref clk, internal SSC */
2698 static struct cdns_reg_pairs sgmii_100_int_ssc_cmn_regs[] = {
2699 	{0x0004, CMN_PLL0_DSM_DIAG_M0},
2700 	{0x0004, CMN_PLL0_DSM_DIAG_M1},
2701 	{0x0004, CMN_PLL1_DSM_DIAG_M0},
2702 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M0},
2703 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M1},
2704 	{0x0509, CMN_PDIAG_PLL1_CP_PADJ_M0},
2705 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M0},
2706 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M1},
2707 	{0x0F00, CMN_PDIAG_PLL1_CP_IADJ_M0},
2708 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M0},
2709 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M1},
2710 	{0x0F08, CMN_PDIAG_PLL1_FILT_PADJ_M0},
2711 	{0x0064, CMN_PLL0_INTDIV_M0},
2712 	{0x0050, CMN_PLL0_INTDIV_M1},
2713 	{0x0064, CMN_PLL1_INTDIV_M0},
2714 	{0x0002, CMN_PLL0_FRACDIVH_M0},
2715 	{0x0002, CMN_PLL0_FRACDIVH_M1},
2716 	{0x0002, CMN_PLL1_FRACDIVH_M0},
2717 	{0x0044, CMN_PLL0_HIGH_THR_M0},
2718 	{0x0036, CMN_PLL0_HIGH_THR_M1},
2719 	{0x0044, CMN_PLL1_HIGH_THR_M0},
2720 	{0x0002, CMN_PDIAG_PLL0_CTRL_M0},
2721 	{0x0002, CMN_PDIAG_PLL0_CTRL_M1},
2722 	{0x0002, CMN_PDIAG_PLL1_CTRL_M0},
2723 	{0x0001, CMN_PLL0_SS_CTRL1_M0},
2724 	{0x0001, CMN_PLL0_SS_CTRL1_M1},
2725 	{0x0001, CMN_PLL1_SS_CTRL1_M0},
2726 	{0x011B, CMN_PLL0_SS_CTRL2_M0},
2727 	{0x011B, CMN_PLL0_SS_CTRL2_M1},
2728 	{0x011B, CMN_PLL1_SS_CTRL2_M0},
2729 	{0x006E, CMN_PLL0_SS_CTRL3_M0},
2730 	{0x0058, CMN_PLL0_SS_CTRL3_M1},
2731 	{0x006E, CMN_PLL1_SS_CTRL3_M0},
2732 	{0x000E, CMN_PLL0_SS_CTRL4_M0},
2733 	{0x0012, CMN_PLL0_SS_CTRL4_M1},
2734 	{0x000E, CMN_PLL1_SS_CTRL4_M0},
2735 	{0x0C5E, CMN_PLL0_VCOCAL_REFTIM_START},
2736 	{0x0C5E, CMN_PLL1_VCOCAL_REFTIM_START},
2737 	{0x0C56, CMN_PLL0_VCOCAL_PLLCNT_START},
2738 	{0x0C56, CMN_PLL1_VCOCAL_PLLCNT_START},
2739 	{0x0003, CMN_PLL0_VCOCAL_TCTRL},
2740 	{0x0003, CMN_PLL1_VCOCAL_TCTRL},
2741 	{0x00C7, CMN_PLL0_LOCK_REFCNT_START},
2742 	{0x00C7, CMN_PLL1_LOCK_REFCNT_START},
2743 	{0x00C7, CMN_PLL0_LOCK_PLLCNT_START},
2744 	{0x00C7, CMN_PLL1_LOCK_PLLCNT_START},
2745 	{0x0005, CMN_PLL0_LOCK_PLLCNT_THR},
2746 	{0x0005, CMN_PLL1_LOCK_PLLCNT_THR},
2747 	{0x3700, CMN_DIAG_BIAS_OVRD1},
2748 	{0x0008, CMN_TXPUCAL_TUNE},
2749 	{0x0008, CMN_TXPDCAL_TUNE}
2750 };
2751 
2752 static struct cdns_torrent_vals sgmii_100_int_ssc_cmn_vals = {
2753 	.reg_pairs = sgmii_100_int_ssc_cmn_regs,
2754 	.num_regs = ARRAY_SIZE(sgmii_100_int_ssc_cmn_regs),
2755 };
2756 
2757 /* QSGMII 100 MHz Ref clk, no SSC */
2758 static struct cdns_reg_pairs qsgmii_100_no_ssc_cmn_regs[] = {
2759 	{0x0003, CMN_PLL0_VCOCAL_TCTRL},
2760 	{0x0003, CMN_PLL1_VCOCAL_TCTRL}
2761 };
2762 
2763 static struct cdns_reg_pairs qsgmii_100_no_ssc_tx_ln_regs[] = {
2764 	{0x00F3, TX_PSC_A0},
2765 	{0x04A2, TX_PSC_A2},
2766 	{0x04A2, TX_PSC_A3},
2767 	{0x0000, TX_TXCC_CPOST_MULT_00},
2768 	{0x0003, DRV_DIAG_TX_DRV}
2769 };
2770 
2771 static struct cdns_reg_pairs qsgmii_100_no_ssc_rx_ln_regs[] = {
2772 	{0x091D, RX_PSC_A0},
2773 	{0x0900, RX_PSC_A2},
2774 	{0x0100, RX_PSC_A3},
2775 	{0x03C7, RX_REE_GCSM1_EQENM_PH1},
2776 	{0x01C7, RX_REE_GCSM1_EQENM_PH2},
2777 	{0x0000, RX_DIAG_DFE_CTRL},
2778 	{0x0019, RX_REE_TAP1_CLIP},
2779 	{0x0019, RX_REE_TAP2TON_CLIP},
2780 	{0x0098, RX_DIAG_NQST_CTRL},
2781 	{0x0C01, RX_DIAG_DFE_AMP_TUNE_2},
2782 	{0x0000, RX_DIAG_DFE_AMP_TUNE_3},
2783 	{0x0000, RX_DIAG_PI_CAP},
2784 	{0x0010, RX_DIAG_PI_RATE},
2785 	{0x0001, RX_DIAG_ACYA},
2786 	{0x018C, RX_CDRLF_CNFG},
2787 };
2788 
2789 static struct cdns_torrent_vals qsgmii_100_no_ssc_cmn_vals = {
2790 	.reg_pairs = qsgmii_100_no_ssc_cmn_regs,
2791 	.num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_cmn_regs),
2792 };
2793 
2794 static struct cdns_torrent_vals qsgmii_100_no_ssc_tx_ln_vals = {
2795 	.reg_pairs = qsgmii_100_no_ssc_tx_ln_regs,
2796 	.num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_tx_ln_regs),
2797 };
2798 
2799 static struct cdns_torrent_vals qsgmii_100_no_ssc_rx_ln_vals = {
2800 	.reg_pairs = qsgmii_100_no_ssc_rx_ln_regs,
2801 	.num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_rx_ln_regs),
2802 };
2803 
2804 /* QSGMII 100 MHz Ref clk, internal SSC */
2805 static struct cdns_reg_pairs qsgmii_100_int_ssc_cmn_regs[] = {
2806 	{0x0004, CMN_PLL0_DSM_DIAG_M0},
2807 	{0x0004, CMN_PLL0_DSM_DIAG_M1},
2808 	{0x0004, CMN_PLL1_DSM_DIAG_M0},
2809 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M0},
2810 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M1},
2811 	{0x0509, CMN_PDIAG_PLL1_CP_PADJ_M0},
2812 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M0},
2813 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M1},
2814 	{0x0F00, CMN_PDIAG_PLL1_CP_IADJ_M0},
2815 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M0},
2816 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M1},
2817 	{0x0F08, CMN_PDIAG_PLL1_FILT_PADJ_M0},
2818 	{0x0064, CMN_PLL0_INTDIV_M0},
2819 	{0x0050, CMN_PLL0_INTDIV_M1},
2820 	{0x0064, CMN_PLL1_INTDIV_M0},
2821 	{0x0002, CMN_PLL0_FRACDIVH_M0},
2822 	{0x0002, CMN_PLL0_FRACDIVH_M1},
2823 	{0x0002, CMN_PLL1_FRACDIVH_M0},
2824 	{0x0044, CMN_PLL0_HIGH_THR_M0},
2825 	{0x0036, CMN_PLL0_HIGH_THR_M1},
2826 	{0x0044, CMN_PLL1_HIGH_THR_M0},
2827 	{0x0002, CMN_PDIAG_PLL0_CTRL_M0},
2828 	{0x0002, CMN_PDIAG_PLL0_CTRL_M1},
2829 	{0x0002, CMN_PDIAG_PLL1_CTRL_M0},
2830 	{0x0001, CMN_PLL0_SS_CTRL1_M0},
2831 	{0x0001, CMN_PLL0_SS_CTRL1_M1},
2832 	{0x0001, CMN_PLL1_SS_CTRL1_M0},
2833 	{0x011B, CMN_PLL0_SS_CTRL2_M0},
2834 	{0x011B, CMN_PLL0_SS_CTRL2_M1},
2835 	{0x011B, CMN_PLL1_SS_CTRL2_M0},
2836 	{0x006E, CMN_PLL0_SS_CTRL3_M0},
2837 	{0x0058, CMN_PLL0_SS_CTRL3_M1},
2838 	{0x006E, CMN_PLL1_SS_CTRL3_M0},
2839 	{0x000E, CMN_PLL0_SS_CTRL4_M0},
2840 	{0x0012, CMN_PLL0_SS_CTRL4_M1},
2841 	{0x000E, CMN_PLL1_SS_CTRL4_M0},
2842 	{0x0C5E, CMN_PLL0_VCOCAL_REFTIM_START},
2843 	{0x0C5E, CMN_PLL1_VCOCAL_REFTIM_START},
2844 	{0x0C56, CMN_PLL0_VCOCAL_PLLCNT_START},
2845 	{0x0C56, CMN_PLL1_VCOCAL_PLLCNT_START},
2846 	{0x0003, CMN_PLL0_VCOCAL_TCTRL},
2847 	{0x0003, CMN_PLL1_VCOCAL_TCTRL},
2848 	{0x00C7, CMN_PLL0_LOCK_REFCNT_START},
2849 	{0x00C7, CMN_PLL1_LOCK_REFCNT_START},
2850 	{0x00C7, CMN_PLL0_LOCK_PLLCNT_START},
2851 	{0x00C7, CMN_PLL1_LOCK_PLLCNT_START},
2852 	{0x0005, CMN_PLL0_LOCK_PLLCNT_THR},
2853 	{0x0005, CMN_PLL1_LOCK_PLLCNT_THR}
2854 };
2855 
2856 static struct cdns_torrent_vals qsgmii_100_int_ssc_cmn_vals = {
2857 	.reg_pairs = qsgmii_100_int_ssc_cmn_regs,
2858 	.num_regs = ARRAY_SIZE(qsgmii_100_int_ssc_cmn_regs),
2859 };
2860 
2861 /* Single SGMII/QSGMII link configuration */
2862 static struct cdns_reg_pairs sl_sgmii_link_cmn_regs[] = {
2863 	{0x0000, PHY_PLL_CFG},
2864 	{0x0601, CMN_PDIAG_PLL0_CLK_SEL_M0}
2865 };
2866 
2867 static struct cdns_reg_pairs sl_sgmii_xcvr_diag_ln_regs[] = {
2868 	{0x0000, XCVR_DIAG_HSCLK_SEL},
2869 	{0x0003, XCVR_DIAG_HSCLK_DIV},
2870 	{0x0013, XCVR_DIAG_PLLDRC_CTRL}
2871 };
2872 
2873 static struct cdns_torrent_vals sl_sgmii_link_cmn_vals = {
2874 	.reg_pairs = sl_sgmii_link_cmn_regs,
2875 	.num_regs = ARRAY_SIZE(sl_sgmii_link_cmn_regs),
2876 };
2877 
2878 static struct cdns_torrent_vals sl_sgmii_xcvr_diag_ln_vals = {
2879 	.reg_pairs = sl_sgmii_xcvr_diag_ln_regs,
2880 	.num_regs = ARRAY_SIZE(sl_sgmii_xcvr_diag_ln_regs),
2881 };
2882 
2883 /* Multi link PCIe, 100 MHz Ref clk, internal SSC */
2884 static struct cdns_reg_pairs pcie_100_int_ssc_cmn_regs[] = {
2885 	{0x0004, CMN_PLL0_DSM_DIAG_M0},
2886 	{0x0004, CMN_PLL0_DSM_DIAG_M1},
2887 	{0x0004, CMN_PLL1_DSM_DIAG_M0},
2888 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M0},
2889 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M1},
2890 	{0x0509, CMN_PDIAG_PLL1_CP_PADJ_M0},
2891 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M0},
2892 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M1},
2893 	{0x0F00, CMN_PDIAG_PLL1_CP_IADJ_M0},
2894 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M0},
2895 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M1},
2896 	{0x0F08, CMN_PDIAG_PLL1_FILT_PADJ_M0},
2897 	{0x0064, CMN_PLL0_INTDIV_M0},
2898 	{0x0050, CMN_PLL0_INTDIV_M1},
2899 	{0x0064, CMN_PLL1_INTDIV_M0},
2900 	{0x0002, CMN_PLL0_FRACDIVH_M0},
2901 	{0x0002, CMN_PLL0_FRACDIVH_M1},
2902 	{0x0002, CMN_PLL1_FRACDIVH_M0},
2903 	{0x0044, CMN_PLL0_HIGH_THR_M0},
2904 	{0x0036, CMN_PLL0_HIGH_THR_M1},
2905 	{0x0044, CMN_PLL1_HIGH_THR_M0},
2906 	{0x0002, CMN_PDIAG_PLL0_CTRL_M0},
2907 	{0x0002, CMN_PDIAG_PLL0_CTRL_M1},
2908 	{0x0002, CMN_PDIAG_PLL1_CTRL_M0},
2909 	{0x0001, CMN_PLL0_SS_CTRL1_M0},
2910 	{0x0001, CMN_PLL0_SS_CTRL1_M1},
2911 	{0x0001, CMN_PLL1_SS_CTRL1_M0},
2912 	{0x011B, CMN_PLL0_SS_CTRL2_M0},
2913 	{0x011B, CMN_PLL0_SS_CTRL2_M1},
2914 	{0x011B, CMN_PLL1_SS_CTRL2_M0},
2915 	{0x006E, CMN_PLL0_SS_CTRL3_M0},
2916 	{0x0058, CMN_PLL0_SS_CTRL3_M1},
2917 	{0x006E, CMN_PLL1_SS_CTRL3_M0},
2918 	{0x000E, CMN_PLL0_SS_CTRL4_M0},
2919 	{0x0012, CMN_PLL0_SS_CTRL4_M1},
2920 	{0x000E, CMN_PLL1_SS_CTRL4_M0},
2921 	{0x0C5E, CMN_PLL0_VCOCAL_REFTIM_START},
2922 	{0x0C5E, CMN_PLL1_VCOCAL_REFTIM_START},
2923 	{0x0C56, CMN_PLL0_VCOCAL_PLLCNT_START},
2924 	{0x0C56, CMN_PLL1_VCOCAL_PLLCNT_START},
2925 	{0x0003, CMN_PLL0_VCOCAL_TCTRL},
2926 	{0x0003, CMN_PLL1_VCOCAL_TCTRL},
2927 	{0x00C7, CMN_PLL0_LOCK_REFCNT_START},
2928 	{0x00C7, CMN_PLL1_LOCK_REFCNT_START},
2929 	{0x00C7, CMN_PLL0_LOCK_PLLCNT_START},
2930 	{0x00C7, CMN_PLL1_LOCK_PLLCNT_START},
2931 	{0x0005, CMN_PLL0_LOCK_PLLCNT_THR},
2932 	{0x0005, CMN_PLL1_LOCK_PLLCNT_THR}
2933 };
2934 
2935 static struct cdns_torrent_vals pcie_100_int_ssc_cmn_vals = {
2936 	.reg_pairs = pcie_100_int_ssc_cmn_regs,
2937 	.num_regs = ARRAY_SIZE(pcie_100_int_ssc_cmn_regs),
2938 };
2939 
2940 /* Single link PCIe, 100 MHz Ref clk, internal SSC */
2941 static struct cdns_reg_pairs sl_pcie_100_int_ssc_cmn_regs[] = {
2942 	{0x0004, CMN_PLL0_DSM_DIAG_M0},
2943 	{0x0004, CMN_PLL0_DSM_DIAG_M1},
2944 	{0x0004, CMN_PLL1_DSM_DIAG_M0},
2945 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M0},
2946 	{0x0509, CMN_PDIAG_PLL0_CP_PADJ_M1},
2947 	{0x0509, CMN_PDIAG_PLL1_CP_PADJ_M0},
2948 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M0},
2949 	{0x0F00, CMN_PDIAG_PLL0_CP_IADJ_M1},
2950 	{0x0F00, CMN_PDIAG_PLL1_CP_IADJ_M0},
2951 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M0},
2952 	{0x0F08, CMN_PDIAG_PLL0_FILT_PADJ_M1},
2953 	{0x0F08, CMN_PDIAG_PLL1_FILT_PADJ_M0},
2954 	{0x0064, CMN_PLL0_INTDIV_M0},
2955 	{0x0050, CMN_PLL0_INTDIV_M1},
2956 	{0x0050, CMN_PLL1_INTDIV_M0},
2957 	{0x0002, CMN_PLL0_FRACDIVH_M0},
2958 	{0x0002, CMN_PLL0_FRACDIVH_M1},
2959 	{0x0002, CMN_PLL1_FRACDIVH_M0},
2960 	{0x0044, CMN_PLL0_HIGH_THR_M0},
2961 	{0x0036, CMN_PLL0_HIGH_THR_M1},
2962 	{0x0036, CMN_PLL1_HIGH_THR_M0},
2963 	{0x0002, CMN_PDIAG_PLL0_CTRL_M0},
2964 	{0x0002, CMN_PDIAG_PLL0_CTRL_M1},
2965 	{0x0002, CMN_PDIAG_PLL1_CTRL_M0},
2966 	{0x0001, CMN_PLL0_SS_CTRL1_M0},
2967 	{0x0001, CMN_PLL0_SS_CTRL1_M1},
2968 	{0x0001, CMN_PLL1_SS_CTRL1_M0},
2969 	{0x011B, CMN_PLL0_SS_CTRL2_M0},
2970 	{0x011B, CMN_PLL0_SS_CTRL2_M1},
2971 	{0x011B, CMN_PLL1_SS_CTRL2_M0},
2972 	{0x006E, CMN_PLL0_SS_CTRL3_M0},
2973 	{0x0058, CMN_PLL0_SS_CTRL3_M1},
2974 	{0x0058, CMN_PLL1_SS_CTRL3_M0},
2975 	{0x000E, CMN_PLL0_SS_CTRL4_M0},
2976 	{0x0012, CMN_PLL0_SS_CTRL4_M1},
2977 	{0x0012, CMN_PLL1_SS_CTRL4_M0},
2978 	{0x0C5E, CMN_PLL0_VCOCAL_REFTIM_START},
2979 	{0x0C5E, CMN_PLL1_VCOCAL_REFTIM_START},
2980 	{0x0C56, CMN_PLL0_VCOCAL_PLLCNT_START},
2981 	{0x0C56, CMN_PLL1_VCOCAL_PLLCNT_START},
2982 	{0x0003, CMN_PLL0_VCOCAL_TCTRL},
2983 	{0x0003, CMN_PLL1_VCOCAL_TCTRL},
2984 	{0x00C7, CMN_PLL0_LOCK_REFCNT_START},
2985 	{0x00C7, CMN_PLL1_LOCK_REFCNT_START},
2986 	{0x00C7, CMN_PLL0_LOCK_PLLCNT_START},
2987 	{0x00C7, CMN_PLL1_LOCK_PLLCNT_START},
2988 	{0x0005, CMN_PLL0_LOCK_PLLCNT_THR},
2989 	{0x0005, CMN_PLL1_LOCK_PLLCNT_THR}
2990 };
2991 
2992 static struct cdns_torrent_vals sl_pcie_100_int_ssc_cmn_vals = {
2993 	.reg_pairs = sl_pcie_100_int_ssc_cmn_regs,
2994 	.num_regs = ARRAY_SIZE(sl_pcie_100_int_ssc_cmn_regs),
2995 };
2996 
2997 /* PCIe, 100 MHz Ref clk, no SSC & external SSC */
2998 static struct cdns_reg_pairs pcie_100_ext_no_ssc_cmn_regs[] = {
2999 	{0x0003, CMN_PLL0_VCOCAL_TCTRL},
3000 	{0x0003, CMN_PLL1_VCOCAL_TCTRL}
3001 };
3002 
3003 static struct cdns_reg_pairs pcie_100_ext_no_ssc_rx_ln_regs[] = {
3004 	{0x0019, RX_REE_TAP1_CLIP},
3005 	{0x0019, RX_REE_TAP2TON_CLIP},
3006 	{0x0001, RX_DIAG_ACYA}
3007 };
3008 
3009 static struct cdns_torrent_vals pcie_100_no_ssc_cmn_vals = {
3010 	.reg_pairs = pcie_100_ext_no_ssc_cmn_regs,
3011 	.num_regs = ARRAY_SIZE(pcie_100_ext_no_ssc_cmn_regs),
3012 };
3013 
3014 static struct cdns_torrent_vals pcie_100_no_ssc_rx_ln_vals = {
3015 	.reg_pairs = pcie_100_ext_no_ssc_rx_ln_regs,
3016 	.num_regs = ARRAY_SIZE(pcie_100_ext_no_ssc_rx_ln_regs),
3017 };
3018 
3019 static const struct cdns_torrent_data cdns_map_torrent = {
3020 	.block_offset_shift = 0x2,
3021 	.reg_offset_shift = 0x2,
3022 	.link_cmn_vals = {
3023 		[TYPE_PCIE] = {
3024 			[TYPE_NONE] = {
3025 				[NO_SSC] = NULL,
3026 				[EXTERNAL_SSC] = NULL,
3027 				[INTERNAL_SSC] = NULL,
3028 			},
3029 			[TYPE_SGMII] = {
3030 				[NO_SSC] = &pcie_sgmii_link_cmn_vals,
3031 				[EXTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3032 				[INTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3033 			},
3034 			[TYPE_QSGMII] = {
3035 				[NO_SSC] = &pcie_sgmii_link_cmn_vals,
3036 				[EXTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3037 				[INTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3038 			},
3039 			[TYPE_USB] = {
3040 				[NO_SSC] = &pcie_usb_link_cmn_vals,
3041 				[EXTERNAL_SSC] = &pcie_usb_link_cmn_vals,
3042 				[INTERNAL_SSC] = &pcie_usb_link_cmn_vals,
3043 			},
3044 		},
3045 		[TYPE_SGMII] = {
3046 			[TYPE_NONE] = {
3047 				[NO_SSC] = &sl_sgmii_link_cmn_vals,
3048 			},
3049 			[TYPE_PCIE] = {
3050 				[NO_SSC] = &pcie_sgmii_link_cmn_vals,
3051 				[EXTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3052 				[INTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3053 			},
3054 			[TYPE_USB] = {
3055 				[NO_SSC] = &usb_sgmii_link_cmn_vals,
3056 				[EXTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3057 				[INTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3058 			},
3059 		},
3060 		[TYPE_QSGMII] = {
3061 			[TYPE_NONE] = {
3062 				[NO_SSC] = &sl_sgmii_link_cmn_vals,
3063 			},
3064 			[TYPE_PCIE] = {
3065 				[NO_SSC] = &pcie_sgmii_link_cmn_vals,
3066 				[EXTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3067 				[INTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3068 			},
3069 			[TYPE_USB] = {
3070 				[NO_SSC] = &usb_sgmii_link_cmn_vals,
3071 				[EXTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3072 				[INTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3073 			},
3074 		},
3075 		[TYPE_USB] = {
3076 			[TYPE_NONE] = {
3077 				[NO_SSC] = &sl_usb_link_cmn_vals,
3078 				[EXTERNAL_SSC] = &sl_usb_link_cmn_vals,
3079 				[INTERNAL_SSC] = &sl_usb_link_cmn_vals,
3080 			},
3081 			[TYPE_PCIE] = {
3082 				[NO_SSC] = &pcie_usb_link_cmn_vals,
3083 				[EXTERNAL_SSC] = &pcie_usb_link_cmn_vals,
3084 				[INTERNAL_SSC] = &pcie_usb_link_cmn_vals,
3085 			},
3086 			[TYPE_SGMII] = {
3087 				[NO_SSC] = &usb_sgmii_link_cmn_vals,
3088 				[EXTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3089 				[INTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3090 			},
3091 			[TYPE_QSGMII] = {
3092 				[NO_SSC] = &usb_sgmii_link_cmn_vals,
3093 				[EXTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3094 				[INTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3095 			},
3096 		},
3097 	},
3098 	.xcvr_diag_vals = {
3099 		[TYPE_PCIE] = {
3100 			[TYPE_NONE] = {
3101 				[NO_SSC] = NULL,
3102 				[EXTERNAL_SSC] = NULL,
3103 				[INTERNAL_SSC] = NULL,
3104 			},
3105 			[TYPE_SGMII] = {
3106 				[NO_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3107 				[EXTERNAL_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3108 				[INTERNAL_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3109 			},
3110 			[TYPE_QSGMII] = {
3111 				[NO_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3112 				[EXTERNAL_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3113 				[INTERNAL_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3114 			},
3115 			[TYPE_USB] = {
3116 				[NO_SSC] = &pcie_usb_xcvr_diag_ln_vals,
3117 				[EXTERNAL_SSC] = &pcie_usb_xcvr_diag_ln_vals,
3118 				[INTERNAL_SSC] = &pcie_usb_xcvr_diag_ln_vals,
3119 			},
3120 		},
3121 		[TYPE_SGMII] = {
3122 			[TYPE_NONE] = {
3123 				[NO_SSC] = &sl_sgmii_xcvr_diag_ln_vals,
3124 			},
3125 			[TYPE_PCIE] = {
3126 				[NO_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3127 				[EXTERNAL_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3128 				[INTERNAL_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3129 			},
3130 			[TYPE_USB] = {
3131 				[NO_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3132 				[EXTERNAL_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3133 				[INTERNAL_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3134 			},
3135 		},
3136 		[TYPE_QSGMII] = {
3137 			[TYPE_NONE] = {
3138 				[NO_SSC] = &sl_sgmii_xcvr_diag_ln_vals,
3139 			},
3140 			[TYPE_PCIE] = {
3141 				[NO_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3142 				[EXTERNAL_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3143 				[INTERNAL_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3144 			},
3145 			[TYPE_USB] = {
3146 				[NO_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3147 				[EXTERNAL_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3148 				[INTERNAL_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3149 			},
3150 		},
3151 		[TYPE_USB] = {
3152 			[TYPE_NONE] = {
3153 				[NO_SSC] = &sl_usb_xcvr_diag_ln_vals,
3154 				[EXTERNAL_SSC] = &sl_usb_xcvr_diag_ln_vals,
3155 				[INTERNAL_SSC] = &sl_usb_xcvr_diag_ln_vals,
3156 			},
3157 			[TYPE_PCIE] = {
3158 				[NO_SSC] = &usb_pcie_xcvr_diag_ln_vals,
3159 				[EXTERNAL_SSC] = &usb_pcie_xcvr_diag_ln_vals,
3160 				[INTERNAL_SSC] = &usb_pcie_xcvr_diag_ln_vals,
3161 			},
3162 			[TYPE_SGMII] = {
3163 				[NO_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3164 				[EXTERNAL_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3165 				[INTERNAL_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3166 			},
3167 			[TYPE_QSGMII] = {
3168 				[NO_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3169 				[EXTERNAL_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3170 				[INTERNAL_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3171 			},
3172 		},
3173 	},
3174 	.pcs_cmn_vals = {
3175 		[TYPE_USB] = {
3176 			[TYPE_NONE] = {
3177 				[NO_SSC] = &usb_phy_pcs_cmn_vals,
3178 				[EXTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3179 				[INTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3180 			},
3181 			[TYPE_PCIE] = {
3182 				[NO_SSC] = &usb_phy_pcs_cmn_vals,
3183 				[EXTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3184 				[INTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3185 			},
3186 			[TYPE_SGMII] = {
3187 				[NO_SSC] = &usb_phy_pcs_cmn_vals,
3188 				[EXTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3189 				[INTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3190 			},
3191 			[TYPE_QSGMII] = {
3192 				[NO_SSC] = &usb_phy_pcs_cmn_vals,
3193 				[EXTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3194 				[INTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3195 			},
3196 		},
3197 	},
3198 	.cmn_vals = {
3199 		[TYPE_PCIE] = {
3200 			[TYPE_NONE] = {
3201 				[NO_SSC] = &pcie_100_no_ssc_cmn_vals,
3202 				[EXTERNAL_SSC] = &pcie_100_no_ssc_cmn_vals,
3203 				[INTERNAL_SSC] = &sl_pcie_100_int_ssc_cmn_vals,
3204 			},
3205 			[TYPE_SGMII] = {
3206 				[NO_SSC] = &pcie_100_no_ssc_cmn_vals,
3207 				[EXTERNAL_SSC] = &pcie_100_no_ssc_cmn_vals,
3208 				[INTERNAL_SSC] = &pcie_100_int_ssc_cmn_vals,
3209 			},
3210 			[TYPE_QSGMII] = {
3211 				[NO_SSC] = &pcie_100_no_ssc_cmn_vals,
3212 				[EXTERNAL_SSC] = &pcie_100_no_ssc_cmn_vals,
3213 				[INTERNAL_SSC] = &pcie_100_int_ssc_cmn_vals,
3214 			},
3215 			[TYPE_USB] = {
3216 				[NO_SSC] = &pcie_100_no_ssc_cmn_vals,
3217 				[EXTERNAL_SSC] = &pcie_100_no_ssc_cmn_vals,
3218 				[INTERNAL_SSC] = &pcie_100_int_ssc_cmn_vals,
3219 			},
3220 		},
3221 		[TYPE_SGMII] = {
3222 			[TYPE_NONE] = {
3223 				[NO_SSC] = &sgmii_100_no_ssc_cmn_vals,
3224 			},
3225 			[TYPE_PCIE] = {
3226 				[NO_SSC] = &sgmii_100_no_ssc_cmn_vals,
3227 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_cmn_vals,
3228 				[INTERNAL_SSC] = &sgmii_100_int_ssc_cmn_vals,
3229 			},
3230 			[TYPE_USB] = {
3231 				[NO_SSC] = &sgmii_100_no_ssc_cmn_vals,
3232 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_cmn_vals,
3233 				[INTERNAL_SSC] = &sgmii_100_no_ssc_cmn_vals,
3234 			},
3235 		},
3236 		[TYPE_QSGMII] = {
3237 			[TYPE_NONE] = {
3238 				[NO_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3239 			},
3240 			[TYPE_PCIE] = {
3241 				[NO_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3242 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3243 				[INTERNAL_SSC] = &qsgmii_100_int_ssc_cmn_vals,
3244 			},
3245 			[TYPE_USB] = {
3246 				[NO_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3247 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3248 				[INTERNAL_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3249 			},
3250 		},
3251 		[TYPE_USB] = {
3252 			[TYPE_NONE] = {
3253 				[NO_SSC] = &usb_100_no_ssc_cmn_vals,
3254 				[EXTERNAL_SSC] = &usb_100_no_ssc_cmn_vals,
3255 				[INTERNAL_SSC] = &sl_usb_100_int_ssc_cmn_vals,
3256 			},
3257 			[TYPE_PCIE] = {
3258 				[NO_SSC] = &usb_100_no_ssc_cmn_vals,
3259 				[EXTERNAL_SSC] = &usb_100_no_ssc_cmn_vals,
3260 				[INTERNAL_SSC] = &usb_100_int_ssc_cmn_vals,
3261 			},
3262 			[TYPE_SGMII] = {
3263 				[NO_SSC] = &usb_100_no_ssc_cmn_vals,
3264 				[EXTERNAL_SSC] = &usb_100_no_ssc_cmn_vals,
3265 				[INTERNAL_SSC] = &sl_usb_100_int_ssc_cmn_vals,
3266 			},
3267 			[TYPE_QSGMII] = {
3268 				[NO_SSC] = &usb_100_no_ssc_cmn_vals,
3269 				[EXTERNAL_SSC] = &usb_100_no_ssc_cmn_vals,
3270 				[INTERNAL_SSC] = &sl_usb_100_int_ssc_cmn_vals,
3271 			},
3272 		},
3273 	},
3274 	.tx_ln_vals = {
3275 		[TYPE_PCIE] = {
3276 			[TYPE_NONE] = {
3277 				[NO_SSC] = NULL,
3278 				[EXTERNAL_SSC] = NULL,
3279 				[INTERNAL_SSC] = NULL,
3280 			},
3281 			[TYPE_SGMII] = {
3282 				[NO_SSC] = NULL,
3283 				[EXTERNAL_SSC] = NULL,
3284 				[INTERNAL_SSC] = NULL,
3285 			},
3286 			[TYPE_QSGMII] = {
3287 				[NO_SSC] = NULL,
3288 				[EXTERNAL_SSC] = NULL,
3289 				[INTERNAL_SSC] = NULL,
3290 			},
3291 			[TYPE_USB] = {
3292 				[NO_SSC] = NULL,
3293 				[EXTERNAL_SSC] = NULL,
3294 				[INTERNAL_SSC] = NULL,
3295 			},
3296 		},
3297 		[TYPE_SGMII] = {
3298 			[TYPE_NONE] = {
3299 				[NO_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3300 			},
3301 			[TYPE_PCIE] = {
3302 				[NO_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3303 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3304 				[INTERNAL_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3305 			},
3306 			[TYPE_USB] = {
3307 				[NO_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3308 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3309 				[INTERNAL_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3310 			},
3311 		},
3312 		[TYPE_QSGMII] = {
3313 			[TYPE_NONE] = {
3314 				[NO_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3315 			},
3316 			[TYPE_PCIE] = {
3317 				[NO_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3318 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3319 				[INTERNAL_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3320 			},
3321 			[TYPE_USB] = {
3322 				[NO_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3323 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3324 				[INTERNAL_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3325 			},
3326 		},
3327 		[TYPE_USB] = {
3328 			[TYPE_NONE] = {
3329 				[NO_SSC] = &usb_100_no_ssc_tx_ln_vals,
3330 				[EXTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3331 				[INTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3332 			},
3333 			[TYPE_PCIE] = {
3334 				[NO_SSC] = &usb_100_no_ssc_tx_ln_vals,
3335 				[EXTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3336 				[INTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3337 			},
3338 			[TYPE_SGMII] = {
3339 				[NO_SSC] = &usb_100_no_ssc_tx_ln_vals,
3340 				[EXTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3341 				[INTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3342 			},
3343 			[TYPE_QSGMII] = {
3344 				[NO_SSC] = &usb_100_no_ssc_tx_ln_vals,
3345 				[EXTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3346 				[INTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3347 			},
3348 		},
3349 	},
3350 	.rx_ln_vals = {
3351 		[TYPE_PCIE] = {
3352 			[TYPE_NONE] = {
3353 				[NO_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3354 				[EXTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3355 				[INTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3356 			},
3357 			[TYPE_SGMII] = {
3358 				[NO_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3359 				[EXTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3360 				[INTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3361 			},
3362 			[TYPE_QSGMII] = {
3363 				[NO_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3364 				[EXTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3365 				[INTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3366 			},
3367 			[TYPE_USB] = {
3368 				[NO_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3369 				[EXTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3370 				[INTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3371 			},
3372 		},
3373 		[TYPE_SGMII] = {
3374 			[TYPE_NONE] = {
3375 				[NO_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3376 			},
3377 			[TYPE_PCIE] = {
3378 				[NO_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3379 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3380 				[INTERNAL_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3381 			},
3382 			[TYPE_USB] = {
3383 				[NO_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3384 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3385 				[INTERNAL_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3386 			},
3387 		},
3388 		[TYPE_QSGMII] = {
3389 			[TYPE_NONE] = {
3390 				[NO_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3391 			},
3392 			[TYPE_PCIE] = {
3393 				[NO_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3394 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3395 				[INTERNAL_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3396 			},
3397 			[TYPE_USB] = {
3398 				[NO_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3399 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3400 				[INTERNAL_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3401 			},
3402 		},
3403 		[TYPE_USB] = {
3404 			[TYPE_NONE] = {
3405 				[NO_SSC] = &usb_100_no_ssc_rx_ln_vals,
3406 				[EXTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3407 				[INTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3408 			},
3409 			[TYPE_PCIE] = {
3410 				[NO_SSC] = &usb_100_no_ssc_rx_ln_vals,
3411 				[EXTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3412 				[INTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3413 			},
3414 			[TYPE_SGMII] = {
3415 				[NO_SSC] = &usb_100_no_ssc_rx_ln_vals,
3416 				[EXTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3417 				[INTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3418 			},
3419 			[TYPE_QSGMII] = {
3420 				[NO_SSC] = &usb_100_no_ssc_rx_ln_vals,
3421 				[EXTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3422 				[INTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3423 			},
3424 		},
3425 	},
3426 };
3427 
3428 static const struct cdns_torrent_data ti_j721e_map_torrent = {
3429 	.block_offset_shift = 0x0,
3430 	.reg_offset_shift = 0x1,
3431 	.link_cmn_vals = {
3432 		[TYPE_PCIE] = {
3433 			[TYPE_NONE] = {
3434 				[NO_SSC] = NULL,
3435 				[EXTERNAL_SSC] = NULL,
3436 				[INTERNAL_SSC] = NULL,
3437 			},
3438 			[TYPE_SGMII] = {
3439 				[NO_SSC] = &pcie_sgmii_link_cmn_vals,
3440 				[EXTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3441 				[INTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3442 			},
3443 			[TYPE_QSGMII] = {
3444 				[NO_SSC] = &pcie_sgmii_link_cmn_vals,
3445 				[EXTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3446 				[INTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3447 			},
3448 			[TYPE_USB] = {
3449 				[NO_SSC] = &pcie_usb_link_cmn_vals,
3450 				[EXTERNAL_SSC] = &pcie_usb_link_cmn_vals,
3451 				[INTERNAL_SSC] = &pcie_usb_link_cmn_vals,
3452 			},
3453 		},
3454 		[TYPE_SGMII] = {
3455 			[TYPE_NONE] = {
3456 				[NO_SSC] = &sl_sgmii_link_cmn_vals,
3457 			},
3458 			[TYPE_PCIE] = {
3459 				[NO_SSC] = &pcie_sgmii_link_cmn_vals,
3460 				[EXTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3461 				[INTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3462 			},
3463 			[TYPE_USB] = {
3464 				[NO_SSC] = &usb_sgmii_link_cmn_vals,
3465 				[EXTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3466 				[INTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3467 			},
3468 		},
3469 		[TYPE_QSGMII] = {
3470 			[TYPE_NONE] = {
3471 				[NO_SSC] = &sl_sgmii_link_cmn_vals,
3472 			},
3473 			[TYPE_PCIE] = {
3474 				[NO_SSC] = &pcie_sgmii_link_cmn_vals,
3475 				[EXTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3476 				[INTERNAL_SSC] = &pcie_sgmii_link_cmn_vals,
3477 			},
3478 			[TYPE_USB] = {
3479 				[NO_SSC] = &usb_sgmii_link_cmn_vals,
3480 				[EXTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3481 				[INTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3482 			},
3483 		},
3484 		[TYPE_USB] = {
3485 			[TYPE_NONE] = {
3486 				[NO_SSC] = &sl_usb_link_cmn_vals,
3487 				[EXTERNAL_SSC] = &sl_usb_link_cmn_vals,
3488 				[INTERNAL_SSC] = &sl_usb_link_cmn_vals,
3489 			},
3490 			[TYPE_PCIE] = {
3491 				[NO_SSC] = &pcie_usb_link_cmn_vals,
3492 				[EXTERNAL_SSC] = &pcie_usb_link_cmn_vals,
3493 				[INTERNAL_SSC] = &pcie_usb_link_cmn_vals,
3494 			},
3495 			[TYPE_SGMII] = {
3496 				[NO_SSC] = &usb_sgmii_link_cmn_vals,
3497 				[EXTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3498 				[INTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3499 			},
3500 			[TYPE_QSGMII] = {
3501 				[NO_SSC] = &usb_sgmii_link_cmn_vals,
3502 				[EXTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3503 				[INTERNAL_SSC] = &usb_sgmii_link_cmn_vals,
3504 			},
3505 		},
3506 	},
3507 	.xcvr_diag_vals = {
3508 		[TYPE_PCIE] = {
3509 			[TYPE_NONE] = {
3510 				[NO_SSC] = NULL,
3511 				[EXTERNAL_SSC] = NULL,
3512 				[INTERNAL_SSC] = NULL,
3513 			},
3514 			[TYPE_SGMII] = {
3515 				[NO_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3516 				[EXTERNAL_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3517 				[INTERNAL_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3518 			},
3519 			[TYPE_QSGMII] = {
3520 				[NO_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3521 				[EXTERNAL_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3522 				[INTERNAL_SSC] = &pcie_sgmii_xcvr_diag_ln_vals,
3523 			},
3524 			[TYPE_USB] = {
3525 				[NO_SSC] = &pcie_usb_xcvr_diag_ln_vals,
3526 				[EXTERNAL_SSC] = &pcie_usb_xcvr_diag_ln_vals,
3527 				[INTERNAL_SSC] = &pcie_usb_xcvr_diag_ln_vals,
3528 			},
3529 		},
3530 		[TYPE_SGMII] = {
3531 			[TYPE_NONE] = {
3532 				[NO_SSC] = &sl_sgmii_xcvr_diag_ln_vals,
3533 			},
3534 			[TYPE_PCIE] = {
3535 				[NO_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3536 				[EXTERNAL_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3537 				[INTERNAL_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3538 			},
3539 			[TYPE_USB] = {
3540 				[NO_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3541 				[EXTERNAL_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3542 				[INTERNAL_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3543 			},
3544 		},
3545 		[TYPE_QSGMII] = {
3546 			[TYPE_NONE] = {
3547 				[NO_SSC] = &sl_sgmii_xcvr_diag_ln_vals,
3548 			},
3549 			[TYPE_PCIE] = {
3550 				[NO_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3551 				[EXTERNAL_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3552 				[INTERNAL_SSC] = &sgmii_pcie_xcvr_diag_ln_vals,
3553 			},
3554 			[TYPE_USB] = {
3555 				[NO_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3556 				[EXTERNAL_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3557 				[INTERNAL_SSC] = &sgmii_usb_xcvr_diag_ln_vals,
3558 			},
3559 		},
3560 		[TYPE_USB] = {
3561 			[TYPE_NONE] = {
3562 				[NO_SSC] = &sl_usb_xcvr_diag_ln_vals,
3563 				[EXTERNAL_SSC] = &sl_usb_xcvr_diag_ln_vals,
3564 				[INTERNAL_SSC] = &sl_usb_xcvr_diag_ln_vals,
3565 			},
3566 			[TYPE_PCIE] = {
3567 				[NO_SSC] = &usb_pcie_xcvr_diag_ln_vals,
3568 				[EXTERNAL_SSC] = &usb_pcie_xcvr_diag_ln_vals,
3569 				[INTERNAL_SSC] = &usb_pcie_xcvr_diag_ln_vals,
3570 			},
3571 			[TYPE_SGMII] = {
3572 				[NO_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3573 				[EXTERNAL_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3574 				[INTERNAL_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3575 			},
3576 			[TYPE_QSGMII] = {
3577 				[NO_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3578 				[EXTERNAL_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3579 				[INTERNAL_SSC] = &usb_sgmii_xcvr_diag_ln_vals,
3580 			},
3581 		},
3582 	},
3583 	.pcs_cmn_vals = {
3584 		[TYPE_USB] = {
3585 			[TYPE_NONE] = {
3586 				[NO_SSC] = &usb_phy_pcs_cmn_vals,
3587 				[EXTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3588 				[INTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3589 			},
3590 			[TYPE_PCIE] = {
3591 				[NO_SSC] = &usb_phy_pcs_cmn_vals,
3592 				[EXTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3593 				[INTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3594 			},
3595 			[TYPE_SGMII] = {
3596 				[NO_SSC] = &usb_phy_pcs_cmn_vals,
3597 				[EXTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3598 				[INTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3599 			},
3600 			[TYPE_QSGMII] = {
3601 				[NO_SSC] = &usb_phy_pcs_cmn_vals,
3602 				[EXTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3603 				[INTERNAL_SSC] = &usb_phy_pcs_cmn_vals,
3604 			},
3605 		},
3606 	},
3607 	.cmn_vals = {
3608 		[TYPE_PCIE] = {
3609 			[TYPE_NONE] = {
3610 				[NO_SSC] = &pcie_100_no_ssc_cmn_vals,
3611 				[EXTERNAL_SSC] = &pcie_100_no_ssc_cmn_vals,
3612 				[INTERNAL_SSC] = &sl_pcie_100_int_ssc_cmn_vals,
3613 			},
3614 			[TYPE_SGMII] = {
3615 				[NO_SSC] = &pcie_100_no_ssc_cmn_vals,
3616 				[EXTERNAL_SSC] = &pcie_100_no_ssc_cmn_vals,
3617 				[INTERNAL_SSC] = &pcie_100_int_ssc_cmn_vals,
3618 			},
3619 			[TYPE_QSGMII] = {
3620 				[NO_SSC] = &pcie_100_no_ssc_cmn_vals,
3621 				[EXTERNAL_SSC] = &pcie_100_no_ssc_cmn_vals,
3622 				[INTERNAL_SSC] = &pcie_100_int_ssc_cmn_vals,
3623 			},
3624 			[TYPE_USB] = {
3625 				[NO_SSC] = &pcie_100_no_ssc_cmn_vals,
3626 				[EXTERNAL_SSC] = &pcie_100_no_ssc_cmn_vals,
3627 				[INTERNAL_SSC] = &pcie_100_int_ssc_cmn_vals,
3628 			},
3629 		},
3630 		[TYPE_SGMII] = {
3631 			[TYPE_NONE] = {
3632 				[NO_SSC] = &sgmii_100_no_ssc_cmn_vals,
3633 			},
3634 			[TYPE_PCIE] = {
3635 				[NO_SSC] = &sgmii_100_no_ssc_cmn_vals,
3636 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_cmn_vals,
3637 				[INTERNAL_SSC] = &sgmii_100_int_ssc_cmn_vals,
3638 			},
3639 			[TYPE_USB] = {
3640 				[NO_SSC] = &sgmii_100_no_ssc_cmn_vals,
3641 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_cmn_vals,
3642 				[INTERNAL_SSC] = &sgmii_100_no_ssc_cmn_vals,
3643 			},
3644 		},
3645 		[TYPE_QSGMII] = {
3646 			[TYPE_NONE] = {
3647 				[NO_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3648 			},
3649 			[TYPE_PCIE] = {
3650 				[NO_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3651 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3652 				[INTERNAL_SSC] = &qsgmii_100_int_ssc_cmn_vals,
3653 			},
3654 			[TYPE_USB] = {
3655 				[NO_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3656 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3657 				[INTERNAL_SSC] = &qsgmii_100_no_ssc_cmn_vals,
3658 			},
3659 		},
3660 		[TYPE_USB] = {
3661 			[TYPE_NONE] = {
3662 				[NO_SSC] = &usb_100_no_ssc_cmn_vals,
3663 				[EXTERNAL_SSC] = &usb_100_no_ssc_cmn_vals,
3664 				[INTERNAL_SSC] = &sl_usb_100_int_ssc_cmn_vals,
3665 			},
3666 			[TYPE_PCIE] = {
3667 				[NO_SSC] = &usb_100_no_ssc_cmn_vals,
3668 				[EXTERNAL_SSC] = &usb_100_no_ssc_cmn_vals,
3669 				[INTERNAL_SSC] = &usb_100_int_ssc_cmn_vals,
3670 			},
3671 			[TYPE_SGMII] = {
3672 				[NO_SSC] = &usb_100_no_ssc_cmn_vals,
3673 				[EXTERNAL_SSC] = &usb_100_no_ssc_cmn_vals,
3674 				[INTERNAL_SSC] = &sl_usb_100_int_ssc_cmn_vals,
3675 			},
3676 			[TYPE_QSGMII] = {
3677 				[NO_SSC] = &usb_100_no_ssc_cmn_vals,
3678 				[EXTERNAL_SSC] = &usb_100_no_ssc_cmn_vals,
3679 				[INTERNAL_SSC] = &sl_usb_100_int_ssc_cmn_vals,
3680 			},
3681 		},
3682 	},
3683 	.tx_ln_vals = {
3684 		[TYPE_PCIE] = {
3685 			[TYPE_NONE] = {
3686 				[NO_SSC] = NULL,
3687 				[EXTERNAL_SSC] = NULL,
3688 				[INTERNAL_SSC] = NULL,
3689 			},
3690 			[TYPE_SGMII] = {
3691 				[NO_SSC] = NULL,
3692 				[EXTERNAL_SSC] = NULL,
3693 				[INTERNAL_SSC] = NULL,
3694 			},
3695 			[TYPE_QSGMII] = {
3696 				[NO_SSC] = NULL,
3697 				[EXTERNAL_SSC] = NULL,
3698 				[INTERNAL_SSC] = NULL,
3699 			},
3700 			[TYPE_USB] = {
3701 				[NO_SSC] = NULL,
3702 				[EXTERNAL_SSC] = NULL,
3703 				[INTERNAL_SSC] = NULL,
3704 			},
3705 		},
3706 		[TYPE_SGMII] = {
3707 			[TYPE_NONE] = {
3708 				[NO_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3709 			},
3710 			[TYPE_PCIE] = {
3711 				[NO_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3712 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3713 				[INTERNAL_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3714 			},
3715 			[TYPE_USB] = {
3716 				[NO_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3717 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3718 				[INTERNAL_SSC] = &sgmii_100_no_ssc_tx_ln_vals,
3719 			},
3720 		},
3721 		[TYPE_QSGMII] = {
3722 			[TYPE_NONE] = {
3723 				[NO_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3724 			},
3725 			[TYPE_PCIE] = {
3726 				[NO_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3727 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3728 				[INTERNAL_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3729 			},
3730 			[TYPE_USB] = {
3731 				[NO_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3732 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3733 				[INTERNAL_SSC] = &qsgmii_100_no_ssc_tx_ln_vals,
3734 			},
3735 		},
3736 		[TYPE_USB] = {
3737 			[TYPE_NONE] = {
3738 				[NO_SSC] = &usb_100_no_ssc_tx_ln_vals,
3739 				[EXTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3740 				[INTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3741 			},
3742 			[TYPE_PCIE] = {
3743 				[NO_SSC] = &usb_100_no_ssc_tx_ln_vals,
3744 				[EXTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3745 				[INTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3746 			},
3747 			[TYPE_SGMII] = {
3748 				[NO_SSC] = &usb_100_no_ssc_tx_ln_vals,
3749 				[EXTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3750 				[INTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3751 			},
3752 			[TYPE_QSGMII] = {
3753 				[NO_SSC] = &usb_100_no_ssc_tx_ln_vals,
3754 				[EXTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3755 				[INTERNAL_SSC] = &usb_100_no_ssc_tx_ln_vals,
3756 			},
3757 		},
3758 	},
3759 	.rx_ln_vals = {
3760 		[TYPE_PCIE] = {
3761 			[TYPE_NONE] = {
3762 				[NO_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3763 				[EXTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3764 				[INTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3765 			},
3766 			[TYPE_SGMII] = {
3767 				[NO_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3768 				[EXTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3769 				[INTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3770 			},
3771 			[TYPE_QSGMII] = {
3772 				[NO_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3773 				[EXTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3774 				[INTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3775 			},
3776 			[TYPE_USB] = {
3777 				[NO_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3778 				[EXTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3779 				[INTERNAL_SSC] = &pcie_100_no_ssc_rx_ln_vals,
3780 			},
3781 		},
3782 		[TYPE_SGMII] = {
3783 			[TYPE_NONE] = {
3784 				[NO_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3785 			},
3786 			[TYPE_PCIE] = {
3787 				[NO_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3788 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3789 				[INTERNAL_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3790 			},
3791 			[TYPE_USB] = {
3792 				[NO_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3793 				[EXTERNAL_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3794 				[INTERNAL_SSC] = &sgmii_100_no_ssc_rx_ln_vals,
3795 			},
3796 		},
3797 		[TYPE_QSGMII] = {
3798 			[TYPE_NONE] = {
3799 				[NO_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3800 			},
3801 			[TYPE_PCIE] = {
3802 				[NO_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3803 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3804 				[INTERNAL_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3805 			},
3806 			[TYPE_USB] = {
3807 				[NO_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3808 				[EXTERNAL_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3809 				[INTERNAL_SSC] = &qsgmii_100_no_ssc_rx_ln_vals,
3810 			},
3811 		},
3812 		[TYPE_USB] = {
3813 			[TYPE_NONE] = {
3814 				[NO_SSC] = &usb_100_no_ssc_rx_ln_vals,
3815 				[EXTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3816 				[INTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3817 			},
3818 			[TYPE_PCIE] = {
3819 				[NO_SSC] = &usb_100_no_ssc_rx_ln_vals,
3820 				[EXTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3821 				[INTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3822 			},
3823 			[TYPE_SGMII] = {
3824 				[NO_SSC] = &usb_100_no_ssc_rx_ln_vals,
3825 				[EXTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3826 				[INTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3827 			},
3828 			[TYPE_QSGMII] = {
3829 				[NO_SSC] = &usb_100_no_ssc_rx_ln_vals,
3830 				[EXTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3831 				[INTERNAL_SSC] = &usb_100_no_ssc_rx_ln_vals,
3832 			},
3833 		},
3834 	},
3835 };
3836 
3837 static const struct of_device_id cdns_torrent_phy_of_match[] = {
3838 	{
3839 		.compatible = "cdns,torrent-phy",
3840 		.data = &cdns_map_torrent,
3841 	},
3842 	{
3843 		.compatible = "ti,j721e-serdes-10g",
3844 		.data = &ti_j721e_map_torrent,
3845 	},
3846 	{}
3847 };
3848 MODULE_DEVICE_TABLE(of, cdns_torrent_phy_of_match);
3849 
3850 static struct platform_driver cdns_torrent_phy_driver = {
3851 	.probe	= cdns_torrent_phy_probe,
3852 	.remove = cdns_torrent_phy_remove,
3853 	.driver = {
3854 		.name	= "cdns-torrent-phy",
3855 		.of_match_table	= cdns_torrent_phy_of_match,
3856 	}
3857 };
3858 module_platform_driver(cdns_torrent_phy_driver);
3859 
3860 MODULE_AUTHOR("Cadence Design Systems, Inc.");
3861 MODULE_DESCRIPTION("Cadence Torrent PHY driver");
3862 MODULE_LICENSE("GPL v2");
3863