[PATCH 2/3] pinctrl: amd: Add a module parameter to configure power button behavior

From: Mario Limonciello
Date: Tue Aug 29 2023 - 15:14:29 EST


On pinctrl-amd supported systems there is a bit in the GPIO controller
register that controls the debounce behavior. The traditional debounce
behavior is configured by software, whereas the 'WinBlue' debounce behavior
is handled internally in the GPIO controller and conforms to Microsoft
requirements.

For any users that find this behavior not desirable, add a module parameter
to force the traditional debounce behavior.

Signed-off-by: Mario Limonciello <mario.limonciello@xxxxxxx>
---
drivers/pinctrl/pinctrl-amd.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index 37d64fa55b66..a2468a988be3 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -36,6 +36,11 @@
#include "pinctrl-utils.h"
#include "pinctrl-amd.h"

+static int powerbtn = -1;
+module_param(powerbtn, int, 0444);
+MODULE_PARM_DESC(powerbtn,
+ "Power button debouncing: 0=traditional, 1=windows, -1=auto");
+
static int amd_gpio_get_direction(struct gpio_chip *gc, unsigned offset)
{
unsigned long flags;
@@ -1075,6 +1080,30 @@ static void amd_get_iomux_res(struct amd_gpio *gpio_dev)
desc->pmxops = NULL;
}

+static void handle_powerbtn(struct amd_gpio *gpio_dev)
+{
+ u32 pin_reg;
+
+ if (powerbtn == -1)
+ return;
+
+ pin_reg = readl(gpio_dev->base + WAKE_INT_MASTER_REG);
+ switch (powerbtn) {
+ case 0:
+ pin_reg &= ~INTERNAL_GPIO0_DEBOUNCE;
+ break;
+ case 1:
+ pin_reg |= INTERNAL_GPIO0_DEBOUNCE;
+ break;
+ default:
+ dev_err(&gpio_dev->pdev->dev, "Invalid module parameter %d\n",
+ powerbtn);
+ return;
+ }
+
+ writel(pin_reg, gpio_dev->base + WAKE_INT_MASTER_REG);
+}
+
static int amd_gpio_probe(struct platform_device *pdev)
{
int ret = 0;
@@ -1095,6 +1124,8 @@ static int amd_gpio_probe(struct platform_device *pdev)
return PTR_ERR(gpio_dev->base);
}

+ handle_powerbtn(gpio_dev);
+
gpio_dev->irq = platform_get_irq(pdev, 0);
if (gpio_dev->irq < 0)
return gpio_dev->irq;
--
2.34.1