Home | History | Annotate | Line # | Download | only in dev
adb.c revision 1.8
      1 /*	$NetBSD: adb.c,v 1.8 2001/04/01 10:40:45 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 	int irq = ca->ca_intr[0];
    106 	int node;
    107 	ADBDataBlock adbdata;
    108 	struct adb_attach_args aa_args;
    109 	int totaladbs;
    110 	int adbindex, adbaddr;
    111 
    112 	extern adb_intr();
    113 	extern volatile u_char *Via1Base;
    114 
    115 	ca->ca_reg[0] += ca->ca_baseaddr;
    116 
    117 	sc->sc_regbase = mapiodev(ca->ca_reg[0], ca->ca_reg[1]);
    118 	Via1Base = sc->sc_regbase;
    119 
    120 	if (strcmp(ca->ca_name, "via-cuda") == 0)
    121 		adbHardware = ADB_HW_CUDA;
    122 	else if (strcmp(ca->ca_name, "via-pmu") == 0)
    123 		adbHardware = ADB_HW_PB;
    124 
    125 	node = getnodebyname(OF_parent(ca->ca_node), "extint-gpio1");
    126 	if (node)
    127 		OF_getprop(node, "interrupts", &irq, 4);
    128 
    129 	printf(" irq %d: ", irq);
    130 
    131 	adb_polling = 1;
    132 	ADBReInit();
    133 
    134 	intr_establish(irq, IST_LEVEL, IPL_HIGH, adb_intr, sc);
    135 
    136 #ifdef ADB_DEBUG
    137 	if (adb_debug)
    138 		printf("adb: done with ADBReInit\n");
    139 #endif
    140 	totaladbs = CountADBs();
    141 
    142 	printf("%d targets\n", totaladbs);
    143 
    144 #if NAED > 0
    145 	/* ADB event device for compatibility */
    146 	aa_args.origaddr = 0;
    147 	aa_args.adbaddr = 0;
    148 	aa_args.handler_id = 0;
    149 	(void)config_found(self, &aa_args, adbprint);
    150 #endif
    151 
    152 	/* for each ADB device */
    153 	for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
    154 		/* Get the ADB information */
    155 		adbaddr = GetIndADB(&adbdata, adbindex);
    156 
    157 		aa_args.origaddr = adbdata.origADBAddr;
    158 		aa_args.adbaddr = adbaddr;
    159 		aa_args.handler_id = adbdata.devType;
    160 
    161 		(void)config_found(self, &aa_args, adbprint);
    162 	}
    163 
    164 	if (adbHardware == ADB_HW_CUDA)
    165 		adb_cuda_autopoll();
    166 	adb_polling = 0;
    167 }
    168 
    169 int
    170 adbprint(args, name)
    171 	void *args;
    172 	const char *name;
    173 {
    174 	struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
    175 	int rv = UNCONF;
    176 
    177 	if (name) {	/* no configured device matched */
    178 		rv = UNSUPP; /* most ADB device types are unsupported */
    179 
    180 		/* print out what kind of ADB device we have found */
    181 		printf("%s addr %d: ", name, aa_args->adbaddr);
    182 		switch(aa_args->origaddr) {
    183 #ifdef DIAGNOSTIC
    184 		case 0:
    185 			printf("ADB event device");
    186 			rv = UNCONF;
    187 			break;
    188 		case ADBADDR_SECURE:
    189 			printf("security dongle (%d)", aa_args->handler_id);
    190 			break;
    191 #endif
    192 		case ADBADDR_MAP:
    193 			printf("mapped device (%d)", aa_args->handler_id);
    194 			rv = UNCONF;
    195 			break;
    196 		case ADBADDR_REL:
    197 			printf("relative positioning device (%d)",
    198 			    aa_args->handler_id);
    199 			rv = UNCONF;
    200 			break;
    201 #ifdef DIAGNOSTIC
    202 		case ADBADDR_ABS:
    203 			switch (aa_args->handler_id) {
    204 			case ADB_ARTPAD:
    205 				printf("WACOM ArtPad II");
    206 				break;
    207 			default:
    208 				printf("absolute positioning device (%d)",
    209 				    aa_args->handler_id);
    210 				break;
    211 			}
    212 			break;
    213 		case ADBADDR_DATATX:
    214 			printf("data transfer device (modem?) (%d)",
    215 			    aa_args->handler_id);
    216 			break;
    217 		case ADBADDR_MISC:
    218 			switch (aa_args->handler_id) {
    219 			case ADB_POWERKEY:
    220 				printf("Sophisticated Circuits PowerKey");
    221 				break;
    222 			default:
    223 				printf("misc. device (remote control?) (%d)",
    224 				    aa_args->handler_id);
    225 				break;
    226 			}
    227 			break;
    228 		default:
    229 			printf("unknown type device, (handler %d)",
    230 			    aa_args->handler_id);
    231 			break;
    232 #endif /* DIAGNOSTIC */
    233 		}
    234 	} else		/* a device matched and was configured */
    235                 printf(" addr %d: ", aa_args->adbaddr);
    236 
    237 	return rv;
    238 }
    239