dzms.c revision 1.4 1 /* $NetBSD: dzms.c,v 1.4 2002/03/17 19:40:54 atatat 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.4 2002/03/17 19:40:54 atatat 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
60 #include <machine/bus.h>
61
62 #include <dev/dec/dzreg.h>
63 #include <dev/dec/dzvar.h>
64 #include <dev/dec/dzkbdvar.h>
65 #include <dev/dec/lk201.h>
66
67 #include <dev/wscons/wsconsio.h>
68 #include <dev/wscons/wsmousevar.h>
69
70 #include "locators.h"
71
72 struct dzms_softc { /* driver status information */
73 struct device dzms_dev; /* required first: base device */
74 struct dz_linestate *dzms_ls;
75
76 int sc_enabled; /* input enabled? */
77 int self_test;
78
79 int inputstate;
80 u_int buttons;
81 signed char dx;
82 signed char dy;
83
84 struct device *sc_wsmousedev;
85 };
86
87 static int dzms_match __P((struct device *, struct cfdata *, void *));
88 static void dzms_attach __P((struct device *, struct device *, void *));
89 static int dzms_input __P((void *, int));
90
91 struct cfattach dzms_ca = {
92 sizeof(struct dzms_softc), dzms_match, dzms_attach,
93 };
94
95 static int dzms_enable __P((void *));
96 static int dzms_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
97 static void dzms_disable __P((void *));
98
99 const struct wsmouse_accessops dzms_accessops = {
100 dzms_enable,
101 dzms_ioctl,
102 dzms_disable,
103 };
104
105 static int
106 dzms_match(parent, cf, aux)
107 struct device *parent;
108 struct cfdata *cf;
109 void *aux;
110 {
111 struct dzkm_attach_args *daa = aux;
112
113 /* Exact match is better than wildcard. */
114 if (cf->cf_loc[DZCF_LINE] == daa->daa_line)
115 return 2;
116
117 /* This driver accepts wildcard. */
118 if (cf->cf_loc[DZCF_LINE] == DZCF_LINE_DEFAULT)
119 return 1;
120
121 return 0;
122 }
123
124 static void
125 dzms_attach(parent, self, aux)
126 struct device *parent, *self;
127 void *aux;
128 {
129 struct dz_softc *dz = (void *)parent;
130 struct dzms_softc *dzms = (void *)self;
131 struct dzkm_attach_args *daa = aux;
132 struct dz_linestate *ls;
133 struct wsmousedev_attach_args a;
134
135 dz->sc_dz[daa->daa_line].dz_catch = dzms_input;
136 dz->sc_dz[daa->daa_line].dz_private = dzms;
137 ls = &dz->sc_dz[daa->daa_line];
138 dzms->dzms_ls = ls;
139
140 printf("\n");
141
142 a.accessops = &dzms_accessops;
143 a.accesscookie = dzms;
144
145 dzms->sc_enabled = 0;
146 dzms->self_test = 0;
147 dzms->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
148 }
149
150 static int
151 dzms_enable(v)
152 void *v;
153 {
154 struct dzms_softc *sc = v;
155
156 if (sc->sc_enabled)
157 return EBUSY;
158
159 /* XXX mice presence test should be done in match/attach context XXX */
160 sc->self_test = 1;
161 dzputc(sc->dzms_ls, MOUSE_SELF_TEST);
162 DELAY(100000);
163 if (sc->self_test < 0) {
164 sc->self_test = 0;
165 return EBUSY;
166 } else if (sc->self_test == 5) {
167 sc->self_test = 0;
168 sc->sc_enabled = 1;
169 }
170 sc->inputstate = 0;
171
172 dzputc(sc->dzms_ls, MOUSE_INCREMENTAL);
173
174 return 0;
175 }
176
177 static void
178 dzms_disable(v)
179 void *v;
180 {
181 struct dzms_softc *sc = v;
182
183 sc->sc_enabled = 0;
184 }
185
186 static int
187 dzms_ioctl(v, cmd, data, flag, p)
188 void *v;
189 u_long cmd;
190 caddr_t data;
191 int flag;
192 struct proc *p;
193 {
194 if (cmd == WSMOUSEIO_GTYPE) {
195 *(u_int *)data = WSMOUSE_TYPE_VSXXX;
196 return 0;
197 }
198 return EPASSTHROUGH;
199 }
200
201 static int
202 dzms_input(vsc, data)
203 void *vsc;
204 int data;
205 {
206 struct dzms_softc *sc = vsc;
207
208 /* XXX mice presence test should be done in match/attach context XXX */
209 if (!sc->sc_enabled) {
210 if (sc->self_test > 0) {
211 if (data < 0) {
212 printf("Timeout on 1st byte of mouse self-test report\n");
213 sc->self_test = -1;
214 } else {
215 sc->self_test++;
216 }
217 }
218 if (sc->self_test == 3) {
219 if ((data & 0x0f) != 0x2) {
220 printf("We don't have a mouse!!!\n");
221 sc->self_test = -1;
222 }
223 }
224 /* Interrupts are not expected. Discard the byte. */
225 return(1);
226 }
227
228 #define WSMS_BUTTON1 0x01
229 #define WSMS_BUTTON2 0x02
230 #define WSMS_BUTTON3 0x04
231
232 if ((data & MOUSE_START_FRAME) != 0)
233 sc->inputstate = 1;
234 else
235 sc->inputstate++;
236
237 if (sc->inputstate == 1) {
238 sc->buttons = 0;
239 if ((data & LEFT_BUTTON) != 0)
240 sc->buttons |= WSMS_BUTTON1;
241 if ((data & MIDDLE_BUTTON) != 0)
242 sc->buttons |= WSMS_BUTTON2;
243 if ((data & RIGHT_BUTTON) != 0)
244 sc->buttons |= WSMS_BUTTON3;
245
246 sc->dx = data & MOUSE_X_SIGN;
247 sc->dy = data & MOUSE_Y_SIGN;
248 } else if (sc->inputstate == 2) {
249 if (sc->dx == 0)
250 sc->dx = -data;
251 else
252 sc->dx = data;
253 } else if (sc->inputstate == 3) {
254 sc->inputstate = 0;
255 if (sc->dy == 0)
256 sc->dy = -data;
257 else
258 sc->dy = data;
259 wsmouse_input(sc->sc_wsmousedev, sc->buttons,
260 sc->dx, sc->dy, 0, WSMOUSE_INPUT_DELTA);
261 }
262
263 return(1);
264 }
265
266