1 // SPDX-License-Identifier: GPL-2.0-only
3 * HIDPP protocol for Logitech Unifying 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 REPORT_ID_HIDPP_SHORT 0x10
45 #define REPORT_ID_HIDPP_LONG 0x11
46 #define REPORT_ID_HIDPP_VERY_LONG 0x12
48 #define HIDPP_REPORT_SHORT_LENGTH 7
49 #define HIDPP_REPORT_LONG_LENGTH 20
50 #define HIDPP_REPORT_VERY_LONG_MAX_LENGTH 64
52 #define HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS 0x03
53 #define HIDPP_SUB_ID_ROLLER 0x05
54 #define HIDPP_SUB_ID_MOUSE_EXTRA_BTNS 0x06
56 #define HIDPP_QUIRK_CLASS_WTP BIT(0)
57 #define HIDPP_QUIRK_CLASS_M560 BIT(1)
58 #define HIDPP_QUIRK_CLASS_K400 BIT(2)
59 #define HIDPP_QUIRK_CLASS_G920 BIT(3)
60 #define HIDPP_QUIRK_CLASS_K750 BIT(4)
62 /* bits 2..20 are reserved for classes */
63 /* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */
64 #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22)
65 #define HIDPP_QUIRK_NO_HIDINPUT BIT(23)
66 #define HIDPP_QUIRK_FORCE_OUTPUT_REPORTS BIT(24)
67 #define HIDPP_QUIRK_UNIFYING BIT(25)
68 #define HIDPP_QUIRK_HI_RES_SCROLL_1P0 BIT(26)
69 #define HIDPP_QUIRK_HI_RES_SCROLL_X2120 BIT(27)
70 #define HIDPP_QUIRK_HI_RES_SCROLL_X2121 BIT(28)
71 #define HIDPP_QUIRK_HIDPP_WHEELS BIT(29)
72 #define HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS BIT(30)
73 #define HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS BIT(31)
75 /* These are just aliases for now */
76 #define HIDPP_QUIRK_KBD_SCROLL_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
77 #define HIDPP_QUIRK_KBD_ZOOM_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
79 /* Convenience constant to check for any high-res support. */
80 #define HIDPP_QUIRK_HI_RES_SCROLL (HIDPP_QUIRK_HI_RES_SCROLL_1P0 | \
81 HIDPP_QUIRK_HI_RES_SCROLL_X2120 | \
82 HIDPP_QUIRK_HI_RES_SCROLL_X2121)
84 #define HIDPP_QUIRK_DELAYED_INIT HIDPP_QUIRK_NO_HIDINPUT
86 #define HIDPP_CAPABILITY_HIDPP10_BATTERY BIT(0)
87 #define HIDPP_CAPABILITY_HIDPP20_BATTERY BIT(1)
88 #define HIDPP_CAPABILITY_BATTERY_MILEAGE BIT(2)
89 #define HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS BIT(3)
92 * There are two hidpp protocols in use, the first version hidpp10 is known
93 * as register access protocol or RAP, the second version hidpp20 is known as
94 * feature access protocol or FAP
96 * Most older devices (including the Unifying usb receiver) use the RAP protocol
97 * where as most newer devices use the FAP protocol. Both protocols are
98 * compatible with the underlying transport, which could be usb, Unifiying, or
99 * bluetooth. The message lengths are defined by the hid vendor specific report
100 * descriptor for the HIDPP_SHORT report type (total message lenth 7 bytes) and
101 * the HIDPP_LONG report type (total message length 20 bytes)
103 * The RAP protocol uses both report types, whereas the FAP only uses HIDPP_LONG
104 * messages. The Unifying receiver itself responds to RAP messages (device index
105 * is 0xFF for the receiver), and all messages (short or long) with a device
106 * index between 1 and 6 are passed untouched to the corresponding paired
109 * The paired device can be RAP or FAP, it will receive the message untouched
110 * from the Unifiying receiver.
115 u8 funcindex_clientid;
116 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
122 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
125 struct hidpp_report {
131 u8 rawbytes[sizeof(struct fap)];
135 struct hidpp_battery {
137 u8 solar_feature_index;
138 struct power_supply_desc desc;
139 struct power_supply *ps;
148 * struct hidpp_scroll_counter - Utility class for processing high-resolution
150 * @dev: the input device for which events should be reported.
151 * @wheel_multiplier: the scalar multiplier to be applied to each wheel event
152 * @remainder: counts the number of high-resolution units moved since the last
153 * low-resolution event (REL_WHEEL or REL_HWHEEL) was sent. Should
154 * only be used by class methods.
155 * @direction: direction of last movement (1 or -1)
156 * @last_time: last event time, used to reset remainder after inactivity
158 struct hidpp_scroll_counter {
159 int wheel_multiplier;
162 unsigned long long last_time;
165 struct hidpp_device {
166 struct hid_device *hid_dev;
167 struct input_dev *input;
168 struct mutex send_mutex;
169 void *send_receive_buf;
170 char *name; /* will never be NULL and should not be freed */
171 wait_queue_head_t wait;
172 int very_long_report_length;
173 bool answer_available;
179 struct work_struct work;
180 struct kfifo delayed_work_fifo;
182 struct input_dev *delayed_input;
184 unsigned long quirks;
185 unsigned long capabilities;
187 struct hidpp_battery battery;
188 struct hidpp_scroll_counter vertical_wheel_counter;
191 /* HID++ 1.0 error codes */
192 #define HIDPP_ERROR 0x8f
193 #define HIDPP_ERROR_SUCCESS 0x00
194 #define HIDPP_ERROR_INVALID_SUBID 0x01
195 #define HIDPP_ERROR_INVALID_ADRESS 0x02
196 #define HIDPP_ERROR_INVALID_VALUE 0x03
197 #define HIDPP_ERROR_CONNECT_FAIL 0x04
198 #define HIDPP_ERROR_TOO_MANY_DEVICES 0x05
199 #define HIDPP_ERROR_ALREADY_EXISTS 0x06
200 #define HIDPP_ERROR_BUSY 0x07
201 #define HIDPP_ERROR_UNKNOWN_DEVICE 0x08
202 #define HIDPP_ERROR_RESOURCE_ERROR 0x09
203 #define HIDPP_ERROR_REQUEST_UNAVAILABLE 0x0a
204 #define HIDPP_ERROR_INVALID_PARAM_VALUE 0x0b
205 #define HIDPP_ERROR_WRONG_PIN_CODE 0x0c
206 /* HID++ 2.0 error codes */
207 #define HIDPP20_ERROR 0xff
209 static void hidpp_connect_event(struct hidpp_device *hidpp_dev);
211 static int __hidpp_send_report(struct hid_device *hdev,
212 struct hidpp_report *hidpp_report)
214 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
215 int fields_count, ret;
217 switch (hidpp_report->report_id) {
218 case REPORT_ID_HIDPP_SHORT:
219 fields_count = HIDPP_REPORT_SHORT_LENGTH;
221 case REPORT_ID_HIDPP_LONG:
222 fields_count = HIDPP_REPORT_LONG_LENGTH;
224 case REPORT_ID_HIDPP_VERY_LONG:
225 fields_count = hidpp->very_long_report_length;
232 * set the device_index as the receiver, it will be overwritten by
233 * hid_hw_request if needed
235 hidpp_report->device_index = 0xff;
237 if (hidpp->quirks & HIDPP_QUIRK_FORCE_OUTPUT_REPORTS) {
238 ret = hid_hw_output_report(hdev, (u8 *)hidpp_report, fields_count);
240 ret = hid_hw_raw_request(hdev, hidpp_report->report_id,
241 (u8 *)hidpp_report, fields_count, HID_OUTPUT_REPORT,
245 return ret == fields_count ? 0 : -1;
249 * hidpp_send_message_sync() returns 0 in case of success, and something else
250 * in case of a failure.
251 * - If ' something else' is positive, that means that an error has been raised
252 * by the protocol itself.
253 * - If ' something else' is negative, that means that we had a classic error
254 * (-ENOMEM, -EPIPE, etc...)
256 static int hidpp_send_message_sync(struct hidpp_device *hidpp,
257 struct hidpp_report *message,
258 struct hidpp_report *response)
262 mutex_lock(&hidpp->send_mutex);
264 hidpp->send_receive_buf = response;
265 hidpp->answer_available = false;
268 * So that we can later validate the answer when it arrives
271 *response = *message;
273 ret = __hidpp_send_report(hidpp->hid_dev, message);
276 dbg_hid("__hidpp_send_report returned err: %d\n", ret);
277 memset(response, 0, sizeof(struct hidpp_report));
281 if (!wait_event_timeout(hidpp->wait, hidpp->answer_available,
283 dbg_hid("%s:timeout waiting for response\n", __func__);
284 memset(response, 0, sizeof(struct hidpp_report));
288 if (response->report_id == REPORT_ID_HIDPP_SHORT &&
289 response->rap.sub_id == HIDPP_ERROR) {
290 ret = response->rap.params[1];
291 dbg_hid("%s:got hidpp error %02X\n", __func__, ret);
295 if ((response->report_id == REPORT_ID_HIDPP_LONG ||
296 response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&
297 response->fap.feature_index == HIDPP20_ERROR) {
298 ret = response->fap.params[1];
299 dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);
304 mutex_unlock(&hidpp->send_mutex);
309 static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
310 u8 feat_index, u8 funcindex_clientid, u8 *params, int param_count,
311 struct hidpp_report *response)
313 struct hidpp_report *message;
316 if (param_count > sizeof(message->fap.params))
319 message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
323 if (param_count > (HIDPP_REPORT_LONG_LENGTH - 4))
324 message->report_id = REPORT_ID_HIDPP_VERY_LONG;
326 message->report_id = REPORT_ID_HIDPP_LONG;
327 message->fap.feature_index = feat_index;
328 message->fap.funcindex_clientid = funcindex_clientid;
329 memcpy(&message->fap.params, params, param_count);
331 ret = hidpp_send_message_sync(hidpp, message, response);
336 static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,
337 u8 report_id, u8 sub_id, u8 reg_address, u8 *params, int param_count,
338 struct hidpp_report *response)
340 struct hidpp_report *message;
344 case REPORT_ID_HIDPP_SHORT:
345 max_count = HIDPP_REPORT_SHORT_LENGTH - 4;
347 case REPORT_ID_HIDPP_LONG:
348 max_count = HIDPP_REPORT_LONG_LENGTH - 4;
350 case REPORT_ID_HIDPP_VERY_LONG:
351 max_count = hidpp_dev->very_long_report_length - 4;
357 if (param_count > max_count)
360 message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
363 message->report_id = report_id;
364 message->rap.sub_id = sub_id;
365 message->rap.reg_address = reg_address;
366 memcpy(&message->rap.params, params, param_count);
368 ret = hidpp_send_message_sync(hidpp_dev, message, response);
373 static void delayed_work_cb(struct work_struct *work)
375 struct hidpp_device *hidpp = container_of(work, struct hidpp_device,
377 hidpp_connect_event(hidpp);
380 static inline bool hidpp_match_answer(struct hidpp_report *question,
381 struct hidpp_report *answer)
383 return (answer->fap.feature_index == question->fap.feature_index) &&
384 (answer->fap.funcindex_clientid == question->fap.funcindex_clientid);
387 static inline bool hidpp_match_error(struct hidpp_report *question,
388 struct hidpp_report *answer)
390 return ((answer->rap.sub_id == HIDPP_ERROR) ||
391 (answer->fap.feature_index == HIDPP20_ERROR)) &&
392 (answer->fap.funcindex_clientid == question->fap.feature_index) &&
393 (answer->fap.params[0] == question->fap.funcindex_clientid);
396 static inline bool hidpp_report_is_connect_event(struct hidpp_report *report)
398 return (report->report_id == REPORT_ID_HIDPP_SHORT) &&
399 (report->rap.sub_id == 0x41);
403 * hidpp_prefix_name() prefixes the current given name with "Logitech ".
405 static void hidpp_prefix_name(char **name, int name_length)
407 #define PREFIX_LENGTH 9 /* "Logitech " */
412 if (name_length > PREFIX_LENGTH &&
413 strncmp(*name, "Logitech ", PREFIX_LENGTH) == 0)
414 /* The prefix has is already in the name */
417 new_length = PREFIX_LENGTH + name_length;
418 new_name = kzalloc(new_length, GFP_KERNEL);
422 snprintf(new_name, new_length, "Logitech %s", *name);
430 * hidpp_scroll_counter_handle_scroll() - Send high- and low-resolution scroll
431 * events given a high-resolution wheel
433 * @counter: a hid_scroll_counter struct describing the wheel.
434 * @hi_res_value: the movement of the wheel, in the mouse's high-resolution
437 * Given a high-resolution movement, this function converts the movement into
438 * fractions of 120 and emits high-resolution scroll events for the input
439 * device. It also uses the multiplier from &struct hid_scroll_counter to
440 * emit low-resolution scroll events when appropriate for
441 * backwards-compatibility with userspace input libraries.
443 static void hidpp_scroll_counter_handle_scroll(struct input_dev *input_dev,
444 struct hidpp_scroll_counter *counter,
447 int low_res_value, remainder, direction;
448 unsigned long long now, previous;
450 hi_res_value = hi_res_value * 120/counter->wheel_multiplier;
451 input_report_rel(input_dev, REL_WHEEL_HI_RES, hi_res_value);
453 remainder = counter->remainder;
454 direction = hi_res_value > 0 ? 1 : -1;
457 previous = counter->last_time;
458 counter->last_time = now;
460 * Reset the remainder after a period of inactivity or when the
461 * direction changes. This prevents the REL_WHEEL emulation point
462 * from sliding for devices that don't always provide the same
463 * number of movements per detent.
465 if (now - previous > 1000000000 || direction != counter->direction)
468 counter->direction = direction;
469 remainder += hi_res_value;
471 /* Some wheels will rest 7/8ths of a detent from the previous detent
472 * after slow movement, so we want the threshold for low-res events to
473 * be in the middle between two detents (e.g. after 4/8ths) as
474 * opposed to on the detents themselves (8/8ths).
476 if (abs(remainder) >= 60) {
477 /* Add (or subtract) 1 because we want to trigger when the wheel
478 * is half-way to the next detent (i.e. scroll 1 detent after a
479 * 1/2 detent movement, 2 detents after a 1 1/2 detent movement,
482 low_res_value = remainder / 120;
483 if (low_res_value == 0)
484 low_res_value = (hi_res_value > 0 ? 1 : -1);
485 input_report_rel(input_dev, REL_WHEEL, low_res_value);
486 remainder -= low_res_value * 120;
488 counter->remainder = remainder;
491 /* -------------------------------------------------------------------------- */
492 /* HIDP++ 1.0 commands */
493 /* -------------------------------------------------------------------------- */
495 #define HIDPP_SET_REGISTER 0x80
496 #define HIDPP_GET_REGISTER 0x81
497 #define HIDPP_SET_LONG_REGISTER 0x82
498 #define HIDPP_GET_LONG_REGISTER 0x83
501 * hidpp10_set_register - Modify a HID++ 1.0 register.
502 * @hidpp_dev: the device to set the register on.
503 * @register_address: the address of the register to modify.
504 * @byte: the byte of the register to modify. Should be less than 3.
505 * @mask: mask of the bits to modify
506 * @value: new values for the bits in mask
507 * Return: 0 if successful, otherwise a negative error code.
509 static int hidpp10_set_register(struct hidpp_device *hidpp_dev,
510 u8 register_address, u8 byte, u8 mask, u8 value)
512 struct hidpp_report response;
514 u8 params[3] = { 0 };
516 ret = hidpp_send_rap_command_sync(hidpp_dev,
517 REPORT_ID_HIDPP_SHORT,
524 memcpy(params, response.rap.params, 3);
526 params[byte] &= ~mask;
527 params[byte] |= value & mask;
529 return hidpp_send_rap_command_sync(hidpp_dev,
530 REPORT_ID_HIDPP_SHORT,
533 params, 3, &response);
536 #define HIDPP_REG_ENABLE_REPORTS 0x00
537 #define HIDPP_ENABLE_CONSUMER_REPORT BIT(0)
538 #define HIDPP_ENABLE_WHEEL_REPORT BIT(2)
539 #define HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT BIT(3)
540 #define HIDPP_ENABLE_BAT_REPORT BIT(4)
541 #define HIDPP_ENABLE_HWHEEL_REPORT BIT(5)
543 static int hidpp10_enable_battery_reporting(struct hidpp_device *hidpp_dev)
545 return hidpp10_set_register(hidpp_dev, HIDPP_REG_ENABLE_REPORTS, 0,
546 HIDPP_ENABLE_BAT_REPORT, HIDPP_ENABLE_BAT_REPORT);
549 #define HIDPP_REG_FEATURES 0x01
550 #define HIDPP_ENABLE_SPECIAL_BUTTON_FUNC BIT(1)
551 #define HIDPP_ENABLE_FAST_SCROLL BIT(6)
553 /* On HID++ 1.0 devices, high-res scroll was called "scrolling acceleration". */
554 static int hidpp10_enable_scrolling_acceleration(struct hidpp_device *hidpp_dev)
556 return hidpp10_set_register(hidpp_dev, HIDPP_REG_FEATURES, 0,
557 HIDPP_ENABLE_FAST_SCROLL, HIDPP_ENABLE_FAST_SCROLL);
560 #define HIDPP_REG_BATTERY_STATUS 0x07
562 static int hidpp10_battery_status_map_level(u8 param)
568 level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
571 level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
574 level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
577 level = POWER_SUPPLY_CAPACITY_LEVEL_HIGH;
580 level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
586 static int hidpp10_battery_status_map_status(u8 param)
592 /* discharging (in use) */
593 status = POWER_SUPPLY_STATUS_DISCHARGING;
595 case 0x21: /* (standard) charging */
596 case 0x24: /* fast charging */
597 case 0x25: /* slow charging */
598 status = POWER_SUPPLY_STATUS_CHARGING;
600 case 0x26: /* topping charge */
601 case 0x22: /* charge complete */
602 status = POWER_SUPPLY_STATUS_FULL;
604 case 0x20: /* unknown */
605 status = POWER_SUPPLY_STATUS_UNKNOWN;
608 * 0x01...0x1F = reserved (not charging)
609 * 0x23 = charging error
610 * 0x27..0xff = reserved
613 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
620 static int hidpp10_query_battery_status(struct hidpp_device *hidpp)
622 struct hidpp_report response;
625 ret = hidpp_send_rap_command_sync(hidpp,
626 REPORT_ID_HIDPP_SHORT,
628 HIDPP_REG_BATTERY_STATUS,
633 hidpp->battery.level =
634 hidpp10_battery_status_map_level(response.rap.params[0]);
635 status = hidpp10_battery_status_map_status(response.rap.params[1]);
636 hidpp->battery.status = status;
637 /* the capacity is only available when discharging or full */
638 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
639 status == POWER_SUPPLY_STATUS_FULL;
644 #define HIDPP_REG_BATTERY_MILEAGE 0x0D
646 static int hidpp10_battery_mileage_map_status(u8 param)
650 switch (param >> 6) {
652 /* discharging (in use) */
653 status = POWER_SUPPLY_STATUS_DISCHARGING;
655 case 0x01: /* charging */
656 status = POWER_SUPPLY_STATUS_CHARGING;
658 case 0x02: /* charge complete */
659 status = POWER_SUPPLY_STATUS_FULL;
662 * 0x03 = charging error
665 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
672 static int hidpp10_query_battery_mileage(struct hidpp_device *hidpp)
674 struct hidpp_report response;
677 ret = hidpp_send_rap_command_sync(hidpp,
678 REPORT_ID_HIDPP_SHORT,
680 HIDPP_REG_BATTERY_MILEAGE,
685 hidpp->battery.capacity = response.rap.params[0];
686 status = hidpp10_battery_mileage_map_status(response.rap.params[2]);
687 hidpp->battery.status = status;
688 /* the capacity is only available when discharging or full */
689 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
690 status == POWER_SUPPLY_STATUS_FULL;
695 static int hidpp10_battery_event(struct hidpp_device *hidpp, u8 *data, int size)
697 struct hidpp_report *report = (struct hidpp_report *)data;
698 int status, capacity, level;
701 if (report->report_id != REPORT_ID_HIDPP_SHORT)
704 switch (report->rap.sub_id) {
705 case HIDPP_REG_BATTERY_STATUS:
706 capacity = hidpp->battery.capacity;
707 level = hidpp10_battery_status_map_level(report->rawbytes[1]);
708 status = hidpp10_battery_status_map_status(report->rawbytes[2]);
710 case HIDPP_REG_BATTERY_MILEAGE:
711 capacity = report->rap.params[0];
712 level = hidpp->battery.level;
713 status = hidpp10_battery_mileage_map_status(report->rawbytes[3]);
719 changed = capacity != hidpp->battery.capacity ||
720 level != hidpp->battery.level ||
721 status != hidpp->battery.status;
723 /* the capacity is only available when discharging or full */
724 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
725 status == POWER_SUPPLY_STATUS_FULL;
728 hidpp->battery.level = level;
729 hidpp->battery.status = status;
730 if (hidpp->battery.ps)
731 power_supply_changed(hidpp->battery.ps);
737 #define HIDPP_REG_PAIRING_INFORMATION 0xB5
738 #define HIDPP_EXTENDED_PAIRING 0x30
739 #define HIDPP_DEVICE_NAME 0x40
741 static char *hidpp_unifying_get_name(struct hidpp_device *hidpp_dev)
743 struct hidpp_report response;
745 u8 params[1] = { HIDPP_DEVICE_NAME };
749 ret = hidpp_send_rap_command_sync(hidpp_dev,
750 REPORT_ID_HIDPP_SHORT,
751 HIDPP_GET_LONG_REGISTER,
752 HIDPP_REG_PAIRING_INFORMATION,
753 params, 1, &response);
757 len = response.rap.params[1];
759 if (2 + len > sizeof(response.rap.params))
762 if (len < 4) /* logitech devices are usually at least Xddd */
765 name = kzalloc(len + 1, GFP_KERNEL);
769 memcpy(name, &response.rap.params[2], len);
771 /* include the terminating '\0' */
772 hidpp_prefix_name(&name, len + 1);
777 static int hidpp_unifying_get_serial(struct hidpp_device *hidpp, u32 *serial)
779 struct hidpp_report response;
781 u8 params[1] = { HIDPP_EXTENDED_PAIRING };
783 ret = hidpp_send_rap_command_sync(hidpp,
784 REPORT_ID_HIDPP_SHORT,
785 HIDPP_GET_LONG_REGISTER,
786 HIDPP_REG_PAIRING_INFORMATION,
787 params, 1, &response);
792 * We don't care about LE or BE, we will output it as a string
793 * with %4phD, so we need to keep the order.
795 *serial = *((u32 *)&response.rap.params[1]);
799 static int hidpp_unifying_init(struct hidpp_device *hidpp)
801 struct hid_device *hdev = hidpp->hid_dev;
806 ret = hidpp_unifying_get_serial(hidpp, &serial);
810 snprintf(hdev->uniq, sizeof(hdev->uniq), "%04x-%4phD",
811 hdev->product, &serial);
812 dbg_hid("HID++ Unifying: Got serial: %s\n", hdev->uniq);
814 name = hidpp_unifying_get_name(hidpp);
818 snprintf(hdev->name, sizeof(hdev->name), "%s", name);
819 dbg_hid("HID++ Unifying: Got name: %s\n", name);
825 /* -------------------------------------------------------------------------- */
827 /* -------------------------------------------------------------------------- */
829 #define HIDPP_PAGE_ROOT 0x0000
830 #define HIDPP_PAGE_ROOT_IDX 0x00
832 #define CMD_ROOT_GET_FEATURE 0x01
833 #define CMD_ROOT_GET_PROTOCOL_VERSION 0x11
835 static int hidpp_root_get_feature(struct hidpp_device *hidpp, u16 feature,
836 u8 *feature_index, u8 *feature_type)
838 struct hidpp_report response;
840 u8 params[2] = { feature >> 8, feature & 0x00FF };
842 ret = hidpp_send_fap_command_sync(hidpp,
844 CMD_ROOT_GET_FEATURE,
845 params, 2, &response);
849 if (response.fap.params[0] == 0)
852 *feature_index = response.fap.params[0];
853 *feature_type = response.fap.params[1];
858 static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
860 const u8 ping_byte = 0x5a;
861 u8 ping_data[3] = { 0, 0, ping_byte };
862 struct hidpp_report response;
865 ret = hidpp_send_rap_command_sync(hidpp,
866 REPORT_ID_HIDPP_SHORT,
868 CMD_ROOT_GET_PROTOCOL_VERSION,
869 ping_data, sizeof(ping_data), &response);
871 if (ret == HIDPP_ERROR_INVALID_SUBID) {
872 hidpp->protocol_major = 1;
873 hidpp->protocol_minor = 0;
877 /* the device might not be connected */
878 if (ret == HIDPP_ERROR_RESOURCE_ERROR)
882 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
889 if (response.rap.params[2] != ping_byte) {
890 hid_err(hidpp->hid_dev, "%s: ping mismatch 0x%02x != 0x%02x\n",
891 __func__, response.rap.params[2], ping_byte);
895 hidpp->protocol_major = response.rap.params[0];
896 hidpp->protocol_minor = response.rap.params[1];
899 hid_info(hidpp->hid_dev, "HID++ %u.%u device connected.\n",
900 hidpp->protocol_major, hidpp->protocol_minor);
904 /* -------------------------------------------------------------------------- */
905 /* 0x0005: GetDeviceNameType */
906 /* -------------------------------------------------------------------------- */
908 #define HIDPP_PAGE_GET_DEVICE_NAME_TYPE 0x0005
910 #define CMD_GET_DEVICE_NAME_TYPE_GET_COUNT 0x01
911 #define CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME 0x11
912 #define CMD_GET_DEVICE_NAME_TYPE_GET_TYPE 0x21
914 static int hidpp_devicenametype_get_count(struct hidpp_device *hidpp,
915 u8 feature_index, u8 *nameLength)
917 struct hidpp_report response;
920 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
921 CMD_GET_DEVICE_NAME_TYPE_GET_COUNT, NULL, 0, &response);
924 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
931 *nameLength = response.fap.params[0];
936 static int hidpp_devicenametype_get_device_name(struct hidpp_device *hidpp,
937 u8 feature_index, u8 char_index, char *device_name, int len_buf)
939 struct hidpp_report response;
943 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
944 CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME, &char_index, 1,
948 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
955 switch (response.report_id) {
956 case REPORT_ID_HIDPP_VERY_LONG:
957 count = hidpp->very_long_report_length - 4;
959 case REPORT_ID_HIDPP_LONG:
960 count = HIDPP_REPORT_LONG_LENGTH - 4;
962 case REPORT_ID_HIDPP_SHORT:
963 count = HIDPP_REPORT_SHORT_LENGTH - 4;
972 for (i = 0; i < count; i++)
973 device_name[i] = response.fap.params[i];
978 static char *hidpp_get_device_name(struct hidpp_device *hidpp)
987 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_GET_DEVICE_NAME_TYPE,
988 &feature_index, &feature_type);
992 ret = hidpp_devicenametype_get_count(hidpp, feature_index,
997 name = kzalloc(__name_length + 1, GFP_KERNEL);
1001 while (index < __name_length) {
1002 ret = hidpp_devicenametype_get_device_name(hidpp,
1003 feature_index, index, name + index,
1004 __name_length - index);
1012 /* include the terminating '\0' */
1013 hidpp_prefix_name(&name, __name_length + 1);
1018 /* -------------------------------------------------------------------------- */
1019 /* 0x1000: Battery level status */
1020 /* -------------------------------------------------------------------------- */
1022 #define HIDPP_PAGE_BATTERY_LEVEL_STATUS 0x1000
1024 #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS 0x00
1025 #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY 0x10
1027 #define EVENT_BATTERY_LEVEL_STATUS_BROADCAST 0x00
1029 #define FLAG_BATTERY_LEVEL_DISABLE_OSD BIT(0)
1030 #define FLAG_BATTERY_LEVEL_MILEAGE BIT(1)
1031 #define FLAG_BATTERY_LEVEL_RECHARGEABLE BIT(2)
1033 static int hidpp_map_battery_level(int capacity)
1036 return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
1038 * The spec says this should be < 31 but some devices report 30
1039 * with brand new batteries and Windows reports 30 as "Good".
1041 else if (capacity < 30)
1042 return POWER_SUPPLY_CAPACITY_LEVEL_LOW;
1043 else if (capacity < 81)
1044 return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
1045 return POWER_SUPPLY_CAPACITY_LEVEL_FULL;
1048 static int hidpp20_batterylevel_map_status_capacity(u8 data[3], int *capacity,
1054 *capacity = data[0];
1055 *next_capacity = data[1];
1056 *level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
1058 /* When discharging, we can rely on the device reported capacity.
1059 * For all other states the device reports 0 (unknown).
1062 case 0: /* discharging (in use) */
1063 status = POWER_SUPPLY_STATUS_DISCHARGING;
1064 *level = hidpp_map_battery_level(*capacity);
1066 case 1: /* recharging */
1067 status = POWER_SUPPLY_STATUS_CHARGING;
1069 case 2: /* charge in final stage */
1070 status = POWER_SUPPLY_STATUS_CHARGING;
1072 case 3: /* charge complete */
1073 status = POWER_SUPPLY_STATUS_FULL;
1074 *level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
1077 case 4: /* recharging below optimal speed */
1078 status = POWER_SUPPLY_STATUS_CHARGING;
1080 /* 5 = invalid battery type
1082 7 = other charging error */
1084 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1091 static int hidpp20_batterylevel_get_battery_capacity(struct hidpp_device *hidpp,
1098 struct hidpp_report response;
1100 u8 *params = (u8 *)response.fap.params;
1102 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1103 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS,
1104 NULL, 0, &response);
1105 /* Ignore these intermittent errors */
1106 if (ret == HIDPP_ERROR_RESOURCE_ERROR)
1109 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1116 *status = hidpp20_batterylevel_map_status_capacity(params, capacity,
1123 static int hidpp20_batterylevel_get_battery_info(struct hidpp_device *hidpp,
1126 struct hidpp_report response;
1128 u8 *params = (u8 *)response.fap.params;
1129 unsigned int level_count, flags;
1131 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1132 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY,
1133 NULL, 0, &response);
1135 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1142 level_count = params[0];
1145 if (level_count < 10 || !(flags & FLAG_BATTERY_LEVEL_MILEAGE))
1146 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS;
1148 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
1153 static int hidpp20_query_battery_info(struct hidpp_device *hidpp)
1157 int status, capacity, next_capacity, level;
1159 if (hidpp->battery.feature_index == 0xff) {
1160 ret = hidpp_root_get_feature(hidpp,
1161 HIDPP_PAGE_BATTERY_LEVEL_STATUS,
1162 &hidpp->battery.feature_index,
1168 ret = hidpp20_batterylevel_get_battery_capacity(hidpp,
1169 hidpp->battery.feature_index,
1171 &next_capacity, &level);
1175 ret = hidpp20_batterylevel_get_battery_info(hidpp,
1176 hidpp->battery.feature_index);
1180 hidpp->battery.status = status;
1181 hidpp->battery.capacity = capacity;
1182 hidpp->battery.level = level;
1183 /* the capacity is only available when discharging or full */
1184 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
1185 status == POWER_SUPPLY_STATUS_FULL;
1190 static int hidpp20_battery_event(struct hidpp_device *hidpp,
1193 struct hidpp_report *report = (struct hidpp_report *)data;
1194 int status, capacity, next_capacity, level;
1197 if (report->fap.feature_index != hidpp->battery.feature_index ||
1198 report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST)
1201 status = hidpp20_batterylevel_map_status_capacity(report->fap.params,
1206 /* the capacity is only available when discharging or full */
1207 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
1208 status == POWER_SUPPLY_STATUS_FULL;
1210 changed = capacity != hidpp->battery.capacity ||
1211 level != hidpp->battery.level ||
1212 status != hidpp->battery.status;
1215 hidpp->battery.level = level;
1216 hidpp->battery.capacity = capacity;
1217 hidpp->battery.status = status;
1218 if (hidpp->battery.ps)
1219 power_supply_changed(hidpp->battery.ps);
1225 static enum power_supply_property hidpp_battery_props[] = {
1226 POWER_SUPPLY_PROP_ONLINE,
1227 POWER_SUPPLY_PROP_STATUS,
1228 POWER_SUPPLY_PROP_SCOPE,
1229 POWER_SUPPLY_PROP_MODEL_NAME,
1230 POWER_SUPPLY_PROP_MANUFACTURER,
1231 POWER_SUPPLY_PROP_SERIAL_NUMBER,
1232 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY, */
1233 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY_LEVEL, */
1236 static int hidpp_battery_get_property(struct power_supply *psy,
1237 enum power_supply_property psp,
1238 union power_supply_propval *val)
1240 struct hidpp_device *hidpp = power_supply_get_drvdata(psy);
1244 case POWER_SUPPLY_PROP_STATUS:
1245 val->intval = hidpp->battery.status;
1247 case POWER_SUPPLY_PROP_CAPACITY:
1248 val->intval = hidpp->battery.capacity;
1250 case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
1251 val->intval = hidpp->battery.level;
1253 case POWER_SUPPLY_PROP_SCOPE:
1254 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1256 case POWER_SUPPLY_PROP_ONLINE:
1257 val->intval = hidpp->battery.online;
1259 case POWER_SUPPLY_PROP_MODEL_NAME:
1260 if (!strncmp(hidpp->name, "Logitech ", 9))
1261 val->strval = hidpp->name + 9;
1263 val->strval = hidpp->name;
1265 case POWER_SUPPLY_PROP_MANUFACTURER:
1266 val->strval = "Logitech";
1268 case POWER_SUPPLY_PROP_SERIAL_NUMBER:
1269 val->strval = hidpp->hid_dev->uniq;
1279 /* -------------------------------------------------------------------------- */
1280 /* 0x2120: Hi-resolution scrolling */
1281 /* -------------------------------------------------------------------------- */
1283 #define HIDPP_PAGE_HI_RESOLUTION_SCROLLING 0x2120
1285 #define CMD_HI_RESOLUTION_SCROLLING_SET_HIGHRES_SCROLLING_MODE 0x10
1287 static int hidpp_hrs_set_highres_scrolling_mode(struct hidpp_device *hidpp,
1288 bool enabled, u8 *multiplier)
1294 struct hidpp_report response;
1296 ret = hidpp_root_get_feature(hidpp,
1297 HIDPP_PAGE_HI_RESOLUTION_SCROLLING,
1303 params[0] = enabled ? BIT(0) : 0;
1304 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1305 CMD_HI_RESOLUTION_SCROLLING_SET_HIGHRES_SCROLLING_MODE,
1306 params, sizeof(params), &response);
1309 *multiplier = response.fap.params[1];
1313 /* -------------------------------------------------------------------------- */
1314 /* 0x2121: HiRes Wheel */
1315 /* -------------------------------------------------------------------------- */
1317 #define HIDPP_PAGE_HIRES_WHEEL 0x2121
1319 #define CMD_HIRES_WHEEL_GET_WHEEL_CAPABILITY 0x00
1320 #define CMD_HIRES_WHEEL_SET_WHEEL_MODE 0x20
1322 static int hidpp_hrw_get_wheel_capability(struct hidpp_device *hidpp,
1328 struct hidpp_report response;
1330 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_HIRES_WHEEL,
1331 &feature_index, &feature_type);
1333 goto return_default;
1335 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1336 CMD_HIRES_WHEEL_GET_WHEEL_CAPABILITY,
1337 NULL, 0, &response);
1339 goto return_default;
1341 *multiplier = response.fap.params[0];
1344 hid_warn(hidpp->hid_dev,
1345 "Couldn't get wheel multiplier (error %d)\n", ret);
1349 static int hidpp_hrw_set_wheel_mode(struct hidpp_device *hidpp, bool invert,
1350 bool high_resolution, bool use_hidpp)
1356 struct hidpp_report response;
1358 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_HIRES_WHEEL,
1359 &feature_index, &feature_type);
1363 params[0] = (invert ? BIT(2) : 0) |
1364 (high_resolution ? BIT(1) : 0) |
1365 (use_hidpp ? BIT(0) : 0);
1367 return hidpp_send_fap_command_sync(hidpp, feature_index,
1368 CMD_HIRES_WHEEL_SET_WHEEL_MODE,
1369 params, sizeof(params), &response);
1372 /* -------------------------------------------------------------------------- */
1373 /* 0x4301: Solar Keyboard */
1374 /* -------------------------------------------------------------------------- */
1376 #define HIDPP_PAGE_SOLAR_KEYBOARD 0x4301
1378 #define CMD_SOLAR_SET_LIGHT_MEASURE 0x00
1380 #define EVENT_SOLAR_BATTERY_BROADCAST 0x00
1381 #define EVENT_SOLAR_BATTERY_LIGHT_MEASURE 0x10
1382 #define EVENT_SOLAR_CHECK_LIGHT_BUTTON 0x20
1384 static int hidpp_solar_request_battery_event(struct hidpp_device *hidpp)
1386 struct hidpp_report response;
1387 u8 params[2] = { 1, 1 };
1391 if (hidpp->battery.feature_index == 0xff) {
1392 ret = hidpp_root_get_feature(hidpp,
1393 HIDPP_PAGE_SOLAR_KEYBOARD,
1394 &hidpp->battery.solar_feature_index,
1400 ret = hidpp_send_fap_command_sync(hidpp,
1401 hidpp->battery.solar_feature_index,
1402 CMD_SOLAR_SET_LIGHT_MEASURE,
1403 params, 2, &response);
1405 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1412 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
1417 static int hidpp_solar_battery_event(struct hidpp_device *hidpp,
1420 struct hidpp_report *report = (struct hidpp_report *)data;
1421 int capacity, lux, status;
1424 function = report->fap.funcindex_clientid;
1427 if (report->fap.feature_index != hidpp->battery.solar_feature_index ||
1428 !(function == EVENT_SOLAR_BATTERY_BROADCAST ||
1429 function == EVENT_SOLAR_BATTERY_LIGHT_MEASURE ||
1430 function == EVENT_SOLAR_CHECK_LIGHT_BUTTON))
1433 capacity = report->fap.params[0];
1436 case EVENT_SOLAR_BATTERY_LIGHT_MEASURE:
1437 lux = (report->fap.params[1] << 8) | report->fap.params[2];
1439 status = POWER_SUPPLY_STATUS_CHARGING;
1441 status = POWER_SUPPLY_STATUS_DISCHARGING;
1443 case EVENT_SOLAR_CHECK_LIGHT_BUTTON:
1445 if (capacity < hidpp->battery.capacity)
1446 status = POWER_SUPPLY_STATUS_DISCHARGING;
1448 status = POWER_SUPPLY_STATUS_CHARGING;
1452 if (capacity == 100)
1453 status = POWER_SUPPLY_STATUS_FULL;
1455 hidpp->battery.online = true;
1456 if (capacity != hidpp->battery.capacity ||
1457 status != hidpp->battery.status) {
1458 hidpp->battery.capacity = capacity;
1459 hidpp->battery.status = status;
1460 if (hidpp->battery.ps)
1461 power_supply_changed(hidpp->battery.ps);
1467 /* -------------------------------------------------------------------------- */
1468 /* 0x6010: Touchpad FW items */
1469 /* -------------------------------------------------------------------------- */
1471 #define HIDPP_PAGE_TOUCHPAD_FW_ITEMS 0x6010
1473 #define CMD_TOUCHPAD_FW_ITEMS_SET 0x10
1475 struct hidpp_touchpad_fw_items {
1477 uint8_t desired_state;
1483 * send a set state command to the device by reading the current items->state
1484 * field. items is then filled with the current state.
1486 static int hidpp_touchpad_fw_items_set(struct hidpp_device *hidpp,
1488 struct hidpp_touchpad_fw_items *items)
1490 struct hidpp_report response;
1492 u8 *params = (u8 *)response.fap.params;
1494 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1495 CMD_TOUCHPAD_FW_ITEMS_SET, &items->state, 1, &response);
1498 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1505 items->presence = params[0];
1506 items->desired_state = params[1];
1507 items->state = params[2];
1508 items->persistent = params[3];
1513 /* -------------------------------------------------------------------------- */
1514 /* 0x6100: TouchPadRawXY */
1515 /* -------------------------------------------------------------------------- */
1517 #define HIDPP_PAGE_TOUCHPAD_RAW_XY 0x6100
1519 #define CMD_TOUCHPAD_GET_RAW_INFO 0x01
1520 #define CMD_TOUCHPAD_SET_RAW_REPORT_STATE 0x21
1522 #define EVENT_TOUCHPAD_RAW_XY 0x00
1524 #define TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT 0x01
1525 #define TOUCHPAD_RAW_XY_ORIGIN_UPPER_LEFT 0x03
1527 struct hidpp_touchpad_raw_info {
1538 struct hidpp_touchpad_raw_xy_finger {
1548 struct hidpp_touchpad_raw_xy {
1550 struct hidpp_touchpad_raw_xy_finger fingers[2];
1557 static int hidpp_touchpad_get_raw_info(struct hidpp_device *hidpp,
1558 u8 feature_index, struct hidpp_touchpad_raw_info *raw_info)
1560 struct hidpp_report response;
1562 u8 *params = (u8 *)response.fap.params;
1564 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1565 CMD_TOUCHPAD_GET_RAW_INFO, NULL, 0, &response);
1568 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1575 raw_info->x_size = get_unaligned_be16(¶ms[0]);
1576 raw_info->y_size = get_unaligned_be16(¶ms[2]);
1577 raw_info->z_range = params[4];
1578 raw_info->area_range = params[5];
1579 raw_info->maxcontacts = params[7];
1580 raw_info->origin = params[8];
1581 /* res is given in unit per inch */
1582 raw_info->res = get_unaligned_be16(¶ms[13]) * 2 / 51;
1587 static int hidpp_touchpad_set_raw_report_state(struct hidpp_device *hidpp_dev,
1588 u8 feature_index, bool send_raw_reports,
1589 bool sensor_enhanced_settings)
1591 struct hidpp_report response;
1595 * bit 0 - enable raw
1596 * bit 1 - 16bit Z, no area
1597 * bit 2 - enhanced sensitivity
1598 * bit 3 - width, height (4 bits each) instead of area
1599 * bit 4 - send raw + gestures (degrades smoothness)
1600 * remaining bits - reserved
1602 u8 params = send_raw_reports | (sensor_enhanced_settings << 2);
1604 return hidpp_send_fap_command_sync(hidpp_dev, feature_index,
1605 CMD_TOUCHPAD_SET_RAW_REPORT_STATE, ¶ms, 1, &response);
1608 static void hidpp_touchpad_touch_event(u8 *data,
1609 struct hidpp_touchpad_raw_xy_finger *finger)
1611 u8 x_m = data[0] << 2;
1612 u8 y_m = data[2] << 2;
1614 finger->x = x_m << 6 | data[1];
1615 finger->y = y_m << 6 | data[3];
1617 finger->contact_type = data[0] >> 6;
1618 finger->contact_status = data[2] >> 6;
1620 finger->z = data[4];
1621 finger->area = data[5];
1622 finger->finger_id = data[6] >> 4;
1625 static void hidpp_touchpad_raw_xy_event(struct hidpp_device *hidpp_dev,
1626 u8 *data, struct hidpp_touchpad_raw_xy *raw_xy)
1628 memset(raw_xy, 0, sizeof(struct hidpp_touchpad_raw_xy));
1629 raw_xy->end_of_frame = data[8] & 0x01;
1630 raw_xy->spurious_flag = (data[8] >> 1) & 0x01;
1631 raw_xy->finger_count = data[15] & 0x0f;
1632 raw_xy->button = (data[8] >> 2) & 0x01;
1634 if (raw_xy->finger_count) {
1635 hidpp_touchpad_touch_event(&data[2], &raw_xy->fingers[0]);
1636 hidpp_touchpad_touch_event(&data[9], &raw_xy->fingers[1]);
1640 /* -------------------------------------------------------------------------- */
1641 /* 0x8123: Force feedback support */
1642 /* -------------------------------------------------------------------------- */
1644 #define HIDPP_FF_GET_INFO 0x01
1645 #define HIDPP_FF_RESET_ALL 0x11
1646 #define HIDPP_FF_DOWNLOAD_EFFECT 0x21
1647 #define HIDPP_FF_SET_EFFECT_STATE 0x31
1648 #define HIDPP_FF_DESTROY_EFFECT 0x41
1649 #define HIDPP_FF_GET_APERTURE 0x51
1650 #define HIDPP_FF_SET_APERTURE 0x61
1651 #define HIDPP_FF_GET_GLOBAL_GAINS 0x71
1652 #define HIDPP_FF_SET_GLOBAL_GAINS 0x81
1654 #define HIDPP_FF_EFFECT_STATE_GET 0x00
1655 #define HIDPP_FF_EFFECT_STATE_STOP 0x01
1656 #define HIDPP_FF_EFFECT_STATE_PLAY 0x02
1657 #define HIDPP_FF_EFFECT_STATE_PAUSE 0x03
1659 #define HIDPP_FF_EFFECT_CONSTANT 0x00
1660 #define HIDPP_FF_EFFECT_PERIODIC_SINE 0x01
1661 #define HIDPP_FF_EFFECT_PERIODIC_SQUARE 0x02
1662 #define HIDPP_FF_EFFECT_PERIODIC_TRIANGLE 0x03
1663 #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP 0x04
1664 #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN 0x05
1665 #define HIDPP_FF_EFFECT_SPRING 0x06
1666 #define HIDPP_FF_EFFECT_DAMPER 0x07
1667 #define HIDPP_FF_EFFECT_FRICTION 0x08
1668 #define HIDPP_FF_EFFECT_INERTIA 0x09
1669 #define HIDPP_FF_EFFECT_RAMP 0x0A
1671 #define HIDPP_FF_EFFECT_AUTOSTART 0x80
1673 #define HIDPP_FF_EFFECTID_NONE -1
1674 #define HIDPP_FF_EFFECTID_AUTOCENTER -2
1676 #define HIDPP_FF_MAX_PARAMS 20
1677 #define HIDPP_FF_RESERVED_SLOTS 1
1679 struct hidpp_ff_private_data {
1680 struct hidpp_device *hidpp;
1688 struct workqueue_struct *wq;
1689 atomic_t workqueue_size;
1692 struct hidpp_ff_work_data {
1693 struct work_struct work;
1694 struct hidpp_ff_private_data *data;
1697 u8 params[HIDPP_FF_MAX_PARAMS];
1701 static const signed short hidpp_ff_effects[] = {
1716 static const signed short hidpp_ff_effects_v2[] = {
1723 static const u8 HIDPP_FF_CONDITION_CMDS[] = {
1724 HIDPP_FF_EFFECT_SPRING,
1725 HIDPP_FF_EFFECT_FRICTION,
1726 HIDPP_FF_EFFECT_DAMPER,
1727 HIDPP_FF_EFFECT_INERTIA
1730 static const char *HIDPP_FF_CONDITION_NAMES[] = {
1738 static u8 hidpp_ff_find_effect(struct hidpp_ff_private_data *data, int effect_id)
1742 for (i = 0; i < data->num_effects; i++)
1743 if (data->effect_ids[i] == effect_id)
1749 static void hidpp_ff_work_handler(struct work_struct *w)
1751 struct hidpp_ff_work_data *wd = container_of(w, struct hidpp_ff_work_data, work);
1752 struct hidpp_ff_private_data *data = wd->data;
1753 struct hidpp_report response;
1757 /* add slot number if needed */
1758 switch (wd->effect_id) {
1759 case HIDPP_FF_EFFECTID_AUTOCENTER:
1760 wd->params[0] = data->slot_autocenter;
1762 case HIDPP_FF_EFFECTID_NONE:
1763 /* leave slot as zero */
1766 /* find current slot for effect */
1767 wd->params[0] = hidpp_ff_find_effect(data, wd->effect_id);
1771 /* send command and wait for reply */
1772 ret = hidpp_send_fap_command_sync(data->hidpp, data->feature_index,
1773 wd->command, wd->params, wd->size, &response);
1776 hid_err(data->hidpp->hid_dev, "Failed to send command to device!\n");
1780 /* parse return data */
1781 switch (wd->command) {
1782 case HIDPP_FF_DOWNLOAD_EFFECT:
1783 slot = response.fap.params[0];
1784 if (slot > 0 && slot <= data->num_effects) {
1785 if (wd->effect_id >= 0)
1786 /* regular effect uploaded */
1787 data->effect_ids[slot-1] = wd->effect_id;
1788 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
1789 /* autocenter spring uploaded */
1790 data->slot_autocenter = slot;
1793 case HIDPP_FF_DESTROY_EFFECT:
1794 if (wd->effect_id >= 0)
1795 /* regular effect destroyed */
1796 data->effect_ids[wd->params[0]-1] = -1;
1797 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
1798 /* autocenter spring destoyed */
1799 data->slot_autocenter = 0;
1801 case HIDPP_FF_SET_GLOBAL_GAINS:
1802 data->gain = (wd->params[0] << 8) + wd->params[1];
1804 case HIDPP_FF_SET_APERTURE:
1805 data->range = (wd->params[0] << 8) + wd->params[1];
1808 /* no action needed */
1813 atomic_dec(&data->workqueue_size);
1817 static int hidpp_ff_queue_work(struct hidpp_ff_private_data *data, int effect_id, u8 command, u8 *params, u8 size)
1819 struct hidpp_ff_work_data *wd = kzalloc(sizeof(*wd), GFP_KERNEL);
1825 INIT_WORK(&wd->work, hidpp_ff_work_handler);
1828 wd->effect_id = effect_id;
1829 wd->command = command;
1831 memcpy(wd->params, params, size);
1833 atomic_inc(&data->workqueue_size);
1834 queue_work(data->wq, &wd->work);
1836 /* warn about excessive queue size */
1837 s = atomic_read(&data->workqueue_size);
1838 if (s >= 20 && s % 20 == 0)
1839 hid_warn(data->hidpp->hid_dev, "Force feedback command queue contains %d commands, causing substantial delays!", s);
1844 static int hidpp_ff_upload_effect(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old)
1846 struct hidpp_ff_private_data *data = dev->ff->private;
1851 /* set common parameters */
1852 params[2] = effect->replay.length >> 8;
1853 params[3] = effect->replay.length & 255;
1854 params[4] = effect->replay.delay >> 8;
1855 params[5] = effect->replay.delay & 255;
1857 switch (effect->type) {
1859 force = (effect->u.constant.level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1860 params[1] = HIDPP_FF_EFFECT_CONSTANT;
1861 params[6] = force >> 8;
1862 params[7] = force & 255;
1863 params[8] = effect->u.constant.envelope.attack_level >> 7;
1864 params[9] = effect->u.constant.envelope.attack_length >> 8;
1865 params[10] = effect->u.constant.envelope.attack_length & 255;
1866 params[11] = effect->u.constant.envelope.fade_level >> 7;
1867 params[12] = effect->u.constant.envelope.fade_length >> 8;
1868 params[13] = effect->u.constant.envelope.fade_length & 255;
1870 dbg_hid("Uploading constant force level=%d in dir %d = %d\n",
1871 effect->u.constant.level,
1872 effect->direction, force);
1873 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1874 effect->u.constant.envelope.attack_level,
1875 effect->u.constant.envelope.attack_length,
1876 effect->u.constant.envelope.fade_level,
1877 effect->u.constant.envelope.fade_length);
1881 switch (effect->u.periodic.waveform) {
1883 params[1] = HIDPP_FF_EFFECT_PERIODIC_SINE;
1886 params[1] = HIDPP_FF_EFFECT_PERIODIC_SQUARE;
1889 params[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP;
1892 params[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN;
1895 params[1] = HIDPP_FF_EFFECT_PERIODIC_TRIANGLE;
1898 hid_err(data->hidpp->hid_dev, "Unexpected periodic waveform type %i!\n", effect->u.periodic.waveform);
1901 force = (effect->u.periodic.magnitude * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1902 params[6] = effect->u.periodic.magnitude >> 8;
1903 params[7] = effect->u.periodic.magnitude & 255;
1904 params[8] = effect->u.periodic.offset >> 8;
1905 params[9] = effect->u.periodic.offset & 255;
1906 params[10] = effect->u.periodic.period >> 8;
1907 params[11] = effect->u.periodic.period & 255;
1908 params[12] = effect->u.periodic.phase >> 8;
1909 params[13] = effect->u.periodic.phase & 255;
1910 params[14] = effect->u.periodic.envelope.attack_level >> 7;
1911 params[15] = effect->u.periodic.envelope.attack_length >> 8;
1912 params[16] = effect->u.periodic.envelope.attack_length & 255;
1913 params[17] = effect->u.periodic.envelope.fade_level >> 7;
1914 params[18] = effect->u.periodic.envelope.fade_length >> 8;
1915 params[19] = effect->u.periodic.envelope.fade_length & 255;
1917 dbg_hid("Uploading periodic force mag=%d/dir=%d, offset=%d, period=%d ms, phase=%d\n",
1918 effect->u.periodic.magnitude, effect->direction,
1919 effect->u.periodic.offset,
1920 effect->u.periodic.period,
1921 effect->u.periodic.phase);
1922 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1923 effect->u.periodic.envelope.attack_level,
1924 effect->u.periodic.envelope.attack_length,
1925 effect->u.periodic.envelope.fade_level,
1926 effect->u.periodic.envelope.fade_length);
1930 params[1] = HIDPP_FF_EFFECT_RAMP;
1931 force = (effect->u.ramp.start_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1932 params[6] = force >> 8;
1933 params[7] = force & 255;
1934 force = (effect->u.ramp.end_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1935 params[8] = force >> 8;
1936 params[9] = force & 255;
1937 params[10] = effect->u.ramp.envelope.attack_level >> 7;
1938 params[11] = effect->u.ramp.envelope.attack_length >> 8;
1939 params[12] = effect->u.ramp.envelope.attack_length & 255;
1940 params[13] = effect->u.ramp.envelope.fade_level >> 7;
1941 params[14] = effect->u.ramp.envelope.fade_length >> 8;
1942 params[15] = effect->u.ramp.envelope.fade_length & 255;
1944 dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n",
1945 effect->u.ramp.start_level,
1946 effect->u.ramp.end_level,
1947 effect->direction, force);
1948 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1949 effect->u.ramp.envelope.attack_level,
1950 effect->u.ramp.envelope.attack_length,
1951 effect->u.ramp.envelope.fade_level,
1952 effect->u.ramp.envelope.fade_length);
1958 params[1] = HIDPP_FF_CONDITION_CMDS[effect->type - FF_SPRING];
1959 params[6] = effect->u.condition[0].left_saturation >> 9;
1960 params[7] = (effect->u.condition[0].left_saturation >> 1) & 255;
1961 params[8] = effect->u.condition[0].left_coeff >> 8;
1962 params[9] = effect->u.condition[0].left_coeff & 255;
1963 params[10] = effect->u.condition[0].deadband >> 9;
1964 params[11] = (effect->u.condition[0].deadband >> 1) & 255;
1965 params[12] = effect->u.condition[0].center >> 8;
1966 params[13] = effect->u.condition[0].center & 255;
1967 params[14] = effect->u.condition[0].right_coeff >> 8;
1968 params[15] = effect->u.condition[0].right_coeff & 255;
1969 params[16] = effect->u.condition[0].right_saturation >> 9;
1970 params[17] = (effect->u.condition[0].right_saturation >> 1) & 255;
1972 dbg_hid("Uploading %s force left coeff=%d, left sat=%d, right coeff=%d, right sat=%d\n",
1973 HIDPP_FF_CONDITION_NAMES[effect->type - FF_SPRING],
1974 effect->u.condition[0].left_coeff,
1975 effect->u.condition[0].left_saturation,
1976 effect->u.condition[0].right_coeff,
1977 effect->u.condition[0].right_saturation);
1978 dbg_hid(" deadband=%d, center=%d\n",
1979 effect->u.condition[0].deadband,
1980 effect->u.condition[0].center);
1983 hid_err(data->hidpp->hid_dev, "Unexpected force type %i!\n", effect->type);
1987 return hidpp_ff_queue_work(data, effect->id, HIDPP_FF_DOWNLOAD_EFFECT, params, size);
1990 static int hidpp_ff_playback(struct input_dev *dev, int effect_id, int value)
1992 struct hidpp_ff_private_data *data = dev->ff->private;
1995 params[1] = value ? HIDPP_FF_EFFECT_STATE_PLAY : HIDPP_FF_EFFECT_STATE_STOP;
1997 dbg_hid("St%sing playback of effect %d.\n", value?"art":"opp", effect_id);
1999 return hidpp_ff_queue_work(data, effect_id, HIDPP_FF_SET_EFFECT_STATE, params, ARRAY_SIZE(params));
2002 static int hidpp_ff_erase_effect(struct input_dev *dev, int effect_id)
2004 struct hidpp_ff_private_data *data = dev->ff->private;
2007 dbg_hid("Erasing effect %d.\n", effect_id);
2009 return hidpp_ff_queue_work(data, effect_id, HIDPP_FF_DESTROY_EFFECT, &slot, 1);
2012 static void hidpp_ff_set_autocenter(struct input_dev *dev, u16 magnitude)
2014 struct hidpp_ff_private_data *data = dev->ff->private;
2017 dbg_hid("Setting autocenter to %d.\n", magnitude);
2019 /* start a standard spring effect */
2020 params[1] = HIDPP_FF_EFFECT_SPRING | HIDPP_FF_EFFECT_AUTOSTART;
2021 /* zero delay and duration */
2022 params[2] = params[3] = params[4] = params[5] = 0;
2023 /* set coeff to 25% of saturation */
2024 params[8] = params[14] = magnitude >> 11;
2025 params[9] = params[15] = (magnitude >> 3) & 255;
2026 params[6] = params[16] = magnitude >> 9;
2027 params[7] = params[17] = (magnitude >> 1) & 255;
2028 /* zero deadband and center */
2029 params[10] = params[11] = params[12] = params[13] = 0;
2031 hidpp_ff_queue_work(data, HIDPP_FF_EFFECTID_AUTOCENTER, HIDPP_FF_DOWNLOAD_EFFECT, params, ARRAY_SIZE(params));
2034 static void hidpp_ff_set_gain(struct input_dev *dev, u16 gain)
2036 struct hidpp_ff_private_data *data = dev->ff->private;
2039 dbg_hid("Setting gain to %d.\n", gain);
2041 params[0] = gain >> 8;
2042 params[1] = gain & 255;
2043 params[2] = 0; /* no boost */
2046 hidpp_ff_queue_work(data, HIDPP_FF_EFFECTID_NONE, HIDPP_FF_SET_GLOBAL_GAINS, params, ARRAY_SIZE(params));
2049 static ssize_t hidpp_ff_range_show(struct device *dev, struct device_attribute *attr, char *buf)
2051 struct hid_device *hid = to_hid_device(dev);
2052 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2053 struct input_dev *idev = hidinput->input;
2054 struct hidpp_ff_private_data *data = idev->ff->private;
2056 return scnprintf(buf, PAGE_SIZE, "%u\n", data->range);
2059 static ssize_t hidpp_ff_range_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
2061 struct hid_device *hid = to_hid_device(dev);
2062 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2063 struct input_dev *idev = hidinput->input;
2064 struct hidpp_ff_private_data *data = idev->ff->private;
2066 int range = simple_strtoul(buf, NULL, 10);
2068 range = clamp(range, 180, 900);
2070 params[0] = range >> 8;
2071 params[1] = range & 0x00FF;
2073 hidpp_ff_queue_work(data, -1, HIDPP_FF_SET_APERTURE, params, ARRAY_SIZE(params));
2078 static DEVICE_ATTR(range, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, hidpp_ff_range_show, hidpp_ff_range_store);
2080 static void hidpp_ff_destroy(struct ff_device *ff)
2082 struct hidpp_ff_private_data *data = ff->private;
2084 kfree(data->effect_ids);
2087 static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index)
2089 struct hid_device *hid = hidpp->hid_dev;
2090 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2091 struct input_dev *dev = hidinput->input;
2092 const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
2093 const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice);
2094 struct ff_device *ff;
2095 struct hidpp_report response;
2096 struct hidpp_ff_private_data *data;
2097 int error, j, num_slots;
2101 hid_err(hid, "Struct input_dev not set!\n");
2105 /* Get firmware release */
2106 version = bcdDevice & 255;
2108 /* Set supported force feedback capabilities */
2109 for (j = 0; hidpp_ff_effects[j] >= 0; j++)
2110 set_bit(hidpp_ff_effects[j], dev->ffbit);
2112 for (j = 0; hidpp_ff_effects_v2[j] >= 0; j++)
2113 set_bit(hidpp_ff_effects_v2[j], dev->ffbit);
2115 /* Read number of slots available in device */
2116 error = hidpp_send_fap_command_sync(hidpp, feature_index,
2117 HIDPP_FF_GET_INFO, NULL, 0, &response);
2121 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
2126 num_slots = response.fap.params[0] - HIDPP_FF_RESERVED_SLOTS;
2128 error = input_ff_create(dev, num_slots);
2131 hid_err(dev, "Failed to create FF device!\n");
2135 data = kzalloc(sizeof(*data), GFP_KERNEL);
2138 data->effect_ids = kcalloc(num_slots, sizeof(int), GFP_KERNEL);
2139 if (!data->effect_ids) {
2143 data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue");
2145 kfree(data->effect_ids);
2150 data->hidpp = hidpp;
2151 data->feature_index = feature_index;
2152 data->version = version;
2153 data->slot_autocenter = 0;
2154 data->num_effects = num_slots;
2155 for (j = 0; j < num_slots; j++)
2156 data->effect_ids[j] = -1;
2161 ff->upload = hidpp_ff_upload_effect;
2162 ff->erase = hidpp_ff_erase_effect;
2163 ff->playback = hidpp_ff_playback;
2164 ff->set_gain = hidpp_ff_set_gain;
2165 ff->set_autocenter = hidpp_ff_set_autocenter;
2166 ff->destroy = hidpp_ff_destroy;
2169 /* reset all forces */
2170 error = hidpp_send_fap_command_sync(hidpp, feature_index,
2171 HIDPP_FF_RESET_ALL, NULL, 0, &response);
2173 /* Read current Range */
2174 error = hidpp_send_fap_command_sync(hidpp, feature_index,
2175 HIDPP_FF_GET_APERTURE, NULL, 0, &response);
2177 hid_warn(hidpp->hid_dev, "Failed to read range from device!\n");
2178 data->range = error ? 900 : get_unaligned_be16(&response.fap.params[0]);
2180 /* Create sysfs interface */
2181 error = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range);
2183 hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d!\n", error);
2185 /* Read the current gain values */
2186 error = hidpp_send_fap_command_sync(hidpp, feature_index,
2187 HIDPP_FF_GET_GLOBAL_GAINS, NULL, 0, &response);
2189 hid_warn(hidpp->hid_dev, "Failed to read gain values from device!\n");
2190 data->gain = error ? 0xffff : get_unaligned_be16(&response.fap.params[0]);
2191 /* ignore boost value at response.fap.params[2] */
2193 /* init the hardware command queue */
2194 atomic_set(&data->workqueue_size, 0);
2196 /* initialize with zero autocenter to get wheel in usable state */
2197 hidpp_ff_set_autocenter(dev, 0);
2199 hid_info(hid, "Force feedback support loaded (firmware release %d).\n",
2205 static int hidpp_ff_deinit(struct hid_device *hid)
2207 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2208 struct input_dev *dev = hidinput->input;
2209 struct hidpp_ff_private_data *data;
2212 hid_err(hid, "Struct input_dev not found!\n");
2216 hid_info(hid, "Unloading HID++ force feedback.\n");
2217 data = dev->ff->private;
2219 hid_err(hid, "Private data not found!\n");
2223 destroy_workqueue(data->wq);
2224 device_remove_file(&hid->dev, &dev_attr_range);
2230 /* ************************************************************************** */
2232 /* Device Support */
2234 /* ************************************************************************** */
2236 /* -------------------------------------------------------------------------- */
2237 /* Touchpad HID++ devices */
2238 /* -------------------------------------------------------------------------- */
2240 #define WTP_MANUAL_RESOLUTION 39
2245 u8 mt_feature_index;
2246 u8 button_feature_index;
2249 unsigned int resolution;
2252 static int wtp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
2253 struct hid_field *field, struct hid_usage *usage,
2254 unsigned long **bit, int *max)
2259 static void wtp_populate_input(struct hidpp_device *hidpp,
2260 struct input_dev *input_dev)
2262 struct wtp_data *wd = hidpp->private_data;
2264 __set_bit(EV_ABS, input_dev->evbit);
2265 __set_bit(EV_KEY, input_dev->evbit);
2266 __clear_bit(EV_REL, input_dev->evbit);
2267 __clear_bit(EV_LED, input_dev->evbit);
2269 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0);
2270 input_abs_set_res(input_dev, ABS_MT_POSITION_X, wd->resolution);
2271 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0);
2272 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, wd->resolution);
2274 /* Max pressure is not given by the devices, pick one */
2275 input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 50, 0, 0);
2277 input_set_capability(input_dev, EV_KEY, BTN_LEFT);
2279 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS)
2280 input_set_capability(input_dev, EV_KEY, BTN_RIGHT);
2282 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
2284 input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER |
2285 INPUT_MT_DROP_UNUSED);
2288 static void wtp_touch_event(struct hidpp_device *hidpp,
2289 struct hidpp_touchpad_raw_xy_finger *touch_report)
2291 struct wtp_data *wd = hidpp->private_data;
2294 if (!touch_report->finger_id || touch_report->contact_type)
2295 /* no actual data */
2298 slot = input_mt_get_slot_by_key(hidpp->input, touch_report->finger_id);
2300 input_mt_slot(hidpp->input, slot);
2301 input_mt_report_slot_state(hidpp->input, MT_TOOL_FINGER,
2302 touch_report->contact_status);
2303 if (touch_report->contact_status) {
2304 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_X,
2306 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_Y,
2307 wd->flip_y ? wd->y_size - touch_report->y :
2309 input_event(hidpp->input, EV_ABS, ABS_MT_PRESSURE,
2310 touch_report->area);
2314 static void wtp_send_raw_xy_event(struct hidpp_device *hidpp,
2315 struct hidpp_touchpad_raw_xy *raw)
2319 for (i = 0; i < 2; i++)
2320 wtp_touch_event(hidpp, &(raw->fingers[i]));
2322 if (raw->end_of_frame &&
2323 !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS))
2324 input_event(hidpp->input, EV_KEY, BTN_LEFT, raw->button);
2326 if (raw->end_of_frame || raw->finger_count <= 2) {
2327 input_mt_sync_frame(hidpp->input);
2328 input_sync(hidpp->input);
2332 static int wtp_mouse_raw_xy_event(struct hidpp_device *hidpp, u8 *data)
2334 struct wtp_data *wd = hidpp->private_data;
2335 u8 c1_area = ((data[7] & 0xf) * (data[7] & 0xf) +
2336 (data[7] >> 4) * (data[7] >> 4)) / 2;
2337 u8 c2_area = ((data[13] & 0xf) * (data[13] & 0xf) +
2338 (data[13] >> 4) * (data[13] >> 4)) / 2;
2339 struct hidpp_touchpad_raw_xy raw = {
2340 .timestamp = data[1],
2344 .contact_status = !!data[7],
2345 .x = get_unaligned_le16(&data[3]),
2346 .y = get_unaligned_le16(&data[5]),
2349 .finger_id = data[2],
2352 .contact_status = !!data[13],
2353 .x = get_unaligned_le16(&data[9]),
2354 .y = get_unaligned_le16(&data[11]),
2357 .finger_id = data[8],
2360 .finger_count = wd->maxcontacts,
2362 .end_of_frame = (data[0] >> 7) == 0,
2363 .button = data[0] & 0x01,
2366 wtp_send_raw_xy_event(hidpp, &raw);
2371 static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size)
2373 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2374 struct wtp_data *wd = hidpp->private_data;
2375 struct hidpp_report *report = (struct hidpp_report *)data;
2376 struct hidpp_touchpad_raw_xy raw;
2378 if (!wd || !hidpp->input)
2384 hid_err(hdev, "Received HID report of bad size (%d)",
2388 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) {
2389 input_event(hidpp->input, EV_KEY, BTN_LEFT,
2390 !!(data[1] & 0x01));
2391 input_event(hidpp->input, EV_KEY, BTN_RIGHT,
2392 !!(data[1] & 0x02));
2393 input_sync(hidpp->input);
2398 return wtp_mouse_raw_xy_event(hidpp, &data[7]);
2400 case REPORT_ID_HIDPP_LONG:
2401 /* size is already checked in hidpp_raw_event. */
2402 if ((report->fap.feature_index != wd->mt_feature_index) ||
2403 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY))
2405 hidpp_touchpad_raw_xy_event(hidpp, data + 4, &raw);
2407 wtp_send_raw_xy_event(hidpp, &raw);
2414 static int wtp_get_config(struct hidpp_device *hidpp)
2416 struct wtp_data *wd = hidpp->private_data;
2417 struct hidpp_touchpad_raw_info raw_info = {0};
2421 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_TOUCHPAD_RAW_XY,
2422 &wd->mt_feature_index, &feature_type);
2424 /* means that the device is not powered up */
2427 ret = hidpp_touchpad_get_raw_info(hidpp, wd->mt_feature_index,
2432 wd->x_size = raw_info.x_size;
2433 wd->y_size = raw_info.y_size;
2434 wd->maxcontacts = raw_info.maxcontacts;
2435 wd->flip_y = raw_info.origin == TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT;
2436 wd->resolution = raw_info.res;
2437 if (!wd->resolution)
2438 wd->resolution = WTP_MANUAL_RESOLUTION;
2443 static int wtp_allocate(struct hid_device *hdev, const struct hid_device_id *id)
2445 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2446 struct wtp_data *wd;
2448 wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data),
2453 hidpp->private_data = wd;
2458 static int wtp_connect(struct hid_device *hdev, bool connected)
2460 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2461 struct wtp_data *wd = hidpp->private_data;
2465 ret = wtp_get_config(hidpp);
2467 hid_err(hdev, "Can not get wtp config: %d\n", ret);
2472 return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index,
2476 /* ------------------------------------------------------------------------- */
2477 /* Logitech M560 devices */
2478 /* ------------------------------------------------------------------------- */
2481 * Logitech M560 protocol overview
2483 * The Logitech M560 mouse, is designed for windows 8. When the middle and/or
2484 * the sides buttons are pressed, it sends some keyboard keys events
2485 * instead of buttons ones.
2486 * To complicate things further, the middle button keys sequence
2487 * is different from the odd press and the even press.
2489 * forward button -> Super_R
2490 * backward button -> Super_L+'d' (press only)
2491 * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
2492 * 2nd time: left-click (press only)
2493 * NB: press-only means that when the button is pressed, the
2494 * KeyPress/ButtonPress and KeyRelease/ButtonRelease events are generated
2495 * together sequentially; instead when the button is released, no event is
2499 * 10<xx>0a 3500af03 (where <xx> is the mouse id),
2500 * the mouse reacts differently:
2501 * - it never sends a keyboard key event
2502 * - for the three mouse button it sends:
2503 * middle button press 11<xx>0a 3500af00...
2504 * side 1 button (forward) press 11<xx>0a 3500b000...
2505 * side 2 button (backward) press 11<xx>0a 3500ae00...
2506 * middle/side1/side2 button release 11<xx>0a 35000000...
2509 static const u8 m560_config_parameter[] = {0x00, 0xaf, 0x03};
2511 /* how buttons are mapped in the report */
2512 #define M560_MOUSE_BTN_LEFT 0x01
2513 #define M560_MOUSE_BTN_RIGHT 0x02
2514 #define M560_MOUSE_BTN_WHEEL_LEFT 0x08
2515 #define M560_MOUSE_BTN_WHEEL_RIGHT 0x10
2517 #define M560_SUB_ID 0x0a
2518 #define M560_BUTTON_MODE_REGISTER 0x35
2520 static int m560_send_config_command(struct hid_device *hdev, bool connected)
2522 struct hidpp_report response;
2523 struct hidpp_device *hidpp_dev;
2525 hidpp_dev = hid_get_drvdata(hdev);
2527 return hidpp_send_rap_command_sync(
2529 REPORT_ID_HIDPP_SHORT,
2531 M560_BUTTON_MODE_REGISTER,
2532 (u8 *)m560_config_parameter,
2533 sizeof(m560_config_parameter),
2538 static int m560_raw_event(struct hid_device *hdev, u8 *data, int size)
2540 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2543 if (!hidpp->input) {
2544 hid_err(hdev, "error in parameter\n");
2549 hid_err(hdev, "error in report\n");
2553 if (data[0] == REPORT_ID_HIDPP_LONG &&
2554 data[2] == M560_SUB_ID && data[6] == 0x00) {
2556 * m560 mouse report for middle, forward and backward button
2559 * data[1] = device-id
2561 * data[5] = 0xaf -> middle
2564 * 0x00 -> release all
2570 input_report_key(hidpp->input, BTN_MIDDLE, 1);
2573 input_report_key(hidpp->input, BTN_FORWARD, 1);
2576 input_report_key(hidpp->input, BTN_BACK, 1);
2579 input_report_key(hidpp->input, BTN_BACK, 0);
2580 input_report_key(hidpp->input, BTN_FORWARD, 0);
2581 input_report_key(hidpp->input, BTN_MIDDLE, 0);
2584 hid_err(hdev, "error in report\n");
2587 input_sync(hidpp->input);
2589 } else if (data[0] == 0x02) {
2591 * Logitech M560 mouse report
2593 * data[0] = type (0x02)
2594 * data[1..2] = buttons
2601 input_report_key(hidpp->input, BTN_LEFT,
2602 !!(data[1] & M560_MOUSE_BTN_LEFT));
2603 input_report_key(hidpp->input, BTN_RIGHT,
2604 !!(data[1] & M560_MOUSE_BTN_RIGHT));
2606 if (data[1] & M560_MOUSE_BTN_WHEEL_LEFT) {
2607 input_report_rel(hidpp->input, REL_HWHEEL, -1);
2608 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES,
2610 } else if (data[1] & M560_MOUSE_BTN_WHEEL_RIGHT) {
2611 input_report_rel(hidpp->input, REL_HWHEEL, 1);
2612 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES,
2616 v = hid_snto32(hid_field_extract(hdev, data+3, 0, 12), 12);
2617 input_report_rel(hidpp->input, REL_X, v);
2619 v = hid_snto32(hid_field_extract(hdev, data+3, 12, 12), 12);
2620 input_report_rel(hidpp->input, REL_Y, v);
2622 v = hid_snto32(data[6], 8);
2624 hidpp_scroll_counter_handle_scroll(hidpp->input,
2625 &hidpp->vertical_wheel_counter, v);
2627 input_sync(hidpp->input);
2633 static void m560_populate_input(struct hidpp_device *hidpp,
2634 struct input_dev *input_dev)
2636 __set_bit(EV_KEY, input_dev->evbit);
2637 __set_bit(BTN_MIDDLE, input_dev->keybit);
2638 __set_bit(BTN_RIGHT, input_dev->keybit);
2639 __set_bit(BTN_LEFT, input_dev->keybit);
2640 __set_bit(BTN_BACK, input_dev->keybit);
2641 __set_bit(BTN_FORWARD, input_dev->keybit);
2643 __set_bit(EV_REL, input_dev->evbit);
2644 __set_bit(REL_X, input_dev->relbit);
2645 __set_bit(REL_Y, input_dev->relbit);
2646 __set_bit(REL_WHEEL, input_dev->relbit);
2647 __set_bit(REL_HWHEEL, input_dev->relbit);
2648 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit);
2649 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit);
2652 static int m560_input_mapping(struct hid_device *hdev, struct hid_input *hi,
2653 struct hid_field *field, struct hid_usage *usage,
2654 unsigned long **bit, int *max)
2659 /* ------------------------------------------------------------------------- */
2660 /* Logitech K400 devices */
2661 /* ------------------------------------------------------------------------- */
2664 * The Logitech K400 keyboard has an embedded touchpad which is seen
2665 * as a mouse from the OS point of view. There is a hardware shortcut to disable
2666 * tap-to-click but the setting is not remembered accross reset, annoying some
2669 * We can toggle this feature from the host by using the feature 0x6010:
2673 struct k400_private_data {
2677 static int k400_disable_tap_to_click(struct hidpp_device *hidpp)
2679 struct k400_private_data *k400 = hidpp->private_data;
2680 struct hidpp_touchpad_fw_items items = {};
2684 if (!k400->feature_index) {
2685 ret = hidpp_root_get_feature(hidpp,
2686 HIDPP_PAGE_TOUCHPAD_FW_ITEMS,
2687 &k400->feature_index, &feature_type);
2689 /* means that the device is not powered up */
2693 ret = hidpp_touchpad_fw_items_set(hidpp, k400->feature_index, &items);
2700 static int k400_allocate(struct hid_device *hdev)
2702 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2703 struct k400_private_data *k400;
2705 k400 = devm_kzalloc(&hdev->dev, sizeof(struct k400_private_data),
2710 hidpp->private_data = k400;
2715 static int k400_connect(struct hid_device *hdev, bool connected)
2717 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2719 if (!disable_tap_to_click)
2722 return k400_disable_tap_to_click(hidpp);
2725 /* ------------------------------------------------------------------------- */
2726 /* Logitech G920 Driving Force Racing Wheel for Xbox One */
2727 /* ------------------------------------------------------------------------- */
2729 #define HIDPP_PAGE_G920_FORCE_FEEDBACK 0x8123
2731 static int g920_get_config(struct hidpp_device *hidpp)
2737 /* Find feature and store for later use */
2738 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_G920_FORCE_FEEDBACK,
2739 &feature_index, &feature_type);
2743 ret = hidpp_ff_init(hidpp, feature_index);
2745 hid_warn(hidpp->hid_dev, "Unable to initialize force feedback support, errno %d\n",
2751 /* -------------------------------------------------------------------------- */
2752 /* HID++1.0 devices which use HID++ reports for their wheels */
2753 /* -------------------------------------------------------------------------- */
2754 static int hidpp10_wheel_connect(struct hidpp_device *hidpp)
2756 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
2757 HIDPP_ENABLE_WHEEL_REPORT | HIDPP_ENABLE_HWHEEL_REPORT,
2758 HIDPP_ENABLE_WHEEL_REPORT | HIDPP_ENABLE_HWHEEL_REPORT);
2761 static int hidpp10_wheel_raw_event(struct hidpp_device *hidpp,
2772 if (data[0] != REPORT_ID_HIDPP_SHORT || data[2] != HIDPP_SUB_ID_ROLLER)
2778 input_report_rel(hidpp->input, REL_WHEEL, value);
2779 input_report_rel(hidpp->input, REL_WHEEL_HI_RES, value * 120);
2780 input_report_rel(hidpp->input, REL_HWHEEL, hvalue);
2781 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, hvalue * 120);
2782 input_sync(hidpp->input);
2787 static void hidpp10_wheel_populate_input(struct hidpp_device *hidpp,
2788 struct input_dev *input_dev)
2790 __set_bit(EV_REL, input_dev->evbit);
2791 __set_bit(REL_WHEEL, input_dev->relbit);
2792 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit);
2793 __set_bit(REL_HWHEEL, input_dev->relbit);
2794 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit);
2797 /* -------------------------------------------------------------------------- */
2798 /* HID++1.0 mice which use HID++ reports for extra mouse buttons */
2799 /* -------------------------------------------------------------------------- */
2800 static int hidpp10_extra_mouse_buttons_connect(struct hidpp_device *hidpp)
2802 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
2803 HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT,
2804 HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT);
2807 static int hidpp10_extra_mouse_buttons_raw_event(struct hidpp_device *hidpp,
2818 if (data[0] != REPORT_ID_HIDPP_SHORT ||
2819 data[2] != HIDPP_SUB_ID_MOUSE_EXTRA_BTNS)
2823 * Buttons are either delivered through the regular mouse report *or*
2824 * through the extra buttons report. At least for button 6 how it is
2825 * delivered differs per receiver firmware version. Even receivers with
2826 * the same usb-id show different behavior, so we handle both cases.
2828 for (i = 0; i < 8; i++)
2829 input_report_key(hidpp->input, BTN_MOUSE + i,
2830 (data[3] & (1 << i)));
2832 /* Some mice report events on button 9+, use BTN_MISC */
2833 for (i = 0; i < 8; i++)
2834 input_report_key(hidpp->input, BTN_MISC + i,
2835 (data[4] & (1 << i)));
2837 input_sync(hidpp->input);
2841 static void hidpp10_extra_mouse_buttons_populate_input(
2842 struct hidpp_device *hidpp, struct input_dev *input_dev)
2844 /* BTN_MOUSE - BTN_MOUSE+7 are set already by the descriptor */
2845 __set_bit(BTN_0, input_dev->keybit);
2846 __set_bit(BTN_1, input_dev->keybit);
2847 __set_bit(BTN_2, input_dev->keybit);
2848 __set_bit(BTN_3, input_dev->keybit);
2849 __set_bit(BTN_4, input_dev->keybit);
2850 __set_bit(BTN_5, input_dev->keybit);
2851 __set_bit(BTN_6, input_dev->keybit);
2852 __set_bit(BTN_7, input_dev->keybit);
2855 /* -------------------------------------------------------------------------- */
2856 /* HID++1.0 kbds which only report 0x10xx consumer usages through sub-id 0x03 */
2857 /* -------------------------------------------------------------------------- */
2859 /* Find the consumer-page input report desc and change Maximums to 0x107f */
2860 static u8 *hidpp10_consumer_keys_report_fixup(struct hidpp_device *hidpp,
2861 u8 *_rdesc, unsigned int *rsize)
2863 /* Note 0 terminated so we can use strnstr to search for this. */
2864 static const char consumer_rdesc_start[] = {
2865 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */
2866 0x09, 0x01, /* USAGE (Consumer Control) */
2867 0xA1, 0x01, /* COLLECTION (Application) */
2868 0x85, 0x03, /* REPORT_ID = 3 */
2869 0x75, 0x10, /* REPORT_SIZE (16) */
2870 0x95, 0x02, /* REPORT_COUNT (2) */
2871 0x15, 0x01, /* LOGICAL_MIN (1) */
2872 0x26, 0x00 /* LOGICAL_MAX (... */
2874 char *consumer_rdesc, *rdesc = (char *)_rdesc;
2877 consumer_rdesc = strnstr(rdesc, consumer_rdesc_start, *rsize);
2878 size = *rsize - (consumer_rdesc - rdesc);
2879 if (consumer_rdesc && size >= 25) {
2880 consumer_rdesc[15] = 0x7f;
2881 consumer_rdesc[16] = 0x10;
2882 consumer_rdesc[20] = 0x7f;
2883 consumer_rdesc[21] = 0x10;
2888 static int hidpp10_consumer_keys_connect(struct hidpp_device *hidpp)
2890 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
2891 HIDPP_ENABLE_CONSUMER_REPORT,
2892 HIDPP_ENABLE_CONSUMER_REPORT);
2895 static int hidpp10_consumer_keys_raw_event(struct hidpp_device *hidpp,
2898 u8 consumer_report[5];
2903 if (data[0] != REPORT_ID_HIDPP_SHORT ||
2904 data[2] != HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS)
2908 * Build a normal consumer report (3) out of the data, this detour
2909 * is necessary to get some keyboards to report their 0x10xx usages.
2911 consumer_report[0] = 0x03;
2912 memcpy(&consumer_report[1], &data[3], 4);
2913 /* We are called from atomic context */
2914 hid_report_raw_event(hidpp->hid_dev, HID_INPUT_REPORT,
2915 consumer_report, 5, 1);
2920 /* -------------------------------------------------------------------------- */
2921 /* High-resolution scroll wheels */
2922 /* -------------------------------------------------------------------------- */
2924 static int hi_res_scroll_enable(struct hidpp_device *hidpp)
2929 if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2121) {
2930 ret = hidpp_hrw_set_wheel_mode(hidpp, false, true, false);
2932 ret = hidpp_hrw_get_wheel_capability(hidpp, &multiplier);
2933 } else if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2120) {
2934 ret = hidpp_hrs_set_highres_scrolling_mode(hidpp, true,
2936 } else /* if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_1P0) */ {
2937 ret = hidpp10_enable_scrolling_acceleration(hidpp);
2943 if (multiplier == 0)
2946 hidpp->vertical_wheel_counter.wheel_multiplier = multiplier;
2947 hid_info(hidpp->hid_dev, "multiplier = %d\n", multiplier);
2951 /* -------------------------------------------------------------------------- */
2952 /* Generic HID++ devices */
2953 /* -------------------------------------------------------------------------- */
2955 static u8 *hidpp_report_fixup(struct hid_device *hdev, u8 *rdesc,
2956 unsigned int *rsize)
2958 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2963 /* For 27 MHz keyboards the quirk gets set after hid_parse. */
2964 if (hdev->group == HID_GROUP_LOGITECH_27MHZ_DEVICE ||
2965 (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS))
2966 rdesc = hidpp10_consumer_keys_report_fixup(hidpp, rdesc, rsize);
2971 static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
2972 struct hid_field *field, struct hid_usage *usage,
2973 unsigned long **bit, int *max)
2975 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2980 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
2981 return wtp_input_mapping(hdev, hi, field, usage, bit, max);
2982 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 &&
2983 field->application != HID_GD_MOUSE)
2984 return m560_input_mapping(hdev, hi, field, usage, bit, max);
2989 static int hidpp_input_mapped(struct hid_device *hdev, struct hid_input *hi,
2990 struct hid_field *field, struct hid_usage *usage,
2991 unsigned long **bit, int *max)
2993 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2998 /* Ensure that Logitech G920 is not given a default fuzz/flat value */
2999 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
3000 if (usage->type == EV_ABS && (usage->code == ABS_X ||
3001 usage->code == ABS_Y || usage->code == ABS_Z ||
3002 usage->code == ABS_RZ)) {
3003 field->application = HID_GD_MULTIAXIS;
3011 static void hidpp_populate_input(struct hidpp_device *hidpp,
3012 struct input_dev *input)
3014 hidpp->input = input;
3016 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
3017 wtp_populate_input(hidpp, input);
3018 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
3019 m560_populate_input(hidpp, input);
3021 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS)
3022 hidpp10_wheel_populate_input(hidpp, input);
3024 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS)
3025 hidpp10_extra_mouse_buttons_populate_input(hidpp, input);
3028 static int hidpp_input_configured(struct hid_device *hdev,
3029 struct hid_input *hidinput)
3031 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3032 struct input_dev *input = hidinput->input;
3037 hidpp_populate_input(hidpp, input);
3042 static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,
3045 struct hidpp_report *question = hidpp->send_receive_buf;
3046 struct hidpp_report *answer = hidpp->send_receive_buf;
3047 struct hidpp_report *report = (struct hidpp_report *)data;
3051 * If the mutex is locked then we have a pending answer from a
3052 * previously sent command.
3054 if (unlikely(mutex_is_locked(&hidpp->send_mutex))) {
3056 * Check for a correct hidpp20 answer or the corresponding
3059 if (hidpp_match_answer(question, report) ||
3060 hidpp_match_error(question, report)) {
3062 hidpp->answer_available = true;
3063 wake_up(&hidpp->wait);
3065 * This was an answer to a command that this driver sent
3066 * We return 1 to hid-core to avoid forwarding the
3067 * command upstream as it has been treated by the driver
3074 if (unlikely(hidpp_report_is_connect_event(report))) {
3075 atomic_set(&hidpp->connected,
3076 !(report->rap.params[0] & (1 << 6)));
3077 if (schedule_work(&hidpp->work) == 0)
3078 dbg_hid("%s: connect event already queued\n", __func__);
3082 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) {
3083 ret = hidpp20_battery_event(hidpp, data, size);
3086 ret = hidpp_solar_battery_event(hidpp, data, size);
3091 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) {
3092 ret = hidpp10_battery_event(hidpp, data, size);
3097 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
3098 ret = hidpp10_wheel_raw_event(hidpp, data, size);
3103 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) {
3104 ret = hidpp10_extra_mouse_buttons_raw_event(hidpp, data, size);
3109 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) {
3110 ret = hidpp10_consumer_keys_raw_event(hidpp, data, size);
3118 static int hidpp_raw_event(struct hid_device *hdev, struct hid_report *report,
3121 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3127 /* Generic HID++ processing. */
3129 case REPORT_ID_HIDPP_VERY_LONG:
3130 if (size != hidpp->very_long_report_length) {
3131 hid_err(hdev, "received hid++ report of bad size (%d)",
3135 ret = hidpp_raw_hidpp_event(hidpp, data, size);
3137 case REPORT_ID_HIDPP_LONG:
3138 if (size != HIDPP_REPORT_LONG_LENGTH) {
3139 hid_err(hdev, "received hid++ report of bad size (%d)",
3143 ret = hidpp_raw_hidpp_event(hidpp, data, size);
3145 case REPORT_ID_HIDPP_SHORT:
3146 if (size != HIDPP_REPORT_SHORT_LENGTH) {
3147 hid_err(hdev, "received hid++ report of bad size (%d)",
3151 ret = hidpp_raw_hidpp_event(hidpp, data, size);
3155 /* If no report is available for further processing, skip calling
3156 * raw_event of subclasses. */
3160 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
3161 return wtp_raw_event(hdev, data, size);
3162 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
3163 return m560_raw_event(hdev, data, size);
3168 static int hidpp_event(struct hid_device *hdev, struct hid_field *field,
3169 struct hid_usage *usage, __s32 value)
3171 /* This function will only be called for scroll events, due to the
3172 * restriction imposed in hidpp_usages.
3174 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3175 struct hidpp_scroll_counter *counter;
3180 counter = &hidpp->vertical_wheel_counter;
3181 /* A scroll event may occur before the multiplier has been retrieved or
3182 * the input device set, or high-res scroll enabling may fail. In such
3183 * cases we must return early (falling back to default behaviour) to
3184 * avoid a crash in hidpp_scroll_counter_handle_scroll.
3186 if (!(hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL) || value == 0
3187 || hidpp->input == NULL || counter->wheel_multiplier == 0)
3190 hidpp_scroll_counter_handle_scroll(hidpp->input, counter, value);
3194 static int hidpp_initialize_battery(struct hidpp_device *hidpp)
3196 static atomic_t battery_no = ATOMIC_INIT(0);
3197 struct power_supply_config cfg = { .drv_data = hidpp };
3198 struct power_supply_desc *desc = &hidpp->battery.desc;
3199 enum power_supply_property *battery_props;
3200 struct hidpp_battery *battery;
3201 unsigned int num_battery_props;
3205 if (hidpp->battery.ps)
3208 hidpp->battery.feature_index = 0xff;
3209 hidpp->battery.solar_feature_index = 0xff;
3211 if (hidpp->protocol_major >= 2) {
3212 if (hidpp->quirks & HIDPP_QUIRK_CLASS_K750)
3213 ret = hidpp_solar_request_battery_event(hidpp);
3215 ret = hidpp20_query_battery_info(hidpp);
3219 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_BATTERY;
3221 ret = hidpp10_query_battery_status(hidpp);
3223 ret = hidpp10_query_battery_mileage(hidpp);
3226 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
3228 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS;
3230 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP10_BATTERY;
3233 battery_props = devm_kmemdup(&hidpp->hid_dev->dev,
3234 hidpp_battery_props,
3235 sizeof(hidpp_battery_props),
3240 num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 2;
3242 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)
3243 battery_props[num_battery_props++] =
3244 POWER_SUPPLY_PROP_CAPACITY;
3246 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS)
3247 battery_props[num_battery_props++] =
3248 POWER_SUPPLY_PROP_CAPACITY_LEVEL;
3250 battery = &hidpp->battery;
3252 n = atomic_inc_return(&battery_no) - 1;
3253 desc->properties = battery_props;
3254 desc->num_properties = num_battery_props;
3255 desc->get_property = hidpp_battery_get_property;
3256 sprintf(battery->name, "hidpp_battery_%ld", n);
3257 desc->name = battery->name;
3258 desc->type = POWER_SUPPLY_TYPE_BATTERY;
3259 desc->use_for_apm = 0;
3261 battery->ps = devm_power_supply_register(&hidpp->hid_dev->dev,
3264 if (IS_ERR(battery->ps))
3265 return PTR_ERR(battery->ps);
3267 power_supply_powers(battery->ps, &hidpp->hid_dev->dev);
3272 static void hidpp_overwrite_name(struct hid_device *hdev)
3274 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3277 if (hidpp->protocol_major < 2)
3280 name = hidpp_get_device_name(hidpp);
3283 hid_err(hdev, "unable to retrieve the name of the device");
3285 dbg_hid("HID++: Got name: %s\n", name);
3286 snprintf(hdev->name, sizeof(hdev->name), "%s", name);
3292 static int hidpp_input_open(struct input_dev *dev)
3294 struct hid_device *hid = input_get_drvdata(dev);
3296 return hid_hw_open(hid);
3299 static void hidpp_input_close(struct input_dev *dev)
3301 struct hid_device *hid = input_get_drvdata(dev);
3306 static struct input_dev *hidpp_allocate_input(struct hid_device *hdev)
3308 struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev);
3309 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3314 input_set_drvdata(input_dev, hdev);
3315 input_dev->open = hidpp_input_open;
3316 input_dev->close = hidpp_input_close;
3318 input_dev->name = hidpp->name;
3319 input_dev->phys = hdev->phys;
3320 input_dev->uniq = hdev->uniq;
3321 input_dev->id.bustype = hdev->bus;
3322 input_dev->id.vendor = hdev->vendor;
3323 input_dev->id.product = hdev->product;
3324 input_dev->id.version = hdev->version;
3325 input_dev->dev.parent = &hdev->dev;
3330 static void hidpp_connect_event(struct hidpp_device *hidpp)
3332 struct hid_device *hdev = hidpp->hid_dev;
3334 bool connected = atomic_read(&hidpp->connected);
3335 struct input_dev *input;
3336 char *name, *devm_name;
3339 if (hidpp->battery.ps) {
3340 hidpp->battery.online = false;
3341 hidpp->battery.status = POWER_SUPPLY_STATUS_UNKNOWN;
3342 hidpp->battery.level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
3343 power_supply_changed(hidpp->battery.ps);
3348 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
3349 ret = wtp_connect(hdev, connected);
3352 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) {
3353 ret = m560_send_config_command(hdev, connected);
3356 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
3357 ret = k400_connect(hdev, connected);
3362 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
3363 ret = hidpp10_wheel_connect(hidpp);
3368 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) {
3369 ret = hidpp10_extra_mouse_buttons_connect(hidpp);
3374 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) {
3375 ret = hidpp10_consumer_keys_connect(hidpp);
3380 /* the device is already connected, we can ask for its name and
3382 if (!hidpp->protocol_major) {
3383 ret = hidpp_root_get_protocol_version(hidpp);
3385 hid_err(hdev, "Can not get the protocol version.\n");
3390 if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) {
3391 name = hidpp_get_device_name(hidpp);
3393 devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
3399 hidpp->name = devm_name;
3403 hidpp_initialize_battery(hidpp);
3405 /* forward current battery state */
3406 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) {
3407 hidpp10_enable_battery_reporting(hidpp);
3408 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)
3409 hidpp10_query_battery_mileage(hidpp);
3411 hidpp10_query_battery_status(hidpp);
3412 } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) {
3413 hidpp20_query_battery_info(hidpp);
3415 if (hidpp->battery.ps)
3416 power_supply_changed(hidpp->battery.ps);
3418 if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL)
3419 hi_res_scroll_enable(hidpp);
3421 if (!(hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) || hidpp->delayed_input)
3422 /* if the input nodes are already created, we can stop now */
3425 input = hidpp_allocate_input(hdev);
3427 hid_err(hdev, "cannot allocate new input device: %d\n", ret);
3431 hidpp_populate_input(hidpp, input);
3433 ret = input_register_device(input);
3435 input_free_device(input);
3437 hidpp->delayed_input = input;
3440 static DEVICE_ATTR(builtin_power_supply, 0000, NULL, NULL);
3442 static struct attribute *sysfs_attrs[] = {
3443 &dev_attr_builtin_power_supply.attr,
3447 static const struct attribute_group ps_attribute_group = {
3448 .attrs = sysfs_attrs
3451 static int hidpp_get_report_length(struct hid_device *hdev, int id)
3453 struct hid_report_enum *re;
3454 struct hid_report *report;
3456 re = &(hdev->report_enum[HID_OUTPUT_REPORT]);
3457 report = re->report_id_hash[id];
3461 return report->field[0]->report_count + 1;
3464 static bool hidpp_validate_report(struct hid_device *hdev, int id,
3465 int expected_length, bool optional)
3469 if (id >= HID_MAX_IDS || id < 0) {
3470 hid_err(hdev, "invalid HID report id %u\n", id);
3474 report_length = hidpp_get_report_length(hdev, id);
3478 if (report_length < expected_length) {
3479 hid_warn(hdev, "not enough values in hidpp report %d\n", id);
3486 static bool hidpp_validate_device(struct hid_device *hdev)
3488 return hidpp_validate_report(hdev, REPORT_ID_HIDPP_SHORT,
3489 HIDPP_REPORT_SHORT_LENGTH, false) &&
3490 hidpp_validate_report(hdev, REPORT_ID_HIDPP_LONG,
3491 HIDPP_REPORT_LONG_LENGTH, true);
3494 static bool hidpp_application_equals(struct hid_device *hdev,
3495 unsigned int application)
3497 struct list_head *report_list;
3498 struct hid_report *report;
3500 report_list = &hdev->report_enum[HID_INPUT_REPORT].report_list;
3501 report = list_first_entry_or_null(report_list, struct hid_report, list);
3502 return report && report->application == application;
3505 static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
3507 struct hidpp_device *hidpp;
3510 unsigned int connect_mask = HID_CONNECT_DEFAULT;
3512 /* report_fixup needs drvdata to be set before we call hid_parse */
3513 hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL);
3517 hidpp->hid_dev = hdev;
3518 hidpp->name = hdev->name;
3519 hidpp->quirks = id->driver_data;
3520 hid_set_drvdata(hdev, hidpp);
3522 ret = hid_parse(hdev);
3524 hid_err(hdev, "%s:parse failed\n", __func__);
3529 * Make sure the device is HID++ capable, otherwise treat as generic HID
3531 if (!hidpp_validate_device(hdev)) {
3532 hid_set_drvdata(hdev, NULL);
3533 devm_kfree(&hdev->dev, hidpp);
3534 return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
3537 hidpp->very_long_report_length =
3538 hidpp_get_report_length(hdev, REPORT_ID_HIDPP_VERY_LONG);
3539 if (hidpp->very_long_report_length > HIDPP_REPORT_VERY_LONG_MAX_LENGTH)
3540 hidpp->very_long_report_length = HIDPP_REPORT_VERY_LONG_MAX_LENGTH;
3542 if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE)
3543 hidpp->quirks |= HIDPP_QUIRK_UNIFYING;
3545 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
3546 hidpp_application_equals(hdev, HID_GD_MOUSE))
3547 hidpp->quirks |= HIDPP_QUIRK_HIDPP_WHEELS |
3548 HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS;
3550 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
3551 hidpp_application_equals(hdev, HID_GD_KEYBOARD))
3552 hidpp->quirks |= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS;
3554 if (disable_raw_mode) {
3555 hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP;
3556 hidpp->quirks &= ~HIDPP_QUIRK_NO_HIDINPUT;
3559 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
3560 ret = wtp_allocate(hdev, id);
3563 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
3564 ret = k400_allocate(hdev);
3569 INIT_WORK(&hidpp->work, delayed_work_cb);
3570 mutex_init(&hidpp->send_mutex);
3571 init_waitqueue_head(&hidpp->wait);
3573 /* indicates we are handling the battery properties in the kernel */
3574 ret = sysfs_create_group(&hdev->dev.kobj, &ps_attribute_group);
3576 hid_warn(hdev, "Cannot allocate sysfs group for %s\n",
3580 * Plain USB connections need to actually call start and open
3581 * on the transport driver to allow incoming data.
3583 ret = hid_hw_start(hdev, 0);
3585 hid_err(hdev, "hw start failed\n");
3586 goto hid_hw_start_fail;
3589 ret = hid_hw_open(hdev);
3591 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n",
3594 goto hid_hw_open_fail;
3597 /* Allow incoming packets */
3598 hid_device_io_start(hdev);
3600 if (hidpp->quirks & HIDPP_QUIRK_UNIFYING)
3601 hidpp_unifying_init(hidpp);
3603 connected = hidpp_root_get_protocol_version(hidpp) == 0;
3604 atomic_set(&hidpp->connected, connected);
3605 if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) {
3608 hid_err(hdev, "Device not connected");
3609 goto hid_hw_init_fail;
3612 hidpp_overwrite_name(hdev);
3615 if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) {
3616 ret = wtp_get_config(hidpp);
3618 goto hid_hw_init_fail;
3619 } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) {
3620 ret = g920_get_config(hidpp);
3622 goto hid_hw_init_fail;
3625 hidpp_connect_event(hidpp);
3627 /* Reset the HID node state */
3628 hid_device_io_stop(hdev);
3632 if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT)
3633 connect_mask &= ~HID_CONNECT_HIDINPUT;
3635 /* Now export the actual inputs and hidraw nodes to the world */
3636 ret = hid_hw_start(hdev, connect_mask);
3638 hid_err(hdev, "%s:hid_hw_start returned error\n", __func__);
3639 goto hid_hw_start_fail;
3649 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
3650 cancel_work_sync(&hidpp->work);
3651 mutex_destroy(&hidpp->send_mutex);
3655 static void hidpp_remove(struct hid_device *hdev)
3657 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3660 return hid_hw_stop(hdev);
3662 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
3664 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)
3665 hidpp_ff_deinit(hdev);
3668 cancel_work_sync(&hidpp->work);
3669 mutex_destroy(&hidpp->send_mutex);
3672 #define LDJ_DEVICE(product) \
3673 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE, \
3674 USB_VENDOR_ID_LOGITECH, (product))
3676 #define L27MHZ_DEVICE(product) \
3677 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_27MHZ_DEVICE, \
3678 USB_VENDOR_ID_LOGITECH, (product))
3680 static const struct hid_device_id hidpp_devices[] = {
3681 { /* wireless touchpad */
3683 .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT |
3684 HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS },
3685 { /* wireless touchpad T650 */
3687 .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT },
3688 { /* wireless touchpad T651 */
3689 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH,
3690 USB_DEVICE_ID_LOGITECH_T651),
3691 .driver_data = HIDPP_QUIRK_CLASS_WTP },
3692 { /* Mouse Logitech Anywhere MX */
3693 LDJ_DEVICE(0x1017), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_1P0 },
3694 { /* Mouse Logitech Cube */
3695 LDJ_DEVICE(0x4010), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2120 },
3696 { /* Mouse Logitech M335 */
3697 LDJ_DEVICE(0x4050), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3698 { /* Mouse Logitech M515 */
3699 LDJ_DEVICE(0x4007), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2120 },
3700 { /* Mouse logitech M560 */
3702 .driver_data = HIDPP_QUIRK_DELAYED_INIT | HIDPP_QUIRK_CLASS_M560
3703 | HIDPP_QUIRK_HI_RES_SCROLL_X2120 },
3704 { /* Mouse Logitech M705 (firmware RQM17) */
3705 LDJ_DEVICE(0x101b), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_1P0 },
3706 { /* Mouse Logitech M705 (firmware RQM67) */
3707 LDJ_DEVICE(0x406d), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3708 { /* Mouse Logitech M720 */
3709 LDJ_DEVICE(0x405e), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3710 { /* Mouse Logitech MX Anywhere 2 */
3711 LDJ_DEVICE(0x404a), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3712 { LDJ_DEVICE(0xb013), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3713 { LDJ_DEVICE(0xb018), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3714 { LDJ_DEVICE(0xb01f), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3715 { /* Mouse Logitech MX Anywhere 2S */
3716 LDJ_DEVICE(0x406a), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3717 { /* Mouse Logitech MX Master */
3718 LDJ_DEVICE(0x4041), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3719 { LDJ_DEVICE(0x4060), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3720 { LDJ_DEVICE(0x4071), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3721 { /* Mouse Logitech MX Master 2S */
3722 LDJ_DEVICE(0x4069), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3723 { /* Mouse Logitech Performance MX */
3724 LDJ_DEVICE(0x101a), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_1P0 },
3725 { /* Keyboard logitech K400 */
3727 .driver_data = HIDPP_QUIRK_CLASS_K400 },
3728 { /* Solar Keyboard Logitech K750 */
3730 .driver_data = HIDPP_QUIRK_CLASS_K750 },
3731 { /* Keyboard MX5000 (Bluetooth-receiver in HID proxy mode) */
3733 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
3734 { /* Keyboard MX5500 (Bluetooth-receiver in HID proxy mode) */
3736 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
3738 { LDJ_DEVICE(HID_ANY_ID) },
3740 { /* Keyboard LX501 (Y-RR53) */
3741 L27MHZ_DEVICE(0x0049),
3742 .driver_data = HIDPP_QUIRK_KBD_ZOOM_WHEEL },
3743 { /* Keyboard MX3000 (Y-RAM74) */
3744 L27MHZ_DEVICE(0x0057),
3745 .driver_data = HIDPP_QUIRK_KBD_SCROLL_WHEEL },
3746 { /* Keyboard MX3200 (Y-RAV80) */
3747 L27MHZ_DEVICE(0x005c),
3748 .driver_data = HIDPP_QUIRK_KBD_ZOOM_WHEEL },
3749 { /* S510 Media Remote */
3750 L27MHZ_DEVICE(0x00fe),
3751 .driver_data = HIDPP_QUIRK_KBD_SCROLL_WHEEL },
3753 { L27MHZ_DEVICE(HID_ANY_ID) },
3755 { /* Logitech G403 Wireless Gaming Mouse over USB */
3756 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC082) },
3757 { /* Logitech G703 Gaming Mouse over USB */
3758 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC087) },
3759 { /* Logitech G703 Hero Gaming Mouse over USB */
3760 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC090) },
3761 { /* Logitech G900 Gaming Mouse over USB */
3762 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC081) },
3763 { /* Logitech G903 Gaming Mouse over USB */
3764 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC086) },
3765 { /* Logitech G903 Hero Gaming Mouse over USB */
3766 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC091) },
3767 { /* Logitech G920 Wheel over USB */
3768 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL),
3769 .driver_data = HIDPP_QUIRK_CLASS_G920 | HIDPP_QUIRK_FORCE_OUTPUT_REPORTS},
3770 { /* Logitech G Pro Gaming Mouse over USB */
3771 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC088) },
3773 { /* MX5000 keyboard over Bluetooth */
3774 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb305),
3775 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
3776 { /* MX5500 keyboard over Bluetooth */
3777 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb30b),
3778 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
3782 MODULE_DEVICE_TABLE(hid, hidpp_devices);
3784 static const struct hid_usage_id hidpp_usages[] = {
3785 { HID_GD_WHEEL, EV_REL, REL_WHEEL_HI_RES },
3786 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
3789 static struct hid_driver hidpp_driver = {
3790 .name = "logitech-hidpp-device",
3791 .id_table = hidpp_devices,
3792 .report_fixup = hidpp_report_fixup,
3793 .probe = hidpp_probe,
3794 .remove = hidpp_remove,
3795 .raw_event = hidpp_raw_event,
3796 .usage_table = hidpp_usages,
3797 .event = hidpp_event,
3798 .input_configured = hidpp_input_configured,
3799 .input_mapping = hidpp_input_mapping,
3800 .input_mapped = hidpp_input_mapped,
3803 module_hid_driver(hidpp_driver);