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.

net: phy: move mdio_device reset handling functions in the code

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>

authored by

Heiner Kallweit and committed by
Jakub Kicinski
2d7bebc9 a99f06e5

+81 -81
+81 -81
drivers/net/phy/mdio_device.c
··· 24 24 #include <linux/property.h> 25 25 #include "mdio-private.h" 26 26 27 + /** 28 + * mdio_device_register_reset - Read and initialize the reset properties of 29 + * an mdio device 30 + * @mdiodev: mdio_device structure 31 + * 32 + * Return: Zero if successful, negative error code on failure 33 + */ 34 + int mdio_device_register_reset(struct mdio_device *mdiodev) 35 + { 36 + struct reset_control *reset; 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 + reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy"); 48 + if (IS_ERR(reset)) { 49 + gpiod_put(mdiodev->reset_gpio); 50 + mdiodev->reset_gpio = NULL; 51 + return PTR_ERR(reset); 52 + } 53 + 54 + mdiodev->reset_ctrl = reset; 55 + 56 + /* Read optional firmware properties */ 57 + device_property_read_u32(&mdiodev->dev, "reset-assert-us", 58 + &mdiodev->reset_assert_delay); 59 + device_property_read_u32(&mdiodev->dev, "reset-deassert-us", 60 + &mdiodev->reset_deassert_delay); 61 + 62 + return 0; 63 + } 64 + 65 + /** 66 + * mdio_device_unregister_reset - uninitialize the reset properties of 67 + * an mdio device 68 + * @mdiodev: mdio_device structure 69 + */ 70 + void mdio_device_unregister_reset(struct mdio_device *mdiodev) 71 + { 72 + gpiod_put(mdiodev->reset_gpio); 73 + mdiodev->reset_gpio = NULL; 74 + reset_control_put(mdiodev->reset_ctrl); 75 + mdiodev->reset_ctrl = NULL; 76 + mdiodev->reset_assert_delay = 0; 77 + mdiodev->reset_deassert_delay = 0; 78 + } 79 + 80 + void mdio_device_reset(struct mdio_device *mdiodev, int value) 81 + { 82 + unsigned int d; 83 + 84 + if (!mdiodev->reset_gpio && !mdiodev->reset_ctrl) 85 + return; 86 + 87 + if (mdiodev->reset_state == value) 88 + return; 89 + 90 + if (mdiodev->reset_gpio) 91 + gpiod_set_value_cansleep(mdiodev->reset_gpio, value); 92 + 93 + if (mdiodev->reset_ctrl) { 94 + if (value) 95 + reset_control_assert(mdiodev->reset_ctrl); 96 + else 97 + reset_control_deassert(mdiodev->reset_ctrl); 98 + } 99 + 100 + d = value ? mdiodev->reset_assert_delay : mdiodev->reset_deassert_delay; 101 + if (d) 102 + fsleep(d); 103 + 104 + mdiodev->reset_state = value; 105 + } 106 + EXPORT_SYMBOL(mdio_device_reset); 107 + 27 108 void mdio_device_free(struct mdio_device *mdiodev) 28 109 { 29 110 put_device(&mdiodev->dev); ··· 188 107 mdiobus_unregister_device(mdiodev); 189 108 } 190 109 EXPORT_SYMBOL(mdio_device_remove); 191 - 192 - /** 193 - * mdio_device_register_reset - Read and initialize the reset properties of 194 - * an mdio device 195 - * @mdiodev: mdio_device structure 196 - * 197 - * Return: Zero if successful, negative error code on failure 198 - */ 199 - int mdio_device_register_reset(struct mdio_device *mdiodev) 200 - { 201 - struct reset_control *reset; 202 - 203 - /* Deassert the optional reset signal */ 204 - mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev, 205 - "reset", GPIOD_OUT_LOW); 206 - if (IS_ERR(mdiodev->reset_gpio)) 207 - return PTR_ERR(mdiodev->reset_gpio); 208 - 209 - if (mdiodev->reset_gpio) 210 - gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset"); 211 - 212 - reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy"); 213 - if (IS_ERR(reset)) { 214 - gpiod_put(mdiodev->reset_gpio); 215 - mdiodev->reset_gpio = NULL; 216 - return PTR_ERR(reset); 217 - } 218 - 219 - mdiodev->reset_ctrl = reset; 220 - 221 - /* Read optional firmware properties */ 222 - device_property_read_u32(&mdiodev->dev, "reset-assert-us", 223 - &mdiodev->reset_assert_delay); 224 - device_property_read_u32(&mdiodev->dev, "reset-deassert-us", 225 - &mdiodev->reset_deassert_delay); 226 - 227 - return 0; 228 - } 229 - 230 - /** 231 - * mdio_device_unregister_reset - uninitialize the reset properties of 232 - * an mdio device 233 - * @mdiodev: mdio_device structure 234 - */ 235 - void mdio_device_unregister_reset(struct mdio_device *mdiodev) 236 - { 237 - gpiod_put(mdiodev->reset_gpio); 238 - mdiodev->reset_gpio = NULL; 239 - reset_control_put(mdiodev->reset_ctrl); 240 - mdiodev->reset_ctrl = NULL; 241 - mdiodev->reset_assert_delay = 0; 242 - mdiodev->reset_deassert_delay = 0; 243 - } 244 - 245 - void mdio_device_reset(struct mdio_device *mdiodev, int value) 246 - { 247 - unsigned int d; 248 - 249 - if (!mdiodev->reset_gpio && !mdiodev->reset_ctrl) 250 - return; 251 - 252 - if (mdiodev->reset_state == value) 253 - return; 254 - 255 - if (mdiodev->reset_gpio) 256 - gpiod_set_value_cansleep(mdiodev->reset_gpio, value); 257 - 258 - if (mdiodev->reset_ctrl) { 259 - if (value) 260 - reset_control_assert(mdiodev->reset_ctrl); 261 - else 262 - reset_control_deassert(mdiodev->reset_ctrl); 263 - } 264 - 265 - d = value ? mdiodev->reset_assert_delay : mdiodev->reset_deassert_delay; 266 - if (d) 267 - fsleep(d); 268 - 269 - mdiodev->reset_state = value; 270 - } 271 - EXPORT_SYMBOL(mdio_device_reset); 272 110 273 111 /** 274 112 * mdio_probe - probe an MDIO device