adb.c revision 1.11 1 /* $NetBSD: adb.c,v 1.11 2002/06/18 05:22:51 itojun 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 #include <dev/ofw/openfirm.h>
49
50 #include "aed.h"
51 #include "apm.h"
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
60 /*
61 * Global variables.
62 */
63 int adb_polling = 0; /* Are we polling? (Debugger mode) */
64 int adb_initted = 0; /* adb_init() has completed successfully */
65 #ifdef ADB_DEBUG
66 int adb_debug = 0; /* Output debugging messages */
67 #endif /* ADB_DEBUG */
68
69 /*
70 * Driver definition.
71 */
72 struct cfattach adb_ca = {
73 sizeof(struct adb_softc), adbmatch, adbattach
74 };
75
76 static int
77 adbmatch(parent, cf, aux)
78 struct device *parent;
79 struct cfdata *cf;
80 void *aux;
81 {
82 struct confargs *ca = aux;
83
84 if (ca->ca_nreg < 8)
85 return 0;
86
87 if (ca->ca_nintr < 4)
88 return 0;
89
90 if (strcmp(ca->ca_name, "via-cuda") == 0)
91 return 1;
92
93 if (strcmp(ca->ca_name, "via-pmu") == 0)
94 return 1;
95
96 return 0;
97 }
98
99 static void
100 adbattach(parent, self, aux)
101 struct device *parent, *self;
102 void *aux;
103 {
104 struct adb_softc *sc = (struct adb_softc *)self;
105 struct confargs *ca = aux;
106 int irq = ca->ca_intr[0];
107 int node;
108 ADBDataBlock adbdata;
109 struct adb_attach_args aa_args;
110 int totaladbs;
111 int adbindex, adbaddr;
112
113 extern volatile u_char *Via1Base;
114
115 ca->ca_reg[0] += ca->ca_baseaddr;
116
117 sc->sc_regbase = mapiodev(ca->ca_reg[0], ca->ca_reg[1]);
118 Via1Base = sc->sc_regbase;
119
120 if (strcmp(ca->ca_name, "via-cuda") == 0)
121 adbHardware = ADB_HW_CUDA;
122 else if (strcmp(ca->ca_name, "via-pmu") == 0)
123 adbHardware = ADB_HW_PB;
124
125 node = getnodebyname(OF_parent(ca->ca_node), "extint-gpio1");
126 if (node)
127 OF_getprop(node, "interrupts", &irq, 4);
128
129 printf(" irq %d: ", irq);
130
131 adb_polling = 1;
132 ADBReInit();
133
134 intr_establish(irq, IST_LEVEL, IPL_HIGH, (int (*)(void *))adb_intr, sc);
135
136 #ifdef ADB_DEBUG
137 if (adb_debug)
138 printf("adb: done with ADBReInit\n");
139 #endif
140 totaladbs = CountADBs();
141
142 printf("%d targets\n", totaladbs);
143
144 #if NAED > 0
145 /* ADB event device for compatibility */
146 aa_args.origaddr = 0;
147 aa_args.adbaddr = 0;
148 aa_args.handler_id = 0;
149 (void)config_found(self, &aa_args, adbprint);
150 #endif
151
152 /* for each ADB device */
153 for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
154 /* Get the ADB information */
155 adbaddr = GetIndADB(&adbdata, adbindex);
156
157 aa_args.origaddr = adbdata.origADBAddr;
158 aa_args.adbaddr = adbaddr;
159 aa_args.handler_id = adbdata.devType;
160
161 (void)config_found(self, &aa_args, adbprint);
162 }
163
164 #if NAPM > 0
165 /* Magic for signalling the apm driver to match. */
166 aa_args.origaddr = ADBADDR_APM;
167 aa_args.adbaddr = ADBADDR_APM;
168 aa_args.handler_id = ADBADDR_APM;
169
170 (void)config_found(self, &aa_args, NULL);
171 #endif
172
173 if (adbHardware == ADB_HW_CUDA)
174 adb_cuda_autopoll();
175 adb_polling = 0;
176 }
177
178 int
179 adbprint(args, name)
180 void *args;
181 const char *name;
182 {
183 struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
184 int rv = UNCONF;
185
186 if (name) { /* no configured device matched */
187 rv = UNSUPP; /* most ADB device types are unsupported */
188
189 /* print out what kind of ADB device we have found */
190 printf("%s addr %d: ", name, aa_args->adbaddr);
191 switch(aa_args->origaddr) {
192 #ifdef DIAGNOSTIC
193 case 0:
194 printf("ADB event device");
195 rv = UNCONF;
196 break;
197 case ADBADDR_SECURE:
198 printf("security dongle (%d)", aa_args->handler_id);
199 break;
200 #endif
201 case ADBADDR_MAP:
202 printf("mapped device (%d)", aa_args->handler_id);
203 rv = UNCONF;
204 break;
205 case ADBADDR_REL:
206 printf("relative positioning device (%d)",
207 aa_args->handler_id);
208 rv = UNCONF;
209 break;
210 #ifdef DIAGNOSTIC
211 case ADBADDR_ABS:
212 switch (aa_args->handler_id) {
213 case ADB_ARTPAD:
214 printf("WACOM ArtPad II");
215 break;
216 default:
217 printf("absolute positioning device (%d)",
218 aa_args->handler_id);
219 break;
220 }
221 break;
222 case ADBADDR_DATATX:
223 printf("data transfer device (modem?) (%d)",
224 aa_args->handler_id);
225 break;
226 case ADBADDR_MISC:
227 switch (aa_args->handler_id) {
228 case ADB_POWERKEY:
229 printf("Sophisticated Circuits PowerKey");
230 break;
231 default:
232 printf("misc. device (remote control?) (%d)",
233 aa_args->handler_id);
234 break;
235 }
236 break;
237 default:
238 printf("unknown type device, (handler %d)",
239 aa_args->handler_id);
240 break;
241 #endif /* DIAGNOSTIC */
242 }
243 } else /* a device matched and was configured */
244 printf(" addr %d: ", aa_args->adbaddr);
245
246 return rv;
247 }
248