diff mbox series

pinctrl: amd: Mask wake bits on probe again

Message ID 20230818144850.1439-1-mario.limonciello@amd.com
State Accepted
Commit 6bc3462a0f5ecaa376a0b3d76dafc55796799e17
Headers show
Series pinctrl: amd: Mask wake bits on probe again | expand

Commit Message

Mario Limonciello Aug. 18, 2023, 2:48 p.m. UTC
Shubhra reports that their laptop is heating up over s2idle. Even though
it's getting into the deepest state, it appears to be having spurious
wakeup events.

While debugging a tangential issue with the RTC Carsten reports that recent
6.1.y based kernel face a similar problem.

Looking at acpidump and GPIO register comparisons these spurious wakeup
events are from the GPIO associated with the I2C touchpad on both laptops
and occur even when the touchpad is not marked as a wake source by the
kernel.

This means that the boot firmware has programmed these bits and because
Linux didn't touch them lead to spurious wakeup events from that GPIO.

To fix this issue, restore most of the code that previously would clear all
the bits associated with wakeup sources. This will allow the kernel to only
program the wake up sources that are necessary.

This is similar to what was done previously; but only the wake bits are
cleared by default instead of interrupts and wake bits.  If any other
problems are reported then it may make sense to clear interrupts again too.

Cc: Sachi King <nakato@nakato.io>
Cc: stable@vger.kernel.org
Cc: Thorsten Leemhuis <regressions@leemhuis.info>
Fixes: 65f6c7c91cb2 ("pinctrl: amd: Revert "pinctrl: amd: disable and mask interrupts on probe"")
Reported-by: "Shubhra Prakash Nandi" <email2shubhra@gmail.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217754
Reported-by: "Carsten Hatger" <xmb8dsv4@gmail.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217626#c28
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/pinctrl/pinctrl-amd.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Comments

Linus Walleij Aug. 21, 2023, 10:29 a.m. UTC | #1
On Fri, Aug 18, 2023 at 4:49 PM Mario Limonciello
<mario.limonciello@amd.com> wrote:

> Shubhra reports that their laptop is heating up over s2idle. Even though
> it's getting into the deepest state, it appears to be having spurious
> wakeup events.
>
> While debugging a tangential issue with the RTC Carsten reports that recent
> 6.1.y based kernel face a similar problem.
>
> Looking at acpidump and GPIO register comparisons these spurious wakeup
> events are from the GPIO associated with the I2C touchpad on both laptops
> and occur even when the touchpad is not marked as a wake source by the
> kernel.
>
> This means that the boot firmware has programmed these bits and because
> Linux didn't touch them lead to spurious wakeup events from that GPIO.
>
> To fix this issue, restore most of the code that previously would clear all
> the bits associated with wakeup sources. This will allow the kernel to only
> program the wake up sources that are necessary.
>
> This is similar to what was done previously; but only the wake bits are
> cleared by default instead of interrupts and wake bits.  If any other
> problems are reported then it may make sense to clear interrupts again too.
>
> Cc: Sachi King <nakato@nakato.io>
> Cc: stable@vger.kernel.org
> Cc: Thorsten Leemhuis <regressions@leemhuis.info>
> Fixes: 65f6c7c91cb2 ("pinctrl: amd: Revert "pinctrl: amd: disable and mask interrupts on probe"")
> Reported-by: "Shubhra Prakash Nandi" <email2shubhra@gmail.com>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217754
> Reported-by: "Carsten Hatger" <xmb8dsv4@gmail.com>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=217626#c28
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>

Patch applied for fixes so we get some rotation in linux-next.

Thanks for looking into this Mario!

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index 20bd97a603d9c..74241b2ff21e3 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -862,6 +862,33 @@  static const struct pinconf_ops amd_pinconf_ops = {
 	.pin_config_group_set = amd_pinconf_group_set,
 };
 
+static void amd_gpio_irq_init(struct amd_gpio *gpio_dev)
+{
+	struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
+	unsigned long flags;
+	u32 pin_reg, mask;
+	int i;
+
+	mask = BIT(WAKE_CNTRL_OFF_S0I3) | BIT(WAKE_CNTRL_OFF_S3) |
+		BIT(WAKE_CNTRL_OFF_S4);
+
+	for (i = 0; i < desc->npins; i++) {
+		int pin = desc->pins[i].number;
+		const struct pin_desc *pd = pin_desc_get(gpio_dev->pctrl, pin);
+
+		if (!pd)
+			continue;
+
+		raw_spin_lock_irqsave(&gpio_dev->lock, flags);
+
+		pin_reg = readl(gpio_dev->base + pin * 4);
+		pin_reg &= ~mask;
+		writel(pin_reg, gpio_dev->base + pin * 4);
+
+		raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
+	}
+}
+
 #ifdef CONFIG_PM_SLEEP
 static bool amd_gpio_should_save(struct amd_gpio *gpio_dev, unsigned int pin)
 {
@@ -1099,6 +1126,9 @@  static int amd_gpio_probe(struct platform_device *pdev)
 		return PTR_ERR(gpio_dev->pctrl);
 	}
 
+	/* Disable and mask interrupts */
+	amd_gpio_irq_init(gpio_dev);
+
 	girq = &gpio_dev->gc.irq;
 	gpio_irq_chip_set_chip(girq, &amd_gpio_irqchip);
 	/* This will let us handle the parent IRQ in the driver */