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
44 #include "opt_evdev.h"
46 #include <sys/stdint.h>
47 #include <sys/stddef.h>
48 #include <sys/param.h>
49 #include <sys/queue.h>
50 #include <sys/types.h>
51 #include <sys/systm.h>
52 #include <sys/kernel.h>
54 #include <sys/module.h>
56 #include <sys/mutex.h>
57 #include <sys/condvar.h>
58 #include <sys/sysctl.h>
60 #include <sys/unistd.h>
61 #include <sys/callout.h>
62 #include <sys/malloc.h>
66 #include <dev/usb/usb.h>
67 #include <dev/usb/usbdi.h>
68 #include <dev/usb/usbdi_util.h>
69 #include <dev/usb/usbhid.h>
71 #define USB_DEBUG_VAR ukbd_debug
72 #include <dev/usb/usb_debug.h>
74 #include <dev/usb/quirk/usb_quirk.h>
77 #include <dev/evdev/input.h>
78 #include <dev/evdev/evdev.h>
81 #include <sys/ioccom.h>
82 #include <sys/filio.h>
85 #include <dev/kbd/kbdreg.h>
87 /* the initial key map, accent map and fkey strings */
88 #if defined(UKBD_DFLT_KEYMAP) && !defined(KLD_MODULE)
89 #define KBD_DFLT_KEYMAP
93 /* the following file must be included after "ukbdmap.h" */
94 #include <dev/kbd/kbdtables.h>
97 static int ukbd_debug = 0;
98 static int ukbd_no_leds = 0;
99 static int ukbd_pollrate = 0;
101 static SYSCTL_NODE(_hw_usb, OID_AUTO, ukbd, CTLFLAG_RW, 0, "USB keyboard");
102 SYSCTL_INT(_hw_usb_ukbd, OID_AUTO, debug, CTLFLAG_RWTUN,
103 &ukbd_debug, 0, "Debug level");
104 SYSCTL_INT(_hw_usb_ukbd, OID_AUTO, no_leds, CTLFLAG_RWTUN,
105 &ukbd_no_leds, 0, "Disables setting of keyboard leds");
106 SYSCTL_INT(_hw_usb_ukbd, OID_AUTO, pollrate, CTLFLAG_RWTUN,
107 &ukbd_pollrate, 0, "Force this polling rate, 1-1000Hz");
110 #define UKBD_EMULATE_ATSCANCODE 1
111 #define UKBD_DRIVER_NAME "ukbd"
112 #define UKBD_NMOD 8 /* units */
113 #define UKBD_NKEYCODE 6 /* units */
114 #define UKBD_IN_BUF_SIZE (2*(UKBD_NMOD + (2*UKBD_NKEYCODE))) /* bytes */
115 #define UKBD_IN_BUF_FULL ((UKBD_IN_BUF_SIZE / 2) - 1) /* bytes */
116 #define UKBD_NFKEY (sizeof(fkey_tab)/sizeof(fkey_tab[0])) /* units */
117 #define UKBD_BUFFER_SIZE 64 /* bytes */
121 #define MOD_CONTROL_L 0x01
122 #define MOD_CONTROL_R 0x10
123 #define MOD_SHIFT_L 0x02
124 #define MOD_SHIFT_R 0x20
125 #define MOD_ALT_L 0x04
126 #define MOD_ALT_R 0x40
127 #define MOD_WIN_L 0x08
128 #define MOD_WIN_R 0x80
130 #define MOD_EJECT 0x0100
131 #define MOD_FN 0x0200
132 uint8_t keycode[UKBD_NKEYCODE];
145 accentmap_t sc_accmap;
146 fkeytab_t sc_fkeymap[UKBD_NFKEY];
147 struct hid_location sc_loc_apple_eject;
148 struct hid_location sc_loc_apple_fn;
149 struct hid_location sc_loc_ctrl_l;
150 struct hid_location sc_loc_ctrl_r;
151 struct hid_location sc_loc_shift_l;
152 struct hid_location sc_loc_shift_r;
153 struct hid_location sc_loc_alt_l;
154 struct hid_location sc_loc_alt_r;
155 struct hid_location sc_loc_win_l;
156 struct hid_location sc_loc_win_r;
157 struct hid_location sc_loc_events;
158 struct hid_location sc_loc_numlock;
159 struct hid_location sc_loc_capslock;
160 struct hid_location sc_loc_scrolllock;
161 struct usb_callout sc_callout;
162 struct ukbd_data sc_ndata;
163 struct ukbd_data sc_odata;
165 struct thread *sc_poll_thread;
166 struct usb_device *sc_udev;
167 struct usb_interface *sc_iface;
168 struct usb_xfer *sc_xfer[UKBD_N_TRANSFER];
170 struct evdev_dev *sc_evdev;
173 sbintime_t sc_co_basetime;
175 uint32_t sc_ntime[UKBD_NKEYCODE];
176 uint32_t sc_otime[UKBD_NKEYCODE];
177 uint32_t sc_input[UKBD_IN_BUF_SIZE]; /* input buffer */
179 uint32_t sc_composed_char; /* composed char code, if non-zero */
180 #ifdef UKBD_EMULATE_ATSCANCODE
181 uint32_t sc_buffered_char[2];
183 uint32_t sc_flags; /* flags */
184 #define UKBD_FLAG_COMPOSE 0x00000001
185 #define UKBD_FLAG_POLLING 0x00000002
186 #define UKBD_FLAG_SET_LEDS 0x00000004
187 #define UKBD_FLAG_ATTACHED 0x00000010
188 #define UKBD_FLAG_GONE 0x00000020
190 #define UKBD_FLAG_HID_MASK 0x003fffc0
191 #define UKBD_FLAG_APPLE_EJECT 0x00000040
192 #define UKBD_FLAG_APPLE_FN 0x00000080
193 #define UKBD_FLAG_APPLE_SWAP 0x00000100
194 #define UKBD_FLAG_CTRL_L 0x00000400
195 #define UKBD_FLAG_CTRL_R 0x00000800
196 #define UKBD_FLAG_SHIFT_L 0x00001000
197 #define UKBD_FLAG_SHIFT_R 0x00002000
198 #define UKBD_FLAG_ALT_L 0x00004000
199 #define UKBD_FLAG_ALT_R 0x00008000
200 #define UKBD_FLAG_WIN_L 0x00010000
201 #define UKBD_FLAG_WIN_R 0x00020000
202 #define UKBD_FLAG_EVENTS 0x00040000
203 #define UKBD_FLAG_NUMLOCK 0x00080000
204 #define UKBD_FLAG_CAPSLOCK 0x00100000
205 #define UKBD_FLAG_SCROLLLOCK 0x00200000
207 int sc_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */
208 int sc_state; /* shift/lock key state */
209 int sc_accents; /* accent key index (> 0) */
210 int sc_polling; /* polling recursion count */
215 uint16_t sc_inputhead;
216 uint16_t sc_inputtail;
217 uint16_t sc_modifiers;
219 uint8_t sc_leds; /* store for async led requests */
220 uint8_t sc_iface_index;
222 uint8_t sc_id_apple_eject;
223 uint8_t sc_id_apple_fn;
224 uint8_t sc_id_ctrl_l;
225 uint8_t sc_id_ctrl_r;
226 uint8_t sc_id_shift_l;
227 uint8_t sc_id_shift_r;
233 uint8_t sc_id_numlock;
234 uint8_t sc_id_capslock;
235 uint8_t sc_id_scrolllock;
236 uint8_t sc_id_events;
239 uint8_t sc_buffer[UKBD_BUFFER_SIZE];
242 #define KEY_ERROR 0x01
245 #define KEY_RELEASE 0x400
246 #define KEY_INDEX(c) ((c) & 0xFF)
249 #define SCAN_RELEASE 0x80
250 #define SCAN_PREFIX_E0 0x100
251 #define SCAN_PREFIX_E1 0x200
252 #define SCAN_PREFIX_CTL 0x400
253 #define SCAN_PREFIX_SHIFT 0x800
254 #define SCAN_PREFIX (SCAN_PREFIX_E0 | SCAN_PREFIX_E1 | \
255 SCAN_PREFIX_CTL | SCAN_PREFIX_SHIFT)
256 #define SCAN_CHAR(c) ((c) & 0x7f)
258 #define UKBD_LOCK() USB_MTX_LOCK(&Giant)
259 #define UKBD_UNLOCK() USB_MTX_UNLOCK(&Giant)
260 #define UKBD_LOCK_ASSERT() USB_MTX_ASSERT(&Giant, MA_OWNED)
266 static const struct ukbd_mods ukbd_mods[UKBD_NMOD] = {
267 {MOD_CONTROL_L, 0xe0},
268 {MOD_CONTROL_R, 0xe4},
277 #define NN 0 /* no translation */
279 * Translate USB keycodes to AT keyboard scancodes.
282 * FIXME: Mac USB keyboard generates:
283 * 0x53: keypad NumLock/Clear
290 * USB Apple Keyboard JIS generates:
294 static const uint8_t ukbd_trtab[256] = {
295 0, 0, 0, 0, 30, 48, 46, 32, /* 00 - 07 */
296 18, 33, 34, 35, 23, 36, 37, 38, /* 08 - 0F */
297 50, 49, 24, 25, 16, 19, 31, 20, /* 10 - 17 */
298 22, 47, 17, 45, 21, 44, 2, 3, /* 18 - 1F */
299 4, 5, 6, 7, 8, 9, 10, 11, /* 20 - 27 */
300 28, 1, 14, 15, 57, 12, 13, 26, /* 28 - 2F */
301 27, 43, 43, 39, 40, 41, 51, 52, /* 30 - 37 */
302 53, 58, 59, 60, 61, 62, 63, 64, /* 38 - 3F */
303 65, 66, 67, 68, 87, 88, 92, 70, /* 40 - 47 */
304 104, 102, 94, 96, 103, 99, 101, 98, /* 48 - 4F */
305 97, 100, 95, 69, 91, 55, 74, 78,/* 50 - 57 */
306 89, 79, 80, 81, 75, 76, 77, 71, /* 58 - 5F */
307 72, 73, 82, 83, 86, 107, 122, NN, /* 60 - 67 */
308 NN, NN, NN, NN, NN, NN, NN, NN, /* 68 - 6F */
309 NN, NN, NN, NN, 115, 108, 111, 113, /* 70 - 77 */
310 109, 110, 112, 118, 114, 116, 117, 119, /* 78 - 7F */
311 121, 120, NN, NN, NN, NN, NN, 123, /* 80 - 87 */
312 124, 125, 126, 127, 128, NN, NN, NN, /* 88 - 8F */
313 129, 130, NN, NN, NN, NN, NN, NN, /* 90 - 97 */
314 NN, NN, NN, NN, NN, NN, NN, NN, /* 98 - 9F */
315 NN, NN, NN, NN, NN, NN, NN, NN, /* A0 - A7 */
316 NN, NN, NN, NN, NN, NN, NN, NN, /* A8 - AF */
317 NN, NN, NN, NN, NN, NN, NN, NN, /* B0 - B7 */
318 NN, NN, NN, NN, NN, NN, NN, NN, /* B8 - BF */
319 NN, NN, NN, NN, NN, NN, NN, NN, /* C0 - C7 */
320 NN, NN, NN, NN, NN, NN, NN, NN, /* C8 - CF */
321 NN, NN, NN, NN, NN, NN, NN, NN, /* D0 - D7 */
322 NN, NN, NN, NN, NN, NN, NN, NN, /* D8 - DF */
323 29, 42, 56, 105, 90, 54, 93, 106, /* E0 - E7 */
324 NN, NN, NN, NN, NN, NN, NN, NN, /* E8 - EF */
325 NN, NN, NN, NN, NN, NN, NN, NN, /* F0 - F7 */
326 NN, NN, NN, NN, NN, NN, NN, NN, /* F8 - FF */
329 static const uint8_t ukbd_boot_desc[] = {
330 0x05, 0x01, 0x09, 0x06, 0xa1,
331 0x01, 0x05, 0x07, 0x19, 0xe0,
332 0x29, 0xe7, 0x15, 0x00, 0x25,
333 0x01, 0x75, 0x01, 0x95, 0x08,
334 0x81, 0x02, 0x95, 0x01, 0x75,
335 0x08, 0x81, 0x01, 0x95, 0x03,
336 0x75, 0x01, 0x05, 0x08, 0x19,
337 0x01, 0x29, 0x03, 0x91, 0x02,
338 0x95, 0x05, 0x75, 0x01, 0x91,
339 0x01, 0x95, 0x06, 0x75, 0x08,
340 0x15, 0x00, 0x26, 0xff, 0x00,
341 0x05, 0x07, 0x19, 0x00, 0x2a,
342 0xff, 0x00, 0x81, 0x00, 0xc0
346 static void ukbd_timeout(void *);
347 static void ukbd_set_leds(struct ukbd_softc *, uint8_t);
348 static int ukbd_set_typematic(keyboard_t *, int);
349 #ifdef UKBD_EMULATE_ATSCANCODE
350 static uint32_t ukbd_atkeycode(int, int);
351 static int ukbd_key2scan(struct ukbd_softc *, int, int, int);
353 static uint32_t ukbd_read_char(keyboard_t *, int);
354 static void ukbd_clear_state(keyboard_t *);
355 static int ukbd_ioctl(keyboard_t *, u_long, caddr_t);
356 static int ukbd_enable(keyboard_t *);
357 static int ukbd_disable(keyboard_t *);
358 static void ukbd_interrupt(struct ukbd_softc *);
359 static void ukbd_event_keyinput(struct ukbd_softc *);
361 static device_probe_t ukbd_probe;
362 static device_attach_t ukbd_attach;
363 static device_detach_t ukbd_detach;
364 static device_resume_t ukbd_resume;
367 static evdev_event_t ukbd_ev_event;
369 static const struct evdev_methods ukbd_evdev_methods = {
370 .ev_event = ukbd_ev_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, now, prec;
393 /* check if initial delay passed and fallback to key repeat delay */
394 if (sc->sc_delay == 0)
395 sc->sc_delay = sc->sc_kbd.kb_delay2;
397 /* compute timeout */
398 delay = SBT_1MS * sc->sc_delay;
399 sc->sc_co_basetime += delay;
401 /* check if we are running behind */
402 if (sc->sc_co_basetime < now)
403 sc->sc_co_basetime = now;
405 /* This is rarely called, so prefer precision to efficiency. */
406 prec = qmin(delay >> 7, SBT_1MS * 10);
407 usb_callout_reset_sbt(&sc->sc_callout, sc->sc_co_basetime, prec,
408 ukbd_timeout, sc, C_ABSOLUTE);
412 ukbd_put_key(struct ukbd_softc *sc, uint32_t key)
417 DPRINTF("0x%02x (%d) %s\n", key, key,
418 (key & KEY_RELEASE) ? "released" : "pressed");
421 if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL) {
422 evdev_push_event(sc->sc_evdev, EV_KEY,
423 evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE));
424 evdev_sync(sc->sc_evdev);
428 if (sc->sc_inputs < UKBD_IN_BUF_SIZE) {
429 sc->sc_input[sc->sc_inputtail] = key;
431 ++(sc->sc_inputtail);
432 if (sc->sc_inputtail >= UKBD_IN_BUF_SIZE) {
433 sc->sc_inputtail = 0;
436 DPRINTF("input buffer is full\n");
441 ukbd_do_poll(struct ukbd_softc *sc, uint8_t wait)
445 KASSERT((sc->sc_flags & UKBD_FLAG_POLLING) != 0,
446 ("ukbd_do_poll called when not polling\n"));
447 DPRINTFN(2, "polling\n");
449 if (USB_IN_POLLING_MODE_FUNC() == 0) {
451 * In this context the kernel is polling for input,
452 * but the USB subsystem works in normal interrupt-driven
453 * mode, so we just wait on the USB threads to do the job.
454 * Note that we currently hold the Giant, but it's also used
455 * as the transfer mtx, so we must release it while waiting.
457 while (sc->sc_inputs == 0) {
459 * Give USB threads a chance to run. Note that
460 * kern_yield performs DROP_GIANT + PICKUP_GIANT.
462 kern_yield(PRI_UNCHANGED);
469 while (sc->sc_inputs == 0) {
471 usbd_transfer_poll(sc->sc_xfer, UKBD_N_TRANSFER);
473 /* Delay-optimised support for repetition of keys */
474 if (ukbd_any_key_pressed(sc)) {
475 /* a key is pressed - need timekeeping */
478 /* 1 millisecond has passed */
490 ukbd_get_key(struct ukbd_softc *sc, uint8_t wait)
495 KASSERT((USB_IN_POLLING_MODE_FUNC() == 0) ||
496 (sc->sc_flags & UKBD_FLAG_POLLING) != 0,
497 ("not polling in kdb or panic\n"));
499 if (sc->sc_inputs == 0 &&
500 (sc->sc_flags & UKBD_FLAG_GONE) == 0) {
501 /* start transfer, if not already started */
502 usbd_transfer_start(sc->sc_xfer[UKBD_INTR_DT_0]);
503 usbd_transfer_start(sc->sc_xfer[UKBD_INTR_DT_1]);
506 if (sc->sc_flags & UKBD_FLAG_POLLING)
507 ukbd_do_poll(sc, wait);
509 if (sc->sc_inputs == 0) {
512 c = sc->sc_input[sc->sc_inputhead];
514 ++(sc->sc_inputhead);
515 if (sc->sc_inputhead >= UKBD_IN_BUF_SIZE) {
516 sc->sc_inputhead = 0;
523 ukbd_interrupt(struct ukbd_softc *sc)
527 uint32_t now = sc->sc_time_ms;
535 if (sc->sc_ndata.keycode[0] == KEY_ERROR)
538 n_mod = sc->sc_ndata.modifiers;
539 o_mod = sc->sc_odata.modifiers;
540 if (n_mod != o_mod) {
541 for (i = 0; i < UKBD_NMOD; i++) {
542 if ((n_mod & ukbd_mods[i].mask) !=
543 (o_mod & ukbd_mods[i].mask)) {
544 ukbd_put_key(sc, ukbd_mods[i].key |
545 ((n_mod & ukbd_mods[i].mask) ?
546 KEY_PRESS : KEY_RELEASE));
550 /* Check for released keys. */
551 for (i = 0; i < UKBD_NKEYCODE; i++) {
552 key = sc->sc_odata.keycode[i];
556 for (j = 0; j < UKBD_NKEYCODE; j++) {
557 if (sc->sc_ndata.keycode[j] == 0) {
560 if (key == sc->sc_ndata.keycode[j]) {
564 ukbd_put_key(sc, key | KEY_RELEASE);
568 /* Check for pressed keys. */
569 for (i = 0; i < UKBD_NKEYCODE; i++) {
570 key = sc->sc_ndata.keycode[i];
574 sc->sc_ntime[i] = now + sc->sc_kbd.kb_delay1;
575 for (j = 0; j < UKBD_NKEYCODE; j++) {
576 if (sc->sc_odata.keycode[j] == 0) {
579 if (key == sc->sc_odata.keycode[j]) {
581 /* key is still pressed */
583 sc->sc_ntime[i] = sc->sc_otime[j];
584 dtime = (sc->sc_otime[j] - now);
587 /* time has not elapsed */
590 sc->sc_ntime[i] = now + sc->sc_kbd.kb_delay2;
594 if (j == UKBD_NKEYCODE) {
595 /* New key - set initial delay and [re]start timer */
596 sc->sc_co_basetime = sbinuptime();
597 sc->sc_delay = sc->sc_kbd.kb_delay1;
598 ukbd_start_timer(sc);
600 ukbd_put_key(sc, key | KEY_PRESS);
603 * If any other key is presently down, force its repeat to be
604 * well in the future (100s). This makes the last key to be
605 * pressed do the autorepeat.
607 for (j = 0; j != UKBD_NKEYCODE; j++) {
609 sc->sc_ntime[j] = now + (100 * 1000);
614 sc->sc_odata = sc->sc_ndata;
616 memcpy(sc->sc_otime, sc->sc_ntime, sizeof(sc->sc_otime));
618 ukbd_event_keyinput(sc);
622 ukbd_event_keyinput(struct ukbd_softc *sc)
628 if ((sc->sc_flags & UKBD_FLAG_POLLING) != 0)
631 if (sc->sc_inputs == 0)
634 if (KBD_IS_ACTIVE(&sc->sc_kbd) &&
635 KBD_IS_BUSY(&sc->sc_kbd)) {
636 /* let the callback function process the input */
637 (sc->sc_kbd.kb_callback.kc_func) (&sc->sc_kbd, KBDIO_KEYINPUT,
638 sc->sc_kbd.kb_callback.kc_arg);
640 /* read and discard the input, no one is waiting for it */
642 c = ukbd_read_char(&sc->sc_kbd, 0);
643 } while (c != NOKEY);
648 ukbd_timeout(void *arg)
650 struct ukbd_softc *sc = arg;
654 sc->sc_time_ms += sc->sc_delay;
659 /* Make sure any leftover key events gets read out */
660 ukbd_event_keyinput(sc);
662 if (ukbd_any_key_pressed(sc) || (sc->sc_inputs != 0)) {
663 ukbd_start_timer(sc);
668 ukbd_apple_fn(uint8_t keycode) {
670 case 0x28: return 0x49; /* RETURN -> INSERT */
671 case 0x2a: return 0x4c; /* BACKSPACE -> DEL */
672 case 0x50: return 0x4a; /* LEFT ARROW -> HOME */
673 case 0x4f: return 0x4d; /* RIGHT ARROW -> END */
674 case 0x52: return 0x4b; /* UP ARROW -> PGUP */
675 case 0x51: return 0x4e; /* DOWN ARROW -> PGDN */
676 default: return keycode;
681 ukbd_apple_swap(uint8_t keycode) {
683 case 0x35: return 0x64;
684 case 0x64: return 0x35;
685 default: return keycode;
690 ukbd_intr_callback(struct usb_xfer *xfer, usb_error_t error)
692 struct ukbd_softc *sc = usbd_xfer_softc(xfer);
693 struct usb_page_cache *pc;
701 usbd_xfer_status(xfer, &len, NULL, NULL, NULL);
702 pc = usbd_xfer_get_frame(xfer, 0);
704 switch (USB_GET_STATE(xfer)) {
705 case USB_ST_TRANSFERRED:
706 DPRINTF("actlen=%d bytes\n", len);
709 DPRINTF("zero length data\n");
713 if (sc->sc_kbd_id != 0) {
714 /* check and remove HID ID byte */
715 usbd_copy_out(pc, 0, &id, 1);
719 DPRINTF("zero length data\n");
727 if (len > UKBD_BUFFER_SIZE)
728 len = UKBD_BUFFER_SIZE;
731 usbd_copy_out(pc, offset, sc->sc_buffer, len);
733 /* clear temporary storage */
734 memset(&sc->sc_ndata, 0, sizeof(sc->sc_ndata));
736 /* scan through HID data */
737 if ((sc->sc_flags & UKBD_FLAG_APPLE_EJECT) &&
738 (id == sc->sc_id_apple_eject)) {
739 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_apple_eject))
740 sc->sc_modifiers |= MOD_EJECT;
742 sc->sc_modifiers &= ~MOD_EJECT;
744 if ((sc->sc_flags & UKBD_FLAG_APPLE_FN) &&
745 (id == sc->sc_id_apple_fn)) {
746 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_apple_fn))
747 sc->sc_modifiers |= MOD_FN;
749 sc->sc_modifiers &= ~MOD_FN;
751 if ((sc->sc_flags & UKBD_FLAG_CTRL_L) &&
752 (id == sc->sc_id_ctrl_l)) {
753 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_ctrl_l))
754 sc-> sc_modifiers |= MOD_CONTROL_L;
756 sc-> sc_modifiers &= ~MOD_CONTROL_L;
758 if ((sc->sc_flags & UKBD_FLAG_CTRL_R) &&
759 (id == sc->sc_id_ctrl_r)) {
760 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_ctrl_r))
761 sc->sc_modifiers |= MOD_CONTROL_R;
763 sc->sc_modifiers &= ~MOD_CONTROL_R;
765 if ((sc->sc_flags & UKBD_FLAG_SHIFT_L) &&
766 (id == sc->sc_id_shift_l)) {
767 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_shift_l))
768 sc->sc_modifiers |= MOD_SHIFT_L;
770 sc->sc_modifiers &= ~MOD_SHIFT_L;
772 if ((sc->sc_flags & UKBD_FLAG_SHIFT_R) &&
773 (id == sc->sc_id_shift_r)) {
774 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_shift_r))
775 sc->sc_modifiers |= MOD_SHIFT_R;
777 sc->sc_modifiers &= ~MOD_SHIFT_R;
779 if ((sc->sc_flags & UKBD_FLAG_ALT_L) &&
780 (id == sc->sc_id_alt_l)) {
781 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_alt_l))
782 sc->sc_modifiers |= MOD_ALT_L;
784 sc->sc_modifiers &= ~MOD_ALT_L;
786 if ((sc->sc_flags & UKBD_FLAG_ALT_R) &&
787 (id == sc->sc_id_alt_r)) {
788 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_alt_r))
789 sc->sc_modifiers |= MOD_ALT_R;
791 sc->sc_modifiers &= ~MOD_ALT_R;
793 if ((sc->sc_flags & UKBD_FLAG_WIN_L) &&
794 (id == sc->sc_id_win_l)) {
795 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_win_l))
796 sc->sc_modifiers |= MOD_WIN_L;
798 sc->sc_modifiers &= ~MOD_WIN_L;
800 if ((sc->sc_flags & UKBD_FLAG_WIN_R) &&
801 (id == sc->sc_id_win_r)) {
802 if (hid_get_data(sc->sc_buffer, len, &sc->sc_loc_win_r))
803 sc->sc_modifiers |= MOD_WIN_R;
805 sc->sc_modifiers &= ~MOD_WIN_R;
808 sc->sc_ndata.modifiers = sc->sc_modifiers;
810 if ((sc->sc_flags & UKBD_FLAG_EVENTS) &&
811 (id == sc->sc_id_events)) {
812 i = sc->sc_loc_events.count;
813 if (i > UKBD_NKEYCODE)
818 sc->sc_ndata.keycode[i] =
819 hid_get_data(sc->sc_buffer + i, len - i,
825 DPRINTF("modifiers = 0x%04x\n", (int)sc->sc_modifiers);
826 for (i = 0; i < UKBD_NKEYCODE; i++) {
827 if (sc->sc_ndata.keycode[i]) {
828 DPRINTF("[%d] = 0x%02x\n",
829 (int)i, (int)sc->sc_ndata.keycode[i]);
833 if (sc->sc_modifiers & MOD_FN) {
834 for (i = 0; i < UKBD_NKEYCODE; i++) {
835 sc->sc_ndata.keycode[i] =
836 ukbd_apple_fn(sc->sc_ndata.keycode[i]);
840 if (sc->sc_flags & UKBD_FLAG_APPLE_SWAP) {
841 for (i = 0; i < UKBD_NKEYCODE; i++) {
842 sc->sc_ndata.keycode[i] =
843 ukbd_apple_swap(sc->sc_ndata.keycode[i]);
851 if (sc->sc_inputs < UKBD_IN_BUF_FULL) {
852 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
853 usbd_transfer_submit(xfer);
855 DPRINTF("input queue is full!\n");
860 DPRINTF("error=%s\n", usbd_errstr(error));
862 if (error != USB_ERR_CANCELLED) {
863 /* try to clear stall first */
864 usbd_xfer_set_stall(xfer);
872 ukbd_set_leds_callback(struct usb_xfer *xfer, usb_error_t error)
874 struct ukbd_softc *sc = usbd_xfer_softc(xfer);
875 struct usb_device_request req;
876 struct usb_page_cache *pc;
888 switch (USB_GET_STATE(xfer)) {
889 case USB_ST_TRANSFERRED:
891 if (!(sc->sc_flags & UKBD_FLAG_SET_LEDS))
893 sc->sc_flags &= ~UKBD_FLAG_SET_LEDS;
895 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
896 req.bRequest = UR_SET_REPORT;
897 USETW2(req.wValue, UHID_OUTPUT_REPORT, 0);
898 req.wIndex[0] = sc->sc_iface_no;
902 memset(sc->sc_buffer, 0, UKBD_BUFFER_SIZE);
907 /* Assumption: All led bits must be in the same ID. */
909 if (sc->sc_flags & UKBD_FLAG_NUMLOCK) {
910 if (sc->sc_leds & NLKED) {
911 hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
912 &sc->sc_loc_numlock, 1);
914 id = sc->sc_id_numlock;
918 if (sc->sc_flags & UKBD_FLAG_SCROLLLOCK) {
919 if (sc->sc_leds & SLKED) {
920 hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
921 &sc->sc_loc_scrolllock, 1);
923 id = sc->sc_id_scrolllock;
927 if (sc->sc_flags & UKBD_FLAG_CAPSLOCK) {
928 if (sc->sc_leds & CLKED) {
929 hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1,
930 &sc->sc_loc_capslock, 1);
932 id = sc->sc_id_capslock;
936 /* if no leds, nothing to do */
941 if (sc->sc_evdev != NULL)
942 evdev_push_leds(sc->sc_evdev, sc->sc_leds);
945 /* range check output report length */
946 len = sc->sc_led_size;
947 if (len > (UKBD_BUFFER_SIZE - 1))
948 len = (UKBD_BUFFER_SIZE - 1);
950 /* check if we need to prefix an ID byte */
951 sc->sc_buffer[0] = id;
953 pc = usbd_xfer_get_frame(xfer, 1);
956 usbd_copy_in(pc, 0, sc->sc_buffer, len);
958 usbd_copy_in(pc, 0, sc->sc_buffer + 1, len);
960 req.wLength[0] = len;
961 usbd_xfer_set_frame_len(xfer, 1, len);
963 DPRINTF("len=%d, id=%d\n", len, id);
965 /* setup control request last */
966 pc = usbd_xfer_get_frame(xfer, 0);
967 usbd_copy_in(pc, 0, &req, sizeof(req));
968 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
970 /* start data transfer */
971 usbd_xfer_set_frames(xfer, 2);
972 usbd_transfer_submit(xfer);
976 DPRINTFN(1, "error=%s\n", usbd_errstr(error));
981 static const struct usb_config ukbd_config[UKBD_N_TRANSFER] = {
984 .type = UE_INTERRUPT,
985 .endpoint = UE_ADDR_ANY,
986 .direction = UE_DIR_IN,
987 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
988 .bufsize = 0, /* use wMaxPacketSize */
989 .callback = &ukbd_intr_callback,
993 .type = UE_INTERRUPT,
994 .endpoint = UE_ADDR_ANY,
995 .direction = UE_DIR_IN,
996 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
997 .bufsize = 0, /* use wMaxPacketSize */
998 .callback = &ukbd_intr_callback,
1003 .endpoint = 0x00, /* Control pipe */
1004 .direction = UE_DIR_ANY,
1005 .bufsize = sizeof(struct usb_device_request) + UKBD_BUFFER_SIZE,
1006 .callback = &ukbd_set_leds_callback,
1007 .timeout = 1000, /* 1 second */
1011 /* A match on these entries will load ukbd */
1012 static const STRUCT_USB_HOST_ID __used ukbd_devs[] = {
1013 {USB_IFACE_CLASS(UICLASS_HID),
1014 USB_IFACE_SUBCLASS(UISUBCLASS_BOOT),
1015 USB_IFACE_PROTOCOL(UIPROTO_BOOT_KEYBOARD),},
1019 ukbd_probe(device_t dev)
1021 keyboard_switch_t *sw = kbd_get_switch(UKBD_DRIVER_NAME);
1022 struct usb_attach_arg *uaa = device_get_ivars(dev);
1033 if (uaa->usb_mode != USB_MODE_HOST) {
1037 if (uaa->info.bInterfaceClass != UICLASS_HID)
1040 if (usb_test_quirk(uaa, UQ_KBD_IGNORE))
1043 if ((uaa->info.bInterfaceSubClass == UISUBCLASS_BOOT) &&
1044 (uaa->info.bInterfaceProtocol == UIPROTO_BOOT_KEYBOARD))
1045 return (BUS_PROBE_DEFAULT);
1047 error = usbd_req_get_hid_desc(uaa->device, NULL,
1048 &d_ptr, &d_len, M_TEMP, uaa->info.bIfaceIndex);
1053 if (hid_is_keyboard(d_ptr, d_len)) {
1054 if (hid_is_mouse(d_ptr, d_len)) {
1056 * NOTE: We currently don't support USB mouse
1057 * and USB keyboard on the same USB endpoint.
1058 * Let "ums" driver win.
1062 error = BUS_PROBE_DEFAULT;
1067 free(d_ptr, M_TEMP);
1072 ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len)
1076 /* reset detected bits */
1077 sc->sc_flags &= ~UKBD_FLAG_HID_MASK;
1079 /* check if there is an ID byte */
1080 sc->sc_kbd_size = hid_report_size(ptr, len,
1081 hid_input, &sc->sc_kbd_id);
1083 /* investigate if this is an Apple Keyboard */
1084 if (hid_locate(ptr, len,
1085 HID_USAGE2(HUP_CONSUMER, HUG_APPLE_EJECT),
1086 hid_input, 0, &sc->sc_loc_apple_eject, &flags,
1087 &sc->sc_id_apple_eject)) {
1088 if (flags & HIO_VARIABLE)
1089 sc->sc_flags |= UKBD_FLAG_APPLE_EJECT |
1090 UKBD_FLAG_APPLE_SWAP;
1091 DPRINTFN(1, "Found Apple eject-key\n");
1093 if (hid_locate(ptr, len,
1094 HID_USAGE2(0xFFFF, 0x0003),
1095 hid_input, 0, &sc->sc_loc_apple_fn, &flags,
1096 &sc->sc_id_apple_fn)) {
1097 if (flags & HIO_VARIABLE)
1098 sc->sc_flags |= UKBD_FLAG_APPLE_FN;
1099 DPRINTFN(1, "Found Apple FN-key\n");
1101 /* figure out some keys */
1102 if (hid_locate(ptr, len,
1103 HID_USAGE2(HUP_KEYBOARD, 0xE0),
1104 hid_input, 0, &sc->sc_loc_ctrl_l, &flags,
1105 &sc->sc_id_ctrl_l)) {
1106 if (flags & HIO_VARIABLE)
1107 sc->sc_flags |= UKBD_FLAG_CTRL_L;
1108 DPRINTFN(1, "Found left control\n");
1110 if (hid_locate(ptr, len,
1111 HID_USAGE2(HUP_KEYBOARD, 0xE4),
1112 hid_input, 0, &sc->sc_loc_ctrl_r, &flags,
1113 &sc->sc_id_ctrl_r)) {
1114 if (flags & HIO_VARIABLE)
1115 sc->sc_flags |= UKBD_FLAG_CTRL_R;
1116 DPRINTFN(1, "Found right control\n");
1118 if (hid_locate(ptr, len,
1119 HID_USAGE2(HUP_KEYBOARD, 0xE1),
1120 hid_input, 0, &sc->sc_loc_shift_l, &flags,
1121 &sc->sc_id_shift_l)) {
1122 if (flags & HIO_VARIABLE)
1123 sc->sc_flags |= UKBD_FLAG_SHIFT_L;
1124 DPRINTFN(1, "Found left shift\n");
1126 if (hid_locate(ptr, len,
1127 HID_USAGE2(HUP_KEYBOARD, 0xE5),
1128 hid_input, 0, &sc->sc_loc_shift_r, &flags,
1129 &sc->sc_id_shift_r)) {
1130 if (flags & HIO_VARIABLE)
1131 sc->sc_flags |= UKBD_FLAG_SHIFT_R;
1132 DPRINTFN(1, "Found right shift\n");
1134 if (hid_locate(ptr, len,
1135 HID_USAGE2(HUP_KEYBOARD, 0xE2),
1136 hid_input, 0, &sc->sc_loc_alt_l, &flags,
1137 &sc->sc_id_alt_l)) {
1138 if (flags & HIO_VARIABLE)
1139 sc->sc_flags |= UKBD_FLAG_ALT_L;
1140 DPRINTFN(1, "Found left alt\n");
1142 if (hid_locate(ptr, len,
1143 HID_USAGE2(HUP_KEYBOARD, 0xE6),
1144 hid_input, 0, &sc->sc_loc_alt_r, &flags,
1145 &sc->sc_id_alt_r)) {
1146 if (flags & HIO_VARIABLE)
1147 sc->sc_flags |= UKBD_FLAG_ALT_R;
1148 DPRINTFN(1, "Found right alt\n");
1150 if (hid_locate(ptr, len,
1151 HID_USAGE2(HUP_KEYBOARD, 0xE3),
1152 hid_input, 0, &sc->sc_loc_win_l, &flags,
1153 &sc->sc_id_win_l)) {
1154 if (flags & HIO_VARIABLE)
1155 sc->sc_flags |= UKBD_FLAG_WIN_L;
1156 DPRINTFN(1, "Found left GUI\n");
1158 if (hid_locate(ptr, len,
1159 HID_USAGE2(HUP_KEYBOARD, 0xE7),
1160 hid_input, 0, &sc->sc_loc_win_r, &flags,
1161 &sc->sc_id_win_r)) {
1162 if (flags & HIO_VARIABLE)
1163 sc->sc_flags |= UKBD_FLAG_WIN_R;
1164 DPRINTFN(1, "Found right GUI\n");
1166 /* figure out event buffer */
1167 if (hid_locate(ptr, len,
1168 HID_USAGE2(HUP_KEYBOARD, 0x00),
1169 hid_input, 0, &sc->sc_loc_events, &flags,
1170 &sc->sc_id_events)) {
1171 if (flags & HIO_VARIABLE) {
1172 DPRINTFN(1, "Ignoring keyboard event control\n");
1174 sc->sc_flags |= UKBD_FLAG_EVENTS;
1175 DPRINTFN(1, "Found keyboard event array\n");
1179 /* figure out leds on keyboard */
1180 sc->sc_led_size = hid_report_size(ptr, len,
1183 if (hid_locate(ptr, len,
1184 HID_USAGE2(HUP_LEDS, 0x01),
1185 hid_output, 0, &sc->sc_loc_numlock, &flags,
1186 &sc->sc_id_numlock)) {
1187 if (flags & HIO_VARIABLE)
1188 sc->sc_flags |= UKBD_FLAG_NUMLOCK;
1189 DPRINTFN(1, "Found keyboard numlock\n");
1191 if (hid_locate(ptr, len,
1192 HID_USAGE2(HUP_LEDS, 0x02),
1193 hid_output, 0, &sc->sc_loc_capslock, &flags,
1194 &sc->sc_id_capslock)) {
1195 if (flags & HIO_VARIABLE)
1196 sc->sc_flags |= UKBD_FLAG_CAPSLOCK;
1197 DPRINTFN(1, "Found keyboard capslock\n");
1199 if (hid_locate(ptr, len,
1200 HID_USAGE2(HUP_LEDS, 0x03),
1201 hid_output, 0, &sc->sc_loc_scrolllock, &flags,
1202 &sc->sc_id_scrolllock)) {
1203 if (flags & HIO_VARIABLE)
1204 sc->sc_flags |= UKBD_FLAG_SCROLLLOCK;
1205 DPRINTFN(1, "Found keyboard scrolllock\n");
1210 ukbd_attach(device_t dev)
1212 struct ukbd_softc *sc = device_get_softc(dev);
1213 struct usb_attach_arg *uaa = device_get_ivars(dev);
1214 int unit = device_get_unit(dev);
1215 keyboard_t *kbd = &sc->sc_kbd;
1216 void *hid_ptr = NULL;
1220 #ifdef EVDEV_SUPPORT
1221 struct evdev_dev *evdev;
1229 kbd_init_struct(kbd, UKBD_DRIVER_NAME, KB_OTHER, unit, 0, 0, 0);
1231 kbd->kb_data = (void *)sc;
1233 device_set_usb_desc(dev);
1235 sc->sc_udev = uaa->device;
1236 sc->sc_iface = uaa->iface;
1237 sc->sc_iface_index = uaa->info.bIfaceIndex;
1238 sc->sc_iface_no = uaa->info.bIfaceNum;
1239 sc->sc_mode = K_XLATE;
1241 usb_callout_init_mtx(&sc->sc_callout, &Giant, 0);
1243 #ifdef UKBD_NO_POLLING
1244 err = usbd_transfer_setup(uaa->device,
1245 &uaa->info.bIfaceIndex, sc->sc_xfer, ukbd_config,
1246 UKBD_N_TRANSFER, sc, &Giant);
1249 * Setup the UKBD USB transfers one by one, so they are memory
1250 * independent which allows for handling panics triggered by
1251 * the keyboard driver itself, typically via CTRL+ALT+ESC
1252 * sequences. Or if the USB keyboard driver was processing a
1253 * key at the moment of panic.
1255 for (n = 0; n != UKBD_N_TRANSFER; n++) {
1256 err = usbd_transfer_setup(uaa->device,
1257 &uaa->info.bIfaceIndex, sc->sc_xfer + n, ukbd_config + n,
1265 DPRINTF("error=%s\n", usbd_errstr(err));
1268 /* setup default keyboard maps */
1270 sc->sc_keymap = key_map;
1271 sc->sc_accmap = accent_map;
1272 for (n = 0; n < UKBD_NFKEY; n++) {
1273 sc->sc_fkeymap[n] = fkey_tab[n];
1276 kbd_set_maps(kbd, &sc->sc_keymap, &sc->sc_accmap,
1277 sc->sc_fkeymap, UKBD_NFKEY);
1279 KBD_FOUND_DEVICE(kbd);
1281 ukbd_clear_state(kbd);
1284 * FIXME: set the initial value for lock keys in "sc_state"
1285 * according to the BIOS data?
1287 KBD_PROBE_DONE(kbd);
1289 /* get HID descriptor */
1290 err = usbd_req_get_hid_desc(uaa->device, NULL, &hid_ptr,
1291 &hid_len, M_TEMP, uaa->info.bIfaceIndex);
1294 DPRINTF("Parsing HID descriptor of %d bytes\n",
1297 ukbd_parse_hid(sc, hid_ptr, hid_len);
1299 free(hid_ptr, M_TEMP);
1302 /* check if we should use the boot protocol */
1303 if (usb_test_quirk(uaa, UQ_KBD_BOOTPROTO) ||
1304 (err != 0) || (!(sc->sc_flags & UKBD_FLAG_EVENTS))) {
1306 DPRINTF("Forcing boot protocol\n");
1308 err = usbd_req_set_protocol(sc->sc_udev, NULL,
1309 sc->sc_iface_index, 0);
1312 DPRINTF("Set protocol error=%s (ignored)\n",
1316 ukbd_parse_hid(sc, ukbd_boot_desc, sizeof(ukbd_boot_desc));
1319 /* ignore if SETIDLE fails, hence it is not crucial */
1320 usbd_req_set_idle(sc->sc_udev, NULL, sc->sc_iface_index, 0, 0);
1322 ukbd_ioctl(kbd, KDSETLED, (caddr_t)&sc->sc_state);
1326 if (kbd_register(kbd) < 0) {
1329 KBD_CONFIG_DONE(kbd);
1333 #ifdef KBD_INSTALL_CDEV
1334 if (kbd_attach(kbd)) {
1339 #ifdef EVDEV_SUPPORT
1340 evdev = evdev_alloc();
1341 evdev_set_name(evdev, device_get_desc(dev));
1342 evdev_set_phys(evdev, device_get_nameunit(dev));
1343 evdev_set_id(evdev, BUS_USB, uaa->info.idVendor,
1344 uaa->info.idProduct, 0);
1345 evdev_set_serial(evdev, usb_get_serial(uaa->device));
1346 evdev_set_methods(evdev, kbd, &ukbd_evdev_methods);
1347 evdev_support_event(evdev, EV_SYN);
1348 evdev_support_event(evdev, EV_KEY);
1349 if (sc->sc_flags & (UKBD_FLAG_NUMLOCK | UKBD_FLAG_CAPSLOCK |
1350 UKBD_FLAG_SCROLLLOCK))
1351 evdev_support_event(evdev, EV_LED);
1352 evdev_support_event(evdev, EV_REP);
1354 for (i = 0x00; i <= 0xFF; i++)
1355 evdev_support_key(evdev, evdev_hid2key(i));
1356 if (sc->sc_flags & UKBD_FLAG_NUMLOCK)
1357 evdev_support_led(evdev, LED_NUML);
1358 if (sc->sc_flags & UKBD_FLAG_CAPSLOCK)
1359 evdev_support_led(evdev, LED_CAPSL);
1360 if (sc->sc_flags & UKBD_FLAG_SCROLLLOCK)
1361 evdev_support_led(evdev, LED_SCROLLL);
1363 if (evdev_register_mtx(evdev, &Giant))
1366 sc->sc_evdev = evdev;
1369 sc->sc_flags |= UKBD_FLAG_ATTACHED;
1372 kbdd_diag(kbd, bootverbose);
1376 /* check for polling rate override */
1377 rate = ukbd_pollrate;
1384 /* set new polling interval in ms */
1385 usbd_xfer_set_interval(sc->sc_xfer[UKBD_INTR_DT_0], rate);
1386 usbd_xfer_set_interval(sc->sc_xfer[UKBD_INTR_DT_1], rate);
1389 /* start the keyboard */
1390 usbd_transfer_start(sc->sc_xfer[UKBD_INTR_DT_0]);
1391 usbd_transfer_start(sc->sc_xfer[UKBD_INTR_DT_1]);
1393 return (0); /* success */
1397 return (ENXIO); /* error */
1401 ukbd_detach(device_t dev)
1403 struct ukbd_softc *sc = device_get_softc(dev);
1410 sc->sc_flags |= UKBD_FLAG_GONE;
1412 usb_callout_stop(&sc->sc_callout);
1414 /* kill any stuck keys */
1415 if (sc->sc_flags & UKBD_FLAG_ATTACHED) {
1416 /* stop receiving events from the USB keyboard */
1417 usbd_transfer_stop(sc->sc_xfer[UKBD_INTR_DT_0]);
1418 usbd_transfer_stop(sc->sc_xfer[UKBD_INTR_DT_1]);
1420 /* release all leftover keys, if any */
1421 memset(&sc->sc_ndata, 0, sizeof(sc->sc_ndata));
1423 /* process releasing of all keys */
1427 ukbd_disable(&sc->sc_kbd);
1429 #ifdef KBD_INSTALL_CDEV
1430 if (sc->sc_flags & UKBD_FLAG_ATTACHED) {
1431 error = kbd_detach(&sc->sc_kbd);
1433 /* usb attach cannot return an error */
1434 device_printf(dev, "WARNING: kbd_detach() "
1435 "returned non-zero! (ignored)\n");
1440 #ifdef EVDEV_SUPPORT
1441 evdev_free(sc->sc_evdev);
1444 if (KBD_IS_CONFIGURED(&sc->sc_kbd)) {
1445 error = kbd_unregister(&sc->sc_kbd);
1447 /* usb attach cannot return an error */
1448 device_printf(dev, "WARNING: kbd_unregister() "
1449 "returned non-zero! (ignored)\n");
1452 sc->sc_kbd.kb_flags = 0;
1454 usbd_transfer_unsetup(sc->sc_xfer, UKBD_N_TRANSFER);
1456 usb_callout_drain(&sc->sc_callout);
1458 DPRINTF("%s: disconnected\n",
1459 device_get_nameunit(dev));
1465 ukbd_resume(device_t dev)
1467 struct ukbd_softc *sc = device_get_softc(dev);
1471 ukbd_clear_state(&sc->sc_kbd);
1476 #ifdef EVDEV_SUPPORT
1478 ukbd_ev_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
1481 keyboard_t *kbd = evdev_get_softc(evdev);
1483 if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD &&
1484 (type == EV_LED || type == EV_REP)) {
1486 kbd_ev_event(kbd, type, code, value);
1492 /* early keyboard probe, not supported */
1494 ukbd_configure(int flags)
1499 /* detect a keyboard, not used */
1501 ukbd__probe(int unit, void *arg, int flags)
1506 /* reset and initialize the device, not used */
1508 ukbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
1513 /* test the interface to the device, not used */
1515 ukbd_test_if(keyboard_t *kbd)
1520 /* finish using this keyboard, not used */
1522 ukbd_term(keyboard_t *kbd)
1527 /* keyboard interrupt routine, not used */
1529 ukbd_intr(keyboard_t *kbd, void *arg)
1534 /* lock the access to the keyboard, not used */
1536 ukbd_lock(keyboard_t *kbd, int lock)
1542 * Enable the access to the device; until this function is called,
1543 * the client cannot read from the keyboard.
1546 ukbd_enable(keyboard_t *kbd)
1556 /* disallow the access to the device */
1558 ukbd_disable(keyboard_t *kbd)
1562 KBD_DEACTIVATE(kbd);
1568 /* check if data is waiting */
1569 /* Currently unused. */
1571 ukbd_check(keyboard_t *kbd)
1573 struct ukbd_softc *sc = kbd->kb_data;
1577 if (!KBD_IS_ACTIVE(kbd))
1580 if (sc->sc_flags & UKBD_FLAG_POLLING)
1581 ukbd_do_poll(sc, 0);
1583 #ifdef UKBD_EMULATE_ATSCANCODE
1584 if (sc->sc_buffered_char[0]) {
1588 if (sc->sc_inputs > 0) {
1594 /* check if char is waiting */
1596 ukbd_check_char_locked(keyboard_t *kbd)
1598 struct ukbd_softc *sc = kbd->kb_data;
1602 if (!KBD_IS_ACTIVE(kbd))
1605 if ((sc->sc_composed_char > 0) &&
1606 (!(sc->sc_flags & UKBD_FLAG_COMPOSE))) {
1609 return (ukbd_check(kbd));
1613 ukbd_check_char(keyboard_t *kbd)
1618 result = ukbd_check_char_locked(kbd);
1624 /* read one byte from the keyboard if it's allowed */
1625 /* Currently unused. */
1627 ukbd_read(keyboard_t *kbd, int wait)
1629 struct ukbd_softc *sc = kbd->kb_data;
1631 #ifdef UKBD_EMULATE_ATSCANCODE
1639 if (!KBD_IS_ACTIVE(kbd))
1642 #ifdef UKBD_EMULATE_ATSCANCODE
1643 if (sc->sc_buffered_char[0]) {
1644 scancode = sc->sc_buffered_char[0];
1645 if (scancode & SCAN_PREFIX) {
1646 sc->sc_buffered_char[0] &= ~SCAN_PREFIX;
1647 return ((scancode & SCAN_PREFIX_E0) ? 0xe0 : 0xe1);
1649 sc->sc_buffered_char[0] = sc->sc_buffered_char[1];
1650 sc->sc_buffered_char[1] = 0;
1653 #endif /* UKBD_EMULATE_ATSCANCODE */
1656 usbcode = ukbd_get_key(sc, (wait == FALSE) ? 0 : 1);
1657 if (!KBD_IS_ACTIVE(kbd) || (usbcode == -1))
1662 #ifdef UKBD_EMULATE_ATSCANCODE
1663 keycode = ukbd_atkeycode(usbcode, sc->sc_ndata.modifiers);
1664 if (keycode == NN) {
1667 return (ukbd_key2scan(sc, keycode, sc->sc_ndata.modifiers,
1668 (usbcode & KEY_RELEASE)));
1669 #else /* !UKBD_EMULATE_ATSCANCODE */
1671 #endif /* UKBD_EMULATE_ATSCANCODE */
1674 /* read char from the keyboard */
1676 ukbd_read_char_locked(keyboard_t *kbd, int wait)
1678 struct ukbd_softc *sc = kbd->kb_data;
1682 #ifdef UKBD_EMULATE_ATSCANCODE
1688 if (!KBD_IS_ACTIVE(kbd))
1693 /* do we have a composed char to return ? */
1695 if ((sc->sc_composed_char > 0) &&
1696 (!(sc->sc_flags & UKBD_FLAG_COMPOSE))) {
1698 action = sc->sc_composed_char;
1699 sc->sc_composed_char = 0;
1701 if (action > 0xFF) {
1706 #ifdef UKBD_EMULATE_ATSCANCODE
1708 /* do we have a pending raw scan code? */
1710 if (sc->sc_mode == K_RAW) {
1711 scancode = sc->sc_buffered_char[0];
1713 if (scancode & SCAN_PREFIX) {
1714 sc->sc_buffered_char[0] = (scancode & ~SCAN_PREFIX);
1715 return ((scancode & SCAN_PREFIX_E0) ? 0xe0 : 0xe1);
1717 sc->sc_buffered_char[0] = sc->sc_buffered_char[1];
1718 sc->sc_buffered_char[1] = 0;
1722 #endif /* UKBD_EMULATE_ATSCANCODE */
1724 /* see if there is something in the keyboard port */
1726 usbcode = ukbd_get_key(sc, (wait == FALSE) ? 0 : 1);
1727 if (usbcode == -1) {
1732 #ifdef UKBD_EMULATE_ATSCANCODE
1733 /* USB key index -> key code -> AT scan code */
1734 keycode = ukbd_atkeycode(usbcode, sc->sc_ndata.modifiers);
1735 if (keycode == NN) {
1738 /* return an AT scan code for the K_RAW mode */
1739 if (sc->sc_mode == K_RAW) {
1740 return (ukbd_key2scan(sc, keycode, sc->sc_ndata.modifiers,
1741 (usbcode & KEY_RELEASE)));
1743 #else /* !UKBD_EMULATE_ATSCANCODE */
1745 /* return the byte as is for the K_RAW mode */
1746 if (sc->sc_mode == K_RAW) {
1749 /* USB key index -> key code */
1750 keycode = ukbd_trtab[KEY_INDEX(usbcode)];
1751 if (keycode == NN) {
1754 #endif /* UKBD_EMULATE_ATSCANCODE */
1757 case 0x38: /* left alt (compose key) */
1758 if (usbcode & KEY_RELEASE) {
1759 if (sc->sc_flags & UKBD_FLAG_COMPOSE) {
1760 sc->sc_flags &= ~UKBD_FLAG_COMPOSE;
1762 if (sc->sc_composed_char > 0xFF) {
1763 sc->sc_composed_char = 0;
1767 if (!(sc->sc_flags & UKBD_FLAG_COMPOSE)) {
1768 sc->sc_flags |= UKBD_FLAG_COMPOSE;
1769 sc->sc_composed_char = 0;
1775 /* return the key code in the K_CODE mode */
1776 if (usbcode & KEY_RELEASE) {
1777 keycode |= SCAN_RELEASE;
1779 if (sc->sc_mode == K_CODE) {
1782 /* compose a character code */
1783 if (sc->sc_flags & UKBD_FLAG_COMPOSE) {
1785 /* key pressed, process it */
1788 case 0x49: /* keypad 7,8,9 */
1789 sc->sc_composed_char *= 10;
1790 sc->sc_composed_char += keycode - 0x40;
1791 goto check_composed;
1795 case 0x4D: /* keypad 4,5,6 */
1796 sc->sc_composed_char *= 10;
1797 sc->sc_composed_char += keycode - 0x47;
1798 goto check_composed;
1802 case 0x51: /* keypad 1,2,3 */
1803 sc->sc_composed_char *= 10;
1804 sc->sc_composed_char += keycode - 0x4E;
1805 goto check_composed;
1807 case 0x52: /* keypad 0 */
1808 sc->sc_composed_char *= 10;
1809 goto check_composed;
1811 /* key released, no interest here */
1812 case SCAN_RELEASE | 0x47:
1813 case SCAN_RELEASE | 0x48:
1814 case SCAN_RELEASE | 0x49: /* keypad 7,8,9 */
1815 case SCAN_RELEASE | 0x4B:
1816 case SCAN_RELEASE | 0x4C:
1817 case SCAN_RELEASE | 0x4D: /* keypad 4,5,6 */
1818 case SCAN_RELEASE | 0x4F:
1819 case SCAN_RELEASE | 0x50:
1820 case SCAN_RELEASE | 0x51: /* keypad 1,2,3 */
1821 case SCAN_RELEASE | 0x52: /* keypad 0 */
1824 case 0x38: /* left alt key */
1828 if (sc->sc_composed_char > 0) {
1829 sc->sc_flags &= ~UKBD_FLAG_COMPOSE;
1830 sc->sc_composed_char = 0;
1836 /* keycode to key action */
1837 action = genkbd_keyaction(kbd, SCAN_CHAR(keycode),
1838 (keycode & SCAN_RELEASE),
1839 &sc->sc_state, &sc->sc_accents);
1840 if (action == NOKEY) {
1847 if (sc->sc_composed_char <= 0xFF) {
1854 /* Currently wait is always false. */
1856 ukbd_read_char(keyboard_t *kbd, int wait)
1861 keycode = ukbd_read_char_locked(kbd, wait);
1867 /* some useful control functions */
1869 ukbd_ioctl_locked(keyboard_t *kbd, u_long cmd, caddr_t arg)
1871 struct ukbd_softc *sc = kbd->kb_data;
1873 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1874 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1882 case KDGKBMODE: /* get keyboard mode */
1883 *(int *)arg = sc->sc_mode;
1885 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1886 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1888 ival = IOCPARM_IVAL(arg);
1889 arg = (caddr_t)&ival;
1892 case KDSKBMODE: /* set keyboard mode */
1893 switch (*(int *)arg) {
1895 if (sc->sc_mode != K_XLATE) {
1896 /* make lock key state and LED state match */
1897 sc->sc_state &= ~LOCK_MASK;
1898 sc->sc_state |= KBD_LED_VAL(kbd);
1903 if (sc->sc_mode != *(int *)arg) {
1904 if ((sc->sc_flags & UKBD_FLAG_POLLING) == 0)
1905 ukbd_clear_state(kbd);
1906 sc->sc_mode = *(int *)arg;
1914 case KDGETLED: /* get keyboard LED */
1915 *(int *)arg = KBD_LED_VAL(kbd);
1917 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1918 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1920 ival = IOCPARM_IVAL(arg);
1921 arg = (caddr_t)&ival;
1924 case KDSETLED: /* set keyboard LED */
1925 /* NOTE: lock key state in "sc_state" won't be changed */
1926 if (*(int *)arg & ~LOCK_MASK)
1931 /* replace CAPS LED with ALTGR LED for ALTGR keyboards */
1932 if (sc->sc_mode == K_XLATE &&
1933 kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
1939 if (KBD_HAS_DEVICE(kbd))
1940 ukbd_set_leds(sc, i);
1942 KBD_LED_VAL(kbd) = *(int *)arg;
1944 case KDGKBSTATE: /* get lock key state */
1945 *(int *)arg = sc->sc_state & LOCK_MASK;
1947 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1948 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1950 ival = IOCPARM_IVAL(arg);
1951 arg = (caddr_t)&ival;
1954 case KDSKBSTATE: /* set lock key state */
1955 if (*(int *)arg & ~LOCK_MASK) {
1958 sc->sc_state &= ~LOCK_MASK;
1959 sc->sc_state |= *(int *)arg;
1961 /* set LEDs and quit */
1962 return (ukbd_ioctl(kbd, KDSETLED, arg));
1964 case KDSETREPEAT: /* set keyboard repeat rate (new
1966 if (!KBD_HAS_DEVICE(kbd)) {
1970 * Convert negative, zero and tiny args to the same limits
1971 * as atkbd. We could support delays of 1 msec, but
1972 * anything much shorter than the shortest atkbd value
1973 * of 250.34 is almost unusable as well as incompatible.
1975 kbd->kb_delay1 = imax(((int *)arg)[0], 250);
1976 kbd->kb_delay2 = imax(((int *)arg)[1], 34);
1977 #ifdef EVDEV_SUPPORT
1978 if (sc->sc_evdev != NULL)
1979 evdev_push_repeats(sc->sc_evdev, kbd);
1983 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1984 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1986 ival = IOCPARM_IVAL(arg);
1987 arg = (caddr_t)&ival;
1990 case KDSETRAD: /* set keyboard repeat rate (old
1992 return (ukbd_set_typematic(kbd, *(int *)arg));
1994 case PIO_KEYMAP: /* set keyboard translation table */
1995 case OPIO_KEYMAP: /* set keyboard translation table
1997 case PIO_KEYMAPENT: /* set keyboard translation table
1999 case PIO_DEADKEYMAP: /* set accent key translation table */
2003 return (genkbd_commonioctl(kbd, cmd, arg));
2010 ukbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
2015 * XXX Check if someone is calling us from a critical section:
2017 if (curthread->td_critnest != 0)
2021 * XXX KDGKBSTATE, KDSKBSTATE and KDSETLED can be called from any
2022 * context where printf(9) can be called, which among other things
2023 * includes interrupt filters and threads with any kinds of locks
2024 * already held. For this reason it would be dangerous to acquire
2025 * the Giant here unconditionally. On the other hand we have to
2026 * have it to handle the ioctl.
2027 * So we make our best effort to auto-detect whether we can grab
2028 * the Giant or not. Blame syscons(4) for this.
2034 if (!mtx_owned(&Giant) && !USB_IN_POLLING_MODE_FUNC())
2035 return (EDEADLK); /* best I could come up with */
2039 result = ukbd_ioctl_locked(kbd, cmd, arg);
2046 /* clear the internal state of the keyboard */
2048 ukbd_clear_state(keyboard_t *kbd)
2050 struct ukbd_softc *sc = kbd->kb_data;
2054 sc->sc_flags &= ~(UKBD_FLAG_COMPOSE | UKBD_FLAG_POLLING);
2055 sc->sc_state &= LOCK_MASK; /* preserve locking key state */
2057 sc->sc_composed_char = 0;
2058 #ifdef UKBD_EMULATE_ATSCANCODE
2059 sc->sc_buffered_char[0] = 0;
2060 sc->sc_buffered_char[1] = 0;
2062 memset(&sc->sc_ndata, 0, sizeof(sc->sc_ndata));
2063 memset(&sc->sc_odata, 0, sizeof(sc->sc_odata));
2064 memset(&sc->sc_ntime, 0, sizeof(sc->sc_ntime));
2065 memset(&sc->sc_otime, 0, sizeof(sc->sc_otime));
2068 /* save the internal state, not used */
2070 ukbd_get_state(keyboard_t *kbd, void *buf, size_t len)
2072 return (len == 0) ? 1 : -1;
2075 /* set the internal state, not used */
2077 ukbd_set_state(keyboard_t *kbd, void *buf, size_t len)
2083 ukbd_poll(keyboard_t *kbd, int on)
2085 struct ukbd_softc *sc = kbd->kb_data;
2089 * Keep a reference count on polling to allow recursive
2090 * cngrab() during a panic for example.
2094 else if (sc->sc_polling > 0)
2097 if (sc->sc_polling != 0) {
2098 sc->sc_flags |= UKBD_FLAG_POLLING;
2099 sc->sc_poll_thread = curthread;
2101 sc->sc_flags &= ~UKBD_FLAG_POLLING;
2109 /* local functions */
2112 ukbd_set_leds(struct ukbd_softc *sc, uint8_t leds)
2116 DPRINTF("leds=0x%02x\n", leds);
2119 sc->sc_flags |= UKBD_FLAG_SET_LEDS;
2121 /* start transfer, if not already started */
2123 usbd_transfer_start(sc->sc_xfer[UKBD_CTRL_LED]);
2127 ukbd_set_typematic(keyboard_t *kbd, int code)
2129 #ifdef EVDEV_SUPPORT
2130 struct ukbd_softc *sc = kbd->kb_data;
2132 static const int delays[] = {250, 500, 750, 1000};
2133 static const int rates[] = {34, 38, 42, 46, 50, 55, 59, 63,
2134 68, 76, 84, 92, 100, 110, 118, 126,
2135 136, 152, 168, 184, 200, 220, 236, 252,
2136 272, 304, 336, 368, 400, 440, 472, 504};
2141 kbd->kb_delay1 = delays[(code >> 5) & 3];
2142 kbd->kb_delay2 = rates[code & 0x1f];
2143 #ifdef EVDEV_SUPPORT
2144 if (sc->sc_evdev != NULL)
2145 evdev_push_repeats(sc->sc_evdev, kbd);
2150 #ifdef UKBD_EMULATE_ATSCANCODE
2152 ukbd_atkeycode(int usbcode, int shift)
2156 keycode = ukbd_trtab[KEY_INDEX(usbcode)];
2158 * Translate Alt-PrintScreen to SysRq.
2160 * Some or all AT keyboards connected through USB have already
2161 * mapped Alted PrintScreens to an unusual usbcode (0x8a).
2162 * ukbd_trtab translates this to 0x7e, and key2scan() would
2163 * translate that to 0x79 (Intl' 4). Assume that if we have
2164 * an Alted 0x7e here then it actually is an Alted PrintScreen.
2166 * The usual usbcode for all PrintScreens is 0x46. ukbd_trtab
2167 * translates this to 0x5c, so the Alt check to classify 0x5c
2170 if ((keycode == 0x5c || keycode == 0x7e) &&
2171 shift & (MOD_ALT_L | MOD_ALT_R))
2177 ukbd_key2scan(struct ukbd_softc *sc, int code, int shift, int up)
2179 static const int scan[] = {
2185 0x137, /* PrintScreen */
2195 0x151, /* PageDown */
2198 0x146, /* Pause/Break */
2199 0x15b, /* Win_L(Super_L) */
2200 0x15c, /* Win_R(Super_R) */
2201 0x15d, /* Application(Menu) */
2203 /* SUN TYPE 6 USB KEYBOARD */
2204 0x168, /* Sun Type 6 Help */
2205 0x15e, /* Sun Type 6 Stop */
2207 0x15f, /* Sun Type 6 Again */
2208 0x160, /* Sun Type 6 Props */
2209 0x161, /* Sun Type 6 Undo */
2210 0x162, /* Sun Type 6 Front */
2211 0x163, /* Sun Type 6 Copy */
2212 0x164, /* Sun Type 6 Open */
2213 0x165, /* Sun Type 6 Paste */
2214 0x166, /* Sun Type 6 Find */
2215 0x167, /* Sun Type 6 Cut */
2216 0x125, /* Sun Type 6 Mute */
2218 0x11f, /* Sun Type 6 VolumeDown */
2219 0x11e, /* Sun Type 6 VolumeUp */
2220 0x120, /* Sun Type 6 PowerDown */
2222 /* Japanese 106/109 keyboard */
2223 0x73, /* Keyboard Intl' 1 (backslash / underscore) */
2224 0x70, /* Keyboard Intl' 2 (Katakana / Hiragana) */
2225 0x7d, /* Keyboard Intl' 3 (Yen sign) (Not using in jp106/109) */
2226 0x79, /* Keyboard Intl' 4 (Henkan) */
2227 0x7b, /* Keyboard Intl' 5 (Muhenkan) */
2228 0x5c, /* Keyboard Intl' 6 (Keypad ,) (For PC-9821 layout) */
2229 0x71, /* Apple Keyboard JIS (Kana) */
2230 0x72, /* Apple Keyboard JIS (Eisu) */
2233 if ((code >= 89) && (code < (int)(89 + nitems(scan)))) {
2234 code = scan[code - 89];
2237 if (code == 0x137 && (!(shift & (MOD_CONTROL_L | MOD_CONTROL_R |
2238 MOD_SHIFT_L | MOD_SHIFT_R)))) {
2239 code |= SCAN_PREFIX_SHIFT;
2242 if ((code == 0x146) && (!(shift & (MOD_CONTROL_L | MOD_CONTROL_R)))) {
2243 code = (0x45 | SCAN_PREFIX_E1 | SCAN_PREFIX_CTL);
2245 code |= (up ? SCAN_RELEASE : SCAN_PRESS);
2247 if (code & SCAN_PREFIX) {
2248 if (code & SCAN_PREFIX_CTL) {
2250 sc->sc_buffered_char[0] = (0x1d | (code & SCAN_RELEASE));
2251 sc->sc_buffered_char[1] = (code & ~SCAN_PREFIX);
2252 } else if (code & SCAN_PREFIX_SHIFT) {
2254 sc->sc_buffered_char[0] = (0x2a | (code & SCAN_RELEASE));
2255 sc->sc_buffered_char[1] = (code & ~SCAN_PREFIX_SHIFT);
2257 sc->sc_buffered_char[0] = (code & ~SCAN_PREFIX);
2258 sc->sc_buffered_char[1] = 0;
2260 return ((code & SCAN_PREFIX_E0) ? 0xe0 : 0xe1);
2266 #endif /* UKBD_EMULATE_ATSCANCODE */
2268 static keyboard_switch_t ukbdsw = {
2269 .probe = &ukbd__probe,
2273 .test_if = &ukbd_test_if,
2274 .enable = &ukbd_enable,
2275 .disable = &ukbd_disable,
2277 .check = &ukbd_check,
2278 .read_char = &ukbd_read_char,
2279 .check_char = &ukbd_check_char,
2280 .ioctl = &ukbd_ioctl,
2282 .clear_state = &ukbd_clear_state,
2283 .get_state = &ukbd_get_state,
2284 .set_state = &ukbd_set_state,
2288 KEYBOARD_DRIVER(ukbd, ukbdsw, ukbd_configure);
2291 ukbd_driver_load(module_t mod, int what, void *arg)
2296 kbd_add_driver(&ukbd_kbd_driver);
2299 kbd_delete_driver(&ukbd_kbd_driver);
2306 static devclass_t ukbd_devclass;
2308 static device_method_t ukbd_methods[] = {
2309 DEVMETHOD(device_probe, ukbd_probe),
2310 DEVMETHOD(device_attach, ukbd_attach),
2311 DEVMETHOD(device_detach, ukbd_detach),
2312 DEVMETHOD(device_resume, ukbd_resume),
2317 static driver_t ukbd_driver = {
2319 .methods = ukbd_methods,
2320 .size = sizeof(struct ukbd_softc),
2323 DRIVER_MODULE(ukbd, uhub, ukbd_driver, ukbd_devclass, ukbd_driver_load, 0);
2324 MODULE_DEPEND(ukbd, usb, 1, 1, 1);
2325 #ifdef EVDEV_SUPPORT
2326 MODULE_DEPEND(ukbd, evdev, 1, 1, 1);
2328 MODULE_VERSION(ukbd, 1);
2329 USB_PNP_HOST_INFO(ukbd_devs);