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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-mdio-improve-reset-handling-of-mdio-devices'

Buday Csaba says:

====================
net: mdio: improve reset handling of mdio devices

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://patch.msgid.link/cover.1763473655.git.buday.csaba@prolan.hu
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+68 -42
-5
drivers/net/mdio/fwnode_mdio.c
··· 92 92 if (fwnode_property_read_bool(child, "broken-turn-around")) 93 93 mdio->phy_ignore_ta_mask |= 1 << addr; 94 94 95 - fwnode_property_read_u32(child, "reset-assert-us", 96 - &phy->mdio.reset_assert_delay); 97 - fwnode_property_read_u32(child, "reset-deassert-us", 98 - &phy->mdio.reset_deassert_delay); 99 - 100 95 /* Associate the fwnode with the device structure so it 101 96 * can be looked up later 102 97 */
+11
drivers/net/phy/mdio-private.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + #ifndef __MDIO_PRIVATE_H 3 + #define __MDIO_PRIVATE_H 4 + 5 + /* MDIO internal helpers 6 + */ 7 + 8 + int mdio_device_register_reset(struct mdio_device *mdiodev); 9 + void mdio_device_unregister_reset(struct mdio_device *mdiodev); 10 + 11 + #endif /* __MDIO_PRIVATE_H */
+3 -37
drivers/net/phy/mdio_bus.c
··· 29 29 #include <linux/string.h> 30 30 #include <linux/uaccess.h> 31 31 #include <linux/unistd.h> 32 + #include "mdio-private.h" 32 33 33 34 #define CREATE_TRACE_POINTS 34 35 #include <trace/events/mdio.h> 35 - 36 - static int mdiobus_register_gpiod(struct mdio_device *mdiodev) 37 - { 38 - /* Deassert the optional reset signal */ 39 - mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev, 40 - "reset", GPIOD_OUT_LOW); 41 - if (IS_ERR(mdiodev->reset_gpio)) 42 - return PTR_ERR(mdiodev->reset_gpio); 43 - 44 - if (mdiodev->reset_gpio) 45 - gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset"); 46 - 47 - return 0; 48 - } 49 - 50 - static int mdiobus_register_reset(struct mdio_device *mdiodev) 51 - { 52 - struct reset_control *reset; 53 - 54 - reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy"); 55 - if (IS_ERR(reset)) 56 - return PTR_ERR(reset); 57 - 58 - mdiodev->reset_ctrl = reset; 59 - 60 - return 0; 61 - } 62 36 63 37 int mdiobus_register_device(struct mdio_device *mdiodev) 64 38 { ··· 42 68 return -EBUSY; 43 69 44 70 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) { 45 - err = mdiobus_register_gpiod(mdiodev); 71 + err = mdio_device_register_reset(mdiodev); 46 72 if (err) 47 73 return err; 48 - 49 - err = mdiobus_register_reset(mdiodev); 50 - if (err) { 51 - gpiod_put(mdiodev->reset_gpio); 52 - mdiodev->reset_gpio = NULL; 53 - return err; 54 - } 55 74 56 75 /* Assert the reset signal */ 57 76 mdio_device_reset(mdiodev, 1); ··· 61 94 if (mdiodev->bus->mdio_map[mdiodev->addr] != mdiodev) 62 95 return -EINVAL; 63 96 64 - gpiod_put(mdiodev->reset_gpio); 65 - reset_control_put(mdiodev->reset_ctrl); 97 + mdio_device_unregister_reset(mdiodev); 66 98 67 99 mdiodev->bus->mdio_map[mdiodev->addr] = NULL; 68 100
+54
drivers/net/phy/mdio_device.c
··· 22 22 #include <linux/string.h> 23 23 #include <linux/unistd.h> 24 24 #include <linux/property.h> 25 + #include "mdio-private.h" 25 26 26 27 void mdio_device_free(struct mdio_device *mdiodev) 27 28 { ··· 118 117 mdiobus_unregister_device(mdiodev); 119 118 } 120 119 EXPORT_SYMBOL(mdio_device_remove); 120 + 121 + /** 122 + * mdio_device_register_reset - Read and initialize the reset properties of 123 + * an mdio device 124 + * @mdiodev: mdio_device structure 125 + * 126 + * Return: Zero if successful, negative error code on failure 127 + */ 128 + int mdio_device_register_reset(struct mdio_device *mdiodev) 129 + { 130 + struct reset_control *reset; 131 + 132 + /* Deassert the optional reset signal */ 133 + mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev, 134 + "reset", GPIOD_OUT_LOW); 135 + if (IS_ERR(mdiodev->reset_gpio)) 136 + return PTR_ERR(mdiodev->reset_gpio); 137 + 138 + if (mdiodev->reset_gpio) 139 + gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset"); 140 + 141 + reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy"); 142 + if (IS_ERR(reset)) { 143 + gpiod_put(mdiodev->reset_gpio); 144 + mdiodev->reset_gpio = NULL; 145 + return PTR_ERR(reset); 146 + } 147 + 148 + mdiodev->reset_ctrl = reset; 149 + 150 + /* Read optional firmware properties */ 151 + device_property_read_u32(&mdiodev->dev, "reset-assert-us", 152 + &mdiodev->reset_assert_delay); 153 + device_property_read_u32(&mdiodev->dev, "reset-deassert-us", 154 + &mdiodev->reset_deassert_delay); 155 + 156 + return 0; 157 + } 158 + 159 + /** 160 + * mdio_device_unregister_reset - uninitialize the reset properties of 161 + * an mdio device 162 + * @mdiodev: mdio_device structure 163 + */ 164 + void mdio_device_unregister_reset(struct mdio_device *mdiodev) 165 + { 166 + gpiod_put(mdiodev->reset_gpio); 167 + mdiodev->reset_gpio = NULL; 168 + reset_control_put(mdiodev->reset_ctrl); 169 + mdiodev->reset_ctrl = NULL; 170 + mdiodev->reset_assert_delay = 0; 171 + mdiodev->reset_deassert_delay = 0; 172 + } 121 173 122 174 void mdio_device_reset(struct mdio_device *mdiodev, int value) 123 175 {