2 * Copyright 1992 by the University of Guelph
4 * Permission to use, copy and modify this
5 * software and its documentation for any purpose and without
6 * fee is hereby granted, provided that the above copyright
7 * notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting
10 * University of Guelph makes no representations about the suitability of
11 * this software for any purpose. It is provided "as is"
12 * without express or implied warranty.
14 * $FreeBSD: src/sys/i386/isa/mse.c,v 1.49.2.1 2000/03/20 13:58:47 yokota Exp $
15 * $DragonFly: src/sys/dev/misc/mse/mse.c,v 1.20 2006/12/22 23:26:17 swildner Exp $
18 * Driver for the Logitech and ATI Inport Bus mice for use with 386bsd and
19 * the X386 port, courtesy of
20 * Rick Macklem, rick@snowhite.cis.uoguelph.ca
21 * Caveats: The driver currently uses spltty(), but doesn't use any
22 * generic tty code. It could use splmse() (that only masks off the
23 * bus mouse interrupt, but that would require hacking in i386/isa/icu.s.
24 * (This may be worth the effort, since the Logitech generates 30/60
25 * interrupts/sec continuously while it is open.)
26 * NB: The ATI has NOT been tested yet!
30 * Modification history:
31 * Sep 6, 1994 -- Lars Fredriksen(fredriks@mcs.com)
32 * improved probe based on input from Logitech.
34 * Oct 19, 1992 -- E. Stark (stark@cs.sunysb.edu)
35 * fixes to make it work with Microsoft InPort busmouse
37 * Jan, 1993 -- E. Stark (stark@cs.sunysb.edu)
38 * added patches for new "select" interface
40 * May 4, 1993 -- E. Stark (stark@cs.sunysb.edu)
41 * changed position of some spl()'s in mseread
43 * October 8, 1993 -- E. Stark (stark@cs.sunysb.edu)
44 * limit maximum negative x/y value to -127 to work around XFree problem
45 * that causes spurious button pushes.
48 #include <sys/param.h>
49 #include <sys/systm.h>
51 #include <sys/device.h>
52 #include <sys/kernel.h>
55 #include <sys/event.h>
56 #include <sys/selinfo.h>
59 #include <sys/thread2.h>
61 #include <machine/clock.h>
62 #include <machine/mouse.h>
64 #include <bus/isa/isavar.h>
66 /* driver configuration flags (config) */
67 #define MSE_CONFIG_ACCEL 0x00f0 /* acceleration factor */
68 #define MSE_CONFIG_FLAGS (MSE_CONFIG_ACCEL)
71 * Software control structure for mouse. The sc_enablemouse(),
72 * sc_disablemouse() and sc_getmouse() routines must be called spl'd().
74 typedef struct mse_softc {
77 struct selinfo sc_selp;
78 struct resource *sc_port;
79 struct resource *sc_intr;
80 bus_space_tag_t sc_iot;
81 bus_space_handle_t sc_ioh;
83 void (*sc_enablemouse) (bus_space_tag_t t,
84 bus_space_handle_t h);
85 void (*sc_disablemouse) (bus_space_tag_t t,
86 bus_space_handle_t h);
87 void (*sc_getmouse) (bus_space_tag_t t,
89 int *dx, int *dy, int *but);
95 u_char sc_bytes[MOUSE_SYS_PACKETSIZE];
96 struct callout sc_callout;
100 mousestatus_t status;
103 static devclass_t mse_devclass;
105 static int mse_probe (device_t dev);
106 static int mse_attach (device_t dev);
107 static int mse_detach (device_t dev);
109 static device_method_t mse_methods[] = {
110 DEVMETHOD(device_probe, mse_probe),
111 DEVMETHOD(device_attach, mse_attach),
112 DEVMETHOD(device_detach, mse_detach),
116 static driver_t mse_driver = {
122 DRIVER_MODULE(mse, isa, mse_driver, mse_devclass, 0, 0);
124 static struct isa_pnp_id mse_ids[] = {
125 { 0x000fd041, "Bus mouse" }, /* PNP0F00 */
126 { 0x020fd041, "InPort mouse" }, /* PNP0F02 */
127 { 0x0d0fd041, "InPort mouse compatible" }, /* PNP0F0D */
128 { 0x110fd041, "Bus mouse compatible" }, /* PNP0F11 */
129 { 0x150fd041, "Logitech bus mouse" }, /* PNP0F15 */
130 { 0x180fd041, "Logitech bus mouse compatible" },/* PNP0F18 */
134 static d_open_t mseopen;
135 static d_close_t mseclose;
136 static d_read_t mseread;
137 static d_ioctl_t mseioctl;
138 static d_poll_t msepoll;
139 static d_kqfilter_t msekqfilter;
141 static void msefilter_detach(struct knote *);
142 static int msefilter(struct knote *, long);
144 #define CDEV_MAJOR 27
145 static struct dev_ops mse_ops = {
146 { "mse", CDEV_MAJOR, 0 },
152 .d_kqfilter = msekqfilter
155 static void mseintr (void *);
156 static timeout_t msetimeout;
159 #define MSESC_OPEN 0x1
160 #define MSESC_WANT 0x2
162 /* and Mouse Types */
163 #define MSE_NONE 0 /* don't move this! */
164 #define MSE_LOGITECH 0x1
165 #define MSE_ATIINPORT 0x2
166 #define MSE_LOGI_SIG 0xA5
174 #define MSE_UNIT(dev) (minor(dev) >> 1)
175 #define MSE_NBLOCKIO(dev) (minor(dev) & 0x1)
178 * Logitech bus mouse definitions
180 #define MSE_SETUP 0x91 /* What does this mean? */
181 /* The definition for the control port */
184 /* D7 = Mode set flag (1 = active) */
185 /* D6,D5 = Mode selection (port A) */
186 /* 00 = Mode 0 = Basic I/O */
187 /* 01 = Mode 1 = Strobed I/O */
188 /* 10 = Mode 2 = Bi-dir bus */
189 /* D4 = Port A direction (1 = input)*/
190 /* D3 = Port C (upper 4 bits) */
191 /* direction. (1 = input) */
192 /* D2 = Mode selection (port B & C) */
193 /* 0 = Mode 0 = Basic I/O */
194 /* 1 = Mode 1 = Strobed I/O */
195 /* D1 = Port B direction (1 = input)*/
196 /* D0 = Port C (lower 4 bits) */
197 /* direction. (1 = input) */
199 /* So 91 means Basic I/O on all 3 ports,*/
200 /* Port A is an input port, B is an */
201 /* output port, C is split with upper */
202 /* 4 bits being an output port and lower*/
203 /* 4 bits an input port, and enable the */
205 /* Courtesy Intel 8255 databook. Lars */
206 #define MSE_HOLD 0x80
207 #define MSE_RXLOW 0x00
208 #define MSE_RXHIGH 0x20
209 #define MSE_RYLOW 0x40
210 #define MSE_RYHIGH 0x60
211 #define MSE_DISINTR 0x10
212 #define MSE_INTREN 0x00
214 static int mse_probelogi (device_t dev, mse_softc_t *sc);
215 static void mse_disablelogi (bus_space_tag_t t,
216 bus_space_handle_t h);
217 static void mse_getlogi (bus_space_tag_t t,
218 bus_space_handle_t h,
219 int *dx, int *dy, int *but);
220 static void mse_enablelogi (bus_space_tag_t t,
221 bus_space_handle_t h);
224 * ATI Inport mouse definitions
226 #define MSE_INPORT_RESET 0x80
227 #define MSE_INPORT_STATUS 0x00
228 #define MSE_INPORT_DX 0x01
229 #define MSE_INPORT_DY 0x02
230 #define MSE_INPORT_MODE 0x07
231 #define MSE_INPORT_HOLD 0x20
232 #define MSE_INPORT_INTREN 0x09
234 static int mse_probeati (device_t dev, mse_softc_t *sc);
235 static void mse_enableati (bus_space_tag_t t,
236 bus_space_handle_t h);
237 static void mse_disableati (bus_space_tag_t t,
238 bus_space_handle_t h);
239 static void mse_getati (bus_space_tag_t t,
240 bus_space_handle_t h,
241 int *dx, int *dy, int *but);
244 * Table of mouse types.
245 * Keep the Logitech last, since I haven't figured out how to probe it
246 * properly yet. (Someday I'll have the documentation.)
248 static struct mse_types {
249 int m_type; /* Type of bus mouse */
250 int (*m_probe) (device_t dev, mse_softc_t *sc);
251 /* Probe routine to test for it */
252 void (*m_enable) (bus_space_tag_t t, bus_space_handle_t h);
254 void (*m_disable) (bus_space_tag_t t, bus_space_handle_t h);
255 /* Disable interrupts routine */
256 void (*m_get) (bus_space_tag_t t, bus_space_handle_t h,
257 int *dx, int *dy, int *but);
258 /* and get mouse status */
259 mousehw_t m_hw; /* buttons iftype type model hwid */
260 mousemode_t m_mode; /* proto rate res accel level size mask */
263 mse_probeati, mse_enableati, mse_disableati, mse_getati,
264 { 2, MOUSE_IF_INPORT, MOUSE_MOUSE, MOUSE_MODEL_GENERIC, 0, },
265 { MOUSE_PROTO_INPORT, -1, -1, 0, 0, MOUSE_MSC_PACKETSIZE,
266 { MOUSE_MSC_SYNCMASK, MOUSE_MSC_SYNC, }, }, },
268 mse_probelogi, mse_enablelogi, mse_disablelogi, mse_getlogi,
269 { 2, MOUSE_IF_BUS, MOUSE_MOUSE, MOUSE_MODEL_GENERIC, 0, },
270 { MOUSE_PROTO_BUS, -1, -1, 0, 0, MOUSE_MSC_PACKETSIZE,
271 { MOUSE_MSC_SYNCMASK, MOUSE_MSC_SYNC, }, }, },
276 mse_probe(device_t dev)
284 error = ISA_PNP_PROBE(device_get_parent(dev), dev, mse_ids);
288 sc = device_get_softc(dev);
290 sc->sc_port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
291 MSE_IOSIZE, RF_ACTIVE);
292 if (sc->sc_port == NULL)
294 sc->sc_iot = rman_get_bustag(sc->sc_port);
295 sc->sc_ioh = rman_get_bushandle(sc->sc_port);
298 * Check for each mouse type in the table.
301 while (mse_types[i].m_type) {
302 if ((*mse_types[i].m_probe)(dev, sc)) {
303 sc->sc_mousetype = mse_types[i].m_type;
304 sc->sc_enablemouse = mse_types[i].m_enable;
305 sc->sc_disablemouse = mse_types[i].m_disable;
306 sc->sc_getmouse = mse_types[i].m_get;
307 sc->hw = mse_types[i].m_hw;
308 sc->mode = mse_types[i].m_mode;
309 bus_release_resource(dev, SYS_RES_IOPORT, rid,
311 device_set_desc(dev, "Bus/InPort Mouse");
316 bus_release_resource(dev, SYS_RES_IOPORT, rid, sc->sc_port);
321 mse_attach(device_t dev)
328 sc = device_get_softc(dev);
329 unit = device_get_unit(dev);
332 sc->sc_port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
333 MSE_IOSIZE, RF_ACTIVE);
334 if (sc->sc_port == NULL)
336 sc->sc_intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
338 if (sc->sc_intr == NULL) {
339 bus_release_resource(dev, SYS_RES_IOPORT, rid, sc->sc_port);
342 sc->sc_iot = rman_get_bustag(sc->sc_port);
343 sc->sc_ioh = rman_get_bushandle(sc->sc_port);
345 if (BUS_SETUP_INTR(device_get_parent(dev), dev, sc->sc_intr,
346 0, mseintr, sc, &sc->sc_ih, NULL)) {
347 bus_release_resource(dev, SYS_RES_IOPORT, rid, sc->sc_port);
348 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->sc_intr);
352 flags = device_get_flags(dev);
353 sc->mode.accelfactor = (flags & MSE_CONFIG_ACCEL) >> 4;
354 callout_init(&sc->sc_callout);
356 make_dev(&mse_ops, unit << 1, 0, 0, 0600, "mse%d", unit);
357 make_dev(&mse_ops, (unit<<1)+1, 0, 0, 0600, "nmse%d", unit);
363 mse_detach(device_t dev)
368 sc = device_get_softc(dev);
369 if (sc->sc_flags & MSESC_OPEN)
373 BUS_TEARDOWN_INTR(device_get_parent(dev), dev, sc->sc_intr, sc->sc_ih);
374 bus_release_resource(dev, SYS_RES_IRQ, rid, sc->sc_intr);
375 bus_release_resource(dev, SYS_RES_IOPORT, rid, sc->sc_port);
376 dev_ops_remove_minor(&mse_ops, device_get_unit(dev) << 1);
382 * Exclusive open the mouse, initialize it and enable interrupts.
385 mseopen(struct dev_open_args *ap)
387 cdev_t dev = ap->a_head.a_dev;
390 sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
393 if (sc->sc_mousetype == MSE_NONE)
395 if (sc->sc_flags & MSESC_OPEN)
397 sc->sc_flags |= MSESC_OPEN;
398 sc->sc_obuttons = sc->sc_buttons = MOUSE_MSC_BUTTONS;
399 sc->sc_deltax = sc->sc_deltay = 0;
400 sc->sc_bytesread = sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
401 sc->sc_watchdog = FALSE;
402 callout_reset(&sc->sc_callout, hz * 2, msetimeout, dev);
404 sc->status.flags = 0;
405 sc->status.button = sc->status.obutton = 0;
406 sc->status.dx = sc->status.dy = sc->status.dz = 0;
409 * Initialize mouse interface and enable interrupts.
412 (*sc->sc_enablemouse)(sc->sc_iot, sc->sc_ioh);
418 * mseclose: just turn off mouse innterrupts.
421 mseclose(struct dev_close_args *ap)
423 cdev_t dev = ap->a_head.a_dev;
424 mse_softc_t *sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
427 callout_stop(&sc->sc_callout);
428 (*sc->sc_disablemouse)(sc->sc_iot, sc->sc_ioh);
429 sc->sc_flags &= ~MSESC_OPEN;
435 * mseread: return mouse info using the MSC serial protocol, but without
436 * using bytes 4 and 5.
437 * (Yes this is cheesy, but it makes the X386 server happy, so...)
440 mseread(struct dev_read_args *ap)
442 cdev_t dev = ap->a_head.a_dev;
443 struct uio *uio = ap->a_uio;
444 mse_softc_t *sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
448 * If there are no protocol bytes to be read, set up a new protocol
451 crit_enter(); /* XXX Should be its own spl, but where is imlXX() */
452 if (sc->sc_bytesread >= sc->mode.packetsize) {
453 while (sc->sc_deltax == 0 && sc->sc_deltay == 0 &&
454 (sc->sc_obuttons ^ sc->sc_buttons) == 0) {
455 if (MSE_NBLOCKIO(dev)) {
459 sc->sc_flags |= MSESC_WANT;
460 error = tsleep((caddr_t)sc, PCATCH, "mseread", 0);
468 * Generate protocol bytes.
469 * For some reason X386 expects 5 bytes but never uses
470 * the fourth or fifth?
472 sc->sc_bytes[0] = sc->mode.syncmask[1]
473 | (sc->sc_buttons & ~sc->mode.syncmask[0]);
474 if (sc->sc_deltax > 127)
476 if (sc->sc_deltax < -127)
477 sc->sc_deltax = -127;
478 sc->sc_deltay = -sc->sc_deltay; /* Otherwise mousey goes wrong way */
479 if (sc->sc_deltay > 127)
481 if (sc->sc_deltay < -127)
482 sc->sc_deltay = -127;
483 sc->sc_bytes[1] = sc->sc_deltax;
484 sc->sc_bytes[2] = sc->sc_deltay;
485 sc->sc_bytes[3] = sc->sc_bytes[4] = 0;
486 sc->sc_bytes[5] = sc->sc_bytes[6] = 0;
487 sc->sc_bytes[7] = MOUSE_SYS_EXTBUTTONS;
488 sc->sc_obuttons = sc->sc_buttons;
489 sc->sc_deltax = sc->sc_deltay = 0;
490 sc->sc_bytesread = 0;
493 xfer = (int)szmin(uio->uio_resid,
494 sc->mode.packetsize - sc->sc_bytesread);
495 error = uiomove(&sc->sc_bytes[sc->sc_bytesread], (size_t)xfer, uio);
498 sc->sc_bytesread += xfer;
503 * mseioctl: process ioctl commands.
506 mseioctl(struct dev_ioctl_args *ap)
508 cdev_t dev = ap->a_head.a_dev;
509 caddr_t addr = ap->a_data;
510 mse_softc_t *sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
511 mousestatus_t status;
515 case MOUSE_GETHWINFO:
517 *(mousehw_t *)addr = sc->hw;
518 if (sc->mode.level == 0)
519 ((mousehw_t *)addr)->model = MOUSE_MODEL_GENERIC;
525 *(mousemode_t *)addr = sc->mode;
526 switch (sc->mode.level) {
530 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_SYSMOUSE;
531 ((mousemode_t *)addr)->syncmask[0] = MOUSE_SYS_SYNCMASK;
532 ((mousemode_t *)addr)->syncmask[1] = MOUSE_SYS_SYNC;
539 switch (((mousemode_t *)addr)->level) {
546 if (((mousemode_t *)addr)->accelfactor < -1)
548 else if (((mousemode_t *)addr)->accelfactor >= 0)
549 sc->mode.accelfactor =
550 ((mousemode_t *)addr)->accelfactor;
551 sc->mode.level = ((mousemode_t *)addr)->level;
552 switch (sc->mode.level) {
554 sc->sc_bytesread = sc->mode.packetsize
555 = MOUSE_MSC_PACKETSIZE;
558 sc->sc_bytesread = sc->mode.packetsize
559 = MOUSE_SYS_PACKETSIZE;
565 *(int *)addr = sc->mode.level;
569 switch (*(int *)addr) {
571 sc->mode.level = *(int *)addr;
572 sc->sc_bytesread = sc->mode.packetsize
573 = MOUSE_MSC_PACKETSIZE;
576 sc->mode.level = *(int *)addr;
577 sc->sc_bytesread = sc->mode.packetsize
578 = MOUSE_SYS_PACKETSIZE;
585 case MOUSE_GETSTATUS:
588 sc->status.flags = 0;
589 sc->status.obutton = sc->status.button;
590 sc->status.button = 0;
595 *(mousestatus_t *)addr = status;
598 case MOUSE_READSTATE:
602 #if (defined(MOUSE_GETVARS))
615 * msepoll: check for mouse input to be processed.
618 msepoll(struct dev_poll_args *ap)
620 cdev_t dev = ap->a_head.a_dev;
621 mse_softc_t *sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
625 if (ap->a_events & (POLLIN | POLLRDNORM)) {
626 if (sc->sc_bytesread != sc->mode.packetsize ||
627 sc->sc_deltax != 0 || sc->sc_deltay != 0 ||
628 (sc->sc_obuttons ^ sc->sc_buttons) != 0)
629 revents |= ap->a_events & (POLLIN | POLLRDNORM);
632 * Since this is an exclusive open device, any previous
633 * proc pointer is trash now, so we can just assign it.
635 selrecord(curthread, &sc->sc_selp);
639 ap->a_events = revents;
643 static struct filterops msefiltops =
644 { 1, NULL, msefilter_detach, msefilter };
647 msekqfilter(struct dev_kqfilter_args *ap)
649 cdev_t dev = ap->a_head.a_dev;
650 mse_softc_t *sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
651 struct knote *kn = ap->a_kn;
656 switch (kn->kn_filter) {
658 kn->kn_fop = &msefiltops;
659 kn->kn_hook = (caddr_t)sc;
662 ap->a_result = EOPNOTSUPP;
667 klist = &sc->sc_selp.si_note;
668 SLIST_INSERT_HEAD(klist, kn, kn_selnext);
675 msefilter_detach(struct knote *kn)
677 mse_softc_t *sc = (mse_softc_t *)kn->kn_hook;
681 klist = &sc->sc_selp.si_note;
682 SLIST_REMOVE(klist, kn, knote, kn_selnext);
687 msefilter(struct knote *kn, long hint)
689 mse_softc_t *sc = (mse_softc_t *)kn->kn_hook;
693 if (sc->sc_bytesread != sc->mode.packetsize ||
694 sc->sc_deltax != 0 || sc->sc_deltay != 0 ||
695 (sc->sc_obuttons ^ sc->sc_buttons) != 0)
704 * msetimeout: watchdog timer routine.
707 msetimeout(void *arg)
713 sc = devclass_get_softc(mse_devclass, MSE_UNIT(dev));
714 if (sc->sc_watchdog) {
716 kprintf("mse%d: lost interrupt?\n", MSE_UNIT(dev));
719 sc->sc_watchdog = TRUE;
720 callout_reset(&sc->sc_callout, hz, msetimeout, dev);
724 * mseintr: update mouse status. sc_deltax and sc_deltay are accumulative.
730 * the table to turn MouseSystem button bits (MOUSE_MSC_BUTTON?UP)
731 * into `mousestatus' button bits (MOUSE_BUTTON?DOWN).
733 static int butmap[8] = {
737 MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN,
739 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN,
740 MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN,
741 MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN
743 mse_softc_t *sc = arg;
748 static int mse_intrcnt = 0;
749 if((mse_intrcnt++ % 10000) == 0)
750 kprintf("mseintr\n");
752 if ((sc->sc_flags & MSESC_OPEN) == 0)
755 (*sc->sc_getmouse)(sc->sc_iot, sc->sc_ioh, &dx, &dy, &but);
756 if (sc->mode.accelfactor > 0) {
758 dx = dx * dx / sc->mode.accelfactor;
764 dy = dy * dy / sc->mode.accelfactor;
772 sc->sc_buttons = but;
774 but = butmap[~but & MOUSE_MSC_BUTTONS];
777 sc->status.flags |= ((dx || dy) ? MOUSE_POSCHANGED : 0)
778 | (sc->status.button ^ but);
779 sc->status.button = but;
781 sc->sc_watchdog = FALSE;
784 * If mouse state has changed, wake up anyone wanting to know.
786 if (sc->sc_deltax != 0 || sc->sc_deltay != 0 ||
787 (sc->sc_obuttons ^ sc->sc_buttons) != 0) {
788 if (sc->sc_flags & MSESC_WANT) {
789 sc->sc_flags &= ~MSESC_WANT;
792 selwakeup(&sc->sc_selp);
797 * Routines for the Logitech mouse.
800 * Test for a Logitech bus mouse and return 1 if it is.
801 * (until I know how to use the signature port properly, just disable
802 * interrupts and return 1)
805 mse_probelogi(device_t dev, mse_softc_t *sc)
810 bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSE_PORTD, MSE_SETUP);
811 /* set the signature port */
812 bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSE_PORTB, MSE_LOGI_SIG);
814 DELAY(30000); /* 30 ms delay */
815 sig = bus_space_read_1(sc->sc_iot, sc->sc_ioh, MSE_PORTB) & 0xFF;
816 if (sig == MSE_LOGI_SIG) {
817 bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSE_PORTC,
822 device_printf(dev, "wrong signature %x\n", sig);
828 * Initialize Logitech mouse and enable interrupts.
831 mse_enablelogi(bus_space_tag_t tag, bus_space_handle_t handle)
835 bus_space_write_1(tag, handle, MSE_PORTD, MSE_SETUP);
836 mse_getlogi(tag, handle, &dx, &dy, &but);
840 * Disable interrupts for Logitech mouse.
843 mse_disablelogi(bus_space_tag_t tag, bus_space_handle_t handle)
846 bus_space_write_1(tag, handle, MSE_PORTC, MSE_DISINTR);
850 * Get the current dx, dy and button up/down state.
853 mse_getlogi(bus_space_tag_t tag, bus_space_handle_t handle, int *dx, int *dy,
858 bus_space_write_1(tag, handle, MSE_PORTC, MSE_HOLD | MSE_RXLOW);
859 x = bus_space_read_1(tag, handle, MSE_PORTA);
860 *but = (x >> 5) & MOUSE_MSC_BUTTONS;
862 bus_space_write_1(tag, handle, MSE_PORTC, MSE_HOLD | MSE_RXHIGH);
863 x |= (bus_space_read_1(tag, handle, MSE_PORTA) << 4);
864 bus_space_write_1(tag, handle, MSE_PORTC, MSE_HOLD | MSE_RYLOW);
865 y = (bus_space_read_1(tag, handle, MSE_PORTA) & 0xf);
866 bus_space_write_1(tag, handle, MSE_PORTC, MSE_HOLD | MSE_RYHIGH);
867 y |= (bus_space_read_1(tag, handle, MSE_PORTA) << 4);
870 bus_space_write_1(tag, handle, MSE_PORTC, MSE_INTREN);
874 * Routines for the ATI Inport bus mouse.
877 * Test for a ATI Inport bus mouse and return 1 if it is.
878 * (do not enable interrupts)
881 mse_probeati(device_t dev, mse_softc_t *sc)
885 for (i = 0; i < 2; i++)
886 if (bus_space_read_1(sc->sc_iot, sc->sc_ioh, MSE_PORTC) == 0xde)
892 * Initialize ATI Inport mouse and enable interrupts.
895 mse_enableati(bus_space_tag_t tag, bus_space_handle_t handle)
898 bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_RESET);
899 bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_MODE);
900 bus_space_write_1(tag, handle, MSE_PORTB, MSE_INPORT_INTREN);
904 * Disable interrupts for ATI Inport mouse.
907 mse_disableati(bus_space_tag_t tag, bus_space_handle_t handle)
910 bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_MODE);
911 bus_space_write_1(tag, handle, MSE_PORTB, 0);
915 * Get current dx, dy and up/down button state.
918 mse_getati(bus_space_tag_t tag, bus_space_handle_t handle, int *dx, int *dy,
923 bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_MODE);
924 bus_space_write_1(tag, handle, MSE_PORTB, MSE_INPORT_HOLD);
925 bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_STATUS);
926 *but = ~bus_space_read_1(tag, handle, MSE_PORTB) & MOUSE_MSC_BUTTONS;
927 bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_DX);
928 byte = bus_space_read_1(tag, handle, MSE_PORTB);
930 bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_DY);
931 byte = bus_space_read_1(tag, handle, MSE_PORTB);
933 bus_space_write_1(tag, handle, MSE_PORTA, MSE_INPORT_MODE);
934 bus_space_write_1(tag, handle, MSE_PORTB, MSE_INPORT_INTREN);