Home | History | Annotate | Line # | Download | only in dev
adb.c revision 1.7.2.1
      1  1.7.2.1  nathanw /*	$NetBSD: adb.c,v 1.7.2.1 2001/04/09 01:53:48 nathanw Exp $	*/
      2      1.1   tsubai 
      3      1.1   tsubai /*-
      4      1.1   tsubai  * Copyright (C) 1994	Bradley A. Grantham
      5      1.1   tsubai  * All rights reserved.
      6      1.1   tsubai  *
      7      1.1   tsubai  * Redistribution and use in source and binary forms, with or without
      8      1.1   tsubai  * modification, are permitted provided that the following conditions
      9      1.1   tsubai  * are met:
     10      1.1   tsubai  * 1. Redistributions of source code must retain the above copyright
     11      1.1   tsubai  *    notice, this list of conditions and the following disclaimer.
     12      1.1   tsubai  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1   tsubai  *    notice, this list of conditions and the following disclaimer in the
     14      1.1   tsubai  *    documentation and/or other materials provided with the distribution.
     15      1.1   tsubai  * 3. All advertising materials mentioning features or use of this software
     16      1.1   tsubai  *    must display the following acknowledgement:
     17      1.1   tsubai  *	This product includes software developed by Bradley A. Grantham.
     18      1.1   tsubai  * 4. The name of the author may not be used to endorse or promote products
     19      1.1   tsubai  *    derived from this software without specific prior written permission.
     20      1.1   tsubai  *
     21      1.1   tsubai  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22      1.1   tsubai  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23      1.1   tsubai  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24      1.1   tsubai  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25      1.1   tsubai  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26      1.1   tsubai  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27      1.1   tsubai  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28      1.1   tsubai  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29      1.1   tsubai  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     30      1.1   tsubai  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31      1.1   tsubai  */
     32      1.1   tsubai 
     33      1.1   tsubai #include <sys/param.h>
     34      1.1   tsubai #include <sys/device.h>
     35      1.1   tsubai #include <sys/fcntl.h>
     36      1.1   tsubai #include <sys/poll.h>
     37      1.1   tsubai #include <sys/select.h>
     38      1.1   tsubai #include <sys/proc.h>
     39      1.1   tsubai #include <sys/signalvar.h>
     40      1.1   tsubai #include <sys/systm.h>
     41      1.1   tsubai 
     42      1.1   tsubai #include <machine/autoconf.h>
     43      1.1   tsubai 
     44      1.1   tsubai #include <macppc/dev/adbvar.h>
     45      1.3   tsubai #include <macppc/dev/akbdvar.h>
     46      1.1   tsubai #include <macppc/dev/viareg.h>
     47      1.1   tsubai 
     48      1.4   tsubai #include "aed.h"
     49      1.4   tsubai 
     50      1.1   tsubai /*
     51      1.1   tsubai  * Function declarations.
     52      1.1   tsubai  */
     53      1.1   tsubai static int	adbmatch __P((struct device *, struct cfdata *, void *));
     54      1.1   tsubai static void	adbattach __P((struct device *, struct device *, void *));
     55      1.3   tsubai static int	adbprint __P((void *, const char *));
     56      1.1   tsubai 
     57      1.1   tsubai /*
     58      1.1   tsubai  * Global variables.
     59      1.1   tsubai  */
     60      1.1   tsubai int     adb_polling = 0;	/* Are we polling?  (Debugger mode) */
     61      1.1   tsubai int     adb_initted = 0;	/* adb_init() has completed successfully */
     62      1.1   tsubai #ifdef ADB_DEBUG
     63      1.1   tsubai int	adb_debug = 0;		/* Output debugging messages */
     64      1.1   tsubai #endif /* ADB_DEBUG */
     65      1.1   tsubai 
     66      1.1   tsubai /*
     67      1.3   tsubai  * Driver definition.
     68      1.1   tsubai  */
     69      1.1   tsubai struct cfattach adb_ca = {
     70      1.1   tsubai 	sizeof(struct adb_softc), adbmatch, adbattach
     71      1.1   tsubai };
     72      1.1   tsubai 
     73      1.5   tsubai extern int adbHardware;
     74      1.5   tsubai 
     75      1.1   tsubai static int
     76      1.1   tsubai adbmatch(parent, cf, aux)
     77      1.1   tsubai 	struct device *parent;
     78      1.1   tsubai 	struct cfdata *cf;
     79      1.1   tsubai 	void *aux;
     80      1.1   tsubai {
     81      1.1   tsubai 	struct confargs *ca = aux;
     82      1.1   tsubai 
     83      1.1   tsubai 	if (ca->ca_nreg < 8)
     84      1.1   tsubai 		return 0;
     85      1.1   tsubai 
     86      1.1   tsubai 	if (ca->ca_nintr < 4)
     87      1.1   tsubai 		return 0;
     88      1.1   tsubai 
     89      1.5   tsubai 	if (strcmp(ca->ca_name, "via-cuda") == 0)
     90      1.5   tsubai 		return 1;
     91      1.5   tsubai 
     92      1.5   tsubai 	if (strcmp(ca->ca_name, "via-pmu") == 0)
     93      1.5   tsubai 		return 1;
     94      1.5   tsubai 
     95      1.5   tsubai 	return 0;
     96      1.1   tsubai }
     97      1.1   tsubai 
     98      1.1   tsubai static void
     99      1.1   tsubai adbattach(parent, self, aux)
    100      1.1   tsubai 	struct device *parent, *self;
    101      1.1   tsubai 	void   *aux;
    102      1.1   tsubai {
    103      1.1   tsubai 	struct adb_softc *sc = (struct adb_softc *)self;
    104      1.1   tsubai 	struct confargs *ca = aux;
    105  1.7.2.1  nathanw 	int irq = ca->ca_intr[0];
    106  1.7.2.1  nathanw 	int node;
    107      1.3   tsubai 	ADBDataBlock adbdata;
    108      1.3   tsubai 	struct adb_attach_args aa_args;
    109      1.3   tsubai 	int totaladbs;
    110      1.3   tsubai 	int adbindex, adbaddr;
    111      1.3   tsubai 
    112      1.1   tsubai 	extern adb_intr();
    113      1.3   tsubai 	extern volatile u_char *Via1Base;
    114      1.1   tsubai 
    115      1.1   tsubai 	ca->ca_reg[0] += ca->ca_baseaddr;
    116      1.1   tsubai 
    117      1.1   tsubai 	sc->sc_regbase = mapiodev(ca->ca_reg[0], ca->ca_reg[1]);
    118      1.1   tsubai 	Via1Base = sc->sc_regbase;
    119      1.1   tsubai 
    120      1.5   tsubai 	if (strcmp(ca->ca_name, "via-cuda") == 0)
    121      1.5   tsubai 		adbHardware = ADB_HW_CUDA;
    122      1.5   tsubai 	else if (strcmp(ca->ca_name, "via-pmu") == 0)
    123      1.5   tsubai 		adbHardware = ADB_HW_PB;
    124      1.5   tsubai 
    125  1.7.2.1  nathanw 	node = getnodebyname(OF_parent(ca->ca_node), "extint-gpio1");
    126  1.7.2.1  nathanw 	if (node)
    127  1.7.2.1  nathanw 		OF_getprop(node, "interrupts", &irq, 4);
    128  1.7.2.1  nathanw 
    129  1.7.2.1  nathanw 	printf(" irq %d: ", irq);
    130  1.7.2.1  nathanw 
    131      1.1   tsubai 	adb_polling = 1;
    132      1.3   tsubai 	ADBReInit();
    133      1.1   tsubai 
    134  1.7.2.1  nathanw 	intr_establish(irq, IST_LEVEL, IPL_HIGH, adb_intr, sc);
    135      1.1   tsubai 
    136      1.3   tsubai #ifdef ADB_DEBUG
    137      1.3   tsubai 	if (adb_debug)
    138      1.3   tsubai 		printf("adb: done with ADBReInit\n");
    139      1.1   tsubai #endif
    140      1.3   tsubai 	totaladbs = CountADBs();
    141      1.1   tsubai 
    142  1.7.2.1  nathanw 	printf("%d targets\n", totaladbs);
    143      1.1   tsubai 
    144      1.4   tsubai #if NAED > 0
    145      1.3   tsubai 	/* ADB event device for compatibility */
    146      1.3   tsubai 	aa_args.origaddr = 0;
    147      1.3   tsubai 	aa_args.adbaddr = 0;
    148      1.3   tsubai 	aa_args.handler_id = 0;
    149      1.3   tsubai 	(void)config_found(self, &aa_args, adbprint);
    150      1.4   tsubai #endif
    151      1.1   tsubai 
    152      1.3   tsubai 	/* for each ADB device */
    153      1.3   tsubai 	for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
    154      1.3   tsubai 		/* Get the ADB information */
    155      1.3   tsubai 		adbaddr = GetIndADB(&adbdata, adbindex);
    156      1.1   tsubai 
    157      1.3   tsubai 		aa_args.origaddr = adbdata.origADBAddr;
    158      1.3   tsubai 		aa_args.adbaddr = adbaddr;
    159      1.3   tsubai 		aa_args.handler_id = adbdata.devType;
    160      1.1   tsubai 
    161      1.3   tsubai 		(void)config_found(self, &aa_args, adbprint);
    162      1.1   tsubai 	}
    163      1.1   tsubai 
    164      1.5   tsubai 	if (adbHardware == ADB_HW_CUDA)
    165      1.5   tsubai 		adb_cuda_autopoll();
    166      1.3   tsubai 	adb_polling = 0;
    167      1.1   tsubai }
    168      1.1   tsubai 
    169      1.3   tsubai int
    170      1.3   tsubai adbprint(args, name)
    171      1.7   tsubai 	void *args;
    172      1.7   tsubai 	const char *name;
    173      1.3   tsubai {
    174      1.3   tsubai 	struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
    175      1.3   tsubai 	int rv = UNCONF;
    176      1.3   tsubai 
    177      1.3   tsubai 	if (name) {	/* no configured device matched */
    178      1.3   tsubai 		rv = UNSUPP; /* most ADB device types are unsupported */
    179      1.3   tsubai 
    180      1.3   tsubai 		/* print out what kind of ADB device we have found */
    181      1.7   tsubai 		printf("%s addr %d: ", name, aa_args->adbaddr);
    182      1.3   tsubai 		switch(aa_args->origaddr) {
    183      1.3   tsubai #ifdef DIAGNOSTIC
    184      1.3   tsubai 		case 0:
    185      1.3   tsubai 			printf("ADB event device");
    186      1.3   tsubai 			rv = UNCONF;
    187      1.3   tsubai 			break;
    188      1.3   tsubai 		case ADBADDR_SECURE:
    189      1.3   tsubai 			printf("security dongle (%d)", aa_args->handler_id);
    190      1.3   tsubai 			break;
    191      1.1   tsubai #endif
    192      1.3   tsubai 		case ADBADDR_MAP:
    193      1.3   tsubai 			printf("mapped device (%d)", aa_args->handler_id);
    194      1.3   tsubai 			rv = UNCONF;
    195      1.3   tsubai 			break;
    196      1.3   tsubai 		case ADBADDR_REL:
    197      1.3   tsubai 			printf("relative positioning device (%d)",
    198      1.3   tsubai 			    aa_args->handler_id);
    199      1.3   tsubai 			rv = UNCONF;
    200      1.3   tsubai 			break;
    201      1.3   tsubai #ifdef DIAGNOSTIC
    202      1.3   tsubai 		case ADBADDR_ABS:
    203      1.3   tsubai 			switch (aa_args->handler_id) {
    204      1.3   tsubai 			case ADB_ARTPAD:
    205      1.3   tsubai 				printf("WACOM ArtPad II");
    206      1.3   tsubai 				break;
    207      1.3   tsubai 			default:
    208      1.3   tsubai 				printf("absolute positioning device (%d)",
    209      1.3   tsubai 				    aa_args->handler_id);
    210      1.3   tsubai 				break;
    211      1.3   tsubai 			}
    212      1.3   tsubai 			break;
    213      1.3   tsubai 		case ADBADDR_DATATX:
    214      1.3   tsubai 			printf("data transfer device (modem?) (%d)",
    215      1.3   tsubai 			    aa_args->handler_id);
    216      1.1   tsubai 			break;
    217      1.3   tsubai 		case ADBADDR_MISC:
    218      1.3   tsubai 			switch (aa_args->handler_id) {
    219      1.3   tsubai 			case ADB_POWERKEY:
    220      1.3   tsubai 				printf("Sophisticated Circuits PowerKey");
    221      1.3   tsubai 				break;
    222      1.3   tsubai 			default:
    223      1.3   tsubai 				printf("misc. device (remote control?) (%d)",
    224      1.3   tsubai 				    aa_args->handler_id);
    225      1.3   tsubai 				break;
    226      1.3   tsubai 			}
    227      1.1   tsubai 			break;
    228      1.1   tsubai 		default:
    229      1.3   tsubai 			printf("unknown type device, (handler %d)",
    230      1.3   tsubai 			    aa_args->handler_id);
    231      1.1   tsubai 			break;
    232      1.3   tsubai #endif /* DIAGNOSTIC */
    233      1.1   tsubai 		}
    234      1.3   tsubai 	} else		/* a device matched and was configured */
    235      1.7   tsubai                 printf(" addr %d: ", aa_args->adbaddr);
    236      1.1   tsubai 
    237      1.7   tsubai 	return rv;
    238      1.1   tsubai }
    239