162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci#ifndef __USBHID_H
362306a36Sopenharmony_ci#define __USBHID_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci/*
662306a36Sopenharmony_ci *  Copyright (c) 1999 Andreas Gal
762306a36Sopenharmony_ci *  Copyright (c) 2000-2001 Vojtech Pavlik
862306a36Sopenharmony_ci *  Copyright (c) 2006 Jiri Kosina
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/*
1262306a36Sopenharmony_ci */
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include <linux/types.h>
1562306a36Sopenharmony_ci#include <linux/slab.h>
1662306a36Sopenharmony_ci#include <linux/list.h>
1762306a36Sopenharmony_ci#include <linux/mutex.h>
1862306a36Sopenharmony_ci#include <linux/timer.h>
1962306a36Sopenharmony_ci#include <linux/wait.h>
2062306a36Sopenharmony_ci#include <linux/workqueue.h>
2162306a36Sopenharmony_ci#include <linux/input.h>
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/*  API provided by hid-core.c for USB HID drivers */
2462306a36Sopenharmony_civoid usbhid_init_reports(struct hid_device *hid);
2562306a36Sopenharmony_cistruct usb_interface *usbhid_find_interface(int minor);
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/* iofl flags */
2862306a36Sopenharmony_ci#define HID_CTRL_RUNNING	1
2962306a36Sopenharmony_ci#define HID_OUT_RUNNING		2
3062306a36Sopenharmony_ci#define HID_IN_RUNNING		3
3162306a36Sopenharmony_ci#define HID_RESET_PENDING	4
3262306a36Sopenharmony_ci#define HID_SUSPENDED		5
3362306a36Sopenharmony_ci#define HID_CLEAR_HALT		6
3462306a36Sopenharmony_ci#define HID_DISCONNECTED	7
3562306a36Sopenharmony_ci#define HID_STARTED		8
3662306a36Sopenharmony_ci#define HID_KEYS_PRESSED	10
3762306a36Sopenharmony_ci#define HID_NO_BANDWIDTH	11
3862306a36Sopenharmony_ci#define HID_RESUME_RUNNING	12
3962306a36Sopenharmony_ci/*
4062306a36Sopenharmony_ci * The device is opened, meaning there is a client that is interested
4162306a36Sopenharmony_ci * in data coming from the device.
4262306a36Sopenharmony_ci */
4362306a36Sopenharmony_ci#define HID_OPENED		13
4462306a36Sopenharmony_ci/*
4562306a36Sopenharmony_ci * We are polling input endpoint by [re]submitting IN URB, because
4662306a36Sopenharmony_ci * either HID device is opened or ALWAYS POLL quirk is set for the
4762306a36Sopenharmony_ci * device.
4862306a36Sopenharmony_ci */
4962306a36Sopenharmony_ci#define HID_IN_POLLING		14
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci/*
5262306a36Sopenharmony_ci * USB-specific HID struct, to be pointed to
5362306a36Sopenharmony_ci * from struct hid_device->driver_data
5462306a36Sopenharmony_ci */
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_cistruct usbhid_device {
5762306a36Sopenharmony_ci	struct hid_device *hid;						/* pointer to corresponding HID dev */
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	struct usb_interface *intf;                                     /* USB interface */
6062306a36Sopenharmony_ci	int ifnum;                                                      /* USB interface number */
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci	unsigned int bufsize;                                           /* URB buffer size */
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci	struct urb *urbin;                                              /* Input URB */
6562306a36Sopenharmony_ci	char *inbuf;                                                    /* Input buffer */
6662306a36Sopenharmony_ci	dma_addr_t inbuf_dma;                                           /* Input buffer dma */
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci	struct urb *urbctrl;                                            /* Control URB */
6962306a36Sopenharmony_ci	struct usb_ctrlrequest *cr;                                     /* Control request struct */
7062306a36Sopenharmony_ci	struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE];  		/* Control fifo */
7162306a36Sopenharmony_ci	unsigned char ctrlhead, ctrltail;                               /* Control fifo head & tail */
7262306a36Sopenharmony_ci	char *ctrlbuf;                                                  /* Control buffer */
7362306a36Sopenharmony_ci	dma_addr_t ctrlbuf_dma;                                         /* Control buffer dma */
7462306a36Sopenharmony_ci	unsigned long last_ctrl;						/* record of last output for timeouts */
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	struct urb *urbout;                                             /* Output URB */
7762306a36Sopenharmony_ci	struct hid_output_fifo out[HID_CONTROL_FIFO_SIZE];              /* Output pipe fifo */
7862306a36Sopenharmony_ci	unsigned char outhead, outtail;                                 /* Output pipe fifo head & tail */
7962306a36Sopenharmony_ci	char *outbuf;                                                   /* Output buffer */
8062306a36Sopenharmony_ci	dma_addr_t outbuf_dma;                                          /* Output buffer dma */
8162306a36Sopenharmony_ci	unsigned long last_out;							/* record of last output for timeouts */
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci	struct mutex mutex;						/* start/stop/open/close */
8462306a36Sopenharmony_ci	spinlock_t lock;						/* fifo spinlock */
8562306a36Sopenharmony_ci	unsigned long iofl;                                             /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
8662306a36Sopenharmony_ci	struct timer_list io_retry;                                     /* Retry timer */
8762306a36Sopenharmony_ci	unsigned long stop_retry;                                       /* Time to give up, in jiffies */
8862306a36Sopenharmony_ci	unsigned int retry_delay;                                       /* Delay length in ms */
8962306a36Sopenharmony_ci	struct work_struct reset_work;                                  /* Task context for resets */
9062306a36Sopenharmony_ci	wait_queue_head_t wait;						/* For sleeping */
9162306a36Sopenharmony_ci};
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci#define	hid_to_usb_dev(hid_dev) \
9462306a36Sopenharmony_ci	to_usb_device(hid_dev->dev.parent->parent)
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#endif
9762306a36Sopenharmony_ci
98