blob: e2f631e330da6d370c51a7f99a1ad983a4e609a9 [file] [log] [blame]
Alan Douglasfda76da2021-07-21 21:28:36 +05301// SPDX-License-Identifier: GPL-2.0
2/*
3 * Cadence Sierra PHY Driver
4 *
5 * Based on the linux driver provided by Cadence
6 *
7 * Copyright (c) 2018 Cadence Design Systems
8 * Author: Alan Douglas <adouglas@cadence.com>
9 *
10 * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
11 * Jean-Jacques Hiblot <jjhiblot@ti.com>
12 *
13 */
14#include <common.h>
15#include <clk.h>
Aswath Govindraju304341f2022-01-28 13:41:36 +053016#include <linux/clk-provider.h>
Alan Douglasfda76da2021-07-21 21:28:36 +053017#include <generic-phy.h>
18#include <reset.h>
19#include <dm/device.h>
20#include <dm/device-internal.h>
21#include <dm/device_compat.h>
22#include <dm/lists.h>
23#include <dm/read.h>
24#include <dm/uclass.h>
25#include <dm/devres.h>
26#include <linux/io.h>
27#include <dt-bindings/phy/phy.h>
Aswath Govindraju304341f2022-01-28 13:41:36 +053028#include <dt-bindings/phy/phy-cadence.h>
Alan Douglasfda76da2021-07-21 21:28:36 +053029#include <regmap.h>
30
Swapnil Jakhadee42a8472022-01-28 13:41:40 +053031#define NUM_SSC_MODE 3
32#define NUM_PHY_TYPE 3
33
Alan Douglasfda76da2021-07-21 21:28:36 +053034/* PHY register offsets */
35#define SIERRA_COMMON_CDB_OFFSET 0x0
36#define SIERRA_MACRO_ID_REG 0x0
Aswath Govindraju304341f2022-01-28 13:41:36 +053037#define SIERRA_CMN_PLLLC_GEN_PREG 0x42
Alan Douglasfda76da2021-07-21 21:28:36 +053038#define SIERRA_CMN_PLLLC_MODE_PREG 0x48
39#define SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG 0x49
40#define SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG 0x4A
41#define SIERRA_CMN_PLLLC_LOCK_CNTSTART_PREG 0x4B
42#define SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG 0x4F
43#define SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG 0x50
44#define SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG 0x62
Aswath Govindraju304341f2022-01-28 13:41:36 +053045#define SIERRA_CMN_REFRCV_PREG 0x98
46#define SIERRA_CMN_REFRCV1_PREG 0xB8
47#define SIERRA_CMN_PLLLC1_GEN_PREG 0xC2
Alan Douglasfda76da2021-07-21 21:28:36 +053048
49#define SIERRA_LANE_CDB_OFFSET(ln, offset) \
50 (0x4000 + ((ln) * (0x800 >> (2 - (offset)))))
51
52#define SIERRA_DET_STANDEC_A_PREG 0x000
53#define SIERRA_DET_STANDEC_B_PREG 0x001
54#define SIERRA_DET_STANDEC_C_PREG 0x002
55#define SIERRA_DET_STANDEC_D_PREG 0x003
56#define SIERRA_DET_STANDEC_E_PREG 0x004
57#define SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG 0x008
58#define SIERRA_PSM_A0IN_TMR_PREG 0x009
59#define SIERRA_PSM_DIAG_PREG 0x015
60#define SIERRA_PSC_TX_A0_PREG 0x028
61#define SIERRA_PSC_TX_A1_PREG 0x029
62#define SIERRA_PSC_TX_A2_PREG 0x02A
63#define SIERRA_PSC_TX_A3_PREG 0x02B
64#define SIERRA_PSC_RX_A0_PREG 0x030
65#define SIERRA_PSC_RX_A1_PREG 0x031
66#define SIERRA_PSC_RX_A2_PREG 0x032
67#define SIERRA_PSC_RX_A3_PREG 0x033
68#define SIERRA_PLLCTRL_SUBRATE_PREG 0x03A
69#define SIERRA_PLLCTRL_GEN_D_PREG 0x03E
70#define SIERRA_PLLCTRL_CPGAIN_MODE_PREG 0x03F
71#define SIERRA_PLLCTRL_STATUS_PREG 0x044
72#define SIERRA_CLKPATH_BIASTRIM_PREG 0x04B
73#define SIERRA_DFE_BIASTRIM_PREG 0x04C
74#define SIERRA_DRVCTRL_ATTEN_PREG 0x06A
75#define SIERRA_CLKPATHCTRL_TMR_PREG 0x081
76#define SIERRA_RX_CREQ_FLTR_A_MODE3_PREG 0x085
77#define SIERRA_RX_CREQ_FLTR_A_MODE2_PREG 0x086
78#define SIERRA_RX_CREQ_FLTR_A_MODE1_PREG 0x087
79#define SIERRA_RX_CREQ_FLTR_A_MODE0_PREG 0x088
80#define SIERRA_CREQ_CCLKDET_MODE01_PREG 0x08E
81#define SIERRA_RX_CTLE_MAINTENANCE_PREG 0x091
82#define SIERRA_CREQ_FSMCLK_SEL_PREG 0x092
83#define SIERRA_CREQ_EQ_CTRL_PREG 0x093
84#define SIERRA_CREQ_SPARE_PREG 0x096
85#define SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG 0x097
86#define SIERRA_CTLELUT_CTRL_PREG 0x098
87#define SIERRA_DFE_ECMP_RATESEL_PREG 0x0C0
88#define SIERRA_DFE_SMP_RATESEL_PREG 0x0C1
89#define SIERRA_DEQ_PHALIGN_CTRL 0x0C4
90#define SIERRA_DEQ_CONCUR_CTRL1_PREG 0x0C8
91#define SIERRA_DEQ_CONCUR_CTRL2_PREG 0x0C9
92#define SIERRA_DEQ_EPIPWR_CTRL2_PREG 0x0CD
93#define SIERRA_DEQ_FAST_MAINT_CYCLES_PREG 0x0CE
94#define SIERRA_DEQ_ERRCMP_CTRL_PREG 0x0D0
95#define SIERRA_DEQ_OFFSET_CTRL_PREG 0x0D8
96#define SIERRA_DEQ_GAIN_CTRL_PREG 0x0E0
97#define SIERRA_DEQ_VGATUNE_CTRL_PREG 0x0E1
98#define SIERRA_DEQ_GLUT0 0x0E8
99#define SIERRA_DEQ_GLUT1 0x0E9
100#define SIERRA_DEQ_GLUT2 0x0EA
101#define SIERRA_DEQ_GLUT3 0x0EB
102#define SIERRA_DEQ_GLUT4 0x0EC
103#define SIERRA_DEQ_GLUT5 0x0ED
104#define SIERRA_DEQ_GLUT6 0x0EE
105#define SIERRA_DEQ_GLUT7 0x0EF
106#define SIERRA_DEQ_GLUT8 0x0F0
107#define SIERRA_DEQ_GLUT9 0x0F1
108#define SIERRA_DEQ_GLUT10 0x0F2
109#define SIERRA_DEQ_GLUT11 0x0F3
110#define SIERRA_DEQ_GLUT12 0x0F4
111#define SIERRA_DEQ_GLUT13 0x0F5
112#define SIERRA_DEQ_GLUT14 0x0F6
113#define SIERRA_DEQ_GLUT15 0x0F7
114#define SIERRA_DEQ_GLUT16 0x0F8
115#define SIERRA_DEQ_ALUT0 0x108
116#define SIERRA_DEQ_ALUT1 0x109
117#define SIERRA_DEQ_ALUT2 0x10A
118#define SIERRA_DEQ_ALUT3 0x10B
119#define SIERRA_DEQ_ALUT4 0x10C
120#define SIERRA_DEQ_ALUT5 0x10D
121#define SIERRA_DEQ_ALUT6 0x10E
122#define SIERRA_DEQ_ALUT7 0x10F
123#define SIERRA_DEQ_ALUT8 0x110
124#define SIERRA_DEQ_ALUT9 0x111
125#define SIERRA_DEQ_ALUT10 0x112
126#define SIERRA_DEQ_ALUT11 0x113
127#define SIERRA_DEQ_ALUT12 0x114
128#define SIERRA_DEQ_ALUT13 0x115
129#define SIERRA_DEQ_DFETAP_CTRL_PREG 0x128
130#define SIERRA_DFE_EN_1010_IGNORE_PREG 0x134
131#define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150
132#define SIERRA_DEQ_TAU_CTRL2_PREG 0x151
133#define SIERRA_DEQ_PICTRL_PREG 0x161
134#define SIERRA_CPICAL_TMRVAL_MODE1_PREG 0x170
135#define SIERRA_CPICAL_TMRVAL_MODE0_PREG 0x171
136#define SIERRA_CPICAL_PICNT_MODE1_PREG 0x174
137#define SIERRA_CPI_OUTBUF_RATESEL_PREG 0x17C
138#define SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG 0x183
139#define SIERRA_LFPSDET_SUPPORT_PREG 0x188
140#define SIERRA_LFPSFILT_NS_PREG 0x18A
141#define SIERRA_LFPSFILT_RD_PREG 0x18B
142#define SIERRA_LFPSFILT_MP_PREG 0x18C
143#define SIERRA_SIGDET_SUPPORT_PREG 0x190
144#define SIERRA_SDFILT_H2L_A_PREG 0x191
145#define SIERRA_SDFILT_L2H_PREG 0x193
146#define SIERRA_RXBUFFER_CTLECTRL_PREG 0x19E
147#define SIERRA_RXBUFFER_RCDFECTRL_PREG 0x19F
148#define SIERRA_RXBUFFER_DFECTRL_PREG 0x1A0
149#define SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG 0x14F
150#define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150
151
152#define SIERRA_PHY_CONFIG_CTRL_OFFSET 0xc000
153#define SIERRA_PHY_PLL_CFG 0xe
154
155#define SIERRA_MACRO_ID 0x00007364
156#define SIERRA_MAX_LANES 16
157#define PLL_LOCK_TIME 100
158
Aswath Govindraju304341f2022-01-28 13:41:36 +0530159#define CDNS_SIERRA_INPUT_CLOCKS 5
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530160enum cdns_sierra_clock_input {
161 PHY_CLK,
162 CMN_REFCLK_DIG_DIV,
163 CMN_REFCLK1_DIG_DIV,
Aswath Govindraju304341f2022-01-28 13:41:36 +0530164 PLL0_REFCLK,
165 PLL1_REFCLK,
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530166};
167
Aswath Govindraju304341f2022-01-28 13:41:36 +0530168#define SIERRA_NUM_CMN_PLLC 2
169#define SIERRA_NUM_CMN_PLLC_PARENTS 2
170
Alan Douglasfda76da2021-07-21 21:28:36 +0530171static const struct reg_field macro_id_type =
172 REG_FIELD(SIERRA_MACRO_ID_REG, 0, 15);
173static const struct reg_field phy_pll_cfg_1 =
174 REG_FIELD(SIERRA_PHY_PLL_CFG, 1, 1);
175static const struct reg_field pllctrl_lock =
176 REG_FIELD(SIERRA_PLLCTRL_STATUS_PREG, 0, 0);
177
Aswath Govindraju304341f2022-01-28 13:41:36 +0530178static const char * const clk_names[] = {
179 [CDNS_SIERRA_PLL_CMNLC] = "pll_cmnlc",
180 [CDNS_SIERRA_PLL_CMNLC1] = "pll_cmnlc1",
181};
182
183enum cdns_sierra_cmn_plllc {
184 CMN_PLLLC,
185 CMN_PLLLC1,
186};
187
188struct cdns_sierra_pll_mux_reg_fields {
189 struct reg_field pfdclk_sel_preg;
190 struct reg_field plllc1en_field;
191 struct reg_field termen_field;
192};
193
194static const struct cdns_sierra_pll_mux_reg_fields cmn_plllc_pfdclk1_sel_preg[] = {
195 [CMN_PLLLC] = {
196 .pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC_GEN_PREG, 1, 1),
197 .plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 8, 8),
198 .termen_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 0, 0),
199 },
200 [CMN_PLLLC1] = {
201 .pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC1_GEN_PREG, 1, 1),
202 .plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 8, 8),
203 .termen_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 0, 0),
204 },
205};
206
207struct cdns_sierra_pll_mux {
208 struct cdns_sierra_phy *sp;
209 struct clk *clk;
210 struct clk *parent_clks[2];
211 struct regmap_field *pfdclk_sel_preg;
212 struct regmap_field *plllc1en_field;
213 struct regmap_field *termen_field;
214};
215
Alan Douglasfda76da2021-07-21 21:28:36 +0530216#define reset_control_assert(rst) cdns_reset_assert(rst)
217#define reset_control_deassert(rst) cdns_reset_deassert(rst)
218#define reset_control reset_ctl
219
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530220enum cdns_sierra_phy_type {
221 TYPE_NONE,
222 TYPE_PCIE,
223 TYPE_USB
224};
225
226enum cdns_sierra_ssc_mode {
227 NO_SSC,
228 EXTERNAL_SSC,
229 INTERNAL_SSC
230};
231
Alan Douglasfda76da2021-07-21 21:28:36 +0530232struct cdns_sierra_inst {
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530233 enum cdns_sierra_phy_type phy_type;
Alan Douglasfda76da2021-07-21 21:28:36 +0530234 u32 num_lanes;
235 u32 mlane;
236 struct reset_ctl_bulk *lnk_rst;
Swapnil Jakhade0d372ea2022-01-28 13:41:42 +0530237 enum cdns_sierra_ssc_mode ssc_mode;
Alan Douglasfda76da2021-07-21 21:28:36 +0530238};
239
240struct cdns_reg_pairs {
241 u16 val;
242 u32 off;
243};
244
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530245struct cdns_sierra_vals {
246 const struct cdns_reg_pairs *reg_pairs;
247 u32 num_regs;
248};
249
Alan Douglasfda76da2021-07-21 21:28:36 +0530250struct cdns_sierra_data {
251 u32 id_value;
252 u8 block_offset_shift;
253 u8 reg_offset_shift;
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530254 struct cdns_sierra_vals *pma_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
255 [NUM_SSC_MODE];
256 struct cdns_sierra_vals *pma_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
257 [NUM_SSC_MODE];
Alan Douglasfda76da2021-07-21 21:28:36 +0530258};
259
Alan Douglasfda76da2021-07-21 21:28:36 +0530260struct cdns_sierra_phy {
261 struct udevice *dev;
262 void *base;
263 size_t size;
264 struct regmap *regmap;
265 struct cdns_sierra_data *init_data;
Aswath Govindraju11fcd0e2022-01-28 13:41:35 +0530266 struct cdns_sierra_inst *phys[SIERRA_MAX_LANES];
Alan Douglasfda76da2021-07-21 21:28:36 +0530267 struct reset_control *phy_rst;
268 struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES];
269 struct regmap *regmap_phy_config_ctrl;
270 struct regmap *regmap_common_cdb;
271 struct regmap_field *macro_id_type;
272 struct regmap_field *phy_pll_cfg_1;
273 struct regmap_field *pllctrl_lock[SIERRA_MAX_LANES];
Aswath Govindraju304341f2022-01-28 13:41:36 +0530274 struct regmap_field *cmn_refrcv_refclk_plllc1en_preg[SIERRA_NUM_CMN_PLLC];
275 struct regmap_field *cmn_refrcv_refclk_termen_preg[SIERRA_NUM_CMN_PLLC];
276 struct regmap_field *cmn_plllc_pfdclk1_sel_preg[SIERRA_NUM_CMN_PLLC];
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530277 struct clk *input_clks[CDNS_SIERRA_INPUT_CLOCKS];
Alan Douglasfda76da2021-07-21 21:28:36 +0530278 int nsubnodes;
279 u32 num_lanes;
280 bool autoconf;
281};
282
283static inline int cdns_reset_assert(struct reset_control *rst)
284{
285 if (rst)
286 return reset_assert(rst);
287 else
288 return 0;
289}
290
291static inline int cdns_reset_deassert(struct reset_control *rst)
292{
293 if (rst)
294 return reset_deassert(rst);
295 else
296 return 0;
297}
298
299static inline struct cdns_sierra_inst *phy_get_drvdata(struct phy *phy)
300{
301 struct cdns_sierra_phy *sp = dev_get_priv(phy->dev);
302 int index;
303
304 if (phy->id >= SIERRA_MAX_LANES)
305 return NULL;
306
307 for (index = 0; index < sp->nsubnodes; index++) {
Aswath Govindraju11fcd0e2022-01-28 13:41:35 +0530308 if (phy->id == sp->phys[index]->mlane)
309 return sp->phys[index];
Alan Douglasfda76da2021-07-21 21:28:36 +0530310 }
311
312 return NULL;
313}
314
315static int cdns_sierra_phy_init(struct phy *gphy)
316{
317 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
318 struct cdns_sierra_phy *phy = dev_get_priv(gphy->dev);
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530319 struct cdns_sierra_data *init_data = phy->init_data;
320 struct cdns_sierra_vals *pma_cmn_vals, *pma_ln_vals;
321 enum cdns_sierra_phy_type phy_type = ins->phy_type;
Swapnil Jakhade0d372ea2022-01-28 13:41:42 +0530322 enum cdns_sierra_ssc_mode ssc = ins->ssc_mode;
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530323 const struct cdns_reg_pairs *reg_pairs;
Alan Douglasfda76da2021-07-21 21:28:36 +0530324 struct regmap *regmap = phy->regmap;
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530325 u32 num_regs;
Alan Douglasfda76da2021-07-21 21:28:36 +0530326 int i, j;
Alan Douglasfda76da2021-07-21 21:28:36 +0530327
328 /* Initialise the PHY registers, unless auto configured */
329 if (phy->autoconf)
330 return 0;
331
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530332 clk_set_rate(phy->input_clks[CMN_REFCLK_DIG_DIV], 25000000);
333 clk_set_rate(phy->input_clks[CMN_REFCLK1_DIG_DIV], 25000000);
Alan Douglasfda76da2021-07-21 21:28:36 +0530334
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530335 /* PMA common registers configurations */
336 pma_cmn_vals = init_data->pma_cmn_vals[phy_type][TYPE_NONE][ssc];
337 if (pma_cmn_vals) {
338 reg_pairs = pma_cmn_vals->reg_pairs;
339 num_regs = pma_cmn_vals->num_regs;
340 regmap = phy->regmap_common_cdb;
341 for (i = 0; i < num_regs; i++)
342 regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
Alan Douglasfda76da2021-07-21 21:28:36 +0530343 }
344
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530345 /* PMA TX lane registers configurations */
346 pma_ln_vals = init_data->pma_ln_vals[phy_type][TYPE_NONE][ssc];
347 if (pma_ln_vals) {
348 reg_pairs = pma_ln_vals->reg_pairs;
349 num_regs = pma_ln_vals->num_regs;
350 for (i = 0; i < ins->num_lanes; i++) {
Alan Douglasfda76da2021-07-21 21:28:36 +0530351 regmap = phy->regmap_lane_cdb[i + ins->mlane];
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530352 for (j = 0; j < num_regs; j++)
353 regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val);
Alan Douglasfda76da2021-07-21 21:28:36 +0530354 }
355 }
356
357 return 0;
358}
359
360static int cdns_sierra_phy_on(struct phy *gphy)
361{
362 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
363 struct cdns_sierra_phy *sp = dev_get_priv(gphy->dev);
364 struct udevice *dev = gphy->dev;
365 u32 val;
366 int ret;
367
Kishon Vijay Abraham I1ff2b712022-01-28 13:41:29 +0530368 ret = reset_control_deassert(sp->phy_rst);
369 if (ret) {
370 dev_err(dev, "Failed to take the PHY out of reset\n");
371 return ret;
372 }
373
Alan Douglasfda76da2021-07-21 21:28:36 +0530374 /* Take the PHY lane group out of reset */
375 ret = reset_deassert_bulk(ins->lnk_rst);
376 if (ret) {
377 dev_err(dev, "Failed to take the PHY lane out of reset\n");
378 return ret;
379 }
380
381 ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane],
382 val, val, 1000, PLL_LOCK_TIME);
383 if (ret < 0)
384 dev_err(dev, "PLL lock of lane failed\n");
385
386 reset_control_assert(sp->phy_rst);
387 reset_control_deassert(sp->phy_rst);
388
389 return ret;
390}
391
392static int cdns_sierra_phy_off(struct phy *gphy)
393{
394 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
395
396 return reset_assert_bulk(ins->lnk_rst);
397}
398
399static int cdns_sierra_phy_reset(struct phy *gphy)
400{
401 struct cdns_sierra_phy *sp = dev_get_priv(gphy->dev);
402
403 reset_control_assert(sp->phy_rst);
404 reset_control_deassert(sp->phy_rst);
405 return 0;
406};
407
408static const struct phy_ops ops = {
409 .init = cdns_sierra_phy_init,
410 .power_on = cdns_sierra_phy_on,
411 .power_off = cdns_sierra_phy_off,
412 .reset = cdns_sierra_phy_reset,
413};
414
Aswath Govindraju304341f2022-01-28 13:41:36 +0530415struct cdns_sierra_pll_mux_sel {
416 enum cdns_sierra_cmn_plllc mux_sel;
417 u32 table[2];
418 const char *node_name;
419 u32 num_parents;
420 u32 parents[2];
421};
422
423static struct cdns_sierra_pll_mux_sel pll_clk_mux_sel[] = {
424 {
425 .num_parents = 2,
426 .parents = { PLL0_REFCLK, PLL1_REFCLK },
427 .mux_sel = CMN_PLLLC,
428 .table = { 0, 1 },
429 .node_name = "pll_cmnlc",
430 },
431 {
432 .num_parents = 2,
433 .parents = { PLL1_REFCLK, PLL0_REFCLK },
434 .mux_sel = CMN_PLLLC1,
435 .table = { 1, 0 },
436 .node_name = "pll_cmnlc1",
437 },
438};
439
440static int cdns_sierra_pll_mux_set_parent(struct clk *clk, struct clk *parent)
441{
442 struct udevice *dev = clk->dev;
443 struct cdns_sierra_pll_mux *priv = dev_get_priv(dev);
444 struct cdns_sierra_pll_mux_sel *data = dev_get_plat(dev);
445 struct cdns_sierra_phy *sp = priv->sp;
446 int ret;
447 int i;
448
449 for (i = 0; i < ARRAY_SIZE(priv->parent_clks); i++) {
450 if (parent->dev == priv->parent_clks[i]->dev)
451 break;
452 }
453
454 if (i == ARRAY_SIZE(priv->parent_clks))
455 return -EINVAL;
456
457 ret = regmap_field_write(sp->cmn_refrcv_refclk_plllc1en_preg[data[clk->id].mux_sel], i);
458 ret |= regmap_field_write(sp->cmn_refrcv_refclk_termen_preg[data[clk->id].mux_sel], i);
459 ret |= regmap_field_write(sp->cmn_plllc_pfdclk1_sel_preg[data[clk->id].mux_sel],
460 data[clk->id].table[i]);
461
462 return ret;
463}
464
465static const struct clk_ops cdns_sierra_pll_mux_ops = {
466 .set_parent = cdns_sierra_pll_mux_set_parent,
467};
468
469int cdns_sierra_pll_mux_probe(struct udevice *dev)
470{
471 struct cdns_sierra_pll_mux *priv = dev_get_priv(dev);
472 struct cdns_sierra_phy *sp = dev_get_priv(dev->parent);
473 struct cdns_sierra_pll_mux_sel *data = dev_get_plat(dev);
474 struct clk *clk;
475 int i, j;
476
477 for (j = 0; j < SIERRA_NUM_CMN_PLLC; j++) {
478 for (i = 0; i < ARRAY_SIZE(priv->parent_clks); i++) {
479 clk = sp->input_clks[data[j].parents[i]];
480 if (IS_ERR_OR_NULL(clk)) {
481 dev_err(dev, "No parent clock for PLL mux clocks\n");
482 return IS_ERR(clk) ? PTR_ERR(clk) : -ENOENT;
483 }
484 priv->parent_clks[i] = clk;
485 }
486 }
487
488 priv->sp = dev_get_priv(dev->parent);
489
490 return 0;
491}
492
493U_BOOT_DRIVER(cdns_sierra_pll_mux_clk) = {
494 .name = "cdns_sierra_mux_clk",
495 .id = UCLASS_CLK,
496 .priv_auto = sizeof(struct cdns_sierra_pll_mux),
497 .ops = &cdns_sierra_pll_mux_ops,
498 .probe = cdns_sierra_pll_mux_probe,
499 .plat_auto = sizeof(struct cdns_sierra_pll_mux_sel) * SIERRA_NUM_CMN_PLLC,
500};
501
502static int cdns_sierra_pll_bind_of_clocks(struct cdns_sierra_phy *sp)
503{
504 struct udevice *dev = sp->dev;
505 struct driver *cdns_sierra_clk_drv;
506 struct cdns_sierra_pll_mux_sel *data = pll_clk_mux_sel;
507 int i, rc;
508
509 cdns_sierra_clk_drv = lists_driver_lookup_name("cdns_sierra_mux_clk");
510 if (!cdns_sierra_clk_drv) {
511 dev_err(dev, "Can not find driver 'cdns_sierra_mux_clk'\n");
512 return -ENOENT;
513 }
514
515 rc = device_bind(dev, cdns_sierra_clk_drv, "pll_mux_clk",
516 data, dev_ofnode(dev), NULL);
517 if (rc) {
518 dev_err(dev, "cannot bind driver for clock %s\n",
519 clk_names[i]);
520 }
521
522 return 0;
523}
524
Alan Douglasfda76da2021-07-21 21:28:36 +0530525static int cdns_sierra_get_optional(struct cdns_sierra_inst *inst,
526 ofnode child)
527{
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530528 u32 phy_type;
529
Alan Douglasfda76da2021-07-21 21:28:36 +0530530 if (ofnode_read_u32(child, "reg", &inst->mlane))
531 return -EINVAL;
532
533 if (ofnode_read_u32(child, "cdns,num-lanes", &inst->num_lanes))
534 return -EINVAL;
535
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530536 if (ofnode_read_u32(child, "cdns,phy-type", &phy_type))
Alan Douglasfda76da2021-07-21 21:28:36 +0530537 return -EINVAL;
538
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530539 switch (phy_type) {
540 case PHY_TYPE_PCIE:
541 inst->phy_type = TYPE_PCIE;
542 break;
543 case PHY_TYPE_USB3:
544 inst->phy_type = TYPE_USB;
545 break;
546 default:
547 return -EINVAL;
548 }
549
Swapnil Jakhade0d372ea2022-01-28 13:41:42 +0530550 inst->ssc_mode = EXTERNAL_SSC;
551 ofnode_read_u32(child, "cdns,ssc-mode", &inst->ssc_mode);
552
Alan Douglasfda76da2021-07-21 21:28:36 +0530553 return 0;
554}
555
556static struct regmap *cdns_regmap_init(struct udevice *dev, void __iomem *base,
557 u32 block_offset, u8 block_offset_shift,
558 u8 reg_offset_shift)
559{
560 struct cdns_sierra_phy *sp = dev_get_priv(dev);
561 struct regmap_config config;
562
563 config.r_start = (ulong)(base + (block_offset << block_offset_shift));
564 config.r_size = sp->size - (block_offset << block_offset_shift);
565 config.reg_offset_shift = reg_offset_shift;
566 config.width = REGMAP_SIZE_16;
567
568 return devm_regmap_init(dev, NULL, NULL, &config);
569}
570
571static int cdns_regfield_init(struct cdns_sierra_phy *sp)
572{
573 struct udevice *dev = sp->dev;
574 struct regmap_field *field;
Aswath Govindraju304341f2022-01-28 13:41:36 +0530575 struct reg_field reg_field;
Alan Douglasfda76da2021-07-21 21:28:36 +0530576 struct regmap *regmap;
577 int i;
578
579 regmap = sp->regmap_common_cdb;
580 field = devm_regmap_field_alloc(dev, regmap, macro_id_type);
581 if (IS_ERR(field)) {
582 dev_err(dev, "MACRO_ID_TYPE reg field init failed\n");
583 return PTR_ERR(field);
584 }
585 sp->macro_id_type = field;
586
Aswath Govindraju304341f2022-01-28 13:41:36 +0530587 for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++) {
588 reg_field = cmn_plllc_pfdclk1_sel_preg[i].pfdclk_sel_preg;
589 field = devm_regmap_field_alloc(dev, regmap, reg_field);
590 if (IS_ERR(field)) {
591 dev_err(dev, "PLLLC%d_PFDCLK1_SEL failed\n", i);
592 return PTR_ERR(field);
593 }
594 sp->cmn_plllc_pfdclk1_sel_preg[i] = field;
595
596 reg_field = cmn_plllc_pfdclk1_sel_preg[i].plllc1en_field;
597 field = devm_regmap_field_alloc(dev, regmap, reg_field);
598 if (IS_ERR(field)) {
599 dev_err(dev, "REFRCV%d_REFCLK_PLLLC1EN failed\n", i);
600 return PTR_ERR(field);
601 }
602 sp->cmn_refrcv_refclk_plllc1en_preg[i] = field;
603
604 reg_field = cmn_plllc_pfdclk1_sel_preg[i].termen_field;
605 field = devm_regmap_field_alloc(dev, regmap, reg_field);
606 if (IS_ERR(field)) {
607 dev_err(dev, "REFRCV%d_REFCLK_TERMEN failed\n", i);
608 return PTR_ERR(field);
609 }
610 sp->cmn_refrcv_refclk_termen_preg[i] = field;
611 }
612
Alan Douglasfda76da2021-07-21 21:28:36 +0530613 regmap = sp->regmap_phy_config_ctrl;
614 field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1);
615 if (IS_ERR(field)) {
616 dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n");
617 return PTR_ERR(field);
618 }
619 sp->phy_pll_cfg_1 = field;
620
621 for (i = 0; i < SIERRA_MAX_LANES; i++) {
622 regmap = sp->regmap_lane_cdb[i];
623 field = devm_regmap_field_alloc(dev, regmap, pllctrl_lock);
624 if (IS_ERR(field)) {
625 dev_err(dev, "P%d_ENABLE reg field init failed\n", i);
626 return PTR_ERR(field);
627 }
628 sp->pllctrl_lock[i] = field;
629 }
630
631 return 0;
632}
633
634static int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp,
635 void __iomem *base, u8 block_offset_shift,
636 u8 reg_offset_shift)
637{
638 struct udevice *dev = sp->dev;
639 struct regmap *regmap;
640 u32 block_offset;
641 int i;
642
643 for (i = 0; i < SIERRA_MAX_LANES; i++) {
644 block_offset = SIERRA_LANE_CDB_OFFSET(i, reg_offset_shift);
645 regmap = cdns_regmap_init(dev, base, block_offset,
646 block_offset_shift, reg_offset_shift);
647 if (IS_ERR(regmap)) {
648 dev_err(dev, "Failed to init lane CDB regmap\n");
649 return PTR_ERR(regmap);
650 }
651 sp->regmap_lane_cdb[i] = regmap;
652 }
653
654 regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET,
655 block_offset_shift, reg_offset_shift);
656 if (IS_ERR(regmap)) {
657 dev_err(dev, "Failed to init common CDB regmap\n");
658 return PTR_ERR(regmap);
659 }
660 sp->regmap_common_cdb = regmap;
661
662 regmap = cdns_regmap_init(dev, base, SIERRA_PHY_CONFIG_CTRL_OFFSET,
663 block_offset_shift, reg_offset_shift);
664 if (IS_ERR(regmap)) {
665 dev_err(dev, "Failed to init PHY config and control regmap\n");
666 return PTR_ERR(regmap);
667 }
668 sp->regmap_phy_config_ctrl = regmap;
669
670 return 0;
671}
672
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530673static int cdns_sierra_phy_get_clocks(struct cdns_sierra_phy *sp,
674 struct udevice *dev)
675{
676 struct clk *clk;
677 int ret;
678
679 clk = devm_clk_get_optional(dev, "phy_clk");
680 if (IS_ERR(clk)) {
681 dev_err(dev, "failed to get clock phy_clk\n");
682 return PTR_ERR(clk);
683 }
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530684 sp->input_clks[PHY_CLK] = clk;
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530685
686 clk = devm_clk_get_optional(dev, "cmn_refclk_dig_div");
687 if (IS_ERR(clk)) {
688 dev_err(dev, "cmn_refclk_dig_div clock not found\n");
689 ret = PTR_ERR(clk);
690 return ret;
691 }
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530692 sp->input_clks[CMN_REFCLK_DIG_DIV] = clk;
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530693
694 clk = devm_clk_get_optional(dev, "cmn_refclk1_dig_div");
695 if (IS_ERR(clk)) {
696 dev_err(dev, "cmn_refclk1_dig_div clock not found\n");
697 ret = PTR_ERR(clk);
698 return ret;
699 }
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530700 sp->input_clks[CMN_REFCLK1_DIG_DIV] = clk;
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530701
Aswath Govindraju304341f2022-01-28 13:41:36 +0530702 clk = devm_clk_get_optional(dev, "pll0_refclk");
703 if (IS_ERR(clk)) {
704 dev_err(dev, "pll0_refclk clock not found\n");
705 ret = PTR_ERR(clk);
706 return ret;
707 }
708 sp->input_clks[PLL0_REFCLK] = clk;
709
710 clk = devm_clk_get_optional(dev, "pll1_refclk");
711 if (IS_ERR(clk)) {
712 dev_err(dev, "pll1_refclk clock not found\n");
713 ret = PTR_ERR(clk);
714 return ret;
715 }
716 sp->input_clks[PLL1_REFCLK] = clk;
717
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530718 return 0;
719}
720
Kishon Vijay Abraham I12fbc5c2022-01-28 13:41:32 +0530721static int cdns_sierra_phy_get_resets(struct cdns_sierra_phy *sp,
722 struct udevice *dev)
723{
724 struct reset_control *rst;
725
726 rst = devm_reset_control_get(dev, "sierra_reset");
727 if (IS_ERR(rst)) {
728 dev_err(dev, "failed to get reset\n");
729 return PTR_ERR(rst);
730 }
731 sp->phy_rst = rst;
732
733 return 0;
734}
735
Aswath Govindraju11fcd0e2022-01-28 13:41:35 +0530736static int cdns_sierra_bind_link_nodes(struct cdns_sierra_phy *sp)
737{
738 struct udevice *dev = sp->dev;
739 struct driver *link_drv;
740 ofnode child;
741 int rc;
742
743 link_drv = lists_driver_lookup_name("sierra_phy_link");
744 if (!link_drv) {
745 dev_err(dev, "Cannot find driver 'sierra_phy_link'\n");
746 return -ENOENT;
747 }
748
749 ofnode_for_each_subnode(child, dev_ofnode(dev)) {
750 if (!(ofnode_name_eq(child, "phy") ||
751 ofnode_name_eq(child, "link")))
752 continue;
753
754 rc = device_bind(dev, link_drv, "link", NULL, child, NULL);
755 if (rc) {
756 dev_err(dev, "cannot bind driver for link\n");
757 return rc;
758 }
759 }
760
761 return 0;
762}
763
764static int cdns_sierra_link_probe(struct udevice *dev)
765{
766 struct cdns_sierra_inst *inst = dev_get_priv(dev);
767 struct cdns_sierra_phy *sp = dev_get_priv(dev->parent);
768 struct reset_ctl_bulk *rst;
769 int ret, node;
770
771 rst = devm_reset_bulk_get_by_node(dev, dev_ofnode(dev));
772 if (IS_ERR(rst)) {
773 ret = PTR_ERR(rst);
774 dev_err(dev, "failed to get reset\n");
775 return ret;
776 }
777 inst->lnk_rst = rst;
778
779 ret = cdns_sierra_get_optional(inst, dev_ofnode(dev));
780 if (ret) {
781 dev_err(dev, "missing property in node\n");
782 return ret;
783 }
784 node = sp->nsubnodes;
785 sp->phys[node] = inst;
786 sp->nsubnodes += 1;
787 sp->num_lanes += inst->num_lanes;
788
789 /* If more than one subnode, configure the PHY as multilink */
790 if (!sp->autoconf && sp->nsubnodes > 1)
791 regmap_field_write(sp->phy_pll_cfg_1, 0x1);
792
793 return 0;
794}
795
796U_BOOT_DRIVER(sierra_phy_link) = {
797 .name = "sierra_phy_link",
798 .id = UCLASS_PHY,
799 .probe = cdns_sierra_link_probe,
800 .priv_auto = sizeof(struct cdns_sierra_inst),
801};
802
Alan Douglasfda76da2021-07-21 21:28:36 +0530803static int cdns_sierra_phy_probe(struct udevice *dev)
804{
805 struct cdns_sierra_phy *sp = dev_get_priv(dev);
806 struct cdns_sierra_data *data;
807 unsigned int id_value;
Aswath Govindraju304341f2022-01-28 13:41:36 +0530808 int ret;
Alan Douglasfda76da2021-07-21 21:28:36 +0530809
810 sp->dev = dev;
811
812 sp->base = devfdt_remap_addr_index(dev, 0);
813 if (!sp->base) {
814 dev_err(dev, "unable to map regs\n");
815 return -ENOMEM;
816 }
817 devfdt_get_addr_size_index(dev, 0, (fdt_size_t *)&sp->size);
818
819 /* Get init data for this PHY */
820 data = (struct cdns_sierra_data *)dev_get_driver_data(dev);
821 sp->init_data = data;
822
823 ret = cdns_regmap_init_blocks(sp, sp->base, data->block_offset_shift,
824 data->reg_offset_shift);
825 if (ret)
826 return ret;
827
828 ret = cdns_regfield_init(sp);
829 if (ret)
830 return ret;
831
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530832 ret = cdns_sierra_phy_get_clocks(sp, dev);
833 if (ret)
834 return ret;
Alan Douglasfda76da2021-07-21 21:28:36 +0530835
Aswath Govindraju304341f2022-01-28 13:41:36 +0530836 ret = cdns_sierra_pll_bind_of_clocks(sp);
837 if (ret)
838 return ret;
Alan Douglasfda76da2021-07-21 21:28:36 +0530839
Kishon Vijay Abraham I12fbc5c2022-01-28 13:41:32 +0530840 ret = cdns_sierra_phy_get_resets(sp, dev);
841 if (ret)
842 return ret;
843
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530844 ret = clk_prepare_enable(sp->input_clks[PHY_CLK]);
Alan Douglasfda76da2021-07-21 21:28:36 +0530845 if (ret)
846 return ret;
847
848 /* Check that PHY is present */
849 regmap_field_read(sp->macro_id_type, &id_value);
850 if (sp->init_data->id_value != id_value) {
851 dev_err(dev, "PHY not found 0x%x vs 0x%x\n",
852 sp->init_data->id_value, id_value);
853 ret = -EINVAL;
854 goto clk_disable;
855 }
856
857 sp->autoconf = dev_read_bool(dev, "cdns,autoconf");
Aswath Govindraju11fcd0e2022-01-28 13:41:35 +0530858 /* Binding link nodes as children to serdes */
859 ret = cdns_sierra_bind_link_nodes(sp);
860 if (ret)
861 goto clk_disable;
Alan Douglasfda76da2021-07-21 21:28:36 +0530862
Alan Douglasfda76da2021-07-21 21:28:36 +0530863 dev_info(dev, "sierra probed\n");
864 return 0;
865
Alan Douglasfda76da2021-07-21 21:28:36 +0530866clk_disable:
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530867 clk_disable_unprepare(sp->input_clks[PHY_CLK]);
Alan Douglasfda76da2021-07-21 21:28:36 +0530868 return ret;
869}
870
871static int cdns_sierra_phy_remove(struct udevice *dev)
872{
873 struct cdns_sierra_phy *phy = dev_get_priv(dev);
874 int i;
875
876 reset_control_assert(phy->phy_rst);
877
878 /*
879 * The device level resets will be put automatically.
880 * Need to put the subnode resets here though.
881 */
882 for (i = 0; i < phy->nsubnodes; i++)
Aswath Govindraju11fcd0e2022-01-28 13:41:35 +0530883 reset_assert_bulk(phy->phys[i]->lnk_rst);
Alan Douglasfda76da2021-07-21 21:28:36 +0530884
Kishon Vijay Abraham I25f8b372022-01-28 13:41:34 +0530885 clk_disable_unprepare(phy->input_clks[PHY_CLK]);
886
Alan Douglasfda76da2021-07-21 21:28:36 +0530887 return 0;
888}
889
890/* refclk100MHz_32b_PCIe_cmn_pll_ext_ssc */
891static struct cdns_reg_pairs cdns_pcie_cmn_regs_ext_ssc[] = {
892 {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
893 {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
894 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
895 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
896 {0x1B1B, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
897};
898
899/* refclk100MHz_32b_PCIe_ln_ext_ssc */
900static struct cdns_reg_pairs cdns_pcie_ln_regs_ext_ssc[] = {
901 {0x813E, SIERRA_CLKPATHCTRL_TMR_PREG},
902 {0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
903 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
904 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
905 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
906 {0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
907 {0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG}
908};
909
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530910static struct cdns_sierra_vals pcie_100_ext_ssc_cmn_vals = {
911 .reg_pairs = cdns_pcie_cmn_regs_ext_ssc,
912 .num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc),
913};
914
915static struct cdns_sierra_vals pcie_100_ext_ssc_ln_vals = {
916 .reg_pairs = cdns_pcie_ln_regs_ext_ssc,
917 .num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc),
918};
919
Alan Douglasfda76da2021-07-21 21:28:36 +0530920/* refclk100MHz_20b_USB_cmn_pll_ext_ssc */
921static struct cdns_reg_pairs cdns_usb_cmn_regs_ext_ssc[] = {
922 {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
923 {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
924 {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
925 {0x0000, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
926};
927
928/* refclk100MHz_20b_USB_ln_ext_ssc */
929static struct cdns_reg_pairs cdns_usb_ln_regs_ext_ssc[] = {
930 {0xFE0A, SIERRA_DET_STANDEC_A_PREG},
931 {0x000F, SIERRA_DET_STANDEC_B_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530932 {0x55A5, SIERRA_DET_STANDEC_C_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530933 {0x69ad, SIERRA_DET_STANDEC_D_PREG},
934 {0x0241, SIERRA_DET_STANDEC_E_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530935 {0x0110, SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530936 {0x0014, SIERRA_PSM_A0IN_TMR_PREG},
937 {0xCF00, SIERRA_PSM_DIAG_PREG},
938 {0x001F, SIERRA_PSC_TX_A0_PREG},
939 {0x0007, SIERRA_PSC_TX_A1_PREG},
940 {0x0003, SIERRA_PSC_TX_A2_PREG},
941 {0x0003, SIERRA_PSC_TX_A3_PREG},
942 {0x0FFF, SIERRA_PSC_RX_A0_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530943 {0x0003, SIERRA_PSC_RX_A1_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530944 {0x0003, SIERRA_PSC_RX_A2_PREG},
945 {0x0001, SIERRA_PSC_RX_A3_PREG},
946 {0x0001, SIERRA_PLLCTRL_SUBRATE_PREG},
947 {0x0406, SIERRA_PLLCTRL_GEN_D_PREG},
948 {0x5233, SIERRA_PLLCTRL_CPGAIN_MODE_PREG},
949 {0x00CA, SIERRA_CLKPATH_BIASTRIM_PREG},
950 {0x2512, SIERRA_DFE_BIASTRIM_PREG},
951 {0x0000, SIERRA_DRVCTRL_ATTEN_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530952 {0x823E, SIERRA_CLKPATHCTRL_TMR_PREG},
953 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
954 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530955 {0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530956 {0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530957 {0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG},
958 {0x0000, SIERRA_CREQ_EQ_CTRL_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530959 {0x0000, SIERRA_CREQ_SPARE_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530960 {0xCC44, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530961 {0x8452, SIERRA_CTLELUT_CTRL_PREG},
962 {0x4121, SIERRA_DFE_ECMP_RATESEL_PREG},
963 {0x4121, SIERRA_DFE_SMP_RATESEL_PREG},
964 {0x0003, SIERRA_DEQ_PHALIGN_CTRL},
Alan Douglasfda76da2021-07-21 21:28:36 +0530965 {0x3200, SIERRA_DEQ_CONCUR_CTRL1_PREG},
966 {0x5064, SIERRA_DEQ_CONCUR_CTRL2_PREG},
967 {0x0030, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
968 {0x0048, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
969 {0x5A5A, SIERRA_DEQ_ERRCMP_CTRL_PREG},
970 {0x02F5, SIERRA_DEQ_OFFSET_CTRL_PREG},
971 {0x02F5, SIERRA_DEQ_GAIN_CTRL_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530972 {0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530973 {0x0014, SIERRA_DEQ_GLUT0},
974 {0x0014, SIERRA_DEQ_GLUT1},
975 {0x0014, SIERRA_DEQ_GLUT2},
976 {0x0014, SIERRA_DEQ_GLUT3},
977 {0x0014, SIERRA_DEQ_GLUT4},
978 {0x0014, SIERRA_DEQ_GLUT5},
979 {0x0014, SIERRA_DEQ_GLUT6},
980 {0x0014, SIERRA_DEQ_GLUT7},
981 {0x0014, SIERRA_DEQ_GLUT8},
982 {0x0014, SIERRA_DEQ_GLUT9},
983 {0x0014, SIERRA_DEQ_GLUT10},
984 {0x0014, SIERRA_DEQ_GLUT11},
985 {0x0014, SIERRA_DEQ_GLUT12},
986 {0x0014, SIERRA_DEQ_GLUT13},
987 {0x0014, SIERRA_DEQ_GLUT14},
988 {0x0014, SIERRA_DEQ_GLUT15},
989 {0x0014, SIERRA_DEQ_GLUT16},
990 {0x0BAE, SIERRA_DEQ_ALUT0},
991 {0x0AEB, SIERRA_DEQ_ALUT1},
992 {0x0A28, SIERRA_DEQ_ALUT2},
993 {0x0965, SIERRA_DEQ_ALUT3},
994 {0x08A2, SIERRA_DEQ_ALUT4},
995 {0x07DF, SIERRA_DEQ_ALUT5},
996 {0x071C, SIERRA_DEQ_ALUT6},
997 {0x0659, SIERRA_DEQ_ALUT7},
998 {0x0596, SIERRA_DEQ_ALUT8},
999 {0x0514, SIERRA_DEQ_ALUT9},
1000 {0x0492, SIERRA_DEQ_ALUT10},
1001 {0x0410, SIERRA_DEQ_ALUT11},
1002 {0x038E, SIERRA_DEQ_ALUT12},
1003 {0x030C, SIERRA_DEQ_ALUT13},
1004 {0x03F4, SIERRA_DEQ_DFETAP_CTRL_PREG},
1005 {0x0001, SIERRA_DFE_EN_1010_IGNORE_PREG},
1006 {0x3C01, SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG},
1007 {0x3C40, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1008 {0x1C08, SIERRA_DEQ_TAU_CTRL2_PREG},
1009 {0x0033, SIERRA_DEQ_PICTRL_PREG},
1010 {0x0400, SIERRA_CPICAL_TMRVAL_MODE1_PREG},
1011 {0x0330, SIERRA_CPICAL_TMRVAL_MODE0_PREG},
1012 {0x01FF, SIERRA_CPICAL_PICNT_MODE1_PREG},
1013 {0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG},
1014 {0x3232, SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG},
1015 {0x0005, SIERRA_LFPSDET_SUPPORT_PREG},
1016 {0x000F, SIERRA_LFPSFILT_NS_PREG},
1017 {0x0009, SIERRA_LFPSFILT_RD_PREG},
1018 {0x0001, SIERRA_LFPSFILT_MP_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +05301019 {0x6013, SIERRA_SIGDET_SUPPORT_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +05301020 {0x8013, SIERRA_SDFILT_H2L_A_PREG},
1021 {0x8009, SIERRA_SDFILT_L2H_PREG},
1022 {0x0024, SIERRA_RXBUFFER_CTLECTRL_PREG},
1023 {0x0020, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1024 {0x4243, SIERRA_RXBUFFER_DFECTRL_PREG}
1025};
1026
Swapnil Jakhadee42a8472022-01-28 13:41:40 +05301027static struct cdns_sierra_vals usb_100_ext_ssc_cmn_vals = {
1028 .reg_pairs = cdns_usb_cmn_regs_ext_ssc,
1029 .num_regs = ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc),
1030};
1031
1032static struct cdns_sierra_vals usb_100_ext_ssc_ln_vals = {
1033 .reg_pairs = cdns_usb_ln_regs_ext_ssc,
1034 .num_regs = ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc),
1035};
1036
Alan Douglasfda76da2021-07-21 21:28:36 +05301037static const struct cdns_sierra_data cdns_map_sierra = {
Swapnil Jakhadee42a8472022-01-28 13:41:40 +05301038 .id_value = SIERRA_MACRO_ID,
1039 .block_offset_shift = 0x2,
1040 .reg_offset_shift = 0x2,
1041 .pma_cmn_vals = {
1042 [TYPE_PCIE] = {
1043 [TYPE_NONE] = {
1044 [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
1045 },
1046 },
1047 [TYPE_USB] = {
1048 [TYPE_NONE] = {
1049 [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1050 },
1051 },
1052 },
1053 .pma_ln_vals = {
1054 [TYPE_PCIE] = {
1055 [TYPE_NONE] = {
1056 [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
1057 },
1058 },
1059 [TYPE_USB] = {
1060 [TYPE_NONE] = {
1061 [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1062 },
1063 },
1064 },
Alan Douglasfda76da2021-07-21 21:28:36 +05301065};
1066
1067static const struct cdns_sierra_data cdns_ti_map_sierra = {
Swapnil Jakhadee42a8472022-01-28 13:41:40 +05301068 .id_value = SIERRA_MACRO_ID,
1069 .block_offset_shift = 0x0,
1070 .reg_offset_shift = 0x1,
1071 .pma_cmn_vals = {
1072 [TYPE_PCIE] = {
1073 [TYPE_NONE] = {
1074 [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
1075 },
1076 },
1077 [TYPE_USB] = {
1078 [TYPE_NONE] = {
1079 [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1080 },
1081 },
1082 },
1083 .pma_ln_vals = {
1084 [TYPE_PCIE] = {
1085 [TYPE_NONE] = {
1086 [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
1087 },
1088 },
1089 [TYPE_USB] = {
1090 [TYPE_NONE] = {
1091 [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1092 },
1093 },
1094 },
Alan Douglasfda76da2021-07-21 21:28:36 +05301095};
1096
1097static const struct udevice_id cdns_sierra_id_table[] = {
1098 {
1099 .compatible = "cdns,sierra-phy-t0",
1100 .data = (ulong)&cdns_map_sierra,
1101 },
1102 {
1103 .compatible = "ti,sierra-phy-t0",
1104 .data = (ulong)&cdns_ti_map_sierra,
1105 },
1106 {}
1107};
1108
1109U_BOOT_DRIVER(sierra_phy_provider) = {
1110 .name = "cdns,sierra",
1111 .id = UCLASS_PHY,
1112 .of_match = cdns_sierra_id_table,
1113 .probe = cdns_sierra_phy_probe,
1114 .remove = cdns_sierra_phy_remove,
1115 .ops = &ops,
1116 .priv_auto = sizeof(struct cdns_sierra_phy),
1117};