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