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;
242 typedef struct synapticspacket {
247 #define SYNAPTICS_PACKETQUEUE 10
248 #define SYNAPTICS_QUEUE_CURSOR(x) \
249 (x + SYNAPTICS_PACKETQUEUE) % SYNAPTICS_PACKETQUEUE
251 #define SYNAPTICS_VERSION_GE(synhw, major, minor) \
252 ((synhw).infoMajor > (major) || \
253 ((synhw).infoMajor == (major) && (synhw).infoMinor >= (minor)))
255 typedef struct smoother {
256 synapticspacket_t queue[SYNAPTICS_PACKETQUEUE];
269 typedef struct gesture {
275 int zmax; /* maximum pressure value */
276 struct timeval taptimeout; /* tap timeout for touchpads */
280 TRACKPOINT_SYSCTL_SENSITIVITY,
281 TRACKPOINT_SYSCTL_NEGATIVE_INERTIA,
282 TRACKPOINT_SYSCTL_UPPER_PLATEAU,
283 TRACKPOINT_SYSCTL_BACKUP_RANGE,
284 TRACKPOINT_SYSCTL_DRAG_HYSTERESIS,
285 TRACKPOINT_SYSCTL_MINIMUM_DRAG,
286 TRACKPOINT_SYSCTL_UP_THRESHOLD,
287 TRACKPOINT_SYSCTL_THRESHOLD,
288 TRACKPOINT_SYSCTL_JENKS_CURVATURE,
289 TRACKPOINT_SYSCTL_Z_TIME,
290 TRACKPOINT_SYSCTL_PRESS_TO_SELECT,
291 TRACKPOINT_SYSCTL_SKIP_BACKUPS
294 typedef struct trackpointinfo {
295 struct sysctl_ctx_list sysctl_ctx;
296 struct sysctl_oid *sysctl_tree;
311 typedef struct finger {
318 #define PSM_FINGERS 2 /* # of processed fingers */
319 #define PSM_FINGER_IS_PEN (1<<0)
320 #define PSM_FINGER_FUZZY (1<<1)
321 #define PSM_FINGER_DEFAULT_P tap_threshold
322 #define PSM_FINGER_DEFAULT_W 1
323 #define PSM_FINGER_IS_SET(f) ((f).x != -1 && (f).y != -1 && (f).p != 0)
324 #define PSM_FINGER_RESET(f) do { \
325 (f) = (finger_t) { .x = -1, .y = -1, .p = 0, .w = 0, .flags = 0 }; \
328 typedef struct elantechhw {
346 /* minimum versions supported by this driver */
347 #define ELANTECH_HW_IS_V1(fwver) ((fwver) < 0x020030 || (fwver) == 0x020600)
349 #define ELANTECH_MAGIC(magic) \
350 ((magic)[0] == 0x3c && (magic)[1] == 0x03 && \
351 ((magic)[2] == 0xc8 || (magic)[2] == 0x00))
353 #define ELANTECH_FW_ID 0x00
354 #define ELANTECH_FW_VERSION 0x01
355 #define ELANTECH_CAPABILITIES 0x02
356 #define ELANTECH_SAMPLE 0x03
357 #define ELANTECH_RESOLUTION 0x04
358 #define ELANTECH_REG_READ 0x10
359 #define ELANTECH_REG_WRITE 0x11
360 #define ELANTECH_REG_RDWR 0x00
361 #define ELANTECH_CUSTOM_CMD 0xf8
364 #define ELANTECH_MAX_FINGERS 5
366 #define ELANTECH_MAX_FINGERS PSM_FINGERS
369 #define ELANTECH_FINGER_MAX_P 255
370 #define ELANTECH_FINGER_MAX_W 15
371 #define ELANTECH_FINGER_SET_XYP(pb) (finger_t) { \
372 .x = (((pb)->ipacket[1] & 0x0f) << 8) | (pb)->ipacket[2], \
373 .y = (((pb)->ipacket[4] & 0x0f) << 8) | (pb)->ipacket[5], \
374 .p = ((pb)->ipacket[1] & 0xf0) | (((pb)->ipacket[4] >> 4) & 0x0f), \
375 .w = PSM_FINGER_DEFAULT_W, \
381 ELANTECH_PKT_TRACKPOINT,
382 ELANTECH_PKT_V2_COMMON,
383 ELANTECH_PKT_V2_2FINGER,
385 ELANTECH_PKT_V4_STATUS,
386 ELANTECH_PKT_V4_HEAD,
387 ELANTECH_PKT_V4_MOTION
390 #define ELANTECH_PKT_IS_TRACKPOINT(pb) (((pb)->ipacket[3] & 0x0f) == 0x06)
391 #define ELANTECH_PKT_IS_DEBOUNCE(pb, hwversion) ((hwversion) == 4 ? 0 : \
392 (pb)->ipacket[0] == ((hwversion) == 2 ? 0x84 : 0xc4) && \
393 (pb)->ipacket[1] == 0xff && (pb)->ipacket[2] == 0xff && \
394 (pb)->ipacket[3] == 0x02 && (pb)->ipacket[4] == 0xff && \
395 (pb)->ipacket[5] == 0xff)
396 #define ELANTECH_PKT_IS_V2(pb) \
397 (((pb)->ipacket[0] & 0x0c) == 0x04 && ((pb)->ipacket[3] & 0x0f) == 0x02)
398 #define ELANTECH_PKT_IS_V3_HEAD(pb, hascrc) ((hascrc) ? \
399 ((pb)->ipacket[3] & 0x09) == 0x08 : \
400 ((pb)->ipacket[0] & 0x0c) == 0x04 && ((pb)->ipacket[3] & 0xcf) == 0x02)
401 #define ELANTECH_PKT_IS_V3_TAIL(pb, hascrc) ((hascrc) ? \
402 ((pb)->ipacket[3] & 0x09) == 0x09 : \
403 ((pb)->ipacket[0] & 0x0c) == 0x0c && ((pb)->ipacket[3] & 0xce) == 0x0c)
404 #define ELANTECH_PKT_IS_V4(pb, hascrc) ((hascrc) ? \
405 ((pb)->ipacket[3] & 0x08) == 0x00 : \
406 ((pb)->ipacket[0] & 0x0c) == 0x04 && ((pb)->ipacket[3] & 0x1c) == 0x10)
408 typedef struct elantechaction {
409 finger_t fingers[ELANTECH_MAX_FINGERS];
414 /* driver control block */
415 struct psm_softc { /* Driver status information */
417 struct selinfo rsel; /* Process selecting for Input */
418 u_char state; /* Mouse driver state */
419 int config; /* driver configuration flags */
420 int flags; /* other flags */
421 KBDC kbdc; /* handle to access kbd controller */
422 struct resource *intr; /* IRQ resource */
423 void *ih; /* interrupt handle */
424 mousehw_t hw; /* hardware information */
425 synapticshw_t synhw; /* Synaptics hardware information */
426 synapticsinfo_t syninfo; /* Synaptics configuration */
427 smoother_t smoother[PSM_FINGERS]; /* Motion smoothing */
428 gesture_t gesture; /* Gesture context */
429 elantechhw_t elanhw; /* Elantech hardware information */
430 elantechaction_t elanaction; /* Elantech action context */
431 int tphw; /* TrackPoint hardware information */
432 trackpointinfo_t tpinfo; /* TrackPoint configuration */
433 mousemode_t mode; /* operation mode */
434 mousemode_t dflt_mode; /* default operation mode */
435 mousestatus_t status; /* accumulated mouse movement */
436 ringbuf_t queue; /* mouse status queue */
437 packetbuf_t pqueue[PSM_PACKETQUEUE]; /* mouse data queue */
438 int pqueue_start; /* start of data in queue */
439 int pqueue_end; /* end of data in queue */
440 int button; /* the latest button state */
441 int xold; /* previous absolute X position */
442 int yold; /* previous absolute Y position */
443 int xaverage; /* average X position */
444 int yaverage; /* average Y position */
445 int squelch; /* level to filter movement at low speed */
446 int syncerrors; /* # of bytes discarded to synchronize */
447 int pkterrors; /* # of packets failed during quaranteen. */
448 int fpcount; /* forcePad valid packet counter */
449 struct timeval inputtimeout;
450 struct timeval lastsoftintr; /* time of last soft interrupt */
451 struct timeval lastinputerr; /* time last sync error happened */
452 struct timeval idletimeout;
453 packetbuf_t idlepacket; /* packet to send after idle timeout */
454 int watchdog; /* watchdog timer flag */
455 struct callout callout; /* watchdog timer call out */
456 struct callout softcallout; /* buffer timer call out */
461 struct sigio *async; /* Processes waiting for SIGIO */
462 int extended_buttons;
463 int muxport; /* MUX port with attached Synaptics */
464 u_char muxsave[3]; /* 3->6 byte proto conversion buffer */
465 int muxtpbuttons; /* Touchpad button state */
466 int muxmsbuttons; /* Mouse (trackpoint) button state */
467 struct timeval muxmidtimeout; /* middle button supression timeout */
469 struct evdev_dev *evdev_a; /* Absolute reporting device */
470 struct evdev_dev *evdev_r; /* Relative reporting device */
473 static devclass_t psm_devclass;
475 /* driver state flags (state) */
476 #define PSM_VALID 0x80
477 #define PSM_OPEN 1 /* Device is open */
478 #define PSM_ASLP 2 /* Waiting for mouse data */
479 #define PSM_SOFTARMED 4 /* Software interrupt armed */
480 #define PSM_NEED_SYNCBITS 8 /* Set syncbits using next data pkt */
481 #define PSM_EV_OPEN_R 0x10 /* Relative evdev device is open */
482 #define PSM_EV_OPEN_A 0x20 /* Absolute evdev device is open */
484 /* driver configuration flags (config) */
485 #define PSM_CONFIG_RESOLUTION 0x000f /* resolution */
486 #define PSM_CONFIG_ACCEL 0x00f0 /* acceleration factor */
487 #define PSM_CONFIG_NOCHECKSYNC 0x0100 /* disable sync. test */
488 #define PSM_CONFIG_NOIDPROBE 0x0200 /* disable mouse model probe */
489 #define PSM_CONFIG_NORESET 0x0400 /* don't reset the mouse */
490 #define PSM_CONFIG_FORCETAP 0x0800 /* assume `tap' action exists */
491 #define PSM_CONFIG_IGNPORTERROR 0x1000 /* ignore error in aux port test */
492 #define PSM_CONFIG_HOOKRESUME 0x2000 /* hook the system resume event */
493 #define PSM_CONFIG_INITAFTERSUSPEND 0x4000 /* init the device at the resume event */
495 #define PSM_CONFIG_FLAGS \
496 (PSM_CONFIG_RESOLUTION | \
498 PSM_CONFIG_NOCHECKSYNC | \
499 PSM_CONFIG_NOIDPROBE | \
500 PSM_CONFIG_NORESET | \
501 PSM_CONFIG_FORCETAP | \
502 PSM_CONFIG_IGNPORTERROR | \
503 PSM_CONFIG_HOOKRESUME | \
504 PSM_CONFIG_INITAFTERSUSPEND)
506 /* other flags (flags) */
507 #define PSM_FLAGS_FINGERDOWN 0x0001 /* VersaPad finger down */
509 #define kbdcp(p) ((atkbdc_softc_t *)(p))
510 #define ALWAYS_RESTORE_CONTROLLER(kbdc) !(kbdcp(kbdc)->quirks \
511 & KBDC_QUIRK_KEEP_ACTIVATED)
514 static int tap_enabled = -1;
515 static int verbose = PSM_DEBUG;
516 static int synaptics_support = 1;
517 static int trackpoint_support = 1;
518 static int elantech_support = 1;
520 /* for backward compatibility */
521 #define OLD_MOUSE_GETHWINFO _IOR('M', 1, old_mousehw_t)
522 #define OLD_MOUSE_GETMODE _IOR('M', 2, old_mousemode_t)
523 #define OLD_MOUSE_SETMODE _IOW('M', 3, old_mousemode_t)
525 typedef struct old_mousehw {
532 typedef struct old_mousemode {
539 #define SYN_OFFSET(field) offsetof(struct psm_softc, syninfo.field)
541 SYNAPTICS_SYSCTL_MIN_PRESSURE = SYN_OFFSET(min_pressure),
542 SYNAPTICS_SYSCTL_MAX_PRESSURE = SYN_OFFSET(max_pressure),
543 SYNAPTICS_SYSCTL_MAX_WIDTH = SYN_OFFSET(max_width),
544 SYNAPTICS_SYSCTL_MARGIN_TOP = SYN_OFFSET(margin_top),
545 SYNAPTICS_SYSCTL_MARGIN_RIGHT = SYN_OFFSET(margin_right),
546 SYNAPTICS_SYSCTL_MARGIN_BOTTOM = SYN_OFFSET(margin_bottom),
547 SYNAPTICS_SYSCTL_MARGIN_LEFT = SYN_OFFSET(margin_left),
548 SYNAPTICS_SYSCTL_NA_TOP = SYN_OFFSET(na_top),
549 SYNAPTICS_SYSCTL_NA_RIGHT = SYN_OFFSET(na_right),
550 SYNAPTICS_SYSCTL_NA_BOTTOM = SYN_OFFSET(na_bottom),
551 SYNAPTICS_SYSCTL_NA_LEFT = SYN_OFFSET(na_left),
552 SYNAPTICS_SYSCTL_WINDOW_MIN = SYN_OFFSET(window_min),
553 SYNAPTICS_SYSCTL_WINDOW_MAX = SYN_OFFSET(window_max),
554 SYNAPTICS_SYSCTL_MULTIPLICATOR = SYN_OFFSET(multiplicator),
555 SYNAPTICS_SYSCTL_WEIGHT_CURRENT = SYN_OFFSET(weight_current),
556 SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS = SYN_OFFSET(weight_previous),
557 SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA = SYN_OFFSET(weight_previous_na),
558 SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED = SYN_OFFSET(weight_len_squared),
559 SYNAPTICS_SYSCTL_DIV_MIN = SYN_OFFSET(div_min),
560 SYNAPTICS_SYSCTL_DIV_MAX = SYN_OFFSET(div_max),
561 SYNAPTICS_SYSCTL_DIV_MAX_NA = SYN_OFFSET(div_max_na),
562 SYNAPTICS_SYSCTL_DIV_LEN = SYN_OFFSET(div_len),
563 SYNAPTICS_SYSCTL_TAP_MAX_DELTA = SYN_OFFSET(tap_max_delta),
564 SYNAPTICS_SYSCTL_TAP_MIN_QUEUE = SYN_OFFSET(tap_min_queue),
565 SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT = SYN_OFFSET(taphold_timeout),
566 SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA = SYN_OFFSET(vscroll_hor_area),
567 SYNAPTICS_SYSCTL_VSCROLL_VER_AREA = SYN_OFFSET(vscroll_ver_area),
568 SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA = SYN_OFFSET(vscroll_min_delta),
569 SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN = SYN_OFFSET(vscroll_div_min),
570 SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX = SYN_OFFSET(vscroll_div_max),
571 SYNAPTICS_SYSCTL_TOUCHPAD_OFF = SYN_OFFSET(touchpad_off),
572 SYNAPTICS_SYSCTL_SOFTBUTTONS_Y = SYN_OFFSET(softbuttons_y),
573 SYNAPTICS_SYSCTL_SOFTBUTTON2_X = SYN_OFFSET(softbutton2_x),
574 SYNAPTICS_SYSCTL_SOFTBUTTON3_X = SYN_OFFSET(softbutton3_x),
575 SYNAPTICS_SYSCTL_NATURAL_SCROLL = SYN_OFFSET(natural_scroll),
576 #define SYNAPTICS_SYSCTL_LAST SYNAPTICS_SYSCTL_NATURAL_SCROLL
579 /* packet formatting function */
580 typedef int packetfunc_t(struct psm_softc *, u_char *, int *, int,
583 /* function prototypes */
584 static void psmidentify(driver_t *, device_t);
585 static int psmprobe(device_t);
586 static int psmattach(device_t);
587 static int psmdetach(device_t);
588 static int psmresume(device_t);
590 static d_open_t psm_cdev_open;
591 static d_close_t psm_cdev_close;
592 static d_read_t psmread;
593 static d_write_t psmwrite;
594 static d_ioctl_t psmioctl;
595 static d_poll_t psmpoll;
597 static int psmopen(struct psm_softc *);
598 static int psmclose(struct psm_softc *);
601 static evdev_open_t psm_ev_open_r;
602 static evdev_close_t psm_ev_close_r;
603 static evdev_open_t psm_ev_open_a;
604 static evdev_close_t psm_ev_close_a;
607 static int enable_aux_dev(KBDC);
608 static int disable_aux_dev(KBDC);
609 static int get_mouse_status(KBDC, int *, int, int);
610 static int get_aux_id(KBDC);
611 static int set_mouse_sampling_rate(KBDC, int);
612 static int set_mouse_scaling(KBDC, int);
613 static int set_mouse_resolution(KBDC, int);
614 static int set_mouse_mode(KBDC);
615 static int get_mouse_buttons(KBDC);
616 static int is_a_mouse(int);
617 static void recover_from_error(KBDC);
618 static int restore_controller(KBDC, int);
619 static int doinitialize(struct psm_softc *, mousemode_t *);
620 static int doopen(struct psm_softc *, int);
621 static int reinitialize(struct psm_softc *, int);
622 static char *model_name(int);
623 static void psmsoftintr(void *);
624 static void psmsoftintridle(void *);
625 static void psmintr(void *);
626 static void psmtimeout(void *);
627 static int timeelapsed(const struct timeval *, int, int,
628 const struct timeval *);
629 static void dropqueue(struct psm_softc *);
630 static void flushpackets(struct psm_softc *);
631 static void proc_mmanplus(struct psm_softc *, packetbuf_t *,
632 mousestatus_t *, int *, int *, int *);
633 static int proc_synaptics(struct psm_softc *, packetbuf_t *,
634 mousestatus_t *, int *, int *, int *);
635 static int proc_synaptics_mux(struct psm_softc *, packetbuf_t *);
636 static void proc_versapad(struct psm_softc *, packetbuf_t *,
637 mousestatus_t *, int *, int *, int *);
638 static int proc_elantech(struct psm_softc *, packetbuf_t *,
639 mousestatus_t *, int *, int *, int *);
640 static int psmpalmdetect(struct psm_softc *, finger_t *, int);
641 static void psmgestures(struct psm_softc *, finger_t *, int,
643 static void psmsmoother(struct psm_softc *, finger_t *, int,
644 mousestatus_t *, int *, int *);
645 static int tame_mouse(struct psm_softc *, packetbuf_t *, mousestatus_t *,
648 /* vendor specific features */
649 enum probearg { PROBE, REINIT };
650 typedef int probefunc_t(struct psm_softc *, enum probearg);
652 static int mouse_id_proc1(KBDC, int, int, int *);
653 static int mouse_ext_command(KBDC, int);
655 static probefunc_t enable_groller;
656 static probefunc_t enable_gmouse;
657 static probefunc_t enable_aglide;
658 static probefunc_t enable_kmouse;
659 static probefunc_t enable_msexplorer;
660 static probefunc_t enable_msintelli;
661 static probefunc_t enable_4dmouse;
662 static probefunc_t enable_4dplus;
663 static probefunc_t enable_mmanplus;
664 static probefunc_t enable_synaptics;
665 static probefunc_t enable_synaptics_mux;
666 static probefunc_t enable_trackpoint;
667 static probefunc_t enable_versapad;
668 static probefunc_t enable_elantech;
670 static void set_trackpoint_parameters(struct psm_softc *sc);
671 static void synaptics_passthrough_on(struct psm_softc *sc);
672 static void synaptics_passthrough_off(struct psm_softc *sc);
673 static int synaptics_preferred_mode(struct psm_softc *sc);
674 static void synaptics_set_mode(struct psm_softc *sc, int mode_byte);
680 probefunc_t *probefunc;
683 * WARNING: the order of probe is very important. Don't mess it
684 * unless you know what you are doing.
686 { MOUSE_MODEL_SYNAPTICS, /* Synaptics Touchpad on Active Mux */
687 0x00, MOUSE_PS2_PACKETSIZE, enable_synaptics_mux },
688 { MOUSE_MODEL_NET, /* Genius NetMouse */
689 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_gmouse },
690 { MOUSE_MODEL_NETSCROLL, /* Genius NetScroll */
691 0xc8, 6, enable_groller },
692 { MOUSE_MODEL_MOUSEMANPLUS, /* Logitech MouseMan+ */
693 0x08, MOUSE_PS2_PACKETSIZE, enable_mmanplus },
694 { MOUSE_MODEL_EXPLORER, /* Microsoft IntelliMouse Explorer */
695 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msexplorer },
696 { MOUSE_MODEL_4D, /* A4 Tech 4D Mouse */
697 0x08, MOUSE_4D_PACKETSIZE, enable_4dmouse },
698 { MOUSE_MODEL_4DPLUS, /* A4 Tech 4D+ Mouse */
699 0xc8, MOUSE_4DPLUS_PACKETSIZE, enable_4dplus },
700 { MOUSE_MODEL_SYNAPTICS, /* Synaptics Touchpad */
701 0xc0, MOUSE_SYNAPTICS_PACKETSIZE, enable_synaptics },
702 { MOUSE_MODEL_ELANTECH, /* Elantech Touchpad */
703 0x04, MOUSE_ELANTECH_PACKETSIZE, enable_elantech },
704 { MOUSE_MODEL_INTELLI, /* Microsoft IntelliMouse */
705 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msintelli },
706 { MOUSE_MODEL_GLIDEPOINT, /* ALPS GlidePoint */
707 0xc0, MOUSE_PS2_PACKETSIZE, enable_aglide },
708 { MOUSE_MODEL_THINK, /* Kensington ThinkingMouse */
709 0x80, MOUSE_PS2_PACKETSIZE, enable_kmouse },
710 { MOUSE_MODEL_VERSAPAD, /* Interlink electronics VersaPad */
711 0xe8, MOUSE_PS2VERSA_PACKETSIZE, enable_versapad },
712 { MOUSE_MODEL_TRACKPOINT, /* IBM/Lenovo TrackPoint */
713 0xc0, MOUSE_PS2_PACKETSIZE, enable_trackpoint },
714 { MOUSE_MODEL_GENERIC,
715 0xc0, MOUSE_PS2_PACKETSIZE, NULL },
717 #define GENERIC_MOUSE_ENTRY (nitems(vendortype) - 1)
719 /* device driver declarateion */
720 static device_method_t psm_methods[] = {
721 /* Device interface */
722 DEVMETHOD(device_identify, psmidentify),
723 DEVMETHOD(device_probe, psmprobe),
724 DEVMETHOD(device_attach, psmattach),
725 DEVMETHOD(device_detach, psmdetach),
726 DEVMETHOD(device_resume, psmresume),
731 static driver_t psm_driver = {
734 sizeof(struct psm_softc),
737 static struct cdevsw psm_cdevsw = {
738 .d_version = D_VERSION,
739 .d_flags = D_NEEDGIANT,
740 .d_open = psm_cdev_open,
741 .d_close = psm_cdev_close,
746 .d_name = PSM_DRIVER_NAME,
750 static const struct evdev_methods psm_ev_methods_r = {
751 .ev_open = psm_ev_open_r,
752 .ev_close = psm_ev_close_r,
754 static const struct evdev_methods psm_ev_methods_a = {
755 .ev_open = psm_ev_open_a,
756 .ev_close = psm_ev_close_a,
760 /* device I/O routines */
762 enable_aux_dev(KBDC kbdc)
766 res = send_aux_command(kbdc, PSMC_ENABLE_DEV);
767 VLOG(2, (LOG_DEBUG, "psm: ENABLE_DEV return code:%04x\n", res));
769 return (res == PSM_ACK);
773 disable_aux_dev(KBDC kbdc)
777 res = send_aux_command(kbdc, PSMC_DISABLE_DEV);
778 VLOG(2, (LOG_DEBUG, "psm: DISABLE_DEV return code:%04x\n", res));
780 return (res == PSM_ACK);
784 get_mouse_status(KBDC kbdc, int *status, int flag, int len)
793 cmd = PSMC_SEND_DEV_STATUS;
796 cmd = PSMC_SEND_DEV_DATA;
799 empty_aux_buffer(kbdc, 5);
800 res = send_aux_command(kbdc, cmd);
801 VLOG(2, (LOG_DEBUG, "psm: SEND_AUX_DEV_%s return code:%04x\n",
802 (flag == 1) ? "DATA" : "STATUS", res));
806 for (i = 0; i < len; ++i) {
807 status[i] = read_aux_data(kbdc);
814 VLOG(1, (LOG_DEBUG, "psm: %s %02x %02x %02x\n",
815 (flag == 1) ? "data" : "status", status[0], status[1], status[2]));
822 get_aux_id(KBDC kbdc)
827 empty_aux_buffer(kbdc, 5);
828 res = send_aux_command(kbdc, PSMC_SEND_DEV_ID);
829 VLOG(2, (LOG_DEBUG, "psm: SEND_DEV_ID return code:%04x\n", res));
836 id = read_aux_data(kbdc);
837 VLOG(2, (LOG_DEBUG, "psm: device ID: %04x\n", id));
843 set_mouse_sampling_rate(KBDC kbdc, int rate)
847 res = send_aux_command_and_data(kbdc, PSMC_SET_SAMPLING_RATE, rate);
848 VLOG(2, (LOG_DEBUG, "psm: SET_SAMPLING_RATE (%d) %04x\n", rate, res));
850 return ((res == PSM_ACK) ? rate : -1);
854 set_mouse_scaling(KBDC kbdc, int scale)
861 scale = PSMC_SET_SCALING11;
864 scale = PSMC_SET_SCALING21;
867 res = send_aux_command(kbdc, scale);
868 VLOG(2, (LOG_DEBUG, "psm: SET_SCALING%s return code:%04x\n",
869 (scale == PSMC_SET_SCALING21) ? "21" : "11", res));
871 return (res == PSM_ACK);
874 /* `val' must be 0 through PSMD_MAX_RESOLUTION */
876 set_mouse_resolution(KBDC kbdc, int val)
880 res = send_aux_command_and_data(kbdc, PSMC_SET_RESOLUTION, val);
881 VLOG(2, (LOG_DEBUG, "psm: SET_RESOLUTION (%d) %04x\n", val, res));
883 return ((res == PSM_ACK) ? val : -1);
887 * NOTE: once `set_mouse_mode()' is called, the mouse device must be
888 * re-enabled by calling `enable_aux_dev()'
891 set_mouse_mode(KBDC kbdc)
895 res = send_aux_command(kbdc, PSMC_SET_STREAM_MODE);
896 VLOG(2, (LOG_DEBUG, "psm: SET_STREAM_MODE return code:%04x\n", res));
898 return (res == PSM_ACK);
902 get_mouse_buttons(KBDC kbdc)
904 int c = 2; /* assume two buttons by default */
908 * NOTE: a special sequence to obtain Logitech Mouse specific
909 * information: set resolution to 25 ppi, set scaling to 1:1, set
910 * scaling to 1:1, set scaling to 1:1. Then the second byte of the
911 * mouse status bytes is the number of available buttons.
912 * Some manufactures also support this sequence.
914 if (set_mouse_resolution(kbdc, PSMD_RES_LOW) != PSMD_RES_LOW)
916 if (set_mouse_scaling(kbdc, 1) && set_mouse_scaling(kbdc, 1) &&
917 set_mouse_scaling(kbdc, 1) &&
918 get_mouse_status(kbdc, status, 0, 3) >= 3 && status[1] != 0)
923 /* misc subroutines */
925 * Someday, I will get the complete list of valid pointing devices and
932 static int valid_ids[] = {
933 PSM_MOUSE_ID, /* mouse */
934 PSM_BALLPOINT_ID, /* ballpoint device */
935 PSM_INTELLI_ID, /* Intellimouse */
936 PSM_EXPLORER_ID, /* Intellimouse Explorer */
937 -1 /* end of table */
941 for (i = 0; valid_ids[i] >= 0; ++i)
942 if (valid_ids[i] == id)
951 model_name(int model)
957 { MOUSE_MODEL_NETSCROLL, "NetScroll" },
958 { MOUSE_MODEL_NET, "NetMouse/NetScroll Optical" },
959 { MOUSE_MODEL_GLIDEPOINT, "GlidePoint" },
960 { MOUSE_MODEL_THINK, "ThinkingMouse" },
961 { MOUSE_MODEL_INTELLI, "IntelliMouse" },
962 { MOUSE_MODEL_MOUSEMANPLUS, "MouseMan+" },
963 { MOUSE_MODEL_VERSAPAD, "VersaPad" },
964 { MOUSE_MODEL_EXPLORER, "IntelliMouse Explorer" },
965 { MOUSE_MODEL_4D, "4D Mouse" },
966 { MOUSE_MODEL_4DPLUS, "4D+ Mouse" },
967 { MOUSE_MODEL_SYNAPTICS, "Synaptics Touchpad" },
968 { MOUSE_MODEL_TRACKPOINT, "IBM/Lenovo TrackPoint" },
969 { MOUSE_MODEL_ELANTECH, "Elantech Touchpad" },
970 { MOUSE_MODEL_GENERIC, "Generic PS/2 mouse" },
971 { MOUSE_MODEL_UNKNOWN, "Unknown" },
975 for (i = 0; models[i].model_code != MOUSE_MODEL_UNKNOWN; ++i)
976 if (models[i].model_code == model)
978 return (models[i].model_name);
982 recover_from_error(KBDC kbdc)
984 /* discard anything left in the output buffer */
985 empty_both_buffers(kbdc, 10);
989 * NOTE: KBDC_RESET_KBD may not restore the communication between the
990 * keyboard and the controller.
995 * NOTE: somehow diagnostic and keyboard port test commands bring the
998 if (!test_controller(kbdc))
999 log(LOG_ERR, "psm: keyboard controller failed.\n");
1000 /* if there isn't a keyboard in the system, the following error is OK */
1001 if (test_kbd_port(kbdc) != 0)
1002 VLOG(1, (LOG_ERR, "psm: keyboard port failed.\n"));
1007 restore_controller(KBDC kbdc, int command_byte)
1009 empty_both_buffers(kbdc, 10);
1011 if (!set_controller_command_byte(kbdc, 0xff, command_byte)) {
1012 log(LOG_ERR, "psm: failed to restore the keyboard controller "
1014 empty_both_buffers(kbdc, 10);
1017 empty_both_buffers(kbdc, 10);
1023 * Re-initialize the aux port and device. The aux port must be enabled
1024 * and its interrupt must be disabled before calling this routine.
1025 * The aux device will be disabled before returning.
1026 * The keyboard controller must be locked via `kbdc_lock()' before
1027 * calling this routine.
1030 doinitialize(struct psm_softc *sc, mousemode_t *mode)
1032 KBDC kbdc = sc->kbdc;
1036 switch((i = test_aux_port(kbdc))) {
1037 case 1: /* ignore these errors */
1043 "psm%d: strange result for test aux port (%d).\n",
1046 case 0: /* no error */
1048 case -1: /* time out */
1049 default: /* error */
1050 recover_from_error(kbdc);
1051 if (sc->config & PSM_CONFIG_IGNPORTERROR)
1053 log(LOG_ERR, "psm%d: the aux port is not functioning (%d).\n",
1058 if (sc->config & PSM_CONFIG_NORESET) {
1060 * Don't try to reset the pointing device. It may possibly
1061 * be left in the unknown state, though...
1065 * NOTE: some controllers appears to hang the `keyboard' when
1066 * the aux port doesn't exist and `PSMC_RESET_DEV' is issued.
1068 if (!reset_aux_dev(kbdc)) {
1069 recover_from_error(kbdc);
1070 log(LOG_ERR, "psm%d: failed to reset the aux device.\n",
1077 * both the aux port and the aux device is functioning, see
1078 * if the device can be enabled.
1080 if (!enable_aux_dev(kbdc) || !disable_aux_dev(kbdc)) {
1081 log(LOG_ERR, "psm%d: failed to enable the aux device.\n",
1085 empty_both_buffers(kbdc, 10); /* remove stray data if any */
1087 /* Re-enable the mouse. */
1088 for (i = 0; vendortype[i].probefunc != NULL; ++i)
1089 if (vendortype[i].model == sc->hw.model)
1090 (*vendortype[i].probefunc)(sc, REINIT);
1092 /* set mouse parameters */
1093 if (mode != (mousemode_t *)NULL) {
1095 mode->rate = set_mouse_sampling_rate(kbdc, mode->rate);
1096 if (mode->resolution >= 0)
1098 set_mouse_resolution(kbdc, mode->resolution);
1099 set_mouse_scaling(kbdc, 1);
1100 set_mouse_mode(kbdc);
1103 /* Record sync on the next data packet we see. */
1104 sc->flags |= PSM_NEED_SYNCBITS;
1106 /* just check the status of the mouse */
1107 if (get_mouse_status(kbdc, stat, 0, 3) < 3)
1108 log(LOG_DEBUG, "psm%d: failed to get status (doinitialize).\n",
1115 doopen(struct psm_softc *sc, int command_byte)
1118 int mux_enabled = FALSE;
1121 * FIXME: Synaptics TouchPad seems to go back to Relative Mode with
1122 * no obvious reason. Thus we check the current mode and restore the
1123 * Absolute Mode if it was cleared.
1125 * The previous hack at the end of psmprobe() wasn't efficient when
1126 * moused(8) was restarted.
1128 * A Reset (FF) or Set Defaults (F6) command would clear the
1129 * Absolute Mode bit. But a verbose boot or debug.psm.loglevel=5
1130 * doesn't show any evidence of such a command.
1132 if (sc->hw.model == MOUSE_MODEL_SYNAPTICS) {
1133 if (sc->muxport != PSM_NOMUX) {
1134 mux_enabled = enable_aux_mux(sc->kbdc) >= 0;
1136 set_active_aux_mux_port(sc->kbdc, sc->muxport);
1138 log(LOG_ERR, "psm%d: failed to enable "
1139 "active multiplexing mode.\n",
1142 mouse_ext_command(sc->kbdc, SYNAPTICS_READ_MODES);
1143 get_mouse_status(sc->kbdc, stat, 0, 3);
1144 if ((SYNAPTICS_VERSION_GE(sc->synhw, 7, 5) ||
1147 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
1148 VLOG(5, (LOG_DEBUG, "psm%d: Synaptis Absolute Mode "
1149 "hopefully restored\n",
1153 disable_aux_mux(sc->kbdc);
1157 * A user may want to disable tap and drag gestures on a Synaptics
1158 * TouchPad when it operates in Relative Mode.
1160 if (sc->hw.model == MOUSE_MODEL_GENERIC) {
1161 if (tap_enabled > 0) {
1163 "psm%d: enable tap and drag gestures\n",
1165 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
1166 } else if (tap_enabled == 0) {
1168 "psm%d: disable tap and drag gestures\n",
1170 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
1174 /* enable the mouse device */
1175 if (!enable_aux_dev(sc->kbdc)) {
1176 /* MOUSE ERROR: failed to enable the mouse because:
1177 * 1) the mouse is faulty,
1178 * 2) the mouse has been removed(!?)
1179 * In the latter case, the keyboard may have hung, and need
1180 * recovery procedure...
1182 recover_from_error(sc->kbdc);
1184 /* FIXME: we could reset the mouse here and try to enable
1185 * it again. But it will take long time and it's not a good
1186 * idea to disable the keyboard that long...
1188 if (!doinitialize(sc, &sc->mode) || !enable_aux_dev(sc->kbdc)) {
1189 recover_from_error(sc->kbdc);
1193 restore_controller(sc->kbdc, command_byte);
1194 /* mark this device is no longer available */
1195 sc->state &= ~PSM_VALID;
1197 "psm%d: failed to enable the device (doopen).\n",
1203 if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
1204 log(LOG_DEBUG, "psm%d: failed to get status (doopen).\n",
1207 /* enable the aux port and interrupt */
1208 if (!set_controller_command_byte(sc->kbdc,
1209 kbdc_get_device_mask(sc->kbdc),
1210 (command_byte & KBD_KBD_CONTROL_BITS) |
1211 KBD_ENABLE_AUX_PORT | KBD_ENABLE_AUX_INT)) {
1212 /* CONTROLLER ERROR */
1213 disable_aux_dev(sc->kbdc);
1214 restore_controller(sc->kbdc, command_byte);
1216 "psm%d: failed to enable the aux interrupt (doopen).\n",
1221 /* start the watchdog timer */
1222 sc->watchdog = FALSE;
1223 callout_reset(&sc->callout, hz * 2, psmtimeout, sc);
1229 reinitialize(struct psm_softc *sc, int doinit)
1235 /* don't let anybody mess with the aux device */
1236 if (!kbdc_lock(sc->kbdc, TRUE))
1240 /* block our watchdog timer */
1241 sc->watchdog = FALSE;
1242 callout_stop(&sc->callout);
1244 /* save the current controller command byte */
1245 empty_both_buffers(sc->kbdc, 10);
1246 c = get_controller_command_byte(sc->kbdc);
1248 "psm%d: current command byte: %04x (reinitialize).\n",
1251 /* enable the aux port but disable the aux interrupt and the keyboard */
1252 if ((c == -1) || !set_controller_command_byte(sc->kbdc,
1253 kbdc_get_device_mask(sc->kbdc),
1254 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
1255 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1256 /* CONTROLLER ERROR */
1258 kbdc_lock(sc->kbdc, FALSE);
1260 "psm%d: unable to set the command byte (reinitialize).\n",
1265 /* flush any data */
1266 if (sc->state & PSM_VALID) {
1267 /* this may fail; but never mind... */
1268 disable_aux_dev(sc->kbdc);
1269 empty_aux_buffer(sc->kbdc, 10);
1274 memset(&sc->lastinputerr, 0, sizeof(sc->lastinputerr));
1276 /* try to detect the aux device; are you still there? */
1279 if (doinitialize(sc, &sc->mode)) {
1281 sc->state |= PSM_VALID;
1283 /* the device has gone! */
1284 restore_controller(sc->kbdc, c);
1285 sc->state &= ~PSM_VALID;
1287 "psm%d: the aux device has gone! (reinitialize).\n",
1294 /* restore the driver state */
1295 if ((sc->state & (PSM_OPEN | PSM_EV_OPEN_R | PSM_EV_OPEN_A)) &&
1297 /* enable the aux device and the port again */
1298 err = doopen(sc, c);
1300 log(LOG_ERR, "psm%d: failed to enable the device "
1301 "(reinitialize).\n", sc->unit);
1303 /* restore the keyboard port and disable the aux port */
1304 if (!set_controller_command_byte(sc->kbdc,
1305 kbdc_get_device_mask(sc->kbdc),
1306 (c & KBD_KBD_CONTROL_BITS) |
1307 KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1308 /* CONTROLLER ERROR */
1309 log(LOG_ERR, "psm%d: failed to disable the aux port "
1310 "(reinitialize).\n", sc->unit);
1315 kbdc_lock(sc->kbdc, FALSE);
1319 /* psm driver entry points */
1322 psmidentify(driver_t *driver, device_t parent)
1329 unit = device_get_unit(parent);
1331 /* always add at least one child */
1332 psm = BUS_ADD_CHILD(parent, KBDC_RID_AUX, driver->name, unit);
1336 irq = bus_get_resource_start(psm, SYS_RES_IRQ, KBDC_RID_AUX);
1341 * If the PS/2 mouse device has already been reported by ACPI or
1342 * PnP BIOS, obtain the IRQ resource from it.
1343 * (See psmcpnp_attach() below.)
1345 psmc = device_find_child(device_get_parent(parent),
1346 PSMCPNP_DRIVER_NAME, unit);
1349 irq = bus_get_resource_start(psmc, SYS_RES_IRQ, 0);
1352 bus_delete_resource(psmc, SYS_RES_IRQ, 0);
1353 bus_set_resource(psm, SYS_RES_IRQ, KBDC_RID_AUX, irq, 1);
1356 #define endprobe(v) do { \
1359 kbdc_set_device_mask(sc->kbdc, mask); \
1360 kbdc_lock(sc->kbdc, FALSE); \
1365 psmprobe(device_t dev)
1367 int unit = device_get_unit(dev);
1368 struct psm_softc *sc = device_get_softc(dev);
1379 /* see if IRQ is available */
1381 sc->intr = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
1382 if (sc->intr == NULL) {
1384 device_printf(dev, "unable to allocate IRQ\n");
1387 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
1390 sc->kbdc = atkbdc_open(device_get_unit(device_get_parent(dev)));
1391 sc->config = device_get_flags(dev) & PSM_CONFIG_FLAGS;
1392 /* XXX: for backward compatibility */
1393 #if defined(PSM_HOOKRESUME) || defined(PSM_HOOKAPM)
1395 #ifdef PSM_RESETAFTERSUSPEND
1396 PSM_CONFIG_INITAFTERSUSPEND;
1398 PSM_CONFIG_HOOKRESUME;
1400 #endif /* PSM_HOOKRESUME | PSM_HOOKAPM */
1402 sc->muxport = PSM_NOMUX;
1406 device_set_desc(dev, "PS/2 Mouse");
1408 if (!kbdc_lock(sc->kbdc, TRUE)) {
1409 printf("psm%d: unable to lock the controller.\n", unit);
1416 * NOTE: two bits in the command byte controls the operation of the
1417 * aux port (mouse port): the aux port disable bit (bit 5) and the aux
1418 * port interrupt (IRQ 12) enable bit (bit 2).
1421 /* discard anything left after the keyboard initialization */
1422 empty_both_buffers(sc->kbdc, 10);
1424 /* save the current command byte; it will be used later */
1425 mask = kbdc_get_device_mask(sc->kbdc) & ~KBD_AUX_CONTROL_BITS;
1426 command_byte = get_controller_command_byte(sc->kbdc);
1428 printf("psm%d: current command byte:%04x\n", unit,
1430 if (command_byte == -1) {
1431 /* CONTROLLER ERROR */
1432 printf("psm%d: unable to get the current command byte value.\n",
1438 * disable the keyboard port while probing the aux port, which must be
1439 * enabled during this routine
1441 if (!set_controller_command_byte(sc->kbdc,
1442 KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS,
1443 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
1444 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1446 * this is CONTROLLER ERROR; I don't know how to recover
1447 * from this error...
1449 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1450 restore_controller(sc->kbdc, command_byte);
1451 printf("psm%d: unable to set the command byte.\n", unit);
1454 write_controller_command(sc->kbdc, KBDC_ENABLE_AUX_PORT);
1457 * NOTE: `test_aux_port()' is designed to return with zero if the aux
1458 * port exists and is functioning. However, some controllers appears
1459 * to respond with zero even when the aux port doesn't exist. (It may
1460 * be that this is only the case when the controller DOES have the aux
1461 * port but the port is not wired on the motherboard.) The keyboard
1462 * controllers without the port, such as the original AT, are
1463 * supposed to return with an error code or simply time out. In any
1464 * case, we have to continue probing the port even when the controller
1467 * XXX: some controllers erroneously return the error code 1, 2 or 3
1468 * when it has a perfectly functional aux port. We have to ignore
1469 * this error code. Even if the controller HAS error with the aux
1470 * port, it will be detected later...
1471 * XXX: another incompatible controller returns PSM_ACK (0xfa)...
1473 switch ((i = test_aux_port(sc->kbdc))) {
1474 case 1: /* ignore these errors */
1479 printf("psm%d: strange result for test aux port "
1480 "(%d).\n", unit, i);
1482 case 0: /* no error */
1484 case -1: /* time out */
1485 default: /* error */
1486 recover_from_error(sc->kbdc);
1487 if (sc->config & PSM_CONFIG_IGNPORTERROR)
1489 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1490 restore_controller(sc->kbdc, command_byte);
1492 printf("psm%d: the aux port is not functioning (%d).\n",
1497 if (sc->config & PSM_CONFIG_NORESET) {
1499 * Don't try to reset the pointing device. It may possibly be
1500 * left in an unknown state, though...
1504 * NOTE: some controllers appears to hang the `keyboard' when
1505 * the aux port doesn't exist and `PSMC_RESET_DEV' is issued.
1507 * Attempt to reset the controller twice -- this helps
1508 * pierce through some KVM switches. The second reset
1511 if (!reset_aux_dev(sc->kbdc)) {
1512 recover_from_error(sc->kbdc);
1513 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1514 restore_controller(sc->kbdc, command_byte);
1516 printf("psm%d: failed to reset the aux "
1519 } else if (!reset_aux_dev(sc->kbdc)) {
1520 recover_from_error(sc->kbdc);
1522 printf("psm%d: failed to reset the aux device "
1528 * both the aux port and the aux device are functioning, see if the
1529 * device can be enabled. NOTE: when enabled, the device will start
1530 * sending data; we shall immediately disable the device once we know
1531 * the device can be enabled.
1533 if (!enable_aux_dev(sc->kbdc) || !disable_aux_dev(sc->kbdc)) {
1535 recover_from_error(sc->kbdc);
1536 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1537 restore_controller(sc->kbdc, command_byte);
1539 printf("psm%d: failed to enable the aux device.\n",
1544 /* save the default values after reset */
1545 if (get_mouse_status(sc->kbdc, stat, 0, 3) >= 3) {
1546 sc->dflt_mode.rate = sc->mode.rate = stat[2];
1547 sc->dflt_mode.resolution = sc->mode.resolution = stat[1];
1549 sc->dflt_mode.rate = sc->mode.rate = -1;
1550 sc->dflt_mode.resolution = sc->mode.resolution = -1;
1553 /* hardware information */
1554 sc->hw.iftype = MOUSE_IF_PS2;
1556 /* verify the device is a mouse */
1557 sc->hw.hwid = get_aux_id(sc->kbdc);
1558 if (!is_a_mouse(sc->hw.hwid)) {
1559 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1560 restore_controller(sc->kbdc, command_byte);
1562 printf("psm%d: unknown device type (%d).\n", unit,
1566 switch (sc->hw.hwid) {
1567 case PSM_BALLPOINT_ID:
1568 sc->hw.type = MOUSE_TRACKBALL;
1571 case PSM_INTELLI_ID:
1572 case PSM_EXPLORER_ID:
1573 case PSM_4DMOUSE_ID:
1575 sc->hw.type = MOUSE_MOUSE;
1578 sc->hw.type = MOUSE_UNKNOWN;
1582 if (sc->config & PSM_CONFIG_NOIDPROBE) {
1584 i = GENERIC_MOUSE_ENTRY;
1587 sc->hw.buttons = get_mouse_buttons(sc->kbdc);
1589 /* other parameters */
1590 for (i = 0; vendortype[i].probefunc != NULL; ++i)
1591 if ((*vendortype[i].probefunc)(sc, PROBE)) {
1593 printf("psm%d: found %s\n", unit,
1594 model_name(vendortype[i].model));
1599 sc->hw.model = vendortype[i].model;
1601 sc->dflt_mode.level = PSM_LEVEL_BASE;
1602 sc->dflt_mode.packetsize = MOUSE_PS2_PACKETSIZE;
1603 sc->dflt_mode.accelfactor = (sc->config & PSM_CONFIG_ACCEL) >> 4;
1604 if (sc->config & PSM_CONFIG_NOCHECKSYNC)
1605 sc->dflt_mode.syncmask[0] = 0;
1607 sc->dflt_mode.syncmask[0] = vendortype[i].syncmask;
1608 if (sc->config & PSM_CONFIG_FORCETAP)
1609 sc->dflt_mode.syncmask[0] &= ~MOUSE_PS2_TAP;
1610 sc->dflt_mode.syncmask[1] = 0; /* syncbits */
1611 sc->mode = sc->dflt_mode;
1612 sc->mode.packetsize = vendortype[i].packetsize;
1614 /* set mouse parameters */
1617 * A version of Logitech FirstMouse+ won't report wheel movement,
1618 * if SET_DEFAULTS is sent... Don't use this command.
1619 * This fix was found by Takashi Nishida.
1621 i = send_aux_command(sc->kbdc, PSMC_SET_DEFAULTS);
1623 printf("psm%d: SET_DEFAULTS return code:%04x\n", unit, i);
1625 if (sc->config & PSM_CONFIG_RESOLUTION)
1626 sc->mode.resolution =
1627 set_mouse_resolution(sc->kbdc,
1628 (sc->config & PSM_CONFIG_RESOLUTION) - 1);
1629 else if (sc->mode.resolution >= 0)
1630 sc->mode.resolution =
1631 set_mouse_resolution(sc->kbdc, sc->dflt_mode.resolution);
1632 if (sc->mode.rate > 0)
1634 set_mouse_sampling_rate(sc->kbdc, sc->dflt_mode.rate);
1635 set_mouse_scaling(sc->kbdc, 1);
1637 /* Record sync on the next data packet we see. */
1638 sc->flags |= PSM_NEED_SYNCBITS;
1640 /* just check the status of the mouse */
1642 * NOTE: XXX there are some arcane controller/mouse combinations out
1643 * there, which hung the controller unless there is data transmission
1644 * after ACK from the mouse.
1646 if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
1647 printf("psm%d: failed to get status.\n", unit);
1650 * When in its native mode, some mice operate with different
1651 * default parameters than in the PS/2 compatible mode.
1653 sc->dflt_mode.rate = sc->mode.rate = stat[2];
1654 sc->dflt_mode.resolution = sc->mode.resolution = stat[1];
1657 /* disable the aux port for now... */
1658 if (!set_controller_command_byte(sc->kbdc,
1659 KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS,
1660 (command_byte & KBD_KBD_CONTROL_BITS) |
1661 KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1663 * this is CONTROLLER ERROR; I don't know the proper way to
1664 * recover from this error...
1666 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1667 restore_controller(sc->kbdc, command_byte);
1668 printf("psm%d: unable to set the command byte.\n", unit);
1673 kbdc_set_device_mask(sc->kbdc, mask | KBD_AUX_CONTROL_BITS);
1674 kbdc_lock(sc->kbdc, FALSE);
1678 #ifdef EVDEV_SUPPORT
1679 /* Values are taken from Linux drivers for userland software compatibility */
1680 #define PS2_MOUSE_VENDOR 0x0002
1681 #define PS2_MOUSE_GENERIC_PRODUCT 0x0001
1682 #define PS2_MOUSE_SYNAPTICS_NAME "SynPS/2 Synaptics TouchPad"
1683 #define PS2_MOUSE_SYNAPTICS_PRODUCT 0x0007
1684 #define PS2_MOUSE_TRACKPOINT_NAME "TPPS/2 IBM TrackPoint"
1685 #define PS2_MOUSE_TRACKPOINT_PRODUCT 0x000A
1686 #define PS2_MOUSE_ELANTECH_NAME "ETPS/2 Elantech Touchpad"
1687 #define PS2_MOUSE_ELANTECH_ST_NAME "ETPS/2 Elantech TrackPoint"
1688 #define PS2_MOUSE_ELANTECH_PRODUCT 0x000E
1690 #define ABSINFO_END { ABS_CNT, 0, 0, 0 }
1693 psm_support_abs_bulk(struct evdev_dev *evdev, const uint16_t info[][4])
1697 for (i = 0; info[i][0] != ABS_CNT; i++)
1698 evdev_support_abs(evdev, info[i][0], 0, info[i][1], info[i][2],
1703 psm_push_mt_finger(struct psm_softc *sc, int id, const finger_t *f)
1705 int y = sc->synhw.minimumYCoord + sc->synhw.maximumYCoord - f->y;
1707 evdev_push_abs(sc->evdev_a, ABS_MT_SLOT, id);
1708 evdev_push_abs(sc->evdev_a, ABS_MT_TRACKING_ID, id);
1709 evdev_push_abs(sc->evdev_a, ABS_MT_POSITION_X, f->x);
1710 evdev_push_abs(sc->evdev_a, ABS_MT_POSITION_Y, y);
1711 evdev_push_abs(sc->evdev_a, ABS_MT_PRESSURE, f->p);
1715 psm_push_st_finger(struct psm_softc *sc, const finger_t *f)
1717 int y = sc->synhw.minimumYCoord + sc->synhw.maximumYCoord - f->y;
1719 evdev_push_abs(sc->evdev_a, ABS_X, f->x);
1720 evdev_push_abs(sc->evdev_a, ABS_Y, y);
1721 evdev_push_abs(sc->evdev_a, ABS_PRESSURE, f->p);
1722 if (sc->synhw.capPalmDetect)
1723 evdev_push_abs(sc->evdev_a, ABS_TOOL_WIDTH, f->w);
1727 psm_release_mt_slot(struct evdev_dev *evdev, int32_t slot)
1730 evdev_push_abs(evdev, ABS_MT_SLOT, slot);
1731 evdev_push_abs(evdev, ABS_MT_TRACKING_ID, -1);
1735 psm_register(device_t dev, int model_code)
1737 struct psm_softc *sc = device_get_softc(dev);
1738 struct evdev_dev *evdev_r;
1739 int error, i, nbuttons, nwheels, product;
1740 bool is_pointing_stick;
1743 name = model_name(model_code);
1744 nbuttons = sc->hw.buttons;
1745 product = PS2_MOUSE_GENERIC_PRODUCT;
1747 is_pointing_stick = false;
1749 switch (model_code) {
1750 case MOUSE_MODEL_TRACKPOINT:
1751 name = PS2_MOUSE_TRACKPOINT_NAME;
1752 product = PS2_MOUSE_TRACKPOINT_PRODUCT;
1754 is_pointing_stick = true;
1757 case MOUSE_MODEL_ELANTECH:
1758 name = PS2_MOUSE_ELANTECH_ST_NAME;
1759 product = PS2_MOUSE_ELANTECH_PRODUCT;
1761 is_pointing_stick = true;
1764 case MOUSE_MODEL_MOUSEMANPLUS:
1765 case MOUSE_MODEL_4D:
1769 case MOUSE_MODEL_EXPLORER:
1770 case MOUSE_MODEL_INTELLI:
1771 case MOUSE_MODEL_NET:
1772 case MOUSE_MODEL_NETSCROLL:
1773 case MOUSE_MODEL_4DPLUS:
1778 evdev_r = evdev_alloc();
1779 evdev_set_name(evdev_r, name);
1780 evdev_set_phys(evdev_r, device_get_nameunit(dev));
1781 evdev_set_id(evdev_r, BUS_I8042, PS2_MOUSE_VENDOR, product, 0);
1782 evdev_set_methods(evdev_r, sc, &psm_ev_methods_r);
1784 evdev_support_prop(evdev_r, INPUT_PROP_POINTER);
1785 if (is_pointing_stick)
1786 evdev_support_prop(evdev_r, INPUT_PROP_POINTING_STICK);
1787 evdev_support_event(evdev_r, EV_SYN);
1788 evdev_support_event(evdev_r, EV_KEY);
1789 evdev_support_event(evdev_r, EV_REL);
1790 evdev_support_rel(evdev_r, REL_X);
1791 evdev_support_rel(evdev_r, REL_Y);
1794 evdev_support_rel(evdev_r, REL_HWHEEL);
1797 evdev_support_rel(evdev_r, REL_WHEEL);
1799 for (i = 0; i < nbuttons; i++)
1800 evdev_support_key(evdev_r, BTN_MOUSE + i);
1802 error = evdev_register_mtx(evdev_r, &Giant);
1804 evdev_free(evdev_r);
1806 sc->evdev_r = evdev_r;
1811 psm_register_synaptics(device_t dev)
1813 struct psm_softc *sc = device_get_softc(dev);
1814 const uint16_t synaptics_absinfo_st[][4] = {
1815 { ABS_X, sc->synhw.minimumXCoord,
1816 sc->synhw.maximumXCoord, sc->synhw.infoXupmm },
1817 { ABS_Y, sc->synhw.minimumYCoord,
1818 sc->synhw.maximumYCoord, sc->synhw.infoYupmm },
1819 { ABS_PRESSURE, 0, ELANTECH_FINGER_MAX_P, 0 },
1822 const uint16_t synaptics_absinfo_mt[][4] = {
1823 { ABS_MT_SLOT, 0, PSM_FINGERS-1, 0},
1824 { ABS_MT_TRACKING_ID, -1, PSM_FINGERS-1, 0},
1825 { ABS_MT_POSITION_X, sc->synhw.minimumXCoord,
1826 sc->synhw.maximumXCoord, sc->synhw.infoXupmm },
1827 { ABS_MT_POSITION_Y, sc->synhw.minimumYCoord,
1828 sc->synhw.maximumYCoord, sc->synhw.infoYupmm },
1829 { ABS_MT_PRESSURE, 0, ELANTECH_FINGER_MAX_P, 0 },
1832 struct evdev_dev *evdev_a;
1833 int error, i, guest_model;
1835 evdev_a = evdev_alloc();
1836 evdev_set_name(evdev_a, PS2_MOUSE_SYNAPTICS_NAME);
1837 evdev_set_phys(evdev_a, device_get_nameunit(dev));
1838 evdev_set_id(evdev_a, BUS_I8042, PS2_MOUSE_VENDOR,
1839 PS2_MOUSE_SYNAPTICS_PRODUCT, 0);
1840 evdev_set_methods(evdev_a, sc, &psm_ev_methods_a);
1842 evdev_support_event(evdev_a, EV_SYN);
1843 evdev_support_event(evdev_a, EV_KEY);
1844 evdev_support_event(evdev_a, EV_ABS);
1845 evdev_support_prop(evdev_a, INPUT_PROP_POINTER);
1846 if (sc->synhw.capAdvancedGestures)
1847 evdev_support_prop(evdev_a, INPUT_PROP_SEMI_MT);
1848 if (sc->synhw.capClickPad)
1849 evdev_support_prop(evdev_a, INPUT_PROP_BUTTONPAD);
1850 if (sc->synhw.capClickPad && sc->synhw.topButtonPad)
1851 evdev_support_prop(evdev_a, INPUT_PROP_TOPBUTTONPAD);
1852 evdev_support_key(evdev_a, BTN_TOUCH);
1853 evdev_support_nfingers(evdev_a, sc->synhw.capReportsV ? 5 : 3);
1854 psm_support_abs_bulk(evdev_a, synaptics_absinfo_st);
1855 if (sc->synhw.capAdvancedGestures || sc->synhw.capReportsV)
1856 psm_support_abs_bulk(evdev_a, synaptics_absinfo_mt);
1857 if (sc->synhw.capPalmDetect)
1858 evdev_support_abs(evdev_a, ABS_TOOL_WIDTH, 0, 0, 15, 0, 0, 0);
1859 evdev_support_key(evdev_a, BTN_LEFT);
1860 if (!sc->synhw.capClickPad) {
1861 evdev_support_key(evdev_a, BTN_RIGHT);
1862 if (sc->synhw.capExtended && sc->synhw.capMiddle)
1863 evdev_support_key(evdev_a, BTN_MIDDLE);
1865 if (sc->synhw.capExtended && sc->synhw.capFourButtons) {
1866 evdev_support_key(evdev_a, BTN_BACK);
1867 evdev_support_key(evdev_a, BTN_FORWARD);
1869 if (sc->synhw.capExtended && (sc->synhw.nExtendedButtons > 0))
1870 for (i = 0; i < sc->synhw.nExtendedButtons; i++)
1871 evdev_support_key(evdev_a, BTN_0 + i);
1873 error = evdev_register_mtx(evdev_a, &Giant);
1874 if (!error && (sc->synhw.capPassthrough || sc->muxport != PSM_NOMUX)) {
1875 guest_model = sc->tpinfo.sysctl_tree != NULL ?
1876 MOUSE_MODEL_TRACKPOINT : MOUSE_MODEL_GENERIC;
1877 error = psm_register(dev, guest_model);
1880 evdev_free(evdev_a);
1882 sc->evdev_a = evdev_a;
1887 psm_register_elantech(device_t dev)
1889 struct psm_softc *sc = device_get_softc(dev);
1890 const uint16_t elantech_absinfo[][4] = {
1891 { ABS_X, 0, sc->elanhw.sizex,
1893 { ABS_Y, 0, sc->elanhw.sizey,
1895 { ABS_PRESSURE, 0, ELANTECH_FINGER_MAX_P, 0 },
1896 { ABS_TOOL_WIDTH, 0, ELANTECH_FINGER_MAX_W, 0 },
1897 { ABS_MT_SLOT, 0, ELANTECH_MAX_FINGERS - 1, 0 },
1898 { ABS_MT_TRACKING_ID, -1, ELANTECH_MAX_FINGERS - 1, 0 },
1899 { ABS_MT_POSITION_X, 0, sc->elanhw.sizex,
1901 { ABS_MT_POSITION_Y, 0, sc->elanhw.sizey,
1903 { ABS_MT_PRESSURE, 0, ELANTECH_FINGER_MAX_P, 0 },
1904 { ABS_MT_TOUCH_MAJOR, 0, ELANTECH_FINGER_MAX_W *
1905 sc->elanhw.dptracex, 0 },
1908 struct evdev_dev *evdev_a;
1911 evdev_a = evdev_alloc();
1912 evdev_set_name(evdev_a, PS2_MOUSE_ELANTECH_NAME);
1913 evdev_set_phys(evdev_a, device_get_nameunit(dev));
1914 evdev_set_id(evdev_a, BUS_I8042, PS2_MOUSE_VENDOR,
1915 PS2_MOUSE_ELANTECH_PRODUCT, 0);
1916 evdev_set_methods(evdev_a, sc, &psm_ev_methods_a);
1918 evdev_support_event(evdev_a, EV_SYN);
1919 evdev_support_event(evdev_a, EV_KEY);
1920 evdev_support_event(evdev_a, EV_ABS);
1921 evdev_support_prop(evdev_a, INPUT_PROP_POINTER);
1922 if (sc->elanhw.issemimt)
1923 evdev_support_prop(evdev_a, INPUT_PROP_SEMI_MT);
1924 if (sc->elanhw.isclickpad)
1925 evdev_support_prop(evdev_a, INPUT_PROP_BUTTONPAD);
1926 evdev_support_key(evdev_a, BTN_TOUCH);
1927 evdev_support_nfingers(evdev_a, ELANTECH_MAX_FINGERS);
1928 evdev_support_key(evdev_a, BTN_LEFT);
1929 if (!sc->elanhw.isclickpad)
1930 evdev_support_key(evdev_a, BTN_RIGHT);
1931 psm_support_abs_bulk(evdev_a, elantech_absinfo);
1933 error = evdev_register_mtx(evdev_a, &Giant);
1934 if (!error && sc->elanhw.hastrackpoint)
1935 error = psm_register(dev, MOUSE_MODEL_ELANTECH);
1937 evdev_free(evdev_a);
1939 sc->evdev_a = evdev_a;
1945 psmattach(device_t dev)
1947 int unit = device_get_unit(dev);
1948 struct psm_softc *sc = device_get_softc(dev);
1952 /* Setup initial state */
1953 sc->state = PSM_VALID;
1954 callout_init(&sc->callout, 0);
1955 callout_init(&sc->softcallout, 0);
1957 /* Setup our interrupt handler */
1959 sc->intr = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
1960 if (sc->intr == NULL)
1962 error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, NULL, psmintr, sc,
1965 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
1970 sc->dev = make_dev(&psm_cdevsw, 0, 0, 0, 0666, "psm%d", unit);
1971 sc->dev->si_drv1 = sc;
1972 sc->bdev = make_dev(&psm_cdevsw, 0, 0, 0, 0666, "bpsm%d", unit);
1973 sc->bdev->si_drv1 = sc;
1975 #ifdef EVDEV_SUPPORT
1976 switch (sc->hw.model) {
1977 case MOUSE_MODEL_SYNAPTICS:
1978 error = psm_register_synaptics(dev);
1981 case MOUSE_MODEL_ELANTECH:
1982 error = psm_register_elantech(dev);
1986 error = psm_register(dev, sc->hw.model);
1993 /* Some touchpad devices need full reinitialization after suspend. */
1994 switch (sc->hw.model) {
1995 case MOUSE_MODEL_SYNAPTICS:
1996 case MOUSE_MODEL_GLIDEPOINT:
1997 case MOUSE_MODEL_VERSAPAD:
1998 case MOUSE_MODEL_ELANTECH:
1999 sc->config |= PSM_CONFIG_INITAFTERSUSPEND;
2002 if (sc->synhw.infoMajor >= 4 || sc->tphw > 0)
2003 sc->config |= PSM_CONFIG_INITAFTERSUSPEND;
2007 /* Elantech trackpad`s sync bit differs from touchpad`s one */
2008 if (sc->hw.model == MOUSE_MODEL_ELANTECH &&
2009 (sc->elanhw.hascrc || sc->elanhw.hastrackpoint)) {
2010 sc->config |= PSM_CONFIG_NOCHECKSYNC;
2011 sc->flags &= ~PSM_NEED_SYNCBITS;
2015 printf("psm%d: model %s, device ID %d\n",
2016 unit, model_name(sc->hw.model), sc->hw.hwid & 0x00ff);
2018 printf("psm%d: model %s, device ID %d-%02x, %d buttons\n",
2019 unit, model_name(sc->hw.model), sc->hw.hwid & 0x00ff,
2020 sc->hw.hwid >> 8, sc->hw.buttons);
2021 printf("psm%d: config:%08x, flags:%08x, packet size:%d\n",
2022 unit, sc->config, sc->flags, sc->mode.packetsize);
2023 printf("psm%d: syncmask:%02x, syncbits:%02x%s\n",
2024 unit, sc->mode.syncmask[0], sc->mode.syncmask[1],
2025 sc->config & PSM_CONFIG_NOCHECKSYNC ? " (sync not checked)" : "");
2035 psmdetach(device_t dev)
2037 struct psm_softc *sc;
2040 sc = device_get_softc(dev);
2041 if (sc->state & PSM_OPEN)
2044 #ifdef EVDEV_SUPPORT
2045 evdev_free(sc->evdev_r);
2046 evdev_free(sc->evdev_a);
2050 bus_teardown_intr(dev, sc->intr, sc->ih);
2051 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
2053 destroy_dev(sc->dev);
2054 destroy_dev(sc->bdev);
2056 callout_drain(&sc->callout);
2057 callout_drain(&sc->softcallout);
2062 #ifdef EVDEV_SUPPORT
2064 psm_ev_open_r(struct evdev_dev *evdev)
2066 struct psm_softc *sc = evdev_get_softc(evdev);
2069 /* Get device data */
2070 if ((sc->state & PSM_VALID) == 0) {
2071 /* the device is no longer valid/functioning */
2075 if (!(sc->state & (PSM_OPEN | PSM_EV_OPEN_A)))
2079 sc->state |= PSM_EV_OPEN_R;
2085 psm_ev_close_r(struct evdev_dev *evdev)
2087 struct psm_softc *sc = evdev_get_softc(evdev);
2090 sc->state &= ~PSM_EV_OPEN_R;
2092 if (sc->state & (PSM_OPEN | PSM_EV_OPEN_A))
2095 if (sc->state & PSM_VALID)
2102 psm_ev_open_a(struct evdev_dev *evdev)
2104 struct psm_softc *sc = evdev_get_softc(evdev);
2107 /* Get device data */
2108 if ((sc->state & PSM_VALID) == 0) {
2109 /* the device is no longer valid/functioning */
2113 if (!(sc->state & (PSM_OPEN | PSM_EV_OPEN_R)))
2117 sc->state |= PSM_EV_OPEN_A;
2123 psm_ev_close_a(struct evdev_dev *evdev)
2125 struct psm_softc *sc = evdev_get_softc(evdev);
2128 sc->state &= ~PSM_EV_OPEN_A;
2130 if (sc->state & (PSM_OPEN | PSM_EV_OPEN_R))
2133 if (sc->state & PSM_VALID)
2141 psm_cdev_open(struct cdev *dev, int flag, int fmt, struct thread *td)
2143 struct psm_softc *sc;
2146 /* Get device data */
2148 if ((sc == NULL) || (sc->state & PSM_VALID) == 0) {
2149 /* the device is no longer valid/functioning */
2153 /* Disallow multiple opens */
2154 if (sc->state & PSM_OPEN)
2157 device_busy(devclass_get_device(psm_devclass, sc->unit));
2159 #ifdef EVDEV_SUPPORT
2160 /* Already opened by evdev */
2161 if (!(sc->state & (PSM_EV_OPEN_R | PSM_EV_OPEN_A)))
2166 sc->state |= PSM_OPEN;
2168 device_unbusy(devclass_get_device(psm_devclass, sc->unit));
2174 psm_cdev_close(struct cdev *dev, int flag, int fmt, struct thread *td)
2176 struct psm_softc *sc;
2179 /* Get device data */
2181 if ((sc == NULL) || (sc->state & PSM_VALID) == 0) {
2182 /* the device is no longer valid/functioning */
2186 #ifdef EVDEV_SUPPORT
2187 /* Still opened by evdev */
2188 if (!(sc->state & (PSM_EV_OPEN_R | PSM_EV_OPEN_A)))
2193 sc->state &= ~PSM_OPEN;
2194 /* clean up and sigio requests */
2195 if (sc->async != NULL) {
2196 funsetown(&sc->async);
2199 device_unbusy(devclass_get_device(psm_devclass, sc->unit));
2206 psmopen(struct psm_softc *sc)
2212 /* Initialize state */
2213 sc->mode.level = sc->dflt_mode.level;
2214 sc->mode.protocol = sc->dflt_mode.protocol;
2215 sc->watchdog = FALSE;
2218 /* flush the event queue */
2219 sc->queue.count = 0;
2222 sc->status.flags = 0;
2223 sc->status.button = 0;
2224 sc->status.obutton = 0;
2229 sc->pqueue_start = 0;
2232 /* empty input buffer */
2237 /* don't let timeout routines in the keyboard driver to poll the kbdc */
2238 if (!kbdc_lock(sc->kbdc, TRUE))
2241 /* save the current controller command byte */
2243 command_byte = get_controller_command_byte(sc->kbdc);
2245 /* enable the aux port and temporalily disable the keyboard */
2246 if (command_byte == -1 || !set_controller_command_byte(sc->kbdc,
2247 kbdc_get_device_mask(sc->kbdc),
2248 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
2249 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
2250 /* CONTROLLER ERROR; do you know how to get out of this? */
2251 kbdc_lock(sc->kbdc, FALSE);
2254 "psm%d: unable to set the command byte (psmopen).\n",
2259 * Now that the keyboard controller is told not to generate
2260 * the keyboard and mouse interrupts, call `splx()' to allow
2261 * the other tty interrupts. The clock interrupt may also occur,
2262 * but timeout routines will be blocked by the poll flag set
2267 /* enable the mouse device */
2268 err = doopen(sc, command_byte);
2271 kbdc_lock(sc->kbdc, FALSE);
2276 psmclose(struct psm_softc *sc)
2282 /* don't let timeout routines in the keyboard driver to poll the kbdc */
2283 if (!kbdc_lock(sc->kbdc, TRUE))
2286 /* save the current controller command byte */
2288 command_byte = get_controller_command_byte(sc->kbdc);
2289 if (command_byte == -1) {
2290 kbdc_lock(sc->kbdc, FALSE);
2295 /* disable the aux interrupt and temporalily disable the keyboard */
2296 if (!set_controller_command_byte(sc->kbdc,
2297 kbdc_get_device_mask(sc->kbdc),
2298 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
2299 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
2301 "psm%d: failed to disable the aux int (psmclose).\n",
2303 /* CONTROLLER ERROR;
2304 * NOTE: we shall force our way through. Because the only
2305 * ill effect we shall see is that we may not be able
2306 * to read ACK from the mouse, and it doesn't matter much
2307 * so long as the mouse will accept the DISABLE command.
2312 /* stop the watchdog timer */
2313 callout_stop(&sc->callout);
2315 /* remove anything left in the output buffer */
2316 empty_aux_buffer(sc->kbdc, 10);
2318 /* disable the aux device, port and interrupt */
2319 if (sc->state & PSM_VALID) {
2320 if (!disable_aux_dev(sc->kbdc)) {
2322 * NOTE: we don't return (error) and continue,
2323 * pretending we have successfully disabled the device.
2324 * It's OK because the interrupt routine will discard
2325 * any data from the mouse hereafter.
2328 "psm%d: failed to disable the device (psmclose).\n",
2332 if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
2334 "psm%d: failed to get status (psmclose).\n",
2338 if (!set_controller_command_byte(sc->kbdc,
2339 kbdc_get_device_mask(sc->kbdc),
2340 (command_byte & KBD_KBD_CONTROL_BITS) |
2341 KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
2344 * we shall ignore this error; see the above comment.
2347 "psm%d: failed to disable the aux port (psmclose).\n",
2351 /* remove anything left in the output buffer */
2352 empty_aux_buffer(sc->kbdc, 10);
2354 /* close is almost always successful */
2355 kbdc_lock(sc->kbdc, FALSE);
2360 tame_mouse(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *status,
2363 static u_char butmapps2[8] = {
2365 MOUSE_PS2_BUTTON1DOWN,
2366 MOUSE_PS2_BUTTON2DOWN,
2367 MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON2DOWN,
2368 MOUSE_PS2_BUTTON3DOWN,
2369 MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON3DOWN,
2370 MOUSE_PS2_BUTTON2DOWN | MOUSE_PS2_BUTTON3DOWN,
2371 MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON2DOWN |
2372 MOUSE_PS2_BUTTON3DOWN,
2374 static u_char butmapmsc[8] = {
2375 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP |
2376 MOUSE_MSC_BUTTON3UP,
2377 MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
2378 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON3UP,
2379 MOUSE_MSC_BUTTON3UP,
2380 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP,
2381 MOUSE_MSC_BUTTON2UP,
2382 MOUSE_MSC_BUTTON1UP,
2388 if (sc->mode.level == PSM_LEVEL_BASE) {
2389 mapped = status->button & ~MOUSE_BUTTON4DOWN;
2390 if (status->button & MOUSE_BUTTON4DOWN)
2391 mapped |= MOUSE_BUTTON1DOWN;
2392 status->button = mapped;
2393 buf[0] = MOUSE_PS2_SYNC | butmapps2[mapped & MOUSE_STDBUTTONS];
2394 i = imax(imin(status->dx, 255), -256);
2396 buf[0] |= MOUSE_PS2_XNEG;
2398 i = imax(imin(status->dy, 255), -256);
2400 buf[0] |= MOUSE_PS2_YNEG;
2402 return (MOUSE_PS2_PACKETSIZE);
2403 } else if (sc->mode.level == PSM_LEVEL_STANDARD) {
2404 buf[0] = MOUSE_MSC_SYNC |
2405 butmapmsc[status->button & MOUSE_STDBUTTONS];
2406 i = imax(imin(status->dx, 255), -256);
2408 buf[3] = i - buf[1];
2409 i = imax(imin(status->dy, 255), -256);
2411 buf[4] = i - buf[2];
2412 i = imax(imin(status->dz, 127), -128);
2413 buf[5] = (i >> 1) & 0x7f;
2414 buf[6] = (i - (i >> 1)) & 0x7f;
2415 buf[7] = (~status->button >> 3) & 0x7f;
2416 return (MOUSE_SYS_PACKETSIZE);
2418 return (pb->inputbytes);
2422 psmread(struct cdev *dev, struct uio *uio, int flag)
2424 struct psm_softc *sc = dev->si_drv1;
2425 u_char buf[PSM_SMALLBUFSIZE];
2430 if ((sc->state & PSM_VALID) == 0)
2433 /* block until mouse activity occurred */
2435 while (sc->queue.count <= 0) {
2436 if (dev != sc->bdev) {
2438 return (EWOULDBLOCK);
2440 sc->state |= PSM_ASLP;
2441 error = tsleep(sc, PZERO | PCATCH, "psmrea", 0);
2442 sc->state &= ~PSM_ASLP;
2446 } else if ((sc->state & PSM_VALID) == 0) {
2447 /* the device disappeared! */
2454 /* copy data to the user land */
2455 while ((sc->queue.count > 0) && (uio->uio_resid > 0)) {
2457 l = imin(sc->queue.count, uio->uio_resid);
2458 if (l > sizeof(buf))
2460 if (l > sizeof(sc->queue.buf) - sc->queue.head) {
2461 bcopy(&sc->queue.buf[sc->queue.head], &buf[0],
2462 sizeof(sc->queue.buf) - sc->queue.head);
2463 bcopy(&sc->queue.buf[0],
2464 &buf[sizeof(sc->queue.buf) - sc->queue.head],
2465 l - (sizeof(sc->queue.buf) - sc->queue.head));
2467 bcopy(&sc->queue.buf[sc->queue.head], &buf[0], l);
2468 sc->queue.count -= l;
2469 sc->queue.head = (sc->queue.head + l) % sizeof(sc->queue.buf);
2471 error = uiomove(buf, l, uio);
2480 block_mouse_data(struct psm_softc *sc, int *c)
2484 if (!kbdc_lock(sc->kbdc, TRUE))
2488 *c = get_controller_command_byte(sc->kbdc);
2489 if ((*c == -1) || !set_controller_command_byte(sc->kbdc,
2490 kbdc_get_device_mask(sc->kbdc),
2491 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
2492 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
2493 /* this is CONTROLLER ERROR */
2495 kbdc_lock(sc->kbdc, FALSE);
2500 * The device may be in the middle of status data transmission.
2501 * The transmission will be interrupted, thus, incomplete status
2502 * data must be discarded. Although the aux interrupt is disabled
2503 * at the keyboard controller level, at most one aux interrupt
2504 * may have already been pending and a data byte is in the
2505 * output buffer; throw it away. Note that the second argument
2506 * to `empty_aux_buffer()' is zero, so that the call will just
2507 * flush the internal queue.
2508 * `psmintr()' will be invoked after `splx()' if an interrupt is
2509 * pending; it will see no data and returns immediately.
2511 empty_aux_buffer(sc->kbdc, 0); /* flush the queue */
2512 read_aux_data_no_wait(sc->kbdc); /* throw away data if any */
2520 dropqueue(struct psm_softc *sc)
2523 sc->queue.count = 0;
2526 if ((sc->state & PSM_SOFTARMED) != 0) {
2527 sc->state &= ~PSM_SOFTARMED;
2528 callout_stop(&sc->softcallout);
2530 sc->pqueue_start = sc->pqueue_end;
2534 flushpackets(struct psm_softc *sc)
2538 bzero(&sc->pqueue, sizeof(sc->pqueue));
2542 unblock_mouse_data(struct psm_softc *sc, int c)
2547 * We may have seen a part of status data during `set_mouse_XXX()'.
2548 * they have been queued; flush it.
2550 empty_aux_buffer(sc->kbdc, 0);
2552 /* restore ports and interrupt */
2553 if (!set_controller_command_byte(sc->kbdc,
2554 kbdc_get_device_mask(sc->kbdc),
2555 c & (KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS))) {
2557 * CONTROLLER ERROR; this is serious, we may have
2558 * been left with the inaccessible keyboard and
2559 * the disabled mouse interrupt.
2564 kbdc_lock(sc->kbdc, FALSE);
2569 psmwrite(struct cdev *dev, struct uio *uio, int flag)
2571 struct psm_softc *sc = dev->si_drv1;
2572 u_char buf[PSM_SMALLBUFSIZE];
2573 int error = 0, i, l;
2575 if ((sc->state & PSM_VALID) == 0)
2578 if (sc->mode.level < PSM_LEVEL_NATIVE)
2581 /* copy data from the user land */
2582 while (uio->uio_resid > 0) {
2583 l = imin(PSM_SMALLBUFSIZE, uio->uio_resid);
2584 error = uiomove(buf, l, uio);
2587 for (i = 0; i < l; i++) {
2588 VLOG(4, (LOG_DEBUG, "psm: cmd 0x%x\n", buf[i]));
2589 if (!write_aux_command(sc->kbdc, buf[i])) {
2591 "psm: cmd 0x%x failed.\n", buf[i]));
2592 return (reinitialize(sc, FALSE));
2601 psmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
2604 struct psm_softc *sc = dev->si_drv1;
2606 mousestatus_t status;
2613 /* Perform IOCTL command */
2616 case OLD_MOUSE_GETHWINFO:
2618 ((old_mousehw_t *)addr)->buttons = sc->hw.buttons;
2619 ((old_mousehw_t *)addr)->iftype = sc->hw.iftype;
2620 ((old_mousehw_t *)addr)->type = sc->hw.type;
2621 ((old_mousehw_t *)addr)->hwid = sc->hw.hwid & 0x00ff;
2625 case MOUSE_GETHWINFO:
2627 *(mousehw_t *)addr = sc->hw;
2628 if (sc->mode.level == PSM_LEVEL_BASE)
2629 ((mousehw_t *)addr)->model = MOUSE_MODEL_GENERIC;
2633 case MOUSE_SYN_GETHWINFO:
2635 if (sc->synhw.infoMajor >= 4)
2636 *(synapticshw_t *)addr = sc->synhw;
2642 case OLD_MOUSE_GETMODE:
2644 switch (sc->mode.level) {
2645 case PSM_LEVEL_BASE:
2646 ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2648 case PSM_LEVEL_STANDARD:
2649 ((old_mousemode_t *)addr)->protocol =
2650 MOUSE_PROTO_SYSMOUSE;
2652 case PSM_LEVEL_NATIVE:
2653 ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2656 ((old_mousemode_t *)addr)->rate = sc->mode.rate;
2657 ((old_mousemode_t *)addr)->resolution = sc->mode.resolution;
2658 ((old_mousemode_t *)addr)->accelfactor = sc->mode.accelfactor;
2664 *(mousemode_t *)addr = sc->mode;
2665 if ((sc->flags & PSM_NEED_SYNCBITS) != 0) {
2666 ((mousemode_t *)addr)->syncmask[0] = 0;
2667 ((mousemode_t *)addr)->syncmask[1] = 0;
2669 ((mousemode_t *)addr)->resolution =
2670 MOUSE_RES_LOW - sc->mode.resolution;
2671 switch (sc->mode.level) {
2672 case PSM_LEVEL_BASE:
2673 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2674 ((mousemode_t *)addr)->packetsize =
2675 MOUSE_PS2_PACKETSIZE;
2677 case PSM_LEVEL_STANDARD:
2678 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_SYSMOUSE;
2679 ((mousemode_t *)addr)->packetsize =
2680 MOUSE_SYS_PACKETSIZE;
2681 ((mousemode_t *)addr)->syncmask[0] = MOUSE_SYS_SYNCMASK;
2682 ((mousemode_t *)addr)->syncmask[1] = MOUSE_SYS_SYNC;
2684 case PSM_LEVEL_NATIVE:
2685 /* FIXME: this isn't quite correct... XXX */
2686 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2692 case OLD_MOUSE_SETMODE:
2694 if (cmd == OLD_MOUSE_SETMODE) {
2695 mode.rate = ((old_mousemode_t *)addr)->rate;
2697 * resolution old I/F new I/F
2704 if (((old_mousemode_t *)addr)->resolution > 0)
2706 -((old_mousemode_t *)addr)->resolution - 1;
2708 mode.resolution = 0;
2710 ((old_mousemode_t *)addr)->accelfactor;
2713 mode = *(mousemode_t *)addr;
2715 /* adjust and validate parameters. */
2716 if (mode.rate > UCHAR_MAX)
2719 mode.rate = sc->dflt_mode.rate;
2720 else if (mode.rate == -1)
2721 /* don't change the current setting */
2723 else if (mode.rate < 0)
2725 if (mode.resolution >= UCHAR_MAX)
2727 if (mode.resolution >= 200)
2728 mode.resolution = MOUSE_RES_HIGH;
2729 else if (mode.resolution >= 100)
2730 mode.resolution = MOUSE_RES_MEDIUMHIGH;
2731 else if (mode.resolution >= 50)
2732 mode.resolution = MOUSE_RES_MEDIUMLOW;
2733 else if (mode.resolution > 0)
2734 mode.resolution = MOUSE_RES_LOW;
2735 if (mode.resolution == MOUSE_RES_DEFAULT)
2736 mode.resolution = sc->dflt_mode.resolution;
2737 else if (mode.resolution == -1)
2738 /* don't change the current setting */
2740 else if (mode.resolution < 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */
2741 mode.resolution = MOUSE_RES_LOW - mode.resolution;
2742 if (mode.level == -1)
2743 /* don't change the current setting */
2744 mode.level = sc->mode.level;
2745 else if ((mode.level < PSM_LEVEL_MIN) ||
2746 (mode.level > PSM_LEVEL_MAX))
2748 if (mode.accelfactor == -1)
2749 /* don't change the current setting */
2750 mode.accelfactor = sc->mode.accelfactor;
2751 else if (mode.accelfactor < 0)
2754 /* don't allow anybody to poll the keyboard controller */
2755 error = block_mouse_data(sc, &command_byte);
2759 /* set mouse parameters */
2761 mode.rate = set_mouse_sampling_rate(sc->kbdc,
2763 if (mode.resolution >= 0)
2765 set_mouse_resolution(sc->kbdc, mode.resolution);
2766 set_mouse_scaling(sc->kbdc, 1);
2767 get_mouse_status(sc->kbdc, stat, 0, 3);
2770 sc->mode.rate = mode.rate;
2771 sc->mode.resolution = mode.resolution;
2772 sc->mode.accelfactor = mode.accelfactor;
2773 sc->mode.level = mode.level;
2776 unblock_mouse_data(sc, command_byte);
2779 case MOUSE_GETLEVEL:
2780 *(int *)addr = sc->mode.level;
2783 case MOUSE_SETLEVEL:
2784 if ((*(int *)addr < PSM_LEVEL_MIN) ||
2785 (*(int *)addr > PSM_LEVEL_MAX))
2787 sc->mode.level = *(int *)addr;
2790 case MOUSE_GETSTATUS:
2792 status = sc->status;
2793 sc->status.flags = 0;
2794 sc->status.obutton = sc->status.button;
2795 sc->status.button = 0;
2800 *(mousestatus_t *)addr = status;
2803 case MOUSE_READSTATE:
2804 case MOUSE_READDATA:
2805 data = (mousedata_t *)addr;
2806 if (data->len > sizeof(data->buf)/sizeof(data->buf[0]))
2809 error = block_mouse_data(sc, &command_byte);
2812 if ((data->len = get_mouse_status(sc->kbdc, data->buf,
2813 (cmd == MOUSE_READDATA) ? 1 : 0, data->len)) <= 0)
2815 unblock_mouse_data(sc, command_byte);
2818 #if (defined(MOUSE_SETRESOLUTION))
2819 case MOUSE_SETRESOLUTION:
2820 mode.resolution = *(int *)addr;
2821 if (mode.resolution >= UCHAR_MAX)
2823 else if (mode.resolution >= 200)
2824 mode.resolution = MOUSE_RES_HIGH;
2825 else if (mode.resolution >= 100)
2826 mode.resolution = MOUSE_RES_MEDIUMHIGH;
2827 else if (mode.resolution >= 50)
2828 mode.resolution = MOUSE_RES_MEDIUMLOW;
2829 else if (mode.resolution > 0)
2830 mode.resolution = MOUSE_RES_LOW;
2831 if (mode.resolution == MOUSE_RES_DEFAULT)
2832 mode.resolution = sc->dflt_mode.resolution;
2833 else if (mode.resolution == -1)
2834 mode.resolution = sc->mode.resolution;
2835 else if (mode.resolution < 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */
2836 mode.resolution = MOUSE_RES_LOW - mode.resolution;
2838 error = block_mouse_data(sc, &command_byte);
2841 sc->mode.resolution =
2842 set_mouse_resolution(sc->kbdc, mode.resolution);
2843 if (sc->mode.resolution != mode.resolution)
2845 unblock_mouse_data(sc, command_byte);
2847 #endif /* MOUSE_SETRESOLUTION */
2849 #if (defined(MOUSE_SETRATE))
2851 mode.rate = *(int *)addr;
2852 if (mode.rate > UCHAR_MAX)
2855 mode.rate = sc->dflt_mode.rate;
2856 else if (mode.rate < 0)
2857 mode.rate = sc->mode.rate;
2859 error = block_mouse_data(sc, &command_byte);
2862 sc->mode.rate = set_mouse_sampling_rate(sc->kbdc, mode.rate);
2863 if (sc->mode.rate != mode.rate)
2865 unblock_mouse_data(sc, command_byte);
2867 #endif /* MOUSE_SETRATE */
2869 #if (defined(MOUSE_SETSCALING))
2870 case MOUSE_SETSCALING:
2871 if ((*(int *)addr <= 0) || (*(int *)addr > 2))
2874 error = block_mouse_data(sc, &command_byte);
2877 if (!set_mouse_scaling(sc->kbdc, *(int *)addr))
2879 unblock_mouse_data(sc, command_byte);
2881 #endif /* MOUSE_SETSCALING */
2883 #if (defined(MOUSE_GETHWID))
2885 error = block_mouse_data(sc, &command_byte);
2888 sc->hw.hwid &= ~0x00ff;
2889 sc->hw.hwid |= get_aux_id(sc->kbdc);
2890 *(int *)addr = sc->hw.hwid & 0x00ff;
2891 unblock_mouse_data(sc, command_byte);
2893 #endif /* MOUSE_GETHWID */
2899 error = fsetown(*(int *)addr, &sc->async);
2902 *(int *) addr = fgetown(&sc->async);
2912 psmtimeout(void *arg)
2914 struct psm_softc *sc;
2917 sc = (struct psm_softc *)arg;
2919 if (sc->watchdog && kbdc_lock(sc->kbdc, TRUE)) {
2920 VLOG(6, (LOG_DEBUG, "psm%d: lost interrupt?\n", sc->unit));
2922 kbdc_lock(sc->kbdc, FALSE);
2924 sc->watchdog = TRUE;
2926 callout_reset(&sc->callout, hz, psmtimeout, sc);
2929 /* Add all sysctls under the debug.psm and hw.psm nodes */
2930 static SYSCTL_NODE(_debug, OID_AUTO, psm, CTLFLAG_RD, 0, "ps/2 mouse");
2931 static SYSCTL_NODE(_hw, OID_AUTO, psm, CTLFLAG_RD, 0, "ps/2 mouse");
2933 SYSCTL_INT(_debug_psm, OID_AUTO, loglevel, CTLFLAG_RWTUN, &verbose, 0,
2936 static int psmhz = 20;
2937 SYSCTL_INT(_debug_psm, OID_AUTO, hz, CTLFLAG_RW, &psmhz, 0,
2938 "Frequency of the softcallout (in hz)");
2939 static int psmerrsecs = 2;
2940 SYSCTL_INT(_debug_psm, OID_AUTO, errsecs, CTLFLAG_RW, &psmerrsecs, 0,
2941 "Number of seconds during which packets will dropped after a sync error");
2942 static int psmerrusecs = 0;
2943 SYSCTL_INT(_debug_psm, OID_AUTO, errusecs, CTLFLAG_RW, &psmerrusecs, 0,
2944 "Microseconds to add to psmerrsecs");
2945 static int psmsecs = 0;
2946 SYSCTL_INT(_debug_psm, OID_AUTO, secs, CTLFLAG_RW, &psmsecs, 0,
2947 "Max number of seconds between soft interrupts");
2948 static int psmusecs = 500000;
2949 SYSCTL_INT(_debug_psm, OID_AUTO, usecs, CTLFLAG_RW, &psmusecs, 0,
2950 "Microseconds to add to psmsecs");
2951 static int pkterrthresh = 2;
2952 SYSCTL_INT(_debug_psm, OID_AUTO, pkterrthresh, CTLFLAG_RW, &pkterrthresh, 0,
2953 "Number of error packets allowed before reinitializing the mouse");
2955 SYSCTL_INT(_hw_psm, OID_AUTO, tap_enabled, CTLFLAG_RWTUN, &tap_enabled, 0,
2956 "Enable tap and drag gestures");
2957 static int tap_threshold = PSM_TAP_THRESHOLD;
2958 SYSCTL_INT(_hw_psm, OID_AUTO, tap_threshold, CTLFLAG_RW, &tap_threshold, 0,
2959 "Button tap threshold");
2960 static int tap_timeout = PSM_TAP_TIMEOUT;
2961 SYSCTL_INT(_hw_psm, OID_AUTO, tap_timeout, CTLFLAG_RW, &tap_timeout, 0,
2962 "Tap timeout for touchpads");
2965 SYSCTL_INT(_hw_psm, OID_AUTO, synaptics_support, CTLFLAG_RDTUN,
2966 &synaptics_support, 0, "Enable support for Synaptics touchpads");
2968 SYSCTL_INT(_hw_psm, OID_AUTO, trackpoint_support, CTLFLAG_RDTUN,
2969 &trackpoint_support, 0, "Enable support for IBM/Lenovo TrackPoint");
2971 SYSCTL_INT(_hw_psm, OID_AUTO, elantech_support, CTLFLAG_RDTUN,
2972 &elantech_support, 0, "Enable support for Elantech touchpads");
2977 struct psm_softc *sc = arg;
2982 if (aux_mux_is_enabled(sc->kbdc))
2983 VLOG(2, (LOG_DEBUG, "psmintr: active multiplexing mode is not "
2986 /* read until there is nothing to read */
2987 while((c = read_aux_data_no_wait(sc->kbdc)) != -1) {
2988 pb = &sc->pqueue[sc->pqueue_end];
2990 /* discard the byte if the device is not open */
2991 if (!(sc->state & (PSM_OPEN | PSM_EV_OPEN_R | PSM_EV_OPEN_A)))
2994 getmicrouptime(&now);
2995 if ((pb->inputbytes > 0) &&
2996 timevalcmp(&now, &sc->inputtimeout, >)) {
2997 VLOG(3, (LOG_DEBUG, "psmintr: delay too long; "
2998 "resetting byte count\n"));
3003 sc->inputtimeout.tv_sec = PSM_INPUT_TIMEOUT / 1000000;
3004 sc->inputtimeout.tv_usec = PSM_INPUT_TIMEOUT % 1000000;
3005 timevaladd(&sc->inputtimeout, &now);
3007 pb->ipacket[pb->inputbytes++] = c;
3009 if (sc->mode.level == PSM_LEVEL_NATIVE) {
3010 VLOG(4, (LOG_DEBUG, "psmintr: %02x\n", pb->ipacket[0]));
3015 if (pb->inputbytes < sc->mode.packetsize)
3019 "psmintr: %02x %02x %02x %02x %02x %02x\n",
3020 pb->ipacket[0], pb->ipacket[1], pb->ipacket[2],
3021 pb->ipacket[3], pb->ipacket[4], pb->ipacket[5]));
3026 if ((sc->flags & PSM_NEED_SYNCBITS) != 0) {
3027 sc->mode.syncmask[1] = (c & sc->mode.syncmask[0]);
3028 sc->flags &= ~PSM_NEED_SYNCBITS;
3030 "psmintr: Sync bytes now %04x,%04x\n",
3031 sc->mode.syncmask[0], sc->mode.syncmask[1]));
3032 } else if ((sc->config & PSM_CONFIG_NOCHECKSYNC) == 0 &&
3033 (c & sc->mode.syncmask[0]) != sc->mode.syncmask[1]) {
3034 VLOG(3, (LOG_DEBUG, "psmintr: out of sync "
3035 "(%04x != %04x) %d cmds since last error.\n",
3036 c & sc->mode.syncmask[0], sc->mode.syncmask[1],
3037 sc->cmdcount - sc->lasterr));
3038 sc->lasterr = sc->cmdcount;
3040 * The sync byte test is a weak measure of packet
3041 * validity. Conservatively discard any input yet
3042 * to be seen by userland when we detect a sync
3043 * error since there is a good chance some of
3044 * the queued packets have undetected errors.
3047 if (sc->syncerrors == 0)
3050 sc->lastinputerr = now;
3051 if (sc->syncerrors >= sc->mode.packetsize * 2 ||
3052 sc->pkterrors >= pkterrthresh) {
3054 * If we've failed to find a single sync byte
3055 * in 2 packets worth of data, or we've seen
3056 * persistent packet errors during the
3057 * validation period, reinitialize the mouse
3058 * in hopes of returning it to the expected
3062 "psmintr: reset the mouse.\n"));
3063 reinitialize(sc, TRUE);
3064 } else if (sc->syncerrors == sc->mode.packetsize) {
3066 * Try a soft reset after searching for a sync
3067 * byte through a packet length of bytes.
3070 "psmintr: re-enable the mouse.\n"));
3072 disable_aux_dev(sc->kbdc);
3073 enable_aux_dev(sc->kbdc);
3076 "psmintr: discard a byte (%d)\n",
3079 bcopy(&pb->ipacket[1], &pb->ipacket[0],
3086 * We have what appears to be a valid packet.
3087 * Reset the error counters.
3092 * Drop even good packets if they occur within a timeout
3093 * period of a sync error. This allows the detection of
3094 * a change in the mouse's packet mode without exposing
3095 * erratic mouse behavior to the user. Some KVMs forget
3096 * enhanced mouse modes during switch events.
3098 if (!timeelapsed(&sc->lastinputerr, psmerrsecs, psmerrusecs,
3105 * Now that we're out of the validation period, reset
3106 * the packet error count.
3112 if (++sc->pqueue_end >= PSM_PACKETQUEUE)
3115 * If we've filled the queue then call the softintr ourselves,
3116 * otherwise schedule the interrupt for later.
3118 if (!timeelapsed(&sc->lastsoftintr, psmsecs, psmusecs, &now) ||
3119 (sc->pqueue_end == sc->pqueue_start)) {
3120 if ((sc->state & PSM_SOFTARMED) != 0) {
3121 sc->state &= ~PSM_SOFTARMED;
3122 callout_stop(&sc->softcallout);
3125 } else if ((sc->state & PSM_SOFTARMED) == 0) {
3126 sc->state |= PSM_SOFTARMED;
3127 callout_reset(&sc->softcallout,
3128 psmhz < 1 ? 1 : (hz/psmhz), psmsoftintr, arg);
3134 proc_mmanplus(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
3135 int *x, int *y, int *z)
3139 * PS2++ protocol packet
3141 * b7 b6 b5 b4 b3 b2 b1 b0
3142 * byte 1: * 1 p3 p2 1 * * *
3143 * byte 2: c1 c2 p1 p0 d1 d0 1 0
3145 * p3-p0: packet type
3146 * c1, c2: c1 & c2 == 1, if p2 == 0
3147 * c1 & c2 == 0, if p2 == 1
3149 * packet type: 0 (device type)
3150 * See comments in enable_mmanplus() below.
3152 * packet type: 1 (wheel data)
3154 * b7 b6 b5 b4 b3 b2 b1 b0
3155 * byte 3: h * B5 B4 s d2 d1 d0
3157 * h: 1, if horizontal roller data
3158 * 0, if vertical roller data
3159 * B4, B5: button 4 and 5
3161 * d2-d0: roller data
3163 * packet type: 2 (reserved)
3165 if (((pb->ipacket[0] & MOUSE_PS2PLUS_SYNCMASK) == MOUSE_PS2PLUS_SYNC) &&
3166 (abs(*x) > 191) && MOUSE_PS2PLUS_CHECKBITS(pb->ipacket)) {
3168 * the extended data packet encodes button
3171 switch (MOUSE_PS2PLUS_PACKET_TYPE(pb->ipacket)) {
3173 /* wheel data packet */
3175 if (pb->ipacket[2] & 0x80) {
3176 /* XXX horizontal roller count - ignore it */
3179 /* vertical roller count */
3180 *z = (pb->ipacket[2] & MOUSE_PS2PLUS_ZNEG) ?
3181 (pb->ipacket[2] & 0x0f) - 16 :
3182 (pb->ipacket[2] & 0x0f);
3184 ms->button |= (pb->ipacket[2] &
3185 MOUSE_PS2PLUS_BUTTON4DOWN) ?
3186 MOUSE_BUTTON4DOWN : 0;
3187 ms->button |= (pb->ipacket[2] &
3188 MOUSE_PS2PLUS_BUTTON5DOWN) ?
3189 MOUSE_BUTTON5DOWN : 0;
3193 * this packet type is reserved by
3197 * IBM ScrollPoint Mouse uses this
3198 * packet type to encode both vertical
3199 * and horizontal scroll movement.
3202 /* horizontal count */
3203 if (pb->ipacket[2] & 0x0f)
3204 *z = (pb->ipacket[2] & MOUSE_SPOINT_WNEG) ?
3206 /* vertical count */
3207 if (pb->ipacket[2] & 0xf0)
3208 *z = (pb->ipacket[2] & MOUSE_SPOINT_ZNEG) ?
3212 /* device type packet - shouldn't happen */
3216 ms->button = ms->obutton;
3217 VLOG(1, (LOG_DEBUG, "psmintr: unknown PS2++ packet "
3218 "type %d: 0x%02x 0x%02x 0x%02x\n",
3219 MOUSE_PS2PLUS_PACKET_TYPE(pb->ipacket),
3220 pb->ipacket[0], pb->ipacket[1], pb->ipacket[2]));
3224 /* preserve button states */
3225 ms->button |= ms->obutton & MOUSE_EXTBUTTONS;
3230 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
3231 int *x, int *y, int *z)
3233 static int touchpad_buttons;
3234 static int guest_buttons;
3235 static int ew_finger_count;
3236 static finger_t f[PSM_FINGERS];
3237 int w, id, nfingers, palm, ewcode, extended_buttons, clickpad_pressed;
3239 extended_buttons = 0;
3241 /* TouchPad PS/2 absolute mode message format with capFourButtons:
3243 * Bits: 7 6 5 4 3 2 1 0 (LSB)
3244 * ------------------------------------------------
3245 * ipacket[0]: 1 0 W3 W2 0 W1 R L
3246 * ipacket[1]: Yb Ya Y9 Y8 Xb Xa X9 X8
3247 * ipacket[2]: Z7 Z6 Z5 Z4 Z3 Z2 Z1 Z0
3248 * ipacket[3]: 1 1 Yc Xc 0 W0 D^R U^L
3249 * ipacket[4]: X7 X6 X5 X4 X3 X2 X1 X0
3250 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
3253 * L: left physical mouse button
3254 * R: right physical mouse button
3262 * Without capFourButtons but with nExtendeButtons and/or capMiddle
3264 * Bits: 7 6 5 4 3 2 1 0 (LSB)
3265 * ------------------------------------------------------
3266 * ipacket[3]: 1 1 Yc Xc 0 W0 E^R M^L
3267 * ipacket[4]: X7 X6 X5 X4 X3|b7 X2|b5 X1|b3 X0|b1
3268 * ipacket[5]: Y7 Y6 Y5 Y4 Y3|b8 Y2|b6 Y1|b4 Y0|b2
3271 * M: Middle physical mouse button
3272 * E: Extended mouse buttons reported instead of low bits of X and Y
3273 * b1-b8: Extended mouse buttons
3274 * Only ((nExtendedButtons + 1) >> 1) bits are used in packet
3275 * 4 and 5, for reading X and Y value they should be zeroed.
3277 * Absolute reportable limits: 0 - 6143.
3278 * Typical bezel limits: 1472 - 5472.
3279 * Typical edge marings: 1632 - 5312.
3281 * w = 3 Passthrough Packet
3283 * Byte 2,5,6 == Byte 1,2,3 of "Guest"
3286 if (!synaptics_support)
3289 /* Sanity check for out of sync packets. */
3290 if ((pb->ipacket[0] & 0xc8) != 0x80 ||
3291 (pb->ipacket[3] & 0xc8) != 0xc0)
3295 ms->button = ms->obutton;
3300 * z = 0 No finger contact
3301 * z = 10 Finger hovering near the pad
3302 * z = 30 Very light finger contact
3303 * z = 80 Normal finger contact
3304 * z = 110 Very heavy finger contact
3305 * z = 200 Finger lying flat on pad surface
3306 * z = 255 Maximum reportable Z
3308 *z = pb->ipacket[2];
3311 * Finger width value
3313 * w = 0 Two finger on the pad (capMultiFinger needed)
3314 * w = 1 Three or more fingers (capMultiFinger needed)
3315 * w = 2 Pen (instead of finger) (capPen needed)
3316 * w = 3 Reserved (passthrough?)
3317 * w = 4-7 Finger of normal width (capPalmDetect needed)
3318 * w = 8-14 Very wide finger or palm (capPalmDetect needed)
3319 * w = 15 Maximum reportable width (capPalmDetect needed)
3321 /* XXX Is checking capExtended enough? */
3322 if (sc->synhw.capExtended)
3323 w = ((pb->ipacket[0] & 0x30) >> 2) |
3324 ((pb->ipacket[0] & 0x04) >> 1) |
3325 ((pb->ipacket[3] & 0x04) >> 2);
3327 /* Assume a finger of regular width. */
3334 * Handle packets from the guest device. See:
3335 * Synaptics PS/2 TouchPad Interfacing Guide, Section 5.1
3337 if (sc->synhw.capPassthrough || sc->muxport != PSM_NOMUX) {
3338 *x = ((pb->ipacket[1] & 0x10) ?
3339 pb->ipacket[4] - 256 : pb->ipacket[4]);
3340 *y = ((pb->ipacket[1] & 0x20) ?
3341 pb->ipacket[5] - 256 : pb->ipacket[5]);
3345 if (pb->ipacket[1] & 0x01)
3346 guest_buttons |= MOUSE_BUTTON1DOWN;
3347 if (pb->ipacket[1] & 0x04)
3348 guest_buttons |= MOUSE_BUTTON2DOWN;
3349 if (pb->ipacket[1] & 0x02)
3350 guest_buttons |= MOUSE_BUTTON3DOWN;
3351 #ifdef EVDEV_SUPPORT
3352 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
3353 evdev_push_rel(sc->evdev_r, REL_X, *x);
3354 evdev_push_rel(sc->evdev_r, REL_Y, -*y);
3355 evdev_push_mouse_btn(sc->evdev_r,
3357 evdev_sync(sc->evdev_r);
3360 ms->button = touchpad_buttons | guest_buttons |
3361 sc->extended_buttons;
3366 /* Handle Extended W mode packets */
3367 ewcode = (pb->ipacket[5] & 0xf0) >> 4;
3371 /* Secondary finger */
3372 if (sc->synhw.capAdvancedGestures)
3374 .x = (((pb->ipacket[4] & 0x0f) << 8) |
3375 pb->ipacket[1]) << 1,
3376 .y = (((pb->ipacket[4] & 0xf0) << 4) |
3377 pb->ipacket[2]) << 1,
3378 .p = ((pb->ipacket[3] & 0x30) |
3379 (pb->ipacket[5] & 0x0f)) << 1,
3380 .w = PSM_FINGER_DEFAULT_W,
3381 .flags = PSM_FINGER_FUZZY,
3383 else if (sc->synhw.capReportsV)
3385 .x = (((pb->ipacket[4] & 0x0f) << 8) |
3386 (pb->ipacket[1] & 0xfe)) << 1,
3387 .y = (((pb->ipacket[4] & 0xf0) << 4) |
3388 (pb->ipacket[2] & 0xfe)) << 1,
3389 .p = ((pb->ipacket[3] & 0x30) |
3390 (pb->ipacket[5] & 0x0e)) << 1,
3391 .w = (((pb->ipacket[5] & 0x01) << 2) |
3392 ((pb->ipacket[2] & 0x01) << 1) |
3393 (pb->ipacket[1] & 0x01)) + 8,
3394 .flags = PSM_FINGER_FUZZY,
3398 ew_finger_count = pb->ipacket[1] & 0x0f;
3406 if (sc->synhw.capReportsV && ew_finger_count > 3) {
3407 nfingers = ew_finger_count;
3419 if (sc->syninfo.touchpad_off)
3422 /* Button presses */
3423 touchpad_buttons = 0;
3424 if (pb->ipacket[0] & 0x01)
3425 touchpad_buttons |= MOUSE_BUTTON1DOWN;
3426 if (pb->ipacket[0] & 0x02)
3427 touchpad_buttons |= MOUSE_BUTTON3DOWN;
3429 if (sc->synhw.capExtended && sc->synhw.capFourButtons) {
3430 if ((pb->ipacket[3] ^ pb->ipacket[0]) & 0x01)
3431 touchpad_buttons |= MOUSE_BUTTON4DOWN;
3432 if ((pb->ipacket[3] ^ pb->ipacket[0]) & 0x02)
3433 touchpad_buttons |= MOUSE_BUTTON5DOWN;
3434 } else if (sc->synhw.capExtended && sc->synhw.capMiddle &&
3435 !sc->synhw.capClickPad) {
3437 if ((pb->ipacket[0] ^ pb->ipacket[3]) & 0x01)
3438 touchpad_buttons |= MOUSE_BUTTON2DOWN;
3439 } else if (sc->synhw.capExtended && (sc->synhw.nExtendedButtons > 0)) {
3440 /* Extended Buttons */
3441 if ((pb->ipacket[0] ^ pb->ipacket[3]) & 0x02) {
3442 if (sc->syninfo.directional_scrolls) {
3443 if (pb->ipacket[4] & 0x01)
3444 extended_buttons |= MOUSE_BUTTON4DOWN;
3445 if (pb->ipacket[5] & 0x01)
3446 extended_buttons |= MOUSE_BUTTON5DOWN;
3447 if (pb->ipacket[4] & 0x02)
3448 extended_buttons |= MOUSE_BUTTON6DOWN;
3449 if (pb->ipacket[5] & 0x02)
3450 extended_buttons |= MOUSE_BUTTON7DOWN;
3452 if (pb->ipacket[4] & 0x01)
3453 extended_buttons |= MOUSE_BUTTON1DOWN;
3454 if (pb->ipacket[5] & 0x01)
3455 extended_buttons |= MOUSE_BUTTON3DOWN;
3456 if (pb->ipacket[4] & 0x02)
3457 extended_buttons |= MOUSE_BUTTON2DOWN;
3458 sc->extended_buttons = extended_buttons;
3462 * Zero out bits used by extended buttons to avoid
3463 * misinterpretation of the data absolute position.
3465 * The bits represented by
3467 * (nExtendedButtons + 1) >> 1
3469 * will be masked out in both bytes.
3470 * The mask for n bits is computed with the formula
3476 maskedbits = (sc->synhw.nExtendedButtons + 1) >> 1;
3477 mask = (1 << maskedbits) - 1;
3478 #ifdef EVDEV_SUPPORT
3480 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
3481 if (sc->synhw.capPassthrough) {
3482 evdev_push_mouse_btn(sc->evdev_r,
3484 evdev_sync(sc->evdev_r);
3486 for (i = 0; i < maskedbits; i++) {
3487 evdev_push_key(sc->evdev_a,
3489 pb->ipacket[4] & (1 << i));
3490 evdev_push_key(sc->evdev_a,
3492 pb->ipacket[5] & (1 << i));
3496 pb->ipacket[4] &= ~(mask);
3497 pb->ipacket[5] &= ~(mask);
3498 } else if (!sc->syninfo.directional_scrolls &&
3499 !sc->gesture.in_vscroll) {
3501 * Keep reporting MOUSE DOWN until we get a new packet
3502 * indicating otherwise.
3504 extended_buttons |= sc->extended_buttons;
3508 if (sc->synhw.capReportsV && nfingers > 1)
3510 .x = ((pb->ipacket[3] & 0x10) << 8) |
3511 ((pb->ipacket[1] & 0x0f) << 8) |
3512 (pb->ipacket[4] & 0xfd),
3513 .y = ((pb->ipacket[3] & 0x20) << 7) |
3514 ((pb->ipacket[1] & 0xf0) << 4) |
3515 (pb->ipacket[5] & 0xfd),
3517 .w = (((pb->ipacket[2] & 0x01) << 2) |
3518 (pb->ipacket[5] & 0x02) |
3519 ((pb->ipacket[4] & 0x02) >> 1)) + 8,
3520 .flags = PSM_FINGER_FUZZY,
3524 .x = ((pb->ipacket[3] & 0x10) << 8) |
3525 ((pb->ipacket[1] & 0x0f) << 8) |
3527 .y = ((pb->ipacket[3] & 0x20) << 7) |
3528 ((pb->ipacket[1] & 0xf0) << 4) |
3532 .flags = nfingers > 1 ? PSM_FINGER_FUZZY : 0,
3535 /* Ignore hovering and unmeasurable touches */
3536 if (f[0].p < sc->syninfo.min_pressure || f[0].x < 2)
3539 /* Handle ClickPad */
3540 if (sc->synhw.capClickPad) {
3541 clickpad_pressed = (pb->ipacket[0] ^ pb->ipacket[3]) & 0x01;
3542 if (sc->synhw.forcePad) {
3544 * Forcepads erroneously report button click if there
3545 * are 2 or more fingers on the touchpad breaking
3546 * multifinger gestures. To workaround this start
3547 * reporting a click only after 4 consecutive single
3548 * touch packets has been received.
3549 * Skip these packets in case more contacts appear.
3556 if (clickpad_pressed && sc->fpcount < INT_MAX)
3560 if (!clickpad_pressed)
3562 if (sc->fpcount >= sc->syninfo.window_min)
3563 touchpad_buttons |= MOUSE_BUTTON1DOWN;
3565 } else if (clickpad_pressed)
3566 touchpad_buttons |= MOUSE_BUTTON1DOWN;
3569 for (id = 0; id < PSM_FINGERS; id++)
3571 PSM_FINGER_RESET(f[id]);
3573 #ifdef EVDEV_SUPPORT
3574 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
3575 for (id = 0; id < PSM_FINGERS; id++) {
3576 if (PSM_FINGER_IS_SET(f[id]))
3577 psm_push_mt_finger(sc, id, &f[id]);
3579 psm_release_mt_slot(sc->evdev_a, id);
3581 evdev_push_key(sc->evdev_a, BTN_TOUCH, nfingers > 0);
3582 evdev_push_nfingers(sc->evdev_a, nfingers);
3584 psm_push_st_finger(sc, &f[0]);
3586 evdev_push_abs(sc->evdev_a, ABS_PRESSURE, 0);
3587 evdev_push_mouse_btn(sc->evdev_a, touchpad_buttons);
3588 if (sc->synhw.capExtended && sc->synhw.capFourButtons) {
3589 evdev_push_key(sc->evdev_a, BTN_FORWARD,
3590 touchpad_buttons & MOUSE_BUTTON4DOWN);
3591 evdev_push_key(sc->evdev_a, BTN_BACK,
3592 touchpad_buttons & MOUSE_BUTTON5DOWN);
3594 evdev_sync(sc->evdev_a);
3598 ms->button = touchpad_buttons;
3600 palm = psmpalmdetect(sc, &f[0], nfingers);
3602 /* Palm detection doesn't terminate the current action. */
3604 psmgestures(sc, &f[0], nfingers, ms);
3606 for (id = 0; id < PSM_FINGERS; id++)
3607 psmsmoother(sc, &f[id], id, ms, x, y);
3611 ms->button = ms->obutton;
3615 ms->button |= extended_buttons | guest_buttons;
3619 * Use the extra buttons as a scrollwheel
3621 * XXX X.Org uses the Z axis for vertical wheel only,
3622 * whereas moused(8) understands special values to differ
3623 * vertical and horizontal wheels.
3625 * xf86-input-mouse needs therefore a small patch to
3626 * understand these special values. Without it, the
3627 * horizontal wheel acts as a vertical wheel in X.Org.
3629 * That's why the horizontal wheel is disabled by
3632 if (ms->button & MOUSE_BUTTON4DOWN)
3634 else if (ms->button & MOUSE_BUTTON5DOWN)
3636 else if (ms->button & MOUSE_BUTTON6DOWN)
3638 else if (ms->button & MOUSE_BUTTON7DOWN)
3642 ms->button &= ~(MOUSE_BUTTON4DOWN | MOUSE_BUTTON5DOWN |
3643 MOUSE_BUTTON6DOWN | MOUSE_BUTTON7DOWN);
3649 proc_synaptics_mux(struct psm_softc *sc, packetbuf_t *pb)
3654 * Convert 3-byte interleaved mixture of Synaptics and generic mouse
3655 * packets into plain 6-byte Synaptics packet protocol.
3656 * While in hidden multiplexing mode KBC does some editing of the
3657 * packet stream. It remembers the button bits from the last packet
3658 * received from each device, and replaces the button bits of every
3659 * packet with the logical OR of all devices’ most recent button bits.
3660 * This button crosstalk should be filtered out as Synaptics and
3661 * generic mouse encode middle button presses in a different way.
3663 switch (pb->ipacket[0] & 0xc0) {
3664 case 0x80: /* First 3 bytes of Synaptics packet */
3665 bcopy(pb->ipacket, sc->muxsave, 3);
3666 /* Compute middle mouse button supression timeout. */
3667 sc->muxmidtimeout.tv_sec = 0;
3668 sc->muxmidtimeout.tv_usec = 50000; /* ~2-3 ints */
3669 timevaladd(&sc->muxmidtimeout, &sc->lastsoftintr);
3672 case 0xc0: /* Second 3 bytes of Synaptics packet */
3673 /* Join two 3-bytes absolute packets */
3674 bcopy(pb->ipacket, pb->ipacket + 3, 3);
3675 bcopy(sc->muxsave, pb->ipacket, 3);
3676 /* Prefer trackpoint buttons over touchpad's */
3677 pb->ipacket[0] &= ~(0x08 | sc->muxmsbuttons);
3678 pb->ipacket[3] &= ~(0x08 | sc->muxmsbuttons);
3679 butt = (pb->ipacket[3] & 0x03) << 2 | (pb->ipacket[0] & 0x03);
3680 /* Add hysteresis to remove spurious middle button events */
3681 if (butt != sc->muxtpbuttons && sc->fpcount < 1) {
3682 pb->ipacket[0] &= 0xfc;
3683 pb->ipacket[0] |= sc->muxtpbuttons & 0x03;
3684 pb->ipacket[3] &= 0xfc;
3685 pb->ipacket[3] |= sc->muxtpbuttons >> 2 & 0x03;
3689 sc->muxtpbuttons = butt;
3691 /* Filter out impossible w induced by middle trackpoint btn */
3692 if (sc->synhw.capExtended && !sc->synhw.capPassthrough &&
3693 (pb->ipacket[0] & 0x34) == 0x04 &&
3694 (pb->ipacket[3] & 0x04) == 0x04) {
3695 pb->ipacket[0] &= 0xfb;
3696 pb->ipacket[3] &= 0xfb;
3698 sc->muxsave[0] &= 0x30;
3701 default: /* Generic mouse (Trackpoint) packet */
3702 /* Filter out middle button events induced by some w values */
3703 if (sc->muxmsbuttons & 0x03 || pb->ipacket[0] & 0x03 ||
3704 (timevalcmp(&sc->lastsoftintr, &sc->muxmidtimeout, <=) &&
3705 (sc->muxsave[0] & 0x30 || sc->muxsave[2] > 8)))
3706 pb->ipacket[0] &= 0xfb;
3707 sc->muxmsbuttons = pb->ipacket[0] & 0x07;
3708 /* Convert to Synaptics pass-through protocol */
3709 pb->ipacket[4] = pb->ipacket[1];
3710 pb->ipacket[5] = pb->ipacket[2];
3711 pb->ipacket[1] = pb->ipacket[0];
3713 pb->ipacket[0] = 0x84 | (sc->muxtpbuttons & 0x03);
3714 pb->ipacket[3] = 0xc4 | (sc->muxtpbuttons >> 2 & 0x03);
3717 VLOG(4, (LOG_DEBUG, "synaptics: %02x %02x %02x %02x %02x %02x\n",
3718 pb->ipacket[0], pb->ipacket[1], pb->ipacket[2],
3719 pb->ipacket[3], pb->ipacket[4], pb->ipacket[5]));
3721 pb->inputbytes = MOUSE_SYNAPTICS_PACKETSIZE;
3726 psmpalmdetect(struct psm_softc *sc, finger_t *f, int nfingers)
3729 ((sc->synhw.capMultiFinger || sc->synhw.capAdvancedGestures) &&
3730 !sc->synhw.capReportsV && nfingers > 1) ||
3731 (sc->synhw.capReportsV && nfingers > 2) ||
3732 (sc->synhw.capPalmDetect && f->w <= sc->syninfo.max_width) ||
3733 (!sc->synhw.capPalmDetect && f->p <= sc->syninfo.max_pressure) ||
3734 (sc->synhw.capPen && f->flags & PSM_FINGER_IS_PEN))) {
3736 * We consider the packet irrelevant for the current
3738 * - the width isn't comprised in:
3740 * - the pressure isn't comprised in:
3741 * [min_pressure; max_pressure]
3742 * - pen aren't supported but PSM_FINGER_IS_PEN is set
3744 VLOG(2, (LOG_DEBUG, "synaptics: palm detected! (%d)\n", f->w));
3751 psmgestures(struct psm_softc *sc, finger_t *fingers, int nfingers,
3754 smoother_t *smoother;
3757 int y_ok, center_button, center_x, right_button, right_x, i;
3760 smoother = &sc->smoother[0];
3761 gest = &sc->gesture;
3763 /* Find first active finger. */
3765 for (i = 0; i < PSM_FINGERS; i++) {
3766 if (PSM_FINGER_IS_SET(fingers[i])) {
3768 smoother = &sc->smoother[i];
3775 * Check pressure to detect a real wanted action on the
3778 if (f->p >= sc->syninfo.min_pressure) {
3781 int start_x, start_y;
3783 int margin_top, margin_right, margin_bottom, margin_left;
3784 int window_min, window_max;
3785 int vscroll_hor_area, vscroll_ver_area;
3786 int two_finger_scroll;
3790 /* XXX Verify values? */
3791 margin_top = sc->syninfo.margin_top;
3792 margin_right = sc->syninfo.margin_right;
3793 margin_bottom = sc->syninfo.margin_bottom;
3794 margin_left = sc->syninfo.margin_left;
3795 window_min = sc->syninfo.window_min;
3796 window_max = sc->syninfo.window_max;
3797 vscroll_hor_area = sc->syninfo.vscroll_hor_area;
3798 vscroll_ver_area = sc->syninfo.vscroll_ver_area;
3799 two_finger_scroll = sc->syninfo.two_finger_scroll;
3800 max_x = sc->syninfo.max_x;
3801 max_y = sc->syninfo.max_y;
3803 /* Read current absolute position. */
3808 * Limit the coordinates to the specified margins because
3809 * this area isn't very reliable.
3811 if (x0 <= margin_left)
3813 else if (x0 >= max_x - margin_right)
3814 x0 = max_x - margin_right;
3815 if (y0 <= margin_bottom)
3817 else if (y0 >= max_y - margin_top)
3818 y0 = max_y - margin_top;
3820 VLOG(3, (LOG_DEBUG, "synaptics: ipacket: [%d, %d], %d, %d\n",
3821 x0, y0, f->p, f->w));
3824 * If the action is just beginning, init the structure and
3825 * compute tap timeout.
3827 if (!(sc->flags & PSM_FLAGS_FINGERDOWN)) {
3828 VLOG(3, (LOG_DEBUG, "synaptics: ----\n"));
3830 /* Initialize queue. */
3831 gest->window_min = window_min;
3833 /* Reset pressure peak. */
3836 /* Reset fingers count. */
3837 gest->fingers_nb = 0;
3839 /* Reset virtual scrolling state. */
3840 gest->in_vscroll = 0;
3842 /* Compute tap timeout. */
3843 if (tap_enabled != 0) {
3844 gest->taptimeout = (struct timeval) {
3845 .tv_sec = tap_timeout / 1000000,
3846 .tv_usec = tap_timeout % 1000000,
3849 &gest->taptimeout, &sc->lastsoftintr);
3851 timevalclear(&gest->taptimeout);
3853 sc->flags |= PSM_FLAGS_FINGERDOWN;
3855 /* Smoother has not been reset yet */
3860 queue_len = smoother->queue_len + 1;
3861 start_x = smoother->start_x;
3862 start_y = smoother->start_y;
3865 /* Process ClickPad softbuttons */
3866 if (sc->synhw.capClickPad && ms->button & MOUSE_BUTTON1DOWN) {
3867 y_ok = sc->syninfo.softbuttons_y >= 0 ?
3868 start_y < sc->syninfo.softbuttons_y :
3869 start_y > max_y + sc->syninfo.softbuttons_y;
3871 center_button = MOUSE_BUTTON2DOWN;
3872 center_x = sc->syninfo.softbutton2_x;
3873 right_button = MOUSE_BUTTON3DOWN;
3874 right_x = sc->syninfo.softbutton3_x;
3876 if (center_x > 0 && right_x > 0 && center_x > right_x) {
3877 center_button = MOUSE_BUTTON3DOWN;
3878 center_x = sc->syninfo.softbutton3_x;
3879 right_button = MOUSE_BUTTON2DOWN;
3880 right_x = sc->syninfo.softbutton2_x;
3883 if (right_x > 0 && start_x > right_x && y_ok)
3884 ms->button = (ms->button &
3885 ~MOUSE_BUTTON1DOWN) | right_button;
3886 else if (center_x > 0 && start_x > center_x && y_ok)
3887 ms->button = (ms->button &
3888 ~MOUSE_BUTTON1DOWN) | center_button;
3891 /* If in tap-hold, add the recorded button. */
3892 if (gest->in_taphold)
3893 ms->button |= gest->tap_button;
3896 * For tap, we keep the maximum number of fingers and the
3897 * pressure peak. Also with multiple fingers, we increase
3898 * the minimum window.
3901 gest->window_min = window_max;
3902 gest->fingers_nb = imax(nfingers, gest->fingers_nb);
3903 gest->zmax = imax(f->p, gest->zmax);
3905 /* Do we have enough packets to consider this a gesture? */
3906 if (queue_len < gest->window_min)
3912 /* Is a scrolling action occurring? */
3913 if (!gest->in_taphold && !ms->button &&
3914 (!gest->in_vscroll || two_finger_scroll)) {
3916 * A scrolling action must not conflict with a tap
3917 * action. Here are the conditions to consider a
3919 * - the action in a configurable area
3920 * - one of the following:
3921 * . the distance between the last packet and the
3922 * first should be above a configurable minimum
3925 dxp = abs(x0 - start_x);
3926 dyp = abs(y0 - start_y);
3928 if (timevalcmp(&sc->lastsoftintr, &gest->taptimeout, >) ||
3929 dxp >= sc->syninfo.vscroll_min_delta ||
3930 dyp >= sc->syninfo.vscroll_min_delta) {
3932 * Handle two finger scrolling.
3933 * Note that we don't rely on fingers_nb
3934 * as that keeps the maximum number of fingers.
3936 if (two_finger_scroll) {
3937 if (nfingers == 2) {
3944 /* Check for horizontal scrolling. */
3945 if ((vscroll_hor_area > 0 &&
3946 start_y <= vscroll_hor_area) ||
3947 (vscroll_hor_area < 0 &&
3949 max_y + vscroll_hor_area))
3950 gest->in_vscroll += 2;
3952 /* Check for vertical scrolling. */
3953 if ((vscroll_ver_area > 0 &&
3954 start_x <= vscroll_ver_area) ||
3955 (vscroll_ver_area < 0 &&
3957 max_x + vscroll_ver_area))
3958 gest->in_vscroll += 1;
3961 /* Avoid conflicts if area overlaps. */
3962 if (gest->in_vscroll >= 3)
3964 (dxp > dyp) ? 2 : 1;
3968 * Reset two finger scrolling when the number of fingers
3969 * is different from two or any button is pressed.
3971 if (two_finger_scroll && gest->in_vscroll != 0 &&
3972 (nfingers != 2 || ms->button))
3973 gest->in_vscroll = 0;
3976 "synaptics: virtual scrolling: %s "
3977 "(direction=%d, dxp=%d, dyp=%d, fingers=%d)\n",
3978 gest->in_vscroll ? "YES" : "NO",
3979 gest->in_vscroll, dxp, dyp,
3982 } else if (sc->flags & PSM_FLAGS_FINGERDOWN) {
3984 * An action is currently taking place but the pressure
3985 * dropped under the minimum, putting an end to it.
3987 int taphold_timeout, dx, dy, tap_max_delta;
3989 dx = abs(smoother->queue[smoother->queue_cursor].x -
3991 dy = abs(smoother->queue[smoother->queue_cursor].y -
3994 /* Max delta is disabled for multi-fingers tap. */
3995 if (gest->fingers_nb > 1)
3996 tap_max_delta = imax(dx, dy);
3998 tap_max_delta = sc->syninfo.tap_max_delta;
4000 sc->flags &= ~PSM_FLAGS_FINGERDOWN;
4002 /* Check for tap. */
4004 "synaptics: zmax=%d, dx=%d, dy=%d, "
4005 "delta=%d, fingers=%d, queue=%d\n",
4006 gest->zmax, dx, dy, tap_max_delta, gest->fingers_nb,
4007 smoother->queue_len));
4008 if (!gest->in_vscroll && gest->zmax >= tap_threshold &&
4009 timevalcmp(&sc->lastsoftintr, &gest->taptimeout, <=) &&
4010 dx <= tap_max_delta && dy <= tap_max_delta &&
4011 smoother->queue_len >= sc->syninfo.tap_min_queue) {
4014 * - the maximum pressure went over tap_threshold
4015 * - the action ended before tap_timeout
4017 * To handle tap-hold, we must delay any button push to
4020 if (gest->in_taphold) {
4022 * This is the second and last tap of a
4023 * double tap action, not a tap-hold.
4025 gest->in_taphold = 0;
4028 * For double-tap to work:
4029 * - no button press is emitted (to
4030 * simulate a button release)
4031 * - PSM_FLAGS_FINGERDOWN is set to
4032 * force the next packet to emit a
4036 "synaptics: button RELEASE: %d\n",
4038 sc->flags |= PSM_FLAGS_FINGERDOWN;
4040 /* Schedule button press on next interrupt */
4041 sc->idletimeout.tv_sec = psmhz > 1 ?
4043 sc->idletimeout.tv_usec = psmhz > 1 ?
4044 1000000 / psmhz : 0;
4047 * This is the first tap: we set the
4048 * tap-hold state and notify the button
4051 gest->in_taphold = 1;
4052 taphold_timeout = sc->syninfo.taphold_timeout;
4053 gest->taptimeout.tv_sec = taphold_timeout /
4055 gest->taptimeout.tv_usec = taphold_timeout %
4057 sc->idletimeout = gest->taptimeout;
4058 timevaladd(&gest->taptimeout,
4061 switch (gest->fingers_nb) {
4075 "synaptics: button PRESS: %d\n",
4077 ms->button |= gest->tap_button;
4081 * Not enough pressure or timeout: reset
4084 if (gest->in_taphold) {
4086 "synaptics: button RELEASE: %d\n",
4088 gest->in_taphold = 0;
4091 "synaptics: not a tap-hold\n"));
4094 } else if (!(sc->flags & PSM_FLAGS_FINGERDOWN) && gest->in_taphold) {
4096 * For a tap-hold to work, the button must remain down at
4097 * least until timeout (where the in_taphold flags will be
4098 * cleared) or during the next action.
4100 if (timevalcmp(&sc->lastsoftintr, &gest->taptimeout, <=)) {
4101 ms->button |= gest->tap_button;
4103 VLOG(2, (LOG_DEBUG, "synaptics: button RELEASE: %d\n",
4105 gest->in_taphold = 0;
4113 psmsmoother(struct psm_softc *sc, finger_t *f, int smoother_id,
4114 mousestatus_t *ms, int *x, int *y)
4116 smoother_t *smoother = &sc->smoother[smoother_id];
4117 gesture_t *gest = &(sc->gesture);
4120 * Check pressure to detect a real wanted action on the
4123 if (f->p >= sc->syninfo.min_pressure) {
4125 int cursor, peer, window;
4126 int dx, dy, dxp, dyp;
4127 int max_width, max_pressure;
4128 int margin_top, margin_right, margin_bottom, margin_left;
4129 int na_top, na_right, na_bottom, na_left;
4130 int window_min, window_max;
4132 int weight_current, weight_previous, weight_len_squared;
4133 int div_min, div_max, div_len;
4134 int vscroll_hor_area, vscroll_ver_area;
4135 int two_finger_scroll;
4137 int len, weight_prev_x, weight_prev_y;
4138 int div_max_x, div_max_y, div_x, div_y;
4143 /* XXX Verify values? */
4144 max_width = sc->syninfo.max_width;
4145 max_pressure = sc->syninfo.max_pressure;
4146 margin_top = sc->syninfo.margin_top;
4147 margin_right = sc->syninfo.margin_right;
4148 margin_bottom = sc->syninfo.margin_bottom;
4149 margin_left = sc->syninfo.margin_left;
4150 na_top = sc->syninfo.na_top;
4151 na_right = sc->syninfo.na_right;
4152 na_bottom = sc->syninfo.na_bottom;
4153 na_left = sc->syninfo.na_left;
4154 window_min = sc->syninfo.window_min;
4155 window_max = sc->syninfo.window_max;
4156 multiplicator = sc->syninfo.multiplicator;
4157 weight_current = sc->syninfo.weight_current;
4158 weight_previous = sc->syninfo.weight_previous;
4159 weight_len_squared = sc->syninfo.weight_len_squared;
4160 div_min = sc->syninfo.div_min;
4161 div_max = sc->syninfo.div_max;
4162 div_len = sc->syninfo.div_len;
4163 vscroll_hor_area = sc->syninfo.vscroll_hor_area;
4164 vscroll_ver_area = sc->syninfo.vscroll_ver_area;
4165 two_finger_scroll = sc->syninfo.two_finger_scroll;
4166 max_x = sc->syninfo.max_x;
4167 max_y = sc->syninfo.max_y;
4168 natural_scroll = sc->syninfo.natural_scroll;
4170 is_fuzzy = (f->flags & PSM_FINGER_FUZZY) != 0;
4172 /* Read current absolute position. */
4177 * Limit the coordinates to the specified margins because
4178 * this area isn't very reliable.
4180 if (x0 <= margin_left)
4182 else if (x0 >= max_x - margin_right)
4183 x0 = max_x - margin_right;
4184 if (y0 <= margin_bottom)
4186 else if (y0 >= max_y - margin_top)
4187 y0 = max_y - margin_top;
4189 /* If the action is just beginning, init the structure. */
4190 if (smoother->active == 0) {
4191 VLOG(3, (LOG_DEBUG, "smoother%d: ---\n", smoother_id));
4193 /* Store the first point of this action. */
4194 smoother->start_x = x0;
4195 smoother->start_y = y0;
4198 /* Initialize queue. */
4199 smoother->queue_cursor = SYNAPTICS_PACKETQUEUE;
4200 smoother->queue_len = 0;
4202 /* Reset average. */
4203 smoother->avg_dx = 0;
4204 smoother->avg_dy = 0;
4206 /* Reset squelch. */
4207 smoother->squelch_x = 0;
4208 smoother->squelch_y = 0;
4210 /* Activate queue */
4211 smoother->active = 1;
4213 /* Calculate the current delta. */
4214 cursor = smoother->queue_cursor;
4215 dx = x0 - smoother->queue[cursor].x;
4216 dy = y0 - smoother->queue[cursor].y;
4219 VLOG(3, (LOG_DEBUG, "smoother%d: ipacket: [%d, %d], %d, %d\n",
4220 smoother_id, x0, y0, f->p, f->w));
4222 /* Queue this new packet. */
4223 cursor = SYNAPTICS_QUEUE_CURSOR(smoother->queue_cursor - 1);
4224 smoother->queue[cursor].x = x0;
4225 smoother->queue[cursor].y = y0;
4226 smoother->queue_cursor = cursor;
4227 if (smoother->queue_len < SYNAPTICS_PACKETQUEUE)
4228 smoother->queue_len++;
4230 "smoother%d: cursor[%d]: x=%d, y=%d, dx=%d, dy=%d\n",
4231 smoother_id, cursor, x0, y0, dx, dy));
4233 /* Do we have enough packets to consider this a movement? */
4234 if (smoother->queue_len < gest->window_min)
4237 weight_prev_x = weight_prev_y = weight_previous;
4238 div_max_x = div_max_y = div_max;
4240 if (gest->in_vscroll) {
4241 /* Dividers are different with virtual scrolling. */
4242 div_min = sc->syninfo.vscroll_div_min;
4243 div_max_x = div_max_y = sc->syninfo.vscroll_div_max;
4246 * There's a lot of noise in coordinates when
4247 * the finger is on the touchpad's borders. When
4248 * using this area, we apply a special weight and
4251 if (x0 <= na_left || x0 >= max_x - na_right) {
4252 weight_prev_x = sc->syninfo.weight_previous_na;
4253 div_max_x = sc->syninfo.div_max_na;
4256 if (y0 <= na_bottom || y0 >= max_y - na_top) {
4257 weight_prev_y = sc->syninfo.weight_previous_na;
4258 div_max_y = sc->syninfo.div_max_na;
4263 * Calculate weights for the average operands and
4264 * the divisor. Both depend on the distance between
4265 * the current packet and a previous one (based on the
4268 window = imin(smoother->queue_len, window_max);
4269 peer = SYNAPTICS_QUEUE_CURSOR(cursor + window - 1);
4270 dxp = abs(x0 - smoother->queue[peer].x) + 1;
4271 dyp = abs(y0 - smoother->queue[peer].y) + 1;
4272 len = (dxp * dxp) + (dyp * dyp);
4273 weight_prev_x = imin(weight_prev_x,
4274 weight_len_squared * weight_prev_x / len);
4275 weight_prev_y = imin(weight_prev_y,
4276 weight_len_squared * weight_prev_y / len);
4278 len = (dxp + dyp) / 2;
4279 div_x = div_len * div_max_x / len;
4280 div_x = imin(div_max_x, div_x);
4281 div_x = imax(div_min, div_x);
4282 div_y = div_len * div_max_y / len;
4283 div_y = imin(div_max_y, div_y);
4284 div_y = imax(div_min, div_y);
4287 "smoother%d: peer=%d, len=%d, weight=%d/%d, div=%d/%d\n",
4288 smoother_id, peer, len, weight_prev_x, weight_prev_y,
4291 /* Compute averages. */
4293 (weight_current * dx * multiplicator +
4294 weight_prev_x * smoother->avg_dx) /
4295 (weight_current + weight_prev_x);
4298 (weight_current * dy * multiplicator +
4299 weight_prev_y * smoother->avg_dy) /
4300 (weight_current + weight_prev_y);
4303 "smoother%d: avg_dx~=%d, avg_dy~=%d\n", smoother_id,
4304 smoother->avg_dx / multiplicator,
4305 smoother->avg_dy / multiplicator));
4307 /* Use these averages to calculate x & y. */
4308 smoother->squelch_x += smoother->avg_dx;
4309 dxp = smoother->squelch_x / (div_x * multiplicator);
4310 smoother->squelch_x = smoother->squelch_x %
4311 (div_x * multiplicator);
4313 smoother->squelch_y += smoother->avg_dy;
4314 dyp = smoother->squelch_y / (div_y * multiplicator);
4315 smoother->squelch_y = smoother->squelch_y %
4316 (div_y * multiplicator);
4318 switch(gest->in_vscroll) {
4319 case 0: /* Pointer movement. */
4320 /* On real<->fuzzy finger switch the x/y pos jumps */
4321 if (is_fuzzy == smoother->is_fuzzy) {
4326 VLOG(3, (LOG_DEBUG, "smoother%d: [%d, %d] -> [%d, %d]\n",
4327 smoother_id, dx, dy, dxp, dyp));
4329 case 1: /* Vertical scrolling. */
4331 if (two_finger_scroll && natural_scroll)
4332 ms->button |= (dyp > 0) ?
4333 MOUSE_BUTTON5DOWN : MOUSE_BUTTON4DOWN;
4335 ms->button |= (dyp > 0) ?
4336 MOUSE_BUTTON4DOWN : MOUSE_BUTTON5DOWN;
4339 case 2: /* Horizontal scrolling. */
4341 if (two_finger_scroll && natural_scroll)
4342 ms->button |= (dxp > 0) ?
4343 MOUSE_BUTTON6DOWN : MOUSE_BUTTON7DOWN;
4345 ms->button |= (dxp > 0) ?
4346 MOUSE_BUTTON7DOWN : MOUSE_BUTTON6DOWN;
4351 smoother->is_fuzzy = is_fuzzy;
4355 * Deactivate queue. Note: We can not just reset queue here
4356 * as these values are still used by gesture processor.
4357 * So postpone reset till next touch.
4359 smoother->active = 0;
4364 proc_elantech(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
4365 int *x, int *y, int *z)
4367 static int touchpad_button, trackpoint_button;
4368 finger_t fn, f[ELANTECH_MAX_FINGERS];
4369 int pkt, id, scale, i, nfingers, mask, palm;
4371 if (!elantech_support)
4374 /* Determine packet format and do a sanity check for out of sync packets. */
4375 if (ELANTECH_PKT_IS_DEBOUNCE(pb, sc->elanhw.hwversion))
4376 pkt = ELANTECH_PKT_NOP;
4377 else if (sc->elanhw.hastrackpoint && ELANTECH_PKT_IS_TRACKPOINT(pb))
4378 pkt = ELANTECH_PKT_TRACKPOINT;
4380 switch (sc->elanhw.hwversion) {
4382 if (!ELANTECH_PKT_IS_V2(pb))
4385 pkt = (pb->ipacket[0] & 0xc0) == 0x80 ?
4386 ELANTECH_PKT_V2_2FINGER : ELANTECH_PKT_V2_COMMON;
4389 if (!ELANTECH_PKT_IS_V3_HEAD(pb, sc->elanhw.hascrc) &&
4390 !ELANTECH_PKT_IS_V3_TAIL(pb, sc->elanhw.hascrc))
4393 pkt = ELANTECH_PKT_V3;
4396 if (!ELANTECH_PKT_IS_V4(pb, sc->elanhw.hascrc))
4399 switch (pb->ipacket[3] & 0x03) {
4401 pkt = ELANTECH_PKT_V4_STATUS;
4404 pkt = ELANTECH_PKT_V4_HEAD;
4407 pkt = ELANTECH_PKT_V4_MOTION;
4417 VLOG(5, (LOG_DEBUG, "elantech: ipacket format: %d\n", pkt));
4419 for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
4420 PSM_FINGER_RESET(f[id]);
4423 ms->button = ms->obutton;
4425 if (sc->syninfo.touchpad_off)
4429 * L: Left mouse button pressed
4430 * R: Right mouse button pressed
4431 * N: number of fingers on touchpad
4432 * X: absolute x value (horizontal)
4433 * Y: absolute y value (vertical)
4434 * W; width of the finger touch
4438 case ELANTECH_PKT_V2_COMMON: /* HW V2. One/Three finger touch */
4439 /* 7 6 5 4 3 2 1 0 (LSB)
4440 * -------------------------------------------
4441 * ipacket[0]: N1 N0 W3 W2 . . R L
4442 * ipacket[1]: P7 P6 P5 P4 X11 X10 X9 X8
4443 * ipacket[2]: X7 X6 X5 X4 X3 X2 X1 X0
4444 * ipacket[3]: N4 VF W1 W0 . . . B2
4445 * ipacket[4]: P3 P1 P2 P0 Y11 Y10 Y9 Y8
4446 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
4447 * -------------------------------------------
4448 * N4: set if more than 3 fingers (only in 3 fingers mode)
4449 * VF: a kind of flag? (only on EF123, 0 when finger
4450 * is over one of the buttons, 1 otherwise)
4451 * B2: (on EF113 only, 0 otherwise), one button pressed
4452 * P & W is not reported on EF113 touchpads
4454 nfingers = (pb->ipacket[0] & 0xc0) >> 6;
4455 if (nfingers == 3 && (pb->ipacket[3] & 0x80))
4458 if (nfingers == 0) {
4459 mask = (1 << nfingers) - 1; /* = 0x00 */
4463 /* Map 3-rd and 4-th fingers to first finger */
4464 mask = (1 << 1) - 1; /* = 0x01 */
4465 f[0] = ELANTECH_FINGER_SET_XYP(pb);
4466 if (sc->elanhw.haspressure) {
4467 f[0].w = ((pb->ipacket[0] & 0x30) >> 2) |
4468 ((pb->ipacket[3] & 0x30) >> 4);
4470 f[0].p = PSM_FINGER_DEFAULT_P;
4471 f[0].w = PSM_FINGER_DEFAULT_W;
4475 * HW v2 dont report exact finger positions when 3 or more
4476 * fingers are on touchpad.
4479 f[0].flags = PSM_FINGER_FUZZY;
4483 case ELANTECH_PKT_V2_2FINGER: /*HW V2. Two finger touch */
4484 /* 7 6 5 4 3 2 1 0 (LSB)
4485 * -------------------------------------------
4486 * ipacket[0]: N1 N0 AY8 AX8 . . R L
4487 * ipacket[1]: AX7 AX6 AX5 AX4 AX3 AX2 AX1 AX0
4488 * ipacket[2]: AY7 AY6 AY5 AY4 AY3 AY2 AY1 AY0
4489 * ipacket[3]: . . BY8 BX8 . . . .
4490 * ipacket[4]: BX7 BX6 BX5 BX4 BX3 BX2 BX1 BX0
4491 * ipacket[5]: BY7 BY6 BY5 BY4 BY3 BY2 BY1 BY0
4492 * -------------------------------------------
4493 * AX: lower-left finger absolute x value
4494 * AY: lower-left finger absolute y value
4495 * BX: upper-right finger absolute x value
4496 * BY: upper-right finger absolute y value
4499 mask = (1 << nfingers) - 1;
4501 for (id = 0; id < imin(2, ELANTECH_MAX_FINGERS); id ++)
4502 f[id] = (finger_t) {
4503 .x = (((pb->ipacket[id * 3] & 0x10) << 4) |
4504 pb->ipacket[id * 3 + 1]) << 2,
4505 .y = (((pb->ipacket[id * 3] & 0x20) << 3) |
4506 pb->ipacket[id * 3 + 2]) << 2,
4507 .p = PSM_FINGER_DEFAULT_P,
4508 .w = PSM_FINGER_DEFAULT_W,
4509 /* HW ver.2 sends bounding box */
4510 .flags = PSM_FINGER_FUZZY
4514 case ELANTECH_PKT_V3: /* HW Version 3 */
4515 /* 7 6 5 4 3 2 1 0 (LSB)
4516 * -------------------------------------------
4517 * ipacket[0]: N1 N0 W3 W2 0 1 R L
4518 * ipacket[1]: P7 P6 P5 P4 X11 X10 X9 X8
4519 * ipacket[2]: X7 X6 X5 X4 X3 X2 X1 X0
4520 * ipacket[3]: 0 0 W1 W0 0 0 1 0
4521 * ipacket[4]: P3 P1 P2 P0 Y11 Y10 Y9 Y8
4522 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
4523 * -------------------------------------------
4525 nfingers = (pb->ipacket[0] & 0xc0) >> 6;
4526 /* Map 3-rd finger to first finger */
4527 id = nfingers > 2 ? 0 : nfingers - 1;
4528 mask = (1 << (id + 1)) - 1;
4533 fn = ELANTECH_FINGER_SET_XYP(pb);
4534 fn.w = ((pb->ipacket[0] & 0x30) >> 2) |
4535 ((pb->ipacket[3] & 0x30) >> 4);
4538 * HW v3 dont report exact finger positions when 3 or more
4539 * fingers are on touchpad.
4542 fn.flags = PSM_FINGER_FUZZY;
4544 if (nfingers == 2) {
4545 if (ELANTECH_PKT_IS_V3_HEAD(pb, sc->elanhw.hascrc)) {
4546 sc->elanaction.fingers[0] = fn;
4549 f[0] = sc->elanaction.fingers[0];
4554 case ELANTECH_PKT_V4_STATUS: /* HW Version 4. Status packet */
4555 /* 7 6 5 4 3 2 1 0 (LSB)
4556 * -------------------------------------------
4557 * ipacket[0]: . . . . 0 1 R L
4558 * ipacket[1]: . . . F4 F3 F2 F1 F0
4559 * ipacket[2]: . . . . . . . .
4560 * ipacket[3]: . . . 1 0 0 0 0
4561 * ipacket[4]: PL . . . . . . .
4562 * ipacket[5]: . . . . . . . .
4563 * -------------------------------------------
4564 * Fn: finger n is on touchpad
4566 * HV ver4 sends a status packet to indicate that the numbers
4567 * or identities of the fingers has been changed
4570 mask = pb->ipacket[1] & 0x1f;
4571 nfingers = bitcount(mask);
4573 if (sc->elanaction.mask_v4wait != 0)
4574 VLOG(3, (LOG_DEBUG, "elantech: HW v4 status packet"
4575 " when not all previous head packets received\n"));
4577 /* Bitmap of fingers to receive before gesture processing */
4578 sc->elanaction.mask_v4wait = mask & ~sc->elanaction.mask;
4580 /* Skip "new finger is on touchpad" packets */
4581 if (sc->elanaction.mask_v4wait) {
4582 sc->elanaction.mask = mask;
4588 case ELANTECH_PKT_V4_HEAD: /* HW Version 4. Head packet */
4589 /* 7 6 5 4 3 2 1 0 (LSB)
4590 * -------------------------------------------
4591 * ipacket[0]: W3 W2 W1 W0 0 1 R L
4592 * ipacket[1]: P7 P6 P5 P4 X11 X10 X9 X8
4593 * ipacket[2]: X7 X6 X5 X4 X3 X2 X1 X0
4594 * ipacket[3]: ID2 ID1 ID0 1 0 0 0 1
4595 * ipacket[4]: P3 P1 P2 P0 Y11 Y10 Y9 Y8
4596 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
4597 * -------------------------------------------
4599 * HW ver 4 sends head packets in two cases:
4600 * 1. One finger touch and movement.
4601 * 2. Next after status packet to tell new finger positions.
4603 mask = sc->elanaction.mask;
4604 nfingers = bitcount(mask);
4605 id = ((pb->ipacket[3] & 0xe0) >> 5) - 1;
4606 fn = ELANTECH_FINGER_SET_XYP(pb);
4607 fn.w =(pb->ipacket[0] & 0xf0) >> 4;
4612 /* Packet is finger position update. Report it */
4613 if (sc->elanaction.mask_v4wait == 0) {
4614 if (id < ELANTECH_MAX_FINGERS)
4619 /* Remove finger from waiting bitmap and store into context */
4620 sc->elanaction.mask_v4wait &= ~(1 << id);
4621 if (id < ELANTECH_MAX_FINGERS)
4622 sc->elanaction.fingers[id] = fn;
4624 /* Wait for other fingers if needed */
4625 if (sc->elanaction.mask_v4wait != 0)
4628 /* All new fingers are received. Report them from context */
4629 for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
4630 if (sc->elanaction.mask & (1 << id))
4631 f[id] = sc->elanaction.fingers[id];
4635 case ELANTECH_PKT_V4_MOTION: /* HW Version 4. Motion packet */
4636 /* 7 6 5 4 3 2 1 0 (LSB)
4637 * -------------------------------------------
4638 * ipacket[0]: ID2 ID1 ID0 OF 0 1 R L
4639 * ipacket[1]: DX7 DX6 DX5 DX4 DX3 DX2 DX1 DX0
4640 * ipacket[2]: DY7 DY6 DY5 DY4 DY3 DY2 DY1 DY0
4641 * ipacket[3]: ID2 ID1 ID0 1 0 0 1 0
4642 * ipacket[4]: DX7 DX6 DX5 DX4 DX3 DX2 DX1 DX0
4643 * ipacket[5]: DY7 DY6 DY5 DY4 DY3 DY2 DY1 DY0
4644 * -------------------------------------------
4645 * OF: delta overflows (> 127 or < -128), in this case
4646 * firmware sends us (delta x / 5) and (delta y / 5)
4648 * DX: delta x (two's complement)
4649 * XY: delta y (two's complement)
4650 * byte 0 ~ 2 for one finger
4651 * byte 3 ~ 5 for another finger
4653 mask = sc->elanaction.mask;
4654 nfingers = bitcount(mask);
4656 scale = (pb->ipacket[0] & 0x10) ? 5 : 1;
4657 for (i = 0; i <= 3; i += 3) {
4658 id = ((pb->ipacket[i] & 0xe0) >> 5) - 1;
4659 if (id < 0 || id >= ELANTECH_MAX_FINGERS)
4662 if (PSM_FINGER_IS_SET(sc->elanaction.fingers[id])) {
4663 f[id] = sc->elanaction.fingers[id];
4664 f[id].x += imax(-f[id].x,
4665 (signed char)pb->ipacket[i+1] * scale);
4666 f[id].y += imax(-f[id].y,
4667 (signed char)pb->ipacket[i+2] * scale);
4669 VLOG(3, (LOG_DEBUG, "elantech: "
4670 "HW v4 motion packet skipped\n"));
4676 case ELANTECH_PKT_TRACKPOINT:
4677 /* 7 6 5 4 3 2 1 0 (LSB)
4678 * -------------------------------------------
4679 * ipacket[0]: 0 0 SY SX 0 M R L
4680 * ipacket[1]: ~SX 0 0 0 0 0 0 0
4681 * ipacket[2]: ~SY 0 0 0 0 0 0 0
4682 * ipacket[3]: 0 0 ~SY ~SX 0 1 1 0
4683 * ipacket[4]: X7 X6 X5 X4 X3 X2 X1 X0
4684 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
4685 * -------------------------------------------
4686 * X and Y are written in two's complement spread
4687 * over 9 bits with SX/SY the relative top bit and
4688 * X7..X0 and Y7..Y0 the lower bits.
4690 if (!(pb->ipacket[0] & 0xC8) && !(pb->ipacket[1] & 0x7F) &&
4691 !(pb->ipacket[2] & 0x7F) && !(pb->ipacket[3] & 0xC9) &&
4692 !(pb->ipacket[0] & 0x10) != !(pb->ipacket[1] & 0x80) &&
4693 !(pb->ipacket[0] & 0x10) != !(pb->ipacket[3] & 0x10) &&
4694 !(pb->ipacket[0] & 0x20) != !(pb->ipacket[2] & 0x80) &&
4695 !(pb->ipacket[0] & 0x20) != !(pb->ipacket[3] & 0x20)) {
4697 *x = (pb->ipacket[0] & MOUSE_PS2_XNEG) ?
4698 pb->ipacket[4] - 256 : pb->ipacket[4];
4699 *y = (pb->ipacket[0] & MOUSE_PS2_YNEG) ?
4700 pb->ipacket[5] - 256 : pb->ipacket[5];
4703 ((pb->ipacket[0] & 0x01) ? MOUSE_BUTTON1DOWN : 0) |
4704 ((pb->ipacket[0] & 0x02) ? MOUSE_BUTTON3DOWN : 0) |
4705 ((pb->ipacket[0] & 0x04) ? MOUSE_BUTTON2DOWN : 0);
4706 #ifdef EVDEV_SUPPORT
4707 evdev_push_rel(sc->evdev_r, REL_X, *x);
4708 evdev_push_rel(sc->evdev_r, REL_Y, -*y);
4709 evdev_push_mouse_btn(sc->evdev_r, trackpoint_button);
4710 evdev_sync(sc->evdev_r);
4712 ms->button = touchpad_button | trackpoint_button;
4714 VLOG(3, (LOG_DEBUG, "elantech: "
4715 "unexpected trackpoint packet skipped\n"));
4718 case ELANTECH_PKT_NOP:
4725 for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
4726 if (PSM_FINGER_IS_SET(f[id]))
4727 VLOG(2, (LOG_DEBUG, "elantech: "
4728 "finger %d: down [%d, %d], %d, %d, %d\n", id + 1,
4729 f[id].x, f[id].y, f[id].p, f[id].w, f[id].flags));
4731 /* Touchpad button presses */
4732 if (sc->elanhw.isclickpad) {
4734 ((pb->ipacket[0] & 0x03) ? MOUSE_BUTTON1DOWN : 0);
4737 ((pb->ipacket[0] & 0x01) ? MOUSE_BUTTON1DOWN : 0) |
4738 ((pb->ipacket[0] & 0x02) ? MOUSE_BUTTON3DOWN : 0);
4741 #ifdef EVDEV_SUPPORT
4742 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE) {
4743 for (id = 0; id < ELANTECH_MAX_FINGERS; id++) {
4744 if (PSM_FINGER_IS_SET(f[id])) {
4745 psm_push_mt_finger(sc, id, &f[id]);
4746 /* Convert touch width to surface units */
4747 evdev_push_abs(sc->evdev_a, ABS_MT_TOUCH_MAJOR,
4748 f[id].w * sc->elanhw.dptracex);
4750 if (sc->elanaction.mask & (1 << id) &&
4751 !(mask & (1 << id)))
4752 psm_release_mt_slot(sc->evdev_a, id);
4754 evdev_push_key(sc->evdev_a, BTN_TOUCH, nfingers > 0);
4755 evdev_push_nfingers(sc->evdev_a, nfingers);
4757 if (PSM_FINGER_IS_SET(f[0]))
4758 psm_push_st_finger(sc, &f[0]);
4760 evdev_push_abs(sc->evdev_a, ABS_PRESSURE, 0);
4761 evdev_push_mouse_btn(sc->evdev_a, touchpad_button);
4762 evdev_sync(sc->evdev_a);
4766 ms->button = touchpad_button | trackpoint_button;
4768 /* Palm detection doesn't terminate the current action. */
4769 palm = psmpalmdetect(sc, &f[0], nfingers);
4771 /* Send finger 1 position to gesture processor */
4772 if ((PSM_FINGER_IS_SET(f[0]) || PSM_FINGER_IS_SET(f[1]) ||
4773 nfingers == 0) && !palm)
4774 psmgestures(sc, &f[0], imin(nfingers, 3), ms);
4776 /* Send fingers positions to movement smoothers */
4777 for (id = 0; id < PSM_FINGERS; id++)
4778 if (PSM_FINGER_IS_SET(f[id]) || !(mask & (1 << id)))
4779 psmsmoother(sc, &f[id], id, ms, x, y);
4781 /* Store current finger positions in action context */
4782 for (id = 0; id < ELANTECH_MAX_FINGERS; id++) {
4783 if (PSM_FINGER_IS_SET(f[id]))
4784 sc->elanaction.fingers[id] = f[id];
4785 if ((sc->elanaction.mask & (1 << id)) && !(mask & (1 << id)))
4786 PSM_FINGER_RESET(sc->elanaction.fingers[id]);
4788 sc->elanaction.mask = mask;
4792 ms->button = ms->obutton;
4796 /* Use the extra buttons as a scrollwheel */
4797 if (ms->button & MOUSE_BUTTON4DOWN)
4799 else if (ms->button & MOUSE_BUTTON5DOWN)
4801 else if (ms->button & MOUSE_BUTTON6DOWN)
4803 else if (ms->button & MOUSE_BUTTON7DOWN)
4807 ms->button &= ~(MOUSE_BUTTON4DOWN | MOUSE_BUTTON5DOWN |
4808 MOUSE_BUTTON6DOWN | MOUSE_BUTTON7DOWN);
4814 proc_versapad(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
4815 int *x, int *y, int *z)
4817 static int butmap_versapad[8] = {
4823 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
4825 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN
4829 /* VersaPad PS/2 absolute mode message format
4831 * [packet1] 7 6 5 4 3 2 1 0(LSB)
4832 * ipacket[0]: 1 1 0 A 1 L T R
4833 * ipacket[1]: H7 H6 H5 H4 H3 H2 H1 H0
4834 * ipacket[2]: V7 V6 V5 V4 V3 V2 V1 V0
4835 * ipacket[3]: 1 1 1 A 1 L T R
4836 * ipacket[4]:V11 V10 V9 V8 H11 H10 H9 H8
4837 * ipacket[5]: 0 P6 P5 P4 P3 P2 P1 P0
4840 * R: right physical mouse button (1=on)
4841 * T: touch pad virtual button (1=tapping)
4842 * L: left physical mouse button (1=on)
4843 * A: position data is valid (1=valid)
4844 * H: horizontal data (12bit signed integer. H11 is sign bit.)
4845 * V: vertical data (12bit signed integer. V11 is sign bit.)
4848 * Tapping is mapped to MOUSE_BUTTON4.
4852 ms->button = butmap_versapad[c & MOUSE_PS2VERSA_BUTTONS];
4853 ms->button |= (c & MOUSE_PS2VERSA_TAP) ? MOUSE_BUTTON4DOWN : 0;
4854 if (c & MOUSE_PS2VERSA_IN_USE) {
4855 x0 = pb->ipacket[1] | (((pb->ipacket[4]) & 0x0f) << 8);
4856 y0 = pb->ipacket[2] | (((pb->ipacket[4]) & 0xf0) << 4);
4861 if (sc->flags & PSM_FLAGS_FINGERDOWN) {
4864 if (*x < 0) /* XXX */
4873 sc->flags |= PSM_FLAGS_FINGERDOWN;
4877 sc->flags &= ~PSM_FLAGS_FINGERDOWN;
4881 psmsoftintridle(void *arg)
4883 struct psm_softc *sc = arg;
4886 /* Invoke soft handler only when pqueue is empty. Otherwise it will be
4887 * invoked from psmintr soon with pqueue filled with real data */
4888 if (sc->pqueue_start == sc->pqueue_end &&
4889 sc->idlepacket.inputbytes > 0) {
4890 /* Grow circular queue backwards to avoid race with psmintr */
4891 if (--sc->pqueue_start < 0)
4892 sc->pqueue_start = PSM_PACKETQUEUE - 1;
4894 pb = &sc->pqueue[sc->pqueue_start];
4895 memcpy(pb, &sc->idlepacket, sizeof(packetbuf_t));
4897 "psmsoftintridle: %02x %02x %02x %02x %02x %02x\n",
4898 pb->ipacket[0], pb->ipacket[1], pb->ipacket[2],
4899 pb->ipacket[3], pb->ipacket[4], pb->ipacket[5]));
4906 psmsoftintr(void *arg)
4909 * the table to turn PS/2 mouse button bits (MOUSE_PS2_BUTTON?DOWN)
4910 * into `mousestatus' button bits (MOUSE_BUTTON?DOWN).
4912 static int butmap[8] = {
4916 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
4918 MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN,
4919 MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN,
4920 MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN
4922 struct psm_softc *sc = arg;
4925 int x, y, z, c, l, s;
4927 getmicrouptime(&sc->lastsoftintr);
4932 pb = &sc->pqueue[sc->pqueue_start];
4934 if (sc->mode.level == PSM_LEVEL_NATIVE)
4939 * A kludge for Kensington device!
4940 * The MSB of the horizontal count appears to be stored in
4943 if (sc->hw.model == MOUSE_MODEL_THINK)
4944 pb->ipacket[1] |= (c & MOUSE_PS2_XOVERFLOW) ? 0x80 : 0;
4946 /* ignore the overflow bits... */
4947 x = (c & MOUSE_PS2_XNEG) ?
4948 pb->ipacket[1] - 256 : pb->ipacket[1];
4949 y = (c & MOUSE_PS2_YNEG) ?
4950 pb->ipacket[2] - 256 : pb->ipacket[2];
4952 ms.obutton = sc->button; /* previous button state */
4953 ms.button = butmap[c & MOUSE_PS2_BUTTONS];
4954 /* `tapping' action */
4955 if (sc->config & PSM_CONFIG_FORCETAP)
4956 ms.button |= ((c & MOUSE_PS2_TAP)) ?
4957 0 : MOUSE_BUTTON4DOWN;
4958 timevalclear(&sc->idletimeout);
4959 sc->idlepacket.inputbytes = 0;
4961 switch (sc->hw.model) {
4963 case MOUSE_MODEL_EXPLORER:
4965 * b7 b6 b5 b4 b3 b2 b1 b0
4966 * byte 1: oy ox sy sx 1 M R L
4967 * byte 2: x x x x x x x x
4968 * byte 3: y y y y y y y y
4969 * byte 4: * * S2 S1 s d2 d1 d0
4971 * L, M, R, S1, S2: left, middle, right and side buttons
4972 * s: wheel data sign bit
4975 z = (pb->ipacket[3] & MOUSE_EXPLORER_ZNEG) ?
4976 (pb->ipacket[3] & 0x0f) - 16 :
4977 (pb->ipacket[3] & 0x0f);
4979 (pb->ipacket[3] & MOUSE_EXPLORER_BUTTON4DOWN) ?
4980 MOUSE_BUTTON4DOWN : 0;
4982 (pb->ipacket[3] & MOUSE_EXPLORER_BUTTON5DOWN) ?
4983 MOUSE_BUTTON5DOWN : 0;
4986 case MOUSE_MODEL_INTELLI:
4987 case MOUSE_MODEL_NET:
4988 /* wheel data is in the fourth byte */
4989 z = (char)pb->ipacket[3];
4991 * XXX some mice may send 7 when there is no Z movement? */
4992 if ((z >= 7) || (z <= -7))
4994 /* some compatible mice have additional buttons */
4995 ms.button |= (c & MOUSE_PS2INTELLI_BUTTON4DOWN) ?
4996 MOUSE_BUTTON4DOWN : 0;
4997 ms.button |= (c & MOUSE_PS2INTELLI_BUTTON5DOWN) ?
4998 MOUSE_BUTTON5DOWN : 0;
5001 case MOUSE_MODEL_MOUSEMANPLUS:
5002 proc_mmanplus(sc, pb, &ms, &x, &y, &z);
5005 case MOUSE_MODEL_GLIDEPOINT:
5006 /* `tapping' action */
5007 ms.button |= ((c & MOUSE_PS2_TAP)) ? 0 :
5011 case MOUSE_MODEL_NETSCROLL:
5013 * three additional bytes encode buttons and
5016 ms.button |= (pb->ipacket[3] & MOUSE_PS2_BUTTON3DOWN) ?
5017 MOUSE_BUTTON4DOWN : 0;
5018 ms.button |= (pb->ipacket[3] & MOUSE_PS2_BUTTON1DOWN) ?
5019 MOUSE_BUTTON5DOWN : 0;
5020 z = (pb->ipacket[3] & MOUSE_PS2_XNEG) ?
5021 pb->ipacket[4] - 256 : pb->ipacket[4];
5024 case MOUSE_MODEL_THINK:
5025 /* the fourth button state in the first byte */
5026 ms.button |= (c & MOUSE_PS2_TAP) ?
5027 MOUSE_BUTTON4DOWN : 0;
5030 case MOUSE_MODEL_VERSAPAD:
5031 proc_versapad(sc, pb, &ms, &x, &y, &z);
5032 c = ((x < 0) ? MOUSE_PS2_XNEG : 0) |
5033 ((y < 0) ? MOUSE_PS2_YNEG : 0);
5036 case MOUSE_MODEL_4D:
5038 * b7 b6 b5 b4 b3 b2 b1 b0
5039 * byte 1: s2 d2 s1 d1 1 M R L
5040 * byte 2: sx x x x x x x x
5041 * byte 3: sy y y y y y y y
5043 * s1: wheel 1 direction
5045 * s2: wheel 2 direction
5048 x = (pb->ipacket[1] & 0x80) ?
5049 pb->ipacket[1] - 256 : pb->ipacket[1];
5050 y = (pb->ipacket[2] & 0x80) ?
5051 pb->ipacket[2] - 256 : pb->ipacket[2];
5052 switch (c & MOUSE_4D_WHEELBITS) {
5059 case 0x40: /* XXX 2nd wheel turning right */
5062 case 0xc0: /* XXX 2nd wheel turning left */
5068 case MOUSE_MODEL_4DPLUS:
5069 if ((x < 16 - 256) && (y < 16 - 256)) {
5071 * b7 b6 b5 b4 b3 b2 b1 b0
5072 * byte 1: 0 0 1 1 1 M R L
5073 * byte 2: 0 0 0 0 1 0 0 0
5074 * byte 3: 0 0 0 0 S s d1 d0
5076 * L, M, R, S: left, middle, right,
5078 * s: wheel data sign bit
5082 if (pb->ipacket[2] & MOUSE_4DPLUS_BUTTON4DOWN)
5083 ms.button |= MOUSE_BUTTON4DOWN;
5084 z = (pb->ipacket[2] & MOUSE_4DPLUS_ZNEG) ?
5085 ((pb->ipacket[2] & 0x07) - 8) :
5086 (pb->ipacket[2] & 0x07) ;
5088 /* preserve previous button states */
5089 ms.button |= ms.obutton & MOUSE_EXTBUTTONS;
5093 case MOUSE_MODEL_SYNAPTICS:
5094 if (pb->inputbytes == MOUSE_PS2_PACKETSIZE)
5095 if (proc_synaptics_mux(sc, pb))
5098 if (proc_synaptics(sc, pb, &ms, &x, &y, &z) != 0) {
5099 VLOG(3, (LOG_DEBUG, "synaptics: "
5100 "packet rejected\n"));
5105 case MOUSE_MODEL_ELANTECH:
5106 if (proc_elantech(sc, pb, &ms, &x, &y, &z) != 0) {
5107 VLOG(3, (LOG_DEBUG, "elantech: "
5108 "packet rejected\n"));
5113 case MOUSE_MODEL_TRACKPOINT:
5114 case MOUSE_MODEL_GENERIC:
5119 #ifdef EVDEV_SUPPORT
5120 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE &&
5121 sc->hw.model != MOUSE_MODEL_ELANTECH &&
5122 sc->hw.model != MOUSE_MODEL_SYNAPTICS) {
5123 evdev_push_rel(sc->evdev_r, REL_X, x);
5124 evdev_push_rel(sc->evdev_r, REL_Y, -y);
5126 switch (sc->hw.model) {
5127 case MOUSE_MODEL_EXPLORER:
5128 case MOUSE_MODEL_INTELLI:
5129 case MOUSE_MODEL_NET:
5130 case MOUSE_MODEL_NETSCROLL:
5131 case MOUSE_MODEL_4DPLUS:
5132 evdev_push_rel(sc->evdev_r, REL_WHEEL, -z);
5134 case MOUSE_MODEL_MOUSEMANPLUS:
5135 case MOUSE_MODEL_4D:
5139 evdev_push_rel(sc->evdev_r, REL_WHEEL, -z);
5143 evdev_push_rel(sc->evdev_r, REL_HWHEEL, z / 2);
5149 evdev_push_mouse_btn(sc->evdev_r, ms.button);
5150 evdev_sync(sc->evdev_r);
5155 if (sc->mode.accelfactor >= 1) {
5157 x = x * x / sc->mode.accelfactor;
5160 if (c & MOUSE_PS2_XNEG)
5164 y = y * y / sc->mode.accelfactor;
5167 if (c & MOUSE_PS2_YNEG)
5172 /* Store last packet for reinjection if it has not been set already */
5173 if (timevalisset(&sc->idletimeout) && sc->idlepacket.inputbytes == 0)
5174 sc->idlepacket = *pb;
5179 ms.flags = ((x || y || z) ? MOUSE_POSCHANGED : 0) |
5180 (ms.obutton ^ ms.button);
5182 pb->inputbytes = tame_mouse(sc, pb, &ms, pb->ipacket);
5184 sc->status.flags |= ms.flags;
5185 sc->status.dx += ms.dx;
5186 sc->status.dy += ms.dy;
5187 sc->status.dz += ms.dz;
5188 sc->status.button = ms.button;
5189 sc->button = ms.button;
5192 sc->watchdog = FALSE;
5195 if (sc->queue.count + pb->inputbytes < sizeof(sc->queue.buf)) {
5196 l = imin(pb->inputbytes,
5197 sizeof(sc->queue.buf) - sc->queue.tail);
5198 bcopy(&pb->ipacket[0], &sc->queue.buf[sc->queue.tail], l);
5199 if (pb->inputbytes > l)
5200 bcopy(&pb->ipacket[l], &sc->queue.buf[0],
5201 pb->inputbytes - l);
5202 sc->queue.tail = (sc->queue.tail + pb->inputbytes) %
5203 sizeof(sc->queue.buf);
5204 sc->queue.count += pb->inputbytes;
5209 if (++sc->pqueue_start >= PSM_PACKETQUEUE)
5210 sc->pqueue_start = 0;
5211 } while (sc->pqueue_start != sc->pqueue_end);
5213 if (sc->state & PSM_ASLP) {
5214 sc->state &= ~PSM_ASLP;
5217 selwakeuppri(&sc->rsel, PZERO);
5218 if (sc->async != NULL) {
5219 pgsigio(&sc->async, SIGIO, 0);
5221 sc->state &= ~PSM_SOFTARMED;
5223 /* schedule injection of predefined packet after idletimeout
5224 * if no data packets have been received from psmintr */
5225 if (timevalisset(&sc->idletimeout)) {
5226 sc->state |= PSM_SOFTARMED;
5227 callout_reset(&sc->softcallout, tvtohz(&sc->idletimeout),
5228 psmsoftintridle, sc);
5229 VLOG(2, (LOG_DEBUG, "softintr: callout set: %d ticks\n",
5230 tvtohz(&sc->idletimeout)));
5236 psmpoll(struct cdev *dev, int events, struct thread *td)
5238 struct psm_softc *sc = dev->si_drv1;
5242 /* Return true if a mouse event available */
5244 if (events & (POLLIN | POLLRDNORM)) {
5245 if (sc->queue.count > 0)
5246 revents |= events & (POLLIN | POLLRDNORM);
5248 selrecord(td, &sc->rsel);
5255 /* vendor/model specific routines */
5257 static int mouse_id_proc1(KBDC kbdc, int res, int scale, int *status)
5259 if (set_mouse_resolution(kbdc, res) != res)
5261 if (set_mouse_scaling(kbdc, scale) &&
5262 set_mouse_scaling(kbdc, scale) &&
5263 set_mouse_scaling(kbdc, scale) &&
5264 (get_mouse_status(kbdc, status, 0, 3) >= 3))
5270 mouse_ext_command(KBDC kbdc, int command)
5274 c = (command >> 6) & 0x03;
5275 if (set_mouse_resolution(kbdc, c) != c)
5277 c = (command >> 4) & 0x03;
5278 if (set_mouse_resolution(kbdc, c) != c)
5280 c = (command >> 2) & 0x03;
5281 if (set_mouse_resolution(kbdc, c) != c)
5283 c = (command >> 0) & 0x03;
5284 if (set_mouse_resolution(kbdc, c) != c)
5290 /* Logitech MouseMan Cordless II */
5292 enable_lcordless(struct psm_softc *sc, enum probearg arg)
5294 KBDC kbdc = sc->kbdc;
5298 if (!mouse_id_proc1(kbdc, PSMD_RES_HIGH, 2, status))
5300 if (status[1] == PSMD_RES_HIGH)
5302 ch = (status[0] & 0x07) - 1; /* channel # */
5303 if ((ch <= 0) || (ch > 4))
5306 * status[1]: always one?
5307 * status[2]: battery status? (0-100)
5313 /* Genius NetScroll Mouse, MouseSystems SmartScroll Mouse */
5315 enable_groller(struct psm_softc *sc, enum probearg arg)
5317 KBDC kbdc = sc->kbdc;
5321 * The special sequence to enable the fourth button and the
5322 * roller. Immediately after this sequence check status bytes.
5323 * if the mouse is NetScroll, the second and the third bytes are
5328 * If the mouse is an ordinary PS/2 mouse, the status bytes should
5329 * look like the following.
5331 * byte 1 bit 7 always 0
5332 * bit 6 stream mode (0)
5333 * bit 5 disabled (0)
5334 * bit 4 1:1 scaling (0)
5336 * bit 0-2 button status
5337 * byte 2 resolution (PSMD_RES_HIGH)
5338 * byte 3 report rate (?)
5341 if (!mouse_id_proc1(kbdc, PSMD_RES_HIGH, 1, status))
5343 if ((status[1] != '3') || (status[2] != 'D'))
5345 /* FIXME: SmartScroll Mouse has 5 buttons! XXX */
5351 /* Genius NetMouse/NetMouse Pro, ASCII Mie Mouse, NetScroll Optical */
5353 enable_gmouse(struct psm_softc *sc, enum probearg arg)
5355 KBDC kbdc = sc->kbdc;
5359 * The special sequence to enable the middle, "rubber" button.
5360 * Immediately after this sequence check status bytes.
5361 * if the mouse is NetMouse, NetMouse Pro, or ASCII MIE Mouse,
5362 * the second and the third bytes are '3' and 'U'.
5363 * NOTE: NetMouse reports that it has three buttons although it has
5364 * two buttons and a rubber button. NetMouse Pro and MIE Mouse
5365 * say they have three buttons too and they do have a button on the
5368 if (!mouse_id_proc1(kbdc, PSMD_RES_HIGH, 1, status))
5370 if ((status[1] != '3') || (status[2] != 'U'))
5375 /* ALPS GlidePoint */
5377 enable_aglide(struct psm_softc *sc, enum probearg arg)
5379 KBDC kbdc = sc->kbdc;
5383 * The special sequence to obtain ALPS GlidePoint specific
5384 * information. Immediately after this sequence, status bytes will
5385 * contain something interesting.
5386 * NOTE: ALPS produces several models of GlidePoint. Some of those
5387 * do not respond to this sequence, thus, cannot be detected this way.
5389 if (set_mouse_sampling_rate(kbdc, 100) != 100)
5391 if (!mouse_id_proc1(kbdc, PSMD_RES_LOW, 2, status))
5393 if ((status[1] == PSMD_RES_LOW) || (status[2] == 100))
5398 /* Kensington ThinkingMouse/Trackball */
5400 enable_kmouse(struct psm_softc *sc, enum probearg arg)
5402 static u_char rate[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
5403 KBDC kbdc = sc->kbdc;
5409 id1 = get_aux_id(kbdc);
5410 if (set_mouse_sampling_rate(kbdc, 10) != 10)
5413 * The device is now in the native mode? It returns a different
5416 id2 = get_aux_id(kbdc);
5417 if ((id1 == id2) || (id2 != 2))
5420 if (set_mouse_resolution(kbdc, PSMD_RES_LOW) != PSMD_RES_LOW)
5423 /* at this point, resolution is LOW, sampling rate is 10/sec */
5424 if (get_mouse_status(kbdc, status, 0, 3) < 3)
5429 * The special sequence to enable the third and fourth buttons.
5430 * Otherwise they behave like the first and second buttons.
5432 for (i = 0; i < nitems(rate); ++i)
5433 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
5437 * At this point, the device is using default resolution and
5438 * sampling rate for the native mode.
5440 if (get_mouse_status(kbdc, status, 0, 3) < 3)
5442 if ((status[1] == PSMD_RES_LOW) || (status[2] == rate[i - 1]))
5445 /* the device appears be enabled by this sequence, diable it for now */
5446 disable_aux_dev(kbdc);
5447 empty_aux_buffer(kbdc, 5);
5452 /* Logitech MouseMan+/FirstMouse+, IBM ScrollPoint Mouse */
5454 enable_mmanplus(struct psm_softc *sc, enum probearg arg)
5456 KBDC kbdc = sc->kbdc;
5459 /* the special sequence to enable the fourth button and the roller. */
5461 * NOTE: for ScrollPoint to respond correctly, the SET_RESOLUTION
5462 * must be called exactly three times since the last RESET command
5463 * before this sequence. XXX
5465 if (!set_mouse_scaling(kbdc, 1))
5467 if (!mouse_ext_command(kbdc, 0x39) || !mouse_ext_command(kbdc, 0xdb))
5469 if (get_mouse_status(kbdc, data, 1, 3) < 3)
5473 * PS2++ protocol, packet type 0
5475 * b7 b6 b5 b4 b3 b2 b1 b0
5476 * byte 1: * 1 p3 p2 1 * * *
5477 * byte 2: 1 1 p1 p0 m1 m0 1 0
5478 * byte 3: m7 m6 m5 m4 m3 m2 m1 m0
5480 * p3-p0: packet type: 0
5481 * m7-m0: model ID: MouseMan+:0x50,
5483 * ScrollPoint:0x58...
5485 /* check constant bits */
5486 if ((data[0] & MOUSE_PS2PLUS_SYNCMASK) != MOUSE_PS2PLUS_SYNC)
5488 if ((data[1] & 0xc3) != 0xc2)
5490 /* check d3-d0 in byte 2 */
5491 if (!MOUSE_PS2PLUS_CHECKBITS(data))
5494 if (MOUSE_PS2PLUS_PACKET_TYPE(data) != 0)
5498 sc->hw.hwid &= 0x00ff;
5499 sc->hw.hwid |= data[2] << 8; /* save model ID */
5503 * MouseMan+ (or FirstMouse+) is now in its native mode, in which
5504 * the wheel and the fourth button events are encoded in the
5505 * special data packet. The mouse may be put in the IntelliMouse mode
5506 * if it is initialized by the IntelliMouse's method.
5511 /* MS IntelliMouse Explorer */
5513 enable_msexplorer(struct psm_softc *sc, enum probearg arg)
5515 KBDC kbdc = sc->kbdc;
5516 static u_char rate0[] = { 200, 100, 80, };
5517 static u_char rate1[] = { 200, 200, 80, };
5522 * This is needed for at least A4Tech X-7xx mice - they do not go
5523 * straight to Explorer mode, but need to be set to Intelli mode
5526 enable_msintelli(sc, arg);
5528 /* the special sequence to enable the extra buttons and the roller. */
5529 for (i = 0; i < nitems(rate1); ++i)
5530 if (set_mouse_sampling_rate(kbdc, rate1[i]) != rate1[i])
5532 /* the device will give the genuine ID only after the above sequence */
5533 id = get_aux_id(kbdc);
5534 if (id != PSM_EXPLORER_ID)
5538 sc->hw.buttons = 5; /* IntelliMouse Explorer XXX */
5543 * XXX: this is a kludge to fool some KVM switch products
5544 * which think they are clever enough to know the 4-byte IntelliMouse
5545 * protocol, and assume any other protocols use 3-byte packets.
5546 * They don't convey 4-byte data packets from the IntelliMouse Explorer
5547 * correctly to the host computer because of this!
5548 * The following sequence is actually IntelliMouse's "wake up"
5549 * sequence; it will make the KVM think the mouse is IntelliMouse
5550 * when it is in fact IntelliMouse Explorer.
5552 for (i = 0; i < nitems(rate0); ++i)
5553 if (set_mouse_sampling_rate(kbdc, rate0[i]) != rate0[i])
5562 * Logitech MouseMan+ and FirstMouse+ will also respond to this
5563 * probe routine and act like IntelliMouse.
5566 enable_msintelli(struct psm_softc *sc, enum probearg arg)
5568 KBDC kbdc = sc->kbdc;
5569 static u_char rate[] = { 200, 100, 80, };
5573 /* the special sequence to enable the third button and the roller. */
5574 for (i = 0; i < nitems(rate); ++i)
5575 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
5577 /* the device will give the genuine ID only after the above sequence */
5578 id = get_aux_id(kbdc);
5579 if (id != PSM_INTELLI_ID)
5592 * Newer wheel mice from A4 Tech may use the 4D+ protocol.
5595 enable_4dmouse(struct psm_softc *sc, enum probearg arg)
5597 static u_char rate[] = { 200, 100, 80, 60, 40, 20 };
5598 KBDC kbdc = sc->kbdc;
5602 for (i = 0; i < nitems(rate); ++i)
5603 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
5605 id = get_aux_id(kbdc);
5607 * WinEasy 4D, 4 Way Scroll 4D: 6
5608 * Cable-Free 4D: 8 (4DPLUS)
5609 * WinBest 4D+, 4 Way Scroll 4D+: 8 (4DPLUS)
5611 if (id != PSM_4DMOUSE_ID)
5615 sc->hw.buttons = 3; /* XXX some 4D mice have 4? */
5624 * Newer wheel mice from A4 Tech seem to use this protocol.
5625 * Older models are recognized as either 4D Mouse or IntelliMouse.
5628 enable_4dplus(struct psm_softc *sc, enum probearg arg)
5630 KBDC kbdc = sc->kbdc;
5634 * enable_4dmouse() already issued the following ID sequence...
5635 static u_char rate[] = { 200, 100, 80, 60, 40, 20 };
5638 for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i)
5639 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
5643 id = get_aux_id(kbdc);
5647 case PSM_4DPLUS_RFSW35_ID:
5654 sc->hw.buttons = (id == PSM_4DPLUS_ID) ? 4 : 3;
5661 /* Synaptics Touchpad */
5663 synaptics_sysctl(SYSCTL_HANDLER_ARGS)
5665 struct psm_softc *sc;
5668 if (oidp->oid_arg1 == NULL || oidp->oid_arg2 < 0 ||
5669 oidp->oid_arg2 > SYNAPTICS_SYSCTL_LAST)
5672 sc = oidp->oid_arg1;
5674 /* Read the current value. */
5675 arg = *(int *)((char *)sc + oidp->oid_arg2);
5676 error = sysctl_handle_int(oidp, &arg, 0, req);
5679 if (error || !req->newptr)
5683 * Check that the new value is in the concerned node's range
5686 switch (oidp->oid_arg2) {
5687 case SYNAPTICS_SYSCTL_MIN_PRESSURE:
5688 case SYNAPTICS_SYSCTL_MAX_PRESSURE:
5689 if (arg < 0 || arg > 255)
5692 case SYNAPTICS_SYSCTL_MAX_WIDTH:
5693 if (arg < 4 || arg > 15)
5696 case SYNAPTICS_SYSCTL_MARGIN_TOP:
5697 case SYNAPTICS_SYSCTL_MARGIN_BOTTOM:
5698 case SYNAPTICS_SYSCTL_NA_TOP:
5699 case SYNAPTICS_SYSCTL_NA_BOTTOM:
5700 if (arg < 0 || arg > sc->synhw.maximumYCoord)
5703 case SYNAPTICS_SYSCTL_SOFTBUTTON2_X:
5704 case SYNAPTICS_SYSCTL_SOFTBUTTON3_X:
5705 /* Softbuttons is clickpad only feature */
5706 if (!sc->synhw.capClickPad && arg != 0)
5709 case SYNAPTICS_SYSCTL_MARGIN_RIGHT:
5710 case SYNAPTICS_SYSCTL_MARGIN_LEFT:
5711 case SYNAPTICS_SYSCTL_NA_RIGHT:
5712 case SYNAPTICS_SYSCTL_NA_LEFT:
5713 if (arg < 0 || arg > sc->synhw.maximumXCoord)
5716 case SYNAPTICS_SYSCTL_WINDOW_MIN:
5717 case SYNAPTICS_SYSCTL_WINDOW_MAX:
5718 case SYNAPTICS_SYSCTL_TAP_MIN_QUEUE:
5719 if (arg < 1 || arg > SYNAPTICS_PACKETQUEUE)
5722 case SYNAPTICS_SYSCTL_MULTIPLICATOR:
5723 case SYNAPTICS_SYSCTL_WEIGHT_CURRENT:
5724 case SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS:
5725 case SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA:
5726 case SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED:
5727 case SYNAPTICS_SYSCTL_DIV_MIN:
5728 case SYNAPTICS_SYSCTL_DIV_MAX:
5729 case SYNAPTICS_SYSCTL_DIV_MAX_NA:
5730 case SYNAPTICS_SYSCTL_DIV_LEN:
5731 case SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN:
5732 case SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX:
5736 case SYNAPTICS_SYSCTL_TAP_MAX_DELTA:
5737 case SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT:
5738 case SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA:
5742 case SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA:
5743 if (arg < -sc->synhw.maximumXCoord ||
5744 arg > sc->synhw.maximumXCoord)
5747 case SYNAPTICS_SYSCTL_SOFTBUTTONS_Y:
5748 /* Softbuttons is clickpad only feature */
5749 if (!sc->synhw.capClickPad && arg != 0)
5752 case SYNAPTICS_SYSCTL_VSCROLL_VER_AREA:
5753 if (arg < -sc->synhw.maximumYCoord ||
5754 arg > sc->synhw.maximumYCoord)
5757 case SYNAPTICS_SYSCTL_TOUCHPAD_OFF:
5758 case SYNAPTICS_SYSCTL_NATURAL_SCROLL:
5759 if (arg < 0 || arg > 1)
5767 *(int *)((char *)sc + oidp->oid_arg2) = arg;
5773 synaptics_sysctl_create_softbuttons_tree(struct psm_softc *sc)
5776 * Set predefined sizes for softbuttons.
5777 * Values are taken to match HP Pavilion dv6 clickpad drawings
5778 * with thin middle softbutton placed on separator
5781 /* hw.psm.synaptics.softbuttons_y */
5782 sc->syninfo.softbuttons_y = sc->synhw.topButtonPad ? -1700 : 1700;
5783 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5784 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5785 "softbuttons_y", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5786 sc, SYNAPTICS_SYSCTL_SOFTBUTTONS_Y,
5787 synaptics_sysctl, "I",
5788 "Vertical size of softbuttons area");
5790 /* hw.psm.synaptics.softbutton2_x */
5791 sc->syninfo.softbutton2_x = 3100;
5792 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5793 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5794 "softbutton2_x", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5795 sc, SYNAPTICS_SYSCTL_SOFTBUTTON2_X,
5796 synaptics_sysctl, "I",
5797 "Horisontal position of 2-nd softbutton left edge (0-disable)");
5799 /* hw.psm.synaptics.softbutton3_x */
5800 sc->syninfo.softbutton3_x = 3900;
5801 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5802 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5803 "softbutton3_x", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5804 sc, SYNAPTICS_SYSCTL_SOFTBUTTON3_X,
5805 synaptics_sysctl, "I",
5806 "Horisontal position of 3-rd softbutton left edge (0-disable)");
5810 synaptics_sysctl_create_tree(struct psm_softc *sc, const char *name,
5814 if (sc->syninfo.sysctl_tree != NULL)
5817 /* Attach extra synaptics sysctl nodes under hw.psm.synaptics */
5818 sysctl_ctx_init(&sc->syninfo.sysctl_ctx);
5819 sc->syninfo.sysctl_tree = SYSCTL_ADD_NODE(&sc->syninfo.sysctl_ctx,
5820 SYSCTL_STATIC_CHILDREN(_hw_psm), OID_AUTO, name, CTLFLAG_RD,
5823 /* hw.psm.synaptics.directional_scrolls. */
5824 sc->syninfo.directional_scrolls = 0;
5825 SYSCTL_ADD_INT(&sc->syninfo.sysctl_ctx,
5826 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5827 "directional_scrolls", CTLFLAG_RW|CTLFLAG_ANYBODY,
5828 &sc->syninfo.directional_scrolls, 0,
5829 "Enable hardware scrolling pad (if non-zero) or register it as "
5830 "extended buttons (if 0)");
5832 /* hw.psm.synaptics.max_x. */
5833 sc->syninfo.max_x = 6143;
5834 SYSCTL_ADD_INT(&sc->syninfo.sysctl_ctx,
5835 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5836 "max_x", CTLFLAG_RD|CTLFLAG_ANYBODY,
5837 &sc->syninfo.max_x, 0,
5838 "Horizontal reporting range");
5840 /* hw.psm.synaptics.max_y. */
5841 sc->syninfo.max_y = 6143;
5842 SYSCTL_ADD_INT(&sc->syninfo.sysctl_ctx,
5843 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5844 "max_y", CTLFLAG_RD|CTLFLAG_ANYBODY,
5845 &sc->syninfo.max_y, 0,
5846 "Vertical reporting range");
5849 * Turn off two finger scroll if we have a
5850 * physical area reserved for scrolling or when
5851 * there's no multi finger support.
5853 if (sc->synhw.verticalScroll || (sc->synhw.capMultiFinger == 0 &&
5854 sc->synhw.capAdvancedGestures == 0))
5855 sc->syninfo.two_finger_scroll = 0;
5857 sc->syninfo.two_finger_scroll = 1;
5858 /* hw.psm.synaptics.two_finger_scroll. */
5859 SYSCTL_ADD_INT(&sc->syninfo.sysctl_ctx,
5860 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5861 "two_finger_scroll", CTLFLAG_RW|CTLFLAG_ANYBODY,
5862 &sc->syninfo.two_finger_scroll, 0,
5863 "Enable two finger scrolling");
5865 /* hw.psm.synaptics.min_pressure. */
5866 sc->syninfo.min_pressure = 32;
5867 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5868 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5869 "min_pressure", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5870 sc, SYNAPTICS_SYSCTL_MIN_PRESSURE,
5871 synaptics_sysctl, "I",
5872 "Minimum pressure required to start an action");
5874 /* hw.psm.synaptics.max_pressure. */
5875 sc->syninfo.max_pressure = 220;
5876 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5877 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5878 "max_pressure", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5879 sc, SYNAPTICS_SYSCTL_MAX_PRESSURE,
5880 synaptics_sysctl, "I",
5881 "Maximum pressure to detect palm");
5883 /* hw.psm.synaptics.max_width. */
5884 sc->syninfo.max_width = 10;
5885 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5886 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5887 "max_width", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5888 sc, SYNAPTICS_SYSCTL_MAX_WIDTH,
5889 synaptics_sysctl, "I",
5890 "Maximum finger width to detect palm");
5892 /* hw.psm.synaptics.top_margin. */
5893 sc->syninfo.margin_top = 200;
5894 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5895 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5896 "margin_top", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5897 sc, SYNAPTICS_SYSCTL_MARGIN_TOP,
5898 synaptics_sysctl, "I",
5901 /* hw.psm.synaptics.right_margin. */
5902 sc->syninfo.margin_right = 200;
5903 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5904 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5905 "margin_right", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5906 sc, SYNAPTICS_SYSCTL_MARGIN_RIGHT,
5907 synaptics_sysctl, "I",
5910 /* hw.psm.synaptics.bottom_margin. */
5911 sc->syninfo.margin_bottom = 200;
5912 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5913 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5914 "margin_bottom", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5915 sc, SYNAPTICS_SYSCTL_MARGIN_BOTTOM,
5916 synaptics_sysctl, "I",
5919 /* hw.psm.synaptics.left_margin. */
5920 sc->syninfo.margin_left = 200;
5921 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5922 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5923 "margin_left", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5924 sc, SYNAPTICS_SYSCTL_MARGIN_LEFT,
5925 synaptics_sysctl, "I",
5928 /* hw.psm.synaptics.na_top. */
5929 sc->syninfo.na_top = 1783;
5930 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5931 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5932 "na_top", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5933 sc, SYNAPTICS_SYSCTL_NA_TOP,
5934 synaptics_sysctl, "I",
5935 "Top noisy area, where weight_previous_na is used instead "
5936 "of weight_previous");
5938 /* hw.psm.synaptics.na_right. */
5939 sc->syninfo.na_right = 563;
5940 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5941 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5942 "na_right", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5943 sc, SYNAPTICS_SYSCTL_NA_RIGHT,
5944 synaptics_sysctl, "I",
5945 "Right noisy area, where weight_previous_na is used instead "
5946 "of weight_previous");
5948 /* hw.psm.synaptics.na_bottom. */
5949 sc->syninfo.na_bottom = 1408;
5950 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5951 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5952 "na_bottom", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5953 sc, SYNAPTICS_SYSCTL_NA_BOTTOM,
5954 synaptics_sysctl, "I",
5955 "Bottom noisy area, where weight_previous_na is used instead "
5956 "of weight_previous");
5958 /* hw.psm.synaptics.na_left. */
5959 sc->syninfo.na_left = 1600;
5960 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5961 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5962 "na_left", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5963 sc, SYNAPTICS_SYSCTL_NA_LEFT,
5964 synaptics_sysctl, "I",
5965 "Left noisy area, where weight_previous_na is used instead "
5966 "of weight_previous");
5968 /* hw.psm.synaptics.window_min. */
5969 sc->syninfo.window_min = 4;
5970 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5971 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5972 "window_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5973 sc, SYNAPTICS_SYSCTL_WINDOW_MIN,
5974 synaptics_sysctl, "I",
5975 "Minimum window size to start an action");
5977 /* hw.psm.synaptics.window_max. */
5978 sc->syninfo.window_max = 10;
5979 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5980 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5981 "window_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5982 sc, SYNAPTICS_SYSCTL_WINDOW_MAX,
5983 synaptics_sysctl, "I",
5984 "Maximum window size");
5986 /* hw.psm.synaptics.multiplicator. */
5987 sc->syninfo.multiplicator = 10000;
5988 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5989 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5990 "multiplicator", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
5991 sc, SYNAPTICS_SYSCTL_MULTIPLICATOR,
5992 synaptics_sysctl, "I",
5993 "Multiplicator to increase precision in averages and divisions");
5995 /* hw.psm.synaptics.weight_current. */
5996 sc->syninfo.weight_current = 3;
5997 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
5998 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
5999 "weight_current", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6000 sc, SYNAPTICS_SYSCTL_WEIGHT_CURRENT,
6001 synaptics_sysctl, "I",
6002 "Weight of the current movement in the new average");
6004 /* hw.psm.synaptics.weight_previous. */
6005 sc->syninfo.weight_previous = 6;
6006 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6007 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6008 "weight_previous", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6009 sc, SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS,
6010 synaptics_sysctl, "I",
6011 "Weight of the previous average");
6013 /* hw.psm.synaptics.weight_previous_na. */
6014 sc->syninfo.weight_previous_na = 20;
6015 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6016 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6017 "weight_previous_na", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6018 sc, SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA,
6019 synaptics_sysctl, "I",
6020 "Weight of the previous average (inside the noisy area)");
6022 /* hw.psm.synaptics.weight_len_squared. */
6023 sc->syninfo.weight_len_squared = 2000;
6024 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6025 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6026 "weight_len_squared", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6027 sc, SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED,
6028 synaptics_sysctl, "I",
6029 "Length (squared) of segments where weight_previous "
6030 "starts to decrease");
6032 /* hw.psm.synaptics.div_min. */
6033 sc->syninfo.div_min = 9;
6034 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6035 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6036 "div_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6037 sc, SYNAPTICS_SYSCTL_DIV_MIN,
6038 synaptics_sysctl, "I",
6039 "Divisor for fast movements");
6041 /* hw.psm.synaptics.div_max. */
6042 sc->syninfo.div_max = 17;
6043 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6044 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6045 "div_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6046 sc, SYNAPTICS_SYSCTL_DIV_MAX,
6047 synaptics_sysctl, "I",
6048 "Divisor for slow movements");
6050 /* hw.psm.synaptics.div_max_na. */
6051 sc->syninfo.div_max_na = 30;
6052 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6053 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6054 "div_max_na", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6055 sc, SYNAPTICS_SYSCTL_DIV_MAX_NA,
6056 synaptics_sysctl, "I",
6057 "Divisor with slow movements (inside the noisy area)");
6059 /* hw.psm.synaptics.div_len. */
6060 sc->syninfo.div_len = 100;
6061 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6062 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6063 "div_len", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6064 sc, SYNAPTICS_SYSCTL_DIV_LEN,
6065 synaptics_sysctl, "I",
6066 "Length of segments where div_max starts to decrease");
6068 /* hw.psm.synaptics.tap_max_delta. */
6069 sc->syninfo.tap_max_delta = 80;
6070 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6071 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6072 "tap_max_delta", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6073 sc, SYNAPTICS_SYSCTL_TAP_MAX_DELTA,
6074 synaptics_sysctl, "I",
6075 "Length of segments above which a tap is ignored");
6077 /* hw.psm.synaptics.tap_min_queue. */
6078 sc->syninfo.tap_min_queue = 2;
6079 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6080 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6081 "tap_min_queue", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6082 sc, SYNAPTICS_SYSCTL_TAP_MIN_QUEUE,
6083 synaptics_sysctl, "I",
6084 "Number of packets required to consider a tap");
6086 /* hw.psm.synaptics.taphold_timeout. */
6087 sc->gesture.in_taphold = 0;
6088 sc->syninfo.taphold_timeout = tap_timeout;
6089 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6090 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6091 "taphold_timeout", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6092 sc, SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT,
6093 synaptics_sysctl, "I",
6094 "Maximum elapsed time between two taps to consider a tap-hold "
6097 /* hw.psm.synaptics.vscroll_hor_area. */
6098 sc->syninfo.vscroll_hor_area = 0; /* 1300 */
6099 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6100 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6101 "vscroll_hor_area", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6102 sc, SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA,
6103 synaptics_sysctl, "I",
6104 "Area reserved for horizontal virtual scrolling");
6106 /* hw.psm.synaptics.vscroll_ver_area. */
6107 sc->syninfo.vscroll_ver_area = -400 - sc->syninfo.margin_right;
6108 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6109 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6110 "vscroll_ver_area", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6111 sc, SYNAPTICS_SYSCTL_VSCROLL_VER_AREA,
6112 synaptics_sysctl, "I",
6113 "Area reserved for vertical virtual scrolling");
6115 /* hw.psm.synaptics.vscroll_min_delta. */
6116 sc->syninfo.vscroll_min_delta = 50;
6117 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6118 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6119 "vscroll_min_delta", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6120 sc, SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA,
6121 synaptics_sysctl, "I",
6122 "Minimum movement to consider virtual scrolling");
6124 /* hw.psm.synaptics.vscroll_div_min. */
6125 sc->syninfo.vscroll_div_min = 100;
6126 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6127 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6128 "vscroll_div_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6129 sc, SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN,
6130 synaptics_sysctl, "I",
6131 "Divisor for fast scrolling");
6133 /* hw.psm.synaptics.vscroll_div_min. */
6134 sc->syninfo.vscroll_div_max = 150;
6135 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6136 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6137 "vscroll_div_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6138 sc, SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX,
6139 synaptics_sysctl, "I",
6140 "Divisor for slow scrolling");
6142 /* hw.psm.synaptics.touchpad_off. */
6143 sc->syninfo.touchpad_off = 0;
6144 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6145 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6146 "touchpad_off", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6147 sc, SYNAPTICS_SYSCTL_TOUCHPAD_OFF,
6148 synaptics_sysctl, "I",
6149 "Turn off touchpad");
6151 /* hw.psm.synaptics.natural_scroll. */
6152 sc->syninfo.natural_scroll = 0;
6153 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
6154 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
6155 "natural_scroll", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6156 sc, SYNAPTICS_SYSCTL_NATURAL_SCROLL,
6157 synaptics_sysctl, "I",
6158 "Enable natural scrolling");
6160 sc->syninfo.softbuttons_y = 0;
6161 sc->syninfo.softbutton2_x = 0;
6162 sc->syninfo.softbutton3_x = 0;
6164 /* skip softbuttons sysctl on not clickpads */
6165 if (sc->synhw.capClickPad)
6166 synaptics_sysctl_create_softbuttons_tree(sc);
6170 synaptics_preferred_mode(struct psm_softc *sc) {
6173 /* Check if we are in relative mode */
6174 if (sc->hw.model != MOUSE_MODEL_SYNAPTICS) {
6175 if (tap_enabled == 0)
6177 * Disable tap & drag gestures. We use a Mode Byte
6178 * and set the DisGest bit (see §2.5 of Synaptics
6179 * TouchPad Interfacing Guide).
6184 * Enable tap & drag gestures. We use a Mode Byte
6185 * and clear the DisGest bit (see §2.5 of Synaptics
6186 * TouchPad Interfacing Guide).
6193 /* request wmode where available */
6194 if (sc->synhw.capExtended)
6201 synaptics_set_mode(struct psm_softc *sc, int mode_byte) {
6202 mouse_ext_command(sc->kbdc, mode_byte);
6204 /* "Commit" the Set Mode Byte command sent above. */
6205 set_mouse_sampling_rate(sc->kbdc, 20);
6208 * Enable advanced gestures mode if supported and we are not entering
6209 * passthrough or relative mode.
6211 if ((sc->synhw.capAdvancedGestures || sc->synhw.capReportsV) &&
6212 sc->hw.model == MOUSE_MODEL_SYNAPTICS && !(mode_byte & (1 << 5))) {
6213 mouse_ext_command(sc->kbdc, SYNAPTICS_READ_MODEL_ID);
6214 set_mouse_sampling_rate(sc->kbdc, 0xc8);
6219 * AUX MUX detection code should be placed at very beginning of probe sequence
6220 * at least before 4-byte protocol mouse probes e.g. MS IntelliMouse probe as
6221 * latter can trigger switching the MUX to incompatible state.
6224 enable_synaptics_mux(struct psm_softc *sc, enum probearg arg)
6226 KBDC kbdc = sc->kbdc;
6229 int active_ports_count = 0;
6230 int active_ports_mask = 0;
6232 version = enable_aux_mux(kbdc);
6236 for (port = 0; port < KBDC_AUX_MUX_NUM_PORTS; port++) {
6237 VLOG(3, (LOG_DEBUG, "aux_mux: ping port %d\n", port));
6238 set_active_aux_mux_port(kbdc, port);
6239 if (enable_aux_dev(kbdc) && disable_aux_dev(kbdc)) {
6240 active_ports_count++;
6241 active_ports_mask |= 1 << port;
6246 printf("Active Multiplexing PS/2 controller v%d.%d with %d "
6247 "active port(s)\n", version >> 4 & 0x0f, version & 0x0f,
6248 active_ports_count);
6250 /* psm has a special support for GenMouse + SynTouchpad combination */
6251 if (active_ports_count >= 2) {
6252 for (port = 0; port < KBDC_AUX_MUX_NUM_PORTS; port++) {
6253 if ((active_ports_mask & 1 << port) == 0)
6255 VLOG(3, (LOG_DEBUG, "aux_mux: probe port %d\n", port));
6256 set_active_aux_mux_port(kbdc, port);
6257 probe = enable_synaptics(sc, arg);
6266 /* IRQ handler does not support active multiplexing mode */
6267 disable_aux_mux(kbdc);
6273 enable_synaptics(struct psm_softc *sc, enum probearg arg)
6276 struct psmcpnp_softc *psmcpnp_sc;
6277 KBDC kbdc = sc->kbdc;
6278 synapticshw_t synhw;
6282 VLOG(3, (LOG_DEBUG, "synaptics: BEGIN init\n"));
6285 * Just to be on the safe side: this avoids troubles with
6286 * following mouse_ext_command() when the previous command
6287 * was PSMC_SET_RESOLUTION. Set Scaling has no effect on
6288 * Synaptics Touchpad behaviour.
6290 set_mouse_scaling(kbdc, 1);
6292 /* Identify the Touchpad version. */
6293 if (mouse_ext_command(kbdc, SYNAPTICS_READ_IDENTITY) == 0)
6295 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6297 if (status[1] != 0x47)
6300 bzero(&synhw, sizeof(synhw));
6301 synhw.infoMinor = status[0];
6302 synhw.infoMajor = status[2] & 0x0f;
6305 printf("Synaptics Touchpad v%d.%d\n", synhw.infoMajor,
6308 if (synhw.infoMajor < 4) {
6309 printf(" Unsupported (pre-v4) Touchpad detected\n");
6313 /* Get the Touchpad model information. */
6314 if (mouse_ext_command(kbdc, SYNAPTICS_READ_MODEL_ID) == 0)
6316 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6318 if ((status[1] & 0x01) != 0) {
6319 printf(" Failed to read model information\n");
6323 synhw.infoRot180 = (status[0] & 0x80) != 0;
6324 synhw.infoPortrait = (status[0] & 0x40) != 0;
6325 synhw.infoSensor = status[0] & 0x3f;
6326 synhw.infoHardware = (status[1] & 0xfe) >> 1;
6327 synhw.infoNewAbs = (status[2] & 0x80) != 0;
6328 synhw.capPen = (status[2] & 0x40) != 0;
6329 synhw.infoSimplC = (status[2] & 0x20) != 0;
6330 synhw.infoGeometry = status[2] & 0x0f;
6333 printf(" Model information:\n");
6334 printf(" infoRot180: %d\n", synhw.infoRot180);
6335 printf(" infoPortrait: %d\n", synhw.infoPortrait);
6336 printf(" infoSensor: %d\n", synhw.infoSensor);
6337 printf(" infoHardware: %d\n", synhw.infoHardware);
6338 printf(" infoNewAbs: %d\n", synhw.infoNewAbs);
6339 printf(" capPen: %d\n", synhw.capPen);
6340 printf(" infoSimplC: %d\n", synhw.infoSimplC);
6341 printf(" infoGeometry: %d\n", synhw.infoGeometry);
6344 /* Read the extended capability bits. */
6345 if (mouse_ext_command(kbdc, SYNAPTICS_READ_CAPABILITIES) == 0)
6347 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6349 if (!SYNAPTICS_VERSION_GE(synhw, 7, 5) && status[1] != 0x47) {
6350 printf(" Failed to read extended capability bits\n");
6354 psmcpnp = devclass_get_device(devclass_find(PSMCPNP_DRIVER_NAME),
6356 psmcpnp_sc = (psmcpnp != NULL) ? device_get_softc(psmcpnp) : NULL;
6358 /* Set the different capabilities when they exist. */
6360 synhw.capExtended = (status[0] & 0x80) != 0;
6361 if (synhw.capExtended) {
6362 synhw.nExtendedQueries = (status[0] & 0x70) >> 4;
6363 synhw.capMiddle = (status[0] & 0x04) != 0;
6364 synhw.capPassthrough = (status[2] & 0x80) != 0;
6365 synhw.capLowPower = (status[2] & 0x40) != 0;
6366 synhw.capMultiFingerReport =
6367 (status[2] & 0x20) != 0;
6368 synhw.capSleep = (status[2] & 0x10) != 0;
6369 synhw.capFourButtons = (status[2] & 0x08) != 0;
6370 synhw.capBallistics = (status[2] & 0x04) != 0;
6371 synhw.capMultiFinger = (status[2] & 0x02) != 0;
6372 synhw.capPalmDetect = (status[2] & 0x01) != 0;
6374 if (!set_mouse_scaling(kbdc, 1))
6376 if (mouse_ext_command(kbdc, SYNAPTICS_READ_RESOLUTIONS) == 0)
6378 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6381 if (status[0] != 0 && (status[1] & 0x80) && status[2] != 0) {
6382 synhw.infoXupmm = status[0];
6383 synhw.infoYupmm = status[2];
6387 printf(" Extended capabilities:\n");
6388 printf(" capExtended: %d\n", synhw.capExtended);
6389 printf(" capMiddle: %d\n", synhw.capMiddle);
6390 printf(" nExtendedQueries: %d\n",
6391 synhw.nExtendedQueries);
6392 printf(" capPassthrough: %d\n", synhw.capPassthrough);
6393 printf(" capLowPower: %d\n", synhw.capLowPower);
6394 printf(" capMultiFingerReport: %d\n",
6395 synhw.capMultiFingerReport);
6396 printf(" capSleep: %d\n", synhw.capSleep);
6397 printf(" capFourButtons: %d\n", synhw.capFourButtons);
6398 printf(" capBallistics: %d\n", synhw.capBallistics);
6399 printf(" capMultiFinger: %d\n", synhw.capMultiFinger);
6400 printf(" capPalmDetect: %d\n", synhw.capPalmDetect);
6401 printf(" infoXupmm: %d\n", synhw.infoXupmm);
6402 printf(" infoYupmm: %d\n", synhw.infoYupmm);
6406 * If nExtendedQueries is 1 or greater, then the TouchPad
6407 * supports this number of extended queries. We can load
6408 * more information about buttons using query 0x09.
6410 if (synhw.nExtendedQueries >= 1) {
6411 if (!set_mouse_scaling(kbdc, 1))
6413 if (mouse_ext_command(kbdc,
6414 SYNAPTICS_READ_EXTENDED) == 0)
6416 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6418 synhw.verticalScroll = (status[0] & 0x01) != 0;
6419 synhw.horizontalScroll = (status[0] & 0x02) != 0;
6420 synhw.verticalWheel = (status[0] & 0x08) != 0;
6421 synhw.nExtendedButtons = (status[1] & 0xf0) >> 4;
6422 synhw.capEWmode = (status[0] & 0x04) != 0;
6424 printf(" Extended model ID:\n");
6425 printf(" verticalScroll: %d\n",
6426 synhw.verticalScroll);
6427 printf(" horizontalScroll: %d\n",
6428 synhw.horizontalScroll);
6429 printf(" verticalWheel: %d\n",
6430 synhw.verticalWheel);
6431 printf(" nExtendedButtons: %d\n",
6432 synhw.nExtendedButtons);
6433 printf(" capEWmode: %d\n",
6437 * Add the number of extended buttons to the total
6438 * button support count, including the middle button
6439 * if capMiddle support bit is set.
6441 buttons = synhw.nExtendedButtons + synhw.capMiddle;
6444 * If the capFourButtons support bit is set,
6445 * add a fourth button to the total button count.
6447 buttons = synhw.capFourButtons ? 1 : 0;
6449 /* Read the continued capabilities bits. */
6450 if (synhw.nExtendedQueries >= 4) {
6451 if (!set_mouse_scaling(kbdc, 1))
6453 if (mouse_ext_command(kbdc,
6454 SYNAPTICS_READ_CAPABILITIES_CONT) == 0)
6456 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6459 synhw.capClickPad = (status[1] & 0x01) << 1;
6460 synhw.capClickPad |= (status[0] & 0x10) != 0;
6461 synhw.capDeluxeLEDs = (status[1] & 0x02) != 0;
6462 synhw.noAbsoluteFilter = (status[1] & 0x04) != 0;
6463 synhw.capReportsV = (status[1] & 0x08) != 0;
6464 synhw.capUniformClickPad = (status[1] & 0x10) != 0;
6465 synhw.capReportsMin = (status[1] & 0x20) != 0;
6466 synhw.capInterTouch = (status[1] & 0x40) != 0;
6467 synhw.capReportsMax = (status[0] & 0x02) != 0;
6468 synhw.capClearPad = (status[0] & 0x04) != 0;
6469 synhw.capAdvancedGestures = (status[0] & 0x08) != 0;
6470 synhw.capCoveredPad = (status[0] & 0x80) != 0;
6472 if (synhw.capReportsMax) {
6473 if (!set_mouse_scaling(kbdc, 1))
6475 if (mouse_ext_command(kbdc,
6476 SYNAPTICS_READ_MAX_COORDS) == 0)
6478 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6481 synhw.maximumXCoord = (status[0] << 5) |
6482 ((status[1] & 0x0f) << 1);
6483 synhw.maximumYCoord = (status[2] << 5) |
6484 ((status[1] & 0xf0) >> 3);
6487 * Typical bezel limits. Taken from 'Synaptics
6488 * PS/2 * TouchPad Interfacing Guide' p.3.2.3.
6490 synhw.maximumXCoord = 5472;
6491 synhw.maximumYCoord = 4448;
6494 if (synhw.capReportsMin) {
6495 if (!set_mouse_scaling(kbdc, 1))
6497 if (mouse_ext_command(kbdc,
6498 SYNAPTICS_READ_MIN_COORDS) == 0)
6500 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6503 synhw.minimumXCoord = (status[0] << 5) |
6504 ((status[1] & 0x0f) << 1);
6505 synhw.minimumYCoord = (status[2] << 5) |
6506 ((status[1] & 0xf0) >> 3);
6509 * Typical bezel limits. Taken from 'Synaptics
6510 * PS/2 * TouchPad Interfacing Guide' p.3.2.3.
6512 synhw.minimumXCoord = 1472;
6513 synhw.minimumYCoord = 1408;
6517 * ClickPad properties are not exported through PS/2
6518 * protocol. Detection is based on controller's PnP ID.
6520 if (synhw.capClickPad && psmcpnp_sc != NULL) {
6521 switch (psmcpnp_sc->type) {
6522 case PSMCPNP_FORCEPAD:
6525 case PSMCPNP_TOPBUTTONPAD:
6526 synhw.topButtonPad = 1;
6534 printf(" Continued capabilities:\n");
6535 printf(" capClickPad: %d\n",
6537 printf(" capDeluxeLEDs: %d\n",
6538 synhw.capDeluxeLEDs);
6539 printf(" noAbsoluteFilter: %d\n",
6540 synhw.noAbsoluteFilter);
6541 printf(" capReportsV: %d\n",
6543 printf(" capUniformClickPad: %d\n",
6544 synhw.capUniformClickPad);
6545 printf(" capReportsMin: %d\n",
6546 synhw.capReportsMin);
6547 printf(" capInterTouch: %d\n",
6548 synhw.capInterTouch);
6549 printf(" capReportsMax: %d\n",
6550 synhw.capReportsMax);
6551 printf(" capClearPad: %d\n",
6553 printf(" capAdvancedGestures: %d\n",
6554 synhw.capAdvancedGestures);
6555 printf(" capCoveredPad: %d\n",
6556 synhw.capCoveredPad);
6557 if (synhw.capReportsMax) {
6558 printf(" maximumXCoord: %d\n",
6559 synhw.maximumXCoord);
6560 printf(" maximumYCoord: %d\n",
6561 synhw.maximumYCoord);
6563 if (synhw.capReportsMin) {
6564 printf(" minimumXCoord: %d\n",
6565 synhw.minimumXCoord);
6566 printf(" minimumYCoord: %d\n",
6567 synhw.minimumYCoord);
6569 if (synhw.capClickPad) {
6570 printf(" Clickpad capabilities:\n");
6571 printf(" forcePad: %d\n",
6573 printf(" topButtonPad: %d\n",
6574 synhw.topButtonPad);
6577 buttons += synhw.capClickPad;
6582 if (synhw.capExtended)
6583 printf(" Additional Buttons: %d\n", buttons);
6585 printf(" No extended capabilities\n");
6589 * Add the default number of 3 buttons to the total
6590 * count of supported buttons reported above.
6595 * Read the mode byte.
6597 * XXX: Note the Synaptics documentation also defines the first
6598 * byte of the response to this query to be a constant 0x3b, this
6599 * does not appear to be true for Touchpads with guest devices.
6601 if (mouse_ext_command(kbdc, SYNAPTICS_READ_MODES) == 0)
6603 if (get_mouse_status(kbdc, status, 0, 3) != 3)
6605 if (!SYNAPTICS_VERSION_GE(synhw, 7, 5) && status[1] != 0x47) {
6606 printf(" Failed to read mode byte\n");
6612 if (!synaptics_support)
6615 /* Set mouse type just now for synaptics_set_mode() */
6616 sc->hw.model = MOUSE_MODEL_SYNAPTICS;
6618 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
6620 if (trackpoint_support && synhw.capPassthrough) {
6621 enable_trackpoint(sc, arg);
6624 VLOG(3, (LOG_DEBUG, "synaptics: END init (%d buttons)\n", buttons));
6627 /* Create sysctl tree. */
6628 synaptics_sysctl_create_tree(sc, "synaptics",
6629 "Synaptics TouchPad");
6630 sc->hw.buttons = buttons;
6637 synaptics_passthrough_on(struct psm_softc *sc)
6639 VLOG(2, (LOG_NOTICE, "psm: setting pass-through mode.\n"));
6640 synaptics_set_mode(sc, synaptics_preferred_mode(sc) | (1 << 5));
6644 synaptics_passthrough_off(struct psm_softc *sc)
6646 VLOG(2, (LOG_NOTICE, "psm: turning pass-through mode off.\n"));
6647 set_mouse_scaling(sc->kbdc, 2);
6648 set_mouse_scaling(sc->kbdc, 1);
6649 synaptics_set_mode(sc, synaptics_preferred_mode(sc));
6652 /* IBM/Lenovo TrackPoint */
6654 trackpoint_command(struct psm_softc *sc, int cmd, int loc, int val)
6656 const int seq[] = { 0xe2, cmd, loc, val };
6659 if (sc->synhw.capPassthrough)
6660 synaptics_passthrough_on(sc);
6662 for (i = 0; i < nitems(seq); i++) {
6663 if (sc->synhw.capPassthrough &&
6664 (seq[i] == 0xff || seq[i] == 0xe7))
6665 if (send_aux_command(sc->kbdc, 0xe7) != PSM_ACK) {
6666 synaptics_passthrough_off(sc);
6669 if (send_aux_command(sc->kbdc, seq[i]) != PSM_ACK) {
6670 if (sc->synhw.capPassthrough)
6671 synaptics_passthrough_off(sc);
6676 if (sc->synhw.capPassthrough)
6677 synaptics_passthrough_off(sc);
6682 #define PSM_TPINFO(x) offsetof(struct psm_softc, tpinfo.x)
6688 trackpoint_sysctl(SYSCTL_HANDLER_ARGS)
6690 static const int data[][3] = {
6691 { 0x00, 0x4a, PSM_TPINFO(sensitivity) },
6692 { 0x00, 0x4d, PSM_TPINFO(inertia) },
6693 { 0x00, 0x60, PSM_TPINFO(uplateau) },
6694 { 0x00, 0x57, PSM_TPINFO(reach) },
6695 { 0x00, 0x58, PSM_TPINFO(draghys) },
6696 { 0x00, 0x59, PSM_TPINFO(mindrag) },
6697 { 0x00, 0x5a, PSM_TPINFO(upthresh) },
6698 { 0x00, 0x5c, PSM_TPINFO(threshold) },
6699 { 0x00, 0x5d, PSM_TPINFO(jenks) },
6700 { 0x00, 0x5e, PSM_TPINFO(ztime) },
6701 { 0x01, 0x2c, PSM_TPINFO(pts) },
6702 { 0x08, 0x2d, PSM_TPINFO(skipback) }
6704 struct psm_softc *sc;
6705 int error, newval, *oldvalp;
6708 if (arg1 == NULL || arg2 < 0 || arg2 >= nitems(data))
6712 oldvalp = (int *)((intptr_t)sc + tp[TPINFO]);
6714 error = sysctl_handle_int(oidp, &newval, 0, req);
6717 if (newval == *oldvalp)
6719 if (newval < 0 || newval > (tp[TPMASK] == 0 ? 255 : 1))
6721 error = trackpoint_command(sc, tp[TPMASK] == 0 ? 0x81 : 0x47,
6722 tp[TPLOC], tp[TPMASK] == 0 ? newval : tp[TPMASK]);
6731 trackpoint_sysctl_create_tree(struct psm_softc *sc)
6734 if (sc->tpinfo.sysctl_tree != NULL)
6737 /* Attach extra trackpoint sysctl nodes under hw.psm.trackpoint */
6738 sysctl_ctx_init(&sc->tpinfo.sysctl_ctx);
6739 sc->tpinfo.sysctl_tree = SYSCTL_ADD_NODE(&sc->tpinfo.sysctl_ctx,
6740 SYSCTL_STATIC_CHILDREN(_hw_psm), OID_AUTO, "trackpoint", CTLFLAG_RD,
6741 0, "IBM/Lenovo TrackPoint");
6743 /* hw.psm.trackpoint.sensitivity */
6744 sc->tpinfo.sensitivity = 0x80;
6745 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6746 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6747 "sensitivity", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6748 sc, TRACKPOINT_SYSCTL_SENSITIVITY,
6749 trackpoint_sysctl, "I",
6752 /* hw.psm.trackpoint.negative_inertia */
6753 sc->tpinfo.inertia = 0x06;
6754 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6755 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6756 "negative_inertia", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6757 sc, TRACKPOINT_SYSCTL_NEGATIVE_INERTIA,
6758 trackpoint_sysctl, "I",
6759 "Negative inertia factor");
6761 /* hw.psm.trackpoint.upper_plateau */
6762 sc->tpinfo.uplateau = 0x61;
6763 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6764 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6765 "upper_plateau", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6766 sc, TRACKPOINT_SYSCTL_UPPER_PLATEAU,
6767 trackpoint_sysctl, "I",
6768 "Transfer function upper plateau speed");
6770 /* hw.psm.trackpoint.backup_range */
6771 sc->tpinfo.reach = 0x0a;
6772 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6773 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6774 "backup_range", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6775 sc, TRACKPOINT_SYSCTL_BACKUP_RANGE,
6776 trackpoint_sysctl, "I",
6779 /* hw.psm.trackpoint.drag_hysteresis */
6780 sc->tpinfo.draghys = 0xff;
6781 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6782 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6783 "drag_hysteresis", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6784 sc, TRACKPOINT_SYSCTL_DRAG_HYSTERESIS,
6785 trackpoint_sysctl, "I",
6788 /* hw.psm.trackpoint.minimum_drag */
6789 sc->tpinfo.mindrag = 0x14;
6790 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6791 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6792 "minimum_drag", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6793 sc, TRACKPOINT_SYSCTL_MINIMUM_DRAG,
6794 trackpoint_sysctl, "I",
6797 /* hw.psm.trackpoint.up_threshold */
6798 sc->tpinfo.upthresh = 0xff;
6799 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6800 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6801 "up_threshold", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6802 sc, TRACKPOINT_SYSCTL_UP_THRESHOLD,
6803 trackpoint_sysctl, "I",
6804 "Up threshold for release");
6806 /* hw.psm.trackpoint.threshold */
6807 sc->tpinfo.threshold = 0x08;
6808 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6809 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6810 "threshold", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6811 sc, TRACKPOINT_SYSCTL_THRESHOLD,
6812 trackpoint_sysctl, "I",
6815 /* hw.psm.trackpoint.jenks_curvature */
6816 sc->tpinfo.jenks = 0x87;
6817 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6818 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6819 "jenks_curvature", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6820 sc, TRACKPOINT_SYSCTL_JENKS_CURVATURE,
6821 trackpoint_sysctl, "I",
6824 /* hw.psm.trackpoint.z_time */
6825 sc->tpinfo.ztime = 0x26;
6826 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6827 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6828 "z_time", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6829 sc, TRACKPOINT_SYSCTL_Z_TIME,
6830 trackpoint_sysctl, "I",
6833 /* hw.psm.trackpoint.press_to_select */
6834 sc->tpinfo.pts = 0x00;
6835 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6836 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6837 "press_to_select", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6838 sc, TRACKPOINT_SYSCTL_PRESS_TO_SELECT,
6839 trackpoint_sysctl, "I",
6842 /* hw.psm.trackpoint.skip_backups */
6843 sc->tpinfo.skipback = 0x00;
6844 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
6845 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
6846 "skip_backups", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
6847 sc, TRACKPOINT_SYSCTL_SKIP_BACKUPS,
6848 trackpoint_sysctl, "I",
6849 "Skip backups from drags");
6853 set_trackpoint_parameters(struct psm_softc *sc)
6855 trackpoint_command(sc, 0x81, 0x4a, sc->tpinfo.sensitivity);
6856 trackpoint_command(sc, 0x81, 0x60, sc->tpinfo.uplateau);
6857 trackpoint_command(sc, 0x81, 0x4d, sc->tpinfo.inertia);
6858 trackpoint_command(sc, 0x81, 0x57, sc->tpinfo.reach);
6859 trackpoint_command(sc, 0x81, 0x58, sc->tpinfo.draghys);
6860 trackpoint_command(sc, 0x81, 0x59, sc->tpinfo.mindrag);
6861 trackpoint_command(sc, 0x81, 0x5a, sc->tpinfo.upthresh);
6862 trackpoint_command(sc, 0x81, 0x5c, sc->tpinfo.threshold);
6863 trackpoint_command(sc, 0x81, 0x5d, sc->tpinfo.jenks);
6864 trackpoint_command(sc, 0x81, 0x5e, sc->tpinfo.ztime);
6865 if (sc->tpinfo.pts == 0x01)
6866 trackpoint_command(sc, 0x47, 0x2c, 0x01);
6867 if (sc->tpinfo.skipback == 0x01)
6868 trackpoint_command(sc, 0x47, 0x2d, 0x08);
6872 enable_trackpoint(struct psm_softc *sc, enum probearg arg)
6874 KBDC kbdc = sc->kbdc;
6878 * If called from enable_synaptics(), make sure that passthrough
6879 * mode is enabled so we can reach the trackpoint.
6880 * However, passthrough mode must be disabled before setting the
6881 * trackpoint parameters, as rackpoint_command() enables and disables
6882 * passthrough mode on its own.
6884 if (sc->synhw.capPassthrough)
6885 synaptics_passthrough_on(sc);
6887 if (send_aux_command(kbdc, 0xe1) != PSM_ACK ||
6888 read_aux_data(kbdc) != 0x01)
6890 id = read_aux_data(kbdc);
6895 if (!trackpoint_support)
6898 if (sc->synhw.capPassthrough)
6899 synaptics_passthrough_off(sc);
6902 trackpoint_sysctl_create_tree(sc);
6904 * Don't overwrite hwid and buttons when we are
6907 if (!sc->synhw.capPassthrough) {
6913 set_trackpoint_parameters(sc);
6918 if (sc->synhw.capPassthrough)
6919 synaptics_passthrough_off(sc);
6924 /* Interlink electronics VersaPad */
6926 enable_versapad(struct psm_softc *sc, enum probearg arg)
6928 KBDC kbdc = sc->kbdc;
6931 set_mouse_resolution(kbdc, PSMD_RES_MEDIUM_HIGH); /* set res. 2 */
6932 set_mouse_sampling_rate(kbdc, 100); /* set rate 100 */
6933 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
6934 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
6935 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
6936 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
6937 if (get_mouse_status(kbdc, data, 0, 3) < 3) /* get status */
6939 if (data[2] != 0xa || data[1] != 0 ) /* rate == 0xa && res. == 0 */
6941 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
6943 return (TRUE); /* PS/2 absolute mode */
6946 /* Elantech Touchpad */
6948 elantech_read_1(KBDC kbdc, int hwversion, int reg, int *val)
6950 int res, readcmd, retidx;
6953 readcmd = hwversion == 2 ? ELANTECH_REG_READ : ELANTECH_REG_RDWR;
6954 retidx = hwversion == 4 ? 1 : 0;
6956 res = send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6957 res |= send_aux_command(kbdc, readcmd) != PSM_ACK;
6958 res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6959 res |= send_aux_command(kbdc, reg) != PSM_ACK;
6960 res |= get_mouse_status(kbdc, resp, 0, 3) != 3;
6963 *val = resp[retidx];
6969 elantech_write_1(KBDC kbdc, int hwversion, int reg, int val)
6973 writecmd = hwversion == 2 ? ELANTECH_REG_WRITE : ELANTECH_REG_RDWR;
6975 res = send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6976 res |= send_aux_command(kbdc, writecmd) != PSM_ACK;
6977 res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6978 res |= send_aux_command(kbdc, reg) != PSM_ACK;
6979 if (hwversion == 4) {
6980 res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6981 res |= send_aux_command(kbdc, writecmd) != PSM_ACK;
6983 res |= send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
6984 res |= send_aux_command(kbdc, val) != PSM_ACK;
6985 res |= set_mouse_scaling(kbdc, 1) == 0;
6991 elantech_cmd(KBDC kbdc, int hwversion, int cmd, int *resp)
6995 if (hwversion == 2) {
6996 res = set_mouse_scaling(kbdc, 1) == 0;
6997 res |= mouse_ext_command(kbdc, cmd) == 0;
6999 res = send_aux_command(kbdc, ELANTECH_CUSTOM_CMD) != PSM_ACK;
7000 res |= send_aux_command(kbdc, cmd) != PSM_ACK;
7002 res |= get_mouse_status(kbdc, resp, 0, 3) != 3;
7008 elantech_init(KBDC kbdc, elantechhw_t *elanhw)
7010 int i, val, res, hwversion, reg10;
7012 /* set absolute mode */
7013 hwversion = elanhw->hwversion;
7015 switch (hwversion) {
7017 reg10 = elanhw->fwversion == 0x020030 ? 0x54 : 0xc4;
7018 res = elantech_write_1(kbdc, hwversion, 0x10, reg10);
7021 res = elantech_write_1(kbdc, hwversion, 0x11, 0x8A);
7025 res = elantech_write_1(kbdc, hwversion, 0x10, reg10);
7028 res = elantech_write_1(kbdc, hwversion, 0x07, 0x01);
7034 /* Read back reg 0x10 to ensure hardware is ready. */
7035 if (res == 0 && reg10 >= 0) {
7036 for (i = 0; i < 5; i++) {
7037 if (elantech_read_1(kbdc, hwversion, 0x10, &val) == 0)
7046 printf("couldn't set absolute mode\n");
7052 elantech_init_synaptics(struct psm_softc *sc)
7055 /* Set capabilites required by movement smother */
7056 sc->synhw.infoMajor = sc->elanhw.hwversion;
7057 sc->synhw.infoMinor = sc->elanhw.fwversion;
7058 sc->synhw.infoXupmm = sc->elanhw.dpmmx;
7059 sc->synhw.infoYupmm = sc->elanhw.dpmmy;
7060 sc->synhw.verticalScroll = 0;
7061 sc->synhw.nExtendedQueries = 4;
7062 sc->synhw.capExtended = 1;
7063 sc->synhw.capPassthrough = sc->elanhw.hastrackpoint;
7064 sc->synhw.capClickPad = sc->elanhw.isclickpad;
7065 sc->synhw.capMultiFinger = 1;
7066 if (sc->elanhw.issemimt)
7067 sc->synhw.capAdvancedGestures = 1;
7069 sc->synhw.capReportsV = 1;
7070 sc->synhw.capPalmDetect = 1;
7071 sc->synhw.capPen = 0;
7072 sc->synhw.capReportsMax = 1;
7073 sc->synhw.maximumXCoord = sc->elanhw.sizex;
7074 sc->synhw.maximumYCoord = sc->elanhw.sizey;
7075 sc->synhw.capReportsMin = 1;
7076 sc->synhw.minimumXCoord = 0;
7077 sc->synhw.minimumYCoord = 0;
7079 if (sc->syninfo.sysctl_tree == NULL) {
7080 synaptics_sysctl_create_tree(sc, "elantech",
7081 "Elantech Touchpad");
7084 * Adjust synaptic smoother tunables
7085 * 1. Disable finger detection pressure threshold. Unlike
7086 * synaptics we assume the finger is acting when packet with
7087 * its X&Y arrives not when pressure exceedes some threshold
7088 * 2. Disable unrelated features like margins and noisy areas
7089 * 3. Disable virtual scroll areas as 2nd finger is preferable
7090 * 4. For clickpads set bottom quarter as 42% - 16% - 42% sized
7092 * 5. Scale down divisors and movement lengths by a factor of 3
7093 * where 3 is Synaptics to Elantech (~2200/800) dpi ratio
7096 /* Set reporting range to be equal touchpad size */
7097 sc->syninfo.max_x = sc->elanhw.sizex;
7098 sc->syninfo.max_y = sc->elanhw.sizey;
7100 /* Disable finger detection pressure threshold */
7101 sc->syninfo.min_pressure = 1;
7103 /* Adjust palm width to nearly match synaptics w=10 */
7104 sc->syninfo.max_width = 7;
7106 /* Elans often report double & triple taps as single event */
7107 sc->syninfo.tap_min_queue = 1;
7109 /* Use full area of touchpad */
7110 sc->syninfo.margin_top = 0;
7111 sc->syninfo.margin_right = 0;
7112 sc->syninfo.margin_bottom = 0;
7113 sc->syninfo.margin_left = 0;
7115 /* Disable noisy area */
7116 sc->syninfo.na_top = 0;
7117 sc->syninfo.na_right = 0;
7118 sc->syninfo.na_bottom = 0;
7119 sc->syninfo.na_left = 0;
7121 /* Tune divisors and movement lengths */
7122 sc->syninfo.weight_len_squared = 200;
7123 sc->syninfo.div_min = 3;
7124 sc->syninfo.div_max = 6;
7125 sc->syninfo.div_max_na = 10;
7126 sc->syninfo.div_len = 30;
7127 sc->syninfo.tap_max_delta = 25;
7129 /* Disable virtual scrolling areas and tune its divisors */
7130 sc->syninfo.vscroll_hor_area = 0;
7131 sc->syninfo.vscroll_ver_area = 0;
7132 sc->syninfo.vscroll_min_delta = 15;
7133 sc->syninfo.vscroll_div_min = 30;
7134 sc->syninfo.vscroll_div_max = 50;
7136 /* Set bottom quarter as 42% - 16% - 42% sized softbuttons */
7137 if (sc->elanhw.isclickpad) {
7138 sc->syninfo.softbuttons_y = sc->elanhw.sizey / 4;
7139 sc->syninfo.softbutton2_x = sc->elanhw.sizex * 11 / 25;
7140 sc->syninfo.softbutton3_x = sc->elanhw.sizex * 14 / 25;
7148 enable_elantech(struct psm_softc *sc, enum probearg arg)
7150 static const int ic2hw[] =
7151 /*IC: 0 1 2 3 4 5 6 7 8 9 a b c d e f */
7152 { 0, 0, 2, 0, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 };
7153 static const int fw_sizes[][3] = {
7154 /* FW.vers MaxX MaxY */
7155 { 0x020030, 1152, 768 },
7156 { 0x020800, 1152, 768 },
7157 { 0x020b00, 1152, 768 },
7158 { 0x040215, 900, 500 },
7159 { 0x040216, 819, 405 },
7160 { 0x040219, 900, 500 },
7162 elantechhw_t elanhw;
7163 int icversion, hwversion, xtr, i, id, resp[3], dpix, dpiy;
7164 KBDC kbdc = sc->kbdc;
7166 VLOG(3, (LOG_DEBUG, "elantech: BEGIN init\n"));
7168 set_mouse_scaling(kbdc, 1);
7169 set_mouse_scaling(kbdc, 1);
7170 set_mouse_scaling(kbdc, 1);
7171 if (get_mouse_status(kbdc, resp, 0, 3) != 3)
7174 if (!ELANTECH_MAGIC(resp))
7177 /* Identify the Touchpad version. */
7178 if (elantech_cmd(kbdc, 2, ELANTECH_FW_VERSION, resp))
7181 bzero(&elanhw, sizeof(elanhw));
7183 elanhw.fwversion = (resp[0] << 16) | (resp[1] << 8) | resp[2];
7184 icversion = resp[0] & 0x0f;
7185 hwversion = ic2hw[icversion];
7188 printf("Elantech touchpad hardware v.%d firmware v.0x%06x\n",
7189 hwversion, elanhw.fwversion);
7191 if (ELANTECH_HW_IS_V1(elanhw.fwversion)) {
7192 printf (" Unsupported touchpad hardware (v1)\n");
7195 if (hwversion == 0) {
7196 printf (" Unknown touchpad hardware (firmware v.0x%06x)\n",
7201 /* Get the Touchpad model information. */
7202 elanhw.hwversion = hwversion;
7203 elanhw.issemimt = hwversion == 2;
7204 elanhw.isclickpad = (resp[1] & 0x10) != 0;
7205 elanhw.hascrc = (resp[1] & 0x40) != 0;
7206 elanhw.haspressure = elanhw.fwversion >= 0x020800;
7208 /* Read the capability bits. */
7209 if (elantech_cmd(kbdc, hwversion, ELANTECH_CAPABILITIES, resp) != 0) {
7210 printf(" Failed to read capability bits\n");
7214 elanhw.ntracesx = imax(resp[1], 3);
7215 elanhw.ntracesy = imax(resp[2], 3);
7216 elanhw.hastrackpoint = (resp[0] & 0x80) != 0;
7218 /* Get the touchpad resolution */
7219 switch (hwversion) {
7221 if (elantech_cmd(kbdc, hwversion, ELANTECH_RESOLUTION, resp)
7223 dpix = (resp[1] & 0x0f) * 10 + 790;
7224 dpiy = ((resp[1] & 0xf0) >> 4) * 10 + 790;
7225 elanhw.dpmmx = (dpix * 10 + 5) / 254;
7226 elanhw.dpmmy = (dpiy * 10 + 5) / 254;
7232 elanhw.dpmmx = elanhw.dpmmy = 32; /* 800 dpi */
7236 if (!elantech_support)
7239 if (elantech_init(kbdc, &elanhw)) {
7240 printf("couldn't initialize elantech touchpad\n");
7245 * Get the touchpad reporting range.
7246 * On HW v.3 touchpads it should be done after switching hardware
7247 * to real resolution mode (by setting bit 3 of reg10)
7249 elanhw.dptracex = elanhw.dptracey = 64;
7250 for (i = 0; i < nitems(fw_sizes); i++) {
7251 if (elanhw.fwversion == fw_sizes[i][0]) {
7252 elanhw.sizex = fw_sizes[i][1];
7253 elanhw.sizey = fw_sizes[i][2];
7257 if (elantech_cmd(kbdc, hwversion, ELANTECH_FW_ID, resp) != 0) {
7258 printf(" Failed to read touchpad size\n");
7259 elanhw.sizex = 10000; /* Arbitrary high values to */
7260 elanhw.sizey = 10000; /* prevent clipping in smoother */
7261 } else if (hwversion == 2) {
7262 if ((elanhw.fwversion >> 16) == 0x14 && (resp[1] & 0x10) &&
7263 !elantech_cmd(kbdc, hwversion, ELANTECH_SAMPLE, resp)) {
7264 elanhw.dptracex = resp[1] / 2;
7265 elanhw.dptracey = resp[2] / 2;
7267 xtr = ((elanhw.fwversion >> 8) == 0x0208) ? 1 : 2;
7268 elanhw.sizex = (elanhw.ntracesx - xtr) * elanhw.dptracex;
7269 elanhw.sizey = (elanhw.ntracesy - xtr) * elanhw.dptracey;
7271 elanhw.sizex = (resp[0] & 0x0f) << 8 | resp[1];
7272 elanhw.sizey = (resp[0] & 0xf0) << 4 | resp[2];
7273 xtr = (elanhw.sizex % (elanhw.ntracesx - 2) == 0) ? 2 : 1;
7274 elanhw.dptracex = elanhw.sizex / (elanhw.ntracesx - xtr);
7275 elanhw.dptracey = elanhw.sizey / (elanhw.ntracesy - xtr);
7279 printf(" Model information:\n");
7280 printf(" MaxX: %d\n", elanhw.sizex);
7281 printf(" MaxY: %d\n", elanhw.sizey);
7282 printf(" DpmmX: %d\n", elanhw.dpmmx);
7283 printf(" DpmmY: %d\n", elanhw.dpmmy);
7284 printf(" TracesX: %d\n", elanhw.ntracesx);
7285 printf(" TracesY: %d\n", elanhw.ntracesy);
7286 printf(" DptraceX: %d\n", elanhw.dptracex);
7287 printf(" DptraceY: %d\n", elanhw.dptracey);
7288 printf(" SemiMT: %d\n", elanhw.issemimt);
7289 printf(" Clickpad: %d\n", elanhw.isclickpad);
7290 printf(" Trackpoint: %d\n", elanhw.hastrackpoint);
7291 printf(" CRC: %d\n", elanhw.hascrc);
7292 printf(" Pressure: %d\n", elanhw.haspressure);
7295 VLOG(3, (LOG_DEBUG, "elantech: END init\n"));
7298 sc->elanhw = elanhw;
7301 /* Initialize synaptics movement smoother */
7302 elantech_init_synaptics(sc);
7304 for (id = 0; id < ELANTECH_MAX_FINGERS; id++)
7305 PSM_FINGER_RESET(sc->elanaction.fingers[id]);
7312 * Return true if 'now' is earlier than (start + (secs.usecs)).
7313 * Now may be NULL and the function will fetch the current time from
7314 * getmicrouptime(), or a cached 'now' can be passed in.
7315 * All values should be numbers derived from getmicrouptime().
7318 timeelapsed(start, secs, usecs, now)
7319 const struct timeval *start, *now;
7322 struct timeval snow, tv;
7324 /* if there is no 'now' passed in, the get it as a convience. */
7326 getmicrouptime(&snow);
7332 timevaladd(&tv, start);
7333 return (timevalcmp(&tv, now, <));
7337 psmresume(device_t dev)
7339 struct psm_softc *sc = device_get_softc(dev);
7340 int unit = device_get_unit(dev);
7343 VLOG(2, (LOG_NOTICE, "psm%d: system resume hook called.\n", unit));
7346 (PSM_CONFIG_HOOKRESUME | PSM_CONFIG_INITAFTERSUSPEND)) == 0)
7349 err = reinitialize(sc, sc->config & PSM_CONFIG_INITAFTERSUSPEND);
7351 if ((sc->state & PSM_ASLP) && !(sc->state & PSM_VALID)) {
7353 * Release the blocked process; it must be notified that
7354 * the device cannot be accessed anymore.
7356 sc->state &= ~PSM_ASLP;
7360 VLOG(2, (LOG_DEBUG, "psm%d: system resume hook exiting.\n", unit));
7365 DRIVER_MODULE(psm, atkbdc, psm_driver, psm_devclass, 0, 0);
7366 #ifdef EVDEV_SUPPORT
7367 MODULE_DEPEND(psm, evdev, 1, 1, 1);
7373 * This sucks up assignments from PNPBIOS and ACPI.
7377 * When the PS/2 mouse device is reported by ACPI or PnP BIOS, it may
7378 * appear BEFORE the AT keyboard controller. As the PS/2 mouse device
7379 * can be probed and attached only after the AT keyboard controller is
7380 * attached, we shall quietly reserve the IRQ resource for later use.
7381 * If the PS/2 mouse device is reported to us AFTER the keyboard controller,
7382 * copy the IRQ resource to the PS/2 mouse device instance hanging
7383 * under the keyboard controller, then probe and attach it.
7386 static devclass_t psmcpnp_devclass;
7388 static device_probe_t psmcpnp_probe;
7389 static device_attach_t psmcpnp_attach;
7391 static device_method_t psmcpnp_methods[] = {
7392 DEVMETHOD(device_probe, psmcpnp_probe),
7393 DEVMETHOD(device_attach, psmcpnp_attach),
7398 static driver_t psmcpnp_driver = {
7399 PSMCPNP_DRIVER_NAME,
7401 sizeof(struct psmcpnp_softc),
7404 static struct isa_pnp_id psmcpnp_ids[] = {
7405 { 0x030fd041, "PS/2 mouse port" }, /* PNP0F03 */
7406 { 0x0e0fd041, "PS/2 mouse port" }, /* PNP0F0E */
7407 { 0x120fd041, "PS/2 mouse port" }, /* PNP0F12 */
7408 { 0x130fd041, "PS/2 mouse port" }, /* PNP0F13 */
7409 { 0x1303d041, "PS/2 port" }, /* PNP0313, XXX */
7410 { 0x02002e4f, "Dell PS/2 mouse port" }, /* Lat. X200, Dell */
7411 { 0x0002a906, "ALPS Glide Point" }, /* ALPS Glide Point */
7412 { 0x80374d24, "IBM PS/2 mouse port" }, /* IBM3780, ThinkPad */
7413 { 0x81374d24, "IBM PS/2 mouse port" }, /* IBM3781, ThinkPad */
7414 { 0x0190d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9001, Vaio */
7415 { 0x0290d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9002, Vaio */
7416 { 0x0390d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9003, Vaio */
7417 { 0x0490d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9004, Vaio */
7421 /* _HID list for quirk detection. Any device below has _CID from psmcpnp_ids */
7422 static struct isa_pnp_id topbtpad_ids[] = {
7423 { 0x1700ae30, "Lenovo PS/2 clickpad port" }, /* LEN0017, ThinkPad */
7424 { 0x1800ae30, "Lenovo PS/2 clickpad port" }, /* LEN0018, ThinkPad */
7425 { 0x1900ae30, "Lenovo PS/2 clickpad port" }, /* LEN0019, ThinkPad */
7426 { 0x2300ae30, "Lenovo PS/2 clickpad port" }, /* LEN0023, ThinkPad */
7427 { 0x2a00ae30, "Lenovo PS/2 clickpad port" }, /* LEN002a, ThinkPad */
7428 { 0x2b00ae30, "Lenovo PS/2 clickpad port" }, /* LEN002b, ThinkPad */
7429 { 0x2c00ae30, "Lenovo PS/2 clickpad port" }, /* LEN002c, ThinkPad */
7430 { 0x2d00ae30, "Lenovo PS/2 clickpad port" }, /* LEN002d, ThinkPad */
7431 { 0x2e00ae30, "Lenovo PS/2 clickpad port" }, /* LEN002e, ThinkPad */
7432 { 0x3300ae30, "Lenovo PS/2 clickpad port" }, /* LEN0033, ThinkPad */
7433 { 0x3400ae30, "Lenovo PS/2 clickpad port" }, /* LEN0034, ThinkPad */
7434 { 0x3500ae30, "Lenovo PS/2 clickpad port" }, /* LEN0035, ThinkPad */
7435 { 0x3600ae30, "Lenovo PS/2 clickpad port" }, /* LEN0036, ThinkPad */
7436 { 0x3700ae30, "Lenovo PS/2 clickpad port" }, /* LEN0037, ThinkPad */
7437 { 0x3800ae30, "Lenovo PS/2 clickpad port" }, /* LEN0038, ThinkPad */
7438 { 0x3900ae30, "Lenovo PS/2 clickpad port" }, /* LEN0039, ThinkPad */
7439 { 0x4100ae30, "Lenovo PS/2 clickpad port" }, /* LEN0041, ThinkPad */
7440 { 0x4200ae30, "Lenovo PS/2 clickpad port" }, /* LEN0042, ThinkPad */
7441 { 0x4500ae30, "Lenovo PS/2 clickpad port" }, /* LEN0045, ThinkPad */
7442 { 0x4700ae30, "Lenovo PS/2 clickpad port" }, /* LEN0047, ThinkPad */
7443 { 0x4900ae30, "Lenovo PS/2 clickpad port" }, /* LEN0049, ThinkPad */
7444 { 0x0020ae30, "Lenovo PS/2 clickpad port" }, /* LEN2000, ThinkPad */
7445 { 0x0120ae30, "Lenovo PS/2 clickpad port" }, /* LEN2001, ThinkPad */
7446 { 0x0220ae30, "Lenovo PS/2 clickpad port" }, /* LEN2002, ThinkPad */
7447 { 0x0320ae30, "Lenovo PS/2 clickpad port" }, /* LEN2003, ThinkPad */
7448 { 0x0420ae30, "Lenovo PS/2 clickpad port" }, /* LEN2004, ThinkPad */
7449 { 0x0520ae30, "Lenovo PS/2 clickpad port" }, /* LEN2005, ThinkPad */
7450 { 0x0620ae30, "Lenovo PS/2 clickpad port" }, /* LEN2006, ThinkPad */
7451 { 0x0720ae30, "Lenovo PS/2 clickpad port" }, /* LEN2007, ThinkPad */
7452 { 0x0820ae30, "Lenovo PS/2 clickpad port" }, /* LEN2008, ThinkPad */
7453 { 0x0920ae30, "Lenovo PS/2 clickpad port" }, /* LEN2009, ThinkPad */
7454 { 0x0a20ae30, "Lenovo PS/2 clickpad port" }, /* LEN200a, ThinkPad */
7455 { 0x0b20ae30, "Lenovo PS/2 clickpad port" }, /* LEN200b, ThinkPad */
7459 /* _HID list for quirk detection. Any device below has _CID from psmcpnp_ids */
7460 static struct isa_pnp_id forcepad_ids[] = {
7461 { 0x0d302e4f, "HP PS/2 forcepad port" }, /* SYN300D, EB 1040 */
7462 { 0x14302e4f, "HP PS/2 forcepad port" }, /* SYN3014, EB 1040 */
7467 create_a_copy(device_t atkbdc, device_t me)
7472 /* find the PS/2 mouse device instance under the keyboard controller */
7473 psm = device_find_child(atkbdc, PSM_DRIVER_NAME,
7474 device_get_unit(atkbdc));
7477 if (device_get_state(psm) != DS_NOTPRESENT)
7480 /* move our resource to the found device */
7481 irq = bus_get_resource_start(me, SYS_RES_IRQ, 0);
7482 bus_delete_resource(me, SYS_RES_IRQ, 0);
7483 bus_set_resource(psm, SYS_RES_IRQ, KBDC_RID_AUX, irq, 1);
7485 /* ...then probe and attach it */
7486 return (device_probe_and_attach(psm));
7490 psmcpnp_probe(device_t dev)
7492 struct psmcpnp_softc *sc = device_get_softc(dev);
7493 struct resource *res;
7497 if (ISA_PNP_PROBE(device_get_parent(dev), dev, forcepad_ids) == 0)
7498 sc->type = PSMCPNP_FORCEPAD;
7499 else if (ISA_PNP_PROBE(device_get_parent(dev), dev, topbtpad_ids) == 0)
7500 sc->type = PSMCPNP_TOPBUTTONPAD;
7501 else if (ISA_PNP_PROBE(device_get_parent(dev), dev, psmcpnp_ids) == 0)
7502 sc->type = PSMCPNP_GENERIC;
7507 * The PnP BIOS and ACPI are supposed to assign an IRQ (12)
7508 * to the PS/2 mouse device node. But, some buggy PnP BIOS
7509 * declares the PS/2 mouse device node without an IRQ resource!
7510 * If this happens, we shall refer to device hints.
7511 * If we still don't find it there, use a hardcoded value... XXX
7514 irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid);
7516 if (resource_long_value(PSM_DRIVER_NAME,
7517 device_get_unit(dev),"irq", &irq) != 0)
7519 device_printf(dev, "irq resource info is missing; "
7520 "assuming irq %ld\n", irq);
7521 bus_set_resource(dev, SYS_RES_IRQ, rid, irq, 1);
7523 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 0);
7524 bus_release_resource(dev, SYS_RES_IRQ, rid, res);
7530 return ((res == NULL) ? ENXIO : 0);
7534 psmcpnp_attach(device_t dev)
7538 /* find the keyboard controller, which may be on acpi* or isa* bus */
7539 atkbdc = devclass_get_device(devclass_find(ATKBDC_DRIVER_NAME),
7540 device_get_unit(dev));
7541 if ((atkbdc != NULL) && (device_get_state(atkbdc) == DS_ATTACHED))
7542 create_a_copy(atkbdc, dev);
7547 DRIVER_MODULE(psmcpnp, isa, psmcpnp_driver, psmcpnp_devclass, 0, 0);
7548 DRIVER_MODULE(psmcpnp, acpi, psmcpnp_driver, psmcpnp_devclass, 0, 0);
7549 ISA_PNP_INFO(psmcpnp_ids);
7550 #endif /* DEV_ISA */