* Re: [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536
2013-11-22 8:12 [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536 Liu Gang
@ 2013-11-22 18:39 ` Scott Wood
2013-11-22 20:51 ` Kumar Gala
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Scott Wood @ 2013-11-22 18:39 UTC (permalink / raw)
To: Liu Gang; +Cc: b07421, linus.walleij, r61911, linux-gpio, agust, linuxppc-dev
On Fri, 2013-11-22 at 16:12 +0800, Liu Gang wrote:
> For MPC8572/MPC8536, the status of GPIOs defined as output
> cannot be determined by reading GPDAT register, so the code
> use shadow data register instead. But the code may give the
> wrong status of GPIOs defined as input under some scenarios:
>
> 1. If some pins were configured as inputs and were asserted
> high before booting the kernel, the shadow data has been
> initialized with those pin values.
> 2. Some pins have been configured as output first and have
> been set to the high value, then reconfigured as input.
>
> The above cases will make the shadow data for those input
> pins to be set to high. Then reading the pin status will
> always return high even if the actual pin status is low.
>
> The code should eliminate the effects of the shadow data to
> the input pins, and the status of those pins should be
> read directly from GPDAT.
>
> Signed-off-by: Liu Gang <Gang.Liu@freescale.com>
> ---
> changes in v2:
> - Added more description of the problem.
> - Reduced one in_be32() call.
> - Do not modify the shadow data.
>
> drivers/gpio/gpio-mpc8xxx.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
> index 914e859..d7d6d72 100644
> --- a/drivers/gpio/gpio-mpc8xxx.c
> +++ b/drivers/gpio/gpio-mpc8xxx.c
> @@ -70,10 +70,14 @@ static int mpc8572_gpio_get(struct gpio_chip *gc, unsigned int gpio)
> u32 val;
> struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
> struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
> + u32 out_mask, out_shadow;
>
> - val = in_be32(mm->regs + GPIO_DAT) & ~in_be32(mm->regs + GPIO_DIR);
> + out_mask = in_be32(mm->regs + GPIO_DIR);
>
> - return (val | mpc8xxx_gc->data) & mpc8xxx_gpio2mask(gpio);
> + val = in_be32(mm->regs + GPIO_DAT) & ~out_mask;
> + out_shadow = mpc8xxx_gc->data & out_mask;
> +
> + return (val | out_shadow) & mpc8xxx_gpio2mask(gpio);
> }
>
> static int mpc8xxx_gpio_get(struct gpio_chip *gc, unsigned int gpio)
Acked-by: Scott Wood <scottwood@freescale.com>
-Scott
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536
2013-11-22 8:12 [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536 Liu Gang
2013-11-22 18:39 ` Scott Wood
@ 2013-11-22 20:51 ` Kumar Gala
2013-11-26 9:20 ` Liu Gang
2013-11-29 9:32 ` Linus Walleij
` (2 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Kumar Gala @ 2013-11-22 20:51 UTC (permalink / raw)
To: Liu Gang; +Cc: b07421, linus.walleij, r61911, linux-gpio, agust, linuxppc-dev
On Nov 22, 2013, at 2:12 AM, Liu Gang <Gang.Liu@freescale.com> wrote:
> For MPC8572/MPC8536, the status of GPIOs defined as output
> cannot be determined by reading GPDAT register, so the code
> use shadow data register instead. But the code may give the
> wrong status of GPIOs defined as input under some scenarios:
>=20
> 1. If some pins were configured as inputs and were asserted
> high before booting the kernel, the shadow data has been
> initialized with those pin values.
> 2. Some pins have been configured as output first and have
> been set to the high value, then reconfigured as input.
>=20
> The above cases will make the shadow data for those input
> pins to be set to high. Then reading the pin status will
> always return high even if the actual pin status is low.
>=20
> The code should eliminate the effects of the shadow data to
> the input pins, and the status of those pins should be
> read directly from GPDAT.
>=20
> Signed-off-by: Liu Gang <Gang.Liu@freescale.com>
> ---
> changes in v2:
> - Added more description of the problem.
> - Reduced one in_be32() call.
> - Do not modify the shadow data.
>=20
> drivers/gpio/gpio-mpc8xxx.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>=20
> diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
> index 914e859..d7d6d72 100644
> --- a/drivers/gpio/gpio-mpc8xxx.c
> +++ b/drivers/gpio/gpio-mpc8xxx.c
> @@ -70,10 +70,14 @@ static int mpc8572_gpio_get(struct gpio_chip *gc, =
unsigned int gpio)
> u32 val;
> struct of_mm_gpio_chip *mm =3D to_of_mm_gpio_chip(gc);
> struct mpc8xxx_gpio_chip *mpc8xxx_gc =3D =
to_mpc8xxx_gpio_chip(mm);
> + u32 out_mask, out_shadow;
>=20
> - val =3D in_be32(mm->regs + GPIO_DAT) & ~in_be32(mm->regs + =
GPIO_DIR);
> + out_mask =3D in_be32(mm->regs + GPIO_DIR);
>=20
> - return (val | mpc8xxx_gc->data) & mpc8xxx_gpio2mask(gpio);
> + val =3D in_be32(mm->regs + GPIO_DAT) & ~out_mask;
> + out_shadow =3D mpc8xxx_gc->data & out_mask;
> +
> + return (val | out_shadow) & mpc8xxx_gpio2mask(gpio);
> }
I really think a comment is worth adding here about why we do this.
- k
>=20
> static int mpc8xxx_gpio_get(struct gpio_chip *gc, unsigned int gpio)
> --=20
> 1.8.4.1
>=20
>=20
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536
2013-11-22 20:51 ` Kumar Gala
@ 2013-11-26 9:20 ` Liu Gang
0 siblings, 0 replies; 7+ messages in thread
From: Liu Gang @ 2013-11-26 9:20 UTC (permalink / raw)
To: Kumar Gala; +Cc: b07421, linus.walleij, r61911, linux-gpio, agust, linuxppc-dev
On Fri, 2013-11-22 at 14:51 -0600, Kumar Gala wrote:
> > drivers/gpio/gpio-mpc8xxx.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
> > index 914e859..d7d6d72 100644
> > --- a/drivers/gpio/gpio-mpc8xxx.c
> > +++ b/drivers/gpio/gpio-mpc8xxx.c
> > @@ -70,10 +70,14 @@ static int mpc8572_gpio_get(struct gpio_chip *gc, unsigned int gpio)
> > u32 val;
> > struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
> > struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
> > + u32 out_mask, out_shadow;
> >
> > - val = in_be32(mm->regs + GPIO_DAT) & ~in_be32(mm->regs + GPIO_DIR);
> > + out_mask = in_be32(mm->regs + GPIO_DIR);
> >
> > - return (val | mpc8xxx_gc->data) & mpc8xxx_gpio2mask(gpio);
> > + val = in_be32(mm->regs + GPIO_DAT) & ~out_mask;
> > + out_shadow = mpc8xxx_gc->data & out_mask;
> > +
> > + return (val | out_shadow) & mpc8xxx_gpio2mask(gpio);
> > }
>
> I really think a comment is worth adding here about why we do this.
>
> - k
Hi, Kumar,
Thanks for your comment. In fact, there already had some comments above
the function:
/* Workaround GPIO 1 errata on MPC8572/MPC8536. The status of GPIOs
* defined as output cannot be determined by reading GPDAT register,
* so we use shadow data register instead. The status of input pins
* is determined by reading GPDAT register.
*/
Best Regards,
Liu Gang
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536
2013-11-22 8:12 [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536 Liu Gang
2013-11-22 18:39 ` Scott Wood
2013-11-22 20:51 ` Kumar Gala
@ 2013-11-29 9:32 ` Linus Walleij
2013-11-29 10:54 ` Anatolij Gustschin
2013-11-29 12:37 ` Linus Walleij
4 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2013-11-29 9:32 UTC (permalink / raw)
To: Liu Gang, Anatolij Gustschin
Cc: linux-gpio@vger.kernel.org, linuxppc-dev@lists.ozlabs.org list,
r61911, b07421
On Fri, Nov 22, 2013 at 9:12 AM, Liu Gang <Gang.Liu@freescale.com> wrote:
> For MPC8572/MPC8536, the status of GPIOs defined as output
> cannot be determined by reading GPDAT register, so the code
> use shadow data register instead. But the code may give the
> wrong status of GPIOs defined as input under some scenarios:
>
> 1. If some pins were configured as inputs and were asserted
> high before booting the kernel, the shadow data has been
> initialized with those pin values.
> 2. Some pins have been configured as output first and have
> been set to the high value, then reconfigured as input.
>
> The above cases will make the shadow data for those input
> pins to be set to high. Then reading the pin status will
> always return high even if the actual pin status is low.
>
> The code should eliminate the effects of the shadow data to
> the input pins, and the status of those pins should be
> read directly from GPDAT.
>
> Signed-off-by: Liu Gang <Gang.Liu@freescale.com>
> ---
> changes in v2:
> - Added more description of the problem.
> - Reduced one in_be32() call.
> - Do not modify the shadow data.
I'm waiting for the maintainers to ACK this before
applying.
Anatolij?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536
2013-11-22 8:12 [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536 Liu Gang
` (2 preceding siblings ...)
2013-11-29 9:32 ` Linus Walleij
@ 2013-11-29 10:54 ` Anatolij Gustschin
2013-11-29 12:37 ` Linus Walleij
4 siblings, 0 replies; 7+ messages in thread
From: Anatolij Gustschin @ 2013-11-29 10:54 UTC (permalink / raw)
To: Liu Gang, linus.walleij; +Cc: linux-gpio, linuxppc-dev, r61911, b07421
On Fri, 22 Nov 2013 16:12:40 +0800
Liu Gang <Gang.Liu@freescale.com> wrote:
> For MPC8572/MPC8536, the status of GPIOs defined as output
> cannot be determined by reading GPDAT register, so the code
> use shadow data register instead. But the code may give the
> wrong status of GPIOs defined as input under some scenarios:
>
> 1. If some pins were configured as inputs and were asserted
> high before booting the kernel, the shadow data has been
> initialized with those pin values.
> 2. Some pins have been configured as output first and have
> been set to the high value, then reconfigured as input.
>
> The above cases will make the shadow data for those input
> pins to be set to high. Then reading the pin status will
> always return high even if the actual pin status is low.
>
> The code should eliminate the effects of the shadow data to
> the input pins, and the status of those pins should be
> read directly from GPDAT.
>
> Signed-off-by: Liu Gang <Gang.Liu@freescale.com>
> ---
> changes in v2:
> - Added more description of the problem.
> - Reduced one in_be32() call.
> - Do not modify the shadow data.
>
> drivers/gpio/gpio-mpc8xxx.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
> index 914e859..d7d6d72 100644
> --- a/drivers/gpio/gpio-mpc8xxx.c
> +++ b/drivers/gpio/gpio-mpc8xxx.c
> @@ -70,10 +70,14 @@ static int mpc8572_gpio_get(struct gpio_chip *gc, unsigned int gpio)
> u32 val;
> struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
> struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
> + u32 out_mask, out_shadow;
>
> - val = in_be32(mm->regs + GPIO_DAT) & ~in_be32(mm->regs + GPIO_DIR);
> + out_mask = in_be32(mm->regs + GPIO_DIR);
>
> - return (val | mpc8xxx_gc->data) & mpc8xxx_gpio2mask(gpio);
> + val = in_be32(mm->regs + GPIO_DAT) & ~out_mask;
> + out_shadow = mpc8xxx_gc->data & out_mask;
> +
> + return (val | out_shadow) & mpc8xxx_gpio2mask(gpio);
> }
>
> static int mpc8xxx_gpio_get(struct gpio_chip *gc, unsigned int gpio)
Acked-by: Anatolij Gustschin <agust@denx.de>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536
2013-11-22 8:12 [PATCH v2] powerpc/gpio: Fix the wrong GPIO input data on MPC8572/MPC8536 Liu Gang
` (3 preceding siblings ...)
2013-11-29 10:54 ` Anatolij Gustschin
@ 2013-11-29 12:37 ` Linus Walleij
4 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2013-11-29 12:37 UTC (permalink / raw)
To: Liu Gang
Cc: linux-gpio@vger.kernel.org, Anatolij Gustschin,
linuxppc-dev@lists.ozlabs.org list, r61911, b07421
On Fri, Nov 22, 2013 at 9:12 AM, Liu Gang <Gang.Liu@freescale.com> wrote:
> For MPC8572/MPC8536, the status of GPIOs defined as output
> cannot be determined by reading GPDAT register, so the code
> use shadow data register instead. But the code may give the
> wrong status of GPIOs defined as input under some scenarios:
(...)
> Signed-off-by: Liu Gang <Gang.Liu@freescale.com>
> ---
> changes in v2:
> - Added more description of the problem.
> - Reduced one in_be32() call.
> - Do not modify the shadow data.
Applied this v2 version, added ACKs and tagged for stable.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread