Devicetree
 help / color / mirror / Atom feed
* [PATCH v4 0/2] Input: gpio-keys - support wakeup pinctrl state
@ 2026-10-05 20:47 Kendall Willis
  2026-10-05 20:47 ` [PATCH v4 1/2] dt-bindings: input: gpio-keys: add pinctrl states Kendall Willis
  2026-10-05 20:47 ` [PATCH v4 2/2] Input: gpio-keys - support wakeup pinctrl state on suspend Kendall Willis
  0 siblings, 2 replies; 4+ messages in thread
From: Kendall Willis @ 2026-10-05 20:47 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: msp, s-kochidanadu, a-kaur, s-tripathi1, vishalm, k-willis,
	linux-input, linux-kernel, devicetree

Add 'wakeup' pinctrl state to support separate pin wakeup
configurations for GPIO. Upon suspend the 'wakeup' pinctrl state is
chosen if it exists. On resume the 'default' pinctrl state is selected.
The 'wakeup' pinctrl state allows wakeup from low-power states if a
specific pin configuration is needed.

On TI K3 AM62 family of devices, the GPIO controller is turned off in
suspend to RAM states, so no interrupt can be received by the
controller. This prevents system wakeup from low-power states.
Alternatively, the pins can wakeup the system if a wakeup flag is set on
the pin by using pinctrl.

A corresponding device tree patch using the 'wakeup' pinctrl state can
be found under "arm64: dts: ti: k3-am62l3-evm: add wakeup-source for GPIO
button" [1].

Tested GPIO wakeup from suspend on AM62L EVM and AM62P EVM.

[1] https://lore.kernel.org/all/20260912-upstream-gpio-wakeup-dts-v1-1-2057d76c63aa@ti.com/

Signed-off-by: Kendall Willis <k-willis@ti.com>
---
Changes in v4:
- Propagate all errors but -ENODEV from devm_pinctrl_get() in probe().
- Link to v3: https://lore.kernel.org/r/20261001-upstream-gpio-wakeup-v3-0-6f3bcde367a3@ti.com

Changes in v3:
- Propagate -EPROBE_DEFER from devm_pinctrl_get() in probe().
- Link to v2: https://lore.kernel.org/r/20260925-upstream-gpio-wakeup-v2-0-6c5533356246@ti.com

Changes in v2:
- Update gpio-keys dt bindings commit message for better explanation of
  wakeup state.
- Fix error pathways for if switching to the "wakeup" pinctrl state
  fails.
- Link to v1: https://lore.kernel.org/r/20260912-upstream-gpio-wakeup-v1-0-f0e12484b836@ti.com

---
Kendall Willis (2):
      dt-bindings: input: gpio-keys: add pinctrl states
      Input: gpio-keys - support wakeup pinctrl state on suspend

 .../devicetree/bindings/input/gpio-keys.yaml       | 16 +++++++++++++
 drivers/input/keyboard/gpio_keys.c                 | 26 ++++++++++++++++++++++
 2 files changed, 42 insertions(+)
---
base-commit: 93f51579e7df248780214094418f205253383cc5
change-id: 20260904-upstream-gpio-wakeup-52a54080c948

Best regards,
-- 
Kendall Willis <k-willis@ti.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v4 1/2] dt-bindings: input: gpio-keys: add pinctrl states
  2026-10-05 20:47 [PATCH v4 0/2] Input: gpio-keys - support wakeup pinctrl state Kendall Willis
@ 2026-10-05 20:47 ` Kendall Willis
  2026-10-05 20:47 ` [PATCH v4 2/2] Input: gpio-keys - support wakeup pinctrl state on suspend Kendall Willis
  1 sibling, 0 replies; 4+ messages in thread
From: Kendall Willis @ 2026-10-05 20:47 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: msp, s-kochidanadu, a-kaur, s-tripathi1, vishalm, k-willis,
	linux-input, linux-kernel, devicetree

Document pinctrl properties on the gpio-keys device node. The default
pinctrl state describes the default pin configuration. The wakeup state
configures pins to be able to wakeup the system from suspend if GPIO is a
wakeup source.

The pinctrl sleep state is not defined here despite being used to configure
pins for system suspend to save power. It is not defined since no
gpio-key device tree nodes utilize it. If the sleep state was added, a
device could use both the wakeup state and sleep state. The sleep state
would be entered upon suspend when wakeup is disabled for the device,
whereas the wakeup state would be entered upon suspend if wakeup is enabled
for the device. For now only the wakeup state is defined since it is
used specifically to enable pin configurations that can wakeup the
system from suspend.

Signed-off-by: Kendall Willis <k-willis@ti.com>
---
 Documentation/devicetree/bindings/input/gpio-keys.yaml | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/gpio-keys.yaml b/Documentation/devicetree/bindings/input/gpio-keys.yaml
index cc78c2152921308fe0cad3e29ca78a5fad08f066..a0712fba45845e42ca63489354e0cae87de2143f 100644
--- a/Documentation/devicetree/bindings/input/gpio-keys.yaml
+++ b/Documentation/devicetree/bindings/input/gpio-keys.yaml
@@ -22,6 +22,22 @@ properties:
 
   poll-interval: true
 
+  pinctrl-0:
+    description: Default pinctrl state
+
+  pinctrl-1:
+    description: Wakeup pinctrl state
+
+  pinctrl-names:
+    description:
+      When present should contain at least "default" describing the default pin
+      states. The "wakeup" state describes the pin state used to wakeup the system
+      when wakeup is enabled and the system is suspended.
+    minItems: 1
+    items:
+      - const: default
+      - const: wakeup
+
 patternProperties:
   "^(button|event|key|switch|(button|event|key|switch)-[a-z0-9-]+|[a-z0-9-]+-(button|event|key|switch))$":
     $ref: input.yaml#

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v4 2/2] Input: gpio-keys - support wakeup pinctrl state on suspend
  2026-10-05 20:47 [PATCH v4 0/2] Input: gpio-keys - support wakeup pinctrl state Kendall Willis
  2026-10-05 20:47 ` [PATCH v4 1/2] dt-bindings: input: gpio-keys: add pinctrl states Kendall Willis
@ 2026-10-05 20:47 ` Kendall Willis
  2026-10-05 20:58   ` sashiko-bot
  1 sibling, 1 reply; 4+ messages in thread
From: Kendall Willis @ 2026-10-05 20:47 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: msp, s-kochidanadu, a-kaur, s-tripathi1, vishalm, k-willis,
	linux-input, linux-kernel, devicetree

GPIO can be used as a wakeup source for TI K3 AM62 devices during
suspend to RAM states. The GPIO controller is powered off in these
states, so a wakeup enable flag must be set on the GPIO pin in the
pinctrl in order to allow wakeup.

If the device is wakeup enabled, select the wakeup pinctrl state on
suspend and restore the default pinctrl state on resume.

Signed-off-by: Kendall Willis <k-willis@ti.com>
---
 drivers/input/keyboard/gpio_keys.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 129fc4212a5ed126496b331ce626682d441c53bf..8d3409c6de1ea87ccc118b2d6ba9ffc313caa027 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -28,6 +28,7 @@
 #include <linux/of.h>
 #include <linux/of_irq.h>
 #include <linux/spinlock.h>
+#include <linux/pinctrl/consumer.h>
 #include <dt-bindings/input/gpio-keys.h>
 
 struct gpio_button_data {
@@ -60,6 +61,8 @@ struct gpio_keys_drvdata {
 	struct input_dev *input;
 	struct mutex disable_lock;
 	unsigned short *keymap;
+	struct pinctrl *pinctrl;
+	struct pinctrl_state *pinctrl_wakeup;
 	struct gpio_button_data data[];
 };
 
@@ -884,6 +887,17 @@ static int gpio_keys_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, ddata);
 	input_set_drvdata(input, ddata);
 
+	ddata->pinctrl = devm_pinctrl_get(dev);
+	if (IS_ERR(ddata->pinctrl)) {
+		error = PTR_ERR(ddata->pinctrl);
+		ddata->pinctrl = NULL;
+
+		if (error != -ENODEV)
+			return dev_err_probe(dev, error, "Failed to get pinctrl\n");
+	} else if (ddata->pinctrl) {
+		ddata->pinctrl_wakeup = pinctrl_lookup_state(ddata->pinctrl, "wakeup");
+	}
+
 	input->name = pdata->name ? : pdev->name;
 	input->phys = "gpio-keys/input0";
 	input->dev.parent = dev;
@@ -1010,6 +1024,12 @@ gpio_keys_enable_wakeup(struct gpio_keys_drvdata *ddata)
 	int error;
 	int i;
 
+	if (!IS_ERR_OR_NULL(ddata->pinctrl_wakeup)) {
+		error = pinctrl_select_state(ddata->pinctrl, ddata->pinctrl_wakeup);
+		if (error)
+			return error;
+	}
+
 	for (i = 0; i < ddata->pdata->nbuttons; i++) {
 		bdata = &ddata->data[i];
 		if (bdata->button->wakeup) {
@@ -1023,6 +1043,9 @@ gpio_keys_enable_wakeup(struct gpio_keys_drvdata *ddata)
 	return 0;
 
 err_out:
+	if (!IS_ERR_OR_NULL(ddata->pinctrl_wakeup))
+		pinctrl_pm_select_default_state(ddata->input->dev.parent);
+
 	while (i--) {
 		bdata = &ddata->data[i];
 		if (bdata->button->wakeup)
@@ -1039,6 +1062,9 @@ gpio_keys_disable_wakeup(struct gpio_keys_drvdata *ddata)
 	struct gpio_button_data *bdata;
 	int i;
 
+	if (!IS_ERR_OR_NULL(ddata->pinctrl_wakeup))
+		pinctrl_pm_select_default_state(ddata->input->dev.parent);
+
 	for (i = 0; i < ddata->pdata->nbuttons; i++) {
 		bdata = &ddata->data[i];
 		bdata->suspended = false;

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 2/2] Input: gpio-keys - support wakeup pinctrl state on suspend
  2026-10-05 20:47 ` [PATCH v4 2/2] Input: gpio-keys - support wakeup pinctrl state on suspend Kendall Willis
@ 2026-10-05 20:58   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-10-05 20:58 UTC (permalink / raw)
  To: Kendall Willis; +Cc: conor+dt, devicetree, dmitry.torokhov, robh, linux-input

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] input: spurious key press on resume due to LIFO violation in pinctrl teardown
--

commit 77748a917235cbadd6477449603ad11920308ecf
Author: Kendall Willis <k-willis@ti.com>

Input: gpio-keys - support wakeup pinctrl state on suspend

This commit adds support for selecting a wakeup pinctrl state on suspend and
restoring the default state on resume for GPIO devices. This enables wakeup
support on certain platforms where the GPIO controller is powered down during
suspend.

> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index e196174856796..b8ecaaded6a44 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
[ ... ]
> @@ -1022,6 +1042,9 @@ gpio_keys_enable_wakeup(struct gpio_keys_drvdata *ddata)
>  	return 0;
>  
>  err_out:
> +	if (!IS_ERR_OR_NULL(ddata->pinctrl_wakeup))
> +		pinctrl_pm_select_default_state(ddata->input->dev.parent);
> +
[Severity: Medium]
Could this error path in gpio_keys_enable_wakeup() in
drivers/input/keyboard/gpio_keys.c trigger a spurious IRQ?

The default pinctrl state is restored before the successfully configured
wakeup IRQs are disabled. If switching the pinctrl state causes a glitch
on the GPIO line, an IRQ might fire prematurely.

>  	while (i--) {
>  		bdata = &ddata->data[i];
>  		if (bdata->button->wakeup)
> @@ -1038,6 +1061,9 @@ gpio_keys_disable_wakeup(struct gpio_keys_drvdata *ddata)
>  	struct gpio_button_data *bdata;
>  	int i;
>  
> +	if (!IS_ERR_OR_NULL(ddata->pinctrl_wakeup))
> +		pinctrl_pm_select_default_state(ddata->input->dev.parent);
> +
[Severity: Medium]
Can this ordering in gpio_keys_disable_wakeup() in
drivers/input/keyboard/gpio_keys.c inject a spurious key press on system
resume?

On resume, gpio_keys_disable_wakeup() restores the default pinctrl state
before disabling the wakeup IRQs and clearing bdata->suspended. If the
pinctrl state transition causes a line glitch, the IRQ fires while
bdata->suspended is still true.

The IRQ handler then sees bdata->suspended is true and explicitly
simulates a key press to handle transient wakeup events. If this key is
mapped to a power or sleep button, it might cause the system to immediately
re-suspend or power off.

Should the default pinctrl state be restored after disabling the IRQs and
clearing the suspended state to maintain a strict LIFO teardown order?

>  	for (i = 0; i < ddata->pdata->nbuttons; i++) {
>  		bdata = &ddata->data[i];
>  		bdata->suspended = false;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261005-upstream-gpio-wakeup-v4-1-96f092de4690@ti.com?part=2

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-05 20:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-05 20:47 [PATCH v4 0/2] Input: gpio-keys - support wakeup pinctrl state Kendall Willis
2026-10-05 20:47 ` [PATCH v4 1/2] dt-bindings: input: gpio-keys: add pinctrl states Kendall Willis
2026-10-05 20:47 ` [PATCH v4 2/2] Input: gpio-keys - support wakeup pinctrl state on suspend Kendall Willis
2026-10-05 20:58   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox