17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/kernel.h>
20 #include <linux/string.h>
21 #include <linux/errno.h>
23 #include <linux/slab.h>
27 #include <linux/device.h>
30 #include <linux/netdevice.h>
35 #include <linux/module.h>
36 #include <linux/mii.h>
37 #include <linux/ethtool.h>
42 #include <asm/uaccess.h>
60 alloc_size = aligned_size +
size;
62 alloc_size =
sizeof(*bus);
68 bus->
priv = (
void *)bus + aligned_size;
82 static void mdiobus_release(
struct device *
d)
91 static struct class mdio_bus_class = {
93 .dev_release = mdiobus_release,
96 #if IS_ENABLED(CONFIG_OF_MDIO)
98 static int of_mdio_bus_match(
struct device *
dev,
void *mdio_bus_np)
100 return dev->
of_node == mdio_bus_np;
147 bus->
state != MDIOBUS_UNREGISTERED);
150 bus->
dev.class = &mdio_bus_class;
156 pr_err(
"mii_bus %s failed to register\n", bus->
id);
166 if ((bus->
phy_mask & (1 << i)) == 0) {
170 if (IS_ERR(phydev)) {
171 err = PTR_ERR(phydev);
177 bus->
state = MDIOBUS_REGISTERED;
196 bus->
state = MDIOBUS_UNREGISTERED;
220 if (bus->
state == MDIOBUS_ALLOCATED) {
226 bus->
state = MDIOBUS_RELEASED;
238 if (IS_ERR(phydev) || phydev ==
NULL)
268 retval = bus->
read(bus, addr, regnum);
293 err = bus->
write(bus, addr, regnum, val);
313 if (of_driver_match_device(dev, drv))
325 static bool mdio_bus_phy_may_suspend(
struct phy_device *phydev)
342 if (netdev->
dev.parent && device_may_wakeup(netdev->
dev.parent))
350 if (device_may_wakeup(&netdev->
dev))
356 static int mdio_bus_suspend(
struct device *dev)
370 if (!mdio_bus_phy_may_suspend(phydev))
373 return phydrv->
suspend(phydev);
376 static int mdio_bus_resume(
struct device *dev)
382 if (!mdio_bus_phy_may_suspend(phydev))
385 ret = phydrv->
resume(phydev);
396 static int mdio_bus_restore(
struct device *dev)
420 .resume = mdio_bus_resume,
421 .freeze = mdio_bus_suspend,
422 .thaw = mdio_bus_resume,
423 .restore = mdio_bus_restore,
426 #define MDIO_BUS_PM_OPS (&mdio_bus_pm_ops)
430 #define MDIO_BUS_PM_OPS NULL
436 .match = mdio_bus_match,