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