vrkiu.c revision 1.2 1 1.2 takemura /* $NetBSD: vrkiu.c,v 1.2 1999/10/24 08:37:30 takemura Exp $ */
2 1.1 takemura
3 1.1 takemura /*-
4 1.2 takemura * Copyright (c) 1999 SASAKI Takesi All rights reserved.
5 1.2 takemura * Copyright (c) 1999 TAKEMRUA, Shin All rights reserved.
6 1.1 takemura * Copyright (c) 1999 PocketBSD Project. All rights reserved.
7 1.1 takemura *
8 1.1 takemura * Redistribution and use in source and binary forms, with or without
9 1.1 takemura * modification, are permitted provided that the following conditions
10 1.1 takemura * are met:
11 1.1 takemura * 1. Redistributions of source code must retain the above copyright
12 1.1 takemura * notice, this list of conditions and the following disclaimer.
13 1.1 takemura * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 takemura * notice, this list of conditions and the following disclaimer in the
15 1.1 takemura * documentation and/or other materials provided with the distribution.
16 1.1 takemura * 3. All advertising materials mentioning features or use of this software
17 1.1 takemura * must display the following acknowledgement:
18 1.1 takemura * This product includes software developed by the PocketBSD project
19 1.1 takemura * and its contributors.
20 1.1 takemura * 4. Neither the name of the project nor the names of its contributors
21 1.1 takemura * may be used to endorse or promote products derived from this software
22 1.1 takemura * without specific prior written permission.
23 1.1 takemura *
24 1.1 takemura * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 takemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 takemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 takemura * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 takemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 takemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 takemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 takemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 takemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 takemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 takemura * SUCH DAMAGE.
35 1.1 takemura *
36 1.1 takemura */
37 1.1 takemura
38 1.1 takemura #define VRKIUDEBUG
39 1.1 takemura
40 1.1 takemura #include <sys/param.h>
41 1.1 takemura #include <sys/tty.h>
42 1.1 takemura #include <sys/systm.h>
43 1.1 takemura #include <sys/device.h>
44 1.1 takemura #include <sys/conf.h>
45 1.1 takemura #include <sys/kernel.h>
46 1.1 takemura #include <sys/proc.h>
47 1.1 takemura
48 1.1 takemura #include <machine/intr.h>
49 1.1 takemura #include <machine/cpu.h>
50 1.1 takemura #include <machine/bus.h>
51 1.1 takemura #include <machine/platid.h>
52 1.1 takemura
53 1.1 takemura #include <hpcmips/vr/vr.h>
54 1.1 takemura #include <hpcmips/vr/vripvar.h>
55 1.1 takemura #include <hpcmips/vr/vrkiuvar.h>
56 1.1 takemura #include <hpcmips/vr/vrkiureg.h>
57 1.1 takemura #include <hpcmips/vr/icureg.h>
58 1.1 takemura
59 1.2 takemura #include <dev/wscons/wsconsio.h>
60 1.2 takemura #include <dev/wscons/wskbdvar.h>
61 1.2 takemura #include <dev/wscons/wsksymdef.h>
62 1.2 takemura #include <dev/wscons/wsksymvar.h>
63 1.2 takemura #include <dev/pckbc/wskbdmap_mfii.h>
64 1.2 takemura
65 1.1 takemura #ifdef VRKIUDEBUG
66 1.1 takemura int vrkiu_debug = 0;
67 1.1 takemura #define DPRINTF(arg) if (vrkiu_debug) printf arg;
68 1.1 takemura #else
69 1.1 takemura #define DPRINTF(arg)
70 1.1 takemura #endif
71 1.1 takemura
72 1.2 takemura /*
73 1.2 takemura * structure and data types
74 1.2 takemura */
75 1.2 takemura struct vrkiu_chip {
76 1.2 takemura bus_space_tag_t kc_iot;
77 1.2 takemura bus_space_handle_t kc_ioh;
78 1.2 takemura unsigned short kc_scandata[KIU_NSCANLINE/2];
79 1.2 takemura int kc_polling;
80 1.2 takemura u_int kc_type;
81 1.2 takemura int kc_data;
82 1.2 takemura
83 1.2 takemura int kc_sft:1, kc_alt:1, kc_ctrl:1;
84 1.2 takemura
85 1.2 takemura struct vrkiu_softc* kc_sc; /* back link */
86 1.2 takemura };
87 1.2 takemura
88 1.2 takemura struct vrkiu_softc {
89 1.2 takemura struct device sc_dev;
90 1.2 takemura struct vrkiu_chip *sc_chip;
91 1.2 takemura struct vrkiu_chip sc_chip_body;
92 1.2 takemura int sc_enabled;
93 1.2 takemura struct device *sc_wskbddev;
94 1.2 takemura
95 1.2 takemura void *sc_handler;
96 1.2 takemura #define NKEYBUF 32
97 1.2 takemura unsigned char keybuf[NKEYBUF];
98 1.2 takemura int keybufhead, keybuftail;
99 1.2 takemura };
100 1.2 takemura
101 1.2 takemura /*
102 1.2 takemura * function prototypes
103 1.2 takemura */
104 1.1 takemura static int vrkiumatch __P((struct device *, struct cfdata *, void *));
105 1.1 takemura static void vrkiuattach __P((struct device *, struct device *, void *));
106 1.1 takemura
107 1.2 takemura int vrkiu_intr __P((void *));
108 1.2 takemura
109 1.2 takemura static int vrkiu_init(struct vrkiu_chip*, bus_space_tag_t, bus_space_handle_t);
110 1.2 takemura static void vrkiu_write __P((struct vrkiu_chip *, int, unsigned short));
111 1.2 takemura static unsigned short vrkiu_read __P((struct vrkiu_chip *, int));
112 1.2 takemura static int vrkiu_is_console(bus_space_tag_t, bus_space_handle_t);
113 1.2 takemura static void detect_key __P((struct vrkiu_chip *));
114 1.1 takemura
115 1.2 takemura static struct vrkiu_softc *the_vrkiu = NULL; /* XXX: kludge!! */
116 1.1 takemura
117 1.2 takemura /* wskbd accessopts */
118 1.2 takemura int vrkiu_enable __P((void *, int));
119 1.2 takemura void vrkiu_set_leds __P((void *, int));
120 1.2 takemura int vrkiu_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
121 1.2 takemura
122 1.2 takemura /* consopts */
123 1.2 takemura void vrkiu_cngetc __P((void*, u_int*, int*));
124 1.2 takemura void vrkiu_cnpollc __P((void *, int));
125 1.1 takemura
126 1.2 takemura /*
127 1.2 takemura * global/static data
128 1.2 takemura */
129 1.1 takemura struct cfattach vrkiu_ca = {
130 1.1 takemura sizeof(struct vrkiu_softc), vrkiumatch, vrkiuattach
131 1.1 takemura };
132 1.1 takemura
133 1.2 takemura const struct wskbd_accessops vrkiu_accessops = {
134 1.2 takemura vrkiu_enable,
135 1.2 takemura vrkiu_set_leds,
136 1.2 takemura vrkiu_ioctl,
137 1.2 takemura };
138 1.2 takemura
139 1.2 takemura const struct wskbd_consops vrkiu_consops = {
140 1.2 takemura vrkiu_cngetc,
141 1.2 takemura vrkiu_cnpollc,
142 1.2 takemura };
143 1.2 takemura
144 1.2 takemura const struct wskbd_mapdata vrkiu_keymapdata = {
145 1.2 takemura pckbd_keydesctab,
146 1.2 takemura KB_US,
147 1.2 takemura };
148 1.2 takemura
149 1.2 takemura struct vrkiu_chip *vrkiu_consdata = NULL;
150 1.1 takemura
151 1.1 takemura /* XXX: This tranlation table may depend on each machine.
152 1.1 takemura Should I build it in? */
153 1.1 takemura static char keytrans[] = {
154 1.1 takemura -1, 28, 25, 52, 21, 48, 44, 57, /* - enter p . y b z space */
155 1.1 takemura -1, 53, 24, 51, 20, 47, 30, -1, /* - / o , t v a - */
156 1.1 takemura -1, -1, 23, 50, 19, 46, 17, -1, /* - - i m r c w - */
157 1.1 takemura 13, -1, 22, -1, 18, 45, 16, 2, /* = - u - e x q 1 */
158 1.1 takemura -1, -1, 11, 38, 40, 34, 15, 59, /* - - 0 l ' g tab f1 */
159 1.1 takemura -1, 39, 10, 49, 6, 33, 3, 37, /* - ; 9 n 5 f 2 k */
160 1.1 takemura -1, 27, 9, 36, 5, 32, 7, -1, /* - ] 8 j 4 d 6 - */
161 1.1 takemura 12, 26, 8, 35, 4, 41, 31, -1, /* - [ 7 h 3 ` s - */
162 1.1 takemura 58, -1, -1, -1, 14, -1, 66, 61, /* caps - - - bs - f8 f3 */
163 1.1 takemura -1, 56, -1, -1, 43, -1, 65, 62, /* - alt - - \ - f7 f4 */
164 1.1 takemura -1, -1, 29, -1, 68, -1, 64, 60, /* - - ctrl - f10 - f6 f2 */
165 1.1 takemura -1, -1, -1, 42, -1, 67, 63, 1, /* - - - shift - f9 f5 esc */
166 1.1 takemura };
167 1.1 takemura /* XXX: fill the field of funct. keys, ex. arrow, fnc, nfer... */
168 1.1 takemura
169 1.1 takemura #define SCROLL 0x0001 /* stop output */
170 1.1 takemura #define NUM 0x0002 /* numeric shift cursors vs. numeric */
171 1.1 takemura #define CAPS 0x0004 /* caps shift -- swaps case of letter */
172 1.1 takemura #define SHIFT 0x0008 /* keyboard shift */
173 1.1 takemura #define CTL 0x0010 /* control shift -- allows ctl function */
174 1.1 takemura #define ASCII 0x0020 /* ascii code for this key */
175 1.1 takemura #define ALT 0x0080 /* alternate shift -- alternate chars */
176 1.1 takemura #define FUNC 0x0100 /* function key */
177 1.1 takemura #define KP 0x0200 /* Keypad keys */
178 1.1 takemura #define NONE 0x0400 /* no function */
179 1.1 takemura
180 1.2 takemura /*
181 1.2 takemura * utilities
182 1.2 takemura */
183 1.2 takemura static inline void
184 1.2 takemura vrkiu_write(chip, port, val)
185 1.2 takemura struct vrkiu_chip *chip;
186 1.2 takemura int port;
187 1.2 takemura unsigned short val;
188 1.2 takemura {
189 1.2 takemura bus_space_write_2(chip->kc_iot, chip->kc_ioh, port, val);
190 1.2 takemura }
191 1.1 takemura
192 1.2 takemura static inline unsigned short
193 1.2 takemura vrkiu_read(chip, port)
194 1.2 takemura struct vrkiu_chip *chip;
195 1.2 takemura int port;
196 1.2 takemura {
197 1.2 takemura return bus_space_read_2(chip->kc_iot, chip->kc_ioh, port);
198 1.2 takemura }
199 1.1 takemura
200 1.2 takemura static inline int
201 1.2 takemura vrkiu_is_console(iot, ioh)
202 1.2 takemura bus_space_tag_t iot;
203 1.2 takemura bus_space_handle_t ioh;
204 1.2 takemura {
205 1.2 takemura if (vrkiu_consdata &&
206 1.2 takemura vrkiu_consdata->kc_iot == iot &&
207 1.2 takemura vrkiu_consdata->kc_ioh == ioh) {
208 1.2 takemura return 1;
209 1.2 takemura } else {
210 1.2 takemura return 0;
211 1.2 takemura }
212 1.2 takemura }
213 1.2 takemura
214 1.2 takemura /*
215 1.2 takemura * initialize device
216 1.2 takemura */
217 1.2 takemura static int
218 1.2 takemura vrkiu_init(chip, iot, ioh)
219 1.2 takemura struct vrkiu_chip* chip;
220 1.2 takemura bus_space_tag_t iot;
221 1.2 takemura bus_space_handle_t ioh;
222 1.2 takemura {
223 1.2 takemura memset(chip, 0, sizeof(struct vrkiu_chip));
224 1.2 takemura chip->kc_iot = iot;
225 1.2 takemura chip->kc_ioh = ioh;
226 1.2 takemura chip->kc_polling = 0;
227 1.1 takemura
228 1.2 takemura /* set KIU */
229 1.2 takemura vrkiu_write(chip, KIURST, 1); /* reset */
230 1.2 takemura vrkiu_write(chip, KIUSCANLINE, 0); /* 96keys */
231 1.2 takemura vrkiu_write(chip, KIUWKS, 0x18a4); /* XXX: scan timing! */
232 1.2 takemura vrkiu_write(chip, KIUWKI, 450);
233 1.2 takemura vrkiu_write(chip, KIUSCANREP, 0x8023);
234 1.2 takemura /* KEYEN | STPREP = 2 | ATSTP | ATSCAN */
235 1.2 takemura return 0;
236 1.2 takemura }
237 1.1 takemura
238 1.2 takemura /*
239 1.2 takemura * probe
240 1.2 takemura */
241 1.1 takemura static int
242 1.1 takemura vrkiumatch(parent, cf, aux)
243 1.1 takemura struct device *parent;
244 1.1 takemura struct cfdata *cf;
245 1.1 takemura void *aux;
246 1.1 takemura {
247 1.2 takemura return 1;
248 1.1 takemura }
249 1.1 takemura
250 1.2 takemura /*
251 1.2 takemura * attach
252 1.2 takemura */
253 1.1 takemura static void
254 1.1 takemura vrkiuattach(parent, self, aux)
255 1.1 takemura struct device *parent;
256 1.1 takemura struct device *self;
257 1.1 takemura void *aux;
258 1.1 takemura {
259 1.1 takemura struct vrkiu_softc *sc = (struct vrkiu_softc *)self;
260 1.1 takemura struct vrip_attach_args *va = aux;
261 1.2 takemura struct wskbddev_attach_args wa;
262 1.2 takemura int isconsole;
263 1.1 takemura
264 1.1 takemura bus_space_tag_t iot = va->va_iot;
265 1.1 takemura bus_space_handle_t ioh;
266 1.1 takemura
267 1.1 takemura if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
268 1.1 takemura printf(": can't map bus space\n");
269 1.1 takemura return;
270 1.1 takemura }
271 1.1 takemura
272 1.2 takemura isconsole = vrkiu_is_console(iot, ioh);
273 1.2 takemura if (isconsole) {
274 1.2 takemura sc->sc_chip = vrkiu_consdata;
275 1.2 takemura } else {
276 1.2 takemura sc->sc_chip = &sc->sc_chip_body;
277 1.2 takemura vrkiu_init(sc->sc_chip, iot, ioh);
278 1.2 takemura }
279 1.2 takemura sc->sc_chip->kc_sc = sc;
280 1.1 takemura
281 1.1 takemura if (!(sc->sc_handler =
282 1.1 takemura vrip_intr_establish(va->va_vc, va->va_intr, IPL_TTY,
283 1.1 takemura vrkiu_intr, sc))) {
284 1.1 takemura printf (": can't map interrupt line.\n");
285 1.1 takemura return;
286 1.1 takemura }
287 1.1 takemura /* Level2 register setting */
288 1.1 takemura vrip_intr_setmask2(va->va_vc, sc->sc_handler, KIUINT_KDATRDY, 1);
289 1.1 takemura
290 1.1 takemura printf("\n");
291 1.2 takemura
292 1.2 takemura wa.console = isconsole;
293 1.2 takemura wa.keymap = &vrkiu_keymapdata;
294 1.2 takemura wa.accessops = &vrkiu_accessops;
295 1.2 takemura wa.accesscookie = sc;
296 1.2 takemura
297 1.2 takemura sc->sc_wskbddev = config_found(self, &wa, wskbddevprint);
298 1.1 takemura }
299 1.1 takemura
300 1.1 takemura int
301 1.1 takemura vrkiu_intr(arg)
302 1.1 takemura void *arg;
303 1.1 takemura {
304 1.1 takemura struct vrkiu_softc *sc = arg;
305 1.2 takemura
306 1.1 takemura /* When key scan finisshed, this entry is called. */
307 1.2 takemura DPRINTF(("%s(%d): vrkiu_intr: %d\n",
308 1.2 takemura __FILE__, __LINE__,
309 1.2 takemura vrkiu_read(sc->sc_chip, KIUINT) & 7));
310 1.2 takemura
311 1.2 takemura detect_key(sc->sc_chip);
312 1.1 takemura
313 1.2 takemura vrkiu_write(sc->sc_chip, KIUINT, 0x7); /* Clear all interrupt */
314 1.1 takemura
315 1.1 takemura return 0;
316 1.1 takemura }
317 1.1 takemura
318 1.1 takemura static void
319 1.2 takemura detect_key(chip)
320 1.2 takemura struct vrkiu_chip* chip;
321 1.1 takemura {
322 1.2 takemura int i, j, modified, mask;
323 1.2 takemura unsigned short scandata[KIU_NSCANLINE/2];
324 1.1 takemura
325 1.1 takemura for (i = 0; i < KIU_NSCANLINE / 2; i++) {
326 1.2 takemura scandata[i] = vrkiu_read(chip, KIUDATP + i * 2);
327 1.1 takemura }
328 1.1 takemura
329 1.2 takemura DPRINTF(("%s(%d): detect_key():", __FILE__, __LINE__));
330 1.2 takemura
331 1.2 takemura if (chip->kc_polling) {
332 1.2 takemura chip->kc_type = WSCONS_EVENT_ALL_KEYS_UP;
333 1.2 takemura }
334 1.1 takemura
335 1.2 takemura for (i = 0; i < KIU_NSCANLINE / 2; i++) {
336 1.2 takemura modified = scandata[i] ^ chip->kc_scandata[i];
337 1.2 takemura mask = 1;
338 1.2 takemura for (j = 0; j < 16; j++) {
339 1.2 takemura /* XXX: The order of keys can be a problem.
340 1.2 takemura If CTRL and normal key are pushed simultaneously,
341 1.2 takemura normal key can be entered in queue first.
342 1.2 takemura Same problem would occur in key break. */
343 1.2 takemura if (modified & mask) {
344 1.2 takemura int key, type;
345 1.2 takemura key = i * 16 + j;
346 1.2 takemura if (keytrans[key] < 0) {
347 1.2 takemura printf("vrkiu: Unkown scan code 0x%02x\n", key);
348 1.2 takemura continue;
349 1.2 takemura }
350 1.2 takemura type = (scandata[i] & mask) ?
351 1.2 takemura WSCONS_EVENT_KEY_DOWN :
352 1.2 takemura WSCONS_EVENT_KEY_UP;
353 1.2 takemura DPRINTF(("(%d,%d)=%s%d ", i, j,
354 1.2 takemura (scandata[i] & mask) ? "v" : "^",
355 1.2 takemura keytrans[key]));
356 1.2 takemura if (chip->kc_polling) {
357 1.2 takemura chip->kc_type = type;
358 1.2 takemura chip->kc_data = keytrans[key];
359 1.2 takemura } else {
360 1.2 takemura wskbd_input(chip->kc_sc->sc_wskbddev,
361 1.2 takemura type,
362 1.2 takemura keytrans[key]);
363 1.2 takemura }
364 1.1 takemura }
365 1.2 takemura mask <<= 1;
366 1.1 takemura }
367 1.2 takemura chip->kc_scandata[i] = scandata[i];
368 1.1 takemura }
369 1.2 takemura DPRINTF(("\n"));
370 1.1 takemura }
371 1.1 takemura
372 1.1 takemura /* called from biconsdev.c */
373 1.1 takemura int
374 1.1 takemura vrkiu_getc()
375 1.1 takemura {
376 1.1 takemura int ret;
377 1.1 takemura
378 1.1 takemura if (the_vrkiu == NULL) {
379 1.1 takemura return 0; /* XXX */
380 1.1 takemura }
381 1.1 takemura
382 1.1 takemura while (the_vrkiu->keybuftail == the_vrkiu->keybufhead) {
383 1.2 takemura detect_key(vrkiu_consdata);
384 1.1 takemura }
385 1.1 takemura ret = the_vrkiu->keybuf[the_vrkiu->keybuftail++];
386 1.1 takemura if (the_vrkiu->keybuftail >= NKEYBUF) {
387 1.1 takemura the_vrkiu->keybuftail = 0;
388 1.1 takemura }
389 1.1 takemura return ret;
390 1.1 takemura }
391 1.1 takemura
392 1.2 takemura int
393 1.2 takemura vrkiu_enable(scx, on)
394 1.2 takemura void *scx;
395 1.2 takemura int on;
396 1.2 takemura {
397 1.2 takemura struct vrkiu_softc *sc = scx;
398 1.2 takemura
399 1.2 takemura if (on) {
400 1.2 takemura if (sc->sc_enabled)
401 1.2 takemura return (EBUSY);
402 1.2 takemura sc->sc_enabled = 1;
403 1.2 takemura } else {
404 1.2 takemura if (sc->sc_chip == vrkiu_consdata)
405 1.2 takemura return (EBUSY);
406 1.2 takemura sc->sc_enabled = 0;
407 1.2 takemura }
408 1.2 takemura
409 1.2 takemura return (0);
410 1.2 takemura }
411 1.2 takemura
412 1.2 takemura void
413 1.2 takemura vrkiu_set_leds(scx, leds)
414 1.2 takemura void *scx;
415 1.2 takemura int leds;
416 1.2 takemura {
417 1.2 takemura /*struct pckbd_softc *sc = scx;
418 1.2 takemura */
419 1.2 takemura
420 1.2 takemura DPRINTF(("%s(%d): vrkiu_set_leds() not implemented\n",
421 1.2 takemura __FILE__, __LINE__));
422 1.2 takemura }
423 1.2 takemura
424 1.2 takemura int
425 1.2 takemura vrkiu_ioctl(scx, cmd, data, flag, p)
426 1.2 takemura void *scx;
427 1.2 takemura u_long cmd;
428 1.2 takemura caddr_t data;
429 1.2 takemura int flag;
430 1.2 takemura struct proc *p;
431 1.2 takemura {
432 1.2 takemura /*struct vrkiu_softc *sc = scx;
433 1.2 takemura */
434 1.2 takemura
435 1.2 takemura switch (cmd) {
436 1.2 takemura case WSKBDIO_GTYPE:
437 1.2 takemura /*
438 1.2 takemura * XXX, fix me !
439 1.2 takemura */
440 1.2 takemura *(int *)data = WSKBD_TYPE_PC_XT;
441 1.2 takemura return 0;
442 1.2 takemura case WSKBDIO_SETLEDS:
443 1.2 takemura DPRINTF(("%s(%d): no LED\n", __FILE__, __LINE__));
444 1.2 takemura return 0;
445 1.2 takemura case WSKBDIO_GETLEDS:
446 1.2 takemura DPRINTF(("%s(%d): no LED\n", __FILE__, __LINE__));
447 1.2 takemura *(int *)data = 0;
448 1.2 takemura return (0);
449 1.2 takemura }
450 1.2 takemura return -1;
451 1.2 takemura }
452 1.2 takemura
453 1.2 takemura /*
454 1.2 takemura * console support routines
455 1.2 takemura */
456 1.2 takemura int
457 1.2 takemura vrkiu_cnattach(iot, iobase)
458 1.2 takemura bus_space_tag_t iot;
459 1.2 takemura int iobase;
460 1.2 takemura {
461 1.2 takemura static struct vrkiu_chip vrkiu_consdata_body;
462 1.2 takemura bus_space_handle_t ioh;
463 1.2 takemura
464 1.2 takemura if (vrkiu_consdata) {
465 1.2 takemura panic("vrkiu is already attached as the console");
466 1.2 takemura }
467 1.2 takemura if (bus_space_map(iot, iobase, 1, 0, &ioh)) {
468 1.2 takemura printf("%s(%d): can't map bus space\n", __FILE__, __LINE__);
469 1.2 takemura return -1;
470 1.2 takemura }
471 1.2 takemura
472 1.2 takemura if (vrkiu_init(&vrkiu_consdata_body, iot, ioh) != 0) {
473 1.2 takemura DPRINTF(("%s(%d): vrkiu_init() failed\n", __FILE__, __LINE__));
474 1.2 takemura return -1;
475 1.2 takemura }
476 1.2 takemura vrkiu_consdata = &vrkiu_consdata_body;
477 1.2 takemura
478 1.2 takemura wskbd_cnattach(&vrkiu_consops, vrkiu_consdata, &vrkiu_keymapdata);
479 1.2 takemura
480 1.2 takemura return (0);
481 1.2 takemura }
482 1.2 takemura
483 1.2 takemura void
484 1.2 takemura vrkiu_cngetc(chipx, type, data)
485 1.2 takemura void *chipx;
486 1.2 takemura u_int *type;
487 1.2 takemura int *data;
488 1.2 takemura {
489 1.2 takemura struct vrkiu_chip* chip = chipx;
490 1.2 takemura int s;
491 1.2 takemura
492 1.2 takemura if (!chip->kc_polling) {
493 1.2 takemura printf("%s(%d): kiu is not polled\n", __FILE__, __LINE__);
494 1.2 takemura while (1);
495 1.2 takemura }
496 1.2 takemura
497 1.2 takemura s = splimp();
498 1.2 takemura if (chip->kc_type == WSCONS_EVENT_ALL_KEYS_UP) {
499 1.2 takemura detect_key(chip);
500 1.2 takemura }
501 1.2 takemura *type = chip->kc_type;
502 1.2 takemura *data = chip->kc_data;
503 1.2 takemura chip->kc_type = WSCONS_EVENT_ALL_KEYS_UP;
504 1.2 takemura splx(s);
505 1.2 takemura }
506 1.2 takemura
507 1.2 takemura void
508 1.2 takemura vrkiu_cnpollc(chipx, on)
509 1.2 takemura void *chipx;
510 1.2 takemura int on;
511 1.2 takemura {
512 1.2 takemura struct vrkiu_chip* chip = chipx;
513 1.2 takemura int s = splimp();
514 1.2 takemura
515 1.2 takemura chip->kc_polling = on;
516 1.2 takemura
517 1.2 takemura splx(s);
518 1.2 takemura
519 1.2 takemura DPRINTF(("%s(%d): vrkiu polling %s\n",
520 1.2 takemura __FILE__, __LINE__, on ? "ON" : "OFF"));
521 1.2 takemura }
522