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