Skip to contentSkip to conversation

platform/x86: ideapad-laptop: Rework touchpad control code

PATCH In review Hans de Goede 3 participants 13 messages Nov 17, 2022 – Nov 21, 2022 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

v2 cover platform/x86: ideapad-laptop: Rework touchpad control code

Hi All,

Here is v2 of my series to rework the ideapad-laptop touchpad control code.

New in v2:
- Split patch 3/3 in to 3 patches (3-5/6) since it was doing to much at once
- Update r_touchpad_val on sysfs read/writes
- Drop the write(VPCCMD_W_TOUCHPAD, 1) call at probe in a separate patch and document why this is done in the commit msg
- Add a new patch (6/6) to hide the touchpad sysfs attribute behind a module-parameter which is disabled by default, see the commit message for why this is done.

Note this applies on top of my review-hans branch which has seen a bunch of other ideapad-laptop changes land recently:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Regards,

Hans

Hans de Goede (6):
platform/x86: ideapad-laptop: Refactor ideapad_sync_touchpad_state() platform/x86: ideapad-laptop: Do not send KEY_TOUCHPAD* events on
probe / resume
platform/x86: ideapad-laptop: Only toggle ps2 aux port on/off on
select models
platform/x86: ideapad-laptop: Send KEY_TOUCHPAD_TOGGLE on some models platform/x86: ideapad-laptop: Stop writing VPCCMD_W_TOUCHPAD at probe
time
platform/x86: ideapad-laptop: Make touchpad_ctrl_via_ec a module
option

 drivers/platform/x86/ideapad-laptop.c | 98 +++++++++++++++++----------
 1 file changed, 61 insertions(+), 37 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH v2 1/6 platform/x86: ideapad-laptop: Refactor ideapad_sync_touchpad_state()

Add an error exit for read_ec_data() failing instead of putting the main body in an if (success) block.

---
 drivers/platform/x86/ideapad-laptop.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/platform/x86/ideapad-laptop.c +15 -12
index 13e3ae731fd8..dcb3a82024da 100644
@@ -1490,23 +1490,26 @@ static void ideapad_kbd_bl_exit(struct ideapad_private *priv)
 static void ideapad_sync_touchpad_state(struct ideapad_private *priv)
 {
 	unsigned long value;
+	unsigned char param;
+	int ret;
 
 	if (!priv->features.touchpad_ctrl_via_ec)
 		return;
 
 	/* Without reading from EC touchpad LED doesn't switch state */
-	if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) {
-		unsigned char param;
-		/*
-		 * Some IdeaPads don't really turn off touchpad - they only
-		 * switch the LED state. We (de)activate KBC AUX port to turn
-		 * touchpad off and on. We send KEY_TOUCHPAD_OFF and
-		 * KEY_TOUCHPAD_ON to not to get out of sync with LED
-		 */
-		i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
-		ideapad_input_report(priv, value ? 67 : 66);
-		sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
-	}
+	ret = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value);
+	if (ret)
+		return;
+
+	/*
+	 * Some IdeaPads don't really turn off touchpad - they only
+	 * switch the LED state. We (de)activate KBC AUX port to turn
+	 * touchpad off and on. We send KEY_TOUCHPAD_OFF and
+	 * KEY_TOUCHPAD_ON to not to get out of sync with LED
+	 */
+	i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
+	ideapad_input_report(priv, value ? 67 : 66);
+	sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
 }
 
 static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
Signature · 1 line
2.38.1
#2 lore raw

PATCH v2 2/6 platform/x86: ideapad-laptop: Do not send KEY_TOUCHPAD* events on probe / resume

In reply to Hans de Goede

The sending of KEY_TOUCHPAD* events is causing spurious touchpad OSD showing on resume.

Disable the sending of events on probe / resume to fix this.

---
 drivers/platform/x86/ideapad-laptop.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/platform/x86/ideapad-laptop.c +9 -6
index dcb3a82024da..eb0b1ec32c13 100644
@@ -1487,7 +1487,7 @@ static void ideapad_kbd_bl_exit(struct ideapad_private *priv)
 /*
  * module init/exit
  */
-static void ideapad_sync_touchpad_state(struct ideapad_private *priv)
+static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_events)
 {
 	unsigned long value;
 	unsigned char param;
@@ -1508,8 +1508,11 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv)
 	 * KEY_TOUCHPAD_ON to not to get out of sync with LED
 	 */
 	i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
-	ideapad_input_report(priv, value ? 67 : 66);
-	sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
+
+	if (send_events) {
+		ideapad_input_report(priv, value ? 67 : 66);
+		sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
+	}
 }
 
 static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
@@ -1550,7 +1553,7 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
 			ideapad_sync_rfk_state(priv);
 			break;
 		case 5:
-			ideapad_sync_touchpad_state(priv);
+			ideapad_sync_touchpad_state(priv, true);
 			break;
 		case 4:
 			ideapad_backlight_notify_brightness(priv);
@@ -1840,7 +1843,7 @@ static int ideapad_acpi_add(struct platform_device *pdev)
 			ideapad_register_rfkill(priv, i);
 
 	ideapad_sync_rfk_state(priv);
-	ideapad_sync_touchpad_state(priv);
+	ideapad_sync_touchpad_state(priv, false);
 
 	err = ideapad_dytc_profile_init(priv);
 	if (err) {
@@ -1925,7 +1928,7 @@ static int ideapad_acpi_resume(struct device *dev)
 	struct ideapad_private *priv = dev_get_drvdata(dev);
 
 	ideapad_sync_rfk_state(priv);
-	ideapad_sync_touchpad_state(priv);
+	ideapad_sync_touchpad_state(priv, false);
 
 	if (priv->dytc)
 		dytc_profile_refresh(priv);
Signature · 1 line
2.38.1
#3 lore raw

PATCH v2 3/6 platform/x86: ideapad-laptop: Only toggle ps2 aux port on/off on select models

In reply to Hans de Goede

Recently there have been multiple patches to disable the ideapad-laptop's touchpad control code, because it is causing issues on various laptops:

Commit d69cd7eea93e ("platform/x86: ideapad-laptop: Disable touchpad_switch for ELAN0634") Commit a231224a601c ("platform/x86: ideapad-laptop: Disable touchpad_switch")

The turning on/off of the ps2 aux port was added specifically for the IdeaPad Z570, where the EC does toggle the touchpad on/off LED and toggles the value returned by reading VPCCMD_R_TOUCHPAD, but it does not actually turn on/off the touchpad.

The ideapad-laptop code really should not be messing with the i8042 controller on all devices just for this special case.

Add a new ctrl_ps2_aux_port flag set based on a DMI based allow-list for devices which need this workaround, populating it with just the Ideapad Z570 for now.

This also adds a module parameter so that this behavior can easily be enabled on other models which may need it.

---
 drivers/platform/x86/ideapad-laptop.c | 29 ++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/platform/x86/ideapad-laptop.c +28 -1
index eb0b1ec32c13..1d86fb988d56 100644
@@ -143,6 +143,7 @@ struct ideapad_private {
 		bool hw_rfkill_switch     : 1;
 		bool kbd_bl               : 1;
 		bool touchpad_ctrl_via_ec : 1;
+		bool ctrl_ps2_aux_port    : 1;
 		bool usb_charging         : 1;
 	} features;
 	struct {
@@ -174,6 +175,12 @@ MODULE_PARM_DESC(set_fn_lock_led,
 	"Enable driver based updates of the fn-lock LED on fn-lock changes. "
 	"If you need this please report this to: [email protected]");
 
+static bool ctrl_ps2_aux_port;
+module_param(ctrl_ps2_aux_port, bool, 0444);
+MODULE_PARM_DESC(ctrl_ps2_aux_port,
+	"Enable driver based PS/2 aux port en-/dis-abling on touchpad on/off toggle. "
+	"If you need this please report this to: [email protected]");
+
 /*
  * shared data
  */
@@ -1507,7 +1514,8 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
 	 * touchpad off and on. We send KEY_TOUCHPAD_OFF and
 	 * KEY_TOUCHPAD_ON to not to get out of sync with LED
 	 */
-	i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
+	if (priv->features.ctrl_ps2_aux_port)
+		i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
 
 	if (send_events) {
 		ideapad_input_report(priv, value ? 67 : 66);
@@ -1615,6 +1623,23 @@ static const struct dmi_system_id hw_rfkill_list[] = {
 	{}
 };
 
+/*
+ * On some models the EC toggles the touchpad muted LED on touchpad toggle
+ * hotkey presses, but the EC does not actually disable the touchpad itself.
+ * On these models the driver needs to explicitly enable/disable the i8042
+ * (PS/2) aux port.
+ */
+static const struct dmi_system_id ctrl_ps2_aux_port_list[] = {
+	{
+	/* Lenovo Ideapad Z570 */
+	.matches = {
+		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+		DMI_MATCH(DMI_PRODUCT_VERSION, "Ideapad Z570"),
+		},
+	},
+	{}
+};
+
 static const struct dmi_system_id no_touchpad_switch_list[] = {
 	{
 	.ident = "Lenovo Yoga 3 Pro 1370",
@@ -1642,6 +1667,8 @@ static void ideapad_check_features(struct ideapad_private *priv)
 		set_fn_lock_led || dmi_check_system(set_fn_lock_led_list);
 	priv->features.hw_rfkill_switch =
 		hw_rfkill_switch || dmi_check_system(hw_rfkill_list);
+	priv->features.ctrl_ps2_aux_port =
+		ctrl_ps2_aux_port || dmi_check_system(ctrl_ps2_aux_port_list);
 
 	/* Most ideapads with ELAN0634 touchpad don't use EC touchpad switch */
 	if (acpi_dev_present("ELAN0634", NULL, -1))
Signature · 1 line
2.38.1
Tested-by on v2 3/6
#4 lore raw

Re: [PATCH v2 3/6] platform/x86: ideapad-laptop: Only toggle ps2 aux port on/off on select models

Quoted 15 lines · Hans de Goede

Recently there have been multiple patches to disable the ideapad-laptop's touchpad control code, because it is causing issues on various laptops:

Commit d69cd7eea93e ("platform/x86: ideapad-laptop: Disable touchpad_switch for ELAN0634") Commit a231224a601c ("platform/x86: ideapad-laptop: Disable touchpad_switch")

The turning on/off of the ps2 aux port was added specifically for the IdeaPad Z570, where the EC does toggle the touchpad on/off LED and toggles the value returned by reading VPCCMD_R_TOUCHPAD, but it does not actually turn on/off the touchpad.

The ideapad-laptop code really should not be messing with the i8042 controller on all devices just for this special case.

Quoted 8 lines

Add a new ctrl_ps2_aux_port flag set based on a DMI based allow-list for devices which need this workaround, populating it with just the Ideapad Z570 for now.

This also adds a module parameter so that this behavior can easily be enabled on other models which may need it.

On Z570:

A few notes for Z570:

1. Touchpad toggle still works properly after this series of patches.

2. My laptop's EC reenables the touchpad on boot and on resume, and this behavior still works after this series.

3. Patch 2 stops sending "spurious" key press events on resume, which actually make sense on my laptop, when the touchpad is reenabled on resume. Maybe we should send a key press, but only if the state changed? (However, for some reason I don't see the OSD for this even before this series.)

4. The sysfs attribute for touchpad doesn't exist on my laptop, but it would still make sense if we made it read only. Right now there is a module parameter to force enable this sysfs attribute, but it's created as read-write, and writes are no-op.

Quoted 75 lines
---
 drivers/platform/x86/ideapad-laptop.c | 29 ++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/platform/x86/ideapad-laptop.c +28 -2
index eb0b1ec32c13..1d86fb988d56 100644
@@ -143,6 +143,7 @@ struct ideapad_private {
                bool hw_rfkill_switch     : 1;
                bool kbd_bl               : 1;
                bool touchpad_ctrl_via_ec : 1;
+               bool ctrl_ps2_aux_port    : 1;
                bool usb_charging         : 1;
        } features;
        struct {
@@ -174,6 +175,12 @@ MODULE_PARM_DESC(set_fn_lock_led,
        "Enable driver based updates of the fn-lock LED on fn-lock changes. "
        "If you need this please report this to: [email protected]");
 
+static bool ctrl_ps2_aux_port;
+module_param(ctrl_ps2_aux_port, bool, 0444);
+MODULE_PARM_DESC(ctrl_ps2_aux_port,
+       "Enable driver based PS/2 aux port en-/dis-abling on touchpad on/off toggle. "
+       "If you need this please report this to: [email protected]");
+
 /*
  * shared data
  */
@@ -1507,7 +1514,8 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
         * touchpad off and on. We send KEY_TOUCHPAD_OFF and
         * KEY_TOUCHPAD_ON to not to get out of sync with LED
         */
-       i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
+       if (priv->features.ctrl_ps2_aux_port)
+               i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
 
        if (send_events) {
                ideapad_input_report(priv, value ? 67 : 66);
@@ -1615,6 +1623,23 @@ static const struct dmi_system_id hw_rfkill_list[] = {
        {}
 };
 
+/*
+ * On some models the EC toggles the touchpad muted LED on touchpad toggle
+ * hotkey presses, but the EC does not actually disable the touchpad itself.
+ * On these models the driver needs to explicitly enable/disable the i8042
+ * (PS/2) aux port.
+ */
+static const struct dmi_system_id ctrl_ps2_aux_port_list[] = {
+       {
+       /* Lenovo Ideapad Z570 */
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+               DMI_MATCH(DMI_PRODUCT_VERSION, "Ideapad Z570"),
+               },
+       },
+       {}
+};
+
 static const struct dmi_system_id no_touchpad_switch_list[] = {
        {
        .ident = "Lenovo Yoga 3 Pro 1370",
@@ -1642,6 +1667,8 @@ static void ideapad_check_features(struct ideapad_private *priv)
                set_fn_lock_led || dmi_check_system(set_fn_lock_led_list);
        priv->features.hw_rfkill_switch =
                hw_rfkill_switch || dmi_check_system(hw_rfkill_list);
+       priv->features.ctrl_ps2_aux_port =
+               ctrl_ps2_aux_port || dmi_check_system(ctrl_ps2_aux_port_list);
 
        /* Most ideapads with ELAN0634 touchpad don't use EC touchpad switch */
        if (acpi_dev_present("ELAN0634", NULL, -1))
--

2.38.1

#5 lore raw

Re: [PATCH v2 3/6] platform/x86: ideapad-laptop: Only toggle ps2 aux port on/off on select models

Hi Максим,

Quoted 20 lines · Максим
Quoted 19 lines · Hans de Goede

Recently there have been multiple patches to disable the ideapad-laptop's touchpad control code, because it is causing issues on various laptops:

Commit d69cd7eea93e ("platform/x86: ideapad-laptop: Disable touchpad_switch for ELAN0634") Commit a231224a601c ("platform/x86: ideapad-laptop: Disable touchpad_switch")

The turning on/off of the ps2 aux port was added specifically for the IdeaPad Z570, where the EC does toggle the touchpad on/off LED and toggles the value returned by reading VPCCMD_R_TOUCHPAD, but it does not actually turn on/off the touchpad.

The ideapad-laptop code really should not be messing with the i8042 controller on all devices just for this special case.

Add a new ctrl_ps2_aux_port flag set based on a DMI based allow-list for devices which need this workaround, populating it with just the Ideapad Z570 for now.

Quoted 8 lines
Quoted 4 lines

This also adds a module parameter so that this behavior can easily be enabled on other models which may need it.

On Z570:

Thank you for testing!

Quoted 4 lines

A few notes for Z570:

1. Touchpad toggle still works properly after this series of patches.

Quoted 8 lines

2. My laptop's EC reenables the touchpad on boot and on resume, and this behavior still works after this series.

3. Patch 2 stops sending "spurious" key press events on resume, which actually make sense on my laptop, when the touchpad is reenabled on resume. Maybe we should send a key press, but only if the state changed? (However, for some reason I don't see the OSD for this even before this series.)

I'm not sure if sending the key-press and thus showing the OSd makes sense in resume even if the state did change. The OSD typically is used to confirm an action by the user. If the touchpad is always re-enabled after resume then the user will get uses to that quick enough and showing an OSD for this will just be a distraction IMHO.

Quoted 4 lines

4. The sysfs attribute for touchpad doesn't exist on my laptop, but it would still make sense if we made it read only. Right now there is a module parameter to force enable this sysfs attribute, but it's created as read-write, and writes are no-op.

Hmm, since the sysfs attr is normally not there at all (now) and since the module option help text says:
"This may not work on all models."

I think that having writing to the sysfs file succeed but not do anything is not really a problem.

I guess we could change the sysfs attr visibility to 444 on models with priv->features.ctrl_ps2_aux_port set, but that seems making the code unnecessarily complicated given that the sysfs attr is hidden by default now anyways.

Regards,

Hans

Quoted 77 lines
Quoted 76 lines
---
 drivers/platform/x86/ideapad-laptop.c | 29 ++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/platform/x86/ideapad-laptop.c +28 -2
index eb0b1ec32c13..1d86fb988d56 100644
@@ -143,6 +143,7 @@ struct ideapad_private {
                bool hw_rfkill_switch     : 1;
                bool kbd_bl               : 1;
                bool touchpad_ctrl_via_ec : 1;
+               bool ctrl_ps2_aux_port    : 1;
                bool usb_charging         : 1;
        } features;
        struct {
@@ -174,6 +175,12 @@ MODULE_PARM_DESC(set_fn_lock_led,
        "Enable driver based updates of the fn-lock LED on fn-lock changes. "
        "If you need this please report this to: [email protected]");
 
+static bool ctrl_ps2_aux_port;
+module_param(ctrl_ps2_aux_port, bool, 0444);
+MODULE_PARM_DESC(ctrl_ps2_aux_port,
+       "Enable driver based PS/2 aux port en-/dis-abling on touchpad on/off toggle. "
+       "If you need this please report this to: [email protected]");
+
 /*
  * shared data
  */
@@ -1507,7 +1514,8 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
         * touchpad off and on. We send KEY_TOUCHPAD_OFF and
         * KEY_TOUCHPAD_ON to not to get out of sync with LED
         */
-       i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
+       if (priv->features.ctrl_ps2_aux_port)
+               i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
 
        if (send_events) {
                ideapad_input_report(priv, value ? 67 : 66);
@@ -1615,6 +1623,23 @@ static const struct dmi_system_id hw_rfkill_list[] = {
        {}
 };
 
+/*
+ * On some models the EC toggles the touchpad muted LED on touchpad toggle
+ * hotkey presses, but the EC does not actually disable the touchpad itself.
+ * On these models the driver needs to explicitly enable/disable the i8042
+ * (PS/2) aux port.
+ */
+static const struct dmi_system_id ctrl_ps2_aux_port_list[] = {
+       {
+       /* Lenovo Ideapad Z570 */
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+               DMI_MATCH(DMI_PRODUCT_VERSION, "Ideapad Z570"),
+               },
+       },
+       {}
+};
+
 static const struct dmi_system_id no_touchpad_switch_list[] = {
        {
        .ident = "Lenovo Yoga 3 Pro 1370",
@@ -1642,6 +1667,8 @@ static void ideapad_check_features(struct ideapad_private *priv)
                set_fn_lock_led || dmi_check_system(set_fn_lock_led_list);
        priv->features.hw_rfkill_switch =
                hw_rfkill_switch || dmi_check_system(hw_rfkill_list);
+       priv->features.ctrl_ps2_aux_port =
+               ctrl_ps2_aux_port || dmi_check_system(ctrl_ps2_aux_port_list);
 
        /* Most ideapads with ELAN0634 touchpad don't use EC touchpad switch */
        if (acpi_dev_present("ELAN0634", NULL, -1))
--

2.38.1

#6 lore raw

Re: [PATCH v2 3/6] platform/x86: ideapad-laptop: Only toggle ps2 aux port on/off on select models

Quoted 42 lines · Hans de Goede

Hi Максим,

Quoted 20 lines · Максим
Quoted 19 lines · Hans de Goede

Recently there have been multiple patches to disable the ideapad-laptop's touchpad control code, because it is causing issues on various laptops:

Commit d69cd7eea93e ("platform/x86: ideapad-laptop: Disable touchpad_switch for ELAN0634") Commit a231224a601c ("platform/x86: ideapad-laptop: Disable touchpad_switch")

The turning on/off of the ps2 aux port was added specifically for the IdeaPad Z570, where the EC does toggle the touchpad on/off LED and toggles the value returned by reading VPCCMD_R_TOUCHPAD, but it does not actually turn on/off the touchpad.

The ideapad-laptop code really should not be messing with the i8042 controller on all devices just for this special case.

Add a new ctrl_ps2_aux_port flag set based on a DMI based allow-list for devices which need this workaround, populating it with just the Ideapad Z570 for now.

Quoted 8 lines
Quoted 4 lines

This also adds a module parameter so that this behavior can easily be enabled on other models which may need it.

On Z570:

Thank you for testing!

Quoted 7 lines

A few notes for Z570:

1. Touchpad toggle still works properly after this series of patches.

2. My laptop's EC reenables the touchpad on boot and on resume, and this behavior still works after this series.

Quoted 8 lines
Quoted 5 lines

3. Patch 2 stops sending "spurious" key press events on resume, which actually make sense on my laptop, when the touchpad is reenabled on resume. Maybe we should send a key press, but only if the state changed? (However, for some reason I don't see the OSD for this even before this series.)

I'm not sure if sending the key-press and thus showing the OSd makes sense in resume even if the state did change.

On one hand, if the state changes, it makes sense to send an event. On the other hand, there was no real key press, so we shouldn't send KEY_TOUCHPAD_ON, a key press event. I'm not sure which of these behaviors is standard, so it's up to you to decide.

Quoted 4 lines

The OSD typically is
used to confirm an action by the user. If the touchpad is always re-enabled after resume then the user will get uses to that quick enough and showing an OSD for this will just be a distraction IMHO.

For some reason, I don't see the OSD on resume, even if the driver sends KEY_TOUCHPAD_ON.

Quoted 10 lines
Quoted 5 lines

4. The sysfs attribute for touchpad doesn't exist on my laptop, but it would still make sense if we made it read only. Right now there is a module parameter to force enable this sysfs attribute, but it's created as read-write, and writes are no-op.

Hmm, since the sysfs attr is normally not there at all (now) and since the module option help text says:
"This may not work on all models."

Quoted 7 lines

I think that having writing to the sysfs file succeed but not do anything is not really a problem.

I guess we could change the sysfs attr visibility to 444 on models with priv->features.ctrl_ps2_aux_port set, but that seems making the code unnecessarily complicated given that the sysfs attr is hidden by default now anyways.

The initial default was to show the sysfs attribute everywhere, not sure why it was hidden afterwards...

BTW, I forgot to mention that I found out that there is the conservation_mode sysfs attribute that shows on Z570, but it's a no-op. Probably the following condition is not enough to discover this feature reliably:

        if (acpi_has_method(handle, "GBMD") && acpi_has_method(handle, "SBMC"))
                priv->features.conservation_mode = true;
Quoted 85 lines

Regards,

Hans

Quoted 77 lines
Quoted 76 lines
---
 drivers/platform/x86/ideapad-laptop.c | 29 ++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/platform/x86/ideapad-laptop.c +28 -2
index eb0b1ec32c13..1d86fb988d56 100644
@@ -143,6 +143,7 @@ struct ideapad_private {
                bool hw_rfkill_switch     : 1;
                bool kbd_bl               : 1;
                bool touchpad_ctrl_via_ec : 1;
+               bool ctrl_ps2_aux_port    : 1;
                bool usb_charging         : 1;
        } features;
        struct {
@@ -174,6 +175,12 @@ MODULE_PARM_DESC(set_fn_lock_led,
        "Enable driver based updates of the fn-lock LED on fn-lock changes. "
        "If you need this please report this to: [email protected]");
 
+static bool ctrl_ps2_aux_port;
+module_param(ctrl_ps2_aux_port, bool, 0444);
+MODULE_PARM_DESC(ctrl_ps2_aux_port,
+       "Enable driver based PS/2 aux port en-/dis-abling on touchpad on/off toggle. "
+       "If you need this please report this to: [email protected]");
+
 /*
  * shared data
  */
@@ -1507,7 +1514,8 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
         * touchpad off and on. We send KEY_TOUCHPAD_OFF and
         * KEY_TOUCHPAD_ON to not to get out of sync with LED
         */
-       i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
+       if (priv->features.ctrl_ps2_aux_port)
+               i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
 
        if (send_events) {
                ideapad_input_report(priv, value ? 67 : 66);
@@ -1615,6 +1623,23 @@ static const struct dmi_system_id hw_rfkill_list[] = {
        {}
 };
 
+/*
+ * On some models the EC toggles the touchpad muted LED on touchpad toggle
+ * hotkey presses, but the EC does not actually disable the touchpad itself.
+ * On these models the driver needs to explicitly enable/disable the i8042
+ * (PS/2) aux port.
+ */
+static const struct dmi_system_id ctrl_ps2_aux_port_list[] = {
+       {
+       /* Lenovo Ideapad Z570 */
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+               DMI_MATCH(DMI_PRODUCT_VERSION, "Ideapad Z570"),
+               },
+       },
+       {}
+};
+
 static const struct dmi_system_id no_touchpad_switch_list[] = {
        {
        .ident = "Lenovo Yoga 3 Pro 1370",
@@ -1642,6 +1667,8 @@ static void ideapad_check_features(struct ideapad_private *priv)
                set_fn_lock_led || dmi_check_system(set_fn_lock_led_list);
        priv->features.hw_rfkill_switch =
                hw_rfkill_switch || dmi_check_system(hw_rfkill_list);
+       priv->features.ctrl_ps2_aux_port =
+               ctrl_ps2_aux_port || dmi_check_system(ctrl_ps2_aux_port_list);
 
        /* Most ideapads with ELAN0634 touchpad don't use EC touchpad switch */
        if (acpi_dev_present("ELAN0634", NULL, -1))
--

2.38.1

#7 lore raw

PATCH v2 4/6 platform/x86: ideapad-laptop: Send KEY_TOUCHPAD_TOGGLE on some models

In reply to Hans de Goede

On recent Ideapad models the EC does not control the touchpad at all, so instead of sending KEY_TOUCHPAD_ON/ _OFF on touchpad toggle hotkey events, ideapad-laptop should send KEY_TOUCHPAD_TOGGLE and let userspace handle the toggling.

Check for this by checking if the value read from VPCCMD_R_TOUCHPAD actually changes when receiving a touchpad-toggle hotkey event; and if it does not change send KEY_TOUCHPAD_TOGGLE to userspace to let userspace enable/disable the touchpad in software.

Note this also drops the priv->features.touchpad_ctrl_via_ec check from ideapad_sync_touchpad_state() so that KEY_TOUCHPAD_TOGGLE will be send on laptops where this is not set too. This can be safely dropped now because the i8042_command(I8042_CMD_AUX_ENABLE/_DISABLE) call is now guarded by its own feature flag.

---
 drivers/platform/x86/ideapad-laptop.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/platform/x86/ideapad-laptop.c +19 -5
index 1d86fb988d56..9b36cfddd36f 100644
@@ -134,6 +134,7 @@ struct ideapad_private {
 	struct ideapad_dytc_priv *dytc;
 	struct dentry *debug;
 	unsigned long cfg;
+	unsigned long r_touchpad_val;
 	struct {
 		bool conservation_mode    : 1;
 		bool dytc                 : 1;
@@ -650,6 +651,8 @@ static ssize_t touchpad_show(struct device *dev,
 	if (err)
 		return err;
 
+	priv->r_touchpad_val = result;
+
 	return sysfs_emit(buf, "%d\n", !!result);
 }
 
@@ -669,6 +672,8 @@ static ssize_t touchpad_store(struct device *dev,
 	if (err)
 		return err;
 
+	priv->r_touchpad_val = state;
+
 	return count;
 }
 
@@ -1159,6 +1164,7 @@ 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 } },
 
 	/*
@@ -1500,9 +1506,6 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
 	unsigned char param;
 	int ret;
 
-	if (!priv->features.touchpad_ctrl_via_ec)
-		return;
-
 	/* Without reading from EC touchpad LED doesn't switch state */
 	ret = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value);
 	if (ret)
@@ -1518,9 +1521,20 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv, bool send_
 		i8042_command(&param, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE);
 
 	if (send_events) {
-		ideapad_input_report(priv, value ? 67 : 66);
-		sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad");
+		/*
+		 * 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);
+		}
 	}
+
+	priv->r_touchpad_val = value;
 }
 
 static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
Signature · 1 line
2.38.1
#8 lore raw

PATCH v2 5/6 platform/x86: ideapad-laptop: Stop writing VPCCMD_W_TOUCHPAD at probe time

In reply to Hans de Goede

Commit d69cd7eea93e ("platform/x86: ideapad-laptop: Disable touchpad_switch for ELAN0634") from Janary 2021 added a flag hiding the touchpad sysfs-attr and disabling ideapad_sync_touchpad_state() because some devices "do not use EC to switch touchpad".

At the same time this added a write(VPCCMD_W_TOUCHPAD, 1) call at probe time on these same devices. This seems to be copied from the rfkill code which does something similar when hw rfkill support is disabled.

But for the rfkill code this is known to be necessary on some models, where as for the touchpad control no motiviation is given for doing this and prior to this patch there were no reports of needing to do this.

So this seems unnecessary; and it is best to avoid poking the hardware unnecessary to avoid unwanted side effects, so remove this.

---
 drivers/platform/x86/ideapad-laptop.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/platform/x86/ideapad-laptop.c +0 -4
index 9b36cfddd36f..fc3d47a75944 100644
@@ -1875,10 +1875,6 @@ static int ideapad_acpi_add(struct platform_device *pdev)
 	if (!priv->features.hw_rfkill_switch)
 		write_ec_cmd(priv->adev->handle, VPCCMD_W_RF, 1);
 
-	/* The same for Touchpad */
-	if (!priv->features.touchpad_ctrl_via_ec)
-		write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, 1);
-
 	for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
 		if (test_bit(ideapad_rfk_data[i].cfgbit, &priv->cfg))
 			ideapad_register_rfkill(priv, i);
Signature · 1 line
2.38.1
#9 lore raw

PATCH v2 6/6 platform/x86: ideapad-laptop: Make touchpad_ctrl_via_ec a module option

In reply to Hans de Goede

Remove the ACPI-HID + DMI-id deny-lists for touchpad_ctrl_via_ec and instead make it a module option which defaults to false.

The touchpad sysfs attribute allowing directly writing VPCCMD_W_TOUCHPAD from userspace has been leading to a lot of bug-reports / patches adding both ACPI HID + dmi-id based deny-lists for it which then need to be expanded all the time going forward leading to a high maintenance load.

At the same time the touchpad sysfs attribute is not a standard Linux userspace API. So it is not used in standard desktop-enviroments, instead it is only used in the following 2 rare circumstances:

1. Ideapad specific control-panel like applets
2. Custom scripts written by users

For 1. these applets need to already deal with the touchpad sysfs attr sometimes not being there because of the existing deny lists so hiding it be default should not cause an issue; and most desktop environments already have a touchpad-disable option in their native control-panel, so having an ideapad specific toggle for this is not necessary.

For 2. since these users are already customizing their systems they can add the module option if they want to keep using the touchpad sysfs attribute.

---
 drivers/platform/x86/ideapad-laptop.c | 33 ++++++---------------------
 1 file changed, 7 insertions(+), 26 deletions(-)
drivers/platform/x86/ideapad-laptop.c +7 -26
index fc3d47a75944..435d2d3d903b 100644
@@ -182,6 +182,12 @@ MODULE_PARM_DESC(ctrl_ps2_aux_port,
 	"Enable driver based PS/2 aux port en-/dis-abling on touchpad on/off toggle. "
 	"If you need this please report this to: [email protected]");
 
+static bool touchpad_ctrl_via_ec;
+module_param(touchpad_ctrl_via_ec, bool, 0444);
+MODULE_PARM_DESC(touchpad_ctrl_via_ec,
+	"Enable registering a 'touchpad' sysfs-attribute which can be used to manually "
+	"tell the EC to enable/disable the touchpad. This may not work on all models.");
+
 /*
  * shared data
  */
@@ -1654,24 +1660,6 @@ static const struct dmi_system_id ctrl_ps2_aux_port_list[] = {
 	{}
 };
 
-static const struct dmi_system_id no_touchpad_switch_list[] = {
-	{
-	.ident = "Lenovo Yoga 3 Pro 1370",
-	.matches = {
-		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
-		DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 3"),
-		},
-	},
-	{
-	.ident = "ZhaoYang K4e-IML",
-	.matches = {
-		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
-		DMI_MATCH(DMI_PRODUCT_VERSION, "ZhaoYang K4e-IML"),
-		},
-	},
-	{}
-};
-
 static void ideapad_check_features(struct ideapad_private *priv)
 {
 	acpi_handle handle = priv->adev->handle;
@@ -1683,14 +1671,7 @@ static void ideapad_check_features(struct ideapad_private *priv)
 		hw_rfkill_switch || dmi_check_system(hw_rfkill_list);
 	priv->features.ctrl_ps2_aux_port =
 		ctrl_ps2_aux_port || dmi_check_system(ctrl_ps2_aux_port_list);
-
-	/* Most ideapads with ELAN0634 touchpad don't use EC touchpad switch */
-	if (acpi_dev_present("ELAN0634", NULL, -1))
-		priv->features.touchpad_ctrl_via_ec = 0;
-	else if (dmi_check_system(no_touchpad_switch_list))
-		priv->features.touchpad_ctrl_via_ec = 0;
-	else
-		priv->features.touchpad_ctrl_via_ec = 1;
+	priv->features.touchpad_ctrl_via_ec = touchpad_ctrl_via_ec;
 
 	if (!read_ec_data(handle, VPCCMD_R_FAN, &val))
 		priv->features.fan_mode = true;
Signature · 1 line
2.38.1
Reviewed-by Tested-by on the v2 series
#10 lore raw
In reply to Hans de Goede
Quoted 4 lines · 在2022年11月17日十一月 上午11:02,Hans de Goede写道:

Hi All,

Here is v2 of my series to rework the ideapad-laptop touchpad control code.

Quoted 9 lines

New in v2:
- Split patch 3/3 in to 3 patches (3-5/6) since it was doing to much at once
- Update r_touchpad_val on sysfs read/writes
- Drop the write(VPCCMD_W_TOUCHPAD, 1) call at probe in a separate patch and document why this is done in the commit msg
- Add a new patch (6/6) to hide the touchpad sysfs attribute behind a module-parameter which is disabled by default, see the commit message for why this is done.

For the whole series:

Can confirm this approach works fine on my problematic ideaPad Yoga 14s.

Thanks
- Jiaxun

Quoted 3 lines
Signature · 2 lines
-- 
2.38.1
Signature · 1 line
- Jiaxun
#11 lore raw

Hi Jiaxun,

Quoted 17 lines · Jiaxun Yang
Quoted 4 lines · 在2022年11月17日十一月 上午11:02,Hans de Goede写道:

Hi All,

Here is v2 of my series to rework the ideapad-laptop touchpad control code.

Quoted 9 lines

New in v2:
- Split patch 3/3 in to 3 patches (3-5/6) since it was doing to much at once
- Update r_touchpad_val on sysfs read/writes
- Drop the write(VPCCMD_W_TOUCHPAD, 1) call at probe in a separate patch and document why this is done in the commit msg
- Add a new patch (6/6) to hide the touchpad sysfs attribute behind a module-parameter which is disabled by default, see the commit message for why this is done.

Quoted 5 lines

For the whole series:

Can confirm this approach works fine on my problematic ideaPad Yoga 14s.

Thank you for the review and for testing!

I will go and add this series to my review-hans branch now and from there it will move to for-next once the builders have done a test-build of it.

Regards,

Hans

#12 lore raw
In reply to Hans de Goede
Quoted 5 lines · Hans de Goede

Hi All,

Here is v2 of my series to rework the ideapad-laptop touchpad control code.

Quoted 8 lines

New in v2:
- Split patch 3/3 in to 3 patches (3-5/6) since it was doing to much at once
- Update r_touchpad_val on sysfs read/writes
- Drop the write(VPCCMD_W_TOUCHPAD, 1) call at probe in a separate patch and document why this is done in the commit msg
- Add a new patch (6/6) to hide the touchpad sysfs attribute behind a module-parameter which is disabled by default, see the commit message for why this is done.

I'll try to take a look at this series and test it on Z570 over the weekend (I've had major issues with electricity supply for the last few days...)

Quoted 10 lines

Note this applies on top of my review-hans branch which has seen a bunch of other ideapad-laptop changes land recently:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Regards,

Hans

Quoted 9 lines

Hans de Goede (6):
platform/x86: ideapad-laptop: Refactor ideapad_sync_touchpad_state() platform/x86: ideapad-laptop: Do not send KEY_TOUCHPAD* events on
probe / resume
platform/x86: ideapad-laptop: Only toggle ps2 aux port on/off on
select models
platform/x86: ideapad-laptop: Send KEY_TOUCHPAD_TOGGLE on some models platform/x86: ideapad-laptop: Stop writing VPCCMD_W_TOUCHPAD at probe
time

IIRC, the touchpad gets enabled on boot on Z570 if it was disabled before rebooting. I'll test if it's still the case after this patch (given that VPCCMD_W_TOUCHPAD seems to be a no-op).

Quoted 9 lines

platform/x86: ideapad-laptop: Make touchpad_ctrl_via_ec a module
option

 drivers/platform/x86/ideapad-laptop.c | 98 +++++++++++++++++----------
 1 file changed, 61 insertions(+), 37 deletions(-)

--
2.38.1