xref: /netbsd-src/sys/dev/dec/vsxxx.c (revision 82b8caba92d0ece070500659c43d13d9ecc6921e)
1 /* $NetBSD: vsxxx.c,v 1.12 2017/10/28 04:53:54 riastradh 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.12 2017/10/28 04:53:54 riastradh 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 #include "ioconf.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 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
vsxxx_enable(void * v)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
vsxxx_disable(void * v)97 vsxxx_disable(void *v)
98 {
99 	/* turn off the hardware? */
100 }
101 
102 /*ARGUSED*/
103 static int
vsxxx_ioctl(void * v,u_long cmd,void * data,int flag,struct proc * p)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
vsxxx_input(int data)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