blob: d490e1641cf9e82cb7771b5623a0fcec0f9d39be [file] [log] [blame]
Alan Douglas44d30d62018-11-12 16:42:16 +00001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Cadence Sierra PHY Driver
4 *
5 * Copyright (c) 2018 Cadence Design Systems
6 * Author: Alan Douglas <adouglas@cadence.com>
7 *
8 */
9#include <linux/clk.h>
10#include <linux/delay.h>
11#include <linux/err.h>
12#include <linux/io.h>
13#include <linux/module.h>
14#include <linux/phy/phy.h>
15#include <linux/platform_device.h>
16#include <linux/pm_runtime.h>
17#include <linux/regmap.h>
18#include <linux/reset.h>
19#include <linux/slab.h>
20#include <linux/of.h>
21#include <linux/of_platform.h>
22#include <dt-bindings/phy/phy.h>
23
24/* PHY register offsets */
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +053025#define SIERRA_COMMON_CDB_OFFSET 0x0
26#define SIERRA_MACRO_ID_REG 0x0
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +053027
28#define SIERRA_LANE_CDB_OFFSET(ln, block_offset, reg_offset) \
29 ((0x4000 << (block_offset)) + \
30 (((ln) << 9) << (reg_offset)))
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +053031
32#define SIERRA_DET_STANDEC_A_PREG 0x000
33#define SIERRA_DET_STANDEC_B_PREG 0x001
34#define SIERRA_DET_STANDEC_C_PREG 0x002
35#define SIERRA_DET_STANDEC_D_PREG 0x003
36#define SIERRA_DET_STANDEC_E_PREG 0x004
37#define SIERRA_PSM_LANECAL_PREG 0x008
38#define SIERRA_PSM_DIAG_PREG 0x015
39#define SIERRA_PSC_TX_A0_PREG 0x028
40#define SIERRA_PSC_TX_A1_PREG 0x029
41#define SIERRA_PSC_TX_A2_PREG 0x02A
42#define SIERRA_PSC_TX_A3_PREG 0x02B
43#define SIERRA_PSC_RX_A0_PREG 0x030
44#define SIERRA_PSC_RX_A1_PREG 0x031
45#define SIERRA_PSC_RX_A2_PREG 0x032
46#define SIERRA_PSC_RX_A3_PREG 0x033
47#define SIERRA_PLLCTRL_SUBRATE_PREG 0x03A
48#define SIERRA_PLLCTRL_GEN_D_PREG 0x03E
49#define SIERRA_DRVCTRL_ATTEN_PREG 0x06A
50#define SIERRA_CLKPATHCTRL_TMR_PREG 0x081
51#define SIERRA_RX_CREQ_FLTR_A_MODE1_PREG 0x087
52#define SIERRA_RX_CREQ_FLTR_A_MODE0_PREG 0x088
53#define SIERRA_CREQ_CCLKDET_MODE01_PREG 0x08E
54#define SIERRA_RX_CTLE_MAINTENANCE_PREG 0x091
55#define SIERRA_CREQ_FSMCLK_SEL_PREG 0x092
56#define SIERRA_CTLELUT_CTRL_PREG 0x098
57#define SIERRA_DFE_ECMP_RATESEL_PREG 0x0C0
58#define SIERRA_DFE_SMP_RATESEL_PREG 0x0C1
59#define SIERRA_DEQ_VGATUNE_CTRL_PREG 0x0E1
60#define SIERRA_TMRVAL_MODE3_PREG 0x16E
61#define SIERRA_TMRVAL_MODE2_PREG 0x16F
62#define SIERRA_TMRVAL_MODE1_PREG 0x170
63#define SIERRA_TMRVAL_MODE0_PREG 0x171
64#define SIERRA_PICNT_MODE1_PREG 0x174
65#define SIERRA_CPI_OUTBUF_RATESEL_PREG 0x17C
66#define SIERRA_LFPSFILT_NS_PREG 0x18A
67#define SIERRA_LFPSFILT_RD_PREG 0x18B
68#define SIERRA_LFPSFILT_MP_PREG 0x18C
69#define SIERRA_SDFILT_H2L_A_PREG 0x191
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +053070
71#define SIERRA_PHY_CONFIG_CTRL_OFFSET(block_offset) \
72 (0xc000 << (block_offset))
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +053073#define SIERRA_PHY_PLL_CFG 0xe
Alan Douglas44d30d62018-11-12 16:42:16 +000074
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +053075#define SIERRA_MACRO_ID 0x00007364
76#define SIERRA_MAX_LANES 4
Alan Douglas44d30d62018-11-12 16:42:16 +000077
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +053078static const struct reg_field macro_id_type =
79 REG_FIELD(SIERRA_MACRO_ID_REG, 0, 15);
80static const struct reg_field phy_pll_cfg_1 =
81 REG_FIELD(SIERRA_PHY_PLL_CFG, 1, 1);
82
Alan Douglas44d30d62018-11-12 16:42:16 +000083struct cdns_sierra_inst {
84 struct phy *phy;
85 u32 phy_type;
86 u32 num_lanes;
87 u32 mlane;
88 struct reset_control *lnk_rst;
89};
90
91struct cdns_reg_pairs {
92 u16 val;
93 u32 off;
94};
95
96struct cdns_sierra_data {
97 u32 id_value;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +053098 u8 block_offset_shift;
99 u8 reg_offset_shift;
Alan Douglas44d30d62018-11-12 16:42:16 +0000100 u32 pcie_regs;
101 u32 usb_regs;
102 struct cdns_reg_pairs *pcie_vals;
103 struct cdns_reg_pairs *usb_vals;
104};
105
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530106struct cdns_regmap_cdb_context {
Alan Douglas44d30d62018-11-12 16:42:16 +0000107 struct device *dev;
108 void __iomem *base;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530109 u8 reg_offset_shift;
110};
111
112struct cdns_sierra_phy {
113 struct device *dev;
114 struct regmap *regmap;
Alan Douglas44d30d62018-11-12 16:42:16 +0000115 struct cdns_sierra_data *init_data;
116 struct cdns_sierra_inst phys[SIERRA_MAX_LANES];
117 struct reset_control *phy_rst;
118 struct reset_control *apb_rst;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530119 struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES];
120 struct regmap *regmap_phy_config_ctrl;
121 struct regmap *regmap_common_cdb;
122 struct regmap_field *macro_id_type;
123 struct regmap_field *phy_pll_cfg_1;
Alan Douglas44d30d62018-11-12 16:42:16 +0000124 struct clk *clk;
125 int nsubnodes;
126 bool autoconf;
127};
128
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530129static int cdns_regmap_write(void *context, unsigned int reg, unsigned int val)
130{
131 struct cdns_regmap_cdb_context *ctx = context;
132 u32 offset = reg << ctx->reg_offset_shift;
133
134 writew(val, ctx->base + offset);
135
136 return 0;
137}
138
139static int cdns_regmap_read(void *context, unsigned int reg, unsigned int *val)
140{
141 struct cdns_regmap_cdb_context *ctx = context;
142 u32 offset = reg << ctx->reg_offset_shift;
143
144 *val = readw(ctx->base + offset);
145 return 0;
146}
147
148#define SIERRA_LANE_CDB_REGMAP_CONF(n) \
149{ \
150 .name = "sierra_lane" n "_cdb", \
151 .reg_stride = 1, \
152 .fast_io = true, \
153 .reg_write = cdns_regmap_write, \
154 .reg_read = cdns_regmap_read, \
155}
156
157static struct regmap_config cdns_sierra_lane_cdb_config[] = {
158 SIERRA_LANE_CDB_REGMAP_CONF("0"),
159 SIERRA_LANE_CDB_REGMAP_CONF("1"),
160 SIERRA_LANE_CDB_REGMAP_CONF("2"),
161 SIERRA_LANE_CDB_REGMAP_CONF("3"),
162};
163
164static struct regmap_config cdns_sierra_common_cdb_config = {
165 .name = "sierra_common_cdb",
166 .reg_stride = 1,
167 .fast_io = true,
168 .reg_write = cdns_regmap_write,
169 .reg_read = cdns_regmap_read,
170};
171
172static struct regmap_config cdns_sierra_phy_config_ctrl_config = {
173 .name = "sierra_phy_config_ctrl",
174 .reg_stride = 1,
175 .fast_io = true,
176 .reg_write = cdns_regmap_write,
177 .reg_read = cdns_regmap_read,
178};
179
Kishon Vijay Abraham Icedcc2e2019-12-16 15:27:03 +0530180static int cdns_sierra_phy_init(struct phy *gphy)
Alan Douglas44d30d62018-11-12 16:42:16 +0000181{
182 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
183 struct cdns_sierra_phy *phy = dev_get_drvdata(gphy->dev.parent);
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530184 struct regmap *regmap = phy->regmap;
Alan Douglas44d30d62018-11-12 16:42:16 +0000185 int i, j;
186 struct cdns_reg_pairs *vals;
187 u32 num_regs;
188
Kishon Vijay Abraham Icedcc2e2019-12-16 15:27:03 +0530189 /* Initialise the PHY registers, unless auto configured */
190 if (phy->autoconf)
191 return 0;
192
Alan Douglas44d30d62018-11-12 16:42:16 +0000193 if (ins->phy_type == PHY_TYPE_PCIE) {
194 num_regs = phy->init_data->pcie_regs;
195 vals = phy->init_data->pcie_vals;
196 } else if (ins->phy_type == PHY_TYPE_USB3) {
197 num_regs = phy->init_data->usb_regs;
198 vals = phy->init_data->usb_vals;
199 } else {
Kishon Vijay Abraham Icedcc2e2019-12-16 15:27:03 +0530200 return -EINVAL;
Alan Douglas44d30d62018-11-12 16:42:16 +0000201 }
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530202 for (i = 0; i < ins->num_lanes; i++) {
203 for (j = 0; j < num_regs ; j++) {
204 regmap = phy->regmap_lane_cdb[i + ins->mlane];
205 regmap_write(regmap, vals[j].off, vals[j].val);
206 }
207 }
Kishon Vijay Abraham Icedcc2e2019-12-16 15:27:03 +0530208
209 return 0;
Alan Douglas44d30d62018-11-12 16:42:16 +0000210}
211
212static int cdns_sierra_phy_on(struct phy *gphy)
213{
214 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
215
216 /* Take the PHY lane group out of reset */
217 return reset_control_deassert(ins->lnk_rst);
218}
219
220static int cdns_sierra_phy_off(struct phy *gphy)
221{
222 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
223
224 return reset_control_assert(ins->lnk_rst);
225}
226
227static const struct phy_ops ops = {
Kishon Vijay Abraham Icedcc2e2019-12-16 15:27:03 +0530228 .init = cdns_sierra_phy_init,
Alan Douglas44d30d62018-11-12 16:42:16 +0000229 .power_on = cdns_sierra_phy_on,
230 .power_off = cdns_sierra_phy_off,
231 .owner = THIS_MODULE,
232};
233
234static int cdns_sierra_get_optional(struct cdns_sierra_inst *inst,
235 struct device_node *child)
236{
237 if (of_property_read_u32(child, "reg", &inst->mlane))
238 return -EINVAL;
239
240 if (of_property_read_u32(child, "cdns,num-lanes", &inst->num_lanes))
241 return -EINVAL;
242
243 if (of_property_read_u32(child, "cdns,phy-type", &inst->phy_type))
244 return -EINVAL;
245
246 return 0;
247}
248
249static const struct of_device_id cdns_sierra_id_table[];
250
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530251static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base,
252 u32 block_offset, u8 reg_offset_shift,
253 const struct regmap_config *config)
254{
255 struct cdns_regmap_cdb_context *ctx;
256
257 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
258 if (!ctx)
259 return ERR_PTR(-ENOMEM);
260
261 ctx->dev = dev;
262 ctx->base = base + block_offset;
263 ctx->reg_offset_shift = reg_offset_shift;
264
265 return devm_regmap_init(dev, NULL, ctx, config);
266}
267
268static int cdns_regfield_init(struct cdns_sierra_phy *sp)
269{
270 struct device *dev = sp->dev;
271 struct regmap_field *field;
272 struct regmap *regmap;
273
274 regmap = sp->regmap_common_cdb;
275 field = devm_regmap_field_alloc(dev, regmap, macro_id_type);
276 if (IS_ERR(field)) {
277 dev_err(dev, "MACRO_ID_TYPE reg field init failed\n");
278 return PTR_ERR(field);
279 }
280 sp->macro_id_type = field;
281
282 regmap = sp->regmap_phy_config_ctrl;
283 field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1);
284 if (IS_ERR(field)) {
285 dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n");
286 return PTR_ERR(field);
287 }
288 sp->phy_pll_cfg_1 = field;
289
290 return 0;
291}
292
293static int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp,
294 void __iomem *base, u8 block_offset_shift,
295 u8 reg_offset_shift)
296{
297 struct device *dev = sp->dev;
298 struct regmap *regmap;
299 u32 block_offset;
300 int i;
301
302 for (i = 0; i < SIERRA_MAX_LANES; i++) {
303 block_offset = SIERRA_LANE_CDB_OFFSET(i, block_offset_shift,
304 reg_offset_shift);
305 regmap = cdns_regmap_init(dev, base, block_offset,
306 reg_offset_shift,
307 &cdns_sierra_lane_cdb_config[i]);
308 if (IS_ERR(regmap)) {
309 dev_err(dev, "Failed to init lane CDB regmap\n");
310 return PTR_ERR(regmap);
311 }
312 sp->regmap_lane_cdb[i] = regmap;
313 }
314
315 regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET,
316 reg_offset_shift,
317 &cdns_sierra_common_cdb_config);
318 if (IS_ERR(regmap)) {
319 dev_err(dev, "Failed to init common CDB regmap\n");
320 return PTR_ERR(regmap);
321 }
322 sp->regmap_common_cdb = regmap;
323
324 block_offset = SIERRA_PHY_CONFIG_CTRL_OFFSET(block_offset_shift);
325 regmap = cdns_regmap_init(dev, base, block_offset, reg_offset_shift,
326 &cdns_sierra_phy_config_ctrl_config);
327 if (IS_ERR(regmap)) {
328 dev_err(dev, "Failed to init PHY config and control regmap\n");
329 return PTR_ERR(regmap);
330 }
331 sp->regmap_phy_config_ctrl = regmap;
332
333 return 0;
334}
335
Alan Douglas44d30d62018-11-12 16:42:16 +0000336static int cdns_sierra_phy_probe(struct platform_device *pdev)
337{
338 struct cdns_sierra_phy *sp;
339 struct phy_provider *phy_provider;
340 struct device *dev = &pdev->dev;
341 const struct of_device_id *match;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530342 struct cdns_sierra_data *data;
343 unsigned int id_value;
Alan Douglas44d30d62018-11-12 16:42:16 +0000344 struct resource *res;
345 int i, ret, node = 0;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530346 void __iomem *base;
Alan Douglas44d30d62018-11-12 16:42:16 +0000347 struct device_node *dn = dev->of_node, *child;
348
349 if (of_get_child_count(dn) == 0)
350 return -ENODEV;
351
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530352 /* Get init data for this PHY */
353 match = of_match_device(cdns_sierra_id_table, dev);
354 if (!match)
355 return -EINVAL;
356
357 data = (struct cdns_sierra_data *)match->data;
358
Alan Douglas44d30d62018-11-12 16:42:16 +0000359 sp = devm_kzalloc(dev, sizeof(*sp), GFP_KERNEL);
360 if (!sp)
361 return -ENOMEM;
362 dev_set_drvdata(dev, sp);
363 sp->dev = dev;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530364 sp->init_data = data;
Alan Douglas44d30d62018-11-12 16:42:16 +0000365
366 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530367 base = devm_ioremap_resource(dev, res);
368 if (IS_ERR(base)) {
Alan Douglas44d30d62018-11-12 16:42:16 +0000369 dev_err(dev, "missing \"reg\"\n");
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530370 return PTR_ERR(base);
Alan Douglas44d30d62018-11-12 16:42:16 +0000371 }
372
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530373 ret = cdns_regmap_init_blocks(sp, base, data->block_offset_shift,
374 data->reg_offset_shift);
375 if (ret)
376 return ret;
377
378 ret = cdns_regfield_init(sp);
379 if (ret)
380 return ret;
Alan Douglas44d30d62018-11-12 16:42:16 +0000381
382 platform_set_drvdata(pdev, sp);
383
Kishon Vijay Abraham I372428d2019-12-16 15:27:00 +0530384 sp->clk = devm_clk_get_optional(dev, "phy_clk");
Alan Douglas44d30d62018-11-12 16:42:16 +0000385 if (IS_ERR(sp->clk)) {
386 dev_err(dev, "failed to get clock phy_clk\n");
387 return PTR_ERR(sp->clk);
388 }
389
390 sp->phy_rst = devm_reset_control_get(dev, "sierra_reset");
391 if (IS_ERR(sp->phy_rst)) {
392 dev_err(dev, "failed to get reset\n");
393 return PTR_ERR(sp->phy_rst);
394 }
395
Kishon Vijay Abraham I372428d2019-12-16 15:27:00 +0530396 sp->apb_rst = devm_reset_control_get_optional(dev, "sierra_apb");
Alan Douglas44d30d62018-11-12 16:42:16 +0000397 if (IS_ERR(sp->apb_rst)) {
398 dev_err(dev, "failed to get apb reset\n");
399 return PTR_ERR(sp->apb_rst);
400 }
401
402 ret = clk_prepare_enable(sp->clk);
403 if (ret)
404 return ret;
405
406 /* Enable APB */
407 reset_control_deassert(sp->apb_rst);
408
409 /* Check that PHY is present */
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530410 regmap_field_read(sp->macro_id_type, &id_value);
411 if (sp->init_data->id_value != id_value) {
Alan Douglas44d30d62018-11-12 16:42:16 +0000412 ret = -EINVAL;
413 goto clk_disable;
414 }
415
416 sp->autoconf = of_property_read_bool(dn, "cdns,autoconf");
417
418 for_each_available_child_of_node(dn, child) {
419 struct phy *gphy;
420
421 sp->phys[node].lnk_rst =
422 of_reset_control_get_exclusive_by_index(child, 0);
423
424 if (IS_ERR(sp->phys[node].lnk_rst)) {
425 dev_err(dev, "failed to get reset %s\n",
426 child->full_name);
427 ret = PTR_ERR(sp->phys[node].lnk_rst);
428 goto put_child2;
429 }
430
431 if (!sp->autoconf) {
432 ret = cdns_sierra_get_optional(&sp->phys[node], child);
433 if (ret) {
434 dev_err(dev, "missing property in node %s\n",
435 child->name);
436 goto put_child;
437 }
438 }
439
440 gphy = devm_phy_create(dev, child, &ops);
441
442 if (IS_ERR(gphy)) {
443 ret = PTR_ERR(gphy);
444 goto put_child;
445 }
446 sp->phys[node].phy = gphy;
447 phy_set_drvdata(gphy, &sp->phys[node]);
448
Alan Douglas44d30d62018-11-12 16:42:16 +0000449 node++;
450 }
451 sp->nsubnodes = node;
452
453 /* If more than one subnode, configure the PHY as multilink */
454 if (!sp->autoconf && sp->nsubnodes > 1)
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530455 regmap_field_write(sp->phy_pll_cfg_1, 0x1);
Alan Douglas44d30d62018-11-12 16:42:16 +0000456
457 pm_runtime_enable(dev);
458 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
459 reset_control_deassert(sp->phy_rst);
460 return PTR_ERR_OR_ZERO(phy_provider);
461
462put_child:
463 node++;
464put_child2:
465 for (i = 0; i < node; i++)
466 reset_control_put(sp->phys[i].lnk_rst);
467 of_node_put(child);
468clk_disable:
469 clk_disable_unprepare(sp->clk);
470 reset_control_assert(sp->apb_rst);
471 return ret;
472}
473
474static int cdns_sierra_phy_remove(struct platform_device *pdev)
475{
476 struct cdns_sierra_phy *phy = dev_get_drvdata(pdev->dev.parent);
477 int i;
478
479 reset_control_assert(phy->phy_rst);
480 reset_control_assert(phy->apb_rst);
481 pm_runtime_disable(&pdev->dev);
482
483 /*
484 * The device level resets will be put automatically.
485 * Need to put the subnode resets here though.
486 */
487 for (i = 0; i < phy->nsubnodes; i++) {
488 reset_control_assert(phy->phys[i].lnk_rst);
489 reset_control_put(phy->phys[i].lnk_rst);
490 }
491 return 0;
492}
493
494static struct cdns_reg_pairs cdns_usb_regs[] = {
495 /*
496 * Write USB configuration parameters to the PHY.
497 * These values are specific to this specific hardware
498 * configuration.
499 */
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +0530500 {0xFE0A, SIERRA_DET_STANDEC_A_PREG},
501 {0x000F, SIERRA_DET_STANDEC_B_PREG},
502 {0x55A5, SIERRA_DET_STANDEC_C_PREG},
503 {0x69AD, SIERRA_DET_STANDEC_D_PREG},
504 {0x0241, SIERRA_DET_STANDEC_E_PREG},
505 {0x0110, SIERRA_PSM_LANECAL_PREG},
506 {0xCF00, SIERRA_PSM_DIAG_PREG},
507 {0x001F, SIERRA_PSC_TX_A0_PREG},
508 {0x0007, SIERRA_PSC_TX_A1_PREG},
509 {0x0003, SIERRA_PSC_TX_A2_PREG},
510 {0x0003, SIERRA_PSC_TX_A3_PREG},
511 {0x0FFF, SIERRA_PSC_RX_A0_PREG},
512 {0x0003, SIERRA_PSC_RX_A1_PREG},
513 {0x0003, SIERRA_PSC_RX_A2_PREG},
514 {0x0001, SIERRA_PSC_RX_A3_PREG},
515 {0x0001, SIERRA_PLLCTRL_SUBRATE_PREG},
516 {0x0406, SIERRA_PLLCTRL_GEN_D_PREG},
517 {0x0000, SIERRA_DRVCTRL_ATTEN_PREG},
518 {0x823E, SIERRA_CLKPATHCTRL_TMR_PREG},
519 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
520 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
521 {0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG},
522 {0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
523 {0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG},
524 {0x8452, SIERRA_CTLELUT_CTRL_PREG},
525 {0x4121, SIERRA_DFE_ECMP_RATESEL_PREG},
526 {0x4121, SIERRA_DFE_SMP_RATESEL_PREG},
527 {0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG},
528 {0x0330, SIERRA_TMRVAL_MODE0_PREG},
529 {0x01FF, SIERRA_PICNT_MODE1_PREG},
530 {0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG},
531 {0x000F, SIERRA_LFPSFILT_NS_PREG},
532 {0x0009, SIERRA_LFPSFILT_RD_PREG},
533 {0x0001, SIERRA_LFPSFILT_MP_PREG},
534 {0x8013, SIERRA_SDFILT_H2L_A_PREG},
535 {0x0400, SIERRA_TMRVAL_MODE1_PREG},
Alan Douglas44d30d62018-11-12 16:42:16 +0000536};
537
538static struct cdns_reg_pairs cdns_pcie_regs[] = {
539 /*
540 * Write PCIe configuration parameters to the PHY.
541 * These values are specific to this specific hardware
542 * configuration.
543 */
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +0530544 {0x891f, SIERRA_DET_STANDEC_D_PREG},
545 {0x0053, SIERRA_DET_STANDEC_E_PREG},
546 {0x0400, SIERRA_TMRVAL_MODE2_PREG},
547 {0x0200, SIERRA_TMRVAL_MODE3_PREG},
Alan Douglas44d30d62018-11-12 16:42:16 +0000548};
549
550static const struct cdns_sierra_data cdns_map_sierra = {
551 SIERRA_MACRO_ID,
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530552 0x2,
553 0x2,
Alan Douglas44d30d62018-11-12 16:42:16 +0000554 ARRAY_SIZE(cdns_pcie_regs),
555 ARRAY_SIZE(cdns_usb_regs),
556 cdns_pcie_regs,
557 cdns_usb_regs
558};
559
Kishon Vijay Abraham I367da972019-12-16 15:27:02 +0530560static const struct cdns_sierra_data cdns_ti_map_sierra = {
561 SIERRA_MACRO_ID,
562 0x0,
563 0x1,
564 ARRAY_SIZE(cdns_pcie_regs),
565 ARRAY_SIZE(cdns_usb_regs),
566 cdns_pcie_regs,
567 cdns_usb_regs
568};
569
Alan Douglas44d30d62018-11-12 16:42:16 +0000570static const struct of_device_id cdns_sierra_id_table[] = {
571 {
572 .compatible = "cdns,sierra-phy-t0",
573 .data = &cdns_map_sierra,
574 },
Kishon Vijay Abraham I367da972019-12-16 15:27:02 +0530575 {
576 .compatible = "ti,sierra-phy-t0",
577 .data = &cdns_ti_map_sierra,
578 },
Alan Douglas44d30d62018-11-12 16:42:16 +0000579 {}
580};
581MODULE_DEVICE_TABLE(of, cdns_sierra_id_table);
582
583static struct platform_driver cdns_sierra_driver = {
584 .probe = cdns_sierra_phy_probe,
585 .remove = cdns_sierra_phy_remove,
586 .driver = {
587 .name = "cdns-sierra-phy",
588 .of_match_table = cdns_sierra_id_table,
589 },
590};
591module_platform_driver(cdns_sierra_driver);
592
593MODULE_ALIAS("platform:cdns_sierra");
594MODULE_AUTHOR("Cadence Design Systems");
595MODULE_DESCRIPTION("CDNS sierra phy driver");
596MODULE_LICENSE("GPL v2");