1 // SPDX-License-Identifier: GPL-2.0
3 * phy-zynqmp.c - PHY driver for Xilinx ZynqMP GT.
5 * Copyright (C) 2018-2021 Xilinx Inc.
13 #include <clk-uclass.h>
15 #include <generic-phy.h>
17 #include <power-domain.h>
21 #include <asm/arch/sys_proto.h>
22 #include <asm/arch/hardware.h>
23 #include <dm/device.h>
24 #include <dm/device_compat.h>
26 #include <dt-bindings/phy/phy.h>
27 #include <linux/bitops.h>
28 #include <linux/delay.h>
29 #include <linux/err.h>
35 /* TX De-emphasis parameters */
36 #define L0_TX_ANA_TM_18 0x0048
37 #define L0_TX_ANA_TM_118 0x01d8
38 #define L0_TX_ANA_TM_118_FORCE_17_0 BIT(0)
40 /* DN Resistor calibration code parameters */
41 #define L0_TXPMA_ST_3 0x0b0c
42 #define L0_DN_CALIB_CODE 0x3f
44 /* PMA control parameters */
45 #define L0_TXPMD_TM_45 0x0cb4
46 #define L0_TXPMD_TM_48 0x0cc0
47 #define L0_TXPMD_TM_45_OVER_DP_MAIN BIT(0)
48 #define L0_TXPMD_TM_45_ENABLE_DP_MAIN BIT(1)
49 #define L0_TXPMD_TM_45_OVER_DP_POST1 BIT(2)
50 #define L0_TXPMD_TM_45_ENABLE_DP_POST1 BIT(3)
51 #define L0_TXPMD_TM_45_OVER_DP_POST2 BIT(4)
52 #define L0_TXPMD_TM_45_ENABLE_DP_POST2 BIT(5)
54 /* PCS control parameters */
55 #define L0_TM_DIG_6 0x106c
56 #define L0_TM_DIS_DESCRAMBLE_DECODER 0x0f
57 #define L0_TX_DIG_61 0x00f4
58 #define L0_TM_DISABLE_SCRAMBLE_ENCODER 0x0f
60 /* PLL Test Mode register parameters */
61 #define L0_TM_PLL_DIG_37 0x2094
62 #define L0_TM_COARSE_CODE_LIMIT 0x10
64 /* PLL SSC step size offsets */
65 #define L0_PLL_SS_STEPS_0_LSB 0x2368
66 #define L0_PLL_SS_STEPS_1_MSB 0x236c
67 #define L0_PLL_SS_STEP_SIZE_0_LSB 0x2370
68 #define L0_PLL_SS_STEP_SIZE_1 0x2374
69 #define L0_PLL_SS_STEP_SIZE_2 0x2378
70 #define L0_PLL_SS_STEP_SIZE_3_MSB 0x237c
71 #define L0_PLL_STATUS_READ_1 0x23e4
73 /* SSC step size parameters */
74 #define STEP_SIZE_0_MASK 0xff
75 #define STEP_SIZE_1_MASK 0xff
76 #define STEP_SIZE_2_MASK 0xff
77 #define STEP_SIZE_3_MASK 0x3
78 #define STEP_SIZE_SHIFT 8
79 #define FORCE_STEP_SIZE 0x10
80 #define FORCE_STEPS 0x20
81 #define STEPS_0_MASK 0xff
82 #define STEPS_1_MASK 0x07
84 /* Reference clock selection parameters */
85 #define L0_Ln_REF_CLK_SEL(n) (0x2860 + (n) * 4)
86 #define L0_REF_CLK_SEL_MASK 0x8f
88 /* Calibration digital logic parameters */
89 #define L3_TM_CALIB_DIG19 0xec4c
90 #define L3_CALIB_DONE_STATUS 0xef14
91 #define L3_TM_CALIB_DIG18 0xec48
92 #define L3_TM_CALIB_DIG19_NSW 0x07
93 #define L3_TM_CALIB_DIG18_NSW 0xe0
94 #define L3_TM_OVERRIDE_NSW_CODE 0x20
95 #define L3_CALIB_DONE 0x02
96 #define L3_NSW_SHIFT 5
97 #define L3_NSW_PIPE_SHIFT 4
98 #define L3_NSW_CALIB_SHIFT 3
100 #define PHY_REG_OFFSET 0x4000
106 /* Refclk selection parameters */
107 #define PLL_REF_SEL(n) (0x10000 + (n) * 4)
108 #define PLL_FREQ_MASK 0x1f
109 #define PLL_STATUS_LOCKED 0x10
111 /* Inter Connect Matrix parameters */
112 #define ICM_CFG0 0x10010
113 #define ICM_CFG1 0x10014
114 #define ICM_CFG0_L0_MASK 0x07
115 #define ICM_CFG0_L1_MASK 0x70
116 #define ICM_CFG1_L2_MASK 0x07
117 #define ICM_CFG2_L3_MASK 0x70
118 #define ICM_CFG_SHIFT 4
120 /* Inter Connect Matrix allowed protocols */
121 #define ICM_PROTOCOL_PD 0x0
122 #define ICM_PROTOCOL_PCIE 0x1
123 #define ICM_PROTOCOL_SATA 0x2
124 #define ICM_PROTOCOL_USB 0x3
125 #define ICM_PROTOCOL_DP 0x4
126 #define ICM_PROTOCOL_SGMII 0x5
128 /* Test Mode common reset control parameters */
129 #define TM_CMN_RST 0x10018
130 #define TM_CMN_RST_EN 0x1
131 #define TM_CMN_RST_SET 0x2
132 #define TM_CMN_RST_MASK 0x3
134 /* Bus width parameters */
135 #define TX_PROT_BUS_WIDTH 0x10040
136 #define RX_PROT_BUS_WIDTH 0x10044
137 #define PROT_BUS_WIDTH_10 0x0
138 #define PROT_BUS_WIDTH_20 0x1
139 #define PROT_BUS_WIDTH_40 0x2
140 #define PROT_BUS_WIDTH_MASK 0x3
141 #define PROT_BUS_WIDTH_SHIFT 2
143 /* Number of GT lanes */
146 /* SIOU SATA control register */
147 #define SATA_CONTROL_OFFSET 0x0100
149 /* Total number of controllers */
150 #define CONTROLLERS_PER_LANE 5
152 /* Protocol Type parameters */
154 XPSGTR_TYPE_USB0 = 0, /* USB controller 0 */
155 XPSGTR_TYPE_USB1 = 1, /* USB controller 1 */
156 XPSGTR_TYPE_SATA_0 = 2, /* SATA controller lane 0 */
157 XPSGTR_TYPE_SATA_1 = 3, /* SATA controller lane 1 */
158 XPSGTR_TYPE_PCIE_0 = 4, /* PCIe controller lane 0 */
159 XPSGTR_TYPE_PCIE_1 = 5, /* PCIe controller lane 1 */
160 XPSGTR_TYPE_PCIE_2 = 6, /* PCIe controller lane 2 */
161 XPSGTR_TYPE_PCIE_3 = 7, /* PCIe controller lane 3 */
162 XPSGTR_TYPE_DP_0 = 8, /* Display Port controller lane 0 */
163 XPSGTR_TYPE_DP_1 = 9, /* Display Port controller lane 1 */
164 XPSGTR_TYPE_SGMII0 = 10, /* Ethernet SGMII controller 0 */
165 XPSGTR_TYPE_SGMII1 = 11, /* Ethernet SGMII controller 1 */
166 XPSGTR_TYPE_SGMII2 = 12, /* Ethernet SGMII controller 2 */
167 XPSGTR_TYPE_SGMII3 = 13, /* Ethernet SGMII controller 3 */
171 #define TIMEOUT_US 10000
173 #define IOU_SLCR_GEM_CLK_CTRL 0x308
174 #define GEM_CTRL_GEM_SGMII_MODE BIT(2)
175 #define GEM_CTRL_GEM_REF_SRC_SEL BIT(1)
177 #define IOU_SLCR_GEM_CTRL 0x360
178 #define GEM_CTRL_GEM_SGMII_SD BIT(0)
181 * struct xpsgtr_ssc - structure to hold SSC settings for a lane
182 * @refclk_rate: PLL reference clock frequency
183 * @pll_ref_clk: value to be written to register for corresponding ref clk rate
184 * @steps: number of steps of SSC (Spread Spectrum Clock)
185 * @step_size: step size of each step
195 * struct xpsgtr_phy - representation of a lane
196 * @dev: pointer to the xpsgtr_dev instance
197 * @refclk: reference clock index
198 * @type: controller which uses this lane
200 * @protocol: protocol in which the lane operates
203 struct xpsgtr_dev *dev;
211 * struct xpsgtr_dev - representation of a ZynMP GT device
212 * @dev: pointer to device
213 * @serdes: serdes base address
214 * @siou: siou base address
216 * @refclk_sscs: spread spectrum settings for the reference clocks
217 * @clk: reference clocks
223 struct xpsgtr_phy phys[NUM_LANES];
224 const struct xpsgtr_ssc *refclk_sscs[NUM_LANES];
225 struct clk clk[NUM_LANES];
228 /* Configuration Data */
229 /* lookup table to hold all settings needed for a ref clock frequency */
230 static const struct xpsgtr_ssc ssc_lookup[] = {
231 { 19200000, 0x05, 608, 264020 },
232 { 20000000, 0x06, 634, 243454 },
233 { 24000000, 0x07, 760, 168973 },
234 { 26000000, 0x08, 824, 143860 },
235 { 27000000, 0x09, 856, 86551 },
236 { 38400000, 0x0a, 1218, 65896 },
237 { 40000000, 0x0b, 634, 243454 },
238 { 52000000, 0x0c, 824, 143860 },
239 { 100000000, 0x0d, 1058, 87533 },
240 { 108000000, 0x0e, 856, 86551 },
241 { 125000000, 0x0f, 992, 119497 },
242 { 135000000, 0x10, 1070, 55393 },
243 { 150000000, 0x11, 792, 187091 }
247 static u32 xpsgtr_read(struct xpsgtr_dev *gtr_dev, u32 reg)
249 return readl(gtr_dev->serdes + reg);
252 static void xpsgtr_write(struct xpsgtr_dev *gtr_dev, u32 reg, u32 value)
254 writel(value, gtr_dev->serdes + reg);
257 static void xpsgtr_clr_set(struct xpsgtr_dev *gtr_dev, u32 reg,
260 u32 value = xpsgtr_read(gtr_dev, reg);
264 xpsgtr_write(gtr_dev, reg, value);
267 static u32 xpsgtr_read_phy(struct xpsgtr_phy *gtr_phy, u32 reg)
269 void __iomem *addr = gtr_phy->dev->serdes
270 + gtr_phy->lane * PHY_REG_OFFSET + reg;
275 static void xpsgtr_write_phy(struct xpsgtr_phy *gtr_phy,
278 void __iomem *addr = gtr_phy->dev->serdes
279 + gtr_phy->lane * PHY_REG_OFFSET + reg;
284 static void xpsgtr_clr_set_phy(struct xpsgtr_phy *gtr_phy,
285 u32 reg, u32 clr, u32 set)
287 void __iomem *addr = gtr_phy->dev->serdes
288 + gtr_phy->lane * PHY_REG_OFFSET + reg;
290 writel((readl(addr) & ~clr) | set, addr);
293 /* Configure PLL and spread-sprectrum clock. */
294 static void xpsgtr_configure_pll(struct xpsgtr_phy *gtr_phy)
296 const struct xpsgtr_ssc *ssc;
299 ssc = gtr_phy->dev->refclk_sscs[gtr_phy->refclk];
300 step_size = ssc->step_size;
302 xpsgtr_clr_set(gtr_phy->dev, PLL_REF_SEL(gtr_phy->lane),
303 PLL_FREQ_MASK, ssc->pll_ref_clk);
305 /* Enable lane clock sharing, if required */
306 if (gtr_phy->refclk != gtr_phy->lane) {
307 /* Lane3 Ref Clock Selection Register */
308 xpsgtr_clr_set(gtr_phy->dev, L0_Ln_REF_CLK_SEL(gtr_phy->lane),
309 L0_REF_CLK_SEL_MASK, 1 << gtr_phy->refclk);
312 /* SSC step size [7:0] */
313 xpsgtr_clr_set_phy(gtr_phy, L0_PLL_SS_STEP_SIZE_0_LSB,
314 STEP_SIZE_0_MASK, step_size & STEP_SIZE_0_MASK);
316 /* SSC step size [15:8] */
317 step_size >>= STEP_SIZE_SHIFT;
318 xpsgtr_clr_set_phy(gtr_phy, L0_PLL_SS_STEP_SIZE_1,
319 STEP_SIZE_1_MASK, step_size & STEP_SIZE_1_MASK);
321 /* SSC step size [23:16] */
322 step_size >>= STEP_SIZE_SHIFT;
323 xpsgtr_clr_set_phy(gtr_phy, L0_PLL_SS_STEP_SIZE_2,
324 STEP_SIZE_2_MASK, step_size & STEP_SIZE_2_MASK);
326 /* SSC steps [7:0] */
327 xpsgtr_clr_set_phy(gtr_phy, L0_PLL_SS_STEPS_0_LSB,
328 STEPS_0_MASK, ssc->steps & STEPS_0_MASK);
330 /* SSC steps [10:8] */
331 xpsgtr_clr_set_phy(gtr_phy, L0_PLL_SS_STEPS_1_MSB,
333 (ssc->steps >> STEP_SIZE_SHIFT) & STEPS_1_MASK);
335 /* SSC step size [24:25] */
336 step_size >>= STEP_SIZE_SHIFT;
337 xpsgtr_clr_set_phy(gtr_phy, L0_PLL_SS_STEP_SIZE_3_MSB,
338 STEP_SIZE_3_MASK, (step_size & STEP_SIZE_3_MASK) |
339 FORCE_STEP_SIZE | FORCE_STEPS);
342 /* Configure the lane protocol. */
343 static void xpsgtr_lane_set_protocol(struct xpsgtr_phy *gtr_phy)
345 struct xpsgtr_dev *gtr_dev = gtr_phy->dev;
346 u8 protocol = gtr_phy->protocol;
348 switch (gtr_phy->lane) {
350 xpsgtr_clr_set(gtr_dev, ICM_CFG0, ICM_CFG0_L0_MASK, protocol);
353 xpsgtr_clr_set(gtr_dev, ICM_CFG0, ICM_CFG0_L1_MASK,
354 protocol << ICM_CFG_SHIFT);
357 xpsgtr_clr_set(gtr_dev, ICM_CFG1, ICM_CFG0_L0_MASK, protocol);
360 xpsgtr_clr_set(gtr_dev, ICM_CFG1, ICM_CFG0_L1_MASK,
361 protocol << ICM_CFG_SHIFT);
364 /* We already checked 0 <= lane <= 3 */
369 /* Bypass (de)scrambler and 8b/10b decoder and encoder. */
370 static void xpsgtr_bypass_scrambler_8b10b(struct xpsgtr_phy *gtr_phy)
372 xpsgtr_write_phy(gtr_phy, L0_TM_DIG_6, L0_TM_DIS_DESCRAMBLE_DECODER);
373 xpsgtr_write_phy(gtr_phy, L0_TX_DIG_61, L0_TM_DISABLE_SCRAMBLE_ENCODER);
376 /* DP-specific initialization. */
377 static void xpsgtr_phy_init_dp(struct xpsgtr_phy *gtr_phy)
379 xpsgtr_write_phy(gtr_phy, L0_TXPMD_TM_45,
380 L0_TXPMD_TM_45_OVER_DP_MAIN |
381 L0_TXPMD_TM_45_ENABLE_DP_MAIN |
382 L0_TXPMD_TM_45_OVER_DP_POST1 |
383 L0_TXPMD_TM_45_OVER_DP_POST2 |
384 L0_TXPMD_TM_45_ENABLE_DP_POST2);
385 xpsgtr_write_phy(gtr_phy, L0_TX_ANA_TM_118,
386 L0_TX_ANA_TM_118_FORCE_17_0);
389 /* SATA-specific initialization. */
390 static void xpsgtr_phy_init_sata(struct xpsgtr_phy *gtr_phy)
392 struct xpsgtr_dev *gtr_dev = gtr_phy->dev;
394 xpsgtr_bypass_scrambler_8b10b(gtr_phy);
396 writel(gtr_phy->lane, gtr_dev->siou + SATA_CONTROL_OFFSET);
399 /* SGMII-specific initialization. */
400 static void xpsgtr_phy_init_sgmii(struct xpsgtr_phy *gtr_phy)
402 struct xpsgtr_dev *gtr_dev = gtr_phy->dev;
403 u32 shift = gtr_phy->lane * PROT_BUS_WIDTH_SHIFT;
405 /* Set SGMII protocol TX and RX bus width to 10 bits. */
406 xpsgtr_clr_set(gtr_dev, TX_PROT_BUS_WIDTH, PROT_BUS_WIDTH_MASK << shift,
407 PROT_BUS_WIDTH_10 << shift);
409 xpsgtr_clr_set(gtr_dev, RX_PROT_BUS_WIDTH, PROT_BUS_WIDTH_MASK << shift,
410 PROT_BUS_WIDTH_10 << shift);
412 xpsgtr_bypass_scrambler_8b10b(gtr_phy);
415 * Below code is just temporary solution till we have a way how to
416 * do it via firmware interface in sync with Linux. Till that happen
417 * this is the most sensible thing to do here.
419 /* GEM I/O Clock Control */
420 clrsetbits_le32(ZYNQMP_IOU_SLCR_BASEADDR + IOU_SLCR_GEM_CLK_CTRL,
422 (GEM_CTRL_GEM_SGMII_MODE | GEM_CTRL_GEM_REF_SRC_SEL) <<
425 /* Setup signal detect */
426 clrsetbits_le32(ZYNQMP_IOU_SLCR_BASEADDR + IOU_SLCR_GEM_CTRL,
427 PROT_BUS_WIDTH_MASK << shift,
428 GEM_CTRL_GEM_SGMII_SD << shift);
431 static int xpsgtr_init(struct phy *x)
433 struct xpsgtr_dev *gtr_dev = dev_get_priv(x->dev);
434 struct xpsgtr_phy *gtr_phy;
435 u32 phy_lane = x->id;
437 gtr_phy = >r_dev->phys[phy_lane];
439 /* Enable coarse code saturation limiting logic. */
440 xpsgtr_write_phy(gtr_phy, L0_TM_PLL_DIG_37, L0_TM_COARSE_CODE_LIMIT);
443 * Configure the PLL, the lane protocol, and perform protocol-specific
446 xpsgtr_configure_pll(gtr_phy);
447 xpsgtr_lane_set_protocol(gtr_phy);
449 switch (gtr_phy->protocol) {
450 case ICM_PROTOCOL_SGMII:
451 xpsgtr_phy_init_sgmii(gtr_phy);
453 case ICM_PROTOCOL_SATA:
454 xpsgtr_phy_init_sata(gtr_phy);
456 case ICM_PROTOCOL_DP:
457 xpsgtr_phy_init_dp(gtr_phy);
461 dev_dbg(gtr_dev->dev, "lane %u (type %u, protocol %u): init done\n",
462 gtr_phy->lane, gtr_phy->type, gtr_phy->protocol);
467 /* Wait for the PLL to lock (with a timeout). */
468 static int xpsgtr_wait_pll_lock(struct phy *phy)
470 struct xpsgtr_dev *gtr_dev = dev_get_priv(phy->dev);
471 struct xpsgtr_phy *gtr_phy;
472 u32 phy_lane = phy->id;
474 unsigned int timeout = TIMEOUT_US;
476 gtr_phy = >r_dev->phys[phy_lane];
478 dev_dbg(gtr_dev->dev, "Waiting for PLL lock\n");
481 u32 reg = xpsgtr_read_phy(gtr_phy, L0_PLL_STATUS_READ_1);
483 if ((reg & PLL_STATUS_LOCKED) == PLL_STATUS_LOCKED) {
488 if (--timeout == 0) {
496 if (ret == -ETIMEDOUT)
497 dev_err(gtr_dev->dev,
498 "lane %u (type %u, protocol %u): PLL lock timeout\n",
499 gtr_phy->lane, gtr_phy->type, gtr_phy->protocol);
504 static int xpsgtr_power_on(struct phy *phy)
506 struct xpsgtr_dev *gtr_dev = dev_get_priv(phy->dev);
507 struct xpsgtr_phy *gtr_phy;
508 u32 phy_lane = phy->id;
511 gtr_phy = >r_dev->phys[phy_lane];
514 * Wait for the PLL to lock. For DP, only wait on DP0 to avoid
515 * cumulating waits for both lanes. The user is expected to initialize
518 if (gtr_phy->protocol != ICM_PROTOCOL_DP ||
519 gtr_phy->type == XPSGTR_TYPE_DP_0)
520 ret = xpsgtr_wait_pll_lock(phy);
529 /* Set the lane type and protocol based on the PHY type and instance number. */
530 static int xpsgtr_set_lane_type(struct xpsgtr_phy *gtr_phy, u8 phy_type,
531 unsigned int phy_instance)
533 unsigned int num_phy_types;
534 const int *phy_types;
537 case PHY_TYPE_SATA: {
538 static const int types[] = {
544 num_phy_types = ARRAY_SIZE(types);
545 gtr_phy->protocol = ICM_PROTOCOL_SATA;
548 case PHY_TYPE_USB3: {
549 static const int types[] = {
555 num_phy_types = ARRAY_SIZE(types);
556 gtr_phy->protocol = ICM_PROTOCOL_USB;
560 static const int types[] = {
566 num_phy_types = ARRAY_SIZE(types);
567 gtr_phy->protocol = ICM_PROTOCOL_DP;
570 case PHY_TYPE_PCIE: {
571 static const int types[] = {
579 num_phy_types = ARRAY_SIZE(types);
580 gtr_phy->protocol = ICM_PROTOCOL_PCIE;
583 case PHY_TYPE_SGMII: {
584 static const int types[] = {
592 num_phy_types = ARRAY_SIZE(types);
593 gtr_phy->protocol = ICM_PROTOCOL_SGMII;
600 if (phy_instance >= num_phy_types)
603 gtr_phy->type = phy_types[phy_instance];
608 * Valid combinations of controllers and lanes (Interconnect Matrix).
610 static const unsigned int icm_matrix[NUM_LANES][CONTROLLERS_PER_LANE] = {
611 { XPSGTR_TYPE_PCIE_0, XPSGTR_TYPE_SATA_0, XPSGTR_TYPE_USB0,
612 XPSGTR_TYPE_DP_1, XPSGTR_TYPE_SGMII0 },
613 { XPSGTR_TYPE_PCIE_1, XPSGTR_TYPE_SATA_1, XPSGTR_TYPE_USB0,
614 XPSGTR_TYPE_DP_0, XPSGTR_TYPE_SGMII1 },
615 { XPSGTR_TYPE_PCIE_2, XPSGTR_TYPE_SATA_0, XPSGTR_TYPE_USB0,
616 XPSGTR_TYPE_DP_1, XPSGTR_TYPE_SGMII2 },
617 { XPSGTR_TYPE_PCIE_3, XPSGTR_TYPE_SATA_1, XPSGTR_TYPE_USB1,
618 XPSGTR_TYPE_DP_0, XPSGTR_TYPE_SGMII3 }
621 /* Translate OF phandle and args to PHY instance. */
622 static int xpsgtr_of_xlate(struct phy *x,
623 struct ofnode_phandle_args *args)
625 struct xpsgtr_dev *gtr_dev = dev_get_priv(x->dev);
626 struct xpsgtr_phy *gtr_phy;
627 struct udevice *dev = x->dev;
628 unsigned int phy_instance;
629 unsigned int phy_lane;
630 unsigned int phy_type;
635 if (args->args_count != 4) {
636 dev_err(dev, "Invalid number of cells in 'phy' property\n");
641 * Get the PHY parameters from the OF arguments and derive the lane
644 phy_lane = args->args[0];
645 if (phy_lane >= NUM_LANES) {
646 dev_err(dev, "Invalid lane number %u\n", phy_lane);
650 gtr_phy = >r_dev->phys[phy_lane];
651 phy_type = args->args[1];
652 phy_instance = args->args[2];
654 ret = xpsgtr_set_lane_type(gtr_phy, phy_type, phy_instance);
656 dev_err(dev, "Invalid PHY type and/or instance\n");
660 refclk = args->args[3];
661 if (refclk >= ARRAY_SIZE(gtr_dev->refclk_sscs) ||
662 !gtr_dev->refclk_sscs[refclk]) {
663 dev_err(dev, "Invalid reference clock number %u\n", refclk);
667 gtr_phy->refclk = refclk;
669 /* This is difference compare to Linux */
670 gtr_phy->dev = gtr_dev;
671 gtr_phy->lane = phy_lane;
674 * Ensure that the Interconnect Matrix is obeyed, i.e a given lane type
675 * is allowed to operate on the lane.
677 for (i = 0; i < CONTROLLERS_PER_LANE; i++) {
678 if (icm_matrix[phy_lane][i] == gtr_phy->type) {
688 * Probe & Platform Driver
690 static int xpsgtr_get_ref_clocks(struct udevice *dev)
693 struct xpsgtr_dev *gtr_dev = dev_get_priv(dev);
696 for (refclk = 0; refclk < NUM_LANES; ++refclk) {
700 struct clk *clk = >r_dev->clk[refclk];
702 snprintf(name, sizeof(name), "ref%u", refclk);
703 dev_dbg(dev, "Checking name: %s\n", name);
704 ret = clk_get_by_name(dev, name, clk);
705 if (ret == -ENODATA) {
706 dev_dbg(dev, "%s clock not specified (err %d)\n",
710 dev_dbg(dev, "couldn't get clock %s (err %d)\n",
715 rate = clk_get_rate(clk);
717 dev_dbg(dev, "clk rate %d\n", rate);
719 ret = clk_enable(clk);
721 dev_err(dev, "failed to enable refclk %d clock\n",
726 for (i = 0 ; i < ARRAY_SIZE(ssc_lookup); i++) {
727 if (rate == ssc_lookup[i].refclk_rate) {
728 gtr_dev->refclk_sscs[refclk] = &ssc_lookup[i];
729 dev_dbg(dev, "Found rate %d\n", i);
734 if (i == ARRAY_SIZE(ssc_lookup)) {
736 "Invalid rate %u for reference clock %u\n",
745 static int xpsgtr_probe(struct udevice *dev)
747 struct xpsgtr_dev *gtr_dev = dev_get_priv(dev);
749 gtr_dev->serdes = dev_remap_addr_name(dev, "serdes");
750 if (!gtr_dev->serdes)
753 gtr_dev->siou = dev_remap_addr_name(dev, "siou");
759 return xpsgtr_get_ref_clocks(dev);
762 static const struct udevice_id xpsgtr_phy_ids[] = {
763 { .compatible = "xlnx,zynqmp-psgtr-v1.1", },
767 static const struct phy_ops xpsgtr_phy_ops = {
769 .of_xlate = xpsgtr_of_xlate,
770 .power_on = xpsgtr_power_on,
773 U_BOOT_DRIVER(psgtr_phy) = {
776 .of_match = xpsgtr_phy_ids,
777 .ops = &xpsgtr_phy_ops,
778 .probe = xpsgtr_probe,
779 .priv_auto = sizeof(struct xpsgtr_dev),