Skip to content

Commit

Permalink
fec: convert to gpio descriptor
Browse files Browse the repository at this point in the history
The driver can be trivially converted, as it only triggers the gpio
pin briefly to do a reset, and it already only supports DT.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Arnd Bergmann authored and David S. Miller committed Jan 30, 2023
1 parent 453d9fd commit 468ba54
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions drivers/net/ethernet/freescale/fec_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
#include <linux/fec.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
#include <linux/regulator/consumer.h>
#include <linux/if_vlan.h>
#include <linux/pinctrl/consumer.h>
#include <linux/gpio/consumer.h>
#include <linux/prefetch.h>
#include <linux/mfd/syscon.h>
#include <linux/regmap.h>
Expand Down Expand Up @@ -4035,10 +4035,11 @@ static int fec_enet_init(struct net_device *ndev)
#ifdef CONFIG_OF
static int fec_reset_phy(struct platform_device *pdev)
{
int err, phy_reset;
struct gpio_desc *phy_reset;
bool active_high = false;
int msec = 1, phy_post_delay = 0;
struct device_node *np = pdev->dev.of_node;
int err;

if (!np)
return 0;
Expand All @@ -4048,33 +4049,25 @@ static int fec_reset_phy(struct platform_device *pdev)
if (!err && msec > 1000)
msec = 1;

phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
if (phy_reset == -EPROBE_DEFER)
return phy_reset;
else if (!gpio_is_valid(phy_reset))
return 0;

err = of_property_read_u32(np, "phy-reset-post-delay", &phy_post_delay);
/* valid reset duration should be less than 1s */
if (!err && phy_post_delay > 1000)
return -EINVAL;

active_high = of_property_read_bool(np, "phy-reset-active-high");

err = devm_gpio_request_one(&pdev->dev, phy_reset,
active_high ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
"phy-reset");
if (err) {
dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
return err;
}
phy_reset = devm_gpiod_get(&pdev->dev, "phy-reset",
active_high ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW);
if (IS_ERR(phy_reset))
return dev_err_probe(&pdev->dev, PTR_ERR(phy_reset),
"failed to get phy-reset-gpios\n");

if (msec > 20)
msleep(msec);
else
usleep_range(msec * 1000, msec * 1000 + 1000);

gpio_set_value_cansleep(phy_reset, !active_high);
gpiod_set_value_cansleep(phy_reset, !active_high);

if (!phy_post_delay)
return 0;
Expand Down

0 comments on commit 468ba54

Please sign in to comment.