Skip to content

Commit 2eca25a

Browse files
andy-shevLinus Walleij
authored andcommitted
gpio: acpi: Factor out acpi_gpio_to_gpiod_flags() helper
The helper function acpi_gpio_to_gpiod_flags() will be used later to configure pin properly whenever it's requested. While here, introduce a checking error code returned by gpiod_configure_flags() and bail out if it's not okay. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent ed7fcf1 commit 2eca25a

1 file changed

Lines changed: 36 additions & 25 deletions

File tree

‎drivers/gpio/gpiolib-acpi.c‎

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,31 @@ static bool acpi_get_driver_gpio_data(struct acpi_device *adev,
423423
return false;
424424
}
425425

426+
static enum gpiod_flags
427+
acpi_gpio_to_gpiod_flags(const struct acpi_resource_gpio *agpio)
428+
{
429+
bool pull_up = agpio->pin_config == ACPI_PIN_CONFIG_PULLUP;
430+
431+
switch (agpio->io_restriction) {
432+
case ACPI_IO_RESTRICT_INPUT:
433+
return GPIOD_IN;
434+
case ACPI_IO_RESTRICT_OUTPUT:
435+
/*
436+
* ACPI GPIO resources don't contain an initial value for the
437+
* GPIO. Therefore we deduce that value from the pull field
438+
* instead. If the pin is pulled up we assume default to be
439+
* high, otherwise low.
440+
*/
441+
return pull_up ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
442+
default:
443+
/*
444+
* Assume that the BIOS has configured the direction and pull
445+
* accordingly.
446+
*/
447+
return GPIOD_ASIS;
448+
}
449+
}
450+
426451
struct acpi_gpio_lookup {
427452
struct acpi_gpio_info info;
428453
int index;
@@ -740,7 +765,6 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
740765
struct acpi_resource *ares;
741766
int pin_index = (int)address;
742767
acpi_status status;
743-
bool pull_up;
744768
int length;
745769
int i;
746770

@@ -755,7 +779,6 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
755779
}
756780

757781
agpio = &ares->data.gpio;
758-
pull_up = agpio->pin_config == ACPI_PIN_CONFIG_PULLUP;
759782

760783
if (WARN_ON(agpio->io_restriction == ACPI_IO_RESTRICT_INPUT &&
761784
function == ACPI_WRITE)) {
@@ -806,35 +829,23 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
806829
}
807830

808831
if (!found) {
809-
desc = gpiochip_request_own_desc(chip, pin,
810-
"ACPI:OpRegion");
832+
enum gpiod_flags flags = acpi_gpio_to_gpiod_flags(agpio);
833+
const char *label = "ACPI:OpRegion";
834+
int err;
835+
836+
desc = gpiochip_request_own_desc(chip, pin, label);
811837
if (IS_ERR(desc)) {
812838
status = AE_ERROR;
813839
mutex_unlock(&achip->conn_lock);
814840
goto out;
815841
}
816842

817-
switch (agpio->io_restriction) {
818-
case ACPI_IO_RESTRICT_INPUT:
819-
gpiod_direction_input(desc);
820-
break;
821-
case ACPI_IO_RESTRICT_OUTPUT:
822-
/*
823-
* ACPI GPIO resources don't contain an
824-
* initial value for the GPIO. Therefore we
825-
* deduce that value from the pull field
826-
* instead. If the pin is pulled up we
827-
* assume default to be high, otherwise
828-
* low.
829-
*/
830-
gpiod_direction_output(desc, pull_up);
831-
break;
832-
default:
833-
/*
834-
* Assume that the BIOS has configured the
835-
* direction and pull accordingly.
836-
*/
837-
break;
843+
err = gpiod_configure_flags(desc, label, 0, flags);
844+
if (err < 0) {
845+
status = AE_NOT_CONFIGURED;
846+
gpiochip_free_own_desc(desc);
847+
mutex_unlock(&achip->conn_lock);
848+
goto out;
838849
}
839850

840851
conn = kzalloc(sizeof(*conn), GFP_KERNEL);

0 commit comments

Comments
 (0)