All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC/PATCH] MIPS: pci: lantiq: switch to using gpiod API
@ 2022-09-26  5:48 Dmitry Torokhov
  2022-09-27  4:59 ` [RFC/PATCH v2] " Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2022-09-26  5:48 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: Linus Walleij, linux-mips, linux-kernel

This patch switches the driver from legacy gpio API to the newer
gpiod API.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

Note that the original version was using "gpio-reset" to look up gpio,
while this one will be using "reset-gpios" and "reset-gpio". However I
do not see any users of this driver in mainline kernel that are using
reset gpio functionality, so maybe it is OK?

If compatibility with existing DTSes is absolutely necessary I can make
a patch that will add needed quirk to drivers/gpio/gpiolib-of.c.

Please let me know.

 arch/mips/pci/pci-lantiq.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/arch/mips/pci/pci-lantiq.c b/arch/mips/pci/pci-lantiq.c
index 1ca42f482130..377b4a2577e1 100644
--- a/arch/mips/pci/pci-lantiq.c
+++ b/arch/mips/pci/pci-lantiq.c
@@ -9,11 +9,11 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/mm.h>
 #include <linux/vmalloc.h>
 #include <linux/clk.h>
 #include <linux/of_platform.h>
-#include <linux/of_gpio.h>
 #include <linux/of_irq.h>
 #include <linux/of_pci.h>
 
@@ -62,7 +62,7 @@
 __iomem void *ltq_pci_mapped_cfg;
 static __iomem void *ltq_pci_membase;
 
-static int reset_gpio;
+static gpio_desc *reset_gpio;
 static struct clk *clk_pci, *clk_external;
 static struct resource pci_io_resource;
 static struct resource pci_mem_resource;
@@ -123,17 +123,14 @@ static int ltq_pci_startup(struct platform_device *pdev)
 		clk_disable(clk_external);
 
 	/* setup reset gpio used by pci */
-	reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
-	if (gpio_is_valid(reset_gpio)) {
-		int ret = devm_gpio_request(&pdev->dev,
-						reset_gpio, "pci-reset");
-		if (ret) {
-			dev_err(&pdev->dev,
-				"failed to request gpio %d\n", reset_gpio);
-			return ret;
-		}
-		gpio_direction_output(reset_gpio, 1);
+	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
+					     GPIOD_OUT_LOW);
+	ret = PTR_ERR_OR_ZERO(reset_gpio);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to request gpio: %d\n", ret);
+		return ret;
 	}
+	gpiod_set_consumer_name(reset_gpio, "pci_reset");
 
 	/* enable auto-switching between PCI and EBU */
 	ltq_pci_w32(0xa, PCI_CR_CLK_CTRL);
@@ -195,11 +192,11 @@ static int ltq_pci_startup(struct platform_device *pdev)
 	ltq_ebu_w32(ltq_ebu_r32(LTQ_EBU_PCC_IEN) | 0x10, LTQ_EBU_PCC_IEN);
 
 	/* toggle reset pin */
-	if (gpio_is_valid(reset_gpio)) {
-		__gpio_set_value(reset_gpio, 0);
+	if (reset_gpio) {
+		gpiod_set_value_cansleep(reset_gpio, 1);
 		wmb();
 		mdelay(1);
-		__gpio_set_value(reset_gpio, 1);
+		gpiod_set_value_cansleep(reset_gpio, 0);
 	}
 	return 0;
 }
-- 
2.37.3.998.g577e59143f-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [RFC/PATCH v2] MIPS: pci: lantiq: switch to using gpiod API
  2022-09-26  5:48 [RFC/PATCH] MIPS: pci: lantiq: switch to using gpiod API Dmitry Torokhov
@ 2022-09-27  4:59 ` Dmitry Torokhov
  2022-09-30 15:15   ` Thomas Bogendoerfer
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2022-09-27  4:59 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: Linus Walleij, linux-mips, linux-kernel

This patch switches the driver from legacy gpio API to the newer
gpiod API.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
v2 - actually compiles.

 arch/mips/pci/pci-lantiq.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/arch/mips/pci/pci-lantiq.c b/arch/mips/pci/pci-lantiq.c
index 1ca42f482130..377b4a2577e1 100644
--- a/arch/mips/pci/pci-lantiq.c
+++ b/arch/mips/pci/pci-lantiq.c
@@ -9,11 +9,11 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/mm.h>
 #include <linux/vmalloc.h>
 #include <linux/clk.h>
 #include <linux/of_platform.h>
-#include <linux/of_gpio.h>
 #include <linux/of_irq.h>
 #include <linux/of_pci.h>
 
@@ -62,7 +62,7 @@
 __iomem void *ltq_pci_mapped_cfg;
 static __iomem void *ltq_pci_membase;
 
-static int reset_gpio;
+static gpio_desc *reset_gpio;
 static struct clk *clk_pci, *clk_external;
 static struct resource pci_io_resource;
 static struct resource pci_mem_resource;
@@ -123,17 +123,14 @@ static int ltq_pci_startup(struct platform_device *pdev)
 		clk_disable(clk_external);
 
 	/* setup reset gpio used by pci */
-	reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
-	if (gpio_is_valid(reset_gpio)) {
-		int ret = devm_gpio_request(&pdev->dev,
-						reset_gpio, "pci-reset");
-		if (ret) {
-			dev_err(&pdev->dev,
-				"failed to request gpio %d\n", reset_gpio);
-			return ret;
-		}
-		gpio_direction_output(reset_gpio, 1);
+	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
+					     GPIOD_OUT_LOW);
+	ret = PTR_ERR_OR_ZERO(reset_gpio);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to request gpio: %d\n", ret);
+		return ret;
 	}
+	gpiod_set_consumer_name(reset_gpio, "pci_reset");
 
 	/* enable auto-switching between PCI and EBU */
 	ltq_pci_w32(0xa, PCI_CR_CLK_CTRL);
@@ -195,11 +192,11 @@ static int ltq_pci_startup(struct platform_device *pdev)
 	ltq_ebu_w32(ltq_ebu_r32(LTQ_EBU_PCC_IEN) | 0x10, LTQ_EBU_PCC_IEN);
 
 	/* toggle reset pin */
-	if (gpio_is_valid(reset_gpio)) {
-		__gpio_set_value(reset_gpio, 0);
+	if (reset_gpio) {
+		gpiod_set_value_cansleep(reset_gpio, 1);
 		wmb();
 		mdelay(1);
-		__gpio_set_value(reset_gpio, 1);
+		gpiod_set_value_cansleep(reset_gpio, 0);
 	}
 	return 0;
 }
-- 
2.38.0.rc1.362.ged0d419d3c-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC/PATCH v2] MIPS: pci: lantiq: switch to using gpiod API
  2022-09-27  4:59 ` [RFC/PATCH v2] " Dmitry Torokhov
@ 2022-09-30 15:15   ` Thomas Bogendoerfer
  2022-09-30 15:52     ` Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Bogendoerfer @ 2022-09-30 15:15 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Linus Walleij, linux-mips, linux-kernel

On Mon, Sep 26, 2022 at 09:59:00PM -0700, Dmitry Torokhov wrote:
> This patch switches the driver from legacy gpio API to the newer
> gpiod API.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> v2 - actually compiles.

I have some doubts...

>  arch/mips/pci/pci-lantiq.c | 27 ++++++++++++---------------
>  1 file changed, 12 insertions(+), 15 deletions(-)
> 
> diff --git a/arch/mips/pci/pci-lantiq.c b/arch/mips/pci/pci-lantiq.c
> index 1ca42f482130..377b4a2577e1 100644
> --- a/arch/mips/pci/pci-lantiq.c
> +++ b/arch/mips/pci/pci-lantiq.c
> @@ -9,11 +9,11 @@
>  #include <linux/kernel.h>
>  #include <linux/init.h>
>  #include <linux/delay.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/mm.h>
>  #include <linux/vmalloc.h>
>  #include <linux/clk.h>
>  #include <linux/of_platform.h>
> -#include <linux/of_gpio.h>
>  #include <linux/of_irq.h>
>  #include <linux/of_pci.h>
>  
> @@ -62,7 +62,7 @@
>  __iomem void *ltq_pci_mapped_cfg;
>  static __iomem void *ltq_pci_membase;
>  
> -static int reset_gpio;
> +static gpio_desc *reset_gpio;

/local/tbogendoerfer/korg/linux/arch/mips/pci/pci-lantiq.c:65:8: error: unknown type name ‘gpio_desc’
 static gpio_desc *reset_gpio;


>  static struct clk *clk_pci, *clk_external;
>  static struct resource pci_io_resource;
>  static struct resource pci_mem_resource;
> @@ -123,17 +123,14 @@ static int ltq_pci_startup(struct platform_device *pdev)
>  		clk_disable(clk_external);
>  
>  	/* setup reset gpio used by pci */
> -	reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
> -	if (gpio_is_valid(reset_gpio)) {
> -		int ret = devm_gpio_request(&pdev->dev,
> -						reset_gpio, "pci-reset");
> -		if (ret) {
> -			dev_err(&pdev->dev,
> -				"failed to request gpio %d\n", reset_gpio);
> -			return ret;
> -		}
> -		gpio_direction_output(reset_gpio, 1);
> +	reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
> +					     GPIOD_OUT_LOW);
> +	ret = PTR_ERR_OR_ZERO(reset_gpio);

/local/tbogendoerfer/korg/linux/arch/mips/pci/pci-lantiq.c:128:2: error: ‘ret’ undeclared (first use in this function)
  ret = PTR_ERR_OR_ZERO(reset_gpio);

Thomas.


-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC/PATCH v2] MIPS: pci: lantiq: switch to using gpiod API
  2022-09-30 15:15   ` Thomas Bogendoerfer
@ 2022-09-30 15:52     ` Dmitry Torokhov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2022-09-30 15:52 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: Linus Walleij, linux-mips, linux-kernel

On Fri, Sep 30, 2022 at 05:15:25PM +0200, Thomas Bogendoerfer wrote:
> On Mon, Sep 26, 2022 at 09:59:00PM -0700, Dmitry Torokhov wrote:
> > This patch switches the driver from legacy gpio API to the newer
> > gpiod API.
> > 
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > ---
> > v2 - actually compiles.
> 
> I have some doubts...

You are right, I am very sorry as I am not sure how that happened. I did
indeed have a version with the exact errors you pointed out, and I fixed
them. I am not sure how I managed to send the wrong one to you...

I will send out the right one as v3, in the meantime here is what I see
on my end with it:

dtor@dtor-ws:~/kernel/cross-tmp ((b4938080955f...))$ date
Fri Sep 30 08:46:26 AM PDT 2022
dtor@dtor-ws:~/kernel/cross-tmp ((b4938080955f...))$ git log -1 --abbrev --oneline HEAD
b4938080955f (HEAD) MIPS: pci: lantiq: switch to using gpiod API
dtor@dtor-ws:~/kernel/cross-tmp ((b4938080955f...))$ git show HEAD | git patch-id
2f4c9e4f56e674980122ce426c9ca9281eb393a1 b4938080955f015ffd1a8f778ce57b2a8e50c7ba
dtor@dtor-ws:~/kernel/cross-tmp ((b4938080955f...))$ COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross -j1 O=./build_dir_mips ARCH=mips SHELL=/bin/bash arch/mips/pci/pci-lantiq.o
Compiler will be installed in /usr/local/google/home/dtor/0day
make --keep-going CONFIG_OF_ALL_DTBS=y CONFIG_DTC=y CROSS_COMPILE=/usr/local/google/home/dtor/0day/gcc-12.1.0-nolibc/mips-linux/bin/mips-linux- -j1 O=./build_dir_mips ARCH=mips SHELL=/bin/bash arch/mips/pci/pci-lantiq.o
make[1]: Entering directory '/usr/local/google/home/dtor/kernel/cross-tmp/build_dir_mips'
  GEN     Makefile
  CALL    ../scripts/checksyscalls.sh
  CC      arch/mips/pci/pci-lantiq.o
  CC      arch/mips/pci/pci-lantiq.o
make[1]: Leaving directory '/usr/local/google/home/dtor/kernel/cross-tmp/build_dir_mips'

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-30 15:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26  5:48 [RFC/PATCH] MIPS: pci: lantiq: switch to using gpiod API Dmitry Torokhov
2022-09-27  4:59 ` [RFC/PATCH v2] " Dmitry Torokhov
2022-09-30 15:15   ` Thomas Bogendoerfer
2022-09-30 15:52     ` Dmitry Torokhov

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.