Home | History | Annotate | Line # | Download | only in isa
lms.c revision 1.38.8.1
      1  1.38.8.1   nathanw /*	$NetBSD: lms.c,v 1.38.8.1 2002/01/08 00:25:36 nathanw Exp $	*/
      2      1.14       cgd 
      3       1.1    andrew /*-
      4      1.35   mycroft  * Copyright (c) 1993, 1994 Charles M. Hannum.
      5       1.1    andrew  * Copyright (c) 1992, 1993 Erik Forsberg.
      6       1.1    andrew  * All rights reserved.
      7       1.1    andrew  *
      8       1.1    andrew  * Redistribution and use in source and binary forms, with or without
      9       1.1    andrew  * modification, are permitted provided that the following conditions
     10       1.1    andrew  * are met:
     11       1.1    andrew  * 1. Redistributions of source code must retain the above copyright
     12       1.1    andrew  *    notice, this list of conditions and the following disclaimer.
     13       1.1    andrew  *
     14       1.1    andrew  * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
     15       1.1    andrew  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     16       1.1    andrew  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
     17       1.1    andrew  * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18       1.1    andrew  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19       1.1    andrew  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20       1.1    andrew  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     21       1.1    andrew  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     22       1.1    andrew  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     23       1.1    andrew  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24       1.1    andrew  */
     25  1.38.8.1   nathanw 
     26  1.38.8.1   nathanw #include <sys/cdefs.h>
     27  1.38.8.1   nathanw __KERNEL_RCSID(0, "$NetBSD: lms.c,v 1.38.8.1 2002/01/08 00:25:36 nathanw Exp $");
     28       1.1    andrew 
     29       1.7   mycroft #include <sys/param.h>
     30       1.7   mycroft #include <sys/systm.h>
     31       1.7   mycroft #include <sys/ioctl.h>
     32       1.8   mycroft #include <sys/device.h>
     33       1.7   mycroft 
     34      1.23   thorpej #include <machine/bus.h>
     35      1.26   mycroft #include <machine/intr.h>
     36       1.1    andrew 
     37      1.19       cgd #include <dev/isa/isavar.h>
     38       1.1    andrew 
     39      1.37  drochner #include <dev/wscons/wsconsio.h>
     40      1.37  drochner #include <dev/wscons/wsmousevar.h>
     41      1.37  drochner 
     42       1.8   mycroft #define	LMS_DATA	0       /* offset for data port, read-only */
     43       1.8   mycroft #define	LMS_SIGN	1       /* offset for signature port, read-write */
     44       1.8   mycroft #define	LMS_INTR	2       /* offset for interrupt port, read-only */
     45       1.8   mycroft #define	LMS_CNTRL	2       /* offset for control port, write-only */
     46       1.8   mycroft #define	LMS_CONFIG	3	/* for configuration port, read-write */
     47       1.8   mycroft #define	LMS_NPORTS	4
     48       1.8   mycroft 
     49       1.8   mycroft struct lms_softc {		/* driver status information */
     50       1.8   mycroft 	struct device sc_dev;
     51      1.19       cgd 	void *sc_ih;
     52       1.8   mycroft 
     53      1.30   thorpej 	bus_space_tag_t sc_iot;		/* bus i/o space identifier */
     54      1.30   thorpej 	bus_space_handle_t sc_ioh;	/* bus i/o handle */
     55      1.23   thorpej 
     56      1.37  drochner 	int sc_enabled; /* device is open */
     57      1.37  drochner 	int oldbuttons;	/* mouse button status */
     58      1.37  drochner 
     59      1.37  drochner 	struct device *sc_wsmousedev;
     60      1.10   mycroft };
     61       1.1    andrew 
     62      1.34  drochner int lmsprobe __P((struct device *, struct cfdata *, void *));
     63      1.16   mycroft void lmsattach __P((struct device *, struct device *, void *));
     64      1.19       cgd int lmsintr __P((void *));
     65       1.1    andrew 
     66      1.22   thorpej struct cfattach lms_ca = {
     67      1.22   thorpej 	sizeof(struct lms_softc), lmsprobe, lmsattach
     68      1.22   thorpej };
     69      1.22   thorpej 
     70      1.37  drochner int	lms_enable __P((void *));
     71      1.37  drochner int	lms_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
     72      1.37  drochner void	lms_disable __P((void *));
     73      1.37  drochner 
     74      1.37  drochner const struct wsmouse_accessops lms_accessops = {
     75      1.37  drochner 	lms_enable,
     76      1.37  drochner 	lms_ioctl,
     77      1.37  drochner 	lms_disable,
     78      1.37  drochner };
     79       1.8   mycroft 
     80       1.8   mycroft int
     81      1.16   mycroft lmsprobe(parent, match, aux)
     82      1.16   mycroft 	struct device *parent;
     83      1.34  drochner 	struct cfdata *match;
     84      1.34  drochner 	void *aux;
     85       1.1    andrew {
     86      1.10   mycroft 	struct isa_attach_args *ia = aux;
     87      1.30   thorpej 	bus_space_tag_t iot = ia->ia_iot;
     88      1.30   thorpej 	bus_space_handle_t ioh;
     89      1.23   thorpej 	int rv;
     90      1.23   thorpej 
     91      1.31   thorpej 	/* Disallow wildcarded i/o base. */
     92      1.32   mycroft 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
     93      1.31   thorpej 		return 0;
     94      1.31   thorpej 
     95      1.23   thorpej 	/* Map the i/o space. */
     96      1.30   thorpej 	if (bus_space_map(iot, ia->ia_iobase, LMS_NPORTS, 0, &ioh))
     97      1.23   thorpej 		return 0;
     98      1.23   thorpej 
     99      1.23   thorpej 	rv = 0;
    100       1.1    andrew 
    101       1.8   mycroft 	/* Configure and check for port present. */
    102      1.30   thorpej 	bus_space_write_1(iot, ioh, LMS_CONFIG, 0x91);
    103       1.9   mycroft 	delay(10);
    104      1.30   thorpej 	bus_space_write_1(iot, ioh, LMS_SIGN, 0x0c);
    105       1.9   mycroft 	delay(10);
    106      1.30   thorpej 	if (bus_space_read_1(iot, ioh, LMS_SIGN) != 0x0c)
    107      1.23   thorpej 		goto out;
    108      1.30   thorpej 	bus_space_write_1(iot, ioh, LMS_SIGN, 0x50);
    109       1.9   mycroft 	delay(10);
    110      1.30   thorpej 	if (bus_space_read_1(iot, ioh, LMS_SIGN) != 0x50)
    111      1.23   thorpej 		goto out;
    112       1.1    andrew 
    113       1.8   mycroft 	/* Disable interrupts. */
    114      1.30   thorpej 	bus_space_write_1(iot, ioh, LMS_CNTRL, 0x10);
    115       1.1    andrew 
    116      1.23   thorpej 	rv = 1;
    117      1.10   mycroft 	ia->ia_iosize = LMS_NPORTS;
    118      1.10   mycroft 	ia->ia_msize = 0;
    119      1.23   thorpej 
    120      1.23   thorpej out:
    121      1.30   thorpej 	bus_space_unmap(iot, ioh, LMS_NPORTS);
    122      1.23   thorpej 	return rv;
    123       1.1    andrew }
    124       1.1    andrew 
    125      1.10   mycroft void
    126      1.10   mycroft lmsattach(parent, self, aux)
    127      1.10   mycroft 	struct device *parent, *self;
    128      1.10   mycroft 	void *aux;
    129       1.1    andrew {
    130      1.10   mycroft 	struct lms_softc *sc = (void *)self;
    131      1.10   mycroft 	struct isa_attach_args *ia = aux;
    132      1.32   mycroft 	bus_space_tag_t iot = ia->ia_iot;
    133      1.32   mycroft 	bus_space_handle_t ioh;
    134      1.37  drochner 	struct wsmousedev_attach_args a;
    135      1.11   mycroft 
    136      1.29  christos 	printf("\n");
    137       1.1    andrew 
    138      1.32   mycroft 	if (bus_space_map(iot, ia->ia_iobase, LMS_NPORTS, 0, &ioh)) {
    139      1.32   mycroft 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    140      1.32   mycroft 		return;
    141      1.32   mycroft 	}
    142      1.32   mycroft 
    143       1.8   mycroft 	/* Other initialization was done by lmsprobe. */
    144      1.32   mycroft 	sc->sc_iot = iot;
    145      1.32   mycroft 	sc->sc_ioh = ioh;
    146      1.37  drochner 	sc->sc_enabled = 0;
    147      1.12   mycroft 
    148      1.24       cgd 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_PULSE,
    149      1.24       cgd 	    IPL_TTY, lmsintr, sc);
    150      1.37  drochner 
    151      1.37  drochner 	a.accessops = &lms_accessops;
    152      1.37  drochner 	a.accesscookie = sc;
    153      1.37  drochner 
    154      1.37  drochner 	/*
    155      1.37  drochner 	 * Attach the wsmouse, saving a handle to it.
    156      1.37  drochner 	 * Note that we don't need to check this pointer against NULL
    157      1.37  drochner 	 * here or in psmintr, because if this fails lms_enable() will
    158      1.37  drochner 	 * never be called, so lmsintr() will never be called.
    159      1.37  drochner 	 */
    160      1.37  drochner 	sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
    161       1.1    andrew }
    162       1.1    andrew 
    163       1.8   mycroft int
    164      1.37  drochner lms_enable(v)
    165      1.37  drochner 	void *v;
    166       1.1    andrew {
    167      1.37  drochner 	struct lms_softc *sc = v;
    168       1.1    andrew 
    169      1.37  drochner 	if (sc->sc_enabled)
    170       1.8   mycroft 		return EBUSY;
    171       1.1    andrew 
    172      1.37  drochner 	sc->sc_enabled = 1;
    173      1.37  drochner 	sc->oldbuttons = 0;
    174       1.1    andrew 
    175       1.8   mycroft 	/* Enable interrupts. */
    176      1.30   thorpej 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, LMS_CNTRL, 0);
    177       1.1    andrew 
    178       1.8   mycroft 	return 0;
    179       1.1    andrew }
    180       1.1    andrew 
    181      1.37  drochner void
    182      1.37  drochner lms_disable(v)
    183      1.37  drochner 	void *v;
    184       1.1    andrew {
    185      1.37  drochner 	struct lms_softc *sc = v;
    186       1.1    andrew 
    187       1.8   mycroft 	/* Disable interrupts. */
    188      1.30   thorpej 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, LMS_CNTRL, 0x10);
    189       1.1    andrew 
    190      1.37  drochner 	sc->sc_enabled = 0;
    191       1.1    andrew }
    192       1.1    andrew 
    193       1.8   mycroft int
    194      1.37  drochner lms_ioctl(v, cmd, data, flag, p)
    195      1.37  drochner 	void *v;
    196      1.15       cgd 	u_long cmd;
    197      1.37  drochner 	caddr_t data;
    198       1.8   mycroft 	int flag;
    199      1.25  christos 	struct proc *p;
    200       1.1    andrew {
    201      1.37  drochner #if 0
    202      1.37  drochner 	struct lms_softc *sc = v;
    203      1.37  drochner #endif
    204       1.1    andrew 
    205       1.1    andrew 	switch (cmd) {
    206      1.37  drochner 	case WSMOUSEIO_GTYPE:
    207      1.37  drochner 		*(u_int *)data = WSMOUSE_TYPE_LMS;
    208      1.37  drochner 		return (0);
    209       1.8   mycroft 	}
    210      1.37  drochner 	return (-1);
    211       1.1    andrew }
    212       1.1    andrew 
    213       1.8   mycroft int
    214      1.19       cgd lmsintr(arg)
    215      1.19       cgd 	void *arg;
    216       1.1    andrew {
    217      1.19       cgd 	struct lms_softc *sc = arg;
    218      1.30   thorpej 	bus_space_tag_t iot = sc->sc_iot;
    219      1.30   thorpej 	bus_space_handle_t ioh = sc->sc_ioh;
    220      1.37  drochner 	u_char hi, lo;
    221      1.37  drochner 	signed char dx, dy;
    222      1.37  drochner 	u_int buttons;
    223      1.37  drochner 	int changed;
    224       1.8   mycroft 
    225      1.37  drochner 	if (!sc->sc_enabled)
    226       1.8   mycroft 		/* Interrupts are not expected. */
    227       1.8   mycroft 		return 0;
    228       1.8   mycroft 
    229      1.30   thorpej 	bus_space_write_1(iot, ioh, LMS_CNTRL, 0xab);
    230      1.30   thorpej 	hi = bus_space_read_1(iot, ioh, LMS_DATA);
    231      1.30   thorpej 	bus_space_write_1(iot, ioh, LMS_CNTRL, 0x90);
    232      1.30   thorpej 	lo = bus_space_read_1(iot, ioh, LMS_DATA);
    233       1.8   mycroft 	dx = ((hi & 0x0f) << 4) | (lo & 0x0f);
    234       1.8   mycroft 	/* Bounding at -127 avoids a bug in XFree86. */
    235       1.3   mycroft 	dx = (dx == -128) ? -127 : dx;
    236       1.3   mycroft 
    237      1.30   thorpej 	bus_space_write_1(iot, ioh, LMS_CNTRL, 0xf0);
    238      1.30   thorpej 	hi = bus_space_read_1(iot, ioh, LMS_DATA);
    239      1.30   thorpej 	bus_space_write_1(iot, ioh, LMS_CNTRL, 0xd0);
    240      1.30   thorpej 	lo = bus_space_read_1(iot, ioh, LMS_DATA);
    241       1.8   mycroft 	dy = ((hi & 0x0f) << 4) | (lo & 0x0f);
    242       1.1    andrew 	dy = (dy == -128) ? 127 : -dy;
    243       1.3   mycroft 
    244      1.30   thorpej 	bus_space_write_1(iot, ioh, LMS_CNTRL, 0);
    245       1.8   mycroft 
    246      1.37  drochner 	buttons = ((hi & 0x80) ? 0 : 0x1) |
    247      1.37  drochner 		((hi & 0x40) ? 0 : 0x2) |
    248      1.37  drochner 		((hi & 0x20) ? 0 : 0x4);
    249      1.37  drochner 	changed = (buttons ^ sc->oldbuttons);
    250      1.37  drochner 	sc->oldbuttons = buttons;
    251      1.37  drochner 
    252      1.37  drochner 	if (dx || dy || changed)
    253      1.37  drochner 		wsmouse_input(sc->sc_wsmousedev,
    254      1.38  takemura 			      buttons, dx, dy, 0, WSMOUSE_INPUT_DELTA);
    255       1.8   mycroft 
    256      1.12   mycroft 	return -1;
    257       1.1    andrew }
    258