1999-02-11 09:41:07 +03:00
|
|
|
/* $NetBSD: adb.c,v 1.27 1999/02/11 06:41:07 ender Exp $ */
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
/*
|
1994-12-04 02:33:55 +03:00
|
|
|
* Copyright (C) 1994 Bradley A. Grantham
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
1998-10-23 05:16:22 +04:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
1994-12-04 02:33:55 +03:00
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bradley A. Grantham.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1998-02-21 03:37:07 +03:00
|
|
|
#include "opt_adb.h"
|
|
|
|
|
1994-12-04 02:33:55 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/fcntl.h>
|
1996-09-14 10:01:12 +04:00
|
|
|
#include <sys/poll.h>
|
1994-12-04 02:33:55 +03:00
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/proc.h>
|
1996-05-05 10:15:56 +04:00
|
|
|
#include <sys/signalvar.h>
|
1994-12-04 02:33:55 +03:00
|
|
|
#include <sys/systm.h>
|
1995-04-21 06:47:35 +04:00
|
|
|
|
1996-05-05 10:15:56 +04:00
|
|
|
#include <machine/autoconf.h>
|
1998-10-23 05:16:22 +04:00
|
|
|
#include <machine/cpu.h>
|
1995-04-21 06:47:35 +04:00
|
|
|
|
1997-08-12 02:53:26 +04:00
|
|
|
#include <mac68k/mac68k/macrom.h>
|
|
|
|
#include <mac68k/dev/adbvar.h>
|
|
|
|
#include <mac68k/dev/itevar.h>
|
1998-10-23 05:16:22 +04:00
|
|
|
#include <mac68k/dev/kbdvar.h>
|
|
|
|
|
|
|
|
#include "aed.h" /* ADB Event Device for compatibility */
|
1994-12-04 02:33:55 +03:00
|
|
|
|
|
|
|
/*
|
1995-04-21 06:47:35 +04:00
|
|
|
* Function declarations.
|
1994-12-04 02:33:55 +03:00
|
|
|
*/
|
1996-12-16 19:17:02 +03:00
|
|
|
static int adbmatch __P((struct device *, struct cfdata *, void *));
|
1996-05-05 10:15:56 +04:00
|
|
|
static void adbattach __P((struct device *, struct device *, void *));
|
1998-10-23 05:16:22 +04:00
|
|
|
static int adbprint __P((void *, const char *));
|
|
|
|
|
|
|
|
extern void adb_jadbproc __P((void));
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/*
|
|
|
|
* Global variables.
|
|
|
|
*/
|
1998-10-23 05:16:22 +04:00
|
|
|
int adb_initted = 0; /* adb_init() has completed successfully */
|
1998-02-21 03:37:07 +03:00
|
|
|
#ifdef ADB_DEBUG
|
|
|
|
int adb_debug = 0; /* Output debugging messages */
|
|
|
|
#endif /* ADB_DEBUG */
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
extern struct mac68k_machine_S mac68k_machine;
|
|
|
|
extern int adbHardware;
|
|
|
|
extern char *adbHardwareDescr[];
|
|
|
|
|
1994-12-04 02:33:55 +03:00
|
|
|
/*
|
1998-10-23 05:16:22 +04:00
|
|
|
* Driver definition.
|
1994-12-04 02:33:55 +03:00
|
|
|
*/
|
1996-03-17 04:26:49 +03:00
|
|
|
struct cfattach adb_ca = {
|
1996-05-05 10:15:56 +04:00
|
|
|
sizeof(struct device), adbmatch, adbattach
|
1996-03-17 04:26:49 +03:00
|
|
|
};
|
|
|
|
|
1996-05-05 10:15:56 +04:00
|
|
|
static int
|
1996-12-16 19:17:02 +03:00
|
|
|
adbmatch(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1996-05-05 10:15:56 +04:00
|
|
|
{
|
1997-11-26 09:28:50 +03:00
|
|
|
static int adb_matched = 0;
|
|
|
|
|
|
|
|
/* Allow only one instance. */
|
|
|
|
if (adb_matched)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
adb_matched = 1;
|
|
|
|
return (1);
|
1996-05-05 10:15:56 +04:00
|
|
|
}
|
|
|
|
|
1994-12-04 02:33:55 +03:00
|
|
|
static void
|
|
|
|
adbattach(parent, dev, aux)
|
1995-04-21 06:47:35 +04:00
|
|
|
struct device *parent, *dev;
|
1998-02-23 06:11:26 +03:00
|
|
|
void *aux;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
1998-10-23 05:16:22 +04:00
|
|
|
ADBDataBlock adbdata;
|
|
|
|
struct adb_attach_args aa_args;
|
|
|
|
int totaladbs;
|
|
|
|
int adbindex, adbaddr;
|
|
|
|
|
|
|
|
#ifdef MRG_ADB
|
|
|
|
/*
|
|
|
|
* Even if serial console only, some models require the
|
|
|
|
* ADB in order to get the date/time and do soft power.
|
|
|
|
*/
|
|
|
|
if ((mac68k_machine.serial_console & 0x03)) {
|
|
|
|
printf(": using serial console");
|
|
|
|
return;
|
|
|
|
}
|
1996-09-14 10:01:12 +04:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
if (!mrg_romready()) {
|
|
|
|
printf(": no ROM ADB driver in this kernel for this machine");
|
|
|
|
return;
|
|
|
|
}
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
#ifdef ADB_DEBUG
|
|
|
|
if (adb_debug)
|
|
|
|
printf("adb: call mrg_initadbintr\n");
|
1996-09-14 10:01:12 +04:00
|
|
|
#endif
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
mrg_initadbintr(); /* Mac ROM Glue okay to do ROM intr */
|
|
|
|
#ifdef ADB_DEBUG
|
|
|
|
if (adb_debug)
|
|
|
|
printf("adb: returned from mrg_initadbintr\n");
|
|
|
|
#endif
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
/* ADBReInit pre/post-processing */
|
|
|
|
JADBProc = adb_jadbproc;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
/* Initialize ADB */
|
|
|
|
#ifdef ADB_DEBUG
|
|
|
|
if (adb_debug)
|
|
|
|
printf("adb: calling ADBAlternateInit.\n");
|
|
|
|
#endif
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
printf(" (mrg) ");
|
1998-10-26 10:09:37 +03:00
|
|
|
ADBAlternateInit();
|
1998-10-23 05:16:22 +04:00
|
|
|
#else
|
|
|
|
ADBReInit();
|
|
|
|
printf(" (direct, %s)", adbHardwareDescr[adbHardware]);
|
|
|
|
#endif /* MRG_ADB */
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
#ifdef ADB_DEBUG
|
|
|
|
if (adb_debug)
|
|
|
|
printf("adb: done with ADBReInit\n");
|
|
|
|
#endif
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
totaladbs = CountADBs();
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
printf(": %d targets\n", totaladbs);
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
#if NAED > 0
|
|
|
|
/* ADB event device for compatibility */
|
|
|
|
aa_args.origaddr = 0;
|
|
|
|
aa_args.adbaddr = 0;
|
|
|
|
aa_args.handler_id = 0;
|
|
|
|
(void)config_found(dev, &aa_args, adbprint);
|
|
|
|
#endif
|
1995-04-21 06:47:35 +04:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
/* for each ADB device */
|
|
|
|
for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
|
|
|
|
/* Get the ADB information */
|
|
|
|
adbaddr = GetIndADB(&adbdata, adbindex);
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1999-02-11 09:41:07 +03:00
|
|
|
aa_args.origaddr = (int)(adbdata.origADBAddr);
|
1998-10-23 05:16:22 +04:00
|
|
|
aa_args.adbaddr = adbaddr;
|
1999-02-11 09:41:07 +03:00
|
|
|
aa_args.handler_id = (int)(adbdata.devType);
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
(void)config_found(dev, &aa_args, adbprint);
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
adbprint(args, name)
|
|
|
|
void *args;
|
|
|
|
const char *name;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
1998-10-23 05:16:22 +04:00
|
|
|
struct adb_attach_args *aa_args = (struct adb_attach_args *)args;
|
|
|
|
int rv = UNCONF;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
if (name) { /* no configured device matched */
|
|
|
|
rv = UNSUPP; /* most ADB device types are unsupported */
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
/* print out what kind of ADB device we have found */
|
|
|
|
printf("%s addr %d: ", name, aa_args->origaddr);
|
|
|
|
switch(aa_args->origaddr) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
case 0:
|
|
|
|
printf("ADB event device");
|
|
|
|
rv = UNCONF;
|
1997-06-16 10:35:26 +04:00
|
|
|
break;
|
1998-10-23 05:16:22 +04:00
|
|
|
case ADBADDR_SECURE:
|
|
|
|
printf("security dongle (%d)", aa_args->handler_id);
|
1996-05-05 18:33:55 +04:00
|
|
|
break;
|
1998-10-23 05:16:22 +04:00
|
|
|
#endif
|
|
|
|
case ADBADDR_MAP:
|
|
|
|
printf("mapped device (%d)", aa_args->handler_id);
|
|
|
|
rv = UNCONF;
|
|
|
|
break;
|
|
|
|
case ADBADDR_REL:
|
|
|
|
printf("relative positioning device (%d)",
|
|
|
|
aa_args->handler_id);
|
|
|
|
rv = UNCONF;
|
|
|
|
break;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
case ADBADDR_ABS:
|
|
|
|
switch (aa_args->handler_id) {
|
|
|
|
case ADB_ARTPAD:
|
|
|
|
printf("WACOM ArtPad II");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("absolute positioning device (%d)",
|
|
|
|
aa_args->handler_id);
|
|
|
|
break;
|
1996-05-05 18:33:55 +04:00
|
|
|
}
|
|
|
|
break;
|
1998-10-23 05:16:22 +04:00
|
|
|
case ADBADDR_DATATX:
|
|
|
|
printf("data transfer device (modem?) (%d)",
|
|
|
|
aa_args->handler_id);
|
|
|
|
break;
|
|
|
|
case ADBADDR_MISC:
|
|
|
|
switch (aa_args->handler_id) {
|
|
|
|
case ADB_POWERKEY:
|
|
|
|
printf("Sophisticated Circuits PowerKey");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("misc. device (remote control?) (%d)",
|
|
|
|
aa_args->handler_id);
|
|
|
|
break;
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
1998-10-23 05:16:22 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("unknown type device, (handler %d)",
|
|
|
|
aa_args->handler_id);
|
|
|
|
break;
|
|
|
|
#endif /* DIAGNOSTIC */
|
|
|
|
}
|
|
|
|
} else /* a device matched and was configured */
|
|
|
|
printf(" addr %d: ", aa_args->origaddr);
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1998-10-23 05:16:22 +04:00
|
|
|
return (rv);
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|