ams.c revision 1.12.6.2 1 1.12.6.2 nathanw /* $NetBSD: ams.c,v 1.12.6.2 2002/04/01 07:40:53 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.2 nathanw struct cfattach ams_ca = {
63 1.12.6.2 nathanw sizeof(struct ams_softc), amsmatch, amsattach
64 1.12.6.2 nathanw };
65 1.12.6.2 nathanw
66 1.12.6.2 nathanw int ams_enable __P((void *));
67 1.12.6.2 nathanw int ams_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
68 1.12.6.2 nathanw void ams_disable __P((void *));
69 1.12.6.2 nathanw
70 1.12.6.2 nathanw const struct wsmouse_accessops ams_accessops = {
71 1.12.6.2 nathanw ams_enable,
72 1.12.6.2 nathanw ams_ioctl,
73 1.12.6.2 nathanw ams_disable,
74 1.12.6.2 nathanw };
75 1.12.6.2 nathanw
76 1.12.6.2 nathanw static int
77 1.12.6.2 nathanw amsmatch(parent, cf, aux)
78 1.12.6.2 nathanw struct device *parent;
79 1.12.6.2 nathanw struct cfdata *cf;
80 1.12.6.2 nathanw void *aux;
81 1.12.6.2 nathanw {
82 1.12.6.2 nathanw struct adb_attach_args *aa_args = aux;
83 1.12.6.2 nathanw
84 1.12.6.2 nathanw if (aa_args->origaddr == ADBADDR_MS)
85 1.12.6.2 nathanw return 1;
86 1.12.6.2 nathanw else
87 1.12.6.2 nathanw return 0;
88 1.12.6.2 nathanw }
89 1.12.6.2 nathanw
90 1.12.6.2 nathanw static void
91 1.12.6.2 nathanw amsattach(parent, self, aux)
92 1.12.6.2 nathanw struct device *parent, *self;
93 1.12.6.2 nathanw void *aux;
94 1.12.6.2 nathanw {
95 1.12.6.2 nathanw ADBSetInfoBlock adbinfo;
96 1.12.6.2 nathanw struct ams_softc *sc = (struct ams_softc *)self;
97 1.12.6.2 nathanw struct adb_attach_args *aa_args = aux;
98 1.12.6.2 nathanw int error;
99 1.12.6.2 nathanw struct wsmousedev_attach_args a;
100 1.12.6.2 nathanw
101 1.12.6.2 nathanw sc->origaddr = aa_args->origaddr;
102 1.12.6.2 nathanw sc->adbaddr = aa_args->adbaddr;
103 1.12.6.2 nathanw sc->handler_id = aa_args->handler_id;
104 1.12.6.2 nathanw
105 1.12.6.2 nathanw sc->sc_class = MSCLASS_MOUSE;
106 1.12.6.2 nathanw sc->sc_buttons = 1;
107 1.12.6.2 nathanw sc->sc_res = 100;
108 1.12.6.2 nathanw sc->sc_devid[0] = 0;
109 1.12.6.2 nathanw sc->sc_devid[4] = 0;
110 1.12.6.2 nathanw
111 1.12.6.2 nathanw adbinfo.siServiceRtPtr = (Ptr)ms_adbcomplete;
112 1.12.6.2 nathanw adbinfo.siDataAreaAddr = (caddr_t)sc;
113 1.12.6.2 nathanw
114 1.12.6.2 nathanw ems_init(sc);
115 1.12.6.2 nathanw
116 1.12.6.2 nathanw /* print out the type of mouse we have */
117 1.12.6.2 nathanw switch (sc->handler_id) {
118 1.12.6.2 nathanw case ADBMS_100DPI:
119 1.12.6.2 nathanw printf("%d-button, %d dpi mouse\n", sc->sc_buttons,
120 1.12.6.2 nathanw (int)(sc->sc_res));
121 1.12.6.2 nathanw break;
122 1.12.6.2 nathanw case ADBMS_200DPI:
123 1.12.6.2 nathanw sc->sc_res = 200;
124 1.12.6.2 nathanw printf("%d-button, %d dpi mouse\n", sc->sc_buttons,
125 1.12.6.2 nathanw (int)(sc->sc_res));
126 1.12.6.2 nathanw break;
127 1.12.6.2 nathanw case ADBMS_MSA3:
128 1.12.6.2 nathanw printf("Mouse Systems A3 mouse, %d-button, %d dpi\n",
129 1.12.6.2 nathanw sc->sc_buttons, (int)(sc->sc_res));
130 1.12.6.2 nathanw break;
131 1.12.6.2 nathanw case ADBMS_USPEED:
132 1.12.6.2 nathanw printf("MicroSpeed mouse, default parameters\n");
133 1.12.6.2 nathanw break;
134 1.12.6.2 nathanw case ADBMS_UCONTOUR:
135 1.12.6.2 nathanw printf("Contour mouse, default parameters\n");
136 1.12.6.2 nathanw break;
137 1.12.6.2 nathanw case ADBMS_TURBO:
138 1.12.6.2 nathanw printf("Kensington Turbo Mouse\n");
139 1.12.6.2 nathanw break;
140 1.12.6.2 nathanw case ADBMS_EXTENDED:
141 1.12.6.2 nathanw if (sc->sc_devid[0] == '\0') {
142 1.12.6.2 nathanw printf("Logitech ");
143 1.12.6.2 nathanw switch (sc->sc_class) {
144 1.12.6.2 nathanw case MSCLASS_MOUSE:
145 1.12.6.2 nathanw printf("MouseMan (non-EMP) mouse");
146 1.12.6.2 nathanw break;
147 1.12.6.2 nathanw case MSCLASS_TRACKBALL:
148 1.12.6.2 nathanw printf("TrackMan (non-EMP) trackball");
149 1.12.6.2 nathanw break;
150 1.12.6.2 nathanw default:
151 1.12.6.2 nathanw printf("non-EMP relative positioning device");
152 1.12.6.2 nathanw break;
153 1.12.6.2 nathanw }
154 1.12.6.2 nathanw printf("\n");
155 1.12.6.2 nathanw } else {
156 1.12.6.2 nathanw printf("EMP ");
157 1.12.6.2 nathanw switch (sc->sc_class) {
158 1.12.6.2 nathanw case MSCLASS_TABLET:
159 1.12.6.2 nathanw printf("tablet");
160 1.12.6.2 nathanw break;
161 1.12.6.2 nathanw case MSCLASS_MOUSE:
162 1.12.6.2 nathanw printf("mouse");
163 1.12.6.2 nathanw break;
164 1.12.6.2 nathanw case MSCLASS_TRACKBALL:
165 1.12.6.2 nathanw printf("trackball");
166 1.12.6.2 nathanw break;
167 1.12.6.2 nathanw case MSCLASS_TRACKPAD:
168 1.12.6.2 nathanw printf("trackpad");
169 1.12.6.2 nathanw break;
170 1.12.6.2 nathanw default:
171 1.12.6.2 nathanw printf("unknown device");
172 1.12.6.2 nathanw break;
173 1.12.6.2 nathanw }
174 1.12.6.2 nathanw printf(" <%s> %d-button, %d dpi\n", sc->sc_devid,
175 1.12.6.2 nathanw sc->sc_buttons, (int)(sc->sc_res));
176 1.12.6.2 nathanw }
177 1.12.6.2 nathanw break;
178 1.12.6.2 nathanw default:
179 1.12.6.2 nathanw printf("relative positioning device (mouse?) (%d)\n",
180 1.12.6.2 nathanw sc->handler_id);
181 1.12.6.2 nathanw break;
182 1.12.6.2 nathanw }
183 1.12.6.2 nathanw error = SetADBInfo(&adbinfo, sc->adbaddr);
184 1.12.6.2 nathanw #ifdef ADB_DEBUG
185 1.12.6.2 nathanw if (adb_debug)
186 1.12.6.2 nathanw printf("ams: returned %d from SetADBInfo\n", error);
187 1.12.6.2 nathanw #endif
188 1.12.6.2 nathanw
189 1.12.6.2 nathanw a.accessops = &ams_accessops;
190 1.12.6.2 nathanw a.accesscookie = sc;
191 1.12.6.2 nathanw sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
192 1.12.6.2 nathanw }
193 1.12.6.2 nathanw
194 1.12.6.2 nathanw
195 1.12.6.2 nathanw /*
196 1.12.6.2 nathanw * Initialize extended mouse support -- probes devices as described
197 1.12.6.2 nathanw * in Inside Macintosh: Devices, Chapter 5 "ADB Manager".
198 1.12.6.2 nathanw *
199 1.12.6.2 nathanw * Extended Mouse Protocol is documented in TechNote HW1:
200 1.12.6.2 nathanw * "ADB - The Untold Story: Space Aliens Ate My Mouse"
201 1.12.6.2 nathanw *
202 1.12.6.2 nathanw * Supports: Extended Mouse Protocol, MicroSpeed Mouse Deluxe,
203 1.12.6.2 nathanw * Mouse Systems A^3 Mouse, Logitech non-EMP MouseMan
204 1.12.6.2 nathanw */
205 1.12.6.2 nathanw void
206 1.12.6.2 nathanw ems_init(sc)
207 1.12.6.2 nathanw struct ams_softc *sc;
208 1.12.6.2 nathanw {
209 1.12.6.2 nathanw int adbaddr;
210 1.12.6.2 nathanw short cmd;
211 1.12.6.2 nathanw u_char buffer[9];
212 1.12.6.2 nathanw
213 1.12.6.2 nathanw adbaddr = sc->adbaddr;
214 1.12.6.2 nathanw if (sc->origaddr != ADBADDR_MS)
215 1.12.6.2 nathanw return;
216 1.12.6.2 nathanw if (sc->handler_id == ADBMS_USPEED ||
217 1.12.6.2 nathanw sc->handler_id == ADBMS_UCONTOUR) {
218 1.12.6.2 nathanw /* Found MicroSpeed Mouse Deluxe Mac or Contour Mouse */
219 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 1);
220 1.12.6.2 nathanw
221 1.12.6.2 nathanw /*
222 1.12.6.2 nathanw * To setup the MicroSpeed or the Contour, it appears
223 1.12.6.2 nathanw * that we can send the following command to the mouse
224 1.12.6.2 nathanw * and then expect data back in the form:
225 1.12.6.2 nathanw * buffer[0] = 4 (bytes)
226 1.12.6.2 nathanw * buffer[1], buffer[2] as std. mouse
227 1.12.6.2 nathanw * buffer[3] = buffer[4] = 0xff when no buttons
228 1.12.6.2 nathanw * are down. When button N down, bit N is clear.
229 1.12.6.2 nathanw * buffer[4]'s locking mask enables a
230 1.12.6.2 nathanw * click to toggle the button down state--sort of
231 1.12.6.2 nathanw * like the "Easy Access" shift/control/etc. keys.
232 1.12.6.2 nathanw * buffer[3]'s alternative speed mask enables using
233 1.12.6.2 nathanw * different speed when the corr. button is down
234 1.12.6.2 nathanw */
235 1.12.6.2 nathanw buffer[0] = 4;
236 1.12.6.2 nathanw buffer[1] = 0x00; /* Alternative speed */
237 1.12.6.2 nathanw buffer[2] = 0x00; /* speed = maximum */
238 1.12.6.2 nathanw buffer[3] = 0x10; /* enable extended protocol,
239 1.12.6.2 nathanw * lower bits = alt. speed mask
240 1.12.6.2 nathanw * = 0000b
241 1.12.6.2 nathanw */
242 1.12.6.2 nathanw buffer[4] = 0x07; /* Locking mask = 0000b,
243 1.12.6.2 nathanw * enable buttons = 0111b
244 1.12.6.2 nathanw */
245 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
246 1.12.6.2 nathanw
247 1.12.6.2 nathanw sc->sc_buttons = 3;
248 1.12.6.2 nathanw sc->sc_res = 200;
249 1.12.6.2 nathanw return;
250 1.12.6.2 nathanw }
251 1.12.6.2 nathanw if (sc->handler_id == ADBMS_TURBO) {
252 1.12.6.2 nathanw /* Found Kensington Turbo Mouse */
253 1.12.6.2 nathanw static u_char data1[] =
254 1.12.6.2 nathanw { 8, 0xe7, 0x8c, 0, 0, 0, 0xff, 0xff, 0x94 };
255 1.12.6.2 nathanw static u_char data2[] =
256 1.12.6.2 nathanw { 8, 0xa5, 0x14, 0, 0, 0x69, 0xff, 0xff, 0x27 };
257 1.12.6.2 nathanw
258 1.12.6.2 nathanw buffer[0] = 0;
259 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, ADBFLUSH(adbaddr));
260 1.12.6.2 nathanw
261 1.12.6.2 nathanw adb_op_sync((Ptr)data1, (Ptr)0, (Ptr)0, ADBLISTEN(adbaddr, 2));
262 1.12.6.2 nathanw
263 1.12.6.2 nathanw buffer[0] = 0;
264 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, ADBFLUSH(adbaddr));
265 1.12.6.2 nathanw
266 1.12.6.2 nathanw adb_op_sync((Ptr)data2, (Ptr)0, (Ptr)0, ADBLISTEN(adbaddr, 2));
267 1.12.6.2 nathanw return;
268 1.12.6.2 nathanw }
269 1.12.6.2 nathanw if ((sc->handler_id == ADBMS_100DPI) ||
270 1.12.6.2 nathanw (sc->handler_id == ADBMS_200DPI)) {
271 1.12.6.2 nathanw /* found a mouse */
272 1.12.6.2 nathanw cmd = ADBTALK(adbaddr, 3);
273 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd)) {
274 1.12.6.2 nathanw #ifdef ADB_DEBUG
275 1.12.6.2 nathanw if (adb_debug)
276 1.12.6.2 nathanw printf("adb: ems_init timed out\n");
277 1.12.6.2 nathanw #endif
278 1.12.6.2 nathanw return;
279 1.12.6.2 nathanw }
280 1.12.6.2 nathanw
281 1.12.6.2 nathanw /* Attempt to initialize Extended Mouse Protocol */
282 1.12.6.2 nathanw buffer[2] = 4; /* make handler ID 4 */
283 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 3);
284 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd)) {
285 1.12.6.2 nathanw #ifdef ADB_DEBUG
286 1.12.6.2 nathanw if (adb_debug)
287 1.12.6.2 nathanw printf("adb: ems_init timed out\n");
288 1.12.6.2 nathanw #endif
289 1.12.6.2 nathanw return;
290 1.12.6.2 nathanw }
291 1.12.6.2 nathanw
292 1.12.6.2 nathanw /*
293 1.12.6.2 nathanw * Check to see if successful, if not
294 1.12.6.2 nathanw * try to initialize it as other types
295 1.12.6.2 nathanw */
296 1.12.6.2 nathanw cmd = ADBTALK(adbaddr, 3);
297 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) == 0 &&
298 1.12.6.2 nathanw buffer[2] == ADBMS_EXTENDED) {
299 1.12.6.2 nathanw sc->handler_id = ADBMS_EXTENDED;
300 1.12.6.2 nathanw cmd = ADBTALK(adbaddr, 1);
301 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd)) {
302 1.12.6.2 nathanw #ifdef ADB_DEBUG
303 1.12.6.2 nathanw if (adb_debug)
304 1.12.6.2 nathanw printf("adb: ems_init timed out\n");
305 1.12.6.2 nathanw #endif
306 1.12.6.2 nathanw } else if (buffer[0] == 8) {
307 1.12.6.2 nathanw /* we have a true EMP device */
308 1.12.6.2 nathanw sc->sc_class = buffer[7];
309 1.12.6.2 nathanw sc->sc_buttons = buffer[8];
310 1.12.6.2 nathanw sc->sc_res = (int)*(short *)&buffer[5];
311 1.12.6.2 nathanw memcpy(sc->sc_devid, &(buffer[1]), 4);
312 1.12.6.2 nathanw } else if (buffer[1] == 0x9a &&
313 1.12.6.2 nathanw ((buffer[2] == 0x20) || (buffer[2] == 0x21))) {
314 1.12.6.2 nathanw /*
315 1.12.6.2 nathanw * Set up non-EMP Mouseman/Trackman to put
316 1.12.6.2 nathanw * button bits in 3rd byte instead of sending
317 1.12.6.2 nathanw * via pseudo keyboard device.
318 1.12.6.2 nathanw */
319 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 1);
320 1.12.6.2 nathanw buffer[0]=2;
321 1.12.6.2 nathanw buffer[1]=0x00;
322 1.12.6.2 nathanw buffer[2]=0x81;
323 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
324 1.12.6.2 nathanw
325 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 1);
326 1.12.6.2 nathanw buffer[0]=2;
327 1.12.6.2 nathanw buffer[1]=0x01;
328 1.12.6.2 nathanw buffer[2]=0x81;
329 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
330 1.12.6.2 nathanw
331 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 1);
332 1.12.6.2 nathanw buffer[0]=2;
333 1.12.6.2 nathanw buffer[1]=0x02;
334 1.12.6.2 nathanw buffer[2]=0x81;
335 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
336 1.12.6.2 nathanw
337 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 1);
338 1.12.6.2 nathanw buffer[0]=2;
339 1.12.6.2 nathanw buffer[1]=0x03;
340 1.12.6.2 nathanw buffer[2]=0x38;
341 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
342 1.12.6.2 nathanw
343 1.12.6.2 nathanw sc->sc_buttons = 3;
344 1.12.6.2 nathanw sc->sc_res = 400;
345 1.12.6.2 nathanw if (buffer[2] == 0x21)
346 1.12.6.2 nathanw sc->sc_class = MSCLASS_TRACKBALL;
347 1.12.6.2 nathanw else
348 1.12.6.2 nathanw sc->sc_class = MSCLASS_MOUSE;
349 1.12.6.2 nathanw } else
350 1.12.6.2 nathanw /* unknown device? */;
351 1.12.6.2 nathanw } else {
352 1.12.6.2 nathanw /* Attempt to initialize as an A3 mouse */
353 1.12.6.2 nathanw buffer[2] = 0x03; /* make handler ID 3 */
354 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 3);
355 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd)) {
356 1.12.6.2 nathanw #ifdef ADB_DEBUG
357 1.12.6.2 nathanw if (adb_debug)
358 1.12.6.2 nathanw printf("adb: ems_init timed out\n");
359 1.12.6.2 nathanw #endif
360 1.12.6.2 nathanw return;
361 1.12.6.2 nathanw }
362 1.12.6.2 nathanw
363 1.12.6.2 nathanw /*
364 1.12.6.2 nathanw * Check to see if successful, if not
365 1.12.6.2 nathanw * try to initialize it as other types
366 1.12.6.2 nathanw */
367 1.12.6.2 nathanw cmd = ADBTALK(adbaddr, 3);
368 1.12.6.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) == 0
369 1.12.6.2 nathanw && buffer[2] == ADBMS_MSA3) {
370 1.12.6.2 nathanw sc->handler_id = ADBMS_MSA3;
371 1.12.6.2 nathanw /* Initialize as above */
372 1.12.6.2 nathanw cmd = ADBLISTEN(adbaddr, 2);
373 1.12.6.2 nathanw /* listen 2 */
374 1.12.6.2 nathanw buffer[0] = 3;
375 1.12.6.2 nathanw buffer[1] = 0x00;
376 1.12.6.2 nathanw /* Irrelevant, buffer has 0x77 */
377 1.12.6.2 nathanw buffer[2] = 0x07;
378 1.12.6.2 nathanw /*
379 1.12.6.2 nathanw * enable 3 button mode = 0111b,
380 1.12.6.2 nathanw * speed = normal
381 1.12.6.2 nathanw */
382 1.12.6.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
383 1.12.6.2 nathanw sc->sc_buttons = 3;
384 1.12.6.2 nathanw sc->sc_res = 300;
385 1.12.6.2 nathanw } else {
386 1.12.6.2 nathanw /* No special support for this mouse */
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 /*
393 1.12.6.2 nathanw * Handle putting the mouse data received from the ADB into
394 1.12.6.2 nathanw * an ADB event record.
395 1.12.6.2 nathanw */
396 1.12.6.2 nathanw void
397 1.12.6.2 nathanw ms_adbcomplete(buffer, data_area, adb_command)
398 1.12.6.2 nathanw caddr_t buffer;
399 1.12.6.2 nathanw caddr_t data_area;
400 1.12.6.2 nathanw int adb_command;
401 1.12.6.2 nathanw {
402 1.12.6.2 nathanw adb_event_t event;
403 1.12.6.2 nathanw struct ams_softc *sc;
404 1.12.6.2 nathanw int adbaddr;
405 1.12.6.2 nathanw #ifdef ADB_DEBUG
406 1.12.6.2 nathanw int i;
407 1.12.6.2 nathanw
408 1.12.6.2 nathanw if (adb_debug)
409 1.12.6.2 nathanw printf("adb: transaction completion\n");
410 1.12.6.2 nathanw #endif
411 1.12.6.2 nathanw
412 1.12.6.2 nathanw adbaddr = ADB_CMDADDR(adb_command);
413 1.12.6.2 nathanw sc = (struct ams_softc *)data_area;
414 1.12.6.2 nathanw
415 1.12.6.2 nathanw if ((sc->handler_id == ADBMS_EXTENDED) && (sc->sc_devid[0] == 0)) {
416 1.12.6.2 nathanw /* massage the data to look like EMP data */
417 1.12.6.2 nathanw if ((buffer[3] & 0x04) == 0x04)
418 1.12.6.2 nathanw buffer[1] &= 0x7f;
419 1.12.6.2 nathanw else
420 1.12.6.2 nathanw buffer[1] |= 0x80;
421 1.12.6.2 nathanw if ((buffer[3] & 0x02) == 0x02)
422 1.12.6.2 nathanw buffer[2] &= 0x7f;
423 1.12.6.2 nathanw else
424 1.12.6.2 nathanw buffer[2] |= 0x80;
425 1.12.6.2 nathanw if ((buffer[3] & 0x01) == 0x01)
426 1.12.6.2 nathanw buffer[3] = 0x00;
427 1.12.6.2 nathanw else
428 1.12.6.2 nathanw buffer[3] = 0x80;
429 1.12.6.2 nathanw }
430 1.12.6.2 nathanw
431 1.12.6.2 nathanw event.addr = adbaddr;
432 1.12.6.2 nathanw event.hand_id = sc->handler_id;
433 1.12.6.2 nathanw event.def_addr = sc->origaddr;
434 1.12.6.2 nathanw event.byte_count = buffer[0];
435 1.12.6.2 nathanw memcpy(event.bytes, buffer + 1, event.byte_count);
436 1.12.6.2 nathanw
437 1.12.6.2 nathanw #ifdef ADB_DEBUG
438 1.12.6.2 nathanw if (adb_debug) {
439 1.12.6.2 nathanw printf("ams: from %d at %d (org %d) %d:", event.addr,
440 1.12.6.2 nathanw event.hand_id, event.def_addr, buffer[0]);
441 1.12.6.2 nathanw for (i = 1; i <= buffer[0]; i++)
442 1.12.6.2 nathanw printf(" %x", buffer[i]);
443 1.12.6.2 nathanw printf("\n");
444 1.12.6.2 nathanw }
445 1.12.6.2 nathanw #endif
446 1.12.6.2 nathanw
447 1.12.6.2 nathanw microtime(&event.timestamp);
448 1.12.6.2 nathanw
449 1.12.6.2 nathanw ms_processevent(&event, sc);
450 1.12.6.2 nathanw }
451 1.12.6.2 nathanw
452 1.12.6.2 nathanw /*
453 1.12.6.2 nathanw * Given a mouse ADB event, record the button settings, calculate the
454 1.12.6.2 nathanw * x- and y-axis motion, and handoff the event to the appropriate subsystem.
455 1.12.6.2 nathanw */
456 1.12.6.2 nathanw static void
457 1.12.6.2 nathanw ms_processevent(event, sc)
458 1.12.6.2 nathanw adb_event_t *event;
459 1.12.6.2 nathanw struct ams_softc *sc;
460 1.12.6.2 nathanw {
461 1.12.6.2 nathanw adb_event_t new_event;
462 1.12.6.2 nathanw int i, button_bit, max_byte, mask, buttons;
463 1.12.6.2 nathanw
464 1.12.6.2 nathanw new_event = *event;
465 1.12.6.2 nathanw buttons = 0;
466 1.12.6.2 nathanw
467 1.12.6.2 nathanw /*
468 1.12.6.2 nathanw * This should handle both plain ol' Apple mice and mice
469 1.12.6.2 nathanw * that claim to support the Extended Apple Mouse Protocol.
470 1.12.6.2 nathanw */
471 1.12.6.2 nathanw max_byte = event->byte_count;
472 1.12.6.2 nathanw button_bit = 1;
473 1.12.6.2 nathanw switch (event->hand_id) {
474 1.12.6.2 nathanw case ADBMS_USPEED:
475 1.12.6.2 nathanw case ADBMS_UCONTOUR:
476 1.12.6.2 nathanw /* MicroSpeed mouse and Contour mouse */
477 1.12.6.2 nathanw if (max_byte == 4)
478 1.12.6.2 nathanw buttons = (~event->bytes[2]) & 0xff;
479 1.12.6.2 nathanw else
480 1.12.6.2 nathanw buttons = (event->bytes[0] & 0x80) ? 0 : 1;
481 1.12.6.2 nathanw break;
482 1.12.6.2 nathanw case ADBMS_MSA3:
483 1.12.6.2 nathanw /* Mouse Systems A3 mouse */
484 1.12.6.2 nathanw if (max_byte == 3)
485 1.12.6.2 nathanw buttons = (~event->bytes[2]) & 0x07;
486 1.12.6.2 nathanw else
487 1.12.6.2 nathanw buttons = (event->bytes[0] & 0x80) ? 0 : 1;
488 1.12.6.2 nathanw break;
489 1.12.6.2 nathanw default:
490 1.12.6.2 nathanw /* Classic Mouse Protocol (up to 2 buttons) */
491 1.12.6.2 nathanw for (i = 0; i < 2; i++, button_bit <<= 1)
492 1.12.6.2 nathanw /* 0 when button down */
493 1.12.6.2 nathanw if (!(event->bytes[i] & 0x80))
494 1.12.6.2 nathanw buttons |= button_bit;
495 1.12.6.2 nathanw else
496 1.12.6.2 nathanw buttons &= ~button_bit;
497 1.12.6.2 nathanw /* Extended Protocol (up to 6 more buttons) */
498 1.12.6.2 nathanw for (mask = 0x80; i < max_byte;
499 1.12.6.2 nathanw i += (mask == 0x80), button_bit <<= 1) {
500 1.12.6.2 nathanw /* 0 when button down */
501 1.12.6.2 nathanw if (!(event->bytes[i] & mask))
502 1.12.6.2 nathanw buttons |= button_bit;
503 1.12.6.2 nathanw else
504 1.12.6.2 nathanw buttons &= ~button_bit;
505 1.12.6.2 nathanw mask = ((mask >> 4) & 0xf)
506 1.12.6.2 nathanw | ((mask & 0xf) << 4);
507 1.12.6.2 nathanw }
508 1.12.6.2 nathanw break;
509 1.12.6.2 nathanw }
510 1.12.6.2 nathanw new_event.u.m.buttons = sc->sc_mb | buttons;
511 1.12.6.2 nathanw new_event.u.m.dx = ((signed int) (event->bytes[1] & 0x3f)) -
512 1.12.6.2 nathanw ((event->bytes[1] & 0x40) ? 64 : 0);
513 1.12.6.2 nathanw new_event.u.m.dy = ((signed int) (event->bytes[0] & 0x3f)) -
514 1.12.6.2 nathanw ((event->bytes[0] & 0x40) ? 64 : 0);
515 1.12.6.2 nathanw
516 1.12.6.2 nathanw if (sc->sc_wsmousedev)
517 1.12.6.2 nathanw wsmouse_input(sc->sc_wsmousedev, new_event.u.m.buttons,
518 1.12.6.2 nathanw new_event.u.m.dx, -new_event.u.m.dy, 0,
519 1.12.6.2 nathanw WSMOUSE_INPUT_DELTA);
520 1.12.6.2 nathanw #if NAED > 0
521 1.12.6.2 nathanw aed_input(&new_event);
522 1.12.6.2 nathanw #endif
523 1.12.6.2 nathanw }
524 1.12.6.2 nathanw
525 1.12.6.2 nathanw int
526 1.12.6.2 nathanw ams_enable(v)
527 1.12.6.2 nathanw void *v;
528 1.12.6.2 nathanw {
529 1.12.6.2 nathanw return 0;
530 1.12.6.2 nathanw }
531 1.12.6.2 nathanw
532 1.12.6.2 nathanw int
533 1.12.6.2 nathanw ams_ioctl(v, cmd, data, flag, p)
534 1.12.6.2 nathanw void *v;
535 1.12.6.2 nathanw u_long cmd;
536 1.12.6.2 nathanw caddr_t data;
537 1.12.6.2 nathanw int flag;
538 1.12.6.2 nathanw struct proc *p;
539 1.12.6.2 nathanw {
540 1.12.6.2 nathanw return EPASSTHROUGH;
541 1.12.6.2 nathanw }
542 1.12.6.2 nathanw
543 1.12.6.2 nathanw void
544 1.12.6.2 nathanw ams_disable(v)
545 1.12.6.2 nathanw void *v;
546 1.12.6.2 nathanw {
547 1.12.6.2 nathanw }
548