Skip to content

Commit 5204472

Browse files
cricard13rafaeljw
authored andcommitted
ACPI / gpio: Add irq_type when a GPIO is used as an interrupt
When a GPIO is used as an interrupt in ACPI, the irq_type was not available for device driver. Make available polarity and triggering information in acpi_find_gpio by renaming acpi_gpio_info field active_low to polarity and adding triggering field (edge/level). For sanity, in gpiolib.c replace info.active_low by "info.polarity == GPIO_ACTIVE_LOW". Set the irq_type if necessary in acpi_dev_gpio_irq_get. Signed-off-by: Christophe Ricard <[email protected]> Acked-by: Mika Westerberg <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 55a9341 commit 5204472

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

drivers/gpio/gpiolib-acpi.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,15 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data)
417417
* ActiveLow is only specified for GpioInt resource. If
418418
* GpioIo is used then the only way to set the flag is
419419
* to use _DSD "gpios" property.
420+
* Note: we expect here:
421+
* - ACPI_ACTIVE_LOW == GPIO_ACTIVE_LOW
422+
* - ACPI_ACTIVE_HIGH == GPIO_ACTIVE_HIGH
420423
*/
421-
if (lookup->info.gpioint)
422-
lookup->info.active_low =
423-
agpio->polarity == ACPI_ACTIVE_LOW;
424+
if (lookup->info.gpioint) {
425+
lookup->info.polarity = agpio->polarity;
426+
lookup->info.triggering = agpio->triggering;
427+
}
428+
424429
}
425430

426431
return 1;
@@ -447,7 +452,7 @@ static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
447452
if (info) {
448453
*info = lookup->info;
449454
if (lookup->active_low)
450-
info->active_low = lookup->active_low;
455+
info->polarity = lookup->active_low;
451456
}
452457
return 0;
453458
}
@@ -595,6 +600,7 @@ struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
595600
int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
596601
{
597602
int idx, i;
603+
unsigned int irq_flags;
598604

599605
for (i = 0, idx = 0; idx <= index; i++) {
600606
struct acpi_gpio_info info;
@@ -603,8 +609,23 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
603609
desc = acpi_get_gpiod_by_index(adev, NULL, i, &info);
604610
if (IS_ERR(desc))
605611
break;
606-
if (info.gpioint && idx++ == index)
607-
return gpiod_to_irq(desc);
612+
if (info.gpioint && idx++ == index) {
613+
int irq = gpiod_to_irq(desc);
614+
615+
if (irq < 0)
616+
return irq;
617+
618+
irq_flags = acpi_dev_get_irq_type(info.triggering,
619+
info.polarity);
620+
621+
/* Set type if specified and different than the current one */
622+
if (irq_flags != IRQ_TYPE_NONE &&
623+
irq_flags != irq_get_trigger_type(irq))
624+
irq_set_irq_type(irq, irq_flags);
625+
626+
return irq;
627+
}
628+
608629
}
609630
return -ENOENT;
610631
}

drivers/gpio/gpiolib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,7 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id,
18791879
return desc;
18801880
}
18811881

1882-
if (info.active_low)
1882+
if (info.polarity == GPIO_ACTIVE_LOW)
18831883
*flags |= GPIO_ACTIVE_LOW;
18841884

18851885
return desc;
@@ -2217,7 +2217,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
22172217

22182218
desc = acpi_node_get_gpiod(fwnode, propname, 0, &info);
22192219
if (!IS_ERR(desc))
2220-
active_low = info.active_low;
2220+
active_low = info.polarity == GPIO_ACTIVE_LOW;
22212221
}
22222222

22232223
if (IS_ERR(desc))

drivers/gpio/gpiolib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ struct acpi_device;
2626
*/
2727
struct acpi_gpio_info {
2828
bool gpioint;
29-
bool active_low;
29+
int polarity;
30+
int triggering;
3031
};
3132

3233
/* gpio suffixes used for ACPI and device tree lookup */

0 commit comments

Comments
 (0)