Skip to contentSkip to conversation

gpio: acpi: Call enable_irq_wake for _IAE GpioInts with Wake set

PATCH Superseded Hans de Goede 4 participants 7 messages Mar 20, 2017 – Mar 24, 2017

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gpio: acpi: Call enable_irq_wake for _IAE GpioInts with Wake set

On Bay Trail / Cherry Trail systems with a LID switch, the LID switch is often connect to a gpioint handled by an _IAE event handler. Before this commit such systems would not wake up when opening the lid, requiring the powerbutton to be pressed after opening the lid to wakeup.

Note that Bay Trail / Cherry Trail systems use suspend-to-idle, so the interrupts are generated anyway on those lines on lid switch changes, but they are treated by the IRQ subsystem as spurious while suspended if not marked as wakeup IRQs.

This commit calls enable_irq_wake() for _IAE GpioInts with a valid event handler which have their Wake flag set. This fixes such systems not waking up when opening the lid.

---
Changes in v2:
-Improve commit msg
-Add Mika's Acked-by

---
 drivers/gpio/gpiolib-acpi.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpio/gpiolib-acpi.c +9 -0
index 8cd3f66..18207b2 100644
@@ -28,6 +28,7 @@ struct acpi_gpio_event {
 	acpi_handle handle;
 	unsigned int pin;
 	unsigned int irq;
+	bool irq_wake_enabled;
 	struct gpio_desc *desc;
 };
 
@@ -266,6 +267,11 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
 		goto fail_free_event;
 	}
 
+	if (agpio->wake_capable == ACPI_WAKE_CAPABLE) {
+		enable_irq_wake(irq);
+		event->irq_wake_enabled = true;
+	}
+
 	list_add_tail(&event->node, &acpi_gpio->events);
 	return AE_OK;
 
@@ -339,6 +345,9 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
 	list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) {
 		struct gpio_desc *desc;
 
+		if (event->irq_wake_enabled)
+			disable_irq_wake(event->irq);
+
 		free_irq(event->irq, event);
 		desc = event->desc;
 		if (WARN_ON(IS_ERR(desc)))
Signature · 1 line
2.9.3
#1 lore raw
Quoted 49 lines · Hans de Goede

On Bay Trail / Cherry Trail systems with a LID switch, the LID switch is often connect to a gpioint handled by an _IAE event handler. Before this commit such systems would not wake up when opening the lid, requiring the powerbutton to be pressed after opening the lid to wakeup.

Note that Bay Trail / Cherry Trail systems use suspend-to-idle, so the interrupts are generated anyway on those lines on lid switch changes, but they are treated by the IRQ subsystem as spurious while suspended if not marked as wakeup IRQs.

This commit calls enable_irq_wake() for _IAE GpioInts with a valid event handler which have their Wake flag set. This fixes such systems not waking up when opening the lid.

---
Changes in v2:

(quoted diff) +0 -3
-Improve commit msg
-Add Mika's Acked-by
---
 drivers/gpio/gpiolib-acpi.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpio/gpiolib-acpi.c +6 -0
index 8cd3f66..18207b2 100644
@@ -28,6 +28,7 @@ struct acpi_gpio_event {
 	acpi_handle handle;
 	unsigned int pin;
 	unsigned int irq;
+	bool irq_wake_enabled;
 	struct gpio_desc *desc;
 };
 
@@ -266,6 +267,11 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
 		goto fail_free_event;
 	}
 
+	if (agpio->wake_capable == ACPI_WAKE_CAPABLE) {
+		enable_irq_wake(irq);
+		event->irq_wake_enabled = true;
+	}
+
 	list_add_tail(&event->node, &acpi_gpio->events);
 	return AE_OK;
 

drivers/gpio/gpiolib-acpi.c void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) · line 348

Quoted 4 lines
drivers/gpio/gpiolib-acpi.c +1 -0
@@ -339,6 +345,9 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
 	list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) {
 		struct gpio_desc *desc;
 
+		if (event->irq_wake_enabled)

It has just occurred to me that if the event is in the list, the IRQ will be enabled to wake up as long as agpio->wake_capable == ACPI_WAKE_CAPABLE, so it looks like it should be sufficient to check

	if (agpio->wake_capable == ACPI_WAKE_CAPABLE)

here and the new flag is not necessary. Or is it?

drivers/gpio/gpiolib-acpi.c void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) · line 353

Quoted 6 lines
drivers/gpio/gpiolib-acpi.c +2 -0
+			disable_irq_wake(event->irq);
+
 		free_irq(event->irq, event);
 		desc = event->desc;
 		if (WARN_ON(IS_ERR(desc)))

Thanks,
Rafael

#2 lore raw

Hi,

Quoted 59 lines · Rafael J. Wysocki
Quoted 49 lines · Hans de Goede

On Bay Trail / Cherry Trail systems with a LID switch, the LID switch is often connect to a gpioint handled by an _IAE event handler. Before this commit such systems would not wake up when opening the lid, requiring the powerbutton to be pressed after opening the lid to wakeup.

Note that Bay Trail / Cherry Trail systems use suspend-to-idle, so the interrupts are generated anyway on those lines on lid switch changes, but they are treated by the IRQ subsystem as spurious while suspended if not marked as wakeup IRQs.

This commit calls enable_irq_wake() for _IAE GpioInts with a valid event handler which have their Wake flag set. This fixes such systems not waking up when opening the lid.

---
Changes in v2:

(quoted diff) +0 -3
-Improve commit msg
-Add Mika's Acked-by
---
 drivers/gpio/gpiolib-acpi.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpio/gpiolib-acpi.c +6 -0
index 8cd3f66..18207b2 100644
@@ -28,6 +28,7 @@ struct acpi_gpio_event {
 	acpi_handle handle;
 	unsigned int pin;
 	unsigned int irq;
+	bool irq_wake_enabled;
 	struct gpio_desc *desc;
 };
 
@@ -266,6 +267,11 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
 		goto fail_free_event;
 	}
 
+	if (agpio->wake_capable == ACPI_WAKE_CAPABLE) {
+		enable_irq_wake(irq);
+		event->irq_wake_enabled = true;
+	}
+
 	list_add_tail(&event->node, &acpi_gpio->events);
 	return AE_OK;
 

drivers/gpio/gpiolib-acpi.c void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) · line 348

Quoted 4 lines
drivers/gpio/gpiolib-acpi.c +1 -0
@@ -339,6 +345,9 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
 	list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) {
 		struct gpio_desc *desc;
 
+		if (event->irq_wake_enabled)

It has just occurred to me that if the event is in the list, the IRQ will be enabled to wake up as long as agpio->wake_capable == ACPI_WAKE_CAPABLE, so it looks like it should be sufficient to check

Quoted 3 lines
	if (agpio->wake_capable == ACPI_WAKE_CAPABLE)

here and the new flag is not necessary. Or is it?

We don't have (readily available) access to the acpi_resource_gpio struct in acpi_gpiochip_free_interrupts, so I'm going to go with Andy's suggestion instead and change the if to:

                if (irqd_is_wakeup_set(irq_get_irq_data(event->irq)))
                        disable_irq_wake(event->irq);

Still need to run some quick tests and then I will send v3 with this change.

Regards,

Hans

#3 lore raw
Quoted 70 lines · Hans de Goede

Hi,

Quoted 59 lines · Rafael J. Wysocki
Quoted 49 lines · Hans de Goede

On Bay Trail / Cherry Trail systems with a LID switch, the LID switch is often connect to a gpioint handled by an _IAE event handler. Before this commit such systems would not wake up when opening the lid, requiring the powerbutton to be pressed after opening the lid to wakeup.

Note that Bay Trail / Cherry Trail systems use suspend-to-idle, so the interrupts are generated anyway on those lines on lid switch changes, but they are treated by the IRQ subsystem as spurious while suspended if not marked as wakeup IRQs.

This commit calls enable_irq_wake() for _IAE GpioInts with a valid event handler which have their Wake flag set. This fixes such systems not waking up when opening the lid.

---
Changes in v2:

(quoted diff) +0 -3
-Improve commit msg
-Add Mika's Acked-by
---
 drivers/gpio/gpiolib-acpi.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpio/gpiolib-acpi.c +6 -0
index 8cd3f66..18207b2 100644
@@ -28,6 +28,7 @@ struct acpi_gpio_event {
 	acpi_handle handle;
 	unsigned int pin;
 	unsigned int irq;
+	bool irq_wake_enabled;
 	struct gpio_desc *desc;
 };
 
@@ -266,6 +267,11 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
 		goto fail_free_event;
 	}
 
+	if (agpio->wake_capable == ACPI_WAKE_CAPABLE) {
+		enable_irq_wake(irq);
+		event->irq_wake_enabled = true;
+	}
+
 	list_add_tail(&event->node, &acpi_gpio->events);
 	return AE_OK;
 

drivers/gpio/gpiolib-acpi.c void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) · line 348

Quoted 4 lines
drivers/gpio/gpiolib-acpi.c +1 -0
@@ -339,6 +345,9 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
 	list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) {
 		struct gpio_desc *desc;
 
+		if (event->irq_wake_enabled)

It has just occurred to me that if the event is in the list, the IRQ will be enabled to wake up as long as agpio->wake_capable == ACPI_WAKE_CAPABLE, so it looks like it should be sufficient to check

Quoted 3 lines
	if (agpio->wake_capable == ACPI_WAKE_CAPABLE)

here and the new flag is not necessary. Or is it?

We don't have (readily available) access to the acpi_resource_gpio struct in acpi_gpiochip_free_interrupts, so I'm going to go with Andy's suggestion instead and change the if to:

Quoted 5 lines
                 if (irqd_is_wakeup_set(irq_get_irq_data(event->irq)))
                         disable_irq_wake(event->irq);

Still need to run some quick tests and then I will send v3 with this change.

OK, fair enough.

Thanks,
Rafael

#4 lore raw
In reply to Hans de Goede
Quoted 24 lines · Hans de Goede

On Bay Trail / Cherry Trail systems with a LID switch, the LID switch is
often connect to a gpioint handled by an _IAE event handler. Before this commit such systems would not wake up when opening the lid,
requiring the powerbutton to be pressed after opening the lid to wakeup.

Note that Bay Trail / Cherry Trail systems use suspend-to-idle, so the interrupts are generated anyway on those lines on lid switch changes,
but they are treated by the IRQ subsystem as spurious while suspended if
not marked as wakeup IRQs.

This commit calls enable_irq_wake() for _IAE GpioInts with a valid event handler which have their Wake flag set. This fixes such systems not waking up when opening the lid.

drivers/gpio/gpiolib-acpi.c struct acpi_gpio_event {

Quoted 4 lines
drivers/gpio/gpiolib-acpi.c +2 -0
+	bool irq_wake_enabled;
 
 
+		if (event->irq_wake_enabled)

Same (new) comment as in v1.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#5 lore raw
Quoted 24 lines · Andy Shevchenko
Quoted 22 lines · Hans de Goede

On Bay Trail / Cherry Trail systems with a LID switch, the LID switch is
often connect to a gpioint handled by an _IAE event handler. Before this commit such systems would not wake up when opening the lid,
requiring the powerbutton to be pressed after opening the lid to wakeup.

Note that Bay Trail / Cherry Trail systems use suspend-to-idle, so the interrupts are generated anyway on those lines on lid switch changes,
but they are treated by the IRQ subsystem as spurious while suspended if
not marked as wakeup IRQs.

This commit calls enable_irq_wake() for _IAE GpioInts with a valid event handler which have their Wake flag set. This fixes such systems not waking up when opening the lid.

Quoted 7 lines

drivers/gpio/gpiolib-acpi.c struct acpi_gpio_event {

Quoted 5 lines
drivers/gpio/gpiolib-acpi.c +2 -0
+     bool irq_wake_enabled;
 
 
+             if (event->irq_wake_enabled)

Same (new) comment as in v1.

Why not just check for agpio->wake_capable == ACPI_WAKE_CAPABLE instead as I said?

Thanks,
Rafael

#6 lore raw
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Hans de Goede

+     bool irq_wake_enabled;

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

+             if (event->irq_wake_enabled)

Same (new) comment as in v1.

Why not just check for agpio->wake_capable == ACPI_WAKE_CAPABLE instead as I said?

Ah, yes, it could work as well as far as I can see from the code point of view.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy