Commit d0281a56 authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller

net: phy: Allow building mdio-boardinfo into the kernel

mdio-boardinfo contains code that is helpful for platforms to register
specific MDIO bus devices independent of how CONFIG_MDIO_DEVICE or
CONFIG_PHYLIB will be selected (modular or built-in). In order to make
that possible, let's do the following:

- descend into drivers/net/phy/ unconditionally

- make mdiobus_setup_mdiodev_from_board_info() take a callback argument
  which allows us not to expose the internal MDIO board info list and
  mutex, yet maintain the logic within the same file

- relocate the code that creates a MDIO device into
  drivers/net/phy/mdio_bus.c

- build mdio-boardinfo.o into the kernel as soon as MDIO_DEVICE is
  defined (y or m)

Fixes: 90eff909 ("net: phy: Allow splitting MDIO bus/device support from PHYs")
Fixes: 648ea013 ("net: phy: Allow pre-declaration of MDIO devices")
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Tested-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2cebaecb
......@@ -18,7 +18,7 @@ obj-$(CONFIG_MII) += mii.o
obj-$(CONFIG_MDIO) += mdio.o
obj-$(CONFIG_NET) += Space.o loopback.o
obj-$(CONFIG_NETCONSOLE) += netconsole.o
obj-$(CONFIG_MDIO_DEVICE) += phy/
obj-y += phy/
obj-$(CONFIG_RIONET) += rionet.o
obj-$(CONFIG_NET_TEAM) += team/
obj-$(CONFIG_TUN) += tun.o
......
# Makefile for Linux PHY drivers and MDIO bus drivers
libphy-y := phy.o phy-core.o phy_device.o
mdio-bus-y += mdio_bus.o mdio_device.o mdio-boardinfo.o
mdio-bus-y += mdio_bus.o mdio_device.o
ifdef CONFIG_MDIO_DEVICE
obj-y += mdio-boardinfo.o
endif
# PHYLIB implies MDIO_DEVICE, in that case, we have a bunch of circular
# dependencies that does not make it possible to split mdio-bus objects into a
......
......@@ -24,10 +24,12 @@ static DEFINE_MUTEX(mdio_board_lock);
* @mdiodev: MDIO device pointer
* Context: can sleep
*/
void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus)
void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus,
int (*cb)
(struct mii_bus *bus,
struct mdio_board_info *bi))
{
struct mdio_board_entry *be;
struct mdio_device *mdiodev;
struct mdio_board_info *bi;
int ret;
......@@ -38,23 +40,14 @@ void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus)
if (strcmp(bus->id, bi->bus_id))
continue;
mdiodev = mdio_device_create(bus, bi->mdio_addr);
if (IS_ERR(mdiodev))
ret = cb(bus, bi);
if (ret)
continue;
strncpy(mdiodev->modalias, bi->modalias,
sizeof(mdiodev->modalias));
mdiodev->bus_match = mdio_device_bus_match;
mdiodev->dev.platform_data = (void *)bi->platform_data;
ret = mdio_device_register(mdiodev);
if (ret) {
mdio_device_free(mdiodev);
continue;
}
}
mutex_unlock(&mdio_board_lock);
}
EXPORT_SYMBOL(mdiobus_setup_mdiodev_from_board_info);
/**
* mdio_register_board_info - register MDIO devices for a given board
......
......@@ -14,6 +14,9 @@ struct mdio_board_entry {
struct mdio_board_info board_info;
};
void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus);
void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus,
int (*cb)
(struct mii_bus *bus,
struct mdio_board_info *bi));
#endif /* __MDIO_BOARD_INFO_H */
......@@ -289,6 +289,36 @@ static inline void of_mdiobus_link_mdiodev(struct mii_bus *mdio,
}
#endif
/**
* mdiobus_create_device_from_board_info - create a full MDIO device given
* a mdio_board_info structure
* @bus: MDIO bus to create the devices on
* @bi: mdio_board_info structure describing the devices
*
* Returns 0 on success or < 0 on error.
*/
static int mdiobus_create_device(struct mii_bus *bus,
struct mdio_board_info *bi)
{
struct mdio_device *mdiodev;
int ret = 0;
mdiodev = mdio_device_create(bus, bi->mdio_addr);
if (IS_ERR(mdiodev))
return -ENODEV;
strncpy(mdiodev->modalias, bi->modalias,
sizeof(mdiodev->modalias));
mdiodev->bus_match = mdio_device_bus_match;
mdiodev->dev.platform_data = (void *)bi->platform_data;
ret = mdio_device_register(mdiodev);
if (ret)
mdio_device_free(mdiodev);
return ret;
}
/**
* __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
* @bus: target mii_bus
......@@ -345,7 +375,7 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
}
}
mdiobus_setup_mdiodev_from_board_info(bus);
mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device);
bus->state = MDIOBUS_REGISTERED;
pr_info("%s: probed\n", bus->name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment