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