diff mbox series

platform/x86: ideapad-laptop: Stop sending KEY_TOUCHPAD_TOGGLE

Message ID 20230330194644.64628-1-hdegoede@redhat.com (mailing list archive)
State Accepted, archived
Headers show
Series platform/x86: ideapad-laptop: Stop sending KEY_TOUCHPAD_TOGGLE | expand

Commit Message

Hans de Goede March 30, 2023, 7:46 p.m. UTC
Commit 5829f8a897e4 ("platform/x86: ideapad-laptop: Send
KEY_TOUCHPAD_TOGGLE on some models") made ideapad-laptop send
KEY_TOUCHPAD_TOGGLE when we receive an ACPI notify with VPC event bit 5 set
and the touchpad-state has not been changed by the EC itself already.

This was done under the assumption that this would be good to do to make
the touchpad-toggle hotkey work on newer models where the EC does not
toggle the touchpad on/off itself (because it is not routed through
the PS/2 controller, but uses I2C).

But it turns out that at least some models, e.g. the Yoga 7-15ITL5 the EC
triggers an ACPI notify with VPC event bit 5 set on resume, which would
now cause a spurious KEY_TOUCHPAD_TOGGLE on resume to which the desktop
environment responds by disabling the touchpad in software, breaking
the touchpad (until manually re-enabled) on resume.

It was never confirmed that sending KEY_TOUCHPAD_TOGGLE actually improves
things on new models and at least some new models like the Yoga 7-15ITL5
don't have a touchpad on/off toggle hotkey at all, while still sending
ACPI notify events with VPC event bit 5 set.

So it seems best to revert the change to send KEY_TOUCHPAD_TOGGLE when
receiving an ACPI notify events with VPC event bit 5 and the touchpad
state as reported by the EC has not changed.

Note this is not a full revert the code to cache the last EC touchpad
state is kept to avoid sending spurious KEY_TOUCHPAD_ON / _OFF events
on resume.

Fixes: 5829f8a897e4 ("platform/x86: ideapad-laptop: Send KEY_TOUCHPAD_TOGGLE on some models")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217234
Cc: stable@vger.kernel.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/ideapad-laptop.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

Comments

Maxim Mikityanskiy March 31, 2023, 9:51 a.m. UTC | #1
On Thu, 30 Mar 2023 at 21:46:44 +0200, Hans de Goede wrote:
> Commit 5829f8a897e4 ("platform/x86: ideapad-laptop: Send
> KEY_TOUCHPAD_TOGGLE on some models") made ideapad-laptop send
> KEY_TOUCHPAD_TOGGLE when we receive an ACPI notify with VPC event bit 5 set
> and the touchpad-state has not been changed by the EC itself already.
> 
> This was done under the assumption that this would be good to do to make
> the touchpad-toggle hotkey work on newer models where the EC does not
> toggle the touchpad on/off itself (because it is not routed through
> the PS/2 controller, but uses I2C).
> 
> But it turns out that at least some models, e.g. the Yoga 7-15ITL5 the EC
> triggers an ACPI notify with VPC event bit 5 set on resume, which would
> now cause a spurious KEY_TOUCHPAD_TOGGLE on resume to which the desktop
> environment responds by disabling the touchpad in software, breaking
> the touchpad (until manually re-enabled) on resume.

Oh gosh, the touchpad toggle on Ideapads is so much broken, I wonder how
the Windows driver deals with all this variety of different behaviors
(unless it's broken too :D).

I'll test the patch on Z570, but as I see, it shouldn't change anything
for Z570.

> It was never confirmed that sending KEY_TOUCHPAD_TOGGLE actually improves
> things on new models and at least some new models like the Yoga 7-15ITL5
> don't have a touchpad on/off toggle hotkey at all, while still sending
> ACPI notify events with VPC event bit 5 set.
> 
> So it seems best to revert the change to send KEY_TOUCHPAD_TOGGLE when
> receiving an ACPI notify events with VPC event bit 5 and the touchpad
> state as reported by the EC has not changed.
> 
> Note this is not a full revert the code to cache the last EC touchpad
> state is kept to avoid sending spurious KEY_TOUCHPAD_ON / _OFF events
> on resume.
> 
> Fixes: 5829f8a897e4 ("platform/x86: ideapad-laptop: Send KEY_TOUCHPAD_TOGGLE on some models")
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=217234
> Cc: stable@vger.kernel.org
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/platform/x86/ideapad-laptop.c | 23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
> index b5ef3452da1f..35c63cce0479 100644
> --- a/drivers/platform/x86/ideapad-laptop.c
> +++ b/drivers/platform/x86/ideapad-laptop.c
> @@ -1170,7 +1170,6 @@ static const struct key_entry ideapad_keymap[] = {
>  	{ KE_KEY,  65, { KEY_PROG4 } },
>  	{ KE_KEY,  66, { KEY_TOUCHPAD_OFF } },
>  	{ KE_KEY,  67, { KEY_TOUCHPAD_ON } },
> -	{ KE_KEY,  68, { KEY_TOUCHPAD_TOGGLE } },
>  	{ KE_KEY, 128, { KEY_ESC } },
>  
>  	/*
> @@ -1526,18 +1525,16 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
>  	if (priv->features.ctrl_ps2_aux_port)
>  		i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
>  
> -	if (send_events) {
> -		/*
> -		 * On older models the EC controls the touchpad and toggles it
> -		 * on/off itself, in this case we report KEY_TOUCHPAD_ON/_OFF.
> -		 * If the EC did not toggle, report KEY_TOUCHPAD_TOGGLE.
> -		 */
> -		if (value != priv->r_touchpad_val) {
> -			ideapad_input_report(priv, value ? 67 : 66);
> -			sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
> -		} else {
> -			ideapad_input_report(priv, 68);
> -		}
> +	/*
> +	 * On older models the EC controls the touchpad and toggles it on/off
> +	 * itself, in this case we report KEY_TOUCHPAD_ON/_OFF. Some models do
> +	 * an acpi-notify with VPC bit 5 set on resume, so this function get
> +	 * called with send_events=true on every resume. Therefor if the EC did
> +	 * not toggle, do nothing to avoid sending spurious KEY_TOUCHPAD_TOGGLE.
> +	 */
> +	if (send_events && value != priv->r_touchpad_val) {
> +		ideapad_input_report(priv, value ? 67 : 66);
> +		sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
>  	}
>  
>  	priv->r_touchpad_val = value;
> -- 
> 2.39.1
>
Hans de Goede March 31, 2023, 5:38 p.m. UTC | #2
Hi,

On 3/30/23 21:46, Hans de Goede wrote:
> Commit 5829f8a897e4 ("platform/x86: ideapad-laptop: Send
> KEY_TOUCHPAD_TOGGLE on some models") made ideapad-laptop send
> KEY_TOUCHPAD_TOGGLE when we receive an ACPI notify with VPC event bit 5 set
> and the touchpad-state has not been changed by the EC itself already.
> 
> This was done under the assumption that this would be good to do to make
> the touchpad-toggle hotkey work on newer models where the EC does not
> toggle the touchpad on/off itself (because it is not routed through
> the PS/2 controller, but uses I2C).
> 
> But it turns out that at least some models, e.g. the Yoga 7-15ITL5 the EC
> triggers an ACPI notify with VPC event bit 5 set on resume, which would
> now cause a spurious KEY_TOUCHPAD_TOGGLE on resume to which the desktop
> environment responds by disabling the touchpad in software, breaking
> the touchpad (until manually re-enabled) on resume.
> 
> It was never confirmed that sending KEY_TOUCHPAD_TOGGLE actually improves
> things on new models and at least some new models like the Yoga 7-15ITL5
> don't have a touchpad on/off toggle hotkey at all, while still sending
> ACPI notify events with VPC event bit 5 set.
> 
> So it seems best to revert the change to send KEY_TOUCHPAD_TOGGLE when
> receiving an ACPI notify events with VPC event bit 5 and the touchpad
> state as reported by the EC has not changed.
> 
> Note this is not a full revert the code to cache the last EC touchpad
> state is kept to avoid sending spurious KEY_TOUCHPAD_ON / _OFF events
> on resume.
> 
> Fixes: 5829f8a897e4 ("platform/x86: ideapad-laptop: Send KEY_TOUCHPAD_TOGGLE on some models")
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=217234
> Cc: stable@vger.kernel.org
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

I've applied this patch to my fixes branch now:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=fixes

Note it will show up in my fixes branch once I've pushed my
local branch there, which might take a while.

I will include this patch in my next fixes pull-req to Linus
for the current kernel development cycle.

Regards,

Hans



> ---
>  drivers/platform/x86/ideapad-laptop.c | 23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
> index b5ef3452da1f..35c63cce0479 100644
> --- a/drivers/platform/x86/ideapad-laptop.c
> +++ b/drivers/platform/x86/ideapad-laptop.c
> @@ -1170,7 +1170,6 @@ static const struct key_entry ideapad_keymap[] = {
>  	{ KE_KEY,  65, { KEY_PROG4 } },
>  	{ KE_KEY,  66, { KEY_TOUCHPAD_OFF } },
>  	{ KE_KEY,  67, { KEY_TOUCHPAD_ON } },
> -	{ KE_KEY,  68, { KEY_TOUCHPAD_TOGGLE } },
>  	{ KE_KEY, 128, { KEY_ESC } },
>  
>  	/*
> @@ -1526,18 +1525,16 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
>  	if (priv->features.ctrl_ps2_aux_port)
>  		i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
>  
> -	if (send_events) {
> -		/*
> -		 * On older models the EC controls the touchpad and toggles it
> -		 * on/off itself, in this case we report KEY_TOUCHPAD_ON/_OFF.
> -		 * If the EC did not toggle, report KEY_TOUCHPAD_TOGGLE.
> -		 */
> -		if (value != priv->r_touchpad_val) {
> -			ideapad_input_report(priv, value ? 67 : 66);
> -			sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
> -		} else {
> -			ideapad_input_report(priv, 68);
> -		}
> +	/*
> +	 * On older models the EC controls the touchpad and toggles it on/off
> +	 * itself, in this case we report KEY_TOUCHPAD_ON/_OFF. Some models do
> +	 * an acpi-notify with VPC bit 5 set on resume, so this function get
> +	 * called with send_events=true on every resume. Therefor if the EC did
> +	 * not toggle, do nothing to avoid sending spurious KEY_TOUCHPAD_TOGGLE.
> +	 */
> +	if (send_events && value != priv->r_touchpad_val) {
> +		ideapad_input_report(priv, value ? 67 : 66);
> +		sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
>  	}
>  
>  	priv->r_touchpad_val = value;
Maxim Mikityanskiy April 3, 2023, 8:51 p.m. UTC | #3
On Fri, 31 Mar 2023 at 12:51:30 +0300, Maxim Mikityanskiy wrote:
> On Thu, 30 Mar 2023 at 21:46:44 +0200, Hans de Goede wrote:
> > Commit 5829f8a897e4 ("platform/x86: ideapad-laptop: Send
> > KEY_TOUCHPAD_TOGGLE on some models") made ideapad-laptop send
> > KEY_TOUCHPAD_TOGGLE when we receive an ACPI notify with VPC event bit 5 set
> > and the touchpad-state has not been changed by the EC itself already.
> > 
> > This was done under the assumption that this would be good to do to make
> > the touchpad-toggle hotkey work on newer models where the EC does not
> > toggle the touchpad on/off itself (because it is not routed through
> > the PS/2 controller, but uses I2C).
> > 
> > But it turns out that at least some models, e.g. the Yoga 7-15ITL5 the EC
> > triggers an ACPI notify with VPC event bit 5 set on resume, which would
> > now cause a spurious KEY_TOUCHPAD_TOGGLE on resume to which the desktop
> > environment responds by disabling the touchpad in software, breaking
> > the touchpad (until manually re-enabled) on resume.
> 
> Oh gosh, the touchpad toggle on Ideapads is so much broken, I wonder how
> the Windows driver deals with all this variety of different behaviors
> (unless it's broken too :D).
> 
> I'll test the patch on Z570, but as I see, it shouldn't change anything
> for Z570.

Tested the kernel from your branch on Z570, the touchpad button still
works fine.

> > It was never confirmed that sending KEY_TOUCHPAD_TOGGLE actually improves
> > things on new models and at least some new models like the Yoga 7-15ITL5
> > don't have a touchpad on/off toggle hotkey at all, while still sending
> > ACPI notify events with VPC event bit 5 set.
> > 
> > So it seems best to revert the change to send KEY_TOUCHPAD_TOGGLE when
> > receiving an ACPI notify events with VPC event bit 5 and the touchpad
> > state as reported by the EC has not changed.
> > 
> > Note this is not a full revert the code to cache the last EC touchpad
> > state is kept to avoid sending spurious KEY_TOUCHPAD_ON / _OFF events
> > on resume.
> > 
> > Fixes: 5829f8a897e4 ("platform/x86: ideapad-laptop: Send KEY_TOUCHPAD_TOGGLE on some models")
> > Link: https://bugzilla.kernel.org/show_bug.cgi?id=217234
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> > ---
> >  drivers/platform/x86/ideapad-laptop.c | 23 ++++++++++-------------
> >  1 file changed, 10 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
> > index b5ef3452da1f..35c63cce0479 100644
> > --- a/drivers/platform/x86/ideapad-laptop.c
> > +++ b/drivers/platform/x86/ideapad-laptop.c
> > @@ -1170,7 +1170,6 @@ static const struct key_entry ideapad_keymap[] = {
> >  	{ KE_KEY,  65, { KEY_PROG4 } },
> >  	{ KE_KEY,  66, { KEY_TOUCHPAD_OFF } },
> >  	{ KE_KEY,  67, { KEY_TOUCHPAD_ON } },
> > -	{ KE_KEY,  68, { KEY_TOUCHPAD_TOGGLE } },
> >  	{ KE_KEY, 128, { KEY_ESC } },
> >  
> >  	/*
> > @@ -1526,18 +1525,16 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
> >  	if (priv->features.ctrl_ps2_aux_port)
> >  		i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
> >  
> > -	if (send_events) {
> > -		/*
> > -		 * On older models the EC controls the touchpad and toggles it
> > -		 * on/off itself, in this case we report KEY_TOUCHPAD_ON/_OFF.
> > -		 * If the EC did not toggle, report KEY_TOUCHPAD_TOGGLE.
> > -		 */
> > -		if (value != priv->r_touchpad_val) {
> > -			ideapad_input_report(priv, value ? 67 : 66);
> > -			sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
> > -		} else {
> > -			ideapad_input_report(priv, 68);
> > -		}
> > +	/*
> > +	 * On older models the EC controls the touchpad and toggles it on/off
> > +	 * itself, in this case we report KEY_TOUCHPAD_ON/_OFF. Some models do
> > +	 * an acpi-notify with VPC bit 5 set on resume, so this function get
> > +	 * called with send_events=true on every resume. Therefor if the EC did
> > +	 * not toggle, do nothing to avoid sending spurious KEY_TOUCHPAD_TOGGLE.
> > +	 */
> > +	if (send_events && value != priv->r_touchpad_val) {
> > +		ideapad_input_report(priv, value ? 67 : 66);
> > +		sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
> >  	}
> >  
> >  	priv->r_touchpad_val = value;
> > -- 
> > 2.39.1
> >
Hans de Goede April 4, 2023, 7:56 a.m. UTC | #4
Hi,

On 4/3/23 22:51, Maxim Mikityanskiy wrote:
> On Fri, 31 Mar 2023 at 12:51:30 +0300, Maxim Mikityanskiy wrote:
>> On Thu, 30 Mar 2023 at 21:46:44 +0200, Hans de Goede wrote:
>>> Commit 5829f8a897e4 ("platform/x86: ideapad-laptop: Send
>>> KEY_TOUCHPAD_TOGGLE on some models") made ideapad-laptop send
>>> KEY_TOUCHPAD_TOGGLE when we receive an ACPI notify with VPC event bit 5 set
>>> and the touchpad-state has not been changed by the EC itself already.
>>>
>>> This was done under the assumption that this would be good to do to make
>>> the touchpad-toggle hotkey work on newer models where the EC does not
>>> toggle the touchpad on/off itself (because it is not routed through
>>> the PS/2 controller, but uses I2C).
>>>
>>> But it turns out that at least some models, e.g. the Yoga 7-15ITL5 the EC
>>> triggers an ACPI notify with VPC event bit 5 set on resume, which would
>>> now cause a spurious KEY_TOUCHPAD_TOGGLE on resume to which the desktop
>>> environment responds by disabling the touchpad in software, breaking
>>> the touchpad (until manually re-enabled) on resume.
>>
>> Oh gosh, the touchpad toggle on Ideapads is so much broken, I wonder how
>> the Windows driver deals with all this variety of different behaviors
>> (unless it's broken too :D).
>>
>> I'll test the patch on Z570, but as I see, it shouldn't change anything
>> for Z570.
> 
> Tested the kernel from your branch on Z570, the touchpad button still
> works fine.

Thank you for testing.

Regards,

Hans
diff mbox series

Patch

diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index b5ef3452da1f..35c63cce0479 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -1170,7 +1170,6 @@  static const struct key_entry ideapad_keymap[] = {
 	{ KE_KEY,  65, { KEY_PROG4 } },
 	{ KE_KEY,  66, { KEY_TOUCHPAD_OFF } },
 	{ KE_KEY,  67, { KEY_TOUCHPAD_ON } },
-	{ KE_KEY,  68, { KEY_TOUCHPAD_TOGGLE } },
 	{ KE_KEY, 128, { KEY_ESC } },
 
 	/*
@@ -1526,18 +1525,16 @@  static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
 	if (priv->features.ctrl_ps2_aux_port)
 		i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
 
-	if (send_events) {
-		/*
-		 * On older models the EC controls the touchpad and toggles it
-		 * on/off itself, in this case we report KEY_TOUCHPAD_ON/_OFF.
-		 * If the EC did not toggle, report KEY_TOUCHPAD_TOGGLE.
-		 */
-		if (value != priv->r_touchpad_val) {
-			ideapad_input_report(priv, value ? 67 : 66);
-			sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
-		} else {
-			ideapad_input_report(priv, 68);
-		}
+	/*
+	 * On older models the EC controls the touchpad and toggles it on/off
+	 * itself, in this case we report KEY_TOUCHPAD_ON/_OFF. Some models do
+	 * an acpi-notify with VPC bit 5 set on resume, so this function get
+	 * called with send_events=true on every resume. Therefor if the EC did
+	 * not toggle, do nothing to avoid sending spurious KEY_TOUCHPAD_TOGGLE.
+	 */
+	if (send_events && value != priv->r_touchpad_val) {
+		ideapad_input_report(priv, value ? 67 : 66);
+		sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
 	}
 
 	priv->r_touchpad_val = value;