Lines Matching +full:battery +full:- +full:powered
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)
198 struct hidpp_battery battery; member
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()
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 /* -------------------------------------------------------------------------- */
1040 /* 0x1000: Battery level status */
1041 /* -------------------------------------------------------------------------- */
1101 /* 5 = invalid battery type in hidpp20_batterylevel_map_status_capacity()
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 /* -------------------------------------------------------------------------- */
1247 /* 0x1001: Battery voltage */
1248 /* -------------------------------------------------------------------------- */
1312 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_battery_get_battery_voltage()
1314 return -EPROTO; in hidpp20_battery_get_battery_voltage()
1319 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_VOLTAGE; in hidpp20_battery_get_battery_voltage()
1333 if (hidpp->battery.voltage_feature_index == 0xff) { in hidpp20_query_battery_voltage_info()
1335 &hidpp->battery.voltage_feature_index, in hidpp20_query_battery_voltage_info()
1342 hidpp->battery.voltage_feature_index, in hidpp20_query_battery_voltage_info()
1348 hidpp->battery.status = status; in hidpp20_query_battery_voltage_info()
1349 hidpp->battery.voltage = voltage; in hidpp20_query_battery_voltage_info()
1350 hidpp->battery.level = level; in hidpp20_query_battery_voltage_info()
1351 hidpp->battery.charge_type = charge_type; in hidpp20_query_battery_voltage_info()
1352 hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING; in hidpp20_query_battery_voltage_info()
1363 if (report->fap.feature_index != hidpp->battery.voltage_feature_index || in hidpp20_battery_voltage_event()
1364 report->fap.funcindex_clientid != EVENT_BATTERY_VOLTAGE_STATUS_BROADCAST) in hidpp20_battery_voltage_event()
1367 status = hidpp20_battery_map_status_voltage(report->fap.params, &voltage, in hidpp20_battery_voltage_event()
1370 hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING; in hidpp20_battery_voltage_event()
1372 if (voltage != hidpp->battery.voltage || status != hidpp->battery.status) { in hidpp20_battery_voltage_event()
1373 hidpp->battery.voltage = voltage; in hidpp20_battery_voltage_event()
1374 hidpp->battery.status = status; in hidpp20_battery_voltage_event()
1375 hidpp->battery.level = level; in hidpp20_battery_voltage_event()
1376 hidpp->battery.charge_type = charge_type; in hidpp20_battery_voltage_event()
1377 if (hidpp->battery.ps) in hidpp20_battery_voltage_event()
1378 power_supply_changed(hidpp->battery.ps); in hidpp20_battery_voltage_event()
1404 val->intval = hidpp->battery.status; in hidpp_battery_get_property()
1407 val->intval = hidpp->battery.capacity; in hidpp_battery_get_property()
1410 val->intval = hidpp->battery.level; in hidpp_battery_get_property()
1413 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in hidpp_battery_get_property()
1416 val->intval = hidpp->battery.online; in hidpp_battery_get_property()
1419 if (!strncmp(hidpp->name, "Logitech ", 9)) in hidpp_battery_get_property()
1420 val->strval = hidpp->name + 9; in hidpp_battery_get_property()
1422 val->strval = hidpp->name; in hidpp_battery_get_property()
1425 val->strval = "Logitech"; in hidpp_battery_get_property()
1428 val->strval = hidpp->hid_dev->uniq; in hidpp_battery_get_property()
1432 val->intval = hidpp->battery.voltage * 1000; in hidpp_battery_get_property()
1435 val->intval = hidpp->battery.charge_type; in hidpp_battery_get_property()
1438 ret = -EINVAL; in hidpp_battery_get_property()
1445 /* -------------------------------------------------------------------------- */
1447 /* -------------------------------------------------------------------------- */
1457 &hidpp->wireless_feature_index, in hidpp_set_wireless_feature_index()
1463 /* -------------------------------------------------------------------------- */
1464 /* 0x2120: Hi-resolution scrolling */
1465 /* -------------------------------------------------------------------------- */
1497 /* -------------------------------------------------------------------------- */
1499 /* -------------------------------------------------------------------------- */
1528 hid_warn(hidpp->hid_dev, in hidpp_hrw_get_wheel_capability()
1556 /* -------------------------------------------------------------------------- */
1558 /* -------------------------------------------------------------------------- */
1575 if (hidpp->battery.feature_index == 0xff) { in hidpp_solar_request_battery_event()
1578 &hidpp->battery.solar_feature_index, in hidpp_solar_request_battery_event()
1585 hidpp->battery.solar_feature_index, in hidpp_solar_request_battery_event()
1589 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_solar_request_battery_event()
1591 return -EPROTO; in hidpp_solar_request_battery_event()
1596 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp_solar_request_battery_event()
1608 function = report->fap.funcindex_clientid; in hidpp_solar_battery_event()
1611 if (report->fap.feature_index != hidpp->battery.solar_feature_index || in hidpp_solar_battery_event()
1617 capacity = report->fap.params[0]; in hidpp_solar_battery_event()
1621 lux = (report->fap.params[1] << 8) | report->fap.params[2]; in hidpp_solar_battery_event()
1629 if (capacity < hidpp->battery.capacity) in hidpp_solar_battery_event()
1639 hidpp->battery.online = true; in hidpp_solar_battery_event()
1640 if (capacity != hidpp->battery.capacity || in hidpp_solar_battery_event()
1641 status != hidpp->battery.status) { in hidpp_solar_battery_event()
1642 hidpp->battery.capacity = capacity; in hidpp_solar_battery_event()
1643 hidpp->battery.status = status; in hidpp_solar_battery_event()
1644 if (hidpp->battery.ps) in hidpp_solar_battery_event()
1645 power_supply_changed(hidpp->battery.ps); in hidpp_solar_battery_event()
1651 /* -------------------------------------------------------------------------- */
1653 /* -------------------------------------------------------------------------- */
1667 * send a set state command to the device by reading the current items->state
1679 CMD_TOUCHPAD_FW_ITEMS_SET, &items->state, 1, &response); in hidpp_touchpad_fw_items_set()
1682 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_touchpad_fw_items_set()
1684 return -EPROTO; in hidpp_touchpad_fw_items_set()
1689 items->presence = params[0]; in hidpp_touchpad_fw_items_set()
1690 items->desired_state = params[1]; in hidpp_touchpad_fw_items_set()
1691 items->state = params[2]; in hidpp_touchpad_fw_items_set()
1692 items->persistent = params[3]; in hidpp_touchpad_fw_items_set()
1697 /* -------------------------------------------------------------------------- */
1699 /* -------------------------------------------------------------------------- */
1752 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_touchpad_get_raw_info()
1754 return -EPROTO; in hidpp_touchpad_get_raw_info()
1759 raw_info->x_size = get_unaligned_be16(¶ms[0]); in hidpp_touchpad_get_raw_info()
1760 raw_info->y_size = get_unaligned_be16(¶ms[2]); in hidpp_touchpad_get_raw_info()
1761 raw_info->z_range = params[4]; in hidpp_touchpad_get_raw_info()
1762 raw_info->area_range = params[5]; in hidpp_touchpad_get_raw_info()
1763 raw_info->maxcontacts = params[7]; in hidpp_touchpad_get_raw_info()
1764 raw_info->origin = params[8]; in hidpp_touchpad_get_raw_info()
1766 raw_info->res = get_unaligned_be16(¶ms[13]) * 2 / 51; in hidpp_touchpad_get_raw_info()
1779 * bit 0 - enable raw in hidpp_touchpad_set_raw_report_state()
1780 * bit 1 - 16bit Z, no area in hidpp_touchpad_set_raw_report_state()
1781 * bit 2 - enhanced sensitivity in hidpp_touchpad_set_raw_report_state()
1782 * bit 3 - width, height (4 bits each) instead of area in hidpp_touchpad_set_raw_report_state()
1783 * bit 4 - send raw + gestures (degrades smoothness) in hidpp_touchpad_set_raw_report_state()
1784 * remaining bits - reserved in hidpp_touchpad_set_raw_report_state()
1798 finger->x = x_m << 6 | data[1]; in hidpp_touchpad_touch_event()
1799 finger->y = y_m << 6 | data[3]; in hidpp_touchpad_touch_event()
1801 finger->contact_type = data[0] >> 6; in hidpp_touchpad_touch_event()
1802 finger->contact_status = data[2] >> 6; in hidpp_touchpad_touch_event()
1804 finger->z = data[4]; in hidpp_touchpad_touch_event()
1805 finger->area = data[5]; in hidpp_touchpad_touch_event()
1806 finger->finger_id = data[6] >> 4; in hidpp_touchpad_touch_event()
1813 raw_xy->end_of_frame = data[8] & 0x01; in hidpp_touchpad_raw_xy_event()
1814 raw_xy->spurious_flag = (data[8] >> 1) & 0x01; in hidpp_touchpad_raw_xy_event()
1815 raw_xy->finger_count = data[15] & 0x0f; in hidpp_touchpad_raw_xy_event()
1816 raw_xy->button = (data[8] >> 2) & 0x01; in hidpp_touchpad_raw_xy_event()
1818 if (raw_xy->finger_count) { in hidpp_touchpad_raw_xy_event()
1819 hidpp_touchpad_touch_event(&data[2], &raw_xy->fingers[0]); in hidpp_touchpad_raw_xy_event()
1820 hidpp_touchpad_touch_event(&data[9], &raw_xy->fingers[1]); in hidpp_touchpad_raw_xy_event()
1824 /* -------------------------------------------------------------------------- */
1826 /* -------------------------------------------------------------------------- */
1857 #define HIDPP_FF_EFFECTID_NONE -1
1858 #define HIDPP_FF_EFFECTID_AUTOCENTER -2
1898 -1
1905 -1
1927 for (i = 0; i < data->num_effects; i++) in hidpp_ff_find_effect()
1928 if (data->effect_ids[i] == effect_id) in hidpp_ff_find_effect()
1937 struct hidpp_ff_private_data *data = wd->data; in hidpp_ff_work_handler()
1943 switch (wd->effect_id) { in hidpp_ff_work_handler()
1945 wd->params[0] = data->slot_autocenter; in hidpp_ff_work_handler()
1952 wd->params[0] = hidpp_ff_find_effect(data, wd->effect_id); in hidpp_ff_work_handler()
1957 ret = hidpp_send_fap_command_sync(data->hidpp, data->feature_index, in hidpp_ff_work_handler()
1958 wd->command, wd->params, wd->size, &response); in hidpp_ff_work_handler()
1961 hid_err(data->hidpp->hid_dev, "Failed to send command to device!\n"); in hidpp_ff_work_handler()
1966 switch (wd->command) { in hidpp_ff_work_handler()
1969 if (slot > 0 && slot <= data->num_effects) { in hidpp_ff_work_handler()
1970 if (wd->effect_id >= 0) in hidpp_ff_work_handler()
1972 data->effect_ids[slot-1] = wd->effect_id; in hidpp_ff_work_handler()
1973 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) in hidpp_ff_work_handler()
1975 data->slot_autocenter = slot; in hidpp_ff_work_handler()
1979 if (wd->effect_id >= 0) in hidpp_ff_work_handler()
1981 data->effect_ids[wd->params[0]-1] = -1; in hidpp_ff_work_handler()
1982 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) in hidpp_ff_work_handler()
1984 data->slot_autocenter = 0; in hidpp_ff_work_handler()
1987 data->gain = (wd->params[0] << 8) + wd->params[1]; in hidpp_ff_work_handler()
1990 data->range = (wd->params[0] << 8) + wd->params[1]; in hidpp_ff_work_handler()
1998 atomic_dec(&data->workqueue_size); in hidpp_ff_work_handler()
2008 return -ENOMEM; in hidpp_ff_queue_work()
2010 INIT_WORK(&wd->work, hidpp_ff_work_handler); in hidpp_ff_queue_work()
2012 wd->data = data; in hidpp_ff_queue_work()
2013 wd->effect_id = effect_id; in hidpp_ff_queue_work()
2014 wd->command = command; in hidpp_ff_queue_work()
2015 wd->size = size; in hidpp_ff_queue_work()
2016 memcpy(wd->params, params, size); in hidpp_ff_queue_work()
2018 atomic_inc(&data->workqueue_size); in hidpp_ff_queue_work()
2019 queue_work(data->wq, &wd->work); in hidpp_ff_queue_work()
2022 s = atomic_read(&data->workqueue_size); in hidpp_ff_queue_work()
2024 …hid_warn(data->hidpp->hid_dev, "Force feedback command queue contains %d commands, causing substan… in hidpp_ff_queue_work()
2031 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_upload_effect()
2037 params[2] = effect->replay.length >> 8; in hidpp_ff_upload_effect()
2038 params[3] = effect->replay.length & 255; in hidpp_ff_upload_effect()
2039 params[4] = effect->replay.delay >> 8; in hidpp_ff_upload_effect()
2040 params[5] = effect->replay.delay & 255; in hidpp_ff_upload_effect()
2042 switch (effect->type) { in hidpp_ff_upload_effect()
2044 force = (effect->u.constant.level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2048 params[8] = effect->u.constant.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
2049 params[9] = effect->u.constant.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
2050 params[10] = effect->u.constant.envelope.attack_length & 255; in hidpp_ff_upload_effect()
2051 params[11] = effect->u.constant.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
2052 params[12] = effect->u.constant.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
2053 params[13] = effect->u.constant.envelope.fade_length & 255; in hidpp_ff_upload_effect()
2056 effect->u.constant.level, in hidpp_ff_upload_effect()
2057 effect->direction, force); in hidpp_ff_upload_effect()
2059 effect->u.constant.envelope.attack_level, in hidpp_ff_upload_effect()
2060 effect->u.constant.envelope.attack_length, in hidpp_ff_upload_effect()
2061 effect->u.constant.envelope.fade_level, in hidpp_ff_upload_effect()
2062 effect->u.constant.envelope.fade_length); in hidpp_ff_upload_effect()
2066 switch (effect->u.periodic.waveform) { in hidpp_ff_upload_effect()
2083 …hid_err(data->hidpp->hid_dev, "Unexpected periodic waveform type %i!\n", effect->u.periodic.wavefo… in hidpp_ff_upload_effect()
2084 return -EINVAL; in hidpp_ff_upload_effect()
2086 force = (effect->u.periodic.magnitude * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2087 params[6] = effect->u.periodic.magnitude >> 8; in hidpp_ff_upload_effect()
2088 params[7] = effect->u.periodic.magnitude & 255; in hidpp_ff_upload_effect()
2089 params[8] = effect->u.periodic.offset >> 8; in hidpp_ff_upload_effect()
2090 params[9] = effect->u.periodic.offset & 255; in hidpp_ff_upload_effect()
2091 params[10] = effect->u.periodic.period >> 8; in hidpp_ff_upload_effect()
2092 params[11] = effect->u.periodic.period & 255; in hidpp_ff_upload_effect()
2093 params[12] = effect->u.periodic.phase >> 8; in hidpp_ff_upload_effect()
2094 params[13] = effect->u.periodic.phase & 255; in hidpp_ff_upload_effect()
2095 params[14] = effect->u.periodic.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
2096 params[15] = effect->u.periodic.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
2097 params[16] = effect->u.periodic.envelope.attack_length & 255; in hidpp_ff_upload_effect()
2098 params[17] = effect->u.periodic.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
2099 params[18] = effect->u.periodic.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
2100 params[19] = effect->u.periodic.envelope.fade_length & 255; in hidpp_ff_upload_effect()
2103 effect->u.periodic.magnitude, effect->direction, in hidpp_ff_upload_effect()
2104 effect->u.periodic.offset, in hidpp_ff_upload_effect()
2105 effect->u.periodic.period, in hidpp_ff_upload_effect()
2106 effect->u.periodic.phase); in hidpp_ff_upload_effect()
2108 effect->u.periodic.envelope.attack_level, in hidpp_ff_upload_effect()
2109 effect->u.periodic.envelope.attack_length, in hidpp_ff_upload_effect()
2110 effect->u.periodic.envelope.fade_level, in hidpp_ff_upload_effect()
2111 effect->u.periodic.envelope.fade_length); in hidpp_ff_upload_effect()
2116 force = (effect->u.ramp.start_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2119 force = (effect->u.ramp.end_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
2122 params[10] = effect->u.ramp.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
2123 params[11] = effect->u.ramp.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
2124 params[12] = effect->u.ramp.envelope.attack_length & 255; in hidpp_ff_upload_effect()
2125 params[13] = effect->u.ramp.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
2126 params[14] = effect->u.ramp.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
2127 params[15] = effect->u.ramp.envelope.fade_length & 255; in hidpp_ff_upload_effect()
2129 dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n", in hidpp_ff_upload_effect()
2130 effect->u.ramp.start_level, in hidpp_ff_upload_effect()
2131 effect->u.ramp.end_level, in hidpp_ff_upload_effect()
2132 effect->direction, force); in hidpp_ff_upload_effect()
2134 effect->u.ramp.envelope.attack_level, in hidpp_ff_upload_effect()
2135 effect->u.ramp.envelope.attack_length, in hidpp_ff_upload_effect()
2136 effect->u.ramp.envelope.fade_level, in hidpp_ff_upload_effect()
2137 effect->u.ramp.envelope.fade_length); in hidpp_ff_upload_effect()
2143 params[1] = HIDPP_FF_CONDITION_CMDS[effect->type - FF_SPRING]; in hidpp_ff_upload_effect()
2144 params[6] = effect->u.condition[0].left_saturation >> 9; in hidpp_ff_upload_effect()
2145 params[7] = (effect->u.condition[0].left_saturation >> 1) & 255; in hidpp_ff_upload_effect()
2146 params[8] = effect->u.condition[0].left_coeff >> 8; in hidpp_ff_upload_effect()
2147 params[9] = effect->u.condition[0].left_coeff & 255; in hidpp_ff_upload_effect()
2148 params[10] = effect->u.condition[0].deadband >> 9; in hidpp_ff_upload_effect()
2149 params[11] = (effect->u.condition[0].deadband >> 1) & 255; in hidpp_ff_upload_effect()
2150 params[12] = effect->u.condition[0].center >> 8; in hidpp_ff_upload_effect()
2151 params[13] = effect->u.condition[0].center & 255; in hidpp_ff_upload_effect()
2152 params[14] = effect->u.condition[0].right_coeff >> 8; in hidpp_ff_upload_effect()
2153 params[15] = effect->u.condition[0].right_coeff & 255; in hidpp_ff_upload_effect()
2154 params[16] = effect->u.condition[0].right_saturation >> 9; in hidpp_ff_upload_effect()
2155 params[17] = (effect->u.condition[0].right_saturation >> 1) & 255; in hidpp_ff_upload_effect()
2158 HIDPP_FF_CONDITION_NAMES[effect->type - FF_SPRING], in hidpp_ff_upload_effect()
2159 effect->u.condition[0].left_coeff, in hidpp_ff_upload_effect()
2160 effect->u.condition[0].left_saturation, in hidpp_ff_upload_effect()
2161 effect->u.condition[0].right_coeff, in hidpp_ff_upload_effect()
2162 effect->u.condition[0].right_saturation); in hidpp_ff_upload_effect()
2164 effect->u.condition[0].deadband, in hidpp_ff_upload_effect()
2165 effect->u.condition[0].center); in hidpp_ff_upload_effect()
2168 hid_err(data->hidpp->hid_dev, "Unexpected force type %i!\n", effect->type); in hidpp_ff_upload_effect()
2169 return -EINVAL; in hidpp_ff_upload_effect()
2172 return hidpp_ff_queue_work(data, effect->id, HIDPP_FF_DOWNLOAD_EFFECT, params, size); in hidpp_ff_upload_effect()
2177 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_playback()
2189 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_erase_effect()
2199 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_set_autocenter()
2221 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_set_gain()
2237 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_range_show()
2238 struct input_dev *idev = hidinput->input; in hidpp_ff_range_show()
2239 struct hidpp_ff_private_data *data = idev->ff->private; in hidpp_ff_range_show()
2241 return scnprintf(buf, PAGE_SIZE, "%u\n", data->range); in hidpp_ff_range_show()
2247 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_range_store()
2248 struct input_dev *idev = hidinput->input; in hidpp_ff_range_store()
2249 struct hidpp_ff_private_data *data = idev->ff->private; in hidpp_ff_range_store()
2258 hidpp_ff_queue_work(data, -1, HIDPP_FF_SET_APERTURE, params, ARRAY_SIZE(params)); in hidpp_ff_range_store()
2267 struct hidpp_ff_private_data *data = ff->private; in hidpp_ff_destroy()
2268 struct hid_device *hid = data->hidpp->hid_dev; in hidpp_ff_destroy()
2272 device_remove_file(&hid->dev, &dev_attr_range); in hidpp_ff_destroy()
2273 destroy_workqueue(data->wq); in hidpp_ff_destroy()
2274 kfree(data->effect_ids); in hidpp_ff_destroy()
2280 struct hid_device *hid = hidpp->hid_dev; in hidpp_ff_init()
2283 const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor); in hidpp_ff_init()
2284 const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice); in hidpp_ff_init()
2286 int error, j, num_slots = data->num_effects; in hidpp_ff_init()
2289 if (list_empty(&hid->inputs)) { in hidpp_ff_init()
2291 return -ENODEV; in hidpp_ff_init()
2293 hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_init()
2294 dev = hidinput->input; in hidpp_ff_init()
2298 return -EINVAL; in hidpp_ff_init()
2306 set_bit(hidpp_ff_effects[j], dev->ffbit); in hidpp_ff_init()
2309 set_bit(hidpp_ff_effects_v2[j], dev->ffbit); in hidpp_ff_init()
2323 return -ENOMEM; in hidpp_ff_init()
2324 data->effect_ids = kcalloc(num_slots, sizeof(int), GFP_KERNEL); in hidpp_ff_init()
2325 if (!data->effect_ids) { in hidpp_ff_init()
2327 return -ENOMEM; in hidpp_ff_init()
2329 data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue"); in hidpp_ff_init()
2330 if (!data->wq) { in hidpp_ff_init()
2331 kfree(data->effect_ids); in hidpp_ff_init()
2333 return -ENOMEM; in hidpp_ff_init()
2336 data->hidpp = hidpp; in hidpp_ff_init()
2337 data->version = version; in hidpp_ff_init()
2339 data->effect_ids[j] = -1; in hidpp_ff_init()
2341 ff = dev->ff; in hidpp_ff_init()
2342 ff->private = data; in hidpp_ff_init()
2344 ff->upload = hidpp_ff_upload_effect; in hidpp_ff_init()
2345 ff->erase = hidpp_ff_erase_effect; in hidpp_ff_init()
2346 ff->playback = hidpp_ff_playback; in hidpp_ff_init()
2347 ff->set_gain = hidpp_ff_set_gain; in hidpp_ff_init()
2348 ff->set_autocenter = hidpp_ff_set_autocenter; in hidpp_ff_init()
2349 ff->destroy = hidpp_ff_destroy; in hidpp_ff_init()
2352 error = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range); in hidpp_ff_init()
2354 hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d!\n", error); in hidpp_ff_init()
2357 atomic_set(&data->workqueue_size, 0); in hidpp_ff_init()
2371 /* -------------------------------------------------------------------------- */
2373 /* -------------------------------------------------------------------------- */
2391 return -1; in wtp_input_mapping()
2397 struct wtp_data *wd = hidpp->private_data; in wtp_populate_input()
2399 __set_bit(EV_ABS, input_dev->evbit); in wtp_populate_input()
2400 __set_bit(EV_KEY, input_dev->evbit); in wtp_populate_input()
2401 __clear_bit(EV_REL, input_dev->evbit); in wtp_populate_input()
2402 __clear_bit(EV_LED, input_dev->evbit); in wtp_populate_input()
2404 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0); in wtp_populate_input()
2405 input_abs_set_res(input_dev, ABS_MT_POSITION_X, wd->resolution); in wtp_populate_input()
2406 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0); in wtp_populate_input()
2407 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, wd->resolution); in wtp_populate_input()
2414 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) in wtp_populate_input()
2417 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); in wtp_populate_input()
2419 input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER | in wtp_populate_input()
2426 struct wtp_data *wd = hidpp->private_data; in wtp_touch_event()
2429 if (!touch_report->finger_id || touch_report->contact_type) in wtp_touch_event()
2433 slot = input_mt_get_slot_by_key(hidpp->input, touch_report->finger_id); in wtp_touch_event()
2435 input_mt_slot(hidpp->input, slot); in wtp_touch_event()
2436 input_mt_report_slot_state(hidpp->input, MT_TOOL_FINGER, in wtp_touch_event()
2437 touch_report->contact_status); in wtp_touch_event()
2438 if (touch_report->contact_status) { in wtp_touch_event()
2439 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_X, in wtp_touch_event()
2440 touch_report->x); in wtp_touch_event()
2441 input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_Y, in wtp_touch_event()
2442 wd->flip_y ? wd->y_size - touch_report->y : in wtp_touch_event()
2443 touch_report->y); in wtp_touch_event()
2444 input_event(hidpp->input, EV_ABS, ABS_MT_PRESSURE, in wtp_touch_event()
2445 touch_report->area); in wtp_touch_event()
2455 wtp_touch_event(hidpp, &(raw->fingers[i])); in wtp_send_raw_xy_event()
2457 if (raw->end_of_frame && in wtp_send_raw_xy_event()
2458 !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS)) in wtp_send_raw_xy_event()
2459 input_event(hidpp->input, EV_KEY, BTN_LEFT, raw->button); in wtp_send_raw_xy_event()
2461 if (raw->end_of_frame || raw->finger_count <= 2) { in wtp_send_raw_xy_event()
2462 input_mt_sync_frame(hidpp->input); in wtp_send_raw_xy_event()
2463 input_sync(hidpp->input); in wtp_send_raw_xy_event()
2469 struct wtp_data *wd = hidpp->private_data; in wtp_mouse_raw_xy_event()
2495 .finger_count = wd->maxcontacts, in wtp_mouse_raw_xy_event()
2509 struct wtp_data *wd = hidpp->private_data; in wtp_raw_event()
2513 if (!wd || !hidpp->input) in wtp_raw_event()
2523 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) { in wtp_raw_event()
2524 input_event(hidpp->input, EV_KEY, BTN_LEFT, in wtp_raw_event()
2526 input_event(hidpp->input, EV_KEY, BTN_RIGHT, in wtp_raw_event()
2528 input_sync(hidpp->input); in wtp_raw_event()
2537 if ((report->fap.feature_index != wd->mt_feature_index) || in wtp_raw_event()
2538 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY)) in wtp_raw_event()
2551 struct wtp_data *wd = hidpp->private_data; in wtp_get_config()
2557 &wd->mt_feature_index, &feature_type); in wtp_get_config()
2559 /* means that the device is not powered up */ in wtp_get_config()
2562 ret = hidpp_touchpad_get_raw_info(hidpp, wd->mt_feature_index, in wtp_get_config()
2567 wd->x_size = raw_info.x_size; in wtp_get_config()
2568 wd->y_size = raw_info.y_size; in wtp_get_config()
2569 wd->maxcontacts = raw_info.maxcontacts; in wtp_get_config()
2570 wd->flip_y = raw_info.origin == TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT; in wtp_get_config()
2571 wd->resolution = raw_info.res; in wtp_get_config()
2572 if (!wd->resolution) in wtp_get_config()
2573 wd->resolution = WTP_MANUAL_RESOLUTION; in wtp_get_config()
2583 wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data), in wtp_allocate()
2586 return -ENOMEM; in wtp_allocate()
2588 hidpp->private_data = wd; in wtp_allocate()
2596 struct wtp_data *wd = hidpp->private_data; in wtp_connect()
2599 if (!wd->x_size) { in wtp_connect()
2607 return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index, in wtp_connect()
2611 /* ------------------------------------------------------------------------- */
2613 /* ------------------------------------------------------------------------- */
2624 * forward button -> Super_R
2625 * backward button -> Super_L+'d' (press only)
2626 * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
2627 * 2nd time: left-click (press only)
2628 * NB: press-only means that when the button is pressed, the
2636 * - it never sends a keyboard key event
2637 * - for the three mouse button it sends:
2678 if (!hidpp->input) { in m560_raw_event()
2680 return -EINVAL; in m560_raw_event()
2694 * data[1] = device-id in m560_raw_event()
2696 * data[5] = 0xaf -> middle in m560_raw_event()
2697 * 0xb0 -> forward in m560_raw_event()
2698 * 0xae -> backward in m560_raw_event()
2699 * 0x00 -> release all in m560_raw_event()
2705 input_report_key(hidpp->input, BTN_MIDDLE, 1); in m560_raw_event()
2708 input_report_key(hidpp->input, BTN_FORWARD, 1); in m560_raw_event()
2711 input_report_key(hidpp->input, BTN_BACK, 1); in m560_raw_event()
2714 input_report_key(hidpp->input, BTN_BACK, 0); in m560_raw_event()
2715 input_report_key(hidpp->input, BTN_FORWARD, 0); in m560_raw_event()
2716 input_report_key(hidpp->input, BTN_MIDDLE, 0); in m560_raw_event()
2722 input_sync(hidpp->input); in m560_raw_event()
2736 input_report_key(hidpp->input, BTN_LEFT, in m560_raw_event()
2738 input_report_key(hidpp->input, BTN_RIGHT, in m560_raw_event()
2742 input_report_rel(hidpp->input, REL_HWHEEL, -1); in m560_raw_event()
2743 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, in m560_raw_event()
2744 -120); in m560_raw_event()
2746 input_report_rel(hidpp->input, REL_HWHEEL, 1); in m560_raw_event()
2747 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, in m560_raw_event()
2752 input_report_rel(hidpp->input, REL_X, v); in m560_raw_event()
2755 input_report_rel(hidpp->input, REL_Y, v); in m560_raw_event()
2759 hidpp_scroll_counter_handle_scroll(hidpp->input, in m560_raw_event()
2760 &hidpp->vertical_wheel_counter, v); in m560_raw_event()
2762 input_sync(hidpp->input); in m560_raw_event()
2771 __set_bit(EV_KEY, input_dev->evbit); in m560_populate_input()
2772 __set_bit(BTN_MIDDLE, input_dev->keybit); in m560_populate_input()
2773 __set_bit(BTN_RIGHT, input_dev->keybit); in m560_populate_input()
2774 __set_bit(BTN_LEFT, input_dev->keybit); in m560_populate_input()
2775 __set_bit(BTN_BACK, input_dev->keybit); in m560_populate_input()
2776 __set_bit(BTN_FORWARD, input_dev->keybit); in m560_populate_input()
2778 __set_bit(EV_REL, input_dev->evbit); in m560_populate_input()
2779 __set_bit(REL_X, input_dev->relbit); in m560_populate_input()
2780 __set_bit(REL_Y, input_dev->relbit); in m560_populate_input()
2781 __set_bit(REL_WHEEL, input_dev->relbit); in m560_populate_input()
2782 __set_bit(REL_HWHEEL, input_dev->relbit); in m560_populate_input()
2783 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit); in m560_populate_input()
2784 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit); in m560_populate_input()
2791 return -1; in m560_input_mapping()
2794 /* ------------------------------------------------------------------------- */
2796 /* ------------------------------------------------------------------------- */
2801 * tap-to-click but the setting is not remembered accross reset, annoying some
2814 struct k400_private_data *k400 = hidpp->private_data; in k400_disable_tap_to_click()
2819 if (!k400->feature_index) { in k400_disable_tap_to_click()
2822 &k400->feature_index, &feature_type); in k400_disable_tap_to_click()
2824 /* means that the device is not powered up */ in k400_disable_tap_to_click()
2828 ret = hidpp_touchpad_fw_items_set(hidpp, k400->feature_index, &items); in k400_disable_tap_to_click()
2840 k400 = devm_kzalloc(&hdev->dev, sizeof(struct k400_private_data), in k400_allocate()
2843 return -ENOMEM; in k400_allocate()
2845 hidpp->private_data = k400; in k400_allocate()
2860 /* ------------------------------------------------------------------------- */
2862 /* ------------------------------------------------------------------------- */
2878 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_ff_set_autocenter()
2883 hid_warn(hidpp->hid_dev, "Failed to autocenter device!\n"); in g920_ff_set_autocenter()
2885 data->slot_autocenter = response.fap.params[0]; in g920_ff_set_autocenter()
2901 &data->feature_index, &feature_type); in g920_get_config()
2906 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
2913 hid_err(hidpp->hid_dev, in g920_get_config()
2915 return -EPROTO; in g920_get_config()
2918 data->num_effects = response.fap.params[0] - HIDPP_FF_RESERVED_SLOTS; in g920_get_config()
2921 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
2926 hid_warn(hidpp->hid_dev, "Failed to reset all forces!\n"); in g920_get_config()
2928 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
2933 hid_warn(hidpp->hid_dev, in g920_get_config()
2936 data->range = ret ? in g920_get_config()
2940 ret = hidpp_send_fap_command_sync(hidpp, data->feature_index, in g920_get_config()
2945 hid_warn(hidpp->hid_dev, in g920_get_config()
2947 data->gain = ret ? in g920_get_config()
2955 /* -------------------------------------------------------------------------- */
2957 /* -------------------------------------------------------------------------- */
2964 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) in lg_dinovo_input_mapping()
2967 switch (usage->hid & HID_USAGE) { in lg_dinovo_input_mapping()
2975 /* -------------------------------------------------------------------------- */
2977 /* -------------------------------------------------------------------------- */
2990 if (!hidpp->input) in hidpp10_wheel_raw_event()
2991 return -EINVAL; in hidpp10_wheel_raw_event()
3002 input_report_rel(hidpp->input, REL_WHEEL, value); in hidpp10_wheel_raw_event()
3003 input_report_rel(hidpp->input, REL_WHEEL_HI_RES, value * 120); in hidpp10_wheel_raw_event()
3004 input_report_rel(hidpp->input, REL_HWHEEL, hvalue); in hidpp10_wheel_raw_event()
3005 input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, hvalue * 120); in hidpp10_wheel_raw_event()
3006 input_sync(hidpp->input); in hidpp10_wheel_raw_event()
3014 __set_bit(EV_REL, input_dev->evbit); in hidpp10_wheel_populate_input()
3015 __set_bit(REL_WHEEL, input_dev->relbit); in hidpp10_wheel_populate_input()
3016 __set_bit(REL_WHEEL_HI_RES, input_dev->relbit); in hidpp10_wheel_populate_input()
3017 __set_bit(REL_HWHEEL, input_dev->relbit); in hidpp10_wheel_populate_input()
3018 __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit); in hidpp10_wheel_populate_input()
3021 /* -------------------------------------------------------------------------- */
3023 /* -------------------------------------------------------------------------- */
3036 if (!hidpp->input) in hidpp10_extra_mouse_buttons_raw_event()
3037 return -EINVAL; in hidpp10_extra_mouse_buttons_raw_event()
3050 * the same usb-id show different behavior, so we handle both cases. in hidpp10_extra_mouse_buttons_raw_event()
3053 input_report_key(hidpp->input, BTN_MOUSE + i, in hidpp10_extra_mouse_buttons_raw_event()
3058 input_report_key(hidpp->input, BTN_MISC + i, in hidpp10_extra_mouse_buttons_raw_event()
3061 input_sync(hidpp->input); in hidpp10_extra_mouse_buttons_raw_event()
3068 /* BTN_MOUSE - BTN_MOUSE+7 are set already by the descriptor */ in hidpp10_extra_mouse_buttons_populate_input()
3069 __set_bit(BTN_0, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3070 __set_bit(BTN_1, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3071 __set_bit(BTN_2, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3072 __set_bit(BTN_3, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3073 __set_bit(BTN_4, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3074 __set_bit(BTN_5, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3075 __set_bit(BTN_6, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3076 __set_bit(BTN_7, input_dev->keybit); in hidpp10_extra_mouse_buttons_populate_input()
3079 /* -------------------------------------------------------------------------- */
3080 /* HID++1.0 kbds which only report 0x10xx consumer usages through sub-id 0x03 */
3081 /* -------------------------------------------------------------------------- */
3083 /* Find the consumer-page input report desc and change Maximums to 0x107f */
3102 size = *rsize - (consumer_rdesc - rdesc); in hidpp10_consumer_keys_report_fixup()
3138 hid_report_raw_event(hidpp->hid_dev, HID_INPUT_REPORT, in hidpp10_consumer_keys_raw_event()
3144 /* -------------------------------------------------------------------------- */
3145 /* High-resolution scroll wheels */
3146 /* -------------------------------------------------------------------------- */
3153 if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2121) { in hi_res_scroll_enable()
3157 } else if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2120) { in hi_res_scroll_enable()
3160 } else /* if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_1P0) */ { in hi_res_scroll_enable()
3170 hidpp->vertical_wheel_counter.wheel_multiplier = multiplier; in hi_res_scroll_enable()
3171 hid_dbg(hidpp->hid_dev, "wheel multiplier = %d\n", multiplier); in hi_res_scroll_enable()
3175 /* -------------------------------------------------------------------------- */
3177 /* -------------------------------------------------------------------------- */
3188 if (hdev->group == HID_GROUP_LOGITECH_27MHZ_DEVICE || in hidpp_report_fixup()
3189 (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS)) in hidpp_report_fixup()
3204 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_input_mapping()
3206 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 && in hidpp_input_mapping()
3207 field->application != HID_GD_MOUSE) in hidpp_input_mapping()
3210 if (hdev->product == DINOVO_MINI_PRODUCT_ID) in hidpp_input_mapping()
3226 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { in hidpp_input_mapped()
3227 if (usage->type == EV_ABS && (usage->code == ABS_X || in hidpp_input_mapped()
3228 usage->code == ABS_Y || usage->code == ABS_Z || in hidpp_input_mapped()
3229 usage->code == ABS_RZ)) { in hidpp_input_mapped()
3230 field->application = HID_GD_MULTIAXIS; in hidpp_input_mapped()
3241 hidpp->input = input; in hidpp_populate_input()
3243 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_populate_input()
3245 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) in hidpp_populate_input()
3248 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) in hidpp_populate_input()
3251 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) in hidpp_populate_input()
3259 struct input_dev *input = hidinput->input; in hidpp_input_configured()
3272 struct hidpp_report *question = hidpp->send_receive_buf; in hidpp_raw_hidpp_event()
3273 struct hidpp_report *answer = hidpp->send_receive_buf; in hidpp_raw_hidpp_event()
3281 if (unlikely(mutex_is_locked(&hidpp->send_mutex))) { in hidpp_raw_hidpp_event()
3289 hidpp->answer_available = true; in hidpp_raw_hidpp_event()
3290 wake_up(&hidpp->wait); in hidpp_raw_hidpp_event()
3293 * We return 1 to hid-core to avoid forwarding the in hidpp_raw_hidpp_event()
3302 atomic_set(&hidpp->connected, in hidpp_raw_hidpp_event()
3303 !(report->rap.params[0] & (1 << 6))); in hidpp_raw_hidpp_event()
3304 if (schedule_work(&hidpp->work) == 0) in hidpp_raw_hidpp_event()
3309 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { in hidpp_raw_hidpp_event()
3321 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) { in hidpp_raw_hidpp_event()
3327 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) { in hidpp_raw_hidpp_event()
3333 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) { in hidpp_raw_hidpp_event()
3339 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) { in hidpp_raw_hidpp_event()
3360 if (size != hidpp->very_long_report_length) { in hidpp_raw_event()
3390 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_raw_event()
3392 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) in hidpp_raw_event()
3410 counter = &hidpp->vertical_wheel_counter; in hidpp_event()
3412 * the input device set, or high-res scroll enabling may fail. In such in hidpp_event()
3416 if (!(hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL) || value == 0 in hidpp_event()
3417 || hidpp->input == NULL || counter->wheel_multiplier == 0) in hidpp_event()
3420 hidpp_scroll_counter_handle_scroll(hidpp->input, counter, value); in hidpp_event()
3428 struct power_supply_desc *desc = &hidpp->battery.desc; in hidpp_initialize_battery()
3430 struct hidpp_battery *battery; in hidpp_initialize_battery() local
3435 if (hidpp->battery.ps) in hidpp_initialize_battery()
3438 hidpp->battery.feature_index = 0xff; in hidpp_initialize_battery()
3439 hidpp->battery.solar_feature_index = 0xff; in hidpp_initialize_battery()
3440 hidpp->battery.voltage_feature_index = 0xff; in hidpp_initialize_battery()
3442 if (hidpp->protocol_major >= 2) { in hidpp_initialize_battery()
3443 if (hidpp->quirks & HIDPP_QUIRK_CLASS_K750) in hidpp_initialize_battery()
3453 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_BATTERY; in hidpp_initialize_battery()
3459 return -ENOENT; in hidpp_initialize_battery()
3460 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp_initialize_battery()
3462 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS; in hidpp_initialize_battery()
3464 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP10_BATTERY; in hidpp_initialize_battery()
3467 battery_props = devm_kmemdup(&hidpp->hid_dev->dev, in hidpp_initialize_battery()
3472 return -ENOMEM; in hidpp_initialize_battery()
3474 num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 3; in hidpp_initialize_battery()
3476 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE) in hidpp_initialize_battery()
3480 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS) in hidpp_initialize_battery()
3484 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE) in hidpp_initialize_battery()
3488 battery = &hidpp->battery; in hidpp_initialize_battery()
3490 n = atomic_inc_return(&battery_no) - 1; in hidpp_initialize_battery()
3491 desc->properties = battery_props; in hidpp_initialize_battery()
3492 desc->num_properties = num_battery_props; in hidpp_initialize_battery()
3493 desc->get_property = hidpp_battery_get_property; in hidpp_initialize_battery()
3494 sprintf(battery->name, "hidpp_battery_%ld", n); in hidpp_initialize_battery()
3495 desc->name = battery->name; in hidpp_initialize_battery()
3496 desc->type = POWER_SUPPLY_TYPE_BATTERY; in hidpp_initialize_battery()
3497 desc->use_for_apm = 0; in hidpp_initialize_battery()
3499 battery->ps = devm_power_supply_register(&hidpp->hid_dev->dev, in hidpp_initialize_battery()
3500 &battery->desc, in hidpp_initialize_battery()
3502 if (IS_ERR(battery->ps)) in hidpp_initialize_battery()
3503 return PTR_ERR(battery->ps); in hidpp_initialize_battery()
3505 power_supply_powers(battery->ps, &hidpp->hid_dev->dev); in hidpp_initialize_battery()
3515 if (hidpp->protocol_major < 2) in hidpp_overwrite_name()
3524 snprintf(hdev->name, sizeof(hdev->name), "%s", name); in hidpp_overwrite_name()
3546 struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev); in hidpp_allocate_input()
3553 input_dev->open = hidpp_input_open; in hidpp_allocate_input()
3554 input_dev->close = hidpp_input_close; in hidpp_allocate_input()
3556 input_dev->name = hidpp->name; in hidpp_allocate_input()
3557 input_dev->phys = hdev->phys; in hidpp_allocate_input()
3558 input_dev->uniq = hdev->uniq; in hidpp_allocate_input()
3559 input_dev->id.bustype = hdev->bus; in hidpp_allocate_input()
3560 input_dev->id.vendor = hdev->vendor; in hidpp_allocate_input()
3561 input_dev->id.product = hdev->product; in hidpp_allocate_input()
3562 input_dev->id.version = hdev->version; in hidpp_allocate_input()
3563 input_dev->dev.parent = &hdev->dev; in hidpp_allocate_input()
3570 struct hid_device *hdev = hidpp->hid_dev; in hidpp_connect_event()
3572 bool connected = atomic_read(&hidpp->connected); in hidpp_connect_event()
3577 if (hidpp->battery.ps) { in hidpp_connect_event()
3578 hidpp->battery.online = false; in hidpp_connect_event()
3579 hidpp->battery.status = POWER_SUPPLY_STATUS_UNKNOWN; in hidpp_connect_event()
3580 hidpp->battery.level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; in hidpp_connect_event()
3581 power_supply_changed(hidpp->battery.ps); in hidpp_connect_event()
3586 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { in hidpp_connect_event()
3590 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) { in hidpp_connect_event()
3594 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) { in hidpp_connect_event()
3600 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) { in hidpp_connect_event()
3606 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) { in hidpp_connect_event()
3612 if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) { in hidpp_connect_event()
3620 if (!hidpp->protocol_major) { in hidpp_connect_event()
3628 if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) { in hidpp_connect_event()
3631 devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL, in hidpp_connect_event()
3637 hidpp->name = devm_name; in hidpp_connect_event()
3643 /* forward current battery state */ in hidpp_connect_event()
3644 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) { in hidpp_connect_event()
3646 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE) in hidpp_connect_event()
3650 } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { in hidpp_connect_event()
3651 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE) in hidpp_connect_event()
3656 if (hidpp->battery.ps) in hidpp_connect_event()
3657 power_supply_changed(hidpp->battery.ps); in hidpp_connect_event()
3659 if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL) in hidpp_connect_event()
3662 if (!(hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) || hidpp->delayed_input) in hidpp_connect_event()
3678 hidpp->delayed_input = input; in hidpp_connect_event()
3697 re = &(hdev->report_enum[HID_OUTPUT_REPORT]); in hidpp_get_report_length()
3698 report = re->report_id_hash[id]; in hidpp_get_report_length()
3702 return report->field[0]->report_count + 1; in hidpp_get_report_length()
3737 hidpp->very_long_report_length = report_length; in hidpp_validate_device()
3753 report_list = &hdev->report_enum[HID_INPUT_REPORT].report_list; in hidpp_application_equals()
3755 return report && report->application == application; in hidpp_application_equals()
3767 hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL); in hidpp_probe()
3769 return -ENOMEM; in hidpp_probe()
3771 hidpp->hid_dev = hdev; in hidpp_probe()
3772 hidpp->name = hdev->name; in hidpp_probe()
3773 hidpp->quirks = id->driver_data; in hidpp_probe()
3785 hidpp->supported_reports = hidpp_validate_device(hdev); in hidpp_probe()
3787 if (!hidpp->supported_reports) { in hidpp_probe()
3789 devm_kfree(&hdev->dev, hidpp); in hidpp_probe()
3793 if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE) in hidpp_probe()
3794 hidpp->quirks |= HIDPP_QUIRK_UNIFYING; in hidpp_probe()
3796 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE && in hidpp_probe()
3798 hidpp->quirks |= HIDPP_QUIRK_HIDPP_WHEELS | in hidpp_probe()
3801 if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE && in hidpp_probe()
3803 hidpp->quirks |= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS; in hidpp_probe()
3806 hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP; in hidpp_probe()
3807 hidpp->quirks &= ~HIDPP_QUIRK_NO_HIDINPUT; in hidpp_probe()
3810 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { in hidpp_probe()
3814 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) { in hidpp_probe()
3820 INIT_WORK(&hidpp->work, delayed_work_cb); in hidpp_probe()
3821 mutex_init(&hidpp->send_mutex); in hidpp_probe()
3822 init_waitqueue_head(&hidpp->wait); in hidpp_probe()
3824 /* indicates we are handling the battery properties in the kernel */ in hidpp_probe()
3825 ret = sysfs_create_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_probe()
3828 hdev->name); in hidpp_probe()
3842 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n", in hidpp_probe()
3850 if (hidpp->quirks & HIDPP_QUIRK_UNIFYING) in hidpp_probe()
3854 atomic_set(&hidpp->connected, connected); in hidpp_probe()
3855 if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) { in hidpp_probe()
3857 ret = -ENODEV; in hidpp_probe()
3865 if (connected && hidpp->protocol_major >= 2) { in hidpp_probe()
3867 if (ret == -ENOENT) in hidpp_probe()
3868 hidpp->wireless_feature_index = 0; in hidpp_probe()
3873 if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { in hidpp_probe()
3877 } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { in hidpp_probe()
3890 if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) in hidpp_probe()
3900 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { in hidpp_probe()
3903 hid_warn(hidpp->hid_dev, in hidpp_probe()
3915 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_probe()
3916 cancel_work_sync(&hidpp->work); in hidpp_probe()
3917 mutex_destroy(&hidpp->send_mutex); in hidpp_probe()
3928 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_remove()
3931 cancel_work_sync(&hidpp->work); in hidpp_remove()
3932 mutex_destroy(&hidpp->send_mutex); in hidpp_remove()
3997 { /* Keyboard MX5000 (Bluetooth-receiver in HID proxy mode) */
4000 { /* Dinovo Edge (Bluetooth-receiver in HID proxy mode) */
4003 { /* Keyboard MX5500 (Bluetooth-receiver in HID proxy mode) */
4009 { /* Keyboard LX501 (Y-RR53) */
4012 { /* Keyboard MX3000 (Y-RAM74) */
4015 { /* Keyboard MX3200 (Y-RAV80) */
4066 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
4070 .name = "logitech-hidpp-device",