1 // SPDX-License-Identifier: GPL-2.0-only
3 * HIDPP protocol for Logitech receivers
5 * Copyright (c) 2011 Logitech (c)
6 * Copyright (c) 2012-2013 Google (c)
7 * Copyright (c) 2013-2014 Red Hat Inc.
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/device.h>
14 #include <linux/input.h>
15 #include <linux/usb.h>
16 #include <linux/hid.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/sched.h>
20 #include <linux/sched/clock.h>
21 #include <linux/kfifo.h>
22 #include <linux/input/mt.h>
23 #include <linux/workqueue.h>
24 #include <linux/atomic.h>
25 #include <linux/fixp-arith.h>
26 #include <linux/unaligned.h>
27 #include "usbhid/usbhid.h"
30 MODULE_DESCRIPTION("Support for Logitech devices relying on the HID++ specification");
31 MODULE_LICENSE("GPL");
32 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
33 MODULE_AUTHOR("Nestor Lopez Casado <nlopezcasad@logitech.com>");
34 MODULE_AUTHOR("Bastien Nocera <hadess@hadess.net>");
36 static bool disable_tap_to_click
;
37 module_param(disable_tap_to_click
, bool, 0644);
38 MODULE_PARM_DESC(disable_tap_to_click
,
39 "Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
41 /* Define a non-zero software ID to identify our own requests */
42 #define LINUX_KERNEL_SW_ID 0x01
44 #define REPORT_ID_HIDPP_SHORT 0x10
45 #define REPORT_ID_HIDPP_LONG 0x11
46 #define REPORT_ID_HIDPP_VERY_LONG 0x12
48 #define HIDPP_REPORT_SHORT_LENGTH 7
49 #define HIDPP_REPORT_LONG_LENGTH 20
50 #define HIDPP_REPORT_VERY_LONG_MAX_LENGTH 64
52 #define HIDPP_REPORT_SHORT_SUPPORTED BIT(0)
53 #define HIDPP_REPORT_LONG_SUPPORTED BIT(1)
54 #define HIDPP_REPORT_VERY_LONG_SUPPORTED BIT(2)
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
59 #define HIDPP_SUB_ID_USER_IFACE_EVENT 0x08
60 #define HIDPP_USER_IFACE_EVENT_ENCRYPTION_KEY_LOST BIT(5)
62 #define HIDPP_QUIRK_CLASS_WTP BIT(0)
63 #define HIDPP_QUIRK_CLASS_M560 BIT(1)
64 #define HIDPP_QUIRK_CLASS_K400 BIT(2)
65 #define HIDPP_QUIRK_CLASS_G920 BIT(3)
66 #define HIDPP_QUIRK_CLASS_K750 BIT(4)
68 /* bits 2..20 are reserved for classes */
69 /* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */
70 #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22)
71 #define HIDPP_QUIRK_DELAYED_INIT BIT(23)
72 #define HIDPP_QUIRK_FORCE_OUTPUT_REPORTS BIT(24)
73 #define HIDPP_QUIRK_HIDPP_WHEELS BIT(25)
74 #define HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS BIT(26)
75 #define HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS BIT(27)
76 #define HIDPP_QUIRK_HI_RES_SCROLL_1P0 BIT(28)
77 #define HIDPP_QUIRK_WIRELESS_STATUS BIT(29)
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_CAPABILITY_HI_RES_SCROLL (HIDPP_CAPABILITY_HIDPP10_FAST_SCROLL | \
85 HIDPP_CAPABILITY_HIDPP20_HI_RES_SCROLL | \
86 HIDPP_CAPABILITY_HIDPP20_HI_RES_WHEEL)
88 #define HIDPP_CAPABILITY_HIDPP10_BATTERY BIT(0)
89 #define HIDPP_CAPABILITY_HIDPP20_BATTERY BIT(1)
90 #define HIDPP_CAPABILITY_BATTERY_MILEAGE BIT(2)
91 #define HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS BIT(3)
92 #define HIDPP_CAPABILITY_BATTERY_VOLTAGE BIT(4)
93 #define HIDPP_CAPABILITY_BATTERY_PERCENTAGE BIT(5)
94 #define HIDPP_CAPABILITY_UNIFIED_BATTERY BIT(6)
95 #define HIDPP_CAPABILITY_HIDPP20_HI_RES_WHEEL BIT(7)
96 #define HIDPP_CAPABILITY_HIDPP20_HI_RES_SCROLL BIT(8)
97 #define HIDPP_CAPABILITY_HIDPP10_FAST_SCROLL BIT(9)
98 #define HIDPP_CAPABILITY_ADC_MEASUREMENT BIT(10)
100 #define lg_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
103 * There are two hidpp protocols in use, the first version hidpp10 is known
104 * as register access protocol or RAP, the second version hidpp20 is known as
105 * feature access protocol or FAP
107 * Most older devices (including the Unifying usb receiver) use the RAP protocol
108 * where as most newer devices use the FAP protocol. Both protocols are
109 * compatible with the underlying transport, which could be usb, Unifiying, or
110 * bluetooth. The message lengths are defined by the hid vendor specific report
111 * descriptor for the HIDPP_SHORT report type (total message lenth 7 bytes) and
112 * the HIDPP_LONG report type (total message length 20 bytes)
114 * The RAP protocol uses both report types, whereas the FAP only uses HIDPP_LONG
115 * messages. The Unifying receiver itself responds to RAP messages (device index
116 * is 0xFF for the receiver), and all messages (short or long) with a device
117 * index between 1 and 6 are passed untouched to the corresponding paired
120 * The paired device can be RAP or FAP, it will receive the message untouched
121 * from the Unifiying receiver.
126 u8 funcindex_clientid
;
127 u8 params
[HIDPP_REPORT_VERY_LONG_MAX_LENGTH
- 4U];
133 u8 params
[HIDPP_REPORT_VERY_LONG_MAX_LENGTH
- 4U];
136 struct hidpp_report
{
142 u8 rawbytes
[sizeof(struct fap
)];
146 struct hidpp_battery
{
148 u8 solar_feature_index
;
149 u8 voltage_feature_index
;
150 u8 adc_measurement_feature_index
;
151 struct power_supply_desc desc
;
152 struct power_supply
*ps
;
160 u8 supported_levels_1004
;
164 * struct hidpp_scroll_counter - Utility class for processing high-resolution
166 * @dev: the input device for which events should be reported.
167 * @wheel_multiplier: the scalar multiplier to be applied to each wheel event
168 * @remainder: counts the number of high-resolution units moved since the last
169 * low-resolution event (REL_WHEEL or REL_HWHEEL) was sent. Should
170 * only be used by class methods.
171 * @direction: direction of last movement (1 or -1)
172 * @last_time: last event time, used to reset remainder after inactivity
174 struct hidpp_scroll_counter
{
175 int wheel_multiplier
;
178 unsigned long long last_time
;
181 struct hidpp_device
{
182 struct hid_device
*hid_dev
;
183 struct input_dev
*input
;
184 struct mutex send_mutex
;
185 void *send_receive_buf
;
186 char *name
; /* will never be NULL and should not be freed */
187 wait_queue_head_t wait
;
188 int very_long_report_length
;
189 bool answer_available
;
195 struct work_struct work
;
196 struct kfifo delayed_work_fifo
;
197 struct input_dev
*delayed_input
;
199 unsigned long quirks
;
200 unsigned long capabilities
;
201 u8 supported_reports
;
203 struct hidpp_battery battery
;
204 struct hidpp_scroll_counter vertical_wheel_counter
;
206 u8 wireless_feature_index
;
211 /* HID++ 1.0 error codes */
212 #define HIDPP_ERROR 0x8f
213 #define HIDPP_ERROR_SUCCESS 0x00
214 #define HIDPP_ERROR_INVALID_SUBID 0x01
215 #define HIDPP_ERROR_INVALID_ADRESS 0x02
216 #define HIDPP_ERROR_INVALID_VALUE 0x03
217 #define HIDPP_ERROR_CONNECT_FAIL 0x04
218 #define HIDPP_ERROR_TOO_MANY_DEVICES 0x05
219 #define HIDPP_ERROR_ALREADY_EXISTS 0x06
220 #define HIDPP_ERROR_BUSY 0x07
221 #define HIDPP_ERROR_UNKNOWN_DEVICE 0x08
222 #define HIDPP_ERROR_RESOURCE_ERROR 0x09
223 #define HIDPP_ERROR_REQUEST_UNAVAILABLE 0x0a
224 #define HIDPP_ERROR_INVALID_PARAM_VALUE 0x0b
225 #define HIDPP_ERROR_WRONG_PIN_CODE 0x0c
226 /* HID++ 2.0 error codes */
227 #define HIDPP20_ERROR_NO_ERROR 0x00
228 #define HIDPP20_ERROR_UNKNOWN 0x01
229 #define HIDPP20_ERROR_INVALID_ARGS 0x02
230 #define HIDPP20_ERROR_OUT_OF_RANGE 0x03
231 #define HIDPP20_ERROR_HW_ERROR 0x04
232 #define HIDPP20_ERROR_NOT_ALLOWED 0x05
233 #define HIDPP20_ERROR_INVALID_FEATURE_INDEX 0x06
234 #define HIDPP20_ERROR_INVALID_FUNCTION_ID 0x07
235 #define HIDPP20_ERROR_BUSY 0x08
236 #define HIDPP20_ERROR_UNSUPPORTED 0x09
237 #define HIDPP20_ERROR 0xff
239 static int __hidpp_send_report(struct hid_device
*hdev
,
240 struct hidpp_report
*hidpp_report
)
242 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
243 int fields_count
, ret
;
245 switch (hidpp_report
->report_id
) {
246 case REPORT_ID_HIDPP_SHORT
:
247 fields_count
= HIDPP_REPORT_SHORT_LENGTH
;
249 case REPORT_ID_HIDPP_LONG
:
250 fields_count
= HIDPP_REPORT_LONG_LENGTH
;
252 case REPORT_ID_HIDPP_VERY_LONG
:
253 fields_count
= hidpp
->very_long_report_length
;
260 * set the device_index as the receiver, it will be overwritten by
261 * hid_hw_request if needed
263 hidpp_report
->device_index
= 0xff;
265 if (hidpp
->quirks
& HIDPP_QUIRK_FORCE_OUTPUT_REPORTS
) {
266 ret
= hid_hw_output_report(hdev
, (u8
*)hidpp_report
, fields_count
);
268 ret
= hid_hw_raw_request(hdev
, hidpp_report
->report_id
,
269 (u8
*)hidpp_report
, fields_count
, HID_OUTPUT_REPORT
,
273 return ret
== fields_count
? 0 : -1;
277 * Effectively send the message to the device, waiting for its answer.
279 * Must be called with hidpp->send_mutex locked
281 * Same return protocol than hidpp_send_message_sync():
283 * - negative error means transport error
284 * - positive value means protocol error
286 static int __do_hidpp_send_message_sync(struct hidpp_device
*hidpp
,
287 struct hidpp_report
*message
,
288 struct hidpp_report
*response
)
292 __must_hold(&hidpp
->send_mutex
);
294 hidpp
->send_receive_buf
= response
;
295 hidpp
->answer_available
= false;
298 * So that we can later validate the answer when it arrives
301 *response
= *message
;
303 ret
= __hidpp_send_report(hidpp
->hid_dev
, message
);
305 dbg_hid("__hidpp_send_report returned err: %d\n", ret
);
306 memset(response
, 0, sizeof(struct hidpp_report
));
310 if (!wait_event_timeout(hidpp
->wait
, hidpp
->answer_available
,
312 dbg_hid("%s:timeout waiting for response\n", __func__
);
313 memset(response
, 0, sizeof(struct hidpp_report
));
317 if (response
->report_id
== REPORT_ID_HIDPP_SHORT
&&
318 response
->rap
.sub_id
== HIDPP_ERROR
) {
319 ret
= response
->rap
.params
[1];
320 dbg_hid("%s:got hidpp error %02X\n", __func__
, ret
);
324 if ((response
->report_id
== REPORT_ID_HIDPP_LONG
||
325 response
->report_id
== REPORT_ID_HIDPP_VERY_LONG
) &&
326 response
->fap
.feature_index
== HIDPP20_ERROR
) {
327 ret
= response
->fap
.params
[1];
328 dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__
, ret
);
336 * hidpp_send_message_sync() returns 0 in case of success, and something else
337 * in case of a failure.
339 * See __do_hidpp_send_message_sync() for a detailed explanation of the returned
342 static int hidpp_send_message_sync(struct hidpp_device
*hidpp
,
343 struct hidpp_report
*message
,
344 struct hidpp_report
*response
)
349 mutex_lock(&hidpp
->send_mutex
);
352 ret
= __do_hidpp_send_message_sync(hidpp
, message
, response
);
353 if (ret
!= HIDPP20_ERROR_BUSY
)
356 dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__
, ret
);
357 } while (--max_retries
);
359 mutex_unlock(&hidpp
->send_mutex
);
365 * hidpp_send_fap_command_sync() returns 0 in case of success, and something else
366 * in case of a failure.
368 * See __do_hidpp_send_message_sync() for a detailed explanation of the returned
371 static int hidpp_send_fap_command_sync(struct hidpp_device
*hidpp
,
372 u8 feat_index
, u8 funcindex_clientid
, u8
*params
, int param_count
,
373 struct hidpp_report
*response
)
375 struct hidpp_report
*message
;
378 if (param_count
> sizeof(message
->fap
.params
)) {
379 hid_dbg(hidpp
->hid_dev
,
380 "Invalid number of parameters passed to command (%d != %llu)\n",
382 (unsigned long long) sizeof(message
->fap
.params
));
386 message
= kzalloc(sizeof(struct hidpp_report
), GFP_KERNEL
);
390 if (param_count
> (HIDPP_REPORT_LONG_LENGTH
- 4))
391 message
->report_id
= REPORT_ID_HIDPP_VERY_LONG
;
393 message
->report_id
= REPORT_ID_HIDPP_LONG
;
394 message
->fap
.feature_index
= feat_index
;
395 message
->fap
.funcindex_clientid
= funcindex_clientid
| LINUX_KERNEL_SW_ID
;
396 memcpy(&message
->fap
.params
, params
, param_count
);
398 ret
= hidpp_send_message_sync(hidpp
, message
, response
);
404 * hidpp_send_rap_command_sync() returns 0 in case of success, and something else
405 * in case of a failure.
407 * See __do_hidpp_send_message_sync() for a detailed explanation of the returned
410 static int hidpp_send_rap_command_sync(struct hidpp_device
*hidpp_dev
,
411 u8 report_id
, u8 sub_id
, u8 reg_address
, u8
*params
, int param_count
,
412 struct hidpp_report
*response
)
414 struct hidpp_report
*message
;
417 /* Send as long report if short reports are not supported. */
418 if (report_id
== REPORT_ID_HIDPP_SHORT
&&
419 !(hidpp_dev
->supported_reports
& HIDPP_REPORT_SHORT_SUPPORTED
))
420 report_id
= REPORT_ID_HIDPP_LONG
;
423 case REPORT_ID_HIDPP_SHORT
:
424 max_count
= HIDPP_REPORT_SHORT_LENGTH
- 4;
426 case REPORT_ID_HIDPP_LONG
:
427 max_count
= HIDPP_REPORT_LONG_LENGTH
- 4;
429 case REPORT_ID_HIDPP_VERY_LONG
:
430 max_count
= hidpp_dev
->very_long_report_length
- 4;
436 if (param_count
> max_count
)
439 message
= kzalloc(sizeof(struct hidpp_report
), GFP_KERNEL
);
442 message
->report_id
= report_id
;
443 message
->rap
.sub_id
= sub_id
;
444 message
->rap
.reg_address
= reg_address
;
445 memcpy(&message
->rap
.params
, params
, param_count
);
447 ret
= hidpp_send_message_sync(hidpp_dev
, message
, response
);
452 static inline bool hidpp_match_answer(struct hidpp_report
*question
,
453 struct hidpp_report
*answer
)
455 return (answer
->fap
.feature_index
== question
->fap
.feature_index
) &&
456 (answer
->fap
.funcindex_clientid
== question
->fap
.funcindex_clientid
);
459 static inline bool hidpp_match_error(struct hidpp_report
*question
,
460 struct hidpp_report
*answer
)
462 return ((answer
->rap
.sub_id
== HIDPP_ERROR
) ||
463 (answer
->fap
.feature_index
== HIDPP20_ERROR
)) &&
464 (answer
->fap
.funcindex_clientid
== question
->fap
.feature_index
) &&
465 (answer
->fap
.params
[0] == question
->fap
.funcindex_clientid
);
468 static inline bool hidpp_report_is_connect_event(struct hidpp_device
*hidpp
,
469 struct hidpp_report
*report
)
471 return (hidpp
->wireless_feature_index
&&
472 (report
->fap
.feature_index
== hidpp
->wireless_feature_index
)) ||
473 ((report
->report_id
== REPORT_ID_HIDPP_SHORT
) &&
474 (report
->rap
.sub_id
== 0x41));
478 * hidpp_prefix_name() prefixes the current given name with "Logitech ".
480 static void hidpp_prefix_name(char **name
, int name_length
)
482 #define PREFIX_LENGTH 9 /* "Logitech " */
487 if (name_length
> PREFIX_LENGTH
&&
488 strncmp(*name
, "Logitech ", PREFIX_LENGTH
) == 0)
489 /* The prefix has is already in the name */
492 new_length
= PREFIX_LENGTH
+ name_length
;
493 new_name
= kzalloc(new_length
, GFP_KERNEL
);
497 snprintf(new_name
, new_length
, "Logitech %s", *name
);
505 * Updates the USB wireless_status based on whether the headset
506 * is turned on and reachable.
508 static void hidpp_update_usb_wireless_status(struct hidpp_device
*hidpp
)
510 struct hid_device
*hdev
= hidpp
->hid_dev
;
511 struct usb_interface
*intf
;
513 if (!(hidpp
->quirks
& HIDPP_QUIRK_WIRELESS_STATUS
))
515 if (!hid_is_usb(hdev
))
518 intf
= to_usb_interface(hdev
->dev
.parent
);
519 usb_set_wireless_status(intf
, hidpp
->battery
.online
?
520 USB_WIRELESS_STATUS_CONNECTED
:
521 USB_WIRELESS_STATUS_DISCONNECTED
);
525 * hidpp_scroll_counter_handle_scroll() - Send high- and low-resolution scroll
526 * events given a high-resolution wheel
528 * @input_dev: Pointer to the input device
529 * @counter: a hid_scroll_counter struct describing the wheel.
530 * @hi_res_value: the movement of the wheel, in the mouse's high-resolution
533 * Given a high-resolution movement, this function converts the movement into
534 * fractions of 120 and emits high-resolution scroll events for the input
535 * device. It also uses the multiplier from &struct hid_scroll_counter to
536 * emit low-resolution scroll events when appropriate for
537 * backwards-compatibility with userspace input libraries.
539 static void hidpp_scroll_counter_handle_scroll(struct input_dev
*input_dev
,
540 struct hidpp_scroll_counter
*counter
,
543 int low_res_value
, remainder
, direction
;
544 unsigned long long now
, previous
;
546 hi_res_value
= hi_res_value
* 120/counter
->wheel_multiplier
;
547 input_report_rel(input_dev
, REL_WHEEL_HI_RES
, hi_res_value
);
549 remainder
= counter
->remainder
;
550 direction
= hi_res_value
> 0 ? 1 : -1;
553 previous
= counter
->last_time
;
554 counter
->last_time
= now
;
556 * Reset the remainder after a period of inactivity or when the
557 * direction changes. This prevents the REL_WHEEL emulation point
558 * from sliding for devices that don't always provide the same
559 * number of movements per detent.
561 if (now
- previous
> 1000000000 || direction
!= counter
->direction
)
564 counter
->direction
= direction
;
565 remainder
+= hi_res_value
;
567 /* Some wheels will rest 7/8ths of a detent from the previous detent
568 * after slow movement, so we want the threshold for low-res events to
569 * be in the middle between two detents (e.g. after 4/8ths) as
570 * opposed to on the detents themselves (8/8ths).
572 if (abs(remainder
) >= 60) {
573 /* Add (or subtract) 1 because we want to trigger when the wheel
574 * is half-way to the next detent (i.e. scroll 1 detent after a
575 * 1/2 detent movement, 2 detents after a 1 1/2 detent movement,
578 low_res_value
= remainder
/ 120;
579 if (low_res_value
== 0)
580 low_res_value
= (hi_res_value
> 0 ? 1 : -1);
581 input_report_rel(input_dev
, REL_WHEEL
, low_res_value
);
582 remainder
-= low_res_value
* 120;
584 counter
->remainder
= remainder
;
587 /* -------------------------------------------------------------------------- */
588 /* HIDP++ 1.0 commands */
589 /* -------------------------------------------------------------------------- */
591 #define HIDPP_SET_REGISTER 0x80
592 #define HIDPP_GET_REGISTER 0x81
593 #define HIDPP_SET_LONG_REGISTER 0x82
594 #define HIDPP_GET_LONG_REGISTER 0x83
597 * hidpp10_set_register - Modify a HID++ 1.0 register.
598 * @hidpp_dev: the device to set the register on.
599 * @register_address: the address of the register to modify.
600 * @byte: the byte of the register to modify. Should be less than 3.
601 * @mask: mask of the bits to modify
602 * @value: new values for the bits in mask
603 * Return: 0 if successful, otherwise a negative error code.
605 static int hidpp10_set_register(struct hidpp_device
*hidpp_dev
,
606 u8 register_address
, u8 byte
, u8 mask
, u8 value
)
608 struct hidpp_report response
;
610 u8 params
[3] = { 0 };
612 ret
= hidpp_send_rap_command_sync(hidpp_dev
,
613 REPORT_ID_HIDPP_SHORT
,
620 memcpy(params
, response
.rap
.params
, 3);
622 params
[byte
] &= ~mask
;
623 params
[byte
] |= value
& mask
;
625 return hidpp_send_rap_command_sync(hidpp_dev
,
626 REPORT_ID_HIDPP_SHORT
,
629 params
, 3, &response
);
632 #define HIDPP_REG_ENABLE_REPORTS 0x00
633 #define HIDPP_ENABLE_CONSUMER_REPORT BIT(0)
634 #define HIDPP_ENABLE_WHEEL_REPORT BIT(2)
635 #define HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT BIT(3)
636 #define HIDPP_ENABLE_BAT_REPORT BIT(4)
637 #define HIDPP_ENABLE_HWHEEL_REPORT BIT(5)
639 static int hidpp10_enable_battery_reporting(struct hidpp_device
*hidpp_dev
)
641 return hidpp10_set_register(hidpp_dev
, HIDPP_REG_ENABLE_REPORTS
, 0,
642 HIDPP_ENABLE_BAT_REPORT
, HIDPP_ENABLE_BAT_REPORT
);
645 #define HIDPP_REG_FEATURES 0x01
646 #define HIDPP_ENABLE_SPECIAL_BUTTON_FUNC BIT(1)
647 #define HIDPP_ENABLE_FAST_SCROLL BIT(6)
649 /* On HID++ 1.0 devices, high-res scroll was called "scrolling acceleration". */
650 static int hidpp10_enable_scrolling_acceleration(struct hidpp_device
*hidpp_dev
)
652 return hidpp10_set_register(hidpp_dev
, HIDPP_REG_FEATURES
, 0,
653 HIDPP_ENABLE_FAST_SCROLL
, HIDPP_ENABLE_FAST_SCROLL
);
656 #define HIDPP_REG_BATTERY_STATUS 0x07
658 static int hidpp10_battery_status_map_level(u8 param
)
664 level
= POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL
;
667 level
= POWER_SUPPLY_CAPACITY_LEVEL_LOW
;
670 level
= POWER_SUPPLY_CAPACITY_LEVEL_NORMAL
;
673 level
= POWER_SUPPLY_CAPACITY_LEVEL_HIGH
;
676 level
= POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN
;
682 static int hidpp10_battery_status_map_status(u8 param
)
688 /* discharging (in use) */
689 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
691 case 0x21: /* (standard) charging */
692 case 0x24: /* fast charging */
693 case 0x25: /* slow charging */
694 status
= POWER_SUPPLY_STATUS_CHARGING
;
696 case 0x26: /* topping charge */
697 case 0x22: /* charge complete */
698 status
= POWER_SUPPLY_STATUS_FULL
;
700 case 0x20: /* unknown */
701 status
= POWER_SUPPLY_STATUS_UNKNOWN
;
704 * 0x01...0x1F = reserved (not charging)
705 * 0x23 = charging error
706 * 0x27..0xff = reserved
709 status
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
716 static int hidpp10_query_battery_status(struct hidpp_device
*hidpp
)
718 struct hidpp_report response
;
721 ret
= hidpp_send_rap_command_sync(hidpp
,
722 REPORT_ID_HIDPP_SHORT
,
724 HIDPP_REG_BATTERY_STATUS
,
729 hidpp
->battery
.level
=
730 hidpp10_battery_status_map_level(response
.rap
.params
[0]);
731 status
= hidpp10_battery_status_map_status(response
.rap
.params
[1]);
732 hidpp
->battery
.status
= status
;
733 /* the capacity is only available when discharging or full */
734 hidpp
->battery
.online
= status
== POWER_SUPPLY_STATUS_DISCHARGING
||
735 status
== POWER_SUPPLY_STATUS_FULL
;
740 #define HIDPP_REG_BATTERY_MILEAGE 0x0D
742 static int hidpp10_battery_mileage_map_status(u8 param
)
746 switch (param
>> 6) {
748 /* discharging (in use) */
749 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
751 case 0x01: /* charging */
752 status
= POWER_SUPPLY_STATUS_CHARGING
;
754 case 0x02: /* charge complete */
755 status
= POWER_SUPPLY_STATUS_FULL
;
758 * 0x03 = charging error
761 status
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
768 static int hidpp10_query_battery_mileage(struct hidpp_device
*hidpp
)
770 struct hidpp_report response
;
773 ret
= hidpp_send_rap_command_sync(hidpp
,
774 REPORT_ID_HIDPP_SHORT
,
776 HIDPP_REG_BATTERY_MILEAGE
,
781 hidpp
->battery
.capacity
= response
.rap
.params
[0];
782 status
= hidpp10_battery_mileage_map_status(response
.rap
.params
[2]);
783 hidpp
->battery
.status
= status
;
784 /* the capacity is only available when discharging or full */
785 hidpp
->battery
.online
= status
== POWER_SUPPLY_STATUS_DISCHARGING
||
786 status
== POWER_SUPPLY_STATUS_FULL
;
791 static int hidpp10_battery_event(struct hidpp_device
*hidpp
, u8
*data
, int size
)
793 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
794 int status
, capacity
, level
;
797 if (report
->report_id
!= REPORT_ID_HIDPP_SHORT
)
800 switch (report
->rap
.sub_id
) {
801 case HIDPP_REG_BATTERY_STATUS
:
802 capacity
= hidpp
->battery
.capacity
;
803 level
= hidpp10_battery_status_map_level(report
->rawbytes
[1]);
804 status
= hidpp10_battery_status_map_status(report
->rawbytes
[2]);
806 case HIDPP_REG_BATTERY_MILEAGE
:
807 capacity
= report
->rap
.params
[0];
808 level
= hidpp
->battery
.level
;
809 status
= hidpp10_battery_mileage_map_status(report
->rawbytes
[3]);
815 changed
= capacity
!= hidpp
->battery
.capacity
||
816 level
!= hidpp
->battery
.level
||
817 status
!= hidpp
->battery
.status
;
819 /* the capacity is only available when discharging or full */
820 hidpp
->battery
.online
= status
== POWER_SUPPLY_STATUS_DISCHARGING
||
821 status
== POWER_SUPPLY_STATUS_FULL
;
824 hidpp
->battery
.level
= level
;
825 hidpp
->battery
.status
= status
;
826 if (hidpp
->battery
.ps
)
827 power_supply_changed(hidpp
->battery
.ps
);
833 #define HIDPP_REG_PAIRING_INFORMATION 0xB5
834 #define HIDPP_EXTENDED_PAIRING 0x30
835 #define HIDPP_DEVICE_NAME 0x40
837 static char *hidpp_unifying_get_name(struct hidpp_device
*hidpp_dev
)
839 struct hidpp_report response
;
841 u8 params
[1] = { HIDPP_DEVICE_NAME
};
845 ret
= hidpp_send_rap_command_sync(hidpp_dev
,
846 REPORT_ID_HIDPP_SHORT
,
847 HIDPP_GET_LONG_REGISTER
,
848 HIDPP_REG_PAIRING_INFORMATION
,
849 params
, 1, &response
);
853 len
= response
.rap
.params
[1];
855 if (2 + len
> sizeof(response
.rap
.params
))
858 if (len
< 4) /* logitech devices are usually at least Xddd */
861 name
= kzalloc(len
+ 1, GFP_KERNEL
);
865 memcpy(name
, &response
.rap
.params
[2], len
);
867 /* include the terminating '\0' */
868 hidpp_prefix_name(&name
, len
+ 1);
873 static int hidpp_unifying_get_serial(struct hidpp_device
*hidpp
, u32
*serial
)
875 struct hidpp_report response
;
877 u8 params
[1] = { HIDPP_EXTENDED_PAIRING
};
879 ret
= hidpp_send_rap_command_sync(hidpp
,
880 REPORT_ID_HIDPP_SHORT
,
881 HIDPP_GET_LONG_REGISTER
,
882 HIDPP_REG_PAIRING_INFORMATION
,
883 params
, 1, &response
);
888 * We don't care about LE or BE, we will output it as a string
889 * with %4phD, so we need to keep the order.
891 *serial
= *((u32
*)&response
.rap
.params
[1]);
895 static int hidpp_unifying_init(struct hidpp_device
*hidpp
)
897 struct hid_device
*hdev
= hidpp
->hid_dev
;
902 ret
= hidpp_unifying_get_serial(hidpp
, &serial
);
906 snprintf(hdev
->uniq
, sizeof(hdev
->uniq
), "%4phD", &serial
);
907 dbg_hid("HID++ Unifying: Got serial: %s\n", hdev
->uniq
);
909 name
= hidpp_unifying_get_name(hidpp
);
913 snprintf(hdev
->name
, sizeof(hdev
->name
), "%s", name
);
914 dbg_hid("HID++ Unifying: Got name: %s\n", name
);
920 /* -------------------------------------------------------------------------- */
922 /* -------------------------------------------------------------------------- */
924 #define HIDPP_PAGE_ROOT 0x0000
925 #define HIDPP_PAGE_ROOT_IDX 0x00
927 #define CMD_ROOT_GET_FEATURE 0x00
928 #define CMD_ROOT_GET_PROTOCOL_VERSION 0x10
930 static int hidpp_root_get_feature(struct hidpp_device
*hidpp
, u16 feature
,
931 u8
*feature_index
, u8
*feature_type
)
933 struct hidpp_report response
;
935 u8 params
[2] = { feature
>> 8, feature
& 0x00FF };
937 ret
= hidpp_send_fap_command_sync(hidpp
,
939 CMD_ROOT_GET_FEATURE
,
940 params
, 2, &response
);
944 if (response
.fap
.params
[0] == 0)
947 *feature_index
= response
.fap
.params
[0];
948 *feature_type
= response
.fap
.params
[1];
953 static int hidpp_root_get_protocol_version(struct hidpp_device
*hidpp
)
955 const u8 ping_byte
= 0x5a;
956 u8 ping_data
[3] = { 0, 0, ping_byte
};
957 struct hidpp_report response
;
960 ret
= hidpp_send_rap_command_sync(hidpp
,
961 REPORT_ID_HIDPP_SHORT
,
963 CMD_ROOT_GET_PROTOCOL_VERSION
| LINUX_KERNEL_SW_ID
,
964 ping_data
, sizeof(ping_data
), &response
);
966 if (ret
== HIDPP_ERROR_INVALID_SUBID
) {
967 hidpp
->protocol_major
= 1;
968 hidpp
->protocol_minor
= 0;
972 /* the device might not be connected */
973 if (ret
== HIDPP_ERROR_RESOURCE_ERROR
)
977 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
984 if (response
.rap
.params
[2] != ping_byte
) {
985 hid_err(hidpp
->hid_dev
, "%s: ping mismatch 0x%02x != 0x%02x\n",
986 __func__
, response
.rap
.params
[2], ping_byte
);
990 hidpp
->protocol_major
= response
.rap
.params
[0];
991 hidpp
->protocol_minor
= response
.rap
.params
[1];
994 if (!hidpp
->connected_once
) {
995 hid_info(hidpp
->hid_dev
, "HID++ %u.%u device connected.\n",
996 hidpp
->protocol_major
, hidpp
->protocol_minor
);
997 hidpp
->connected_once
= true;
999 hid_dbg(hidpp
->hid_dev
, "HID++ %u.%u device connected.\n",
1000 hidpp
->protocol_major
, hidpp
->protocol_minor
);
1004 /* -------------------------------------------------------------------------- */
1005 /* 0x0003: Device Information */
1006 /* -------------------------------------------------------------------------- */
1008 #define HIDPP_PAGE_DEVICE_INFORMATION 0x0003
1010 #define CMD_GET_DEVICE_INFO 0x00
1012 static int hidpp_get_serial(struct hidpp_device
*hidpp
, u32
*serial
)
1014 struct hidpp_report response
;
1019 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_DEVICE_INFORMATION
,
1025 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1026 CMD_GET_DEVICE_INFO
,
1027 NULL
, 0, &response
);
1031 /* See hidpp_unifying_get_serial() */
1032 *serial
= *((u32
*)&response
.rap
.params
[1]);
1036 static int hidpp_serial_init(struct hidpp_device
*hidpp
)
1038 struct hid_device
*hdev
= hidpp
->hid_dev
;
1042 ret
= hidpp_get_serial(hidpp
, &serial
);
1046 snprintf(hdev
->uniq
, sizeof(hdev
->uniq
), "%4phD", &serial
);
1047 dbg_hid("HID++ DeviceInformation: Got serial: %s\n", hdev
->uniq
);
1052 /* -------------------------------------------------------------------------- */
1053 /* 0x0005: GetDeviceNameType */
1054 /* -------------------------------------------------------------------------- */
1056 #define HIDPP_PAGE_GET_DEVICE_NAME_TYPE 0x0005
1058 #define CMD_GET_DEVICE_NAME_TYPE_GET_COUNT 0x00
1059 #define CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME 0x10
1060 #define CMD_GET_DEVICE_NAME_TYPE_GET_TYPE 0x20
1062 static int hidpp_devicenametype_get_count(struct hidpp_device
*hidpp
,
1063 u8 feature_index
, u8
*nameLength
)
1065 struct hidpp_report response
;
1068 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1069 CMD_GET_DEVICE_NAME_TYPE_GET_COUNT
, NULL
, 0, &response
);
1072 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1079 *nameLength
= response
.fap
.params
[0];
1084 static int hidpp_devicenametype_get_device_name(struct hidpp_device
*hidpp
,
1085 u8 feature_index
, u8 char_index
, char *device_name
, int len_buf
)
1087 struct hidpp_report response
;
1091 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1092 CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME
, &char_index
, 1,
1096 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1103 switch (response
.report_id
) {
1104 case REPORT_ID_HIDPP_VERY_LONG
:
1105 count
= hidpp
->very_long_report_length
- 4;
1107 case REPORT_ID_HIDPP_LONG
:
1108 count
= HIDPP_REPORT_LONG_LENGTH
- 4;
1110 case REPORT_ID_HIDPP_SHORT
:
1111 count
= HIDPP_REPORT_SHORT_LENGTH
- 4;
1117 if (len_buf
< count
)
1120 for (i
= 0; i
< count
; i
++)
1121 device_name
[i
] = response
.fap
.params
[i
];
1126 static char *hidpp_get_device_name(struct hidpp_device
*hidpp
)
1135 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_GET_DEVICE_NAME_TYPE
,
1136 &feature_index
, &feature_type
);
1140 ret
= hidpp_devicenametype_get_count(hidpp
, feature_index
,
1145 name
= kzalloc(__name_length
+ 1, GFP_KERNEL
);
1149 while (index
< __name_length
) {
1150 ret
= hidpp_devicenametype_get_device_name(hidpp
,
1151 feature_index
, index
, name
+ index
,
1152 __name_length
- index
);
1160 /* include the terminating '\0' */
1161 hidpp_prefix_name(&name
, __name_length
+ 1);
1166 /* -------------------------------------------------------------------------- */
1167 /* 0x1000: Battery level status */
1168 /* -------------------------------------------------------------------------- */
1170 #define HIDPP_PAGE_BATTERY_LEVEL_STATUS 0x1000
1172 #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS 0x00
1173 #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY 0x10
1175 #define EVENT_BATTERY_LEVEL_STATUS_BROADCAST 0x00
1177 #define FLAG_BATTERY_LEVEL_DISABLE_OSD BIT(0)
1178 #define FLAG_BATTERY_LEVEL_MILEAGE BIT(1)
1179 #define FLAG_BATTERY_LEVEL_RECHARGEABLE BIT(2)
1181 static int hidpp_map_battery_level(int capacity
)
1184 return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL
;
1186 * The spec says this should be < 31 but some devices report 30
1187 * with brand new batteries and Windows reports 30 as "Good".
1189 else if (capacity
< 30)
1190 return POWER_SUPPLY_CAPACITY_LEVEL_LOW
;
1191 else if (capacity
< 81)
1192 return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL
;
1193 return POWER_SUPPLY_CAPACITY_LEVEL_FULL
;
1196 static int hidpp20_batterylevel_map_status_capacity(u8 data
[3], int *capacity
,
1202 *capacity
= data
[0];
1203 *next_capacity
= data
[1];
1204 *level
= POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN
;
1206 /* When discharging, we can rely on the device reported capacity.
1207 * For all other states the device reports 0 (unknown).
1210 case 0: /* discharging (in use) */
1211 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
1212 *level
= hidpp_map_battery_level(*capacity
);
1214 case 1: /* recharging */
1215 status
= POWER_SUPPLY_STATUS_CHARGING
;
1217 case 2: /* charge in final stage */
1218 status
= POWER_SUPPLY_STATUS_CHARGING
;
1220 case 3: /* charge complete */
1221 status
= POWER_SUPPLY_STATUS_FULL
;
1222 *level
= POWER_SUPPLY_CAPACITY_LEVEL_FULL
;
1225 case 4: /* recharging below optimal speed */
1226 status
= POWER_SUPPLY_STATUS_CHARGING
;
1228 /* 5 = invalid battery type
1230 7 = other charging error */
1232 status
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1239 static int hidpp20_batterylevel_get_battery_capacity(struct hidpp_device
*hidpp
,
1246 struct hidpp_report response
;
1248 u8
*params
= (u8
*)response
.fap
.params
;
1250 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1251 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS
,
1252 NULL
, 0, &response
);
1253 /* Ignore these intermittent errors */
1254 if (ret
== HIDPP_ERROR_RESOURCE_ERROR
)
1257 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1264 *status
= hidpp20_batterylevel_map_status_capacity(params
, capacity
,
1271 static int hidpp20_batterylevel_get_battery_info(struct hidpp_device
*hidpp
,
1274 struct hidpp_report response
;
1276 u8
*params
= (u8
*)response
.fap
.params
;
1277 unsigned int level_count
, flags
;
1279 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1280 CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY
,
1281 NULL
, 0, &response
);
1283 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1290 level_count
= params
[0];
1293 if (level_count
< 10 || !(flags
& FLAG_BATTERY_LEVEL_MILEAGE
))
1294 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS
;
1296 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_MILEAGE
;
1301 static int hidpp20_query_battery_info_1000(struct hidpp_device
*hidpp
)
1305 int status
, capacity
, next_capacity
, level
;
1307 if (hidpp
->battery
.feature_index
== 0xff) {
1308 ret
= hidpp_root_get_feature(hidpp
,
1309 HIDPP_PAGE_BATTERY_LEVEL_STATUS
,
1310 &hidpp
->battery
.feature_index
,
1316 ret
= hidpp20_batterylevel_get_battery_capacity(hidpp
,
1317 hidpp
->battery
.feature_index
,
1319 &next_capacity
, &level
);
1323 ret
= hidpp20_batterylevel_get_battery_info(hidpp
,
1324 hidpp
->battery
.feature_index
);
1328 hidpp
->battery
.status
= status
;
1329 hidpp
->battery
.capacity
= capacity
;
1330 hidpp
->battery
.level
= level
;
1331 /* the capacity is only available when discharging or full */
1332 hidpp
->battery
.online
= status
== POWER_SUPPLY_STATUS_DISCHARGING
||
1333 status
== POWER_SUPPLY_STATUS_FULL
;
1338 static int hidpp20_battery_event_1000(struct hidpp_device
*hidpp
,
1341 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
1342 int status
, capacity
, next_capacity
, level
;
1345 if (report
->fap
.feature_index
!= hidpp
->battery
.feature_index
||
1346 report
->fap
.funcindex_clientid
!= EVENT_BATTERY_LEVEL_STATUS_BROADCAST
)
1349 status
= hidpp20_batterylevel_map_status_capacity(report
->fap
.params
,
1354 /* the capacity is only available when discharging or full */
1355 hidpp
->battery
.online
= status
== POWER_SUPPLY_STATUS_DISCHARGING
||
1356 status
== POWER_SUPPLY_STATUS_FULL
;
1358 changed
= capacity
!= hidpp
->battery
.capacity
||
1359 level
!= hidpp
->battery
.level
||
1360 status
!= hidpp
->battery
.status
;
1363 hidpp
->battery
.level
= level
;
1364 hidpp
->battery
.capacity
= capacity
;
1365 hidpp
->battery
.status
= status
;
1366 if (hidpp
->battery
.ps
)
1367 power_supply_changed(hidpp
->battery
.ps
);
1373 /* -------------------------------------------------------------------------- */
1374 /* 0x1001: Battery voltage */
1375 /* -------------------------------------------------------------------------- */
1377 #define HIDPP_PAGE_BATTERY_VOLTAGE 0x1001
1379 #define CMD_BATTERY_VOLTAGE_GET_BATTERY_VOLTAGE 0x00
1381 #define EVENT_BATTERY_VOLTAGE_STATUS_BROADCAST 0x00
1383 static int hidpp20_battery_map_status_voltage(u8 data
[3], int *voltage
,
1384 int *level
, int *charge_type
)
1388 long flags
= (long) data
[2];
1389 *level
= POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN
;
1392 switch (flags
& 0x07) {
1394 status
= POWER_SUPPLY_STATUS_CHARGING
;
1397 status
= POWER_SUPPLY_STATUS_FULL
;
1398 *level
= POWER_SUPPLY_CAPACITY_LEVEL_FULL
;
1401 status
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1404 status
= POWER_SUPPLY_STATUS_UNKNOWN
;
1408 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
1410 *charge_type
= POWER_SUPPLY_CHARGE_TYPE_STANDARD
;
1411 if (test_bit(3, &flags
)) {
1412 *charge_type
= POWER_SUPPLY_CHARGE_TYPE_FAST
;
1414 if (test_bit(4, &flags
)) {
1415 *charge_type
= POWER_SUPPLY_CHARGE_TYPE_TRICKLE
;
1417 if (test_bit(5, &flags
)) {
1418 *level
= POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL
;
1421 *voltage
= get_unaligned_be16(data
);
1426 static int hidpp20_battery_get_battery_voltage(struct hidpp_device
*hidpp
,
1428 int *status
, int *voltage
,
1429 int *level
, int *charge_type
)
1431 struct hidpp_report response
;
1433 u8
*params
= (u8
*)response
.fap
.params
;
1435 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1436 CMD_BATTERY_VOLTAGE_GET_BATTERY_VOLTAGE
,
1437 NULL
, 0, &response
);
1440 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1447 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_VOLTAGE
;
1449 *status
= hidpp20_battery_map_status_voltage(params
, voltage
,
1450 level
, charge_type
);
1455 static int hidpp20_map_battery_capacity(struct hid_device
*hid_dev
, int voltage
)
1457 /* NB: This voltage curve doesn't necessarily map perfectly to all
1458 * devices that implement the BATTERY_VOLTAGE feature. This is because
1459 * there are a few devices that use different battery technology.
1462 static const int voltages
[100] = {
1463 4186, 4156, 4143, 4133, 4122, 4113, 4103, 4094, 4086, 4075,
1464 4067, 4059, 4051, 4043, 4035, 4027, 4019, 4011, 4003, 3997,
1465 3989, 3983, 3976, 3969, 3961, 3955, 3949, 3942, 3935, 3929,
1466 3922, 3916, 3909, 3902, 3896, 3890, 3883, 3877, 3870, 3865,
1467 3859, 3853, 3848, 3842, 3837, 3833, 3828, 3824, 3819, 3815,
1468 3811, 3808, 3804, 3800, 3797, 3793, 3790, 3787, 3784, 3781,
1469 3778, 3775, 3772, 3770, 3767, 3764, 3762, 3759, 3757, 3754,
1470 3751, 3748, 3744, 3741, 3737, 3734, 3730, 3726, 3724, 3720,
1471 3717, 3714, 3710, 3706, 3702, 3697, 3693, 3688, 3683, 3677,
1472 3671, 3666, 3662, 3658, 3654, 3646, 3633, 3612, 3579, 3537
1477 if (unlikely(voltage
< 3500 || voltage
>= 5000))
1478 hid_warn_once(hid_dev
,
1479 "%s: possibly using the wrong voltage curve\n",
1482 for (i
= 0; i
< ARRAY_SIZE(voltages
); i
++) {
1483 if (voltage
>= voltages
[i
])
1484 return ARRAY_SIZE(voltages
) - i
;
1490 static int hidpp20_query_battery_voltage_info(struct hidpp_device
*hidpp
)
1494 int status
, voltage
, level
, charge_type
;
1496 if (hidpp
->battery
.voltage_feature_index
== 0xff) {
1497 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_BATTERY_VOLTAGE
,
1498 &hidpp
->battery
.voltage_feature_index
,
1504 ret
= hidpp20_battery_get_battery_voltage(hidpp
,
1505 hidpp
->battery
.voltage_feature_index
,
1506 &status
, &voltage
, &level
, &charge_type
);
1511 hidpp
->battery
.status
= status
;
1512 hidpp
->battery
.voltage
= voltage
;
1513 hidpp
->battery
.capacity
= hidpp20_map_battery_capacity(hidpp
->hid_dev
,
1515 hidpp
->battery
.level
= level
;
1516 hidpp
->battery
.charge_type
= charge_type
;
1517 hidpp
->battery
.online
= status
!= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1522 static int hidpp20_battery_voltage_event(struct hidpp_device
*hidpp
,
1525 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
1526 int status
, voltage
, level
, charge_type
;
1528 if (report
->fap
.feature_index
!= hidpp
->battery
.voltage_feature_index
||
1529 report
->fap
.funcindex_clientid
!= EVENT_BATTERY_VOLTAGE_STATUS_BROADCAST
)
1532 status
= hidpp20_battery_map_status_voltage(report
->fap
.params
, &voltage
,
1533 &level
, &charge_type
);
1535 hidpp
->battery
.online
= status
!= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1537 if (voltage
!= hidpp
->battery
.voltage
|| status
!= hidpp
->battery
.status
) {
1538 hidpp
->battery
.voltage
= voltage
;
1539 hidpp
->battery
.capacity
= hidpp20_map_battery_capacity(hidpp
->hid_dev
,
1541 hidpp
->battery
.status
= status
;
1542 hidpp
->battery
.level
= level
;
1543 hidpp
->battery
.charge_type
= charge_type
;
1544 if (hidpp
->battery
.ps
)
1545 power_supply_changed(hidpp
->battery
.ps
);
1550 /* -------------------------------------------------------------------------- */
1551 /* 0x1004: Unified battery */
1552 /* -------------------------------------------------------------------------- */
1554 #define HIDPP_PAGE_UNIFIED_BATTERY 0x1004
1556 #define CMD_UNIFIED_BATTERY_GET_CAPABILITIES 0x00
1557 #define CMD_UNIFIED_BATTERY_GET_STATUS 0x10
1559 #define EVENT_UNIFIED_BATTERY_STATUS_EVENT 0x00
1561 #define FLAG_UNIFIED_BATTERY_LEVEL_CRITICAL BIT(0)
1562 #define FLAG_UNIFIED_BATTERY_LEVEL_LOW BIT(1)
1563 #define FLAG_UNIFIED_BATTERY_LEVEL_GOOD BIT(2)
1564 #define FLAG_UNIFIED_BATTERY_LEVEL_FULL BIT(3)
1566 #define FLAG_UNIFIED_BATTERY_FLAGS_RECHARGEABLE BIT(0)
1567 #define FLAG_UNIFIED_BATTERY_FLAGS_STATE_OF_CHARGE BIT(1)
1569 static int hidpp20_unifiedbattery_get_capabilities(struct hidpp_device
*hidpp
,
1572 struct hidpp_report response
;
1574 u8
*params
= (u8
*)response
.fap
.params
;
1576 if (hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS
||
1577 hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_PERCENTAGE
) {
1578 /* we have already set the device capabilities, so let's skip */
1582 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1583 CMD_UNIFIED_BATTERY_GET_CAPABILITIES
,
1584 NULL
, 0, &response
);
1585 /* Ignore these intermittent errors */
1586 if (ret
== HIDPP_ERROR_RESOURCE_ERROR
)
1589 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1597 * If the device supports state of charge (battery percentage) we won't
1598 * export the battery level information. there are 4 possible battery
1599 * levels and they all are optional, this means that the device might
1600 * not support any of them, we are just better off with the battery
1603 if (params
[1] & FLAG_UNIFIED_BATTERY_FLAGS_STATE_OF_CHARGE
) {
1604 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_PERCENTAGE
;
1605 hidpp
->battery
.supported_levels_1004
= 0;
1607 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS
;
1608 hidpp
->battery
.supported_levels_1004
= params
[0];
1614 static int hidpp20_unifiedbattery_map_status(struct hidpp_device
*hidpp
,
1616 u8 external_power_status
)
1620 switch (charging_status
) {
1621 case 0: /* discharging */
1622 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
1624 case 1: /* charging */
1625 case 2: /* charging slow */
1626 status
= POWER_SUPPLY_STATUS_CHARGING
;
1628 case 3: /* complete */
1629 status
= POWER_SUPPLY_STATUS_FULL
;
1632 status
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1633 hid_info(hidpp
->hid_dev
, "%s: charging error",
1637 status
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1644 static int hidpp20_unifiedbattery_map_level(struct hidpp_device
*hidpp
,
1647 /* cler unsupported level bits */
1648 battery_level
&= hidpp
->battery
.supported_levels_1004
;
1650 if (battery_level
& FLAG_UNIFIED_BATTERY_LEVEL_FULL
)
1651 return POWER_SUPPLY_CAPACITY_LEVEL_FULL
;
1652 else if (battery_level
& FLAG_UNIFIED_BATTERY_LEVEL_GOOD
)
1653 return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL
;
1654 else if (battery_level
& FLAG_UNIFIED_BATTERY_LEVEL_LOW
)
1655 return POWER_SUPPLY_CAPACITY_LEVEL_LOW
;
1656 else if (battery_level
& FLAG_UNIFIED_BATTERY_LEVEL_CRITICAL
)
1657 return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL
;
1659 return POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN
;
1662 static int hidpp20_unifiedbattery_get_status(struct hidpp_device
*hidpp
,
1664 u8
*state_of_charge
,
1668 struct hidpp_report response
;
1670 u8
*params
= (u8
*)response
.fap
.params
;
1672 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1673 CMD_UNIFIED_BATTERY_GET_STATUS
,
1674 NULL
, 0, &response
);
1675 /* Ignore these intermittent errors */
1676 if (ret
== HIDPP_ERROR_RESOURCE_ERROR
)
1679 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1686 *state_of_charge
= params
[0];
1687 *status
= hidpp20_unifiedbattery_map_status(hidpp
, params
[2], params
[3]);
1688 *level
= hidpp20_unifiedbattery_map_level(hidpp
, params
[1]);
1693 static int hidpp20_query_battery_info_1004(struct hidpp_device
*hidpp
)
1700 if (hidpp
->battery
.feature_index
== 0xff) {
1701 ret
= hidpp_root_get_feature(hidpp
,
1702 HIDPP_PAGE_UNIFIED_BATTERY
,
1703 &hidpp
->battery
.feature_index
,
1709 ret
= hidpp20_unifiedbattery_get_capabilities(hidpp
,
1710 hidpp
->battery
.feature_index
);
1714 ret
= hidpp20_unifiedbattery_get_status(hidpp
,
1715 hidpp
->battery
.feature_index
,
1722 hidpp
->capabilities
|= HIDPP_CAPABILITY_UNIFIED_BATTERY
;
1723 hidpp
->battery
.capacity
= state_of_charge
;
1724 hidpp
->battery
.status
= status
;
1725 hidpp
->battery
.level
= level
;
1726 hidpp
->battery
.online
= true;
1731 static int hidpp20_battery_event_1004(struct hidpp_device
*hidpp
,
1734 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
1735 u8
*params
= (u8
*)report
->fap
.params
;
1736 int state_of_charge
, status
, level
;
1739 if (report
->fap
.feature_index
!= hidpp
->battery
.feature_index
||
1740 report
->fap
.funcindex_clientid
!= EVENT_UNIFIED_BATTERY_STATUS_EVENT
)
1743 state_of_charge
= params
[0];
1744 status
= hidpp20_unifiedbattery_map_status(hidpp
, params
[2], params
[3]);
1745 level
= hidpp20_unifiedbattery_map_level(hidpp
, params
[1]);
1747 changed
= status
!= hidpp
->battery
.status
||
1748 (state_of_charge
!= hidpp
->battery
.capacity
&&
1749 hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_PERCENTAGE
) ||
1750 (level
!= hidpp
->battery
.level
&&
1751 hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS
);
1754 hidpp
->battery
.capacity
= state_of_charge
;
1755 hidpp
->battery
.status
= status
;
1756 hidpp
->battery
.level
= level
;
1757 if (hidpp
->battery
.ps
)
1758 power_supply_changed(hidpp
->battery
.ps
);
1764 /* -------------------------------------------------------------------------- */
1765 /* Battery feature helpers */
1766 /* -------------------------------------------------------------------------- */
1768 static enum power_supply_property hidpp_battery_props
[] = {
1769 POWER_SUPPLY_PROP_ONLINE
,
1770 POWER_SUPPLY_PROP_STATUS
,
1771 POWER_SUPPLY_PROP_SCOPE
,
1772 POWER_SUPPLY_PROP_MODEL_NAME
,
1773 POWER_SUPPLY_PROP_MANUFACTURER
,
1774 POWER_SUPPLY_PROP_SERIAL_NUMBER
,
1775 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY, */
1776 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY_LEVEL, */
1777 0, /* placeholder for POWER_SUPPLY_PROP_VOLTAGE_NOW, */
1780 static int hidpp_battery_get_property(struct power_supply
*psy
,
1781 enum power_supply_property psp
,
1782 union power_supply_propval
*val
)
1784 struct hidpp_device
*hidpp
= power_supply_get_drvdata(psy
);
1788 case POWER_SUPPLY_PROP_STATUS
:
1789 val
->intval
= hidpp
->battery
.status
;
1791 case POWER_SUPPLY_PROP_CAPACITY
:
1792 val
->intval
= hidpp
->battery
.capacity
;
1794 case POWER_SUPPLY_PROP_CAPACITY_LEVEL
:
1795 val
->intval
= hidpp
->battery
.level
;
1797 case POWER_SUPPLY_PROP_SCOPE
:
1798 val
->intval
= POWER_SUPPLY_SCOPE_DEVICE
;
1800 case POWER_SUPPLY_PROP_ONLINE
:
1801 val
->intval
= hidpp
->battery
.online
;
1803 case POWER_SUPPLY_PROP_MODEL_NAME
:
1804 if (!strncmp(hidpp
->name
, "Logitech ", 9))
1805 val
->strval
= hidpp
->name
+ 9;
1807 val
->strval
= hidpp
->name
;
1809 case POWER_SUPPLY_PROP_MANUFACTURER
:
1810 val
->strval
= "Logitech";
1812 case POWER_SUPPLY_PROP_SERIAL_NUMBER
:
1813 val
->strval
= hidpp
->hid_dev
->uniq
;
1815 case POWER_SUPPLY_PROP_VOLTAGE_NOW
:
1816 /* hardware reports voltage in mV. sysfs expects uV */
1817 val
->intval
= hidpp
->battery
.voltage
* 1000;
1819 case POWER_SUPPLY_PROP_CHARGE_TYPE
:
1820 val
->intval
= hidpp
->battery
.charge_type
;
1830 /* -------------------------------------------------------------------------- */
1831 /* 0x1d4b: Wireless device status */
1832 /* -------------------------------------------------------------------------- */
1833 #define HIDPP_PAGE_WIRELESS_DEVICE_STATUS 0x1d4b
1835 static int hidpp_get_wireless_feature_index(struct hidpp_device
*hidpp
, u8
*feature_index
)
1840 ret
= hidpp_root_get_feature(hidpp
,
1841 HIDPP_PAGE_WIRELESS_DEVICE_STATUS
,
1842 feature_index
, &feature_type
);
1847 /* -------------------------------------------------------------------------- */
1848 /* 0x1f20: ADC measurement */
1849 /* -------------------------------------------------------------------------- */
1851 #define HIDPP_PAGE_ADC_MEASUREMENT 0x1f20
1853 #define CMD_ADC_MEASUREMENT_GET_ADC_MEASUREMENT 0x00
1855 #define EVENT_ADC_MEASUREMENT_STATUS_BROADCAST 0x00
1857 static int hidpp20_map_adc_measurement_1f20_capacity(struct hid_device
*hid_dev
, int voltage
)
1859 /* NB: This voltage curve doesn't necessarily map perfectly to all
1860 * devices that implement the ADC_MEASUREMENT feature. This is because
1861 * there are a few devices that use different battery technology.
1864 * https://github.com/Sapd/HeadsetControl/blob/acd972be0468e039b93aae81221f20a54d2d60f7/src/devices/logitech_g633_g933_935.c#L44-L52
1866 static const int voltages
[100] = {
1867 4030, 4024, 4018, 4011, 4003, 3994, 3985, 3975, 3963, 3951,
1868 3937, 3922, 3907, 3893, 3880, 3868, 3857, 3846, 3837, 3828,
1869 3820, 3812, 3805, 3798, 3791, 3785, 3779, 3773, 3768, 3762,
1870 3757, 3752, 3747, 3742, 3738, 3733, 3729, 3724, 3720, 3716,
1871 3712, 3708, 3704, 3700, 3696, 3692, 3688, 3685, 3681, 3677,
1872 3674, 3670, 3667, 3663, 3660, 3657, 3653, 3650, 3646, 3643,
1873 3640, 3637, 3633, 3630, 3627, 3624, 3620, 3617, 3614, 3611,
1874 3608, 3604, 3601, 3598, 3595, 3592, 3589, 3585, 3582, 3579,
1875 3576, 3573, 3569, 3566, 3563, 3560, 3556, 3553, 3550, 3546,
1876 3543, 3539, 3536, 3532, 3529, 3525, 3499, 3466, 3433, 3399,
1884 if (unlikely(voltage
< 3400 || voltage
>= 5000))
1885 hid_warn_once(hid_dev
,
1886 "%s: possibly using the wrong voltage curve\n",
1889 for (i
= 0; i
< ARRAY_SIZE(voltages
); i
++) {
1890 if (voltage
>= voltages
[i
])
1891 return ARRAY_SIZE(voltages
) - i
;
1897 static int hidpp20_map_adc_measurement_1f20(u8 data
[3], int *voltage
)
1906 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
1909 status
= POWER_SUPPLY_STATUS_CHARGING
;
1912 status
= POWER_SUPPLY_STATUS_FULL
;
1916 status
= POWER_SUPPLY_STATUS_UNKNOWN
;
1920 *voltage
= get_unaligned_be16(data
);
1922 dbg_hid("Parsed 1f20 data as flag 0x%02x voltage %dmV\n",
1928 /* Return value is whether the device is online */
1929 static bool hidpp20_get_adc_measurement_1f20(struct hidpp_device
*hidpp
,
1931 int *status
, int *voltage
)
1933 struct hidpp_report response
;
1935 u8
*params
= (u8
*)response
.fap
.params
;
1937 *status
= POWER_SUPPLY_STATUS_UNKNOWN
;
1939 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
1940 CMD_ADC_MEASUREMENT_GET_ADC_MEASUREMENT
,
1941 NULL
, 0, &response
);
1944 hid_dbg(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
1949 *status
= hidpp20_map_adc_measurement_1f20(params
, voltage
);
1953 static int hidpp20_query_adc_measurement_info_1f20(struct hidpp_device
*hidpp
)
1957 if (hidpp
->battery
.adc_measurement_feature_index
== 0xff) {
1960 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_ADC_MEASUREMENT
,
1961 &hidpp
->battery
.adc_measurement_feature_index
,
1966 hidpp
->capabilities
|= HIDPP_CAPABILITY_ADC_MEASUREMENT
;
1969 hidpp
->battery
.online
= hidpp20_get_adc_measurement_1f20(hidpp
,
1970 hidpp
->battery
.adc_measurement_feature_index
,
1971 &hidpp
->battery
.status
,
1972 &hidpp
->battery
.voltage
);
1973 hidpp
->battery
.capacity
= hidpp20_map_adc_measurement_1f20_capacity(hidpp
->hid_dev
,
1974 hidpp
->battery
.voltage
);
1975 hidpp_update_usb_wireless_status(hidpp
);
1980 static int hidpp20_adc_measurement_event_1f20(struct hidpp_device
*hidpp
,
1983 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
1984 int status
, voltage
;
1986 if (report
->fap
.feature_index
!= hidpp
->battery
.adc_measurement_feature_index
||
1987 report
->fap
.funcindex_clientid
!= EVENT_ADC_MEASUREMENT_STATUS_BROADCAST
)
1990 status
= hidpp20_map_adc_measurement_1f20(report
->fap
.params
, &voltage
);
1992 hidpp
->battery
.online
= status
!= POWER_SUPPLY_STATUS_UNKNOWN
;
1994 if (voltage
!= hidpp
->battery
.voltage
|| status
!= hidpp
->battery
.status
) {
1995 hidpp
->battery
.status
= status
;
1996 hidpp
->battery
.voltage
= voltage
;
1997 hidpp
->battery
.capacity
= hidpp20_map_adc_measurement_1f20_capacity(hidpp
->hid_dev
, voltage
);
1998 if (hidpp
->battery
.ps
)
1999 power_supply_changed(hidpp
->battery
.ps
);
2000 hidpp_update_usb_wireless_status(hidpp
);
2005 /* -------------------------------------------------------------------------- */
2006 /* 0x2120: Hi-resolution scrolling */
2007 /* -------------------------------------------------------------------------- */
2009 #define HIDPP_PAGE_HI_RESOLUTION_SCROLLING 0x2120
2011 #define CMD_HI_RESOLUTION_SCROLLING_SET_HIGHRES_SCROLLING_MODE 0x10
2013 static int hidpp_hrs_set_highres_scrolling_mode(struct hidpp_device
*hidpp
,
2014 bool enabled
, u8
*multiplier
)
2020 struct hidpp_report response
;
2022 ret
= hidpp_root_get_feature(hidpp
,
2023 HIDPP_PAGE_HI_RESOLUTION_SCROLLING
,
2029 params
[0] = enabled
? BIT(0) : 0;
2030 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
2031 CMD_HI_RESOLUTION_SCROLLING_SET_HIGHRES_SCROLLING_MODE
,
2032 params
, sizeof(params
), &response
);
2035 *multiplier
= response
.fap
.params
[1];
2039 /* -------------------------------------------------------------------------- */
2040 /* 0x2121: HiRes Wheel */
2041 /* -------------------------------------------------------------------------- */
2043 #define HIDPP_PAGE_HIRES_WHEEL 0x2121
2045 #define CMD_HIRES_WHEEL_GET_WHEEL_CAPABILITY 0x00
2046 #define CMD_HIRES_WHEEL_SET_WHEEL_MODE 0x20
2048 static int hidpp_hrw_get_wheel_capability(struct hidpp_device
*hidpp
,
2054 struct hidpp_report response
;
2056 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_HIRES_WHEEL
,
2057 &feature_index
, &feature_type
);
2059 goto return_default
;
2061 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
2062 CMD_HIRES_WHEEL_GET_WHEEL_CAPABILITY
,
2063 NULL
, 0, &response
);
2065 goto return_default
;
2067 *multiplier
= response
.fap
.params
[0];
2070 hid_warn(hidpp
->hid_dev
,
2071 "Couldn't get wheel multiplier (error %d)\n", ret
);
2075 static int hidpp_hrw_set_wheel_mode(struct hidpp_device
*hidpp
, bool invert
,
2076 bool high_resolution
, bool use_hidpp
)
2082 struct hidpp_report response
;
2084 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_HIRES_WHEEL
,
2085 &feature_index
, &feature_type
);
2089 params
[0] = (invert
? BIT(2) : 0) |
2090 (high_resolution
? BIT(1) : 0) |
2091 (use_hidpp
? BIT(0) : 0);
2093 return hidpp_send_fap_command_sync(hidpp
, feature_index
,
2094 CMD_HIRES_WHEEL_SET_WHEEL_MODE
,
2095 params
, sizeof(params
), &response
);
2098 /* -------------------------------------------------------------------------- */
2099 /* 0x4301: Solar Keyboard */
2100 /* -------------------------------------------------------------------------- */
2102 #define HIDPP_PAGE_SOLAR_KEYBOARD 0x4301
2104 #define CMD_SOLAR_SET_LIGHT_MEASURE 0x00
2106 #define EVENT_SOLAR_BATTERY_BROADCAST 0x00
2107 #define EVENT_SOLAR_BATTERY_LIGHT_MEASURE 0x10
2108 #define EVENT_SOLAR_CHECK_LIGHT_BUTTON 0x20
2110 static int hidpp_solar_request_battery_event(struct hidpp_device
*hidpp
)
2112 struct hidpp_report response
;
2113 u8 params
[2] = { 1, 1 };
2117 if (hidpp
->battery
.feature_index
== 0xff) {
2118 ret
= hidpp_root_get_feature(hidpp
,
2119 HIDPP_PAGE_SOLAR_KEYBOARD
,
2120 &hidpp
->battery
.solar_feature_index
,
2126 ret
= hidpp_send_fap_command_sync(hidpp
,
2127 hidpp
->battery
.solar_feature_index
,
2128 CMD_SOLAR_SET_LIGHT_MEASURE
,
2129 params
, 2, &response
);
2131 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
2138 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_MILEAGE
;
2143 static int hidpp_solar_battery_event(struct hidpp_device
*hidpp
,
2146 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
2147 int capacity
, lux
, status
;
2150 function
= report
->fap
.funcindex_clientid
;
2153 if (report
->fap
.feature_index
!= hidpp
->battery
.solar_feature_index
||
2154 !(function
== EVENT_SOLAR_BATTERY_BROADCAST
||
2155 function
== EVENT_SOLAR_BATTERY_LIGHT_MEASURE
||
2156 function
== EVENT_SOLAR_CHECK_LIGHT_BUTTON
))
2159 capacity
= report
->fap
.params
[0];
2162 case EVENT_SOLAR_BATTERY_LIGHT_MEASURE
:
2163 lux
= (report
->fap
.params
[1] << 8) | report
->fap
.params
[2];
2165 status
= POWER_SUPPLY_STATUS_CHARGING
;
2167 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
2169 case EVENT_SOLAR_CHECK_LIGHT_BUTTON
:
2171 if (capacity
< hidpp
->battery
.capacity
)
2172 status
= POWER_SUPPLY_STATUS_DISCHARGING
;
2174 status
= POWER_SUPPLY_STATUS_CHARGING
;
2178 if (capacity
== 100)
2179 status
= POWER_SUPPLY_STATUS_FULL
;
2181 hidpp
->battery
.online
= true;
2182 if (capacity
!= hidpp
->battery
.capacity
||
2183 status
!= hidpp
->battery
.status
) {
2184 hidpp
->battery
.capacity
= capacity
;
2185 hidpp
->battery
.status
= status
;
2186 if (hidpp
->battery
.ps
)
2187 power_supply_changed(hidpp
->battery
.ps
);
2193 /* -------------------------------------------------------------------------- */
2194 /* 0x6010: Touchpad FW items */
2195 /* -------------------------------------------------------------------------- */
2197 #define HIDPP_PAGE_TOUCHPAD_FW_ITEMS 0x6010
2199 #define CMD_TOUCHPAD_FW_ITEMS_SET 0x10
2201 struct hidpp_touchpad_fw_items
{
2203 uint8_t desired_state
;
2209 * send a set state command to the device by reading the current items->state
2210 * field. items is then filled with the current state.
2212 static int hidpp_touchpad_fw_items_set(struct hidpp_device
*hidpp
,
2214 struct hidpp_touchpad_fw_items
*items
)
2216 struct hidpp_report response
;
2218 u8
*params
= (u8
*)response
.fap
.params
;
2220 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
2221 CMD_TOUCHPAD_FW_ITEMS_SET
, &items
->state
, 1, &response
);
2224 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
2231 items
->presence
= params
[0];
2232 items
->desired_state
= params
[1];
2233 items
->state
= params
[2];
2234 items
->persistent
= params
[3];
2239 /* -------------------------------------------------------------------------- */
2240 /* 0x6100: TouchPadRawXY */
2241 /* -------------------------------------------------------------------------- */
2243 #define HIDPP_PAGE_TOUCHPAD_RAW_XY 0x6100
2245 #define CMD_TOUCHPAD_GET_RAW_INFO 0x00
2246 #define CMD_TOUCHPAD_SET_RAW_REPORT_STATE 0x20
2248 #define EVENT_TOUCHPAD_RAW_XY 0x00
2250 #define TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT 0x01
2251 #define TOUCHPAD_RAW_XY_ORIGIN_UPPER_LEFT 0x03
2253 struct hidpp_touchpad_raw_info
{
2264 struct hidpp_touchpad_raw_xy_finger
{
2274 struct hidpp_touchpad_raw_xy
{
2276 struct hidpp_touchpad_raw_xy_finger fingers
[2];
2283 static int hidpp_touchpad_get_raw_info(struct hidpp_device
*hidpp
,
2284 u8 feature_index
, struct hidpp_touchpad_raw_info
*raw_info
)
2286 struct hidpp_report response
;
2288 u8
*params
= (u8
*)response
.fap
.params
;
2290 ret
= hidpp_send_fap_command_sync(hidpp
, feature_index
,
2291 CMD_TOUCHPAD_GET_RAW_INFO
, NULL
, 0, &response
);
2294 hid_err(hidpp
->hid_dev
, "%s: received protocol error 0x%02x\n",
2301 raw_info
->x_size
= get_unaligned_be16(¶ms
[0]);
2302 raw_info
->y_size
= get_unaligned_be16(¶ms
[2]);
2303 raw_info
->z_range
= params
[4];
2304 raw_info
->area_range
= params
[5];
2305 raw_info
->maxcontacts
= params
[7];
2306 raw_info
->origin
= params
[8];
2307 /* res is given in unit per inch */
2308 raw_info
->res
= get_unaligned_be16(¶ms
[13]) * 2 / 51;
2313 static int hidpp_touchpad_set_raw_report_state(struct hidpp_device
*hidpp_dev
,
2314 u8 feature_index
, bool send_raw_reports
,
2315 bool sensor_enhanced_settings
)
2317 struct hidpp_report response
;
2321 * bit 0 - enable raw
2322 * bit 1 - 16bit Z, no area
2323 * bit 2 - enhanced sensitivity
2324 * bit 3 - width, height (4 bits each) instead of area
2325 * bit 4 - send raw + gestures (degrades smoothness)
2326 * remaining bits - reserved
2328 u8 params
= send_raw_reports
| (sensor_enhanced_settings
<< 2);
2330 return hidpp_send_fap_command_sync(hidpp_dev
, feature_index
,
2331 CMD_TOUCHPAD_SET_RAW_REPORT_STATE
, ¶ms
, 1, &response
);
2334 static void hidpp_touchpad_touch_event(u8
*data
,
2335 struct hidpp_touchpad_raw_xy_finger
*finger
)
2337 u8 x_m
= data
[0] << 2;
2338 u8 y_m
= data
[2] << 2;
2340 finger
->x
= x_m
<< 6 | data
[1];
2341 finger
->y
= y_m
<< 6 | data
[3];
2343 finger
->contact_type
= data
[0] >> 6;
2344 finger
->contact_status
= data
[2] >> 6;
2346 finger
->z
= data
[4];
2347 finger
->area
= data
[5];
2348 finger
->finger_id
= data
[6] >> 4;
2351 static void hidpp_touchpad_raw_xy_event(struct hidpp_device
*hidpp_dev
,
2352 u8
*data
, struct hidpp_touchpad_raw_xy
*raw_xy
)
2354 memset(raw_xy
, 0, sizeof(struct hidpp_touchpad_raw_xy
));
2355 raw_xy
->end_of_frame
= data
[8] & 0x01;
2356 raw_xy
->spurious_flag
= (data
[8] >> 1) & 0x01;
2357 raw_xy
->finger_count
= data
[15] & 0x0f;
2358 raw_xy
->button
= (data
[8] >> 2) & 0x01;
2360 if (raw_xy
->finger_count
) {
2361 hidpp_touchpad_touch_event(&data
[2], &raw_xy
->fingers
[0]);
2362 hidpp_touchpad_touch_event(&data
[9], &raw_xy
->fingers
[1]);
2366 /* -------------------------------------------------------------------------- */
2367 /* 0x8123: Force feedback support */
2368 /* -------------------------------------------------------------------------- */
2370 #define HIDPP_FF_GET_INFO 0x01
2371 #define HIDPP_FF_RESET_ALL 0x11
2372 #define HIDPP_FF_DOWNLOAD_EFFECT 0x21
2373 #define HIDPP_FF_SET_EFFECT_STATE 0x31
2374 #define HIDPP_FF_DESTROY_EFFECT 0x41
2375 #define HIDPP_FF_GET_APERTURE 0x51
2376 #define HIDPP_FF_SET_APERTURE 0x61
2377 #define HIDPP_FF_GET_GLOBAL_GAINS 0x71
2378 #define HIDPP_FF_SET_GLOBAL_GAINS 0x81
2380 #define HIDPP_FF_EFFECT_STATE_GET 0x00
2381 #define HIDPP_FF_EFFECT_STATE_STOP 0x01
2382 #define HIDPP_FF_EFFECT_STATE_PLAY 0x02
2383 #define HIDPP_FF_EFFECT_STATE_PAUSE 0x03
2385 #define HIDPP_FF_EFFECT_CONSTANT 0x00
2386 #define HIDPP_FF_EFFECT_PERIODIC_SINE 0x01
2387 #define HIDPP_FF_EFFECT_PERIODIC_SQUARE 0x02
2388 #define HIDPP_FF_EFFECT_PERIODIC_TRIANGLE 0x03
2389 #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP 0x04
2390 #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN 0x05
2391 #define HIDPP_FF_EFFECT_SPRING 0x06
2392 #define HIDPP_FF_EFFECT_DAMPER 0x07
2393 #define HIDPP_FF_EFFECT_FRICTION 0x08
2394 #define HIDPP_FF_EFFECT_INERTIA 0x09
2395 #define HIDPP_FF_EFFECT_RAMP 0x0A
2397 #define HIDPP_FF_EFFECT_AUTOSTART 0x80
2399 #define HIDPP_FF_EFFECTID_NONE -1
2400 #define HIDPP_FF_EFFECTID_AUTOCENTER -2
2401 #define HIDPP_AUTOCENTER_PARAMS_LENGTH 18
2403 #define HIDPP_FF_MAX_PARAMS 20
2404 #define HIDPP_FF_RESERVED_SLOTS 1
2406 struct hidpp_ff_private_data
{
2407 struct hidpp_device
*hidpp
;
2415 struct workqueue_struct
*wq
;
2416 atomic_t workqueue_size
;
2419 struct hidpp_ff_work_data
{
2420 struct work_struct work
;
2421 struct hidpp_ff_private_data
*data
;
2424 u8 params
[HIDPP_FF_MAX_PARAMS
];
2428 static const signed short hidpp_ff_effects
[] = {
2443 static const signed short hidpp_ff_effects_v2
[] = {
2450 static const u8 HIDPP_FF_CONDITION_CMDS
[] = {
2451 HIDPP_FF_EFFECT_SPRING
,
2452 HIDPP_FF_EFFECT_FRICTION
,
2453 HIDPP_FF_EFFECT_DAMPER
,
2454 HIDPP_FF_EFFECT_INERTIA
2457 static const char *HIDPP_FF_CONDITION_NAMES
[] = {
2465 static u8
hidpp_ff_find_effect(struct hidpp_ff_private_data
*data
, int effect_id
)
2469 for (i
= 0; i
< data
->num_effects
; i
++)
2470 if (data
->effect_ids
[i
] == effect_id
)
2476 static void hidpp_ff_work_handler(struct work_struct
*w
)
2478 struct hidpp_ff_work_data
*wd
= container_of(w
, struct hidpp_ff_work_data
, work
);
2479 struct hidpp_ff_private_data
*data
= wd
->data
;
2480 struct hidpp_report response
;
2484 /* add slot number if needed */
2485 switch (wd
->effect_id
) {
2486 case HIDPP_FF_EFFECTID_AUTOCENTER
:
2487 wd
->params
[0] = data
->slot_autocenter
;
2489 case HIDPP_FF_EFFECTID_NONE
:
2490 /* leave slot as zero */
2493 /* find current slot for effect */
2494 wd
->params
[0] = hidpp_ff_find_effect(data
, wd
->effect_id
);
2498 /* send command and wait for reply */
2499 ret
= hidpp_send_fap_command_sync(data
->hidpp
, data
->feature_index
,
2500 wd
->command
, wd
->params
, wd
->size
, &response
);
2503 hid_err(data
->hidpp
->hid_dev
, "Failed to send command to device!\n");
2507 /* parse return data */
2508 switch (wd
->command
) {
2509 case HIDPP_FF_DOWNLOAD_EFFECT
:
2510 slot
= response
.fap
.params
[0];
2511 if (slot
> 0 && slot
<= data
->num_effects
) {
2512 if (wd
->effect_id
>= 0)
2513 /* regular effect uploaded */
2514 data
->effect_ids
[slot
-1] = wd
->effect_id
;
2515 else if (wd
->effect_id
>= HIDPP_FF_EFFECTID_AUTOCENTER
)
2516 /* autocenter spring uploaded */
2517 data
->slot_autocenter
= slot
;
2520 case HIDPP_FF_DESTROY_EFFECT
:
2521 if (wd
->effect_id
>= 0)
2522 /* regular effect destroyed */
2523 data
->effect_ids
[wd
->params
[0]-1] = -1;
2524 else if (wd
->effect_id
>= HIDPP_FF_EFFECTID_AUTOCENTER
)
2525 /* autocenter spring destoyed */
2526 data
->slot_autocenter
= 0;
2528 case HIDPP_FF_SET_GLOBAL_GAINS
:
2529 data
->gain
= (wd
->params
[0] << 8) + wd
->params
[1];
2531 case HIDPP_FF_SET_APERTURE
:
2532 data
->range
= (wd
->params
[0] << 8) + wd
->params
[1];
2535 /* no action needed */
2540 atomic_dec(&data
->workqueue_size
);
2544 static int hidpp_ff_queue_work(struct hidpp_ff_private_data
*data
, int effect_id
, u8 command
, u8
*params
, u8 size
)
2546 struct hidpp_ff_work_data
*wd
= kzalloc(sizeof(*wd
), GFP_KERNEL
);
2552 INIT_WORK(&wd
->work
, hidpp_ff_work_handler
);
2555 wd
->effect_id
= effect_id
;
2556 wd
->command
= command
;
2558 memcpy(wd
->params
, params
, size
);
2560 s
= atomic_inc_return(&data
->workqueue_size
);
2561 queue_work(data
->wq
, &wd
->work
);
2563 /* warn about excessive queue size */
2564 if (s
>= 20 && s
% 20 == 0)
2565 hid_warn(data
->hidpp
->hid_dev
, "Force feedback command queue contains %d commands, causing substantial delays!", s
);
2570 static int hidpp_ff_upload_effect(struct input_dev
*dev
, struct ff_effect
*effect
, struct ff_effect
*old
)
2572 struct hidpp_ff_private_data
*data
= dev
->ff
->private;
2577 /* set common parameters */
2578 params
[2] = effect
->replay
.length
>> 8;
2579 params
[3] = effect
->replay
.length
& 255;
2580 params
[4] = effect
->replay
.delay
>> 8;
2581 params
[5] = effect
->replay
.delay
& 255;
2583 switch (effect
->type
) {
2585 force
= (effect
->u
.constant
.level
* fixp_sin16((effect
->direction
* 360) >> 16)) >> 15;
2586 params
[1] = HIDPP_FF_EFFECT_CONSTANT
;
2587 params
[6] = force
>> 8;
2588 params
[7] = force
& 255;
2589 params
[8] = effect
->u
.constant
.envelope
.attack_level
>> 7;
2590 params
[9] = effect
->u
.constant
.envelope
.attack_length
>> 8;
2591 params
[10] = effect
->u
.constant
.envelope
.attack_length
& 255;
2592 params
[11] = effect
->u
.constant
.envelope
.fade_level
>> 7;
2593 params
[12] = effect
->u
.constant
.envelope
.fade_length
>> 8;
2594 params
[13] = effect
->u
.constant
.envelope
.fade_length
& 255;
2596 dbg_hid("Uploading constant force level=%d in dir %d = %d\n",
2597 effect
->u
.constant
.level
,
2598 effect
->direction
, force
);
2599 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
2600 effect
->u
.constant
.envelope
.attack_level
,
2601 effect
->u
.constant
.envelope
.attack_length
,
2602 effect
->u
.constant
.envelope
.fade_level
,
2603 effect
->u
.constant
.envelope
.fade_length
);
2607 switch (effect
->u
.periodic
.waveform
) {
2609 params
[1] = HIDPP_FF_EFFECT_PERIODIC_SINE
;
2612 params
[1] = HIDPP_FF_EFFECT_PERIODIC_SQUARE
;
2615 params
[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP
;
2618 params
[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN
;
2621 params
[1] = HIDPP_FF_EFFECT_PERIODIC_TRIANGLE
;
2624 hid_err(data
->hidpp
->hid_dev
, "Unexpected periodic waveform type %i!\n", effect
->u
.periodic
.waveform
);
2627 force
= (effect
->u
.periodic
.magnitude
* fixp_sin16((effect
->direction
* 360) >> 16)) >> 15;
2628 params
[6] = effect
->u
.periodic
.magnitude
>> 8;
2629 params
[7] = effect
->u
.periodic
.magnitude
& 255;
2630 params
[8] = effect
->u
.periodic
.offset
>> 8;
2631 params
[9] = effect
->u
.periodic
.offset
& 255;
2632 params
[10] = effect
->u
.periodic
.period
>> 8;
2633 params
[11] = effect
->u
.periodic
.period
& 255;
2634 params
[12] = effect
->u
.periodic
.phase
>> 8;
2635 params
[13] = effect
->u
.periodic
.phase
& 255;
2636 params
[14] = effect
->u
.periodic
.envelope
.attack_level
>> 7;
2637 params
[15] = effect
->u
.periodic
.envelope
.attack_length
>> 8;
2638 params
[16] = effect
->u
.periodic
.envelope
.attack_length
& 255;
2639 params
[17] = effect
->u
.periodic
.envelope
.fade_level
>> 7;
2640 params
[18] = effect
->u
.periodic
.envelope
.fade_length
>> 8;
2641 params
[19] = effect
->u
.periodic
.envelope
.fade_length
& 255;
2643 dbg_hid("Uploading periodic force mag=%d/dir=%d, offset=%d, period=%d ms, phase=%d\n",
2644 effect
->u
.periodic
.magnitude
, effect
->direction
,
2645 effect
->u
.periodic
.offset
,
2646 effect
->u
.periodic
.period
,
2647 effect
->u
.periodic
.phase
);
2648 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
2649 effect
->u
.periodic
.envelope
.attack_level
,
2650 effect
->u
.periodic
.envelope
.attack_length
,
2651 effect
->u
.periodic
.envelope
.fade_level
,
2652 effect
->u
.periodic
.envelope
.fade_length
);
2656 params
[1] = HIDPP_FF_EFFECT_RAMP
;
2657 force
= (effect
->u
.ramp
.start_level
* fixp_sin16((effect
->direction
* 360) >> 16)) >> 15;
2658 params
[6] = force
>> 8;
2659 params
[7] = force
& 255;
2660 force
= (effect
->u
.ramp
.end_level
* fixp_sin16((effect
->direction
* 360) >> 16)) >> 15;
2661 params
[8] = force
>> 8;
2662 params
[9] = force
& 255;
2663 params
[10] = effect
->u
.ramp
.envelope
.attack_level
>> 7;
2664 params
[11] = effect
->u
.ramp
.envelope
.attack_length
>> 8;
2665 params
[12] = effect
->u
.ramp
.envelope
.attack_length
& 255;
2666 params
[13] = effect
->u
.ramp
.envelope
.fade_level
>> 7;
2667 params
[14] = effect
->u
.ramp
.envelope
.fade_length
>> 8;
2668 params
[15] = effect
->u
.ramp
.envelope
.fade_length
& 255;
2670 dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n",
2671 effect
->u
.ramp
.start_level
,
2672 effect
->u
.ramp
.end_level
,
2673 effect
->direction
, force
);
2674 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
2675 effect
->u
.ramp
.envelope
.attack_level
,
2676 effect
->u
.ramp
.envelope
.attack_length
,
2677 effect
->u
.ramp
.envelope
.fade_level
,
2678 effect
->u
.ramp
.envelope
.fade_length
);
2684 params
[1] = HIDPP_FF_CONDITION_CMDS
[effect
->type
- FF_SPRING
];
2685 params
[6] = effect
->u
.condition
[0].left_saturation
>> 9;
2686 params
[7] = (effect
->u
.condition
[0].left_saturation
>> 1) & 255;
2687 params
[8] = effect
->u
.condition
[0].left_coeff
>> 8;
2688 params
[9] = effect
->u
.condition
[0].left_coeff
& 255;
2689 params
[10] = effect
->u
.condition
[0].deadband
>> 9;
2690 params
[11] = (effect
->u
.condition
[0].deadband
>> 1) & 255;
2691 params
[12] = effect
->u
.condition
[0].center
>> 8;
2692 params
[13] = effect
->u
.condition
[0].center
& 255;
2693 params
[14] = effect
->u
.condition
[0].right_coeff
>> 8;
2694 params
[15] = effect
->u
.condition
[0].right_coeff
& 255;
2695 params
[16] = effect
->u
.condition
[0].right_saturation
>> 9;
2696 params
[17] = (effect
->u
.condition
[0].right_saturation
>> 1) & 255;
2698 dbg_hid("Uploading %s force left coeff=%d, left sat=%d, right coeff=%d, right sat=%d\n",
2699 HIDPP_FF_CONDITION_NAMES
[effect
->type
- FF_SPRING
],
2700 effect
->u
.condition
[0].left_coeff
,
2701 effect
->u
.condition
[0].left_saturation
,
2702 effect
->u
.condition
[0].right_coeff
,
2703 effect
->u
.condition
[0].right_saturation
);
2704 dbg_hid(" deadband=%d, center=%d\n",
2705 effect
->u
.condition
[0].deadband
,
2706 effect
->u
.condition
[0].center
);
2709 hid_err(data
->hidpp
->hid_dev
, "Unexpected force type %i!\n", effect
->type
);
2713 return hidpp_ff_queue_work(data
, effect
->id
, HIDPP_FF_DOWNLOAD_EFFECT
, params
, size
);
2716 static int hidpp_ff_playback(struct input_dev
*dev
, int effect_id
, int value
)
2718 struct hidpp_ff_private_data
*data
= dev
->ff
->private;
2721 params
[1] = value
? HIDPP_FF_EFFECT_STATE_PLAY
: HIDPP_FF_EFFECT_STATE_STOP
;
2723 dbg_hid("St%sing playback of effect %d.\n", value
?"art":"opp", effect_id
);
2725 return hidpp_ff_queue_work(data
, effect_id
, HIDPP_FF_SET_EFFECT_STATE
, params
, ARRAY_SIZE(params
));
2728 static int hidpp_ff_erase_effect(struct input_dev
*dev
, int effect_id
)
2730 struct hidpp_ff_private_data
*data
= dev
->ff
->private;
2733 dbg_hid("Erasing effect %d.\n", effect_id
);
2735 return hidpp_ff_queue_work(data
, effect_id
, HIDPP_FF_DESTROY_EFFECT
, &slot
, 1);
2738 static void hidpp_ff_set_autocenter(struct input_dev
*dev
, u16 magnitude
)
2740 struct hidpp_ff_private_data
*data
= dev
->ff
->private;
2741 u8 params
[HIDPP_AUTOCENTER_PARAMS_LENGTH
];
2743 dbg_hid("Setting autocenter to %d.\n", magnitude
);
2745 /* start a standard spring effect */
2746 params
[1] = HIDPP_FF_EFFECT_SPRING
| HIDPP_FF_EFFECT_AUTOSTART
;
2747 /* zero delay and duration */
2748 params
[2] = params
[3] = params
[4] = params
[5] = 0;
2749 /* set coeff to 25% of saturation */
2750 params
[8] = params
[14] = magnitude
>> 11;
2751 params
[9] = params
[15] = (magnitude
>> 3) & 255;
2752 params
[6] = params
[16] = magnitude
>> 9;
2753 params
[7] = params
[17] = (magnitude
>> 1) & 255;
2754 /* zero deadband and center */
2755 params
[10] = params
[11] = params
[12] = params
[13] = 0;
2757 hidpp_ff_queue_work(data
, HIDPP_FF_EFFECTID_AUTOCENTER
, HIDPP_FF_DOWNLOAD_EFFECT
, params
, ARRAY_SIZE(params
));
2760 static void hidpp_ff_set_gain(struct input_dev
*dev
, u16 gain
)
2762 struct hidpp_ff_private_data
*data
= dev
->ff
->private;
2765 dbg_hid("Setting gain to %d.\n", gain
);
2767 params
[0] = gain
>> 8;
2768 params
[1] = gain
& 255;
2769 params
[2] = 0; /* no boost */
2772 hidpp_ff_queue_work(data
, HIDPP_FF_EFFECTID_NONE
, HIDPP_FF_SET_GLOBAL_GAINS
, params
, ARRAY_SIZE(params
));
2775 static ssize_t
hidpp_ff_range_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2777 struct hid_device
*hid
= to_hid_device(dev
);
2778 struct hid_input
*hidinput
= list_entry(hid
->inputs
.next
, struct hid_input
, list
);
2779 struct input_dev
*idev
= hidinput
->input
;
2780 struct hidpp_ff_private_data
*data
= idev
->ff
->private;
2782 return scnprintf(buf
, PAGE_SIZE
, "%u\n", data
->range
);
2785 static ssize_t
hidpp_ff_range_store(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
2787 struct hid_device
*hid
= to_hid_device(dev
);
2788 struct hid_input
*hidinput
= list_entry(hid
->inputs
.next
, struct hid_input
, list
);
2789 struct input_dev
*idev
= hidinput
->input
;
2790 struct hidpp_ff_private_data
*data
= idev
->ff
->private;
2792 int range
= simple_strtoul(buf
, NULL
, 10);
2794 range
= clamp(range
, 180, 900);
2796 params
[0] = range
>> 8;
2797 params
[1] = range
& 0x00FF;
2799 hidpp_ff_queue_work(data
, -1, HIDPP_FF_SET_APERTURE
, params
, ARRAY_SIZE(params
));
2804 static DEVICE_ATTR(range
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
, hidpp_ff_range_show
, hidpp_ff_range_store
);
2806 static void hidpp_ff_destroy(struct ff_device
*ff
)
2808 struct hidpp_ff_private_data
*data
= ff
->private;
2809 struct hid_device
*hid
= data
->hidpp
->hid_dev
;
2811 hid_info(hid
, "Unloading HID++ force feedback.\n");
2813 device_remove_file(&hid
->dev
, &dev_attr_range
);
2814 destroy_workqueue(data
->wq
);
2815 kfree(data
->effect_ids
);
2818 static int hidpp_ff_init(struct hidpp_device
*hidpp
,
2819 struct hidpp_ff_private_data
*data
)
2821 struct hid_device
*hid
= hidpp
->hid_dev
;
2822 struct hid_input
*hidinput
;
2823 struct input_dev
*dev
;
2824 struct usb_device_descriptor
*udesc
;
2826 struct ff_device
*ff
;
2827 int error
, j
, num_slots
= data
->num_effects
;
2830 if (!hid_is_usb(hid
)) {
2831 hid_err(hid
, "device is not USB\n");
2835 if (list_empty(&hid
->inputs
)) {
2836 hid_err(hid
, "no inputs found\n");
2839 hidinput
= list_entry(hid
->inputs
.next
, struct hid_input
, list
);
2840 dev
= hidinput
->input
;
2843 hid_err(hid
, "Struct input_dev not set!\n");
2847 /* Get firmware release */
2848 udesc
= &(hid_to_usb_dev(hid
)->descriptor
);
2849 bcdDevice
= le16_to_cpu(udesc
->bcdDevice
);
2850 version
= bcdDevice
& 255;
2852 /* Set supported force feedback capabilities */
2853 for (j
= 0; hidpp_ff_effects
[j
] >= 0; j
++)
2854 set_bit(hidpp_ff_effects
[j
], dev
->ffbit
);
2856 for (j
= 0; hidpp_ff_effects_v2
[j
] >= 0; j
++)
2857 set_bit(hidpp_ff_effects_v2
[j
], dev
->ffbit
);
2859 error
= input_ff_create(dev
, num_slots
);
2862 hid_err(dev
, "Failed to create FF device!\n");
2866 * Create a copy of passed data, so we can transfer memory
2867 * ownership to FF core
2869 data
= kmemdup(data
, sizeof(*data
), GFP_KERNEL
);
2872 data
->effect_ids
= kcalloc(num_slots
, sizeof(int), GFP_KERNEL
);
2873 if (!data
->effect_ids
) {
2877 data
->wq
= create_singlethread_workqueue("hidpp-ff-sendqueue");
2879 kfree(data
->effect_ids
);
2884 data
->hidpp
= hidpp
;
2885 data
->version
= version
;
2886 for (j
= 0; j
< num_slots
; j
++)
2887 data
->effect_ids
[j
] = -1;
2892 ff
->upload
= hidpp_ff_upload_effect
;
2893 ff
->erase
= hidpp_ff_erase_effect
;
2894 ff
->playback
= hidpp_ff_playback
;
2895 ff
->set_gain
= hidpp_ff_set_gain
;
2896 ff
->set_autocenter
= hidpp_ff_set_autocenter
;
2897 ff
->destroy
= hidpp_ff_destroy
;
2899 /* Create sysfs interface */
2900 error
= device_create_file(&(hidpp
->hid_dev
->dev
), &dev_attr_range
);
2902 hid_warn(hidpp
->hid_dev
, "Unable to create sysfs interface for \"range\", errno %d!\n", error
);
2904 /* init the hardware command queue */
2905 atomic_set(&data
->workqueue_size
, 0);
2907 hid_info(hid
, "Force feedback support loaded (firmware release %d).\n",
2913 /* ************************************************************************** */
2915 /* Device Support */
2917 /* ************************************************************************** */
2919 /* -------------------------------------------------------------------------- */
2920 /* Touchpad HID++ devices */
2921 /* -------------------------------------------------------------------------- */
2923 #define WTP_MANUAL_RESOLUTION 39
2928 u8 mt_feature_index
;
2929 u8 button_feature_index
;
2932 unsigned int resolution
;
2935 static int wtp_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
2936 struct hid_field
*field
, struct hid_usage
*usage
,
2937 unsigned long **bit
, int *max
)
2942 static void wtp_populate_input(struct hidpp_device
*hidpp
,
2943 struct input_dev
*input_dev
)
2945 struct wtp_data
*wd
= hidpp
->private_data
;
2947 __set_bit(EV_ABS
, input_dev
->evbit
);
2948 __set_bit(EV_KEY
, input_dev
->evbit
);
2949 __clear_bit(EV_REL
, input_dev
->evbit
);
2950 __clear_bit(EV_LED
, input_dev
->evbit
);
2952 input_set_abs_params(input_dev
, ABS_MT_POSITION_X
, 0, wd
->x_size
, 0, 0);
2953 input_abs_set_res(input_dev
, ABS_MT_POSITION_X
, wd
->resolution
);
2954 input_set_abs_params(input_dev
, ABS_MT_POSITION_Y
, 0, wd
->y_size
, 0, 0);
2955 input_abs_set_res(input_dev
, ABS_MT_POSITION_Y
, wd
->resolution
);
2957 /* Max pressure is not given by the devices, pick one */
2958 input_set_abs_params(input_dev
, ABS_MT_PRESSURE
, 0, 50, 0, 0);
2960 input_set_capability(input_dev
, EV_KEY
, BTN_LEFT
);
2962 if (hidpp
->quirks
& HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS
)
2963 input_set_capability(input_dev
, EV_KEY
, BTN_RIGHT
);
2965 __set_bit(INPUT_PROP_BUTTONPAD
, input_dev
->propbit
);
2967 input_mt_init_slots(input_dev
, wd
->maxcontacts
, INPUT_MT_POINTER
|
2968 INPUT_MT_DROP_UNUSED
);
2971 static void wtp_touch_event(struct hidpp_device
*hidpp
,
2972 struct hidpp_touchpad_raw_xy_finger
*touch_report
)
2974 struct wtp_data
*wd
= hidpp
->private_data
;
2977 if (!touch_report
->finger_id
|| touch_report
->contact_type
)
2978 /* no actual data */
2981 slot
= input_mt_get_slot_by_key(hidpp
->input
, touch_report
->finger_id
);
2983 input_mt_slot(hidpp
->input
, slot
);
2984 input_mt_report_slot_state(hidpp
->input
, MT_TOOL_FINGER
,
2985 touch_report
->contact_status
);
2986 if (touch_report
->contact_status
) {
2987 input_event(hidpp
->input
, EV_ABS
, ABS_MT_POSITION_X
,
2989 input_event(hidpp
->input
, EV_ABS
, ABS_MT_POSITION_Y
,
2990 wd
->flip_y
? wd
->y_size
- touch_report
->y
:
2992 input_event(hidpp
->input
, EV_ABS
, ABS_MT_PRESSURE
,
2993 touch_report
->area
);
2997 static void wtp_send_raw_xy_event(struct hidpp_device
*hidpp
,
2998 struct hidpp_touchpad_raw_xy
*raw
)
3002 for (i
= 0; i
< 2; i
++)
3003 wtp_touch_event(hidpp
, &(raw
->fingers
[i
]));
3005 if (raw
->end_of_frame
&&
3006 !(hidpp
->quirks
& HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS
))
3007 input_event(hidpp
->input
, EV_KEY
, BTN_LEFT
, raw
->button
);
3009 if (raw
->end_of_frame
|| raw
->finger_count
<= 2) {
3010 input_mt_sync_frame(hidpp
->input
);
3011 input_sync(hidpp
->input
);
3015 static int wtp_mouse_raw_xy_event(struct hidpp_device
*hidpp
, u8
*data
)
3017 struct wtp_data
*wd
= hidpp
->private_data
;
3018 u8 c1_area
= ((data
[7] & 0xf) * (data
[7] & 0xf) +
3019 (data
[7] >> 4) * (data
[7] >> 4)) / 2;
3020 u8 c2_area
= ((data
[13] & 0xf) * (data
[13] & 0xf) +
3021 (data
[13] >> 4) * (data
[13] >> 4)) / 2;
3022 struct hidpp_touchpad_raw_xy raw
= {
3023 .timestamp
= data
[1],
3027 .contact_status
= !!data
[7],
3028 .x
= get_unaligned_le16(&data
[3]),
3029 .y
= get_unaligned_le16(&data
[5]),
3032 .finger_id
= data
[2],
3035 .contact_status
= !!data
[13],
3036 .x
= get_unaligned_le16(&data
[9]),
3037 .y
= get_unaligned_le16(&data
[11]),
3040 .finger_id
= data
[8],
3043 .finger_count
= wd
->maxcontacts
,
3045 .end_of_frame
= (data
[0] >> 7) == 0,
3046 .button
= data
[0] & 0x01,
3049 wtp_send_raw_xy_event(hidpp
, &raw
);
3054 static int wtp_raw_event(struct hid_device
*hdev
, u8
*data
, int size
)
3056 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3057 struct wtp_data
*wd
= hidpp
->private_data
;
3058 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
3059 struct hidpp_touchpad_raw_xy raw
;
3061 if (!wd
|| !hidpp
->input
)
3067 hid_err(hdev
, "Received HID report of bad size (%d)",
3071 if (hidpp
->quirks
& HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS
) {
3072 input_event(hidpp
->input
, EV_KEY
, BTN_LEFT
,
3073 !!(data
[1] & 0x01));
3074 input_event(hidpp
->input
, EV_KEY
, BTN_RIGHT
,
3075 !!(data
[1] & 0x02));
3076 input_sync(hidpp
->input
);
3081 return wtp_mouse_raw_xy_event(hidpp
, &data
[7]);
3083 case REPORT_ID_HIDPP_LONG
:
3084 /* size is already checked in hidpp_raw_event. */
3085 if ((report
->fap
.feature_index
!= wd
->mt_feature_index
) ||
3086 (report
->fap
.funcindex_clientid
!= EVENT_TOUCHPAD_RAW_XY
))
3088 hidpp_touchpad_raw_xy_event(hidpp
, data
+ 4, &raw
);
3090 wtp_send_raw_xy_event(hidpp
, &raw
);
3097 static int wtp_get_config(struct hidpp_device
*hidpp
)
3099 struct wtp_data
*wd
= hidpp
->private_data
;
3100 struct hidpp_touchpad_raw_info raw_info
= {0};
3104 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_TOUCHPAD_RAW_XY
,
3105 &wd
->mt_feature_index
, &feature_type
);
3107 /* means that the device is not powered up */
3110 ret
= hidpp_touchpad_get_raw_info(hidpp
, wd
->mt_feature_index
,
3115 wd
->x_size
= raw_info
.x_size
;
3116 wd
->y_size
= raw_info
.y_size
;
3117 wd
->maxcontacts
= raw_info
.maxcontacts
;
3118 wd
->flip_y
= raw_info
.origin
== TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT
;
3119 wd
->resolution
= raw_info
.res
;
3120 if (!wd
->resolution
)
3121 wd
->resolution
= WTP_MANUAL_RESOLUTION
;
3126 static int wtp_allocate(struct hid_device
*hdev
, const struct hid_device_id
*id
)
3128 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3129 struct wtp_data
*wd
;
3131 wd
= devm_kzalloc(&hdev
->dev
, sizeof(struct wtp_data
),
3136 hidpp
->private_data
= wd
;
3141 static int wtp_connect(struct hid_device
*hdev
)
3143 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3144 struct wtp_data
*wd
= hidpp
->private_data
;
3148 ret
= wtp_get_config(hidpp
);
3150 hid_err(hdev
, "Can not get wtp config: %d\n", ret
);
3155 return hidpp_touchpad_set_raw_report_state(hidpp
, wd
->mt_feature_index
,
3159 /* ------------------------------------------------------------------------- */
3160 /* Logitech M560 devices */
3161 /* ------------------------------------------------------------------------- */
3164 * Logitech M560 protocol overview
3166 * The Logitech M560 mouse, is designed for windows 8. When the middle and/or
3167 * the sides buttons are pressed, it sends some keyboard keys events
3168 * instead of buttons ones.
3169 * To complicate things further, the middle button keys sequence
3170 * is different from the odd press and the even press.
3172 * forward button -> Super_R
3173 * backward button -> Super_L+'d' (press only)
3174 * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
3175 * 2nd time: left-click (press only)
3176 * NB: press-only means that when the button is pressed, the
3177 * KeyPress/ButtonPress and KeyRelease/ButtonRelease events are generated
3178 * together sequentially; instead when the button is released, no event is
3182 * 10<xx>0a 3500af03 (where <xx> is the mouse id),
3183 * the mouse reacts differently:
3184 * - it never sends a keyboard key event
3185 * - for the three mouse button it sends:
3186 * middle button press 11<xx>0a 3500af00...
3187 * side 1 button (forward) press 11<xx>0a 3500b000...
3188 * side 2 button (backward) press 11<xx>0a 3500ae00...
3189 * middle/side1/side2 button release 11<xx>0a 35000000...
3192 static const u8 m560_config_parameter
[] = {0x00, 0xaf, 0x03};
3194 /* how buttons are mapped in the report */
3195 #define M560_MOUSE_BTN_LEFT 0x01
3196 #define M560_MOUSE_BTN_RIGHT 0x02
3197 #define M560_MOUSE_BTN_WHEEL_LEFT 0x08
3198 #define M560_MOUSE_BTN_WHEEL_RIGHT 0x10
3200 #define M560_SUB_ID 0x0a
3201 #define M560_BUTTON_MODE_REGISTER 0x35
3203 static int m560_send_config_command(struct hid_device
*hdev
)
3205 struct hidpp_report response
;
3206 struct hidpp_device
*hidpp_dev
;
3208 hidpp_dev
= hid_get_drvdata(hdev
);
3210 return hidpp_send_rap_command_sync(
3212 REPORT_ID_HIDPP_SHORT
,
3214 M560_BUTTON_MODE_REGISTER
,
3215 (u8
*)m560_config_parameter
,
3216 sizeof(m560_config_parameter
),
3221 static int m560_raw_event(struct hid_device
*hdev
, u8
*data
, int size
)
3223 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3226 if (!hidpp
->input
) {
3227 hid_err(hdev
, "error in parameter\n");
3232 hid_err(hdev
, "error in report\n");
3236 if (data
[0] == REPORT_ID_HIDPP_LONG
&&
3237 data
[2] == M560_SUB_ID
&& data
[6] == 0x00) {
3239 * m560 mouse report for middle, forward and backward button
3242 * data[1] = device-id
3244 * data[5] = 0xaf -> middle
3247 * 0x00 -> release all
3253 input_report_key(hidpp
->input
, BTN_MIDDLE
, 1);
3256 input_report_key(hidpp
->input
, BTN_FORWARD
, 1);
3259 input_report_key(hidpp
->input
, BTN_BACK
, 1);
3262 input_report_key(hidpp
->input
, BTN_BACK
, 0);
3263 input_report_key(hidpp
->input
, BTN_FORWARD
, 0);
3264 input_report_key(hidpp
->input
, BTN_MIDDLE
, 0);
3267 hid_err(hdev
, "error in report\n");
3270 input_sync(hidpp
->input
);
3272 } else if (data
[0] == 0x02) {
3274 * Logitech M560 mouse report
3276 * data[0] = type (0x02)
3277 * data[1..2] = buttons
3284 input_report_key(hidpp
->input
, BTN_LEFT
,
3285 !!(data
[1] & M560_MOUSE_BTN_LEFT
));
3286 input_report_key(hidpp
->input
, BTN_RIGHT
,
3287 !!(data
[1] & M560_MOUSE_BTN_RIGHT
));
3289 if (data
[1] & M560_MOUSE_BTN_WHEEL_LEFT
) {
3290 input_report_rel(hidpp
->input
, REL_HWHEEL
, -1);
3291 input_report_rel(hidpp
->input
, REL_HWHEEL_HI_RES
,
3293 } else if (data
[1] & M560_MOUSE_BTN_WHEEL_RIGHT
) {
3294 input_report_rel(hidpp
->input
, REL_HWHEEL
, 1);
3295 input_report_rel(hidpp
->input
, REL_HWHEEL_HI_RES
,
3299 v
= hid_snto32(hid_field_extract(hdev
, data
+3, 0, 12), 12);
3300 input_report_rel(hidpp
->input
, REL_X
, v
);
3302 v
= hid_snto32(hid_field_extract(hdev
, data
+3, 12, 12), 12);
3303 input_report_rel(hidpp
->input
, REL_Y
, v
);
3305 v
= hid_snto32(data
[6], 8);
3307 hidpp_scroll_counter_handle_scroll(hidpp
->input
,
3308 &hidpp
->vertical_wheel_counter
, v
);
3310 input_sync(hidpp
->input
);
3316 static void m560_populate_input(struct hidpp_device
*hidpp
,
3317 struct input_dev
*input_dev
)
3319 __set_bit(EV_KEY
, input_dev
->evbit
);
3320 __set_bit(BTN_MIDDLE
, input_dev
->keybit
);
3321 __set_bit(BTN_RIGHT
, input_dev
->keybit
);
3322 __set_bit(BTN_LEFT
, input_dev
->keybit
);
3323 __set_bit(BTN_BACK
, input_dev
->keybit
);
3324 __set_bit(BTN_FORWARD
, input_dev
->keybit
);
3326 __set_bit(EV_REL
, input_dev
->evbit
);
3327 __set_bit(REL_X
, input_dev
->relbit
);
3328 __set_bit(REL_Y
, input_dev
->relbit
);
3329 __set_bit(REL_WHEEL
, input_dev
->relbit
);
3330 __set_bit(REL_HWHEEL
, input_dev
->relbit
);
3331 __set_bit(REL_WHEEL_HI_RES
, input_dev
->relbit
);
3332 __set_bit(REL_HWHEEL_HI_RES
, input_dev
->relbit
);
3335 static int m560_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
3336 struct hid_field
*field
, struct hid_usage
*usage
,
3337 unsigned long **bit
, int *max
)
3342 /* ------------------------------------------------------------------------- */
3343 /* Logitech K400 devices */
3344 /* ------------------------------------------------------------------------- */
3347 * The Logitech K400 keyboard has an embedded touchpad which is seen
3348 * as a mouse from the OS point of view. There is a hardware shortcut to disable
3349 * tap-to-click but the setting is not remembered accross reset, annoying some
3352 * We can toggle this feature from the host by using the feature 0x6010:
3356 struct k400_private_data
{
3360 static int k400_disable_tap_to_click(struct hidpp_device
*hidpp
)
3362 struct k400_private_data
*k400
= hidpp
->private_data
;
3363 struct hidpp_touchpad_fw_items items
= {};
3367 if (!k400
->feature_index
) {
3368 ret
= hidpp_root_get_feature(hidpp
,
3369 HIDPP_PAGE_TOUCHPAD_FW_ITEMS
,
3370 &k400
->feature_index
, &feature_type
);
3372 /* means that the device is not powered up */
3376 ret
= hidpp_touchpad_fw_items_set(hidpp
, k400
->feature_index
, &items
);
3383 static int k400_allocate(struct hid_device
*hdev
)
3385 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3386 struct k400_private_data
*k400
;
3388 k400
= devm_kzalloc(&hdev
->dev
, sizeof(struct k400_private_data
),
3393 hidpp
->private_data
= k400
;
3398 static int k400_connect(struct hid_device
*hdev
)
3400 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3402 if (!disable_tap_to_click
)
3405 return k400_disable_tap_to_click(hidpp
);
3408 /* ------------------------------------------------------------------------- */
3409 /* Logitech G920 Driving Force Racing Wheel for Xbox One */
3410 /* ------------------------------------------------------------------------- */
3412 #define HIDPP_PAGE_G920_FORCE_FEEDBACK 0x8123
3414 static int g920_ff_set_autocenter(struct hidpp_device
*hidpp
,
3415 struct hidpp_ff_private_data
*data
)
3417 struct hidpp_report response
;
3418 u8 params
[HIDPP_AUTOCENTER_PARAMS_LENGTH
] = {
3419 [1] = HIDPP_FF_EFFECT_SPRING
| HIDPP_FF_EFFECT_AUTOSTART
,
3423 /* initialize with zero autocenter to get wheel in usable state */
3425 dbg_hid("Setting autocenter to 0.\n");
3426 ret
= hidpp_send_fap_command_sync(hidpp
, data
->feature_index
,
3427 HIDPP_FF_DOWNLOAD_EFFECT
,
3428 params
, ARRAY_SIZE(params
),
3431 hid_warn(hidpp
->hid_dev
, "Failed to autocenter device!\n");
3433 data
->slot_autocenter
= response
.fap
.params
[0];
3438 static int g920_get_config(struct hidpp_device
*hidpp
,
3439 struct hidpp_ff_private_data
*data
)
3441 struct hidpp_report response
;
3445 memset(data
, 0, sizeof(*data
));
3447 /* Find feature and store for later use */
3448 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_G920_FORCE_FEEDBACK
,
3449 &data
->feature_index
, &feature_type
);
3453 /* Read number of slots available in device */
3454 ret
= hidpp_send_fap_command_sync(hidpp
, data
->feature_index
,
3461 hid_err(hidpp
->hid_dev
,
3462 "%s: received protocol error 0x%02x\n", __func__
, ret
);
3466 data
->num_effects
= response
.fap
.params
[0] - HIDPP_FF_RESERVED_SLOTS
;
3468 /* reset all forces */
3469 ret
= hidpp_send_fap_command_sync(hidpp
, data
->feature_index
,
3474 hid_warn(hidpp
->hid_dev
, "Failed to reset all forces!\n");
3476 ret
= hidpp_send_fap_command_sync(hidpp
, data
->feature_index
,
3477 HIDPP_FF_GET_APERTURE
,
3481 hid_warn(hidpp
->hid_dev
,
3482 "Failed to read range from device!\n");
3485 900 : get_unaligned_be16(&response
.fap
.params
[0]);
3487 /* Read the current gain values */
3488 ret
= hidpp_send_fap_command_sync(hidpp
, data
->feature_index
,
3489 HIDPP_FF_GET_GLOBAL_GAINS
,
3493 hid_warn(hidpp
->hid_dev
,
3494 "Failed to read gain values from device!\n");
3496 0xffff : get_unaligned_be16(&response
.fap
.params
[0]);
3498 /* ignore boost value at response.fap.params[2] */
3500 return g920_ff_set_autocenter(hidpp
, data
);
3503 /* -------------------------------------------------------------------------- */
3504 /* Logitech Dinovo Mini keyboard with builtin touchpad */
3505 /* -------------------------------------------------------------------------- */
3506 #define DINOVO_MINI_PRODUCT_ID 0xb30c
3508 static int lg_dinovo_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
3509 struct hid_field
*field
, struct hid_usage
*usage
,
3510 unsigned long **bit
, int *max
)
3512 if ((usage
->hid
& HID_USAGE_PAGE
) != HID_UP_LOGIVENDOR
)
3515 switch (usage
->hid
& HID_USAGE
) {
3516 case 0x00d: lg_map_key_clear(KEY_MEDIA
); break;
3523 /* -------------------------------------------------------------------------- */
3524 /* HID++1.0 devices which use HID++ reports for their wheels */
3525 /* -------------------------------------------------------------------------- */
3526 static int hidpp10_wheel_connect(struct hidpp_device
*hidpp
)
3528 return hidpp10_set_register(hidpp
, HIDPP_REG_ENABLE_REPORTS
, 0,
3529 HIDPP_ENABLE_WHEEL_REPORT
| HIDPP_ENABLE_HWHEEL_REPORT
,
3530 HIDPP_ENABLE_WHEEL_REPORT
| HIDPP_ENABLE_HWHEEL_REPORT
);
3533 static int hidpp10_wheel_raw_event(struct hidpp_device
*hidpp
,
3544 if (data
[0] != REPORT_ID_HIDPP_SHORT
|| data
[2] != HIDPP_SUB_ID_ROLLER
)
3550 input_report_rel(hidpp
->input
, REL_WHEEL
, value
);
3551 input_report_rel(hidpp
->input
, REL_WHEEL_HI_RES
, value
* 120);
3552 input_report_rel(hidpp
->input
, REL_HWHEEL
, hvalue
);
3553 input_report_rel(hidpp
->input
, REL_HWHEEL_HI_RES
, hvalue
* 120);
3554 input_sync(hidpp
->input
);
3559 static void hidpp10_wheel_populate_input(struct hidpp_device
*hidpp
,
3560 struct input_dev
*input_dev
)
3562 __set_bit(EV_REL
, input_dev
->evbit
);
3563 __set_bit(REL_WHEEL
, input_dev
->relbit
);
3564 __set_bit(REL_WHEEL_HI_RES
, input_dev
->relbit
);
3565 __set_bit(REL_HWHEEL
, input_dev
->relbit
);
3566 __set_bit(REL_HWHEEL_HI_RES
, input_dev
->relbit
);
3569 /* -------------------------------------------------------------------------- */
3570 /* HID++1.0 mice which use HID++ reports for extra mouse buttons */
3571 /* -------------------------------------------------------------------------- */
3572 static int hidpp10_extra_mouse_buttons_connect(struct hidpp_device
*hidpp
)
3574 return hidpp10_set_register(hidpp
, HIDPP_REG_ENABLE_REPORTS
, 0,
3575 HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT
,
3576 HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT
);
3579 static int hidpp10_extra_mouse_buttons_raw_event(struct hidpp_device
*hidpp
,
3590 if (data
[0] != REPORT_ID_HIDPP_SHORT
||
3591 data
[2] != HIDPP_SUB_ID_MOUSE_EXTRA_BTNS
)
3595 * Buttons are either delivered through the regular mouse report *or*
3596 * through the extra buttons report. At least for button 6 how it is
3597 * delivered differs per receiver firmware version. Even receivers with
3598 * the same usb-id show different behavior, so we handle both cases.
3600 for (i
= 0; i
< 8; i
++)
3601 input_report_key(hidpp
->input
, BTN_MOUSE
+ i
,
3602 (data
[3] & (1 << i
)));
3604 /* Some mice report events on button 9+, use BTN_MISC */
3605 for (i
= 0; i
< 8; i
++)
3606 input_report_key(hidpp
->input
, BTN_MISC
+ i
,
3607 (data
[4] & (1 << i
)));
3609 input_sync(hidpp
->input
);
3613 static void hidpp10_extra_mouse_buttons_populate_input(
3614 struct hidpp_device
*hidpp
, struct input_dev
*input_dev
)
3616 /* BTN_MOUSE - BTN_MOUSE+7 are set already by the descriptor */
3617 __set_bit(BTN_0
, input_dev
->keybit
);
3618 __set_bit(BTN_1
, input_dev
->keybit
);
3619 __set_bit(BTN_2
, input_dev
->keybit
);
3620 __set_bit(BTN_3
, input_dev
->keybit
);
3621 __set_bit(BTN_4
, input_dev
->keybit
);
3622 __set_bit(BTN_5
, input_dev
->keybit
);
3623 __set_bit(BTN_6
, input_dev
->keybit
);
3624 __set_bit(BTN_7
, input_dev
->keybit
);
3627 /* -------------------------------------------------------------------------- */
3628 /* HID++1.0 kbds which only report 0x10xx consumer usages through sub-id 0x03 */
3629 /* -------------------------------------------------------------------------- */
3631 /* Find the consumer-page input report desc and change Maximums to 0x107f */
3632 static u8
*hidpp10_consumer_keys_report_fixup(struct hidpp_device
*hidpp
,
3633 u8
*_rdesc
, unsigned int *rsize
)
3635 /* Note 0 terminated so we can use strnstr to search for this. */
3636 static const char consumer_rdesc_start
[] = {
3637 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */
3638 0x09, 0x01, /* USAGE (Consumer Control) */
3639 0xA1, 0x01, /* COLLECTION (Application) */
3640 0x85, 0x03, /* REPORT_ID = 3 */
3641 0x75, 0x10, /* REPORT_SIZE (16) */
3642 0x95, 0x02, /* REPORT_COUNT (2) */
3643 0x15, 0x01, /* LOGICAL_MIN (1) */
3644 0x26, 0x00 /* LOGICAL_MAX (... */
3646 char *consumer_rdesc
, *rdesc
= (char *)_rdesc
;
3649 consumer_rdesc
= strnstr(rdesc
, consumer_rdesc_start
, *rsize
);
3650 size
= *rsize
- (consumer_rdesc
- rdesc
);
3651 if (consumer_rdesc
&& size
>= 25) {
3652 consumer_rdesc
[15] = 0x7f;
3653 consumer_rdesc
[16] = 0x10;
3654 consumer_rdesc
[20] = 0x7f;
3655 consumer_rdesc
[21] = 0x10;
3660 static int hidpp10_consumer_keys_connect(struct hidpp_device
*hidpp
)
3662 return hidpp10_set_register(hidpp
, HIDPP_REG_ENABLE_REPORTS
, 0,
3663 HIDPP_ENABLE_CONSUMER_REPORT
,
3664 HIDPP_ENABLE_CONSUMER_REPORT
);
3667 static int hidpp10_consumer_keys_raw_event(struct hidpp_device
*hidpp
,
3670 u8 consumer_report
[5];
3675 if (data
[0] != REPORT_ID_HIDPP_SHORT
||
3676 data
[2] != HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS
)
3680 * Build a normal consumer report (3) out of the data, this detour
3681 * is necessary to get some keyboards to report their 0x10xx usages.
3683 consumer_report
[0] = 0x03;
3684 memcpy(&consumer_report
[1], &data
[3], 4);
3685 /* We are called from atomic context */
3686 hid_report_raw_event(hidpp
->hid_dev
, HID_INPUT_REPORT
,
3687 consumer_report
, 5, 1);
3692 /* -------------------------------------------------------------------------- */
3693 /* High-resolution scroll wheels */
3694 /* -------------------------------------------------------------------------- */
3696 static int hi_res_scroll_enable(struct hidpp_device
*hidpp
)
3701 if (hidpp
->capabilities
& HIDPP_CAPABILITY_HIDPP20_HI_RES_WHEEL
) {
3702 ret
= hidpp_hrw_set_wheel_mode(hidpp
, false, true, false);
3704 ret
= hidpp_hrw_get_wheel_capability(hidpp
, &multiplier
);
3705 } else if (hidpp
->capabilities
& HIDPP_CAPABILITY_HIDPP20_HI_RES_SCROLL
) {
3706 ret
= hidpp_hrs_set_highres_scrolling_mode(hidpp
, true,
3708 } else /* if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_FAST_SCROLL) */ {
3709 ret
= hidpp10_enable_scrolling_acceleration(hidpp
);
3713 hid_dbg(hidpp
->hid_dev
,
3714 "Could not enable hi-res scrolling: %d\n", ret
);
3718 if (multiplier
== 0) {
3719 hid_dbg(hidpp
->hid_dev
,
3720 "Invalid multiplier 0 from device, setting it to 1\n");
3724 hidpp
->vertical_wheel_counter
.wheel_multiplier
= multiplier
;
3725 hid_dbg(hidpp
->hid_dev
, "wheel multiplier = %d\n", multiplier
);
3729 static int hidpp_initialize_hires_scroll(struct hidpp_device
*hidpp
)
3732 unsigned long capabilities
;
3734 capabilities
= hidpp
->capabilities
;
3736 if (hidpp
->protocol_major
>= 2) {
3740 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_HIRES_WHEEL
,
3741 &feature_index
, &feature_type
);
3743 hidpp
->capabilities
|= HIDPP_CAPABILITY_HIDPP20_HI_RES_WHEEL
;
3744 hid_dbg(hidpp
->hid_dev
, "Detected HID++ 2.0 hi-res scroll wheel\n");
3747 ret
= hidpp_root_get_feature(hidpp
, HIDPP_PAGE_HI_RESOLUTION_SCROLLING
,
3748 &feature_index
, &feature_type
);
3750 hidpp
->capabilities
|= HIDPP_CAPABILITY_HIDPP20_HI_RES_SCROLL
;
3751 hid_dbg(hidpp
->hid_dev
, "Detected HID++ 2.0 hi-res scrolling\n");
3754 /* We cannot detect fast scrolling support on HID++ 1.0 devices */
3755 if (hidpp
->quirks
& HIDPP_QUIRK_HI_RES_SCROLL_1P0
) {
3756 hidpp
->capabilities
|= HIDPP_CAPABILITY_HIDPP10_FAST_SCROLL
;
3757 hid_dbg(hidpp
->hid_dev
, "Detected HID++ 1.0 fast scroll\n");
3761 if (hidpp
->capabilities
== capabilities
)
3762 hid_dbg(hidpp
->hid_dev
, "Did not detect HID++ hi-res scrolling hardware support\n");
3766 /* -------------------------------------------------------------------------- */
3767 /* Generic HID++ devices */
3768 /* -------------------------------------------------------------------------- */
3770 static const u8
*hidpp_report_fixup(struct hid_device
*hdev
, u8
*rdesc
,
3771 unsigned int *rsize
)
3773 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3778 /* For 27 MHz keyboards the quirk gets set after hid_parse. */
3779 if (hdev
->group
== HID_GROUP_LOGITECH_27MHZ_DEVICE
||
3780 (hidpp
->quirks
& HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS
))
3781 rdesc
= hidpp10_consumer_keys_report_fixup(hidpp
, rdesc
, rsize
);
3786 static int hidpp_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
3787 struct hid_field
*field
, struct hid_usage
*usage
,
3788 unsigned long **bit
, int *max
)
3790 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3795 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
)
3796 return wtp_input_mapping(hdev
, hi
, field
, usage
, bit
, max
);
3797 else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_M560
&&
3798 field
->application
!= HID_GD_MOUSE
)
3799 return m560_input_mapping(hdev
, hi
, field
, usage
, bit
, max
);
3801 if (hdev
->product
== DINOVO_MINI_PRODUCT_ID
)
3802 return lg_dinovo_input_mapping(hdev
, hi
, field
, usage
, bit
, max
);
3807 static int hidpp_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
3808 struct hid_field
*field
, struct hid_usage
*usage
,
3809 unsigned long **bit
, int *max
)
3811 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3816 /* Ensure that Logitech G920 is not given a default fuzz/flat value */
3817 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_G920
) {
3818 if (usage
->type
== EV_ABS
&& (usage
->code
== ABS_X
||
3819 usage
->code
== ABS_Y
|| usage
->code
== ABS_Z
||
3820 usage
->code
== ABS_RZ
)) {
3821 field
->application
= HID_GD_MULTIAXIS
;
3829 static void hidpp_populate_input(struct hidpp_device
*hidpp
,
3830 struct input_dev
*input
)
3832 hidpp
->input
= input
;
3834 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
)
3835 wtp_populate_input(hidpp
, input
);
3836 else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_M560
)
3837 m560_populate_input(hidpp
, input
);
3839 if (hidpp
->quirks
& HIDPP_QUIRK_HIDPP_WHEELS
)
3840 hidpp10_wheel_populate_input(hidpp
, input
);
3842 if (hidpp
->quirks
& HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS
)
3843 hidpp10_extra_mouse_buttons_populate_input(hidpp
, input
);
3846 static int hidpp_input_configured(struct hid_device
*hdev
,
3847 struct hid_input
*hidinput
)
3849 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3850 struct input_dev
*input
= hidinput
->input
;
3855 hidpp_populate_input(hidpp
, input
);
3860 static int hidpp_raw_hidpp_event(struct hidpp_device
*hidpp
, u8
*data
,
3863 struct hidpp_report
*question
= hidpp
->send_receive_buf
;
3864 struct hidpp_report
*answer
= hidpp
->send_receive_buf
;
3865 struct hidpp_report
*report
= (struct hidpp_report
*)data
;
3869 * If the mutex is locked then we have a pending answer from a
3870 * previously sent command.
3872 if (unlikely(mutex_is_locked(&hidpp
->send_mutex
))) {
3874 * Check for a correct hidpp20 answer or the corresponding
3877 if (hidpp_match_answer(question
, report
) ||
3878 hidpp_match_error(question
, report
)) {
3880 hidpp
->answer_available
= true;
3881 wake_up(&hidpp
->wait
);
3883 * This was an answer to a command that this driver sent
3884 * We return 1 to hid-core to avoid forwarding the
3885 * command upstream as it has been treated by the driver
3892 if (unlikely(hidpp_report_is_connect_event(hidpp
, report
))) {
3893 if (schedule_work(&hidpp
->work
) == 0)
3894 dbg_hid("%s: connect event already queued\n", __func__
);
3898 if (hidpp
->hid_dev
->group
== HID_GROUP_LOGITECH_27MHZ_DEVICE
&&
3899 data
[0] == REPORT_ID_HIDPP_SHORT
&&
3900 data
[2] == HIDPP_SUB_ID_USER_IFACE_EVENT
&&
3901 (data
[3] & HIDPP_USER_IFACE_EVENT_ENCRYPTION_KEY_LOST
)) {
3902 dev_err_ratelimited(&hidpp
->hid_dev
->dev
,
3903 "Error the keyboard's wireless encryption key has been lost, your keyboard will not work unless you re-configure encryption.\n");
3904 dev_err_ratelimited(&hidpp
->hid_dev
->dev
,
3905 "See: https://gitlab.freedesktop.org/jwrdegoede/logitech-27mhz-keyboard-encryption-setup/\n");
3908 if (hidpp
->capabilities
& HIDPP_CAPABILITY_HIDPP20_BATTERY
) {
3909 ret
= hidpp20_battery_event_1000(hidpp
, data
, size
);
3912 ret
= hidpp20_battery_event_1004(hidpp
, data
, size
);
3915 ret
= hidpp_solar_battery_event(hidpp
, data
, size
);
3918 ret
= hidpp20_battery_voltage_event(hidpp
, data
, size
);
3921 ret
= hidpp20_adc_measurement_event_1f20(hidpp
, data
, size
);
3926 if (hidpp
->capabilities
& HIDPP_CAPABILITY_HIDPP10_BATTERY
) {
3927 ret
= hidpp10_battery_event(hidpp
, data
, size
);
3932 if (hidpp
->quirks
& HIDPP_QUIRK_HIDPP_WHEELS
) {
3933 ret
= hidpp10_wheel_raw_event(hidpp
, data
, size
);
3938 if (hidpp
->quirks
& HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS
) {
3939 ret
= hidpp10_extra_mouse_buttons_raw_event(hidpp
, data
, size
);
3944 if (hidpp
->quirks
& HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS
) {
3945 ret
= hidpp10_consumer_keys_raw_event(hidpp
, data
, size
);
3953 static int hidpp_raw_event(struct hid_device
*hdev
, struct hid_report
*report
,
3956 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
3962 /* Generic HID++ processing. */
3964 case REPORT_ID_HIDPP_VERY_LONG
:
3965 if (size
!= hidpp
->very_long_report_length
) {
3966 hid_err(hdev
, "received hid++ report of bad size (%d)",
3970 ret
= hidpp_raw_hidpp_event(hidpp
, data
, size
);
3972 case REPORT_ID_HIDPP_LONG
:
3973 if (size
!= HIDPP_REPORT_LONG_LENGTH
) {
3974 hid_err(hdev
, "received hid++ report of bad size (%d)",
3978 ret
= hidpp_raw_hidpp_event(hidpp
, data
, size
);
3980 case REPORT_ID_HIDPP_SHORT
:
3981 if (size
!= HIDPP_REPORT_SHORT_LENGTH
) {
3982 hid_err(hdev
, "received hid++ report of bad size (%d)",
3986 ret
= hidpp_raw_hidpp_event(hidpp
, data
, size
);
3990 /* If no report is available for further processing, skip calling
3991 * raw_event of subclasses. */
3995 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
)
3996 return wtp_raw_event(hdev
, data
, size
);
3997 else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_M560
)
3998 return m560_raw_event(hdev
, data
, size
);
4003 static int hidpp_event(struct hid_device
*hdev
, struct hid_field
*field
,
4004 struct hid_usage
*usage
, __s32 value
)
4006 /* This function will only be called for scroll events, due to the
4007 * restriction imposed in hidpp_usages.
4009 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
4010 struct hidpp_scroll_counter
*counter
;
4015 counter
= &hidpp
->vertical_wheel_counter
;
4016 /* A scroll event may occur before the multiplier has been retrieved or
4017 * the input device set, or high-res scroll enabling may fail. In such
4018 * cases we must return early (falling back to default behaviour) to
4019 * avoid a crash in hidpp_scroll_counter_handle_scroll.
4021 if (!(hidpp
->capabilities
& HIDPP_CAPABILITY_HI_RES_SCROLL
)
4022 || value
== 0 || hidpp
->input
== NULL
4023 || counter
->wheel_multiplier
== 0)
4026 hidpp_scroll_counter_handle_scroll(hidpp
->input
, counter
, value
);
4030 static int hidpp_initialize_battery(struct hidpp_device
*hidpp
)
4032 static atomic_t battery_no
= ATOMIC_INIT(0);
4033 struct power_supply_config cfg
= { .drv_data
= hidpp
};
4034 struct power_supply_desc
*desc
= &hidpp
->battery
.desc
;
4035 enum power_supply_property
*battery_props
;
4036 struct hidpp_battery
*battery
;
4037 unsigned int num_battery_props
;
4041 if (hidpp
->battery
.ps
)
4044 hidpp
->battery
.feature_index
= 0xff;
4045 hidpp
->battery
.solar_feature_index
= 0xff;
4046 hidpp
->battery
.voltage_feature_index
= 0xff;
4047 hidpp
->battery
.adc_measurement_feature_index
= 0xff;
4049 if (hidpp
->protocol_major
>= 2) {
4050 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_K750
)
4051 ret
= hidpp_solar_request_battery_event(hidpp
);
4053 /* we only support one battery feature right now, so let's
4054 first check the ones that support battery level first
4055 and leave voltage for last */
4056 ret
= hidpp20_query_battery_info_1000(hidpp
);
4058 ret
= hidpp20_query_battery_info_1004(hidpp
);
4060 ret
= hidpp20_query_battery_voltage_info(hidpp
);
4062 ret
= hidpp20_query_adc_measurement_info_1f20(hidpp
);
4067 hidpp
->capabilities
|= HIDPP_CAPABILITY_HIDPP20_BATTERY
;
4069 ret
= hidpp10_query_battery_status(hidpp
);
4071 ret
= hidpp10_query_battery_mileage(hidpp
);
4074 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_MILEAGE
;
4076 hidpp
->capabilities
|= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS
;
4078 hidpp
->capabilities
|= HIDPP_CAPABILITY_HIDPP10_BATTERY
;
4081 battery_props
= devm_kmemdup(&hidpp
->hid_dev
->dev
,
4082 hidpp_battery_props
,
4083 sizeof(hidpp_battery_props
),
4088 num_battery_props
= ARRAY_SIZE(hidpp_battery_props
) - 3;
4090 if (hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_MILEAGE
||
4091 hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_PERCENTAGE
||
4092 hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_VOLTAGE
||
4093 hidpp
->capabilities
& HIDPP_CAPABILITY_ADC_MEASUREMENT
)
4094 battery_props
[num_battery_props
++] =
4095 POWER_SUPPLY_PROP_CAPACITY
;
4097 if (hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS
)
4098 battery_props
[num_battery_props
++] =
4099 POWER_SUPPLY_PROP_CAPACITY_LEVEL
;
4101 if (hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_VOLTAGE
||
4102 hidpp
->capabilities
& HIDPP_CAPABILITY_ADC_MEASUREMENT
)
4103 battery_props
[num_battery_props
++] =
4104 POWER_SUPPLY_PROP_VOLTAGE_NOW
;
4106 battery
= &hidpp
->battery
;
4108 n
= atomic_inc_return(&battery_no
) - 1;
4109 desc
->properties
= battery_props
;
4110 desc
->num_properties
= num_battery_props
;
4111 desc
->get_property
= hidpp_battery_get_property
;
4112 sprintf(battery
->name
, "hidpp_battery_%ld", n
);
4113 desc
->name
= battery
->name
;
4114 desc
->type
= POWER_SUPPLY_TYPE_BATTERY
;
4115 desc
->use_for_apm
= 0;
4117 battery
->ps
= devm_power_supply_register(&hidpp
->hid_dev
->dev
,
4120 if (IS_ERR(battery
->ps
))
4121 return PTR_ERR(battery
->ps
);
4123 power_supply_powers(battery
->ps
, &hidpp
->hid_dev
->dev
);
4128 /* Get name + serial for USB and Bluetooth HID++ devices */
4129 static void hidpp_non_unifying_init(struct hidpp_device
*hidpp
)
4131 struct hid_device
*hdev
= hidpp
->hid_dev
;
4134 /* Bluetooth devices already have their serialnr set */
4135 if (hid_is_usb(hdev
))
4136 hidpp_serial_init(hidpp
);
4138 name
= hidpp_get_device_name(hidpp
);
4140 dbg_hid("HID++: Got name: %s\n", name
);
4141 snprintf(hdev
->name
, sizeof(hdev
->name
), "%s", name
);
4146 static int hidpp_input_open(struct input_dev
*dev
)
4148 struct hid_device
*hid
= input_get_drvdata(dev
);
4150 return hid_hw_open(hid
);
4153 static void hidpp_input_close(struct input_dev
*dev
)
4155 struct hid_device
*hid
= input_get_drvdata(dev
);
4160 static struct input_dev
*hidpp_allocate_input(struct hid_device
*hdev
)
4162 struct input_dev
*input_dev
= devm_input_allocate_device(&hdev
->dev
);
4163 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
4168 input_set_drvdata(input_dev
, hdev
);
4169 input_dev
->open
= hidpp_input_open
;
4170 input_dev
->close
= hidpp_input_close
;
4172 input_dev
->name
= hidpp
->name
;
4173 input_dev
->phys
= hdev
->phys
;
4174 input_dev
->uniq
= hdev
->uniq
;
4175 input_dev
->id
.bustype
= hdev
->bus
;
4176 input_dev
->id
.vendor
= hdev
->vendor
;
4177 input_dev
->id
.product
= hdev
->product
;
4178 input_dev
->id
.version
= hdev
->version
;
4179 input_dev
->dev
.parent
= &hdev
->dev
;
4184 static void hidpp_connect_event(struct work_struct
*work
)
4186 struct hidpp_device
*hidpp
= container_of(work
, struct hidpp_device
, work
);
4187 struct hid_device
*hdev
= hidpp
->hid_dev
;
4188 struct input_dev
*input
;
4189 char *name
, *devm_name
;
4192 /* Get device version to check if it is connected */
4193 ret
= hidpp_root_get_protocol_version(hidpp
);
4195 hid_dbg(hidpp
->hid_dev
, "Disconnected\n");
4196 if (hidpp
->battery
.ps
) {
4197 hidpp
->battery
.online
= false;
4198 hidpp
->battery
.status
= POWER_SUPPLY_STATUS_UNKNOWN
;
4199 hidpp
->battery
.level
= POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN
;
4200 power_supply_changed(hidpp
->battery
.ps
);
4205 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
) {
4206 ret
= wtp_connect(hdev
);
4209 } else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_M560
) {
4210 ret
= m560_send_config_command(hdev
);
4213 } else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_K400
) {
4214 ret
= k400_connect(hdev
);
4219 if (hidpp
->quirks
& HIDPP_QUIRK_HIDPP_WHEELS
) {
4220 ret
= hidpp10_wheel_connect(hidpp
);
4225 if (hidpp
->quirks
& HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS
) {
4226 ret
= hidpp10_extra_mouse_buttons_connect(hidpp
);
4231 if (hidpp
->quirks
& HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS
) {
4232 ret
= hidpp10_consumer_keys_connect(hidpp
);
4237 if (hidpp
->protocol_major
>= 2) {
4240 if (!hidpp_get_wireless_feature_index(hidpp
, &feature_index
))
4241 hidpp
->wireless_feature_index
= feature_index
;
4244 if (hidpp
->name
== hdev
->name
&& hidpp
->protocol_major
>= 2) {
4245 name
= hidpp_get_device_name(hidpp
);
4247 devm_name
= devm_kasprintf(&hdev
->dev
, GFP_KERNEL
,
4253 hidpp
->name
= devm_name
;
4257 hidpp_initialize_battery(hidpp
);
4258 if (!hid_is_usb(hidpp
->hid_dev
))
4259 hidpp_initialize_hires_scroll(hidpp
);
4261 /* forward current battery state */
4262 if (hidpp
->capabilities
& HIDPP_CAPABILITY_HIDPP10_BATTERY
) {
4263 hidpp10_enable_battery_reporting(hidpp
);
4264 if (hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_MILEAGE
)
4265 hidpp10_query_battery_mileage(hidpp
);
4267 hidpp10_query_battery_status(hidpp
);
4268 } else if (hidpp
->capabilities
& HIDPP_CAPABILITY_HIDPP20_BATTERY
) {
4269 if (hidpp
->capabilities
& HIDPP_CAPABILITY_BATTERY_VOLTAGE
)
4270 hidpp20_query_battery_voltage_info(hidpp
);
4271 else if (hidpp
->capabilities
& HIDPP_CAPABILITY_UNIFIED_BATTERY
)
4272 hidpp20_query_battery_info_1004(hidpp
);
4273 else if (hidpp
->capabilities
& HIDPP_CAPABILITY_ADC_MEASUREMENT
)
4274 hidpp20_query_adc_measurement_info_1f20(hidpp
);
4276 hidpp20_query_battery_info_1000(hidpp
);
4278 if (hidpp
->battery
.ps
)
4279 power_supply_changed(hidpp
->battery
.ps
);
4281 if (hidpp
->capabilities
& HIDPP_CAPABILITY_HI_RES_SCROLL
)
4282 hi_res_scroll_enable(hidpp
);
4284 if (!(hidpp
->quirks
& HIDPP_QUIRK_DELAYED_INIT
) || hidpp
->delayed_input
)
4285 /* if the input nodes are already created, we can stop now */
4288 input
= hidpp_allocate_input(hdev
);
4290 hid_err(hdev
, "cannot allocate new input device: %d\n", ret
);
4294 hidpp_populate_input(hidpp
, input
);
4296 ret
= input_register_device(input
);
4298 input_free_device(input
);
4302 hidpp
->delayed_input
= input
;
4305 static DEVICE_ATTR(builtin_power_supply
, 0000, NULL
, NULL
);
4307 static struct attribute
*sysfs_attrs
[] = {
4308 &dev_attr_builtin_power_supply
.attr
,
4312 static const struct attribute_group ps_attribute_group
= {
4313 .attrs
= sysfs_attrs
4316 static int hidpp_get_report_length(struct hid_device
*hdev
, int id
)
4318 struct hid_report_enum
*re
;
4319 struct hid_report
*report
;
4321 re
= &(hdev
->report_enum
[HID_OUTPUT_REPORT
]);
4322 report
= re
->report_id_hash
[id
];
4326 return report
->field
[0]->report_count
+ 1;
4329 static u8
hidpp_validate_device(struct hid_device
*hdev
)
4331 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
4332 int id
, report_length
;
4333 u8 supported_reports
= 0;
4335 id
= REPORT_ID_HIDPP_SHORT
;
4336 report_length
= hidpp_get_report_length(hdev
, id
);
4337 if (report_length
) {
4338 if (report_length
< HIDPP_REPORT_SHORT_LENGTH
)
4341 supported_reports
|= HIDPP_REPORT_SHORT_SUPPORTED
;
4344 id
= REPORT_ID_HIDPP_LONG
;
4345 report_length
= hidpp_get_report_length(hdev
, id
);
4346 if (report_length
) {
4347 if (report_length
< HIDPP_REPORT_LONG_LENGTH
)
4350 supported_reports
|= HIDPP_REPORT_LONG_SUPPORTED
;
4353 id
= REPORT_ID_HIDPP_VERY_LONG
;
4354 report_length
= hidpp_get_report_length(hdev
, id
);
4355 if (report_length
) {
4356 if (report_length
< HIDPP_REPORT_LONG_LENGTH
||
4357 report_length
> HIDPP_REPORT_VERY_LONG_MAX_LENGTH
)
4360 supported_reports
|= HIDPP_REPORT_VERY_LONG_SUPPORTED
;
4361 hidpp
->very_long_report_length
= report_length
;
4364 return supported_reports
;
4367 hid_warn(hdev
, "not enough values in hidpp report %d\n", id
);
4371 static bool hidpp_application_equals(struct hid_device
*hdev
,
4372 unsigned int application
)
4374 struct list_head
*report_list
;
4375 struct hid_report
*report
;
4377 report_list
= &hdev
->report_enum
[HID_INPUT_REPORT
].report_list
;
4378 report
= list_first_entry_or_null(report_list
, struct hid_report
, list
);
4379 return report
&& report
->application
== application
;
4382 static int hidpp_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
4384 struct hidpp_device
*hidpp
;
4386 unsigned int connect_mask
= HID_CONNECT_DEFAULT
;
4388 /* report_fixup needs drvdata to be set before we call hid_parse */
4389 hidpp
= devm_kzalloc(&hdev
->dev
, sizeof(*hidpp
), GFP_KERNEL
);
4393 hidpp
->hid_dev
= hdev
;
4394 hidpp
->name
= hdev
->name
;
4395 hidpp
->quirks
= id
->driver_data
;
4396 hid_set_drvdata(hdev
, hidpp
);
4398 ret
= hid_parse(hdev
);
4400 hid_err(hdev
, "%s:parse failed\n", __func__
);
4405 * Make sure the device is HID++ capable, otherwise treat as generic HID
4407 hidpp
->supported_reports
= hidpp_validate_device(hdev
);
4409 if (!hidpp
->supported_reports
) {
4410 hid_set_drvdata(hdev
, NULL
);
4411 devm_kfree(&hdev
->dev
, hidpp
);
4412 return hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
4415 if (id
->group
== HID_GROUP_LOGITECH_27MHZ_DEVICE
&&
4416 hidpp_application_equals(hdev
, HID_GD_MOUSE
))
4417 hidpp
->quirks
|= HIDPP_QUIRK_HIDPP_WHEELS
|
4418 HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS
;
4420 if (id
->group
== HID_GROUP_LOGITECH_27MHZ_DEVICE
&&
4421 hidpp_application_equals(hdev
, HID_GD_KEYBOARD
))
4422 hidpp
->quirks
|= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS
;
4424 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_WTP
) {
4425 ret
= wtp_allocate(hdev
, id
);
4428 } else if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_K400
) {
4429 ret
= k400_allocate(hdev
);
4434 INIT_WORK(&hidpp
->work
, hidpp_connect_event
);
4435 mutex_init(&hidpp
->send_mutex
);
4436 init_waitqueue_head(&hidpp
->wait
);
4438 /* indicates we are handling the battery properties in the kernel */
4439 ret
= sysfs_create_group(&hdev
->dev
.kobj
, &ps_attribute_group
);
4441 hid_warn(hdev
, "Cannot allocate sysfs group for %s\n",
4445 * First call hid_hw_start(hdev, 0) to allow IO without connecting any
4446 * hid subdrivers (hid-input, hidraw). This allows retrieving the dev's
4447 * name and serial number and store these in hdev->name and hdev->uniq,
4448 * before the hid-input and hidraw drivers expose these to userspace.
4450 ret
= hid_hw_start(hdev
, 0);
4452 hid_err(hdev
, "hw start failed\n");
4453 goto hid_hw_start_fail
;
4456 ret
= hid_hw_open(hdev
);
4458 dev_err(&hdev
->dev
, "%s:hid_hw_open returned error:%d\n",
4460 goto hid_hw_open_fail
;
4463 /* Allow incoming packets */
4464 hid_device_io_start(hdev
);
4466 /* Get name + serial, store in hdev->name + hdev->uniq */
4467 if (id
->group
== HID_GROUP_LOGITECH_DJ_DEVICE
)
4468 hidpp_unifying_init(hidpp
);
4470 hidpp_non_unifying_init(hidpp
);
4472 if (hidpp
->quirks
& HIDPP_QUIRK_DELAYED_INIT
)
4473 connect_mask
&= ~HID_CONNECT_HIDINPUT
;
4475 /* Now export the actual inputs and hidraw nodes to the world */
4476 hid_device_io_stop(hdev
);
4477 ret
= hid_connect(hdev
, connect_mask
);
4479 hid_err(hdev
, "%s:hid_connect returned error %d\n", __func__
, ret
);
4480 goto hid_hw_init_fail
;
4483 /* Check for connected devices now that incoming packets will not be disabled again */
4484 hid_device_io_start(hdev
);
4485 schedule_work(&hidpp
->work
);
4486 flush_work(&hidpp
->work
);
4488 if (hidpp
->quirks
& HIDPP_QUIRK_CLASS_G920
) {
4489 struct hidpp_ff_private_data data
;
4491 ret
= g920_get_config(hidpp
, &data
);
4493 ret
= hidpp_ff_init(hidpp
, &data
);
4496 hid_warn(hidpp
->hid_dev
,
4497 "Unable to initialize force feedback support, errno %d\n",
4502 * This relies on logi_dj_ll_close() being a no-op so that DJ connection
4503 * events will still be received.
4513 sysfs_remove_group(&hdev
->dev
.kobj
, &ps_attribute_group
);
4514 cancel_work_sync(&hidpp
->work
);
4515 mutex_destroy(&hidpp
->send_mutex
);
4519 static void hidpp_remove(struct hid_device
*hdev
)
4521 struct hidpp_device
*hidpp
= hid_get_drvdata(hdev
);
4524 return hid_hw_stop(hdev
);
4526 sysfs_remove_group(&hdev
->dev
.kobj
, &ps_attribute_group
);
4529 cancel_work_sync(&hidpp
->work
);
4530 mutex_destroy(&hidpp
->send_mutex
);
4533 #define LDJ_DEVICE(product) \
4534 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE, \
4535 USB_VENDOR_ID_LOGITECH, (product))
4537 #define L27MHZ_DEVICE(product) \
4538 HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_27MHZ_DEVICE, \
4539 USB_VENDOR_ID_LOGITECH, (product))
4541 static const struct hid_device_id hidpp_devices
[] = {
4542 { /* wireless touchpad */
4544 .driver_data
= HIDPP_QUIRK_CLASS_WTP
| HIDPP_QUIRK_DELAYED_INIT
|
4545 HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS
},
4546 { /* wireless touchpad T650 */
4548 .driver_data
= HIDPP_QUIRK_CLASS_WTP
| HIDPP_QUIRK_DELAYED_INIT
},
4549 { /* wireless touchpad T651 */
4550 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
,
4551 USB_DEVICE_ID_LOGITECH_T651
),
4552 .driver_data
= HIDPP_QUIRK_CLASS_WTP
| HIDPP_QUIRK_DELAYED_INIT
},
4553 { /* Mouse Logitech Anywhere MX */
4554 LDJ_DEVICE(0x1017), .driver_data
= HIDPP_QUIRK_HI_RES_SCROLL_1P0
},
4555 { /* Mouse logitech M560 */
4557 .driver_data
= HIDPP_QUIRK_DELAYED_INIT
| HIDPP_QUIRK_CLASS_M560
},
4558 { /* Mouse Logitech M705 (firmware RQM17) */
4559 LDJ_DEVICE(0x101b), .driver_data
= HIDPP_QUIRK_HI_RES_SCROLL_1P0
},
4560 { /* Mouse Logitech Performance MX */
4561 LDJ_DEVICE(0x101a), .driver_data
= HIDPP_QUIRK_HI_RES_SCROLL_1P0
},
4562 { /* Keyboard logitech K400 */
4564 .driver_data
= HIDPP_QUIRK_CLASS_K400
},
4565 { /* Solar Keyboard Logitech K750 */
4567 .driver_data
= HIDPP_QUIRK_CLASS_K750
},
4568 { /* Keyboard MX5000 (Bluetooth-receiver in HID proxy mode) */
4570 .driver_data
= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS
},
4571 { /* Dinovo Edge (Bluetooth-receiver in HID proxy mode) */
4573 .driver_data
= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS
},
4574 { /* Keyboard MX5500 (Bluetooth-receiver in HID proxy mode) */
4576 .driver_data
= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS
},
4578 { LDJ_DEVICE(HID_ANY_ID
) },
4580 { /* Keyboard LX501 (Y-RR53) */
4581 L27MHZ_DEVICE(0x0049),
4582 .driver_data
= HIDPP_QUIRK_KBD_ZOOM_WHEEL
},
4583 { /* Keyboard MX3000 (Y-RAM74) */
4584 L27MHZ_DEVICE(0x0057),
4585 .driver_data
= HIDPP_QUIRK_KBD_SCROLL_WHEEL
},
4586 { /* Keyboard MX3200 (Y-RAV80) */
4587 L27MHZ_DEVICE(0x005c),
4588 .driver_data
= HIDPP_QUIRK_KBD_ZOOM_WHEEL
},
4589 { /* S510 Media Remote */
4590 L27MHZ_DEVICE(0x00fe),
4591 .driver_data
= HIDPP_QUIRK_KBD_SCROLL_WHEEL
},
4593 { L27MHZ_DEVICE(HID_ANY_ID
) },
4595 { /* Logitech G403 Wireless Gaming Mouse over USB */
4596 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC082) },
4597 { /* Logitech G502 Lightspeed Wireless Gaming Mouse over USB */
4598 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC08D) },
4599 { /* Logitech G703 Gaming Mouse over USB */
4600 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC087) },
4601 { /* Logitech G703 Hero Gaming Mouse over USB */
4602 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC090) },
4603 { /* Logitech G900 Gaming Mouse over USB */
4604 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC081) },
4605 { /* Logitech G903 Gaming Mouse over USB */
4606 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC086) },
4607 { /* Logitech G Pro Gaming Mouse over USB */
4608 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC088) },
4609 { /* MX Vertical over USB */
4610 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC08A) },
4611 { /* Logitech G703 Hero Gaming Mouse over USB */
4612 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC090) },
4613 { /* Logitech G903 Hero Gaming Mouse over USB */
4614 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC091) },
4615 { /* Logitech G915 TKL Keyboard over USB */
4616 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC343) },
4617 { /* Logitech G920 Wheel over USB */
4618 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_G920_WHEEL
),
4619 .driver_data
= HIDPP_QUIRK_CLASS_G920
| HIDPP_QUIRK_FORCE_OUTPUT_REPORTS
},
4620 { /* Logitech G923 Wheel (Xbox version) over USB */
4621 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, USB_DEVICE_ID_LOGITECH_G923_XBOX_WHEEL
),
4622 .driver_data
= HIDPP_QUIRK_CLASS_G920
| HIDPP_QUIRK_FORCE_OUTPUT_REPORTS
},
4623 { /* Logitech G Pro X Superlight Gaming Mouse over USB */
4624 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC094) },
4625 { /* Logitech G Pro X Superlight 2 Gaming Mouse over USB */
4626 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xC09b) },
4628 { /* G935 Gaming Headset */
4629 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH
, 0x0a87),
4630 .driver_data
= HIDPP_QUIRK_WIRELESS_STATUS
},
4632 { /* MX5000 keyboard over Bluetooth */
4633 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb305),
4634 .driver_data
= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS
},
4635 { /* Dinovo Edge keyboard over Bluetooth */
4636 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb309),
4637 .driver_data
= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS
},
4638 { /* MX5500 keyboard over Bluetooth */
4639 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb30b),
4640 .driver_data
= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS
},
4641 { /* Logitech G915 TKL keyboard over Bluetooth */
4642 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb35f) },
4643 { /* M-RCQ142 V470 Cordless Laser Mouse over Bluetooth */
4644 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb008) },
4645 { /* MX Master mouse over Bluetooth */
4646 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb012) },
4647 { /* M720 Triathlon mouse over Bluetooth */
4648 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb015) },
4649 { /* MX Master 2S mouse over Bluetooth */
4650 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb019) },
4651 { /* MX Ergo trackball over Bluetooth */
4652 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb01d) },
4653 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb01e) },
4654 { /* MX Vertical mouse over Bluetooth */
4655 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb020) },
4656 { /* Signature M650 over Bluetooth */
4657 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb02a) },
4658 { /* MX Master 3 mouse over Bluetooth */
4659 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb023) },
4660 { /* MX Anywhere 3 mouse over Bluetooth */
4661 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb025) },
4662 { /* MX Master 3S mouse over Bluetooth */
4663 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb034) },
4664 { /* MX Anywhere 3SB mouse over Bluetooth */
4665 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH
, 0xb038) },
4669 MODULE_DEVICE_TABLE(hid
, hidpp_devices
);
4671 static const struct hid_usage_id hidpp_usages
[] = {
4672 { HID_GD_WHEEL
, EV_REL
, REL_WHEEL_HI_RES
},
4673 { HID_ANY_ID
- 1, HID_ANY_ID
- 1, HID_ANY_ID
- 1}
4676 static struct hid_driver hidpp_driver
= {
4677 .name
= "logitech-hidpp-device",
4678 .id_table
= hidpp_devices
,
4679 .report_fixup
= hidpp_report_fixup
,
4680 .probe
= hidpp_probe
,
4681 .remove
= hidpp_remove
,
4682 .raw_event
= hidpp_raw_event
,
4683 .usage_table
= hidpp_usages
,
4684 .event
= hidpp_event
,
4685 .input_configured
= hidpp_input_configured
,
4686 .input_mapping
= hidpp_input_mapping
,
4687 .input_mapped
= hidpp_input_mapped
,
4690 module_hid_driver(hidpp_driver
);