public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Fabio Estevam <festevam@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] gpio: mxc_gpio: Fix gpio_get_value() when the GPIO is an output
Date: Sat, 28 Sep 2013 14:22:44 -0300	[thread overview]
Message-ID: <1380388964-26009-1-git-send-email-festevam@gmail.com> (raw)

From: Fabio Estevam <fabio.estevam@freescale.com>

When the GPIO is configured as an output, we should return the value from the DR
register.

This implements the same fix as in the following kernel commit from FSL BSP:
http://git.freescale.com/git/cgit.cgi/imx/linux-2.6-imx.git/commit/arch/arm/plat-mxc/gpio.c?h=imx_3.0.35_4.1.0&id=d6f32393eaf455ce3c32d4e9bafd34d9091eaf45

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Otavio,

I don't have i.mx hardware access at the moment to try it, but this should fix 
your LED problem.

 drivers/gpio/mxc_gpio.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index 6a572d5..debbecb 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -93,7 +93,7 @@ int gpio_get_value(unsigned gpio)
 {
 	unsigned int port = GPIO_TO_PORT(gpio);
 	struct gpio_regs *regs;
-	u32 val;
+	u32 direction;
 
 	if (port >= ARRAY_SIZE(gpio_ports))
 		return -1;
@@ -102,9 +102,12 @@ int gpio_get_value(unsigned gpio)
 
 	regs = (struct gpio_regs *)gpio_ports[port];
 
-	val = (readl(&regs->gpio_psr) >> gpio) & 0x01;
+	direction = readl(&regs->gpio_dir);
 
-	return val;
+	if ((direction >> gpio) & 1)
+		return (readl(&regs->gpio_dr) >> gpio) & 1; /* output mode */
+	else
+		return (readl(&regs->gpio_psr) >> gpio) & 1; /* input mode */
 }
 
 int gpio_request(unsigned gpio, const char *label)
-- 
1.8.1.2

             reply	other threads:[~2013-09-28 17:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-28 17:22 Fabio Estevam [this message]
2013-09-28 19:04 ` [U-Boot] [PATCH] gpio: mxc_gpio: Fix gpio_get_value() when the GPIO is an output Otavio Salvador
2013-09-29 13:21 ` Benoît Thébaudeau
2013-09-29 17:09   ` Eric Bénard
2013-09-29 17:48     ` Otavio Salvador
2013-09-29 18:19       ` Eric Bénard
2013-09-29 18:22         ` Fabio Estevam
2013-09-29 18:26           ` Eric Bénard
2013-09-29 18:48             ` Fabio Estevam
2013-09-29 18:50               ` Benoît Thébaudeau
2013-09-29 18:58                 ` Fabio Estevam
2013-09-29 19:25                   ` Benoît Thébaudeau
2013-09-29 19:42                     ` Otavio Salvador
2013-09-29 19:45                       ` Benoît Thébaudeau
2013-09-29 19:49                         ` Otavio Salvador
2013-09-29 22:24                           ` Otavio Salvador
2013-09-30  1:32                             ` Fabio Estevam
2013-09-30 11:08                               ` Benoît Thébaudeau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1380388964-26009-1-git-send-email-festevam@gmail.com \
    --to=festevam@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox