1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/* $OpenBSD: ihidev.h,v 1.7 2019/07/22 14:37:06 jcs Exp $ */
/*
* HID-over-i2c driver
*
* Copyright (c) 2015, 2016 joshua stein <jcs@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/timeout.h>
/* from usbdi.h: Match codes. */
/* First five codes is for a whole device. */
#define IMATCH_VENDOR_PRODUCT_REV 14
#define IMATCH_VENDOR_PRODUCT 13
#define IMATCH_VENDOR_DEVCLASS_DEVPROTO 12
#define IMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11
#define IMATCH_DEVCLASS_DEVSUBCLASS 10
/* Next six codes are for interfaces. */
#define IMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9
#define IMATCH_VENDOR_PRODUCT_CONF_IFACE 8
#define IMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7
#define IMATCH_VENDOR_IFACESUBCLASS 6
#define IMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5
#define IMATCH_IFACECLASS_IFACESUBCLASS 4
#define IMATCH_IFACECLASS 3
#define IMATCH_IFACECLASS_GENERIC 2
/* Generic driver */
#define IMATCH_GENERIC 1
/* No match */
#define IMATCH_NONE 0
#define IHIDBUSCF_REPORTID 0
#define IHIDBUSCF_REPORTID_DEFAULT -1
#define ihidevcf_reportid cf_loc[IHIDBUSCF_REPORTID]
#define IHIDEV_UNK_REPORTID IHIDBUSCF_REPORTID_DEFAULT
/* 5.1.1 - HID Descriptor Format */
struct i2c_hid_desc {
uint16_t wHIDDescLength;
uint16_t bcdVersion;
uint16_t wReportDescLength;
uint16_t wReportDescRegister;
uint16_t wInputRegister;
uint16_t wMaxInputLength;
uint16_t wOutputRegister;
uint16_t wMaxOutputLength;
uint16_t wCommandRegister;
uint16_t wDataRegister;
uint16_t wVendorID;
uint16_t wProductID;
uint16_t wVersionID;
uint32_t reserved;
} __packed;
struct ihidev_softc {
struct device sc_dev;
i2c_tag_t sc_tag;
i2c_addr_t sc_addr;
void *sc_ih;
u_int sc_hid_desc_addr;
union {
uint8_t hid_desc_buf[sizeof(struct i2c_hid_desc)];
struct i2c_hid_desc hid_desc;
};
uint8_t *sc_report;
int sc_reportlen;
int sc_nrepid;
struct ihidev **sc_subdevs;
u_int sc_isize;
u_char *sc_ibuf;
int sc_refcnt;
int sc_poll;
int sc_frompoll;
int sc_fastpoll;
struct timeout sc_timer;
int sc_dying;
};
struct ihidev {
struct device sc_idev;
struct ihidev_softc *sc_parent;
uint8_t sc_report_id;
uint8_t sc_state;
#define IHIDEV_OPEN 0x01 /* device is open */
void (*sc_intr)(struct ihidev *, void *, u_int);
int sc_isize;
int sc_osize;
int sc_fsize;
};
struct ihidev_attach_arg {
struct i2c_attach_args *iaa;
struct ihidev_softc *parent;
uint8_t reportid;
#define IHIDEV_CLAIM_ALLREPORTID 255
};
struct i2c_hid_report_request {
u_int id;
u_int type;
#define I2C_HID_REPORT_TYPE_INPUT 0x1
#define I2C_HID_REPORT_TYPE_OUTPUT 0x2
#define I2C_HID_REPORT_TYPE_FEATURE 0x3
void *data;
u_int len;
};
void ihidev_get_report_desc(struct ihidev_softc *, void **, int *);
int ihidev_open(struct ihidev *);
void ihidev_close(struct ihidev *);
int ihidev_ioctl(struct ihidev *, u_long, caddr_t, int, struct proc *);
int ihidev_report_type_conv(int);
int ihidev_set_report(struct device *, int, int, void *, int);
int ihidev_get_report(struct device *, int, int, void *, int);
|