Lines Matching +full:long +full:- +full:press +full:- +full:ms
5 * Copyright (c) 2012-2013 Google (c)
6 * Copyright (c) 2013-2014 Red Hat Inc.
28 #include <linux/fixp-arith.h>
31 #include "hid-ids.h"
45 "Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
89 * is 0xFF for the receiver), and all messages (short or long) with a device
100 u8 params[HIDPP_REPORT_VERY_LONG_LENGTH - 4U];
106 u8 params[HIDPP_REPORT_VERY_LONG_LENGTH - 4U];
148 unsigned long quirks;
149 unsigned long capabilities;
182 switch (hidpp_report->report_id) { in __hidpp_send_report()
193 return -ENODEV; in __hidpp_send_report()
200 hidpp_report->device_index = 0xff; in __hidpp_send_report()
202 if (hidpp->quirks & HIDPP_QUIRK_FORCE_OUTPUT_REPORTS) { in __hidpp_send_report()
205 ret = hid_hw_raw_request(hdev, hidpp_report->report_id, in __hidpp_send_report()
210 return ret == fields_count ? 0 : -1; in __hidpp_send_report()
216 * - If ' something else' is positive, that means that an error has been raised
218 * - If ' something else' is negative, that means that we had a classic error
219 * (-ENOMEM, -EPIPE, etc...)
227 mutex_lock(&hidpp->send_mutex); in hidpp_send_message_sync()
229 hidpp->send_receive_buf = response; in hidpp_send_message_sync()
230 hidpp->answer_available = false; in hidpp_send_message_sync()
238 ret = __hidpp_send_report(hidpp->hid_dev, message); in hidpp_send_message_sync()
246 if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, in hidpp_send_message_sync()
250 ret = -ETIMEDOUT; in hidpp_send_message_sync()
253 if (response->report_id == REPORT_ID_HIDPP_SHORT && in hidpp_send_message_sync()
254 response->rap.sub_id == HIDPP_ERROR) { in hidpp_send_message_sync()
255 ret = response->rap.params[1]; in hidpp_send_message_sync()
260 if ((response->report_id == REPORT_ID_HIDPP_LONG || in hidpp_send_message_sync()
261 response->report_id == REPORT_ID_HIDPP_VERY_LONG) && in hidpp_send_message_sync()
262 response->fap.feature_index == HIDPP20_ERROR) { in hidpp_send_message_sync()
263 ret = response->fap.params[1]; in hidpp_send_message_sync()
269 mutex_unlock(&hidpp->send_mutex); in hidpp_send_message_sync()
281 if (param_count > sizeof(message->fap.params)) in hidpp_send_fap_command_sync()
282 return -EINVAL; in hidpp_send_fap_command_sync()
286 return -ENOMEM; in hidpp_send_fap_command_sync()
288 if (param_count > (HIDPP_REPORT_LONG_LENGTH - 4)) in hidpp_send_fap_command_sync()
289 message->report_id = REPORT_ID_HIDPP_VERY_LONG; in hidpp_send_fap_command_sync()
291 message->report_id = REPORT_ID_HIDPP_LONG; in hidpp_send_fap_command_sync()
292 message->fap.feature_index = feat_index; in hidpp_send_fap_command_sync()
293 message->fap.funcindex_clientid = funcindex_clientid; in hidpp_send_fap_command_sync()
294 memcpy(&message->fap.params, params, param_count); in hidpp_send_fap_command_sync()
310 max_count = HIDPP_REPORT_SHORT_LENGTH - 4; in hidpp_send_rap_command_sync()
313 max_count = HIDPP_REPORT_LONG_LENGTH - 4; in hidpp_send_rap_command_sync()
316 max_count = HIDPP_REPORT_VERY_LONG_LENGTH - 4; in hidpp_send_rap_command_sync()
319 return -EINVAL; in hidpp_send_rap_command_sync()
323 return -EINVAL; in hidpp_send_rap_command_sync()
327 return -ENOMEM; in hidpp_send_rap_command_sync()
328 message->report_id = report_id; in hidpp_send_rap_command_sync()
329 message->rap.sub_id = sub_id; in hidpp_send_rap_command_sync()
330 message->rap.reg_address = reg_address; in hidpp_send_rap_command_sync()
331 memcpy(&message->rap.params, params, param_count); in hidpp_send_rap_command_sync()
348 return (answer->fap.feature_index == question->fap.feature_index) && in hidpp_match_answer()
349 (answer->fap.funcindex_clientid == question->fap.funcindex_clientid); in hidpp_match_answer()
355 return ((answer->rap.sub_id == HIDPP_ERROR) || in hidpp_match_error()
356 (answer->fap.feature_index == HIDPP20_ERROR)) && in hidpp_match_error()
357 (answer->fap.funcindex_clientid == question->fap.feature_index) && in hidpp_match_error()
358 (answer->fap.params[0] == question->fap.funcindex_clientid); in hidpp_match_error()
363 return (report->report_id == REPORT_ID_HIDPP_SHORT) && in hidpp_report_is_connect_event()
364 (report->rap.sub_id == 0x41); in hidpp_report_is_connect_event()
394 /* -------------------------------------------------------------------------- */
396 /* -------------------------------------------------------------------------- */
504 hidpp->battery.level = in hidpp10_query_battery_status()
507 hidpp->battery.status = status; in hidpp10_query_battery_status()
509 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp10_query_battery_status()
556 hidpp->battery.capacity = response.rap.params[0]; in hidpp10_query_battery_mileage()
558 hidpp->battery.status = status; in hidpp10_query_battery_mileage()
560 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp10_query_battery_mileage()
572 if (report->report_id != REPORT_ID_HIDPP_SHORT) in hidpp10_battery_event()
575 switch (report->rap.sub_id) { in hidpp10_battery_event()
577 capacity = hidpp->battery.capacity; in hidpp10_battery_event()
578 level = hidpp10_battery_status_map_level(report->rawbytes[1]); in hidpp10_battery_event()
579 status = hidpp10_battery_status_map_status(report->rawbytes[2]); in hidpp10_battery_event()
582 capacity = report->rap.params[0]; in hidpp10_battery_event()
583 level = hidpp->battery.level; in hidpp10_battery_event()
584 status = hidpp10_battery_mileage_map_status(report->rawbytes[3]); in hidpp10_battery_event()
590 changed = capacity != hidpp->battery.capacity || in hidpp10_battery_event()
591 level != hidpp->battery.level || in hidpp10_battery_event()
592 status != hidpp->battery.status; in hidpp10_battery_event()
595 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp10_battery_event()
599 hidpp->battery.level = level; in hidpp10_battery_event()
600 hidpp->battery.status = status; in hidpp10_battery_event()
601 if (hidpp->battery.ps) in hidpp10_battery_event()
602 power_supply_changed(hidpp->battery.ps); in hidpp10_battery_event()
669 struct hid_device *hdev = hidpp->hid_dev; in hidpp_unifying_init()
678 snprintf(hdev->uniq, sizeof(hdev->uniq), "%04x-%4phD", in hidpp_unifying_init()
679 hdev->product, &serial); in hidpp_unifying_init()
680 dbg_hid("HID++ Unifying: Got serial: %s\n", hdev->uniq); in hidpp_unifying_init()
684 return -EIO; in hidpp_unifying_init()
686 snprintf(hdev->name, sizeof(hdev->name), "%s", name); in hidpp_unifying_init()
693 /* -------------------------------------------------------------------------- */
695 /* -------------------------------------------------------------------------- */
718 return -ENOENT; in hidpp_root_get_feature()
740 hidpp->protocol_major = 1; in hidpp_root_get_protocol_version()
741 hidpp->protocol_minor = 0; in hidpp_root_get_protocol_version()
747 return -EIO; in hidpp_root_get_protocol_version()
750 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_root_get_protocol_version()
752 return -EPROTO; in hidpp_root_get_protocol_version()
758 hid_err(hidpp->hid_dev, "%s: ping mismatch 0x%02x != 0x%02x\n", in hidpp_root_get_protocol_version()
760 return -EPROTO; in hidpp_root_get_protocol_version()
763 hidpp->protocol_major = response.rap.params[0]; in hidpp_root_get_protocol_version()
764 hidpp->protocol_minor = response.rap.params[1]; in hidpp_root_get_protocol_version()
775 hid_dbg(hidpp->hid_dev, "HID++ %u.%u device connected.\n", in hidpp_is_connected()
776 hidpp->protocol_major, hidpp->protocol_minor); in hidpp_is_connected()
780 /* -------------------------------------------------------------------------- */
782 /* -------------------------------------------------------------------------- */
800 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_devicenametype_get_count()
802 return -EPROTO; in hidpp_devicenametype_get_count()
824 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_devicenametype_get_device_name()
826 return -EPROTO; in hidpp_devicenametype_get_device_name()
833 count = HIDPP_REPORT_VERY_LONG_LENGTH - 4; in hidpp_devicenametype_get_device_name()
836 count = HIDPP_REPORT_LONG_LENGTH - 4; in hidpp_devicenametype_get_device_name()
839 count = HIDPP_REPORT_SHORT_LENGTH - 4; in hidpp_devicenametype_get_device_name()
842 return -EPROTO; in hidpp_devicenametype_get_device_name()
880 __name_length - index); in hidpp_get_device_name()
894 /* -------------------------------------------------------------------------- */
896 /* -------------------------------------------------------------------------- */
983 return -EIO; in hidpp20_batterylevel_get_battery_capacity()
985 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_batterylevel_get_battery_capacity()
987 return -EPROTO; in hidpp20_batterylevel_get_battery_capacity()
1011 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp20_batterylevel_get_battery_info()
1013 return -EPROTO; in hidpp20_batterylevel_get_battery_info()
1022 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS; in hidpp20_batterylevel_get_battery_info()
1024 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp20_batterylevel_get_battery_info()
1035 if (hidpp->battery.feature_index == 0xff) { in hidpp20_query_battery_info()
1038 &hidpp->battery.feature_index, in hidpp20_query_battery_info()
1045 hidpp->battery.feature_index, in hidpp20_query_battery_info()
1052 hidpp->battery.feature_index); in hidpp20_query_battery_info()
1056 hidpp->battery.status = status; in hidpp20_query_battery_info()
1057 hidpp->battery.capacity = capacity; in hidpp20_query_battery_info()
1058 hidpp->battery.level = level; in hidpp20_query_battery_info()
1060 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp20_query_battery_info()
1073 if (report->fap.feature_index != hidpp->battery.feature_index || in hidpp20_battery_event()
1074 report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST) in hidpp20_battery_event()
1077 status = hidpp20_batterylevel_map_status_capacity(report->fap.params, in hidpp20_battery_event()
1083 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || in hidpp20_battery_event()
1086 changed = capacity != hidpp->battery.capacity || in hidpp20_battery_event()
1087 level != hidpp->battery.level || in hidpp20_battery_event()
1088 status != hidpp->battery.status; in hidpp20_battery_event()
1091 hidpp->battery.level = level; in hidpp20_battery_event()
1092 hidpp->battery.capacity = capacity; in hidpp20_battery_event()
1093 hidpp->battery.status = status; in hidpp20_battery_event()
1094 if (hidpp->battery.ps) in hidpp20_battery_event()
1095 power_supply_changed(hidpp->battery.ps); in hidpp20_battery_event()
1121 val->intval = hidpp->battery.status; in hidpp_battery_get_property()
1124 val->intval = hidpp->battery.capacity; in hidpp_battery_get_property()
1127 val->intval = hidpp->battery.level; in hidpp_battery_get_property()
1130 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in hidpp_battery_get_property()
1133 val->intval = hidpp->battery.online; in hidpp_battery_get_property()
1136 if (!strncmp(hidpp->name, "Logitech ", 9)) in hidpp_battery_get_property()
1137 val->strval = hidpp->name + 9; in hidpp_battery_get_property()
1139 val->strval = hidpp->name; in hidpp_battery_get_property()
1142 val->strval = "Logitech"; in hidpp_battery_get_property()
1145 val->strval = hidpp->hid_dev->uniq; in hidpp_battery_get_property()
1148 ret = -EINVAL; in hidpp_battery_get_property()
1155 /* -------------------------------------------------------------------------- */
1157 /* -------------------------------------------------------------------------- */
1174 if (hidpp->battery.feature_index == 0xff) { in hidpp_solar_request_battery_event()
1177 &hidpp->battery.solar_feature_index, in hidpp_solar_request_battery_event()
1184 hidpp->battery.solar_feature_index, in hidpp_solar_request_battery_event()
1188 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_solar_request_battery_event()
1190 return -EPROTO; in hidpp_solar_request_battery_event()
1195 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp_solar_request_battery_event()
1207 function = report->fap.funcindex_clientid; in hidpp_solar_battery_event()
1210 if (report->fap.feature_index != hidpp->battery.solar_feature_index || in hidpp_solar_battery_event()
1216 capacity = report->fap.params[0]; in hidpp_solar_battery_event()
1220 lux = (report->fap.params[1] << 8) | report->fap.params[2]; in hidpp_solar_battery_event()
1228 if (capacity < hidpp->battery.capacity) in hidpp_solar_battery_event()
1238 hidpp->battery.online = true; in hidpp_solar_battery_event()
1239 if (capacity != hidpp->battery.capacity || in hidpp_solar_battery_event()
1240 status != hidpp->battery.status) { in hidpp_solar_battery_event()
1241 hidpp->battery.capacity = capacity; in hidpp_solar_battery_event()
1242 hidpp->battery.status = status; in hidpp_solar_battery_event()
1243 if (hidpp->battery.ps) in hidpp_solar_battery_event()
1244 power_supply_changed(hidpp->battery.ps); in hidpp_solar_battery_event()
1250 /* -------------------------------------------------------------------------- */
1252 /* -------------------------------------------------------------------------- */
1266 * send a set state command to the device by reading the current items->state
1278 CMD_TOUCHPAD_FW_ITEMS_SET, &items->state, 1, &response); in hidpp_touchpad_fw_items_set()
1281 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_touchpad_fw_items_set()
1283 return -EPROTO; in hidpp_touchpad_fw_items_set()
1288 items->presence = params[0]; in hidpp_touchpad_fw_items_set()
1289 items->desired_state = params[1]; in hidpp_touchpad_fw_items_set()
1290 items->state = params[2]; in hidpp_touchpad_fw_items_set()
1291 items->persistent = params[3]; in hidpp_touchpad_fw_items_set()
1296 /* -------------------------------------------------------------------------- */
1298 /* -------------------------------------------------------------------------- */
1351 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_touchpad_get_raw_info()
1353 return -EPROTO; in hidpp_touchpad_get_raw_info()
1358 raw_info->x_size = get_unaligned_be16(¶ms[0]); in hidpp_touchpad_get_raw_info()
1359 raw_info->y_size = get_unaligned_be16(¶ms[2]); in hidpp_touchpad_get_raw_info()
1360 raw_info->z_range = params[4]; in hidpp_touchpad_get_raw_info()
1361 raw_info->area_range = params[5]; in hidpp_touchpad_get_raw_info()
1362 raw_info->maxcontacts = params[7]; in hidpp_touchpad_get_raw_info()
1363 raw_info->origin = params[8]; in hidpp_touchpad_get_raw_info()
1365 raw_info->res = get_unaligned_be16(¶ms[13]) * 2 / 51; in hidpp_touchpad_get_raw_info()
1378 * bit 0 - enable raw in hidpp_touchpad_set_raw_report_state()
1379 * bit 1 - 16bit Z, no area in hidpp_touchpad_set_raw_report_state()
1380 * bit 2 - enhanced sensitivity in hidpp_touchpad_set_raw_report_state()
1381 * bit 3 - width, height (4 bits each) instead of area in hidpp_touchpad_set_raw_report_state()
1382 * bit 4 - send raw + gestures (degrades smoothness) in hidpp_touchpad_set_raw_report_state()
1383 * remaining bits - reserved in hidpp_touchpad_set_raw_report_state()
1397 finger->x = x_m << 6 | data[1]; in hidpp_touchpad_touch_event()
1398 finger->y = y_m << 6 | data[3]; in hidpp_touchpad_touch_event()
1400 finger->contact_type = data[0] >> 6; in hidpp_touchpad_touch_event()
1401 finger->contact_status = data[2] >> 6; in hidpp_touchpad_touch_event()
1403 finger->z = data[4]; in hidpp_touchpad_touch_event()
1404 finger->area = data[5]; in hidpp_touchpad_touch_event()
1405 finger->finger_id = data[6] >> 4; in hidpp_touchpad_touch_event()
1412 raw_xy->end_of_frame = data[8] & 0x01; in hidpp_touchpad_raw_xy_event()
1413 raw_xy->spurious_flag = (data[8] >> 1) & 0x01; in hidpp_touchpad_raw_xy_event()
1414 raw_xy->finger_count = data[15] & 0x0f; in hidpp_touchpad_raw_xy_event()
1415 raw_xy->button = (data[8] >> 2) & 0x01; in hidpp_touchpad_raw_xy_event()
1417 if (raw_xy->finger_count) { in hidpp_touchpad_raw_xy_event()
1418 hidpp_touchpad_touch_event(&data[2], &raw_xy->fingers[0]); in hidpp_touchpad_raw_xy_event()
1419 hidpp_touchpad_touch_event(&data[9], &raw_xy->fingers[1]); in hidpp_touchpad_raw_xy_event()
1423 /* -------------------------------------------------------------------------- */
1425 /* -------------------------------------------------------------------------- */
1456 #define HIDPP_FF_EFFECTID_NONE -1
1457 #define HIDPP_FF_EFFECTID_AUTOCENTER -2
1496 -1
1503 -1
1525 for (i = 0; i < data->num_effects; i++) in hidpp_ff_find_effect()
1526 if (data->effect_ids[i] == effect_id) in hidpp_ff_find_effect()
1535 struct hidpp_ff_private_data *data = wd->data; in hidpp_ff_work_handler()
1541 switch (wd->effect_id) { in hidpp_ff_work_handler()
1543 wd->params[0] = data->slot_autocenter; in hidpp_ff_work_handler()
1550 wd->params[0] = hidpp_ff_find_effect(data, wd->effect_id); in hidpp_ff_work_handler()
1555 ret = hidpp_send_fap_command_sync(data->hidpp, data->feature_index, in hidpp_ff_work_handler()
1556 wd->command, wd->params, wd->size, &response); in hidpp_ff_work_handler()
1559 hid_err(data->hidpp->hid_dev, "Failed to send command to device!\n"); in hidpp_ff_work_handler()
1564 switch (wd->command) { in hidpp_ff_work_handler()
1567 if (slot > 0 && slot <= data->num_effects) { in hidpp_ff_work_handler()
1568 if (wd->effect_id >= 0) in hidpp_ff_work_handler()
1570 data->effect_ids[slot-1] = wd->effect_id; in hidpp_ff_work_handler()
1571 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) in hidpp_ff_work_handler()
1573 data->slot_autocenter = slot; in hidpp_ff_work_handler()
1577 if (wd->effect_id >= 0) in hidpp_ff_work_handler()
1579 data->effect_ids[wd->params[0]-1] = -1; in hidpp_ff_work_handler()
1580 else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) in hidpp_ff_work_handler()
1582 data->slot_autocenter = 0; in hidpp_ff_work_handler()
1585 data->gain = (wd->params[0] << 8) + wd->params[1]; in hidpp_ff_work_handler()
1588 data->range = (wd->params[0] << 8) + wd->params[1]; in hidpp_ff_work_handler()
1596 atomic_dec(&data->workqueue_size); in hidpp_ff_work_handler()
1606 return -ENOMEM; in hidpp_ff_queue_work()
1608 INIT_WORK(&wd->work, hidpp_ff_work_handler); in hidpp_ff_queue_work()
1610 wd->data = data; in hidpp_ff_queue_work()
1611 wd->effect_id = effect_id; in hidpp_ff_queue_work()
1612 wd->command = command; in hidpp_ff_queue_work()
1613 wd->size = size; in hidpp_ff_queue_work()
1614 memcpy(wd->params, params, size); in hidpp_ff_queue_work()
1616 atomic_inc(&data->workqueue_size); in hidpp_ff_queue_work()
1617 queue_work(data->wq, &wd->work); in hidpp_ff_queue_work()
1620 s = atomic_read(&data->workqueue_size); in hidpp_ff_queue_work()
1622 …hid_warn(data->hidpp->hid_dev, "Force feedback command queue contains %d commands, causing substan… in hidpp_ff_queue_work()
1629 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_upload_effect()
1635 params[2] = effect->replay.length >> 8; in hidpp_ff_upload_effect()
1636 params[3] = effect->replay.length & 255; in hidpp_ff_upload_effect()
1637 params[4] = effect->replay.delay >> 8; in hidpp_ff_upload_effect()
1638 params[5] = effect->replay.delay & 255; in hidpp_ff_upload_effect()
1640 switch (effect->type) { in hidpp_ff_upload_effect()
1642 force = (effect->u.constant.level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
1646 params[8] = effect->u.constant.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
1647 params[9] = effect->u.constant.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
1648 params[10] = effect->u.constant.envelope.attack_length & 255; in hidpp_ff_upload_effect()
1649 params[11] = effect->u.constant.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
1650 params[12] = effect->u.constant.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
1651 params[13] = effect->u.constant.envelope.fade_length & 255; in hidpp_ff_upload_effect()
1654 effect->u.constant.level, in hidpp_ff_upload_effect()
1655 effect->direction, force); in hidpp_ff_upload_effect()
1656 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n", in hidpp_ff_upload_effect()
1657 effect->u.constant.envelope.attack_level, in hidpp_ff_upload_effect()
1658 effect->u.constant.envelope.attack_length, in hidpp_ff_upload_effect()
1659 effect->u.constant.envelope.fade_level, in hidpp_ff_upload_effect()
1660 effect->u.constant.envelope.fade_length); in hidpp_ff_upload_effect()
1664 switch (effect->u.periodic.waveform) { in hidpp_ff_upload_effect()
1681 …hid_err(data->hidpp->hid_dev, "Unexpected periodic waveform type %i!\n", effect->u.periodic.wavefo… in hidpp_ff_upload_effect()
1682 return -EINVAL; in hidpp_ff_upload_effect()
1684 force = (effect->u.periodic.magnitude * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
1685 params[6] = effect->u.periodic.magnitude >> 8; in hidpp_ff_upload_effect()
1686 params[7] = effect->u.periodic.magnitude & 255; in hidpp_ff_upload_effect()
1687 params[8] = effect->u.periodic.offset >> 8; in hidpp_ff_upload_effect()
1688 params[9] = effect->u.periodic.offset & 255; in hidpp_ff_upload_effect()
1689 params[10] = effect->u.periodic.period >> 8; in hidpp_ff_upload_effect()
1690 params[11] = effect->u.periodic.period & 255; in hidpp_ff_upload_effect()
1691 params[12] = effect->u.periodic.phase >> 8; in hidpp_ff_upload_effect()
1692 params[13] = effect->u.periodic.phase & 255; in hidpp_ff_upload_effect()
1693 params[14] = effect->u.periodic.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
1694 params[15] = effect->u.periodic.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
1695 params[16] = effect->u.periodic.envelope.attack_length & 255; in hidpp_ff_upload_effect()
1696 params[17] = effect->u.periodic.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
1697 params[18] = effect->u.periodic.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
1698 params[19] = effect->u.periodic.envelope.fade_length & 255; in hidpp_ff_upload_effect()
1700 dbg_hid("Uploading periodic force mag=%d/dir=%d, offset=%d, period=%d ms, phase=%d\n", in hidpp_ff_upload_effect()
1701 effect->u.periodic.magnitude, effect->direction, in hidpp_ff_upload_effect()
1702 effect->u.periodic.offset, in hidpp_ff_upload_effect()
1703 effect->u.periodic.period, in hidpp_ff_upload_effect()
1704 effect->u.periodic.phase); in hidpp_ff_upload_effect()
1705 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n", in hidpp_ff_upload_effect()
1706 effect->u.periodic.envelope.attack_level, in hidpp_ff_upload_effect()
1707 effect->u.periodic.envelope.attack_length, in hidpp_ff_upload_effect()
1708 effect->u.periodic.envelope.fade_level, in hidpp_ff_upload_effect()
1709 effect->u.periodic.envelope.fade_length); in hidpp_ff_upload_effect()
1714 force = (effect->u.ramp.start_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
1717 force = (effect->u.ramp.end_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15; in hidpp_ff_upload_effect()
1720 params[10] = effect->u.ramp.envelope.attack_level >> 7; in hidpp_ff_upload_effect()
1721 params[11] = effect->u.ramp.envelope.attack_length >> 8; in hidpp_ff_upload_effect()
1722 params[12] = effect->u.ramp.envelope.attack_length & 255; in hidpp_ff_upload_effect()
1723 params[13] = effect->u.ramp.envelope.fade_level >> 7; in hidpp_ff_upload_effect()
1724 params[14] = effect->u.ramp.envelope.fade_length >> 8; in hidpp_ff_upload_effect()
1725 params[15] = effect->u.ramp.envelope.fade_length & 255; in hidpp_ff_upload_effect()
1727 dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n", in hidpp_ff_upload_effect()
1728 effect->u.ramp.start_level, in hidpp_ff_upload_effect()
1729 effect->u.ramp.end_level, in hidpp_ff_upload_effect()
1730 effect->direction, force); in hidpp_ff_upload_effect()
1731 dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n", in hidpp_ff_upload_effect()
1732 effect->u.ramp.envelope.attack_level, in hidpp_ff_upload_effect()
1733 effect->u.ramp.envelope.attack_length, in hidpp_ff_upload_effect()
1734 effect->u.ramp.envelope.fade_level, in hidpp_ff_upload_effect()
1735 effect->u.ramp.envelope.fade_length); in hidpp_ff_upload_effect()
1741 params[1] = HIDPP_FF_CONDITION_CMDS[effect->type - FF_SPRING]; in hidpp_ff_upload_effect()
1742 params[6] = effect->u.condition[0].left_saturation >> 9; in hidpp_ff_upload_effect()
1743 params[7] = (effect->u.condition[0].left_saturation >> 1) & 255; in hidpp_ff_upload_effect()
1744 params[8] = effect->u.condition[0].left_coeff >> 8; in hidpp_ff_upload_effect()
1745 params[9] = effect->u.condition[0].left_coeff & 255; in hidpp_ff_upload_effect()
1746 params[10] = effect->u.condition[0].deadband >> 9; in hidpp_ff_upload_effect()
1747 params[11] = (effect->u.condition[0].deadband >> 1) & 255; in hidpp_ff_upload_effect()
1748 params[12] = effect->u.condition[0].center >> 8; in hidpp_ff_upload_effect()
1749 params[13] = effect->u.condition[0].center & 255; in hidpp_ff_upload_effect()
1750 params[14] = effect->u.condition[0].right_coeff >> 8; in hidpp_ff_upload_effect()
1751 params[15] = effect->u.condition[0].right_coeff & 255; in hidpp_ff_upload_effect()
1752 params[16] = effect->u.condition[0].right_saturation >> 9; in hidpp_ff_upload_effect()
1753 params[17] = (effect->u.condition[0].right_saturation >> 1) & 255; in hidpp_ff_upload_effect()
1756 HIDPP_FF_CONDITION_NAMES[effect->type - FF_SPRING], in hidpp_ff_upload_effect()
1757 effect->u.condition[0].left_coeff, in hidpp_ff_upload_effect()
1758 effect->u.condition[0].left_saturation, in hidpp_ff_upload_effect()
1759 effect->u.condition[0].right_coeff, in hidpp_ff_upload_effect()
1760 effect->u.condition[0].right_saturation); in hidpp_ff_upload_effect()
1762 effect->u.condition[0].deadband, in hidpp_ff_upload_effect()
1763 effect->u.condition[0].center); in hidpp_ff_upload_effect()
1766 hid_err(data->hidpp->hid_dev, "Unexpected force type %i!\n", effect->type); in hidpp_ff_upload_effect()
1767 return -EINVAL; in hidpp_ff_upload_effect()
1770 return hidpp_ff_queue_work(data, effect->id, HIDPP_FF_DOWNLOAD_EFFECT, params, size); in hidpp_ff_upload_effect()
1775 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_playback()
1787 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_erase_effect()
1797 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_set_autocenter()
1819 struct hidpp_ff_private_data *data = dev->ff->private; in hidpp_ff_set_gain()
1835 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_range_show()
1836 struct input_dev *idev = hidinput->input; in hidpp_ff_range_show()
1837 struct hidpp_ff_private_data *data = idev->ff->private; in hidpp_ff_range_show()
1839 return scnprintf(buf, PAGE_SIZE, "%u\n", data->range); in hidpp_ff_range_show()
1845 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_range_store()
1846 struct input_dev *idev = hidinput->input; in hidpp_ff_range_store()
1847 struct hidpp_ff_private_data *data = idev->ff->private; in hidpp_ff_range_store()
1856 hidpp_ff_queue_work(data, -1, HIDPP_FF_SET_APERTURE, params, ARRAY_SIZE(params)); in hidpp_ff_range_store()
1865 struct hidpp_ff_private_data *data = ff->private; in hidpp_ff_destroy()
1867 kfree(data->effect_ids); in hidpp_ff_destroy()
1872 struct hid_device *hid = hidpp->hid_dev; in hidpp_ff_init()
1875 const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor); in hidpp_ff_init()
1876 const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice); in hidpp_ff_init()
1883 if (list_empty(&hid->inputs)) { in hidpp_ff_init()
1885 return -ENODEV; in hidpp_ff_init()
1887 hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_init()
1888 dev = hidinput->input; in hidpp_ff_init()
1892 return -EINVAL; in hidpp_ff_init()
1900 set_bit(hiddpp_ff_effects[j], dev->ffbit); in hidpp_ff_init()
1903 set_bit(hiddpp_ff_effects_v2[j], dev->ffbit); in hidpp_ff_init()
1911 hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", in hidpp_ff_init()
1913 return -EPROTO; in hidpp_ff_init()
1916 num_slots = response.fap.params[0] - HIDPP_FF_RESERVED_SLOTS; in hidpp_ff_init()
1927 return -ENOMEM; in hidpp_ff_init()
1928 data->effect_ids = kcalloc(num_slots, sizeof(int), GFP_KERNEL); in hidpp_ff_init()
1929 if (!data->effect_ids) { in hidpp_ff_init()
1931 return -ENOMEM; in hidpp_ff_init()
1933 data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue"); in hidpp_ff_init()
1934 if (!data->wq) { in hidpp_ff_init()
1935 kfree(data->effect_ids); in hidpp_ff_init()
1937 return -ENOMEM; in hidpp_ff_init()
1940 data->hidpp = hidpp; in hidpp_ff_init()
1941 data->feature_index = feature_index; in hidpp_ff_init()
1942 data->version = version; in hidpp_ff_init()
1943 data->slot_autocenter = 0; in hidpp_ff_init()
1944 data->num_effects = num_slots; in hidpp_ff_init()
1946 data->effect_ids[j] = -1; in hidpp_ff_init()
1948 ff = dev->ff; in hidpp_ff_init()
1949 ff->private = data; in hidpp_ff_init()
1951 ff->upload = hidpp_ff_upload_effect; in hidpp_ff_init()
1952 ff->erase = hidpp_ff_erase_effect; in hidpp_ff_init()
1953 ff->playback = hidpp_ff_playback; in hidpp_ff_init()
1954 ff->set_gain = hidpp_ff_set_gain; in hidpp_ff_init()
1955 ff->set_autocenter = hidpp_ff_set_autocenter; in hidpp_ff_init()
1956 ff->destroy = hidpp_ff_destroy; in hidpp_ff_init()
1967 hid_warn(hidpp->hid_dev, "Failed to read range from device!\n"); in hidpp_ff_init()
1968 data->range = error ? 900 : get_unaligned_be16(&response.fap.params[0]); in hidpp_ff_init()
1971 error = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range); in hidpp_ff_init()
1973 hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d!\n", error); in hidpp_ff_init()
1979 hid_warn(hidpp->hid_dev, "Failed to read gain values from device!\n"); in hidpp_ff_init()
1980 data->gain = error ? 0xffff : get_unaligned_be16(&response.fap.params[0]); in hidpp_ff_init()
1984 atomic_set(&data->workqueue_size, 0); in hidpp_ff_init()
1997 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); in hidpp_ff_deinit()
1998 struct input_dev *dev = hidinput->input; in hidpp_ff_deinit()
2003 return -EINVAL; in hidpp_ff_deinit()
2007 data = dev->ff->private; in hidpp_ff_deinit()
2010 return -EINVAL; in hidpp_ff_deinit()
2013 destroy_workqueue(data->wq); in hidpp_ff_deinit()
2014 device_remove_file(&hid->dev, &dev_attr_range); in hidpp_ff_deinit()
2026 /* -------------------------------------------------------------------------- */
2028 /* -------------------------------------------------------------------------- */
2045 unsigned long **bit, int *max) in wtp_input_mapping()
2047 return -1; in wtp_input_mapping()
2053 struct wtp_data *wd = hidpp->private_data; in wtp_populate_input()
2055 __set_bit(EV_ABS, input_dev->evbit); in wtp_populate_input()
2056 __set_bit(EV_KEY, input_dev->evbit); in wtp_populate_input()
2057 __clear_bit(EV_REL, input_dev->evbit); in wtp_populate_input()
2058 __clear_bit(EV_LED, input_dev->evbit); in wtp_populate_input()
2060 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0); in wtp_populate_input()
2061 input_abs_set_res(input_dev, ABS_MT_POSITION_X, wd->resolution); in wtp_populate_input()
2062 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0); in wtp_populate_input()
2063 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, wd->resolution); in wtp_populate_input()
2070 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) in wtp_populate_input()
2073 __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); in wtp_populate_input()
2075 input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER | in wtp_populate_input()
2078 wd->input = input_dev; in wtp_populate_input()
2086 if (!touch_report->finger_id || touch_report->contact_type) in wtp_touch_event()
2090 slot = input_mt_get_slot_by_key(wd->input, touch_report->finger_id); in wtp_touch_event()
2092 input_mt_slot(wd->input, slot); in wtp_touch_event()
2093 input_mt_report_slot_state(wd->input, MT_TOOL_FINGER, in wtp_touch_event()
2094 touch_report->contact_status); in wtp_touch_event()
2095 if (touch_report->contact_status) { in wtp_touch_event()
2096 input_event(wd->input, EV_ABS, ABS_MT_POSITION_X, in wtp_touch_event()
2097 touch_report->x); in wtp_touch_event()
2098 input_event(wd->input, EV_ABS, ABS_MT_POSITION_Y, in wtp_touch_event()
2099 wd->flip_y ? wd->y_size - touch_report->y : in wtp_touch_event()
2100 touch_report->y); in wtp_touch_event()
2101 input_event(wd->input, EV_ABS, ABS_MT_PRESSURE, in wtp_touch_event()
2102 touch_report->area); in wtp_touch_event()
2109 struct wtp_data *wd = hidpp->private_data; in wtp_send_raw_xy_event()
2113 wtp_touch_event(wd, &(raw->fingers[i])); in wtp_send_raw_xy_event()
2115 if (raw->end_of_frame && in wtp_send_raw_xy_event()
2116 !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS)) in wtp_send_raw_xy_event()
2117 input_event(wd->input, EV_KEY, BTN_LEFT, raw->button); in wtp_send_raw_xy_event()
2119 if (raw->end_of_frame || raw->finger_count <= 2) { in wtp_send_raw_xy_event()
2120 input_mt_sync_frame(wd->input); in wtp_send_raw_xy_event()
2121 input_sync(wd->input); in wtp_send_raw_xy_event()
2127 struct wtp_data *wd = hidpp->private_data; in wtp_mouse_raw_xy_event()
2153 .finger_count = wd->maxcontacts, in wtp_mouse_raw_xy_event()
2167 struct wtp_data *wd = hidpp->private_data; in wtp_raw_event()
2171 if (!wd || !wd->input) in wtp_raw_event()
2181 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) { in wtp_raw_event()
2182 input_event(wd->input, EV_KEY, BTN_LEFT, in wtp_raw_event()
2184 input_event(wd->input, EV_KEY, BTN_RIGHT, in wtp_raw_event()
2186 input_sync(wd->input); in wtp_raw_event()
2195 if ((report->fap.feature_index != wd->mt_feature_index) || in wtp_raw_event()
2196 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY)) in wtp_raw_event()
2209 struct wtp_data *wd = hidpp->private_data; in wtp_get_config()
2215 &wd->mt_feature_index, &feature_type); in wtp_get_config()
2220 ret = hidpp_touchpad_get_raw_info(hidpp, wd->mt_feature_index, in wtp_get_config()
2225 wd->x_size = raw_info.x_size; in wtp_get_config()
2226 wd->y_size = raw_info.y_size; in wtp_get_config()
2227 wd->maxcontacts = raw_info.maxcontacts; in wtp_get_config()
2228 wd->flip_y = raw_info.origin == TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT; in wtp_get_config()
2229 wd->resolution = raw_info.res; in wtp_get_config()
2230 if (!wd->resolution) in wtp_get_config()
2231 wd->resolution = WTP_MANUAL_RESOLUTION; in wtp_get_config()
2241 wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data), in wtp_allocate()
2244 return -ENOMEM; in wtp_allocate()
2246 hidpp->private_data = wd; in wtp_allocate()
2254 struct wtp_data *wd = hidpp->private_data; in wtp_connect()
2257 if (!wd->x_size) { in wtp_connect()
2265 return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index, in wtp_connect()
2269 /* ------------------------------------------------------------------------- */
2271 /* ------------------------------------------------------------------------- */
2280 * is different from the odd press and the even press.
2282 * forward button -> Super_R
2283 * backward button -> Super_L+'d' (press only)
2284 * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
2285 * 2nd time: left-click (press only)
2286 * NB: press-only means that when the button is pressed, the
2294 * - it never sends a keyboard key event
2295 * - for the three mouse button it sends:
2296 * middle button press 11<xx>0a 3500af00...
2297 * side 1 button (forward) press 11<xx>0a 3500b000...
2298 * side 2 button (backward) press 11<xx>0a 3500ae00...
2340 d = devm_kzalloc(&hdev->dev, sizeof(struct m560_private_data), in m560_allocate()
2343 return -ENOMEM; in m560_allocate()
2345 hidpp->private_data = d; in m560_allocate()
2353 struct m560_private_data *mydata = hidpp->private_data; in m560_raw_event()
2356 if (!mydata || !mydata->input) { in m560_raw_event()
2358 return -EINVAL; in m560_raw_event()
2372 * data[1] = device-id in m560_raw_event()
2374 * data[5] = 0xaf -> middle in m560_raw_event()
2375 * 0xb0 -> forward in m560_raw_event()
2376 * 0xae -> backward in m560_raw_event()
2377 * 0x00 -> release all in m560_raw_event()
2383 input_report_key(mydata->input, BTN_MIDDLE, 1); in m560_raw_event()
2386 input_report_key(mydata->input, BTN_FORWARD, 1); in m560_raw_event()
2389 input_report_key(mydata->input, BTN_BACK, 1); in m560_raw_event()
2392 input_report_key(mydata->input, BTN_BACK, 0); in m560_raw_event()
2393 input_report_key(mydata->input, BTN_FORWARD, 0); in m560_raw_event()
2394 input_report_key(mydata->input, BTN_MIDDLE, 0); in m560_raw_event()
2400 input_sync(mydata->input); in m560_raw_event()
2414 input_report_key(mydata->input, BTN_LEFT, in m560_raw_event()
2416 input_report_key(mydata->input, BTN_RIGHT, in m560_raw_event()
2420 input_report_rel(mydata->input, REL_HWHEEL, -1); in m560_raw_event()
2422 input_report_rel(mydata->input, REL_HWHEEL, 1); in m560_raw_event()
2425 input_report_rel(mydata->input, REL_X, v); in m560_raw_event()
2428 input_report_rel(mydata->input, REL_Y, v); in m560_raw_event()
2431 input_report_rel(mydata->input, REL_WHEEL, v); in m560_raw_event()
2433 input_sync(mydata->input); in m560_raw_event()
2442 struct m560_private_data *mydata = hidpp->private_data; in m560_populate_input()
2444 mydata->input = input_dev; in m560_populate_input()
2446 __set_bit(EV_KEY, mydata->input->evbit); in m560_populate_input()
2447 __set_bit(BTN_MIDDLE, mydata->input->keybit); in m560_populate_input()
2448 __set_bit(BTN_RIGHT, mydata->input->keybit); in m560_populate_input()
2449 __set_bit(BTN_LEFT, mydata->input->keybit); in m560_populate_input()
2450 __set_bit(BTN_BACK, mydata->input->keybit); in m560_populate_input()
2451 __set_bit(BTN_FORWARD, mydata->input->keybit); in m560_populate_input()
2453 __set_bit(EV_REL, mydata->input->evbit); in m560_populate_input()
2454 __set_bit(REL_X, mydata->input->relbit); in m560_populate_input()
2455 __set_bit(REL_Y, mydata->input->relbit); in m560_populate_input()
2456 __set_bit(REL_WHEEL, mydata->input->relbit); in m560_populate_input()
2457 __set_bit(REL_HWHEEL, mydata->input->relbit); in m560_populate_input()
2462 unsigned long **bit, int *max) in m560_input_mapping()
2464 return -1; in m560_input_mapping()
2467 /* ------------------------------------------------------------------------- */
2469 /* ------------------------------------------------------------------------- */
2474 * tap-to-click but the setting is not remembered accross reset, annoying some
2487 struct k400_private_data *k400 = hidpp->private_data; in k400_disable_tap_to_click()
2492 if (!k400->feature_index) { in k400_disable_tap_to_click()
2495 &k400->feature_index, &feature_type); in k400_disable_tap_to_click()
2501 ret = hidpp_touchpad_fw_items_set(hidpp, k400->feature_index, &items); in k400_disable_tap_to_click()
2513 k400 = devm_kzalloc(&hdev->dev, sizeof(struct k400_private_data), in k400_allocate()
2516 return -ENOMEM; in k400_allocate()
2518 hidpp->private_data = k400; in k400_allocate()
2533 /* ------------------------------------------------------------------------- */
2535 /* ------------------------------------------------------------------------- */
2553 hid_warn(hidpp->hid_dev, "Unable to initialize force feedback support, errno %d\n", in g920_get_config()
2559 /* -------------------------------------------------------------------------- */
2561 /* -------------------------------------------------------------------------- */
2565 unsigned long **bit, int *max) in hidpp_input_mapping()
2569 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_input_mapping()
2571 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 && in hidpp_input_mapping()
2572 field->application != HID_GD_MOUSE) in hidpp_input_mapping()
2580 unsigned long **bit, int *max) in hidpp_input_mapped()
2585 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { in hidpp_input_mapped()
2586 if (usage->type == EV_ABS && (usage->code == ABS_X || in hidpp_input_mapped()
2587 usage->code == ABS_Y || usage->code == ABS_Z || in hidpp_input_mapped()
2588 usage->code == ABS_RZ)) { in hidpp_input_mapped()
2589 field->application = HID_GD_MULTIAXIS; in hidpp_input_mapped()
2600 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_populate_input()
2602 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) in hidpp_populate_input()
2610 struct input_dev *input = hidinput->input; in hidpp_input_configured()
2620 struct hidpp_report *question = hidpp->send_receive_buf; in hidpp_raw_hidpp_event()
2621 struct hidpp_report *answer = hidpp->send_receive_buf; in hidpp_raw_hidpp_event()
2629 if (unlikely(mutex_is_locked(&hidpp->send_mutex))) { in hidpp_raw_hidpp_event()
2637 hidpp->answer_available = true; in hidpp_raw_hidpp_event()
2638 wake_up(&hidpp->wait); in hidpp_raw_hidpp_event()
2641 * We return 1 to hid-core to avoid forwarding the in hidpp_raw_hidpp_event()
2650 atomic_set(&hidpp->connected, in hidpp_raw_hidpp_event()
2651 !(report->rap.params[0] & (1 << 6))); in hidpp_raw_hidpp_event()
2652 if (schedule_work(&hidpp->work) == 0) in hidpp_raw_hidpp_event()
2657 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { in hidpp_raw_hidpp_event()
2666 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) { in hidpp_raw_hidpp_event()
2714 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) in hidpp_raw_event()
2716 else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) in hidpp_raw_event()
2726 struct power_supply_desc *desc = &hidpp->battery.desc; in hidpp_initialize_battery()
2730 unsigned long n; in hidpp_initialize_battery()
2733 if (hidpp->battery.ps) in hidpp_initialize_battery()
2736 hidpp->battery.feature_index = 0xff; in hidpp_initialize_battery()
2737 hidpp->battery.solar_feature_index = 0xff; in hidpp_initialize_battery()
2739 if (hidpp->protocol_major >= 2) { in hidpp_initialize_battery()
2740 if (hidpp->quirks & HIDPP_QUIRK_CLASS_K750) in hidpp_initialize_battery()
2747 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_BATTERY; in hidpp_initialize_battery()
2753 return -ENOENT; in hidpp_initialize_battery()
2754 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE; in hidpp_initialize_battery()
2756 hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS; in hidpp_initialize_battery()
2758 hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP10_BATTERY; in hidpp_initialize_battery()
2761 battery_props = devm_kmemdup(&hidpp->hid_dev->dev, in hidpp_initialize_battery()
2766 return -ENOMEM; in hidpp_initialize_battery()
2768 num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 2; in hidpp_initialize_battery()
2770 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE) in hidpp_initialize_battery()
2774 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS) in hidpp_initialize_battery()
2778 battery = &hidpp->battery; in hidpp_initialize_battery()
2780 n = atomic_inc_return(&battery_no) - 1; in hidpp_initialize_battery()
2781 desc->properties = battery_props; in hidpp_initialize_battery()
2782 desc->num_properties = num_battery_props; in hidpp_initialize_battery()
2783 desc->get_property = hidpp_battery_get_property; in hidpp_initialize_battery()
2784 sprintf(battery->name, "hidpp_battery_%ld", n); in hidpp_initialize_battery()
2785 desc->name = battery->name; in hidpp_initialize_battery()
2786 desc->type = POWER_SUPPLY_TYPE_BATTERY; in hidpp_initialize_battery()
2787 desc->use_for_apm = 0; in hidpp_initialize_battery()
2789 battery->ps = devm_power_supply_register(&hidpp->hid_dev->dev, in hidpp_initialize_battery()
2790 &battery->desc, in hidpp_initialize_battery()
2792 if (IS_ERR(battery->ps)) in hidpp_initialize_battery()
2793 return PTR_ERR(battery->ps); in hidpp_initialize_battery()
2795 power_supply_powers(battery->ps, &hidpp->hid_dev->dev); in hidpp_initialize_battery()
2805 if (hidpp->protocol_major < 2) in hidpp_overwrite_name()
2814 snprintf(hdev->name, sizeof(hdev->name), "%s", name); in hidpp_overwrite_name()
2836 struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev); in hidpp_allocate_input()
2843 input_dev->open = hidpp_input_open; in hidpp_allocate_input()
2844 input_dev->close = hidpp_input_close; in hidpp_allocate_input()
2846 input_dev->name = hidpp->name; in hidpp_allocate_input()
2847 input_dev->phys = hdev->phys; in hidpp_allocate_input()
2848 input_dev->uniq = hdev->uniq; in hidpp_allocate_input()
2849 input_dev->id.bustype = hdev->bus; in hidpp_allocate_input()
2850 input_dev->id.vendor = hdev->vendor; in hidpp_allocate_input()
2851 input_dev->id.product = hdev->product; in hidpp_allocate_input()
2852 input_dev->id.version = hdev->version; in hidpp_allocate_input()
2853 input_dev->dev.parent = &hdev->dev; in hidpp_allocate_input()
2860 struct hid_device *hdev = hidpp->hid_dev; in hidpp_connect_event()
2862 bool connected = atomic_read(&hidpp->connected); in hidpp_connect_event()
2867 if (hidpp->battery.ps) { in hidpp_connect_event()
2868 hidpp->battery.online = false; in hidpp_connect_event()
2869 hidpp->battery.status = POWER_SUPPLY_STATUS_UNKNOWN; in hidpp_connect_event()
2870 hidpp->battery.level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; in hidpp_connect_event()
2871 power_supply_changed(hidpp->battery.ps); in hidpp_connect_event()
2876 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { in hidpp_connect_event()
2880 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) { in hidpp_connect_event()
2884 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) { in hidpp_connect_event()
2892 if (!hidpp->protocol_major) { in hidpp_connect_event()
2899 hidpp->protocol_major, hidpp->protocol_minor); in hidpp_connect_event()
2902 if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) { in hidpp_connect_event()
2910 devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s", name); in hidpp_connect_event()
2915 hidpp->name = devm_name; in hidpp_connect_event()
2921 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) { in hidpp_connect_event()
2923 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE) in hidpp_connect_event()
2927 } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { in hidpp_connect_event()
2930 if (hidpp->battery.ps) in hidpp_connect_event()
2931 power_supply_changed(hidpp->battery.ps); in hidpp_connect_event()
2933 if (!(hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) || hidpp->delayed_input) in hidpp_connect_event()
2949 hidpp->delayed_input = input; in hidpp_connect_event()
2970 hidpp = devm_kzalloc(&hdev->dev, sizeof(struct hidpp_device), in hidpp_probe()
2973 return -ENOMEM; in hidpp_probe()
2975 hidpp->hid_dev = hdev; in hidpp_probe()
2976 hidpp->name = hdev->name; in hidpp_probe()
2979 hidpp->quirks = id->driver_data; in hidpp_probe()
2981 if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE) in hidpp_probe()
2982 hidpp->quirks |= HIDPP_QUIRK_UNIFYING; in hidpp_probe()
2985 hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP; in hidpp_probe()
2986 hidpp->quirks &= ~HIDPP_QUIRK_NO_HIDINPUT; in hidpp_probe()
2989 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { in hidpp_probe()
2993 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) { in hidpp_probe()
2997 } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) { in hidpp_probe()
3003 INIT_WORK(&hidpp->work, delayed_work_cb); in hidpp_probe()
3004 mutex_init(&hidpp->send_mutex); in hidpp_probe()
3005 init_waitqueue_head(&hidpp->wait); in hidpp_probe()
3008 ret = sysfs_create_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_probe()
3011 hdev->name); in hidpp_probe()
3019 if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) in hidpp_probe()
3022 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { in hidpp_probe()
3030 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n", in hidpp_probe()
3041 if (hidpp->quirks & HIDPP_QUIRK_UNIFYING) in hidpp_probe()
3045 atomic_set(&hidpp->connected, connected); in hidpp_probe()
3046 if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) { in hidpp_probe()
3048 ret = -ENODEV; in hidpp_probe()
3054 hidpp->protocol_major, hidpp->protocol_minor); in hidpp_probe()
3059 if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { in hidpp_probe()
3063 } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { in hidpp_probe()
3072 if (!(hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { in hidpp_probe()
3089 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { in hidpp_probe()
3095 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_probe()
3096 cancel_work_sync(&hidpp->work); in hidpp_probe()
3097 mutex_destroy(&hidpp->send_mutex); in hidpp_probe()
3107 sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); in hidpp_remove()
3109 if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { in hidpp_remove()
3114 cancel_work_sync(&hidpp->work); in hidpp_remove()
3115 mutex_destroy(&hidpp->send_mutex); in hidpp_remove()
3156 .name = "logitech-hidpp-device",