gpio: mpc8xxx: latch GPIOs state on module load when configured as output
authorMichal Smulski <michal.smulski@ooma.com>
Thu, 1 Jun 2023 23:02:00 +0000 (16:02 -0700)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Fri, 16 Jun 2023 09:11:27 +0000 (11:11 +0200)
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>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpio-mpc8xxx.c

index 3eb08cd1fdc0818a89458b5ad72a4761b2b31a9c..6340e738c912ac510888aee2783c353ab14874e7 100644 (file)
@@ -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) {