Home | History | Annotate | Line # | Download | only in dev
adb.c revision 1.27.2.3
      1 /*	$NetBSD: adb.c,v 1.27.2.3 1999/11/28 10:13:17 scottr 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 "opt_adb.h"
     34 
     35 #include <sys/param.h>
     36 #include <sys/device.h>
     37 #include <sys/fcntl.h>
     38 #include <sys/poll.h>
     39 #include <sys/select.h>
     40 #include <sys/proc.h>
     41 #include <sys/signalvar.h>
     42 #include <sys/systm.h>
     43 
     44 #include <machine/autoconf.h>
     45 #include <machine/cpu.h>
     46 
     47 #include <mac68k/mac68k/macrom.h>
     48 #include <mac68k/dev/adbvar.h>
     49 #include <mac68k/dev/itevar.h>
     50 #include <mac68k/dev/akbdvar.h>
     51 
     52 #include "aed.h"		/* ADB Event Device for compatibility */
     53 
     54 /*
     55  * Function declarations.
     56  */
     57 static int	adbmatch __P((struct device *, struct cfdata *, void *));
     58 static void	adbattach __P((struct device *, struct device *, void *));
     59 static int	adbprint __P((void *, const char *));
     60 void		adb_config_interrupts __P((struct device *));
     61 
     62 extern void	adb_jadbproc __P((void));
     63 
     64 /*
     65  * Global variables.
     66  */
     67 int	adb_polling = 0;	/* Are we polling?  (Debugger mode) */
     68 #ifdef ADB_DEBUG
     69 #if 1
     70 int	adb_debug = 0xff;
     71 #else
     72 int	adb_debug = 0;		/* Output debugging messages */
     73 #endif
     74 #endif /* ADB_DEBUG */
     75 
     76 extern struct	mac68k_machine_S mac68k_machine;
     77 extern int	adbHardware;
     78 extern char	*adbHardwareDescr[];
     79 
     80 /*
     81  * Driver definition.
     82  */
     83 struct cfattach adb_ca = {
     84 	sizeof(struct device), adbmatch, adbattach
     85 };
     86 
     87 static int
     88 adbmatch(parent, cf, aux)
     89 	struct device *parent;
     90 	struct cfdata *cf;
     91 	void *aux;
     92 {
     93 	static int adb_matched = 0;
     94 
     95 	/* Allow only one instance. */
     96 	if (adb_matched)
     97 		return (0);
     98 
     99 	adb_matched = 1;
    100 	return (1);
    101 }
    102 
    103 static void
    104 adbattach(parent, self, aux)
    105 	struct device *parent, *self;
    106 	void *aux;
    107 {
    108 	printf("\n");
    109 
    110 	/*
    111 	 * Defer configuration until interrupts are enabled.
    112 	 */
    113 	config_interrupts(self, adb_config_interrupts);
    114 }
    115 
    116 void
    117 adb_config_interrupts(self)
    118 	struct device *self;
    119 {
    120 	ADBDataBlock adbdata;
    121 	struct adb_attach_args aa_args;
    122 	int totaladbs;
    123 	int adbindex, adbaddr;
    124 
    125 	printf("%s", self->dv_xname);
    126 	adb_polling = 1;
    127 
    128 #ifdef MRG_ADB
    129 	/*
    130 	 * Even if serial console only, some models require the
    131 	 * ADB in order to get the date/time and do soft power.
    132 	 */
    133 	if ((mac68k_machine.serial_console & 0x03)) {
    134 		printf(": using serial console\n");
    135 		return;
    136 	}
    137 
    138 	if (!mrg_romready()) {
    139 		printf(": no ROM ADB driver in this kernel for this machine\n");
    140 		return;
    141 	}
    142 
    143 #ifdef ADB_DEBUG
    144 	if (adb_debug)
    145 		printf("adb: call mrg_initadbintr\n");
    146 #endif
    147 
    148 	mrg_initadbintr();	/* Mac ROM Glue okay to do ROM intr */
    149 #ifdef ADB_DEBUG
    150 	if (adb_debug)
    151 		printf("adb: returned from mrg_initadbintr\n");
    152 #endif
    153 
    154 	/* ADBReInit pre/post-processing */
    155 	JADBProc = adb_jadbproc;
    156 
    157 	/* Initialize ADB */
    158 #ifdef ADB_DEBUG
    159 	if (adb_debug)
    160 		printf("adb: calling ADBAlternateInit.\n");
    161 #endif
    162 
    163 	printf(" (mrg)");
    164 	ADBAlternateInit();
    165 #else
    166 	ADBReInit();
    167 	printf(" (direct, %s)", adbHardwareDescr[adbHardware]);
    168 #endif /* MRG_ADB */
    169 
    170 #ifdef ADB_DEBUG
    171 	if (adb_debug)
    172 		printf("adb: done with ADBReInit\n");
    173 #endif
    174 
    175 	totaladbs = CountADBs();
    176 
    177 	printf(": %d target%s\n", totaladbs, (totaladbs == 1) ? "" : "s");
    178 
    179 #if NAED > 0
    180 	/* ADB event device for compatibility */
    181 	aa_args.origaddr = 0;
    182 	aa_args.adbaddr = 0;
    183 	aa_args.handler_id = 0;
    184 	(void)config_found(self, &aa_args, adbprint);
    185 #endif
    186 
    187 	/* for each ADB device */
    188 	for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
    189 		/* Get the ADB information */
    190 		adbaddr = GetIndADB(&adbdata, adbindex);
    191 
    192 		aa_args.origaddr = (int)(adbdata.origADBAddr);
    193 		aa_args.adbaddr = adbaddr;
    194 		aa_args.handler_id = (int)(adbdata.devType);
    195 
    196 		(void)config_found(self, &aa_args, adbprint);
    197 	}
    198 	adb_polling = 0;
    199 }
    200 
    201 
    202 int
    203 adbprint(args, name)
    204 	void *args;
    205 	const char *name;
    206 {
    207 	struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
    208 	int rv = UNCONF;
    209 
    210 	if (name) {	/* no configured device matched */
    211 		rv = UNSUPP; /* most ADB device types are unsupported */
    212 
    213 		/* print out what kind of ADB device we have found */
    214 		printf("%s addr %d: ", name, aa_args->origaddr);
    215 		switch(aa_args->origaddr) {
    216 #ifdef DIAGNOSTIC
    217 		case 0:
    218 			printf("ADB event device");
    219 			rv = UNCONF;
    220 			break;
    221 		case ADBADDR_SECURE:
    222 			printf("security dongle (%d)", aa_args->handler_id);
    223 			break;
    224 #endif
    225 		case ADBADDR_MAP:
    226 			printf("mapped device (%d)", aa_args->handler_id);
    227 			rv = UNCONF;
    228 			break;
    229 		case ADBADDR_REL:
    230 			printf("relative positioning device (%d)",
    231 			    aa_args->handler_id);
    232 			rv = UNCONF;
    233 			break;
    234 #ifdef DIAGNOSTIC
    235 		case ADBADDR_ABS:
    236 			switch (aa_args->handler_id) {
    237 			case ADB_ARTPAD:
    238 				printf("WACOM ArtPad II");
    239 				break;
    240 			default:
    241 				printf("absolute positioning device (%d)",
    242 				    aa_args->handler_id);
    243 				break;
    244 			}
    245 			break;
    246 		case ADBADDR_DATATX:
    247 			printf("data transfer device (modem?) (%d)",
    248 			    aa_args->handler_id);
    249 			break;
    250 		case ADBADDR_MISC:
    251 			switch (aa_args->handler_id) {
    252 			case ADB_POWERKEY:
    253 				printf("Sophisticated Circuits PowerKey");
    254 				break;
    255 			default:
    256 				printf("misc. device (remote control?) (%d)",
    257 				    aa_args->handler_id);
    258 				break;
    259 			}
    260 			break;
    261 		default:
    262 			printf("unknown type device, (handler %d)",
    263 			    aa_args->handler_id);
    264 			break;
    265 #endif /* DIAGNOSTIC */
    266 		}
    267 	} else		/* a device matched and was configured */
    268 		printf(" addr %d: ", aa_args->origaddr);
    269 
    270 	return (rv);
    271 }
    272