Commit 14eeb6e0 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski Committed by David S. Miller

of: mdio: provide devm_of_mdiobus_register()

Implement a managed variant of of_mdiobus_register(). We need to make
mdio_devres into its own module because otherwise we'd hit circular
sumbol dependencies between phylib and of_mdio.
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a0bd96f5
...@@ -343,6 +343,7 @@ MDIO ...@@ -343,6 +343,7 @@ MDIO
devm_mdiobus_alloc() devm_mdiobus_alloc()
devm_mdiobus_alloc_size() devm_mdiobus_alloc_size()
devm_mdiobus_register() devm_mdiobus_register()
devm_of_mdiobus_register()
MEM MEM
devm_free_pages() devm_free_pages()
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
libphy-y := phy.o phy-c45.o phy-core.o phy_device.o \ libphy-y := phy.o phy-c45.o phy-core.o phy_device.o \
linkmode.o linkmode.o
mdio-bus-y += mdio_bus.o mdio_device.o mdio_devres.o mdio-bus-y += mdio_bus.o mdio_device.o
mdio-devres-y += mdio_devres.o
ifdef CONFIG_MDIO_DEVICE ifdef CONFIG_MDIO_DEVICE
obj-y += mdio-boardinfo.o obj-y += mdio-boardinfo.o
...@@ -17,6 +18,7 @@ libphy-y += $(mdio-bus-y) ...@@ -17,6 +18,7 @@ libphy-y += $(mdio-bus-y)
else else
obj-$(CONFIG_MDIO_DEVICE) += mdio-bus.o obj-$(CONFIG_MDIO_DEVICE) += mdio-bus.o
endif endif
obj-$(CONFIG_MDIO_DEVICE) += mdio-devres.o
libphy-$(CONFIG_SWPHY) += swphy.o libphy-$(CONFIG_SWPHY) += swphy.o
libphy-$(CONFIG_LED_TRIGGER_PHY) += phy_led_triggers.o libphy-$(CONFIG_LED_TRIGGER_PHY) += phy_led_triggers.o
......
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <linux/device.h> #include <linux/device.h>
#include <linux/of_mdio.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/stddef.h> #include <linux/stddef.h>
...@@ -94,3 +95,39 @@ int __devm_mdiobus_register(struct device *dev, struct mii_bus *bus, ...@@ -94,3 +95,39 @@ int __devm_mdiobus_register(struct device *dev, struct mii_bus *bus,
return 0; return 0;
} }
EXPORT_SYMBOL(__devm_mdiobus_register); EXPORT_SYMBOL(__devm_mdiobus_register);
#if IS_ENABLED(CONFIG_OF_MDIO)
/**
* devm_of_mdiobus_register - Resource managed variant of of_mdiobus_register()
* @dev: Device to register mii_bus for
* @mdio: MII bus structure to register
* @np: Device node to parse
*/
int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
struct device_node *np)
{
struct mdiobus_devres *dr;
int ret;
if (WARN_ON(!devres_find(dev, devm_mdiobus_free,
mdiobus_devres_match, mdio)))
return -EINVAL;
dr = devres_alloc(devm_mdiobus_unregister, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
ret = of_mdiobus_register(mdio, np);
if (ret) {
devres_free(dr);
return ret;
}
dr->mii = mdio;
devres_add(dev, dr);
return 0;
}
EXPORT_SYMBOL(devm_of_mdiobus_register);
#endif /* CONFIG_OF_MDIO */
MODULE_LICENSE("GPL");
...@@ -8,12 +8,15 @@ ...@@ -8,12 +8,15 @@
#ifndef __LINUX_OF_MDIO_H #ifndef __LINUX_OF_MDIO_H
#define __LINUX_OF_MDIO_H #define __LINUX_OF_MDIO_H
#include <linux/device.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/of.h> #include <linux/of.h>
#if IS_ENABLED(CONFIG_OF_MDIO) #if IS_ENABLED(CONFIG_OF_MDIO)
bool of_mdiobus_child_is_phy(struct device_node *child); bool of_mdiobus_child_is_phy(struct device_node *child);
int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np); int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np);
int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
struct device_node *np);
struct phy_device *of_phy_find_device(struct device_node *phy_np); struct phy_device *of_phy_find_device(struct device_node *phy_np);
struct phy_device * struct phy_device *
of_phy_connect(struct net_device *dev, struct device_node *phy_np, of_phy_connect(struct net_device *dev, struct device_node *phy_np,
......
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