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