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
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
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);
--
2.55.0.795.g602f6c329a-goog