2 * HIDPP protocol for Logitech Unifying receivers
4 * Copyright (c) 2011 Logitech (c)
5 * Copyright (c) 2012-2013 Google (c)
6 * Copyright (c) 2013-2014 Red Hat Inc.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; version 2 of the License.
15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 #include <linux/device.h>
18 #include <linux/input.h>
19 #include <linux/usb.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/sched.h>
24 #include <linux/sched/clock.h>
25 #include <linux/kfifo.h>
26 #include <linux/input/mt.h>
27 #include <linux/workqueue.h>
28 #include <linux/atomic.h>
29 #include <linux/fixp-arith.h>
30 #include <asm/unaligned.h>
31 #include "usbhid/usbhid.h"
34 MODULE_LICENSE("GPL");
38 static bool disable_raw_mode;
39 module_param(disable_raw_mode, bool, 0644);
40 MODULE_PARM_DESC(disable_raw_mode,
41 "Disable Raw mode reporting for touchpads and keep firmware gestures.");
43 static bool disable_tap_to_click;
44 module_param(disable_tap_to_click, bool, 0644);
45 MODULE_PARM_DESC(disable_tap_to_click,
46 "Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
48 #define REPORT_ID_HIDPP_SHORT 0x10
49 #define REPORT_ID_HIDPP_LONG 0x11
50 #define REPORT_ID_HIDPP_VERY_LONG 0x12
52 #define HIDPP_REPORT_SHORT_LENGTH 7
53 #define HIDPP_REPORT_LONG_LENGTH 20
54 #define HIDPP_REPORT_VERY_LONG_MAX_LENGTH 64
56 #define HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS 0x03
57 #define HIDPP_SUB_ID_ROLLER 0x05
58 #define HIDPP_SUB_ID_MOUSE_EXTRA_BTNS 0x06
60 #define HIDPP_QUIRK_CLASS_WTP BIT(0)
61 #define HIDPP_QUIRK_CLASS_M560 BIT(1)
62 #define HIDPP_QUIRK_CLASS_K400 BIT(2)
63 #define HIDPP_QUIRK_CLASS_G920 BIT(3)
64 #define HIDPP_QUIRK_CLASS_K750 BIT(4)
66 /* bits 2..20 are reserved for classes */
67 /* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */
68 #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22)
69 #define HIDPP_QUIRK_NO_HIDINPUT BIT(23)
70 #define HIDPP_QUIRK_FORCE_OUTPUT_REPORTS BIT(24)
71 #define HIDPP_QUIRK_UNIFYING BIT(25)
72 #define HIDPP_QUIRK_HI_RES_SCROLL_1P0 BIT(26)
73 #define HIDPP_QUIRK_HI_RES_SCROLL_X2120 BIT(27)
74 #define HIDPP_QUIRK_HI_RES_SCROLL_X2121 BIT(28)
75 #define HIDPP_QUIRK_HIDPP_WHEELS BIT(29)
76 #define HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS BIT(30)
77 #define HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS BIT(31)
79 /* These are just aliases for now */
80 #define HIDPP_QUIRK_KBD_SCROLL_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
81 #define HIDPP_QUIRK_KBD_ZOOM_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
83 /* Convenience constant to check for any high-res support. */
84 #define HIDPP_QUIRK_HI_RES_SCROLL (HIDPP_QUIRK_HI_RES_SCROLL_1P0 | \
85 HIDPP_QUIRK_HI_RES_SCROLL_X2120 | \
86 HIDPP_QUIRK_HI_RES_SCROLL_X2121)
88 #define HIDPP_QUIRK_DELAYED_INIT HIDPP_QUIRK_NO_HIDINPUT
90 #define HIDPP_CAPABILITY_HIDPP10_BATTERY BIT(0)
91 #define HIDPP_CAPABILITY_HIDPP20_BATTERY BIT(1)
92 #define HIDPP_CAPABILITY_BATTERY_MILEAGE BIT(2)
93 #define HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS BIT(3)
96 * There are two hidpp protocols in use, the first version hidpp10 is known
97 * as register access protocol or RAP, the second version hidpp20 is known as
98 * feature access protocol or FAP
100 * Most older devices (including the Unifying usb receiver) use the RAP protocol
101 * where as most newer devices use the FAP protocol. Both protocols are
102 * compatible with the underlying transport, which could be usb, Unifiying, or
103 * bluetooth. The message lengths are defined by the hid vendor specific report
104 * descriptor for the HIDPP_SHORT report type (total message lenth 7 bytes) and
105 * the HIDPP_LONG report type (total message length 20 bytes)
107 * The RAP protocol uses both report types, whereas the FAP only uses HIDPP_LONG
108 * messages. The Unifying receiver itself responds to RAP messages (device index
109 * is 0xFF for the receiver), and all messages (short or long) with a device
110 * index between 1 and 6 are passed untouched to the corresponding paired
113 * The paired device can be RAP or FAP, it will receive the message untouched
114 * from the Unifiying receiver.
119 u8 funcindex_clientid;
120 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
126 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
129 struct hidpp_report {
135 u8 rawbytes[sizeof(struct fap)];
139 struct hidpp_battery {
141 u8 solar_feature_index;
142 struct power_supply_desc desc;
143 struct power_supply *ps;
152 * struct hidpp_scroll_counter - Utility class for processing high-resolution
154 * @dev: the input device for which events should be reported.
155 * @wheel_multiplier: the scalar multiplier to be applied to each wheel event
156 * @remainder: counts the number of high-resolution units moved since the last
157 * low-resolution event (REL_WHEEL or REL_HWHEEL) was sent. Should
158 * only be used by class methods.
159 * @direction: direction of last movement (1 or -1)
160 * @last_time: last event time, used to reset remainder after inactivity
162 struct hidpp_scroll_counter {
163 int wheel_multiplier;
166 unsigned long long last_time;
169 struct hidpp_device {
170 struct hid_device *hid_dev;
171 struct input_dev *input;
172 struct mutex send_mutex;
173 void *send_receive_buf;
174 char *name; /* will never be NULL and should not be freed */
175 wait_queue_head_t wait;
176 int very_long_report_length;
177 bool answer_available;
183 struct work_struct work;
184 struct kfifo delayed_work_fifo;
186 struct input_dev *delayed_input;
188 unsigned long quirks;
189 unsigned long capabilities;
191 struct hidpp_battery battery;
192 struct hidpp_scroll_counter vertical_wheel_counter;
195 /* HID++ 1.0 error codes */
196 #define HIDPP_ERROR 0x8f
197 #define HIDPP_ERROR_SUCCESS 0x00
198 #define HIDPP_ERROR_INVALID_SUBID 0x01
199 #define HIDPP_ERROR_INVALID_ADRESS 0x02
200 #define HIDPP_ERROR_INVALID_VALUE 0x03
201 #define HIDPP_ERROR_CONNECT_FAIL 0x04
202 #define HIDPP_ERROR_TOO_MANY_DEVICES 0x05
203 #define HIDPP_ERROR_ALREADY_EXISTS 0x06
204 #define HIDPP_ERROR_BUSY 0x07
205 #define HIDPP_ERROR_UNKNOWN_DEVICE 0x08
206 #define HIDPP_ERROR_RESOURCE_ERROR 0x09
207 #define HIDPP_ERROR_REQUEST_UNAVAILABLE 0x0a
208 #define HIDPP_ERROR_INVALID_PARAM_VALUE 0x0b
209 #define HIDPP_ERROR_WRONG_PIN_CODE 0x0c
210 /* HID++ 2.0 error codes */
211 #define HIDPP20_ERROR 0xff
213 static void hidpp_connect_event(struct hidpp_device *hidpp_dev);
215 static int __hidpp_send_report(struct hid_device *hdev,
216 struct hidpp_report *hidpp_report)
218 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
219 int fields_count, ret;
221 switch (hidpp_report->report_id) {
222 case REPORT_ID_HIDPP_SHORT:
223 fields_count = HIDPP_REPORT_SHORT_LENGTH;
225 case REPORT_ID_HIDPP_LONG:
226 fields_count = HIDPP_REPORT_LONG_LENGTH;
228 case REPORT_ID_HIDPP_VERY_LONG:
229 fields_count = hidpp->very_long_report_length;
236 * set the device_index as the receiver, it will be overwritten by
237 * hid_hw_request if needed
239 hidpp_report->device_index = 0xff;
241 if (hidpp->quirks & HIDPP_QUIRK_FORCE_OUTPUT_REPORTS) {
242 ret = hid_hw_output_report(hdev, (u8 *)hidpp_report, fields_count);
244 ret = hid_hw_raw_request(hdev, hidpp_report->report_id,
245 (u8 *)hidpp_report, fields_count, HID_OUTPUT_REPORT,
249 return ret == fields_count ? 0 : -1;
253 * hidpp_send_message_sync() returns 0 in case of success, and something else
254 * in case of a failure.
255 * - If ' something else' is positive, that means that an error has been raised
256 * by the protocol itself.
257 * - If ' something else' is negative, that means that we had a classic error
258 * (-ENOMEM, -EPIPE, etc...)
260 static int hidpp_send_message_sync(struct hidpp_device *hidpp,
261 struct hidpp_report *message,
262 struct hidpp_report *response)
266 mutex_lock(&hidpp->send_mutex);
268 hidpp->send_receive_buf = response;
269 hidpp->answer_available = false;
272 * So that we can later validate the answer when it arrives
275 *response = *message;
277 ret = __hidpp_send_report(hidpp->hid_dev, message);
280 dbg_hid("__hidpp_send_report returned err: %d\n", ret);
281 memset(response, 0, sizeof(struct hidpp_report));
285 if (!wait_event_timeout(hidpp->wait, hidpp->answer_available,
287 dbg_hid("%s:timeout waiting for response\n", __func__);
288 memset(response, 0, sizeof(struct hidpp_report));
292 if (response->report_id == REPORT_ID_HIDPP_SHORT &&
293 response->rap.sub_id == HIDPP_ERROR) {
294 ret = response->rap.params[1];
295 dbg_hid("%s:got hidpp error %02X\n", __func__, ret);
299 if ((response->report_id == REPORT_ID_HIDPP_LONG ||
300 response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&
301 response->fap.feature_index == HIDPP20_ERROR) {
302 ret = response->fap.params[1];
303 dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);
308 mutex_unlock(&hidpp->send_mutex);
313 static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
314 u8 feat_index, u8 funcindex_clientid, u8 *params, int param_count,
315 struct hidpp_report *response)
317 struct hidpp_report *message;
320 if (param_count > sizeof(message->fap.params))
323 message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
327 if (param_count > (HIDPP_REPORT_LONG_LENGTH - 4))
328 message->report_id = REPORT_ID_HIDPP_VERY_LONG;
330 message->report_id = REPORT_ID_HIDPP_LONG;
331 message->fap.feature_index = feat_index;
332 message->fap.funcindex_clientid = funcindex_clientid;
333 memcpy(&message->fap.params, params, param_count);
335 ret = hidpp_send_message_sync(hidpp, message, response);
340 static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,
341 u8 report_id, u8 sub_id, u8 reg_address, u8 *params, int param_count,
342 struct hidpp_report *response)
344 struct hidpp_report *message;
348 case REPORT_ID_HIDPP_SHORT:
349 max_count = HIDPP_REPORT_SHORT_LENGTH - 4;
351 case REPORT_ID_HIDPP_LONG:
352 max_count = HIDPP_REPORT_LONG_LENGTH - 4;
354 case REPORT_ID_HIDPP_VERY_LONG:
355 max_count = hidpp_dev->very_long_report_length - 4;
361 if (param_count > max_count)
364 message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
367 message->report_id = report_id;
368 message->rap.sub_id = sub_id;
369 message->rap.reg_address = reg_address;
370 memcpy(&message->rap.params, params, param_count);
372 ret = hidpp_send_message_sync(hidpp_dev, message, response);
377 static void delayed_work_cb(struct work_struct *work)
379 struct hidpp_device *hidpp = container_of(work, struct hidpp_device,
381 hidpp_connect_event(hidpp);
384 static inline bool hidpp_match_answer(struct hidpp_report *question,
385 struct hidpp_report *answer)
387 return (answer->fap.feature_index == question->fap.feature_index) &&
388 (answer->fap.funcindex_clientid == question->fap.funcindex_clientid);
391 static inline bool hidpp_match_error(struct hidpp_report *question,
392 struct hidpp_report *answer)
394 return ((answer->rap.sub_id == HIDPP_ERROR) ||
395 (answer->fap.feature_index == HIDPP20_ERROR)) &&
396 (answer->fap.funcindex_clientid == question->fap.feature_index) &&
397 (answer->fap.params[0] == question->fap.funcindex_clientid);
400 static inline bool hidpp_report_is_connect_event(struct hidpp_report *report)
402 return (report->report_id == REPORT_ID_HIDPP_SHORT) &&
403 (report->rap.sub_id == 0x41);
407 * hidpp_prefix_name() prefixes the current given name with "Logitech ".
409 static void hidpp_prefix_name(char **name, int name_length)
411 #define PREFIX_LENGTH 9 /* "Logitech " */
416 if (name_length > PREFIX_LENGTH &&
417 strncmp(*name, "Logitech ", PREFIX_LENGTH) == 0)
418 /* The prefix has is already in the name */
421 new_length = PREFIX_LENGTH + name_length;
422 new_name = kzalloc(new_length, GFP_KERNEL);
426 snprintf(new_name, new_length, "Logitech %s", *name);
434 * hidpp_scroll_counter_handle_scroll() - Send high- and low-resolution scroll
435 * events given a high-resolution wheel
437 * @counter: a hid_scroll_counter struct describing the wheel.
438 * @hi_res_value: the movement of the wheel, in the mouse's high-resolution
441 * Given a high-resolution movement, this function converts the movement into
442 * fractions of 120 and emits high-resolution scroll events for the input
443 * device. It also uses the multiplier from &struct hid_scroll_counter to
444 * emit low-resolution scroll events when appropriate for
445 * backwards-compatibility with userspace input libraries.
447 static void hidpp_scroll_counter_handle_scroll(struct input_dev *input_dev,
448 struct hidpp_scroll_counter *counter,
451 int low_res_value, remainder, direction;
452 unsigned long long now, previous;
454 hi_res_value = hi_res_value * 120/counter->wheel_multiplier;
455 input_report_rel(input_dev, REL_WHEEL_HI_RES, hi_res_value);
457 remainder = counter->remainder;
458 direction = hi_res_value > 0 ? 1 : -1;
461 previous = counter->last_time;
462 counter->last_time = now;
464 * Reset the remainder after a period of inactivity or when the
465 * direction changes. This prevents the REL_WHEEL emulation point
466 * from sliding for devices that don't always provide the same
467 * number of movements per detent.
469 if (now - previous > 1000000000 || direction != counter->direction)
472 counter->direction = direction;
473 remainder += hi_res_value;
475 /* Some wheels will rest 7/8ths of a detent from the previous detent
476 * after slow movement, so we want the threshold for low-res events to
477 * be in the middle between two detents (e.g. after 4/8ths) as
478 * opposed to on the detents themselves (8/8ths).
480 if (abs(remainder) >= 60) {
481 /* Add (or subtract) 1 because we want to trigger when the wheel
482 * is half-way to the next detent (i.e. scroll 1 detent after a
483 * 1/2 detent movement, 2 detents after a 1 1/2 detent movement,
486 low_res_value = remainder / 120;
487 if (low_res_value == 0)
488 low_res_value = (hi_res_value > 0 ? 1 : -1);
489 input_report_rel(input_dev, REL_WHEEL, low_res_value);
490 remainder -= low_res_value * 120;
492 counter->remainder = remainder;
495 /* -------------------------------------------------------------------------- */
496 /* HIDP++ 1.0 commands */
497 /* -------------------------------------------------------------------------- */
499 #define HIDPP_SET_REGISTER 0x80
500 #define HIDPP_GET_REGISTER 0x81
501 #define HIDPP_SET_LONG_REGISTER 0x82
502 #define HIDPP_GET_LONG_REGISTER 0x83
505 * hidpp10_set_register - Modify a HID++ 1.0 register.
506 * @hidpp_dev: the device to set the register on.
507 * @register_address: the address of the register to modify.
508 * @byte: the byte of the register to modify. Should be less than 3.
509 * @mask: mask of the bits to modify
510 * @value: new values for the bits in mask
511 * Return: 0 if successful, otherwise a negative error code.
513 static int hidpp10_set_register(struct hidpp_device *hidpp_dev,
514 u8 register_address, u8 byte, u8 mask, u8 value)
516 struct hidpp_report response;
518 u8 params[3] = { 0 };
520 ret = hidpp_send_rap_command_sync(hidpp_dev,
521 REPORT_ID_HIDPP_SHORT,
528 memcpy(params, response.rap.params, 3);
530 params[byte] &= ~mask;
531 params[byte] |= value & mask;
533 return hidpp_send_rap_command_sync(hidpp_dev,
534 REPORT_ID_HIDPP_SHORT,
537 params, 3, &response);
540 #define HIDPP_REG_ENABLE_REPORTS 0x00
541 #define HIDPP_ENABLE_CONSUMER_REPORT BIT(0)
542 #define HIDPP_ENABLE_WHEEL_REPORT BIT(2)
543 #define HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT BIT(3)
544 #define HIDPP_ENABLE_BAT_REPORT BIT(4)
545 #define HIDPP_ENABLE_HWHEEL_REPORT BIT(5)
547 static int hidpp10_enable_battery_reporting(struct hidpp_device *hidpp_dev)
549 return hidpp10_set_register(hidpp_dev, HIDPP_REG_ENABLE_REPORTS, 0,
550 HIDPP_ENABLE_BAT_REPORT, HIDPP_ENABLE_BAT_REPORT);
553 #define HIDPP_REG_FEATURES 0x01
554 #define HIDPP_ENABLE_SPECIAL_BUTTON_FUNC BIT(1)
555 #define HIDPP_ENABLE_FAST_SCROLL BIT(6)
557 /* On HID++ 1.0 devices, high-res scroll was called "scrolling acceleration". */
558 static int hidpp10_enable_scrolling_acceleration(struct hidpp_device *hidpp_dev)
560 return hidpp10_set_register(hidpp_dev, HIDPP_REG_FEATURES, 0,
561 HIDPP_ENABLE_FAST_SCROLL, HIDPP_ENABLE_FAST_SCROLL);
564 #define HIDPP_REG_BATTERY_STATUS 0x07
566 static int hidpp10_battery_status_map_level(u8 param)
572 level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
575 level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
578 level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
581 level = POWER_SUPPLY_CAPACITY_LEVEL_HIGH;
584 level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
590 static int hidpp10_battery_status_map_status(u8 param)
596 /* discharging (in use) */
597 status = POWER_SUPPLY_STATUS_DISCHARGING;
599 case 0x21: /* (standard) charging */
600 case 0x24: /* fast charging */
601 case 0x25: /* slow charging */
602 status = POWER_SUPPLY_STATUS_CHARGING;
604 case 0x26: /* topping charge */
605 case 0x22: /* charge complete */
606 status = POWER_SUPPLY_STATUS_FULL;
608 case 0x20: /* unknown */
609 status = POWER_SUPPLY_STATUS_UNKNOWN;
612 * 0x01...0x1F = reserved (not charging)
613 * 0x23 = charging error
614 * 0x27..0xff = reserved
617 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
624 static int hidpp10_query_battery_status(struct hidpp_device *hidpp)
626 struct hidpp_report response;
629 ret = hidpp_send_rap_command_sync(hidpp,
630 REPORT_ID_HIDPP_SHORT,
632 HIDPP_REG_BATTERY_STATUS,
637 hidpp->battery.level =
638 hidpp10_battery_status_map_level(response.rap.params[0]);
639 status = hidpp10_battery_status_map_status(response.rap.params[1]);
640 hidpp->battery.status = status;
641 /* the capacity is only available when discharging or full */
642 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
643 status == POWER_SUPPLY_STATUS_FULL;
648 #define HIDPP_REG_BATTERY_MILEAGE 0x0D
650 static int hidpp10_battery_mileage_map_status(u8 param)
654 switch (param >> 6) {
656 /* discharging (in use) */
657 status = POWER_SUPPLY_STATUS_DISCHARGING;
659 case 0x01: /* charging */
660 status = POWER_SUPPLY_STATUS_CHARGING;
662 case 0x02: /* charge complete */
663 status = POWER_SUPPLY_STATUS_FULL;
666 * 0x03 = charging error
669 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
676 static int hidpp10_query_battery_mileage(struct hidpp_device *hidpp)
678 struct hidpp_report response;
681 ret = hidpp_send_rap_command_sync(hidpp,
682 REPORT_ID_HIDPP_SHORT,
684 HIDPP_REG_BATTERY_MILEAGE,
689 hidpp->battery.capacity = response.rap.params[0];
690 status = hidpp10_battery_mileage_map_status(response.rap.params[2]);
691 hidpp->battery.status = status;
692 /* the capacity is only available when discharging or full */
693 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
694 status == POWER_SUPPLY_STATUS_FULL;
699 static int hidpp10_battery_event(struct hidpp_device *hidpp, u8 *data, int size)
701 struct hidpp_report *report = (struct hidpp_report *)data;
702 int status, capacity, level;
705 if (report->report_id != REPORT_ID_HIDPP_SHORT)
708 switch (report->rap.sub_id) {
709 case HIDPP_REG_BATTERY_STATUS:
710 capacity = hidpp->battery.capacity;
711 level = hidpp10_battery_status_map_level(report->rawbytes[1]);
712 status = hidpp10_battery_status_map_status(report->rawbytes[2]);
714 case HIDPP_REG_BATTERY_MILEAGE:
715 capacity = report->rap.params[0];
716 level = hidpp->battery.level;
717 status = hidpp10_battery_mileage_map_status(report->rawbytes[3]);
723 changed = capacity != hidpp->battery.capacity ||
724 level != hidpp->battery.level ||
725 status != hidpp->battery.status;
727 /* the capacity is only available when discharging or full */
728 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
729 status == POWER_SUPPLY_STATUS_FULL;
732 hidpp->battery.level = level;
733 hidpp->battery.status = status;
734 if (hidpp->battery.ps)
735 power_supply_changed(hidpp->battery.ps);
741 #define HIDPP_REG_PAIRING_INFORMATION 0xB5
742 #define HIDPP_EXTENDED_PAIRING 0x30
743 #define HIDPP_DEVICE_NAME 0x40
745 static char *hidpp_unifying_get_name(struct hidpp_device *hidpp_dev)
747 struct hidpp_report response;
749 u8 params[1] = { HIDPP_DEVICE_NAME };
753 ret = hidpp_send_rap_command_sync(hidpp_dev,
754 REPORT_ID_HIDPP_SHORT,
755 HIDPP_GET_LONG_REGISTER,
756 HIDPP_REG_PAIRING_INFORMATION,
757 params, 1, &response);
761 len = response.rap.params[1];
763 if (2 + len > sizeof(response.rap.params))
766 if (len < 4) /* logitech devices are usually at least Xddd */
769 name = kzalloc(len + 1, GFP_KERNEL);
773 memcpy(name, &response.rap.params[2], len);
775 /* include the terminating '\0' */
776 hidpp_prefix_name(&name, len + 1);
781 static int hidpp_unifying_get_serial(struct hidpp_device *hidpp, u32 *serial)
783 struct hidpp_report response;
785 u8 params[1] = { HIDPP_EXTENDED_PAIRING };
787 ret = hidpp_send_rap_command_sync(hidpp,
788 REPORT_ID_HIDPP_SHORT,
789 HIDPP_GET_LONG_REGISTER,
790 HIDPP_REG_PAIRING_INFORMATION,
791 params, 1, &response);
796 * We don't care about LE or BE, we will output it as a string
797 * with %4phD, so we need to keep the order.
799 *serial = *((u32 *)&response.rap.params[1]);
803 static int hidpp_unifying_init(struct hidpp_device *hidpp)
805 struct hid_device *hdev = hidpp->hid_dev;
810 ret = hidpp_unifying_get_serial(hidpp, &serial);
814 snprintf(hdev->uniq, sizeof(hdev->uniq), "%04x-%4phD",
815 hdev->product, &serial);
816 dbg_hid("HID++ Unifying: Got serial: %s\n", hdev->uniq);
818 name = hidpp_unifying_get_name(hidpp);
822 snprintf(hdev->name, sizeof(hdev->name), "%s", name);
823 dbg_hid("HID++ Unifying: Got name: %s\n", name);
829 /* -------------------------------------------------------------------------- */
831 /* -------------------------------------------------------------------------- */
833 #define HIDPP_PAGE_ROOT 0x0000
834 #define HIDPP_PAGE_ROOT_IDX 0x00
836 #define CMD_ROOT_GET_FEATURE 0x01
837 #define CMD_ROOT_GET_PROTOCOL_VERSION 0x11
839 static int hidpp_root_get_feature(struct hidpp_device *hidpp, u16 feature,
840 u8 *feature_index, u8 *feature_type)
842 struct hidpp_report response;
844 u8 params[2] = { feature >> 8, feature & 0x00FF };
846 ret = hidpp_send_fap_command_sync(hidpp,
848 CMD_ROOT_GET_FEATURE,
849 params, 2, &response);
853 if (response.fap.params[0] == 0)
856 *feature_index = response.fap.params[0];
857 *feature_type = response.fap.params[1];
862 static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
864 const u8 ping_byte = 0x5a;
865 u8 ping_data[3] = { 0, 0, ping_byte };
866 struct hidpp_report response;
869 ret = hidpp_send_rap_command_sync(hidpp,
870 REPORT_ID_HIDPP_SHORT,
872 CMD_ROOT_GET_PROTOCOL_VERSION,
873 ping_data, sizeof(ping_data), &response);
875 if (ret == HIDPP_ERROR_INVALID_SUBID) {
876 hidpp->protocol_major = 1;
877 hidpp->protocol_minor = 0;
881 /* the device might not be connected */
882 if (ret == HIDPP_ERROR_RESOURCE_ERROR)
886 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
893 if (response.rap.params[2] != ping_byte) {
894 hid_err(hidpp->hid_dev, "%s: ping mismatch 0x%02x != 0x%02x\n",
895 __func__, response.rap.params[2], ping_byte);
899 hidpp->protocol_major = response.rap.params[0];
900 hidpp->protocol_minor = response.rap.params[1];
903 hid_info(hidpp->hid_dev, "HID++ %u.%u device connected.\n",
904 hidpp->protocol_major, hidpp->protocol_minor);
908 /* -------------------------------------------------------------------------- */
909 /* 0x0005: GetDeviceNameType */
910 /* -------------------------------------------------------------------------- */
912 #define HIDPP_PAGE_GET_DEVICE_NAME_TYPE 0x0005
914 #define CMD_GET_DEVICE_NAME_TYPE_GET_COUNT 0x01
915 #define CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME 0x11
916 #define CMD_GET_DEVICE_NAME_TYPE_GET_TYPE 0x21
918 static int hidpp_devicenametype_get_count(struct hidpp_device *hidpp,
919 u8 feature_index, u8 *nameLength)
921 struct hidpp_report response;
924 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
925 CMD_GET_DEVICE_NAME_TYPE_GET_COUNT, NULL, 0, &response);
928 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
935 *nameLength = response.fap.params[0];
940 static int hidpp_devicenametype_get_device_name(struct hidpp_device *hidpp,
941 u8 feature_index, u8 char_index, char *device_name, int len_buf)
943 struct hidpp_report response;
947 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
948 CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME, &char_index, 1,
952 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
959 switch (response.report_id) {
960 case REPORT_ID_HIDPP_VERY_LONG:
961 count = hidpp->very_long_report_length - 4;
963 case REPORT_ID_HIDPP_LONG:
964 count = HIDPP_REPORT_LONG_LENGTH - 4;
966 case REPORT_ID_HIDPP_SHORT:
967 count = HIDPP_REPORT_SHORT_LENGTH - 4;
976 for (i = 0; i < count; i++)
977 device_name[i] = response.fap.params[i];
982 static char *hidpp_get_device_name(struct hidpp_device *hidpp)
991 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_GET_DEVICE_NAME_TYPE,
992 &feature_index, &feature_type);
996 ret = hidpp_devicenametype_get_count(hidpp, feature_index,
1001 name = kzalloc(__name_length + 1, GFP_KERNEL);
1005 while (index < __name_length) {
1006 ret = hidpp_devicenametype_get_device_name(hidpp,
1007 feature_index, index, name + index,
1008 __name_length - index);
1016 /* include the terminating '\0' */
1017 hidpp_prefix_name(&name, __name_length + 1);
1022 /* -------------------------------------------------------------------------- */
1023 /* 0x1000: Battery level status */
1024 /* -------------------------------------------------------------------------- */
1026 #define HIDPP_PAGE_BATTERY_LEVEL_STATUS 0x1000
1028 #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS 0x00
1029 #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY 0x10
1031 #define EVENT_BATTERY_LEVEL_STATUS_BROADCAST 0x00
1033 #define FLAG_BATTERY_LEVEL_DISABLE_OSD BIT(0)
1034 #define FLAG_BATTERY_LEVEL_MILEAGE BIT(1)
1035 #define FLAG_BATTERY_LEVEL_RECHARGEABLE BIT(2)
1037 static int hidpp_map_battery_level(int capacity)
1040 return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
1042 * The spec says this should be < 31 but some devices report 30
1043 * with brand new batteries and Windows reports 30 as "Good".
1045 else if (capacity < 30)
1046 return POWER_SUPPLY_CAPACITY_LEVEL_LOW;
1047 else if (capacity < 81)
1048 return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
1049 return POWER_SUPPLY_CAPACITY_LEVEL_FULL;
1052 static int hidpp20_batterylevel_map_status_capacity(u8 data[3], int *capacity,
1058 *capacity = data[0];
1059 *next_capacity = data[1];
1060 *level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
1062 /* When discharging, we can rely on the device reported capacity.
1063 * For all other states the device reports 0 (unknown).
1066 case 0: /* discharging (in use) */
1067 status = POWER_SUPPLY_STATUS_DISCHARGING;
1068 *level = hidpp_map_battery_level(*capacity);
1070 case 1: /* recharging */
1071 status = POWER_SUPPLY_STATUS_CHARGING;
1073 case 2: /* charge in final stage */
1074 status = POWER_SUPPLY_STATUS_CHARGING;
1076 case 3: /* charge complete */
1077 status = POWER_SUPPLY_STATUS_FULL;
1078 *level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
1081 case 4: /* recharging below optimal speed */
1082 status = POWER_SUPPLY_STATUS_CHARGING;
1084 /* 5 = invalid battery type
1086 7 = other charging error */
1088 status = POWER_SUPPLY_STATUS_NOT_CHARGING;
1095 static int hidpp20_batterylevel_get_battery_capacity(struct hidpp_device *hidpp,
1102 struct hidpp_report response;
1104 u8 *params = (u8 *)response.fap.params;
1106 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1107 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS,
1108 NULL, 0, &response);
1110 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1117 *status = hidpp20_batterylevel_map_status_capacity(params, capacity,
1124 static int hidpp20_batterylevel_get_battery_info(struct hidpp_device *hidpp,
1127 struct hidpp_report response;
1129 u8 *params = (u8 *)response.fap.params;
1130 unsigned int level_count, flags;
1132 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1133 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY,
1134 NULL, 0, &response);
1136 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1143 level_count = params[0];
1146 if (level_count < 10 || !(flags & FLAG_BATTERY_LEVEL_MILEAGE))
1147 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS;
1149 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
1154 static int hidpp20_query_battery_info(struct hidpp_device *hidpp)
1158 int status, capacity, next_capacity, level;
1160 if (hidpp->battery.feature_index == 0xff) {
1161 ret = hidpp_root_get_feature(hidpp,
1162 HIDPP_PAGE_BATTERY_LEVEL_STATUS,
1163 &hidpp->battery.feature_index,
1169 ret = hidpp20_batterylevel_get_battery_capacity(hidpp,
1170 hidpp->battery.feature_index,
1172 &next_capacity, &level);
1176 ret = hidpp20_batterylevel_get_battery_info(hidpp,
1177 hidpp->battery.feature_index);
1181 hidpp->battery.status = status;
1182 hidpp->battery.capacity = capacity;
1183 hidpp->battery.level = level;
1184 /* the capacity is only available when discharging or full */
1185 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
1186 status == POWER_SUPPLY_STATUS_FULL;
1191 static int hidpp20_battery_event(struct hidpp_device *hidpp,
1194 struct hidpp_report *report = (struct hidpp_report *)data;
1195 int status, capacity, next_capacity, level;
1198 if (report->fap.feature_index != hidpp->battery.feature_index ||
1199 report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST)
1202 status = hidpp20_batterylevel_map_status_capacity(report->fap.params,
1207 /* the capacity is only available when discharging or full */
1208 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
1209 status == POWER_SUPPLY_STATUS_FULL;
1211 changed = capacity != hidpp->battery.capacity ||
1212 level != hidpp->battery.level ||
1213 status != hidpp->battery.status;
1216 hidpp->battery.level = level;
1217 hidpp->battery.capacity = capacity;
1218 hidpp->battery.status = status;
1219 if (hidpp->battery.ps)
1220 power_supply_changed(hidpp->battery.ps);
1226 static enum power_supply_property hidpp_battery_props[] = {
1227 POWER_SUPPLY_PROP_ONLINE,
1228 POWER_SUPPLY_PROP_STATUS,
1229 POWER_SUPPLY_PROP_SCOPE,
1230 POWER_SUPPLY_PROP_MODEL_NAME,
1231 POWER_SUPPLY_PROP_MANUFACTURER,
1232 POWER_SUPPLY_PROP_SERIAL_NUMBER,
1233 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY, */
1234 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY_LEVEL, */
1237 static int hidpp_battery_get_property(struct power_supply *psy,
1238 enum power_supply_property psp,
1239 union power_supply_propval *val)
1241 struct hidpp_device *hidpp = power_supply_get_drvdata(psy);
1245 case POWER_SUPPLY_PROP_STATUS:
1246 val->intval = hidpp->battery.status;
1248 case POWER_SUPPLY_PROP_CAPACITY:
1249 val->intval = hidpp->battery.capacity;
1251 case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
1252 val->intval = hidpp->battery.level;
1254 case POWER_SUPPLY_PROP_SCOPE:
1255 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1257 case POWER_SUPPLY_PROP_ONLINE:
1258 val->intval = hidpp->battery.online;
1260 case POWER_SUPPLY_PROP_MODEL_NAME:
1261 if (!strncmp(hidpp->name, "Logitech ", 9))
1262 val->strval = hidpp->name + 9;
1264 val->strval = hidpp->name;
1266 case POWER_SUPPLY_PROP_MANUFACTURER:
1267 val->strval = "Logitech";
1269 case POWER_SUPPLY_PROP_SERIAL_NUMBER:
1270 val->strval = hidpp->hid_dev->uniq;
1280 /* -------------------------------------------------------------------------- */
1281 /* 0x2120: Hi-resolution scrolling */
1282 /* -------------------------------------------------------------------------- */
1284 #define HIDPP_PAGE_HI_RESOLUTION_SCROLLING 0x2120
1286 #define CMD_HI_RESOLUTION_SCROLLING_SET_HIGHRES_SCROLLING_MODE 0x10
1288 static int hidpp_hrs_set_highres_scrolling_mode(struct hidpp_device *hidpp,
1289 bool enabled, u8 *multiplier)
1295 struct hidpp_report response;
1297 ret = hidpp_root_get_feature(hidpp,
1298 HIDPP_PAGE_HI_RESOLUTION_SCROLLING,
1304 params[0] = enabled ? BIT(0) : 0;
1305 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1306 CMD_HI_RESOLUTION_SCROLLING_SET_HIGHRES_SCROLLING_MODE,
1307 params, sizeof(params), &response);
1310 *multiplier = response.fap.params[1];
1314 /* -------------------------------------------------------------------------- */
1315 /* 0x2121: HiRes Wheel */
1316 /* -------------------------------------------------------------------------- */
1318 #define HIDPP_PAGE_HIRES_WHEEL 0x2121
1320 #define CMD_HIRES_WHEEL_GET_WHEEL_CAPABILITY 0x00
1321 #define CMD_HIRES_WHEEL_SET_WHEEL_MODE 0x20
1323 static int hidpp_hrw_get_wheel_capability(struct hidpp_device *hidpp,
1329 struct hidpp_report response;
1331 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_HIRES_WHEEL,
1332 &feature_index, &feature_type);
1334 goto return_default;
1336 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1337 CMD_HIRES_WHEEL_GET_WHEEL_CAPABILITY,
1338 NULL, 0, &response);
1340 goto return_default;
1342 *multiplier = response.fap.params[0];
1345 hid_warn(hidpp->hid_dev,
1346 "Couldn't get wheel multiplier (error %d)\n", ret);
1350 static int hidpp_hrw_set_wheel_mode(struct hidpp_device *hidpp, bool invert,
1351 bool high_resolution, bool use_hidpp)
1357 struct hidpp_report response;
1359 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_HIRES_WHEEL,
1360 &feature_index, &feature_type);
1364 params[0] = (invert ? BIT(2) : 0) |
1365 (high_resolution ? BIT(1) : 0) |
1366 (use_hidpp ? BIT(0) : 0);
1368 return hidpp_send_fap_command_sync(hidpp, feature_index,
1369 CMD_HIRES_WHEEL_SET_WHEEL_MODE,
1370 params, sizeof(params), &response);
1373 /* -------------------------------------------------------------------------- */
1374 /* 0x4301: Solar Keyboard */
1375 /* -------------------------------------------------------------------------- */
1377 #define HIDPP_PAGE_SOLAR_KEYBOARD 0x4301
1379 #define CMD_SOLAR_SET_LIGHT_MEASURE 0x00
1381 #define EVENT_SOLAR_BATTERY_BROADCAST 0x00
1382 #define EVENT_SOLAR_BATTERY_LIGHT_MEASURE 0x10
1383 #define EVENT_SOLAR_CHECK_LIGHT_BUTTON 0x20
1385 static int hidpp_solar_request_battery_event(struct hidpp_device *hidpp)
1387 struct hidpp_report response;
1388 u8 params[2] = { 1, 1 };
1392 if (hidpp->battery.feature_index == 0xff) {
1393 ret = hidpp_root_get_feature(hidpp,
1394 HIDPP_PAGE_SOLAR_KEYBOARD,
1395 &hidpp->battery.solar_feature_index,
1401 ret = hidpp_send_fap_command_sync(hidpp,
1402 hidpp->battery.solar_feature_index,
1403 CMD_SOLAR_SET_LIGHT_MEASURE,
1404 params, 2, &response);
1406 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1413 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
1418 static int hidpp_solar_battery_event(struct hidpp_device *hidpp,
1421 struct hidpp_report *report = (struct hidpp_report *)data;
1422 int capacity, lux, status;
1425 function = report->fap.funcindex_clientid;
1428 if (report->fap.feature_index != hidpp->battery.solar_feature_index ||
1429 !(function == EVENT_SOLAR_BATTERY_BROADCAST ||
1430 function == EVENT_SOLAR_BATTERY_LIGHT_MEASURE ||
1431 function == EVENT_SOLAR_CHECK_LIGHT_BUTTON))
1434 capacity = report->fap.params[0];
1437 case EVENT_SOLAR_BATTERY_LIGHT_MEASURE:
1438 lux = (report->fap.params[1] << 8) | report->fap.params[2];
1440 status = POWER_SUPPLY_STATUS_CHARGING;
1442 status = POWER_SUPPLY_STATUS_DISCHARGING;
1444 case EVENT_SOLAR_CHECK_LIGHT_BUTTON:
1446 if (capacity < hidpp->battery.capacity)
1447 status = POWER_SUPPLY_STATUS_DISCHARGING;
1449 status = POWER_SUPPLY_STATUS_CHARGING;
1453 if (capacity == 100)
1454 status = POWER_SUPPLY_STATUS_FULL;
1456 hidpp->battery.online = true;
1457 if (capacity != hidpp->battery.capacity ||
1458 status != hidpp->battery.status) {
1459 hidpp->battery.capacity = capacity;
1460 hidpp->battery.status = status;
1461 if (hidpp->battery.ps)
1462 power_supply_changed(hidpp->battery.ps);
1468 /* -------------------------------------------------------------------------- */
1469 /* 0x6010: Touchpad FW items */
1470 /* -------------------------------------------------------------------------- */
1472 #define HIDPP_PAGE_TOUCHPAD_FW_ITEMS 0x6010
1474 #define CMD_TOUCHPAD_FW_ITEMS_SET 0x10
1476 struct hidpp_touchpad_fw_items {
1478 uint8_t desired_state;
1484 * send a set state command to the device by reading the current items->state
1485 * field. items is then filled with the current state.
1487 static int hidpp_touchpad_fw_items_set(struct hidpp_device *hidpp,
1489 struct hidpp_touchpad_fw_items *items)
1491 struct hidpp_report response;
1493 u8 *params = (u8 *)response.fap.params;
1495 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1496 CMD_TOUCHPAD_FW_ITEMS_SET, &items->state, 1, &response);
1499 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1506 items->presence = params[0];
1507 items->desired_state = params[1];
1508 items->state = params[2];
1509 items->persistent = params[3];
1514 /* -------------------------------------------------------------------------- */
1515 /* 0x6100: TouchPadRawXY */
1516 /* -------------------------------------------------------------------------- */
1518 #define HIDPP_PAGE_TOUCHPAD_RAW_XY 0x6100
1520 #define CMD_TOUCHPAD_GET_RAW_INFO 0x01
1521 #define CMD_TOUCHPAD_SET_RAW_REPORT_STATE 0x21
1523 #define EVENT_TOUCHPAD_RAW_XY 0x00
1525 #define TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT 0x01
1526 #define TOUCHPAD_RAW_XY_ORIGIN_UPPER_LEFT 0x03
1528 struct hidpp_touchpad_raw_info {
1539 struct hidpp_touchpad_raw_xy_finger {
1549 struct hidpp_touchpad_raw_xy {
1551 struct hidpp_touchpad_raw_xy_finger fingers[2];
1558 static int hidpp_touchpad_get_raw_info(struct hidpp_device *hidpp,
1559 u8 feature_index, struct hidpp_touchpad_raw_info *raw_info)
1561 struct hidpp_report response;
1563 u8 *params = (u8 *)response.fap.params;
1565 ret = hidpp_send_fap_command_sync(hidpp, feature_index,
1566 CMD_TOUCHPAD_GET_RAW_INFO, NULL, 0, &response);
1569 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
1576 raw_info->x_size = get_unaligned_be16(¶ms[0]);
1577 raw_info->y_size = get_unaligned_be16(¶ms[2]);
1578 raw_info->z_range = params[4];
1579 raw_info->area_range = params[5];
1580 raw_info->maxcontacts = params[7];
1581 raw_info->origin = params[8];
1582 /* res is given in unit per inch */
1583 raw_info->res = get_unaligned_be16(¶ms[13]) * 2 / 51;
1588 static int hidpp_touchpad_set_raw_report_state(struct hidpp_device *hidpp_dev,
1589 u8 feature_index, bool send_raw_reports,
1590 bool sensor_enhanced_settings)
1592 struct hidpp_report response;
1596 * bit 0 - enable raw
1597 * bit 1 - 16bit Z, no area
1598 * bit 2 - enhanced sensitivity
1599 * bit 3 - width, height (4 bits each) instead of area
1600 * bit 4 - send raw + gestures (degrades smoothness)
1601 * remaining bits - reserved
1603 u8 params = send_raw_reports | (sensor_enhanced_settings << 2);
1605 return hidpp_send_fap_command_sync(hidpp_dev, feature_index,
1606 CMD_TOUCHPAD_SET_RAW_REPORT_STATE, ¶ms, 1, &response);
1609 static void hidpp_touchpad_touch_event(u8 *data,
1610 struct hidpp_touchpad_raw_xy_finger *finger)
1612 u8 x_m = data[0] << 2;
1613 u8 y_m = data[2] << 2;
1615 finger->x = x_m << 6 | data[1];
1616 finger->y = y_m << 6 | data[3];
1618 finger->contact_type = data[0] >> 6;
1619 finger->contact_status = data[2] >> 6;
1621 finger->z = data[4];
1622 finger->area = data[5];
1623 finger->finger_id = data[6] >> 4;
1626 static void hidpp_touchpad_raw_xy_event(struct hidpp_device *hidpp_dev,
1627 u8 *data, struct hidpp_touchpad_raw_xy *raw_xy)
1629 memset(raw_xy, 0, sizeof(struct hidpp_touchpad_raw_xy));
1630 raw_xy->end_of_frame = data[8] & 0x01;
1631 raw_xy->spurious_flag = (data[8] >> 1) & 0x01;
1632 raw_xy->finger_count = data[15] & 0x0f;
1633 raw_xy->button = (data[8] >> 2) & 0x01;
1635 if (raw_xy->finger_count) {
1636 hidpp_touchpad_touch_event(&data[2], &raw_xy->fingers[0]);
1637 hidpp_touchpad_touch_event(&data[9], &raw_xy->fingers[1]);
1641 /* -------------------------------------------------------------------------- */
1642 /* 0x8123: Force feedback support */
1643 /* -------------------------------------------------------------------------- */
1645 #define HIDPP_FF_GET_INFO 0x01
1646 #define HIDPP_FF_RESET_ALL 0x11
1647 #define HIDPP_FF_DOWNLOAD_EFFECT 0x21
1648 #define HIDPP_FF_SET_EFFECT_STATE 0x31
1649 #define HIDPP_FF_DESTROY_EFFECT 0x41
1650 #define HIDPP_FF_GET_APERTURE 0x51
1651 #define HIDPP_FF_SET_APERTURE 0x61
1652 #define HIDPP_FF_GET_GLOBAL_GAINS 0x71
1653 #define HIDPP_FF_SET_GLOBAL_GAINS 0x81
1655 #define HIDPP_FF_EFFECT_STATE_GET 0x00
1656 #define HIDPP_FF_EFFECT_STATE_STOP 0x01
1657 #define HIDPP_FF_EFFECT_STATE_PLAY 0x02
1658 #define HIDPP_FF_EFFECT_STATE_PAUSE 0x03
1660 #define HIDPP_FF_EFFECT_CONSTANT 0x00
1661 #define HIDPP_FF_EFFECT_PERIODIC_SINE 0x01
1662 #define HIDPP_FF_EFFECT_PERIODIC_SQUARE 0x02
1663 #define HIDPP_FF_EFFECT_PERIODIC_TRIANGLE 0x03
1664 #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP 0x04
1665 #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN 0x05
1666 #define HIDPP_FF_EFFECT_SPRING 0x06
1667 #define HIDPP_FF_EFFECT_DAMPER 0x07
1668 #define HIDPP_FF_EFFECT_FRICTION 0x08
1669 #define HIDPP_FF_EFFECT_INERTIA 0x09
1670 #define HIDPP_FF_EFFECT_RAMP 0x0A
1672 #define HIDPP_FF_EFFECT_AUTOSTART 0x80
1674 #define HIDPP_FF_EFFECTID_NONE -1
1675 #define HIDPP_FF_EFFECTID_AUTOCENTER -2
1677 #define HIDPP_FF_MAX_PARAMS 20
1678 #define HIDPP_FF_RESERVED_SLOTS 1
1680 struct hidpp_ff_private_data {
1681 struct hidpp_device *hidpp;
1689 struct workqueue_struct *wq;
1690 atomic_t workqueue_size;
1693 struct hidpp_ff_work_data {
1694 struct work_struct work;
1695 struct hidpp_ff_private_data *data;
1698 u8 params[HIDPP_FF_MAX_PARAMS];
1702 static const signed short hidpp_ff_effects[] = {
1717 static const signed short hidpp_ff_effects_v2[] = {
1724 static const u8 HIDPP_FF_CONDITION_CMDS[] = {
1725 HIDPP_FF_EFFECT_SPRING,
1726 HIDPP_FF_EFFECT_FRICTION,
1727 HIDPP_FF_EFFECT_DAMPER,
1728 HIDPP_FF_EFFECT_INERTIA
1731 static const char *HIDPP_FF_CONDITION_NAMES[] = {
1739 static u8 hidpp_ff_find_effect(struct hidpp_ff_private_data *data, int effect_id)
1743 for (i = 0; i < data->num_effects; i++)
1744 if (data->effect_ids[i] == effect_id)
1750 static void hidpp_ff_work_handler(struct work_struct *w)
1752 struct hidpp_ff_work_data *wd = container_of(w, struct hidpp_ff_work_data, work);
1753 struct hidpp_ff_private_data *data = wd->data;
1754 struct hidpp_report response;
1758 /* add slot number if needed */
1759 switch (wd->effect_id) {
1760 case HIDPP_FF_EFFECTID_AUTOCENTER:
1761 wd->params[0] = data->slot_autocenter;
1763 case HIDPP_FF_EFFECTID_NONE:
1764 /* leave slot as zero */
1767 /* find current slot for effect */
1768 wd->params[0] = hidpp_ff_find_effect(data, wd->effect_id);
1772 /* send command and wait for reply */
1773 ret = hidpp_send_fap_command_sync(data->hidpp, data->feature_index,
1774 wd->command, wd->params, wd->size, &response);
1777 hid_err(data->hidpp->hid_dev, "Failed to send command to device!\n");
1781 /* parse return data */
1782 switch (wd->command) {
1783 case HIDPP_FF_DOWNLOAD_EFFECT:
1784 slot = response.fap.params[0];
1785 if (slot > 0 && slot <= data->num_effects) {
1786 if (wd->effect_id >= 0)
1787 /* regular effect uploaded */
1788 data->effect_ids[slot-1] = wd->effect_id;
1789 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
1790 /* autocenter spring uploaded */
1791 data->slot_autocenter = slot;
1794 case HIDPP_FF_DESTROY_EFFECT:
1795 if (wd->effect_id >= 0)
1796 /* regular effect destroyed */
1797 data->effect_ids[wd->params[0]-1] = -1;
1798 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
1799 /* autocenter spring destoyed */
1800 data->slot_autocenter = 0;
1802 case HIDPP_FF_SET_GLOBAL_GAINS:
1803 data->gain = (wd->params[0] << 8) + wd->params[1];
1805 case HIDPP_FF_SET_APERTURE:
1806 data->range = (wd->params[0] << 8) + wd->params[1];
1809 /* no action needed */
1814 atomic_dec(&data->workqueue_size);
1818 static int hidpp_ff_queue_work(struct hidpp_ff_private_data *data, int effect_id, u8 command, u8 *params, u8 size)
1820 struct hidpp_ff_work_data *wd = kzalloc(sizeof(*wd), GFP_KERNEL);
1826 INIT_WORK(&wd->work, hidpp_ff_work_handler);
1829 wd->effect_id = effect_id;
1830 wd->command = command;
1832 memcpy(wd->params, params, size);
1834 atomic_inc(&data->workqueue_size);
1835 queue_work(data->wq, &wd->work);
1837 /* warn about excessive queue size */
1838 s = atomic_read(&data->workqueue_size);
1839 if (s >= 20 && s % 20 == 0)
1840 hid_warn(data->hidpp->hid_dev, "Force feedback command queue contains %d commands, causing substantial delays!", s);
1845 static int hidpp_ff_upload_effect(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old)
1847 struct hidpp_ff_private_data *data = dev->ff->private;
1852 /* set common parameters */
1853 params[2] = effect->replay.length >> 8;
1854 params[3] = effect->replay.length & 255;
1855 params[4] = effect->replay.delay >> 8;
1856 params[5] = effect->replay.delay & 255;
1858 switch (effect->type) {
1860 force = (effect->u.constant.level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1861 params[1] = HIDPP_FF_EFFECT_CONSTANT;
1862 params[6] = force >> 8;
1863 params[7] = force & 255;
1864 params[8] = effect->u.constant.envelope.attack_level >> 7;
1865 params[9] = effect->u.constant.envelope.attack_length >> 8;
1866 params[10] = effect->u.constant.envelope.attack_length & 255;
1867 params[11] = effect->u.constant.envelope.fade_level >> 7;
1868 params[12] = effect->u.constant.envelope.fade_length >> 8;
1869 params[13] = effect->u.constant.envelope.fade_length & 255;
1871 dbg_hid("Uploading constant force level=%d in dir %d = %d\n",
1872 effect->u.constant.level,
1873 effect->direction, force);
1874 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1875 effect->u.constant.envelope.attack_level,
1876 effect->u.constant.envelope.attack_length,
1877 effect->u.constant.envelope.fade_level,
1878 effect->u.constant.envelope.fade_length);
1882 switch (effect->u.periodic.waveform) {
1884 params[1] = HIDPP_FF_EFFECT_PERIODIC_SINE;
1887 params[1] = HIDPP_FF_EFFECT_PERIODIC_SQUARE;
1890 params[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP;
1893 params[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN;
1896 params[1] = HIDPP_FF_EFFECT_PERIODIC_TRIANGLE;
1899 hid_err(data->hidpp->hid_dev, "Unexpected periodic waveform type %i!\n", effect->u.periodic.waveform);
1902 force = (effect->u.periodic.magnitude * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1903 params[6] = effect->u.periodic.magnitude >> 8;
1904 params[7] = effect->u.periodic.magnitude & 255;
1905 params[8] = effect->u.periodic.offset >> 8;
1906 params[9] = effect->u.periodic.offset & 255;
1907 params[10] = effect->u.periodic.period >> 8;
1908 params[11] = effect->u.periodic.period & 255;
1909 params[12] = effect->u.periodic.phase >> 8;
1910 params[13] = effect->u.periodic.phase & 255;
1911 params[14] = effect->u.periodic.envelope.attack_level >> 7;
1912 params[15] = effect->u.periodic.envelope.attack_length >> 8;
1913 params[16] = effect->u.periodic.envelope.attack_length & 255;
1914 params[17] = effect->u.periodic.envelope.fade_level >> 7;
1915 params[18] = effect->u.periodic.envelope.fade_length >> 8;
1916 params[19] = effect->u.periodic.envelope.fade_length & 255;
1918 dbg_hid("Uploading periodic force mag=%d/dir=%d, offset=%d, period=%d ms, phase=%d\n",
1919 effect->u.periodic.magnitude, effect->direction,
1920 effect->u.periodic.offset,
1921 effect->u.periodic.period,
1922 effect->u.periodic.phase);
1923 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1924 effect->u.periodic.envelope.attack_level,
1925 effect->u.periodic.envelope.attack_length,
1926 effect->u.periodic.envelope.fade_level,
1927 effect->u.periodic.envelope.fade_length);
1931 params[1] = HIDPP_FF_EFFECT_RAMP;
1932 force = (effect->u.ramp.start_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1933 params[6] = force >> 8;
1934 params[7] = force & 255;
1935 force = (effect->u.ramp.end_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
1936 params[8] = force >> 8;
1937 params[9] = force & 255;
1938 params[10] = effect->u.ramp.envelope.attack_level >> 7;
1939 params[11] = effect->u.ramp.envelope.attack_length >> 8;
1940 params[12] = effect->u.ramp.envelope.attack_length & 255;
1941 params[13] = effect->u.ramp.envelope.fade_level >> 7;
1942 params[14] = effect->u.ramp.envelope.fade_length >> 8;
1943 params[15] = effect->u.ramp.envelope.fade_length & 255;
1945 dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n",
1946 effect->u.ramp.start_level,
1947 effect->u.ramp.end_level,
1948 effect->direction, force);
1949 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
1950 effect->u.ramp.envelope.attack_level,
1951 effect->u.ramp.envelope.attack_length,
1952 effect->u.ramp.envelope.fade_level,
1953 effect->u.ramp.envelope.fade_length);
1959 params[1] = HIDPP_FF_CONDITION_CMDS[effect->type - FF_SPRING];
1960 params[6] = effect->u.condition[0].left_saturation >> 9;
1961 params[7] = (effect->u.condition[0].left_saturation >> 1) & 255;
1962 params[8] = effect->u.condition[0].left_coeff >> 8;
1963 params[9] = effect->u.condition[0].left_coeff & 255;
1964 params[10] = effect->u.condition[0].deadband >> 9;
1965 params[11] = (effect->u.condition[0].deadband >> 1) & 255;
1966 params[12] = effect->u.condition[0].center >> 8;
1967 params[13] = effect->u.condition[0].center & 255;
1968 params[14] = effect->u.condition[0].right_coeff >> 8;
1969 params[15] = effect->u.condition[0].right_coeff & 255;
1970 params[16] = effect->u.condition[0].right_saturation >> 9;
1971 params[17] = (effect->u.condition[0].right_saturation >> 1) & 255;
1973 dbg_hid("Uploading %s force left coeff=%d, left sat=%d, right coeff=%d, right sat=%d\n",
1974 HIDPP_FF_CONDITION_NAMES[effect->type - FF_SPRING],
1975 effect->u.condition[0].left_coeff,
1976 effect->u.condition[0].left_saturation,
1977 effect->u.condition[0].right_coeff,
1978 effect->u.condition[0].right_saturation);
1979 dbg_hid(" deadband=%d, center=%d\n",
1980 effect->u.condition[0].deadband,
1981 effect->u.condition[0].center);
1984 hid_err(data->hidpp->hid_dev, "Unexpected force type %i!\n", effect->type);
1988 return hidpp_ff_queue_work(data, effect->id, HIDPP_FF_DOWNLOAD_EFFECT, params, size);
1991 static int hidpp_ff_playback(struct input_dev *dev, int effect_id, int value)
1993 struct hidpp_ff_private_data *data = dev->ff->private;
1996 params[1] = value ? HIDPP_FF_EFFECT_STATE_PLAY : HIDPP_FF_EFFECT_STATE_STOP;
1998 dbg_hid("St%sing playback of effect %d.\n", value?"art":"opp", effect_id);
2000 return hidpp_ff_queue_work(data, effect_id, HIDPP_FF_SET_EFFECT_STATE, params, ARRAY_SIZE(params));
2003 static int hidpp_ff_erase_effect(struct input_dev *dev, int effect_id)
2005 struct hidpp_ff_private_data *data = dev->ff->private;
2008 dbg_hid("Erasing effect %d.\n", effect_id);
2010 return hidpp_ff_queue_work(data, effect_id, HIDPP_FF_DESTROY_EFFECT, &slot, 1);
2013 static void hidpp_ff_set_autocenter(struct input_dev *dev, u16 magnitude)
2015 struct hidpp_ff_private_data *data = dev->ff->private;
2018 dbg_hid("Setting autocenter to %d.\n", magnitude);
2020 /* start a standard spring effect */
2021 params[1] = HIDPP_FF_EFFECT_SPRING | HIDPP_FF_EFFECT_AUTOSTART;
2022 /* zero delay and duration */
2023 params[2] = params[3] = params[4] = params[5] = 0;
2024 /* set coeff to 25% of saturation */
2025 params[8] = params[14] = magnitude >> 11;
2026 params[9] = params[15] = (magnitude >> 3) & 255;
2027 params[6] = params[16] = magnitude >> 9;
2028 params[7] = params[17] = (magnitude >> 1) & 255;
2029 /* zero deadband and center */
2030 params[10] = params[11] = params[12] = params[13] = 0;
2032 hidpp_ff_queue_work(data, HIDPP_FF_EFFECTID_AUTOCENTER, HIDPP_FF_DOWNLOAD_EFFECT, params, ARRAY_SIZE(params));
2035 static void hidpp_ff_set_gain(struct input_dev *dev, u16 gain)
2037 struct hidpp_ff_private_data *data = dev->ff->private;
2040 dbg_hid("Setting gain to %d.\n", gain);
2042 params[0] = gain >> 8;
2043 params[1] = gain & 255;
2044 params[2] = 0; /* no boost */
2047 hidpp_ff_queue_work(data, HIDPP_FF_EFFECTID_NONE, HIDPP_FF_SET_GLOBAL_GAINS, params, ARRAY_SIZE(params));
2050 static ssize_t hidpp_ff_range_show(struct device *dev, struct device_attribute *attr, char *buf)
2052 struct hid_device *hid = to_hid_device(dev);
2053 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2054 struct input_dev *idev = hidinput->input;
2055 struct hidpp_ff_private_data *data = idev->ff->private;
2057 return scnprintf(buf, PAGE_SIZE, "%u\n", data->range);
2060 static ssize_t hidpp_ff_range_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
2062 struct hid_device *hid = to_hid_device(dev);
2063 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2064 struct input_dev *idev = hidinput->input;
2065 struct hidpp_ff_private_data *data = idev->ff->private;
2067 int range = simple_strtoul(buf, NULL, 10);
2069 range = clamp(range, 180, 900);
2071 params[0] = range >> 8;
2072 params[1] = range & 0x00FF;
2074 hidpp_ff_queue_work(data, -1, HIDPP_FF_SET_APERTURE, params, ARRAY_SIZE(params));
2079 static DEVICE_ATTR(range, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, hidpp_ff_range_show, hidpp_ff_range_store);
2081 static void hidpp_ff_destroy(struct ff_device *ff)
2083 struct hidpp_ff_private_data *data = ff->private;
2085 kfree(data->effect_ids);
2088 static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index)
2090 struct hid_device *hid = hidpp->hid_dev;
2091 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2092 struct input_dev *dev = hidinput->input;
2093 const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
2094 const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice);
2095 struct ff_device *ff;
2096 struct hidpp_report response;
2097 struct hidpp_ff_private_data *data;
2098 int error, j, num_slots;
2102 hid_err(hid, "Struct input_dev not set!\n");
2106 /* Get firmware release */
2107 version = bcdDevice & 255;
2109 /* Set supported force feedback capabilities */
2110 for (j = 0; hidpp_ff_effects[j] >= 0; j++)
2111 set_bit(hidpp_ff_effects[j], dev->ffbit);
2113 for (j = 0; hidpp_ff_effects_v2[j] >= 0; j++)
2114 set_bit(hidpp_ff_effects_v2[j], dev->ffbit);
2116 /* Read number of slots available in device */
2117 error = hidpp_send_fap_command_sync(hidpp, feature_index,
2118 HIDPP_FF_GET_INFO, NULL, 0, &response);
2122 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
2127 num_slots = response.fap.params[0] - HIDPP_FF_RESERVED_SLOTS;
2129 error = input_ff_create(dev, num_slots);
2132 hid_err(dev, "Failed to create FF device!\n");
2136 data = kzalloc(sizeof(*data), GFP_KERNEL);
2139 data->effect_ids = kcalloc(num_slots, sizeof(int), GFP_KERNEL);
2140 if (!data->effect_ids) {
2144 data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue");
2146 kfree(data->effect_ids);
2151 data->hidpp = hidpp;
2152 data->feature_index = feature_index;
2153 data->version = version;
2154 data->slot_autocenter = 0;
2155 data->num_effects = num_slots;
2156 for (j = 0; j < num_slots; j++)
2157 data->effect_ids[j] = -1;
2162 ff->upload = hidpp_ff_upload_effect;
2163 ff->erase = hidpp_ff_erase_effect;
2164 ff->playback = hidpp_ff_playback;
2165 ff->set_gain = hidpp_ff_set_gain;
2166 ff->set_autocenter = hidpp_ff_set_autocenter;
2167 ff->destroy = hidpp_ff_destroy;
2170 /* reset all forces */
2171 error = hidpp_send_fap_command_sync(hidpp, feature_index,
2172 HIDPP_FF_RESET_ALL, NULL, 0, &response);
2174 /* Read current Range */
2175 error = hidpp_send_fap_command_sync(hidpp, feature_index,
2176 HIDPP_FF_GET_APERTURE, NULL, 0, &response);
2178 hid_warn(hidpp->hid_dev, "Failed to read range from device!\n");
2179 data->range = error ? 900 : get_unaligned_be16(&response.fap.params[0]);
2181 /* Create sysfs interface */
2182 error = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range);
2184 hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d!\n", error);
2186 /* Read the current gain values */
2187 error = hidpp_send_fap_command_sync(hidpp, feature_index,
2188 HIDPP_FF_GET_GLOBAL_GAINS, NULL, 0, &response);
2190 hid_warn(hidpp->hid_dev, "Failed to read gain values from device!\n");
2191 data->gain = error ? 0xffff : get_unaligned_be16(&response.fap.params[0]);
2192 /* ignore boost value at response.fap.params[2] */
2194 /* init the hardware command queue */
2195 atomic_set(&data->workqueue_size, 0);
2197 /* initialize with zero autocenter to get wheel in usable state */
2198 hidpp_ff_set_autocenter(dev, 0);
2200 hid_info(hid, "Force feedback support loaded (firmware release %d).\n",
2206 static int hidpp_ff_deinit(struct hid_device *hid)
2208 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
2209 struct input_dev *dev = hidinput->input;
2210 struct hidpp_ff_private_data *data;
2213 hid_err(hid, "Struct input_dev not found!\n");
2217 hid_info(hid, "Unloading HID++ force feedback.\n");
2218 data = dev->ff->private;
2220 hid_err(hid, "Private data not found!\n");
2224 destroy_workqueue(data->wq);
2225 device_remove_file(&hid->dev, &dev_attr_range);
2231 /* ************************************************************************** */
2233 /* Device Support */
2235 /* ************************************************************************** */
2237 /* -------------------------------------------------------------------------- */
2238 /* Touchpad HID++ devices */
2239 /* -------------------------------------------------------------------------- */
2241 #define WTP_MANUAL_RESOLUTION 39
2246 u8 mt_feature_index;
2247 u8 button_feature_index;
2250 unsigned int resolution;
2253 static int wtp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
2254 struct hid_field *field, struct hid_usage *usage,
2255 unsigned long **bit, int *max)
2260 static void wtp_populate_input(struct hidpp_device *hidpp,
2261 struct input_dev *input_dev)
2263 struct wtp_data *wd = hidpp->private_data;
2265 __set_bit(EV_ABS, input_dev->evbit);
2266 __set_bit(EV_KEY, input_dev->evbit);
2267 __clear_bit(EV_REL, input_dev->evbit);
2268 __clear_bit(EV_LED, input_dev->evbit);
2270 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0);
2271 input_abs_set_res(input_dev, ABS_MT_POSITION_X, wd->resolution);
2272 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0);
2273 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, wd->resolution);
2275 /* Max pressure is not given by the devices, pick one */
2276 input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 50, 0, 0);
2278 input_set_capability(input_dev, EV_KEY, BTN_LEFT);
2280 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS)
2281 input_set_capability(input_dev, EV_KEY, BTN_RIGHT);
2283 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
2285 input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER |
2286 INPUT_MT_DROP_UNUSED);
2289 static void wtp_touch_event(struct hidpp_device *hidpp,
2290 struct hidpp_touchpad_raw_xy_finger *touch_report)
2292 struct wtp_data *wd = hidpp->private_data;
2295 if (!touch_report->finger_id || touch_report->contact_type)
2296 /* no actual data */
2299 slot = input_mt_get_slot_by_key(hidpp->input, touch_report->finger_id);
2301 input_mt_slot(hidpp->input, slot);
2302 input_mt_report_slot_state(hidpp->input, MT_TOOL_FINGER,
2303 touch_report->contact_status);
2304 if (touch_report->contact_status) {
2305 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_X,
2307 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_Y,
2308 wd->flip_y ? wd->y_size - touch_report->y :
2310 input_event(hidpp->input, EV_ABS, ABS_MT_PRESSURE,
2311 touch_report->area);
2315 static void wtp_send_raw_xy_event(struct hidpp_device *hidpp,
2316 struct hidpp_touchpad_raw_xy *raw)
2320 for (i = 0; i < 2; i++)
2321 wtp_touch_event(hidpp, &(raw->fingers[i]));
2323 if (raw->end_of_frame &&
2324 !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS))
2325 input_event(hidpp->input, EV_KEY, BTN_LEFT, raw->button);
2327 if (raw->end_of_frame || raw->finger_count <= 2) {
2328 input_mt_sync_frame(hidpp->input);
2329 input_sync(hidpp->input);
2333 static int wtp_mouse_raw_xy_event(struct hidpp_device *hidpp, u8 *data)
2335 struct wtp_data *wd = hidpp->private_data;
2336 u8 c1_area = ((data[7] & 0xf) * (data[7] & 0xf) +
2337 (data[7] >> 4) * (data[7] >> 4)) / 2;
2338 u8 c2_area = ((data[13] & 0xf) * (data[13] & 0xf) +
2339 (data[13] >> 4) * (data[13] >> 4)) / 2;
2340 struct hidpp_touchpad_raw_xy raw = {
2341 .timestamp = data[1],
2345 .contact_status = !!data[7],
2346 .x = get_unaligned_le16(&data[3]),
2347 .y = get_unaligned_le16(&data[5]),
2350 .finger_id = data[2],
2353 .contact_status = !!data[13],
2354 .x = get_unaligned_le16(&data[9]),
2355 .y = get_unaligned_le16(&data[11]),
2358 .finger_id = data[8],
2361 .finger_count = wd->maxcontacts,
2363 .end_of_frame = (data[0] >> 7) == 0,
2364 .button = data[0] & 0x01,
2367 wtp_send_raw_xy_event(hidpp, &raw);
2372 static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size)
2374 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2375 struct wtp_data *wd = hidpp->private_data;
2376 struct hidpp_report *report = (struct hidpp_report *)data;
2377 struct hidpp_touchpad_raw_xy raw;
2379 if (!wd || !hidpp->input)
2385 hid_err(hdev, "Received HID report of bad size (%d)",
2389 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) {
2390 input_event(hidpp->input, EV_KEY, BTN_LEFT,
2391 !!(data[1] & 0x01));
2392 input_event(hidpp->input, EV_KEY, BTN_RIGHT,
2393 !!(data[1] & 0x02));
2394 input_sync(hidpp->input);
2399 return wtp_mouse_raw_xy_event(hidpp, &data[7]);
2401 case REPORT_ID_HIDPP_LONG:
2402 /* size is already checked in hidpp_raw_event. */
2403 if ((report->fap.feature_index != wd->mt_feature_index) ||
2404 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY))
2406 hidpp_touchpad_raw_xy_event(hidpp, data + 4, &raw);
2408 wtp_send_raw_xy_event(hidpp, &raw);
2415 static int wtp_get_config(struct hidpp_device *hidpp)
2417 struct wtp_data *wd = hidpp->private_data;
2418 struct hidpp_touchpad_raw_info raw_info = {0};
2422 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_TOUCHPAD_RAW_XY,
2423 &wd->mt_feature_index, &feature_type);
2425 /* means that the device is not powered up */
2428 ret = hidpp_touchpad_get_raw_info(hidpp, wd->mt_feature_index,
2433 wd->x_size = raw_info.x_size;
2434 wd->y_size = raw_info.y_size;
2435 wd->maxcontacts = raw_info.maxcontacts;
2436 wd->flip_y = raw_info.origin == TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT;
2437 wd->resolution = raw_info.res;
2438 if (!wd->resolution)
2439 wd->resolution = WTP_MANUAL_RESOLUTION;
2444 static int wtp_allocate(struct hid_device *hdev, const struct hid_device_id *id)
2446 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2447 struct wtp_data *wd;
2449 wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data),
2454 hidpp->private_data = wd;
2459 static int wtp_connect(struct hid_device *hdev, bool connected)
2461 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2462 struct wtp_data *wd = hidpp->private_data;
2466 ret = wtp_get_config(hidpp);
2468 hid_err(hdev, "Can not get wtp config: %d\n", ret);
2473 return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index,
2477 /* ------------------------------------------------------------------------- */
2478 /* Logitech M560 devices */
2479 /* ------------------------------------------------------------------------- */
2482 * Logitech M560 protocol overview
2484 * The Logitech M560 mouse, is designed for windows 8. When the middle and/or
2485 * the sides buttons are pressed, it sends some keyboard keys events
2486 * instead of buttons ones.
2487 * To complicate things further, the middle button keys sequence
2488 * is different from the odd press and the even press.
2490 * forward button -> Super_R
2491 * backward button -> Super_L+'d' (press only)
2492 * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
2493 * 2nd time: left-click (press only)
2494 * NB: press-only means that when the button is pressed, the
2495 * KeyPress/ButtonPress and KeyRelease/ButtonRelease events are generated
2496 * together sequentially; instead when the button is released, no event is
2500 * 10<xx>0a 3500af03 (where <xx> is the mouse id),
2501 * the mouse reacts differently:
2502 * - it never sends a keyboard key event
2503 * - for the three mouse button it sends:
2504 * middle button press 11<xx>0a 3500af00...
2505 * side 1 button (forward) press 11<xx>0a 3500b000...
2506 * side 2 button (backward) press 11<xx>0a 3500ae00...
2507 * middle/side1/side2 button release 11<xx>0a 35000000...
2510 static const u8 m560_config_parameter[] = {0x00, 0xaf, 0x03};
2512 /* how buttons are mapped in the report */
2513 #define M560_MOUSE_BTN_LEFT 0x01
2514 #define M560_MOUSE_BTN_RIGHT 0x02
2515 #define M560_MOUSE_BTN_WHEEL_LEFT 0x08
2516 #define M560_MOUSE_BTN_WHEEL_RIGHT 0x10
2518 #define M560_SUB_ID 0x0a
2519 #define M560_BUTTON_MODE_REGISTER 0x35
2521 static int m560_send_config_command(struct hid_device *hdev, bool connected)
2523 struct hidpp_report response;
2524 struct hidpp_device *hidpp_dev;
2526 hidpp_dev = hid_get_drvdata(hdev);
2528 return hidpp_send_rap_command_sync(
2530 REPORT_ID_HIDPP_SHORT,
2532 M560_BUTTON_MODE_REGISTER,
2533 (u8 *)m560_config_parameter,
2534 sizeof(m560_config_parameter),
2539 static int m560_raw_event(struct hid_device *hdev, u8 *data, int size)
2541 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2544 if (!hidpp->input) {
2545 hid_err(hdev, "error in parameter\n");
2550 hid_err(hdev, "error in report\n");
2554 if (data[0] == REPORT_ID_HIDPP_LONG &&
2555 data[2] == M560_SUB_ID && data[6] == 0x00) {
2557 * m560 mouse report for middle, forward and backward button
2560 * data[1] = device-id
2562 * data[5] = 0xaf -> middle
2565 * 0x00 -> release all
2571 input_report_key(hidpp->input, BTN_MIDDLE, 1);
2574 input_report_key(hidpp->input, BTN_FORWARD, 1);
2577 input_report_key(hidpp->input, BTN_BACK, 1);
2580 input_report_key(hidpp->input, BTN_BACK, 0);
2581 input_report_key(hidpp->input, BTN_FORWARD, 0);
2582 input_report_key(hidpp->input, BTN_MIDDLE, 0);
2585 hid_err(hdev, "error in report\n");
2588 input_sync(hidpp->input);
2590 } else if (data[0] == 0x02) {
2592 * Logitech M560 mouse report
2594 * data[0] = type (0x02)
2595 * data[1..2] = buttons
2602 input_report_key(hidpp->input, BTN_LEFT,
2603 !!(data[1] & M560_MOUSE_BTN_LEFT));
2604 input_report_key(hidpp->input, BTN_RIGHT,
2605 !!(data[1] & M560_MOUSE_BTN_RIGHT));
2607 if (data[1] & M560_MOUSE_BTN_WHEEL_LEFT) {
2608 input_report_rel(hidpp->input, REL_HWHEEL, -1);
2609 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES,
2611 } else if (data[1] & M560_MOUSE_BTN_WHEEL_RIGHT) {
2612 input_report_rel(hidpp->input, REL_HWHEEL, 1);
2613 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES,
2617 v = hid_snto32(hid_field_extract(hdev, data+3, 0, 12), 12);
2618 input_report_rel(hidpp->input, REL_X, v);
2620 v = hid_snto32(hid_field_extract(hdev, data+3, 12, 12), 12);
2621 input_report_rel(hidpp->input, REL_Y, v);
2623 v = hid_snto32(data[6], 8);
2625 hidpp_scroll_counter_handle_scroll(hidpp->input,
2626 &hidpp->vertical_wheel_counter, v);
2628 input_sync(hidpp->input);
2634 static void m560_populate_input(struct hidpp_device *hidpp,
2635 struct input_dev *input_dev)
2637 __set_bit(EV_KEY, input_dev->evbit);
2638 __set_bit(BTN_MIDDLE, input_dev->keybit);
2639 __set_bit(BTN_RIGHT, input_dev->keybit);
2640 __set_bit(BTN_LEFT, input_dev->keybit);
2641 __set_bit(BTN_BACK, input_dev->keybit);
2642 __set_bit(BTN_FORWARD, input_dev->keybit);
2644 __set_bit(EV_REL, input_dev->evbit);
2645 __set_bit(REL_X, input_dev->relbit);
2646 __set_bit(REL_Y, input_dev->relbit);
2647 __set_bit(REL_WHEEL, input_dev->relbit);
2648 __set_bit(REL_HWHEEL, input_dev->relbit);
2649 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit);
2650 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit);
2653 static int m560_input_mapping(struct hid_device *hdev, struct hid_input *hi,
2654 struct hid_field *field, struct hid_usage *usage,
2655 unsigned long **bit, int *max)
2660 /* ------------------------------------------------------------------------- */
2661 /* Logitech K400 devices */
2662 /* ------------------------------------------------------------------------- */
2665 * The Logitech K400 keyboard has an embedded touchpad which is seen
2666 * as a mouse from the OS point of view. There is a hardware shortcut to disable
2667 * tap-to-click but the setting is not remembered accross reset, annoying some
2670 * We can toggle this feature from the host by using the feature 0x6010:
2674 struct k400_private_data {
2678 static int k400_disable_tap_to_click(struct hidpp_device *hidpp)
2680 struct k400_private_data *k400 = hidpp->private_data;
2681 struct hidpp_touchpad_fw_items items = {};
2685 if (!k400->feature_index) {
2686 ret = hidpp_root_get_feature(hidpp,
2687 HIDPP_PAGE_TOUCHPAD_FW_ITEMS,
2688 &k400->feature_index, &feature_type);
2690 /* means that the device is not powered up */
2694 ret = hidpp_touchpad_fw_items_set(hidpp, k400->feature_index, &items);
2701 static int k400_allocate(struct hid_device *hdev)
2703 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2704 struct k400_private_data *k400;
2706 k400 = devm_kzalloc(&hdev->dev, sizeof(struct k400_private_data),
2711 hidpp->private_data = k400;
2716 static int k400_connect(struct hid_device *hdev, bool connected)
2718 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2720 if (!disable_tap_to_click)
2723 return k400_disable_tap_to_click(hidpp);
2726 /* ------------------------------------------------------------------------- */
2727 /* Logitech G920 Driving Force Racing Wheel for Xbox One */
2728 /* ------------------------------------------------------------------------- */
2730 #define HIDPP_PAGE_G920_FORCE_FEEDBACK 0x8123
2732 static int g920_get_config(struct hidpp_device *hidpp)
2738 /* Find feature and store for later use */
2739 ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_G920_FORCE_FEEDBACK,
2740 &feature_index, &feature_type);
2744 ret = hidpp_ff_init(hidpp, feature_index);
2746 hid_warn(hidpp->hid_dev, "Unable to initialize force feedback support, errno %d\n",
2752 /* -------------------------------------------------------------------------- */
2753 /* HID++1.0 devices which use HID++ reports for their wheels */
2754 /* -------------------------------------------------------------------------- */
2755 static int hidpp10_wheel_connect(struct hidpp_device *hidpp)
2757 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
2758 HIDPP_ENABLE_WHEEL_REPORT | HIDPP_ENABLE_HWHEEL_REPORT,
2759 HIDPP_ENABLE_WHEEL_REPORT | HIDPP_ENABLE_HWHEEL_REPORT);
2762 static int hidpp10_wheel_raw_event(struct hidpp_device *hidpp,
2773 if (data[0] != REPORT_ID_HIDPP_SHORT || data[2] != HIDPP_SUB_ID_ROLLER)
2779 input_report_rel(hidpp->input, REL_WHEEL, value);
2780 input_report_rel(hidpp->input, REL_WHEEL_HI_RES, value * 120);
2781 input_report_rel(hidpp->input, REL_HWHEEL, hvalue);
2782 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, hvalue * 120);
2783 input_sync(hidpp->input);
2788 static void hidpp10_wheel_populate_input(struct hidpp_device *hidpp,
2789 struct input_dev *input_dev)
2791 __set_bit(EV_REL, input_dev->evbit);
2792 __set_bit(REL_WHEEL, input_dev->relbit);
2793 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit);
2794 __set_bit(REL_HWHEEL, input_dev->relbit);
2795 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit);
2798 /* -------------------------------------------------------------------------- */
2799 /* HID++1.0 mice which use HID++ reports for extra mouse buttons */
2800 /* -------------------------------------------------------------------------- */
2801 static int hidpp10_extra_mouse_buttons_connect(struct hidpp_device *hidpp)
2803 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
2804 HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT,
2805 HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT);
2808 static int hidpp10_extra_mouse_buttons_raw_event(struct hidpp_device *hidpp,
2819 if (data[0] != REPORT_ID_HIDPP_SHORT ||
2820 data[2] != HIDPP_SUB_ID_MOUSE_EXTRA_BTNS)
2824 * Buttons are either delivered through the regular mouse report *or*
2825 * through the extra buttons report. At least for button 6 how it is
2826 * delivered differs per receiver firmware version. Even receivers with
2827 * the same usb-id show different behavior, so we handle both cases.
2829 for (i = 0; i < 8; i++)
2830 input_report_key(hidpp->input, BTN_MOUSE + i,
2831 (data[3] & (1 << i)));
2833 /* Some mice report events on button 9+, use BTN_MISC */
2834 for (i = 0; i < 8; i++)
2835 input_report_key(hidpp->input, BTN_MISC + i,
2836 (data[4] & (1 << i)));
2838 input_sync(hidpp->input);
2842 static void hidpp10_extra_mouse_buttons_populate_input(
2843 struct hidpp_device *hidpp, struct input_dev *input_dev)
2845 /* BTN_MOUSE - BTN_MOUSE+7 are set already by the descriptor */
2846 __set_bit(BTN_0, input_dev->keybit);
2847 __set_bit(BTN_1, input_dev->keybit);
2848 __set_bit(BTN_2, input_dev->keybit);
2849 __set_bit(BTN_3, input_dev->keybit);
2850 __set_bit(BTN_4, input_dev->keybit);
2851 __set_bit(BTN_5, input_dev->keybit);
2852 __set_bit(BTN_6, input_dev->keybit);
2853 __set_bit(BTN_7, input_dev->keybit);
2856 /* -------------------------------------------------------------------------- */
2857 /* HID++1.0 kbds which only report 0x10xx consumer usages through sub-id 0x03 */
2858 /* -------------------------------------------------------------------------- */
2860 /* Find the consumer-page input report desc and change Maximums to 0x107f */
2861 static u8 *hidpp10_consumer_keys_report_fixup(struct hidpp_device *hidpp,
2862 u8 *_rdesc, unsigned int *rsize)
2864 /* Note 0 terminated so we can use strnstr to search for this. */
2865 const char consumer_rdesc_start[] = {
2866 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */
2867 0x09, 0x01, /* USAGE (Consumer Control) */
2868 0xA1, 0x01, /* COLLECTION (Application) */
2869 0x85, 0x03, /* REPORT_ID = 3 */
2870 0x75, 0x10, /* REPORT_SIZE (16) */
2871 0x95, 0x02, /* REPORT_COUNT (2) */
2872 0x15, 0x01, /* LOGICAL_MIN (1) */
2873 0x26, 0x00 /* LOGICAL_MAX (... */
2875 char *consumer_rdesc, *rdesc = (char *)_rdesc;
2878 consumer_rdesc = strnstr(rdesc, consumer_rdesc_start, *rsize);
2879 size = *rsize - (consumer_rdesc - rdesc);
2880 if (consumer_rdesc && size >= 25) {
2881 consumer_rdesc[15] = 0x7f;
2882 consumer_rdesc[16] = 0x10;
2883 consumer_rdesc[20] = 0x7f;
2884 consumer_rdesc[21] = 0x10;
2889 static int hidpp10_consumer_keys_connect(struct hidpp_device *hidpp)
2891 return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
2892 HIDPP_ENABLE_CONSUMER_REPORT,
2893 HIDPP_ENABLE_CONSUMER_REPORT);
2896 static int hidpp10_consumer_keys_raw_event(struct hidpp_device *hidpp,
2899 u8 consumer_report[5];
2904 if (data[0] != REPORT_ID_HIDPP_SHORT ||
2905 data[2] != HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS)
2909 * Build a normal consumer report (3) out of the data, this detour
2910 * is necessary to get some keyboards to report their 0x10xx usages.
2912 consumer_report[0] = 0x03;
2913 memcpy(&consumer_report[1], &data[3], 4);
2914 /* We are called from atomic context */
2915 hid_report_raw_event(hidpp->hid_dev, HID_INPUT_REPORT,
2916 consumer_report, 5, 1);
2921 /* -------------------------------------------------------------------------- */
2922 /* High-resolution scroll wheels */
2923 /* -------------------------------------------------------------------------- */
2925 static int hi_res_scroll_enable(struct hidpp_device *hidpp)
2930 if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2121) {
2931 ret = hidpp_hrw_set_wheel_mode(hidpp, false, true, false);
2933 ret = hidpp_hrw_get_wheel_capability(hidpp, &multiplier);
2934 } else if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2120) {
2935 ret = hidpp_hrs_set_highres_scrolling_mode(hidpp, true,
2937 } else /* if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_1P0) */ {
2938 ret = hidpp10_enable_scrolling_acceleration(hidpp);
2944 if (multiplier == 0)
2947 hidpp->vertical_wheel_counter.wheel_multiplier = multiplier;
2948 hid_info(hidpp->hid_dev, "multiplier = %d\n", multiplier);
2952 /* -------------------------------------------------------------------------- */
2953 /* Generic HID++ devices */
2954 /* -------------------------------------------------------------------------- */
2956 static u8 *hidpp_report_fixup(struct hid_device *hdev, u8 *rdesc,
2957 unsigned int *rsize)
2959 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2964 /* For 27 MHz keyboards the quirk gets set after hid_parse. */
2965 if (hdev->group == HID_GROUP_LOGITECH_27MHZ_DEVICE ||
2966 (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS))
2967 rdesc = hidpp10_consumer_keys_report_fixup(hidpp, rdesc, rsize);
2972 static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
2973 struct hid_field *field, struct hid_usage *usage,
2974 unsigned long **bit, int *max)
2976 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2981 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
2982 return wtp_input_mapping(hdev, hi, field, usage, bit, max);
2983 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 &&
2984 field->application != HID_GD_MOUSE)
2985 return m560_input_mapping(hdev, hi, field, usage, bit, max);
2990 static int hidpp_input_mapped(struct hid_device *hdev, struct hid_input *hi,
2991 struct hid_field *field, struct hid_usage *usage,
2992 unsigned long **bit, int *max)
2994 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
2999 /* Ensure that Logitech G920 is not given a default fuzz/flat value */
3000 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
3001 if (usage->type == EV_ABS && (usage->code == ABS_X ||
3002 usage->code == ABS_Y || usage->code == ABS_Z ||
3003 usage->code == ABS_RZ)) {
3004 field->application = HID_GD_MULTIAXIS;
3012 static void hidpp_populate_input(struct hidpp_device *hidpp,
3013 struct input_dev *input)
3015 hidpp->input = input;
3017 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
3018 wtp_populate_input(hidpp, input);
3019 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
3020 m560_populate_input(hidpp, input);
3022 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS)
3023 hidpp10_wheel_populate_input(hidpp, input);
3025 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS)
3026 hidpp10_extra_mouse_buttons_populate_input(hidpp, input);
3029 static int hidpp_input_configured(struct hid_device *hdev,
3030 struct hid_input *hidinput)
3032 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3033 struct input_dev *input = hidinput->input;
3038 hidpp_populate_input(hidpp, input);
3043 static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,
3046 struct hidpp_report *question = hidpp->send_receive_buf;
3047 struct hidpp_report *answer = hidpp->send_receive_buf;
3048 struct hidpp_report *report = (struct hidpp_report *)data;
3052 * If the mutex is locked then we have a pending answer from a
3053 * previously sent command.
3055 if (unlikely(mutex_is_locked(&hidpp->send_mutex))) {
3057 * Check for a correct hidpp20 answer or the corresponding
3060 if (hidpp_match_answer(question, report) ||
3061 hidpp_match_error(question, report)) {
3063 hidpp->answer_available = true;
3064 wake_up(&hidpp->wait);
3066 * This was an answer to a command that this driver sent
3067 * We return 1 to hid-core to avoid forwarding the
3068 * command upstream as it has been treated by the driver
3075 if (unlikely(hidpp_report_is_connect_event(report))) {
3076 atomic_set(&hidpp->connected,
3077 !(report->rap.params[0] & (1 << 6)));
3078 if (schedule_work(&hidpp->work) == 0)
3079 dbg_hid("%s: connect event already queued\n", __func__);
3083 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) {
3084 ret = hidpp20_battery_event(hidpp, data, size);
3087 ret = hidpp_solar_battery_event(hidpp, data, size);
3092 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) {
3093 ret = hidpp10_battery_event(hidpp, data, size);
3098 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
3099 ret = hidpp10_wheel_raw_event(hidpp, data, size);
3104 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) {
3105 ret = hidpp10_extra_mouse_buttons_raw_event(hidpp, data, size);
3110 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) {
3111 ret = hidpp10_consumer_keys_raw_event(hidpp, data, size);
3119 static int hidpp_raw_event(struct hid_device *hdev, struct hid_report *report,
3122 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3128 /* Generic HID++ processing. */
3130 case REPORT_ID_HIDPP_VERY_LONG:
3131 if (size != hidpp->very_long_report_length) {
3132 hid_err(hdev, "received hid++ report of bad size (%d)",
3136 ret = hidpp_raw_hidpp_event(hidpp, data, size);
3138 case REPORT_ID_HIDPP_LONG:
3139 if (size != HIDPP_REPORT_LONG_LENGTH) {
3140 hid_err(hdev, "received hid++ report of bad size (%d)",
3144 ret = hidpp_raw_hidpp_event(hidpp, data, size);
3146 case REPORT_ID_HIDPP_SHORT:
3147 if (size != HIDPP_REPORT_SHORT_LENGTH) {
3148 hid_err(hdev, "received hid++ report of bad size (%d)",
3152 ret = hidpp_raw_hidpp_event(hidpp, data, size);
3156 /* If no report is available for further processing, skip calling
3157 * raw_event of subclasses. */
3161 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
3162 return wtp_raw_event(hdev, data, size);
3163 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
3164 return m560_raw_event(hdev, data, size);
3169 static int hidpp_event(struct hid_device *hdev, struct hid_field *field,
3170 struct hid_usage *usage, __s32 value)
3172 /* This function will only be called for scroll events, due to the
3173 * restriction imposed in hidpp_usages.
3175 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3176 struct hidpp_scroll_counter *counter;
3181 counter = &hidpp->vertical_wheel_counter;
3182 /* A scroll event may occur before the multiplier has been retrieved or
3183 * the input device set, or high-res scroll enabling may fail. In such
3184 * cases we must return early (falling back to default behaviour) to
3185 * avoid a crash in hidpp_scroll_counter_handle_scroll.
3187 if (!(hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL) || value == 0
3188 || hidpp->input == NULL || counter->wheel_multiplier == 0)
3191 hidpp_scroll_counter_handle_scroll(hidpp->input, counter, value);
3195 static int hidpp_initialize_battery(struct hidpp_device *hidpp)
3197 static atomic_t battery_no = ATOMIC_INIT(0);
3198 struct power_supply_config cfg = { .drv_data = hidpp };
3199 struct power_supply_desc *desc = &hidpp->battery.desc;
3200 enum power_supply_property *battery_props;
3201 struct hidpp_battery *battery;
3202 unsigned int num_battery_props;
3206 if (hidpp->battery.ps)
3209 hidpp->battery.feature_index = 0xff;
3210 hidpp->battery.solar_feature_index = 0xff;
3212 if (hidpp->protocol_major >= 2) {
3213 if (hidpp->quirks & HIDPP_QUIRK_CLASS_K750)
3214 ret = hidpp_solar_request_battery_event(hidpp);
3216 ret = hidpp20_query_battery_info(hidpp);
3220 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_BATTERY;
3222 ret = hidpp10_query_battery_status(hidpp);
3224 ret = hidpp10_query_battery_mileage(hidpp);
3227 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
3229 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS;
3231 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP10_BATTERY;
3234 battery_props = devm_kmemdup(&hidpp->hid_dev->dev,
3235 hidpp_battery_props,
3236 sizeof(hidpp_battery_props),
3241 num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 2;
3243 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)
3244 battery_props[num_battery_props++] =
3245 POWER_SUPPLY_PROP_CAPACITY;
3247 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS)
3248 battery_props[num_battery_props++] =
3249 POWER_SUPPLY_PROP_CAPACITY_LEVEL;
3251 battery = &hidpp->battery;
3253 n = atomic_inc_return(&battery_no) - 1;
3254 desc->properties = battery_props;
3255 desc->num_properties = num_battery_props;
3256 desc->get_property = hidpp_battery_get_property;
3257 sprintf(battery->name, "hidpp_battery_%ld", n);
3258 desc->name = battery->name;
3259 desc->type = POWER_SUPPLY_TYPE_BATTERY;
3260 desc->use_for_apm = 0;
3262 battery->ps = devm_power_supply_register(&hidpp->hid_dev->dev,
3265 if (IS_ERR(battery->ps))
3266 return PTR_ERR(battery->ps);
3268 power_supply_powers(battery->ps, &hidpp->hid_dev->dev);
3273 static void hidpp_overwrite_name(struct hid_device *hdev)
3275 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3278 if (hidpp->protocol_major < 2)
3281 name = hidpp_get_device_name(hidpp);
3284 hid_err(hdev, "unable to retrieve the name of the device");
3286 dbg_hid("HID++: Got name: %s\n", name);
3287 snprintf(hdev->name, sizeof(hdev->name), "%s", name);
3293 static int hidpp_input_open(struct input_dev *dev)
3295 struct hid_device *hid = input_get_drvdata(dev);
3297 return hid_hw_open(hid);
3300 static void hidpp_input_close(struct input_dev *dev)
3302 struct hid_device *hid = input_get_drvdata(dev);
3307 static struct input_dev *hidpp_allocate_input(struct hid_device *hdev)
3309 struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev);
3310 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3315 input_set_drvdata(input_dev, hdev);
3316 input_dev->open = hidpp_input_open;
3317 input_dev->close = hidpp_input_close;
3319 input_dev->name = hidpp->name;
3320 input_dev->phys = hdev->phys;
3321 input_dev->uniq = hdev->uniq;
3322 input_dev->id.bustype = hdev->bus;
3323 input_dev->id.vendor = hdev->vendor;
3324 input_dev->id.product = hdev->product;
3325 input_dev->id.version = hdev->version;
3326 input_dev->dev.parent = &hdev->dev;
3331 static void hidpp_connect_event(struct hidpp_device *hidpp)
3333 struct hid_device *hdev = hidpp->hid_dev;
3335 bool connected = atomic_read(&hidpp->connected);
3336 struct input_dev *input;
3337 char *name, *devm_name;
3340 if (hidpp->battery.ps) {
3341 hidpp->battery.online = false;
3342 hidpp->battery.status = POWER_SUPPLY_STATUS_UNKNOWN;
3343 hidpp->battery.level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
3344 power_supply_changed(hidpp->battery.ps);
3349 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
3350 ret = wtp_connect(hdev, connected);
3353 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) {
3354 ret = m560_send_config_command(hdev, connected);
3357 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
3358 ret = k400_connect(hdev, connected);
3363 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
3364 ret = hidpp10_wheel_connect(hidpp);
3369 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) {
3370 ret = hidpp10_extra_mouse_buttons_connect(hidpp);
3375 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) {
3376 ret = hidpp10_consumer_keys_connect(hidpp);
3381 /* the device is already connected, we can ask for its name and
3383 if (!hidpp->protocol_major) {
3384 ret = hidpp_root_get_protocol_version(hidpp);
3386 hid_err(hdev, "Can not get the protocol version.\n");
3391 if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) {
3392 name = hidpp_get_device_name(hidpp);
3394 devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
3400 hidpp->name = devm_name;
3404 hidpp_initialize_battery(hidpp);
3406 /* forward current battery state */
3407 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) {
3408 hidpp10_enable_battery_reporting(hidpp);
3409 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)
3410 hidpp10_query_battery_mileage(hidpp);
3412 hidpp10_query_battery_status(hidpp);
3413 } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) {
3414 hidpp20_query_battery_info(hidpp);
3416 if (hidpp->battery.ps)
3417 power_supply_changed(hidpp->battery.ps);
3419 if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL)
3420 hi_res_scroll_enable(hidpp);
3422 if (!(hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) || hidpp->delayed_input)
3423 /* if the input nodes are already created, we can stop now */
3426 input = hidpp_allocate_input(hdev);
3428 hid_err(hdev, "cannot allocate new input device: %d\n", ret);
3432 hidpp_populate_input(hidpp, input);
3434 ret = input_register_device(input);
3436 input_free_device(input);
3438 hidpp->delayed_input = input;
3441 static DEVICE_ATTR(builtin_power_supply, 0000, NULL, NULL);
3443 static struct attribute *sysfs_attrs[] = {
3444 &dev_attr_builtin_power_supply.attr,
3448 static const struct attribute_group ps_attribute_group = {
3449 .attrs = sysfs_attrs
3452 static int hidpp_get_report_length(struct hid_device *hdev, int id)
3454 struct hid_report_enum *re;
3455 struct hid_report *report;
3457 re = &(hdev->report_enum[HID_OUTPUT_REPORT]);
3458 report = re->report_id_hash[id];
3462 return report->field[0]->report_count + 1;
3465 static bool hidpp_validate_report(struct hid_device *hdev, int id,
3466 int expected_length, bool optional)
3470 if (id >= HID_MAX_IDS || id < 0) {
3471 hid_err(hdev, "invalid HID report id %u\n", id);
3475 report_length = hidpp_get_report_length(hdev, id);
3479 if (report_length < expected_length) {
3480 hid_warn(hdev, "not enough values in hidpp report %d\n", id);
3487 static bool hidpp_validate_device(struct hid_device *hdev)
3489 return hidpp_validate_report(hdev, REPORT_ID_HIDPP_SHORT,
3490 HIDPP_REPORT_SHORT_LENGTH, false) &&
3491 hidpp_validate_report(hdev, REPORT_ID_HIDPP_LONG,
3492 HIDPP_REPORT_LONG_LENGTH, true);
3495 static bool hidpp_application_equals(struct hid_device *hdev,
3496 unsigned int application)
3498 struct list_head *report_list;
3499 struct hid_report *report;
3501 report_list = &hdev->report_enum[HID_INPUT_REPORT].report_list;
3502 report = list_first_entry_or_null(report_list, struct hid_report, list);
3503 return report && report->application == application;
3506 static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
3508 struct hidpp_device *hidpp;
3511 unsigned int connect_mask = HID_CONNECT_DEFAULT;
3513 /* report_fixup needs drvdata to be set before we call hid_parse */
3514 hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL);
3518 hidpp->hid_dev = hdev;
3519 hidpp->name = hdev->name;
3520 hidpp->quirks = id->driver_data;
3521 hid_set_drvdata(hdev, hidpp);
3523 ret = hid_parse(hdev);
3525 hid_err(hdev, "%s:parse failed\n", __func__);
3530 * Make sure the device is HID++ capable, otherwise treat as generic HID
3532 if (!hidpp_validate_device(hdev)) {
3533 hid_set_drvdata(hdev, NULL);
3534 devm_kfree(&hdev->dev, hidpp);
3535 return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
3538 hidpp->very_long_report_length =
3539 hidpp_get_report_length(hdev, REPORT_ID_HIDPP_VERY_LONG);
3540 if (hidpp->very_long_report_length > HIDPP_REPORT_VERY_LONG_MAX_LENGTH)
3541 hidpp->very_long_report_length = HIDPP_REPORT_VERY_LONG_MAX_LENGTH;
3543 if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE)
3544 hidpp->quirks |= HIDPP_QUIRK_UNIFYING;
3546 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
3547 hidpp_application_equals(hdev, HID_GD_MOUSE))
3548 hidpp->quirks |= HIDPP_QUIRK_HIDPP_WHEELS |
3549 HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS;
3551 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
3552 hidpp_application_equals(hdev, HID_GD_KEYBOARD))
3553 hidpp->quirks |= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS;
3555 if (disable_raw_mode) {
3556 hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP;
3557 hidpp->quirks &= ~HIDPP_QUIRK_NO_HIDINPUT;
3560 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
3561 ret = wtp_allocate(hdev, id);
3564 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
3565 ret = k400_allocate(hdev);
3570 INIT_WORK(&hidpp->work, delayed_work_cb);
3571 mutex_init(&hidpp->send_mutex);
3572 init_waitqueue_head(&hidpp->wait);
3574 /* indicates we are handling the battery properties in the kernel */
3575 ret = sysfs_create_group(&hdev->dev.kobj, &ps_attribute_group);
3577 hid_warn(hdev, "Cannot allocate sysfs group for %s\n",
3581 * Plain USB connections need to actually call start and open
3582 * on the transport driver to allow incoming data.
3584 ret = hid_hw_start(hdev, 0);
3586 hid_err(hdev, "hw start failed\n");
3587 goto hid_hw_start_fail;
3590 ret = hid_hw_open(hdev);
3592 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n",
3595 goto hid_hw_open_fail;
3598 /* Allow incoming packets */
3599 hid_device_io_start(hdev);
3601 if (hidpp->quirks & HIDPP_QUIRK_UNIFYING)
3602 hidpp_unifying_init(hidpp);
3604 connected = hidpp_root_get_protocol_version(hidpp) == 0;
3605 atomic_set(&hidpp->connected, connected);
3606 if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) {
3609 hid_err(hdev, "Device not connected");
3610 goto hid_hw_init_fail;
3613 hidpp_overwrite_name(hdev);
3616 if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) {
3617 ret = wtp_get_config(hidpp);
3619 goto hid_hw_init_fail;
3620 } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) {
3621 ret = g920_get_config(hidpp);
3623 goto hid_hw_init_fail;
3626 hidpp_connect_event(hidpp);
3628 /* Reset the HID node state */
3629 hid_device_io_stop(hdev);
3633 if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT)
3634 connect_mask &= ~HID_CONNECT_HIDINPUT;
3636 /* Now export the actual inputs and hidraw nodes to the world */
3637 ret = hid_hw_start(hdev, connect_mask);
3639 hid_err(hdev, "%s:hid_hw_start returned error\n", __func__);
3640 goto hid_hw_start_fail;
3650 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
3651 cancel_work_sync(&hidpp->work);
3652 mutex_destroy(&hidpp->send_mutex);
3656 static void hidpp_remove(struct hid_device *hdev)
3658 struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3661 return hid_hw_stop(hdev);
3663 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
3665 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)
3666 hidpp_ff_deinit(hdev);
3669 cancel_work_sync(&hidpp->work);
3670 mutex_destroy(&hidpp->send_mutex);
3673 #define LDJ_DEVICE(product) \
3674 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE, \
3675 USB_VENDOR_ID_LOGITECH, (product))
3677 #define L27MHZ_DEVICE(product) \
3678 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_27MHZ_DEVICE, \
3679 USB_VENDOR_ID_LOGITECH, (product))
3681 static const struct hid_device_id hidpp_devices[] = {
3682 { /* wireless touchpad */
3684 .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT |
3685 HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS },
3686 { /* wireless touchpad T650 */
3688 .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT },
3689 { /* wireless touchpad T651 */
3690 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH,
3691 USB_DEVICE_ID_LOGITECH_T651),
3692 .driver_data = HIDPP_QUIRK_CLASS_WTP },
3693 { /* Mouse Logitech Anywhere MX */
3694 LDJ_DEVICE(0x1017), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_1P0 },
3695 { /* Mouse Logitech Cube */
3696 LDJ_DEVICE(0x4010), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2120 },
3697 { /* Mouse Logitech M335 */
3698 LDJ_DEVICE(0x4050), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3699 { /* Mouse Logitech M515 */
3700 LDJ_DEVICE(0x4007), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2120 },
3701 { /* Mouse logitech M560 */
3703 .driver_data = HIDPP_QUIRK_DELAYED_INIT | HIDPP_QUIRK_CLASS_M560
3704 | HIDPP_QUIRK_HI_RES_SCROLL_X2120 },
3705 { /* Mouse Logitech M705 (firmware RQM17) */
3706 LDJ_DEVICE(0x101b), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_1P0 },
3707 { /* Mouse Logitech M705 (firmware RQM67) */
3708 LDJ_DEVICE(0x406d), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3709 { /* Mouse Logitech M720 */
3710 LDJ_DEVICE(0x405e), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3711 { /* Mouse Logitech MX Anywhere 2 */
3712 LDJ_DEVICE(0x404a), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3713 { LDJ_DEVICE(0xb013), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3714 { LDJ_DEVICE(0xb018), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3715 { LDJ_DEVICE(0xb01f), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3716 { /* Mouse Logitech MX Anywhere 2S */
3717 LDJ_DEVICE(0x406a), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3718 { /* Mouse Logitech MX Master */
3719 LDJ_DEVICE(0x4041), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3720 { LDJ_DEVICE(0x4060), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3721 { LDJ_DEVICE(0x4071), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3722 { /* Mouse Logitech MX Master 2S */
3723 LDJ_DEVICE(0x4069), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3724 { /* Mouse Logitech Performance MX */
3725 LDJ_DEVICE(0x101a), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_1P0 },
3726 { /* Keyboard logitech K400 */
3728 .driver_data = HIDPP_QUIRK_CLASS_K400 },
3729 { /* Solar Keyboard Logitech K750 */
3731 .driver_data = HIDPP_QUIRK_CLASS_K750 },
3732 { /* Keyboard MX5000 (Bluetooth-receiver in HID proxy mode) */
3734 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
3736 { LDJ_DEVICE(HID_ANY_ID) },
3738 { /* Keyboard LX501 (Y-RR53) */
3739 L27MHZ_DEVICE(0x0049),
3740 .driver_data = HIDPP_QUIRK_KBD_ZOOM_WHEEL },
3741 { /* Keyboard MX3000 (Y-RAM74) */
3742 L27MHZ_DEVICE(0x0057),
3743 .driver_data = HIDPP_QUIRK_KBD_SCROLL_WHEEL },
3744 { /* Keyboard MX3200 (Y-RAV80) */
3745 L27MHZ_DEVICE(0x005c),
3746 .driver_data = HIDPP_QUIRK_KBD_ZOOM_WHEEL },
3748 { L27MHZ_DEVICE(HID_ANY_ID) },
3750 { /* Logitech G403 Gaming Mouse over USB */
3751 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC082) },
3752 { /* Logitech G700 Gaming Mouse over USB */
3753 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC06B) },
3754 { /* Logitech G900 Gaming Mouse over USB */
3755 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC081) },
3756 { /* Logitech G920 Wheel over USB */
3757 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL),
3758 .driver_data = HIDPP_QUIRK_CLASS_G920 | HIDPP_QUIRK_FORCE_OUTPUT_REPORTS},
3760 { /* MX5000 keyboard over Bluetooth */
3761 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb305),
3762 .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
3766 MODULE_DEVICE_TABLE(hid, hidpp_devices);
3768 static const struct hid_usage_id hidpp_usages[] = {
3769 { HID_GD_WHEEL, EV_REL, REL_WHEEL_HI_RES },
3770 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
3773 static struct hid_driver hidpp_driver = {
3774 .name = "logitech-hidpp-device",
3775 .id_table = hidpp_devices,
3776 .report_fixup = hidpp_report_fixup,
3777 .probe = hidpp_probe,
3778 .remove = hidpp_remove,
3779 .raw_event = hidpp_raw_event,
3780 .usage_table = hidpp_usages,
3781 .event = hidpp_event,
3782 .input_configured = hidpp_input_configured,
3783 .input_mapping = hidpp_input_mapping,
3784 .input_mapped = hidpp_input_mapped,
3787 module_hid_driver(hidpp_driver);