All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] gpio: of: fix GPIO drivers with multiple gpio_chip for a single node
@ 2016-10-24  7:43 Masahiro Yamada
  2016-10-24 16:58 ` Sylvain Lemieux
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Masahiro Yamada @ 2016-10-24  7:43 UTC (permalink / raw)
  To: linux-gpio
  Cc: Linus Walleij, Vladimir Zapolskiy, Alexandre Courbot,
	Masahiro Yamada, linux-kernel

Sylvain Lemieux reports the LPC32xx GPIO driver is broken since
commit 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and
struct gg_data").  Probably, gpio-etraxfs.c and gpio-davinci.c are
broken as well.

Those drivers register multiple gpio_chip that are associated to a
single OF node, and their own .of_xlate() checks if the passed
gpio_chip is valid.

Now, the problem is of_find_gpiochip_by_node() returns the first
gpio_chip found to match the given node.  So, .of_xlate() fails,
except for the first GPIO bank.

Reverting the commit could be a solution, but I do not want to go
back to the mess of struct gg_data.  Another solution here is to
take the match by a node pointer and the success of .of_xlate().
It is a bit clumsy to call .of_xlate twice; for gpio_chip matching
and for really getting the gpio_desc index.  Perhaps, the long-term
goal might be to convert drivers to single chip registration, but
this commit will solve the problem until then.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reported-by: <slemieux.tyco@gmail.com>
---

 drivers/gpio/gpiolib-of.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index ecad3f0..f996596 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -26,14 +26,18 @@
 
 #include "gpiolib.h"
 
-static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)
+static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
 {
-	return chip->gpiodev->dev.of_node == data;
+	struct of_phandle_args *gpiospec = data;
+
+	return chip->gpiodev->dev.of_node == gpiospec->np &&
+					!chip->of_xlate(chip, gpiospec, NULL);
 }
 
-static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np)
+static struct gpio_chip *of_find_gpiochip_by_xlate(
+					struct of_phandle_args *gpiospec)
 {
-	return gpiochip_find(np, of_gpiochip_match_node);
+	return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate);
 }
 
 static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
@@ -79,7 +83,7 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
 		return ERR_PTR(ret);
 	}
 
-	chip = of_find_gpiochip_by_node(gpiospec.np);
+	chip = of_find_gpiochip_by_xlate(&gpiospec);
 	if (!chip) {
 		desc = ERR_PTR(-EPROBE_DEFER);
 		goto out;
-- 
1.9.1

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

* Re: [RFC PATCH] gpio: of: fix GPIO drivers with multiple gpio_chip for a single node
  2016-10-24  7:43 [RFC PATCH] gpio: of: fix GPIO drivers with multiple gpio_chip for a single node Masahiro Yamada
@ 2016-10-24 16:58 ` Sylvain Lemieux
  2016-10-25  1:46   ` Masahiro Yamada
  2016-10-24 21:31 ` [RFC] " David Lechner
  2016-10-24 22:07 ` [RFC PATCH] " Vladimir Zapolskiy
  2 siblings, 1 reply; 5+ messages in thread
From: Sylvain Lemieux @ 2016-10-24 16:58 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-gpio, Linus Walleij, Vladimir Zapolskiy, Alexandre Courbot,
	linux-kernel, Axel Haslam

Hi Masahiro,

On Mon, 2016-10-24 at 16:43 +0900, Masahiro Yamada wrote:
> Sylvain Lemieux reports the LPC32xx GPIO driver is broken since
> commit 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and
> struct gg_data").  Probably, gpio-etraxfs.c and gpio-davinci.c are
> broken as well.
> 
> Those drivers register multiple gpio_chip that are associated to a
> single OF node, and their own .of_xlate() checks if the passed
> gpio_chip is valid.
> 
> Now, the problem is of_find_gpiochip_by_node() returns the first
> gpio_chip found to match the given node.  So, .of_xlate() fails,
> except for the first GPIO bank.
> 
> Reverting the commit could be a solution, but I do not want to go
> back to the mess of struct gg_data.  Another solution here is to
> take the match by a node pointer and the success of .of_xlate().
> It is a bit clumsy to call .of_xlate twice; for gpio_chip matching
> and for really getting the gpio_desc index.  Perhaps, the long-term
> goal might be to convert drivers to single chip registration, but
> this commit will solve the problem until then.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Reported-by: <slemieux.tyco@gmail.com>
> ---
> 
>  drivers/gpio/gpiolib-of.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index ecad3f0..f996596 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -26,14 +26,18 @@
>  
>  #include "gpiolib.h"
>  
> -static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)
> +static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
>  {
> -	return chip->gpiodev->dev.of_node == data;
> +	struct of_phandle_args *gpiospec = data;
> +
> +	return chip->gpiodev->dev.of_node == gpiospec->np &&
> +					!chip->of_xlate(chip, gpiospec, NULL);

for the patch to work, the second compare of the return statement
should be updated:
	return chip->gpiodev->dev.of_node == gpiospec->np && 
	       chip->of_xlate(chip, gpiospec, NULL) >= 0;

the patch, with this return statement, is fixing the issue;
can you submit an updated version of your patch?

>  }
>  
> -static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np)
> +static struct gpio_chip *of_find_gpiochip_by_xlate(
> +					struct of_phandle_args *gpiospec)
>  {
> -	return gpiochip_find(np, of_gpiochip_match_node);
> +	return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate);
>  }
>  
>  static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
> @@ -79,7 +83,7 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
>  		return ERR_PTR(ret);
>  	}
>  
> -	chip = of_find_gpiochip_by_node(gpiospec.np);
> +	chip = of_find_gpiochip_by_xlate(&gpiospec);
>  	if (!chip) {
>  		desc = ERR_PTR(-EPROBE_DEFER);
>  		goto out;

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

* Re: [RFC] gpio: of: fix GPIO drivers with multiple gpio_chip for a single node
  2016-10-24  7:43 [RFC PATCH] gpio: of: fix GPIO drivers with multiple gpio_chip for a single node Masahiro Yamada
  2016-10-24 16:58 ` Sylvain Lemieux
@ 2016-10-24 21:31 ` David Lechner
  2016-10-24 22:07 ` [RFC PATCH] " Vladimir Zapolskiy
  2 siblings, 0 replies; 5+ messages in thread
From: David Lechner @ 2016-10-24 21:31 UTC (permalink / raw)
  To: Masahiro Yamada, linux-gpio
  Cc: Linus Walleij, Vladimir Zapolskiy, Alexandre Courbot,
	linux-kernel, Axel Haslam, Sekhar Nori, Kevin Hilman

On 10/24/2016 02:43 AM, Masahiro Yamada wrote:
> Sylvain Lemieux reports the LPC32xx GPIO driver is broken since
> commit 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and
> struct gg_data").  Probably, gpio-etraxfs.c and gpio-davinci.c are
> broken as well.
>
> Those drivers register multiple gpio_chip that are associated to a
> single OF node, and their own .of_xlate() checks if the passed
> gpio_chip is valid.
>
> Now, the problem is of_find_gpiochip_by_node() returns the first
> gpio_chip found to match the given node.  So, .of_xlate() fails,
> except for the first GPIO bank.
>
> Reverting the commit could be a solution, but I do not want to go
> back to the mess of struct gg_data.  Another solution here is to
> take the match by a node pointer and the success of .of_xlate().
> It is a bit clumsy to call .of_xlate twice; for gpio_chip matching
> and for really getting the gpio_desc index.  Perhaps, the long-term
> goal might be to convert drivers to single chip registration, but
> this commit will solve the problem until then.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Reported-by: <slemieux.tyco@gmail.com>

This fixes gpio-davinci. Tested on LEGO MINDSTORMS EV3 (I included the 
chip->of_xlate(chip, gpiospec, NULL) >= 0 suggestion from  Sylvain 
Lemieux when I tested).

Tested-By: David Lechner <david@lechnology.com>

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

* Re: [RFC PATCH] gpio: of: fix GPIO drivers with multiple gpio_chip for a single node
  2016-10-24  7:43 [RFC PATCH] gpio: of: fix GPIO drivers with multiple gpio_chip for a single node Masahiro Yamada
  2016-10-24 16:58 ` Sylvain Lemieux
  2016-10-24 21:31 ` [RFC] " David Lechner
@ 2016-10-24 22:07 ` Vladimir Zapolskiy
  2 siblings, 0 replies; 5+ messages in thread
From: Vladimir Zapolskiy @ 2016-10-24 22:07 UTC (permalink / raw)
  To: Masahiro Yamada, linux-gpio
  Cc: Linus Walleij, Alexandre Courbot, linux-kernel

Hi Masahiro,

On 24.10.2016 10:43, Masahiro Yamada wrote:
> Sylvain Lemieux reports the LPC32xx GPIO driver is broken since
> commit 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and
> struct gg_data").  Probably, gpio-etraxfs.c and gpio-davinci.c are
> broken as well.
> 
> Those drivers register multiple gpio_chip that are associated to a
> single OF node, and their own .of_xlate() checks if the passed
> gpio_chip is valid.
> 
> Now, the problem is of_find_gpiochip_by_node() returns the first
> gpio_chip found to match the given node.  So, .of_xlate() fails,
> except for the first GPIO bank.
> 
> Reverting the commit could be a solution, but I do not want to go
> back to the mess of struct gg_data.  Another solution here is to
> take the match by a node pointer and the success of .of_xlate().
> It is a bit clumsy to call .of_xlate twice; for gpio_chip matching
> and for really getting the gpio_desc index.  Perhaps, the long-term
> goal might be to convert drivers to single chip registration, but
> this commit will solve the problem until then.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Reported-by: <slemieux.tyco@gmail.com>

Fixes: 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and struct gg_data")

> ---
> 
>  drivers/gpio/gpiolib-of.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index ecad3f0..f996596 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -26,14 +26,18 @@
>  
>  #include "gpiolib.h"
>  
> -static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)
> +static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
>  {
> -	return chip->gpiodev->dev.of_node == data;
> +	struct of_phandle_args *gpiospec = data;
> +
> +	return chip->gpiodev->dev.of_node == gpiospec->np &&
> +					!chip->of_xlate(chip, gpiospec, NULL);

That's an awful but hopefully safe hack to support 3-4 broken GPIO
drivers, however it should work with a correction given by Sylvain.

Here I would recommend to expand the statement, so it will be easier
to simplify it in future:

  if (chip->gpiodev->dev.of_node != gpiospec->np)
          return 0;

  if (chip->of_xlate(chip, gpiospec, NULL) < 0)
          return 0;

  return 1;

As far as I can say it should work correctly with of_gpio_simple_xlate(),
brcmstb_gpio_of_xlate(), lpc32xx_of_xlate(), davinci_gpio_of_xlate(),
pxa_gpio_of_xlate() and etraxfs_gpio_of_xlate() flavours.

>  }
>  
> -static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np)
> +static struct gpio_chip *of_find_gpiochip_by_xlate(
> +					struct of_phandle_args *gpiospec)
>  {
> -	return gpiochip_find(np, of_gpiochip_match_node);
> +	return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate);
>  }
>  
>  static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
> @@ -79,7 +83,7 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
>  		return ERR_PTR(ret);
>  	}
>  
> -	chip = of_find_gpiochip_by_node(gpiospec.np);
> +	chip = of_find_gpiochip_by_xlate(&gpiospec);
>  	if (!chip) {
>  		desc = ERR_PTR(-EPROBE_DEFER);
>  		goto out;
> 

--
With best wishes,
Vladimir

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

* Re: [RFC PATCH] gpio: of: fix GPIO drivers with multiple gpio_chip for a single node
  2016-10-24 16:58 ` Sylvain Lemieux
@ 2016-10-25  1:46   ` Masahiro Yamada
  0 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2016-10-25  1:46 UTC (permalink / raw)
  To: Sylvain Lemieux
  Cc: linux-gpio, Linus Walleij, Vladimir Zapolskiy, Alexandre Courbot,
	Linux Kernel Mailing List, Axel Haslam

2016-10-25 1:58 GMT+09:00 Sylvain Lemieux <slemieux.tyco@gmail.com>:
> Hi Masahiro,
>
> On Mon, 2016-10-24 at 16:43 +0900, Masahiro Yamada wrote:
>> Sylvain Lemieux reports the LPC32xx GPIO driver is broken since
>> commit 762c2e46c059 ("gpio: of: remove of_gpiochip_and_xlate() and
>> struct gg_data").  Probably, gpio-etraxfs.c and gpio-davinci.c are
>> broken as well.
>>
>> Those drivers register multiple gpio_chip that are associated to a
>> single OF node, and their own .of_xlate() checks if the passed
>> gpio_chip is valid.
>>
>> Now, the problem is of_find_gpiochip_by_node() returns the first
>> gpio_chip found to match the given node.  So, .of_xlate() fails,
>> except for the first GPIO bank.
>>
>> Reverting the commit could be a solution, but I do not want to go
>> back to the mess of struct gg_data.  Another solution here is to
>> take the match by a node pointer and the success of .of_xlate().
>> It is a bit clumsy to call .of_xlate twice; for gpio_chip matching
>> and for really getting the gpio_desc index.  Perhaps, the long-term
>> goal might be to convert drivers to single chip registration, but
>> this commit will solve the problem until then.
>>
>> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>> Reported-by: <slemieux.tyco@gmail.com>
>> ---
>>
>>  drivers/gpio/gpiolib-of.c | 14 +++++++++-----
>>  1 file changed, 9 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
>> index ecad3f0..f996596 100644
>> --- a/drivers/gpio/gpiolib-of.c
>> +++ b/drivers/gpio/gpiolib-of.c
>> @@ -26,14 +26,18 @@
>>
>>  #include "gpiolib.h"
>>
>> -static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)
>> +static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
>>  {
>> -     return chip->gpiodev->dev.of_node == data;
>> +     struct of_phandle_args *gpiospec = data;
>> +
>> +     return chip->gpiodev->dev.of_node == gpiospec->np &&
>> +                                     !chip->of_xlate(chip, gpiospec, NULL);
>
> for the patch to work, the second compare of the return statement
> should be updated:
>         return chip->gpiodev->dev.of_node == gpiospec->np &&
>                chip->of_xlate(chip, gpiospec, NULL) >= 0;
>
> the patch, with this return statement, is fixing the issue;
> can you submit an updated version of your patch?
>

Thanks for correction.
I've sent v2.


-- 
Best Regards
Masahiro Yamada

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

end of thread, other threads:[~2016-10-25  1:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-24  7:43 [RFC PATCH] gpio: of: fix GPIO drivers with multiple gpio_chip for a single node Masahiro Yamada
2016-10-24 16:58 ` Sylvain Lemieux
2016-10-25  1:46   ` Masahiro Yamada
2016-10-24 21:31 ` [RFC] " David Lechner
2016-10-24 22:07 ` [RFC PATCH] " Vladimir Zapolskiy

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.