1 // SPDX-License-Identifier: GPL-2.0+
9 #include <asm/arch/fsl_serdes.h>
16 #include <fsl-mc/fsl_mc.h>
17 #include <fsl-mc/ldpaa_wriop.h>
19 #include "../common/qixis.h"
21 #include "ls1088a_qixis.h"
23 #ifdef CONFIG_FSL_MC_ENET
27 /* - In LS1088A A there are only 16 SERDES lanes, spread across 2 SERDES banks.
28 * Bank 1 -> Lanes A, B, C, D,
29 * Bank 2 -> Lanes A,B, C, D,
32 /* Mapping of 8 SERDES lanes to LS1088A QDS board slots. A value of '0' here
33 * means that the mapping must be determined dynamically, or that the lane
34 * maps to something other than a board slot.
37 static u8 lane_to_slot_fsm1[] = {
38 0, 0, 0, 0, 0, 0, 0, 0
41 /* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs
45 static int xqsgii_riser_phy_addr[] = {
46 XQSGMII_CARD_PHY1_PORT0_ADDR,
47 XQSGMII_CARD_PHY2_PORT0_ADDR,
48 XQSGMII_CARD_PHY3_PORT0_ADDR,
49 XQSGMII_CARD_PHY4_PORT0_ADDR,
50 XQSGMII_CARD_PHY3_PORT2_ADDR,
51 XQSGMII_CARD_PHY1_PORT2_ADDR,
52 XQSGMII_CARD_PHY4_PORT2_ADDR,
53 XQSGMII_CARD_PHY2_PORT2_ADDR,
56 static int sgmii_riser_phy_addr[] = {
57 SGMII_CARD_PORT1_PHY_ADDR,
58 SGMII_CARD_PORT2_PHY_ADDR,
59 SGMII_CARD_PORT3_PHY_ADDR,
60 SGMII_CARD_PORT4_PHY_ADDR,
63 /* Slot2 does not have EMI connections */
69 static const char * const mdio_names[] = {
73 DEFAULT_WRIOP_MDIO2_NAME,
76 struct ls1088a_qds_mdio {
78 struct mii_dev *realbus;
81 static void sgmii_configure_repeater(int dpmac)
87 const char *dev = "LS1088A_QDS_MDIO2";
88 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
92 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
93 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
94 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
95 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
97 /* Set I2c to Slot 1 */
98 i2c_write(0x77, 0, 0, &a, 1);
102 i2c_phy_addr = i2c_addr[1];
106 i2c_phy_addr = i2c_addr[0];
110 i2c_phy_addr = i2c_addr[3];
114 i2c_phy_addr = i2c_addr[2];
119 /* Check the PHY status */
120 ret = miiphy_set_current_dev(dev);
124 bus = mdio_get_current_dev();
125 debug("Reading from bus %s\n", bus->name);
127 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
132 ret = miiphy_read(dev, phy_addr, 0x11, &value);
138 if ((value & 0xfff) == 0x401) {
139 miiphy_write(dev, phy_addr, 0x1f, 0);
140 printf("DPMAC %d:PHY is ..... Configured\n", dpmac);
144 for (i = 0; i < 4; i++) {
145 for (j = 0; j < 4; j++) {
147 i2c_write(i2c_phy_addr, 6, 1, &a, 1);
149 i2c_write(i2c_phy_addr, 4, 1, &a, 1);
151 i2c_write(i2c_phy_addr, 8, 1, &a, 1);
153 i2c_write(i2c_phy_addr, 0xf, 1,
155 i2c_write(i2c_phy_addr, 0x11, 1,
158 i2c_write(i2c_phy_addr, 0x16, 1,
160 i2c_write(i2c_phy_addr, 0x18, 1,
164 i2c_write(i2c_phy_addr, 0x23, 1, &a, 1);
166 i2c_write(i2c_phy_addr, 0x2d, 1, &a, 1);
168 i2c_write(i2c_phy_addr, 4, 1, &a, 1);
170 ret = miiphy_read(dev, phy_addr, 0x11, &value);
175 ret = miiphy_read(dev, phy_addr, 0x11, &value);
179 if ((value & 0xfff) == 0x401) {
180 printf("DPMAC %d :PHY is configured ",
182 printf("after setting repeater 0x%x\n",
187 printf("DPMAC %d :PHY is failed to ",
189 printf("configure the repeater 0x%x\n", value);
193 miiphy_write(dev, phy_addr, 0x1f, 0);
196 printf("DPMAC %d ..... FAILED to configure PHY\n", dpmac);
200 static void qsgmii_configure_repeater(int dpmac)
204 int i2c_phy_addr = 0;
206 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
208 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
209 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
210 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
211 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
213 const char *dev = mdio_names[EMI1_SLOT1];
215 unsigned short value;
217 /* Set I2c to Slot 1 */
218 i2c_write(0x77, 0, 0, &a, 1);
225 i2c_phy_addr = i2c_addr[2];
233 i2c_phy_addr = i2c_addr[3];
238 /* Check the PHY status */
239 ret = miiphy_set_current_dev(dev);
240 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
242 ret = miiphy_read(dev, phy_addr, 0x11, &value);
244 ret = miiphy_read(dev, phy_addr, 0x11, &value);
246 if ((value & 0xf) == 0xf) {
247 miiphy_write(dev, phy_addr, 0x1f, 0);
248 printf("DPMAC %d :PHY is ..... Configured\n", dpmac);
252 for (i = 0; i < 4; i++) {
253 for (j = 0; j < 4; j++) {
255 i2c_write(i2c_phy_addr, 6, 1, &a, 1);
257 i2c_write(i2c_phy_addr, 4, 1, &a, 1);
259 i2c_write(i2c_phy_addr, 8, 1, &a, 1);
261 i2c_write(i2c_phy_addr, 0xf, 1, &ch_a_eq[i], 1);
262 i2c_write(i2c_phy_addr, 0x11, 1, &ch_a_ctl2[j], 1);
264 i2c_write(i2c_phy_addr, 0x16, 1, &ch_b_eq[i], 1);
265 i2c_write(i2c_phy_addr, 0x18, 1, &ch_b_ctl2[j], 1);
268 i2c_write(i2c_phy_addr, 0x23, 1, &a, 1);
270 i2c_write(i2c_phy_addr, 0x2d, 1, &a, 1);
272 i2c_write(i2c_phy_addr, 4, 1, &a, 1);
274 ret = miiphy_read(dev, phy_addr, 0x11, &value);
278 ret = miiphy_read(dev, phy_addr, 0x11, &value);
282 if ((value & 0xf) == 0xf) {
283 miiphy_write(dev, phy_addr, 0x1f, 0);
284 printf("DPMAC %d :PHY is ..... Configured\n",
291 printf("DPMAC %d :PHY ..... FAILED to configure PHY\n", dpmac);
295 static const char *ls1088a_qds_mdio_name_for_muxval(u8 muxval)
297 return mdio_names[muxval];
300 struct mii_dev *mii_dev_for_muxval(u8 muxval)
303 const char *name = ls1088a_qds_mdio_name_for_muxval(muxval);
306 printf("No bus for muxval %x\n", muxval);
310 bus = miiphy_get_dev_by_name(name);
313 printf("No bus by name %s\n", name);
320 static void ls1088a_qds_enable_SFP_TX(u8 muxval)
324 brdcfg9 = QIXIS_READ(brdcfg[9]);
325 brdcfg9 &= ~BRDCFG9_SFPTX_MASK;
326 brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT);
327 QIXIS_WRITE(brdcfg[9], brdcfg9);
330 static void ls1088a_qds_mux_mdio(u8 muxval)
335 brdcfg4 = QIXIS_READ(brdcfg[4]);
336 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
337 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
338 QIXIS_WRITE(brdcfg[4], brdcfg4);
342 static int ls1088a_qds_mdio_read(struct mii_dev *bus, int addr,
343 int devad, int regnum)
345 struct ls1088a_qds_mdio *priv = bus->priv;
347 ls1088a_qds_mux_mdio(priv->muxval);
349 return priv->realbus->read(priv->realbus, addr, devad, regnum);
352 static int ls1088a_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
353 int regnum, u16 value)
355 struct ls1088a_qds_mdio *priv = bus->priv;
357 ls1088a_qds_mux_mdio(priv->muxval);
359 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
362 static int ls1088a_qds_mdio_reset(struct mii_dev *bus)
364 struct ls1088a_qds_mdio *priv = bus->priv;
366 return priv->realbus->reset(priv->realbus);
369 static int ls1088a_qds_mdio_init(char *realbusname, u8 muxval)
371 struct ls1088a_qds_mdio *pmdio;
372 struct mii_dev *bus = mdio_alloc();
375 printf("Failed to allocate ls1088a_qds MDIO bus\n");
379 pmdio = malloc(sizeof(*pmdio));
381 printf("Failed to allocate ls1088a_qds private data\n");
386 bus->read = ls1088a_qds_mdio_read;
387 bus->write = ls1088a_qds_mdio_write;
388 bus->reset = ls1088a_qds_mdio_reset;
389 sprintf(bus->name, ls1088a_qds_mdio_name_for_muxval(muxval));
391 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
393 if (!pmdio->realbus) {
394 printf("No bus with name %s\n", realbusname);
400 pmdio->muxval = muxval;
403 return mdio_register(bus);
407 * Initialize the dpmac_info array.
410 static void initialize_dpmac_to_slot(void)
412 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
413 u32 serdes1_prtcl, cfg;
415 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
416 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
417 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
418 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
420 switch (serdes1_prtcl) {
422 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
424 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
425 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
426 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
427 lane_to_slot_fsm1[3] = EMI1_SLOT1 - 1;
431 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
433 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
434 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
435 lane_to_slot_fsm1[2] = EMI_NONE;
436 lane_to_slot_fsm1[3] = EMI_NONE;
439 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
441 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
442 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
443 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
444 lane_to_slot_fsm1[3] = EMI_NONE;
447 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
449 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
450 lane_to_slot_fsm1[1] = EMI_NONE;
451 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
452 lane_to_slot_fsm1[3] = EMI1_SLOT1 - 1;
456 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
457 __func__, serdes1_prtcl);
462 void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
465 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
466 u32 serdes1_prtcl, cfg;
468 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
469 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
470 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
471 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
474 char *env_hwconfig = env_get("hwconfig");
476 if (hwconfig_f("xqsgmii", env_hwconfig))
477 riser_phy_addr = &xqsgii_riser_phy_addr[0];
479 riser_phy_addr = &sgmii_riser_phy_addr[0];
481 switch (serdes1_prtcl) {
488 wriop_set_phy_address(dpmac_id, riser_phy_addr[1]);
491 wriop_set_phy_address(dpmac_id, riser_phy_addr[0]);
494 wriop_set_phy_address(dpmac_id, riser_phy_addr[3]);
497 wriop_set_phy_address(dpmac_id, riser_phy_addr[2]);
500 printf("WRIOP: Wrong DPMAC%d set to SGMII", dpmac_id);
505 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
506 __func__, serdes1_prtcl);
509 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
510 bus = mii_dev_for_muxval(EMI1_SLOT1);
511 wriop_set_mdio(dpmac_id, bus);
514 void ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
517 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
518 u32 serdes1_prtcl, cfg;
520 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
521 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
522 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
523 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
525 switch (serdes1_prtcl) {
533 wriop_set_phy_address(dpmac_id, dpmac_id + 9);
539 wriop_set_phy_address(dpmac_id, dpmac_id + 1);
543 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
544 bus = mii_dev_for_muxval(EMI1_SLOT1);
545 wriop_set_mdio(dpmac_id, bus);
548 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
554 void ls1088a_handle_phy_interface_xsgmii(int i)
556 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
557 u32 serdes1_prtcl, cfg;
559 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
560 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
561 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
562 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
564 switch (serdes1_prtcl) {
568 wriop_set_phy_address(i, i + 26);
569 ls1088a_qds_enable_SFP_TX(SFP_TX);
572 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
578 static void ls1088a_handle_phy_interface_rgmii(int dpmac_id)
580 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
581 u32 serdes1_prtcl, cfg;
584 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
585 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
586 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
587 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
591 wriop_set_phy_address(dpmac_id, RGMII_PHY1_ADDR);
592 dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
593 bus = mii_dev_for_muxval(EMI1_RGMII1);
594 wriop_set_mdio(dpmac_id, bus);
597 wriop_set_phy_address(dpmac_id, RGMII_PHY2_ADDR);
598 dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
599 bus = mii_dev_for_muxval(EMI1_RGMII2);
600 wriop_set_mdio(dpmac_id, bus);
603 printf("qds: WRIOP: Unsupported RGMII SerDes Protocol 0x%02x\n",
610 int board_eth_init(bd_t *bis)
613 #ifdef CONFIG_FSL_MC_ENET
614 struct memac_mdio_info *memac_mdio0_info;
615 char *env_hwconfig = env_get("hwconfig");
617 initialize_dpmac_to_slot();
619 memac_mdio0_info = (struct memac_mdio_info *)malloc(
620 sizeof(struct memac_mdio_info));
621 memac_mdio0_info->regs =
622 (struct memac_mdio_controller *)
623 CONFIG_SYS_FSL_WRIOP1_MDIO1;
624 memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
626 /* Register the real MDIO1 bus */
627 fm_memac_mdio_init(bis, memac_mdio0_info);
628 /* Register the muxing front-ends to the MDIO buses */
629 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_RGMII1);
630 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_RGMII2);
631 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
633 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
634 switch (wriop_get_enet_if(i)) {
635 case PHY_INTERFACE_MODE_RGMII:
636 case PHY_INTERFACE_MODE_RGMII_ID:
637 ls1088a_handle_phy_interface_rgmii(i);
639 case PHY_INTERFACE_MODE_QSGMII:
640 ls1088a_handle_phy_interface_qsgmii(i);
642 case PHY_INTERFACE_MODE_SGMII:
643 ls1088a_handle_phy_interface_sgmii(i);
645 case PHY_INTERFACE_MODE_XGMII:
646 ls1088a_handle_phy_interface_xsgmii(i);
656 error = cpu_eth_init(bis);
658 if (hwconfig_f("xqsgmii", env_hwconfig)) {
659 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
660 switch (wriop_get_enet_if(i)) {
661 case PHY_INTERFACE_MODE_QSGMII:
662 qsgmii_configure_repeater(i);
664 case PHY_INTERFACE_MODE_SGMII:
665 sgmii_configure_repeater(i);
676 error = pci_eth_init(bis);
680 #if defined(CONFIG_RESET_PHY_R)
685 #endif /* CONFIG_RESET_PHY_R */