1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014 Freescale Semiconductor, Inc.
5 * This file handles the board muxing between the RGMII/SGMII PHYs on
6 * Freescale LS1021AQDS board. The RGMII PHYs are the three on-board 1Gb
7 * ports. The SGMII PHYs are provided by the standard Freescale four-port
10 * Muxing is handled via the PIXIS BRDCFG4 register. The EMI1 bits control
11 * muxing among the RGMII PHYs and the SGMII PHYs. The value for RGMII depends
12 * on which port is used. The value for SGMII depends on which slot the riser
18 #include <asm/arch/fsl_serdes.h>
23 #include "../common/sgmii_riser.h"
24 #include "../common/qixis.h"
26 #define EMI1_MASK 0x1f
30 #define EMI1_SGMII1 0x1c
31 #define EMI1_SGMII2 0x1d
34 struct mii_dev *realbus;
37 static void ls1021a_mux_mdio(int addr)
41 brdcfg4 = QIXIS_READ(brdcfg[4]);
65 QIXIS_WRITE(brdcfg[4], brdcfg4);
68 static int ls1021a_mdio_read(struct mii_dev *bus, int addr, int devad,
71 struct ls1021a_mdio *priv = bus->priv;
73 ls1021a_mux_mdio(addr);
75 return priv->realbus->read(priv->realbus, addr, devad, regnum);
78 static int ls1021a_mdio_write(struct mii_dev *bus, int addr, int devad,
79 int regnum, u16 value)
81 struct ls1021a_mdio *priv = bus->priv;
83 ls1021a_mux_mdio(addr);
85 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
88 static int ls1021a_mdio_reset(struct mii_dev *bus)
90 struct ls1021a_mdio *priv = bus->priv;
92 return priv->realbus->reset(priv->realbus);
95 static int ls1021a_mdio_init(char *realbusname, char *fakebusname)
97 struct ls1021a_mdio *lsmdio;
98 struct mii_dev *bus = mdio_alloc();
101 printf("Failed to allocate LS102xA MDIO bus\n");
105 lsmdio = malloc(sizeof(*lsmdio));
107 printf("Failed to allocate LS102xA private data\n");
112 bus->read = ls1021a_mdio_read;
113 bus->write = ls1021a_mdio_write;
114 bus->reset = ls1021a_mdio_reset;
115 strcpy(bus->name, fakebusname);
117 lsmdio->realbus = miiphy_get_dev_by_name(realbusname);
119 if (!lsmdio->realbus) {
120 printf("No bus with name %s\n", realbusname);
128 return mdio_register(bus);
131 int board_eth_init(bd_t *bis)
133 struct fsl_pq_mdio_info mdio_info;
134 struct tsec_info_struct tsec_info[3];
138 SET_STD_TSEC_INFO(tsec_info[num], 1);
139 if (is_serdes_configured(SGMII_TSEC1)) {
140 puts("eTSEC1 is in sgmii mode\n");
141 tsec_info[num].flags |= TSEC_SGMII;
142 tsec_info[num].mii_devname = "LS1021A_SGMII_MDIO";
144 tsec_info[num].mii_devname = "LS1021A_RGMII_MDIO";
149 SET_STD_TSEC_INFO(tsec_info[num], 2);
150 if (is_serdes_configured(SGMII_TSEC2)) {
151 puts("eTSEC2 is in sgmii mode\n");
152 tsec_info[num].flags |= TSEC_SGMII;
153 tsec_info[num].mii_devname = "LS1021A_SGMII_MDIO";
155 tsec_info[num].mii_devname = "LS1021A_RGMII_MDIO";
160 SET_STD_TSEC_INFO(tsec_info[num], 3);
161 tsec_info[num].mii_devname = "LS1021A_RGMII_MDIO";
165 printf("No TSECs initialized\n");
169 #ifdef CONFIG_FSL_SGMII_RISER
170 fsl_sgmii_riser_init(tsec_info, num);
173 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
174 mdio_info.name = DEFAULT_MII_NAME;
176 fsl_pq_mdio_init(bis, &mdio_info);
178 /* Register the virtual MDIO front-ends */
179 ls1021a_mdio_init(DEFAULT_MII_NAME, "LS1021A_RGMII_MDIO");
180 ls1021a_mdio_init(DEFAULT_MII_NAME, "LS1021A_SGMII_MDIO");
182 tsec_eth_init(bis, tsec_info, num);
184 return pci_eth_init(bis);