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