1 /* $NetBSD: kb.c,v 1.8 2007/03/04 06:00:24 christos Exp $ */
4 * Copyright (c) 2001 Izumi Tsutsui. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Copyright (c) 2000 Tsubai Masanari.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. The name of the author may not be used to endorse or promote products
40 * derived from this software without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
43 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
45 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
46 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 #include <sys/cdefs.h>
55 __KERNEL_RCSID(0, "$NetBSD: kb.c,v 1.8 2007/03/04 06:00:24 christos Exp $");
57 #include <sys/param.h>
58 #include <sys/systm.h>
59 #include <sys/device.h>
61 #include <dev/wscons/wsconsio.h>
62 #include <dev/wscons/wskbdvar.h>
63 #include <dev/wscons/wsksymdef.h>
64 #include <dev/wscons/wsksymvar.h>
66 #include <machine/bus.h>
68 #include <arch/news68k/dev/kbvar.h>
70 /* #define KB_DEBUG */
72 void kb_cngetc(void *, u_int
*, int *);
73 void kb_cnpollc(void *, int);
74 int kb_enable(void *, int);
75 void kb_set_leds(void *, int);
76 int kb_ioctl(void *, u_long
, void *, int, struct lwp
*);
78 extern struct wscons_keydesc newskb_keydesctab
[];
80 struct wskbd_accessops kb_accessops
= {
86 struct wskbd_consops kb_consops
= {
91 struct wskbd_mapdata kb_keymapdata
= {
97 kb_intr(struct kb_softc
*sc
)
99 struct console_softc
*kb_conssc
= sc
->sc_conssc
;
100 bus_space_tag_t bt
= sc
->sc_bt
;
101 bus_space_handle_t bh
= sc
->sc_bh
;
102 bus_size_t offset
= sc
->sc_offset
;
106 kb_conssc
->cs_nkeyevents
++;
108 key
= bus_space_read_1(bt
, bh
, offset
);
109 type
= (key
& 0x80) ? WSCONS_EVENT_KEY_UP
: WSCONS_EVENT_KEY_DOWN
;
113 printf("kb_intr: key=%02x, type=%d, val=%02x\n", key
, type
, val
);
115 kb_conssc
->cs_key
= key
;
116 kb_conssc
->cs_type
= type
;
117 kb_conssc
->cs_val
= val
;
119 if (!kb_conssc
->cs_polling
)
120 wskbd_input(sc
->sc_wskbddev
, type
, val
);
124 kb_cnattach(struct console_softc
*conssc_p
)
127 wskbd_cnattach(&kb_consops
, conssc_p
, &kb_keymapdata
);
132 kb_cngetc(void *v
, u_int
*type
, int *data
)
134 struct console_softc
*conssc
= v
;
137 /* set to polling mode */
138 conssc
->cs_polling
= 1;
140 /* wait until any keyevent occur */
141 nkey
= conssc
->cs_nkeyevents
;
142 while (conssc
->cs_nkeyevents
== nkey
)
145 /* get last keyevent */
146 *data
= conssc
->cs_val
;
147 *type
= conssc
->cs_type
;
149 conssc
->cs_polling
= 0;
153 kb_cnpollc(void *v
, int on
)
158 kb_enable(void *v
, int on
)
165 kb_set_leds(void *v
, int on
)
170 kb_ioctl(void *v
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
173 struct console_softc
*cs
= v
;
178 *(int *)data
= 0; /* XXX */
180 case WSKBDIO_SETLEDS
:
182 case WSKBDIO_GETLEDS
:
185 case WSKBDIO_COMPLEXBELL
: