net: mdio: switch to using gpiod_get_optional()
Subsystems (3)
PATCH v2 1/1 net: mdio: switch to using gpiod_get_optional()
The MDIO device reset line is optional and now that gpiod_get_optional() returns proper value when GPIO support is compiled out, there is no reason to use fwnode_get_named_gpiod() that I plan to hide away.
Let's switch to using more standard gpiod_get_optional() and gpiod_set_consumer_name() to keep the nice "PHY reset" label.
Also there is no reason to only try to fetch the reset GPIO when we have OF node, gpiolib can fetch GPIO data from firmwares as well.
---
Note this is an update to a patch titled "[PATCH 05/11] net: mdio:
switch to using fwnode_gpiod_get_index()" that no longer uses the new proposed API and instead works with already existing ones.
drivers/net/phy/mdio_bus.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/net/phy/mdio_bus.c +9 -13
@@ -42,21 +42,17 @@static int mdiobus_register_gpiod (struct mdio_device *mdiodev) { -struct gpio_desc *gpiod =NULL ; +int error;/* Deassert the optional reset signal */ -if (mdiodev->dev.of_node) - gpiod =fwnode_get_named_gpiod (&mdiodev->dev.of_node->fwnode, -"reset-gpios" ,0 ,GPIOD_OUT_LOW , -"PHY reset" ); -if (IS_ERR (gpiod)) { -if (PTR_ERR (gpiod) == -ENOENT ||PTR_ERR (gpiod) == -ENOSYS ) - gpiod =NULL ; -else -return PTR_ERR (gpiod); - } - - mdiodev->reset_gpio = gpiod; + mdiodev->reset_gpio =gpiod_get_optional (&mdiodev->dev, +"reset" ,GPIOD_OUT_LOW ); + error =PTR_ERR_OR_ZERO (mdiodev->reset_gpio); +if (error) +return error; + +if (mdiodev->reset_gpio) +gpiod_set_consumer_name (mdiodev->reset_gpio,"PHY reset" );return 0 ; }
Signature · 5 lines
2.23.0.237.gc6a4ce50a0-goog -- Dmitry
Quoted 11 lines · Dmitry Torokhov
The MDIO device reset line is optional and now that
gpiod_get_optional()returns proper value when GPIO support is compiled out, there is no reason to usefwnode_get_named_gpiod()that I plan to hide away.Let's switch to using more standard
gpiod_get_optional()andgpiod_set_consumer_name()to keep the nice "PHY reset" label.Also there is no reason to only try to fetch the reset GPIO when we have OF node, gpiolib can fetch GPIO data from firmwares as well.
Signed-off-by Dmitry Torokhov <[email protected]>
Andrew
Quoted 10 lines · Dmitry Torokhov
The MDIO device reset line is optional and now that
gpiod_get_optional()returns proper value when GPIO support is compiled out, there is no reason to usefwnode_get_named_gpiod()that I plan to hide away.Let's switch to using more standard
gpiod_get_optional()andgpiod_set_consumer_name()to keep the nice "PHY reset" label.Also there is no reason to only try to fetch the reset GPIO when we have OF node, gpiolib can fetch GPIO data from firmwares as well.
But see comment below.
Quoted 32 lines
Signed-off-by Dmitry Torokhov <[email protected]>---
Note this is an update to a patch titled "[PATCH 05/11] net: mdio:
switch to usingfwnode_gpiod_get_index()" that no longer uses the new proposed API and instead works with already existing ones.drivers/net/phy/mdio_bus.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)drivers/net/phy/mdio_bus.c +1
-11@@ -42,21 +42,17 @@static int mdiobus_register_gpiod (struct mdio_device *mdiodev) { -struct gpio_desc *gpiod =NULL ; +int error;/* Deassert the optional reset signal */ -if (mdiodev->dev.of_node) - gpiod =fwnode_get_named_gpiod (&mdiodev->dev.of_node->fwnode, -"reset-gpios" ,0 ,GPIOD_OUT_LOW , -"PHY reset" ); -if (IS_ERR (gpiod)) { -if (PTR_ERR (gpiod) == -ENOENT ||PTR_ERR (gpiod) == -ENOSYS ) - gpiod =NULL ; -else -return PTR_ERR (gpiod); - }
drivers/net/phy/mdio_bus.c line 55
Quoted 10 lines
drivers/net/phy/mdio_bus.c +7
-2- - mdiodev->reset_gpio = gpiod; + mdiodev->reset_gpio =gpiod_get_optional (&mdiodev->dev, +"reset" ,GPIOD_OUT_LOW ); + error =PTR_ERR_OR_ZERO (mdiodev->reset_gpio); +if (error) +return error; + +if (mdiodev->reset_gpio)
This is redundant check.
Quoted 10 lines
drivers/net/phy/mdio_bus.c +1
-0+gpiod_set_consumer_name (mdiodev->reset_gpio,"PHY reset" );return 0 ;}
Signature · 5 lines
2.23.0.237.gc6a4ce50a0-goog -- Dmitry
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Dmitry Torokhov
The MDIO device reset line is optional and now that
gpiod_get_optional()returns proper value when GPIO support is compiled out, there is no reason to usefwnode_get_named_gpiod()that I plan to hide away.
Quoted 8 lines
Quoted 6 lines
Let's switch to using more standard
gpiod_get_optional()andgpiod_set_consumer_name()to keep the nice "PHY reset" label.Also there is no reason to only try to fetch the reset GPIO when we have OF node, gpiolib can fetch GPIO data from firmwares as well.
Reviewed-by Andy Shevchenko <[email protected]>
Thanks Andy.
Quoted 11 lines
But see comment below.
Quoted 6 lines
drivers/net/phy/mdio_bus.c +6
-0+ mdiodev->reset_gpio =gpiod_get_optional (&mdiodev->dev, +"reset" ,GPIOD_OUT_LOW ); + error =PTR_ERR_OR_ZERO (mdiodev->reset_gpio); +if (error) +return error; +
Quoted 3 lines
drivers/net/phy/mdio_bus.c line 54
Quoted 1 line
drivers/net/phy/mdio_bus.c +1
-0+if (mdiodev->reset_gpio)This is redundant check.
I see that gpiod_* API handle NULL desc and usually return immediately, but frankly I am not that comfortable with it. I'm OK with functions that free/destroy objects that recognize NULL resources, but it is unusual for other types of APIs.
Thanks.
Signature · 1 line
Dmitry
Quoted 11 lines · Dmitry Torokhov
Quoted 10 lines · Andy Shevchenko
Quoted 7 lines · Dmitry Torokhov
drivers/net/phy/mdio_bus.c +6
-0+ mdiodev->reset_gpio =gpiod_get_optional (&mdiodev->dev, +"reset" ,GPIOD_OUT_LOW ); + error =PTR_ERR_OR_ZERO (mdiodev->reset_gpio); +if (error) +return error; +if (mdiodev->reset_gpio)
Quoted 8 lines
Quoted 1 line
This is redundant check.
I see that gpiod_* API handle NULL desc and usually return immediately, but frankly I am not that comfortable with it. I'm OK with functions that free/destroy objects that recognize NULL resources,
but it is
unusual for other types of APIs.
CLK, reset, ... frameworks do check for NULL pointer since they provide an *_optional() getters. So, it's not unusual. --
With Best Regards,
Andy Shevchenko