linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] gpio: Fix ngpio in gpio-xilinx driver
@ 2014-09-18  9:03 Gernot Vormayr
  2014-09-23 15:38 ` Linus Walleij
  2014-09-23 22:58 ` [PATCH v2 " Gernot Vormayr
  0 siblings, 2 replies; 5+ messages in thread
From: Gernot Vormayr @ 2014-09-18  9:03 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Michal Simek, linux-gpio
  Cc: linux-arm-kernel, linux-kernel, Gernot Vormayr

If one adds 'gpio-controller;' to the chip in the devicetree, then
initialization fails with 'gpiochip_find_base: cannot find free range',
because ngpio is 0. This patch fixes the bug.

Tested on ml507 board.

Signed-off-by: Gernot Vormayr <gvormayr@gmail.com>
---
 drivers/gpio/gpio-xilinx.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index 1248186..4606ad2 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -197,6 +197,7 @@ static int xgpio_of_probe(struct device_node *np)
 	struct xgpio_instance *chip;
 	int status = 0;
 	const u32 *tree_info;
+	u32 ngpio;
 
 	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
 	if (!chip)
@@ -215,8 +216,9 @@ static int xgpio_of_probe(struct device_node *np)
 	chip->mmchip.gc.ngpio = 32;
 
 	/* Check device node and parent device node for device width */
-	of_property_read_u32(np, "xlnx,gpio-width",
-			      (u32 *)&chip->mmchip.gc.ngpio);
+	status = of_property_read_u32(np, "xlnx,gpio-width", &ngpio);
+	if (status == 0)
+		chip->mmchip.gc.ngpio = (u16)ngpio;
 
 	spin_lock_init(&chip->gpio_lock);
 
@@ -262,8 +264,9 @@ static int xgpio_of_probe(struct device_node *np)
 		chip->mmchip.gc.ngpio = 32;
 
 		/* Check device node and parent device node for device width */
-		of_property_read_u32(np, "xlnx,gpio2-width",
-				     (u32 *)&chip->mmchip.gc.ngpio);
+		status = of_property_read_u32(np, "xlnx,gpio2-width", &ngpio);
+		if (status == 0)
+			chip->mmchip.gc.ngpio = (u16)ngpio;
 
 		spin_lock_init(&chip->gpio_lock);
 
-- 
2.1.0


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

* Re: [PATCH 1/1] gpio: Fix ngpio in gpio-xilinx driver
  2014-09-18  9:03 [PATCH 1/1] gpio: Fix ngpio in gpio-xilinx driver Gernot Vormayr
@ 2014-09-23 15:38 ` Linus Walleij
  2014-09-23 22:48   ` Gernot Vormayr
  2014-09-23 22:58 ` [PATCH v2 " Gernot Vormayr
  1 sibling, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2014-09-23 15:38 UTC (permalink / raw)
  To: Gernot Vormayr
  Cc: Alexandre Courbot, Michal Simek, linux-gpio, linux-arm-kernel,
	linux-kernel

On Thu, Sep 18, 2014 at 11:03 AM, Gernot Vormayr <gvormayr@gmail.com> wrote:

> If one adds 'gpio-controller;' to the chip in the devicetree, then
> initialization fails with 'gpiochip_find_base: cannot find free range',
> because ngpio is 0. This patch fixes the bug.
>
> Tested on ml507 board.
>
> Signed-off-by: Gernot Vormayr <gvormayr@gmail.com>
> ---
>  drivers/gpio/gpio-xilinx.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
> index 1248186..4606ad2 100644
> --- a/drivers/gpio/gpio-xilinx.c
> +++ b/drivers/gpio/gpio-xilinx.c
> @@ -197,6 +197,7 @@ static int xgpio_of_probe(struct device_node *np)
>         struct xgpio_instance *chip;
>         int status = 0;
>         const u32 *tree_info;
> +       u32 ngpio;
>
>         chip = kzalloc(sizeof(*chip), GFP_KERNEL);
>         if (!chip)
> @@ -215,8 +216,9 @@ static int xgpio_of_probe(struct device_node *np)
>         chip->mmchip.gc.ngpio = 32;

Delete that line ^

>
>         /* Check device node and parent device node for device width */
> -       of_property_read_u32(np, "xlnx,gpio-width",
> -                             (u32 *)&chip->mmchip.gc.ngpio);
> +       status = of_property_read_u32(np, "xlnx,gpio-width", &ngpio);
> +       if (status == 0)
> +               chip->mmchip.gc.ngpio = (u16)ngpio;

Rewrite like this:

if (of_property_read_u32(np, "xlnx,gpio-width", &ngpio))
    ngpio = 32;
chip->mmchip.gc.ngpio = (u16)ngpio;

>
>         spin_lock_init(&chip->gpio_lock);
>
> @@ -262,8 +264,9 @@ static int xgpio_of_probe(struct device_node *np)
>                 chip->mmchip.gc.ngpio = 32;
>
>                 /* Check device node and parent device node for device width */
> -               of_property_read_u32(np, "xlnx,gpio2-width",
> -                                    (u32 *)&chip->mmchip.gc.ngpio);
> +               status = of_property_read_u32(np, "xlnx,gpio2-width", &ngpio);
> +               if (status == 0)
> +                       chip->mmchip.gc.ngpio = (u16)ngpio;

Same comment.

The fact that the same code appears in two places tells us something
is not quite right. Can you look into consolidating this (in a separate
patch)?

Yours,
Linus Walleij

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

* Re: [PATCH 1/1] gpio: Fix ngpio in gpio-xilinx driver
  2014-09-23 15:38 ` Linus Walleij
@ 2014-09-23 22:48   ` Gernot Vormayr
  0 siblings, 0 replies; 5+ messages in thread
From: Gernot Vormayr @ 2014-09-23 22:48 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Michal Simek, linux-gpio, linux-arm-kernel,
	linux-kernel

On Tue, Sep 23, 2014 at 5:38 PM, Linus Walleij <linus.walleij@linaro.org> wrote:
>
> The fact that the same code appears in two places tells us something
> is not quite right. Can you look into consolidating this (in a separate
> patch)?


Well, I already thought about that, but since the second time is for the
second part of a dual gpio, which has different device tree property names,
the only way of consolidating that I can think of right now would be to
create a function that takes the property names. If you think that's ok,
I can try to come up with something.

Cheers,
Gernot Vormayr

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

* [PATCH v2 1/1] gpio: Fix ngpio in gpio-xilinx driver
  2014-09-18  9:03 [PATCH 1/1] gpio: Fix ngpio in gpio-xilinx driver Gernot Vormayr
  2014-09-23 15:38 ` Linus Walleij
@ 2014-09-23 22:58 ` Gernot Vormayr
  2014-09-24 11:38   ` Linus Walleij
  1 sibling, 1 reply; 5+ messages in thread
From: Gernot Vormayr @ 2014-09-23 22:58 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Michal Simek, linux-gpio
  Cc: linux-arm-kernel, linux-kernel, Gernot Vormayr

If one adds gpio-controller; to the chip in the devicetree, then
initialization fails with 'gpiochip_find_base: cannot find free range',
because ngpio is 0. This patch fixes the bug.

This version includes the suggestions from Linus Walleij.

Tested on ml507 board.

Signed-off-by: Gernot Vormayr <gvormayr@gmail.com>
---
 drivers/gpio/gpio-xilinx.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index 1248186..c11bc11 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -197,6 +197,7 @@ static int xgpio_of_probe(struct device_node *np)
 	struct xgpio_instance *chip;
 	int status = 0;
 	const u32 *tree_info;
+	u32 ngpio;
 
 	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
 	if (!chip)
@@ -211,12 +212,11 @@ static int xgpio_of_probe(struct device_node *np)
 	/* Update GPIO direction shadow register with default value */
 	of_property_read_u32(np, "xlnx,tri-default", &chip->gpio_dir);
 
-	/* By default assume full GPIO controller */
-	chip->mmchip.gc.ngpio = 32;
-
-	/* Check device node and parent device node for device width */
-	of_property_read_u32(np, "xlnx,gpio-width",
-			      (u32 *)&chip->mmchip.gc.ngpio);
+	/* Check device node and parent device node for device width
+	   and assume default width of 32 */
+	if (of_property_read_u32(np, "xlnx,gpio-width", &ngpio))
+		ngpio = 32;
+	chip->mmchip.gc.ngpio = (u16)ngpio;
 
 	spin_lock_init(&chip->gpio_lock);
 
@@ -258,12 +258,11 @@ static int xgpio_of_probe(struct device_node *np)
 		/* Update GPIO direction shadow register with default value */
 		of_property_read_u32(np, "xlnx,tri-default-2", &chip->gpio_dir);
 
-		/* By default assume full GPIO controller */
-		chip->mmchip.gc.ngpio = 32;
-
-		/* Check device node and parent device node for device width */
-		of_property_read_u32(np, "xlnx,gpio2-width",
-				     (u32 *)&chip->mmchip.gc.ngpio);
+		/* Check device node and parent device node for device width
+		   and assume default width of 32 */
+		if (of_property_read_u32(np, "xlnx,gpio2-width", &ngpio))
+			ngpio = 32;
+		chip->mmchip.gc.ngpio = (u16)ngpio;
 
 		spin_lock_init(&chip->gpio_lock);
 
-- 
2.1.0


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

* Re: [PATCH v2 1/1] gpio: Fix ngpio in gpio-xilinx driver
  2014-09-23 22:58 ` [PATCH v2 " Gernot Vormayr
@ 2014-09-24 11:38   ` Linus Walleij
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2014-09-24 11:38 UTC (permalink / raw)
  To: Gernot Vormayr
  Cc: Alexandre Courbot, Michal Simek, linux-gpio, linux-arm-kernel,
	linux-kernel

On Wed, Sep 24, 2014 at 12:58 AM, Gernot Vormayr <gvormayr@gmail.com> wrote:

> If one adds gpio-controller; to the chip in the devicetree, then
> initialization fails with 'gpiochip_find_base: cannot find free range',
> because ngpio is 0. This patch fixes the bug.
>
> This version includes the suggestions from Linus Walleij.
>
> Tested on ml507 board.
>
> Signed-off-by: Gernot Vormayr <gvormayr@gmail.com>

Patch applied.

Yours,
Linus Walleij

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

end of thread, other threads:[~2014-09-24 11:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-18  9:03 [PATCH 1/1] gpio: Fix ngpio in gpio-xilinx driver Gernot Vormayr
2014-09-23 15:38 ` Linus Walleij
2014-09-23 22:48   ` Gernot Vormayr
2014-09-23 22:58 ` [PATCH v2 " Gernot Vormayr
2014-09-24 11:38   ` 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).