History log of /openbsd-current/sys/dev/pckbc/pms.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.98 16-Aug-2023 bru

Identify Synaptics touchpads without multifinger support.

ok miod@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.97 23-Jul-2022 sdk

Discard relative movement packets outside of [-127, 127] range to
prevent cursor jumps when using the trackpoint on some lenovo laptops.

Known affected models:
- Lenovo Thinkpad X13 Gen1
- Lenovo Thinkpad T14(s)
- Lenovo Thinkpad E15 Gen3
- Lenovo A475

With help from stsp@

OK stsp@ miod@ deraadt@ bru@


# 1.96 06-Apr-2022 naddy

constify struct cfattach


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.95 23-Oct-2020 bru

1. Work around a firmware bug of some Elantech-v1 touchpads.

2. Remove obsolete code from the v1-/v2-packet handlers (coordinate
values are ignored if z is 0).

Thanks to sxvghd for providing the base of this patch, and for testing.


Revision tags: OPENBSD_6_8_BASE
# 1.94 10-Aug-2020 mglocker

Get Elantech v1 touchpad with fw version 0x20022 working.

From sxvghd (at) firemail (dot) cc, on tech@


# 1.93 04-Jul-2020 mglocker

Fix intermittent failing device initialization seen on some Synaptics
devices which has been re-introduced by pms.c revision 1.92.

ok tb@


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Mar-2020 bru

1. Run Synaptics touchpads in plain W-mode. 2. Update the AGM-check.

Enabling extended W-mode is unnecessary as long as pms does not process
the additional packets properly.

Thanks to David Demelier for his reports and tests.

ok anton@ mpi@


# 1.91 22-Jan-2020 mpi

Unbreak !DIAGNOSTIC build.

From Andrius V vezhlys (at) gmail, on bugs@


Revision tags: OPENBSD_6_6_BASE
# 1.90 20-Sep-2019 bru

Extend the identification and validation of elantech-v4 packets to the
"crc-enabled" format.

ok awolk@


# 1.89 19-Aug-2019 bru

Accept more elantech-v4 models, and apply a test for external buttons.

Thanks to Alexander Cronheim.

ok mpi@


Revision tags: OPENBSD_6_5_BASE
# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.97 23-Jul-2022 sdk

Discard relative movement packets outside of [-127, 127] range to
prevent cursor jumps when using the trackpoint on some lenovo laptops.

Known affected models:
- Lenovo Thinkpad X13 Gen1
- Lenovo Thinkpad T14(s)
- Lenovo Thinkpad E15 Gen3
- Lenovo A475

With help from stsp@

OK stsp@ miod@ deraadt@ bru@


# 1.96 06-Apr-2022 naddy

constify struct cfattach


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.95 23-Oct-2020 bru

1. Work around a firmware bug of some Elantech-v1 touchpads.

2. Remove obsolete code from the v1-/v2-packet handlers (coordinate
values are ignored if z is 0).

Thanks to sxvghd for providing the base of this patch, and for testing.


Revision tags: OPENBSD_6_8_BASE
# 1.94 10-Aug-2020 mglocker

Get Elantech v1 touchpad with fw version 0x20022 working.

From sxvghd (at) firemail (dot) cc, on tech@


# 1.93 04-Jul-2020 mglocker

Fix intermittent failing device initialization seen on some Synaptics
devices which has been re-introduced by pms.c revision 1.92.

ok tb@


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Mar-2020 bru

1. Run Synaptics touchpads in plain W-mode. 2. Update the AGM-check.

Enabling extended W-mode is unnecessary as long as pms does not process
the additional packets properly.

Thanks to David Demelier for his reports and tests.

ok anton@ mpi@


# 1.91 22-Jan-2020 mpi

Unbreak !DIAGNOSTIC build.

From Andrius V vezhlys (at) gmail, on bugs@


Revision tags: OPENBSD_6_6_BASE
# 1.90 20-Sep-2019 bru

Extend the identification and validation of elantech-v4 packets to the
"crc-enabled" format.

ok awolk@


# 1.89 19-Aug-2019 bru

Accept more elantech-v4 models, and apply a test for external buttons.

Thanks to Alexander Cronheim.

ok mpi@


Revision tags: OPENBSD_6_5_BASE
# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.96 06-Apr-2022 naddy

constify struct cfattach


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.95 23-Oct-2020 bru

1. Work around a firmware bug of some Elantech-v1 touchpads.

2. Remove obsolete code from the v1-/v2-packet handlers (coordinate
values are ignored if z is 0).

Thanks to sxvghd for providing the base of this patch, and for testing.


Revision tags: OPENBSD_6_8_BASE
# 1.94 10-Aug-2020 mglocker

Get Elantech v1 touchpad with fw version 0x20022 working.

From sxvghd (at) firemail (dot) cc, on tech@


# 1.93 04-Jul-2020 mglocker

Fix intermittent failing device initialization seen on some Synaptics
devices which has been re-introduced by pms.c revision 1.92.

ok tb@


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Mar-2020 bru

1. Run Synaptics touchpads in plain W-mode. 2. Update the AGM-check.

Enabling extended W-mode is unnecessary as long as pms does not process
the additional packets properly.

Thanks to David Demelier for his reports and tests.

ok anton@ mpi@


# 1.91 22-Jan-2020 mpi

Unbreak !DIAGNOSTIC build.

From Andrius V vezhlys (at) gmail, on bugs@


Revision tags: OPENBSD_6_6_BASE
# 1.90 20-Sep-2019 bru

Extend the identification and validation of elantech-v4 packets to the
"crc-enabled" format.

ok awolk@


# 1.89 19-Aug-2019 bru

Accept more elantech-v4 models, and apply a test for external buttons.

Thanks to Alexander Cronheim.

ok mpi@


Revision tags: OPENBSD_6_5_BASE
# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.95 23-Oct-2020 bru

1. Work around a firmware bug of some Elantech-v1 touchpads.

2. Remove obsolete code from the v1-/v2-packet handlers (coordinate
values are ignored if z is 0).


Revision tags: OPENBSD_6_8_BASE
# 1.94 10-Aug-2020 mglocker

Get Elantech v1 touchpad with fw version 0x20022 working.

From sxvghd (at) firemail (dot) cc, on tech@


# 1.93 04-Jul-2020 mglocker

Fix intermittent failing device initialization seen on some Synaptics
devices which has been re-introduced by pms.c revision 1.92.

ok tb@


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Mar-2020 bru

1. Run Synaptics touchpads in plain W-mode. 2. Update the AGM-check.

Enabling extended W-mode is unnecessary as long as pms does not process
the additional packets properly.

Thanks to David Demelier for his reports and tests.

ok anton@ mpi@


# 1.91 22-Jan-2020 mpi

Unbreak !DIAGNOSTIC build.

From Andrius V vezhlys (at) gmail, on bugs@


Revision tags: OPENBSD_6_6_BASE
# 1.90 20-Sep-2019 bru

Extend the identification and validation of elantech-v4 packets to the
"crc-enabled" format.

ok awolk@


# 1.89 19-Aug-2019 bru

Accept more elantech-v4 models, and apply a test for external buttons.

Thanks to Alexander Cronheim.

ok mpi@


Revision tags: OPENBSD_6_5_BASE
# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.94 10-Aug-2020 mglocker

Get Elantech v1 touchpad with fw version 0x20022 working.

From sxvghd (at) firemail (dot) cc, on tech@


# 1.93 04-Jul-2020 mglocker

Fix intermittent failing device initialization seen on some Synaptics
devices which has been re-introduced by pms.c revision 1.92.

ok tb@


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Mar-2020 bru

1. Run Synaptics touchpads in plain W-mode. 2. Update the AGM-check.

Enabling extended W-mode is unnecessary as long as pms does not process
the additional packets properly.

Thanks to David Demelier for his reports and tests.

ok anton@ mpi@


# 1.91 22-Jan-2020 mpi

Unbreak !DIAGNOSTIC build.

From Andrius V vezhlys (at) gmail, on bugs@


Revision tags: OPENBSD_6_6_BASE
# 1.90 20-Sep-2019 bru

Extend the identification and validation of elantech-v4 packets to the
"crc-enabled" format.

ok awolk@


# 1.89 19-Aug-2019 bru

Accept more elantech-v4 models, and apply a test for external buttons.

Thanks to Alexander Cronheim.

ok mpi@


Revision tags: OPENBSD_6_5_BASE
# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.93 04-Jul-2020 mglocker

Fix intermittent failing device initialization seen on some Synaptics
devices which has been re-introduced by pms.c revision 1.92.

ok tb@


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Mar-2020 bru

1. Run Synaptics touchpads in plain W-mode. 2. Update the AGM-check.

Enabling extended W-mode is unnecessary as long as pms does not process
the additional packets properly.

Thanks to David Demelier for his reports and tests.

ok anton@ mpi@


# 1.91 22-Jan-2020 mpi

Unbreak !DIAGNOSTIC build.

From Andrius V vezhlys (at) gmail, on bugs@


Revision tags: OPENBSD_6_6_BASE
# 1.90 20-Sep-2019 bru

Extend the identification and validation of elantech-v4 packets to the
"crc-enabled" format.

ok awolk@


# 1.89 19-Aug-2019 bru

Accept more elantech-v4 models, and apply a test for external buttons.

Thanks to Alexander Cronheim.

ok mpi@


Revision tags: OPENBSD_6_5_BASE
# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.92 18-Mar-2020 bru

1. Run Synaptics touchpads in plain W-mode. 2. Update the AGM-check.

Enabling extended W-mode is unnecessary as long as pms does not process
the additional packets properly.

Thanks to David Demelier for his reports and tests.

ok anton@ mpi@


# 1.91 22-Jan-2020 mpi

Unbreak !DIAGNOSTIC build.

From Andrius V vezhlys (at) gmail, on bugs@


Revision tags: OPENBSD_6_6_BASE
# 1.90 20-Sep-2019 bru

Extend the identification and validation of elantech-v4 packets to the
"crc-enabled" format.

ok awolk@


# 1.89 19-Aug-2019 bru

Accept more elantech-v4 models, and apply a test for external buttons.

Thanks to Alexander Cronheim.

ok mpi@


Revision tags: OPENBSD_6_5_BASE
# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.91 22-Jan-2020 mpi

Unbreak !DIAGNOSTIC build.

From Andrius V vezhlys (at) gmail, on bugs@


Revision tags: OPENBSD_6_6_BASE
# 1.90 20-Sep-2019 bru

Extend the identification and validation of elantech-v4 packets to the
"crc-enabled" format.

ok awolk@


# 1.89 19-Aug-2019 bru

Accept more elantech-v4 models, and apply a test for external buttons.

Thanks to Alexander Cronheim.

ok mpi@


Revision tags: OPENBSD_6_5_BASE
# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.90 20-Sep-2019 bru

Extend the identification and validation of elantech-v4 packets to the
"crc-enabled" format.

ok awolk@


# 1.89 19-Aug-2019 bru

Accept more elantech-v4 models, and apply a test for external buttons.

Thanks to Alexander Cronheim.

ok mpi@


Revision tags: OPENBSD_6_5_BASE
# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.89 19-Aug-2019 bru

Accept more elantech-v4 models, and apply a test for external buttons.

Thanks to Alexander Cronheim.

ok mpi@


Revision tags: OPENBSD_6_5_BASE
# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.88 26-Jan-2019 mglocker

Wait a bit for the set mode command to complete for Synaptics devices to
make sure that the device doesn't get enabled before, which would make it
fail.
Fixes regular occurring 'not in sync yet, discard input' issue seen on
ThinkPad X1 Gen6.

ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.87 13-May-2018 bru

Add support for Elantech trackpoints to pms. Extend the list of
"IC types" that identify Elantech-V4 touchpads.

Thanks to Ryan Lennox for help and testing.

ok mpi@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.86 29-Apr-2018 krw

'juming' -> 'jumping' in comment.

Pointed out by Ryan Lennox via tech@


Revision tags: OPENBSD_6_3_BASE
# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.85 29-Jan-2018 bru

pms: minor cleanups in the alps code.

1. Update the ALPS_*_BEZEL values, which don't match the actual limits
accurately. The new values are used by Linux for all models with the
protocols "V1" and "V2".

2. Models with the ID 0x7331 are not supported properly, remove it
from the list.

3. Report to wsmouse that multiple contacts aren't recognized.


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@


# 1.84 04-Dec-2017 robert

add the alps touchpad that can be found in the ideapad 710s

ok mpi@


# 1.83 14-Nov-2017 anton

Detect touchpad reset announcements. On rare occasions, the touchpad is reset
due to power failure and an announcement is transmitted as input by the device
making it detectable. At this point, the device must be re-enabled to continue
working since any configuration done prior to the reset is lost.

Detection is implemented using a watchdog and enabled for all protocols. So far,
the announcement has been observed on Synaptics by me and on Elantech v4 by
bru@. Extra care has been taken to handle potential false positives: when the
announcement byte sequence is part of a valid input packet.

with help and ok bru@, mpi@


# 1.82 14-Nov-2017 anton

Print out the offending data causing pms sync to fail.

ok bru@, mpi@ (as part of a larger diff)


# 1.81 28-Oct-2017 bru

Adapt the Elantech handlers (v1-3) to the new wsmouse infrastructure.

The new versions use wsmouse_configure, and leave compat-mode handling
to wsmouse.

ok stsp


Revision tags: OPENBSD_6_2_BASE
# 1.80 26-Aug-2017 bru

bug fix: intialize variables in synaptics_get_hwinfo


# 1.79 25-Aug-2017 bru

Query the lower coordinate limits.


# 1.78 21-Jul-2017 bru

Show Synaptics Model IDs.


# 1.77 18-Jun-2017 bru

pms/alps: configure compat mode


# 1.76 06-Jun-2017 bru

Set the weak variant of hysteresis as default.


# 1.75 08-May-2017 bru

improved coordinate filters

ok mpi@


Revision tags: OPENBSD_6_1_BASE
# 1.74 06-Mar-2017 mpi

Use nitems() when passing all known parameters to wsmouse_configure().

ok bru@


# 1.73 27-Feb-2017 bru

pms/elantech-v4: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.72 27-Feb-2017 bru

pms/synaptics: configure wsmouse for handling compat-mode

ok @matthieu @stsp @mpi


# 1.71 23-Oct-2016 bru

Improved parameter handling in wsmouse and new ioctls for reading and
setting parameter values.

ok matthieu@


Revision tags: OPENBSD_6_0_BASE
# 1.70 22-May-2016 bru

Use the new input functions of wsmouse in mouse and touchscreen drivers.

ok kettenis@


# 1.69 30-Mar-2016 bru

Add support for multitouch input to wsmouse.

This change adds new input-processing functions to wsmouse and
adapts the touchpad drivers.

ok mpi@, shadchin@


# 1.68 27-Feb-2016 mmcc

pakets -> packets


Revision tags: OPENBSD_5_9_BASE
# 1.67 05-Sep-2015 bru

Support Synaptics touchpads without W mode.

Emulate W mode if a Synaptics model doesn't provide it, and check
for the success of the resolution query during setup.

ok shadchin@, mpi@


# 1.66 05-Sep-2015 bru

Improve tap-and-drag detection for ALPS touchpads.

The ALPS mechanism for gesture detection can produce long delays between
a packet that signals a tap and the next packet, which either signals
the end of the gesture or the start of a drag-operation. The time spans
can exceed the timeouts used by the generic detection mechanism in the
synaptics driver. Reporting both the touch and the release event when
the second packet has arrived ensures that the tap will be recognized.

ok mpi@ shadchin@


# 1.65 23-Aug-2015 deraadt

fairly trivial sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.64 20-Jul-2015 kspillner

Tweak previous; the Synaptics TrackPoint in my ThinkPad T500 works again.

ok krw@


# 1.63 19-Jul-2015 krw

Don't emit values for 'width' that

/usr/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c

doesn't understand.

'Fixes' synaptics trackpad in Dell L400 laptop so the cursor can
be moved in X. Problem noted and experimental Dell L400 donated by
Paolo Aglialoro. Thanks!

ok miod@ mpi@ jcs@


# 1.62 08-Jun-2015 stsp

pms(4): Don't match Elantech v4 devices with firmware versions 0xX7XXXX.
Apparently we don't support these touchpads properly so leave them in
PS/2 compat mode. Regression reported by Remi Locherer on bugs@. And stop
matching devices with firmware versions higher than 0xX8XXXX since we cannot
be sure they work.
ok mpi@


# 1.61 25-May-2015 mpi

Match newer elantech v4 touchpads, logic taken from Linux.

Based on a submission from and ok jcs@.


# 1.60 04-May-2015 mpi

Print irq informations in pckbc_set_inputhandler().

ok miod@


# 1.59 10-Apr-2015 stsp

Add support for CRC-enabled elantech v3 touchpads.
Patch by Fasse <fasse.f2@gmail.com>
ok mpi@


# 1.58 26-Mar-2015 jsg

Use the 0x10 extended capability to determine if the trackstick
buttons are wired to the trackpad and need to be re-routed to the
trackstick. Without this change the buttons on 2015 thinkpads
get picked up as extended buttons that show up as scroll up/down.

Remove the X1 Carbon 2015 (LEN0048) and X250 (LEN0046) from the
top button area/soft buttons quirks list. Also avoid using the
quirk list entirely if the capability bit is set.

Based on work from jcs@ with feedback from mpi@
ok mpi@ jcs@


Revision tags: OPENBSD_5_7_BASE
# 1.57 09-Feb-2015 mpi

Complete rewrite of the Elantech clickpads v4 packet parser in order to
support "click-and-drag".

This implements a simple filter to keep track of a moving finger on the
clickpad. For the moment wsmouse(4) and wscons(4) are still unaware of
multitouch events and pms(4) has to do the translation, but this is a
small steps in this direction.

All the good work has been done by Ulf Brosziewski.


# 1.56 15-Jan-2015 jsg

Define a new wscons mouse type for Synaptics clickpad devices that lack
physical buttons. This will be used if the acpi pnpid for the mouse
matches a list provided by Synaptics found in Linux.

Combined with the xenocara changes this will remove the need for an xorg
config file for the x240/t440/t540 generation of thinkpads.

ok matthieu@ shadchin@ kettenis@


# 1.55 07-Jan-2015 mpi

Only MS IntelliMouse have a Z axis, prevent a false positive triggered
by -Wuninitialized reported by jsg@.

ok stsp@


# 1.54 29-Aug-2014 shadchin

Fix checking sync for old synaptics touchpad (ver 5.9)
From Thierry Deval <thierry at deval dot be>

ok mpi@


# 1.53 19-Aug-2014 mpi

Make sure state changes are properly serialized.

When pms(4) is attached to a touchpad it generally presents two different
wsmouse(4) devices: one for the touchpad itself and one for the clitpad
and/or some interleaved packets. But since both devices are writing to
the same pckbc slot, a race can occur if they try to change the state at
the same time.

So prevent two process opening the two /dev/wsmouse* node at the same time
to corrupt the magic sequences needed to enable/disable the touchpad.

ok schadchin@


Revision tags: OPENBSD_5_6_BASE
# 1.52 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.51 18-May-2014 stsp

Fix tail packet check in elantech v3 touchpad code. Due to a typo this
code was masking out bits which were also tested in the same expression.
Reported by cppcheck via jsg@ (Expression '(X & 0xfc) != 0x2' is always true).
Tested with Elantech Touchpad, version 3, firmware 0x250f00.


# 1.50 25-Apr-2014 mpi

Do no reprobe for a supported protocol when enabling a pointing
device of type PMS_STANDARD, probing during autoconf(9) is enough!.

In such case, the device can be a simple PS/2 mouse, a unsupported
touchpad or a downgraded touchpad if something bad happened. But
it is very unlikely that reprobing will improve the situation and
transform a standard mouse into a multitouch-aware touchpad ;)

This fixes the 12 seconds delay seen on various Dell laptops (E4310
and Latitude D630) when starting Xorg, reported by K��rlis Mi��elsons
on bugs@.

ok stsp@, dcoppa@, shadchin@


Revision tags: OPENBSD_5_5_BASE
# 1.49 30-Oct-2013 shadchin

Fix jagged diagonal lines (kernel part)

Send WSCONS_EVENT_SYNC every time you call wsmouse_input(). Used to synchronize
and separate events into packets of input data changes occurring at the same
moment in time. For example, motion of a mouse may set the DELTA_X and DELTA_Y
values for one motion, then emit a SYNC.

ok matthieu@. tested edd@, Henri Kemppainen and Alf Schlichting.


# 1.48 20-Sep-2013 stsp

Use a working magic sequence to configure absolute mode for elantech v2.
The synaptics driver now attaches to elantech v2 touchpads. It seems these
pads were always falling back to compat mode, which went unnoticed until r1.47.

Fix based on a patch submitted by Cedric Tessier:
http://marc.info/?l=openbsd-bugs&m=136904396518528&w=2
which in turn was probably based on parts of this patch:
https://launchpadlibrarian.net/73099683/elantech.patch
which updates the Linux driver code but isn't part of Torvald's Linux.

Behaviour of elantech firmware versions seems to vary quite a bit so print
the firmware version at attach time for reference in future bug reports.

Fix tested by frantisek holop and Peter J. Philipp.
ok mpi@


# 1.47 03-Sep-2013 stsp

When /dev/wsmouse is opened right after resume, some synaptics touchpads
are still taking time to wake up. So make the pms(4) driver wait a little
longer before giving up on them. Fixes mouse after resume on my x130e TP.
ok mpi, earlier versions tested by weerd with no regressions seen


# 1.46 03-Sep-2013 mpi

Only free the per-protocol descriptor if a touchpad cannot be correctly
identified during attach. This prevents the driver to downgrade itself
to use the standard mouse protocol and reattach a new wsmouse child if
something bad happens when we re-query the hardware (during resume for
example).

Discussed with and ok stsp@


Revision tags: OPENBSD_5_4_BASE
# 1.45 16-Jul-2013 mpi

Correctly initialized the width value to 0 instead of passing garbage
to wsmouse_input() when no finger are reported.

Pointed out by Maxime Villard.


# 1.44 28-Jun-2013 jcs

send proper z value to elantech_send_input in previous v4 commit

pointed out by Owain G. Ainsworth


# 1.43 31-May-2013 jcs

add elantech v4 (clickpad) support
tested on an asus ux21a

ok mpi@ stsp@


# 1.42 23-May-2013 tobias

Revert Active PS/2 support for now, until we find a solution suitable
for chipsets which stopped working.

ok mpi


# 1.41 20-Apr-2013 tobias

Enable active PS/2 multiplexing if available.
Supported for i386 and amd64 except SMALL_KERNEL.

Based on Miod's former work on this subject.

ok mpi


# 1.40 15-Apr-2013 mpi

Revert r1.37 now that we stop after the first matching protocol, tested
by Peter J. Philipp, thanks.


# 1.39 15-Apr-2013 mpi

Move the IntelliMouse protocol definition after Elantech ones, because some
touchpads support both of them and we want to pick the latter.

Reported by Peter J. Philipp, thanks.


# 1.38 15-Apr-2013 mpi

Don't probe for all supported protocols this can confuse some touchpads and
makes it harder to pick the right protocol if a device answers to more than
one magic sequence.

Tested by many on tech@, ok shadchin@


# 1.37 18-Mar-2013 stsp

Once we've detected an elantech touchpad, stop probing for other hardware
versions. Fixes a problem reported by Peter J. Philipp where the pms driver
spits out "not in sync yet" messages after attaching to elantech v2 hardware.
Fix tested by me on v3 hardware, and by Peter on v2 hardware.
ok mpi@ shadchin@


# 1.36 16-Mar-2013 stsp

Enable untested Elantech touchpad v1 and v2 code. I'd like some test reports.
ok mpi@ shadchin@


Revision tags: OPENBSD_5_3_BASE
# 1.35 05-Nov-2012 shadchin

Fix memory leak in error paths for synaptics and alps (pointed stsp@).
Also small simplify elantech part.

ok stsp@, mpi@


# 1.34 03-Nov-2012 stsp

Handle elantech touchpad buttons in a common code path for all
hardware variants. ok shadchin mikeb mpi


# 1.33 02-Nov-2012 stsp

Don't OR flags into an uninitialized variable in elantech hardware v1 code.
Fix by oga, via mikeb.


# 1.32 29-Oct-2012 stsp

Add support for Elantech touchpads to pms(4). This allows the X synaptics(4)
input driver to configure these touchpads properly, e.g. toggle tap-to-click,
two-finger scrolling, edge-scrolling, etc. So far these pads were working
only in PS/2 mouse compatibility mode.

Support for up to hardware version 3 has been implemented. But only version 3
has been tested so versions 1 and 2 remain disabled via #ifdef notyet until
someone tests (bugs in this code could seriously mess up the mouse and I
don't want to end up shipping such bugs in 5.3).

help and ok mpi@ shadchin@


Revision tags: OPENBSD_5_2_BASE
# 1.31 22-Jul-2012 shadchin

Fix for ClickPad. On issue pointed gilles@ and matthieu@

ok gilles@, matthieu@, mpi@, miod@, deraadt@


# 1.30 01-Jul-2012 mpi

Pass a width value corresponding to one finger for ALPS touchpads when the
reported pressure is non-null. Fix the use of ALPS touchpads with recent
(>1.6) xf86-input-synaptics drivers, issue reported by janis at cieti lv.

Tested by yasuoka@ and janis, ok shadchin@


# 1.29 28-Apr-2012 tobias

Added yet another magic for my ALPS touchpad.

ok mpi@


# 1.28 05-Mar-2012 shadchin

Adds support for a slightly different version of the ALPS protocol,
which send 'interleaved' PS2 packets in between absolute ALPS packets.
Dell laptops (E6xxx and E5500 at least) have this kind of touchpad.

ok and some rework mpi@, tested okan@.


Revision tags: OPENBSD_5_1_BASE
# 1.27 28-Jan-2012 mpi

Blacklist a dualpoint model which clitpad sends non compatible PS2 packets.

Issue reported by deraadt@


# 1.26 04-Dec-2011 shadchin

renaming synaptics_pt_* -> pms_sec_*
(synaptics and alps uses this for trackpoint)

ok mpi@


# 1.25 03-Dec-2011 mpi

Correctly handle clitpad packets for some ALPS models.

reported by espie@, not reported by miod@

with and ok shadchin@, ok espie@


# 1.24 17-Oct-2011 mpi

Blacklist alps devices that might have a clitpad untill the driver get fixed


# 1.23 17-Oct-2011 mpi

Fix the synchronization of some alps pads, issue reported by Bryan (brakeb)
on misc@

Similar diff tested by okan@ and Mathieu (ptr.jetable)

ok shadchin@


# 1.22 04-Oct-2011 mpi

Add support for ALPS touchpads.

This also fix the "slow touchpad" problem due to the fact that some ALPS
devices respond to some Synaptics messages and stay in un half-configured
state.

Tested by Rivo Nurges, armani@, shadchin@ and matthieu@

ok shadchin@


# 1.21 24-Aug-2011 shadchin

revert the last commit. pms_enable_alps() does not guarantee
the accuracy detection ALPS.

ok mpi@


# 1.20 22-Aug-2011 shadchin

Adding stub for ALPS touchpad, which not supported yet.
This fixed "react strangely" when the pms driver probes
for a synaptic-compatible touchpad.

Tested and ok mpi@


# 1.19 17-Aug-2011 shadchin

Adding support Synaptics touchpad. Thanks all for test.

ok miod@, matthieu@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.18 03-Jan-2011 shadchin

remove sc->sc_kbcslot, as is always PCKBC_AUX_SLOT
ok krw, miod


# 1.17 27-Dec-2010 shadchin

cleanup pms_enable_intelli: magic numbers -> defines
ok krw, miod


# 1.16 24-Dec-2010 shadchin

fix crash:
after boot and before the first activation (wsmoused or X),
sc->protocol is not initialized, and any call ioctl lead to crash
(example 'wsconsctl -a')

thanks and ok krw@


# 1.15 23-Dec-2010 shadchin

Add a common interface for various devices

This is to make it easier to add additional mice types in future

ok krw@, miod@, nicm@


# 1.14 15-Nov-2010 krw

Aesthetic improvements to make it appear more normal and knf'y.

No functional change. From Alexandr Scadchin again.


# 1.13 15-Nov-2010 krw

More cleanup. Add DEVNAME() macro and generic functions for various
actions (set/get/reset/enable/disable) to wrap pms_cmd() invocations.

No functional change. From Alexandr Scadchin again.


# 1.12 05-Nov-2010 krw

Minor code cleanups. No functional change. From Alexandr Shadchin.

ok nicm@


# 1.11 19-Oct-2010 krw

Unify some error messages to simplify reset code. No functional
change.

ok nicm@

From shadchin.


# 1.10 17-Oct-2010 krw

Ansify non-ansified function definitions. No functional change.

ok nicm@

From shadchin.


# 1.9 16-Oct-2010 krw

Remove some duplicated code. No need to flush/reset at attach and then
again at PMS_STATE_CHANGE events.

Tested my myself, ian@ and nicm@ without regressions on usual
problematic machines.

From shadchin.


# 1.8 07-Oct-2010 krw

Fix some pms(4) vs wsmoused issues. From Alexandr Shadchin via
tech@. Tested on the usual problematic machines by myself, nicm@
and ian@.


# 1.7 02-Oct-2010 krw

Fix Ian@'s pms keyboard/mouse while keeping my eeePC working.

For posterity: there is one time when pckbc commands must be thrown,
and one time when pckbc commands must be polled.

Diff from shadchin.

ok miod@


# 1.6 29-Sep-2010 deraadt

The attach function can return 1 now because there is no more priority
scheme relating to pmsi.
from alexandr.shadchin@gmail.com


# 1.5 27-Sep-2010 miod

Make sure the SEND_DEV_ID command is sent synchronously, so the response buffer
is valid when we look at it. Repairs intellimouse (former pmsi) operation.


# 1.4 26-Sep-2010 miod

Merge pmsi(4) into pms(4). From Alexandr Shadchin on tech@.


Revision tags: OPENBSD_4_8_BASE
# 1.3 22-Jul-2010 deraadt

Toggle the mouse through the disabled and enabled states when suspending
and restoring. Fixes most mice.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.2 17-Oct-2007 deraadt

use NULL to point to the response buffer, which avoids confusion; ok fgsch


Revision tags: OPENBSD_4_2_BASE
# 1.1 01-Aug-2007 kettenis

Correct a 10-year old typo inherited from NetBSD by renaming psm.c,
psm_intelli.c and psmreg.h into pms.c, pms_intelli.c and pmsreg.h.

ok deraadt@