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/23 00: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/selinfo.h>
58 #include <sys/thread2.h>
60 #include <machine/clock.h>
61 #include <machine/mouse.h>
63 #include <bus/isa/isavar.h>
65 /* driver configuration flags (config) */
66 #define MSE_CONFIG_ACCEL 0x00f0 /* acceleration factor */
67 #define MSE_CONFIG_FLAGS (MSE_CONFIG_ACCEL)
70 * Software control structure for mouse. The sc_enablemouse(),
71 * sc_disablemouse() and sc_getmouse() routines must be called spl'd().
73 typedef struct mse_softc
{
76 struct selinfo sc_selp
;
77 struct resource
*sc_port
;
78 struct resource
*sc_intr
;
79 bus_space_tag_t sc_iot
;
80 bus_space_handle_t sc_ioh
;
82 void (*sc_enablemouse
) (bus_space_tag_t t
,
83 bus_space_handle_t h
);
84 void (*sc_disablemouse
) (bus_space_tag_t t
,
85 bus_space_handle_t h
);
86 void (*sc_getmouse
) (bus_space_tag_t t
,
88 int *dx
, int *dy
, int *but
);
94 u_char sc_bytes
[MOUSE_SYS_PACKETSIZE
];
95 struct callout sc_callout
;
102 static devclass_t mse_devclass
;
104 static int mse_probe (device_t dev
);
105 static int mse_attach (device_t dev
);
106 static int mse_detach (device_t dev
);
108 static device_method_t mse_methods
[] = {
109 DEVMETHOD(device_probe
, mse_probe
),
110 DEVMETHOD(device_attach
, mse_attach
),
111 DEVMETHOD(device_detach
, mse_detach
),
115 static driver_t mse_driver
= {
121 DRIVER_MODULE(mse
, isa
, mse_driver
, mse_devclass
, 0, 0);
123 static struct isa_pnp_id mse_ids
[] = {
124 { 0x000fd041, "Bus mouse" }, /* PNP0F00 */
125 { 0x020fd041, "InPort mouse" }, /* PNP0F02 */
126 { 0x0d0fd041, "InPort mouse compatible" }, /* PNP0F0D */
127 { 0x110fd041, "Bus mouse compatible" }, /* PNP0F11 */
128 { 0x150fd041, "Logitech bus mouse" }, /* PNP0F15 */
129 { 0x180fd041, "Logitech bus mouse compatible" },/* PNP0F18 */
133 static d_open_t mseopen
;
134 static d_close_t mseclose
;
135 static d_read_t mseread
;
136 static d_ioctl_t mseioctl
;
137 static d_poll_t msepoll
;
139 #define CDEV_MAJOR 27
140 static struct dev_ops mse_ops
= {
141 { "mse", CDEV_MAJOR
, 0 },
149 static void mseintr (void *);
150 static timeout_t msetimeout
;
153 #define MSESC_OPEN 0x1
154 #define MSESC_WANT 0x2
156 /* and Mouse Types */
157 #define MSE_NONE 0 /* don't move this! */
158 #define MSE_LOGITECH 0x1
159 #define MSE_ATIINPORT 0x2
160 #define MSE_LOGI_SIG 0xA5
168 #define MSE_UNIT(dev) (minor(dev) >> 1)
169 #define MSE_NBLOCKIO(dev) (minor(dev) & 0x1)
172 * Logitech bus mouse definitions
174 #define MSE_SETUP 0x91 /* What does this mean? */
175 /* The definition for the control port */
178 /* D7 = Mode set flag (1 = active) */
179 /* D6,D5 = Mode selection (port A) */
180 /* 00 = Mode 0 = Basic I/O */
181 /* 01 = Mode 1 = Strobed I/O */
182 /* 10 = Mode 2 = Bi-dir bus */
183 /* D4 = Port A direction (1 = input)*/
184 /* D3 = Port C (upper 4 bits) */
185 /* direction. (1 = input) */
186 /* D2 = Mode selection (port B & C) */
187 /* 0 = Mode 0 = Basic I/O */
188 /* 1 = Mode 1 = Strobed I/O */
189 /* D1 = Port B direction (1 = input)*/
190 /* D0 = Port C (lower 4 bits) */
191 /* direction. (1 = input) */
193 /* So 91 means Basic I/O on all 3 ports,*/
194 /* Port A is an input port, B is an */
195 /* output port, C is split with upper */
196 /* 4 bits being an output port and lower*/
197 /* 4 bits an input port, and enable the */
199 /* Courtesy Intel 8255 databook. Lars */
200 #define MSE_HOLD 0x80
201 #define MSE_RXLOW 0x00
202 #define MSE_RXHIGH 0x20
203 #define MSE_RYLOW 0x40
204 #define MSE_RYHIGH 0x60
205 #define MSE_DISINTR 0x10
206 #define MSE_INTREN 0x00
208 static int mse_probelogi (device_t dev
, mse_softc_t
*sc
);
209 static void mse_disablelogi (bus_space_tag_t t
,
210 bus_space_handle_t h
);
211 static void mse_getlogi (bus_space_tag_t t
,
212 bus_space_handle_t h
,
213 int *dx
, int *dy
, int *but
);
214 static void mse_enablelogi (bus_space_tag_t t
,
215 bus_space_handle_t h
);
218 * ATI Inport mouse definitions
220 #define MSE_INPORT_RESET 0x80
221 #define MSE_INPORT_STATUS 0x00
222 #define MSE_INPORT_DX 0x01
223 #define MSE_INPORT_DY 0x02
224 #define MSE_INPORT_MODE 0x07
225 #define MSE_INPORT_HOLD 0x20
226 #define MSE_INPORT_INTREN 0x09
228 static int mse_probeati (device_t dev
, mse_softc_t
*sc
);
229 static void mse_enableati (bus_space_tag_t t
,
230 bus_space_handle_t h
);
231 static void mse_disableati (bus_space_tag_t t
,
232 bus_space_handle_t h
);
233 static void mse_getati (bus_space_tag_t t
,
234 bus_space_handle_t h
,
235 int *dx
, int *dy
, int *but
);
238 * Table of mouse types.
239 * Keep the Logitech last, since I haven't figured out how to probe it
240 * properly yet. (Someday I'll have the documentation.)
242 static struct mse_types
{
243 int m_type
; /* Type of bus mouse */
244 int (*m_probe
) (device_t dev
, mse_softc_t
*sc
);
245 /* Probe routine to test for it */
246 void (*m_enable
) (bus_space_tag_t t
, bus_space_handle_t h
);
248 void (*m_disable
) (bus_space_tag_t t
, bus_space_handle_t h
);
249 /* Disable interrupts routine */
250 void (*m_get
) (bus_space_tag_t t
, bus_space_handle_t h
,
251 int *dx
, int *dy
, int *but
);
252 /* and get mouse status */
253 mousehw_t m_hw
; /* buttons iftype type model hwid */
254 mousemode_t m_mode
; /* proto rate res accel level size mask */
257 mse_probeati
, mse_enableati
, mse_disableati
, mse_getati
,
258 { 2, MOUSE_IF_INPORT
, MOUSE_MOUSE
, MOUSE_MODEL_GENERIC
, 0, },
259 { MOUSE_PROTO_INPORT
, -1, -1, 0, 0, MOUSE_MSC_PACKETSIZE
,
260 { MOUSE_MSC_SYNCMASK
, MOUSE_MSC_SYNC
, }, }, },
262 mse_probelogi
, mse_enablelogi
, mse_disablelogi
, mse_getlogi
,
263 { 2, MOUSE_IF_BUS
, MOUSE_MOUSE
, MOUSE_MODEL_GENERIC
, 0, },
264 { MOUSE_PROTO_BUS
, -1, -1, 0, 0, MOUSE_MSC_PACKETSIZE
,
265 { MOUSE_MSC_SYNCMASK
, MOUSE_MSC_SYNC
, }, }, },
270 mse_probe(device_t dev
)
278 error
= ISA_PNP_PROBE(device_get_parent(dev
), dev
, mse_ids
);
282 sc
= device_get_softc(dev
);
284 sc
->sc_port
= bus_alloc_resource(dev
, SYS_RES_IOPORT
, &rid
, 0, ~0,
285 MSE_IOSIZE
, RF_ACTIVE
);
286 if (sc
->sc_port
== NULL
)
288 sc
->sc_iot
= rman_get_bustag(sc
->sc_port
);
289 sc
->sc_ioh
= rman_get_bushandle(sc
->sc_port
);
292 * Check for each mouse type in the table.
295 while (mse_types
[i
].m_type
) {
296 if ((*mse_types
[i
].m_probe
)(dev
, sc
)) {
297 sc
->sc_mousetype
= mse_types
[i
].m_type
;
298 sc
->sc_enablemouse
= mse_types
[i
].m_enable
;
299 sc
->sc_disablemouse
= mse_types
[i
].m_disable
;
300 sc
->sc_getmouse
= mse_types
[i
].m_get
;
301 sc
->hw
= mse_types
[i
].m_hw
;
302 sc
->mode
= mse_types
[i
].m_mode
;
303 bus_release_resource(dev
, SYS_RES_IOPORT
, rid
,
305 device_set_desc(dev
, "Bus/InPort Mouse");
310 bus_release_resource(dev
, SYS_RES_IOPORT
, rid
, sc
->sc_port
);
315 mse_attach(device_t dev
)
322 sc
= device_get_softc(dev
);
323 unit
= device_get_unit(dev
);
326 sc
->sc_port
= bus_alloc_resource(dev
, SYS_RES_IOPORT
, &rid
, 0, ~0,
327 MSE_IOSIZE
, RF_ACTIVE
);
328 if (sc
->sc_port
== NULL
)
330 sc
->sc_intr
= bus_alloc_resource(dev
, SYS_RES_IRQ
, &rid
, 0, ~0, 1,
332 if (sc
->sc_intr
== NULL
) {
333 bus_release_resource(dev
, SYS_RES_IOPORT
, rid
, sc
->sc_port
);
336 sc
->sc_iot
= rman_get_bustag(sc
->sc_port
);
337 sc
->sc_ioh
= rman_get_bushandle(sc
->sc_port
);
339 if (BUS_SETUP_INTR(device_get_parent(dev
), dev
, sc
->sc_intr
,
340 0, mseintr
, sc
, &sc
->sc_ih
, NULL
)) {
341 bus_release_resource(dev
, SYS_RES_IOPORT
, rid
, sc
->sc_port
);
342 bus_release_resource(dev
, SYS_RES_IRQ
, rid
, sc
->sc_intr
);
346 flags
= device_get_flags(dev
);
347 sc
->mode
.accelfactor
= (flags
& MSE_CONFIG_ACCEL
) >> 4;
348 callout_init(&sc
->sc_callout
);
350 dev_ops_add(&mse_ops
, ~1, unit
<< 1);
351 make_dev(&mse_ops
, unit
<< 1, 0, 0, 0600, "mse%d", unit
);
352 make_dev(&mse_ops
, (unit
<<1)+1, 0, 0, 0600, "nmse%d", unit
);
358 mse_detach(device_t dev
)
363 sc
= device_get_softc(dev
);
364 if (sc
->sc_flags
& MSESC_OPEN
)
368 BUS_TEARDOWN_INTR(device_get_parent(dev
), dev
, sc
->sc_intr
, sc
->sc_ih
);
369 bus_release_resource(dev
, SYS_RES_IRQ
, rid
, sc
->sc_intr
);
370 bus_release_resource(dev
, SYS_RES_IOPORT
, rid
, sc
->sc_port
);
371 dev_ops_remove(&mse_ops
, ~1, device_get_unit(dev
) << 1);
377 * Exclusive open the mouse, initialize it and enable interrupts.
380 mseopen(struct dev_open_args
*ap
)
382 cdev_t dev
= ap
->a_head
.a_dev
;
385 sc
= devclass_get_softc(mse_devclass
, MSE_UNIT(dev
));
388 if (sc
->sc_mousetype
== MSE_NONE
)
390 if (sc
->sc_flags
& MSESC_OPEN
)
392 sc
->sc_flags
|= MSESC_OPEN
;
393 sc
->sc_obuttons
= sc
->sc_buttons
= MOUSE_MSC_BUTTONS
;
394 sc
->sc_deltax
= sc
->sc_deltay
= 0;
395 sc
->sc_bytesread
= sc
->mode
.packetsize
= MOUSE_MSC_PACKETSIZE
;
396 sc
->sc_watchdog
= FALSE
;
397 callout_reset(&sc
->sc_callout
, hz
* 2, msetimeout
, dev
);
399 sc
->status
.flags
= 0;
400 sc
->status
.button
= sc
->status
.obutton
= 0;
401 sc
->status
.dx
= sc
->status
.dy
= sc
->status
.dz
= 0;
404 * Initialize mouse interface and enable interrupts.
407 (*sc
->sc_enablemouse
)(sc
->sc_iot
, sc
->sc_ioh
);
413 * mseclose: just turn off mouse innterrupts.
416 mseclose(struct dev_close_args
*ap
)
418 cdev_t dev
= ap
->a_head
.a_dev
;
419 mse_softc_t
*sc
= devclass_get_softc(mse_devclass
, MSE_UNIT(dev
));
422 callout_stop(&sc
->sc_callout
);
423 (*sc
->sc_disablemouse
)(sc
->sc_iot
, sc
->sc_ioh
);
424 sc
->sc_flags
&= ~MSESC_OPEN
;
430 * mseread: return mouse info using the MSC serial protocol, but without
431 * using bytes 4 and 5.
432 * (Yes this is cheesy, but it makes the X386 server happy, so...)
435 mseread(struct dev_read_args
*ap
)
437 cdev_t dev
= ap
->a_head
.a_dev
;
438 struct uio
*uio
= ap
->a_uio
;
439 mse_softc_t
*sc
= devclass_get_softc(mse_devclass
, MSE_UNIT(dev
));
443 * If there are no protocol bytes to be read, set up a new protocol
446 crit_enter(); /* XXX Should be its own spl, but where is imlXX() */
447 if (sc
->sc_bytesread
>= sc
->mode
.packetsize
) {
448 while (sc
->sc_deltax
== 0 && sc
->sc_deltay
== 0 &&
449 (sc
->sc_obuttons
^ sc
->sc_buttons
) == 0) {
450 if (MSE_NBLOCKIO(dev
)) {
454 sc
->sc_flags
|= MSESC_WANT
;
455 error
= tsleep((caddr_t
)sc
, PCATCH
, "mseread", 0);
463 * Generate protocol bytes.
464 * For some reason X386 expects 5 bytes but never uses
465 * the fourth or fifth?
467 sc
->sc_bytes
[0] = sc
->mode
.syncmask
[1]
468 | (sc
->sc_buttons
& ~sc
->mode
.syncmask
[0]);
469 if (sc
->sc_deltax
> 127)
471 if (sc
->sc_deltax
< -127)
472 sc
->sc_deltax
= -127;
473 sc
->sc_deltay
= -sc
->sc_deltay
; /* Otherwise mousey goes wrong way */
474 if (sc
->sc_deltay
> 127)
476 if (sc
->sc_deltay
< -127)
477 sc
->sc_deltay
= -127;
478 sc
->sc_bytes
[1] = sc
->sc_deltax
;
479 sc
->sc_bytes
[2] = sc
->sc_deltay
;
480 sc
->sc_bytes
[3] = sc
->sc_bytes
[4] = 0;
481 sc
->sc_bytes
[5] = sc
->sc_bytes
[6] = 0;
482 sc
->sc_bytes
[7] = MOUSE_SYS_EXTBUTTONS
;
483 sc
->sc_obuttons
= sc
->sc_buttons
;
484 sc
->sc_deltax
= sc
->sc_deltay
= 0;
485 sc
->sc_bytesread
= 0;
488 xfer
= min(uio
->uio_resid
, sc
->mode
.packetsize
- sc
->sc_bytesread
);
489 error
= uiomove(&sc
->sc_bytes
[sc
->sc_bytesread
], xfer
, uio
);
492 sc
->sc_bytesread
+= xfer
;
497 * mseioctl: process ioctl commands.
500 mseioctl(struct dev_ioctl_args
*ap
)
502 cdev_t dev
= ap
->a_head
.a_dev
;
503 caddr_t addr
= ap
->a_data
;
504 mse_softc_t
*sc
= devclass_get_softc(mse_devclass
, MSE_UNIT(dev
));
505 mousestatus_t status
;
509 case MOUSE_GETHWINFO
:
511 *(mousehw_t
*)addr
= sc
->hw
;
512 if (sc
->mode
.level
== 0)
513 ((mousehw_t
*)addr
)->model
= MOUSE_MODEL_GENERIC
;
519 *(mousemode_t
*)addr
= sc
->mode
;
520 switch (sc
->mode
.level
) {
524 ((mousemode_t
*)addr
)->protocol
= MOUSE_PROTO_SYSMOUSE
;
525 ((mousemode_t
*)addr
)->syncmask
[0] = MOUSE_SYS_SYNCMASK
;
526 ((mousemode_t
*)addr
)->syncmask
[1] = MOUSE_SYS_SYNC
;
533 switch (((mousemode_t
*)addr
)->level
) {
540 if (((mousemode_t
*)addr
)->accelfactor
< -1)
542 else if (((mousemode_t
*)addr
)->accelfactor
>= 0)
543 sc
->mode
.accelfactor
=
544 ((mousemode_t
*)addr
)->accelfactor
;
545 sc
->mode
.level
= ((mousemode_t
*)addr
)->level
;
546 switch (sc
->mode
.level
) {
548 sc
->sc_bytesread
= sc
->mode
.packetsize
549 = MOUSE_MSC_PACKETSIZE
;
552 sc
->sc_bytesread
= sc
->mode
.packetsize
553 = MOUSE_SYS_PACKETSIZE
;
559 *(int *)addr
= sc
->mode
.level
;
563 switch (*(int *)addr
) {
565 sc
->mode
.level
= *(int *)addr
;
566 sc
->sc_bytesread
= sc
->mode
.packetsize
567 = MOUSE_MSC_PACKETSIZE
;
570 sc
->mode
.level
= *(int *)addr
;
571 sc
->sc_bytesread
= sc
->mode
.packetsize
572 = MOUSE_SYS_PACKETSIZE
;
579 case MOUSE_GETSTATUS
:
582 sc
->status
.flags
= 0;
583 sc
->status
.obutton
= sc
->status
.button
;
584 sc
->status
.button
= 0;
589 *(mousestatus_t
*)addr
= status
;
592 case MOUSE_READSTATE
:
596 #if (defined(MOUSE_GETVARS))
609 * msepoll: check for mouse input to be processed.
612 msepoll(struct dev_poll_args
*ap
)
614 cdev_t dev
= ap
->a_head
.a_dev
;
615 mse_softc_t
*sc
= devclass_get_softc(mse_devclass
, MSE_UNIT(dev
));
619 if (ap
->a_events
& (POLLIN
| POLLRDNORM
)) {
620 if (sc
->sc_bytesread
!= sc
->mode
.packetsize
||
621 sc
->sc_deltax
!= 0 || sc
->sc_deltay
!= 0 ||
622 (sc
->sc_obuttons
^ sc
->sc_buttons
) != 0)
623 revents
|= ap
->a_events
& (POLLIN
| POLLRDNORM
);
626 * Since this is an exclusive open device, any previous
627 * proc pointer is trash now, so we can just assign it.
629 selrecord(curthread
, &sc
->sc_selp
);
633 ap
->a_events
= revents
;
638 * msetimeout: watchdog timer routine.
641 msetimeout(void *arg
)
647 sc
= devclass_get_softc(mse_devclass
, MSE_UNIT(dev
));
648 if (sc
->sc_watchdog
) {
650 kprintf("mse%d: lost interrupt?\n", MSE_UNIT(dev
));
653 sc
->sc_watchdog
= TRUE
;
654 callout_reset(&sc
->sc_callout
, hz
, msetimeout
, dev
);
658 * mseintr: update mouse status. sc_deltax and sc_deltay are accumulative.
664 * the table to turn MouseSystem button bits (MOUSE_MSC_BUTTON?UP)
665 * into `mousestatus' button bits (MOUSE_BUTTON?DOWN).
667 static int butmap
[8] = {
671 MOUSE_BUTTON2DOWN
| MOUSE_BUTTON3DOWN
,
673 MOUSE_BUTTON1DOWN
| MOUSE_BUTTON3DOWN
,
674 MOUSE_BUTTON1DOWN
| MOUSE_BUTTON2DOWN
,
675 MOUSE_BUTTON1DOWN
| MOUSE_BUTTON2DOWN
| MOUSE_BUTTON3DOWN
677 mse_softc_t
*sc
= arg
;
682 static int mse_intrcnt
= 0;
683 if((mse_intrcnt
++ % 10000) == 0)
684 kprintf("mseintr\n");
686 if ((sc
->sc_flags
& MSESC_OPEN
) == 0)
689 (*sc
->sc_getmouse
)(sc
->sc_iot
, sc
->sc_ioh
, &dx
, &dy
, &but
);
690 if (sc
->mode
.accelfactor
> 0) {
692 dx
= dx
* dx
/ sc
->mode
.accelfactor
;
698 dy
= dy
* dy
/ sc
->mode
.accelfactor
;
706 sc
->sc_buttons
= but
;
708 but
= butmap
[~but
& MOUSE_MSC_BUTTONS
];
711 sc
->status
.flags
|= ((dx
|| dy
) ? MOUSE_POSCHANGED
: 0)
712 | (sc
->status
.button
^ but
);
713 sc
->status
.button
= but
;
715 sc
->sc_watchdog
= FALSE
;
718 * If mouse state has changed, wake up anyone wanting to know.
720 if (sc
->sc_deltax
!= 0 || sc
->sc_deltay
!= 0 ||
721 (sc
->sc_obuttons
^ sc
->sc_buttons
) != 0) {
722 if (sc
->sc_flags
& MSESC_WANT
) {
723 sc
->sc_flags
&= ~MSESC_WANT
;
726 selwakeup(&sc
->sc_selp
);
731 * Routines for the Logitech mouse.
734 * Test for a Logitech bus mouse and return 1 if it is.
735 * (until I know how to use the signature port properly, just disable
736 * interrupts and return 1)
739 mse_probelogi(device_t dev
, mse_softc_t
*sc
)
744 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, MSE_PORTD
, MSE_SETUP
);
745 /* set the signature port */
746 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, MSE_PORTB
, MSE_LOGI_SIG
);
748 DELAY(30000); /* 30 ms delay */
749 sig
= bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, MSE_PORTB
) & 0xFF;
750 if (sig
== MSE_LOGI_SIG
) {
751 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, MSE_PORTC
,
756 device_printf(dev
, "wrong signature %x\n", sig
);
762 * Initialize Logitech mouse and enable interrupts.
765 mse_enablelogi(bus_space_tag_t tag
, bus_space_handle_t handle
)
769 bus_space_write_1(tag
, handle
, MSE_PORTD
, MSE_SETUP
);
770 mse_getlogi(tag
, handle
, &dx
, &dy
, &but
);
774 * Disable interrupts for Logitech mouse.
777 mse_disablelogi(bus_space_tag_t tag
, bus_space_handle_t handle
)
780 bus_space_write_1(tag
, handle
, MSE_PORTC
, MSE_DISINTR
);
784 * Get the current dx, dy and button up/down state.
787 mse_getlogi(bus_space_tag_t tag
, bus_space_handle_t handle
, int *dx
, int *dy
,
792 bus_space_write_1(tag
, handle
, MSE_PORTC
, MSE_HOLD
| MSE_RXLOW
);
793 x
= bus_space_read_1(tag
, handle
, MSE_PORTA
);
794 *but
= (x
>> 5) & MOUSE_MSC_BUTTONS
;
796 bus_space_write_1(tag
, handle
, MSE_PORTC
, MSE_HOLD
| MSE_RXHIGH
);
797 x
|= (bus_space_read_1(tag
, handle
, MSE_PORTA
) << 4);
798 bus_space_write_1(tag
, handle
, MSE_PORTC
, MSE_HOLD
| MSE_RYLOW
);
799 y
= (bus_space_read_1(tag
, handle
, MSE_PORTA
) & 0xf);
800 bus_space_write_1(tag
, handle
, MSE_PORTC
, MSE_HOLD
| MSE_RYHIGH
);
801 y
|= (bus_space_read_1(tag
, handle
, MSE_PORTA
) << 4);
804 bus_space_write_1(tag
, handle
, MSE_PORTC
, MSE_INTREN
);
808 * Routines for the ATI Inport bus mouse.
811 * Test for a ATI Inport bus mouse and return 1 if it is.
812 * (do not enable interrupts)
815 mse_probeati(device_t dev
, mse_softc_t
*sc
)
819 for (i
= 0; i
< 2; i
++)
820 if (bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, MSE_PORTC
) == 0xde)
826 * Initialize ATI Inport mouse and enable interrupts.
829 mse_enableati(bus_space_tag_t tag
, bus_space_handle_t handle
)
832 bus_space_write_1(tag
, handle
, MSE_PORTA
, MSE_INPORT_RESET
);
833 bus_space_write_1(tag
, handle
, MSE_PORTA
, MSE_INPORT_MODE
);
834 bus_space_write_1(tag
, handle
, MSE_PORTB
, MSE_INPORT_INTREN
);
838 * Disable interrupts for ATI Inport mouse.
841 mse_disableati(bus_space_tag_t tag
, bus_space_handle_t handle
)
844 bus_space_write_1(tag
, handle
, MSE_PORTA
, MSE_INPORT_MODE
);
845 bus_space_write_1(tag
, handle
, MSE_PORTB
, 0);
849 * Get current dx, dy and up/down button state.
852 mse_getati(bus_space_tag_t tag
, bus_space_handle_t handle
, int *dx
, int *dy
,
857 bus_space_write_1(tag
, handle
, MSE_PORTA
, MSE_INPORT_MODE
);
858 bus_space_write_1(tag
, handle
, MSE_PORTB
, MSE_INPORT_HOLD
);
859 bus_space_write_1(tag
, handle
, MSE_PORTA
, MSE_INPORT_STATUS
);
860 *but
= ~bus_space_read_1(tag
, handle
, MSE_PORTB
) & MOUSE_MSC_BUTTONS
;
861 bus_space_write_1(tag
, handle
, MSE_PORTA
, MSE_INPORT_DX
);
862 byte
= bus_space_read_1(tag
, handle
, MSE_PORTB
);
864 bus_space_write_1(tag
, handle
, MSE_PORTA
, MSE_INPORT_DY
);
865 byte
= bus_space_read_1(tag
, handle
, MSE_PORTB
);
867 bus_space_write_1(tag
, handle
, MSE_PORTA
, MSE_INPORT_MODE
);
868 bus_space_write_1(tag
, handle
, MSE_PORTB
, MSE_INPORT_INTREN
);