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