1 // SPDX-License-Identifier: GPL-2.0-only
3 * HIDPP protocol for Logitech receivers
5 * Copyright (c) 2011 Logitech (c)
6 * Copyright (c) 2012-2013 Google (c)
7 * Copyright (c) 2013-2014 Red Hat Inc.
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/device.h>
14 #include <linux/input.h>
15 #include <linux/usb.h>
16 #include <linux/hid.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/sched.h>
20 #include <linux/sched/clock.h>
21 #include <linux/kfifo.h>
22 #include <linux/input/mt.h>
23 #include <linux/workqueue.h>
24 #include <linux/atomic.h>
25 #include <linux/fixp-arith.h>
26 #include <asm/unaligned.h>
27 #include "usbhid/usbhid.h"
30 MODULE_LICENSE("GPL");
31 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
32 MODULE_AUTHOR("Nestor Lopez Casado <nlopezcasad@logitech.com>");
34 static bool disable_raw_mode;
35 module_param(disable_raw_mode, bool, 0644);
36 MODULE_PARM_DESC(disable_raw_mode,
37 "Disable Raw mode reporting for touchpads and keep firmware gestures.");
39 static bool disable_tap_to_click;
40 module_param(disable_tap_to_click, bool, 0644);
41 MODULE_PARM_DESC(disable_tap_to_click,
42 "Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
44 /* Define a non-zero software ID to identify our own requests */
45 #define LINUX_KERNEL_SW_ID 0x01
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_MAX_LENGTH 64
55 #define HIDPP_REPORT_SHORT_SUPPORTED BIT(0)
56 #define HIDPP_REPORT_LONG_SUPPORTED BIT(1)
57 #define HIDPP_REPORT_VERY_LONG_SUPPORTED BIT(2)
59 #define HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS 0x03
60 #define HIDPP_SUB_ID_ROLLER 0x05
61 #define HIDPP_SUB_ID_MOUSE_EXTRA_BTNS 0x06
62 #define HIDPP_SUB_ID_USER_IFACE_EVENT 0x08
63 #define HIDPP_USER_IFACE_EVENT_ENCRYPTION_KEY_LOST BIT(5)
65 #define HIDPP_QUIRK_CLASS_WTP BIT(0)
66 #define HIDPP_QUIRK_CLASS_M560 BIT(1)
67 #define HIDPP_QUIRK_CLASS_K400 BIT(2)
68 #define HIDPP_QUIRK_CLASS_G920 BIT(3)
69 #define HIDPP_QUIRK_CLASS_K750 BIT(4)
71 /* bits 2..20 are reserved for classes */
72 /* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */
73 #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22)
74 #define HIDPP_QUIRK_NO_HIDINPUT BIT(23)
75 #define HIDPP_QUIRK_FORCE_OUTPUT_REPORTS BIT(24)
76 #define HIDPP_QUIRK_UNIFYING BIT(25)
77 #define HIDPP_QUIRK_HIDPP_WHEELS BIT(26)
78 #define HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS BIT(27)
79 #define HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS BIT(28)
81 /* These are just aliases for now */
82 #define HIDPP_QUIRK_KBD_SCROLL_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
83 #define HIDPP_QUIRK_KBD_ZOOM_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
85 /* Convenience constant to check for any high-res support. */
86 #define HIDPP_CAPABILITY_HI_RES_SCROLL (HIDPP_CAPABILITY_HIDPP10_FAST_SCROLL | \
87 HIDPP_CAPABILITY_HIDPP20_HI_RES_SCROLL | \
88 HIDPP_CAPABILITY_HIDPP20_HI_RES_WHEEL)
90 #define HIDPP_QUIRK_DELAYED_INIT HIDPP_QUIRK_NO_HIDINPUT
92 #define HIDPP_CAPABILITY_HIDPP10_BATTERY BIT(0)
93 #define HIDPP_CAPABILITY_HIDPP20_BATTERY BIT(1)
94 #define HIDPP_CAPABILITY_BATTERY_MILEAGE BIT(2)
95 #define HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS BIT(3)
96 #define HIDPP_CAPABILITY_BATTERY_VOLTAGE BIT(4)
97 #define HIDPP_CAPABILITY_BATTERY_PERCENTAGE BIT(5)
98 #define HIDPP_CAPABILITY_UNIFIED_BATTERY BIT(6)
99 #define HIDPP_CAPABILITY_HIDPP20_HI_RES_WHEEL BIT(7)
100 #define HIDPP_CAPABILITY_HIDPP20_HI_RES_SCROLL BIT(8)
101 #define HIDPP_CAPABILITY_HIDPP10_FAST_SCROLL BIT(9)
103 #define lg_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
106 * There are two hidpp protocols in use, the first version hidpp10 is known
107 * as register access protocol or RAP, the second version hidpp20 is known as
108 * feature access protocol or FAP
110 * Most older devices (including the Unifying usb receiver) use the RAP protocol
111 * where as most newer devices use the FAP protocol. Both protocols are
112 * compatible with the underlying transport, which could be usb, Unifiying, or
113 * bluetooth. The message lengths are defined by the hid vendor specific report
114 * descriptor for the HIDPP_SHORT report type (total message lenth 7 bytes) and
115 * the HIDPP_LONG report type (total message length 20 bytes)
117 * The RAP protocol uses both report types, whereas the FAP only uses HIDPP_LONG
118 * messages. The Unifying receiver itself responds to RAP messages (device index
119 * is 0xFF for the receiver), and all messages (short or long) with a device
120 * index between 1 and 6 are passed untouched to the corresponding paired
123 * The paired device can be RAP or FAP, it will receive the message untouched
124 * from the Unifiying receiver.
129 u8 funcindex_clientid;
130 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
136 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
139 struct hidpp_report {
145 u8 rawbytes[sizeof(struct fap)];
149 struct hidpp_battery {
151 u8 solar_feature_index;
152 u8 voltage_feature_index;
153 struct power_supply_desc desc;
154 struct power_supply *ps;
162 u8 supported_levels_1004;
166 * struct hidpp_scroll_counter - Utility class for processing high-resolution
168 * @dev: the input device for which events should be reported.
169 * @wheel_multiplier: the scalar multiplier to be applied to each wheel event
170 * @remainder: counts the number of high-resolution units moved since the last
171 * low-resolution event (REL_WHEEL or REL_HWHEEL) was sent. Should
172 * only be used by class methods.
173 * @direction: direction of last movement (1 or -1)
174 * @last_time: last event time, used to reset remainder after inactivity
176 struct hidpp_scroll_counter {
177 int wheel_multiplier;
180 unsigned long long last_time;
183 struct hidpp_device {
184 struct hid_device *hid_dev;
185 struct input_dev *input;
186 struct mutex send_mutex;
187 void *send_receive_buf;
188 char *name; /* will never be NULL and should not be freed */
189 wait_queue_head_t wait;
190 int very_long_report_length;
191 bool answer_available;
197 struct work_struct work;
198 struct kfifo delayed_work_fifo;
200 struct input_dev *delayed_input;
202 unsigned long quirks;
203 unsigned long capabilities;
204 u8 supported_reports;
206 struct hidpp_battery battery;
207 struct hidpp_scroll_counter vertical_wheel_counter;
209 u8 wireless_feature_index;
212 /* HID++ 1.0 error codes */
213 #define HIDPP_ERROR 0x8f
214 #define HIDPP_ERROR_SUCCESS 0x00
215 #define HIDPP_ERROR_INVALID_SUBID 0x01
216 #define HIDPP_ERROR_INVALID_ADRESS 0x02
217 #define HIDPP_ERROR_INVALID_VALUE 0x03
218 #define HIDPP_ERROR_CONNECT_FAIL 0x04
219 #define HIDPP_ERROR_TOO_MANY_DEVICES 0x05
220 #define HIDPP_ERROR_ALREADY_EXISTS 0x06
221 #define HIDPP_ERROR_BUSY 0x07
222 #define HIDPP_ERROR_UNKNOWN_DEVICE 0x08
223 #define HIDPP_ERROR_RESOURCE_ERROR 0x09
224 #define HIDPP_ERROR_REQUEST_UNAVAILABLE 0x0a
225 #define HIDPP_ERROR_INVALID_PARAM_VALUE 0x0b
226 #define HIDPP_ERROR_WRONG_PIN_CODE 0x0c
227 /* HID++ 2.0 error codes */
228 #define HIDPP20_ERROR 0xff
230 static void hidpp_connect_event(struct hidpp_device *hidpp_dev);
232 static int __hidpp_send_report(struct hid_device *hdev,
233 struct hidpp_report *hidpp_report)
235 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
236 int fields_count, ret;
238 switch (hidpp_report->report_id) {
239 case REPORT_ID_HIDPP_SHORT:
240 fields_count = HIDPP_REPORT_SHORT_LENGTH;
242 case REPORT_ID_HIDPP_LONG:
243 fields_count = HIDPP_REPORT_LONG_LENGTH;
245 case REPORT_ID_HIDPP_VERY_LONG:
246 fields_count = hidpp->very_long_report_length;
253 * set the device_index as the receiver, it will be overwritten by
254 * hid_hw_request if needed
256 hidpp_report->device_index = 0xff;
258 if (hidpp->quirks & HIDPP_QUIRK_FORCE_OUTPUT_REPORTS) {
259 ret = hid_hw_output_report(hdev, (u8 *)hidpp_report, fields_count);
261 ret = hid_hw_raw_request(hdev, hidpp_report->report_id,
262 (u8 *)hidpp_report, fields_count, HID_OUTPUT_REPORT,
266 return ret == fields_count ? 0 : -1;
270 * hidpp_send_message_sync() returns 0 in case of success, and something else
271 * in case of a failure.
272 * - If ' something else' is positive, that means that an error has been raised
273 * by the protocol itself.
274 * - If ' something else' is negative, that means that we had a classic error
275 * (-ENOMEM, -EPIPE, etc...)
277 static int hidpp_send_message_sync(struct hidpp_device *hidpp,
278 struct hidpp_report *message,
279 struct hidpp_report *response)
283 mutex_lock(&hidpp->send_mutex);
285 hidpp->send_receive_buf = response;
286 hidpp->answer_available = false;
289 * So that we can later validate the answer when it arrives
292 *response = *message;
294 ret = __hidpp_send_report(hidpp->hid_dev, message);
297 dbg_hid("__hidpp_send_report returned err: %d\n", ret);
298 memset(response, 0, sizeof(struct hidpp_report));
302 if (!wait_event_timeout(hidpp->wait, hidpp->answer_available,
304 dbg_hid("%s:timeout waiting for response\n", __func__);
305 memset(response, 0, sizeof(struct hidpp_report));
309 if (response->report_id == REPORT_ID_HIDPP_SHORT &&
310 response->rap.sub_id == HIDPP_ERROR) {
311 ret = response->rap.params[1];
312 dbg_hid("%s:got hidpp error %02X\n", __func__, ret);
316 if ((response->report_id == REPORT_ID_HIDPP_LONG ||
317 response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&
318 response->fap.feature_index == HIDPP20_ERROR) {
319 ret = response->fap.params[1];
320 dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);
325 mutex_unlock(&hidpp->send_mutex);
330 static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
331 u8 feat_index, u8 funcindex_clientid, u8 *params, int param_count,
332 struct hidpp_report *response)
334 struct hidpp_report *message;
337 if (param_count > sizeof(message->fap.params))
340 message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
344 if (param_count > (HIDPP_REPORT_LONG_LENGTH - 4))
345 message->report_id = REPORT_ID_HIDPP_VERY_LONG;
347 message->report_id = REPORT_ID_HIDPP_LONG;
348 message->fap.feature_index = feat_index;
349 message->fap.funcindex_clientid = funcindex_clientid | LINUX_KERNEL_SW_ID;
350 memcpy(&message->fap.params, params, param_count);
352 ret = hidpp_send_message_sync(hidpp, message, response);
357 static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,
358 u8 report_id, u8 sub_id, u8 reg_address, u8 *params, int param_count,
359 struct hidpp_report *response)
361 struct hidpp_report *message;
364 /* Send as long report if short reports are not supported. */
365 if (report_id == REPORT_ID_HIDPP_SHORT &&
366 !(hidpp_dev->supported_reports & HIDPP_REPORT_SHORT_SUPPORTED))
367 report_id = REPORT_ID_HIDPP_LONG;
370 case REPORT_ID_HIDPP_SHORT:
371 max_count = HIDPP_REPORT_SHORT_LENGTH - 4;
373 case REPORT_ID_HIDPP_LONG:
374 max_count = HIDPP_REPORT_LONG_LENGTH - 4;
376 case REPORT_ID_HIDPP_VERY_LONG:
377 max_count = hidpp_dev->very_long_report_length - 4;
383 if (param_count > max_count)
386 message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
389 message->report_id = report_id;
390 message->rap.sub_id = sub_id;
391 message->rap.reg_address = reg_address;
392 memcpy(&message->rap.params, params, param_count);
394 ret = hidpp_send_message_sync(hidpp_dev, message, response);
399 static void delayed_work_cb(struct work_struct *work)
401 struct hidpp_device *hidpp = container_of(work, struct hidpp_device,
403 hidpp_connect_event(hidpp);
406 static inline bool hidpp_match_answer(struct hidpp_report *question,
407 struct hidpp_report *answer)
409 return (answer->fap.feature_index == question->fap.feature_index) &&
410 (answer->fap.funcindex_clientid == question->fap.funcindex_clientid);
413 static inline bool hidpp_match_error(struct hidpp_report *question,
414 struct hidpp_report *answer)
416 return ((answer->rap.sub_id == HIDPP_ERROR) ||
417 (answer->fap.feature_index == HIDPP20_ERROR)) &&
418 (answer->fap.funcindex_clientid == question->fap.feature_index) &&
419 (answer->fap.params[0] == question->fap.funcindex_clientid);
422 static inline bool hidpp_report_is_connect_event(struct hidpp_device *hidpp,
423 struct hidpp_report *report)
425 return (hidpp->wireless_feature_index &&
426 (report->fap.feature_index == hidpp->wireless_feature_index)) ||
427 ((report->report_id == REPORT_ID_HIDPP_SHORT) &&
428 (report->rap.sub_id == 0x41));
432 * hidpp_prefix_name() prefixes the current given name with "Logitech ".
434 static void hidpp_prefix_name(char **name, int name_length)
436 #define PREFIX_LENGTH 9 /* "Logitech " */
441 if (name_length > PREFIX_LENGTH &&
442 strncmp(*name, "Logitech ", PREFIX_LENGTH) == 0)
443 /* The prefix has is already in the name */
446 new_length = PREFIX_LENGTH + name_length;
447 new_name = kzalloc(new_length, GFP_KERNEL);
451 snprintf(new_name, new_length, "Logitech %s", *name);
459 * hidpp_scroll_counter_handle_scroll() - Send high- and low-resolution scroll
460 * events given a high-resolution wheel
462 * @input_dev: Pointer to the input device
463 * @counter: a hid_scroll_counter struct describing the wheel.
464 * @hi_res_value: the movement of the wheel, in the mouse's high-resolution
467 * Given a high-resolution movement, this function converts the movement into
468 * fractions of 120 and emits high-resolution scroll events for the input
469 * device. It also uses the multiplier from &struct hid_scroll_counter to
470 * emit low-resolution scroll events when appropriate for
471 * backwards-compatibility with userspace input libraries.
473 static void hidpp_scroll_counter_handle_scroll(struct input_dev *input_dev,
474 struct hidpp_scroll_counter *counter,
477 int low_res_value, remainder, direction;
478 unsigned long long now, previous;
480 hi_res_value = hi_res_value * 120/counter->wheel_multiplier;
481 input_report_rel(input_dev, REL_WHEEL_HI_RES, hi_res_value);
483 remainder = counter->remainder;
484 direction = hi_res_value > 0 ? 1 : -1;
487 previous = counter->last_time;
488 counter->last_time = now;
490 * Reset the remainder after a period of inactivity or when the
491 * direction changes. This prevents the REL_WHEEL emulation point
492 * from sliding for devices that don't always provide the same
493 * number of movements per detent.
495 if (now - previous > 1000000000 || direction != counter->direction)
498 counter->direction = direction;
499 remainder += hi_res_value;
501 /* Some wheels will rest 7/8ths of a detent from the previous detent
502 * after slow movement, so we want the threshold for low-res events to
503 * be in the middle between two detents (e.g. after 4/8ths) as
504 * opposed to on the detents themselves (8/8ths).
506 if (abs(remainder) >= 60) {
507 /* Add (or subtract) 1 because we want to trigger when the wheel
508 * is half-way to the next detent (i.e. scroll 1 detent after a
509 * 1/2 detent movement, 2 detents after a 1 1/2 detent movement,
512 low_res_value = remainder / 120;
513 if (low_res_value == 0)
514 low_res_value = (hi_res_value > 0 ? 1 : -1);
515 input_report_rel(input_dev, REL_WHEEL, low_res_value);
516 remainder -= low_res_value * 120;
518 counter->remainder = remainder;
521 /* -------------------------------------------------------------------------- */
522 /* HIDP++ 1.0 commands */
523 /* -------------------------------------------------------------------------- */
525 #define HIDPP_SET_REGISTER 0x80
526 #define HIDPP_GET_REGISTER 0x81
527 #define HIDPP_SET_LONG_REGISTER 0x82
528 #define HIDPP_GET_LONG_REGISTER 0x83
531 * hidpp10_set_register - Modify a HID++ 1.0 register.
532 * @hidpp_dev: the device to set the register on.
533 * @register_address: the address of the register to modify.
534 * @byte: the byte of the register to modify. Should be less than 3.
535 * @mask: mask of the bits to modify
536 * @value: new values for the bits in mask
537 * Return: 0 if successful, otherwise a negative error code.
539 static int hidpp10_set_register(struct hidpp_device *hidpp_dev,
540 u8 register_address, u8 byte, u8 mask, u8 value)
542 struct hidpp_report response;
544 u8 params[3] = { 0 };
546 ret = hidpp_send_rap_command_sync(hidpp_dev,
547 REPORT_ID_HIDPP_SHORT,
554 memcpy(params, response.rap.params, 3);
556 params[byte] &= ~mask;
557 params[byte] |= value & mask;
559 return hidpp_send_rap_command_sync(hidpp_dev,
560 REPORT_ID_HIDPP_SHORT,
563 params, 3, &response);
566 #define HIDPP_REG_ENABLE_REPORTS 0x00
567 #define HIDPP_ENABLE_CONSUMER_REPORT BIT(0)
568 #define HIDPP_ENABLE_WHEEL_REPORT BIT(2)
569 #define HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT BIT(3)
570 #define HIDPP_ENABLE_BAT_REPORT BIT(4)
571 #define HIDPP_ENABLE_HWHEEL_REPORT BIT(5)
573 static int hidpp10_enable_battery_reporting(struct hidpp_device *hidpp_dev)
575 return hidpp10_set_register(hidpp_dev, HIDPP_REG_ENABLE_REPORTS, 0,
576 HIDPP_ENABLE_BAT_REPORT, HIDPP_ENABLE_BAT_REPORT);
579 #define HIDPP_REG_FEATURES 0x01
580 #define HIDPP_ENABLE_SPECIAL_BUTTON_FUNC BIT(1)
581 #define HIDPP_ENABLE_FAST_SCROLL BIT(6)
583 /* On HID++ 1.0 devices, high-res scroll was called "scrolling acceleration". */
584 static int hidpp10_enable_scrolling_acceleration(struct hidpp_device *hidpp_dev)
586 return hidpp10_set_register(hidpp_dev, HIDPP_REG_FEATURES, 0,
587 HIDPP_ENABLE_FAST_SCROLL, HIDPP_ENABLE_FAST_SCROLL);
590 #define HIDPP_REG_BATTERY_STATUS 0x07
592 static int hidpp10_battery_status_map_level(u8 param)
598 level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
601 level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
604 level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
607 level = POWER_SUPPLY_CAPACITY_LEVEL_HIGH;
610 level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
616 static int hidpp10_battery_status_map_status(u8 param)
622 /* discharging (in use) */
623 status = POWER_SUPPLY_STATUS_DISCHARGING;
625 case 0x21: /* (standard) charging */
626 case 0x24: /* fast charging */
627 case 0x25: /* slow charging */
628 status = POWER_SUPPLY_STATUS_CHARGING;
630 case 0x26: /* topping charge */
631 case 0x22: /* charge complete */
632 status = POWER_SUPPLY_STATUS_FULL;
634 case 0x20: /* unknown */
635 status = POWER_SUPPLY_STATUS_UNKNOWN;
638 * 0x01...0x1F = reserved (not charging)
639 * 0x23 = charging error
640 * 0x27..0xff = reserved
643 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
650 static int hidpp10_query_battery_status(struct hidpp_device *hidpp)
652 struct hidpp_report response;
655 ret = hidpp_send_rap_command_sync(hidpp,
656 REPORT_ID_HIDPP_SHORT,
658 HIDPP_REG_BATTERY_STATUS,
663 hidpp->battery.level =
664 hidpp10_battery_status_map_level(response.rap.params[0]);
665 status = hidpp10_battery_status_map_status(response.rap.params[1]);
666 hidpp->battery.status = status;
667 /* the capacity is only available when discharging or full */
668 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
669 status == POWER_SUPPLY_STATUS_FULL;
674 #define HIDPP_REG_BATTERY_MILEAGE 0x0D
676 static int hidpp10_battery_mileage_map_status(u8 param)
680 switch (param >> 6) {
682 /* discharging (in use) */
683 status = POWER_SUPPLY_STATUS_DISCHARGING;
685 case 0x01: /* charging */
686 status = POWER_SUPPLY_STATUS_CHARGING;
688 case 0x02: /* charge complete */
689 status = POWER_SUPPLY_STATUS_FULL;
692 * 0x03 = charging error
695 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
702 static int hidpp10_query_battery_mileage(struct hidpp_device *hidpp)
704 struct hidpp_report response;
707 ret = hidpp_send_rap_command_sync(hidpp,
708 REPORT_ID_HIDPP_SHORT,
710 HIDPP_REG_BATTERY_MILEAGE,
715 hidpp->battery.capacity = response.rap.params[0];
716 status = hidpp10_battery_mileage_map_status(response.rap.params[2]);
717 hidpp->battery.status = status;
718 /* the capacity is only available when discharging or full */
719 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
720 status == POWER_SUPPLY_STATUS_FULL;
725 static int hidpp10_battery_event(struct hidpp_device *hidpp, u8 *data, int size)
727 struct hidpp_report *report = (struct hidpp_report *)data;
728 int status, capacity, level;
731 if (report->report_id != REPORT_ID_HIDPP_SHORT)
734 switch (report->rap.sub_id) {
735 case HIDPP_REG_BATTERY_STATUS:
736 capacity = hidpp->battery.capacity;
737 level = hidpp10_battery_status_map_level(report->rawbytes[1]);
738 status = hidpp10_battery_status_map_status(report->rawbytes[2]);
740 case HIDPP_REG_BATTERY_MILEAGE:
741 capacity = report->rap.params[0];
742 level = hidpp->battery.level;
743 status = hidpp10_battery_mileage_map_status(report->rawbytes[3]);
749 changed = capacity != hidpp->battery.capacity ||
750 level != hidpp->battery.level ||
751 status != hidpp->battery.status;
753 /* the capacity is only available when discharging or full */
754 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
755 status == POWER_SUPPLY_STATUS_FULL;
758 hidpp->battery.level = level;
759 hidpp->battery.status = status;
760 if (hidpp->battery.ps)
761 power_supply_changed(hidpp->battery.ps);
767 #define HIDPP_REG_PAIRING_INFORMATION 0xB5
768 #define HIDPP_EXTENDED_PAIRING 0x30
769 #define HIDPP_DEVICE_NAME 0x40
771 static char *hidpp_unifying_get_name(struct hidpp_device *hidpp_dev)
773 struct hidpp_report response;
775 u8 params[1] = { HIDPP_DEVICE_NAME };
779 ret = hidpp_send_rap_command_sync(hidpp_dev,
780 REPORT_ID_HIDPP_SHORT,
781 HIDPP_GET_LONG_REGISTER,
782 HIDPP_REG_PAIRING_INFORMATION,
783 params, 1, &response);
787 len = response.rap.params[1];
789 if (2 + len > sizeof(response.rap.params))
792 if (len < 4) /* logitech devices are usually at least Xddd */
795 name = kzalloc(len + 1, GFP_KERNEL);
799 memcpy(name, &response.rap.params[2], len);
801 /* include the terminating '\0' */
802 hidpp_prefix_name(&name, len + 1);
807 static int hidpp_unifying_get_serial(struct hidpp_device *hidpp, u32 *serial)
809 struct hidpp_report response;
811 u8 params[1] = { HIDPP_EXTENDED_PAIRING };
813 ret = hidpp_send_rap_command_sync(hidpp,
814 REPORT_ID_HIDPP_SHORT,
815 HIDPP_GET_LONG_REGISTER,
816 HIDPP_REG_PAIRING_INFORMATION,
817 params, 1, &response);
822 * We don't care about LE or BE, we will output it as a string
823 * with %4phD, so we need to keep the order.
825 *serial = *((u32 *)&response.rap.params[1]);
829 static int hidpp_unifying_init(struct hidpp_device *hidpp)
831 struct hid_device *hdev = hidpp->hid_dev;
836 ret = hidpp_unifying_get_serial(hidpp, &serial);
840 snprintf(hdev->uniq, sizeof(hdev->uniq), "%04x-%4phD",
841 hdev->product, &serial);
842 dbg_hid("HID++ Unifying: Got serial: %s\n", hdev->uniq);
844 name = hidpp_unifying_get_name(hidpp);
848 snprintf(hdev->name, sizeof(hdev->name), "%s", name);
849 dbg_hid("HID++ Unifying: Got name: %s\n", name);
855 /* -------------------------------------------------------------------------- */
857 /* -------------------------------------------------------------------------- */
859 #define HIDPP_PAGE_ROOT 0x0000
860 #define HIDPP_PAGE_ROOT_IDX 0x00
862 #define CMD_ROOT_GET_FEATURE 0x00
863 #define CMD_ROOT_GET_PROTOCOL_VERSION 0x10
865 static int hidpp_root_get_feature(struct hidpp_device *hidpp, u16 feature,
866 u8 *feature_index, u8 *feature_type)
868 struct hidpp_report response;
870 u8 params[2] = { feature >> 8, feature & 0x00FF };
872 ret = hidpp_send_fap_command_sync(hidpp,
874 CMD_ROOT_GET_FEATURE,
875 params, 2, &response);
879 if (response.fap.params[0] == 0)
882 *feature_index = response.fap.params[0];
883 *feature_type = response.fap.params[1];
888 static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
890 const u8 ping_byte = 0x5a;
891 u8 ping_data[3] = { 0, 0, ping_byte };
892 struct hidpp_report response;
895 ret = hidpp_send_rap_command_sync(hidpp,
896 REPORT_ID_HIDPP_SHORT,
898 CMD_ROOT_GET_PROTOCOL_VERSION,
899 ping_data, sizeof(ping_data), &response);
901 if (ret == HIDPP_ERROR_INVALID_SUBID) {
902 hidpp->protocol_major = 1;
903 hidpp->protocol_minor = 0;
907 /* the device might not be connected */
908 if (ret == HIDPP_ERROR_RESOURCE_ERROR)
912 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
919 if (response.rap.params[2] != ping_byte) {
920 hid_err(hidpp->hid_dev, "%s: ping mismatch 0x%02x != 0x%02x\n",
921 __func__, response.rap.params[2], ping_byte);
925 hidpp->protocol_major = response.rap.params[0];
926 hidpp->protocol_minor = response.rap.params[1];
929 hid_info(hidpp->hid_dev, "HID++ %u.%u device connected.\n",
930 hidpp->protocol_major, hidpp->protocol_minor);
934 /* -------------------------------------------------------------------------- */
935 /* 0x0005: GetDeviceNameType */
936 /* -------------------------------------------------------------------------- */
938 #define HIDPP_PAGE_GET_DEVICE_NAME_TYPE 0x0005
940 #define CMD_GET_DEVICE_NAME_TYPE_GET_COUNT 0x00
941 #define CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME 0x10
942 #define CMD_GET_DEVICE_NAME_TYPE_GET_TYPE 0x20
944 static int hidpp_devicenametype_get_count(struct hidpp_device *hidpp,
945 u8 feature_index, u8 *nameLength)
947 struct hidpp_report response;
950 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
951 CMD_GET_DEVICE_NAME_TYPE_GET_COUNT, NULL, 0, &response);
954 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
961 *nameLength = response.fap.params[0];
966 static int hidpp_devicenametype_get_device_name(struct hidpp_device *hidpp,
967 u8 feature_index, u8 char_index, char *device_name, int len_buf)
969 struct hidpp_report response;
973 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
974 CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME, &char_index, 1,
978 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
985 switch (response.report_id) {
986 case REPORT_ID_HIDPP_VERY_LONG:
987 count = hidpp->very_long_report_length - 4;
989 case REPORT_ID_HIDPP_LONG:
990 count = HIDPP_REPORT_LONG_LENGTH - 4;
992 case REPORT_ID_HIDPP_SHORT:
993 count = HIDPP_REPORT_SHORT_LENGTH - 4;
1002 for (i = 0; i < count; i++)
1003 device_name[i] = response.fap.params[i];
1008 static char *hidpp_get_device_name(struct hidpp_device *hidpp)
1017 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_GET_DEVICE_NAME_TYPE,
1018 &feature_index, &feature_type);
1022 ret = hidpp_devicenametype_get_count(hidpp, feature_index,
1027 name = kzalloc(__name_length + 1, GFP_KERNEL);
1031 while (index < __name_length) {
1032 ret = hidpp_devicenametype_get_device_name(hidpp,
1033 feature_index, index, name + index,
1034 __name_length - index);
1042 /* include the terminating '\0' */
1043 hidpp_prefix_name(&name, __name_length + 1);
1048 /* -------------------------------------------------------------------------- */
1049 /* 0x1000: Battery level status */
1050 /* -------------------------------------------------------------------------- */
1052 #define HIDPP_PAGE_BATTERY_LEVEL_STATUS 0x1000
1054 #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS 0x00
1055 #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY 0x10
1057 #define EVENT_BATTERY_LEVEL_STATUS_BROADCAST 0x00
1059 #define FLAG_BATTERY_LEVEL_DISABLE_OSD BIT(0)
1060 #define FLAG_BATTERY_LEVEL_MILEAGE BIT(1)
1061 #define FLAG_BATTERY_LEVEL_RECHARGEABLE BIT(2)
1063 static int hidpp_map_battery_level(int capacity)
1066 return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
1068 * The spec says this should be < 31 but some devices report 30
1069 * with brand new batteries and Windows reports 30 as "Good".
1071 else if (capacity < 30)
1072 return POWER_SUPPLY_CAPACITY_LEVEL_LOW;
1073 else if (capacity < 81)
1074 return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
1075 return POWER_SUPPLY_CAPACITY_LEVEL_FULL;
1078 static int hidpp20_batterylevel_map_status_capacity(u8 data[3], int *capacity,
1084 *capacity = data[0];
1085 *next_capacity = data[1];
1086 *level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
1088 /* When discharging, we can rely on the device reported capacity.
1089 * For all other states the device reports 0 (unknown).
1092 case 0: /* discharging (in use) */
1093 status = POWER_SUPPLY_STATUS_DISCHARGING;
1094 *level = hidpp_map_battery_level(*capacity);
1096 case 1: /* recharging */
1097 status = POWER_SUPPLY_STATUS_CHARGING;
1099 case 2: /* charge in final stage */
1100 status = POWER_SUPPLY_STATUS_CHARGING;
1102 case 3: /* charge complete */
1103 status = POWER_SUPPLY_STATUS_FULL;
1104 *level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
1107 case 4: /* recharging below optimal speed */
1108 status = POWER_SUPPLY_STATUS_CHARGING;
1110 /* 5 = invalid battery type
1112 7 = other charging error */
1114 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1121 static int hidpp20_batterylevel_get_battery_capacity(struct hidpp_device *hidpp,
1128 struct hidpp_report response;
1130 u8 *params = (u8 *)response.fap.params;
1132 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1133 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS,
1134 NULL, 0, &response);
1135 /* Ignore these intermittent errors */
1136 if (ret == HIDPP_ERROR_RESOURCE_ERROR)
1139 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1146 *status = hidpp20_batterylevel_map_status_capacity(params, capacity,
1153 static int hidpp20_batterylevel_get_battery_info(struct hidpp_device *hidpp,
1156 struct hidpp_report response;
1158 u8 *params = (u8 *)response.fap.params;
1159 unsigned int level_count, flags;
1161 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1162 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY,
1163 NULL, 0, &response);
1165 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1172 level_count = params[0];
1175 if (level_count < 10 || !(flags & FLAG_BATTERY_LEVEL_MILEAGE))
1176 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS;
1178 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
1183 static int hidpp20_query_battery_info_1000(struct hidpp_device *hidpp)
1187 int status, capacity, next_capacity, level;
1189 if (hidpp->battery.feature_index == 0xff) {
1190 ret = hidpp_root_get_feature(hidpp,
1191 HIDPP_PAGE_BATTERY_LEVEL_STATUS,
1192 &hidpp->battery.feature_index,
1198 ret = hidpp20_batterylevel_get_battery_capacity(hidpp,
1199 hidpp->battery.feature_index,
1201 &next_capacity, &level);
1205 ret = hidpp20_batterylevel_get_battery_info(hidpp,
1206 hidpp->battery.feature_index);
1210 hidpp->battery.status = status;
1211 hidpp->battery.capacity = capacity;
1212 hidpp->battery.level = level;
1213 /* the capacity is only available when discharging or full */
1214 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
1215 status == POWER_SUPPLY_STATUS_FULL;
1220 static int hidpp20_battery_event_1000(struct hidpp_device *hidpp,
1223 struct hidpp_report *report = (struct hidpp_report *)data;
1224 int status, capacity, next_capacity, level;
1227 if (report->fap.feature_index != hidpp->battery.feature_index ||
1228 report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST)
1231 status = hidpp20_batterylevel_map_status_capacity(report->fap.params,
1236 /* the capacity is only available when discharging or full */
1237 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
1238 status == POWER_SUPPLY_STATUS_FULL;
1240 changed = capacity != hidpp->battery.capacity ||
1241 level != hidpp->battery.level ||
1242 status != hidpp->battery.status;
1245 hidpp->battery.level = level;
1246 hidpp->battery.capacity = capacity;
1247 hidpp->battery.status = status;
1248 if (hidpp->battery.ps)
1249 power_supply_changed(hidpp->battery.ps);
1255 /* -------------------------------------------------------------------------- */
1256 /* 0x1001: Battery voltage */
1257 /* -------------------------------------------------------------------------- */
1259 #define HIDPP_PAGE_BATTERY_VOLTAGE 0x1001
1261 #define CMD_BATTERY_VOLTAGE_GET_BATTERY_VOLTAGE 0x00
1263 #define EVENT_BATTERY_VOLTAGE_STATUS_BROADCAST 0x00
1265 static int hidpp20_battery_map_status_voltage(u8 data[3], int *voltage,
1266 int *level, int *charge_type)
1270 long flags = (long) data[2];
1271 *level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
1274 switch (flags & 0x07) {
1276 status = POWER_SUPPLY_STATUS_CHARGING;
1279 status = POWER_SUPPLY_STATUS_FULL;
1280 *level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
1283 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1286 status = POWER_SUPPLY_STATUS_UNKNOWN;
1290 status = POWER_SUPPLY_STATUS_DISCHARGING;
1292 *charge_type = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
1293 if (test_bit(3, &flags)) {
1294 *charge_type = POWER_SUPPLY_CHARGE_TYPE_FAST;
1296 if (test_bit(4, &flags)) {
1297 *charge_type = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
1299 if (test_bit(5, &flags)) {
1300 *level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
1303 *voltage = get_unaligned_be16(data);
1308 static int hidpp20_battery_get_battery_voltage(struct hidpp_device *hidpp,
1310 int *status, int *voltage,
1311 int *level, int *charge_type)
1313 struct hidpp_report response;
1315 u8 *params = (u8 *)response.fap.params;
1317 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1318 CMD_BATTERY_VOLTAGE_GET_BATTERY_VOLTAGE,
1319 NULL, 0, &response);
1322 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1329 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_VOLTAGE;
1331 *status = hidpp20_battery_map_status_voltage(params, voltage,
1332 level, charge_type);
1337 static int hidpp20_map_battery_capacity(struct hid_device *hid_dev, int voltage)
1339 /* NB: This voltage curve doesn't necessarily map perfectly to all
1340 * devices that implement the BATTERY_VOLTAGE feature. This is because
1341 * there are a few devices that use different battery technology.
1344 static const int voltages[] = {
1345 4186, 4156, 4143, 4133, 4122, 4113, 4103, 4094, 4086, 4075,
1346 4067, 4059, 4051, 4043, 4035, 4027, 4019, 4011, 4003, 3997,
1347 3989, 3983, 3976, 3969, 3961, 3955, 3949, 3942, 3935, 3929,
1348 3922, 3916, 3909, 3902, 3896, 3890, 3883, 3877, 3870, 3865,
1349 3859, 3853, 3848, 3842, 3837, 3833, 3828, 3824, 3819, 3815,
1350 3811, 3808, 3804, 3800, 3797, 3793, 3790, 3787, 3784, 3781,
1351 3778, 3775, 3772, 3770, 3767, 3764, 3762, 3759, 3757, 3754,
1352 3751, 3748, 3744, 3741, 3737, 3734, 3730, 3726, 3724, 3720,
1353 3717, 3714, 3710, 3706, 3702, 3697, 3693, 3688, 3683, 3677,
1354 3671, 3666, 3662, 3658, 3654, 3646, 3633, 3612, 3579, 3537
1359 BUILD_BUG_ON(ARRAY_SIZE(voltages) != 100);
1361 if (unlikely(voltage < 3500 || voltage >= 5000))
1362 hid_warn_once(hid_dev,
1363 "%s: possibly using the wrong voltage curve\n",
1366 for (i = 0; i < ARRAY_SIZE(voltages); i++) {
1367 if (voltage >= voltages[i])
1368 return ARRAY_SIZE(voltages) - i;
1374 static int hidpp20_query_battery_voltage_info(struct hidpp_device *hidpp)
1378 int status, voltage, level, charge_type;
1380 if (hidpp->battery.voltage_feature_index == 0xff) {
1381 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_BATTERY_VOLTAGE,
1382 &hidpp->battery.voltage_feature_index,
1388 ret = hidpp20_battery_get_battery_voltage(hidpp,
1389 hidpp->battery.voltage_feature_index,
1390 &status, &voltage, &level, &charge_type);
1395 hidpp->battery.status = status;
1396 hidpp->battery.voltage = voltage;
1397 hidpp->battery.capacity = hidpp20_map_battery_capacity(hidpp->hid_dev,
1399 hidpp->battery.level = level;
1400 hidpp->battery.charge_type = charge_type;
1401 hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING;
1406 static int hidpp20_battery_voltage_event(struct hidpp_device *hidpp,
1409 struct hidpp_report *report = (struct hidpp_report *)data;
1410 int status, voltage, level, charge_type;
1412 if (report->fap.feature_index != hidpp->battery.voltage_feature_index ||
1413 report->fap.funcindex_clientid != EVENT_BATTERY_VOLTAGE_STATUS_BROADCAST)
1416 status = hidpp20_battery_map_status_voltage(report->fap.params, &voltage,
1417 &level, &charge_type);
1419 hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING;
1421 if (voltage != hidpp->battery.voltage || status != hidpp->battery.status) {
1422 hidpp->battery.voltage = voltage;
1423 hidpp->battery.capacity = hidpp20_map_battery_capacity(hidpp->hid_dev,
1425 hidpp->battery.status = status;
1426 hidpp->battery.level = level;
1427 hidpp->battery.charge_type = charge_type;
1428 if (hidpp->battery.ps)
1429 power_supply_changed(hidpp->battery.ps);
1434 /* -------------------------------------------------------------------------- */
1435 /* 0x1004: Unified battery */
1436 /* -------------------------------------------------------------------------- */
1438 #define HIDPP_PAGE_UNIFIED_BATTERY 0x1004
1440 #define CMD_UNIFIED_BATTERY_GET_CAPABILITIES 0x00
1441 #define CMD_UNIFIED_BATTERY_GET_STATUS 0x10
1443 #define EVENT_UNIFIED_BATTERY_STATUS_EVENT 0x00
1445 #define FLAG_UNIFIED_BATTERY_LEVEL_CRITICAL BIT(0)
1446 #define FLAG_UNIFIED_BATTERY_LEVEL_LOW BIT(1)
1447 #define FLAG_UNIFIED_BATTERY_LEVEL_GOOD BIT(2)
1448 #define FLAG_UNIFIED_BATTERY_LEVEL_FULL BIT(3)
1450 #define FLAG_UNIFIED_BATTERY_FLAGS_RECHARGEABLE BIT(0)
1451 #define FLAG_UNIFIED_BATTERY_FLAGS_STATE_OF_CHARGE BIT(1)
1453 static int hidpp20_unifiedbattery_get_capabilities(struct hidpp_device *hidpp,
1456 struct hidpp_report response;
1458 u8 *params = (u8 *)response.fap.params;
1460 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS ||
1461 hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE) {
1462 /* we have already set the device capabilities, so let's skip */
1466 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1467 CMD_UNIFIED_BATTERY_GET_CAPABILITIES,
1468 NULL, 0, &response);
1469 /* Ignore these intermittent errors */
1470 if (ret == HIDPP_ERROR_RESOURCE_ERROR)
1473 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1481 * If the device supports state of charge (battery percentage) we won't
1482 * export the battery level information. there are 4 possible battery
1483 * levels and they all are optional, this means that the device might
1484 * not support any of them, we are just better off with the battery
1487 if (params[1] & FLAG_UNIFIED_BATTERY_FLAGS_STATE_OF_CHARGE) {
1488 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_PERCENTAGE;
1489 hidpp->battery.supported_levels_1004 = 0;
1491 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS;
1492 hidpp->battery.supported_levels_1004 = params[0];
1498 static int hidpp20_unifiedbattery_map_status(struct hidpp_device *hidpp,
1500 u8 external_power_status)
1504 switch (charging_status) {
1505 case 0: /* discharging */
1506 status = POWER_SUPPLY_STATUS_DISCHARGING;
1508 case 1: /* charging */
1509 case 2: /* charging slow */
1510 status = POWER_SUPPLY_STATUS_CHARGING;
1512 case 3: /* complete */
1513 status = POWER_SUPPLY_STATUS_FULL;
1516 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1517 hid_info(hidpp->hid_dev, "%s: charging error",
1521 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1528 static int hidpp20_unifiedbattery_map_level(struct hidpp_device *hidpp,
1531 /* cler unsupported level bits */
1532 battery_level &= hidpp->battery.supported_levels_1004;
1534 if (battery_level & FLAG_UNIFIED_BATTERY_LEVEL_FULL)
1535 return POWER_SUPPLY_CAPACITY_LEVEL_FULL;
1536 else if (battery_level & FLAG_UNIFIED_BATTERY_LEVEL_GOOD)
1537 return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
1538 else if (battery_level & FLAG_UNIFIED_BATTERY_LEVEL_LOW)
1539 return POWER_SUPPLY_CAPACITY_LEVEL_LOW;
1540 else if (battery_level & FLAG_UNIFIED_BATTERY_LEVEL_CRITICAL)
1541 return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
1543 return POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
1546 static int hidpp20_unifiedbattery_get_status(struct hidpp_device *hidpp,
1548 u8 *state_of_charge,
1552 struct hidpp_report response;
1554 u8 *params = (u8 *)response.fap.params;
1556 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1557 CMD_UNIFIED_BATTERY_GET_STATUS,
1558 NULL, 0, &response);
1559 /* Ignore these intermittent errors */
1560 if (ret == HIDPP_ERROR_RESOURCE_ERROR)
1563 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1570 *state_of_charge = params[0];
1571 *status = hidpp20_unifiedbattery_map_status(hidpp, params[2], params[3]);
1572 *level = hidpp20_unifiedbattery_map_level(hidpp, params[1]);
1577 static int hidpp20_query_battery_info_1004(struct hidpp_device *hidpp)
1584 if (hidpp->battery.feature_index == 0xff) {
1585 ret = hidpp_root_get_feature(hidpp,
1586 HIDPP_PAGE_UNIFIED_BATTERY,
1587 &hidpp->battery.feature_index,
1593 ret = hidpp20_unifiedbattery_get_capabilities(hidpp,
1594 hidpp->battery.feature_index);
1598 ret = hidpp20_unifiedbattery_get_status(hidpp,
1599 hidpp->battery.feature_index,
1606 hidpp->capabilities |= HIDPP_CAPABILITY_UNIFIED_BATTERY;
1607 hidpp->battery.capacity = state_of_charge;
1608 hidpp->battery.status = status;
1609 hidpp->battery.level = level;
1610 hidpp->battery.online = true;
1615 static int hidpp20_battery_event_1004(struct hidpp_device *hidpp,
1618 struct hidpp_report *report = (struct hidpp_report *)data;
1619 u8 *params = (u8 *)report->fap.params;
1620 int state_of_charge, status, level;
1623 if (report->fap.feature_index != hidpp->battery.feature_index ||
1624 report->fap.funcindex_clientid != EVENT_UNIFIED_BATTERY_STATUS_EVENT)
1627 state_of_charge = params[0];
1628 status = hidpp20_unifiedbattery_map_status(hidpp, params[2], params[3]);
1629 level = hidpp20_unifiedbattery_map_level(hidpp, params[1]);
1631 changed = status != hidpp->battery.status ||
1632 (state_of_charge != hidpp->battery.capacity &&
1633 hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE) ||
1634 (level != hidpp->battery.level &&
1635 hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS);
1638 hidpp->battery.capacity = state_of_charge;
1639 hidpp->battery.status = status;
1640 hidpp->battery.level = level;
1641 if (hidpp->battery.ps)
1642 power_supply_changed(hidpp->battery.ps);
1648 /* -------------------------------------------------------------------------- */
1649 /* Battery feature helpers */
1650 /* -------------------------------------------------------------------------- */
1652 static enum power_supply_property hidpp_battery_props[] = {
1653 POWER_SUPPLY_PROP_ONLINE,
1654 POWER_SUPPLY_PROP_STATUS,
1655 POWER_SUPPLY_PROP_SCOPE,
1656 POWER_SUPPLY_PROP_MODEL_NAME,
1657 POWER_SUPPLY_PROP_MANUFACTURER,
1658 POWER_SUPPLY_PROP_SERIAL_NUMBER,
1659 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY, */
1660 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY_LEVEL, */
1661 0, /* placeholder for POWER_SUPPLY_PROP_VOLTAGE_NOW, */
1664 static int hidpp_battery_get_property(struct power_supply *psy,
1665 enum power_supply_property psp,
1666 union power_supply_propval *val)
1668 struct hidpp_device *hidpp = power_supply_get_drvdata(psy);
1672 case POWER_SUPPLY_PROP_STATUS:
1673 val->intval = hidpp->battery.status;
1675 case POWER_SUPPLY_PROP_CAPACITY:
1676 val->intval = hidpp->battery.capacity;
1678 case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
1679 val->intval = hidpp->battery.level;
1681 case POWER_SUPPLY_PROP_SCOPE:
1682 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1684 case POWER_SUPPLY_PROP_ONLINE:
1685 val->intval = hidpp->battery.online;
1687 case POWER_SUPPLY_PROP_MODEL_NAME:
1688 if (!strncmp(hidpp->name, "Logitech ", 9))
1689 val->strval = hidpp->name + 9;
1691 val->strval = hidpp->name;
1693 case POWER_SUPPLY_PROP_MANUFACTURER:
1694 val->strval = "Logitech";
1696 case POWER_SUPPLY_PROP_SERIAL_NUMBER:
1697 val->strval = hidpp->hid_dev->uniq;
1699 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
1700 /* hardware reports voltage in mV. sysfs expects uV */
1701 val->intval = hidpp->battery.voltage * 1000;
1703 case POWER_SUPPLY_PROP_CHARGE_TYPE:
1704 val->intval = hidpp->battery.charge_type;
1714 /* -------------------------------------------------------------------------- */
1715 /* 0x1d4b: Wireless device status */
1716 /* -------------------------------------------------------------------------- */
1717 #define HIDPP_PAGE_WIRELESS_DEVICE_STATUS 0x1d4b
1719 static int hidpp_set_wireless_feature_index(struct hidpp_device *hidpp)
1724 ret = hidpp_root_get_feature(hidpp,
1725 HIDPP_PAGE_WIRELESS_DEVICE_STATUS,
1726 &hidpp->wireless_feature_index,
1732 /* -------------------------------------------------------------------------- */
1733 /* 0x2120: Hi-resolution scrolling */
1734 /* -------------------------------------------------------------------------- */
1736 #define HIDPP_PAGE_HI_RESOLUTION_SCROLLING 0x2120
1738 #define CMD_HI_RESOLUTION_SCROLLING_SET_HIGHRES_SCROLLING_MODE 0x10
1740 static int hidpp_hrs_set_highres_scrolling_mode(struct hidpp_device *hidpp,
1741 bool enabled, u8 *multiplier)
1747 struct hidpp_report response;
1749 ret = hidpp_root_get_feature(hidpp,
1750 HIDPP_PAGE_HI_RESOLUTION_SCROLLING,
1756 params[0] = enabled ? BIT(0) : 0;
1757 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1758 CMD_HI_RESOLUTION_SCROLLING_SET_HIGHRES_SCROLLING_MODE,
1759 params, sizeof(params), &response);
1762 *multiplier = response.fap.params[1];
1766 /* -------------------------------------------------------------------------- */
1767 /* 0x2121: HiRes Wheel */
1768 /* -------------------------------------------------------------------------- */
1770 #define HIDPP_PAGE_HIRES_WHEEL 0x2121
1772 #define CMD_HIRES_WHEEL_GET_WHEEL_CAPABILITY 0x00
1773 #define CMD_HIRES_WHEEL_SET_WHEEL_MODE 0x20
1775 static int hidpp_hrw_get_wheel_capability(struct hidpp_device *hidpp,
1781 struct hidpp_report response;
1783 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_HIRES_WHEEL,
1784 &feature_index, &feature_type);
1786 goto return_default;
1788 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1789 CMD_HIRES_WHEEL_GET_WHEEL_CAPABILITY,
1790 NULL, 0, &response);
1792 goto return_default;
1794 *multiplier = response.fap.params[0];
1797 hid_warn(hidpp->hid_dev,
1798 "Couldn't get wheel multiplier (error %d)\n", ret);
1802 static int hidpp_hrw_set_wheel_mode(struct hidpp_device *hidpp, bool invert,
1803 bool high_resolution, bool use_hidpp)
1809 struct hidpp_report response;
1811 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_HIRES_WHEEL,
1812 &feature_index, &feature_type);
1816 params[0] = (invert ? BIT(2) : 0) |
1817 (high_resolution ? BIT(1) : 0) |
1818 (use_hidpp ? BIT(0) : 0);
1820 return hidpp_send_fap_command_sync(hidpp, feature_index,
1821 CMD_HIRES_WHEEL_SET_WHEEL_MODE,
1822 params, sizeof(params), &response);
1825 /* -------------------------------------------------------------------------- */
1826 /* 0x4301: Solar Keyboard */
1827 /* -------------------------------------------------------------------------- */
1829 #define HIDPP_PAGE_SOLAR_KEYBOARD 0x4301
1831 #define CMD_SOLAR_SET_LIGHT_MEASURE 0x00
1833 #define EVENT_SOLAR_BATTERY_BROADCAST 0x00
1834 #define EVENT_SOLAR_BATTERY_LIGHT_MEASURE 0x10
1835 #define EVENT_SOLAR_CHECK_LIGHT_BUTTON 0x20
1837 static int hidpp_solar_request_battery_event(struct hidpp_device *hidpp)
1839 struct hidpp_report response;
1840 u8 params[2] = { 1, 1 };
1844 if (hidpp->battery.feature_index == 0xff) {
1845 ret = hidpp_root_get_feature(hidpp,
1846 HIDPP_PAGE_SOLAR_KEYBOARD,
1847 &hidpp->battery.solar_feature_index,
1853 ret = hidpp_send_fap_command_sync(hidpp,
1854 hidpp->battery.solar_feature_index,
1855 CMD_SOLAR_SET_LIGHT_MEASURE,
1856 params, 2, &response);
1858 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1865 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
1870 static int hidpp_solar_battery_event(struct hidpp_device *hidpp,
1873 struct hidpp_report *report = (struct hidpp_report *)data;
1874 int capacity, lux, status;
1877 function = report->fap.funcindex_clientid;
1880 if (report->fap.feature_index != hidpp->battery.solar_feature_index ||
1881 !(function == EVENT_SOLAR_BATTERY_BROADCAST ||
1882 function == EVENT_SOLAR_BATTERY_LIGHT_MEASURE ||
1883 function == EVENT_SOLAR_CHECK_LIGHT_BUTTON))
1886 capacity = report->fap.params[0];
1889 case EVENT_SOLAR_BATTERY_LIGHT_MEASURE:
1890 lux = (report->fap.params[1] << 8) | report->fap.params[2];
1892 status = POWER_SUPPLY_STATUS_CHARGING;
1894 status = POWER_SUPPLY_STATUS_DISCHARGING;
1896 case EVENT_SOLAR_CHECK_LIGHT_BUTTON:
1898 if (capacity < hidpp->battery.capacity)
1899 status = POWER_SUPPLY_STATUS_DISCHARGING;
1901 status = POWER_SUPPLY_STATUS_CHARGING;
1905 if (capacity == 100)
1906 status = POWER_SUPPLY_STATUS_FULL;
1908 hidpp->battery.online = true;
1909 if (capacity != hidpp->battery.capacity ||
1910 status != hidpp->battery.status) {
1911 hidpp->battery.capacity = capacity;
1912 hidpp->battery.status = status;
1913 if (hidpp->battery.ps)
1914 power_supply_changed(hidpp->battery.ps);
1920 /* -------------------------------------------------------------------------- */
1921 /* 0x6010: Touchpad FW items */
1922 /* -------------------------------------------------------------------------- */
1924 #define HIDPP_PAGE_TOUCHPAD_FW_ITEMS 0x6010
1926 #define CMD_TOUCHPAD_FW_ITEMS_SET 0x10
1928 struct hidpp_touchpad_fw_items {
1930 uint8_t desired_state;
1936 * send a set state command to the device by reading the current items->state
1937 * field. items is then filled with the current state.
1939 static int hidpp_touchpad_fw_items_set(struct hidpp_device *hidpp,
1941 struct hidpp_touchpad_fw_items *items)
1943 struct hidpp_report response;
1945 u8 *params = (u8 *)response.fap.params;
1947 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1948 CMD_TOUCHPAD_FW_ITEMS_SET, &items->state, 1, &response);
1951 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1958 items->presence = params[0];
1959 items->desired_state = params[1];
1960 items->state = params[2];
1961 items->persistent = params[3];
1966 /* -------------------------------------------------------------------------- */
1967 /* 0x6100: TouchPadRawXY */
1968 /* -------------------------------------------------------------------------- */
1970 #define HIDPP_PAGE_TOUCHPAD_RAW_XY 0x6100
1972 #define CMD_TOUCHPAD_GET_RAW_INFO 0x00
1973 #define CMD_TOUCHPAD_SET_RAW_REPORT_STATE 0x20
1975 #define EVENT_TOUCHPAD_RAW_XY 0x00
1977 #define TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT 0x01
1978 #define TOUCHPAD_RAW_XY_ORIGIN_UPPER_LEFT 0x03
1980 struct hidpp_touchpad_raw_info {
1991 struct hidpp_touchpad_raw_xy_finger {
2001 struct hidpp_touchpad_raw_xy {
2003 struct hidpp_touchpad_raw_xy_finger fingers[2];
2010 static int hidpp_touchpad_get_raw_info(struct hidpp_device *hidpp,
2011 u8 feature_index, struct hidpp_touchpad_raw_info *raw_info)
2013 struct hidpp_report response;
2015 u8 *params = (u8 *)response.fap.params;
2017 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
2018 CMD_TOUCHPAD_GET_RAW_INFO, NULL, 0, &response);
2021 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
2028 raw_info->x_size = get_unaligned_be16(¶ms[0]);
2029 raw_info->y_size = get_unaligned_be16(¶ms[2]);
2030 raw_info->z_range = params[4];
2031 raw_info->area_range = params[5];
2032 raw_info->maxcontacts = params[7];
2033 raw_info->origin = params[8];
2034 /* res is given in unit per inch */
2035 raw_info->res = get_unaligned_be16(¶ms[13]) * 2 / 51;
2040 static int hidpp_touchpad_set_raw_report_state(struct hidpp_device *hidpp_dev,
2041 u8 feature_index, bool send_raw_reports,
2042 bool sensor_enhanced_settings)
2044 struct hidpp_report response;
2048 * bit 0 - enable raw
2049 * bit 1 - 16bit Z, no area
2050 * bit 2 - enhanced sensitivity
2051 * bit 3 - width, height (4 bits each) instead of area
2052 * bit 4 - send raw + gestures (degrades smoothness)
2053 * remaining bits - reserved
2055 u8 params = send_raw_reports | (sensor_enhanced_settings << 2);
2057 return hidpp_send_fap_command_sync(hidpp_dev, feature_index,
2058 CMD_TOUCHPAD_SET_RAW_REPORT_STATE, ¶ms, 1, &response);
2061 static void hidpp_touchpad_touch_event(u8 *data,
2062 struct hidpp_touchpad_raw_xy_finger *finger)
2064 u8 x_m = data[0] << 2;
2065 u8 y_m = data[2] << 2;
2067 finger->x = x_m << 6 | data[1];
2068 finger->y = y_m << 6 | data[3];
2070 finger->contact_type = data[0] >> 6;
2071 finger->contact_status = data[2] >> 6;
2073 finger->z = data[4];
2074 finger->area = data[5];
2075 finger->finger_id = data[6] >> 4;
2078 static void hidpp_touchpad_raw_xy_event(struct hidpp_device *hidpp_dev,
2079 u8 *data, struct hidpp_touchpad_raw_xy *raw_xy)
2081 memset(raw_xy, 0, sizeof(struct hidpp_touchpad_raw_xy));
2082 raw_xy->end_of_frame = data[8] & 0x01;
2083 raw_xy->spurious_flag = (data[8] >> 1) & 0x01;
2084 raw_xy->finger_count = data[15] & 0x0f;
2085 raw_xy->button = (data[8] >> 2) & 0x01;
2087 if (raw_xy->finger_count) {
2088 hidpp_touchpad_touch_event(&data[2], &raw_xy->fingers[0]);
2089 hidpp_touchpad_touch_event(&data[9], &raw_xy->fingers[1]);
2093 /* -------------------------------------------------------------------------- */
2094 /* 0x8123: Force feedback support */
2095 /* -------------------------------------------------------------------------- */
2097 #define HIDPP_FF_GET_INFO 0x01
2098 #define HIDPP_FF_RESET_ALL 0x11
2099 #define HIDPP_FF_DOWNLOAD_EFFECT 0x21
2100 #define HIDPP_FF_SET_EFFECT_STATE 0x31
2101 #define HIDPP_FF_DESTROY_EFFECT 0x41
2102 #define HIDPP_FF_GET_APERTURE 0x51
2103 #define HIDPP_FF_SET_APERTURE 0x61
2104 #define HIDPP_FF_GET_GLOBAL_GAINS 0x71
2105 #define HIDPP_FF_SET_GLOBAL_GAINS 0x81
2107 #define HIDPP_FF_EFFECT_STATE_GET 0x00
2108 #define HIDPP_FF_EFFECT_STATE_STOP 0x01
2109 #define HIDPP_FF_EFFECT_STATE_PLAY 0x02
2110 #define HIDPP_FF_EFFECT_STATE_PAUSE 0x03
2112 #define HIDPP_FF_EFFECT_CONSTANT 0x00
2113 #define HIDPP_FF_EFFECT_PERIODIC_SINE 0x01
2114 #define HIDPP_FF_EFFECT_PERIODIC_SQUARE 0x02
2115 #define HIDPP_FF_EFFECT_PERIODIC_TRIANGLE 0x03
2116 #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP 0x04
2117 #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN 0x05
2118 #define HIDPP_FF_EFFECT_SPRING 0x06
2119 #define HIDPP_FF_EFFECT_DAMPER 0x07
2120 #define HIDPP_FF_EFFECT_FRICTION 0x08
2121 #define HIDPP_FF_EFFECT_INERTIA 0x09
2122 #define HIDPP_FF_EFFECT_RAMP 0x0A
2124 #define HIDPP_FF_EFFECT_AUTOSTART 0x80
2126 #define HIDPP_FF_EFFECTID_NONE -1
2127 #define HIDPP_FF_EFFECTID_AUTOCENTER -2
2128 #define HIDPP_AUTOCENTER_PARAMS_LENGTH 18
2130 #define HIDPP_FF_MAX_PARAMS 20
2131 #define HIDPP_FF_RESERVED_SLOTS 1
2133 struct hidpp_ff_private_data {
2134 struct hidpp_device *hidpp;
2142 struct workqueue_struct *wq;
2143 atomic_t workqueue_size;
2146 struct hidpp_ff_work_data {
2147 struct work_struct work;
2148 struct hidpp_ff_private_data *data;
2151 u8 params[HIDPP_FF_MAX_PARAMS];
2155 static const signed short hidpp_ff_effects[] = {
2170 static const signed short hidpp_ff_effects_v2[] = {
2177 static const u8 HIDPP_FF_CONDITION_CMDS[] = {
2178 HIDPP_FF_EFFECT_SPRING,
2179 HIDPP_FF_EFFECT_FRICTION,
2180 HIDPP_FF_EFFECT_DAMPER,
2181 HIDPP_FF_EFFECT_INERTIA
2184 static const char *HIDPP_FF_CONDITION_NAMES[] = {
2192 static u8 hidpp_ff_find_effect(struct hidpp_ff_private_data *data, int effect_id)
2196 for (i = 0; i < data->num_effects; i++)
2197 if (data->effect_ids[i] == effect_id)
2203 static void hidpp_ff_work_handler(struct work_struct *w)
2205 struct hidpp_ff_work_data *wd = container_of(w, struct hidpp_ff_work_data, work);
2206 struct hidpp_ff_private_data *data = wd->data;
2207 struct hidpp_report response;
2211 /* add slot number if needed */
2212 switch (wd->effect_id) {
2213 case HIDPP_FF_EFFECTID_AUTOCENTER:
2214 wd->params[0] = data->slot_autocenter;
2216 case HIDPP_FF_EFFECTID_NONE:
2217 /* leave slot as zero */
2220 /* find current slot for effect */
2221 wd->params[0] = hidpp_ff_find_effect(data, wd->effect_id);
2225 /* send command and wait for reply */
2226 ret = hidpp_send_fap_command_sync(data->hidpp, data->feature_index,
2227 wd->command, wd->params, wd->size, &response);
2230 hid_err(data->hidpp->hid_dev, "Failed to send command to device!\n");
2234 /* parse return data */
2235 switch (wd->command) {
2236 case HIDPP_FF_DOWNLOAD_EFFECT:
2237 slot = response.fap.params[0];
2238 if (slot > 0 && slot <= data->num_effects) {
2239 if (wd->effect_id >= 0)
2240 /* regular effect uploaded */
2241 data->effect_ids[slot-1] = wd->effect_id;
2242 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
2243 /* autocenter spring uploaded */
2244 data->slot_autocenter = slot;
2247 case HIDPP_FF_DESTROY_EFFECT:
2248 if (wd->effect_id >= 0)
2249 /* regular effect destroyed */
2250 data->effect_ids[wd->params[0]-1] = -1;
2251 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
2252 /* autocenter spring destoyed */
2253 data->slot_autocenter = 0;
2255 case HIDPP_FF_SET_GLOBAL_GAINS:
2256 data->gain = (wd->params[0] << 8) + wd->params[1];
2258 case HIDPP_FF_SET_APERTURE:
2259 data->range = (wd->params[0] << 8) + wd->params[1];
2262 /* no action needed */
2267 atomic_dec(&data->workqueue_size);
2271 static int hidpp_ff_queue_work(struct hidpp_ff_private_data *data, int effect_id, u8 command, u8 *params, u8 size)
2273 struct hidpp_ff_work_data *wd = kzalloc(sizeof(*wd), GFP_KERNEL);
2279 INIT_WORK(&wd->work, hidpp_ff_work_handler);
2282 wd->effect_id = effect_id;
2283 wd->command = command;
2285 memcpy(wd->params, params, size);
2287 s = atomic_inc_return(&data->workqueue_size);
2288 queue_work(data->wq, &wd->work);
2290 /* warn about excessive queue size */
2291 if (s >= 20 && s % 20 == 0)
2292 hid_warn(data->hidpp->hid_dev, "Force feedback command queue contains %d commands, causing substantial delays!", s);
2297 static int hidpp_ff_upload_effect(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old)
2299 struct hidpp_ff_private_data *data = dev->ff->private;
2304 /* set common parameters */
2305 params[2] = effect->replay.length >> 8;
2306 params[3] = effect->replay.length & 255;
2307 params[4] = effect->replay.delay >> 8;
2308 params[5] = effect->replay.delay & 255;
2310 switch (effect->type) {
2312 force = (effect->u.constant.level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
2313 params[1] = HIDPP_FF_EFFECT_CONSTANT;
2314 params[6] = force >> 8;
2315 params[7] = force & 255;
2316 params[8] = effect->u.constant.envelope.attack_level >> 7;
2317 params[9] = effect->u.constant.envelope.attack_length >> 8;
2318 params[10] = effect->u.constant.envelope.attack_length & 255;
2319 params[11] = effect->u.constant.envelope.fade_level >> 7;
2320 params[12] = effect->u.constant.envelope.fade_length >> 8;
2321 params[13] = effect->u.constant.envelope.fade_length & 255;
2323 dbg_hid("Uploading constant force level=%d in dir %d = %d\n",
2324 effect->u.constant.level,
2325 effect->direction, force);
2326 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
2327 effect->u.constant.envelope.attack_level,
2328 effect->u.constant.envelope.attack_length,
2329 effect->u.constant.envelope.fade_level,
2330 effect->u.constant.envelope.fade_length);
2334 switch (effect->u.periodic.waveform) {
2336 params[1] = HIDPP_FF_EFFECT_PERIODIC_SINE;
2339 params[1] = HIDPP_FF_EFFECT_PERIODIC_SQUARE;
2342 params[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP;
2345 params[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN;
2348 params[1] = HIDPP_FF_EFFECT_PERIODIC_TRIANGLE;
2351 hid_err(data->hidpp->hid_dev, "Unexpected periodic waveform type %i!\n", effect->u.periodic.waveform);
2354 force = (effect->u.periodic.magnitude * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
2355 params[6] = effect->u.periodic.magnitude >> 8;
2356 params[7] = effect->u.periodic.magnitude & 255;
2357 params[8] = effect->u.periodic.offset >> 8;
2358 params[9] = effect->u.periodic.offset & 255;
2359 params[10] = effect->u.periodic.period >> 8;
2360 params[11] = effect->u.periodic.period & 255;
2361 params[12] = effect->u.periodic.phase >> 8;
2362 params[13] = effect->u.periodic.phase & 255;
2363 params[14] = effect->u.periodic.envelope.attack_level >> 7;
2364 params[15] = effect->u.periodic.envelope.attack_length >> 8;
2365 params[16] = effect->u.periodic.envelope.attack_length & 255;
2366 params[17] = effect->u.periodic.envelope.fade_level >> 7;
2367 params[18] = effect->u.periodic.envelope.fade_length >> 8;
2368 params[19] = effect->u.periodic.envelope.fade_length & 255;
2370 dbg_hid("Uploading periodic force mag=%d/dir=%d, offset=%d, period=%d ms, phase=%d\n",
2371 effect->u.periodic.magnitude, effect->direction,
2372 effect->u.periodic.offset,
2373 effect->u.periodic.period,
2374 effect->u.periodic.phase);
2375 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
2376 effect->u.periodic.envelope.attack_level,
2377 effect->u.periodic.envelope.attack_length,
2378 effect->u.periodic.envelope.fade_level,
2379 effect->u.periodic.envelope.fade_length);
2383 params[1] = HIDPP_FF_EFFECT_RAMP;
2384 force = (effect->u.ramp.start_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
2385 params[6] = force >> 8;
2386 params[7] = force & 255;
2387 force = (effect->u.ramp.end_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
2388 params[8] = force >> 8;
2389 params[9] = force & 255;
2390 params[10] = effect->u.ramp.envelope.attack_level >> 7;
2391 params[11] = effect->u.ramp.envelope.attack_length >> 8;
2392 params[12] = effect->u.ramp.envelope.attack_length & 255;
2393 params[13] = effect->u.ramp.envelope.fade_level >> 7;
2394 params[14] = effect->u.ramp.envelope.fade_length >> 8;
2395 params[15] = effect->u.ramp.envelope.fade_length & 255;
2397 dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n",
2398 effect->u.ramp.start_level,
2399 effect->u.ramp.end_level,
2400 effect->direction, force);
2401 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
2402 effect->u.ramp.envelope.attack_level,
2403 effect->u.ramp.envelope.attack_length,
2404 effect->u.ramp.envelope.fade_level,
2405 effect->u.ramp.envelope.fade_length);
2411 params[1] = HIDPP_FF_CONDITION_CMDS[effect->type - FF_SPRING];
2412 params[6] = effect->u.condition[0].left_saturation >> 9;
2413 params[7] = (effect->u.condition[0].left_saturation >> 1) & 255;
2414 params[8] = effect->u.condition[0].left_coeff >> 8;
2415 params[9] = effect->u.condition[0].left_coeff & 255;
2416 params[10] = effect->u.condition[0].deadband >> 9;
2417 params[11] = (effect->u.condition[0].deadband >> 1) & 255;
2418 params[12] = effect->u.condition[0].center >> 8;
2419 params[13] = effect->u.condition[0].center & 255;
2420 params[14] = effect->u.condition[0].right_coeff >> 8;
2421 params[15] = effect->u.condition[0].right_coeff & 255;
2422 params[16] = effect->u.condition[0].right_saturation >> 9;
2423 params[17] = (effect->u.condition[0].right_saturation >> 1) & 255;
2425 dbg_hid("Uploading %s force left coeff=%d, left sat=%d, right coeff=%d, right sat=%d\n",
2426 HIDPP_FF_CONDITION_NAMES[effect->type - FF_SPRING],
2427 effect->u.condition[0].left_coeff,
2428 effect->u.condition[0].left_saturation,
2429 effect->u.condition[0].right_coeff,
2430 effect->u.condition[0].right_saturation);
2431 dbg_hid(" deadband=%d, center=%d\n",
2432 effect->u.condition[0].deadband,
2433 effect->u.condition[0].center);
2436 hid_err(data->hidpp->hid_dev, "Unexpected force type %i!\n", effect->type);
2440 return hidpp_ff_queue_work(data, effect->id, HIDPP_FF_DOWNLOAD_EFFECT, params, size);
2443 static int hidpp_ff_playback(struct input_dev *dev, int effect_id, int value)
2445 struct hidpp_ff_private_data *data = dev->ff->private;
2448 params[1] = value ? HIDPP_FF_EFFECT_STATE_PLAY : HIDPP_FF_EFFECT_STATE_STOP;
2450 dbg_hid("St%sing playback of effect %d.\n", value?"art":"opp", effect_id);
2452 return hidpp_ff_queue_work(data, effect_id, HIDPP_FF_SET_EFFECT_STATE, params, ARRAY_SIZE(params));
2455 static int hidpp_ff_erase_effect(struct input_dev *dev, int effect_id)
2457 struct hidpp_ff_private_data *data = dev->ff->private;
2460 dbg_hid("Erasing effect %d.\n", effect_id);
2462 return hidpp_ff_queue_work(data, effect_id, HIDPP_FF_DESTROY_EFFECT, &slot, 1);
2465 static void hidpp_ff_set_autocenter(struct input_dev *dev, u16 magnitude)
2467 struct hidpp_ff_private_data *data = dev->ff->private;
2468 u8 params[HIDPP_AUTOCENTER_PARAMS_LENGTH];
2470 dbg_hid("Setting autocenter to %d.\n", magnitude);
2472 /* start a standard spring effect */
2473 params[1] = HIDPP_FF_EFFECT_SPRING | HIDPP_FF_EFFECT_AUTOSTART;
2474 /* zero delay and duration */
2475 params[2] = params[3] = params[4] = params[5] = 0;
2476 /* set coeff to 25% of saturation */
2477 params[8] = params[14] = magnitude >> 11;
2478 params[9] = params[15] = (magnitude >> 3) & 255;
2479 params[6] = params[16] = magnitude >> 9;
2480 params[7] = params[17] = (magnitude >> 1) & 255;
2481 /* zero deadband and center */
2482 params[10] = params[11] = params[12] = params[13] = 0;
2484 hidpp_ff_queue_work(data, HIDPP_FF_EFFECTID_AUTOCENTER, HIDPP_FF_DOWNLOAD_EFFECT, params, ARRAY_SIZE(params));
2487 static void hidpp_ff_set_gain(struct input_dev *dev, u16 gain)
2489 struct hidpp_ff_private_data *data = dev->ff->private;
2492 dbg_hid("Setting gain to %d.\n", gain);
2494 params[0] = gain >> 8;
2495 params[1] = gain & 255;
2496 params[2] = 0; /* no boost */
2499 hidpp_ff_queue_work(data, HIDPP_FF_EFFECTID_NONE, HIDPP_FF_SET_GLOBAL_GAINS, params, ARRAY_SIZE(params));
2502 static ssize_t hidpp_ff_range_show(struct device *dev, struct device_attribute *attr, char *buf)
2504 struct hid_device *hid = to_hid_device(dev);
2505 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2506 struct input_dev *idev = hidinput->input;
2507 struct hidpp_ff_private_data *data = idev->ff->private;
2509 return scnprintf(buf, PAGE_SIZE, "%u\n", data->range);
2512 static ssize_t hidpp_ff_range_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
2514 struct hid_device *hid = to_hid_device(dev);
2515 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2516 struct input_dev *idev = hidinput->input;
2517 struct hidpp_ff_private_data *data = idev->ff->private;
2519 int range = simple_strtoul(buf, NULL, 10);
2521 range = clamp(range, 180, 900);
2523 params[0] = range >> 8;
2524 params[1] = range & 0x00FF;
2526 hidpp_ff_queue_work(data, -1, HIDPP_FF_SET_APERTURE, params, ARRAY_SIZE(params));
2531 static DEVICE_ATTR(range, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, hidpp_ff_range_show, hidpp_ff_range_store);
2533 static void hidpp_ff_destroy(struct ff_device *ff)
2535 struct hidpp_ff_private_data *data = ff->private;
2536 struct hid_device *hid = data->hidpp->hid_dev;
2538 hid_info(hid, "Unloading HID++ force feedback.\n");
2540 device_remove_file(&hid->dev, &dev_attr_range);
2541 destroy_workqueue(data->wq);
2542 kfree(data->effect_ids);
2545 static int hidpp_ff_init(struct hidpp_device *hidpp,
2546 struct hidpp_ff_private_data *data)
2548 struct hid_device *hid = hidpp->hid_dev;
2549 struct hid_input *hidinput;
2550 struct input_dev *dev;
2551 const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
2552 const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice);
2553 struct ff_device *ff;
2554 int error, j, num_slots = data->num_effects;
2557 if (list_empty(&hid->inputs)) {
2558 hid_err(hid, "no inputs found\n");
2561 hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2562 dev = hidinput->input;
2565 hid_err(hid, "Struct input_dev not set!\n");
2569 /* Get firmware release */
2570 version = bcdDevice & 255;
2572 /* Set supported force feedback capabilities */
2573 for (j = 0; hidpp_ff_effects[j] >= 0; j++)
2574 set_bit(hidpp_ff_effects[j], dev->ffbit);
2576 for (j = 0; hidpp_ff_effects_v2[j] >= 0; j++)
2577 set_bit(hidpp_ff_effects_v2[j], dev->ffbit);
2579 error = input_ff_create(dev, num_slots);
2582 hid_err(dev, "Failed to create FF device!\n");
2586 * Create a copy of passed data, so we can transfer memory
2587 * ownership to FF core
2589 data = kmemdup(data, sizeof(*data), GFP_KERNEL);
2592 data->effect_ids = kcalloc(num_slots, sizeof(int), GFP_KERNEL);
2593 if (!data->effect_ids) {
2597 data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue");
2599 kfree(data->effect_ids);
2604 data->hidpp = hidpp;
2605 data->version = version;
2606 for (j = 0; j < num_slots; j++)
2607 data->effect_ids[j] = -1;
2612 ff->upload = hidpp_ff_upload_effect;
2613 ff->erase = hidpp_ff_erase_effect;
2614 ff->playback = hidpp_ff_playback;
2615 ff->set_gain = hidpp_ff_set_gain;
2616 ff->set_autocenter = hidpp_ff_set_autocenter;
2617 ff->destroy = hidpp_ff_destroy;
2619 /* Create sysfs interface */
2620 error = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range);
2622 hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d!\n", error);
2624 /* init the hardware command queue */
2625 atomic_set(&data->workqueue_size, 0);
2627 hid_info(hid, "Force feedback support loaded (firmware release %d).\n",
2633 /* ************************************************************************** */
2635 /* Device Support */
2637 /* ************************************************************************** */
2639 /* -------------------------------------------------------------------------- */
2640 /* Touchpad HID++ devices */
2641 /* -------------------------------------------------------------------------- */
2643 #define WTP_MANUAL_RESOLUTION 39
2648 u8 mt_feature_index;
2649 u8 button_feature_index;
2652 unsigned int resolution;
2655 static int wtp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
2656 struct hid_field *field, struct hid_usage *usage,
2657 unsigned long **bit, int *max)
2662 static void wtp_populate_input(struct hidpp_device *hidpp,
2663 struct input_dev *input_dev)
2665 struct wtp_data *wd = hidpp->private_data;
2667 __set_bit(EV_ABS, input_dev->evbit);
2668 __set_bit(EV_KEY, input_dev->evbit);
2669 __clear_bit(EV_REL, input_dev->evbit);
2670 __clear_bit(EV_LED, input_dev->evbit);
2672 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0);
2673 input_abs_set_res(input_dev, ABS_MT_POSITION_X, wd->resolution);
2674 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0);
2675 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, wd->resolution);
2677 /* Max pressure is not given by the devices, pick one */
2678 input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 50, 0, 0);
2680 input_set_capability(input_dev, EV_KEY, BTN_LEFT);
2682 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS)
2683 input_set_capability(input_dev, EV_KEY, BTN_RIGHT);
2685 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
2687 input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER |
2688 INPUT_MT_DROP_UNUSED);
2691 static void wtp_touch_event(struct hidpp_device *hidpp,
2692 struct hidpp_touchpad_raw_xy_finger *touch_report)
2694 struct wtp_data *wd = hidpp->private_data;
2697 if (!touch_report->finger_id || touch_report->contact_type)
2698 /* no actual data */
2701 slot = input_mt_get_slot_by_key(hidpp->input, touch_report->finger_id);
2703 input_mt_slot(hidpp->input, slot);
2704 input_mt_report_slot_state(hidpp->input, MT_TOOL_FINGER,
2705 touch_report->contact_status);
2706 if (touch_report->contact_status) {
2707 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_X,
2709 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_Y,
2710 wd->flip_y ? wd->y_size - touch_report->y :
2712 input_event(hidpp->input, EV_ABS, ABS_MT_PRESSURE,
2713 touch_report->area);
2717 static void wtp_send_raw_xy_event(struct hidpp_device *hidpp,
2718 struct hidpp_touchpad_raw_xy *raw)
2722 for (i = 0; i < 2; i++)
2723 wtp_touch_event(hidpp, &(raw->fingers[i]));
2725 if (raw->end_of_frame &&
2726 !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS))
2727 input_event(hidpp->input, EV_KEY, BTN_LEFT, raw->button);
2729 if (raw->end_of_frame || raw->finger_count <= 2) {
2730 input_mt_sync_frame(hidpp->input);
2731 input_sync(hidpp->input);
2735 static int wtp_mouse_raw_xy_event(struct hidpp_device *hidpp, u8 *data)
2737 struct wtp_data *wd = hidpp->private_data;
2738 u8 c1_area = ((data[7] & 0xf) * (data[7] & 0xf) +
2739 (data[7] >> 4) * (data[7] >> 4)) / 2;
2740 u8 c2_area = ((data[13] & 0xf) * (data[13] & 0xf) +
2741 (data[13] >> 4) * (data[13] >> 4)) / 2;
2742 struct hidpp_touchpad_raw_xy raw = {
2743 .timestamp = data[1],
2747 .contact_status = !!data[7],
2748 .x = get_unaligned_le16(&data[3]),
2749 .y = get_unaligned_le16(&data[5]),
2752 .finger_id = data[2],
2755 .contact_status = !!data[13],
2756 .x = get_unaligned_le16(&data[9]),
2757 .y = get_unaligned_le16(&data[11]),
2760 .finger_id = data[8],
2763 .finger_count = wd->maxcontacts,
2765 .end_of_frame = (data[0] >> 7) == 0,
2766 .button = data[0] & 0x01,
2769 wtp_send_raw_xy_event(hidpp, &raw);
2774 static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size)
2776 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2777 struct wtp_data *wd = hidpp->private_data;
2778 struct hidpp_report *report = (struct hidpp_report *)data;
2779 struct hidpp_touchpad_raw_xy raw;
2781 if (!wd || !hidpp->input)
2787 hid_err(hdev, "Received HID report of bad size (%d)",
2791 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) {
2792 input_event(hidpp->input, EV_KEY, BTN_LEFT,
2793 !!(data[1] & 0x01));
2794 input_event(hidpp->input, EV_KEY, BTN_RIGHT,
2795 !!(data[1] & 0x02));
2796 input_sync(hidpp->input);
2801 return wtp_mouse_raw_xy_event(hidpp, &data[7]);
2803 case REPORT_ID_HIDPP_LONG:
2804 /* size is already checked in hidpp_raw_event. */
2805 if ((report->fap.feature_index != wd->mt_feature_index) ||
2806 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY))
2808 hidpp_touchpad_raw_xy_event(hidpp, data + 4, &raw);
2810 wtp_send_raw_xy_event(hidpp, &raw);
2817 static int wtp_get_config(struct hidpp_device *hidpp)
2819 struct wtp_data *wd = hidpp->private_data;
2820 struct hidpp_touchpad_raw_info raw_info = {0};
2824 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_TOUCHPAD_RAW_XY,
2825 &wd->mt_feature_index, &feature_type);
2827 /* means that the device is not powered up */
2830 ret = hidpp_touchpad_get_raw_info(hidpp, wd->mt_feature_index,
2835 wd->x_size = raw_info.x_size;
2836 wd->y_size = raw_info.y_size;
2837 wd->maxcontacts = raw_info.maxcontacts;
2838 wd->flip_y = raw_info.origin == TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT;
2839 wd->resolution = raw_info.res;
2840 if (!wd->resolution)
2841 wd->resolution = WTP_MANUAL_RESOLUTION;
2846 static int wtp_allocate(struct hid_device *hdev, const struct hid_device_id *id)
2848 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2849 struct wtp_data *wd;
2851 wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data),
2856 hidpp->private_data = wd;
2861 static int wtp_connect(struct hid_device *hdev, bool connected)
2863 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2864 struct wtp_data *wd = hidpp->private_data;
2868 ret = wtp_get_config(hidpp);
2870 hid_err(hdev, "Can not get wtp config: %d\n", ret);
2875 return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index,
2879 /* ------------------------------------------------------------------------- */
2880 /* Logitech M560 devices */
2881 /* ------------------------------------------------------------------------- */
2884 * Logitech M560 protocol overview
2886 * The Logitech M560 mouse, is designed for windows 8. When the middle and/or
2887 * the sides buttons are pressed, it sends some keyboard keys events
2888 * instead of buttons ones.
2889 * To complicate things further, the middle button keys sequence
2890 * is different from the odd press and the even press.
2892 * forward button -> Super_R
2893 * backward button -> Super_L+'d' (press only)
2894 * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
2895 * 2nd time: left-click (press only)
2896 * NB: press-only means that when the button is pressed, the
2897 * KeyPress/ButtonPress and KeyRelease/ButtonRelease events are generated
2898 * together sequentially; instead when the button is released, no event is
2902 * 10<xx>0a 3500af03 (where <xx> is the mouse id),
2903 * the mouse reacts differently:
2904 * - it never sends a keyboard key event
2905 * - for the three mouse button it sends:
2906 * middle button press 11<xx>0a 3500af00...
2907 * side 1 button (forward) press 11<xx>0a 3500b000...
2908 * side 2 button (backward) press 11<xx>0a 3500ae00...
2909 * middle/side1/side2 button release 11<xx>0a 35000000...
2912 static const u8 m560_config_parameter[] = {0x00, 0xaf, 0x03};
2914 /* how buttons are mapped in the report */
2915 #define M560_MOUSE_BTN_LEFT 0x01
2916 #define M560_MOUSE_BTN_RIGHT 0x02
2917 #define M560_MOUSE_BTN_WHEEL_LEFT 0x08
2918 #define M560_MOUSE_BTN_WHEEL_RIGHT 0x10
2920 #define M560_SUB_ID 0x0a
2921 #define M560_BUTTON_MODE_REGISTER 0x35
2923 static int m560_send_config_command(struct hid_device *hdev, bool connected)
2925 struct hidpp_report response;
2926 struct hidpp_device *hidpp_dev;
2928 hidpp_dev = hid_get_drvdata(hdev);
2930 return hidpp_send_rap_command_sync(
2932 REPORT_ID_HIDPP_SHORT,
2934 M560_BUTTON_MODE_REGISTER,
2935 (u8 *)m560_config_parameter,
2936 sizeof(m560_config_parameter),
2941 static int m560_raw_event(struct hid_device *hdev, u8 *data, int size)
2943 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2946 if (!hidpp->input) {
2947 hid_err(hdev, "error in parameter\n");
2952 hid_err(hdev, "error in report\n");
2956 if (data[0] == REPORT_ID_HIDPP_LONG &&
2957 data[2] == M560_SUB_ID && data[6] == 0x00) {
2959 * m560 mouse report for middle, forward and backward button
2962 * data[1] = device-id
2964 * data[5] = 0xaf -> middle
2967 * 0x00 -> release all
2973 input_report_key(hidpp->input, BTN_MIDDLE, 1);
2976 input_report_key(hidpp->input, BTN_FORWARD, 1);
2979 input_report_key(hidpp->input, BTN_BACK, 1);
2982 input_report_key(hidpp->input, BTN_BACK, 0);
2983 input_report_key(hidpp->input, BTN_FORWARD, 0);
2984 input_report_key(hidpp->input, BTN_MIDDLE, 0);
2987 hid_err(hdev, "error in report\n");
2990 input_sync(hidpp->input);
2992 } else if (data[0] == 0x02) {
2994 * Logitech M560 mouse report
2996 * data[0] = type (0x02)
2997 * data[1..2] = buttons
3004 input_report_key(hidpp->input, BTN_LEFT,
3005 !!(data[1] & M560_MOUSE_BTN_LEFT));
3006 input_report_key(hidpp->input, BTN_RIGHT,
3007 !!(data[1] & M560_MOUSE_BTN_RIGHT));
3009 if (data[1] & M560_MOUSE_BTN_WHEEL_LEFT) {
3010 input_report_rel(hidpp->input, REL_HWHEEL, -1);
3011 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES,
3013 } else if (data[1] & M560_MOUSE_BTN_WHEEL_RIGHT) {
3014 input_report_rel(hidpp->input, REL_HWHEEL, 1);
3015 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES,
3019 v = hid_snto32(hid_field_extract(hdev, data+3, 0, 12), 12);
3020 input_report_rel(hidpp->input, REL_X, v);
3022 v = hid_snto32(hid_field_extract(hdev, data+3, 12, 12), 12);
3023 input_report_rel(hidpp->input, REL_Y, v);
3025 v = hid_snto32(data[6], 8);
3027 hidpp_scroll_counter_handle_scroll(hidpp->input,
3028 &hidpp->vertical_wheel_counter, v);
3030 input_sync(hidpp->input);
3036 static void m560_populate_input(struct hidpp_device *hidpp,
3037 struct input_dev *input_dev)
3039 __set_bit(EV_KEY, input_dev->evbit);
3040 __set_bit(BTN_MIDDLE, input_dev->keybit);
3041 __set_bit(BTN_RIGHT, input_dev->keybit);
3042 __set_bit(BTN_LEFT, input_dev->keybit);
3043 __set_bit(BTN_BACK, input_dev->keybit);
3044 __set_bit(BTN_FORWARD, input_dev->keybit);
3046 __set_bit(EV_REL, input_dev->evbit);
3047 __set_bit(REL_X, input_dev->relbit);
3048 __set_bit(REL_Y, input_dev->relbit);
3049 __set_bit(REL_WHEEL, input_dev->relbit);
3050 __set_bit(REL_HWHEEL, input_dev->relbit);
3051 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit);
3052 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit);
3055 static int m560_input_mapping(struct hid_device *hdev, struct hid_input *hi,
3056 struct hid_field *field, struct hid_usage *usage,
3057 unsigned long **bit, int *max)
3062 /* ------------------------------------------------------------------------- */
3063 /* Logitech K400 devices */
3064 /* ------------------------------------------------------------------------- */
3067 * The Logitech K400 keyboard has an embedded touchpad which is seen
3068 * as a mouse from the OS point of view. There is a hardware shortcut to disable
3069 * tap-to-click but the setting is not remembered accross reset, annoying some
3072 * We can toggle this feature from the host by using the feature 0x6010:
3076 struct k400_private_data {
3080 static int k400_disable_tap_to_click(struct hidpp_device *hidpp)
3082 struct k400_private_data *k400 = hidpp->private_data;
3083 struct hidpp_touchpad_fw_items items = {};
3087 if (!k400->feature_index) {
3088 ret = hidpp_root_get_feature(hidpp,
3089 HIDPP_PAGE_TOUCHPAD_FW_ITEMS,
3090 &k400->feature_index, &feature_type);
3092 /* means that the device is not powered up */
3096 ret = hidpp_touchpad_fw_items_set(hidpp, k400->feature_index, &items);
3103 static int k400_allocate(struct hid_device *hdev)
3105 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3106 struct k400_private_data *k400;
3108 k400 = devm_kzalloc(&hdev->dev, sizeof(struct k400_private_data),
3113 hidpp->private_data = k400;
3118 static int k400_connect(struct hid_device *hdev, bool connected)
3120 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3122 if (!disable_tap_to_click)
3125 return k400_disable_tap_to_click(hidpp);
3128 /* ------------------------------------------------------------------------- */
3129 /* Logitech G920 Driving Force Racing Wheel for Xbox One */
3130 /* ------------------------------------------------------------------------- */
3132 #define HIDPP_PAGE_G920_FORCE_FEEDBACK 0x8123
3134 static int g920_ff_set_autocenter(struct hidpp_device *hidpp,
3135 struct hidpp_ff_private_data *data)
3137 struct hidpp_report response;
3138 u8 params[HIDPP_AUTOCENTER_PARAMS_LENGTH] = {
3139 [1] = HIDPP_FF_EFFECT_SPRING | HIDPP_FF_EFFECT_AUTOSTART,
3143 /* initialize with zero autocenter to get wheel in usable state */
3145 dbg_hid("Setting autocenter to 0.\n");
3146 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
3147 HIDPP_FF_DOWNLOAD_EFFECT,
3148 params, ARRAY_SIZE(params),
3151 hid_warn(hidpp->hid_dev, "Failed to autocenter device!\n");
3153 data->slot_autocenter = response.fap.params[0];
3158 static int g920_get_config(struct hidpp_device *hidpp,
3159 struct hidpp_ff_private_data *data)
3161 struct hidpp_report response;
3165 memset(data, 0, sizeof(*data));
3167 /* Find feature and store for later use */
3168 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_G920_FORCE_FEEDBACK,
3169 &data->feature_index, &feature_type);
3173 /* Read number of slots available in device */
3174 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
3181 hid_err(hidpp->hid_dev,
3182 "%s: received protocol error 0x%02x\n", __func__, ret);
3186 data->num_effects = response.fap.params[0] - HIDPP_FF_RESERVED_SLOTS;
3188 /* reset all forces */
3189 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
3194 hid_warn(hidpp->hid_dev, "Failed to reset all forces!\n");
3196 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
3197 HIDPP_FF_GET_APERTURE,
3201 hid_warn(hidpp->hid_dev,
3202 "Failed to read range from device!\n");
3205 900 : get_unaligned_be16(&response.fap.params[0]);
3207 /* Read the current gain values */
3208 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
3209 HIDPP_FF_GET_GLOBAL_GAINS,
3213 hid_warn(hidpp->hid_dev,
3214 "Failed to read gain values from device!\n");
3216 0xffff : get_unaligned_be16(&response.fap.params[0]);
3218 /* ignore boost value at response.fap.params[2] */
3220 return g920_ff_set_autocenter(hidpp, data);
3223 /* -------------------------------------------------------------------------- */
3224 /* Logitech Dinovo Mini keyboard with builtin touchpad */
3225 /* -------------------------------------------------------------------------- */
3226 #define DINOVO_MINI_PRODUCT_ID 0xb30c
3228 static int lg_dinovo_input_mapping(struct hid_device *hdev, struct hid_input *hi,
3229 struct hid_field *field, struct hid_usage *usage,
3230 unsigned long **bit, int *max)
3232 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
3235 switch (usage->hid & HID_USAGE) {
3236 case 0x00d: lg_map_key_clear(KEY_MEDIA); break;
3243 /* -------------------------------------------------------------------------- */
3244 /* HID++1.0 devices which use HID++ reports for their wheels */
3245 /* -------------------------------------------------------------------------- */
3246 static int hidpp10_wheel_connect(struct hidpp_device *hidpp)
3248 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
3249 HIDPP_ENABLE_WHEEL_REPORT | HIDPP_ENABLE_HWHEEL_REPORT,
3250 HIDPP_ENABLE_WHEEL_REPORT | HIDPP_ENABLE_HWHEEL_REPORT);
3253 static int hidpp10_wheel_raw_event(struct hidpp_device *hidpp,
3264 if (data[0] != REPORT_ID_HIDPP_SHORT || data[2] != HIDPP_SUB_ID_ROLLER)
3270 input_report_rel(hidpp->input, REL_WHEEL, value);
3271 input_report_rel(hidpp->input, REL_WHEEL_HI_RES, value * 120);
3272 input_report_rel(hidpp->input, REL_HWHEEL, hvalue);
3273 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, hvalue * 120);
3274 input_sync(hidpp->input);
3279 static void hidpp10_wheel_populate_input(struct hidpp_device *hidpp,
3280 struct input_dev *input_dev)
3282 __set_bit(EV_REL, input_dev->evbit);
3283 __set_bit(REL_WHEEL, input_dev->relbit);
3284 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit);
3285 __set_bit(REL_HWHEEL, input_dev->relbit);
3286 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit);
3289 /* -------------------------------------------------------------------------- */
3290 /* HID++1.0 mice which use HID++ reports for extra mouse buttons */
3291 /* -------------------------------------------------------------------------- */
3292 static int hidpp10_extra_mouse_buttons_connect(struct hidpp_device *hidpp)
3294 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
3295 HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT,
3296 HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT);
3299 static int hidpp10_extra_mouse_buttons_raw_event(struct hidpp_device *hidpp,
3310 if (data[0] != REPORT_ID_HIDPP_SHORT ||
3311 data[2] != HIDPP_SUB_ID_MOUSE_EXTRA_BTNS)
3315 * Buttons are either delivered through the regular mouse report *or*
3316 * through the extra buttons report. At least for button 6 how it is
3317 * delivered differs per receiver firmware version. Even receivers with
3318 * the same usb-id show different behavior, so we handle both cases.
3320 for (i = 0; i < 8; i++)
3321 input_report_key(hidpp->input, BTN_MOUSE + i,
3322 (data[3] & (1 << i)));
3324 /* Some mice report events on button 9+, use BTN_MISC */
3325 for (i = 0; i < 8; i++)
3326 input_report_key(hidpp->input, BTN_MISC + i,
3327 (data[4] & (1 << i)));
3329 input_sync(hidpp->input);
3333 static void hidpp10_extra_mouse_buttons_populate_input(
3334 struct hidpp_device *hidpp, struct input_dev *input_dev)
3336 /* BTN_MOUSE - BTN_MOUSE+7 are set already by the descriptor */
3337 __set_bit(BTN_0, input_dev->keybit);
3338 __set_bit(BTN_1, input_dev->keybit);
3339 __set_bit(BTN_2, input_dev->keybit);
3340 __set_bit(BTN_3, input_dev->keybit);
3341 __set_bit(BTN_4, input_dev->keybit);
3342 __set_bit(BTN_5, input_dev->keybit);
3343 __set_bit(BTN_6, input_dev->keybit);
3344 __set_bit(BTN_7, input_dev->keybit);
3347 /* -------------------------------------------------------------------------- */
3348 /* HID++1.0 kbds which only report 0x10xx consumer usages through sub-id 0x03 */
3349 /* -------------------------------------------------------------------------- */
3351 /* Find the consumer-page input report desc and change Maximums to 0x107f */
3352 static u8 *hidpp10_consumer_keys_report_fixup(struct hidpp_device *hidpp,
3353 u8 *_rdesc, unsigned int *rsize)
3355 /* Note 0 terminated so we can use strnstr to search for this. */
3356 static const char consumer_rdesc_start[] = {
3357 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */
3358 0x09, 0x01, /* USAGE (Consumer Control) */
3359 0xA1, 0x01, /* COLLECTION (Application) */
3360 0x85, 0x03, /* REPORT_ID = 3 */
3361 0x75, 0x10, /* REPORT_SIZE (16) */
3362 0x95, 0x02, /* REPORT_COUNT (2) */
3363 0x15, 0x01, /* LOGICAL_MIN (1) */
3364 0x26, 0x00 /* LOGICAL_MAX (... */
3366 char *consumer_rdesc, *rdesc = (char *)_rdesc;
3369 consumer_rdesc = strnstr(rdesc, consumer_rdesc_start, *rsize);
3370 size = *rsize - (consumer_rdesc - rdesc);
3371 if (consumer_rdesc && size >= 25) {
3372 consumer_rdesc[15] = 0x7f;
3373 consumer_rdesc[16] = 0x10;
3374 consumer_rdesc[20] = 0x7f;
3375 consumer_rdesc[21] = 0x10;
3380 static int hidpp10_consumer_keys_connect(struct hidpp_device *hidpp)
3382 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
3383 HIDPP_ENABLE_CONSUMER_REPORT,
3384 HIDPP_ENABLE_CONSUMER_REPORT);
3387 static int hidpp10_consumer_keys_raw_event(struct hidpp_device *hidpp,
3390 u8 consumer_report[5];
3395 if (data[0] != REPORT_ID_HIDPP_SHORT ||
3396 data[2] != HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS)
3400 * Build a normal consumer report (3) out of the data, this detour
3401 * is necessary to get some keyboards to report their 0x10xx usages.
3403 consumer_report[0] = 0x03;
3404 memcpy(&consumer_report[1], &data[3], 4);
3405 /* We are called from atomic context */
3406 hid_report_raw_event(hidpp->hid_dev, HID_INPUT_REPORT,
3407 consumer_report, 5, 1);
3412 /* -------------------------------------------------------------------------- */
3413 /* High-resolution scroll wheels */
3414 /* -------------------------------------------------------------------------- */
3416 static int hi_res_scroll_enable(struct hidpp_device *hidpp)
3421 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_HI_RES_WHEEL) {
3422 ret = hidpp_hrw_set_wheel_mode(hidpp, false, true, false);
3424 ret = hidpp_hrw_get_wheel_capability(hidpp, &multiplier);
3425 } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_HI_RES_SCROLL) {
3426 ret = hidpp_hrs_set_highres_scrolling_mode(hidpp, true,
3428 } else /* if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_FAST_SCROLL) */ {
3429 ret = hidpp10_enable_scrolling_acceleration(hidpp);
3435 if (multiplier == 0)
3438 hidpp->vertical_wheel_counter.wheel_multiplier = multiplier;
3439 hid_dbg(hidpp->hid_dev, "wheel multiplier = %d\n", multiplier);
3443 static int hidpp_initialize_hires_scroll(struct hidpp_device *hidpp)
3446 unsigned long capabilities;
3448 capabilities = hidpp->capabilities;
3450 if (hidpp->protocol_major >= 2) {
3454 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_HIRES_WHEEL,
3455 &feature_index, &feature_type);
3457 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_HI_RES_WHEEL;
3458 hid_dbg(hidpp->hid_dev, "Detected HID++ 2.0 hi-res scroll wheel\n");
3461 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_HI_RESOLUTION_SCROLLING,
3462 &feature_index, &feature_type);
3464 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_HI_RES_SCROLL;
3465 hid_dbg(hidpp->hid_dev, "Detected HID++ 2.0 hi-res scrolling\n");
3468 struct hidpp_report response;
3470 ret = hidpp_send_rap_command_sync(hidpp,
3471 REPORT_ID_HIDPP_SHORT,
3473 HIDPP_ENABLE_FAST_SCROLL,
3474 NULL, 0, &response);
3476 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP10_FAST_SCROLL;
3477 hid_dbg(hidpp->hid_dev, "Detected HID++ 1.0 fast scroll\n");
3481 if (hidpp->capabilities == capabilities)
3482 hid_dbg(hidpp->hid_dev, "Did not detect HID++ hi-res scrolling hardware support\n");
3486 /* -------------------------------------------------------------------------- */
3487 /* Generic HID++ devices */
3488 /* -------------------------------------------------------------------------- */
3490 static u8 *hidpp_report_fixup(struct hid_device *hdev, u8 *rdesc,
3491 unsigned int *rsize)
3493 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3498 /* For 27 MHz keyboards the quirk gets set after hid_parse. */
3499 if (hdev->group == HID_GROUP_LOGITECH_27MHZ_DEVICE ||
3500 (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS))
3501 rdesc = hidpp10_consumer_keys_report_fixup(hidpp, rdesc, rsize);
3506 static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
3507 struct hid_field *field, struct hid_usage *usage,
3508 unsigned long **bit, int *max)
3510 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3515 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
3516 return wtp_input_mapping(hdev, hi, field, usage, bit, max);
3517 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 &&
3518 field->application != HID_GD_MOUSE)
3519 return m560_input_mapping(hdev, hi, field, usage, bit, max);
3521 if (hdev->product == DINOVO_MINI_PRODUCT_ID)
3522 return lg_dinovo_input_mapping(hdev, hi, field, usage, bit, max);
3527 static int hidpp_input_mapped(struct hid_device *hdev, struct hid_input *hi,
3528 struct hid_field *field, struct hid_usage *usage,
3529 unsigned long **bit, int *max)
3531 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3536 /* Ensure that Logitech G920 is not given a default fuzz/flat value */
3537 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
3538 if (usage->type == EV_ABS && (usage->code == ABS_X ||
3539 usage->code == ABS_Y || usage->code == ABS_Z ||
3540 usage->code == ABS_RZ)) {
3541 field->application = HID_GD_MULTIAXIS;
3549 static void hidpp_populate_input(struct hidpp_device *hidpp,
3550 struct input_dev *input)
3552 hidpp->input = input;
3554 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
3555 wtp_populate_input(hidpp, input);
3556 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
3557 m560_populate_input(hidpp, input);
3559 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS)
3560 hidpp10_wheel_populate_input(hidpp, input);
3562 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS)
3563 hidpp10_extra_mouse_buttons_populate_input(hidpp, input);
3566 static int hidpp_input_configured(struct hid_device *hdev,
3567 struct hid_input *hidinput)
3569 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3570 struct input_dev *input = hidinput->input;
3575 hidpp_populate_input(hidpp, input);
3580 static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,
3583 struct hidpp_report *question = hidpp->send_receive_buf;
3584 struct hidpp_report *answer = hidpp->send_receive_buf;
3585 struct hidpp_report *report = (struct hidpp_report *)data;
3589 * If the mutex is locked then we have a pending answer from a
3590 * previously sent command.
3592 if (unlikely(mutex_is_locked(&hidpp->send_mutex))) {
3594 * Check for a correct hidpp20 answer or the corresponding
3597 if (hidpp_match_answer(question, report) ||
3598 hidpp_match_error(question, report)) {
3600 hidpp->answer_available = true;
3601 wake_up(&hidpp->wait);
3603 * This was an answer to a command that this driver sent
3604 * We return 1 to hid-core to avoid forwarding the
3605 * command upstream as it has been treated by the driver
3612 if (unlikely(hidpp_report_is_connect_event(hidpp, report))) {
3613 atomic_set(&hidpp->connected,
3614 !(report->rap.params[0] & (1 << 6)));
3615 if (schedule_work(&hidpp->work) == 0)
3616 dbg_hid("%s: connect event already queued\n", __func__);
3620 if (hidpp->hid_dev->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
3621 data[0] == REPORT_ID_HIDPP_SHORT &&
3622 data[2] == HIDPP_SUB_ID_USER_IFACE_EVENT &&
3623 (data[3] & HIDPP_USER_IFACE_EVENT_ENCRYPTION_KEY_LOST)) {
3624 dev_err_ratelimited(&hidpp->hid_dev->dev,
3625 "Error the keyboard's wireless encryption key has been lost, your keyboard will not work unless you re-configure encryption.\n");
3626 dev_err_ratelimited(&hidpp->hid_dev->dev,
3627 "See: https://gitlab.freedesktop.org/jwrdegoede/logitech-27mhz-keyboard-encryption-setup/\n");
3630 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) {
3631 ret = hidpp20_battery_event_1000(hidpp, data, size);
3634 ret = hidpp20_battery_event_1004(hidpp, data, size);
3637 ret = hidpp_solar_battery_event(hidpp, data, size);
3640 ret = hidpp20_battery_voltage_event(hidpp, data, size);
3645 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) {
3646 ret = hidpp10_battery_event(hidpp, data, size);
3651 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
3652 ret = hidpp10_wheel_raw_event(hidpp, data, size);
3657 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) {
3658 ret = hidpp10_extra_mouse_buttons_raw_event(hidpp, data, size);
3663 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) {
3664 ret = hidpp10_consumer_keys_raw_event(hidpp, data, size);
3672 static int hidpp_raw_event(struct hid_device *hdev, struct hid_report *report,
3675 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3681 /* Generic HID++ processing. */
3683 case REPORT_ID_HIDPP_VERY_LONG:
3684 if (size != hidpp->very_long_report_length) {
3685 hid_err(hdev, "received hid++ report of bad size (%d)",
3689 ret = hidpp_raw_hidpp_event(hidpp, data, size);
3691 case REPORT_ID_HIDPP_LONG:
3692 if (size != HIDPP_REPORT_LONG_LENGTH) {
3693 hid_err(hdev, "received hid++ report of bad size (%d)",
3697 ret = hidpp_raw_hidpp_event(hidpp, data, size);
3699 case REPORT_ID_HIDPP_SHORT:
3700 if (size != HIDPP_REPORT_SHORT_LENGTH) {
3701 hid_err(hdev, "received hid++ report of bad size (%d)",
3705 ret = hidpp_raw_hidpp_event(hidpp, data, size);
3709 /* If no report is available for further processing, skip calling
3710 * raw_event of subclasses. */
3714 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
3715 return wtp_raw_event(hdev, data, size);
3716 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
3717 return m560_raw_event(hdev, data, size);
3722 static int hidpp_event(struct hid_device *hdev, struct hid_field *field,
3723 struct hid_usage *usage, __s32 value)
3725 /* This function will only be called for scroll events, due to the
3726 * restriction imposed in hidpp_usages.
3728 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3729 struct hidpp_scroll_counter *counter;
3734 counter = &hidpp->vertical_wheel_counter;
3735 /* A scroll event may occur before the multiplier has been retrieved or
3736 * the input device set, or high-res scroll enabling may fail. In such
3737 * cases we must return early (falling back to default behaviour) to
3738 * avoid a crash in hidpp_scroll_counter_handle_scroll.
3740 if (!(hidpp->capabilities & HIDPP_CAPABILITY_HI_RES_SCROLL)
3741 || value == 0 || hidpp->input == NULL
3742 || counter->wheel_multiplier == 0)
3745 hidpp_scroll_counter_handle_scroll(hidpp->input, counter, value);
3749 static int hidpp_initialize_battery(struct hidpp_device *hidpp)
3751 static atomic_t battery_no = ATOMIC_INIT(0);
3752 struct power_supply_config cfg = { .drv_data = hidpp };
3753 struct power_supply_desc *desc = &hidpp->battery.desc;
3754 enum power_supply_property *battery_props;
3755 struct hidpp_battery *battery;
3756 unsigned int num_battery_props;
3760 if (hidpp->battery.ps)
3763 hidpp->battery.feature_index = 0xff;
3764 hidpp->battery.solar_feature_index = 0xff;
3765 hidpp->battery.voltage_feature_index = 0xff;
3767 if (hidpp->protocol_major >= 2) {
3768 if (hidpp->quirks & HIDPP_QUIRK_CLASS_K750)
3769 ret = hidpp_solar_request_battery_event(hidpp);
3771 /* we only support one battery feature right now, so let's
3772 first check the ones that support battery level first
3773 and leave voltage for last */
3774 ret = hidpp20_query_battery_info_1000(hidpp);
3776 ret = hidpp20_query_battery_info_1004(hidpp);
3778 ret = hidpp20_query_battery_voltage_info(hidpp);
3783 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_BATTERY;
3785 ret = hidpp10_query_battery_status(hidpp);
3787 ret = hidpp10_query_battery_mileage(hidpp);
3790 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
3792 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS;
3794 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP10_BATTERY;
3797 battery_props = devm_kmemdup(&hidpp->hid_dev->dev,
3798 hidpp_battery_props,
3799 sizeof(hidpp_battery_props),
3804 num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 3;
3806 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE ||
3807 hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE ||
3808 hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE)
3809 battery_props[num_battery_props++] =
3810 POWER_SUPPLY_PROP_CAPACITY;
3812 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS)
3813 battery_props[num_battery_props++] =
3814 POWER_SUPPLY_PROP_CAPACITY_LEVEL;
3816 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE)
3817 battery_props[num_battery_props++] =
3818 POWER_SUPPLY_PROP_VOLTAGE_NOW;
3820 battery = &hidpp->battery;
3822 n = atomic_inc_return(&battery_no) - 1;
3823 desc->properties = battery_props;
3824 desc->num_properties = num_battery_props;
3825 desc->get_property = hidpp_battery_get_property;
3826 sprintf(battery->name, "hidpp_battery_%ld", n);
3827 desc->name = battery->name;
3828 desc->type = POWER_SUPPLY_TYPE_BATTERY;
3829 desc->use_for_apm = 0;
3831 battery->ps = devm_power_supply_register(&hidpp->hid_dev->dev,
3834 if (IS_ERR(battery->ps))
3835 return PTR_ERR(battery->ps);
3837 power_supply_powers(battery->ps, &hidpp->hid_dev->dev);
3842 static void hidpp_overwrite_name(struct hid_device *hdev)
3844 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3847 if (hidpp->protocol_major < 2)
3850 name = hidpp_get_device_name(hidpp);
3853 hid_err(hdev, "unable to retrieve the name of the device");
3855 dbg_hid("HID++: Got name: %s\n", name);
3856 snprintf(hdev->name, sizeof(hdev->name), "%s", name);
3862 static int hidpp_input_open(struct input_dev *dev)
3864 struct hid_device *hid = input_get_drvdata(dev);
3866 return hid_hw_open(hid);
3869 static void hidpp_input_close(struct input_dev *dev)
3871 struct hid_device *hid = input_get_drvdata(dev);
3876 static struct input_dev *hidpp_allocate_input(struct hid_device *hdev)
3878 struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev);
3879 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3884 input_set_drvdata(input_dev, hdev);
3885 input_dev->open = hidpp_input_open;
3886 input_dev->close = hidpp_input_close;
3888 input_dev->name = hidpp->name;
3889 input_dev->phys = hdev->phys;
3890 input_dev->uniq = hdev->uniq;
3891 input_dev->id.bustype = hdev->bus;
3892 input_dev->id.vendor = hdev->vendor;
3893 input_dev->id.product = hdev->product;
3894 input_dev->id.version = hdev->version;
3895 input_dev->dev.parent = &hdev->dev;
3900 static void hidpp_connect_event(struct hidpp_device *hidpp)
3902 struct hid_device *hdev = hidpp->hid_dev;
3904 bool connected = atomic_read(&hidpp->connected);
3905 struct input_dev *input;
3906 char *name, *devm_name;
3909 if (hidpp->battery.ps) {
3910 hidpp->battery.online = false;
3911 hidpp->battery.status = POWER_SUPPLY_STATUS_UNKNOWN;
3912 hidpp->battery.level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
3913 power_supply_changed(hidpp->battery.ps);
3918 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
3919 ret = wtp_connect(hdev, connected);
3922 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) {
3923 ret = m560_send_config_command(hdev, connected);
3926 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
3927 ret = k400_connect(hdev, connected);
3932 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
3933 ret = hidpp10_wheel_connect(hidpp);
3938 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) {
3939 ret = hidpp10_extra_mouse_buttons_connect(hidpp);
3944 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) {
3945 ret = hidpp10_consumer_keys_connect(hidpp);
3950 /* the device is already connected, we can ask for its name and
3952 if (!hidpp->protocol_major) {
3953 ret = hidpp_root_get_protocol_version(hidpp);
3955 hid_err(hdev, "Can not get the protocol version.\n");
3960 if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) {
3961 name = hidpp_get_device_name(hidpp);
3963 devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
3969 hidpp->name = devm_name;
3973 hidpp_initialize_battery(hidpp);
3974 hidpp_initialize_hires_scroll(hidpp);
3976 /* forward current battery state */
3977 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) {
3978 hidpp10_enable_battery_reporting(hidpp);
3979 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)
3980 hidpp10_query_battery_mileage(hidpp);
3982 hidpp10_query_battery_status(hidpp);
3983 } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) {
3984 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE)
3985 hidpp20_query_battery_voltage_info(hidpp);
3986 else if (hidpp->capabilities & HIDPP_CAPABILITY_UNIFIED_BATTERY)
3987 hidpp20_query_battery_info_1004(hidpp);
3989 hidpp20_query_battery_info_1000(hidpp);
3991 if (hidpp->battery.ps)
3992 power_supply_changed(hidpp->battery.ps);
3994 if (hidpp->capabilities & HIDPP_CAPABILITY_HI_RES_SCROLL)
3995 hi_res_scroll_enable(hidpp);
3997 if (!(hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) || hidpp->delayed_input)
3998 /* if the input nodes are already created, we can stop now */
4001 input = hidpp_allocate_input(hdev);
4003 hid_err(hdev, "cannot allocate new input device: %d\n", ret);
4007 hidpp_populate_input(hidpp, input);
4009 ret = input_register_device(input);
4011 input_free_device(input);
4015 hidpp->delayed_input = input;
4018 static DEVICE_ATTR(builtin_power_supply, 0000, NULL, NULL);
4020 static struct attribute *sysfs_attrs[] = {
4021 &dev_attr_builtin_power_supply.attr,
4025 static const struct attribute_group ps_attribute_group = {
4026 .attrs = sysfs_attrs
4029 static int hidpp_get_report_length(struct hid_device *hdev, int id)
4031 struct hid_report_enum *re;
4032 struct hid_report *report;
4034 re = &(hdev->report_enum[HID_OUTPUT_REPORT]);
4035 report = re->report_id_hash[id];
4039 return report->field[0]->report_count + 1;
4042 static u8 hidpp_validate_device(struct hid_device *hdev)
4044 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
4045 int id, report_length;
4046 u8 supported_reports = 0;
4048 id = REPORT_ID_HIDPP_SHORT;
4049 report_length = hidpp_get_report_length(hdev, id);
4050 if (report_length) {
4051 if (report_length < HIDPP_REPORT_SHORT_LENGTH)
4054 supported_reports |= HIDPP_REPORT_SHORT_SUPPORTED;
4057 id = REPORT_ID_HIDPP_LONG;
4058 report_length = hidpp_get_report_length(hdev, id);
4059 if (report_length) {
4060 if (report_length < HIDPP_REPORT_LONG_LENGTH)
4063 supported_reports |= HIDPP_REPORT_LONG_SUPPORTED;
4066 id = REPORT_ID_HIDPP_VERY_LONG;
4067 report_length = hidpp_get_report_length(hdev, id);
4068 if (report_length) {
4069 if (report_length < HIDPP_REPORT_LONG_LENGTH ||
4070 report_length > HIDPP_REPORT_VERY_LONG_MAX_LENGTH)
4073 supported_reports |= HIDPP_REPORT_VERY_LONG_SUPPORTED;
4074 hidpp->very_long_report_length = report_length;
4077 return supported_reports;
4080 hid_warn(hdev, "not enough values in hidpp report %d\n", id);
4084 static bool hidpp_application_equals(struct hid_device *hdev,
4085 unsigned int application)
4087 struct list_head *report_list;
4088 struct hid_report *report;
4090 report_list = &hdev->report_enum[HID_INPUT_REPORT].report_list;
4091 report = list_first_entry_or_null(report_list, struct hid_report, list);
4092 return report && report->application == application;
4095 static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
4097 struct hidpp_device *hidpp;
4100 unsigned int connect_mask = HID_CONNECT_DEFAULT;
4101 struct hidpp_ff_private_data data;
4103 /* report_fixup needs drvdata to be set before we call hid_parse */
4104 hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL);
4108 hidpp->hid_dev = hdev;
4109 hidpp->name = hdev->name;
4110 hidpp->quirks = id->driver_data;
4111 hid_set_drvdata(hdev, hidpp);
4113 ret = hid_parse(hdev);
4115 hid_err(hdev, "%s:parse failed\n", __func__);
4120 * Make sure the device is HID++ capable, otherwise treat as generic HID
4122 hidpp->supported_reports = hidpp_validate_device(hdev);
4124 if (!hidpp->supported_reports) {
4125 hid_set_drvdata(hdev, NULL);
4126 devm_kfree(&hdev->dev, hidpp);
4127 return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
4130 if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE)
4131 hidpp->quirks |= HIDPP_QUIRK_UNIFYING;
4133 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
4134 hidpp_application_equals(hdev, HID_GD_MOUSE))
4135 hidpp->quirks |= HIDPP_QUIRK_HIDPP_WHEELS |
4136 HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS;
4138 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
4139 hidpp_application_equals(hdev, HID_GD_KEYBOARD))
4140 hidpp->quirks |= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS;
4142 if (disable_raw_mode) {
4143 hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP;
4144 hidpp->quirks &= ~HIDPP_QUIRK_NO_HIDINPUT;
4147 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
4148 ret = wtp_allocate(hdev, id);
4151 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
4152 ret = k400_allocate(hdev);
4157 INIT_WORK(&hidpp->work, delayed_work_cb);
4158 mutex_init(&hidpp->send_mutex);
4159 init_waitqueue_head(&hidpp->wait);
4161 /* indicates we are handling the battery properties in the kernel */
4162 ret = sysfs_create_group(&hdev->dev.kobj, &ps_attribute_group);
4164 hid_warn(hdev, "Cannot allocate sysfs group for %s\n",
4168 * Plain USB connections need to actually call start and open
4169 * on the transport driver to allow incoming data.
4171 ret = hid_hw_start(hdev, 0);
4173 hid_err(hdev, "hw start failed\n");
4174 goto hid_hw_start_fail;
4177 ret = hid_hw_open(hdev);
4179 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n",
4181 goto hid_hw_open_fail;
4184 /* Allow incoming packets */
4185 hid_device_io_start(hdev);
4187 if (hidpp->quirks & HIDPP_QUIRK_UNIFYING)
4188 hidpp_unifying_init(hidpp);
4190 connected = hidpp_root_get_protocol_version(hidpp) == 0;
4191 atomic_set(&hidpp->connected, connected);
4192 if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) {
4195 hid_err(hdev, "Device not connected");
4196 goto hid_hw_init_fail;
4199 hidpp_overwrite_name(hdev);
4202 if (connected && hidpp->protocol_major >= 2) {
4203 ret = hidpp_set_wireless_feature_index(hidpp);
4205 hidpp->wireless_feature_index = 0;
4207 goto hid_hw_init_fail;
4210 if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) {
4211 ret = wtp_get_config(hidpp);
4213 goto hid_hw_init_fail;
4214 } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) {
4215 ret = g920_get_config(hidpp, &data);
4217 goto hid_hw_init_fail;
4220 hidpp_connect_event(hidpp);
4222 /* Reset the HID node state */
4223 hid_device_io_stop(hdev);
4227 if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT)
4228 connect_mask &= ~HID_CONNECT_HIDINPUT;
4230 /* Now export the actual inputs and hidraw nodes to the world */
4231 ret = hid_hw_start(hdev, connect_mask);
4233 hid_err(hdev, "%s:hid_hw_start returned error\n", __func__);
4234 goto hid_hw_start_fail;
4237 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
4238 ret = hidpp_ff_init(hidpp, &data);
4240 hid_warn(hidpp->hid_dev,
4241 "Unable to initialize force feedback support, errno %d\n",
4252 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
4253 cancel_work_sync(&hidpp->work);
4254 mutex_destroy(&hidpp->send_mutex);
4258 static void hidpp_remove(struct hid_device *hdev)
4260 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
4263 return hid_hw_stop(hdev);
4265 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
4268 cancel_work_sync(&hidpp->work);
4269 mutex_destroy(&hidpp->send_mutex);
4272 static const struct hid_device_id unhandled_hidpp_devices[] = {
4273 /* Logitech Harmony Adapter for PS3, handled in hid-sony */
4274 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
4275 /* Handled in hid-generic */
4276 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DINOVO_EDGE_KBD) },
4280 static bool hidpp_match(struct hid_device *hdev,
4281 bool ignore_special_driver)
4283 /* Refuse to handle devices handled by other HID drivers */
4284 return !hid_match_id(hdev, unhandled_hidpp_devices);
4287 #define LDJ_DEVICE(product) \
4288 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE, \
4289 USB_VENDOR_ID_LOGITECH, (product))
4291 #define L27MHZ_DEVICE(product) \
4292 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_27MHZ_DEVICE, \
4293 USB_VENDOR_ID_LOGITECH, (product))
4295 static const struct hid_device_id hidpp_devices[] = {
4296 { /* wireless touchpad */
4298 .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT |
4299 HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS },
4300 { /* wireless touchpad T650 */
4302 .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT },
4303 { /* wireless touchpad T651 */
4304 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH,
4305 USB_DEVICE_ID_LOGITECH_T651),
4306 .driver_data = HIDPP_QUIRK_CLASS_WTP },
4307 { /* Mouse logitech M560 */
4309 .driver_data = HIDPP_QUIRK_DELAYED_INIT | HIDPP_QUIRK_CLASS_M560 },
4310 { /* Keyboard logitech K400 */
4312 .driver_data = HIDPP_QUIRK_CLASS_K400 },
4313 { /* Solar Keyboard Logitech K750 */
4315 .driver_data = HIDPP_QUIRK_CLASS_K750 },
4316 { /* Keyboard MX5000 (Bluetooth-receiver in HID proxy mode) */
4318 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
4319 { /* Dinovo Edge (Bluetooth-receiver in HID proxy mode) */
4321 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
4322 { /* Keyboard MX5500 (Bluetooth-receiver in HID proxy mode) */
4324 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
4326 { LDJ_DEVICE(HID_ANY_ID) },
4328 { /* Keyboard LX501 (Y-RR53) */
4329 L27MHZ_DEVICE(0x0049),
4330 .driver_data = HIDPP_QUIRK_KBD_ZOOM_WHEEL },
4331 { /* Keyboard MX3000 (Y-RAM74) */
4332 L27MHZ_DEVICE(0x0057),
4333 .driver_data = HIDPP_QUIRK_KBD_SCROLL_WHEEL },
4334 { /* Keyboard MX3200 (Y-RAV80) */
4335 L27MHZ_DEVICE(0x005c),
4336 .driver_data = HIDPP_QUIRK_KBD_ZOOM_WHEEL },
4337 { /* S510 Media Remote */
4338 L27MHZ_DEVICE(0x00fe),
4339 .driver_data = HIDPP_QUIRK_KBD_SCROLL_WHEEL },
4341 { L27MHZ_DEVICE(HID_ANY_ID) },
4343 { /* Logitech G403 Wireless Gaming Mouse over USB */
4344 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC082) },
4345 { /* Logitech G703 Gaming Mouse over USB */
4346 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC087) },
4347 { /* Logitech G703 Hero Gaming Mouse over USB */
4348 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC090) },
4349 { /* Logitech G900 Gaming Mouse over USB */
4350 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC081) },
4351 { /* Logitech G903 Gaming Mouse over USB */
4352 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC086) },
4353 { /* Logitech G903 Hero Gaming Mouse over USB */
4354 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC091) },
4355 { /* Logitech G920 Wheel over USB */
4356 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL),
4357 .driver_data = HIDPP_QUIRK_CLASS_G920 | HIDPP_QUIRK_FORCE_OUTPUT_REPORTS},
4358 { /* Logitech G Pro Gaming Mouse over USB */
4359 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC088) },
4361 { /* MX5000 keyboard over Bluetooth */
4362 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb305),
4363 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
4364 { /* Dinovo Edge keyboard over Bluetooth */
4365 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb309),
4366 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
4367 { /* MX5500 keyboard over Bluetooth */
4368 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb30b),
4369 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
4371 { /* And try to enable HID++ for all the Logitech Bluetooth devices */
4372 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_ANY, USB_VENDOR_ID_LOGITECH, HID_ANY_ID) },
4376 MODULE_DEVICE_TABLE(hid, hidpp_devices);
4378 static const struct hid_usage_id hidpp_usages[] = {
4379 { HID_GD_WHEEL, EV_REL, REL_WHEEL_HI_RES },
4380 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
4383 static struct hid_driver hidpp_driver = {
4384 .name = "logitech-hidpp-device",
4385 .id_table = hidpp_devices,
4386 .match = hidpp_match,
4387 .report_fixup = hidpp_report_fixup,
4388 .probe = hidpp_probe,
4389 .remove = hidpp_remove,
4390 .raw_event = hidpp_raw_event,
4391 .usage_table = hidpp_usages,
4392 .event = hidpp_event,
4393 .input_configured = hidpp_input_configured,
4394 .input_mapping = hidpp_input_mapping,
4395 .input_mapped = hidpp_input_mapped,
4398 module_hid_driver(hidpp_driver);