Lines Matching +full:abs +full:- +full:fuzz
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"
42 "Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
83 /* Convenience constant to check for any high-res support. */
123 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
129 u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
158 * struct hidpp_scroll_counter - Utility class for processing high-resolution
162 * @remainder: counts the number of high-resolution units moved since the last
163 * low-resolution event (REL_WHEEL or REL_HWHEEL) was sent. Should
165 * @direction: direction of last movement (1 or -1)
230 switch (hidpp_report->report_id) { in __hidpp_send_report()
238 fields_count = hidpp->very_long_report_length; in __hidpp_send_report()
241 return -ENODEV; in __hidpp_send_report()
248 hidpp_report->device_index = 0xff; in __hidpp_send_report()
250 if (hidpp->quirks & HIDPP_QUIRK_FORCE_OUTPUT_REPORTS) { in __hidpp_send_report()
253 ret = hid_hw_raw_request(hdev, hidpp_report->report_id, in __hidpp_send_report()
258 return ret == fields_count ? 0 : -1; in __hidpp_send_report()
264 * - If ' something else' is positive, that means that an error has been raised
266 * - If ' something else' is negative, that means that we had a classic error
267 * (-ENOMEM, -EPIPE, etc...)
275 mutex_lock(&hidpp->send_mutex); in hidpp_send_message_sync()
277 hidpp->send_receive_buf = response; in hidpp_send_message_sync()
278 hidpp->answer_available = false; in hidpp_send_message_sync()
286 ret = __hidpp_send_report(hidpp->hid_dev, message); in hidpp_send_message_sync()
294 if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, in hidpp_send_message_sync()
298 ret = -ETIMEDOUT; in hidpp_send_message_sync()
301 if (response->report_id == REPORT_ID_HIDPP_SHORT && in hidpp_send_message_sync()
302 response->rap.sub_id == HIDPP_ERROR) { in hidpp_send_message_sync()
303 ret = response->rap.params[1]; in hidpp_send_message_sync()
308 if ((response->report_id == REPORT_ID_HIDPP_LONG || in hidpp_send_message_sync()
309 response->report_id == REPORT_ID_HIDPP_VERY_LONG) && in hidpp_send_message_sync()
310 response->fap.feature_index == HIDPP20_ERROR) { in hidpp_send_message_sync()
311 ret = response->fap.params[1]; in hidpp_send_message_sync()
317 mutex_unlock(&hidpp->send_mutex); in hidpp_send_message_sync()
329 if (param_count > sizeof(message->fap.params)) in hidpp_send_fap_command_sync()
330 return -EINVAL; in hidpp_send_fap_command_sync()
334 return -ENOMEM; in hidpp_send_fap_command_sync()
336 if (param_count > (HIDPP_REPORT_LONG_LENGTH - 4)) in hidpp_send_fap_command_sync()
337 message->report_id = REPORT_ID_HIDPP_VERY_LONG; in hidpp_send_fap_command_sync()
339 message->report_id = REPORT_ID_HIDPP_LONG; in hidpp_send_fap_command_sync()
340 message->fap.feature_index = feat_index; in hidpp_send_fap_command_sync()
341 message->fap.funcindex_clientid = funcindex_clientid; in hidpp_send_fap_command_sync()
342 memcpy(&message->fap.params, params, param_count); in hidpp_send_fap_command_sync()
358 !(hidpp_dev->supported_reports & HIDPP_REPORT_SHORT_SUPPORTED)) in hidpp_send_rap_command_sync()
363 max_count = HIDPP_REPORT_SHORT_LENGTH - 4; in hidpp_send_rap_command_sync()
366 max_count = HIDPP_REPORT_LONG_LENGTH - 4; in hidpp_send_rap_command_sync()
369 max_count = hidpp_dev->very_long_report_length - 4; in hidpp_send_rap_command_sync()
372 return -EINVAL; in hidpp_send_rap_command_sync()
376 return -EINVAL; in hidpp_send_rap_command_sync()
380 return -ENOMEM; in hidpp_send_rap_command_sync()
381 message->report_id = report_id; in hidpp_send_rap_command_sync()
382 message->rap.sub_id = sub_id; in hidpp_send_rap_command_sync()
383 message->rap.reg_address = reg_address; in hidpp_send_rap_command_sync()
384 memcpy(&message->rap.params, params, param_count); in hidpp_send_rap_command_sync()
401 return (answer->fap.feature_index == question->fap.feature_index) && in hidpp_match_answer()
402 (answer->fap.funcindex_clientid == question->fap.funcindex_clientid); in hidpp_match_answer()
408 return ((answer->rap.sub_id == HIDPP_ERROR) || in hidpp_match_error()
409 (answer->fap.feature_index == HIDPP20_ERROR)) && in hidpp_match_error()
410 (answer->fap.funcindex_clientid == question->fap.feature_index) && in hidpp_match_error()
411 (answer->fap.params[0] == question->fap.funcindex_clientid); in hidpp_match_error()
417 return (hidpp->wireless_feature_index && in hidpp_report_is_connect_event()
418 (report->fap.feature_index == hidpp->wireless_feature_index)) || in hidpp_report_is_connect_event()
419 ((report->report_id == REPORT_ID_HIDPP_SHORT) && in hidpp_report_is_connect_event()
420 (report->rap.sub_id == 0x41)); in hidpp_report_is_connect_event()
451 * hidpp_scroll_counter_handle_scroll() - Send high- and low-resolution scroll
452 * events given a high-resolution wheel
455 * @hi_res_value: the movement of the wheel, in the mouse's high-resolution
458 * Given a high-resolution movement, this function converts the movement into
459 * fractions of 120 and emits high-resolution scroll events for the input
461 * emit low-resolution scroll events when appropriate for
462 * backwards-compatibility with userspace input libraries.
471 hi_res_value = hi_res_value * 120/counter->wheel_multiplier; in hidpp_scroll_counter_handle_scroll()
474 remainder = counter->remainder; in hidpp_scroll_counter_handle_scroll()
475 direction = hi_res_value > 0 ? 1 : -1; in hidpp_scroll_counter_handle_scroll()
478 previous = counter->last_time; in hidpp_scroll_counter_handle_scroll()
479 counter->last_time = now; in hidpp_scroll_counter_handle_scroll()
486 if (now - previous > 1000000000 || direction != counter->direction) in hidpp_scroll_counter_handle_scroll()
489 counter->direction = direction; in hidpp_scroll_counter_handle_scroll()
493 * after slow movement, so we want the threshold for low-res events to in hidpp_scroll_counter_handle_scroll()
497 if (abs(remainder) >= 60) { in hidpp_scroll_counter_handle_scroll()
499 * is half-way to the next detent (i.e. scroll 1 detent after a in hidpp_scroll_counter_handle_scroll()
505 low_res_value = (hi_res_value > 0 ? 1 : -1); in hidpp_scroll_counter_handle_scroll()
507 remainder -= low_res_value * 120; in hidpp_scroll_counter_handle_scroll()
509 counter->remainder = remainder; in hidpp_scroll_counter_handle_scroll()
512 /* -------------------------------------------------------------------------- */
514 /* -------------------------------------------------------------------------- */
522 * hidpp10_set_register - Modify a HID++ 1.0 register.
574 /* On HID++ 1.0 devices, high-res scroll was called "scrolling acceleration". */
654 hidpp->battery.level = in hidpp10_query_battery_status()
657 hidpp->battery.status = status; in hidpp10_query_battery_status()
659 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp10_query_battery_status()
706 hidpp->battery.capacity = response.rap.params[0]; in hidpp10_query_battery_mileage()
708 hidpp->battery.status = status; in hidpp10_query_battery_mileage()
710 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp10_query_battery_mileage()
722 if (report->report_id != REPORT_ID_HIDPP_SHORT) in hidpp10_battery_event()
725 switch (report->rap.sub_id) { in hidpp10_battery_event()
727 capacity = hidpp->battery.capacity; in hidpp10_battery_event()
728 level = hidpp10_battery_status_map_level(report->rawbytes[1]); in hidpp10_battery_event()
729 status = hidpp10_battery_status_map_status(report->rawbytes[2]); in hidpp10_battery_event()
732 capacity = report->rap.params[0]; in hidpp10_battery_event()
733 level = hidpp->battery.level; in hidpp10_battery_event()
734 status = hidpp10_battery_mileage_map_status(report->rawbytes[3]); in hidpp10_battery_event()
740 changed = capacity != hidpp->battery.capacity || in hidpp10_battery_event()
741 level != hidpp->battery.level || in hidpp10_battery_event()
742 status != hidpp->battery.status; in hidpp10_battery_event()
745 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp10_battery_event()
749 hidpp->battery.level = level; in hidpp10_battery_event()
750 hidpp->battery.status = status; in hidpp10_battery_event()
751 if (hidpp->battery.ps) in hidpp10_battery_event()
752 power_supply_changed(hidpp->battery.ps); in hidpp10_battery_event()
822 struct hid_device *hdev = hidpp->hid_dev; in hidpp_unifying_init()
831 snprintf(hdev->uniq, sizeof(hdev->uniq), "%04x-%4phD", in hidpp_unifying_init()
832 hdev->product, &serial); in hidpp_unifying_init()
833 dbg_hid("HID++ Unifying: Got serial: %s\n", hdev->uniq); in hidpp_unifying_init()
837 return -EIO; in hidpp_unifying_init()
839 snprintf(hdev->name, sizeof(hdev->name), "%s", name); in hidpp_unifying_init()
846 /* -------------------------------------------------------------------------- */
848 /* -------------------------------------------------------------------------- */
871 return -ENOENT; in hidpp_root_get_feature()
893 hidpp->protocol_major = 1; in hidpp_root_get_protocol_version()
894 hidpp->protocol_minor = 0; in hidpp_root_get_protocol_version()
900 return -EIO; in hidpp_root_get_protocol_version()
903 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_root_get_protocol_version()
905 return -EPROTO; in hidpp_root_get_protocol_version()
911 hid_err(hidpp->hid_dev, "%s: ping mismatch 0x%02x != 0x%02x\n", in hidpp_root_get_protocol_version()
913 return -EPROTO; in hidpp_root_get_protocol_version()
916 hidpp->protocol_major = response.rap.params[0]; in hidpp_root_get_protocol_version()
917 hidpp->protocol_minor = response.rap.params[1]; in hidpp_root_get_protocol_version()
920 hid_info(hidpp->hid_dev, "HID++ %u.%u device connected.\n", in hidpp_root_get_protocol_version()
921 hidpp->protocol_major, hidpp->protocol_minor); in hidpp_root_get_protocol_version()
925 /* -------------------------------------------------------------------------- */
927 /* -------------------------------------------------------------------------- */
945 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_devicenametype_get_count()
947 return -EPROTO; in hidpp_devicenametype_get_count()
969 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_devicenametype_get_device_name()
971 return -EPROTO; in hidpp_devicenametype_get_device_name()
978 count = hidpp->very_long_report_length - 4; in hidpp_devicenametype_get_device_name()
981 count = HIDPP_REPORT_LONG_LENGTH - 4; in hidpp_devicenametype_get_device_name()
984 count = HIDPP_REPORT_SHORT_LENGTH - 4; in hidpp_devicenametype_get_device_name()
987 return -EPROTO; in hidpp_devicenametype_get_device_name()
1025 __name_length - index); in hidpp_get_device_name()
1039 /* -------------------------------------------------------------------------- */
1041 /* -------------------------------------------------------------------------- */
1128 return -EIO; in hidpp20_batterylevel_get_battery_capacity()
1130 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_batterylevel_get_battery_capacity()
1132 return -EPROTO; in hidpp20_batterylevel_get_battery_capacity()
1156 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_batterylevel_get_battery_info()
1158 return -EPROTO; in hidpp20_batterylevel_get_battery_info()
1167 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS; in hidpp20_batterylevel_get_battery_info()
1169 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp20_batterylevel_get_battery_info()
1180 if (hidpp->battery.feature_index == 0xff) { in hidpp20_query_battery_info()
1183 &hidpp->battery.feature_index, in hidpp20_query_battery_info()
1190 hidpp->battery.feature_index, in hidpp20_query_battery_info()
1197 hidpp->battery.feature_index); in hidpp20_query_battery_info()
1201 hidpp->battery.status = status; in hidpp20_query_battery_info()
1202 hidpp->battery.capacity = capacity; in hidpp20_query_battery_info()
1203 hidpp->battery.level = level; in hidpp20_query_battery_info()
1205 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp20_query_battery_info()
1218 if (report->fap.feature_index != hidpp->battery.feature_index || in hidpp20_battery_event()
1219 report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST) in hidpp20_battery_event()
1222 status = hidpp20_batterylevel_map_status_capacity(report->fap.params, in hidpp20_battery_event()
1228 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp20_battery_event()
1231 changed = capacity != hidpp->battery.capacity || in hidpp20_battery_event()
1232 level != hidpp->battery.level || in hidpp20_battery_event()
1233 status != hidpp->battery.status; in hidpp20_battery_event()
1236 hidpp->battery.level = level; in hidpp20_battery_event()
1237 hidpp->battery.capacity = capacity; in hidpp20_battery_event()
1238 hidpp->battery.status = status; in hidpp20_battery_event()
1239 if (hidpp->battery.ps) in hidpp20_battery_event()
1240 power_supply_changed(hidpp->battery.ps); in hidpp20_battery_event()
1246 /* -------------------------------------------------------------------------- */
1248 /* -------------------------------------------------------------------------- */
1313 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_battery_get_battery_voltage()
1315 return -EPROTO; in hidpp20_battery_get_battery_voltage()
1320 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_VOLTAGE; in hidpp20_battery_get_battery_voltage()
1334 if (hidpp->battery.voltage_feature_index == 0xff) { in hidpp20_query_battery_voltage_info()
1336 &hidpp->battery.voltage_feature_index, in hidpp20_query_battery_voltage_info()
1343 hidpp->battery.voltage_feature_index, in hidpp20_query_battery_voltage_info()
1349 hidpp->battery.status = status; in hidpp20_query_battery_voltage_info()
1350 hidpp->battery.voltage = voltage; in hidpp20_query_battery_voltage_info()
1351 hidpp->battery.level = level; in hidpp20_query_battery_voltage_info()
1352 hidpp->battery.charge_type = charge_type; in hidpp20_query_battery_voltage_info()
1353 hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING; in hidpp20_query_battery_voltage_info()
1364 if (report->fap.feature_index != hidpp->battery.voltage_feature_index || in hidpp20_battery_voltage_event()
1365 report->fap.funcindex_clientid != EVENT_BATTERY_VOLTAGE_STATUS_BROADCAST) in hidpp20_battery_voltage_event()
1368 status = hidpp20_battery_map_status_voltage(report->fap.params, &voltage, in hidpp20_battery_voltage_event()
1371 hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING; in hidpp20_battery_voltage_event()
1373 if (voltage != hidpp->battery.voltage || status != hidpp->battery.status) { in hidpp20_battery_voltage_event()
1374 hidpp->battery.voltage = voltage; in hidpp20_battery_voltage_event()
1375 hidpp->battery.status = status; in hidpp20_battery_voltage_event()
1376 hidpp->battery.level = level; in hidpp20_battery_voltage_event()
1377 hidpp->battery.charge_type = charge_type; in hidpp20_battery_voltage_event()
1378 if (hidpp->battery.ps) in hidpp20_battery_voltage_event()
1379 power_supply_changed(hidpp->battery.ps); in hidpp20_battery_voltage_event()
1405 val->intval = hidpp->battery.status; in hidpp_battery_get_property()
1408 val->intval = hidpp->battery.capacity; in hidpp_battery_get_property()
1411 val->intval = hidpp->battery.level; in hidpp_battery_get_property()
1414 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in hidpp_battery_get_property()
1417 val->intval = hidpp->battery.online; in hidpp_battery_get_property()
1420 if (!strncmp(hidpp->name, "Logitech ", 9)) in hidpp_battery_get_property()
1421 val->strval = hidpp->name + 9; in hidpp_battery_get_property()
1423 val->strval = hidpp->name; in hidpp_battery_get_property()
1426 val->strval = "Logitech"; in hidpp_battery_get_property()
1429 val->strval = hidpp->hid_dev->uniq; in hidpp_battery_get_property()
1433 val->intval = hidpp->battery.voltage * 1000; in hidpp_battery_get_property()
1436 val->intval = hidpp->battery.charge_type; in hidpp_battery_get_property()
1439 ret = -EINVAL; in hidpp_battery_get_property()
1446 /* -------------------------------------------------------------------------- */
1448 /* -------------------------------------------------------------------------- */
1458 &hidpp->wireless_feature_index, in hidpp_set_wireless_feature_index()
1464 /* -------------------------------------------------------------------------- */
1465 /* 0x2120: Hi-resolution scrolling */
1466 /* -------------------------------------------------------------------------- */
1498 /* -------------------------------------------------------------------------- */
1500 /* -------------------------------------------------------------------------- */
1529 hid_warn(hidpp->hid_dev, in hidpp_hrw_get_wheel_capability()
1557 /* -------------------------------------------------------------------------- */
1559 /* -------------------------------------------------------------------------- */
1576 if (hidpp->battery.feature_index == 0xff) { in hidpp_solar_request_battery_event()
1579 &hidpp->battery.solar_feature_index, in hidpp_solar_request_battery_event()
1586 hidpp->battery.solar_feature_index, in hidpp_solar_request_battery_event()
1590 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_solar_request_battery_event()
1592 return -EPROTO; in hidpp_solar_request_battery_event()
1597 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp_solar_request_battery_event()
1609 function = report->fap.funcindex_clientid; in hidpp_solar_battery_event()
1612 if (report->fap.feature_index != hidpp->battery.solar_feature_index || in hidpp_solar_battery_event()
1618 capacity = report->fap.params[0]; in hidpp_solar_battery_event()
1622 lux = (report->fap.params[1] << 8) | report->fap.params[2]; in hidpp_solar_battery_event()
1630 if (capacity < hidpp->battery.capacity) in hidpp_solar_battery_event()
1640 hidpp->battery.online = true; in hidpp_solar_battery_event()
1641 if (capacity != hidpp->battery.capacity || in hidpp_solar_battery_event()
1642 status != hidpp->battery.status) { in hidpp_solar_battery_event()
1643 hidpp->battery.capacity = capacity; in hidpp_solar_battery_event()
1644 hidpp->battery.status = status; in hidpp_solar_battery_event()
1645 if (hidpp->battery.ps) in hidpp_solar_battery_event()
1646 power_supply_changed(hidpp->battery.ps); in hidpp_solar_battery_event()
1652 /* -------------------------------------------------------------------------- */
1654 /* -------------------------------------------------------------------------- */
1668 * send a set state command to the device by reading the current items->state
1680 CMD_TOUCHPAD_FW_ITEMS_SET, &items->state, 1, &response); in hidpp_touchpad_fw_items_set()
1683 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_touchpad_fw_items_set()
1685 return -EPROTO; in hidpp_touchpad_fw_items_set()
1690 items->presence = params[0]; in hidpp_touchpad_fw_items_set()
1691 items->desired_state = params[1]; in hidpp_touchpad_fw_items_set()
1692 items->state = params[2]; in hidpp_touchpad_fw_items_set()
1693 items->persistent = params[3]; in hidpp_touchpad_fw_items_set()
1698 /* -------------------------------------------------------------------------- */
1700 /* -------------------------------------------------------------------------- */
1753 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_touchpad_get_raw_info()
1755 return -EPROTO; in hidpp_touchpad_get_raw_info()
1760 raw_info->x_size = get_unaligned_be16(¶ms[0]); in hidpp_touchpad_get_raw_info()
1761 raw_info->y_size = get_unaligned_be16(¶ms[2]); in hidpp_touchpad_get_raw_info()
1762 raw_info->z_range = params[4]; in hidpp_touchpad_get_raw_info()
1763 raw_info->area_range = params[5]; in hidpp_touchpad_get_raw_info()
1764 raw_info->maxcontacts = params[7]; in hidpp_touchpad_get_raw_info()
1765 raw_info->origin = params[8]; in hidpp_touchpad_get_raw_info()
1767 raw_info->res = get_unaligned_be16(¶ms[13]) * 2 / 51; in hidpp_touchpad_get_raw_info()
1780 * bit 0 - enable raw in hidpp_touchpad_set_raw_report_state()
1781 * bit 1 - 16bit Z, no area in hidpp_touchpad_set_raw_report_state()
1782 * bit 2 - enhanced sensitivity in hidpp_touchpad_set_raw_report_state()
1783 * bit 3 - width, height (4 bits each) instead of area in hidpp_touchpad_set_raw_report_state()
1784 * bit 4 - send raw + gestures (degrades smoothness) in hidpp_touchpad_set_raw_report_state()
1785 * remaining bits - reserved in hidpp_touchpad_set_raw_report_state()
1799 finger->x = x_m << 6 | data[1]; in hidpp_touchpad_touch_event()
1800 finger->y = y_m << 6 | data[3]; in hidpp_touchpad_touch_event()
1802 finger->contact_type = data[0] >> 6; in hidpp_touchpad_touch_event()
1803 finger->contact_status = data[2] >> 6; in hidpp_touchpad_touch_event()
1805 finger->z = data[4]; in hidpp_touchpad_touch_event()
1806 finger->area = data[5]; in hidpp_touchpad_touch_event()
1807 finger->finger_id = data[6] >> 4; in hidpp_touchpad_touch_event()
1814 raw_xy->end_of_frame = data[8] & 0x01; in hidpp_touchpad_raw_xy_event()
1815 raw_xy->spurious_flag = (data[8] >> 1) & 0x01; in hidpp_touchpad_raw_xy_event()
1816 raw_xy->finger_count = data[15] & 0x0f; in hidpp_touchpad_raw_xy_event()
1817 raw_xy->button = (data[8] >> 2) & 0x01; in hidpp_touchpad_raw_xy_event()
1819 if (raw_xy->finger_count) { in hidpp_touchpad_raw_xy_event()
1820 hidpp_touchpad_touch_event(&data[2], &raw_xy->fingers[0]); in hidpp_touchpad_raw_xy_event()
1821 hidpp_touchpad_touch_event(&data[9], &raw_xy->fingers[1]); in hidpp_touchpad_raw_xy_event()
1825 /* -------------------------------------------------------------------------- */
1827 /* -------------------------------------------------------------------------- */
1858 #define HIDPP_FF_EFFECTID_NONE -1
1859 #define HIDPP_FF_EFFECTID_AUTOCENTER -2
1899 -1
1906 -1
1928 for (i = 0; i < data->num_effects; i++) in hidpp_ff_find_effect()
1929 if (data->effect_ids[i] == effect_id) in hidpp_ff_find_effect()
1938 struct hidpp_ff_private_data *data = wd->data; in hidpp_ff_work_handler()
1944 switch (wd->effect_id) { in hidpp_ff_work_handler()
1946 wd->params[0] = data->slot_autocenter; in hidpp_ff_work_handler()
1953 wd->params[0] = hidpp_ff_find_effect(data, wd->effect_id); in hidpp_ff_work_handler()
1958 ret = hidpp_send_fap_command_sync(data->hidpp, data->feature_index, in hidpp_ff_work_handler()
1959 wd->command, wd->params, wd->size, &response); in hidpp_ff_work_handler()
1962 hid_err(data->hidpp->hid_dev, "Failed to send command to device!\n"); in hidpp_ff_work_handler()
1967 switch (wd->command) { in hidpp_ff_work_handler()
1970 if (slot > 0 && slot <= data->num_effects) { in hidpp_ff_work_handler()
1971 if (wd->effect_id >= 0) in hidpp_ff_work_handler()
1973 data->effect_ids[slot-1] = wd->effect_id; in hidpp_ff_work_handler()
1974 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) in hidpp_ff_work_handler()
1976 data->slot_autocenter = slot; in hidpp_ff_work_handler()
1980 if (wd->effect_id >= 0) in hidpp_ff_work_handler()
1982 data->effect_ids[wd->params[0]-1] = -1; in hidpp_ff_work_handler()
1983 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) in hidpp_ff_work_handler()
1985 data->slot_autocenter = 0; in hidpp_ff_work_handler()
1988 data->gain = (wd->params[0] << 8) + wd->params[1]; in hidpp_ff_work_handler()
1991 data->range = (wd->params[0] << 8) + wd->params[1]; in hidpp_ff_work_handler()
1999 atomic_dec(&data->workqueue_size); in hidpp_ff_work_handler()
2009 return -ENOMEM; in hidpp_ff_queue_work()
2011 INIT_WORK(&wd->work, hidpp_ff_work_handler); in hidpp_ff_queue_work()
2013 wd->data = data; in hidpp_ff_queue_work()
2014 wd->effect_id = effect_id; in hidpp_ff_queue_work()
2015 wd->command = command; in hidpp_ff_queue_work()
2016 wd->size = size; in hidpp_ff_queue_work()
2017 memcpy(wd->params, params, size); in hidpp_ff_queue_work()
2019 atomic_inc(&data->workqueue_size); in hidpp_ff_queue_work()
2020 queue_work(data->wq, &wd->work); in hidpp_ff_queue_work()
2023 s = atomic_read(&data->workqueue_size); in hidpp_ff_queue_work()
2025 …hid_warn(data->hidpp->hid_dev, "Force feedback command queue contains %d commands, causing substan… in hidpp_ff_queue_work()
2032 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_upload_effect()
2038 params[2] = effect->replay.length >> 8; in hidpp_ff_upload_effect()
2039 params[3] = effect->replay.length & 255; in hidpp_ff_upload_effect()
2040 params[4] = effect->replay.delay >> 8; in hidpp_ff_upload_effect()
2041 params[5] = effect->replay.delay & 255; in hidpp_ff_upload_effect()
2043 switch (effect->type) { in hidpp_ff_upload_effect()
2045 force = (effect->u.constant.level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2049 params[8] = effect->u.constant.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
2050 params[9] = effect->u.constant.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
2051 params[10] = effect->u.constant.envelope.attack_length & 255; in hidpp_ff_upload_effect()
2052 params[11] = effect->u.constant.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
2053 params[12] = effect->u.constant.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
2054 params[13] = effect->u.constant.envelope.fade_length & 255; in hidpp_ff_upload_effect()
2057 effect->u.constant.level, in hidpp_ff_upload_effect()
2058 effect->direction, force); in hidpp_ff_upload_effect()
2060 effect->u.constant.envelope.attack_level, in hidpp_ff_upload_effect()
2061 effect->u.constant.envelope.attack_length, in hidpp_ff_upload_effect()
2062 effect->u.constant.envelope.fade_level, in hidpp_ff_upload_effect()
2063 effect->u.constant.envelope.fade_length); in hidpp_ff_upload_effect()
2067 switch (effect->u.periodic.waveform) { in hidpp_ff_upload_effect()
2084 …hid_err(data->hidpp->hid_dev, "Unexpected periodic waveform type %i!\n", effect->u.periodic.wavefo… in hidpp_ff_upload_effect()
2085 return -EINVAL; in hidpp_ff_upload_effect()
2087 force = (effect->u.periodic.magnitude * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2088 params[6] = effect->u.periodic.magnitude >> 8; in hidpp_ff_upload_effect()
2089 params[7] = effect->u.periodic.magnitude & 255; in hidpp_ff_upload_effect()
2090 params[8] = effect->u.periodic.offset >> 8; in hidpp_ff_upload_effect()
2091 params[9] = effect->u.periodic.offset & 255; in hidpp_ff_upload_effect()
2092 params[10] = effect->u.periodic.period >> 8; in hidpp_ff_upload_effect()
2093 params[11] = effect->u.periodic.period & 255; in hidpp_ff_upload_effect()
2094 params[12] = effect->u.periodic.phase >> 8; in hidpp_ff_upload_effect()
2095 params[13] = effect->u.periodic.phase & 255; in hidpp_ff_upload_effect()
2096 params[14] = effect->u.periodic.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
2097 params[15] = effect->u.periodic.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
2098 params[16] = effect->u.periodic.envelope.attack_length & 255; in hidpp_ff_upload_effect()
2099 params[17] = effect->u.periodic.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
2100 params[18] = effect->u.periodic.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
2101 params[19] = effect->u.periodic.envelope.fade_length & 255; in hidpp_ff_upload_effect()
2104 effect->u.periodic.magnitude, effect->direction, in hidpp_ff_upload_effect()
2105 effect->u.periodic.offset, in hidpp_ff_upload_effect()
2106 effect->u.periodic.period, in hidpp_ff_upload_effect()
2107 effect->u.periodic.phase); in hidpp_ff_upload_effect()
2109 effect->u.periodic.envelope.attack_level, in hidpp_ff_upload_effect()
2110 effect->u.periodic.envelope.attack_length, in hidpp_ff_upload_effect()
2111 effect->u.periodic.envelope.fade_level, in hidpp_ff_upload_effect()
2112 effect->u.periodic.envelope.fade_length); in hidpp_ff_upload_effect()
2117 force = (effect->u.ramp.start_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2120 force = (effect->u.ramp.end_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2123 params[10] = effect->u.ramp.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
2124 params[11] = effect->u.ramp.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
2125 params[12] = effect->u.ramp.envelope.attack_length & 255; in hidpp_ff_upload_effect()
2126 params[13] = effect->u.ramp.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
2127 params[14] = effect->u.ramp.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
2128 params[15] = effect->u.ramp.envelope.fade_length & 255; in hidpp_ff_upload_effect()
2130 dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n", in hidpp_ff_upload_effect()
2131 effect->u.ramp.start_level, in hidpp_ff_upload_effect()
2132 effect->u.ramp.end_level, in hidpp_ff_upload_effect()
2133 effect->direction, force); in hidpp_ff_upload_effect()
2135 effect->u.ramp.envelope.attack_level, in hidpp_ff_upload_effect()
2136 effect->u.ramp.envelope.attack_length, in hidpp_ff_upload_effect()
2137 effect->u.ramp.envelope.fade_level, in hidpp_ff_upload_effect()
2138 effect->u.ramp.envelope.fade_length); in hidpp_ff_upload_effect()
2144 params[1] = HIDPP_FF_CONDITION_CMDS[effect->type - FF_SPRING]; in hidpp_ff_upload_effect()
2145 params[6] = effect->u.condition[0].left_saturation >> 9; in hidpp_ff_upload_effect()
2146 params[7] = (effect->u.condition[0].left_saturation >> 1) & 255; in hidpp_ff_upload_effect()
2147 params[8] = effect->u.condition[0].left_coeff >> 8; in hidpp_ff_upload_effect()
2148 params[9] = effect->u.condition[0].left_coeff & 255; in hidpp_ff_upload_effect()
2149 params[10] = effect->u.condition[0].deadband >> 9; in hidpp_ff_upload_effect()
2150 params[11] = (effect->u.condition[0].deadband >> 1) & 255; in hidpp_ff_upload_effect()
2151 params[12] = effect->u.condition[0].center >> 8; in hidpp_ff_upload_effect()
2152 params[13] = effect->u.condition[0].center & 255; in hidpp_ff_upload_effect()
2153 params[14] = effect->u.condition[0].right_coeff >> 8; in hidpp_ff_upload_effect()
2154 params[15] = effect->u.condition[0].right_coeff & 255; in hidpp_ff_upload_effect()
2155 params[16] = effect->u.condition[0].right_saturation >> 9; in hidpp_ff_upload_effect()
2156 params[17] = (effect->u.condition[0].right_saturation >> 1) & 255; in hidpp_ff_upload_effect()
2159 HIDPP_FF_CONDITION_NAMES[effect->type - FF_SPRING], in hidpp_ff_upload_effect()
2160 effect->u.condition[0].left_coeff, in hidpp_ff_upload_effect()
2161 effect->u.condition[0].left_saturation, in hidpp_ff_upload_effect()
2162 effect->u.condition[0].right_coeff, in hidpp_ff_upload_effect()
2163 effect->u.condition[0].right_saturation); in hidpp_ff_upload_effect()
2165 effect->u.condition[0].deadband, in hidpp_ff_upload_effect()
2166 effect->u.condition[0].center); in hidpp_ff_upload_effect()
2169 hid_err(data->hidpp->hid_dev, "Unexpected force type %i!\n", effect->type); in hidpp_ff_upload_effect()
2170 return -EINVAL; in hidpp_ff_upload_effect()
2173 return hidpp_ff_queue_work(data, effect->id, HIDPP_FF_DOWNLOAD_EFFECT, params, size); in hidpp_ff_upload_effect()
2178 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_playback()
2190 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_erase_effect()
2200 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_set_autocenter()
2222 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_set_gain()
2238 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_range_show()
2239 struct input_dev *idev = hidinput->input; in hidpp_ff_range_show()
2240 struct hidpp_ff_private_data *data = idev->ff->private; in hidpp_ff_range_show()
2242 return scnprintf(buf, PAGE_SIZE, "%u\n", data->range); in hidpp_ff_range_show()
2248 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_range_store()
2249 struct input_dev *idev = hidinput->input; in hidpp_ff_range_store()
2250 struct hidpp_ff_private_data *data = idev->ff->private; in hidpp_ff_range_store()
2259 hidpp_ff_queue_work(data, -1, HIDPP_FF_SET_APERTURE, params, ARRAY_SIZE(params)); in hidpp_ff_range_store()
2268 struct hidpp_ff_private_data *data = ff->private; in hidpp_ff_destroy()
2269 struct hid_device *hid = data->hidpp->hid_dev; in hidpp_ff_destroy()
2273 device_remove_file(&hid->dev, &dev_attr_range); in hidpp_ff_destroy()
2274 destroy_workqueue(data->wq); in hidpp_ff_destroy()
2275 kfree(data->effect_ids); in hidpp_ff_destroy()
2281 struct hid_device *hid = hidpp->hid_dev; in hidpp_ff_init()
2284 const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor); in hidpp_ff_init()
2285 const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice); in hidpp_ff_init()
2287 int error, j, num_slots = data->num_effects; in hidpp_ff_init()
2290 if (list_empty(&hid->inputs)) { in hidpp_ff_init()
2292 return -ENODEV; in hidpp_ff_init()
2294 hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_init()
2295 dev = hidinput->input; in hidpp_ff_init()
2299 return -EINVAL; in hidpp_ff_init()
2307 set_bit(hidpp_ff_effects[j], dev->ffbit); in hidpp_ff_init()
2310 set_bit(hidpp_ff_effects_v2[j], dev->ffbit); in hidpp_ff_init()
2324 return -ENOMEM; in hidpp_ff_init()
2325 data->effect_ids = kcalloc(num_slots, sizeof(int), GFP_KERNEL); in hidpp_ff_init()
2326 if (!data->effect_ids) { in hidpp_ff_init()
2328 return -ENOMEM; in hidpp_ff_init()
2330 data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue"); in hidpp_ff_init()
2331 if (!data->wq) { in hidpp_ff_init()
2332 kfree(data->effect_ids); in hidpp_ff_init()
2334 return -ENOMEM; in hidpp_ff_init()
2337 data->hidpp = hidpp; in hidpp_ff_init()
2338 data->version = version; in hidpp_ff_init()
2340 data->effect_ids[j] = -1; in hidpp_ff_init()
2342 ff = dev->ff; in hidpp_ff_init()
2343 ff->private = data; in hidpp_ff_init()
2345 ff->upload = hidpp_ff_upload_effect; in hidpp_ff_init()
2346 ff->erase = hidpp_ff_erase_effect; in hidpp_ff_init()
2347 ff->playback = hidpp_ff_playback; in hidpp_ff_init()
2348 ff->set_gain = hidpp_ff_set_gain; in hidpp_ff_init()
2349 ff->set_autocenter = hidpp_ff_set_autocenter; in hidpp_ff_init()
2350 ff->destroy = hidpp_ff_destroy; in hidpp_ff_init()
2353 error = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range); in hidpp_ff_init()
2355 hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d!\n", error); in hidpp_ff_init()
2358 atomic_set(&data->workqueue_size, 0); in hidpp_ff_init()
2372 /* -------------------------------------------------------------------------- */
2374 /* -------------------------------------------------------------------------- */
2392 return -1; in wtp_input_mapping()
2398 struct wtp_data *wd = hidpp->private_data; in wtp_populate_input()
2400 __set_bit(EV_ABS, input_dev->evbit); in wtp_populate_input()
2401 __set_bit(EV_KEY, input_dev->evbit); in wtp_populate_input()
2402 __clear_bit(EV_REL, input_dev->evbit); in wtp_populate_input()
2403 __clear_bit(EV_LED, input_dev->evbit); in wtp_populate_input()
2405 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0); in wtp_populate_input()
2406 input_abs_set_res(input_dev, ABS_MT_POSITION_X, wd->resolution); in wtp_populate_input()
2407 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0); in wtp_populate_input()
2408 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, wd->resolution); in wtp_populate_input()
2415 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) in wtp_populate_input()
2418 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); in wtp_populate_input()
2420 input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER | in wtp_populate_input()
2427 struct wtp_data *wd = hidpp->private_data; in wtp_touch_event()
2430 if (!touch_report->finger_id || touch_report->contact_type) in wtp_touch_event()
2434 slot = input_mt_get_slot_by_key(hidpp->input, touch_report->finger_id); in wtp_touch_event()
2436 input_mt_slot(hidpp->input, slot); in wtp_touch_event()
2437 input_mt_report_slot_state(hidpp->input, MT_TOOL_FINGER, in wtp_touch_event()
2438 touch_report->contact_status); in wtp_touch_event()
2439 if (touch_report->contact_status) { in wtp_touch_event()
2440 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_X, in wtp_touch_event()
2441 touch_report->x); in wtp_touch_event()
2442 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_Y, in wtp_touch_event()
2443 wd->flip_y ? wd->y_size - touch_report->y : in wtp_touch_event()
2444 touch_report->y); in wtp_touch_event()
2445 input_event(hidpp->input, EV_ABS, ABS_MT_PRESSURE, in wtp_touch_event()
2446 touch_report->area); in wtp_touch_event()
2456 wtp_touch_event(hidpp, &(raw->fingers[i])); in wtp_send_raw_xy_event()
2458 if (raw->end_of_frame && in wtp_send_raw_xy_event()
2459 !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS)) in wtp_send_raw_xy_event()
2460 input_event(hidpp->input, EV_KEY, BTN_LEFT, raw->button); in wtp_send_raw_xy_event()
2462 if (raw->end_of_frame || raw->finger_count <= 2) { in wtp_send_raw_xy_event()
2463 input_mt_sync_frame(hidpp->input); in wtp_send_raw_xy_event()
2464 input_sync(hidpp->input); in wtp_send_raw_xy_event()
2470 struct wtp_data *wd = hidpp->private_data; in wtp_mouse_raw_xy_event()
2496 .finger_count = wd->maxcontacts, in wtp_mouse_raw_xy_event()
2510 struct wtp_data *wd = hidpp->private_data; in wtp_raw_event()
2514 if (!wd || !hidpp->input) in wtp_raw_event()
2524 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) { in wtp_raw_event()
2525 input_event(hidpp->input, EV_KEY, BTN_LEFT, in wtp_raw_event()
2527 input_event(hidpp->input, EV_KEY, BTN_RIGHT, in wtp_raw_event()
2529 input_sync(hidpp->input); in wtp_raw_event()
2538 if ((report->fap.feature_index != wd->mt_feature_index) || in wtp_raw_event()
2539 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY)) in wtp_raw_event()
2552 struct wtp_data *wd = hidpp->private_data; in wtp_get_config()
2558 &wd->mt_feature_index, &feature_type); in wtp_get_config()
2563 ret = hidpp_touchpad_get_raw_info(hidpp, wd->mt_feature_index, in wtp_get_config()
2568 wd->x_size = raw_info.x_size; in wtp_get_config()
2569 wd->y_size = raw_info.y_size; in wtp_get_config()
2570 wd->maxcontacts = raw_info.maxcontacts; in wtp_get_config()
2571 wd->flip_y = raw_info.origin == TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT; in wtp_get_config()
2572 wd->resolution = raw_info.res; in wtp_get_config()
2573 if (!wd->resolution) in wtp_get_config()
2574 wd->resolution = WTP_MANUAL_RESOLUTION; in wtp_get_config()
2584 wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data), in wtp_allocate()
2587 return -ENOMEM; in wtp_allocate()
2589 hidpp->private_data = wd; in wtp_allocate()
2597 struct wtp_data *wd = hidpp->private_data; in wtp_connect()
2600 if (!wd->x_size) { in wtp_connect()
2608 return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index, in wtp_connect()
2612 /* ------------------------------------------------------------------------- */
2614 /* ------------------------------------------------------------------------- */
2625 * forward button -> Super_R
2626 * backward button -> Super_L+'d' (press only)
2627 * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
2628 * 2nd time: left-click (press only)
2629 * NB: press-only means that when the button is pressed, the
2637 * - it never sends a keyboard key event
2638 * - for the three mouse button it sends:
2679 if (!hidpp->input) { in m560_raw_event()
2681 return -EINVAL; in m560_raw_event()
2695 * data[1] = device-id in m560_raw_event()
2697 * data[5] = 0xaf -> middle in m560_raw_event()
2698 * 0xb0 -> forward in m560_raw_event()
2699 * 0xae -> backward in m560_raw_event()
2700 * 0x00 -> release all in m560_raw_event()
2706 input_report_key(hidpp->input, BTN_MIDDLE, 1); in m560_raw_event()
2709 input_report_key(hidpp->input, BTN_FORWARD, 1); in m560_raw_event()
2712 input_report_key(hidpp->input, BTN_BACK, 1); in m560_raw_event()
2715 input_report_key(hidpp->input, BTN_BACK, 0); in m560_raw_event()
2716 input_report_key(hidpp->input, BTN_FORWARD, 0); in m560_raw_event()
2717 input_report_key(hidpp->input, BTN_MIDDLE, 0); in m560_raw_event()
2723 input_sync(hidpp->input); in m560_raw_event()
2737 input_report_key(hidpp->input, BTN_LEFT, in m560_raw_event()
2739 input_report_key(hidpp->input, BTN_RIGHT, in m560_raw_event()
2743 input_report_rel(hidpp->input, REL_HWHEEL, -1); in m560_raw_event()
2744 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, in m560_raw_event()
2745 -120); in m560_raw_event()
2747 input_report_rel(hidpp->input, REL_HWHEEL, 1); in m560_raw_event()
2748 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, in m560_raw_event()
2753 input_report_rel(hidpp->input, REL_X, v); in m560_raw_event()
2756 input_report_rel(hidpp->input, REL_Y, v); in m560_raw_event()
2760 hidpp_scroll_counter_handle_scroll(hidpp->input, in m560_raw_event()
2761 &hidpp->vertical_wheel_counter, v); in m560_raw_event()
2763 input_sync(hidpp->input); in m560_raw_event()
2772 __set_bit(EV_KEY, input_dev->evbit); in m560_populate_input()
2773 __set_bit(BTN_MIDDLE, input_dev->keybit); in m560_populate_input()
2774 __set_bit(BTN_RIGHT, input_dev->keybit); in m560_populate_input()
2775 __set_bit(BTN_LEFT, input_dev->keybit); in m560_populate_input()
2776 __set_bit(BTN_BACK, input_dev->keybit); in m560_populate_input()
2777 __set_bit(BTN_FORWARD, input_dev->keybit); in m560_populate_input()
2779 __set_bit(EV_REL, input_dev->evbit); in m560_populate_input()
2780 __set_bit(REL_X, input_dev->relbit); in m560_populate_input()
2781 __set_bit(REL_Y, input_dev->relbit); in m560_populate_input()
2782 __set_bit(REL_WHEEL, input_dev->relbit); in m560_populate_input()
2783 __set_bit(REL_HWHEEL, input_dev->relbit); in m560_populate_input()
2784 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit); in m560_populate_input()
2785 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit); in m560_populate_input()
2792 return -1; in m560_input_mapping()
2795 /* ------------------------------------------------------------------------- */
2797 /* ------------------------------------------------------------------------- */
2802 * tap-to-click but the setting is not remembered accross reset, annoying some
2815 struct k400_private_data *k400 = hidpp->private_data; in k400_disable_tap_to_click()
2820 if (!k400->feature_index) { in k400_disable_tap_to_click()
2823 &k400->feature_index, &feature_type); in k400_disable_tap_to_click()
2829 ret = hidpp_touchpad_fw_items_set(hidpp, k400->feature_index, &items); in k400_disable_tap_to_click()
2841 k400 = devm_kzalloc(&hdev->dev, sizeof(struct k400_private_data), in k400_allocate()
2844 return -ENOMEM; in k400_allocate()
2846 hidpp->private_data = k400; in k400_allocate()
2861 /* ------------------------------------------------------------------------- */
2863 /* ------------------------------------------------------------------------- */
2879 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_ff_set_autocenter()
2884 hid_warn(hidpp->hid_dev, "Failed to autocenter device!\n"); in g920_ff_set_autocenter()
2886 data->slot_autocenter = response.fap.params[0]; in g920_ff_set_autocenter()
2902 &data->feature_index, &feature_type); in g920_get_config()
2907 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
2914 hid_err(hidpp->hid_dev, in g920_get_config()
2916 return -EPROTO; in g920_get_config()
2919 data->num_effects = response.fap.params[0] - HIDPP_FF_RESERVED_SLOTS; in g920_get_config()
2922 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
2927 hid_warn(hidpp->hid_dev, "Failed to reset all forces!\n"); in g920_get_config()
2929 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
2934 hid_warn(hidpp->hid_dev, in g920_get_config()
2937 data->range = ret ? in g920_get_config()
2941 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
2946 hid_warn(hidpp->hid_dev, in g920_get_config()
2948 data->gain = ret ? in g920_get_config()
2956 /* -------------------------------------------------------------------------- */
2958 /* -------------------------------------------------------------------------- */
2965 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) in lg_dinovo_input_mapping()
2968 switch (usage->hid & HID_USAGE) { in lg_dinovo_input_mapping()
2976 /* -------------------------------------------------------------------------- */
2978 /* -------------------------------------------------------------------------- */
2991 if (!hidpp->input) in hidpp10_wheel_raw_event()
2992 return -EINVAL; in hidpp10_wheel_raw_event()
3003 input_report_rel(hidpp->input, REL_WHEEL, value); in hidpp10_wheel_raw_event()
3004 input_report_rel(hidpp->input, REL_WHEEL_HI_RES, value * 120); in hidpp10_wheel_raw_event()
3005 input_report_rel(hidpp->input, REL_HWHEEL, hvalue); in hidpp10_wheel_raw_event()
3006 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, hvalue * 120); in hidpp10_wheel_raw_event()
3007 input_sync(hidpp->input); in hidpp10_wheel_raw_event()
3015 __set_bit(EV_REL, input_dev->evbit); in hidpp10_wheel_populate_input()
3016 __set_bit(REL_WHEEL, input_dev->relbit); in hidpp10_wheel_populate_input()
3017 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit); in hidpp10_wheel_populate_input()
3018 __set_bit(REL_HWHEEL, input_dev->relbit); in hidpp10_wheel_populate_input()
3019 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit); in hidpp10_wheel_populate_input()
3022 /* -------------------------------------------------------------------------- */
3024 /* -------------------------------------------------------------------------- */
3037 if (!hidpp->input) in hidpp10_extra_mouse_buttons_raw_event()
3038 return -EINVAL; in hidpp10_extra_mouse_buttons_raw_event()
3051 * the same usb-id show different behavior, so we handle both cases. in hidpp10_extra_mouse_buttons_raw_event()
3054 input_report_key(hidpp->input, BTN_MOUSE + i, in hidpp10_extra_mouse_buttons_raw_event()
3059 input_report_key(hidpp->input, BTN_MISC + i, in hidpp10_extra_mouse_buttons_raw_event()
3062 input_sync(hidpp->input); in hidpp10_extra_mouse_buttons_raw_event()
3069 /* BTN_MOUSE - BTN_MOUSE+7 are set already by the descriptor */ in hidpp10_extra_mouse_buttons_populate_input()
3070 __set_bit(BTN_0, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3071 __set_bit(BTN_1, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3072 __set_bit(BTN_2, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3073 __set_bit(BTN_3, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3074 __set_bit(BTN_4, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3075 __set_bit(BTN_5, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3076 __set_bit(BTN_6, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3077 __set_bit(BTN_7, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3080 /* -------------------------------------------------------------------------- */
3081 /* HID++1.0 kbds which only report 0x10xx consumer usages through sub-id 0x03 */
3082 /* -------------------------------------------------------------------------- */
3084 /* Find the consumer-page input report desc and change Maximums to 0x107f */
3103 size = *rsize - (consumer_rdesc - rdesc); in hidpp10_consumer_keys_report_fixup()
3139 hid_report_raw_event(hidpp->hid_dev, HID_INPUT_REPORT, in hidpp10_consumer_keys_raw_event()
3145 /* -------------------------------------------------------------------------- */
3146 /* High-resolution scroll wheels */
3147 /* -------------------------------------------------------------------------- */
3154 if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2121) { in hi_res_scroll_enable()
3158 } else if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2120) { in hi_res_scroll_enable()
3161 } else /* if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_1P0) */ { in hi_res_scroll_enable()
3171 hidpp->vertical_wheel_counter.wheel_multiplier = multiplier; in hi_res_scroll_enable()
3172 hid_dbg(hidpp->hid_dev, "wheel multiplier = %d\n", multiplier); in hi_res_scroll_enable()
3176 /* -------------------------------------------------------------------------- */
3178 /* -------------------------------------------------------------------------- */
3189 if (hdev->group == HID_GROUP_LOGITECH_27MHZ_DEVICE || in hidpp_report_fixup()
3190 (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS)) in hidpp_report_fixup()
3205 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_input_mapping()
3207 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 && in hidpp_input_mapping()
3208 field->application != HID_GD_MOUSE) in hidpp_input_mapping()
3211 if (hdev->product == DINOVO_MINI_PRODUCT_ID) in hidpp_input_mapping()
3226 /* Ensure that Logitech G920 is not given a default fuzz/flat value */ in hidpp_input_mapped()
3227 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { in hidpp_input_mapped()
3228 if (usage->type == EV_ABS && (usage->code == ABS_X || in hidpp_input_mapped()
3229 usage->code == ABS_Y || usage->code == ABS_Z || in hidpp_input_mapped()
3230 usage->code == ABS_RZ)) { in hidpp_input_mapped()
3231 field->application = HID_GD_MULTIAXIS; in hidpp_input_mapped()
3242 hidpp->input = input; in hidpp_populate_input()
3244 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_populate_input()
3246 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) in hidpp_populate_input()
3249 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) in hidpp_populate_input()
3252 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) in hidpp_populate_input()
3260 struct input_dev *input = hidinput->input; in hidpp_input_configured()
3273 struct hidpp_report *question = hidpp->send_receive_buf; in hidpp_raw_hidpp_event()
3274 struct hidpp_report *answer = hidpp->send_receive_buf; in hidpp_raw_hidpp_event()
3282 if (unlikely(mutex_is_locked(&hidpp->send_mutex))) { in hidpp_raw_hidpp_event()
3290 hidpp->answer_available = true; in hidpp_raw_hidpp_event()
3291 wake_up(&hidpp->wait); in hidpp_raw_hidpp_event()
3294 * We return 1 to hid-core to avoid forwarding the in hidpp_raw_hidpp_event()
3303 atomic_set(&hidpp->connected, in hidpp_raw_hidpp_event()
3304 !(report->rap.params[0] & (1 << 6))); in hidpp_raw_hidpp_event()
3305 if (schedule_work(&hidpp->work) == 0) in hidpp_raw_hidpp_event()
3310 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { in hidpp_raw_hidpp_event()
3322 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) { in hidpp_raw_hidpp_event()
3328 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) { in hidpp_raw_hidpp_event()
3334 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) { in hidpp_raw_hidpp_event()
3340 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) { in hidpp_raw_hidpp_event()
3361 if (size != hidpp->very_long_report_length) { in hidpp_raw_event()
3391 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_raw_event()
3393 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) in hidpp_raw_event()
3411 counter = &hidpp->vertical_wheel_counter; in hidpp_event()
3413 * the input device set, or high-res scroll enabling may fail. In such in hidpp_event()
3417 if (!(hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL) || value == 0 in hidpp_event()
3418 || hidpp->input == NULL || counter->wheel_multiplier == 0) in hidpp_event()
3421 hidpp_scroll_counter_handle_scroll(hidpp->input, counter, value); in hidpp_event()
3429 struct power_supply_desc *desc = &hidpp->battery.desc; in hidpp_initialize_battery()
3436 if (hidpp->battery.ps) in hidpp_initialize_battery()
3439 hidpp->battery.feature_index = 0xff; in hidpp_initialize_battery()
3440 hidpp->battery.solar_feature_index = 0xff; in hidpp_initialize_battery()
3441 hidpp->battery.voltage_feature_index = 0xff; in hidpp_initialize_battery()
3443 if (hidpp->protocol_major >= 2) { in hidpp_initialize_battery()
3444 if (hidpp->quirks & HIDPP_QUIRK_CLASS_K750) in hidpp_initialize_battery()
3454 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_BATTERY; in hidpp_initialize_battery()
3460 return -ENOENT; in hidpp_initialize_battery()
3461 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp_initialize_battery()
3463 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS; in hidpp_initialize_battery()
3465 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP10_BATTERY; in hidpp_initialize_battery()
3468 battery_props = devm_kmemdup(&hidpp->hid_dev->dev, in hidpp_initialize_battery()
3473 return -ENOMEM; in hidpp_initialize_battery()
3475 num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 3; in hidpp_initialize_battery()
3477 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE) in hidpp_initialize_battery()
3481 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS) in hidpp_initialize_battery()
3485 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE) in hidpp_initialize_battery()
3489 battery = &hidpp->battery; in hidpp_initialize_battery()
3491 n = atomic_inc_return(&battery_no) - 1; in hidpp_initialize_battery()
3492 desc->properties = battery_props; in hidpp_initialize_battery()
3493 desc->num_properties = num_battery_props; in hidpp_initialize_battery()
3494 desc->get_property = hidpp_battery_get_property; in hidpp_initialize_battery()
3495 sprintf(battery->name, "hidpp_battery_%ld", n); in hidpp_initialize_battery()
3496 desc->name = battery->name; in hidpp_initialize_battery()
3497 desc->type = POWER_SUPPLY_TYPE_BATTERY; in hidpp_initialize_battery()
3498 desc->use_for_apm = 0; in hidpp_initialize_battery()
3500 battery->ps = devm_power_supply_register(&hidpp->hid_dev->dev, in hidpp_initialize_battery()
3501 &battery->desc, in hidpp_initialize_battery()
3503 if (IS_ERR(battery->ps)) in hidpp_initialize_battery()
3504 return PTR_ERR(battery->ps); in hidpp_initialize_battery()
3506 power_supply_powers(battery->ps, &hidpp->hid_dev->dev); in hidpp_initialize_battery()
3516 if (hidpp->protocol_major < 2) in hidpp_overwrite_name()
3525 snprintf(hdev->name, sizeof(hdev->name), "%s", name); in hidpp_overwrite_name()
3547 struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev); in hidpp_allocate_input()
3554 input_dev->open = hidpp_input_open; in hidpp_allocate_input()
3555 input_dev->close = hidpp_input_close; in hidpp_allocate_input()
3557 input_dev->name = hidpp->name; in hidpp_allocate_input()
3558 input_dev->phys = hdev->phys; in hidpp_allocate_input()
3559 input_dev->uniq = hdev->uniq; in hidpp_allocate_input()
3560 input_dev->id.bustype = hdev->bus; in hidpp_allocate_input()
3561 input_dev->id.vendor = hdev->vendor; in hidpp_allocate_input()
3562 input_dev->id.product = hdev->product; in hidpp_allocate_input()
3563 input_dev->id.version = hdev->version; in hidpp_allocate_input()
3564 input_dev->dev.parent = &hdev->dev; in hidpp_allocate_input()
3571 struct hid_device *hdev = hidpp->hid_dev; in hidpp_connect_event()
3573 bool connected = atomic_read(&hidpp->connected); in hidpp_connect_event()
3578 if (hidpp->battery.ps) { in hidpp_connect_event()
3579 hidpp->battery.online = false; in hidpp_connect_event()
3580 hidpp->battery.status = POWER_SUPPLY_STATUS_UNKNOWN; in hidpp_connect_event()
3581 hidpp->battery.level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; in hidpp_connect_event()
3582 power_supply_changed(hidpp->battery.ps); in hidpp_connect_event()
3587 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { in hidpp_connect_event()
3591 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) { in hidpp_connect_event()
3595 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) { in hidpp_connect_event()
3601 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) { in hidpp_connect_event()
3607 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) { in hidpp_connect_event()
3613 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) { in hidpp_connect_event()
3621 if (!hidpp->protocol_major) { in hidpp_connect_event()
3629 if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) { in hidpp_connect_event()
3632 devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL, in hidpp_connect_event()
3638 hidpp->name = devm_name; in hidpp_connect_event()
3645 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) { in hidpp_connect_event()
3647 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE) in hidpp_connect_event()
3651 } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { in hidpp_connect_event()
3652 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE) in hidpp_connect_event()
3657 if (hidpp->battery.ps) in hidpp_connect_event()
3658 power_supply_changed(hidpp->battery.ps); in hidpp_connect_event()
3660 if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL) in hidpp_connect_event()
3663 if (!(hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) || hidpp->delayed_input) in hidpp_connect_event()
3679 hidpp->delayed_input = input; in hidpp_connect_event()
3698 re = &(hdev->report_enum[HID_OUTPUT_REPORT]); in hidpp_get_report_length()
3699 report = re->report_id_hash[id]; in hidpp_get_report_length()
3703 return report->field[0]->report_count + 1; in hidpp_get_report_length()
3738 hidpp->very_long_report_length = report_length; in hidpp_validate_device()
3754 report_list = &hdev->report_enum[HID_INPUT_REPORT].report_list; in hidpp_application_equals()
3756 return report && report->application == application; in hidpp_application_equals()
3768 hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL); in hidpp_probe()
3770 return -ENOMEM; in hidpp_probe()
3772 hidpp->hid_dev = hdev; in hidpp_probe()
3773 hidpp->name = hdev->name; in hidpp_probe()
3774 hidpp->quirks = id->driver_data; in hidpp_probe()
3786 hidpp->supported_reports = hidpp_validate_device(hdev); in hidpp_probe()
3788 if (!hidpp->supported_reports) { in hidpp_probe()
3790 devm_kfree(&hdev->dev, hidpp); in hidpp_probe()
3794 if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE) in hidpp_probe()
3795 hidpp->quirks |= HIDPP_QUIRK_UNIFYING; in hidpp_probe()
3797 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE && in hidpp_probe()
3799 hidpp->quirks |= HIDPP_QUIRK_HIDPP_WHEELS | in hidpp_probe()
3802 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE && in hidpp_probe()
3804 hidpp->quirks |= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS; in hidpp_probe()
3807 hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP; in hidpp_probe()
3808 hidpp->quirks &= ~HIDPP_QUIRK_NO_HIDINPUT; in hidpp_probe()
3811 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { in hidpp_probe()
3815 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) { in hidpp_probe()
3821 INIT_WORK(&hidpp->work, delayed_work_cb); in hidpp_probe()
3822 mutex_init(&hidpp->send_mutex); in hidpp_probe()
3823 init_waitqueue_head(&hidpp->wait); in hidpp_probe()
3826 ret = sysfs_create_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_probe()
3829 hdev->name); in hidpp_probe()
3843 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n", in hidpp_probe()
3851 if (hidpp->quirks & HIDPP_QUIRK_UNIFYING) in hidpp_probe()
3855 atomic_set(&hidpp->connected, connected); in hidpp_probe()
3856 if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) { in hidpp_probe()
3858 ret = -ENODEV; in hidpp_probe()
3866 if (connected && hidpp->protocol_major >= 2) { in hidpp_probe()
3868 if (ret == -ENOENT) in hidpp_probe()
3869 hidpp->wireless_feature_index = 0; in hidpp_probe()
3874 if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { in hidpp_probe()
3878 } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { in hidpp_probe()
3891 if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) in hidpp_probe()
3901 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { in hidpp_probe()
3904 hid_warn(hidpp->hid_dev, in hidpp_probe()
3916 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_probe()
3917 cancel_work_sync(&hidpp->work); in hidpp_probe()
3918 mutex_destroy(&hidpp->send_mutex); in hidpp_probe()
3929 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_remove()
3932 cancel_work_sync(&hidpp->work); in hidpp_remove()
3933 mutex_destroy(&hidpp->send_mutex); in hidpp_remove()
3998 { /* Keyboard MX5000 (Bluetooth-receiver in HID proxy mode) */
4001 { /* Dinovo Edge (Bluetooth-receiver in HID proxy mode) */
4004 { /* Keyboard MX5500 (Bluetooth-receiver in HID proxy mode) */
4010 { /* Keyboard LX501 (Y-RR53) */
4013 { /* Keyboard MX3000 (Y-RAM74) */
4016 { /* Keyboard MX3200 (Y-RAV80) */
4069 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
4073 .name = "logitech-hidpp-device",