18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef __USBHID_H
38c2ecf20Sopenharmony_ci#define __USBHID_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci *  Copyright (c) 1999 Andreas Gal
78c2ecf20Sopenharmony_ci *  Copyright (c) 2000-2001 Vojtech Pavlik
88c2ecf20Sopenharmony_ci *  Copyright (c) 2006 Jiri Kosina
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/*
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/types.h>
158c2ecf20Sopenharmony_ci#include <linux/slab.h>
168c2ecf20Sopenharmony_ci#include <linux/list.h>
178c2ecf20Sopenharmony_ci#include <linux/mutex.h>
188c2ecf20Sopenharmony_ci#include <linux/timer.h>
198c2ecf20Sopenharmony_ci#include <linux/wait.h>
208c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
218c2ecf20Sopenharmony_ci#include <linux/input.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/*  API provided by hid-core.c for USB HID drivers */
248c2ecf20Sopenharmony_civoid usbhid_init_reports(struct hid_device *hid);
258c2ecf20Sopenharmony_cistruct usb_interface *usbhid_find_interface(int minor);
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* iofl flags */
288c2ecf20Sopenharmony_ci#define HID_CTRL_RUNNING	1
298c2ecf20Sopenharmony_ci#define HID_OUT_RUNNING		2
308c2ecf20Sopenharmony_ci#define HID_IN_RUNNING		3
318c2ecf20Sopenharmony_ci#define HID_RESET_PENDING	4
328c2ecf20Sopenharmony_ci#define HID_SUSPENDED		5
338c2ecf20Sopenharmony_ci#define HID_CLEAR_HALT		6
348c2ecf20Sopenharmony_ci#define HID_DISCONNECTED	7
358c2ecf20Sopenharmony_ci#define HID_STARTED		8
368c2ecf20Sopenharmony_ci#define HID_KEYS_PRESSED	10
378c2ecf20Sopenharmony_ci#define HID_NO_BANDWIDTH	11
388c2ecf20Sopenharmony_ci#define HID_RESUME_RUNNING	12
398c2ecf20Sopenharmony_ci/*
408c2ecf20Sopenharmony_ci * The device is opened, meaning there is a client that is interested
418c2ecf20Sopenharmony_ci * in data coming from the device.
428c2ecf20Sopenharmony_ci */
438c2ecf20Sopenharmony_ci#define HID_OPENED		13
448c2ecf20Sopenharmony_ci/*
458c2ecf20Sopenharmony_ci * We are polling input endpoint by [re]submitting IN URB, because
468c2ecf20Sopenharmony_ci * either HID device is opened or ALWAYS POLL quirk is set for the
478c2ecf20Sopenharmony_ci * device.
488c2ecf20Sopenharmony_ci */
498c2ecf20Sopenharmony_ci#define HID_IN_POLLING		14
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/*
528c2ecf20Sopenharmony_ci * USB-specific HID struct, to be pointed to
538c2ecf20Sopenharmony_ci * from struct hid_device->driver_data
548c2ecf20Sopenharmony_ci */
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistruct usbhid_device {
578c2ecf20Sopenharmony_ci	struct hid_device *hid;						/* pointer to corresponding HID dev */
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	struct usb_interface *intf;                                     /* USB interface */
608c2ecf20Sopenharmony_ci	int ifnum;                                                      /* USB interface number */
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	unsigned int bufsize;                                           /* URB buffer size */
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	struct urb *urbin;                                              /* Input URB */
658c2ecf20Sopenharmony_ci	char *inbuf;                                                    /* Input buffer */
668c2ecf20Sopenharmony_ci	dma_addr_t inbuf_dma;                                           /* Input buffer dma */
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	struct urb *urbctrl;                                            /* Control URB */
698c2ecf20Sopenharmony_ci	struct usb_ctrlrequest *cr;                                     /* Control request struct */
708c2ecf20Sopenharmony_ci	struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE];  		/* Control fifo */
718c2ecf20Sopenharmony_ci	unsigned char ctrlhead, ctrltail;                               /* Control fifo head & tail */
728c2ecf20Sopenharmony_ci	char *ctrlbuf;                                                  /* Control buffer */
738c2ecf20Sopenharmony_ci	dma_addr_t ctrlbuf_dma;                                         /* Control buffer dma */
748c2ecf20Sopenharmony_ci	unsigned long last_ctrl;						/* record of last output for timeouts */
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	struct urb *urbout;                                             /* Output URB */
778c2ecf20Sopenharmony_ci	struct hid_output_fifo out[HID_CONTROL_FIFO_SIZE];              /* Output pipe fifo */
788c2ecf20Sopenharmony_ci	unsigned char outhead, outtail;                                 /* Output pipe fifo head & tail */
798c2ecf20Sopenharmony_ci	char *outbuf;                                                   /* Output buffer */
808c2ecf20Sopenharmony_ci	dma_addr_t outbuf_dma;                                          /* Output buffer dma */
818c2ecf20Sopenharmony_ci	unsigned long last_out;							/* record of last output for timeouts */
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	struct mutex mutex;						/* start/stop/open/close */
848c2ecf20Sopenharmony_ci	spinlock_t lock;						/* fifo spinlock */
858c2ecf20Sopenharmony_ci	unsigned long iofl;                                             /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
868c2ecf20Sopenharmony_ci	struct timer_list io_retry;                                     /* Retry timer */
878c2ecf20Sopenharmony_ci	unsigned long stop_retry;                                       /* Time to give up, in jiffies */
888c2ecf20Sopenharmony_ci	unsigned int retry_delay;                                       /* Delay length in ms */
898c2ecf20Sopenharmony_ci	struct work_struct reset_work;                                  /* Task context for resets */
908c2ecf20Sopenharmony_ci	wait_queue_head_t wait;						/* For sleeping */
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define	hid_to_usb_dev(hid_dev) \
948c2ecf20Sopenharmony_ci	to_usb_device(hid_dev->dev.parent->parent)
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#endif
978c2ecf20Sopenharmony_ci
98