dzms.c revision 1.6 1 /* $NetBSD: dzms.c,v 1.6 2002/09/24 12:53:30 ad Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)ms.c 8.1 (Berkeley) 6/11/93
45 */
46
47 /*
48 * VSXXX mice attached to line 1 of the DZ*
49 */
50
51 #include <sys/cdefs.h>
52 __KERNEL_RCSID(0, "$NetBSD: dzms.c,v 1.6 2002/09/24 12:53:30 ad Exp $");
53
54 #include <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/device.h>
57 #include <sys/ioctl.h>
58 #include <sys/syslog.h>
59 #include <sys/kernel.h>
60 #include <sys/proc.h>
61 #include <sys/tty.h>
62
63 #include <machine/bus.h>
64
65 #include <dev/dec/dzreg.h>
66 #include <dev/dec/dzvar.h>
67 #include <dev/dec/dzkbdvar.h>
68 #include <dev/dec/lk201.h>
69
70 #include <dev/wscons/wsconsio.h>
71 #include <dev/wscons/wsmousevar.h>
72
73 #include "locators.h"
74
75 struct dzms_softc { /* driver status information */
76 struct device dzms_dev; /* required first: base device */
77 struct dz_linestate *dzms_ls;
78
79 int sc_enabled; /* input enabled? */
80 int sc_selftest;
81
82 int inputstate;
83 u_int buttons;
84 int dx, dy;
85
86 struct device *sc_wsmousedev;
87 };
88
89 static int dzms_match __P((struct device *, struct cfdata *, void *));
90 static void dzms_attach __P((struct device *, struct device *, void *));
91 static int dzms_input __P((void *, int));
92
93 struct cfattach dzms_ca = {
94 sizeof(struct dzms_softc), dzms_match, dzms_attach,
95 };
96
97 static int dzms_enable __P((void *));
98 static int dzms_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
99 static void dzms_disable __P((void *));
100
101 const struct wsmouse_accessops dzms_accessops = {
102 dzms_enable,
103 dzms_ioctl,
104 dzms_disable,
105 };
106
107 static int
108 dzms_match(parent, cf, aux)
109 struct device *parent;
110 struct cfdata *cf;
111 void *aux;
112 {
113 struct dzkm_attach_args *daa = aux;
114
115 /* Exact match is better than wildcard. */
116 if (cf->cf_loc[DZCF_LINE] == daa->daa_line)
117 return 2;
118
119 /* This driver accepts wildcard. */
120 if (cf->cf_loc[DZCF_LINE] == DZCF_LINE_DEFAULT)
121 return 1;
122
123 return 0;
124 }
125
126 static void
127 dzms_attach(parent, self, aux)
128 struct device *parent, *self;
129 void *aux;
130 {
131 struct dz_softc *dz = (void *)parent;
132 struct dzms_softc *dzms = (void *)self;
133 struct dzkm_attach_args *daa = aux;
134 struct dz_linestate *ls;
135 struct wsmousedev_attach_args a;
136
137 dz->sc_dz[daa->daa_line].dz_catch = dzms_input;
138 dz->sc_dz[daa->daa_line].dz_private = dzms;
139 ls = &dz->sc_dz[daa->daa_line];
140 dzms->dzms_ls = ls;
141
142 printf("\n");
143
144 a.accessops = &dzms_accessops;
145 a.accesscookie = dzms;
146
147 dzms->sc_enabled = 0;
148 dzms->sc_selftest = 0;
149 dzms->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
150 }
151
152 static int
153 dzms_enable(v)
154 void *v;
155 {
156 struct dzms_softc *sc = v;
157
158 if (sc->sc_enabled)
159 return EBUSY;
160
161 sc->sc_selftest = 4; /* wait for 4 byte reply upto 1/2 sec */
162 dzputc(sc->dzms_ls, MOUSE_SELF_TEST);
163 (void)tsleep(dzms_enable, TTIPRI, "dzmsopen", hz / 2);
164 if (sc->sc_selftest != 0) {
165 sc->sc_selftest = 0;
166 return ENXIO;
167 }
168 DELAY(150);
169 dzputc(sc->dzms_ls, MOUSE_INCREMENTAL);
170 sc->sc_enabled = 1;
171 sc->inputstate = 0;
172 return 0;
173 }
174
175 static void
176 dzms_disable(v)
177 void *v;
178 {
179 struct dzms_softc *sc = v;
180
181 sc->sc_enabled = 0;
182 }
183
184 static int
185 dzms_ioctl(v, cmd, data, flag, p)
186 void *v;
187 u_long cmd;
188 caddr_t data;
189 int flag;
190 struct proc *p;
191 {
192 if (cmd == WSMOUSEIO_GTYPE) {
193 *(u_int *)data = WSMOUSE_TYPE_VSXXX;
194 return 0;
195 }
196 return EPASSTHROUGH;
197 }
198
199 static int
200 dzms_input(vsc, data)
201 void *vsc;
202 int data;
203 {
204 struct dzms_softc *sc = vsc;
205
206 if (sc->sc_enabled == 0) {
207 if (sc->sc_selftest > 0) {
208 sc->sc_selftest -= 1;
209 if (sc->sc_selftest == 0)
210 wakeup(dzms_enable);
211 }
212 return (1);
213 }
214
215 #define WSMS_BUTTON1 0x01
216 #define WSMS_BUTTON2 0x02
217 #define WSMS_BUTTON3 0x04
218
219 if ((data & MOUSE_START_FRAME) != 0)
220 sc->inputstate = 1;
221 else
222 sc->inputstate++;
223
224 if (sc->inputstate == 1) {
225 sc->buttons = 0;
226 if ((data & LEFT_BUTTON) != 0)
227 sc->buttons |= WSMS_BUTTON1;
228 if ((data & MIDDLE_BUTTON) != 0)
229 sc->buttons |= WSMS_BUTTON2;
230 if ((data & RIGHT_BUTTON) != 0)
231 sc->buttons |= WSMS_BUTTON3;
232
233 sc->dx = data & MOUSE_X_SIGN;
234 sc->dy = data & MOUSE_Y_SIGN;
235 } else if (sc->inputstate == 2) {
236 if (sc->dx == 0)
237 sc->dx = -data;
238 else
239 sc->dx = data;
240 } else if (sc->inputstate == 3) {
241 sc->inputstate = 0;
242 if (sc->dy == 0)
243 sc->dy = -data;
244 else
245 sc->dy = data;
246 wsmouse_input(sc->sc_wsmousedev, sc->buttons,
247 sc->dx, sc->dy, 0, WSMOUSE_INPUT_DELTA);
248 }
249
250 return(1);
251 }
252
253