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"
28 #ifdef CONFIG_FSL_MC_ENET
32 /* - In LS1088A A there are only 16 SERDES lanes, spread across 2 SERDES banks.
33 * Bank 1 -> Lanes A, B, C, D,
34 * Bank 2 -> Lanes A,B, C, D,
37 /* Mapping of 8 SERDES lanes to LS1088A QDS board slots. A value of '0' here
38 * means that the mapping must be determined dynamically, or that the lane
39 * maps to something other than a board slot.
42 static u8 lane_to_slot_fsm1[] = {
43 0, 0, 0, 0, 0, 0, 0, 0
46 /* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs
50 static int xqsgii_riser_phy_addr[] = {
51 XQSGMII_CARD_PHY1_PORT0_ADDR,
52 XQSGMII_CARD_PHY2_PORT0_ADDR,
53 XQSGMII_CARD_PHY3_PORT0_ADDR,
54 XQSGMII_CARD_PHY4_PORT0_ADDR,
55 XQSGMII_CARD_PHY3_PORT2_ADDR,
56 XQSGMII_CARD_PHY1_PORT2_ADDR,
57 XQSGMII_CARD_PHY4_PORT2_ADDR,
58 XQSGMII_CARD_PHY2_PORT2_ADDR,
61 static int sgmii_riser_phy_addr[] = {
62 SGMII_CARD_PORT1_PHY_ADDR,
63 SGMII_CARD_PORT2_PHY_ADDR,
64 SGMII_CARD_PORT3_PHY_ADDR,
65 SGMII_CARD_PORT4_PHY_ADDR,
68 /* Slot2 does not have EMI connections */
74 static const char * const mdio_names[] = {
78 DEFAULT_WRIOP_MDIO2_NAME,
81 struct ls1088a_qds_mdio {
83 struct mii_dev *realbus;
91 static void sgmii_configure_repeater(int dpmac)
97 const char *dev = "LS1088A_QDS_MDIO2";
98 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
102 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
103 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
104 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
105 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
107 u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
108 struct reg_pair reg_pair[10] = {
109 {6, ®_val[0]}, {4, ®_val[1]},
110 {8, ®_val[2]}, {0xf, NULL},
111 {0x11, NULL}, {0x16, NULL},
112 {0x18, NULL}, {0x23, ®_val[3]},
113 {0x2d, ®_val[4]}, {4, ®_val[5]},
116 struct udevice *udev;
119 /* Set I2c to Slot 1 */
120 #ifndef CONFIG_DM_I2C
121 ret = i2c_write(0x77, 0, 0, &a, 1);
123 ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
125 ret = dm_i2c_write(udev, 0, &a, 1);
132 i2c_phy_addr = i2c_addr[1];
136 i2c_phy_addr = i2c_addr[0];
140 i2c_phy_addr = i2c_addr[3];
144 i2c_phy_addr = i2c_addr[2];
149 /* Check the PHY status */
150 ret = miiphy_set_current_dev(dev);
154 bus = mdio_get_current_dev();
155 debug("Reading from bus %s\n", bus->name);
157 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
162 ret = miiphy_read(dev, phy_addr, 0x11, &value);
168 if ((value & 0xfff) == 0x401) {
169 miiphy_write(dev, phy_addr, 0x1f, 0);
170 printf("DPMAC %d:PHY is ..... Configured\n", dpmac);
175 i2c_get_chip_for_busnum(0, i2c_phy_addr, 1, &udev);
178 for (i = 0; i < 4; i++) {
179 for (j = 0; j < 4; j++) {
180 reg_pair[3].val = &ch_a_eq[i];
181 reg_pair[4].val = &ch_a_ctl2[j];
182 reg_pair[5].val = &ch_b_eq[i];
183 reg_pair[6].val = &ch_b_ctl2[j];
184 for (k = 0; k < 10; k++) {
185 #ifndef CONFIG_DM_I2C
186 ret = i2c_write(i2c_phy_addr,
188 1, reg_pair[k].val, 1);
190 ret = i2c_get_chip_for_busnum(0,
194 ret = dm_i2c_write(udev,
203 ret = miiphy_read(dev, phy_addr, 0x11, &value);
208 ret = miiphy_read(dev, phy_addr, 0x11, &value);
212 if ((value & 0xfff) == 0x401) {
213 printf("DPMAC %d :PHY is configured ",
215 printf("after setting repeater 0x%x\n",
220 printf("DPMAC %d :PHY is failed to ",
222 printf("configure the repeater 0x%x\n", value);
226 miiphy_write(dev, phy_addr, 0x1f, 0);
229 printf("DPMAC %d ..... FAILED to configure PHY\n", dpmac);
233 static void qsgmii_configure_repeater(int dpmac)
237 int i2c_phy_addr = 0;
239 int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
241 uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
242 uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
243 uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
244 uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
246 u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
247 struct reg_pair reg_pair[10] = {
248 {6, ®_val[0]}, {4, ®_val[1]},
249 {8, ®_val[2]}, {0xf, NULL},
250 {0x11, NULL}, {0x16, NULL},
251 {0x18, NULL}, {0x23, ®_val[3]},
252 {0x2d, ®_val[4]}, {4, ®_val[5]},
255 const char *dev = mdio_names[EMI1_SLOT1];
257 unsigned short value;
259 struct udevice *udev;
262 /* Set I2c to Slot 1 */
263 #ifndef CONFIG_DM_I2C
264 ret = i2c_write(0x77, 0, 0, &a, 1);
266 ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
268 ret = dm_i2c_write(udev, 0, &a, 1);
278 i2c_phy_addr = i2c_addr[2];
286 i2c_phy_addr = i2c_addr[3];
291 /* Check the PHY status */
292 ret = miiphy_set_current_dev(dev);
293 ret = miiphy_write(dev, phy_addr, 0x1f, 3);
295 ret = miiphy_read(dev, phy_addr, 0x11, &value);
297 ret = miiphy_read(dev, phy_addr, 0x11, &value);
299 if ((value & 0xf) == 0xf) {
300 miiphy_write(dev, phy_addr, 0x1f, 0);
301 printf("DPMAC %d :PHY is ..... Configured\n", dpmac);
306 i2c_get_chip_for_busnum(0, i2c_phy_addr, 1, &udev);
309 for (i = 0; i < 4; i++) {
310 for (j = 0; j < 4; j++) {
311 reg_pair[3].val = &ch_a_eq[i];
312 reg_pair[4].val = &ch_a_ctl2[j];
313 reg_pair[5].val = &ch_b_eq[i];
314 reg_pair[6].val = &ch_b_ctl2[j];
316 for (k = 0; k < 10; k++) {
317 #ifndef CONFIG_DM_I2C
318 ret = i2c_write(i2c_phy_addr,
320 1, reg_pair[k].val, 1);
322 ret = i2c_get_chip_for_busnum(0,
326 ret = dm_i2c_write(udev,
334 ret = miiphy_read(dev, phy_addr, 0x11, &value);
338 ret = miiphy_read(dev, phy_addr, 0x11, &value);
342 if ((value & 0xf) == 0xf) {
343 miiphy_write(dev, phy_addr, 0x1f, 0);
344 printf("DPMAC %d :PHY is ..... Configured\n",
351 printf("DPMAC %d :PHY ..... FAILED to configure PHY\n", dpmac);
355 static const char *ls1088a_qds_mdio_name_for_muxval(u8 muxval)
357 return mdio_names[muxval];
360 struct mii_dev *mii_dev_for_muxval(u8 muxval)
363 const char *name = ls1088a_qds_mdio_name_for_muxval(muxval);
366 printf("No bus for muxval %x\n", muxval);
370 bus = miiphy_get_dev_by_name(name);
373 printf("No bus by name %s\n", name);
380 static void ls1088a_qds_enable_SFP_TX(u8 muxval)
384 brdcfg9 = QIXIS_READ(brdcfg[9]);
385 brdcfg9 &= ~BRDCFG9_SFPTX_MASK;
386 brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT);
387 QIXIS_WRITE(brdcfg[9], brdcfg9);
390 static void ls1088a_qds_mux_mdio(u8 muxval)
395 brdcfg4 = QIXIS_READ(brdcfg[4]);
396 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
397 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
398 QIXIS_WRITE(brdcfg[4], brdcfg4);
402 static int ls1088a_qds_mdio_read(struct mii_dev *bus, int addr,
403 int devad, int regnum)
405 struct ls1088a_qds_mdio *priv = bus->priv;
407 ls1088a_qds_mux_mdio(priv->muxval);
409 return priv->realbus->read(priv->realbus, addr, devad, regnum);
412 static int ls1088a_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
413 int regnum, u16 value)
415 struct ls1088a_qds_mdio *priv = bus->priv;
417 ls1088a_qds_mux_mdio(priv->muxval);
419 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
422 static int ls1088a_qds_mdio_reset(struct mii_dev *bus)
424 struct ls1088a_qds_mdio *priv = bus->priv;
426 return priv->realbus->reset(priv->realbus);
429 static int ls1088a_qds_mdio_init(char *realbusname, u8 muxval)
431 struct ls1088a_qds_mdio *pmdio;
432 struct mii_dev *bus = mdio_alloc();
435 printf("Failed to allocate ls1088a_qds MDIO bus\n");
439 pmdio = malloc(sizeof(*pmdio));
441 printf("Failed to allocate ls1088a_qds private data\n");
446 bus->read = ls1088a_qds_mdio_read;
447 bus->write = ls1088a_qds_mdio_write;
448 bus->reset = ls1088a_qds_mdio_reset;
449 sprintf(bus->name, ls1088a_qds_mdio_name_for_muxval(muxval));
451 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
453 if (!pmdio->realbus) {
454 printf("No bus with name %s\n", realbusname);
460 pmdio->muxval = muxval;
463 return mdio_register(bus);
467 * Initialize the dpmac_info array.
470 static void initialize_dpmac_to_slot(void)
472 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
473 u32 serdes1_prtcl, cfg;
475 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
476 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
477 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
478 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
480 switch (serdes1_prtcl) {
482 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
484 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
485 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
486 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
487 lane_to_slot_fsm1[3] = EMI1_SLOT1 - 1;
491 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
493 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
494 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
495 lane_to_slot_fsm1[2] = EMI_NONE;
496 lane_to_slot_fsm1[3] = EMI_NONE;
499 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
501 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
502 lane_to_slot_fsm1[1] = EMI1_SLOT1 - 1;
503 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
504 lane_to_slot_fsm1[3] = EMI_NONE;
507 printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
509 lane_to_slot_fsm1[0] = EMI1_SLOT1 - 1;
510 lane_to_slot_fsm1[1] = EMI_NONE;
511 lane_to_slot_fsm1[2] = EMI1_SLOT1 - 1;
512 lane_to_slot_fsm1[3] = EMI1_SLOT1 - 1;
516 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
517 __func__, serdes1_prtcl);
522 void ls1088a_handle_phy_interface_sgmii(int dpmac_id)
525 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
526 u32 serdes1_prtcl, cfg;
528 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
529 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
530 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
531 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
534 char *env_hwconfig = env_get("hwconfig");
536 if (hwconfig_f("xqsgmii", env_hwconfig))
537 riser_phy_addr = &xqsgii_riser_phy_addr[0];
539 riser_phy_addr = &sgmii_riser_phy_addr[0];
541 switch (serdes1_prtcl) {
548 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[1]);
551 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[0]);
554 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[3]);
557 wriop_set_phy_address(dpmac_id, 0, riser_phy_addr[2]);
560 printf("WRIOP: Wrong DPMAC%d set to SGMII", dpmac_id);
565 printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
566 __func__, serdes1_prtcl);
569 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
570 bus = mii_dev_for_muxval(EMI1_SLOT1);
571 wriop_set_mdio(dpmac_id, bus);
574 void ls1088a_handle_phy_interface_qsgmii(int dpmac_id)
577 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
578 u32 serdes1_prtcl, cfg;
580 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
581 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
582 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
583 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
585 switch (serdes1_prtcl) {
593 wriop_set_phy_address(dpmac_id, 0, dpmac_id + 9);
599 wriop_set_phy_address(dpmac_id, 0, dpmac_id + 1);
603 dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
604 bus = mii_dev_for_muxval(EMI1_SLOT1);
605 wriop_set_mdio(dpmac_id, bus);
608 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
614 void ls1088a_handle_phy_interface_xsgmii(int i)
616 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
617 u32 serdes1_prtcl, cfg;
619 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
620 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
621 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
622 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
624 switch (serdes1_prtcl) {
628 wriop_set_phy_address(i, 0, i + 26);
629 ls1088a_qds_enable_SFP_TX(SFP_TX);
632 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
638 static void ls1088a_handle_phy_interface_rgmii(int dpmac_id)
640 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
641 u32 serdes1_prtcl, cfg;
644 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
645 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
646 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
647 serdes1_prtcl = serdes_get_number(FSL_SRDS_1, cfg);
651 wriop_set_phy_address(dpmac_id, 0, RGMII_PHY1_ADDR);
652 dpmac_info[dpmac_id].board_mux = EMI1_RGMII1;
653 bus = mii_dev_for_muxval(EMI1_RGMII1);
654 wriop_set_mdio(dpmac_id, bus);
657 wriop_set_phy_address(dpmac_id, 0, RGMII_PHY2_ADDR);
658 dpmac_info[dpmac_id].board_mux = EMI1_RGMII2;
659 bus = mii_dev_for_muxval(EMI1_RGMII2);
660 wriop_set_mdio(dpmac_id, bus);
663 printf("qds: WRIOP: Unsupported RGMII SerDes Protocol 0x%02x\n",
670 int board_eth_init(bd_t *bis)
673 #ifdef CONFIG_FSL_MC_ENET
674 struct memac_mdio_info *memac_mdio0_info;
675 char *env_hwconfig = env_get("hwconfig");
677 initialize_dpmac_to_slot();
679 memac_mdio0_info = (struct memac_mdio_info *)malloc(
680 sizeof(struct memac_mdio_info));
681 memac_mdio0_info->regs =
682 (struct memac_mdio_controller *)
683 CONFIG_SYS_FSL_WRIOP1_MDIO1;
684 memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
686 /* Register the real MDIO1 bus */
687 fm_memac_mdio_init(bis, memac_mdio0_info);
688 /* Register the muxing front-ends to the MDIO buses */
689 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_RGMII1);
690 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_RGMII2);
691 ls1088a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
693 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
694 switch (wriop_get_enet_if(i)) {
695 case PHY_INTERFACE_MODE_RGMII:
696 case PHY_INTERFACE_MODE_RGMII_ID:
697 ls1088a_handle_phy_interface_rgmii(i);
699 case PHY_INTERFACE_MODE_QSGMII:
700 ls1088a_handle_phy_interface_qsgmii(i);
702 case PHY_INTERFACE_MODE_SGMII:
703 ls1088a_handle_phy_interface_sgmii(i);
705 case PHY_INTERFACE_MODE_XGMII:
706 ls1088a_handle_phy_interface_xsgmii(i);
716 error = cpu_eth_init(bis);
718 if (hwconfig_f("xqsgmii", env_hwconfig)) {
719 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
720 switch (wriop_get_enet_if(i)) {
721 case PHY_INTERFACE_MODE_QSGMII:
722 qsgmii_configure_repeater(i);
724 case PHY_INTERFACE_MODE_SGMII:
725 sgmii_configure_repeater(i);
736 error = pci_eth_init(bis);
739 #endif // !CONFIG_DM_ETH
741 #if defined(CONFIG_RESET_PHY_R)
746 #endif /* CONFIG_RESET_PHY_R */
748 #if defined(CONFIG_DM_ETH) && defined(CONFIG_MULTI_DTB_FIT)
750 /* Structure to hold SERDES protocols supported in case of
751 * CONFIG_DM_ETH enabled (network interfaces are described in the DTS).
753 * @serdes_block: the index of the SERDES block
754 * @serdes_protocol: the decimal value of the protocol supported
755 * @dts_needed: DTS notes describing the current configuration are needed
757 * When dts_needed is true, the board_fit_config_name_match() function
758 * will try to exactly match the current configuration of the block with a DTS
761 static struct serdes_configuration {
765 } supported_protocols[] = {
766 /* Serdes block #1 */
771 #define SUPPORTED_SERDES_PROTOCOLS ARRAY_SIZE(supported_protocols)
773 static bool protocol_supported(u8 serdes_block, u32 protocol)
775 struct serdes_configuration serdes_conf;
778 for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
779 serdes_conf = supported_protocols[i];
780 if (serdes_conf.serdes_block == serdes_block &&
781 serdes_conf.serdes_protocol == protocol)
788 static void get_str_protocol(u8 serdes_block, u32 protocol, char *str)
790 struct serdes_configuration serdes_conf;
793 for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
794 serdes_conf = supported_protocols[i];
795 if (serdes_conf.serdes_block == serdes_block &&
796 serdes_conf.serdes_protocol == protocol) {
797 if (serdes_conf.dts_needed == true)
798 sprintf(str, "%u", protocol);
806 int board_fit_config_name_match(const char *name)
808 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
809 char expected_dts[100];
813 cfg = in_le32(&gur->rcwsr[FSL_CHASSIS3_SRDS1_REGSR - 1]) &
814 FSL_CHASSIS3_SRDS1_PRTCL_MASK;
815 cfg >>= FSL_CHASSIS3_SRDS1_PRTCL_SHIFT;
816 srds_s1 = serdes_get_number(FSL_SRDS_1, cfg);
818 /* Check for supported protocols. The default DTS will be used
821 if (!protocol_supported(1, srds_s1))
824 get_str_protocol(1, srds_s1, srds_s1_str);
826 sprintf(expected_dts, "fsl-ls1088a-qds-%s-x", srds_s1_str);
828 if (!strcmp(name, expected_dts))