diff mbox series

[RFC] gpio/acpi: set direction for ACPI OpRegion GPIOs

Message ID 20190529101342.30673-1-ard.biesheuvel@linaro.org
State New
Headers show
Series [RFC] gpio/acpi: set direction for ACPI OpRegion GPIOs | expand

Commit Message

Ard Biesheuvel May 29, 2019, 10:13 a.m. UTC
The ACPI GPIO OpRegion code never sets the direction for GPIOs that
it configures from scratch, leaving unconfigured GPIOs to be left
at the default direction, which is typically input not output.

So set the direction and default value explicitly.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 drivers/gpio/gpiolib-acpi.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Mika Westerberg May 29, 2019, 10:27 a.m. UTC | #1
On Wed, May 29, 2019 at 12:13:42PM +0200, Ard Biesheuvel wrote:
> The ACPI GPIO OpRegion code never sets the direction for GPIOs that
> it configures from scratch, leaving unconfigured GPIOs to be left
> at the default direction, which is typically input not output.

The code does:

  enum gpiod_flags flags = acpi_gpio_to_gpiod_flags(agpio);

before it requests the GPIO. Isn't that sufficient?
Ard Biesheuvel May 29, 2019, 10:50 a.m. UTC | #2
On Wed, 29 May 2019 at 12:27, Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
>
> On Wed, May 29, 2019 at 12:13:42PM +0200, Ard Biesheuvel wrote:
> > The ACPI GPIO OpRegion code never sets the direction for GPIOs that
> > it configures from scratch, leaving unconfigured GPIOs to be left
> > at the default direction, which is typically input not output.
>
> The code does:
>
>   enum gpiod_flags flags = acpi_gpio_to_gpiod_flags(agpio);
>
> before it requests the GPIO. Isn't that sufficient?

Yes, it works if I set the PullXxx value explicitly in the GpioIo() resource.
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index c9fc9e232aaf..02a2bc7fe18b 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -966,6 +966,12 @@  acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
 				goto out;
 			}
 
+			if (function == ACPI_WRITE)
+				gpiod_direction_output(desc,
+						       !!((1 << i) & *value));
+			else
+				gpiod_direction_input(desc);
+
 			conn->pin = pin;
 			conn->desc = desc;
 			list_add_tail(&conn->node, &achip->conns);