From f762eec91dba290af454bf84ee96a3e05e50c0d8 Mon Sep 17 00:00:00 2001 From: Michael Trimarchi Date: Sun, 17 Jun 2018 15:22:39 +0200 Subject: eth: dm: fec: Add gpio phy reset binding Add the missing gpio phy reset binding to the gpio and reset time configuration Signed-off-by: Michael Trimarchi Acked-by: Joe Hershberger (cherry picked from commit efd0b791069af93e9d439a70d1fe2ae8994dbbfa) Conflicts: drivers/net/fec_mxc.c Signed-off-by: Max Krummenacher --- drivers/net/fec_mxc.c | 43 +++++++++++++++++++++++++++++++++++++------ drivers/net/fec_mxc.h | 5 ++++- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index cc23aeacf5..fe389dee1b 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -15,7 +15,6 @@ #include #include #include -#include "fec_mxc.h" #include #include @@ -25,6 +24,9 @@ #include #include #include +#include + +#include "fec_mxc.h" DECLARE_GLOBAL_DATA_PTR; @@ -1258,6 +1260,19 @@ static int fec_phy_init(struct fec_priv *priv, struct udevice *dev) return 0; } +#ifdef CONFIG_DM_GPIO +/* FEC GPIO reset */ +static void fec_gpio_reset(struct fec_priv *priv) +{ + debug("fec_gpio_reset: fec_gpio_reset(dev)\n"); + if (dm_gpio_is_valid(&priv->phy_reset_gpio)) { + dm_gpio_set_value(&priv->phy_reset_gpio, 1); + udelay(priv->reset_delay); + dm_gpio_set_value(&priv->phy_reset_gpio, 0); + } +} +#endif + static int fecmxc_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_platdata(dev); @@ -1278,6 +1293,9 @@ static int fecmxc_probe(struct udevice *dev) if (ret) return ret; +#ifdef CONFIG_DM_GPIO + fec_gpio_reset(priv); +#endif /* Reset chip. */ writel(readl(&priv->eth->ecntrl) | FEC_ECNTRL_RESET, &priv->eth->ecntrl); @@ -1335,6 +1353,7 @@ static int fecmxc_remove(struct udevice *dev) static int fecmxc_ofdata_to_platdata(struct udevice *dev) { + int ret = 0; struct eth_pdata *pdata = dev_get_platdata(dev); struct fec_priv *priv = dev_get_priv(dev); const char *phy_mode; @@ -1352,12 +1371,24 @@ static int fecmxc_ofdata_to_platdata(struct udevice *dev) return -EINVAL; } - /* TODO - * Need to get the reset-gpio and related properties from DT - * and implemet the enet reset code on .probe call - */ +#ifdef CONFIG_DM_GPIO + ret = gpio_request_by_name(dev, "phy-reset-gpios", 0, + &priv->phy_reset_gpio, GPIOD_IS_OUT); + if (ret == 0) { + ret = dev_read_u32_array(dev, "phy-reset-duration", + &priv->reset_delay, 1); + } else if (ret == -ENOENT) { + priv->reset_delay = 1000; + ret = 0; + } - return 0; + if (priv->reset_delay > 1000) { + printf("FEX MXC: gpio reset timeout should be less the 1000\n"); + priv->reset_delay = 1000; + } +#endif + + return ret; } static const struct udevice_id fecmxc_ids[] = { diff --git a/drivers/net/fec_mxc.h b/drivers/net/fec_mxc.h index 43a7d7bed8..dd2a0051c0 100644 --- a/drivers/net/fec_mxc.h +++ b/drivers/net/fec_mxc.h @@ -251,7 +251,10 @@ struct fec_priv { int phy_id; int (*mii_postcall)(int); #endif - +#ifdef CONFIG_DM_GPIO + struct gpio_desc phy_reset_gpio; + uint32_t reset_delay; +#endif #ifdef CONFIG_DM_ETH u32 interface; #endif -- cgit v1.2.3