Index: head/sys/dev/usb/input/ukbd.c =================================================================== --- head/sys/dev/usb/input/ukbd.c +++ head/sys/dev/usb/input/ukbd.c @@ -40,6 +40,7 @@ #include "opt_compat.h" #include "opt_kbd.h" #include "opt_ukbd.h" +#include "opt_evdev.h" #include #include @@ -71,6 +72,11 @@ #include +#ifdef EVDEV +#include +#include +#endif + #include #include #include @@ -160,6 +166,9 @@ struct usb_device *sc_udev; struct usb_interface *sc_iface; struct usb_xfer *sc_xfer[UKBD_N_TRANSFER]; +#ifdef EVDEV + struct evdev_dev *sc_evdev; +#endif sbintime_t sc_co_basetime; int sc_delay; @@ -354,6 +363,12 @@ static device_detach_t ukbd_detach; static device_resume_t ukbd_resume; +#ifdef EVDEV +static struct evdev_methods ukbd_evdev_methods = { + .ev_event = evdev_ev_kbd_event, +}; +#endif + static uint8_t ukbd_any_key_pressed(struct ukbd_softc *sc) { @@ -388,6 +403,14 @@ DPRINTF("0x%02x (%d) %s\n", key, key, (key & KEY_RELEASE) ? "released" : "pressed"); +#ifdef EVDEV + if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL) { + evdev_push_event(sc->sc_evdev, EV_KEY, + evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE)); + evdev_sync(sc->sc_evdev); + } +#endif + if (sc->sc_inputs < UKBD_IN_BUF_SIZE) { sc->sc_input[sc->sc_inputtail] = key; ++(sc->sc_inputs); @@ -908,6 +931,11 @@ if (!any) break; +#ifdef EVDEV + if (sc->sc_evdev != NULL) + evdev_push_leds(sc->sc_evdev, sc->sc_leds); +#endif + /* range check output report length */ len = sc->sc_led_size; if (len > (UKBD_BUFFER_SIZE - 1)) @@ -1183,6 +1211,10 @@ usb_error_t err; uint16_t n; uint16_t hid_len; +#ifdef EVDEV + struct evdev_dev *evdev; + int i; +#endif #ifdef USB_DEBUG int rate; #endif @@ -1297,6 +1329,37 @@ goto detach; } #endif + +#ifdef EVDEV + evdev = evdev_alloc(); + evdev_set_name(evdev, device_get_desc(dev)); + evdev_set_phys(evdev, device_get_nameunit(dev)); + evdev_set_id(evdev, BUS_USB, uaa->info.idVendor, + uaa->info.idProduct, 0); + evdev_set_serial(evdev, usb_get_serial(uaa->device)); + evdev_set_methods(evdev, kbd, &ukbd_evdev_methods); + evdev_support_event(evdev, EV_SYN); + evdev_support_event(evdev, EV_KEY); + if (sc->sc_flags & (UKBD_FLAG_NUMLOCK | UKBD_FLAG_CAPSLOCK | + UKBD_FLAG_SCROLLLOCK)) + evdev_support_event(evdev, EV_LED); + evdev_support_event(evdev, EV_REP); + + for (i = 0x00; i <= 0xFF; i++) + evdev_support_key(evdev, evdev_hid2key(i)); + if (sc->sc_flags & UKBD_FLAG_NUMLOCK) + evdev_support_led(evdev, LED_NUML); + if (sc->sc_flags & UKBD_FLAG_CAPSLOCK) + evdev_support_led(evdev, LED_CAPSL); + if (sc->sc_flags & UKBD_FLAG_SCROLLLOCK) + evdev_support_led(evdev, LED_SCROLLL); + + if (evdev_register(evdev)) + evdev_free(evdev); + else + sc->sc_evdev = evdev; +#endif + sc->sc_flags |= UKBD_FLAG_ATTACHED; if (bootverbose) { @@ -1367,6 +1430,12 @@ } } #endif + +#ifdef EVDEV + if (sc->sc_evdev != NULL) + evdev_free(sc->sc_evdev); +#endif + if (KBD_IS_CONFIGURED(&sc->sc_kbd)) { error = kbd_unregister(&sc->sc_kbd); if (error) { @@ -1884,6 +1953,10 @@ */ kbd->kb_delay1 = imax(((int *)arg)[0], 250); kbd->kb_delay2 = imax(((int *)arg)[1], 34); +#ifdef EVDEV + if (sc->sc_evdev != NULL) + evdev_push_repeats(sc->sc_evdev, kbd); +#endif return (0); #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ @@ -2032,6 +2105,9 @@ static int ukbd_set_typematic(keyboard_t *kbd, int code) { +#ifdef EVDEV + struct ukbd_softc *sc = kbd->kb_data; +#endif static const int delays[] = {250, 500, 750, 1000}; static const int rates[] = {34, 38, 42, 46, 50, 55, 59, 63, 68, 76, 84, 92, 100, 110, 118, 126, @@ -2043,6 +2119,10 @@ } kbd->kb_delay1 = delays[(code >> 5) & 3]; kbd->kb_delay2 = rates[code & 0x1f]; +#ifdef EVDEV + if (sc->sc_evdev != NULL) + evdev_push_repeats(sc->sc_evdev, kbd); +#endif return (0); } Index: head/sys/modules/usb/ukbd/Makefile =================================================================== --- head/sys/modules/usb/ukbd/Makefile +++ head/sys/modules/usb/ukbd/Makefile @@ -30,7 +30,7 @@ .PATH: $S/dev/usb/input KMOD= ukbd -SRCS= opt_bus.h opt_compat.h opt_kbd.h opt_ukbd.h opt_usb.h \ +SRCS= opt_bus.h opt_compat.h opt_evdev.h opt_kbd.h opt_ukbd.h opt_usb.h \ device_if.h bus_if.h usb_if.h usbdevs.h \ ukbd.c