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