diff mbox series

[v2] Input: elantech - fix touchpad state on resume for Lenovo N24

Message ID 20240503155020.v2.1.Ifa0e25ebf968d8f307f58d678036944141ab17e6@changeid (mailing list archive)
State New
Headers show
Series [v2] Input: elantech - fix touchpad state on resume for Lenovo N24 | expand

Commit Message

Jonathan Denose May 3, 2024, 4:12 p.m. UTC
The Lenovo N24 on resume becomes stuck in a state where it
sends incorrect packets, causing elantech_packet_check_v4 to fail.
The only way for the device to resume sending the correct packets is for
it to be disabled and then re-enabled.

This change adds a dmi check to trigger this behavior on resume.
Signed-off-by: Jonathan Denose <jdenose@google.com>
---

Changes in v2:
- change ps2_sendbyte() calls to ps2_command()

 drivers/input/mouse/elantech.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Jonathan Denose May 15, 2024, 3:29 p.m. UTC | #1
On Fri, May 3, 2024 at 11:12 AM Jonathan Denose <jdenose@google.com> wrote:
>
> The Lenovo N24 on resume becomes stuck in a state where it
> sends incorrect packets, causing elantech_packet_check_v4 to fail.
> The only way for the device to resume sending the correct packets is for
> it to be disabled and then re-enabled.
>
> This change adds a dmi check to trigger this behavior on resume.
> Signed-off-by: Jonathan Denose <jdenose@google.com>
> ---
>
> Changes in v2:
> - change ps2_sendbyte() calls to ps2_command()
>
>  drivers/input/mouse/elantech.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
>
> diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
> index 4e38229404b4b..18f26315cae25 100644
> --- a/drivers/input/mouse/elantech.c
> +++ b/drivers/input/mouse/elantech.c
> @@ -1476,6 +1476,23 @@ static void elantech_disconnect(struct psmouse *psmouse)
>         psmouse->private = NULL;
>  }
>
> +/*
> + * Some hw_version 4 models fail to properly activate absolute mode on
> + * resume without going through disable/enable cycle.
> + */
> +static const struct dmi_system_id elantech_needs_reenable[] = {
> +#if defined(CONFIG_DMI) && defined(CONFIG_X86)
> +       {
> +               /* Lenovo N24 */
> +               .matches = {
> +                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
> +                       DMI_MATCH(DMI_PRODUCT_NAME, "81AF"),
> +               },
> +       },
> +#endif
> +       { }
> +};
> +
>  /*
>   * Put the touchpad back into absolute mode when reconnecting
>   */
> @@ -1486,6 +1503,22 @@ static int elantech_reconnect(struct psmouse *psmouse)
>         if (elantech_detect(psmouse, 0))
>                 return -1;
>
> +       if (dmi_check_system(elantech_needs_reenable)) {
> +               int err;
> +
> +               err = ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE);
> +
> +               if (err)
> +                       psmouse_warn(psmouse, "Failed to deactivate mouse on %s: %d\n",
> +                                       psmouse->ps2dev.serio->phys, err);
> +
> +               err = ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE);
> +
> +               if (err)
> +                       psmouse_warn(psmouse, "Failed to reactivate mouse on %s: %d\n",
> +                                       psmouse->ps2dev.serio->phys, err);
> +       }
> +
>         if (elantech_set_absolute_mode(psmouse)) {
>                 psmouse_err(psmouse,
>                             "failed to put touchpad back into absolute mode.\n");
> --
> 2.45.0.rc1.225.g2a3ae87e7f-goog
>

Hello,

Is there anything else needed from me?
Dmitry Torokhov May 15, 2024, 10:28 p.m. UTC | #2
On Wed, May 15, 2024 at 10:29:58AM -0500, Jonathan Denose wrote:
> On Fri, May 3, 2024 at 11:12 AM Jonathan Denose <jdenose@google.com> wrote:
> >
> > The Lenovo N24 on resume becomes stuck in a state where it
> > sends incorrect packets, causing elantech_packet_check_v4 to fail.
> > The only way for the device to resume sending the correct packets is for
> > it to be disabled and then re-enabled.
> >
> > This change adds a dmi check to trigger this behavior on resume.
> > Signed-off-by: Jonathan Denose <jdenose@google.com>
> > ---
> >
> > Changes in v2:
> > - change ps2_sendbyte() calls to ps2_command()
> >
> >  drivers/input/mouse/elantech.c | 33 +++++++++++++++++++++++++++++++++
> >  1 file changed, 33 insertions(+)
> >
> > diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
> > index 4e38229404b4b..18f26315cae25 100644
> > --- a/drivers/input/mouse/elantech.c
> > +++ b/drivers/input/mouse/elantech.c
> > @@ -1476,6 +1476,23 @@ static void elantech_disconnect(struct psmouse *psmouse)
> >         psmouse->private = NULL;
> >  }
> >
> > +/*
> > + * Some hw_version 4 models fail to properly activate absolute mode on
> > + * resume without going through disable/enable cycle.
> > + */
> > +static const struct dmi_system_id elantech_needs_reenable[] = {
> > +#if defined(CONFIG_DMI) && defined(CONFIG_X86)
> > +       {
> > +               /* Lenovo N24 */
> > +               .matches = {
> > +                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
> > +                       DMI_MATCH(DMI_PRODUCT_NAME, "81AF"),
> > +               },
> > +       },
> > +#endif
> > +       { }
> > +};
> > +
> >  /*
> >   * Put the touchpad back into absolute mode when reconnecting
> >   */
> > @@ -1486,6 +1503,22 @@ static int elantech_reconnect(struct psmouse *psmouse)
> >         if (elantech_detect(psmouse, 0))
> >                 return -1;
> >
> > +       if (dmi_check_system(elantech_needs_reenable)) {
> > +               int err;
> > +
> > +               err = ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE);
> > +
> > +               if (err)
> > +                       psmouse_warn(psmouse, "Failed to deactivate mouse on %s: %d\n",
> > +                                       psmouse->ps2dev.serio->phys, err);
> > +
> > +               err = ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE);
> > +
> > +               if (err)
> > +                       psmouse_warn(psmouse, "Failed to reactivate mouse on %s: %d\n",
> > +                                       psmouse->ps2dev.serio->phys, err);
> > +       }
> > +
> >         if (elantech_set_absolute_mode(psmouse)) {
> >                 psmouse_err(psmouse,
> >                             "failed to put touchpad back into absolute mode.\n");
> > --
> > 2.45.0.rc1.225.g2a3ae87e7f-goog
> >
> 
> Hello,
> 
> Is there anything else needed from me?

Josh, Jingle, do you have any feedback on this patch?

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 4e38229404b4b..18f26315cae25 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -1476,6 +1476,23 @@  static void elantech_disconnect(struct psmouse *psmouse)
 	psmouse->private = NULL;
 }
 
+/*
+ * Some hw_version 4 models fail to properly activate absolute mode on
+ * resume without going through disable/enable cycle.
+ */
+static const struct dmi_system_id elantech_needs_reenable[] = {
+#if defined(CONFIG_DMI) && defined(CONFIG_X86)
+	{
+		/* Lenovo N24 */
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+			DMI_MATCH(DMI_PRODUCT_NAME, "81AF"),
+		},
+	},
+#endif
+	{ }
+};
+
 /*
  * Put the touchpad back into absolute mode when reconnecting
  */
@@ -1486,6 +1503,22 @@  static int elantech_reconnect(struct psmouse *psmouse)
 	if (elantech_detect(psmouse, 0))
 		return -1;
 
+	if (dmi_check_system(elantech_needs_reenable)) {
+		int err;
+
+		err = ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE);
+
+		if (err)
+			psmouse_warn(psmouse, "Failed to deactivate mouse on %s: %d\n",
+					psmouse->ps2dev.serio->phys, err);
+
+		err = ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE);
+
+		if (err)
+			psmouse_warn(psmouse, "Failed to reactivate mouse on %s: %d\n",
+					psmouse->ps2dev.serio->phys, err);
+	}
+
 	if (elantech_set_absolute_mode(psmouse)) {
 		psmouse_err(psmouse,
 			    "failed to put touchpad back into absolute mode.\n");