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