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