mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 04:24:31 +01:00
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>
This commit is contained in:
parent
02aeff20e8
commit
acde7ad968
4 changed files with 34 additions and 25 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -42,17 +42,10 @@ int mdiobus_register_device(struct mdio_device *mdiodev)
|
|||
return -EBUSY;
|
||||
|
||||
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
|
||||
err = mdio_device_register_gpiod(mdiodev);
|
||||
err = mdio_device_register_reset(mdiodev);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = mdio_device_register_reset(mdiodev);
|
||||
if (err) {
|
||||
gpiod_put(mdiodev->reset_gpio);
|
||||
mdiodev->reset_gpio = NULL;
|
||||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue