[PATCH 1/1] iMX gpio: Allow reading back of pin status if configuredas gpio output

From: Georg Waibel
Date: Fri Jan 17 2014 - 08:51:38 EST

Register PSR was used to read the pin status in the mxc_gpio driver. This
register reflects the pin status if a pin is configured as gpio input.
If a pin is configured as an gpio output register PSR is not updated and
returns 0 instead of the actual pin status. Thus attempting to read back the
status of an gpio output pin via PSR returns a wrong value.

Reading register DR instead of PSR fixes this issue:
- If pin is gpio output: DR returns the value written to DR by software
- If pin is gpio input: DR returns the value of register PSR und thus the
pin status

This behaviour is valid for all processors >= iMX31. Verified on iMX6q.
See the iMX reference manuals gpio section for details.

Signed-off-by: Georg Waibel <georg.waibel@xxxxxxxxxxxxxxxxx>
drivers/gpio/gpio-mxc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index 3307f6d..3717e09 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -407,6 +407,7 @@ static int mxc_gpio_probe(struct platform_device *pdev)
struct resource *iores;
int irq_base;
int err;
+ int dat;


@@ -447,8 +448,9 @@ static int mxc_gpio_probe(struct platform_device *pdev)

+ dat = (mxc_gpio_hwtype == IMX21_GPIO) ? GPIO_PSR : GPIO_DR;
err = bgpio_init(&port->bgc, &pdev->dev, 4,
- port->base + GPIO_PSR,
+ port->base + dat,
port->base + GPIO_DR, NULL,
port->base + GPIO_GDIR, NULL, 0);
if (err)
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/