Input: imx_keypad - make sure keyboard can always wake up system
authorAnson Huang <anson.huang@nxp.com>
Wed, 12 Jun 2019 00:50:44 +0000 (17:50 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 21 Jul 2019 07:04:23 +0000 (09:04 +0200)
[ Upstream commit ce9a53eb3dbca89e7ad86673d94ab886e9bea704 ]

There are several scenarios that keyboard can NOT wake up system
from suspend, e.g., if a keyboard is depressed between system
device suspend phase and device noirq suspend phase, the keyboard
ISR will be called and both keyboard depress and release interrupts
will be disabled, then keyboard will no longer be able to wake up
system. Another scenario would be, if a keyboard is kept depressed,
and then system goes into suspend, the expected behavior would be
when keyboard is released, system will be waked up, but current
implementation can NOT achieve that, because both depress and release
interrupts are disabled in ISR, and the event check is still in
progress.

To fix these issues, need to make sure keyboard's depress or release
interrupt is enabled after noirq device suspend phase, this patch
moves the suspend/resume callback to noirq suspend/resume phase, and
enable the corresponding interrupt according to current keyboard status.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/input/keyboard/imx_keypad.c

index 2165f3dd328babc2285a0e98e5bcf06fc423b983..842c0235471d482f60eeafc33ac033884375171b 100644 (file)
@@ -530,11 +530,12 @@ static int imx_keypad_probe(struct platform_device *pdev)
        return 0;
 }
 
-static int __maybe_unused imx_kbd_suspend(struct device *dev)
+static int __maybe_unused imx_kbd_noirq_suspend(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct imx_keypad *kbd = platform_get_drvdata(pdev);
        struct input_dev *input_dev = kbd->input_dev;
+       unsigned short reg_val = readw(kbd->mmio_base + KPSR);
 
        /* imx kbd can wake up system even clock is disabled */
        mutex_lock(&input_dev->mutex);
@@ -544,13 +545,20 @@ static int __maybe_unused imx_kbd_suspend(struct device *dev)
 
        mutex_unlock(&input_dev->mutex);
 
-       if (device_may_wakeup(&pdev->dev))
+       if (device_may_wakeup(&pdev->dev)) {
+               if (reg_val & KBD_STAT_KPKD)
+                       reg_val |= KBD_STAT_KRIE;
+               if (reg_val & KBD_STAT_KPKR)
+                       reg_val |= KBD_STAT_KDIE;
+               writew(reg_val, kbd->mmio_base + KPSR);
+
                enable_irq_wake(kbd->irq);
+       }
 
        return 0;
 }
 
-static int __maybe_unused imx_kbd_resume(struct device *dev)
+static int __maybe_unused imx_kbd_noirq_resume(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct imx_keypad *kbd = platform_get_drvdata(pdev);
@@ -574,7 +582,9 @@ err_clk:
        return ret;
 }
 
-static SIMPLE_DEV_PM_OPS(imx_kbd_pm_ops, imx_kbd_suspend, imx_kbd_resume);
+static const struct dev_pm_ops imx_kbd_pm_ops = {
+       SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(imx_kbd_noirq_suspend, imx_kbd_noirq_resume)
+};
 
 static struct platform_driver imx_keypad_driver = {
        .driver         = {