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
48 #include <sys/stdint.h>
49 #include <sys/stddef.h>
50 #include <sys/param.h>
51 #include <sys/queue.h>
52 #include <sys/types.h>
53 #include <sys/systm.h>
54 #include <sys/kernel.h>
56 #include <sys/module.h>
58 #include <sys/mutex.h>
59 #include <sys/condvar.h>
60 #include <sys/sysctl.h>
62 #include <sys/unistd.h>
63 #include <sys/callout.h>
64 #include <sys/malloc.h>
67 #include <sys/fcntl.h>
69 #include <dev/hid/hid.h>
72 #include <dev/usb/usb.h>
73 #include <dev/usb/usbdi.h>
74 #include <dev/usb/usbdi_util.h>
75 #include <dev/usb/usbhid.h>
76 #include <dev/usb/usb_ioctl.h>
77 #include <dev/usb/usb_generic.h>
79 #define USB_DEBUG_VAR uhid_debug
80 #include <dev/usb/usb_debug.h>
82 #include <dev/usb/input/usb_rdesc.h>
83 #include <dev/usb/quirk/usb_quirk.h>
86 static int uhid_debug = 0;
88 static SYSCTL_NODE(_hw_usb, OID_AUTO, uhid, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
90 SYSCTL_INT(_hw_usb_uhid, OID_AUTO, debug, CTLFLAG_RWTUN,
91 &uhid_debug, 0, "Debug level");
94 #define UHID_BSIZE 1024 /* bytes, buffer size */
95 #define UHID_FRAME_NUM 50 /* bytes, frame number */
106 struct usb_fifo_sc sc_fifo;
109 struct usb_xfer *sc_xfer[UHID_N_TRANSFER];
110 struct usb_device *sc_udev;
111 void *sc_repdesc_ptr;
117 uint16_t sc_repdesc_size;
120 uint8_t sc_iface_index;
125 #define UHID_FLAG_IMMED 0x01 /* set if read should be immediate */
126 #define UHID_FLAG_STATIC_DESC 0x04 /* set if report descriptors are
130 static const uint8_t uhid_xb360gp_report_descr[] = {UHID_XB360GP_REPORT_DESCR()};
131 static const uint8_t uhid_graphire_report_descr[] = {UHID_GRAPHIRE_REPORT_DESCR()};
132 static const uint8_t uhid_graphire3_4x5_report_descr[] = {UHID_GRAPHIRE3_4X5_REPORT_DESCR()};
136 static device_probe_t uhid_probe;
137 static device_attach_t uhid_attach;
138 static device_detach_t uhid_detach;
140 static usb_callback_t uhid_intr_write_callback;
141 static usb_callback_t uhid_intr_read_callback;
142 static usb_callback_t uhid_write_callback;
143 static usb_callback_t uhid_read_callback;
145 static usb_fifo_cmd_t uhid_start_read;
146 static usb_fifo_cmd_t uhid_stop_read;
147 static usb_fifo_cmd_t uhid_start_write;
148 static usb_fifo_cmd_t uhid_stop_write;
149 static usb_fifo_open_t uhid_open;
150 static usb_fifo_close_t uhid_close;
151 static usb_fifo_ioctl_t uhid_ioctl;
152 static usb_fifo_ioctl_t uhid_ioctl_post;
154 static struct usb_fifo_methods uhid_fifo_methods = {
155 .f_open = &uhid_open,
156 .f_close = &uhid_close,
157 .f_ioctl = &uhid_ioctl,
158 .f_ioctl_post = &uhid_ioctl_post,
159 .f_start_read = &uhid_start_read,
160 .f_stop_read = &uhid_stop_read,
161 .f_start_write = &uhid_start_write,
162 .f_stop_write = &uhid_stop_write,
163 .basename[0] = "uhid",
167 uhid_intr_write_callback(struct usb_xfer *xfer, usb_error_t error)
169 struct uhid_softc *sc = usbd_xfer_softc(xfer);
170 struct usb_page_cache *pc;
173 switch (USB_GET_STATE(xfer)) {
174 case USB_ST_TRANSFERRED:
177 pc = usbd_xfer_get_frame(xfer, 0);
178 if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
179 0, usbd_xfer_max_len(xfer), &actlen, 0)) {
180 usbd_xfer_set_frame_len(xfer, 0, actlen);
181 usbd_transfer_submit(xfer);
186 if (error != USB_ERR_CANCELLED) {
187 /* try to clear stall first */
188 usbd_xfer_set_stall(xfer);
196 uhid_intr_read_callback(struct usb_xfer *xfer, usb_error_t error)
198 struct uhid_softc *sc = usbd_xfer_softc(xfer);
199 struct usb_page_cache *pc;
202 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
204 switch (USB_GET_STATE(xfer)) {
205 case USB_ST_TRANSFERRED:
206 DPRINTF("transferred!\n");
208 pc = usbd_xfer_get_frame(xfer, 0);
211 * If the ID byte is non zero we allow descriptors
212 * having multiple sizes:
214 if ((actlen >= (int)sc->sc_isize) ||
215 ((actlen > 0) && (sc->sc_iid != 0))) {
216 /* limit report length to the maximum */
217 if (actlen > (int)sc->sc_isize)
218 actlen = sc->sc_isize;
219 usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], pc,
223 DPRINTF("ignored transfer, %d bytes\n", actlen);
228 if (usb_fifo_put_bytes_max(
229 sc->sc_fifo.fp[USB_FIFO_RX]) != 0) {
230 usbd_xfer_set_frame_len(xfer, 0, sc->sc_isize);
231 usbd_transfer_submit(xfer);
236 if (error != USB_ERR_CANCELLED) {
237 /* try to clear stall first */
238 usbd_xfer_set_stall(xfer);
246 uhid_fill_set_report(struct usb_device_request *req, uint8_t iface_no,
247 uint8_t type, uint8_t id, uint16_t size)
249 req->bmRequestType = UT_WRITE_CLASS_INTERFACE;
250 req->bRequest = UR_SET_REPORT;
251 USETW2(req->wValue, type, id);
252 req->wIndex[0] = iface_no;
254 USETW(req->wLength, size);
258 uhid_fill_get_report(struct usb_device_request *req, uint8_t iface_no,
259 uint8_t type, uint8_t id, uint16_t size)
261 req->bmRequestType = UT_READ_CLASS_INTERFACE;
262 req->bRequest = UR_GET_REPORT;
263 USETW2(req->wValue, type, id);
264 req->wIndex[0] = iface_no;
266 USETW(req->wLength, size);
270 uhid_write_callback(struct usb_xfer *xfer, usb_error_t error)
272 struct uhid_softc *sc = usbd_xfer_softc(xfer);
273 struct usb_device_request req;
274 struct usb_page_cache *pc;
275 uint32_t size = sc->sc_osize;
279 switch (USB_GET_STATE(xfer)) {
280 case USB_ST_TRANSFERRED:
282 /* try to extract the ID byte */
284 pc = usbd_xfer_get_frame(xfer, 0);
285 if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
290 usbd_copy_out(pc, 0, &id, 1);
302 pc = usbd_xfer_get_frame(xfer, 1);
303 if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
304 0, UHID_BSIZE, &actlen, 1)) {
305 if (actlen != size) {
309 (&req, sc->sc_iface_no,
310 UHID_OUTPUT_REPORT, id, size);
312 pc = usbd_xfer_get_frame(xfer, 0);
313 usbd_copy_in(pc, 0, &req, sizeof(req));
315 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
316 usbd_xfer_set_frame_len(xfer, 1, size);
317 usbd_xfer_set_frames(xfer, size ? 2 : 1);
318 usbd_transfer_submit(xfer);
325 usb_fifo_get_data_error(sc->sc_fifo.fp[USB_FIFO_TX]);
331 uhid_read_callback(struct usb_xfer *xfer, usb_error_t error)
333 struct uhid_softc *sc = usbd_xfer_softc(xfer);
334 struct usb_device_request req;
335 struct usb_page_cache *pc;
337 pc = usbd_xfer_get_frame(xfer, 0);
339 switch (USB_GET_STATE(xfer)) {
340 case USB_ST_TRANSFERRED:
341 usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], pc, sizeof(req),
347 if (usb_fifo_put_bytes_max(sc->sc_fifo.fp[USB_FIFO_RX]) > 0) {
349 (&req, sc->sc_iface_no, UHID_INPUT_REPORT,
350 sc->sc_iid, sc->sc_isize);
352 usbd_copy_in(pc, 0, &req, sizeof(req));
354 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
355 usbd_xfer_set_frame_len(xfer, 1, sc->sc_isize);
356 usbd_xfer_set_frames(xfer, sc->sc_isize ? 2 : 1);
357 usbd_transfer_submit(xfer);
363 usb_fifo_put_data_error(sc->sc_fifo.fp[USB_FIFO_RX]);
368 static const struct usb_config uhid_config[UHID_N_TRANSFER] = {
369 [UHID_INTR_DT_WR] = {
370 .type = UE_INTERRUPT,
371 .endpoint = UE_ADDR_ANY,
372 .direction = UE_DIR_OUT,
373 .flags = {.pipe_bof = 1,.no_pipe_ok = 1, },
374 .bufsize = UHID_BSIZE,
375 .callback = &uhid_intr_write_callback,
378 [UHID_INTR_DT_RD] = {
379 .type = UE_INTERRUPT,
380 .endpoint = UE_ADDR_ANY,
381 .direction = UE_DIR_IN,
382 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
383 .bufsize = UHID_BSIZE,
384 .callback = &uhid_intr_read_callback,
387 [UHID_CTRL_DT_WR] = {
389 .endpoint = 0x00, /* Control pipe */
390 .direction = UE_DIR_ANY,
391 .bufsize = sizeof(struct usb_device_request) + UHID_BSIZE,
392 .callback = &uhid_write_callback,
393 .timeout = 1000, /* 1 second */
396 [UHID_CTRL_DT_RD] = {
398 .endpoint = 0x00, /* Control pipe */
399 .direction = UE_DIR_ANY,
400 .bufsize = sizeof(struct usb_device_request) + UHID_BSIZE,
401 .callback = &uhid_read_callback,
402 .timeout = 1000, /* 1 second */
407 uhid_start_read(struct usb_fifo *fifo)
409 struct uhid_softc *sc = usb_fifo_softc(fifo);
411 if (sc->sc_flags & UHID_FLAG_IMMED) {
412 usbd_transfer_start(sc->sc_xfer[UHID_CTRL_DT_RD]);
414 usbd_transfer_start(sc->sc_xfer[UHID_INTR_DT_RD]);
419 uhid_stop_read(struct usb_fifo *fifo)
421 struct uhid_softc *sc = usb_fifo_softc(fifo);
423 usbd_transfer_stop(sc->sc_xfer[UHID_CTRL_DT_RD]);
424 usbd_transfer_stop(sc->sc_xfer[UHID_INTR_DT_RD]);
428 uhid_start_write(struct usb_fifo *fifo)
430 struct uhid_softc *sc = usb_fifo_softc(fifo);
432 if ((sc->sc_flags & UHID_FLAG_IMMED) ||
433 sc->sc_xfer[UHID_INTR_DT_WR] == NULL) {
434 usbd_transfer_start(sc->sc_xfer[UHID_CTRL_DT_WR]);
436 usbd_transfer_start(sc->sc_xfer[UHID_INTR_DT_WR]);
441 uhid_stop_write(struct usb_fifo *fifo)
443 struct uhid_softc *sc = usb_fifo_softc(fifo);
445 usbd_transfer_stop(sc->sc_xfer[UHID_CTRL_DT_WR]);
446 usbd_transfer_stop(sc->sc_xfer[UHID_INTR_DT_WR]);
450 uhid_get_report(struct uhid_softc *sc, uint8_t type,
451 uint8_t id, void *kern_data, void *user_data,
455 uint8_t free_data = 0;
457 if (kern_data == NULL) {
458 kern_data = malloc(len, M_USBDEV, M_WAITOK);
461 err = usbd_req_get_report(sc->sc_udev, NULL, kern_data,
462 len, sc->sc_iface_index, type, id);
469 err = copyout(kern_data, user_data, len);
476 free(kern_data, M_USBDEV);
482 uhid_set_report(struct uhid_softc *sc, uint8_t type,
483 uint8_t id, void *kern_data, void *user_data,
487 uint8_t free_data = 0;
489 if (kern_data == NULL) {
490 kern_data = malloc(len, M_USBDEV, M_WAITOK);
492 err = copyin(user_data, kern_data, len);
497 err = usbd_req_set_report(sc->sc_udev, NULL, kern_data,
498 len, sc->sc_iface_index, type, id);
505 free(kern_data, M_USBDEV);
511 uhid_open(struct usb_fifo *fifo, int fflags)
513 struct uhid_softc *sc = usb_fifo_softc(fifo);
516 * The buffers are one byte larger than maximum so that one
517 * can detect too large read/writes and short transfers:
519 if (fflags & FREAD) {
521 mtx_lock(&sc->sc_mtx);
522 sc->sc_flags &= ~UHID_FLAG_IMMED;
523 mtx_unlock(&sc->sc_mtx);
525 if (usb_fifo_alloc_buffer(fifo,
526 sc->sc_isize + 1, UHID_FRAME_NUM)) {
530 if (fflags & FWRITE) {
531 if (usb_fifo_alloc_buffer(fifo,
532 sc->sc_osize + 1, UHID_FRAME_NUM)) {
540 uhid_close(struct usb_fifo *fifo, int fflags)
542 if (fflags & (FREAD | FWRITE)) {
543 usb_fifo_free_buffer(fifo);
548 uhid_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr,
551 struct uhid_softc *sc = usb_fifo_softc(fifo);
552 struct usb_gen_descriptor *ugd;
558 case USB_GET_REPORT_DESC:
560 if (sc->sc_repdesc_size > ugd->ugd_maxlen) {
561 size = ugd->ugd_maxlen;
563 size = sc->sc_repdesc_size;
565 ugd->ugd_actlen = size;
566 if (ugd->ugd_data == NULL)
567 break; /* descriptor length only */
568 error = copyout(sc->sc_repdesc_ptr, ugd->ugd_data, size);
572 if (!(fflags & FREAD)) {
579 error = uhid_get_report(sc, UHID_INPUT_REPORT,
580 sc->sc_iid, NULL, NULL, sc->sc_isize);
584 mtx_lock(&sc->sc_mtx);
585 sc->sc_flags |= UHID_FLAG_IMMED;
586 mtx_unlock(&sc->sc_mtx);
588 mtx_lock(&sc->sc_mtx);
589 sc->sc_flags &= ~UHID_FLAG_IMMED;
590 mtx_unlock(&sc->sc_mtx);
595 if (!(fflags & FREAD)) {
600 switch (ugd->ugd_report_type) {
601 case UHID_INPUT_REPORT:
605 case UHID_OUTPUT_REPORT:
609 case UHID_FEATURE_REPORT:
617 copyin(ugd->ugd_data, &id, 1);
618 error = uhid_get_report(sc, ugd->ugd_report_type, id,
619 NULL, ugd->ugd_data, imin(ugd->ugd_maxlen, size));
623 if (!(fflags & FWRITE)) {
628 switch (ugd->ugd_report_type) {
629 case UHID_INPUT_REPORT:
633 case UHID_OUTPUT_REPORT:
637 case UHID_FEATURE_REPORT:
645 copyin(ugd->ugd_data, &id, 1);
646 error = uhid_set_report(sc, ugd->ugd_report_type, id,
647 NULL, ugd->ugd_data, imin(ugd->ugd_maxlen, size));
650 case USB_GET_REPORT_ID:
651 *(int *)addr = 0; /* XXX: we only support reportid 0? */
662 uhid_ioctl_post(struct usb_fifo *fifo, u_long cmd, void *addr,
668 case USB_GET_DEVICEINFO:
669 error = ugen_fill_deviceinfo(fifo, addr);
679 static const STRUCT_USB_HOST_ID uhid_devs[] = {
680 /* generic HID class */
681 {USB_IFACE_CLASS(UICLASS_HID),},
682 /* the Xbox 360 gamepad doesn't use the HID class */
683 {USB_IFACE_CLASS(UICLASS_VENDOR),
684 USB_IFACE_SUBCLASS(UISUBCLASS_XBOX360_CONTROLLER),
685 USB_IFACE_PROTOCOL(UIPROTO_XBOX360_GAMEPAD),},
689 uhid_probe(device_t dev)
691 struct usb_attach_arg *uaa = device_get_ivars(dev);
698 if (uaa->usb_mode != USB_MODE_HOST)
701 error = usbd_lookup_id_by_uaa(uhid_devs, sizeof(uhid_devs), uaa);
705 if (usb_test_quirk(uaa, UQ_HID_IGNORE))
709 * Don't attach to mouse and keyboard devices, hence then no
710 * "nomatch" event is generated and then ums and ukbd won't
711 * attach properly when loaded.
713 if ((uaa->info.bInterfaceClass == UICLASS_HID) &&
714 (uaa->info.bInterfaceSubClass == UISUBCLASS_BOOT) &&
715 (((uaa->info.bInterfaceProtocol == UIPROTO_BOOT_KEYBOARD) &&
716 !usb_test_quirk(uaa, UQ_KBD_IGNORE)) ||
717 ((uaa->info.bInterfaceProtocol == UIPROTO_MOUSE) &&
718 !usb_test_quirk(uaa, UQ_UMS_IGNORE))))
721 /* Check for mandatory multitouch usages to give wmt(4) a chance */
722 if (!usb_test_quirk(uaa, UQ_WMT_IGNORE)) {
723 error = usbd_req_get_hid_desc(uaa->device, NULL,
724 &buf, &len, M_USBDEV, uaa->info.bIfaceIndex);
725 /* Let HID decscriptor-less devices to be handled at attach */
727 if (hid_locate(buf, len,
728 HID_USAGE2(HUP_DIGITIZERS, HUD_CONTACT_MAX),
729 hid_feature, 0, NULL, NULL, NULL) &&
731 HID_USAGE2(HUP_DIGITIZERS, HUD_CONTACTID),
732 hid_input, 0, NULL, NULL, NULL)) {
740 return (BUS_PROBE_GENERIC);
744 uhid_attach(device_t dev)
746 struct usb_attach_arg *uaa = device_get_ivars(dev);
747 struct uhid_softc *sc = device_get_softc(dev);
748 int unit = device_get_unit(dev);
751 DPRINTFN(10, "sc=%p\n", sc);
753 device_set_usb_desc(dev);
755 mtx_init(&sc->sc_mtx, "uhid lock", NULL, MTX_DEF | MTX_RECURSE);
757 sc->sc_udev = uaa->device;
759 sc->sc_iface_no = uaa->info.bIfaceNum;
760 sc->sc_iface_index = uaa->info.bIfaceIndex;
762 error = usbd_transfer_setup(uaa->device,
763 &uaa->info.bIfaceIndex, sc->sc_xfer, uhid_config,
764 UHID_N_TRANSFER, sc, &sc->sc_mtx);
767 DPRINTF("error=%s\n", usbd_errstr(error));
770 if (uaa->info.idVendor == USB_VENDOR_WACOM) {
771 /* the report descriptor for the Wacom Graphire is broken */
773 if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE) {
774 sc->sc_repdesc_size = sizeof(uhid_graphire_report_descr);
775 sc->sc_repdesc_ptr = __DECONST(void *, &uhid_graphire_report_descr);
776 sc->sc_flags |= UHID_FLAG_STATIC_DESC;
778 } else if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE3_4X5) {
779 static uint8_t reportbuf[] = {2, 2, 2};
782 * The Graphire3 needs 0x0202 to be written to
783 * feature report ID 2 before it'll start
784 * returning digitizer data.
786 error = usbd_req_set_report(uaa->device, NULL,
787 reportbuf, sizeof(reportbuf),
788 uaa->info.bIfaceIndex, UHID_FEATURE_REPORT, 2);
791 DPRINTF("set report failed, error=%s (ignored)\n",
794 sc->sc_repdesc_size = sizeof(uhid_graphire3_4x5_report_descr);
795 sc->sc_repdesc_ptr = __DECONST(void *, &uhid_graphire3_4x5_report_descr);
796 sc->sc_flags |= UHID_FLAG_STATIC_DESC;
798 } else if ((uaa->info.bInterfaceClass == UICLASS_VENDOR) &&
799 (uaa->info.bInterfaceSubClass == UISUBCLASS_XBOX360_CONTROLLER) &&
800 (uaa->info.bInterfaceProtocol == UIPROTO_XBOX360_GAMEPAD)) {
801 static const uint8_t reportbuf[3] = {1, 3, 0};
803 * Turn off the four LEDs on the gamepad which
804 * are blinking by default:
806 error = usbd_req_set_report(uaa->device, NULL,
807 __DECONST(void *, reportbuf), sizeof(reportbuf),
808 uaa->info.bIfaceIndex, UHID_OUTPUT_REPORT, 0);
810 DPRINTF("set output report failed, error=%s (ignored)\n",
813 /* the Xbox 360 gamepad has no report descriptor */
814 sc->sc_repdesc_size = sizeof(uhid_xb360gp_report_descr);
815 sc->sc_repdesc_ptr = __DECONST(void *, &uhid_xb360gp_report_descr);
816 sc->sc_flags |= UHID_FLAG_STATIC_DESC;
818 if (sc->sc_repdesc_ptr == NULL) {
819 error = usbd_req_get_hid_desc(uaa->device, NULL,
820 &sc->sc_repdesc_ptr, &sc->sc_repdesc_size,
821 M_USBDEV, uaa->info.bIfaceIndex);
824 device_printf(dev, "no report descriptor\n");
828 error = usbd_req_set_idle(uaa->device, NULL,
829 uaa->info.bIfaceIndex, 0, 0);
832 DPRINTF("set idle failed, error=%s (ignored)\n",
835 sc->sc_isize = hid_report_size_max
836 (sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_input, &sc->sc_iid);
838 sc->sc_osize = hid_report_size_max
839 (sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_output, &sc->sc_oid);
841 sc->sc_fsize = hid_report_size_max
842 (sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_feature, &sc->sc_fid);
844 if (sc->sc_isize > UHID_BSIZE) {
845 DPRINTF("input size is too large, "
846 "%d bytes (truncating)\n",
848 sc->sc_isize = UHID_BSIZE;
850 if (sc->sc_osize > UHID_BSIZE) {
851 DPRINTF("output size is too large, "
852 "%d bytes (truncating)\n",
854 sc->sc_osize = UHID_BSIZE;
856 if (sc->sc_fsize > UHID_BSIZE) {
857 DPRINTF("feature size is too large, "
858 "%d bytes (truncating)\n",
860 sc->sc_fsize = UHID_BSIZE;
863 error = usb_fifo_attach(uaa->device, sc, &sc->sc_mtx,
864 &uhid_fifo_methods, &sc->sc_fifo,
865 unit, -1, uaa->info.bIfaceIndex,
866 UID_ROOT, GID_OPERATOR, 0644);
870 return (0); /* success */
878 uhid_detach(device_t dev)
880 struct uhid_softc *sc = device_get_softc(dev);
882 usb_fifo_detach(&sc->sc_fifo);
884 usbd_transfer_unsetup(sc->sc_xfer, UHID_N_TRANSFER);
886 if (sc->sc_repdesc_ptr) {
887 if (!(sc->sc_flags & UHID_FLAG_STATIC_DESC)) {
888 free(sc->sc_repdesc_ptr, M_USBDEV);
891 mtx_destroy(&sc->sc_mtx);
896 #ifndef HIDRAW_MAKE_UHID_ALIAS
897 static devclass_t uhid_devclass;
900 static device_method_t uhid_methods[] = {
901 DEVMETHOD(device_probe, uhid_probe),
902 DEVMETHOD(device_attach, uhid_attach),
903 DEVMETHOD(device_detach, uhid_detach),
908 static driver_t uhid_driver = {
909 #ifdef HIDRAW_MAKE_UHID_ALIAS
914 .methods = uhid_methods,
915 .size = sizeof(struct uhid_softc),
918 #ifdef HIDRAW_MAKE_UHID_ALIAS
919 DRIVER_MODULE(uhid, uhub, uhid_driver, hidraw_devclass, NULL, 0);
921 DRIVER_MODULE(uhid, uhub, uhid_driver, uhid_devclass, NULL, 0);
923 MODULE_DEPEND(uhid, usb, 1, 1, 1);
924 MODULE_DEPEND(uhid, hid, 1, 1, 1);
925 MODULE_VERSION(uhid, 1);
926 USB_PNP_HOST_INFO(uhid_devs);