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