Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Bartosz Golaszewski and committed by
David S. Miller
14eeb6e0 a0bd96f5

+44 -1
+1
Documentation/driver-api/driver-model/devres.rst
··· 343 343 devm_mdiobus_alloc() 344 344 devm_mdiobus_alloc_size() 345 345 devm_mdiobus_register() 346 + devm_of_mdiobus_register() 346 347 347 348 MEM 348 349 devm_free_pages()
+3 -1
drivers/net/phy/Makefile
··· 3 3 4 4 libphy-y := phy.o phy-c45.o phy-core.o phy_device.o \ 5 5 linkmode.o 6 - mdio-bus-y += mdio_bus.o mdio_device.o mdio_devres.o 6 + mdio-bus-y += mdio_bus.o mdio_device.o 7 + mdio-devres-y += mdio_devres.o 7 8 8 9 ifdef CONFIG_MDIO_DEVICE 9 10 obj-y += mdio-boardinfo.o ··· 18 17 else 19 18 obj-$(CONFIG_MDIO_DEVICE) += mdio-bus.o 20 19 endif 20 + obj-$(CONFIG_MDIO_DEVICE) += mdio-devres.o 21 21 libphy-$(CONFIG_SWPHY) += swphy.o 22 22 libphy-$(CONFIG_LED_TRIGGER_PHY) += phy_led_triggers.o 23 23
+37
drivers/net/phy/mdio_devres.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 2 3 3 #include <linux/device.h> 4 + #include <linux/of_mdio.h> 4 5 #include <linux/phy.h> 5 6 #include <linux/stddef.h> 6 7 ··· 95 94 return 0; 96 95 } 97 96 EXPORT_SYMBOL(__devm_mdiobus_register); 97 + 98 + #if IS_ENABLED(CONFIG_OF_MDIO) 99 + /** 100 + * devm_of_mdiobus_register - Resource managed variant of of_mdiobus_register() 101 + * @dev: Device to register mii_bus for 102 + * @mdio: MII bus structure to register 103 + * @np: Device node to parse 104 + */ 105 + int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio, 106 + struct device_node *np) 107 + { 108 + struct mdiobus_devres *dr; 109 + int ret; 110 + 111 + if (WARN_ON(!devres_find(dev, devm_mdiobus_free, 112 + mdiobus_devres_match, mdio))) 113 + return -EINVAL; 114 + 115 + dr = devres_alloc(devm_mdiobus_unregister, sizeof(*dr), GFP_KERNEL); 116 + if (!dr) 117 + return -ENOMEM; 118 + 119 + ret = of_mdiobus_register(mdio, np); 120 + if (ret) { 121 + devres_free(dr); 122 + return ret; 123 + } 124 + 125 + dr->mii = mdio; 126 + devres_add(dev, dr); 127 + return 0; 128 + } 129 + EXPORT_SYMBOL(devm_of_mdiobus_register); 130 + #endif /* CONFIG_OF_MDIO */ 131 + 132 + MODULE_LICENSE("GPL");
+3
include/linux/of_mdio.h
··· 8 8 #ifndef __LINUX_OF_MDIO_H 9 9 #define __LINUX_OF_MDIO_H 10 10 11 + #include <linux/device.h> 11 12 #include <linux/phy.h> 12 13 #include <linux/of.h> 13 14 14 15 #if IS_ENABLED(CONFIG_OF_MDIO) 15 16 bool of_mdiobus_child_is_phy(struct device_node *child); 16 17 int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np); 18 + int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio, 19 + struct device_node *np); 17 20 struct phy_device *of_phy_find_device(struct device_node *phy_np); 18 21 struct phy_device * 19 22 of_phy_connect(struct net_device *dev, struct device_node *phy_np,