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

net: mdio: common handling of phy device reset properties

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

authored by

Buday Csaba and committed by
Jakub Kicinski
acde7ad9 02aeff20

+34 -25
-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 */
+1 -1
drivers/net/phy/mdio-private.h
··· 6 6 */ 7 7 8 8 int mdio_device_register_reset(struct mdio_device *mdiodev); 9 - int mdio_device_register_gpiod(struct mdio_device *mdiodev); 9 + void mdio_device_unregister_reset(struct mdio_device *mdiodev); 10 10 11 11 #endif /* __MDIO_PRIVATE_H */
+2 -10
drivers/net/phy/mdio_bus.c
··· 42 42 return -EBUSY; 43 43 44 44 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) { 45 - err = mdio_device_register_gpiod(mdiodev); 45 + err = mdio_device_register_reset(mdiodev); 46 46 if (err) 47 47 return err; 48 - 49 - err = mdio_device_register_reset(mdiodev); 50 - if (err) { 51 - gpiod_put(mdiodev->reset_gpio); 52 - mdiodev->reset_gpio = NULL; 53 - return err; 54 - } 55 48 56 49 /* Assert the reset signal */ 57 50 mdio_device_reset(mdiodev, 1); ··· 61 68 if (mdiodev->bus->mdio_map[mdiodev->addr] != mdiodev) 62 69 return -EINVAL; 63 70 64 - gpiod_put(mdiodev->reset_gpio); 65 - reset_control_put(mdiodev->reset_ctrl); 71 + mdio_device_unregister_reset(mdiodev); 66 72 67 73 mdiodev->bus->mdio_map[mdiodev->addr] = NULL; 68 74
+31 -9
drivers/net/phy/mdio_device.c
··· 119 119 } 120 120 EXPORT_SYMBOL(mdio_device_remove); 121 121 122 - int mdio_device_register_gpiod(struct mdio_device *mdiodev) 122 + /** 123 + * mdio_device_register_reset - Read and initialize the reset properties of 124 + * an mdio device 125 + * @mdiodev: mdio_device structure 126 + * 127 + * Return: Zero if successful, negative error code on failure 128 + */ 129 + int mdio_device_register_reset(struct mdio_device *mdiodev) 123 130 { 131 + struct reset_control *reset; 132 + 124 133 /* Deassert the optional reset signal */ 125 134 mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev, 126 135 "reset", GPIOD_OUT_LOW); ··· 139 130 if (mdiodev->reset_gpio) 140 131 gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset"); 141 132 142 - return 0; 143 - } 144 - 145 - int mdio_device_register_reset(struct mdio_device *mdiodev) 146 - { 147 - struct reset_control *reset; 148 - 149 133 reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy"); 150 - if (IS_ERR(reset)) 134 + if (IS_ERR(reset)) { 135 + gpiod_put(mdiodev->reset_gpio); 136 + mdiodev->reset_gpio = NULL; 151 137 return PTR_ERR(reset); 138 + } 152 139 153 140 mdiodev->reset_ctrl = reset; 154 141 142 + /* Read optional firmware properties */ 143 + fwnode_property_read_u32(dev_fwnode(&mdiodev->dev), "reset-assert-us", 144 + &mdiodev->reset_assert_delay); 145 + fwnode_property_read_u32(dev_fwnode(&mdiodev->dev), "reset-deassert-us", 146 + &mdiodev->reset_deassert_delay); 147 + 155 148 return 0; 149 + } 150 + 151 + /** 152 + * mdio_device_unregister_reset - uninitialize the reset properties of 153 + * an mdio device 154 + * @mdiodev: mdio_device structure 155 + */ 156 + void mdio_device_unregister_reset(struct mdio_device *mdiodev) 157 + { 158 + gpiod_put(mdiodev->reset_gpio); 159 + reset_control_put(mdiodev->reset_ctrl); 156 160 } 157 161 158 162 void mdio_device_reset(struct mdio_device *mdiodev, int value)