11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 26db3dfefSJiri Kosina #ifndef __USBHID_H 36db3dfefSJiri Kosina #define __USBHID_H 46db3dfefSJiri Kosina 56db3dfefSJiri Kosina /* 66db3dfefSJiri Kosina * Copyright (c) 1999 Andreas Gal 76db3dfefSJiri Kosina * Copyright (c) 2000-2001 Vojtech Pavlik 86db3dfefSJiri Kosina * Copyright (c) 2006 Jiri Kosina 96db3dfefSJiri Kosina */ 106db3dfefSJiri Kosina 116db3dfefSJiri Kosina /* 126db3dfefSJiri Kosina */ 136db3dfefSJiri Kosina 146db3dfefSJiri Kosina #include <linux/types.h> 156db3dfefSJiri Kosina #include <linux/slab.h> 166db3dfefSJiri Kosina #include <linux/list.h> 173d5afd32SJiri Slaby #include <linux/mutex.h> 186db3dfefSJiri Kosina #include <linux/timer.h> 191d1bdd20SJiri Slaby #include <linux/wait.h> 206db3dfefSJiri Kosina #include <linux/workqueue.h> 216db3dfefSJiri Kosina #include <linux/input.h> 226db3dfefSJiri Kosina 236db3dfefSJiri Kosina /* API provided by hid-core.c for USB HID drivers */ 246db3dfefSJiri Kosina void usbhid_init_reports(struct hid_device *hid); 258fe294caSGuillaume Chazarain struct usb_interface *usbhid_find_interface(int minor); 266db3dfefSJiri Kosina 270ed94b33SJiri Slaby /* iofl flags */ 280ed94b33SJiri Slaby #define HID_CTRL_RUNNING 1 290ed94b33SJiri Slaby #define HID_OUT_RUNNING 2 300ed94b33SJiri Slaby #define HID_IN_RUNNING 3 310ed94b33SJiri Slaby #define HID_RESET_PENDING 4 320ed94b33SJiri Slaby #define HID_SUSPENDED 5 330ed94b33SJiri Slaby #define HID_CLEAR_HALT 6 340ed94b33SJiri Slaby #define HID_DISCONNECTED 7 350ed94b33SJiri Slaby #define HID_STARTED 8 360361a28dSOliver Neukum #define HID_KEYS_PRESSED 10 37a8c52b66SOliver Neukum #define HID_NO_BANDWIDTH 11 38b905811aSBenjamin Tissoires #define HID_RESUME_RUNNING 12 3928cbc863SDmitry Torokhov /* 4028cbc863SDmitry Torokhov * The device is opened, meaning there is a client that is interested 4128cbc863SDmitry Torokhov * in data coming from the device. 4228cbc863SDmitry Torokhov */ 4328cbc863SDmitry Torokhov #define HID_OPENED 13 4428cbc863SDmitry Torokhov /* 4528cbc863SDmitry Torokhov * We are polling input endpoint by [re]submitting IN URB, because 4628cbc863SDmitry Torokhov * either HID device is opened or ALWAYS POLL quirk is set for the 4728cbc863SDmitry Torokhov * device. 4828cbc863SDmitry Torokhov */ 4928cbc863SDmitry Torokhov #define HID_IN_POLLING 14 500ed94b33SJiri Slaby 516db3dfefSJiri Kosina /* 526db3dfefSJiri Kosina * USB-specific HID struct, to be pointed to 536db3dfefSJiri Kosina * from struct hid_device->driver_data 546db3dfefSJiri Kosina */ 556db3dfefSJiri Kosina 566db3dfefSJiri Kosina struct usbhid_device { 576db3dfefSJiri Kosina struct hid_device *hid; /* pointer to corresponding HID dev */ 586db3dfefSJiri Kosina 596db3dfefSJiri Kosina struct usb_interface *intf; /* USB interface */ 606db3dfefSJiri Kosina int ifnum; /* USB interface number */ 616db3dfefSJiri Kosina 626db3dfefSJiri Kosina unsigned int bufsize; /* URB buffer size */ 636db3dfefSJiri Kosina 646db3dfefSJiri Kosina struct urb *urbin; /* Input URB */ 656db3dfefSJiri Kosina char *inbuf; /* Input buffer */ 666db3dfefSJiri Kosina dma_addr_t inbuf_dma; /* Input buffer dma */ 676db3dfefSJiri Kosina 686db3dfefSJiri Kosina struct urb *urbctrl; /* Control URB */ 696db3dfefSJiri Kosina struct usb_ctrlrequest *cr; /* Control request struct */ 706db3dfefSJiri Kosina struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */ 716db3dfefSJiri Kosina unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */ 726db3dfefSJiri Kosina char *ctrlbuf; /* Control buffer */ 736db3dfefSJiri Kosina dma_addr_t ctrlbuf_dma; /* Control buffer dma */ 74858155fbSOliver Neukum unsigned long last_ctrl; /* record of last output for timeouts */ 756db3dfefSJiri Kosina 766db3dfefSJiri Kosina struct urb *urbout; /* Output URB */ 77f129ea6dSAnssi Hannula struct hid_output_fifo out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */ 786db3dfefSJiri Kosina unsigned char outhead, outtail; /* Output pipe fifo head & tail */ 796db3dfefSJiri Kosina char *outbuf; /* Output buffer */ 806db3dfefSJiri Kosina dma_addr_t outbuf_dma; /* Output buffer dma */ 81858155fbSOliver Neukum unsigned long last_out; /* record of last output for timeouts */ 826db3dfefSJiri Kosina 83*0ed08fadSAlan Stern struct mutex mutex; /* start/stop/open/close */ 840361a28dSOliver Neukum spinlock_t lock; /* fifo spinlock */ 856db3dfefSJiri Kosina unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ 866db3dfefSJiri Kosina struct timer_list io_retry; /* Retry timer */ 876db3dfefSJiri Kosina unsigned long stop_retry; /* Time to give up, in jiffies */ 886db3dfefSJiri Kosina unsigned int retry_delay; /* Delay length in ms */ 896db3dfefSJiri Kosina struct work_struct reset_work; /* Task context for resets */ 901d1bdd20SJiri Slaby wait_queue_head_t wait; /* For sleeping */ 916db3dfefSJiri Kosina }; 926db3dfefSJiri Kosina 936db3dfefSJiri Kosina #define hid_to_usb_dev(hid_dev) \ 947775fb92SGeliang Tang to_usb_device(hid_dev->dev.parent->parent) 956db3dfefSJiri Kosina 966db3dfefSJiri Kosina #endif 976db3dfefSJiri Kosina 98