Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 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 | /* |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/list.h> |
Jiri Slaby | 3d5afd3 | 2008-10-27 12:16:15 +0100 | [diff] [blame] | 17 | #include <linux/mutex.h> |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 18 | #include <linux/timer.h> |
Jiri Slaby | 1d1bdd2 | 2008-03-19 21:55:04 +0100 | [diff] [blame] | 19 | #include <linux/wait.h> |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 20 | #include <linux/workqueue.h> |
| 21 | #include <linux/input.h> |
| 22 | |
| 23 | /* API provided by hid-core.c for USB HID drivers */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 24 | void usbhid_init_reports(struct hid_device *hid); |
Guillaume Chazarain | 8fe294c | 2010-09-12 21:32:35 +0200 | [diff] [blame] | 25 | struct usb_interface *usbhid_find_interface(int minor); |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 26 | |
Jiri Slaby | 0ed94b3 | 2008-11-24 16:20:07 +0100 | [diff] [blame] | 27 | /* iofl flags */ |
| 28 | #define HID_CTRL_RUNNING 1 |
| 29 | #define HID_OUT_RUNNING 2 |
| 30 | #define HID_IN_RUNNING 3 |
| 31 | #define HID_RESET_PENDING 4 |
| 32 | #define HID_SUSPENDED 5 |
| 33 | #define HID_CLEAR_HALT 6 |
| 34 | #define HID_DISCONNECTED 7 |
| 35 | #define HID_STARTED 8 |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 36 | #define HID_KEYS_PRESSED 10 |
Oliver Neukum | a8c52b6 | 2012-03-28 13:16:19 +0200 | [diff] [blame] | 37 | #define HID_NO_BANDWIDTH 11 |
Benjamin Tissoires | b905811 | 2014-09-30 14:28:22 -0400 | [diff] [blame] | 38 | #define HID_RESUME_RUNNING 12 |
Dmitry Torokhov | 28cbc86 | 2017-06-06 23:59:33 -0700 | [diff] [blame] | 39 | /* |
| 40 | * The device is opened, meaning there is a client that is interested |
| 41 | * in data coming from the device. |
| 42 | */ |
| 43 | #define HID_OPENED 13 |
| 44 | /* |
| 45 | * We are polling input endpoint by [re]submitting IN URB, because |
| 46 | * either HID device is opened or ALWAYS POLL quirk is set for the |
| 47 | * device. |
| 48 | */ |
| 49 | #define HID_IN_POLLING 14 |
Jiri Slaby | 0ed94b3 | 2008-11-24 16:20:07 +0100 | [diff] [blame] | 50 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 51 | /* |
| 52 | * USB-specific HID struct, to be pointed to |
| 53 | * from struct hid_device->driver_data |
| 54 | */ |
| 55 | |
| 56 | struct usbhid_device { |
| 57 | struct hid_device *hid; /* pointer to corresponding HID dev */ |
| 58 | |
| 59 | struct usb_interface *intf; /* USB interface */ |
| 60 | int ifnum; /* USB interface number */ |
| 61 | |
| 62 | unsigned int bufsize; /* URB buffer size */ |
| 63 | |
| 64 | struct urb *urbin; /* Input URB */ |
| 65 | char *inbuf; /* Input buffer */ |
| 66 | dma_addr_t inbuf_dma; /* Input buffer dma */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 67 | |
| 68 | struct urb *urbctrl; /* Control URB */ |
| 69 | struct usb_ctrlrequest *cr; /* Control request struct */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 70 | struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */ |
| 71 | unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */ |
| 72 | char *ctrlbuf; /* Control buffer */ |
| 73 | dma_addr_t ctrlbuf_dma; /* Control buffer dma */ |
Oliver Neukum | 858155f | 2010-02-12 13:02:28 +0100 | [diff] [blame] | 74 | unsigned long last_ctrl; /* record of last output for timeouts */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 75 | |
| 76 | struct urb *urbout; /* Output URB */ |
Anssi Hannula | f129ea6 | 2008-10-04 14:44:06 +0200 | [diff] [blame] | 77 | struct hid_output_fifo out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 78 | unsigned char outhead, outtail; /* Output pipe fifo head & tail */ |
| 79 | char *outbuf; /* Output buffer */ |
| 80 | dma_addr_t outbuf_dma; /* Output buffer dma */ |
Oliver Neukum | 858155f | 2010-02-12 13:02:28 +0100 | [diff] [blame] | 81 | unsigned long last_out; /* record of last output for timeouts */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 82 | |
Alan Stern | 0ed08fa | 2020-04-22 16:18:48 -0400 | [diff] [blame] | 83 | struct mutex mutex; /* start/stop/open/close */ |
Oliver Neukum | 0361a28 | 2008-12-17 15:38:03 +0100 | [diff] [blame] | 84 | spinlock_t lock; /* fifo spinlock */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 85 | unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ |
| 86 | struct timer_list io_retry; /* Retry timer */ |
| 87 | unsigned long stop_retry; /* Time to give up, in jiffies */ |
| 88 | unsigned int retry_delay; /* Delay length in ms */ |
| 89 | struct work_struct reset_work; /* Task context for resets */ |
Jiri Slaby | 1d1bdd2 | 2008-03-19 21:55:04 +0100 | [diff] [blame] | 90 | wait_queue_head_t wait; /* For sleeping */ |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 91 | }; |
| 92 | |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 93 | #define hid_to_usb_dev(hid_dev) \ |
Geliang Tang | 7775fb9 | 2015-12-23 21:26:53 +0800 | [diff] [blame] | 94 | to_usb_device(hid_dev->dev.parent->parent) |
Anssi Hannula | be82097 | 2007-01-19 19:28:17 +0200 | [diff] [blame] | 95 | |
Jiri Kosina | 4916b3a | 2006-12-08 18:41:03 +0100 | [diff] [blame] | 96 | #endif |
| 97 | |