adb.c revision 1.32 1 /* $NetBSD: adb.c,v 1.32 1999/11/07 08:22:50 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 #ifdef ADB_DEBUG
69 int adb_debug = 0; /* Output debugging messages */
70 #endif /* ADB_DEBUG */
71
72 extern struct mac68k_machine_S mac68k_machine;
73 extern int adbHardware;
74 extern char *adbHardwareDescr[];
75
76 /*
77 * Driver definition.
78 */
79 struct cfattach adb_ca = {
80 sizeof(struct device), adbmatch, adbattach
81 };
82
83 static int
84 adbmatch(parent, cf, aux)
85 struct device *parent;
86 struct cfdata *cf;
87 void *aux;
88 {
89 static int adb_matched = 0;
90
91 /* Allow only one instance. */
92 if (adb_matched)
93 return (0);
94
95 adb_matched = 1;
96 return (1);
97 }
98
99 static void
100 adbattach(parent, self, aux)
101 struct device *parent, *self;
102 void *aux;
103 {
104 printf("\n");
105
106 /*
107 * Defer configuration until interrupts are enabled.
108 */
109 config_interrupts(self, adb_config_interrupts);
110 }
111
112 void
113 adb_config_interrupts(self)
114 struct device *self;
115 {
116 ADBDataBlock adbdata;
117 struct adb_attach_args aa_args;
118 int totaladbs;
119 int adbindex, adbaddr;
120
121 printf("%s", self->dv_xname);
122 adb_polling = 1;
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 #ifdef ADB_DEBUG
155 if (adb_debug)
156 printf("adb: calling ADBAlternateInit.\n");
157 #endif
158
159 printf(" (mrg)");
160 ADBAlternateInit();
161 #else
162 ADBReInit();
163 printf(" (direct, %s)", adbHardwareDescr[adbHardware]);
164 #endif /* MRG_ADB */
165
166 #ifdef ADB_DEBUG
167 if (adb_debug)
168 printf("adb: done with ADBReInit\n");
169 #endif
170
171 totaladbs = CountADBs();
172
173 printf(": %d targets\n", totaladbs);
174
175 #if NAED > 0
176 /* ADB event device for compatibility */
177 aa_args.origaddr = 0;
178 aa_args.adbaddr = 0;
179 aa_args.handler_id = 0;
180 (void)config_found(self, &aa_args, adbprint);
181 #endif
182
183 /* for each ADB device */
184 for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
185 /* Get the ADB information */
186 adbaddr = GetIndADB(&adbdata, adbindex);
187
188 aa_args.origaddr = (int)(adbdata.origADBAddr);
189 aa_args.adbaddr = adbaddr;
190 aa_args.handler_id = (int)(adbdata.devType);
191
192 (void)config_found(self, &aa_args, adbprint);
193 }
194 adb_polling = 0;
195 }
196
197
198 int
199 adbprint(args, name)
200 void *args;
201 const char *name;
202 {
203 struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
204 int rv = UNCONF;
205
206 if (name) { /* no configured device matched */
207 rv = UNSUPP; /* most ADB device types are unsupported */
208
209 /* print out what kind of ADB device we have found */
210 printf("%s addr %d: ", name, aa_args->origaddr);
211 switch(aa_args->origaddr) {
212 #ifdef DIAGNOSTIC
213 case 0:
214 printf("ADB event device");
215 rv = UNCONF;
216 break;
217 case ADBADDR_SECURE:
218 printf("security dongle (%d)", aa_args->handler_id);
219 break;
220 #endif
221 case ADBADDR_MAP:
222 printf("mapped device (%d)", aa_args->handler_id);
223 rv = UNCONF;
224 break;
225 case ADBADDR_REL:
226 printf("relative positioning device (%d)",
227 aa_args->handler_id);
228 rv = UNCONF;
229 break;
230 #ifdef DIAGNOSTIC
231 case ADBADDR_ABS:
232 switch (aa_args->handler_id) {
233 case ADB_ARTPAD:
234 printf("WACOM ArtPad II");
235 break;
236 default:
237 printf("absolute positioning device (%d)",
238 aa_args->handler_id);
239 break;
240 }
241 break;
242 case ADBADDR_DATATX:
243 printf("data transfer device (modem?) (%d)",
244 aa_args->handler_id);
245 break;
246 case ADBADDR_MISC:
247 switch (aa_args->handler_id) {
248 case ADB_POWERKEY:
249 printf("Sophisticated Circuits PowerKey");
250 break;
251 default:
252 printf("misc. device (remote control?) (%d)",
253 aa_args->handler_id);
254 break;
255 }
256 break;
257 default:
258 printf("unknown type device, (handler %d)",
259 aa_args->handler_id);
260 break;
261 #endif /* DIAGNOSTIC */
262 }
263 } else /* a device matched and was configured */
264 printf(" addr %d: ", aa_args->origaddr);
265
266 return (rv);
267 }
268