adb.c revision 1.34 1 /* $NetBSD: adb.c,v 1.34 2000/02/14 07:01:45 scottr 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/akbdvar.h>
50
51 #include "aed.h" /* ADB Event Device for compatibility */
52
53 /*
54 * Function declarations.
55 */
56 static int adbmatch __P((struct device *, struct cfdata *, void *));
57 static void adbattach __P((struct device *, struct device *, void *));
58 static int adbprint __P((void *, const char *));
59 void adb_config_interrupts __P((struct device *));
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 #if 1
69 int adb_debug = 0xff;
70 #else
71 int adb_debug = 0; /* Output debugging messages */
72 #endif
73 #endif /* ADB_DEBUG */
74
75 extern struct mac68k_machine_S mac68k_machine;
76 extern int adbHardware;
77 extern char *adbHardwareDescr[];
78
79 /*
80 * Driver definition.
81 */
82 struct cfattach adb_ca = {
83 sizeof(struct device), adbmatch, adbattach
84 };
85
86 static int
87 adbmatch(parent, cf, aux)
88 struct device *parent;
89 struct cfdata *cf;
90 void *aux;
91 {
92 static int adb_matched = 0;
93
94 /* Allow only one instance. */
95 if (adb_matched)
96 return (0);
97
98 adb_matched = 1;
99 return (1);
100 }
101
102 static void
103 adbattach(parent, self, aux)
104 struct device *parent, *self;
105 void *aux;
106 {
107 printf("\n");
108
109 /*
110 * Defer configuration until interrupts are enabled.
111 */
112 config_interrupts(self, adb_config_interrupts);
113 }
114
115 void
116 adb_config_interrupts(self)
117 struct device *self;
118 {
119 ADBDataBlock adbdata;
120 struct adb_attach_args aa_args;
121 int totaladbs;
122 int adbindex, adbaddr;
123
124 printf("%s", self->dv_xname);
125 adb_polling = 1;
126
127 #ifdef MRG_ADB
128 /*
129 * Even if serial console only, some models require the
130 * ADB in order to get the date/time and do soft power.
131 */
132 if ((mac68k_machine.serial_console & 0x03)) {
133 printf(": using serial console\n");
134 return;
135 }
136
137 if (!mrg_romready()) {
138 printf(": no ROM ADB driver in this kernel for this machine\n");
139 return;
140 }
141
142 #ifdef ADB_DEBUG
143 if (adb_debug)
144 printf("adb: call mrg_initadbintr\n");
145 #endif
146
147 mrg_initadbintr(); /* Mac ROM Glue okay to do ROM intr */
148 #ifdef ADB_DEBUG
149 if (adb_debug)
150 printf("adb: returned from mrg_initadbintr\n");
151 #endif
152
153 /* ADBReInit pre/post-processing */
154 JADBProc = adb_jadbproc;
155
156 /* Initialize ADB */
157 #ifdef ADB_DEBUG
158 if (adb_debug)
159 printf("adb: calling ADBAlternateInit.\n");
160 #endif
161
162 printf(" (mrg)");
163 ADBAlternateInit();
164 #else
165 ADBReInit();
166 printf(" (direct, %s)", adbHardwareDescr[adbHardware]);
167 #endif /* MRG_ADB */
168
169 #ifdef ADB_DEBUG
170 if (adb_debug)
171 printf("adb: done with ADBReInit\n");
172 #endif
173
174 totaladbs = CountADBs();
175
176 printf(": %d target%s\n", totaladbs, (totaladbs == 1) ? "" : "s");
177
178 #if NAED > 0
179 /* ADB event device for compatibility */
180 aa_args.origaddr = 0;
181 aa_args.adbaddr = 0;
182 aa_args.handler_id = 0;
183 (void)config_found(self, &aa_args, adbprint);
184 #endif
185
186 /* for each ADB device */
187 for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
188 /* Get the ADB information */
189 adbaddr = GetIndADB(&adbdata, adbindex);
190
191 aa_args.origaddr = (int)(adbdata.origADBAddr);
192 aa_args.adbaddr = adbaddr;
193 aa_args.handler_id = (int)(adbdata.devType);
194
195 (void)config_found(self, &aa_args, adbprint);
196 }
197 adb_polling = 0;
198 }
199
200
201 int
202 adbprint(args, name)
203 void *args;
204 const char *name;
205 {
206 struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
207 int rv = UNCONF;
208
209 if (name) { /* no configured device matched */
210 rv = UNSUPP; /* most ADB device types are unsupported */
211
212 /* print out what kind of ADB device we have found */
213 printf("%s addr %d: ", name, aa_args->origaddr);
214 switch(aa_args->origaddr) {
215 #ifdef DIAGNOSTIC
216 case 0:
217 printf("ADB event device");
218 rv = UNCONF;
219 break;
220 case ADBADDR_SECURE:
221 printf("security dongle (%d)", aa_args->handler_id);
222 break;
223 #endif
224 case ADBADDR_MAP:
225 printf("mapped device (%d)", aa_args->handler_id);
226 rv = UNCONF;
227 break;
228 case ADBADDR_REL:
229 printf("relative positioning device (%d)",
230 aa_args->handler_id);
231 rv = UNCONF;
232 break;
233 #ifdef DIAGNOSTIC
234 case ADBADDR_ABS:
235 switch (aa_args->handler_id) {
236 case ADB_ARTPAD:
237 printf("WACOM ArtPad II");
238 break;
239 default:
240 printf("absolute positioning device (%d)",
241 aa_args->handler_id);
242 break;
243 }
244 break;
245 case ADBADDR_DATATX:
246 printf("data transfer device (modem?) (%d)",
247 aa_args->handler_id);
248 break;
249 case ADBADDR_MISC:
250 switch (aa_args->handler_id) {
251 case ADB_POWERKEY:
252 printf("Sophisticated Circuits PowerKey");
253 break;
254 default:
255 printf("misc. device (remote control?) (%d)",
256 aa_args->handler_id);
257 break;
258 }
259 break;
260 default:
261 printf("unknown type device, (handler %d)",
262 aa_args->handler_id);
263 break;
264 #endif /* DIAGNOSTIC */
265 }
266 } else /* a device matched and was configured */
267 printf(" addr %d: ", aa_args->origaddr);
268
269 return (rv);
270 }
271