Skip to contentSkip to conversation

gpio: rgpio2p: Enhance reading of GPIO pin value

PATCH Superseded Christoph Fritz 3 participants 6 messages Jan 24, 2022 – Feb 24, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/gpio/imx_rgpio2p.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpio/imx_rgpio2p.c +13 -1
index 0e2874ca95c..175e460aff5 100644
@@ -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)
Signature · 1 line
2.30.2
reviewer
#1 lore raw

[Adding the NXP folks to help reviewing it]

Quoted 46 lines · Christoph Fritz

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

---
 drivers/gpio/imx_rgpio2p.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpio/imx_rgpio2p.c +13 -2
index 0e2874ca95c..175e460aff5 100644
@@ -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

reviewer
#2 lore raw
Quoted 2 lines · Fabio Estevam

[Adding the NXP folks to help reviewing it]

Sorry, added the NXP Linux folks instead of the NXP U-Boot folks.

Quoted 49 lines
Quoted 46 lines · Christoph Fritz

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

---
 drivers/gpio/imx_rgpio2p.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpio/imx_rgpio2p.c +13 -2
index 0e2874ca95c..175e460aff5 100644
@@ -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

#3 lore raw

*ping*, any objections getting this patch applied?

Quoted 65 lines · Fabio Estevam
Quoted 2 lines · Fabio Estevam

[Adding the NXP folks to help reviewing it]

Sorry, added the NXP Linux folks instead of the NXP U-Boot folks.

Quoted 58 lines
Quoted 55 lines · Christoph Fritz

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

---
 drivers/gpio/imx_rgpio2p.c | 14 +++++++++++++-

 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpio/imx_rgpio2p.c +8 -0
index 0e2874ca95c..175e460aff5 100644
@@ -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)
 {

drivers/gpio/imx_rgpio2p.c +5 -1
@@ -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

reviewer
#4 lore raw
In reply to Christoph Fritz

Hi Peng and Ye Li,

Could you please help reviewing this patch?

Thanks

Quoted 46 lines · Christoph Fritz

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

---
 drivers/gpio/imx_rgpio2p.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpio/imx_rgpio2p.c +13 -2
index 0e2874ca95c..175e460aff5 100644
@@ -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

Reviewed-by Peng Fan
#5 lore raw
Quoted 5 lines

Subject: Re: [PATCH] gpio: rgpio2p: Enhance reading of GPIO pin value

Hi Peng and Ye Li,

Could you please help reviewing this patch?

Not able to find the original patch in my mailbox, so just reply here.

Quoted 10 lines

Thanks

Quoted 5 lines · Christoph Fritz

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

Quoted 41 lines

drivers/gpio/imx_rgpio2p.c static int imx_rgpio2p_is_output(struct gpio_regs

Quoted 9 lines
---
 drivers/gpio/imx_rgpio2p.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpio/imx_rgpio2p.c +0 -0
index 0e2874ca95c..175e460aff5 100644
@@ -39,6 +39,14 @@ static int imx_rgpio2p_is_output(struct gpio_regs

*regs, int offset)

Quoted 31 lines
drivers/gpio/imx_rgpio2p.c +7 -0
        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) {

drivers/gpio/imx_rgpio2p.c +5 -1
-       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