[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1529292733-13243-2-git-send-email-liwei1412@163.com>
Date: Mon, 18 Jun 2018 11:32:13 +0800
From: Wei Li <liwei1412@....com>
To: andrew@...n.ch, f.fainelli@...il.com
Cc: netdev@...r.kernel.org
Subject: [PATCH 2/2] eth phy: add mdio bus char device interface
Add the notifier for the change of mdio bus, since i wanna that a char device
represents a mii_bus not a mdio_device.
Signed-off-by: Wei Li <liwei1412@....com>
---
drivers/net/phy/mdio_bus.c | 21 ++++++++++++++++++++-
include/linux/mdio.h | 1 +
include/linux/phy.h | 2 ++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 24b5511..3821dc8 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -240,10 +240,25 @@ static void mdiobus_release(struct device *d)
kfree(bus);
}
-static struct class mdio_bus_class = {
+struct class mdio_bus_class = {
.name = "mdio_bus",
.dev_release = mdiobus_release,
};
+EXPORT_SYMBOL_GPL(mdio_bus_class);
+
+static BLOCKING_NOTIFIER_HEAD(mdio_bus_notifier_list);
+
+int mdiobus_register_notifier(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_register(
+ &mdio_bus_notifier_list, nb);
+}
+
+int mdiobus_unregister_notifier(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_unregister(
+ &mdio_bus_notifier_list, nb);
+}
#if IS_ENABLED(CONFIG_OF_MDIO)
/* Helper function for of_mdio_find_bus */
@@ -418,6 +433,8 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device);
bus->state = MDIOBUS_REGISTERED;
+ blocking_notifier_call_chain(&mdio_bus_notifier_list,
+ BUS_NOTIFY_ADD_DEVICE, &bus->dev);
pr_info("%s: probed\n", bus->name);
return 0;
@@ -446,6 +463,8 @@ void mdiobus_unregister(struct mii_bus *bus)
int i;
BUG_ON(bus->state != MDIOBUS_REGISTERED);
+ blocking_notifier_call_chain(&mdio_bus_notifier_list,
+ BUS_NOTIFY_DEL_DEVICE, &bus->dev);
bus->state = MDIOBUS_UNREGISTERED;
for (i = 0; i < PHY_MAX_ADDR; i++) {
diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 2cfffe5..29ab455 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -79,6 +79,7 @@ void mdio_device_reset(struct mdio_device *mdiodev, int value);
int mdio_driver_register(struct mdio_driver *drv);
void mdio_driver_unregister(struct mdio_driver *drv);
int mdio_device_bus_match(struct device *dev, struct device_driver *drv);
+extern struct class mdio_bus_class;
static inline bool mdio_phy_id_is_c45(int phy_id)
{
diff --git a/include/linux/phy.h b/include/linux/phy.h
index f0b5870..39f2609 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -246,6 +246,8 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner);
#define mdiobus_register(bus) __mdiobus_register(bus, THIS_MODULE)
void mdiobus_unregister(struct mii_bus *bus);
void mdiobus_free(struct mii_bus *bus);
+int mdiobus_register_notifier(struct notifier_block *nb);
+int mdiobus_unregister_notifier(struct notifier_block *nb);
struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv);
static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
{
--
2.1.4
Powered by blists - more mailing lists