adb.c revision 1.3 1 /* $NetBSD: adb.c,v 1.3 1998/10/13 11:21:21 tsubai 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 <sys/param.h>
34 #include <sys/device.h>
35 #include <sys/fcntl.h>
36 #include <sys/poll.h>
37 #include <sys/select.h>
38 #include <sys/proc.h>
39 #include <sys/signalvar.h>
40 #include <sys/systm.h>
41
42 #include <machine/autoconf.h>
43
44 #include <macppc/dev/adbvar.h>
45 #include <macppc/dev/akbdvar.h>
46 #include <macppc/dev/viareg.h>
47
48 /*
49 * Function declarations.
50 */
51 static int adbmatch __P((struct device *, struct cfdata *, void *));
52 static void adbattach __P((struct device *, struct device *, void *));
53 static int adbprint __P((void *, const char *));
54
55 /*
56 * Global variables.
57 */
58 int adb_polling = 0; /* Are we polling? (Debugger mode) */
59 int adb_initted = 0; /* adb_init() has completed successfully */
60 #ifdef ADB_DEBUG
61 int adb_debug = 0; /* Output debugging messages */
62 #endif /* ADB_DEBUG */
63
64 /*
65 * Driver definition.
66 */
67 struct cfattach adb_ca = {
68 sizeof(struct adb_softc), adbmatch, adbattach
69 };
70
71 static int
72 adbmatch(parent, cf, aux)
73 struct device *parent;
74 struct cfdata *cf;
75 void *aux;
76 {
77 struct confargs *ca = aux;
78
79 if (strcmp(ca->ca_name, "via-cuda") != 0)
80 return 0;
81
82 if (ca->ca_nreg < 8)
83 return 0;
84
85 if (ca->ca_nintr < 4)
86 return 0;
87
88 return 1;
89 }
90
91 static void
92 adbattach(parent, self, aux)
93 struct device *parent, *self;
94 void *aux;
95 {
96 struct adb_softc *sc = (struct adb_softc *)self;
97 struct confargs *ca = aux;
98
99 ADBDataBlock adbdata;
100 struct adb_attach_args aa_args;
101 int totaladbs;
102 int adbindex, adbaddr;
103
104 extern adb_intr();
105 extern volatile u_char *Via1Base;
106
107 ca->ca_reg[0] += ca->ca_baseaddr;
108
109 sc->sc_regbase = mapiodev(ca->ca_reg[0], ca->ca_reg[1]);
110 Via1Base = sc->sc_regbase;
111
112 adb_polling = 1;
113 ADBReInit();
114
115 intr_establish(ca->ca_intr[0], IST_LEVEL, IPL_HIGH, adb_intr, sc);
116
117 #ifdef ADB_DEBUG
118 if (adb_debug)
119 printf("adb: done with ADBReInit\n");
120 #endif
121 totaladbs = CountADBs();
122
123 printf(" irq %d", ca->ca_intr[0]);
124 printf(": %d targets\n", totaladbs);
125
126 /* ADB event device for compatibility */
127 aa_args.origaddr = 0;
128 aa_args.adbaddr = 0;
129 aa_args.handler_id = 0;
130 (void)config_found(self, &aa_args, adbprint);
131
132 /* for each ADB device */
133 for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
134 /* Get the ADB information */
135 adbaddr = GetIndADB(&adbdata, adbindex);
136
137 aa_args.origaddr = adbdata.origADBAddr;
138 aa_args.adbaddr = adbaddr;
139 aa_args.handler_id = adbdata.devType;
140
141 (void)config_found(self, &aa_args, adbprint);
142 }
143
144 adb_cuda_autopoll();
145 adb_polling = 0;
146 }
147
148 int
149 adbprint(args, name)
150 void *args;
151 const char *name;
152 {
153 struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
154 int rv = UNCONF;
155
156 if (name) { /* no configured device matched */
157 rv = UNSUPP; /* most ADB device types are unsupported */
158
159 /* print out what kind of ADB device we have found */
160 printf("%s addr %d: ", name, aa_args->origaddr);
161 switch(aa_args->origaddr) {
162 #ifdef DIAGNOSTIC
163 case 0:
164 printf("ADB event device");
165 rv = UNCONF;
166 break;
167 case ADBADDR_SECURE:
168 printf("security dongle (%d)", aa_args->handler_id);
169 break;
170 #endif
171 case ADBADDR_MAP:
172 printf("mapped device (%d)", aa_args->handler_id);
173 rv = UNCONF;
174 break;
175 case ADBADDR_REL:
176 printf("relative positioning device (%d)",
177 aa_args->handler_id);
178 rv = UNCONF;
179 break;
180 #ifdef DIAGNOSTIC
181 case ADBADDR_ABS:
182 switch (aa_args->handler_id) {
183 case ADB_ARTPAD:
184 printf("WACOM ArtPad II");
185 break;
186 default:
187 printf("absolute positioning device (%d)",
188 aa_args->handler_id);
189 break;
190 }
191 break;
192 case ADBADDR_DATATX:
193 printf("data transfer device (modem?) (%d)",
194 aa_args->handler_id);
195 break;
196 case ADBADDR_MISC:
197 switch (aa_args->handler_id) {
198 case ADB_POWERKEY:
199 printf("Sophisticated Circuits PowerKey");
200 break;
201 default:
202 printf("misc. device (remote control?) (%d)",
203 aa_args->handler_id);
204 break;
205 }
206 break;
207 default:
208 printf("unknown type device, (handler %d)",
209 aa_args->handler_id);
210 break;
211 #endif /* DIAGNOSTIC */
212 }
213 } else /* a device matched and was configured */
214 printf(" addr %d: ", aa_args->origaddr);
215
216 return (rv);
217 }
218