diff mbox

[2/4] gpio/mxc: specify gpio base for device tree probe

Message ID 1344146488-9496-2-git-send-email-shawn.guo@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Shawn Guo Aug. 5, 2012, 6:01 a.m. UTC
Currently, unlike the non-DT probe where the gpio base is specified
with pdev->id, the DT probe uses the base dynamically allocated by
gpio core, which uses a completely different numbering scheme.  This
causes two issues to user space applications which access sysfs entry
/sys/class/gpio/gpioN.

* It breaks the compatibility with user space applications between
  non-DT and DT kernels.

* It's not intuitive and sometimes hard for users to map the Linux
  gpio number to the actual hardware pin.

Use alias to identify the gpio port/bank, and then the gpio base
can be specified with port id to solve above issues.  If alias is not
defined in device tree, the base number dynamically allocated by gpio
core will be used.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 drivers/gpio/gpio-mxc.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

Comments

Linus Walleij Aug. 5, 2012, 9:47 a.m. UTC | #1
On Sun, Aug 5, 2012 at 8:01 AM, Shawn Guo <shawn.guo@linaro.org> wrote:

> Currently, unlike the non-DT probe where the gpio base is specified
> with pdev->id, the DT probe uses the base dynamically allocated by
> gpio core, which uses a completely different numbering scheme.  This
> causes two issues to user space applications which access sysfs entry
> /sys/class/gpio/gpioN.

Applied.

Thanks,
Linus Walleij
Uwe Kleine-König Aug. 6, 2012, 2:12 p.m. UTC | #2
On Sun, Aug 05, 2012 at 02:01:26PM +0800, Shawn Guo wrote:
> Currently, unlike the non-DT probe where the gpio base is specified
> with pdev->id, the DT probe uses the base dynamically allocated by
> gpio core, which uses a completely different numbering scheme.  This
> causes two issues to user space applications which access sysfs entry
> /sys/class/gpio/gpioN.
> 
> * It breaks the compatibility with user space applications between
>   non-DT and DT kernels.
> 
> * It's not intuitive and sometimes hard for users to map the Linux
>   gpio number to the actual hardware pin.
> 
> Use alias to identify the gpio port/bank, and then the gpio base
> can be specified with port id to solve above issues.  If alias is not
> defined in device tree, the base number dynamically allocated by gpio
> core will be used.
> 
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
I applied patches 1, 2 and 4 to my imx35 dt tree and they work like a
charm.

Tested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

for these three.

Thanks
Uwe
diff mbox

Patch

diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index 76e8cda..80f44bb 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -465,7 +465,8 @@  static int __devinit mxc_gpio_probe(struct platform_device *pdev)
 		goto out_iounmap;
 
 	port->bgc.gc.to_irq = mxc_gpio_to_irq;
-	port->bgc.gc.base = pdev->id * 32;
+	port->bgc.gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 :
+					     pdev->id * 32;
 
 	err = gpiochip_add(&port->bgc.gc);
 	if (err)