xref: /netbsd-src/sys/dev/dec/vsxxx.c (revision 413d532bcc3f62d122e56d92e13ac64825a40baf)
1 /* $NetBSD: vsxxx.c,v 1.11 2009/03/14 21:04:19 dsl 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.11 2009/03/14 21:04:19 dsl 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(void *v)
90 {
91 	/* turn on the hardware? */
92 	((struct vsxxx_softc *)v)->sc_nbyte = 0;
93 	return 0;
94 }
95 
96 static void
97 vsxxx_disable(void *v)
98 {
99 	/* turn off the hardware? */
100 }
101 
102 /*ARGUSED*/
103 static int
104 vsxxx_ioctl(void *v, u_long cmd, void *data, int flag, struct proc *p)
105 {
106 	if (cmd == WSMOUSEIO_GTYPE) {
107 		*(u_int *)data = WSMOUSE_TYPE_VSXXX;
108 		return 0;
109 	}
110 	return EPASSTHROUGH;
111 }
112 
113 /* EXPORT */ void
114 vsxxx_input(int data)
115 {
116 	struct vsxxx_softc *sc = device_lookup_private(&vsms_cd, 0);
117 	int x, y;
118 
119 	if (data & VS_START_FRAME)
120 		sc->sc_nbyte = 0;
121 
122 	sc->sc_report.raw[sc->sc_nbyte++] = data;
123 
124 	if (sc->sc_nbyte < VS_MOUSE_REPSZ)
125 		return;
126 	sc->sc_nbyte = 0;
127 
128 	x = sc->sc_report.ms.xpos;
129 	y = sc->sc_report.ms.ypos;
130 	if ((sc->sc_report.raw[0] & VS_X_SIGN) == 0)
131 		x = -x;
132 	if ((sc->sc_report.raw[0] & VS_Y_SIGN) != 0)
133 		y = -y;					/* Eeeh? */
134 	wsmouse_input(sc->sc_wsmousedev,
135 			sc->sc_report.raw[0] & 07,
136 			x, y, 0, 0,
137 			WSMOUSE_INPUT_DELTA);
138 }
139