adb.c revision 1.27.2.1 1 /* $NetBSD: adb.c,v 1.27.2.1 1999/03/05 08:24:24 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/akbdvar.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 int adb_initted = 0; /* adb_init() has completed successfully */
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, dev, aux)
101 struct device *parent, *dev;
102 void *aux;
103 {
104 ADBDataBlock adbdata;
105 struct adb_attach_args aa_args;
106 int totaladbs;
107 int adbindex, adbaddr;
108
109 #ifdef MRG_ADB
110 /*
111 * Even if serial console only, some models require the
112 * ADB in order to get the date/time and do soft power.
113 */
114 if ((mac68k_machine.serial_console & 0x03)) {
115 printf(": using serial console");
116 return;
117 }
118
119 if (!mrg_romready()) {
120 printf(": no ROM ADB driver in this kernel for this machine");
121 return;
122 }
123
124 #ifdef ADB_DEBUG
125 if (adb_debug)
126 printf("adb: call mrg_initadbintr\n");
127 #endif
128
129 mrg_initadbintr(); /* Mac ROM Glue okay to do ROM intr */
130 #ifdef ADB_DEBUG
131 if (adb_debug)
132 printf("adb: returned from mrg_initadbintr\n");
133 #endif
134
135 /* ADBReInit pre/post-processing */
136 JADBProc = adb_jadbproc;
137
138 /* Initialize ADB */
139 #ifdef ADB_DEBUG
140 if (adb_debug)
141 printf("adb: calling ADBAlternateInit.\n");
142 #endif
143
144 printf(" (mrg) ");
145 ADBAlternateInit();
146 #else
147 ADBReInit();
148 printf(" (direct, %s)", adbHardwareDescr[adbHardware]);
149 #endif /* MRG_ADB */
150
151 #ifdef ADB_DEBUG
152 if (adb_debug)
153 printf("adb: done with ADBReInit\n");
154 #endif
155
156 totaladbs = CountADBs();
157
158 printf(": %d targets\n", totaladbs);
159
160 #if NAED > 0
161 /* ADB event device for compatibility */
162 aa_args.origaddr = 0;
163 aa_args.adbaddr = 0;
164 aa_args.handler_id = 0;
165 (void)config_found(dev, &aa_args, adbprint);
166 #endif
167
168 /* for each ADB device */
169 for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
170 /* Get the ADB information */
171 adbaddr = GetIndADB(&adbdata, adbindex);
172
173 aa_args.origaddr = (int)(adbdata.origADBAddr);
174 aa_args.adbaddr = adbaddr;
175 aa_args.handler_id = (int)(adbdata.devType);
176
177 (void)config_found(dev, &aa_args, adbprint);
178 }
179 }
180
181
182 int
183 adbprint(args, name)
184 void *args;
185 const char *name;
186 {
187 struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
188 int rv = UNCONF;
189
190 if (name) { /* no configured device matched */
191 rv = UNSUPP; /* most ADB device types are unsupported */
192
193 /* print out what kind of ADB device we have found */
194 printf("%s addr %d: ", name, aa_args->origaddr);
195 switch(aa_args->origaddr) {
196 #ifdef DIAGNOSTIC
197 case 0:
198 printf("ADB event device");
199 rv = UNCONF;
200 break;
201 case ADBADDR_SECURE:
202 printf("security dongle (%d)", aa_args->handler_id);
203 break;
204 #endif
205 case ADBADDR_MAP:
206 printf("mapped device (%d)", aa_args->handler_id);
207 rv = UNCONF;
208 break;
209 case ADBADDR_REL:
210 printf("relative positioning device (%d)",
211 aa_args->handler_id);
212 rv = UNCONF;
213 break;
214 #ifdef DIAGNOSTIC
215 case ADBADDR_ABS:
216 switch (aa_args->handler_id) {
217 case ADB_ARTPAD:
218 printf("WACOM ArtPad II");
219 break;
220 default:
221 printf("absolute positioning device (%d)",
222 aa_args->handler_id);
223 break;
224 }
225 break;
226 case ADBADDR_DATATX:
227 printf("data transfer device (modem?) (%d)",
228 aa_args->handler_id);
229 break;
230 case ADBADDR_MISC:
231 switch (aa_args->handler_id) {
232 case ADB_POWERKEY:
233 printf("Sophisticated Circuits PowerKey");
234 break;
235 default:
236 printf("misc. device (remote control?) (%d)",
237 aa_args->handler_id);
238 break;
239 }
240 break;
241 default:
242 printf("unknown type device, (handler %d)",
243 aa_args->handler_id);
244 break;
245 #endif /* DIAGNOSTIC */
246 }
247 } else /* a device matched and was configured */
248 printf(" addr %d: ", aa_args->origaddr);
249
250 return (rv);
251 }
252