2000-01-08 05:57:22 +03:00
|
|
|
/* $NetBSD: mms.c,v 1.35 2000/01/08 02:57:25 takemura Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1993-06-13 17:55:03 +04:00
|
|
|
/*-
|
1998-08-15 07:02:31 +04:00
|
|
|
* Copyright (c) 1993, 1994 Charles M. Hannum.
|
1993-06-13 17:55:03 +04:00
|
|
|
* Copyright (c) 1992, 1993 Erik Forsberg.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
|
|
|
* NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/ioctl.h>
|
1994-02-17 06:39:52 +03:00
|
|
|
#include <sys/device.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1996-05-13 03:11:54 +04:00
|
|
|
#include <machine/intr.h>
|
1997-10-19 23:17:07 +04:00
|
|
|
#include <machine/bus.h>
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/isa/isavar.h>
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wscons/wsmousevar.h>
|
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
#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
|
|
|
|
|
|
|
|
struct mms_softc { /* driver status information */
|
|
|
|
struct device sc_dev;
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih;
|
1994-02-17 06:39:52 +03:00
|
|
|
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_tag_t sc_iot;
|
|
|
|
bus_space_handle_t sc_ioh;
|
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
int sc_enabled; /* device is open */
|
|
|
|
|
|
|
|
struct device *sc_wsmousedev;
|
1994-03-29 08:35:37 +04:00
|
|
|
};
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1998-03-22 15:52:03 +03:00
|
|
|
int mmsprobe __P((struct device *, struct cfdata *, void *));
|
1994-11-04 02:08:27 +03:00
|
|
|
void mmsattach __P((struct device *, struct device *, void *));
|
1995-04-17 16:06:30 +04:00
|
|
|
int mmsintr __P((void *));
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1996-03-17 04:26:49 +03:00
|
|
|
struct cfattach mms_ca = {
|
|
|
|
sizeof(struct mms_softc), mmsprobe, mmsattach
|
|
|
|
};
|
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
int mms_enable __P((void *));
|
|
|
|
int mms_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
|
|
|
|
void mms_disable __P((void *));
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
const struct wsmouse_accessops mms_accessops = {
|
|
|
|
mms_enable,
|
|
|
|
mms_ioctl,
|
|
|
|
mms_disable,
|
|
|
|
};
|
1994-02-17 06:39:52 +03:00
|
|
|
|
|
|
|
int
|
1994-11-04 02:08:27 +03:00
|
|
|
mmsprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
1998-03-22 15:52:03 +03:00
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
1993-06-13 17:55:03 +04:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
1997-10-20 00:31:29 +04:00
|
|
|
int rv;
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1997-10-19 23:17:07 +04:00
|
|
|
/* Disallow wildcarded i/o address. */
|
|
|
|
if (ia->ia_iobase == ISACF_PORT_DEFAULT)
|
|
|
|
return 0;
|
|
|
|
|
1997-10-20 00:31:29 +04:00
|
|
|
/* Map the i/o space. */
|
1997-10-19 23:17:07 +04:00
|
|
|
if (bus_space_map(iot, ia->ia_iobase, MMS_NPORTS, 0, &ioh))
|
1994-02-17 06:39:52 +03:00
|
|
|
return 0;
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1997-10-20 00:31:29 +04:00
|
|
|
rv = 0;
|
|
|
|
|
1997-10-19 23:17:07 +04:00
|
|
|
/* Read identification register to see if present */
|
|
|
|
if (bus_space_read_1(iot, ioh, MMS_IDENT) != 0xde)
|
|
|
|
goto out;
|
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
/* Seems it was there; reset. */
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_write_1(iot, ioh, MMS_ADDR, 0x87);
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1997-10-19 23:17:07 +04:00
|
|
|
rv = 1;
|
1994-03-29 08:35:37 +04:00
|
|
|
ia->ia_iosize = MMS_NPORTS;
|
|
|
|
ia->ia_msize = 0;
|
1997-10-20 00:31:29 +04:00
|
|
|
|
|
|
|
out:
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_unmap(iot, ioh, MMS_NPORTS);
|
|
|
|
return rv;
|
1993-06-13 17:55:03 +04:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
void
|
|
|
|
mmsattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-06-13 17:55:03 +04:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct mms_softc *sc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
1999-01-23 18:03:50 +03:00
|
|
|
struct wsmousedev_attach_args a;
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1996-10-13 07:19:38 +04:00
|
|
|
printf("\n");
|
1994-03-30 04:54:43 +04:00
|
|
|
|
1997-10-19 23:17:07 +04:00
|
|
|
if (bus_space_map(iot, ia->ia_iobase, MMS_NPORTS, 0, &ioh)) {
|
|
|
|
printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
/* Other initialization was done by mmsprobe. */
|
1997-10-19 23:17:07 +04:00
|
|
|
sc->sc_iot = iot;
|
|
|
|
sc->sc_ioh = ioh;
|
1999-01-23 18:03:50 +03:00
|
|
|
sc->sc_enabled = 0;
|
1994-04-07 10:48:19 +04:00
|
|
|
|
1996-04-12 02:15:08 +04:00
|
|
|
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_PULSE,
|
|
|
|
IPL_TTY, mmsintr, sc);
|
1999-01-23 18:03:50 +03:00
|
|
|
|
|
|
|
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);
|
1993-06-13 17:55:03 +04:00
|
|
|
}
|
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
int
|
1999-01-23 18:03:50 +03:00
|
|
|
mms_enable(v)
|
|
|
|
void *v;
|
1993-06-13 17:55:03 +04:00
|
|
|
{
|
1999-01-23 18:03:50 +03:00
|
|
|
struct mms_softc *sc = v;
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
if (sc->sc_enabled)
|
1994-02-17 06:39:52 +03:00
|
|
|
return EBUSY;
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
sc->sc_enabled = 1;
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
/* Enable interrupts. */
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MMS_ADDR, 0x07);
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MMS_DATA, 0x09);
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
return 0;
|
1993-06-13 17:55:03 +04:00
|
|
|
}
|
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
void
|
|
|
|
mms_disable(v)
|
|
|
|
void *v;
|
1993-06-13 17:55:03 +04:00
|
|
|
{
|
1999-01-23 18:03:50 +03:00
|
|
|
struct mms_softc *sc = v;
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
/* Disable interrupts. */
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MMS_ADDR, 0x87);
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
sc->sc_enabled = 0;
|
1993-06-13 17:55:03 +04:00
|
|
|
}
|
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
int
|
1999-01-23 18:03:50 +03:00
|
|
|
mms_ioctl(v, cmd, data, flag, p)
|
|
|
|
void *v;
|
1994-10-31 00:43:03 +03:00
|
|
|
u_long cmd;
|
1999-01-23 18:03:50 +03:00
|
|
|
caddr_t data;
|
1994-02-17 06:39:52 +03:00
|
|
|
int flag;
|
1996-05-04 00:11:57 +04:00
|
|
|
struct proc *p;
|
1993-06-13 17:55:03 +04:00
|
|
|
{
|
1999-01-23 18:03:50 +03:00
|
|
|
#if 0
|
|
|
|
struct mms_softc *sc = v;
|
|
|
|
#endif
|
1993-06-13 17:55:03 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
1999-01-23 18:03:50 +03:00
|
|
|
case WSMOUSEIO_GTYPE:
|
|
|
|
*(u_int *)data = WSMOUSE_TYPE_MMS;
|
|
|
|
return (0);
|
1994-02-17 06:39:52 +03:00
|
|
|
}
|
1999-01-23 18:03:50 +03:00
|
|
|
return (-1);
|
1993-06-13 17:55:03 +04:00
|
|
|
}
|
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
int
|
1995-04-17 16:06:30 +04:00
|
|
|
mmsintr(arg)
|
|
|
|
void *arg;
|
1993-06-13 17:55:03 +04:00
|
|
|
{
|
1995-04-17 16:06:30 +04:00
|
|
|
struct mms_softc *sc = arg;
|
1997-10-20 00:31:29 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1999-01-23 18:03:50 +03:00
|
|
|
u_char status;
|
|
|
|
signed char dx, dy;
|
|
|
|
u_int buttons;
|
|
|
|
int changed;
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
if (!sc->sc_enabled)
|
1994-02-17 06:39:52 +03:00
|
|
|
/* Interrupts are not expected. */
|
|
|
|
return 0;
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
/* Freeze InPort registers (disabling interrupts). */
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_write_1(iot, ioh, MMS_ADDR, 0x07);
|
|
|
|
bus_space_write_1(iot, ioh, MMS_DATA, 0x29);
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_write_1(iot, ioh, MMS_ADDR, 0x00);
|
|
|
|
status = bus_space_read_1(iot, ioh, MMS_DATA);
|
1993-06-13 17:55:03 +04:00
|
|
|
|
|
|
|
if (status & 0x40) {
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_write_1(iot, ioh, MMS_ADDR, 1);
|
|
|
|
dx = bus_space_read_1(iot, ioh, MMS_DATA);
|
1999-01-23 18:03:50 +03:00
|
|
|
/* Bounding at -127 avoids a bug in XFree86. */
|
1994-02-17 06:39:52 +03:00
|
|
|
dx = (dx == -128) ? -127 : dx;
|
1999-01-23 18:03:50 +03:00
|
|
|
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_write_1(iot, ioh, MMS_ADDR, 2);
|
|
|
|
dy = bus_space_read_1(iot, ioh, MMS_DATA);
|
1993-06-13 17:55:03 +04:00
|
|
|
dy = (dy == -128) ? 127 : -dy;
|
1994-02-17 06:39:52 +03:00
|
|
|
} else
|
1993-06-13 17:55:03 +04:00
|
|
|
dx = dy = 0;
|
|
|
|
|
1994-02-17 06:39:52 +03:00
|
|
|
/* Unfreeze InPort registers (reenabling interrupts). */
|
1997-10-19 23:17:07 +04:00
|
|
|
bus_space_write_1(iot, ioh, MMS_ADDR, 0x07);
|
|
|
|
bus_space_write_1(iot, ioh, MMS_DATA, 0x09);
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
buttons = ((status & 0x04) ? 0x1 : 0) |
|
|
|
|
((status & 0x02) ? 0x2 : 0) |
|
|
|
|
((status & 0x01) ? 0x4 : 0);
|
|
|
|
changed = status & 0x38;
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
if (dx || dy || changed)
|
|
|
|
wsmouse_input(sc->sc_wsmousedev,
|
2000-01-08 05:57:22 +03:00
|
|
|
buttons, dx, dy, 0, WSMOUSE_INPUT_DELTA);
|
1993-06-13 17:55:03 +04:00
|
|
|
|
1999-01-23 18:03:50 +03:00
|
|
|
return -1;
|
1993-06-13 17:55:03 +04:00
|
|
|
}
|