mse.c revision 56845
1/* 2 * Copyright 1992 by the University of Guelph 3 * 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 9 * documentation. 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. 13 * 14 * $FreeBSD: head/sys/dev/mse/mse.c 56845 2000-01-29 16:17:36Z peter $ 15 */ 16/* 17 * Driver for the Logitech and ATI Inport Bus mice for use with 386bsd and 18 * the X386 port, courtesy of 19 * Rick Macklem, rick@snowhite.cis.uoguelph.ca 20 * Caveats: The driver currently uses spltty(), but doesn't use any 21 * generic tty code. It could use splmse() (that only masks off the 22 * bus mouse interrupt, but that would require hacking in i386/isa/icu.s. 23 * (This may be worth the effort, since the Logitech generates 30/60 24 * interrupts/sec continuously while it is open.) 25 * NB: The ATI has NOT been tested yet! 26 */ 27 28/* 29 * Modification history: 30 * Sep 6, 1994 -- Lars Fredriksen(fredriks@mcs.com) 31 * improved probe based on input from Logitech. 32 * 33 * Oct 19, 1992 -- E. Stark (stark@cs.sunysb.edu) 34 * fixes to make it work with Microsoft InPort busmouse 35 * 36 * Jan, 1993 -- E. Stark (stark@cs.sunysb.edu) 37 * added patches for new "select" interface 38 * 39 * May 4, 1993 -- E. Stark (stark@cs.sunysb.edu) 40 * changed position of some spl()'s in mseread 41 * 42 * October 8, 1993 -- E. Stark (stark@cs.sunysb.edu) 43 * limit maximum negative x/y value to -127 to work around XFree problem 44 * that causes spurious button pushes. 45 */ 46 47#include "mse.h" 48#include <sys/param.h> 49#include <sys/systm.h> 50#include <sys/conf.h> 51#include <sys/kernel.h> 52#include <sys/poll.h> 53#include <sys/select.h> 54#include <sys/uio.h> 55 56#include <machine/clock.h> 57#include <machine/mouse.h> 58 59#include <i386/isa/isa_device.h> 60 61/* driver configuration flags (config) */ 62#define MSE_CONFIG_ACCEL 0x00f0 /* acceleration factor */ 63#define MSE_CONFIG_FLAGS (MSE_CONFIG_ACCEL) 64 65static int mseprobe(struct isa_device *); 66static int mseattach(struct isa_device *); 67 68struct isa_driver msedriver = { 69 mseprobe, mseattach, "mse" 70}; 71 72static d_open_t mseopen; 73static d_close_t mseclose; 74static d_read_t mseread; 75static d_ioctl_t mseioctl; 76static d_poll_t msepoll; 77 78#define CDEV_MAJOR 27 79static struct cdevsw mse_cdevsw = { 80 /* open */ mseopen, 81 /* close */ mseclose, 82 /* read */ mseread, 83 /* write */ nowrite, 84 /* ioctl */ mseioctl, 85 /* poll */ msepoll, 86 /* mmap */ nommap, 87 /* strategy */ nostrategy, 88 /* name */ "mse", 89 /* maj */ CDEV_MAJOR, 90 /* dump */ nodump, 91 /* psize */ nopsize, 92 /* flags */ 0, 93 /* bmaj */ -1 94}; 95 96static ointhand2_t mseintr; 97 98/* 99 * Software control structure for mouse. The sc_enablemouse(), 100 * sc_disablemouse() and sc_getmouse() routines must be called spl'd(). 101 */ 102static struct mse_softc { 103 int sc_flags; 104 int sc_mousetype; 105 struct selinfo sc_selp; 106 u_int sc_port; 107 void (*sc_enablemouse) __P((u_int port)); 108 void (*sc_disablemouse) __P((u_int port)); 109 void (*sc_getmouse) __P((u_int port, int *dx, int *dy, int *but)); 110 int sc_deltax; 111 int sc_deltay; 112 int sc_obuttons; 113 int sc_buttons; 114 int sc_bytesread; 115 u_char sc_bytes[MOUSE_SYS_PACKETSIZE]; 116 mousehw_t hw; 117 mousemode_t mode; 118 mousestatus_t status; 119} mse_sc[NMSE]; 120 121/* Flags */ 122#define MSESC_OPEN 0x1 123#define MSESC_WANT 0x2 124 125/* and Mouse Types */ 126#define MSE_NONE 0 /* don't move this! */ 127#define MSE_LOGITECH 0x1 128#define MSE_ATIINPORT 0x2 129#define MSE_LOGI_SIG 0xA5 130 131#define MSE_PORTA 0 132#define MSE_PORTB 1 133#define MSE_PORTC 2 134#define MSE_PORTD 3 135 136#define MSE_UNIT(dev) (minor(dev) >> 1) 137#define MSE_NBLOCKIO(dev) (minor(dev) & 0x1) 138 139/* 140 * Logitech bus mouse definitions 141 */ 142#define MSE_SETUP 0x91 /* What does this mean? */ 143 /* The definition for the control port */ 144 /* is as follows: */ 145 146 /* D7 = Mode set flag (1 = active) */ 147 /* D6,D5 = Mode selection (port A) */ 148 /* 00 = Mode 0 = Basic I/O */ 149 /* 01 = Mode 1 = Strobed I/O */ 150 /* 10 = Mode 2 = Bi-dir bus */ 151 /* D4 = Port A direction (1 = input)*/ 152 /* D3 = Port C (upper 4 bits) */ 153 /* direction. (1 = input) */ 154 /* D2 = Mode selection (port B & C) */ 155 /* 0 = Mode 0 = Basic I/O */ 156 /* 1 = Mode 1 = Strobed I/O */ 157 /* D1 = Port B direction (1 = input)*/ 158 /* D0 = Port C (lower 4 bits) */ 159 /* direction. (1 = input) */ 160 161 /* So 91 means Basic I/O on all 3 ports,*/ 162 /* Port A is an input port, B is an */ 163 /* output port, C is split with upper */ 164 /* 4 bits being an output port and lower*/ 165 /* 4 bits an input port, and enable the */ 166 /* sucker. */ 167 /* Courtesy Intel 8255 databook. Lars */ 168#define MSE_HOLD 0x80 169#define MSE_RXLOW 0x00 170#define MSE_RXHIGH 0x20 171#define MSE_RYLOW 0x40 172#define MSE_RYHIGH 0x60 173#define MSE_DISINTR 0x10 174#define MSE_INTREN 0x00 175 176static int mse_probelogi __P((struct isa_device *idp)); 177static void mse_disablelogi __P((u_int port)); 178static void mse_getlogi __P((u_int port, int *dx, int *dy, int *but)); 179static void mse_enablelogi __P((u_int port)); 180 181/* 182 * ATI Inport mouse definitions 183 */ 184#define MSE_INPORT_RESET 0x80 185#define MSE_INPORT_STATUS 0x00 186#define MSE_INPORT_DX 0x01 187#define MSE_INPORT_DY 0x02 188#define MSE_INPORT_MODE 0x07 189#define MSE_INPORT_HOLD 0x20 190#define MSE_INPORT_INTREN 0x09 191 192static int mse_probeati __P((struct isa_device *idp)); 193static void mse_enableati __P((u_int port)); 194static void mse_disableati __P((u_int port)); 195static void mse_getati __P((u_int port, int *dx, int *dy, int *but)); 196 197#define MSEPRI (PZERO + 3) 198 199/* 200 * Table of mouse types. 201 * Keep the Logitech last, since I haven't figured out how to probe it 202 * properly yet. (Someday I'll have the documentation.) 203 */ 204static struct mse_types { 205 int m_type; /* Type of bus mouse */ 206 int (*m_probe) __P((struct isa_device *idp)); 207 /* Probe routine to test for it */ 208 void (*m_enable) __P((u_int port)); 209 /* Start routine */ 210 void (*m_disable) __P((u_int port)); 211 /* Disable interrupts routine */ 212 void (*m_get) __P((u_int port, int *dx, int *dy, int *but)); 213 /* and get mouse status */ 214 mousehw_t m_hw; /* buttons iftype type model hwid */ 215 mousemode_t m_mode; /* proto rate res accel level size mask */ 216} mse_types[] = { 217 { MSE_ATIINPORT, 218 mse_probeati, mse_enableati, mse_disableati, mse_getati, 219 { 2, MOUSE_IF_INPORT, MOUSE_MOUSE, MOUSE_MODEL_GENERIC, 0, }, 220 { MOUSE_PROTO_INPORT, -1, -1, 0, 0, MOUSE_MSC_PACKETSIZE, 221 { MOUSE_MSC_SYNCMASK, MOUSE_MSC_SYNC, }, }, }, 222 { MSE_LOGITECH, 223 mse_probelogi, mse_enablelogi, mse_disablelogi, mse_getlogi, 224 { 2, MOUSE_IF_BUS, MOUSE_MOUSE, MOUSE_MODEL_GENERIC, 0, }, 225 { MOUSE_PROTO_BUS, -1, -1, 0, 0, MOUSE_MSC_PACKETSIZE, 226 { MOUSE_MSC_SYNCMASK, MOUSE_MSC_SYNC, }, }, }, 227 { 0, }, 228}; 229 230int 231mseprobe(idp) 232 register struct isa_device *idp; 233{ 234 register struct mse_softc *sc = &mse_sc[idp->id_unit]; 235 register int i; 236 237 /* 238 * Check for each mouse type in the table. 239 */ 240 i = 0; 241 while (mse_types[i].m_type) { 242 if ((*mse_types[i].m_probe)(idp)) { 243 sc->sc_mousetype = mse_types[i].m_type; 244 sc->sc_enablemouse = mse_types[i].m_enable; 245 sc->sc_disablemouse = mse_types[i].m_disable; 246 sc->sc_getmouse = mse_types[i].m_get; 247 sc->hw = mse_types[i].m_hw; 248 sc->mode = mse_types[i].m_mode; 249 return (1); 250 } 251 i++; 252 } 253 return (0); 254} 255 256int 257mseattach(idp) 258 struct isa_device *idp; 259{ 260 int unit = idp->id_unit; 261 struct mse_softc *sc = &mse_sc[unit]; 262 263 idp->id_ointr = mseintr; 264 sc->sc_port = idp->id_iobase; 265 sc->mode.accelfactor = (idp->id_flags & MSE_CONFIG_ACCEL) >> 4; 266 make_dev(&mse_cdevsw, unit << 1, 0, 0, 0600, "mse%d", unit); 267 make_dev(&mse_cdevsw, (unit<<1)+1, 0, 0, 0600, "nmse%d", unit); 268 return (1); 269} 270 271/* 272 * Exclusive open the mouse, initialize it and enable interrupts. 273 */ 274static int 275mseopen(dev, flags, fmt, p) 276 dev_t dev; 277 int flags; 278 int fmt; 279 struct proc *p; 280{ 281 register struct mse_softc *sc; 282 int s; 283 284 if (MSE_UNIT(dev) >= NMSE) 285 return (ENXIO); 286 sc = &mse_sc[MSE_UNIT(dev)]; 287 if (sc->sc_mousetype == MSE_NONE) 288 return (ENXIO); 289 if (sc->sc_flags & MSESC_OPEN) 290 return (EBUSY); 291 sc->sc_flags |= MSESC_OPEN; 292 sc->sc_obuttons = sc->sc_buttons = MOUSE_MSC_BUTTONS; 293 sc->sc_deltax = sc->sc_deltay = 0; 294 sc->sc_bytesread = sc->mode.packetsize = MOUSE_MSC_PACKETSIZE; 295 sc->mode.level = 0; 296 sc->status.flags = 0; 297 sc->status.button = sc->status.obutton = 0; 298 sc->status.dx = sc->status.dy = sc->status.dz = 0; 299 300 /* 301 * Initialize mouse interface and enable interrupts. 302 */ 303 s = spltty(); 304 (*sc->sc_enablemouse)(sc->sc_port); 305 splx(s); 306 return (0); 307} 308 309/* 310 * mseclose: just turn off mouse innterrupts. 311 */ 312static int 313mseclose(dev, flags, fmt, p) 314 dev_t dev; 315 int flags; 316 int fmt; 317 struct proc *p; 318{ 319 struct mse_softc *sc = &mse_sc[MSE_UNIT(dev)]; 320 int s; 321 322 s = spltty(); 323 (*sc->sc_disablemouse)(sc->sc_port); 324 sc->sc_flags &= ~MSESC_OPEN; 325 splx(s); 326 return(0); 327} 328 329/* 330 * mseread: return mouse info using the MSC serial protocol, but without 331 * using bytes 4 and 5. 332 * (Yes this is cheesy, but it makes the X386 server happy, so...) 333 */ 334static int 335mseread(dev, uio, ioflag) 336 dev_t dev; 337 struct uio *uio; 338 int ioflag; 339{ 340 register struct mse_softc *sc = &mse_sc[MSE_UNIT(dev)]; 341 int xfer, s, error; 342 343 /* 344 * If there are no protocol bytes to be read, set up a new protocol 345 * packet. 346 */ 347 s = spltty(); /* XXX Should be its own spl, but where is imlXX() */ 348 if (sc->sc_bytesread >= sc->mode.packetsize) { 349 while (sc->sc_deltax == 0 && sc->sc_deltay == 0 && 350 (sc->sc_obuttons ^ sc->sc_buttons) == 0) { 351 if (MSE_NBLOCKIO(dev)) { 352 splx(s); 353 return (0); 354 } 355 sc->sc_flags |= MSESC_WANT; 356 error = tsleep((caddr_t)sc, MSEPRI | PCATCH, 357 "mseread", 0); 358 if (error) { 359 splx(s); 360 return (error); 361 } 362 } 363 364 /* 365 * Generate protocol bytes. 366 * For some reason X386 expects 5 bytes but never uses 367 * the fourth or fifth? 368 */ 369 sc->sc_bytes[0] = sc->mode.syncmask[1] 370 | (sc->sc_buttons & ~sc->mode.syncmask[0]); 371 if (sc->sc_deltax > 127) 372 sc->sc_deltax = 127; 373 if (sc->sc_deltax < -127) 374 sc->sc_deltax = -127; 375 sc->sc_deltay = -sc->sc_deltay; /* Otherwise mousey goes wrong way */ 376 if (sc->sc_deltay > 127) 377 sc->sc_deltay = 127; 378 if (sc->sc_deltay < -127) 379 sc->sc_deltay = -127; 380 sc->sc_bytes[1] = sc->sc_deltax; 381 sc->sc_bytes[2] = sc->sc_deltay; 382 sc->sc_bytes[3] = sc->sc_bytes[4] = 0; 383 sc->sc_bytes[5] = sc->sc_bytes[6] = 0; 384 sc->sc_bytes[7] = MOUSE_SYS_EXTBUTTONS; 385 sc->sc_obuttons = sc->sc_buttons; 386 sc->sc_deltax = sc->sc_deltay = 0; 387 sc->sc_bytesread = 0; 388 } 389 splx(s); 390 xfer = min(uio->uio_resid, sc->mode.packetsize - sc->sc_bytesread); 391 error = uiomove(&sc->sc_bytes[sc->sc_bytesread], xfer, uio); 392 if (error) 393 return (error); 394 sc->sc_bytesread += xfer; 395 return(0); 396} 397 398/* 399 * mseioctl: process ioctl commands. 400 */ 401static int 402mseioctl(dev, cmd, addr, flag, p) 403 dev_t dev; 404 u_long cmd; 405 caddr_t addr; 406 int flag; 407 struct proc *p; 408{ 409 register struct mse_softc *sc = &mse_sc[MSE_UNIT(dev)]; 410 mousestatus_t status; 411 int err = 0; 412 int s; 413 414 switch (cmd) { 415 416 case MOUSE_GETHWINFO: 417 s = spltty(); 418 *(mousehw_t *)addr = sc->hw; 419 if (sc->mode.level == 0) 420 ((mousehw_t *)addr)->model = MOUSE_MODEL_GENERIC; 421 splx(s); 422 break; 423 424 case MOUSE_GETMODE: 425 s = spltty(); 426 *(mousemode_t *)addr = sc->mode; 427 switch (sc->mode.level) { 428 case 0: 429 break; 430 case 1: 431 ((mousemode_t *)addr)->protocol = MOUSE_PROTO_SYSMOUSE; 432 ((mousemode_t *)addr)->syncmask[0] = MOUSE_SYS_SYNCMASK; 433 ((mousemode_t *)addr)->syncmask[1] = MOUSE_SYS_SYNC; 434 break; 435 } 436 splx(s); 437 break; 438 439 case MOUSE_SETMODE: 440 switch (((mousemode_t *)addr)->level) { 441 case 0: 442 case 1: 443 break; 444 default: 445 return (EINVAL); 446 } 447 if (((mousemode_t *)addr)->accelfactor < -1) 448 return (EINVAL); 449 else if (((mousemode_t *)addr)->accelfactor >= 0) 450 sc->mode.accelfactor = 451 ((mousemode_t *)addr)->accelfactor; 452 sc->mode.level = ((mousemode_t *)addr)->level; 453 switch (sc->mode.level) { 454 case 0: 455 sc->sc_bytesread = sc->mode.packetsize 456 = MOUSE_MSC_PACKETSIZE; 457 break; 458 case 1: 459 sc->sc_bytesread = sc->mode.packetsize 460 = MOUSE_SYS_PACKETSIZE; 461 break; 462 } 463 break; 464 465 case MOUSE_GETLEVEL: 466 *(int *)addr = sc->mode.level; 467 break; 468 469 case MOUSE_SETLEVEL: 470 switch (*(int *)addr) { 471 case 0: 472 sc->mode.level = *(int *)addr; 473 sc->sc_bytesread = sc->mode.packetsize 474 = MOUSE_MSC_PACKETSIZE; 475 break; 476 case 1: 477 sc->mode.level = *(int *)addr; 478 sc->sc_bytesread = sc->mode.packetsize 479 = MOUSE_SYS_PACKETSIZE; 480 break; 481 default: 482 return (EINVAL); 483 } 484 break; 485 486 case MOUSE_GETSTATUS: 487 s = spltty(); 488 status = sc->status; 489 sc->status.flags = 0; 490 sc->status.obutton = sc->status.button; 491 sc->status.button = 0; 492 sc->status.dx = 0; 493 sc->status.dy = 0; 494 sc->status.dz = 0; 495 splx(s); 496 *(mousestatus_t *)addr = status; 497 break; 498 499 case MOUSE_READSTATE: 500 case MOUSE_READDATA: 501 return (ENODEV); 502 503#if (defined(MOUSE_GETVARS)) 504 case MOUSE_GETVARS: 505 case MOUSE_SETVARS: 506 return (ENODEV); 507#endif 508 509 default: 510 return (ENOTTY); 511 } 512 return (err); 513} 514 515/* 516 * msepoll: check for mouse input to be processed. 517 */ 518static int 519msepoll(dev, events, p) 520 dev_t dev; 521 int events; 522 struct proc *p; 523{ 524 register struct mse_softc *sc = &mse_sc[MSE_UNIT(dev)]; 525 int s; 526 int revents = 0; 527 528 s = spltty(); 529 if (events & (POLLIN | POLLRDNORM)) { 530 if (sc->sc_bytesread != sc->mode.packetsize || 531 sc->sc_deltax != 0 || sc->sc_deltay != 0 || 532 (sc->sc_obuttons ^ sc->sc_buttons) != 0) 533 revents |= events & (POLLIN | POLLRDNORM); 534 else { 535 /* 536 * Since this is an exclusive open device, any previous 537 * proc pointer is trash now, so we can just assign it. 538 */ 539 selrecord(p, &sc->sc_selp); 540 } 541 } 542 splx(s); 543 return (revents); 544} 545 546/* 547 * mseintr: update mouse status. sc_deltax and sc_deltay are accumulative. 548 */ 549static void 550mseintr(unit) 551 int unit; 552{ 553 /* 554 * the table to turn MouseSystem button bits (MOUSE_MSC_BUTTON?UP) 555 * into `mousestatus' button bits (MOUSE_BUTTON?DOWN). 556 */ 557 static int butmap[8] = { 558 0, 559 MOUSE_BUTTON3DOWN, 560 MOUSE_BUTTON2DOWN, 561 MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN, 562 MOUSE_BUTTON1DOWN, 563 MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, 564 MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN, 565 MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN 566 }; 567 register struct mse_softc *sc = &mse_sc[unit]; 568 int dx, dy, but; 569 int sign; 570 571#ifdef DEBUG 572 static int mse_intrcnt = 0; 573 if((mse_intrcnt++ % 10000) == 0) 574 printf("mseintr\n"); 575#endif /* DEBUG */ 576 if ((sc->sc_flags & MSESC_OPEN) == 0) 577 return; 578 579 (*sc->sc_getmouse)(sc->sc_port, &dx, &dy, &but); 580 if (sc->mode.accelfactor > 0) { 581 sign = (dx < 0); 582 dx = dx * dx / sc->mode.accelfactor; 583 if (dx == 0) 584 dx = 1; 585 if (sign) 586 dx = -dx; 587 sign = (dy < 0); 588 dy = dy * dy / sc->mode.accelfactor; 589 if (dy == 0) 590 dy = 1; 591 if (sign) 592 dy = -dy; 593 } 594 sc->sc_deltax += dx; 595 sc->sc_deltay += dy; 596 sc->sc_buttons = but; 597 598 but = butmap[~but & MOUSE_MSC_BUTTONS]; 599 sc->status.dx += dx; 600 sc->status.dy += dy; 601 sc->status.flags |= ((dx || dy) ? MOUSE_POSCHANGED : 0) 602 | (sc->status.button ^ but); 603 sc->status.button = but; 604 605 /* 606 * If mouse state has changed, wake up anyone wanting to know. 607 */ 608 if (sc->sc_deltax != 0 || sc->sc_deltay != 0 || 609 (sc->sc_obuttons ^ sc->sc_buttons) != 0) { 610 if (sc->sc_flags & MSESC_WANT) { 611 sc->sc_flags &= ~MSESC_WANT; 612 wakeup((caddr_t)sc); 613 } 614 selwakeup(&sc->sc_selp); 615 } 616} 617 618/* 619 * Routines for the Logitech mouse. 620 */ 621/* 622 * Test for a Logitech bus mouse and return 1 if it is. 623 * (until I know how to use the signature port properly, just disable 624 * interrupts and return 1) 625 */ 626static int 627mse_probelogi(idp) 628 register struct isa_device *idp; 629{ 630 631 int sig; 632 633 outb(idp->id_iobase + MSE_PORTD, MSE_SETUP); 634 /* set the signature port */ 635 outb(idp->id_iobase + MSE_PORTB, MSE_LOGI_SIG); 636 637 DELAY(30000); /* 30 ms delay */ 638 sig = inb(idp->id_iobase + MSE_PORTB) & 0xFF; 639 if (sig == MSE_LOGI_SIG) { 640 outb(idp->id_iobase + MSE_PORTC, MSE_DISINTR); 641 return(1); 642 } else { 643 if (bootverbose) 644 printf("mse%d: wrong signature %x\n",idp->id_unit,sig); 645 return(0); 646 } 647} 648 649/* 650 * Initialize Logitech mouse and enable interrupts. 651 */ 652static void 653mse_enablelogi(port) 654 register u_int port; 655{ 656 int dx, dy, but; 657 658 outb(port + MSE_PORTD, MSE_SETUP); 659 mse_getlogi(port, &dx, &dy, &but); 660} 661 662/* 663 * Disable interrupts for Logitech mouse. 664 */ 665static void 666mse_disablelogi(port) 667 register u_int port; 668{ 669 670 outb(port + MSE_PORTC, MSE_DISINTR); 671} 672 673/* 674 * Get the current dx, dy and button up/down state. 675 */ 676static void 677mse_getlogi(port, dx, dy, but) 678 register u_int port; 679 int *dx; 680 int *dy; 681 int *but; 682{ 683 register char x, y; 684 685 outb(port + MSE_PORTC, MSE_HOLD | MSE_RXLOW); 686 x = inb(port + MSE_PORTA); 687 *but = (x >> 5) & MOUSE_MSC_BUTTONS; 688 x &= 0xf; 689 outb(port + MSE_PORTC, MSE_HOLD | MSE_RXHIGH); 690 x |= (inb(port + MSE_PORTA) << 4); 691 outb(port + MSE_PORTC, MSE_HOLD | MSE_RYLOW); 692 y = (inb(port + MSE_PORTA) & 0xf); 693 outb(port + MSE_PORTC, MSE_HOLD | MSE_RYHIGH); 694 y |= (inb(port + MSE_PORTA) << 4); 695 *dx = x; 696 *dy = y; 697 outb(port + MSE_PORTC, MSE_INTREN); 698} 699 700/* 701 * Routines for the ATI Inport bus mouse. 702 */ 703/* 704 * Test for a ATI Inport bus mouse and return 1 if it is. 705 * (do not enable interrupts) 706 */ 707static int 708mse_probeati(idp) 709 register struct isa_device *idp; 710{ 711 int i; 712 713 for (i = 0; i < 2; i++) 714 if (inb(idp->id_iobase + MSE_PORTC) == 0xde) 715 return (1); 716 return (0); 717} 718 719/* 720 * Initialize ATI Inport mouse and enable interrupts. 721 */ 722static void 723mse_enableati(port) 724 register u_int port; 725{ 726 727 outb(port + MSE_PORTA, MSE_INPORT_RESET); 728 outb(port + MSE_PORTA, MSE_INPORT_MODE); 729 outb(port + MSE_PORTB, MSE_INPORT_INTREN); 730} 731 732/* 733 * Disable interrupts for ATI Inport mouse. 734 */ 735static void 736mse_disableati(port) 737 register u_int port; 738{ 739 740 outb(port + MSE_PORTA, MSE_INPORT_MODE); 741 outb(port + MSE_PORTB, 0); 742} 743 744/* 745 * Get current dx, dy and up/down button state. 746 */ 747static void 748mse_getati(port, dx, dy, but) 749 register u_int port; 750 int *dx; 751 int *dy; 752 int *but; 753{ 754 register char byte; 755 756 outb(port + MSE_PORTA, MSE_INPORT_MODE); 757 outb(port + MSE_PORTB, MSE_INPORT_HOLD); 758 outb(port + MSE_PORTA, MSE_INPORT_STATUS); 759 *but = ~inb(port + MSE_PORTB) & MOUSE_MSC_BUTTONS; 760 outb(port + MSE_PORTA, MSE_INPORT_DX); 761 byte = inb(port + MSE_PORTB); 762 *dx = byte; 763 outb(port + MSE_PORTA, MSE_INPORT_DY); 764 byte = inb(port + MSE_PORTB); 765 *dy = byte; 766 outb(port + MSE_PORTA, MSE_INPORT_MODE); 767 outb(port + MSE_PORTB, MSE_INPORT_INTREN); 768} 769