Lines Matching +full:timeout +full:- +full:press +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright (c) 2012-2013 Google (c)
7 * Copyright (c) 2013-2014 Red Hat Inc.
25 #include <linux/fixp-arith.h>
28 #include "hid-ids.h"
38 "Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
40 /* Define a non-zero software ID to identify our own requests */
83 /* Convenience constant to check for any high-res support. */
127 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
133 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
164 * struct hidpp_scroll_counter - Utility class for processing high-resolution
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
171 * @direction: direction of last movement (1 or -1)
246 switch (hidpp_report->report_id) { in __hidpp_send_report()
254 fields_count = hidpp->very_long_report_length; in __hidpp_send_report()
257 return -ENODEV; in __hidpp_send_report()
264 hidpp_report->device_index = 0xff; in __hidpp_send_report()
266 if (hidpp->quirks & HIDPP_QUIRK_FORCE_OUTPUT_REPORTS) { in __hidpp_send_report()
269 ret = hid_hw_raw_request(hdev, hidpp_report->report_id, in __hidpp_send_report()
274 return ret == fields_count ? 0 : -1; in __hidpp_send_report()
280 * Must be called with hidpp->send_mutex locked
283 * - success on 0
284 * - negative error means transport error
285 * - positive value means protocol error
293 __must_hold(&hidpp->send_mutex); in __do_hidpp_send_message_sync()
295 hidpp->send_receive_buf = response; in __do_hidpp_send_message_sync()
296 hidpp->answer_available = false; in __do_hidpp_send_message_sync()
304 ret = __hidpp_send_report(hidpp->hid_dev, message); in __do_hidpp_send_message_sync()
311 if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, in __do_hidpp_send_message_sync()
313 dbg_hid("%s:timeout waiting for response\n", __func__); in __do_hidpp_send_message_sync()
315 return -ETIMEDOUT; in __do_hidpp_send_message_sync()
318 if (response->report_id == REPORT_ID_HIDPP_SHORT && in __do_hidpp_send_message_sync()
319 response->rap.sub_id == HIDPP_ERROR) { in __do_hidpp_send_message_sync()
320 ret = response->rap.params[1]; in __do_hidpp_send_message_sync()
325 if ((response->report_id == REPORT_ID_HIDPP_LONG || in __do_hidpp_send_message_sync()
326 response->report_id == REPORT_ID_HIDPP_VERY_LONG) && in __do_hidpp_send_message_sync()
327 response->fap.feature_index == HIDPP20_ERROR) { in __do_hidpp_send_message_sync()
328 ret = response->fap.params[1]; in __do_hidpp_send_message_sync()
350 mutex_lock(&hidpp->send_mutex); in hidpp_send_message_sync()
358 } while (--max_retries); in hidpp_send_message_sync()
360 mutex_unlock(&hidpp->send_mutex); in hidpp_send_message_sync()
379 if (param_count > sizeof(message->fap.params)) { in hidpp_send_fap_command_sync()
380 hid_dbg(hidpp->hid_dev, in hidpp_send_fap_command_sync()
383 (unsigned long long) sizeof(message->fap.params)); in hidpp_send_fap_command_sync()
384 return -EINVAL; in hidpp_send_fap_command_sync()
389 return -ENOMEM; in hidpp_send_fap_command_sync()
391 if (param_count > (HIDPP_REPORT_LONG_LENGTH - 4)) in hidpp_send_fap_command_sync()
392 message->report_id = REPORT_ID_HIDPP_VERY_LONG; in hidpp_send_fap_command_sync()
394 message->report_id = REPORT_ID_HIDPP_LONG; in hidpp_send_fap_command_sync()
395 message->fap.feature_index = feat_index; in hidpp_send_fap_command_sync()
396 message->fap.funcindex_clientid = funcindex_clientid | LINUX_KERNEL_SW_ID; in hidpp_send_fap_command_sync()
397 memcpy(&message->fap.params, params, param_count); in hidpp_send_fap_command_sync()
420 !(hidpp_dev->supported_reports & HIDPP_REPORT_SHORT_SUPPORTED)) in hidpp_send_rap_command_sync()
425 max_count = HIDPP_REPORT_SHORT_LENGTH - 4; in hidpp_send_rap_command_sync()
428 max_count = HIDPP_REPORT_LONG_LENGTH - 4; in hidpp_send_rap_command_sync()
431 max_count = hidpp_dev->very_long_report_length - 4; in hidpp_send_rap_command_sync()
434 return -EINVAL; in hidpp_send_rap_command_sync()
438 return -EINVAL; in hidpp_send_rap_command_sync()
442 return -ENOMEM; in hidpp_send_rap_command_sync()
443 message->report_id = report_id; in hidpp_send_rap_command_sync()
444 message->rap.sub_id = sub_id; in hidpp_send_rap_command_sync()
445 message->rap.reg_address = reg_address; in hidpp_send_rap_command_sync()
446 memcpy(&message->rap.params, params, param_count); in hidpp_send_rap_command_sync()
463 return (answer->fap.feature_index == question->fap.feature_index) && in hidpp_match_answer()
464 (answer->fap.funcindex_clientid == question->fap.funcindex_clientid); in hidpp_match_answer()
470 return ((answer->rap.sub_id == HIDPP_ERROR) || in hidpp_match_error()
471 (answer->fap.feature_index == HIDPP20_ERROR)) && in hidpp_match_error()
472 (answer->fap.funcindex_clientid == question->fap.feature_index) && in hidpp_match_error()
473 (answer->fap.params[0] == question->fap.funcindex_clientid); in hidpp_match_error()
479 return (hidpp->wireless_feature_index && in hidpp_report_is_connect_event()
480 (report->fap.feature_index == hidpp->wireless_feature_index)) || in hidpp_report_is_connect_event()
481 ((report->report_id == REPORT_ID_HIDPP_SHORT) && in hidpp_report_is_connect_event()
482 (report->rap.sub_id == 0x41)); in hidpp_report_is_connect_event()
518 struct hid_device *hdev = hidpp->hid_dev; in hidpp_update_usb_wireless_status()
521 if (!(hidpp->quirks & HIDPP_QUIRK_WIRELESS_STATUS)) in hidpp_update_usb_wireless_status()
526 intf = to_usb_interface(hdev->dev.parent); in hidpp_update_usb_wireless_status()
527 usb_set_wireless_status(intf, hidpp->battery.online ? in hidpp_update_usb_wireless_status()
533 * hidpp_scroll_counter_handle_scroll() - Send high- and low-resolution scroll
534 * events given a high-resolution wheel
538 * @hi_res_value: the movement of the wheel, in the mouse's high-resolution
541 * Given a high-resolution movement, this function converts the movement into
542 * fractions of 120 and emits high-resolution scroll events for the input
544 * emit low-resolution scroll events when appropriate for
545 * backwards-compatibility with userspace input libraries.
554 hi_res_value = hi_res_value * 120/counter->wheel_multiplier; in hidpp_scroll_counter_handle_scroll()
557 remainder = counter->remainder; in hidpp_scroll_counter_handle_scroll()
558 direction = hi_res_value > 0 ? 1 : -1; in hidpp_scroll_counter_handle_scroll()
561 previous = counter->last_time; in hidpp_scroll_counter_handle_scroll()
562 counter->last_time = now; in hidpp_scroll_counter_handle_scroll()
569 if (now - previous > 1000000000 || direction != counter->direction) in hidpp_scroll_counter_handle_scroll()
572 counter->direction = direction; in hidpp_scroll_counter_handle_scroll()
576 * after slow movement, so we want the threshold for low-res events to in hidpp_scroll_counter_handle_scroll()
582 * is half-way to the next detent (i.e. scroll 1 detent after a in hidpp_scroll_counter_handle_scroll()
588 low_res_value = (hi_res_value > 0 ? 1 : -1); in hidpp_scroll_counter_handle_scroll()
590 remainder -= low_res_value * 120; in hidpp_scroll_counter_handle_scroll()
592 counter->remainder = remainder; in hidpp_scroll_counter_handle_scroll()
595 /* -------------------------------------------------------------------------- */
597 /* -------------------------------------------------------------------------- */
605 * hidpp10_set_register - Modify a HID++ 1.0 register.
657 /* On HID++ 1.0 devices, high-res scroll was called "scrolling acceleration". */
737 hidpp->battery.level = in hidpp10_query_battery_status()
740 hidpp->battery.status = status; in hidpp10_query_battery_status()
742 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp10_query_battery_status()
789 hidpp->battery.capacity = response.rap.params[0]; in hidpp10_query_battery_mileage()
791 hidpp->battery.status = status; in hidpp10_query_battery_mileage()
793 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp10_query_battery_mileage()
805 if (report->report_id != REPORT_ID_HIDPP_SHORT) in hidpp10_battery_event()
808 switch (report->rap.sub_id) { in hidpp10_battery_event()
810 capacity = hidpp->battery.capacity; in hidpp10_battery_event()
811 level = hidpp10_battery_status_map_level(report->rawbytes[1]); in hidpp10_battery_event()
812 status = hidpp10_battery_status_map_status(report->rawbytes[2]); in hidpp10_battery_event()
815 capacity = report->rap.params[0]; in hidpp10_battery_event()
816 level = hidpp->battery.level; in hidpp10_battery_event()
817 status = hidpp10_battery_mileage_map_status(report->rawbytes[3]); in hidpp10_battery_event()
823 changed = capacity != hidpp->battery.capacity || in hidpp10_battery_event()
824 level != hidpp->battery.level || in hidpp10_battery_event()
825 status != hidpp->battery.status; in hidpp10_battery_event()
828 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp10_battery_event()
832 hidpp->battery.level = level; in hidpp10_battery_event()
833 hidpp->battery.status = status; in hidpp10_battery_event()
834 if (hidpp->battery.ps) in hidpp10_battery_event()
835 power_supply_changed(hidpp->battery.ps); in hidpp10_battery_event()
905 struct hid_device *hdev = hidpp->hid_dev; in hidpp_unifying_init()
914 snprintf(hdev->uniq, sizeof(hdev->uniq), "%4phD", &serial); in hidpp_unifying_init()
915 dbg_hid("HID++ Unifying: Got serial: %s\n", hdev->uniq); in hidpp_unifying_init()
919 return -EIO; in hidpp_unifying_init()
921 snprintf(hdev->name, sizeof(hdev->name), "%s", name); in hidpp_unifying_init()
928 /* -------------------------------------------------------------------------- */
930 /* -------------------------------------------------------------------------- */
953 return -ENOENT; in hidpp_root_get_feature()
975 hidpp->protocol_major = 1; in hidpp_root_get_protocol_version()
976 hidpp->protocol_minor = 0; in hidpp_root_get_protocol_version()
982 return -EIO; in hidpp_root_get_protocol_version()
985 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_root_get_protocol_version()
987 return -EPROTO; in hidpp_root_get_protocol_version()
993 hid_err(hidpp->hid_dev, "%s: ping mismatch 0x%02x != 0x%02x\n", in hidpp_root_get_protocol_version()
995 return -EPROTO; in hidpp_root_get_protocol_version()
998 hidpp->protocol_major = response.rap.params[0]; in hidpp_root_get_protocol_version()
999 hidpp->protocol_minor = response.rap.params[1]; in hidpp_root_get_protocol_version()
1002 hid_info(hidpp->hid_dev, "HID++ %u.%u device connected.\n", in hidpp_root_get_protocol_version()
1003 hidpp->protocol_major, hidpp->protocol_minor); in hidpp_root_get_protocol_version()
1007 /* -------------------------------------------------------------------------- */
1009 /* -------------------------------------------------------------------------- */
1041 struct hid_device *hdev = hidpp->hid_dev; in hidpp_serial_init()
1049 snprintf(hdev->uniq, sizeof(hdev->uniq), "%4phD", &serial); in hidpp_serial_init()
1050 dbg_hid("HID++ DeviceInformation: Got serial: %s\n", hdev->uniq); in hidpp_serial_init()
1055 /* -------------------------------------------------------------------------- */
1057 /* -------------------------------------------------------------------------- */
1075 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_devicenametype_get_count()
1077 return -EPROTO; in hidpp_devicenametype_get_count()
1099 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_devicenametype_get_device_name()
1101 return -EPROTO; in hidpp_devicenametype_get_device_name()
1108 count = hidpp->very_long_report_length - 4; in hidpp_devicenametype_get_device_name()
1111 count = HIDPP_REPORT_LONG_LENGTH - 4; in hidpp_devicenametype_get_device_name()
1114 count = HIDPP_REPORT_SHORT_LENGTH - 4; in hidpp_devicenametype_get_device_name()
1117 return -EPROTO; in hidpp_devicenametype_get_device_name()
1155 __name_length - index); in hidpp_get_device_name()
1169 /* -------------------------------------------------------------------------- */
1171 /* -------------------------------------------------------------------------- */
1258 return -EIO; in hidpp20_batterylevel_get_battery_capacity()
1260 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_batterylevel_get_battery_capacity()
1262 return -EPROTO; in hidpp20_batterylevel_get_battery_capacity()
1286 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_batterylevel_get_battery_info()
1288 return -EPROTO; in hidpp20_batterylevel_get_battery_info()
1297 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS; in hidpp20_batterylevel_get_battery_info()
1299 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp20_batterylevel_get_battery_info()
1310 if (hidpp->battery.feature_index == 0xff) { in hidpp20_query_battery_info_1000()
1313 &hidpp->battery.feature_index, in hidpp20_query_battery_info_1000()
1320 hidpp->battery.feature_index, in hidpp20_query_battery_info_1000()
1327 hidpp->battery.feature_index); in hidpp20_query_battery_info_1000()
1331 hidpp->battery.status = status; in hidpp20_query_battery_info_1000()
1332 hidpp->battery.capacity = capacity; in hidpp20_query_battery_info_1000()
1333 hidpp->battery.level = level; in hidpp20_query_battery_info_1000()
1335 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp20_query_battery_info_1000()
1348 if (report->fap.feature_index != hidpp->battery.feature_index || in hidpp20_battery_event_1000()
1349 report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST) in hidpp20_battery_event_1000()
1352 status = hidpp20_batterylevel_map_status_capacity(report->fap.params, in hidpp20_battery_event_1000()
1358 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp20_battery_event_1000()
1361 changed = capacity != hidpp->battery.capacity || in hidpp20_battery_event_1000()
1362 level != hidpp->battery.level || in hidpp20_battery_event_1000()
1363 status != hidpp->battery.status; in hidpp20_battery_event_1000()
1366 hidpp->battery.level = level; in hidpp20_battery_event_1000()
1367 hidpp->battery.capacity = capacity; in hidpp20_battery_event_1000()
1368 hidpp->battery.status = status; in hidpp20_battery_event_1000()
1369 if (hidpp->battery.ps) in hidpp20_battery_event_1000()
1370 power_supply_changed(hidpp->battery.ps); in hidpp20_battery_event_1000()
1376 /* -------------------------------------------------------------------------- */
1378 /* -------------------------------------------------------------------------- */
1443 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_battery_get_battery_voltage()
1445 return -EPROTO; in hidpp20_battery_get_battery_voltage()
1450 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_VOLTAGE; in hidpp20_battery_get_battery_voltage()
1487 return ARRAY_SIZE(voltages) - i; in hidpp20_map_battery_capacity()
1499 if (hidpp->battery.voltage_feature_index == 0xff) { in hidpp20_query_battery_voltage_info()
1501 &hidpp->battery.voltage_feature_index, in hidpp20_query_battery_voltage_info()
1508 hidpp->battery.voltage_feature_index, in hidpp20_query_battery_voltage_info()
1514 hidpp->battery.status = status; in hidpp20_query_battery_voltage_info()
1515 hidpp->battery.voltage = voltage; in hidpp20_query_battery_voltage_info()
1516 hidpp->battery.capacity = hidpp20_map_battery_capacity(hidpp->hid_dev, in hidpp20_query_battery_voltage_info()
1518 hidpp->battery.level = level; in hidpp20_query_battery_voltage_info()
1519 hidpp->battery.charge_type = charge_type; in hidpp20_query_battery_voltage_info()
1520 hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING; in hidpp20_query_battery_voltage_info()
1531 if (report->fap.feature_index != hidpp->battery.voltage_feature_index || in hidpp20_battery_voltage_event()
1532 report->fap.funcindex_clientid != EVENT_BATTERY_VOLTAGE_STATUS_BROADCAST) in hidpp20_battery_voltage_event()
1535 status = hidpp20_battery_map_status_voltage(report->fap.params, &voltage, in hidpp20_battery_voltage_event()
1538 hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING; in hidpp20_battery_voltage_event()
1540 if (voltage != hidpp->battery.voltage || status != hidpp->battery.status) { in hidpp20_battery_voltage_event()
1541 hidpp->battery.voltage = voltage; in hidpp20_battery_voltage_event()
1542 hidpp->battery.capacity = hidpp20_map_battery_capacity(hidpp->hid_dev, in hidpp20_battery_voltage_event()
1544 hidpp->battery.status = status; in hidpp20_battery_voltage_event()
1545 hidpp->battery.level = level; in hidpp20_battery_voltage_event()
1546 hidpp->battery.charge_type = charge_type; in hidpp20_battery_voltage_event()
1547 if (hidpp->battery.ps) in hidpp20_battery_voltage_event()
1548 power_supply_changed(hidpp->battery.ps); in hidpp20_battery_voltage_event()
1553 /* -------------------------------------------------------------------------- */
1555 /* -------------------------------------------------------------------------- */
1579 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS || in hidpp20_unifiedbattery_get_capabilities()
1580 hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE) { in hidpp20_unifiedbattery_get_capabilities()
1590 return -EIO; in hidpp20_unifiedbattery_get_capabilities()
1592 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_unifiedbattery_get_capabilities()
1594 return -EPROTO; in hidpp20_unifiedbattery_get_capabilities()
1607 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_PERCENTAGE; in hidpp20_unifiedbattery_get_capabilities()
1608 hidpp->battery.supported_levels_1004 = 0; in hidpp20_unifiedbattery_get_capabilities()
1610 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS; in hidpp20_unifiedbattery_get_capabilities()
1611 hidpp->battery.supported_levels_1004 = params[0]; in hidpp20_unifiedbattery_get_capabilities()
1636 hid_info(hidpp->hid_dev, "%s: charging error", in hidpp20_unifiedbattery_map_status()
1637 hidpp->name); in hidpp20_unifiedbattery_map_status()
1651 battery_level &= hidpp->battery.supported_levels_1004; in hidpp20_unifiedbattery_map_level()
1680 return -EIO; in hidpp20_unifiedbattery_get_status()
1682 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_unifiedbattery_get_status()
1684 return -EPROTO; in hidpp20_unifiedbattery_get_status()
1703 if (hidpp->battery.feature_index == 0xff) { in hidpp20_query_battery_info_1004()
1706 &hidpp->battery.feature_index, in hidpp20_query_battery_info_1004()
1713 hidpp->battery.feature_index); in hidpp20_query_battery_info_1004()
1718 hidpp->battery.feature_index, in hidpp20_query_battery_info_1004()
1725 hidpp->capabilities |= HIDPP_CAPABILITY_UNIFIED_BATTERY; in hidpp20_query_battery_info_1004()
1726 hidpp->battery.capacity = state_of_charge; in hidpp20_query_battery_info_1004()
1727 hidpp->battery.status = status; in hidpp20_query_battery_info_1004()
1728 hidpp->battery.level = level; in hidpp20_query_battery_info_1004()
1729 hidpp->battery.online = true; in hidpp20_query_battery_info_1004()
1738 u8 *params = (u8 *)report->fap.params; in hidpp20_battery_event_1004()
1742 if (report->fap.feature_index != hidpp->battery.feature_index || in hidpp20_battery_event_1004()
1743 report->fap.funcindex_clientid != EVENT_UNIFIED_BATTERY_STATUS_EVENT) in hidpp20_battery_event_1004()
1750 changed = status != hidpp->battery.status || in hidpp20_battery_event_1004()
1751 (state_of_charge != hidpp->battery.capacity && in hidpp20_battery_event_1004()
1752 hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE) || in hidpp20_battery_event_1004()
1753 (level != hidpp->battery.level && in hidpp20_battery_event_1004()
1754 hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS); in hidpp20_battery_event_1004()
1757 hidpp->battery.capacity = state_of_charge; in hidpp20_battery_event_1004()
1758 hidpp->battery.status = status; in hidpp20_battery_event_1004()
1759 hidpp->battery.level = level; in hidpp20_battery_event_1004()
1760 if (hidpp->battery.ps) in hidpp20_battery_event_1004()
1761 power_supply_changed(hidpp->battery.ps); in hidpp20_battery_event_1004()
1767 /* -------------------------------------------------------------------------- */
1769 /* -------------------------------------------------------------------------- */
1792 val->intval = hidpp->battery.status; in hidpp_battery_get_property()
1795 val->intval = hidpp->battery.capacity; in hidpp_battery_get_property()
1798 val->intval = hidpp->battery.level; in hidpp_battery_get_property()
1801 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in hidpp_battery_get_property()
1804 val->intval = hidpp->battery.online; in hidpp_battery_get_property()
1807 if (!strncmp(hidpp->name, "Logitech ", 9)) in hidpp_battery_get_property()
1808 val->strval = hidpp->name + 9; in hidpp_battery_get_property()
1810 val->strval = hidpp->name; in hidpp_battery_get_property()
1813 val->strval = "Logitech"; in hidpp_battery_get_property()
1816 val->strval = hidpp->hid_dev->uniq; in hidpp_battery_get_property()
1820 val->intval = hidpp->battery.voltage * 1000; in hidpp_battery_get_property()
1823 val->intval = hidpp->battery.charge_type; in hidpp_battery_get_property()
1826 ret = -EINVAL; in hidpp_battery_get_property()
1833 /* -------------------------------------------------------------------------- */
1835 /* -------------------------------------------------------------------------- */
1850 /* -------------------------------------------------------------------------- */
1852 /* -------------------------------------------------------------------------- */
1867 …tControl/blob/acd972be0468e039b93aae81221f20a54d2d60f7/src/devices/logitech_g633_g933_935.c#L44-L52 in hidpp20_map_adc_measurement_1f20_capacity()
1894 return ARRAY_SIZE(voltages) - i; in hidpp20_map_adc_measurement_1f20_capacity()
1947 hid_dbg(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_get_adc_measurement_1f20()
1960 if (hidpp->battery.adc_measurement_feature_index == 0xff) { in hidpp20_query_adc_measurement_info_1f20()
1964 &hidpp->battery.adc_measurement_feature_index, in hidpp20_query_adc_measurement_info_1f20()
1969 hidpp->capabilities |= HIDPP_CAPABILITY_ADC_MEASUREMENT; in hidpp20_query_adc_measurement_info_1f20()
1972 hidpp->battery.online = hidpp20_get_adc_measurement_1f20(hidpp, in hidpp20_query_adc_measurement_info_1f20()
1973 hidpp->battery.adc_measurement_feature_index, in hidpp20_query_adc_measurement_info_1f20()
1974 &hidpp->battery.status, in hidpp20_query_adc_measurement_info_1f20()
1975 &hidpp->battery.voltage); in hidpp20_query_adc_measurement_info_1f20()
1976 hidpp->battery.capacity = hidpp20_map_adc_measurement_1f20_capacity(hidpp->hid_dev, in hidpp20_query_adc_measurement_info_1f20()
1977 hidpp->battery.voltage); in hidpp20_query_adc_measurement_info_1f20()
1989 if (report->fap.feature_index != hidpp->battery.adc_measurement_feature_index || in hidpp20_adc_measurement_event_1f20()
1990 report->fap.funcindex_clientid != EVENT_ADC_MEASUREMENT_STATUS_BROADCAST) in hidpp20_adc_measurement_event_1f20()
1993 status = hidpp20_map_adc_measurement_1f20(report->fap.params, &voltage); in hidpp20_adc_measurement_event_1f20()
1995 hidpp->battery.online = status != POWER_SUPPLY_STATUS_UNKNOWN; in hidpp20_adc_measurement_event_1f20()
1997 if (voltage != hidpp->battery.voltage || status != hidpp->battery.status) { in hidpp20_adc_measurement_event_1f20()
1998 hidpp->battery.status = status; in hidpp20_adc_measurement_event_1f20()
1999 hidpp->battery.voltage = voltage; in hidpp20_adc_measurement_event_1f20()
2000 hidpp->battery.capacity = hidpp20_map_adc_measurement_1f20_capacity(hidpp->hid_dev, voltage); in hidpp20_adc_measurement_event_1f20()
2001 if (hidpp->battery.ps) in hidpp20_adc_measurement_event_1f20()
2002 power_supply_changed(hidpp->battery.ps); in hidpp20_adc_measurement_event_1f20()
2008 /* -------------------------------------------------------------------------- */
2009 /* 0x2120: Hi-resolution scrolling */
2010 /* -------------------------------------------------------------------------- */
2042 /* -------------------------------------------------------------------------- */
2044 /* -------------------------------------------------------------------------- */
2073 hid_warn(hidpp->hid_dev, in hidpp_hrw_get_wheel_capability()
2101 /* -------------------------------------------------------------------------- */
2103 /* -------------------------------------------------------------------------- */
2120 if (hidpp->battery.feature_index == 0xff) { in hidpp_solar_request_battery_event()
2123 &hidpp->battery.solar_feature_index, in hidpp_solar_request_battery_event()
2130 hidpp->battery.solar_feature_index, in hidpp_solar_request_battery_event()
2134 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_solar_request_battery_event()
2136 return -EPROTO; in hidpp_solar_request_battery_event()
2141 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp_solar_request_battery_event()
2153 function = report->fap.funcindex_clientid; in hidpp_solar_battery_event()
2156 if (report->fap.feature_index != hidpp->battery.solar_feature_index || in hidpp_solar_battery_event()
2162 capacity = report->fap.params[0]; in hidpp_solar_battery_event()
2166 lux = (report->fap.params[1] << 8) | report->fap.params[2]; in hidpp_solar_battery_event()
2174 if (capacity < hidpp->battery.capacity) in hidpp_solar_battery_event()
2184 hidpp->battery.online = true; in hidpp_solar_battery_event()
2185 if (capacity != hidpp->battery.capacity || in hidpp_solar_battery_event()
2186 status != hidpp->battery.status) { in hidpp_solar_battery_event()
2187 hidpp->battery.capacity = capacity; in hidpp_solar_battery_event()
2188 hidpp->battery.status = status; in hidpp_solar_battery_event()
2189 if (hidpp->battery.ps) in hidpp_solar_battery_event()
2190 power_supply_changed(hidpp->battery.ps); in hidpp_solar_battery_event()
2196 /* -------------------------------------------------------------------------- */
2198 /* -------------------------------------------------------------------------- */
2212 * send a set state command to the device by reading the current items->state
2224 CMD_TOUCHPAD_FW_ITEMS_SET, &items->state, 1, &response); in hidpp_touchpad_fw_items_set()
2227 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_touchpad_fw_items_set()
2229 return -EPROTO; in hidpp_touchpad_fw_items_set()
2234 items->presence = params[0]; in hidpp_touchpad_fw_items_set()
2235 items->desired_state = params[1]; in hidpp_touchpad_fw_items_set()
2236 items->state = params[2]; in hidpp_touchpad_fw_items_set()
2237 items->persistent = params[3]; in hidpp_touchpad_fw_items_set()
2242 /* -------------------------------------------------------------------------- */
2244 /* -------------------------------------------------------------------------- */
2297 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_touchpad_get_raw_info()
2299 return -EPROTO; in hidpp_touchpad_get_raw_info()
2304 raw_info->x_size = get_unaligned_be16(&params[0]); in hidpp_touchpad_get_raw_info()
2305 raw_info->y_size = get_unaligned_be16(&params[2]); in hidpp_touchpad_get_raw_info()
2306 raw_info->z_range = params[4]; in hidpp_touchpad_get_raw_info()
2307 raw_info->area_range = params[5]; in hidpp_touchpad_get_raw_info()
2308 raw_info->maxcontacts = params[7]; in hidpp_touchpad_get_raw_info()
2309 raw_info->origin = params[8]; in hidpp_touchpad_get_raw_info()
2311 raw_info->res = get_unaligned_be16(&params[13]) * 2 / 51; in hidpp_touchpad_get_raw_info()
2324 * bit 0 - enable raw in hidpp_touchpad_set_raw_report_state()
2325 * bit 1 - 16bit Z, no area in hidpp_touchpad_set_raw_report_state()
2326 * bit 2 - enhanced sensitivity in hidpp_touchpad_set_raw_report_state()
2327 * bit 3 - width, height (4 bits each) instead of area in hidpp_touchpad_set_raw_report_state()
2328 * bit 4 - send raw + gestures (degrades smoothness) in hidpp_touchpad_set_raw_report_state()
2329 * remaining bits - reserved in hidpp_touchpad_set_raw_report_state()
2343 finger->x = x_m << 6 | data[1]; in hidpp_touchpad_touch_event()
2344 finger->y = y_m << 6 | data[3]; in hidpp_touchpad_touch_event()
2346 finger->contact_type = data[0] >> 6; in hidpp_touchpad_touch_event()
2347 finger->contact_status = data[2] >> 6; in hidpp_touchpad_touch_event()
2349 finger->z = data[4]; in hidpp_touchpad_touch_event()
2350 finger->area = data[5]; in hidpp_touchpad_touch_event()
2351 finger->finger_id = data[6] >> 4; in hidpp_touchpad_touch_event()
2358 raw_xy->end_of_frame = data[8] & 0x01; in hidpp_touchpad_raw_xy_event()
2359 raw_xy->spurious_flag = (data[8] >> 1) & 0x01; in hidpp_touchpad_raw_xy_event()
2360 raw_xy->finger_count = data[15] & 0x0f; in hidpp_touchpad_raw_xy_event()
2361 raw_xy->button = (data[8] >> 2) & 0x01; in hidpp_touchpad_raw_xy_event()
2363 if (raw_xy->finger_count) { in hidpp_touchpad_raw_xy_event()
2364 hidpp_touchpad_touch_event(&data[2], &raw_xy->fingers[0]); in hidpp_touchpad_raw_xy_event()
2365 hidpp_touchpad_touch_event(&data[9], &raw_xy->fingers[1]); in hidpp_touchpad_raw_xy_event()
2369 /* -------------------------------------------------------------------------- */
2371 /* -------------------------------------------------------------------------- */
2402 #define HIDPP_FF_EFFECTID_NONE -1
2403 #define HIDPP_FF_EFFECTID_AUTOCENTER -2
2443 -1
2450 -1
2472 for (i = 0; i < data->num_effects; i++) in hidpp_ff_find_effect()
2473 if (data->effect_ids[i] == effect_id) in hidpp_ff_find_effect()
2482 struct hidpp_ff_private_data *data = wd->data; in hidpp_ff_work_handler()
2488 switch (wd->effect_id) { in hidpp_ff_work_handler()
2490 wd->params[0] = data->slot_autocenter; in hidpp_ff_work_handler()
2497 wd->params[0] = hidpp_ff_find_effect(data, wd->effect_id); in hidpp_ff_work_handler()
2502 ret = hidpp_send_fap_command_sync(data->hidpp, data->feature_index, in hidpp_ff_work_handler()
2503 wd->command, wd->params, wd->size, &response); in hidpp_ff_work_handler()
2506 hid_err(data->hidpp->hid_dev, "Failed to send command to device!\n"); in hidpp_ff_work_handler()
2511 switch (wd->command) { in hidpp_ff_work_handler()
2514 if (slot > 0 && slot <= data->num_effects) { in hidpp_ff_work_handler()
2515 if (wd->effect_id >= 0) in hidpp_ff_work_handler()
2517 data->effect_ids[slot-1] = wd->effect_id; in hidpp_ff_work_handler()
2518 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) in hidpp_ff_work_handler()
2520 data->slot_autocenter = slot; in hidpp_ff_work_handler()
2524 if (wd->effect_id >= 0) in hidpp_ff_work_handler()
2526 data->effect_ids[wd->params[0]-1] = -1; in hidpp_ff_work_handler()
2527 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) in hidpp_ff_work_handler()
2529 data->slot_autocenter = 0; in hidpp_ff_work_handler()
2532 data->gain = (wd->params[0] << 8) + wd->params[1]; in hidpp_ff_work_handler()
2535 data->range = (wd->params[0] << 8) + wd->params[1]; in hidpp_ff_work_handler()
2543 atomic_dec(&data->workqueue_size); in hidpp_ff_work_handler()
2553 return -ENOMEM; in hidpp_ff_queue_work()
2555 INIT_WORK(&wd->work, hidpp_ff_work_handler); in hidpp_ff_queue_work()
2557 wd->data = data; in hidpp_ff_queue_work()
2558 wd->effect_id = effect_id; in hidpp_ff_queue_work()
2559 wd->command = command; in hidpp_ff_queue_work()
2560 wd->size = size; in hidpp_ff_queue_work()
2561 memcpy(wd->params, params, size); in hidpp_ff_queue_work()
2563 s = atomic_inc_return(&data->workqueue_size); in hidpp_ff_queue_work()
2564 queue_work(data->wq, &wd->work); in hidpp_ff_queue_work()
2568 …hid_warn(data->hidpp->hid_dev, "Force feedback command queue contains %d commands, causing substan… in hidpp_ff_queue_work()
2575 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_upload_effect()
2581 params[2] = effect->replay.length >> 8; in hidpp_ff_upload_effect()
2582 params[3] = effect->replay.length & 255; in hidpp_ff_upload_effect()
2583 params[4] = effect->replay.delay >> 8; in hidpp_ff_upload_effect()
2584 params[5] = effect->replay.delay & 255; in hidpp_ff_upload_effect()
2586 switch (effect->type) { in hidpp_ff_upload_effect()
2588 force = (effect->u.constant.level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2592 params[8] = effect->u.constant.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
2593 params[9] = effect->u.constant.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
2594 params[10] = effect->u.constant.envelope.attack_length & 255; in hidpp_ff_upload_effect()
2595 params[11] = effect->u.constant.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
2596 params[12] = effect->u.constant.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
2597 params[13] = effect->u.constant.envelope.fade_length & 255; in hidpp_ff_upload_effect()
2600 effect->u.constant.level, in hidpp_ff_upload_effect()
2601 effect->direction, force); in hidpp_ff_upload_effect()
2602 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n", in hidpp_ff_upload_effect()
2603 effect->u.constant.envelope.attack_level, in hidpp_ff_upload_effect()
2604 effect->u.constant.envelope.attack_length, in hidpp_ff_upload_effect()
2605 effect->u.constant.envelope.fade_level, in hidpp_ff_upload_effect()
2606 effect->u.constant.envelope.fade_length); in hidpp_ff_upload_effect()
2610 switch (effect->u.periodic.waveform) { in hidpp_ff_upload_effect()
2627 …hid_err(data->hidpp->hid_dev, "Unexpected periodic waveform type %i!\n", effect->u.periodic.wavefo… in hidpp_ff_upload_effect()
2628 return -EINVAL; in hidpp_ff_upload_effect()
2630 force = (effect->u.periodic.magnitude * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2631 params[6] = effect->u.periodic.magnitude >> 8; in hidpp_ff_upload_effect()
2632 params[7] = effect->u.periodic.magnitude & 255; in hidpp_ff_upload_effect()
2633 params[8] = effect->u.periodic.offset >> 8; in hidpp_ff_upload_effect()
2634 params[9] = effect->u.periodic.offset & 255; in hidpp_ff_upload_effect()
2635 params[10] = effect->u.periodic.period >> 8; in hidpp_ff_upload_effect()
2636 params[11] = effect->u.periodic.period & 255; in hidpp_ff_upload_effect()
2637 params[12] = effect->u.periodic.phase >> 8; in hidpp_ff_upload_effect()
2638 params[13] = effect->u.periodic.phase & 255; in hidpp_ff_upload_effect()
2639 params[14] = effect->u.periodic.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
2640 params[15] = effect->u.periodic.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
2641 params[16] = effect->u.periodic.envelope.attack_length & 255; in hidpp_ff_upload_effect()
2642 params[17] = effect->u.periodic.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
2643 params[18] = effect->u.periodic.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
2644 params[19] = effect->u.periodic.envelope.fade_length & 255; in hidpp_ff_upload_effect()
2646 dbg_hid("Uploading periodic force mag=%d/dir=%d, offset=%d, period=%d ms, phase=%d\n", in hidpp_ff_upload_effect()
2647 effect->u.periodic.magnitude, effect->direction, in hidpp_ff_upload_effect()
2648 effect->u.periodic.offset, in hidpp_ff_upload_effect()
2649 effect->u.periodic.period, in hidpp_ff_upload_effect()
2650 effect->u.periodic.phase); in hidpp_ff_upload_effect()
2651 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n", in hidpp_ff_upload_effect()
2652 effect->u.periodic.envelope.attack_level, in hidpp_ff_upload_effect()
2653 effect->u.periodic.envelope.attack_length, in hidpp_ff_upload_effect()
2654 effect->u.periodic.envelope.fade_level, in hidpp_ff_upload_effect()
2655 effect->u.periodic.envelope.fade_length); in hidpp_ff_upload_effect()
2660 force = (effect->u.ramp.start_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2663 force = (effect->u.ramp.end_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2666 params[10] = effect->u.ramp.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
2667 params[11] = effect->u.ramp.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
2668 params[12] = effect->u.ramp.envelope.attack_length & 255; in hidpp_ff_upload_effect()
2669 params[13] = effect->u.ramp.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
2670 params[14] = effect->u.ramp.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
2671 params[15] = effect->u.ramp.envelope.fade_length & 255; in hidpp_ff_upload_effect()
2673 dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n", in hidpp_ff_upload_effect()
2674 effect->u.ramp.start_level, in hidpp_ff_upload_effect()
2675 effect->u.ramp.end_level, in hidpp_ff_upload_effect()
2676 effect->direction, force); in hidpp_ff_upload_effect()
2677 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n", in hidpp_ff_upload_effect()
2678 effect->u.ramp.envelope.attack_level, in hidpp_ff_upload_effect()
2679 effect->u.ramp.envelope.attack_length, in hidpp_ff_upload_effect()
2680 effect->u.ramp.envelope.fade_level, in hidpp_ff_upload_effect()
2681 effect->u.ramp.envelope.fade_length); in hidpp_ff_upload_effect()
2687 params[1] = HIDPP_FF_CONDITION_CMDS[effect->type - FF_SPRING]; in hidpp_ff_upload_effect()
2688 params[6] = effect->u.condition[0].left_saturation >> 9; in hidpp_ff_upload_effect()
2689 params[7] = (effect->u.condition[0].left_saturation >> 1) & 255; in hidpp_ff_upload_effect()
2690 params[8] = effect->u.condition[0].left_coeff >> 8; in hidpp_ff_upload_effect()
2691 params[9] = effect->u.condition[0].left_coeff & 255; in hidpp_ff_upload_effect()
2692 params[10] = effect->u.condition[0].deadband >> 9; in hidpp_ff_upload_effect()
2693 params[11] = (effect->u.condition[0].deadband >> 1) & 255; in hidpp_ff_upload_effect()
2694 params[12] = effect->u.condition[0].center >> 8; in hidpp_ff_upload_effect()
2695 params[13] = effect->u.condition[0].center & 255; in hidpp_ff_upload_effect()
2696 params[14] = effect->u.condition[0].right_coeff >> 8; in hidpp_ff_upload_effect()
2697 params[15] = effect->u.condition[0].right_coeff & 255; in hidpp_ff_upload_effect()
2698 params[16] = effect->u.condition[0].right_saturation >> 9; in hidpp_ff_upload_effect()
2699 params[17] = (effect->u.condition[0].right_saturation >> 1) & 255; in hidpp_ff_upload_effect()
2702 HIDPP_FF_CONDITION_NAMES[effect->type - FF_SPRING], in hidpp_ff_upload_effect()
2703 effect->u.condition[0].left_coeff, in hidpp_ff_upload_effect()
2704 effect->u.condition[0].left_saturation, in hidpp_ff_upload_effect()
2705 effect->u.condition[0].right_coeff, in hidpp_ff_upload_effect()
2706 effect->u.condition[0].right_saturation); in hidpp_ff_upload_effect()
2708 effect->u.condition[0].deadband, in hidpp_ff_upload_effect()
2709 effect->u.condition[0].center); in hidpp_ff_upload_effect()
2712 hid_err(data->hidpp->hid_dev, "Unexpected force type %i!\n", effect->type); in hidpp_ff_upload_effect()
2713 return -EINVAL; in hidpp_ff_upload_effect()
2716 return hidpp_ff_queue_work(data, effect->id, HIDPP_FF_DOWNLOAD_EFFECT, params, size); in hidpp_ff_upload_effect()
2721 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_playback()
2733 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_erase_effect()
2743 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_set_autocenter()
2765 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_set_gain()
2781 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_range_show()
2782 struct input_dev *idev = hidinput->input; in hidpp_ff_range_show()
2783 struct hidpp_ff_private_data *data = idev->ff->private; in hidpp_ff_range_show()
2785 return scnprintf(buf, PAGE_SIZE, "%u\n", data->range); in hidpp_ff_range_show()
2791 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_range_store()
2792 struct input_dev *idev = hidinput->input; in hidpp_ff_range_store()
2793 struct hidpp_ff_private_data *data = idev->ff->private; in hidpp_ff_range_store()
2802 hidpp_ff_queue_work(data, -1, HIDPP_FF_SET_APERTURE, params, ARRAY_SIZE(params)); in hidpp_ff_range_store()
2811 struct hidpp_ff_private_data *data = ff->private; in hidpp_ff_destroy()
2812 struct hid_device *hid = data->hidpp->hid_dev; in hidpp_ff_destroy()
2816 device_remove_file(&hid->dev, &dev_attr_range); in hidpp_ff_destroy()
2817 destroy_workqueue(data->wq); in hidpp_ff_destroy()
2818 kfree(data->effect_ids); in hidpp_ff_destroy()
2824 struct hid_device *hid = hidpp->hid_dev; in hidpp_ff_init()
2830 int error, j, num_slots = data->num_effects; in hidpp_ff_init()
2835 return -ENODEV; in hidpp_ff_init()
2838 if (list_empty(&hid->inputs)) { in hidpp_ff_init()
2840 return -ENODEV; in hidpp_ff_init()
2842 hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_init()
2843 dev = hidinput->input; in hidpp_ff_init()
2847 return -EINVAL; in hidpp_ff_init()
2851 udesc = &(hid_to_usb_dev(hid)->descriptor); in hidpp_ff_init()
2852 bcdDevice = le16_to_cpu(udesc->bcdDevice); in hidpp_ff_init()
2857 set_bit(hidpp_ff_effects[j], dev->ffbit); in hidpp_ff_init()
2860 set_bit(hidpp_ff_effects_v2[j], dev->ffbit); in hidpp_ff_init()
2874 return -ENOMEM; in hidpp_ff_init()
2875 data->effect_ids = kcalloc(num_slots, sizeof(int), GFP_KERNEL); in hidpp_ff_init()
2876 if (!data->effect_ids) { in hidpp_ff_init()
2878 return -ENOMEM; in hidpp_ff_init()
2880 data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue"); in hidpp_ff_init()
2881 if (!data->wq) { in hidpp_ff_init()
2882 kfree(data->effect_ids); in hidpp_ff_init()
2884 return -ENOMEM; in hidpp_ff_init()
2887 data->hidpp = hidpp; in hidpp_ff_init()
2888 data->version = version; in hidpp_ff_init()
2890 data->effect_ids[j] = -1; in hidpp_ff_init()
2892 ff = dev->ff; in hidpp_ff_init()
2893 ff->private = data; in hidpp_ff_init()
2895 ff->upload = hidpp_ff_upload_effect; in hidpp_ff_init()
2896 ff->erase = hidpp_ff_erase_effect; in hidpp_ff_init()
2897 ff->playback = hidpp_ff_playback; in hidpp_ff_init()
2898 ff->set_gain = hidpp_ff_set_gain; in hidpp_ff_init()
2899 ff->set_autocenter = hidpp_ff_set_autocenter; in hidpp_ff_init()
2900 ff->destroy = hidpp_ff_destroy; in hidpp_ff_init()
2903 error = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range); in hidpp_ff_init()
2905 hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d!\n", error); in hidpp_ff_init()
2908 atomic_set(&data->workqueue_size, 0); in hidpp_ff_init()
2922 /* -------------------------------------------------------------------------- */
2924 /* -------------------------------------------------------------------------- */
2942 return -1; in wtp_input_mapping()
2948 struct wtp_data *wd = hidpp->private_data; in wtp_populate_input()
2950 __set_bit(EV_ABS, input_dev->evbit); in wtp_populate_input()
2951 __set_bit(EV_KEY, input_dev->evbit); in wtp_populate_input()
2952 __clear_bit(EV_REL, input_dev->evbit); in wtp_populate_input()
2953 __clear_bit(EV_LED, input_dev->evbit); in wtp_populate_input()
2955 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0); in wtp_populate_input()
2956 input_abs_set_res(input_dev, ABS_MT_POSITION_X, wd->resolution); in wtp_populate_input()
2957 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0); in wtp_populate_input()
2958 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, wd->resolution); in wtp_populate_input()
2965 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) in wtp_populate_input()
2968 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); in wtp_populate_input()
2970 input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER | in wtp_populate_input()
2977 struct wtp_data *wd = hidpp->private_data; in wtp_touch_event()
2980 if (!touch_report->finger_id || touch_report->contact_type) in wtp_touch_event()
2984 slot = input_mt_get_slot_by_key(hidpp->input, touch_report->finger_id); in wtp_touch_event()
2986 input_mt_slot(hidpp->input, slot); in wtp_touch_event()
2987 input_mt_report_slot_state(hidpp->input, MT_TOOL_FINGER, in wtp_touch_event()
2988 touch_report->contact_status); in wtp_touch_event()
2989 if (touch_report->contact_status) { in wtp_touch_event()
2990 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_X, in wtp_touch_event()
2991 touch_report->x); in wtp_touch_event()
2992 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_Y, in wtp_touch_event()
2993 wd->flip_y ? wd->y_size - touch_report->y : in wtp_touch_event()
2994 touch_report->y); in wtp_touch_event()
2995 input_event(hidpp->input, EV_ABS, ABS_MT_PRESSURE, in wtp_touch_event()
2996 touch_report->area); in wtp_touch_event()
3006 wtp_touch_event(hidpp, &(raw->fingers[i])); in wtp_send_raw_xy_event()
3008 if (raw->end_of_frame && in wtp_send_raw_xy_event()
3009 !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS)) in wtp_send_raw_xy_event()
3010 input_event(hidpp->input, EV_KEY, BTN_LEFT, raw->button); in wtp_send_raw_xy_event()
3012 if (raw->end_of_frame || raw->finger_count <= 2) { in wtp_send_raw_xy_event()
3013 input_mt_sync_frame(hidpp->input); in wtp_send_raw_xy_event()
3014 input_sync(hidpp->input); in wtp_send_raw_xy_event()
3020 struct wtp_data *wd = hidpp->private_data; in wtp_mouse_raw_xy_event()
3046 .finger_count = wd->maxcontacts, in wtp_mouse_raw_xy_event()
3060 struct wtp_data *wd = hidpp->private_data; in wtp_raw_event()
3064 if (!wd || !hidpp->input) in wtp_raw_event()
3074 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) { in wtp_raw_event()
3075 input_event(hidpp->input, EV_KEY, BTN_LEFT, in wtp_raw_event()
3077 input_event(hidpp->input, EV_KEY, BTN_RIGHT, in wtp_raw_event()
3079 input_sync(hidpp->input); in wtp_raw_event()
3088 if ((report->fap.feature_index != wd->mt_feature_index) || in wtp_raw_event()
3089 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY)) in wtp_raw_event()
3102 struct wtp_data *wd = hidpp->private_data; in wtp_get_config()
3108 &wd->mt_feature_index, &feature_type); in wtp_get_config()
3113 ret = hidpp_touchpad_get_raw_info(hidpp, wd->mt_feature_index, in wtp_get_config()
3118 wd->x_size = raw_info.x_size; in wtp_get_config()
3119 wd->y_size = raw_info.y_size; in wtp_get_config()
3120 wd->maxcontacts = raw_info.maxcontacts; in wtp_get_config()
3121 wd->flip_y = raw_info.origin == TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT; in wtp_get_config()
3122 wd->resolution = raw_info.res; in wtp_get_config()
3123 if (!wd->resolution) in wtp_get_config()
3124 wd->resolution = WTP_MANUAL_RESOLUTION; in wtp_get_config()
3134 wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data), in wtp_allocate()
3137 return -ENOMEM; in wtp_allocate()
3139 hidpp->private_data = wd; in wtp_allocate()
3147 struct wtp_data *wd = hidpp->private_data; in wtp_connect()
3150 if (!wd->x_size) { in wtp_connect()
3158 return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index, in wtp_connect()
3162 /* ------------------------------------------------------------------------- */
3164 /* ------------------------------------------------------------------------- */
3173 * is different from the odd press and the even press.
3175 * forward button -> Super_R
3176 * backward button -> Super_L+'d' (press only)
3177 * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
3178 * 2nd time: left-click (press only)
3179 * NB: press-only means that when the button is pressed, the
3187 * - it never sends a keyboard key event
3188 * - for the three mouse button it sends:
3189 * middle button press 11<xx>0a 3500af00...
3190 * side 1 button (forward) press 11<xx>0a 3500b000...
3191 * side 2 button (backward) press 11<xx>0a 3500ae00...
3229 if (!hidpp->input) { in m560_raw_event()
3231 return -EINVAL; in m560_raw_event()
3245 * data[1] = device-id in m560_raw_event()
3247 * data[5] = 0xaf -> middle in m560_raw_event()
3248 * 0xb0 -> forward in m560_raw_event()
3249 * 0xae -> backward in m560_raw_event()
3250 * 0x00 -> release all in m560_raw_event()
3256 input_report_key(hidpp->input, BTN_MIDDLE, 1); in m560_raw_event()
3259 input_report_key(hidpp->input, BTN_FORWARD, 1); in m560_raw_event()
3262 input_report_key(hidpp->input, BTN_BACK, 1); in m560_raw_event()
3265 input_report_key(hidpp->input, BTN_BACK, 0); in m560_raw_event()
3266 input_report_key(hidpp->input, BTN_FORWARD, 0); in m560_raw_event()
3267 input_report_key(hidpp->input, BTN_MIDDLE, 0); in m560_raw_event()
3273 input_sync(hidpp->input); in m560_raw_event()
3287 input_report_key(hidpp->input, BTN_LEFT, in m560_raw_event()
3289 input_report_key(hidpp->input, BTN_RIGHT, in m560_raw_event()
3293 input_report_rel(hidpp->input, REL_HWHEEL, -1); in m560_raw_event()
3294 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, in m560_raw_event()
3295 -120); in m560_raw_event()
3297 input_report_rel(hidpp->input, REL_HWHEEL, 1); in m560_raw_event()
3298 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, in m560_raw_event()
3303 input_report_rel(hidpp->input, REL_X, v); in m560_raw_event()
3306 input_report_rel(hidpp->input, REL_Y, v); in m560_raw_event()
3310 hidpp_scroll_counter_handle_scroll(hidpp->input, in m560_raw_event()
3311 &hidpp->vertical_wheel_counter, v); in m560_raw_event()
3313 input_sync(hidpp->input); in m560_raw_event()
3322 __set_bit(EV_KEY, input_dev->evbit); in m560_populate_input()
3323 __set_bit(BTN_MIDDLE, input_dev->keybit); in m560_populate_input()
3324 __set_bit(BTN_RIGHT, input_dev->keybit); in m560_populate_input()
3325 __set_bit(BTN_LEFT, input_dev->keybit); in m560_populate_input()
3326 __set_bit(BTN_BACK, input_dev->keybit); in m560_populate_input()
3327 __set_bit(BTN_FORWARD, input_dev->keybit); in m560_populate_input()
3329 __set_bit(EV_REL, input_dev->evbit); in m560_populate_input()
3330 __set_bit(REL_X, input_dev->relbit); in m560_populate_input()
3331 __set_bit(REL_Y, input_dev->relbit); in m560_populate_input()
3332 __set_bit(REL_WHEEL, input_dev->relbit); in m560_populate_input()
3333 __set_bit(REL_HWHEEL, input_dev->relbit); in m560_populate_input()
3334 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit); in m560_populate_input()
3335 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit); in m560_populate_input()
3342 return -1; in m560_input_mapping()
3345 /* ------------------------------------------------------------------------- */
3347 /* ------------------------------------------------------------------------- */
3352 * tap-to-click but the setting is not remembered accross reset, annoying some
3365 struct k400_private_data *k400 = hidpp->private_data; in k400_disable_tap_to_click()
3370 if (!k400->feature_index) { in k400_disable_tap_to_click()
3373 &k400->feature_index, &feature_type); in k400_disable_tap_to_click()
3379 ret = hidpp_touchpad_fw_items_set(hidpp, k400->feature_index, &items); in k400_disable_tap_to_click()
3391 k400 = devm_kzalloc(&hdev->dev, sizeof(struct k400_private_data), in k400_allocate()
3394 return -ENOMEM; in k400_allocate()
3396 hidpp->private_data = k400; in k400_allocate()
3411 /* ------------------------------------------------------------------------- */
3413 /* ------------------------------------------------------------------------- */
3429 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_ff_set_autocenter()
3434 hid_warn(hidpp->hid_dev, "Failed to autocenter device!\n"); in g920_ff_set_autocenter()
3436 data->slot_autocenter = response.fap.params[0]; in g920_ff_set_autocenter()
3452 &data->feature_index, &feature_type); in g920_get_config()
3457 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
3464 hid_err(hidpp->hid_dev, in g920_get_config()
3466 return -EPROTO; in g920_get_config()
3469 data->num_effects = response.fap.params[0] - HIDPP_FF_RESERVED_SLOTS; in g920_get_config()
3472 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
3477 hid_warn(hidpp->hid_dev, "Failed to reset all forces!\n"); in g920_get_config()
3479 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
3484 hid_warn(hidpp->hid_dev, in g920_get_config()
3487 data->range = ret ? in g920_get_config()
3491 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
3496 hid_warn(hidpp->hid_dev, in g920_get_config()
3498 data->gain = ret ? in g920_get_config()
3506 /* -------------------------------------------------------------------------- */
3508 /* -------------------------------------------------------------------------- */
3515 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) in lg_dinovo_input_mapping()
3518 switch (usage->hid & HID_USAGE) { in lg_dinovo_input_mapping()
3526 /* -------------------------------------------------------------------------- */
3528 /* -------------------------------------------------------------------------- */
3541 if (!hidpp->input) in hidpp10_wheel_raw_event()
3542 return -EINVAL; in hidpp10_wheel_raw_event()
3553 input_report_rel(hidpp->input, REL_WHEEL, value); in hidpp10_wheel_raw_event()
3554 input_report_rel(hidpp->input, REL_WHEEL_HI_RES, value * 120); in hidpp10_wheel_raw_event()
3555 input_report_rel(hidpp->input, REL_HWHEEL, hvalue); in hidpp10_wheel_raw_event()
3556 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, hvalue * 120); in hidpp10_wheel_raw_event()
3557 input_sync(hidpp->input); in hidpp10_wheel_raw_event()
3565 __set_bit(EV_REL, input_dev->evbit); in hidpp10_wheel_populate_input()
3566 __set_bit(REL_WHEEL, input_dev->relbit); in hidpp10_wheel_populate_input()
3567 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit); in hidpp10_wheel_populate_input()
3568 __set_bit(REL_HWHEEL, input_dev->relbit); in hidpp10_wheel_populate_input()
3569 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit); in hidpp10_wheel_populate_input()
3572 /* -------------------------------------------------------------------------- */
3574 /* -------------------------------------------------------------------------- */
3587 if (!hidpp->input) in hidpp10_extra_mouse_buttons_raw_event()
3588 return -EINVAL; in hidpp10_extra_mouse_buttons_raw_event()
3601 * the same usb-id show different behavior, so we handle both cases. in hidpp10_extra_mouse_buttons_raw_event()
3604 input_report_key(hidpp->input, BTN_MOUSE + i, in hidpp10_extra_mouse_buttons_raw_event()
3609 input_report_key(hidpp->input, BTN_MISC + i, in hidpp10_extra_mouse_buttons_raw_event()
3612 input_sync(hidpp->input); in hidpp10_extra_mouse_buttons_raw_event()
3619 /* BTN_MOUSE - BTN_MOUSE+7 are set already by the descriptor */ in hidpp10_extra_mouse_buttons_populate_input()
3620 __set_bit(BTN_0, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3621 __set_bit(BTN_1, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3622 __set_bit(BTN_2, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3623 __set_bit(BTN_3, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3624 __set_bit(BTN_4, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3625 __set_bit(BTN_5, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3626 __set_bit(BTN_6, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3627 __set_bit(BTN_7, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3630 /* -------------------------------------------------------------------------- */
3631 /* HID++1.0 kbds which only report 0x10xx consumer usages through sub-id 0x03 */
3632 /* -------------------------------------------------------------------------- */
3634 /* Find the consumer-page input report desc and change Maximums to 0x107f */
3653 size = *rsize - (consumer_rdesc - rdesc); in hidpp10_consumer_keys_report_fixup()
3689 hid_report_raw_event(hidpp->hid_dev, HID_INPUT_REPORT, in hidpp10_consumer_keys_raw_event()
3695 /* -------------------------------------------------------------------------- */
3696 /* High-resolution scroll wheels */
3697 /* -------------------------------------------------------------------------- */
3704 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_HI_RES_WHEEL) { in hi_res_scroll_enable()
3708 } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_HI_RES_SCROLL) { in hi_res_scroll_enable()
3711 } else /* if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_FAST_SCROLL) */ { in hi_res_scroll_enable()
3716 hid_dbg(hidpp->hid_dev, in hi_res_scroll_enable()
3717 "Could not enable hi-res scrolling: %d\n", ret); in hi_res_scroll_enable()
3722 hid_dbg(hidpp->hid_dev, in hi_res_scroll_enable()
3727 hidpp->vertical_wheel_counter.wheel_multiplier = multiplier; in hi_res_scroll_enable()
3728 hid_dbg(hidpp->hid_dev, "wheel multiplier = %d\n", multiplier); in hi_res_scroll_enable()
3737 capabilities = hidpp->capabilities; in hidpp_initialize_hires_scroll()
3739 if (hidpp->protocol_major >= 2) { in hidpp_initialize_hires_scroll()
3746 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_HI_RES_WHEEL; in hidpp_initialize_hires_scroll()
3747 hid_dbg(hidpp->hid_dev, "Detected HID++ 2.0 hi-res scroll wheel\n"); in hidpp_initialize_hires_scroll()
3753 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_HI_RES_SCROLL; in hidpp_initialize_hires_scroll()
3754 hid_dbg(hidpp->hid_dev, "Detected HID++ 2.0 hi-res scrolling\n"); in hidpp_initialize_hires_scroll()
3758 if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_1P0) { in hidpp_initialize_hires_scroll()
3759 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP10_FAST_SCROLL; in hidpp_initialize_hires_scroll()
3760 hid_dbg(hidpp->hid_dev, "Detected HID++ 1.0 fast scroll\n"); in hidpp_initialize_hires_scroll()
3764 if (hidpp->capabilities == capabilities) in hidpp_initialize_hires_scroll()
3765 hid_dbg(hidpp->hid_dev, "Did not detect HID++ hi-res scrolling hardware support\n"); in hidpp_initialize_hires_scroll()
3769 /* -------------------------------------------------------------------------- */
3771 /* -------------------------------------------------------------------------- */
3782 if (hdev->group == HID_GROUP_LOGITECH_27MHZ_DEVICE || in hidpp_report_fixup()
3783 (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS)) in hidpp_report_fixup()
3798 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_input_mapping()
3800 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 && in hidpp_input_mapping()
3801 field->application != HID_GD_MOUSE) in hidpp_input_mapping()
3804 if (hdev->product == DINOVO_MINI_PRODUCT_ID) in hidpp_input_mapping()
3820 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { in hidpp_input_mapped()
3821 if (usage->type == EV_ABS && (usage->code == ABS_X || in hidpp_input_mapped()
3822 usage->code == ABS_Y || usage->code == ABS_Z || in hidpp_input_mapped()
3823 usage->code == ABS_RZ)) { in hidpp_input_mapped()
3824 field->application = HID_GD_MULTIAXIS; in hidpp_input_mapped()
3835 hidpp->input = input; in hidpp_populate_input()
3837 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_populate_input()
3839 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) in hidpp_populate_input()
3842 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) in hidpp_populate_input()
3845 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) in hidpp_populate_input()
3853 struct input_dev *input = hidinput->input; in hidpp_input_configured()
3866 struct hidpp_report *question = hidpp->send_receive_buf; in hidpp_raw_hidpp_event()
3867 struct hidpp_report *answer = hidpp->send_receive_buf; in hidpp_raw_hidpp_event()
3875 if (unlikely(mutex_is_locked(&hidpp->send_mutex))) { in hidpp_raw_hidpp_event()
3883 hidpp->answer_available = true; in hidpp_raw_hidpp_event()
3884 wake_up(&hidpp->wait); in hidpp_raw_hidpp_event()
3887 * We return 1 to hid-core to avoid forwarding the in hidpp_raw_hidpp_event()
3896 atomic_set(&hidpp->connected, in hidpp_raw_hidpp_event()
3897 !(report->rap.params[0] & (1 << 6))); in hidpp_raw_hidpp_event()
3898 if (schedule_work(&hidpp->work) == 0) in hidpp_raw_hidpp_event()
3903 if (hidpp->hid_dev->group == HID_GROUP_LOGITECH_27MHZ_DEVICE && in hidpp_raw_hidpp_event()
3907 dev_err_ratelimited(&hidpp->hid_dev->dev, in hidpp_raw_hidpp_event()
3908 …less encryption key has been lost, your keyboard will not work unless you re-configure encryption.… in hidpp_raw_hidpp_event()
3909 dev_err_ratelimited(&hidpp->hid_dev->dev, in hidpp_raw_hidpp_event()
3910 "See: https://gitlab.freedesktop.org/jwrdegoede/logitech-27mhz-keyboard-encryption-setup/\n"); in hidpp_raw_hidpp_event()
3913 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { in hidpp_raw_hidpp_event()
3931 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) { in hidpp_raw_hidpp_event()
3937 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) { in hidpp_raw_hidpp_event()
3943 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) { in hidpp_raw_hidpp_event()
3949 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) { in hidpp_raw_hidpp_event()
3970 if (size != hidpp->very_long_report_length) { in hidpp_raw_event()
4000 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_raw_event()
4002 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) in hidpp_raw_event()
4020 counter = &hidpp->vertical_wheel_counter; in hidpp_event()
4022 * the input device set, or high-res scroll enabling may fail. In such in hidpp_event()
4026 if (!(hidpp->capabilities & HIDPP_CAPABILITY_HI_RES_SCROLL) in hidpp_event()
4027 || value == 0 || hidpp->input == NULL in hidpp_event()
4028 || counter->wheel_multiplier == 0) in hidpp_event()
4031 hidpp_scroll_counter_handle_scroll(hidpp->input, counter, value); in hidpp_event()
4039 struct power_supply_desc *desc = &hidpp->battery.desc; in hidpp_initialize_battery()
4046 if (hidpp->battery.ps) in hidpp_initialize_battery()
4049 hidpp->battery.feature_index = 0xff; in hidpp_initialize_battery()
4050 hidpp->battery.solar_feature_index = 0xff; in hidpp_initialize_battery()
4051 hidpp->battery.voltage_feature_index = 0xff; in hidpp_initialize_battery()
4052 hidpp->battery.adc_measurement_feature_index = 0xff; in hidpp_initialize_battery()
4054 if (hidpp->protocol_major >= 2) { in hidpp_initialize_battery()
4055 if (hidpp->quirks & HIDPP_QUIRK_CLASS_K750) in hidpp_initialize_battery()
4072 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_BATTERY; in hidpp_initialize_battery()
4078 return -ENOENT; in hidpp_initialize_battery()
4079 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp_initialize_battery()
4081 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS; in hidpp_initialize_battery()
4083 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP10_BATTERY; in hidpp_initialize_battery()
4086 battery_props = devm_kmemdup(&hidpp->hid_dev->dev, in hidpp_initialize_battery()
4091 return -ENOMEM; in hidpp_initialize_battery()
4093 num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 3; in hidpp_initialize_battery()
4095 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE || in hidpp_initialize_battery()
4096 hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE || in hidpp_initialize_battery()
4097 hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE || in hidpp_initialize_battery()
4098 hidpp->capabilities & HIDPP_CAPABILITY_ADC_MEASUREMENT) in hidpp_initialize_battery()
4102 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS) in hidpp_initialize_battery()
4106 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE || in hidpp_initialize_battery()
4107 hidpp->capabilities & HIDPP_CAPABILITY_ADC_MEASUREMENT) in hidpp_initialize_battery()
4111 battery = &hidpp->battery; in hidpp_initialize_battery()
4113 n = atomic_inc_return(&battery_no) - 1; in hidpp_initialize_battery()
4114 desc->properties = battery_props; in hidpp_initialize_battery()
4115 desc->num_properties = num_battery_props; in hidpp_initialize_battery()
4116 desc->get_property = hidpp_battery_get_property; in hidpp_initialize_battery()
4117 sprintf(battery->name, "hidpp_battery_%ld", n); in hidpp_initialize_battery()
4118 desc->name = battery->name; in hidpp_initialize_battery()
4119 desc->type = POWER_SUPPLY_TYPE_BATTERY; in hidpp_initialize_battery()
4120 desc->use_for_apm = 0; in hidpp_initialize_battery()
4122 battery->ps = devm_power_supply_register(&hidpp->hid_dev->dev, in hidpp_initialize_battery()
4123 &battery->desc, in hidpp_initialize_battery()
4125 if (IS_ERR(battery->ps)) in hidpp_initialize_battery()
4126 return PTR_ERR(battery->ps); in hidpp_initialize_battery()
4128 power_supply_powers(battery->ps, &hidpp->hid_dev->dev); in hidpp_initialize_battery()
4138 if (hidpp->protocol_major < 2) in hidpp_overwrite_name()
4147 snprintf(hdev->name, sizeof(hdev->name), "%s", name); in hidpp_overwrite_name()
4169 struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev); in hidpp_allocate_input()
4176 input_dev->open = hidpp_input_open; in hidpp_allocate_input()
4177 input_dev->close = hidpp_input_close; in hidpp_allocate_input()
4179 input_dev->name = hidpp->name; in hidpp_allocate_input()
4180 input_dev->phys = hdev->phys; in hidpp_allocate_input()
4181 input_dev->uniq = hdev->uniq; in hidpp_allocate_input()
4182 input_dev->id.bustype = hdev->bus; in hidpp_allocate_input()
4183 input_dev->id.vendor = hdev->vendor; in hidpp_allocate_input()
4184 input_dev->id.product = hdev->product; in hidpp_allocate_input()
4185 input_dev->id.version = hdev->version; in hidpp_allocate_input()
4186 input_dev->dev.parent = &hdev->dev; in hidpp_allocate_input()
4193 struct hid_device *hdev = hidpp->hid_dev; in hidpp_connect_event()
4195 bool connected = atomic_read(&hidpp->connected); in hidpp_connect_event()
4200 if (hidpp->battery.ps) { in hidpp_connect_event()
4201 hidpp->battery.online = false; in hidpp_connect_event()
4202 hidpp->battery.status = POWER_SUPPLY_STATUS_UNKNOWN; in hidpp_connect_event()
4203 hidpp->battery.level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; in hidpp_connect_event()
4204 power_supply_changed(hidpp->battery.ps); in hidpp_connect_event()
4209 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { in hidpp_connect_event()
4213 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) { in hidpp_connect_event()
4217 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) { in hidpp_connect_event()
4223 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) { in hidpp_connect_event()
4229 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) { in hidpp_connect_event()
4235 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) { in hidpp_connect_event()
4243 if (!hidpp->protocol_major) { in hidpp_connect_event()
4251 if (hidpp->protocol_major >= 2) { in hidpp_connect_event()
4255 hidpp->wireless_feature_index = feature_index; in hidpp_connect_event()
4258 if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) { in hidpp_connect_event()
4261 devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL, in hidpp_connect_event()
4267 hidpp->name = devm_name; in hidpp_connect_event()
4272 if (!hid_is_usb(hidpp->hid_dev)) in hidpp_connect_event()
4276 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) { in hidpp_connect_event()
4278 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE) in hidpp_connect_event()
4282 } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { in hidpp_connect_event()
4283 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE) in hidpp_connect_event()
4285 else if (hidpp->capabilities & HIDPP_CAPABILITY_UNIFIED_BATTERY) in hidpp_connect_event()
4287 else if (hidpp->capabilities & HIDPP_CAPABILITY_ADC_MEASUREMENT) in hidpp_connect_event()
4292 if (hidpp->battery.ps) in hidpp_connect_event()
4293 power_supply_changed(hidpp->battery.ps); in hidpp_connect_event()
4295 if (hidpp->capabilities & HIDPP_CAPABILITY_HI_RES_SCROLL) in hidpp_connect_event()
4298 if (!(hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT) || hidpp->delayed_input) in hidpp_connect_event()
4316 hidpp->delayed_input = input; in hidpp_connect_event()
4335 re = &(hdev->report_enum[HID_OUTPUT_REPORT]); in hidpp_get_report_length()
4336 report = re->report_id_hash[id]; in hidpp_get_report_length()
4340 return report->field[0]->report_count + 1; in hidpp_get_report_length()
4375 hidpp->very_long_report_length = report_length; in hidpp_validate_device()
4391 report_list = &hdev->report_enum[HID_INPUT_REPORT].report_list; in hidpp_application_equals()
4393 return report && report->application == application; in hidpp_application_equals()
4405 hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL); in hidpp_probe()
4407 return -ENOMEM; in hidpp_probe()
4409 hidpp->hid_dev = hdev; in hidpp_probe()
4410 hidpp->name = hdev->name; in hidpp_probe()
4411 hidpp->quirks = id->driver_data; in hidpp_probe()
4423 hidpp->supported_reports = hidpp_validate_device(hdev); in hidpp_probe()
4425 if (!hidpp->supported_reports) { in hidpp_probe()
4427 devm_kfree(&hdev->dev, hidpp); in hidpp_probe()
4431 if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE) in hidpp_probe()
4432 hidpp->quirks |= HIDPP_QUIRK_UNIFYING; in hidpp_probe()
4434 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE && in hidpp_probe()
4436 hidpp->quirks |= HIDPP_QUIRK_HIDPP_WHEELS | in hidpp_probe()
4439 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE && in hidpp_probe()
4441 hidpp->quirks |= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS; in hidpp_probe()
4443 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { in hidpp_probe()
4447 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) { in hidpp_probe()
4453 INIT_WORK(&hidpp->work, delayed_work_cb); in hidpp_probe()
4454 mutex_init(&hidpp->send_mutex); in hidpp_probe()
4455 init_waitqueue_head(&hidpp->wait); in hidpp_probe()
4458 ret = sysfs_create_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_probe()
4461 hdev->name); in hidpp_probe()
4465 * hid subdrivers (hid-input, hidraw). This allows retrieving the dev's in hidpp_probe()
4466 * name and serial number and store these in hdev->name and hdev->uniq, in hidpp_probe()
4467 * before the hid-input and hidraw drivers expose these to userspace. in hidpp_probe()
4477 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n", in hidpp_probe()
4485 if (hidpp->quirks & HIDPP_QUIRK_UNIFYING) in hidpp_probe()
4487 else if (hid_is_usb(hidpp->hid_dev)) in hidpp_probe()
4491 atomic_set(&hidpp->connected, connected); in hidpp_probe()
4492 if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) { in hidpp_probe()
4494 ret = -ENODEV; in hidpp_probe()
4502 if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { in hidpp_probe()
4506 } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { in hidpp_probe()
4512 schedule_work(&hidpp->work); in hidpp_probe()
4513 flush_work(&hidpp->work); in hidpp_probe()
4515 if (hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT) in hidpp_probe()
4525 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { in hidpp_probe()
4528 hid_warn(hidpp->hid_dev, in hidpp_probe()
4534 * This relies on logi_dj_ll_close() being a no-op so that DJ connection in hidpp_probe()
4545 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_probe()
4546 cancel_work_sync(&hidpp->work); in hidpp_probe()
4547 mutex_destroy(&hidpp->send_mutex); in hidpp_probe()
4558 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_remove()
4561 cancel_work_sync(&hidpp->work); in hidpp_remove()
4562 mutex_destroy(&hidpp->send_mutex); in hidpp_remove()
4600 { /* Keyboard MX5000 (Bluetooth-receiver in HID proxy mode) */
4603 { /* Dinovo Edge (Bluetooth-receiver in HID proxy mode) */
4606 { /* Keyboard MX5500 (Bluetooth-receiver in HID proxy mode) */
4612 { /* Keyboard LX501 (Y-RR53) */
4615 { /* Keyboard MX3000 (Y-RAM74) */
4618 { /* Keyboard MX3200 (Y-RAV80) */
4671 { /* M-RCQ142 V470 Cordless Laser Mouse over Bluetooth */
4695 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
4699 .name = "logitech-hidpp-device",