6 * SPDX-License-Identifier: BSD-2-Clause-NetBSD
8 * Copyright (c) 1998 The NetBSD Foundation, Inc.
11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Lennart Augustsson (lennart@augustsson.net) at
13 * Carlstedt Research & Technology.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
39 * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
42 #include "opt_compat.h"
45 #include "opt_evdev.h"
47 #include <sys/stdint.h>
48 #include <sys/stddef.h>
49 #include <sys/param.h>
50 #include <sys/queue.h>
51 #include <sys/types.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
55 #include <sys/module.h>
57 #include <sys/mutex.h>
58 #include <sys/condvar.h>
59 #include <sys/sysctl.h>
61 #include <sys/unistd.h>
62 #include <sys/callout.h>
63 #include <sys/malloc.h>
67 #include <dev/usb/usb.h>
68 #include <dev/usb/usbdi.h>
69 #include <dev/usb/usbdi_util.h>
70 #include <dev/usb/usbhid.h>
72 #define USB_DEBUG_VAR ukbd_debug
73 #include <dev/usb/usb_debug.h>
75 #include <dev/usb/quirk/usb_quirk.h>
78 #include <dev/evdev/input.h>
79 #include <dev/evdev/evdev.h>
82 #include <sys/ioccom.h>
83 #include <sys/filio.h>
87 #include <dev/kbd/kbdreg.h>
89 /* the initial key map, accent map and fkey strings */
90 #if defined(UKBD_DFLT_KEYMAP) && !defined(KLD_MODULE)
91 #define KBD_DFLT_KEYMAP
95 /* the following file must be included after "ukbdmap.h" */
96 #include <dev/kbd/kbdtables.h>
99 static int ukbd_debug = 0;
100 static int ukbd_no_leds = 0;
101 static int ukbd_pollrate = 0;
103 static SYSCTL_NODE(_hw_usb, OID_AUTO, ukbd, CTLFLAG_RW, 0, "USB keyboard");
104 SYSCTL_INT(_hw_usb_ukbd, OID_AUTO, debug, CTLFLAG_RWTUN,
105 &ukbd_debug, 0, "Debug level");
106 SYSCTL_INT(_hw_usb_ukbd, OID_AUTO, no_leds, CTLFLAG_RWTUN,
107 &ukbd_no_leds, 0, "Disables setting of keyboard leds");
108 SYSCTL_INT(_hw_usb_ukbd, OID_AUTO, pollrate, CTLFLAG_RWTUN,
109 &ukbd_pollrate, 0, "Force this polling rate, 1-1000Hz");
112 #define UKBD_EMULATE_ATSCANCODE 1
113 #define UKBD_DRIVER_NAME "ukbd"
114 #define UKBD_NMOD 8 /* units */
115 #define UKBD_NKEYCODE 6 /* units */
116 #define UKBD_IN_BUF_SIZE (2*(UKBD_NMOD + (2*UKBD_NKEYCODE))) /* bytes */
117 #define UKBD_IN_BUF_FULL ((UKBD_IN_BUF_SIZE / 2) - 1) /* bytes */
118 #define UKBD_NFKEY (sizeof(fkey_tab)/sizeof(fkey_tab[0])) /* units */
119 #define UKBD_BUFFER_SIZE 64 /* bytes */
123 #define MOD_CONTROL_L 0x01
124 #define MOD_CONTROL_R 0x10
125 #define MOD_SHIFT_L 0x02
126 #define MOD_SHIFT_R 0x20
127 #define MOD_ALT_L 0x04
128 #define MOD_ALT_R 0x40
129 #define MOD_WIN_L 0x08
130 #define MOD_WIN_R 0x80
132 #define MOD_EJECT 0x0100
133 #define MOD_FN 0x0200
134 uint8_t keycode[UKBD_NKEYCODE];
147 accentmap_t sc_accmap;
148 fkeytab_t sc_fkeymap[UKBD_NFKEY];
149 struct hid_location sc_loc_apple_eject;
150 struct hid_location sc_loc_apple_fn;
151 struct hid_location sc_loc_ctrl_l;
152 struct hid_location sc_loc_ctrl_r;
153 struct hid_location sc_loc_shift_l;
154 struct hid_location sc_loc_shift_r;
155 struct hid_location sc_loc_alt_l;
156 struct hid_location sc_loc_alt_r;
157 struct hid_location sc_loc_win_l;
158 struct hid_location sc_loc_win_r;
159 struct hid_location sc_loc_events;
160 struct hid_location sc_loc_numlock;
161 struct hid_location sc_loc_capslock;
162 struct hid_location sc_loc_scrolllock;
163 struct usb_callout sc_callout;
164 struct ukbd_data sc_ndata;
165 struct ukbd_data sc_odata;
167 struct thread *sc_poll_thread;
168 struct usb_device *sc_udev;
169 struct usb_interface *sc_iface;
170 struct usb_xfer *sc_xfer[UKBD_N_TRANSFER];
172 struct evdev_dev *sc_evdev;
175 sbintime_t sc_co_basetime;
177 uint32_t sc_ntime[UKBD_NKEYCODE];
178 uint32_t sc_otime[UKBD_NKEYCODE];
179 uint32_t sc_input[UKBD_IN_BUF_SIZE]; /* input buffer */
181 uint32_t sc_composed_char; /* composed char code, if non-zero */
182 #ifdef UKBD_EMULATE_ATSCANCODE
183 uint32_t sc_buffered_char[2];
185 uint32_t sc_flags; /* flags */
186 #define UKBD_FLAG_COMPOSE 0x00000001
187 #define UKBD_FLAG_POLLING 0x00000002
188 #define UKBD_FLAG_SET_LEDS 0x00000004
189 #define UKBD_FLAG_ATTACHED 0x00000010
190 #define UKBD_FLAG_GONE 0x00000020
192 #define UKBD_FLAG_HID_MASK 0x003fffc0
193 #define UKBD_FLAG_APPLE_EJECT 0x00000040
194 #define UKBD_FLAG_APPLE_FN 0x00000080
195 #define UKBD_FLAG_APPLE_SWAP 0x00000100
196 #define UKBD_FLAG_CTRL_L 0x00000400
197 #define UKBD_FLAG_CTRL_R 0x00000800
198 #define UKBD_FLAG_SHIFT_L 0x00001000
199 #define UKBD_FLAG_SHIFT_R 0x00002000
200 #define UKBD_FLAG_ALT_L 0x00004000
201 #define UKBD_FLAG_ALT_R 0x00008000
202 #define UKBD_FLAG_WIN_L 0x00010000
203 #define UKBD_FLAG_WIN_R 0x00020000
204 #define UKBD_FLAG_EVENTS 0x00040000
205 #define UKBD_FLAG_NUMLOCK 0x00080000
206 #define UKBD_FLAG_CAPSLOCK 0x00100000
207 #define UKBD_FLAG_SCROLLLOCK 0x00200000
209 int sc_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */
210 int sc_state; /* shift/lock key state */
211 int sc_accents; /* accent key index (> 0) */
212 int sc_polling; /* polling recursion count */
217 uint16_t sc_inputhead;
218 uint16_t sc_inputtail;
219 uint16_t sc_modifiers;
221 uint8_t sc_leds; /* store for async led requests */
222 uint8_t sc_iface_index;
224 uint8_t sc_id_apple_eject;
225 uint8_t sc_id_apple_fn;
226 uint8_t sc_id_ctrl_l;
227 uint8_t sc_id_ctrl_r;
228 uint8_t sc_id_shift_l;
229 uint8_t sc_id_shift_r;
235 uint8_t sc_id_numlock;
236 uint8_t sc_id_capslock;
237 uint8_t sc_id_scrolllock;
238 uint8_t sc_id_events;
241 uint8_t sc_buffer[UKBD_BUFFER_SIZE];
244 #define KEY_ERROR 0x01
247 #define KEY_RELEASE 0x400
248 #define KEY_INDEX(c) ((c) & 0xFF)
251 #define SCAN_RELEASE 0x80
252 #define SCAN_PREFIX_E0 0x100
253 #define SCAN_PREFIX_E1 0x200
254 #define SCAN_PREFIX_CTL 0x400
255 #define SCAN_PREFIX_SHIFT 0x800
256 #define SCAN_PREFIX (SCAN_PREFIX_E0 | SCAN_PREFIX_E1 | \
257 SCAN_PREFIX_CTL | SCAN_PREFIX_SHIFT)
258 #define SCAN_CHAR(c) ((c) & 0x7f)
260 #define UKBD_LOCK() USB_MTX_LOCK(&Giant)
261 #define UKBD_UNLOCK() USB_MTX_UNLOCK(&Giant)
262 #define UKBD_LOCK_ASSERT() USB_MTX_ASSERT(&Giant, MA_OWNED)
268 static const struct ukbd_mods ukbd_mods[UKBD_NMOD] = {
269 {MOD_CONTROL_L, 0xe0},
270 {MOD_CONTROL_R, 0xe4},
279 #define NN 0 /* no translation */
281 * Translate USB keycodes to AT keyboard scancodes.
284 * FIXME: Mac USB keyboard generates:
285 * 0x53: keypad NumLock/Clear
292 * USB Apple Keyboard JIS generates:
296 static const uint8_t ukbd_trtab[256] = {
297 0, 0, 0, 0, 30, 48, 46, 32, /* 00 - 07 */
298 18, 33, 34, 35, 23, 36, 37, 38, /* 08 - 0F */
299 50, 49, 24, 25, 16, 19, 31, 20, /* 10 - 17 */
300 22, 47, 17, 45, 21, 44, 2, 3, /* 18 - 1F */
301 4, 5, 6, 7, 8, 9, 10, 11, /* 20 - 27 */
302 28, 1, 14, 15, 57, 12, 13, 26, /* 28 - 2F */
303 27, 43, 43, 39, 40, 41, 51, 52, /* 30 - 37 */
304 53, 58, 59, 60, 61, 62, 63, 64, /* 38 - 3F */
305 65, 66, 67, 68, 87, 88, 92, 70, /* 40 - 47 */
306 104, 102, 94, 96, 103, 99, 101, 98, /* 48 - 4F */
307 97, 100, 95, 69, 91, 55, 74, 78,/* 50 - 57 */
308 89, 79, 80, 81, 75, 76, 77, 71, /* 58 - 5F */
309 72, 73, 82, 83, 86, 107, 122, NN, /* 60 - 67 */
310 NN, NN, NN, NN, NN, NN, NN, NN, /* 68 - 6F */
311 NN, NN, NN, NN, 115, 108, 111, 113, /* 70 - 77 */
312 109, 110, 112, 118, 114, 116, 117, 119, /* 78 - 7F */
313 121, 120, NN, NN, NN, NN, NN, 123, /* 80 - 87 */
314 124, 125, 126, 127, 128, NN, NN, NN, /* 88 - 8F */
315 129, 130, NN, NN, NN, NN, NN, NN, /* 90 - 97 */
316 NN, NN, NN, NN, NN, NN, NN, NN, /* 98 - 9F */
317 NN, NN, NN, NN, NN, NN, NN, NN, /* A0 - A7 */
318 NN, NN, NN, NN, NN, NN, NN, NN, /* A8 - AF */
319 NN, NN, NN, NN, NN, NN, NN, NN, /* B0 - B7 */
320 NN, NN, NN, NN, NN, NN, NN, NN, /* B8 - BF */
321 NN, NN, NN, NN, NN, NN, NN, NN, /* C0 - C7 */
322 NN, NN, NN, NN, NN, NN, NN, NN, /* C8 - CF */
323 NN, NN, NN, NN, NN, NN, NN, NN, /* D0 - D7 */
324 NN, NN, NN, NN, NN, NN, NN, NN, /* D8 - DF */
325 29, 42, 56, 105, 90, 54, 93, 106, /* E0 - E7 */
326 NN, NN, NN, NN, NN, NN, NN, NN, /* E8 - EF */
327 NN, NN, NN, NN, NN, NN, NN, NN, /* F0 - F7 */
328 NN, NN, NN, NN, NN, NN, NN, NN, /* F8 - FF */
331 static const uint8_t ukbd_boot_desc[] = {
332 0x05, 0x01, 0x09, 0x06, 0xa1,
333 0x01, 0x05, 0x07, 0x19, 0xe0,
334 0x29, 0xe7, 0x15, 0x00, 0x25,
335 0x01, 0x75, 0x01, 0x95, 0x08,
336 0x81, 0x02, 0x95, 0x01, 0x75,
337 0x08, 0x81, 0x01, 0x95, 0x03,
338 0x75, 0x01, 0x05, 0x08, 0x19,
339 0x01, 0x29, 0x03, 0x91, 0x02,
340 0x95, 0x05, 0x75, 0x01, 0x91,
341 0x01, 0x95, 0x06, 0x75, 0x08,
342 0x15, 0x00, 0x26, 0xff, 0x00,
343 0x05, 0x07, 0x19, 0x00, 0x2a,
344 0xff, 0x00, 0x81, 0x00, 0xc0
348 static void ukbd_timeout(void *);
349 static void ukbd_set_leds(struct ukbd_softc *, uint8_t);
350 static int ukbd_set_typematic(keyboard_t *, int);
351 #ifdef UKBD_EMULATE_ATSCANCODE
352 static uint32_t ukbd_atkeycode(int, int);
353 static int ukbd_key2scan(struct ukbd_softc *, int, int, int);
355 static uint32_t ukbd_read_char(keyboard_t *, int);
356 static void ukbd_clear_state(keyboard_t *);
357 static int ukbd_ioctl(keyboard_t *, u_long, caddr_t);
358 static int ukbd_enable(keyboard_t *);
359 static int ukbd_disable(keyboard_t *);
360 static void ukbd_interrupt(struct ukbd_softc *);
361 static void ukbd_event_keyinput(struct ukbd_softc *);
363 static device_probe_t ukbd_probe;
364 static device_attach_t ukbd_attach;
365 static device_detach_t ukbd_detach;
366 static device_resume_t ukbd_resume;
369 static const struct evdev_methods ukbd_evdev_methods = {
370 .ev_event = evdev_ev_kbd_event,
375 ukbd_any_key_pressed(struct ukbd_softc *sc)
380 for (j = i = 0; i < UKBD_NKEYCODE; i++)
381 j |= sc->sc_odata.keycode[i];
387 ukbd_start_timer(struct ukbd_softc *sc)
389 sbintime_t delay, prec;
391 delay = SBT_1MS * sc->sc_delay;
392 sc->sc_co_basetime += delay;
393 /* This is rarely called, so prefer precision to efficiency. */
394 prec = qmin(delay >> 7, SBT_1MS * 10);
395 usb_callout_reset_sbt(&sc->sc_callout, sc->sc_co_basetime, prec,
396 ukbd_timeout, sc, C_ABSOLUTE);
400 ukbd_put_key(struct ukbd_softc *sc, uint32_t key)
405 DPRINTF("0x%02x (%d) %s\n", key, key,
406 (key & KEY_RELEASE) ? "released" : "pressed");
409 if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL) {
410 evdev_push_event(sc->sc_evdev, EV_KEY,
411 evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE));
412 evdev_sync(sc->sc_evdev);
416 if (sc->sc_inputs < UKBD_IN_BUF_SIZE) {
417 sc->sc_input[sc->sc_inputtail] = key;
419 ++(sc->sc_inputtail);
420 if (sc->sc_inputtail >= UKBD_IN_BUF_SIZE) {
421 sc->sc_inputtail = 0;
424 DPRINTF("input buffer is full\n");
429 ukbd_do_poll(struct ukbd_softc *sc, uint8_t wait)
433 KASSERT((sc->sc_flags & UKBD_FLAG_POLLING) != 0,
434 ("ukbd_do_poll called when not polling\n"));
435 DPRINTFN(2, "polling\n");
437 if (USB_IN_POLLING_MODE_FUNC() == 0) {
439 * In this context the kernel is polling for input,
440 * but the USB subsystem works in normal interrupt-driven
441 * mode, so we just wait on the USB threads to do the job.
442 * Note that we currently hold the Giant, but it's also used
443 * as the transfer mtx, so we must release it while waiting.
445 while (sc->sc_inputs == 0) {
447 * Give USB threads a chance to run. Note that
448 * kern_yield performs DROP_GIANT + PICKUP_GIANT.
450 kern_yield(PRI_UNCHANGED);
457 while (sc->sc_inputs == 0) {
459 usbd_transfer_poll(sc->sc_xfer, UKBD_N_TRANSFER);
461 /* Delay-optimised support for repetition of keys */
462 if (ukbd_any_key_pressed(sc)) {
463 /* a key is pressed - need timekeeping */
466 /* 1 millisecond has passed */
478 ukbd_get_key(struct ukbd_softc *sc, uint8_t wait)
483 KASSERT((USB_IN_POLLING_MODE_FUNC() == 0) ||
484 (sc->sc_flags & UKBD_FLAG_POLLING) != 0,
485 ("not polling in kdb or panic\n"));
487 if (sc->sc_inputs == 0 &&
488 (sc->sc_flags & UKBD_FLAG_GONE) == 0) {
489 /* start transfer, if not already started */
490 usbd_transfer_start(sc->sc_xfer[UKBD_INTR_DT_0]);
491 usbd_transfer_start(sc->sc_xfer[UKBD_INTR_DT_1]);
494 if (sc->sc_flags & UKBD_FLAG_POLLING)
495 ukbd_do_poll(sc, wait);
497 if (sc->sc_inputs == 0) {
500 c = sc->sc_input[sc->sc_inputhead];
502 ++(sc->sc_inputhead);
503 if (sc->sc_inputhead >= UKBD_IN_BUF_SIZE) {
504 sc->sc_inputhead = 0;
511 ukbd_interrupt(struct ukbd_softc *sc)
516 uint32_t now = sc->sc_time_ms;
524 if (sc->sc_ndata.keycode[0] == KEY_ERROR)
527 n_mod = sc->sc_ndata.modifiers;
528 o_mod = sc->sc_odata.modifiers;
529 if (n_mod != o_mod) {
530 for (i = 0; i < UKBD_NMOD; i++) {
531 if ((n_mod & ukbd_mods[i].mask) !=
532 (o_mod & ukbd_mods[i].mask)) {
533 ukbd_put_key(sc, ukbd_mods[i].key |
534 ((n_mod & ukbd_mods[i].mask) ?
535 KEY_PRESS : KEY_RELEASE));
539 /* Check for released keys. */
540 for (i = 0; i < UKBD_NKEYCODE; i++) {
541 key = sc->sc_odata.keycode[i];
545 for (j = 0; j < UKBD_NKEYCODE; j++) {
546 if (sc->sc_ndata.keycode[j] == 0) {
549 if (key == sc->sc_ndata.keycode[j]) {
553 ukbd_put_key(sc, key | KEY_RELEASE);
557 /* Check for pressed keys. */
558 for (i = 0; i < UKBD_NKEYCODE; i++) {
559 key = sc->sc_ndata.keycode[i];
563 sc->sc_ntime[i] = now + sc->sc_kbd.kb_delay1;
564 for (j = 0; j < UKBD_NKEYCODE; j++) {
565 if (sc->sc_odata.keycode[j] == 0) {
568 if (key == sc->sc_odata.keycode[j]) {
570 /* key is still pressed */
572 sc->sc_ntime[i] = sc->sc_otime[j];
573 dtime = (sc->sc_otime[j] - now);
576 /* time has not elapsed */
579 sc->sc_ntime[i] = now + sc->sc_kbd.kb_delay2;
583 if (j < UKBD_NKEYCODE) {
584 /* Old key repeating. */
585 sc->sc_delay = sc->sc_kbd.kb_delay2;
589 sc->sc_co_basetime = tvtosbt(ctv);
590 sc->sc_delay = sc->sc_kbd.kb_delay1;
592 ukbd_put_key(sc, key | KEY_PRESS);
595 * If any other key is presently down, force its repeat to be
596 * well in the future (100s). This makes the last key to be
597 * pressed do the autorepeat.
599 for (j = 0; j != UKBD_NKEYCODE; j++) {
601 sc->sc_ntime[j] = now + (100 * 1000);
606 sc->sc_odata = sc->sc_ndata;
608 memcpy(sc->sc_otime, sc->sc_ntime, sizeof(sc->sc_otime));
610 ukbd_event_keyinput(sc);
614 ukbd_event_keyinput(struct ukbd_softc *sc)
620 if ((sc->sc_flags & UKBD_FLAG_POLLING) != 0)
623 if (sc->sc_inputs == 0)
626 if (KBD_IS_ACTIVE(&sc->sc_kbd) &&
627 KBD_IS_BUSY(&sc->sc_kbd)) {
628 /* let the callback function process the input */
629 (sc->sc_kbd.kb_callback.kc_func) (&sc->sc_kbd, KBDIO_KEYINPUT,
630 sc->sc_kbd.kb_callback.kc_arg);
632 /* read and discard the input, no one is waiting for it */
634 c = ukbd_read_char(&sc->sc_kbd, 0);
635 } while (c != NOKEY);
640 ukbd_timeout(void *arg)
642 struct ukbd_softc *sc = arg;
646 sc->sc_time_ms += sc->sc_delay;
651 /* Make sure any leftover key events gets read out */
652 ukbd_event_keyinput(sc);
654 if (ukbd_any_key_pressed(sc) || (sc->sc_inputs != 0)) {
655 ukbd_start_timer(sc);
660 ukbd_apple_fn(uint8_t keycode) {
662 case 0x28: return 0x49; /* RETURN -> INSERT */
663 case 0x2a: return 0x4c; /* BACKSPACE -> DEL */
664 case 0x50: return 0x4a; /* LEFT ARROW -> HOME */
665 case 0x4f: return 0x4d; /* RIGHT ARROW -> END */
666 case 0x52: return 0x4b; /* UP ARROW -> PGUP */
667 case 0x51: return 0x4e; /* DOWN ARROW -> PGDN */
668 default: return keycode;
673 ukbd_apple_swap(uint8_t keycode) {
675 case 0x35: return 0x64;
676 case 0x64: return 0x35;
677 default: return keycode;
682 ukbd_intr_callback(struct usb_xfer *xfer, usb_error_t error)
684 struct ukbd_softc *sc = usbd_xfer_softc(xfer);
685 struct usb_page_cache *pc;
693 usbd_xfer_status(xfer, &len, NULL, NULL, NULL);
694 pc = usbd_xfer_get_frame(xfer, 0);
696 switch (USB_GET_STATE(xfer)) {
697 case USB_ST_TRANSFERRED:
698 DPRINTF("actlen=%d bytes\n", len);
701 DPRINTF("zero length data\n");
705 if (sc->sc_kbd_id != 0) {
706 /* check and remove HID ID byte */
707 usbd_copy_out(pc, 0, &id, 1);
711 DPRINTF("zero length data\n");
719 if (len > UKBD_BUFFER_SIZE)
720 len = UKBD_BUFFER_SIZE;
723 usbd_copy_out(pc, offset, sc->sc_buffer, len);
725 /* clear temporary storage */
726 memset(&sc->sc_ndata, 0, sizeof(sc->sc_ndata));
728 /* scan through HID data */
729 if ((sc->sc_flags & UKBD_FLAG_APPLE_EJECT) &&
730 (id == sc->sc_id_apple_eject)) {
731 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_apple_eject))
732 sc->sc_modifiers |= MOD_EJECT;
734 sc->sc_modifiers &= ~MOD_EJECT;
736 if ((sc->sc_flags & UKBD_FLAG_APPLE_FN) &&
737 (id == sc->sc_id_apple_fn)) {
738 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_apple_fn))
739 sc->sc_modifiers |= MOD_FN;
741 sc->sc_modifiers &= ~MOD_FN;
743 if ((sc->sc_flags & UKBD_FLAG_CTRL_L) &&
744 (id == sc->sc_id_ctrl_l)) {
745 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_ctrl_l))
746 sc-> sc_modifiers |= MOD_CONTROL_L;
748 sc-> sc_modifiers &= ~MOD_CONTROL_L;
750 if ((sc->sc_flags & UKBD_FLAG_CTRL_R) &&
751 (id == sc->sc_id_ctrl_r)) {
752 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_ctrl_r))
753 sc->sc_modifiers |= MOD_CONTROL_R;
755 sc->sc_modifiers &= ~MOD_CONTROL_R;
757 if ((sc->sc_flags & UKBD_FLAG_SHIFT_L) &&
758 (id == sc->sc_id_shift_l)) {
759 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_shift_l))
760 sc->sc_modifiers |= MOD_SHIFT_L;
762 sc->sc_modifiers &= ~MOD_SHIFT_L;
764 if ((sc->sc_flags & UKBD_FLAG_SHIFT_R) &&
765 (id == sc->sc_id_shift_r)) {
766 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_shift_r))
767 sc->sc_modifiers |= MOD_SHIFT_R;
769 sc->sc_modifiers &= ~MOD_SHIFT_R;
771 if ((sc->sc_flags & UKBD_FLAG_ALT_L) &&
772 (id == sc->sc_id_alt_l)) {
773 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_alt_l))
774 sc->sc_modifiers |= MOD_ALT_L;
776 sc->sc_modifiers &= ~MOD_ALT_L;
778 if ((sc->sc_flags & UKBD_FLAG_ALT_R) &&
779 (id == sc->sc_id_alt_r)) {
780 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_alt_r))
781 sc->sc_modifiers |= MOD_ALT_R;
783 sc->sc_modifiers &= ~MOD_ALT_R;
785 if ((sc->sc_flags & UKBD_FLAG_WIN_L) &&
786 (id == sc->sc_id_win_l)) {
787 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_win_l))
788 sc->sc_modifiers |= MOD_WIN_L;
790 sc->sc_modifiers &= ~MOD_WIN_L;
792 if ((sc->sc_flags & UKBD_FLAG_WIN_R) &&
793 (id == sc->sc_id_win_r)) {
794 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_win_r))
795 sc->sc_modifiers |= MOD_WIN_R;
797 sc->sc_modifiers &= ~MOD_WIN_R;
800 sc->sc_ndata.modifiers = sc->sc_modifiers;
802 if ((sc->sc_flags & UKBD_FLAG_EVENTS) &&
803 (id == sc->sc_id_events)) {
804 i = sc->sc_loc_events.count;
805 if (i > UKBD_NKEYCODE)
810 sc->sc_ndata.keycode[i] =
811 hid_get_data(sc->sc_buffer + i, len - i,
817 DPRINTF("modifiers = 0x%04x\n", (int)sc->sc_modifiers);
818 for (i = 0; i < UKBD_NKEYCODE; i++) {
819 if (sc->sc_ndata.keycode[i]) {
820 DPRINTF("[%d] = 0x%02x\n",
821 (int)i, (int)sc->sc_ndata.keycode[i]);
825 if (sc->sc_modifiers & MOD_FN) {
826 for (i = 0; i < UKBD_NKEYCODE; i++) {
827 sc->sc_ndata.keycode[i] =
828 ukbd_apple_fn(sc->sc_ndata.keycode[i]);
832 if (sc->sc_flags & UKBD_FLAG_APPLE_SWAP) {
833 for (i = 0; i < UKBD_NKEYCODE; i++) {
834 sc->sc_ndata.keycode[i] =
835 ukbd_apple_swap(sc->sc_ndata.keycode[i]);
841 if (ukbd_any_key_pressed(sc) != 0) {
842 ukbd_start_timer(sc);
847 if (sc->sc_inputs < UKBD_IN_BUF_FULL) {
848 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
849 usbd_transfer_submit(xfer);
851 DPRINTF("input queue is full!\n");
856 DPRINTF("error=%s\n", usbd_errstr(error));
858 if (error != USB_ERR_CANCELLED) {
859 /* try to clear stall first */
860 usbd_xfer_set_stall(xfer);
868 ukbd_set_leds_callback(struct usb_xfer *xfer, usb_error_t error)
870 struct ukbd_softc *sc = usbd_xfer_softc(xfer);
871 struct usb_device_request req;
872 struct usb_page_cache *pc;
884 switch (USB_GET_STATE(xfer)) {
885 case USB_ST_TRANSFERRED:
887 if (!(sc->sc_flags & UKBD_FLAG_SET_LEDS))
889 sc->sc_flags &= ~UKBD_FLAG_SET_LEDS;
891 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
892 req.bRequest = UR_SET_REPORT;
893 USETW2(req.wValue, UHID_OUTPUT_REPORT, 0);
894 req.wIndex[0] = sc->sc_iface_no;
898 memset(sc->sc_buffer, 0, UKBD_BUFFER_SIZE);
903 /* Assumption: All led bits must be in the same ID. */
905 if (sc->sc_flags & UKBD_FLAG_NUMLOCK) {
906 if (sc->sc_leds & NLKED) {
907 hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
908 &sc->sc_loc_numlock, 1);
910 id = sc->sc_id_numlock;
914 if (sc->sc_flags & UKBD_FLAG_SCROLLLOCK) {
915 if (sc->sc_leds & SLKED) {
916 hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
917 &sc->sc_loc_scrolllock, 1);
919 id = sc->sc_id_scrolllock;
923 if (sc->sc_flags & UKBD_FLAG_CAPSLOCK) {
924 if (sc->sc_leds & CLKED) {
925 hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
926 &sc->sc_loc_capslock, 1);
928 id = sc->sc_id_capslock;
932 /* if no leds, nothing to do */
937 if (sc->sc_evdev != NULL)
938 evdev_push_leds(sc->sc_evdev, sc->sc_leds);
941 /* range check output report length */
942 len = sc->sc_led_size;
943 if (len > (UKBD_BUFFER_SIZE - 1))
944 len = (UKBD_BUFFER_SIZE - 1);
946 /* check if we need to prefix an ID byte */
947 sc->sc_buffer[0] = id;
949 pc = usbd_xfer_get_frame(xfer, 1);
952 usbd_copy_in(pc, 0, sc->sc_buffer, len);
954 usbd_copy_in(pc, 0, sc->sc_buffer + 1, len);
956 req.wLength[0] = len;
957 usbd_xfer_set_frame_len(xfer, 1, len);
959 DPRINTF("len=%d, id=%d\n", len, id);
961 /* setup control request last */
962 pc = usbd_xfer_get_frame(xfer, 0);
963 usbd_copy_in(pc, 0, &req, sizeof(req));
964 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
966 /* start data transfer */
967 usbd_xfer_set_frames(xfer, 2);
968 usbd_transfer_submit(xfer);
972 DPRINTFN(1, "error=%s\n", usbd_errstr(error));
977 static const struct usb_config ukbd_config[UKBD_N_TRANSFER] = {
980 .type = UE_INTERRUPT,
981 .endpoint = UE_ADDR_ANY,
982 .direction = UE_DIR_IN,
983 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
984 .bufsize = 0, /* use wMaxPacketSize */
985 .callback = &ukbd_intr_callback,
989 .type = UE_INTERRUPT,
990 .endpoint = UE_ADDR_ANY,
991 .direction = UE_DIR_IN,
992 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
993 .bufsize = 0, /* use wMaxPacketSize */
994 .callback = &ukbd_intr_callback,
999 .endpoint = 0x00, /* Control pipe */
1000 .direction = UE_DIR_ANY,
1001 .bufsize = sizeof(struct usb_device_request) + UKBD_BUFFER_SIZE,
1002 .callback = &ukbd_set_leds_callback,
1003 .timeout = 1000, /* 1 second */
1007 /* A match on these entries will load ukbd */
1008 static const STRUCT_USB_HOST_ID __used ukbd_devs[] = {
1009 {USB_IFACE_CLASS(UICLASS_HID),
1010 USB_IFACE_SUBCLASS(UISUBCLASS_BOOT),
1011 USB_IFACE_PROTOCOL(UIPROTO_BOOT_KEYBOARD),},
1015 ukbd_probe(device_t dev)
1017 keyboard_switch_t *sw = kbd_get_switch(UKBD_DRIVER_NAME);
1018 struct usb_attach_arg *uaa = device_get_ivars(dev);
1029 if (uaa->usb_mode != USB_MODE_HOST) {
1033 if (uaa->info.bInterfaceClass != UICLASS_HID)
1036 if (usb_test_quirk(uaa, UQ_KBD_IGNORE))
1039 if ((uaa->info.bInterfaceSubClass == UISUBCLASS_BOOT) &&
1040 (uaa->info.bInterfaceProtocol == UIPROTO_BOOT_KEYBOARD))
1041 return (BUS_PROBE_DEFAULT);
1043 error = usbd_req_get_hid_desc(uaa->device, NULL,
1044 &d_ptr, &d_len, M_TEMP, uaa->info.bIfaceIndex);
1049 if (hid_is_keyboard(d_ptr, d_len)) {
1050 if (hid_is_mouse(d_ptr, d_len)) {
1052 * NOTE: We currently don't support USB mouse
1053 * and USB keyboard on the same USB endpoint.
1054 * Let "ums" driver win.
1058 error = BUS_PROBE_DEFAULT;
1063 free(d_ptr, M_TEMP);
1068 ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len)
1072 /* reset detected bits */
1073 sc->sc_flags &= ~UKBD_FLAG_HID_MASK;
1075 /* check if there is an ID byte */
1076 sc->sc_kbd_size = hid_report_size(ptr, len,
1077 hid_input, &sc->sc_kbd_id);
1079 /* investigate if this is an Apple Keyboard */
1080 if (hid_locate(ptr, len,
1081 HID_USAGE2(HUP_CONSUMER, HUG_APPLE_EJECT),
1082 hid_input, 0, &sc->sc_loc_apple_eject, &flags,
1083 &sc->sc_id_apple_eject)) {
1084 if (flags & HIO_VARIABLE)
1085 sc->sc_flags |= UKBD_FLAG_APPLE_EJECT |
1086 UKBD_FLAG_APPLE_SWAP;
1087 DPRINTFN(1, "Found Apple eject-key\n");
1089 if (hid_locate(ptr, len,
1090 HID_USAGE2(0xFFFF, 0x0003),
1091 hid_input, 0, &sc->sc_loc_apple_fn, &flags,
1092 &sc->sc_id_apple_fn)) {
1093 if (flags & HIO_VARIABLE)
1094 sc->sc_flags |= UKBD_FLAG_APPLE_FN;
1095 DPRINTFN(1, "Found Apple FN-key\n");
1097 /* figure out some keys */
1098 if (hid_locate(ptr, len,
1099 HID_USAGE2(HUP_KEYBOARD, 0xE0),
1100 hid_input, 0, &sc->sc_loc_ctrl_l, &flags,
1101 &sc->sc_id_ctrl_l)) {
1102 if (flags & HIO_VARIABLE)
1103 sc->sc_flags |= UKBD_FLAG_CTRL_L;
1104 DPRINTFN(1, "Found left control\n");
1106 if (hid_locate(ptr, len,
1107 HID_USAGE2(HUP_KEYBOARD, 0xE4),
1108 hid_input, 0, &sc->sc_loc_ctrl_r, &flags,
1109 &sc->sc_id_ctrl_r)) {
1110 if (flags & HIO_VARIABLE)
1111 sc->sc_flags |= UKBD_FLAG_CTRL_R;
1112 DPRINTFN(1, "Found right control\n");
1114 if (hid_locate(ptr, len,
1115 HID_USAGE2(HUP_KEYBOARD, 0xE1),
1116 hid_input, 0, &sc->sc_loc_shift_l, &flags,
1117 &sc->sc_id_shift_l)) {
1118 if (flags & HIO_VARIABLE)
1119 sc->sc_flags |= UKBD_FLAG_SHIFT_L;
1120 DPRINTFN(1, "Found left shift\n");
1122 if (hid_locate(ptr, len,
1123 HID_USAGE2(HUP_KEYBOARD, 0xE5),
1124 hid_input, 0, &sc->sc_loc_shift_r, &flags,
1125 &sc->sc_id_shift_r)) {
1126 if (flags & HIO_VARIABLE)
1127 sc->sc_flags |= UKBD_FLAG_SHIFT_R;
1128 DPRINTFN(1, "Found right shift\n");
1130 if (hid_locate(ptr, len,
1131 HID_USAGE2(HUP_KEYBOARD, 0xE2),
1132 hid_input, 0, &sc->sc_loc_alt_l, &flags,
1133 &sc->sc_id_alt_l)) {
1134 if (flags & HIO_VARIABLE)
1135 sc->sc_flags |= UKBD_FLAG_ALT_L;
1136 DPRINTFN(1, "Found left alt\n");
1138 if (hid_locate(ptr, len,
1139 HID_USAGE2(HUP_KEYBOARD, 0xE6),
1140 hid_input, 0, &sc->sc_loc_alt_r, &flags,
1141 &sc->sc_id_alt_r)) {
1142 if (flags & HIO_VARIABLE)
1143 sc->sc_flags |= UKBD_FLAG_ALT_R;
1144 DPRINTFN(1, "Found right alt\n");
1146 if (hid_locate(ptr, len,
1147 HID_USAGE2(HUP_KEYBOARD, 0xE3),
1148 hid_input, 0, &sc->sc_loc_win_l, &flags,
1149 &sc->sc_id_win_l)) {
1150 if (flags & HIO_VARIABLE)
1151 sc->sc_flags |= UKBD_FLAG_WIN_L;
1152 DPRINTFN(1, "Found left GUI\n");
1154 if (hid_locate(ptr, len,
1155 HID_USAGE2(HUP_KEYBOARD, 0xE7),
1156 hid_input, 0, &sc->sc_loc_win_r, &flags,
1157 &sc->sc_id_win_r)) {
1158 if (flags & HIO_VARIABLE)
1159 sc->sc_flags |= UKBD_FLAG_WIN_R;
1160 DPRINTFN(1, "Found right GUI\n");
1162 /* figure out event buffer */
1163 if (hid_locate(ptr, len,
1164 HID_USAGE2(HUP_KEYBOARD, 0x00),
1165 hid_input, 0, &sc->sc_loc_events, &flags,
1166 &sc->sc_id_events)) {
1167 if (flags & HIO_VARIABLE) {
1168 DPRINTFN(1, "Ignoring keyboard event control\n");
1170 sc->sc_flags |= UKBD_FLAG_EVENTS;
1171 DPRINTFN(1, "Found keyboard event array\n");
1175 /* figure out leds on keyboard */
1176 sc->sc_led_size = hid_report_size(ptr, len,
1179 if (hid_locate(ptr, len,
1180 HID_USAGE2(HUP_LEDS, 0x01),
1181 hid_output, 0, &sc->sc_loc_numlock, &flags,
1182 &sc->sc_id_numlock)) {
1183 if (flags & HIO_VARIABLE)
1184 sc->sc_flags |= UKBD_FLAG_NUMLOCK;
1185 DPRINTFN(1, "Found keyboard numlock\n");
1187 if (hid_locate(ptr, len,
1188 HID_USAGE2(HUP_LEDS, 0x02),
1189 hid_output, 0, &sc->sc_loc_capslock, &flags,
1190 &sc->sc_id_capslock)) {
1191 if (flags & HIO_VARIABLE)
1192 sc->sc_flags |= UKBD_FLAG_CAPSLOCK;
1193 DPRINTFN(1, "Found keyboard capslock\n");
1195 if (hid_locate(ptr, len,
1196 HID_USAGE2(HUP_LEDS, 0x03),
1197 hid_output, 0, &sc->sc_loc_scrolllock, &flags,
1198 &sc->sc_id_scrolllock)) {
1199 if (flags & HIO_VARIABLE)
1200 sc->sc_flags |= UKBD_FLAG_SCROLLLOCK;
1201 DPRINTFN(1, "Found keyboard scrolllock\n");
1206 ukbd_attach(device_t dev)
1208 struct ukbd_softc *sc = device_get_softc(dev);
1209 struct usb_attach_arg *uaa = device_get_ivars(dev);
1210 int unit = device_get_unit(dev);
1211 keyboard_t *kbd = &sc->sc_kbd;
1212 void *hid_ptr = NULL;
1216 #ifdef EVDEV_SUPPORT
1217 struct evdev_dev *evdev;
1225 kbd_init_struct(kbd, UKBD_DRIVER_NAME, KB_OTHER, unit, 0, 0, 0);
1227 kbd->kb_data = (void *)sc;
1229 device_set_usb_desc(dev);
1231 sc->sc_udev = uaa->device;
1232 sc->sc_iface = uaa->iface;
1233 sc->sc_iface_index = uaa->info.bIfaceIndex;
1234 sc->sc_iface_no = uaa->info.bIfaceNum;
1235 sc->sc_mode = K_XLATE;
1237 usb_callout_init_mtx(&sc->sc_callout, &Giant, 0);
1239 #ifdef UKBD_NO_POLLING
1240 err = usbd_transfer_setup(uaa->device,
1241 &uaa->info.bIfaceIndex, sc->sc_xfer, ukbd_config,
1242 UKBD_N_TRANSFER, sc, &Giant);
1245 * Setup the UKBD USB transfers one by one, so they are memory
1246 * independent which allows for handling panics triggered by
1247 * the keyboard driver itself, typically via CTRL+ALT+ESC
1248 * sequences. Or if the USB keyboard driver was processing a
1249 * key at the moment of panic.
1251 for (n = 0; n != UKBD_N_TRANSFER; n++) {
1252 err = usbd_transfer_setup(uaa->device,
1253 &uaa->info.bIfaceIndex, sc->sc_xfer + n, ukbd_config + n,
1261 DPRINTF("error=%s\n", usbd_errstr(err));
1264 /* setup default keyboard maps */
1266 sc->sc_keymap = key_map;
1267 sc->sc_accmap = accent_map;
1268 for (n = 0; n < UKBD_NFKEY; n++) {
1269 sc->sc_fkeymap[n] = fkey_tab[n];
1272 kbd_set_maps(kbd, &sc->sc_keymap, &sc->sc_accmap,
1273 sc->sc_fkeymap, UKBD_NFKEY);
1275 KBD_FOUND_DEVICE(kbd);
1277 ukbd_clear_state(kbd);
1280 * FIXME: set the initial value for lock keys in "sc_state"
1281 * according to the BIOS data?
1283 KBD_PROBE_DONE(kbd);
1285 /* get HID descriptor */
1286 err = usbd_req_get_hid_desc(uaa->device, NULL, &hid_ptr,
1287 &hid_len, M_TEMP, uaa->info.bIfaceIndex);
1290 DPRINTF("Parsing HID descriptor of %d bytes\n",
1293 ukbd_parse_hid(sc, hid_ptr, hid_len);
1295 free(hid_ptr, M_TEMP);
1298 /* check if we should use the boot protocol */
1299 if (usb_test_quirk(uaa, UQ_KBD_BOOTPROTO) ||
1300 (err != 0) || (!(sc->sc_flags & UKBD_FLAG_EVENTS))) {
1302 DPRINTF("Forcing boot protocol\n");
1304 err = usbd_req_set_protocol(sc->sc_udev, NULL,
1305 sc->sc_iface_index, 0);
1308 DPRINTF("Set protocol error=%s (ignored)\n",
1312 ukbd_parse_hid(sc, ukbd_boot_desc, sizeof(ukbd_boot_desc));
1315 /* ignore if SETIDLE fails, hence it is not crucial */
1316 usbd_req_set_idle(sc->sc_udev, NULL, sc->sc_iface_index, 0, 0);
1318 ukbd_ioctl(kbd, KDSETLED, (caddr_t)&sc->sc_state);
1322 if (kbd_register(kbd) < 0) {
1325 KBD_CONFIG_DONE(kbd);
1329 #ifdef KBD_INSTALL_CDEV
1330 if (kbd_attach(kbd)) {
1335 #ifdef EVDEV_SUPPORT
1336 evdev = evdev_alloc();
1337 evdev_set_name(evdev, device_get_desc(dev));
1338 evdev_set_phys(evdev, device_get_nameunit(dev));
1339 evdev_set_id(evdev, BUS_USB, uaa->info.idVendor,
1340 uaa->info.idProduct, 0);
1341 evdev_set_serial(evdev, usb_get_serial(uaa->device));
1342 evdev_set_methods(evdev, kbd, &ukbd_evdev_methods);
1343 evdev_support_event(evdev, EV_SYN);
1344 evdev_support_event(evdev, EV_KEY);
1345 if (sc->sc_flags & (UKBD_FLAG_NUMLOCK | UKBD_FLAG_CAPSLOCK |
1346 UKBD_FLAG_SCROLLLOCK))
1347 evdev_support_event(evdev, EV_LED);
1348 evdev_support_event(evdev, EV_REP);
1350 for (i = 0x00; i <= 0xFF; i++)
1351 evdev_support_key(evdev, evdev_hid2key(i));
1352 if (sc->sc_flags & UKBD_FLAG_NUMLOCK)
1353 evdev_support_led(evdev, LED_NUML);
1354 if (sc->sc_flags & UKBD_FLAG_CAPSLOCK)
1355 evdev_support_led(evdev, LED_CAPSL);
1356 if (sc->sc_flags & UKBD_FLAG_SCROLLLOCK)
1357 evdev_support_led(evdev, LED_SCROLLL);
1359 if (evdev_register(evdev))
1362 sc->sc_evdev = evdev;
1365 sc->sc_flags |= UKBD_FLAG_ATTACHED;
1368 genkbd_diag(kbd, bootverbose);
1372 /* check for polling rate override */
1373 rate = ukbd_pollrate;
1380 /* set new polling interval in ms */
1381 usbd_xfer_set_interval(sc->sc_xfer[UKBD_INTR_DT_0], rate);
1382 usbd_xfer_set_interval(sc->sc_xfer[UKBD_INTR_DT_1], rate);
1385 /* start the keyboard */
1386 usbd_transfer_start(sc->sc_xfer[UKBD_INTR_DT_0]);
1387 usbd_transfer_start(sc->sc_xfer[UKBD_INTR_DT_1]);
1389 return (0); /* success */
1393 return (ENXIO); /* error */
1397 ukbd_detach(device_t dev)
1399 struct ukbd_softc *sc = device_get_softc(dev);
1406 sc->sc_flags |= UKBD_FLAG_GONE;
1408 usb_callout_stop(&sc->sc_callout);
1410 /* kill any stuck keys */
1411 if (sc->sc_flags & UKBD_FLAG_ATTACHED) {
1412 /* stop receiving events from the USB keyboard */
1413 usbd_transfer_stop(sc->sc_xfer[UKBD_INTR_DT_0]);
1414 usbd_transfer_stop(sc->sc_xfer[UKBD_INTR_DT_1]);
1416 /* release all leftover keys, if any */
1417 memset(&sc->sc_ndata, 0, sizeof(sc->sc_ndata));
1419 /* process releasing of all keys */
1423 ukbd_disable(&sc->sc_kbd);
1425 #ifdef KBD_INSTALL_CDEV
1426 if (sc->sc_flags & UKBD_FLAG_ATTACHED) {
1427 error = kbd_detach(&sc->sc_kbd);
1429 /* usb attach cannot return an error */
1430 device_printf(dev, "WARNING: kbd_detach() "
1431 "returned non-zero! (ignored)\n");
1436 #ifdef EVDEV_SUPPORT
1437 evdev_free(sc->sc_evdev);
1440 if (KBD_IS_CONFIGURED(&sc->sc_kbd)) {
1441 error = kbd_unregister(&sc->sc_kbd);
1443 /* usb attach cannot return an error */
1444 device_printf(dev, "WARNING: kbd_unregister() "
1445 "returned non-zero! (ignored)\n");
1448 sc->sc_kbd.kb_flags = 0;
1450 usbd_transfer_unsetup(sc->sc_xfer, UKBD_N_TRANSFER);
1452 usb_callout_drain(&sc->sc_callout);
1454 DPRINTF("%s: disconnected\n",
1455 device_get_nameunit(dev));
1461 ukbd_resume(device_t dev)
1463 struct ukbd_softc *sc = device_get_softc(dev);
1467 ukbd_clear_state(&sc->sc_kbd);
1472 /* early keyboard probe, not supported */
1474 ukbd_configure(int flags)
1479 /* detect a keyboard, not used */
1481 ukbd__probe(int unit, void *arg, int flags)
1486 /* reset and initialize the device, not used */
1488 ukbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
1493 /* test the interface to the device, not used */
1495 ukbd_test_if(keyboard_t *kbd)
1500 /* finish using this keyboard, not used */
1502 ukbd_term(keyboard_t *kbd)
1507 /* keyboard interrupt routine, not used */
1509 ukbd_intr(keyboard_t *kbd, void *arg)
1514 /* lock the access to the keyboard, not used */
1516 ukbd_lock(keyboard_t *kbd, int lock)
1522 * Enable the access to the device; until this function is called,
1523 * the client cannot read from the keyboard.
1526 ukbd_enable(keyboard_t *kbd)
1536 /* disallow the access to the device */
1538 ukbd_disable(keyboard_t *kbd)
1542 KBD_DEACTIVATE(kbd);
1548 /* check if data is waiting */
1549 /* Currently unused. */
1551 ukbd_check(keyboard_t *kbd)
1553 struct ukbd_softc *sc = kbd->kb_data;
1557 if (!KBD_IS_ACTIVE(kbd))
1560 if (sc->sc_flags & UKBD_FLAG_POLLING)
1561 ukbd_do_poll(sc, 0);
1563 #ifdef UKBD_EMULATE_ATSCANCODE
1564 if (sc->sc_buffered_char[0]) {
1568 if (sc->sc_inputs > 0) {
1574 /* check if char is waiting */
1576 ukbd_check_char_locked(keyboard_t *kbd)
1578 struct ukbd_softc *sc = kbd->kb_data;
1582 if (!KBD_IS_ACTIVE(kbd))
1585 if ((sc->sc_composed_char > 0) &&
1586 (!(sc->sc_flags & UKBD_FLAG_COMPOSE))) {
1589 return (ukbd_check(kbd));
1593 ukbd_check_char(keyboard_t *kbd)
1598 result = ukbd_check_char_locked(kbd);
1604 /* read one byte from the keyboard if it's allowed */
1605 /* Currently unused. */
1607 ukbd_read(keyboard_t *kbd, int wait)
1609 struct ukbd_softc *sc = kbd->kb_data;
1611 #ifdef UKBD_EMULATE_ATSCANCODE
1619 if (!KBD_IS_ACTIVE(kbd))
1622 #ifdef UKBD_EMULATE_ATSCANCODE
1623 if (sc->sc_buffered_char[0]) {
1624 scancode = sc->sc_buffered_char[0];
1625 if (scancode & SCAN_PREFIX) {
1626 sc->sc_buffered_char[0] &= ~SCAN_PREFIX;
1627 return ((scancode & SCAN_PREFIX_E0) ? 0xe0 : 0xe1);
1629 sc->sc_buffered_char[0] = sc->sc_buffered_char[1];
1630 sc->sc_buffered_char[1] = 0;
1633 #endif /* UKBD_EMULATE_ATSCANCODE */
1636 usbcode = ukbd_get_key(sc, (wait == FALSE) ? 0 : 1);
1637 if (!KBD_IS_ACTIVE(kbd) || (usbcode == -1))
1642 #ifdef UKBD_EMULATE_ATSCANCODE
1643 keycode = ukbd_atkeycode(usbcode, sc->sc_ndata.modifiers);
1644 if (keycode == NN) {
1647 return (ukbd_key2scan(sc, keycode, sc->sc_ndata.modifiers,
1648 (usbcode & KEY_RELEASE)));
1649 #else /* !UKBD_EMULATE_ATSCANCODE */
1651 #endif /* UKBD_EMULATE_ATSCANCODE */
1654 /* read char from the keyboard */
1656 ukbd_read_char_locked(keyboard_t *kbd, int wait)
1658 struct ukbd_softc *sc = kbd->kb_data;
1662 #ifdef UKBD_EMULATE_ATSCANCODE
1668 if (!KBD_IS_ACTIVE(kbd))
1673 /* do we have a composed char to return ? */
1675 if ((sc->sc_composed_char > 0) &&
1676 (!(sc->sc_flags & UKBD_FLAG_COMPOSE))) {
1678 action = sc->sc_composed_char;
1679 sc->sc_composed_char = 0;
1681 if (action > 0xFF) {
1686 #ifdef UKBD_EMULATE_ATSCANCODE
1688 /* do we have a pending raw scan code? */
1690 if (sc->sc_mode == K_RAW) {
1691 scancode = sc->sc_buffered_char[0];
1693 if (scancode & SCAN_PREFIX) {
1694 sc->sc_buffered_char[0] = (scancode & ~SCAN_PREFIX);
1695 return ((scancode & SCAN_PREFIX_E0) ? 0xe0 : 0xe1);
1697 sc->sc_buffered_char[0] = sc->sc_buffered_char[1];
1698 sc->sc_buffered_char[1] = 0;
1702 #endif /* UKBD_EMULATE_ATSCANCODE */
1704 /* see if there is something in the keyboard port */
1706 usbcode = ukbd_get_key(sc, (wait == FALSE) ? 0 : 1);
1707 if (usbcode == -1) {
1712 #ifdef UKBD_EMULATE_ATSCANCODE
1713 /* USB key index -> key code -> AT scan code */
1714 keycode = ukbd_atkeycode(usbcode, sc->sc_ndata.modifiers);
1715 if (keycode == NN) {
1718 /* return an AT scan code for the K_RAW mode */
1719 if (sc->sc_mode == K_RAW) {
1720 return (ukbd_key2scan(sc, keycode, sc->sc_ndata.modifiers,
1721 (usbcode & KEY_RELEASE)));
1723 #else /* !UKBD_EMULATE_ATSCANCODE */
1725 /* return the byte as is for the K_RAW mode */
1726 if (sc->sc_mode == K_RAW) {
1729 /* USB key index -> key code */
1730 keycode = ukbd_trtab[KEY_INDEX(usbcode)];
1731 if (keycode == NN) {
1734 #endif /* UKBD_EMULATE_ATSCANCODE */
1737 case 0x38: /* left alt (compose key) */
1738 if (usbcode & KEY_RELEASE) {
1739 if (sc->sc_flags & UKBD_FLAG_COMPOSE) {
1740 sc->sc_flags &= ~UKBD_FLAG_COMPOSE;
1742 if (sc->sc_composed_char > 0xFF) {
1743 sc->sc_composed_char = 0;
1747 if (!(sc->sc_flags & UKBD_FLAG_COMPOSE)) {
1748 sc->sc_flags |= UKBD_FLAG_COMPOSE;
1749 sc->sc_composed_char = 0;
1755 /* return the key code in the K_CODE mode */
1756 if (usbcode & KEY_RELEASE) {
1757 keycode |= SCAN_RELEASE;
1759 if (sc->sc_mode == K_CODE) {
1762 /* compose a character code */
1763 if (sc->sc_flags & UKBD_FLAG_COMPOSE) {
1765 /* key pressed, process it */
1768 case 0x49: /* keypad 7,8,9 */
1769 sc->sc_composed_char *= 10;
1770 sc->sc_composed_char += keycode - 0x40;
1771 goto check_composed;
1775 case 0x4D: /* keypad 4,5,6 */
1776 sc->sc_composed_char *= 10;
1777 sc->sc_composed_char += keycode - 0x47;
1778 goto check_composed;
1782 case 0x51: /* keypad 1,2,3 */
1783 sc->sc_composed_char *= 10;
1784 sc->sc_composed_char += keycode - 0x4E;
1785 goto check_composed;
1787 case 0x52: /* keypad 0 */
1788 sc->sc_composed_char *= 10;
1789 goto check_composed;
1791 /* key released, no interest here */
1792 case SCAN_RELEASE | 0x47:
1793 case SCAN_RELEASE | 0x48:
1794 case SCAN_RELEASE | 0x49: /* keypad 7,8,9 */
1795 case SCAN_RELEASE | 0x4B:
1796 case SCAN_RELEASE | 0x4C:
1797 case SCAN_RELEASE | 0x4D: /* keypad 4,5,6 */
1798 case SCAN_RELEASE | 0x4F:
1799 case SCAN_RELEASE | 0x50:
1800 case SCAN_RELEASE | 0x51: /* keypad 1,2,3 */
1801 case SCAN_RELEASE | 0x52: /* keypad 0 */
1804 case 0x38: /* left alt key */
1808 if (sc->sc_composed_char > 0) {
1809 sc->sc_flags &= ~UKBD_FLAG_COMPOSE;
1810 sc->sc_composed_char = 0;
1816 /* keycode to key action */
1817 action = genkbd_keyaction(kbd, SCAN_CHAR(keycode),
1818 (keycode & SCAN_RELEASE),
1819 &sc->sc_state, &sc->sc_accents);
1820 if (action == NOKEY) {
1827 if (sc->sc_composed_char <= 0xFF) {
1834 /* Currently wait is always false. */
1836 ukbd_read_char(keyboard_t *kbd, int wait)
1841 keycode = ukbd_read_char_locked(kbd, wait);
1847 /* some useful control functions */
1849 ukbd_ioctl_locked(keyboard_t *kbd, u_long cmd, caddr_t arg)
1851 struct ukbd_softc *sc = kbd->kb_data;
1853 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1854 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1862 case KDGKBMODE: /* get keyboard mode */
1863 *(int *)arg = sc->sc_mode;
1865 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1866 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1868 ival = IOCPARM_IVAL(arg);
1869 arg = (caddr_t)&ival;
1872 case KDSKBMODE: /* set keyboard mode */
1873 switch (*(int *)arg) {
1875 if (sc->sc_mode != K_XLATE) {
1876 /* make lock key state and LED state match */
1877 sc->sc_state &= ~LOCK_MASK;
1878 sc->sc_state |= KBD_LED_VAL(kbd);
1883 if (sc->sc_mode != *(int *)arg) {
1884 if ((sc->sc_flags & UKBD_FLAG_POLLING) == 0)
1885 ukbd_clear_state(kbd);
1886 sc->sc_mode = *(int *)arg;
1894 case KDGETLED: /* get keyboard LED */
1895 *(int *)arg = KBD_LED_VAL(kbd);
1897 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1898 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1900 ival = IOCPARM_IVAL(arg);
1901 arg = (caddr_t)&ival;
1904 case KDSETLED: /* set keyboard LED */
1905 /* NOTE: lock key state in "sc_state" won't be changed */
1906 if (*(int *)arg & ~LOCK_MASK)
1911 /* replace CAPS LED with ALTGR LED for ALTGR keyboards */
1912 if (sc->sc_mode == K_XLATE &&
1913 kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
1919 if (KBD_HAS_DEVICE(kbd))
1920 ukbd_set_leds(sc, i);
1922 KBD_LED_VAL(kbd) = *(int *)arg;
1924 case KDGKBSTATE: /* get lock key state */
1925 *(int *)arg = sc->sc_state & LOCK_MASK;
1927 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1928 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1930 ival = IOCPARM_IVAL(arg);
1931 arg = (caddr_t)&ival;
1934 case KDSKBSTATE: /* set lock key state */
1935 if (*(int *)arg & ~LOCK_MASK) {
1938 sc->sc_state &= ~LOCK_MASK;
1939 sc->sc_state |= *(int *)arg;
1941 /* set LEDs and quit */
1942 return (ukbd_ioctl(kbd, KDSETLED, arg));
1944 case KDSETREPEAT: /* set keyboard repeat rate (new
1946 if (!KBD_HAS_DEVICE(kbd)) {
1950 * Convert negative, zero and tiny args to the same limits
1951 * as atkbd. We could support delays of 1 msec, but
1952 * anything much shorter than the shortest atkbd value
1953 * of 250.34 is almost unusable as well as incompatible.
1955 kbd->kb_delay1 = imax(((int *)arg)[0], 250);
1956 kbd->kb_delay2 = imax(((int *)arg)[1], 34);
1957 #ifdef EVDEV_SUPPORT
1958 if (sc->sc_evdev != NULL)
1959 evdev_push_repeats(sc->sc_evdev, kbd);
1963 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1964 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1966 ival = IOCPARM_IVAL(arg);
1967 arg = (caddr_t)&ival;
1970 case KDSETRAD: /* set keyboard repeat rate (old
1972 return (ukbd_set_typematic(kbd, *(int *)arg));
1974 case PIO_KEYMAP: /* set keyboard translation table */
1975 case OPIO_KEYMAP: /* set keyboard translation table
1977 case PIO_KEYMAPENT: /* set keyboard translation table
1979 case PIO_DEADKEYMAP: /* set accent key translation table */
1983 return (genkbd_commonioctl(kbd, cmd, arg));
1990 ukbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
1995 * XXX Check if someone is calling us from a critical section:
1997 if (curthread->td_critnest != 0)
2001 * XXX KDGKBSTATE, KDSKBSTATE and KDSETLED can be called from any
2002 * context where printf(9) can be called, which among other things
2003 * includes interrupt filters and threads with any kinds of locks
2004 * already held. For this reason it would be dangerous to acquire
2005 * the Giant here unconditionally. On the other hand we have to
2006 * have it to handle the ioctl.
2007 * So we make our best effort to auto-detect whether we can grab
2008 * the Giant or not. Blame syscons(4) for this.
2014 if (!mtx_owned(&Giant) && !USB_IN_POLLING_MODE_FUNC())
2015 return (EDEADLK); /* best I could come up with */
2019 result = ukbd_ioctl_locked(kbd, cmd, arg);
2026 /* clear the internal state of the keyboard */
2028 ukbd_clear_state(keyboard_t *kbd)
2030 struct ukbd_softc *sc = kbd->kb_data;
2034 sc->sc_flags &= ~(UKBD_FLAG_COMPOSE | UKBD_FLAG_POLLING);
2035 sc->sc_state &= LOCK_MASK; /* preserve locking key state */
2037 sc->sc_composed_char = 0;
2038 #ifdef UKBD_EMULATE_ATSCANCODE
2039 sc->sc_buffered_char[0] = 0;
2040 sc->sc_buffered_char[1] = 0;
2042 memset(&sc->sc_ndata, 0, sizeof(sc->sc_ndata));
2043 memset(&sc->sc_odata, 0, sizeof(sc->sc_odata));
2044 memset(&sc->sc_ntime, 0, sizeof(sc->sc_ntime));
2045 memset(&sc->sc_otime, 0, sizeof(sc->sc_otime));
2048 /* save the internal state, not used */
2050 ukbd_get_state(keyboard_t *kbd, void *buf, size_t len)
2052 return (len == 0) ? 1 : -1;
2055 /* set the internal state, not used */
2057 ukbd_set_state(keyboard_t *kbd, void *buf, size_t len)
2063 ukbd_poll(keyboard_t *kbd, int on)
2065 struct ukbd_softc *sc = kbd->kb_data;
2069 * Keep a reference count on polling to allow recursive
2070 * cngrab() during a panic for example.
2074 else if (sc->sc_polling > 0)
2077 if (sc->sc_polling != 0) {
2078 sc->sc_flags |= UKBD_FLAG_POLLING;
2079 sc->sc_poll_thread = curthread;
2081 sc->sc_flags &= ~UKBD_FLAG_POLLING;
2089 /* local functions */
2092 ukbd_set_leds(struct ukbd_softc *sc, uint8_t leds)
2096 DPRINTF("leds=0x%02x\n", leds);
2099 sc->sc_flags |= UKBD_FLAG_SET_LEDS;
2101 /* start transfer, if not already started */
2103 usbd_transfer_start(sc->sc_xfer[UKBD_CTRL_LED]);
2107 ukbd_set_typematic(keyboard_t *kbd, int code)
2109 #ifdef EVDEV_SUPPORT
2110 struct ukbd_softc *sc = kbd->kb_data;
2112 static const int delays[] = {250, 500, 750, 1000};
2113 static const int rates[] = {34, 38, 42, 46, 50, 55, 59, 63,
2114 68, 76, 84, 92, 100, 110, 118, 126,
2115 136, 152, 168, 184, 200, 220, 236, 252,
2116 272, 304, 336, 368, 400, 440, 472, 504};
2121 kbd->kb_delay1 = delays[(code >> 5) & 3];
2122 kbd->kb_delay2 = rates[code & 0x1f];
2123 #ifdef EVDEV_SUPPORT
2124 if (sc->sc_evdev != NULL)
2125 evdev_push_repeats(sc->sc_evdev, kbd);
2130 #ifdef UKBD_EMULATE_ATSCANCODE
2132 ukbd_atkeycode(int usbcode, int shift)
2136 keycode = ukbd_trtab[KEY_INDEX(usbcode)];
2138 * Translate Alt-PrintScreen to SysRq.
2140 * Some or all AT keyboards connected through USB have already
2141 * mapped Alted PrintScreens to an unusual usbcode (0x8a).
2142 * ukbd_trtab translates this to 0x7e, and key2scan() would
2143 * translate that to 0x79 (Intl' 4). Assume that if we have
2144 * an Alted 0x7e here then it actually is an Alted PrintScreen.
2146 * The usual usbcode for all PrintScreens is 0x46. ukbd_trtab
2147 * translates this to 0x5c, so the Alt check to classify 0x5c
2150 if ((keycode == 0x5c || keycode == 0x7e) &&
2151 shift & (MOD_ALT_L | MOD_ALT_R))
2157 ukbd_key2scan(struct ukbd_softc *sc, int code, int shift, int up)
2159 static const int scan[] = {
2165 0x137, /* PrintScreen */
2175 0x151, /* PageDown */
2178 0x146, /* Pause/Break */
2179 0x15b, /* Win_L(Super_L) */
2180 0x15c, /* Win_R(Super_R) */
2181 0x15d, /* Application(Menu) */
2183 /* SUN TYPE 6 USB KEYBOARD */
2184 0x168, /* Sun Type 6 Help */
2185 0x15e, /* Sun Type 6 Stop */
2187 0x15f, /* Sun Type 6 Again */
2188 0x160, /* Sun Type 6 Props */
2189 0x161, /* Sun Type 6 Undo */
2190 0x162, /* Sun Type 6 Front */
2191 0x163, /* Sun Type 6 Copy */
2192 0x164, /* Sun Type 6 Open */
2193 0x165, /* Sun Type 6 Paste */
2194 0x166, /* Sun Type 6 Find */
2195 0x167, /* Sun Type 6 Cut */
2196 0x125, /* Sun Type 6 Mute */
2198 0x11f, /* Sun Type 6 VolumeDown */
2199 0x11e, /* Sun Type 6 VolumeUp */
2200 0x120, /* Sun Type 6 PowerDown */
2202 /* Japanese 106/109 keyboard */
2203 0x73, /* Keyboard Intl' 1 (backslash / underscore) */
2204 0x70, /* Keyboard Intl' 2 (Katakana / Hiragana) */
2205 0x7d, /* Keyboard Intl' 3 (Yen sign) (Not using in jp106/109) */
2206 0x79, /* Keyboard Intl' 4 (Henkan) */
2207 0x7b, /* Keyboard Intl' 5 (Muhenkan) */
2208 0x5c, /* Keyboard Intl' 6 (Keypad ,) (For PC-9821 layout) */
2209 0x71, /* Apple Keyboard JIS (Kana) */
2210 0x72, /* Apple Keyboard JIS (Eisu) */
2213 if ((code >= 89) && (code < (int)(89 + nitems(scan)))) {
2214 code = scan[code - 89];
2217 if (code == 0x137 && (!(shift & (MOD_CONTROL_L | MOD_CONTROL_R |
2218 MOD_SHIFT_L | MOD_SHIFT_R)))) {
2219 code |= SCAN_PREFIX_SHIFT;
2222 if ((code == 0x146) && (!(shift & (MOD_CONTROL_L | MOD_CONTROL_R)))) {
2223 code = (0x45 | SCAN_PREFIX_E1 | SCAN_PREFIX_CTL);
2225 code |= (up ? SCAN_RELEASE : SCAN_PRESS);
2227 if (code & SCAN_PREFIX) {
2228 if (code & SCAN_PREFIX_CTL) {
2230 sc->sc_buffered_char[0] = (0x1d | (code & SCAN_RELEASE));
2231 sc->sc_buffered_char[1] = (code & ~SCAN_PREFIX);
2232 } else if (code & SCAN_PREFIX_SHIFT) {
2234 sc->sc_buffered_char[0] = (0x2a | (code & SCAN_RELEASE));
2235 sc->sc_buffered_char[1] = (code & ~SCAN_PREFIX_SHIFT);
2237 sc->sc_buffered_char[0] = (code & ~SCAN_PREFIX);
2238 sc->sc_buffered_char[1] = 0;
2240 return ((code & SCAN_PREFIX_E0) ? 0xe0 : 0xe1);
2246 #endif /* UKBD_EMULATE_ATSCANCODE */
2248 static keyboard_switch_t ukbdsw = {
2249 .probe = &ukbd__probe,
2253 .test_if = &ukbd_test_if,
2254 .enable = &ukbd_enable,
2255 .disable = &ukbd_disable,
2257 .check = &ukbd_check,
2258 .read_char = &ukbd_read_char,
2259 .check_char = &ukbd_check_char,
2260 .ioctl = &ukbd_ioctl,
2262 .clear_state = &ukbd_clear_state,
2263 .get_state = &ukbd_get_state,
2264 .set_state = &ukbd_set_state,
2265 .get_fkeystr = &genkbd_get_fkeystr,
2267 .diag = &genkbd_diag,
2270 KEYBOARD_DRIVER(ukbd, ukbdsw, ukbd_configure);
2273 ukbd_driver_load(module_t mod, int what, void *arg)
2277 kbd_add_driver(&ukbd_kbd_driver);
2280 kbd_delete_driver(&ukbd_kbd_driver);
2286 static devclass_t ukbd_devclass;
2288 static device_method_t ukbd_methods[] = {
2289 DEVMETHOD(device_probe, ukbd_probe),
2290 DEVMETHOD(device_attach, ukbd_attach),
2291 DEVMETHOD(device_detach, ukbd_detach),
2292 DEVMETHOD(device_resume, ukbd_resume),
2297 static driver_t ukbd_driver = {
2299 .methods = ukbd_methods,
2300 .size = sizeof(struct ukbd_softc),
2303 DRIVER_MODULE(ukbd, uhub, ukbd_driver, ukbd_devclass, ukbd_driver_load, 0);
2304 MODULE_DEPEND(ukbd, usb, 1, 1, 1);
2305 #ifdef EVDEV_SUPPORT
2306 MODULE_DEPEND(ukbd, evdev, 1, 1, 1);
2308 MODULE_VERSION(ukbd, 1);
2309 USB_PNP_HOST_INFO(ukbd_devs);