From: Jagan Teki <ja...@openedev.com> phy-reset-gpios property needed for adding mii_dev reset bus operation, so the board code not take care of phy_reset anymore if it use DM_ETH
Cc: Joe Hershberger <joe.hershber...@ni.com> Cc: Fabio Estevam <fabio.este...@nxp.com> Signed-off-by: Jagan Teki <ja...@openedev.com> --- drivers/net/fec_mxc.c | 64 +++++++++++++++++++++++++++++++++++++++++++++------ drivers/net/fec_mxc.h | 8 +++++++ include/netdev.h | 5 ++++ 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index 08bea8b..5e16f02 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -180,13 +180,27 @@ static int fec_mdio_write(struct ethernet_regs *eth, uint8_t phyaddr, static int fec_phy_read(struct mii_dev *bus, int phyaddr, int dev_addr, int regaddr) { - return fec_mdio_read(bus->priv, phyaddr, regaddr); +#ifdef CONFIG_DM_ETH + struct fec_priv *priv = dev_get_priv((struct udevice *)bus->priv); + struct ethernet_regs *eth = priv->eth; +#else + struct ethernet_regs *eth = bus->priv; +#endif + + return fec_mdio_read(eth, phyaddr, regaddr); } static int fec_phy_write(struct mii_dev *bus, int phyaddr, int dev_addr, int regaddr, u16 data) { - return fec_mdio_write(bus->priv, phyaddr, regaddr, data); +#ifdef CONFIG_DM_ETH + struct fec_priv *priv = dev_get_priv((struct udevice *)bus->priv); + struct ethernet_regs *eth = priv->eth; +#else + struct ethernet_regs *eth = bus->priv; +#endif + + return fec_mdio_write(eth, phyaddr, regaddr, data); } #ifndef CONFIG_PHYLIB @@ -985,9 +999,36 @@ static void fec_free_descs(struct fec_priv *fec) free(fec->tbd_base); } +#if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_GPIO) +static int fec_phy_reset(struct mii_dev *bus) +{ + struct fec_priv *priv = dev_get_priv((struct udevice *)bus->priv); + + if (!dm_gpio_is_valid(&priv->reset_gpio)) + return 0; + + /* phy reset */ + dm_gpio_set_value(&priv->reset_gpio, 0); + udelay(100); + dm_gpio_set_value(&priv->reset_gpio, 1); + udelay(100); + + return 0; +} +#endif + +#ifdef CONFIG_DM_ETH +struct mii_dev *fec_get_miibus(struct udevice *dev, int dev_id) +#else struct mii_dev *fec_get_miibus(uint32_t base_addr, int dev_id) +#endif { +#ifdef CONFIG_DM_ETH + struct fec_priv *priv = dev_get_priv(dev); + struct ethernet_regs *eth = priv->eth; +#else struct ethernet_regs *eth = (struct ethernet_regs *)base_addr; +#endif struct mii_dev *bus; int ret; @@ -998,7 +1039,14 @@ struct mii_dev *fec_get_miibus(uint32_t base_addr, int dev_id) } bus->read = fec_phy_read; bus->write = fec_phy_write; +#ifdef CONFIG_DM_ETH + bus->priv = dev; +# ifdef CONFIG_DM_GPIO + bus->reset = fec_phy_reset; +# endif +#else bus->priv = eth; +#endif fec_set_dev_name(bus->name, dev_id); ret = mdio_register(bus); @@ -1223,7 +1271,7 @@ static int fecmxc_probe(struct udevice *dev) if (ret) return ret; - bus = fec_get_miibus((uint32_t)priv->eth, dev_id); + bus = fec_get_miibus(dev, dev_id); if (!bus) goto err_mii; @@ -1292,10 +1340,12 @@ 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 + /* phy reset gpio */ + gpio_request_by_name_nodev(gd->fdt_blob, dev_of_offset(dev), + "phy-reset-gpios", 0, + &priv->reset_gpio, GPIOD_IS_OUT); +#endif return 0; } diff --git a/drivers/net/fec_mxc.h b/drivers/net/fec_mxc.h index 43a7d7b..74ede4a 100644 --- a/drivers/net/fec_mxc.h +++ b/drivers/net/fec_mxc.h @@ -17,6 +17,10 @@ #ifndef __FEC_MXC_H #define __FEC_MXC_H +#ifdef CONFIG_DM_GPIO +# include <asm-generic/gpio.h> +#endif + /* Layout description of the FEC */ struct ethernet_regs { /* [10:2]addr = 00 */ @@ -254,6 +258,10 @@ struct fec_priv { #ifdef CONFIG_DM_ETH u32 interface; + +# ifdef CONFIG_DM_GPIO + struct gpio_desc reset_gpio; +# endif #endif }; diff --git a/include/netdev.h b/include/netdev.h index 8eb8b46..e5668f4 100644 --- a/include/netdev.h +++ b/include/netdev.h @@ -133,7 +133,12 @@ static inline int pci_eth_init(bd_t *bis) return num; } +#ifdef CONFIG_DM_ETH +struct mii_dev *fec_get_miibus(struct udevice *dev, int dev_id); +#else struct mii_dev *fec_get_miibus(uint32_t base_addr, int dev_id); +#endif + #ifdef CONFIG_PHYLIB struct phy_device; int fec_probe(bd_t *bd, int dev_id, uint32_t base_addr, -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot