Skip to content

Commit

Permalink
gpiolib: acpi: Take into account debounce settings
Browse files Browse the repository at this point in the history
We didn't take into account the debounce settings supplied by ACPI.
This change is targeting the mentioned gap.

Reported-by: Coiby Xu <coiby.xu@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
  • Loading branch information
Andy Shevchenko committed Nov 16, 2020
1 parent 32fa655 commit 8dcb7a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions drivers/gpio/gpiolib-acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares,
return AE_OK;
}

ret = gpio_set_debounce_timeout(desc, agpio->debounce_timeout);
if (ret)
goto fail_free_desc;

ret = gpiochip_lock_as_irq(chip, pin);
if (ret) {
dev_err(chip->parent,
Expand Down Expand Up @@ -664,6 +668,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr,
agpio->pin_table[pin_index]);
lookup->info.pin_config = agpio->pin_config;
lookup->info.debounce = agpio->debounce_timeout;
lookup->info.gpioint = gpioint;

/*
Expand Down Expand Up @@ -961,6 +966,10 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
if (ret < 0)
return ret;

ret = gpio_set_debounce_timeout(desc, info.debounce);
if (ret)
return ret;

irq_flags = acpi_dev_get_irq_type(info.triggering,
info.polarity);

Expand Down Expand Up @@ -1048,6 +1057,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
if (!found) {
enum gpiod_flags flags = acpi_gpio_to_gpiod_flags(agpio);
const char *label = "ACPI:OpRegion";
int ret;

desc = gpiochip_request_own_desc(chip, pin, label,
GPIO_ACTIVE_HIGH,
Expand All @@ -1058,6 +1068,14 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
goto out;
}

ret = gpio_set_debounce_timeout(desc, agpio->debounce_timeout);
if (ret) {
gpiochip_free_own_desc(desc);
mutex_unlock(&achip->conn_lock);
status = AE_ERROR;
goto out;
}

conn = kzalloc(sizeof(*conn), GFP_KERNEL);
if (!conn) {
status = AE_NO_MEMORY;
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpio/gpiolib-acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct acpi_device;
* @pin_config: pin bias as provided by ACPI
* @polarity: interrupt polarity as provided by ACPI
* @triggering: triggering type as provided by ACPI
* @debounce: debounce timeout as provided by ACPI
* @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping
*/
struct acpi_gpio_info {
Expand All @@ -27,6 +28,7 @@ struct acpi_gpio_info {
int pin_config;
int polarity;
int triggering;
unsigned int debounce;
unsigned int quirks;
};

Expand Down

0 comments on commit 8dcb7a1

Please sign in to comment.