blob: 4031405ac191d8bc83e9948ff32934aa72f26fc1 [file] [log] [blame]
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001/*
2 * HIDPP protocol for Logitech Unifying receivers
3 *
4 * Copyright (c) 2011 Logitech (c)
5 * Copyright (c) 2012-2013 Google (c)
6 * Copyright (c) 2013-2014 Red Hat Inc.
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; version 2 of the License.
13 */
14
15#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16
17#include <linux/device.h>
Edwin Veldsff21a632016-01-11 00:25:15 +010018#include <linux/input.h>
19#include <linux/usb.h>
Benjamin Tissoires2f31c522014-09-30 13:18:27 -040020#include <linux/hid.h>
21#include <linux/module.h>
22#include <linux/slab.h>
23#include <linux/sched.h>
24#include <linux/kfifo.h>
25#include <linux/input/mt.h>
Edwin Veldsff21a632016-01-11 00:25:15 +010026#include <linux/workqueue.h>
27#include <linux/atomic.h>
28#include <linux/fixp-arith.h>
Benjamin Tissoires2f31c522014-09-30 13:18:27 -040029#include <asm/unaligned.h>
Edwin Veldsff21a632016-01-11 00:25:15 +010030#include "usbhid/usbhid.h"
Benjamin Tissoires2f31c522014-09-30 13:18:27 -040031#include "hid-ids.h"
32
33MODULE_LICENSE("GPL");
34MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
35MODULE_AUTHOR("Nestor Lopez Casado <nlopezcasad@logitech.com>");
36
Benjamin Tissoires9188dba2015-03-26 12:41:57 -040037static bool disable_raw_mode;
38module_param(disable_raw_mode, bool, 0644);
39MODULE_PARM_DESC(disable_raw_mode,
40 "Disable Raw mode reporting for touchpads and keep firmware gestures.");
41
Benjamin Tissoires90cdd982015-09-03 09:08:30 -040042static bool disable_tap_to_click;
43module_param(disable_tap_to_click, bool, 0644);
44MODULE_PARM_DESC(disable_tap_to_click,
45 "Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
46
Benjamin Tissoires2f31c522014-09-30 13:18:27 -040047#define REPORT_ID_HIDPP_SHORT 0x10
48#define REPORT_ID_HIDPP_LONG 0x11
Simon Wooda5ce8f52015-11-19 16:42:11 -070049#define REPORT_ID_HIDPP_VERY_LONG 0x12
Benjamin Tissoires2f31c522014-09-30 13:18:27 -040050
51#define HIDPP_REPORT_SHORT_LENGTH 7
52#define HIDPP_REPORT_LONG_LENGTH 20
Simon Wooda5ce8f52015-11-19 16:42:11 -070053#define HIDPP_REPORT_VERY_LONG_LENGTH 64
Benjamin Tissoires2f31c522014-09-30 13:18:27 -040054
55#define HIDPP_QUIRK_CLASS_WTP BIT(0)
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +020056#define HIDPP_QUIRK_CLASS_M560 BIT(1)
Benjamin Tissoires90cdd982015-09-03 09:08:30 -040057#define HIDPP_QUIRK_CLASS_K400 BIT(2)
Simon Wood7bfd2922015-11-19 16:42:12 -070058#define HIDPP_QUIRK_CLASS_G920 BIT(3)
Benjamin Tissoires2f31c522014-09-30 13:18:27 -040059
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +020060/* bits 2..20 are reserved for classes */
Benjamin Tissoires6bd4e652016-06-29 19:28:02 +100061/* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */
Benjamin Tissoires57ac86c2014-09-30 13:18:34 -040062#define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22)
Benjamin Tissoires580a7e82015-09-03 09:08:29 -040063#define HIDPP_QUIRK_NO_HIDINPUT BIT(23)
Simon Wood7bfd2922015-11-19 16:42:12 -070064#define HIDPP_QUIRK_FORCE_OUTPUT_REPORTS BIT(24)
Peter Hutterer5a2b1902016-06-29 19:28:01 +100065#define HIDPP_QUIRK_HIDPP20_BATTERY BIT(25)
66#define HIDPP_QUIRK_HIDPP10_BATTERY BIT(26)
Benjamin Tissoires580a7e82015-09-03 09:08:29 -040067
Benjamin Tissoires6bd4e652016-06-29 19:28:02 +100068#define HIDPP_QUIRK_DELAYED_INIT HIDPP_QUIRK_NO_HIDINPUT
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -040069
Benjamin Tissoires2f31c522014-09-30 13:18:27 -040070/*
71 * There are two hidpp protocols in use, the first version hidpp10 is known
72 * as register access protocol or RAP, the second version hidpp20 is known as
73 * feature access protocol or FAP
74 *
75 * Most older devices (including the Unifying usb receiver) use the RAP protocol
76 * where as most newer devices use the FAP protocol. Both protocols are
77 * compatible with the underlying transport, which could be usb, Unifiying, or
78 * bluetooth. The message lengths are defined by the hid vendor specific report
79 * descriptor for the HIDPP_SHORT report type (total message lenth 7 bytes) and
80 * the HIDPP_LONG report type (total message length 20 bytes)
81 *
82 * The RAP protocol uses both report types, whereas the FAP only uses HIDPP_LONG
83 * messages. The Unifying receiver itself responds to RAP messages (device index
84 * is 0xFF for the receiver), and all messages (short or long) with a device
85 * index between 1 and 6 are passed untouched to the corresponding paired
86 * Unifying device.
87 *
88 * The paired device can be RAP or FAP, it will receive the message untouched
89 * from the Unifiying receiver.
90 */
91
92struct fap {
93 u8 feature_index;
94 u8 funcindex_clientid;
Simon Wooda5ce8f52015-11-19 16:42:11 -070095 u8 params[HIDPP_REPORT_VERY_LONG_LENGTH - 4U];
Benjamin Tissoires2f31c522014-09-30 13:18:27 -040096};
97
98struct rap {
99 u8 sub_id;
100 u8 reg_address;
Simon Wooda5ce8f52015-11-19 16:42:11 -0700101 u8 params[HIDPP_REPORT_VERY_LONG_LENGTH - 4U];
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400102};
103
104struct hidpp_report {
105 u8 report_id;
106 u8 device_index;
107 union {
108 struct fap fap;
109 struct rap rap;
110 u8 rawbytes[sizeof(struct fap)];
111 };
112} __packed;
113
Peter Hutterer5a2b1902016-06-29 19:28:01 +1000114struct hidpp_battery {
115 u8 feature_index;
116 struct power_supply_desc desc;
117 struct power_supply *ps;
118 char name[64];
119 int status;
120 int level;
121};
122
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400123struct hidpp_device {
124 struct hid_device *hid_dev;
125 struct mutex send_mutex;
126 void *send_receive_buf;
Benjamin Tissoires005b3f52015-01-08 14:37:12 -0500127 char *name; /* will never be NULL and should not be freed */
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400128 wait_queue_head_t wait;
129 bool answer_available;
130 u8 protocol_major;
131 u8 protocol_minor;
132
133 void *private_data;
134
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -0400135 struct work_struct work;
136 struct kfifo delayed_work_fifo;
137 atomic_t connected;
138 struct input_dev *delayed_input;
139
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400140 unsigned long quirks;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400141
Peter Hutterer5a2b1902016-06-29 19:28:01 +1000142 struct hidpp_battery battery;
143};
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400144
Peter Wuf677bb12014-12-16 01:50:14 +0100145/* HID++ 1.0 error codes */
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400146#define HIDPP_ERROR 0x8f
147#define HIDPP_ERROR_SUCCESS 0x00
148#define HIDPP_ERROR_INVALID_SUBID 0x01
149#define HIDPP_ERROR_INVALID_ADRESS 0x02
150#define HIDPP_ERROR_INVALID_VALUE 0x03
151#define HIDPP_ERROR_CONNECT_FAIL 0x04
152#define HIDPP_ERROR_TOO_MANY_DEVICES 0x05
153#define HIDPP_ERROR_ALREADY_EXISTS 0x06
154#define HIDPP_ERROR_BUSY 0x07
155#define HIDPP_ERROR_UNKNOWN_DEVICE 0x08
156#define HIDPP_ERROR_RESOURCE_ERROR 0x09
157#define HIDPP_ERROR_REQUEST_UNAVAILABLE 0x0a
158#define HIDPP_ERROR_INVALID_PARAM_VALUE 0x0b
159#define HIDPP_ERROR_WRONG_PIN_CODE 0x0c
Peter Wuf677bb12014-12-16 01:50:14 +0100160/* HID++ 2.0 error codes */
161#define HIDPP20_ERROR 0xff
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400162
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -0400163static void hidpp_connect_event(struct hidpp_device *hidpp_dev);
164
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400165static int __hidpp_send_report(struct hid_device *hdev,
166 struct hidpp_report *hidpp_report)
167{
Simon Wood7bfd2922015-11-19 16:42:12 -0700168 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400169 int fields_count, ret;
170
Simon Wood7bfd2922015-11-19 16:42:12 -0700171 hidpp = hid_get_drvdata(hdev);
172
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400173 switch (hidpp_report->report_id) {
174 case REPORT_ID_HIDPP_SHORT:
175 fields_count = HIDPP_REPORT_SHORT_LENGTH;
176 break;
177 case REPORT_ID_HIDPP_LONG:
178 fields_count = HIDPP_REPORT_LONG_LENGTH;
179 break;
Simon Wooda5ce8f52015-11-19 16:42:11 -0700180 case REPORT_ID_HIDPP_VERY_LONG:
181 fields_count = HIDPP_REPORT_VERY_LONG_LENGTH;
182 break;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400183 default:
184 return -ENODEV;
185 }
186
187 /*
188 * set the device_index as the receiver, it will be overwritten by
189 * hid_hw_request if needed
190 */
191 hidpp_report->device_index = 0xff;
192
Simon Wood7bfd2922015-11-19 16:42:12 -0700193 if (hidpp->quirks & HIDPP_QUIRK_FORCE_OUTPUT_REPORTS) {
194 ret = hid_hw_output_report(hdev, (u8 *)hidpp_report, fields_count);
195 } else {
196 ret = hid_hw_raw_request(hdev, hidpp_report->report_id,
197 (u8 *)hidpp_report, fields_count, HID_OUTPUT_REPORT,
198 HID_REQ_SET_REPORT);
199 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400200
201 return ret == fields_count ? 0 : -1;
202}
203
Benjamin Tissoires8c9952b2014-11-03 16:09:58 -0500204/**
205 * hidpp_send_message_sync() returns 0 in case of success, and something else
206 * in case of a failure.
207 * - If ' something else' is positive, that means that an error has been raised
208 * by the protocol itself.
209 * - If ' something else' is negative, that means that we had a classic error
210 * (-ENOMEM, -EPIPE, etc...)
211 */
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400212static int hidpp_send_message_sync(struct hidpp_device *hidpp,
213 struct hidpp_report *message,
214 struct hidpp_report *response)
215{
216 int ret;
217
218 mutex_lock(&hidpp->send_mutex);
219
220 hidpp->send_receive_buf = response;
221 hidpp->answer_available = false;
222
223 /*
224 * So that we can later validate the answer when it arrives
225 * in hidpp_raw_event
226 */
227 *response = *message;
228
229 ret = __hidpp_send_report(hidpp->hid_dev, message);
230
231 if (ret) {
232 dbg_hid("__hidpp_send_report returned err: %d\n", ret);
233 memset(response, 0, sizeof(struct hidpp_report));
234 goto exit;
235 }
236
237 if (!wait_event_timeout(hidpp->wait, hidpp->answer_available,
238 5*HZ)) {
239 dbg_hid("%s:timeout waiting for response\n", __func__);
240 memset(response, 0, sizeof(struct hidpp_report));
241 ret = -ETIMEDOUT;
242 }
243
244 if (response->report_id == REPORT_ID_HIDPP_SHORT &&
Peter Wuf677bb12014-12-16 01:50:14 +0100245 response->rap.sub_id == HIDPP_ERROR) {
246 ret = response->rap.params[1];
247 dbg_hid("%s:got hidpp error %02X\n", __func__, ret);
248 goto exit;
249 }
250
Simon Wooda5ce8f52015-11-19 16:42:11 -0700251 if ((response->report_id == REPORT_ID_HIDPP_LONG ||
252 response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&
253 response->fap.feature_index == HIDPP20_ERROR) {
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400254 ret = response->fap.params[1];
Peter Wuf677bb12014-12-16 01:50:14 +0100255 dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400256 goto exit;
257 }
258
259exit:
260 mutex_unlock(&hidpp->send_mutex);
261 return ret;
262
263}
264
265static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
266 u8 feat_index, u8 funcindex_clientid, u8 *params, int param_count,
267 struct hidpp_report *response)
268{
Dan Carpenter3e7830c2014-10-31 12:14:39 +0300269 struct hidpp_report *message;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400270 int ret;
271
272 if (param_count > sizeof(message->fap.params))
273 return -EINVAL;
274
Dan Carpenter3e7830c2014-10-31 12:14:39 +0300275 message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
276 if (!message)
277 return -ENOMEM;
Simon Wooda5ce8f52015-11-19 16:42:11 -0700278
279 if (param_count > (HIDPP_REPORT_LONG_LENGTH - 4))
280 message->report_id = REPORT_ID_HIDPP_VERY_LONG;
281 else
282 message->report_id = REPORT_ID_HIDPP_LONG;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400283 message->fap.feature_index = feat_index;
284 message->fap.funcindex_clientid = funcindex_clientid;
285 memcpy(&message->fap.params, params, param_count);
286
287 ret = hidpp_send_message_sync(hidpp, message, response);
288 kfree(message);
289 return ret;
290}
291
Benjamin Tissoires33797822014-09-30 13:18:30 -0400292static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,
293 u8 report_id, u8 sub_id, u8 reg_address, u8 *params, int param_count,
294 struct hidpp_report *response)
295{
Dan Carpenter3e7830c2014-10-31 12:14:39 +0300296 struct hidpp_report *message;
Simon Wooda5ce8f52015-11-19 16:42:11 -0700297 int ret, max_count;
Benjamin Tissoires33797822014-09-30 13:18:30 -0400298
Simon Wooda5ce8f52015-11-19 16:42:11 -0700299 switch (report_id) {
300 case REPORT_ID_HIDPP_SHORT:
301 max_count = HIDPP_REPORT_SHORT_LENGTH - 4;
302 break;
303 case REPORT_ID_HIDPP_LONG:
304 max_count = HIDPP_REPORT_LONG_LENGTH - 4;
305 break;
306 case REPORT_ID_HIDPP_VERY_LONG:
307 max_count = HIDPP_REPORT_VERY_LONG_LENGTH - 4;
308 break;
309 default:
Benjamin Tissoires33797822014-09-30 13:18:30 -0400310 return -EINVAL;
Simon Wooda5ce8f52015-11-19 16:42:11 -0700311 }
Benjamin Tissoires33797822014-09-30 13:18:30 -0400312
Simon Wooda5ce8f52015-11-19 16:42:11 -0700313 if (param_count > max_count)
Benjamin Tissoires33797822014-09-30 13:18:30 -0400314 return -EINVAL;
315
Dan Carpenter3e7830c2014-10-31 12:14:39 +0300316 message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
317 if (!message)
318 return -ENOMEM;
Benjamin Tissoires33797822014-09-30 13:18:30 -0400319 message->report_id = report_id;
320 message->rap.sub_id = sub_id;
321 message->rap.reg_address = reg_address;
322 memcpy(&message->rap.params, params, param_count);
323
324 ret = hidpp_send_message_sync(hidpp_dev, message, response);
325 kfree(message);
326 return ret;
327}
328
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -0400329static void delayed_work_cb(struct work_struct *work)
330{
331 struct hidpp_device *hidpp = container_of(work, struct hidpp_device,
332 work);
333 hidpp_connect_event(hidpp);
334}
335
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400336static inline bool hidpp_match_answer(struct hidpp_report *question,
337 struct hidpp_report *answer)
338{
339 return (answer->fap.feature_index == question->fap.feature_index) &&
340 (answer->fap.funcindex_clientid == question->fap.funcindex_clientid);
341}
342
343static inline bool hidpp_match_error(struct hidpp_report *question,
344 struct hidpp_report *answer)
345{
Peter Wuf677bb12014-12-16 01:50:14 +0100346 return ((answer->rap.sub_id == HIDPP_ERROR) ||
347 (answer->fap.feature_index == HIDPP20_ERROR)) &&
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400348 (answer->fap.funcindex_clientid == question->fap.feature_index) &&
349 (answer->fap.params[0] == question->fap.funcindex_clientid);
350}
351
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -0400352static inline bool hidpp_report_is_connect_event(struct hidpp_report *report)
353{
354 return (report->report_id == REPORT_ID_HIDPP_SHORT) &&
355 (report->rap.sub_id == 0x41);
356}
357
Benjamin Tissoiresa0e625f2014-12-11 17:39:59 -0500358/**
359 * hidpp_prefix_name() prefixes the current given name with "Logitech ".
360 */
361static void hidpp_prefix_name(char **name, int name_length)
362{
363#define PREFIX_LENGTH 9 /* "Logitech " */
364
365 int new_length;
366 char *new_name;
367
368 if (name_length > PREFIX_LENGTH &&
369 strncmp(*name, "Logitech ", PREFIX_LENGTH) == 0)
370 /* The prefix has is already in the name */
371 return;
372
373 new_length = PREFIX_LENGTH + name_length;
374 new_name = kzalloc(new_length, GFP_KERNEL);
375 if (!new_name)
376 return;
377
378 snprintf(new_name, new_length, "Logitech %s", *name);
379
380 kfree(*name);
381
382 *name = new_name;
383}
384
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400385/* -------------------------------------------------------------------------- */
Benjamin Tissoires33797822014-09-30 13:18:30 -0400386/* HIDP++ 1.0 commands */
387/* -------------------------------------------------------------------------- */
388
389#define HIDPP_SET_REGISTER 0x80
390#define HIDPP_GET_REGISTER 0x81
391#define HIDPP_SET_LONG_REGISTER 0x82
392#define HIDPP_GET_LONG_REGISTER 0x83
393
394#define HIDPP_REG_PAIRING_INFORMATION 0xB5
395#define DEVICE_NAME 0x40
396
397static char *hidpp_get_unifying_name(struct hidpp_device *hidpp_dev)
398{
399 struct hidpp_report response;
400 int ret;
401 /* hid-logitech-dj is in charge of setting the right device index */
402 u8 params[1] = { DEVICE_NAME };
403 char *name;
404 int len;
405
406 ret = hidpp_send_rap_command_sync(hidpp_dev,
407 REPORT_ID_HIDPP_SHORT,
408 HIDPP_GET_LONG_REGISTER,
409 HIDPP_REG_PAIRING_INFORMATION,
410 params, 1, &response);
411 if (ret)
412 return NULL;
413
414 len = response.rap.params[1];
415
Peter Wu3a034a72014-12-11 13:51:19 +0100416 if (2 + len > sizeof(response.rap.params))
417 return NULL;
418
Benjamin Tissoires33797822014-09-30 13:18:30 -0400419 name = kzalloc(len + 1, GFP_KERNEL);
420 if (!name)
421 return NULL;
422
423 memcpy(name, &response.rap.params[2], len);
Benjamin Tissoiresa0e625f2014-12-11 17:39:59 -0500424
425 /* include the terminating '\0' */
426 hidpp_prefix_name(&name, len + 1);
427
Benjamin Tissoires33797822014-09-30 13:18:30 -0400428 return name;
429}
430
431/* -------------------------------------------------------------------------- */
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400432/* 0x0000: Root */
433/* -------------------------------------------------------------------------- */
434
435#define HIDPP_PAGE_ROOT 0x0000
436#define HIDPP_PAGE_ROOT_IDX 0x00
437
438#define CMD_ROOT_GET_FEATURE 0x01
439#define CMD_ROOT_GET_PROTOCOL_VERSION 0x11
440
441static int hidpp_root_get_feature(struct hidpp_device *hidpp, u16 feature,
442 u8 *feature_index, u8 *feature_type)
443{
444 struct hidpp_report response;
445 int ret;
446 u8 params[2] = { feature >> 8, feature & 0x00FF };
447
448 ret = hidpp_send_fap_command_sync(hidpp,
449 HIDPP_PAGE_ROOT_IDX,
450 CMD_ROOT_GET_FEATURE,
451 params, 2, &response);
452 if (ret)
453 return ret;
454
455 *feature_index = response.fap.params[0];
456 *feature_type = response.fap.params[1];
457
458 return ret;
459}
460
461static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
462{
463 struct hidpp_report response;
464 int ret;
465
466 ret = hidpp_send_fap_command_sync(hidpp,
467 HIDPP_PAGE_ROOT_IDX,
468 CMD_ROOT_GET_PROTOCOL_VERSION,
469 NULL, 0, &response);
470
Benjamin Tissoires552f12e2014-11-03 16:09:59 -0500471 if (ret == HIDPP_ERROR_INVALID_SUBID) {
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400472 hidpp->protocol_major = 1;
473 hidpp->protocol_minor = 0;
474 return 0;
475 }
476
Benjamin Tissoires552f12e2014-11-03 16:09:59 -0500477 /* the device might not be connected */
478 if (ret == HIDPP_ERROR_RESOURCE_ERROR)
479 return -EIO;
480
Benjamin Tissoires8c9952b2014-11-03 16:09:58 -0500481 if (ret > 0) {
482 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
483 __func__, ret);
484 return -EPROTO;
485 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400486 if (ret)
Benjamin Tissoires8c9952b2014-11-03 16:09:58 -0500487 return ret;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400488
489 hidpp->protocol_major = response.fap.params[0];
490 hidpp->protocol_minor = response.fap.params[1];
491
492 return ret;
493}
494
495static bool hidpp_is_connected(struct hidpp_device *hidpp)
496{
497 int ret;
498
499 ret = hidpp_root_get_protocol_version(hidpp);
500 if (!ret)
501 hid_dbg(hidpp->hid_dev, "HID++ %u.%u device connected.\n",
502 hidpp->protocol_major, hidpp->protocol_minor);
503 return ret == 0;
504}
505
506/* -------------------------------------------------------------------------- */
507/* 0x0005: GetDeviceNameType */
508/* -------------------------------------------------------------------------- */
509
510#define HIDPP_PAGE_GET_DEVICE_NAME_TYPE 0x0005
511
512#define CMD_GET_DEVICE_NAME_TYPE_GET_COUNT 0x01
513#define CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME 0x11
514#define CMD_GET_DEVICE_NAME_TYPE_GET_TYPE 0x21
515
516static int hidpp_devicenametype_get_count(struct hidpp_device *hidpp,
517 u8 feature_index, u8 *nameLength)
518{
519 struct hidpp_report response;
520 int ret;
521
522 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
523 CMD_GET_DEVICE_NAME_TYPE_GET_COUNT, NULL, 0, &response);
524
Benjamin Tissoires8c9952b2014-11-03 16:09:58 -0500525 if (ret > 0) {
526 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
527 __func__, ret);
528 return -EPROTO;
529 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400530 if (ret)
Benjamin Tissoires8c9952b2014-11-03 16:09:58 -0500531 return ret;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400532
533 *nameLength = response.fap.params[0];
534
535 return ret;
536}
537
538static int hidpp_devicenametype_get_device_name(struct hidpp_device *hidpp,
539 u8 feature_index, u8 char_index, char *device_name, int len_buf)
540{
541 struct hidpp_report response;
542 int ret, i;
543 int count;
544
545 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
546 CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME, &char_index, 1,
547 &response);
548
Benjamin Tissoires8c9952b2014-11-03 16:09:58 -0500549 if (ret > 0) {
550 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
551 __func__, ret);
552 return -EPROTO;
553 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400554 if (ret)
Benjamin Tissoires8c9952b2014-11-03 16:09:58 -0500555 return ret;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400556
Simon Wooda5ce8f52015-11-19 16:42:11 -0700557 switch (response.report_id) {
558 case REPORT_ID_HIDPP_VERY_LONG:
559 count = HIDPP_REPORT_VERY_LONG_LENGTH - 4;
560 break;
561 case REPORT_ID_HIDPP_LONG:
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400562 count = HIDPP_REPORT_LONG_LENGTH - 4;
Simon Wooda5ce8f52015-11-19 16:42:11 -0700563 break;
564 case REPORT_ID_HIDPP_SHORT:
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400565 count = HIDPP_REPORT_SHORT_LENGTH - 4;
Simon Wooda5ce8f52015-11-19 16:42:11 -0700566 break;
567 default:
568 return -EPROTO;
569 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400570
571 if (len_buf < count)
572 count = len_buf;
573
574 for (i = 0; i < count; i++)
575 device_name[i] = response.fap.params[i];
576
577 return count;
578}
579
Peter Wu02cc0972014-12-11 13:51:17 +0100580static char *hidpp_get_device_name(struct hidpp_device *hidpp)
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400581{
582 u8 feature_type;
583 u8 feature_index;
584 u8 __name_length;
585 char *name;
586 unsigned index = 0;
587 int ret;
588
589 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_GET_DEVICE_NAME_TYPE,
590 &feature_index, &feature_type);
591 if (ret)
Peter Wu02cc0972014-12-11 13:51:17 +0100592 return NULL;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400593
594 ret = hidpp_devicenametype_get_count(hidpp, feature_index,
595 &__name_length);
596 if (ret)
Peter Wu02cc0972014-12-11 13:51:17 +0100597 return NULL;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400598
599 name = kzalloc(__name_length + 1, GFP_KERNEL);
600 if (!name)
Peter Wu02cc0972014-12-11 13:51:17 +0100601 return NULL;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400602
Peter Wu1430ee72014-12-11 13:51:18 +0100603 while (index < __name_length) {
604 ret = hidpp_devicenametype_get_device_name(hidpp,
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400605 feature_index, index, name + index,
606 __name_length - index);
Peter Wu1430ee72014-12-11 13:51:18 +0100607 if (ret <= 0) {
608 kfree(name);
609 return NULL;
610 }
611 index += ret;
612 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400613
Benjamin Tissoiresa0e625f2014-12-11 17:39:59 -0500614 /* include the terminating '\0' */
615 hidpp_prefix_name(&name, __name_length + 1);
616
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400617 return name;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400618}
619
620/* -------------------------------------------------------------------------- */
Peter Hutterer5a2b1902016-06-29 19:28:01 +1000621/* 0x1000: Battery level status */
622/* -------------------------------------------------------------------------- */
623
624#define HIDPP_PAGE_BATTERY_LEVEL_STATUS 0x1000
625
626#define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS 0x00
627#define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY 0x10
628
629#define EVENT_BATTERY_LEVEL_STATUS_BROADCAST 0x00
630
631static int hidpp20_batterylevel_map_status_level(u8 data[3], int *level,
632 int *next_level)
633{
634 int status;
635 int level_override;
636
637 *level = data[0];
638 *next_level = data[1];
639
640 /* When discharging, we can rely on the device reported level.
641 * For all other states the device reports level 0 (unknown). Make up
642 * a number instead
643 */
644 switch (data[2]) {
645 case 0: /* discharging (in use) */
646 status = POWER_SUPPLY_STATUS_DISCHARGING;
647 level_override = 0;
648 break;
649 case 1: /* recharging */
650 status = POWER_SUPPLY_STATUS_CHARGING;
651 level_override = 80;
652 break;
653 case 2: /* charge in final stage */
654 status = POWER_SUPPLY_STATUS_CHARGING;
655 level_override = 90;
656 break;
657 case 3: /* charge complete */
658 status = POWER_SUPPLY_STATUS_FULL;
659 level_override = 100;
660 break;
661 case 4: /* recharging below optimal speed */
662 status = POWER_SUPPLY_STATUS_CHARGING;
663 level_override = 50;
664 break;
665 /* 5 = invalid battery type
666 6 = thermal error
667 7 = other charging error */
668 default:
669 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
670 level_override = 0;
671 break;
672 }
673
674 if (level_override != 0 && *level == 0)
675 *level = level_override;
676
677 return status;
678}
679
680static int hidpp20_batterylevel_get_battery_level(struct hidpp_device *hidpp,
681 u8 feature_index,
682 int *status,
683 int *level,
684 int *next_level)
685{
686 struct hidpp_report response;
687 int ret;
688 u8 *params = (u8 *)response.fap.params;
689
690 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
691 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS,
692 NULL, 0, &response);
693 if (ret > 0) {
694 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
695 __func__, ret);
696 return -EPROTO;
697 }
698 if (ret)
699 return ret;
700
701 *status = hidpp20_batterylevel_map_status_level(params, level,
702 next_level);
703
704 return 0;
705}
706
707static int hidpp20_query_battery_info(struct hidpp_device *hidpp)
708{
709 u8 feature_type;
710 int ret;
711 int status, level, next_level;
712
713 if (hidpp->battery.feature_index == 0) {
714 ret = hidpp_root_get_feature(hidpp,
715 HIDPP_PAGE_BATTERY_LEVEL_STATUS,
716 &hidpp->battery.feature_index,
717 &feature_type);
718 if (ret)
719 return ret;
720 }
721
722 ret = hidpp20_batterylevel_get_battery_level(hidpp,
723 hidpp->battery.feature_index,
724 &status, &level, &next_level);
725 if (ret)
726 return ret;
727
728 hidpp->battery.status = status;
729 hidpp->battery.level = level;
730
731 return 0;
732}
733
734static int hidpp20_battery_event(struct hidpp_device *hidpp,
735 u8 *data, int size)
736{
737 struct hidpp_report *report = (struct hidpp_report *)data;
738 int status, level, next_level;
739 bool changed;
740
741 if (report->fap.feature_index != hidpp->battery.feature_index ||
742 report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST)
743 return 0;
744
745 status = hidpp20_batterylevel_map_status_level(report->fap.params,
746 &level, &next_level);
747
748 changed = level != hidpp->battery.level ||
749 status != hidpp->battery.status;
750
751 if (changed) {
752 hidpp->battery.level = level;
753 hidpp->battery.status = status;
754 if (hidpp->battery.ps)
755 power_supply_changed(hidpp->battery.ps);
756 }
757
758 return 0;
759}
760
761static enum power_supply_property hidpp_battery_props[] = {
762 POWER_SUPPLY_PROP_STATUS,
763 POWER_SUPPLY_PROP_CAPACITY,
Bastien Nocera3861e6c2017-03-27 16:59:22 +0200764 POWER_SUPPLY_PROP_SCOPE,
Peter Hutterer5a2b1902016-06-29 19:28:01 +1000765};
766
767static int hidpp_battery_get_property(struct power_supply *psy,
768 enum power_supply_property psp,
769 union power_supply_propval *val)
770{
771 struct hidpp_device *hidpp = power_supply_get_drvdata(psy);
772 int ret = 0;
773
774 switch(psp) {
775 case POWER_SUPPLY_PROP_STATUS:
776 val->intval = hidpp->battery.status;
777 break;
778 case POWER_SUPPLY_PROP_CAPACITY:
779 val->intval = hidpp->battery.level;
780 break;
Bastien Nocera3861e6c2017-03-27 16:59:22 +0200781 case POWER_SUPPLY_PROP_SCOPE:
782 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
783 break;
Peter Hutterer5a2b1902016-06-29 19:28:01 +1000784 default:
785 ret = -EINVAL;
786 break;
787 }
788
789 return ret;
790}
791
792static int hidpp20_initialize_battery(struct hidpp_device *hidpp)
793{
794 static atomic_t battery_no = ATOMIC_INIT(0);
795 struct power_supply_config cfg = { .drv_data = hidpp };
796 struct power_supply_desc *desc = &hidpp->battery.desc;
797 struct hidpp_battery *battery;
798 unsigned long n;
799 int ret;
800
801 ret = hidpp20_query_battery_info(hidpp);
802 if (ret)
803 return ret;
804
805 battery = &hidpp->battery;
806
807 n = atomic_inc_return(&battery_no) - 1;
808 desc->properties = hidpp_battery_props;
809 desc->num_properties = ARRAY_SIZE(hidpp_battery_props);
810 desc->get_property = hidpp_battery_get_property;
811 sprintf(battery->name, "hidpp_battery_%ld", n);
812 desc->name = battery->name;
813 desc->type = POWER_SUPPLY_TYPE_BATTERY;
814 desc->use_for_apm = 0;
815
816 battery->ps = devm_power_supply_register(&hidpp->hid_dev->dev,
817 &battery->desc,
818 &cfg);
819 if (IS_ERR(battery->ps))
820 return PTR_ERR(battery->ps);
821
822 power_supply_powers(battery->ps, &hidpp->hid_dev->dev);
823
824 return 0;
825}
826
827static int hidpp_initialize_battery(struct hidpp_device *hidpp)
828{
829 int ret;
830
Benjamin Tissoires680de742017-03-27 16:59:23 +0200831 if (hidpp->battery.ps)
832 return 0;
833
Peter Hutterer5a2b1902016-06-29 19:28:01 +1000834 if (hidpp->protocol_major >= 2) {
835 ret = hidpp20_initialize_battery(hidpp);
836 if (ret == 0)
837 hidpp->quirks |= HIDPP_QUIRK_HIDPP20_BATTERY;
838 }
839
840 return ret;
841}
842
843/* -------------------------------------------------------------------------- */
Benjamin Tissoires90cdd982015-09-03 09:08:30 -0400844/* 0x6010: Touchpad FW items */
845/* -------------------------------------------------------------------------- */
846
847#define HIDPP_PAGE_TOUCHPAD_FW_ITEMS 0x6010
848
849#define CMD_TOUCHPAD_FW_ITEMS_SET 0x10
850
851struct hidpp_touchpad_fw_items {
852 uint8_t presence;
853 uint8_t desired_state;
854 uint8_t state;
855 uint8_t persistent;
856};
857
858/**
859 * send a set state command to the device by reading the current items->state
860 * field. items is then filled with the current state.
861 */
862static int hidpp_touchpad_fw_items_set(struct hidpp_device *hidpp,
863 u8 feature_index,
864 struct hidpp_touchpad_fw_items *items)
865{
866 struct hidpp_report response;
867 int ret;
868 u8 *params = (u8 *)response.fap.params;
869
870 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
871 CMD_TOUCHPAD_FW_ITEMS_SET, &items->state, 1, &response);
872
873 if (ret > 0) {
874 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
875 __func__, ret);
876 return -EPROTO;
877 }
878 if (ret)
879 return ret;
880
881 items->presence = params[0];
882 items->desired_state = params[1];
883 items->state = params[2];
884 items->persistent = params[3];
885
886 return 0;
887}
888
889/* -------------------------------------------------------------------------- */
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400890/* 0x6100: TouchPadRawXY */
891/* -------------------------------------------------------------------------- */
892
893#define HIDPP_PAGE_TOUCHPAD_RAW_XY 0x6100
894
895#define CMD_TOUCHPAD_GET_RAW_INFO 0x01
Benjamin Tissoires586bdc42014-09-30 13:18:33 -0400896#define CMD_TOUCHPAD_SET_RAW_REPORT_STATE 0x21
897
898#define EVENT_TOUCHPAD_RAW_XY 0x00
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400899
900#define TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT 0x01
901#define TOUCHPAD_RAW_XY_ORIGIN_UPPER_LEFT 0x03
902
903struct hidpp_touchpad_raw_info {
904 u16 x_size;
905 u16 y_size;
906 u8 z_range;
907 u8 area_range;
908 u8 timestamp_unit;
909 u8 maxcontacts;
910 u8 origin;
911 u16 res;
912};
913
914struct hidpp_touchpad_raw_xy_finger {
915 u8 contact_type;
916 u8 contact_status;
917 u16 x;
918 u16 y;
919 u8 z;
920 u8 area;
921 u8 finger_id;
922};
923
924struct hidpp_touchpad_raw_xy {
925 u16 timestamp;
926 struct hidpp_touchpad_raw_xy_finger fingers[2];
927 u8 spurious_flag;
928 u8 end_of_frame;
929 u8 finger_count;
930 u8 button;
931};
932
933static int hidpp_touchpad_get_raw_info(struct hidpp_device *hidpp,
934 u8 feature_index, struct hidpp_touchpad_raw_info *raw_info)
935{
936 struct hidpp_report response;
937 int ret;
938 u8 *params = (u8 *)response.fap.params;
939
940 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
941 CMD_TOUCHPAD_GET_RAW_INFO, NULL, 0, &response);
942
Benjamin Tissoires8c9952b2014-11-03 16:09:58 -0500943 if (ret > 0) {
944 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
945 __func__, ret);
946 return -EPROTO;
947 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400948 if (ret)
Benjamin Tissoires8c9952b2014-11-03 16:09:58 -0500949 return ret;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -0400950
951 raw_info->x_size = get_unaligned_be16(&params[0]);
952 raw_info->y_size = get_unaligned_be16(&params[2]);
953 raw_info->z_range = params[4];
954 raw_info->area_range = params[5];
955 raw_info->maxcontacts = params[7];
956 raw_info->origin = params[8];
957 /* res is given in unit per inch */
958 raw_info->res = get_unaligned_be16(&params[13]) * 2 / 51;
959
960 return ret;
961}
962
Benjamin Tissoires586bdc42014-09-30 13:18:33 -0400963static int hidpp_touchpad_set_raw_report_state(struct hidpp_device *hidpp_dev,
964 u8 feature_index, bool send_raw_reports,
965 bool sensor_enhanced_settings)
966{
967 struct hidpp_report response;
968
969 /*
970 * Params:
971 * bit 0 - enable raw
972 * bit 1 - 16bit Z, no area
973 * bit 2 - enhanced sensitivity
974 * bit 3 - width, height (4 bits each) instead of area
975 * bit 4 - send raw + gestures (degrades smoothness)
976 * remaining bits - reserved
977 */
978 u8 params = send_raw_reports | (sensor_enhanced_settings << 2);
979
980 return hidpp_send_fap_command_sync(hidpp_dev, feature_index,
981 CMD_TOUCHPAD_SET_RAW_REPORT_STATE, &params, 1, &response);
982}
983
984static void hidpp_touchpad_touch_event(u8 *data,
985 struct hidpp_touchpad_raw_xy_finger *finger)
986{
987 u8 x_m = data[0] << 2;
988 u8 y_m = data[2] << 2;
989
990 finger->x = x_m << 6 | data[1];
991 finger->y = y_m << 6 | data[3];
992
993 finger->contact_type = data[0] >> 6;
994 finger->contact_status = data[2] >> 6;
995
996 finger->z = data[4];
997 finger->area = data[5];
998 finger->finger_id = data[6] >> 4;
999}
1000
1001static void hidpp_touchpad_raw_xy_event(struct hidpp_device *hidpp_dev,
1002 u8 *data, struct hidpp_touchpad_raw_xy *raw_xy)
1003{
1004 memset(raw_xy, 0, sizeof(struct hidpp_touchpad_raw_xy));
1005 raw_xy->end_of_frame = data[8] & 0x01;
1006 raw_xy->spurious_flag = (data[8] >> 1) & 0x01;
1007 raw_xy->finger_count = data[15] & 0x0f;
1008 raw_xy->button = (data[8] >> 2) & 0x01;
1009
1010 if (raw_xy->finger_count) {
1011 hidpp_touchpad_touch_event(&data[2], &raw_xy->fingers[0]);
1012 hidpp_touchpad_touch_event(&data[9], &raw_xy->fingers[1]);
1013 }
1014}
1015
Edwin Veldsff21a632016-01-11 00:25:15 +01001016/* -------------------------------------------------------------------------- */
1017/* 0x8123: Force feedback support */
1018/* -------------------------------------------------------------------------- */
1019
1020#define HIDPP_FF_GET_INFO 0x01
1021#define HIDPP_FF_RESET_ALL 0x11
1022#define HIDPP_FF_DOWNLOAD_EFFECT 0x21
1023#define HIDPP_FF_SET_EFFECT_STATE 0x31
1024#define HIDPP_FF_DESTROY_EFFECT 0x41
1025#define HIDPP_FF_GET_APERTURE 0x51
1026#define HIDPP_FF_SET_APERTURE 0x61
1027#define HIDPP_FF_GET_GLOBAL_GAINS 0x71
1028#define HIDPP_FF_SET_GLOBAL_GAINS 0x81
1029
1030#define HIDPP_FF_EFFECT_STATE_GET 0x00
1031#define HIDPP_FF_EFFECT_STATE_STOP 0x01
1032#define HIDPP_FF_EFFECT_STATE_PLAY 0x02
1033#define HIDPP_FF_EFFECT_STATE_PAUSE 0x03
1034
1035#define HIDPP_FF_EFFECT_CONSTANT 0x00
1036#define HIDPP_FF_EFFECT_PERIODIC_SINE 0x01
1037#define HIDPP_FF_EFFECT_PERIODIC_SQUARE 0x02
1038#define HIDPP_FF_EFFECT_PERIODIC_TRIANGLE 0x03
1039#define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP 0x04
1040#define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN 0x05
1041#define HIDPP_FF_EFFECT_SPRING 0x06
1042#define HIDPP_FF_EFFECT_DAMPER 0x07
1043#define HIDPP_FF_EFFECT_FRICTION 0x08
1044#define HIDPP_FF_EFFECT_INERTIA 0x09
1045#define HIDPP_FF_EFFECT_RAMP 0x0A
1046
1047#define HIDPP_FF_EFFECT_AUTOSTART 0x80
1048
1049#define HIDPP_FF_EFFECTID_NONE -1
1050#define HIDPP_FF_EFFECTID_AUTOCENTER -2
1051
1052#define HIDPP_FF_MAX_PARAMS 20
1053#define HIDPP_FF_RESERVED_SLOTS 1
1054
1055struct hidpp_ff_private_data {
1056 struct hidpp_device *hidpp;
1057 u8 feature_index;
1058 u8 version;
1059 u16 gain;
1060 s16 range;
1061 u8 slot_autocenter;
1062 u8 num_effects;
1063 int *effect_ids;
1064 struct workqueue_struct *wq;
1065 atomic_t workqueue_size;
1066};
1067
1068struct hidpp_ff_work_data {
1069 struct work_struct work;
1070 struct hidpp_ff_private_data *data;
1071 int effect_id;
1072 u8 command;
1073 u8 params[HIDPP_FF_MAX_PARAMS];
1074 u8 size;
1075};
1076
1077static const signed short hiddpp_ff_effects[] = {
1078 FF_CONSTANT,
1079 FF_PERIODIC,
1080 FF_SINE,
1081 FF_SQUARE,
1082 FF_SAW_UP,
1083 FF_SAW_DOWN,
1084 FF_TRIANGLE,
1085 FF_SPRING,
1086 FF_DAMPER,
1087 FF_AUTOCENTER,
1088 FF_GAIN,
1089 -1
1090};
1091
1092static const signed short hiddpp_ff_effects_v2[] = {
1093 FF_RAMP,
1094 FF_FRICTION,
1095 FF_INERTIA,
1096 -1
1097};
1098
1099static const u8 HIDPP_FF_CONDITION_CMDS[] = {
1100 HIDPP_FF_EFFECT_SPRING,
1101 HIDPP_FF_EFFECT_FRICTION,
1102 HIDPP_FF_EFFECT_DAMPER,
1103 HIDPP_FF_EFFECT_INERTIA
1104};
1105
1106static const char *HIDPP_FF_CONDITION_NAMES[] = {
1107 "spring",
1108 "friction",
1109 "damper",
1110 "inertia"
1111};
1112
1113
1114static u8 hidpp_ff_find_effect(struct hidpp_ff_private_data *data, int effect_id)
1115{
1116 int i;
1117
1118 for (i = 0; i < data->num_effects; i++)
1119 if (data->effect_ids[i] == effect_id)
1120 return i+1;
1121
1122 return 0;
1123}
1124
1125static void hidpp_ff_work_handler(struct work_struct *w)
1126{
1127 struct hidpp_ff_work_data *wd = container_of(w, struct hidpp_ff_work_data, work);
1128 struct hidpp_ff_private_data *data = wd->data;
1129 struct hidpp_report response;
1130 u8 slot;
1131 int ret;
1132
1133 /* add slot number if needed */
1134 switch (wd->effect_id) {
1135 case HIDPP_FF_EFFECTID_AUTOCENTER:
1136 wd->params[0] = data->slot_autocenter;
1137 break;
1138 case HIDPP_FF_EFFECTID_NONE:
1139 /* leave slot as zero */
1140 break;
1141 default:
1142 /* find current slot for effect */
1143 wd->params[0] = hidpp_ff_find_effect(data, wd->effect_id);
1144 break;
1145 }
1146
1147 /* send command and wait for reply */
1148 ret = hidpp_send_fap_command_sync(data->hidpp, data->feature_index,
1149 wd->command, wd->params, wd->size, &response);
1150
1151 if (ret) {
1152 hid_err(data->hidpp->hid_dev, "Failed to send command to device!\n");
1153 goto out;
1154 }
1155
1156 /* parse return data */
1157 switch (wd->command) {
1158 case HIDPP_FF_DOWNLOAD_EFFECT:
1159 slot = response.fap.params[0];
1160 if (slot > 0 && slot <= data->num_effects) {
1161 if (wd->effect_id >= 0)
1162 /* regular effect uploaded */
1163 data->effect_ids[slot-1] = wd->effect_id;
1164 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
1165 /* autocenter spring uploaded */
1166 data->slot_autocenter = slot;
1167 }
1168 break;
1169 case HIDPP_FF_DESTROY_EFFECT:
1170 if (wd->effect_id >= 0)
1171 /* regular effect destroyed */
1172 data->effect_ids[wd->params[0]-1] = -1;
1173 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
1174 /* autocenter spring destoyed */
1175 data->slot_autocenter = 0;
1176 break;
1177 case HIDPP_FF_SET_GLOBAL_GAINS:
1178 data->gain = (wd->params[0] << 8) + wd->params[1];
1179 break;
1180 case HIDPP_FF_SET_APERTURE:
1181 data->range = (wd->params[0] << 8) + wd->params[1];
1182 break;
1183 default:
1184 /* no action needed */
1185 break;
1186 }
1187
1188out:
1189 atomic_dec(&data->workqueue_size);
1190 kfree(wd);
1191}
1192
1193static int hidpp_ff_queue_work(struct hidpp_ff_private_data *data, int effect_id, u8 command, u8 *params, u8 size)
1194{
1195 struct hidpp_ff_work_data *wd = kzalloc(sizeof(*wd), GFP_KERNEL);
1196 int s;
1197
1198 if (!wd)
1199 return -ENOMEM;
1200
1201 INIT_WORK(&wd->work, hidpp_ff_work_handler);
1202
1203 wd->data = data;
1204 wd->effect_id = effect_id;
1205 wd->command = command;
1206 wd->size = size;
1207 memcpy(wd->params, params, size);
1208
1209 atomic_inc(&data->workqueue_size);
1210 queue_work(data->wq, &wd->work);
1211
1212 /* warn about excessive queue size */
1213 s = atomic_read(&data->workqueue_size);
1214 if (s >= 20 && s % 20 == 0)
1215 hid_warn(data->hidpp->hid_dev, "Force feedback command queue contains %d commands, causing substantial delays!", s);
1216
1217 return 0;
1218}
1219
1220static int hidpp_ff_upload_effect(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old)
1221{
1222 struct hidpp_ff_private_data *data = dev->ff->private;
1223 u8 params[20];
1224 u8 size;
1225 int force;
1226
1227 /* set common parameters */
1228 params[2] = effect->replay.length >> 8;
1229 params[3] = effect->replay.length & 255;
1230 params[4] = effect->replay.delay >> 8;
1231 params[5] = effect->replay.delay & 255;
1232
1233 switch (effect->type) {
1234 case FF_CONSTANT:
1235 force = (effect->u.constant.level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1236 params[1] = HIDPP_FF_EFFECT_CONSTANT;
1237 params[6] = force >> 8;
1238 params[7] = force & 255;
1239 params[8] = effect->u.constant.envelope.attack_level >> 7;
1240 params[9] = effect->u.constant.envelope.attack_length >> 8;
1241 params[10] = effect->u.constant.envelope.attack_length & 255;
1242 params[11] = effect->u.constant.envelope.fade_level >> 7;
1243 params[12] = effect->u.constant.envelope.fade_length >> 8;
1244 params[13] = effect->u.constant.envelope.fade_length & 255;
1245 size = 14;
1246 dbg_hid("Uploading constant force level=%d in dir %d = %d\n",
1247 effect->u.constant.level,
1248 effect->direction, force);
1249 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1250 effect->u.constant.envelope.attack_level,
1251 effect->u.constant.envelope.attack_length,
1252 effect->u.constant.envelope.fade_level,
1253 effect->u.constant.envelope.fade_length);
1254 break;
1255 case FF_PERIODIC:
1256 {
1257 switch (effect->u.periodic.waveform) {
1258 case FF_SINE:
1259 params[1] = HIDPP_FF_EFFECT_PERIODIC_SINE;
1260 break;
1261 case FF_SQUARE:
1262 params[1] = HIDPP_FF_EFFECT_PERIODIC_SQUARE;
1263 break;
1264 case FF_SAW_UP:
1265 params[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP;
1266 break;
1267 case FF_SAW_DOWN:
1268 params[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN;
1269 break;
1270 case FF_TRIANGLE:
1271 params[1] = HIDPP_FF_EFFECT_PERIODIC_TRIANGLE;
1272 break;
1273 default:
1274 hid_err(data->hidpp->hid_dev, "Unexpected periodic waveform type %i!\n", effect->u.periodic.waveform);
1275 return -EINVAL;
1276 }
1277 force = (effect->u.periodic.magnitude * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1278 params[6] = effect->u.periodic.magnitude >> 8;
1279 params[7] = effect->u.periodic.magnitude & 255;
1280 params[8] = effect->u.periodic.offset >> 8;
1281 params[9] = effect->u.periodic.offset & 255;
1282 params[10] = effect->u.periodic.period >> 8;
1283 params[11] = effect->u.periodic.period & 255;
1284 params[12] = effect->u.periodic.phase >> 8;
1285 params[13] = effect->u.periodic.phase & 255;
1286 params[14] = effect->u.periodic.envelope.attack_level >> 7;
1287 params[15] = effect->u.periodic.envelope.attack_length >> 8;
1288 params[16] = effect->u.periodic.envelope.attack_length & 255;
1289 params[17] = effect->u.periodic.envelope.fade_level >> 7;
1290 params[18] = effect->u.periodic.envelope.fade_length >> 8;
1291 params[19] = effect->u.periodic.envelope.fade_length & 255;
1292 size = 20;
1293 dbg_hid("Uploading periodic force mag=%d/dir=%d, offset=%d, period=%d ms, phase=%d\n",
1294 effect->u.periodic.magnitude, effect->direction,
1295 effect->u.periodic.offset,
1296 effect->u.periodic.period,
1297 effect->u.periodic.phase);
1298 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1299 effect->u.periodic.envelope.attack_level,
1300 effect->u.periodic.envelope.attack_length,
1301 effect->u.periodic.envelope.fade_level,
1302 effect->u.periodic.envelope.fade_length);
1303 break;
1304 }
1305 case FF_RAMP:
1306 params[1] = HIDPP_FF_EFFECT_RAMP;
1307 force = (effect->u.ramp.start_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1308 params[6] = force >> 8;
1309 params[7] = force & 255;
1310 force = (effect->u.ramp.end_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1311 params[8] = force >> 8;
1312 params[9] = force & 255;
1313 params[10] = effect->u.ramp.envelope.attack_level >> 7;
1314 params[11] = effect->u.ramp.envelope.attack_length >> 8;
1315 params[12] = effect->u.ramp.envelope.attack_length & 255;
1316 params[13] = effect->u.ramp.envelope.fade_level >> 7;
1317 params[14] = effect->u.ramp.envelope.fade_length >> 8;
1318 params[15] = effect->u.ramp.envelope.fade_length & 255;
1319 size = 16;
1320 dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n",
1321 effect->u.ramp.start_level,
1322 effect->u.ramp.end_level,
1323 effect->direction, force);
1324 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1325 effect->u.ramp.envelope.attack_level,
1326 effect->u.ramp.envelope.attack_length,
1327 effect->u.ramp.envelope.fade_level,
1328 effect->u.ramp.envelope.fade_length);
1329 break;
1330 case FF_FRICTION:
1331 case FF_INERTIA:
1332 case FF_SPRING:
1333 case FF_DAMPER:
1334 params[1] = HIDPP_FF_CONDITION_CMDS[effect->type - FF_SPRING];
1335 params[6] = effect->u.condition[0].left_saturation >> 9;
1336 params[7] = (effect->u.condition[0].left_saturation >> 1) & 255;
1337 params[8] = effect->u.condition[0].left_coeff >> 8;
1338 params[9] = effect->u.condition[0].left_coeff & 255;
1339 params[10] = effect->u.condition[0].deadband >> 9;
1340 params[11] = (effect->u.condition[0].deadband >> 1) & 255;
1341 params[12] = effect->u.condition[0].center >> 8;
1342 params[13] = effect->u.condition[0].center & 255;
1343 params[14] = effect->u.condition[0].right_coeff >> 8;
1344 params[15] = effect->u.condition[0].right_coeff & 255;
1345 params[16] = effect->u.condition[0].right_saturation >> 9;
1346 params[17] = (effect->u.condition[0].right_saturation >> 1) & 255;
1347 size = 18;
1348 dbg_hid("Uploading %s force left coeff=%d, left sat=%d, right coeff=%d, right sat=%d\n",
1349 HIDPP_FF_CONDITION_NAMES[effect->type - FF_SPRING],
1350 effect->u.condition[0].left_coeff,
1351 effect->u.condition[0].left_saturation,
1352 effect->u.condition[0].right_coeff,
1353 effect->u.condition[0].right_saturation);
1354 dbg_hid(" deadband=%d, center=%d\n",
1355 effect->u.condition[0].deadband,
1356 effect->u.condition[0].center);
1357 break;
1358 default:
1359 hid_err(data->hidpp->hid_dev, "Unexpected force type %i!\n", effect->type);
1360 return -EINVAL;
1361 }
1362
1363 return hidpp_ff_queue_work(data, effect->id, HIDPP_FF_DOWNLOAD_EFFECT, params, size);
1364}
1365
1366static int hidpp_ff_playback(struct input_dev *dev, int effect_id, int value)
1367{
1368 struct hidpp_ff_private_data *data = dev->ff->private;
1369 u8 params[2];
1370
1371 params[1] = value ? HIDPP_FF_EFFECT_STATE_PLAY : HIDPP_FF_EFFECT_STATE_STOP;
1372
1373 dbg_hid("St%sing playback of effect %d.\n", value?"art":"opp", effect_id);
1374
1375 return hidpp_ff_queue_work(data, effect_id, HIDPP_FF_SET_EFFECT_STATE, params, ARRAY_SIZE(params));
1376}
1377
1378static int hidpp_ff_erase_effect(struct input_dev *dev, int effect_id)
1379{
1380 struct hidpp_ff_private_data *data = dev->ff->private;
1381 u8 slot = 0;
1382
1383 dbg_hid("Erasing effect %d.\n", effect_id);
1384
1385 return hidpp_ff_queue_work(data, effect_id, HIDPP_FF_DESTROY_EFFECT, &slot, 1);
1386}
1387
1388static void hidpp_ff_set_autocenter(struct input_dev *dev, u16 magnitude)
1389{
1390 struct hidpp_ff_private_data *data = dev->ff->private;
1391 u8 params[18];
1392
1393 dbg_hid("Setting autocenter to %d.\n", magnitude);
1394
1395 /* start a standard spring effect */
1396 params[1] = HIDPP_FF_EFFECT_SPRING | HIDPP_FF_EFFECT_AUTOSTART;
1397 /* zero delay and duration */
1398 params[2] = params[3] = params[4] = params[5] = 0;
1399 /* set coeff to 25% of saturation */
1400 params[8] = params[14] = magnitude >> 11;
1401 params[9] = params[15] = (magnitude >> 3) & 255;
1402 params[6] = params[16] = magnitude >> 9;
1403 params[7] = params[17] = (magnitude >> 1) & 255;
1404 /* zero deadband and center */
1405 params[10] = params[11] = params[12] = params[13] = 0;
1406
1407 hidpp_ff_queue_work(data, HIDPP_FF_EFFECTID_AUTOCENTER, HIDPP_FF_DOWNLOAD_EFFECT, params, ARRAY_SIZE(params));
1408}
1409
1410static void hidpp_ff_set_gain(struct input_dev *dev, u16 gain)
1411{
1412 struct hidpp_ff_private_data *data = dev->ff->private;
1413 u8 params[4];
1414
1415 dbg_hid("Setting gain to %d.\n", gain);
1416
1417 params[0] = gain >> 8;
1418 params[1] = gain & 255;
1419 params[2] = 0; /* no boost */
1420 params[3] = 0;
1421
1422 hidpp_ff_queue_work(data, HIDPP_FF_EFFECTID_NONE, HIDPP_FF_SET_GLOBAL_GAINS, params, ARRAY_SIZE(params));
1423}
1424
1425static ssize_t hidpp_ff_range_show(struct device *dev, struct device_attribute *attr, char *buf)
1426{
1427 struct hid_device *hid = to_hid_device(dev);
1428 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
1429 struct input_dev *idev = hidinput->input;
1430 struct hidpp_ff_private_data *data = idev->ff->private;
1431
1432 return scnprintf(buf, PAGE_SIZE, "%u\n", data->range);
1433}
1434
1435static ssize_t hidpp_ff_range_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1436{
1437 struct hid_device *hid = to_hid_device(dev);
1438 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
1439 struct input_dev *idev = hidinput->input;
1440 struct hidpp_ff_private_data *data = idev->ff->private;
1441 u8 params[2];
1442 int range = simple_strtoul(buf, NULL, 10);
1443
1444 range = clamp(range, 180, 900);
1445
1446 params[0] = range >> 8;
1447 params[1] = range & 0x00FF;
1448
1449 hidpp_ff_queue_work(data, -1, HIDPP_FF_SET_APERTURE, params, ARRAY_SIZE(params));
1450
1451 return count;
1452}
1453
1454static DEVICE_ATTR(range, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, hidpp_ff_range_show, hidpp_ff_range_store);
1455
1456static void hidpp_ff_destroy(struct ff_device *ff)
1457{
1458 struct hidpp_ff_private_data *data = ff->private;
1459
1460 kfree(data->effect_ids);
1461}
1462
Jiri Kosinaaf2e6282016-01-28 14:28:39 +01001463static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index)
Edwin Veldsff21a632016-01-11 00:25:15 +01001464{
1465 struct hid_device *hid = hidpp->hid_dev;
1466 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
1467 struct input_dev *dev = hidinput->input;
1468 const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
1469 const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice);
1470 struct ff_device *ff;
1471 struct hidpp_report response;
1472 struct hidpp_ff_private_data *data;
1473 int error, j, num_slots;
1474 u8 version;
1475
1476 if (!dev) {
1477 hid_err(hid, "Struct input_dev not set!\n");
1478 return -EINVAL;
1479 }
1480
1481 /* Get firmware release */
1482 version = bcdDevice & 255;
1483
1484 /* Set supported force feedback capabilities */
1485 for (j = 0; hiddpp_ff_effects[j] >= 0; j++)
1486 set_bit(hiddpp_ff_effects[j], dev->ffbit);
1487 if (version > 1)
1488 for (j = 0; hiddpp_ff_effects_v2[j] >= 0; j++)
1489 set_bit(hiddpp_ff_effects_v2[j], dev->ffbit);
1490
1491 /* Read number of slots available in device */
1492 error = hidpp_send_fap_command_sync(hidpp, feature_index,
1493 HIDPP_FF_GET_INFO, NULL, 0, &response);
1494 if (error) {
1495 if (error < 0)
1496 return error;
1497 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1498 __func__, error);
1499 return -EPROTO;
1500 }
1501
1502 num_slots = response.fap.params[0] - HIDPP_FF_RESERVED_SLOTS;
1503
1504 error = input_ff_create(dev, num_slots);
1505
1506 if (error) {
1507 hid_err(dev, "Failed to create FF device!\n");
1508 return error;
1509 }
1510
1511 data = kzalloc(sizeof(*data), GFP_KERNEL);
1512 if (!data)
1513 return -ENOMEM;
1514 data->effect_ids = kcalloc(num_slots, sizeof(int), GFP_KERNEL);
1515 if (!data->effect_ids) {
1516 kfree(data);
1517 return -ENOMEM;
1518 }
1519 data->hidpp = hidpp;
1520 data->feature_index = feature_index;
1521 data->version = version;
1522 data->slot_autocenter = 0;
1523 data->num_effects = num_slots;
1524 for (j = 0; j < num_slots; j++)
1525 data->effect_ids[j] = -1;
1526
1527 ff = dev->ff;
1528 ff->private = data;
1529
1530 ff->upload = hidpp_ff_upload_effect;
1531 ff->erase = hidpp_ff_erase_effect;
1532 ff->playback = hidpp_ff_playback;
1533 ff->set_gain = hidpp_ff_set_gain;
1534 ff->set_autocenter = hidpp_ff_set_autocenter;
1535 ff->destroy = hidpp_ff_destroy;
1536
1537
1538 /* reset all forces */
1539 error = hidpp_send_fap_command_sync(hidpp, feature_index,
1540 HIDPP_FF_RESET_ALL, NULL, 0, &response);
1541
1542 /* Read current Range */
1543 error = hidpp_send_fap_command_sync(hidpp, feature_index,
1544 HIDPP_FF_GET_APERTURE, NULL, 0, &response);
1545 if (error)
1546 hid_warn(hidpp->hid_dev, "Failed to read range from device!\n");
1547 data->range = error ? 900 : get_unaligned_be16(&response.fap.params[0]);
1548
1549 /* Create sysfs interface */
1550 error = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range);
1551 if (error)
1552 hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d!\n", error);
1553
1554 /* Read the current gain values */
1555 error = hidpp_send_fap_command_sync(hidpp, feature_index,
1556 HIDPP_FF_GET_GLOBAL_GAINS, NULL, 0, &response);
1557 if (error)
1558 hid_warn(hidpp->hid_dev, "Failed to read gain values from device!\n");
1559 data->gain = error ? 0xffff : get_unaligned_be16(&response.fap.params[0]);
1560 /* ignore boost value at response.fap.params[2] */
1561
1562 /* init the hardware command queue */
1563 data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue");
1564 atomic_set(&data->workqueue_size, 0);
1565
1566 /* initialize with zero autocenter to get wheel in usable state */
1567 hidpp_ff_set_autocenter(dev, 0);
1568
1569 hid_info(hid, "Force feeback support loaded (firmware release %d).\n", version);
1570
1571 return 0;
1572}
1573
Jiri Kosinaaf2e6282016-01-28 14:28:39 +01001574static int hidpp_ff_deinit(struct hid_device *hid)
Edwin Veldsff21a632016-01-11 00:25:15 +01001575{
1576 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
1577 struct input_dev *dev = hidinput->input;
1578 struct hidpp_ff_private_data *data;
1579
1580 if (!dev) {
1581 hid_err(hid, "Struct input_dev not found!\n");
1582 return -EINVAL;
1583 }
1584
1585 hid_info(hid, "Unloading HID++ force feedback.\n");
1586 data = dev->ff->private;
1587 if (!data) {
1588 hid_err(hid, "Private data not found!\n");
1589 return -EINVAL;
1590 }
1591
1592 destroy_workqueue(data->wq);
1593 device_remove_file(&hid->dev, &dev_attr_range);
1594
1595 return 0;
1596}
1597
1598
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001599/* ************************************************************************** */
1600/* */
1601/* Device Support */
1602/* */
1603/* ************************************************************************** */
1604
1605/* -------------------------------------------------------------------------- */
1606/* Touchpad HID++ devices */
1607/* -------------------------------------------------------------------------- */
1608
Benjamin Tissoires57ac86c2014-09-30 13:18:34 -04001609#define WTP_MANUAL_RESOLUTION 39
1610
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001611struct wtp_data {
1612 struct input_dev *input;
1613 u16 x_size, y_size;
1614 u8 finger_count;
1615 u8 mt_feature_index;
1616 u8 button_feature_index;
1617 u8 maxcontacts;
1618 bool flip_y;
1619 unsigned int resolution;
1620};
1621
1622static int wtp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
1623 struct hid_field *field, struct hid_usage *usage,
1624 unsigned long **bit, int *max)
1625{
1626 return -1;
1627}
1628
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04001629static void wtp_populate_input(struct hidpp_device *hidpp,
1630 struct input_dev *input_dev, bool origin_is_hid_core)
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001631{
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001632 struct wtp_data *wd = hidpp->private_data;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001633
1634 __set_bit(EV_ABS, input_dev->evbit);
1635 __set_bit(EV_KEY, input_dev->evbit);
1636 __clear_bit(EV_REL, input_dev->evbit);
1637 __clear_bit(EV_LED, input_dev->evbit);
1638
1639 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0);
1640 input_abs_set_res(input_dev, ABS_MT_POSITION_X, wd->resolution);
1641 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0);
1642 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, wd->resolution);
1643
1644 /* Max pressure is not given by the devices, pick one */
1645 input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 50, 0, 0);
1646
1647 input_set_capability(input_dev, EV_KEY, BTN_LEFT);
1648
Benjamin Tissoires57ac86c2014-09-30 13:18:34 -04001649 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS)
1650 input_set_capability(input_dev, EV_KEY, BTN_RIGHT);
1651 else
1652 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001653
1654 input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER |
1655 INPUT_MT_DROP_UNUSED);
1656
1657 wd->input = input_dev;
1658}
1659
1660static void wtp_touch_event(struct wtp_data *wd,
1661 struct hidpp_touchpad_raw_xy_finger *touch_report)
1662{
1663 int slot;
1664
1665 if (!touch_report->finger_id || touch_report->contact_type)
1666 /* no actual data */
1667 return;
1668
1669 slot = input_mt_get_slot_by_key(wd->input, touch_report->finger_id);
1670
1671 input_mt_slot(wd->input, slot);
1672 input_mt_report_slot_state(wd->input, MT_TOOL_FINGER,
1673 touch_report->contact_status);
1674 if (touch_report->contact_status) {
1675 input_event(wd->input, EV_ABS, ABS_MT_POSITION_X,
1676 touch_report->x);
1677 input_event(wd->input, EV_ABS, ABS_MT_POSITION_Y,
1678 wd->flip_y ? wd->y_size - touch_report->y :
1679 touch_report->y);
1680 input_event(wd->input, EV_ABS, ABS_MT_PRESSURE,
1681 touch_report->area);
1682 }
1683}
1684
1685static void wtp_send_raw_xy_event(struct hidpp_device *hidpp,
1686 struct hidpp_touchpad_raw_xy *raw)
1687{
1688 struct wtp_data *wd = hidpp->private_data;
1689 int i;
1690
1691 for (i = 0; i < 2; i++)
1692 wtp_touch_event(wd, &(raw->fingers[i]));
1693
Benjamin Tissoires57ac86c2014-09-30 13:18:34 -04001694 if (raw->end_of_frame &&
1695 !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS))
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001696 input_event(wd->input, EV_KEY, BTN_LEFT, raw->button);
1697
1698 if (raw->end_of_frame || raw->finger_count <= 2) {
1699 input_mt_sync_frame(wd->input);
1700 input_sync(wd->input);
1701 }
1702}
1703
1704static int wtp_mouse_raw_xy_event(struct hidpp_device *hidpp, u8 *data)
1705{
1706 struct wtp_data *wd = hidpp->private_data;
1707 u8 c1_area = ((data[7] & 0xf) * (data[7] & 0xf) +
1708 (data[7] >> 4) * (data[7] >> 4)) / 2;
1709 u8 c2_area = ((data[13] & 0xf) * (data[13] & 0xf) +
1710 (data[13] >> 4) * (data[13] >> 4)) / 2;
1711 struct hidpp_touchpad_raw_xy raw = {
1712 .timestamp = data[1],
1713 .fingers = {
1714 {
1715 .contact_type = 0,
1716 .contact_status = !!data[7],
1717 .x = get_unaligned_le16(&data[3]),
1718 .y = get_unaligned_le16(&data[5]),
1719 .z = c1_area,
1720 .area = c1_area,
1721 .finger_id = data[2],
1722 }, {
1723 .contact_type = 0,
1724 .contact_status = !!data[13],
1725 .x = get_unaligned_le16(&data[9]),
1726 .y = get_unaligned_le16(&data[11]),
1727 .z = c2_area,
1728 .area = c2_area,
1729 .finger_id = data[8],
1730 }
1731 },
1732 .finger_count = wd->maxcontacts,
1733 .spurious_flag = 0,
1734 .end_of_frame = (data[0] >> 7) == 0,
1735 .button = data[0] & 0x01,
1736 };
1737
1738 wtp_send_raw_xy_event(hidpp, &raw);
1739
1740 return 1;
1741}
1742
1743static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size)
1744{
1745 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
1746 struct wtp_data *wd = hidpp->private_data;
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04001747 struct hidpp_report *report = (struct hidpp_report *)data;
1748 struct hidpp_touchpad_raw_xy raw;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001749
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04001750 if (!wd || !wd->input)
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001751 return 1;
1752
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04001753 switch (data[0]) {
1754 case 0x02:
Peter Wu0b3f6562014-12-16 16:55:22 +01001755 if (size < 2) {
1756 hid_err(hdev, "Received HID report of bad size (%d)",
1757 size);
1758 return 1;
1759 }
Benjamin Tissoires57ac86c2014-09-30 13:18:34 -04001760 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) {
1761 input_event(wd->input, EV_KEY, BTN_LEFT,
1762 !!(data[1] & 0x01));
1763 input_event(wd->input, EV_KEY, BTN_RIGHT,
1764 !!(data[1] & 0x02));
1765 input_sync(wd->input);
Peter Wu8abd8202014-12-16 01:50:16 +01001766 return 0;
Benjamin Tissoires57ac86c2014-09-30 13:18:34 -04001767 } else {
1768 if (size < 21)
1769 return 1;
1770 return wtp_mouse_raw_xy_event(hidpp, &data[7]);
1771 }
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04001772 case REPORT_ID_HIDPP_LONG:
Peter Wu0b3f6562014-12-16 16:55:22 +01001773 /* size is already checked in hidpp_raw_event. */
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04001774 if ((report->fap.feature_index != wd->mt_feature_index) ||
1775 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY))
1776 return 1;
1777 hidpp_touchpad_raw_xy_event(hidpp, data + 4, &raw);
1778
1779 wtp_send_raw_xy_event(hidpp, &raw);
1780 return 0;
1781 }
1782
1783 return 0;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001784}
1785
1786static int wtp_get_config(struct hidpp_device *hidpp)
1787{
1788 struct wtp_data *wd = hidpp->private_data;
1789 struct hidpp_touchpad_raw_info raw_info = {0};
1790 u8 feature_type;
1791 int ret;
1792
1793 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_TOUCHPAD_RAW_XY,
1794 &wd->mt_feature_index, &feature_type);
1795 if (ret)
1796 /* means that the device is not powered up */
1797 return ret;
1798
1799 ret = hidpp_touchpad_get_raw_info(hidpp, wd->mt_feature_index,
1800 &raw_info);
1801 if (ret)
1802 return ret;
1803
1804 wd->x_size = raw_info.x_size;
1805 wd->y_size = raw_info.y_size;
1806 wd->maxcontacts = raw_info.maxcontacts;
1807 wd->flip_y = raw_info.origin == TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT;
1808 wd->resolution = raw_info.res;
Benjamin Tissoires57ac86c2014-09-30 13:18:34 -04001809 if (!wd->resolution)
1810 wd->resolution = WTP_MANUAL_RESOLUTION;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04001811
1812 return 0;
1813}
1814
1815static int wtp_allocate(struct hid_device *hdev, const struct hid_device_id *id)
1816{
1817 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
1818 struct wtp_data *wd;
1819
1820 wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data),
1821 GFP_KERNEL);
1822 if (!wd)
1823 return -ENOMEM;
1824
1825 hidpp->private_data = wd;
1826
1827 return 0;
1828};
1829
Benjamin Tissoiresbf159442014-12-16 17:06:01 -05001830static int wtp_connect(struct hid_device *hdev, bool connected)
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04001831{
1832 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
1833 struct wtp_data *wd = hidpp->private_data;
1834 int ret;
1835
1836 if (!connected)
Benjamin Tissoiresbf159442014-12-16 17:06:01 -05001837 return 0;
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04001838
1839 if (!wd->x_size) {
1840 ret = wtp_get_config(hidpp);
1841 if (ret) {
1842 hid_err(hdev, "Can not get wtp config: %d\n", ret);
Benjamin Tissoiresbf159442014-12-16 17:06:01 -05001843 return ret;
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04001844 }
1845 }
1846
Benjamin Tissoiresbf159442014-12-16 17:06:01 -05001847 return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index,
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04001848 true, true);
1849}
1850
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +02001851/* ------------------------------------------------------------------------- */
1852/* Logitech M560 devices */
1853/* ------------------------------------------------------------------------- */
1854
1855/*
1856 * Logitech M560 protocol overview
1857 *
1858 * The Logitech M560 mouse, is designed for windows 8. When the middle and/or
1859 * the sides buttons are pressed, it sends some keyboard keys events
1860 * instead of buttons ones.
1861 * To complicate things further, the middle button keys sequence
1862 * is different from the odd press and the even press.
1863 *
1864 * forward button -> Super_R
1865 * backward button -> Super_L+'d' (press only)
1866 * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
1867 * 2nd time: left-click (press only)
1868 * NB: press-only means that when the button is pressed, the
1869 * KeyPress/ButtonPress and KeyRelease/ButtonRelease events are generated
1870 * together sequentially; instead when the button is released, no event is
1871 * generated !
1872 *
1873 * With the command
1874 * 10<xx>0a 3500af03 (where <xx> is the mouse id),
1875 * the mouse reacts differently:
1876 * - it never sends a keyboard key event
1877 * - for the three mouse button it sends:
1878 * middle button press 11<xx>0a 3500af00...
1879 * side 1 button (forward) press 11<xx>0a 3500b000...
1880 * side 2 button (backward) press 11<xx>0a 3500ae00...
1881 * middle/side1/side2 button release 11<xx>0a 35000000...
1882 */
1883
1884static const u8 m560_config_parameter[] = {0x00, 0xaf, 0x03};
1885
1886struct m560_private_data {
1887 struct input_dev *input;
1888};
1889
1890/* how buttons are mapped in the report */
1891#define M560_MOUSE_BTN_LEFT 0x01
1892#define M560_MOUSE_BTN_RIGHT 0x02
1893#define M560_MOUSE_BTN_WHEEL_LEFT 0x08
1894#define M560_MOUSE_BTN_WHEEL_RIGHT 0x10
1895
1896#define M560_SUB_ID 0x0a
1897#define M560_BUTTON_MODE_REGISTER 0x35
1898
1899static int m560_send_config_command(struct hid_device *hdev, bool connected)
1900{
1901 struct hidpp_report response;
1902 struct hidpp_device *hidpp_dev;
1903
1904 hidpp_dev = hid_get_drvdata(hdev);
1905
1906 if (!connected)
1907 return -ENODEV;
1908
1909 return hidpp_send_rap_command_sync(
1910 hidpp_dev,
1911 REPORT_ID_HIDPP_SHORT,
1912 M560_SUB_ID,
1913 M560_BUTTON_MODE_REGISTER,
1914 (u8 *)m560_config_parameter,
1915 sizeof(m560_config_parameter),
1916 &response
1917 );
1918}
1919
1920static int m560_allocate(struct hid_device *hdev)
1921{
1922 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
1923 struct m560_private_data *d;
1924
1925 d = devm_kzalloc(&hdev->dev, sizeof(struct m560_private_data),
1926 GFP_KERNEL);
1927 if (!d)
1928 return -ENOMEM;
1929
1930 hidpp->private_data = d;
1931
1932 return 0;
1933};
1934
1935static int m560_raw_event(struct hid_device *hdev, u8 *data, int size)
1936{
1937 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
1938 struct m560_private_data *mydata = hidpp->private_data;
1939
1940 /* sanity check */
1941 if (!mydata || !mydata->input) {
1942 hid_err(hdev, "error in parameter\n");
1943 return -EINVAL;
1944 }
1945
1946 if (size < 7) {
1947 hid_err(hdev, "error in report\n");
1948 return 0;
1949 }
1950
1951 if (data[0] == REPORT_ID_HIDPP_LONG &&
1952 data[2] == M560_SUB_ID && data[6] == 0x00) {
1953 /*
1954 * m560 mouse report for middle, forward and backward button
1955 *
1956 * data[0] = 0x11
1957 * data[1] = device-id
1958 * data[2] = 0x0a
1959 * data[5] = 0xaf -> middle
1960 * 0xb0 -> forward
1961 * 0xae -> backward
1962 * 0x00 -> release all
1963 * data[6] = 0x00
1964 */
1965
1966 switch (data[5]) {
1967 case 0xaf:
1968 input_report_key(mydata->input, BTN_MIDDLE, 1);
1969 break;
1970 case 0xb0:
1971 input_report_key(mydata->input, BTN_FORWARD, 1);
1972 break;
1973 case 0xae:
1974 input_report_key(mydata->input, BTN_BACK, 1);
1975 break;
1976 case 0x00:
1977 input_report_key(mydata->input, BTN_BACK, 0);
1978 input_report_key(mydata->input, BTN_FORWARD, 0);
1979 input_report_key(mydata->input, BTN_MIDDLE, 0);
1980 break;
1981 default:
1982 hid_err(hdev, "error in report\n");
1983 return 0;
1984 }
1985 input_sync(mydata->input);
1986
1987 } else if (data[0] == 0x02) {
1988 /*
1989 * Logitech M560 mouse report
1990 *
1991 * data[0] = type (0x02)
1992 * data[1..2] = buttons
1993 * data[3..5] = xy
1994 * data[6] = wheel
1995 */
1996
1997 int v;
1998
1999 input_report_key(mydata->input, BTN_LEFT,
2000 !!(data[1] & M560_MOUSE_BTN_LEFT));
2001 input_report_key(mydata->input, BTN_RIGHT,
2002 !!(data[1] & M560_MOUSE_BTN_RIGHT));
2003
2004 if (data[1] & M560_MOUSE_BTN_WHEEL_LEFT)
2005 input_report_rel(mydata->input, REL_HWHEEL, -1);
2006 else if (data[1] & M560_MOUSE_BTN_WHEEL_RIGHT)
2007 input_report_rel(mydata->input, REL_HWHEEL, 1);
2008
2009 v = hid_snto32(hid_field_extract(hdev, data+3, 0, 12), 12);
2010 input_report_rel(mydata->input, REL_X, v);
2011
2012 v = hid_snto32(hid_field_extract(hdev, data+3, 12, 12), 12);
2013 input_report_rel(mydata->input, REL_Y, v);
2014
2015 v = hid_snto32(data[6], 8);
2016 input_report_rel(mydata->input, REL_WHEEL, v);
2017
2018 input_sync(mydata->input);
2019 }
2020
2021 return 1;
2022}
2023
2024static void m560_populate_input(struct hidpp_device *hidpp,
2025 struct input_dev *input_dev, bool origin_is_hid_core)
2026{
2027 struct m560_private_data *mydata = hidpp->private_data;
2028
2029 mydata->input = input_dev;
2030
2031 __set_bit(EV_KEY, mydata->input->evbit);
2032 __set_bit(BTN_MIDDLE, mydata->input->keybit);
2033 __set_bit(BTN_RIGHT, mydata->input->keybit);
2034 __set_bit(BTN_LEFT, mydata->input->keybit);
2035 __set_bit(BTN_BACK, mydata->input->keybit);
2036 __set_bit(BTN_FORWARD, mydata->input->keybit);
2037
2038 __set_bit(EV_REL, mydata->input->evbit);
2039 __set_bit(REL_X, mydata->input->relbit);
2040 __set_bit(REL_Y, mydata->input->relbit);
2041 __set_bit(REL_WHEEL, mydata->input->relbit);
2042 __set_bit(REL_HWHEEL, mydata->input->relbit);
2043}
2044
2045static int m560_input_mapping(struct hid_device *hdev, struct hid_input *hi,
2046 struct hid_field *field, struct hid_usage *usage,
2047 unsigned long **bit, int *max)
2048{
2049 return -1;
2050}
2051
Benjamin Tissoires90cdd982015-09-03 09:08:30 -04002052/* ------------------------------------------------------------------------- */
2053/* Logitech K400 devices */
2054/* ------------------------------------------------------------------------- */
2055
2056/*
2057 * The Logitech K400 keyboard has an embedded touchpad which is seen
2058 * as a mouse from the OS point of view. There is a hardware shortcut to disable
2059 * tap-to-click but the setting is not remembered accross reset, annoying some
2060 * users.
2061 *
2062 * We can toggle this feature from the host by using the feature 0x6010:
2063 * Touchpad FW items
2064 */
2065
2066struct k400_private_data {
2067 u8 feature_index;
2068};
2069
2070static int k400_disable_tap_to_click(struct hidpp_device *hidpp)
2071{
2072 struct k400_private_data *k400 = hidpp->private_data;
2073 struct hidpp_touchpad_fw_items items = {};
2074 int ret;
2075 u8 feature_type;
2076
2077 if (!k400->feature_index) {
2078 ret = hidpp_root_get_feature(hidpp,
2079 HIDPP_PAGE_TOUCHPAD_FW_ITEMS,
2080 &k400->feature_index, &feature_type);
2081 if (ret)
2082 /* means that the device is not powered up */
2083 return ret;
2084 }
2085
2086 ret = hidpp_touchpad_fw_items_set(hidpp, k400->feature_index, &items);
2087 if (ret)
2088 return ret;
2089
2090 return 0;
2091}
2092
2093static int k400_allocate(struct hid_device *hdev)
2094{
2095 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2096 struct k400_private_data *k400;
2097
2098 k400 = devm_kzalloc(&hdev->dev, sizeof(struct k400_private_data),
2099 GFP_KERNEL);
2100 if (!k400)
2101 return -ENOMEM;
2102
2103 hidpp->private_data = k400;
2104
2105 return 0;
2106};
2107
2108static int k400_connect(struct hid_device *hdev, bool connected)
2109{
2110 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2111
2112 if (!connected)
2113 return 0;
2114
2115 if (!disable_tap_to_click)
2116 return 0;
2117
2118 return k400_disable_tap_to_click(hidpp);
2119}
2120
Simon Wood7f4b49f2015-11-19 16:42:13 -07002121/* ------------------------------------------------------------------------- */
2122/* Logitech G920 Driving Force Racing Wheel for Xbox One */
2123/* ------------------------------------------------------------------------- */
2124
2125#define HIDPP_PAGE_G920_FORCE_FEEDBACK 0x8123
2126
Simon Wood7f4b49f2015-11-19 16:42:13 -07002127static int g920_get_config(struct hidpp_device *hidpp)
2128{
Simon Wood7f4b49f2015-11-19 16:42:13 -07002129 u8 feature_type;
2130 u8 feature_index;
2131 int ret;
2132
Simon Wood7f4b49f2015-11-19 16:42:13 -07002133 /* Find feature and store for later use */
2134 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_G920_FORCE_FEEDBACK,
2135 &feature_index, &feature_type);
2136 if (ret)
2137 return ret;
2138
Edwin Veldsff21a632016-01-11 00:25:15 +01002139 ret = hidpp_ff_init(hidpp, feature_index);
Simon Wood7f4b49f2015-11-19 16:42:13 -07002140 if (ret)
Edwin Veldsff21a632016-01-11 00:25:15 +01002141 hid_warn(hidpp->hid_dev, "Unable to initialize force feedback support, errno %d\n",
2142 ret);
Simon Wood7f4b49f2015-11-19 16:42:13 -07002143
2144 return 0;
2145}
2146
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002147/* -------------------------------------------------------------------------- */
2148/* Generic HID++ devices */
2149/* -------------------------------------------------------------------------- */
2150
2151static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
2152 struct hid_field *field, struct hid_usage *usage,
2153 unsigned long **bit, int *max)
2154{
2155 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2156
2157 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
2158 return wtp_input_mapping(hdev, hi, field, usage, bit, max);
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +02002159 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 &&
2160 field->application != HID_GD_MOUSE)
2161 return m560_input_mapping(hdev, hi, field, usage, bit, max);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002162
2163 return 0;
2164}
2165
Simon Wood0b1804e2015-11-19 16:42:15 -07002166static int hidpp_input_mapped(struct hid_device *hdev, struct hid_input *hi,
2167 struct hid_field *field, struct hid_usage *usage,
2168 unsigned long **bit, int *max)
2169{
2170 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2171
2172 /* Ensure that Logitech G920 is not given a default fuzz/flat value */
2173 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
2174 if (usage->type == EV_ABS && (usage->code == ABS_X ||
2175 usage->code == ABS_Y || usage->code == ABS_Z ||
2176 usage->code == ABS_RZ)) {
2177 field->application = HID_GD_MULTIAXIS;
2178 }
2179 }
2180
2181 return 0;
2182}
2183
2184
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002185static void hidpp_populate_input(struct hidpp_device *hidpp,
2186 struct input_dev *input, bool origin_is_hid_core)
2187{
2188 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
2189 wtp_populate_input(hidpp, input, origin_is_hid_core);
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +02002190 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
2191 m560_populate_input(hidpp, input, origin_is_hid_core);
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002192}
2193
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07002194static int hidpp_input_configured(struct hid_device *hdev,
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002195 struct hid_input *hidinput)
2196{
2197 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002198 struct input_dev *input = hidinput->input;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002199
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002200 hidpp_populate_input(hidpp, input, true);
Dmitry Torokhovb2c68a22015-09-29 15:52:59 -07002201
2202 return 0;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002203}
2204
2205static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,
2206 int size)
2207{
2208 struct hidpp_report *question = hidpp->send_receive_buf;
2209 struct hidpp_report *answer = hidpp->send_receive_buf;
2210 struct hidpp_report *report = (struct hidpp_report *)data;
2211
2212 /*
2213 * If the mutex is locked then we have a pending answer from a
Peter Wue529fea2014-12-17 00:23:51 +01002214 * previously sent command.
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002215 */
2216 if (unlikely(mutex_is_locked(&hidpp->send_mutex))) {
2217 /*
2218 * Check for a correct hidpp20 answer or the corresponding
2219 * error
2220 */
2221 if (hidpp_match_answer(question, report) ||
2222 hidpp_match_error(question, report)) {
2223 *answer = *report;
2224 hidpp->answer_available = true;
2225 wake_up(&hidpp->wait);
2226 /*
2227 * This was an answer to a command that this driver sent
2228 * We return 1 to hid-core to avoid forwarding the
2229 * command upstream as it has been treated by the driver
2230 */
2231
2232 return 1;
2233 }
2234 }
2235
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002236 if (unlikely(hidpp_report_is_connect_event(report))) {
2237 atomic_set(&hidpp->connected,
2238 !(report->rap.params[0] & (1 << 6)));
Benjamin Tissoires6bd4e652016-06-29 19:28:02 +10002239 if (schedule_work(&hidpp->work) == 0)
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002240 dbg_hid("%s: connect event already queued\n", __func__);
2241 return 1;
2242 }
2243
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002244 return 0;
2245}
2246
2247static int hidpp_raw_event(struct hid_device *hdev, struct hid_report *report,
2248 u8 *data, int size)
2249{
2250 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
Peter Wue529fea2014-12-17 00:23:51 +01002251 int ret = 0;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002252
Peter Wue529fea2014-12-17 00:23:51 +01002253 /* Generic HID++ processing. */
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002254 switch (data[0]) {
Simon Wooda5ce8f52015-11-19 16:42:11 -07002255 case REPORT_ID_HIDPP_VERY_LONG:
2256 if (size != HIDPP_REPORT_VERY_LONG_LENGTH) {
2257 hid_err(hdev, "received hid++ report of bad size (%d)",
2258 size);
2259 return 1;
2260 }
2261 ret = hidpp_raw_hidpp_event(hidpp, data, size);
2262 break;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002263 case REPORT_ID_HIDPP_LONG:
2264 if (size != HIDPP_REPORT_LONG_LENGTH) {
2265 hid_err(hdev, "received hid++ report of bad size (%d)",
2266 size);
2267 return 1;
2268 }
Peter Wue529fea2014-12-17 00:23:51 +01002269 ret = hidpp_raw_hidpp_event(hidpp, data, size);
2270 break;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002271 case REPORT_ID_HIDPP_SHORT:
2272 if (size != HIDPP_REPORT_SHORT_LENGTH) {
2273 hid_err(hdev, "received hid++ report of bad size (%d)",
2274 size);
2275 return 1;
2276 }
Peter Wue529fea2014-12-17 00:23:51 +01002277 ret = hidpp_raw_hidpp_event(hidpp, data, size);
2278 break;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002279 }
2280
Peter Wue529fea2014-12-17 00:23:51 +01002281 /* If no report is available for further processing, skip calling
2282 * raw_event of subclasses. */
2283 if (ret != 0)
2284 return ret;
2285
Peter Hutterer5a2b1902016-06-29 19:28:01 +10002286 if (hidpp->quirks & HIDPP_QUIRK_HIDPP20_BATTERY) {
2287 ret = hidpp20_battery_event(hidpp, data, size);
2288 if (ret != 0)
2289 return ret;
2290 }
2291
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002292 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
2293 return wtp_raw_event(hdev, data, size);
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +02002294 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
2295 return m560_raw_event(hdev, data, size);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002296
2297 return 0;
2298}
2299
Benjamin Tissoires33797822014-09-30 13:18:30 -04002300static void hidpp_overwrite_name(struct hid_device *hdev, bool use_unifying)
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002301{
2302 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2303 char *name;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002304
Benjamin Tissoires33797822014-09-30 13:18:30 -04002305 if (use_unifying)
2306 /*
2307 * the device is connected through an Unifying receiver, and
2308 * might not be already connected.
2309 * Ask the receiver for its name.
2310 */
2311 name = hidpp_get_unifying_name(hidpp);
Benjamin Tissoiresb4f8ce02017-03-27 16:59:24 +02002312 else if (hidpp->protocol_major < 2)
2313 return;
Benjamin Tissoires33797822014-09-30 13:18:30 -04002314 else
Peter Wu02cc0972014-12-11 13:51:17 +01002315 name = hidpp_get_device_name(hidpp);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002316
Simon Wood7bfd2922015-11-19 16:42:12 -07002317 if (!name) {
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002318 hid_err(hdev, "unable to retrieve the name of the device");
Simon Wood7bfd2922015-11-19 16:42:12 -07002319 } else {
2320 dbg_hid("HID++: Got name: %s\n", name);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002321 snprintf(hdev->name, sizeof(hdev->name), "%s", name);
Simon Wood7bfd2922015-11-19 16:42:12 -07002322 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002323
2324 kfree(name);
2325}
2326
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002327static int hidpp_input_open(struct input_dev *dev)
2328{
2329 struct hid_device *hid = input_get_drvdata(dev);
2330
2331 return hid_hw_open(hid);
2332}
2333
2334static void hidpp_input_close(struct input_dev *dev)
2335{
2336 struct hid_device *hid = input_get_drvdata(dev);
2337
2338 hid_hw_close(hid);
2339}
2340
2341static struct input_dev *hidpp_allocate_input(struct hid_device *hdev)
2342{
2343 struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev);
Benjamin Tissoires005b3f52015-01-08 14:37:12 -05002344 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002345
2346 if (!input_dev)
2347 return NULL;
2348
2349 input_set_drvdata(input_dev, hdev);
2350 input_dev->open = hidpp_input_open;
2351 input_dev->close = hidpp_input_close;
2352
Benjamin Tissoires005b3f52015-01-08 14:37:12 -05002353 input_dev->name = hidpp->name;
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002354 input_dev->phys = hdev->phys;
2355 input_dev->uniq = hdev->uniq;
2356 input_dev->id.bustype = hdev->bus;
2357 input_dev->id.vendor = hdev->vendor;
2358 input_dev->id.product = hdev->product;
2359 input_dev->id.version = hdev->version;
2360 input_dev->dev.parent = &hdev->dev;
2361
2362 return input_dev;
2363}
2364
2365static void hidpp_connect_event(struct hidpp_device *hidpp)
2366{
2367 struct hid_device *hdev = hidpp->hid_dev;
2368 int ret = 0;
2369 bool connected = atomic_read(&hidpp->connected);
2370 struct input_dev *input;
2371 char *name, *devm_name;
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002372
Benjamin Tissoiresbf159442014-12-16 17:06:01 -05002373 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
2374 ret = wtp_connect(hdev, connected);
2375 if (ret)
2376 return;
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +02002377 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) {
2378 ret = m560_send_config_command(hdev, connected);
2379 if (ret)
2380 return;
Benjamin Tissoires90cdd982015-09-03 09:08:30 -04002381 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
2382 ret = k400_connect(hdev, connected);
2383 if (ret)
2384 return;
Benjamin Tissoiresbf159442014-12-16 17:06:01 -05002385 }
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04002386
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002387 if (!connected || hidpp->delayed_input)
2388 return;
2389
Benjamin Tissoires580a7e82015-09-03 09:08:29 -04002390 /* the device is already connected, we can ask for its name and
2391 * protocol */
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002392 if (!hidpp->protocol_major) {
2393 ret = !hidpp_is_connected(hidpp);
2394 if (ret) {
2395 hid_err(hdev, "Can not get the protocol version.\n");
2396 return;
2397 }
Benjamin Tissoires580a7e82015-09-03 09:08:29 -04002398 hid_info(hdev, "HID++ %u.%u device connected.\n",
2399 hidpp->protocol_major, hidpp->protocol_minor);
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002400 }
2401
Peter Hutterer5a2b1902016-06-29 19:28:01 +10002402 hidpp_initialize_battery(hidpp);
2403
Benjamin Tissoires580a7e82015-09-03 09:08:29 -04002404 if (!(hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT))
2405 /* if HID created the input nodes for us, we can stop now */
2406 return;
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002407
Benjamin Tissoires005b3f52015-01-08 14:37:12 -05002408 if (!hidpp->name || hidpp->name == hdev->name) {
2409 name = hidpp_get_device_name(hidpp);
2410 if (!name) {
2411 hid_err(hdev,
2412 "unable to retrieve the name of the device");
2413 return;
2414 }
2415
2416 devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s", name);
2417 kfree(name);
2418 if (!devm_name)
2419 return;
2420
2421 hidpp->name = devm_name;
2422 }
2423
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002424 input = hidpp_allocate_input(hdev);
2425 if (!input) {
2426 hid_err(hdev, "cannot allocate new input device: %d\n", ret);
2427 return;
2428 }
2429
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002430 hidpp_populate_input(hidpp, input, false);
2431
2432 ret = input_register_device(input);
2433 if (ret)
2434 input_free_device(input);
2435
2436 hidpp->delayed_input = input;
2437}
2438
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002439static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
2440{
2441 struct hidpp_device *hidpp;
2442 int ret;
2443 bool connected;
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002444 unsigned int connect_mask = HID_CONNECT_DEFAULT;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002445
2446 hidpp = devm_kzalloc(&hdev->dev, sizeof(struct hidpp_device),
2447 GFP_KERNEL);
2448 if (!hidpp)
2449 return -ENOMEM;
2450
2451 hidpp->hid_dev = hdev;
Benjamin Tissoires005b3f52015-01-08 14:37:12 -05002452 hidpp->name = hdev->name;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002453 hid_set_drvdata(hdev, hidpp);
2454
2455 hidpp->quirks = id->driver_data;
2456
Benjamin Tissoires9188dba2015-03-26 12:41:57 -04002457 if (disable_raw_mode) {
2458 hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP;
Benjamin Tissoires580a7e82015-09-03 09:08:29 -04002459 hidpp->quirks &= ~HIDPP_QUIRK_NO_HIDINPUT;
Benjamin Tissoires9188dba2015-03-26 12:41:57 -04002460 }
2461
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002462 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
2463 ret = wtp_allocate(hdev, id);
2464 if (ret)
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +02002465 goto allocate_fail;
2466 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) {
2467 ret = m560_allocate(hdev);
2468 if (ret)
2469 goto allocate_fail;
Benjamin Tissoires90cdd982015-09-03 09:08:30 -04002470 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
2471 ret = k400_allocate(hdev);
2472 if (ret)
2473 goto allocate_fail;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002474 }
2475
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002476 INIT_WORK(&hidpp->work, delayed_work_cb);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002477 mutex_init(&hidpp->send_mutex);
2478 init_waitqueue_head(&hidpp->wait);
2479
2480 ret = hid_parse(hdev);
2481 if (ret) {
2482 hid_err(hdev, "%s:parse failed\n", __func__);
2483 goto hid_parse_fail;
2484 }
2485
Simon Wood7bfd2922015-11-19 16:42:12 -07002486 if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT)
2487 connect_mask &= ~HID_CONNECT_HIDINPUT;
2488
2489 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
2490 ret = hid_hw_start(hdev, connect_mask);
2491 if (ret) {
2492 hid_err(hdev, "hw start failed\n");
2493 goto hid_hw_start_fail;
2494 }
2495 ret = hid_hw_open(hdev);
2496 if (ret < 0) {
2497 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n",
2498 __func__, ret);
2499 hid_hw_stop(hdev);
2500 goto hid_hw_start_fail;
2501 }
2502 }
2503
2504
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002505 /* Allow incoming packets */
2506 hid_device_io_start(hdev);
2507
2508 connected = hidpp_is_connected(hidpp);
Benjamin Tissoiresab94e562014-09-30 13:18:28 -04002509 if (id->group != HID_GROUP_LOGITECH_DJ_DEVICE) {
2510 if (!connected) {
Julia Lawallb832da52015-04-05 14:06:29 +02002511 ret = -ENODEV;
Benjamin Tissoiresab94e562014-09-30 13:18:28 -04002512 hid_err(hdev, "Device not connected");
Simon Wood7bfd2922015-11-19 16:42:12 -07002513 goto hid_hw_open_failed;
Benjamin Tissoiresab94e562014-09-30 13:18:28 -04002514 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002515
Benjamin Tissoiresab94e562014-09-30 13:18:28 -04002516 hid_info(hdev, "HID++ %u.%u device connected.\n",
2517 hidpp->protocol_major, hidpp->protocol_minor);
Benjamin Tissoiresab94e562014-09-30 13:18:28 -04002518 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002519
Benjamin Tissoires33797822014-09-30 13:18:30 -04002520 hidpp_overwrite_name(hdev, id->group == HID_GROUP_LOGITECH_DJ_DEVICE);
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002521 atomic_set(&hidpp->connected, connected);
Benjamin Tissoires33797822014-09-30 13:18:30 -04002522
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002523 if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) {
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002524 ret = wtp_get_config(hidpp);
2525 if (ret)
Simon Wood7bfd2922015-11-19 16:42:12 -07002526 goto hid_hw_open_failed;
Simon Wood7f4b49f2015-11-19 16:42:13 -07002527 } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) {
2528 ret = g920_get_config(hidpp);
2529 if (ret)
2530 goto hid_hw_open_failed;
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002531 }
2532
2533 /* Block incoming packets */
2534 hid_device_io_stop(hdev);
2535
Simon Wood7bfd2922015-11-19 16:42:12 -07002536 if (!(hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) {
2537 ret = hid_hw_start(hdev, connect_mask);
2538 if (ret) {
2539 hid_err(hdev, "%s:hid_hw_start returned error\n", __func__);
2540 goto hid_hw_start_fail;
2541 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002542 }
2543
Benjamin Tissoires6bd4e652016-06-29 19:28:02 +10002544 /* Allow incoming packets */
2545 hid_device_io_start(hdev);
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002546
Benjamin Tissoires6bd4e652016-06-29 19:28:02 +10002547 hidpp_connect_event(hidpp);
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002548
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002549 return ret;
2550
Simon Wood7bfd2922015-11-19 16:42:12 -07002551hid_hw_open_failed:
2552 hid_device_io_stop(hdev);
2553 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
2554 hid_hw_close(hdev);
2555 hid_hw_stop(hdev);
2556 }
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002557hid_hw_start_fail:
2558hid_parse_fail:
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002559 cancel_work_sync(&hidpp->work);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002560 mutex_destroy(&hidpp->send_mutex);
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +02002561allocate_fail:
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002562 hid_set_drvdata(hdev, NULL);
2563 return ret;
2564}
2565
2566static void hidpp_remove(struct hid_device *hdev)
2567{
2568 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2569
Simon Wood7f4b49f2015-11-19 16:42:13 -07002570 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
Edwin Veldsff21a632016-01-11 00:25:15 +01002571 hidpp_ff_deinit(hdev);
Simon Wood7bfd2922015-11-19 16:42:12 -07002572 hid_hw_close(hdev);
Simon Wood7f4b49f2015-11-19 16:42:13 -07002573 }
Simon Wood7bfd2922015-11-19 16:42:12 -07002574 hid_hw_stop(hdev);
Benjamin Tissoiresc39e3d52014-09-30 13:18:32 -04002575 cancel_work_sync(&hidpp->work);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002576 mutex_destroy(&hidpp->send_mutex);
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002577}
2578
2579static const struct hid_device_id hidpp_devices[] = {
Benjamin Tissoires57ac86c2014-09-30 13:18:34 -04002580 { /* wireless touchpad */
2581 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
2582 USB_VENDOR_ID_LOGITECH, 0x4011),
2583 .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT |
2584 HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS },
Benjamin Tissoires586bdc42014-09-30 13:18:33 -04002585 { /* wireless touchpad T650 */
2586 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
2587 USB_VENDOR_ID_LOGITECH, 0x4101),
2588 .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT },
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002589 { /* wireless touchpad T651 */
2590 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH,
2591 USB_DEVICE_ID_LOGITECH_T651),
2592 .driver_data = HIDPP_QUIRK_CLASS_WTP },
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +02002593 { /* Mouse logitech M560 */
Benjamin Tissoires3a61e972014-09-30 13:18:35 -04002594 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
Goffredo Baroncelli8a09b4f2015-05-30 11:00:27 +02002595 USB_VENDOR_ID_LOGITECH, 0x402d),
2596 .driver_data = HIDPP_QUIRK_DELAYED_INIT | HIDPP_QUIRK_CLASS_M560 },
Benjamin Tissoires90cdd982015-09-03 09:08:30 -04002597 { /* Keyboard logitech K400 */
2598 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
2599 USB_VENDOR_ID_LOGITECH, 0x4024),
Benjamin Tissoires6bd4e652016-06-29 19:28:02 +10002600 .driver_data = HIDPP_QUIRK_CLASS_K400 },
Benjamin Tissoiresab94e562014-09-30 13:18:28 -04002601
2602 { HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
2603 USB_VENDOR_ID_LOGITECH, HID_ANY_ID)},
Simon Wood7bfd2922015-11-19 16:42:12 -07002604
2605 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL),
2606 .driver_data = HIDPP_QUIRK_CLASS_G920 | HIDPP_QUIRK_FORCE_OUTPUT_REPORTS},
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002607 {}
2608};
2609
2610MODULE_DEVICE_TABLE(hid, hidpp_devices);
2611
2612static struct hid_driver hidpp_driver = {
2613 .name = "logitech-hidpp-device",
2614 .id_table = hidpp_devices,
2615 .probe = hidpp_probe,
2616 .remove = hidpp_remove,
2617 .raw_event = hidpp_raw_event,
2618 .input_configured = hidpp_input_configured,
2619 .input_mapping = hidpp_input_mapping,
Simon Wood0b1804e2015-11-19 16:42:15 -07002620 .input_mapped = hidpp_input_mapped,
Benjamin Tissoires2f31c522014-09-30 13:18:27 -04002621};
2622
2623module_hid_driver(hidpp_driver);