blob: eaa32939c1c22b3425e4f35acba083eacaf84a8f [file] [log] [blame]
Alan Douglas39b82332021-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>
16#include <generic-phy.h>
17#include <reset.h>
18#include <dm/device.h>
19#include <dm/device-internal.h>
20#include <dm/device_compat.h>
21#include <dm/lists.h>
22#include <dm/read.h>
23#include <dm/uclass.h>
24#include <dm/devres.h>
25#include <linux/io.h>
26#include <dt-bindings/phy/phy.h>
27#include <regmap.h>
28
29/* PHY register offsets */
30#define SIERRA_COMMON_CDB_OFFSET 0x0
31#define SIERRA_MACRO_ID_REG 0x0
32#define SIERRA_CMN_PLLLC_MODE_PREG 0x48
33#define SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG 0x49
34#define SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG 0x4A
35#define SIERRA_CMN_PLLLC_LOCK_CNTSTART_PREG 0x4B
36#define SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG 0x4F
37#define SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG 0x50
38#define SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG 0x62
39
40#define SIERRA_LANE_CDB_OFFSET(ln, offset) \
41 (0x4000 + ((ln) * (0x800 >> (2 - (offset)))))
42
43#define SIERRA_DET_STANDEC_A_PREG 0x000
44#define SIERRA_DET_STANDEC_B_PREG 0x001
45#define SIERRA_DET_STANDEC_C_PREG 0x002
46#define SIERRA_DET_STANDEC_D_PREG 0x003
47#define SIERRA_DET_STANDEC_E_PREG 0x004
48#define SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG 0x008
49#define SIERRA_PSM_A0IN_TMR_PREG 0x009
50#define SIERRA_PSM_DIAG_PREG 0x015
51#define SIERRA_PSC_TX_A0_PREG 0x028
52#define SIERRA_PSC_TX_A1_PREG 0x029
53#define SIERRA_PSC_TX_A2_PREG 0x02A
54#define SIERRA_PSC_TX_A3_PREG 0x02B
55#define SIERRA_PSC_RX_A0_PREG 0x030
56#define SIERRA_PSC_RX_A1_PREG 0x031
57#define SIERRA_PSC_RX_A2_PREG 0x032
58#define SIERRA_PSC_RX_A3_PREG 0x033
59#define SIERRA_PLLCTRL_SUBRATE_PREG 0x03A
60#define SIERRA_PLLCTRL_GEN_D_PREG 0x03E
61#define SIERRA_PLLCTRL_CPGAIN_MODE_PREG 0x03F
62#define SIERRA_PLLCTRL_STATUS_PREG 0x044
63#define SIERRA_CLKPATH_BIASTRIM_PREG 0x04B
64#define SIERRA_DFE_BIASTRIM_PREG 0x04C
65#define SIERRA_DRVCTRL_ATTEN_PREG 0x06A
66#define SIERRA_CLKPATHCTRL_TMR_PREG 0x081
67#define SIERRA_RX_CREQ_FLTR_A_MODE3_PREG 0x085
68#define SIERRA_RX_CREQ_FLTR_A_MODE2_PREG 0x086
69#define SIERRA_RX_CREQ_FLTR_A_MODE1_PREG 0x087
70#define SIERRA_RX_CREQ_FLTR_A_MODE0_PREG 0x088
71#define SIERRA_CREQ_CCLKDET_MODE01_PREG 0x08E
72#define SIERRA_RX_CTLE_MAINTENANCE_PREG 0x091
73#define SIERRA_CREQ_FSMCLK_SEL_PREG 0x092
74#define SIERRA_CREQ_EQ_CTRL_PREG 0x093
75#define SIERRA_CREQ_SPARE_PREG 0x096
76#define SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG 0x097
77#define SIERRA_CTLELUT_CTRL_PREG 0x098
78#define SIERRA_DFE_ECMP_RATESEL_PREG 0x0C0
79#define SIERRA_DFE_SMP_RATESEL_PREG 0x0C1
80#define SIERRA_DEQ_PHALIGN_CTRL 0x0C4
81#define SIERRA_DEQ_CONCUR_CTRL1_PREG 0x0C8
82#define SIERRA_DEQ_CONCUR_CTRL2_PREG 0x0C9
83#define SIERRA_DEQ_EPIPWR_CTRL2_PREG 0x0CD
84#define SIERRA_DEQ_FAST_MAINT_CYCLES_PREG 0x0CE
85#define SIERRA_DEQ_ERRCMP_CTRL_PREG 0x0D0
86#define SIERRA_DEQ_OFFSET_CTRL_PREG 0x0D8
87#define SIERRA_DEQ_GAIN_CTRL_PREG 0x0E0
88#define SIERRA_DEQ_VGATUNE_CTRL_PREG 0x0E1
89#define SIERRA_DEQ_GLUT0 0x0E8
90#define SIERRA_DEQ_GLUT1 0x0E9
91#define SIERRA_DEQ_GLUT2 0x0EA
92#define SIERRA_DEQ_GLUT3 0x0EB
93#define SIERRA_DEQ_GLUT4 0x0EC
94#define SIERRA_DEQ_GLUT5 0x0ED
95#define SIERRA_DEQ_GLUT6 0x0EE
96#define SIERRA_DEQ_GLUT7 0x0EF
97#define SIERRA_DEQ_GLUT8 0x0F0
98#define SIERRA_DEQ_GLUT9 0x0F1
99#define SIERRA_DEQ_GLUT10 0x0F2
100#define SIERRA_DEQ_GLUT11 0x0F3
101#define SIERRA_DEQ_GLUT12 0x0F4
102#define SIERRA_DEQ_GLUT13 0x0F5
103#define SIERRA_DEQ_GLUT14 0x0F6
104#define SIERRA_DEQ_GLUT15 0x0F7
105#define SIERRA_DEQ_GLUT16 0x0F8
106#define SIERRA_DEQ_ALUT0 0x108
107#define SIERRA_DEQ_ALUT1 0x109
108#define SIERRA_DEQ_ALUT2 0x10A
109#define SIERRA_DEQ_ALUT3 0x10B
110#define SIERRA_DEQ_ALUT4 0x10C
111#define SIERRA_DEQ_ALUT5 0x10D
112#define SIERRA_DEQ_ALUT6 0x10E
113#define SIERRA_DEQ_ALUT7 0x10F
114#define SIERRA_DEQ_ALUT8 0x110
115#define SIERRA_DEQ_ALUT9 0x111
116#define SIERRA_DEQ_ALUT10 0x112
117#define SIERRA_DEQ_ALUT11 0x113
118#define SIERRA_DEQ_ALUT12 0x114
119#define SIERRA_DEQ_ALUT13 0x115
120#define SIERRA_DEQ_DFETAP_CTRL_PREG 0x128
121#define SIERRA_DFE_EN_1010_IGNORE_PREG 0x134
122#define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150
123#define SIERRA_DEQ_TAU_CTRL2_PREG 0x151
124#define SIERRA_DEQ_PICTRL_PREG 0x161
125#define SIERRA_CPICAL_TMRVAL_MODE1_PREG 0x170
126#define SIERRA_CPICAL_TMRVAL_MODE0_PREG 0x171
127#define SIERRA_CPICAL_PICNT_MODE1_PREG 0x174
128#define SIERRA_CPI_OUTBUF_RATESEL_PREG 0x17C
129#define SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG 0x183
130#define SIERRA_LFPSDET_SUPPORT_PREG 0x188
131#define SIERRA_LFPSFILT_NS_PREG 0x18A
132#define SIERRA_LFPSFILT_RD_PREG 0x18B
133#define SIERRA_LFPSFILT_MP_PREG 0x18C
134#define SIERRA_SIGDET_SUPPORT_PREG 0x190
135#define SIERRA_SDFILT_H2L_A_PREG 0x191
136#define SIERRA_SDFILT_L2H_PREG 0x193
137#define SIERRA_RXBUFFER_CTLECTRL_PREG 0x19E
138#define SIERRA_RXBUFFER_RCDFECTRL_PREG 0x19F
139#define SIERRA_RXBUFFER_DFECTRL_PREG 0x1A0
140#define SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG 0x14F
141#define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150
142
143#define SIERRA_PHY_CONFIG_CTRL_OFFSET 0xc000
144#define SIERRA_PHY_PLL_CFG 0xe
145
146#define SIERRA_MACRO_ID 0x00007364
147#define SIERRA_MAX_LANES 16
148#define PLL_LOCK_TIME 100
149
150static const struct reg_field macro_id_type =
151 REG_FIELD(SIERRA_MACRO_ID_REG, 0, 15);
152static const struct reg_field phy_pll_cfg_1 =
153 REG_FIELD(SIERRA_PHY_PLL_CFG, 1, 1);
154static const struct reg_field pllctrl_lock =
155 REG_FIELD(SIERRA_PLLCTRL_STATUS_PREG, 0, 0);
156
157#define reset_control_assert(rst) cdns_reset_assert(rst)
158#define reset_control_deassert(rst) cdns_reset_deassert(rst)
159#define reset_control reset_ctl
160
161struct cdns_sierra_inst {
162 u32 phy_type;
163 u32 num_lanes;
164 u32 mlane;
165 struct reset_ctl_bulk *lnk_rst;
166};
167
168struct cdns_reg_pairs {
169 u16 val;
170 u32 off;
171};
172
173struct cdns_sierra_data {
174 u32 id_value;
175 u8 block_offset_shift;
176 u8 reg_offset_shift;
177 u32 pcie_cmn_regs;
178 u32 pcie_ln_regs;
179 u32 usb_cmn_regs;
180 u32 usb_ln_regs;
181 struct cdns_reg_pairs *pcie_cmn_vals;
182 struct cdns_reg_pairs *pcie_ln_vals;
183 struct cdns_reg_pairs *usb_cmn_vals;
184 struct cdns_reg_pairs *usb_ln_vals;
185};
186
187struct cdns_regmap_cdb_context {
188 struct udevice *dev;
189 void __iomem *base;
190 u8 reg_offset_shift;
191};
192
193struct cdns_sierra_phy {
194 struct udevice *dev;
195 void *base;
196 size_t size;
197 struct regmap *regmap;
198 struct cdns_sierra_data *init_data;
199 struct cdns_sierra_inst phys[SIERRA_MAX_LANES];
200 struct reset_control *phy_rst;
201 struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES];
202 struct regmap *regmap_phy_config_ctrl;
203 struct regmap *regmap_common_cdb;
204 struct regmap_field *macro_id_type;
205 struct regmap_field *phy_pll_cfg_1;
206 struct regmap_field *pllctrl_lock[SIERRA_MAX_LANES];
207 struct clk *clk;
208 struct clk *cmn_refclk;
209 struct clk *cmn_refclk1;
210 int nsubnodes;
211 u32 num_lanes;
212 bool autoconf;
213};
214
215static inline int cdns_reset_assert(struct reset_control *rst)
216{
217 if (rst)
218 return reset_assert(rst);
219 else
220 return 0;
221}
222
223static inline int cdns_reset_deassert(struct reset_control *rst)
224{
225 if (rst)
226 return reset_deassert(rst);
227 else
228 return 0;
229}
230
231static inline struct cdns_sierra_inst *phy_get_drvdata(struct phy *phy)
232{
233 struct cdns_sierra_phy *sp = dev_get_priv(phy->dev);
234 int index;
235
236 if (phy->id >= SIERRA_MAX_LANES)
237 return NULL;
238
239 for (index = 0; index < sp->nsubnodes; index++) {
240 if (phy->id == sp->phys[index].mlane)
241 return &sp->phys[index];
242 }
243
244 return NULL;
245}
246
247static int cdns_sierra_phy_init(struct phy *gphy)
248{
249 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
250 struct cdns_sierra_phy *phy = dev_get_priv(gphy->dev);
251 struct regmap *regmap = phy->regmap;
252 int i, j;
253 struct cdns_reg_pairs *cmn_vals, *ln_vals;
254 u32 num_cmn_regs, num_ln_regs;
255
256 /* Initialise the PHY registers, unless auto configured */
257 if (phy->autoconf)
258 return 0;
259
260 clk_set_rate(phy->cmn_refclk, 25000000);
261 clk_set_rate(phy->cmn_refclk1, 25000000);
262
263 if (ins->phy_type == PHY_TYPE_PCIE) {
264 num_cmn_regs = phy->init_data->pcie_cmn_regs;
265 num_ln_regs = phy->init_data->pcie_ln_regs;
266 cmn_vals = phy->init_data->pcie_cmn_vals;
267 ln_vals = phy->init_data->pcie_ln_vals;
268 } else if (ins->phy_type == PHY_TYPE_USB3) {
269 num_cmn_regs = phy->init_data->usb_cmn_regs;
270 num_ln_regs = phy->init_data->usb_ln_regs;
271 cmn_vals = phy->init_data->usb_cmn_vals;
272 ln_vals = phy->init_data->usb_ln_vals;
273 } else {
274 return -EINVAL;
275 }
276
277 regmap = phy->regmap_common_cdb;
278 for (j = 0; j < num_cmn_regs ; j++)
279 regmap_write(regmap, cmn_vals[j].off, cmn_vals[j].val);
280
281 for (i = 0; i < ins->num_lanes; i++) {
282 for (j = 0; j < num_ln_regs ; j++) {
283 regmap = phy->regmap_lane_cdb[i + ins->mlane];
284 regmap_write(regmap, ln_vals[j].off, ln_vals[j].val);
285 }
286 }
287
288 return 0;
289}
290
291static int cdns_sierra_phy_on(struct phy *gphy)
292{
293 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
294 struct cdns_sierra_phy *sp = dev_get_priv(gphy->dev);
295 struct udevice *dev = gphy->dev;
296 u32 val;
297 int ret;
298
Kishon Vijay Abraham I67703ee2022-01-28 13:41:29 +0530299 ret = reset_control_deassert(sp->phy_rst);
300 if (ret) {
301 dev_err(dev, "Failed to take the PHY out of reset\n");
302 return ret;
303 }
304
Alan Douglas39b82332021-07-21 21:28:36 +0530305 /* Take the PHY lane group out of reset */
306 ret = reset_deassert_bulk(ins->lnk_rst);
307 if (ret) {
308 dev_err(dev, "Failed to take the PHY lane out of reset\n");
309 return ret;
310 }
311
312 ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane],
313 val, val, 1000, PLL_LOCK_TIME);
314 if (ret < 0)
315 dev_err(dev, "PLL lock of lane failed\n");
316
317 reset_control_assert(sp->phy_rst);
318 reset_control_deassert(sp->phy_rst);
319
320 return ret;
321}
322
323static int cdns_sierra_phy_off(struct phy *gphy)
324{
325 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
326
327 return reset_assert_bulk(ins->lnk_rst);
328}
329
330static int cdns_sierra_phy_reset(struct phy *gphy)
331{
332 struct cdns_sierra_phy *sp = dev_get_priv(gphy->dev);
333
334 reset_control_assert(sp->phy_rst);
335 reset_control_deassert(sp->phy_rst);
336 return 0;
337};
338
339static const struct phy_ops ops = {
340 .init = cdns_sierra_phy_init,
341 .power_on = cdns_sierra_phy_on,
342 .power_off = cdns_sierra_phy_off,
343 .reset = cdns_sierra_phy_reset,
344};
345
346static int cdns_sierra_get_optional(struct cdns_sierra_inst *inst,
347 ofnode child)
348{
349 if (ofnode_read_u32(child, "reg", &inst->mlane))
350 return -EINVAL;
351
352 if (ofnode_read_u32(child, "cdns,num-lanes", &inst->num_lanes))
353 return -EINVAL;
354
355 if (ofnode_read_u32(child, "cdns,phy-type", &inst->phy_type))
356 return -EINVAL;
357
358 return 0;
359}
360
361static struct regmap *cdns_regmap_init(struct udevice *dev, void __iomem *base,
362 u32 block_offset, u8 block_offset_shift,
363 u8 reg_offset_shift)
364{
365 struct cdns_sierra_phy *sp = dev_get_priv(dev);
366 struct regmap_config config;
367
368 config.r_start = (ulong)(base + (block_offset << block_offset_shift));
369 config.r_size = sp->size - (block_offset << block_offset_shift);
370 config.reg_offset_shift = reg_offset_shift;
371 config.width = REGMAP_SIZE_16;
372
373 return devm_regmap_init(dev, NULL, NULL, &config);
374}
375
376static int cdns_regfield_init(struct cdns_sierra_phy *sp)
377{
378 struct udevice *dev = sp->dev;
379 struct regmap_field *field;
380 struct regmap *regmap;
381 int i;
382
383 regmap = sp->regmap_common_cdb;
384 field = devm_regmap_field_alloc(dev, regmap, macro_id_type);
385 if (IS_ERR(field)) {
386 dev_err(dev, "MACRO_ID_TYPE reg field init failed\n");
387 return PTR_ERR(field);
388 }
389 sp->macro_id_type = field;
390
391 regmap = sp->regmap_phy_config_ctrl;
392 field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1);
393 if (IS_ERR(field)) {
394 dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n");
395 return PTR_ERR(field);
396 }
397 sp->phy_pll_cfg_1 = field;
398
399 for (i = 0; i < SIERRA_MAX_LANES; i++) {
400 regmap = sp->regmap_lane_cdb[i];
401 field = devm_regmap_field_alloc(dev, regmap, pllctrl_lock);
402 if (IS_ERR(field)) {
403 dev_err(dev, "P%d_ENABLE reg field init failed\n", i);
404 return PTR_ERR(field);
405 }
406 sp->pllctrl_lock[i] = field;
407 }
408
409 return 0;
410}
411
412static int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp,
413 void __iomem *base, u8 block_offset_shift,
414 u8 reg_offset_shift)
415{
416 struct udevice *dev = sp->dev;
417 struct regmap *regmap;
418 u32 block_offset;
419 int i;
420
421 for (i = 0; i < SIERRA_MAX_LANES; i++) {
422 block_offset = SIERRA_LANE_CDB_OFFSET(i, reg_offset_shift);
423 regmap = cdns_regmap_init(dev, base, block_offset,
424 block_offset_shift, reg_offset_shift);
425 if (IS_ERR(regmap)) {
426 dev_err(dev, "Failed to init lane CDB regmap\n");
427 return PTR_ERR(regmap);
428 }
429 sp->regmap_lane_cdb[i] = regmap;
430 }
431
432 regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET,
433 block_offset_shift, reg_offset_shift);
434 if (IS_ERR(regmap)) {
435 dev_err(dev, "Failed to init common CDB regmap\n");
436 return PTR_ERR(regmap);
437 }
438 sp->regmap_common_cdb = regmap;
439
440 regmap = cdns_regmap_init(dev, base, SIERRA_PHY_CONFIG_CTRL_OFFSET,
441 block_offset_shift, reg_offset_shift);
442 if (IS_ERR(regmap)) {
443 dev_err(dev, "Failed to init PHY config and control regmap\n");
444 return PTR_ERR(regmap);
445 }
446 sp->regmap_phy_config_ctrl = regmap;
447
448 return 0;
449}
450
Kishon Vijay Abraham Ia9382b02022-01-28 13:41:31 +0530451static int cdns_sierra_phy_get_clocks(struct cdns_sierra_phy *sp,
452 struct udevice *dev)
453{
454 struct clk *clk;
455 int ret;
456
457 clk = devm_clk_get_optional(dev, "phy_clk");
458 if (IS_ERR(clk)) {
459 dev_err(dev, "failed to get clock phy_clk\n");
460 return PTR_ERR(clk);
461 }
462 sp->clk = clk;
463
464 clk = devm_clk_get_optional(dev, "cmn_refclk_dig_div");
465 if (IS_ERR(clk)) {
466 dev_err(dev, "cmn_refclk_dig_div clock not found\n");
467 ret = PTR_ERR(clk);
468 return ret;
469 }
470 sp->cmn_refclk = clk;
471
472 clk = devm_clk_get_optional(dev, "cmn_refclk1_dig_div");
473 if (IS_ERR(clk)) {
474 dev_err(dev, "cmn_refclk1_dig_div clock not found\n");
475 ret = PTR_ERR(clk);
476 return ret;
477 }
478 sp->cmn_refclk1 = clk;
479
480 return 0;
481}
482
Kishon Vijay Abraham Ic1c1b342022-01-28 13:41:32 +0530483static int cdns_sierra_phy_get_resets(struct cdns_sierra_phy *sp,
484 struct udevice *dev)
485{
486 struct reset_control *rst;
487
488 rst = devm_reset_control_get(dev, "sierra_reset");
489 if (IS_ERR(rst)) {
490 dev_err(dev, "failed to get reset\n");
491 return PTR_ERR(rst);
492 }
493 sp->phy_rst = rst;
494
495 return 0;
496}
497
Alan Douglas39b82332021-07-21 21:28:36 +0530498static int cdns_sierra_phy_probe(struct udevice *dev)
499{
500 struct cdns_sierra_phy *sp = dev_get_priv(dev);
501 struct cdns_sierra_data *data;
502 unsigned int id_value;
503 int ret, node = 0;
Alan Douglas39b82332021-07-21 21:28:36 +0530504 ofnode child;
505
506 sp->dev = dev;
507
508 sp->base = devfdt_remap_addr_index(dev, 0);
509 if (!sp->base) {
510 dev_err(dev, "unable to map regs\n");
511 return -ENOMEM;
512 }
513 devfdt_get_addr_size_index(dev, 0, (fdt_size_t *)&sp->size);
514
515 /* Get init data for this PHY */
516 data = (struct cdns_sierra_data *)dev_get_driver_data(dev);
517 sp->init_data = data;
518
519 ret = cdns_regmap_init_blocks(sp, sp->base, data->block_offset_shift,
520 data->reg_offset_shift);
521 if (ret)
522 return ret;
523
524 ret = cdns_regfield_init(sp);
525 if (ret)
526 return ret;
527
Kishon Vijay Abraham Ia9382b02022-01-28 13:41:31 +0530528 ret = cdns_sierra_phy_get_clocks(sp, dev);
529 if (ret)
530 return ret;
Alan Douglas39b82332021-07-21 21:28:36 +0530531
532 sp->phy_rst = devm_reset_control_get(dev, "sierra_reset");
533 if (IS_ERR(sp->phy_rst)) {
534 dev_err(dev, "failed to get reset\n");
535 return PTR_ERR(sp->phy_rst);
536 }
537
Kishon Vijay Abraham Ic1c1b342022-01-28 13:41:32 +0530538 ret = cdns_sierra_phy_get_resets(sp, dev);
539 if (ret)
540 return ret;
541
Alan Douglas39b82332021-07-21 21:28:36 +0530542 ret = clk_prepare_enable(sp->clk);
543 if (ret)
544 return ret;
545
546 /* Check that PHY is present */
547 regmap_field_read(sp->macro_id_type, &id_value);
548 if (sp->init_data->id_value != id_value) {
549 dev_err(dev, "PHY not found 0x%x vs 0x%x\n",
550 sp->init_data->id_value, id_value);
551 ret = -EINVAL;
552 goto clk_disable;
553 }
554
555 sp->autoconf = dev_read_bool(dev, "cdns,autoconf");
556
557 ofnode_for_each_subnode(child, dev_ofnode(dev)) {
Kishon Vijay Abraham I432286c2022-01-28 13:41:30 +0530558 if (!(ofnode_name_eq(child, "phy") ||
559 ofnode_name_eq(child, "link")))
560 continue;
561
Alan Douglas39b82332021-07-21 21:28:36 +0530562 sp->phys[node].lnk_rst = devm_reset_bulk_get_by_node(dev,
563 child);
564 if (IS_ERR(sp->phys[node].lnk_rst)) {
565 ret = PTR_ERR(sp->phys[node].lnk_rst);
566 dev_err(dev, "failed to get reset %s\n",
567 ofnode_get_name(child));
568 goto put_child2;
569 }
570
571 if (!sp->autoconf) {
572 ret = cdns_sierra_get_optional(&sp->phys[node], child);
573 if (ret) {
574 dev_err(dev, "missing property in node %s\n",
575 ofnode_get_name(child));
576 goto put_child;
577 }
578 }
579 sp->num_lanes += sp->phys[node].num_lanes;
580
581 node++;
582 }
583 sp->nsubnodes = node;
584
585 /* If more than one subnode, configure the PHY as multilink */
586 if (!sp->autoconf && sp->nsubnodes > 1)
587 regmap_field_write(sp->phy_pll_cfg_1, 0x1);
588
Alan Douglas39b82332021-07-21 21:28:36 +0530589 dev_info(dev, "sierra probed\n");
590 return 0;
591
592put_child:
593 node++;
594put_child2:
595
596clk_disable:
597 clk_disable_unprepare(sp->clk);
598 return ret;
599}
600
601static int cdns_sierra_phy_remove(struct udevice *dev)
602{
603 struct cdns_sierra_phy *phy = dev_get_priv(dev);
604 int i;
605
606 reset_control_assert(phy->phy_rst);
607
608 /*
609 * The device level resets will be put automatically.
610 * Need to put the subnode resets here though.
611 */
612 for (i = 0; i < phy->nsubnodes; i++)
613 reset_assert_bulk(phy->phys[i].lnk_rst);
614
615 return 0;
616}
617
618/* refclk100MHz_32b_PCIe_cmn_pll_ext_ssc */
619static struct cdns_reg_pairs cdns_pcie_cmn_regs_ext_ssc[] = {
620 {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
621 {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
622 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
623 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
624 {0x1B1B, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
625};
626
627/* refclk100MHz_32b_PCIe_ln_ext_ssc */
628static struct cdns_reg_pairs cdns_pcie_ln_regs_ext_ssc[] = {
629 {0x813E, SIERRA_CLKPATHCTRL_TMR_PREG},
630 {0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
631 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
632 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
633 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
634 {0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
635 {0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG}
636};
637
638/* refclk100MHz_20b_USB_cmn_pll_ext_ssc */
639static struct cdns_reg_pairs cdns_usb_cmn_regs_ext_ssc[] = {
640 {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
641 {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
642 {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
643 {0x0000, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
644};
645
646/* refclk100MHz_20b_USB_ln_ext_ssc */
647static struct cdns_reg_pairs cdns_usb_ln_regs_ext_ssc[] = {
648 {0xFE0A, SIERRA_DET_STANDEC_A_PREG},
649 {0x000F, SIERRA_DET_STANDEC_B_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +0530650 {0x55A5, SIERRA_DET_STANDEC_C_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +0530651 {0x69ad, SIERRA_DET_STANDEC_D_PREG},
652 {0x0241, SIERRA_DET_STANDEC_E_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +0530653 {0x0110, SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +0530654 {0x0014, SIERRA_PSM_A0IN_TMR_PREG},
655 {0xCF00, SIERRA_PSM_DIAG_PREG},
656 {0x001F, SIERRA_PSC_TX_A0_PREG},
657 {0x0007, SIERRA_PSC_TX_A1_PREG},
658 {0x0003, SIERRA_PSC_TX_A2_PREG},
659 {0x0003, SIERRA_PSC_TX_A3_PREG},
660 {0x0FFF, SIERRA_PSC_RX_A0_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +0530661 {0x0003, SIERRA_PSC_RX_A1_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +0530662 {0x0003, SIERRA_PSC_RX_A2_PREG},
663 {0x0001, SIERRA_PSC_RX_A3_PREG},
664 {0x0001, SIERRA_PLLCTRL_SUBRATE_PREG},
665 {0x0406, SIERRA_PLLCTRL_GEN_D_PREG},
666 {0x5233, SIERRA_PLLCTRL_CPGAIN_MODE_PREG},
667 {0x00CA, SIERRA_CLKPATH_BIASTRIM_PREG},
668 {0x2512, SIERRA_DFE_BIASTRIM_PREG},
669 {0x0000, SIERRA_DRVCTRL_ATTEN_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +0530670 {0x823E, SIERRA_CLKPATHCTRL_TMR_PREG},
671 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
672 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +0530673 {0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +0530674 {0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +0530675 {0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG},
676 {0x0000, SIERRA_CREQ_EQ_CTRL_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +0530677 {0x0000, SIERRA_CREQ_SPARE_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +0530678 {0xCC44, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +0530679 {0x8452, SIERRA_CTLELUT_CTRL_PREG},
680 {0x4121, SIERRA_DFE_ECMP_RATESEL_PREG},
681 {0x4121, SIERRA_DFE_SMP_RATESEL_PREG},
682 {0x0003, SIERRA_DEQ_PHALIGN_CTRL},
Alan Douglas39b82332021-07-21 21:28:36 +0530683 {0x3200, SIERRA_DEQ_CONCUR_CTRL1_PREG},
684 {0x5064, SIERRA_DEQ_CONCUR_CTRL2_PREG},
685 {0x0030, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
686 {0x0048, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
687 {0x5A5A, SIERRA_DEQ_ERRCMP_CTRL_PREG},
688 {0x02F5, SIERRA_DEQ_OFFSET_CTRL_PREG},
689 {0x02F5, SIERRA_DEQ_GAIN_CTRL_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +0530690 {0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +0530691 {0x0014, SIERRA_DEQ_GLUT0},
692 {0x0014, SIERRA_DEQ_GLUT1},
693 {0x0014, SIERRA_DEQ_GLUT2},
694 {0x0014, SIERRA_DEQ_GLUT3},
695 {0x0014, SIERRA_DEQ_GLUT4},
696 {0x0014, SIERRA_DEQ_GLUT5},
697 {0x0014, SIERRA_DEQ_GLUT6},
698 {0x0014, SIERRA_DEQ_GLUT7},
699 {0x0014, SIERRA_DEQ_GLUT8},
700 {0x0014, SIERRA_DEQ_GLUT9},
701 {0x0014, SIERRA_DEQ_GLUT10},
702 {0x0014, SIERRA_DEQ_GLUT11},
703 {0x0014, SIERRA_DEQ_GLUT12},
704 {0x0014, SIERRA_DEQ_GLUT13},
705 {0x0014, SIERRA_DEQ_GLUT14},
706 {0x0014, SIERRA_DEQ_GLUT15},
707 {0x0014, SIERRA_DEQ_GLUT16},
708 {0x0BAE, SIERRA_DEQ_ALUT0},
709 {0x0AEB, SIERRA_DEQ_ALUT1},
710 {0x0A28, SIERRA_DEQ_ALUT2},
711 {0x0965, SIERRA_DEQ_ALUT3},
712 {0x08A2, SIERRA_DEQ_ALUT4},
713 {0x07DF, SIERRA_DEQ_ALUT5},
714 {0x071C, SIERRA_DEQ_ALUT6},
715 {0x0659, SIERRA_DEQ_ALUT7},
716 {0x0596, SIERRA_DEQ_ALUT8},
717 {0x0514, SIERRA_DEQ_ALUT9},
718 {0x0492, SIERRA_DEQ_ALUT10},
719 {0x0410, SIERRA_DEQ_ALUT11},
720 {0x038E, SIERRA_DEQ_ALUT12},
721 {0x030C, SIERRA_DEQ_ALUT13},
722 {0x03F4, SIERRA_DEQ_DFETAP_CTRL_PREG},
723 {0x0001, SIERRA_DFE_EN_1010_IGNORE_PREG},
724 {0x3C01, SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG},
725 {0x3C40, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
726 {0x1C08, SIERRA_DEQ_TAU_CTRL2_PREG},
727 {0x0033, SIERRA_DEQ_PICTRL_PREG},
728 {0x0400, SIERRA_CPICAL_TMRVAL_MODE1_PREG},
729 {0x0330, SIERRA_CPICAL_TMRVAL_MODE0_PREG},
730 {0x01FF, SIERRA_CPICAL_PICNT_MODE1_PREG},
731 {0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG},
732 {0x3232, SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG},
733 {0x0005, SIERRA_LFPSDET_SUPPORT_PREG},
734 {0x000F, SIERRA_LFPSFILT_NS_PREG},
735 {0x0009, SIERRA_LFPSFILT_RD_PREG},
736 {0x0001, SIERRA_LFPSFILT_MP_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +0530737 {0x6013, SIERRA_SIGDET_SUPPORT_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +0530738 {0x8013, SIERRA_SDFILT_H2L_A_PREG},
739 {0x8009, SIERRA_SDFILT_L2H_PREG},
740 {0x0024, SIERRA_RXBUFFER_CTLECTRL_PREG},
741 {0x0020, SIERRA_RXBUFFER_RCDFECTRL_PREG},
742 {0x4243, SIERRA_RXBUFFER_DFECTRL_PREG}
743};
744
745static const struct cdns_sierra_data cdns_map_sierra = {
746 SIERRA_MACRO_ID,
747 0x2,
748 0x2,
749 ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc),
750 ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc),
751 ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc),
752 ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc),
753 cdns_pcie_cmn_regs_ext_ssc,
754 cdns_pcie_ln_regs_ext_ssc,
755 cdns_usb_cmn_regs_ext_ssc,
756 cdns_usb_ln_regs_ext_ssc,
757};
758
759static const struct cdns_sierra_data cdns_ti_map_sierra = {
760 SIERRA_MACRO_ID,
761 0x0,
762 0x1,
763 ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc),
764 ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc),
765 ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc),
766 ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc),
767 cdns_pcie_cmn_regs_ext_ssc,
768 cdns_pcie_ln_regs_ext_ssc,
769 cdns_usb_cmn_regs_ext_ssc,
770 cdns_usb_ln_regs_ext_ssc,
771};
772
773static const struct udevice_id cdns_sierra_id_table[] = {
774 {
775 .compatible = "cdns,sierra-phy-t0",
776 .data = (ulong)&cdns_map_sierra,
777 },
778 {
779 .compatible = "ti,sierra-phy-t0",
780 .data = (ulong)&cdns_ti_map_sierra,
781 },
782 {}
783};
784
785U_BOOT_DRIVER(sierra_phy_provider) = {
786 .name = "cdns,sierra",
787 .id = UCLASS_PHY,
788 .of_match = cdns_sierra_id_table,
789 .probe = cdns_sierra_phy_probe,
790 .remove = cdns_sierra_phy_remove,
791 .ops = &ops,
792 .priv_auto = sizeof(struct cdns_sierra_phy),
793};