Lines Matching full:hid

3  *  USB HID support for Linux
32 #include <linux/hid.h>
34 #include <linux/hid-debug.h>
42 #define DRIVER_DESC "USB HID core driver"
67 MODULE_PARM_DESC(quirks, "Add/modify USB HID quirks by specifying "
74 static void hid_io_error(struct hid_device *hid);
75 static int hid_submit_out(struct hid_device *hid);
76 static int hid_submit_ctrl(struct hid_device *hid);
80 static int hid_start_in(struct hid_device *hid) in hid_start_in() argument
84 struct usbhid_device *usbhid = hid->driver_data; in hid_start_in()
108 struct hid_device *hid = usbhid->hid; in hid_retry_timeout() local
111 if (hid_start_in(hid)) in hid_retry_timeout()
112 hid_io_error(hid); in hid_retry_timeout()
120 struct hid_device *hid = usbhid->hid; in hid_reset() local
125 rc = usb_clear_halt(hid_to_usb_dev(hid), usbhid->urbin->pipe); in hid_reset()
128 hid_start_in(hid); in hid_reset()
143 static void hid_io_error(struct hid_device *hid) in hid_io_error() argument
146 struct usbhid_device *usbhid = hid->driver_data; in hid_io_error()
192 struct hid_device *hid = usb_get_intfdata(usbhid->intf); in usbhid_restart_out_queue() local
196 if (!hid || test_bit(HID_RESET_PENDING, &usbhid->iofl) || in usbhid_restart_out_queue()
201 hid_dbg(hid, "Kicking head %d tail %d", usbhid->outhead, usbhid->outtail); in usbhid_restart_out_queue()
219 if (hid_submit_out(hid)) { in usbhid_restart_out_queue()
230 struct hid_device *hid = usb_get_intfdata(usbhid->intf); in usbhid_restart_ctrl_queue() local
234 WARN_ON(hid == NULL); in usbhid_restart_ctrl_queue()
235 if (!hid || test_bit(HID_RESET_PENDING, &usbhid->iofl) || in usbhid_restart_ctrl_queue()
240 hid_dbg(hid, "Kicking head %d tail %d", usbhid->ctrlhead, usbhid->ctrltail); in usbhid_restart_ctrl_queue()
258 if (hid_submit_ctrl(hid)) { in usbhid_restart_ctrl_queue()
273 struct hid_device *hid = urb->context; in hid_irq_in() local
274 struct usbhid_device *usbhid = hid->driver_data; in hid_irq_in()
292 if (hid_check_keys_pressed(hid)) in hid_irq_in()
315 hid_io_error(hid); in hid_irq_in()
326 hid_err(hid, "can't resubmit intr, %s-%s/input%d, status %d\n", in hid_irq_in()
327 hid_to_usb_dev(hid)->bus->bus_name, in hid_irq_in()
328 hid_to_usb_dev(hid)->devpath, in hid_irq_in()
330 hid_io_error(hid); in hid_irq_in()
335 static int hid_submit_out(struct hid_device *hid) in hid_submit_out() argument
339 struct usbhid_device *usbhid = hid->driver_data; in hid_submit_out()
346 usbhid->urbout->dev = hid_to_usb_dev(hid); in hid_submit_out()
358 hid_err(hid, "usb_submit_urb(out) failed: %d\n", r); in hid_submit_out()
365 static int hid_submit_ctrl(struct hid_device *hid) in hid_submit_ctrl() argument
371 struct usbhid_device *usbhid = hid->driver_data; in hid_submit_ctrl()
379 usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0); in hid_submit_ctrl()
388 usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0); in hid_submit_ctrl()
389 maxpacket = usb_maxpacket(hid_to_usb_dev(hid), in hid_submit_ctrl()
397 usbhid->urbctrl->dev = hid_to_usb_dev(hid); in hid_submit_ctrl()
414 hid_err(hid, "usb_submit_urb(ctrl) failed: %d\n", r); in hid_submit_ctrl()
427 struct hid_device *hid = urb->context; in hid_irq_out() local
428 struct usbhid_device *usbhid = hid->driver_data; in hid_irq_out()
456 hid_submit_out(hid) == 0) { in hid_irq_out()
475 struct hid_device *hid = urb->context; in hid_ctrl() local
476 struct usbhid_device *usbhid = hid->driver_data; in hid_ctrl()
508 hid_submit_ctrl(hid) == 0) { in hid_ctrl()
521 static void __usbhid_submit_report(struct hid_device *hid, struct hid_report *report, in __usbhid_submit_report() argument
525 struct usbhid_device *usbhid = hid->driver_data; in __usbhid_submit_report()
527 if (((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) || in __usbhid_submit_report()
533 hid_warn(hid, "output queue full\n"); in __usbhid_submit_report()
539 hid_warn(hid, "output queueing failed\n"); in __usbhid_submit_report()
581 hid_warn(hid, "control queue full\n"); in __usbhid_submit_report()
588 hid_warn(hid, "control queueing failed\n"); in __usbhid_submit_report()
630 static void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char d… in usbhid_submit_report() argument
632 struct usbhid_device *usbhid = hid->driver_data; in usbhid_submit_report()
636 __usbhid_submit_report(hid, report, dir); in usbhid_submit_report()
640 static int usbhid_wait_io(struct hid_device *hid) in usbhid_wait_io() argument
642 struct usbhid_device *usbhid = hid->driver_data; in usbhid_wait_io()
678 static int usbhid_open(struct hid_device *hid) in usbhid_open() argument
680 struct usbhid_device *usbhid = hid->driver_data; in usbhid_open()
687 if (hid->quirks & HID_QUIRK_ALWAYS_POLL) { in usbhid_open()
705 res = hid_start_in(hid); in usbhid_open()
708 hid_io_error(hid); in usbhid_open()
725 * to go through hid. in usbhid_open()
737 static void usbhid_close(struct hid_device *hid) in usbhid_close() argument
739 struct usbhid_device *usbhid = hid->driver_data; in usbhid_close()
750 if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL)) in usbhid_close()
754 if (!(hid->quirks & HID_QUIRK_ALWAYS_POLL)) { in usbhid_close()
767 void usbhid_init_reports(struct hid_device *hid) in usbhid_init_reports() argument
770 struct usbhid_device *usbhid = hid->driver_data; in usbhid_init_reports()
774 report_enum = &hid->report_enum[HID_INPUT_REPORT]; in usbhid_init_reports()
776 usbhid_submit_report(hid, report, USB_DIR_IN); in usbhid_init_reports()
778 report_enum = &hid->report_enum[HID_FEATURE_REPORT]; in usbhid_init_reports()
780 usbhid_submit_report(hid, report, USB_DIR_IN); in usbhid_init_reports()
783 ret = usbhid_wait_io(hid); in usbhid_init_reports()
790 ret = usbhid_wait_io(hid); in usbhid_init_reports()
794 hid_warn(hid, "timeout initializing reports\n"); in usbhid_init_reports()
800 static int hid_find_field_early(struct hid_device *hid, unsigned int page, in hid_find_field_early() argument
808 list_for_each_entry(report, &hid->report_enum[HID_OUTPUT_REPORT].report_list, list) { in hid_find_field_early()
813 if ((usage->hid & HID_USAGE_PAGE) == page && in hid_find_field_early()
814 (usage->hid & 0xFFFF) == hid_code) { in hid_find_field_early()
824 static void usbhid_set_leds(struct hid_device *hid) in usbhid_set_leds() argument
829 if ((offset = hid_find_field_early(hid, HID_UP_LED, 0x01, &field)) != -1) { in usbhid_set_leds()
831 usbhid_submit_report(hid, field->report, USB_DIR_OUT); in usbhid_set_leds()
838 static void hid_find_max_report(struct hid_device *hid, unsigned int type, in hid_find_max_report() argument
844 list_for_each_entry(report, &hid->report_enum[type].report_list, list) { in hid_find_max_report()
845 size = ((report->size - 1) >> 3) + 1 + hid->report_enum[type].numbered; in hid_find_max_report()
851 static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid) in hid_alloc_buffers() argument
853 struct usbhid_device *usbhid = hid->driver_data; in hid_alloc_buffers()
869 static int usbhid_get_raw_report(struct hid_device *hid, in usbhid_get_raw_report() argument
873 struct usbhid_device *usbhid = hid->driver_data; in usbhid_get_raw_report()
874 struct usb_device *dev = hid_to_usb_dev(hid); in usbhid_get_raw_report()
903 static int usbhid_set_raw_report(struct hid_device *hid, unsigned int reportnum, in usbhid_set_raw_report() argument
906 struct usbhid_device *usbhid = hid->driver_data; in usbhid_set_raw_report()
907 struct usb_device *dev = hid_to_usb_dev(hid); in usbhid_set_raw_report()
914 (hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORT_ID)) in usbhid_set_raw_report()
939 static int usbhid_output_report(struct hid_device *hid, __u8 *buf, size_t count) in usbhid_output_report() argument
941 struct usbhid_device *usbhid = hid->driver_data; in usbhid_output_report()
942 struct usb_device *dev = hid_to_usb_dev(hid); in usbhid_output_report()
969 static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid) in hid_free_buffers() argument
971 struct usbhid_device *usbhid = hid->driver_data; in hid_free_buffers()
979 static int usbhid_parse(struct hid_device *hid) in usbhid_parse() argument
981 struct usb_interface *intf = to_usb_interface(hid->dev.parent); in usbhid_parse()
992 quirks = hid_lookup_quirk(hid); in usbhid_parse()
1013 dbg_hid("hid descriptor is too short\n"); in usbhid_parse()
1017 hid->version = le16_to_cpu(hdesc->bcdHID); in usbhid_parse()
1018 hid->country = hdesc->bCountryCode; in usbhid_parse()
1046 ret = hid_parse_report(hid, rdesc, rsize); in usbhid_parse()
1053 hid->quirks |= quirks; in usbhid_parse()
1060 static int usbhid_start(struct hid_device *hid) in usbhid_start() argument
1062 struct usb_interface *intf = to_usb_interface(hid->dev.parent); in usbhid_start()
1065 struct usbhid_device *usbhid = hid->driver_data; in usbhid_start()
1074 hid_find_max_report(hid, HID_INPUT_REPORT, &usbhid->bufsize); in usbhid_start()
1075 hid_find_max_report(hid, HID_OUTPUT_REPORT, &usbhid->bufsize); in usbhid_start()
1076 hid_find_max_report(hid, HID_FEATURE_REPORT, &usbhid->bufsize); in usbhid_start()
1081 hid_find_max_report(hid, HID_INPUT_REPORT, &insize); in usbhid_start()
1086 if (hid_alloc_buffers(dev, hid)) { in usbhid_start()
1103 if (hid->quirks & HID_QUIRK_FULLSPEED_INTERVAL && in usbhid_start()
1107 hid->name, endpoint->bInterval, interval); in usbhid_start()
1113 switch (hid->collection->usage) { in usbhid_start()
1136 hid_irq_in, hid, interval); in usbhid_start()
1146 hid_irq_out, hid, interval); in usbhid_start()
1159 usbhid->ctrlbuf, 1, hid_ctrl, hid); in usbhid_start()
1165 if (hid->quirks & HID_QUIRK_ALWAYS_POLL) { in usbhid_start()
1171 ret = hid_start_in(hid); in usbhid_start()
1173 dev_err(&hid->dev, in usbhid_start()
1188 usbhid_set_leds(hid); in usbhid_start()
1202 hid_free_buffers(dev, hid); in usbhid_start()
1207 static void usbhid_stop(struct hid_device *hid) in usbhid_stop() argument
1209 struct usbhid_device *usbhid = hid->driver_data; in usbhid_stop()
1214 if (hid->quirks & HID_QUIRK_ALWAYS_POLL) { in usbhid_stop()
1242 hid->claimed = 0; in usbhid_stop()
1251 hid_free_buffers(hid_to_usb_dev(hid), hid); in usbhid_stop()
1256 static int usbhid_power(struct hid_device *hid, int lvl) in usbhid_power() argument
1258 struct usbhid_device *usbhid = hid->driver_data; in usbhid_power()
1274 static void usbhid_request(struct hid_device *hid, struct hid_report *rep, int reqtype) in usbhid_request() argument
1278 usbhid_submit_report(hid, rep, USB_DIR_IN); in usbhid_request()
1281 usbhid_submit_report(hid, rep, USB_DIR_OUT); in usbhid_request()
1286 static int usbhid_raw_request(struct hid_device *hid, unsigned char reportnum, in usbhid_raw_request() argument
1292 return usbhid_get_raw_report(hid, reportnum, buf, len, rtype); in usbhid_raw_request()
1294 return usbhid_set_raw_report(hid, reportnum, buf, len, rtype); in usbhid_raw_request()
1300 static int usbhid_idle(struct hid_device *hid, int report, int idle, in usbhid_idle() argument
1303 struct usb_device *dev = hid_to_usb_dev(hid); in usbhid_idle()
1304 struct usb_interface *intf = to_usb_interface(hid->dev.parent); in usbhid_idle()
1314 static bool usbhid_may_wakeup(struct hid_device *hid) in usbhid_may_wakeup() argument
1316 struct usb_device *dev = hid_to_usb_dev(hid); in usbhid_may_wakeup()
1342 struct hid_device *hid; in usbhid_probe() local
1347 dbg_hid("HID probe called for ifnum %d\n", in usbhid_probe()
1358 hid = hid_allocate_device(); in usbhid_probe()
1359 if (IS_ERR(hid)) in usbhid_probe()
1360 return PTR_ERR(hid); in usbhid_probe()
1362 usb_set_intfdata(intf, hid); in usbhid_probe()
1363 hid->ll_driver = &usb_hid_driver; in usbhid_probe()
1364 hid->ff_init = hid_pidff_init; in usbhid_probe()
1366 hid->hiddev_connect = hiddev_connect; in usbhid_probe()
1367 hid->hiddev_disconnect = hiddev_disconnect; in usbhid_probe()
1368 hid->hiddev_hid_event = hiddev_hid_event; in usbhid_probe()
1369 hid->hiddev_report_event = hiddev_report_event; in usbhid_probe()
1371 hid->dev.parent = &intf->dev; in usbhid_probe()
1372 hid->bus = BUS_USB; in usbhid_probe()
1373 hid->vendor = le16_to_cpu(dev->descriptor.idVendor); in usbhid_probe()
1374 hid->product = le16_to_cpu(dev->descriptor.idProduct); in usbhid_probe()
1375 hid->version = le16_to_cpu(dev->descriptor.bcdDevice); in usbhid_probe()
1376 hid->name[0] = 0; in usbhid_probe()
1379 hid->type = HID_TYPE_USBMOUSE; in usbhid_probe()
1381 hid->type = HID_TYPE_USBNONE; in usbhid_probe()
1384 strscpy(hid->name, dev->manufacturer, sizeof(hid->name)); in usbhid_probe()
1388 strlcat(hid->name, " ", sizeof(hid->name)); in usbhid_probe()
1389 strlcat(hid->name, dev->product, sizeof(hid->name)); in usbhid_probe()
1392 if (!strlen(hid->name)) in usbhid_probe()
1393 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x", in usbhid_probe()
1397 usb_make_path(dev, hid->phys, sizeof(hid->phys)); in usbhid_probe()
1398 strlcat(hid->phys, "/input", sizeof(hid->phys)); in usbhid_probe()
1399 len = strlen(hid->phys); in usbhid_probe()
1400 if (len < sizeof(hid->phys) - 1) in usbhid_probe()
1401 snprintf(hid->phys + len, sizeof(hid->phys) - len, in usbhid_probe()
1404 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) in usbhid_probe()
1405 hid->uniq[0] = 0; in usbhid_probe()
1413 hid->driver_data = usbhid; in usbhid_probe()
1414 usbhid->hid = hid; in usbhid_probe()
1424 ret = hid_add_device(hid); in usbhid_probe()
1427 hid_err(intf, "can't add hid device: %d\n", ret); in usbhid_probe()
1435 hid_destroy_device(hid); in usbhid_probe()
1441 struct hid_device *hid = usb_get_intfdata(intf); in usbhid_disconnect() local
1444 if (WARN_ON(!hid)) in usbhid_disconnect()
1447 usbhid = hid->driver_data; in usbhid_disconnect()
1451 hid_destroy_device(hid); in usbhid_disconnect()
1469 static void hid_restart_io(struct hid_device *hid) in hid_restart_io() argument
1471 struct usbhid_device *usbhid = hid->driver_data; in hid_restart_io()
1488 if (hid_start_in(hid) < 0) in hid_restart_io()
1489 hid_io_error(hid); in hid_restart_io()
1503 struct hid_device *hid = usb_get_intfdata(intf); in hid_pre_reset() local
1504 struct usbhid_device *usbhid = hid->driver_data; in hid_pre_reset()
1518 struct hid_device *hid = usb_get_intfdata(intf); in hid_post_reset() local
1519 struct usbhid_device *usbhid = hid->driver_data; in hid_post_reset()
1524 /* Fetch and examine the HID report descriptor. If this in hid_post_reset()
1527 * the size of the HID report descriptor has not changed. in hid_post_reset()
1529 rdesc = kmalloc(hid->dev_rsize, GFP_KERNEL); in hid_post_reset()
1535 HID_DT_REPORT, rdesc, hid->dev_rsize); in hid_post_reset()
1541 status = memcmp(rdesc, hid->dev_rdesc, hid->dev_rsize); in hid_post_reset()
1555 hid_restart_io(hid); in hid_post_reset()
1561 static int hid_resume_common(struct hid_device *hid, bool driver_suspended) in hid_resume_common() argument
1565 hid_restart_io(hid); in hid_resume_common()
1567 status = hid_driver_resume(hid); in hid_resume_common()
1573 struct hid_device *hid = usb_get_intfdata(intf); in hid_suspend() local
1574 struct usbhid_device *usbhid = hid->driver_data; in hid_suspend()
1580 ledcount = hidinput_count_leds(hid); in hid_suspend()
1591 status = hid_driver_suspend(hid, message); in hid_suspend()
1603 status = hid_driver_suspend(hid, message); in hid_suspend()
1608 if (usbhid_wait_io(hid) < 0) in hid_suspend()
1624 hid_resume_common(hid, driver_suspended); in hid_suspend()
1630 struct hid_device *hid = usb_get_intfdata (intf); in hid_resume() local
1633 status = hid_resume_common(hid, true); in hid_resume()
1640 struct hid_device *hid = usb_get_intfdata(intf); in hid_reset_resume() local
1645 int ret = hid_driver_reset_resume(hid); in hid_reset_resume()