linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Valentin <edubezval@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>
Cc: ubrindis56@gmail.com, Fabio Estevam <fabio.estevam@freescale.com>,
	festevam@gmail.com, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Eduardo Valentin <edubezval@gmail.com>
Subject: [PATCH 2/2] gpio/mxc: implement reading output gpio value
Date: Wed,  5 Aug 2015 10:23:08 -0700	[thread overview]
Message-ID: <1438795388-22743-3-git-send-email-edubezval@gmail.com> (raw)
In-Reply-To: <1438795388-22743-1-git-send-email-edubezval@gmail.com>

In current implementation, reading the value of an output gpio
always return 0. The reason is because when a gpio is configured
as output, its output status can be read from the GPIO_DR register,
and when it is configure as input, its value can be read from
GPIO_PSR. With current implementation of basic mmio gpio driver,
we can only read the value from one single register.

Therefore, to workaround the basic mmio gpio driver limitation,
this patch changes the gpio-mxc driver to provide its own .get
callback. In the callback, we check the current status of the
gpio direction, and read the correct register based on its
current gpio direction status.

Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Alexandre Courbot <gnurou@gmail.com>
Cc: linux-gpio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ulises Brindis <ubrindis56@gmail.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
---
 drivers/gpio/gpio-mxc.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index 9e5bdbd..8822823 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -401,6 +401,18 @@ static int mxc_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
 	return irq_find_mapping(port->domain, offset);
 }
 
+static int mxc_gpio_get(struct gpio_chip *gc, unsigned int gpio)
+{
+	struct bgpio_chip *bgc = to_bgpio_chip(gc);
+
+	if (!!(bgc->read_reg(bgc->reg_dir) & bgc->pin2mask(bgc, gpio)))
+		return !!(bgc->read_reg(bgc->reg_set) &
+						bgc->pin2mask(bgc, gpio));
+	else
+		return !!(bgc->read_reg(bgc->reg_dat) &
+						bgc->pin2mask(bgc, gpio));
+}
+
 static int mxc_gpio_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -455,6 +467,7 @@ static int mxc_gpio_probe(struct platform_device *pdev)
 	if (err)
 		goto out_bgio;
 
+	port->bgc.gc.get = mxc_gpio_get;
 	port->bgc.gc.to_irq = mxc_gpio_to_irq;
 	port->bgc.gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 :
 					     pdev->id * 32;
-- 
2.5.0

  parent reply	other threads:[~2015-08-05 17:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-05 17:23 [PATCH 0/2] couple of fixes on IMX gpio driver Eduardo Valentin
2015-08-05 17:23 ` [PATCH 1/2] gpio/mxc: mask gpio interrupts in suspend Eduardo Valentin
2015-08-13 12:47   ` Linus Walleij
2015-08-05 17:23 ` Eduardo Valentin [this message]
2015-08-05 17:43   ` [PATCH 2/2] gpio/mxc: implement reading output gpio value Fabio Estevam
2015-08-05 18:02     ` Eduardo Valentin
2015-08-05 18:11       ` Fabio Estevam
2015-08-05 19:46         ` Eduardo Valentin
2015-08-05 20:44           ` Fabio Estevam

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=1438795388-22743-3-git-send-email-edubezval@gmail.com \
    --to=edubezval@gmail.com \
    --cc=fabio.estevam@freescale.com \
    --cc=festevam@gmail.com \
    --cc=gnurou@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ubrindis56@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).