1 // SPDX-License-Identifier: GPL-2.0+
4 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
9 #include <gdsys_fpga.h>
14 static inline u16 read_control(struct ihs_mdio_info *info)
18 FPGA_GET_REG(info->fpga, mdio.control, &val);
23 static inline void write_control(struct ihs_mdio_info *info, u16 val)
25 FPGA_SET_REG(info->fpga, mdio.control, val);
28 static inline void write_addr_data(struct ihs_mdio_info *info, u16 val)
30 FPGA_SET_REG(info->fpga, mdio.address_data, val);
33 static inline u16 read_rx_data(struct ihs_mdio_info *info)
37 FPGA_GET_REG(info->fpga, mdio.rx_data, &val);
42 static int ihs_mdio_idle(struct mii_dev *bus)
44 struct ihs_mdio_info *info = bus->priv;
49 val = read_control(info);
53 } while (!(val & (1 << 12)));
58 static int ihs_mdio_reset(struct mii_dev *bus)
65 static int ihs_mdio_read(struct mii_dev *bus, int addr, int dev_addr,
68 struct ihs_mdio_info *info = bus->priv;
74 ((addr & 0x1f) << 5) | (regnum & 0x1f) | (2 << 10));
76 /* wait for rx data available */
79 val = read_rx_data(info);
84 static int ihs_mdio_write(struct mii_dev *bus, int addr, int dev_addr,
85 int regnum, u16 value)
87 struct ihs_mdio_info *info = bus->priv;
91 write_addr_data(info, value);
92 write_control(info, ((addr & 0x1f) << 5) | (regnum & 0x1f) | (1 << 10));
97 int ihs_mdio_init(struct ihs_mdio_info *info)
99 struct mii_dev *bus = mdio_alloc();
102 printf("Failed to allocate FSL MDIO bus\n");
106 bus->read = ihs_mdio_read;
107 bus->write = ihs_mdio_write;
108 bus->reset = ihs_mdio_reset;
109 strcpy(bus->name, info->name);
113 return mdio_register(bus);