blob: ec20400c7f2904bf793ac82b37cac65df03ac161 [file] [log] [blame]
Jiri Kosina4916b3a2006-12-08 18:41:03 +01001#ifndef __USBHID_H
2#define __USBHID_H
3
4/*
5 * Copyright (c) 1999 Andreas Gal
6 * Copyright (c) 2000-2001 Vojtech Pavlik
7 * Copyright (c) 2006 Jiri Kosina
8 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#include <linux/types.h>
28#include <linux/slab.h>
29#include <linux/list.h>
Jiri Slaby3d5afd32008-10-27 12:16:15 +010030#include <linux/mutex.h>
Jiri Kosina4916b3a2006-12-08 18:41:03 +010031#include <linux/timer.h>
Jiri Slaby1d1bdd22008-03-19 21:55:04 +010032#include <linux/wait.h>
Jiri Kosina4916b3a2006-12-08 18:41:03 +010033#include <linux/workqueue.h>
34#include <linux/input.h>
35
36/* API provided by hid-core.c for USB HID drivers */
37int usbhid_wait_io(struct hid_device* hid);
38void usbhid_close(struct hid_device *hid);
39int usbhid_open(struct hid_device *hid);
40void usbhid_init_reports(struct hid_device *hid);
Oliver Neukum0361a282008-12-17 15:38:03 +010041void usbhid_submit_report
42(struct hid_device *hid, struct hid_report *report, unsigned char dir);
43int usbhid_get_power(struct hid_device *hid);
44void usbhid_put_power(struct hid_device *hid);
Jiri Kosina4916b3a2006-12-08 18:41:03 +010045
Jiri Slaby0ed94b32008-11-24 16:20:07 +010046/* iofl flags */
47#define HID_CTRL_RUNNING 1
48#define HID_OUT_RUNNING 2
49#define HID_IN_RUNNING 3
50#define HID_RESET_PENDING 4
51#define HID_SUSPENDED 5
52#define HID_CLEAR_HALT 6
53#define HID_DISCONNECTED 7
54#define HID_STARTED 8
Oliver Neukum0361a282008-12-17 15:38:03 +010055#define HID_REPORTED_IDLE 9
56#define HID_KEYS_PRESSED 10
57#define HID_LED_ON 11
Jiri Slaby0ed94b32008-11-24 16:20:07 +010058
Jiri Kosina4916b3a2006-12-08 18:41:03 +010059/*
60 * USB-specific HID struct, to be pointed to
61 * from struct hid_device->driver_data
62 */
63
64struct usbhid_device {
65 struct hid_device *hid; /* pointer to corresponding HID dev */
66
67 struct usb_interface *intf; /* USB interface */
68 int ifnum; /* USB interface number */
69
70 unsigned int bufsize; /* URB buffer size */
71
72 struct urb *urbin; /* Input URB */
73 char *inbuf; /* Input buffer */
74 dma_addr_t inbuf_dma; /* Input buffer dma */
Jiri Kosina4916b3a2006-12-08 18:41:03 +010075
76 struct urb *urbctrl; /* Control URB */
77 struct usb_ctrlrequest *cr; /* Control request struct */
78 dma_addr_t cr_dma; /* Control request struct dma */
79 struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */
80 unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */
81 char *ctrlbuf; /* Control buffer */
82 dma_addr_t ctrlbuf_dma; /* Control buffer dma */
Oliver Neukum858155f2010-02-12 13:02:28 +010083 unsigned long last_ctrl; /* record of last output for timeouts */
Jiri Kosina4916b3a2006-12-08 18:41:03 +010084
85 struct urb *urbout; /* Output URB */
Anssi Hannulaf129ea62008-10-04 14:44:06 +020086 struct hid_output_fifo out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */
Jiri Kosina4916b3a2006-12-08 18:41:03 +010087 unsigned char outhead, outtail; /* Output pipe fifo head & tail */
88 char *outbuf; /* Output buffer */
89 dma_addr_t outbuf_dma; /* Output buffer dma */
Oliver Neukum858155f2010-02-12 13:02:28 +010090 unsigned long last_out; /* record of last output for timeouts */
Jiri Kosina4916b3a2006-12-08 18:41:03 +010091
Oliver Neukum0361a282008-12-17 15:38:03 +010092 spinlock_t lock; /* fifo spinlock */
Jiri Kosina4916b3a2006-12-08 18:41:03 +010093 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
94 struct timer_list io_retry; /* Retry timer */
95 unsigned long stop_retry; /* Time to give up, in jiffies */
96 unsigned int retry_delay; /* Delay length in ms */
97 struct work_struct reset_work; /* Task context for resets */
Oliver Neukum0361a282008-12-17 15:38:03 +010098 struct work_struct restart_work; /* waking up for output to be done in a task */
Jiri Slaby1d1bdd22008-03-19 21:55:04 +010099 wait_queue_head_t wait; /* For sleeping */
Oliver Neukum0361a282008-12-17 15:38:03 +0100100 int ledcount; /* counting the number of active leds */
Jiri Kosina4916b3a2006-12-08 18:41:03 +0100101};
102
Anssi Hannulabe820972007-01-19 19:28:17 +0200103#define hid_to_usb_dev(hid_dev) \
Jiri Slaby85cdaf52008-05-16 11:49:15 +0200104 container_of(hid_dev->dev.parent->parent, struct usb_device, dev)
Anssi Hannulabe820972007-01-19 19:28:17 +0200105
Jiri Kosina4916b3a2006-12-08 18:41:03 +0100106#endif
107