diff mbox series

[v2] gpio: mpc8xxx: latch GPIOs state on module load when configured as output

Message ID 20230531204139.10570-1-msmulski2@gmail.com
State New
Headers show
Series [v2] gpio: mpc8xxx: latch GPIOs state on module load when configured as output | expand

Commit Message

msmulski2@gmail.com May 31, 2023, 8:41 p.m. UTC
From: Michal Smulski <michal.smulski@ooma.com>

Qoriq and related devices allow reading out state of GPIO set as output.
However, currently on driver's init, all outputs are configured as driven
low. So, any changes to GPIO confiuration will drive all pins (configured
as output) as output-low.
This patch latches state of output GPIOs before any GPIO configuration
takes place. This preserves any output settings done prior to loading
the driver (for example, by u-boot).

Signed-off-by: Michal Smulski <michal.smulski@ooma.com>
---
 drivers/gpio/gpio-mpc8xxx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Bartosz Golaszewski June 1, 2023, 7:37 a.m. UTC | #1
On Wed, May 31, 2023 at 10:41 PM <msmulski2@gmail.com> wrote:
>
> From: Michal Smulski <michal.smulski@ooma.com>
>
> Qoriq and related devices allow reading out state of GPIO set as output.
> However, currently on driver's init, all outputs are configured as driven
> low. So, any changes to GPIO confiuration will drive all pins (configured
> as output) as output-low.
> This patch latches state of output GPIOs before any GPIO configuration
> takes place. This preserves any output settings done prior to loading
> the driver (for example, by u-boot).
>
> Signed-off-by: Michal Smulski <michal.smulski@ooma.com>
> ---
>  drivers/gpio/gpio-mpc8xxx.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
> index 3eb08cd1fdc0..6340e738c912 100644
> --- a/drivers/gpio/gpio-mpc8xxx.c
> +++ b/drivers/gpio/gpio-mpc8xxx.c
> @@ -375,8 +375,12 @@ static int mpc8xxx_probe(struct platform_device *pdev)
>         if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
>             of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
>             of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
> -           is_acpi_node(fwnode))
> +           is_acpi_node(fwnode)) {
>                 gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0xffffffff);
> +               /* Also, latch state of GPIOs configured as output by bootloader. */
> +               gc->bgpio_data = gc->read_reg(mpc8xxx_gc->regs + GPIO_DAT) &
> +                       gc->read_reg(mpc8xxx_gc->regs + GPIO_DIR);
> +       }
>
>         ret = devm_gpiochip_add_data(&pdev->dev, gc, mpc8xxx_gc);
>         if (ret) {
> --
> 2.34.1
>

When sending a new version, please list the changes since the last submission.

Bart
Michal Smulski June 1, 2023, 11 p.m. UTC | #2
Yes, I will re-send version v2 with cover letter.
Regards,
Michal

-----Original Message-----
From: Bartosz Golaszewski <brgl@bgdev.pl> 
Sent: Thursday, June 1, 2023 12:37 AM
To: msmulski2@gmail.com
Cc: linus.walleij@linaro.org; linux-gpio@vger.kernel.org; Michal Smulski <michal.smulski@ooma.com>
Subject: Re: [PATCH v2] gpio: mpc8xxx: latch GPIOs state on module load when configured as output

CAUTION: This email is originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.


On Wed, May 31, 2023 at 10:41 PM <msmulski2@gmail.com> wrote:
>
> From: Michal Smulski <michal.smulski@ooma.com>
>
> Qoriq and related devices allow reading out state of GPIO set as output.
> However, currently on driver's init, all outputs are configured as driven
> low. So, any changes to GPIO confiuration will drive all pins (configured
> as output) as output-low.
> This patch latches state of output GPIOs before any GPIO configuration
> takes place. This preserves any output settings done prior to loading
> the driver (for example, by u-boot).
>
> Signed-off-by: Michal Smulski <michal.smulski@ooma.com>
> ---
>  drivers/gpio/gpio-mpc8xxx.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
> index 3eb08cd1fdc0..6340e738c912 100644
> --- a/drivers/gpio/gpio-mpc8xxx.c
> +++ b/drivers/gpio/gpio-mpc8xxx.c
> @@ -375,8 +375,12 @@ static int mpc8xxx_probe(struct platform_device *pdev)
>         if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
>             of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
>             of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
> -           is_acpi_node(fwnode))
> +           is_acpi_node(fwnode)) {
>                 gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0xffffffff);
> +               /* Also, latch state of GPIOs configured as output by bootloader. */
> +               gc->bgpio_data = gc->read_reg(mpc8xxx_gc->regs + GPIO_DAT) &
> +                       gc->read_reg(mpc8xxx_gc->regs + GPIO_DIR);
> +       }
>
>         ret = devm_gpiochip_add_data(&pdev->dev, gc, mpc8xxx_gc);
>         if (ret) {
> --
> 2.34.1
>

When sending a new version, please list the changes since the last submission.

Bart
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 3eb08cd1fdc0..6340e738c912 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -375,8 +375,12 @@  static int mpc8xxx_probe(struct platform_device *pdev)
 	if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
 	    of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
 	    of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
-	    is_acpi_node(fwnode))
+	    is_acpi_node(fwnode)) {
 		gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0xffffffff);
+		/* Also, latch state of GPIOs configured as output by bootloader. */
+		gc->bgpio_data = gc->read_reg(mpc8xxx_gc->regs + GPIO_DAT) &
+			gc->read_reg(mpc8xxx_gc->regs + GPIO_DIR);
+	}
 
 	ret = devm_gpiochip_add_data(&pdev->dev, gc, mpc8xxx_gc);
 	if (ret) {