Home | History | Annotate | Line # | Download | only in dev
adb.c revision 1.13
      1 /*	$NetBSD: adb.c,v 1.13 2002/10/02 05:30:38 thorpej 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 #include "apm.h"
     52 
     53 /*
     54  * Function declarations.
     55  */
     56 static int	adbmatch __P((struct device *, struct cfdata *, void *));
     57 static void	adbattach __P((struct device *, struct device *, void *));
     58 static int	adbprint __P((void *, const char *));
     59 
     60 /*
     61  * Global variables.
     62  */
     63 int     adb_polling = 0;	/* Are we polling?  (Debugger mode) */
     64 int     adb_initted = 0;	/* adb_init() has completed successfully */
     65 #ifdef ADB_DEBUG
     66 int	adb_debug = 0;		/* Output debugging messages */
     67 #endif /* ADB_DEBUG */
     68 
     69 /*
     70  * Driver definition.
     71  */
     72 CFATTACH_DECL(adb, sizeof(struct adb_softc),
     73     adbmatch, adbattach, NULL, NULL);
     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 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 	node = getnodebyname(OF_parent(ca->ca_node), "extint-gpio1");
    125 	if (node)
    126 		OF_getprop(node, "interrupts", &irq, 4);
    127 
    128 	printf(" irq %d: ", irq);
    129 
    130 	adb_polling = 1;
    131 	ADBReInit();
    132 
    133 	intr_establish(irq, IST_LEVEL, IPL_HIGH, (int (*)(void *))adb_intr, sc);
    134 
    135 #ifdef ADB_DEBUG
    136 	if (adb_debug)
    137 		printf("adb: done with ADBReInit\n");
    138 #endif
    139 	totaladbs = CountADBs();
    140 
    141 	printf("%d targets\n", totaladbs);
    142 
    143 #if NAED > 0
    144 	/* ADB event device for compatibility */
    145 	aa_args.origaddr = 0;
    146 	aa_args.adbaddr = 0;
    147 	aa_args.handler_id = 0;
    148 	(void)config_found(self, &aa_args, adbprint);
    149 #endif
    150 
    151 	/* for each ADB device */
    152 	for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
    153 		/* Get the ADB information */
    154 		adbaddr = GetIndADB(&adbdata, adbindex);
    155 
    156 		aa_args.origaddr = adbdata.origADBAddr;
    157 		aa_args.adbaddr = adbaddr;
    158 		aa_args.handler_id = adbdata.devType;
    159 
    160 		(void)config_found(self, &aa_args, adbprint);
    161 	}
    162 
    163 #if NAPM > 0
    164 	/* Magic for signalling the apm driver to match. */
    165 	aa_args.origaddr = ADBADDR_APM;
    166 	aa_args.adbaddr = ADBADDR_APM;
    167 	aa_args.handler_id = ADBADDR_APM;
    168 
    169 	(void)config_found(self, &aa_args, NULL);
    170 #endif
    171 
    172 	if (adbHardware == ADB_HW_CUDA)
    173 		adb_cuda_autopoll();
    174 	adb_polling = 0;
    175 }
    176 
    177 int
    178 adbprint(args, name)
    179 	void *args;
    180 	const char *name;
    181 {
    182 	struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
    183 	int rv = UNCONF;
    184 
    185 	if (name) {	/* no configured device matched */
    186 		rv = UNSUPP; /* most ADB device types are unsupported */
    187 
    188 		/* print out what kind of ADB device we have found */
    189 		printf("%s addr %d: ", name, aa_args->adbaddr);
    190 		switch(aa_args->origaddr) {
    191 #ifdef DIAGNOSTIC
    192 		case 0:
    193 			printf("ADB event device");
    194 			rv = UNCONF;
    195 			break;
    196 		case ADBADDR_SECURE:
    197 			printf("security dongle (%d)", aa_args->handler_id);
    198 			break;
    199 #endif
    200 		case ADBADDR_MAP:
    201 			printf("mapped device (%d)", aa_args->handler_id);
    202 			rv = UNCONF;
    203 			break;
    204 		case ADBADDR_REL:
    205 			printf("relative positioning device (%d)",
    206 			    aa_args->handler_id);
    207 			rv = UNCONF;
    208 			break;
    209 #ifdef DIAGNOSTIC
    210 		case ADBADDR_ABS:
    211 			switch (aa_args->handler_id) {
    212 			case ADB_ARTPAD:
    213 				printf("WACOM ArtPad II");
    214 				break;
    215 			default:
    216 				printf("absolute positioning device (%d)",
    217 				    aa_args->handler_id);
    218 				break;
    219 			}
    220 			break;
    221 		case ADBADDR_DATATX:
    222 			printf("data transfer device (modem?) (%d)",
    223 			    aa_args->handler_id);
    224 			break;
    225 		case ADBADDR_MISC:
    226 			switch (aa_args->handler_id) {
    227 			case ADB_POWERKEY:
    228 				printf("Sophisticated Circuits PowerKey");
    229 				break;
    230 			default:
    231 				printf("misc. device (remote control?) (%d)",
    232 				    aa_args->handler_id);
    233 				break;
    234 			}
    235 			break;
    236 		default:
    237 			printf("unknown type device, (handler %d)",
    238 			    aa_args->handler_id);
    239 			break;
    240 #endif /* DIAGNOSTIC */
    241 		}
    242 	} else		/* a device matched and was configured */
    243                 printf(" addr %d: ", aa_args->adbaddr);
    244 
    245 	return rv;
    246 }
    247