On Sat, Jul 16, 2022 at 08:26:49AM +0200, Stefan Hagen wrote: > Hi, > > This is a workaround taken from Linux to mitigate sporadic cursor jumps > due to a firmware bug. Known affected laptops are: > > - Lenovo Thinkpad X13 Gen1 (AMD version) > - Lenovo Thinkpad T14s (AMD version) > - Lenovo A475 > > The trackpoint device is a touchpad/trackpoint combination that shows up > in dmesg as "Elantech Clickpad, version 4". > > The faulty packets are reporting relative movements greater than 127 and > cause the mouse cursor to jump into a corner of the screen. It only > happens when the trackpoint is used. The touchpad is not affected. > > The bug report leading up to the fix: > https://bugzilla.kernel.org/show_bug.cgi?id=209167 > > The packet layout is described here: > https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/input/mouse/elantech.c?h=v5.18.9#n492 > > I'm running with this diff since r2k22 and haven't had a cursor jump or > other negative side effects. > > Thanks to stsp@ for helping. > > Comments? OK?
ok stsp@, but I would remove the entire #ifdef DIAGNOSTIC printf block before commit. Documenting the issue via the comment is good enough. In general, printing messages in interrupt handlers is bad. And usually done only under #ifdef DEBUG (code under DIAGNOSTIC is compiled in by default). If a device ends up triggering this very often then a lot of messages on the console could render the system unsuable. > Index: sys/dev/pckbc/pms.c > =================================================================== > RCS file: /home/cvs/src/sys/dev/pckbc/pms.c,v > retrieving revision 1.96 > diff -u -p -u -p -r1.96 pms.c > --- sys/dev/pckbc/pms.c 6 Apr 2022 18:59:30 -0000 1.96 > +++ sys/dev/pckbc/pms.c 2 Jul 2022 20:23:45 -0000 > @@ -2610,6 +2610,22 @@ pms_proc_elantech_v4(struct pms_softc *s > > case ELANTECH_PKT_TRACKPOINT: > if (sc->sc_dev_enable & PMS_DEV_SECONDARY) { > + /* > + * This firmware misreport coordinates for trackpoint > + * occasionally. Discard packets outside of [-127, 127] > range > + * to prevent cursor jumps. > + */ > + if (sc->packet[4] == 0x80 || sc->packet[5] == 0x80 || > + sc->packet[1] >> 7 == sc->packet[4] >> 7 || > + sc->packet[2] >> 7 == sc->packet[5] >> 7) { > +#ifdef DIAGNOSTIC > + printf("%s: discard faulty packet (elantech > bug) " > + "(state = %d,", DEVNAME(sc), > sc->inputstate); > + pms_print_packet(sc); > + printf(")\n"); > +#endif > + return; > + } > x = sc->packet[4] - 0x100 + (sc->packet[1] << 1); > y = sc->packet[5] - 0x100 + (sc->packet[2] << 1); > buttons = butmap[sc->packet[0] & 7]; > >