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