1 /* $NetBSD: dnkbd.c,v 1.12 2008/04/28 20:23:19 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Michael Smith and Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * Apollo Domain keyboard routines for the standalone ITE. 34 */ 35 36 #if defined(ITECONSOLE) && defined(DOMAIN_KEYBOARD) 37 38 #include <sys/param.h> 39 40 #include <hp300/dev/frodoreg.h> /* for apci offsets */ 41 #include <hp300/dev/intioreg.h> /* for frodo offsets */ 42 43 #include <hp300/stand/common/dcareg.h> /* for the register bit definitions */ 44 #include <hp300/stand/common/apcireg.h> /* for the apci registers */ 45 #include <hp300/stand/common/samachdep.h> 46 #include <hp300/stand/common/kbdvar.h> 47 48 #ifndef SMALL 49 50 /* 51 * The Apollo keyboard is used in `cooked' mode as configured by the 52 * firmware; only one table is required. 53 * 54 * Note that if an entry in this table is set to 0, the key is passed 55 * through untranslated. If the entry is 0xff, the key is ignored. 56 */ 57 u_char dnkbd_keymap[] = { 58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 07 */ 59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0f */ 60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 17 */ 61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1f */ 62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 27 */ 63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2f */ 64 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 37 */ 65 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3f */ 66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 47 */ 67 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4f */ 68 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 57 */ 69 0x00, 0x00, 0x00, '{', 0x00, '}', 0x00, 0x00, /* 5f */ 70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 67 */ 71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 6f */ 72 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 77 */ 73 0x00, 0x00, 0x00, '[', 0x00, ']', 0x00, 0x00, /* 7f */ 74 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 87 */ 75 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 8f */ 76 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 97 */ 77 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 9f */ 78 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* a7 */ 79 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* af */ 80 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* b7 */ 81 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* bf */ 82 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* c7 */ 83 '\\', '|', 0x09, 0x0a, '/', 0xff, 0xff, 0xff, /* cf */ 84 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* d7 */ 85 0xff, 0xff, 0xff, 0xff, '?', 0xff, 0x08, 0xff, /* df */ 86 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* e7 */ 87 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* ef */ 88 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* f7 */ 89 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* ff */ 90 }; 91 92 int dnkbd_ignore; /* for ignoring mouse packets */ 93 94 int 95 dnkbd_getc(void) 96 { 97 struct apciregs *apci = 98 (struct apciregs *)IIOV(FRODO_BASE + FRODO_APCI_OFFSET(0)); 99 int c; 100 101 /* default to `no key' */ 102 c = 0; 103 104 /* Is data in the UART? */ 105 if (apci->ap_lsr & LSR_RXRDY) { 106 /* Get the character. */ 107 c = apci->ap_data; 108 109 /* Ignoring mouse? */ 110 if (dnkbd_ignore) { 111 dnkbd_ignore--; 112 return 0; 113 } 114 115 /* Is this the start of a mouse packet? */ 116 if (c == 0xdf) { 117 dnkbd_ignore = 3; /* 3 bytes of junk */ 118 return 0; 119 } 120 121 /* It's a keyboard event. */ 122 switch (dnkbd_keymap[c]) { 123 case 0x00: 124 /* passthrough */ 125 break; 126 127 case 0xff: 128 /* ignore */ 129 c = 0; 130 break; 131 132 default: 133 c = dnkbd_keymap[c]; 134 break; 135 } 136 } 137 138 return c; 139 } 140 #endif /* SMALL */ 141 142 void 143 dnkbd_nmi(void) 144 { 145 146 /* 147 * XXX Should we do anything? Can we even generate one? 148 */ 149 } 150 151 int 152 dnkbd_init(void) 153 { 154 155 /* 156 * 400, 425, and 433 models can have a Domain keyboard. 157 */ 158 switch (machineid) { 159 case HP_400: 160 case HP_425: 161 case HP_433: 162 break; 163 default: 164 return 0; 165 } 166 167 /* 168 * Look for a Frodo utility chip. If we find one, assume there 169 * is a Domain keyboard attached. 170 */ 171 if (badaddr((void *)IIOV(FRODO_BASE + FRODO_APCI_OFFSET(0)))) 172 return 0; 173 174 /* 175 * XXX Any other initialization? This appears to work ok. 176 */ 177 return 1; 178 } 179 #endif /* ITECONSOLE && DOMAIN_KEYBOARD */ 180