FreeBSD/Linux Kernel Cross Reference
sys/dev/dec/vsxxx.c
1 /* $NetBSD: vsxxx.c,v 1.10 2008/06/12 21:51:12 cegger 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.10 2008/06/12 21:51:12 cegger 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(int data)
122 {
123 struct vsxxx_softc *sc = device_lookup_private(&vsms_cd, 0);
124 int x, y;
125
126 if (data & VS_START_FRAME)
127 sc->sc_nbyte = 0;
128
129 sc->sc_report.raw[sc->sc_nbyte++] = data;
130
131 if (sc->sc_nbyte < VS_MOUSE_REPSZ)
132 return;
133 sc->sc_nbyte = 0;
134
135 x = sc->sc_report.ms.xpos;
136 y = sc->sc_report.ms.ypos;
137 if ((sc->sc_report.raw[0] & VS_X_SIGN) == 0)
138 x = -x;
139 if ((sc->sc_report.raw[0] & VS_Y_SIGN) != 0)
140 y = -y; /* Eeeh? */
141 wsmouse_input(sc->sc_wsmousedev,
142 sc->sc_report.raw[0] & 07,
143 x, y, 0, 0,
144 WSMOUSE_INPUT_DELTA);
145 }
Cache object: 59b60f6db310499e9e89eab37b909a6c
|