2 * Copyright (c) 1992, 1993 Erik Forsberg.
3 * Copyright (c) 1996, 1997 Kazutaka YOKOTA.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
19 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 * Ported to 386bsd Oct 17, 1992
25 * Sandi Donno, Computer Science, University of Cape Town, South Africa
26 * Please send bug reports to sandi@cs.uct.ac.za
28 * Thanks are also due to Rick Macklem, rick@snowhite.cis.uoguelph.ca -
29 * although I was only partially successful in getting the alpha release
30 * of his "driver for the Logitech and ATI Inport Bus mice for use with
31 * 386bsd and the X386 port" to work with my Microsoft mouse, I nevertheless
32 * found his code to be an invaluable reference when porting this driver
35 * Further modifications for latest 386BSD+patchkit and port to NetBSD,
36 * Andrew Herbert <andrew@werple.apana.org.au> - 8 June 1993
38 * Cloned from the Microsoft Bus Mouse driver, also by Erik Forsberg, by
39 * Andrew Herbert - 12 June 1993
41 * Modified for PS/2 mouse by Charles Hannum <mycroft@ai.mit.edu>
44 * Modified for PS/2 AUX mouse by Shoji Yuen <yuen@nuie.nagoya-u.ac.jp>
47 * Hardware access routines and probe logic rewritten by
48 * Kazutaka Yokota <yokota@zodiac.mech.utsunomiya-u.ac.jp>
49 * - 3, 14, 22 October 1996.
50 * - 12 November 1996. IOCTLs and rearranging `psmread', `psmioctl'...
51 * - 14, 30 November 1996. Uses `kbdio.c'.
52 * - 13 December 1996. Uses queuing version of `kbdio.c'.
53 * - January/February 1997. Tweaked probe logic for
54 * HiNote UltraII/Latitude/Armada laptops.
55 * - 30 July 1997. Added APM support.
56 * - 5 March 1997. Defined driver configuration flags (PSM_CONFIG_XXX).
57 * Improved sync check logic.
58 * Vendor specific support routines.
61 #include <sys/cdefs.h>
62 __FBSDID("$FreeBSD$");
66 #include "opt_evdev.h"
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/kernel.h>
71 #include <sys/module.h>
74 #include <sys/filio.h>
75 #include <sys/mutex.h>
77 #include <sys/sigio.h>
78 #include <sys/signalvar.h>
79 #include <sys/syslog.h>
80 #include <machine/bus.h>
82 #include <sys/selinfo.h>
83 #include <sys/sysctl.h>
87 #include <sys/limits.h>
88 #include <sys/mouse.h>
89 #include <machine/resource.h>
92 #include <isa/isavar.h>
96 #include <dev/evdev/evdev.h>
97 #include <dev/evdev/input.h>
100 #include <dev/atkbdc/atkbdcreg.h>
101 #include <dev/atkbdc/psm.h>
104 * Driver specific options: the following options may be set by
105 * `options' statements in the kernel configuration file.
110 #define PSM_DEBUG 0 /*
111 * logging: 0: none, 1: brief, 2: verbose
112 * 3: sync errors, 4: all packets
115 #define VLOG(level, args) do { \
116 if (verbose >= level) \
120 #ifndef PSM_INPUT_TIMEOUT
121 #define PSM_INPUT_TIMEOUT 2000000 /* 2 sec */
124 #ifndef PSM_TAP_TIMEOUT
125 #define PSM_TAP_TIMEOUT 125000
128 #ifndef PSM_TAP_THRESHOLD
129 #define PSM_TAP_THRESHOLD 25
132 /* end of driver specific options */
134 #define PSMCPNP_DRIVER_NAME "psmcpnp"
136 struct psmcpnp_softc {
140 PSMCPNP_TOPBUTTONPAD,
141 } type; /* Based on PnP ID */
145 #define PSM_BUFSIZE 960
146 #define PSM_SMALLBUFSIZE 240
148 /* operation levels */
149 #define PSM_LEVEL_BASE 0
150 #define PSM_LEVEL_STANDARD 1
151 #define PSM_LEVEL_NATIVE 2
152 #define PSM_LEVEL_MIN PSM_LEVEL_BASE
153 #define PSM_LEVEL_MAX PSM_LEVEL_NATIVE
155 /* Active PS/2 multiplexing */
156 #define PSM_NOMUX (-1)
158 /* Logitech PS2++ protocol */
159 #define MOUSE_PS2PLUS_CHECKBITS(b) \
160 ((((b[2] & 0x03) << 2) | 0x02) == (b[1] & 0x0f))
161 #define MOUSE_PS2PLUS_PACKET_TYPE(b) \
162 (((b[0] & 0x30) >> 2) | ((b[1] & 0x30) >> 4))
165 typedef struct ringbuf {
166 int count; /* # of valid elements in the buffer */
167 int head; /* head pointer */
168 int tail; /* tail poiner */
169 u_char buf[PSM_BUFSIZE];
173 typedef struct packetbuf {
174 u_char ipacket[16]; /* interim input buffer */
175 int inputbytes; /* # of bytes in the input buffer */
178 #ifndef PSM_PACKETQUEUE
179 #define PSM_PACKETQUEUE 128
183 * Synaptics command definitions.
185 #define SYNAPTICS_READ_IDENTITY 0x00
186 #define SYNAPTICS_READ_MODES 0x01
187 #define SYNAPTICS_READ_CAPABILITIES 0x02
188 #define SYNAPTICS_READ_MODEL_ID 0x03
189 #define SYNAPTICS_READ_SERIAL_PREFIX 0x06
190 #define SYNAPTICS_READ_SERIAL_SUFFIX 0x07
191 #define SYNAPTICS_READ_RESOLUTIONS 0x08
192 #define SYNAPTICS_READ_EXTENDED 0x09
193 #define SYNAPTICS_READ_CAPABILITIES_CONT 0x0c
194 #define SYNAPTICS_READ_MAX_COORDS 0x0d
195 #define SYNAPTICS_READ_DELUXE_LED 0x0e
196 #define SYNAPTICS_READ_MIN_COORDS 0x0f
198 typedef struct synapticsinfo {
199 struct sysctl_ctx_list sysctl_ctx;
200 struct sysctl_oid *sysctl_tree;
201 int directional_scrolls;
202 int two_finger_scroll;
219 int weight_previous_na;
220 int weight_len_squared;
228 int vscroll_ver_area;
229 int vscroll_hor_area;
230 int vscroll_min_delta;
239 int three_finger_drag;
243 typedef struct synapticspacket {
248 #define SYNAPTICS_PACKETQUEUE 10
249 #define SYNAPTICS_QUEUE_CURSOR(x) \
250 (x + SYNAPTICS_PACKETQUEUE) % SYNAPTICS_PACKETQUEUE
252 #define SYNAPTICS_VERSION_GE(synhw, major, minor) \
253 ((synhw).infoMajor > (major) || \
254 ((synhw).infoMajor == (major) && (synhw).infoMinor >= (minor)))
256 typedef struct smoother {
257 synapticspacket_t queue[SYNAPTICS_PACKETQUEUE];
270 typedef struct gesture {
276 int zmax; /* maximum pressure value */
277 struct timeval taptimeout; /* tap timeout for touchpads */
281 TRACKPOINT_SYSCTL_SENSITIVITY,
282 TRACKPOINT_SYSCTL_NEGATIVE_INERTIA,
283 TRACKPOINT_SYSCTL_UPPER_PLATEAU,
284 TRACKPOINT_SYSCTL_BACKUP_RANGE,
285 TRACKPOINT_SYSCTL_DRAG_HYSTERESIS,
286 TRACKPOINT_SYSCTL_MINIMUM_DRAG,
287 TRACKPOINT_SYSCTL_UP_THRESHOLD,
288 TRACKPOINT_SYSCTL_THRESHOLD,
289 TRACKPOINT_SYSCTL_JENKS_CURVATURE,
290 TRACKPOINT_SYSCTL_Z_TIME,
291 TRACKPOINT_SYSCTL_PRESS_TO_SELECT,
292 TRACKPOINT_SYSCTL_SKIP_BACKUPS
295 typedef struct trackpointinfo {
296 struct sysctl_ctx_list sysctl_ctx;
297 struct sysctl_oid *sysctl_tree;
312 typedef struct finger {
319 #define PSM_FINGERS 2 /* # of processed fingers */
320 #define PSM_FINGER_IS_PEN (1<<0)
321 #define PSM_FINGER_FUZZY (1<<1)
322 #define PSM_FINGER_DEFAULT_P tap_threshold
323 #define PSM_FINGER_DEFAULT_W 1
324 #define PSM_FINGER_IS_SET(f) ((f).x != -1 && (f).y != -1 && (f).p != 0)
325 #define PSM_FINGER_RESET(f) do { \
326 (f) = (finger_t) { .x = -1, .y = -1, .p = 0, .w = 0, .flags = 0 }; \
329 typedef struct elantechhw {
347 /* minimum versions supported by this driver */
348 #define ELANTECH_HW_IS_V1(fwver) ((fwver) < 0x020030 || (fwver) == 0x020600)
350 #define ELANTECH_MAGIC(magic) \
351 ((magic)[0] == 0x3c && (magic)[1] == 0x03 && \
352 ((magic)[2] == 0xc8 || (magic)[2] == 0x00))
354 #define ELANTECH_FW_ID 0x00
355 #define ELANTECH_FW_VERSION 0x01
356 #define ELANTECH_CAPABILITIES 0x02
357 #define ELANTECH_SAMPLE 0x03
358 #define ELANTECH_RESOLUTION 0x04
359 #define ELANTECH_REG_READ 0x10
360 #define ELANTECH_REG_WRITE 0x11
361 #define ELANTECH_REG_RDWR 0x00
362 #define ELANTECH_CUSTOM_CMD 0xf8
365 #define ELANTECH_MAX_FINGERS 5
367 #define ELANTECH_MAX_FINGERS PSM_FINGERS
370 #define ELANTECH_FINGER_MAX_P 255
371 #define ELANTECH_FINGER_MAX_W 15
372 #define ELANTECH_FINGER_SET_XYP(pb) (finger_t) { \
373 .x = (((pb)->ipacket[1] & 0x0f) << 8) | (pb)->ipacket[2], \
374 .y = (((pb)->ipacket[4] & 0x0f) << 8) | (pb)->ipacket[5], \
375 .p = ((pb)->ipacket[1] & 0xf0) | (((pb)->ipacket[4] >> 4) & 0x0f), \
376 .w = PSM_FINGER_DEFAULT_W, \
382 ELANTECH_PKT_TRACKPOINT,
383 ELANTECH_PKT_V2_COMMON,
384 ELANTECH_PKT_V2_2FINGER,
386 ELANTECH_PKT_V4_STATUS,
387 ELANTECH_PKT_V4_HEAD,
388 ELANTECH_PKT_V4_MOTION
391 #define ELANTECH_PKT_IS_TRACKPOINT(pb) (((pb)->ipacket[3] & 0x0f) == 0x06)
392 #define ELANTECH_PKT_IS_DEBOUNCE(pb, hwversion) ((hwversion) == 4 ? 0 : \
393 (pb)->ipacket[0] == ((hwversion) == 2 ? 0x84 : 0xc4) && \
394 (pb)->ipacket[1] == 0xff && (pb)->ipacket[2] == 0xff && \
395 (pb)->ipacket[3] == 0x02 && (pb)->ipacket[4] == 0xff && \
396 (pb)->ipacket[5] == 0xff)
397 #define ELANTECH_PKT_IS_V2(pb) \
398 (((pb)->ipacket[0] & 0x0c) == 0x04 && ((pb)->ipacket[3] & 0x0f) == 0x02)
399 #define ELANTECH_PKT_IS_V3_HEAD(pb, hascrc) ((hascrc) ? \
400 ((pb)->ipacket[3] & 0x09) == 0x08 : \
401 ((pb)->ipacket[0] & 0x0c) == 0x04 && ((pb)->ipacket[3] & 0xcf) == 0x02)
402 #define ELANTECH_PKT_IS_V3_TAIL(pb, hascrc) ((hascrc) ? \
403 ((pb)->ipacket[3] & 0x09) == 0x09 : \
404 ((pb)->ipacket[0] & 0x0c) == 0x0c && ((pb)->ipacket[3] & 0xce) == 0x0c)
405 #define ELANTECH_PKT_IS_V4(pb, hascrc) ((hascrc) ? \
406 ((pb)->ipacket[3] & 0x08) == 0x00 : \
407 ((pb)->ipacket[0] & 0x0c) == 0x04 && ((pb)->ipacket[3] & 0x1c) == 0x10)
409 typedef struct elantechaction {
410 finger_t fingers[ELANTECH_MAX_FINGERS];
415 /* driver control block */
416 struct psm_softc { /* Driver status information */
418 struct selinfo rsel; /* Process selecting for Input */
419 u_char state; /* Mouse driver state */
420 int config; /* driver configuration flags */
421 int flags; /* other flags */
422 KBDC kbdc; /* handle to access kbd controller */
423 struct resource *intr; /* IRQ resource */
424 void *ih; /* interrupt handle */
425 mousehw_t hw; /* hardware information */
426 synapticshw_t synhw; /* Synaptics hardware information */
427 synapticsinfo_t syninfo; /* Synaptics configuration */
428 smoother_t smoother[PSM_FINGERS]; /* Motion smoothing */
429 gesture_t gesture; /* Gesture context */
430 elantechhw_t elanhw; /* Elantech hardware information */
431 elantechaction_t elanaction; /* Elantech action context */
432 int tphw; /* TrackPoint hardware information */
433 trackpointinfo_t tpinfo; /* TrackPoint configuration */
434 mousemode_t mode; /* operation mode */
435 mousemode_t dflt_mode; /* default operation mode */
436 mousestatus_t status; /* accumulated mouse movement */
437 ringbuf_t queue; /* mouse status queue */
438 packetbuf_t pqueue[PSM_PACKETQUEUE]; /* mouse data queue */
439 int pqueue_start; /* start of data in queue */
440 int pqueue_end; /* end of data in queue */
441 int button; /* the latest button state */
442 int xold; /* previous absolute X position */
443 int yold; /* previous absolute Y position */
444 int xaverage; /* average X position */
445 int yaverage; /* average Y position */
446 int squelch; /* level to filter movement at low speed */
447 int syncerrors; /* # of bytes discarded to synchronize */
448 int pkterrors; /* # of packets failed during quaranteen. */
449 int fpcount; /* forcePad valid packet counter */
450 struct timeval inputtimeout;
451 struct timeval lastsoftintr; /* time of last soft interrupt */
452 struct timeval lastinputerr; /* time last sync error happened */
453 struct timeval idletimeout;
454 packetbuf_t idlepacket; /* packet to send after idle timeout */
455 int watchdog; /* watchdog timer flag */
456 struct callout callout; /* watchdog timer call out */
457 struct callout softcallout; /* buffer timer call out */
462 struct sigio *async; /* Processes waiting for SIGIO */
463 int extended_buttons;
464 int muxport; /* MUX port with attached Synaptics */
465 u_char muxsave[3]; /* 3->6 byte proto conversion buffer */
466 int muxtpbuttons; /* Touchpad button state */
467 int muxmsbuttons; /* Mouse (trackpoint) button state */
468 struct timeval muxmidtimeout; /* middle button supression timeout */
470 struct evdev_dev *evdev_a; /* Absolute reporting device */
471 struct evdev_dev *evdev_r; /* Relative reporting device */
474 static devclass_t psm_devclass;
476 /* driver state flags (state) */
477 #define PSM_VALID 0x80
478 #define PSM_OPEN 1 /* Device is open */
479 #define PSM_ASLP 2 /* Waiting for mouse data */
480 #define PSM_SOFTARMED 4 /* Software interrupt armed */
481 #define PSM_NEED_SYNCBITS 8 /* Set syncbits using next data pkt */
482 #define PSM_EV_OPEN_R 0x10 /* Relative evdev device is open */
483 #define PSM_EV_OPEN_A 0x20 /* Absolute evdev device is open */
485 /* driver configuration flags (config) */
486 #define PSM_CONFIG_RESOLUTION 0x000f /* resolution */
487 #define PSM_CONFIG_ACCEL 0x00f0 /* acceleration factor */
488 #define PSM_CONFIG_NOCHECKSYNC 0x0100 /* disable sync. test */
489 #define PSM_CONFIG_NOIDPROBE 0x0200 /* disable mouse model probe */
490 #define PSM_CONFIG_NORESET 0x0400 /* don't reset the mouse */
491 #define PSM_CONFIG_FORCETAP 0x0800 /* assume `tap' action exists */
492 #define PSM_CONFIG_IGNPORTERROR 0x1000 /* ignore error in aux port test */
493 #define PSM_CONFIG_HOOKRESUME 0x2000 /* hook the system resume event */
494 #define PSM_CONFIG_INITAFTERSUSPEND 0x4000 /* init the device at the resume event */
496 #define PSM_CONFIG_FLAGS \
497 (PSM_CONFIG_RESOLUTION | \
499 PSM_CONFIG_NOCHECKSYNC | \
500 PSM_CONFIG_NOIDPROBE | \
501 PSM_CONFIG_NORESET | \
502 PSM_CONFIG_FORCETAP | \
503 PSM_CONFIG_IGNPORTERROR | \
504 PSM_CONFIG_HOOKRESUME | \
505 PSM_CONFIG_INITAFTERSUSPEND)
507 /* other flags (flags) */
508 #define PSM_FLAGS_FINGERDOWN 0x0001 /* VersaPad finger down */
510 #define kbdcp(p) ((atkbdc_softc_t *)(p))
511 #define ALWAYS_RESTORE_CONTROLLER(kbdc) !(kbdcp(kbdc)->quirks \
512 & KBDC_QUIRK_KEEP_ACTIVATED)
515 static int tap_enabled = -1;
516 static int verbose = PSM_DEBUG;
517 static int synaptics_support = 1;
518 static int trackpoint_support = 1;
519 static int elantech_support = 1;
521 /* for backward compatibility */
522 #define OLD_MOUSE_GETHWINFO _IOR('M', 1, old_mousehw_t)
523 #define OLD_MOUSE_GETMODE _IOR('M', 2, old_mousemode_t)
524 #define OLD_MOUSE_SETMODE _IOW('M', 3, old_mousemode_t)
526 typedef struct old_mousehw {
533 typedef struct old_mousemode {
540 #define SYN_OFFSET(field) offsetof(struct psm_softc, syninfo.field)
542 SYNAPTICS_SYSCTL_MIN_PRESSURE = SYN_OFFSET(min_pressure),
543 SYNAPTICS_SYSCTL_MAX_PRESSURE = SYN_OFFSET(max_pressure),
544 SYNAPTICS_SYSCTL_MAX_WIDTH = SYN_OFFSET(max_width),
545 SYNAPTICS_SYSCTL_MARGIN_TOP = SYN_OFFSET(margin_top),
546 SYNAPTICS_SYSCTL_MARGIN_RIGHT = SYN_OFFSET(margin_right),
547 SYNAPTICS_SYSCTL_MARGIN_BOTTOM = SYN_OFFSET(margin_bottom),
548 SYNAPTICS_SYSCTL_MARGIN_LEFT = SYN_OFFSET(margin_left),
549 SYNAPTICS_SYSCTL_NA_TOP = SYN_OFFSET(na_top),
550 SYNAPTICS_SYSCTL_NA_RIGHT = SYN_OFFSET(na_right),
551 SYNAPTICS_SYSCTL_NA_BOTTOM = SYN_OFFSET(na_bottom),
552 SYNAPTICS_SYSCTL_NA_LEFT = SYN_OFFSET(na_left),
553 SYNAPTICS_SYSCTL_WINDOW_MIN = SYN_OFFSET(window_min),
554 SYNAPTICS_SYSCTL_WINDOW_MAX = SYN_OFFSET(window_max),
555 SYNAPTICS_SYSCTL_MULTIPLICATOR = SYN_OFFSET(multiplicator),
556 SYNAPTICS_SYSCTL_WEIGHT_CURRENT = SYN_OFFSET(weight_current),
557 SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS = SYN_OFFSET(weight_previous),
558 SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA = SYN_OFFSET(weight_previous_na),
559 SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED = SYN_OFFSET(weight_len_squared),
560 SYNAPTICS_SYSCTL_DIV_MIN = SYN_OFFSET(div_min),
561 SYNAPTICS_SYSCTL_DIV_MAX = SYN_OFFSET(div_max),
562 SYNAPTICS_SYSCTL_DIV_MAX_NA = SYN_OFFSET(div_max_na),
563 SYNAPTICS_SYSCTL_DIV_LEN = SYN_OFFSET(div_len),
564 SYNAPTICS_SYSCTL_TAP_MAX_DELTA = SYN_OFFSET(tap_max_delta),
565 SYNAPTICS_SYSCTL_TAP_MIN_QUEUE = SYN_OFFSET(tap_min_queue),
566 SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT = SYN_OFFSET(taphold_timeout),
567 SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA = SYN_OFFSET(vscroll_hor_area),
568 SYNAPTICS_SYSCTL_VSCROLL_VER_AREA = SYN_OFFSET(vscroll_ver_area),
569 SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA = SYN_OFFSET(vscroll_min_delta),
570 SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN = SYN_OFFSET(vscroll_div_min),
571 SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX = SYN_OFFSET(vscroll_div_max),
572 SYNAPTICS_SYSCTL_TOUCHPAD_OFF = SYN_OFFSET(touchpad_off),
573 SYNAPTICS_SYSCTL_SOFTBUTTONS_Y = SYN_OFFSET(softbuttons_y),
574 SYNAPTICS_SYSCTL_SOFTBUTTON2_X = SYN_OFFSET(softbutton2_x),
575 SYNAPTICS_SYSCTL_SOFTBUTTON3_X = SYN_OFFSET(softbutton3_x),
576 SYNAPTICS_SYSCTL_THREE_FINGER_DRAG = SYN_OFFSET(three_finger_drag),
577 SYNAPTICS_SYSCTL_NATURAL_SCROLL = SYN_OFFSET(natural_scroll),
578 #define SYNAPTICS_SYSCTL_LAST SYNAPTICS_SYSCTL_NATURAL_SCROLL
581 /* packet formatting function */
582 typedef int packetfunc_t(struct psm_softc *, u_char *, int *, int,
585 /* function prototypes */
586 static void psmidentify(driver_t *, device_t);
587 static int psmprobe(device_t);
588 static int psmattach(device_t);
589 static int psmdetach(device_t);
590 static int psmresume(device_t);
592 static d_open_t psm_cdev_open;
593 static d_close_t psm_cdev_close;
594 static d_read_t psmread;
595 static d_write_t psmwrite;
596 static d_ioctl_t psmioctl;
597 static d_poll_t psmpoll;
599 static int psmopen(struct psm_softc *);
600 static int psmclose(struct psm_softc *);
603 static evdev_open_t psm_ev_open_r;
604 static evdev_close_t psm_ev_close_r;
605 static evdev_open_t psm_ev_open_a;
606 static evdev_close_t psm_ev_close_a;
609 static int enable_aux_dev(KBDC);
610 static int disable_aux_dev(KBDC);
611 static int get_mouse_status(KBDC, int *, int, int);
612 static int get_aux_id(KBDC);
613 static int set_mouse_sampling_rate(KBDC, int);
614 static int set_mouse_scaling(KBDC, int);
615 static int set_mouse_resolution(KBDC, int);
616 static int set_mouse_mode(KBDC);
617 static int get_mouse_buttons(KBDC);
618 static int is_a_mouse(int);
619 static void recover_from_error(KBDC);
620 static int restore_controller(KBDC, int);
621 static int doinitialize(struct psm_softc *, mousemode_t *);
622 static int doopen(struct psm_softc *, int);
623 static int reinitialize(struct psm_softc *, int);
624 static char *model_name(int);
625 static void psmsoftintr(void *);
626 static void psmsoftintridle(void *);
627 static void psmintr(void *);
628 static void psmtimeout(void *);
629 static int timeelapsed(const struct timeval *, int, int,
630 const struct timeval *);
631 static void dropqueue(struct psm_softc *);
632 static void flushpackets(struct psm_softc *);
633 static void proc_mmanplus(struct psm_softc *, packetbuf_t *,
634 mousestatus_t *, int *, int *, int *);
635 static int proc_synaptics(struct psm_softc *, packetbuf_t *,
636 mousestatus_t *, int *, int *, int *);
637 static int proc_synaptics_mux(struct psm_softc *, packetbuf_t *);
638 static void proc_versapad(struct psm_softc *, packetbuf_t *,
639 mousestatus_t *, int *, int *, int *);
640 static int proc_elantech(struct psm_softc *, packetbuf_t *,
641 mousestatus_t *, int *, int *, int *);
642 static int psmpalmdetect(struct psm_softc *, finger_t *, int);
643 static void psmgestures(struct psm_softc *, finger_t *, int,
645 static void psmsmoother(struct psm_softc *, finger_t *, int,
646 mousestatus_t *, int *, int *);
647 static int tame_mouse(struct psm_softc *, packetbuf_t *, mousestatus_t *,
650 /* vendor specific features */
651 enum probearg { PROBE, REINIT };
652 typedef int probefunc_t(struct psm_softc *, enum probearg);
654 static int mouse_id_proc1(KBDC, int, int, int *);
655 static int mouse_ext_command(KBDC, int);
657 static probefunc_t enable_groller;
658 static probefunc_t enable_gmouse;
659 static probefunc_t enable_aglide;
660 static probefunc_t enable_kmouse;
661 static probefunc_t enable_msexplorer;
662 static probefunc_t enable_msintelli;
663 static probefunc_t enable_4dmouse;
664 static probefunc_t enable_4dplus;
665 static probefunc_t enable_mmanplus;
666 static probefunc_t enable_synaptics;
667 static probefunc_t enable_synaptics_mux;
668 static probefunc_t enable_trackpoint;
669 static probefunc_t enable_versapad;
670 static probefunc_t enable_elantech;
672 static void set_trackpoint_parameters(struct psm_softc *sc);
673 static void synaptics_passthrough_on(struct psm_softc *sc);
674 static void synaptics_passthrough_off(struct psm_softc *sc);
675 static int synaptics_preferred_mode(struct psm_softc *sc);
676 static void synaptics_set_mode(struct psm_softc *sc, int mode_byte);
682 probefunc_t *probefunc;
685 * WARNING: the order of probe is very important. Don't mess it
686 * unless you know what you are doing.
688 { MOUSE_MODEL_SYNAPTICS, /* Synaptics Touchpad on Active Mux */
689 0x00, MOUSE_PS2_PACKETSIZE, enable_synaptics_mux },
690 { MOUSE_MODEL_NET, /* Genius NetMouse */
691 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_gmouse },
692 { MOUSE_MODEL_NETSCROLL, /* Genius NetScroll */
693 0xc8, 6, enable_groller },
694 { MOUSE_MODEL_MOUSEMANPLUS, /* Logitech MouseMan+ */
695 0x08, MOUSE_PS2_PACKETSIZE, enable_mmanplus },
696 { MOUSE_MODEL_EXPLORER, /* Microsoft IntelliMouse Explorer */
697 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msexplorer },
698 { MOUSE_MODEL_4D, /* A4 Tech 4D Mouse */
699 0x08, MOUSE_4D_PACKETSIZE, enable_4dmouse },
700 { MOUSE_MODEL_4DPLUS, /* A4 Tech 4D+ Mouse */
701 0xc8, MOUSE_4DPLUS_PACKETSIZE, enable_4dplus },
702 { MOUSE_MODEL_SYNAPTICS, /* Synaptics Touchpad */
703 0xc0, MOUSE_SYNAPTICS_PACKETSIZE, enable_synaptics },
704 { MOUSE_MODEL_ELANTECH, /* Elantech Touchpad */
705 0x04, MOUSE_ELANTECH_PACKETSIZE, enable_elantech },
706 { MOUSE_MODEL_INTELLI, /* Microsoft IntelliMouse */
707 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msintelli },
708 { MOUSE_MODEL_GLIDEPOINT, /* ALPS GlidePoint */
709 0xc0, MOUSE_PS2_PACKETSIZE, enable_aglide },
710 { MOUSE_MODEL_THINK, /* Kensington ThinkingMouse */
711 0x80, MOUSE_PS2_PACKETSIZE, enable_kmouse },
712 { MOUSE_MODEL_VERSAPAD, /* Interlink electronics VersaPad */
713 0xe8, MOUSE_PS2VERSA_PACKETSIZE, enable_versapad },
714 { MOUSE_MODEL_TRACKPOINT, /* IBM/Lenovo TrackPoint */
715 0xc0, MOUSE_PS2_PACKETSIZE, enable_trackpoint },
716 { MOUSE_MODEL_GENERIC,
717 0xc0, MOUSE_PS2_PACKETSIZE, NULL },
719 #define GENERIC_MOUSE_ENTRY (nitems(vendortype) - 1)
721 /* device driver declarateion */
722 static device_method_t psm_methods[] = {
723 /* Device interface */
724 DEVMETHOD(device_identify, psmidentify),
725 DEVMETHOD(device_probe, psmprobe),
726 DEVMETHOD(device_attach, psmattach),
727 DEVMETHOD(device_detach, psmdetach),
728 DEVMETHOD(device_resume, psmresume),
733 static driver_t psm_driver = {
736 sizeof(struct psm_softc),
739 static struct cdevsw psm_cdevsw = {
740 .d_version = D_VERSION,
741 .d_flags = D_NEEDGIANT,
742 .d_open = psm_cdev_open,
743 .d_close = psm_cdev_close,
748 .d_name = PSM_DRIVER_NAME,
752 static const struct evdev_methods psm_ev_methods_r = {
753 .ev_open = psm_ev_open_r,
754 .ev_close = psm_ev_close_r,
756 static const struct evdev_methods psm_ev_methods_a = {
757 .ev_open = psm_ev_open_a,
758 .ev_close = psm_ev_close_a,
762 /* device I/O routines */
764 enable_aux_dev(KBDC kbdc)
768 res = send_aux_command(kbdc, PSMC_ENABLE_DEV);
769 VLOG(2, (LOG_DEBUG, "psm: ENABLE_DEV return code:%04x\n", res));
771 return (res == PSM_ACK);
775 disable_aux_dev(KBDC kbdc)
779 res = send_aux_command(kbdc, PSMC_DISABLE_DEV);
780 VLOG(2, (LOG_DEBUG, "psm: DISABLE_DEV return code:%04x\n", res));
782 return (res == PSM_ACK);
786 get_mouse_status(KBDC kbdc, int *status, int flag, int len)
795 cmd = PSMC_SEND_DEV_STATUS;
798 cmd = PSMC_SEND_DEV_DATA;
801 empty_aux_buffer(kbdc, 5);
802 res = send_aux_command(kbdc, cmd);
803 VLOG(2, (LOG_DEBUG, "psm: SEND_AUX_DEV_%s return code:%04x\n",
804 (flag == 1) ? "DATA" : "STATUS", res));
808 for (i = 0; i < len; ++i) {
809 status[i] = read_aux_data(kbdc);
816 VLOG(1, (LOG_DEBUG, "psm: %s %02x %02x %02x\n",
817 (flag == 1) ? "data" : "status", status[0], status[1], status[2]));
824 get_aux_id(KBDC kbdc)
829 empty_aux_buffer(kbdc, 5);
830 res = send_aux_command(kbdc, PSMC_SEND_DEV_ID);
831 VLOG(2, (LOG_DEBUG, "psm: SEND_DEV_ID return code:%04x\n", res));
838 id = read_aux_data(kbdc);
839 VLOG(2, (LOG_DEBUG, "psm: device ID: %04x\n", id));
845 set_mouse_sampling_rate(KBDC kbdc, int rate)
849 res = send_aux_command_and_data(kbdc, PSMC_SET_SAMPLING_RATE, rate);
850 VLOG(2, (LOG_DEBUG, "psm: SET_SAMPLING_RATE (%d) %04x\n", rate, res));
852 return ((res == PSM_ACK) ? rate : -1);
856 set_mouse_scaling(KBDC kbdc, int scale)
863 scale = PSMC_SET_SCALING11;
866 scale = PSMC_SET_SCALING21;
869 res = send_aux_command(kbdc, scale);
870 VLOG(2, (LOG_DEBUG, "psm: SET_SCALING%s return code:%04x\n",
871 (scale == PSMC_SET_SCALING21) ? "21" : "11", res));
873 return (res == PSM_ACK);
876 /* `val' must be 0 through PSMD_MAX_RESOLUTION */
878 set_mouse_resolution(KBDC kbdc, int val)
882 res = send_aux_command_and_data(kbdc, PSMC_SET_RESOLUTION, val);
883 VLOG(2, (LOG_DEBUG, "psm: SET_RESOLUTION (%d) %04x\n", val, res));
885 return ((res == PSM_ACK) ? val : -1);
889 * NOTE: once `set_mouse_mode()' is called, the mouse device must be
890 * re-enabled by calling `enable_aux_dev()'
893 set_mouse_mode(KBDC kbdc)
897 res = send_aux_command(kbdc, PSMC_SET_STREAM_MODE);
898 VLOG(2, (LOG_DEBUG, "psm: SET_STREAM_MODE return code:%04x\n", res));
900 return (res == PSM_ACK);
904 get_mouse_buttons(KBDC kbdc)
906 int c = 2; /* assume two buttons by default */
910 * NOTE: a special sequence to obtain Logitech Mouse specific
911 * information: set resolution to 25 ppi, set scaling to 1:1, set
912 * scaling to 1:1, set scaling to 1:1. Then the second byte of the
913 * mouse status bytes is the number of available buttons.
914 * Some manufactures also support this sequence.
916 if (set_mouse_resolution(kbdc, PSMD_RES_LOW) != PSMD_RES_LOW)
918 if (set_mouse_scaling(kbdc, 1) && set_mouse_scaling(kbdc, 1) &&
919 set_mouse_scaling(kbdc, 1) &&
920 get_mouse_status(kbdc, status, 0, 3) >= 3 && status[1] != 0)
925 /* misc subroutines */
927 * Someday, I will get the complete list of valid pointing devices and
934 static int valid_ids[] = {
935 PSM_MOUSE_ID, /* mouse */
936 PSM_BALLPOINT_ID, /* ballpoint device */
937 PSM_INTELLI_ID, /* Intellimouse */
938 PSM_EXPLORER_ID, /* Intellimouse Explorer */
939 -1 /* end of table */
943 for (i = 0; valid_ids[i] >= 0; ++i)
944 if (valid_ids[i] == id)
953 model_name(int model)
959 { MOUSE_MODEL_NETSCROLL, "NetScroll" },
960 { MOUSE_MODEL_NET, "NetMouse/NetScroll Optical" },
961 { MOUSE_MODEL_GLIDEPOINT, "GlidePoint" },
962 { MOUSE_MODEL_THINK, "ThinkingMouse" },
963 { MOUSE_MODEL_INTELLI, "IntelliMouse" },
964 { MOUSE_MODEL_MOUSEMANPLUS, "MouseMan+" },
965 { MOUSE_MODEL_VERSAPAD, "VersaPad" },
966 { MOUSE_MODEL_EXPLORER, "IntelliMouse Explorer" },
967 { MOUSE_MODEL_4D, "4D Mouse" },
968 { MOUSE_MODEL_4DPLUS, "4D+ Mouse" },
969 { MOUSE_MODEL_SYNAPTICS, "Synaptics Touchpad" },
970 { MOUSE_MODEL_TRACKPOINT, "IBM/Lenovo TrackPoint" },
971 { MOUSE_MODEL_ELANTECH, "Elantech Touchpad" },
972 { MOUSE_MODEL_GENERIC, "Generic PS/2 mouse" },
973 { MOUSE_MODEL_UNKNOWN, "Unknown" },
977 for (i = 0; models[i].model_code != MOUSE_MODEL_UNKNOWN; ++i)
978 if (models[i].model_code == model)
980 return (models[i].model_name);
984 recover_from_error(KBDC kbdc)
986 /* discard anything left in the output buffer */
987 empty_both_buffers(kbdc, 10);
991 * NOTE: KBDC_RESET_KBD may not restore the communication between the
992 * keyboard and the controller.
997 * NOTE: somehow diagnostic and keyboard port test commands bring the
1000 if (!test_controller(kbdc))
1001 log(LOG_ERR, "psm: keyboard controller failed.\n");
1002 /* if there isn't a keyboard in the system, the following error is OK */
1003 if (test_kbd_port(kbdc) != 0)
1004 VLOG(1, (LOG_ERR, "psm: keyboard port failed.\n"));
1009 restore_controller(KBDC kbdc, int command_byte)
1011 empty_both_buffers(kbdc, 10);
1013 if (!set_controller_command_byte(kbdc, 0xff, command_byte)) {
1014 log(LOG_ERR, "psm: failed to restore the keyboard controller "
1016 empty_both_buffers(kbdc, 10);
1019 empty_both_buffers(kbdc, 10);
1025 * Re-initialize the aux port and device. The aux port must be enabled
1026 * and its interrupt must be disabled before calling this routine.
1027 * The aux device will be disabled before returning.
1028 * The keyboard controller must be locked via `kbdc_lock()' before
1029 * calling this routine.
1032 doinitialize(struct psm_softc *sc, mousemode_t *mode)
1034 KBDC kbdc = sc->kbdc;
1038 switch((i = test_aux_port(kbdc))) {
1039 case 1: /* ignore these errors */
1045 "psm%d: strange result for test aux port (%d).\n",
1048 case 0: /* no error */
1050 case -1: /* time out */
1051 default: /* error */
1052 recover_from_error(kbdc);
1053 if (sc->config & PSM_CONFIG_IGNPORTERROR)
1055 log(LOG_ERR, "psm%d: the aux port is not functioning (%d).\n",
1060 if (sc->config & PSM_CONFIG_NORESET) {
1062 * Don't try to reset the pointing device. It may possibly
1063 * be left in the unknown state, though...
1067 * NOTE: some controllers appears to hang the `keyboard' when
1068 * the aux port doesn't exist and `PSMC_RESET_DEV' is issued.
1070 if (!reset_aux_dev(kbdc)) {
1071 recover_from_error(kbdc);
1072 log(LOG_ERR, "psm%d: failed to reset the aux device.\n",
1079 * both the aux port and the aux device is functioning, see
1080 * if the device can be enabled.
1082 if (!enable_aux_dev(kbdc) || !disable_aux_dev(kbdc)) {
1083 log(LOG_ERR, "psm%d: failed to enable the aux device.\n",
1087 empty_both_buffers(kbdc, 10); /* remove stray data if any */
1089 /* Re-enable the mouse. */
1090 for (i = 0; vendortype[i].probefunc != NULL; ++i)
1091 if (vendortype[i].model == sc->hw.model)
1092 (*vendortype[i].probefunc)(sc, REINIT);
1094 /* set mouse parameters */
1095 if (mode != (mousemode_t *)NULL) {
1097 mode->rate = set_mouse_sampling_rate(kbdc, mode->rate);
1098 if (mode->resolution >= 0)
1100 set_mouse_resolution(kbdc, mode->resolution);
1101 set_mouse_scaling(kbdc, 1);
1102 set_mouse_mode(kbdc);
1105 /* Record sync on the next data packet we see. */
1106 sc->flags |= PSM_NEED_SYNCBITS;
1108 /* just check the status of the mouse */
1109 if (get_mouse_status(kbdc, stat, 0, 3) < 3)
1110 log(LOG_DEBUG, "psm%d: failed to get status (doinitialize).\n",
1117 doopen(struct psm_softc *sc, int command_byte)
1120 int mux_enabled = FALSE;
1123 * FIXME: Synaptics TouchPad seems to go back to Relative Mode with
1124 * no obvious reason. Thus we check the current mode and restore the
1125 * Absolute Mode if it was cleared.
1127 * The previous hack at the end of psmprobe() wasn't efficient when
1128 * moused(8) was restarted.
1130 * A Reset (FF) or Set Defaults (F6) command would clear the
1131 * Absolute Mode bit. But a verbose boot or debug.psm.loglevel=5
1132 * doesn't show any evidence of such a command.
1134 if (sc->hw.model == MOUSE_MODEL_SYNAPTICS) {
1135 if (sc->muxport != PSM_NOMUX) {
1136 mux_enabled = enable_aux_mux(sc->kbdc) >= 0;
1138 set_active_aux_mux_port(sc->kbdc, sc->muxport);
1140 log(LOG_ERR, "psm%d: failed to enable "
1141 "active multiplexing mode.\n",
1144 mouse_ext_command(sc->kbdc, SYNAPTICS_READ_MODES);
1145 get_mouse_status(sc->kbdc, stat, 0, 3);
1146 if ((SYNAPTICS_VERSION_GE(sc->synhw, 7, 5) ||
1149 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
1150 VLOG(5, (LOG_DEBUG, "psm%d: Synaptis Absolute Mode "
1151 "hopefully restored\n",
1155 disable_aux_mux(sc->kbdc);
1159 * A user may want to disable tap and drag gestures on a Synaptics
1160 * TouchPad when it operates in Relative Mode.
1162 if (sc->hw.model == MOUSE_MODEL_GENERIC) {
1163 if (tap_enabled > 0) {
1165 "psm%d: enable tap and drag gestures\n",
1167 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
1168 } else if (tap_enabled == 0) {
1170 "psm%d: disable tap and drag gestures\n",
1172 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
1176 /* enable the mouse device */
1177 if (!enable_aux_dev(sc->kbdc)) {
1178 /* MOUSE ERROR: failed to enable the mouse because:
1179 * 1) the mouse is faulty,
1180 * 2) the mouse has been removed(!?)
1181 * In the latter case, the keyboard may have hung, and need
1182 * recovery procedure...
1184 recover_from_error(sc->kbdc);
1186 /* FIXME: we could reset the mouse here and try to enable
1187 * it again. But it will take long time and it's not a good
1188 * idea to disable the keyboard that long...
1190 if (!doinitialize(sc, &sc->mode) || !enable_aux_dev(sc->kbdc)) {
1191 recover_from_error(sc->kbdc);
1195 restore_controller(sc->kbdc, command_byte);
1196 /* mark this device is no longer available */
1197 sc->state &= ~PSM_VALID;
1199 "psm%d: failed to enable the device (doopen).\n",
1205 if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
1206 log(LOG_DEBUG, "psm%d: failed to get status (doopen).\n",
1209 /* enable the aux port and interrupt */
1210 if (!set_controller_command_byte(sc->kbdc,
1211 kbdc_get_device_mask(sc->kbdc),
1212 (command_byte & KBD_KBD_CONTROL_BITS) |
1213 KBD_ENABLE_AUX_PORT | KBD_ENABLE_AUX_INT)) {
1214 /* CONTROLLER ERROR */
1215 disable_aux_dev(sc->kbdc);
1216 restore_controller(sc->kbdc, command_byte);
1218 "psm%d: failed to enable the aux interrupt (doopen).\n",
1223 /* start the watchdog timer */
1224 sc->watchdog = FALSE;
1225 callout_reset(&sc->callout, hz * 2, psmtimeout, sc);
1231 reinitialize(struct psm_softc *sc, int doinit)
1237 /* don't let anybody mess with the aux device */
1238 if (!kbdc_lock(sc->kbdc, TRUE))
1242 /* block our watchdog timer */
1243 sc->watchdog = FALSE;
1244 callout_stop(&sc->callout);
1246 /* save the current controller command byte */
1247 empty_both_buffers(sc->kbdc, 10);
1248 c = get_controller_command_byte(sc->kbdc);
1250 "psm%d: current command byte: %04x (reinitialize).\n",
1253 /* enable the aux port but disable the aux interrupt and the keyboard */
1254 if ((c == -1) || !set_controller_command_byte(sc->kbdc,
1255 kbdc_get_device_mask(sc->kbdc),
1256 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
1257 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1258 /* CONTROLLER ERROR */
1260 kbdc_lock(sc->kbdc, FALSE);
1262 "psm%d: unable to set the command byte (reinitialize).\n",
1267 /* flush any data */
1268 if (sc->state & PSM_VALID) {
1269 /* this may fail; but never mind... */
1270 disable_aux_dev(sc->kbdc);
1271 empty_aux_buffer(sc->kbdc, 10);
1276 memset(&sc->lastinputerr, 0, sizeof(sc->lastinputerr));
1278 /* try to detect the aux device; are you still there? */
1281 if (doinitialize(sc, &sc->mode)) {
1283 sc->state |= PSM_VALID;
1285 /* the device has gone! */
1286 restore_controller(sc->kbdc, c);
1287 sc->state &= ~PSM_VALID;
1289 "psm%d: the aux device has gone! (reinitialize).\n",
1296 /* restore the driver state */
1297 if ((sc->state & (PSM_OPEN | PSM_EV_OPEN_R | PSM_EV_OPEN_A)) &&
1299 /* enable the aux device and the port again */
1300 err = doopen(sc, c);
1302 log(LOG_ERR, "psm%d: failed to enable the device "
1303 "(reinitialize).\n", sc->unit);
1305 /* restore the keyboard port and disable the aux port */
1306 if (!set_controller_command_byte(sc->kbdc,
1307 kbdc_get_device_mask(sc->kbdc),
1308 (c & KBD_KBD_CONTROL_BITS) |
1309 KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1310 /* CONTROLLER ERROR */
1311 log(LOG_ERR, "psm%d: failed to disable the aux port "
1312 "(reinitialize).\n", sc->unit);
1317 kbdc_lock(sc->kbdc, FALSE);
1321 /* psm driver entry points */
1324 psmidentify(driver_t *driver, device_t parent)
1331 unit = device_get_unit(parent);
1333 /* always add at least one child */
1334 psm = BUS_ADD_CHILD(parent, KBDC_RID_AUX, driver->name, unit);
1338 irq = bus_get_resource_start(psm, SYS_RES_IRQ, KBDC_RID_AUX);
1343 * If the PS/2 mouse device has already been reported by ACPI or
1344 * PnP BIOS, obtain the IRQ resource from it.
1345 * (See psmcpnp_attach() below.)
1347 psmc = device_find_child(device_get_parent(parent),
1348 PSMCPNP_DRIVER_NAME, unit);
1351 irq = bus_get_resource_start(psmc, SYS_RES_IRQ, 0);
1354 bus_delete_resource(psmc, SYS_RES_IRQ, 0);
1355 bus_set_resource(psm, SYS_RES_IRQ, KBDC_RID_AUX, irq, 1);
1358 #define endprobe(v) do { \
1361 kbdc_set_device_mask(sc->kbdc, mask); \
1362 kbdc_lock(sc->kbdc, FALSE); \
1367 psmprobe(device_t dev)
1369 int unit = device_get_unit(dev);
1370 struct psm_softc *sc = device_get_softc(dev);
1381 /* see if IRQ is available */
1383 sc->intr = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
1384 if (sc->intr == NULL) {
1386 device_printf(dev, "unable to allocate IRQ\n");
1389 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
1392 sc->kbdc = atkbdc_open(device_get_unit(device_get_parent(dev)));
1393 if (sc->kbdc == NULL)
1395 sc->config = device_get_flags(dev) & PSM_CONFIG_FLAGS;
1396 /* XXX: for backward compatibility */
1397 #if defined(PSM_HOOKRESUME) || defined(PSM_HOOKAPM)
1399 #ifdef PSM_RESETAFTERSUSPEND
1400 PSM_CONFIG_INITAFTERSUSPEND;
1402 PSM_CONFIG_HOOKRESUME;
1404 #endif /* PSM_HOOKRESUME | PSM_HOOKAPM */
1406 sc->muxport = PSM_NOMUX;
1410 device_set_desc(dev, "PS/2 Mouse");
1412 if (!kbdc_lock(sc->kbdc, TRUE)) {
1413 printf("psm%d: unable to lock the controller.\n", unit);
1420 * NOTE: two bits in the command byte controls the operation of the
1421 * aux port (mouse port): the aux port disable bit (bit 5) and the aux
1422 * port interrupt (IRQ 12) enable bit (bit 2).
1425 /* discard anything left after the keyboard initialization */
1426 empty_both_buffers(sc->kbdc, 10);
1428 /* save the current command byte; it will be used later */
1429 mask = kbdc_get_device_mask(sc->kbdc) & ~KBD_AUX_CONTROL_BITS;
1430 command_byte = get_controller_command_byte(sc->kbdc);
1432 printf("psm%d: current command byte:%04x\n", unit,
1434 if (command_byte == -1) {
1435 /* CONTROLLER ERROR */
1436 printf("psm%d: unable to get the current command byte value.\n",
1442 * disable the keyboard port while probing the aux port, which must be
1443 * enabled during this routine
1445 if (!set_controller_command_byte(sc->kbdc,
1446 KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS,
1447 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
1448 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1450 * this is CONTROLLER ERROR; I don't know how to recover
1451 * from this error...
1453 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1454 restore_controller(sc->kbdc, command_byte);
1455 printf("psm%d: unable to set the command byte.\n", unit);
1458 write_controller_command(sc->kbdc, KBDC_ENABLE_AUX_PORT);
1461 * NOTE: `test_aux_port()' is designed to return with zero if the aux
1462 * port exists and is functioning. However, some controllers appears
1463 * to respond with zero even when the aux port doesn't exist. (It may
1464 * be that this is only the case when the controller DOES have the aux
1465 * port but the port is not wired on the motherboard.) The keyboard
1466 * controllers without the port, such as the original AT, are
1467 * supposed to return with an error code or simply time out. In any
1468 * case, we have to continue probing the port even when the controller
1471 * XXX: some controllers erroneously return the error code 1, 2 or 3
1472 * when it has a perfectly functional aux port. We have to ignore
1473 * this error code. Even if the controller HAS error with the aux
1474 * port, it will be detected later...
1475 * XXX: another incompatible controller returns PSM_ACK (0xfa)...
1477 switch ((i = test_aux_port(sc->kbdc))) {
1478 case 1: /* ignore these errors */
1483 printf("psm%d: strange result for test aux port "
1484 "(%d).\n", unit, i);
1486 case 0: /* no error */
1488 case -1: /* time out */
1489 default: /* error */
1490 recover_from_error(sc->kbdc);
1491 if (sc->config & PSM_CONFIG_IGNPORTERROR)
1493 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1494 restore_controller(sc->kbdc, command_byte);
1496 printf("psm%d: the aux port is not functioning (%d).\n",
1501 if (sc->config & PSM_CONFIG_NORESET) {
1503 * Don't try to reset the pointing device. It may possibly be
1504 * left in an unknown state, though...
1508 * NOTE: some controllers appears to hang the `keyboard' when
1509 * the aux port doesn't exist and `PSMC_RESET_DEV' is issued.
1511 * Attempt to reset the controller twice -- this helps
1512 * pierce through some KVM switches. The second reset
1515 if (!reset_aux_dev(sc->kbdc)) {
1516 recover_from_error(sc->kbdc);
1517 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1518 restore_controller(sc->kbdc, command_byte);
1520 printf("psm%d: failed to reset the aux "
1523 } else if (!reset_aux_dev(sc->kbdc)) {
1524 recover_from_error(sc->kbdc);
1526 printf("psm%d: failed to reset the aux device "
1532 * both the aux port and the aux device are functioning, see if the
1533 * device can be enabled. NOTE: when enabled, the device will start
1534 * sending data; we shall immediately disable the device once we know
1535 * the device can be enabled.
1537 if (!enable_aux_dev(sc->kbdc) || !disable_aux_dev(sc->kbdc)) {
1539 recover_from_error(sc->kbdc);
1540 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1541 restore_controller(sc->kbdc, command_byte);
1543 printf("psm%d: failed to enable the aux device.\n",
1548 /* save the default values after reset */
1549 if (get_mouse_status(sc->kbdc, stat, 0, 3) >= 3) {
1550 sc->dflt_mode.rate = sc->mode.rate = stat[2];
1551 sc->dflt_mode.resolution = sc->mode.resolution = stat[1];
1553 sc->dflt_mode.rate = sc->mode.rate = -1;
1554 sc->dflt_mode.resolution = sc->mode.resolution = -1;
1557 /* hardware information */
1558 sc->hw.iftype = MOUSE_IF_PS2;
1560 /* verify the device is a mouse */
1561 sc->hw.hwid = get_aux_id(sc->kbdc);
1562 if (!is_a_mouse(sc->hw.hwid)) {
1563 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1564 restore_controller(sc->kbdc, command_byte);
1566 printf("psm%d: unknown device type (%d).\n", unit,
1570 switch (sc->hw.hwid) {
1571 case PSM_BALLPOINT_ID:
1572 sc->hw.type = MOUSE_TRACKBALL;
1575 case PSM_INTELLI_ID:
1576 case PSM_EXPLORER_ID:
1577 case PSM_4DMOUSE_ID:
1579 sc->hw.type = MOUSE_MOUSE;
1582 sc->hw.type = MOUSE_UNKNOWN;
1586 if (sc->config & PSM_CONFIG_NOIDPROBE) {
1588 i = GENERIC_MOUSE_ENTRY;
1591 sc->hw.buttons = get_mouse_buttons(sc->kbdc);
1593 /* other parameters */
1594 for (i = 0; vendortype[i].probefunc != NULL; ++i)
1595 if ((*vendortype[i].probefunc)(sc, PROBE)) {
1597 printf("psm%d: found %s\n", unit,
1598 model_name(vendortype[i].model));
1603 sc->hw.model = vendortype[i].model;
1605 sc->dflt_mode.level = PSM_LEVEL_BASE;
1606 sc->dflt_mode.packetsize = MOUSE_PS2_PACKETSIZE;
1607 sc->dflt_mode.accelfactor = (sc->config & PSM_CONFIG_ACCEL) >> 4;
1608 if (sc->config & PSM_CONFIG_NOCHECKSYNC)
1609 sc->dflt_mode.syncmask[0] = 0;
1611 sc->dflt_mode.syncmask[0] = vendortype[i].syncmask;
1612 if (sc->config & PSM_CONFIG_FORCETAP)
1613 sc->dflt_mode.syncmask[0] &= ~MOUSE_PS2_TAP;
1614 sc->dflt_mode.syncmask[1] = 0; /* syncbits */
1615 sc->mode = sc->dflt_mode;
1616 sc->mode.packetsize = vendortype[i].packetsize;
1618 /* set mouse parameters */
1621 * A version of Logitech FirstMouse+ won't report wheel movement,
1622 * if SET_DEFAULTS is sent... Don't use this command.
1623 * This fix was found by Takashi Nishida.
1625 i = send_aux_command(sc->kbdc, PSMC_SET_DEFAULTS);
1627 printf("psm%d: SET_DEFAULTS return code:%04x\n", unit, i);
1629 if (sc->config & PSM_CONFIG_RESOLUTION)
1630 sc->mode.resolution =
1631 set_mouse_resolution(sc->kbdc,
1632 (sc->config & PSM_CONFIG_RESOLUTION) - 1);
1633 else if (sc->mode.resolution >= 0)
1634 sc->mode.resolution =
1635 set_mouse_resolution(sc->kbdc, sc->dflt_mode.resolution);
1636 if (sc->mode.rate > 0)
1638 set_mouse_sampling_rate(sc->kbdc, sc->dflt_mode.rate);
1639 set_mouse_scaling(sc->kbdc, 1);
1641 /* Record sync on the next data packet we see. */
1642 sc->flags |= PSM_NEED_SYNCBITS;
1644 /* just check the status of the mouse */
1646 * NOTE: XXX there are some arcane controller/mouse combinations out
1647 * there, which hung the controller unless there is data transmission
1648 * after ACK from the mouse.
1650 if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
1651 printf("psm%d: failed to get status.\n", unit);
1654 * When in its native mode, some mice operate with different
1655 * default parameters than in the PS/2 compatible mode.
1657 sc->dflt_mode.rate = sc->mode.rate = stat[2];
1658 sc->dflt_mode.resolution = sc->mode.resolution = stat[1];
1661 /* disable the aux port for now... */
1662 if (!set_controller_command_byte(sc->kbdc,
1663 KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS,
1664 (command_byte & KBD_KBD_CONTROL_BITS) |
1665 KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1667 * this is CONTROLLER ERROR; I don't know the proper way to
1668 * recover from this error...
1670 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1671 restore_controller(sc->kbdc, command_byte);
1672 printf("psm%d: unable to set the command byte.\n", unit);
1677 kbdc_set_device_mask(sc->kbdc, mask | KBD_AUX_CONTROL_BITS);
1678 kbdc_lock(sc->kbdc, FALSE);
1682 #ifdef EVDEV_SUPPORT
1683 /* Values are taken from Linux drivers for userland software compatibility */
1684 #define PS2_MOUSE_VENDOR 0x0002
1685 #define PS2_MOUSE_GENERIC_PRODUCT 0x0001
1686 #define PS2_MOUSE_SYNAPTICS_NAME "SynPS/2 Synaptics TouchPad"
1687 #define PS2_MOUSE_SYNAPTICS_PRODUCT 0x0007
1688 #define PS2_MOUSE_TRACKPOINT_NAME "TPPS/2 IBM TrackPoint"
1689 #define PS2_MOUSE_TRACKPOINT_PRODUCT 0x000A
1690 #define PS2_MOUSE_ELANTECH_NAME "ETPS/2 Elantech Touchpad"
1691 #define PS2_MOUSE_ELANTECH_ST_NAME "ETPS/2 Elantech TrackPoint"
1692 #define PS2_MOUSE_ELANTECH_PRODUCT 0x000E
1694 #define ABSINFO_END { ABS_CNT, 0, 0, 0 }
1697 psm_support_abs_bulk(struct evdev_dev *evdev, const uint16_t info[][4])
1701 for (i = 0; info[i][0] != ABS_CNT; i++)
1702 evdev_support_abs(evdev, info[i][0], 0, info[i][1], info[i][2],
1707 psm_push_mt_finger(struct psm_softc *sc, int id, const finger_t *f)
1709 int y = sc->synhw.minimumYCoord + sc->synhw.maximumYCoord - f->y;
1711 evdev_push_abs(sc->evdev_a, ABS_MT_SLOT, id);
1712 evdev_push_abs(sc->evdev_a, ABS_MT_TRACKING_ID, id);
1713 evdev_push_abs(sc->evdev_a, ABS_MT_POSITION_X, f->x);
1714 evdev_push_abs(sc->evdev_a, ABS_MT_POSITION_Y, y);
1715 evdev_push_abs(sc->evdev_a, ABS_MT_PRESSURE, f->p);
1719 psm_push_st_finger(struct psm_softc *sc, const finger_t *f)
1721 int y = sc->synhw.minimumYCoord + sc->synhw.maximumYCoord - f->y;
1723 evdev_push_abs(sc->evdev_a, ABS_X, f->x);
1724 evdev_push_abs(sc->evdev_a, ABS_Y, y);
1725 evdev_push_abs(sc->evdev_a, ABS_PRESSURE, f->p);
1726 if (sc->synhw.capPalmDetect)
1727 evdev_push_abs(sc->evdev_a, ABS_TOOL_WIDTH, f->w);
1731 psm_release_mt_slot(struct evdev_dev *evdev, int32_t slot)
1734 evdev_push_abs(evdev, ABS_MT_SLOT, slot);
1735 evdev_push_abs(evdev, ABS_MT_TRACKING_ID, -1);
1739 psm_register(device_t dev, int model_code)
1741 struct psm_softc *sc = device_get_softc(dev);
1742 struct evdev_dev *evdev_r;
1743 int error, i, nbuttons, nwheels, product;
1744 bool is_pointing_stick;
1747 name = model_name(model_code);
1748 nbuttons = sc->hw.buttons;
1749 product = PS2_MOUSE_GENERIC_PRODUCT;
1751 is_pointing_stick = false;
1753 switch (model_code) {
1754 case MOUSE_MODEL_TRACKPOINT:
1755 name = PS2_MOUSE_TRACKPOINT_NAME;
1756 product = PS2_MOUSE_TRACKPOINT_PRODUCT;
1758 is_pointing_stick = true;
1761 case MOUSE_MODEL_ELANTECH:
1762 name = PS2_MOUSE_ELANTECH_ST_NAME;
1763 product = PS2_MOUSE_ELANTECH_PRODUCT;
1765 is_pointing_stick = true;
1768 case MOUSE_MODEL_MOUSEMANPLUS:
1769 case MOUSE_MODEL_4D:
1773 case MOUSE_MODEL_EXPLORER:
1774 case MOUSE_MODEL_INTELLI:
1775 case MOUSE_MODEL_NET:
1776 case MOUSE_MODEL_NETSCROLL:
1777 case MOUSE_MODEL_4DPLUS:
1782 evdev_r = evdev_alloc();
1783 evdev_set_name(evdev_r, name);
1784 evdev_set_phys(evdev_r, device_get_nameunit(dev));
1785 evdev_set_id(evdev_r, BUS_I8042, PS2_MOUSE_VENDOR, product, 0);
1786 evdev_set_methods(evdev_r, sc, &psm_ev_methods_r);
1788 evdev_support_prop(evdev_r, INPUT_PROP_POINTER);
1789 if (is_pointing_stick)
1790 evdev_support_prop(evdev_r, INPUT_PROP_POINTING_STICK);
1791 evdev_support_event(evdev_r, EV_SYN);
1792 evdev_support_event(evdev_r, EV_KEY);
1793 evdev_support_event(evdev_r, EV_REL);
1794 evdev_support_rel(evdev_r, REL_X);
1795 evdev_support_rel(evdev_r, REL_Y);
1798 evdev_support_rel(evdev_r, REL_HWHEEL);
1801 evdev_support_rel(evdev_r, REL_WHEEL);
1803 for (i = 0; i < nbuttons; i++)
1804 evdev_support_key(evdev_r, BTN_MOUSE + i);
1806 error = evdev_register_mtx(evdev_r, &Giant);
1808 evdev_free(evdev_r);
1810 sc->evdev_r = evdev_r;
1815 psm_register_synaptics(device_t dev)
1817 struct psm_softc *sc = device_get_softc(dev);
1818 const uint16_t synaptics_absinfo_st[][4] = {
1819 { ABS_X, sc->synhw.minimumXCoord,
1820 sc->synhw.maximumXCoord, sc->synhw.infoXupmm },
1821 { ABS_Y, sc->synhw.minimumYCoord,
1822 sc->synhw.maximumYCoord, sc->synhw.infoYupmm },
1823 { ABS_PRESSURE, 0, ELANTECH_FINGER_MAX_P, 0 },
1826 const uint16_t synaptics_absinfo_mt[][4] = {
1827 { ABS_MT_SLOT, 0, PSM_FINGERS-1, 0},
1828 { ABS_MT_TRACKING_ID, -1, PSM_FINGERS-1, 0},
1829 { ABS_MT_POSITION_X, sc->synhw.minimumXCoord,
1830 sc->synhw.maximumXCoord, sc->synhw.infoXupmm },
1831 { ABS_MT_POSITION_Y, sc->synhw.minimumYCoord,
1832 sc->synhw.maximumYCoord, sc->synhw.infoYupmm },
1833 { ABS_MT_PRESSURE, 0, ELANTECH_FINGER_MAX_P, 0 },
1836 struct evdev_dev *evdev_a;
1837 int error, i, guest_model;
1839 evdev_a = evdev_alloc();
1840 evdev_set_name(evdev_a, PS2_MOUSE_SYNAPTICS_NAME);
1841 evdev_set_phys(evdev_a, device_get_nameunit(dev));
1842 evdev_set_id(evdev_a, BUS_I8042, PS2_MOUSE_VENDOR,
1843 PS2_MOUSE_SYNAPTICS_PRODUCT, 0);
1844 evdev_set_methods(evdev_a, sc, &psm_ev_methods_a);
1846 evdev_support_event(evdev_a, EV_SYN);
1847 evdev_support_event(evdev_a, EV_KEY);
1848 evdev_support_event(evdev_a, EV_ABS);
1849 evdev_support_prop(evdev_a, INPUT_PROP_POINTER);
1850 if (sc->synhw.capAdvancedGestures)
1851 evdev_support_prop(evdev_a, INPUT_PROP_SEMI_MT);
1852 if (sc->synhw.capClickPad)
1853 evdev_support_prop(evdev_a, INPUT_PROP_BUTTONPAD);
1854 if (sc->synhw.capClickPad && sc->synhw.topButtonPad)
1855 evdev_support_prop(evdev_a, INPUT_PROP_TOPBUTTONPAD);
1856 evdev_support_key(evdev_a, BTN_TOUCH);
1857 evdev_support_nfingers(evdev_a, sc->synhw.capReportsV ? 5 : 3);
1858 psm_support_abs_bulk(evdev_a, synaptics_absinfo_st);
1859 if (sc->synhw.capAdvancedGestures || sc->synhw.capReportsV)
1860 psm_support_abs_bulk(evdev_a, synaptics_absinfo_mt);
1861 if (sc->synhw.capPalmDetect)
1862 evdev_support_abs(evdev_a, ABS_TOOL_WIDTH, 0, 0, 15, 0, 0, 0);
1863 evdev_support_key(evdev_a, BTN_LEFT);
1864 if (!sc->synhw.capClickPad) {
1865 evdev_support_key(evdev_a, BTN_RIGHT);
1866 if (sc->synhw.capExtended && sc->synhw.capMiddle)
1867 evdev_support_key(evdev_a, BTN_MIDDLE);
1869 if (sc->synhw.capExtended && sc->synhw.capFourButtons) {
1870 evdev_support_key(evdev_a, BTN_BACK);
1871 evdev_support_key(evdev_a, BTN_FORWARD);
1873 if (sc->synhw.capExtended && (sc->synhw.nExtendedButtons > 0))
1874 for (i = 0; i < sc->synhw.nExtendedButtons; i++)
1875 evdev_support_key(evdev_a, BTN_0 + i);
1877 error = evdev_register_mtx(evdev_a, &Giant);
1878 if (!error && (sc->synhw.capPassthrough || sc->muxport != PSM_NOMUX)) {
1879 guest_model = sc->tpinfo.sysctl_tree != NULL ?
1880 MOUSE_MODEL_TRACKPOINT : MOUSE_MODEL_GENERIC;
1881 error = psm_register(dev, guest_model);
1884 evdev_free(evdev_a);
1886 sc->evdev_a = evdev_a;
1891 psm_register_elantech(device_t dev)
1893 struct psm_softc *sc = device_get_softc(dev);
1894 const uint16_t elantech_absinfo[][4] = {
1895 { ABS_X, 0, sc->elanhw.sizex,
1897 { ABS_Y, 0, sc->elanhw.sizey,
1899 { ABS_PRESSURE, 0, ELANTECH_FINGER_MAX_P, 0 },
1900 { ABS_TOOL_WIDTH, 0, ELANTECH_FINGER_MAX_W, 0 },
1901 { ABS_MT_SLOT, 0, ELANTECH_MAX_FINGERS - 1, 0 },
1902 { ABS_MT_TRACKING_ID, -1, ELANTECH_MAX_FINGERS - 1, 0 },
1903 { ABS_MT_POSITION_X, 0, sc->elanhw.sizex,
1905 { ABS_MT_POSITION_Y, 0, sc->elanhw.sizey,
1907 { ABS_MT_PRESSURE, 0, ELANTECH_FINGER_MAX_P, 0 },
1908 { ABS_MT_TOUCH_MAJOR, 0, ELANTECH_FINGER_MAX_W *
1909 sc->elanhw.dptracex, 0 },
1912 struct evdev_dev *evdev_a;
1915 evdev_a = evdev_alloc();
1916 evdev_set_name(evdev_a, PS2_MOUSE_ELANTECH_NAME);
1917 evdev_set_phys(evdev_a, device_get_nameunit(dev));
1918 evdev_set_id(evdev_a, BUS_I8042, PS2_MOUSE_VENDOR,
1919 PS2_MOUSE_ELANTECH_PRODUCT, 0);
1920 evdev_set_methods(evdev_a, sc, &psm_ev_methods_a);
1922 evdev_support_event(evdev_a, EV_SYN);
1923 evdev_support_event(evdev_a, EV_KEY);
1924 evdev_support_event(evdev_a, EV_ABS);
1925 evdev_support_prop(evdev_a, INPUT_PROP_POINTER);
1926 if (sc->elanhw.issemimt)
1927 evdev_support_prop(evdev_a, INPUT_PROP_SEMI_MT);
1928 if (sc->elanhw.isclickpad)
1929 evdev_support_prop(evdev_a, INPUT_PROP_BUTTONPAD);
1930 evdev_support_key(evdev_a, BTN_TOUCH);
1931 evdev_support_nfingers(evdev_a, ELANTECH_MAX_FINGERS);
1932 evdev_support_key(evdev_a, BTN_LEFT);
1933 if (!sc->elanhw.isclickpad)
1934 evdev_support_key(evdev_a, BTN_RIGHT);
1935 psm_support_abs_bulk(evdev_a, elantech_absinfo);
1937 error = evdev_register_mtx(evdev_a, &Giant);
1938 if (!error && sc->elanhw.hastrackpoint)
1939 error = psm_register(dev, MOUSE_MODEL_ELANTECH);
1941 evdev_free(evdev_a);
1943 sc->evdev_a = evdev_a;
1949 psmattach(device_t dev)
1951 int unit = device_get_unit(dev);
1952 struct psm_softc *sc = device_get_softc(dev);
1956 /* Setup initial state */
1957 sc->state = PSM_VALID;
1958 callout_init(&sc->callout, 0);
1959 callout_init(&sc->softcallout, 0);
1961 /* Setup our interrupt handler */
1963 sc->intr = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
1964 if (sc->intr == NULL)
1966 error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, NULL, psmintr, sc,
1969 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
1974 sc->dev = make_dev(&psm_cdevsw, 0, 0, 0, 0666, "psm%d", unit);
1975 sc->dev->si_drv1 = sc;
1976 sc->bdev = make_dev(&psm_cdevsw, 0, 0, 0, 0666, "bpsm%d", unit);
1977 sc->bdev->si_drv1 = sc;
1979 #ifdef EVDEV_SUPPORT
1980 switch (sc->hw.model) {
1981 case MOUSE_MODEL_SYNAPTICS:
1982 error = psm_register_synaptics(dev);
1985 case MOUSE_MODEL_ELANTECH:
1986 error = psm_register_elantech(dev);
1990 error = psm_register(dev, sc->hw.model);
1997 /* Some touchpad devices need full reinitialization after suspend. */
1998 switch (sc->hw.model) {
1999 case MOUSE_MODEL_SYNAPTICS:
2000 case MOUSE_MODEL_GLIDEPOINT:
2001 case MOUSE_MODEL_VERSAPAD:
2002 case MOUSE_MODEL_ELANTECH:
2003 sc->config |= PSM_CONFIG_INITAFTERSUSPEND;
2006 if (sc->synhw.infoMajor >= 4 || sc->tphw > 0)
2007 sc->config |= PSM_CONFIG_INITAFTERSUSPEND;
2011 /* Elantech trackpad`s sync bit differs from touchpad`s one */
2012 if (sc->hw.model == MOUSE_MODEL_ELANTECH &&
2013 (sc->elanhw.hascrc || sc->elanhw.hastrackpoint)) {
2014 sc->config |= PSM_CONFIG_NOCHECKSYNC;
2015 sc->flags &= ~PSM_NEED_SYNCBITS;
2019 printf("psm%d: model %s, device ID %d\n",
2020 unit, model_name(sc->hw.model), sc->hw.hwid & 0x00ff);
2022 printf("psm%d: model %s, device ID %d-%02x, %d buttons\n",
2023 unit, model_name(sc->hw.model), sc->hw.hwid & 0x00ff,
2024 sc->hw.hwid >> 8, sc->hw.buttons);
2025 printf("psm%d: config:%08x, flags:%08x, packet size:%d\n",
2026 unit, sc->config, sc->flags, sc->mode.packetsize);
2027 printf("psm%d: syncmask:%02x, syncbits:%02x%s\n",
2028 unit, sc->mode.syncmask[0], sc->mode.syncmask[1],
2029 sc->config & PSM_CONFIG_NOCHECKSYNC ? " (sync not checked)" : "");
2039 psmdetach(device_t dev)
2041 struct psm_softc *sc;
2044 sc = device_get_softc(dev);
2045 if (sc->state & PSM_OPEN)
2048 #ifdef EVDEV_SUPPORT
2049 evdev_free(sc->evdev_r);
2050 evdev_free(sc->evdev_a);
2054 bus_teardown_intr(dev, sc->intr, sc->ih);
2055 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
2057 destroy_dev(sc->dev);
2058 destroy_dev(sc->bdev);
2060 callout_drain(&sc->callout);
2061 callout_drain(&sc->softcallout);
2066 #ifdef EVDEV_SUPPORT
2068 psm_ev_open_r(struct evdev_dev *evdev)
2070 struct psm_softc *sc = evdev_get_softc(evdev);
2073 /* Get device data */
2074 if ((sc->state & PSM_VALID) == 0) {
2075 /* the device is no longer valid/functioning */
2079 if (!(sc->state & (PSM_OPEN | PSM_EV_OPEN_A)))
2083 sc->state |= PSM_EV_OPEN_R;
2089 psm_ev_close_r(struct evdev_dev *evdev)
2091 struct psm_softc *sc = evdev_get_softc(evdev);
2094 sc->state &= ~PSM_EV_OPEN_R;
2096 if (sc->state & (PSM_OPEN | PSM_EV_OPEN_A))
2099 if (sc->state & PSM_VALID)
2106 psm_ev_open_a(struct evdev_dev *evdev)
2108 struct psm_softc *sc = evdev_get_softc(evdev);
2111 /* Get device data */
2112 if ((sc->state & PSM_VALID) == 0) {
2113 /* the device is no longer valid/functioning */
2117 if (!(sc->state & (PSM_OPEN | PSM_EV_OPEN_R)))
2121 sc->state |= PSM_EV_OPEN_A;
2127 psm_ev_close_a(struct evdev_dev *evdev)
2129 struct psm_softc *sc = evdev_get_softc(evdev);
2132 sc->state &= ~PSM_EV_OPEN_A;
2134 if (sc->state & (PSM_OPEN | PSM_EV_OPEN_R))
2137 if (sc->state & PSM_VALID)
2145 psm_cdev_open(struct cdev *dev, int flag, int fmt, struct thread *td)
2147 struct psm_softc *sc;
2150 /* Get device data */
2152 if ((sc == NULL) || (sc->state & PSM_VALID) == 0) {
2153 /* the device is no longer valid/functioning */
2157 /* Disallow multiple opens */
2158 if (sc->state & PSM_OPEN)
2161 device_busy(devclass_get_device(psm_devclass, sc->unit));
2163 #ifdef EVDEV_SUPPORT
2164 /* Already opened by evdev */
2165 if (!(sc->state & (PSM_EV_OPEN_R | PSM_EV_OPEN_A)))
2170 sc->state |= PSM_OPEN;
2172 device_unbusy(devclass_get_device(psm_devclass, sc->unit));
2178 psm_cdev_close(struct cdev *dev, int flag, int fmt, struct thread *td)
2180 struct psm_softc *sc;
2183 /* Get device data */
2185 if ((sc == NULL) || (sc->state & PSM_VALID) == 0) {
2186 /* the device is no longer valid/functioning */
2190 #ifdef EVDEV_SUPPORT
2191 /* Still opened by evdev */
2192 if (!(sc->state & (PSM_EV_OPEN_R | PSM_EV_OPEN_A)))
2197 sc->state &= ~PSM_OPEN;
2198 /* clean up and sigio requests */
2199 if (sc->async != NULL) {
2200 funsetown(&sc->async);
2203 device_unbusy(devclass_get_device(psm_devclass, sc->unit));
2210 psmopen(struct psm_softc *sc)
2216 /* Initialize state */
2217 sc->mode.level = sc->dflt_mode.level;
2218 sc->mode.protocol = sc->dflt_mode.protocol;
2219 sc->watchdog = FALSE;
2222 /* flush the event queue */
2223 sc->queue.count = 0;
2226 sc->status.flags = 0;
2227 sc->status.button = 0;
2228 sc->status.obutton = 0;
2233 sc->pqueue_start = 0;
2236 /* empty input buffer */
2241 /* don't let timeout routines in the keyboard driver to poll the kbdc */
2242 if (!kbdc_lock(sc->kbdc, TRUE))
2245 /* save the current controller command byte */
2247 command_byte = get_controller_command_byte(sc->kbdc);
2249 /* enable the aux port and temporalily disable the keyboard */
2250 if (command_byte == -1 || !set_controller_command_byte(sc->kbdc,
2251 kbdc_get_device_mask(sc->kbdc),
2252 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
2253 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
2254 /* CONTROLLER ERROR; do you know how to get out of this? */
2255 kbdc_lock(sc->kbdc, FALSE);
2258 "psm%d: unable to set the command byte (psmopen).\n",
2263 * Now that the keyboard controller is told not to generate
2264 * the keyboard and mouse interrupts, call `splx()' to allow
2265 * the other tty interrupts. The clock interrupt may also occur,
2266 * but timeout routines will be blocked by the poll flag set
2271 /* enable the mouse device */
2272 err = doopen(sc, command_byte);
2275 kbdc_lock(sc->kbdc, FALSE);
2280 psmclose(struct psm_softc *sc)
2286 /* don't let timeout routines in the keyboard driver to poll the kbdc */
2287 if (!kbdc_lock(sc->kbdc, TRUE))
2290 /* save the current controller command byte */
2292 command_byte = get_controller_command_byte(sc->kbdc);
2293 if (command_byte == -1) {
2294 kbdc_lock(sc->kbdc, FALSE);
2299 /* disable the aux interrupt and temporalily disable the keyboard */
2300 if (!set_controller_command_byte(sc->kbdc,
2301 kbdc_get_device_mask(sc->kbdc),
2302 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
2303 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
2305 "psm%d: failed to disable the aux int (psmclose).\n",
2307 /* CONTROLLER ERROR;
2308 * NOTE: we shall force our way through. Because the only
2309 * ill effect we shall see is that we may not be able
2310 * to read ACK from the mouse, and it doesn't matter much
2311 * so long as the mouse will accept the DISABLE command.
2316 /* stop the watchdog timer */
2317 callout_stop(&sc->callout);
2319 /* remove anything left in the output buffer */
2320 empty_aux_buffer(sc->kbdc, 10);
2322 /* disable the aux device, port and interrupt */
2323 if (sc->state & PSM_VALID) {
2324 if (!disable_aux_dev(sc->kbdc)) {
2326 * NOTE: we don't return (error) and continue,
2327 * pretending we have successfully disabled the device.
2328 * It's OK because the interrupt routine will discard
2329 * any data from the mouse hereafter.
2332 "psm%d: failed to disable the device (psmclose).\n",
2336 if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
2338 "psm%d: failed to get status (psmclose).\n",
2342 if (!set_controller_command_byte(sc->kbdc,
2343 kbdc_get_device_mask(sc->kbdc),
2344 (command_byte & KBD_KBD_CONTROL_BITS) |
2345 KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
2348 * we shall ignore this error; see the above comment.
2351 "psm%d: failed to disable the aux port (psmclose).\n",
2355 /* remove anything left in the output buffer */
2356 empty_aux_buffer(sc->kbdc, 10);
2358 /* close is almost always successful */
2359 kbdc_lock(sc->kbdc, FALSE);
2364 tame_mouse(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *status,
2367 static u_char butmapps2[8] = {
2369 MOUSE_PS2_BUTTON1DOWN,
2370 MOUSE_PS2_BUTTON2DOWN,
2371 MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON2DOWN,
2372 MOUSE_PS2_BUTTON3DOWN,
2373 MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON3DOWN,
2374 MOUSE_PS2_BUTTON2DOWN | MOUSE_PS2_BUTTON3DOWN,
2375 MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON2DOWN |
2376 MOUSE_PS2_BUTTON3DOWN,
2378 static u_char butmapmsc[8] = {
2379 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP |
2380 MOUSE_MSC_BUTTON3UP,
2381 MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
2382 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON3UP,
2383 MOUSE_MSC_BUTTON3UP,
2384 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP,
2385 MOUSE_MSC_BUTTON2UP,
2386 MOUSE_MSC_BUTTON1UP,
2392 if (sc->mode.level == PSM_LEVEL_BASE) {
2393 mapped = status->button & ~MOUSE_BUTTON4DOWN;
2394 if (status->button & MOUSE_BUTTON4DOWN)
2395 mapped |= MOUSE_BUTTON1DOWN;
2396 status->button = mapped;
2397 buf[0] = MOUSE_PS2_SYNC | butmapps2[mapped & MOUSE_STDBUTTONS];
2398 i = imax(imin(status->dx, 255), -256);
2400 buf[0] |= MOUSE_PS2_XNEG;
2402 i = imax(imin(status->dy, 255), -256);
2404 buf[0] |= MOUSE_PS2_YNEG;
2406 return (MOUSE_PS2_PACKETSIZE);
2407 } else if (sc->mode.level == PSM_LEVEL_STANDARD) {
2408 buf[0] = MOUSE_MSC_SYNC |
2409 butmapmsc[status->button & MOUSE_STDBUTTONS];
2410 i = imax(imin(status->dx, 255), -256);
2412 buf[3] = i - buf[1];
2413 i = imax(imin(status->dy, 255), -256);
2415 buf[4] = i - buf[2];
2416 i = imax(imin(status->dz, 127), -128);
2417 buf[5] = (i >> 1) & 0x7f;
2418 buf[6] = (i - (i >> 1)) & 0x7f;
2419 buf[7] = (~status->button >> 3) & 0x7f;
2420 return (MOUSE_SYS_PACKETSIZE);
2422 return (pb->inputbytes);
2426 psmread(struct cdev *dev, struct uio *uio, int flag)
2428 struct psm_softc *sc = dev->si_drv1;
2429 u_char buf[PSM_SMALLBUFSIZE];
2434 if ((sc->state & PSM_VALID) == 0)
2437 /* block until mouse activity occurred */
2439 while (sc->queue.count <= 0) {
2440 if (dev != sc->bdev) {
2442 return (EWOULDBLOCK);
2444 sc->state |= PSM_ASLP;
2445 error = tsleep(sc, PZERO | PCATCH, "psmrea", 0);
2446 sc->state &= ~PSM_ASLP;
2450 } else if ((sc->state & PSM_VALID) == 0) {
2451 /* the device disappeared! */
2458 /* copy data to the user land */
2459 while ((sc->queue.count > 0) && (uio->uio_resid > 0)) {
2461 l = imin(sc->queue.count, uio->uio_resid);
2462 if (l > sizeof(buf))
2464 if (l > sizeof(sc->queue.buf) - sc->queue.head) {
2465 bcopy(&sc->queue.buf[sc->queue.head], &buf[0],
2466 sizeof(sc->queue.buf) - sc->queue.head);
2467 bcopy(&sc->queue.buf[0],
2468 &buf[sizeof(sc->queue.buf) - sc->queue.head],
2469 l - (sizeof(sc->queue.buf) - sc->queue.head));
2471 bcopy(&sc->queue.buf[sc->queue.head], &buf[0], l);
2472 sc->queue.count -= l;
2473 sc->queue.head = (sc->queue.head + l) % sizeof(sc->queue.buf);
2475 error = uiomove(buf, l, uio);
2484 block_mouse_data(struct psm_softc *sc, int *c)
2488 if (!kbdc_lock(sc->kbdc, TRUE))
2492 *c = get_controller_command_byte(sc->kbdc);
2493 if ((*c == -1) || !set_controller_command_byte(sc->kbdc,
2494 kbdc_get_device_mask(sc->kbdc),
2495 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
2496 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
2497 /* this is CONTROLLER ERROR */
2499 kbdc_lock(sc->kbdc, FALSE);
2504 * The device may be in the middle of status data transmission.
2505 * The transmission will be interrupted, thus, incomplete status
2506 * data must be discarded. Although the aux interrupt is disabled
2507 * at the keyboard controller level, at most one aux interrupt
2508 * may have already been pending and a data byte is in the
2509 * output buffer; throw it away. Note that the second argument
2510 * to `empty_aux_buffer()' is zero, so that the call will just
2511 * flush the internal queue.
2512 * `psmintr()' will be invoked after `splx()' if an interrupt is
2513 * pending; it will see no data and returns immediately.
2515 empty_aux_buffer(sc->kbdc, 0); /* flush the queue */
2516 read_aux_data_no_wait(sc->kbdc); /* throw away data if any */
2524 dropqueue(struct psm_softc *sc)
2527 sc->queue.count = 0;
2530 if ((sc->state & PSM_SOFTARMED) != 0) {
2531 sc->state &= ~PSM_SOFTARMED;
2532 callout_stop(&sc->softcallout);
2534 sc->pqueue_start = sc->pqueue_end;
2538 flushpackets(struct psm_softc *sc)
2542 bzero(&sc->pqueue, sizeof(sc->pqueue));
2546 unblock_mouse_data(struct psm_softc *sc, int c)
2551 * We may have seen a part of status data during `set_mouse_XXX()'.
2552 * they have been queued; flush it.
2554 empty_aux_buffer(sc->kbdc, 0);
2556 /* restore ports and interrupt */
2557 if (!set_controller_command_byte(sc->kbdc,
2558 kbdc_get_device_mask(sc->kbdc),
2559 c & (KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS))) {
2561 * CONTROLLER ERROR; this is serious, we may have
2562 * been left with the inaccessible keyboard and
2563 * the disabled mouse interrupt.
2568 kbdc_lock(sc->kbdc, FALSE);
2573 psmwrite(struct cdev *dev, struct uio *uio, int flag)
2575 struct psm_softc *sc = dev->si_drv1;
2576 u_char buf[PSM_SMALLBUFSIZE];
2577 int error = 0, i, l;
2579 if ((sc->state & PSM_VALID) == 0)
2582 if (sc->mode.level < PSM_LEVEL_NATIVE)
2585 /* copy data from the user land */
2586 while (uio->uio_resid > 0) {
2587 l = imin(PSM_SMALLBUFSIZE, uio->uio_resid);
2588 error = uiomove(buf, l, uio);
2591 for (i = 0; i < l; i++) {
2592 VLOG(4, (LOG_DEBUG, "psm: cmd 0x%x\n", buf[i]));
2593 if (!write_aux_command(sc->kbdc, buf[i])) {
2595 "psm: cmd 0x%x failed.\n", buf[i]));
2596 return (reinitialize(sc, FALSE));
2605 psmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
2608 struct psm_softc *sc = dev->si_drv1;
2610 mousestatus_t status;
2617 /* Perform IOCTL command */
2620 case OLD_MOUSE_GETHWINFO:
2622 ((old_mousehw_t *)addr)->buttons = sc->hw.buttons;
2623 ((old_mousehw_t *)addr)->iftype = sc->hw.iftype;
2624 ((old_mousehw_t *)addr)->type = sc->hw.type;
2625 ((old_mousehw_t *)addr)->hwid = sc->hw.hwid & 0x00ff;
2629 case MOUSE_GETHWINFO:
2631 *(mousehw_t *)addr = sc->hw;
2632 if (sc->mode.level == PSM_LEVEL_BASE)
2633 ((mousehw_t *)addr)->model = MOUSE_MODEL_GENERIC;
2637 case MOUSE_SYN_GETHWINFO:
2639 if (sc->synhw.infoMajor >= 4)
2640 *(synapticshw_t *)addr = sc->synhw;
2646 case OLD_MOUSE_GETMODE:
2648 switch (sc->mode.level) {
2649 case PSM_LEVEL_BASE:
2650 ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2652 case PSM_LEVEL_STANDARD:
2653 ((old_mousemode_t *)addr)->protocol =
2654 MOUSE_PROTO_SYSMOUSE;
2656 case PSM_LEVEL_NATIVE:
2657 ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2660 ((old_mousemode_t *)addr)->rate = sc->mode.rate;
2661 ((old_mousemode_t *)addr)->resolution = sc->mode.resolution;
2662 ((old_mousemode_t *)addr)->accelfactor = sc->mode.accelfactor;
2668 *(mousemode_t *)addr = sc->mode;
2669 if ((sc->flags & PSM_NEED_SYNCBITS) != 0) {
2670 ((mousemode_t *)addr)->syncmask[0] = 0;
2671 ((mousemode_t *)addr)->syncmask[1] = 0;
2673 ((mousemode_t *)addr)->resolution =
2674 MOUSE_RES_LOW - sc->mode.resolution;
2675 switch (sc->mode.level) {
2676 case PSM_LEVEL_BASE:
2677 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2678 ((mousemode_t *)addr)->packetsize =
2679 MOUSE_PS2_PACKETSIZE;
2681 case PSM_LEVEL_STANDARD:
2682 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_SYSMOUSE;
2683 ((mousemode_t *)addr)->packetsize =
2684 MOUSE_SYS_PACKETSIZE;
2685 ((mousemode_t *)addr)->syncmask[0] = MOUSE_SYS_SYNCMASK;
2686 ((mousemode_t *)addr)->syncmask[1] = MOUSE_SYS_SYNC;
2688 case PSM_LEVEL_NATIVE:
2689 /* FIXME: this isn't quite correct... XXX */
2690 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2696 case OLD_MOUSE_SETMODE:
2698 if (cmd == OLD_MOUSE_SETMODE) {
2699 mode.rate = ((old_mousemode_t *)addr)->rate;
2701 * resolution old I/F new I/F
2708 if (((old_mousemode_t *)addr)->resolution > 0)
2710 -((old_mousemode_t *)addr)->resolution - 1;
2712 mode.resolution = 0;
2714 ((old_mousemode_t *)addr)->accelfactor;
2717 mode = *(mousemode_t *)addr;
2719 /* adjust and validate parameters. */
2720 if (mode.rate > UCHAR_MAX)
2723 mode.rate = sc->dflt_mode.rate;
2724 else if (mode.rate == -1)
2725 /* don't change the current setting */
2727 else if (mode.rate < 0)
2729 if (mode.resolution >= UCHAR_MAX)
2731 if (mode.resolution >= 200)
2732 mode.resolution = MOUSE_RES_HIGH;
2733 else if (mode.resolution >= 100)
2734 mode.resolution = MOUSE_RES_MEDIUMHIGH;
2735 else if (mode.resolution >= 50)
2736 mode.resolution = MOUSE_RES_MEDIUMLOW;
2737 else if (mode.resolution > 0)
2738 mode.resolution = MOUSE_RES_LOW;
2739 if (mode.resolution == MOUSE_RES_DEFAULT)
2740 mode.resolution = sc->dflt_mode.resolution;
2741 else if (mode.resolution == -1)
2742 /* don't change the current setting */
2744 else if (mode.resolution < 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */
2745 mode.resolution = MOUSE_RES_LOW - mode.resolution;
2746 if (mode.level == -1)
2747 /* don't change the current setting */
2748 mode.level = sc->mode.level;
2749 else if ((mode.level < PSM_LEVEL_MIN) ||
2750 (mode.level > PSM_LEVEL_MAX))
2752 if (mode.accelfactor == -1)
2753 /* don't change the current setting */
2754 mode.accelfactor = sc->mode.accelfactor;
2755 else if (mode.accelfactor < 0)
2758 /* don't allow anybody to poll the keyboard controller */
2759 error = block_mouse_data(sc, &command_byte);
2763 /* set mouse parameters */
2765 mode.rate = set_mouse_sampling_rate(sc->kbdc,
2767 if (mode.resolution >= 0)
2769 set_mouse_resolution(sc->kbdc, mode.resolution);
2770 set_mouse_scaling(sc->kbdc, 1);
2771 get_mouse_status(sc->kbdc, stat, 0, 3);
2774 sc->mode.rate = mode.rate;
2775 sc->mode.resolution = mode.resolution;
2776 sc->mode.accelfactor = mode.accelfactor;
2777 sc->mode.level = mode.level;
2780 unblock_mouse_data(sc, command_byte);
2783 case MOUSE_GETLEVEL:
2784 *(int *)addr = sc->mode.level;
2787 case MOUSE_SETLEVEL:
2788 if ((*(int *)addr < PSM_LEVEL_MIN) ||
2789 (*(int *)addr > PSM_LEVEL_MAX))
2791 sc->mode.level = *(int *)addr;
2794 case MOUSE_GETSTATUS:
2796 status = sc->status;
2797 sc->status.flags = 0;
2798 sc->status.obutton = sc->status.button;
2799 sc->status.button = 0;
2804 *(mousestatus_t *)addr = status;
2807 case MOUSE_READSTATE:
2808 case MOUSE_READDATA:
2809 data = (mousedata_t *)addr;
2810 if (data->len > sizeof(data->buf)/sizeof(data->buf[0]))
2813 error = block_mouse_data(sc, &command_byte);
2816 if ((data->len = get_mouse_status(sc->kbdc, data->buf,
2817 (cmd == MOUSE_READDATA) ? 1 : 0, data->len)) <= 0)
2819 unblock_mouse_data(sc, command_byte);
2822 #if (defined(MOUSE_SETRESOLUTION))
2823 case MOUSE_SETRESOLUTION:
2824 mode.resolution = *(int *)addr;
2825 if (mode.resolution >= UCHAR_MAX)
2827 else if (mode.resolution >= 200)
2828 mode.resolution = MOUSE_RES_HIGH;
2829 else if (mode.resolution >= 100)
2830 mode.resolution = MOUSE_RES_MEDIUMHIGH;
2831 else if (mode.resolution >= 50)
2832 mode.resolution = MOUSE_RES_MEDIUMLOW;
2833 else if (mode.resolution > 0)
2834 mode.resolution = MOUSE_RES_LOW;
2835 if (mode.resolution == MOUSE_RES_DEFAULT)
2836 mode.resolution = sc->dflt_mode.resolution;
2837 else if (mode.resolution == -1)
2838 mode.resolution = sc->mode.resolution;
2839 else if (mode.resolution < 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */
2840 mode.resolution = MOUSE_RES_LOW - mode.resolution;
2842 error = block_mouse_data(sc, &command_byte);
2845 sc->mode.resolution =
2846 set_mouse_resolution(sc->kbdc, mode.resolution);
2847 if (sc->mode.resolution != mode.resolution)
2849 unblock_mouse_data(sc, command_byte);
2851 #endif /* MOUSE_SETRESOLUTION */
2853 #if (defined(MOUSE_SETRATE))
2855 mode.rate = *(int *)addr;
2856 if (mode.rate > UCHAR_MAX)
2859 mode.rate = sc->dflt_mode.rate;
2860 else if (mode.rate < 0)
2861 mode.rate = sc->mode.rate;
2863 error = block_mouse_data(sc, &command_byte);
2866 sc->mode.rate = set_mouse_sampling_rate(sc->kbdc, mode.rate);
2867 if (sc->mode.rate != mode.rate)
2869 unblock_mouse_data(sc, command_byte);
2871 #endif /* MOUSE_SETRATE */
2873 #if (defined(MOUSE_SETSCALING))
2874 case MOUSE_SETSCALING:
2875 if ((*(int *)addr <= 0) || (*(int *)addr > 2))
2878 error = block_mouse_data(sc, &command_byte);
2881 if (!set_mouse_scaling(sc->kbdc, *(int *)addr))
2883 unblock_mouse_data(sc, command_byte);
2885 #endif /* MOUSE_SETSCALING */
2887 #if (defined(MOUSE_GETHWID))
2889 error = block_mouse_data(sc, &command_byte);
2892 sc->hw.hwid &= ~0x00ff;
2893 sc->hw.hwid |= get_aux_id(sc->kbdc);
2894 *(int *)addr = sc->hw.hwid & 0x00ff;
2895 unblock_mouse_data(sc, command_byte);
2897 #endif /* MOUSE_GETHWID */
2903 error = fsetown(*(int *)addr, &sc->async);
2906 *(int *) addr = fgetown(&sc->async);
2916 psmtimeout(void *arg)
2918 struct psm_softc *sc;
2921 sc = (struct psm_softc *)arg;
2923 if (sc->watchdog && kbdc_lock(sc->kbdc, TRUE)) {
2924 VLOG(6, (LOG_DEBUG, "psm%d: lost interrupt?\n", sc->unit));
2926 kbdc_lock(sc->kbdc, FALSE);
2928 sc->watchdog = TRUE;
2930 callout_reset(&sc->callout, hz, psmtimeout, sc);
2933 /* Add all sysctls under the debug.psm and hw.psm nodes */
2934 static SYSCTL_NODE(_debug, OID_AUTO, psm, CTLFLAG_RD, 0, "ps/2 mouse");
2935 static SYSCTL_NODE(_hw, OID_AUTO, psm, CTLFLAG_RD, 0, "ps/2 mouse");
2937 SYSCTL_INT(_debug_psm, OID_AUTO, loglevel, CTLFLAG_RWTUN, &verbose, 0,
2940 static int psmhz = 20;
2941 SYSCTL_INT(_debug_psm, OID_AUTO, hz, CTLFLAG_RW, &psmhz, 0,
2942 "Frequency of the softcallout (in hz)");
2943 static int psmerrsecs = 2;
2944 SYSCTL_INT(_debug_psm, OID_AUTO, errsecs, CTLFLAG_RW, &psmerrsecs, 0,
2945 "Number of seconds during which packets will dropped after a sync error");
2946 static int psmerrusecs = 0;
2947 SYSCTL_INT(_debug_psm, OID_AUTO, errusecs, CTLFLAG_RW, &psmerrusecs, 0,
2948 "Microseconds to add to psmerrsecs");
2949 static int psmsecs = 0;
2950 SYSCTL_INT(_debug_psm, OID_AUTO, secs, CTLFLAG_RW, &psmsecs, 0,
2951 "Max number of seconds between soft interrupts");
2952 static int psmusecs = 500000;
2953 SYSCTL_INT(_debug_psm, OID_AUTO, usecs, CTLFLAG_RW, &psmusecs, 0,
2954 "Microseconds to add to psmsecs");
2955 static int pkterrthresh = 2;
2956 SYSCTL_INT(_debug_psm, OID_AUTO, pkterrthresh, CTLFLAG_RW, &pkterrthresh, 0,
2957 "Number of error packets allowed before reinitializing the mouse");
2959 SYSCTL_INT(_hw_psm, OID_AUTO, tap_enabled, CTLFLAG_RWTUN, &tap_enabled, 0,
2960 "Enable tap and drag gestures");
2961 static int tap_threshold = PSM_TAP_THRESHOLD;
2962 SYSCTL_INT(_hw_psm, OID_AUTO, tap_threshold, CTLFLAG_RW, &tap_threshold, 0,
2963 "Button tap threshold");
2964 static int tap_timeout = PSM_TAP_TIMEOUT;
2965 SYSCTL_INT(_hw_psm, OID_AUTO, tap_timeout, CTLFLAG_RW, &tap_timeout, 0,
2966 "Tap timeout for touchpads");
2969 SYSCTL_INT(_hw_psm, OID_AUTO, synaptics_support, CTLFLAG_RDTUN,
2970 &synaptics_support, 0, "Enable support for Synaptics touchpads");
2972 SYSCTL_INT(_hw_psm, OID_AUTO, trackpoint_support, CTLFLAG_RDTUN,
2973 &trackpoint_support, 0, "Enable support for IBM/Lenovo TrackPoint");
2975 SYSCTL_INT(_hw_psm, OID_AUTO, elantech_support, CTLFLAG_RDTUN,
2976 &elantech_support, 0, "Enable support for Elantech touchpads");
2981 struct psm_softc *sc = arg;
2986 if (aux_mux_is_enabled(sc->kbdc))
2987 VLOG(2, (LOG_DEBUG, "psmintr: active multiplexing mode is not "
2990 /* read until there is nothing to read */
2991 while((c = read_aux_data_no_wait(sc->kbdc)) != -1) {
2992 pb = &sc->pqueue[sc->pqueue_end];
2994 /* discard the byte if the device is not open */
2995 if (!(sc->state & (PSM_OPEN | PSM_EV_OPEN_R | PSM_EV_OPEN_A)))
2998 getmicrouptime(&now);
2999 if ((pb->inputbytes > 0) &&
3000 timevalcmp(&now, &sc->inputtimeout, >)) {
3001 VLOG(3, (LOG_DEBUG, "psmintr: delay too long; "
3002 "resetting byte count\n"));
3007 sc->inputtimeout.tv_sec = PSM_INPUT_TIMEOUT / 1000000;
3008 sc->inputtimeout.tv_usec = PSM_INPUT_TIMEOUT % 1000000;
3009 timevaladd(&sc->inputtimeout, &now);
3011 pb->ipacket[pb->inputbytes++] = c;
3013 if (sc->mode.level == PSM_LEVEL_NATIVE) {
3014 VLOG(4, (LOG_DEBUG, "psmintr: %02x\n", pb->ipacket[0]));
3019 if (pb->inputbytes < sc->mode.packetsize)
3023 "psmintr: %02x %02x %02x %02x %02x %02x\n",
3024 pb->ipacket[0], pb->ipacket[1], pb->ipacket[2],
3025 pb->ipacket[3], pb->ipacket[4], pb->ipacket[5]));
3030 if ((sc->flags & PSM_NEED_SYNCBITS) != 0) {
3031 sc->mode.syncmask[1] = (c & sc->mode.syncmask[0]);
3032 sc->flags &= ~PSM_NEED_SYNCBITS;
3034 "psmintr: Sync bytes now %04x,%04x\n",
3035 sc->mode.syncmask[0], sc->mode.syncmask[1]));
3036 } else if ((sc->config & PSM_CONFIG_NOCHECKSYNC) == 0 &&
3037 (c & sc->mode.syncmask[0]) != sc->mode.syncmask[1]) {
3038 VLOG(3, (LOG_DEBUG, "psmintr: out of sync "
3039 "(%04x != %04x) %d cmds since last error.\n",
3040 c & sc->mode.syncmask[0], sc->mode.syncmask[1],
3041 sc->cmdcount - sc->lasterr));
3042 sc->lasterr = sc->cmdcount;
3044 * The sync byte test is a weak measure of packet
3045 * validity. Conservatively discard any input yet
3046 * to be seen by userland when we detect a sync
3047 * error since there is a good chance some of
3048 * the queued packets have undetected errors.
3051 if (sc->syncerrors == 0)
3054 sc->lastinputerr = now;
3055 if (sc->syncerrors >= sc->mode.packetsize * 2 ||
3056 sc->pkterrors >= pkterrthresh) {
3058 * If we've failed to find a single sync byte
3059 * in 2 packets worth of data, or we've seen
3060 * persistent packet errors during the
3061 * validation period, reinitialize the mouse
3062 * in hopes of returning it to the expected
3066 "psmintr: reset the mouse.\n"));
3067 reinitialize(sc, TRUE);
3068 } else if (sc->syncerrors == sc->mode.packetsize) {
3070 * Try a soft reset after searching for a sync
3071 * byte through a packet length of bytes.
3074 "psmintr: re-enable the mouse.\n"));
3076 disable_aux_dev(sc->kbdc);
3077 enable_aux_dev(sc->kbdc);
3080 "psmintr: discard a byte (%d)\n",
3083 bcopy(&pb->ipacket[1], &pb->ipacket[0],
3090 * We have what appears to be a valid packet.
3091 * Reset the error counters.
3096 * Drop even good packets if they occur within a timeout
3097 * period of a sync error. This allows the detection of
3098 * a change in the mouse's packet mode without exposing
3099 * erratic mouse behavior to the user. Some KVMs forget
3100 * enhanced mouse modes during switch events.
3102 if (!timeelapsed(&sc->lastinputerr, psmerrsecs, psmerrusecs,
3109 * Now that we're out of the validation period, reset
3110 * the packet error count.
3116 if (++sc->pqueue_end >= PSM_PACKETQUEUE)
3119 * If we've filled the queue then call the softintr ourselves,
3120 * otherwise schedule the interrupt for later.
3122 if (!timeelapsed(&sc->lastsoftintr, psmsecs, psmusecs, &now) ||
3123 (sc->pqueue_end == sc->pqueue_start)) {
3124 if ((sc->state & PSM_SOFTARMED) != 0) {
3125 sc->state &= ~PSM_SOFTARMED;
3126 callout_stop(&sc->softcallout);
3129 } else if ((sc->state & PSM_SOFTARMED) == 0) {
3130 sc->state |= PSM_SOFTARMED;
3131 callout_reset(&sc->softcallout,
3132 psmhz < 1 ? 1 : (hz/psmhz), psmsoftintr, arg);
3138 proc_mmanplus(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
3139 int *x, int *y, int *z)
3143 * PS2++ protocol packet
3145 * b7 b6 b5 b4 b3 b2 b1 b0
3146 * byte 1: * 1 p3 p2 1 * * *
3147 * byte 2: c1 c2 p1 p0 d1 d0 1 0
3149 * p3-p0: packet type
3150 * c1, c2: c1 & c2 == 1, if p2 == 0
3151 * c1 & c2 == 0, if p2 == 1
3153 * packet type: 0 (device type)
3154 * See comments in enable_mmanplus() below.
3156 * packet type: 1 (wheel data)
3158 * b7 b6 b5 b4 b3 b2 b1 b0
3159 * byte 3: h * B5 B4 s d2 d1 d0
3161 * h: 1, if horizontal roller data
3162 * 0, if vertical roller data
3163 * B4, B5: button 4 and 5
3165 * d2-d0: roller data
3167 * packet type: 2 (reserved)
3169 if (((pb->ipacket[0] & MOUSE_PS2PLUS_SYNCMASK) == MOUSE_PS2PLUS_SYNC) &&
3170 (abs(*x) > 191) && MOUSE_PS2PLUS_CHECKBITS(pb->ipacket)) {
3172 * the extended data packet encodes button
3175 switch (MOUSE_PS2PLUS_PACKET_TYPE(pb->ipacket)) {
3177 /* wheel data packet */
3179 if (pb->ipacket[2] & 0x80) {
3180 /* XXX horizontal roller count - ignore it */
3183 /* vertical roller count */
3184 *z = (pb->ipacket[2] & MOUSE_PS2PLUS_ZNEG) ?
3185 (pb->ipacket[2] & 0x0f) - 16 :
3186 (pb->ipacket[2] & 0x0f);
3188 ms->button |= (pb->ipacket[2] &
3189 MOUSE_PS2PLUS_BUTTON4DOWN) ?
3190 MOUSE_BUTTON4DOWN : 0;
3191 ms->button |= (pb->ipacket[2] &
3192 MOUSE_PS2PLUS_BUTTON5DOWN) ?
3193 MOUSE_BUTTON5DOWN : 0;
3197 * this packet type is reserved by
3201 * IBM ScrollPoint Mouse uses this
3202 * packet type to encode both vertical
3203 * and horizontal scroll movement.
3206 /* horizontal count */
3207 if (pb->ipacket[2] & 0x0f)
3208 *z = (pb->ipacket[2] & MOUSE_SPOINT_WNEG) ?
3210 /* vertical count */
3211 if (pb->ipacket[2] & 0xf0)
3212 *z = (pb->ipacket[2] & MOUSE_SPOINT_ZNEG) ?
3216 /* device type packet - shouldn't happen */
3220 ms->button = ms->obutton;
3221 VLOG(1, (LOG_DEBUG, "psmintr: unknown PS2++ packet "
3222 "type %d: 0x%02x 0x%02x 0x%02x\n",
3223 MOUSE_PS2PLUS_PACKET_TYPE(pb->ipacket),
3224 pb->ipacket[0], pb->ipacket[1], pb->ipacket[2]));
3228 /* preserve button states */
3229 ms->button |= ms->obutton & MOUSE_EXTBUTTONS;
3234 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
3235 int *x, int *y, int *z)
3237 static int touchpad_buttons;
3238 static int guest_buttons;
3239 static int ew_finger_count;
3240 static finger_t f[PSM_FINGERS];
3241 int w, id, nfingers, palm, ewcode, extended_buttons, clickpad_pressed;
3243 extended_buttons = 0;
3245 /* TouchPad PS/2 absolute mode message format with capFourButtons:
3247 * Bits: 7 6 5 4 3 2 1 0 (LSB)
3248 * ------------------------------------------------
3249 * ipacket[0]: 1 0 W3 W2 0 W1 R L
3250 * ipacket[1]: Yb Ya Y9 Y8 Xb Xa X9 X8
3251 * ipacket[2]: Z7 Z6 Z5 Z4 Z3 Z2 Z1 Z0
3252 * ipacket[3]: 1 1 Yc Xc 0 W0 D^R U^L
3253 * ipacket[4]: X7 X6 X5 X4 X3 X2 X1 X0
3254 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
3257 * L: left physical mouse button
3258 * R: right physical mouse button
3266 * Without capFourButtons but with nExtendeButtons and/or capMiddle
3268 * Bits: 7 6 5 4 3 2 1 0 (LSB)
3269 * ------------------------------------------------------
3270 * ipacket[3]: 1 1 Yc Xc 0 W0 E^R M^L
3271 * ipacket[4]: X7 X6 X5 X4 X3|b7 X2|b5 X1|b3 X0|b1
3272 * ipacket[5]: Y7 Y6 Y5 Y4 Y3|b8 Y2|b6 Y1|b4 Y0|b2
3275 * M: Middle physical mouse button
3276 * E: Extended mouse buttons reported instead of low bits of X and Y
3277 * b1-b8: Extended mouse buttons
3278 * Only ((nExtendedButtons + 1) >> 1) bits are used in packet
3279 * 4 and 5, for reading X and Y value they should be zeroed.
3281 * Absolute reportable limits: 0 - 6143.
3282 * Typical bezel limits: 1472 - 5472.
3283 * Typical edge marings: 1632 - 5312.
3285 * w = 3 Passthrough Packet
3287 * Byte 2,5,6 == Byte 1,2,3 of "Guest"
3290 if (!synaptics_support)
3293 /* Sanity check for out of sync packets. */
3294 if ((pb->ipacket[0] & 0xc8) != 0x80 ||
3295 (pb->ipacket[3] & 0xc8) != 0xc0)
3299 ms->button = ms->obutton;
3304 * z = 0 No finger contact
3305 * z = 10 Finger hovering near the pad
3306 * z = 30 Very light finger contact
3307 * z = 80 Normal finger contact
3308 * z = 110 Very heavy finger contact
3309 * z = 200 Finger lying flat on pad surface
3310 * z = 255 Maximum reportable Z
3312 *z = pb->ipacket[2];
3315 * Finger width value
3317 * w = 0 Two finger on the pad (capMultiFinger needed)
3318 * w = 1 Three or more fingers (capMultiFinger needed)
3319 * w = 2 Pen (instead of finger) (capPen needed)
3320 * w = 3 Reserved (passthrough?)
3321 * w = 4-7 Finger of normal width (capPalmDetect needed)
3322 * w = 8-14 Very wide finger or palm (capPalmDetect needed)
3323 * w = 15 Maximum reportable width (capPalmDetect needed)
3325 /* XXX Is checking capExtended enough? */
3326 if (sc->synhw.capExtended)
3327 w = ((pb->ipacket[0] & 0x30) >> 2) |
3328 ((pb->ipacket[0] & 0x04) >> 1) |
3329 ((pb->ipacket[3] & 0x04) >> 2);
3331 /* Assume a finger of regular width. */
3338 * Handle packets from the guest device. See:
3339 * Synaptics PS/2 TouchPad Interfacing Guide, Section 5.1
3341 if (sc->synhw.capPassthrough || sc->muxport != PSM_NOMUX) {
3342 *x = ((pb->ipacket[1] & 0x10) ?
3343 pb->ipacket[4] - 256 : pb->ipacket[4]);
3344 *y = ((pb->ipacket[1] & 0x20) ?
3345 pb->ipacket[5] - 256 : pb->ipacket[5]);
3349 if (pb->ipacket[1] & 0x01)
3350 guest_buttons |= MOUSE_BUTTON1DOWN;
3351 if (pb->ipacket[1] & 0x04)
3352 guest_buttons |= MOUSE_BUTTON2DOWN;
3353 if (pb->ipacket[1] & 0x02)
3354 guest_buttons |= MOUSE_BUTTON3DOWN;
3355 #ifdef EVDEV_SUPPORT
3356 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
3357 evdev_push_rel(sc->evdev_r, REL_X, *x);
3358 evdev_push_rel(sc->evdev_r, REL_Y, -*y);
3359 evdev_push_mouse_btn(sc->evdev_r,
3361 evdev_sync(sc->evdev_r);
3364 ms->button = touchpad_buttons | guest_buttons |
3365 sc->extended_buttons;
3370 /* Handle Extended W mode packets */
3371 ewcode = (pb->ipacket[5] & 0xf0) >> 4;
3375 /* Secondary finger */
3376 if (sc->synhw.capAdvancedGestures)
3378 .x = (((pb->ipacket[4] & 0x0f) << 8) |
3379 pb->ipacket[1]) << 1,
3380 .y = (((pb->ipacket[4] & 0xf0) << 4) |
3381 pb->ipacket[2]) << 1,
3382 .p = ((pb->ipacket[3] & 0x30) |
3383 (pb->ipacket[5] & 0x0f)) << 1,
3384 .w = PSM_FINGER_DEFAULT_W,
3385 .flags = PSM_FINGER_FUZZY,
3387 else if (sc->synhw.capReportsV)
3389 .x = (((pb->ipacket[4] & 0x0f) << 8) |
3390 (pb->ipacket[1] & 0xfe)) << 1,
3391 .y = (((pb->ipacket[4] & 0xf0) << 4) |
3392 (pb->ipacket[2] & 0xfe)) << 1,
3393 .p = ((pb->ipacket[3] & 0x30) |
3394 (pb->ipacket[5] & 0x0e)) << 1,
3395 .w = (((pb->ipacket[5] & 0x01) << 2) |
3396 ((pb->ipacket[2] & 0x01) << 1) |
3397 (pb->ipacket[1] & 0x01)) + 8,
3398 .flags = PSM_FINGER_FUZZY,
3402 ew_finger_count = pb->ipacket[1] & 0x0f;
3410 if (sc->synhw.capReportsV && ew_finger_count > 3) {
3411 nfingers = ew_finger_count;
3423 if (sc->syninfo.touchpad_off)
3426 /* Button presses */
3427 touchpad_buttons = 0;
3428 if (pb->ipacket[0] & 0x01)
3429 touchpad_buttons |= MOUSE_BUTTON1DOWN;
3430 if (pb->ipacket[0] & 0x02)
3431 touchpad_buttons |= MOUSE_BUTTON3DOWN;
3433 if (sc->synhw.capExtended && sc->synhw.capFourButtons) {
3434 if ((pb->ipacket[3] ^ pb->ipacket[0]) & 0x01)
3435 touchpad_buttons |= MOUSE_BUTTON4DOWN;
3436 if ((pb->ipacket[3] ^ pb->ipacket[0]) & 0x02)
3437 touchpad_buttons |= MOUSE_BUTTON5DOWN;
3438 } else if (sc->synhw.capExtended && sc->synhw.capMiddle &&
3439 !sc->synhw.capClickPad) {
3441 if ((pb->ipacket[0] ^ pb->ipacket[3]) & 0x01)
3442 touchpad_buttons |= MOUSE_BUTTON2DOWN;
3443 } else if (sc->synhw.capExtended && (sc->synhw.nExtendedButtons > 0)) {
3444 /* Extended Buttons */
3445 if ((pb->ipacket[0] ^ pb->ipacket[3]) & 0x02) {
3446 if (sc->syninfo.directional_scrolls) {
3447 if (pb->ipacket[4] & 0x01)
3448 extended_buttons |= MOUSE_BUTTON4DOWN;
3449 if (pb->ipacket[5] & 0x01)
3450 extended_buttons |= MOUSE_BUTTON5DOWN;
3451 if (pb->ipacket[4] & 0x02)
3452 extended_buttons |= MOUSE_BUTTON6DOWN;
3453 if (pb->ipacket[5] & 0x02)
3454 extended_buttons |= MOUSE_BUTTON7DOWN;
3456 if (pb->ipacket[4] & 0x01)
3457 extended_buttons |= MOUSE_BUTTON1DOWN;
3458 if (pb->ipacket[5] & 0x01)
3459 extended_buttons |= MOUSE_BUTTON3DOWN;
3460 if (pb->ipacket[4] & 0x02)
3461 extended_buttons |= MOUSE_BUTTON2DOWN;
3462 sc->extended_buttons = extended_buttons;
3466 * Zero out bits used by extended buttons to avoid
3467 * misinterpretation of the data absolute position.
3469 * The bits represented by
3471 * (nExtendedButtons + 1) >> 1
3473 * will be masked out in both bytes.
3474 * The mask for n bits is computed with the formula
3480 maskedbits = (sc->synhw.nExtendedButtons + 1) >> 1;
3481 mask = (1 << maskedbits) - 1;
3482 #ifdef EVDEV_SUPPORT
3484 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
3485 if (sc->synhw.capPassthrough) {
3486 evdev_push_mouse_btn(sc->evdev_r,
3488 evdev_sync(sc->evdev_r);
3490 for (i = 0; i < maskedbits; i++) {
3491 evdev_push_key(sc->evdev_a,
3493 pb->ipacket[4] & (1 << i));
3494 evdev_push_key(sc->evdev_a,
3496 pb->ipacket[5] & (1 << i));
3500 pb->ipacket[4] &= ~(mask);
3501 pb->ipacket[5] &= ~(mask);
3502 } else if (!sc->syninfo.directional_scrolls &&
3503 !sc->gesture.in_vscroll) {
3505 * Keep reporting MOUSE DOWN until we get a new packet
3506 * indicating otherwise.
3508 extended_buttons |= sc->extended_buttons;
3512 if (sc->synhw.capReportsV && nfingers > 1)
3514 .x = ((pb->ipacket[3] & 0x10) << 8) |
3515 ((pb->ipacket[1] & 0x0f) << 8) |
3516 (pb->ipacket[4] & 0xfd),
3517 .y = ((pb->ipacket[3] & 0x20) << 7) |
3518 ((pb->ipacket[1] & 0xf0) << 4) |
3519 (pb->ipacket[5] & 0xfd),
3521 .w = (((pb->ipacket[2] & 0x01) << 2) |
3522 (pb->ipacket[5] & 0x02) |
3523 ((pb->ipacket[4] & 0x02) >> 1)) + 8,
3524 .flags = PSM_FINGER_FUZZY,
3528 .x = ((pb->ipacket[3] & 0x10) << 8) |
3529 ((pb->ipacket[1] & 0x0f) << 8) |
3531 .y = ((pb->ipacket[3] & 0x20) << 7) |
3532 ((pb->ipacket[1] & 0xf0) << 4) |
3536 .flags = nfingers > 1 ? PSM_FINGER_FUZZY : 0,
3539 /* Ignore hovering and unmeasurable touches */
3540 if (f[0].p < sc->syninfo.min_pressure || f[0].x < 2)
3543 /* Handle ClickPad */
3544 if (sc->synhw.capClickPad) {
3545 clickpad_pressed = (pb->ipacket[0] ^ pb->ipacket[3]) & 0x01;
3546 if (sc->synhw.forcePad) {
3548 * Forcepads erroneously report button click if there
3549 * are 2 or more fingers on the touchpad breaking
3550 * multifinger gestures. To workaround this start
3551 * reporting a click only after 4 consecutive single
3552 * touch packets has been received.
3553 * Skip these packets in case more contacts appear.
3560 if (clickpad_pressed && sc->fpcount < INT_MAX)
3564 if (!clickpad_pressed)
3566 if (sc->fpcount >= sc->syninfo.window_min)
3567 touchpad_buttons |= MOUSE_BUTTON1DOWN;
3569 } else if (clickpad_pressed)
3570 touchpad_buttons |= MOUSE_BUTTON1DOWN;
3573 for (id = 0; id < PSM_FINGERS; id++)
3575 PSM_FINGER_RESET(f[id]);
3577 #ifdef EVDEV_SUPPORT
3578 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
3579 for (id = 0; id < PSM_FINGERS; id++) {
3580 if (PSM_FINGER_IS_SET(f[id]))
3581 psm_push_mt_finger(sc, id, &f[id]);
3583 psm_release_mt_slot(sc->evdev_a, id);
3585 evdev_push_key(sc->evdev_a, BTN_TOUCH, nfingers > 0);
3586 evdev_push_nfingers(sc->evdev_a, nfingers);
3588 psm_push_st_finger(sc, &f[0]);
3590 evdev_push_abs(sc->evdev_a, ABS_PRESSURE, 0);
3591 evdev_push_mouse_btn(sc->evdev_a, touchpad_buttons);
3592 if (sc->synhw.capExtended && sc->synhw.capFourButtons) {
3593 evdev_push_key(sc->evdev_a, BTN_FORWARD,
3594 touchpad_buttons & MOUSE_BUTTON4DOWN);
3595 evdev_push_key(sc->evdev_a, BTN_BACK,
3596 touchpad_buttons & MOUSE_BUTTON5DOWN);
3598 evdev_sync(sc->evdev_a);
3602 ms->button = touchpad_buttons;
3604 palm = psmpalmdetect(sc, &f[0], nfingers);
3606 /* Palm detection doesn't terminate the current action. */
3608 psmgestures(sc, &f[0], nfingers, ms);
3610 for (id = 0; id < PSM_FINGERS; id++)
3611 psmsmoother(sc, &f[id], id, ms, x, y);
3615 ms->button = ms->obutton;
3619 ms->button |= extended_buttons | guest_buttons;
3623 * Use the extra buttons as a scrollwheel
3625 * XXX X.Org uses the Z axis for vertical wheel only,
3626 * whereas moused(8) understands special values to differ
3627 * vertical and horizontal wheels.
3629 * xf86-input-mouse needs therefore a small patch to
3630 * understand these special values. Without it, the
3631 * horizontal wheel acts as a vertical wheel in X.Org.
3633 * That's why the horizontal wheel is disabled by
3636 if (ms->button & MOUSE_BUTTON4DOWN)
3638 else if (ms->button & MOUSE_BUTTON5DOWN)
3640 else if (ms->button & MOUSE_BUTTON6DOWN)
3642 else if (ms->button & MOUSE_BUTTON7DOWN)
3646 ms->button &= ~(MOUSE_BUTTON4DOWN | MOUSE_BUTTON5DOWN |
3647 MOUSE_BUTTON6DOWN | MOUSE_BUTTON7DOWN);
3653 proc_synaptics_mux(struct psm_softc *sc, packetbuf_t *pb)
3658 * Convert 3-byte interleaved mixture of Synaptics and generic mouse
3659 * packets into plain 6-byte Synaptics packet protocol.
3660 * While in hidden multiplexing mode KBC does some editing of the
3661 * packet stream. It remembers the button bits from the last packet
3662 * received from each device, and replaces the button bits of every
3663 * packet with the logical OR of all devices’ most recent button bits.
3664 * This button crosstalk should be filtered out as Synaptics and
3665 * generic mouse encode middle button presses in a different way.
3667 switch (pb->ipacket[0] & 0xc0) {
3668 case 0x80: /* First 3 bytes of Synaptics packet */
3669 bcopy(pb->ipacket, sc->muxsave, 3);
3670 /* Compute middle mouse button supression timeout. */
3671 sc->muxmidtimeout.tv_sec = 0;
3672 sc->muxmidtimeout.tv_usec = 50000; /* ~2-3 ints */
3673 timevaladd(&sc->muxmidtimeout, &sc->lastsoftintr);
3676 case 0xc0: /* Second 3 bytes of Synaptics packet */
3677 /* Join two 3-bytes absolute packets */
3678 bcopy(pb->ipacket, pb->ipacket + 3, 3);
3679 bcopy(sc->muxsave, pb->ipacket, 3);
3680 /* Prefer trackpoint buttons over touchpad's */
3681 pb->ipacket[0] &= ~(0x08 | sc->muxmsbuttons);
3682 pb->ipacket[3] &= ~(0x08 | sc->muxmsbuttons);
3683 butt = (pb->ipacket[3] & 0x03) << 2 | (pb->ipacket[0] & 0x03);
3684 /* Add hysteresis to remove spurious middle button events */
3685 if (butt != sc->muxtpbuttons && sc->fpcount < 1) {
3686 pb->ipacket[0] &= 0xfc;
3687 pb->ipacket[0] |= sc->muxtpbuttons & 0x03;
3688 pb->ipacket[3] &= 0xfc;
3689 pb->ipacket[3] |= sc->muxtpbuttons >> 2 & 0x03;
3693 sc->muxtpbuttons = butt;
3695 /* Filter out impossible w induced by middle trackpoint btn */
3696 if (sc->synhw.capExtended && !sc->synhw.capPassthrough &&
3697 (pb->ipacket[0] & 0x34) == 0x04 &&
3698 (pb->ipacket[3] & 0x04) == 0x04) {
3699 pb->ipacket[0] &= 0xfb;
3700 pb->ipacket[3] &= 0xfb;
3702 sc->muxsave[0] &= 0x30;
3705 default: /* Generic mouse (Trackpoint) packet */
3706 /* Filter out middle button events induced by some w values */
3707 if (sc->muxmsbuttons & 0x03 || pb->ipacket[0] & 0x03 ||
3708 (timevalcmp(&sc->lastsoftintr, &sc->muxmidtimeout, <=) &&
3709 (sc->muxsave[0] & 0x30 || sc->muxsave[2] > 8)))
3710 pb->ipacket[0] &= 0xfb;
3711 sc->muxmsbuttons = pb->ipacket[0] & 0x07;
3712 /* Convert to Synaptics pass-through protocol */
3713 pb->ipacket[4] = pb->ipacket[1];
3714 pb->ipacket[5] = pb->ipacket[2];
3715 pb->ipacket[1] = pb->ipacket[0];
3717 pb->ipacket[0] = 0x84 | (sc->muxtpbuttons & 0x03);
3718 pb->ipacket[3] = 0xc4 | (sc->muxtpbuttons >> 2 & 0x03);
3721 VLOG(4, (LOG_DEBUG, "synaptics: %02x %02x %02x %02x %02x %02x\n",
3722 pb->ipacket[0], pb->ipacket[1], pb->ipacket[2],
3723 pb->ipacket[3], pb->ipacket[4], pb->ipacket[5]));
3725 pb->inputbytes = MOUSE_SYNAPTICS_PACKETSIZE;
3730 psmpalmdetect(struct psm_softc *sc, finger_t *f, int nfingers)
3733 ((sc->synhw.capMultiFinger || sc->synhw.capAdvancedGestures) &&
3734 !sc->synhw.capReportsV && nfingers > 1) ||
3735 (sc->synhw.capReportsV && nfingers > 2) ||
3736 (sc->synhw.capPalmDetect && f->w <= sc->syninfo.max_width) ||
3737 (!sc->synhw.capPalmDetect && f->p <= sc->syninfo.max_pressure) ||
3738 (sc->synhw.capPen && f->flags & PSM_FINGER_IS_PEN))) {
3740 * We consider the packet irrelevant for the current
3742 * - the width isn't comprised in:
3744 * - the pressure isn't comprised in:
3745 * [min_pressure; max_pressure]
3746 * - pen aren't supported but PSM_FINGER_IS_PEN is set
3748 VLOG(2, (LOG_DEBUG, "synaptics: palm detected! (%d)\n", f->w));
3755 psmgestures(struct psm_softc *sc, finger_t *fingers, int nfingers,
3758 smoother_t *smoother;
3761 int y_ok, center_button, center_x, right_button, right_x, i;
3764 smoother = &sc->smoother[0];
3765 gest = &sc->gesture;
3767 /* Find first active finger. */
3769 for (i = 0; i < PSM_FINGERS; i++) {
3770 if (PSM_FINGER_IS_SET(fingers[i])) {
3772 smoother = &sc->smoother[i];
3779 * Check pressure to detect a real wanted action on the
3782 if (f->p >= sc->syninfo.min_pressure) {
3785 int start_x, start_y;
3787 int margin_top, margin_right, margin_bottom, margin_left;
3788 int window_min, window_max;
3789 int vscroll_hor_area, vscroll_ver_area;
3790 int two_finger_scroll;
3792 int three_finger_drag;
3795 /* XXX Verify values? */
3796 margin_top = sc->syninfo.margin_top;
3797 margin_right = sc->syninfo.margin_right;
3798 margin_bottom = sc->syninfo.margin_bottom;
3799 margin_left = sc->syninfo.margin_left;
3800 window_min = sc->syninfo.window_min;
3801 window_max = sc->syninfo.window_max;
3802 vscroll_hor_area = sc->syninfo.vscroll_hor_area;
3803 vscroll_ver_area = sc->syninfo.vscroll_ver_area;
3804 two_finger_scroll = sc->syninfo.two_finger_scroll;
3805 max_x = sc->syninfo.max_x;
3806 max_y = sc->syninfo.max_y;
3807 three_finger_drag = sc->syninfo.three_finger_drag;
3808 /* Read current absolute position. */
3813 * Limit the coordinates to the specified margins because
3814 * this area isn't very reliable.
3816 if (x0 <= margin_left)
3818 else if (x0 >= max_x - margin_right)
3819 x0 = max_x - margin_right;
3820 if (y0 <= margin_bottom)
3822 else if (y0 >= max_y - margin_top)
3823 y0 = max_y - margin_top;
3825 VLOG(3, (LOG_DEBUG, "synaptics: ipacket: [%d, %d], %d, %d\n",
3826 x0, y0, f->p, f->w));
3829 * If the action is just beginning, init the structure and
3830 * compute tap timeout.
3832 if (!(sc->flags & PSM_FLAGS_FINGERDOWN)) {
3833 VLOG(3, (LOG_DEBUG, "synaptics: ----\n"));
3835 /* Initialize queue. */
3836 gest->window_min = window_min;
3838 /* Reset pressure peak. */
3841 /* Reset fingers count. */
3842 gest->fingers_nb = 0;
3844 /* Reset virtual scrolling state. */
3845 gest->in_vscroll = 0;
3847 /* Compute tap timeout. */
3848 if (tap_enabled != 0) {
3849 gest->taptimeout = (struct timeval) {
3850 .tv_sec = tap_timeout / 1000000,
3851 .tv_usec = tap_timeout % 1000000,
3854 &gest->taptimeout, &sc->lastsoftintr);
3856 timevalclear(&gest->taptimeout);
3858 sc->flags |= PSM_FLAGS_FINGERDOWN;
3860 /* Smoother has not been reset yet */
3865 queue_len = smoother->queue_len + 1;
3866 start_x = smoother->start_x;
3867 start_y = smoother->start_y;
3870 /* Process ClickPad softbuttons */
3871 if (sc->synhw.capClickPad && ms->button & MOUSE_BUTTON1DOWN) {
3872 y_ok = sc->syninfo.softbuttons_y >= 0 ?
3873 start_y < sc->syninfo.softbuttons_y :
3874 start_y > max_y + sc->syninfo.softbuttons_y;
3876 center_button = MOUSE_BUTTON2DOWN;
3877 center_x = sc->syninfo.softbutton2_x;
3878 right_button = MOUSE_BUTTON3DOWN;
3879 right_x = sc->syninfo.softbutton3_x;
3881 if (center_x > 0 && right_x > 0 && center_x > right_x) {
3882 center_button = MOUSE_BUTTON3DOWN;
3883 center_x = sc->syninfo.softbutton3_x;
3884 right_button = MOUSE_BUTTON2DOWN;
3885 right_x = sc->syninfo.softbutton2_x;
3888 if (right_x > 0 && start_x > right_x && y_ok)
3889 ms->button = (ms->button &
3890 ~MOUSE_BUTTON1DOWN) | right_button;
3891 else if (center_x > 0 && start_x > center_x && y_ok)
3892 ms->button = (ms->button &
3893 ~MOUSE_BUTTON1DOWN) | center_button;
3896 /* If in tap-hold or three fingers, add the recorded button. */
3897 if (gest->in_taphold || (nfingers == 3 && three_finger_drag))
3898 ms->button |= gest->tap_button;
3901 * For tap, we keep the maximum number of fingers and the
3902 * pressure peak. Also with multiple fingers, we increase
3903 * the minimum window.
3906 gest->window_min = window_max;
3907 gest->fingers_nb = imax(nfingers, gest->fingers_nb);
3908 gest->zmax = imax(f->p, gest->zmax);
3910 /* Do we have enough packets to consider this a gesture? */
3911 if (queue_len < gest->window_min)
3917 /* Is a scrolling action occurring? */
3918 if (!gest->in_taphold && !ms->button &&
3919 (!gest->in_vscroll || two_finger_scroll)) {
3921 * A scrolling action must not conflict with a tap
3922 * action. Here are the conditions to consider a
3924 * - the action in a configurable area
3925 * - one of the following:
3926 * . the distance between the last packet and the
3927 * first should be above a configurable minimum
3930 dxp = abs(x0 - start_x);
3931 dyp = abs(y0 - start_y);
3933 if (timevalcmp(&sc->lastsoftintr, &gest->taptimeout, >) ||
3934 dxp >= sc->syninfo.vscroll_min_delta ||
3935 dyp >= sc->syninfo.vscroll_min_delta) {
3937 * Handle two finger scrolling.
3938 * Note that we don't rely on fingers_nb
3939 * as that keeps the maximum number of fingers.
3941 if (two_finger_scroll) {
3942 if (nfingers == 2) {
3949 /* Check for horizontal scrolling. */
3950 if ((vscroll_hor_area > 0 &&
3951 start_y <= vscroll_hor_area) ||
3952 (vscroll_hor_area < 0 &&
3954 max_y + vscroll_hor_area))
3955 gest->in_vscroll += 2;
3957 /* Check for vertical scrolling. */
3958 if ((vscroll_ver_area > 0 &&
3959 start_x <= vscroll_ver_area) ||
3960 (vscroll_ver_area < 0 &&
3962 max_x + vscroll_ver_area))
3963 gest->in_vscroll += 1;
3966 /* Avoid conflicts if area overlaps. */
3967 if (gest->in_vscroll >= 3)
3969 (dxp > dyp) ? 2 : 1;
3973 * Reset two finger scrolling when the number of fingers
3974 * is different from two or any button is pressed.
3976 if (two_finger_scroll && gest->in_vscroll != 0 &&
3977 (nfingers != 2 || ms->button))
3978 gest->in_vscroll = 0;
3981 "synaptics: virtual scrolling: %s "
3982 "(direction=%d, dxp=%d, dyp=%d, fingers=%d)\n",
3983 gest->in_vscroll ? "YES" : "NO",
3984 gest->in_vscroll, dxp, dyp,
3987 } else if (sc->flags & PSM_FLAGS_FINGERDOWN) {
3989 * An action is currently taking place but the pressure
3990 * dropped under the minimum, putting an end to it.
3992 int taphold_timeout, dx, dy, tap_max_delta;
3994 dx = abs(smoother->queue[smoother->queue_cursor].x -
3996 dy = abs(smoother->queue[smoother->queue_cursor].y -
3999 /* Max delta is disabled for multi-fingers tap. */
4000 if (gest->fingers_nb > 1)
4001 tap_max_delta = imax(dx, dy);
4003 tap_max_delta = sc->syninfo.tap_max_delta;
4005 sc->flags &= ~PSM_FLAGS_FINGERDOWN;
4007 /* Check for tap. */
4009 "synaptics: zmax=%d, dx=%d, dy=%d, "
4010 "delta=%d, fingers=%d, queue=%d\n",
4011 gest->zmax, dx, dy, tap_max_delta, gest->fingers_nb,
4012 smoother->queue_len));
4013 if (!gest->in_vscroll && gest->zmax >= tap_threshold &&
4014 timevalcmp(&sc->lastsoftintr, &gest->taptimeout, <=) &&
4015 dx <= tap_max_delta && dy <= tap_max_delta &&
4016 smoother->queue_len >= sc->syninfo.tap_min_queue) {
4019 * - the maximum pressure went over tap_threshold
4020 * - the action ended before tap_timeout
4022 * To handle tap-hold, we must delay any button push to
4025 if (gest->in_taphold) {
4027 * This is the second and last tap of a
4028 * double tap action, not a tap-hold.
4030 gest->in_taphold = 0;
4033 * For double-tap to work:
4034 * - no button press is emitted (to
4035 * simulate a button release)
4036 * - PSM_FLAGS_FINGERDOWN is set to
4037 * force the next packet to emit a
4041 "synaptics: button RELEASE: %d\n",
4043 sc->flags |= PSM_FLAGS_FINGERDOWN;
4045 /* Schedule button press on next interrupt */
4046 sc->idletimeout.tv_sec = psmhz > 1 ?
4048 sc->idletimeout.tv_usec = psmhz > 1 ?
4049 1000000 / psmhz : 0;
4052 * This is the first tap: we set the
4053 * tap-hold state and notify the button
4056 gest->in_taphold = 1;
4057 taphold_timeout = sc->syninfo.taphold_timeout;
4058 gest->taptimeout.tv_sec = taphold_timeout /
4060 gest->taptimeout.tv_usec = taphold_timeout %
4062 sc->idletimeout = gest->taptimeout;
4063 timevaladd(&gest->taptimeout,
4066 switch (gest->fingers_nb) {
4080 "synaptics: button PRESS: %d\n",
4082 ms->button |= gest->tap_button;
4086 * Not enough pressure or timeout: reset
4089 if (gest->in_taphold) {
4091 "synaptics: button RELEASE: %d\n",
4093 gest->in_taphold = 0;
4096 "synaptics: not a tap-hold\n"));
4099 } else if (!(sc->flags & PSM_FLAGS_FINGERDOWN) && gest->in_taphold) {
4101 * For a tap-hold to work, the button must remain down at
4102 * least until timeout (where the in_taphold flags will be
4103 * cleared) or during the next action.
4105 if (timevalcmp(&sc->lastsoftintr, &gest->taptimeout, <=)) {
4106 ms->button |= gest->tap_button;
4108 VLOG(2, (LOG_DEBUG, "synaptics: button RELEASE: %d\n",
4110 gest->in_taphold = 0;
4118 psmsmoother(struct psm_softc *sc, finger_t *f, int smoother_id,
4119 mousestatus_t *ms, int *x, int *y)
4121 smoother_t *smoother = &sc->smoother[smoother_id];
4122 gesture_t *gest = &(sc->gesture);
4125 * Check pressure to detect a real wanted action on the
4128 if (f->p >= sc->syninfo.min_pressure) {
4130 int cursor, peer, window;
4131 int dx, dy, dxp, dyp;
4132 int max_width, max_pressure;
4133 int margin_top, margin_right, margin_bottom, margin_left;
4134 int na_top, na_right, na_bottom, na_left;
4135 int window_min, window_max;
4137 int weight_current, weight_previous, weight_len_squared;
4138 int div_min, div_max, div_len;
4139 int vscroll_hor_area, vscroll_ver_area;
4140 int two_finger_scroll;
4142 int len, weight_prev_x, weight_prev_y;
4143 int div_max_x, div_max_y, div_x, div_y;
4148 /* XXX Verify values? */
4149 max_width = sc->syninfo.max_width;
4150 max_pressure = sc->syninfo.max_pressure;
4151 margin_top = sc->syninfo.margin_top;
4152 margin_right = sc->syninfo.margin_right;
4153 margin_bottom = sc->syninfo.margin_bottom;
4154 margin_left = sc->syninfo.margin_left;
4155 na_top = sc->syninfo.na_top;
4156 na_right = sc->syninfo.na_right;
4157 na_bottom = sc->syninfo.na_bottom;
4158 na_left = sc->syninfo.na_left;
4159 window_min = sc->syninfo.window_min;
4160 window_max = sc->syninfo.window_max;
4161 multiplicator = sc->syninfo.multiplicator;
4162 weight_current = sc->syninfo.weight_current;
4163 weight_previous = sc->syninfo.weight_previous;
4164 weight_len_squared = sc->syninfo.weight_len_squared;
4165 div_min = sc->syninfo.div_min;
4166 div_max = sc->syninfo.div_max;
4167 div_len = sc->syninfo.div_len;
4168 vscroll_hor_area = sc->syninfo.vscroll_hor_area;
4169 vscroll_ver_area = sc->syninfo.vscroll_ver_area;
4170 two_finger_scroll = sc->syninfo.two_finger_scroll;
4171 max_x = sc->syninfo.max_x;
4172 max_y = sc->syninfo.max_y;
4173 natural_scroll = sc->syninfo.natural_scroll;
4175 is_fuzzy = (f->flags & PSM_FINGER_FUZZY) != 0;
4177 /* Read current absolute position. */
4182 * Limit the coordinates to the specified margins because
4183 * this area isn't very reliable.
4185 if (x0 <= margin_left)
4187 else if (x0 >= max_x - margin_right)
4188 x0 = max_x - margin_right;
4189 if (y0 <= margin_bottom)
4191 else if (y0 >= max_y - margin_top)
4192 y0 = max_y - margin_top;
4194 /* If the action is just beginning, init the structure. */
4195 if (smoother->active == 0) {
4196 VLOG(3, (LOG_DEBUG, "smoother%d: ---\n", smoother_id));
4198 /* Store the first point of this action. */
4199 smoother->start_x = x0;
4200 smoother->start_y = y0;
4203 /* Initialize queue. */
4204 smoother->queue_cursor = SYNAPTICS_PACKETQUEUE;
4205 smoother->queue_len = 0;
4207 /* Reset average. */
4208 smoother->avg_dx = 0;
4209 smoother->avg_dy = 0;
4211 /* Reset squelch. */
4212 smoother->squelch_x = 0;
4213 smoother->squelch_y = 0;
4215 /* Activate queue */
4216 smoother->active = 1;
4218 /* Calculate the current delta. */
4219 cursor = smoother->queue_cursor;
4220 dx = x0 - smoother->queue[cursor].x;
4221 dy = y0 - smoother->queue[cursor].y;
4224 VLOG(3, (LOG_DEBUG, "smoother%d: ipacket: [%d, %d], %d, %d\n",
4225 smoother_id, x0, y0, f->p, f->w));
4227 /* Queue this new packet. */
4228 cursor = SYNAPTICS_QUEUE_CURSOR(smoother->queue_cursor - 1);
4229 smoother->queue[cursor].x = x0;
4230 smoother->queue[cursor].y = y0;
4231 smoother->queue_cursor = cursor;
4232 if (smoother->queue_len < SYNAPTICS_PACKETQUEUE)
4233 smoother->queue_len++;
4235 "smoother%d: cursor[%d]: x=%d, y=%d, dx=%d, dy=%d\n",
4236 smoother_id, cursor, x0, y0, dx, dy));
4238 /* Do we have enough packets to consider this a movement? */
4239 if (smoother->queue_len < gest->window_min)
4242 weight_prev_x = weight_prev_y = weight_previous;
4243 div_max_x = div_max_y = div_max;
4245 if (gest->in_vscroll) {
4246 /* Dividers are different with virtual scrolling. */
4247 div_min = sc->syninfo.vscroll_div_min;
4248 div_max_x = div_max_y = sc->syninfo.vscroll_div_max;
4251 * There's a lot of noise in coordinates when
4252 * the finger is on the touchpad's borders. When
4253 * using this area, we apply a special weight and
4256 if (x0 <= na_left || x0 >= max_x - na_right) {
4257 weight_prev_x = sc->syninfo.weight_previous_na;
4258 div_max_x = sc->syninfo.div_max_na;
4261 if (y0 <= na_bottom || y0 >= max_y - na_top) {
4262 weight_prev_y = sc->syninfo.weight_previous_na;
4263 div_max_y = sc->syninfo.div_max_na;
4268 * Calculate weights for the average operands and
4269 * the divisor. Both depend on the distance between
4270 * the current packet and a previous one (based on the
4273 window = imin(smoother->queue_len, window_max);
4274 peer = SYNAPTICS_QUEUE_CURSOR(cursor + window - 1);
4275 dxp = abs(x0 - smoother->queue[peer].x) + 1;
4276 dyp = abs(y0 - smoother->queue[peer].y) + 1;
4277 len = (dxp * dxp) + (dyp * dyp);
4278 weight_prev_x = imin(weight_prev_x,
4279 weight_len_squared * weight_prev_x / len);
4280 weight_prev_y = imin(weight_prev_y,
4281 weight_len_squared * weight_prev_y / len);
4283 len = (dxp + dyp) / 2;
4284 div_x = div_len * div_max_x / len;
4285 div_x = imin(div_max_x, div_x);
4286 div_x = imax(div_min, div_x);
4287 div_y = div_len * div_max_y / len;
4288 div_y = imin(div_max_y, div_y);
4289 div_y = imax(div_min, div_y);
4292 "smoother%d: peer=%d, len=%d, weight=%d/%d, div=%d/%d\n",
4293 smoother_id, peer, len, weight_prev_x, weight_prev_y,
4296 /* Compute averages. */
4298 (weight_current * dx * multiplicator +
4299 weight_prev_x * smoother->avg_dx) /
4300 (weight_current + weight_prev_x);
4303 (weight_current * dy * multiplicator +
4304 weight_prev_y * smoother->avg_dy) /
4305 (weight_current + weight_prev_y);
4308 "smoother%d: avg_dx~=%d, avg_dy~=%d\n", smoother_id,
4309 smoother->avg_dx / multiplicator,
4310 smoother->avg_dy / multiplicator));
4312 /* Use these averages to calculate x & y. */
4313 smoother->squelch_x += smoother->avg_dx;
4314 dxp = smoother->squelch_x / (div_x * multiplicator);
4315 smoother->squelch_x = smoother->squelch_x %
4316 (div_x * multiplicator);
4318 smoother->squelch_y += smoother->avg_dy;
4319 dyp = smoother->squelch_y / (div_y * multiplicator);
4320 smoother->squelch_y = smoother->squelch_y %
4321 (div_y * multiplicator);
4323 switch(gest->in_vscroll) {
4324 case 0: /* Pointer movement. */
4325 /* On real<->fuzzy finger switch the x/y pos jumps */
4326 if (is_fuzzy == smoother->is_fuzzy) {
4331 VLOG(3, (LOG_DEBUG, "smoother%d: [%d, %d] -> [%d, %d]\n",
4332 smoother_id, dx, dy, dxp, dyp));
4334 case 1: /* Vertical scrolling. */
4336 if (two_finger_scroll && natural_scroll)
4337 ms->button |= (dyp > 0) ?
4338 MOUSE_BUTTON5DOWN : MOUSE_BUTTON4DOWN;
4340 ms->button |= (dyp > 0) ?
4341 MOUSE_BUTTON4DOWN : MOUSE_BUTTON5DOWN;
4344 case 2: /* Horizontal scrolling. */
4346 if (two_finger_scroll && natural_scroll)
4347 ms->button |= (dxp > 0) ?
4348 MOUSE_BUTTON6DOWN : MOUSE_BUTTON7DOWN;
4350 ms->button |= (dxp > 0) ?
4351 MOUSE_BUTTON7DOWN : MOUSE_BUTTON6DOWN;
4356 smoother->is_fuzzy = is_fuzzy;
4360 * Deactivate queue. Note: We can not just reset queue here
4361 * as these values are still used by gesture processor.
4362 * So postpone reset till next touch.
4364 smoother->active = 0;
4369 proc_elantech(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
4370 int *x, int *y, int *z)
4372 static int touchpad_button, trackpoint_button;
4373 finger_t fn, f[ELANTECH_MAX_FINGERS];
4374 int pkt, id, scale, i, nfingers, mask, palm;
4376 if (!elantech_support)
4379 /* Determine packet format and do a sanity check for out of sync packets. */
4380 if (ELANTECH_PKT_IS_DEBOUNCE(pb, sc->elanhw.hwversion))
4381 pkt = ELANTECH_PKT_NOP;
4382 else if (sc->elanhw.hastrackpoint && ELANTECH_PKT_IS_TRACKPOINT(pb))
4383 pkt = ELANTECH_PKT_TRACKPOINT;
4385 switch (sc->elanhw.hwversion) {
4387 if (!ELANTECH_PKT_IS_V2(pb))
4390 pkt = (pb->ipacket[0] & 0xc0) == 0x80 ?
4391 ELANTECH_PKT_V2_2FINGER : ELANTECH_PKT_V2_COMMON;
4394 if (!ELANTECH_PKT_IS_V3_HEAD(pb, sc->elanhw.hascrc) &&
4395 !ELANTECH_PKT_IS_V3_TAIL(pb, sc->elanhw.hascrc))
4398 pkt = ELANTECH_PKT_V3;
4401 if (!ELANTECH_PKT_IS_V4(pb, sc->elanhw.hascrc))
4404 switch (pb->ipacket[3] & 0x03) {
4406 pkt = ELANTECH_PKT_V4_STATUS;
4409 pkt = ELANTECH_PKT_V4_HEAD;
4412 pkt = ELANTECH_PKT_V4_MOTION;
4422 VLOG(5, (LOG_DEBUG, "elantech: ipacket format: %d\n", pkt));
4424 for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
4425 PSM_FINGER_RESET(f[id]);
4428 ms->button = ms->obutton;
4430 if (sc->syninfo.touchpad_off)
4434 * L: Left mouse button pressed
4435 * R: Right mouse button pressed
4436 * N: number of fingers on touchpad
4437 * X: absolute x value (horizontal)
4438 * Y: absolute y value (vertical)
4439 * W; width of the finger touch
4443 case ELANTECH_PKT_V2_COMMON: /* HW V2. One/Three finger touch */
4444 /* 7 6 5 4 3 2 1 0 (LSB)
4445 * -------------------------------------------
4446 * ipacket[0]: N1 N0 W3 W2 . . R L
4447 * ipacket[1]: P7 P6 P5 P4 X11 X10 X9 X8
4448 * ipacket[2]: X7 X6 X5 X4 X3 X2 X1 X0
4449 * ipacket[3]: N4 VF W1 W0 . . . B2
4450 * ipacket[4]: P3 P1 P2 P0 Y11 Y10 Y9 Y8
4451 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
4452 * -------------------------------------------
4453 * N4: set if more than 3 fingers (only in 3 fingers mode)
4454 * VF: a kind of flag? (only on EF123, 0 when finger
4455 * is over one of the buttons, 1 otherwise)
4456 * B2: (on EF113 only, 0 otherwise), one button pressed
4457 * P & W is not reported on EF113 touchpads
4459 nfingers = (pb->ipacket[0] & 0xc0) >> 6;
4460 if (nfingers == 3 && (pb->ipacket[3] & 0x80))
4463 if (nfingers == 0) {
4464 mask = (1 << nfingers) - 1; /* = 0x00 */
4468 /* Map 3-rd and 4-th fingers to first finger */
4469 mask = (1 << 1) - 1; /* = 0x01 */
4470 f[0] = ELANTECH_FINGER_SET_XYP(pb);
4471 if (sc->elanhw.haspressure) {
4472 f[0].w = ((pb->ipacket[0] & 0x30) >> 2) |
4473 ((pb->ipacket[3] & 0x30) >> 4);
4475 f[0].p = PSM_FINGER_DEFAULT_P;
4476 f[0].w = PSM_FINGER_DEFAULT_W;
4480 * HW v2 dont report exact finger positions when 3 or more
4481 * fingers are on touchpad.
4484 f[0].flags = PSM_FINGER_FUZZY;
4488 case ELANTECH_PKT_V2_2FINGER: /*HW V2. Two finger touch */
4489 /* 7 6 5 4 3 2 1 0 (LSB)
4490 * -------------------------------------------
4491 * ipacket[0]: N1 N0 AY8 AX8 . . R L
4492 * ipacket[1]: AX7 AX6 AX5 AX4 AX3 AX2 AX1 AX0
4493 * ipacket[2]: AY7 AY6 AY5 AY4 AY3 AY2 AY1 AY0
4494 * ipacket[3]: . . BY8 BX8 . . . .
4495 * ipacket[4]: BX7 BX6 BX5 BX4 BX3 BX2 BX1 BX0
4496 * ipacket[5]: BY7 BY6 BY5 BY4 BY3 BY2 BY1 BY0
4497 * -------------------------------------------
4498 * AX: lower-left finger absolute x value
4499 * AY: lower-left finger absolute y value
4500 * BX: upper-right finger absolute x value
4501 * BY: upper-right finger absolute y value
4504 mask = (1 << nfingers) - 1;
4506 for (id = 0; id < imin(2, ELANTECH_MAX_FINGERS); id ++)
4507 f[id] = (finger_t) {
4508 .x = (((pb->ipacket[id * 3] & 0x10) << 4) |
4509 pb->ipacket[id * 3 + 1]) << 2,
4510 .y = (((pb->ipacket[id * 3] & 0x20) << 3) |
4511 pb->ipacket[id * 3 + 2]) << 2,
4512 .p = PSM_FINGER_DEFAULT_P,
4513 .w = PSM_FINGER_DEFAULT_W,
4514 /* HW ver.2 sends bounding box */
4515 .flags = PSM_FINGER_FUZZY
4519 case ELANTECH_PKT_V3: /* HW Version 3 */
4520 /* 7 6 5 4 3 2 1 0 (LSB)
4521 * -------------------------------------------
4522 * ipacket[0]: N1 N0 W3 W2 0 1 R L
4523 * ipacket[1]: P7 P6 P5 P4 X11 X10 X9 X8
4524 * ipacket[2]: X7 X6 X5 X4 X3 X2 X1 X0
4525 * ipacket[3]: 0 0 W1 W0 0 0 1 0
4526 * ipacket[4]: P3 P1 P2 P0 Y11 Y10 Y9 Y8
4527 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
4528 * -------------------------------------------
4530 nfingers = (pb->ipacket[0] & 0xc0) >> 6;
4531 /* Map 3-rd finger to first finger */
4532 id = nfingers > 2 ? 0 : nfingers - 1;
4533 mask = (1 << (id + 1)) - 1;
4538 fn = ELANTECH_FINGER_SET_XYP(pb);
4539 fn.w = ((pb->ipacket[0] & 0x30) >> 2) |
4540 ((pb->ipacket[3] & 0x30) >> 4);
4543 * HW v3 dont report exact finger positions when 3 or more
4544 * fingers are on touchpad.
4547 fn.flags = PSM_FINGER_FUZZY;
4549 if (nfingers == 2) {
4550 if (ELANTECH_PKT_IS_V3_HEAD(pb, sc->elanhw.hascrc)) {
4551 sc->elanaction.fingers[0] = fn;
4554 f[0] = sc->elanaction.fingers[0];
4559 case ELANTECH_PKT_V4_STATUS: /* HW Version 4. Status packet */
4560 /* 7 6 5 4 3 2 1 0 (LSB)
4561 * -------------------------------------------
4562 * ipacket[0]: . . . . 0 1 R L
4563 * ipacket[1]: . . . F4 F3 F2 F1 F0
4564 * ipacket[2]: . . . . . . . .
4565 * ipacket[3]: . . . 1 0 0 0 0
4566 * ipacket[4]: PL . . . . . . .
4567 * ipacket[5]: . . . . . . . .
4568 * -------------------------------------------
4569 * Fn: finger n is on touchpad
4571 * HV ver4 sends a status packet to indicate that the numbers
4572 * or identities of the fingers has been changed
4575 mask = pb->ipacket[1] & 0x1f;
4576 nfingers = bitcount(mask);
4578 if (sc->elanaction.mask_v4wait != 0)
4579 VLOG(3, (LOG_DEBUG, "elantech: HW v4 status packet"
4580 " when not all previous head packets received\n"));
4582 /* Bitmap of fingers to receive before gesture processing */
4583 sc->elanaction.mask_v4wait = mask & ~sc->elanaction.mask;
4585 /* Skip "new finger is on touchpad" packets */
4586 if (sc->elanaction.mask_v4wait) {
4587 sc->elanaction.mask = mask;
4593 case ELANTECH_PKT_V4_HEAD: /* HW Version 4. Head packet */
4594 /* 7 6 5 4 3 2 1 0 (LSB)
4595 * -------------------------------------------
4596 * ipacket[0]: W3 W2 W1 W0 0 1 R L
4597 * ipacket[1]: P7 P6 P5 P4 X11 X10 X9 X8
4598 * ipacket[2]: X7 X6 X5 X4 X3 X2 X1 X0
4599 * ipacket[3]: ID2 ID1 ID0 1 0 0 0 1
4600 * ipacket[4]: P3 P1 P2 P0 Y11 Y10 Y9 Y8
4601 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
4602 * -------------------------------------------
4604 * HW ver 4 sends head packets in two cases:
4605 * 1. One finger touch and movement.
4606 * 2. Next after status packet to tell new finger positions.
4608 mask = sc->elanaction.mask;
4609 nfingers = bitcount(mask);
4610 id = ((pb->ipacket[3] & 0xe0) >> 5) - 1;
4611 fn = ELANTECH_FINGER_SET_XYP(pb);
4612 fn.w =(pb->ipacket[0] & 0xf0) >> 4;
4617 /* Packet is finger position update. Report it */
4618 if (sc->elanaction.mask_v4wait == 0) {
4619 if (id < ELANTECH_MAX_FINGERS)
4624 /* Remove finger from waiting bitmap and store into context */
4625 sc->elanaction.mask_v4wait &= ~(1 << id);
4626 if (id < ELANTECH_MAX_FINGERS)
4627 sc->elanaction.fingers[id] = fn;
4629 /* Wait for other fingers if needed */
4630 if (sc->elanaction.mask_v4wait != 0)
4633 /* All new fingers are received. Report them from context */
4634 for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
4635 if (sc->elanaction.mask & (1 << id))
4636 f[id] = sc->elanaction.fingers[id];
4640 case ELANTECH_PKT_V4_MOTION: /* HW Version 4. Motion packet */
4641 /* 7 6 5 4 3 2 1 0 (LSB)
4642 * -------------------------------------------
4643 * ipacket[0]: ID2 ID1 ID0 OF 0 1 R L
4644 * ipacket[1]: DX7 DX6 DX5 DX4 DX3 DX2 DX1 DX0
4645 * ipacket[2]: DY7 DY6 DY5 DY4 DY3 DY2 DY1 DY0
4646 * ipacket[3]: ID2 ID1 ID0 1 0 0 1 0
4647 * ipacket[4]: DX7 DX6 DX5 DX4 DX3 DX2 DX1 DX0
4648 * ipacket[5]: DY7 DY6 DY5 DY4 DY3 DY2 DY1 DY0
4649 * -------------------------------------------
4650 * OF: delta overflows (> 127 or < -128), in this case
4651 * firmware sends us (delta x / 5) and (delta y / 5)
4653 * DX: delta x (two's complement)
4654 * XY: delta y (two's complement)
4655 * byte 0 ~ 2 for one finger
4656 * byte 3 ~ 5 for another finger
4658 mask = sc->elanaction.mask;
4659 nfingers = bitcount(mask);
4661 scale = (pb->ipacket[0] & 0x10) ? 5 : 1;
4662 for (i = 0; i <= 3; i += 3) {
4663 id = ((pb->ipacket[i] & 0xe0) >> 5) - 1;
4664 if (id < 0 || id >= ELANTECH_MAX_FINGERS)
4667 if (PSM_FINGER_IS_SET(sc->elanaction.fingers[id])) {
4668 f[id] = sc->elanaction.fingers[id];
4669 f[id].x += imax(-f[id].x,
4670 (signed char)pb->ipacket[i+1] * scale);
4671 f[id].y += imax(-f[id].y,
4672 (signed char)pb->ipacket[i+2] * scale);
4674 VLOG(3, (LOG_DEBUG, "elantech: "
4675 "HW v4 motion packet skipped\n"));
4681 case ELANTECH_PKT_TRACKPOINT:
4682 /* 7 6 5 4 3 2 1 0 (LSB)
4683 * -------------------------------------------
4684 * ipacket[0]: 0 0 SY SX 0 M R L
4685 * ipacket[1]: ~SX 0 0 0 0 0 0 0
4686 * ipacket[2]: ~SY 0 0 0 0 0 0 0
4687 * ipacket[3]: 0 0 ~SY ~SX 0 1 1 0
4688 * ipacket[4]: X7 X6 X5 X4 X3 X2 X1 X0
4689 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
4690 * -------------------------------------------
4691 * X and Y are written in two's complement spread
4692 * over 9 bits with SX/SY the relative top bit and
4693 * X7..X0 and Y7..Y0 the lower bits.
4695 if (!(pb->ipacket[0] & 0xC8) && !(pb->ipacket[1] & 0x7F) &&
4696 !(pb->ipacket[2] & 0x7F) && !(pb->ipacket[3] & 0xC9) &&
4697 !(pb->ipacket[0] & 0x10) != !(pb->ipacket[1] & 0x80) &&
4698 !(pb->ipacket[0] & 0x10) != !(pb->ipacket[3] & 0x10) &&
4699 !(pb->ipacket[0] & 0x20) != !(pb->ipacket[2] & 0x80) &&
4700 !(pb->ipacket[0] & 0x20) != !(pb->ipacket[3] & 0x20)) {
4702 *x = (pb->ipacket[0] & MOUSE_PS2_XNEG) ?
4703 pb->ipacket[4] - 256 : pb->ipacket[4];
4704 *y = (pb->ipacket[0] & MOUSE_PS2_YNEG) ?
4705 pb->ipacket[5] - 256 : pb->ipacket[5];
4708 ((pb->ipacket[0] & 0x01) ? MOUSE_BUTTON1DOWN : 0) |
4709 ((pb->ipacket[0] & 0x02) ? MOUSE_BUTTON3DOWN : 0) |
4710 ((pb->ipacket[0] & 0x04) ? MOUSE_BUTTON2DOWN : 0);
4711 #ifdef EVDEV_SUPPORT
4712 evdev_push_rel(sc->evdev_r, REL_X, *x);
4713 evdev_push_rel(sc->evdev_r, REL_Y, -*y);
4714 evdev_push_mouse_btn(sc->evdev_r, trackpoint_button);
4715 evdev_sync(sc->evdev_r);
4717 ms->button = touchpad_button | trackpoint_button;
4719 VLOG(3, (LOG_DEBUG, "elantech: "
4720 "unexpected trackpoint packet skipped\n"));
4723 case ELANTECH_PKT_NOP:
4730 for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
4731 if (PSM_FINGER_IS_SET(f[id]))
4732 VLOG(2, (LOG_DEBUG, "elantech: "
4733 "finger %d: down [%d, %d], %d, %d, %d\n", id + 1,
4734 f[id].x, f[id].y, f[id].p, f[id].w, f[id].flags));
4736 /* Touchpad button presses */
4737 if (sc->elanhw.isclickpad) {
4739 ((pb->ipacket[0] & 0x03) ? MOUSE_BUTTON1DOWN : 0);
4742 ((pb->ipacket[0] & 0x01) ? MOUSE_BUTTON1DOWN : 0) |
4743 ((pb->ipacket[0] & 0x02) ? MOUSE_BUTTON3DOWN : 0);
4746 #ifdef EVDEV_SUPPORT
4747 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
4748 for (id = 0; id < ELANTECH_MAX_FINGERS; id++) {
4749 if (PSM_FINGER_IS_SET(f[id])) {
4750 psm_push_mt_finger(sc, id, &f[id]);
4751 /* Convert touch width to surface units */
4752 evdev_push_abs(sc->evdev_a, ABS_MT_TOUCH_MAJOR,
4753 f[id].w * sc->elanhw.dptracex);
4755 if (sc->elanaction.mask & (1 << id) &&
4756 !(mask & (1 << id)))
4757 psm_release_mt_slot(sc->evdev_a, id);
4759 evdev_push_key(sc->evdev_a, BTN_TOUCH, nfingers > 0);
4760 evdev_push_nfingers(sc->evdev_a, nfingers);
4762 if (PSM_FINGER_IS_SET(f[0]))
4763 psm_push_st_finger(sc, &f[0]);
4765 evdev_push_abs(sc->evdev_a, ABS_PRESSURE, 0);
4766 evdev_push_mouse_btn(sc->evdev_a, touchpad_button);
4767 evdev_sync(sc->evdev_a);
4771 ms->button = touchpad_button | trackpoint_button;
4773 /* Palm detection doesn't terminate the current action. */
4774 palm = psmpalmdetect(sc, &f[0], nfingers);
4776 /* Send finger 1 position to gesture processor */
4777 if ((PSM_FINGER_IS_SET(f[0]) || PSM_FINGER_IS_SET(f[1]) ||
4778 nfingers == 0) && !palm)
4779 psmgestures(sc, &f[0], imin(nfingers, 3), ms);
4781 /* Send fingers positions to movement smoothers */
4782 for (id = 0; id < PSM_FINGERS; id++)
4783 if (PSM_FINGER_IS_SET(f[id]) || !(mask & (1 << id)))
4784 psmsmoother(sc, &f[id], id, ms, x, y);
4786 /* Store current finger positions in action context */
4787 for (id = 0; id < ELANTECH_MAX_FINGERS; id++) {
4788 if (PSM_FINGER_IS_SET(f[id]))
4789 sc->elanaction.fingers[id] = f[id];
4790 if ((sc->elanaction.mask & (1 << id)) && !(mask & (1 << id)))
4791 PSM_FINGER_RESET(sc->elanaction.fingers[id]);
4793 sc->elanaction.mask = mask;
4797 ms->button = ms->obutton;
4801 /* Use the extra buttons as a scrollwheel */
4802 if (ms->button & MOUSE_BUTTON4DOWN)
4804 else if (ms->button & MOUSE_BUTTON5DOWN)
4806 else if (ms->button & MOUSE_BUTTON6DOWN)
4808 else if (ms->button & MOUSE_BUTTON7DOWN)
4812 ms->button &= ~(MOUSE_BUTTON4DOWN | MOUSE_BUTTON5DOWN |
4813 MOUSE_BUTTON6DOWN | MOUSE_BUTTON7DOWN);
4819 proc_versapad(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
4820 int *x, int *y, int *z)
4822 static int butmap_versapad[8] = {
4828 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
4830 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN
4834 /* VersaPad PS/2 absolute mode message format
4836 * [packet1] 7 6 5 4 3 2 1 0(LSB)
4837 * ipacket[0]: 1 1 0 A 1 L T R
4838 * ipacket[1]: H7 H6 H5 H4 H3 H2 H1 H0
4839 * ipacket[2]: V7 V6 V5 V4 V3 V2 V1 V0
4840 * ipacket[3]: 1 1 1 A 1 L T R
4841 * ipacket[4]:V11 V10 V9 V8 H11 H10 H9 H8
4842 * ipacket[5]: 0 P6 P5 P4 P3 P2 P1 P0
4845 * R: right physical mouse button (1=on)
4846 * T: touch pad virtual button (1=tapping)
4847 * L: left physical mouse button (1=on)
4848 * A: position data is valid (1=valid)
4849 * H: horizontal data (12bit signed integer. H11 is sign bit.)
4850 * V: vertical data (12bit signed integer. V11 is sign bit.)
4853 * Tapping is mapped to MOUSE_BUTTON4.
4857 ms->button = butmap_versapad[c & MOUSE_PS2VERSA_BUTTONS];
4858 ms->button |= (c & MOUSE_PS2VERSA_TAP) ? MOUSE_BUTTON4DOWN : 0;
4859 if (c & MOUSE_PS2VERSA_IN_USE) {
4860 x0 = pb->ipacket[1] | (((pb->ipacket[4]) & 0x0f) << 8);
4861 y0 = pb->ipacket[2] | (((pb->ipacket[4]) & 0xf0) << 4);
4866 if (sc->flags & PSM_FLAGS_FINGERDOWN) {
4869 if (*x < 0) /* XXX */
4878 sc->flags |= PSM_FLAGS_FINGERDOWN;
4882 sc->flags &= ~PSM_FLAGS_FINGERDOWN;
4886 psmsoftintridle(void *arg)
4888 struct psm_softc *sc = arg;
4891 /* Invoke soft handler only when pqueue is empty. Otherwise it will be
4892 * invoked from psmintr soon with pqueue filled with real data */
4893 if (sc->pqueue_start == sc->pqueue_end &&
4894 sc->idlepacket.inputbytes > 0) {
4895 /* Grow circular queue backwards to avoid race with psmintr */
4896 if (--sc->pqueue_start < 0)
4897 sc->pqueue_start = PSM_PACKETQUEUE - 1;
4899 pb = &sc->pqueue[sc->pqueue_start];
4900 memcpy(pb, &sc->idlepacket, sizeof(packetbuf_t));
4902 "psmsoftintridle: %02x %02x %02x %02x %02x %02x\n",
4903 pb->ipacket[0], pb->ipacket[1], pb->ipacket[2],
4904 pb->ipacket[3], pb->ipacket[4], pb->ipacket[5]));
4911 psmsoftintr(void *arg)
4914 * the table to turn PS/2 mouse button bits (MOUSE_PS2_BUTTON?DOWN)
4915 * into `mousestatus' button bits (MOUSE_BUTTON?DOWN).
4917 static int butmap[8] = {
4921 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
4923 MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN,
4924 MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN,
4925 MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN
4927 struct psm_softc *sc = arg;
4930 int x, y, z, c, l, s;
4932 getmicrouptime(&sc->lastsoftintr);
4937 pb = &sc->pqueue[sc->pqueue_start];
4939 if (sc->mode.level == PSM_LEVEL_NATIVE)
4944 * A kludge for Kensington device!
4945 * The MSB of the horizontal count appears to be stored in
4948 if (sc->hw.model == MOUSE_MODEL_THINK)
4949 pb->ipacket[1] |= (c & MOUSE_PS2_XOVERFLOW) ? 0x80 : 0;
4951 /* ignore the overflow bits... */
4952 x = (c & MOUSE_PS2_XNEG) ?
4953 pb->ipacket[1] - 256 : pb->ipacket[1];
4954 y = (c & MOUSE_PS2_YNEG) ?
4955 pb->ipacket[2] - 256 : pb->ipacket[2];
4957 ms.obutton = sc->button; /* previous button state */
4958 ms.button = butmap[c & MOUSE_PS2_BUTTONS];
4959 /* `tapping' action */
4960 if (sc->config & PSM_CONFIG_FORCETAP)
4961 ms.button |= ((c & MOUSE_PS2_TAP)) ?
4962 0 : MOUSE_BUTTON4DOWN;
4963 timevalclear(&sc->idletimeout);
4964 sc->idlepacket.inputbytes = 0;
4966 switch (sc->hw.model) {
4968 case MOUSE_MODEL_EXPLORER:
4970 * b7 b6 b5 b4 b3 b2 b1 b0
4971 * byte 1: oy ox sy sx 1 M R L
4972 * byte 2: x x x x x x x x
4973 * byte 3: y y y y y y y y
4974 * byte 4: * * S2 S1 s d2 d1 d0
4976 * L, M, R, S1, S2: left, middle, right and side buttons
4977 * s: wheel data sign bit
4980 z = (pb->ipacket[3] & MOUSE_EXPLORER_ZNEG) ?
4981 (pb->ipacket[3] & 0x0f) - 16 :
4982 (pb->ipacket[3] & 0x0f);
4984 (pb->ipacket[3] & MOUSE_EXPLORER_BUTTON4DOWN) ?
4985 MOUSE_BUTTON4DOWN : 0;
4987 (pb->ipacket[3] & MOUSE_EXPLORER_BUTTON5DOWN) ?
4988 MOUSE_BUTTON5DOWN : 0;
4991 case MOUSE_MODEL_INTELLI:
4992 case MOUSE_MODEL_NET:
4993 /* wheel data is in the fourth byte */
4994 z = (char)pb->ipacket[3];
4996 * XXX some mice may send 7 when there is no Z movement? */
4997 if ((z >= 7) || (z <= -7))
4999 /* some compatible mice have additional buttons */
5000 ms.button |= (c & MOUSE_PS2INTELLI_BUTTON4DOWN) ?
5001 MOUSE_BUTTON4DOWN : 0;
5002 ms.button |= (c & MOUSE_PS2INTELLI_BUTTON5DOWN) ?
5003 MOUSE_BUTTON5DOWN : 0;
5006 case MOUSE_MODEL_MOUSEMANPLUS:
5007 proc_mmanplus(sc, pb, &ms, &x, &y, &z);
5010 case MOUSE_MODEL_GLIDEPOINT:
5011 /* `tapping' action */
5012 ms.button |= ((c & MOUSE_PS2_TAP)) ? 0 :
5016 case MOUSE_MODEL_NETSCROLL:
5018 * three additional bytes encode buttons and
5021 ms.button |= (pb->ipacket[3] & MOUSE_PS2_BUTTON3DOWN) ?
5022 MOUSE_BUTTON4DOWN : 0;
5023 ms.button |= (pb->ipacket[3] & MOUSE_PS2_BUTTON1DOWN) ?
5024 MOUSE_BUTTON5DOWN : 0;
5025 z = (pb->ipacket[3] & MOUSE_PS2_XNEG) ?
5026 pb->ipacket[4] - 256 : pb->ipacket[4];
5029 case MOUSE_MODEL_THINK:
5030 /* the fourth button state in the first byte */
5031 ms.button |= (c & MOUSE_PS2_TAP) ?
5032 MOUSE_BUTTON4DOWN : 0;
5035 case MOUSE_MODEL_VERSAPAD:
5036 proc_versapad(sc, pb, &ms, &x, &y, &z);
5037 c = ((x < 0) ? MOUSE_PS2_XNEG : 0) |
5038 ((y < 0) ? MOUSE_PS2_YNEG : 0);
5041 case MOUSE_MODEL_4D:
5043 * b7 b6 b5 b4 b3 b2 b1 b0
5044 * byte 1: s2 d2 s1 d1 1 M R L
5045 * byte 2: sx x x x x x x x
5046 * byte 3: sy y y y y y y y
5048 * s1: wheel 1 direction
5050 * s2: wheel 2 direction
5053 x = (pb->ipacket[1] & 0x80) ?
5054 pb->ipacket[1] - 256 : pb->ipacket[1];
5055 y = (pb->ipacket[2] & 0x80) ?
5056 pb->ipacket[2] - 256 : pb->ipacket[2];
5057 switch (c & MOUSE_4D_WHEELBITS) {
5064 case 0x40: /* XXX 2nd wheel turning right */
5067 case 0xc0: /* XXX 2nd wheel turning left */
5073 case MOUSE_MODEL_4DPLUS:
5074 if ((x < 16 - 256) && (y < 16 - 256)) {
5076 * b7 b6 b5 b4 b3 b2 b1 b0
5077 * byte 1: 0 0 1 1 1 M R L
5078 * byte 2: 0 0 0 0 1 0 0 0
5079 * byte 3: 0 0 0 0 S s d1 d0
5081 * L, M, R, S: left, middle, right,
5083 * s: wheel data sign bit
5087 if (pb->ipacket[2] & MOUSE_4DPLUS_BUTTON4DOWN)
5088 ms.button |= MOUSE_BUTTON4DOWN;
5089 z = (pb->ipacket[2] & MOUSE_4DPLUS_ZNEG) ?
5090 ((pb->ipacket[2] & 0x07) - 8) :
5091 (pb->ipacket[2] & 0x07) ;
5093 /* preserve previous button states */
5094 ms.button |= ms.obutton & MOUSE_EXTBUTTONS;
5098 case MOUSE_MODEL_SYNAPTICS:
5099 if (pb->inputbytes == MOUSE_PS2_PACKETSIZE)
5100 if (proc_synaptics_mux(sc, pb))
5103 if (proc_synaptics(sc, pb, &ms, &x, &y, &z) != 0) {
5104 VLOG(3, (LOG_DEBUG, "synaptics: "
5105 "packet rejected\n"));
5110 case MOUSE_MODEL_ELANTECH:
5111 if (proc_elantech(sc, pb, &ms, &x, &y, &z) != 0) {
5112 VLOG(3, (LOG_DEBUG, "elantech: "
5113 "packet rejected\n"));
5118 case MOUSE_MODEL_TRACKPOINT:
5119 case MOUSE_MODEL_GENERIC:
5124 #ifdef EVDEV_SUPPORT
5125 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE &&
5126 sc->hw.model != MOUSE_MODEL_ELANTECH &&
5127 sc->hw.model != MOUSE_MODEL_SYNAPTICS) {
5128 evdev_push_rel(sc->evdev_r, REL_X, x);
5129 evdev_push_rel(sc->evdev_r, REL_Y, -y);
5131 switch (sc->hw.model) {
5132 case MOUSE_MODEL_EXPLORER:
5133 case MOUSE_MODEL_INTELLI:
5134 case MOUSE_MODEL_NET:
5135 case MOUSE_MODEL_NETSCROLL:
5136 case MOUSE_MODEL_4DPLUS:
5137 evdev_push_rel(sc->evdev_r, REL_WHEEL, -z);
5139 case MOUSE_MODEL_MOUSEMANPLUS:
5140 case MOUSE_MODEL_4D:
5144 evdev_push_rel(sc->evdev_r, REL_WHEEL, -z);
5148 evdev_push_rel(sc->evdev_r, REL_HWHEEL, z / 2);
5154 evdev_push_mouse_btn(sc->evdev_r, ms.button);
5155 evdev_sync(sc->evdev_r);
5160 if (sc->mode.accelfactor >= 1) {
5162 x = x * x / sc->mode.accelfactor;
5165 if (c & MOUSE_PS2_XNEG)
5169 y = y * y / sc->mode.accelfactor;
5172 if (c & MOUSE_PS2_YNEG)
5177 /* Store last packet for reinjection if it has not been set already */
5178 if (timevalisset(&sc->idletimeout) && sc->idlepacket.inputbytes == 0)
5179 sc->idlepacket = *pb;
5184 ms.flags = ((x || y || z) ? MOUSE_POSCHANGED : 0) |
5185 (ms.obutton ^ ms.button);
5187 pb->inputbytes = tame_mouse(sc, pb, &ms, pb->ipacket);
5189 sc->status.flags |= ms.flags;
5190 sc->status.dx += ms.dx;
5191 sc->status.dy += ms.dy;
5192 sc->status.dz += ms.dz;
5193 sc->status.button = ms.button;
5194 sc->button = ms.button;
5197 sc->watchdog = FALSE;
5200 if (sc->queue.count + pb->inputbytes < sizeof(sc->queue.buf)) {
5201 l = imin(pb->inputbytes,
5202 sizeof(sc->queue.buf) - sc->queue.tail);
5203 bcopy(&pb->ipacket[0], &sc->queue.buf[sc->queue.tail], l);
5204 if (pb->inputbytes > l)
5205 bcopy(&pb->ipacket[l], &sc->queue.buf[0],
5206 pb->inputbytes - l);
5207 sc->queue.tail = (sc->queue.tail + pb->inputbytes) %
5208 sizeof(sc->queue.buf);
5209 sc->queue.count += pb->inputbytes;
5214 if (++sc->pqueue_start >= PSM_PACKETQUEUE)
5215 sc->pqueue_start = 0;
5216 } while (sc->pqueue_start != sc->pqueue_end);
5218 if (sc->state & PSM_ASLP) {
5219 sc->state &= ~PSM_ASLP;
5222 selwakeuppri(&sc->rsel, PZERO);
5223 if (sc->async != NULL) {
5224 pgsigio(&sc->async, SIGIO, 0);
5226 sc->state &= ~PSM_SOFTARMED;
5228 /* schedule injection of predefined packet after idletimeout
5229 * if no data packets have been received from psmintr */
5230 if (timevalisset(&sc->idletimeout)) {
5231 sc->state |= PSM_SOFTARMED;
5232 callout_reset(&sc->softcallout, tvtohz(&sc->idletimeout),
5233 psmsoftintridle, sc);
5234 VLOG(2, (LOG_DEBUG, "softintr: callout set: %d ticks\n",
5235 tvtohz(&sc->idletimeout)));
5241 psmpoll(struct cdev *dev, int events, struct thread *td)
5243 struct psm_softc *sc = dev->si_drv1;
5247 /* Return true if a mouse event available */
5249 if (events & (POLLIN | POLLRDNORM)) {
5250 if (sc->queue.count > 0)
5251 revents |= events & (POLLIN | POLLRDNORM);
5253 selrecord(td, &sc->rsel);
5260 /* vendor/model specific routines */
5262 static int mouse_id_proc1(KBDC kbdc, int res, int scale, int *status)
5264 if (set_mouse_resolution(kbdc, res) != res)
5266 if (set_mouse_scaling(kbdc, scale) &&
5267 set_mouse_scaling(kbdc, scale) &&
5268 set_mouse_scaling(kbdc, scale) &&
5269 (get_mouse_status(kbdc, status, 0, 3) >= 3))
5275 mouse_ext_command(KBDC kbdc, int command)
5279 c = (command >> 6) & 0x03;
5280 if (set_mouse_resolution(kbdc, c) != c)
5282 c = (command >> 4) & 0x03;
5283 if (set_mouse_resolution(kbdc, c) != c)
5285 c = (command >> 2) & 0x03;
5286 if (set_mouse_resolution(kbdc, c) != c)
5288 c = (command >> 0) & 0x03;
5289 if (set_mouse_resolution(kbdc, c) != c)
5295 /* Logitech MouseMan Cordless II */
5297 enable_lcordless(struct psm_softc *sc, enum probearg arg)
5299 KBDC kbdc = sc->kbdc;
5303 if (!mouse_id_proc1(kbdc, PSMD_RES_HIGH, 2, status))
5305 if (status[1] == PSMD_RES_HIGH)
5307 ch = (status[0] & 0x07) - 1; /* channel # */
5308 if ((ch <= 0) || (ch > 4))
5311 * status[1]: always one?
5312 * status[2]: battery status? (0-100)
5318 /* Genius NetScroll Mouse, MouseSystems SmartScroll Mouse */
5320 enable_groller(struct psm_softc *sc, enum probearg arg)
5322 KBDC kbdc = sc->kbdc;
5326 * The special sequence to enable the fourth button and the
5327 * roller. Immediately after this sequence check status bytes.
5328 * if the mouse is NetScroll, the second and the third bytes are
5333 * If the mouse is an ordinary PS/2 mouse, the status bytes should
5334 * look like the following.
5336 * byte 1 bit 7 always 0
5337 * bit 6 stream mode (0)
5338 * bit 5 disabled (0)
5339 * bit 4 1:1 scaling (0)
5341 * bit 0-2 button status
5342 * byte 2 resolution (PSMD_RES_HIGH)
5343 * byte 3 report rate (?)
5346 if (!mouse_id_proc1(kbdc, PSMD_RES_HIGH, 1, status))
5348 if ((status[1] != '3') || (status[2] != 'D'))
5350 /* FIXME: SmartScroll Mouse has 5 buttons! XXX */
5356 /* Genius NetMouse/NetMouse Pro, ASCII Mie Mouse, NetScroll Optical */
5358 enable_gmouse(struct psm_softc *sc, enum probearg arg)
5360 KBDC kbdc = sc->kbdc;
5364 * The special sequence to enable the middle, "rubber" button.
5365 * Immediately after this sequence check status bytes.
5366 * if the mouse is NetMouse, NetMouse Pro, or ASCII MIE Mouse,
5367 * the second and the third bytes are '3' and 'U'.
5368 * NOTE: NetMouse reports that it has three buttons although it has
5369 * two buttons and a rubber button. NetMouse Pro and MIE Mouse
5370 * say they have three buttons too and they do have a button on the
5373 if (!mouse_id_proc1(kbdc, PSMD_RES_HIGH, 1, status))
5375 if ((status[1] != '3') || (status[2] != 'U'))
5380 /* ALPS GlidePoint */
5382 enable_aglide(struct psm_softc *sc, enum probearg arg)
5384 KBDC kbdc = sc->kbdc;
5388 * The special sequence to obtain ALPS GlidePoint specific
5389 * information. Immediately after this sequence, status bytes will
5390 * contain something interesting.
5391 * NOTE: ALPS produces several models of GlidePoint. Some of those
5392 * do not respond to this sequence, thus, cannot be detected this way.
5394 if (set_mouse_sampling_rate(kbdc, 100) != 100)
5396 if (!mouse_id_proc1(kbdc, PSMD_RES_LOW, 2, status))
5398 if ((status[1] == PSMD_RES_LOW) || (status[2] == 100))
5403 /* Kensington ThinkingMouse/Trackball */
5405 enable_kmouse(struct psm_softc *sc, enum probearg arg)
5407 static u_char rate[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
5408 KBDC kbdc = sc->kbdc;
5414 id1 = get_aux_id(kbdc);
5415 if (set_mouse_sampling_rate(kbdc, 10) != 10)
5418 * The device is now in the native mode? It returns a different
5421 id2 = get_aux_id(kbdc);
5422 if ((id1 == id2) || (id2 != 2))
5425 if (set_mouse_resolution(kbdc, PSMD_RES_LOW) != PSMD_RES_LOW)
5428 /* at this point, resolution is LOW, sampling rate is 10/sec */
5429 if (get_mouse_status(kbdc, status, 0, 3) < 3)
5434 * The special sequence to enable the third and fourth buttons.
5435 * Otherwise they behave like the first and second buttons.
5437 for (i = 0; i < nitems(rate); ++i)
5438 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
5442 * At this point, the device is using default resolution and
5443 * sampling rate for the native mode.
5445 if (get_mouse_status(kbdc, status, 0, 3) < 3)
5447 if ((status[1] == PSMD_RES_LOW) || (status[2] == rate[i - 1]))
5450 /* the device appears be enabled by this sequence, diable it for now */
5451 disable_aux_dev(kbdc);
5452 empty_aux_buffer(kbdc, 5);
5457 /* Logitech MouseMan+/FirstMouse+, IBM ScrollPoint Mouse */
5459 enable_mmanplus(struct psm_softc *sc, enum probearg arg)
5461 KBDC kbdc = sc->kbdc;
5464 /* the special sequence to enable the fourth button and the roller. */
5466 * NOTE: for ScrollPoint to respond correctly, the SET_RESOLUTION
5467 * must be called exactly three times since the last RESET command
5468 * before this sequence. XXX
5470 if (!set_mouse_scaling(kbdc, 1))
5472 if (!mouse_ext_command(kbdc, 0x39) || !mouse_ext_command(kbdc, 0xdb))
5474 if (get_mouse_status(kbdc, data, 1, 3) < 3)
5478 * PS2++ protocol, packet type 0
5480 * b7 b6 b5 b4 b3 b2 b1 b0
5481 * byte 1: * 1 p3 p2 1 * * *
5482 * byte 2: 1 1 p1 p0 m1 m0 1 0
5483 * byte 3: m7 m6 m5 m4 m3 m2 m1 m0
5485 * p3-p0: packet type: 0
5486 * m7-m0: model ID: MouseMan+:0x50,
5488 * ScrollPoint:0x58...
5490 /* check constant bits */
5491 if ((data[0] & MOUSE_PS2PLUS_SYNCMASK) != MOUSE_PS2PLUS_SYNC)
5493 if ((data[1] & 0xc3) != 0xc2)
5495 /* check d3-d0 in byte 2 */
5496 if (!MOUSE_PS2PLUS_CHECKBITS(data))
5499 if (MOUSE_PS2PLUS_PACKET_TYPE(data) != 0)
5503 sc->hw.hwid &= 0x00ff;
5504 sc->hw.hwid |= data[2] << 8; /* save model ID */
5508 * MouseMan+ (or FirstMouse+) is now in its native mode, in which
5509 * the wheel and the fourth button events are encoded in the
5510 * special data packet. The mouse may be put in the IntelliMouse mode
5511 * if it is initialized by the IntelliMouse's method.
5516 /* MS IntelliMouse Explorer */
5518 enable_msexplorer(struct psm_softc *sc, enum probearg arg)
5520 KBDC kbdc = sc->kbdc;
5521 static u_char rate0[] = { 200, 100, 80, };
5522 static u_char rate1[] = { 200, 200, 80, };
5527 * This is needed for at least A4Tech X-7xx mice - they do not go
5528 * straight to Explorer mode, but need to be set to Intelli mode
5531 enable_msintelli(sc, arg);
5533 /* the special sequence to enable the extra buttons and the roller. */
5534 for (i = 0; i < nitems(rate1); ++i)
5535 if (set_mouse_sampling_rate(kbdc, rate1[i]) != rate1[i])
5537 /* the device will give the genuine ID only after the above sequence */
5538 id = get_aux_id(kbdc);
5539 if (id != PSM_EXPLORER_ID)
5543 sc->hw.buttons = 5; /* IntelliMouse Explorer XXX */
5548 * XXX: this is a kludge to fool some KVM switch products
5549 * which think they are clever enough to know the 4-byte IntelliMouse
5550 * protocol, and assume any other protocols use 3-byte packets.
5551 * They don't convey 4-byte data packets from the IntelliMouse Explorer
5552 * correctly to the host computer because of this!
5553 * The following sequence is actually IntelliMouse's "wake up"
5554 * sequence; it will make the KVM think the mouse is IntelliMouse
5555 * when it is in fact IntelliMouse Explorer.
5557 for (i = 0; i < nitems(rate0); ++i)
5558 if (set_mouse_sampling_rate(kbdc, rate0[i]) != rate0[i])
5567 * Logitech MouseMan+ and FirstMouse+ will also respond to this
5568 * probe routine and act like IntelliMouse.
5571 enable_msintelli(struct psm_softc *sc, enum probearg arg)
5573 KBDC kbdc = sc->kbdc;
5574 static u_char rate[] = { 200, 100, 80, };
5578 /* the special sequence to enable the third button and the roller. */
5579 for (i = 0; i < nitems(rate); ++i)
5580 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
5582 /* the device will give the genuine ID only after the above sequence */
5583 id = get_aux_id(kbdc);
5584 if (id != PSM_INTELLI_ID)
5597 * Newer wheel mice from A4 Tech may use the 4D+ protocol.
5600 enable_4dmouse(struct psm_softc *sc, enum probearg arg)
5602 static u_char rate[] = { 200, 100, 80, 60, 40, 20 };
5603 KBDC kbdc = sc->kbdc;
5607 for (i = 0; i < nitems(rate); ++i)
5608 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
5610 id = get_aux_id(kbdc);
5612 * WinEasy 4D, 4 Way Scroll 4D: 6
5613 * Cable-Free 4D: 8 (4DPLUS)
5614 * WinBest 4D+, 4 Way Scroll 4D+: 8 (4DPLUS)
5616 if (id != PSM_4DMOUSE_ID)
5620 sc->hw.buttons = 3; /* XXX some 4D mice have 4? */
5629 * Newer wheel mice from A4 Tech seem to use this protocol.
5630 * Older models are recognized as either 4D Mouse or IntelliMouse.
5633 enable_4dplus(struct psm_softc *sc, enum probearg arg)
5635 KBDC kbdc = sc->kbdc;
5639 * enable_4dmouse() already issued the following ID sequence...
5640 static u_char rate[] = { 200, 100, 80, 60, 40, 20 };
5643 for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i)
5644 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
5648 id = get_aux_id(kbdc);
5652 case PSM_4DPLUS_RFSW35_ID:
5659 sc->hw.buttons = (id == PSM_4DPLUS_ID) ? 4 : 3;
5666 /* Synaptics Touchpad */
5668 synaptics_sysctl(SYSCTL_HANDLER_ARGS)
5670 struct psm_softc *sc;
5673 if (oidp->oid_arg1 == NULL || oidp->oid_arg2 < 0 ||
5674 oidp->oid_arg2 > SYNAPTICS_SYSCTL_LAST)
5677 sc = oidp->oid_arg1;
5679 /* Read the current value. */
5680 arg = *(int *)((char *)sc + oidp->oid_arg2);
5681 error = sysctl_handle_int(oidp, &arg, 0, req);
5684 if (error || !req->newptr)
5688 * Check that the new value is in the concerned node's range
5691 switch (oidp->oid_arg2) {
5692 case SYNAPTICS_SYSCTL_MIN_PRESSURE:
5693 case SYNAPTICS_SYSCTL_MAX_PRESSURE:
5694 if (arg < 0 || arg > 255)
5697 case SYNAPTICS_SYSCTL_MAX_WIDTH:
5698 if (arg < 4 || arg > 15)
5701 case SYNAPTICS_SYSCTL_MARGIN_TOP:
5702 case SYNAPTICS_SYSCTL_MARGIN_BOTTOM:
5703 case SYNAPTICS_SYSCTL_NA_TOP:
5704 case SYNAPTICS_SYSCTL_NA_BOTTOM:
5705 if (arg < 0 || arg > sc->synhw.maximumYCoord)
5708 case SYNAPTICS_SYSCTL_SOFTBUTTON2_X:
5709 case SYNAPTICS_SYSCTL_SOFTBUTTON3_X:
5710 /* Softbuttons is clickpad only feature */
5711 if (!sc->synhw.capClickPad && arg != 0)
5714 case SYNAPTICS_SYSCTL_MARGIN_RIGHT:
5715 case SYNAPTICS_SYSCTL_MARGIN_LEFT:
5716 case SYNAPTICS_SYSCTL_NA_RIGHT:
5717 case SYNAPTICS_SYSCTL_NA_LEFT:
5718 if (arg < 0 || arg > sc->synhw.maximumXCoord)
5721 case SYNAPTICS_SYSCTL_WINDOW_MIN:
5722 case SYNAPTICS_SYSCTL_WINDOW_MAX:
5723 case SYNAPTICS_SYSCTL_TAP_MIN_QUEUE:
5724 if (arg < 1 || arg > SYNAPTICS_PACKETQUEUE)
5727 case SYNAPTICS_SYSCTL_MULTIPLICATOR:
5728 case SYNAPTICS_SYSCTL_WEIGHT_CURRENT:
5729 case SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS:
5730 case SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA:
5731 case SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED:
5732 case SYNAPTICS_SYSCTL_DIV_MIN:
5733 case SYNAPTICS_SYSCTL_DIV_MAX:
5734 case SYNAPTICS_SYSCTL_DIV_MAX_NA:
5735 case SYNAPTICS_SYSCTL_DIV_LEN:
5736 case SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN:
5737 case SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX:
5741 case SYNAPTICS_SYSCTL_TAP_MAX_DELTA:
5742 case SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT:
5743 case SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA:
5747 case SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA:
5748 if (arg < -sc->synhw.maximumXCoord ||
5749 arg > sc->synhw.maximumXCoord)
5752 case SYNAPTICS_SYSCTL_SOFTBUTTONS_Y:
5753 /* Softbuttons is clickpad only feature */
5754 if (!sc->synhw.capClickPad && arg != 0)
5757 case SYNAPTICS_SYSCTL_VSCROLL_VER_AREA:
5758 if (arg < -sc->synhw.maximumYCoord ||
5759 arg > sc->synhw.maximumYCoord)
5762 case SYNAPTICS_SYSCTL_TOUCHPAD_OFF:
5763 case SYNAPTICS_SYSCTL_THREE_FINGER_DRAG:
5764 case SYNAPTICS_SYSCTL_NATURAL_SCROLL:
5765 if (arg < 0 || arg > 1)
5773 *(int *)((char *)sc + oidp->oid_arg2) = arg;
5779 synaptics_sysctl_create_softbuttons_tree(struct psm_softc *sc)
5782 * Set predefined sizes for softbuttons.
5783 * Values are taken to match HP Pavilion dv6 clickpad drawings
5784 * with thin middle softbutton placed on separator
5787 /* hw.psm.synaptics.softbuttons_y */
5788 sc->syninfo.softbuttons_y = sc->synhw.topButtonPad ? -1700 : 1700;
5789 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5790 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5791 "softbuttons_y", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5792 sc, SYNAPTICS_SYSCTL_SOFTBUTTONS_Y,
5793 synaptics_sysctl, "I",
5794 "Vertical size of softbuttons area");
5796 /* hw.psm.synaptics.softbutton2_x */
5797 sc->syninfo.softbutton2_x = 3100;
5798 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5799 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5800 "softbutton2_x", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5801 sc, SYNAPTICS_SYSCTL_SOFTBUTTON2_X,
5802 synaptics_sysctl, "I",
5803 "Horisontal position of 2-nd softbutton left edge (0-disable)");
5805 /* hw.psm.synaptics.softbutton3_x */
5806 sc->syninfo.softbutton3_x = 3900;
5807 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5808 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5809 "softbutton3_x", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5810 sc, SYNAPTICS_SYSCTL_SOFTBUTTON3_X,
5811 synaptics_sysctl, "I",
5812 "Horisontal position of 3-rd softbutton left edge (0-disable)");
5816 synaptics_sysctl_create_tree(struct psm_softc *sc, const char *name,
5820 if (sc->syninfo.sysctl_tree != NULL)
5823 /* Attach extra synaptics sysctl nodes under hw.psm.synaptics */
5824 sysctl_ctx_init(&sc->syninfo.sysctl_ctx);
5825 sc->syninfo.sysctl_tree = SYSCTL_ADD_NODE(&sc->syninfo.sysctl_ctx,
5826 SYSCTL_STATIC_CHILDREN(_hw_psm), OID_AUTO, name, CTLFLAG_RD,
5829 /* hw.psm.synaptics.directional_scrolls. */
5830 sc->syninfo.directional_scrolls = 0;
5831 SYSCTL_ADD_INT(&sc->syninfo.sysctl_ctx,
5832 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5833 "directional_scrolls", CTLFLAG_RW|CTLFLAG_ANYBODY,
5834 &sc->syninfo.directional_scrolls, 0,
5835 "Enable hardware scrolling pad (if non-zero) or register it as "
5836 "extended buttons (if 0)");
5838 /* hw.psm.synaptics.max_x. */
5839 sc->syninfo.max_x = 6143;
5840 SYSCTL_ADD_INT(&sc->syninfo.sysctl_ctx,
5841 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5842 "max_x", CTLFLAG_RD|CTLFLAG_ANYBODY,
5843 &sc->syninfo.max_x, 0,
5844 "Horizontal reporting range");
5846 /* hw.psm.synaptics.max_y. */
5847 sc->syninfo.max_y = 6143;
5848 SYSCTL_ADD_INT(&sc->syninfo.sysctl_ctx,
5849 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5850 "max_y", CTLFLAG_RD|CTLFLAG_ANYBODY,
5851 &sc->syninfo.max_y, 0,
5852 "Vertical reporting range");
5855 * Turn off two finger scroll if we have a
5856 * physical area reserved for scrolling or when
5857 * there's no multi finger support.
5859 if (sc->synhw.verticalScroll || (sc->synhw.capMultiFinger == 0 &&
5860 sc->synhw.capAdvancedGestures == 0))
5861 sc->syninfo.two_finger_scroll = 0;
5863 sc->syninfo.two_finger_scroll = 1;
5864 /* hw.psm.synaptics.two_finger_scroll. */
5865 SYSCTL_ADD_INT(&sc->syninfo.sysctl_ctx,
5866 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5867 "two_finger_scroll", CTLFLAG_RW|CTLFLAG_ANYBODY,
5868 &sc->syninfo.two_finger_scroll, 0,
5869 "Enable two finger scrolling");
5871 /* hw.psm.synaptics.min_pressure. */
5872 sc->syninfo.min_pressure = 32;
5873 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5874 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5875 "min_pressure", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5876 sc, SYNAPTICS_SYSCTL_MIN_PRESSURE,
5877 synaptics_sysctl, "I",
5878 "Minimum pressure required to start an action");
5880 /* hw.psm.synaptics.max_pressure. */
5881 sc->syninfo.max_pressure = 220;
5882 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5883 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5884 "max_pressure", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5885 sc, SYNAPTICS_SYSCTL_MAX_PRESSURE,
5886 synaptics_sysctl, "I",
5887 "Maximum pressure to detect palm");
5889 /* hw.psm.synaptics.max_width. */
5890 sc->syninfo.max_width = 10;
5891 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5892 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5893 "max_width", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5894 sc, SYNAPTICS_SYSCTL_MAX_WIDTH,
5895 synaptics_sysctl, "I",
5896 "Maximum finger width to detect palm");
5898 /* hw.psm.synaptics.top_margin. */
5899 sc->syninfo.margin_top = 200;
5900 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5901 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5902 "margin_top", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5903 sc, SYNAPTICS_SYSCTL_MARGIN_TOP,
5904 synaptics_sysctl, "I",
5907 /* hw.psm.synaptics.right_margin. */
5908 sc->syninfo.margin_right = 200;
5909 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5910 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5911 "margin_right", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5912 sc, SYNAPTICS_SYSCTL_MARGIN_RIGHT,
5913 synaptics_sysctl, "I",
5916 /* hw.psm.synaptics.bottom_margin. */
5917 sc->syninfo.margin_bottom = 200;
5918 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5919 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5920 "margin_bottom", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5921 sc, SYNAPTICS_SYSCTL_MARGIN_BOTTOM,
5922 synaptics_sysctl, "I",
5925 /* hw.psm.synaptics.left_margin. */
5926 sc->syninfo.margin_left = 200;
5927 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5928 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5929 "margin_left", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5930 sc, SYNAPTICS_SYSCTL_MARGIN_LEFT,
5931 synaptics_sysctl, "I",
5934 /* hw.psm.synaptics.na_top. */
5935 sc->syninfo.na_top = 1783;
5936 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5937 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5938 "na_top", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5939 sc, SYNAPTICS_SYSCTL_NA_TOP,
5940 synaptics_sysctl, "I",
5941 "Top noisy area, where weight_previous_na is used instead "
5942 "of weight_previous");
5944 /* hw.psm.synaptics.na_right. */
5945 sc->syninfo.na_right = 563;
5946 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5947 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5948 "na_right", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5949 sc, SYNAPTICS_SYSCTL_NA_RIGHT,
5950 synaptics_sysctl, "I",
5951 "Right noisy area, where weight_previous_na is used instead "
5952 "of weight_previous");
5954 /* hw.psm.synaptics.na_bottom. */
5955 sc->syninfo.na_bottom = 1408;
5956 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5957 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5958 "na_bottom", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5959 sc, SYNAPTICS_SYSCTL_NA_BOTTOM,
5960 synaptics_sysctl, "I",
5961 "Bottom noisy area, where weight_previous_na is used instead "
5962 "of weight_previous");
5964 /* hw.psm.synaptics.na_left. */
5965 sc->syninfo.na_left = 1600;
5966 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5967 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5968 "na_left", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5969 sc, SYNAPTICS_SYSCTL_NA_LEFT,
5970 synaptics_sysctl, "I",
5971 "Left noisy area, where weight_previous_na is used instead "
5972 "of weight_previous");
5974 /* hw.psm.synaptics.window_min. */
5975 sc->syninfo.window_min = 4;
5976 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5977 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5978 "window_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5979 sc, SYNAPTICS_SYSCTL_WINDOW_MIN,
5980 synaptics_sysctl, "I",
5981 "Minimum window size to start an action");
5983 /* hw.psm.synaptics.window_max. */
5984 sc->syninfo.window_max = 10;
5985 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5986 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5987 "window_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5988 sc, SYNAPTICS_SYSCTL_WINDOW_MAX,
5989 synaptics_sysctl, "I",
5990 "Maximum window size");
5992 /* hw.psm.synaptics.multiplicator. */
5993 sc->syninfo.multiplicator = 10000;
5994 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5995 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5996 "multiplicator", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5997 sc, SYNAPTICS_SYSCTL_MULTIPLICATOR,
5998 synaptics_sysctl, "I",
5999 "Multiplicator to increase precision in averages and divisions");
6001 /* hw.psm.synaptics.weight_current. */
6002 sc->syninfo.weight_current = 3;
6003 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6004 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6005 "weight_current", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6006 sc, SYNAPTICS_SYSCTL_WEIGHT_CURRENT,
6007 synaptics_sysctl, "I",
6008 "Weight of the current movement in the new average");
6010 /* hw.psm.synaptics.weight_previous. */
6011 sc->syninfo.weight_previous = 6;
6012 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6013 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6014 "weight_previous", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6015 sc, SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS,
6016 synaptics_sysctl, "I",
6017 "Weight of the previous average");
6019 /* hw.psm.synaptics.weight_previous_na. */
6020 sc->syninfo.weight_previous_na = 20;
6021 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6022 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6023 "weight_previous_na", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6024 sc, SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA,
6025 synaptics_sysctl, "I",
6026 "Weight of the previous average (inside the noisy area)");
6028 /* hw.psm.synaptics.weight_len_squared. */
6029 sc->syninfo.weight_len_squared = 2000;
6030 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6031 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6032 "weight_len_squared", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6033 sc, SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED,
6034 synaptics_sysctl, "I",
6035 "Length (squared) of segments where weight_previous "
6036 "starts to decrease");
6038 /* hw.psm.synaptics.div_min. */
6039 sc->syninfo.div_min = 9;
6040 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6041 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6042 "div_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6043 sc, SYNAPTICS_SYSCTL_DIV_MIN,
6044 synaptics_sysctl, "I",
6045 "Divisor for fast movements");
6047 /* hw.psm.synaptics.div_max. */
6048 sc->syninfo.div_max = 17;
6049 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6050 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6051 "div_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6052 sc, SYNAPTICS_SYSCTL_DIV_MAX,
6053 synaptics_sysctl, "I",
6054 "Divisor for slow movements");
6056 /* hw.psm.synaptics.div_max_na. */
6057 sc->syninfo.div_max_na = 30;
6058 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6059 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6060 "div_max_na", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6061 sc, SYNAPTICS_SYSCTL_DIV_MAX_NA,
6062 synaptics_sysctl, "I",
6063 "Divisor with slow movements (inside the noisy area)");
6065 /* hw.psm.synaptics.div_len. */
6066 sc->syninfo.div_len = 100;
6067 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6068 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6069 "div_len", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6070 sc, SYNAPTICS_SYSCTL_DIV_LEN,
6071 synaptics_sysctl, "I",
6072 "Length of segments where div_max starts to decrease");
6074 /* hw.psm.synaptics.tap_max_delta. */
6075 sc->syninfo.tap_max_delta = 80;
6076 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6077 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6078 "tap_max_delta", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6079 sc, SYNAPTICS_SYSCTL_TAP_MAX_DELTA,
6080 synaptics_sysctl, "I",
6081 "Length of segments above which a tap is ignored");
6083 /* hw.psm.synaptics.tap_min_queue. */
6084 sc->syninfo.tap_min_queue = 2;
6085 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6086 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6087 "tap_min_queue", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6088 sc, SYNAPTICS_SYSCTL_TAP_MIN_QUEUE,
6089 synaptics_sysctl, "I",
6090 "Number of packets required to consider a tap");
6092 /* hw.psm.synaptics.taphold_timeout. */
6093 sc->gesture.in_taphold = 0;
6094 sc->syninfo.taphold_timeout = tap_timeout;
6095 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6096 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6097 "taphold_timeout", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6098 sc, SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT,
6099 synaptics_sysctl, "I",
6100 "Maximum elapsed time between two taps to consider a tap-hold "
6103 /* hw.psm.synaptics.vscroll_hor_area. */
6104 sc->syninfo.vscroll_hor_area = 0; /* 1300 */
6105 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6106 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6107 "vscroll_hor_area", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6108 sc, SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA,
6109 synaptics_sysctl, "I",
6110 "Area reserved for horizontal virtual scrolling");
6112 /* hw.psm.synaptics.vscroll_ver_area. */
6113 sc->syninfo.vscroll_ver_area = -400 - sc->syninfo.margin_right;
6114 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6115 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6116 "vscroll_ver_area", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6117 sc, SYNAPTICS_SYSCTL_VSCROLL_VER_AREA,
6118 synaptics_sysctl, "I",
6119 "Area reserved for vertical virtual scrolling");
6121 /* hw.psm.synaptics.vscroll_min_delta. */
6122 sc->syninfo.vscroll_min_delta = 50;
6123 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6124 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6125 "vscroll_min_delta", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6126 sc, SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA,
6127 synaptics_sysctl, "I",
6128 "Minimum movement to consider virtual scrolling");
6130 /* hw.psm.synaptics.vscroll_div_min. */
6131 sc->syninfo.vscroll_div_min = 100;
6132 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6133 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6134 "vscroll_div_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6135 sc, SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN,
6136 synaptics_sysctl, "I",
6137 "Divisor for fast scrolling");
6139 /* hw.psm.synaptics.vscroll_div_min. */
6140 sc->syninfo.vscroll_div_max = 150;
6141 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6142 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6143 "vscroll_div_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6144 sc, SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX,
6145 synaptics_sysctl, "I",
6146 "Divisor for slow scrolling");
6148 /* hw.psm.synaptics.touchpad_off. */
6149 sc->syninfo.touchpad_off = 0;
6150 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6151 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6152 "touchpad_off", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6153 sc, SYNAPTICS_SYSCTL_TOUCHPAD_OFF,
6154 synaptics_sysctl, "I",
6155 "Turn off touchpad");
6157 sc->syninfo.three_finger_drag = 0;
6158 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6159 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6160 "three_finger_drag", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6161 sc, SYNAPTICS_SYSCTL_THREE_FINGER_DRAG,
6162 synaptics_sysctl, "I",
6163 "Enable dragging with three fingers");
6165 /* hw.psm.synaptics.natural_scroll. */
6166 sc->syninfo.natural_scroll = 0;
6167 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6168 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6169 "natural_scroll", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6170 sc, SYNAPTICS_SYSCTL_NATURAL_SCROLL,
6171 synaptics_sysctl, "I",
6172 "Enable natural scrolling");
6174 sc->syninfo.softbuttons_y = 0;
6175 sc->syninfo.softbutton2_x = 0;
6176 sc->syninfo.softbutton3_x = 0;
6178 /* skip softbuttons sysctl on not clickpads */
6179 if (sc->synhw.capClickPad)
6180 synaptics_sysctl_create_softbuttons_tree(sc);
6184 synaptics_preferred_mode(struct psm_softc *sc) {
6187 /* Check if we are in relative mode */
6188 if (sc->hw.model != MOUSE_MODEL_SYNAPTICS) {
6189 if (tap_enabled == 0)
6191 * Disable tap & drag gestures. We use a Mode Byte
6192 * and set the DisGest bit (see §2.5 of Synaptics
6193 * TouchPad Interfacing Guide).
6198 * Enable tap & drag gestures. We use a Mode Byte
6199 * and clear the DisGest bit (see §2.5 of Synaptics
6200 * TouchPad Interfacing Guide).
6207 /* request wmode where available */
6208 if (sc->synhw.capExtended)
6215 synaptics_set_mode(struct psm_softc *sc, int mode_byte) {
6216 mouse_ext_command(sc->kbdc, mode_byte);
6218 /* "Commit" the Set Mode Byte command sent above. */
6219 set_mouse_sampling_rate(sc->kbdc, 20);
6222 * Enable advanced gestures mode if supported and we are not entering
6223 * passthrough or relative mode.
6225 if ((sc->synhw.capAdvancedGestures || sc->synhw.capReportsV) &&
6226 sc->hw.model == MOUSE_MODEL_SYNAPTICS && !(mode_byte & (1 << 5))) {
6227 mouse_ext_command(sc->kbdc, SYNAPTICS_READ_MODEL_ID);
6228 set_mouse_sampling_rate(sc->kbdc, 0xc8);
6233 * AUX MUX detection code should be placed at very beginning of probe sequence
6234 * at least before 4-byte protocol mouse probes e.g. MS IntelliMouse probe as
6235 * latter can trigger switching the MUX to incompatible state.
6238 enable_synaptics_mux(struct psm_softc *sc, enum probearg arg)
6240 KBDC kbdc = sc->kbdc;
6243 int active_ports_count = 0;
6244 int active_ports_mask = 0;
6246 version = enable_aux_mux(kbdc);
6250 for (port = 0; port < KBDC_AUX_MUX_NUM_PORTS; port++) {
6251 VLOG(3, (LOG_DEBUG, "aux_mux: ping port %d\n", port));
6252 set_active_aux_mux_port(kbdc, port);
6253 if (enable_aux_dev(kbdc) && disable_aux_dev(kbdc)) {
6254 active_ports_count++;
6255 active_ports_mask |= 1 << port;
6260 printf("Active Multiplexing PS/2 controller v%d.%d with %d "
6261 "active port(s)\n", version >> 4 & 0x0f, version & 0x0f,
6262 active_ports_count);
6264 /* psm has a special support for GenMouse + SynTouchpad combination */
6265 if (active_ports_count >= 2) {
6266 for (port = 0; port < KBDC_AUX_MUX_NUM_PORTS; port++) {
6267 if ((active_ports_mask & 1 << port) == 0)
6269 VLOG(3, (LOG_DEBUG, "aux_mux: probe port %d\n", port));
6270 set_active_aux_mux_port(kbdc, port);
6271 probe = enable_synaptics(sc, arg);
6280 /* IRQ handler does not support active multiplexing mode */
6281 disable_aux_mux(kbdc);
6287 enable_synaptics(struct psm_softc *sc, enum probearg arg)
6290 struct psmcpnp_softc *psmcpnp_sc;
6291 KBDC kbdc = sc->kbdc;
6292 synapticshw_t synhw;
6296 VLOG(3, (LOG_DEBUG, "synaptics: BEGIN init\n"));
6299 * Just to be on the safe side: this avoids troubles with
6300 * following mouse_ext_command() when the previous command
6301 * was PSMC_SET_RESOLUTION. Set Scaling has no effect on
6302 * Synaptics Touchpad behaviour.
6304 set_mouse_scaling(kbdc, 1);
6306 /* Identify the Touchpad version. */
6307 if (mouse_ext_command(kbdc, SYNAPTICS_READ_IDENTITY) == 0)
6309 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6311 if (status[1] != 0x47)
6314 bzero(&synhw, sizeof(synhw));
6315 synhw.infoMinor = status[0];
6316 synhw.infoMajor = status[2] & 0x0f;
6319 printf("Synaptics Touchpad v%d.%d\n", synhw.infoMajor,
6322 if (synhw.infoMajor < 4) {
6323 printf(" Unsupported (pre-v4) Touchpad detected\n");
6327 /* Get the Touchpad model information. */
6328 if (mouse_ext_command(kbdc, SYNAPTICS_READ_MODEL_ID) == 0)
6330 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6332 if ((status[1] & 0x01) != 0) {
6333 printf(" Failed to read model information\n");
6337 synhw.infoRot180 = (status[0] & 0x80) != 0;
6338 synhw.infoPortrait = (status[0] & 0x40) != 0;
6339 synhw.infoSensor = status[0] & 0x3f;
6340 synhw.infoHardware = (status[1] & 0xfe) >> 1;
6341 synhw.infoNewAbs = (status[2] & 0x80) != 0;
6342 synhw.capPen = (status[2] & 0x40) != 0;
6343 synhw.infoSimplC = (status[2] & 0x20) != 0;
6344 synhw.infoGeometry = status[2] & 0x0f;
6347 printf(" Model information:\n");
6348 printf(" infoRot180: %d\n", synhw.infoRot180);
6349 printf(" infoPortrait: %d\n", synhw.infoPortrait);
6350 printf(" infoSensor: %d\n", synhw.infoSensor);
6351 printf(" infoHardware: %d\n", synhw.infoHardware);
6352 printf(" infoNewAbs: %d\n", synhw.infoNewAbs);
6353 printf(" capPen: %d\n", synhw.capPen);
6354 printf(" infoSimplC: %d\n", synhw.infoSimplC);
6355 printf(" infoGeometry: %d\n", synhw.infoGeometry);
6358 /* Read the extended capability bits. */
6359 if (mouse_ext_command(kbdc, SYNAPTICS_READ_CAPABILITIES) == 0)
6361 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6363 if (!SYNAPTICS_VERSION_GE(synhw, 7, 5) && status[1] != 0x47) {
6364 printf(" Failed to read extended capability bits\n");
6368 psmcpnp = devclass_get_device(devclass_find(PSMCPNP_DRIVER_NAME),
6370 psmcpnp_sc = (psmcpnp != NULL) ? device_get_softc(psmcpnp) : NULL;
6372 /* Set the different capabilities when they exist. */
6374 synhw.capExtended = (status[0] & 0x80) != 0;
6375 if (synhw.capExtended) {
6376 synhw.nExtendedQueries = (status[0] & 0x70) >> 4;
6377 synhw.capMiddle = (status[0] & 0x04) != 0;
6378 synhw.capPassthrough = (status[2] & 0x80) != 0;
6379 synhw.capLowPower = (status[2] & 0x40) != 0;
6380 synhw.capMultiFingerReport =
6381 (status[2] & 0x20) != 0;
6382 synhw.capSleep = (status[2] & 0x10) != 0;
6383 synhw.capFourButtons = (status[2] & 0x08) != 0;
6384 synhw.capBallistics = (status[2] & 0x04) != 0;
6385 synhw.capMultiFinger = (status[2] & 0x02) != 0;
6386 synhw.capPalmDetect = (status[2] & 0x01) != 0;
6388 if (!set_mouse_scaling(kbdc, 1))
6390 if (mouse_ext_command(kbdc, SYNAPTICS_READ_RESOLUTIONS) == 0)
6392 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6395 if (status[0] != 0 && (status[1] & 0x80) && status[2] != 0) {
6396 synhw.infoXupmm = status[0];
6397 synhw.infoYupmm = status[2];
6401 printf(" Extended capabilities:\n");
6402 printf(" capExtended: %d\n", synhw.capExtended);
6403 printf(" capMiddle: %d\n", synhw.capMiddle);
6404 printf(" nExtendedQueries: %d\n",
6405 synhw.nExtendedQueries);
6406 printf(" capPassthrough: %d\n", synhw.capPassthrough);
6407 printf(" capLowPower: %d\n", synhw.capLowPower);
6408 printf(" capMultiFingerReport: %d\n",
6409 synhw.capMultiFingerReport);
6410 printf(" capSleep: %d\n", synhw.capSleep);
6411 printf(" capFourButtons: %d\n", synhw.capFourButtons);
6412 printf(" capBallistics: %d\n", synhw.capBallistics);
6413 printf(" capMultiFinger: %d\n", synhw.capMultiFinger);
6414 printf(" capPalmDetect: %d\n", synhw.capPalmDetect);
6415 printf(" infoXupmm: %d\n", synhw.infoXupmm);
6416 printf(" infoYupmm: %d\n", synhw.infoYupmm);
6420 * If nExtendedQueries is 1 or greater, then the TouchPad
6421 * supports this number of extended queries. We can load
6422 * more information about buttons using query 0x09.
6424 if (synhw.nExtendedQueries >= 1) {
6425 if (!set_mouse_scaling(kbdc, 1))
6427 if (mouse_ext_command(kbdc,
6428 SYNAPTICS_READ_EXTENDED) == 0)
6430 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6432 synhw.verticalScroll = (status[0] & 0x01) != 0;
6433 synhw.horizontalScroll = (status[0] & 0x02) != 0;
6434 synhw.verticalWheel = (status[0] & 0x08) != 0;
6435 synhw.nExtendedButtons = (status[1] & 0xf0) >> 4;
6436 synhw.capEWmode = (status[0] & 0x04) != 0;
6438 printf(" Extended model ID:\n");
6439 printf(" verticalScroll: %d\n",
6440 synhw.verticalScroll);
6441 printf(" horizontalScroll: %d\n",
6442 synhw.horizontalScroll);
6443 printf(" verticalWheel: %d\n",
6444 synhw.verticalWheel);
6445 printf(" nExtendedButtons: %d\n",
6446 synhw.nExtendedButtons);
6447 printf(" capEWmode: %d\n",
6451 * Add the number of extended buttons to the total
6452 * button support count, including the middle button
6453 * if capMiddle support bit is set.
6455 buttons = synhw.nExtendedButtons + synhw.capMiddle;
6458 * If the capFourButtons support bit is set,
6459 * add a fourth button to the total button count.
6461 buttons = synhw.capFourButtons ? 1 : 0;
6463 /* Read the continued capabilities bits. */
6464 if (synhw.nExtendedQueries >= 4) {
6465 if (!set_mouse_scaling(kbdc, 1))
6467 if (mouse_ext_command(kbdc,
6468 SYNAPTICS_READ_CAPABILITIES_CONT) == 0)
6470 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6473 synhw.capClickPad = (status[1] & 0x01) << 1;
6474 synhw.capClickPad |= (status[0] & 0x10) != 0;
6475 synhw.capDeluxeLEDs = (status[1] & 0x02) != 0;
6476 synhw.noAbsoluteFilter = (status[1] & 0x04) != 0;
6477 synhw.capReportsV = (status[1] & 0x08) != 0;
6478 synhw.capUniformClickPad = (status[1] & 0x10) != 0;
6479 synhw.capReportsMin = (status[1] & 0x20) != 0;
6480 synhw.capInterTouch = (status[1] & 0x40) != 0;
6481 synhw.capReportsMax = (status[0] & 0x02) != 0;
6482 synhw.capClearPad = (status[0] & 0x04) != 0;
6483 synhw.capAdvancedGestures = (status[0] & 0x08) != 0;
6484 synhw.capCoveredPad = (status[0] & 0x80) != 0;
6486 if (synhw.capReportsMax) {
6487 if (!set_mouse_scaling(kbdc, 1))
6489 if (mouse_ext_command(kbdc,
6490 SYNAPTICS_READ_MAX_COORDS) == 0)
6492 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6495 synhw.maximumXCoord = (status[0] << 5) |
6496 ((status[1] & 0x0f) << 1);
6497 synhw.maximumYCoord = (status[2] << 5) |
6498 ((status[1] & 0xf0) >> 3);
6501 * Typical bezel limits. Taken from 'Synaptics
6502 * PS/2 * TouchPad Interfacing Guide' p.3.2.3.
6504 synhw.maximumXCoord = 5472;
6505 synhw.maximumYCoord = 4448;
6508 if (synhw.capReportsMin) {
6509 if (!set_mouse_scaling(kbdc, 1))
6511 if (mouse_ext_command(kbdc,
6512 SYNAPTICS_READ_MIN_COORDS) == 0)
6514 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6517 synhw.minimumXCoord = (status[0] << 5) |
6518 ((status[1] & 0x0f) << 1);
6519 synhw.minimumYCoord = (status[2] << 5) |
6520 ((status[1] & 0xf0) >> 3);
6523 * Typical bezel limits. Taken from 'Synaptics
6524 * PS/2 * TouchPad Interfacing Guide' p.3.2.3.
6526 synhw.minimumXCoord = 1472;
6527 synhw.minimumYCoord = 1408;
6531 * ClickPad properties are not exported through PS/2
6532 * protocol. Detection is based on controller's PnP ID.
6534 if (synhw.capClickPad && psmcpnp_sc != NULL) {
6535 switch (psmcpnp_sc->type) {
6536 case PSMCPNP_FORCEPAD:
6539 case PSMCPNP_TOPBUTTONPAD:
6540 synhw.topButtonPad = 1;
6548 printf(" Continued capabilities:\n");
6549 printf(" capClickPad: %d\n",
6551 printf(" capDeluxeLEDs: %d\n",
6552 synhw.capDeluxeLEDs);
6553 printf(" noAbsoluteFilter: %d\n",
6554 synhw.noAbsoluteFilter);
6555 printf(" capReportsV: %d\n",
6557 printf(" capUniformClickPad: %d\n",
6558 synhw.capUniformClickPad);
6559 printf(" capReportsMin: %d\n",
6560 synhw.capReportsMin);
6561 printf(" capInterTouch: %d\n",
6562 synhw.capInterTouch);
6563 printf(" capReportsMax: %d\n",
6564 synhw.capReportsMax);
6565 printf(" capClearPad: %d\n",
6567 printf(" capAdvancedGestures: %d\n",
6568 synhw.capAdvancedGestures);
6569 printf(" capCoveredPad: %d\n",
6570 synhw.capCoveredPad);
6571 if (synhw.capReportsMax) {
6572 printf(" maximumXCoord: %d\n",
6573 synhw.maximumXCoord);
6574 printf(" maximumYCoord: %d\n",
6575 synhw.maximumYCoord);
6577 if (synhw.capReportsMin) {
6578 printf(" minimumXCoord: %d\n",
6579 synhw.minimumXCoord);
6580 printf(" minimumYCoord: %d\n",
6581 synhw.minimumYCoord);
6583 if (synhw.capClickPad) {
6584 printf(" Clickpad capabilities:\n");
6585 printf(" forcePad: %d\n",
6587 printf(" topButtonPad: %d\n",
6588 synhw.topButtonPad);
6591 buttons += synhw.capClickPad;
6596 if (synhw.capExtended)
6597 printf(" Additional Buttons: %d\n", buttons);
6599 printf(" No extended capabilities\n");
6603 * Add the default number of 3 buttons to the total
6604 * count of supported buttons reported above.
6609 * Read the mode byte.
6611 * XXX: Note the Synaptics documentation also defines the first
6612 * byte of the response to this query to be a constant 0x3b, this
6613 * does not appear to be true for Touchpads with guest devices.
6615 if (mouse_ext_command(kbdc, SYNAPTICS_READ_MODES) == 0)
6617 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6619 if (!SYNAPTICS_VERSION_GE(synhw, 7, 5) && status[1] != 0x47) {
6620 printf(" Failed to read mode byte\n");
6626 if (!synaptics_support)
6629 /* Set mouse type just now for synaptics_set_mode() */
6630 sc->hw.model = MOUSE_MODEL_SYNAPTICS;
6632 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
6634 if (trackpoint_support && synhw.capPassthrough) {
6635 enable_trackpoint(sc, arg);
6638 VLOG(3, (LOG_DEBUG, "synaptics: END init (%d buttons)\n", buttons));
6641 /* Create sysctl tree. */
6642 synaptics_sysctl_create_tree(sc, "synaptics",
6643 "Synaptics TouchPad");
6644 sc->hw.buttons = buttons;
6651 synaptics_passthrough_on(struct psm_softc *sc)
6653 VLOG(2, (LOG_NOTICE, "psm: setting pass-through mode.\n"));
6654 synaptics_set_mode(sc, synaptics_preferred_mode(sc) | (1 << 5));
6658 synaptics_passthrough_off(struct psm_softc *sc)
6660 VLOG(2, (LOG_NOTICE, "psm: turning pass-through mode off.\n"));
6661 set_mouse_scaling(sc->kbdc, 2);
6662 set_mouse_scaling(sc->kbdc, 1);
6663 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
6666 /* IBM/Lenovo TrackPoint */
6668 trackpoint_command(struct psm_softc *sc, int cmd, int loc, int val)
6670 const int seq[] = { 0xe2, cmd, loc, val };
6673 if (sc->synhw.capPassthrough)
6674 synaptics_passthrough_on(sc);
6676 for (i = 0; i < nitems(seq); i++) {
6677 if (sc->synhw.capPassthrough &&
6678 (seq[i] == 0xff || seq[i] == 0xe7))
6679 if (send_aux_command(sc->kbdc, 0xe7) != PSM_ACK) {
6680 synaptics_passthrough_off(sc);
6683 if (send_aux_command(sc->kbdc, seq[i]) != PSM_ACK) {
6684 if (sc->synhw.capPassthrough)
6685 synaptics_passthrough_off(sc);
6690 if (sc->synhw.capPassthrough)
6691 synaptics_passthrough_off(sc);
6696 #define PSM_TPINFO(x) offsetof(struct psm_softc, tpinfo.x)
6702 trackpoint_sysctl(SYSCTL_HANDLER_ARGS)
6704 static const int data[][3] = {
6705 { 0x00, 0x4a, PSM_TPINFO(sensitivity) },
6706 { 0x00, 0x4d, PSM_TPINFO(inertia) },
6707 { 0x00, 0x60, PSM_TPINFO(uplateau) },
6708 { 0x00, 0x57, PSM_TPINFO(reach) },
6709 { 0x00, 0x58, PSM_TPINFO(draghys) },
6710 { 0x00, 0x59, PSM_TPINFO(mindrag) },
6711 { 0x00, 0x5a, PSM_TPINFO(upthresh) },
6712 { 0x00, 0x5c, PSM_TPINFO(threshold) },
6713 { 0x00, 0x5d, PSM_TPINFO(jenks) },
6714 { 0x00, 0x5e, PSM_TPINFO(ztime) },
6715 { 0x01, 0x2c, PSM_TPINFO(pts) },
6716 { 0x08, 0x2d, PSM_TPINFO(skipback) }
6718 struct psm_softc *sc;
6719 int error, newval, *oldvalp;
6722 if (arg1 == NULL || arg2 < 0 || arg2 >= nitems(data))
6726 oldvalp = (int *)((intptr_t)sc + tp[TPINFO]);
6728 error = sysctl_handle_int(oidp, &newval, 0, req);
6731 if (newval == *oldvalp)
6733 if (newval < 0 || newval > (tp[TPMASK] == 0 ? 255 : 1))
6735 error = trackpoint_command(sc, tp[TPMASK] == 0 ? 0x81 : 0x47,
6736 tp[TPLOC], tp[TPMASK] == 0 ? newval : tp[TPMASK]);
6745 trackpoint_sysctl_create_tree(struct psm_softc *sc)
6748 if (sc->tpinfo.sysctl_tree != NULL)
6751 /* Attach extra trackpoint sysctl nodes under hw.psm.trackpoint */
6752 sysctl_ctx_init(&sc->tpinfo.sysctl_ctx);
6753 sc->tpinfo.sysctl_tree = SYSCTL_ADD_NODE(&sc->tpinfo.sysctl_ctx,
6754 SYSCTL_STATIC_CHILDREN(_hw_psm), OID_AUTO, "trackpoint", CTLFLAG_RD,
6755 0, "IBM/Lenovo TrackPoint");
6757 /* hw.psm.trackpoint.sensitivity */
6758 sc->tpinfo.sensitivity = 0x80;
6759 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6760 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6761 "sensitivity", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6762 sc, TRACKPOINT_SYSCTL_SENSITIVITY,
6763 trackpoint_sysctl, "I",
6766 /* hw.psm.trackpoint.negative_inertia */
6767 sc->tpinfo.inertia = 0x06;
6768 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6769 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6770 "negative_inertia", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6771 sc, TRACKPOINT_SYSCTL_NEGATIVE_INERTIA,
6772 trackpoint_sysctl, "I",
6773 "Negative inertia factor");
6775 /* hw.psm.trackpoint.upper_plateau */
6776 sc->tpinfo.uplateau = 0x61;
6777 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6778 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6779 "upper_plateau", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6780 sc, TRACKPOINT_SYSCTL_UPPER_PLATEAU,
6781 trackpoint_sysctl, "I",
6782 "Transfer function upper plateau speed");
6784 /* hw.psm.trackpoint.backup_range */
6785 sc->tpinfo.reach = 0x0a;
6786 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6787 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6788 "backup_range", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6789 sc, TRACKPOINT_SYSCTL_BACKUP_RANGE,
6790 trackpoint_sysctl, "I",
6793 /* hw.psm.trackpoint.drag_hysteresis */
6794 sc->tpinfo.draghys = 0xff;
6795 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6796 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6797 "drag_hysteresis", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6798 sc, TRACKPOINT_SYSCTL_DRAG_HYSTERESIS,
6799 trackpoint_sysctl, "I",
6802 /* hw.psm.trackpoint.minimum_drag */
6803 sc->tpinfo.mindrag = 0x14;
6804 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6805 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6806 "minimum_drag", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6807 sc, TRACKPOINT_SYSCTL_MINIMUM_DRAG,
6808 trackpoint_sysctl, "I",
6811 /* hw.psm.trackpoint.up_threshold */
6812 sc->tpinfo.upthresh = 0xff;
6813 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6814 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6815 "up_threshold", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6816 sc, TRACKPOINT_SYSCTL_UP_THRESHOLD,
6817 trackpoint_sysctl, "I",
6818 "Up threshold for release");
6820 /* hw.psm.trackpoint.threshold */
6821 sc->tpinfo.threshold = 0x08;
6822 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6823 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6824 "threshold", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6825 sc, TRACKPOINT_SYSCTL_THRESHOLD,
6826 trackpoint_sysctl, "I",
6829 /* hw.psm.trackpoint.jenks_curvature */
6830 sc->tpinfo.jenks = 0x87;
6831 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6832 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6833 "jenks_curvature", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6834 sc, TRACKPOINT_SYSCTL_JENKS_CURVATURE,
6835 trackpoint_sysctl, "I",
6838 /* hw.psm.trackpoint.z_time */
6839 sc->tpinfo.ztime = 0x26;
6840 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6841 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6842 "z_time", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6843 sc, TRACKPOINT_SYSCTL_Z_TIME,
6844 trackpoint_sysctl, "I",
6847 /* hw.psm.trackpoint.press_to_select */
6848 sc->tpinfo.pts = 0x00;
6849 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6850 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6851 "press_to_select", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6852 sc, TRACKPOINT_SYSCTL_PRESS_TO_SELECT,
6853 trackpoint_sysctl, "I",
6856 /* hw.psm.trackpoint.skip_backups */
6857 sc->tpinfo.skipback = 0x00;
6858 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6859 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6860 "skip_backups", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6861 sc, TRACKPOINT_SYSCTL_SKIP_BACKUPS,
6862 trackpoint_sysctl, "I",
6863 "Skip backups from drags");
6867 set_trackpoint_parameters(struct psm_softc *sc)
6869 trackpoint_command(sc, 0x81, 0x4a, sc->tpinfo.sensitivity);
6870 trackpoint_command(sc, 0x81, 0x60, sc->tpinfo.uplateau);
6871 trackpoint_command(sc, 0x81, 0x4d, sc->tpinfo.inertia);
6872 trackpoint_command(sc, 0x81, 0x57, sc->tpinfo.reach);
6873 trackpoint_command(sc, 0x81, 0x58, sc->tpinfo.draghys);
6874 trackpoint_command(sc, 0x81, 0x59, sc->tpinfo.mindrag);
6875 trackpoint_command(sc, 0x81, 0x5a, sc->tpinfo.upthresh);
6876 trackpoint_command(sc, 0x81, 0x5c, sc->tpinfo.threshold);
6877 trackpoint_command(sc, 0x81, 0x5d, sc->tpinfo.jenks);
6878 trackpoint_command(sc, 0x81, 0x5e, sc->tpinfo.ztime);
6879 if (sc->tpinfo.pts == 0x01)
6880 trackpoint_command(sc, 0x47, 0x2c, 0x01);
6881 if (sc->tpinfo.skipback == 0x01)
6882 trackpoint_command(sc, 0x47, 0x2d, 0x08);
6886 enable_trackpoint(struct psm_softc *sc, enum probearg arg)
6888 KBDC kbdc = sc->kbdc;
6892 * If called from enable_synaptics(), make sure that passthrough
6893 * mode is enabled so we can reach the trackpoint.
6894 * However, passthrough mode must be disabled before setting the
6895 * trackpoint parameters, as rackpoint_command() enables and disables
6896 * passthrough mode on its own.
6898 if (sc->synhw.capPassthrough)
6899 synaptics_passthrough_on(sc);
6901 if (send_aux_command(kbdc, 0xe1) != PSM_ACK ||
6902 read_aux_data(kbdc) != 0x01)
6904 id = read_aux_data(kbdc);
6909 if (!trackpoint_support)
6912 if (sc->synhw.capPassthrough)
6913 synaptics_passthrough_off(sc);
6916 trackpoint_sysctl_create_tree(sc);
6918 * Don't overwrite hwid and buttons when we are
6921 if (!sc->synhw.capPassthrough) {
6927 set_trackpoint_parameters(sc);
6932 if (sc->synhw.capPassthrough)
6933 synaptics_passthrough_off(sc);
6938 /* Interlink electronics VersaPad */
6940 enable_versapad(struct psm_softc *sc, enum probearg arg)
6942 KBDC kbdc = sc->kbdc;
6945 set_mouse_resolution(kbdc, PSMD_RES_MEDIUM_HIGH); /* set res. 2 */
6946 set_mouse_sampling_rate(kbdc, 100); /* set rate 100 */
6947 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
6948 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
6949 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
6950 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
6951 if (get_mouse_status(kbdc, data, 0, 3) < 3) /* get status */
6953 if (data[2] != 0xa || data[1] != 0 ) /* rate == 0xa && res. == 0 */
6955 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
6957 return (TRUE); /* PS/2 absolute mode */
6960 /* Elantech Touchpad */
6962 elantech_read_1(KBDC kbdc, int hwversion, int reg, int *val)
6964 int res, readcmd, retidx;
6967 readcmd = hwversion == 2 ? ELANTECH_REG_READ : ELANTECH_REG_RDWR;
6968 retidx = hwversion == 4 ? 1 : 0;
6970 res = send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6971 res |= send_aux_command(kbdc, readcmd) != PSM_ACK;
6972 res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6973 res |= send_aux_command(kbdc, reg) != PSM_ACK;
6974 res |= get_mouse_status(kbdc, resp, 0, 3) != 3;
6977 *val = resp[retidx];
6983 elantech_write_1(KBDC kbdc, int hwversion, int reg, int val)
6987 writecmd = hwversion == 2 ? ELANTECH_REG_WRITE : ELANTECH_REG_RDWR;
6989 res = send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6990 res |= send_aux_command(kbdc, writecmd) != PSM_ACK;
6991 res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6992 res |= send_aux_command(kbdc, reg) != PSM_ACK;
6993 if (hwversion == 4) {
6994 res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6995 res |= send_aux_command(kbdc, writecmd) != PSM_ACK;
6997 res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6998 res |= send_aux_command(kbdc, val) != PSM_ACK;
6999 res |= set_mouse_scaling(kbdc, 1) == 0;
7005 elantech_cmd(KBDC kbdc, int hwversion, int cmd, int *resp)
7009 if (hwversion == 2) {
7010 res = set_mouse_scaling(kbdc, 1) == 0;
7011 res |= mouse_ext_command(kbdc, cmd) == 0;
7013 res = send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
7014 res |= send_aux_command(kbdc, cmd) != PSM_ACK;
7016 res |= get_mouse_status(kbdc, resp, 0, 3) != 3;
7022 elantech_init(KBDC kbdc, elantechhw_t *elanhw)
7024 int i, val, res, hwversion, reg10;
7026 /* set absolute mode */
7027 hwversion = elanhw->hwversion;
7029 switch (hwversion) {
7031 reg10 = elanhw->fwversion == 0x020030 ? 0x54 : 0xc4;
7032 res = elantech_write_1(kbdc, hwversion, 0x10, reg10);
7035 res = elantech_write_1(kbdc, hwversion, 0x11, 0x8A);
7039 res = elantech_write_1(kbdc, hwversion, 0x10, reg10);
7042 res = elantech_write_1(kbdc, hwversion, 0x07, 0x01);
7048 /* Read back reg 0x10 to ensure hardware is ready. */
7049 if (res == 0 && reg10 >= 0) {
7050 for (i = 0; i < 5; i++) {
7051 if (elantech_read_1(kbdc, hwversion, 0x10, &val) == 0)
7060 printf("couldn't set absolute mode\n");
7066 elantech_init_synaptics(struct psm_softc *sc)
7069 /* Set capabilites required by movement smother */
7070 sc->synhw.infoMajor = sc->elanhw.hwversion;
7071 sc->synhw.infoMinor = sc->elanhw.fwversion;
7072 sc->synhw.infoXupmm = sc->elanhw.dpmmx;
7073 sc->synhw.infoYupmm = sc->elanhw.dpmmy;
7074 sc->synhw.verticalScroll = 0;
7075 sc->synhw.nExtendedQueries = 4;
7076 sc->synhw.capExtended = 1;
7077 sc->synhw.capPassthrough = sc->elanhw.hastrackpoint;
7078 sc->synhw.capClickPad = sc->elanhw.isclickpad;
7079 sc->synhw.capMultiFinger = 1;
7080 if (sc->elanhw.issemimt)
7081 sc->synhw.capAdvancedGestures = 1;
7083 sc->synhw.capReportsV = 1;
7084 sc->synhw.capPalmDetect = 1;
7085 sc->synhw.capPen = 0;
7086 sc->synhw.capReportsMax = 1;
7087 sc->synhw.maximumXCoord = sc->elanhw.sizex;
7088 sc->synhw.maximumYCoord = sc->elanhw.sizey;
7089 sc->synhw.capReportsMin = 1;
7090 sc->synhw.minimumXCoord = 0;
7091 sc->synhw.minimumYCoord = 0;
7093 if (sc->syninfo.sysctl_tree == NULL) {
7094 synaptics_sysctl_create_tree(sc, "elantech",
7095 "Elantech Touchpad");
7098 * Adjust synaptic smoother tunables
7099 * 1. Disable finger detection pressure threshold. Unlike
7100 * synaptics we assume the finger is acting when packet with
7101 * its X&Y arrives not when pressure exceedes some threshold
7102 * 2. Disable unrelated features like margins and noisy areas
7103 * 3. Disable virtual scroll areas as 2nd finger is preferable
7104 * 4. For clickpads set bottom quarter as 42% - 16% - 42% sized
7106 * 5. Scale down divisors and movement lengths by a factor of 3
7107 * where 3 is Synaptics to Elantech (~2200/800) dpi ratio
7110 /* Set reporting range to be equal touchpad size */
7111 sc->syninfo.max_x = sc->elanhw.sizex;
7112 sc->syninfo.max_y = sc->elanhw.sizey;
7114 /* Disable finger detection pressure threshold */
7115 sc->syninfo.min_pressure = 1;
7117 /* Adjust palm width to nearly match synaptics w=10 */
7118 sc->syninfo.max_width = 7;
7120 /* Elans often report double & triple taps as single event */
7121 sc->syninfo.tap_min_queue = 1;
7123 /* Use full area of touchpad */
7124 sc->syninfo.margin_top = 0;
7125 sc->syninfo.margin_right = 0;
7126 sc->syninfo.margin_bottom = 0;
7127 sc->syninfo.margin_left = 0;
7129 /* Disable noisy area */
7130 sc->syninfo.na_top = 0;
7131 sc->syninfo.na_right = 0;
7132 sc->syninfo.na_bottom = 0;
7133 sc->syninfo.na_left = 0;
7135 /* Tune divisors and movement lengths */
7136 sc->syninfo.weight_len_squared = 200;
7137 sc->syninfo.div_min = 3;
7138 sc->syninfo.div_max = 6;
7139 sc->syninfo.div_max_na = 10;
7140 sc->syninfo.div_len = 30;
7141 sc->syninfo.tap_max_delta = 25;
7143 /* Disable virtual scrolling areas and tune its divisors */
7144 sc->syninfo.vscroll_hor_area = 0;
7145 sc->syninfo.vscroll_ver_area = 0;
7146 sc->syninfo.vscroll_min_delta = 15;
7147 sc->syninfo.vscroll_div_min = 30;
7148 sc->syninfo.vscroll_div_max = 50;
7150 /* Set bottom quarter as 42% - 16% - 42% sized softbuttons */
7151 if (sc->elanhw.isclickpad) {
7152 sc->syninfo.softbuttons_y = sc->elanhw.sizey / 4;
7153 sc->syninfo.softbutton2_x = sc->elanhw.sizex * 11 / 25;
7154 sc->syninfo.softbutton3_x = sc->elanhw.sizex * 14 / 25;
7162 enable_elantech(struct psm_softc *sc, enum probearg arg)
7164 static const int ic2hw[] =
7165 /*IC: 0 1 2 3 4 5 6 7 8 9 a b c d e f */
7166 { 0, 0, 2, 0, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 };
7167 static const int fw_sizes[][3] = {
7168 /* FW.vers MaxX MaxY */
7169 { 0x020030, 1152, 768 },
7170 { 0x020800, 1152, 768 },
7171 { 0x020b00, 1152, 768 },
7172 { 0x040215, 900, 500 },
7173 { 0x040216, 819, 405 },
7174 { 0x040219, 900, 500 },
7176 elantechhw_t elanhw;
7177 int icversion, hwversion, xtr, i, id, resp[3], dpix, dpiy;
7178 KBDC kbdc = sc->kbdc;
7180 VLOG(3, (LOG_DEBUG, "elantech: BEGIN init\n"));
7182 set_mouse_scaling(kbdc, 1);
7183 set_mouse_scaling(kbdc, 1);
7184 set_mouse_scaling(kbdc, 1);
7185 if (get_mouse_status(kbdc, resp, 0, 3) != 3)
7188 if (!ELANTECH_MAGIC(resp))
7191 /* Identify the Touchpad version. */
7192 if (elantech_cmd(kbdc, 2, ELANTECH_FW_VERSION, resp))
7195 bzero(&elanhw, sizeof(elanhw));
7197 elanhw.fwversion = (resp[0] << 16) | (resp[1] << 8) | resp[2];
7198 icversion = resp[0] & 0x0f;
7199 hwversion = ic2hw[icversion];
7202 printf("Elantech touchpad hardware v.%d firmware v.0x%06x\n",
7203 hwversion, elanhw.fwversion);
7205 if (ELANTECH_HW_IS_V1(elanhw.fwversion)) {
7206 printf (" Unsupported touchpad hardware (v1)\n");
7209 if (hwversion == 0) {
7210 printf (" Unknown touchpad hardware (firmware v.0x%06x)\n",
7215 /* Get the Touchpad model information. */
7216 elanhw.hwversion = hwversion;
7217 elanhw.issemimt = hwversion == 2;
7218 elanhw.isclickpad = (resp[1] & 0x10) != 0;
7219 elanhw.hascrc = (resp[1] & 0x40) != 0;
7220 elanhw.haspressure = elanhw.fwversion >= 0x020800;
7222 /* Read the capability bits. */
7223 if (elantech_cmd(kbdc, hwversion, ELANTECH_CAPABILITIES, resp) != 0) {
7224 printf(" Failed to read capability bits\n");
7228 elanhw.ntracesx = imax(resp[1], 3);
7229 elanhw.ntracesy = imax(resp[2], 3);
7230 elanhw.hastrackpoint = (resp[0] & 0x80) != 0;
7232 /* Get the touchpad resolution */
7233 switch (hwversion) {
7235 if (elantech_cmd(kbdc, hwversion, ELANTECH_RESOLUTION, resp)
7237 dpix = (resp[1] & 0x0f) * 10 + 790;
7238 dpiy = ((resp[1] & 0xf0) >> 4) * 10 + 790;
7239 elanhw.dpmmx = (dpix * 10 + 5) / 254;
7240 elanhw.dpmmy = (dpiy * 10 + 5) / 254;
7246 elanhw.dpmmx = elanhw.dpmmy = 32; /* 800 dpi */
7250 if (!elantech_support)
7253 if (elantech_init(kbdc, &elanhw)) {
7254 printf("couldn't initialize elantech touchpad\n");
7259 * Get the touchpad reporting range.
7260 * On HW v.3 touchpads it should be done after switching hardware
7261 * to real resolution mode (by setting bit 3 of reg10)
7263 elanhw.dptracex = elanhw.dptracey = 64;
7264 for (i = 0; i < nitems(fw_sizes); i++) {
7265 if (elanhw.fwversion == fw_sizes[i][0]) {
7266 elanhw.sizex = fw_sizes[i][1];
7267 elanhw.sizey = fw_sizes[i][2];
7271 if (elantech_cmd(kbdc, hwversion, ELANTECH_FW_ID, resp) != 0) {
7272 printf(" Failed to read touchpad size\n");
7273 elanhw.sizex = 10000; /* Arbitrary high values to */
7274 elanhw.sizey = 10000; /* prevent clipping in smoother */
7275 } else if (hwversion == 2) {
7276 if ((elanhw.fwversion >> 16) == 0x14 && (resp[1] & 0x10) &&
7277 !elantech_cmd(kbdc, hwversion, ELANTECH_SAMPLE, resp)) {
7278 elanhw.dptracex = resp[1] / 2;
7279 elanhw.dptracey = resp[2] / 2;
7281 xtr = ((elanhw.fwversion >> 8) == 0x0208) ? 1 : 2;
7282 elanhw.sizex = (elanhw.ntracesx - xtr) * elanhw.dptracex;
7283 elanhw.sizey = (elanhw.ntracesy - xtr) * elanhw.dptracey;
7285 elanhw.sizex = (resp[0] & 0x0f) << 8 | resp[1];
7286 elanhw.sizey = (resp[0] & 0xf0) << 4 | resp[2];
7287 xtr = (elanhw.sizex % (elanhw.ntracesx - 2) == 0) ? 2 : 1;
7288 elanhw.dptracex = elanhw.sizex / (elanhw.ntracesx - xtr);
7289 elanhw.dptracey = elanhw.sizey / (elanhw.ntracesy - xtr);
7293 printf(" Model information:\n");
7294 printf(" MaxX: %d\n", elanhw.sizex);
7295 printf(" MaxY: %d\n", elanhw.sizey);
7296 printf(" DpmmX: %d\n", elanhw.dpmmx);
7297 printf(" DpmmY: %d\n", elanhw.dpmmy);
7298 printf(" TracesX: %d\n", elanhw.ntracesx);
7299 printf(" TracesY: %d\n", elanhw.ntracesy);
7300 printf(" DptraceX: %d\n", elanhw.dptracex);
7301 printf(" DptraceY: %d\n", elanhw.dptracey);
7302 printf(" SemiMT: %d\n", elanhw.issemimt);
7303 printf(" Clickpad: %d\n", elanhw.isclickpad);
7304 printf(" Trackpoint: %d\n", elanhw.hastrackpoint);
7305 printf(" CRC: %d\n", elanhw.hascrc);
7306 printf(" Pressure: %d\n", elanhw.haspressure);
7309 VLOG(3, (LOG_DEBUG, "elantech: END init\n"));
7312 sc->elanhw = elanhw;
7315 /* Initialize synaptics movement smoother */
7316 elantech_init_synaptics(sc);
7318 for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
7319 PSM_FINGER_RESET(sc->elanaction.fingers[id]);
7326 * Return true if 'now' is earlier than (start + (secs.usecs)).
7327 * Now may be NULL and the function will fetch the current time from
7328 * getmicrouptime(), or a cached 'now' can be passed in.
7329 * All values should be numbers derived from getmicrouptime().
7332 timeelapsed(start, secs, usecs, now)
7333 const struct timeval *start, *now;
7336 struct timeval snow, tv;
7338 /* if there is no 'now' passed in, the get it as a convience. */
7340 getmicrouptime(&snow);
7346 timevaladd(&tv, start);
7347 return (timevalcmp(&tv, now, <));
7351 psmresume(device_t dev)
7353 struct psm_softc *sc = device_get_softc(dev);
7354 int unit = device_get_unit(dev);
7357 VLOG(2, (LOG_NOTICE, "psm%d: system resume hook called.\n", unit));
7360 (PSM_CONFIG_HOOKRESUME | PSM_CONFIG_INITAFTERSUSPEND)) == 0)
7363 err = reinitialize(sc, sc->config & PSM_CONFIG_INITAFTERSUSPEND);
7365 if ((sc->state & PSM_ASLP) && !(sc->state & PSM_VALID)) {
7367 * Release the blocked process; it must be notified that
7368 * the device cannot be accessed anymore.
7370 sc->state &= ~PSM_ASLP;
7374 VLOG(2, (LOG_DEBUG, "psm%d: system resume hook exiting.\n", unit));
7379 DRIVER_MODULE(psm, atkbdc, psm_driver, psm_devclass, 0, 0);
7380 #ifdef EVDEV_SUPPORT
7381 MODULE_DEPEND(psm, evdev, 1, 1, 1);
7387 * This sucks up assignments from PNPBIOS and ACPI.
7391 * When the PS/2 mouse device is reported by ACPI or PnP BIOS, it may
7392 * appear BEFORE the AT keyboard controller. As the PS/2 mouse device
7393 * can be probed and attached only after the AT keyboard controller is
7394 * attached, we shall quietly reserve the IRQ resource for later use.
7395 * If the PS/2 mouse device is reported to us AFTER the keyboard controller,
7396 * copy the IRQ resource to the PS/2 mouse device instance hanging
7397 * under the keyboard controller, then probe and attach it.
7400 static devclass_t psmcpnp_devclass;
7402 static device_probe_t psmcpnp_probe;
7403 static device_attach_t psmcpnp_attach;
7405 static device_method_t psmcpnp_methods[] = {
7406 DEVMETHOD(device_probe, psmcpnp_probe),
7407 DEVMETHOD(device_attach, psmcpnp_attach),
7412 static driver_t psmcpnp_driver = {
7413 PSMCPNP_DRIVER_NAME,
7415 sizeof(struct psmcpnp_softc),
7418 static struct isa_pnp_id psmcpnp_ids[] = {
7419 { 0x030fd041, "PS/2 mouse port" }, /* PNP0F03 */
7420 { 0x0e0fd041, "PS/2 mouse port" }, /* PNP0F0E */
7421 { 0x120fd041, "PS/2 mouse port" }, /* PNP0F12 */
7422 { 0x130fd041, "PS/2 mouse port" }, /* PNP0F13 */
7423 { 0x1303d041, "PS/2 port" }, /* PNP0313, XXX */
7424 { 0x02002e4f, "Dell PS/2 mouse port" }, /* Lat. X200, Dell */
7425 { 0x0002a906, "ALPS Glide Point" }, /* ALPS Glide Point */
7426 { 0x80374d24, "IBM PS/2 mouse port" }, /* IBM3780, ThinkPad */
7427 { 0x81374d24, "IBM PS/2 mouse port" }, /* IBM3781, ThinkPad */
7428 { 0x0190d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9001, Vaio */
7429 { 0x0290d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9002, Vaio */
7430 { 0x0390d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9003, Vaio */
7431 { 0x0490d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9004, Vaio */
7435 /* _HID list for quirk detection. Any device below has _CID from psmcpnp_ids */
7436 static struct isa_pnp_id topbtpad_ids[] = {
7437 { 0x1700ae30, "Lenovo PS/2 clickpad port" }, /* LEN0017, ThinkPad */
7438 { 0x1800ae30, "Lenovo PS/2 clickpad port" }, /* LEN0018, ThinkPad */
7439 { 0x1900ae30, "Lenovo PS/2 clickpad port" }, /* LEN0019, ThinkPad */
7440 { 0x2300ae30, "Lenovo PS/2 clickpad port" }, /* LEN0023, ThinkPad */
7441 { 0x2a00ae30, "Lenovo PS/2 clickpad port" }, /* LEN002a, ThinkPad */
7442 { 0x2b00ae30, "Lenovo PS/2 clickpad port" }, /* LEN002b, ThinkPad */
7443 { 0x2c00ae30, "Lenovo PS/2 clickpad port" }, /* LEN002c, ThinkPad */
7444 { 0x2d00ae30, "Lenovo PS/2 clickpad port" }, /* LEN002d, ThinkPad */
7445 { 0x2e00ae30, "Lenovo PS/2 clickpad port" }, /* LEN002e, ThinkPad */
7446 { 0x3300ae30, "Lenovo PS/2 clickpad port" }, /* LEN0033, ThinkPad */
7447 { 0x3400ae30, "Lenovo PS/2 clickpad port" }, /* LEN0034, ThinkPad */
7448 { 0x3500ae30, "Lenovo PS/2 clickpad port" }, /* LEN0035, ThinkPad */
7449 { 0x3600ae30, "Lenovo PS/2 clickpad port" }, /* LEN0036, ThinkPad */
7450 { 0x3700ae30, "Lenovo PS/2 clickpad port" }, /* LEN0037, ThinkPad */
7451 { 0x3800ae30, "Lenovo PS/2 clickpad port" }, /* LEN0038, ThinkPad */
7452 { 0x3900ae30, "Lenovo PS/2 clickpad port" }, /* LEN0039, ThinkPad */
7453 { 0x4100ae30, "Lenovo PS/2 clickpad port" }, /* LEN0041, ThinkPad */
7454 { 0x4200ae30, "Lenovo PS/2 clickpad port" }, /* LEN0042, ThinkPad */
7455 { 0x4500ae30, "Lenovo PS/2 clickpad port" }, /* LEN0045, ThinkPad */
7456 { 0x4700ae30, "Lenovo PS/2 clickpad port" }, /* LEN0047, ThinkPad */
7457 { 0x4900ae30, "Lenovo PS/2 clickpad port" }, /* LEN0049, ThinkPad */
7458 { 0x0020ae30, "Lenovo PS/2 clickpad port" }, /* LEN2000, ThinkPad */
7459 { 0x0120ae30, "Lenovo PS/2 clickpad port" }, /* LEN2001, ThinkPad */
7460 { 0x0220ae30, "Lenovo PS/2 clickpad port" }, /* LEN2002, ThinkPad */
7461 { 0x0320ae30, "Lenovo PS/2 clickpad port" }, /* LEN2003, ThinkPad */
7462 { 0x0420ae30, "Lenovo PS/2 clickpad port" }, /* LEN2004, ThinkPad */
7463 { 0x0520ae30, "Lenovo PS/2 clickpad port" }, /* LEN2005, ThinkPad */
7464 { 0x0620ae30, "Lenovo PS/2 clickpad port" }, /* LEN2006, ThinkPad */
7465 { 0x0720ae30, "Lenovo PS/2 clickpad port" }, /* LEN2007, ThinkPad */
7466 { 0x0820ae30, "Lenovo PS/2 clickpad port" }, /* LEN2008, ThinkPad */
7467 { 0x0920ae30, "Lenovo PS/2 clickpad port" }, /* LEN2009, ThinkPad */
7468 { 0x0a20ae30, "Lenovo PS/2 clickpad port" }, /* LEN200a, ThinkPad */
7469 { 0x0b20ae30, "Lenovo PS/2 clickpad port" }, /* LEN200b, ThinkPad */
7473 /* _HID list for quirk detection. Any device below has _CID from psmcpnp_ids */
7474 static struct isa_pnp_id forcepad_ids[] = {
7475 { 0x0d302e4f, "HP PS/2 forcepad port" }, /* SYN300D, EB 1040 */
7476 { 0x14302e4f, "HP PS/2 forcepad port" }, /* SYN3014, EB 1040 */
7481 create_a_copy(device_t atkbdc, device_t me)
7486 /* find the PS/2 mouse device instance under the keyboard controller */
7487 psm = device_find_child(atkbdc, PSM_DRIVER_NAME,
7488 device_get_unit(atkbdc));
7491 if (device_get_state(psm) != DS_NOTPRESENT)
7494 /* move our resource to the found device */
7495 irq = bus_get_resource_start(me, SYS_RES_IRQ, 0);
7496 bus_delete_resource(me, SYS_RES_IRQ, 0);
7497 bus_set_resource(psm, SYS_RES_IRQ, KBDC_RID_AUX, irq, 1);
7499 /* ...then probe and attach it */
7500 return (device_probe_and_attach(psm));
7504 psmcpnp_probe(device_t dev)
7506 struct psmcpnp_softc *sc = device_get_softc(dev);
7507 struct resource *res;
7511 if (ISA_PNP_PROBE(device_get_parent(dev), dev, forcepad_ids) == 0)
7512 sc->type = PSMCPNP_FORCEPAD;
7513 else if (ISA_PNP_PROBE(device_get_parent(dev), dev, topbtpad_ids) == 0)
7514 sc->type = PSMCPNP_TOPBUTTONPAD;
7515 else if (ISA_PNP_PROBE(device_get_parent(dev), dev, psmcpnp_ids) == 0)
7516 sc->type = PSMCPNP_GENERIC;
7521 * The PnP BIOS and ACPI are supposed to assign an IRQ (12)
7522 * to the PS/2 mouse device node. But, some buggy PnP BIOS
7523 * declares the PS/2 mouse device node without an IRQ resource!
7524 * If this happens, we shall refer to device hints.
7525 * If we still don't find it there, use a hardcoded value... XXX
7528 irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid);
7530 if (resource_long_value(PSM_DRIVER_NAME,
7531 device_get_unit(dev),"irq", &irq) != 0)
7533 device_printf(dev, "irq resource info is missing; "
7534 "assuming irq %ld\n", irq);
7535 bus_set_resource(dev, SYS_RES_IRQ, rid, irq, 1);
7537 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 0);
7538 bus_release_resource(dev, SYS_RES_IRQ, rid, res);
7544 return ((res == NULL) ? ENXIO : 0);
7548 psmcpnp_attach(device_t dev)
7552 /* find the keyboard controller, which may be on acpi* or isa* bus */
7553 atkbdc = devclass_get_device(devclass_find(ATKBDC_DRIVER_NAME),
7554 device_get_unit(dev));
7555 if ((atkbdc != NULL) && (device_get_state(atkbdc) == DS_ATTACHED))
7556 create_a_copy(atkbdc, dev);
7561 DRIVER_MODULE(psmcpnp, isa, psmcpnp_driver, psmcpnp_devclass, 0, 0);
7562 DRIVER_MODULE(psmcpnp, acpi, psmcpnp_driver, psmcpnp_devclass, 0, 0);
7563 ISA_PNP_INFO(psmcpnp_ids);
7564 #endif /* DEV_ISA */