Subject: RE: Apollo keyboard support (SYS_UBOOT)
To: mike smith <miff@spam.frisbee.net.au>
From: Lyann <Omnipotent-1@msn.com>
List: port-hp300
Date: 04/13/1997 22:53:53
take me off your mailing list

----------
From: 	port-hp300-owner@NetBSD.ORG on behalf of mike smith
Sent: 	Sunday, April 13, 1997 12:35 AM
To: 	port-hp300@netbsd.org
Subject: 	Apollo keyboard support (SYS_UBOOT)

This is a multi-part message in MIME format.

--------------5648FDB4373BFA8763AA6AC6
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Here is a diff and a new file (hp300/dev/apcireg.h) to provide
support for Apollo keyboards on hp4xx machines in SYS_UBOOT.

This is primarily for Jason's review, but if you have such
a combination I would appreciate any feedback you may have.

Support for these keyboards as the console keyboard is
proceeding; I haven't had any feedback about wscons, so I
will be integrating the Apollo keyboard support into ite.

--
Mike Smith  *BSD hack  Unix hardware collector
The question "why are the fundamental laws of nature mathematical"
invites the trivial response "because we define as fundamental those
laws which are mathematical".  Paul Davies, _The_Mind_of_God_

--------------5648FDB4373BFA8763AA6AC6
Content-Type: text/plain; charset=us-ascii; name="stand_apkbd.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="stand_apkbd.diff"

diff -ur /work/sys/arch/hp300/stand/common/hil.c stand/common/hil.c
--- /work/sys/arch/hp300/stand/common/hil.c	Fri Mar 21 20:55:00 1997
+++ stand/common/hil.c	Sun Apr 13 14:27:49 1997
@@ -57,6 +57,9 @@
 
 #include <hp300/stand/common/samachdep.h>
 
+#include <hp300/dev/dcareg.h>		/* for the register bit defines */
+#include <hp300/dev/apcireg.h>		/* for apci registers */
+
 #ifndef SMALL
 
 /*
@@ -200,14 +203,84 @@
 char	*kbd_shiftmap = us_shiftmap;
 char	*kbd_ctrlmap = us_ctrlmap;
 
+/*
+ * The Apollo keyboard is used in 'cooked' mode as configured by the 
+ * firmware; only one table is required.
+ *
+ * Note that if an entry in this table is set to 0, the key is passed
+ * through untranslated.  If the entry is 0xff, the key is ignored.
+ */
+
+static u_char ap_keymap[] = {
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 07 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 0f */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 17 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 1f */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 27 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 2f */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 37 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 3f */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 47 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 4f */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 57 */
+	0x00, 0x00, 0x00, '{',  0x00, '}',  0x00, 0x00,	/* 5f */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 67 */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 6f */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* 77 */
+	0x00, 0x00, 0x00, '[',  0x00, ']',  0x00, 0x00,	/* 7f */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 87 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 8f */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 97 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 9f */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* a7 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* af */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* b7 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* bf */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* c7 */
+	'\\', '|',  0x09, 0x0a, '/',  0xff, 0xff, 0xff,	/* cf */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* d7 */
+	0xff, 0xff, 0xff, 0xff, '?',  0xff, 0x08, 0xff,	/* df */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* e7 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* ef */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* f7 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* ff */
+};
+
+static int ap_ignore;			/* for ignoring mouse packets */
+static int ap_present;			/* is an Apollo keyboard present? */
+
 kbdgetc()
 {
 	register int status, c;
 	register struct hil_dev *hiladdr = HILADDR;
+	/* XXX should have a name for this address somewhere */
+	struct apciregs	*apci = (struct apciregs *)0x41c000;
 
 	status = hiladdr->hil_stat;
-	if ((status & HIL_DATA_RDY) == 0)
+	if ((status & HIL_DATA_RDY) == 0) {		/* no HIL data */
+	        if (ap_present) {			/* Apollo keyboard? */
+		        if (apci->ap_lsr & LSR_RXRDY) {	/* data in the UART? */
+		                c = apci->ap_data;	/* get the data */
+				if (ap_ignore) {	/* ignoring mouse? */
+				        ap_ignore--;	/* discard */
+					return(0);
+				}
+				if (c == 0xdf) {	/* start of mouse */
+				        ap_ignore = 3;	/* 3 bytes of junk */
+					return(0);
+				}
+				switch (ap_keymap[c]) {
+				case 0x00:		/* passthrough */
+			                return(c);
+				case 0xff:		/* ignore */
+			                return(0);
+				default:		/* translate */
+			               return(ap_keymap[c]);
+				}
+			}
+		}
 		return(0);
+	}
 	c = hiladdr->hil_data;
 	switch ((status>>KBD_SSHIFT) & KBD_SMASK) {
 	case KBD_SHIFT:
@@ -261,5 +334,13 @@
 		}
 	HILWAIT(hiladdr);
 	hiladdr->hil_cmd = HIL_INTON;
+
+	/* setup for Apollo keyboard */
+	if (!badaddr(0x41c000)) {
+	    ap_ignore = 0;
+	    ap_present = 1;	/* looks like there's an apollo keyboard */
+	    /* XXX do init?  talk to it? seems OK like this */
+	}
 }
 #endif
+

--------------5648FDB4373BFA8763AA6AC6
Content-Type: text/plain; charset=us-ascii; name="apcireg.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="apcireg.h"

/*	$NetBSD$ */

/*
 * Copyright (c) 1997 Michael Smith.  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.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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 <hp300/dev/iotypes.h>

struct apciregs
{
    vu_char	ap_data;
    u_char	pad0[3];
    vu_char	ap_ier;
    u_char	pad1[3];
    vu_char	ap_iir;
#define ap_fifo ap_iir
    u_char	pad2[3];
    vu_char	ap_cfcr;
    u_char	pad3[3];
    vu_char	ap_mcr;
    u_char	pad4[3];
    vu_char	ap_lsr;
    u_char	pad5[3];
    vu_char	ap_msr;
    u_char	pad6[3];
    vu_char	ap_scratch;
};

/* max number of apci ports */
#define APCI_MAXPORT	4

/* frodo interrupt number of lowest apci port */
#define APCI_INTR0	12

/*
 * baudrate divisor calculations.
 *
 * The input clock frequency appears to be 8.0064MHz, giving a scale
 * factor of 500400.  (Using exactly 8MHz gives framing errors with
 * the Apollo keyboard.)
 */
#define APCIBRD(x)	(500000 / (x))



--------------5648FDB4373BFA8763AA6AC6--