NetBSD/sys/arch/i386/isa/lms.c

258 lines
6.2 KiB
C
Raw Normal View History

2001-11-15 10:03:28 +03:00
/* $NetBSD: lms.c,v 1.39 2001/11/15 07:03:32 lukem Exp $ */
1994-10-27 07:14:23 +03:00
1993-06-13 17:59:52 +04:00
/*-
* Copyright (c) 1993, 1994 Charles M. Hannum.
1993-06-13 17:59:52 +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.
*/
2001-11-15 10:03:28 +03:00
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lms.c,v 1.39 2001/11/15 07:03:32 lukem Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/ioctl.h>
1994-02-17 06:39:52 +03:00
#include <sys/device.h>
1996-04-09 04:46:15 +04:00
#include <machine/bus.h>
1996-05-13 03:11:54 +04:00
#include <machine/intr.h>
1993-06-13 17:59:52 +04:00
#include <dev/isa/isavar.h>
1993-06-13 17:59:52 +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 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 */
#define LMS_CNTRL 2 /* offset for control port, write-only */
#define LMS_CONFIG 3 /* for configuration port, read-write */
#define LMS_NPORTS 4
struct lms_softc { /* driver status information */
struct device sc_dev;
void *sc_ih;
1994-02-17 06:39:52 +03:00
bus_space_tag_t sc_iot; /* bus i/o space identifier */
bus_space_handle_t sc_ioh; /* bus i/o handle */
1996-04-09 04:46:15 +04:00
1999-01-23 18:03:50 +03:00
int sc_enabled; /* device is open */
int oldbuttons; /* mouse button status */
struct device *sc_wsmousedev;
1994-03-29 08:35:37 +04:00
};
1993-06-13 17:59:52 +04:00
1998-03-22 15:52:03 +03:00
int lmsprobe __P((struct device *, struct cfdata *, void *));
1994-11-04 02:08:27 +03:00
void lmsattach __P((struct device *, struct device *, void *));
int lmsintr __P((void *));
1993-06-13 17:59:52 +04:00
struct cfattach lms_ca = {
sizeof(struct lms_softc), lmsprobe, lmsattach
};
1999-01-23 18:03:50 +03:00
int lms_enable __P((void *));
int lms_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
void lms_disable __P((void *));
1993-06-13 17:59:52 +04:00
1999-01-23 18:03:50 +03:00
const struct wsmouse_accessops lms_accessops = {
lms_enable,
lms_ioctl,
lms_disable,
};
1993-06-13 17:59:52 +04:00
1994-02-17 06:39:52 +03:00
int
1994-11-04 02:08:27 +03:00
lmsprobe(parent, match, aux)
struct device *parent;
1998-03-22 15:52:03 +03:00
struct cfdata *match;
void *aux;
1994-02-17 06:39:52 +03:00
{
1994-03-29 08:35:37 +04:00
struct isa_attach_args *ia = aux;
bus_space_tag_t iot = ia->ia_iot;
bus_space_handle_t ioh;
1996-04-09 04:46:15 +04:00
int rv;
/* Disallow wildcarded i/o base. */
if (ia->ia_iobase == ISACF_PORT_DEFAULT)
return 0;
1996-04-09 04:46:15 +04:00
/* Map the i/o space. */
if (bus_space_map(iot, ia->ia_iobase, LMS_NPORTS, 0, &ioh))
1996-04-09 04:46:15 +04:00
return 0;
rv = 0;
1993-06-13 17:59:52 +04:00
1994-02-17 06:39:52 +03:00
/* Configure and check for port present. */
bus_space_write_1(iot, ioh, LMS_CONFIG, 0x91);
delay(10);
bus_space_write_1(iot, ioh, LMS_SIGN, 0x0c);
delay(10);
if (bus_space_read_1(iot, ioh, LMS_SIGN) != 0x0c)
1996-04-09 04:46:15 +04:00
goto out;
bus_space_write_1(iot, ioh, LMS_SIGN, 0x50);
delay(10);
if (bus_space_read_1(iot, ioh, LMS_SIGN) != 0x50)
1996-04-09 04:46:15 +04:00
goto out;
1993-06-13 17:59:52 +04:00
1994-02-17 06:39:52 +03:00
/* Disable interrupts. */
bus_space_write_1(iot, ioh, LMS_CNTRL, 0x10);
1993-06-13 17:59:52 +04:00
1996-04-09 04:46:15 +04:00
rv = 1;
1994-03-29 08:35:37 +04:00
ia->ia_iosize = LMS_NPORTS;
ia->ia_msize = 0;
1996-04-09 04:46:15 +04:00
out:
bus_space_unmap(iot, ioh, LMS_NPORTS);
1996-04-09 04:46:15 +04:00
return rv;
1993-06-13 17:59:52 +04:00
}
1994-03-29 08:35:37 +04:00
void
lmsattach(parent, self, aux)
struct device *parent, *self;
void *aux;
1993-06-13 17:59:52 +04:00
{
1994-03-29 08:35:37 +04:00
struct lms_softc *sc = (void *)self;
struct isa_attach_args *ia = aux;
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:59:52 +04:00
1996-10-13 07:19:38 +04:00
printf("\n");
1994-03-30 04:54:43 +04:00
if (bus_space_map(iot, ia->ia_iobase, LMS_NPORTS, 0, &ioh)) {
printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
return;
}
1996-04-09 04:46:15 +04:00
/* Other initialization was done by lmsprobe. */
sc->sc_iot = iot;
sc->sc_ioh = ioh;
1999-01-23 18:03:50 +03:00
sc->sc_enabled = 0;
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_PULSE,
IPL_TTY, lmsintr, sc);
1999-01-23 18:03:50 +03:00
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);
1993-06-13 17:59:52 +04:00
}
1994-02-17 06:39:52 +03:00
int
1999-01-23 18:03:50 +03:00
lms_enable(v)
void *v;
1993-06-13 17:59:52 +04:00
{
1999-01-23 18:03:50 +03:00
struct lms_softc *sc = v;
1993-06-13 17:59:52 +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:59:52 +04:00
1999-01-23 18:03:50 +03:00
sc->sc_enabled = 1;
sc->oldbuttons = 0;
1993-06-13 17:59:52 +04:00
1994-02-17 06:39:52 +03:00
/* Enable interrupts. */
bus_space_write_1(sc->sc_iot, sc->sc_ioh, LMS_CNTRL, 0);
1993-06-13 17:59:52 +04:00
1994-02-17 06:39:52 +03:00
return 0;
1993-06-13 17:59:52 +04:00
}
1999-01-23 18:03:50 +03:00
void
lms_disable(v)
void *v;
1993-06-13 17:59:52 +04:00
{
1999-01-23 18:03:50 +03:00
struct lms_softc *sc = v;
1993-06-13 17:59:52 +04:00
1994-02-17 06:39:52 +03:00
/* Disable interrupts. */
bus_space_write_1(sc->sc_iot, sc->sc_ioh, LMS_CNTRL, 0x10);
1993-06-13 17:59:52 +04:00
1999-01-23 18:03:50 +03:00
sc->sc_enabled = 0;
1993-06-13 17:59:52 +04:00
}
1994-02-17 06:39:52 +03:00
int
1999-01-23 18:03:50 +03:00
lms_ioctl(v, cmd, data, flag, p)
void *v;
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:59:52 +04:00
{
1999-01-23 18:03:50 +03:00
#if 0
struct lms_softc *sc = v;
#endif
1993-06-13 17:59:52 +04:00
switch (cmd) {
1999-01-23 18:03:50 +03:00
case WSMOUSEIO_GTYPE:
*(u_int *)data = WSMOUSE_TYPE_LMS;
return (0);
1994-02-17 06:39:52 +03:00
}
1999-01-23 18:03:50 +03:00
return (-1);
1993-06-13 17:59:52 +04:00
}
1994-02-17 06:39:52 +03:00
int
lmsintr(arg)
void *arg;
1993-06-13 17:59:52 +04:00
{
struct lms_softc *sc = arg;
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 hi, lo;
signed char dx, dy;
u_int buttons;
int changed;
1994-02-17 06:39:52 +03: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;
bus_space_write_1(iot, ioh, LMS_CNTRL, 0xab);
hi = bus_space_read_1(iot, ioh, LMS_DATA);
bus_space_write_1(iot, ioh, LMS_CNTRL, 0x90);
lo = bus_space_read_1(iot, ioh, LMS_DATA);
1994-02-17 06:39:52 +03:00
dx = ((hi & 0x0f) << 4) | (lo & 0x0f);
/* Bounding at -127 avoids a bug in XFree86. */
1993-06-14 20:38:25 +04:00
dx = (dx == -128) ? -127 : dx;
bus_space_write_1(iot, ioh, LMS_CNTRL, 0xf0);
hi = bus_space_read_1(iot, ioh, LMS_DATA);
bus_space_write_1(iot, ioh, LMS_CNTRL, 0xd0);
lo = bus_space_read_1(iot, ioh, LMS_DATA);
1994-02-17 06:39:52 +03:00
dy = ((hi & 0x0f) << 4) | (lo & 0x0f);
1993-06-13 17:59:52 +04:00
dy = (dy == -128) ? 127 : -dy;
1993-06-14 20:38:25 +04:00
bus_space_write_1(iot, ioh, LMS_CNTRL, 0);
1993-06-13 17:59:52 +04:00
1999-01-23 18:03:50 +03:00
buttons = ((hi & 0x80) ? 0 : 0x1) |
((hi & 0x40) ? 0 : 0x2) |
((hi & 0x20) ? 0 : 0x4);
changed = (buttons ^ sc->oldbuttons);
sc->oldbuttons = buttons;
1994-02-17 06:39:52 +03:00
1999-01-23 18:03:50 +03:00
if (dx || dy || changed)
wsmouse_input(sc->sc_wsmousedev,
buttons, dx, dy, 0, WSMOUSE_INPUT_DELTA);
1993-06-13 17:59:52 +04:00
1999-01-23 18:03:50 +03:00
return -1;
1993-06-13 17:59:52 +04:00
}