From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Jeff Kirsher <jeffrey.t.kirsher@intel.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, John Crispin <john@phrozen.org>,
Sean Wang <sean.wang@mediatek.com>,
Mark Lee <Mark-MC.Lee@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Rob Herring <robh+dt@kernel.org>,
Frank Rowand <frowand.list@gmail.com>
Cc: devicetree@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 09/10] of: mdio: provide devm_of_mdiobus_register()
Date: Mon, 29 Jun 2020 14:03:45 +0200 [thread overview]
Message-ID: <20200629120346.4382-10-brgl@bgdev.pl> (raw)
In-Reply-To: <20200629120346.4382-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
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>
---
.../driver-api/driver-model/devres.rst | 1 +
drivers/net/phy/Makefile | 4 +-
drivers/net/phy/mdio_devres.c | 37 +++++++++++++++++++
include/linux/of_mdio.h | 3 ++
4 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index e0333d66a7f4..eaaaafc21134 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -343,6 +343,7 @@ MDIO
devm_mdiobus_alloc()
devm_mdiobus_alloc_size()
devm_mdiobus_register()
+ devm_of_mdiobus_register()
MEM
devm_free_pages()
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 896afdcac437..c9a9adf194d5 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -3,7 +3,8 @@
libphy-y := phy.o phy-c45.o phy-core.o phy_device.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
obj-y += mdio-boardinfo.o
@@ -17,6 +18,7 @@ libphy-y += $(mdio-bus-y)
else
obj-$(CONFIG_MDIO_DEVICE) += mdio-bus.o
endif
+obj-$(CONFIG_MDIO_DEVICE) += mdio-devres.o
libphy-$(CONFIG_SWPHY) += swphy.o
libphy-$(CONFIG_LED_TRIGGER_PHY) += phy_led_triggers.o
diff --git a/drivers/net/phy/mdio_devres.c b/drivers/net/phy/mdio_devres.c
index 0b9bd9a61378..b560e99695df 100644
--- a/drivers/net/phy/mdio_devres.c
+++ b/drivers/net/phy/mdio_devres.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <linux/device.h>
+#include <linux/of_mdio.h>
#include <linux/phy.h>
#include <linux/stddef.h>
@@ -94,3 +95,39 @@ int __devm_mdiobus_register(struct device *dev, struct mii_bus *bus,
return 0;
}
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");
diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h
index ba8e157f24ad..1efb88d9f892 100644
--- a/include/linux/of_mdio.h
+++ b/include/linux/of_mdio.h
@@ -8,12 +8,15 @@
#ifndef __LINUX_OF_MDIO_H
#define __LINUX_OF_MDIO_H
+#include <linux/device.h>
#include <linux/phy.h>
#include <linux/of.h>
#if IS_ENABLED(CONFIG_OF_MDIO)
bool of_mdiobus_child_is_phy(struct device_node *child);
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_connect(struct net_device *dev, struct device_node *phy_np,
--
2.26.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-06-29 12:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-29 12:03 [PATCH v2 00/10] net: improve devres helpers Bartosz Golaszewski
2020-06-29 12:03 ` [PATCH v2 01/10] net: ethernet: ixgbe: check the return value of ixgbe_mii_bus_init() Bartosz Golaszewski
2020-06-29 16:57 ` Florian Fainelli
2020-06-29 17:17 ` Kirsher, Jeffrey T
2020-06-29 12:03 ` [PATCH v2 02/10] net: ethernet: ixgbe: don't call devm_mdiobus_free() Bartosz Golaszewski
2020-06-29 16:58 ` Florian Fainelli
2020-06-29 17:18 ` Kirsher, Jeffrey T
2020-06-29 12:03 ` [PATCH v2 03/10] net: devres: rename the release callback of devm_register_netdev() Bartosz Golaszewski
2020-06-29 17:17 ` Florian Fainelli
2020-06-29 12:03 ` [PATCH v2 04/10] Documentation: devres: add missing mdio helper Bartosz Golaszewski
2020-06-29 16:57 ` Florian Fainelli
2020-06-29 12:03 ` [PATCH v2 05/10] phy: un-inline devm_mdiobus_register() Bartosz Golaszewski
2020-06-29 17:19 ` Florian Fainelli
2020-06-29 12:03 ` [PATCH v2 06/10] phy: mdio: add kerneldoc for __devm_mdiobus_register() Bartosz Golaszewski
2020-06-29 17:19 ` Florian Fainelli
2020-06-29 12:03 ` [PATCH v2 07/10] net: phy: don't abuse devres in devm_mdiobus_register() Bartosz Golaszewski
2020-06-29 12:03 ` [PATCH v2 08/10] of: mdio: remove the 'extern' keyword from function declarations Bartosz Golaszewski
2020-06-29 17:20 ` Florian Fainelli
2020-06-29 12:03 ` Bartosz Golaszewski [this message]
2020-06-29 12:03 ` [PATCH v2 10/10] net: ethernet: mtk-star-emac: use devm_of_mdiobus_register() Bartosz Golaszewski
2020-06-30 19:30 ` [PATCH v2 00/10] net: improve devres helpers Jakub Kicinski
2020-06-30 22:58 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200629120346.4382-10-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=Mark-MC.Lee@mediatek.com \
--cc=andrew@lunn.ch \
--cc=bgolaszewski@baylibre.com \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=frowand.list@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=jeffrey.t.kirsher@intel.com \
--cc=john@phrozen.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=matthias.bgg@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=sean.wang@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).