All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Paul Cercueil <paul@crapouillou.net>
Cc: "David S. Miller" <davem@davemloft.net>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] net: davicom: dm9000: switch to using gpiod API
Date: Fri, 18 Nov 2022 07:58:21 -0800	[thread overview]
Message-ID: <Y3ernUQfdWMBtO9z@google.com> (raw)
In-Reply-To: <88VJLR.GYSEKGBPLGZC1@crapouillou.net>

Hi Paul,

On Fri, Nov 18, 2022 at 03:33:44PM +0000, Paul Cercueil wrote:
> Hi Dmitry,
> 
> Le mar. 6 sept. 2022 à 13:49:20 -0700, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> a écrit :
> > This patch switches the driver away from legacy gpio/of_gpio API to
> > gpiod API, and removes use of of_get_named_gpio_flags() which I want to
> > make private to gpiolib.
> > 
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > ---
> >  drivers/net/ethernet/davicom/dm9000.c | 26 ++++++++++++++------------
> >  1 file changed, 14 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/davicom/dm9000.c
> > b/drivers/net/ethernet/davicom/dm9000.c
> > index 77229e53b04e..c85a6ebd79fc 100644
> > --- a/drivers/net/ethernet/davicom/dm9000.c
> > +++ b/drivers/net/ethernet/davicom/dm9000.c
> > @@ -28,8 +28,7 @@
> >  #include <linux/irq.h>
> >  #include <linux/slab.h>
> >  #include <linux/regulator/consumer.h>
> > -#include <linux/gpio.h>
> > -#include <linux/of_gpio.h>
> > +#include <linux/gpio/consumer.h>
> > 
> >  #include <asm/delay.h>
> >  #include <asm/irq.h>
> > @@ -1421,8 +1420,7 @@ dm9000_probe(struct platform_device *pdev)
> >  	int iosize;
> >  	int i;
> >  	u32 id_val;
> > -	int reset_gpios;
> > -	enum of_gpio_flags flags;
> > +	struct gpio_desc *reset_gpio;
> >  	struct regulator *power;
> >  	bool inv_mac_addr = false;
> >  	u8 addr[ETH_ALEN];
> > @@ -1442,20 +1440,24 @@ dm9000_probe(struct platform_device *pdev)
> >  		dev_dbg(dev, "regulator enabled\n");
> >  	}
> > 
> > -	reset_gpios = of_get_named_gpio_flags(dev->of_node, "reset-gpios", 0,
> > -					      &flags);
> > -	if (gpio_is_valid(reset_gpios)) {
> > -		ret = devm_gpio_request_one(dev, reset_gpios, flags,
> > -					    "dm9000_reset");
> > +	reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> > +	ret = PTR_ERR_OR_ZERO(reset_gpio);
> > +	if (ret) {
> > +		dev_err(dev, "failed to request reset gpio: %d\n", ret);
> > +		goto out_regulator_disable;
> > +	}
> > +
> > +	if (reset_gpio) {
> > +		ret = gpiod_set_consumer_name(reset_gpio, "dm9000_reset");
> >  		if (ret) {
> > -			dev_err(dev, "failed to request reset gpio %d: %d\n",
> > -				reset_gpios, ret);
> > +			dev_err(dev, "failed to set reset gpio name: %d\n",
> > +				ret);
> >  			goto out_regulator_disable;
> >  		}
> > 
> >  		/* According to manual PWRST# Low Period Min 1ms */
> >  		msleep(2);
> > -		gpio_set_value(reset_gpios, 1);
> > +		gpiod_set_value_cansleep(reset_gpio, 0);
> 
> Why is that 1 magically turned into a 0?

Because gpiod uses logical states (think active/inactive), not absolute
ones. Here we are deasserting the reset line.

> 
> On my CI20 board I can't get the DM9000 chip to probe correctly with this
> patch (it fails to read the ID).
> If I revert this patch then everything works fine.

Sorry, it is my fault of course: I missed that board has incorrect
annotation for the reset line. I will send out the patch below
(formatted properly of course):

diff --git a/arch/mips/boot/dts/ingenic/ci20.dts b/arch/mips/boot/dts/ingenic/ci20.dts
index 37c46720c719..f38c39572a9e 100644
--- a/arch/mips/boot/dts/ingenic/ci20.dts
+++ b/arch/mips/boot/dts/ingenic/ci20.dts
@@ -438,7 +438,7 @@ dm9000@6 {
 		ingenic,nemc-tAW = <50>;
 		ingenic,nemc-tSTRV = <100>;
 
-		reset-gpios = <&gpf 12 GPIO_ACTIVE_HIGH>;
+		reset-gpios = <&gpf 12 GPIO_ACTIVE_LOW>;
 		vcc-supply = <&eth0_power>;
 
 		interrupt-parent = <&gpe>;


Thanks.

-- 
Dmitry

  reply	other threads:[~2022-11-18 15:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-06 20:49 [PATCH 1/3] net: davicom: dm9000: switch to using gpiod API Dmitry Torokhov
2022-09-06 20:49 ` [PATCH 2/3] net: ks8851: " Dmitry Torokhov
2022-09-07 21:46   ` Linus Walleij
2022-09-06 20:49 ` [PATCH 3/3] net: phy: spi_ks8895: " Dmitry Torokhov
2022-09-07 21:47   ` Linus Walleij
2022-09-07 21:45 ` [PATCH 1/3] net: davicom: dm9000: " Linus Walleij
2022-09-08 12:06   ` Andrew Lunn
2022-09-15  9:58     ` Paolo Abeni
2022-09-15 10:10 ` patchwork-bot+netdevbpf
2022-11-18 15:33 ` Paul Cercueil
2022-11-18 15:58   ` Dmitry Torokhov [this message]
2022-11-18 16:26     ` Paul Cercueil
2022-11-18 16:30       ` Dmitry Torokhov
2022-11-18 17:50     ` Andrew Lunn
2022-11-18 17:55       ` Dmitry Torokhov
2022-11-21 13:35         ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y3ernUQfdWMBtO9z@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=brgl@bgdev.pl \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=paul@crapouillou.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.