adb.c revision 1.27.4.1 1 /* $NetBSD: adb.c,v 1.27.4.1 1999/11/21 15:02:46 he Exp $ */
2
3 /*
4 * Copyright (C) 1994 Bradley A. Grantham
5 * All rights reserved.
6 *
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.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Bradley A. Grantham.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include "opt_adb.h"
34
35 #include <sys/param.h>
36 #include <sys/device.h>
37 #include <sys/fcntl.h>
38 #include <sys/poll.h>
39 #include <sys/select.h>
40 #include <sys/proc.h>
41 #include <sys/signalvar.h>
42 #include <sys/systm.h>
43
44 #include <machine/autoconf.h>
45 #include <machine/cpu.h>
46
47 #include <mac68k/mac68k/macrom.h>
48 #include <mac68k/dev/adbvar.h>
49 #include <mac68k/dev/itevar.h>
50 #include <mac68k/dev/kbdvar.h>
51
52 #include "aed.h" /* ADB Event Device for compatibility */
53
54 /*
55 * Function declarations.
56 */
57 static int adbmatch __P((struct device *, struct cfdata *, void *));
58 static void adbattach __P((struct device *, struct device *, void *));
59 static int adbprint __P((void *, const char *));
60
61 extern void adb_jadbproc __P((void));
62
63 /*
64 * Global variables.
65 */
66 int adb_polling = 0; /* Are we polling? (Debugger mode) */
67 #ifdef ADB_DEBUG
68 int adb_debug = 0; /* Output debugging messages */
69 #endif /* ADB_DEBUG */
70
71 extern struct mac68k_machine_S mac68k_machine;
72 extern int adbHardware;
73 extern char *adbHardwareDescr[];
74
75 /*
76 * Driver definition.
77 */
78 struct cfattach adb_ca = {
79 sizeof(struct device), adbmatch, adbattach
80 };
81
82 static int
83 adbmatch(parent, cf, aux)
84 struct device *parent;
85 struct cfdata *cf;
86 void *aux;
87 {
88 static int adb_matched = 0;
89
90 /* Allow only one instance. */
91 if (adb_matched)
92 return (0);
93
94 adb_matched = 1;
95 return (1);
96 }
97
98 static void
99 adbattach(parent, dev, aux)
100 struct device *parent, *dev;
101 void *aux;
102 {
103 ADBDataBlock adbdata;
104 struct adb_attach_args aa_args;
105 int totaladbs;
106 int adbindex, adbaddr;
107
108 adb_polling = 1;
109
110 #ifdef MRG_ADB
111 /*
112 * Even if serial console only, some models require the
113 * ADB in order to get the date/time and do soft power.
114 */
115 if ((mac68k_machine.serial_console & 0x03)) {
116 printf(": using serial console");
117 return;
118 }
119
120 if (!mrg_romready()) {
121 printf(": no ROM ADB driver in this kernel for this machine");
122 return;
123 }
124
125 #ifdef ADB_DEBUG
126 if (adb_debug)
127 printf("adb: call mrg_initadbintr\n");
128 #endif
129
130 mrg_initadbintr(); /* Mac ROM Glue okay to do ROM intr */
131 #ifdef ADB_DEBUG
132 if (adb_debug)
133 printf("adb: returned from mrg_initadbintr\n");
134 #endif
135
136 /* ADBReInit pre/post-processing */
137 JADBProc = adb_jadbproc;
138
139 /* Initialize ADB */
140 #ifdef ADB_DEBUG
141 if (adb_debug)
142 printf("adb: calling ADBAlternateInit.\n");
143 #endif
144
145 printf(" (mrg)");
146 ADBAlternateInit();
147 #else
148 ADBReInit();
149 printf(" (direct, %s)", adbHardwareDescr[adbHardware]);
150 #endif /* MRG_ADB */
151
152 #ifdef ADB_DEBUG
153 if (adb_debug)
154 printf("adb: done with ADBReInit\n");
155 #endif
156
157 totaladbs = CountADBs();
158
159 printf(": %d targets\n", totaladbs);
160
161 #if NAED > 0
162 /* ADB event device for compatibility */
163 aa_args.origaddr = 0;
164 aa_args.adbaddr = 0;
165 aa_args.handler_id = 0;
166 (void)config_found(dev, &aa_args, adbprint);
167 #endif
168
169 /* for each ADB device */
170 for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
171 /* Get the ADB information */
172 adbaddr = GetIndADB(&adbdata, adbindex);
173
174 aa_args.origaddr = (int)(adbdata.origADBAddr);
175 aa_args.adbaddr = adbaddr;
176 aa_args.handler_id = (int)(adbdata.devType);
177
178 (void)config_found(dev, &aa_args, adbprint);
179 }
180 adb_polling = 0;
181 }
182
183
184 int
185 adbprint(args, name)
186 void *args;
187 const char *name;
188 {
189 struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
190 int rv = UNCONF;
191
192 if (name) { /* no configured device matched */
193 rv = UNSUPP; /* most ADB device types are unsupported */
194
195 /* print out what kind of ADB device we have found */
196 printf("%s addr %d: ", name, aa_args->origaddr);
197 switch(aa_args->origaddr) {
198 #ifdef DIAGNOSTIC
199 case 0:
200 printf("ADB event device");
201 rv = UNCONF;
202 break;
203 case ADBADDR_SECURE:
204 printf("security dongle (%d)", aa_args->handler_id);
205 break;
206 #endif
207 case ADBADDR_MAP:
208 printf("mapped device (%d)", aa_args->handler_id);
209 rv = UNCONF;
210 break;
211 case ADBADDR_REL:
212 printf("relative positioning device (%d)",
213 aa_args->handler_id);
214 rv = UNCONF;
215 break;
216 #ifdef DIAGNOSTIC
217 case ADBADDR_ABS:
218 switch (aa_args->handler_id) {
219 case ADB_ARTPAD:
220 printf("WACOM ArtPad II");
221 break;
222 default:
223 printf("absolute positioning device (%d)",
224 aa_args->handler_id);
225 break;
226 }
227 break;
228 case ADBADDR_DATATX:
229 printf("data transfer device (modem?) (%d)",
230 aa_args->handler_id);
231 break;
232 case ADBADDR_MISC:
233 switch (aa_args->handler_id) {
234 case ADB_POWERKEY:
235 printf("Sophisticated Circuits PowerKey");
236 break;
237 default:
238 printf("misc. device (remote control?) (%d)",
239 aa_args->handler_id);
240 break;
241 }
242 break;
243 default:
244 printf("unknown type device, (handler %d)",
245 aa_args->handler_id);
246 break;
247 #endif /* DIAGNOSTIC */
248 }
249 } else /* a device matched and was configured */
250 printf(" addr %d: ", aa_args->origaddr);
251
252 return (rv);
253 }
254