1 // SPDX-License-Identifier: GPL-2.0+
13 #include <asm/arch/fsl_serdes.h>
21 #include <fsl-mc/fsl_mc.h>
22 #include <fsl-mc/ldpaa_wriop.h>
23 #include <linux/delay.h>
25 #include "../common/qixis.h"
27 #include "ls1088a_qixis.h"
29 #ifdef CONFIG_FSL_MC_ENET
33 /* - In LS1088A A there are only 16 SERDES lanes, spread across 2 SERDES banks.
34 * Bank 1 -> Lanes A, B, C, D,
35 * Bank 2 -> Lanes A,B, C, D,
38 /* Mapping of 8 SERDES lanes to LS1088A QDS board slots. A value of '0' here
39 * means that the mapping must be determined dynamically, or that the lane
40 * maps to something other than a board slot.
43 static u8 lane_to_slot_fsm1[] = {
44 0, 0, 0, 0, 0, 0, 0, 0
47 /* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs
51 static int xqsgii_riser_phy_addr[] = {
52 XQSGMII_CARD_PHY1_PORT0_ADDR,
53 XQSGMII_CARD_PHY2_PORT0_ADDR,
54 XQSGMII_CARD_PHY3_PORT0_ADDR,
55 XQSGMII_CARD_PHY4_PORT0_ADDR,
56 XQSGMII_CARD_PHY3_PORT2_ADDR,
57 XQSGMII_CARD_PHY1_PORT2_ADDR,
58 XQSGMII_CARD_PHY4_PORT2_ADDR,
59 XQSGMII_CARD_PHY2_PORT2_ADDR,
62 static int sgmii_riser_phy_addr[] = {
63 SGMII_CARD_PORT1_PHY_ADDR,
64 SGMII_CARD_PORT2_PHY_ADDR,
65 SGMII_CARD_PORT3_PHY_ADDR,
66 SGMII_CARD_PORT4_PHY_ADDR,
69 /* Slot2 does not have EMI connections */
75 static const char * const mdio_names[] = {
79 DEFAULT_WRIOP_MDIO2_NAME,
82 struct ls1088a_qds_mdio {
84 struct mii_dev *realbus;
92 static void sgmii_configure_repeater(int dpmac)
98 const char *dev = "LS1088A_QDS_MDIO2";
99 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
100 int i2c_phy_addr = 0;
103 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
104 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
105 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
106 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
108 u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
109 struct reg_pair reg_pair[10] = {
110 {6, ®_val[0]}, {4, ®_val[1]},
111 {8, ®_val[2]}, {0xf, NULL},
112 {0x11, NULL}, {0x16, NULL},
113 {0x18, NULL}, {0x23, ®_val[3]},
114 {0x2d, ®_val[4]}, {4, ®_val[5]},
117 struct udevice *udev;
120 /* Set I2c to Slot 1 */
121 #ifndef CONFIG_DM_I2C
122 ret = i2c_write(0x77, 0, 0, &a, 1);
124 ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
126 ret = dm_i2c_write(udev, 0, &a, 1);
133 i2c_phy_addr = i2c_addr[1];
137 i2c_phy_addr = i2c_addr[0];
141 i2c_phy_addr = i2c_addr[3];
145 i2c_phy_addr = i2c_addr[2];
150 /* Check the PHY status */
151 ret = miiphy_set_current_dev(dev);
155 bus = mdio_get_current_dev();
156 debug("Reading from bus %s\n", bus->name);
158 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
163 ret = miiphy_read(dev, phy_addr, 0x11, &value);
169 if ((value & 0xfff) == 0x401) {
170 miiphy_write(dev, phy_addr, 0x1f, 0);
171 printf("DPMAC %d:PHY is ..... Configured\n", dpmac);
176 i2c_get_chip_for_busnum(0, i2c_phy_addr, 1, &udev);
179 for (i = 0; i < 4; i++) {
180 for (j = 0; j < 4; j++) {
181 reg_pair[3].val = &ch_a_eq[i];
182 reg_pair[4].val = &ch_a_ctl2[j];
183 reg_pair[5].val = &ch_b_eq[i];
184 reg_pair[6].val = &ch_b_ctl2[j];
185 for (k = 0; k < 10; k++) {
186 #ifndef CONFIG_DM_I2C
187 ret = i2c_write(i2c_phy_addr,
189 1, reg_pair[k].val, 1);
191 ret = i2c_get_chip_for_busnum(0,
195 ret = dm_i2c_write(udev,
204 ret = miiphy_read(dev, phy_addr, 0x11, &value);
209 ret = miiphy_read(dev, phy_addr, 0x11, &value);
213 if ((value & 0xfff) == 0x401) {
214 printf("DPMAC %d :PHY is configured ",
216 printf("after setting repeater 0x%x\n",
221 printf("DPMAC %d :PHY is failed to ",
223 printf("configure the repeater 0x%x\n", value);
227 miiphy_write(dev, phy_addr, 0x1f, 0);
230 printf("DPMAC %d ..... FAILED to configure PHY\n", dpmac);
234 static void qsgmii_configure_repeater(int dpmac)
238 int i2c_phy_addr = 0;
240 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
242 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
243 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
244 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
245 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
247 u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
248 struct reg_pair reg_pair[10] = {
249 {6, ®_val[0]}, {4, ®_val[1]},
250 {8, ®_val[2]}, {0xf, NULL},
251 {0x11, NULL}, {0x16, NULL},
252 {0x18, NULL}, {0x23, ®_val[3]},
253 {0x2d, ®_val[4]}, {4, ®_val[5]},
256 const char *dev = mdio_names[EMI1_SLOT1];
258 unsigned short value;
260 struct udevice *udev;
263 /* Set I2c to Slot 1 */
264 #ifndef CONFIG_DM_I2C
265 ret = i2c_write(0x77, 0, 0, &a, 1);
267 ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
269 ret = dm_i2c_write(udev, 0, &a, 1);
279 i2c_phy_addr = i2c_addr[2];
287 i2c_phy_addr = i2c_addr[3];
292 /* Check the PHY status */
293 ret = miiphy_set_current_dev(dev);
294 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
296 ret = miiphy_read(dev, phy_addr, 0x11, &value);
298 ret = miiphy_read(dev, phy_addr, 0x11, &value);
300 if ((value & 0xf) == 0xf) {
301 miiphy_write(dev, phy_addr, 0x1f, 0);
302 printf("DPMAC %d :PHY is ..... Configured\n", dpmac);
307 i2c_get_chip_for_busnum(0, i2c_phy_addr, 1, &udev);
310 for (i = 0; i < 4; i++) {
311 for (j = 0; j < 4; j++) {
312 reg_pair[3].val = &ch_a_eq[i];
313 reg_pair[4].val = &ch_a_ctl2[j];
314 reg_pair[5].val = &ch_b_eq[i];
315 reg_pair[6].val = &ch_b_ctl2[j];
317 for (k = 0; k < 10; k++) {
318 #ifndef CONFIG_DM_I2C
319 ret = i2c_write(i2c_phy_addr,
321 1, reg_pair[k].val, 1);
323 ret = i2c_get_chip_for_busnum(0,
327 ret = dm_i2c_write(udev,
335 ret = miiphy_read(dev, phy_addr, 0x11, &value);
339 ret = miiphy_read(dev, phy_addr, 0x11, &value);
343 if ((value & 0xf) == 0xf) {
344 miiphy_write(dev, phy_addr, 0x1f, 0);
345 printf("DPMAC %d :PHY is ..... Configured\n",
352 printf("DPMAC %d :PHY ..... FAILED to configure PHY\n", dpmac);
356 static const char *ls1088a_qds_mdio_name_for_muxval(u8 muxval)
358 return mdio_names[muxval];
361 struct mii_dev *mii_dev_for_muxval(u8 muxval)
364 const char *name = ls1088a_qds_mdio_name_for_muxval(muxval);
367 printf("No bus for muxval %x\n", muxval);
371 bus = miiphy_get_dev_by_name(name);
374 printf("No bus by name %s\n", name);
381 static void ls1088a_qds_enable_SFP_TX(u8 muxval)
385 brdcfg9 = QIXIS_READ(brdcfg[9]);
386 brdcfg9 &= ~BRDCFG9_SFPTX_MASK;
387 brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT);
388 QIXIS_WRITE(brdcfg[9], brdcfg9);
391 static void ls1088a_qds_mux_mdio(u8 muxval)
396 brdcfg4 = QIXIS_READ(brdcfg[4]);
397 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
398 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
399 QIXIS_WRITE(brdcfg[4], brdcfg4);
403 static int ls1088a_qds_mdio_read(struct mii_dev *bus, int addr,
404 int devad, int regnum)
406 struct ls1088a_qds_mdio *priv = bus->priv;
408 ls1088a_qds_mux_mdio(priv->muxval);
410 return priv->realbus->read(priv->realbus, addr, devad, regnum);
413 static int ls1088a_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
414 int regnum, u16 value)
416 struct ls1088a_qds_mdio *priv = bus->priv;
418 ls1088a_qds_mux_mdio(priv->muxval);
420 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
423 static int ls1088a_qds_mdio_reset(struct mii_dev *bus)
425 struct ls1088a_qds_mdio *priv = bus->priv;
427 return priv->realbus->reset(priv->realbus);
430 static int ls1088a_qds_mdio_init(char *realbusname, u8 muxval)
432 struct ls1088a_qds_mdio *pmdio;
433 struct mii_dev *bus = mdio_alloc();
436 printf("Failed to allocate ls1088a_qds MDIO bus\n");
440 pmdio = malloc(sizeof(*pmdio));
442 printf("Failed to allocate ls1088a_qds private data\n");
447 bus->read = ls1088a_qds_mdio_read;
448 bus->write = ls1088a_qds_mdio_write;
449 bus->reset = ls1088a_qds_mdio_reset;
450 sprintf(bus->name, ls1088a_qds_mdio_name_for_muxval(muxval));
452 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
454 if (!pmdio->realbus) {
455 printf("No bus with name %s\n", realbusname);
461 pmdio->muxval = muxval;
464 return mdio_register(bus);
468 * Initialize the dpmac_info array.
471 static void initialize_dpmac_to_slot(void)
473 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
474 u32 serdes1_prtcl, cfg;
476 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
477 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
478 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
479 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
481 switch (serdes1_prtcl) {
483 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
485 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
486 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
487 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
488 lane_to_slot_fsm1[3] = EMI1_SLOT1 - 1;
492 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
494 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
495 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
496 lane_to_slot_fsm1[2] = EMI_NONE;
497 lane_to_slot_fsm1[3] = EMI_NONE;
500 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
502 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
503 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
504 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
505 lane_to_slot_fsm1[3] = EMI_NONE;
508 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
510 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
511 lane_to_slot_fsm1[1] = EMI_NONE;
512 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
513 lane_to_slot_fsm1[3] = EMI1_SLOT1 - 1;
517 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
518 __func__, serdes1_prtcl);
523 void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
526 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
527 u32 serdes1_prtcl, cfg;
529 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
530 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
531 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
532 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
535 char *env_hwconfig = env_get("hwconfig");
537 if (hwconfig_f("xqsgmii", env_hwconfig))
538 riser_phy_addr = &xqsgii_riser_phy_addr[0];
540 riser_phy_addr = &sgmii_riser_phy_addr[0];
542 switch (serdes1_prtcl) {
549 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[1]);
552 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[0]);
555 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[3]);
558 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[2]);
561 printf("WRIOP: Wrong DPMAC%d set to SGMII", dpmac_id);
566 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
567 __func__, serdes1_prtcl);
570 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
571 bus = mii_dev_for_muxval(EMI1_SLOT1);
572 wriop_set_mdio(dpmac_id, bus);
575 void ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
578 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
579 u32 serdes1_prtcl, cfg;
581 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
582 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
583 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
584 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
586 switch (serdes1_prtcl) {
594 wriop_set_phy_address(dpmac_id, 0, dpmac_id + 9);
600 wriop_set_phy_address(dpmac_id, 0, dpmac_id + 1);
604 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
605 bus = mii_dev_for_muxval(EMI1_SLOT1);
606 wriop_set_mdio(dpmac_id, bus);
609 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
615 void ls1088a_handle_phy_interface_xsgmii(int i)
617 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
618 u32 serdes1_prtcl, cfg;
620 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
621 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
622 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
623 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
625 switch (serdes1_prtcl) {
629 wriop_set_phy_address(i, 0, i + 26);
630 ls1088a_qds_enable_SFP_TX(SFP_TX);
633 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
639 static void ls1088a_handle_phy_interface_rgmii(int dpmac_id)
641 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
642 u32 serdes1_prtcl, cfg;
645 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
646 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
647 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
648 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
652 wriop_set_phy_address(dpmac_id, 0, RGMII_PHY1_ADDR);
653 dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
654 bus = mii_dev_for_muxval(EMI1_RGMII1);
655 wriop_set_mdio(dpmac_id, bus);
658 wriop_set_phy_address(dpmac_id, 0, RGMII_PHY2_ADDR);
659 dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
660 bus = mii_dev_for_muxval(EMI1_RGMII2);
661 wriop_set_mdio(dpmac_id, bus);
664 printf("qds: WRIOP: Unsupported RGMII SerDes Protocol 0x%02x\n",
671 int board_eth_init(bd_t *bis)
674 #ifdef CONFIG_FSL_MC_ENET
675 struct memac_mdio_info *memac_mdio0_info;
676 char *env_hwconfig = env_get("hwconfig");
678 initialize_dpmac_to_slot();
680 memac_mdio0_info = (struct memac_mdio_info *)malloc(
681 sizeof(struct memac_mdio_info));
682 memac_mdio0_info->regs =
683 (struct memac_mdio_controller *)
684 CONFIG_SYS_FSL_WRIOP1_MDIO1;
685 memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
687 /* Register the real MDIO1 bus */
688 fm_memac_mdio_init(bis, memac_mdio0_info);
689 /* Register the muxing front-ends to the MDIO buses */
690 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_RGMII1);
691 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_RGMII2);
692 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
694 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
695 switch (wriop_get_enet_if(i)) {
696 case PHY_INTERFACE_MODE_RGMII:
697 case PHY_INTERFACE_MODE_RGMII_ID:
698 ls1088a_handle_phy_interface_rgmii(i);
700 case PHY_INTERFACE_MODE_QSGMII:
701 ls1088a_handle_phy_interface_qsgmii(i);
703 case PHY_INTERFACE_MODE_SGMII:
704 ls1088a_handle_phy_interface_sgmii(i);
706 case PHY_INTERFACE_MODE_XGMII:
707 ls1088a_handle_phy_interface_xsgmii(i);
717 error = cpu_eth_init(bis);
719 if (hwconfig_f("xqsgmii", env_hwconfig)) {
720 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
721 switch (wriop_get_enet_if(i)) {
722 case PHY_INTERFACE_MODE_QSGMII:
723 qsgmii_configure_repeater(i);
725 case PHY_INTERFACE_MODE_SGMII:
726 sgmii_configure_repeater(i);
737 error = pci_eth_init(bis);
741 #if defined(CONFIG_RESET_PHY_R)
746 #endif /* CONFIG_RESET_PHY_R */