Home | History | Annotate | Line # | Download | only in iomd
qms.c revision 1.4.6.5
      1  1.4.6.5     skrll /*	$NetBSD: qms.c,v 1.4.6.5 2005/01/13 08:33:11 skrll Exp $	*/
      2      1.1   reinoud 
      3  1.4.6.2     skrll /*-
      4  1.4.6.2     skrll  * Copyright (c) 2001 Reinoud Zandijk
      5  1.4.6.2     skrll  * All rights reserved.
      6  1.4.6.2     skrll  *
      7  1.4.6.2     skrll  * This code is derived from software contributed to The NetBSD Foundation
      8  1.4.6.2     skrll  * by Reinoud Zandijk
      9      1.1   reinoud  *
     10      1.1   reinoud  * Redistribution and use in source and binary forms, with or without
     11      1.1   reinoud  * modification, are permitted provided that the following conditions
     12      1.1   reinoud  * are met:
     13      1.1   reinoud  * 1. Redistributions of source code must retain the above copyright
     14      1.1   reinoud  *    notice, this list of conditions and the following disclaimer.
     15      1.1   reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1   reinoud  *    notice, this list of conditions and the following disclaimer in the
     17      1.1   reinoud  *    documentation and/or other materials provided with the distribution.
     18      1.1   reinoud  * 3. All advertising materials mentioning features or use of this software
     19      1.1   reinoud  *    must display the following acknowledgement:
     20  1.4.6.2     skrll  *      This product includes software developed by the NetBSD
     21  1.4.6.2     skrll  *      Foundation, Inc. and its contributors.
     22  1.4.6.2     skrll  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.4.6.2     skrll  *    contributors may be used to endorse or promote products derived
     24  1.4.6.2     skrll  *    from this software without specific prior written permission.
     25      1.1   reinoud  *
     26  1.4.6.2     skrll  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.4.6.2     skrll  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.4.6.2     skrll  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.4.6.2     skrll  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.4.6.2     skrll  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.4.6.2     skrll  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.4.6.2     skrll  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.4.6.2     skrll  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.4.6.2     skrll  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.4.6.2     skrll  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.4.6.2     skrll  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1   reinoud  */
     38      1.1   reinoud /*
     39  1.4.6.2     skrll  * Quadrature mouse driver for the wscons as used in the IOMD
     40      1.1   reinoud  */
     41      1.1   reinoud 
     42      1.1   reinoud #include <sys/param.h>
     43  1.4.6.2     skrll 
     44  1.4.6.5     skrll __KERNEL_RCSID(0, "$NetBSD: qms.c,v 1.4.6.5 2005/01/13 08:33:11 skrll Exp $");
     45  1.4.6.2     skrll 
     46  1.4.6.2     skrll #include <sys/callout.h>
     47  1.4.6.2     skrll #include <sys/device.h>
     48  1.4.6.2     skrll #include <sys/errno.h>
     49      1.1   reinoud #include <sys/ioctl.h>
     50      1.1   reinoud #include <sys/kernel.h>
     51  1.4.6.2     skrll #include <sys/malloc.h>
     52      1.1   reinoud #include <sys/proc.h>
     53  1.4.6.2     skrll #include <sys/tty.h>
     54  1.4.6.2     skrll #include <sys/types.h>
     55  1.4.6.2     skrll #include <sys/syslog.h>
     56  1.4.6.2     skrll #include <sys/systm.h>
     57  1.4.6.2     skrll #include <sys/select.h>
     58      1.1   reinoud 
     59      1.1   reinoud #include <machine/bus.h>
     60  1.4.6.2     skrll #include <machine/intr.h>
     61      1.1   reinoud 
     62  1.4.6.2     skrll #include <arm/iomd/iomdvar.h>
     63      1.1   reinoud 
     64  1.4.6.2     skrll #include <dev/wscons/wsconsio.h>
     65  1.4.6.2     skrll #include <dev/wscons/wsmousevar.h>
     66      1.1   reinoud 
     67  1.4.6.2     skrll struct qms_softc {
     68  1.4.6.2     skrll 	struct device  sc_dev;
     69  1.4.6.2     skrll 	struct device *sc_wsmousedev;
     70      1.1   reinoud 
     71  1.4.6.2     skrll 	bus_space_tag_t sc_iot;		/* bus tag */
     72  1.4.6.2     skrll 	bus_space_handle_t sc_ioh;	/* bus handle for XY */
     73  1.4.6.2     skrll 	bus_space_handle_t sc_butioh;	/* bus handle for buttons */
     74      1.2   gehenna 
     75  1.4.6.2     skrll 	struct callout sc_callout;
     76      1.2   gehenna 
     77  1.4.6.2     skrll 	u_int16_t lastx;
     78  1.4.6.2     skrll 	u_int16_t lasty;
     79  1.4.6.2     skrll 	int lastb;
     80      1.2   gehenna };
     81      1.1   reinoud 
     82      1.1   reinoud /* Offsets of hardware registers */
     83  1.4.6.2     skrll #define QMS_MOUSEX	0		/* 16 bits X register */
     84  1.4.6.2     skrll #define QMS_MOUSEY	1		/* 16 bits Y register */
     85  1.4.6.2     skrll #define QMS_BUTTONS	0 		/* mouse buttons in bits 4,5,6 */
     86  1.4.6.2     skrll 
     87  1.4.6.2     skrll static int  qms_match(struct device *, struct cfdata *, void *);
     88  1.4.6.2     skrll static void qms_attach(struct device *, struct device *, void *);
     89  1.4.6.2     skrll 
     90  1.4.6.2     skrll static int qms_enable(void *);
     91  1.4.6.5     skrll static int qms_ioctl(void *, u_long, caddr_t, int, struct lwp *);
     92  1.4.6.2     skrll static void qms_disable(void *cookie);
     93  1.4.6.2     skrll static void qms_intr(void *arg);
     94      1.1   reinoud 
     95  1.4.6.2     skrll CFATTACH_DECL(qms, sizeof(struct qms_softc),
     96  1.4.6.2     skrll     qms_match, qms_attach, NULL, NULL);
     97      1.1   reinoud 
     98  1.4.6.2     skrll static struct wsmouse_accessops qms_accessops = {
     99  1.4.6.2     skrll 	qms_enable, qms_ioctl, qms_disable
    100  1.4.6.2     skrll };
    101      1.1   reinoud 
    102      1.1   reinoud 
    103  1.4.6.2     skrll static int
    104  1.4.6.2     skrll qms_match(struct device *parent, struct cfdata *cf, void *aux)
    105      1.1   reinoud {
    106  1.4.6.2     skrll 	struct qms_attach_args *qa = aux;
    107      1.1   reinoud 
    108  1.4.6.2     skrll 	if (strcmp(qa->qa_name, "qms") == 0)
    109  1.4.6.2     skrll 		return(1);
    110      1.1   reinoud 
    111      1.1   reinoud 	return(0);
    112      1.1   reinoud }
    113      1.1   reinoud 
    114      1.1   reinoud 
    115  1.4.6.2     skrll static void
    116  1.4.6.2     skrll qms_attach(struct device *parent, struct device *self, void *aux)
    117      1.1   reinoud {
    118  1.4.6.2     skrll 	struct qms_softc *sc = (void *)self;
    119  1.4.6.2     skrll 	struct qms_attach_args *qa = aux;
    120  1.4.6.2     skrll 	struct wsmousedev_attach_args wsmouseargs;
    121      1.1   reinoud 
    122  1.4.6.2     skrll 	sc->sc_iot = qa->qa_iot;
    123  1.4.6.2     skrll 	sc->sc_ioh = qa->qa_ioh;
    124  1.4.6.2     skrll 	sc->sc_butioh = qa->qa_ioh_but;
    125      1.1   reinoud 
    126  1.4.6.2     skrll 	/* set up wsmouse attach arguments */
    127  1.4.6.2     skrll 	wsmouseargs.accessops = &qms_accessops;
    128  1.4.6.2     skrll 	wsmouseargs.accesscookie = sc;
    129      1.1   reinoud 
    130  1.4.6.2     skrll 	printf("\n");
    131      1.1   reinoud 
    132  1.4.6.2     skrll 	sc->sc_wsmousedev =
    133  1.4.6.2     skrll 	    config_found(&sc->sc_dev, &wsmouseargs, wsmousedevprint);
    134      1.1   reinoud 
    135  1.4.6.2     skrll 	callout_init(&sc->sc_callout);
    136      1.1   reinoud }
    137      1.1   reinoud 
    138      1.1   reinoud 
    139  1.4.6.2     skrll static int
    140  1.4.6.2     skrll qms_enable(void *cookie)
    141      1.1   reinoud {
    142  1.4.6.2     skrll 	struct qms_softc *sc = cookie;
    143  1.4.6.2     skrll 	int b;
    144      1.1   reinoud 
    145  1.4.6.2     skrll 	/* We don't want the mouse to warp on open. */
    146  1.4.6.2     skrll 	sc->lastx = bus_space_read_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX);
    147  1.4.6.2     skrll 	sc->lasty = bus_space_read_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY);
    148  1.4.6.2     skrll 	b = bus_space_read_1(sc->sc_iot, sc->sc_butioh, QMS_BUTTONS) & 0x70;
    149      1.1   reinoud 
    150  1.4.6.2     skrll 	/* patch up the buttons */
    151      1.1   reinoud 	b >>= 4;
    152  1.4.6.2     skrll 	sc->lastb = ~( ((b & 1)<<2) | (b & 2) | ((b & 4)>>2));
    153      1.1   reinoud 
    154  1.4.6.2     skrll 	callout_reset(&sc->sc_callout, hz / 100, qms_intr, sc);
    155  1.4.6.2     skrll 	return 0;
    156      1.1   reinoud }
    157      1.1   reinoud 
    158      1.1   reinoud 
    159  1.4.6.2     skrll static void
    160  1.4.6.2     skrll qms_disable(void *cookie)
    161      1.1   reinoud {
    162  1.4.6.2     skrll 	struct qms_softc *sc = cookie;
    163      1.1   reinoud 
    164  1.4.6.2     skrll 	callout_stop(&sc->sc_callout);
    165      1.1   reinoud }
    166      1.1   reinoud 
    167      1.1   reinoud 
    168  1.4.6.2     skrll static int
    169  1.4.6.5     skrll qms_ioctl(void *cookie, u_long cmd, caddr_t data, int flag, struct lwp *l)
    170      1.1   reinoud {
    171      1.1   reinoud 
    172  1.4.6.2     skrll 	switch (cmd) {
    173  1.4.6.2     skrll 	case WSMOUSEIO_GTYPE:
    174  1.4.6.2     skrll 		*(int *)data = WSMOUSE_TYPE_ARCHIMEDES;
    175  1.4.6.2     skrll 		return 0;
    176      1.1   reinoud 	}
    177      1.1   reinoud 
    178  1.4.6.2     skrll 	return EPASSTHROUGH;
    179      1.1   reinoud }
    180      1.3  jdolecek 
    181  1.4.6.2     skrll 
    182      1.3  jdolecek static void
    183  1.4.6.2     skrll qms_intr(void *arg)
    184      1.3  jdolecek {
    185  1.4.6.2     skrll 	struct qms_softc *sc = arg;
    186  1.4.6.2     skrll 	int b;
    187  1.4.6.2     skrll 	u_int16_t x, y;
    188  1.4.6.2     skrll 	int16_t dx, dy;
    189  1.4.6.2     skrll 
    190  1.4.6.2     skrll 	x = bus_space_read_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX);
    191  1.4.6.2     skrll 	y = bus_space_read_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY);
    192  1.4.6.2     skrll 	b = bus_space_read_1(sc->sc_iot, sc->sc_butioh, QMS_BUTTONS) & 0x70;
    193      1.3  jdolecek 
    194  1.4.6.2     skrll 	/* patch up the buttons */
    195  1.4.6.2     skrll 	b >>= 4;
    196  1.4.6.2     skrll 	b = ~( ((b & 1)<<2) | (b & 2) | ((b & 4)>>2));
    197      1.3  jdolecek 
    198  1.4.6.2     skrll 	if ((x != sc->lastx) || (y != sc->lasty) || (b != sc->lastb)) {
    199  1.4.6.2     skrll 		/* This assumes that int16_t is two's complement. */
    200  1.4.6.2     skrll 		dx = x - sc->lastx;
    201  1.4.6.2     skrll 		dy = y - sc->lasty;
    202  1.4.6.2     skrll 		wsmouse_input(sc->sc_wsmousedev, b, dx, dy, 0,
    203  1.4.6.2     skrll 		    WSMOUSE_INPUT_DELTA);
    204      1.3  jdolecek 
    205  1.4.6.2     skrll 		/* save old values */
    206  1.4.6.2     skrll 		sc->lastx = x;
    207  1.4.6.2     skrll 		sc->lasty = y;
    208  1.4.6.2     skrll 		sc->lastb = b;
    209  1.4.6.2     skrll 	};
    210  1.4.6.2     skrll 	callout_reset(&sc->sc_callout, hz / 100, qms_intr, sc);
    211      1.3  jdolecek }
    212      1.3  jdolecek 
    213      1.1   reinoud 
    214  1.4.6.2     skrll /* end of qms.c */
    215