ams.c revision 1.12.6.3 1 1.12.6.3 nathanw /* $NetBSD: ams.c,v 1.12.6.3 2002/10/18 02:38:33 nathanw Exp $ */
2 1.12.6.2 nathanw
3 1.12.6.2 nathanw /*
4 1.12.6.2 nathanw * Copyright (C) 1998 Colin Wood
5 1.12.6.2 nathanw * All rights reserved.
6 1.12.6.2 nathanw *
7 1.12.6.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.12.6.2 nathanw * modification, are permitted provided that the following conditions
9 1.12.6.2 nathanw * are met:
10 1.12.6.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.12.6.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.12.6.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.12.6.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.12.6.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.12.6.2 nathanw * 3. All advertising materials mentioning features or use of this software
16 1.12.6.2 nathanw * must display the following acknowledgement:
17 1.12.6.2 nathanw * This product includes software developed by Colin Wood.
18 1.12.6.2 nathanw * 4. The name of the author may not be used to endorse or promote products
19 1.12.6.2 nathanw * derived from this software without specific prior written permission.
20 1.12.6.2 nathanw *
21 1.12.6.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.12.6.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.12.6.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.12.6.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.12.6.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.12.6.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.12.6.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.12.6.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.12.6.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 1.12.6.2 nathanw * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.12.6.2 nathanw */
32 1.12.6.2 nathanw
33 1.12.6.2 nathanw #include <sys/param.h>
34 1.12.6.2 nathanw #include <sys/device.h>
35 1.12.6.2 nathanw #include <sys/fcntl.h>
36 1.12.6.2 nathanw #include <sys/poll.h>
37 1.12.6.2 nathanw #include <sys/select.h>
38 1.12.6.2 nathanw #include <sys/proc.h>
39 1.12.6.2 nathanw #include <sys/signalvar.h>
40 1.12.6.2 nathanw #include <sys/systm.h>
41 1.12.6.2 nathanw
42 1.12.6.2 nathanw #include <machine/autoconf.h>
43 1.12.6.2 nathanw
44 1.12.6.2 nathanw #include <dev/wscons/wsconsio.h>
45 1.12.6.2 nathanw #include <dev/wscons/wsmousevar.h>
46 1.12.6.2 nathanw
47 1.12.6.2 nathanw #include <macppc/dev/adbvar.h>
48 1.12.6.2 nathanw #include <macppc/dev/aedvar.h>
49 1.12.6.2 nathanw #include <macppc/dev/amsvar.h>
50 1.12.6.2 nathanw
51 1.12.6.2 nathanw #include "aed.h"
52 1.12.6.2 nathanw
53 1.12.6.2 nathanw /*
54 1.12.6.2 nathanw * Function declarations.
55 1.12.6.2 nathanw */
56 1.12.6.2 nathanw static int amsmatch __P((struct device *, struct cfdata *, void *));
57 1.12.6.2 nathanw static void amsattach __P((struct device *, struct device *, void *));
58 1.12.6.2 nathanw static void ems_init __P((struct ams_softc *));
59 1.12.6.2 nathanw static void ms_processevent __P((adb_event_t *event, struct ams_softc *));
60 1.12.6.2 nathanw
61 1.12.6.2 nathanw /* Driver definition. */
62 1.12.6.3 nathanw CFATTACH_DECL(ams, sizeof(struct ams_softc),
63 1.12.6.3 nathanw amsmatch, amsattach, NULL, NULL);
64 1.12.6.2 nathanw
65 1.12.6.2 nathanw int ams_enable __P((void *));
66 1.12.6.2 nathanw int ams_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
67 1.12.6.2 nathanw void ams_disable __P((void *));
68 1.12.6.2 nathanw
69 1.12.6.2 nathanw const struct wsmouse_accessops ams_accessops = {
70 1.12.6.2 nathanw ams_enable,
71 1.12.6.2 nathanw ams_ioctl,
72 1.12.6.2 nathanw ams_disable,
73 1.12.6.2 nathanw };
74 1.12.6.2 nathanw
75 1.12.6.2 nathanw static int
76 1.12.6.2 nathanw amsmatch(parent, cf, aux)
77 1.12.6.2 nathanw struct device *parent;
78 1.12.6.2 nathanw struct cfdata *cf;
79 1.12.6.2 nathanw void *aux;
80 1.12.6.2 nathanw {
81 1.12.6.2 nathanw struct adb_attach_args *aa_args = aux;
82 1.12.6.2 nathanw
83 1.12.6.2 nathanw if (aa_args->origaddr == ADBADDR_MS)
84 1.12.6.2 nathanw return 1;
85 1.12.6.2 nathanw else
86 1.12.6.2 nathanw return 0;
87 1.12.6.2 nathanw }
88 1.12.6.2 nathanw
89 1.12.6.2 nathanw static void
90 1.12.6.2 nathanw amsattach(parent, self, aux)
91 1.12.6.2 nathanw struct device *parent, *self;
92 1.12.6.2 nathanw void *aux;
93 1.12.6.2 nathanw {
94 1.12.6.2 nathanw ADBSetInfoBlock adbinfo;
95 1.12.6.2 nathanw struct ams_softc *sc = (struct ams_softc *)self;
96 1.12.6.2 nathanw struct adb_attach_args *aa_args = aux;
97 1.12.6.2 nathanw int error;
98 1.12.6.2 nathanw struct wsmousedev_attach_args a;
99 1.12.6.2 nathanw
100 1.12.6.2 nathanw sc->origaddr = aa_args->origaddr;
101 1.12.6.2 nathanw sc->adbaddr = aa_args->adbaddr;
102 1.12.6.2 nathanw sc->handler_id = aa_args->handler_id;
103 1.12.6.2 nathanw
104 1.12.6.2 nathanw sc->sc_class = MSCLASS_MOUSE;
105 1.12.6.2 nathanw sc->sc_buttons = 1;
106 1.12.6.2 nathanw sc->sc_res = 100;
107 1.12.6.2 nathanw sc->sc_devid[0] = 0;
108 1.12.6.2 nathanw sc->sc_devid[4] = 0;
109 1.12.6.2 nathanw
110 1.12.6.2 nathanw adbinfo.siServiceRtPtr = (Ptr)ms_adbcomplete;
111 1.12.6.2 nathanw adbinfo.siDataAreaAddr = (caddr_t)sc;
112 1.12.6.2 nathanw
113 1.12.6.2 nathanw ems_init(sc);
114 1.12.6.2 nathanw
115 1.12.6.2 nathanw /* print out the type of mouse we have */
116 1.12.6.2 nathanw switch (sc->handler_id) {
117 1.12.6.2 nathanw case ADBMS_100DPI:
118 1.12.6.2 nathanw printf("%d-button, %d dpi mouse\n", sc->sc_buttons,
119 1.12.6.2 nathanw (int)(sc->sc_res));
120 1.12.6.2 nathanw break;
121 1.12.6.2 nathanw case ADBMS_200DPI:
122 1.12.6.2 nathanw sc->sc_res = 200;
123 1.12.6.2 nathanw printf("%d-button, %d dpi mouse\n", sc->sc_buttons,
124 1.12.6.2 nathanw (int)(sc->sc_res));
125 1.12.6.2 nathanw break;
126 1.12.6.2 nathanw case ADBMS_MSA3:
127 1.12.6.2 nathanw printf("Mouse Systems A3 mouse, %d-button, %d dpi\n",
128 1.12.6.2 nathanw sc->sc_buttons, (int)(sc->sc_res));
129 1.12.6.2 nathanw break;
130 1.12.6.2 nathanw case ADBMS_USPEED:
131 1.12.6.2 nathanw printf("MicroSpeed mouse, default parameters\n");
132 1.12.6.2 nathanw break;
133 1.12.6.2 nathanw case ADBMS_UCONTOUR:
134 1.12.6.2 nathanw printf("Contour mouse, default parameters\n");
135 1.12.6.2 nathanw break;
136 1.12.6.2 nathanw case ADBMS_TURBO:
137 1.12.6.2 nathanw printf("Kensington Turbo Mouse\n");
138 1.12.6.2 nathanw break;
139 1.12.6.2 nathanw case ADBMS_EXTENDED:
140 1.12.6.2 nathanw if (sc->sc_devid[0] == '\0') {
141 1.12.6.2 nathanw printf("Logitech ");
142 1.12.6.2 nathanw switch (sc->sc_class) {
143 1.12.6.2 nathanw case MSCLASS_MOUSE:
144 1.12.6.2 nathanw printf("MouseMan (non-EMP) mouse");
145 1.12.6.2 nathanw break;
146 1.12.6.2 nathanw case MSCLASS_TRACKBALL:
147 1.12.6.2 nathanw printf("TrackMan (non-EMP) trackball");
148 1.12.6.2 nathanw break;
149 1.12.6.2 nathanw default:
150 1.12.6.2 nathanw printf("non-EMP relative positioning device");
151 1.12.6.2 nathanw break;
152 1.12.6.2 nathanw }
153 1.12.6.2 nathanw printf("\n");
154 1.12.6.2 nathanw } else {
155 1.12.6.2 nathanw printf("EMP ");
156 1.12.6.2 nathanw switch (sc->sc_class) {
157 1.12.6.2 nathanw case MSCLASS_TABLET:
158 1.12.6.2 nathanw printf("tablet");
159 1.12.6.2 nathanw break;
160 1.12.6.2 nathanw case MSCLASS_MOUSE:
161 1.12.6.2 nathanw printf("mouse");
162 1.12.6.2 nathanw break;
163 1.12.6.2 nathanw case MSCLASS_TRACKBALL:
164 1.12.6.2 nathanw printf("trackball");
165 1.12.6.2 nathanw break;
166 1.12.6.2 nathanw case MSCLASS_TRACKPAD:
167 1.12.6.2 nathanw printf("trackpad");
168 1.12.6.2 nathanw break;
169 1.12.6.2 nathanw default:
170 1.12.6.2 nathanw printf("unknown device");
171 1.12.6.2 nathanw break;
172 1.12.6.2 nathanw }
173 1.12.6.2 nathanw printf(" <%s> %d-button, %d dpi\n", sc->sc_devid,
174 1.12.6.2 nathanw sc->sc_buttons, (int)(sc->sc_res));
175 1.12.6.2 nathanw }
176 1.12.6.2 nathanw break;
177 1.12.6.2 nathanw default:
178 1.12.6.2 nathanw printf("relative positioning device (mouse?) (%d)\n",
179 1.12.6.2 nathanw sc->handler_id);
180 1.12.6.2 nathanw break;
181 1.12.6.2 nathanw }
182 1.12.6.2 nathanw error = SetADBInfo(&adbinfo, sc->adbaddr);
183 1.12.6.2 nathanw #ifdef ADB_DEBUG
184 1.12.6.2 nathanw if (adb_debug)
185 1.12.6.2 nathanw printf("ams: returned %d from SetADBInfo\n", error);
186 1.12.6.2 nathanw #endif
187 1.12.6.2 nathanw
188 1.12.6.2 nathanw a.accessops = &ams_accessops;
189 1.12.6.2 nathanw a.accesscookie = sc;
190 1.12.6.2 nathanw sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
191 1.12.6.2 nathanw }
192 1.12.6.2 nathanw
193 1.12.6.2 nathanw
194 1.12.6.2 nathanw /*
195 1.12.6.2 nathanw * Initialize extended mouse support -- probes devices as described
196 1.12.6.2 nathanw * in Inside Macintosh: Devices, Chapter 5 "ADB Manager".
197 1.12.6.2 nathanw *
198 1.12.6.2 nathanw * Extended Mouse Protocol is documented in TechNote HW1:
199 1.12.6.2 nathanw * "ADB - The Untold Story: Space Aliens Ate My Mouse"
200 1.12.6.2 nathanw *
201 1.12.6.2 nathanw * Supports: Extended Mouse Protocol, MicroSpeed Mouse Deluxe,
202 1.12.6.2 nathanw * Mouse Systems A^3 Mouse, Logitech non-EMP MouseMan
203 1.12.6.2 nathanw */
204 1.12.6.2 nathanw void
205 1.12.6.2 nathanw ems_init(sc)
206 1.12.6.2 nathanw struct ams_softc *sc;
207 1.12.6.2 nathanw {
208 1.12.6.2 nathanw int adbaddr;
209 1.12.6.2 nathanw short cmd;
210 1.12.6.2 nathanw u_char buffer[9];
211 1.12.6.2 nathanw
212 1.12.6.2 nathanw adbaddr = sc->adbaddr;
213 1.12.6.2 nathanw if (sc->origaddr != ADBADDR_MS)
214 1.12.6.2 nathanw return;
215 1.12.6.2 nathanw if (sc->handler_id == ADBMS_USPEED ||
216 1.12.6.2 nathanw sc->handler_id == ADBMS_UCONTOUR) {
217 1.12.6.2 nathanw /* Found MicroSpeed Mouse Deluxe Mac or Contour Mouse */
218 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 1);
219 1.12.6.2 nathanw
220 1.12.6.2 nathanw /*
221 1.12.6.2 nathanw * To setup the MicroSpeed or the Contour, it appears
222 1.12.6.2 nathanw * that we can send the following command to the mouse
223 1.12.6.2 nathanw * and then expect data back in the form:
224 1.12.6.2 nathanw * buffer[0] = 4 (bytes)
225 1.12.6.2 nathanw * buffer[1], buffer[2] as std. mouse
226 1.12.6.2 nathanw * buffer[3] = buffer[4] = 0xff when no buttons
227 1.12.6.2 nathanw * are down. When button N down, bit N is clear.
228 1.12.6.2 nathanw * buffer[4]'s locking mask enables a
229 1.12.6.2 nathanw * click to toggle the button down state--sort of
230 1.12.6.2 nathanw * like the "Easy Access" shift/control/etc. keys.
231 1.12.6.2 nathanw * buffer[3]'s alternative speed mask enables using
232 1.12.6.2 nathanw * different speed when the corr. button is down
233 1.12.6.2 nathanw */
234 1.12.6.2 nathanw buffer[0] = 4;
235 1.12.6.2 nathanw buffer[1] = 0x00; /* Alternative speed */
236 1.12.6.2 nathanw buffer[2] = 0x00; /* speed = maximum */
237 1.12.6.2 nathanw buffer[3] = 0x10; /* enable extended protocol,
238 1.12.6.2 nathanw * lower bits = alt. speed mask
239 1.12.6.2 nathanw * = 0000b
240 1.12.6.2 nathanw */
241 1.12.6.2 nathanw buffer[4] = 0x07; /* Locking mask = 0000b,
242 1.12.6.2 nathanw * enable buttons = 0111b
243 1.12.6.2 nathanw */
244 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
245 1.12.6.2 nathanw
246 1.12.6.2 nathanw sc->sc_buttons = 3;
247 1.12.6.2 nathanw sc->sc_res = 200;
248 1.12.6.2 nathanw return;
249 1.12.6.2 nathanw }
250 1.12.6.2 nathanw if (sc->handler_id == ADBMS_TURBO) {
251 1.12.6.2 nathanw /* Found Kensington Turbo Mouse */
252 1.12.6.2 nathanw static u_char data1[] =
253 1.12.6.2 nathanw { 8, 0xe7, 0x8c, 0, 0, 0, 0xff, 0xff, 0x94 };
254 1.12.6.2 nathanw static u_char data2[] =
255 1.12.6.2 nathanw { 8, 0xa5, 0x14, 0, 0, 0x69, 0xff, 0xff, 0x27 };
256 1.12.6.2 nathanw
257 1.12.6.2 nathanw buffer[0] = 0;
258 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, ADBFLUSH(adbaddr));
259 1.12.6.2 nathanw
260 1.12.6.2 nathanw adb_op_sync((Ptr)data1, (Ptr)0, (Ptr)0, ADBLISTEN(adbaddr, 2));
261 1.12.6.2 nathanw
262 1.12.6.2 nathanw buffer[0] = 0;
263 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, ADBFLUSH(adbaddr));
264 1.12.6.2 nathanw
265 1.12.6.2 nathanw adb_op_sync((Ptr)data2, (Ptr)0, (Ptr)0, ADBLISTEN(adbaddr, 2));
266 1.12.6.2 nathanw return;
267 1.12.6.2 nathanw }
268 1.12.6.2 nathanw if ((sc->handler_id == ADBMS_100DPI) ||
269 1.12.6.2 nathanw (sc->handler_id == ADBMS_200DPI)) {
270 1.12.6.2 nathanw /* found a mouse */
271 1.12.6.2 nathanw cmd = ADBTALK(adbaddr, 3);
272 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd)) {
273 1.12.6.2 nathanw #ifdef ADB_DEBUG
274 1.12.6.2 nathanw if (adb_debug)
275 1.12.6.2 nathanw printf("adb: ems_init timed out\n");
276 1.12.6.2 nathanw #endif
277 1.12.6.2 nathanw return;
278 1.12.6.2 nathanw }
279 1.12.6.2 nathanw
280 1.12.6.2 nathanw /* Attempt to initialize Extended Mouse Protocol */
281 1.12.6.2 nathanw buffer[2] = 4; /* make handler ID 4 */
282 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 3);
283 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd)) {
284 1.12.6.2 nathanw #ifdef ADB_DEBUG
285 1.12.6.2 nathanw if (adb_debug)
286 1.12.6.2 nathanw printf("adb: ems_init timed out\n");
287 1.12.6.2 nathanw #endif
288 1.12.6.2 nathanw return;
289 1.12.6.2 nathanw }
290 1.12.6.2 nathanw
291 1.12.6.2 nathanw /*
292 1.12.6.2 nathanw * Check to see if successful, if not
293 1.12.6.2 nathanw * try to initialize it as other types
294 1.12.6.2 nathanw */
295 1.12.6.2 nathanw cmd = ADBTALK(adbaddr, 3);
296 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) == 0 &&
297 1.12.6.2 nathanw buffer[2] == ADBMS_EXTENDED) {
298 1.12.6.2 nathanw sc->handler_id = ADBMS_EXTENDED;
299 1.12.6.2 nathanw cmd = ADBTALK(adbaddr, 1);
300 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd)) {
301 1.12.6.2 nathanw #ifdef ADB_DEBUG
302 1.12.6.2 nathanw if (adb_debug)
303 1.12.6.2 nathanw printf("adb: ems_init timed out\n");
304 1.12.6.2 nathanw #endif
305 1.12.6.2 nathanw } else if (buffer[0] == 8) {
306 1.12.6.2 nathanw /* we have a true EMP device */
307 1.12.6.2 nathanw sc->sc_class = buffer[7];
308 1.12.6.2 nathanw sc->sc_buttons = buffer[8];
309 1.12.6.2 nathanw sc->sc_res = (int)*(short *)&buffer[5];
310 1.12.6.2 nathanw memcpy(sc->sc_devid, &(buffer[1]), 4);
311 1.12.6.2 nathanw } else if (buffer[1] == 0x9a &&
312 1.12.6.2 nathanw ((buffer[2] == 0x20) || (buffer[2] == 0x21))) {
313 1.12.6.2 nathanw /*
314 1.12.6.2 nathanw * Set up non-EMP Mouseman/Trackman to put
315 1.12.6.2 nathanw * button bits in 3rd byte instead of sending
316 1.12.6.2 nathanw * via pseudo keyboard device.
317 1.12.6.2 nathanw */
318 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 1);
319 1.12.6.2 nathanw buffer[0]=2;
320 1.12.6.2 nathanw buffer[1]=0x00;
321 1.12.6.2 nathanw buffer[2]=0x81;
322 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
323 1.12.6.2 nathanw
324 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 1);
325 1.12.6.2 nathanw buffer[0]=2;
326 1.12.6.2 nathanw buffer[1]=0x01;
327 1.12.6.2 nathanw buffer[2]=0x81;
328 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
329 1.12.6.2 nathanw
330 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 1);
331 1.12.6.2 nathanw buffer[0]=2;
332 1.12.6.2 nathanw buffer[1]=0x02;
333 1.12.6.2 nathanw buffer[2]=0x81;
334 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
335 1.12.6.2 nathanw
336 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 1);
337 1.12.6.2 nathanw buffer[0]=2;
338 1.12.6.2 nathanw buffer[1]=0x03;
339 1.12.6.2 nathanw buffer[2]=0x38;
340 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
341 1.12.6.2 nathanw
342 1.12.6.2 nathanw sc->sc_buttons = 3;
343 1.12.6.2 nathanw sc->sc_res = 400;
344 1.12.6.2 nathanw if (buffer[2] == 0x21)
345 1.12.6.2 nathanw sc->sc_class = MSCLASS_TRACKBALL;
346 1.12.6.2 nathanw else
347 1.12.6.2 nathanw sc->sc_class = MSCLASS_MOUSE;
348 1.12.6.2 nathanw } else
349 1.12.6.2 nathanw /* unknown device? */;
350 1.12.6.2 nathanw } else {
351 1.12.6.2 nathanw /* Attempt to initialize as an A3 mouse */
352 1.12.6.2 nathanw buffer[2] = 0x03; /* make handler ID 3 */
353 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 3);
354 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd)) {
355 1.12.6.2 nathanw #ifdef ADB_DEBUG
356 1.12.6.2 nathanw if (adb_debug)
357 1.12.6.2 nathanw printf("adb: ems_init timed out\n");
358 1.12.6.2 nathanw #endif
359 1.12.6.2 nathanw return;
360 1.12.6.2 nathanw }
361 1.12.6.2 nathanw
362 1.12.6.2 nathanw /*
363 1.12.6.2 nathanw * Check to see if successful, if not
364 1.12.6.2 nathanw * try to initialize it as other types
365 1.12.6.2 nathanw */
366 1.12.6.2 nathanw cmd = ADBTALK(adbaddr, 3);
367 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) == 0
368 1.12.6.2 nathanw && buffer[2] == ADBMS_MSA3) {
369 1.12.6.2 nathanw sc->handler_id = ADBMS_MSA3;
370 1.12.6.2 nathanw /* Initialize as above */
371 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 2);
372 1.12.6.2 nathanw /* listen 2 */
373 1.12.6.2 nathanw buffer[0] = 3;
374 1.12.6.2 nathanw buffer[1] = 0x00;
375 1.12.6.2 nathanw /* Irrelevant, buffer has 0x77 */
376 1.12.6.2 nathanw buffer[2] = 0x07;
377 1.12.6.2 nathanw /*
378 1.12.6.2 nathanw * enable 3 button mode = 0111b,
379 1.12.6.2 nathanw * speed = normal
380 1.12.6.2 nathanw */
381 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
382 1.12.6.2 nathanw sc->sc_buttons = 3;
383 1.12.6.2 nathanw sc->sc_res = 300;
384 1.12.6.2 nathanw } else {
385 1.12.6.2 nathanw /* No special support for this mouse */
386 1.12.6.2 nathanw }
387 1.12.6.2 nathanw }
388 1.12.6.2 nathanw }
389 1.12.6.2 nathanw }
390 1.12.6.2 nathanw
391 1.12.6.2 nathanw /*
392 1.12.6.2 nathanw * Handle putting the mouse data received from the ADB into
393 1.12.6.2 nathanw * an ADB event record.
394 1.12.6.2 nathanw */
395 1.12.6.2 nathanw void
396 1.12.6.2 nathanw ms_adbcomplete(buffer, data_area, adb_command)
397 1.12.6.2 nathanw caddr_t buffer;
398 1.12.6.2 nathanw caddr_t data_area;
399 1.12.6.2 nathanw int adb_command;
400 1.12.6.2 nathanw {
401 1.12.6.2 nathanw adb_event_t event;
402 1.12.6.2 nathanw struct ams_softc *sc;
403 1.12.6.2 nathanw int adbaddr;
404 1.12.6.2 nathanw #ifdef ADB_DEBUG
405 1.12.6.2 nathanw int i;
406 1.12.6.2 nathanw
407 1.12.6.2 nathanw if (adb_debug)
408 1.12.6.2 nathanw printf("adb: transaction completion\n");
409 1.12.6.2 nathanw #endif
410 1.12.6.2 nathanw
411 1.12.6.2 nathanw adbaddr = ADB_CMDADDR(adb_command);
412 1.12.6.2 nathanw sc = (struct ams_softc *)data_area;
413 1.12.6.2 nathanw
414 1.12.6.2 nathanw if ((sc->handler_id == ADBMS_EXTENDED) && (sc->sc_devid[0] == 0)) {
415 1.12.6.2 nathanw /* massage the data to look like EMP data */
416 1.12.6.2 nathanw if ((buffer[3] & 0x04) == 0x04)
417 1.12.6.2 nathanw buffer[1] &= 0x7f;
418 1.12.6.2 nathanw else
419 1.12.6.2 nathanw buffer[1] |= 0x80;
420 1.12.6.2 nathanw if ((buffer[3] & 0x02) == 0x02)
421 1.12.6.2 nathanw buffer[2] &= 0x7f;
422 1.12.6.2 nathanw else
423 1.12.6.2 nathanw buffer[2] |= 0x80;
424 1.12.6.2 nathanw if ((buffer[3] & 0x01) == 0x01)
425 1.12.6.2 nathanw buffer[3] = 0x00;
426 1.12.6.2 nathanw else
427 1.12.6.2 nathanw buffer[3] = 0x80;
428 1.12.6.2 nathanw }
429 1.12.6.2 nathanw
430 1.12.6.2 nathanw event.addr = adbaddr;
431 1.12.6.2 nathanw event.hand_id = sc->handler_id;
432 1.12.6.2 nathanw event.def_addr = sc->origaddr;
433 1.12.6.2 nathanw event.byte_count = buffer[0];
434 1.12.6.2 nathanw memcpy(event.bytes, buffer + 1, event.byte_count);
435 1.12.6.2 nathanw
436 1.12.6.2 nathanw #ifdef ADB_DEBUG
437 1.12.6.2 nathanw if (adb_debug) {
438 1.12.6.2 nathanw printf("ams: from %d at %d (org %d) %d:", event.addr,
439 1.12.6.2 nathanw event.hand_id, event.def_addr, buffer[0]);
440 1.12.6.2 nathanw for (i = 1; i <= buffer[0]; i++)
441 1.12.6.2 nathanw printf(" %x", buffer[i]);
442 1.12.6.2 nathanw printf("\n");
443 1.12.6.2 nathanw }
444 1.12.6.2 nathanw #endif
445 1.12.6.2 nathanw
446 1.12.6.2 nathanw microtime(&event.timestamp);
447 1.12.6.2 nathanw
448 1.12.6.2 nathanw ms_processevent(&event, sc);
449 1.12.6.2 nathanw }
450 1.12.6.2 nathanw
451 1.12.6.2 nathanw /*
452 1.12.6.2 nathanw * Given a mouse ADB event, record the button settings, calculate the
453 1.12.6.2 nathanw * x- and y-axis motion, and handoff the event to the appropriate subsystem.
454 1.12.6.2 nathanw */
455 1.12.6.2 nathanw static void
456 1.12.6.2 nathanw ms_processevent(event, sc)
457 1.12.6.2 nathanw adb_event_t *event;
458 1.12.6.2 nathanw struct ams_softc *sc;
459 1.12.6.2 nathanw {
460 1.12.6.2 nathanw adb_event_t new_event;
461 1.12.6.2 nathanw int i, button_bit, max_byte, mask, buttons;
462 1.12.6.2 nathanw
463 1.12.6.2 nathanw new_event = *event;
464 1.12.6.2 nathanw buttons = 0;
465 1.12.6.2 nathanw
466 1.12.6.2 nathanw /*
467 1.12.6.2 nathanw * This should handle both plain ol' Apple mice and mice
468 1.12.6.2 nathanw * that claim to support the Extended Apple Mouse Protocol.
469 1.12.6.2 nathanw */
470 1.12.6.2 nathanw max_byte = event->byte_count;
471 1.12.6.2 nathanw button_bit = 1;
472 1.12.6.2 nathanw switch (event->hand_id) {
473 1.12.6.2 nathanw case ADBMS_USPEED:
474 1.12.6.2 nathanw case ADBMS_UCONTOUR:
475 1.12.6.2 nathanw /* MicroSpeed mouse and Contour mouse */
476 1.12.6.2 nathanw if (max_byte == 4)
477 1.12.6.2 nathanw buttons = (~event->bytes[2]) & 0xff;
478 1.12.6.2 nathanw else
479 1.12.6.2 nathanw buttons = (event->bytes[0] & 0x80) ? 0 : 1;
480 1.12.6.2 nathanw break;
481 1.12.6.2 nathanw case ADBMS_MSA3:
482 1.12.6.2 nathanw /* Mouse Systems A3 mouse */
483 1.12.6.2 nathanw if (max_byte == 3)
484 1.12.6.2 nathanw buttons = (~event->bytes[2]) & 0x07;
485 1.12.6.2 nathanw else
486 1.12.6.2 nathanw buttons = (event->bytes[0] & 0x80) ? 0 : 1;
487 1.12.6.2 nathanw break;
488 1.12.6.2 nathanw default:
489 1.12.6.2 nathanw /* Classic Mouse Protocol (up to 2 buttons) */
490 1.12.6.2 nathanw for (i = 0; i < 2; i++, button_bit <<= 1)
491 1.12.6.2 nathanw /* 0 when button down */
492 1.12.6.2 nathanw if (!(event->bytes[i] & 0x80))
493 1.12.6.2 nathanw buttons |= button_bit;
494 1.12.6.2 nathanw else
495 1.12.6.2 nathanw buttons &= ~button_bit;
496 1.12.6.2 nathanw /* Extended Protocol (up to 6 more buttons) */
497 1.12.6.2 nathanw for (mask = 0x80; i < max_byte;
498 1.12.6.2 nathanw i += (mask == 0x80), button_bit <<= 1) {
499 1.12.6.2 nathanw /* 0 when button down */
500 1.12.6.2 nathanw if (!(event->bytes[i] & mask))
501 1.12.6.2 nathanw buttons |= button_bit;
502 1.12.6.2 nathanw else
503 1.12.6.2 nathanw buttons &= ~button_bit;
504 1.12.6.2 nathanw mask = ((mask >> 4) & 0xf)
505 1.12.6.2 nathanw | ((mask & 0xf) << 4);
506 1.12.6.2 nathanw }
507 1.12.6.2 nathanw break;
508 1.12.6.2 nathanw }
509 1.12.6.2 nathanw new_event.u.m.buttons = sc->sc_mb | buttons;
510 1.12.6.2 nathanw new_event.u.m.dx = ((signed int) (event->bytes[1] & 0x3f)) -
511 1.12.6.2 nathanw ((event->bytes[1] & 0x40) ? 64 : 0);
512 1.12.6.2 nathanw new_event.u.m.dy = ((signed int) (event->bytes[0] & 0x3f)) -
513 1.12.6.2 nathanw ((event->bytes[0] & 0x40) ? 64 : 0);
514 1.12.6.2 nathanw
515 1.12.6.2 nathanw if (sc->sc_wsmousedev)
516 1.12.6.2 nathanw wsmouse_input(sc->sc_wsmousedev, new_event.u.m.buttons,
517 1.12.6.2 nathanw new_event.u.m.dx, -new_event.u.m.dy, 0,
518 1.12.6.2 nathanw WSMOUSE_INPUT_DELTA);
519 1.12.6.2 nathanw #if NAED > 0
520 1.12.6.2 nathanw aed_input(&new_event);
521 1.12.6.2 nathanw #endif
522 1.12.6.2 nathanw }
523 1.12.6.2 nathanw
524 1.12.6.2 nathanw int
525 1.12.6.2 nathanw ams_enable(v)
526 1.12.6.2 nathanw void *v;
527 1.12.6.2 nathanw {
528 1.12.6.2 nathanw return 0;
529 1.12.6.2 nathanw }
530 1.12.6.2 nathanw
531 1.12.6.2 nathanw int
532 1.12.6.2 nathanw ams_ioctl(v, cmd, data, flag, p)
533 1.12.6.2 nathanw void *v;
534 1.12.6.2 nathanw u_long cmd;
535 1.12.6.2 nathanw caddr_t data;
536 1.12.6.2 nathanw int flag;
537 1.12.6.2 nathanw struct proc *p;
538 1.12.6.2 nathanw {
539 1.12.6.2 nathanw return EPASSTHROUGH;
540 1.12.6.2 nathanw }
541 1.12.6.2 nathanw
542 1.12.6.2 nathanw void
543 1.12.6.2 nathanw ams_disable(v)
544 1.12.6.2 nathanw void *v;
545 1.12.6.2 nathanw {
546 1.12.6.2 nathanw }
547