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$");
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/kernel.h>
70 #include <sys/module.h>
73 #include <sys/filio.h>
75 #include <sys/sigio.h>
76 #include <sys/signalvar.h>
77 #include <sys/syslog.h>
78 #include <machine/bus.h>
80 #include <sys/selinfo.h>
81 #include <sys/sysctl.h>
85 #include <sys/limits.h>
86 #include <sys/mouse.h>
87 #include <machine/resource.h>
90 #include <isa/isavar.h>
93 #include <dev/atkbdc/atkbdcreg.h>
94 #include <dev/atkbdc/psm.h>
97 * Driver specific options: the following options may be set by
98 * `options' statements in the kernel configuration file.
103 #define PSM_DEBUG 0 /*
104 * logging: 0: none, 1: brief, 2: verbose
105 * 3: sync errors, 4: all packets
108 #define VLOG(level, args) do { \
109 if (verbose >= level) \
113 #ifndef PSM_INPUT_TIMEOUT
114 #define PSM_INPUT_TIMEOUT 2000000 /* 2 sec */
117 #ifndef PSM_TAP_TIMEOUT
118 #define PSM_TAP_TIMEOUT 125000
121 #ifndef PSM_TAP_THRESHOLD
122 #define PSM_TAP_THRESHOLD 25
125 /* end of driver specific options */
127 #define PSMCPNP_DRIVER_NAME "psmcpnp"
130 #define PSM_BUFSIZE 960
131 #define PSM_SMALLBUFSIZE 240
133 /* operation levels */
134 #define PSM_LEVEL_BASE 0
135 #define PSM_LEVEL_STANDARD 1
136 #define PSM_LEVEL_NATIVE 2
137 #define PSM_LEVEL_MIN PSM_LEVEL_BASE
138 #define PSM_LEVEL_MAX PSM_LEVEL_NATIVE
140 /* Logitech PS2++ protocol */
141 #define MOUSE_PS2PLUS_CHECKBITS(b) \
142 ((((b[2] & 0x03) << 2) | 0x02) == (b[1] & 0x0f))
143 #define MOUSE_PS2PLUS_PACKET_TYPE(b) \
144 (((b[0] & 0x30) >> 2) | ((b[1] & 0x30) >> 4))
147 typedef struct ringbuf {
148 int count; /* # of valid elements in the buffer */
149 int head; /* head pointer */
150 int tail; /* tail poiner */
151 u_char buf[PSM_BUFSIZE];
155 typedef struct packetbuf {
156 u_char ipacket[16]; /* interim input buffer */
157 int inputbytes; /* # of bytes in the input buffer */
160 #ifndef PSM_PACKETQUEUE
161 #define PSM_PACKETQUEUE 128
165 SYNAPTICS_SYSCTL_MIN_PRESSURE,
166 SYNAPTICS_SYSCTL_MAX_PRESSURE,
167 SYNAPTICS_SYSCTL_MAX_WIDTH,
168 SYNAPTICS_SYSCTL_MARGIN_TOP,
169 SYNAPTICS_SYSCTL_MARGIN_RIGHT,
170 SYNAPTICS_SYSCTL_MARGIN_BOTTOM,
171 SYNAPTICS_SYSCTL_MARGIN_LEFT,
172 SYNAPTICS_SYSCTL_NA_TOP,
173 SYNAPTICS_SYSCTL_NA_RIGHT,
174 SYNAPTICS_SYSCTL_NA_BOTTOM,
175 SYNAPTICS_SYSCTL_NA_LEFT,
176 SYNAPTICS_SYSCTL_WINDOW_MIN,
177 SYNAPTICS_SYSCTL_WINDOW_MAX,
178 SYNAPTICS_SYSCTL_MULTIPLICATOR,
179 SYNAPTICS_SYSCTL_WEIGHT_CURRENT,
180 SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS,
181 SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA,
182 SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED,
183 SYNAPTICS_SYSCTL_DIV_MIN,
184 SYNAPTICS_SYSCTL_DIV_MAX,
185 SYNAPTICS_SYSCTL_DIV_MAX_NA,
186 SYNAPTICS_SYSCTL_DIV_LEN,
187 SYNAPTICS_SYSCTL_TAP_MAX_DELTA,
188 SYNAPTICS_SYSCTL_TAP_MIN_QUEUE,
189 SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT,
190 SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA,
191 SYNAPTICS_SYSCTL_VSCROLL_VER_AREA,
192 SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA,
193 SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN,
194 SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX,
195 SYNAPTICS_SYSCTL_TOUCHPAD_OFF
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;
236 typedef struct synapticspacket {
241 #define SYNAPTICS_PACKETQUEUE 10
242 #define SYNAPTICS_QUEUE_CURSOR(x) \
243 (x + SYNAPTICS_PACKETQUEUE) % SYNAPTICS_PACKETQUEUE
245 #define SYNAPTICS_VERSION_GE(synhw, major, minor) \
246 ((synhw).infoMajor > (major) || \
247 ((synhw).infoMajor == (major) && (synhw).infoMinor >= (minor)))
249 typedef struct synapticsaction {
250 synapticspacket_t queue[SYNAPTICS_PACKETQUEUE];
267 TRACKPOINT_SYSCTL_SENSITIVITY,
268 TRACKPOINT_SYSCTL_NEGATIVE_INERTIA,
269 TRACKPOINT_SYSCTL_UPPER_PLATEAU,
270 TRACKPOINT_SYSCTL_BACKUP_RANGE,
271 TRACKPOINT_SYSCTL_DRAG_HYSTERESIS,
272 TRACKPOINT_SYSCTL_MINIMUM_DRAG,
273 TRACKPOINT_SYSCTL_UP_THRESHOLD,
274 TRACKPOINT_SYSCTL_THRESHOLD,
275 TRACKPOINT_SYSCTL_JENKS_CURVATURE,
276 TRACKPOINT_SYSCTL_Z_TIME,
277 TRACKPOINT_SYSCTL_PRESS_TO_SELECT,
278 TRACKPOINT_SYSCTL_SKIP_BACKUPS
281 typedef struct trackpointinfo {
282 struct sysctl_ctx_list sysctl_ctx;
283 struct sysctl_oid *sysctl_tree;
298 /* driver control block */
299 struct psm_softc { /* Driver status information */
301 struct selinfo rsel; /* Process selecting for Input */
302 u_char state; /* Mouse driver state */
303 int config; /* driver configuration flags */
304 int flags; /* other flags */
305 KBDC kbdc; /* handle to access kbd controller */
306 struct resource *intr; /* IRQ resource */
307 void *ih; /* interrupt handle */
308 mousehw_t hw; /* hardware information */
309 synapticshw_t synhw; /* Synaptics hardware information */
310 synapticsinfo_t syninfo; /* Synaptics configuration */
311 synapticsaction_t synaction; /* Synaptics action context */
312 int tphw; /* TrackPoint hardware information */
313 trackpointinfo_t tpinfo; /* TrackPoint configuration */
314 mousemode_t mode; /* operation mode */
315 mousemode_t dflt_mode; /* default operation mode */
316 mousestatus_t status; /* accumulated mouse movement */
317 ringbuf_t queue; /* mouse status queue */
318 packetbuf_t pqueue[PSM_PACKETQUEUE]; /* mouse data queue */
319 int pqueue_start; /* start of data in queue */
320 int pqueue_end; /* end of data in queue */
321 int button; /* the latest button state */
322 int xold; /* previous absolute X position */
323 int yold; /* previous absolute Y position */
324 int xaverage; /* average X position */
325 int yaverage; /* average Y position */
326 int squelch; /* level to filter movement at low speed */
327 int zmax; /* maximum pressure value for touchpads */
328 int syncerrors; /* # of bytes discarded to synchronize */
329 int pkterrors; /* # of packets failed during quaranteen. */
330 struct timeval inputtimeout;
331 struct timeval lastsoftintr; /* time of last soft interrupt */
332 struct timeval lastinputerr; /* time last sync error happened */
333 struct timeval taptimeout; /* tap timeout for touchpads */
334 int watchdog; /* watchdog timer flag */
335 struct callout callout; /* watchdog timer call out */
336 struct callout softcallout; /* buffer timer call out */
341 struct sigio *async; /* Processes waiting for SIGIO */
342 int extended_buttons;
344 static devclass_t psm_devclass;
346 /* driver state flags (state) */
347 #define PSM_VALID 0x80
348 #define PSM_OPEN 1 /* Device is open */
349 #define PSM_ASLP 2 /* Waiting for mouse data */
350 #define PSM_SOFTARMED 4 /* Software interrupt armed */
351 #define PSM_NEED_SYNCBITS 8 /* Set syncbits using next data pkt */
353 /* driver configuration flags (config) */
354 #define PSM_CONFIG_RESOLUTION 0x000f /* resolution */
355 #define PSM_CONFIG_ACCEL 0x00f0 /* acceleration factor */
356 #define PSM_CONFIG_NOCHECKSYNC 0x0100 /* disable sync. test */
357 #define PSM_CONFIG_NOIDPROBE 0x0200 /* disable mouse model probe */
358 #define PSM_CONFIG_NORESET 0x0400 /* don't reset the mouse */
359 #define PSM_CONFIG_FORCETAP 0x0800 /* assume `tap' action exists */
360 #define PSM_CONFIG_IGNPORTERROR 0x1000 /* ignore error in aux port test */
361 #define PSM_CONFIG_HOOKRESUME 0x2000 /* hook the system resume event */
362 #define PSM_CONFIG_INITAFTERSUSPEND 0x4000 /* init the device at the resume event */
364 #define PSM_CONFIG_FLAGS \
365 (PSM_CONFIG_RESOLUTION | \
367 PSM_CONFIG_NOCHECKSYNC | \
368 PSM_CONFIG_NOIDPROBE | \
369 PSM_CONFIG_NORESET | \
370 PSM_CONFIG_FORCETAP | \
371 PSM_CONFIG_IGNPORTERROR | \
372 PSM_CONFIG_HOOKRESUME | \
373 PSM_CONFIG_INITAFTERSUSPEND)
375 /* other flags (flags) */
376 #define PSM_FLAGS_FINGERDOWN 0x0001 /* VersaPad finger down */
378 #define kbdcp(p) ((atkbdc_softc_t *)(p))
379 #define ALWAYS_RESTORE_CONTROLLER(kbdc) !(kbdcp(kbdc)->quirks \
380 & KBDC_QUIRK_KEEP_ACTIVATED)
383 static int tap_enabled = -1;
384 TUNABLE_INT("hw.psm.tap_enabled", &tap_enabled);
386 static int synaptics_support = 0;
387 TUNABLE_INT("hw.psm.synaptics_support", &synaptics_support);
389 static int trackpoint_support = 0;
390 TUNABLE_INT("hw.psm.trackpoint_support", &trackpoint_support);
392 static int verbose = PSM_DEBUG;
393 TUNABLE_INT("debug.psm.loglevel", &verbose);
395 /* for backward compatibility */
396 #define OLD_MOUSE_GETHWINFO _IOR('M', 1, old_mousehw_t)
397 #define OLD_MOUSE_GETMODE _IOR('M', 2, old_mousemode_t)
398 #define OLD_MOUSE_SETMODE _IOW('M', 3, old_mousemode_t)
400 typedef struct old_mousehw {
407 typedef struct old_mousemode {
414 /* packet formatting function */
415 typedef int packetfunc_t(struct psm_softc *, u_char *, int *, int,
418 /* function prototypes */
419 static void psmidentify(driver_t *, device_t);
420 static int psmprobe(device_t);
421 static int psmattach(device_t);
422 static int psmdetach(device_t);
423 static int psmresume(device_t);
425 static d_open_t psmopen;
426 static d_close_t psmclose;
427 static d_read_t psmread;
428 static d_write_t psmwrite;
429 static d_ioctl_t psmioctl;
430 static d_poll_t psmpoll;
432 static int enable_aux_dev(KBDC);
433 static int disable_aux_dev(KBDC);
434 static int get_mouse_status(KBDC, int *, int, int);
435 static int get_aux_id(KBDC);
436 static int set_mouse_sampling_rate(KBDC, int);
437 static int set_mouse_scaling(KBDC, int);
438 static int set_mouse_resolution(KBDC, int);
439 static int set_mouse_mode(KBDC);
440 static int get_mouse_buttons(KBDC);
441 static int is_a_mouse(int);
442 static void recover_from_error(KBDC);
443 static int restore_controller(KBDC, int);
444 static int doinitialize(struct psm_softc *, mousemode_t *);
445 static int doopen(struct psm_softc *, int);
446 static int reinitialize(struct psm_softc *, int);
447 static char *model_name(int);
448 static void psmsoftintr(void *);
449 static void psmintr(void *);
450 static void psmtimeout(void *);
451 static int timeelapsed(const struct timeval *, int, int,
452 const struct timeval *);
453 static void dropqueue(struct psm_softc *);
454 static void flushpackets(struct psm_softc *);
455 static void proc_mmanplus(struct psm_softc *, packetbuf_t *,
456 mousestatus_t *, int *, int *, int *);
457 static int proc_synaptics(struct psm_softc *, packetbuf_t *,
458 mousestatus_t *, int *, int *, int *);
459 static void proc_versapad(struct psm_softc *, packetbuf_t *,
460 mousestatus_t *, int *, int *, int *);
461 static int tame_mouse(struct psm_softc *, packetbuf_t *, mousestatus_t *,
464 /* vendor specific features */
465 typedef int probefunc_t(KBDC, struct psm_softc *);
467 static int mouse_id_proc1(KBDC, int, int, int *);
468 static int mouse_ext_command(KBDC, int);
470 static probefunc_t enable_groller;
471 static probefunc_t enable_gmouse;
472 static probefunc_t enable_aglide;
473 static probefunc_t enable_kmouse;
474 static probefunc_t enable_msexplorer;
475 static probefunc_t enable_msintelli;
476 static probefunc_t enable_4dmouse;
477 static probefunc_t enable_4dplus;
478 static probefunc_t enable_mmanplus;
479 static probefunc_t enable_synaptics;
480 static probefunc_t enable_trackpoint;
481 static probefunc_t enable_versapad;
483 static void set_trackpoint_parameters(struct psm_softc *sc);
484 static void synaptics_passthrough_on(struct psm_softc *sc);
485 static void synaptics_passthrough_off(struct psm_softc *sc);
491 probefunc_t *probefunc;
494 * WARNING: the order of probe is very important. Don't mess it
495 * unless you know what you are doing.
497 { MOUSE_MODEL_NET, /* Genius NetMouse */
498 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_gmouse },
499 { MOUSE_MODEL_NETSCROLL, /* Genius NetScroll */
500 0xc8, 6, enable_groller },
501 { MOUSE_MODEL_MOUSEMANPLUS, /* Logitech MouseMan+ */
502 0x08, MOUSE_PS2_PACKETSIZE, enable_mmanplus },
503 { MOUSE_MODEL_EXPLORER, /* Microsoft IntelliMouse Explorer */
504 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msexplorer },
505 { MOUSE_MODEL_4D, /* A4 Tech 4D Mouse */
506 0x08, MOUSE_4D_PACKETSIZE, enable_4dmouse },
507 { MOUSE_MODEL_4DPLUS, /* A4 Tech 4D+ Mouse */
508 0xc8, MOUSE_4DPLUS_PACKETSIZE, enable_4dplus },
509 { MOUSE_MODEL_SYNAPTICS, /* Synaptics Touchpad */
510 0xc0, MOUSE_SYNAPTICS_PACKETSIZE, enable_synaptics },
511 { MOUSE_MODEL_INTELLI, /* Microsoft IntelliMouse */
512 0x08, MOUSE_PS2INTELLI_PACKETSIZE, enable_msintelli },
513 { MOUSE_MODEL_GLIDEPOINT, /* ALPS GlidePoint */
514 0xc0, MOUSE_PS2_PACKETSIZE, enable_aglide },
515 { MOUSE_MODEL_THINK, /* Kensington ThinkingMouse */
516 0x80, MOUSE_PS2_PACKETSIZE, enable_kmouse },
517 { MOUSE_MODEL_VERSAPAD, /* Interlink electronics VersaPad */
518 0xe8, MOUSE_PS2VERSA_PACKETSIZE, enable_versapad },
519 { MOUSE_MODEL_TRACKPOINT, /* IBM/Lenovo TrackPoint */
520 0xc0, MOUSE_PS2_PACKETSIZE, enable_trackpoint },
521 { MOUSE_MODEL_GENERIC,
522 0xc0, MOUSE_PS2_PACKETSIZE, NULL },
524 #define GENERIC_MOUSE_ENTRY \
525 ((sizeof(vendortype) / sizeof(*vendortype)) - 1)
527 /* device driver declarateion */
528 static device_method_t psm_methods[] = {
529 /* Device interface */
530 DEVMETHOD(device_identify, psmidentify),
531 DEVMETHOD(device_probe, psmprobe),
532 DEVMETHOD(device_attach, psmattach),
533 DEVMETHOD(device_detach, psmdetach),
534 DEVMETHOD(device_resume, psmresume),
539 static driver_t psm_driver = {
542 sizeof(struct psm_softc),
545 static struct cdevsw psm_cdevsw = {
546 .d_version = D_VERSION,
547 .d_flags = D_NEEDGIANT,
554 .d_name = PSM_DRIVER_NAME,
557 /* device I/O routines */
559 enable_aux_dev(KBDC kbdc)
563 res = send_aux_command(kbdc, PSMC_ENABLE_DEV);
564 VLOG(2, (LOG_DEBUG, "psm: ENABLE_DEV return code:%04x\n", res));
566 return (res == PSM_ACK);
570 disable_aux_dev(KBDC kbdc)
574 res = send_aux_command(kbdc, PSMC_DISABLE_DEV);
575 VLOG(2, (LOG_DEBUG, "psm: DISABLE_DEV return code:%04x\n", res));
577 return (res == PSM_ACK);
581 get_mouse_status(KBDC kbdc, int *status, int flag, int len)
590 cmd = PSMC_SEND_DEV_STATUS;
593 cmd = PSMC_SEND_DEV_DATA;
596 empty_aux_buffer(kbdc, 5);
597 res = send_aux_command(kbdc, cmd);
598 VLOG(2, (LOG_DEBUG, "psm: SEND_AUX_DEV_%s return code:%04x\n",
599 (flag == 1) ? "DATA" : "STATUS", res));
603 for (i = 0; i < len; ++i) {
604 status[i] = read_aux_data(kbdc);
609 VLOG(1, (LOG_DEBUG, "psm: %s %02x %02x %02x\n",
610 (flag == 1) ? "data" : "status", status[0], status[1], status[2]));
616 get_aux_id(KBDC kbdc)
621 empty_aux_buffer(kbdc, 5);
622 res = send_aux_command(kbdc, PSMC_SEND_DEV_ID);
623 VLOG(2, (LOG_DEBUG, "psm: SEND_DEV_ID return code:%04x\n", res));
630 id = read_aux_data(kbdc);
631 VLOG(2, (LOG_DEBUG, "psm: device ID: %04x\n", id));
637 set_mouse_sampling_rate(KBDC kbdc, int rate)
641 res = send_aux_command_and_data(kbdc, PSMC_SET_SAMPLING_RATE, rate);
642 VLOG(2, (LOG_DEBUG, "psm: SET_SAMPLING_RATE (%d) %04x\n", rate, res));
644 return ((res == PSM_ACK) ? rate : -1);
648 set_mouse_scaling(KBDC kbdc, int scale)
655 scale = PSMC_SET_SCALING11;
658 scale = PSMC_SET_SCALING21;
661 res = send_aux_command(kbdc, scale);
662 VLOG(2, (LOG_DEBUG, "psm: SET_SCALING%s return code:%04x\n",
663 (scale == PSMC_SET_SCALING21) ? "21" : "11", res));
665 return (res == PSM_ACK);
668 /* `val' must be 0 through PSMD_MAX_RESOLUTION */
670 set_mouse_resolution(KBDC kbdc, int val)
674 res = send_aux_command_and_data(kbdc, PSMC_SET_RESOLUTION, val);
675 VLOG(2, (LOG_DEBUG, "psm: SET_RESOLUTION (%d) %04x\n", val, res));
677 return ((res == PSM_ACK) ? val : -1);
681 * NOTE: once `set_mouse_mode()' is called, the mouse device must be
682 * re-enabled by calling `enable_aux_dev()'
685 set_mouse_mode(KBDC kbdc)
689 res = send_aux_command(kbdc, PSMC_SET_STREAM_MODE);
690 VLOG(2, (LOG_DEBUG, "psm: SET_STREAM_MODE return code:%04x\n", res));
692 return (res == PSM_ACK);
696 get_mouse_buttons(KBDC kbdc)
698 int c = 2; /* assume two buttons by default */
702 * NOTE: a special sequence to obtain Logitech Mouse specific
703 * information: set resolution to 25 ppi, set scaling to 1:1, set
704 * scaling to 1:1, set scaling to 1:1. Then the second byte of the
705 * mouse status bytes is the number of available buttons.
706 * Some manufactures also support this sequence.
708 if (set_mouse_resolution(kbdc, PSMD_RES_LOW) != PSMD_RES_LOW)
710 if (set_mouse_scaling(kbdc, 1) && set_mouse_scaling(kbdc, 1) &&
711 set_mouse_scaling(kbdc, 1) &&
712 get_mouse_status(kbdc, status, 0, 3) >= 3 && status[1] != 0)
717 /* misc subroutines */
719 * Someday, I will get the complete list of valid pointing devices and
726 static int valid_ids[] = {
727 PSM_MOUSE_ID, /* mouse */
728 PSM_BALLPOINT_ID, /* ballpoint device */
729 PSM_INTELLI_ID, /* Intellimouse */
730 PSM_EXPLORER_ID, /* Intellimouse Explorer */
731 -1 /* end of table */
735 for (i = 0; valid_ids[i] >= 0; ++i)
736 if (valid_ids[i] == id)
745 model_name(int model)
751 { MOUSE_MODEL_NETSCROLL, "NetScroll" },
752 { MOUSE_MODEL_NET, "NetMouse/NetScroll Optical" },
753 { MOUSE_MODEL_GLIDEPOINT, "GlidePoint" },
754 { MOUSE_MODEL_THINK, "ThinkingMouse" },
755 { MOUSE_MODEL_INTELLI, "IntelliMouse" },
756 { MOUSE_MODEL_MOUSEMANPLUS, "MouseMan+" },
757 { MOUSE_MODEL_VERSAPAD, "VersaPad" },
758 { MOUSE_MODEL_EXPLORER, "IntelliMouse Explorer" },
759 { MOUSE_MODEL_4D, "4D Mouse" },
760 { MOUSE_MODEL_4DPLUS, "4D+ Mouse" },
761 { MOUSE_MODEL_SYNAPTICS, "Synaptics Touchpad" },
762 { MOUSE_MODEL_TRACKPOINT, "IBM/Lenovo TrackPoint" },
763 { MOUSE_MODEL_GENERIC, "Generic PS/2 mouse" },
764 { MOUSE_MODEL_UNKNOWN, "Unknown" },
768 for (i = 0; models[i].model_code != MOUSE_MODEL_UNKNOWN; ++i)
769 if (models[i].model_code == model)
771 return (models[i].model_name);
775 recover_from_error(KBDC kbdc)
777 /* discard anything left in the output buffer */
778 empty_both_buffers(kbdc, 10);
782 * NOTE: KBDC_RESET_KBD may not restore the communication between the
783 * keyboard and the controller.
788 * NOTE: somehow diagnostic and keyboard port test commands bring the
791 if (!test_controller(kbdc))
792 log(LOG_ERR, "psm: keyboard controller failed.\n");
793 /* if there isn't a keyboard in the system, the following error is OK */
794 if (test_kbd_port(kbdc) != 0)
795 VLOG(1, (LOG_ERR, "psm: keyboard port failed.\n"));
800 restore_controller(KBDC kbdc, int command_byte)
802 empty_both_buffers(kbdc, 10);
804 if (!set_controller_command_byte(kbdc, 0xff, command_byte)) {
805 log(LOG_ERR, "psm: failed to restore the keyboard controller "
807 empty_both_buffers(kbdc, 10);
810 empty_both_buffers(kbdc, 10);
816 * Re-initialize the aux port and device. The aux port must be enabled
817 * and its interrupt must be disabled before calling this routine.
818 * The aux device will be disabled before returning.
819 * The keyboard controller must be locked via `kbdc_lock()' before
820 * calling this routine.
823 doinitialize(struct psm_softc *sc, mousemode_t *mode)
825 KBDC kbdc = sc->kbdc;
829 switch((i = test_aux_port(kbdc))) {
830 case 1: /* ignore these errors */
836 "psm%d: strange result for test aux port (%d).\n",
839 case 0: /* no error */
841 case -1: /* time out */
843 recover_from_error(kbdc);
844 if (sc->config & PSM_CONFIG_IGNPORTERROR)
846 log(LOG_ERR, "psm%d: the aux port is not functioning (%d).\n",
851 if (sc->config & PSM_CONFIG_NORESET) {
853 * Don't try to reset the pointing device. It may possibly
854 * be left in the unknown state, though...
858 * NOTE: some controllers appears to hang the `keyboard' when
859 * the aux port doesn't exist and `PSMC_RESET_DEV' is issued.
861 if (!reset_aux_dev(kbdc)) {
862 recover_from_error(kbdc);
863 log(LOG_ERR, "psm%d: failed to reset the aux device.\n",
870 * both the aux port and the aux device is functioning, see
871 * if the device can be enabled.
873 if (!enable_aux_dev(kbdc) || !disable_aux_dev(kbdc)) {
874 log(LOG_ERR, "psm%d: failed to enable the aux device.\n",
878 empty_both_buffers(kbdc, 10); /* remove stray data if any */
880 /* Re-enable the mouse. */
881 for (i = 0; vendortype[i].probefunc != NULL; ++i)
882 if (vendortype[i].model == sc->hw.model)
883 (*vendortype[i].probefunc)(sc->kbdc, NULL);
885 /* set mouse parameters */
886 if (mode != (mousemode_t *)NULL) {
888 mode->rate = set_mouse_sampling_rate(kbdc, mode->rate);
889 if (mode->resolution >= 0)
891 set_mouse_resolution(kbdc, mode->resolution);
892 set_mouse_scaling(kbdc, 1);
893 set_mouse_mode(kbdc);
896 * Trackpoint settings are lost on resume.
900 set_trackpoint_parameters(sc);
903 /* Record sync on the next data packet we see. */
904 sc->flags |= PSM_NEED_SYNCBITS;
906 /* just check the status of the mouse */
907 if (get_mouse_status(kbdc, stat, 0, 3) < 3)
908 log(LOG_DEBUG, "psm%d: failed to get status (doinitialize).\n",
915 doopen(struct psm_softc *sc, int command_byte)
920 * FIXME: Synaptics TouchPad seems to go back to Relative Mode with
921 * no obvious reason. Thus we check the current mode and restore the
922 * Absolute Mode if it was cleared.
924 * The previous hack at the end of psmprobe() wasn't efficient when
925 * moused(8) was restarted.
927 * A Reset (FF) or Set Defaults (F6) command would clear the
928 * Absolute Mode bit. But a verbose boot or debug.psm.loglevel=5
929 * doesn't show any evidence of such a command.
931 if (sc->hw.model == MOUSE_MODEL_SYNAPTICS) {
932 mouse_ext_command(sc->kbdc, 1);
933 get_mouse_status(sc->kbdc, stat, 0, 3);
934 if ((SYNAPTICS_VERSION_GE(sc->synhw, 7, 5) ||
937 /* Set the mode byte -- request wmode where
939 if (sc->synhw.capExtended)
940 mouse_ext_command(sc->kbdc, 0xc1);
942 mouse_ext_command(sc->kbdc, 0xc0);
943 set_mouse_sampling_rate(sc->kbdc, 20);
944 VLOG(5, (LOG_DEBUG, "psm%d: Synaptis Absolute Mode "
945 "hopefully restored\n",
951 * A user may want to disable tap and drag gestures on a Synaptics
952 * TouchPad when it operates in Relative Mode.
954 if (sc->hw.model == MOUSE_MODEL_GENERIC) {
955 if (tap_enabled > 0) {
957 * Enable tap & drag gestures. We use a Mode Byte
958 * and clear the DisGest bit (see §2.5 of Synaptics
959 * TouchPad Interfacing Guide).
962 "psm%d: enable tap and drag gestures\n",
964 mouse_ext_command(sc->kbdc, 0x00);
965 set_mouse_sampling_rate(sc->kbdc, 20);
966 } else if (tap_enabled == 0) {
968 * Disable tap & drag gestures. We use a Mode Byte
969 * and set the DisGest bit (see §2.5 of Synaptics
970 * TouchPad Interfacing Guide).
973 "psm%d: disable tap and drag gestures\n",
975 mouse_ext_command(sc->kbdc, 0x04);
976 set_mouse_sampling_rate(sc->kbdc, 20);
980 /* enable the mouse device */
981 if (!enable_aux_dev(sc->kbdc)) {
982 /* MOUSE ERROR: failed to enable the mouse because:
983 * 1) the mouse is faulty,
984 * 2) the mouse has been removed(!?)
985 * In the latter case, the keyboard may have hung, and need
986 * recovery procedure...
988 recover_from_error(sc->kbdc);
990 /* FIXME: we could reset the mouse here and try to enable
991 * it again. But it will take long time and it's not a good
992 * idea to disable the keyboard that long...
994 if (!doinitialize(sc, &sc->mode) || !enable_aux_dev(sc->kbdc)) {
995 recover_from_error(sc->kbdc);
999 restore_controller(sc->kbdc, command_byte);
1000 /* mark this device is no longer available */
1001 sc->state &= ~PSM_VALID;
1003 "psm%d: failed to enable the device (doopen).\n",
1009 if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
1010 log(LOG_DEBUG, "psm%d: failed to get status (doopen).\n",
1013 /* enable the aux port and interrupt */
1014 if (!set_controller_command_byte(sc->kbdc,
1015 kbdc_get_device_mask(sc->kbdc),
1016 (command_byte & KBD_KBD_CONTROL_BITS) |
1017 KBD_ENABLE_AUX_PORT | KBD_ENABLE_AUX_INT)) {
1018 /* CONTROLLER ERROR */
1019 disable_aux_dev(sc->kbdc);
1020 restore_controller(sc->kbdc, command_byte);
1022 "psm%d: failed to enable the aux interrupt (doopen).\n",
1027 /* start the watchdog timer */
1028 sc->watchdog = FALSE;
1029 callout_reset(&sc->callout, hz * 2, psmtimeout, sc);
1035 reinitialize(struct psm_softc *sc, int doinit)
1041 /* don't let anybody mess with the aux device */
1042 if (!kbdc_lock(sc->kbdc, TRUE))
1046 /* block our watchdog timer */
1047 sc->watchdog = FALSE;
1048 callout_stop(&sc->callout);
1050 /* save the current controller command byte */
1051 empty_both_buffers(sc->kbdc, 10);
1052 c = get_controller_command_byte(sc->kbdc);
1054 "psm%d: current command byte: %04x (reinitialize).\n",
1057 /* enable the aux port but disable the aux interrupt and the keyboard */
1058 if ((c == -1) || !set_controller_command_byte(sc->kbdc,
1059 kbdc_get_device_mask(sc->kbdc),
1060 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
1061 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1062 /* CONTROLLER ERROR */
1064 kbdc_lock(sc->kbdc, FALSE);
1066 "psm%d: unable to set the command byte (reinitialize).\n",
1071 /* flush any data */
1072 if (sc->state & PSM_VALID) {
1073 /* this may fail; but never mind... */
1074 disable_aux_dev(sc->kbdc);
1075 empty_aux_buffer(sc->kbdc, 10);
1080 memset(&sc->lastinputerr, 0, sizeof(sc->lastinputerr));
1082 /* try to detect the aux device; are you still there? */
1085 if (doinitialize(sc, &sc->mode)) {
1087 sc->state |= PSM_VALID;
1089 /* the device has gone! */
1090 restore_controller(sc->kbdc, c);
1091 sc->state &= ~PSM_VALID;
1093 "psm%d: the aux device has gone! (reinitialize).\n",
1100 /* restore the driver state */
1101 if ((sc->state & PSM_OPEN) && (err == 0)) {
1102 /* enable the aux device and the port again */
1103 err = doopen(sc, c);
1105 log(LOG_ERR, "psm%d: failed to enable the device "
1106 "(reinitialize).\n", sc->unit);
1108 /* restore the keyboard port and disable the aux port */
1109 if (!set_controller_command_byte(sc->kbdc,
1110 kbdc_get_device_mask(sc->kbdc),
1111 (c & KBD_KBD_CONTROL_BITS) |
1112 KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1113 /* CONTROLLER ERROR */
1114 log(LOG_ERR, "psm%d: failed to disable the aux port "
1115 "(reinitialize).\n", sc->unit);
1120 kbdc_lock(sc->kbdc, FALSE);
1124 /* psm driver entry points */
1127 psmidentify(driver_t *driver, device_t parent)
1134 unit = device_get_unit(parent);
1136 /* always add at least one child */
1137 psm = BUS_ADD_CHILD(parent, KBDC_RID_AUX, driver->name, unit);
1141 irq = bus_get_resource_start(psm, SYS_RES_IRQ, KBDC_RID_AUX);
1146 * If the PS/2 mouse device has already been reported by ACPI or
1147 * PnP BIOS, obtain the IRQ resource from it.
1148 * (See psmcpnp_attach() below.)
1150 psmc = device_find_child(device_get_parent(parent),
1151 PSMCPNP_DRIVER_NAME, unit);
1154 irq = bus_get_resource_start(psmc, SYS_RES_IRQ, 0);
1157 bus_delete_resource(psmc, SYS_RES_IRQ, 0);
1158 bus_set_resource(psm, SYS_RES_IRQ, KBDC_RID_AUX, irq, 1);
1161 #define endprobe(v) do { \
1164 kbdc_set_device_mask(sc->kbdc, mask); \
1165 kbdc_lock(sc->kbdc, FALSE); \
1170 psmprobe(device_t dev)
1172 int unit = device_get_unit(dev);
1173 struct psm_softc *sc = device_get_softc(dev);
1184 /* see if IRQ is available */
1186 sc->intr = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
1187 if (sc->intr == NULL) {
1189 device_printf(dev, "unable to allocate IRQ\n");
1192 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
1195 sc->kbdc = atkbdc_open(device_get_unit(device_get_parent(dev)));
1196 sc->config = device_get_flags(dev) & PSM_CONFIG_FLAGS;
1197 /* XXX: for backward compatibility */
1198 #if defined(PSM_HOOKRESUME) || defined(PSM_HOOKAPM)
1200 #ifdef PSM_RESETAFTERSUSPEND
1201 PSM_CONFIG_INITAFTERSUSPEND;
1203 PSM_CONFIG_HOOKRESUME;
1205 #endif /* PSM_HOOKRESUME | PSM_HOOKAPM */
1210 device_set_desc(dev, "PS/2 Mouse");
1212 if (!kbdc_lock(sc->kbdc, TRUE)) {
1213 printf("psm%d: unable to lock the controller.\n", unit);
1220 * NOTE: two bits in the command byte controls the operation of the
1221 * aux port (mouse port): the aux port disable bit (bit 5) and the aux
1222 * port interrupt (IRQ 12) enable bit (bit 2).
1225 /* discard anything left after the keyboard initialization */
1226 empty_both_buffers(sc->kbdc, 10);
1228 /* save the current command byte; it will be used later */
1229 mask = kbdc_get_device_mask(sc->kbdc) & ~KBD_AUX_CONTROL_BITS;
1230 command_byte = get_controller_command_byte(sc->kbdc);
1232 printf("psm%d: current command byte:%04x\n", unit,
1234 if (command_byte == -1) {
1235 /* CONTROLLER ERROR */
1236 printf("psm%d: unable to get the current command byte value.\n",
1242 * disable the keyboard port while probing the aux port, which must be
1243 * enabled during this routine
1245 if (!set_controller_command_byte(sc->kbdc,
1246 KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS,
1247 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
1248 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1250 * this is CONTROLLER ERROR; I don't know how to recover
1251 * from this error...
1253 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1254 restore_controller(sc->kbdc, command_byte);
1255 printf("psm%d: unable to set the command byte.\n", unit);
1258 write_controller_command(sc->kbdc, KBDC_ENABLE_AUX_PORT);
1261 * NOTE: `test_aux_port()' is designed to return with zero if the aux
1262 * port exists and is functioning. However, some controllers appears
1263 * to respond with zero even when the aux port doesn't exist. (It may
1264 * be that this is only the case when the controller DOES have the aux
1265 * port but the port is not wired on the motherboard.) The keyboard
1266 * controllers without the port, such as the original AT, are
1267 * supposed to return with an error code or simply time out. In any
1268 * case, we have to continue probing the port even when the controller
1271 * XXX: some controllers erroneously return the error code 1, 2 or 3
1272 * when it has a perfectly functional aux port. We have to ignore
1273 * this error code. Even if the controller HAS error with the aux
1274 * port, it will be detected later...
1275 * XXX: another incompatible controller returns PSM_ACK (0xfa)...
1277 switch ((i = test_aux_port(sc->kbdc))) {
1278 case 1: /* ignore these errors */
1283 printf("psm%d: strange result for test aux port "
1284 "(%d).\n", unit, i);
1286 case 0: /* no error */
1288 case -1: /* time out */
1289 default: /* error */
1290 recover_from_error(sc->kbdc);
1291 if (sc->config & PSM_CONFIG_IGNPORTERROR)
1293 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1294 restore_controller(sc->kbdc, command_byte);
1296 printf("psm%d: the aux port is not functioning (%d).\n",
1301 if (sc->config & PSM_CONFIG_NORESET) {
1303 * Don't try to reset the pointing device. It may possibly be
1304 * left in an unknown state, though...
1308 * NOTE: some controllers appears to hang the `keyboard' when
1309 * the aux port doesn't exist and `PSMC_RESET_DEV' is issued.
1311 * Attempt to reset the controller twice -- this helps
1312 * pierce through some KVM switches. The second reset
1315 if (!reset_aux_dev(sc->kbdc)) {
1316 recover_from_error(sc->kbdc);
1317 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1318 restore_controller(sc->kbdc, command_byte);
1320 printf("psm%d: failed to reset the aux "
1323 } else if (!reset_aux_dev(sc->kbdc)) {
1324 recover_from_error(sc->kbdc);
1326 printf("psm%d: failed to reset the aux device "
1332 * both the aux port and the aux device are functioning, see if the
1333 * device can be enabled. NOTE: when enabled, the device will start
1334 * sending data; we shall immediately disable the device once we know
1335 * the device can be enabled.
1337 if (!enable_aux_dev(sc->kbdc) || !disable_aux_dev(sc->kbdc)) {
1339 recover_from_error(sc->kbdc);
1340 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1341 restore_controller(sc->kbdc, command_byte);
1343 printf("psm%d: failed to enable the aux device.\n",
1348 /* save the default values after reset */
1349 if (get_mouse_status(sc->kbdc, stat, 0, 3) >= 3) {
1350 sc->dflt_mode.rate = sc->mode.rate = stat[2];
1351 sc->dflt_mode.resolution = sc->mode.resolution = stat[1];
1353 sc->dflt_mode.rate = sc->mode.rate = -1;
1354 sc->dflt_mode.resolution = sc->mode.resolution = -1;
1357 /* hardware information */
1358 sc->hw.iftype = MOUSE_IF_PS2;
1360 /* verify the device is a mouse */
1361 sc->hw.hwid = get_aux_id(sc->kbdc);
1362 if (!is_a_mouse(sc->hw.hwid)) {
1363 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1364 restore_controller(sc->kbdc, command_byte);
1366 printf("psm%d: unknown device type (%d).\n", unit,
1370 switch (sc->hw.hwid) {
1371 case PSM_BALLPOINT_ID:
1372 sc->hw.type = MOUSE_TRACKBALL;
1375 case PSM_INTELLI_ID:
1376 case PSM_EXPLORER_ID:
1377 case PSM_4DMOUSE_ID:
1379 sc->hw.type = MOUSE_MOUSE;
1382 sc->hw.type = MOUSE_UNKNOWN;
1386 if (sc->config & PSM_CONFIG_NOIDPROBE) {
1388 i = GENERIC_MOUSE_ENTRY;
1391 sc->hw.buttons = get_mouse_buttons(sc->kbdc);
1393 /* other parameters */
1394 for (i = 0; vendortype[i].probefunc != NULL; ++i)
1395 if ((*vendortype[i].probefunc)(sc->kbdc, sc)) {
1397 printf("psm%d: found %s\n", unit,
1398 model_name(vendortype[i].model));
1403 sc->hw.model = vendortype[i].model;
1405 sc->dflt_mode.level = PSM_LEVEL_BASE;
1406 sc->dflt_mode.packetsize = MOUSE_PS2_PACKETSIZE;
1407 sc->dflt_mode.accelfactor = (sc->config & PSM_CONFIG_ACCEL) >> 4;
1408 if (sc->config & PSM_CONFIG_NOCHECKSYNC)
1409 sc->dflt_mode.syncmask[0] = 0;
1411 sc->dflt_mode.syncmask[0] = vendortype[i].syncmask;
1412 if (sc->config & PSM_CONFIG_FORCETAP)
1413 sc->dflt_mode.syncmask[0] &= ~MOUSE_PS2_TAP;
1414 sc->dflt_mode.syncmask[1] = 0; /* syncbits */
1415 sc->mode = sc->dflt_mode;
1416 sc->mode.packetsize = vendortype[i].packetsize;
1418 /* set mouse parameters */
1421 * A version of Logitech FirstMouse+ won't report wheel movement,
1422 * if SET_DEFAULTS is sent... Don't use this command.
1423 * This fix was found by Takashi Nishida.
1425 i = send_aux_command(sc->kbdc, PSMC_SET_DEFAULTS);
1427 printf("psm%d: SET_DEFAULTS return code:%04x\n", unit, i);
1429 if (sc->config & PSM_CONFIG_RESOLUTION)
1430 sc->mode.resolution =
1431 set_mouse_resolution(sc->kbdc,
1432 (sc->config & PSM_CONFIG_RESOLUTION) - 1);
1433 else if (sc->mode.resolution >= 0)
1434 sc->mode.resolution =
1435 set_mouse_resolution(sc->kbdc, sc->dflt_mode.resolution);
1436 if (sc->mode.rate > 0)
1438 set_mouse_sampling_rate(sc->kbdc, sc->dflt_mode.rate);
1439 set_mouse_scaling(sc->kbdc, 1);
1441 /* Record sync on the next data packet we see. */
1442 sc->flags |= PSM_NEED_SYNCBITS;
1444 /* just check the status of the mouse */
1446 * NOTE: XXX there are some arcane controller/mouse combinations out
1447 * there, which hung the controller unless there is data transmission
1448 * after ACK from the mouse.
1450 if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
1451 printf("psm%d: failed to get status.\n", unit);
1454 * When in its native mode, some mice operate with different
1455 * default parameters than in the PS/2 compatible mode.
1457 sc->dflt_mode.rate = sc->mode.rate = stat[2];
1458 sc->dflt_mode.resolution = sc->mode.resolution = stat[1];
1461 /* disable the aux port for now... */
1462 if (!set_controller_command_byte(sc->kbdc,
1463 KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS,
1464 (command_byte & KBD_KBD_CONTROL_BITS) |
1465 KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1467 * this is CONTROLLER ERROR; I don't know the proper way to
1468 * recover from this error...
1470 if (ALWAYS_RESTORE_CONTROLLER(sc->kbdc))
1471 restore_controller(sc->kbdc, command_byte);
1472 printf("psm%d: unable to set the command byte.\n", unit);
1477 kbdc_set_device_mask(sc->kbdc, mask | KBD_AUX_CONTROL_BITS);
1478 kbdc_lock(sc->kbdc, FALSE);
1483 psmattach(device_t dev)
1485 int unit = device_get_unit(dev);
1486 struct psm_softc *sc = device_get_softc(dev);
1490 /* Setup initial state */
1491 sc->state = PSM_VALID;
1492 callout_init(&sc->callout, 0);
1493 callout_init(&sc->softcallout, 0);
1495 /* Setup our interrupt handler */
1497 sc->intr = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
1498 if (sc->intr == NULL)
1500 error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, NULL, psmintr, sc,
1503 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
1508 sc->dev = make_dev(&psm_cdevsw, 0, 0, 0, 0666, "psm%d", unit);
1509 sc->dev->si_drv1 = sc;
1510 sc->bdev = make_dev(&psm_cdevsw, 0, 0, 0, 0666, "bpsm%d", unit);
1511 sc->bdev->si_drv1 = sc;
1513 /* Some touchpad devices need full reinitialization after suspend. */
1514 switch (sc->hw.model) {
1515 case MOUSE_MODEL_SYNAPTICS:
1516 case MOUSE_MODEL_GLIDEPOINT:
1517 case MOUSE_MODEL_VERSAPAD:
1518 sc->config |= PSM_CONFIG_INITAFTERSUSPEND;
1521 if (sc->synhw.infoMajor >= 4 || sc->tphw > 0)
1522 sc->config |= PSM_CONFIG_INITAFTERSUSPEND;
1527 printf("psm%d: model %s, device ID %d\n",
1528 unit, model_name(sc->hw.model), sc->hw.hwid & 0x00ff);
1530 printf("psm%d: model %s, device ID %d-%02x, %d buttons\n",
1531 unit, model_name(sc->hw.model), sc->hw.hwid & 0x00ff,
1532 sc->hw.hwid >> 8, sc->hw.buttons);
1533 printf("psm%d: config:%08x, flags:%08x, packet size:%d\n",
1534 unit, sc->config, sc->flags, sc->mode.packetsize);
1535 printf("psm%d: syncmask:%02x, syncbits:%02x\n",
1536 unit, sc->mode.syncmask[0], sc->mode.syncmask[1]);
1546 psmdetach(device_t dev)
1548 struct psm_softc *sc;
1551 sc = device_get_softc(dev);
1552 if (sc->state & PSM_OPEN)
1556 bus_teardown_intr(dev, sc->intr, sc->ih);
1557 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr);
1559 destroy_dev(sc->dev);
1560 destroy_dev(sc->bdev);
1562 callout_drain(&sc->callout);
1563 callout_drain(&sc->softcallout);
1569 psmopen(struct cdev *dev, int flag, int fmt, struct thread *td)
1571 struct psm_softc *sc;
1576 /* Get device data */
1578 if ((sc == NULL) || (sc->state & PSM_VALID) == 0) {
1579 /* the device is no longer valid/functioning */
1583 /* Disallow multiple opens */
1584 if (sc->state & PSM_OPEN)
1587 device_busy(devclass_get_device(psm_devclass, sc->unit));
1589 /* Initialize state */
1590 sc->mode.level = sc->dflt_mode.level;
1591 sc->mode.protocol = sc->dflt_mode.protocol;
1592 sc->watchdog = FALSE;
1595 /* flush the event queue */
1596 sc->queue.count = 0;
1599 sc->status.flags = 0;
1600 sc->status.button = 0;
1601 sc->status.obutton = 0;
1606 sc->pqueue_start = 0;
1609 /* empty input buffer */
1614 /* don't let timeout routines in the keyboard driver to poll the kbdc */
1615 if (!kbdc_lock(sc->kbdc, TRUE))
1618 /* save the current controller command byte */
1620 command_byte = get_controller_command_byte(sc->kbdc);
1622 /* enable the aux port and temporalily disable the keyboard */
1623 if (command_byte == -1 || !set_controller_command_byte(sc->kbdc,
1624 kbdc_get_device_mask(sc->kbdc),
1625 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
1626 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1627 /* CONTROLLER ERROR; do you know how to get out of this? */
1628 kbdc_lock(sc->kbdc, FALSE);
1631 "psm%d: unable to set the command byte (psmopen).\n",
1636 * Now that the keyboard controller is told not to generate
1637 * the keyboard and mouse interrupts, call `splx()' to allow
1638 * the other tty interrupts. The clock interrupt may also occur,
1639 * but timeout routines will be blocked by the poll flag set
1644 /* enable the mouse device */
1645 err = doopen(sc, command_byte);
1649 sc->state |= PSM_OPEN;
1650 kbdc_lock(sc->kbdc, FALSE);
1655 psmclose(struct cdev *dev, int flag, int fmt, struct thread *td)
1657 struct psm_softc *sc = dev->si_drv1;
1662 /* don't let timeout routines in the keyboard driver to poll the kbdc */
1663 if (!kbdc_lock(sc->kbdc, TRUE))
1666 /* save the current controller command byte */
1668 command_byte = get_controller_command_byte(sc->kbdc);
1669 if (command_byte == -1) {
1670 kbdc_lock(sc->kbdc, FALSE);
1675 /* disable the aux interrupt and temporalily disable the keyboard */
1676 if (!set_controller_command_byte(sc->kbdc,
1677 kbdc_get_device_mask(sc->kbdc),
1678 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
1679 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1681 "psm%d: failed to disable the aux int (psmclose).\n",
1683 /* CONTROLLER ERROR;
1684 * NOTE: we shall force our way through. Because the only
1685 * ill effect we shall see is that we may not be able
1686 * to read ACK from the mouse, and it doesn't matter much
1687 * so long as the mouse will accept the DISABLE command.
1692 /* stop the watchdog timer */
1693 callout_stop(&sc->callout);
1695 /* remove anything left in the output buffer */
1696 empty_aux_buffer(sc->kbdc, 10);
1698 /* disable the aux device, port and interrupt */
1699 if (sc->state & PSM_VALID) {
1700 if (!disable_aux_dev(sc->kbdc)) {
1702 * NOTE: we don't return (error) and continue,
1703 * pretending we have successfully disabled the device.
1704 * It's OK because the interrupt routine will discard
1705 * any data from the mouse hereafter.
1708 "psm%d: failed to disable the device (psmclose).\n",
1712 if (get_mouse_status(sc->kbdc, stat, 0, 3) < 3)
1714 "psm%d: failed to get status (psmclose).\n",
1718 if (!set_controller_command_byte(sc->kbdc,
1719 kbdc_get_device_mask(sc->kbdc),
1720 (command_byte & KBD_KBD_CONTROL_BITS) |
1721 KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1724 * we shall ignore this error; see the above comment.
1727 "psm%d: failed to disable the aux port (psmclose).\n",
1731 /* remove anything left in the output buffer */
1732 empty_aux_buffer(sc->kbdc, 10);
1734 /* clean up and sigio requests */
1735 if (sc->async != NULL) {
1736 funsetown(&sc->async);
1740 /* close is almost always successful */
1741 sc->state &= ~PSM_OPEN;
1742 kbdc_lock(sc->kbdc, FALSE);
1743 device_unbusy(devclass_get_device(psm_devclass, sc->unit));
1748 tame_mouse(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *status,
1751 static u_char butmapps2[8] = {
1753 MOUSE_PS2_BUTTON1DOWN,
1754 MOUSE_PS2_BUTTON2DOWN,
1755 MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON2DOWN,
1756 MOUSE_PS2_BUTTON3DOWN,
1757 MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON3DOWN,
1758 MOUSE_PS2_BUTTON2DOWN | MOUSE_PS2_BUTTON3DOWN,
1759 MOUSE_PS2_BUTTON1DOWN | MOUSE_PS2_BUTTON2DOWN |
1760 MOUSE_PS2_BUTTON3DOWN,
1762 static u_char butmapmsc[8] = {
1763 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP |
1764 MOUSE_MSC_BUTTON3UP,
1765 MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
1766 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON3UP,
1767 MOUSE_MSC_BUTTON3UP,
1768 MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP,
1769 MOUSE_MSC_BUTTON2UP,
1770 MOUSE_MSC_BUTTON1UP,
1776 if (sc->mode.level == PSM_LEVEL_BASE) {
1777 mapped = status->button & ~MOUSE_BUTTON4DOWN;
1778 if (status->button & MOUSE_BUTTON4DOWN)
1779 mapped |= MOUSE_BUTTON1DOWN;
1780 status->button = mapped;
1781 buf[0] = MOUSE_PS2_SYNC | butmapps2[mapped & MOUSE_STDBUTTONS];
1782 i = imax(imin(status->dx, 255), -256);
1784 buf[0] |= MOUSE_PS2_XNEG;
1786 i = imax(imin(status->dy, 255), -256);
1788 buf[0] |= MOUSE_PS2_YNEG;
1790 return (MOUSE_PS2_PACKETSIZE);
1791 } else if (sc->mode.level == PSM_LEVEL_STANDARD) {
1792 buf[0] = MOUSE_MSC_SYNC |
1793 butmapmsc[status->button & MOUSE_STDBUTTONS];
1794 i = imax(imin(status->dx, 255), -256);
1796 buf[3] = i - buf[1];
1797 i = imax(imin(status->dy, 255), -256);
1799 buf[4] = i - buf[2];
1800 i = imax(imin(status->dz, 127), -128);
1801 buf[5] = (i >> 1) & 0x7f;
1802 buf[6] = (i - (i >> 1)) & 0x7f;
1803 buf[7] = (~status->button >> 3) & 0x7f;
1804 return (MOUSE_SYS_PACKETSIZE);
1806 return (pb->inputbytes);
1810 psmread(struct cdev *dev, struct uio *uio, int flag)
1812 struct psm_softc *sc = dev->si_drv1;
1813 u_char buf[PSM_SMALLBUFSIZE];
1818 if ((sc->state & PSM_VALID) == 0)
1821 /* block until mouse activity occured */
1823 while (sc->queue.count <= 0) {
1824 if (dev != sc->bdev) {
1826 return (EWOULDBLOCK);
1828 sc->state |= PSM_ASLP;
1829 error = tsleep(sc, PZERO | PCATCH, "psmrea", 0);
1830 sc->state &= ~PSM_ASLP;
1834 } else if ((sc->state & PSM_VALID) == 0) {
1835 /* the device disappeared! */
1842 /* copy data to the user land */
1843 while ((sc->queue.count > 0) && (uio->uio_resid > 0)) {
1845 l = imin(sc->queue.count, uio->uio_resid);
1846 if (l > sizeof(buf))
1848 if (l > sizeof(sc->queue.buf) - sc->queue.head) {
1849 bcopy(&sc->queue.buf[sc->queue.head], &buf[0],
1850 sizeof(sc->queue.buf) - sc->queue.head);
1851 bcopy(&sc->queue.buf[0],
1852 &buf[sizeof(sc->queue.buf) - sc->queue.head],
1853 l - (sizeof(sc->queue.buf) - sc->queue.head));
1855 bcopy(&sc->queue.buf[sc->queue.head], &buf[0], l);
1856 sc->queue.count -= l;
1857 sc->queue.head = (sc->queue.head + l) % sizeof(sc->queue.buf);
1859 error = uiomove(buf, l, uio);
1868 block_mouse_data(struct psm_softc *sc, int *c)
1872 if (!kbdc_lock(sc->kbdc, TRUE))
1876 *c = get_controller_command_byte(sc->kbdc);
1877 if ((*c == -1) || !set_controller_command_byte(sc->kbdc,
1878 kbdc_get_device_mask(sc->kbdc),
1879 KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT |
1880 KBD_ENABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) {
1881 /* this is CONTROLLER ERROR */
1883 kbdc_lock(sc->kbdc, FALSE);
1888 * The device may be in the middle of status data transmission.
1889 * The transmission will be interrupted, thus, incomplete status
1890 * data must be discarded. Although the aux interrupt is disabled
1891 * at the keyboard controller level, at most one aux interrupt
1892 * may have already been pending and a data byte is in the
1893 * output buffer; throw it away. Note that the second argument
1894 * to `empty_aux_buffer()' is zero, so that the call will just
1895 * flush the internal queue.
1896 * `psmintr()' will be invoked after `splx()' if an interrupt is
1897 * pending; it will see no data and returns immediately.
1899 empty_aux_buffer(sc->kbdc, 0); /* flush the queue */
1900 read_aux_data_no_wait(sc->kbdc); /* throw away data if any */
1908 dropqueue(struct psm_softc *sc)
1911 sc->queue.count = 0;
1914 if ((sc->state & PSM_SOFTARMED) != 0) {
1915 sc->state &= ~PSM_SOFTARMED;
1916 callout_stop(&sc->softcallout);
1918 sc->pqueue_start = sc->pqueue_end;
1922 flushpackets(struct psm_softc *sc)
1926 bzero(&sc->pqueue, sizeof(sc->pqueue));
1930 unblock_mouse_data(struct psm_softc *sc, int c)
1935 * We may have seen a part of status data during `set_mouse_XXX()'.
1936 * they have been queued; flush it.
1938 empty_aux_buffer(sc->kbdc, 0);
1940 /* restore ports and interrupt */
1941 if (!set_controller_command_byte(sc->kbdc,
1942 kbdc_get_device_mask(sc->kbdc),
1943 c & (KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS))) {
1945 * CONTROLLER ERROR; this is serious, we may have
1946 * been left with the inaccessible keyboard and
1947 * the disabled mouse interrupt.
1952 kbdc_lock(sc->kbdc, FALSE);
1957 psmwrite(struct cdev *dev, struct uio *uio, int flag)
1959 struct psm_softc *sc = dev->si_drv1;
1960 u_char buf[PSM_SMALLBUFSIZE];
1961 int error = 0, i, l;
1963 if ((sc->state & PSM_VALID) == 0)
1966 if (sc->mode.level < PSM_LEVEL_NATIVE)
1969 /* copy data from the user land */
1970 while (uio->uio_resid > 0) {
1971 l = imin(PSM_SMALLBUFSIZE, uio->uio_resid);
1972 error = uiomove(buf, l, uio);
1975 for (i = 0; i < l; i++) {
1976 VLOG(4, (LOG_DEBUG, "psm: cmd 0x%x\n", buf[i]));
1977 if (!write_aux_command(sc->kbdc, buf[i])) {
1979 "psm: cmd 0x%x failed.\n", buf[i]));
1980 return (reinitialize(sc, FALSE));
1989 psmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
1992 struct psm_softc *sc = dev->si_drv1;
1994 mousestatus_t status;
1995 #if (defined(MOUSE_GETVARS))
2004 /* Perform IOCTL command */
2007 case OLD_MOUSE_GETHWINFO:
2009 ((old_mousehw_t *)addr)->buttons = sc->hw.buttons;
2010 ((old_mousehw_t *)addr)->iftype = sc->hw.iftype;
2011 ((old_mousehw_t *)addr)->type = sc->hw.type;
2012 ((old_mousehw_t *)addr)->hwid = sc->hw.hwid & 0x00ff;
2016 case MOUSE_GETHWINFO:
2018 *(mousehw_t *)addr = sc->hw;
2019 if (sc->mode.level == PSM_LEVEL_BASE)
2020 ((mousehw_t *)addr)->model = MOUSE_MODEL_GENERIC;
2024 case MOUSE_SYN_GETHWINFO:
2026 if (sc->synhw.infoMajor >= 4)
2027 *(synapticshw_t *)addr = sc->synhw;
2033 case OLD_MOUSE_GETMODE:
2035 switch (sc->mode.level) {
2036 case PSM_LEVEL_BASE:
2037 ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2039 case PSM_LEVEL_STANDARD:
2040 ((old_mousemode_t *)addr)->protocol =
2041 MOUSE_PROTO_SYSMOUSE;
2043 case PSM_LEVEL_NATIVE:
2044 ((old_mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2047 ((old_mousemode_t *)addr)->rate = sc->mode.rate;
2048 ((old_mousemode_t *)addr)->resolution = sc->mode.resolution;
2049 ((old_mousemode_t *)addr)->accelfactor = sc->mode.accelfactor;
2055 *(mousemode_t *)addr = sc->mode;
2056 if ((sc->flags & PSM_NEED_SYNCBITS) != 0) {
2057 ((mousemode_t *)addr)->syncmask[0] = 0;
2058 ((mousemode_t *)addr)->syncmask[1] = 0;
2060 ((mousemode_t *)addr)->resolution =
2061 MOUSE_RES_LOW - sc->mode.resolution;
2062 switch (sc->mode.level) {
2063 case PSM_LEVEL_BASE:
2064 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2065 ((mousemode_t *)addr)->packetsize =
2066 MOUSE_PS2_PACKETSIZE;
2068 case PSM_LEVEL_STANDARD:
2069 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_SYSMOUSE;
2070 ((mousemode_t *)addr)->packetsize =
2071 MOUSE_SYS_PACKETSIZE;
2072 ((mousemode_t *)addr)->syncmask[0] = MOUSE_SYS_SYNCMASK;
2073 ((mousemode_t *)addr)->syncmask[1] = MOUSE_SYS_SYNC;
2075 case PSM_LEVEL_NATIVE:
2076 /* FIXME: this isn't quite correct... XXX */
2077 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_PS2;
2083 case OLD_MOUSE_SETMODE:
2085 if (cmd == OLD_MOUSE_SETMODE) {
2086 mode.rate = ((old_mousemode_t *)addr)->rate;
2088 * resolution old I/F new I/F
2095 if (((old_mousemode_t *)addr)->resolution > 0)
2097 -((old_mousemode_t *)addr)->resolution - 1;
2099 mode.resolution = 0;
2101 ((old_mousemode_t *)addr)->accelfactor;
2104 mode = *(mousemode_t *)addr;
2106 /* adjust and validate parameters. */
2107 if (mode.rate > UCHAR_MAX)
2110 mode.rate = sc->dflt_mode.rate;
2111 else if (mode.rate == -1)
2112 /* don't change the current setting */
2114 else if (mode.rate < 0)
2116 if (mode.resolution >= UCHAR_MAX)
2118 if (mode.resolution >= 200)
2119 mode.resolution = MOUSE_RES_HIGH;
2120 else if (mode.resolution >= 100)
2121 mode.resolution = MOUSE_RES_MEDIUMHIGH;
2122 else if (mode.resolution >= 50)
2123 mode.resolution = MOUSE_RES_MEDIUMLOW;
2124 else if (mode.resolution > 0)
2125 mode.resolution = MOUSE_RES_LOW;
2126 if (mode.resolution == MOUSE_RES_DEFAULT)
2127 mode.resolution = sc->dflt_mode.resolution;
2128 else if (mode.resolution == -1)
2129 /* don't change the current setting */
2131 else if (mode.resolution < 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */
2132 mode.resolution = MOUSE_RES_LOW - mode.resolution;
2133 if (mode.level == -1)
2134 /* don't change the current setting */
2135 mode.level = sc->mode.level;
2136 else if ((mode.level < PSM_LEVEL_MIN) ||
2137 (mode.level > PSM_LEVEL_MAX))
2139 if (mode.accelfactor == -1)
2140 /* don't change the current setting */
2141 mode.accelfactor = sc->mode.accelfactor;
2142 else if (mode.accelfactor < 0)
2145 /* don't allow anybody to poll the keyboard controller */
2146 error = block_mouse_data(sc, &command_byte);
2150 /* set mouse parameters */
2152 mode.rate = set_mouse_sampling_rate(sc->kbdc,
2154 if (mode.resolution >= 0)
2156 set_mouse_resolution(sc->kbdc, mode.resolution);
2157 set_mouse_scaling(sc->kbdc, 1);
2158 get_mouse_status(sc->kbdc, stat, 0, 3);
2161 sc->mode.rate = mode.rate;
2162 sc->mode.resolution = mode.resolution;
2163 sc->mode.accelfactor = mode.accelfactor;
2164 sc->mode.level = mode.level;
2167 unblock_mouse_data(sc, command_byte);
2170 case MOUSE_GETLEVEL:
2171 *(int *)addr = sc->mode.level;
2174 case MOUSE_SETLEVEL:
2175 if ((*(int *)addr < PSM_LEVEL_MIN) ||
2176 (*(int *)addr > PSM_LEVEL_MAX))
2178 sc->mode.level = *(int *)addr;
2181 case MOUSE_GETSTATUS:
2183 status = sc->status;
2184 sc->status.flags = 0;
2185 sc->status.obutton = sc->status.button;
2186 sc->status.button = 0;
2191 *(mousestatus_t *)addr = status;
2194 #if (defined(MOUSE_GETVARS))
2196 var = (mousevar_t *)addr;
2197 bzero(var, sizeof(*var));
2199 var->var[0] = MOUSE_VARS_PS2_SIG;
2200 var->var[1] = sc->config;
2201 var->var[2] = sc->flags;
2207 #endif /* MOUSE_GETVARS */
2209 case MOUSE_READSTATE:
2210 case MOUSE_READDATA:
2211 data = (mousedata_t *)addr;
2212 if (data->len > sizeof(data->buf)/sizeof(data->buf[0]))
2215 error = block_mouse_data(sc, &command_byte);
2218 if ((data->len = get_mouse_status(sc->kbdc, data->buf,
2219 (cmd == MOUSE_READDATA) ? 1 : 0, data->len)) <= 0)
2221 unblock_mouse_data(sc, command_byte);
2224 #if (defined(MOUSE_SETRESOLUTION))
2225 case MOUSE_SETRESOLUTION:
2226 mode.resolution = *(int *)addr;
2227 if (mode.resolution >= UCHAR_MAX)
2229 else if (mode.resolution >= 200)
2230 mode.resolution = MOUSE_RES_HIGH;
2231 else if (mode.resolution >= 100)
2232 mode.resolution = MOUSE_RES_MEDIUMHIGH;
2233 else if (mode.resolution >= 50)
2234 mode.resolution = MOUSE_RES_MEDIUMLOW;
2235 else if (mode.resolution > 0)
2236 mode.resolution = MOUSE_RES_LOW;
2237 if (mode.resolution == MOUSE_RES_DEFAULT)
2238 mode.resolution = sc->dflt_mode.resolution;
2239 else if (mode.resolution == -1)
2240 mode.resolution = sc->mode.resolution;
2241 else if (mode.resolution < 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */
2242 mode.resolution = MOUSE_RES_LOW - mode.resolution;
2244 error = block_mouse_data(sc, &command_byte);
2247 sc->mode.resolution =
2248 set_mouse_resolution(sc->kbdc, mode.resolution);
2249 if (sc->mode.resolution != mode.resolution)
2251 unblock_mouse_data(sc, command_byte);
2253 #endif /* MOUSE_SETRESOLUTION */
2255 #if (defined(MOUSE_SETRATE))
2257 mode.rate = *(int *)addr;
2258 if (mode.rate > UCHAR_MAX)
2261 mode.rate = sc->dflt_mode.rate;
2262 else if (mode.rate < 0)
2263 mode.rate = sc->mode.rate;
2265 error = block_mouse_data(sc, &command_byte);
2268 sc->mode.rate = set_mouse_sampling_rate(sc->kbdc, mode.rate);
2269 if (sc->mode.rate != mode.rate)
2271 unblock_mouse_data(sc, command_byte);
2273 #endif /* MOUSE_SETRATE */
2275 #if (defined(MOUSE_SETSCALING))
2276 case MOUSE_SETSCALING:
2277 if ((*(int *)addr <= 0) || (*(int *)addr > 2))
2280 error = block_mouse_data(sc, &command_byte);
2283 if (!set_mouse_scaling(sc->kbdc, *(int *)addr))
2285 unblock_mouse_data(sc, command_byte);
2287 #endif /* MOUSE_SETSCALING */
2289 #if (defined(MOUSE_GETHWID))
2291 error = block_mouse_data(sc, &command_byte);
2294 sc->hw.hwid &= ~0x00ff;
2295 sc->hw.hwid |= get_aux_id(sc->kbdc);
2296 *(int *)addr = sc->hw.hwid & 0x00ff;
2297 unblock_mouse_data(sc, command_byte);
2299 #endif /* MOUSE_GETHWID */
2305 error = fsetown(*(int *)addr, &sc->async);
2308 *(int *) addr = fgetown(&sc->async);
2318 psmtimeout(void *arg)
2320 struct psm_softc *sc;
2323 sc = (struct psm_softc *)arg;
2325 if (sc->watchdog && kbdc_lock(sc->kbdc, TRUE)) {
2326 VLOG(4, (LOG_DEBUG, "psm%d: lost interrupt?\n", sc->unit));
2328 kbdc_lock(sc->kbdc, FALSE);
2330 sc->watchdog = TRUE;
2332 callout_reset(&sc->callout, hz, psmtimeout, sc);
2335 /* Add all sysctls under the debug.psm and hw.psm nodes */
2336 static SYSCTL_NODE(_debug, OID_AUTO, psm, CTLFLAG_RD, 0, "ps/2 mouse");
2337 static SYSCTL_NODE(_hw, OID_AUTO, psm, CTLFLAG_RD, 0, "ps/2 mouse");
2339 SYSCTL_INT(_debug_psm, OID_AUTO, loglevel, CTLFLAG_RW, &verbose, 0,
2342 static int psmhz = 20;
2343 SYSCTL_INT(_debug_psm, OID_AUTO, hz, CTLFLAG_RW, &psmhz, 0,
2344 "Frequency of the softcallout (in hz)");
2345 static int psmerrsecs = 2;
2346 SYSCTL_INT(_debug_psm, OID_AUTO, errsecs, CTLFLAG_RW, &psmerrsecs, 0,
2347 "Number of seconds during which packets will dropped after a sync error");
2348 static int psmerrusecs = 0;
2349 SYSCTL_INT(_debug_psm, OID_AUTO, errusecs, CTLFLAG_RW, &psmerrusecs, 0,
2350 "Microseconds to add to psmerrsecs");
2351 static int psmsecs = 0;
2352 SYSCTL_INT(_debug_psm, OID_AUTO, secs, CTLFLAG_RW, &psmsecs, 0,
2353 "Max number of seconds between soft interrupts");
2354 static int psmusecs = 500000;
2355 SYSCTL_INT(_debug_psm, OID_AUTO, usecs, CTLFLAG_RW, &psmusecs, 0,
2356 "Microseconds to add to psmsecs");
2357 static int pkterrthresh = 2;
2358 SYSCTL_INT(_debug_psm, OID_AUTO, pkterrthresh, CTLFLAG_RW, &pkterrthresh, 0,
2359 "Number of error packets allowed before reinitializing the mouse");
2361 SYSCTL_INT(_hw_psm, OID_AUTO, tap_enabled, CTLFLAG_RW, &tap_enabled, 0,
2362 "Enable tap and drag gestures");
2363 static int tap_threshold = PSM_TAP_THRESHOLD;
2364 SYSCTL_INT(_hw_psm, OID_AUTO, tap_threshold, CTLFLAG_RW, &tap_threshold, 0,
2365 "Button tap threshold");
2366 static int tap_timeout = PSM_TAP_TIMEOUT;
2367 SYSCTL_INT(_hw_psm, OID_AUTO, tap_timeout, CTLFLAG_RW, &tap_timeout, 0,
2368 "Tap timeout for touchpads");
2373 struct psm_softc *sc = arg;
2379 /* read until there is nothing to read */
2380 while((c = read_aux_data_no_wait(sc->kbdc)) != -1) {
2381 pb = &sc->pqueue[sc->pqueue_end];
2383 /* discard the byte if the device is not open */
2384 if ((sc->state & PSM_OPEN) == 0)
2387 getmicrouptime(&now);
2388 if ((pb->inputbytes > 0) &&
2389 timevalcmp(&now, &sc->inputtimeout, >)) {
2390 VLOG(3, (LOG_DEBUG, "psmintr: delay too long; "
2391 "resetting byte count\n"));
2396 sc->inputtimeout.tv_sec = PSM_INPUT_TIMEOUT / 1000000;
2397 sc->inputtimeout.tv_usec = PSM_INPUT_TIMEOUT % 1000000;
2398 timevaladd(&sc->inputtimeout, &now);
2400 pb->ipacket[pb->inputbytes++] = c;
2402 if (sc->mode.level == PSM_LEVEL_NATIVE) {
2403 VLOG(4, (LOG_DEBUG, "psmintr: %02x\n", pb->ipacket[0]));
2408 if (pb->inputbytes < sc->mode.packetsize)
2412 "psmintr: %02x %02x %02x %02x %02x %02x\n",
2413 pb->ipacket[0], pb->ipacket[1], pb->ipacket[2],
2414 pb->ipacket[3], pb->ipacket[4], pb->ipacket[5]));
2419 if ((sc->flags & PSM_NEED_SYNCBITS) != 0) {
2420 sc->mode.syncmask[1] = (c & sc->mode.syncmask[0]);
2421 sc->flags &= ~PSM_NEED_SYNCBITS;
2423 "psmintr: Sync bytes now %04x,%04x\n",
2424 sc->mode.syncmask[0], sc->mode.syncmask[0]));
2425 } else if ((c & sc->mode.syncmask[0]) != sc->mode.syncmask[1]) {
2426 VLOG(3, (LOG_DEBUG, "psmintr: out of sync "
2427 "(%04x != %04x) %d cmds since last error.\n",
2428 c & sc->mode.syncmask[0], sc->mode.syncmask[1],
2429 sc->cmdcount - sc->lasterr));
2430 sc->lasterr = sc->cmdcount;
2432 * The sync byte test is a weak measure of packet
2433 * validity. Conservatively discard any input yet
2434 * to be seen by userland when we detect a sync
2435 * error since there is a good chance some of
2436 * the queued packets have undetected errors.
2439 if (sc->syncerrors == 0)
2442 sc->lastinputerr = now;
2443 if (sc->syncerrors >= sc->mode.packetsize * 2 ||
2444 sc->pkterrors >= pkterrthresh) {
2446 * If we've failed to find a single sync byte
2447 * in 2 packets worth of data, or we've seen
2448 * persistent packet errors during the
2449 * validation period, reinitialize the mouse
2450 * in hopes of returning it to the expected
2454 "psmintr: reset the mouse.\n"));
2455 reinitialize(sc, TRUE);
2456 } else if (sc->syncerrors == sc->mode.packetsize) {
2458 * Try a soft reset after searching for a sync
2459 * byte through a packet length of bytes.
2462 "psmintr: re-enable the mouse.\n"));
2464 disable_aux_dev(sc->kbdc);
2465 enable_aux_dev(sc->kbdc);
2468 "psmintr: discard a byte (%d)\n",
2471 bcopy(&pb->ipacket[1], &pb->ipacket[0],
2478 * We have what appears to be a valid packet.
2479 * Reset the error counters.
2484 * Drop even good packets if they occur within a timeout
2485 * period of a sync error. This allows the detection of
2486 * a change in the mouse's packet mode without exposing
2487 * erratic mouse behavior to the user. Some KVMs forget
2488 * enhanced mouse modes during switch events.
2490 if (!timeelapsed(&sc->lastinputerr, psmerrsecs, psmerrusecs,
2497 * Now that we're out of the validation period, reset
2498 * the packet error count.
2504 if (++sc->pqueue_end >= PSM_PACKETQUEUE)
2507 * If we've filled the queue then call the softintr ourselves,
2508 * otherwise schedule the interrupt for later.
2510 if (!timeelapsed(&sc->lastsoftintr, psmsecs, psmusecs, &now) ||
2511 (sc->pqueue_end == sc->pqueue_start)) {
2512 if ((sc->state & PSM_SOFTARMED) != 0) {
2513 sc->state &= ~PSM_SOFTARMED;
2514 callout_stop(&sc->softcallout);
2517 } else if ((sc->state & PSM_SOFTARMED) == 0) {
2518 sc->state |= PSM_SOFTARMED;
2519 callout_reset(&sc->softcallout,
2520 psmhz < 1 ? 1 : (hz/psmhz), psmsoftintr, arg);
2526 proc_mmanplus(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
2527 int *x, int *y, int *z)
2531 * PS2++ protocol packet
2533 * b7 b6 b5 b4 b3 b2 b1 b0
2534 * byte 1: * 1 p3 p2 1 * * *
2535 * byte 2: c1 c2 p1 p0 d1 d0 1 0
2537 * p3-p0: packet type
2538 * c1, c2: c1 & c2 == 1, if p2 == 0
2539 * c1 & c2 == 0, if p2 == 1
2541 * packet type: 0 (device type)
2542 * See comments in enable_mmanplus() below.
2544 * packet type: 1 (wheel data)
2546 * b7 b6 b5 b4 b3 b2 b1 b0
2547 * byte 3: h * B5 B4 s d2 d1 d0
2549 * h: 1, if horizontal roller data
2550 * 0, if vertical roller data
2551 * B4, B5: button 4 and 5
2553 * d2-d0: roller data
2555 * packet type: 2 (reserved)
2557 if (((pb->ipacket[0] & MOUSE_PS2PLUS_SYNCMASK) == MOUSE_PS2PLUS_SYNC) &&
2558 (abs(*x) > 191) && MOUSE_PS2PLUS_CHECKBITS(pb->ipacket)) {
2560 * the extended data packet encodes button
2563 switch (MOUSE_PS2PLUS_PACKET_TYPE(pb->ipacket)) {
2565 /* wheel data packet */
2567 if (pb->ipacket[2] & 0x80) {
2568 /* XXX horizontal roller count - ignore it */
2571 /* vertical roller count */
2572 *z = (pb->ipacket[2] & MOUSE_PS2PLUS_ZNEG) ?
2573 (pb->ipacket[2] & 0x0f) - 16 :
2574 (pb->ipacket[2] & 0x0f);
2576 ms->button |= (pb->ipacket[2] &
2577 MOUSE_PS2PLUS_BUTTON4DOWN) ?
2578 MOUSE_BUTTON4DOWN : 0;
2579 ms->button |= (pb->ipacket[2] &
2580 MOUSE_PS2PLUS_BUTTON5DOWN) ?
2581 MOUSE_BUTTON5DOWN : 0;
2585 * this packet type is reserved by
2589 * IBM ScrollPoint Mouse uses this
2590 * packet type to encode both vertical
2591 * and horizontal scroll movement.
2594 /* horizontal count */
2595 if (pb->ipacket[2] & 0x0f)
2596 *z = (pb->ipacket[2] & MOUSE_SPOINT_WNEG) ?
2598 /* vertical count */
2599 if (pb->ipacket[2] & 0xf0)
2600 *z = (pb->ipacket[2] & MOUSE_SPOINT_ZNEG) ?
2604 /* device type packet - shouldn't happen */
2608 ms->button = ms->obutton;
2609 VLOG(1, (LOG_DEBUG, "psmintr: unknown PS2++ packet "
2610 "type %d: 0x%02x 0x%02x 0x%02x\n",
2611 MOUSE_PS2PLUS_PACKET_TYPE(pb->ipacket),
2612 pb->ipacket[0], pb->ipacket[1], pb->ipacket[2]));
2616 /* preserve button states */
2617 ms->button |= ms->obutton & MOUSE_EXTBUTTONS;
2622 proc_synaptics(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
2623 int *x, int *y, int *z)
2625 static int touchpad_buttons;
2626 static int guest_buttons;
2629 /* TouchPad PS/2 absolute mode message format with capFourButtons:
2631 * Bits: 7 6 5 4 3 2 1 0 (LSB)
2632 * ------------------------------------------------
2633 * ipacket[0]: 1 0 W3 W2 0 W1 R L
2634 * ipacket[1]: Yb Ya Y9 Y8 Xb Xa X9 X8
2635 * ipacket[2]: Z7 Z6 Z5 Z4 Z3 Z2 Z1 Z0
2636 * ipacket[3]: 1 1 Yc Xc 0 W0 D^R U^L
2637 * ipacket[4]: X7 X6 X5 X4 X3 X2 X1 X0
2638 * ipacket[5]: Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
2641 * L: left physical mouse button
2642 * R: right physical mouse button
2650 * Without capFourButtons but with nExtendeButtons and/or capMiddle
2652 * Bits: 7 6 5 4 3 2 1 0 (LSB)
2653 * ------------------------------------------------------
2654 * ipacket[3]: 1 1 Yc Xc 0 W0 E^R M^L
2655 * ipacket[4]: X7 X6 X5 X4 X3|b7 X2|b5 X1|b3 X0|b1
2656 * ipacket[5]: Y7 Y6 Y5 Y4 Y3|b8 Y2|b6 Y1|b4 Y0|b2
2659 * M: Middle physical mouse button
2660 * E: Extended mouse buttons reported instead of low bits of X and Y
2661 * b1-b8: Extended mouse buttons
2662 * Only ((nExtendedButtons + 1) >> 1) bits are used in packet
2663 * 4 and 5, for reading X and Y value they should be zeroed.
2665 * Absolute reportable limits: 0 - 6143.
2666 * Typical bezel limits: 1472 - 5472.
2667 * Typical edge marings: 1632 - 5312.
2669 * w = 3 Passthrough Packet
2671 * Byte 2,5,6 == Byte 1,2,3 of "Guest"
2674 if (!synaptics_support)
2677 /* Sanity check for out of sync packets. */
2678 if ((pb->ipacket[0] & 0xc8) != 0x80 ||
2679 (pb->ipacket[3] & 0xc8) != 0xc0)
2687 * z = 0 No finger contact
2688 * z = 10 Finger hovering near the pad
2689 * z = 30 Very light finger contact
2690 * z = 80 Normal finger contact
2691 * z = 110 Very heavy finger contact
2692 * z = 200 Finger lying flat on pad surface
2693 * z = 255 Maximum reportable Z
2695 *z = pb->ipacket[2];
2698 * Finger width value
2700 * w = 0 Two finger on the pad (capMultiFinger needed)
2701 * w = 1 Three or more fingers (capMultiFinger needed)
2702 * w = 2 Pen (instead of finger) (capPen needed)
2703 * w = 3 Reserved (passthrough?)
2704 * w = 4-7 Finger of normal width (capPalmDetect needed)
2705 * w = 8-14 Very wide finger or palm (capPalmDetect needed)
2706 * w = 15 Maximum reportable width (capPalmDetect needed)
2708 /* XXX Is checking capExtended enough? */
2709 if (sc->synhw.capExtended)
2710 w = ((pb->ipacket[0] & 0x30) >> 2) |
2711 ((pb->ipacket[0] & 0x04) >> 1) |
2712 ((pb->ipacket[3] & 0x04) >> 2);
2714 /* Assume a finger of regular width. */
2719 * Handle packets from the guest device. See:
2720 * Synaptics PS/2 TouchPad Interfacing Guide, Section 5.1
2722 if (w == 3 && sc->synhw.capPassthrough) {
2723 *x = ((pb->ipacket[1] & 0x10) ?
2724 pb->ipacket[4] - 256 : pb->ipacket[4]);
2725 *y = ((pb->ipacket[1] & 0x20) ?
2726 pb->ipacket[5] - 256 : pb->ipacket[5]);
2730 if (pb->ipacket[1] & 0x01)
2731 guest_buttons |= MOUSE_BUTTON1DOWN;
2732 if (pb->ipacket[1] & 0x04)
2733 guest_buttons |= MOUSE_BUTTON2DOWN;
2734 if (pb->ipacket[1] & 0x02)
2735 guest_buttons |= MOUSE_BUTTON3DOWN;
2737 ms->button = touchpad_buttons | guest_buttons;
2741 if (sc->syninfo.touchpad_off) {
2743 ms->button = ms->obutton;
2747 /* Button presses */
2748 touchpad_buttons = 0;
2749 if (pb->ipacket[0] & 0x01)
2750 touchpad_buttons |= MOUSE_BUTTON1DOWN;
2751 if (pb->ipacket[0] & 0x02)
2752 touchpad_buttons |= MOUSE_BUTTON3DOWN;
2754 if (sc->synhw.capExtended && sc->synhw.capFourButtons) {
2755 if ((pb->ipacket[3] ^ pb->ipacket[0]) & 0x01)
2756 touchpad_buttons |= MOUSE_BUTTON4DOWN;
2757 if ((pb->ipacket[3] ^ pb->ipacket[0]) & 0x02)
2758 touchpad_buttons |= MOUSE_BUTTON5DOWN;
2759 } else if (sc->synhw.capExtended && sc->synhw.capMiddle &&
2760 !sc->synhw.capClickPad) {
2762 if ((pb->ipacket[0] ^ pb->ipacket[3]) & 0x01)
2763 touchpad_buttons |= MOUSE_BUTTON2DOWN;
2764 } else if (sc->synhw.capExtended && (sc->synhw.nExtendedButtons > 0)) {
2765 /* Extended Buttons */
2766 if ((pb->ipacket[0] ^ pb->ipacket[3]) & 0x02) {
2767 if (sc->syninfo.directional_scrolls) {
2768 if (pb->ipacket[4] & 0x01)
2769 touchpad_buttons |= MOUSE_BUTTON4DOWN;
2770 if (pb->ipacket[5] & 0x01)
2771 touchpad_buttons |= MOUSE_BUTTON5DOWN;
2772 if (pb->ipacket[4] & 0x02)
2773 touchpad_buttons |= MOUSE_BUTTON6DOWN;
2774 if (pb->ipacket[5] & 0x02)
2775 touchpad_buttons |= MOUSE_BUTTON7DOWN;
2777 if (pb->ipacket[4] & 0x01)
2778 touchpad_buttons |= MOUSE_BUTTON1DOWN;
2779 if (pb->ipacket[5] & 0x01)
2780 touchpad_buttons |= MOUSE_BUTTON3DOWN;
2781 if (pb->ipacket[4] & 0x02)
2782 touchpad_buttons |= MOUSE_BUTTON2DOWN;
2783 sc->extended_buttons = touchpad_buttons;
2787 * Zero out bits used by extended buttons to avoid
2788 * misinterpretation of the data absolute position.
2790 * The bits represented by
2792 * (nExtendedButtons + 1) >> 1
2794 * will be masked out in both bytes.
2795 * The mask for n bits is computed with the formula
2801 maskedbits = (sc->synhw.nExtendedButtons + 1) >> 1;
2802 mask = (1 << maskedbits) - 1;
2803 pb->ipacket[4] &= ~(mask);
2804 pb->ipacket[5] &= ~(mask);
2805 } else if (!sc->syninfo.directional_scrolls &&
2806 !sc->synaction.in_vscroll) {
2808 * Keep reporting MOUSE DOWN until we get a new packet
2809 * indicating otherwise.
2811 touchpad_buttons |= sc->extended_buttons;
2814 /* Handle ClickPad. */
2815 if (sc->synhw.capClickPad &&
2816 ((pb->ipacket[0] ^ pb->ipacket[3]) & 0x01))
2817 touchpad_buttons |= MOUSE_BUTTON1DOWN;
2819 ms->button = touchpad_buttons | guest_buttons;
2822 * Check pressure to detect a real wanted action on the
2825 if (*z >= sc->syninfo.min_pressure) {
2826 synapticsaction_t *synaction;
2827 int cursor, peer, window;
2828 int dx, dy, dxp, dyp;
2829 int max_width, max_pressure;
2830 int margin_top, margin_right, margin_bottom, margin_left;
2831 int na_top, na_right, na_bottom, na_left;
2832 int window_min, window_max;
2834 int weight_current, weight_previous, weight_len_squared;
2835 int div_min, div_max, div_len;
2836 int vscroll_hor_area, vscroll_ver_area;
2837 int two_finger_scroll;
2838 int len, weight_prev_x, weight_prev_y;
2839 int div_max_x, div_max_y, div_x, div_y;
2842 /* XXX Verify values? */
2843 max_width = sc->syninfo.max_width;
2844 max_pressure = sc->syninfo.max_pressure;
2845 margin_top = sc->syninfo.margin_top;
2846 margin_right = sc->syninfo.margin_right;
2847 margin_bottom = sc->syninfo.margin_bottom;
2848 margin_left = sc->syninfo.margin_left;
2849 na_top = sc->syninfo.na_top;
2850 na_right = sc->syninfo.na_right;
2851 na_bottom = sc->syninfo.na_bottom;
2852 na_left = sc->syninfo.na_left;
2853 window_min = sc->syninfo.window_min;
2854 window_max = sc->syninfo.window_max;
2855 multiplicator = sc->syninfo.multiplicator;
2856 weight_current = sc->syninfo.weight_current;
2857 weight_previous = sc->syninfo.weight_previous;
2858 weight_len_squared = sc->syninfo.weight_len_squared;
2859 div_min = sc->syninfo.div_min;
2860 div_max = sc->syninfo.div_max;
2861 div_len = sc->syninfo.div_len;
2862 vscroll_hor_area = sc->syninfo.vscroll_hor_area;
2863 vscroll_ver_area = sc->syninfo.vscroll_ver_area;
2864 two_finger_scroll = sc->syninfo.two_finger_scroll;
2866 /* Palm detection. */
2868 (sc->synhw.capMultiFinger && (w == 0 || w == 1)) ||
2869 (sc->synhw.capPalmDetect && w >= 4 && w <= max_width) ||
2870 (!sc->synhw.capPalmDetect && *z <= max_pressure) ||
2871 (sc->synhw.capPen && w == 2))) {
2873 * We consider the packet irrelevant for the current
2875 * - the width isn't comprised in:
2877 * - the pressure isn't comprised in:
2878 * [min_pressure; max_pressure]
2879 * - pen aren't supported but w is 2
2881 * Note that this doesn't terminate the current action.
2884 "synaptics: palm detected! (%d)\n", w));
2888 /* Read current absolute position. */
2889 x0 = ((pb->ipacket[3] & 0x10) << 8) |
2890 ((pb->ipacket[1] & 0x0f) << 8) |
2892 y0 = ((pb->ipacket[3] & 0x20) << 7) |
2893 ((pb->ipacket[1] & 0xf0) << 4) |
2896 synaction = &(sc->synaction);
2899 * If the action is just beginning, init the structure and
2900 * compute tap timeout.
2902 if (!(sc->flags & PSM_FLAGS_FINGERDOWN)) {
2903 VLOG(3, (LOG_DEBUG, "synaptics: ----\n"));
2905 /* Store the first point of this action. */
2906 synaction->start_x = x0;
2907 synaction->start_y = y0;
2910 /* Initialize queue. */
2911 synaction->queue_cursor = SYNAPTICS_PACKETQUEUE;
2912 synaction->queue_len = 0;
2913 synaction->window_min = window_min;
2915 /* Reset average. */
2916 synaction->avg_dx = 0;
2917 synaction->avg_dy = 0;
2919 /* Reset squelch. */
2920 synaction->squelch_x = 0;
2921 synaction->squelch_y = 0;
2923 /* Reset pressure peak. */
2926 /* Reset fingers count. */
2927 synaction->fingers_nb = 0;
2929 /* Reset virtual scrolling state. */
2930 synaction->in_vscroll = 0;
2932 /* Compute tap timeout. */
2933 sc->taptimeout.tv_sec = tap_timeout / 1000000;
2934 sc->taptimeout.tv_usec = tap_timeout % 1000000;
2935 timevaladd(&sc->taptimeout, &sc->lastsoftintr);
2937 sc->flags |= PSM_FLAGS_FINGERDOWN;
2939 /* Calculate the current delta. */
2940 cursor = synaction->queue_cursor;
2941 dx = x0 - synaction->queue[cursor].x;
2942 dy = y0 - synaction->queue[cursor].y;
2945 /* If in tap-hold, add the recorded button. */
2946 if (synaction->in_taphold)
2947 ms->button |= synaction->tap_button;
2950 * From now on, we can use the SYNAPTICS_END label to skip
2951 * the current packet.
2955 * Limit the coordinates to the specified margins because
2956 * this area isn't very reliable.
2958 if (x0 <= margin_left)
2960 else if (x0 >= 6143 - margin_right)
2961 x0 = 6143 - margin_right;
2962 if (y0 <= margin_bottom)
2964 else if (y0 >= 6143 - margin_top)
2965 y0 = 6143 - margin_top;
2967 VLOG(3, (LOG_DEBUG, "synaptics: ipacket: [%d, %d], %d, %d\n",
2970 /* Queue this new packet. */
2971 cursor = SYNAPTICS_QUEUE_CURSOR(synaction->queue_cursor - 1);
2972 synaction->queue[cursor].x = x0;
2973 synaction->queue[cursor].y = y0;
2974 synaction->queue_cursor = cursor;
2975 if (synaction->queue_len < SYNAPTICS_PACKETQUEUE)
2976 synaction->queue_len++;
2978 "synaptics: cursor[%d]: x=%d, y=%d, dx=%d, dy=%d\n",
2979 cursor, x0, y0, dx, dy));
2982 * For tap, we keep the maximum number of fingers and the
2983 * pressure peak. Also with multiple fingers, we increase
2984 * the minimum window.
2987 case 1: /* Three or more fingers. */
2988 synaction->fingers_nb = imax(3, synaction->fingers_nb);
2989 synaction->window_min = window_max;
2991 case 0: /* Two fingers. */
2992 synaction->fingers_nb = imax(2, synaction->fingers_nb);
2993 synaction->window_min = window_max;
2995 default: /* One finger or undetectable. */
2996 synaction->fingers_nb = imax(1, synaction->fingers_nb);
2998 sc->zmax = imax(*z, sc->zmax);
3000 /* Do we have enough packets to consider this a movement? */
3001 if (synaction->queue_len < synaction->window_min)
3004 /* Is a scrolling action occuring? */
3005 if (!synaction->in_taphold && !synaction->in_vscroll) {
3007 * A scrolling action must not conflict with a tap
3008 * action. Here are the conditions to consider a
3010 * - the action in a configurable area
3011 * - one of the following:
3012 * . the distance between the last packet and the
3013 * first should be above a configurable minimum
3016 dxp = abs(synaction->queue[synaction->queue_cursor].x -
3017 synaction->start_x);
3018 dyp = abs(synaction->queue[synaction->queue_cursor].y -
3019 synaction->start_y);
3021 if (timevalcmp(&sc->lastsoftintr, &sc->taptimeout, >) ||
3022 dxp >= sc->syninfo.vscroll_min_delta ||
3023 dyp >= sc->syninfo.vscroll_min_delta) {
3025 * Handle two finger scrolling.
3026 * Note that we don't rely on fingers_nb
3027 * as that keeps the maximum number of fingers.
3029 if (two_finger_scroll) {
3031 synaction->in_vscroll +=
3033 synaction->in_vscroll +=
3037 /* Check for horizontal scrolling. */
3038 if ((vscroll_hor_area > 0 &&
3039 synaction->start_y <=
3040 vscroll_hor_area) ||
3041 (vscroll_hor_area < 0 &&
3042 synaction->start_y >=
3043 6143 + vscroll_hor_area))
3044 synaction->in_vscroll += 2;
3046 /* Check for vertical scrolling. */
3047 if ((vscroll_ver_area > 0 &&
3048 synaction->start_x <=
3049 vscroll_ver_area) ||
3050 (vscroll_ver_area < 0 &&
3051 synaction->start_x >=
3052 6143 + vscroll_ver_area))
3053 synaction->in_vscroll += 1;
3056 /* Avoid conflicts if area overlaps. */
3057 if (synaction->in_vscroll >= 3)
3058 synaction->in_vscroll =
3059 (dxp > dyp) ? 2 : 1;
3063 * Reset two finger scrolling when the number of fingers
3064 * is different from two.
3066 if (two_finger_scroll && w != 0)
3067 synaction->in_vscroll = 0;
3070 "synaptics: virtual scrolling: %s "
3071 "(direction=%d, dxp=%d, dyp=%d, fingers=%d)\n",
3072 synaction->in_vscroll ? "YES" : "NO",
3073 synaction->in_vscroll, dxp, dyp,
3074 synaction->fingers_nb));
3076 weight_prev_x = weight_prev_y = weight_previous;
3077 div_max_x = div_max_y = div_max;
3079 if (synaction->in_vscroll) {
3080 /* Dividers are different with virtual scrolling. */
3081 div_min = sc->syninfo.vscroll_div_min;
3082 div_max_x = div_max_y = sc->syninfo.vscroll_div_max;
3085 * There's a lot of noise in coordinates when
3086 * the finger is on the touchpad's borders. When
3087 * using this area, we apply a special weight and
3090 if (x0 <= na_left || x0 >= 6143 - na_right) {
3091 weight_prev_x = sc->syninfo.weight_previous_na;
3092 div_max_x = sc->syninfo.div_max_na;
3095 if (y0 <= na_bottom || y0 >= 6143 - na_top) {
3096 weight_prev_y = sc->syninfo.weight_previous_na;
3097 div_max_y = sc->syninfo.div_max_na;
3102 * Calculate weights for the average operands and
3103 * the divisor. Both depend on the distance between
3104 * the current packet and a previous one (based on the
3107 window = imin(synaction->queue_len, window_max);
3108 peer = SYNAPTICS_QUEUE_CURSOR(cursor + window - 1);
3109 dxp = abs(x0 - synaction->queue[peer].x) + 1;
3110 dyp = abs(y0 - synaction->queue[peer].y) + 1;
3111 len = (dxp * dxp) + (dyp * dyp);
3112 weight_prev_x = imin(weight_prev_x,
3113 weight_len_squared * weight_prev_x / len);
3114 weight_prev_y = imin(weight_prev_y,
3115 weight_len_squared * weight_prev_y / len);
3117 len = (dxp + dyp) / 2;
3118 div_x = div_len * div_max_x / len;
3119 div_x = imin(div_max_x, div_x);
3120 div_x = imax(div_min, div_x);
3121 div_y = div_len * div_max_y / len;
3122 div_y = imin(div_max_y, div_y);
3123 div_y = imax(div_min, div_y);
3126 "synaptics: peer=%d, len=%d, weight=%d/%d, div=%d/%d\n",
3127 peer, len, weight_prev_x, weight_prev_y, div_x, div_y));
3129 /* Compute averages. */
3131 (weight_current * dx * multiplicator +
3132 weight_prev_x * synaction->avg_dx) /
3133 (weight_current + weight_prev_x);
3136 (weight_current * dy * multiplicator +
3137 weight_prev_y * synaction->avg_dy) /
3138 (weight_current + weight_prev_y);
3141 "synaptics: avg_dx~=%d, avg_dy~=%d\n",
3142 synaction->avg_dx / multiplicator,
3143 synaction->avg_dy / multiplicator));
3145 /* Use these averages to calculate x & y. */
3146 synaction->squelch_x += synaction->avg_dx;
3147 *x = synaction->squelch_x / (div_x * multiplicator);
3148 synaction->squelch_x = synaction->squelch_x %
3149 (div_x * multiplicator);
3151 synaction->squelch_y += synaction->avg_dy;
3152 *y = synaction->squelch_y / (div_y * multiplicator);
3153 synaction->squelch_y = synaction->squelch_y %
3154 (div_y * multiplicator);
3156 if (synaction->in_vscroll) {
3157 switch(synaction->in_vscroll) {
3158 case 1: /* Vertical scrolling. */
3160 ms->button |= (*y > 0) ?
3164 case 2: /* Horizontal scrolling. */
3166 ms->button |= (*x > 0) ?
3172 /* The pointer is not moved. */
3175 VLOG(3, (LOG_DEBUG, "synaptics: [%d, %d] -> [%d, %d]\n",
3178 } else if (sc->flags & PSM_FLAGS_FINGERDOWN) {
3180 * An action is currently taking place but the pressure
3181 * dropped under the minimum, putting an end to it.
3183 synapticsaction_t *synaction;
3184 int taphold_timeout, dx, dy, tap_max_delta;
3186 synaction = &(sc->synaction);
3187 dx = abs(synaction->queue[synaction->queue_cursor].x -
3188 synaction->start_x);
3189 dy = abs(synaction->queue[synaction->queue_cursor].y -
3190 synaction->start_y);
3192 /* Max delta is disabled for multi-fingers tap. */
3193 if (synaction->fingers_nb > 1)
3194 tap_max_delta = imax(dx, dy);
3196 tap_max_delta = sc->syninfo.tap_max_delta;
3198 sc->flags &= ~PSM_FLAGS_FINGERDOWN;
3200 /* Check for tap. */
3202 "synaptics: zmax=%d, dx=%d, dy=%d, "
3203 "delta=%d, fingers=%d, queue=%d\n",
3204 sc->zmax, dx, dy, tap_max_delta, synaction->fingers_nb,
3205 synaction->queue_len));
3206 if (!synaction->in_vscroll && sc->zmax >= tap_threshold &&
3207 timevalcmp(&sc->lastsoftintr, &sc->taptimeout, <=) &&
3208 dx <= tap_max_delta && dy <= tap_max_delta &&
3209 synaction->queue_len >= sc->syninfo.tap_min_queue) {
3212 * - the maximum pressure went over tap_threshold
3213 * - the action ended before tap_timeout
3215 * To handle tap-hold, we must delay any button push to
3218 if (synaction->in_taphold) {
3220 * This is the second and last tap of a
3221 * double tap action, not a tap-hold.
3223 synaction->in_taphold = 0;
3226 * For double-tap to work:
3227 * - no button press is emitted (to
3228 * simulate a button release)
3229 * - PSM_FLAGS_FINGERDOWN is set to
3230 * force the next packet to emit a
3234 "synaptics: button RELEASE: %d\n",
3235 synaction->tap_button));
3236 sc->flags |= PSM_FLAGS_FINGERDOWN;
3239 * This is the first tap: we set the
3240 * tap-hold state and notify the button
3243 synaction->in_taphold = 1;
3244 taphold_timeout = sc->syninfo.taphold_timeout;
3245 sc->taptimeout.tv_sec = taphold_timeout /
3247 sc->taptimeout.tv_usec = taphold_timeout %
3249 timevaladd(&sc->taptimeout, &sc->lastsoftintr);
3251 switch (synaction->fingers_nb) {
3253 synaction->tap_button =
3257 synaction->tap_button =
3261 synaction->tap_button =
3265 "synaptics: button PRESS: %d\n",
3266 synaction->tap_button));
3267 ms->button |= synaction->tap_button;
3271 * Not enough pressure or timeout: reset
3274 if (synaction->in_taphold) {
3276 "synaptics: button RELEASE: %d\n",
3277 synaction->tap_button));
3278 synaction->in_taphold = 0;
3281 "synaptics: not a tap-hold\n"));
3284 } else if (!(sc->flags & PSM_FLAGS_FINGERDOWN) &&
3285 sc->synaction.in_taphold) {
3287 * For a tap-hold to work, the button must remain down at
3288 * least until timeout (where the in_taphold flags will be
3289 * cleared) or during the next action.
3291 if (timevalcmp(&sc->lastsoftintr, &sc->taptimeout, <=)) {
3292 ms->button |= sc->synaction.tap_button;
3295 "synaptics: button RELEASE: %d\n",
3296 sc->synaction.tap_button));
3297 sc->synaction.in_taphold = 0;
3303 * Use the extra buttons as a scrollwheel
3305 * XXX X.Org uses the Z axis for vertical wheel only,
3306 * whereas moused(8) understands special values to differ
3307 * vertical and horizontal wheels.
3309 * xf86-input-mouse needs therefore a small patch to
3310 * understand these special values. Without it, the
3311 * horizontal wheel acts as a vertical wheel in X.Org.
3313 * That's why the horizontal wheel is disabled by
3317 if (ms->button & MOUSE_BUTTON4DOWN) {
3319 ms->button &= ~MOUSE_BUTTON4DOWN;
3320 } else if (ms->button & MOUSE_BUTTON5DOWN) {
3322 ms->button &= ~MOUSE_BUTTON5DOWN;
3323 } else if (ms->button & MOUSE_BUTTON6DOWN) {
3325 ms->button &= ~MOUSE_BUTTON6DOWN;
3326 } else if (ms->button & MOUSE_BUTTON7DOWN) {
3328 ms->button &= ~MOUSE_BUTTON7DOWN;
3336 proc_versapad(struct psm_softc *sc, packetbuf_t *pb, mousestatus_t *ms,
3337 int *x, int *y, int *z)
3339 static int butmap_versapad[8] = {
3345 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
3347 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN
3351 /* VersaPad PS/2 absolute mode message format
3353 * [packet1] 7 6 5 4 3 2 1 0(LSB)
3354 * ipacket[0]: 1 1 0 A 1 L T R
3355 * ipacket[1]: H7 H6 H5 H4 H3 H2 H1 H0
3356 * ipacket[2]: V7 V6 V5 V4 V3 V2 V1 V0
3357 * ipacket[3]: 1 1 1 A 1 L T R
3358 * ipacket[4]:V11 V10 V9 V8 H11 H10 H9 H8
3359 * ipacket[5]: 0 P6 P5 P4 P3 P2 P1 P0
3362 * R: right physical mouse button (1=on)
3363 * T: touch pad virtual button (1=tapping)
3364 * L: left physical mouse button (1=on)
3365 * A: position data is valid (1=valid)
3366 * H: horizontal data (12bit signed integer. H11 is sign bit.)
3367 * V: vertical data (12bit signed integer. V11 is sign bit.)
3370 * Tapping is mapped to MOUSE_BUTTON4.
3374 ms->button = butmap_versapad[c & MOUSE_PS2VERSA_BUTTONS];
3375 ms->button |= (c & MOUSE_PS2VERSA_TAP) ? MOUSE_BUTTON4DOWN : 0;
3376 if (c & MOUSE_PS2VERSA_IN_USE) {
3377 x0 = pb->ipacket[1] | (((pb->ipacket[4]) & 0x0f) << 8);
3378 y0 = pb->ipacket[2] | (((pb->ipacket[4]) & 0xf0) << 4);
3383 if (sc->flags & PSM_FLAGS_FINGERDOWN) {
3386 if (*x < 0) /* XXX */
3395 sc->flags |= PSM_FLAGS_FINGERDOWN;
3399 sc->flags &= ~PSM_FLAGS_FINGERDOWN;
3403 psmsoftintr(void *arg)
3406 * the table to turn PS/2 mouse button bits (MOUSE_PS2_BUTTON?DOWN)
3407 * into `mousestatus' button bits (MOUSE_BUTTON?DOWN).
3409 static int butmap[8] = {
3413 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
3415 MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN,
3416 MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN,
3417 MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN
3419 struct psm_softc *sc = arg;
3422 int x, y, z, c, l, s;
3424 getmicrouptime(&sc->lastsoftintr);
3429 pb = &sc->pqueue[sc->pqueue_start];
3431 if (sc->mode.level == PSM_LEVEL_NATIVE)
3436 * A kludge for Kensington device!
3437 * The MSB of the horizontal count appears to be stored in
3440 if (sc->hw.model == MOUSE_MODEL_THINK)
3441 pb->ipacket[1] |= (c & MOUSE_PS2_XOVERFLOW) ? 0x80 : 0;
3443 /* ignore the overflow bits... */
3444 x = (c & MOUSE_PS2_XNEG) ?
3445 pb->ipacket[1] - 256 : pb->ipacket[1];
3446 y = (c & MOUSE_PS2_YNEG) ?
3447 pb->ipacket[2] - 256 : pb->ipacket[2];
3449 ms.obutton = sc->button; /* previous button state */
3450 ms.button = butmap[c & MOUSE_PS2_BUTTONS];
3451 /* `tapping' action */
3452 if (sc->config & PSM_CONFIG_FORCETAP)
3453 ms.button |= ((c & MOUSE_PS2_TAP)) ?
3454 0 : MOUSE_BUTTON4DOWN;
3456 switch (sc->hw.model) {
3458 case MOUSE_MODEL_EXPLORER:
3460 * b7 b6 b5 b4 b3 b2 b1 b0
3461 * byte 1: oy ox sy sx 1 M R L
3462 * byte 2: x x x x x x x x
3463 * byte 3: y y y y y y y y
3464 * byte 4: * * S2 S1 s d2 d1 d0
3466 * L, M, R, S1, S2: left, middle, right and side buttons
3467 * s: wheel data sign bit
3470 z = (pb->ipacket[3] & MOUSE_EXPLORER_ZNEG) ?
3471 (pb->ipacket[3] & 0x0f) - 16 :
3472 (pb->ipacket[3] & 0x0f);
3474 (pb->ipacket[3] & MOUSE_EXPLORER_BUTTON4DOWN) ?
3475 MOUSE_BUTTON4DOWN : 0;
3477 (pb->ipacket[3] & MOUSE_EXPLORER_BUTTON5DOWN) ?
3478 MOUSE_BUTTON5DOWN : 0;
3481 case MOUSE_MODEL_INTELLI:
3482 case MOUSE_MODEL_NET:
3483 /* wheel data is in the fourth byte */
3484 z = (char)pb->ipacket[3];
3486 * XXX some mice may send 7 when there is no Z movement? */
3487 if ((z >= 7) || (z <= -7))
3489 /* some compatible mice have additional buttons */
3490 ms.button |= (c & MOUSE_PS2INTELLI_BUTTON4DOWN) ?
3491 MOUSE_BUTTON4DOWN : 0;
3492 ms.button |= (c & MOUSE_PS2INTELLI_BUTTON5DOWN) ?
3493 MOUSE_BUTTON5DOWN : 0;
3496 case MOUSE_MODEL_MOUSEMANPLUS:
3497 proc_mmanplus(sc, pb, &ms, &x, &y, &z);
3500 case MOUSE_MODEL_GLIDEPOINT:
3501 /* `tapping' action */
3502 ms.button |= ((c & MOUSE_PS2_TAP)) ? 0 :
3506 case MOUSE_MODEL_NETSCROLL:
3508 * three addtional bytes encode buttons and
3511 ms.button |= (pb->ipacket[3] & MOUSE_PS2_BUTTON3DOWN) ?
3512 MOUSE_BUTTON4DOWN : 0;
3513 ms.button |= (pb->ipacket[3] & MOUSE_PS2_BUTTON1DOWN) ?
3514 MOUSE_BUTTON5DOWN : 0;
3515 z = (pb->ipacket[3] & MOUSE_PS2_XNEG) ?
3516 pb->ipacket[4] - 256 : pb->ipacket[4];
3519 case MOUSE_MODEL_THINK:
3520 /* the fourth button state in the first byte */
3521 ms.button |= (c & MOUSE_PS2_TAP) ?
3522 MOUSE_BUTTON4DOWN : 0;
3525 case MOUSE_MODEL_VERSAPAD:
3526 proc_versapad(sc, pb, &ms, &x, &y, &z);
3527 c = ((x < 0) ? MOUSE_PS2_XNEG : 0) |
3528 ((y < 0) ? MOUSE_PS2_YNEG : 0);
3531 case MOUSE_MODEL_4D:
3533 * b7 b6 b5 b4 b3 b2 b1 b0
3534 * byte 1: s2 d2 s1 d1 1 M R L
3535 * byte 2: sx x x x x x x x
3536 * byte 3: sy y y y y y y y
3538 * s1: wheel 1 direction
3540 * s2: wheel 2 direction
3543 x = (pb->ipacket[1] & 0x80) ?
3544 pb->ipacket[1] - 256 : pb->ipacket[1];
3545 y = (pb->ipacket[2] & 0x80) ?
3546 pb->ipacket[2] - 256 : pb->ipacket[2];
3547 switch (c & MOUSE_4D_WHEELBITS) {
3554 case 0x40: /* XXX 2nd wheel turning right */
3557 case 0xc0: /* XXX 2nd wheel turning left */
3563 case MOUSE_MODEL_4DPLUS:
3564 if ((x < 16 - 256) && (y < 16 - 256)) {
3566 * b7 b6 b5 b4 b3 b2 b1 b0
3567 * byte 1: 0 0 1 1 1 M R L
3568 * byte 2: 0 0 0 0 1 0 0 0
3569 * byte 3: 0 0 0 0 S s d1 d0
3571 * L, M, R, S: left, middle, right,
3573 * s: wheel data sign bit
3577 if (pb->ipacket[2] & MOUSE_4DPLUS_BUTTON4DOWN)
3578 ms.button |= MOUSE_BUTTON4DOWN;
3579 z = (pb->ipacket[2] & MOUSE_4DPLUS_ZNEG) ?
3580 ((pb->ipacket[2] & 0x07) - 8) :
3581 (pb->ipacket[2] & 0x07) ;
3583 /* preserve previous button states */
3584 ms.button |= ms.obutton & MOUSE_EXTBUTTONS;
3588 case MOUSE_MODEL_SYNAPTICS:
3589 if (proc_synaptics(sc, pb, &ms, &x, &y, &z) != 0)
3593 case MOUSE_MODEL_TRACKPOINT:
3594 case MOUSE_MODEL_GENERIC:
3600 if (sc->mode.accelfactor >= 1) {
3602 x = x * x / sc->mode.accelfactor;
3605 if (c & MOUSE_PS2_XNEG)
3609 y = y * y / sc->mode.accelfactor;
3612 if (c & MOUSE_PS2_YNEG)
3620 ms.flags = ((x || y || z) ? MOUSE_POSCHANGED : 0) |
3621 (ms.obutton ^ ms.button);
3623 pb->inputbytes = tame_mouse(sc, pb, &ms, pb->ipacket);
3625 sc->status.flags |= ms.flags;
3626 sc->status.dx += ms.dx;
3627 sc->status.dy += ms.dy;
3628 sc->status.dz += ms.dz;
3629 sc->status.button = ms.button;
3630 sc->button = ms.button;
3633 sc->watchdog = FALSE;
3636 if (sc->queue.count + pb->inputbytes < sizeof(sc->queue.buf)) {
3637 l = imin(pb->inputbytes,
3638 sizeof(sc->queue.buf) - sc->queue.tail);
3639 bcopy(&pb->ipacket[0], &sc->queue.buf[sc->queue.tail], l);
3640 if (pb->inputbytes > l)
3641 bcopy(&pb->ipacket[l], &sc->queue.buf[0],
3642 pb->inputbytes - l);
3643 sc->queue.tail = (sc->queue.tail + pb->inputbytes) %
3644 sizeof(sc->queue.buf);
3645 sc->queue.count += pb->inputbytes;
3650 if (++sc->pqueue_start >= PSM_PACKETQUEUE)
3651 sc->pqueue_start = 0;
3652 } while (sc->pqueue_start != sc->pqueue_end);
3654 if (sc->state & PSM_ASLP) {
3655 sc->state &= ~PSM_ASLP;
3658 selwakeuppri(&sc->rsel, PZERO);
3659 if (sc->async != NULL) {
3660 pgsigio(&sc->async, SIGIO, 0);
3662 sc->state &= ~PSM_SOFTARMED;
3667 psmpoll(struct cdev *dev, int events, struct thread *td)
3669 struct psm_softc *sc = dev->si_drv1;
3673 /* Return true if a mouse event available */
3675 if (events & (POLLIN | POLLRDNORM)) {
3676 if (sc->queue.count > 0)
3677 revents |= events & (POLLIN | POLLRDNORM);
3679 selrecord(td, &sc->rsel);
3686 /* vendor/model specific routines */
3688 static int mouse_id_proc1(KBDC kbdc, int res, int scale, int *status)
3690 if (set_mouse_resolution(kbdc, res) != res)
3692 if (set_mouse_scaling(kbdc, scale) &&
3693 set_mouse_scaling(kbdc, scale) &&
3694 set_mouse_scaling(kbdc, scale) &&
3695 (get_mouse_status(kbdc, status, 0, 3) >= 3))
3701 mouse_ext_command(KBDC kbdc, int command)
3705 c = (command >> 6) & 0x03;
3706 if (set_mouse_resolution(kbdc, c) != c)
3708 c = (command >> 4) & 0x03;
3709 if (set_mouse_resolution(kbdc, c) != c)
3711 c = (command >> 2) & 0x03;
3712 if (set_mouse_resolution(kbdc, c) != c)
3714 c = (command >> 0) & 0x03;
3715 if (set_mouse_resolution(kbdc, c) != c)
3721 /* Logitech MouseMan Cordless II */
3723 enable_lcordless(KDBC kbdc, struct psm_softc *sc)
3728 if (!mouse_id_proc1(kbdc, PSMD_RES_HIGH, 2, status))
3730 if (status[1] == PSMD_RES_HIGH)
3732 ch = (status[0] & 0x07) - 1; /* channel # */
3733 if ((ch <= 0) || (ch > 4))
3736 * status[1]: always one?
3737 * status[2]: battery status? (0-100)
3743 /* Genius NetScroll Mouse, MouseSystems SmartScroll Mouse */
3745 enable_groller(KBDC kbdc, struct psm_softc *sc)
3750 * The special sequence to enable the fourth button and the
3751 * roller. Immediately after this sequence check status bytes.
3752 * if the mouse is NetScroll, the second and the third bytes are
3757 * If the mouse is an ordinary PS/2 mouse, the status bytes should
3758 * look like the following.
3760 * byte 1 bit 7 always 0
3761 * bit 6 stream mode (0)
3762 * bit 5 disabled (0)
3763 * bit 4 1:1 scaling (0)
3765 * bit 0-2 button status
3766 * byte 2 resolution (PSMD_RES_HIGH)
3767 * byte 3 report rate (?)
3770 if (!mouse_id_proc1(kbdc, PSMD_RES_HIGH, 1, status))
3772 if ((status[1] != '3') || (status[2] != 'D'))
3774 /* FIXME: SmartScroll Mouse has 5 buttons! XXX */
3780 /* Genius NetMouse/NetMouse Pro, ASCII Mie Mouse, NetScroll Optical */
3782 enable_gmouse(KBDC kbdc, struct psm_softc *sc)
3787 * The special sequence to enable the middle, "rubber" button.
3788 * Immediately after this sequence check status bytes.
3789 * if the mouse is NetMouse, NetMouse Pro, or ASCII MIE Mouse,
3790 * the second and the third bytes are '3' and 'U'.
3791 * NOTE: NetMouse reports that it has three buttons although it has
3792 * two buttons and a rubber button. NetMouse Pro and MIE Mouse
3793 * say they have three buttons too and they do have a button on the
3796 if (!mouse_id_proc1(kbdc, PSMD_RES_HIGH, 1, status))
3798 if ((status[1] != '3') || (status[2] != 'U'))
3803 /* ALPS GlidePoint */
3805 enable_aglide(KBDC kbdc, struct psm_softc *sc)
3810 * The special sequence to obtain ALPS GlidePoint specific
3811 * information. Immediately after this sequence, status bytes will
3812 * contain something interesting.
3813 * NOTE: ALPS produces several models of GlidePoint. Some of those
3814 * do not respond to this sequence, thus, cannot be detected this way.
3816 if (set_mouse_sampling_rate(kbdc, 100) != 100)
3818 if (!mouse_id_proc1(kbdc, PSMD_RES_LOW, 2, status))
3820 if ((status[1] == PSMD_RES_LOW) || (status[2] == 100))
3825 /* Kensington ThinkingMouse/Trackball */
3827 enable_kmouse(KBDC kbdc, struct psm_softc *sc)
3829 static u_char rate[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
3835 id1 = get_aux_id(kbdc);
3836 if (set_mouse_sampling_rate(kbdc, 10) != 10)
3839 * The device is now in the native mode? It returns a different
3842 id2 = get_aux_id(kbdc);
3843 if ((id1 == id2) || (id2 != 2))
3846 if (set_mouse_resolution(kbdc, PSMD_RES_LOW) != PSMD_RES_LOW)
3849 /* at this point, resolution is LOW, sampling rate is 10/sec */
3850 if (get_mouse_status(kbdc, status, 0, 3) < 3)
3855 * The special sequence to enable the third and fourth buttons.
3856 * Otherwise they behave like the first and second buttons.
3858 for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i)
3859 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
3863 * At this point, the device is using default resolution and
3864 * sampling rate for the native mode.
3866 if (get_mouse_status(kbdc, status, 0, 3) < 3)
3868 if ((status[1] == PSMD_RES_LOW) || (status[2] == rate[i - 1]))
3871 /* the device appears be enabled by this sequence, diable it for now */
3872 disable_aux_dev(kbdc);
3873 empty_aux_buffer(kbdc, 5);
3878 /* Logitech MouseMan+/FirstMouse+, IBM ScrollPoint Mouse */
3880 enable_mmanplus(KBDC kbdc, struct psm_softc *sc)
3884 /* the special sequence to enable the fourth button and the roller. */
3886 * NOTE: for ScrollPoint to respond correctly, the SET_RESOLUTION
3887 * must be called exactly three times since the last RESET command
3888 * before this sequence. XXX
3890 if (!set_mouse_scaling(kbdc, 1))
3892 if (!mouse_ext_command(kbdc, 0x39) || !mouse_ext_command(kbdc, 0xdb))
3894 if (get_mouse_status(kbdc, data, 1, 3) < 3)
3898 * PS2++ protocol, packet type 0
3900 * b7 b6 b5 b4 b3 b2 b1 b0
3901 * byte 1: * 1 p3 p2 1 * * *
3902 * byte 2: 1 1 p1 p0 m1 m0 1 0
3903 * byte 3: m7 m6 m5 m4 m3 m2 m1 m0
3905 * p3-p0: packet type: 0
3906 * m7-m0: model ID: MouseMan+:0x50,
3908 * ScrollPoint:0x58...
3910 /* check constant bits */
3911 if ((data[0] & MOUSE_PS2PLUS_SYNCMASK) != MOUSE_PS2PLUS_SYNC)
3913 if ((data[1] & 0xc3) != 0xc2)
3915 /* check d3-d0 in byte 2 */
3916 if (!MOUSE_PS2PLUS_CHECKBITS(data))
3919 if (MOUSE_PS2PLUS_PACKET_TYPE(data) != 0)
3923 sc->hw.hwid &= 0x00ff;
3924 sc->hw.hwid |= data[2] << 8; /* save model ID */
3928 * MouseMan+ (or FirstMouse+) is now in its native mode, in which
3929 * the wheel and the fourth button events are encoded in the
3930 * special data packet. The mouse may be put in the IntelliMouse mode
3931 * if it is initialized by the IntelliMouse's method.
3936 /* MS IntelliMouse Explorer */
3938 enable_msexplorer(KBDC kbdc, struct psm_softc *sc)
3940 static u_char rate0[] = { 200, 100, 80, };
3941 static u_char rate1[] = { 200, 200, 80, };
3946 * This is needed for at least A4Tech X-7xx mice - they do not go
3947 * straight to Explorer mode, but need to be set to Intelli mode
3950 enable_msintelli(kbdc, sc);
3952 /* the special sequence to enable the extra buttons and the roller. */
3953 for (i = 0; i < sizeof(rate1)/sizeof(rate1[0]); ++i)
3954 if (set_mouse_sampling_rate(kbdc, rate1[i]) != rate1[i])
3956 /* the device will give the genuine ID only after the above sequence */
3957 id = get_aux_id(kbdc);
3958 if (id != PSM_EXPLORER_ID)
3962 sc->hw.buttons = 5; /* IntelliMouse Explorer XXX */
3967 * XXX: this is a kludge to fool some KVM switch products
3968 * which think they are clever enough to know the 4-byte IntelliMouse
3969 * protocol, and assume any other protocols use 3-byte packets.
3970 * They don't convey 4-byte data packets from the IntelliMouse Explorer
3971 * correctly to the host computer because of this!
3972 * The following sequence is actually IntelliMouse's "wake up"
3973 * sequence; it will make the KVM think the mouse is IntelliMouse
3974 * when it is in fact IntelliMouse Explorer.
3976 for (i = 0; i < sizeof(rate0)/sizeof(rate0[0]); ++i)
3977 if (set_mouse_sampling_rate(kbdc, rate0[i]) != rate0[i])
3984 /* MS IntelliMouse */
3986 enable_msintelli(KBDC kbdc, struct psm_softc *sc)
3989 * Logitech MouseMan+ and FirstMouse+ will also respond to this
3990 * probe routine and act like IntelliMouse.
3993 static u_char rate[] = { 200, 100, 80, };
3997 /* the special sequence to enable the third button and the roller. */
3998 for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i)
3999 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
4001 /* the device will give the genuine ID only after the above sequence */
4002 id = get_aux_id(kbdc);
4003 if (id != PSM_INTELLI_ID)
4014 /* A4 Tech 4D Mouse */
4016 enable_4dmouse(KBDC kbdc, struct psm_softc *sc)
4019 * Newer wheel mice from A4 Tech may use the 4D+ protocol.
4022 static u_char rate[] = { 200, 100, 80, 60, 40, 20 };
4026 for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i)
4027 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
4029 id = get_aux_id(kbdc);
4031 * WinEasy 4D, 4 Way Scroll 4D: 6
4032 * Cable-Free 4D: 8 (4DPLUS)
4033 * WinBest 4D+, 4 Way Scroll 4D+: 8 (4DPLUS)
4035 if (id != PSM_4DMOUSE_ID)
4039 sc->hw.buttons = 3; /* XXX some 4D mice have 4? */
4046 /* A4 Tech 4D+ Mouse */
4048 enable_4dplus(KBDC kbdc, struct psm_softc *sc)
4051 * Newer wheel mice from A4 Tech seem to use this protocol.
4052 * Older models are recognized as either 4D Mouse or IntelliMouse.
4057 * enable_4dmouse() already issued the following ID sequence...
4058 static u_char rate[] = { 200, 100, 80, 60, 40, 20 };
4061 for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i)
4062 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
4066 id = get_aux_id(kbdc);
4070 case PSM_4DPLUS_RFSW35_ID:
4077 sc->hw.buttons = (id == PSM_4DPLUS_ID) ? 4 : 3;
4084 /* Synaptics Touchpad */
4086 synaptics_sysctl(SYSCTL_HANDLER_ARGS)
4090 /* Read the current value. */
4091 arg = *(int *)oidp->oid_arg1;
4092 error = sysctl_handle_int(oidp, &arg, 0, req);
4095 if (error || !req->newptr)
4099 * Check that the new value is in the concerned node's range
4102 switch (oidp->oid_arg2) {
4103 case SYNAPTICS_SYSCTL_MIN_PRESSURE:
4104 case SYNAPTICS_SYSCTL_MAX_PRESSURE:
4105 if (arg < 0 || arg > 255)
4108 case SYNAPTICS_SYSCTL_MAX_WIDTH:
4109 if (arg < 4 || arg > 15)
4112 case SYNAPTICS_SYSCTL_MARGIN_TOP:
4113 case SYNAPTICS_SYSCTL_MARGIN_RIGHT:
4114 case SYNAPTICS_SYSCTL_MARGIN_BOTTOM:
4115 case SYNAPTICS_SYSCTL_MARGIN_LEFT:
4116 case SYNAPTICS_SYSCTL_NA_TOP:
4117 case SYNAPTICS_SYSCTL_NA_RIGHT:
4118 case SYNAPTICS_SYSCTL_NA_BOTTOM:
4119 case SYNAPTICS_SYSCTL_NA_LEFT:
4120 if (arg < 0 || arg > 6143)
4123 case SYNAPTICS_SYSCTL_WINDOW_MIN:
4124 case SYNAPTICS_SYSCTL_WINDOW_MAX:
4125 case SYNAPTICS_SYSCTL_TAP_MIN_QUEUE:
4126 if (arg < 1 || arg > SYNAPTICS_PACKETQUEUE)
4129 case SYNAPTICS_SYSCTL_MULTIPLICATOR:
4130 case SYNAPTICS_SYSCTL_WEIGHT_CURRENT:
4131 case SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS:
4132 case SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA:
4133 case SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED:
4134 case SYNAPTICS_SYSCTL_DIV_MIN:
4135 case SYNAPTICS_SYSCTL_DIV_MAX:
4136 case SYNAPTICS_SYSCTL_DIV_MAX_NA:
4137 case SYNAPTICS_SYSCTL_DIV_LEN:
4138 case SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN:
4139 case SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX:
4143 case SYNAPTICS_SYSCTL_TAP_MAX_DELTA:
4144 case SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT:
4145 case SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA:
4149 case SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA:
4150 case SYNAPTICS_SYSCTL_VSCROLL_VER_AREA:
4151 if (arg < -6143 || arg > 6143)
4154 case SYNAPTICS_SYSCTL_TOUCHPAD_OFF:
4155 if (arg < 0 || arg > 1)
4163 *(int *)oidp->oid_arg1 = arg;
4169 synaptics_sysctl_create_tree(struct psm_softc *sc)
4172 if (sc->syninfo.sysctl_tree != NULL)
4175 /* Attach extra synaptics sysctl nodes under hw.psm.synaptics */
4176 sysctl_ctx_init(&sc->syninfo.sysctl_ctx);
4177 sc->syninfo.sysctl_tree = SYSCTL_ADD_NODE(&sc->syninfo.sysctl_ctx,
4178 SYSCTL_STATIC_CHILDREN(_hw_psm), OID_AUTO, "synaptics", CTLFLAG_RD,
4179 0, "Synaptics TouchPad");
4181 /* hw.psm.synaptics.directional_scrolls. */
4182 sc->syninfo.directional_scrolls = 0;
4183 SYSCTL_ADD_INT(&sc->syninfo.sysctl_ctx,
4184 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4185 "directional_scrolls", CTLFLAG_RW|CTLFLAG_ANYBODY,
4186 &sc->syninfo.directional_scrolls, 0,
4187 "Enable hardware scrolling pad (if non-zero) or register it as "
4188 "extended buttons (if 0)");
4191 * Turn off two finger scroll if we have a
4192 * physical area reserved for scrolling or when
4193 * there's no multi finger support.
4195 if (sc->synhw.verticalScroll || sc->synhw.capMultiFinger == 0)
4196 sc->syninfo.two_finger_scroll = 0;
4198 sc->syninfo.two_finger_scroll = 1;
4199 /* hw.psm.synaptics.two_finger_scroll. */
4200 SYSCTL_ADD_INT(&sc->syninfo.sysctl_ctx,
4201 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4202 "two_finger_scroll", CTLFLAG_RW|CTLFLAG_ANYBODY,
4203 &sc->syninfo.two_finger_scroll, 0,
4204 "Enable two finger scrolling");
4206 /* hw.psm.synaptics.min_pressure. */
4207 sc->syninfo.min_pressure = 16;
4208 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4209 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4210 "min_pressure", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4211 &sc->syninfo.min_pressure, SYNAPTICS_SYSCTL_MIN_PRESSURE,
4212 synaptics_sysctl, "I",
4213 "Minimum pressure required to start an action");
4215 /* hw.psm.synaptics.max_pressure. */
4216 sc->syninfo.max_pressure = 220;
4217 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4218 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4219 "max_pressure", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4220 &sc->syninfo.max_pressure, SYNAPTICS_SYSCTL_MAX_PRESSURE,
4221 synaptics_sysctl, "I",
4222 "Maximum pressure to detect palm");
4224 /* hw.psm.synaptics.max_width. */
4225 sc->syninfo.max_width = 10;
4226 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4227 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4228 "max_width", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4229 &sc->syninfo.max_width, SYNAPTICS_SYSCTL_MAX_WIDTH,
4230 synaptics_sysctl, "I",
4231 "Maximum finger width to detect palm");
4233 /* hw.psm.synaptics.top_margin. */
4234 sc->syninfo.margin_top = 200;
4235 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4236 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4237 "margin_top", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4238 &sc->syninfo.margin_top, SYNAPTICS_SYSCTL_MARGIN_TOP,
4239 synaptics_sysctl, "I",
4242 /* hw.psm.synaptics.right_margin. */
4243 sc->syninfo.margin_right = 200;
4244 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4245 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4246 "margin_right", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4247 &sc->syninfo.margin_right, SYNAPTICS_SYSCTL_MARGIN_RIGHT,
4248 synaptics_sysctl, "I",
4251 /* hw.psm.synaptics.bottom_margin. */
4252 sc->syninfo.margin_bottom = 200;
4253 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4254 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4255 "margin_bottom", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4256 &sc->syninfo.margin_bottom, SYNAPTICS_SYSCTL_MARGIN_BOTTOM,
4257 synaptics_sysctl, "I",
4260 /* hw.psm.synaptics.left_margin. */
4261 sc->syninfo.margin_left = 200;
4262 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4263 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4264 "margin_left", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4265 &sc->syninfo.margin_left, SYNAPTICS_SYSCTL_MARGIN_LEFT,
4266 synaptics_sysctl, "I",
4269 /* hw.psm.synaptics.na_top. */
4270 sc->syninfo.na_top = 1783;
4271 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4272 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4273 "na_top", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4274 &sc->syninfo.na_top, SYNAPTICS_SYSCTL_NA_TOP,
4275 synaptics_sysctl, "I",
4276 "Top noisy area, where weight_previous_na is used instead "
4277 "of weight_previous");
4279 /* hw.psm.synaptics.na_right. */
4280 sc->syninfo.na_right = 563;
4281 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4282 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4283 "na_right", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4284 &sc->syninfo.na_right, SYNAPTICS_SYSCTL_NA_RIGHT,
4285 synaptics_sysctl, "I",
4286 "Right noisy area, where weight_previous_na is used instead "
4287 "of weight_previous");
4289 /* hw.psm.synaptics.na_bottom. */
4290 sc->syninfo.na_bottom = 1408;
4291 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4292 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4293 "na_bottom", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4294 &sc->syninfo.na_bottom, SYNAPTICS_SYSCTL_NA_BOTTOM,
4295 synaptics_sysctl, "I",
4296 "Bottom noisy area, where weight_previous_na is used instead "
4297 "of weight_previous");
4299 /* hw.psm.synaptics.na_left. */
4300 sc->syninfo.na_left = 1600;
4301 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4302 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4303 "na_left", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4304 &sc->syninfo.na_left, SYNAPTICS_SYSCTL_NA_LEFT,
4305 synaptics_sysctl, "I",
4306 "Left noisy area, where weight_previous_na is used instead "
4307 "of weight_previous");
4309 /* hw.psm.synaptics.window_min. */
4310 sc->syninfo.window_min = 4;
4311 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4312 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4313 "window_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4314 &sc->syninfo.window_min, SYNAPTICS_SYSCTL_WINDOW_MIN,
4315 synaptics_sysctl, "I",
4316 "Minimum window size to start an action");
4318 /* hw.psm.synaptics.window_max. */
4319 sc->syninfo.window_max = 10;
4320 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4321 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4322 "window_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4323 &sc->syninfo.window_max, SYNAPTICS_SYSCTL_WINDOW_MAX,
4324 synaptics_sysctl, "I",
4325 "Maximum window size");
4327 /* hw.psm.synaptics.multiplicator. */
4328 sc->syninfo.multiplicator = 10000;
4329 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4330 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4331 "multiplicator", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4332 &sc->syninfo.multiplicator, SYNAPTICS_SYSCTL_MULTIPLICATOR,
4333 synaptics_sysctl, "I",
4334 "Multiplicator to increase precision in averages and divisions");
4336 /* hw.psm.synaptics.weight_current. */
4337 sc->syninfo.weight_current = 3;
4338 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4339 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4340 "weight_current", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4341 &sc->syninfo.weight_current, SYNAPTICS_SYSCTL_WEIGHT_CURRENT,
4342 synaptics_sysctl, "I",
4343 "Weight of the current movement in the new average");
4345 /* hw.psm.synaptics.weight_previous. */
4346 sc->syninfo.weight_previous = 6;
4347 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4348 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4349 "weight_previous", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4350 &sc->syninfo.weight_previous, SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS,
4351 synaptics_sysctl, "I",
4352 "Weight of the previous average");
4354 /* hw.psm.synaptics.weight_previous_na. */
4355 sc->syninfo.weight_previous_na = 20;
4356 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4357 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4358 "weight_previous_na", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4359 &sc->syninfo.weight_previous_na,
4360 SYNAPTICS_SYSCTL_WEIGHT_PREVIOUS_NA,
4361 synaptics_sysctl, "I",
4362 "Weight of the previous average (inside the noisy area)");
4364 /* hw.psm.synaptics.weight_len_squared. */
4365 sc->syninfo.weight_len_squared = 2000;
4366 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4367 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4368 "weight_len_squared", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4369 &sc->syninfo.weight_len_squared,
4370 SYNAPTICS_SYSCTL_WEIGHT_LEN_SQUARED,
4371 synaptics_sysctl, "I",
4372 "Length (squared) of segments where weight_previous "
4373 "starts to decrease");
4375 /* hw.psm.synaptics.div_min. */
4376 sc->syninfo.div_min = 9;
4377 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4378 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4379 "div_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4380 &sc->syninfo.div_min, SYNAPTICS_SYSCTL_DIV_MIN,
4381 synaptics_sysctl, "I",
4382 "Divisor for fast movements");
4384 /* hw.psm.synaptics.div_max. */
4385 sc->syninfo.div_max = 17;
4386 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4387 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4388 "div_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4389 &sc->syninfo.div_max, SYNAPTICS_SYSCTL_DIV_MAX,
4390 synaptics_sysctl, "I",
4391 "Divisor for slow movements");
4393 /* hw.psm.synaptics.div_max_na. */
4394 sc->syninfo.div_max_na = 30;
4395 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4396 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4397 "div_max_na", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4398 &sc->syninfo.div_max_na, SYNAPTICS_SYSCTL_DIV_MAX_NA,
4399 synaptics_sysctl, "I",
4400 "Divisor with slow movements (inside the noisy area)");
4402 /* hw.psm.synaptics.div_len. */
4403 sc->syninfo.div_len = 100;
4404 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4405 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4406 "div_len", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4407 &sc->syninfo.div_len, SYNAPTICS_SYSCTL_DIV_LEN,
4408 synaptics_sysctl, "I",
4409 "Length of segments where div_max starts to decrease");
4411 /* hw.psm.synaptics.tap_max_delta. */
4412 sc->syninfo.tap_max_delta = 80;
4413 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4414 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4415 "tap_max_delta", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4416 &sc->syninfo.tap_max_delta, SYNAPTICS_SYSCTL_TAP_MAX_DELTA,
4417 synaptics_sysctl, "I",
4418 "Length of segments above which a tap is ignored");
4420 /* hw.psm.synaptics.tap_min_queue. */
4421 sc->syninfo.tap_min_queue = 2;
4422 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4423 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4424 "tap_min_queue", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4425 &sc->syninfo.tap_min_queue, SYNAPTICS_SYSCTL_TAP_MIN_QUEUE,
4426 synaptics_sysctl, "I",
4427 "Number of packets required to consider a tap");
4429 /* hw.psm.synaptics.taphold_timeout. */
4430 sc->synaction.in_taphold = 0;
4431 sc->syninfo.taphold_timeout = tap_timeout;
4432 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4433 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4434 "taphold_timeout", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4435 &sc->syninfo.taphold_timeout, SYNAPTICS_SYSCTL_TAPHOLD_TIMEOUT,
4436 synaptics_sysctl, "I",
4437 "Maximum elapsed time between two taps to consider a tap-hold "
4440 /* hw.psm.synaptics.vscroll_hor_area. */
4441 sc->syninfo.vscroll_hor_area = 0; /* 1300 */
4442 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4443 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4444 "vscroll_hor_area", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4445 &sc->syninfo.vscroll_hor_area, SYNAPTICS_SYSCTL_VSCROLL_HOR_AREA,
4446 synaptics_sysctl, "I",
4447 "Area reserved for horizontal virtual scrolling");
4449 /* hw.psm.synaptics.vscroll_ver_area. */
4450 sc->syninfo.vscroll_ver_area = -600;
4451 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4452 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4453 "vscroll_ver_area", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4454 &sc->syninfo.vscroll_ver_area, SYNAPTICS_SYSCTL_VSCROLL_VER_AREA,
4455 synaptics_sysctl, "I",
4456 "Area reserved for vertical virtual scrolling");
4458 /* hw.psm.synaptics.vscroll_min_delta. */
4459 sc->syninfo.vscroll_min_delta = 50;
4460 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4461 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4462 "vscroll_min_delta", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4463 &sc->syninfo.vscroll_min_delta,
4464 SYNAPTICS_SYSCTL_VSCROLL_MIN_DELTA,
4465 synaptics_sysctl, "I",
4466 "Minimum movement to consider virtual scrolling");
4468 /* hw.psm.synaptics.vscroll_div_min. */
4469 sc->syninfo.vscroll_div_min = 100;
4470 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4471 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4472 "vscroll_div_min", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4473 &sc->syninfo.vscroll_div_min, SYNAPTICS_SYSCTL_VSCROLL_DIV_MIN,
4474 synaptics_sysctl, "I",
4475 "Divisor for fast scrolling");
4477 /* hw.psm.synaptics.vscroll_div_min. */
4478 sc->syninfo.vscroll_div_max = 150;
4479 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4480 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4481 "vscroll_div_max", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4482 &sc->syninfo.vscroll_div_max, SYNAPTICS_SYSCTL_VSCROLL_DIV_MAX,
4483 synaptics_sysctl, "I",
4484 "Divisor for slow scrolling");
4486 /* hw.psm.synaptics.touchpad_off. */
4487 sc->syninfo.touchpad_off = 0;
4488 SYSCTL_ADD_PROC(&sc->syninfo.sysctl_ctx,
4489 SYSCTL_CHILDREN(sc->syninfo.sysctl_tree), OID_AUTO,
4490 "touchpad_off", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4491 &sc->syninfo.touchpad_off, SYNAPTICS_SYSCTL_TOUCHPAD_OFF,
4492 synaptics_sysctl, "I",
4493 "Turn off touchpad");
4497 enable_synaptics(KBDC kbdc, struct psm_softc *sc)
4499 synapticshw_t synhw;
4503 VLOG(3, (LOG_DEBUG, "synaptics: BEGIN init\n"));
4506 * Just to be on the safe side: this avoids troubles with
4507 * following mouse_ext_command() when the previous command
4508 * was PSMC_SET_RESOLUTION. Set Scaling has no effect on
4509 * Synaptics Touchpad behaviour.
4511 set_mouse_scaling(kbdc, 1);
4513 /* Identify the Touchpad version. */
4514 if (mouse_ext_command(kbdc, 0) == 0)
4516 if (get_mouse_status(kbdc, status, 0, 3) != 3)
4518 if (status[1] != 0x47)
4521 bzero(&synhw, sizeof(synhw));
4522 synhw.infoMinor = status[0];
4523 synhw.infoMajor = status[2] & 0x0f;
4526 printf("Synaptics Touchpad v%d.%d\n", synhw.infoMajor,
4529 if (synhw.infoMajor < 4) {
4530 printf(" Unsupported (pre-v4) Touchpad detected\n");
4534 /* Get the Touchpad model information. */
4535 if (mouse_ext_command(kbdc, 3) == 0)
4537 if (get_mouse_status(kbdc, status, 0, 3) != 3)
4539 if ((status[1] & 0x01) != 0) {
4540 printf(" Failed to read model information\n");
4544 synhw.infoRot180 = (status[0] & 0x80) != 0;
4545 synhw.infoPortrait = (status[0] & 0x40) != 0;
4546 synhw.infoSensor = status[0] & 0x3f;
4547 synhw.infoHardware = (status[1] & 0xfe) >> 1;
4548 synhw.infoNewAbs = (status[2] & 0x80) != 0;
4549 synhw.capPen = (status[2] & 0x40) != 0;
4550 synhw.infoSimplC = (status[2] & 0x20) != 0;
4551 synhw.infoGeometry = status[2] & 0x0f;
4554 printf(" Model information:\n");
4555 printf(" infoRot180: %d\n", synhw.infoRot180);
4556 printf(" infoPortrait: %d\n", synhw.infoPortrait);
4557 printf(" infoSensor: %d\n", synhw.infoSensor);
4558 printf(" infoHardware: %d\n", synhw.infoHardware);
4559 printf(" infoNewAbs: %d\n", synhw.infoNewAbs);
4560 printf(" capPen: %d\n", synhw.capPen);
4561 printf(" infoSimplC: %d\n", synhw.infoSimplC);
4562 printf(" infoGeometry: %d\n", synhw.infoGeometry);
4565 /* Read the extended capability bits. */
4566 if (mouse_ext_command(kbdc, 2) == 0)
4568 if (get_mouse_status(kbdc, status, 0, 3) != 3)
4570 if (!SYNAPTICS_VERSION_GE(synhw, 7, 5) && status[1] != 0x47) {
4571 printf(" Failed to read extended capability bits\n");
4575 /* Set the different capabilities when they exist. */
4577 synhw.capExtended = (status[0] & 0x80) != 0;
4578 if (synhw.capExtended) {
4579 synhw.nExtendedQueries = (status[0] & 0x70) != 0;
4580 synhw.capMiddle = (status[0] & 0x04) != 0;
4581 synhw.capPassthrough = (status[2] & 0x80) != 0;
4582 synhw.capLowPower = (status[2] & 0x40) != 0;
4583 synhw.capMultiFingerReport =
4584 (status[2] & 0x20) != 0;
4585 synhw.capSleep = (status[2] & 0x10) != 0;
4586 synhw.capFourButtons = (status[2] & 0x08) != 0;
4587 synhw.capBallistics = (status[2] & 0x04) != 0;
4588 synhw.capMultiFinger = (status[2] & 0x02) != 0;
4589 synhw.capPalmDetect = (status[2] & 0x01) != 0;
4592 printf(" Extended capabilities:\n");
4593 printf(" capExtended: %d\n", synhw.capExtended);
4594 printf(" capMiddle: %d\n", synhw.capMiddle);
4595 printf(" nExtendedQueries: %d\n",
4596 synhw.nExtendedQueries);
4597 printf(" capPassthrough: %d\n", synhw.capPassthrough);
4598 printf(" capLowPower: %d\n", synhw.capLowPower);
4599 printf(" capMultiFingerReport: %d\n",
4600 synhw.capMultiFingerReport);
4601 printf(" capSleep: %d\n", synhw.capSleep);
4602 printf(" capFourButtons: %d\n", synhw.capFourButtons);
4603 printf(" capBallistics: %d\n", synhw.capBallistics);
4604 printf(" capMultiFinger: %d\n", synhw.capMultiFinger);
4605 printf(" capPalmDetect: %d\n", synhw.capPalmDetect);
4609 * If nExtendedQueries is 1 or greater, then the TouchPad
4610 * supports this number of extended queries. We can load
4611 * more information about buttons using query 0x09.
4613 if (synhw.capExtended && synhw.nExtendedQueries) {
4614 if (mouse_ext_command(kbdc, 0x09) == 0)
4616 if (get_mouse_status(kbdc, status, 0, 3) != 3)
4618 synhw.verticalScroll = (status[0] & 0x01) != 0;
4619 synhw.horizontalScroll = (status[0] & 0x02) != 0;
4620 synhw.verticalWheel = (status[0] & 0x08) != 0;
4621 synhw.nExtendedButtons = (status[1] & 0xf0) >> 4;
4623 printf(" Extended model ID:\n");
4624 printf(" verticalScroll: %d\n",
4625 synhw.verticalScroll);
4626 printf(" horizontalScroll: %d\n",
4627 synhw.horizontalScroll);
4628 printf(" verticalWheel: %d\n",
4629 synhw.verticalWheel);
4630 printf(" nExtendedButtons: %d\n",
4631 synhw.nExtendedButtons);
4634 * Add the number of extended buttons to the total
4635 * button support count, including the middle button
4636 * if capMiddle support bit is set.
4638 buttons = synhw.nExtendedButtons + synhw.capMiddle;
4641 * If the capFourButtons support bit is set,
4642 * add a fourth button to the total button count.
4644 buttons = synhw.capFourButtons ? 1 : 0;
4647 if (synhw.capExtended)
4648 printf(" Additional Buttons: %d\n", buttons);
4650 printf(" No extended capabilities\n");
4653 /* Read the continued capabilities bits. */
4654 if (mouse_ext_command(kbdc, 0xc) != 0 &&
4655 get_mouse_status(kbdc, status, 0, 3) == 3) {
4656 synhw.capClickPad = (status[1] & 0x01) << 1;
4657 synhw.capClickPad |= (status[0] & 0x10) != 0;
4658 synhw.capDeluxeLEDs = (status[1] & 0x02) != 0;
4659 synhw.noAbsoluteFilter = (status[1] & 0x04) != 0;
4660 synhw.capReportsV = (status[1] & 0x08) != 0;
4661 synhw.capUniformClickPad = (status[1] & 0x10) != 0;
4662 synhw.capReportsMin = (status[1] & 0x20) != 0;
4663 synhw.capInterTouch = (status[1] & 0x40) != 0;
4664 synhw.capReportsMax = (status[2] & 0x02) != 0;
4665 synhw.capClearPad = (status[2] & 0x04) != 0;
4666 synhw.capAdvancedGestures = (status[2] & 0x08) != 0;
4667 synhw.capCoveredPad = (status[2] & 0x80) != 0;
4670 printf(" Continued capabilities:\n");
4671 printf(" capClickPad: %d\n", synhw.capClickPad);
4672 printf(" capDeluxeLEDs: %d\n", synhw.capDeluxeLEDs);
4673 printf(" noAbsoluteFilter: %d\n",
4674 synhw.noAbsoluteFilter);
4675 printf(" capReportsV: %d\n", synhw.capReportsV);
4676 printf(" capUniformClickPad: %d\n",
4677 synhw.capUniformClickPad);
4678 printf(" capReportsMin: %d\n", synhw.capReportsMin);
4679 printf(" capInterTouch: %d\n", synhw.capInterTouch);
4680 printf(" capReportsMax: %d\n", synhw.capReportsMax);
4681 printf(" capClearPad: %d\n", synhw.capClearPad);
4682 printf(" capAdvancedGestures: %d\n",
4683 synhw.capAdvancedGestures);
4684 printf(" capCoveredPad: %d\n", synhw.capCoveredPad);
4686 buttons += synhw.capClickPad;
4690 * Add the default number of 3 buttons to the total
4691 * count of supported buttons reported above.
4696 * Read the mode byte.
4698 * XXX: Note the Synaptics documentation also defines the first
4699 * byte of the response to this query to be a constant 0x3b, this
4700 * does not appear to be true for Touchpads with guest devices.
4702 if (mouse_ext_command(kbdc, 1) == 0)
4704 if (get_mouse_status(kbdc, status, 0, 3) != 3)
4706 if (!SYNAPTICS_VERSION_GE(synhw, 7, 5) && status[1] != 0x47) {
4707 printf(" Failed to read mode byte\n");
4713 if (!synaptics_support)
4716 /* Set the mode byte; request wmode where available. */
4717 mouse_ext_command(kbdc, synhw.capExtended ? 0xc1 : 0xc0);
4719 /* "Commit" the Set Mode Byte command sent above. */
4720 set_mouse_sampling_rate(kbdc, 20);
4722 VLOG(3, (LOG_DEBUG, "synaptics: END init (%d buttons)\n", buttons));
4725 if (trackpoint_support && synhw.capPassthrough) {
4726 synaptics_passthrough_on(sc);
4727 enable_trackpoint(kbdc, sc);
4728 synaptics_passthrough_off(sc);
4730 /* Create sysctl tree. */
4731 synaptics_sysctl_create_tree(sc);
4732 sc->hw.buttons = buttons;
4739 synaptics_passthrough_on(struct psm_softc *sc)
4743 mode_byte = 0xc1 | (1 << 5);
4744 VLOG(2, (LOG_NOTICE, "psm: setting pass-through mode. %d\n",
4746 mouse_ext_command(sc->kbdc, mode_byte);
4748 /* "Commit" the Set Mode Byte command sent above. */
4749 set_mouse_sampling_rate(sc->kbdc, 20);
4753 synaptics_passthrough_off(struct psm_softc *sc)
4758 VLOG(2, (LOG_NOTICE, "psm: turning pass-through mode off.\n"));
4759 set_mouse_scaling(sc->kbdc, 2);
4760 set_mouse_scaling(sc->kbdc, 1);
4761 mouse_ext_command(sc->kbdc, mode_byte);
4763 /* "Commit" the Set Mode Byte command sent above. */
4764 set_mouse_sampling_rate(sc->kbdc, 20);
4767 /* IBM/Lenovo TrackPoint */
4769 trackpoint_command(struct psm_softc *sc, int cmd, int loc, int val)
4771 const int seq[] = { 0xe2, cmd, loc, val };
4774 if (sc->synhw.capPassthrough)
4775 synaptics_passthrough_on(sc);
4777 for (i = 0; i < nitems(seq); i++) {
4778 if (sc->synhw.capPassthrough &&
4779 (seq[i] == 0xff || seq[i] == 0xe7))
4780 if (send_aux_command(sc->kbdc, 0xe7) != PSM_ACK) {
4781 synaptics_passthrough_off(sc);
4784 if (send_aux_command(sc->kbdc, seq[i]) != PSM_ACK) {
4785 if (sc->synhw.capPassthrough)
4786 synaptics_passthrough_off(sc);
4791 if (sc->synhw.capPassthrough)
4792 synaptics_passthrough_off(sc);
4797 #define PSM_TPINFO(x) offsetof(struct psm_softc, tpinfo.x)
4803 trackpoint_sysctl(SYSCTL_HANDLER_ARGS)
4805 static const int data[][3] = {
4806 { 0x00, 0x4a, PSM_TPINFO(sensitivity) },
4807 { 0x00, 0x4d, PSM_TPINFO(inertia) },
4808 { 0x00, 0x60, PSM_TPINFO(uplateau) },
4809 { 0x00, 0x57, PSM_TPINFO(reach) },
4810 { 0x00, 0x58, PSM_TPINFO(draghys) },
4811 { 0x00, 0x59, PSM_TPINFO(mindrag) },
4812 { 0x00, 0x5a, PSM_TPINFO(upthresh) },
4813 { 0x00, 0x5c, PSM_TPINFO(threshold) },
4814 { 0x00, 0x5d, PSM_TPINFO(jenks) },
4815 { 0x00, 0x5e, PSM_TPINFO(ztime) },
4816 { 0x01, 0x2c, PSM_TPINFO(pts) },
4817 { 0x08, 0x2d, PSM_TPINFO(skipback) }
4819 struct psm_softc *sc;
4820 int error, newval, *oldvalp;
4823 if (arg1 == NULL || arg2 < 0 || arg2 >= nitems(data))
4827 oldvalp = (int *)((intptr_t)sc + tp[TPINFO]);
4829 error = sysctl_handle_int(oidp, &newval, 0, req);
4832 if (newval == *oldvalp)
4834 if (newval < 0 || newval > (tp[TPMASK] == 0 ? 255 : 1))
4836 error = trackpoint_command(sc, tp[TPMASK] == 0 ? 0x81 : 0x47,
4837 tp[TPLOC], tp[TPMASK] == 0 ? newval : tp[TPMASK]);
4846 trackpoint_sysctl_create_tree(struct psm_softc *sc)
4849 if (sc->tpinfo.sysctl_tree != NULL)
4852 /* Attach extra trackpoint sysctl nodes under hw.psm.trackpoint */
4853 sysctl_ctx_init(&sc->tpinfo.sysctl_ctx);
4854 sc->tpinfo.sysctl_tree = SYSCTL_ADD_NODE(&sc->tpinfo.sysctl_ctx,
4855 SYSCTL_STATIC_CHILDREN(_hw_psm), OID_AUTO, "trackpoint", CTLFLAG_RD,
4856 0, "IBM/Lenovo TrackPoint");
4858 /* hw.psm.trackpoint.sensitivity */
4859 sc->tpinfo.sensitivity = 0x80;
4860 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4861 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4862 "sensitivity", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4863 sc, TRACKPOINT_SYSCTL_SENSITIVITY,
4864 trackpoint_sysctl, "I",
4867 /* hw.psm.trackpoint.negative_inertia */
4868 sc->tpinfo.inertia = 0x06;
4869 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4870 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4871 "negative_inertia", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4872 sc, TRACKPOINT_SYSCTL_NEGATIVE_INERTIA,
4873 trackpoint_sysctl, "I",
4874 "Negative inertia factor");
4876 /* hw.psm.trackpoint.upper_plateau */
4877 sc->tpinfo.uplateau = 0x61;
4878 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4879 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4880 "upper_plateau", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4881 sc, TRACKPOINT_SYSCTL_UPPER_PLATEAU,
4882 trackpoint_sysctl, "I",
4883 "Transfer function upper plateau speed");
4885 /* hw.psm.trackpoint.backup_range */
4886 sc->tpinfo.reach = 0x0a;
4887 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4888 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4889 "backup_range", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4890 sc, TRACKPOINT_SYSCTL_BACKUP_RANGE,
4891 trackpoint_sysctl, "I",
4894 /* hw.psm.trackpoint.drag_hysteresis */
4895 sc->tpinfo.draghys = 0xff;
4896 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4897 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4898 "drag_hysteresis", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4899 sc, TRACKPOINT_SYSCTL_DRAG_HYSTERESIS,
4900 trackpoint_sysctl, "I",
4903 /* hw.psm.trackpoint.minimum_drag */
4904 sc->tpinfo.mindrag = 0x14;
4905 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4906 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4907 "minimum_drag", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4908 sc, TRACKPOINT_SYSCTL_MINIMUM_DRAG,
4909 trackpoint_sysctl, "I",
4912 /* hw.psm.trackpoint.up_threshold */
4913 sc->tpinfo.upthresh = 0xff;
4914 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4915 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4916 "up_threshold", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4917 sc, TRACKPOINT_SYSCTL_UP_THRESHOLD,
4918 trackpoint_sysctl, "I",
4919 "Up threshold for release");
4921 /* hw.psm.trackpoint.threshold */
4922 sc->tpinfo.threshold = 0x08;
4923 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4924 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4925 "threshold", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4926 sc, TRACKPOINT_SYSCTL_THRESHOLD,
4927 trackpoint_sysctl, "I",
4930 /* hw.psm.trackpoint.jenks_curvature */
4931 sc->tpinfo.jenks = 0x87;
4932 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4933 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4934 "jenks_curvature", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4935 sc, TRACKPOINT_SYSCTL_JENKS_CURVATURE,
4936 trackpoint_sysctl, "I",
4939 /* hw.psm.trackpoint.z_time */
4940 sc->tpinfo.ztime = 0x26;
4941 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4942 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4943 "z_time", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4944 sc, TRACKPOINT_SYSCTL_Z_TIME,
4945 trackpoint_sysctl, "I",
4948 /* hw.psm.trackpoint.press_to_select */
4949 sc->tpinfo.pts = 0x00;
4950 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4951 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4952 "press_to_select", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4953 sc, TRACKPOINT_SYSCTL_PRESS_TO_SELECT,
4954 trackpoint_sysctl, "I",
4957 /* hw.psm.trackpoint.skip_backups */
4958 sc->tpinfo.skipback = 0x00;
4959 SYSCTL_ADD_PROC(&sc->tpinfo.sysctl_ctx,
4960 SYSCTL_CHILDREN(sc->tpinfo.sysctl_tree), OID_AUTO,
4961 "skip_backups", CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY,
4962 sc, TRACKPOINT_SYSCTL_SKIP_BACKUPS,
4963 trackpoint_sysctl, "I",
4964 "Skip backups from drags");
4968 set_trackpoint_parameters(struct psm_softc *sc)
4970 trackpoint_command(sc, 0x81, 0x4a, sc->tpinfo.sensitivity);
4971 trackpoint_command(sc, 0x81, 0x60, sc->tpinfo.uplateau);
4972 trackpoint_command(sc, 0x81, 0x4d, sc->tpinfo.inertia);
4973 trackpoint_command(sc, 0x81, 0x57, sc->tpinfo.reach);
4974 trackpoint_command(sc, 0x81, 0x58, sc->tpinfo.draghys);
4975 trackpoint_command(sc, 0x81, 0x59, sc->tpinfo.mindrag);
4976 trackpoint_command(sc, 0x81, 0x5a, sc->tpinfo.upthresh);
4977 trackpoint_command(sc, 0x81, 0x5c, sc->tpinfo.threshold);
4978 trackpoint_command(sc, 0x81, 0x5d, sc->tpinfo.jenks);
4979 trackpoint_command(sc, 0x81, 0x5e, sc->tpinfo.ztime);
4980 if (sc->tpinfo.pts == 0x01)
4981 trackpoint_command(sc, 0x47, 0x2c, 0x01);
4982 if (sc->tpinfo.skipback == 0x01)
4983 trackpoint_command(sc, 0x47, 0x2d, 0x08);
4987 enable_trackpoint(KBDC kbdc, struct psm_softc *sc)
4991 if (send_aux_command(kbdc, 0xe1) != PSM_ACK ||
4992 read_aux_data(kbdc) != 0x01)
4994 id = read_aux_data(kbdc);
4999 if (!trackpoint_support)
5003 /* Create sysctl tree. */
5004 trackpoint_sysctl_create_tree(sc);
5007 * Don't overwrite hwid and buttons when we are
5010 if (!sc->synhw.capPassthrough) {
5019 /* Interlink electronics VersaPad */
5021 enable_versapad(KBDC kbdc, struct psm_softc *sc)
5025 set_mouse_resolution(kbdc, PSMD_RES_MEDIUM_HIGH); /* set res. 2 */
5026 set_mouse_sampling_rate(kbdc, 100); /* set rate 100 */
5027 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
5028 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
5029 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
5030 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
5031 if (get_mouse_status(kbdc, data, 0, 3) < 3) /* get status */
5033 if (data[2] != 0xa || data[1] != 0 ) /* rate == 0xa && res. == 0 */
5035 set_mouse_scaling(kbdc, 1); /* set scale 1:1 */
5037 return (TRUE); /* PS/2 absolute mode */
5041 * Return true if 'now' is earlier than (start + (secs.usecs)).
5042 * Now may be NULL and the function will fetch the current time from
5043 * getmicrouptime(), or a cached 'now' can be passed in.
5044 * All values should be numbers derived from getmicrouptime().
5047 timeelapsed(start, secs, usecs, now)
5048 const struct timeval *start, *now;
5051 struct timeval snow, tv;
5053 /* if there is no 'now' passed in, the get it as a convience. */
5055 getmicrouptime(&snow);
5061 timevaladd(&tv, start);
5062 return (timevalcmp(&tv, now, <));
5066 psmresume(device_t dev)
5068 struct psm_softc *sc = device_get_softc(dev);
5069 int unit = device_get_unit(dev);
5072 VLOG(2, (LOG_NOTICE, "psm%d: system resume hook called.\n", unit));
5075 (PSM_CONFIG_HOOKRESUME | PSM_CONFIG_INITAFTERSUSPEND)) == 0)
5078 err = reinitialize(sc, sc->config & PSM_CONFIG_INITAFTERSUSPEND);
5080 if ((sc->state & PSM_ASLP) && !(sc->state & PSM_VALID)) {
5082 * Release the blocked process; it must be notified that
5083 * the device cannot be accessed anymore.
5085 sc->state &= ~PSM_ASLP;
5089 VLOG(2, (LOG_DEBUG, "psm%d: system resume hook exiting.\n", unit));
5094 DRIVER_MODULE(psm, atkbdc, psm_driver, psm_devclass, 0, 0);
5099 * This sucks up assignments from PNPBIOS and ACPI.
5103 * When the PS/2 mouse device is reported by ACPI or PnP BIOS, it may
5104 * appear BEFORE the AT keyboard controller. As the PS/2 mouse device
5105 * can be probed and attached only after the AT keyboard controller is
5106 * attached, we shall quietly reserve the IRQ resource for later use.
5107 * If the PS/2 mouse device is reported to us AFTER the keyboard controller,
5108 * copy the IRQ resource to the PS/2 mouse device instance hanging
5109 * under the keyboard controller, then probe and attach it.
5112 static devclass_t psmcpnp_devclass;
5114 static device_probe_t psmcpnp_probe;
5115 static device_attach_t psmcpnp_attach;
5117 static device_method_t psmcpnp_methods[] = {
5118 DEVMETHOD(device_probe, psmcpnp_probe),
5119 DEVMETHOD(device_attach, psmcpnp_attach),
5124 static driver_t psmcpnp_driver = {
5125 PSMCPNP_DRIVER_NAME,
5130 static struct isa_pnp_id psmcpnp_ids[] = {
5131 { 0x030fd041, "PS/2 mouse port" }, /* PNP0F03 */
5132 { 0x0e0fd041, "PS/2 mouse port" }, /* PNP0F0E */
5133 { 0x120fd041, "PS/2 mouse port" }, /* PNP0F12 */
5134 { 0x130fd041, "PS/2 mouse port" }, /* PNP0F13 */
5135 { 0x1303d041, "PS/2 port" }, /* PNP0313, XXX */
5136 { 0x02002e4f, "Dell PS/2 mouse port" }, /* Lat. X200, Dell */
5137 { 0x0002a906, "ALPS Glide Point" }, /* ALPS Glide Point */
5138 { 0x80374d24, "IBM PS/2 mouse port" }, /* IBM3780, ThinkPad */
5139 { 0x81374d24, "IBM PS/2 mouse port" }, /* IBM3781, ThinkPad */
5140 { 0x0190d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9001, Vaio */
5141 { 0x0290d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9002, Vaio */
5142 { 0x0390d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9003, Vaio */
5143 { 0x0490d94d, "SONY VAIO PS/2 mouse port"}, /* SNY9004, Vaio */
5148 create_a_copy(device_t atkbdc, device_t me)
5153 /* find the PS/2 mouse device instance under the keyboard controller */
5154 psm = device_find_child(atkbdc, PSM_DRIVER_NAME,
5155 device_get_unit(atkbdc));
5158 if (device_get_state(psm) != DS_NOTPRESENT)
5161 /* move our resource to the found device */
5162 irq = bus_get_resource_start(me, SYS_RES_IRQ, 0);
5163 bus_delete_resource(me, SYS_RES_IRQ, 0);
5164 bus_set_resource(psm, SYS_RES_IRQ, KBDC_RID_AUX, irq, 1);
5166 /* ...then probe and attach it */
5167 return (device_probe_and_attach(psm));
5171 psmcpnp_probe(device_t dev)
5173 struct resource *res;
5177 if (ISA_PNP_PROBE(device_get_parent(dev), dev, psmcpnp_ids))
5181 * The PnP BIOS and ACPI are supposed to assign an IRQ (12)
5182 * to the PS/2 mouse device node. But, some buggy PnP BIOS
5183 * declares the PS/2 mouse device node without an IRQ resource!
5184 * If this happens, we shall refer to device hints.
5185 * If we still don't find it there, use a hardcoded value... XXX
5188 irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid);
5190 if (resource_long_value(PSM_DRIVER_NAME,
5191 device_get_unit(dev),"irq", &irq) != 0)
5193 device_printf(dev, "irq resource info is missing; "
5194 "assuming irq %ld\n", irq);
5195 bus_set_resource(dev, SYS_RES_IRQ, rid, irq, 1);
5197 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 0);
5198 bus_release_resource(dev, SYS_RES_IRQ, rid, res);
5204 return ((res == NULL) ? ENXIO : 0);
5208 psmcpnp_attach(device_t dev)
5212 /* find the keyboard controller, which may be on acpi* or isa* bus */
5213 atkbdc = devclass_get_device(devclass_find(ATKBDC_DRIVER_NAME),
5214 device_get_unit(dev));
5215 if ((atkbdc != NULL) && (device_get_state(atkbdc) == DS_ATTACHED))
5216 create_a_copy(atkbdc, dev);
5221 DRIVER_MODULE(psmcpnp, isa, psmcpnp_driver, psmcpnp_devclass, 0, 0);
5222 DRIVER_MODULE(psmcpnp, acpi, psmcpnp_driver, psmcpnp_devclass, 0, 0);
5224 #endif /* DEV_ISA */