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