linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode
@ 2022-11-09 15:07 Andy Shevchenko
  2022-11-09 15:07 ` [PATCH v1 2/2] gpiolib: of: Drop redundant check in of_mm_gpiochip_remove() Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-11-09 15:07 UTC (permalink / raw)
  To: Bartosz Golaszewski, Dmitry Torokhov, linux-gpio, linux-kernel
  Cc: Linus Walleij, Andy Shevchenko

GPIO library is getting rid of of_node, fwnode should be utilized instead.
Prepare of_mm_gpiochip_add_data() for fwnode.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib-of.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 4be3c21aa718..feeb9e8e846d 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -919,14 +919,15 @@ int of_mm_gpiochip_add_data(struct device_node *np,
 			    struct of_mm_gpio_chip *mm_gc,
 			    void *data)
 {
+	struct fwnode_handle *fwnode = of_fwnode_handle(np);
 	int ret = -ENOMEM;
 	struct gpio_chip *gc = &mm_gc->gc;
 
-	gc->label = kasprintf(GFP_KERNEL, "%pOF", np);
+	gc->label = kasprintf(GFP_KERNEL, "%pfw", fwnode);
 	if (!gc->label)
 		goto err0;
 
-	mm_gc->regs = of_iomap(np, 0);
+	mm_gc->regs = fwnode_iomap(fwnode, 0);
 	if (!mm_gc->regs)
 		goto err1;
 
@@ -935,8 +936,8 @@ int of_mm_gpiochip_add_data(struct device_node *np,
 	if (mm_gc->save_regs)
 		mm_gc->save_regs(mm_gc);
 
-	of_node_put(mm_gc->gc.of_node);
-	mm_gc->gc.of_node = of_node_get(np);
+	fwnode_handle_put(mm_gc->gc.fwnode);
+	mm_gc->gc.fwnode = fwnode_handle_get(fwnode);
 
 	ret = gpiochip_add_data(gc, data);
 	if (ret)
@@ -944,12 +945,12 @@ int of_mm_gpiochip_add_data(struct device_node *np,
 
 	return 0;
 err2:
-	of_node_put(np);
+	fwnode_handle_put(fwnode);
 	iounmap(mm_gc->regs);
 err1:
 	kfree(gc->label);
 err0:
-	pr_err("%pOF: GPIO chip registration failed with status %d\n", np, ret);
+	pr_err("%pfw: GPIO chip registration failed with status %d\n", fwnode, ret);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(of_mm_gpiochip_add_data);
-- 
2.35.1


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

* [PATCH v1 2/2] gpiolib: of: Drop redundant check in of_mm_gpiochip_remove()
  2022-11-09 15:07 [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode Andy Shevchenko
@ 2022-11-09 15:07 ` Andy Shevchenko
  2022-11-09 21:13   ` Dmitry Torokhov
  2022-11-09 15:16 ` [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode Andy Shevchenko
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2022-11-09 15:07 UTC (permalink / raw)
  To: Bartosz Golaszewski, Dmitry Torokhov, linux-gpio, linux-kernel
  Cc: Linus Walleij, Andy Shevchenko

The callers never call the function with invalid pointer.
Moreover, compiler quite likely dropped that check anyway
because we use that pointer before the check.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib-of.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index feeb9e8e846d..83997434215e 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -963,9 +963,6 @@ void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc)
 {
 	struct gpio_chip *gc = &mm_gc->gc;
 
-	if (!mm_gc)
-		return;
-
 	gpiochip_remove(gc);
 	iounmap(mm_gc->regs);
 	kfree(gc->label);
-- 
2.35.1


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

* Re: [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode
  2022-11-09 15:07 [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode Andy Shevchenko
  2022-11-09 15:07 ` [PATCH v1 2/2] gpiolib: of: Drop redundant check in of_mm_gpiochip_remove() Andy Shevchenko
@ 2022-11-09 15:16 ` Andy Shevchenko
  2022-11-09 21:19 ` Dmitry Torokhov
  2022-11-10 10:11 ` Linus Walleij
  3 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-11-09 15:16 UTC (permalink / raw)
  To: Bartosz Golaszewski, Dmitry Torokhov, linux-gpio, linux-kernel
  Cc: Linus Walleij

On Wed, Nov 09, 2022 at 05:07:33PM +0200, Andy Shevchenko wrote:
> GPIO library is getting rid of of_node, fwnode should be utilized instead.
> Prepare of_mm_gpiochip_add_data() for fwnode.

I believe this is the last preparatory patch to get rid of of_node from
GPIO chip data structure.

After rc1 I will send that clean up and it would be nice to start next cycle
of_node free.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1 2/2] gpiolib: of: Drop redundant check in of_mm_gpiochip_remove()
  2022-11-09 15:07 ` [PATCH v1 2/2] gpiolib: of: Drop redundant check in of_mm_gpiochip_remove() Andy Shevchenko
@ 2022-11-09 21:13   ` Dmitry Torokhov
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry Torokhov @ 2022-11-09 21:13 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, Linus Walleij

On Wed, Nov 09, 2022 at 05:07:34PM +0200, Andy Shevchenko wrote:
> The callers never call the function with invalid pointer.
> Moreover, compiler quite likely dropped that check anyway
> because we use that pointer before the check.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

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

> ---
>  drivers/gpio/gpiolib-of.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index feeb9e8e846d..83997434215e 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -963,9 +963,6 @@ void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc)
>  {
>  	struct gpio_chip *gc = &mm_gc->gc;
>  
> -	if (!mm_gc)
> -		return;
> -
>  	gpiochip_remove(gc);
>  	iounmap(mm_gc->regs);
>  	kfree(gc->label);
> -- 
> 2.35.1
> 

-- 
Dmitry

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

* Re: [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode
  2022-11-09 15:07 [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode Andy Shevchenko
  2022-11-09 15:07 ` [PATCH v1 2/2] gpiolib: of: Drop redundant check in of_mm_gpiochip_remove() Andy Shevchenko
  2022-11-09 15:16 ` [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode Andy Shevchenko
@ 2022-11-09 21:19 ` Dmitry Torokhov
  2022-11-10 13:56   ` Andy Shevchenko
  2022-11-10 10:11 ` Linus Walleij
  3 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2022-11-09 21:19 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, Linus Walleij

On Wed, Nov 09, 2022 at 05:07:33PM +0200, Andy Shevchenko wrote:
> GPIO library is getting rid of of_node, fwnode should be utilized instead.
> Prepare of_mm_gpiochip_add_data() for fwnode.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpiolib-of.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index 4be3c21aa718..feeb9e8e846d 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -919,14 +919,15 @@ int of_mm_gpiochip_add_data(struct device_node *np,
>  			    struct of_mm_gpio_chip *mm_gc,
>  			    void *data)
>  {
> +	struct fwnode_handle *fwnode = of_fwnode_handle(np);
>  	int ret = -ENOMEM;
>  	struct gpio_chip *gc = &mm_gc->gc;
>  
> -	gc->label = kasprintf(GFP_KERNEL, "%pOF", np);
> +	gc->label = kasprintf(GFP_KERNEL, "%pfw", fwnode);
>  	if (!gc->label)
>  		goto err0;
>  
> -	mm_gc->regs = of_iomap(np, 0);
> +	mm_gc->regs = fwnode_iomap(fwnode, 0);
>  	if (!mm_gc->regs)
>  		goto err1;
>  
> @@ -935,8 +936,8 @@ int of_mm_gpiochip_add_data(struct device_node *np,
>  	if (mm_gc->save_regs)
>  		mm_gc->save_regs(mm_gc);
>  
> -	of_node_put(mm_gc->gc.of_node);
> -	mm_gc->gc.of_node = of_node_get(np);
> +	fwnode_handle_put(mm_gc->gc.fwnode);
> +	mm_gc->gc.fwnode = fwnode_handle_get(fwnode);

Can we reduce the patch to

	fwnode_handle_put(mm_gc->gc.fwnode);
	mm_gc->gc.fwnode = fwnode_handle_get(of_fwnode_handle(np));

?

I do not see a reason for converting the rest of invocations to fwnode
given that this is clearly an OF API.

Thanks.

-- 
Dmitry

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

* Re: [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode
  2022-11-09 15:07 [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode Andy Shevchenko
                   ` (2 preceding siblings ...)
  2022-11-09 21:19 ` Dmitry Torokhov
@ 2022-11-10 10:11 ` Linus Walleij
  3 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2022-11-10 10:11 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Bartosz Golaszewski, Dmitry Torokhov, linux-gpio, linux-kernel

On Wed, Nov 9, 2022 at 4:07 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> GPIO library is getting rid of of_node, fwnode should be utilized instead.
> Prepare of_mm_gpiochip_add_data() for fwnode.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

I actually want to get rid of of_mm_gpiochip_add_data() altogether and
just replace all of them with regular gpio_chip, as stated in the GPIO TODO.

Hmmm... who is using this...

$ git grep of_mm_gpiochip_add_data
arch/powerpc/platforms/4xx/gpio.c:              ret =
of_mm_gpiochip_add_data(np, mm_gc, ppc4xx_gc);
arch/powerpc/platforms/8xx/cpm1.c:      return
of_mm_gpiochip_add_data(np, mm_gc, cpm1_gc);
arch/powerpc/platforms/8xx/cpm1.c:      return
of_mm_gpiochip_add_data(np, mm_gc, cpm1_gc);
arch/powerpc/sysdev/cpm_common.c:       return
of_mm_gpiochip_add_data(np, mm_gc, cpm2_gc);
drivers/gpio/gpio-altera.c:     ret = of_mm_gpiochip_add_data(node,
&altera_gc->mmchip, altera_gc);
drivers/gpio/gpio-mm-lantiq.c:  return
of_mm_gpiochip_add_data(pdev->dev.of_node, &chip->mmchip, chip);
drivers/gpio/gpio-mpc5200.c:    ret =
of_mm_gpiochip_add_data(ofdev->dev.of_node, &chip->mmchip, chip);
drivers/gpio/gpio-mpc5200.c:    ret =
of_mm_gpiochip_add_data(ofdev->dev.of_node, &chip->mmchip, chip);
drivers/soc/fsl/qe/gpio.c:              ret =
of_mm_gpiochip_add_data(np, mm_gc, qe_gc);

Aha PPC and MIPS, OK so not the most familiar territory for either of us to go
and fix.

I guess it's fine if you refactor this for the time being, but let's make it
go away soon.

Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode
  2022-11-09 21:19 ` Dmitry Torokhov
@ 2022-11-10 13:56   ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-11-10 13:56 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, Linus Walleij

On Wed, Nov 09, 2022 at 01:19:30PM -0800, Dmitry Torokhov wrote:
> On Wed, Nov 09, 2022 at 05:07:33PM +0200, Andy Shevchenko wrote:

...

> > -	of_node_put(mm_gc->gc.of_node);
> > -	mm_gc->gc.of_node = of_node_get(np);
> > +	fwnode_handle_put(mm_gc->gc.fwnode);
> > +	mm_gc->gc.fwnode = fwnode_handle_get(fwnode);
> 
> Can we reduce the patch to
> 
> 	fwnode_handle_put(mm_gc->gc.fwnode);
> 	mm_gc->gc.fwnode = fwnode_handle_get(of_fwnode_handle(np));
> 
> ?

Sure. As Linus pointed out, it's anyway temporary.

> I do not see a reason for converting the rest of invocations to fwnode
> given that this is clearly an OF API.

...which should go away.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2022-11-10 13:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-09 15:07 [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode Andy Shevchenko
2022-11-09 15:07 ` [PATCH v1 2/2] gpiolib: of: Drop redundant check in of_mm_gpiochip_remove() Andy Shevchenko
2022-11-09 21:13   ` Dmitry Torokhov
2022-11-09 15:16 ` [PATCH v1 1/2] gpiolib: of: Prepare of_mm_gpiochip_add_data() for fwnode Andy Shevchenko
2022-11-09 21:19 ` Dmitry Torokhov
2022-11-10 13:56   ` Andy Shevchenko
2022-11-10 10:11 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).