1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/hid.h>
17#include <uapi/linux/input.h>
18#include <linux/sched.h>
19#include <linux/wait.h>
20#include "ishtp/client.h"
21#include "ishtp-hid.h"
22
23
24
25
26
27
28
29
30
31static int ishtp_hid_parse(struct hid_device *hid)
32{
33 struct ishtp_hid_data *hid_data = hid->driver_data;
34 struct ishtp_cl_data *client_data = hid_data->client_data;
35 int rv;
36
37 rv = hid_parse_report(hid, client_data->report_descr[hid_data->index],
38 client_data->report_descr_size[hid_data->index]);
39 if (rv)
40 return rv;
41
42 return 0;
43}
44
45
46static int ishtp_hid_start(struct hid_device *hid)
47{
48 return 0;
49}
50
51static void ishtp_hid_stop(struct hid_device *hid)
52{
53}
54
55static int ishtp_hid_open(struct hid_device *hid)
56{
57 return 0;
58}
59
60static void ishtp_hid_close(struct hid_device *hid)
61{
62}
63
64static int ishtp_raw_request(struct hid_device *hdev, unsigned char reportnum,
65 __u8 *buf, size_t len, unsigned char rtype, int reqtype)
66{
67 return 0;
68}
69
70
71
72
73
74
75
76
77
78static void ishtp_hid_request(struct hid_device *hid, struct hid_report *rep,
79 int reqtype)
80{
81 struct ishtp_hid_data *hid_data = hid->driver_data;
82
83 unsigned int len = ((rep->size - 1) >> 3) + 1 + (rep->id > 0);
84 char *buf;
85 unsigned int header_size = sizeof(struct hostif_msg);
86
87 len += header_size;
88
89 hid_data->request_done = false;
90 switch (reqtype) {
91 case HID_REQ_GET_REPORT:
92 hid_ishtp_get_report(hid, rep->id, rep->type);
93 break;
94 case HID_REQ_SET_REPORT:
95
96
97
98
99 buf = kzalloc(len + 7, GFP_KERNEL);
100 if (!buf)
101 return;
102
103 hid_output_report(rep, buf + header_size);
104 hid_ishtp_set_feature(hid, buf, len, rep->id);
105 kfree(buf);
106 break;
107 }
108}
109
110
111
112
113
114
115
116
117
118static int ishtp_wait_for_response(struct hid_device *hid)
119{
120 struct ishtp_hid_data *hid_data = hid->driver_data;
121 struct ishtp_cl_data *client_data = hid_data->client_data;
122 int rv;
123
124 hid_ishtp_trace(client_data, "%s hid %p\n", __func__, hid);
125
126 rv = ishtp_hid_link_ready_wait(hid_data->client_data);
127 if (rv)
128 return rv;
129
130 if (!hid_data->request_done)
131 wait_event_interruptible_timeout(hid_data->hid_wait,
132 hid_data->request_done, 3 * HZ);
133
134 if (!hid_data->request_done) {
135 hid_err(hid,
136 "timeout waiting for response from ISHTP device\n");
137 return -ETIMEDOUT;
138 }
139 hid_ishtp_trace(client_data, "%s hid %p done\n", __func__, hid);
140
141 hid_data->request_done = false;
142
143 return 0;
144}
145
146
147
148
149
150
151
152void ishtp_hid_wakeup(struct hid_device *hid)
153{
154 struct ishtp_hid_data *hid_data = hid->driver_data;
155
156 hid_data->request_done = true;
157 wake_up_interruptible(&hid_data->hid_wait);
158}
159
160static struct hid_ll_driver ishtp_hid_ll_driver = {
161 .parse = ishtp_hid_parse,
162 .start = ishtp_hid_start,
163 .stop = ishtp_hid_stop,
164 .open = ishtp_hid_open,
165 .close = ishtp_hid_close,
166 .request = ishtp_hid_request,
167 .wait = ishtp_wait_for_response,
168 .raw_request = ishtp_raw_request
169};
170
171
172
173
174
175
176
177
178
179
180int ishtp_hid_probe(unsigned int cur_hid_dev,
181 struct ishtp_cl_data *client_data)
182{
183 int rv;
184 struct hid_device *hid;
185 struct ishtp_hid_data *hid_data;
186
187 hid = hid_allocate_device();
188 if (IS_ERR(hid)) {
189 rv = PTR_ERR(hid);
190 return -ENOMEM;
191 }
192
193 hid_data = kzalloc(sizeof(*hid_data), GFP_KERNEL);
194 if (!hid_data) {
195 rv = -ENOMEM;
196 goto err_hid_data;
197 }
198
199 hid_data->index = cur_hid_dev;
200 hid_data->client_data = client_data;
201 init_waitqueue_head(&hid_data->hid_wait);
202
203 hid->driver_data = hid_data;
204
205 client_data->hid_sensor_hubs[cur_hid_dev] = hid;
206
207 hid->ll_driver = &ishtp_hid_ll_driver;
208 hid->bus = BUS_INTEL_ISHTP;
209 hid->dev.parent = &client_data->cl_device->dev;
210 hid->version = le16_to_cpu(ISH_HID_VERSION);
211 hid->vendor = le16_to_cpu(ISH_HID_VENDOR);
212 hid->product = le16_to_cpu(ISH_HID_PRODUCT);
213 snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X", "hid-ishtp",
214 hid->vendor, hid->product);
215
216 rv = hid_add_device(hid);
217 if (rv)
218 goto err_hid_device;
219
220 hid_ishtp_trace(client_data, "%s allocated hid %p\n", __func__, hid);
221
222 return 0;
223
224err_hid_device:
225 kfree(hid_data);
226err_hid_data:
227 hid_destroy_device(hid);
228 return rv;
229}
230
231
232
233
234
235
236
237void ishtp_hid_remove(struct ishtp_cl_data *client_data)
238{
239 int i;
240
241 for (i = 0; i < client_data->num_hid_devices; ++i) {
242 if (client_data->hid_sensor_hubs[i]) {
243 kfree(client_data->hid_sensor_hubs[i]->driver_data);
244 hid_destroy_device(client_data->hid_sensor_hubs[i]);
245 client_data->hid_sensor_hubs[i] = NULL;
246 }
247 }
248}
249