adb.c revision 1.17 1 1.17 briggs /* $NetBSD: adb.c,v 1.17 2005/02/01 02:46:00 briggs Exp $ */
2 1.1 tsubai
3 1.1 tsubai /*-
4 1.1 tsubai * Copyright (C) 1994 Bradley A. Grantham
5 1.1 tsubai * All rights reserved.
6 1.1 tsubai *
7 1.1 tsubai * Redistribution and use in source and binary forms, with or without
8 1.1 tsubai * modification, are permitted provided that the following conditions
9 1.1 tsubai * are met:
10 1.1 tsubai * 1. Redistributions of source code must retain the above copyright
11 1.1 tsubai * notice, this list of conditions and the following disclaimer.
12 1.1 tsubai * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tsubai * notice, this list of conditions and the following disclaimer in the
14 1.1 tsubai * documentation and/or other materials provided with the distribution.
15 1.1 tsubai * 3. All advertising materials mentioning features or use of this software
16 1.1 tsubai * must display the following acknowledgement:
17 1.1 tsubai * This product includes software developed by Bradley A. Grantham.
18 1.1 tsubai * 4. The name of the author may not be used to endorse or promote products
19 1.1 tsubai * derived from this software without specific prior written permission.
20 1.1 tsubai *
21 1.1 tsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 tsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 tsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 tsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 tsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 tsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 tsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 tsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 tsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 1.1 tsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 tsubai */
32 1.15 lukem
33 1.15 lukem #include <sys/cdefs.h>
34 1.17 briggs __KERNEL_RCSID(0, "$NetBSD: adb.c,v 1.17 2005/02/01 02:46:00 briggs Exp $");
35 1.1 tsubai
36 1.1 tsubai #include <sys/param.h>
37 1.1 tsubai #include <sys/device.h>
38 1.1 tsubai #include <sys/fcntl.h>
39 1.1 tsubai #include <sys/poll.h>
40 1.1 tsubai #include <sys/select.h>
41 1.1 tsubai #include <sys/proc.h>
42 1.1 tsubai #include <sys/signalvar.h>
43 1.1 tsubai #include <sys/systm.h>
44 1.1 tsubai
45 1.1 tsubai #include <machine/autoconf.h>
46 1.1 tsubai
47 1.1 tsubai #include <macppc/dev/adbvar.h>
48 1.3 tsubai #include <macppc/dev/akbdvar.h>
49 1.17 briggs #include <macppc/dev/pm_direct.h>
50 1.1 tsubai #include <macppc/dev/viareg.h>
51 1.1 tsubai
52 1.9 matt #include <dev/ofw/openfirm.h>
53 1.9 matt
54 1.4 tsubai #include "aed.h"
55 1.11 itojun #include "apm.h"
56 1.4 tsubai
57 1.1 tsubai /*
58 1.1 tsubai * Function declarations.
59 1.1 tsubai */
60 1.1 tsubai static int adbmatch __P((struct device *, struct cfdata *, void *));
61 1.1 tsubai static void adbattach __P((struct device *, struct device *, void *));
62 1.3 tsubai static int adbprint __P((void *, const char *));
63 1.1 tsubai
64 1.1 tsubai /*
65 1.1 tsubai * Global variables.
66 1.1 tsubai */
67 1.1 tsubai int adb_polling = 0; /* Are we polling? (Debugger mode) */
68 1.1 tsubai int adb_initted = 0; /* adb_init() has completed successfully */
69 1.1 tsubai #ifdef ADB_DEBUG
70 1.1 tsubai int adb_debug = 0; /* Output debugging messages */
71 1.1 tsubai #endif /* ADB_DEBUG */
72 1.1 tsubai
73 1.1 tsubai /*
74 1.3 tsubai * Driver definition.
75 1.1 tsubai */
76 1.13 thorpej CFATTACH_DECL(adb, sizeof(struct adb_softc),
77 1.13 thorpej adbmatch, adbattach, NULL, NULL);
78 1.5 tsubai
79 1.1 tsubai static int
80 1.1 tsubai adbmatch(parent, cf, aux)
81 1.1 tsubai struct device *parent;
82 1.1 tsubai struct cfdata *cf;
83 1.1 tsubai void *aux;
84 1.1 tsubai {
85 1.1 tsubai struct confargs *ca = aux;
86 1.1 tsubai
87 1.1 tsubai if (ca->ca_nreg < 8)
88 1.1 tsubai return 0;
89 1.1 tsubai
90 1.1 tsubai if (ca->ca_nintr < 4)
91 1.1 tsubai return 0;
92 1.1 tsubai
93 1.5 tsubai if (strcmp(ca->ca_name, "via-cuda") == 0)
94 1.5 tsubai return 1;
95 1.5 tsubai
96 1.5 tsubai if (strcmp(ca->ca_name, "via-pmu") == 0)
97 1.5 tsubai return 1;
98 1.5 tsubai
99 1.5 tsubai return 0;
100 1.1 tsubai }
101 1.1 tsubai
102 1.1 tsubai static void
103 1.1 tsubai adbattach(parent, self, aux)
104 1.1 tsubai struct device *parent, *self;
105 1.1 tsubai void *aux;
106 1.1 tsubai {
107 1.1 tsubai struct adb_softc *sc = (struct adb_softc *)self;
108 1.1 tsubai struct confargs *ca = aux;
109 1.8 tsubai int irq = ca->ca_intr[0];
110 1.8 tsubai int node;
111 1.3 tsubai ADBDataBlock adbdata;
112 1.3 tsubai struct adb_attach_args aa_args;
113 1.3 tsubai int totaladbs;
114 1.3 tsubai int adbindex, adbaddr;
115 1.3 tsubai
116 1.3 tsubai extern volatile u_char *Via1Base;
117 1.1 tsubai
118 1.1 tsubai ca->ca_reg[0] += ca->ca_baseaddr;
119 1.1 tsubai
120 1.1 tsubai sc->sc_regbase = mapiodev(ca->ca_reg[0], ca->ca_reg[1]);
121 1.1 tsubai Via1Base = sc->sc_regbase;
122 1.1 tsubai
123 1.5 tsubai if (strcmp(ca->ca_name, "via-cuda") == 0)
124 1.5 tsubai adbHardware = ADB_HW_CUDA;
125 1.5 tsubai else if (strcmp(ca->ca_name, "via-pmu") == 0)
126 1.16 briggs adbHardware = ADB_HW_PMU;
127 1.5 tsubai
128 1.8 tsubai node = getnodebyname(OF_parent(ca->ca_node), "extint-gpio1");
129 1.8 tsubai if (node)
130 1.8 tsubai OF_getprop(node, "interrupts", &irq, 4);
131 1.8 tsubai
132 1.8 tsubai printf(" irq %d: ", irq);
133 1.8 tsubai
134 1.1 tsubai adb_polling = 1;
135 1.3 tsubai ADBReInit();
136 1.1 tsubai
137 1.9 matt intr_establish(irq, IST_LEVEL, IPL_HIGH, (int (*)(void *))adb_intr, sc);
138 1.17 briggs if (adbHardware == ADB_HW_PMU) {
139 1.17 briggs pm_init();
140 1.17 briggs }
141 1.1 tsubai
142 1.3 tsubai #ifdef ADB_DEBUG
143 1.3 tsubai if (adb_debug)
144 1.3 tsubai printf("adb: done with ADBReInit\n");
145 1.1 tsubai #endif
146 1.3 tsubai totaladbs = CountADBs();
147 1.1 tsubai
148 1.8 tsubai printf("%d targets\n", totaladbs);
149 1.1 tsubai
150 1.4 tsubai #if NAED > 0
151 1.3 tsubai /* ADB event device for compatibility */
152 1.3 tsubai aa_args.origaddr = 0;
153 1.3 tsubai aa_args.adbaddr = 0;
154 1.3 tsubai aa_args.handler_id = 0;
155 1.3 tsubai (void)config_found(self, &aa_args, adbprint);
156 1.4 tsubai #endif
157 1.1 tsubai
158 1.3 tsubai /* for each ADB device */
159 1.3 tsubai for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
160 1.3 tsubai /* Get the ADB information */
161 1.3 tsubai adbaddr = GetIndADB(&adbdata, adbindex);
162 1.1 tsubai
163 1.3 tsubai aa_args.origaddr = adbdata.origADBAddr;
164 1.3 tsubai aa_args.adbaddr = adbaddr;
165 1.3 tsubai aa_args.handler_id = adbdata.devType;
166 1.1 tsubai
167 1.3 tsubai (void)config_found(self, &aa_args, adbprint);
168 1.1 tsubai }
169 1.11 itojun
170 1.11 itojun #if NAPM > 0
171 1.11 itojun /* Magic for signalling the apm driver to match. */
172 1.11 itojun aa_args.origaddr = ADBADDR_APM;
173 1.11 itojun aa_args.adbaddr = ADBADDR_APM;
174 1.11 itojun aa_args.handler_id = ADBADDR_APM;
175 1.11 itojun
176 1.11 itojun (void)config_found(self, &aa_args, NULL);
177 1.11 itojun #endif
178 1.1 tsubai
179 1.5 tsubai if (adbHardware == ADB_HW_CUDA)
180 1.5 tsubai adb_cuda_autopoll();
181 1.3 tsubai adb_polling = 0;
182 1.1 tsubai }
183 1.1 tsubai
184 1.3 tsubai int
185 1.3 tsubai adbprint(args, name)
186 1.7 tsubai void *args;
187 1.7 tsubai const char *name;
188 1.3 tsubai {
189 1.3 tsubai struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
190 1.3 tsubai int rv = UNCONF;
191 1.3 tsubai
192 1.3 tsubai if (name) { /* no configured device matched */
193 1.3 tsubai rv = UNSUPP; /* most ADB device types are unsupported */
194 1.3 tsubai
195 1.3 tsubai /* print out what kind of ADB device we have found */
196 1.14 thorpej aprint_normal("%s addr %d: ", name, aa_args->adbaddr);
197 1.3 tsubai switch(aa_args->origaddr) {
198 1.3 tsubai #ifdef DIAGNOSTIC
199 1.3 tsubai case 0:
200 1.14 thorpej aprint_normal("ADB event device");
201 1.3 tsubai rv = UNCONF;
202 1.3 tsubai break;
203 1.3 tsubai case ADBADDR_SECURE:
204 1.14 thorpej aprint_normal("security dongle (%d)",
205 1.14 thorpej aa_args->handler_id);
206 1.3 tsubai break;
207 1.1 tsubai #endif
208 1.3 tsubai case ADBADDR_MAP:
209 1.14 thorpej aprint_normal("mapped device (%d)",
210 1.14 thorpej aa_args->handler_id);
211 1.3 tsubai rv = UNCONF;
212 1.3 tsubai break;
213 1.3 tsubai case ADBADDR_REL:
214 1.14 thorpej aprint_normal("relative positioning device (%d)",
215 1.3 tsubai aa_args->handler_id);
216 1.3 tsubai rv = UNCONF;
217 1.3 tsubai break;
218 1.3 tsubai #ifdef DIAGNOSTIC
219 1.3 tsubai case ADBADDR_ABS:
220 1.3 tsubai switch (aa_args->handler_id) {
221 1.3 tsubai case ADB_ARTPAD:
222 1.14 thorpej aprint_normal("WACOM ArtPad II");
223 1.3 tsubai break;
224 1.3 tsubai default:
225 1.14 thorpej aprint_normal("absolute positioning device (%d)",
226 1.3 tsubai aa_args->handler_id);
227 1.3 tsubai break;
228 1.3 tsubai }
229 1.3 tsubai break;
230 1.3 tsubai case ADBADDR_DATATX:
231 1.14 thorpej aprint_normal("data transfer device (modem?) (%d)",
232 1.3 tsubai aa_args->handler_id);
233 1.1 tsubai break;
234 1.3 tsubai case ADBADDR_MISC:
235 1.3 tsubai switch (aa_args->handler_id) {
236 1.3 tsubai case ADB_POWERKEY:
237 1.14 thorpej aprint_normal("Sophisticated Circuits PowerKey");
238 1.3 tsubai break;
239 1.3 tsubai default:
240 1.14 thorpej aprint_normal("misc. device (remote control?) (%d)",
241 1.3 tsubai aa_args->handler_id);
242 1.3 tsubai break;
243 1.3 tsubai }
244 1.1 tsubai break;
245 1.1 tsubai default:
246 1.14 thorpej aprint_normal("unknown type device, (handler %d)",
247 1.3 tsubai aa_args->handler_id);
248 1.1 tsubai break;
249 1.3 tsubai #endif /* DIAGNOSTIC */
250 1.1 tsubai }
251 1.3 tsubai } else /* a device matched and was configured */
252 1.14 thorpej aprint_normal(" addr %d: ", aa_args->adbaddr);
253 1.1 tsubai
254 1.7 tsubai return rv;
255 1.1 tsubai }
256