Skip to contentSkip to conversation

ACPI: Add stubs for wakeup handler functions

PATCH Superseded Mario Limonciello 3 participants 5 messages Oct 26, 2021 – Oct 27, 2021

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 ACPI: Add stubs for wakeup handler functions

The commit ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()") added new functions for drivers to use during the s2idle wakeup path, but didn't add stubs for when CONFIG_ACPI wasn't set.

Add those stubs in for other drivers to be able to use.

Fixes ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()")

---
Changes from v3->v4:
* Reword commit message
* Adjust whitespace
* Return -ENXIO instead of -EINVAL

 include/linux/acpi.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/linux/acpi.h +9 -0
index 72e4f7fd268c..e29b4c1da377 100644
@@ -976,6 +976,15 @@ static inline int acpi_get_local_address(acpi_handle handle, u32 *addr)
 	return -ENODEV;
 }
 
+static inline int acpi_register_wakeup_handler(int wake_irq,
+	bool (*wakeup)(void *context), void *context)
+{
+	return -ENXIO;
+}
+
+static inline void acpi_unregister_wakeup_handler(
+	bool (*wakeup)(void *context), void *context) { }
+
 #endif	/* !CONFIG_ACPI */
 
 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 2/2 pinctrl: amd: Fix wakeups when IRQ is shared with SCI

On some Lenovo AMD Gen2 platforms the IRQ for the SCI and pinctrl drivers are shared. Due to how the s2idle loop handling works, this case needs an extra explicit check whether the interrupt was caused by SCI or by the GPIO controller.

To fix this rework the existing IRQ handler function to function as a checker and an IRQ handler depending on the calling arguments.

---
Note:
This is *possibly* a fix from fdde0ff8590b, 56b991849009 or other changes in the acpi_s2idle_wake handling, but AMD didn't support s2idle across the kernel widely until 5.14 or later. This is the reason for lack of a fixes tag.
Changes from v3->v4:
* Adjust to reverse xmas for newly added variable
* Add a debugging line to show the values in the register that caused system wake to allow for debugging of spurious wakeups
Changes from v2->v3:
* Add new precursor patch for fixing missing ACPI function stubs
* Add __maybe_unused for unused function when set with COMPILE_TEST
Changes from v1->v2:
* drop Kconfig changes to drop COMPILE_TEST, instead #ifdef CONFIG_ACPI
* fix a logic error during wakeup
* Use IRQ_RETVAL()

 drivers/pinctrl/pinctrl-amd.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)
drivers/pinctrl/pinctrl-amd.c +28 -3
index d19974aceb2e..f15d6435a4c9 100644
@@ -598,14 +598,14 @@ static struct irq_chip amd_gpio_irqchip = {
 
 #define PIN_IRQ_PENDING	(BIT(INTERRUPT_STS_OFF) | BIT(WAKE_STS_OFF))
 
-static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)
+static bool _amd_gpio_irq_handler(int irq, void *dev_id)
 {
 	struct amd_gpio *gpio_dev = dev_id;
 	struct gpio_chip *gc = &gpio_dev->gc;
-	irqreturn_t ret = IRQ_NONE;
 	unsigned int i, irqnr;
 	unsigned long flags;
 	u32 __iomem *regs;
+	bool ret = false;
 	u32  regval;
 	u64 status, mask;
 
@@ -627,6 +627,16 @@ static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)
 		/* Each status bit covers four pins */
 		for (i = 0; i < 4; i++) {
 			regval = readl(regs + i);
+			/* called from resume context on a shared IRQ, just
+			 * checking wake source.
+			 */
+			if (irq < 0 && (regval & BIT(WAKE_STS_OFF))) {
+				dev_dbg(&gpio_dev->pdev->dev,
+					"Waking due to GPIO register 0x%p: 0x%x",
+					regs + i, regval);
+				return true;
+			}
+
 			if (!(regval & PIN_IRQ_PENDING) ||
 			    !(regval & BIT(INTERRUPT_MASK_OFF)))
 				continue;
@@ -652,9 +662,12 @@ static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)
 			}
 			writel(regval, regs + i);
 			raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
-			ret = IRQ_HANDLED;
+			ret = true;
 		}
 	}
+	/* called from resume context on shared IRQ but didn't cause wake */
+	if (irq < 0)
+		return false;
 
 	/* Signal EOI to the GPIO unit */
 	raw_spin_lock_irqsave(&gpio_dev->lock, flags);
@@ -666,6 +679,16 @@ static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)
 	return ret;
 }
 
+static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)
+{
+	return IRQ_RETVAL(_amd_gpio_irq_handler(irq, dev_id));
+}
+
+static bool __maybe_unused amd_gpio_check_wake(void *dev_id)
+{
+	return _amd_gpio_irq_handler(-1, dev_id);
+}
+
 static int amd_get_groups_count(struct pinctrl_dev *pctldev)
 {
 	struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
@@ -1004,6 +1027,7 @@ static int amd_gpio_probe(struct platform_device *pdev)
 		goto out2;
 
 	platform_set_drvdata(pdev, gpio_dev);
+	acpi_register_wakeup_handler(gpio_dev->irq, amd_gpio_check_wake, gpio_dev);
 
 	dev_dbg(&pdev->dev, "amd gpio driver loaded\n");
 	return ret;
@@ -1021,6 +1045,7 @@ static int amd_gpio_remove(struct platform_device *pdev)
 	gpio_dev = platform_get_drvdata(pdev);
 
 	gpiochip_remove(&gpio_dev->gc);
+	acpi_unregister_wakeup_handler(amd_gpio_check_wake, gpio_dev);
 
 	return 0;
 }
Signature · 1 line
2.25.1
#2 lore raw
In reply to Mario Limonciello
Quoted 8 lines · Mario Limonciello

The commit ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()") added new functions for drivers to use during the s2idle wakeup path, but didn't add stubs for when CONFIG_ACPI wasn't set.

Add those stubs in for other drivers to be able to use.

Fixes ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()")

I need an ACK from an ACPI maintainer to take this with the other fix into the pinctrl tree.

Alternatively both can be merged into the ACPI tree.

Should these two patches be tagged for stable?

Yours,
Linus Walleij

#3 lore raw

[Public]

Quoted 13 lines
Quoted 1 line · Mario Limonciello

The commit ddfd9dcf270c ("ACPI: PM: Add

acpi_[un]register_wakeup_handler()")

Quoted 7 lines

added new functions for drivers to use during the s2idle wakeup path, but didn't add stubs for when CONFIG_ACPI wasn't set.

Add those stubs in for other drivers to be able to use.

Fixes ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()")
Quoted 7 lines

I need an ACK from an ACPI maintainer to take this with the other fix into the pinctrl tree.

Alternatively both can be merged into the ACPI tree.

Should these two patches be tagged for stable?

Yes; I think they should be tagged to stable, but only if these come too:

acd47b9f28e55b505aedb842131b40904e151d7c
7e6f8d6f4a42ef9b693ff1b49267c546931d4619

maintainer Acked-by
#4 lore raw
In reply to Linus Walleij
Quoted 8 lines · Linus Walleij
Quoted 4 lines · Mario Limonciello

The commit ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()") added new functions for drivers to use during the s2idle wakeup path, but didn't add stubs for when CONFIG_ACPI wasn't set.

Quoted 7 lines
Quoted 4 lines

Add those stubs in for other drivers to be able to use.

Fixes ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()")

I need an ACK from an ACPI maintainer to take this with the other fix into the pinctrl tree.

There you are: