NetBSD/sys/arch/mac68k/dev/adbsys.c

305 lines
8.2 KiB
C
Raw Normal View History

/* $NetBSD: adbsys.c,v 1.25 1997/04/08 03:19:05 scottr Exp $ */
1994-10-26 11:45:48 +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
* notice, this list of conditions and the following disclaimer in the
* 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.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <machine/cpu.h>
1996-03-29 05:06:04 +03:00
#include <machine/viareg.h>
1995-04-21 06:47:35 +04:00
#include <arch/mac68k/mac68k/macrom.h>
#include "adbvar.h"
extern struct mac68k_machine_S mac68k_machine;
1995-04-21 06:47:35 +04:00
/* from adb.c */
void adb_processevent __P((adb_event_t * event));
extern void adb_jadbproc __P((void));
1995-04-21 06:47:35 +04:00
void
adb_complete(buffer, data_area, adb_command)
caddr_t buffer;
caddr_t data_area;
int adb_command;
{
1995-04-21 06:47:35 +04:00
adb_event_t event;
ADBDataBlock adbdata;
int adbaddr;
int error;
#ifdef MRG_DEBUG
register int i;
1996-10-13 07:21:13 +04:00
printf("adb: transaction completion\n");
#endif
1995-04-21 06:47:35 +04:00
adbaddr = (adb_command & 0xf0) >> 4;
error = GetADBInfo(&adbdata, adbaddr);
#ifdef MRG_DEBUG
1996-10-13 07:21:13 +04:00
printf("adb: GetADBInfo returned %d\n", error);
#endif
event.addr = adbaddr;
event.hand_id = adbdata.devType;
event.def_addr = adbdata.origADBAddr;
event.byte_count = buffer[0];
memcpy(event.bytes, buffer + 1, event.byte_count);
#ifdef MRG_DEBUG
1996-10-13 07:21:13 +04:00
printf("adb: from %d at %d (org %d) %d:", event.addr,
event.hand_id, event.def_addr, buffer[0]);
1995-04-21 06:47:35 +04:00
for (i = 1; i <= buffer[0]; i++)
1996-10-13 07:21:13 +04:00
printf(" %x", buffer[i]);
printf("\n");
#endif
microtime(&event.timestamp);
adb_processevent(&event);
}
static volatile int extdms_done;
/*
* initialize extended mouse - probes devices as
* described in _Inside Macintosh, Devices_.
*/
void
extdms_init(totaladbs)
int totaladbs;
{
ADBDataBlock adbdata;
int adbindex, adbaddr;
short cmd;
char buffer[9];
for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
/* Get the ADB information */
adbaddr = GetIndADB(&adbdata, adbindex);
if (adbdata.origADBAddr == ADBADDR_MS &&
(adbdata.devType == ADBMS_USPEED)) {
/* Found MicroSpeed Mouse Deluxe Mac */
1996-05-08 17:36:41 +04:00
cmd = ((adbaddr<<4)&0xF0)|0x9; /* listen 1 */
/*
* To setup the MicroSpeed, it appears that we can
* send the following command to the mouse and then
* expect data back in the form:
* buffer[0] = 4 (bytes)
* buffer[1], buffer[2] as std. mouse
* buffer[3] = buffer[4] = 0xff when no buttons
* are down. When button N down, bit N is clear.
* buffer[4]'s locking mask enables a
* click to toggle the button down state--sort of
* like the "Easy Access" shift/control/etc. keys.
* buffer[3]'s alternative speed mask enables using
* different speed when the corr. button is down
*/
buffer[0] = 4;
buffer[1] = 0x00; /* Alternative speed */
buffer[2] = 0x00; /* speed = maximum */
buffer[3] = 0x10; /* enable extended protocol,
* lower bits = alt. speed mask
* = 0000b
*/
buffer[4] = 0x07; /* Locking mask = 0000b,
* enable buttons = 0111b
*/
extdms_done = 0;
ADBOp((Ptr)buffer, (Ptr)extdms_complete,
(Ptr)&extdms_done, cmd);
while (!extdms_done)
/* busy wait until done */;
}
if (adbdata.origADBAddr == ADBADDR_MS &&
( adbdata.devType == ADBMS_100DPI
|| adbdata.devType == ADBMS_200DPI)) {
/* found a mouse */
cmd = ((adbaddr << 4) & 0xf0) | 0x3;
extdms_done = 0;
cmd = (cmd & 0xf3) | 0x0c; /* talk command */
ADBOp((Ptr)buffer, (Ptr)extdms_complete,
(Ptr)&extdms_done, cmd);
while (!extdms_done)
/* busy wait until done */;
buffer[2] = '\004'; /* make handler ID 4 */
extdms_done = 0;
cmd = (cmd & 0xf3) | 0x08; /* listen command */
ADBOp((Ptr)buffer, (Ptr)extdms_complete,
(Ptr)&extdms_done, cmd);
while (!extdms_done)
/* busy wait until done */;
}
}
}
1995-04-21 06:47:35 +04:00
void
adb_init()
{
ADBDataBlock adbdata;
ADBSetInfoBlock adbinfo;
1995-04-21 06:47:35 +04:00
int totaladbs;
int adbindex, adbaddr;
int error;
char buffer[9];
if ((mac68k_machine.serial_console & 0x03)) {
1996-10-13 07:21:13 +04:00
printf("adb: using serial console\n");
return;
}
#ifdef MRG_ADB
1995-04-21 06:47:35 +04:00
if (!mrg_romready()) {
1996-10-13 07:21:13 +04:00
printf("adb: no ROM ADB driver in this kernel for this machine\n");
return;
}
1996-10-13 07:21:13 +04:00
printf("adb: bus subsystem\n");
#ifdef MRG_DEBUG
1996-10-13 07:21:13 +04:00
printf("adb: call mrg_initadbintr\n");
#endif
mrg_initadbintr(); /* Mac ROM Glue okay to do ROM intr */
#ifdef MRG_DEBUG
1996-10-13 07:21:13 +04:00
printf("adb: returned from mrg_initadbintr\n");
#endif
1995-04-21 06:47:35 +04:00
/* ADBReInit pre/post-processing */
JADBProc = adb_jadbproc;
1995-04-21 06:47:35 +04:00
/* Initialize ADB */
#ifdef MRG_DEBUG
1996-10-13 07:21:13 +04:00
printf("adb: calling ADBAlternateInit.\n");
#endif
ADBAlternateInit();
#else
ADBReInit();
#endif /* MRG_ADB */
#ifdef MRG_DEBUG
1996-10-13 07:21:13 +04:00
printf("adb: done with ADBReInit\n");
#endif
totaladbs = CountADBs();
extdms_init(totaladbs);
1995-04-21 06:47:35 +04:00
/* for each ADB device */
for (adbindex = 1; adbindex <= totaladbs; adbindex++) {
/* Get the ADB information */
adbaddr = GetIndADB(&adbdata, adbindex);
1995-04-21 06:47:35 +04:00
/* Print out the glory */
1996-10-13 07:21:13 +04:00
printf("adb: ");
1995-04-21 06:47:35 +04:00
switch (adbdata.origADBAddr) {
case ADBADDR_MAP:
1995-04-21 06:47:35 +04:00
switch (adbdata.devType) {
case ADB_STDKBD:
1996-10-13 07:21:13 +04:00
printf("keyboard");
1995-04-21 06:47:35 +04:00
break;
case ADB_EXTKBD:
1996-10-13 07:21:13 +04:00
printf("extended keyboard");
1995-04-21 06:47:35 +04:00
break;
case ADB_PBKBD:
1996-10-13 07:21:13 +04:00
printf("PowerBook keyboard");
1995-04-21 06:47:35 +04:00
break;
default:
1996-10-13 07:21:13 +04:00
printf("mapped device (%d)",
1995-04-21 06:47:35 +04:00
adbdata.devType);
break;
1995-04-21 06:47:35 +04:00
}
break;
case ADBADDR_REL:
extdms_done = 0;
/* talk register 3 */
ADBOp((Ptr)buffer, (Ptr)extdms_complete,
(Ptr)&extdms_done, (adbaddr << 4) | 0xf);
while (!extdms_done)
/* busy-wait until done */;
switch (buffer[2]) {
case ADBMS_100DPI:
1996-10-13 07:21:13 +04:00
printf("100 dpi mouse");
break;
case ADBMS_200DPI:
1996-10-13 07:21:13 +04:00
printf("200 dpi mouse");
break;
case ADBMS_USPEED:
1996-10-13 07:21:13 +04:00
printf("MicroSpeed mouse, default parameters");
break;
case ADBMS_EXTENDED:
extdms_done = 0;
/* talk register 1 */
ADBOp((Ptr)buffer, (Ptr)extdms_complete,
(Ptr)&extdms_done,
(adbaddr << 4) | 0xd);
while (!extdms_done)
/* busy-wait until done */;
1996-10-13 07:21:13 +04:00
printf("extended mouse "
"<%c%c%c%c> %d-button %d dpi ",
buffer[1], buffer[2],
buffer[3], buffer[4],
(int)buffer[8],
(int)*(short *)&buffer[5]);
if (buffer[7] == 1)
1996-10-13 07:21:13 +04:00
printf("mouse");
else if (buffer[7] == 2)
1996-10-13 07:21:13 +04:00
printf("trackball");
else
1996-10-13 07:21:13 +04:00
printf("unknown device");
break;
default:
1996-10-13 07:21:13 +04:00
printf("relative positioning device (mouse?) (%d)", adbdata.devType);
break;
1995-04-21 06:47:35 +04:00
}
break;
case ADBADDR_ABS:
1996-10-13 07:21:13 +04:00
printf("absolute positioning device (tablet?) (%d)", adbdata.devType);
1995-04-21 06:47:35 +04:00
break;
default:
1996-10-13 07:21:13 +04:00
printf("unknown type device, (def %d, handler %d)", adbdata.origADBAddr,
1995-04-21 06:47:35 +04:00
adbdata.devType);
break;
}
1996-10-13 07:21:13 +04:00
printf(" at %d\n", adbaddr);
1995-04-21 06:47:35 +04:00
/* Set completion routine to be MacBSD's */
1995-06-25 06:46:46 +04:00
adbinfo.siServiceRtPtr = (Ptr) adb_asmcomplete;
adbinfo.siDataAreaAddr = NULL;
error = SetADBInfo(&adbinfo, adbaddr);
#ifdef MRG_DEBUG
1996-10-13 07:21:13 +04:00
printf("returned %d from SetADBInfo\n", error);
#endif
}
}