usbhid.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __USBHID_H
  3. #define __USBHID_H
  4. /*
  5. * Copyright (c) 1999 Andreas Gal
  6. * Copyright (c) 2000-2001 Vojtech Pavlik
  7. * Copyright (c) 2006 Jiri Kosina
  8. */
  9. /*
  10. */
  11. #include <linux/types.h>
  12. #include <linux/slab.h>
  13. #include <linux/list.h>
  14. #include <linux/mutex.h>
  15. #include <linux/timer.h>
  16. #include <linux/wait.h>
  17. #include <linux/workqueue.h>
  18. #include <linux/input.h>
  19. /* API provided by hid-core.c for USB HID drivers */
  20. void usbhid_init_reports(struct hid_device *hid);
  21. struct usb_interface *usbhid_find_interface(int minor);
  22. /* iofl flags */
  23. #define HID_CTRL_RUNNING 1
  24. #define HID_OUT_RUNNING 2
  25. #define HID_IN_RUNNING 3
  26. #define HID_RESET_PENDING 4
  27. #define HID_SUSPENDED 5
  28. #define HID_CLEAR_HALT 6
  29. #define HID_DISCONNECTED 7
  30. #define HID_STARTED 8
  31. #define HID_KEYS_PRESSED 10
  32. #define HID_NO_BANDWIDTH 11
  33. #define HID_RESUME_RUNNING 12
  34. /*
  35. * The device is opened, meaning there is a client that is interested
  36. * in data coming from the device.
  37. */
  38. #define HID_OPENED 13
  39. /*
  40. * We are polling input endpoint by [re]submitting IN URB, because
  41. * either HID device is opened or ALWAYS POLL quirk is set for the
  42. * device.
  43. */
  44. #define HID_IN_POLLING 14
  45. /*
  46. * USB-specific HID struct, to be pointed to
  47. * from struct hid_device->driver_data
  48. */
  49. struct usbhid_device {
  50. struct hid_device *hid; /* pointer to corresponding HID dev */
  51. struct usb_interface *intf; /* USB interface */
  52. int ifnum; /* USB interface number */
  53. unsigned int bufsize; /* URB buffer size */
  54. struct urb *urbin; /* Input URB */
  55. char *inbuf; /* Input buffer */
  56. dma_addr_t inbuf_dma; /* Input buffer dma */
  57. struct urb *urbctrl; /* Control URB */
  58. struct usb_ctrlrequest *cr; /* Control request struct */
  59. struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */
  60. unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */
  61. char *ctrlbuf; /* Control buffer */
  62. dma_addr_t ctrlbuf_dma; /* Control buffer dma */
  63. unsigned long last_ctrl; /* record of last output for timeouts */
  64. struct urb *urbout; /* Output URB */
  65. struct hid_output_fifo out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */
  66. unsigned char outhead, outtail; /* Output pipe fifo head & tail */
  67. char *outbuf; /* Output buffer */
  68. dma_addr_t outbuf_dma; /* Output buffer dma */
  69. unsigned long last_out; /* record of last output for timeouts */
  70. struct mutex mutex; /* start/stop/open/close */
  71. spinlock_t lock; /* fifo spinlock */
  72. unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
  73. struct timer_list io_retry; /* Retry timer */
  74. unsigned long stop_retry; /* Time to give up, in jiffies */
  75. unsigned int retry_delay; /* Delay length in ms */
  76. struct work_struct reset_work; /* Task context for resets */
  77. wait_queue_head_t wait; /* For sleeping */
  78. };
  79. #define hid_to_usb_dev(hid_dev) \
  80. to_usb_device(hid_dev->dev.parent->parent)
  81. #endif