1 // SPDX-License-Identifier: GPL-2.0+
12 #include <asm/arch/fsl_serdes.h>
20 #include <fsl-mc/fsl_mc.h>
21 #include <fsl-mc/ldpaa_wriop.h>
23 #include "../common/qixis.h"
25 #include "ls1088a_qixis.h"
27 #ifdef CONFIG_FSL_MC_ENET
31 /* - In LS1088A A there are only 16 SERDES lanes, spread across 2 SERDES banks.
32 * Bank 1 -> Lanes A, B, C, D,
33 * Bank 2 -> Lanes A,B, C, D,
36 /* Mapping of 8 SERDES lanes to LS1088A QDS board slots. A value of '0' here
37 * means that the mapping must be determined dynamically, or that the lane
38 * maps to something other than a board slot.
41 static u8 lane_to_slot_fsm1[] = {
42 0, 0, 0, 0, 0, 0, 0, 0
45 /* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs
49 static int xqsgii_riser_phy_addr[] = {
50 XQSGMII_CARD_PHY1_PORT0_ADDR,
51 XQSGMII_CARD_PHY2_PORT0_ADDR,
52 XQSGMII_CARD_PHY3_PORT0_ADDR,
53 XQSGMII_CARD_PHY4_PORT0_ADDR,
54 XQSGMII_CARD_PHY3_PORT2_ADDR,
55 XQSGMII_CARD_PHY1_PORT2_ADDR,
56 XQSGMII_CARD_PHY4_PORT2_ADDR,
57 XQSGMII_CARD_PHY2_PORT2_ADDR,
60 static int sgmii_riser_phy_addr[] = {
61 SGMII_CARD_PORT1_PHY_ADDR,
62 SGMII_CARD_PORT2_PHY_ADDR,
63 SGMII_CARD_PORT3_PHY_ADDR,
64 SGMII_CARD_PORT4_PHY_ADDR,
67 /* Slot2 does not have EMI connections */
73 static const char * const mdio_names[] = {
77 DEFAULT_WRIOP_MDIO2_NAME,
80 struct ls1088a_qds_mdio {
82 struct mii_dev *realbus;
90 static void sgmii_configure_repeater(int dpmac)
96 const char *dev = "LS1088A_QDS_MDIO2";
97 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
101 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
102 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
103 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
104 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
106 u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
107 struct reg_pair reg_pair[10] = {
108 {6, ®_val[0]}, {4, ®_val[1]},
109 {8, ®_val[2]}, {0xf, NULL},
110 {0x11, NULL}, {0x16, NULL},
111 {0x18, NULL}, {0x23, ®_val[3]},
112 {0x2d, ®_val[4]}, {4, ®_val[5]},
115 struct udevice *udev;
118 /* Set I2c to Slot 1 */
119 #ifndef CONFIG_DM_I2C
120 ret = i2c_write(0x77, 0, 0, &a, 1);
122 ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
124 ret = dm_i2c_write(udev, 0, &a, 1);
131 i2c_phy_addr = i2c_addr[1];
135 i2c_phy_addr = i2c_addr[0];
139 i2c_phy_addr = i2c_addr[3];
143 i2c_phy_addr = i2c_addr[2];
148 /* Check the PHY status */
149 ret = miiphy_set_current_dev(dev);
153 bus = mdio_get_current_dev();
154 debug("Reading from bus %s\n", bus->name);
156 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
161 ret = miiphy_read(dev, phy_addr, 0x11, &value);
167 if ((value & 0xfff) == 0x401) {
168 miiphy_write(dev, phy_addr, 0x1f, 0);
169 printf("DPMAC %d:PHY is ..... Configured\n", dpmac);
174 i2c_get_chip_for_busnum(0, i2c_phy_addr, 1, &udev);
177 for (i = 0; i < 4; i++) {
178 for (j = 0; j < 4; j++) {
179 reg_pair[3].val = &ch_a_eq[i];
180 reg_pair[4].val = &ch_a_ctl2[j];
181 reg_pair[5].val = &ch_b_eq[i];
182 reg_pair[6].val = &ch_b_ctl2[j];
183 for (k = 0; k < 10; k++) {
184 #ifndef CONFIG_DM_I2C
185 ret = i2c_write(i2c_phy_addr,
187 1, reg_pair[k].val, 1);
189 ret = i2c_get_chip_for_busnum(0,
193 ret = dm_i2c_write(udev,
202 ret = miiphy_read(dev, phy_addr, 0x11, &value);
207 ret = miiphy_read(dev, phy_addr, 0x11, &value);
211 if ((value & 0xfff) == 0x401) {
212 printf("DPMAC %d :PHY is configured ",
214 printf("after setting repeater 0x%x\n",
219 printf("DPMAC %d :PHY is failed to ",
221 printf("configure the repeater 0x%x\n", value);
225 miiphy_write(dev, phy_addr, 0x1f, 0);
228 printf("DPMAC %d ..... FAILED to configure PHY\n", dpmac);
232 static void qsgmii_configure_repeater(int dpmac)
236 int i2c_phy_addr = 0;
238 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
240 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
241 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
242 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
243 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
245 u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
246 struct reg_pair reg_pair[10] = {
247 {6, ®_val[0]}, {4, ®_val[1]},
248 {8, ®_val[2]}, {0xf, NULL},
249 {0x11, NULL}, {0x16, NULL},
250 {0x18, NULL}, {0x23, ®_val[3]},
251 {0x2d, ®_val[4]}, {4, ®_val[5]},
254 const char *dev = mdio_names[EMI1_SLOT1];
256 unsigned short value;
258 struct udevice *udev;
261 /* Set I2c to Slot 1 */
262 #ifndef CONFIG_DM_I2C
263 ret = i2c_write(0x77, 0, 0, &a, 1);
265 ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
267 ret = dm_i2c_write(udev, 0, &a, 1);
277 i2c_phy_addr = i2c_addr[2];
285 i2c_phy_addr = i2c_addr[3];
290 /* Check the PHY status */
291 ret = miiphy_set_current_dev(dev);
292 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
294 ret = miiphy_read(dev, phy_addr, 0x11, &value);
296 ret = miiphy_read(dev, phy_addr, 0x11, &value);
298 if ((value & 0xf) == 0xf) {
299 miiphy_write(dev, phy_addr, 0x1f, 0);
300 printf("DPMAC %d :PHY is ..... Configured\n", dpmac);
305 i2c_get_chip_for_busnum(0, i2c_phy_addr, 1, &udev);
308 for (i = 0; i < 4; i++) {
309 for (j = 0; j < 4; j++) {
310 reg_pair[3].val = &ch_a_eq[i];
311 reg_pair[4].val = &ch_a_ctl2[j];
312 reg_pair[5].val = &ch_b_eq[i];
313 reg_pair[6].val = &ch_b_ctl2[j];
315 for (k = 0; k < 10; k++) {
316 #ifndef CONFIG_DM_I2C
317 ret = i2c_write(i2c_phy_addr,
319 1, reg_pair[k].val, 1);
321 ret = i2c_get_chip_for_busnum(0,
325 ret = dm_i2c_write(udev,
333 ret = miiphy_read(dev, phy_addr, 0x11, &value);
337 ret = miiphy_read(dev, phy_addr, 0x11, &value);
341 if ((value & 0xf) == 0xf) {
342 miiphy_write(dev, phy_addr, 0x1f, 0);
343 printf("DPMAC %d :PHY is ..... Configured\n",
350 printf("DPMAC %d :PHY ..... FAILED to configure PHY\n", dpmac);
354 static const char *ls1088a_qds_mdio_name_for_muxval(u8 muxval)
356 return mdio_names[muxval];
359 struct mii_dev *mii_dev_for_muxval(u8 muxval)
362 const char *name = ls1088a_qds_mdio_name_for_muxval(muxval);
365 printf("No bus for muxval %x\n", muxval);
369 bus = miiphy_get_dev_by_name(name);
372 printf("No bus by name %s\n", name);
379 static void ls1088a_qds_enable_SFP_TX(u8 muxval)
383 brdcfg9 = QIXIS_READ(brdcfg[9]);
384 brdcfg9 &= ~BRDCFG9_SFPTX_MASK;
385 brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT);
386 QIXIS_WRITE(brdcfg[9], brdcfg9);
389 static void ls1088a_qds_mux_mdio(u8 muxval)
394 brdcfg4 = QIXIS_READ(brdcfg[4]);
395 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
396 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
397 QIXIS_WRITE(brdcfg[4], brdcfg4);
401 static int ls1088a_qds_mdio_read(struct mii_dev *bus, int addr,
402 int devad, int regnum)
404 struct ls1088a_qds_mdio *priv = bus->priv;
406 ls1088a_qds_mux_mdio(priv->muxval);
408 return priv->realbus->read(priv->realbus, addr, devad, regnum);
411 static int ls1088a_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
412 int regnum, u16 value)
414 struct ls1088a_qds_mdio *priv = bus->priv;
416 ls1088a_qds_mux_mdio(priv->muxval);
418 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
421 static int ls1088a_qds_mdio_reset(struct mii_dev *bus)
423 struct ls1088a_qds_mdio *priv = bus->priv;
425 return priv->realbus->reset(priv->realbus);
428 static int ls1088a_qds_mdio_init(char *realbusname, u8 muxval)
430 struct ls1088a_qds_mdio *pmdio;
431 struct mii_dev *bus = mdio_alloc();
434 printf("Failed to allocate ls1088a_qds MDIO bus\n");
438 pmdio = malloc(sizeof(*pmdio));
440 printf("Failed to allocate ls1088a_qds private data\n");
445 bus->read = ls1088a_qds_mdio_read;
446 bus->write = ls1088a_qds_mdio_write;
447 bus->reset = ls1088a_qds_mdio_reset;
448 sprintf(bus->name, ls1088a_qds_mdio_name_for_muxval(muxval));
450 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
452 if (!pmdio->realbus) {
453 printf("No bus with name %s\n", realbusname);
459 pmdio->muxval = muxval;
462 return mdio_register(bus);
466 * Initialize the dpmac_info array.
469 static void initialize_dpmac_to_slot(void)
471 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
472 u32 serdes1_prtcl, cfg;
474 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
475 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
476 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
477 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
479 switch (serdes1_prtcl) {
481 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
483 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
484 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
485 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
486 lane_to_slot_fsm1[3] = EMI1_SLOT1 - 1;
490 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
492 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
493 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
494 lane_to_slot_fsm1[2] = EMI_NONE;
495 lane_to_slot_fsm1[3] = EMI_NONE;
498 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
500 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
501 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
502 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
503 lane_to_slot_fsm1[3] = EMI_NONE;
506 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
508 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
509 lane_to_slot_fsm1[1] = EMI_NONE;
510 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
511 lane_to_slot_fsm1[3] = EMI1_SLOT1 - 1;
515 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
516 __func__, serdes1_prtcl);
521 void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
524 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
525 u32 serdes1_prtcl, cfg;
527 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
528 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
529 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
530 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
533 char *env_hwconfig = env_get("hwconfig");
535 if (hwconfig_f("xqsgmii", env_hwconfig))
536 riser_phy_addr = &xqsgii_riser_phy_addr[0];
538 riser_phy_addr = &sgmii_riser_phy_addr[0];
540 switch (serdes1_prtcl) {
547 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[1]);
550 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[0]);
553 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[3]);
556 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[2]);
559 printf("WRIOP: Wrong DPMAC%d set to SGMII", dpmac_id);
564 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
565 __func__, serdes1_prtcl);
568 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
569 bus = mii_dev_for_muxval(EMI1_SLOT1);
570 wriop_set_mdio(dpmac_id, bus);
573 void ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
576 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
577 u32 serdes1_prtcl, cfg;
579 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
580 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
581 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
582 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
584 switch (serdes1_prtcl) {
592 wriop_set_phy_address(dpmac_id, 0, dpmac_id + 9);
598 wriop_set_phy_address(dpmac_id, 0, dpmac_id + 1);
602 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
603 bus = mii_dev_for_muxval(EMI1_SLOT1);
604 wriop_set_mdio(dpmac_id, bus);
607 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
613 void ls1088a_handle_phy_interface_xsgmii(int i)
615 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
616 u32 serdes1_prtcl, cfg;
618 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
619 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
620 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
621 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
623 switch (serdes1_prtcl) {
627 wriop_set_phy_address(i, 0, i + 26);
628 ls1088a_qds_enable_SFP_TX(SFP_TX);
631 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
637 static void ls1088a_handle_phy_interface_rgmii(int dpmac_id)
639 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
640 u32 serdes1_prtcl, cfg;
643 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
644 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
645 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
646 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
650 wriop_set_phy_address(dpmac_id, 0, RGMII_PHY1_ADDR);
651 dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
652 bus = mii_dev_for_muxval(EMI1_RGMII1);
653 wriop_set_mdio(dpmac_id, bus);
656 wriop_set_phy_address(dpmac_id, 0, RGMII_PHY2_ADDR);
657 dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
658 bus = mii_dev_for_muxval(EMI1_RGMII2);
659 wriop_set_mdio(dpmac_id, bus);
662 printf("qds: WRIOP: Unsupported RGMII SerDes Protocol 0x%02x\n",
669 int board_eth_init(bd_t *bis)
672 #ifdef CONFIG_FSL_MC_ENET
673 struct memac_mdio_info *memac_mdio0_info;
674 char *env_hwconfig = env_get("hwconfig");
676 initialize_dpmac_to_slot();
678 memac_mdio0_info = (struct memac_mdio_info *)malloc(
679 sizeof(struct memac_mdio_info));
680 memac_mdio0_info->regs =
681 (struct memac_mdio_controller *)
682 CONFIG_SYS_FSL_WRIOP1_MDIO1;
683 memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
685 /* Register the real MDIO1 bus */
686 fm_memac_mdio_init(bis, memac_mdio0_info);
687 /* Register the muxing front-ends to the MDIO buses */
688 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_RGMII1);
689 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_RGMII2);
690 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
692 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
693 switch (wriop_get_enet_if(i)) {
694 case PHY_INTERFACE_MODE_RGMII:
695 case PHY_INTERFACE_MODE_RGMII_ID:
696 ls1088a_handle_phy_interface_rgmii(i);
698 case PHY_INTERFACE_MODE_QSGMII:
699 ls1088a_handle_phy_interface_qsgmii(i);
701 case PHY_INTERFACE_MODE_SGMII:
702 ls1088a_handle_phy_interface_sgmii(i);
704 case PHY_INTERFACE_MODE_XGMII:
705 ls1088a_handle_phy_interface_xsgmii(i);
715 error = cpu_eth_init(bis);
717 if (hwconfig_f("xqsgmii", env_hwconfig)) {
718 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
719 switch (wriop_get_enet_if(i)) {
720 case PHY_INTERFACE_MODE_QSGMII:
721 qsgmii_configure_repeater(i);
723 case PHY_INTERFACE_MODE_SGMII:
724 sgmii_configure_repeater(i);
735 error = pci_eth_init(bis);
739 #if defined(CONFIG_RESET_PHY_R)
744 #endif /* CONFIG_RESET_PHY_R */
746 #if defined(CONFIG_DM_ETH) && defined(CONFIG_MULTI_DTB_FIT)
748 /* Structure to hold SERDES protocols supported in case of
749 * CONFIG_DM_ETH enabled (network interfaces are described in the DTS).
751 * @serdes_block: the index of the SERDES block
752 * @serdes_protocol: the decimal value of the protocol supported
753 * @dts_needed: DTS notes describing the current configuration are needed
755 * When dts_needed is true, the board_fit_config_name_match() function
756 * will try to exactly match the current configuration of the block with a DTS
759 static struct serdes_configuration {
763 } supported_protocols[] = {
764 /* Serdes block #1 */
769 #define SUPPORTED_SERDES_PROTOCOLS ARRAY_SIZE(supported_protocols)
771 static bool protocol_supported(u8 serdes_block, u32 protocol)
773 struct serdes_configuration serdes_conf;
776 for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
777 serdes_conf = supported_protocols[i];
778 if (serdes_conf.serdes_block == serdes_block &&
779 serdes_conf.serdes_protocol == protocol)
786 static void get_str_protocol(u8 serdes_block, u32 protocol, char *str)
788 struct serdes_configuration serdes_conf;
791 for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
792 serdes_conf = supported_protocols[i];
793 if (serdes_conf.serdes_block == serdes_block &&
794 serdes_conf.serdes_protocol == protocol) {
795 if (serdes_conf.dts_needed == true)
796 sprintf(str, "%u", protocol);
804 int board_fit_config_name_match(const char *name)
806 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
807 char expected_dts[100];
811 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
812 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
813 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
814 srds_s1 = serdes_get_number(FSL_SRDS_1, cfg);
816 /* Check for supported protocols. The default DTS will be used
819 if (!protocol_supported(1, srds_s1))
822 get_str_protocol(1, srds_s1, srds_s1_str);
824 sprintf(expected_dts, "fsl-ls1088a-qds-%s-x", srds_s1_str);
826 if (!strcmp(name, expected_dts))