]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: phy: move mdio_device reset handling functions in the code
authorHeiner Kallweit <hkallweit1@gmail.com>
Mon, 9 Mar 2026 17:02:38 +0000 (18:02 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sat, 14 Mar 2026 19:23:01 +0000 (12:23 -0700)
In preparation of a follow-up patch this moves reset-related functions
in the code.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Link: https://patch.msgid.link/8ea1a929-33b8-49ee-afe6-355f5a7d2bd1@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/mdio_device.c

index b8a5a1838196558b09e894fc159cefbd05d807ac..da4fb7484c7c77d456445bff3d0aa88f9f7e6409 100644 (file)
 #include <linux/property.h>
 #include "mdio-private.h"
 
+/**
+ * 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);
+       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");
+
+       reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
+       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 */
+       device_property_read_u32(&mdiodev->dev, "reset-assert-us",
+                                &mdiodev->reset_assert_delay);
+       device_property_read_u32(&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);
+       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)
+{
+       unsigned int d;
+
+       if (!mdiodev->reset_gpio && !mdiodev->reset_ctrl)
+               return;
+
+       if (mdiodev->reset_state == value)
+               return;
+
+       if (mdiodev->reset_gpio)
+               gpiod_set_value_cansleep(mdiodev->reset_gpio, value);
+
+       if (mdiodev->reset_ctrl) {
+               if (value)
+                       reset_control_assert(mdiodev->reset_ctrl);
+               else
+                       reset_control_deassert(mdiodev->reset_ctrl);
+       }
+
+       d = value ? mdiodev->reset_assert_delay : mdiodev->reset_deassert_delay;
+       if (d)
+               fsleep(d);
+
+       mdiodev->reset_state = value;
+}
+EXPORT_SYMBOL(mdio_device_reset);
+
 void mdio_device_free(struct mdio_device *mdiodev)
 {
        put_device(&mdiodev->dev);
@@ -108,87 +189,6 @@ void mdio_device_remove(struct mdio_device *mdiodev)
 }
 EXPORT_SYMBOL(mdio_device_remove);
 
-/**
- * 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);
-       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");
-
-       reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
-       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 */
-       device_property_read_u32(&mdiodev->dev, "reset-assert-us",
-                                &mdiodev->reset_assert_delay);
-       device_property_read_u32(&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);
-       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)
-{
-       unsigned int d;
-
-       if (!mdiodev->reset_gpio && !mdiodev->reset_ctrl)
-               return;
-
-       if (mdiodev->reset_state == value)
-               return;
-
-       if (mdiodev->reset_gpio)
-               gpiod_set_value_cansleep(mdiodev->reset_gpio, value);
-
-       if (mdiodev->reset_ctrl) {
-               if (value)
-                       reset_control_assert(mdiodev->reset_ctrl);
-               else
-                       reset_control_deassert(mdiodev->reset_ctrl);
-       }
-
-       d = value ? mdiodev->reset_assert_delay : mdiodev->reset_deassert_delay;
-       if (d)
-               fsleep(d);
-
-       mdiodev->reset_state = value;
-}
-EXPORT_SYMBOL(mdio_device_reset);
-
 /**
  * mdio_probe - probe an MDIO device
  * @dev: device to probe