Skip to contentSkip to conversation

pinctrl: amd: Clear GPIO debounce for suspend

PATCH Superseded Mario Limonciello 2 participants 3 messages Jun 26, 2025 – Jun 27, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: amd: Clear GPIO debounce for suspend

From: Mario Limonciello <[email protected]>

soc-button-array hardcodes a debounce value by means of gpio_keys which uses pinctrl-amd as a backend to program debounce for a GPIO.

This hardcoded value doesn't match what the firmware intended to be programmed in _AEI. The hardcoded debounce leads to problems waking from suspend. There isn't appetite to conditionalize the behavior in soc-button-array or gpio-keys so clear it when the system suspends to avoid problems with being able to resume.

---
 drivers/pinctrl/pinctrl-amd.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/pinctrl/pinctrl-amd.c +7 -0
index 5cf3db6d78b79..4276bbe77e0e9 100644
@@ -979,6 +979,13 @@ static int amd_gpio_suspend_hibernate_common(struct device *dev, bool is_suspend
 				  pin, is_suspend ? "suspend" : "hibernate");
 		}
 
+		/* clear debounce */
+		if (gpio_dev->saved_regs[i] & (DB_CNTRl_MASK << DB_CNTRL_OFF)) {
+			amd_gpio_set_debounce(gpio_dev, pin, 0);
+			pm_pr_dbg("Clearing debounce for GPIO #%d during %s.\n",
+				  pin, is_suspend ? "suspend" : "hibernate");
+		}
+
 		raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
 	}
 
Signature · 1 line
2.43.0
#1 lore raw

Hi Mario,

Quoted 10 lines · Mario Limonciello

From: Mario Limonciello <[email protected]>

soc-button-array hardcodes a debounce value by means of gpio_keys which uses pinctrl-amd as a backend to program debounce for a GPIO.

This hardcoded value doesn't match what the firmware intended to be programmed in _AEI. The hardcoded debounce leads to problems waking from suspend. There isn't appetite to conditionalize the behavior in soc-button-array or gpio-keys so clear it when the system suspends to avoid problems with being able to resume.

Nice I do think this is a better solution then disabling hw-debounce in soc-button-array as we did before.

Quoted 15 lines
---
 drivers/pinctrl/pinctrl-amd.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/pinctrl/pinctrl-amd.c +0 -0
index 5cf3db6d78b79..4276bbe77e0e9 100644

drivers/pinctrl/pinctrl-amd.c static int amd_gpio_suspend_hibernate_common(struct device *dev, bool is_suspend · line 988

Quoted 10 lines
drivers/pinctrl/pinctrl-amd.c +7 -0
@@ -979,6 +979,13 @@ static int amd_gpio_suspend_hibernate_common(struct device *dev, bool is_suspend
 				  pin, is_suspend ? "suspend" : "hibernate");
 		}
 
+		/* clear debounce */
+		if (gpio_dev->saved_regs[i] & (DB_CNTRl_MASK << DB_CNTRL_OFF)) {
+			amd_gpio_set_debounce(gpio_dev, pin, 0);
+			pm_pr_dbg("Clearing debounce for GPIO #%d during %s.\n",
+				  pin, is_suspend ? "suspend" : "hibernate");
+		}
+

I notice that the if () { } block above this checks if a pin is not configured to be a wakeup src. Since we only need this for wakeup sources maybe put this in an else block of the if () { } block above this ?

I've not strong preference for doing this change, just something which I noticed while looking at the code.

Either way this should probably have a comment on why the clearing is done here.

Regards,

Hans

Quoted 3 lines
drivers/pinctrl/pinctrl-amd.c +0 -0
 		raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
 	}
 
#2 lore raw
Quoted 8 lines · Hans de Goede

Hi Mario,

Quoted 5 lines · Mario Limonciello

From: Mario Limonciello <[email protected]>

soc-button-array hardcodes a debounce value by means of gpio_keys which uses pinctrl-amd as a backend to program debounce for a GPIO.

Quoted 8 lines
Quoted 5 lines

This hardcoded value doesn't match what the firmware intended to be programmed in _AEI. The hardcoded debounce leads to problems waking from suspend. There isn't appetite to conditionalize the behavior in soc-button-array or gpio-keys so clear it when the system suspends to avoid problems with being able to resume.

Nice I do think this is a better solution then disabling hw-debounce in soc-button-array as we did before.

Although it helps this issue and should be harmless I intend to land it I do want to note we still have a difference in behavior for Windows and Linux in that Windows never programs the hardware debounce for the ACPI0011 device.

I think we should still consider a way to keep compatibility of behavior (my previous v3 3/4 seemed to do that just fine).

Quoted 32 lines
Quoted 16 lines
---
  drivers/pinctrl/pinctrl-amd.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/pinctrl/pinctrl-amd.c +0 -0
index 5cf3db6d78b79..4276bbe77e0e9 100644

drivers/pinctrl/pinctrl-amd.c static int amd_gpio_suspend_hibernate_common(struct device *dev, bool is_suspend · line 988

Quoted 10 lines
drivers/pinctrl/pinctrl-amd.c +7 -0
@@ -979,6 +979,13 @@ static int amd_gpio_suspend_hibernate_common(struct device *dev, bool is_suspend
  				  pin, is_suspend ? "suspend" : "hibernate");
  		}
 
+		/* clear debounce */
+		if (gpio_dev->saved_regs[i] & (DB_CNTRl_MASK << DB_CNTRL_OFF)) {
+			amd_gpio_set_debounce(gpio_dev, pin, 0);
+			pm_pr_dbg("Clearing debounce for GPIO #%d during %s.\n",
+				  pin, is_suspend ? "suspend" : "hibernate");
+		}
+

I notice that the if () { } block above this checks if a pin is not configured to be a wakeup src. Since we only need this for wakeup sources maybe put this in an else block of the if () { } block above this ?

Quoted 4 lines

I've not strong preference for doing this change, just something which I noticed while looking at the code.

Either way this should probably have a comment on why the clearing is done here.

I'll respin with an updated comment. I would rather keep the blocks separate so it's clearer in debug logs when multiple workarounds are enacted.

Quoted 11 lines

Regards,

Hans

Quoted 3 lines
drivers/pinctrl/pinctrl-amd.c +0 -0
  		raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
  	}