1 /* $NetBSD: uhid.c,v 1.46 2001/11/13 06:24:55 lukem Exp $ */
3 /* Also already merged from NetBSD:
4 * $NetBSD: uhid.c,v 1.54 2002/09/23 05:51:21 simonb Exp $
11 * SPDX-License-Identifier: BSD-2-Clause-NetBSD
13 * Copyright (c) 1998 The NetBSD Foundation, Inc.
14 * All rights reserved.
16 * This code is derived from software contributed to The NetBSD Foundation
17 * by Lennart Augustsson (lennart@augustsson.net) at
18 * Carlstedt Research & Technology.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
29 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
43 * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
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>
65 #include <sys/fcntl.h>
67 #include <dev/hid/hid.h>
70 #include <dev/usb/usb.h>
71 #include <dev/usb/usbdi.h>
72 #include <dev/usb/usbdi_util.h>
73 #include <dev/usb/usbhid.h>
74 #include <dev/usb/usb_ioctl.h>
75 #include <dev/usb/usb_generic.h>
77 #define USB_DEBUG_VAR uhid_debug
78 #include <dev/usb/usb_debug.h>
80 #include <dev/usb/input/usb_rdesc.h>
81 #include <dev/usb/quirk/usb_quirk.h>
84 static int uhid_debug = 0;
86 static SYSCTL_NODE(_hw_usb, OID_AUTO, uhid, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
88 SYSCTL_INT(_hw_usb_uhid, OID_AUTO, debug, CTLFLAG_RWTUN,
89 &uhid_debug, 0, "Debug level");
92 #define UHID_BSIZE 1024 /* bytes, buffer size */
93 #define UHID_FRAME_NUM 50 /* bytes, frame number */
104 struct usb_fifo_sc sc_fifo;
107 struct usb_xfer *sc_xfer[UHID_N_TRANSFER];
108 struct usb_device *sc_udev;
109 void *sc_repdesc_ptr;
115 uint16_t sc_repdesc_size;
118 uint8_t sc_iface_index;
123 #define UHID_FLAG_IMMED 0x01 /* set if read should be immediate */
124 #define UHID_FLAG_STATIC_DESC 0x04 /* set if report descriptors are
128 static const uint8_t uhid_xb360gp_report_descr[] = {UHID_XB360GP_REPORT_DESCR()};
129 static const uint8_t uhid_graphire_report_descr[] = {UHID_GRAPHIRE_REPORT_DESCR()};
130 static const uint8_t uhid_graphire3_4x5_report_descr[] = {UHID_GRAPHIRE3_4X5_REPORT_DESCR()};
134 static device_probe_t uhid_probe;
135 static device_attach_t uhid_attach;
136 static device_detach_t uhid_detach;
138 static usb_callback_t uhid_intr_write_callback;
139 static usb_callback_t uhid_intr_read_callback;
140 static usb_callback_t uhid_write_callback;
141 static usb_callback_t uhid_read_callback;
143 static usb_fifo_cmd_t uhid_start_read;
144 static usb_fifo_cmd_t uhid_stop_read;
145 static usb_fifo_cmd_t uhid_start_write;
146 static usb_fifo_cmd_t uhid_stop_write;
147 static usb_fifo_open_t uhid_open;
148 static usb_fifo_close_t uhid_close;
149 static usb_fifo_ioctl_t uhid_ioctl;
150 static usb_fifo_ioctl_t uhid_ioctl_post;
152 static struct usb_fifo_methods uhid_fifo_methods = {
153 .f_open = &uhid_open,
154 .f_close = &uhid_close,
155 .f_ioctl = &uhid_ioctl,
156 .f_ioctl_post = &uhid_ioctl_post,
157 .f_start_read = &uhid_start_read,
158 .f_stop_read = &uhid_stop_read,
159 .f_start_write = &uhid_start_write,
160 .f_stop_write = &uhid_stop_write,
161 .basename[0] = "uhid",
165 uhid_intr_write_callback(struct usb_xfer *xfer, usb_error_t error)
167 struct uhid_softc *sc = usbd_xfer_softc(xfer);
168 struct usb_page_cache *pc;
171 switch (USB_GET_STATE(xfer)) {
172 case USB_ST_TRANSFERRED:
175 pc = usbd_xfer_get_frame(xfer, 0);
176 if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
177 0, usbd_xfer_max_len(xfer), &actlen, 0)) {
178 usbd_xfer_set_frame_len(xfer, 0, actlen);
179 usbd_transfer_submit(xfer);
184 if (error != USB_ERR_CANCELLED) {
185 /* try to clear stall first */
186 usbd_xfer_set_stall(xfer);
194 uhid_intr_read_callback(struct usb_xfer *xfer, usb_error_t error)
196 struct uhid_softc *sc = usbd_xfer_softc(xfer);
197 struct usb_page_cache *pc;
200 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
202 switch (USB_GET_STATE(xfer)) {
203 case USB_ST_TRANSFERRED:
204 DPRINTF("transferred!\n");
206 pc = usbd_xfer_get_frame(xfer, 0);
209 * If the ID byte is non zero we allow descriptors
210 * having multiple sizes:
212 if ((actlen >= (int)sc->sc_isize) ||
213 ((actlen > 0) && (sc->sc_iid != 0))) {
214 /* limit report length to the maximum */
215 if (actlen > (int)sc->sc_isize)
216 actlen = sc->sc_isize;
217 usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], pc,
221 DPRINTF("ignored transfer, %d bytes\n", actlen);
226 if (usb_fifo_put_bytes_max(
227 sc->sc_fifo.fp[USB_FIFO_RX]) != 0) {
228 usbd_xfer_set_frame_len(xfer, 0, sc->sc_isize);
229 usbd_transfer_submit(xfer);
234 if (error != USB_ERR_CANCELLED) {
235 /* try to clear stall first */
236 usbd_xfer_set_stall(xfer);
244 uhid_fill_set_report(struct usb_device_request *req, uint8_t iface_no,
245 uint8_t type, uint8_t id, uint16_t size)
247 req->bmRequestType = UT_WRITE_CLASS_INTERFACE;
248 req->bRequest = UR_SET_REPORT;
249 USETW2(req->wValue, type, id);
250 req->wIndex[0] = iface_no;
252 USETW(req->wLength, size);
256 uhid_fill_get_report(struct usb_device_request *req, uint8_t iface_no,
257 uint8_t type, uint8_t id, uint16_t size)
259 req->bmRequestType = UT_READ_CLASS_INTERFACE;
260 req->bRequest = UR_GET_REPORT;
261 USETW2(req->wValue, type, id);
262 req->wIndex[0] = iface_no;
264 USETW(req->wLength, size);
268 uhid_write_callback(struct usb_xfer *xfer, usb_error_t error)
270 struct uhid_softc *sc = usbd_xfer_softc(xfer);
271 struct usb_device_request req;
272 struct usb_page_cache *pc;
273 uint32_t size = sc->sc_osize;
277 switch (USB_GET_STATE(xfer)) {
278 case USB_ST_TRANSFERRED:
280 /* try to extract the ID byte */
282 pc = usbd_xfer_get_frame(xfer, 0);
283 if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
288 usbd_copy_out(pc, 0, &id, 1);
300 pc = usbd_xfer_get_frame(xfer, 1);
301 if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
302 0, UHID_BSIZE, &actlen, 1)) {
303 if (actlen != size) {
307 (&req, sc->sc_iface_no,
308 UHID_OUTPUT_REPORT, id, size);
310 pc = usbd_xfer_get_frame(xfer, 0);
311 usbd_copy_in(pc, 0, &req, sizeof(req));
313 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
314 usbd_xfer_set_frame_len(xfer, 1, size);
315 usbd_xfer_set_frames(xfer, size ? 2 : 1);
316 usbd_transfer_submit(xfer);
323 usb_fifo_get_data_error(sc->sc_fifo.fp[USB_FIFO_TX]);
329 uhid_read_callback(struct usb_xfer *xfer, usb_error_t error)
331 struct uhid_softc *sc = usbd_xfer_softc(xfer);
332 struct usb_device_request req;
333 struct usb_page_cache *pc;
335 pc = usbd_xfer_get_frame(xfer, 0);
337 switch (USB_GET_STATE(xfer)) {
338 case USB_ST_TRANSFERRED:
339 usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], pc, sizeof(req),
345 if (usb_fifo_put_bytes_max(sc->sc_fifo.fp[USB_FIFO_RX]) > 0) {
347 (&req, sc->sc_iface_no, UHID_INPUT_REPORT,
348 sc->sc_iid, sc->sc_isize);
350 usbd_copy_in(pc, 0, &req, sizeof(req));
352 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
353 usbd_xfer_set_frame_len(xfer, 1, sc->sc_isize);
354 usbd_xfer_set_frames(xfer, sc->sc_isize ? 2 : 1);
355 usbd_transfer_submit(xfer);
361 usb_fifo_put_data_error(sc->sc_fifo.fp[USB_FIFO_RX]);
366 static const struct usb_config uhid_config[UHID_N_TRANSFER] = {
367 [UHID_INTR_DT_WR] = {
368 .type = UE_INTERRUPT,
369 .endpoint = UE_ADDR_ANY,
370 .direction = UE_DIR_OUT,
371 .flags = {.pipe_bof = 1,.no_pipe_ok = 1, },
372 .bufsize = UHID_BSIZE,
373 .callback = &uhid_intr_write_callback,
376 [UHID_INTR_DT_RD] = {
377 .type = UE_INTERRUPT,
378 .endpoint = UE_ADDR_ANY,
379 .direction = UE_DIR_IN,
380 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
381 .bufsize = UHID_BSIZE,
382 .callback = &uhid_intr_read_callback,
385 [UHID_CTRL_DT_WR] = {
387 .endpoint = 0x00, /* Control pipe */
388 .direction = UE_DIR_ANY,
389 .bufsize = sizeof(struct usb_device_request) + UHID_BSIZE,
390 .callback = &uhid_write_callback,
391 .timeout = 1000, /* 1 second */
394 [UHID_CTRL_DT_RD] = {
396 .endpoint = 0x00, /* Control pipe */
397 .direction = UE_DIR_ANY,
398 .bufsize = sizeof(struct usb_device_request) + UHID_BSIZE,
399 .callback = &uhid_read_callback,
400 .timeout = 1000, /* 1 second */
405 uhid_start_read(struct usb_fifo *fifo)
407 struct uhid_softc *sc = usb_fifo_softc(fifo);
409 if (sc->sc_flags & UHID_FLAG_IMMED) {
410 usbd_transfer_start(sc->sc_xfer[UHID_CTRL_DT_RD]);
412 usbd_transfer_start(sc->sc_xfer[UHID_INTR_DT_RD]);
417 uhid_stop_read(struct usb_fifo *fifo)
419 struct uhid_softc *sc = usb_fifo_softc(fifo);
421 usbd_transfer_stop(sc->sc_xfer[UHID_CTRL_DT_RD]);
422 usbd_transfer_stop(sc->sc_xfer[UHID_INTR_DT_RD]);
426 uhid_start_write(struct usb_fifo *fifo)
428 struct uhid_softc *sc = usb_fifo_softc(fifo);
430 if ((sc->sc_flags & UHID_FLAG_IMMED) ||
431 sc->sc_xfer[UHID_INTR_DT_WR] == NULL) {
432 usbd_transfer_start(sc->sc_xfer[UHID_CTRL_DT_WR]);
434 usbd_transfer_start(sc->sc_xfer[UHID_INTR_DT_WR]);
439 uhid_stop_write(struct usb_fifo *fifo)
441 struct uhid_softc *sc = usb_fifo_softc(fifo);
443 usbd_transfer_stop(sc->sc_xfer[UHID_CTRL_DT_WR]);
444 usbd_transfer_stop(sc->sc_xfer[UHID_INTR_DT_WR]);
448 uhid_get_report(struct uhid_softc *sc, uint8_t type,
449 uint8_t id, void *kern_data, void *user_data,
453 uint8_t free_data = 0;
455 if (kern_data == NULL) {
456 kern_data = malloc(len, M_USBDEV, M_WAITOK);
459 err = usbd_req_get_report(sc->sc_udev, NULL, kern_data,
460 len, sc->sc_iface_index, type, id);
467 err = copyout(kern_data, user_data, len);
474 free(kern_data, M_USBDEV);
480 uhid_set_report(struct uhid_softc *sc, uint8_t type,
481 uint8_t id, void *kern_data, void *user_data,
485 uint8_t free_data = 0;
487 if (kern_data == NULL) {
488 kern_data = malloc(len, M_USBDEV, M_WAITOK);
490 err = copyin(user_data, kern_data, len);
495 err = usbd_req_set_report(sc->sc_udev, NULL, kern_data,
496 len, sc->sc_iface_index, type, id);
503 free(kern_data, M_USBDEV);
509 uhid_open(struct usb_fifo *fifo, int fflags)
511 struct uhid_softc *sc = usb_fifo_softc(fifo);
514 * The buffers are one byte larger than maximum so that one
515 * can detect too large read/writes and short transfers:
517 if (fflags & FREAD) {
519 mtx_lock(&sc->sc_mtx);
520 sc->sc_flags &= ~UHID_FLAG_IMMED;
521 mtx_unlock(&sc->sc_mtx);
523 if (usb_fifo_alloc_buffer(fifo,
524 sc->sc_isize + 1, UHID_FRAME_NUM)) {
528 if (fflags & FWRITE) {
529 if (usb_fifo_alloc_buffer(fifo,
530 sc->sc_osize + 1, UHID_FRAME_NUM)) {
538 uhid_close(struct usb_fifo *fifo, int fflags)
540 if (fflags & (FREAD | FWRITE)) {
541 usb_fifo_free_buffer(fifo);
546 uhid_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr,
549 struct uhid_softc *sc = usb_fifo_softc(fifo);
550 struct usb_gen_descriptor *ugd;
556 case USB_GET_REPORT_DESC:
558 if (sc->sc_repdesc_size > ugd->ugd_maxlen) {
559 size = ugd->ugd_maxlen;
561 size = sc->sc_repdesc_size;
563 ugd->ugd_actlen = size;
564 if (ugd->ugd_data == NULL)
565 break; /* descriptor length only */
566 error = copyout(sc->sc_repdesc_ptr, ugd->ugd_data, size);
570 if (!(fflags & FREAD)) {
577 error = uhid_get_report(sc, UHID_INPUT_REPORT,
578 sc->sc_iid, NULL, NULL, sc->sc_isize);
582 mtx_lock(&sc->sc_mtx);
583 sc->sc_flags |= UHID_FLAG_IMMED;
584 mtx_unlock(&sc->sc_mtx);
586 mtx_lock(&sc->sc_mtx);
587 sc->sc_flags &= ~UHID_FLAG_IMMED;
588 mtx_unlock(&sc->sc_mtx);
593 if (!(fflags & FREAD)) {
598 switch (ugd->ugd_report_type) {
599 case UHID_INPUT_REPORT:
603 case UHID_OUTPUT_REPORT:
607 case UHID_FEATURE_REPORT:
615 copyin(ugd->ugd_data, &id, 1);
616 error = uhid_get_report(sc, ugd->ugd_report_type, id,
617 NULL, ugd->ugd_data, imin(ugd->ugd_maxlen, size));
621 if (!(fflags & FWRITE)) {
626 switch (ugd->ugd_report_type) {
627 case UHID_INPUT_REPORT:
631 case UHID_OUTPUT_REPORT:
635 case UHID_FEATURE_REPORT:
643 copyin(ugd->ugd_data, &id, 1);
644 error = uhid_set_report(sc, ugd->ugd_report_type, id,
645 NULL, ugd->ugd_data, imin(ugd->ugd_maxlen, size));
648 case USB_GET_REPORT_ID:
649 *(int *)addr = 0; /* XXX: we only support reportid 0? */
660 uhid_ioctl_post(struct usb_fifo *fifo, u_long cmd, void *addr,
666 case USB_GET_DEVICEINFO:
667 error = ugen_fill_deviceinfo(fifo, addr);
677 static const STRUCT_USB_HOST_ID uhid_devs[] = {
678 /* generic HID class */
679 {USB_IFACE_CLASS(UICLASS_HID),},
680 /* the Xbox 360 gamepad doesn't use the HID class */
681 {USB_IFACE_CLASS(UICLASS_VENDOR),
682 USB_IFACE_SUBCLASS(UISUBCLASS_XBOX360_CONTROLLER),
683 USB_IFACE_PROTOCOL(UIPROTO_XBOX360_GAMEPAD),},
687 uhid_probe(device_t dev)
689 struct usb_attach_arg *uaa = device_get_ivars(dev);
696 if (uaa->usb_mode != USB_MODE_HOST)
699 error = usbd_lookup_id_by_uaa(uhid_devs, sizeof(uhid_devs), uaa);
703 if (usb_test_quirk(uaa, UQ_HID_IGNORE))
707 * Don't attach to mouse and keyboard devices, hence then no
708 * "nomatch" event is generated and then ums and ukbd won't
709 * attach properly when loaded.
711 if ((uaa->info.bInterfaceClass == UICLASS_HID) &&
712 (uaa->info.bInterfaceSubClass == UISUBCLASS_BOOT) &&
713 (((uaa->info.bInterfaceProtocol == UIPROTO_BOOT_KEYBOARD) &&
714 !usb_test_quirk(uaa, UQ_KBD_IGNORE)) ||
715 ((uaa->info.bInterfaceProtocol == UIPROTO_MOUSE) &&
716 !usb_test_quirk(uaa, UQ_UMS_IGNORE))))
719 /* Check for mandatory multitouch usages to give wmt(4) a chance */
720 if (!usb_test_quirk(uaa, UQ_WMT_IGNORE)) {
721 error = usbd_req_get_hid_desc(uaa->device, NULL,
722 &buf, &len, M_USBDEV, uaa->info.bIfaceIndex);
723 /* Let HID decscriptor-less devices to be handled at attach */
725 if (hid_locate(buf, len,
726 HID_USAGE2(HUP_DIGITIZERS, HUD_CONTACT_MAX),
727 hid_feature, 0, NULL, NULL, NULL) &&
729 HID_USAGE2(HUP_DIGITIZERS, HUD_CONTACTID),
730 hid_input, 0, NULL, NULL, NULL)) {
738 return (BUS_PROBE_GENERIC);
742 uhid_attach(device_t dev)
744 struct usb_attach_arg *uaa = device_get_ivars(dev);
745 struct uhid_softc *sc = device_get_softc(dev);
746 int unit = device_get_unit(dev);
749 DPRINTFN(10, "sc=%p\n", sc);
751 device_set_usb_desc(dev);
753 mtx_init(&sc->sc_mtx, "uhid lock", NULL, MTX_DEF | MTX_RECURSE);
755 sc->sc_udev = uaa->device;
757 sc->sc_iface_no = uaa->info.bIfaceNum;
758 sc->sc_iface_index = uaa->info.bIfaceIndex;
760 error = usbd_transfer_setup(uaa->device,
761 &uaa->info.bIfaceIndex, sc->sc_xfer, uhid_config,
762 UHID_N_TRANSFER, sc, &sc->sc_mtx);
765 DPRINTF("error=%s\n", usbd_errstr(error));
768 if (uaa->info.idVendor == USB_VENDOR_WACOM) {
769 /* the report descriptor for the Wacom Graphire is broken */
771 if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE) {
772 sc->sc_repdesc_size = sizeof(uhid_graphire_report_descr);
773 sc->sc_repdesc_ptr = __DECONST(void *, &uhid_graphire_report_descr);
774 sc->sc_flags |= UHID_FLAG_STATIC_DESC;
776 } else if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE3_4X5) {
777 static uint8_t reportbuf[] = {2, 2, 2};
780 * The Graphire3 needs 0x0202 to be written to
781 * feature report ID 2 before it'll start
782 * returning digitizer data.
784 error = usbd_req_set_report(uaa->device, NULL,
785 reportbuf, sizeof(reportbuf),
786 uaa->info.bIfaceIndex, UHID_FEATURE_REPORT, 2);
789 DPRINTF("set report failed, error=%s (ignored)\n",
792 sc->sc_repdesc_size = sizeof(uhid_graphire3_4x5_report_descr);
793 sc->sc_repdesc_ptr = __DECONST(void *, &uhid_graphire3_4x5_report_descr);
794 sc->sc_flags |= UHID_FLAG_STATIC_DESC;
796 } else if ((uaa->info.bInterfaceClass == UICLASS_VENDOR) &&
797 (uaa->info.bInterfaceSubClass == UISUBCLASS_XBOX360_CONTROLLER) &&
798 (uaa->info.bInterfaceProtocol == UIPROTO_XBOX360_GAMEPAD)) {
799 static const uint8_t reportbuf[3] = {1, 3, 0};
801 * Turn off the four LEDs on the gamepad which
802 * are blinking by default:
804 error = usbd_req_set_report(uaa->device, NULL,
805 __DECONST(void *, reportbuf), sizeof(reportbuf),
806 uaa->info.bIfaceIndex, UHID_OUTPUT_REPORT, 0);
808 DPRINTF("set output report failed, error=%s (ignored)\n",
811 /* the Xbox 360 gamepad has no report descriptor */
812 sc->sc_repdesc_size = sizeof(uhid_xb360gp_report_descr);
813 sc->sc_repdesc_ptr = __DECONST(void *, &uhid_xb360gp_report_descr);
814 sc->sc_flags |= UHID_FLAG_STATIC_DESC;
816 if (sc->sc_repdesc_ptr == NULL) {
817 error = usbd_req_get_hid_desc(uaa->device, NULL,
818 &sc->sc_repdesc_ptr, &sc->sc_repdesc_size,
819 M_USBDEV, uaa->info.bIfaceIndex);
822 device_printf(dev, "no report descriptor\n");
826 error = usbd_req_set_idle(uaa->device, NULL,
827 uaa->info.bIfaceIndex, 0, 0);
830 DPRINTF("set idle failed, error=%s (ignored)\n",
833 sc->sc_isize = hid_report_size_max
834 (sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_input, &sc->sc_iid);
836 sc->sc_osize = hid_report_size_max
837 (sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_output, &sc->sc_oid);
839 sc->sc_fsize = hid_report_size_max
840 (sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_feature, &sc->sc_fid);
842 if (sc->sc_isize > UHID_BSIZE) {
843 DPRINTF("input size is too large, "
844 "%d bytes (truncating)\n",
846 sc->sc_isize = UHID_BSIZE;
848 if (sc->sc_osize > UHID_BSIZE) {
849 DPRINTF("output size is too large, "
850 "%d bytes (truncating)\n",
852 sc->sc_osize = UHID_BSIZE;
854 if (sc->sc_fsize > UHID_BSIZE) {
855 DPRINTF("feature size is too large, "
856 "%d bytes (truncating)\n",
858 sc->sc_fsize = UHID_BSIZE;
861 error = usb_fifo_attach(uaa->device, sc, &sc->sc_mtx,
862 &uhid_fifo_methods, &sc->sc_fifo,
863 unit, -1, uaa->info.bIfaceIndex,
864 UID_ROOT, GID_OPERATOR, 0644);
868 return (0); /* success */
876 uhid_detach(device_t dev)
878 struct uhid_softc *sc = device_get_softc(dev);
880 usb_fifo_detach(&sc->sc_fifo);
882 usbd_transfer_unsetup(sc->sc_xfer, UHID_N_TRANSFER);
884 if (sc->sc_repdesc_ptr) {
885 if (!(sc->sc_flags & UHID_FLAG_STATIC_DESC)) {
886 free(sc->sc_repdesc_ptr, M_USBDEV);
889 mtx_destroy(&sc->sc_mtx);
894 static devclass_t uhid_devclass;
896 static device_method_t uhid_methods[] = {
897 DEVMETHOD(device_probe, uhid_probe),
898 DEVMETHOD(device_attach, uhid_attach),
899 DEVMETHOD(device_detach, uhid_detach),
904 static driver_t uhid_driver = {
906 .methods = uhid_methods,
907 .size = sizeof(struct uhid_softc),
910 DRIVER_MODULE(uhid, uhub, uhid_driver, uhid_devclass, NULL, 0);
911 MODULE_DEPEND(uhid, usb, 1, 1, 1);
912 MODULE_DEPEND(uhid, hid, 1, 1, 1);
913 MODULE_VERSION(uhid, 1);
914 #ifndef USBHID_ENABLED
915 USB_PNP_HOST_INFO(uhid_devs);