On Wed, 9 Nov 2022 at 22:59, Hans de Goede <hdegoede@xxxxxxxxxx> wrote: > > Hi All, > > I'm emailing you all because you have written patches or > reported bugs related to the ideapad-laptop touchpad > handling the past. > > 1. History > ========== > > I have done a bit of digging into the history of > the touchpad handling: > > What I believe is the troublesome part of the touchpad handling > started in 2012 with: > > 07a4a4fc83dd ("ideapad: add Lenovo IdeaPad Z570 support (part 2)") > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=07a4a4fc83dd > > Which added the ideapad_sync_touchpad_state() function which depending > on the result of reading VPCCMD_R_TOUCHPAD send an i8042 command to > enable/disable the aux port of the ps2 controller *and* which sends > KEY_TOUCHPAD_OFF/KEY_TOUCHPAD_ON events to userspace to let userspace > know the state of the touchpad. For the reference, this cumbersome solution was needed in the first place, because Z570 has an LED, and EC toggles the LED on each touchpad toggle button press, but EC only controls the LED, it doesn't actually disable the touchpad. Normally, when EC doesn't disable the touchpad, we can send KEY_TOUCHPAD_TOGGLE and leave the action to the DE. However, as Z570 has this LED, which will get out of sync with the touchpad state, we can't use KEY_TOUCHPAD_TOGGLE. That leads to the following idea: if newer Lenovos have issues with VPCCMD_R_TOUCHPAD and they don't have the touchpad LED, we can just use KEY_TOUCHPAD_TOGGLE for them. However, if it turns out that some Lenovo model does actually disable the touchpad in hardware, this also needs to be taken into account. However, this idea doesn't answer the question of how to detect such laptops. I wonder how the Windows driver does it. By the way, newer Lenovos also have other incompatibilities, for example, fan modes are no longer relevant on some models, and I don't know how to detect those either. > > The first commit to optionally disable ideapad_sync_touchpad_state() > was actually written by me in 2014, for a "Lenovo Yoga 2 11": > > f79a901331a8 ("ideapad-laptop: Disable touchpad interface on Yoga models") > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f79a901331a8 > > The problem on the "Lenovo Yoga 2 11" was a spurious KEY_TOUCHPAD_OFF > event on resume, other then that there were no bad side effects. > > This patch got reverted soon afterwards in commit 3b264d279e72 because > it stopped the touchpad enable/disable button from working on > a "Lenovo Yoga 2 13". > > Then in 2021 a patch was added to again disable ideapad_sync_touchpad_state() > on some models, this time based on the ACPI HID (ELAN0634) of the touchpad: > > d69cd7eea93e ("platform/x86: ideapad-laptop: Disable touchpad_switch for ELAN0634") > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d69cd7eea93e > > And the last couple of weeks the following 2 patches were added to disable > ideapad_sync_touchpad_state() on more models based on DMI ids for the first > patch (already merged) + adding a new ACPI HID for the second patch: > > a231224a601c ("platform/x86: ideapad-laptop: Disable touchpad_switch") > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a231224a601c > > https://patchwork.kernel.org/project/platform-driver-x86/patch/20221029120311.11152-8-erayorcunus@xxxxxxxxx/ > > As mentioned in the commit msg of d69cd7eea93e ("platform/x86: > ideapad-laptop: Disable touchpad_switch for ELAN0634") part of > the problem is VPCCMD_R_TOUCHPAD returning 0 leading to the aux > ps/2 port getting turned off. > > This can be a problem even on devices where the touchpad shows up as > an i2c/smbus device because often on those devices the touchpad is > connected over both ps/2 + i2c and at least for synaptics devices > the touchpad needs to be contacted over i2c within a couple of > 100s of ms of doing a ps/2 reset for it to switch to i2c mode. > > > 2. Possible solutions > ===================== > > 1. Do something with BIOS date to only enable touchpad_ctrl_via_ec on > older models. Problem is that BIOS updates happen and those can be > of much later date then the production year of the model > > 2. Move to an allow list for setting touchpad_ctrl_via_ec to true, given > how soon after my initial patch to disable touchpad_ctrl_via_ec I got > a bug report about this, which even was due to a deny-list DMI entry > not being narrow enough this seems like a bad idea. OTOH missing > the ability to turn the touchpad on/off is less of a big deal > then a non working touchpad. So if we fail to find a better > solution this might be the best thing to do. > > 3. Since the problems are caused when VPCCMD_R_TOUCHPAD reads as 0 at > boot, causing ideapad_sync_touchpad_state() to turn off the ps/2 aux port > and since the touchpad is normally on at boot, we can check for > VPCCMD_R_TOUCHPAD reading as 0 at boot and if that happens assume that > means touchpad-ctrl via the EC is not available. I have attached > a patch implementing this approach. I need to check it, but it's entirely possible that the touchpad state is preserved after reboot. In that case, reading VPCCMD_R_TOUCHPAD as 0 on boot would be normal. I think it's also possible that the user can disable the touchpad before Linux starts. This approach looks problematic. > > > 3. Please test > ============== > > If you have ideapads where touchpad_ctrl_via_ec should be 1 because > it is needed to toggle the touchpad on/off with the hotkey. I still own my Z570, but it's located in another city. I can do some testing on it, though. I can also provide the DSDT dump along with the BIOS version. Also adding Kryštof to this thread, who is a Lenovo Yoga 720-15ikb user. It would be perfect if someone could reverse engineer what the Windows driver does in order to distinguish the old and the new interfaces. With a proper detection mechanism, we could: 1. Just send KEY_TOUCHPAD_ON/OFF if EC disables the touchpad (any known models?). 2. Disable the touchpad in the driver if the laptop has the LED and EC doesn't disable the touchpad (Z570). 3. Just send KEY_TOUCHPAD_TOGGLE if the laptop doesn't have the LED and EC doesn't disable the touchpad (any known models?). > > Or the exact opposite you have ideapads where it should be disabled > because ideapad_sync_touchpad_state() turning off the ps/2 aux port > is causing problems. > > Then please give the attached patch a try. Note this applies on > top of Torvald's current master, or on top of 6.0 with : > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a231224a601c > added. > > Regards, > > Hans >