blob: 745c34088a5b740ddbe17416d9168cc2bcbf4cf2 [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;
237};
238
239struct cdns_reg_pairs {
240 u16 val;
241 u32 off;
242};
243
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530244struct cdns_sierra_vals {
245 const struct cdns_reg_pairs *reg_pairs;
246 u32 num_regs;
247};
248
Alan Douglasfda76da2021-07-21 21:28:36 +0530249struct cdns_sierra_data {
250 u32 id_value;
251 u8 block_offset_shift;
252 u8 reg_offset_shift;
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530253 struct cdns_sierra_vals *pma_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
254 [NUM_SSC_MODE];
255 struct cdns_sierra_vals *pma_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
256 [NUM_SSC_MODE];
Alan Douglasfda76da2021-07-21 21:28:36 +0530257};
258
Alan Douglasfda76da2021-07-21 21:28:36 +0530259struct cdns_sierra_phy {
260 struct udevice *dev;
261 void *base;
262 size_t size;
263 struct regmap *regmap;
264 struct cdns_sierra_data *init_data;
Aswath Govindraju11fcd0e2022-01-28 13:41:35 +0530265 struct cdns_sierra_inst *phys[SIERRA_MAX_LANES];
Alan Douglasfda76da2021-07-21 21:28:36 +0530266 struct reset_control *phy_rst;
267 struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES];
268 struct regmap *regmap_phy_config_ctrl;
269 struct regmap *regmap_common_cdb;
270 struct regmap_field *macro_id_type;
271 struct regmap_field *phy_pll_cfg_1;
272 struct regmap_field *pllctrl_lock[SIERRA_MAX_LANES];
Aswath Govindraju304341f2022-01-28 13:41:36 +0530273 struct regmap_field *cmn_refrcv_refclk_plllc1en_preg[SIERRA_NUM_CMN_PLLC];
274 struct regmap_field *cmn_refrcv_refclk_termen_preg[SIERRA_NUM_CMN_PLLC];
275 struct regmap_field *cmn_plllc_pfdclk1_sel_preg[SIERRA_NUM_CMN_PLLC];
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530276 struct clk *input_clks[CDNS_SIERRA_INPUT_CLOCKS];
Alan Douglasfda76da2021-07-21 21:28:36 +0530277 int nsubnodes;
278 u32 num_lanes;
279 bool autoconf;
280};
281
282static inline int cdns_reset_assert(struct reset_control *rst)
283{
284 if (rst)
285 return reset_assert(rst);
286 else
287 return 0;
288}
289
290static inline int cdns_reset_deassert(struct reset_control *rst)
291{
292 if (rst)
293 return reset_deassert(rst);
294 else
295 return 0;
296}
297
298static inline struct cdns_sierra_inst *phy_get_drvdata(struct phy *phy)
299{
300 struct cdns_sierra_phy *sp = dev_get_priv(phy->dev);
301 int index;
302
303 if (phy->id >= SIERRA_MAX_LANES)
304 return NULL;
305
306 for (index = 0; index < sp->nsubnodes; index++) {
Aswath Govindraju11fcd0e2022-01-28 13:41:35 +0530307 if (phy->id == sp->phys[index]->mlane)
308 return sp->phys[index];
Alan Douglasfda76da2021-07-21 21:28:36 +0530309 }
310
311 return NULL;
312}
313
314static int cdns_sierra_phy_init(struct phy *gphy)
315{
316 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
317 struct cdns_sierra_phy *phy = dev_get_priv(gphy->dev);
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530318 struct cdns_sierra_data *init_data = phy->init_data;
319 struct cdns_sierra_vals *pma_cmn_vals, *pma_ln_vals;
320 enum cdns_sierra_phy_type phy_type = ins->phy_type;
321 enum cdns_sierra_ssc_mode ssc = EXTERNAL_SSC;
322 const struct cdns_reg_pairs *reg_pairs;
Alan Douglasfda76da2021-07-21 21:28:36 +0530323 struct regmap *regmap = phy->regmap;
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530324 u32 num_regs;
Alan Douglasfda76da2021-07-21 21:28:36 +0530325 int i, j;
Alan Douglasfda76da2021-07-21 21:28:36 +0530326
327 /* Initialise the PHY registers, unless auto configured */
328 if (phy->autoconf)
329 return 0;
330
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530331 clk_set_rate(phy->input_clks[CMN_REFCLK_DIG_DIV], 25000000);
332 clk_set_rate(phy->input_clks[CMN_REFCLK1_DIG_DIV], 25000000);
Alan Douglasfda76da2021-07-21 21:28:36 +0530333
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530334 /* PMA common registers configurations */
335 pma_cmn_vals = init_data->pma_cmn_vals[phy_type][TYPE_NONE][ssc];
336 if (pma_cmn_vals) {
337 reg_pairs = pma_cmn_vals->reg_pairs;
338 num_regs = pma_cmn_vals->num_regs;
339 regmap = phy->regmap_common_cdb;
340 for (i = 0; i < num_regs; i++)
341 regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
Alan Douglasfda76da2021-07-21 21:28:36 +0530342 }
343
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530344 /* PMA TX lane registers configurations */
345 pma_ln_vals = init_data->pma_ln_vals[phy_type][TYPE_NONE][ssc];
346 if (pma_ln_vals) {
347 reg_pairs = pma_ln_vals->reg_pairs;
348 num_regs = pma_ln_vals->num_regs;
349 for (i = 0; i < ins->num_lanes; i++) {
Alan Douglasfda76da2021-07-21 21:28:36 +0530350 regmap = phy->regmap_lane_cdb[i + ins->mlane];
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530351 for (j = 0; j < num_regs; j++)
352 regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val);
Alan Douglasfda76da2021-07-21 21:28:36 +0530353 }
354 }
355
356 return 0;
357}
358
359static int cdns_sierra_phy_on(struct phy *gphy)
360{
361 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
362 struct cdns_sierra_phy *sp = dev_get_priv(gphy->dev);
363 struct udevice *dev = gphy->dev;
364 u32 val;
365 int ret;
366
Kishon Vijay Abraham I1ff2b712022-01-28 13:41:29 +0530367 ret = reset_control_deassert(sp->phy_rst);
368 if (ret) {
369 dev_err(dev, "Failed to take the PHY out of reset\n");
370 return ret;
371 }
372
Alan Douglasfda76da2021-07-21 21:28:36 +0530373 /* Take the PHY lane group out of reset */
374 ret = reset_deassert_bulk(ins->lnk_rst);
375 if (ret) {
376 dev_err(dev, "Failed to take the PHY lane out of reset\n");
377 return ret;
378 }
379
380 ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane],
381 val, val, 1000, PLL_LOCK_TIME);
382 if (ret < 0)
383 dev_err(dev, "PLL lock of lane failed\n");
384
385 reset_control_assert(sp->phy_rst);
386 reset_control_deassert(sp->phy_rst);
387
388 return ret;
389}
390
391static int cdns_sierra_phy_off(struct phy *gphy)
392{
393 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
394
395 return reset_assert_bulk(ins->lnk_rst);
396}
397
398static int cdns_sierra_phy_reset(struct phy *gphy)
399{
400 struct cdns_sierra_phy *sp = dev_get_priv(gphy->dev);
401
402 reset_control_assert(sp->phy_rst);
403 reset_control_deassert(sp->phy_rst);
404 return 0;
405};
406
407static const struct phy_ops ops = {
408 .init = cdns_sierra_phy_init,
409 .power_on = cdns_sierra_phy_on,
410 .power_off = cdns_sierra_phy_off,
411 .reset = cdns_sierra_phy_reset,
412};
413
Aswath Govindraju304341f2022-01-28 13:41:36 +0530414struct cdns_sierra_pll_mux_sel {
415 enum cdns_sierra_cmn_plllc mux_sel;
416 u32 table[2];
417 const char *node_name;
418 u32 num_parents;
419 u32 parents[2];
420};
421
422static struct cdns_sierra_pll_mux_sel pll_clk_mux_sel[] = {
423 {
424 .num_parents = 2,
425 .parents = { PLL0_REFCLK, PLL1_REFCLK },
426 .mux_sel = CMN_PLLLC,
427 .table = { 0, 1 },
428 .node_name = "pll_cmnlc",
429 },
430 {
431 .num_parents = 2,
432 .parents = { PLL1_REFCLK, PLL0_REFCLK },
433 .mux_sel = CMN_PLLLC1,
434 .table = { 1, 0 },
435 .node_name = "pll_cmnlc1",
436 },
437};
438
439static int cdns_sierra_pll_mux_set_parent(struct clk *clk, struct clk *parent)
440{
441 struct udevice *dev = clk->dev;
442 struct cdns_sierra_pll_mux *priv = dev_get_priv(dev);
443 struct cdns_sierra_pll_mux_sel *data = dev_get_plat(dev);
444 struct cdns_sierra_phy *sp = priv->sp;
445 int ret;
446 int i;
447
448 for (i = 0; i < ARRAY_SIZE(priv->parent_clks); i++) {
449 if (parent->dev == priv->parent_clks[i]->dev)
450 break;
451 }
452
453 if (i == ARRAY_SIZE(priv->parent_clks))
454 return -EINVAL;
455
456 ret = regmap_field_write(sp->cmn_refrcv_refclk_plllc1en_preg[data[clk->id].mux_sel], i);
457 ret |= regmap_field_write(sp->cmn_refrcv_refclk_termen_preg[data[clk->id].mux_sel], i);
458 ret |= regmap_field_write(sp->cmn_plllc_pfdclk1_sel_preg[data[clk->id].mux_sel],
459 data[clk->id].table[i]);
460
461 return ret;
462}
463
464static const struct clk_ops cdns_sierra_pll_mux_ops = {
465 .set_parent = cdns_sierra_pll_mux_set_parent,
466};
467
468int cdns_sierra_pll_mux_probe(struct udevice *dev)
469{
470 struct cdns_sierra_pll_mux *priv = dev_get_priv(dev);
471 struct cdns_sierra_phy *sp = dev_get_priv(dev->parent);
472 struct cdns_sierra_pll_mux_sel *data = dev_get_plat(dev);
473 struct clk *clk;
474 int i, j;
475
476 for (j = 0; j < SIERRA_NUM_CMN_PLLC; j++) {
477 for (i = 0; i < ARRAY_SIZE(priv->parent_clks); i++) {
478 clk = sp->input_clks[data[j].parents[i]];
479 if (IS_ERR_OR_NULL(clk)) {
480 dev_err(dev, "No parent clock for PLL mux clocks\n");
481 return IS_ERR(clk) ? PTR_ERR(clk) : -ENOENT;
482 }
483 priv->parent_clks[i] = clk;
484 }
485 }
486
487 priv->sp = dev_get_priv(dev->parent);
488
489 return 0;
490}
491
492U_BOOT_DRIVER(cdns_sierra_pll_mux_clk) = {
493 .name = "cdns_sierra_mux_clk",
494 .id = UCLASS_CLK,
495 .priv_auto = sizeof(struct cdns_sierra_pll_mux),
496 .ops = &cdns_sierra_pll_mux_ops,
497 .probe = cdns_sierra_pll_mux_probe,
498 .plat_auto = sizeof(struct cdns_sierra_pll_mux_sel) * SIERRA_NUM_CMN_PLLC,
499};
500
501static int cdns_sierra_pll_bind_of_clocks(struct cdns_sierra_phy *sp)
502{
503 struct udevice *dev = sp->dev;
504 struct driver *cdns_sierra_clk_drv;
505 struct cdns_sierra_pll_mux_sel *data = pll_clk_mux_sel;
506 int i, rc;
507
508 cdns_sierra_clk_drv = lists_driver_lookup_name("cdns_sierra_mux_clk");
509 if (!cdns_sierra_clk_drv) {
510 dev_err(dev, "Can not find driver 'cdns_sierra_mux_clk'\n");
511 return -ENOENT;
512 }
513
514 rc = device_bind(dev, cdns_sierra_clk_drv, "pll_mux_clk",
515 data, dev_ofnode(dev), NULL);
516 if (rc) {
517 dev_err(dev, "cannot bind driver for clock %s\n",
518 clk_names[i]);
519 }
520
521 return 0;
522}
523
Alan Douglasfda76da2021-07-21 21:28:36 +0530524static int cdns_sierra_get_optional(struct cdns_sierra_inst *inst,
525 ofnode child)
526{
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530527 u32 phy_type;
528
Alan Douglasfda76da2021-07-21 21:28:36 +0530529 if (ofnode_read_u32(child, "reg", &inst->mlane))
530 return -EINVAL;
531
532 if (ofnode_read_u32(child, "cdns,num-lanes", &inst->num_lanes))
533 return -EINVAL;
534
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530535 if (ofnode_read_u32(child, "cdns,phy-type", &phy_type))
Alan Douglasfda76da2021-07-21 21:28:36 +0530536 return -EINVAL;
537
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530538 switch (phy_type) {
539 case PHY_TYPE_PCIE:
540 inst->phy_type = TYPE_PCIE;
541 break;
542 case PHY_TYPE_USB3:
543 inst->phy_type = TYPE_USB;
544 break;
545 default:
546 return -EINVAL;
547 }
548
Alan Douglasfda76da2021-07-21 21:28:36 +0530549 return 0;
550}
551
552static struct regmap *cdns_regmap_init(struct udevice *dev, void __iomem *base,
553 u32 block_offset, u8 block_offset_shift,
554 u8 reg_offset_shift)
555{
556 struct cdns_sierra_phy *sp = dev_get_priv(dev);
557 struct regmap_config config;
558
559 config.r_start = (ulong)(base + (block_offset << block_offset_shift));
560 config.r_size = sp->size - (block_offset << block_offset_shift);
561 config.reg_offset_shift = reg_offset_shift;
562 config.width = REGMAP_SIZE_16;
563
564 return devm_regmap_init(dev, NULL, NULL, &config);
565}
566
567static int cdns_regfield_init(struct cdns_sierra_phy *sp)
568{
569 struct udevice *dev = sp->dev;
570 struct regmap_field *field;
Aswath Govindraju304341f2022-01-28 13:41:36 +0530571 struct reg_field reg_field;
Alan Douglasfda76da2021-07-21 21:28:36 +0530572 struct regmap *regmap;
573 int i;
574
575 regmap = sp->regmap_common_cdb;
576 field = devm_regmap_field_alloc(dev, regmap, macro_id_type);
577 if (IS_ERR(field)) {
578 dev_err(dev, "MACRO_ID_TYPE reg field init failed\n");
579 return PTR_ERR(field);
580 }
581 sp->macro_id_type = field;
582
Aswath Govindraju304341f2022-01-28 13:41:36 +0530583 for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++) {
584 reg_field = cmn_plllc_pfdclk1_sel_preg[i].pfdclk_sel_preg;
585 field = devm_regmap_field_alloc(dev, regmap, reg_field);
586 if (IS_ERR(field)) {
587 dev_err(dev, "PLLLC%d_PFDCLK1_SEL failed\n", i);
588 return PTR_ERR(field);
589 }
590 sp->cmn_plllc_pfdclk1_sel_preg[i] = field;
591
592 reg_field = cmn_plllc_pfdclk1_sel_preg[i].plllc1en_field;
593 field = devm_regmap_field_alloc(dev, regmap, reg_field);
594 if (IS_ERR(field)) {
595 dev_err(dev, "REFRCV%d_REFCLK_PLLLC1EN failed\n", i);
596 return PTR_ERR(field);
597 }
598 sp->cmn_refrcv_refclk_plllc1en_preg[i] = field;
599
600 reg_field = cmn_plllc_pfdclk1_sel_preg[i].termen_field;
601 field = devm_regmap_field_alloc(dev, regmap, reg_field);
602 if (IS_ERR(field)) {
603 dev_err(dev, "REFRCV%d_REFCLK_TERMEN failed\n", i);
604 return PTR_ERR(field);
605 }
606 sp->cmn_refrcv_refclk_termen_preg[i] = field;
607 }
608
Alan Douglasfda76da2021-07-21 21:28:36 +0530609 regmap = sp->regmap_phy_config_ctrl;
610 field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1);
611 if (IS_ERR(field)) {
612 dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n");
613 return PTR_ERR(field);
614 }
615 sp->phy_pll_cfg_1 = field;
616
617 for (i = 0; i < SIERRA_MAX_LANES; i++) {
618 regmap = sp->regmap_lane_cdb[i];
619 field = devm_regmap_field_alloc(dev, regmap, pllctrl_lock);
620 if (IS_ERR(field)) {
621 dev_err(dev, "P%d_ENABLE reg field init failed\n", i);
622 return PTR_ERR(field);
623 }
624 sp->pllctrl_lock[i] = field;
625 }
626
627 return 0;
628}
629
630static int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp,
631 void __iomem *base, u8 block_offset_shift,
632 u8 reg_offset_shift)
633{
634 struct udevice *dev = sp->dev;
635 struct regmap *regmap;
636 u32 block_offset;
637 int i;
638
639 for (i = 0; i < SIERRA_MAX_LANES; i++) {
640 block_offset = SIERRA_LANE_CDB_OFFSET(i, reg_offset_shift);
641 regmap = cdns_regmap_init(dev, base, block_offset,
642 block_offset_shift, reg_offset_shift);
643 if (IS_ERR(regmap)) {
644 dev_err(dev, "Failed to init lane CDB regmap\n");
645 return PTR_ERR(regmap);
646 }
647 sp->regmap_lane_cdb[i] = regmap;
648 }
649
650 regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET,
651 block_offset_shift, reg_offset_shift);
652 if (IS_ERR(regmap)) {
653 dev_err(dev, "Failed to init common CDB regmap\n");
654 return PTR_ERR(regmap);
655 }
656 sp->regmap_common_cdb = regmap;
657
658 regmap = cdns_regmap_init(dev, base, SIERRA_PHY_CONFIG_CTRL_OFFSET,
659 block_offset_shift, reg_offset_shift);
660 if (IS_ERR(regmap)) {
661 dev_err(dev, "Failed to init PHY config and control regmap\n");
662 return PTR_ERR(regmap);
663 }
664 sp->regmap_phy_config_ctrl = regmap;
665
666 return 0;
667}
668
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530669static int cdns_sierra_phy_get_clocks(struct cdns_sierra_phy *sp,
670 struct udevice *dev)
671{
672 struct clk *clk;
673 int ret;
674
675 clk = devm_clk_get_optional(dev, "phy_clk");
676 if (IS_ERR(clk)) {
677 dev_err(dev, "failed to get clock phy_clk\n");
678 return PTR_ERR(clk);
679 }
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530680 sp->input_clks[PHY_CLK] = clk;
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530681
682 clk = devm_clk_get_optional(dev, "cmn_refclk_dig_div");
683 if (IS_ERR(clk)) {
684 dev_err(dev, "cmn_refclk_dig_div clock not found\n");
685 ret = PTR_ERR(clk);
686 return ret;
687 }
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530688 sp->input_clks[CMN_REFCLK_DIG_DIV] = clk;
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530689
690 clk = devm_clk_get_optional(dev, "cmn_refclk1_dig_div");
691 if (IS_ERR(clk)) {
692 dev_err(dev, "cmn_refclk1_dig_div clock not found\n");
693 ret = PTR_ERR(clk);
694 return ret;
695 }
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530696 sp->input_clks[CMN_REFCLK1_DIG_DIV] = clk;
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530697
Aswath Govindraju304341f2022-01-28 13:41:36 +0530698 clk = devm_clk_get_optional(dev, "pll0_refclk");
699 if (IS_ERR(clk)) {
700 dev_err(dev, "pll0_refclk clock not found\n");
701 ret = PTR_ERR(clk);
702 return ret;
703 }
704 sp->input_clks[PLL0_REFCLK] = clk;
705
706 clk = devm_clk_get_optional(dev, "pll1_refclk");
707 if (IS_ERR(clk)) {
708 dev_err(dev, "pll1_refclk clock not found\n");
709 ret = PTR_ERR(clk);
710 return ret;
711 }
712 sp->input_clks[PLL1_REFCLK] = clk;
713
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530714 return 0;
715}
716
Kishon Vijay Abraham I12fbc5c2022-01-28 13:41:32 +0530717static int cdns_sierra_phy_get_resets(struct cdns_sierra_phy *sp,
718 struct udevice *dev)
719{
720 struct reset_control *rst;
721
722 rst = devm_reset_control_get(dev, "sierra_reset");
723 if (IS_ERR(rst)) {
724 dev_err(dev, "failed to get reset\n");
725 return PTR_ERR(rst);
726 }
727 sp->phy_rst = rst;
728
729 return 0;
730}
731
Aswath Govindraju11fcd0e2022-01-28 13:41:35 +0530732static int cdns_sierra_bind_link_nodes(struct cdns_sierra_phy *sp)
733{
734 struct udevice *dev = sp->dev;
735 struct driver *link_drv;
736 ofnode child;
737 int rc;
738
739 link_drv = lists_driver_lookup_name("sierra_phy_link");
740 if (!link_drv) {
741 dev_err(dev, "Cannot find driver 'sierra_phy_link'\n");
742 return -ENOENT;
743 }
744
745 ofnode_for_each_subnode(child, dev_ofnode(dev)) {
746 if (!(ofnode_name_eq(child, "phy") ||
747 ofnode_name_eq(child, "link")))
748 continue;
749
750 rc = device_bind(dev, link_drv, "link", NULL, child, NULL);
751 if (rc) {
752 dev_err(dev, "cannot bind driver for link\n");
753 return rc;
754 }
755 }
756
757 return 0;
758}
759
760static int cdns_sierra_link_probe(struct udevice *dev)
761{
762 struct cdns_sierra_inst *inst = dev_get_priv(dev);
763 struct cdns_sierra_phy *sp = dev_get_priv(dev->parent);
764 struct reset_ctl_bulk *rst;
765 int ret, node;
766
767 rst = devm_reset_bulk_get_by_node(dev, dev_ofnode(dev));
768 if (IS_ERR(rst)) {
769 ret = PTR_ERR(rst);
770 dev_err(dev, "failed to get reset\n");
771 return ret;
772 }
773 inst->lnk_rst = rst;
774
775 ret = cdns_sierra_get_optional(inst, dev_ofnode(dev));
776 if (ret) {
777 dev_err(dev, "missing property in node\n");
778 return ret;
779 }
780 node = sp->nsubnodes;
781 sp->phys[node] = inst;
782 sp->nsubnodes += 1;
783 sp->num_lanes += inst->num_lanes;
784
785 /* If more than one subnode, configure the PHY as multilink */
786 if (!sp->autoconf && sp->nsubnodes > 1)
787 regmap_field_write(sp->phy_pll_cfg_1, 0x1);
788
789 return 0;
790}
791
792U_BOOT_DRIVER(sierra_phy_link) = {
793 .name = "sierra_phy_link",
794 .id = UCLASS_PHY,
795 .probe = cdns_sierra_link_probe,
796 .priv_auto = sizeof(struct cdns_sierra_inst),
797};
798
Alan Douglasfda76da2021-07-21 21:28:36 +0530799static int cdns_sierra_phy_probe(struct udevice *dev)
800{
801 struct cdns_sierra_phy *sp = dev_get_priv(dev);
802 struct cdns_sierra_data *data;
803 unsigned int id_value;
Aswath Govindraju304341f2022-01-28 13:41:36 +0530804 int ret;
Alan Douglasfda76da2021-07-21 21:28:36 +0530805
806 sp->dev = dev;
807
808 sp->base = devfdt_remap_addr_index(dev, 0);
809 if (!sp->base) {
810 dev_err(dev, "unable to map regs\n");
811 return -ENOMEM;
812 }
813 devfdt_get_addr_size_index(dev, 0, (fdt_size_t *)&sp->size);
814
815 /* Get init data for this PHY */
816 data = (struct cdns_sierra_data *)dev_get_driver_data(dev);
817 sp->init_data = data;
818
819 ret = cdns_regmap_init_blocks(sp, sp->base, data->block_offset_shift,
820 data->reg_offset_shift);
821 if (ret)
822 return ret;
823
824 ret = cdns_regfield_init(sp);
825 if (ret)
826 return ret;
827
Kishon Vijay Abraham I47d0bcb2022-01-28 13:41:31 +0530828 ret = cdns_sierra_phy_get_clocks(sp, dev);
829 if (ret)
830 return ret;
Alan Douglasfda76da2021-07-21 21:28:36 +0530831
Aswath Govindraju304341f2022-01-28 13:41:36 +0530832 ret = cdns_sierra_pll_bind_of_clocks(sp);
833 if (ret)
834 return ret;
Alan Douglasfda76da2021-07-21 21:28:36 +0530835
Kishon Vijay Abraham I12fbc5c2022-01-28 13:41:32 +0530836 ret = cdns_sierra_phy_get_resets(sp, dev);
837 if (ret)
838 return ret;
839
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530840 ret = clk_prepare_enable(sp->input_clks[PHY_CLK]);
Alan Douglasfda76da2021-07-21 21:28:36 +0530841 if (ret)
842 return ret;
843
844 /* Check that PHY is present */
845 regmap_field_read(sp->macro_id_type, &id_value);
846 if (sp->init_data->id_value != id_value) {
847 dev_err(dev, "PHY not found 0x%x vs 0x%x\n",
848 sp->init_data->id_value, id_value);
849 ret = -EINVAL;
850 goto clk_disable;
851 }
852
853 sp->autoconf = dev_read_bool(dev, "cdns,autoconf");
Aswath Govindraju11fcd0e2022-01-28 13:41:35 +0530854 /* Binding link nodes as children to serdes */
855 ret = cdns_sierra_bind_link_nodes(sp);
856 if (ret)
857 goto clk_disable;
Alan Douglasfda76da2021-07-21 21:28:36 +0530858
Alan Douglasfda76da2021-07-21 21:28:36 +0530859 dev_info(dev, "sierra probed\n");
860 return 0;
861
Alan Douglasfda76da2021-07-21 21:28:36 +0530862clk_disable:
Kishon Vijay Abraham Id6042522022-01-28 13:41:33 +0530863 clk_disable_unprepare(sp->input_clks[PHY_CLK]);
Alan Douglasfda76da2021-07-21 21:28:36 +0530864 return ret;
865}
866
867static int cdns_sierra_phy_remove(struct udevice *dev)
868{
869 struct cdns_sierra_phy *phy = dev_get_priv(dev);
870 int i;
871
872 reset_control_assert(phy->phy_rst);
873
874 /*
875 * The device level resets will be put automatically.
876 * Need to put the subnode resets here though.
877 */
878 for (i = 0; i < phy->nsubnodes; i++)
Aswath Govindraju11fcd0e2022-01-28 13:41:35 +0530879 reset_assert_bulk(phy->phys[i]->lnk_rst);
Alan Douglasfda76da2021-07-21 21:28:36 +0530880
Kishon Vijay Abraham I25f8b372022-01-28 13:41:34 +0530881 clk_disable_unprepare(phy->input_clks[PHY_CLK]);
882
Alan Douglasfda76da2021-07-21 21:28:36 +0530883 return 0;
884}
885
886/* refclk100MHz_32b_PCIe_cmn_pll_ext_ssc */
887static struct cdns_reg_pairs cdns_pcie_cmn_regs_ext_ssc[] = {
888 {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
889 {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
890 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
891 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
892 {0x1B1B, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
893};
894
895/* refclk100MHz_32b_PCIe_ln_ext_ssc */
896static struct cdns_reg_pairs cdns_pcie_ln_regs_ext_ssc[] = {
897 {0x813E, SIERRA_CLKPATHCTRL_TMR_PREG},
898 {0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
899 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
900 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
901 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
902 {0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
903 {0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG}
904};
905
Swapnil Jakhadee42a8472022-01-28 13:41:40 +0530906static struct cdns_sierra_vals pcie_100_ext_ssc_cmn_vals = {
907 .reg_pairs = cdns_pcie_cmn_regs_ext_ssc,
908 .num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc),
909};
910
911static struct cdns_sierra_vals pcie_100_ext_ssc_ln_vals = {
912 .reg_pairs = cdns_pcie_ln_regs_ext_ssc,
913 .num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc),
914};
915
Alan Douglasfda76da2021-07-21 21:28:36 +0530916/* refclk100MHz_20b_USB_cmn_pll_ext_ssc */
917static struct cdns_reg_pairs cdns_usb_cmn_regs_ext_ssc[] = {
918 {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
919 {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
920 {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
921 {0x0000, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
922};
923
924/* refclk100MHz_20b_USB_ln_ext_ssc */
925static struct cdns_reg_pairs cdns_usb_ln_regs_ext_ssc[] = {
926 {0xFE0A, SIERRA_DET_STANDEC_A_PREG},
927 {0x000F, SIERRA_DET_STANDEC_B_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530928 {0x55A5, SIERRA_DET_STANDEC_C_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530929 {0x69ad, SIERRA_DET_STANDEC_D_PREG},
930 {0x0241, SIERRA_DET_STANDEC_E_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530931 {0x0110, SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530932 {0x0014, SIERRA_PSM_A0IN_TMR_PREG},
933 {0xCF00, SIERRA_PSM_DIAG_PREG},
934 {0x001F, SIERRA_PSC_TX_A0_PREG},
935 {0x0007, SIERRA_PSC_TX_A1_PREG},
936 {0x0003, SIERRA_PSC_TX_A2_PREG},
937 {0x0003, SIERRA_PSC_TX_A3_PREG},
938 {0x0FFF, SIERRA_PSC_RX_A0_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530939 {0x0003, SIERRA_PSC_RX_A1_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530940 {0x0003, SIERRA_PSC_RX_A2_PREG},
941 {0x0001, SIERRA_PSC_RX_A3_PREG},
942 {0x0001, SIERRA_PLLCTRL_SUBRATE_PREG},
943 {0x0406, SIERRA_PLLCTRL_GEN_D_PREG},
944 {0x5233, SIERRA_PLLCTRL_CPGAIN_MODE_PREG},
945 {0x00CA, SIERRA_CLKPATH_BIASTRIM_PREG},
946 {0x2512, SIERRA_DFE_BIASTRIM_PREG},
947 {0x0000, SIERRA_DRVCTRL_ATTEN_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530948 {0x823E, SIERRA_CLKPATHCTRL_TMR_PREG},
949 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
950 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530951 {0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530952 {0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530953 {0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG},
954 {0x0000, SIERRA_CREQ_EQ_CTRL_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530955 {0x0000, SIERRA_CREQ_SPARE_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530956 {0xCC44, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530957 {0x8452, SIERRA_CTLELUT_CTRL_PREG},
958 {0x4121, SIERRA_DFE_ECMP_RATESEL_PREG},
959 {0x4121, SIERRA_DFE_SMP_RATESEL_PREG},
960 {0x0003, SIERRA_DEQ_PHALIGN_CTRL},
Alan Douglasfda76da2021-07-21 21:28:36 +0530961 {0x3200, SIERRA_DEQ_CONCUR_CTRL1_PREG},
962 {0x5064, SIERRA_DEQ_CONCUR_CTRL2_PREG},
963 {0x0030, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
964 {0x0048, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
965 {0x5A5A, SIERRA_DEQ_ERRCMP_CTRL_PREG},
966 {0x02F5, SIERRA_DEQ_OFFSET_CTRL_PREG},
967 {0x02F5, SIERRA_DEQ_GAIN_CTRL_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +0530968 {0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +0530969 {0x0014, SIERRA_DEQ_GLUT0},
970 {0x0014, SIERRA_DEQ_GLUT1},
971 {0x0014, SIERRA_DEQ_GLUT2},
972 {0x0014, SIERRA_DEQ_GLUT3},
973 {0x0014, SIERRA_DEQ_GLUT4},
974 {0x0014, SIERRA_DEQ_GLUT5},
975 {0x0014, SIERRA_DEQ_GLUT6},
976 {0x0014, SIERRA_DEQ_GLUT7},
977 {0x0014, SIERRA_DEQ_GLUT8},
978 {0x0014, SIERRA_DEQ_GLUT9},
979 {0x0014, SIERRA_DEQ_GLUT10},
980 {0x0014, SIERRA_DEQ_GLUT11},
981 {0x0014, SIERRA_DEQ_GLUT12},
982 {0x0014, SIERRA_DEQ_GLUT13},
983 {0x0014, SIERRA_DEQ_GLUT14},
984 {0x0014, SIERRA_DEQ_GLUT15},
985 {0x0014, SIERRA_DEQ_GLUT16},
986 {0x0BAE, SIERRA_DEQ_ALUT0},
987 {0x0AEB, SIERRA_DEQ_ALUT1},
988 {0x0A28, SIERRA_DEQ_ALUT2},
989 {0x0965, SIERRA_DEQ_ALUT3},
990 {0x08A2, SIERRA_DEQ_ALUT4},
991 {0x07DF, SIERRA_DEQ_ALUT5},
992 {0x071C, SIERRA_DEQ_ALUT6},
993 {0x0659, SIERRA_DEQ_ALUT7},
994 {0x0596, SIERRA_DEQ_ALUT8},
995 {0x0514, SIERRA_DEQ_ALUT9},
996 {0x0492, SIERRA_DEQ_ALUT10},
997 {0x0410, SIERRA_DEQ_ALUT11},
998 {0x038E, SIERRA_DEQ_ALUT12},
999 {0x030C, SIERRA_DEQ_ALUT13},
1000 {0x03F4, SIERRA_DEQ_DFETAP_CTRL_PREG},
1001 {0x0001, SIERRA_DFE_EN_1010_IGNORE_PREG},
1002 {0x3C01, SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG},
1003 {0x3C40, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1004 {0x1C08, SIERRA_DEQ_TAU_CTRL2_PREG},
1005 {0x0033, SIERRA_DEQ_PICTRL_PREG},
1006 {0x0400, SIERRA_CPICAL_TMRVAL_MODE1_PREG},
1007 {0x0330, SIERRA_CPICAL_TMRVAL_MODE0_PREG},
1008 {0x01FF, SIERRA_CPICAL_PICNT_MODE1_PREG},
1009 {0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG},
1010 {0x3232, SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG},
1011 {0x0005, SIERRA_LFPSDET_SUPPORT_PREG},
1012 {0x000F, SIERRA_LFPSFILT_NS_PREG},
1013 {0x0009, SIERRA_LFPSFILT_RD_PREG},
1014 {0x0001, SIERRA_LFPSFILT_MP_PREG},
Sanket Parmara3666262022-01-28 13:41:28 +05301015 {0x6013, SIERRA_SIGDET_SUPPORT_PREG},
Alan Douglasfda76da2021-07-21 21:28:36 +05301016 {0x8013, SIERRA_SDFILT_H2L_A_PREG},
1017 {0x8009, SIERRA_SDFILT_L2H_PREG},
1018 {0x0024, SIERRA_RXBUFFER_CTLECTRL_PREG},
1019 {0x0020, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1020 {0x4243, SIERRA_RXBUFFER_DFECTRL_PREG}
1021};
1022
Swapnil Jakhadee42a8472022-01-28 13:41:40 +05301023static struct cdns_sierra_vals usb_100_ext_ssc_cmn_vals = {
1024 .reg_pairs = cdns_usb_cmn_regs_ext_ssc,
1025 .num_regs = ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc),
1026};
1027
1028static struct cdns_sierra_vals usb_100_ext_ssc_ln_vals = {
1029 .reg_pairs = cdns_usb_ln_regs_ext_ssc,
1030 .num_regs = ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc),
1031};
1032
Alan Douglasfda76da2021-07-21 21:28:36 +05301033static const struct cdns_sierra_data cdns_map_sierra = {
Swapnil Jakhadee42a8472022-01-28 13:41:40 +05301034 .id_value = SIERRA_MACRO_ID,
1035 .block_offset_shift = 0x2,
1036 .reg_offset_shift = 0x2,
1037 .pma_cmn_vals = {
1038 [TYPE_PCIE] = {
1039 [TYPE_NONE] = {
1040 [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
1041 },
1042 },
1043 [TYPE_USB] = {
1044 [TYPE_NONE] = {
1045 [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1046 },
1047 },
1048 },
1049 .pma_ln_vals = {
1050 [TYPE_PCIE] = {
1051 [TYPE_NONE] = {
1052 [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
1053 },
1054 },
1055 [TYPE_USB] = {
1056 [TYPE_NONE] = {
1057 [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1058 },
1059 },
1060 },
Alan Douglasfda76da2021-07-21 21:28:36 +05301061};
1062
1063static const struct cdns_sierra_data cdns_ti_map_sierra = {
Swapnil Jakhadee42a8472022-01-28 13:41:40 +05301064 .id_value = SIERRA_MACRO_ID,
1065 .block_offset_shift = 0x0,
1066 .reg_offset_shift = 0x1,
1067 .pma_cmn_vals = {
1068 [TYPE_PCIE] = {
1069 [TYPE_NONE] = {
1070 [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
1071 },
1072 },
1073 [TYPE_USB] = {
1074 [TYPE_NONE] = {
1075 [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1076 },
1077 },
1078 },
1079 .pma_ln_vals = {
1080 [TYPE_PCIE] = {
1081 [TYPE_NONE] = {
1082 [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
1083 },
1084 },
1085 [TYPE_USB] = {
1086 [TYPE_NONE] = {
1087 [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1088 },
1089 },
1090 },
Alan Douglasfda76da2021-07-21 21:28:36 +05301091};
1092
1093static const struct udevice_id cdns_sierra_id_table[] = {
1094 {
1095 .compatible = "cdns,sierra-phy-t0",
1096 .data = (ulong)&cdns_map_sierra,
1097 },
1098 {
1099 .compatible = "ti,sierra-phy-t0",
1100 .data = (ulong)&cdns_ti_map_sierra,
1101 },
1102 {}
1103};
1104
1105U_BOOT_DRIVER(sierra_phy_provider) = {
1106 .name = "cdns,sierra",
1107 .id = UCLASS_PHY,
1108 .of_match = cdns_sierra_id_table,
1109 .probe = cdns_sierra_phy_probe,
1110 .remove = cdns_sierra_phy_remove,
1111 .ops = &ops,
1112 .priv_auto = sizeof(struct cdns_sierra_phy),
1113};