diff mbox series

gpio: rgpio2p: Enhance reading of GPIO pin value

Message ID 1fe3fadd8f669058ad737c32b7af5d2c6ccb189e.camel@googlemail.com
State Superseded
Delegated to: Stefano Babic
Headers show
Series gpio: rgpio2p: Enhance reading of GPIO pin value | expand

Commit Message

Christoph Fritz Jan. 24, 2022, 8:38 p.m. UTC
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>
---
 drivers/gpio/imx_rgpio2p.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Fabio Estevam Jan. 24, 2022, 8:50 p.m. UTC | #1
[Adding the NXP folks to help reviewing it]

On Mon, Jan 24, 2022 at 5:46 PM Christoph Fritz
<chf.fritz@googlemail.com> wrote:
>
> 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>
> ---
>  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
>
>
>
Fabio Estevam Jan. 24, 2022, 8:51 p.m. UTC | #2
On Mon, Jan 24, 2022 at 5:50 PM Fabio Estevam <festevam@gmail.com> wrote:
>
> [Adding the NXP folks to help reviewing it]

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

>
> On Mon, Jan 24, 2022 at 5:46 PM Christoph Fritz
> <chf.fritz@googlemail.com> wrote:
> >
> > 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>
> > ---
> >  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
> >
> >
> >
Christoph Fritz Feb. 22, 2022, 9:23 a.m. UTC | #3
*ping*, any objections getting this patch applied?

On Mon, 2022-01-24 at 17:51 -0300, Fabio Estevam wrote:
> On Mon, Jan 24, 2022 at 5:50 PM Fabio Estevam <festevam@gmail.com>
> wrote:
> > 
> > [Adding the NXP folks to help reviewing it]
> 
> Sorry, added the NXP Linux folks instead of the NXP U-Boot folks.
> 
> > 
> > On Mon, Jan 24, 2022 at 5:46 PM Christoph Fritz
> > <chf.fritz@googlemail.com> wrote:
> > > 
> > > 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>
> > > ---
> > >  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
> > > 
> > > 
> > >
Fabio Estevam Feb. 22, 2022, 11:56 a.m. UTC | #4
Hi Peng and Ye Li,

Could you please help reviewing this patch?

Thanks

On Mon, Jan 24, 2022 at 5:46 PM Christoph Fritz
<chf.fritz@googlemail.com> wrote:
>
> 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>
> ---
>  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
>
>
>
Peng Fan (OSS) Feb. 24, 2022, 12:24 p.m. UTC | #5
> 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.
> 
> Thanks
> 
> On Mon, Jan 24, 2022 at 5:46 PM Christoph Fritz <chf.fritz@googlemail.com>
> wrote:
> >
> > 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>

> > ---
> >  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
> >
> >
> >
diff mbox series

Patch

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)