kb.c revision 1.1.2.2 1 1.1.2.2 bouyer /* $NetBSD: kb.c,v 1.1.2.2 2001/02/11 19:11:14 bouyer Exp $ */
2 1.1.2.2 bouyer
3 1.1.2.2 bouyer /*
4 1.1.2.2 bouyer * Copyright (c) 2001 Izumi Tsutsui.
5 1.1.2.2 bouyer * Copyright (c) 2000 Tsubai Masanari.
6 1.1.2.2 bouyer * All rights reserved.
7 1.1.2.2 bouyer *
8 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
10 1.1.2.2 bouyer * are met:
11 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
16 1.1.2.2 bouyer * 3. The name of the author may not be used to endorse or promote products
17 1.1.2.2 bouyer * derived from this software without specific prior written permission.
18 1.1.2.2 bouyer *
19 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 1.1.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 1.1.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.1.2.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 1.1.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 1.1.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 1.1.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 1.1.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 1.1.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 1.1.2.2 bouyer * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 1.1.2.2 bouyer */
30 1.1.2.2 bouyer
31 1.1.2.2 bouyer #include <sys/param.h>
32 1.1.2.2 bouyer #include <sys/systm.h>
33 1.1.2.2 bouyer #include <sys/device.h>
34 1.1.2.2 bouyer
35 1.1.2.2 bouyer #include <dev/wscons/wsconsio.h>
36 1.1.2.2 bouyer #include <dev/wscons/wskbdvar.h>
37 1.1.2.2 bouyer #include <dev/wscons/wsksymdef.h>
38 1.1.2.2 bouyer #include <dev/wscons/wsksymvar.h>
39 1.1.2.2 bouyer
40 1.1.2.2 bouyer #include <machine/bus.h>
41 1.1.2.2 bouyer
42 1.1.2.2 bouyer #include <arch/news68k/dev/kbvar.h>
43 1.1.2.2 bouyer
44 1.1.2.2 bouyer /* #define KB_DEBUG */
45 1.1.2.2 bouyer
46 1.1.2.2 bouyer void kb_cngetc(void *, u_int *, int *);
47 1.1.2.2 bouyer void kb_cnpollc(void *, int);
48 1.1.2.2 bouyer int kb_enable(void *, int);
49 1.1.2.2 bouyer void kb_set_leds(void *, int);
50 1.1.2.2 bouyer int kb_ioctl(void *, u_long, caddr_t, int, struct proc *);
51 1.1.2.2 bouyer
52 1.1.2.2 bouyer extern struct wscons_keydesc newskb_keydesctab[];
53 1.1.2.2 bouyer
54 1.1.2.2 bouyer struct wskbd_accessops kb_accessops = {
55 1.1.2.2 bouyer kb_enable,
56 1.1.2.2 bouyer kb_set_leds,
57 1.1.2.2 bouyer kb_ioctl,
58 1.1.2.2 bouyer };
59 1.1.2.2 bouyer
60 1.1.2.2 bouyer struct wskbd_consops kb_consops = {
61 1.1.2.2 bouyer kb_cngetc,
62 1.1.2.2 bouyer kb_cnpollc,
63 1.1.2.2 bouyer };
64 1.1.2.2 bouyer
65 1.1.2.2 bouyer struct wskbd_mapdata kb_keymapdata = {
66 1.1.2.2 bouyer newskb_keydesctab,
67 1.1.2.2 bouyer KB_JP,
68 1.1.2.2 bouyer };
69 1.1.2.2 bouyer
70 1.1.2.2 bouyer void
71 1.1.2.2 bouyer kb_intr(sc)
72 1.1.2.2 bouyer struct kb_softc *sc;
73 1.1.2.2 bouyer {
74 1.1.2.2 bouyer struct console_softc *kb_conssc = sc->sc_conssc;
75 1.1.2.2 bouyer bus_space_tag_t bt = sc->sc_bt;
76 1.1.2.2 bouyer bus_space_handle_t bh = sc->sc_bh;
77 1.1.2.2 bouyer bus_size_t offset = sc->sc_offset;
78 1.1.2.2 bouyer int key, val;
79 1.1.2.2 bouyer u_int type;
80 1.1.2.2 bouyer
81 1.1.2.2 bouyer kb_conssc->cs_nkeyevents++;
82 1.1.2.2 bouyer
83 1.1.2.2 bouyer key = bus_space_read_1(bt, bh, offset);
84 1.1.2.2 bouyer type = (key & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
85 1.1.2.2 bouyer val = key & 0x7f;
86 1.1.2.2 bouyer
87 1.1.2.2 bouyer #ifdef KB_DEBUG
88 1.1.2.2 bouyer printf("kb_intr: key=%02x, type=%d, val=%02x\n", key, type, val);
89 1.1.2.2 bouyer #endif
90 1.1.2.2 bouyer kb_conssc->cs_key = key;
91 1.1.2.2 bouyer kb_conssc->cs_type = type;
92 1.1.2.2 bouyer kb_conssc->cs_val = val;
93 1.1.2.2 bouyer
94 1.1.2.2 bouyer if (!kb_conssc->cs_polling)
95 1.1.2.2 bouyer wskbd_input(sc->sc_wskbddev, type, val);
96 1.1.2.2 bouyer }
97 1.1.2.2 bouyer
98 1.1.2.2 bouyer int
99 1.1.2.2 bouyer kb_cnattach(conssc_p)
100 1.1.2.2 bouyer struct console_softc *conssc_p;
101 1.1.2.2 bouyer {
102 1.1.2.2 bouyer
103 1.1.2.2 bouyer wskbd_cnattach(&kb_consops, conssc_p, &kb_keymapdata);
104 1.1.2.2 bouyer return 0;
105 1.1.2.2 bouyer }
106 1.1.2.2 bouyer
107 1.1.2.2 bouyer
108 1.1.2.2 bouyer void
109 1.1.2.2 bouyer kb_cngetc(v, type, data)
110 1.1.2.2 bouyer void *v;
111 1.1.2.2 bouyer u_int *type;
112 1.1.2.2 bouyer int *data;
113 1.1.2.2 bouyer {
114 1.1.2.2 bouyer struct console_softc *conssc = v;
115 1.1.2.2 bouyer int nkey;
116 1.1.2.2 bouyer
117 1.1.2.2 bouyer /* set to polling mode */
118 1.1.2.2 bouyer conssc->cs_polling = 1;
119 1.1.2.2 bouyer
120 1.1.2.2 bouyer /* wait until any keyevent occur */
121 1.1.2.2 bouyer nkey = conssc->cs_nkeyevents;
122 1.1.2.2 bouyer while (conssc->cs_nkeyevents == nkey)
123 1.1.2.2 bouyer ;
124 1.1.2.2 bouyer
125 1.1.2.2 bouyer /* get last keyevent */
126 1.1.2.2 bouyer *data = conssc->cs_val;
127 1.1.2.2 bouyer *type = conssc->cs_type;
128 1.1.2.2 bouyer
129 1.1.2.2 bouyer conssc->cs_polling = 0;
130 1.1.2.2 bouyer }
131 1.1.2.2 bouyer
132 1.1.2.2 bouyer void
133 1.1.2.2 bouyer kb_cnpollc(v, on)
134 1.1.2.2 bouyer void *v;
135 1.1.2.2 bouyer int on;
136 1.1.2.2 bouyer {
137 1.1.2.2 bouyer }
138 1.1.2.2 bouyer
139 1.1.2.2 bouyer int
140 1.1.2.2 bouyer kb_enable(v, on)
141 1.1.2.2 bouyer void *v;
142 1.1.2.2 bouyer int on;
143 1.1.2.2 bouyer {
144 1.1.2.2 bouyer return 0;
145 1.1.2.2 bouyer }
146 1.1.2.2 bouyer
147 1.1.2.2 bouyer void
148 1.1.2.2 bouyer kb_set_leds(v, on)
149 1.1.2.2 bouyer void *v;
150 1.1.2.2 bouyer int on;
151 1.1.2.2 bouyer {
152 1.1.2.2 bouyer return;
153 1.1.2.2 bouyer }
154 1.1.2.2 bouyer
155 1.1.2.2 bouyer int
156 1.1.2.2 bouyer kb_ioctl(v, cmd, data, flag, p)
157 1.1.2.2 bouyer void *v;
158 1.1.2.2 bouyer u_long cmd;
159 1.1.2.2 bouyer caddr_t data;
160 1.1.2.2 bouyer int flag;
161 1.1.2.2 bouyer struct proc *p;
162 1.1.2.2 bouyer {
163 1.1.2.2 bouyer #if 0
164 1.1.2.2 bouyer struct console_softc *cs = v;
165 1.1.2.2 bouyer #endif
166 1.1.2.2 bouyer
167 1.1.2.2 bouyer switch (cmd) {
168 1.1.2.2 bouyer case WSKBDIO_GTYPE:
169 1.1.2.2 bouyer *(int *)data = 0; /* XXX */
170 1.1.2.2 bouyer return 0;
171 1.1.2.2 bouyer case WSKBDIO_SETLEDS:
172 1.1.2.2 bouyer return 0;
173 1.1.2.2 bouyer case WSKBDIO_GETLEDS:
174 1.1.2.2 bouyer *(int *)data = 0;
175 1.1.2.2 bouyer return 0;
176 1.1.2.2 bouyer case WSKBDIO_COMPLEXBELL:
177 1.1.2.2 bouyer return 0;
178 1.1.2.2 bouyer }
179 1.1.2.2 bouyer
180 1.1.2.2 bouyer return -1;
181 1.1.2.2 bouyer }
182