All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Fritz <chf.fritz@googlemail.com>
To: u-boot <u-boot@lists.denx.de>, Stefano Babic <sbabic@denx.de>
Cc: Peng Fan <peng.fan@nxp.com>, Fabio Estevam <festevam@gmail.com>
Subject: [RESEND PATCH] gpio: rgpio2p: Enhance reading of GPIO pin value
Date: Thu, 24 Mar 2022 16:11:11 +0100	[thread overview]
Message-ID: <92957fd3e899d2e1e907884469a82f7ef3723739.camel@googlemail.com> (raw)

Add support for reading GPIO pin value when function is output.
With this patch applied, gpio toggle command is working.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
Cc: Fabio Estevam <festevam@gmail.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/gpio/imx_rgpio2p.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/imx_rgpio2p.c b/drivers/gpio/imx_rgpio2p.c
index 0e2874ca95c..175e460aff5 100644
--- a/drivers/gpio/imx_rgpio2p.c
+++ b/drivers/gpio/imx_rgpio2p.c
@@ -39,6 +39,14 @@ static int imx_rgpio2p_is_output(struct gpio_regs *regs, int offset)
 	return val & (1 << offset) ? 1 : 0;
 }
 
+static int imx_rgpio2p_bank_get_direction(struct gpio_regs *regs, int offset)
+{
+	if ((readl(&regs->gpio_pddr) >> offset) & 0x01)
+		return IMX_RGPIO2P_DIRECTION_OUT;
+
+	return IMX_RGPIO2P_DIRECTION_IN;
+}
+
 static void imx_rgpio2p_bank_direction(struct gpio_regs *regs, int offset,
 				    enum imx_rgpio2p_direction direction)
 {
@@ -67,7 +75,11 @@ static void imx_rgpio2p_bank_set_value(struct gpio_regs *regs, int offset,
 
 static int imx_rgpio2p_bank_get_value(struct gpio_regs *regs, int offset)
 {
-	return (readl(&regs->gpio_pdir) >> offset) & 0x01;
+	if (imx_rgpio2p_bank_get_direction(regs, offset) ==
+	    IMX_RGPIO2P_DIRECTION_IN)
+		return (readl(&regs->gpio_pdir) >> offset) & 0x01;
+
+	return (readl(&regs->gpio_pdor) >> offset) & 0x01;
 }
 
 static int  imx_rgpio2p_direction_input(struct udevice *dev, unsigned offset)
-- 
2.30.2




             reply	other threads:[~2022-03-24 15:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24 15:11 Christoph Fritz [this message]
2022-03-24 16:00 ` [RESEND PATCH] gpio: rgpio2p: Enhance reading of GPIO pin value Fabio Estevam
2022-04-05 10:29 Christoph Fritz
2022-04-23 20:37 ` Christoph Fritz
2022-05-21  0:17   ` Christoph Fritz
2022-05-21 13:35     ` Stefano Babic
2022-05-23 11:33 sbabic

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=92957fd3e899d2e1e907884469a82f7ef3723739.camel@googlemail.com \
    --to=chf.fritz@googlemail.com \
    --cc=festevam@gmail.com \
    --cc=peng.fan@nxp.com \
    --cc=sbabic@denx.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.