ukbd.c revision 1.9 1 1.9 augustss /* $NetBSD: ukbd.c,v 1.9 1998/08/02 22:27:01 augustss Exp $ */
2 1.1 augustss
3 1.1 augustss /*
4 1.1 augustss * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 augustss * All rights reserved.
6 1.1 augustss *
7 1.1 augustss * Author: Lennart Augustsson <augustss (at) carlstedt.se>
8 1.1 augustss * Carlstedt Research & Technology
9 1.1 augustss *
10 1.1 augustss * Redistribution and use in source and binary forms, with or without
11 1.1 augustss * modification, are permitted provided that the following conditions
12 1.1 augustss * are met:
13 1.1 augustss * 1. Redistributions of source code must retain the above copyright
14 1.1 augustss * notice, this list of conditions and the following disclaimer.
15 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 augustss * notice, this list of conditions and the following disclaimer in the
17 1.1 augustss * documentation and/or other materials provided with the distribution.
18 1.1 augustss * 3. All advertising materials mentioning features or use of this software
19 1.1 augustss * must display the following acknowledgement:
20 1.1 augustss * This product includes software developed by the NetBSD
21 1.1 augustss * Foundation, Inc. and its contributors.
22 1.1 augustss * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 augustss * contributors may be used to endorse or promote products derived
24 1.1 augustss * from this software without specific prior written permission.
25 1.1 augustss *
26 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
37 1.1 augustss */
38 1.1 augustss
39 1.1 augustss
40 1.1 augustss #include <sys/param.h>
41 1.1 augustss #include <sys/systm.h>
42 1.1 augustss #include <sys/kernel.h>
43 1.1 augustss #include <sys/malloc.h>
44 1.1 augustss #include <sys/device.h>
45 1.1 augustss #include <sys/ioctl.h>
46 1.1 augustss #include <sys/tty.h>
47 1.1 augustss #include <sys/file.h>
48 1.1 augustss #include <sys/select.h>
49 1.1 augustss #include <sys/proc.h>
50 1.1 augustss #include <sys/vnode.h>
51 1.1 augustss #include <sys/device.h>
52 1.1 augustss #include <sys/poll.h>
53 1.1 augustss
54 1.1 augustss #include <dev/usb/usb.h>
55 1.2 augustss #include <dev/usb/usbhid.h>
56 1.1 augustss #include <dev/usb/usbdi.h>
57 1.1 augustss #include <dev/usb/usbdi_util.h>
58 1.1 augustss #include <dev/usb/usbdevs.h>
59 1.1 augustss #include <dev/usb/usb_quirks.h>
60 1.1 augustss #include <dev/usb/hid.h>
61 1.1 augustss
62 1.2 augustss #include <dev/wscons/wsconsio.h>
63 1.2 augustss #include <dev/wscons/wskbdvar.h>
64 1.2 augustss #include <dev/wscons/wsksymdef.h>
65 1.2 augustss #include <dev/wscons/wsksymvar.h>
66 1.2 augustss #include <dev/wscons/wskbdmap_mfii.h>
67 1.2 augustss
68 1.2 augustss #include "opt_pckbd_layout.h"
69 1.2 augustss #include "opt_wsdisplay_compat.h"
70 1.2 augustss
71 1.1 augustss #ifdef USB_DEBUG
72 1.1 augustss #define DPRINTF(x) if (ukbddebug) printf x
73 1.1 augustss #define DPRINTFN(n,x) if (ukbddebug>(n)) printf x
74 1.1 augustss int ukbddebug = 0;
75 1.1 augustss #else
76 1.1 augustss #define DPRINTF(x)
77 1.1 augustss #define DPRINTFN(n,x)
78 1.1 augustss #endif
79 1.1 augustss
80 1.1 augustss #define UPROTO_BOOT_KEYBOARD 1
81 1.1 augustss
82 1.1 augustss #define NKEYCODE 6
83 1.1 augustss
84 1.2 augustss #define NUM_LOCK 0x01
85 1.2 augustss #define CAPS_LOCK 0x02
86 1.2 augustss #define SCROLL_LOCK 0x04
87 1.2 augustss
88 1.1 augustss struct ukbd_data {
89 1.1 augustss u_int8_t modifiers;
90 1.1 augustss #define MOD_CONTROL_L 0x01
91 1.1 augustss #define MOD_CONTROL_R 0x10
92 1.1 augustss #define MOD_SHIFT_L 0x02
93 1.1 augustss #define MOD_SHIFT_R 0x20
94 1.1 augustss #define MOD_ALT_L 0x04
95 1.1 augustss #define MOD_ALT_R 0x40
96 1.1 augustss #define MOD_WIN_L 0x08
97 1.1 augustss #define MOD_WIN_R 0x80
98 1.1 augustss u_int8_t reserved;
99 1.1 augustss u_int8_t keycode[NKEYCODE];
100 1.1 augustss };
101 1.1 augustss
102 1.1 augustss #define PRESS 0
103 1.5 augustss #define RELEASE 0x100
104 1.1 augustss
105 1.1 augustss #define NMOD 6
106 1.1 augustss static struct {
107 1.1 augustss int mask, key;
108 1.1 augustss } ukbd_mods[NMOD] = {
109 1.1 augustss { MOD_CONTROL_L, 29 },
110 1.1 augustss { MOD_CONTROL_R, 58 },
111 1.1 augustss { MOD_SHIFT_L, 42 },
112 1.1 augustss { MOD_SHIFT_R, 54 },
113 1.1 augustss { MOD_ALT_L, 56 },
114 1.5 augustss { MOD_ALT_R, 184 },
115 1.1 augustss };
116 1.1 augustss
117 1.5 augustss #define NN 0 /* no translation */
118 1.5 augustss /* Translate USB keycodes to US keyboard AT scancodes. */
119 1.5 augustss static u_int8_t ukbd_trtab[256] = {
120 1.5 augustss 0, 0, 0, 0, 30, 48, 46, 32, /* 00 - 07 */
121 1.5 augustss 18, 33, 34, 35, 23, 36, 37, 38, /* 08 - 0F */
122 1.5 augustss 50, 49, 24, 25, 16, 19, 31, 20, /* 10 - 17 */
123 1.5 augustss 22, 47, 17, 45, 21, 44, 2, 3, /* 18 - 1F */
124 1.5 augustss 4, 5, 6, 7, 8, 9, 10, 11, /* 20 - 27 */
125 1.5 augustss 28, 1, 14, 15, 57, 12, 13, 26, /* 28 - 2F */
126 1.5 augustss 27, 43, NN, 39, 40, 41, 51, 52, /* 30 - 37 */
127 1.5 augustss 53, 58, 59, 60, 61, 62, 63, 64, /* 38 - 3F */
128 1.5 augustss 65, 66, 67, 68, 87, 88, 170, 70, /* 40 - 47 */
129 1.5 augustss 127, 210, 199, 201, 211, 207, 209, 205, /* 48 - 4F */
130 1.5 augustss 203, 208, 200, 69, 181, 55, 74, 78, /* 50 - 57 */
131 1.5 augustss 156, 79, 80, 81, 75, 76, 77, 71, /* 58 - 5F */
132 1.5 augustss 72, 73, 82, 83, NN, NN, NN, NN, /* 60 - 67 */
133 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* 68 - 6F */
134 1.5 augustss NN, NN, NN, NN, NN, NN, 221, NN, /* 70 - 77 */
135 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* 78 - 7F */
136 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* 80 - 87 */
137 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* 88 - 8F */
138 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* 90 - 97 */
139 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* 98 - 9F */
140 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* A0 - A7 */
141 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* A8 - AF */
142 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* B0 - B7 */
143 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* B8 - BF */
144 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* C0 - C7 */
145 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* C8 - CF */
146 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* D0 - D7 */
147 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* D8 - DF */
148 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* E0 - E7 */
149 1.5 augustss NN, NN, NN, 219, NN, NN, NN, 220, /* E8 - EF */
150 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* F0 - F7 */
151 1.5 augustss NN, NN, NN, NN, NN, NN, NN, NN, /* F8 - FF */
152 1.1 augustss };
153 1.1 augustss
154 1.1 augustss #define KEY_ERROR 0x01
155 1.1 augustss
156 1.1 augustss struct ukbd_softc {
157 1.1 augustss struct device sc_dev; /* base device */
158 1.1 augustss usbd_interface_handle sc_iface; /* interface */
159 1.1 augustss usbd_pipe_handle sc_intrpipe; /* interrupt pipe */
160 1.1 augustss int sc_ep_addr;
161 1.1 augustss
162 1.1 augustss struct ukbd_data sc_ndata;
163 1.1 augustss struct ukbd_data sc_odata;
164 1.1 augustss
165 1.9 augustss char sc_enabled;
166 1.9 augustss char sc_disconnected; /* device is gone */
167 1.1 augustss
168 1.2 augustss int sc_leds;
169 1.2 augustss struct device *sc_wskbddev;
170 1.2 augustss #ifdef WSDISPLAY_COMPAT_RAWKBD
171 1.2 augustss int sc_rawkbd;
172 1.2 augustss #endif
173 1.3 augustss
174 1.3 augustss int sc_polling;
175 1.3 augustss int sc_pollchar;
176 1.1 augustss };
177 1.1 augustss
178 1.1 augustss #define UKBDUNIT(dev) (minor(dev))
179 1.1 augustss #define UKBD_CHUNK 128 /* chunk size for read */
180 1.1 augustss #define UKBD_BSIZE 1020 /* buffer size */
181 1.1 augustss
182 1.2 augustss int ukbd_match __P((struct device *, struct cfdata *, void *));
183 1.2 augustss void ukbd_attach __P((struct device *, struct device *, void *));
184 1.1 augustss
185 1.3 augustss void ukbd_cngetc __P((void *, u_int *, int *));
186 1.3 augustss void ukbd_cnpollc __P((void *, int));
187 1.3 augustss
188 1.8 drochner const struct wskbd_consops ukbd_consops = {
189 1.8 drochner ukbd_cngetc,
190 1.8 drochner ukbd_cnpollc,
191 1.8 drochner };
192 1.8 drochner
193 1.2 augustss void ukbd_intr __P((usbd_request_handle, usbd_private_handle, usbd_status));
194 1.2 augustss void ukbd_disco __P((void *));
195 1.2 augustss
196 1.8 drochner int ukbd_enable __P((void *, int));
197 1.2 augustss void ukbd_set_leds __P((void *, int));
198 1.2 augustss int ukbd_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
199 1.1 augustss
200 1.8 drochner const struct wskbd_accessops ukbd_accessops = {
201 1.8 drochner ukbd_enable,
202 1.8 drochner ukbd_set_leds,
203 1.8 drochner ukbd_ioctl,
204 1.8 drochner };
205 1.8 drochner
206 1.8 drochner const struct wskbd_mapdata ukbd_keymapdata = {
207 1.8 drochner pckbd_keydesctab,
208 1.8 drochner sizeof(pckbd_keydesctab)/sizeof(pckbd_keydesctab[0]),
209 1.8 drochner #ifdef PCKBD_LAYOUT
210 1.8 drochner PCKBD_LAYOUT,
211 1.8 drochner #else
212 1.8 drochner KB_US,
213 1.8 drochner #endif
214 1.8 drochner };
215 1.8 drochner
216 1.1 augustss extern struct cfdriver ukbd_cd;
217 1.1 augustss
218 1.1 augustss struct cfattach ukbd_ca = {
219 1.1 augustss sizeof(struct ukbd_softc), ukbd_match, ukbd_attach
220 1.1 augustss };
221 1.1 augustss
222 1.1 augustss int
223 1.1 augustss ukbd_match(parent, match, aux)
224 1.1 augustss struct device *parent;
225 1.1 augustss struct cfdata *match;
226 1.1 augustss void *aux;
227 1.1 augustss {
228 1.1 augustss struct usb_attach_arg *uaa = (struct usb_attach_arg *)aux;
229 1.1 augustss usb_interface_descriptor_t *id;
230 1.1 augustss
231 1.1 augustss /* Check that this is a keyboard that speaks the boot protocol. */
232 1.1 augustss if (!uaa->iface)
233 1.1 augustss return (UMATCH_NONE);
234 1.1 augustss id = usbd_get_interface_descriptor(uaa->iface);
235 1.1 augustss if (id->bInterfaceClass != UCLASS_HID ||
236 1.1 augustss id->bInterfaceSubClass != USUBCLASS_BOOT ||
237 1.1 augustss id->bInterfaceProtocol != UPROTO_BOOT_KEYBOARD)
238 1.1 augustss return (UMATCH_NONE);
239 1.1 augustss return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
240 1.1 augustss }
241 1.1 augustss
242 1.1 augustss void
243 1.1 augustss ukbd_attach(parent, self, aux)
244 1.1 augustss struct device *parent;
245 1.1 augustss struct device *self;
246 1.1 augustss void *aux;
247 1.1 augustss {
248 1.1 augustss struct ukbd_softc *sc = (struct ukbd_softc *)self;
249 1.1 augustss struct usb_attach_arg *uaa = aux;
250 1.1 augustss usbd_interface_handle iface = uaa->iface;
251 1.1 augustss usb_interface_descriptor_t *id;
252 1.1 augustss usb_endpoint_descriptor_t *ed;
253 1.1 augustss usbd_status r;
254 1.1 augustss char devinfo[1024];
255 1.2 augustss struct wskbddev_attach_args a;
256 1.1 augustss
257 1.1 augustss sc->sc_disconnected = 1;
258 1.1 augustss sc->sc_iface = iface;
259 1.1 augustss id = usbd_get_interface_descriptor(iface);
260 1.1 augustss usbd_devinfo(uaa->device, 0, devinfo);
261 1.1 augustss printf(": %s (interface class %d/%d)\n", devinfo,
262 1.1 augustss id->bInterfaceClass, id->bInterfaceSubClass);
263 1.1 augustss ed = usbd_interface2endpoint_descriptor(iface, 0);
264 1.1 augustss if (!ed) {
265 1.1 augustss printf("%s: could not read endpoint descriptor\n",
266 1.1 augustss sc->sc_dev.dv_xname);
267 1.1 augustss return;
268 1.1 augustss }
269 1.1 augustss
270 1.1 augustss DPRINTFN(10,("ukbd_attach: \
271 1.1 augustss bLength=%d bDescriptorType=%d bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d bInterval=%d\n",
272 1.1 augustss ed->bLength, ed->bDescriptorType, ed->bEndpointAddress & UE_ADDR,
273 1.1 augustss ed->bEndpointAddress & UE_IN ? "in" : "out",
274 1.1 augustss ed->bmAttributes & UE_XFERTYPE,
275 1.1 augustss UGETW(ed->wMaxPacketSize), ed->bInterval));
276 1.1 augustss
277 1.1 augustss if ((ed->bEndpointAddress & UE_IN) != UE_IN ||
278 1.1 augustss (ed->bmAttributes & UE_XFERTYPE) != UE_INTERRUPT) {
279 1.1 augustss printf("%s: unexpected endpoint\n",
280 1.1 augustss sc->sc_dev.dv_xname);
281 1.1 augustss return;
282 1.1 augustss }
283 1.1 augustss
284 1.1 augustss if ((usbd_get_quirks(uaa->device)->uq_flags & UQ_NO_SET_PROTO) == 0) {
285 1.1 augustss r = usbd_set_protocol(iface, 0);
286 1.1 augustss DPRINTFN(5, ("ukbd_attach: protocol set\n"));
287 1.1 augustss if (r != USBD_NORMAL_COMPLETION) {
288 1.1 augustss printf("%s: set protocol failed\n",
289 1.1 augustss sc->sc_dev.dv_xname);
290 1.1 augustss return;
291 1.1 augustss }
292 1.1 augustss }
293 1.6 augustss /* Ignore if SETIDLE fails since it is not crucial. */
294 1.5 augustss usbd_set_idle(iface, 0, 0);
295 1.1 augustss
296 1.1 augustss sc->sc_ep_addr = ed->bEndpointAddress;
297 1.1 augustss sc->sc_disconnected = 0;
298 1.2 augustss
299 1.2 augustss a.console = 0; /* XXX */
300 1.8 drochner
301 1.8 drochner a.keymap = &ukbd_keymapdata;
302 1.8 drochner
303 1.8 drochner a.accessops = &ukbd_accessops;
304 1.2 augustss a.accesscookie = sc;
305 1.8 drochner
306 1.2 augustss sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
307 1.1 augustss }
308 1.1 augustss
309 1.1 augustss void
310 1.1 augustss ukbd_disco(p)
311 1.1 augustss void *p;
312 1.1 augustss {
313 1.1 augustss struct ukbd_softc *sc = p;
314 1.7 augustss
315 1.7 augustss DPRINTF(("ukbd_disco: sc=%p\n", sc));
316 1.7 augustss usbd_abort_pipe(sc->sc_intrpipe);
317 1.1 augustss sc->sc_disconnected = 1;
318 1.8 drochner }
319 1.8 drochner
320 1.8 drochner int
321 1.8 drochner ukbd_enable(v, on)
322 1.8 drochner void *v;
323 1.8 drochner int on;
324 1.8 drochner {
325 1.9 augustss struct ukbd_softc *sc = v;
326 1.9 augustss usbd_status r;
327 1.9 augustss
328 1.9 augustss if (on) {
329 1.9 augustss /* Set up interrupt pipe. */
330 1.9 augustss if (sc->sc_enabled)
331 1.9 augustss return EBUSY;
332 1.9 augustss
333 1.9 augustss sc->sc_enabled = 1;
334 1.9 augustss r = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr,
335 1.9 augustss USBD_SHORT_XFER_OK,
336 1.9 augustss &sc->sc_intrpipe, sc, &sc->sc_ndata,
337 1.9 augustss sizeof(sc->sc_ndata), ukbd_intr);
338 1.9 augustss if (r != USBD_NORMAL_COMPLETION)
339 1.9 augustss return (EIO);
340 1.9 augustss usbd_set_disco(sc->sc_intrpipe, ukbd_disco, sc);
341 1.9 augustss } else {
342 1.9 augustss /* Disable interrupts. */
343 1.9 augustss usbd_abort_pipe(sc->sc_intrpipe);
344 1.9 augustss usbd_close_pipe(sc->sc_intrpipe);
345 1.9 augustss
346 1.9 augustss sc->sc_enabled = 0;
347 1.9 augustss }
348 1.9 augustss
349 1.8 drochner return (0);
350 1.1 augustss }
351 1.1 augustss
352 1.1 augustss void
353 1.1 augustss ukbd_intr(reqh, addr, status)
354 1.1 augustss usbd_request_handle reqh;
355 1.1 augustss usbd_private_handle addr;
356 1.1 augustss usbd_status status;
357 1.1 augustss {
358 1.1 augustss struct ukbd_softc *sc = addr;
359 1.1 augustss struct ukbd_data *ud = &sc->sc_ndata;
360 1.1 augustss int mod, omod;
361 1.5 augustss int ibuf[NMOD+2*NKEYCODE]; /* chars events */
362 1.1 augustss int nkeys, i, j;
363 1.2 augustss int key, c;
364 1.1 augustss #define ADDKEY(c) ibuf[nkeys++] = (c)
365 1.1 augustss
366 1.1 augustss DPRINTFN(5, ("ukbd_intr: status=%d\n", status));
367 1.1 augustss if (status == USBD_CANCELLED)
368 1.1 augustss return;
369 1.1 augustss
370 1.1 augustss if (status != USBD_NORMAL_COMPLETION) {
371 1.1 augustss DPRINTF(("ukbd_intr: status=%d\n", status));
372 1.4 augustss usbd_clear_endpoint_stall_async(sc->sc_intrpipe);
373 1.1 augustss return;
374 1.1 augustss }
375 1.1 augustss
376 1.1 augustss DPRINTFN(5, (" mod=0x%02x key0=0x%02x key1=0x%02x\n",
377 1.1 augustss ud->modifiers, ud->keycode[0], ud->keycode[1]));
378 1.1 augustss
379 1.1 augustss if (ud->keycode[0] == KEY_ERROR)
380 1.1 augustss return; /* ignore */
381 1.1 augustss nkeys = 0;
382 1.1 augustss mod = ud->modifiers;
383 1.1 augustss omod = sc->sc_odata.modifiers;
384 1.1 augustss if (mod != omod)
385 1.1 augustss for (i = 0; i < NMOD; i++)
386 1.1 augustss if (( mod & ukbd_mods[i].mask) !=
387 1.1 augustss (omod & ukbd_mods[i].mask))
388 1.1 augustss ADDKEY(ukbd_mods[i].key |
389 1.1 augustss (mod & ukbd_mods[i].mask
390 1.1 augustss ? PRESS : RELEASE));
391 1.1 augustss if (memcmp(ud->keycode, sc->sc_odata.keycode, NKEYCODE) != 0) {
392 1.1 augustss /* Check for released keys. */
393 1.1 augustss for (i = 0; i < NKEYCODE; i++) {
394 1.1 augustss key = sc->sc_odata.keycode[i];
395 1.1 augustss if (key == 0)
396 1.1 augustss continue;
397 1.1 augustss for (j = 0; j < NKEYCODE; j++)
398 1.1 augustss if (key == ud->keycode[j])
399 1.1 augustss goto rfound;
400 1.2 augustss c = ukbd_trtab[key];
401 1.2 augustss if (c)
402 1.2 augustss ADDKEY(c | RELEASE);
403 1.1 augustss rfound:
404 1.1 augustss ;
405 1.1 augustss }
406 1.1 augustss
407 1.1 augustss /* Check for pressed keys. */
408 1.1 augustss for (i = 0; i < NKEYCODE; i++) {
409 1.1 augustss key = ud->keycode[i];
410 1.1 augustss if (key == 0)
411 1.1 augustss continue;
412 1.1 augustss for (j = 0; j < NKEYCODE; j++)
413 1.1 augustss if (key == sc->sc_odata.keycode[j])
414 1.1 augustss goto pfound;
415 1.2 augustss c = ukbd_trtab[key];
416 1.5 augustss DPRINTFN(2,("ukbd_intr: press key=0x%02x -> 0x%02x\n",
417 1.5 augustss key, c));
418 1.2 augustss if (c)
419 1.2 augustss ADDKEY(c | PRESS);
420 1.1 augustss pfound:
421 1.1 augustss ;
422 1.1 augustss }
423 1.1 augustss }
424 1.1 augustss sc->sc_odata = *ud;
425 1.1 augustss
426 1.3 augustss if (sc->sc_polling) {
427 1.3 augustss if (nkeys > 0)
428 1.6 augustss sc->sc_pollchar = ibuf[0]; /* XXX lost keys? */
429 1.3 augustss return;
430 1.3 augustss }
431 1.2 augustss for (i = 0; i < nkeys; i++) {
432 1.2 augustss c = ibuf[i];
433 1.2 augustss wskbd_input(sc->sc_wskbddev,
434 1.5 augustss c & RELEASE ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN,
435 1.5 augustss c & 0xff);
436 1.1 augustss }
437 1.1 augustss }
438 1.1 augustss
439 1.2 augustss void
440 1.2 augustss ukbd_set_leds(v, leds)
441 1.2 augustss void *v;
442 1.2 augustss int leds;
443 1.1 augustss {
444 1.2 augustss struct ukbd_softc *sc = v;
445 1.2 augustss u_int8_t res;
446 1.1 augustss
447 1.2 augustss DPRINTF(("ukbd_set_leds: sc=%p leds=%d\n", sc, leds));
448 1.1 augustss
449 1.2 augustss sc->sc_leds = leds;
450 1.2 augustss res = 0;
451 1.2 augustss if (leds & WSKBD_LED_SCROLL)
452 1.2 augustss res |= SCROLL_LOCK;
453 1.2 augustss if (leds & WSKBD_LED_NUM)
454 1.2 augustss res |= NUM_LOCK;
455 1.2 augustss if (leds & WSKBD_LED_CAPS)
456 1.2 augustss res |= CAPS_LOCK;
457 1.4 augustss usbd_set_report_async(sc->sc_iface, UHID_OUTPUT_REPORT, 0, &res, 1);
458 1.1 augustss }
459 1.1 augustss
460 1.1 augustss int
461 1.2 augustss ukbd_ioctl(v, cmd, data, flag, p)
462 1.2 augustss void *v;
463 1.1 augustss u_long cmd;
464 1.2 augustss caddr_t data;
465 1.1 augustss int flag;
466 1.1 augustss struct proc *p;
467 1.1 augustss {
468 1.2 augustss struct ukbd_softc *sc = v;
469 1.1 augustss
470 1.2 augustss switch (cmd) {
471 1.2 augustss case WSKBDIO_GTYPE:
472 1.2 augustss *(int *)data = WSKBD_TYPE_PC_XT;
473 1.2 augustss return 0;
474 1.2 augustss case WSKBDIO_SETLEDS:
475 1.2 augustss ukbd_set_leds(v, *(int *)data);
476 1.2 augustss return 0;
477 1.2 augustss case WSKBDIO_GETLEDS:
478 1.2 augustss *(int *)data = sc->sc_leds;
479 1.2 augustss return (0);
480 1.2 augustss #ifdef WSDISPLAY_COMPAT_RAWKBD
481 1.2 augustss case WSKBDIO_SETMODE:
482 1.2 augustss sc->sc_rawkbd = *(int *)data == WSKBD_RAW;
483 1.2 augustss return (0);
484 1.2 augustss #endif
485 1.2 augustss }
486 1.2 augustss return -1;
487 1.1 augustss }
488 1.7 augustss
489 1.7 augustss /* Console interface. */
490 1.7 augustss /* XXX does not work. */
491 1.3 augustss void
492 1.3 augustss ukbd_cngetc(v, type, data)
493 1.3 augustss void *v;
494 1.3 augustss u_int *type;
495 1.3 augustss int *data;
496 1.3 augustss {
497 1.3 augustss struct ukbd_softc *sc = v;
498 1.3 augustss usbd_lock_token s;
499 1.4 augustss int c;
500 1.3 augustss
501 1.4 augustss DPRINTFN(1,("ukbd_cngetc: enter\n"));
502 1.3 augustss s = usbd_lock();
503 1.3 augustss sc->sc_polling = 1;
504 1.3 augustss sc->sc_pollchar = -1;
505 1.3 augustss while(sc->sc_pollchar == -1)
506 1.3 augustss usbd_dopoll(sc->sc_iface);
507 1.3 augustss sc->sc_polling = 0;
508 1.4 augustss c = sc->sc_pollchar;
509 1.6 augustss *type = c & RELEASE ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
510 1.6 augustss *data = c & 0xff;
511 1.3 augustss usbd_unlock(s);
512 1.4 augustss DPRINTFN(1,("ukbd_cngetc: return 0x%02x\n", c));
513 1.3 augustss }
514 1.3 augustss
515 1.3 augustss void
516 1.3 augustss ukbd_cnpollc(v, on)
517 1.3 augustss void *v;
518 1.3 augustss int on;
519 1.3 augustss {
520 1.6 augustss struct ukbd_softc *sc = v;
521 1.6 augustss
522 1.4 augustss DPRINTFN(1,("ukbd_cnpollc: sc=%p on=%d\n", v, on));
523 1.6 augustss
524 1.6 augustss usbd_set_polling(sc->sc_iface, on);
525 1.3 augustss }
526