diff mbox series

[2/2] input: keyboard: snvs_pwrkey: Fix missed key press after suspend

Message ID 20240716205612.1502608-2-Frank.Li@nxp.com
State New
Headers show
Series [v2,1/1] input: bbnsm_pwrkey: Fix missed key press after suspend | expand

Commit Message

Frank Li July 16, 2024, 8:56 p.m. UTC
Report input event directly on wakeup to ensure no press event is missed
when resuming from suspend.

Fixes: d3dc6e232215 ("input: keyboard: imx: add snvs power key driver")
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Joy Zou <joy.zou@nxp.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/input/keyboard/snvs_pwrkey.c | 37 ++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
diff mbox series

Patch

diff --git a/drivers/input/keyboard/snvs_pwrkey.c b/drivers/input/keyboard/snvs_pwrkey.c
index b352148a0cfb2..a1c04fe8fe05c 100644
--- a/drivers/input/keyboard/snvs_pwrkey.c
+++ b/drivers/input/keyboard/snvs_pwrkey.c
@@ -37,6 +37,7 @@  struct pwrkey_drv_data {
 	int keycode;
 	int keystate;  /* 1:pressed */
 	int wakeup;
+	bool suspended;
 	struct clk *clk;
 	struct timer_list check_timer;
 	struct input_dev *input;
@@ -79,6 +80,18 @@  static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)
 
 	pm_wakeup_event(input->dev.parent, 0);
 
+	/*
+	 * Directly report press event in interrupt handler after suspend
+	 * to ensure no press event miss.
+	 */
+	if (pdata->suspended) {
+		pdata->keystate = 1;
+		input_event(input, EV_KEY, pdata->keycode, 1);
+		input_sync(input);
+		/* Fire at most once per suspend/resume cycle */
+		pdata->suspended = false;
+	}
+
 	regmap_read(pdata->snvs, SNVS_LPSR_REG, &lp_status);
 	if (lp_status & SNVS_LPSR_SPO) {
 		if (pdata->minor_rev == 0) {
@@ -236,6 +249,29 @@  static int imx_snvs_pwrkey_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static int __maybe_unused imx_snvs_pwrkey_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev);
+
+	pdata->suspended = true;
+
+	return 0;
+}
+
+static int __maybe_unused imx_snvs_pwrkey_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev);
+
+	pdata->suspended = false;
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(imx_snvs_pwrkey_pm_ops, imx_snvs_pwrkey_suspend,
+				imx_snvs_pwrkey_resume);
+
 static const struct of_device_id imx_snvs_pwrkey_ids[] = {
 	{ .compatible = "fsl,sec-v4.0-pwrkey" },
 	{ /* sentinel */ }
@@ -245,6 +281,7 @@  MODULE_DEVICE_TABLE(of, imx_snvs_pwrkey_ids);
 static struct platform_driver imx_snvs_pwrkey_driver = {
 	.driver = {
 		.name = "snvs_pwrkey",
+		.pm = &imx_snvs_pwrkey_pm_ops,
 		.of_match_table = imx_snvs_pwrkey_ids,
 	},
 	.probe = imx_snvs_pwrkey_probe,