linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib: fix chip->base handling in of_gpio_simple_xlate()
@ 2012-07-22 17:10 Daniel Mack
  2012-07-23 14:43 ` Daniel Mack
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Mack @ 2012-07-22 17:10 UTC (permalink / raw)
  To: linux-kernel; +Cc: Daniel Mack, Grant Likely, Linus Walleij

of_gpio_simple_xlate() is called for each chip when a GPIO is looked up.
When registering several chips off the same DT node (with different pin
offsets) however, the lookup fails as the GPIO number passed in to
of_gpio_simple_xlate() is likely higher than the chip's ->ngpio value.

Fix that by taking into account the chip's ->base value, and return the
relative offset of the pin inside the chip.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Linus Walleij <linus.walleij@stericsson.com>
---

I'm currently porting the PXA pieces over to DT, and stumbled over what
looks like an obvious bug to me. Correct me if I'm mistaken, but I see
no reason why one shouldn't be able to instanciate several GPIO chips
from a single DT node.

Thanks,
Daniel

 drivers/gpio/gpiolib-of.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index d18068a..51bc232 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -147,13 +147,13 @@ int of_gpio_simple_xlate(struct gpio_chip *gc,
 	if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
 		return -EINVAL;
 
-	if (gpiospec->args[0] >= gc->ngpio)
+	if (gpiospec->args[0] >= gc->ngpio + gc->base)
 		return -EINVAL;
 
 	if (flags)
 		*flags = gpiospec->args[1];
 
-	return gpiospec->args[0];
+	return gpiospec->args[0] - gc->base;
 }
 EXPORT_SYMBOL(of_gpio_simple_xlate);
 
-- 
1.7.10.4


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

end of thread, other threads:[~2012-07-24 15:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-22 17:10 [PATCH] gpiolib: fix chip->base handling in of_gpio_simple_xlate() Daniel Mack
2012-07-23 14:43 ` Daniel Mack
2012-07-24 12:56   ` Arnd Bergmann
2012-07-24 13:04     ` Daniel Mack
2012-07-24 14:08       ` Arnd Bergmann
2012-07-24 15:22         ` Daniel Mack

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).