make the busmice work with wscons
This commit is contained in:
parent
75fee98847
commit
45ecb32709
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lms.c,v 1.36 1998/08/25 04:58:36 thorpej Exp $ */
|
||||
/* $NetBSD: lms.c,v 1.37 1999/01/23 15:03:50 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993, 1994 Charles M. Hannum.
|
||||
@ -24,27 +24,18 @@
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/tty.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/intr.h>
|
||||
#include <machine/mouse.h>
|
||||
#include <machine/conf.h>
|
||||
|
||||
#include <dev/isa/isavar.h>
|
||||
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
#include <dev/wscons/wsmousevar.h>
|
||||
|
||||
#define LMS_DATA 0 /* offset for data port, read-only */
|
||||
#define LMS_SIGN 1 /* offset for signature port, read-write */
|
||||
#define LMS_INTR 2 /* offset for interrupt port, read-only */
|
||||
@ -52,9 +43,6 @@
|
||||
#define LMS_CONFIG 3 /* for configuration port, read-write */
|
||||
#define LMS_NPORTS 4
|
||||
|
||||
#define LMS_CHUNK 128 /* chunk size for read */
|
||||
#define LMS_BSIZE 1020 /* buffer size */
|
||||
|
||||
struct lms_softc { /* driver status information */
|
||||
struct device sc_dev;
|
||||
void *sc_ih;
|
||||
@ -62,13 +50,10 @@ struct lms_softc { /* driver status information */
|
||||
bus_space_tag_t sc_iot; /* bus i/o space identifier */
|
||||
bus_space_handle_t sc_ioh; /* bus i/o handle */
|
||||
|
||||
struct clist sc_q;
|
||||
struct selinfo sc_rsel;
|
||||
u_char sc_state; /* mouse driver state */
|
||||
#define LMS_OPEN 0x01 /* device is open */
|
||||
#define LMS_ASLP 0x02 /* waiting for mouse data */
|
||||
u_char sc_status; /* mouse button status */
|
||||
int sc_x, sc_y; /* accumulated motion in the X,Y axis */
|
||||
int sc_enabled; /* device is open */
|
||||
int oldbuttons; /* mouse button status */
|
||||
|
||||
struct device *sc_wsmousedev;
|
||||
};
|
||||
|
||||
int lmsprobe __P((struct device *, struct cfdata *, void *));
|
||||
@ -79,9 +64,15 @@ struct cfattach lms_ca = {
|
||||
sizeof(struct lms_softc), lmsprobe, lmsattach
|
||||
};
|
||||
|
||||
extern struct cfdriver lms_cd;
|
||||
int lms_enable __P((void *));
|
||||
int lms_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
|
||||
void lms_disable __P((void *));
|
||||
|
||||
#define LMSUNIT(dev) (minor(dev))
|
||||
const struct wsmouse_accessops lms_accessops = {
|
||||
lms_enable,
|
||||
lms_ioctl,
|
||||
lms_disable,
|
||||
};
|
||||
|
||||
int
|
||||
lmsprobe(parent, match, aux)
|
||||
@ -137,6 +128,7 @@ lmsattach(parent, self, aux)
|
||||
struct isa_attach_args *ia = aux;
|
||||
bus_space_tag_t iot = ia->ia_iot;
|
||||
bus_space_handle_t ioh;
|
||||
struct wsmousedev_attach_args a;
|
||||
|
||||
printf("\n");
|
||||
|
||||
@ -148,37 +140,34 @@ lmsattach(parent, self, aux)
|
||||
/* Other initialization was done by lmsprobe. */
|
||||
sc->sc_iot = iot;
|
||||
sc->sc_ioh = ioh;
|
||||
sc->sc_state = 0;
|
||||
sc->sc_enabled = 0;
|
||||
|
||||
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_PULSE,
|
||||
IPL_TTY, lmsintr, sc);
|
||||
|
||||
a.accessops = &lms_accessops;
|
||||
a.accesscookie = sc;
|
||||
|
||||
/*
|
||||
* Attach the wsmouse, saving a handle to it.
|
||||
* Note that we don't need to check this pointer against NULL
|
||||
* here or in psmintr, because if this fails lms_enable() will
|
||||
* never be called, so lmsintr() will never be called.
|
||||
*/
|
||||
sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
|
||||
}
|
||||
|
||||
int
|
||||
lmsopen(dev, flag, mode, p)
|
||||
dev_t dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct proc *p;
|
||||
lms_enable(v)
|
||||
void *v;
|
||||
{
|
||||
int unit = LMSUNIT(dev);
|
||||
struct lms_softc *sc;
|
||||
struct lms_softc *sc = v;
|
||||
|
||||
if (unit >= lms_cd.cd_ndevs)
|
||||
return ENXIO;
|
||||
sc = lms_cd.cd_devs[unit];
|
||||
if (!sc)
|
||||
return ENXIO;
|
||||
|
||||
if (sc->sc_state & LMS_OPEN)
|
||||
if (sc->sc_enabled)
|
||||
return EBUSY;
|
||||
|
||||
if (clalloc(&sc->sc_q, LMS_BSIZE, 0) == -1)
|
||||
return ENOMEM;
|
||||
|
||||
sc->sc_state |= LMS_OPEN;
|
||||
sc->sc_status = 0;
|
||||
sc->sc_x = sc->sc_y = 0;
|
||||
sc->sc_enabled = 1;
|
||||
sc->oldbuttons = 0;
|
||||
|
||||
/* Enable interrupts. */
|
||||
bus_space_write_1(sc->sc_iot, sc->sc_ioh, LMS_CNTRL, 0);
|
||||
@ -186,124 +175,36 @@ lmsopen(dev, flag, mode, p)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
lmsclose(dev, flag, mode, p)
|
||||
dev_t dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct proc *p;
|
||||
void
|
||||
lms_disable(v)
|
||||
void *v;
|
||||
{
|
||||
struct lms_softc *sc = lms_cd.cd_devs[LMSUNIT(dev)];
|
||||
struct lms_softc *sc = v;
|
||||
|
||||
/* Disable interrupts. */
|
||||
bus_space_write_1(sc->sc_iot, sc->sc_ioh, LMS_CNTRL, 0x10);
|
||||
|
||||
sc->sc_state &= ~LMS_OPEN;
|
||||
|
||||
clfree(&sc->sc_q);
|
||||
|
||||
return 0;
|
||||
sc->sc_enabled = 0;
|
||||
}
|
||||
|
||||
int
|
||||
lmsread(dev, uio, flag)
|
||||
dev_t dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
struct lms_softc *sc = lms_cd.cd_devs[LMSUNIT(dev)];
|
||||
int s;
|
||||
int error = 0;
|
||||
size_t length;
|
||||
u_char buffer[LMS_CHUNK];
|
||||
|
||||
/* Block until mouse activity occured. */
|
||||
|
||||
s = spltty();
|
||||
while (sc->sc_q.c_cc == 0) {
|
||||
if (flag & IO_NDELAY) {
|
||||
splx(s);
|
||||
return EWOULDBLOCK;
|
||||
}
|
||||
sc->sc_state |= LMS_ASLP;
|
||||
error = tsleep((caddr_t)sc, PZERO | PCATCH, "lmsrea", 0);
|
||||
if (error) {
|
||||
sc->sc_state &= ~LMS_ASLP;
|
||||
splx(s);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
splx(s);
|
||||
|
||||
/* Transfer as many chunks as possible. */
|
||||
|
||||
while (sc->sc_q.c_cc > 0 && uio->uio_resid > 0) {
|
||||
length = min(sc->sc_q.c_cc, uio->uio_resid);
|
||||
if (length > sizeof(buffer))
|
||||
length = sizeof(buffer);
|
||||
|
||||
/* Remove a small chunk from the input queue. */
|
||||
(void) q_to_b(&sc->sc_q, buffer, length);
|
||||
|
||||
/* Copy the data to the user process. */
|
||||
if ((error = uiomove(buffer, length, uio)) != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
lmsioctl(dev, cmd, addr, flag, p)
|
||||
dev_t dev;
|
||||
lms_ioctl(v, cmd, data, flag, p)
|
||||
void *v;
|
||||
u_long cmd;
|
||||
caddr_t addr;
|
||||
caddr_t data;
|
||||
int flag;
|
||||
struct proc *p;
|
||||
{
|
||||
struct lms_softc *sc = lms_cd.cd_devs[LMSUNIT(dev)];
|
||||
struct mouseinfo info;
|
||||
int s;
|
||||
int error;
|
||||
#if 0
|
||||
struct lms_softc *sc = v;
|
||||
#endif
|
||||
|
||||
switch (cmd) {
|
||||
case MOUSEIOCREAD:
|
||||
s = spltty();
|
||||
|
||||
info.status = sc->sc_status;
|
||||
if (sc->sc_x || sc->sc_y)
|
||||
info.status |= MOVEMENT;
|
||||
|
||||
if (sc->sc_x > 127)
|
||||
info.xmotion = 127;
|
||||
else if (sc->sc_x < -127)
|
||||
/* Bounding at -127 avoids a bug in XFree86. */
|
||||
info.xmotion = -127;
|
||||
else
|
||||
info.xmotion = sc->sc_x;
|
||||
|
||||
if (sc->sc_y > 127)
|
||||
info.ymotion = 127;
|
||||
else if (sc->sc_y < -127)
|
||||
info.ymotion = -127;
|
||||
else
|
||||
info.ymotion = sc->sc_y;
|
||||
|
||||
/* Reset historical information. */
|
||||
sc->sc_x = sc->sc_y = 0;
|
||||
sc->sc_status &= ~BUTCHNGMASK;
|
||||
ndflush(&sc->sc_q, sc->sc_q.c_cc);
|
||||
|
||||
splx(s);
|
||||
error = copyout(&info, addr, sizeof(struct mouseinfo));
|
||||
break;
|
||||
|
||||
default:
|
||||
error = EINVAL;
|
||||
break;
|
||||
case WSMOUSEIO_GTYPE:
|
||||
*(u_int *)data = WSMOUSE_TYPE_LMS;
|
||||
return (0);
|
||||
}
|
||||
|
||||
return error;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
@ -313,11 +214,12 @@ lmsintr(arg)
|
||||
struct lms_softc *sc = arg;
|
||||
bus_space_tag_t iot = sc->sc_iot;
|
||||
bus_space_handle_t ioh = sc->sc_ioh;
|
||||
u_char hi, lo, buttons, changed;
|
||||
char dx, dy;
|
||||
u_char buffer[5];
|
||||
u_char hi, lo;
|
||||
signed char dx, dy;
|
||||
u_int buttons;
|
||||
int changed;
|
||||
|
||||
if ((sc->sc_state & LMS_OPEN) == 0)
|
||||
if (!sc->sc_enabled)
|
||||
/* Interrupts are not expected. */
|
||||
return 0;
|
||||
|
||||
@ -338,49 +240,15 @@ lmsintr(arg)
|
||||
|
||||
bus_space_write_1(iot, ioh, LMS_CNTRL, 0);
|
||||
|
||||
buttons = (~hi >> 5) & 0x07;
|
||||
changed = ((buttons ^ sc->sc_status) & 0x07) << 3;
|
||||
sc->sc_status = buttons | (sc->sc_status & ~BUTSTATMASK) | changed;
|
||||
buttons = ((hi & 0x80) ? 0 : 0x1) |
|
||||
((hi & 0x40) ? 0 : 0x2) |
|
||||
((hi & 0x20) ? 0 : 0x4);
|
||||
changed = (buttons ^ sc->oldbuttons);
|
||||
sc->oldbuttons = buttons;
|
||||
|
||||
if (dx || dy || changed) {
|
||||
/* Update accumulated movements. */
|
||||
sc->sc_x += dx;
|
||||
sc->sc_y += dy;
|
||||
|
||||
/* Add this event to the queue. */
|
||||
buffer[0] = 0x80 | (buttons ^ BUTSTATMASK);
|
||||
buffer[1] = dx;
|
||||
buffer[2] = dy;
|
||||
buffer[3] = buffer[4] = 0;
|
||||
(void) b_to_q(buffer, sizeof buffer, &sc->sc_q);
|
||||
|
||||
if (sc->sc_state & LMS_ASLP) {
|
||||
sc->sc_state &= ~LMS_ASLP;
|
||||
wakeup((caddr_t)sc);
|
||||
}
|
||||
selwakeup(&sc->sc_rsel);
|
||||
}
|
||||
if (dx || dy || changed)
|
||||
wsmouse_input(sc->sc_wsmousedev,
|
||||
buttons, dx, dy, 0);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
lmspoll(dev, events, p)
|
||||
dev_t dev;
|
||||
int events;
|
||||
struct proc *p;
|
||||
{
|
||||
struct lms_softc *sc = lms_cd.cd_devs[LMSUNIT(dev)];
|
||||
int revents = 0;
|
||||
int s = spltty();
|
||||
|
||||
if (events & (POLLIN | POLLRDNORM)) {
|
||||
if (sc->sc_q.c_cc > 0)
|
||||
revents |= events & (POLLIN | POLLRDNORM);
|
||||
else
|
||||
selrecord(p, &sc->sc_rsel);
|
||||
}
|
||||
|
||||
splx(s);
|
||||
return (revents);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mms.c,v 1.33 1998/08/25 04:59:28 thorpej Exp $ */
|
||||
/* $NetBSD: mms.c,v 1.34 1999/01/23 15:03:50 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993, 1994 Charles M. Hannum.
|
||||
@ -24,35 +24,23 @@
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/tty.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/intr.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/mouse.h>
|
||||
#include <machine/conf.h>
|
||||
|
||||
#include <dev/isa/isavar.h>
|
||||
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
#include <dev/wscons/wsmousevar.h>
|
||||
|
||||
#define MMS_ADDR 0 /* offset for register select */
|
||||
#define MMS_DATA 1 /* offset for InPort data */
|
||||
#define MMS_IDENT 2 /* offset for identification register */
|
||||
#define MMS_NPORTS 4
|
||||
|
||||
#define MMS_CHUNK 128 /* chunk size for read */
|
||||
#define MMS_BSIZE 1020 /* buffer size */
|
||||
|
||||
struct mms_softc { /* driver status information */
|
||||
struct device sc_dev;
|
||||
void *sc_ih;
|
||||
@ -60,13 +48,9 @@ struct mms_softc { /* driver status information */
|
||||
bus_space_tag_t sc_iot;
|
||||
bus_space_handle_t sc_ioh;
|
||||
|
||||
struct clist sc_q;
|
||||
struct selinfo sc_rsel;
|
||||
u_char sc_state; /* mouse driver state */
|
||||
#define MMS_OPEN 0x01 /* device is open */
|
||||
#define MMS_ASLP 0x02 /* waiting for mouse data */
|
||||
u_char sc_status; /* mouse button status */
|
||||
int sc_x, sc_y; /* accumulated motion in the X,Y axis */
|
||||
int sc_enabled; /* device is open */
|
||||
|
||||
struct device *sc_wsmousedev;
|
||||
};
|
||||
|
||||
int mmsprobe __P((struct device *, struct cfdata *, void *));
|
||||
@ -77,9 +61,15 @@ struct cfattach mms_ca = {
|
||||
sizeof(struct mms_softc), mmsprobe, mmsattach
|
||||
};
|
||||
|
||||
extern struct cfdriver mms_cd;
|
||||
int mms_enable __P((void *));
|
||||
int mms_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
|
||||
void mms_disable __P((void *));
|
||||
|
||||
#define MMSUNIT(dev) (minor(dev))
|
||||
const struct wsmouse_accessops mms_accessops = {
|
||||
mms_enable,
|
||||
mms_ioctl,
|
||||
mms_disable,
|
||||
};
|
||||
|
||||
int
|
||||
mmsprobe(parent, match, aux)
|
||||
@ -127,6 +117,7 @@ mmsattach(parent, self, aux)
|
||||
struct isa_attach_args *ia = aux;
|
||||
bus_space_tag_t iot = ia->ia_iot;
|
||||
bus_space_handle_t ioh;
|
||||
struct wsmousedev_attach_args a;
|
||||
|
||||
printf("\n");
|
||||
|
||||
@ -138,37 +129,33 @@ mmsattach(parent, self, aux)
|
||||
/* Other initialization was done by mmsprobe. */
|
||||
sc->sc_iot = iot;
|
||||
sc->sc_ioh = ioh;
|
||||
sc->sc_state = 0;
|
||||
sc->sc_enabled = 0;
|
||||
|
||||
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_PULSE,
|
||||
IPL_TTY, mmsintr, sc);
|
||||
|
||||
a.accessops = &mms_accessops;
|
||||
a.accesscookie = sc;
|
||||
|
||||
/*
|
||||
* Attach the wsmouse, saving a handle to it.
|
||||
* Note that we don't need to check this pointer against NULL
|
||||
* here or in psmintr, because if this fails lms_enable() will
|
||||
* never be called, so lmsintr() will never be called.
|
||||
*/
|
||||
sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
|
||||
}
|
||||
|
||||
int
|
||||
mmsopen(dev, flag, mode, p)
|
||||
dev_t dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct proc *p;
|
||||
mms_enable(v)
|
||||
void *v;
|
||||
{
|
||||
int unit = MMSUNIT(dev);
|
||||
struct mms_softc *sc;
|
||||
struct mms_softc *sc = v;
|
||||
|
||||
if (unit >= mms_cd.cd_ndevs)
|
||||
return ENXIO;
|
||||
sc = mms_cd.cd_devs[unit];
|
||||
if (!sc)
|
||||
return ENXIO;
|
||||
|
||||
if (sc->sc_state & MMS_OPEN)
|
||||
if (sc->sc_enabled)
|
||||
return EBUSY;
|
||||
|
||||
if (clalloc(&sc->sc_q, MMS_BSIZE, 0) == -1)
|
||||
return ENOMEM;
|
||||
|
||||
sc->sc_state |= MMS_OPEN;
|
||||
sc->sc_status = 0;
|
||||
sc->sc_x = sc->sc_y = 0;
|
||||
sc->sc_enabled = 1;
|
||||
|
||||
/* Enable interrupts. */
|
||||
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MMS_ADDR, 0x07);
|
||||
@ -177,124 +164,36 @@ mmsopen(dev, flag, mode, p)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
mmsclose(dev, flag, mode, p)
|
||||
dev_t dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct proc *p;
|
||||
void
|
||||
mms_disable(v)
|
||||
void *v;
|
||||
{
|
||||
struct mms_softc *sc = mms_cd.cd_devs[MMSUNIT(dev)];
|
||||
struct mms_softc *sc = v;
|
||||
|
||||
/* Disable interrupts. */
|
||||
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MMS_ADDR, 0x87);
|
||||
|
||||
sc->sc_state &= ~MMS_OPEN;
|
||||
|
||||
clfree(&sc->sc_q);
|
||||
|
||||
return 0;
|
||||
sc->sc_enabled = 0;
|
||||
}
|
||||
|
||||
int
|
||||
mmsread(dev, uio, flag)
|
||||
dev_t dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
struct mms_softc *sc = mms_cd.cd_devs[MMSUNIT(dev)];
|
||||
int s;
|
||||
int error = 0;
|
||||
size_t length;
|
||||
u_char buffer[MMS_CHUNK];
|
||||
|
||||
/* Block until mouse activity occured. */
|
||||
|
||||
s = spltty();
|
||||
while (sc->sc_q.c_cc == 0) {
|
||||
if (flag & IO_NDELAY) {
|
||||
splx(s);
|
||||
return EWOULDBLOCK;
|
||||
}
|
||||
sc->sc_state |= MMS_ASLP;
|
||||
error = tsleep((caddr_t)sc, PZERO | PCATCH, "mmsrea", 0);
|
||||
if (error) {
|
||||
sc->sc_state &= ~MMS_ASLP;
|
||||
splx(s);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
splx(s);
|
||||
|
||||
/* Transfer as many chunks as possible. */
|
||||
|
||||
while (sc->sc_q.c_cc > 0 && uio->uio_resid > 0) {
|
||||
length = min(sc->sc_q.c_cc, uio->uio_resid);
|
||||
if (length > sizeof(buffer))
|
||||
length = sizeof(buffer);
|
||||
|
||||
/* Remove a small chunk from the input queue. */
|
||||
(void) q_to_b(&sc->sc_q, buffer, length);
|
||||
|
||||
/* Copy the data to the user process. */
|
||||
if ((error = uiomove(buffer, length, uio)) != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
mmsioctl(dev, cmd, addr, flag, p)
|
||||
dev_t dev;
|
||||
mms_ioctl(v, cmd, data, flag, p)
|
||||
void *v;
|
||||
u_long cmd;
|
||||
caddr_t addr;
|
||||
caddr_t data;
|
||||
int flag;
|
||||
struct proc *p;
|
||||
{
|
||||
struct mms_softc *sc = mms_cd.cd_devs[MMSUNIT(dev)];
|
||||
struct mouseinfo info;
|
||||
int s;
|
||||
int error;
|
||||
#if 0
|
||||
struct mms_softc *sc = v;
|
||||
#endif
|
||||
|
||||
switch (cmd) {
|
||||
case MOUSEIOCREAD:
|
||||
s = spltty();
|
||||
|
||||
info.status = sc->sc_status;
|
||||
if (sc->sc_x || sc->sc_y)
|
||||
info.status |= MOVEMENT;
|
||||
|
||||
if (sc->sc_x > 127)
|
||||
info.xmotion = 127;
|
||||
else if (sc->sc_x < -127)
|
||||
/* Bounding at -127 avoids a bug in XFree86. */
|
||||
info.xmotion = -127;
|
||||
else
|
||||
info.xmotion = sc->sc_x;
|
||||
|
||||
if (sc->sc_y > 127)
|
||||
info.ymotion = 127;
|
||||
else if (sc->sc_y < -127)
|
||||
info.ymotion = -127;
|
||||
else
|
||||
info.ymotion = sc->sc_y;
|
||||
|
||||
/* Reset historical information. */
|
||||
sc->sc_x = sc->sc_y = 0;
|
||||
sc->sc_status &= ~BUTCHNGMASK;
|
||||
ndflush(&sc->sc_q, sc->sc_q.c_cc);
|
||||
|
||||
splx(s);
|
||||
error = copyout(&info, addr, sizeof(struct mouseinfo));
|
||||
break;
|
||||
|
||||
default:
|
||||
error = EINVAL;
|
||||
break;
|
||||
case WSMOUSEIO_GTYPE:
|
||||
*(u_int *)data = WSMOUSE_TYPE_MMS;
|
||||
return (0);
|
||||
}
|
||||
|
||||
return error;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
@ -304,11 +203,12 @@ mmsintr(arg)
|
||||
struct mms_softc *sc = arg;
|
||||
bus_space_tag_t iot = sc->sc_iot;
|
||||
bus_space_handle_t ioh = sc->sc_ioh;
|
||||
u_char buttons, changed, status;
|
||||
char dx, dy;
|
||||
u_char buffer[5];
|
||||
u_char status;
|
||||
signed char dx, dy;
|
||||
u_int buttons;
|
||||
int changed;
|
||||
|
||||
if ((sc->sc_state & MMS_OPEN) == 0)
|
||||
if (!sc->sc_enabled)
|
||||
/* Interrupts are not expected. */
|
||||
return 0;
|
||||
|
||||
@ -322,7 +222,9 @@ mmsintr(arg)
|
||||
if (status & 0x40) {
|
||||
bus_space_write_1(iot, ioh, MMS_ADDR, 1);
|
||||
dx = bus_space_read_1(iot, ioh, MMS_DATA);
|
||||
/* Bounding at -127 avoids a bug in XFree86. */
|
||||
dx = (dx == -128) ? -127 : dx;
|
||||
|
||||
bus_space_write_1(iot, ioh, MMS_ADDR, 2);
|
||||
dy = bus_space_read_1(iot, ioh, MMS_DATA);
|
||||
dy = (dy == -128) ? 127 : -dy;
|
||||
@ -333,49 +235,14 @@ mmsintr(arg)
|
||||
bus_space_write_1(iot, ioh, MMS_ADDR, 0x07);
|
||||
bus_space_write_1(iot, ioh, MMS_DATA, 0x09);
|
||||
|
||||
buttons = status & BUTSTATMASK;
|
||||
changed = status & BUTCHNGMASK;
|
||||
sc->sc_status = buttons | (sc->sc_status & ~BUTSTATMASK) | changed;
|
||||
buttons = ((status & 0x04) ? 0x1 : 0) |
|
||||
((status & 0x02) ? 0x2 : 0) |
|
||||
((status & 0x01) ? 0x4 : 0);
|
||||
changed = status & 0x38;
|
||||
|
||||
if (dx || dy || changed) {
|
||||
/* Update accumulated movements. */
|
||||
sc->sc_x += dx;
|
||||
sc->sc_y += dy;
|
||||
|
||||
/* Add this event to the queue. */
|
||||
buffer[0] = 0x80 | (buttons ^ BUTSTATMASK);
|
||||
buffer[1] = dx;
|
||||
buffer[2] = dy;
|
||||
buffer[3] = buffer[4] = 0;
|
||||
(void) b_to_q(buffer, sizeof buffer, &sc->sc_q);
|
||||
|
||||
if (sc->sc_state & MMS_ASLP) {
|
||||
sc->sc_state &= ~MMS_ASLP;
|
||||
wakeup((caddr_t)sc);
|
||||
}
|
||||
selwakeup(&sc->sc_rsel);
|
||||
}
|
||||
if (dx || dy || changed)
|
||||
wsmouse_input(sc->sc_wsmousedev,
|
||||
buttons, dx, dy, 0);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
mmspoll(dev, events, p)
|
||||
dev_t dev;
|
||||
int events;
|
||||
struct proc *p;
|
||||
{
|
||||
struct mms_softc *sc = mms_cd.cd_devs[MMSUNIT(dev)];
|
||||
int revents = 0;
|
||||
int s = spltty();
|
||||
|
||||
if (events & (POLLIN | POLLRDNORM)) {
|
||||
if (sc->sc_q.c_cc > 0)
|
||||
revents |= events & (POLLIN | POLLRDNORM);
|
||||
else
|
||||
selrecord(p, &sc->sc_rsel);
|
||||
}
|
||||
|
||||
splx(s);
|
||||
return (revents);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user