2 * HIDPP protocol for Logitech Unifying receivers
4 * Copyright (c) 2011 Logitech (c)
5 * Copyright (c) 2012-2013 Google (c)
6 * Copyright (c) 2013-2014 Red Hat Inc.
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.
15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 #include <linux/device.h>
18 #include <linux/input.h>
19 #include <linux/usb.h>
20 #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>
26 #include <linux/workqueue.h>
27 #include <linux/atomic.h>
28 #include <linux/fixp-arith.h>
29 #include <asm/unaligned.h>
30 #include "usbhid/usbhid.h"
33 MODULE_LICENSE("GPL");
34 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
35 MODULE_AUTHOR("Nestor Lopez Casado <nlopezcasad@logitech.com>");
37 static bool disable_raw_mode
;
38 module_param(disable_raw_mode
, bool, 0644);
39 MODULE_PARM_DESC(disable_raw_mode
,
40 "Disable Raw mode reporting for touchpads and keep firmware gestures.");
42 static bool disable_tap_to_click
;
43 module_param(disable_tap_to_click
, bool, 0644);
44 MODULE_PARM_DESC(disable_tap_to_click
,
45 "Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
47 #define REPORT_ID_HIDPP_SHORT 0x10
48 #define REPORT_ID_HIDPP_LONG 0x11
49 #define REPORT_ID_HIDPP_VERY_LONG 0x12
51 #define HIDPP_REPORT_SHORT_LENGTH 7
52 #define HIDPP_REPORT_LONG_LENGTH 20
53 #define HIDPP_REPORT_VERY_LONG_LENGTH 64
55 #define HIDPP_QUIRK_CLASS_WTP BIT(0)
56 #define HIDPP_QUIRK_CLASS_M560 BIT(1)
57 #define HIDPP_QUIRK_CLASS_K400 BIT(2)
58 #define HIDPP_QUIRK_CLASS_G920 BIT(3)
59 #define HIDPP_QUIRK_CLASS_K750 BIT(4)
61 /* bits 2..20 are reserved for classes */
62 /* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */
63 #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22)
64 #define HIDPP_QUIRK_NO_HIDINPUT BIT(23)
65 #define HIDPP_QUIRK_FORCE_OUTPUT_REPORTS BIT(24)
66 #define HIDPP_QUIRK_UNIFYING BIT(25)
68 #define HIDPP_QUIRK_DELAYED_INIT HIDPP_QUIRK_NO_HIDINPUT
70 #define HIDPP_CAPABILITY_HIDPP10_BATTERY BIT(0)
71 #define HIDPP_CAPABILITY_HIDPP20_BATTERY BIT(1)
72 #define HIDPP_CAPABILITY_BATTERY_MILEAGE BIT(2)
73 #define HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS BIT(3)
76 * There are two hidpp protocols in use, the first version hidpp10 is known
77 * as register access protocol or RAP, the second version hidpp20 is known as
78 * feature access protocol or FAP
80 * Most older devices (including the Unifying usb receiver) use the RAP protocol
81 * where as most newer devices use the FAP protocol. Both protocols are
82 * compatible with the underlying transport, which could be usb, Unifiying, or
83 * bluetooth. The message lengths are defined by the hid vendor specific report
84 * descriptor for the HIDPP_SHORT report type (total message lenth 7 bytes) and
85 * the HIDPP_LONG report type (total message length 20 bytes)
87 * The RAP protocol uses both report types, whereas the FAP only uses HIDPP_LONG
88 * messages. The Unifying receiver itself responds to RAP messages (device index
89 * is 0xFF for the receiver), and all messages (short or long) with a device
90 * index between 1 and 6 are passed untouched to the corresponding paired
93 * The paired device can be RAP or FAP, it will receive the message untouched
94 * from the Unifiying receiver.
99 u8 funcindex_clientid
;
100 u8 params
[HIDPP_REPORT_VERY_LONG_LENGTH
- 4U];
106 u8 params
[HIDPP_REPORT_VERY_LONG_LENGTH
- 4U];
109 struct hidpp_report
{
115 u8 rawbytes
[sizeof(struct fap
)];
119 struct hidpp_battery
{
121 u8 solar_feature_index
;
122 struct power_supply_desc desc
;
123 struct power_supply
*ps
;
131 struct hidpp_device
{
132 struct hid_device
*hid_dev
;
133 struct mutex send_mutex
;
134 void *send_receive_buf
;
135 char *name
; /* will never be NULL and should not be freed */
136 wait_queue_head_t wait
;
137 bool answer_available
;
143 struct work_struct work
;
144 struct kfifo delayed_work_fifo
;
146 struct input_dev
*delayed_input
;
148 unsigned long quirks
;
149 unsigned long capabilities
;
151 struct hidpp_battery battery
;
154 /* HID++ 1.0 error codes */
155 #define HIDPP_ERROR 0x8f
156 #define HIDPP_ERROR_SUCCESS 0x00
157 #define HIDPP_ERROR_INVALID_SUBID 0x01
158 #define HIDPP_ERROR_INVALID_ADRESS 0x02
159 #define HIDPP_ERROR_INVALID_VALUE 0x03
160 #define HIDPP_ERROR_CONNECT_FAIL 0x04
161 #define HIDPP_ERROR_TOO_MANY_DEVICES 0x05
162 #define HIDPP_ERROR_ALREADY_EXISTS 0x06
163 #define HIDPP_ERROR_BUSY 0x07
164 #define HIDPP_ERROR_UNKNOWN_DEVICE 0x08
165 #define HIDPP_ERROR_RESOURCE_ERROR 0x09
166 #define HIDPP_ERROR_REQUEST_UNAVAILABLE 0x0a
167 #define HIDPP_ERROR_INVALID_PARAM_VALUE 0x0b
168 #define HIDPP_ERROR_WRONG_PIN_CODE 0x0c
169 /* HID++ 2.0 error codes */
170 #define HIDPP20_ERROR 0xff
172 static void hidpp_connect_event(struct hidpp_device
*hidpp_dev
);
174 static int __hidpp_send_report(struct hid_device
*hdev
,
175 struct hidpp_report
*hidpp_report
)
177 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
178 int fields_count
, ret
;
180 hidpp
= hid_get_drvdata(hdev
);
182 switch (hidpp_report
->report_id
) {
183 case REPORT_ID_HIDPP_SHORT
:
184 fields_count
= HIDPP_REPORT_SHORT_LENGTH
;
186 case REPORT_ID_HIDPP_LONG
:
187 fields_count
= HIDPP_REPORT_LONG_LENGTH
;
189 case REPORT_ID_HIDPP_VERY_LONG
:
190 fields_count
= HIDPP_REPORT_VERY_LONG_LENGTH
;
197 * set the device_index as the receiver, it will be overwritten by
198 * hid_hw_request if needed
200 hidpp_report
->device_index
= 0xff;
202 if (hidpp
->quirks
& HIDPP_QUIRK_FORCE_OUTPUT_REPORTS
) {
203 ret
= hid_hw_output_report(hdev
, (u8
*)hidpp_report
, fields_count
);
205 ret
= hid_hw_raw_request(hdev
, hidpp_report
->report_id
,
206 (u8
*)hidpp_report
, fields_count
, HID_OUTPUT_REPORT
,
210 return ret
== fields_count
? 0 : -1;
214 * hidpp_send_message_sync() returns 0 in case of success, and something else
215 * in case of a failure.
216 * - If ' something else' is positive, that means that an error has been raised
217 * by the protocol itself.
218 * - If ' something else' is negative, that means that we had a classic error
219 * (-ENOMEM, -EPIPE, etc...)
221 static int hidpp_send_message_sync(struct hidpp_device
*hidpp
,
222 struct hidpp_report
*message
,
223 struct hidpp_report
*response
)
227 mutex_lock(&hidpp
->send_mutex
);
229 hidpp
->send_receive_buf
= response
;
230 hidpp
->answer_available
= false;
233 * So that we can later validate the answer when it arrives
236 *response
= *message
;
238 ret
= __hidpp_send_report(hidpp
->hid_dev
, message
);
241 dbg_hid("__hidpp_send_report returned err: %d\n", ret
);
242 memset(response
, 0, sizeof(struct hidpp_report
));
246 if (!wait_event_timeout(hidpp
->wait
, hidpp
->answer_available
,
248 dbg_hid("%s:timeout waiting for response\n", __func__
);
249 memset(response
, 0, sizeof(struct hidpp_report
));
253 if (response
->report_id
== REPORT_ID_HIDPP_SHORT
&&
254 response
->rap
.sub_id
== HIDPP_ERROR
) {
255 ret
= response
->rap
.params
[1];
256 dbg_hid("%s:got hidpp error %02X\n", __func__
, ret
);
260 if ((response
->report_id
== REPORT_ID_HIDPP_LONG
||
261 response
->report_id
== REPORT_ID_HIDPP_VERY_LONG
) &&
262 response
->fap
.feature_index
== HIDPP20_ERROR
) {
263 ret
= response
->fap
.params
[1];
264 dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__
, ret
);
269 mutex_unlock(&hidpp
->send_mutex
);
274 static int hidpp_send_fap_command_sync(struct hidpp_device
*hidpp
,
275 u8 feat_index
, u8 funcindex_clientid
, u8
*params
, int param_count
,
276 struct hidpp_report
*response
)
278 struct hidpp_report
*message
;
281 if (param_count
> sizeof(message
->fap
.params
))
284 message
= kzalloc(sizeof(struct hidpp_report
), GFP_KERNEL
);
288 if (param_count
> (HIDPP_REPORT_LONG_LENGTH
- 4))
289 message
->report_id
= REPORT_ID_HIDPP_VERY_LONG
;
291 message
->report_id
= REPORT_ID_HIDPP_LONG
;
292 message
->fap
.feature_index
= feat_index
;
293 message
->fap
.funcindex_clientid
= funcindex_clientid
;
294 memcpy(&message
->fap
.params
, params
, param_count
);
296 ret
= hidpp_send_message_sync(hidpp
, message
, response
);
301 static int hidpp_send_rap_command_sync(struct hidpp_device
*hidpp_dev
,
302 u8 report_id
, u8 sub_id
, u8 reg_address
, u8
*params
, int param_count
,
303 struct hidpp_report
*response
)
305 struct hidpp_report
*message
;
309 case REPORT_ID_HIDPP_SHORT
:
310 max_count
= HIDPP_REPORT_SHORT_LENGTH
- 4;
312 case REPORT_ID_HIDPP_LONG
:
313 max_count
= HIDPP_REPORT_LONG_LENGTH
- 4;
315 case REPORT_ID_HIDPP_VERY_LONG
:
316 max_count
= HIDPP_REPORT_VERY_LONG_LENGTH
- 4;
322 if (param_count
> max_count
)
325 message
= kzalloc(sizeof(struct hidpp_report
), GFP_KERNEL
);
328 message
->report_id
= report_id
;
329 message
->rap
.sub_id
= sub_id
;
330 message
->rap
.reg_address
= reg_address
;
331 memcpy(&message
->rap
.params
, params
, param_count
);
333 ret
= hidpp_send_message_sync(hidpp_dev
, message
, response
);
338 static void delayed_work_cb(struct work_struct
*work
)
340 struct hidpp_device
*hidpp
= container_of(work
, struct hidpp_device
,
342 hidpp_connect_event(hidpp
);
345 static inline bool hidpp_match_answer(struct hidpp_report
*question
,
346 struct hidpp_report
*answer
)
348 return (answer
->fap
.feature_index
== question
->fap
.feature_index
) &&
349 (answer
->fap
.funcindex_clientid
== question
->fap
.funcindex_clientid
);
352 static inline bool hidpp_match_error(struct hidpp_report
*question
,
353 struct hidpp_report
*answer
)
355 return ((answer
->rap
.sub_id
== HIDPP_ERROR
) ||
356 (answer
->fap
.feature_index
== HIDPP20_ERROR
)) &&
357 (answer
->fap
.funcindex_clientid
== question
->fap
.feature_index
) &&
358 (answer
->fap
.params
[0] == question
->fap
.funcindex_clientid
);
361 static inline bool hidpp_report_is_connect_event(struct hidpp_report
*report
)
363 return (report
->report_id
== REPORT_ID_HIDPP_SHORT
) &&
364 (report
->rap
.sub_id
== 0x41);
368 * hidpp_prefix_name() prefixes the current given name with "Logitech ".
370 static void hidpp_prefix_name(char **name
, int name_length
)
372 #define PREFIX_LENGTH 9 /* "Logitech " */
377 if (name_length
> PREFIX_LENGTH
&&
378 strncmp(*name
, "Logitech ", PREFIX_LENGTH
) == 0)
379 /* The prefix has is already in the name */
382 new_length
= PREFIX_LENGTH
+ name_length
;
383 new_name
= kzalloc(new_length
, GFP_KERNEL
);
387 snprintf(new_name
, new_length
, "Logitech %s", *name
);
394 /* -------------------------------------------------------------------------- */
395 /* HIDP++ 1.0 commands */
396 /* -------------------------------------------------------------------------- */
398 #define HIDPP_SET_REGISTER 0x80
399 #define HIDPP_GET_REGISTER 0x81
400 #define HIDPP_SET_LONG_REGISTER 0x82
401 #define HIDPP_GET_LONG_REGISTER 0x83
403 #define HIDPP_REG_PAIRING_INFORMATION 0xB5
404 #define HIDPP_EXTENDED_PAIRING 0x30
405 #define HIDPP_DEVICE_NAME 0x40
407 static char *hidpp_unifying_get_name(struct hidpp_device
*hidpp_dev
)
409 struct hidpp_report response
;
411 u8 params
[1] = { HIDPP_DEVICE_NAME
};
415 ret
= hidpp_send_rap_command_sync(hidpp_dev
,
416 REPORT_ID_HIDPP_SHORT
,
417 HIDPP_GET_LONG_REGISTER
,
418 HIDPP_REG_PAIRING_INFORMATION
,
419 params
, 1, &response
);
423 len
= response
.rap
.params
[1];
425 if (2 + len
> sizeof(response
.rap
.params
))
428 name
= kzalloc(len
+ 1, GFP_KERNEL
);
432 memcpy(name
, &response
.rap
.params
[2], len
);
434 /* include the terminating '\0' */
435 hidpp_prefix_name(&name
, len
+ 1);
440 static int hidpp_unifying_get_serial(struct hidpp_device
*hidpp
, u32
*serial
)
442 struct hidpp_report response
;
444 u8 params
[1] = { HIDPP_EXTENDED_PAIRING
};
446 ret
= hidpp_send_rap_command_sync(hidpp
,
447 REPORT_ID_HIDPP_SHORT
,
448 HIDPP_GET_LONG_REGISTER
,
449 HIDPP_REG_PAIRING_INFORMATION
,
450 params
, 1, &response
);
455 * We don't care about LE or BE, we will output it as a string
456 * with %4phD, so we need to keep the order.
458 *serial
= *((u32
*)&response
.rap
.params
[1]);
462 static int hidpp_unifying_init(struct hidpp_device
*hidpp
)
464 struct hid_device
*hdev
= hidpp
->hid_dev
;
469 ret
= hidpp_unifying_get_serial(hidpp
, &serial
);
473 snprintf(hdev
->uniq
, sizeof(hdev
->uniq
), "%04x-%4phD",
474 hdev
->product
, &serial
);
475 dbg_hid("HID++ Unifying: Got serial: %s\n", hdev
->uniq
);
477 name
= hidpp_unifying_get_name(hidpp
);
481 snprintf(hdev
->name
, sizeof(hdev
->name
), "%s", name
);
482 dbg_hid("HID++ Unifying: Got name: %s\n", name
);
488 /* -------------------------------------------------------------------------- */
490 /* -------------------------------------------------------------------------- */
492 #define HIDPP_PAGE_ROOT 0x0000
493 #define HIDPP_PAGE_ROOT_IDX 0x00
495 #define CMD_ROOT_GET_FEATURE 0x01
496 #define CMD_ROOT_GET_PROTOCOL_VERSION 0x11
498 static int hidpp_root_get_feature(struct hidpp_device
*hidpp
, u16 feature
,
499 u8
*feature_index
, u8
*feature_type
)
501 struct hidpp_report response
;
503 u8 params
[2] = { feature
>> 8, feature
& 0x00FF };
505 ret
= hidpp_send_fap_command_sync(hidpp
,
507 CMD_ROOT_GET_FEATURE
,
508 params
, 2, &response
);
512 if (response
.fap
.params
[0] == 0)
515 *feature_index
= response
.fap
.params
[0];
516 *feature_type
= response
.fap
.params
[1];
521 static int hidpp_root_get_protocol_version(struct hidpp_device
*hidpp
)
523 struct hidpp_report response
;
526 ret
= hidpp_send_fap_command_sync(hidpp
,
528 CMD_ROOT_GET_PROTOCOL_VERSION
,
531 if (ret
== HIDPP_ERROR_INVALID_SUBID
) {
532 hidpp
->protocol_major
= 1;
533 hidpp
->protocol_minor
= 0;
537 /* the device might not be connected */
538 if (ret
== HIDPP_ERROR_RESOURCE_ERROR
)
542 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
549 hidpp
->protocol_major
= response
.fap
.params
[0];
550 hidpp
->protocol_minor
= response
.fap
.params
[1];
555 static bool hidpp_is_connected(struct hidpp_device
*hidpp
)
559 ret
= hidpp_root_get_protocol_version(hidpp
);
561 hid_dbg(hidpp
->hid_dev
, "HID++ %u.%u device connected.\n",
562 hidpp
->protocol_major
, hidpp
->protocol_minor
);
566 /* -------------------------------------------------------------------------- */
567 /* 0x0005: GetDeviceNameType */
568 /* -------------------------------------------------------------------------- */
570 #define HIDPP_PAGE_GET_DEVICE_NAME_TYPE 0x0005
572 #define CMD_GET_DEVICE_NAME_TYPE_GET_COUNT 0x01
573 #define CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME 0x11
574 #define CMD_GET_DEVICE_NAME_TYPE_GET_TYPE 0x21
576 static int hidpp_devicenametype_get_count(struct hidpp_device
*hidpp
,
577 u8 feature_index
, u8
*nameLength
)
579 struct hidpp_report response
;
582 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
583 CMD_GET_DEVICE_NAME_TYPE_GET_COUNT
, NULL
, 0, &response
);
586 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
593 *nameLength
= response
.fap
.params
[0];
598 static int hidpp_devicenametype_get_device_name(struct hidpp_device
*hidpp
,
599 u8 feature_index
, u8 char_index
, char *device_name
, int len_buf
)
601 struct hidpp_report response
;
605 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
606 CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME
, &char_index
, 1,
610 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
617 switch (response
.report_id
) {
618 case REPORT_ID_HIDPP_VERY_LONG
:
619 count
= HIDPP_REPORT_VERY_LONG_LENGTH
- 4;
621 case REPORT_ID_HIDPP_LONG
:
622 count
= HIDPP_REPORT_LONG_LENGTH
- 4;
624 case REPORT_ID_HIDPP_SHORT
:
625 count
= HIDPP_REPORT_SHORT_LENGTH
- 4;
634 for (i
= 0; i
< count
; i
++)
635 device_name
[i
] = response
.fap
.params
[i
];
640 static char *hidpp_get_device_name(struct hidpp_device
*hidpp
)
649 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_GET_DEVICE_NAME_TYPE
,
650 &feature_index
, &feature_type
);
654 ret
= hidpp_devicenametype_get_count(hidpp
, feature_index
,
659 name
= kzalloc(__name_length
+ 1, GFP_KERNEL
);
663 while (index
< __name_length
) {
664 ret
= hidpp_devicenametype_get_device_name(hidpp
,
665 feature_index
, index
, name
+ index
,
666 __name_length
- index
);
674 /* include the terminating '\0' */
675 hidpp_prefix_name(&name
, __name_length
+ 1);
680 /* -------------------------------------------------------------------------- */
681 /* 0x1000: Battery level status */
682 /* -------------------------------------------------------------------------- */
684 #define HIDPP_PAGE_BATTERY_LEVEL_STATUS 0x1000
686 #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS 0x00
687 #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY 0x10
689 #define EVENT_BATTERY_LEVEL_STATUS_BROADCAST 0x00
691 #define FLAG_BATTERY_LEVEL_DISABLE_OSD BIT(0)
692 #define FLAG_BATTERY_LEVEL_MILEAGE BIT(1)
693 #define FLAG_BATTERY_LEVEL_RECHARGEABLE BIT(2)
695 static int hidpp_map_battery_level(int capacity
)
698 return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL
;
699 else if (capacity
< 31)
700 return POWER_SUPPLY_CAPACITY_LEVEL_LOW
;
701 else if (capacity
< 81)
702 return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL
;
703 return POWER_SUPPLY_CAPACITY_LEVEL_FULL
;
706 static int hidpp20_batterylevel_map_status_capacity(u8 data
[3], int *capacity
,
713 *next_capacity
= data
[1];
714 *level
= POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN
;
716 /* When discharging, we can rely on the device reported capacity.
717 * For all other states the device reports 0 (unknown).
720 case 0: /* discharging (in use) */
721 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
722 *level
= hidpp_map_battery_level(*capacity
);
724 case 1: /* recharging */
725 status
= POWER_SUPPLY_STATUS_CHARGING
;
727 case 2: /* charge in final stage */
728 status
= POWER_SUPPLY_STATUS_CHARGING
;
730 case 3: /* charge complete */
731 status
= POWER_SUPPLY_STATUS_FULL
;
732 *level
= POWER_SUPPLY_CAPACITY_LEVEL_FULL
;
735 case 4: /* recharging below optimal speed */
736 status
= POWER_SUPPLY_STATUS_CHARGING
;
738 /* 5 = invalid battery type
740 7 = other charging error */
742 status
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
749 static int hidpp20_batterylevel_get_battery_capacity(struct hidpp_device
*hidpp
,
756 struct hidpp_report response
;
758 u8
*params
= (u8
*)response
.fap
.params
;
760 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
761 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS
,
764 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
771 *status
= hidpp20_batterylevel_map_status_capacity(params
, capacity
,
778 static int hidpp20_batterylevel_get_battery_info(struct hidpp_device
*hidpp
,
781 struct hidpp_report response
;
783 u8
*params
= (u8
*)response
.fap
.params
;
784 unsigned int level_count
, flags
;
786 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
787 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY
,
790 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
797 level_count
= params
[0];
800 if (level_count
< 10 || !(flags
& FLAG_BATTERY_LEVEL_MILEAGE
))
801 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS
;
803 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_MILEAGE
;
808 static int hidpp20_query_battery_info(struct hidpp_device
*hidpp
)
812 int status
, capacity
, next_capacity
, level
;
814 if (hidpp
->battery
.feature_index
== 0xff) {
815 ret
= hidpp_root_get_feature(hidpp
,
816 HIDPP_PAGE_BATTERY_LEVEL_STATUS
,
817 &hidpp
->battery
.feature_index
,
823 ret
= hidpp20_batterylevel_get_battery_capacity(hidpp
,
824 hidpp
->battery
.feature_index
,
826 &next_capacity
, &level
);
830 ret
= hidpp20_batterylevel_get_battery_info(hidpp
,
831 hidpp
->battery
.feature_index
);
835 hidpp
->battery
.status
= status
;
836 hidpp
->battery
.capacity
= capacity
;
837 hidpp
->battery
.level
= level
;
838 /* the capacity is only available when discharging or full */
839 hidpp
->battery
.online
= status
== POWER_SUPPLY_STATUS_DISCHARGING
||
840 status
== POWER_SUPPLY_STATUS_FULL
;
845 static int hidpp20_battery_event(struct hidpp_device
*hidpp
,
848 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
849 int status
, capacity
, next_capacity
, level
;
852 if (report
->fap
.feature_index
!= hidpp
->battery
.feature_index
||
853 report
->fap
.funcindex_clientid
!= EVENT_BATTERY_LEVEL_STATUS_BROADCAST
)
856 status
= hidpp20_batterylevel_map_status_capacity(report
->fap
.params
,
861 /* the capacity is only available when discharging or full */
862 hidpp
->battery
.online
= status
== POWER_SUPPLY_STATUS_DISCHARGING
||
863 status
== POWER_SUPPLY_STATUS_FULL
;
865 changed
= capacity
!= hidpp
->battery
.capacity
||
866 level
!= hidpp
->battery
.level
||
867 status
!= hidpp
->battery
.status
;
870 hidpp
->battery
.level
= level
;
871 hidpp
->battery
.capacity
= capacity
;
872 hidpp
->battery
.status
= status
;
873 if (hidpp
->battery
.ps
)
874 power_supply_changed(hidpp
->battery
.ps
);
880 static enum power_supply_property hidpp_battery_props
[] = {
881 POWER_SUPPLY_PROP_ONLINE
,
882 POWER_SUPPLY_PROP_STATUS
,
883 POWER_SUPPLY_PROP_SCOPE
,
884 POWER_SUPPLY_PROP_MODEL_NAME
,
885 POWER_SUPPLY_PROP_MANUFACTURER
,
886 POWER_SUPPLY_PROP_SERIAL_NUMBER
,
887 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY, */
888 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY_LEVEL, */
891 static int hidpp_battery_get_property(struct power_supply
*psy
,
892 enum power_supply_property psp
,
893 union power_supply_propval
*val
)
895 struct hidpp_device
*hidpp
= power_supply_get_drvdata(psy
);
899 case POWER_SUPPLY_PROP_STATUS
:
900 val
->intval
= hidpp
->battery
.status
;
902 case POWER_SUPPLY_PROP_CAPACITY
:
903 val
->intval
= hidpp
->battery
.capacity
;
905 case POWER_SUPPLY_PROP_CAPACITY_LEVEL
:
906 val
->intval
= hidpp
->battery
.level
;
908 case POWER_SUPPLY_PROP_SCOPE
:
909 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
911 case POWER_SUPPLY_PROP_ONLINE
:
912 val
->intval
= hidpp
->battery
.online
;
914 case POWER_SUPPLY_PROP_MODEL_NAME
:
915 if (!strncmp(hidpp
->name
, "Logitech ", 9))
916 val
->strval
= hidpp
->name
+ 9;
918 val
->strval
= hidpp
->name
;
920 case POWER_SUPPLY_PROP_MANUFACTURER
:
921 val
->strval
= "Logitech";
923 case POWER_SUPPLY_PROP_SERIAL_NUMBER
:
924 val
->strval
= hidpp
->hid_dev
->uniq
;
934 /* -------------------------------------------------------------------------- */
935 /* 0x4301: Solar Keyboard */
936 /* -------------------------------------------------------------------------- */
938 #define HIDPP_PAGE_SOLAR_KEYBOARD 0x4301
940 #define CMD_SOLAR_SET_LIGHT_MEASURE 0x00
942 #define EVENT_SOLAR_BATTERY_BROADCAST 0x00
943 #define EVENT_SOLAR_BATTERY_LIGHT_MEASURE 0x10
944 #define EVENT_SOLAR_CHECK_LIGHT_BUTTON 0x20
946 static int hidpp_solar_request_battery_event(struct hidpp_device
*hidpp
)
948 struct hidpp_report response
;
949 u8 params
[2] = { 1, 1 };
953 if (hidpp
->battery
.feature_index
== 0xff) {
954 ret
= hidpp_root_get_feature(hidpp
,
955 HIDPP_PAGE_SOLAR_KEYBOARD
,
956 &hidpp
->battery
.solar_feature_index
,
962 ret
= hidpp_send_fap_command_sync(hidpp
,
963 hidpp
->battery
.solar_feature_index
,
964 CMD_SOLAR_SET_LIGHT_MEASURE
,
965 params
, 2, &response
);
967 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
974 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_MILEAGE
;
979 static int hidpp_solar_battery_event(struct hidpp_device
*hidpp
,
982 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
983 int capacity
, lux
, status
;
986 function
= report
->fap
.funcindex_clientid
;
989 if (report
->fap
.feature_index
!= hidpp
->battery
.solar_feature_index
||
990 !(function
== EVENT_SOLAR_BATTERY_BROADCAST
||
991 function
== EVENT_SOLAR_BATTERY_LIGHT_MEASURE
||
992 function
== EVENT_SOLAR_CHECK_LIGHT_BUTTON
))
995 capacity
= report
->fap
.params
[0];
998 case EVENT_SOLAR_BATTERY_LIGHT_MEASURE
:
999 lux
= (report
->fap
.params
[1] << 8) | report
->fap
.params
[2];
1001 status
= POWER_SUPPLY_STATUS_CHARGING
;
1003 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
1005 case EVENT_SOLAR_CHECK_LIGHT_BUTTON
:
1007 if (capacity
< hidpp
->battery
.capacity
)
1008 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
1010 status
= POWER_SUPPLY_STATUS_CHARGING
;
1014 if (capacity
== 100)
1015 status
= POWER_SUPPLY_STATUS_FULL
;
1017 hidpp
->battery
.online
= true;
1018 if (capacity
!= hidpp
->battery
.capacity
||
1019 status
!= hidpp
->battery
.status
) {
1020 hidpp
->battery
.capacity
= capacity
;
1021 hidpp
->battery
.status
= status
;
1022 if (hidpp
->battery
.ps
)
1023 power_supply_changed(hidpp
->battery
.ps
);
1029 /* -------------------------------------------------------------------------- */
1030 /* 0x6010: Touchpad FW items */
1031 /* -------------------------------------------------------------------------- */
1033 #define HIDPP_PAGE_TOUCHPAD_FW_ITEMS 0x6010
1035 #define CMD_TOUCHPAD_FW_ITEMS_SET 0x10
1037 struct hidpp_touchpad_fw_items
{
1039 uint8_t desired_state
;
1045 * send a set state command to the device by reading the current items->state
1046 * field. items is then filled with the current state.
1048 static int hidpp_touchpad_fw_items_set(struct hidpp_device
*hidpp
,
1050 struct hidpp_touchpad_fw_items
*items
)
1052 struct hidpp_report response
;
1054 u8
*params
= (u8
*)response
.fap
.params
;
1056 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1057 CMD_TOUCHPAD_FW_ITEMS_SET
, &items
->state
, 1, &response
);
1060 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1067 items
->presence
= params
[0];
1068 items
->desired_state
= params
[1];
1069 items
->state
= params
[2];
1070 items
->persistent
= params
[3];
1075 /* -------------------------------------------------------------------------- */
1076 /* 0x6100: TouchPadRawXY */
1077 /* -------------------------------------------------------------------------- */
1079 #define HIDPP_PAGE_TOUCHPAD_RAW_XY 0x6100
1081 #define CMD_TOUCHPAD_GET_RAW_INFO 0x01
1082 #define CMD_TOUCHPAD_SET_RAW_REPORT_STATE 0x21
1084 #define EVENT_TOUCHPAD_RAW_XY 0x00
1086 #define TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT 0x01
1087 #define TOUCHPAD_RAW_XY_ORIGIN_UPPER_LEFT 0x03
1089 struct hidpp_touchpad_raw_info
{
1100 struct hidpp_touchpad_raw_xy_finger
{
1110 struct hidpp_touchpad_raw_xy
{
1112 struct hidpp_touchpad_raw_xy_finger fingers
[2];
1119 static int hidpp_touchpad_get_raw_info(struct hidpp_device
*hidpp
,
1120 u8 feature_index
, struct hidpp_touchpad_raw_info
*raw_info
)
1122 struct hidpp_report response
;
1124 u8
*params
= (u8
*)response
.fap
.params
;
1126 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1127 CMD_TOUCHPAD_GET_RAW_INFO
, NULL
, 0, &response
);
1130 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1137 raw_info
->x_size
= get_unaligned_be16(¶ms
[0]);
1138 raw_info
->y_size
= get_unaligned_be16(¶ms
[2]);
1139 raw_info
->z_range
= params
[4];
1140 raw_info
->area_range
= params
[5];
1141 raw_info
->maxcontacts
= params
[7];
1142 raw_info
->origin
= params
[8];
1143 /* res is given in unit per inch */
1144 raw_info
->res
= get_unaligned_be16(¶ms
[13]) * 2 / 51;
1149 static int hidpp_touchpad_set_raw_report_state(struct hidpp_device
*hidpp_dev
,
1150 u8 feature_index
, bool send_raw_reports
,
1151 bool sensor_enhanced_settings
)
1153 struct hidpp_report response
;
1157 * bit 0 - enable raw
1158 * bit 1 - 16bit Z, no area
1159 * bit 2 - enhanced sensitivity
1160 * bit 3 - width, height (4 bits each) instead of area
1161 * bit 4 - send raw + gestures (degrades smoothness)
1162 * remaining bits - reserved
1164 u8 params
= send_raw_reports
| (sensor_enhanced_settings
<< 2);
1166 return hidpp_send_fap_command_sync(hidpp_dev
, feature_index
,
1167 CMD_TOUCHPAD_SET_RAW_REPORT_STATE
, ¶ms
, 1, &response
);
1170 static void hidpp_touchpad_touch_event(u8
*data
,
1171 struct hidpp_touchpad_raw_xy_finger
*finger
)
1173 u8 x_m
= data
[0] << 2;
1174 u8 y_m
= data
[2] << 2;
1176 finger
->x
= x_m
<< 6 | data
[1];
1177 finger
->y
= y_m
<< 6 | data
[3];
1179 finger
->contact_type
= data
[0] >> 6;
1180 finger
->contact_status
= data
[2] >> 6;
1182 finger
->z
= data
[4];
1183 finger
->area
= data
[5];
1184 finger
->finger_id
= data
[6] >> 4;
1187 static void hidpp_touchpad_raw_xy_event(struct hidpp_device
*hidpp_dev
,
1188 u8
*data
, struct hidpp_touchpad_raw_xy
*raw_xy
)
1190 memset(raw_xy
, 0, sizeof(struct hidpp_touchpad_raw_xy
));
1191 raw_xy
->end_of_frame
= data
[8] & 0x01;
1192 raw_xy
->spurious_flag
= (data
[8] >> 1) & 0x01;
1193 raw_xy
->finger_count
= data
[15] & 0x0f;
1194 raw_xy
->button
= (data
[8] >> 2) & 0x01;
1196 if (raw_xy
->finger_count
) {
1197 hidpp_touchpad_touch_event(&data
[2], &raw_xy
->fingers
[0]);
1198 hidpp_touchpad_touch_event(&data
[9], &raw_xy
->fingers
[1]);
1202 /* -------------------------------------------------------------------------- */
1203 /* 0x8123: Force feedback support */
1204 /* -------------------------------------------------------------------------- */
1206 #define HIDPP_FF_GET_INFO 0x01
1207 #define HIDPP_FF_RESET_ALL 0x11
1208 #define HIDPP_FF_DOWNLOAD_EFFECT 0x21
1209 #define HIDPP_FF_SET_EFFECT_STATE 0x31
1210 #define HIDPP_FF_DESTROY_EFFECT 0x41
1211 #define HIDPP_FF_GET_APERTURE 0x51
1212 #define HIDPP_FF_SET_APERTURE 0x61
1213 #define HIDPP_FF_GET_GLOBAL_GAINS 0x71
1214 #define HIDPP_FF_SET_GLOBAL_GAINS 0x81
1216 #define HIDPP_FF_EFFECT_STATE_GET 0x00
1217 #define HIDPP_FF_EFFECT_STATE_STOP 0x01
1218 #define HIDPP_FF_EFFECT_STATE_PLAY 0x02
1219 #define HIDPP_FF_EFFECT_STATE_PAUSE 0x03
1221 #define HIDPP_FF_EFFECT_CONSTANT 0x00
1222 #define HIDPP_FF_EFFECT_PERIODIC_SINE 0x01
1223 #define HIDPP_FF_EFFECT_PERIODIC_SQUARE 0x02
1224 #define HIDPP_FF_EFFECT_PERIODIC_TRIANGLE 0x03
1225 #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP 0x04
1226 #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN 0x05
1227 #define HIDPP_FF_EFFECT_SPRING 0x06
1228 #define HIDPP_FF_EFFECT_DAMPER 0x07
1229 #define HIDPP_FF_EFFECT_FRICTION 0x08
1230 #define HIDPP_FF_EFFECT_INERTIA 0x09
1231 #define HIDPP_FF_EFFECT_RAMP 0x0A
1233 #define HIDPP_FF_EFFECT_AUTOSTART 0x80
1235 #define HIDPP_FF_EFFECTID_NONE -1
1236 #define HIDPP_FF_EFFECTID_AUTOCENTER -2
1238 #define HIDPP_FF_MAX_PARAMS 20
1239 #define HIDPP_FF_RESERVED_SLOTS 1
1241 struct hidpp_ff_private_data
{
1242 struct hidpp_device
*hidpp
;
1250 struct workqueue_struct
*wq
;
1251 atomic_t workqueue_size
;
1254 struct hidpp_ff_work_data
{
1255 struct work_struct work
;
1256 struct hidpp_ff_private_data
*data
;
1259 u8 params
[HIDPP_FF_MAX_PARAMS
];
1263 static const signed short hiddpp_ff_effects
[] = {
1278 static const signed short hiddpp_ff_effects_v2
[] = {
1285 static const u8 HIDPP_FF_CONDITION_CMDS
[] = {
1286 HIDPP_FF_EFFECT_SPRING
,
1287 HIDPP_FF_EFFECT_FRICTION
,
1288 HIDPP_FF_EFFECT_DAMPER
,
1289 HIDPP_FF_EFFECT_INERTIA
1292 static const char *HIDPP_FF_CONDITION_NAMES
[] = {
1300 static u8
hidpp_ff_find_effect(struct hidpp_ff_private_data
*data
, int effect_id
)
1304 for (i
= 0; i
< data
->num_effects
; i
++)
1305 if (data
->effect_ids
[i
] == effect_id
)
1311 static void hidpp_ff_work_handler(struct work_struct
*w
)
1313 struct hidpp_ff_work_data
*wd
= container_of(w
, struct hidpp_ff_work_data
, work
);
1314 struct hidpp_ff_private_data
*data
= wd
->data
;
1315 struct hidpp_report response
;
1319 /* add slot number if needed */
1320 switch (wd
->effect_id
) {
1321 case HIDPP_FF_EFFECTID_AUTOCENTER
:
1322 wd
->params
[0] = data
->slot_autocenter
;
1324 case HIDPP_FF_EFFECTID_NONE
:
1325 /* leave slot as zero */
1328 /* find current slot for effect */
1329 wd
->params
[0] = hidpp_ff_find_effect(data
, wd
->effect_id
);
1333 /* send command and wait for reply */
1334 ret
= hidpp_send_fap_command_sync(data
->hidpp
, data
->feature_index
,
1335 wd
->command
, wd
->params
, wd
->size
, &response
);
1338 hid_err(data
->hidpp
->hid_dev
, "Failed to send command to device!\n");
1342 /* parse return data */
1343 switch (wd
->command
) {
1344 case HIDPP_FF_DOWNLOAD_EFFECT
:
1345 slot
= response
.fap
.params
[0];
1346 if (slot
> 0 && slot
<= data
->num_effects
) {
1347 if (wd
->effect_id
>= 0)
1348 /* regular effect uploaded */
1349 data
->effect_ids
[slot
-1] = wd
->effect_id
;
1350 else if (wd
->effect_id
>= HIDPP_FF_EFFECTID_AUTOCENTER
)
1351 /* autocenter spring uploaded */
1352 data
->slot_autocenter
= slot
;
1355 case HIDPP_FF_DESTROY_EFFECT
:
1356 if (wd
->effect_id
>= 0)
1357 /* regular effect destroyed */
1358 data
->effect_ids
[wd
->params
[0]-1] = -1;
1359 else if (wd
->effect_id
>= HIDPP_FF_EFFECTID_AUTOCENTER
)
1360 /* autocenter spring destoyed */
1361 data
->slot_autocenter
= 0;
1363 case HIDPP_FF_SET_GLOBAL_GAINS
:
1364 data
->gain
= (wd
->params
[0] << 8) + wd
->params
[1];
1366 case HIDPP_FF_SET_APERTURE
:
1367 data
->range
= (wd
->params
[0] << 8) + wd
->params
[1];
1370 /* no action needed */
1375 atomic_dec(&data
->workqueue_size
);
1379 static int hidpp_ff_queue_work(struct hidpp_ff_private_data
*data
, int effect_id
, u8 command
, u8
*params
, u8 size
)
1381 struct hidpp_ff_work_data
*wd
= kzalloc(sizeof(*wd
), GFP_KERNEL
);
1387 INIT_WORK(&wd
->work
, hidpp_ff_work_handler
);
1390 wd
->effect_id
= effect_id
;
1391 wd
->command
= command
;
1393 memcpy(wd
->params
, params
, size
);
1395 atomic_inc(&data
->workqueue_size
);
1396 queue_work(data
->wq
, &wd
->work
);
1398 /* warn about excessive queue size */
1399 s
= atomic_read(&data
->workqueue_size
);
1400 if (s
>= 20 && s
% 20 == 0)
1401 hid_warn(data
->hidpp
->hid_dev
, "Force feedback command queue contains %d commands, causing substantial delays!", s
);
1406 static int hidpp_ff_upload_effect(struct input_dev
*dev
, struct ff_effect
*effect
, struct ff_effect
*old
)
1408 struct hidpp_ff_private_data
*data
= dev
->ff
->private;
1413 /* set common parameters */
1414 params
[2] = effect
->replay
.length
>> 8;
1415 params
[3] = effect
->replay
.length
& 255;
1416 params
[4] = effect
->replay
.delay
>> 8;
1417 params
[5] = effect
->replay
.delay
& 255;
1419 switch (effect
->type
) {
1421 force
= (effect
->u
.constant
.level
* fixp_sin16((effect
->direction
* 360) >> 16)) >> 15;
1422 params
[1] = HIDPP_FF_EFFECT_CONSTANT
;
1423 params
[6] = force
>> 8;
1424 params
[7] = force
& 255;
1425 params
[8] = effect
->u
.constant
.envelope
.attack_level
>> 7;
1426 params
[9] = effect
->u
.constant
.envelope
.attack_length
>> 8;
1427 params
[10] = effect
->u
.constant
.envelope
.attack_length
& 255;
1428 params
[11] = effect
->u
.constant
.envelope
.fade_level
>> 7;
1429 params
[12] = effect
->u
.constant
.envelope
.fade_length
>> 8;
1430 params
[13] = effect
->u
.constant
.envelope
.fade_length
& 255;
1432 dbg_hid("Uploading constant force level=%d in dir %d = %d\n",
1433 effect
->u
.constant
.level
,
1434 effect
->direction
, force
);
1435 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1436 effect
->u
.constant
.envelope
.attack_level
,
1437 effect
->u
.constant
.envelope
.attack_length
,
1438 effect
->u
.constant
.envelope
.fade_level
,
1439 effect
->u
.constant
.envelope
.fade_length
);
1443 switch (effect
->u
.periodic
.waveform
) {
1445 params
[1] = HIDPP_FF_EFFECT_PERIODIC_SINE
;
1448 params
[1] = HIDPP_FF_EFFECT_PERIODIC_SQUARE
;
1451 params
[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP
;
1454 params
[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN
;
1457 params
[1] = HIDPP_FF_EFFECT_PERIODIC_TRIANGLE
;
1460 hid_err(data
->hidpp
->hid_dev
, "Unexpected periodic waveform type %i!\n", effect
->u
.periodic
.waveform
);
1463 force
= (effect
->u
.periodic
.magnitude
* fixp_sin16((effect
->direction
* 360) >> 16)) >> 15;
1464 params
[6] = effect
->u
.periodic
.magnitude
>> 8;
1465 params
[7] = effect
->u
.periodic
.magnitude
& 255;
1466 params
[8] = effect
->u
.periodic
.offset
>> 8;
1467 params
[9] = effect
->u
.periodic
.offset
& 255;
1468 params
[10] = effect
->u
.periodic
.period
>> 8;
1469 params
[11] = effect
->u
.periodic
.period
& 255;
1470 params
[12] = effect
->u
.periodic
.phase
>> 8;
1471 params
[13] = effect
->u
.periodic
.phase
& 255;
1472 params
[14] = effect
->u
.periodic
.envelope
.attack_level
>> 7;
1473 params
[15] = effect
->u
.periodic
.envelope
.attack_length
>> 8;
1474 params
[16] = effect
->u
.periodic
.envelope
.attack_length
& 255;
1475 params
[17] = effect
->u
.periodic
.envelope
.fade_level
>> 7;
1476 params
[18] = effect
->u
.periodic
.envelope
.fade_length
>> 8;
1477 params
[19] = effect
->u
.periodic
.envelope
.fade_length
& 255;
1479 dbg_hid("Uploading periodic force mag=%d/dir=%d, offset=%d, period=%d ms, phase=%d\n",
1480 effect
->u
.periodic
.magnitude
, effect
->direction
,
1481 effect
->u
.periodic
.offset
,
1482 effect
->u
.periodic
.period
,
1483 effect
->u
.periodic
.phase
);
1484 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1485 effect
->u
.periodic
.envelope
.attack_level
,
1486 effect
->u
.periodic
.envelope
.attack_length
,
1487 effect
->u
.periodic
.envelope
.fade_level
,
1488 effect
->u
.periodic
.envelope
.fade_length
);
1492 params
[1] = HIDPP_FF_EFFECT_RAMP
;
1493 force
= (effect
->u
.ramp
.start_level
* fixp_sin16((effect
->direction
* 360) >> 16)) >> 15;
1494 params
[6] = force
>> 8;
1495 params
[7] = force
& 255;
1496 force
= (effect
->u
.ramp
.end_level
* fixp_sin16((effect
->direction
* 360) >> 16)) >> 15;
1497 params
[8] = force
>> 8;
1498 params
[9] = force
& 255;
1499 params
[10] = effect
->u
.ramp
.envelope
.attack_level
>> 7;
1500 params
[11] = effect
->u
.ramp
.envelope
.attack_length
>> 8;
1501 params
[12] = effect
->u
.ramp
.envelope
.attack_length
& 255;
1502 params
[13] = effect
->u
.ramp
.envelope
.fade_level
>> 7;
1503 params
[14] = effect
->u
.ramp
.envelope
.fade_length
>> 8;
1504 params
[15] = effect
->u
.ramp
.envelope
.fade_length
& 255;
1506 dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n",
1507 effect
->u
.ramp
.start_level
,
1508 effect
->u
.ramp
.end_level
,
1509 effect
->direction
, force
);
1510 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1511 effect
->u
.ramp
.envelope
.attack_level
,
1512 effect
->u
.ramp
.envelope
.attack_length
,
1513 effect
->u
.ramp
.envelope
.fade_level
,
1514 effect
->u
.ramp
.envelope
.fade_length
);
1520 params
[1] = HIDPP_FF_CONDITION_CMDS
[effect
->type
- FF_SPRING
];
1521 params
[6] = effect
->u
.condition
[0].left_saturation
>> 9;
1522 params
[7] = (effect
->u
.condition
[0].left_saturation
>> 1) & 255;
1523 params
[8] = effect
->u
.condition
[0].left_coeff
>> 8;
1524 params
[9] = effect
->u
.condition
[0].left_coeff
& 255;
1525 params
[10] = effect
->u
.condition
[0].deadband
>> 9;
1526 params
[11] = (effect
->u
.condition
[0].deadband
>> 1) & 255;
1527 params
[12] = effect
->u
.condition
[0].center
>> 8;
1528 params
[13] = effect
->u
.condition
[0].center
& 255;
1529 params
[14] = effect
->u
.condition
[0].right_coeff
>> 8;
1530 params
[15] = effect
->u
.condition
[0].right_coeff
& 255;
1531 params
[16] = effect
->u
.condition
[0].right_saturation
>> 9;
1532 params
[17] = (effect
->u
.condition
[0].right_saturation
>> 1) & 255;
1534 dbg_hid("Uploading %s force left coeff=%d, left sat=%d, right coeff=%d, right sat=%d\n",
1535 HIDPP_FF_CONDITION_NAMES
[effect
->type
- FF_SPRING
],
1536 effect
->u
.condition
[0].left_coeff
,
1537 effect
->u
.condition
[0].left_saturation
,
1538 effect
->u
.condition
[0].right_coeff
,
1539 effect
->u
.condition
[0].right_saturation
);
1540 dbg_hid(" deadband=%d, center=%d\n",
1541 effect
->u
.condition
[0].deadband
,
1542 effect
->u
.condition
[0].center
);
1545 hid_err(data
->hidpp
->hid_dev
, "Unexpected force type %i!\n", effect
->type
);
1549 return hidpp_ff_queue_work(data
, effect
->id
, HIDPP_FF_DOWNLOAD_EFFECT
, params
, size
);
1552 static int hidpp_ff_playback(struct input_dev
*dev
, int effect_id
, int value
)
1554 struct hidpp_ff_private_data
*data
= dev
->ff
->private;
1557 params
[1] = value
? HIDPP_FF_EFFECT_STATE_PLAY
: HIDPP_FF_EFFECT_STATE_STOP
;
1559 dbg_hid("St%sing playback of effect %d.\n", value
?"art":"opp", effect_id
);
1561 return hidpp_ff_queue_work(data
, effect_id
, HIDPP_FF_SET_EFFECT_STATE
, params
, ARRAY_SIZE(params
));
1564 static int hidpp_ff_erase_effect(struct input_dev
*dev
, int effect_id
)
1566 struct hidpp_ff_private_data
*data
= dev
->ff
->private;
1569 dbg_hid("Erasing effect %d.\n", effect_id
);
1571 return hidpp_ff_queue_work(data
, effect_id
, HIDPP_FF_DESTROY_EFFECT
, &slot
, 1);
1574 static void hidpp_ff_set_autocenter(struct input_dev
*dev
, u16 magnitude
)
1576 struct hidpp_ff_private_data
*data
= dev
->ff
->private;
1579 dbg_hid("Setting autocenter to %d.\n", magnitude
);
1581 /* start a standard spring effect */
1582 params
[1] = HIDPP_FF_EFFECT_SPRING
| HIDPP_FF_EFFECT_AUTOSTART
;
1583 /* zero delay and duration */
1584 params
[2] = params
[3] = params
[4] = params
[5] = 0;
1585 /* set coeff to 25% of saturation */
1586 params
[8] = params
[14] = magnitude
>> 11;
1587 params
[9] = params
[15] = (magnitude
>> 3) & 255;
1588 params
[6] = params
[16] = magnitude
>> 9;
1589 params
[7] = params
[17] = (magnitude
>> 1) & 255;
1590 /* zero deadband and center */
1591 params
[10] = params
[11] = params
[12] = params
[13] = 0;
1593 hidpp_ff_queue_work(data
, HIDPP_FF_EFFECTID_AUTOCENTER
, HIDPP_FF_DOWNLOAD_EFFECT
, params
, ARRAY_SIZE(params
));
1596 static void hidpp_ff_set_gain(struct input_dev
*dev
, u16 gain
)
1598 struct hidpp_ff_private_data
*data
= dev
->ff
->private;
1601 dbg_hid("Setting gain to %d.\n", gain
);
1603 params
[0] = gain
>> 8;
1604 params
[1] = gain
& 255;
1605 params
[2] = 0; /* no boost */
1608 hidpp_ff_queue_work(data
, HIDPP_FF_EFFECTID_NONE
, HIDPP_FF_SET_GLOBAL_GAINS
, params
, ARRAY_SIZE(params
));
1611 static ssize_t
hidpp_ff_range_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1613 struct hid_device
*hid
= to_hid_device(dev
);
1614 struct hid_input
*hidinput
= list_entry(hid
->inputs
.next
, struct hid_input
, list
);
1615 struct input_dev
*idev
= hidinput
->input
;
1616 struct hidpp_ff_private_data
*data
= idev
->ff
->private;
1618 return scnprintf(buf
, PAGE_SIZE
, "%u\n", data
->range
);
1621 static ssize_t
hidpp_ff_range_store(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
1623 struct hid_device
*hid
= to_hid_device(dev
);
1624 struct hid_input
*hidinput
= list_entry(hid
->inputs
.next
, struct hid_input
, list
);
1625 struct input_dev
*idev
= hidinput
->input
;
1626 struct hidpp_ff_private_data
*data
= idev
->ff
->private;
1628 int range
= simple_strtoul(buf
, NULL
, 10);
1630 range
= clamp(range
, 180, 900);
1632 params
[0] = range
>> 8;
1633 params
[1] = range
& 0x00FF;
1635 hidpp_ff_queue_work(data
, -1, HIDPP_FF_SET_APERTURE
, params
, ARRAY_SIZE(params
));
1640 static DEVICE_ATTR(range
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
, hidpp_ff_range_show
, hidpp_ff_range_store
);
1642 static void hidpp_ff_destroy(struct ff_device
*ff
)
1644 struct hidpp_ff_private_data
*data
= ff
->private;
1646 kfree(data
->effect_ids
);
1649 static int hidpp_ff_init(struct hidpp_device
*hidpp
, u8 feature_index
)
1651 struct hid_device
*hid
= hidpp
->hid_dev
;
1652 struct hid_input
*hidinput
= list_entry(hid
->inputs
.next
, struct hid_input
, list
);
1653 struct input_dev
*dev
= hidinput
->input
;
1654 const struct usb_device_descriptor
*udesc
= &(hid_to_usb_dev(hid
)->descriptor
);
1655 const u16 bcdDevice
= le16_to_cpu(udesc
->bcdDevice
);
1656 struct ff_device
*ff
;
1657 struct hidpp_report response
;
1658 struct hidpp_ff_private_data
*data
;
1659 int error
, j
, num_slots
;
1663 hid_err(hid
, "Struct input_dev not set!\n");
1667 /* Get firmware release */
1668 version
= bcdDevice
& 255;
1670 /* Set supported force feedback capabilities */
1671 for (j
= 0; hiddpp_ff_effects
[j
] >= 0; j
++)
1672 set_bit(hiddpp_ff_effects
[j
], dev
->ffbit
);
1674 for (j
= 0; hiddpp_ff_effects_v2
[j
] >= 0; j
++)
1675 set_bit(hiddpp_ff_effects_v2
[j
], dev
->ffbit
);
1677 /* Read number of slots available in device */
1678 error
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1679 HIDPP_FF_GET_INFO
, NULL
, 0, &response
);
1683 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1688 num_slots
= response
.fap
.params
[0] - HIDPP_FF_RESERVED_SLOTS
;
1690 error
= input_ff_create(dev
, num_slots
);
1693 hid_err(dev
, "Failed to create FF device!\n");
1697 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1700 data
->effect_ids
= kcalloc(num_slots
, sizeof(int), GFP_KERNEL
);
1701 if (!data
->effect_ids
) {
1705 data
->hidpp
= hidpp
;
1706 data
->feature_index
= feature_index
;
1707 data
->version
= version
;
1708 data
->slot_autocenter
= 0;
1709 data
->num_effects
= num_slots
;
1710 for (j
= 0; j
< num_slots
; j
++)
1711 data
->effect_ids
[j
] = -1;
1716 ff
->upload
= hidpp_ff_upload_effect
;
1717 ff
->erase
= hidpp_ff_erase_effect
;
1718 ff
->playback
= hidpp_ff_playback
;
1719 ff
->set_gain
= hidpp_ff_set_gain
;
1720 ff
->set_autocenter
= hidpp_ff_set_autocenter
;
1721 ff
->destroy
= hidpp_ff_destroy
;
1724 /* reset all forces */
1725 error
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1726 HIDPP_FF_RESET_ALL
, NULL
, 0, &response
);
1728 /* Read current Range */
1729 error
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1730 HIDPP_FF_GET_APERTURE
, NULL
, 0, &response
);
1732 hid_warn(hidpp
->hid_dev
, "Failed to read range from device!\n");
1733 data
->range
= error
? 900 : get_unaligned_be16(&response
.fap
.params
[0]);
1735 /* Create sysfs interface */
1736 error
= device_create_file(&(hidpp
->hid_dev
->dev
), &dev_attr_range
);
1738 hid_warn(hidpp
->hid_dev
, "Unable to create sysfs interface for \"range\", errno %d!\n", error
);
1740 /* Read the current gain values */
1741 error
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1742 HIDPP_FF_GET_GLOBAL_GAINS
, NULL
, 0, &response
);
1744 hid_warn(hidpp
->hid_dev
, "Failed to read gain values from device!\n");
1745 data
->gain
= error
? 0xffff : get_unaligned_be16(&response
.fap
.params
[0]);
1746 /* ignore boost value at response.fap.params[2] */
1748 /* init the hardware command queue */
1749 data
->wq
= create_singlethread_workqueue("hidpp-ff-sendqueue");
1750 atomic_set(&data
->workqueue_size
, 0);
1752 /* initialize with zero autocenter to get wheel in usable state */
1753 hidpp_ff_set_autocenter(dev
, 0);
1755 hid_info(hid
, "Force feeback support loaded (firmware release %d).\n", version
);
1760 static int hidpp_ff_deinit(struct hid_device
*hid
)
1762 struct hid_input
*hidinput
= list_entry(hid
->inputs
.next
, struct hid_input
, list
);
1763 struct input_dev
*dev
= hidinput
->input
;
1764 struct hidpp_ff_private_data
*data
;
1767 hid_err(hid
, "Struct input_dev not found!\n");
1771 hid_info(hid
, "Unloading HID++ force feedback.\n");
1772 data
= dev
->ff
->private;
1774 hid_err(hid
, "Private data not found!\n");
1778 destroy_workqueue(data
->wq
);
1779 device_remove_file(&hid
->dev
, &dev_attr_range
);
1785 /* ************************************************************************** */
1787 /* Device Support */
1789 /* ************************************************************************** */
1791 /* -------------------------------------------------------------------------- */
1792 /* Touchpad HID++ devices */
1793 /* -------------------------------------------------------------------------- */
1795 #define WTP_MANUAL_RESOLUTION 39
1798 struct input_dev
*input
;
1801 u8 mt_feature_index
;
1802 u8 button_feature_index
;
1805 unsigned int resolution
;
1808 static int wtp_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
1809 struct hid_field
*field
, struct hid_usage
*usage
,
1810 unsigned long **bit
, int *max
)
1815 static void wtp_populate_input(struct hidpp_device
*hidpp
,
1816 struct input_dev
*input_dev
, bool origin_is_hid_core
)
1818 struct wtp_data
*wd
= hidpp
->private_data
;
1820 __set_bit(EV_ABS
, input_dev
->evbit
);
1821 __set_bit(EV_KEY
, input_dev
->evbit
);
1822 __clear_bit(EV_REL
, input_dev
->evbit
);
1823 __clear_bit(EV_LED
, input_dev
->evbit
);
1825 input_set_abs_params(input_dev
, ABS_MT_POSITION_X
, 0, wd
->x_size
, 0, 0);
1826 input_abs_set_res(input_dev
, ABS_MT_POSITION_X
, wd
->resolution
);
1827 input_set_abs_params(input_dev
, ABS_MT_POSITION_Y
, 0, wd
->y_size
, 0, 0);
1828 input_abs_set_res(input_dev
, ABS_MT_POSITION_Y
, wd
->resolution
);
1830 /* Max pressure is not given by the devices, pick one */
1831 input_set_abs_params(input_dev
, ABS_MT_PRESSURE
, 0, 50, 0, 0);
1833 input_set_capability(input_dev
, EV_KEY
, BTN_LEFT
);
1835 if (hidpp
->quirks
& HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS
)
1836 input_set_capability(input_dev
, EV_KEY
, BTN_RIGHT
);
1838 __set_bit(INPUT_PROP_BUTTONPAD
, input_dev
->propbit
);
1840 input_mt_init_slots(input_dev
, wd
->maxcontacts
, INPUT_MT_POINTER
|
1841 INPUT_MT_DROP_UNUSED
);
1843 wd
->input
= input_dev
;
1846 static void wtp_touch_event(struct wtp_data
*wd
,
1847 struct hidpp_touchpad_raw_xy_finger
*touch_report
)
1851 if (!touch_report
->finger_id
|| touch_report
->contact_type
)
1852 /* no actual data */
1855 slot
= input_mt_get_slot_by_key(wd
->input
, touch_report
->finger_id
);
1857 input_mt_slot(wd
->input
, slot
);
1858 input_mt_report_slot_state(wd
->input
, MT_TOOL_FINGER
,
1859 touch_report
->contact_status
);
1860 if (touch_report
->contact_status
) {
1861 input_event(wd
->input
, EV_ABS
, ABS_MT_POSITION_X
,
1863 input_event(wd
->input
, EV_ABS
, ABS_MT_POSITION_Y
,
1864 wd
->flip_y
? wd
->y_size
- touch_report
->y
:
1866 input_event(wd
->input
, EV_ABS
, ABS_MT_PRESSURE
,
1867 touch_report
->area
);
1871 static void wtp_send_raw_xy_event(struct hidpp_device
*hidpp
,
1872 struct hidpp_touchpad_raw_xy
*raw
)
1874 struct wtp_data
*wd
= hidpp
->private_data
;
1877 for (i
= 0; i
< 2; i
++)
1878 wtp_touch_event(wd
, &(raw
->fingers
[i
]));
1880 if (raw
->end_of_frame
&&
1881 !(hidpp
->quirks
& HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS
))
1882 input_event(wd
->input
, EV_KEY
, BTN_LEFT
, raw
->button
);
1884 if (raw
->end_of_frame
|| raw
->finger_count
<= 2) {
1885 input_mt_sync_frame(wd
->input
);
1886 input_sync(wd
->input
);
1890 static int wtp_mouse_raw_xy_event(struct hidpp_device
*hidpp
, u8
*data
)
1892 struct wtp_data
*wd
= hidpp
->private_data
;
1893 u8 c1_area
= ((data
[7] & 0xf) * (data
[7] & 0xf) +
1894 (data
[7] >> 4) * (data
[7] >> 4)) / 2;
1895 u8 c2_area
= ((data
[13] & 0xf) * (data
[13] & 0xf) +
1896 (data
[13] >> 4) * (data
[13] >> 4)) / 2;
1897 struct hidpp_touchpad_raw_xy raw
= {
1898 .timestamp
= data
[1],
1902 .contact_status
= !!data
[7],
1903 .x
= get_unaligned_le16(&data
[3]),
1904 .y
= get_unaligned_le16(&data
[5]),
1907 .finger_id
= data
[2],
1910 .contact_status
= !!data
[13],
1911 .x
= get_unaligned_le16(&data
[9]),
1912 .y
= get_unaligned_le16(&data
[11]),
1915 .finger_id
= data
[8],
1918 .finger_count
= wd
->maxcontacts
,
1920 .end_of_frame
= (data
[0] >> 7) == 0,
1921 .button
= data
[0] & 0x01,
1924 wtp_send_raw_xy_event(hidpp
, &raw
);
1929 static int wtp_raw_event(struct hid_device
*hdev
, u8
*data
, int size
)
1931 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
1932 struct wtp_data
*wd
= hidpp
->private_data
;
1933 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
1934 struct hidpp_touchpad_raw_xy raw
;
1936 if (!wd
|| !wd
->input
)
1942 hid_err(hdev
, "Received HID report of bad size (%d)",
1946 if (hidpp
->quirks
& HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS
) {
1947 input_event(wd
->input
, EV_KEY
, BTN_LEFT
,
1948 !!(data
[1] & 0x01));
1949 input_event(wd
->input
, EV_KEY
, BTN_RIGHT
,
1950 !!(data
[1] & 0x02));
1951 input_sync(wd
->input
);
1956 return wtp_mouse_raw_xy_event(hidpp
, &data
[7]);
1958 case REPORT_ID_HIDPP_LONG
:
1959 /* size is already checked in hidpp_raw_event. */
1960 if ((report
->fap
.feature_index
!= wd
->mt_feature_index
) ||
1961 (report
->fap
.funcindex_clientid
!= EVENT_TOUCHPAD_RAW_XY
))
1963 hidpp_touchpad_raw_xy_event(hidpp
, data
+ 4, &raw
);
1965 wtp_send_raw_xy_event(hidpp
, &raw
);
1972 static int wtp_get_config(struct hidpp_device
*hidpp
)
1974 struct wtp_data
*wd
= hidpp
->private_data
;
1975 struct hidpp_touchpad_raw_info raw_info
= {0};
1979 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_TOUCHPAD_RAW_XY
,
1980 &wd
->mt_feature_index
, &feature_type
);
1982 /* means that the device is not powered up */
1985 ret
= hidpp_touchpad_get_raw_info(hidpp
, wd
->mt_feature_index
,
1990 wd
->x_size
= raw_info
.x_size
;
1991 wd
->y_size
= raw_info
.y_size
;
1992 wd
->maxcontacts
= raw_info
.maxcontacts
;
1993 wd
->flip_y
= raw_info
.origin
== TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT
;
1994 wd
->resolution
= raw_info
.res
;
1995 if (!wd
->resolution
)
1996 wd
->resolution
= WTP_MANUAL_RESOLUTION
;
2001 static int wtp_allocate(struct hid_device
*hdev
, const struct hid_device_id
*id
)
2003 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2004 struct wtp_data
*wd
;
2006 wd
= devm_kzalloc(&hdev
->dev
, sizeof(struct wtp_data
),
2011 hidpp
->private_data
= wd
;
2016 static int wtp_connect(struct hid_device
*hdev
, bool connected
)
2018 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2019 struct wtp_data
*wd
= hidpp
->private_data
;
2023 ret
= wtp_get_config(hidpp
);
2025 hid_err(hdev
, "Can not get wtp config: %d\n", ret
);
2030 return hidpp_touchpad_set_raw_report_state(hidpp
, wd
->mt_feature_index
,
2034 /* ------------------------------------------------------------------------- */
2035 /* Logitech M560 devices */
2036 /* ------------------------------------------------------------------------- */
2039 * Logitech M560 protocol overview
2041 * The Logitech M560 mouse, is designed for windows 8. When the middle and/or
2042 * the sides buttons are pressed, it sends some keyboard keys events
2043 * instead of buttons ones.
2044 * To complicate things further, the middle button keys sequence
2045 * is different from the odd press and the even press.
2047 * forward button -> Super_R
2048 * backward button -> Super_L+'d' (press only)
2049 * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
2050 * 2nd time: left-click (press only)
2051 * NB: press-only means that when the button is pressed, the
2052 * KeyPress/ButtonPress and KeyRelease/ButtonRelease events are generated
2053 * together sequentially; instead when the button is released, no event is
2057 * 10<xx>0a 3500af03 (where <xx> is the mouse id),
2058 * the mouse reacts differently:
2059 * - it never sends a keyboard key event
2060 * - for the three mouse button it sends:
2061 * middle button press 11<xx>0a 3500af00...
2062 * side 1 button (forward) press 11<xx>0a 3500b000...
2063 * side 2 button (backward) press 11<xx>0a 3500ae00...
2064 * middle/side1/side2 button release 11<xx>0a 35000000...
2067 static const u8 m560_config_parameter
[] = {0x00, 0xaf, 0x03};
2069 struct m560_private_data
{
2070 struct input_dev
*input
;
2073 /* how buttons are mapped in the report */
2074 #define M560_MOUSE_BTN_LEFT 0x01
2075 #define M560_MOUSE_BTN_RIGHT 0x02
2076 #define M560_MOUSE_BTN_WHEEL_LEFT 0x08
2077 #define M560_MOUSE_BTN_WHEEL_RIGHT 0x10
2079 #define M560_SUB_ID 0x0a
2080 #define M560_BUTTON_MODE_REGISTER 0x35
2082 static int m560_send_config_command(struct hid_device
*hdev
, bool connected
)
2084 struct hidpp_report response
;
2085 struct hidpp_device
*hidpp_dev
;
2087 hidpp_dev
= hid_get_drvdata(hdev
);
2089 return hidpp_send_rap_command_sync(
2091 REPORT_ID_HIDPP_SHORT
,
2093 M560_BUTTON_MODE_REGISTER
,
2094 (u8
*)m560_config_parameter
,
2095 sizeof(m560_config_parameter
),
2100 static int m560_allocate(struct hid_device
*hdev
)
2102 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2103 struct m560_private_data
*d
;
2105 d
= devm_kzalloc(&hdev
->dev
, sizeof(struct m560_private_data
),
2110 hidpp
->private_data
= d
;
2115 static int m560_raw_event(struct hid_device
*hdev
, u8
*data
, int size
)
2117 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2118 struct m560_private_data
*mydata
= hidpp
->private_data
;
2121 if (!mydata
|| !mydata
->input
) {
2122 hid_err(hdev
, "error in parameter\n");
2127 hid_err(hdev
, "error in report\n");
2131 if (data
[0] == REPORT_ID_HIDPP_LONG
&&
2132 data
[2] == M560_SUB_ID
&& data
[6] == 0x00) {
2134 * m560 mouse report for middle, forward and backward button
2137 * data[1] = device-id
2139 * data[5] = 0xaf -> middle
2142 * 0x00 -> release all
2148 input_report_key(mydata
->input
, BTN_MIDDLE
, 1);
2151 input_report_key(mydata
->input
, BTN_FORWARD
, 1);
2154 input_report_key(mydata
->input
, BTN_BACK
, 1);
2157 input_report_key(mydata
->input
, BTN_BACK
, 0);
2158 input_report_key(mydata
->input
, BTN_FORWARD
, 0);
2159 input_report_key(mydata
->input
, BTN_MIDDLE
, 0);
2162 hid_err(hdev
, "error in report\n");
2165 input_sync(mydata
->input
);
2167 } else if (data
[0] == 0x02) {
2169 * Logitech M560 mouse report
2171 * data[0] = type (0x02)
2172 * data[1..2] = buttons
2179 input_report_key(mydata
->input
, BTN_LEFT
,
2180 !!(data
[1] & M560_MOUSE_BTN_LEFT
));
2181 input_report_key(mydata
->input
, BTN_RIGHT
,
2182 !!(data
[1] & M560_MOUSE_BTN_RIGHT
));
2184 if (data
[1] & M560_MOUSE_BTN_WHEEL_LEFT
)
2185 input_report_rel(mydata
->input
, REL_HWHEEL
, -1);
2186 else if (data
[1] & M560_MOUSE_BTN_WHEEL_RIGHT
)
2187 input_report_rel(mydata
->input
, REL_HWHEEL
, 1);
2189 v
= hid_snto32(hid_field_extract(hdev
, data
+3, 0, 12), 12);
2190 input_report_rel(mydata
->input
, REL_X
, v
);
2192 v
= hid_snto32(hid_field_extract(hdev
, data
+3, 12, 12), 12);
2193 input_report_rel(mydata
->input
, REL_Y
, v
);
2195 v
= hid_snto32(data
[6], 8);
2196 input_report_rel(mydata
->input
, REL_WHEEL
, v
);
2198 input_sync(mydata
->input
);
2204 static void m560_populate_input(struct hidpp_device
*hidpp
,
2205 struct input_dev
*input_dev
, bool origin_is_hid_core
)
2207 struct m560_private_data
*mydata
= hidpp
->private_data
;
2209 mydata
->input
= input_dev
;
2211 __set_bit(EV_KEY
, mydata
->input
->evbit
);
2212 __set_bit(BTN_MIDDLE
, mydata
->input
->keybit
);
2213 __set_bit(BTN_RIGHT
, mydata
->input
->keybit
);
2214 __set_bit(BTN_LEFT
, mydata
->input
->keybit
);
2215 __set_bit(BTN_BACK
, mydata
->input
->keybit
);
2216 __set_bit(BTN_FORWARD
, mydata
->input
->keybit
);
2218 __set_bit(EV_REL
, mydata
->input
->evbit
);
2219 __set_bit(REL_X
, mydata
->input
->relbit
);
2220 __set_bit(REL_Y
, mydata
->input
->relbit
);
2221 __set_bit(REL_WHEEL
, mydata
->input
->relbit
);
2222 __set_bit(REL_HWHEEL
, mydata
->input
->relbit
);
2225 static int m560_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
2226 struct hid_field
*field
, struct hid_usage
*usage
,
2227 unsigned long **bit
, int *max
)
2232 /* ------------------------------------------------------------------------- */
2233 /* Logitech K400 devices */
2234 /* ------------------------------------------------------------------------- */
2237 * The Logitech K400 keyboard has an embedded touchpad which is seen
2238 * as a mouse from the OS point of view. There is a hardware shortcut to disable
2239 * tap-to-click but the setting is not remembered accross reset, annoying some
2242 * We can toggle this feature from the host by using the feature 0x6010:
2246 struct k400_private_data
{
2250 static int k400_disable_tap_to_click(struct hidpp_device
*hidpp
)
2252 struct k400_private_data
*k400
= hidpp
->private_data
;
2253 struct hidpp_touchpad_fw_items items
= {};
2257 if (!k400
->feature_index
) {
2258 ret
= hidpp_root_get_feature(hidpp
,
2259 HIDPP_PAGE_TOUCHPAD_FW_ITEMS
,
2260 &k400
->feature_index
, &feature_type
);
2262 /* means that the device is not powered up */
2266 ret
= hidpp_touchpad_fw_items_set(hidpp
, k400
->feature_index
, &items
);
2273 static int k400_allocate(struct hid_device
*hdev
)
2275 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2276 struct k400_private_data
*k400
;
2278 k400
= devm_kzalloc(&hdev
->dev
, sizeof(struct k400_private_data
),
2283 hidpp
->private_data
= k400
;
2288 static int k400_connect(struct hid_device
*hdev
, bool connected
)
2290 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2292 if (!disable_tap_to_click
)
2295 return k400_disable_tap_to_click(hidpp
);
2298 /* ------------------------------------------------------------------------- */
2299 /* Logitech G920 Driving Force Racing Wheel for Xbox One */
2300 /* ------------------------------------------------------------------------- */
2302 #define HIDPP_PAGE_G920_FORCE_FEEDBACK 0x8123
2304 static int g920_get_config(struct hidpp_device
*hidpp
)
2310 /* Find feature and store for later use */
2311 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_G920_FORCE_FEEDBACK
,
2312 &feature_index
, &feature_type
);
2316 ret
= hidpp_ff_init(hidpp
, feature_index
);
2318 hid_warn(hidpp
->hid_dev
, "Unable to initialize force feedback support, errno %d\n",
2324 /* -------------------------------------------------------------------------- */
2325 /* Generic HID++ devices */
2326 /* -------------------------------------------------------------------------- */
2328 static int hidpp_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
2329 struct hid_field
*field
, struct hid_usage
*usage
,
2330 unsigned long **bit
, int *max
)
2332 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2334 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
)
2335 return wtp_input_mapping(hdev
, hi
, field
, usage
, bit
, max
);
2336 else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_M560
&&
2337 field
->application
!= HID_GD_MOUSE
)
2338 return m560_input_mapping(hdev
, hi
, field
, usage
, bit
, max
);
2343 static int hidpp_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
2344 struct hid_field
*field
, struct hid_usage
*usage
,
2345 unsigned long **bit
, int *max
)
2347 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2349 /* Ensure that Logitech G920 is not given a default fuzz/flat value */
2350 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_G920
) {
2351 if (usage
->type
== EV_ABS
&& (usage
->code
== ABS_X
||
2352 usage
->code
== ABS_Y
|| usage
->code
== ABS_Z
||
2353 usage
->code
== ABS_RZ
)) {
2354 field
->application
= HID_GD_MULTIAXIS
;
2362 static void hidpp_populate_input(struct hidpp_device
*hidpp
,
2363 struct input_dev
*input
, bool origin_is_hid_core
)
2365 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
)
2366 wtp_populate_input(hidpp
, input
, origin_is_hid_core
);
2367 else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_M560
)
2368 m560_populate_input(hidpp
, input
, origin_is_hid_core
);
2371 static int hidpp_input_configured(struct hid_device
*hdev
,
2372 struct hid_input
*hidinput
)
2374 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2375 struct input_dev
*input
= hidinput
->input
;
2377 hidpp_populate_input(hidpp
, input
, true);
2382 static int hidpp_raw_hidpp_event(struct hidpp_device
*hidpp
, u8
*data
,
2385 struct hidpp_report
*question
= hidpp
->send_receive_buf
;
2386 struct hidpp_report
*answer
= hidpp
->send_receive_buf
;
2387 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
2391 * If the mutex is locked then we have a pending answer from a
2392 * previously sent command.
2394 if (unlikely(mutex_is_locked(&hidpp
->send_mutex
))) {
2396 * Check for a correct hidpp20 answer or the corresponding
2399 if (hidpp_match_answer(question
, report
) ||
2400 hidpp_match_error(question
, report
)) {
2402 hidpp
->answer_available
= true;
2403 wake_up(&hidpp
->wait
);
2405 * This was an answer to a command that this driver sent
2406 * We return 1 to hid-core to avoid forwarding the
2407 * command upstream as it has been treated by the driver
2414 if (unlikely(hidpp_report_is_connect_event(report
))) {
2415 atomic_set(&hidpp
->connected
,
2416 !(report
->rap
.params
[0] & (1 << 6)));
2417 if (schedule_work(&hidpp
->work
) == 0)
2418 dbg_hid("%s: connect event already queued\n", __func__
);
2422 if (hidpp
->capabilities
& HIDPP_CAPABILITY_HIDPP20_BATTERY
) {
2423 ret
= hidpp20_battery_event(hidpp
, data
, size
);
2426 ret
= hidpp_solar_battery_event(hidpp
, data
, size
);
2434 static int hidpp_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
2437 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2440 /* Generic HID++ processing. */
2442 case REPORT_ID_HIDPP_VERY_LONG
:
2443 if (size
!= HIDPP_REPORT_VERY_LONG_LENGTH
) {
2444 hid_err(hdev
, "received hid++ report of bad size (%d)",
2448 ret
= hidpp_raw_hidpp_event(hidpp
, data
, size
);
2450 case REPORT_ID_HIDPP_LONG
:
2451 if (size
!= HIDPP_REPORT_LONG_LENGTH
) {
2452 hid_err(hdev
, "received hid++ report of bad size (%d)",
2456 ret
= hidpp_raw_hidpp_event(hidpp
, data
, size
);
2458 case REPORT_ID_HIDPP_SHORT
:
2459 if (size
!= HIDPP_REPORT_SHORT_LENGTH
) {
2460 hid_err(hdev
, "received hid++ report of bad size (%d)",
2464 ret
= hidpp_raw_hidpp_event(hidpp
, data
, size
);
2468 /* If no report is available for further processing, skip calling
2469 * raw_event of subclasses. */
2473 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
)
2474 return wtp_raw_event(hdev
, data
, size
);
2475 else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_M560
)
2476 return m560_raw_event(hdev
, data
, size
);
2481 static int hidpp_initialize_battery(struct hidpp_device
*hidpp
)
2483 static atomic_t battery_no
= ATOMIC_INIT(0);
2484 struct power_supply_config cfg
= { .drv_data
= hidpp
};
2485 struct power_supply_desc
*desc
= &hidpp
->battery
.desc
;
2486 enum power_supply_property
*battery_props
;
2487 struct hidpp_battery
*battery
;
2488 unsigned int num_battery_props
;
2492 if (hidpp
->battery
.ps
)
2495 hidpp
->battery
.feature_index
= 0xff;
2496 hidpp
->battery
.solar_feature_index
= 0xff;
2498 if (hidpp
->protocol_major
>= 2) {
2499 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_K750
)
2500 ret
= hidpp_solar_request_battery_event(hidpp
);
2502 ret
= hidpp20_query_battery_info(hidpp
);
2506 hidpp
->capabilities
|= HIDPP_CAPABILITY_HIDPP20_BATTERY
;
2511 battery_props
= devm_kmemdup(&hidpp
->hid_dev
->dev
,
2512 hidpp_battery_props
,
2513 sizeof(hidpp_battery_props
),
2515 num_battery_props
= ARRAY_SIZE(hidpp_battery_props
) - 2;
2517 if (hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_MILEAGE
)
2518 battery_props
[num_battery_props
++] =
2519 POWER_SUPPLY_PROP_CAPACITY
;
2521 if (hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS
)
2522 battery_props
[num_battery_props
++] =
2523 POWER_SUPPLY_PROP_CAPACITY_LEVEL
;
2525 battery
= &hidpp
->battery
;
2527 n
= atomic_inc_return(&battery_no
) - 1;
2528 desc
->properties
= battery_props
;
2529 desc
->num_properties
= num_battery_props
;
2530 desc
->get_property
= hidpp_battery_get_property
;
2531 sprintf(battery
->name
, "hidpp_battery_%ld", n
);
2532 desc
->name
= battery
->name
;
2533 desc
->type
= POWER_SUPPLY_TYPE_BATTERY
;
2534 desc
->use_for_apm
= 0;
2536 battery
->ps
= devm_power_supply_register(&hidpp
->hid_dev
->dev
,
2539 if (IS_ERR(battery
->ps
))
2540 return PTR_ERR(battery
->ps
);
2542 power_supply_powers(battery
->ps
, &hidpp
->hid_dev
->dev
);
2547 static void hidpp_overwrite_name(struct hid_device
*hdev
)
2549 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2552 if (hidpp
->protocol_major
< 2)
2555 name
= hidpp_get_device_name(hidpp
);
2558 hid_err(hdev
, "unable to retrieve the name of the device");
2560 dbg_hid("HID++: Got name: %s\n", name
);
2561 snprintf(hdev
->name
, sizeof(hdev
->name
), "%s", name
);
2567 static int hidpp_input_open(struct input_dev
*dev
)
2569 struct hid_device
*hid
= input_get_drvdata(dev
);
2571 return hid_hw_open(hid
);
2574 static void hidpp_input_close(struct input_dev
*dev
)
2576 struct hid_device
*hid
= input_get_drvdata(dev
);
2581 static struct input_dev
*hidpp_allocate_input(struct hid_device
*hdev
)
2583 struct input_dev
*input_dev
= devm_input_allocate_device(&hdev
->dev
);
2584 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2589 input_set_drvdata(input_dev
, hdev
);
2590 input_dev
->open
= hidpp_input_open
;
2591 input_dev
->close
= hidpp_input_close
;
2593 input_dev
->name
= hidpp
->name
;
2594 input_dev
->phys
= hdev
->phys
;
2595 input_dev
->uniq
= hdev
->uniq
;
2596 input_dev
->id
.bustype
= hdev
->bus
;
2597 input_dev
->id
.vendor
= hdev
->vendor
;
2598 input_dev
->id
.product
= hdev
->product
;
2599 input_dev
->id
.version
= hdev
->version
;
2600 input_dev
->dev
.parent
= &hdev
->dev
;
2605 static void hidpp_connect_event(struct hidpp_device
*hidpp
)
2607 struct hid_device
*hdev
= hidpp
->hid_dev
;
2609 bool connected
= atomic_read(&hidpp
->connected
);
2610 struct input_dev
*input
;
2611 char *name
, *devm_name
;
2614 if (hidpp
->battery
.ps
) {
2615 hidpp
->battery
.online
= false;
2616 hidpp
->battery
.status
= POWER_SUPPLY_STATUS_UNKNOWN
;
2617 hidpp
->battery
.level
= POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN
;
2618 power_supply_changed(hidpp
->battery
.ps
);
2623 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
) {
2624 ret
= wtp_connect(hdev
, connected
);
2627 } else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_M560
) {
2628 ret
= m560_send_config_command(hdev
, connected
);
2631 } else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_K400
) {
2632 ret
= k400_connect(hdev
, connected
);
2637 /* the device is already connected, we can ask for its name and
2639 if (!hidpp
->protocol_major
) {
2640 ret
= !hidpp_is_connected(hidpp
);
2642 hid_err(hdev
, "Can not get the protocol version.\n");
2645 hid_info(hdev
, "HID++ %u.%u device connected.\n",
2646 hidpp
->protocol_major
, hidpp
->protocol_minor
);
2649 if (hidpp
->name
== hdev
->name
&& hidpp
->protocol_major
>= 2) {
2650 name
= hidpp_get_device_name(hidpp
);
2653 "unable to retrieve the name of the device");
2657 devm_name
= devm_kasprintf(&hdev
->dev
, GFP_KERNEL
, "%s", name
);
2662 hidpp
->name
= devm_name
;
2665 hidpp_initialize_battery(hidpp
);
2667 /* forward current battery state */
2668 if (hidpp
->capabilities
& HIDPP_CAPABILITY_HIDPP20_BATTERY
) {
2669 hidpp20_query_battery_info(hidpp
);
2670 if (hidpp
->battery
.ps
)
2671 power_supply_changed(hidpp
->battery
.ps
);
2674 if (!(hidpp
->quirks
& HIDPP_QUIRK_NO_HIDINPUT
) || hidpp
->delayed_input
)
2675 /* if the input nodes are already created, we can stop now */
2678 input
= hidpp_allocate_input(hdev
);
2680 hid_err(hdev
, "cannot allocate new input device: %d\n", ret
);
2684 hidpp_populate_input(hidpp
, input
, false);
2686 ret
= input_register_device(input
);
2688 input_free_device(input
);
2690 hidpp
->delayed_input
= input
;
2693 static int hidpp_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
2695 struct hidpp_device
*hidpp
;
2698 unsigned int connect_mask
= HID_CONNECT_DEFAULT
;
2700 hidpp
= devm_kzalloc(&hdev
->dev
, sizeof(struct hidpp_device
),
2705 hidpp
->hid_dev
= hdev
;
2706 hidpp
->name
= hdev
->name
;
2707 hid_set_drvdata(hdev
, hidpp
);
2709 hidpp
->quirks
= id
->driver_data
;
2711 if (id
->group
== HID_GROUP_LOGITECH_DJ_DEVICE
)
2712 hidpp
->quirks
|= HIDPP_QUIRK_UNIFYING
;
2714 if (disable_raw_mode
) {
2715 hidpp
->quirks
&= ~HIDPP_QUIRK_CLASS_WTP
;
2716 hidpp
->quirks
&= ~HIDPP_QUIRK_NO_HIDINPUT
;
2719 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
) {
2720 ret
= wtp_allocate(hdev
, id
);
2723 } else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_M560
) {
2724 ret
= m560_allocate(hdev
);
2727 } else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_K400
) {
2728 ret
= k400_allocate(hdev
);
2733 INIT_WORK(&hidpp
->work
, delayed_work_cb
);
2734 mutex_init(&hidpp
->send_mutex
);
2735 init_waitqueue_head(&hidpp
->wait
);
2737 ret
= hid_parse(hdev
);
2739 hid_err(hdev
, "%s:parse failed\n", __func__
);
2740 goto hid_parse_fail
;
2743 if (hidpp
->quirks
& HIDPP_QUIRK_NO_HIDINPUT
)
2744 connect_mask
&= ~HID_CONNECT_HIDINPUT
;
2746 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_G920
) {
2747 ret
= hid_hw_start(hdev
, connect_mask
);
2749 hid_err(hdev
, "hw start failed\n");
2750 goto hid_hw_start_fail
;
2752 ret
= hid_hw_open(hdev
);
2754 dev_err(&hdev
->dev
, "%s:hid_hw_open returned error:%d\n",
2757 goto hid_hw_start_fail
;
2762 /* Allow incoming packets */
2763 hid_device_io_start(hdev
);
2765 if (hidpp
->quirks
& HIDPP_QUIRK_UNIFYING
)
2766 hidpp_unifying_init(hidpp
);
2768 connected
= hidpp_is_connected(hidpp
);
2769 atomic_set(&hidpp
->connected
, connected
);
2770 if (!(hidpp
->quirks
& HIDPP_QUIRK_UNIFYING
)) {
2773 hid_err(hdev
, "Device not connected");
2774 goto hid_hw_open_failed
;
2777 hid_info(hdev
, "HID++ %u.%u device connected.\n",
2778 hidpp
->protocol_major
, hidpp
->protocol_minor
);
2780 hidpp_overwrite_name(hdev
);
2783 if (connected
&& (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
)) {
2784 ret
= wtp_get_config(hidpp
);
2786 goto hid_hw_open_failed
;
2787 } else if (connected
&& (hidpp
->quirks
& HIDPP_QUIRK_CLASS_G920
)) {
2788 ret
= g920_get_config(hidpp
);
2790 goto hid_hw_open_failed
;
2793 /* Block incoming packets */
2794 hid_device_io_stop(hdev
);
2796 if (!(hidpp
->quirks
& HIDPP_QUIRK_CLASS_G920
)) {
2797 ret
= hid_hw_start(hdev
, connect_mask
);
2799 hid_err(hdev
, "%s:hid_hw_start returned error\n", __func__
);
2800 goto hid_hw_start_fail
;
2804 /* Allow incoming packets */
2805 hid_device_io_start(hdev
);
2807 hidpp_connect_event(hidpp
);
2812 hid_device_io_stop(hdev
);
2813 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_G920
) {
2819 cancel_work_sync(&hidpp
->work
);
2820 mutex_destroy(&hidpp
->send_mutex
);
2822 hid_set_drvdata(hdev
, NULL
);
2826 static void hidpp_remove(struct hid_device
*hdev
)
2828 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
2830 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_G920
) {
2831 hidpp_ff_deinit(hdev
);
2835 cancel_work_sync(&hidpp
->work
);
2836 mutex_destroy(&hidpp
->send_mutex
);
2839 static const struct hid_device_id hidpp_devices
[] = {
2840 { /* wireless touchpad */
2841 HID_DEVICE(BUS_USB
, HID_GROUP_LOGITECH_DJ_DEVICE
,
2842 USB_VENDOR_ID_LOGITECH
, 0x4011),
2843 .driver_data
= HIDPP_QUIRK_CLASS_WTP
| HIDPP_QUIRK_DELAYED_INIT
|
2844 HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS
},
2845 { /* wireless touchpad T650 */
2846 HID_DEVICE(BUS_USB
, HID_GROUP_LOGITECH_DJ_DEVICE
,
2847 USB_VENDOR_ID_LOGITECH
, 0x4101),
2848 .driver_data
= HIDPP_QUIRK_CLASS_WTP
| HIDPP_QUIRK_DELAYED_INIT
},
2849 { /* wireless touchpad T651 */
2850 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
,
2851 USB_DEVICE_ID_LOGITECH_T651
),
2852 .driver_data
= HIDPP_QUIRK_CLASS_WTP
},
2853 { /* Mouse logitech M560 */
2854 HID_DEVICE(BUS_USB
, HID_GROUP_LOGITECH_DJ_DEVICE
,
2855 USB_VENDOR_ID_LOGITECH
, 0x402d),
2856 .driver_data
= HIDPP_QUIRK_DELAYED_INIT
| HIDPP_QUIRK_CLASS_M560
},
2857 { /* Keyboard logitech K400 */
2858 HID_DEVICE(BUS_USB
, HID_GROUP_LOGITECH_DJ_DEVICE
,
2859 USB_VENDOR_ID_LOGITECH
, 0x4024),
2860 .driver_data
= HIDPP_QUIRK_CLASS_K400
},
2861 { /* Solar Keyboard Logitech K750 */
2862 HID_DEVICE(BUS_USB
, HID_GROUP_LOGITECH_DJ_DEVICE
,
2863 USB_VENDOR_ID_LOGITECH
, 0x4002),
2864 .driver_data
= HIDPP_QUIRK_CLASS_K750
},
2866 { HID_DEVICE(BUS_USB
, HID_GROUP_LOGITECH_DJ_DEVICE
,
2867 USB_VENDOR_ID_LOGITECH
, HID_ANY_ID
)},
2869 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_G920_WHEEL
),
2870 .driver_data
= HIDPP_QUIRK_CLASS_G920
| HIDPP_QUIRK_FORCE_OUTPUT_REPORTS
},
2874 MODULE_DEVICE_TABLE(hid
, hidpp_devices
);
2876 static struct hid_driver hidpp_driver
= {
2877 .name
= "logitech-hidpp-device",
2878 .id_table
= hidpp_devices
,
2879 .probe
= hidpp_probe
,
2880 .remove
= hidpp_remove
,
2881 .raw_event
= hidpp_raw_event
,
2882 .input_configured
= hidpp_input_configured
,
2883 .input_mapping
= hidpp_input_mapping
,
2884 .input_mapped
= hidpp_input_mapped
,
2887 module_hid_driver(hidpp_driver
);