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