* [PATCH net-next v3 0/3] net: mdio: improve reset handling of mdio devices
@ 2025-11-18 13:58 Buday Csaba
2025-11-18 13:58 ` [PATCH net-next v3 1/3] net: mdio: move device reset functions to mdio_device.c Buday Csaba
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Buday Csaba @ 2025-11-18 13:58 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Philipp Zabel,
linux-kernel, netdev
Cc: Buday Csaba
This patchset refactors and slightly improves the reset handling of
`mdio_device`.
The patches were split from a larger series, discussed previously in the
links below.
The difference between v2 and v3, is that the helper function declarations
have been moved to a new header file: drivers/net/phy/mdio-private.h
See links for the previous versions, and for the now separate leak fix.
Link: https://lore.kernel.org/all/cover.1761732347.git.buday.csaba@prolan.hu/
Link: https://lore.kernel.org/all/cover.1761909948.git.buday.csaba@prolan.hu/
Link: https://lore.kernel.org/all/4b419377f8dd7d2f63f919d0f74a336c734f8fff.1762584481.git.buday.csaba@prolan.hu/
Link: https://lore.kernel.org/all/cover.1763371003.git.buday.csaba@prolan.hu/
Buday Csaba (3):
net: mdio: move device reset functions to mdio_device.c
net: mdio: common handling of phy device reset properties
net: mdio: improve reset handling in mdio_device.c
drivers/net/mdio/fwnode_mdio.c | 5 ----
drivers/net/phy/mdio-private.h | 11 +++++++
drivers/net/phy/mdio_bus.c | 40 ++-----------------------
drivers/net/phy/mdio_device.c | 54 ++++++++++++++++++++++++++++++++++
4 files changed, 68 insertions(+), 42 deletions(-)
create mode 100644 drivers/net/phy/mdio-private.h
base-commit: c9dfb92de0738eb7fe6a591ad1642333793e8b6e
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next v3 1/3] net: mdio: move device reset functions to mdio_device.c
2025-11-18 13:58 [PATCH net-next v3 0/3] net: mdio: improve reset handling of mdio devices Buday Csaba
@ 2025-11-18 13:58 ` Buday Csaba
2025-11-18 13:58 ` [PATCH net-next v3 2/3] net: mdio: common handling of phy device reset properties Buday Csaba
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Buday Csaba @ 2025-11-18 13:58 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Philipp Zabel,
linux-kernel, netdev
Cc: Buday Csaba
The functions mdiobus_register_gpiod() and mdiobus_register_reset()
handle the mdio device reset initialization, which belong to
mdio_device.c.
Move them from mdio_bus.c to mdio_device.c, and rename them to match
the corresponding source file: mdio_device_register_gpio() and
mdio_device_register_reset().
Remove 'static' qualifiers and declare them in
drivers/net/phy/mdio-private.h (new header file).
Signed-off-by: Buday Csaba <buday.csaba@prolan.hu>
---
V2 -> V3: removed declarations from include/linux/mdio.h to
drivers/net/phy/mdio-private.h on maintainer request.
V1 -> V2: rebase, no changes
---
drivers/net/phy/mdio-private.h | 11 +++++++++++
drivers/net/phy/mdio_bus.c | 32 +++-----------------------------
drivers/net/phy/mdio_device.c | 28 ++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 29 deletions(-)
create mode 100644 drivers/net/phy/mdio-private.h
diff --git a/drivers/net/phy/mdio-private.h b/drivers/net/phy/mdio-private.h
new file mode 100644
index 000000000..44e2e0907
--- /dev/null
+++ b/drivers/net/phy/mdio-private.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef __MDIO_PRIVATE_H
+#define __MDIO_PRIVATE_H
+
+/* MDIO internal helpers
+ */
+
+int mdio_device_register_reset(struct mdio_device *mdiodev);
+int mdio_device_register_gpiod(struct mdio_device *mdiodev);
+
+#endif /* __MDIO_PRIVATE_H */
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 435424113..575b8bb5b 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -29,37 +29,11 @@
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/unistd.h>
+#include "mdio-private.h"
#define CREATE_TRACE_POINTS
#include <trace/events/mdio.h>
-static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
-{
- /* Deassert the optional reset signal */
- mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev,
- "reset", GPIOD_OUT_LOW);
- if (IS_ERR(mdiodev->reset_gpio))
- return PTR_ERR(mdiodev->reset_gpio);
-
- if (mdiodev->reset_gpio)
- gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset");
-
- return 0;
-}
-
-static int mdiobus_register_reset(struct mdio_device *mdiodev)
-{
- struct reset_control *reset;
-
- reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
- if (IS_ERR(reset))
- return PTR_ERR(reset);
-
- mdiodev->reset_ctrl = reset;
-
- return 0;
-}
-
int mdiobus_register_device(struct mdio_device *mdiodev)
{
int err;
@@ -68,11 +42,11 @@ int mdiobus_register_device(struct mdio_device *mdiodev)
return -EBUSY;
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
- err = mdiobus_register_gpiod(mdiodev);
+ err = mdio_device_register_gpiod(mdiodev);
if (err)
return err;
- err = mdiobus_register_reset(mdiodev);
+ err = mdio_device_register_reset(mdiodev);
if (err) {
gpiod_put(mdiodev->reset_gpio);
mdiodev->reset_gpio = NULL;
diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c
index f64176e0e..0e04bddd3 100644
--- a/drivers/net/phy/mdio_device.c
+++ b/drivers/net/phy/mdio_device.c
@@ -22,6 +22,7 @@
#include <linux/string.h>
#include <linux/unistd.h>
#include <linux/property.h>
+#include "mdio-private.h"
void mdio_device_free(struct mdio_device *mdiodev)
{
@@ -118,6 +119,33 @@ void mdio_device_remove(struct mdio_device *mdiodev)
}
EXPORT_SYMBOL(mdio_device_remove);
+int mdio_device_register_gpiod(struct mdio_device *mdiodev)
+{
+ /* Deassert the optional reset signal */
+ mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev,
+ "reset", GPIOD_OUT_LOW);
+ if (IS_ERR(mdiodev->reset_gpio))
+ return PTR_ERR(mdiodev->reset_gpio);
+
+ if (mdiodev->reset_gpio)
+ gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset");
+
+ return 0;
+}
+
+int mdio_device_register_reset(struct mdio_device *mdiodev)
+{
+ struct reset_control *reset;
+
+ reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
+ if (IS_ERR(reset))
+ return PTR_ERR(reset);
+
+ mdiodev->reset_ctrl = reset;
+
+ return 0;
+}
+
void mdio_device_reset(struct mdio_device *mdiodev, int value)
{
unsigned int d;
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next v3 2/3] net: mdio: common handling of phy device reset properties
2025-11-18 13:58 [PATCH net-next v3 0/3] net: mdio: improve reset handling of mdio devices Buday Csaba
2025-11-18 13:58 ` [PATCH net-next v3 1/3] net: mdio: move device reset functions to mdio_device.c Buday Csaba
@ 2025-11-18 13:58 ` Buday Csaba
2025-11-18 13:58 ` [PATCH net-next v3 3/3] net: mdio: improve reset handling in mdio_device.c Buday Csaba
2025-11-21 1:50 ` [PATCH net-next v3 0/3] net: mdio: improve reset handling of mdio devices patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Buday Csaba @ 2025-11-18 13:58 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Philipp Zabel,
linux-kernel, netdev
Cc: Buday Csaba
Unify the handling of the per device reset properties for
`mdio_device`.
Merge mdio_device_register_gpiod() and mdio_device_register_reset()
into mdio_device_register_reset(), that handles both
reset-controllers and reset-gpios.
Move reading of the reset firmware properties (reset-assert-us,
reset-deassert-us) from fwnode_mdio.c to mdio_device_register_reset(),
so all reset related initialization code is kept in one place.
Introduce mdio_device_unregister_reset() to release the associated
resources.
These changes make tracking the reset properties easier.
Added kernel-doc for mdio_device_register/unregister_reset().
Signed-off-by: Buday Csaba <buday.csaba@prolan.hu>
---
V2 -> V3: moved declarations to drivers/net/phy/mdio-private.h
V1 -> V2: rebase, no change (leak fix already applied to base)
---
drivers/net/mdio/fwnode_mdio.c | 5 -----
drivers/net/phy/mdio-private.h | 2 +-
drivers/net/phy/mdio_bus.c | 12 ++--------
drivers/net/phy/mdio_device.c | 40 ++++++++++++++++++++++++++--------
4 files changed, 34 insertions(+), 25 deletions(-)
diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c
index 9b41d4697..ba7091518 100644
--- a/drivers/net/mdio/fwnode_mdio.c
+++ b/drivers/net/mdio/fwnode_mdio.c
@@ -92,11 +92,6 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,
if (fwnode_property_read_bool(child, "broken-turn-around"))
mdio->phy_ignore_ta_mask |= 1 << addr;
- fwnode_property_read_u32(child, "reset-assert-us",
- &phy->mdio.reset_assert_delay);
- fwnode_property_read_u32(child, "reset-deassert-us",
- &phy->mdio.reset_deassert_delay);
-
/* Associate the fwnode with the device structure so it
* can be looked up later
*/
diff --git a/drivers/net/phy/mdio-private.h b/drivers/net/phy/mdio-private.h
index 44e2e0907..8bc6d9088 100644
--- a/drivers/net/phy/mdio-private.h
+++ b/drivers/net/phy/mdio-private.h
@@ -6,6 +6,6 @@
*/
int mdio_device_register_reset(struct mdio_device *mdiodev);
-int mdio_device_register_gpiod(struct mdio_device *mdiodev);
+void mdio_device_unregister_reset(struct mdio_device *mdiodev);
#endif /* __MDIO_PRIVATE_H */
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 575b8bb5b..ef041ad66 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -42,16 +42,9 @@ int mdiobus_register_device(struct mdio_device *mdiodev)
return -EBUSY;
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
- err = mdio_device_register_gpiod(mdiodev);
- if (err)
- return err;
-
err = mdio_device_register_reset(mdiodev);
- if (err) {
- gpiod_put(mdiodev->reset_gpio);
- mdiodev->reset_gpio = NULL;
+ if (err)
return err;
- }
/* Assert the reset signal */
mdio_device_reset(mdiodev, 1);
@@ -68,8 +61,7 @@ int mdiobus_unregister_device(struct mdio_device *mdiodev)
if (mdiodev->bus->mdio_map[mdiodev->addr] != mdiodev)
return -EINVAL;
- gpiod_put(mdiodev->reset_gpio);
- reset_control_put(mdiodev->reset_ctrl);
+ mdio_device_unregister_reset(mdiodev);
mdiodev->bus->mdio_map[mdiodev->addr] = NULL;
diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c
index 0e04bddd3..a4d9c6ccf 100644
--- a/drivers/net/phy/mdio_device.c
+++ b/drivers/net/phy/mdio_device.c
@@ -119,8 +119,17 @@ void mdio_device_remove(struct mdio_device *mdiodev)
}
EXPORT_SYMBOL(mdio_device_remove);
-int mdio_device_register_gpiod(struct mdio_device *mdiodev)
+/**
+ * mdio_device_register_reset - Read and initialize the reset properties of
+ * an mdio device
+ * @mdiodev: mdio_device structure
+ *
+ * Return: Zero if successful, negative error code on failure
+ */
+int mdio_device_register_reset(struct mdio_device *mdiodev)
{
+ struct reset_control *reset;
+
/* Deassert the optional reset signal */
mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev,
"reset", GPIOD_OUT_LOW);
@@ -130,22 +139,35 @@ int mdio_device_register_gpiod(struct mdio_device *mdiodev)
if (mdiodev->reset_gpio)
gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset");
- return 0;
-}
-
-int mdio_device_register_reset(struct mdio_device *mdiodev)
-{
- struct reset_control *reset;
-
reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
- if (IS_ERR(reset))
+ if (IS_ERR(reset)) {
+ gpiod_put(mdiodev->reset_gpio);
+ mdiodev->reset_gpio = NULL;
return PTR_ERR(reset);
+ }
mdiodev->reset_ctrl = reset;
+ /* Read optional firmware properties */
+ fwnode_property_read_u32(dev_fwnode(&mdiodev->dev), "reset-assert-us",
+ &mdiodev->reset_assert_delay);
+ fwnode_property_read_u32(dev_fwnode(&mdiodev->dev), "reset-deassert-us",
+ &mdiodev->reset_deassert_delay);
+
return 0;
}
+/**
+ * mdio_device_unregister_reset - uninitialize the reset properties of
+ * an mdio device
+ * @mdiodev: mdio_device structure
+ */
+void mdio_device_unregister_reset(struct mdio_device *mdiodev)
+{
+ gpiod_put(mdiodev->reset_gpio);
+ reset_control_put(mdiodev->reset_ctrl);
+}
+
void mdio_device_reset(struct mdio_device *mdiodev, int value)
{
unsigned int d;
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next v3 3/3] net: mdio: improve reset handling in mdio_device.c
2025-11-18 13:58 [PATCH net-next v3 0/3] net: mdio: improve reset handling of mdio devices Buday Csaba
2025-11-18 13:58 ` [PATCH net-next v3 1/3] net: mdio: move device reset functions to mdio_device.c Buday Csaba
2025-11-18 13:58 ` [PATCH net-next v3 2/3] net: mdio: common handling of phy device reset properties Buday Csaba
@ 2025-11-18 13:58 ` Buday Csaba
2025-11-21 1:50 ` [PATCH net-next v3 0/3] net: mdio: improve reset handling of mdio devices patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Buday Csaba @ 2025-11-18 13:58 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Philipp Zabel,
linux-kernel, netdev
Cc: Buday Csaba
Change fwnode_property_read_u32() in mdio_device_register_reset()
to device_property_read_u32(), which is more appropriate here.
Make mdio_device_unregister_reset() truly reverse
mdio_device_register_reset() by setting the internal fields to
their default values.
Signed-off-by: Buday Csaba <buday.csaba@prolan.hu>
---
V2 -> V3: no changes
V1 -> V2: rebase, leak fix removed, since it is already in base
---
drivers/net/phy/mdio_device.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c
index a4d9c6ccf..fd0e16dbc 100644
--- a/drivers/net/phy/mdio_device.c
+++ b/drivers/net/phy/mdio_device.c
@@ -149,9 +149,9 @@ int mdio_device_register_reset(struct mdio_device *mdiodev)
mdiodev->reset_ctrl = reset;
/* Read optional firmware properties */
- fwnode_property_read_u32(dev_fwnode(&mdiodev->dev), "reset-assert-us",
+ device_property_read_u32(&mdiodev->dev, "reset-assert-us",
&mdiodev->reset_assert_delay);
- fwnode_property_read_u32(dev_fwnode(&mdiodev->dev), "reset-deassert-us",
+ device_property_read_u32(&mdiodev->dev, "reset-deassert-us",
&mdiodev->reset_deassert_delay);
return 0;
@@ -165,7 +165,11 @@ int mdio_device_register_reset(struct mdio_device *mdiodev)
void mdio_device_unregister_reset(struct mdio_device *mdiodev)
{
gpiod_put(mdiodev->reset_gpio);
+ mdiodev->reset_gpio = NULL;
reset_control_put(mdiodev->reset_ctrl);
+ mdiodev->reset_ctrl = NULL;
+ mdiodev->reset_assert_delay = 0;
+ mdiodev->reset_deassert_delay = 0;
}
void mdio_device_reset(struct mdio_device *mdiodev, int value)
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v3 0/3] net: mdio: improve reset handling of mdio devices
2025-11-18 13:58 [PATCH net-next v3 0/3] net: mdio: improve reset handling of mdio devices Buday Csaba
` (2 preceding siblings ...)
2025-11-18 13:58 ` [PATCH net-next v3 3/3] net: mdio: improve reset handling in mdio_device.c Buday Csaba
@ 2025-11-21 1:50 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-11-21 1:50 UTC (permalink / raw)
To: Buday Csaba
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, p.zabel,
linux-kernel, netdev
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 18 Nov 2025 14:58:51 +0100 you wrote:
> This patchset refactors and slightly improves the reset handling of
> `mdio_device`.
>
> The patches were split from a larger series, discussed previously in the
> links below.
>
> The difference between v2 and v3, is that the helper function declarations
> have been moved to a new header file: drivers/net/phy/mdio-private.h
> See links for the previous versions, and for the now separate leak fix.
>
> [...]
Here is the summary with links:
- [net-next,v3,1/3] net: mdio: move device reset functions to mdio_device.c
https://git.kernel.org/netdev/net-next/c/02aeff20e8f5
- [net-next,v3,2/3] net: mdio: common handling of phy device reset properties
https://git.kernel.org/netdev/net-next/c/acde7ad968f6
- [net-next,v3,3/3] net: mdio: improve reset handling in mdio_device.c
https://git.kernel.org/netdev/net-next/c/e5a440bf020e
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-21 1:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-18 13:58 [PATCH net-next v3 0/3] net: mdio: improve reset handling of mdio devices Buday Csaba
2025-11-18 13:58 ` [PATCH net-next v3 1/3] net: mdio: move device reset functions to mdio_device.c Buday Csaba
2025-11-18 13:58 ` [PATCH net-next v3 2/3] net: mdio: common handling of phy device reset properties Buday Csaba
2025-11-18 13:58 ` [PATCH net-next v3 3/3] net: mdio: improve reset handling in mdio_device.c Buday Csaba
2025-11-21 1:50 ` [PATCH net-next v3 0/3] net: mdio: improve reset handling of mdio devices patchwork-bot+netdevbpf
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).