summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Fritz <chf.fritz@googlemail.com>2022-04-05 13:29:30 +0300
committerStefano Babic <sbabic@denx.de>2022-05-23 12:37:58 +0300
commit0539d16d22f65b5958800489701249f990531073 (patch)
tree5fd79af0aabbd343357e2d4cc78ffa8a33f71a3c
parent9d371e5fea39002c077db3335395ffc62e84e5fa (diff)
downloadu-boot-0539d16d22f65b5958800489701249f990531073.tar.xz
gpio: rgpio2p: Enhance reading of GPIO pin value
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> Reviewed-by: Peng Fan <peng.fan@nxp.com> Reviewed-by: Fabio Estevam <festevam@denx.de>
-rw-r--r--drivers/gpio/imx_rgpio2p.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/drivers/gpio/imx_rgpio2p.c b/drivers/gpio/imx_rgpio2p.c
index 0e2874ca95..175e460aff 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)