1 /* $NetBSD: dnkbd.c,v 1.13 2014/04/22 15:49:14 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 *
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
dnkbd_getc(void)95 dnkbd_getc(void)
96 {
97 struct apciregs *apci =
98 (struct apciregs *)IIOV(INTIOBASE + FRODO_BASE +
99 FRODO_APCI_OFFSET(0));
100 int c;
101
102 /* default to `no key' */
103 c = 0;
104
105 /* Is data in the UART? */
106 if (apci->ap_lsr & LSR_RXRDY) {
107 /* Get the character. */
108 c = apci->ap_data;
109
110 /* Ignoring mouse? */
111 if (dnkbd_ignore) {
112 dnkbd_ignore--;
113 return 0;
114 }
115
116 /* Is this the start of a mouse packet? */
117 if (c == 0xdf) {
118 dnkbd_ignore = 3; /* 3 bytes of junk */
119 return 0;
120 }
121
122 /* It's a keyboard event. */
123 switch (dnkbd_keymap[c]) {
124 case 0x00:
125 /* passthrough */
126 break;
127
128 case 0xff:
129 /* ignore */
130 c = 0;
131 break;
132
133 default:
134 c = dnkbd_keymap[c];
135 break;
136 }
137 }
138
139 return c;
140 }
141 #endif /* SMALL */
142
143 void
dnkbd_nmi(void)144 dnkbd_nmi(void)
145 {
146
147 /*
148 * XXX Should we do anything? Can we even generate one?
149 */
150 }
151
152 int
dnkbd_init(void)153 dnkbd_init(void)
154 {
155
156 /*
157 * 400, 425, and 433 models can have a Domain keyboard.
158 */
159 switch (machineid) {
160 case HP_400:
161 case HP_425:
162 case HP_433:
163 break;
164 default:
165 return 0;
166 }
167
168 /*
169 * Look for a Frodo utility chip. If we find one, assume there
170 * is a Domain keyboard attached.
171 */
172 if (badaddr((void *)IIOV(INTIOBASE + FRODO_BASE +
173 FRODO_APCI_OFFSET(0))))
174 return 0;
175
176 /*
177 * XXX Any other initialization? This appears to work ok.
178 */
179 return 1;
180 }
181 #endif /* ITECONSOLE && DOMAIN_KEYBOARD */
182