cons_zskbd.c revision 1.1.18.2 1 1.1.18.2 yamt /* $NetBSD: cons_zskbd.c,v 1.1.18.2 2006/06/21 14:51:20 yamt Exp $ */
2 1.1.18.2 yamt
3 1.1.18.2 yamt /*-
4 1.1.18.2 yamt * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
5 1.1.18.2 yamt * All rights reserved.
6 1.1.18.2 yamt *
7 1.1.18.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.1.18.2 yamt * by UCHIYAMA Yasushi.
9 1.1.18.2 yamt *
10 1.1.18.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.1.18.2 yamt * modification, are permitted provided that the following conditions
12 1.1.18.2 yamt * are met:
13 1.1.18.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.1.18.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.1.18.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.18.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.1.18.2 yamt * documentation and/or other materials provided with the distribution.
18 1.1.18.2 yamt * 3. All advertising materials mentioning features or use of this software
19 1.1.18.2 yamt * must display the following acknowledgement:
20 1.1.18.2 yamt * This product includes software developed by the NetBSD
21 1.1.18.2 yamt * Foundation, Inc. and its contributors.
22 1.1.18.2 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.18.2 yamt * contributors may be used to endorse or promote products derived
24 1.1.18.2 yamt * from this software without specific prior written permission.
25 1.1.18.2 yamt *
26 1.1.18.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.18.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.18.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.18.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.18.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.18.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.18.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.18.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.18.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.18.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.18.2 yamt * POSSIBILITY OF SUCH DAMAGE.
37 1.1.18.2 yamt */
38 1.1.18.2 yamt
39 1.1.18.2 yamt #include <sys/param.h>
40 1.1.18.2 yamt #include <sys/systm.h>
41 1.1.18.2 yamt
42 1.1.18.2 yamt #include <lib/libsa/stand.h>
43 1.1.18.2 yamt #include <lib/libkern/libkern.h>
44 1.1.18.2 yamt
45 1.1.18.2 yamt #include <machine/sbd.h>
46 1.1.18.2 yamt
47 1.1.18.2 yamt #include "console.h"
48 1.1.18.2 yamt
49 1.1.18.2 yamt struct zskbd zskbd;
50 1.1.18.2 yamt
51 1.1.18.2 yamt int zskbd_common_getc(int);
52 1.1.18.2 yamt void zskbd_busy(void);
53 1.1.18.2 yamt
54 1.1.18.2 yamt static const uint8_t map_normal[] = {
55 1.1.18.2 yamt '0', '1', '2', '3', '4', '5', '6', '7',
56 1.1.18.2 yamt '8', '9', '-', '^', '\\', ':', '.', '/',
57 1.1.18.2 yamt '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
58 1.1.18.2 yamt 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
59 1.1.18.2 yamt 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
60 1.1.18.2 yamt 'x', 'y', 'z', '[', ',', ']', ';', 0x00,
61 1.1.18.2 yamt '0', '1', '2', '3', '4', '5', '6', '7',
62 1.1.18.2 yamt '8', '9', ' ', ',', 0x00, 0x00, 0x00, 0x00,
63 1.1.18.2 yamt 0x0d, 0x0d, 0x00, 0x00, 0x0d, 0x00, '-', '.',
64 1.1.18.2 yamt 0xa3, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65 1.1.18.2 yamt 0x08, 0x00, 0x0c, 0x7f, 0x12, 0x00, 0x00, 0x00,
66 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68 1.1.18.2 yamt 0x00, 0x00, 0xa0, 0xa1, 0x00, 0x00, 0x00, 0x00,
69 1.1.18.2 yamt '+', '*', '/', 0x1b, 0x01, '=', 0x09, 0x00,
70 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
71 1.1.18.2 yamt };
72 1.1.18.2 yamt
73 1.1.18.2 yamt static const uint8_t map_shift[] = {
74 1.1.18.2 yamt '0', '!', '\"', '#', '$', '%', '&', '\'',
75 1.1.18.2 yamt '(', ')', '=', '^', '|', '*', '>', '?',
76 1.1.18.2 yamt '~', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
77 1.1.18.2 yamt 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
78 1.1.18.2 yamt 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
79 1.1.18.2 yamt 'X', 'Y', 'Z', '{', '<', '}', '+', '_',
80 1.1.18.2 yamt '0', '1', '2', '3', '4', '5', '6', '7',
81 1.1.18.2 yamt '8', '9', ' ', ',', 0x00, 0x00, 0x00, 0x00,
82 1.1.18.2 yamt 0x0d, 0x0d, 'B', 'C', 0x0d, 'E', '-', '.',
83 1.1.18.2 yamt 0xa3, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 1.1.18.2 yamt 0x08, 0x00, 0x0b, 0x7f, 0x12, 0x09, 0x00, 0x00,
85 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 1.1.18.2 yamt 0x00, 0x00, 0xa0, 0xa1, 0x00, 0x00, 0x00, 0x00,
88 1.1.18.2 yamt '+', '*', '/', 0x1b, 0x01, '=', 0x09, 0x00,
89 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90 1.1.18.2 yamt };
91 1.1.18.2 yamt
92 1.1.18.2 yamt static const uint8_t map_ctrl[] = {
93 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 1.1.18.2 yamt 0xa4, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
96 1.1.18.2 yamt 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
97 1.1.18.2 yamt 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
98 1.1.18.2 yamt 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
99 1.1.18.2 yamt '0', '1', '2', '3', '4', '5', '6', '7',
100 1.1.18.2 yamt '8', '9', ' ', ',', 0x00, 0x00, 0x00, 0x00,
101 1.1.18.2 yamt 0x0d, 0x0d, 0x00, 0x00, 0x0d, 0x00, '-', '.',
102 1.1.18.2 yamt 0xa3, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103 1.1.18.2 yamt 0x08, 0x00, 0x00, 0x7f, 0x12, 0x00, 0x00, 0x00,
104 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106 1.1.18.2 yamt 0x00, 0x00, 0xa0, 0xa1, 0x00, 0x00, 0x00, 0x00,
107 1.1.18.2 yamt '+', '*', '/', 0x1b, 0x01, '=', 0x09, 0x00,
108 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109 1.1.18.2 yamt };
110 1.1.18.2 yamt
111 1.1.18.2 yamt static const uint8_t map_capslock[] = {
112 1.1.18.2 yamt '0', '1', '2', '3', '4', '5', '6', '7',
113 1.1.18.2 yamt '8', '9', '-', '^', '\\', ':', '.', '/',
114 1.1.18.2 yamt '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
115 1.1.18.2 yamt 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
116 1.1.18.2 yamt 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
117 1.1.18.2 yamt 'X', 'Y', 'Z', '[', ',', ']', ';', 0x00,
118 1.1.18.2 yamt '0', '1', '2', '3', '4', '5', '6', '7',
119 1.1.18.2 yamt '8', '9', ' ', ',', 0x00, 0x00, 0x00, 0x00,
120 1.1.18.2 yamt 0x0d, 0x0d, 0x00, 0x00, 0x0d, 0x00, '-', '.',
121 1.1.18.2 yamt 0xa3, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122 1.1.18.2 yamt 0x08, 0x00, 0x0c, 0x7f, 0x12, 0x00, 0x00, 0x00,
123 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125 1.1.18.2 yamt 0x00, 0x00, 0xa0, 0xa1, 0x00, 0x00, 0x00, 0x00,
126 1.1.18.2 yamt '+', '*', '/', 0x1b, 0x01, '=', 0x09, 0x00,
127 1.1.18.2 yamt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128 1.1.18.2 yamt };
129 1.1.18.2 yamt
130 1.1.18.2 yamt void
131 1.1.18.2 yamt zskbd_set_addr(uint32_t status, uint32_t data)
132 1.1.18.2 yamt {
133 1.1.18.2 yamt zskbd.status = (volatile uint8_t *)status;
134 1.1.18.2 yamt zskbd.data = (volatile uint8_t *)data;
135 1.1.18.2 yamt zskbd.normal = map_normal;
136 1.1.18.2 yamt zskbd.shift = map_shift;
137 1.1.18.2 yamt zskbd.ctrl = map_ctrl;
138 1.1.18.2 yamt zskbd.capslock = map_capslock;
139 1.1.18.2 yamt
140 1.1.18.2 yamt cons.getc = zskbd_getc;
141 1.1.18.2 yamt cons.scan = zskbd_scan;
142 1.1.18.2 yamt }
143 1.1.18.2 yamt
144 1.1.18.2 yamt void
145 1.1.18.2 yamt zskbd_print_keyscan(int on)
146 1.1.18.2 yamt {
147 1.1.18.2 yamt
148 1.1.18.2 yamt zskbd.print = on;
149 1.1.18.2 yamt }
150 1.1.18.2 yamt
151 1.1.18.2 yamt int
152 1.1.18.2 yamt zskbd_getc(void)
153 1.1.18.2 yamt {
154 1.1.18.2 yamt
155 1.1.18.2 yamt return zskbd_common_getc(0);
156 1.1.18.2 yamt }
157 1.1.18.2 yamt
158 1.1.18.2 yamt int
159 1.1.18.2 yamt zskbd_scan(void)
160 1.1.18.2 yamt {
161 1.1.18.2 yamt
162 1.1.18.2 yamt return zskbd_common_getc(1);
163 1.1.18.2 yamt }
164 1.1.18.2 yamt
165 1.1.18.2 yamt int
166 1.1.18.2 yamt zskbd_common_getc(int scan)
167 1.1.18.2 yamt {
168 1.1.18.2 yamt #ifdef CHECK_KEY_RELEASE
169 1.1.18.2 yamt static int released = 1;
170 1.1.18.2 yamt int push;
171 1.1.18.2 yamt #endif
172 1.1.18.2 yamt int v, c;
173 1.1.18.2 yamt
174 1.1.18.2 yamt for (;;) {
175 1.1.18.2 yamt if (scan) {
176 1.1.18.2 yamt if ((*zskbd.status & 0x01) != 0x01)
177 1.1.18.2 yamt return -1;
178 1.1.18.2 yamt } else {
179 1.1.18.2 yamt while ((*zskbd.status & 0x01) != 0x01)
180 1.1.18.2 yamt continue;
181 1.1.18.2 yamt }
182 1.1.18.2 yamt
183 1.1.18.2 yamt v = *zskbd.data;
184 1.1.18.2 yamt if (zskbd.print)
185 1.1.18.2 yamt printf("scancode = 0x%x\n", v);
186 1.1.18.2 yamt
187 1.1.18.2 yamt switch (v) {
188 1.1.18.2 yamt case 123: /* Shift-L */
189 1.1.18.2 yamt /* FALLTHROUGH */
190 1.1.18.2 yamt case 124: /* Shift-R */
191 1.1.18.2 yamt zskbd.keymap |= 0x01;
192 1.1.18.2 yamt break;
193 1.1.18.2 yamt case 251:
194 1.1.18.2 yamt /* FALLTHROUGH */
195 1.1.18.2 yamt case 252:
196 1.1.18.2 yamt zskbd.keymap &= ~0x01;
197 1.1.18.2 yamt break;
198 1.1.18.2 yamt case 120: /* Ctrl-L */
199 1.1.18.2 yamt zskbd.keymap |= 0x02;
200 1.1.18.2 yamt break;
201 1.1.18.2 yamt case 248:
202 1.1.18.2 yamt zskbd.keymap &= ~0x02;
203 1.1.18.2 yamt break;
204 1.1.18.2 yamt case 121: /* CapsLock */
205 1.1.18.2 yamt if (zskbd.keymap & 0x04) {
206 1.1.18.2 yamt zskbd.keymap &= ~0x04;
207 1.1.18.2 yamt zskbd_busy();
208 1.1.18.2 yamt *zskbd.data = 0x90; /* LED */
209 1.1.18.2 yamt } else {
210 1.1.18.2 yamt zskbd.keymap |= 0x04;
211 1.1.18.2 yamt zskbd_busy();
212 1.1.18.2 yamt *zskbd.data = 0x92; /* LED */
213 1.1.18.2 yamt }
214 1.1.18.2 yamt break;
215 1.1.18.2 yamt default:
216 1.1.18.2 yamt #ifdef CHECK_KEY_RELEASE
217 1.1.18.2 yamt push = (v & 0x80) == 0;
218 1.1.18.2 yamt if (push && released) {
219 1.1.18.2 yamt released = 0;
220 1.1.18.2 yamt goto exit_loop;
221 1.1.18.2 yamt }
222 1.1.18.2 yamt if (!push)
223 1.1.18.2 yamt released = 1;
224 1.1.18.2 yamt #else /* CHECK_KEY_RELEASE */
225 1.1.18.2 yamt if ((v & 0x80) == 0)
226 1.1.18.2 yamt goto exit_loop;
227 1.1.18.2 yamt #endif /* CHECK_KEY_RELEASE */
228 1.1.18.2 yamt break;
229 1.1.18.2 yamt }
230 1.1.18.2 yamt }
231 1.1.18.2 yamt
232 1.1.18.2 yamt exit_loop:
233 1.1.18.2 yamt c = v & 0x7f;
234 1.1.18.2 yamt if (zskbd.keymap & 0x01) /* Shift */
235 1.1.18.2 yamt return *(zskbd.shift + c);
236 1.1.18.2 yamt if (zskbd.keymap & 0x02) /* Ctrl */
237 1.1.18.2 yamt return *(zskbd.ctrl + c);
238 1.1.18.2 yamt if (zskbd.keymap & 0x04) /* CapsLock */
239 1.1.18.2 yamt return *(zskbd.capslock + c);
240 1.1.18.2 yamt /* Normal */
241 1.1.18.2 yamt return *(zskbd.normal + c);
242 1.1.18.2 yamt }
243 1.1.18.2 yamt
244 1.1.18.2 yamt void
245 1.1.18.2 yamt zskbd_busy(void)
246 1.1.18.2 yamt {
247 1.1.18.2 yamt
248 1.1.18.2 yamt #if 0 /* I misunderstand??? -uch */
249 1.1.18.2 yamt do {
250 1.1.18.2 yamt while ((*zskbd.status & 0x20) != 0x20)
251 1.1.18.2 yamt ;
252 1.1.18.2 yamt } while ((*zskbd.status & 0x4) != 0x4);
253 1.1.18.2 yamt #endif
254 1.1.18.2 yamt }
255