1 // SPDX-License-Identifier: GPL-2.0+
4 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
9 #include <gdsys_fpga.h>
14 static int ihs_mdio_idle(struct mii_dev *bus)
16 struct ihs_mdio_info *info = bus->priv;
21 FPGA_GET_REG(info->fpga, mdio.control, &val);
25 } while (!(val & (1 << 12)));
30 static int ihs_mdio_reset(struct mii_dev *bus)
37 static int ihs_mdio_read(struct mii_dev *bus, int addr, int dev_addr,
40 struct ihs_mdio_info *info = bus->priv;
45 FPGA_SET_REG(info->fpga, mdio.control,
46 ((addr & 0x1f) << 5) | (regnum & 0x1f) | (2 << 10));
48 /* wait for rx data available */
51 FPGA_GET_REG(info->fpga, mdio.rx_data, &val);
56 static int ihs_mdio_write(struct mii_dev *bus, int addr, int dev_addr,
57 int regnum, u16 value)
59 struct ihs_mdio_info *info = bus->priv;
63 FPGA_SET_REG(info->fpga, mdio.address_data, value);
64 FPGA_SET_REG(info->fpga, mdio.control,
65 ((addr & 0x1f) << 5) | (regnum & 0x1f) | (1 << 10));
70 int ihs_mdio_init(struct ihs_mdio_info *info)
72 struct mii_dev *bus = mdio_alloc();
75 printf("Failed to allocate FSL MDIO bus\n");
79 bus->read = ihs_mdio_read;
80 bus->write = ihs_mdio_write;
81 bus->reset = ihs_mdio_reset;
82 strcpy(bus->name, info->name);
86 return mdio_register(bus);