Home | History | Annotate | Line # | Download | only in dec
vsxxx.c revision 1.1.2.1
      1  1.1.2.1  wrstuden /* $NetBSD: vsxxx.c,v 1.1.2.1 1999/12/27 18:34:41 wrstuden Exp $ */
      2      1.1  nisimura 
      3      1.1  nisimura /*
      4      1.1  nisimura  * Copyright (c) 1999 Tohru Nishimura.  All rights reserved.
      5      1.1  nisimura  *
      6      1.1  nisimura  * Redistribution and use in source and binary forms, with or without
      7      1.1  nisimura  * modification, are permitted provided that the following conditions
      8      1.1  nisimura  * are met:
      9      1.1  nisimura  * 1. Redistributions of source code must retain the above copyright
     10      1.1  nisimura  *    notice, this list of conditions and the following disclaimer.
     11      1.1  nisimura  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1  nisimura  *    notice, this list of conditions and the following disclaimer in the
     13      1.1  nisimura  *    documentation and/or other materials provided with the distribution.
     14      1.1  nisimura  * 3. All advertising materials mentioning features or use of this software
     15      1.1  nisimura  *    must display the following acknowledgement:
     16      1.1  nisimura  *      This product includes software developed by Tohru Nishimura.
     17      1.1  nisimura  *	for the NetBSD Project.
     18      1.1  nisimura  * 4. The name of the author may not be used to endorse or promote products
     19      1.1  nisimura  *    derived from this software without specific prior written permission
     20      1.1  nisimura  *
     21      1.1  nisimura  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22      1.1  nisimura  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23      1.1  nisimura  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24      1.1  nisimura  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25      1.1  nisimura  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26      1.1  nisimura  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27      1.1  nisimura  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28      1.1  nisimura  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29      1.1  nisimura  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30      1.1  nisimura  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31      1.1  nisimura  */
     32      1.1  nisimura 
     33      1.1  nisimura #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     34      1.1  nisimura 
     35  1.1.2.1  wrstuden __KERNEL_RCSID(0, "$NetBSD: vsxxx.c,v 1.1.2.1 1999/12/27 18:34:41 wrstuden Exp $");
     36      1.1  nisimura 
     37      1.1  nisimura /*
     38      1.1  nisimura  * Common machinary for VSXXX mice and tablet
     39      1.1  nisimura  */
     40      1.1  nisimura 
     41      1.1  nisimura #include <sys/param.h>
     42      1.1  nisimura #include <sys/systm.h>
     43      1.1  nisimura #include <sys/device.h>
     44      1.1  nisimura 
     45      1.1  nisimura #include <dev/wscons/wsconsio.h>
     46      1.1  nisimura #include <dev/wscons/wsmousevar.h>
     47      1.1  nisimura 
     48      1.1  nisimura #include <dev/dec/vsxxxvar.h>
     49      1.1  nisimura 
     50      1.1  nisimura /*
     51      1.1  nisimura  * XXX XXX XXX
     52      1.1  nisimura  *
     53      1.1  nisimura  * collect various mice and tablet parameters/protocol design
     54      1.1  nisimura  * and establish vsxxx.h
     55      1.1  nisimura  *
     56      1.1  nisimura  * XXX XXX XXX
     57      1.1  nisimura  */
     58      1.1  nisimura #define	VS_SELFTEST	'T'
     59      1.1  nisimura #define	VS_INCREMENTAL	'R'
     60      1.1  nisimura #define	VS_PROMPTING	'D'
     61      1.1  nisimura #define	VS_REQ_POSITION	'P'
     62      1.1  nisimura 
     63      1.1  nisimura #define	VS_MOUSE_REPSZ	3
     64      1.1  nisimura #define	VS_TABLET_REPSZ	5
     65      1.1  nisimura 
     66      1.1  nisimura /* first octet */
     67      1.1  nisimura #define	VS_START_FRAME	0x80
     68      1.1  nisimura #define	VS_R_BUTTON	0x01
     69      1.1  nisimura #define	VS_M_BUTTON	0x02
     70      1.1  nisimura #define	VS_L_BUTTON	0x04
     71      1.1  nisimura #define	VS_Y_SIGN	0x08
     72      1.1  nisimura #define	VS_X_SIGN	0x10
     73      1.1  nisimura 
     74      1.1  nisimura /* low order 4 bit of the second octet in a SELFTEST reply */
     75      1.1  nisimura #define	VS_MOUSE	0x2
     76      1.1  nisimura #define	VS_TABLET	0x4
     77      1.1  nisimura 
     78      1.1  nisimura extern struct cfdriver vsms_cd;
     79      1.1  nisimura 
     80      1.1  nisimura static int  vsxxx_enable __P((void *));
     81      1.1  nisimura static int  vsxxx_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
     82      1.1  nisimura static void vsxxx_disable __P((void *));
     83      1.1  nisimura 
     84      1.1  nisimura struct wsmouse_accessops vsxxx_accessops = {	/* EXPORT */
     85      1.1  nisimura 	vsxxx_enable,				/* MD? */
     86      1.1  nisimura 	vsxxx_ioctl,
     87      1.1  nisimura 	vsxxx_disable,				/* MD? */
     88      1.1  nisimura };
     89      1.1  nisimura 
     90      1.1  nisimura static int
     91      1.1  nisimura vsxxx_enable(v)
     92      1.1  nisimura 	void *v;
     93      1.1  nisimura {
     94      1.1  nisimura 	/* turn on the hardware? */
     95      1.1  nisimura 	((struct vsxxx_softc *)v)->sc_nbyte = 0;
     96      1.1  nisimura 	return 0;
     97      1.1  nisimura }
     98      1.1  nisimura 
     99      1.1  nisimura static void
    100      1.1  nisimura vsxxx_disable(v)
    101      1.1  nisimura 	void *v;
    102      1.1  nisimura {
    103      1.1  nisimura 	/* turn off the hardware? */
    104      1.1  nisimura }
    105      1.1  nisimura 
    106      1.1  nisimura /*ARGUSED*/
    107      1.1  nisimura static int
    108      1.1  nisimura vsxxx_ioctl(v, cmd, data, flag, p)
    109      1.1  nisimura 	void *v;
    110      1.1  nisimura 	u_long cmd;
    111      1.1  nisimura 	caddr_t data;
    112      1.1  nisimura 	int flag;
    113      1.1  nisimura 	struct proc *p;
    114      1.1  nisimura {
    115      1.1  nisimura 	if (cmd == WSMOUSEIO_GTYPE) {
    116      1.1  nisimura 		*(u_int *)data = WSMOUSE_TYPE_VSXXX;
    117      1.1  nisimura 		return 0;
    118      1.1  nisimura 	}
    119      1.1  nisimura 	return ENOTTY;
    120      1.1  nisimura }
    121      1.1  nisimura 
    122      1.1  nisimura /* EXPORT */ void
    123      1.1  nisimura vsxxx_input(data)
    124      1.1  nisimura 	int data;
    125      1.1  nisimura {
    126      1.1  nisimura 	struct vsxxx_softc *sc = (void *)vsms_cd.cd_devs[0];
    127      1.1  nisimura 	int x, y;
    128      1.1  nisimura 
    129      1.1  nisimura 	if (data & VS_START_FRAME)
    130      1.1  nisimura 		sc->sc_nbyte = 0;
    131      1.1  nisimura 
    132      1.1  nisimura 	sc->sc_report.raw[sc->sc_nbyte++] = data;
    133      1.1  nisimura 
    134      1.1  nisimura 	if (sc->sc_nbyte < VS_MOUSE_REPSZ)
    135      1.1  nisimura 		return;
    136      1.1  nisimura 	sc->sc_nbyte = 0;
    137      1.1  nisimura 
    138      1.1  nisimura 	x = sc->sc_report.ms.xpos;
    139      1.1  nisimura 	y = sc->sc_report.ms.ypos;
    140      1.1  nisimura 	if ((sc->sc_report.raw[0] & VS_X_SIGN) == 0)
    141      1.1  nisimura 		x = -x;
    142      1.1  nisimura 	if ((sc->sc_report.raw[0] & VS_Y_SIGN) != 0)
    143      1.1  nisimura 		y = -y;					/* Eeeh? */
    144      1.1  nisimura 	wsmouse_input(sc->sc_wsmousedev, sc->sc_report.raw[0] & 07, x, y, 0);
    145      1.1  nisimura }
    146