1 /* $NetBSD: adbsys.c,v 1.47 2007/03/04 06:00:06 christos Exp $ */
4 * Copyright (C) 1994 Bradley A. Grantham
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: adbsys.c,v 1.47 2007/03/04 06:00:06 christos Exp $");
33 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <machine/cpu.h>
37 #include <machine/viareg.h>
39 #include <mac68k/mac68k/macrom.h>
40 #include <mac68k/dev/adbvar.h>
42 extern struct mac68k_machine_S mac68k_machine
;
45 void adb_processevent(adb_event_t
*);
47 extern void adb_jadbproc(void);
50 adb_complete(void *buffer
, void *data_area
, int adb_command
)
60 printf("adb: transaction completion\n");
63 adbaddr
= ADB_CMDADDR(adb_command
);
64 error
= GetADBInfo(&adbdata
, adbaddr
);
67 printf("adb: GetADBInfo returned %d\n", error
);
71 event
.hand_id
= (int)(adbdata
.devType
);
72 event
.def_addr
= (int)(adbdata
.origADBAddr
);
73 event
.byte_count
= buffer
[0];
74 memcpy(event
.bytes
, buffer
+ 1, event
.byte_count
);
78 printf("adb: from %d at %d (org %d) %d:", event
.addr
,
79 event
.hand_id
, event
.def_addr
, buffer
[0]);
80 for (i
= 1; i
<= buffer
[0]; i
++)
81 printf(" %x", buffer
[i
]);
86 microtime(&event
.timestamp
);
88 adb_processevent(&event
);
92 adb_msa3_complete(void *buffer
, void *data_area
, int adb_command
)
102 printf("adb: transaction completion\n");
105 adbaddr
= ADB_CMDADDR(adb_command
);
106 error
= GetADBInfo(&adbdata
, adbaddr
);
109 printf("adb: GetADBInfo returned %d\n", error
);
112 event
.addr
= adbaddr
;
113 event
.hand_id
= ADBMS_MSA3
;
114 event
.def_addr
= (int)(adbdata
.origADBAddr
);
115 event
.byte_count
= buffer
[0];
116 memcpy(event
.bytes
, buffer
+ 1, event
.byte_count
);
120 printf("adb: from %d at %d (org %d) %d:",
121 event
.addr
, event
.hand_id
, event
.def_addr
, buffer
[0]);
122 for (i
= 1; i
<= buffer
[0]; i
++)
123 printf(" %x", buffer
[i
]);
128 microtime(&event
.timestamp
);
130 adb_processevent(&event
);
134 adb_mm_nonemp_complete(void *buffer
, void *data_area
, int adb_command
)
137 ADBDataBlock adbdata
;
145 printf("adb: transaction completion\n");
148 adbaddr
= ADB_CMDADDR(adb_command
);
149 error
= GetADBInfo(&adbdata
, adbaddr
);
152 printf("adb: GetADBInfo returned %d\n", error
);
156 printf("adb: from %d at %d (org %d) %d:", event
.addr
,
157 event
.hand_id
, event
.def_addr
, buffer
[0]);
158 for (i
= 1; i
<= buffer
[0]; i
++)
159 printf(" %x", buffer
[i
]);
163 /* massage the data to look like EMP data */
164 if ((buffer
[3] & 0x04) == 0x04)
168 if ((buffer
[3] & 0x02) == 0x02)
172 if ((buffer
[3] & 0x01) == 0x01)
177 event
.addr
= adbaddr
;
178 event
.hand_id
= (int)(adbdata
.devType
);
179 event
.def_addr
= (int)(adbdata
.origADBAddr
);
180 event
.byte_count
= buffer
[0];
181 memcpy(event
.bytes
, buffer
+ 1, event
.byte_count
);
185 printf("adb: from %d at %d (org %d) %d:", event
.addr
,
186 event
.hand_id
, event
.def_addr
, buffer
[0]);
187 for (i
= 1; i
<= buffer
[0]; i
++)
188 printf(" %x", buffer
[i
]);
193 microtime(&event
.timestamp
);
195 adb_processevent(&event
);
198 static volatile int extdms_done
;
201 * initialize extended mouse - probes devices as
202 * described in _Inside Macintosh, Devices_.
205 extdms_init(int totaladbs
)
207 ADBDataBlock adbdata
;
208 int adbindex
, adbaddr
, count
;
212 for (adbindex
= 1; adbindex
<= totaladbs
; adbindex
++) {
213 /* Get the ADB information */
214 adbaddr
= GetIndADB(&adbdata
, adbindex
);
215 if (adbdata
.origADBAddr
== ADBADDR_MS
&&
216 (adbdata
.devType
== ADBMS_USPEED
||
217 adbdata
.devType
== ADBMS_UCONTOUR
)) {
218 /* Found MicroSpeed Mouse Deluxe Mac or Contour Mouse */
219 cmd
= ADBLISTEN(adbaddr
, 1);
222 * To setup the MicroSpeed or the Contour, it appears
223 * that we can send the following command to the mouse
224 * and then expect data back in the form:
225 * buffer[0] = 4 (bytes)
226 * buffer[1], buffer[2] as std. mouse
227 * buffer[3] = buffer[4] = 0xff when no buttons
228 * are down. When button N down, bit N is clear.
229 * buffer[4]'s locking mask enables a
230 * click to toggle the button down state--sort of
231 * like the "Easy Access" shift/control/etc. keys.
232 * buffer[3]'s alternative speed mask enables using
233 * different speed when the corr. button is down
236 buffer
[1] = 0x00; /* Alternative speed */
237 buffer
[2] = 0x00; /* speed = maximum */
238 buffer
[3] = 0x10; /* enable extended protocol,
239 * lower bits = alt. speed mask
242 buffer
[4] = 0x07; /* Locking mask = 0000b,
243 * enable buttons = 0111b
246 ADBOp((Ptr
)buffer
, (Ptr
)extdms_complete
,
247 (Ptr
)&extdms_done
, cmd
);
249 /* busy wait until done */;
251 if (adbdata
.origADBAddr
== ADBADDR_MS
&&
252 (adbdata
.devType
== ADBMS_100DPI
||
253 adbdata
.devType
== ADBMS_200DPI
)) {
255 cmd
= ADBTALK(adbaddr
, 3);
257 ADBOp((Ptr
)buffer
, (Ptr
)extdms_complete
,
258 (Ptr
)&extdms_done
, cmd
);
260 /* Wait until done, but no more than 2 secs */
262 while (!extdms_done
&& count
-- > 0)
268 printf("adb: extdms_init timed out\n");
273 /* Attempt to initialize Extended Mouse Protocol */
274 buffer
[2] = '\004'; /* make handler ID 4 */
276 cmd
= ADBLISTEN(adbaddr
, 3);
277 ADBOp((Ptr
)buffer
, (Ptr
)extdms_complete
,
278 (Ptr
)&extdms_done
, cmd
);
280 /* busy wait until done */;
283 * Check to see if successful, if not
284 * try to initialize it as other types
286 cmd
= ADBTALK(adbaddr
, 3);
288 ADBOp((Ptr
)buffer
, (Ptr
)extdms_complete
,
289 (Ptr
)&extdms_done
, cmd
);
291 /* busy wait until done */;
293 if (buffer
[2] != ADBMS_EXTENDED
) {
294 /* Attempt to initialize as an A3 mouse */
295 buffer
[2] = 0x03; /* make handler ID 3 */
297 cmd
= ADBLISTEN(adbaddr
, 3);
298 ADBOp((Ptr
)buffer
, (Ptr
)extdms_complete
,
299 (Ptr
)&extdms_done
, cmd
);
301 /* busy wait until done */;
304 * Check to see if successful, if not
305 * try to initialize it as other types
307 cmd
= ADBTALK(adbaddr
, 3);
309 ADBOp((Ptr
)buffer
, (Ptr
)extdms_complete
,
310 (Ptr
)&extdms_done
, cmd
);
312 /* busy wait until done */;
314 if (buffer
[2] == ADBMS_MSA3
) {
315 /* Initialize as above */
316 cmd
= ADBLISTEN(adbaddr
, 2);
320 /* Irrelevant, buffer has 0x77 */
323 * enable 3 button mode = 0111b,
327 ADBOp((Ptr
)buffer
, (Ptr
)extdms_complete
,
328 (Ptr
)&extdms_done
, cmd
);
330 /* busy wait until done */;
332 /* No special support for this mouse */