Home | History | Annotate | Line # | Download | only in dev
adb.c revision 1.4
      1 /*	$NetBSD: adb.c,v 1.4 1998/10/18 09:52:16 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 static int
     74 adbmatch(parent, cf, aux)
     75 	struct device *parent;
     76 	struct cfdata *cf;
     77 	void *aux;
     78 {
     79 	struct confargs *ca = aux;
     80 
     81 	if (strcmp(ca->ca_name, "via-cuda") != 0)
     82 		return 0;
     83 
     84 	if (ca->ca_nreg < 8)
     85 		return 0;
     86 
     87 	if (ca->ca_nintr < 4)
     88 		return 0;
     89 
     90 	return 1;
     91 }
     92 
     93 static void
     94 adbattach(parent, self, aux)
     95 	struct device *parent, *self;
     96 	void   *aux;
     97 {
     98 	struct adb_softc *sc = (struct adb_softc *)self;
     99 	struct confargs *ca = aux;
    100 
    101 	ADBDataBlock adbdata;
    102 	struct adb_attach_args aa_args;
    103 	int totaladbs;
    104 	int adbindex, adbaddr;
    105 
    106 	extern adb_intr();
    107 	extern volatile u_char *Via1Base;
    108 
    109 	ca->ca_reg[0] += ca->ca_baseaddr;
    110 
    111 	sc->sc_regbase = mapiodev(ca->ca_reg[0], ca->ca_reg[1]);
    112 	Via1Base = sc->sc_regbase;
    113 
    114 	adb_polling = 1;
    115 	ADBReInit();
    116 
    117 	intr_establish(ca->ca_intr[0], IST_LEVEL, IPL_HIGH, adb_intr, sc);
    118 
    119 #ifdef ADB_DEBUG
    120 	if (adb_debug)
    121 		printf("adb: done with ADBReInit\n");
    122 #endif
    123 	totaladbs = CountADBs();
    124 
    125 	printf(" irq %d", ca->ca_intr[0]);
    126 	printf(": %d targets\n", totaladbs);
    127 
    128 #if NAED > 0
    129 	/* ADB event device for compatibility */
    130 	aa_args.origaddr = 0;
    131 	aa_args.adbaddr = 0;
    132 	aa_args.handler_id = 0;
    133 	(void)config_found(self, &aa_args, adbprint);
    134 #endif
    135 
    136 	/* for each ADB device */
    137 	for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
    138 		/* Get the ADB information */
    139 		adbaddr = GetIndADB(&adbdata, adbindex);
    140 
    141 		aa_args.origaddr = adbdata.origADBAddr;
    142 		aa_args.adbaddr = adbaddr;
    143 		aa_args.handler_id = adbdata.devType;
    144 
    145 		(void)config_found(self, &aa_args, adbprint);
    146 	}
    147 
    148 	adb_cuda_autopoll();
    149 	adb_polling = 0;
    150 }
    151 
    152 int
    153 adbprint(args, name)
    154         void *args;
    155         const char *name;
    156 {
    157 	struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
    158 	int rv = UNCONF;
    159 
    160 	if (name) {	/* no configured device matched */
    161 		rv = UNSUPP; /* most ADB device types are unsupported */
    162 
    163 		/* print out what kind of ADB device we have found */
    164 		printf("%s addr %d: ", name, aa_args->origaddr);
    165 		switch(aa_args->origaddr) {
    166 #ifdef DIAGNOSTIC
    167 		case 0:
    168 			printf("ADB event device");
    169 			rv = UNCONF;
    170 			break;
    171 		case ADBADDR_SECURE:
    172 			printf("security dongle (%d)", aa_args->handler_id);
    173 			break;
    174 #endif
    175 		case ADBADDR_MAP:
    176 			printf("mapped device (%d)", aa_args->handler_id);
    177 			rv = UNCONF;
    178 			break;
    179 		case ADBADDR_REL:
    180 			printf("relative positioning device (%d)",
    181 			    aa_args->handler_id);
    182 			rv = UNCONF;
    183 			break;
    184 #ifdef DIAGNOSTIC
    185 		case ADBADDR_ABS:
    186 			switch (aa_args->handler_id) {
    187 			case ADB_ARTPAD:
    188 				printf("WACOM ArtPad II");
    189 				break;
    190 			default:
    191 				printf("absolute positioning device (%d)",
    192 				    aa_args->handler_id);
    193 				break;
    194 			}
    195 			break;
    196 		case ADBADDR_DATATX:
    197 			printf("data transfer device (modem?) (%d)",
    198 			    aa_args->handler_id);
    199 			break;
    200 		case ADBADDR_MISC:
    201 			switch (aa_args->handler_id) {
    202 			case ADB_POWERKEY:
    203 				printf("Sophisticated Circuits PowerKey");
    204 				break;
    205 			default:
    206 				printf("misc. device (remote control?) (%d)",
    207 				    aa_args->handler_id);
    208 				break;
    209 			}
    210 			break;
    211 		default:
    212 			printf("unknown type device, (handler %d)",
    213 			    aa_args->handler_id);
    214 			break;
    215 #endif /* DIAGNOSTIC */
    216 		}
    217 	} else		/* a device matched and was configured */
    218                 printf(" addr %d: ", aa_args->origaddr);
    219 
    220 	return (rv);
    221 }
    222