* [PATCH 1/1] input: bbnsm_pwrkey: Fix missed key press after suspend
@ 2024-07-12 22:43 Frank Li
2024-07-12 23:04 ` Dmitry Torokhov
0 siblings, 1 reply; 4+ messages in thread
From: Frank Li @ 2024-07-12 22:43 UTC (permalink / raw)
To: Dmitry Torokhov, Jacky Bai, Jason Liu, Peng Fan,
open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
open list
Cc: imx
From: Jacky Bai <ping.bai@nxp.com>
Report input event directly on wakeup to ensure no press event is missed
when resuming from suspend.
Signed-off-by: Jacky Bai <ping.bai@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Acked-by: Jason Liu <jason.hui.liu@nxp.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
drivers/input/misc/nxp-bbnsm-pwrkey.c | 36 +++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/drivers/input/misc/nxp-bbnsm-pwrkey.c b/drivers/input/misc/nxp-bbnsm-pwrkey.c
index 1d99206dd3a8b..9675717ecbdfe 100644
--- a/drivers/input/misc/nxp-bbnsm-pwrkey.c
+++ b/drivers/input/misc/nxp-bbnsm-pwrkey.c
@@ -38,6 +38,7 @@ struct bbnsm_pwrkey {
int irq;
int keycode;
int keystate; /* 1:pressed */
+ bool suspended;
struct timer_list check_timer;
struct input_dev *input;
};
@@ -70,6 +71,7 @@ static irqreturn_t bbnsm_pwrkey_interrupt(int irq, void *dev_id)
{
struct platform_device *pdev = dev_id;
struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev);
+ struct input_dev *input = bbnsm->input;
u32 event;
regmap_read(bbnsm->regmap, BBNSM_EVENTS, &event);
@@ -81,6 +83,16 @@ static irqreturn_t bbnsm_pwrkey_interrupt(int irq, void *dev_id)
mod_timer(&bbnsm->check_timer,
jiffies + msecs_to_jiffies(DEBOUNCE_TIME));
+ /*
+ * Directly report key event after resume to make sure key press
+ * event is never missed.
+ */
+ if (bbnsm->suspended) {
+ bbnsm->keystate = 1;
+ input_event(input, EV_KEY, bbnsm->keycode, 1);
+ input_sync(input);
+ }
+
/* clear PWR OFF */
regmap_write(bbnsm->regmap, BBNSM_EVENTS, BBNSM_BTN_OFF);
@@ -173,6 +185,29 @@ static int bbnsm_pwrkey_probe(struct platform_device *pdev)
return 0;
}
+static int __maybe_unused bbnsm_pwrkey_suspend(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev);
+
+ bbnsm->suspended = true;
+
+ return 0;
+}
+
+static int __maybe_unused bbnsm_pwrkey_resume(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev);
+
+ bbnsm->suspended = false;
+
+ return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(bbnsm_pwrkey_pm_ops, bbnsm_pwrkey_suspend,
+ bbnsm_pwrkey_resume);
+
static const struct of_device_id bbnsm_pwrkey_ids[] = {
{ .compatible = "nxp,imx93-bbnsm-pwrkey" },
{ /* sentinel */ }
@@ -182,6 +217,7 @@ MODULE_DEVICE_TABLE(of, bbnsm_pwrkey_ids);
static struct platform_driver bbnsm_pwrkey_driver = {
.driver = {
.name = "bbnsm_pwrkey",
+ .pm = &bbnsm_pwrkey_pm_ops,
.of_match_table = bbnsm_pwrkey_ids,
},
.probe = bbnsm_pwrkey_probe,
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] input: bbnsm_pwrkey: Fix missed key press after suspend
2024-07-12 22:43 [PATCH 1/1] input: bbnsm_pwrkey: Fix missed key press after suspend Frank Li
@ 2024-07-12 23:04 ` Dmitry Torokhov
2024-07-12 23:17 ` Frank Li
0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2024-07-12 23:04 UTC (permalink / raw)
To: Frank Li
Cc: Jacky Bai, Jason Liu, Peng Fan,
open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
open list, imx
Hi Frank,
On Fri, Jul 12, 2024 at 06:43:51PM -0400, Frank Li wrote:
> From: Jacky Bai <ping.bai@nxp.com>
>
> Report input event directly on wakeup to ensure no press event is missed
> when resuming from suspend.
>
> Signed-off-by: Jacky Bai <ping.bai@nxp.com>
> Reviewed-by: Peng Fan <peng.fan@nxp.com>
> Acked-by: Jason Liu <jason.hui.liu@nxp.com>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
> drivers/input/misc/nxp-bbnsm-pwrkey.c | 36 +++++++++++++++++++++++++++
> 1 file changed, 36 insertions(+)
>
> diff --git a/drivers/input/misc/nxp-bbnsm-pwrkey.c b/drivers/input/misc/nxp-bbnsm-pwrkey.c
> index 1d99206dd3a8b..9675717ecbdfe 100644
> --- a/drivers/input/misc/nxp-bbnsm-pwrkey.c
> +++ b/drivers/input/misc/nxp-bbnsm-pwrkey.c
> @@ -38,6 +38,7 @@ struct bbnsm_pwrkey {
> int irq;
> int keycode;
> int keystate; /* 1:pressed */
> + bool suspended;
> struct timer_list check_timer;
> struct input_dev *input;
> };
> @@ -70,6 +71,7 @@ static irqreturn_t bbnsm_pwrkey_interrupt(int irq, void *dev_id)
> {
> struct platform_device *pdev = dev_id;
> struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev);
> + struct input_dev *input = bbnsm->input;
> u32 event;
>
> regmap_read(bbnsm->regmap, BBNSM_EVENTS, &event);
> @@ -81,6 +83,16 @@ static irqreturn_t bbnsm_pwrkey_interrupt(int irq, void *dev_id)
> mod_timer(&bbnsm->check_timer,
> jiffies + msecs_to_jiffies(DEBOUNCE_TIME));
>
> + /*
> + * Directly report key event after resume to make sure key press
> + * event is never missed.
> + */
How do you know that wakeup was caused by the key press on this device?
As far as I can see the driver requests the interrupt as shared, so we
could end up in bbnsm_pwrkey_interrupt() even if button was not pressed.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] input: bbnsm_pwrkey: Fix missed key press after suspend
2024-07-12 23:04 ` Dmitry Torokhov
@ 2024-07-12 23:17 ` Frank Li
2024-07-13 0:11 ` Dmitry Torokhov
0 siblings, 1 reply; 4+ messages in thread
From: Frank Li @ 2024-07-12 23:17 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Jacky Bai, Jason Liu, Peng Fan,
open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
open list, imx
On Fri, Jul 12, 2024 at 04:04:28PM -0700, Dmitry Torokhov wrote:
> Hi Frank,
>
> On Fri, Jul 12, 2024 at 06:43:51PM -0400, Frank Li wrote:
> > From: Jacky Bai <ping.bai@nxp.com>
> >
> > Report input event directly on wakeup to ensure no press event is missed
> > when resuming from suspend.
> >
> > Signed-off-by: Jacky Bai <ping.bai@nxp.com>
> > Reviewed-by: Peng Fan <peng.fan@nxp.com>
> > Acked-by: Jason Liu <jason.hui.liu@nxp.com>
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > ---
> > drivers/input/misc/nxp-bbnsm-pwrkey.c | 36 +++++++++++++++++++++++++++
> > 1 file changed, 36 insertions(+)
> >
> > diff --git a/drivers/input/misc/nxp-bbnsm-pwrkey.c b/drivers/input/misc/nxp-bbnsm-pwrkey.c
> > index 1d99206dd3a8b..9675717ecbdfe 100644
> > --- a/drivers/input/misc/nxp-bbnsm-pwrkey.c
> > +++ b/drivers/input/misc/nxp-bbnsm-pwrkey.c
> > @@ -38,6 +38,7 @@ struct bbnsm_pwrkey {
> > int irq;
> > int keycode;
> > int keystate; /* 1:pressed */
> > + bool suspended;
> > struct timer_list check_timer;
> > struct input_dev *input;
> > };
> > @@ -70,6 +71,7 @@ static irqreturn_t bbnsm_pwrkey_interrupt(int irq, void *dev_id)
> > {
> > struct platform_device *pdev = dev_id;
> > struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev);
> > + struct input_dev *input = bbnsm->input;
> > u32 event;
> >
> > regmap_read(bbnsm->regmap, BBNSM_EVENTS, &event);
> > @@ -81,6 +83,16 @@ static irqreturn_t bbnsm_pwrkey_interrupt(int irq, void *dev_id)
> > mod_timer(&bbnsm->check_timer,
> > jiffies + msecs_to_jiffies(DEBOUNCE_TIME));
> >
> > + /*
> > + * Directly report key event after resume to make sure key press
> > + * event is never missed.
> > + */
>
> How do you know that wakeup was caused by the key press on this device?
> As far as I can see the driver requests the interrupt as shared, so we
> could end up in bbnsm_pwrkey_interrupt() even if button was not pressed.
>
In bbnsm_pwrky_interrupt()
{ ...
regmap_read(bbnsm->regmap, BBNSM_EVENTS, &event);
if (!(event & BBNSM_BTN_OFF))
return IRQ_NONE;
...
}
If wakeup was not caused by pwr key, irq will do nothing, code will not
reach to here.
Frank
> Thanks.
>
> --
> Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] input: bbnsm_pwrkey: Fix missed key press after suspend
2024-07-12 23:17 ` Frank Li
@ 2024-07-13 0:11 ` Dmitry Torokhov
0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2024-07-13 0:11 UTC (permalink / raw)
To: Frank Li
Cc: Jacky Bai, Jason Liu, Peng Fan,
open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
open list, imx
On Fri, Jul 12, 2024 at 07:17:11PM -0400, Frank Li wrote:
> On Fri, Jul 12, 2024 at 04:04:28PM -0700, Dmitry Torokhov wrote:
> > Hi Frank,
> >
> > On Fri, Jul 12, 2024 at 06:43:51PM -0400, Frank Li wrote:
> > > From: Jacky Bai <ping.bai@nxp.com>
> > >
> > > Report input event directly on wakeup to ensure no press event is missed
> > > when resuming from suspend.
> > >
> > > Signed-off-by: Jacky Bai <ping.bai@nxp.com>
> > > Reviewed-by: Peng Fan <peng.fan@nxp.com>
> > > Acked-by: Jason Liu <jason.hui.liu@nxp.com>
> > > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > > ---
> > > drivers/input/misc/nxp-bbnsm-pwrkey.c | 36 +++++++++++++++++++++++++++
> > > 1 file changed, 36 insertions(+)
> > >
> > > diff --git a/drivers/input/misc/nxp-bbnsm-pwrkey.c b/drivers/input/misc/nxp-bbnsm-pwrkey.c
> > > index 1d99206dd3a8b..9675717ecbdfe 100644
> > > --- a/drivers/input/misc/nxp-bbnsm-pwrkey.c
> > > +++ b/drivers/input/misc/nxp-bbnsm-pwrkey.c
> > > @@ -38,6 +38,7 @@ struct bbnsm_pwrkey {
> > > int irq;
> > > int keycode;
> > > int keystate; /* 1:pressed */
> > > + bool suspended;
> > > struct timer_list check_timer;
> > > struct input_dev *input;
> > > };
> > > @@ -70,6 +71,7 @@ static irqreturn_t bbnsm_pwrkey_interrupt(int irq, void *dev_id)
> > > {
> > > struct platform_device *pdev = dev_id;
> > > struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev);
> > > + struct input_dev *input = bbnsm->input;
> > > u32 event;
> > >
> > > regmap_read(bbnsm->regmap, BBNSM_EVENTS, &event);
> > > @@ -81,6 +83,16 @@ static irqreturn_t bbnsm_pwrkey_interrupt(int irq, void *dev_id)
> > > mod_timer(&bbnsm->check_timer,
> > > jiffies + msecs_to_jiffies(DEBOUNCE_TIME));
> > >
> > > + /*
> > > + * Directly report key event after resume to make sure key press
> > > + * event is never missed.
> > > + */
> >
> > How do you know that wakeup was caused by the key press on this device?
> > As far as I can see the driver requests the interrupt as shared, so we
> > could end up in bbnsm_pwrkey_interrupt() even if button was not pressed.
> >
>
> In bbnsm_pwrky_interrupt()
> { ...
> regmap_read(bbnsm->regmap, BBNSM_EVENTS, &event);
> if (!(event & BBNSM_BTN_OFF))
> return IRQ_NONE;
>
> ...
> }
>
> If wakeup was not caused by pwr key, irq will do nothing, code will not
> reach to here.
OK, so the case you are trying to fix is when interrupt is delayed so
the key is either already released or it will be released by the time
the normal debouncing interval passes?
I think you want to reset ->suspended in the interrupt handler so that
this block fires at most once per suspend/resume cycle. And maybe move
it before calling mod_timer().
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-13 0:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-12 22:43 [PATCH 1/1] input: bbnsm_pwrkey: Fix missed key press after suspend Frank Li
2024-07-12 23:04 ` Dmitry Torokhov
2024-07-12 23:17 ` Frank Li
2024-07-13 0:11 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).