Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / mac68k / dev / adbsys.c
blobfc616fcd320b5d47f468290566356e166e5cd984
1 /* $NetBSD: adbsys.c,v 1.47 2007/03/04 06:00:06 christos Exp $ */
3 /*-
4 * Copyright (C) 1994 Bradley A. Grantham
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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 $");
31 #include "opt_adb.h"
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;
44 /* from adb.c */
45 void adb_processevent(adb_event_t *);
47 extern void adb_jadbproc(void);
49 void
50 adb_complete(void *buffer, void *data_area, int adb_command)
52 adb_event_t event;
53 ADBDataBlock adbdata;
54 int adbaddr;
55 int error;
56 #ifdef ADB_DEBUG
57 int i;
59 if (adb_debug)
60 printf("adb: transaction completion\n");
61 #endif
63 adbaddr = ADB_CMDADDR(adb_command);
64 error = GetADBInfo(&adbdata, adbaddr);
65 #ifdef ADB_DEBUG
66 if (adb_debug)
67 printf("adb: GetADBInfo returned %d\n", error);
68 #endif
70 event.addr = adbaddr;
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);
76 #ifdef ADB_DEBUG
77 if (adb_debug) {
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]);
82 printf("\n");
84 #endif
86 microtime(&event.timestamp);
88 adb_processevent(&event);
91 void
92 adb_msa3_complete(void *buffer, void *data_area, int adb_command)
94 adb_event_t event;
95 ADBDataBlock adbdata;
96 int adbaddr;
97 int error;
98 #ifdef ADB_DEBUG
99 int i;
101 if (adb_debug)
102 printf("adb: transaction completion\n");
103 #endif
105 adbaddr = ADB_CMDADDR(adb_command);
106 error = GetADBInfo(&adbdata, adbaddr);
107 #ifdef ADB_DEBUG
108 if (adb_debug)
109 printf("adb: GetADBInfo returned %d\n", error);
110 #endif
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);
118 #ifdef ADB_DEBUG
119 if (adb_debug) {
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]);
124 printf("\n");
126 #endif
128 microtime(&event.timestamp);
130 adb_processevent(&event);
133 void
134 adb_mm_nonemp_complete(void *buffer, void *data_area, int adb_command)
136 adb_event_t event;
137 ADBDataBlock adbdata;
138 int adbaddr;
139 int error;
141 #ifdef ADB_DEBUG
142 int i;
144 if (adb_debug)
145 printf("adb: transaction completion\n");
146 #endif
148 adbaddr = ADB_CMDADDR(adb_command);
149 error = GetADBInfo(&adbdata, adbaddr);
150 #ifdef ADB_DEBUG
151 if (adb_debug)
152 printf("adb: GetADBInfo returned %d\n", error);
153 #endif
155 #if 0
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]);
160 printf("\n");
161 #endif
163 /* massage the data to look like EMP data */
164 if ((buffer[3] & 0x04) == 0x04)
165 buffer[1] &= 0x7f;
166 else
167 buffer[1] |= 0x80;
168 if ((buffer[3] & 0x02) == 0x02)
169 buffer[2] &= 0x7f;
170 else
171 buffer[2] |= 0x80;
172 if ((buffer[3] & 0x01) == 0x01)
173 buffer[3] = 0x00;
174 else
175 buffer[3] = 0x80;
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);
183 #ifdef ADB_DEBUG
184 if (adb_debug) {
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]);
189 printf("\n");
191 #endif
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_.
204 void
205 extdms_init(int totaladbs)
207 ADBDataBlock adbdata;
208 int adbindex, adbaddr, count;
209 short cmd;
210 u_char buffer[9];
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
235 buffer[0] = 4;
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
240 * = 0000b
242 buffer[4] = 0x07; /* Locking mask = 0000b,
243 * enable buttons = 0111b
245 extdms_done = 0;
246 ADBOp((Ptr)buffer, (Ptr)extdms_complete,
247 (Ptr)&extdms_done, cmd);
248 while (!extdms_done)
249 /* busy wait until done */;
251 if (adbdata.origADBAddr == ADBADDR_MS &&
252 (adbdata.devType == ADBMS_100DPI ||
253 adbdata.devType == ADBMS_200DPI)) {
254 /* found a mouse */
255 cmd = ADBTALK(adbaddr, 3);
256 extdms_done = 0;
257 ADBOp((Ptr)buffer, (Ptr)extdms_complete,
258 (Ptr)&extdms_done, cmd);
260 /* Wait until done, but no more than 2 secs */
261 count = 40000;
262 while (!extdms_done && count-- > 0)
263 delay(50);
265 if (!extdms_done) {
266 #ifdef ADB_DEBUG
267 if (adb_debug)
268 printf("adb: extdms_init timed out\n");
269 #endif
270 return;
273 /* Attempt to initialize Extended Mouse Protocol */
274 buffer[2] = '\004'; /* make handler ID 4 */
275 extdms_done = 0;
276 cmd = ADBLISTEN(adbaddr, 3);
277 ADBOp((Ptr)buffer, (Ptr)extdms_complete,
278 (Ptr)&extdms_done, cmd);
279 while (!extdms_done)
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);
287 extdms_done = 0;
288 ADBOp((Ptr)buffer, (Ptr)extdms_complete,
289 (Ptr)&extdms_done, cmd);
290 while (!extdms_done)
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 */
296 extdms_done = 0;
297 cmd = ADBLISTEN(adbaddr, 3);
298 ADBOp((Ptr)buffer, (Ptr)extdms_complete,
299 (Ptr)&extdms_done, cmd);
300 while (!extdms_done)
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);
308 extdms_done = 0;
309 ADBOp((Ptr)buffer, (Ptr)extdms_complete,
310 (Ptr)&extdms_done, cmd);
311 while (!extdms_done)
312 /* busy wait until done */;
314 if (buffer[2] == ADBMS_MSA3) {
315 /* Initialize as above */
316 cmd = ADBLISTEN(adbaddr, 2);
317 /* listen 2 */
318 buffer[0] = 3;
319 buffer[1] = 0x00;
320 /* Irrelevant, buffer has 0x77 */
321 buffer[2] = 0x07;
323 * enable 3 button mode = 0111b,
324 * speed = normal
326 extdms_done = 0;
327 ADBOp((Ptr)buffer, (Ptr)extdms_complete,
328 (Ptr)&extdms_done, cmd);
329 while (!extdms_done)
330 /* busy wait until done */;
331 } else {
332 /* No special support for this mouse */