14 #include <linux/kernel.h>
15 #include <linux/slab.h>
17 #include <linux/module.h>
19 #include <linux/mdio.h>
34 #define MDIO_STAT_CLKDIV(x) (((x>>1) & 0xff) << 8)
35 #define MDIO_STAT_BSY (1 << 0)
36 #define MDIO_STAT_RD_ER (1 << 1)
37 #define MDIO_CTL_DEV_ADDR(x) (x & 0x1f)
38 #define MDIO_CTL_PORT_ADDR(x) ((x & 0x1f) << 5)
39 #define MDIO_CTL_PRE_DIS (1 << 10)
40 #define MDIO_CTL_SCAN_EN (1 << 11)
41 #define MDIO_CTL_POST_INC (1 << 14)
42 #define MDIO_CTL_READ (1 << 15)
44 #define MDIO_DATA(x) (x & 0xffff)
45 #define MDIO_DATA_BSY (1 << 31)
50 static int xgmac_wait_until_free(
struct device *
dev,
56 status = spin_event_timeout(
59 dev_err(dev,
"timeout waiting for bus to be free\n");
69 static int xgmac_wait_until_done(
struct device *
dev,
75 status = spin_event_timeout(
78 dev_err(dev,
"timeout waiting for operation to complete\n");
99 ret = xgmac_wait_until_free(&bus->
dev, regs);
110 ret = xgmac_wait_until_free(&bus->
dev, regs);
117 ret = xgmac_wait_until_done(&bus->
dev, regs);
129 static int xgmac_mdio_read(
struct mii_bus *bus,
int phy_id,
int regnum)
140 ret = xgmac_wait_until_free(&bus->
dev, regs);
151 ret = xgmac_wait_until_free(&bus->
dev, regs);
158 ret = xgmac_wait_until_done(&bus->
dev, regs);
175 static int xgmac_mdio_reset(
struct mii_bus *bus)
185 ret = xgmac_wait_until_free(&bus->
dev, regs);
201 dev_err(&pdev->
dev,
"could not obtain address\n");
209 bus->
name =
"Freescale XGMAC MDIO Bus";
210 bus->
read = xgmac_mdio_read;
211 bus->
write = xgmac_mdio_write;
212 bus->
reset = xgmac_mdio_reset;
226 dev_err(&pdev->
dev,
"cannot register MDIO bus\n");
227 goto err_registration;
256 .compatible =
"fsl,fman-xmdio",
264 .name =
"fsl-fman_xmdio",
265 .of_match_table = xgmac_mdio_match,
267 .probe = xgmac_mdio_probe,
268 .remove = xgmac_mdio_remove,