From 116087d9db1502de054fb0453fdb002c0562019d Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Mon, 13 Jul 2026 22:39:37 -0700 Subject: [PATCH] Input: samsung-keypad - clean up wakeup configuration logic When checking if the device can wake the system, we should pull the device_may_wakeup() check to the caller instead of repeating it inside the toggle_wakeup() handler. Furthermore, when configuring the wakeup, we should safely ensure we write to the registers in the correct order: configure the interrupt receiver before enabling the peripheral's wake functionality, and vice-versa. Assisted-by: Antigravity:gemini-3.1-pro Link: https://patch.msgid.link/20260713-samsung-kp-irq-v2-1-acc84b6daf9a@gmail.com Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/samsung-keypad.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c index 17127269e3f0..a578f429d100 100644 --- a/drivers/input/keyboard/samsung-keypad.c +++ b/drivers/input/keyboard/samsung-keypad.c @@ -492,15 +492,14 @@ static void samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad, val = readl(keypad->base + SAMSUNG_KEYIFCON); if (enable) { + enable_irq_wake(keypad->irq); val |= SAMSUNG_KEYIFCON_WAKEUPEN; - if (device_may_wakeup(&keypad->pdev->dev)) - enable_irq_wake(keypad->irq); + writel(val, keypad->base + SAMSUNG_KEYIFCON); } else { val &= ~SAMSUNG_KEYIFCON_WAKEUPEN; - if (device_may_wakeup(&keypad->pdev->dev)) - disable_irq_wake(keypad->irq); + writel(val, keypad->base + SAMSUNG_KEYIFCON); + disable_irq_wake(keypad->irq); } - writel(val, keypad->base + SAMSUNG_KEYIFCON); clk_disable(keypad->clk); } @@ -516,7 +515,8 @@ static int samsung_keypad_suspend(struct device *dev) if (input_device_enabled(input_dev)) samsung_keypad_stop(keypad); - samsung_keypad_toggle_wakeup(keypad, true); + if (device_may_wakeup(dev)) + samsung_keypad_toggle_wakeup(keypad, true); return 0; } @@ -529,7 +529,8 @@ static int samsung_keypad_resume(struct device *dev) guard(mutex)(&input_dev->mutex); - samsung_keypad_toggle_wakeup(keypad, false); + if (device_may_wakeup(dev)) + samsung_keypad_toggle_wakeup(keypad, false); if (input_device_enabled(input_dev)) samsung_keypad_start(keypad);