[PATCH 1/2] net: designware: eqos: reset phy

Sascha Hauer s.hauer at pengutronix.de
Mon Jun 7 15:22:34 PDT 2021


On Mon, Jun 07, 2021 at 05:59:02PM +0200, Ahmad Fatoum wrote:
> Hello Sascha,
> 
> On 07.06.21 16:10, Sascha Hauer wrote:
> > The designware eqos DT binding has support for specifying reset GPIOs.
> > Add support for them.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  drivers/net/designware_eqos.c | 33 +++++++++++++++++++++++++++++++++
> >  drivers/of/of_gpio.c          |  7 +++++++
> >  2 files changed, 40 insertions(+)
> > 
> > diff --git a/drivers/net/designware_eqos.c b/drivers/net/designware_eqos.c
> > index d2baaeaf63..0321024169 100644
> > --- a/drivers/net/designware_eqos.c
> > +++ b/drivers/net/designware_eqos.c
> > @@ -8,9 +8,11 @@
> >  
> >  #include <common.h>
> >  #include <init.h>
> > +#include <gpio.h>
> >  #include <dma.h>
> >  #include <net.h>
> >  #include <of_net.h>
> > +#include <of_gpio.h>
> >  #include <linux/iopoll.h>
> >  #include <linux/time.h>
> >  #include <linux/sizes.h>
> > @@ -189,6 +191,33 @@ struct eqos_desc {
> >  
> >  #define MII_BUSY		(1 << 0)
> >  
> > +static int eqos_phy_reset(struct device_d *dev, struct eqos *eqos)
> > +{
> > +	int phy_reset;
> > +	int ret;
> > +	u32 delays[3] = { 0, 0, 0 };
> > +
> > +	phy_reset = of_get_named_gpio(dev->device_node, "snps,reset-gpio", 0);
> > +
> > +        if (!gpio_is_valid(phy_reset))
> > +		return 0;
> 
> Whitespace is wrong.
> 
> > +
> > +	ret = gpio_request(phy_reset, "phy-reset");
> > +	if (ret)
> > +		return ret;
> 
> Can you use gpiod_get instead? This would reduce the boilerplate here.

Sure. I didn't realize I don't honour the active high/low flags the way
I did it.

> 
> > +
> > +	of_property_read_u32_array(dev->device_node,
> > +				   "snps,reset-delays-us",
> > +				   delays, ARRAY_SIZE(delays));
> > +
> 
> Looks strange to read out a delay and not act on it. I'd prefer
> waiting delays[0] here.

Yes, it looks strange, but that's because the binding doesn't make much
sense. Why should I insert a delay before doing anything?
I can a delay here, it wouldn't make much difference as all users except
one specify zero delay here anyway. For the one exception I would bet
someone has inserted the first delay without a good reason, they are all
10000.

> 
> > +	gpio_direction_active(phy_reset, 0);
> 
> This always sets logical zero, because gpio_request above doesn't
> accept a flag telling it otherwise. You'll need of_get_named_gpio_flags
> here, at which point, you'll have basically open-coded gpiod_get(), so
> you could use that.

Right.

> 
> > +	udelay(delays[1]);
> 
> Linux rounds up to 1 msec granularity here. We should do likewise.

I don't see a good reason for that. The Linux driver used udelay()
initially, that was changed to msleep as the times were too long for
busy waiting. I have no clue why the author didn't use usleep_range
instead.

> 
> > +	gpio_set_active(phy_reset, 1);
> 
> Nitpick: true/false.

Ok.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list