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"
30 #ifdef CONFIG_FSL_MC_ENET
34 /* - In LS1088A A there are only 16 SERDES lanes, spread across 2 SERDES banks.
35 * Bank 1 -> Lanes A, B, C, D,
36 * Bank 2 -> Lanes A,B, C, D,
39 /* Mapping of 8 SERDES lanes to LS1088A QDS board slots. A value of '0' here
40 * means that the mapping must be determined dynamically, or that the lane
41 * maps to something other than a board slot.
44 static u8 lane_to_slot_fsm1[] = {
45 0, 0, 0, 0, 0, 0, 0, 0
48 /* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs
52 static int xqsgii_riser_phy_addr[] = {
53 XQSGMII_CARD_PHY1_PORT0_ADDR,
54 XQSGMII_CARD_PHY2_PORT0_ADDR,
55 XQSGMII_CARD_PHY3_PORT0_ADDR,
56 XQSGMII_CARD_PHY4_PORT0_ADDR,
57 XQSGMII_CARD_PHY3_PORT2_ADDR,
58 XQSGMII_CARD_PHY1_PORT2_ADDR,
59 XQSGMII_CARD_PHY4_PORT2_ADDR,
60 XQSGMII_CARD_PHY2_PORT2_ADDR,
63 static int sgmii_riser_phy_addr[] = {
64 SGMII_CARD_PORT1_PHY_ADDR,
65 SGMII_CARD_PORT2_PHY_ADDR,
66 SGMII_CARD_PORT3_PHY_ADDR,
67 SGMII_CARD_PORT4_PHY_ADDR,
70 /* Slot2 does not have EMI connections */
76 static const char * const mdio_names[] = {
80 DEFAULT_WRIOP_MDIO2_NAME,
83 struct ls1088a_qds_mdio {
85 struct mii_dev *realbus;
93 static void sgmii_configure_repeater(int dpmac)
99 const char *dev = "LS1088A_QDS_MDIO2";
100 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
101 int i2c_phy_addr = 0;
104 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
105 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
106 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
107 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
109 u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
110 struct reg_pair reg_pair[10] = {
111 {6, ®_val[0]}, {4, ®_val[1]},
112 {8, ®_val[2]}, {0xf, NULL},
113 {0x11, NULL}, {0x16, NULL},
114 {0x18, NULL}, {0x23, ®_val[3]},
115 {0x2d, ®_val[4]}, {4, ®_val[5]},
117 #if CONFIG_IS_ENABLED(DM_I2C)
118 struct udevice *udev;
121 /* Set I2c to Slot 1 */
122 #if !CONFIG_IS_ENABLED(DM_I2C)
123 ret = i2c_write(0x77, 0, 0, &a, 1);
125 ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
127 ret = dm_i2c_write(udev, 0, &a, 1);
134 i2c_phy_addr = i2c_addr[1];
138 i2c_phy_addr = i2c_addr[0];
142 i2c_phy_addr = i2c_addr[3];
146 i2c_phy_addr = i2c_addr[2];
151 /* Check the PHY status */
152 ret = miiphy_set_current_dev(dev);
156 bus = mdio_get_current_dev();
157 debug("Reading from bus %s\n", bus->name);
159 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
164 ret = miiphy_read(dev, phy_addr, 0x11, &value);
170 if ((value & 0xfff) == 0x401) {
171 miiphy_write(dev, phy_addr, 0x1f, 0);
172 printf("DPMAC %d:PHY is ..... Configured\n", dpmac);
176 #if CONFIG_IS_ENABLED(DM_I2C)
177 i2c_get_chip_for_busnum(0, i2c_phy_addr, 1, &udev);
180 for (i = 0; i < 4; i++) {
181 for (j = 0; j < 4; j++) {
182 reg_pair[3].val = &ch_a_eq[i];
183 reg_pair[4].val = &ch_a_ctl2[j];
184 reg_pair[5].val = &ch_b_eq[i];
185 reg_pair[6].val = &ch_b_ctl2[j];
186 for (k = 0; k < 10; k++) {
187 #if !CONFIG_IS_ENABLED(DM_I2C)
188 ret = i2c_write(i2c_phy_addr,
190 1, reg_pair[k].val, 1);
192 ret = i2c_get_chip_for_busnum(0,
196 ret = dm_i2c_write(udev,
205 ret = miiphy_read(dev, phy_addr, 0x11, &value);
210 ret = miiphy_read(dev, phy_addr, 0x11, &value);
214 if ((value & 0xfff) == 0x401) {
215 printf("DPMAC %d :PHY is configured ",
217 printf("after setting repeater 0x%x\n",
222 printf("DPMAC %d :PHY is failed to ",
224 printf("configure the repeater 0x%x\n", value);
228 miiphy_write(dev, phy_addr, 0x1f, 0);
231 printf("DPMAC %d ..... FAILED to configure PHY\n", dpmac);
235 static void qsgmii_configure_repeater(int dpmac)
239 int i2c_phy_addr = 0;
241 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
243 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
244 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
245 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
246 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
248 u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
249 struct reg_pair reg_pair[10] = {
250 {6, ®_val[0]}, {4, ®_val[1]},
251 {8, ®_val[2]}, {0xf, NULL},
252 {0x11, NULL}, {0x16, NULL},
253 {0x18, NULL}, {0x23, ®_val[3]},
254 {0x2d, ®_val[4]}, {4, ®_val[5]},
257 const char *dev = mdio_names[EMI1_SLOT1];
259 unsigned short value;
260 #if CONFIG_IS_ENABLED(DM_I2C)
261 struct udevice *udev;
264 /* Set I2c to Slot 1 */
265 #if !CONFIG_IS_ENABLED(DM_I2C)
266 ret = i2c_write(0x77, 0, 0, &a, 1);
268 ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
270 ret = dm_i2c_write(udev, 0, &a, 1);
280 i2c_phy_addr = i2c_addr[2];
288 i2c_phy_addr = i2c_addr[3];
293 /* Check the PHY status */
294 ret = miiphy_set_current_dev(dev);
295 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
297 ret = miiphy_read(dev, phy_addr, 0x11, &value);
299 ret = miiphy_read(dev, phy_addr, 0x11, &value);
301 if ((value & 0xf) == 0xf) {
302 miiphy_write(dev, phy_addr, 0x1f, 0);
303 printf("DPMAC %d :PHY is ..... Configured\n", dpmac);
307 #if CONFIG_IS_ENABLED(DM_I2C)
308 i2c_get_chip_for_busnum(0, i2c_phy_addr, 1, &udev);
311 for (i = 0; i < 4; i++) {
312 for (j = 0; j < 4; j++) {
313 reg_pair[3].val = &ch_a_eq[i];
314 reg_pair[4].val = &ch_a_ctl2[j];
315 reg_pair[5].val = &ch_b_eq[i];
316 reg_pair[6].val = &ch_b_ctl2[j];
318 for (k = 0; k < 10; k++) {
319 #if !CONFIG_IS_ENABLED(DM_I2C)
320 ret = i2c_write(i2c_phy_addr,
322 1, reg_pair[k].val, 1);
324 ret = i2c_get_chip_for_busnum(0,
328 ret = dm_i2c_write(udev,
336 ret = miiphy_read(dev, phy_addr, 0x11, &value);
340 ret = miiphy_read(dev, phy_addr, 0x11, &value);
344 if ((value & 0xf) == 0xf) {
345 miiphy_write(dev, phy_addr, 0x1f, 0);
346 printf("DPMAC %d :PHY is ..... Configured\n",
353 printf("DPMAC %d :PHY ..... FAILED to configure PHY\n", dpmac);
357 static const char *ls1088a_qds_mdio_name_for_muxval(u8 muxval)
359 return mdio_names[muxval];
362 struct mii_dev *mii_dev_for_muxval(u8 muxval)
365 const char *name = ls1088a_qds_mdio_name_for_muxval(muxval);
368 printf("No bus for muxval %x\n", muxval);
372 bus = miiphy_get_dev_by_name(name);
375 printf("No bus by name %s\n", name);
382 static void ls1088a_qds_enable_SFP_TX(u8 muxval)
386 brdcfg9 = QIXIS_READ(brdcfg[9]);
387 brdcfg9 &= ~BRDCFG9_SFPTX_MASK;
388 brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT);
389 QIXIS_WRITE(brdcfg[9], brdcfg9);
392 static void ls1088a_qds_mux_mdio(u8 muxval)
397 brdcfg4 = QIXIS_READ(brdcfg[4]);
398 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
399 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
400 QIXIS_WRITE(brdcfg[4], brdcfg4);
404 static int ls1088a_qds_mdio_read(struct mii_dev *bus, int addr,
405 int devad, int regnum)
407 struct ls1088a_qds_mdio *priv = bus->priv;
409 ls1088a_qds_mux_mdio(priv->muxval);
411 return priv->realbus->read(priv->realbus, addr, devad, regnum);
414 static int ls1088a_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
415 int regnum, u16 value)
417 struct ls1088a_qds_mdio *priv = bus->priv;
419 ls1088a_qds_mux_mdio(priv->muxval);
421 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
424 static int ls1088a_qds_mdio_reset(struct mii_dev *bus)
426 struct ls1088a_qds_mdio *priv = bus->priv;
428 return priv->realbus->reset(priv->realbus);
431 static int ls1088a_qds_mdio_init(char *realbusname, u8 muxval)
433 struct ls1088a_qds_mdio *pmdio;
434 struct mii_dev *bus = mdio_alloc();
437 printf("Failed to allocate ls1088a_qds MDIO bus\n");
441 pmdio = malloc(sizeof(*pmdio));
443 printf("Failed to allocate ls1088a_qds private data\n");
448 bus->read = ls1088a_qds_mdio_read;
449 bus->write = ls1088a_qds_mdio_write;
450 bus->reset = ls1088a_qds_mdio_reset;
451 sprintf(bus->name, ls1088a_qds_mdio_name_for_muxval(muxval));
453 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
455 if (!pmdio->realbus) {
456 printf("No bus with name %s\n", realbusname);
462 pmdio->muxval = muxval;
465 return mdio_register(bus);
469 * Initialize the dpmac_info array.
472 static void initialize_dpmac_to_slot(void)
474 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
475 u32 serdes1_prtcl, cfg;
477 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
478 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
479 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
480 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
482 switch (serdes1_prtcl) {
484 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
486 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
487 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
488 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
489 lane_to_slot_fsm1[3] = EMI1_SLOT1 - 1;
493 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
495 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
496 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
497 lane_to_slot_fsm1[2] = EMI_NONE;
498 lane_to_slot_fsm1[3] = EMI_NONE;
501 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
503 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
504 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
505 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
506 lane_to_slot_fsm1[3] = EMI_NONE;
509 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
511 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
512 lane_to_slot_fsm1[1] = EMI_NONE;
513 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
514 lane_to_slot_fsm1[3] = EMI1_SLOT1 - 1;
518 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
519 __func__, serdes1_prtcl);
524 void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
527 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
528 u32 serdes1_prtcl, cfg;
530 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
531 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
532 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
533 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
536 char *env_hwconfig = env_get("hwconfig");
538 if (hwconfig_f("xqsgmii", env_hwconfig))
539 riser_phy_addr = &xqsgii_riser_phy_addr[0];
541 riser_phy_addr = &sgmii_riser_phy_addr[0];
543 switch (serdes1_prtcl) {
550 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[1]);
553 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[0]);
556 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[3]);
559 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[2]);
562 printf("WRIOP: Wrong DPMAC%d set to SGMII", dpmac_id);
567 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
568 __func__, serdes1_prtcl);
571 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
572 bus = mii_dev_for_muxval(EMI1_SLOT1);
573 wriop_set_mdio(dpmac_id, bus);
576 void ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
579 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
580 u32 serdes1_prtcl, cfg;
582 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
583 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
584 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
585 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
587 switch (serdes1_prtcl) {
595 wriop_set_phy_address(dpmac_id, 0, dpmac_id + 9);
601 wriop_set_phy_address(dpmac_id, 0, dpmac_id + 1);
605 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
606 bus = mii_dev_for_muxval(EMI1_SLOT1);
607 wriop_set_mdio(dpmac_id, bus);
610 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
616 void ls1088a_handle_phy_interface_xsgmii(int i)
618 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
619 u32 serdes1_prtcl, cfg;
621 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
622 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
623 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
624 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
626 switch (serdes1_prtcl) {
630 wriop_set_phy_address(i, 0, i + 26);
631 ls1088a_qds_enable_SFP_TX(SFP_TX);
634 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
640 static void ls1088a_handle_phy_interface_rgmii(int dpmac_id)
642 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
643 u32 serdes1_prtcl, cfg;
646 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
647 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
648 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
649 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
653 wriop_set_phy_address(dpmac_id, 0, RGMII_PHY1_ADDR);
654 dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
655 bus = mii_dev_for_muxval(EMI1_RGMII1);
656 wriop_set_mdio(dpmac_id, bus);
659 wriop_set_phy_address(dpmac_id, 0, RGMII_PHY2_ADDR);
660 dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
661 bus = mii_dev_for_muxval(EMI1_RGMII2);
662 wriop_set_mdio(dpmac_id, bus);
665 printf("qds: WRIOP: Unsupported RGMII SerDes Protocol 0x%02x\n",
672 int board_eth_init(struct bd_info *bis)
675 #ifdef CONFIG_FSL_MC_ENET
676 struct memac_mdio_info *memac_mdio0_info;
677 char *env_hwconfig = env_get("hwconfig");
679 initialize_dpmac_to_slot();
681 memac_mdio0_info = (struct memac_mdio_info *)malloc(
682 sizeof(struct memac_mdio_info));
683 memac_mdio0_info->regs =
684 (struct memac_mdio_controller *)
685 CONFIG_SYS_FSL_WRIOP1_MDIO1;
686 memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
688 /* Register the real MDIO1 bus */
689 fm_memac_mdio_init(bis, memac_mdio0_info);
690 /* Register the muxing front-ends to the MDIO buses */
691 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_RGMII1);
692 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_RGMII2);
693 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
695 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
696 switch (wriop_get_enet_if(i)) {
697 case PHY_INTERFACE_MODE_RGMII:
698 case PHY_INTERFACE_MODE_RGMII_ID:
699 ls1088a_handle_phy_interface_rgmii(i);
701 case PHY_INTERFACE_MODE_QSGMII:
702 ls1088a_handle_phy_interface_qsgmii(i);
704 case PHY_INTERFACE_MODE_SGMII:
705 ls1088a_handle_phy_interface_sgmii(i);
707 case PHY_INTERFACE_MODE_XGMII:
708 ls1088a_handle_phy_interface_xsgmii(i);
718 error = cpu_eth_init(bis);
720 if (hwconfig_f("xqsgmii", env_hwconfig)) {
721 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
722 switch (wriop_get_enet_if(i)) {
723 case PHY_INTERFACE_MODE_QSGMII:
724 qsgmii_configure_repeater(i);
726 case PHY_INTERFACE_MODE_SGMII:
727 sgmii_configure_repeater(i);
738 error = pci_eth_init(bis);
741 #endif // !CONFIG_DM_ETH
743 #if defined(CONFIG_RESET_PHY_R)
748 #endif /* CONFIG_RESET_PHY_R */
750 #if defined(CONFIG_DM_ETH) && defined(CONFIG_MULTI_DTB_FIT)
752 /* Structure to hold SERDES protocols supported in case of
753 * CONFIG_DM_ETH enabled (network interfaces are described in the DTS).
755 * @serdes_block: the index of the SERDES block
756 * @serdes_protocol: the decimal value of the protocol supported
757 * @dts_needed: DTS notes describing the current configuration are needed
759 * When dts_needed is true, the board_fit_config_name_match() function
760 * will try to exactly match the current configuration of the block with a DTS
763 static struct serdes_configuration {
767 } supported_protocols[] = {
768 /* Serdes block #1 */
773 #define SUPPORTED_SERDES_PROTOCOLS ARRAY_SIZE(supported_protocols)
775 static bool protocol_supported(u8 serdes_block, u32 protocol)
777 struct serdes_configuration serdes_conf;
780 for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
781 serdes_conf = supported_protocols[i];
782 if (serdes_conf.serdes_block == serdes_block &&
783 serdes_conf.serdes_protocol == protocol)
790 static void get_str_protocol(u8 serdes_block, u32 protocol, char *str)
792 struct serdes_configuration serdes_conf;
795 for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
796 serdes_conf = supported_protocols[i];
797 if (serdes_conf.serdes_block == serdes_block &&
798 serdes_conf.serdes_protocol == protocol) {
799 if (serdes_conf.dts_needed == true)
800 sprintf(str, "%u", protocol);
808 int board_fit_config_name_match(const char *name)
810 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
811 char expected_dts[100];
815 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
816 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
817 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
818 srds_s1 = serdes_get_number(FSL_SRDS_1, cfg);
820 /* Check for supported protocols. The default DTS will be used
823 if (!protocol_supported(1, srds_s1))
826 get_str_protocol(1, srds_s1, srds_s1_str);
828 sprintf(expected_dts, "fsl-ls1088a-qds-%s-x", srds_s1_str);
830 if (!strcmp(name, expected_dts))