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.
23 * $FreeBSD: src/sys/isa/psm.c,v 1.23.2.7 2003/11/12 04:26:26 mikeh Exp $
24 * $DragonFly: src/sys/dev/misc/psm/psm.c,v 1.25 2007/06/13 17:15:25 dillon Exp $
28 * Ported to 386bsd Oct 17, 1992
29 * Sandi Donno, Computer Science, University of Cape Town, South Africa
30 * Please send bug reports to sandi@cs.uct.ac.za
32 * Thanks are also due to Rick Macklem, rick@snowhite.cis.uoguelph.ca -
33 * although I was only partially successful in getting the alpha release
34 * of his "driver for the Logitech and ATI Inport Bus mice for use with
35 * 386bsd and the X386 port" to work with my Microsoft mouse, I nevertheless
36 * found his code to be an invaluable reference when porting this driver
39 * Further modifications for latest 386BSD+patchkit and port to NetBSD,
40 * Andrew Herbert <andrew@werple.apana.org.au> - 8 June 1993
42 * Cloned from the Microsoft Bus Mouse driver, also by Erik Forsberg, by
43 * Andrew Herbert - 12 June 1993
45 * Modified for PS/2 mouse by Charles Hannum <mycroft@ai.mit.edu>
48 * Modified for PS/2 AUX mouse by Shoji Yuen <yuen@nuie.nagoya-u.ac.jp>
51 * Hardware access routines and probe logic rewritten by
52 * Kazutaka Yokota <yokota@zodiac.mech.utsunomiya-u.ac.jp>
53 * - 3, 14, 22 October 1996.
54 * - 12 November 1996. IOCTLs and rearranging `psmread', `psmioctl'...
55 * - 14, 30 November 1996. Uses `kbdio.c'.
56 * - 13 December 1996. Uses queuing version of `kbdio.c'.
57 * - January/February 1997. Tweaked probe logic for
58 * HiNote UltraII/Latitude/Armada laptops.
59 * - 30 July 1997. Added APM support.
60 * - 5 March 1997. Defined driver configuration flags (PSM_CONFIG_XXX).
61 * Improved sync check logic.
62 * Vendor specific support routines.
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/kernel.h>
70 #include <sys/module.h>
73 #include <sys/device.h>
75 #include <sys/syslog.h>
76 #include <sys/malloc.h>
78 #include <sys/selinfo.h>
79 #include <sys/thread2.h>
83 #include <machine/clock.h>
84 #include <machine/limits.h>
85 #include <machine/mouse.h>
87 #include <bus/isa/isavar.h>
88 #include <dev/misc/kbd/atkbdcreg.h>
91 * Driver specific options: the following options may be set by
92 * `options' statements in the kernel configuration file.
97 #define PSM_DEBUG 0 /* logging: 0: none, 1: brief, 2: verbose */
100 #ifndef PSM_SYNCERR_THRESHOLD1
101 #define PSM_SYNCERR_THRESHOLD1 20
104 #ifndef PSM_INPUT_TIMEOUT
105 #define PSM_INPUT_TIMEOUT 2000000 /* 2 sec */
108 /* end of driver specific options */
110 #define PSM_DRIVER_NAME "psm"
111 #define PSMCPNP_DRIVER_NAME "psmcpnp"
114 #define PSM_BUFSIZE 960
115 #define PSM_SMALLBUFSIZE 240
117 /* operation levels */
118 #define PSM_LEVEL_BASE 0
119 #define PSM_LEVEL_STANDARD 1
120 #define PSM_LEVEL_NATIVE 2
121 #define PSM_LEVEL_MIN PSM_LEVEL_BASE
122 #define PSM_LEVEL_MAX PSM_LEVEL_NATIVE
124 /* Logitech PS2++ protocol */
125 #define MOUSE_PS2PLUS_CHECKBITS(b) \
126 ((((b[2] & 0x03) << 2) | 0x02) == (b[1] & 0x0f))
127 #define MOUSE_PS2PLUS_PACKET_TYPE(b) \
128 (((b[0] & 0x30) >> 2) | ((b[1] & 0x30) >> 4))
131 #define PSM_UNIT(dev) (minor(dev) >> 1)
132 #define PSM_NBLOCKIO(dev) (minor(dev) & 1)
133 #define PSM_MKMINOR(unit,block) ((((unit) & 0xff) << 1) | ((block) ? 0:1))
136 #define max(x,y) ((x) > (y) ? (x) : (y))
139 #define min(x,y) ((x) < (y) ? (x) : (y))
142 #define abs(x) (((x) < 0) ? -(x) : (x))
145 typedef struct ringbuf
{
146 int count
; /* # of valid elements in the buffer */
147 int head
; /* head pointer */
148 int tail
; /* tail poiner */
149 unsigned char buf
[PSM_BUFSIZE
];
152 /* driver control block */
153 struct psm_softc
{ /* Driver status information */
155 struct selinfo rsel
; /* Process selecting for Input */
156 unsigned char state
; /* Mouse driver state */
157 int config
; /* driver configuration flags */
158 int flags
; /* other flags */
159 KBDC kbdc
; /* handle to access the keyboard controller */
160 struct resource
*intr
; /* IRQ resource */
161 void *ih
; /* interrupt handle */
162 mousehw_t hw
; /* hardware information */
163 mousemode_t mode
; /* operation mode */
164 mousemode_t dflt_mode
; /* default operation mode */
165 mousestatus_t status
; /* accumulated mouse movement */
166 ringbuf_t queue
; /* mouse status queue */
167 unsigned char ipacket
[16]; /* interim input buffer */
168 int inputbytes
; /* # of bytes in the input buffer */
169 int button
; /* the latest button state */
170 int xold
; /* previous absolute X position */
171 int yold
; /* previous absolute Y position */
173 struct timeval inputtimeout
;
174 int watchdog
; /* watchdog timer flag */
175 struct callout callout
; /* watchdog timer call out */
177 devclass_t psm_devclass
;
178 #define PSM_SOFTC(unit) ((struct psm_softc*)devclass_get_softc(psm_devclass, unit))
180 /* driver state flags (state) */
181 #define PSM_VALID 0x80
182 #define PSM_OPEN 1 /* Device is open */
183 #define PSM_ASLP 2 /* Waiting for mouse data */
185 /* driver configuration flags (config) */
186 #define PSM_CONFIG_RESOLUTION 0x000f /* resolution */
187 #define PSM_CONFIG_ACCEL 0x00f0 /* acceleration factor */
188 #define PSM_CONFIG_NOCHECKSYNC 0x0100 /* disable sync. test */
189 #define PSM_CONFIG_NOIDPROBE 0x0200 /* disable mouse model probe */
190 #define PSM_CONFIG_NORESET 0x0400 /* don't reset the mouse */
191 #define PSM_CONFIG_FORCETAP 0x0800 /* assume `tap' action exists */
192 #define PSM_CONFIG_IGNPORTERROR 0x1000 /* ignore error in aux port test */
193 #define PSM_CONFIG_HOOKRESUME 0x2000 /* hook the system resume event */
194 #define PSM_CONFIG_INITAFTERSUSPEND 0x4000 /* init the device at the resume event */
195 #define PSM_CONFIG_SYNCHACK 0x8000 /* enable `out-of-sync' hack */
197 #define PSM_CONFIG_FLAGS (PSM_CONFIG_RESOLUTION \
199 | PSM_CONFIG_NOCHECKSYNC \
200 | PSM_CONFIG_SYNCHACK \
201 | PSM_CONFIG_NOIDPROBE \
202 | PSM_CONFIG_NORESET \
203 | PSM_CONFIG_FORCETAP \
204 | PSM_CONFIG_IGNPORTERROR \
205 | PSM_CONFIG_HOOKRESUME \
206 | PSM_CONFIG_INITAFTERSUSPEND)
208 /* other flags (flags) */
209 #define PSM_FLAGS_FINGERDOWN 0x0001 /* VersaPad finger down */
211 /* for backward compatibility */
212 #define OLD_MOUSE_GETHWINFO _IOR('M', 1, old_mousehw_t)
213 #define OLD_MOUSE_GETMODE _IOR('M', 2, old_mousemode_t)
214 #define OLD_MOUSE_SETMODE _IOW('M', 3, old_mousemode_t)
216 typedef struct old_mousehw
{
223 typedef struct old_mousemode
{
230 /* packet formatting function */
231 typedef int packetfunc_t (struct psm_softc
*, unsigned char *,
232 int *, int, mousestatus_t
*);
234 /* function prototypes */
235 static int psmprobe (device_t
);
236 static int psmattach (device_t
);
237 static int psmdetach (device_t
);
238 static int psmresume (device_t
);
240 static d_open_t psmopen
;
241 static d_close_t psmclose
;
242 static d_read_t psmread
;
243 static d_ioctl_t psmioctl
;
244 static d_poll_t psmpoll
;
246 static int enable_aux_dev (KBDC
);
247 static int disable_aux_dev (KBDC
);
248 static int get_mouse_status (KBDC
, int *, int, int);
249 static int get_aux_id (KBDC
);
250 static int set_mouse_sampling_rate (KBDC
, int);
251 static int set_mouse_scaling (KBDC
, int);
252 static int set_mouse_resolution (KBDC
, int);
253 static int set_mouse_mode (KBDC
);
254 static int get_mouse_buttons (KBDC
);
255 static int is_a_mouse (int);
256 static void recover_from_error (KBDC
);
257 static int restore_controller (KBDC
, int);
258 static int doinitialize (struct psm_softc
*, mousemode_t
*);
259 static int doopen (struct psm_softc
*, int);
260 static int reinitialize (struct psm_softc
*, int);
261 static char *model_name (int);
262 static void psmintr (void *);
263 static void psmtimeout (void *);
265 /* vendor specific features */
266 typedef int probefunc_t (struct psm_softc
*);
268 static int mouse_id_proc1 (KBDC
, int, int, int *);
269 static int mouse_ext_command (KBDC
, int);
270 static probefunc_t enable_groller
;
271 static probefunc_t enable_gmouse
;
272 static probefunc_t enable_aglide
;
273 static probefunc_t enable_kmouse
;
274 static probefunc_t enable_msexplorer
;
275 static probefunc_t enable_msintelli
;
276 static probefunc_t enable_4dmouse
;
277 static probefunc_t enable_4dplus
;
278 static probefunc_t enable_mmanplus
;
279 static probefunc_t enable_versapad
;
280 static int tame_mouse (struct psm_softc
*, mousestatus_t
*, unsigned char *);
284 unsigned char syncmask
;
286 probefunc_t
*probefunc
;
289 * WARNING: the order of probe is very important. Don't mess it
290 * unless you know what you are doing.
292 { MOUSE_MODEL_NET
, /* Genius NetMouse */
293 0x08, MOUSE_PS2INTELLI_PACKETSIZE
, enable_gmouse
, },
294 { MOUSE_MODEL_NETSCROLL
, /* Genius NetScroll */
295 0xc8, 6, enable_groller
, },
296 { MOUSE_MODEL_MOUSEMANPLUS
, /* Logitech MouseMan+ */
297 0x08, MOUSE_PS2_PACKETSIZE
, enable_mmanplus
, },
298 { MOUSE_MODEL_EXPLORER
, /* Microsoft IntelliMouse Explorer */
299 0x08, MOUSE_PS2INTELLI_PACKETSIZE
, enable_msexplorer
, },
300 { MOUSE_MODEL_4D
, /* A4 Tech 4D Mouse */
301 0x08, MOUSE_4D_PACKETSIZE
, enable_4dmouse
, },
302 { MOUSE_MODEL_4DPLUS
, /* A4 Tech 4D+ Mouse */
303 0xc8, MOUSE_4DPLUS_PACKETSIZE
, enable_4dplus
, },
304 { MOUSE_MODEL_INTELLI
, /* Microsoft IntelliMouse */
305 0x08, MOUSE_PS2INTELLI_PACKETSIZE
, enable_msintelli
, },
306 { MOUSE_MODEL_GLIDEPOINT
, /* ALPS GlidePoint */
307 0xc0, MOUSE_PS2_PACKETSIZE
, enable_aglide
, },
308 { MOUSE_MODEL_THINK
, /* Kensignton ThinkingMouse */
309 0x80, MOUSE_PS2_PACKETSIZE
, enable_kmouse
, },
310 { MOUSE_MODEL_VERSAPAD
, /* Interlink electronics VersaPad */
311 0xe8, MOUSE_PS2VERSA_PACKETSIZE
, enable_versapad
, },
312 { MOUSE_MODEL_GENERIC
,
313 0xc0, MOUSE_PS2_PACKETSIZE
, NULL
, },
315 #define GENERIC_MOUSE_ENTRY ((sizeof(vendortype) / sizeof(*vendortype)) - 1)
317 /* device driver declarateion */
318 static device_method_t psm_methods
[] = {
319 /* Device interface */
320 DEVMETHOD(device_probe
, psmprobe
),
321 DEVMETHOD(device_attach
, psmattach
),
322 DEVMETHOD(device_detach
, psmdetach
),
323 DEVMETHOD(device_resume
, psmresume
),
328 static driver_t psm_driver
= {
331 sizeof(struct psm_softc
),
335 static struct isa_pnp_id psm_ids
[] = {
336 { 0x130fd041, "PS/2 mouse port" }, /* PNP0F13 */
337 { 0x1303d041, "PS/2 port" }, /* PNP0313, XXX */
342 #define CDEV_MAJOR 21
344 static struct dev_ops psm_ops
= {
345 { PSM_DRIVER_NAME
, CDEV_MAJOR
, 0 },
353 /* debug message level */
354 static int verbose
= PSM_DEBUG
;
356 /* device I/O routines */
358 enable_aux_dev(KBDC kbdc
)
362 res
= send_aux_command(kbdc
, PSMC_ENABLE_DEV
);
364 log(LOG_DEBUG
, "psm: ENABLE_DEV return code:%04x\n", res
);
366 return (res
== PSM_ACK
);
370 disable_aux_dev(KBDC kbdc
)
374 res
= send_aux_command(kbdc
, PSMC_DISABLE_DEV
);
376 log(LOG_DEBUG
, "psm: DISABLE_DEV return code:%04x\n", res
);
378 return (res
== PSM_ACK
);
382 get_mouse_status(KBDC kbdc
, int *status
, int flag
, int len
)
391 cmd
= PSMC_SEND_DEV_STATUS
;
394 cmd
= PSMC_SEND_DEV_DATA
;
397 empty_aux_buffer(kbdc
, 5);
398 res
= send_aux_command(kbdc
, cmd
);
400 log(LOG_DEBUG
, "psm: SEND_AUX_DEV_%s return code:%04x\n",
401 (flag
== 1) ? "DATA" : "STATUS", res
);
405 for (i
= 0; i
< len
; ++i
) {
406 status
[i
] = read_aux_data(kbdc
);
412 log(LOG_DEBUG
, "psm: %s %02x %02x %02x\n",
413 (flag
== 1) ? "data" : "status", status
[0], status
[1], status
[2]);
420 get_aux_id(KBDC kbdc
)
425 empty_aux_buffer(kbdc
, 5);
426 res
= send_aux_command(kbdc
, PSMC_SEND_DEV_ID
);
428 log(LOG_DEBUG
, "psm: SEND_DEV_ID return code:%04x\n", res
);
435 id
= read_aux_data(kbdc
);
437 log(LOG_DEBUG
, "psm: device ID: %04x\n", id
);
443 set_mouse_sampling_rate(KBDC kbdc
, int rate
)
447 res
= send_aux_command_and_data(kbdc
, PSMC_SET_SAMPLING_RATE
, rate
);
449 log(LOG_DEBUG
, "psm: SET_SAMPLING_RATE (%d) %04x\n", rate
, res
);
451 return ((res
== PSM_ACK
) ? rate
: -1);
455 set_mouse_scaling(KBDC kbdc
, int scale
)
462 scale
= PSMC_SET_SCALING11
;
465 scale
= PSMC_SET_SCALING21
;
468 res
= send_aux_command(kbdc
, scale
);
470 log(LOG_DEBUG
, "psm: SET_SCALING%s return code:%04x\n",
471 (scale
== PSMC_SET_SCALING21
) ? "21" : "11", res
);
473 return (res
== PSM_ACK
);
476 /* `val' must be 0 through PSMD_MAX_RESOLUTION */
478 set_mouse_resolution(KBDC kbdc
, int val
)
482 res
= send_aux_command_and_data(kbdc
, PSMC_SET_RESOLUTION
, val
);
484 log(LOG_DEBUG
, "psm: SET_RESOLUTION (%d) %04x\n", val
, res
);
486 return ((res
== PSM_ACK
) ? val
: -1);
490 * NOTE: once `set_mouse_mode()' is called, the mouse device must be
491 * re-enabled by calling `enable_aux_dev()'
494 set_mouse_mode(KBDC kbdc
)
498 res
= send_aux_command(kbdc
, PSMC_SET_STREAM_MODE
);
500 log(LOG_DEBUG
, "psm: SET_STREAM_MODE return code:%04x\n", res
);
502 return (res
== PSM_ACK
);
506 get_mouse_buttons(KBDC kbdc
)
508 int c
= 2; /* assume two buttons by default */
512 * NOTE: a special sequence to obtain Logitech Mouse specific
513 * information: set resolution to 25 ppi, set scaling to 1:1, set
514 * scaling to 1:1, set scaling to 1:1. Then the second byte of the
515 * mouse status bytes is the number of available buttons.
516 * Some manufactures also support this sequence.
518 if (set_mouse_resolution(kbdc
, PSMD_RES_LOW
) != PSMD_RES_LOW
)
520 if (set_mouse_scaling(kbdc
, 1) && set_mouse_scaling(kbdc
, 1)
521 && set_mouse_scaling(kbdc
, 1)
522 && (get_mouse_status(kbdc
, status
, 0, 3) >= 3)) {
529 /* misc subroutines */
531 * Someday, I will get the complete list of valid pointing devices and
538 static int valid_ids
[] = {
539 PSM_MOUSE_ID
, /* mouse */
540 PSM_BALLPOINT_ID
, /* ballpoint device */
541 PSM_INTELLI_ID
, /* Intellimouse */
542 PSM_EXPLORER_ID
, /* Intellimouse Explorer */
543 -1 /* end of table */
547 for (i
= 0; valid_ids
[i
] >= 0; ++i
)
548 if (valid_ids
[i
] == id
)
557 model_name(int model
)
563 { MOUSE_MODEL_NETSCROLL
, "NetScroll" },
564 { MOUSE_MODEL_NET
, "NetMouse/NetScroll Optical" },
565 { MOUSE_MODEL_GLIDEPOINT
, "GlidePoint" },
566 { MOUSE_MODEL_THINK
, "ThinkingMouse" },
567 { MOUSE_MODEL_INTELLI
, "IntelliMouse" },
568 { MOUSE_MODEL_MOUSEMANPLUS
, "MouseMan+" },
569 { MOUSE_MODEL_VERSAPAD
, "VersaPad" },
570 { MOUSE_MODEL_EXPLORER
, "IntelliMouse Explorer" },
571 { MOUSE_MODEL_4D
, "4D Mouse" },
572 { MOUSE_MODEL_4DPLUS
, "4D+ Mouse" },
573 { MOUSE_MODEL_GENERIC
, "Generic PS/2 mouse" },
574 { MOUSE_MODEL_UNKNOWN
, NULL
},
578 for (i
= 0; models
[i
].model_code
!= MOUSE_MODEL_UNKNOWN
; ++i
) {
579 if (models
[i
].model_code
== model
)
580 return models
[i
].model_name
;
586 recover_from_error(KBDC kbdc
)
588 /* discard anything left in the output buffer */
589 empty_both_buffers(kbdc
, 10);
593 * NOTE: KBDC_RESET_KBD may not restore the communication between the
594 * keyboard and the controller.
599 * NOTE: somehow diagnostic and keyboard port test commands bring the
602 if (!test_controller(kbdc
))
603 log(LOG_ERR
, "psm: keyboard controller failed.\n");
604 /* if there isn't a keyboard in the system, the following error is OK */
605 if (test_kbd_port(kbdc
) != 0) {
607 log(LOG_ERR
, "psm: keyboard port failed.\n");
613 restore_controller(KBDC kbdc
, int command_byte
)
615 empty_both_buffers(kbdc
, 10);
617 if (!set_controller_command_byte(kbdc
, 0xff, command_byte
)) {
618 log(LOG_ERR
, "psm: failed to restore the keyboard controller "
620 empty_both_buffers(kbdc
, 10);
623 empty_both_buffers(kbdc
, 10);
629 * Re-initialize the aux port and device. The aux port must be enabled
630 * and its interrupt must be disabled before calling this routine.
631 * The aux device will be disabled before returning.
632 * The keyboard controller must be locked via `kbdc_lock()' before
633 * calling this routine.
636 doinitialize(struct psm_softc
*sc
, mousemode_t
*mode
)
638 KBDC kbdc
= sc
->kbdc
;
642 switch((i
= test_aux_port(kbdc
))) {
643 case 1: /* ignore this error */
644 case 2: /* Ignore 2 and 3 for use with some acer and compal laptops */
648 log(LOG_DEBUG
, "psm%d: strange result for test aux port (%d).\n",
651 case 0: /* no error */
653 case -1: /* time out */
655 recover_from_error(kbdc
);
656 if (sc
->config
& PSM_CONFIG_IGNPORTERROR
)
658 log(LOG_ERR
, "psm%d: the aux port is not functioning (%d).\n",
663 if (sc
->config
& PSM_CONFIG_NORESET
) {
665 * Don't try to reset the pointing device. It may possibly be
666 * left in the unknown state, though...
670 * NOTE: some controllers appears to hang the `keyboard' when
671 * the aux port doesn't exist and `PSMC_RESET_DEV' is issued.
673 if (!reset_aux_dev(kbdc
)) {
674 recover_from_error(kbdc
);
675 log(LOG_ERR
, "psm%d: failed to reset the aux device.\n", sc
->unit
);
681 * both the aux port and the aux device is functioning, see
682 * if the device can be enabled.
684 if (!enable_aux_dev(kbdc
) || !disable_aux_dev(kbdc
)) {
685 log(LOG_ERR
, "psm%d: failed to enable the aux device.\n", sc
->unit
);
688 empty_both_buffers(kbdc
, 10); /* remove stray data if any */
690 if (sc
->config
& PSM_CONFIG_NOIDPROBE
) {
691 i
= GENERIC_MOUSE_ENTRY
;
693 /* FIXME: hardware ID, mouse buttons? */
695 /* other parameters */
696 for (i
= 0; vendortype
[i
].probefunc
!= NULL
; ++i
) {
697 if ((*vendortype
[i
].probefunc
)(sc
)) {
699 log(LOG_ERR
, "psm%d: found %s\n",
700 sc
->unit
, model_name(vendortype
[i
].model
));
706 sc
->hw
.model
= vendortype
[i
].model
;
707 sc
->mode
.packetsize
= vendortype
[i
].packetsize
;
709 /* set mouse parameters */
710 if (mode
!= (mousemode_t
*)NULL
) {
712 mode
->rate
= set_mouse_sampling_rate(kbdc
, mode
->rate
);
713 if (mode
->resolution
>= 0)
714 mode
->resolution
= set_mouse_resolution(kbdc
, mode
->resolution
);
715 set_mouse_scaling(kbdc
, 1);
716 set_mouse_mode(kbdc
);
719 /* request a data packet and extract sync. bits */
720 if (get_mouse_status(kbdc
, stat
, 1, 3) < 3) {
721 log(LOG_DEBUG
, "psm%d: failed to get data (doinitialize).\n",
723 sc
->mode
.syncmask
[0] = 0;
725 sc
->mode
.syncmask
[1] = stat
[0] & sc
->mode
.syncmask
[0]; /* syncbits */
726 /* the NetScroll Mouse will send three more bytes... Ignore them */
727 empty_aux_buffer(kbdc
, 5);
730 /* just check the status of the mouse */
731 if (get_mouse_status(kbdc
, stat
, 0, 3) < 3)
732 log(LOG_DEBUG
, "psm%d: failed to get status (doinitialize).\n",
739 doopen(struct psm_softc
*sc
, int command_byte
)
743 /* enable the mouse device */
744 if (!enable_aux_dev(sc
->kbdc
)) {
745 /* MOUSE ERROR: failed to enable the mouse because:
746 * 1) the mouse is faulty,
747 * 2) the mouse has been removed(!?)
748 * In the latter case, the keyboard may have hung, and need
749 * recovery procedure...
751 recover_from_error(sc
->kbdc
);
753 /* FIXME: we could reset the mouse here and try to enable
754 * it again. But it will take long time and it's not a good
755 * idea to disable the keyboard that long...
757 if (!doinitialize(sc
, &sc
->mode
) || !enable_aux_dev(sc
->kbdc
)) {
758 recover_from_error(sc
->kbdc
);
762 restore_controller(sc
->kbdc
, command_byte
);
763 /* mark this device is no longer available */
764 sc
->state
&= ~PSM_VALID
;
765 log(LOG_ERR
, "psm%d: failed to enable the device (doopen).\n",
771 if (get_mouse_status(sc
->kbdc
, stat
, 0, 3) < 3)
772 log(LOG_DEBUG
, "psm%d: failed to get status (doopen).\n", sc
->unit
);
774 /* enable the aux port and interrupt */
775 if (!set_controller_command_byte(sc
->kbdc
,
776 kbdc_get_device_mask(sc
->kbdc
),
777 (command_byte
& KBD_KBD_CONTROL_BITS
)
778 | KBD_ENABLE_AUX_PORT
| KBD_ENABLE_AUX_INT
)) {
779 /* CONTROLLER ERROR */
780 disable_aux_dev(sc
->kbdc
);
781 restore_controller(sc
->kbdc
, command_byte
);
782 log(LOG_ERR
, "psm%d: failed to enable the aux interrupt (doopen).\n",
787 /* start the watchdog timer */
788 sc
->watchdog
= FALSE
;
789 callout_reset(&sc
->callout
, hz
* 2, psmtimeout
, (void *)(uintptr_t)sc
);
795 reinitialize(struct psm_softc
*sc
, int doinit
)
800 /* don't let anybody mess with the aux device */
801 if (!kbdc_lock(sc
->kbdc
, TRUE
))
805 /* block our watchdog timer */
806 sc
->watchdog
= FALSE
;
807 callout_stop(&sc
->callout
);
809 /* save the current controller command byte */
810 empty_both_buffers(sc
->kbdc
, 10);
811 c
= get_controller_command_byte(sc
->kbdc
);
813 log(LOG_DEBUG
, "psm%d: current command byte: %04x (reinitialize).\n",
816 /* enable the aux port but disable the aux interrupt and the keyboard */
817 if ((c
== -1) || !set_controller_command_byte(sc
->kbdc
,
818 kbdc_get_device_mask(sc
->kbdc
),
819 KBD_DISABLE_KBD_PORT
| KBD_DISABLE_KBD_INT
820 | KBD_ENABLE_AUX_PORT
| KBD_DISABLE_AUX_INT
)) {
821 /* CONTROLLER ERROR */
823 kbdc_lock(sc
->kbdc
, FALSE
);
824 log(LOG_ERR
, "psm%d: unable to set the command byte (reinitialize).\n",
830 if (sc
->state
& PSM_VALID
) {
831 disable_aux_dev(sc
->kbdc
); /* this may fail; but never mind... */
832 empty_aux_buffer(sc
->kbdc
, 10);
837 /* try to detect the aux device; are you still there? */
840 if (doinitialize(sc
, &sc
->mode
)) {
842 sc
->state
|= PSM_VALID
;
844 /* the device has gone! */
845 restore_controller(sc
->kbdc
, c
);
846 sc
->state
&= ~PSM_VALID
;
847 log(LOG_ERR
, "psm%d: the aux device has gone! (reinitialize).\n",
854 /* restore the driver state */
855 if ((sc
->state
& PSM_OPEN
) && (err
== 0)) {
856 /* enable the aux device and the port again */
859 log(LOG_ERR
, "psm%d: failed to enable the device (reinitialize).\n",
862 /* restore the keyboard port and disable the aux port */
863 if (!set_controller_command_byte(sc
->kbdc
,
864 kbdc_get_device_mask(sc
->kbdc
),
865 (c
& KBD_KBD_CONTROL_BITS
)
866 | KBD_DISABLE_AUX_PORT
| KBD_DISABLE_AUX_INT
)) {
867 /* CONTROLLER ERROR */
868 log(LOG_ERR
, "psm%d: failed to disable the aux port (reinitialize).\n",
874 kbdc_lock(sc
->kbdc
, FALSE
);
878 /* psm driver entry points */
880 #define endprobe(v) { if (bootverbose) \
882 kbdc_set_device_mask(sc->kbdc, mask); \
883 kbdc_lock(sc->kbdc, FALSE); \
888 psmprobe(device_t dev
)
890 int unit
= device_get_unit(dev
);
891 struct psm_softc
*sc
= device_get_softc(dev
);
906 if (XXX_PNP_PROBE(device_get_parent(dev
), dev
, psm_ids
) == ENXIO
)
910 BUS_READ_IVAR(device_get_parent(dev
), dev
, KBDC_IVAR_IRQ
, &irq
);
911 BUS_READ_IVAR(device_get_parent(dev
), dev
, KBDC_IVAR_FLAGS
, &flags
);
914 sc
->kbdc
= atkbdc_open(device_get_unit(device_get_parent(dev
)));
915 sc
->config
= flags
& PSM_CONFIG_FLAGS
;
916 /* XXX: for backward compatibility */
917 #if defined(PSM_HOOKRESUME) || defined(PSM_HOOKAPM)
919 #ifdef PSM_RESETAFTERSUSPEND
920 PSM_CONFIG_HOOKRESUME
| PSM_CONFIG_INITAFTERSUSPEND
;
922 PSM_CONFIG_HOOKRESUME
;
924 #endif /* PSM_HOOKRESUME | PSM_HOOKAPM */
929 device_set_desc(dev
, "PS/2 Mouse");
931 if (!kbdc_lock(sc
->kbdc
, TRUE
)) {
932 kprintf("psm%d: unable to lock the controller.\n", unit
);
939 * NOTE: two bits in the command byte controls the operation of the
940 * aux port (mouse port): the aux port disable bit (bit 5) and the aux
941 * port interrupt (IRQ 12) enable bit (bit 2).
944 /* discard anything left after the keyboard initialization */
945 empty_both_buffers(sc
->kbdc
, 10);
947 /* save the current command byte; it will be used later */
948 mask
= kbdc_get_device_mask(sc
->kbdc
) & ~KBD_AUX_CONTROL_BITS
;
949 command_byte
= get_controller_command_byte(sc
->kbdc
);
951 kprintf("psm%d: current command byte:%04x\n", unit
, command_byte
);
952 if (command_byte
== -1) {
953 /* CONTROLLER ERROR */
954 kprintf("psm%d: unable to get the current command byte value.\n",
960 * disable the keyboard port while probing the aux port, which must be
961 * enabled during this routine
963 if (!set_controller_command_byte(sc
->kbdc
,
964 KBD_KBD_CONTROL_BITS
| KBD_AUX_CONTROL_BITS
,
965 KBD_DISABLE_KBD_PORT
| KBD_DISABLE_KBD_INT
966 | KBD_ENABLE_AUX_PORT
| KBD_DISABLE_AUX_INT
)) {
968 * this is CONTROLLER ERROR; I don't know how to recover
971 restore_controller(sc
->kbdc
, command_byte
);
972 kprintf("psm%d: unable to set the command byte.\n", unit
);
975 write_controller_command(sc
->kbdc
, KBDC_ENABLE_AUX_PORT
);
978 * NOTE: `test_aux_port()' is designed to return with zero if the aux
979 * port exists and is functioning. However, some controllers appears
980 * to respond with zero even when the aux port doesn't exist. (It may
981 * be that this is only the case when the controller DOES have the aux
982 * port but the port is not wired on the motherboard.) The keyboard
983 * controllers without the port, such as the original AT, are
984 * supporsed to return with an error code or simply time out. In any
985 * case, we have to continue probing the port even when the controller
988 * XXX: some controllers erroneously return the error code 1 when
989 * it has the perfectly functional aux port. We have to ignore this
990 * error code. Even if the controller HAS error with the aux port,
991 * it will be detected later...
992 * XXX: another incompatible controller returns PSM_ACK (0xfa)...
994 switch ((i
= test_aux_port(sc
->kbdc
))) {
995 case 1: /* ignore this error */
996 case 2: /* Ignore 2 and 3 for use with some acer and compal laptops */
1000 kprintf("psm%d: strange result for test aux port (%d).\n",
1003 case 0: /* no error */
1005 case -1: /* time out */
1006 default: /* error */
1007 recover_from_error(sc
->kbdc
);
1008 if (sc
->config
& PSM_CONFIG_IGNPORTERROR
)
1010 restore_controller(sc
->kbdc
, command_byte
);
1012 kprintf("psm%d: the aux port is not functioning (%d).\n",
1017 if (sc
->config
& PSM_CONFIG_NORESET
) {
1019 * Don't try to reset the pointing device. It may possibly be
1020 * left in the unknown state, though...
1024 * NOTE: some controllers appears to hang the `keyboard' when the aux
1025 * port doesn't exist and `PSMC_RESET_DEV' is issued.
1027 * Attempt to reset the controller twice -- this helps
1028 * pierce through some KVM switches. The second reset
1031 if (!reset_aux_dev(sc
->kbdc
)) {
1032 recover_from_error(sc
->kbdc
);
1033 restore_controller(sc
->kbdc
, command_byte
);
1035 kprintf("psm%d: failed to reset the aux device.\n", unit
);
1037 } else if (!reset_aux_dev(sc
->kbdc
)) {
1038 recover_from_error(sc
->kbdc
);
1040 kprintf("psm%d: failed to reset the aux device (2).\n",
1046 * both the aux port and the aux device is functioning, see if the
1047 * device can be enabled. NOTE: when enabled, the device will start
1048 * sending data; we shall immediately disable the device once we know
1049 * the device can be enabled.
1051 if (!enable_aux_dev(sc
->kbdc
) || !disable_aux_dev(sc
->kbdc
)) {
1053 recover_from_error(sc
->kbdc
);
1054 restore_controller(sc
->kbdc
, command_byte
);
1056 kprintf("psm%d: failed to enable the aux device.\n", unit
);
1060 /* save the default values after reset */
1061 if (get_mouse_status(sc
->kbdc
, stat
, 0, 3) >= 3) {
1062 sc
->dflt_mode
.rate
= sc
->mode
.rate
= stat
[2];
1063 sc
->dflt_mode
.resolution
= sc
->mode
.resolution
= stat
[1];
1065 sc
->dflt_mode
.rate
= sc
->mode
.rate
= -1;
1066 sc
->dflt_mode
.resolution
= sc
->mode
.resolution
= -1;
1069 /* hardware information */
1070 sc
->hw
.iftype
= MOUSE_IF_PS2
;
1072 /* verify the device is a mouse */
1073 sc
->hw
.hwid
= get_aux_id(sc
->kbdc
);
1074 if (!is_a_mouse(sc
->hw
.hwid
)) {
1075 restore_controller(sc
->kbdc
, command_byte
);
1077 kprintf("psm%d: unknown device type (%d).\n", unit
, sc
->hw
.hwid
);
1080 switch (sc
->hw
.hwid
) {
1081 case PSM_BALLPOINT_ID
:
1082 sc
->hw
.type
= MOUSE_TRACKBALL
;
1085 case PSM_INTELLI_ID
:
1086 case PSM_EXPLORER_ID
:
1087 case PSM_4DMOUSE_ID
:
1089 sc
->hw
.type
= MOUSE_MOUSE
;
1092 sc
->hw
.type
= MOUSE_UNKNOWN
;
1096 if (sc
->config
& PSM_CONFIG_NOIDPROBE
) {
1098 i
= GENERIC_MOUSE_ENTRY
;
1101 sc
->hw
.buttons
= get_mouse_buttons(sc
->kbdc
);
1103 /* other parameters */
1104 for (i
= 0; vendortype
[i
].probefunc
!= NULL
; ++i
) {
1105 if ((*vendortype
[i
].probefunc
)(sc
)) {
1107 kprintf("psm%d: found %s\n",
1108 unit
, model_name(vendortype
[i
].model
));
1114 sc
->hw
.model
= vendortype
[i
].model
;
1116 sc
->dflt_mode
.level
= PSM_LEVEL_BASE
;
1117 sc
->dflt_mode
.packetsize
= MOUSE_PS2_PACKETSIZE
;
1118 sc
->dflt_mode
.accelfactor
= (sc
->config
& PSM_CONFIG_ACCEL
) >> 4;
1119 if (sc
->config
& PSM_CONFIG_NOCHECKSYNC
)
1120 sc
->dflt_mode
.syncmask
[0] = 0;
1122 sc
->dflt_mode
.syncmask
[0] = vendortype
[i
].syncmask
;
1123 if (sc
->config
& PSM_CONFIG_FORCETAP
)
1124 sc
->mode
.syncmask
[0] &= ~MOUSE_PS2_TAP
;
1125 sc
->dflt_mode
.syncmask
[1] = 0; /* syncbits */
1126 sc
->mode
= sc
->dflt_mode
;
1127 sc
->mode
.packetsize
= vendortype
[i
].packetsize
;
1129 /* set mouse parameters */
1132 * A version of Logitech FirstMouse+ won't report wheel movement,
1133 * if SET_DEFAULTS is sent... Don't use this command.
1134 * This fix was found by Takashi Nishida.
1136 i
= send_aux_command(sc
->kbdc
, PSMC_SET_DEFAULTS
);
1138 kprintf("psm%d: SET_DEFAULTS return code:%04x\n", unit
, i
);
1140 if (sc
->config
& PSM_CONFIG_RESOLUTION
) {
1142 = set_mouse_resolution(sc
->kbdc
,
1143 (sc
->config
& PSM_CONFIG_RESOLUTION
) - 1);
1144 } else if (sc
->mode
.resolution
>= 0) {
1146 = set_mouse_resolution(sc
->kbdc
, sc
->dflt_mode
.resolution
);
1148 if (sc
->mode
.rate
> 0) {
1149 sc
->mode
.rate
= set_mouse_sampling_rate(sc
->kbdc
, sc
->dflt_mode
.rate
);
1151 set_mouse_scaling(sc
->kbdc
, 1);
1153 /* request a data packet and extract sync. bits */
1154 if (get_mouse_status(sc
->kbdc
, stat
, 1, 3) < 3) {
1155 kprintf("psm%d: failed to get data.\n", unit
);
1156 sc
->mode
.syncmask
[0] = 0;
1158 sc
->mode
.syncmask
[1] = stat
[0] & sc
->mode
.syncmask
[0]; /* syncbits */
1159 /* the NetScroll Mouse will send three more bytes... Ignore them */
1160 empty_aux_buffer(sc
->kbdc
, 5);
1163 /* just check the status of the mouse */
1165 * NOTE: XXX there are some arcane controller/mouse combinations out
1166 * there, which hung the controller unless there is data transmission
1167 * after ACK from the mouse.
1169 if (get_mouse_status(sc
->kbdc
, stat
, 0, 3) < 3) {
1170 kprintf("psm%d: failed to get status.\n", unit
);
1173 * When in its native mode, some mice operate with different
1174 * default parameters than in the PS/2 compatible mode.
1176 sc
->dflt_mode
.rate
= sc
->mode
.rate
= stat
[2];
1177 sc
->dflt_mode
.resolution
= sc
->mode
.resolution
= stat
[1];
1180 /* disable the aux port for now... */
1181 if (!set_controller_command_byte(sc
->kbdc
,
1182 KBD_KBD_CONTROL_BITS
| KBD_AUX_CONTROL_BITS
,
1183 (command_byte
& KBD_KBD_CONTROL_BITS
)
1184 | KBD_DISABLE_AUX_PORT
| KBD_DISABLE_AUX_INT
)) {
1186 * this is CONTROLLER ERROR; I don't know the proper way to
1187 * recover from this error...
1189 restore_controller(sc
->kbdc
, command_byte
);
1190 kprintf("psm%d: unable to set the command byte.\n", unit
);
1194 /* see if IRQ is available */
1196 sc
->intr
= bus_alloc_resource(dev
, SYS_RES_IRQ
, &rid
, irq
, irq
, 1,
1198 if (sc
->intr
== NULL
) {
1199 kprintf("psm%d: unable to allocate the IRQ resource (%d).\n",
1203 bus_release_resource(dev
, SYS_RES_IRQ
, rid
, sc
->intr
);
1207 kbdc_set_device_mask(sc
->kbdc
, mask
| KBD_AUX_CONTROL_BITS
);
1208 kbdc_lock(sc
->kbdc
, FALSE
);
1213 psmattach(device_t dev
)
1215 int unit
= device_get_unit(dev
);
1216 struct psm_softc
*sc
= device_get_softc(dev
);
1221 if (sc
== NULL
) /* shouldn't happen */
1224 /* Setup initial state */
1225 sc
->state
= PSM_VALID
;
1226 callout_init(&sc
->callout
);
1228 /* Setup our interrupt handler */
1230 BUS_READ_IVAR(device_get_parent(dev
), dev
, KBDC_IVAR_IRQ
, &irq
);
1231 sc
->intr
= bus_alloc_resource(dev
, SYS_RES_IRQ
, &rid
, irq
, irq
, 1,
1233 if (sc
->intr
== NULL
)
1235 error
= BUS_SETUP_INTR(device_get_parent(dev
), dev
, sc
->intr
,
1236 INTR_NOPOLL
, psmintr
, sc
, &sc
->ih
, NULL
);
1238 bus_release_resource(dev
, SYS_RES_IRQ
, rid
, sc
->intr
);
1243 dev_ops_add(&psm_ops
, PSM_MKMINOR(-1, 0), PSM_MKMINOR(unit
, 0));
1244 make_dev(&psm_ops
, PSM_MKMINOR(unit
, FALSE
), 0, 0, 0666, "psm%d", unit
);
1245 make_dev(&psm_ops
, PSM_MKMINOR(unit
, TRUE
), 0, 0, 0666, "bpsm%d", unit
);
1248 kprintf("psm%d: model %s, device ID %d\n",
1249 unit
, model_name(sc
->hw
.model
), sc
->hw
.hwid
& 0x00ff);
1251 kprintf("psm%d: model %s, device ID %d-%02x, %d buttons\n",
1252 unit
, model_name(sc
->hw
.model
),
1253 sc
->hw
.hwid
& 0x00ff, sc
->hw
.hwid
>> 8, sc
->hw
.buttons
);
1254 kprintf("psm%d: config:%08x, flags:%08x, packet size:%d\n",
1255 unit
, sc
->config
, sc
->flags
, sc
->mode
.packetsize
);
1256 kprintf("psm%d: syncmask:%02x, syncbits:%02x\n",
1257 unit
, sc
->mode
.syncmask
[0], sc
->mode
.syncmask
[1]);
1267 psmdetach(device_t dev
)
1269 struct psm_softc
*sc
;
1273 sc
= device_get_softc(dev
);
1274 if (sc
->state
& PSM_OPEN
)
1277 unit
= device_get_unit(dev
);
1280 BUS_TEARDOWN_INTR(device_get_parent(dev
), dev
, sc
->intr
, sc
->ih
);
1281 bus_release_resource(dev
, SYS_RES_IRQ
, rid
, sc
->intr
);
1282 dev_ops_remove(&psm_ops
, PSM_MKMINOR(-1, 0), PSM_MKMINOR(unit
, 0));
1288 psmopen(struct dev_open_args
*ap
)
1290 cdev_t dev
= ap
->a_head
.a_dev
;
1291 int unit
= PSM_UNIT(dev
);
1292 struct psm_softc
*sc
;
1296 /* Get device data */
1297 sc
= PSM_SOFTC(unit
);
1298 if ((sc
== NULL
) || (sc
->state
& PSM_VALID
) == 0)
1299 /* the device is no longer valid/functioning */
1302 /* Disallow multiple opens */
1303 if (sc
->state
& PSM_OPEN
)
1307 device_busy(devclass_get_device(psm_devclass
, unit
));
1310 /* Initialize state */
1311 sc
->rsel
.si_flags
= 0;
1312 sc
->rsel
.si_pid
= 0;
1313 sc
->mode
.level
= sc
->dflt_mode
.level
;
1314 sc
->mode
.protocol
= sc
->dflt_mode
.protocol
;
1315 sc
->watchdog
= FALSE
;
1317 /* flush the event queue */
1318 sc
->queue
.count
= 0;
1321 sc
->status
.flags
= 0;
1322 sc
->status
.button
= 0;
1323 sc
->status
.obutton
= 0;
1329 /* empty input buffer */
1330 bzero(sc
->ipacket
, sizeof(sc
->ipacket
));
1334 /* don't let timeout routines in the keyboard driver to poll the kbdc */
1335 if (!kbdc_lock(sc
->kbdc
, TRUE
))
1338 /* save the current controller command byte */
1340 command_byte
= get_controller_command_byte(sc
->kbdc
);
1342 /* enable the aux port and temporalily disable the keyboard */
1343 if ((command_byte
== -1)
1344 || !set_controller_command_byte(sc
->kbdc
,
1345 kbdc_get_device_mask(sc
->kbdc
),
1346 KBD_DISABLE_KBD_PORT
| KBD_DISABLE_KBD_INT
1347 | KBD_ENABLE_AUX_PORT
| KBD_DISABLE_AUX_INT
)) {
1348 /* CONTROLLER ERROR; do you know how to get out of this? */
1349 kbdc_lock(sc
->kbdc
, FALSE
);
1351 log(LOG_ERR
, "psm%d: unable to set the command byte (psmopen).\n",
1356 * Now that the keyboard controller is told not to generate
1357 * the keyboard and mouse interrupts, call `splx()' to allow
1358 * the other tty interrupts. The clock interrupt may also occur,
1359 * but timeout routines will be blocked by the poll flag set
1364 /* enable the mouse device */
1365 err
= doopen(sc
, command_byte
);
1369 sc
->state
|= PSM_OPEN
;
1370 kbdc_lock(sc
->kbdc
, FALSE
);
1375 psmclose(struct dev_close_args
*ap
)
1377 cdev_t dev
= ap
->a_head
.a_dev
;
1378 int unit
= PSM_UNIT(dev
);
1379 struct psm_softc
*sc
= PSM_SOFTC(unit
);
1383 /* don't let timeout routines in the keyboard driver to poll the kbdc */
1384 if (!kbdc_lock(sc
->kbdc
, TRUE
))
1387 /* save the current controller command byte */
1389 command_byte
= get_controller_command_byte(sc
->kbdc
);
1390 if (command_byte
== -1) {
1391 kbdc_lock(sc
->kbdc
, FALSE
);
1396 /* disable the aux interrupt and temporalily disable the keyboard */
1397 if (!set_controller_command_byte(sc
->kbdc
,
1398 kbdc_get_device_mask(sc
->kbdc
),
1399 KBD_DISABLE_KBD_PORT
| KBD_DISABLE_KBD_INT
1400 | KBD_ENABLE_AUX_PORT
| KBD_DISABLE_AUX_INT
)) {
1401 log(LOG_ERR
, "psm%d: failed to disable the aux int (psmclose).\n",
1403 /* CONTROLLER ERROR;
1404 * NOTE: we shall force our way through. Because the only
1405 * ill effect we shall see is that we may not be able
1406 * to read ACK from the mouse, and it doesn't matter much
1407 * so long as the mouse will accept the DISABLE command.
1412 /* stop the watchdog timer */
1413 callout_stop(&sc
->callout
);
1415 /* remove anything left in the output buffer */
1416 empty_aux_buffer(sc
->kbdc
, 10);
1418 /* disable the aux device, port and interrupt */
1419 if (sc
->state
& PSM_VALID
) {
1420 if (!disable_aux_dev(sc
->kbdc
)) {
1422 * NOTE: we don't return error and continue, pretending
1423 * we have successfully disabled the device. It's OK because
1424 * the interrupt routine will discard any data from the mouse
1427 log(LOG_ERR
, "psm%d: failed to disable the device (psmclose).\n",
1431 if (get_mouse_status(sc
->kbdc
, stat
, 0, 3) < 3)
1432 log(LOG_DEBUG
, "psm%d: failed to get status (psmclose).\n",
1436 if (!set_controller_command_byte(sc
->kbdc
,
1437 kbdc_get_device_mask(sc
->kbdc
),
1438 (command_byte
& KBD_KBD_CONTROL_BITS
)
1439 | KBD_DISABLE_AUX_PORT
| KBD_DISABLE_AUX_INT
)) {
1440 /* CONTROLLER ERROR;
1441 * we shall ignore this error; see the above comment.
1443 log(LOG_ERR
, "psm%d: failed to disable the aux port (psmclose).\n",
1447 /* remove anything left in the output buffer */
1448 empty_aux_buffer(sc
->kbdc
, 10);
1450 /* close is almost always successful */
1451 sc
->state
&= ~PSM_OPEN
;
1452 kbdc_lock(sc
->kbdc
, FALSE
);
1454 device_unbusy(devclass_get_device(psm_devclass
, unit
));
1460 tame_mouse(struct psm_softc
*sc
, mousestatus_t
*status
, unsigned char *buf
)
1462 static unsigned char butmapps2
[8] = {
1464 MOUSE_PS2_BUTTON1DOWN
,
1465 MOUSE_PS2_BUTTON2DOWN
,
1466 MOUSE_PS2_BUTTON1DOWN
| MOUSE_PS2_BUTTON2DOWN
,
1467 MOUSE_PS2_BUTTON3DOWN
,
1468 MOUSE_PS2_BUTTON1DOWN
| MOUSE_PS2_BUTTON3DOWN
,
1469 MOUSE_PS2_BUTTON2DOWN
| MOUSE_PS2_BUTTON3DOWN
,
1470 MOUSE_PS2_BUTTON1DOWN
| MOUSE_PS2_BUTTON2DOWN
| MOUSE_PS2_BUTTON3DOWN
,
1472 static unsigned char butmapmsc
[8] = {
1473 MOUSE_MSC_BUTTON1UP
| MOUSE_MSC_BUTTON2UP
| MOUSE_MSC_BUTTON3UP
,
1474 MOUSE_MSC_BUTTON2UP
| MOUSE_MSC_BUTTON3UP
,
1475 MOUSE_MSC_BUTTON1UP
| MOUSE_MSC_BUTTON3UP
,
1476 MOUSE_MSC_BUTTON3UP
,
1477 MOUSE_MSC_BUTTON1UP
| MOUSE_MSC_BUTTON2UP
,
1478 MOUSE_MSC_BUTTON2UP
,
1479 MOUSE_MSC_BUTTON1UP
,
1485 if (sc
->mode
.level
== PSM_LEVEL_BASE
) {
1486 mapped
= status
->button
& ~MOUSE_BUTTON4DOWN
;
1487 if (status
->button
& MOUSE_BUTTON4DOWN
)
1488 mapped
|= MOUSE_BUTTON1DOWN
;
1489 status
->button
= mapped
;
1490 buf
[0] = MOUSE_PS2_SYNC
| butmapps2
[mapped
& MOUSE_STDBUTTONS
];
1491 i
= max(min(status
->dx
, 255), -256);
1493 buf
[0] |= MOUSE_PS2_XNEG
;
1495 i
= max(min(status
->dy
, 255), -256);
1497 buf
[0] |= MOUSE_PS2_YNEG
;
1499 return MOUSE_PS2_PACKETSIZE
;
1500 } else if (sc
->mode
.level
== PSM_LEVEL_STANDARD
) {
1501 buf
[0] = MOUSE_MSC_SYNC
| butmapmsc
[status
->button
& MOUSE_STDBUTTONS
];
1502 i
= max(min(status
->dx
, 255), -256);
1504 buf
[3] = i
- buf
[1];
1505 i
= max(min(status
->dy
, 255), -256);
1507 buf
[4] = i
- buf
[2];
1508 i
= max(min(status
->dz
, 127), -128);
1509 buf
[5] = (i
>> 1) & 0x7f;
1510 buf
[6] = (i
- (i
>> 1)) & 0x7f;
1511 buf
[7] = (~status
->button
>> 3) & 0x7f;
1512 return MOUSE_SYS_PACKETSIZE
;
1514 return sc
->inputbytes
;
1518 psmread(struct dev_read_args
*ap
)
1520 cdev_t dev
= ap
->a_head
.a_dev
;
1521 struct uio
*uio
= ap
->a_uio
;
1522 struct psm_softc
*sc
= PSM_SOFTC(PSM_UNIT(dev
));
1523 unsigned char buf
[PSM_SMALLBUFSIZE
];
1527 if ((sc
->state
& PSM_VALID
) == 0)
1530 /* block until mouse activity occured */
1532 while (sc
->queue
.count
<= 0) {
1533 if (PSM_NBLOCKIO(dev
)) {
1537 sc
->state
|= PSM_ASLP
;
1538 error
= tsleep((caddr_t
) sc
, PCATCH
, "psmrea", 0);
1539 sc
->state
&= ~PSM_ASLP
;
1543 } else if ((sc
->state
& PSM_VALID
) == 0) {
1544 /* the device disappeared! */
1551 /* copy data to the user land */
1552 while ((sc
->queue
.count
> 0) && (uio
->uio_resid
> 0)) {
1554 l
= min(sc
->queue
.count
, uio
->uio_resid
);
1555 if (l
> sizeof(buf
))
1557 if (l
> sizeof(sc
->queue
.buf
) - sc
->queue
.head
) {
1558 bcopy(&sc
->queue
.buf
[sc
->queue
.head
], &buf
[0],
1559 sizeof(sc
->queue
.buf
) - sc
->queue
.head
);
1560 bcopy(&sc
->queue
.buf
[0],
1561 &buf
[sizeof(sc
->queue
.buf
) - sc
->queue
.head
],
1562 l
- (sizeof(sc
->queue
.buf
) - sc
->queue
.head
));
1564 bcopy(&sc
->queue
.buf
[sc
->queue
.head
], &buf
[0], l
);
1566 sc
->queue
.count
-= l
;
1567 sc
->queue
.head
= (sc
->queue
.head
+ l
) % sizeof(sc
->queue
.buf
);
1569 error
= uiomove(buf
, l
, uio
);
1578 block_mouse_data(struct psm_softc
*sc
, int *c
)
1580 if (!kbdc_lock(sc
->kbdc
, TRUE
))
1584 *c
= get_controller_command_byte(sc
->kbdc
);
1586 || !set_controller_command_byte(sc
->kbdc
,
1587 kbdc_get_device_mask(sc
->kbdc
),
1588 KBD_DISABLE_KBD_PORT
| KBD_DISABLE_KBD_INT
1589 | KBD_ENABLE_AUX_PORT
| KBD_DISABLE_AUX_INT
)) {
1590 /* this is CONTROLLER ERROR */
1592 kbdc_lock(sc
->kbdc
, FALSE
);
1597 * The device may be in the middle of status data transmission.
1598 * The transmission will be interrupted, thus, incomplete status
1599 * data must be discarded. Although the aux interrupt is disabled
1600 * at the keyboard controller level, at most one aux interrupt
1601 * may have already been pending and a data byte is in the
1602 * output buffer; throw it away. Note that the second argument
1603 * to `empty_aux_buffer()' is zero, so that the call will just
1604 * flush the internal queue.
1605 * `psmintr()' will be invoked after `splx()' if an interrupt is
1606 * pending; it will see no data and returns immediately.
1608 empty_aux_buffer(sc
->kbdc
, 0); /* flush the queue */
1609 read_aux_data_no_wait(sc
->kbdc
); /* throw away data if any */
1617 unblock_mouse_data(struct psm_softc
*sc
, int c
)
1622 * We may have seen a part of status data during `set_mouse_XXX()'.
1623 * they have been queued; flush it.
1625 empty_aux_buffer(sc
->kbdc
, 0);
1627 /* restore ports and interrupt */
1628 if (!set_controller_command_byte(sc
->kbdc
,
1629 kbdc_get_device_mask(sc
->kbdc
),
1630 c
& (KBD_KBD_CONTROL_BITS
| KBD_AUX_CONTROL_BITS
))) {
1631 /* CONTROLLER ERROR; this is serious, we may have
1632 * been left with the inaccessible keyboard and
1633 * the disabled mouse interrupt.
1638 kbdc_lock(sc
->kbdc
, FALSE
);
1643 psmioctl(struct dev_ioctl_args
*ap
)
1645 cdev_t dev
= ap
->a_head
.a_dev
;
1646 caddr_t addr
= ap
->a_data
;
1647 struct psm_softc
*sc
= PSM_SOFTC(PSM_UNIT(dev
));
1649 mousestatus_t status
;
1650 #if (defined(MOUSE_GETVARS))
1658 /* Perform IOCTL command */
1660 switch (ap
->a_cmd
) {
1661 case OLD_MOUSE_GETHWINFO
:
1663 ((old_mousehw_t
*)addr
)->buttons
= sc
->hw
.buttons
;
1664 ((old_mousehw_t
*)addr
)->iftype
= sc
->hw
.iftype
;
1665 ((old_mousehw_t
*)addr
)->type
= sc
->hw
.type
;
1666 ((old_mousehw_t
*)addr
)->hwid
= sc
->hw
.hwid
& 0x00ff;
1670 case MOUSE_GETHWINFO
:
1672 *(mousehw_t
*)addr
= sc
->hw
;
1673 if (sc
->mode
.level
== PSM_LEVEL_BASE
)
1674 ((mousehw_t
*)addr
)->model
= MOUSE_MODEL_GENERIC
;
1678 case OLD_MOUSE_GETMODE
:
1680 switch (sc
->mode
.level
) {
1681 case PSM_LEVEL_BASE
:
1682 ((old_mousemode_t
*)addr
)->protocol
= MOUSE_PROTO_PS2
;
1684 case PSM_LEVEL_STANDARD
:
1685 ((old_mousemode_t
*)addr
)->protocol
= MOUSE_PROTO_SYSMOUSE
;
1687 case PSM_LEVEL_NATIVE
:
1688 ((old_mousemode_t
*)addr
)->protocol
= MOUSE_PROTO_PS2
;
1691 ((old_mousemode_t
*)addr
)->rate
= sc
->mode
.rate
;
1692 ((old_mousemode_t
*)addr
)->resolution
= sc
->mode
.resolution
;
1693 ((old_mousemode_t
*)addr
)->accelfactor
= sc
->mode
.accelfactor
;
1699 *(mousemode_t
*)addr
= sc
->mode
;
1700 ((mousemode_t
*)addr
)->resolution
=
1701 MOUSE_RES_LOW
- sc
->mode
.resolution
;
1702 switch (sc
->mode
.level
) {
1703 case PSM_LEVEL_BASE
:
1704 ((mousemode_t
*)addr
)->protocol
= MOUSE_PROTO_PS2
;
1705 ((mousemode_t
*)addr
)->packetsize
= MOUSE_PS2_PACKETSIZE
;
1707 case PSM_LEVEL_STANDARD
:
1708 ((mousemode_t
*)addr
)->protocol
= MOUSE_PROTO_SYSMOUSE
;
1709 ((mousemode_t
*)addr
)->packetsize
= MOUSE_SYS_PACKETSIZE
;
1710 ((mousemode_t
*)addr
)->syncmask
[0] = MOUSE_SYS_SYNCMASK
;
1711 ((mousemode_t
*)addr
)->syncmask
[1] = MOUSE_SYS_SYNC
;
1713 case PSM_LEVEL_NATIVE
:
1714 /* FIXME: this isn't quite correct... XXX */
1715 ((mousemode_t
*)addr
)->protocol
= MOUSE_PROTO_PS2
;
1721 case OLD_MOUSE_SETMODE
:
1723 if (ap
->a_cmd
== OLD_MOUSE_SETMODE
) {
1724 mode
.rate
= ((old_mousemode_t
*)addr
)->rate
;
1726 * resolution old I/F new I/F
1733 if (((old_mousemode_t
*)addr
)->resolution
> 0)
1734 mode
.resolution
= -((old_mousemode_t
*)addr
)->resolution
- 1;
1735 mode
.accelfactor
= ((old_mousemode_t
*)addr
)->accelfactor
;
1738 mode
= *(mousemode_t
*)addr
;
1741 /* adjust and validate parameters. */
1742 if (mode
.rate
> UCHAR_MAX
)
1745 mode
.rate
= sc
->dflt_mode
.rate
;
1746 else if (mode
.rate
== -1)
1747 /* don't change the current setting */
1749 else if (mode
.rate
< 0)
1751 if (mode
.resolution
>= UCHAR_MAX
)
1753 if (mode
.resolution
>= 200)
1754 mode
.resolution
= MOUSE_RES_HIGH
;
1755 else if (mode
.resolution
>= 100)
1756 mode
.resolution
= MOUSE_RES_MEDIUMHIGH
;
1757 else if (mode
.resolution
>= 50)
1758 mode
.resolution
= MOUSE_RES_MEDIUMLOW
;
1759 else if (mode
.resolution
> 0)
1760 mode
.resolution
= MOUSE_RES_LOW
;
1761 if (mode
.resolution
== MOUSE_RES_DEFAULT
)
1762 mode
.resolution
= sc
->dflt_mode
.resolution
;
1763 else if (mode
.resolution
== -1)
1764 /* don't change the current setting */
1766 else if (mode
.resolution
< 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */
1767 mode
.resolution
= MOUSE_RES_LOW
- mode
.resolution
;
1768 if (mode
.level
== -1)
1769 /* don't change the current setting */
1770 mode
.level
= sc
->mode
.level
;
1771 else if ((mode
.level
< PSM_LEVEL_MIN
) || (mode
.level
> PSM_LEVEL_MAX
))
1773 if (mode
.accelfactor
== -1)
1774 /* don't change the current setting */
1775 mode
.accelfactor
= sc
->mode
.accelfactor
;
1776 else if (mode
.accelfactor
< 0)
1779 /* don't allow anybody to poll the keyboard controller */
1780 error
= block_mouse_data(sc
, &command_byte
);
1784 /* set mouse parameters */
1786 mode
.rate
= set_mouse_sampling_rate(sc
->kbdc
, mode
.rate
);
1787 if (mode
.resolution
>= 0)
1788 mode
.resolution
= set_mouse_resolution(sc
->kbdc
, mode
.resolution
);
1789 set_mouse_scaling(sc
->kbdc
, 1);
1790 get_mouse_status(sc
->kbdc
, stat
, 0, 3);
1793 sc
->mode
.rate
= mode
.rate
;
1794 sc
->mode
.resolution
= mode
.resolution
;
1795 sc
->mode
.accelfactor
= mode
.accelfactor
;
1796 sc
->mode
.level
= mode
.level
;
1799 unblock_mouse_data(sc
, command_byte
);
1802 case MOUSE_GETLEVEL
:
1803 *(int *)addr
= sc
->mode
.level
;
1806 case MOUSE_SETLEVEL
:
1807 if ((*(int *)addr
< PSM_LEVEL_MIN
) || (*(int *)addr
> PSM_LEVEL_MAX
))
1809 sc
->mode
.level
= *(int *)addr
;
1812 case MOUSE_GETSTATUS
:
1814 status
= sc
->status
;
1815 sc
->status
.flags
= 0;
1816 sc
->status
.obutton
= sc
->status
.button
;
1817 sc
->status
.button
= 0;
1822 *(mousestatus_t
*)addr
= status
;
1825 #if (defined(MOUSE_GETVARS))
1827 var
= (mousevar_t
*)addr
;
1828 bzero(var
, sizeof(*var
));
1830 var
->var
[0] = MOUSE_VARS_PS2_SIG
;
1831 var
->var
[1] = sc
->config
;
1832 var
->var
[2] = sc
->flags
;
1838 #endif /* MOUSE_GETVARS */
1840 case MOUSE_READSTATE
:
1841 case MOUSE_READDATA
:
1842 data
= (mousedata_t
*)addr
;
1843 if (data
->len
> sizeof(data
->buf
)/sizeof(data
->buf
[0]))
1846 error
= block_mouse_data(sc
, &command_byte
);
1849 if ((data
->len
= get_mouse_status(sc
->kbdc
, data
->buf
,
1850 (ap
->a_cmd
== MOUSE_READDATA
) ? 1 : 0, data
->len
)) <= 0)
1852 unblock_mouse_data(sc
, command_byte
);
1855 #if (defined(MOUSE_SETRESOLUTION))
1856 case MOUSE_SETRESOLUTION
:
1857 mode
.resolution
= *(int *)addr
;
1858 if (mode
.resolution
>= UCHAR_MAX
)
1860 else if (mode
.resolution
>= 200)
1861 mode
.resolution
= MOUSE_RES_HIGH
;
1862 else if (mode
.resolution
>= 100)
1863 mode
.resolution
= MOUSE_RES_MEDIUMHIGH
;
1864 else if (mode
.resolution
>= 50)
1865 mode
.resolution
= MOUSE_RES_MEDIUMLOW
;
1866 else if (mode
.resolution
> 0)
1867 mode
.resolution
= MOUSE_RES_LOW
;
1868 if (mode
.resolution
== MOUSE_RES_DEFAULT
)
1869 mode
.resolution
= sc
->dflt_mode
.resolution
;
1870 else if (mode
.resolution
== -1)
1871 mode
.resolution
= sc
->mode
.resolution
;
1872 else if (mode
.resolution
< 0) /* MOUSE_RES_LOW/MEDIUM/HIGH */
1873 mode
.resolution
= MOUSE_RES_LOW
- mode
.resolution
;
1875 error
= block_mouse_data(sc
, &command_byte
);
1878 sc
->mode
.resolution
= set_mouse_resolution(sc
->kbdc
, mode
.resolution
);
1879 if (sc
->mode
.resolution
!= mode
.resolution
)
1881 unblock_mouse_data(sc
, command_byte
);
1883 #endif /* MOUSE_SETRESOLUTION */
1885 #if (defined(MOUSE_SETRATE))
1887 mode
.rate
= *(int *)addr
;
1888 if (mode
.rate
> UCHAR_MAX
)
1891 mode
.rate
= sc
->dflt_mode
.rate
;
1892 else if (mode
.rate
< 0)
1893 mode
.rate
= sc
->mode
.rate
;
1895 error
= block_mouse_data(sc
, &command_byte
);
1898 sc
->mode
.rate
= set_mouse_sampling_rate(sc
->kbdc
, mode
.rate
);
1899 if (sc
->mode
.rate
!= mode
.rate
)
1901 unblock_mouse_data(sc
, command_byte
);
1903 #endif /* MOUSE_SETRATE */
1905 #if (defined(MOUSE_SETSCALING))
1906 case MOUSE_SETSCALING
:
1907 if ((*(int *)addr
<= 0) || (*(int *)addr
> 2))
1910 error
= block_mouse_data(sc
, &command_byte
);
1913 if (!set_mouse_scaling(sc
->kbdc
, *(int *)addr
))
1915 unblock_mouse_data(sc
, command_byte
);
1917 #endif /* MOUSE_SETSCALING */
1919 #if (defined(MOUSE_GETHWID))
1921 error
= block_mouse_data(sc
, &command_byte
);
1924 sc
->hw
.hwid
&= ~0x00ff;
1925 sc
->hw
.hwid
|= get_aux_id(sc
->kbdc
);
1926 *(int *)addr
= sc
->hw
.hwid
& 0x00ff;
1927 unblock_mouse_data(sc
, command_byte
);
1929 #endif /* MOUSE_GETHWID */
1939 psmtimeout(void *arg
)
1941 struct psm_softc
*sc
;
1943 sc
= (struct psm_softc
*)arg
;
1945 if (sc
->watchdog
&& kbdc_lock(sc
->kbdc
, TRUE
)) {
1947 log(LOG_DEBUG
, "psm%d: lost interrupt?\n", sc
->unit
);
1949 kbdc_lock(sc
->kbdc
, FALSE
);
1951 sc
->watchdog
= TRUE
;
1952 callout_reset(&sc
->callout
, hz
, psmtimeout
, (void *)(uintptr_t)sc
);
1960 * the table to turn PS/2 mouse button bits (MOUSE_PS2_BUTTON?DOWN)
1961 * into `mousestatus' button bits (MOUSE_BUTTON?DOWN).
1963 static int butmap
[8] = {
1967 MOUSE_BUTTON1DOWN
| MOUSE_BUTTON3DOWN
,
1969 MOUSE_BUTTON1DOWN
| MOUSE_BUTTON2DOWN
,
1970 MOUSE_BUTTON2DOWN
| MOUSE_BUTTON3DOWN
,
1971 MOUSE_BUTTON1DOWN
| MOUSE_BUTTON2DOWN
| MOUSE_BUTTON3DOWN
1973 static int butmap_versapad
[8] = {
1979 MOUSE_BUTTON1DOWN
| MOUSE_BUTTON3DOWN
,
1981 MOUSE_BUTTON1DOWN
| MOUSE_BUTTON3DOWN
1983 struct psm_softc
*sc
= arg
;
1991 /* read until there is nothing to read */
1992 while((c
= read_aux_data_no_wait(sc
->kbdc
)) != -1) {
1994 /* discard the byte if the device is not open */
1995 if ((sc
->state
& PSM_OPEN
) == 0)
1998 getmicrouptime(&tv
);
1999 if ((sc
->inputbytes
> 0) && timevalcmp(&tv
, &sc
->inputtimeout
, >)) {
2000 log(LOG_DEBUG
, "psmintr: delay too long; resetting byte count\n");
2004 sc
->inputtimeout
.tv_sec
= PSM_INPUT_TIMEOUT
/1000000;
2005 sc
->inputtimeout
.tv_usec
= PSM_INPUT_TIMEOUT
%1000000;
2006 timevaladd(&sc
->inputtimeout
, &tv
);
2008 sc
->ipacket
[sc
->inputbytes
++] = c
;
2009 if (sc
->inputbytes
< sc
->mode
.packetsize
)
2013 log(LOG_DEBUG
, "psmintr: %02x %02x %02x %02x %02x %02x\n",
2014 sc
->ipacket
[0], sc
->ipacket
[1], sc
->ipacket
[2],
2015 sc
->ipacket
[3], sc
->ipacket
[4], sc
->ipacket
[5]);
2020 if ((c
& sc
->mode
.syncmask
[0]) != sc
->mode
.syncmask
[1]) {
2021 log(LOG_DEBUG
, "psmintr: out of sync (%04x != %04x).\n",
2022 c
& sc
->mode
.syncmask
[0], sc
->mode
.syncmask
[1]);
2024 if (sc
->syncerrors
< sc
->mode
.packetsize
) {
2025 log(LOG_DEBUG
, "psmintr: discard a byte (%d).\n", sc
->syncerrors
);
2027 bcopy(&sc
->ipacket
[1], &sc
->ipacket
[0], sc
->inputbytes
);
2028 } else if (sc
->syncerrors
== sc
->mode
.packetsize
) {
2029 log(LOG_DEBUG
, "psmintr: re-enable the mouse.\n");
2031 disable_aux_dev(sc
->kbdc
);
2032 enable_aux_dev(sc
->kbdc
);
2033 } else if (sc
->syncerrors
< PSM_SYNCERR_THRESHOLD1
) {
2034 log(LOG_DEBUG
, "psmintr: discard a byte (%d).\n", sc
->syncerrors
);
2036 bcopy(&sc
->ipacket
[1], &sc
->ipacket
[0], sc
->inputbytes
);
2037 } else if (sc
->syncerrors
>= PSM_SYNCERR_THRESHOLD1
) {
2038 log(LOG_DEBUG
, "psmintr: reset the mouse.\n");
2039 reinitialize(sc
, TRUE
);
2045 * A kludge for Kensington device!
2046 * The MSB of the horizontal count appears to be stored in
2049 if (sc
->hw
.model
== MOUSE_MODEL_THINK
)
2050 sc
->ipacket
[1] |= (c
& MOUSE_PS2_XOVERFLOW
) ? 0x80 : 0;
2052 /* ignore the overflow bits... */
2053 x
= (c
& MOUSE_PS2_XNEG
) ? sc
->ipacket
[1] - 256 : sc
->ipacket
[1];
2054 y
= (c
& MOUSE_PS2_YNEG
) ? sc
->ipacket
[2] - 256 : sc
->ipacket
[2];
2056 ms
.obutton
= sc
->button
; /* previous button state */
2057 ms
.button
= butmap
[c
& MOUSE_PS2_BUTTONS
];
2058 /* `tapping' action */
2059 if (sc
->config
& PSM_CONFIG_FORCETAP
)
2060 ms
.button
|= ((c
& MOUSE_PS2_TAP
)) ? 0 : MOUSE_BUTTON4DOWN
;
2062 switch (sc
->hw
.model
) {
2064 case MOUSE_MODEL_EXPLORER
:
2066 * b7 b6 b5 b4 b3 b2 b1 b0
2067 * byte 1: oy ox sy sx 1 M R L
2068 * byte 2: x x x x x x x x
2069 * byte 3: y y y y y y y y
2070 * byte 4: * * S2 S1 s d2 d1 d0
2072 * L, M, R, S1, S2: left, middle, right and side buttons
2073 * s: wheel data sign bit
2076 z
= (sc
->ipacket
[3] & MOUSE_EXPLORER_ZNEG
)
2077 ? (sc
->ipacket
[3] & 0x0f) - 16 : (sc
->ipacket
[3] & 0x0f);
2078 ms
.button
|= (sc
->ipacket
[3] & MOUSE_EXPLORER_BUTTON4DOWN
)
2079 ? MOUSE_BUTTON4DOWN
: 0;
2080 ms
.button
|= (sc
->ipacket
[3] & MOUSE_EXPLORER_BUTTON5DOWN
)
2081 ? MOUSE_BUTTON5DOWN
: 0;
2084 case MOUSE_MODEL_INTELLI
:
2085 case MOUSE_MODEL_NET
:
2086 /* wheel data is in the fourth byte */
2087 z
= (char)sc
->ipacket
[3];
2088 /* some mice may send 7 when there is no Z movement?! XXX */
2089 if ((z
>= 7) || (z
<= -7))
2091 /* some compatible mice have additional buttons */
2092 ms
.button
|= (c
& MOUSE_PS2INTELLI_BUTTON4DOWN
)
2093 ? MOUSE_BUTTON4DOWN
: 0;
2094 ms
.button
|= (c
& MOUSE_PS2INTELLI_BUTTON5DOWN
)
2095 ? MOUSE_BUTTON5DOWN
: 0;
2098 case MOUSE_MODEL_MOUSEMANPLUS
:
2100 * PS2++ protocl packet
2102 * b7 b6 b5 b4 b3 b2 b1 b0
2103 * byte 1: * 1 p3 p2 1 * * *
2104 * byte 2: c1 c2 p1 p0 d1 d0 1 0
2106 * p3-p0: packet type
2107 * c1, c2: c1 & c2 == 1, if p2 == 0
2108 * c1 & c2 == 0, if p2 == 1
2110 * packet type: 0 (device type)
2111 * See comments in enable_mmanplus() below.
2113 * packet type: 1 (wheel data)
2115 * b7 b6 b5 b4 b3 b2 b1 b0
2116 * byte 3: h * B5 B4 s d2 d1 d0
2118 * h: 1, if horizontal roller data
2119 * 0, if vertical roller data
2120 * B4, B5: button 4 and 5
2122 * d2-d0: roller data
2124 * packet type: 2 (reserved)
2126 if (((c
& MOUSE_PS2PLUS_SYNCMASK
) == MOUSE_PS2PLUS_SYNC
)
2128 && MOUSE_PS2PLUS_CHECKBITS(sc
->ipacket
)) {
2129 /* the extended data packet encodes button and wheel events */
2130 switch (MOUSE_PS2PLUS_PACKET_TYPE(sc
->ipacket
)) {
2132 /* wheel data packet */
2134 if (sc
->ipacket
[2] & 0x80) {
2135 /* horizontal roller count - ignore it XXX*/
2137 /* vertical roller count */
2138 z
= (sc
->ipacket
[2] & MOUSE_PS2PLUS_ZNEG
)
2139 ? (sc
->ipacket
[2] & 0x0f) - 16
2140 : (sc
->ipacket
[2] & 0x0f);
2142 ms
.button
|= (sc
->ipacket
[2] & MOUSE_PS2PLUS_BUTTON4DOWN
)
2143 ? MOUSE_BUTTON4DOWN
: 0;
2144 ms
.button
|= (sc
->ipacket
[2] & MOUSE_PS2PLUS_BUTTON5DOWN
)
2145 ? MOUSE_BUTTON5DOWN
: 0;
2148 /* this packet type is reserved by Logitech... */
2150 * IBM ScrollPoint Mouse uses this packet type to
2151 * encode both vertical and horizontal scroll movement.
2154 /* horizontal count */
2155 if (sc
->ipacket
[2] & 0x0f)
2156 z
= (sc
->ipacket
[2] & MOUSE_SPOINT_WNEG
) ? -2 : 2;
2157 /* vertical count */
2158 if (sc
->ipacket
[2] & 0xf0)
2159 z
= (sc
->ipacket
[2] & MOUSE_SPOINT_ZNEG
) ? -1 : 1;
2161 /* vertical count */
2162 z
= (sc
->ipacket
[2] & MOUSE_SPOINT_ZNEG
)
2163 ? ((sc
->ipacket
[2] >> 4) & 0x0f) - 16
2164 : ((sc
->ipacket
[2] >> 4) & 0x0f);
2165 /* horizontal count */
2166 w
= (sc
->ipacket
[2] & MOUSE_SPOINT_WNEG
)
2167 ? (sc
->ipacket
[2] & 0x0f) - 16
2168 : (sc
->ipacket
[2] & 0x0f);
2172 /* device type packet - shouldn't happen */
2176 ms
.button
= ms
.obutton
;
2178 log(LOG_DEBUG
, "psmintr: unknown PS2++ packet type %d: "
2179 "0x%02x 0x%02x 0x%02x\n",
2180 MOUSE_PS2PLUS_PACKET_TYPE(sc
->ipacket
),
2181 sc
->ipacket
[0], sc
->ipacket
[1], sc
->ipacket
[2]);
2185 /* preserve button states */
2186 ms
.button
|= ms
.obutton
& MOUSE_EXTBUTTONS
;
2190 case MOUSE_MODEL_GLIDEPOINT
:
2191 /* `tapping' action */
2192 ms
.button
|= ((c
& MOUSE_PS2_TAP
)) ? 0 : MOUSE_BUTTON4DOWN
;
2195 case MOUSE_MODEL_NETSCROLL
:
2196 /* three addtional bytes encode buttons and wheel events */
2197 ms
.button
|= (sc
->ipacket
[3] & MOUSE_PS2_BUTTON3DOWN
)
2198 ? MOUSE_BUTTON4DOWN
: 0;
2199 ms
.button
|= (sc
->ipacket
[3] & MOUSE_PS2_BUTTON1DOWN
)
2200 ? MOUSE_BUTTON5DOWN
: 0;
2201 z
= (sc
->ipacket
[3] & MOUSE_PS2_XNEG
)
2202 ? sc
->ipacket
[4] - 256 : sc
->ipacket
[4];
2205 case MOUSE_MODEL_THINK
:
2206 /* the fourth button state in the first byte */
2207 ms
.button
|= (c
& MOUSE_PS2_TAP
) ? MOUSE_BUTTON4DOWN
: 0;
2210 case MOUSE_MODEL_VERSAPAD
:
2211 /* VersaPad PS/2 absolute mode message format
2213 * [packet1] 7 6 5 4 3 2 1 0(LSB)
2214 * ipacket[0]: 1 1 0 A 1 L T R
2215 * ipacket[1]: H7 H6 H5 H4 H3 H2 H1 H0
2216 * ipacket[2]: V7 V6 V5 V4 V3 V2 V1 V0
2217 * ipacket[3]: 1 1 1 A 1 L T R
2218 * ipacket[4]:V11 V10 V9 V8 H11 H10 H9 H8
2219 * ipacket[5]: 0 P6 P5 P4 P3 P2 P1 P0
2222 * R: right physical mouse button (1=on)
2223 * T: touch pad virtual button (1=tapping)
2224 * L: left physical mouse button (1=on)
2225 * A: position data is valid (1=valid)
2226 * H: horizontal data (12bit signed integer. H11 is sign bit.)
2227 * V: vertical data (12bit signed integer. V11 is sign bit.)
2230 * Tapping is mapped to MOUSE_BUTTON4.
2232 ms
.button
= butmap_versapad
[c
& MOUSE_PS2VERSA_BUTTONS
];
2233 ms
.button
|= (c
& MOUSE_PS2VERSA_TAP
) ? MOUSE_BUTTON4DOWN
: 0;
2235 if (c
& MOUSE_PS2VERSA_IN_USE
) {
2236 x0
= sc
->ipacket
[1] | (((sc
->ipacket
[4]) & 0x0f) << 8);
2237 y0
= sc
->ipacket
[2] | (((sc
->ipacket
[4]) & 0xf0) << 4);
2242 if (sc
->flags
& PSM_FLAGS_FINGERDOWN
) {
2245 if (x
< 0) /* XXX */
2254 sc
->flags
|= PSM_FLAGS_FINGERDOWN
;
2259 sc
->flags
&= ~PSM_FLAGS_FINGERDOWN
;
2261 c
= ((x
< 0) ? MOUSE_PS2_XNEG
: 0)
2262 | ((y
< 0) ? MOUSE_PS2_YNEG
: 0);
2265 case MOUSE_MODEL_4D
:
2267 * b7 b6 b5 b4 b3 b2 b1 b0
2268 * byte 1: s2 d2 s1 d1 1 M R L
2269 * byte 2: sx x x x x x x x
2270 * byte 3: sy y y y y y y y
2272 * s1: wheel 1 direction
2274 * s2: wheel 2 direction
2277 x
= (sc
->ipacket
[1] & 0x80) ? sc
->ipacket
[1] - 256 : sc
->ipacket
[1];
2278 y
= (sc
->ipacket
[2] & 0x80) ? sc
->ipacket
[2] - 256 : sc
->ipacket
[2];
2279 switch (c
& MOUSE_4D_WHEELBITS
) {
2286 case 0x40: /* 2nd wheel turning right XXX */
2289 case 0xc0: /* 2nd wheel turning left XXX */
2295 case MOUSE_MODEL_4DPLUS
:
2296 if ((x
< 16 - 256) && (y
< 16 - 256)) {
2298 * b7 b6 b5 b4 b3 b2 b1 b0
2299 * byte 1: 0 0 1 1 1 M R L
2300 * byte 2: 0 0 0 0 1 0 0 0
2301 * byte 3: 0 0 0 0 S s d1 d0
2303 * L, M, R, S: left, middle, right and side buttons
2304 * s: wheel data sign bit
2308 if (sc
->ipacket
[2] & MOUSE_4DPLUS_BUTTON4DOWN
)
2309 ms
.button
|= MOUSE_BUTTON4DOWN
;
2310 z
= (sc
->ipacket
[2] & MOUSE_4DPLUS_ZNEG
)
2311 ? ((sc
->ipacket
[2] & 0x07) - 8)
2312 : (sc
->ipacket
[2] & 0x07) ;
2314 /* preserve previous button states */
2315 ms
.button
|= ms
.obutton
& MOUSE_EXTBUTTONS
;
2319 case MOUSE_MODEL_GENERIC
:
2325 if (sc
->mode
.accelfactor
>= 1) {
2327 x
= x
* x
/ sc
->mode
.accelfactor
;
2330 if (c
& MOUSE_PS2_XNEG
)
2334 y
= y
* y
/ sc
->mode
.accelfactor
;
2337 if (c
& MOUSE_PS2_YNEG
)
2345 ms
.flags
= ((x
|| y
|| z
) ? MOUSE_POSCHANGED
: 0)
2346 | (ms
.obutton
^ ms
.button
);
2348 if (sc
->mode
.level
< PSM_LEVEL_NATIVE
)
2349 sc
->inputbytes
= tame_mouse(sc
, &ms
, sc
->ipacket
);
2351 sc
->status
.flags
|= ms
.flags
;
2352 sc
->status
.dx
+= ms
.dx
;
2353 sc
->status
.dy
+= ms
.dy
;
2354 sc
->status
.dz
+= ms
.dz
;
2355 sc
->status
.button
= ms
.button
;
2356 sc
->button
= ms
.button
;
2358 sc
->watchdog
= FALSE
;
2361 if (sc
->queue
.count
+ sc
->inputbytes
< sizeof(sc
->queue
.buf
)) {
2362 l
= min(sc
->inputbytes
, sizeof(sc
->queue
.buf
) - sc
->queue
.tail
);
2363 bcopy(&sc
->ipacket
[0], &sc
->queue
.buf
[sc
->queue
.tail
], l
);
2364 if (sc
->inputbytes
> l
)
2365 bcopy(&sc
->ipacket
[l
], &sc
->queue
.buf
[0], sc
->inputbytes
- l
);
2367 (sc
->queue
.tail
+ sc
->inputbytes
) % sizeof(sc
->queue
.buf
);
2368 sc
->queue
.count
+= sc
->inputbytes
;
2372 if (sc
->state
& PSM_ASLP
) {
2373 sc
->state
&= ~PSM_ASLP
;
2374 wakeup((caddr_t
) sc
);
2376 selwakeup(&sc
->rsel
);
2381 psmpoll(struct dev_poll_args
*ap
)
2383 cdev_t dev
= ap
->a_head
.a_dev
;
2384 struct psm_softc
*sc
= PSM_SOFTC(PSM_UNIT(dev
));
2387 /* Return true if a mouse event available */
2389 if (ap
->a_events
& (POLLIN
| POLLRDNORM
)) {
2390 if (sc
->queue
.count
> 0)
2391 revents
|= ap
->a_events
& (POLLIN
| POLLRDNORM
);
2393 selrecord(curthread
, &sc
->rsel
);
2396 ap
->a_events
= revents
;
2400 /* vendor/model specific routines */
2402 static int mouse_id_proc1(KBDC kbdc
, int res
, int scale
, int *status
)
2404 if (set_mouse_resolution(kbdc
, res
) != res
)
2406 if (set_mouse_scaling(kbdc
, scale
)
2407 && set_mouse_scaling(kbdc
, scale
)
2408 && set_mouse_scaling(kbdc
, scale
)
2409 && (get_mouse_status(kbdc
, status
, 0, 3) >= 3))
2415 mouse_ext_command(KBDC kbdc
, int command
)
2419 c
= (command
>> 6) & 0x03;
2420 if (set_mouse_resolution(kbdc
, c
) != c
)
2422 c
= (command
>> 4) & 0x03;
2423 if (set_mouse_resolution(kbdc
, c
) != c
)
2425 c
= (command
>> 2) & 0x03;
2426 if (set_mouse_resolution(kbdc
, c
) != c
)
2428 c
= (command
>> 0) & 0x03;
2429 if (set_mouse_resolution(kbdc
, c
) != c
)
2435 /* Logitech MouseMan Cordless II */
2437 enable_lcordless(struct psm_softc
*sc
)
2442 if (!mouse_id_proc1(sc
->kbdc
, PSMD_RES_HIGH
, 2, status
))
2444 if (status
[1] == PSMD_RES_HIGH
)
2446 ch
= (status
[0] & 0x07) - 1; /* channel # */
2447 if ((ch
<= 0) || (ch
> 4))
2450 * status[1]: always one?
2451 * status[2]: battery status? (0-100)
2457 /* Genius NetScroll Mouse, MouseSystems SmartScroll Mouse */
2459 enable_groller(struct psm_softc
*sc
)
2464 * The special sequence to enable the fourth button and the
2465 * roller. Immediately after this sequence check status bytes.
2466 * if the mouse is NetScroll, the second and the third bytes are
2471 * If the mouse is an ordinary PS/2 mouse, the status bytes should
2472 * look like the following.
2474 * byte 1 bit 7 always 0
2475 * bit 6 stream mode (0)
2476 * bit 5 disabled (0)
2477 * bit 4 1:1 scaling (0)
2479 * bit 0-2 button status
2480 * byte 2 resolution (PSMD_RES_HIGH)
2481 * byte 3 report rate (?)
2484 if (!mouse_id_proc1(sc
->kbdc
, PSMD_RES_HIGH
, 1, status
))
2486 if ((status
[1] != '3') || (status
[2] != 'D'))
2488 /* FIXME: SmartScroll Mouse has 5 buttons! XXX */
2493 /* Genius NetMouse/NetMouse Pro, ASCII Mie Mouse, NetScroll Optical */
2495 enable_gmouse(struct psm_softc
*sc
)
2500 * The special sequence to enable the middle, "rubber" button.
2501 * Immediately after this sequence check status bytes.
2502 * if the mouse is NetMouse, NetMouse Pro, or ASCII MIE Mouse,
2503 * the second and the third bytes are '3' and 'U'.
2504 * NOTE: NetMouse reports that it has three buttons although it has
2505 * two buttons and a rubber button. NetMouse Pro and MIE Mouse
2506 * say they have three buttons too and they do have a button on the
2509 if (!mouse_id_proc1(sc
->kbdc
, PSMD_RES_HIGH
, 1, status
))
2511 if ((status
[1] != '3') || (status
[2] != 'U'))
2516 /* ALPS GlidePoint */
2518 enable_aglide(struct psm_softc
*sc
)
2523 * The special sequence to obtain ALPS GlidePoint specific
2524 * information. Immediately after this sequence, status bytes will
2525 * contain something interesting.
2526 * NOTE: ALPS produces several models of GlidePoint. Some of those
2527 * do not respond to this sequence, thus, cannot be detected this way.
2529 if (set_mouse_sampling_rate(sc
->kbdc
, 100) != 100)
2531 if (!mouse_id_proc1(sc
->kbdc
, PSMD_RES_LOW
, 2, status
))
2533 if ((status
[1] == PSMD_RES_LOW
) || (status
[2] == 100))
2538 /* Kensington ThinkingMouse/Trackball */
2540 enable_kmouse(struct psm_softc
*sc
)
2542 static unsigned char rate
[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
2543 KBDC kbdc
= sc
->kbdc
;
2549 id1
= get_aux_id(kbdc
);
2550 if (set_mouse_sampling_rate(kbdc
, 10) != 10)
2553 * The device is now in the native mode? It returns a different
2556 id2
= get_aux_id(kbdc
);
2557 if ((id1
== id2
) || (id2
!= 2))
2560 if (set_mouse_resolution(kbdc
, PSMD_RES_LOW
) != PSMD_RES_LOW
)
2563 /* at this point, resolution is LOW, sampling rate is 10/sec */
2564 if (get_mouse_status(kbdc
, status
, 0, 3) < 3)
2569 * The special sequence to enable the third and fourth buttons.
2570 * Otherwise they behave like the first and second buttons.
2572 for (i
= 0; i
< sizeof(rate
)/sizeof(rate
[0]); ++i
) {
2573 if (set_mouse_sampling_rate(kbdc
, rate
[i
]) != rate
[i
])
2578 * At this point, the device is using default resolution and
2579 * sampling rate for the native mode.
2581 if (get_mouse_status(kbdc
, status
, 0, 3) < 3)
2583 if ((status
[1] == PSMD_RES_LOW
) || (status
[2] == rate
[i
- 1]))
2586 /* the device appears be enabled by this sequence, diable it for now */
2587 disable_aux_dev(kbdc
);
2588 empty_aux_buffer(kbdc
, 5);
2593 /* Logitech MouseMan+/FirstMouse+, IBM ScrollPoint Mouse */
2595 enable_mmanplus(struct psm_softc
*sc
)
2597 KBDC kbdc
= sc
->kbdc
;
2600 /* the special sequence to enable the fourth button and the roller. */
2602 * NOTE: for ScrollPoint to respond correctly, the SET_RESOLUTION
2603 * must be called exactly three times since the last RESET command
2604 * before this sequence. XXX
2606 if (!set_mouse_scaling(kbdc
, 1))
2608 if (!mouse_ext_command(kbdc
, 0x39) || !mouse_ext_command(kbdc
, 0xdb))
2610 if (get_mouse_status(kbdc
, data
, 1, 3) < 3)
2614 * PS2++ protocl, packet type 0
2616 * b7 b6 b5 b4 b3 b2 b1 b0
2617 * byte 1: * 1 p3 p2 1 * * *
2618 * byte 2: 1 1 p1 p0 m1 m0 1 0
2619 * byte 3: m7 m6 m5 m4 m3 m2 m1 m0
2621 * p3-p0: packet type: 0
2622 * m7-m0: model ID: MouseMan+:0x50, FirstMouse+:0x51, ScrollPoint:0x58...
2624 /* check constant bits */
2625 if ((data
[0] & MOUSE_PS2PLUS_SYNCMASK
) != MOUSE_PS2PLUS_SYNC
)
2627 if ((data
[1] & 0xc3) != 0xc2)
2629 /* check d3-d0 in byte 2 */
2630 if (!MOUSE_PS2PLUS_CHECKBITS(data
))
2633 if (MOUSE_PS2PLUS_PACKET_TYPE(data
) != 0)
2636 sc
->hw
.hwid
&= 0x00ff;
2637 sc
->hw
.hwid
|= data
[2] << 8; /* save model ID */
2640 * MouseMan+ (or FirstMouse+) is now in its native mode, in which
2641 * the wheel and the fourth button events are encoded in the
2642 * special data packet. The mouse may be put in the IntelliMouse mode
2643 * if it is initialized by the IntelliMouse's method.
2648 /* MS IntelliMouse Explorer */
2650 enable_msexplorer(struct psm_softc
*sc
)
2652 static unsigned char rate0
[] = { 200, 100, 80, };
2653 static unsigned char rate1
[] = { 200, 200, 80, };
2654 KBDC kbdc
= sc
->kbdc
;
2658 /* the special sequence to enable the extra buttons and the roller. */
2659 for (i
= 0; i
< sizeof(rate1
)/sizeof(rate1
[0]); ++i
) {
2660 if (set_mouse_sampling_rate(kbdc
, rate1
[i
]) != rate1
[i
])
2663 /* the device will give the genuine ID only after the above sequence */
2664 id
= get_aux_id(kbdc
);
2665 if (id
!= PSM_EXPLORER_ID
)
2669 sc
->hw
.buttons
= 5; /* IntelliMouse Explorer XXX */
2672 * XXX: this is a kludge to fool some KVM switch products
2673 * which think they are clever enough to know the 4-byte IntelliMouse
2674 * protocol, and assume any other protocols use 3-byte packets.
2675 * They don't convey 4-byte data packets from the IntelliMouse Explorer
2676 * correctly to the host computer because of this!
2677 * The following sequence is actually IntelliMouse's "wake up"
2678 * sequence; it will make the KVM think the mouse is IntelliMouse
2679 * when it is in fact IntelliMouse Explorer.
2681 for (i
= 0; i
< sizeof(rate0
)/sizeof(rate0
[0]); ++i
) {
2682 if (set_mouse_sampling_rate(kbdc
, rate0
[i
]) != rate0
[i
])
2685 id
= get_aux_id(kbdc
);
2690 /* MS IntelliMouse */
2692 enable_msintelli(struct psm_softc
*sc
)
2695 * Logitech MouseMan+ and FirstMouse+ will also respond to this
2696 * probe routine and act like IntelliMouse.
2699 static unsigned char rate
[] = { 200, 100, 80, };
2700 KBDC kbdc
= sc
->kbdc
;
2704 /* the special sequence to enable the third button and the roller. */
2705 for (i
= 0; i
< sizeof(rate
)/sizeof(rate
[0]); ++i
) {
2706 if (set_mouse_sampling_rate(kbdc
, rate
[i
]) != rate
[i
])
2709 /* the device will give the genuine ID only after the above sequence */
2710 id
= get_aux_id(kbdc
);
2711 if (id
!= PSM_INTELLI_ID
)
2720 /* A4 Tech 4D Mouse */
2722 enable_4dmouse(struct psm_softc
*sc
)
2725 * Newer wheel mice from A4 Tech may use the 4D+ protocol.
2728 static unsigned char rate
[] = { 200, 100, 80, 60, 40, 20 };
2729 KBDC kbdc
= sc
->kbdc
;
2733 for (i
= 0; i
< sizeof(rate
)/sizeof(rate
[0]); ++i
) {
2734 if (set_mouse_sampling_rate(kbdc
, rate
[i
]) != rate
[i
])
2737 id
= get_aux_id(kbdc
);
2739 * WinEasy 4D, 4 Way Scroll 4D: 6
2740 * Cable-Free 4D: 8 (4DPLUS)
2741 * WinBest 4D+, 4 Way Scroll 4D+: 8 (4DPLUS)
2743 if (id
!= PSM_4DMOUSE_ID
)
2747 sc
->hw
.buttons
= 3; /* XXX some 4D mice have 4? */
2752 /* A4 Tech 4D+ Mouse */
2754 enable_4dplus(struct psm_softc
*sc
)
2757 * Newer wheel mice from A4 Tech seem to use this protocol.
2758 * Older models are recognized as either 4D Mouse or IntelliMouse.
2760 KBDC kbdc
= sc
->kbdc
;
2764 * enable_4dmouse() already issued the following ID sequence...
2765 static unsigned char rate[] = { 200, 100, 80, 60, 40, 20 };
2768 for (i = 0; i < sizeof(rate)/sizeof(rate[0]); ++i) {
2769 if (set_mouse_sampling_rate(kbdc, rate[i]) != rate[i])
2774 id
= get_aux_id(kbdc
);
2775 if (id
!= PSM_4DPLUS_ID
)
2779 sc
->hw
.buttons
= 4; /* XXX */
2784 /* Interlink electronics VersaPad */
2786 enable_versapad(struct psm_softc
*sc
)
2788 KBDC kbdc
= sc
->kbdc
;
2791 set_mouse_resolution(kbdc
, PSMD_RES_MEDIUM_HIGH
); /* set res. 2 */
2792 set_mouse_sampling_rate(kbdc
, 100); /* set rate 100 */
2793 set_mouse_scaling(kbdc
, 1); /* set scale 1:1 */
2794 set_mouse_scaling(kbdc
, 1); /* set scale 1:1 */
2795 set_mouse_scaling(kbdc
, 1); /* set scale 1:1 */
2796 set_mouse_scaling(kbdc
, 1); /* set scale 1:1 */
2797 if (get_mouse_status(kbdc
, data
, 0, 3) < 3) /* get status */
2799 if (data
[2] != 0xa || data
[1] != 0 ) /* rate == 0xa && res. == 0 */
2801 set_mouse_scaling(kbdc
, 1); /* set scale 1:1 */
2803 sc
->config
|= PSM_CONFIG_HOOKRESUME
| PSM_CONFIG_INITAFTERSUSPEND
;
2805 return TRUE
; /* PS/2 absolute mode */
2809 psmresume(device_t dev
)
2811 struct psm_softc
*sc
= device_get_softc(dev
);
2812 int unit
= device_get_unit(dev
);
2816 log(LOG_NOTICE
, "psm%d: system resume hook called.\n", unit
);
2818 if (!(sc
->config
& PSM_CONFIG_HOOKRESUME
))
2821 err
= reinitialize(sc
, sc
->config
& PSM_CONFIG_INITAFTERSUSPEND
);
2823 if ((sc
->state
& PSM_ASLP
) && !(sc
->state
& PSM_VALID
)) {
2825 * Release the blocked process; it must be notified that the device
2826 * cannot be accessed anymore.
2828 sc
->state
&= ~PSM_ASLP
;
2829 wakeup((caddr_t
)sc
);
2833 log(LOG_DEBUG
, "psm%d: system resume hook exiting.\n", unit
);
2838 DRIVER_MODULE(psm
, atkbdc
, psm_driver
, psm_devclass
, 0, 0);