^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * HIDPP protocol for Logitech receivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2011 Logitech (c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2012-2013 Google (c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2013-2014 Red Hat Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/sched/clock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/kfifo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/fixp-arith.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "usbhid/usbhid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) MODULE_AUTHOR("Nestor Lopez Casado <nlopezcasad@logitech.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static bool disable_raw_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) module_param(disable_raw_mode, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) MODULE_PARM_DESC(disable_raw_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) "Disable Raw mode reporting for touchpads and keep firmware gestures.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static bool disable_tap_to_click;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) module_param(disable_tap_to_click, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) MODULE_PARM_DESC(disable_tap_to_click,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) "Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define REPORT_ID_HIDPP_SHORT 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define REPORT_ID_HIDPP_LONG 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define REPORT_ID_HIDPP_VERY_LONG 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define HIDPP_REPORT_SHORT_LENGTH 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define HIDPP_REPORT_LONG_LENGTH 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define HIDPP_REPORT_VERY_LONG_MAX_LENGTH 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define HIDPP_REPORT_SHORT_SUPPORTED BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define HIDPP_REPORT_LONG_SUPPORTED BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define HIDPP_REPORT_VERY_LONG_SUPPORTED BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define HIDPP_SUB_ID_ROLLER 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define HIDPP_SUB_ID_MOUSE_EXTRA_BTNS 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define HIDPP_QUIRK_CLASS_WTP BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define HIDPP_QUIRK_CLASS_M560 BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define HIDPP_QUIRK_CLASS_K400 BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define HIDPP_QUIRK_CLASS_G920 BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define HIDPP_QUIRK_CLASS_K750 BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* bits 2..20 are reserved for classes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define HIDPP_QUIRK_NO_HIDINPUT BIT(23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define HIDPP_QUIRK_FORCE_OUTPUT_REPORTS BIT(24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define HIDPP_QUIRK_UNIFYING BIT(25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define HIDPP_QUIRK_HI_RES_SCROLL_1P0 BIT(26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define HIDPP_QUIRK_HI_RES_SCROLL_X2120 BIT(27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define HIDPP_QUIRK_HI_RES_SCROLL_X2121 BIT(28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define HIDPP_QUIRK_HIDPP_WHEELS BIT(29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS BIT(30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS BIT(31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* These are just aliases for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define HIDPP_QUIRK_KBD_SCROLL_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define HIDPP_QUIRK_KBD_ZOOM_WHEEL HIDPP_QUIRK_HIDPP_WHEELS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* Convenience constant to check for any high-res support. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define HIDPP_QUIRK_HI_RES_SCROLL (HIDPP_QUIRK_HI_RES_SCROLL_1P0 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) HIDPP_QUIRK_HI_RES_SCROLL_X2120 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) HIDPP_QUIRK_HI_RES_SCROLL_X2121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define HIDPP_QUIRK_DELAYED_INIT HIDPP_QUIRK_NO_HIDINPUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define HIDPP_CAPABILITY_HIDPP10_BATTERY BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define HIDPP_CAPABILITY_HIDPP20_BATTERY BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define HIDPP_CAPABILITY_BATTERY_MILEAGE BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define HIDPP_CAPABILITY_BATTERY_VOLTAGE BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define lg_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * There are two hidpp protocols in use, the first version hidpp10 is known
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * as register access protocol or RAP, the second version hidpp20 is known as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * feature access protocol or FAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * Most older devices (including the Unifying usb receiver) use the RAP protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * where as most newer devices use the FAP protocol. Both protocols are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * compatible with the underlying transport, which could be usb, Unifiying, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * bluetooth. The message lengths are defined by the hid vendor specific report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * descriptor for the HIDPP_SHORT report type (total message lenth 7 bytes) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * the HIDPP_LONG report type (total message length 20 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * The RAP protocol uses both report types, whereas the FAP only uses HIDPP_LONG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * messages. The Unifying receiver itself responds to RAP messages (device index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * is 0xFF for the receiver), and all messages (short or long) with a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * index between 1 and 6 are passed untouched to the corresponding paired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * Unifying device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * The paired device can be RAP or FAP, it will receive the message untouched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * from the Unifiying receiver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct fap {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u8 feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) u8 funcindex_clientid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct rap {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) u8 sub_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u8 reg_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) u8 params[HIDPP_REPORT_VERY_LONG_MAX_LENGTH - 4U];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct hidpp_report {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) u8 report_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) u8 device_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct fap fap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct rap rap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) u8 rawbytes[sizeof(struct fap)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct hidpp_battery {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u8 feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) u8 solar_feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) u8 voltage_feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct power_supply_desc desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct power_supply *ps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) char name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int voltage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) int charge_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) bool online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * struct hidpp_scroll_counter - Utility class for processing high-resolution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * scroll events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * @dev: the input device for which events should be reported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * @wheel_multiplier: the scalar multiplier to be applied to each wheel event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * @remainder: counts the number of high-resolution units moved since the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * low-resolution event (REL_WHEEL or REL_HWHEEL) was sent. Should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * only be used by class methods.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * @direction: direction of last movement (1 or -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * @last_time: last event time, used to reset remainder after inactivity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct hidpp_scroll_counter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int wheel_multiplier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int remainder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) unsigned long long last_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct hidpp_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct hid_device *hid_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct mutex send_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) void *send_receive_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) char *name; /* will never be NULL and should not be freed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) wait_queue_head_t wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int very_long_report_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) bool answer_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) u8 protocol_major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u8 protocol_minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) void *private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct kfifo delayed_work_fifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) atomic_t connected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct input_dev *delayed_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) unsigned long quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) unsigned long capabilities;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) u8 supported_reports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct hidpp_battery battery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct hidpp_scroll_counter vertical_wheel_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) u8 wireless_feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* HID++ 1.0 error codes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define HIDPP_ERROR 0x8f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define HIDPP_ERROR_SUCCESS 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #define HIDPP_ERROR_INVALID_SUBID 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #define HIDPP_ERROR_INVALID_ADRESS 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) #define HIDPP_ERROR_INVALID_VALUE 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define HIDPP_ERROR_CONNECT_FAIL 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #define HIDPP_ERROR_TOO_MANY_DEVICES 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) #define HIDPP_ERROR_ALREADY_EXISTS 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define HIDPP_ERROR_BUSY 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #define HIDPP_ERROR_UNKNOWN_DEVICE 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #define HIDPP_ERROR_RESOURCE_ERROR 0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define HIDPP_ERROR_REQUEST_UNAVAILABLE 0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define HIDPP_ERROR_INVALID_PARAM_VALUE 0x0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #define HIDPP_ERROR_WRONG_PIN_CODE 0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* HID++ 2.0 error codes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #define HIDPP20_ERROR 0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static void hidpp_connect_event(struct hidpp_device *hidpp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static int __hidpp_send_report(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct hidpp_report *hidpp_report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int fields_count, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) switch (hidpp_report->report_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) case REPORT_ID_HIDPP_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) fields_count = HIDPP_REPORT_SHORT_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) case REPORT_ID_HIDPP_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) fields_count = HIDPP_REPORT_LONG_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) case REPORT_ID_HIDPP_VERY_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) fields_count = hidpp->very_long_report_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * set the device_index as the receiver, it will be overwritten by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * hid_hw_request if needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) hidpp_report->device_index = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (hidpp->quirks & HIDPP_QUIRK_FORCE_OUTPUT_REPORTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ret = hid_hw_output_report(hdev, (u8 *)hidpp_report, fields_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) ret = hid_hw_raw_request(hdev, hidpp_report->report_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) (u8 *)hidpp_report, fields_count, HID_OUTPUT_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return ret == fields_count ? 0 : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * hidpp_send_message_sync() returns 0 in case of success, and something else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * in case of a failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * - If ' something else' is positive, that means that an error has been raised
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * by the protocol itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * - If ' something else' is negative, that means that we had a classic error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * (-ENOMEM, -EPIPE, etc...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int hidpp_send_message_sync(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct hidpp_report *message,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct hidpp_report *response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) mutex_lock(&hidpp->send_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) hidpp->send_receive_buf = response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) hidpp->answer_available = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * So that we can later validate the answer when it arrives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * in hidpp_raw_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) *response = *message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ret = __hidpp_send_report(hidpp->hid_dev, message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) dbg_hid("__hidpp_send_report returned err: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) memset(response, 0, sizeof(struct hidpp_report));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (!wait_event_timeout(hidpp->wait, hidpp->answer_available,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 5*HZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) dbg_hid("%s:timeout waiting for response\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) memset(response, 0, sizeof(struct hidpp_report));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) ret = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (response->report_id == REPORT_ID_HIDPP_SHORT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) response->rap.sub_id == HIDPP_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ret = response->rap.params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) dbg_hid("%s:got hidpp error %02X\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if ((response->report_id == REPORT_ID_HIDPP_LONG ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) response->report_id == REPORT_ID_HIDPP_VERY_LONG) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) response->fap.feature_index == HIDPP20_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) ret = response->fap.params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) mutex_unlock(&hidpp->send_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) u8 feat_index, u8 funcindex_clientid, u8 *params, int param_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct hidpp_report *response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct hidpp_report *message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (param_count > sizeof(message->fap.params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (!message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (param_count > (HIDPP_REPORT_LONG_LENGTH - 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) message->report_id = REPORT_ID_HIDPP_VERY_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) message->report_id = REPORT_ID_HIDPP_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) message->fap.feature_index = feat_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) message->fap.funcindex_clientid = funcindex_clientid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) memcpy(&message->fap.params, params, param_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ret = hidpp_send_message_sync(hidpp, message, response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) kfree(message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) u8 report_id, u8 sub_id, u8 reg_address, u8 *params, int param_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct hidpp_report *response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) struct hidpp_report *message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) int ret, max_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /* Send as long report if short reports are not supported. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (report_id == REPORT_ID_HIDPP_SHORT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) !(hidpp_dev->supported_reports & HIDPP_REPORT_SHORT_SUPPORTED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) report_id = REPORT_ID_HIDPP_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) switch (report_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) case REPORT_ID_HIDPP_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) max_count = HIDPP_REPORT_SHORT_LENGTH - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) case REPORT_ID_HIDPP_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) max_count = HIDPP_REPORT_LONG_LENGTH - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) case REPORT_ID_HIDPP_VERY_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) max_count = hidpp_dev->very_long_report_length - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (param_count > max_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (!message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) message->report_id = report_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) message->rap.sub_id = sub_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) message->rap.reg_address = reg_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) memcpy(&message->rap.params, params, param_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) ret = hidpp_send_message_sync(hidpp_dev, message, response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) kfree(message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static void delayed_work_cb(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct hidpp_device *hidpp = container_of(work, struct hidpp_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) hidpp_connect_event(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static inline bool hidpp_match_answer(struct hidpp_report *question,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct hidpp_report *answer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return (answer->fap.feature_index == question->fap.feature_index) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) (answer->fap.funcindex_clientid == question->fap.funcindex_clientid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static inline bool hidpp_match_error(struct hidpp_report *question,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct hidpp_report *answer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return ((answer->rap.sub_id == HIDPP_ERROR) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) (answer->fap.feature_index == HIDPP20_ERROR)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) (answer->fap.funcindex_clientid == question->fap.feature_index) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) (answer->fap.params[0] == question->fap.funcindex_clientid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static inline bool hidpp_report_is_connect_event(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct hidpp_report *report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return (hidpp->wireless_feature_index &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) (report->fap.feature_index == hidpp->wireless_feature_index)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) ((report->report_id == REPORT_ID_HIDPP_SHORT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) (report->rap.sub_id == 0x41));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * hidpp_prefix_name() prefixes the current given name with "Logitech ".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static void hidpp_prefix_name(char **name, int name_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) #define PREFIX_LENGTH 9 /* "Logitech " */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) int new_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) char *new_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (name_length > PREFIX_LENGTH &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) strncmp(*name, "Logitech ", PREFIX_LENGTH) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* The prefix has is already in the name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) new_length = PREFIX_LENGTH + name_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) new_name = kzalloc(new_length, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (!new_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) snprintf(new_name, new_length, "Logitech %s", *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) kfree(*name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) *name = new_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * hidpp_scroll_counter_handle_scroll() - Send high- and low-resolution scroll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * events given a high-resolution wheel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) * movement.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * @counter: a hid_scroll_counter struct describing the wheel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * @hi_res_value: the movement of the wheel, in the mouse's high-resolution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * units.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * Given a high-resolution movement, this function converts the movement into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * fractions of 120 and emits high-resolution scroll events for the input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * device. It also uses the multiplier from &struct hid_scroll_counter to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * emit low-resolution scroll events when appropriate for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * backwards-compatibility with userspace input libraries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static void hidpp_scroll_counter_handle_scroll(struct input_dev *input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) struct hidpp_scroll_counter *counter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) int hi_res_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) int low_res_value, remainder, direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) unsigned long long now, previous;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) hi_res_value = hi_res_value * 120/counter->wheel_multiplier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) input_report_rel(input_dev, REL_WHEEL_HI_RES, hi_res_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) remainder = counter->remainder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) direction = hi_res_value > 0 ? 1 : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) now = sched_clock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) previous = counter->last_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) counter->last_time = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * Reset the remainder after a period of inactivity or when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * direction changes. This prevents the REL_WHEEL emulation point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * from sliding for devices that don't always provide the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * number of movements per detent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (now - previous > 1000000000 || direction != counter->direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) remainder = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) counter->direction = direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) remainder += hi_res_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /* Some wheels will rest 7/8ths of a detent from the previous detent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * after slow movement, so we want the threshold for low-res events to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * be in the middle between two detents (e.g. after 4/8ths) as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * opposed to on the detents themselves (8/8ths).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (abs(remainder) >= 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) /* Add (or subtract) 1 because we want to trigger when the wheel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * is half-way to the next detent (i.e. scroll 1 detent after a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * 1/2 detent movement, 2 detents after a 1 1/2 detent movement,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * etc.).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) low_res_value = remainder / 120;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (low_res_value == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) low_res_value = (hi_res_value > 0 ? 1 : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) input_report_rel(input_dev, REL_WHEEL, low_res_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) remainder -= low_res_value * 120;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) counter->remainder = remainder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /* HIDP++ 1.0 commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) #define HIDPP_SET_REGISTER 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) #define HIDPP_GET_REGISTER 0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) #define HIDPP_SET_LONG_REGISTER 0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) #define HIDPP_GET_LONG_REGISTER 0x83
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * hidpp10_set_register - Modify a HID++ 1.0 register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * @hidpp_dev: the device to set the register on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * @register_address: the address of the register to modify.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * @byte: the byte of the register to modify. Should be less than 3.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) * @mask: mask of the bits to modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) * @value: new values for the bits in mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) * Return: 0 if successful, otherwise a negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) static int hidpp10_set_register(struct hidpp_device *hidpp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) u8 register_address, u8 byte, u8 mask, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) u8 params[3] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) ret = hidpp_send_rap_command_sync(hidpp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) REPORT_ID_HIDPP_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) HIDPP_GET_REGISTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) register_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) NULL, 0, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) memcpy(params, response.rap.params, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) params[byte] &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) params[byte] |= value & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) return hidpp_send_rap_command_sync(hidpp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) REPORT_ID_HIDPP_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) HIDPP_SET_REGISTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) register_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) params, 3, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) #define HIDPP_REG_ENABLE_REPORTS 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) #define HIDPP_ENABLE_CONSUMER_REPORT BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) #define HIDPP_ENABLE_WHEEL_REPORT BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) #define HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) #define HIDPP_ENABLE_BAT_REPORT BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) #define HIDPP_ENABLE_HWHEEL_REPORT BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static int hidpp10_enable_battery_reporting(struct hidpp_device *hidpp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) return hidpp10_set_register(hidpp_dev, HIDPP_REG_ENABLE_REPORTS, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) HIDPP_ENABLE_BAT_REPORT, HIDPP_ENABLE_BAT_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) #define HIDPP_REG_FEATURES 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) #define HIDPP_ENABLE_SPECIAL_BUTTON_FUNC BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) #define HIDPP_ENABLE_FAST_SCROLL BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /* On HID++ 1.0 devices, high-res scroll was called "scrolling acceleration". */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static int hidpp10_enable_scrolling_acceleration(struct hidpp_device *hidpp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return hidpp10_set_register(hidpp_dev, HIDPP_REG_FEATURES, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) HIDPP_ENABLE_FAST_SCROLL, HIDPP_ENABLE_FAST_SCROLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) #define HIDPP_REG_BATTERY_STATUS 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) static int hidpp10_battery_status_map_level(u8 param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) int level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) case 1 ... 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) case 3 ... 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) case 5 ... 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) level = POWER_SUPPLY_CAPACITY_LEVEL_HIGH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) static int hidpp10_battery_status_map_status(u8 param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) switch (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) case 0x00:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) /* discharging (in use) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) status = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) case 0x21: /* (standard) charging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) case 0x24: /* fast charging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) case 0x25: /* slow charging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) status = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) case 0x26: /* topping charge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) case 0x22: /* charge complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) status = POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) case 0x20: /* unknown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) status = POWER_SUPPLY_STATUS_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) * 0x01...0x1F = reserved (not charging)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) * 0x23 = charging error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) * 0x27..0xff = reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) status = POWER_SUPPLY_STATUS_NOT_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static int hidpp10_query_battery_status(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) int ret, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) ret = hidpp_send_rap_command_sync(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) REPORT_ID_HIDPP_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) HIDPP_GET_REGISTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) HIDPP_REG_BATTERY_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) NULL, 0, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) hidpp->battery.level =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) hidpp10_battery_status_map_level(response.rap.params[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) status = hidpp10_battery_status_map_status(response.rap.params[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) hidpp->battery.status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) /* the capacity is only available when discharging or full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) status == POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) #define HIDPP_REG_BATTERY_MILEAGE 0x0D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) static int hidpp10_battery_mileage_map_status(u8 param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) switch (param >> 6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) case 0x00:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /* discharging (in use) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) status = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) case 0x01: /* charging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) status = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) case 0x02: /* charge complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) status = POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) * 0x03 = charging error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) status = POWER_SUPPLY_STATUS_NOT_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) static int hidpp10_query_battery_mileage(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) int ret, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) ret = hidpp_send_rap_command_sync(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) REPORT_ID_HIDPP_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) HIDPP_GET_REGISTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) HIDPP_REG_BATTERY_MILEAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) NULL, 0, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) hidpp->battery.capacity = response.rap.params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) status = hidpp10_battery_mileage_map_status(response.rap.params[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) hidpp->battery.status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) /* the capacity is only available when discharging or full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) status == POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) static int hidpp10_battery_event(struct hidpp_device *hidpp, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) struct hidpp_report *report = (struct hidpp_report *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) int status, capacity, level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) bool changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (report->report_id != REPORT_ID_HIDPP_SHORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) switch (report->rap.sub_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) case HIDPP_REG_BATTERY_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) capacity = hidpp->battery.capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) level = hidpp10_battery_status_map_level(report->rawbytes[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) status = hidpp10_battery_status_map_status(report->rawbytes[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) case HIDPP_REG_BATTERY_MILEAGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) capacity = report->rap.params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) level = hidpp->battery.level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) status = hidpp10_battery_mileage_map_status(report->rawbytes[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) changed = capacity != hidpp->battery.capacity ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) level != hidpp->battery.level ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) status != hidpp->battery.status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) /* the capacity is only available when discharging or full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) status == POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) hidpp->battery.level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) hidpp->battery.status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if (hidpp->battery.ps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) power_supply_changed(hidpp->battery.ps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) #define HIDPP_REG_PAIRING_INFORMATION 0xB5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) #define HIDPP_EXTENDED_PAIRING 0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) #define HIDPP_DEVICE_NAME 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) static char *hidpp_unifying_get_name(struct hidpp_device *hidpp_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) u8 params[1] = { HIDPP_DEVICE_NAME };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) ret = hidpp_send_rap_command_sync(hidpp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) REPORT_ID_HIDPP_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) HIDPP_GET_LONG_REGISTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) HIDPP_REG_PAIRING_INFORMATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) params, 1, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) len = response.rap.params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (2 + len > sizeof(response.rap.params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) if (len < 4) /* logitech devices are usually at least Xddd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) name = kzalloc(len + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) memcpy(name, &response.rap.params[2], len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) /* include the terminating '\0' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) hidpp_prefix_name(&name, len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) return name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) static int hidpp_unifying_get_serial(struct hidpp_device *hidpp, u32 *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) u8 params[1] = { HIDPP_EXTENDED_PAIRING };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) ret = hidpp_send_rap_command_sync(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) REPORT_ID_HIDPP_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) HIDPP_GET_LONG_REGISTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) HIDPP_REG_PAIRING_INFORMATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) params, 1, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) * We don't care about LE or BE, we will output it as a string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) * with %4phD, so we need to keep the order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) *serial = *((u32 *)&response.rap.params[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) static int hidpp_unifying_init(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) struct hid_device *hdev = hidpp->hid_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) u32 serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) ret = hidpp_unifying_get_serial(hidpp, &serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) snprintf(hdev->uniq, sizeof(hdev->uniq), "%04x-%4phD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) hdev->product, &serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) dbg_hid("HID++ Unifying: Got serial: %s\n", hdev->uniq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) name = hidpp_unifying_get_name(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) snprintf(hdev->name, sizeof(hdev->name), "%s", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) dbg_hid("HID++ Unifying: Got name: %s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /* 0x0000: Root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) #define HIDPP_PAGE_ROOT 0x0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) #define HIDPP_PAGE_ROOT_IDX 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) #define CMD_ROOT_GET_FEATURE 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) #define CMD_ROOT_GET_PROTOCOL_VERSION 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) static int hidpp_root_get_feature(struct hidpp_device *hidpp, u16 feature,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) u8 *feature_index, u8 *feature_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) u8 params[2] = { feature >> 8, feature & 0x00FF };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) ret = hidpp_send_fap_command_sync(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) HIDPP_PAGE_ROOT_IDX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) CMD_ROOT_GET_FEATURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) params, 2, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (response.fap.params[0] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) *feature_index = response.fap.params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) *feature_type = response.fap.params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) const u8 ping_byte = 0x5a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) u8 ping_data[3] = { 0, 0, ping_byte };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) ret = hidpp_send_rap_command_sync(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) REPORT_ID_HIDPP_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) HIDPP_PAGE_ROOT_IDX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) CMD_ROOT_GET_PROTOCOL_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) ping_data, sizeof(ping_data), &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (ret == HIDPP_ERROR_INVALID_SUBID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) hidpp->protocol_major = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) hidpp->protocol_minor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) goto print_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) /* the device might not be connected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (ret == HIDPP_ERROR_RESOURCE_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (response.rap.params[2] != ping_byte) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) hid_err(hidpp->hid_dev, "%s: ping mismatch 0x%02x != 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) __func__, response.rap.params[2], ping_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) hidpp->protocol_major = response.rap.params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) hidpp->protocol_minor = response.rap.params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) print_version:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) hid_info(hidpp->hid_dev, "HID++ %u.%u device connected.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) hidpp->protocol_major, hidpp->protocol_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) /* 0x0005: GetDeviceNameType */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) #define HIDPP_PAGE_GET_DEVICE_NAME_TYPE 0x0005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) #define CMD_GET_DEVICE_NAME_TYPE_GET_COUNT 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) #define CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) #define CMD_GET_DEVICE_NAME_TYPE_GET_TYPE 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) static int hidpp_devicenametype_get_count(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) u8 feature_index, u8 *nameLength)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) ret = hidpp_send_fap_command_sync(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) CMD_GET_DEVICE_NAME_TYPE_GET_COUNT, NULL, 0, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) *nameLength = response.fap.params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) static int hidpp_devicenametype_get_device_name(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) u8 feature_index, u8 char_index, char *device_name, int len_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) ret = hidpp_send_fap_command_sync(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME, &char_index, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) switch (response.report_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) case REPORT_ID_HIDPP_VERY_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) count = hidpp->very_long_report_length - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) case REPORT_ID_HIDPP_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) count = HIDPP_REPORT_LONG_LENGTH - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) case REPORT_ID_HIDPP_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) count = HIDPP_REPORT_SHORT_LENGTH - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) if (len_buf < count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) count = len_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) device_name[i] = response.fap.params[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) static char *hidpp_get_device_name(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) u8 feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) u8 __name_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) unsigned index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_GET_DEVICE_NAME_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) &feature_index, &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) ret = hidpp_devicenametype_get_count(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) &__name_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) name = kzalloc(__name_length + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) while (index < __name_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) ret = hidpp_devicenametype_get_device_name(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) feature_index, index, name + index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) __name_length - index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) if (ret <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) index += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) /* include the terminating '\0' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) hidpp_prefix_name(&name, __name_length + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) return name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) /* 0x1000: Battery level status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) #define HIDPP_PAGE_BATTERY_LEVEL_STATUS 0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) #define CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) #define EVENT_BATTERY_LEVEL_STATUS_BROADCAST 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) #define FLAG_BATTERY_LEVEL_DISABLE_OSD BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) #define FLAG_BATTERY_LEVEL_MILEAGE BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) #define FLAG_BATTERY_LEVEL_RECHARGEABLE BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) static int hidpp_map_battery_level(int capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if (capacity < 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) * The spec says this should be < 31 but some devices report 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) * with brand new batteries and Windows reports 30 as "Good".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) else if (capacity < 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) return POWER_SUPPLY_CAPACITY_LEVEL_LOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) else if (capacity < 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) return POWER_SUPPLY_CAPACITY_LEVEL_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) static int hidpp20_batterylevel_map_status_capacity(u8 data[3], int *capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) int *next_capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) int *level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) *capacity = data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) *next_capacity = data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) *level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) /* When discharging, we can rely on the device reported capacity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) * For all other states the device reports 0 (unknown).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) switch (data[2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) case 0: /* discharging (in use) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) status = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) *level = hidpp_map_battery_level(*capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) case 1: /* recharging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) status = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) case 2: /* charge in final stage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) status = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) case 3: /* charge complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) status = POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) *level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) *capacity = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) case 4: /* recharging below optimal speed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) status = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) /* 5 = invalid battery type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 6 = thermal error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 7 = other charging error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) status = POWER_SUPPLY_STATUS_NOT_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) static int hidpp20_batterylevel_get_battery_capacity(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) u8 feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) int *status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) int *capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) int *next_capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) int *level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) u8 *params = (u8 *)response.fap.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) ret = hidpp_send_fap_command_sync(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) NULL, 0, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) /* Ignore these intermittent errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) if (ret == HIDPP_ERROR_RESOURCE_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) *status = hidpp20_batterylevel_map_status_capacity(params, capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) next_capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) static int hidpp20_batterylevel_get_battery_info(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) u8 feature_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) u8 *params = (u8 *)response.fap.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) unsigned int level_count, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) ret = hidpp_send_fap_command_sync(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_CAPABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) NULL, 0, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) level_count = params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) flags = params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) if (level_count < 10 || !(flags & FLAG_BATTERY_LEVEL_MILEAGE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) static int hidpp20_query_battery_info(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) int status, capacity, next_capacity, level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) if (hidpp->battery.feature_index == 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) ret = hidpp_root_get_feature(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) HIDPP_PAGE_BATTERY_LEVEL_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) &hidpp->battery.feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) ret = hidpp20_batterylevel_get_battery_capacity(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) hidpp->battery.feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) &status, &capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) &next_capacity, &level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) ret = hidpp20_batterylevel_get_battery_info(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) hidpp->battery.feature_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) hidpp->battery.status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) hidpp->battery.capacity = capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) hidpp->battery.level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) /* the capacity is only available when discharging or full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) status == POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) static int hidpp20_battery_event(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) struct hidpp_report *report = (struct hidpp_report *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) int status, capacity, next_capacity, level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) bool changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) if (report->fap.feature_index != hidpp->battery.feature_index ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) status = hidpp20_batterylevel_map_status_capacity(report->fap.params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) &capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) &next_capacity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) &level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) /* the capacity is only available when discharging or full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) status == POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) changed = capacity != hidpp->battery.capacity ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) level != hidpp->battery.level ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) status != hidpp->battery.status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) hidpp->battery.level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) hidpp->battery.capacity = capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) hidpp->battery.status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) if (hidpp->battery.ps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) power_supply_changed(hidpp->battery.ps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) /* 0x1001: Battery voltage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) #define HIDPP_PAGE_BATTERY_VOLTAGE 0x1001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) #define CMD_BATTERY_VOLTAGE_GET_BATTERY_VOLTAGE 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) #define EVENT_BATTERY_VOLTAGE_STATUS_BROADCAST 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) static int hidpp20_battery_map_status_voltage(u8 data[3], int *voltage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) int *level, int *charge_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) long flags = (long) data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) *level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) if (flags & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) switch (flags & 0x07) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) status = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) status = POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) *level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) status = POWER_SUPPLY_STATUS_NOT_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) status = POWER_SUPPLY_STATUS_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) status = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) *charge_type = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) if (test_bit(3, &flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) *charge_type = POWER_SUPPLY_CHARGE_TYPE_FAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) if (test_bit(4, &flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) *charge_type = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) if (test_bit(5, &flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) *level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) *voltage = get_unaligned_be16(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) static int hidpp20_battery_get_battery_voltage(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) u8 feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) int *status, int *voltage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) int *level, int *charge_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) u8 *params = (u8 *)response.fap.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) ret = hidpp_send_fap_command_sync(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) CMD_BATTERY_VOLTAGE_GET_BATTERY_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) NULL, 0, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_VOLTAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) *status = hidpp20_battery_map_status_voltage(params, voltage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) level, charge_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) static int hidpp20_query_battery_voltage_info(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) int status, voltage, level, charge_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) if (hidpp->battery.voltage_feature_index == 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_BATTERY_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) &hidpp->battery.voltage_feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) ret = hidpp20_battery_get_battery_voltage(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) hidpp->battery.voltage_feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) &status, &voltage, &level, &charge_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) hidpp->battery.status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) hidpp->battery.voltage = voltage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) hidpp->battery.level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) hidpp->battery.charge_type = charge_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) static int hidpp20_battery_voltage_event(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) struct hidpp_report *report = (struct hidpp_report *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) int status, voltage, level, charge_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) if (report->fap.feature_index != hidpp->battery.voltage_feature_index ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) report->fap.funcindex_clientid != EVENT_BATTERY_VOLTAGE_STATUS_BROADCAST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) status = hidpp20_battery_map_status_voltage(report->fap.params, &voltage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) &level, &charge_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) if (voltage != hidpp->battery.voltage || status != hidpp->battery.status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) hidpp->battery.voltage = voltage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) hidpp->battery.status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) hidpp->battery.level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) hidpp->battery.charge_type = charge_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) if (hidpp->battery.ps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) power_supply_changed(hidpp->battery.ps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) static enum power_supply_property hidpp_battery_props[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) POWER_SUPPLY_PROP_ONLINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) POWER_SUPPLY_PROP_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) POWER_SUPPLY_PROP_SCOPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) POWER_SUPPLY_PROP_MODEL_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) POWER_SUPPLY_PROP_MANUFACTURER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) POWER_SUPPLY_PROP_SERIAL_NUMBER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY_LEVEL, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 0, /* placeholder for POWER_SUPPLY_PROP_VOLTAGE_NOW, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) static int hidpp_battery_get_property(struct power_supply *psy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) enum power_supply_property psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) union power_supply_propval *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) struct hidpp_device *hidpp = power_supply_get_drvdata(psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) switch(psp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) case POWER_SUPPLY_PROP_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) val->intval = hidpp->battery.status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) case POWER_SUPPLY_PROP_CAPACITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) val->intval = hidpp->battery.capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) val->intval = hidpp->battery.level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) case POWER_SUPPLY_PROP_SCOPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) val->intval = POWER_SUPPLY_SCOPE_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) case POWER_SUPPLY_PROP_ONLINE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) val->intval = hidpp->battery.online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) case POWER_SUPPLY_PROP_MODEL_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) if (!strncmp(hidpp->name, "Logitech ", 9))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) val->strval = hidpp->name + 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) val->strval = hidpp->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) case POWER_SUPPLY_PROP_MANUFACTURER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) val->strval = "Logitech";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) case POWER_SUPPLY_PROP_SERIAL_NUMBER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) val->strval = hidpp->hid_dev->uniq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) case POWER_SUPPLY_PROP_VOLTAGE_NOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) /* hardware reports voltage in in mV. sysfs expects uV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) val->intval = hidpp->battery.voltage * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) case POWER_SUPPLY_PROP_CHARGE_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) val->intval = hidpp->battery.charge_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) /* 0x1d4b: Wireless device status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) #define HIDPP_PAGE_WIRELESS_DEVICE_STATUS 0x1d4b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) static int hidpp_set_wireless_feature_index(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) ret = hidpp_root_get_feature(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) HIDPP_PAGE_WIRELESS_DEVICE_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) &hidpp->wireless_feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) /* 0x2120: Hi-resolution scrolling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) #define HIDPP_PAGE_HI_RESOLUTION_SCROLLING 0x2120
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) #define CMD_HI_RESOLUTION_SCROLLING_SET_HIGHRES_SCROLLING_MODE 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) static int hidpp_hrs_set_highres_scrolling_mode(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) bool enabled, u8 *multiplier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) u8 feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) u8 params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) ret = hidpp_root_get_feature(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) HIDPP_PAGE_HI_RESOLUTION_SCROLLING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) &feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) params[0] = enabled ? BIT(0) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) ret = hidpp_send_fap_command_sync(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) CMD_HI_RESOLUTION_SCROLLING_SET_HIGHRES_SCROLLING_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) params, sizeof(params), &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) *multiplier = response.fap.params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) /* 0x2121: HiRes Wheel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) #define HIDPP_PAGE_HIRES_WHEEL 0x2121
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) #define CMD_HIRES_WHEEL_GET_WHEEL_CAPABILITY 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) #define CMD_HIRES_WHEEL_SET_WHEEL_MODE 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) static int hidpp_hrw_get_wheel_capability(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) u8 *multiplier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) u8 feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_HIRES_WHEEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) &feature_index, &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) goto return_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) ret = hidpp_send_fap_command_sync(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) CMD_HIRES_WHEEL_GET_WHEEL_CAPABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) NULL, 0, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) goto return_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) *multiplier = response.fap.params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) return_default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) hid_warn(hidpp->hid_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) "Couldn't get wheel multiplier (error %d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) static int hidpp_hrw_set_wheel_mode(struct hidpp_device *hidpp, bool invert,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) bool high_resolution, bool use_hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) u8 feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) u8 params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_HIRES_WHEEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) &feature_index, &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) params[0] = (invert ? BIT(2) : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) (high_resolution ? BIT(1) : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) (use_hidpp ? BIT(0) : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) return hidpp_send_fap_command_sync(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) CMD_HIRES_WHEEL_SET_WHEEL_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) params, sizeof(params), &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) /* 0x4301: Solar Keyboard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) #define HIDPP_PAGE_SOLAR_KEYBOARD 0x4301
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) #define CMD_SOLAR_SET_LIGHT_MEASURE 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) #define EVENT_SOLAR_BATTERY_BROADCAST 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) #define EVENT_SOLAR_BATTERY_LIGHT_MEASURE 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) #define EVENT_SOLAR_CHECK_LIGHT_BUTTON 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) static int hidpp_solar_request_battery_event(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) u8 params[2] = { 1, 1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) if (hidpp->battery.feature_index == 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) ret = hidpp_root_get_feature(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) HIDPP_PAGE_SOLAR_KEYBOARD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) &hidpp->battery.solar_feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) ret = hidpp_send_fap_command_sync(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) hidpp->battery.solar_feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) CMD_SOLAR_SET_LIGHT_MEASURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) params, 2, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) static int hidpp_solar_battery_event(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) struct hidpp_report *report = (struct hidpp_report *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) int capacity, lux, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) u8 function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) function = report->fap.funcindex_clientid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) if (report->fap.feature_index != hidpp->battery.solar_feature_index ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) !(function == EVENT_SOLAR_BATTERY_BROADCAST ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) function == EVENT_SOLAR_BATTERY_LIGHT_MEASURE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) function == EVENT_SOLAR_CHECK_LIGHT_BUTTON))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) capacity = report->fap.params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) switch (function) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) case EVENT_SOLAR_BATTERY_LIGHT_MEASURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) lux = (report->fap.params[1] << 8) | report->fap.params[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) if (lux > 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) status = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) status = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) case EVENT_SOLAR_CHECK_LIGHT_BUTTON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) if (capacity < hidpp->battery.capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) status = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) status = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) if (capacity == 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) status = POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) hidpp->battery.online = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) if (capacity != hidpp->battery.capacity ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) status != hidpp->battery.status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) hidpp->battery.capacity = capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) hidpp->battery.status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) if (hidpp->battery.ps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) power_supply_changed(hidpp->battery.ps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) /* 0x6010: Touchpad FW items */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) #define HIDPP_PAGE_TOUCHPAD_FW_ITEMS 0x6010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) #define CMD_TOUCHPAD_FW_ITEMS_SET 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) struct hidpp_touchpad_fw_items {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) uint8_t presence;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) uint8_t desired_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) uint8_t state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) uint8_t persistent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) * send a set state command to the device by reading the current items->state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) * field. items is then filled with the current state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) static int hidpp_touchpad_fw_items_set(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) u8 feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) struct hidpp_touchpad_fw_items *items)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) u8 *params = (u8 *)response.fap.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) ret = hidpp_send_fap_command_sync(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) CMD_TOUCHPAD_FW_ITEMS_SET, &items->state, 1, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) items->presence = params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) items->desired_state = params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) items->state = params[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) items->persistent = params[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) /* 0x6100: TouchPadRawXY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) #define HIDPP_PAGE_TOUCHPAD_RAW_XY 0x6100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) #define CMD_TOUCHPAD_GET_RAW_INFO 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) #define CMD_TOUCHPAD_SET_RAW_REPORT_STATE 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) #define EVENT_TOUCHPAD_RAW_XY 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) #define TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) #define TOUCHPAD_RAW_XY_ORIGIN_UPPER_LEFT 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) struct hidpp_touchpad_raw_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) u16 x_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) u16 y_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) u8 z_range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) u8 area_range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) u8 timestamp_unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) u8 maxcontacts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) u8 origin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) u16 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) struct hidpp_touchpad_raw_xy_finger {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) u8 contact_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) u8 contact_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) u16 x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) u16 y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) u8 z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) u8 area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) u8 finger_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) struct hidpp_touchpad_raw_xy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) u16 timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) struct hidpp_touchpad_raw_xy_finger fingers[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) u8 spurious_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) u8 end_of_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) u8 finger_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) u8 button;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) static int hidpp_touchpad_get_raw_info(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) u8 feature_index, struct hidpp_touchpad_raw_info *raw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) u8 *params = (u8 *)response.fap.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) ret = hidpp_send_fap_command_sync(hidpp, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) CMD_TOUCHPAD_GET_RAW_INFO, NULL, 0, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) raw_info->x_size = get_unaligned_be16(¶ms[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) raw_info->y_size = get_unaligned_be16(¶ms[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) raw_info->z_range = params[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) raw_info->area_range = params[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) raw_info->maxcontacts = params[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) raw_info->origin = params[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) /* res is given in unit per inch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) raw_info->res = get_unaligned_be16(¶ms[13]) * 2 / 51;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) static int hidpp_touchpad_set_raw_report_state(struct hidpp_device *hidpp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) u8 feature_index, bool send_raw_reports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) bool sensor_enhanced_settings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) * Params:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) * bit 0 - enable raw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) * bit 1 - 16bit Z, no area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) * bit 2 - enhanced sensitivity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) * bit 3 - width, height (4 bits each) instead of area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) * bit 4 - send raw + gestures (degrades smoothness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) * remaining bits - reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) u8 params = send_raw_reports | (sensor_enhanced_settings << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) return hidpp_send_fap_command_sync(hidpp_dev, feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) CMD_TOUCHPAD_SET_RAW_REPORT_STATE, ¶ms, 1, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) static void hidpp_touchpad_touch_event(u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) struct hidpp_touchpad_raw_xy_finger *finger)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) u8 x_m = data[0] << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) u8 y_m = data[2] << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) finger->x = x_m << 6 | data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) finger->y = y_m << 6 | data[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) finger->contact_type = data[0] >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) finger->contact_status = data[2] >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) finger->z = data[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) finger->area = data[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) finger->finger_id = data[6] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) static void hidpp_touchpad_raw_xy_event(struct hidpp_device *hidpp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) u8 *data, struct hidpp_touchpad_raw_xy *raw_xy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) memset(raw_xy, 0, sizeof(struct hidpp_touchpad_raw_xy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) raw_xy->end_of_frame = data[8] & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) raw_xy->spurious_flag = (data[8] >> 1) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) raw_xy->finger_count = data[15] & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) raw_xy->button = (data[8] >> 2) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) if (raw_xy->finger_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) hidpp_touchpad_touch_event(&data[2], &raw_xy->fingers[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) hidpp_touchpad_touch_event(&data[9], &raw_xy->fingers[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) /* 0x8123: Force feedback support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) #define HIDPP_FF_GET_INFO 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) #define HIDPP_FF_RESET_ALL 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) #define HIDPP_FF_DOWNLOAD_EFFECT 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) #define HIDPP_FF_SET_EFFECT_STATE 0x31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) #define HIDPP_FF_DESTROY_EFFECT 0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) #define HIDPP_FF_GET_APERTURE 0x51
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) #define HIDPP_FF_SET_APERTURE 0x61
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) #define HIDPP_FF_GET_GLOBAL_GAINS 0x71
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) #define HIDPP_FF_SET_GLOBAL_GAINS 0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) #define HIDPP_FF_EFFECT_STATE_GET 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) #define HIDPP_FF_EFFECT_STATE_STOP 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) #define HIDPP_FF_EFFECT_STATE_PLAY 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) #define HIDPP_FF_EFFECT_STATE_PAUSE 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) #define HIDPP_FF_EFFECT_CONSTANT 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) #define HIDPP_FF_EFFECT_PERIODIC_SINE 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) #define HIDPP_FF_EFFECT_PERIODIC_SQUARE 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) #define HIDPP_FF_EFFECT_PERIODIC_TRIANGLE 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) #define HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) #define HIDPP_FF_EFFECT_SPRING 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) #define HIDPP_FF_EFFECT_DAMPER 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) #define HIDPP_FF_EFFECT_FRICTION 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) #define HIDPP_FF_EFFECT_INERTIA 0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) #define HIDPP_FF_EFFECT_RAMP 0x0A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) #define HIDPP_FF_EFFECT_AUTOSTART 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) #define HIDPP_FF_EFFECTID_NONE -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) #define HIDPP_FF_EFFECTID_AUTOCENTER -2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) #define HIDPP_AUTOCENTER_PARAMS_LENGTH 18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) #define HIDPP_FF_MAX_PARAMS 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) #define HIDPP_FF_RESERVED_SLOTS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) struct hidpp_ff_private_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) struct hidpp_device *hidpp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) u8 feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) u8 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) u16 gain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) s16 range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) u8 slot_autocenter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) u8 num_effects;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) int *effect_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) struct workqueue_struct *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) atomic_t workqueue_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) struct hidpp_ff_work_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) struct hidpp_ff_private_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) int effect_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) u8 command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) u8 params[HIDPP_FF_MAX_PARAMS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) u8 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) static const signed short hidpp_ff_effects[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) FF_CONSTANT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) FF_PERIODIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) FF_SINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) FF_SQUARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) FF_SAW_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) FF_SAW_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) FF_TRIANGLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) FF_SPRING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) FF_DAMPER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) FF_AUTOCENTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) FF_GAIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) static const signed short hidpp_ff_effects_v2[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) FF_RAMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) FF_FRICTION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) FF_INERTIA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) static const u8 HIDPP_FF_CONDITION_CMDS[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) HIDPP_FF_EFFECT_SPRING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) HIDPP_FF_EFFECT_FRICTION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) HIDPP_FF_EFFECT_DAMPER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) HIDPP_FF_EFFECT_INERTIA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) static const char *HIDPP_FF_CONDITION_NAMES[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) "spring",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) "friction",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) "damper",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) "inertia"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) static u8 hidpp_ff_find_effect(struct hidpp_ff_private_data *data, int effect_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) for (i = 0; i < data->num_effects; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) if (data->effect_ids[i] == effect_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) return i+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) static void hidpp_ff_work_handler(struct work_struct *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) struct hidpp_ff_work_data *wd = container_of(w, struct hidpp_ff_work_data, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) struct hidpp_ff_private_data *data = wd->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) u8 slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) /* add slot number if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) switch (wd->effect_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) case HIDPP_FF_EFFECTID_AUTOCENTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) wd->params[0] = data->slot_autocenter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) case HIDPP_FF_EFFECTID_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) /* leave slot as zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) /* find current slot for effect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) wd->params[0] = hidpp_ff_find_effect(data, wd->effect_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) /* send command and wait for reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) ret = hidpp_send_fap_command_sync(data->hidpp, data->feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) wd->command, wd->params, wd->size, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) hid_err(data->hidpp->hid_dev, "Failed to send command to device!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) /* parse return data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) switch (wd->command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) case HIDPP_FF_DOWNLOAD_EFFECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) slot = response.fap.params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) if (slot > 0 && slot <= data->num_effects) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) if (wd->effect_id >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) /* regular effect uploaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) data->effect_ids[slot-1] = wd->effect_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) /* autocenter spring uploaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) data->slot_autocenter = slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) case HIDPP_FF_DESTROY_EFFECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) if (wd->effect_id >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) /* regular effect destroyed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) data->effect_ids[wd->params[0]-1] = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) /* autocenter spring destoyed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) data->slot_autocenter = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) case HIDPP_FF_SET_GLOBAL_GAINS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) data->gain = (wd->params[0] << 8) + wd->params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) case HIDPP_FF_SET_APERTURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) data->range = (wd->params[0] << 8) + wd->params[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) /* no action needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) atomic_dec(&data->workqueue_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) kfree(wd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) static int hidpp_ff_queue_work(struct hidpp_ff_private_data *data, int effect_id, u8 command, u8 *params, u8 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) struct hidpp_ff_work_data *wd = kzalloc(sizeof(*wd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) int s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) if (!wd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) INIT_WORK(&wd->work, hidpp_ff_work_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) wd->data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) wd->effect_id = effect_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) wd->command = command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) wd->size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) memcpy(wd->params, params, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) atomic_inc(&data->workqueue_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) queue_work(data->wq, &wd->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) /* warn about excessive queue size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) s = atomic_read(&data->workqueue_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) if (s >= 20 && s % 20 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) hid_warn(data->hidpp->hid_dev, "Force feedback command queue contains %d commands, causing substantial delays!", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) static int hidpp_ff_upload_effect(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) struct hidpp_ff_private_data *data = dev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) u8 params[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) u8 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) int force;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) /* set common parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) params[2] = effect->replay.length >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) params[3] = effect->replay.length & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) params[4] = effect->replay.delay >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) params[5] = effect->replay.delay & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) switch (effect->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) case FF_CONSTANT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) force = (effect->u.constant.level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) params[1] = HIDPP_FF_EFFECT_CONSTANT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) params[6] = force >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) params[7] = force & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) params[8] = effect->u.constant.envelope.attack_level >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) params[9] = effect->u.constant.envelope.attack_length >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) params[10] = effect->u.constant.envelope.attack_length & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) params[11] = effect->u.constant.envelope.fade_level >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) params[12] = effect->u.constant.envelope.fade_length >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) params[13] = effect->u.constant.envelope.fade_length & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) size = 14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) dbg_hid("Uploading constant force level=%d in dir %d = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) effect->u.constant.level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) effect->direction, force);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) effect->u.constant.envelope.attack_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) effect->u.constant.envelope.attack_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) effect->u.constant.envelope.fade_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) effect->u.constant.envelope.fade_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) case FF_PERIODIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) switch (effect->u.periodic.waveform) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) case FF_SINE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) params[1] = HIDPP_FF_EFFECT_PERIODIC_SINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) case FF_SQUARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) params[1] = HIDPP_FF_EFFECT_PERIODIC_SQUARE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) case FF_SAW_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) params[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) case FF_SAW_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) params[1] = HIDPP_FF_EFFECT_PERIODIC_SAWTOOTHDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) case FF_TRIANGLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) params[1] = HIDPP_FF_EFFECT_PERIODIC_TRIANGLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) hid_err(data->hidpp->hid_dev, "Unexpected periodic waveform type %i!\n", effect->u.periodic.waveform);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) force = (effect->u.periodic.magnitude * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) params[6] = effect->u.periodic.magnitude >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) params[7] = effect->u.periodic.magnitude & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) params[8] = effect->u.periodic.offset >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) params[9] = effect->u.periodic.offset & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) params[10] = effect->u.periodic.period >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) params[11] = effect->u.periodic.period & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) params[12] = effect->u.periodic.phase >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) params[13] = effect->u.periodic.phase & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) params[14] = effect->u.periodic.envelope.attack_level >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) params[15] = effect->u.periodic.envelope.attack_length >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) params[16] = effect->u.periodic.envelope.attack_length & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) params[17] = effect->u.periodic.envelope.fade_level >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) params[18] = effect->u.periodic.envelope.fade_length >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) params[19] = effect->u.periodic.envelope.fade_length & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) size = 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) dbg_hid("Uploading periodic force mag=%d/dir=%d, offset=%d, period=%d ms, phase=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) effect->u.periodic.magnitude, effect->direction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) effect->u.periodic.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) effect->u.periodic.period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) effect->u.periodic.phase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) effect->u.periodic.envelope.attack_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) effect->u.periodic.envelope.attack_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) effect->u.periodic.envelope.fade_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) effect->u.periodic.envelope.fade_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) case FF_RAMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) params[1] = HIDPP_FF_EFFECT_RAMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) force = (effect->u.ramp.start_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) params[6] = force >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) params[7] = force & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) force = (effect->u.ramp.end_level * fixp_sin16((effect->direction * 360) >> 16)) >> 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) params[8] = force >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) params[9] = force & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) params[10] = effect->u.ramp.envelope.attack_level >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) params[11] = effect->u.ramp.envelope.attack_length >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) params[12] = effect->u.ramp.envelope.attack_length & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) params[13] = effect->u.ramp.envelope.fade_level >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) params[14] = effect->u.ramp.envelope.fade_length >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) params[15] = effect->u.ramp.envelope.fade_length & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) size = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) dbg_hid("Uploading ramp force level=%d -> %d in dir %d = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) effect->u.ramp.start_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) effect->u.ramp.end_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) effect->direction, force);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) dbg_hid(" envelope attack=(%d, %d ms) fade=(%d, %d ms)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) effect->u.ramp.envelope.attack_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) effect->u.ramp.envelope.attack_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) effect->u.ramp.envelope.fade_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) effect->u.ramp.envelope.fade_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) case FF_FRICTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) case FF_INERTIA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) case FF_SPRING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) case FF_DAMPER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) params[1] = HIDPP_FF_CONDITION_CMDS[effect->type - FF_SPRING];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) params[6] = effect->u.condition[0].left_saturation >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) params[7] = (effect->u.condition[0].left_saturation >> 1) & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) params[8] = effect->u.condition[0].left_coeff >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) params[9] = effect->u.condition[0].left_coeff & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) params[10] = effect->u.condition[0].deadband >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) params[11] = (effect->u.condition[0].deadband >> 1) & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) params[12] = effect->u.condition[0].center >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) params[13] = effect->u.condition[0].center & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) params[14] = effect->u.condition[0].right_coeff >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) params[15] = effect->u.condition[0].right_coeff & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) params[16] = effect->u.condition[0].right_saturation >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) params[17] = (effect->u.condition[0].right_saturation >> 1) & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) size = 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) dbg_hid("Uploading %s force left coeff=%d, left sat=%d, right coeff=%d, right sat=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) HIDPP_FF_CONDITION_NAMES[effect->type - FF_SPRING],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) effect->u.condition[0].left_coeff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) effect->u.condition[0].left_saturation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) effect->u.condition[0].right_coeff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) effect->u.condition[0].right_saturation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) dbg_hid(" deadband=%d, center=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) effect->u.condition[0].deadband,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) effect->u.condition[0].center);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) hid_err(data->hidpp->hid_dev, "Unexpected force type %i!\n", effect->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) return hidpp_ff_queue_work(data, effect->id, HIDPP_FF_DOWNLOAD_EFFECT, params, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) static int hidpp_ff_playback(struct input_dev *dev, int effect_id, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) struct hidpp_ff_private_data *data = dev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) u8 params[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) params[1] = value ? HIDPP_FF_EFFECT_STATE_PLAY : HIDPP_FF_EFFECT_STATE_STOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) dbg_hid("St%sing playback of effect %d.\n", value?"art":"opp", effect_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) return hidpp_ff_queue_work(data, effect_id, HIDPP_FF_SET_EFFECT_STATE, params, ARRAY_SIZE(params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) static int hidpp_ff_erase_effect(struct input_dev *dev, int effect_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) struct hidpp_ff_private_data *data = dev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) u8 slot = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) dbg_hid("Erasing effect %d.\n", effect_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) return hidpp_ff_queue_work(data, effect_id, HIDPP_FF_DESTROY_EFFECT, &slot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) static void hidpp_ff_set_autocenter(struct input_dev *dev, u16 magnitude)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) struct hidpp_ff_private_data *data = dev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) u8 params[HIDPP_AUTOCENTER_PARAMS_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) dbg_hid("Setting autocenter to %d.\n", magnitude);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) /* start a standard spring effect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) params[1] = HIDPP_FF_EFFECT_SPRING | HIDPP_FF_EFFECT_AUTOSTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) /* zero delay and duration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) params[2] = params[3] = params[4] = params[5] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) /* set coeff to 25% of saturation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) params[8] = params[14] = magnitude >> 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) params[9] = params[15] = (magnitude >> 3) & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) params[6] = params[16] = magnitude >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) params[7] = params[17] = (magnitude >> 1) & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) /* zero deadband and center */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) params[10] = params[11] = params[12] = params[13] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) hidpp_ff_queue_work(data, HIDPP_FF_EFFECTID_AUTOCENTER, HIDPP_FF_DOWNLOAD_EFFECT, params, ARRAY_SIZE(params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) static void hidpp_ff_set_gain(struct input_dev *dev, u16 gain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) struct hidpp_ff_private_data *data = dev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) u8 params[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) dbg_hid("Setting gain to %d.\n", gain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) params[0] = gain >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) params[1] = gain & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) params[2] = 0; /* no boost */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) params[3] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) hidpp_ff_queue_work(data, HIDPP_FF_EFFECTID_NONE, HIDPP_FF_SET_GLOBAL_GAINS, params, ARRAY_SIZE(params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) static ssize_t hidpp_ff_range_show(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) struct hid_device *hid = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) struct input_dev *idev = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) struct hidpp_ff_private_data *data = idev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) return scnprintf(buf, PAGE_SIZE, "%u\n", data->range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) static ssize_t hidpp_ff_range_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) struct hid_device *hid = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) struct input_dev *idev = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) struct hidpp_ff_private_data *data = idev->ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) u8 params[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) int range = simple_strtoul(buf, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) range = clamp(range, 180, 900);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) params[0] = range >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) params[1] = range & 0x00FF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) hidpp_ff_queue_work(data, -1, HIDPP_FF_SET_APERTURE, params, ARRAY_SIZE(params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) static DEVICE_ATTR(range, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, hidpp_ff_range_show, hidpp_ff_range_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) static void hidpp_ff_destroy(struct ff_device *ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) struct hidpp_ff_private_data *data = ff->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) struct hid_device *hid = data->hidpp->hid_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) hid_info(hid, "Unloading HID++ force feedback.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) device_remove_file(&hid->dev, &dev_attr_range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) destroy_workqueue(data->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) kfree(data->effect_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) static int hidpp_ff_init(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) struct hidpp_ff_private_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) struct hid_device *hid = hidpp->hid_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) struct hid_input *hidinput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) struct ff_device *ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) int error, j, num_slots = data->num_effects;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) u8 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) if (list_empty(&hid->inputs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) hid_err(hid, "no inputs found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) hidinput = list_entry(hid->inputs.next, struct hid_input, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) dev = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) hid_err(hid, "Struct input_dev not set!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) /* Get firmware release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) version = bcdDevice & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) /* Set supported force feedback capabilities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) for (j = 0; hidpp_ff_effects[j] >= 0; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) set_bit(hidpp_ff_effects[j], dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) if (version > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) for (j = 0; hidpp_ff_effects_v2[j] >= 0; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) set_bit(hidpp_ff_effects_v2[j], dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) error = input_ff_create(dev, num_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) hid_err(dev, "Failed to create FF device!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) * Create a copy of passed data, so we can transfer memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) * ownership to FF core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) data = kmemdup(data, sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) data->effect_ids = kcalloc(num_slots, sizeof(int), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) if (!data->effect_ids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) if (!data->wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) kfree(data->effect_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) data->hidpp = hidpp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) data->version = version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) for (j = 0; j < num_slots; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) data->effect_ids[j] = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) ff = dev->ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) ff->private = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) ff->upload = hidpp_ff_upload_effect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) ff->erase = hidpp_ff_erase_effect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) ff->playback = hidpp_ff_playback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) ff->set_gain = hidpp_ff_set_gain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) ff->set_autocenter = hidpp_ff_set_autocenter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) ff->destroy = hidpp_ff_destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) /* Create sysfs interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) error = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d!\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) /* init the hardware command queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) atomic_set(&data->workqueue_size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) hid_info(hid, "Force feedback support loaded (firmware release %d).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) /* ************************************************************************** */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) /* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) /* Device Support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) /* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) /* ************************************************************************** */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) /* Touchpad HID++ devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) #define WTP_MANUAL_RESOLUTION 39
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) struct wtp_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) u16 x_size, y_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) u8 finger_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) u8 mt_feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) u8 button_feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) u8 maxcontacts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) bool flip_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) unsigned int resolution;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) static int wtp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) static void wtp_populate_input(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) struct input_dev *input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) struct wtp_data *wd = hidpp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) __set_bit(EV_ABS, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) __set_bit(EV_KEY, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) __clear_bit(EV_REL, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) __clear_bit(EV_LED, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) input_abs_set_res(input_dev, ABS_MT_POSITION_X, wd->resolution);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) input_abs_set_res(input_dev, ABS_MT_POSITION_Y, wd->resolution);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) /* Max pressure is not given by the devices, pick one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 50, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) input_set_capability(input_dev, EV_KEY, BTN_LEFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) input_set_capability(input_dev, EV_KEY, BTN_RIGHT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) INPUT_MT_DROP_UNUSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) static void wtp_touch_event(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) struct hidpp_touchpad_raw_xy_finger *touch_report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) struct wtp_data *wd = hidpp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) int slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) if (!touch_report->finger_id || touch_report->contact_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) /* no actual data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) slot = input_mt_get_slot_by_key(hidpp->input, touch_report->finger_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) input_mt_slot(hidpp->input, slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) input_mt_report_slot_state(hidpp->input, MT_TOOL_FINGER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) touch_report->contact_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) if (touch_report->contact_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) touch_report->x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) wd->flip_y ? wd->y_size - touch_report->y :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) touch_report->y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) input_event(hidpp->input, EV_ABS, ABS_MT_PRESSURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) touch_report->area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) static void wtp_send_raw_xy_event(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) struct hidpp_touchpad_raw_xy *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) wtp_touch_event(hidpp, &(raw->fingers[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) if (raw->end_of_frame &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) input_event(hidpp->input, EV_KEY, BTN_LEFT, raw->button);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) if (raw->end_of_frame || raw->finger_count <= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) input_mt_sync_frame(hidpp->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) input_sync(hidpp->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) static int wtp_mouse_raw_xy_event(struct hidpp_device *hidpp, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) struct wtp_data *wd = hidpp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) u8 c1_area = ((data[7] & 0xf) * (data[7] & 0xf) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) (data[7] >> 4) * (data[7] >> 4)) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) u8 c2_area = ((data[13] & 0xf) * (data[13] & 0xf) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) (data[13] >> 4) * (data[13] >> 4)) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) struct hidpp_touchpad_raw_xy raw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) .timestamp = data[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) .fingers = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) .contact_type = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) .contact_status = !!data[7],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) .x = get_unaligned_le16(&data[3]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) .y = get_unaligned_le16(&data[5]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) .z = c1_area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) .area = c1_area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) .finger_id = data[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) .contact_type = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) .contact_status = !!data[13],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) .x = get_unaligned_le16(&data[9]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) .y = get_unaligned_le16(&data[11]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) .z = c2_area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) .area = c2_area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) .finger_id = data[8],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) .finger_count = wd->maxcontacts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) .spurious_flag = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) .end_of_frame = (data[0] >> 7) == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) .button = data[0] & 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) wtp_send_raw_xy_event(hidpp, &raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) struct wtp_data *wd = hidpp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) struct hidpp_report *report = (struct hidpp_report *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) struct hidpp_touchpad_raw_xy raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) if (!wd || !hidpp->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) switch (data[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) case 0x02:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) if (size < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) hid_err(hdev, "Received HID report of bad size (%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) input_event(hidpp->input, EV_KEY, BTN_LEFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) !!(data[1] & 0x01));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) input_event(hidpp->input, EV_KEY, BTN_RIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) !!(data[1] & 0x02));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) input_sync(hidpp->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) if (size < 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) return wtp_mouse_raw_xy_event(hidpp, &data[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) case REPORT_ID_HIDPP_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) /* size is already checked in hidpp_raw_event. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) if ((report->fap.feature_index != wd->mt_feature_index) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) hidpp_touchpad_raw_xy_event(hidpp, data + 4, &raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) wtp_send_raw_xy_event(hidpp, &raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) static int wtp_get_config(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) struct wtp_data *wd = hidpp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) struct hidpp_touchpad_raw_info raw_info = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_TOUCHPAD_RAW_XY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) &wd->mt_feature_index, &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) /* means that the device is not powered up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) ret = hidpp_touchpad_get_raw_info(hidpp, wd->mt_feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) &raw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) wd->x_size = raw_info.x_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) wd->y_size = raw_info.y_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) wd->maxcontacts = raw_info.maxcontacts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) wd->flip_y = raw_info.origin == TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) wd->resolution = raw_info.res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) if (!wd->resolution)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) wd->resolution = WTP_MANUAL_RESOLUTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) static int wtp_allocate(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) struct wtp_data *wd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) if (!wd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) hidpp->private_data = wd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) static int wtp_connect(struct hid_device *hdev, bool connected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) struct wtp_data *wd = hidpp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) if (!wd->x_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) ret = wtp_get_config(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) hid_err(hdev, "Can not get wtp config: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) true, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) /* ------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) /* Logitech M560 devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) /* ------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) * Logitech M560 protocol overview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) * The Logitech M560 mouse, is designed for windows 8. When the middle and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) * the sides buttons are pressed, it sends some keyboard keys events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) * instead of buttons ones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) * To complicate things further, the middle button keys sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) * is different from the odd press and the even press.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) * forward button -> Super_R
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) * backward button -> Super_L+'d' (press only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) * middle button -> 1st time: Alt_L+SuperL+XF86TouchpadOff (press only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) * 2nd time: left-click (press only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) * NB: press-only means that when the button is pressed, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) * KeyPress/ButtonPress and KeyRelease/ButtonRelease events are generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) * together sequentially; instead when the button is released, no event is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) * generated !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) * With the command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) * 10<xx>0a 3500af03 (where <xx> is the mouse id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) * the mouse reacts differently:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) * - it never sends a keyboard key event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) * - for the three mouse button it sends:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) * middle button press 11<xx>0a 3500af00...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) * side 1 button (forward) press 11<xx>0a 3500b000...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) * side 2 button (backward) press 11<xx>0a 3500ae00...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) * middle/side1/side2 button release 11<xx>0a 35000000...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) static const u8 m560_config_parameter[] = {0x00, 0xaf, 0x03};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) /* how buttons are mapped in the report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) #define M560_MOUSE_BTN_LEFT 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) #define M560_MOUSE_BTN_RIGHT 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) #define M560_MOUSE_BTN_WHEEL_LEFT 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) #define M560_MOUSE_BTN_WHEEL_RIGHT 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) #define M560_SUB_ID 0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) #define M560_BUTTON_MODE_REGISTER 0x35
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) static int m560_send_config_command(struct hid_device *hdev, bool connected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) struct hidpp_device *hidpp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) hidpp_dev = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) return hidpp_send_rap_command_sync(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) hidpp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) REPORT_ID_HIDPP_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) M560_SUB_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) M560_BUTTON_MODE_REGISTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) (u8 *)m560_config_parameter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) sizeof(m560_config_parameter),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) &response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) static int m560_raw_event(struct hid_device *hdev, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) /* sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) if (!hidpp->input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) hid_err(hdev, "error in parameter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) if (size < 7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) hid_err(hdev, "error in report\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) if (data[0] == REPORT_ID_HIDPP_LONG &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) data[2] == M560_SUB_ID && data[6] == 0x00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) * m560 mouse report for middle, forward and backward button
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) * data[0] = 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) * data[1] = device-id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) * data[2] = 0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) * data[5] = 0xaf -> middle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) * 0xb0 -> forward
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) * 0xae -> backward
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) * 0x00 -> release all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) * data[6] = 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) switch (data[5]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) case 0xaf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) input_report_key(hidpp->input, BTN_MIDDLE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) case 0xb0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) input_report_key(hidpp->input, BTN_FORWARD, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) case 0xae:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) input_report_key(hidpp->input, BTN_BACK, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) case 0x00:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) input_report_key(hidpp->input, BTN_BACK, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) input_report_key(hidpp->input, BTN_FORWARD, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) input_report_key(hidpp->input, BTN_MIDDLE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) hid_err(hdev, "error in report\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) input_sync(hidpp->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) } else if (data[0] == 0x02) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) * Logitech M560 mouse report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) * data[0] = type (0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) * data[1..2] = buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) * data[3..5] = xy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) * data[6] = wheel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) int v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) input_report_key(hidpp->input, BTN_LEFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) !!(data[1] & M560_MOUSE_BTN_LEFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) input_report_key(hidpp->input, BTN_RIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) !!(data[1] & M560_MOUSE_BTN_RIGHT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) if (data[1] & M560_MOUSE_BTN_WHEEL_LEFT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) input_report_rel(hidpp->input, REL_HWHEEL, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) input_report_rel(hidpp->input, REL_HWHEEL_HI_RES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) -120);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) } else if (data[1] & M560_MOUSE_BTN_WHEEL_RIGHT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) input_report_rel(hidpp->input, REL_HWHEEL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) input_report_rel(hidpp->input, REL_HWHEEL_HI_RES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 120);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) v = hid_snto32(hid_field_extract(hdev, data+3, 0, 12), 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) input_report_rel(hidpp->input, REL_X, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) v = hid_snto32(hid_field_extract(hdev, data+3, 12, 12), 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) input_report_rel(hidpp->input, REL_Y, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) v = hid_snto32(data[6], 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) if (v != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) hidpp_scroll_counter_handle_scroll(hidpp->input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) &hidpp->vertical_wheel_counter, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) input_sync(hidpp->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) static void m560_populate_input(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) struct input_dev *input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) __set_bit(EV_KEY, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) __set_bit(BTN_MIDDLE, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) __set_bit(BTN_RIGHT, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) __set_bit(BTN_LEFT, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) __set_bit(BTN_BACK, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) __set_bit(BTN_FORWARD, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) __set_bit(EV_REL, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) __set_bit(REL_X, input_dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) __set_bit(REL_Y, input_dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) __set_bit(REL_WHEEL, input_dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) __set_bit(REL_HWHEEL, input_dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) __set_bit(REL_WHEEL_HI_RES, input_dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) static int m560_input_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) /* ------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) /* Logitech K400 devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) /* ------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) * The Logitech K400 keyboard has an embedded touchpad which is seen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) * as a mouse from the OS point of view. There is a hardware shortcut to disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) * tap-to-click but the setting is not remembered accross reset, annoying some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) * users.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) * We can toggle this feature from the host by using the feature 0x6010:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) * Touchpad FW items
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) struct k400_private_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) u8 feature_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) static int k400_disable_tap_to_click(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) struct k400_private_data *k400 = hidpp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) struct hidpp_touchpad_fw_items items = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) if (!k400->feature_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) ret = hidpp_root_get_feature(hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) HIDPP_PAGE_TOUCHPAD_FW_ITEMS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) &k400->feature_index, &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) /* means that the device is not powered up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) ret = hidpp_touchpad_fw_items_set(hidpp, k400->feature_index, &items);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) static int k400_allocate(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) struct k400_private_data *k400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) k400 = devm_kzalloc(&hdev->dev, sizeof(struct k400_private_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) if (!k400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) hidpp->private_data = k400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) static int k400_connect(struct hid_device *hdev, bool connected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) if (!disable_tap_to_click)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) return k400_disable_tap_to_click(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) /* ------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) /* Logitech G920 Driving Force Racing Wheel for Xbox One */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) /* ------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) #define HIDPP_PAGE_G920_FORCE_FEEDBACK 0x8123
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) static int g920_ff_set_autocenter(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) struct hidpp_ff_private_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) u8 params[HIDPP_AUTOCENTER_PARAMS_LENGTH] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) [1] = HIDPP_FF_EFFECT_SPRING | HIDPP_FF_EFFECT_AUTOSTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) /* initialize with zero autocenter to get wheel in usable state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) dbg_hid("Setting autocenter to 0.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) HIDPP_FF_DOWNLOAD_EFFECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) params, ARRAY_SIZE(params),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) hid_warn(hidpp->hid_dev, "Failed to autocenter device!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) data->slot_autocenter = response.fap.params[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) static int g920_get_config(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) struct hidpp_ff_private_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) struct hidpp_report response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) u8 feature_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) memset(data, 0, sizeof(*data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) /* Find feature and store for later use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_G920_FORCE_FEEDBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) &data->feature_index, &feature_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) /* Read number of slots available in device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) HIDPP_FF_GET_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) hid_err(hidpp->hid_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) "%s: received protocol error 0x%02x\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) data->num_effects = response.fap.params[0] - HIDPP_FF_RESERVED_SLOTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) /* reset all forces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) HIDPP_FF_RESET_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) hid_warn(hidpp->hid_dev, "Failed to reset all forces!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) HIDPP_FF_GET_APERTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) hid_warn(hidpp->hid_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) "Failed to read range from device!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) data->range = ret ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 900 : get_unaligned_be16(&response.fap.params[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) /* Read the current gain values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) ret = hidpp_send_fap_command_sync(hidpp, data->feature_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) HIDPP_FF_GET_GLOBAL_GAINS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) hid_warn(hidpp->hid_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) "Failed to read gain values from device!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) data->gain = ret ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 0xffff : get_unaligned_be16(&response.fap.params[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) /* ignore boost value at response.fap.params[2] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) return g920_ff_set_autocenter(hidpp, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) /* Logitech Dinovo Mini keyboard with builtin touchpad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) #define DINOVO_MINI_PRODUCT_ID 0xb30c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) static int lg_dinovo_input_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) switch (usage->hid & HID_USAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) case 0x00d: lg_map_key_clear(KEY_MEDIA); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) /* HID++1.0 devices which use HID++ reports for their wheels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) static int hidpp10_wheel_connect(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) HIDPP_ENABLE_WHEEL_REPORT | HIDPP_ENABLE_HWHEEL_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) HIDPP_ENABLE_WHEEL_REPORT | HIDPP_ENABLE_HWHEEL_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) static int hidpp10_wheel_raw_event(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) s8 value, hvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) if (!hidpp->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) if (size < 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) if (data[0] != REPORT_ID_HIDPP_SHORT || data[2] != HIDPP_SUB_ID_ROLLER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) value = data[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) hvalue = data[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) input_report_rel(hidpp->input, REL_WHEEL, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) input_report_rel(hidpp->input, REL_WHEEL_HI_RES, value * 120);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) input_report_rel(hidpp->input, REL_HWHEEL, hvalue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) input_report_rel(hidpp->input, REL_HWHEEL_HI_RES, hvalue * 120);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) input_sync(hidpp->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) static void hidpp10_wheel_populate_input(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) struct input_dev *input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) __set_bit(EV_REL, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) __set_bit(REL_WHEEL, input_dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) __set_bit(REL_WHEEL_HI_RES, input_dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) __set_bit(REL_HWHEEL, input_dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) __set_bit(REL_HWHEEL_HI_RES, input_dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) /* HID++1.0 mice which use HID++ reports for extra mouse buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) static int hidpp10_extra_mouse_buttons_connect(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) HIDPP_ENABLE_MOUSE_EXTRA_BTN_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) static int hidpp10_extra_mouse_buttons_raw_event(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) if (!hidpp->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) if (size < 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) if (data[0] != REPORT_ID_HIDPP_SHORT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) data[2] != HIDPP_SUB_ID_MOUSE_EXTRA_BTNS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) * Buttons are either delivered through the regular mouse report *or*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) * through the extra buttons report. At least for button 6 how it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) * delivered differs per receiver firmware version. Even receivers with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) * the same usb-id show different behavior, so we handle both cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) for (i = 0; i < 8; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) input_report_key(hidpp->input, BTN_MOUSE + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) (data[3] & (1 << i)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) /* Some mice report events on button 9+, use BTN_MISC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) for (i = 0; i < 8; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) input_report_key(hidpp->input, BTN_MISC + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) (data[4] & (1 << i)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) input_sync(hidpp->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) static void hidpp10_extra_mouse_buttons_populate_input(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) struct hidpp_device *hidpp, struct input_dev *input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) /* BTN_MOUSE - BTN_MOUSE+7 are set already by the descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) __set_bit(BTN_0, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) __set_bit(BTN_1, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) __set_bit(BTN_2, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) __set_bit(BTN_3, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) __set_bit(BTN_4, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) __set_bit(BTN_5, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) __set_bit(BTN_6, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) __set_bit(BTN_7, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) /* HID++1.0 kbds which only report 0x10xx consumer usages through sub-id 0x03 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) /* Find the consumer-page input report desc and change Maximums to 0x107f */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) static u8 *hidpp10_consumer_keys_report_fixup(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) u8 *_rdesc, unsigned int *rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) /* Note 0 terminated so we can use strnstr to search for this. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) static const char consumer_rdesc_start[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 0x09, 0x01, /* USAGE (Consumer Control) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 0xA1, 0x01, /* COLLECTION (Application) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 0x85, 0x03, /* REPORT_ID = 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 0x75, 0x10, /* REPORT_SIZE (16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 0x95, 0x02, /* REPORT_COUNT (2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 0x15, 0x01, /* LOGICAL_MIN (1) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 0x26, 0x00 /* LOGICAL_MAX (... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) char *consumer_rdesc, *rdesc = (char *)_rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) consumer_rdesc = strnstr(rdesc, consumer_rdesc_start, *rsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) size = *rsize - (consumer_rdesc - rdesc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) if (consumer_rdesc && size >= 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) consumer_rdesc[15] = 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) consumer_rdesc[16] = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) consumer_rdesc[20] = 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) consumer_rdesc[21] = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) return _rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) static int hidpp10_consumer_keys_connect(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) return hidpp10_set_register(hidpp, HIDPP_REG_ENABLE_REPORTS, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) HIDPP_ENABLE_CONSUMER_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) HIDPP_ENABLE_CONSUMER_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) static int hidpp10_consumer_keys_raw_event(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) u8 consumer_report[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) if (size < 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) if (data[0] != REPORT_ID_HIDPP_SHORT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) data[2] != HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) * Build a normal consumer report (3) out of the data, this detour
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) * is necessary to get some keyboards to report their 0x10xx usages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) consumer_report[0] = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) memcpy(&consumer_report[1], &data[3], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) /* We are called from atomic context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) hid_report_raw_event(hidpp->hid_dev, HID_INPUT_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) consumer_report, 5, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) /* High-resolution scroll wheels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) static int hi_res_scroll_enable(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) u8 multiplier = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) ret = hidpp_hrw_set_wheel_mode(hidpp, false, true, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) ret = hidpp_hrw_get_wheel_capability(hidpp, &multiplier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) } else if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) ret = hidpp_hrs_set_highres_scrolling_mode(hidpp, true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) &multiplier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) } else /* if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_1P0) */ {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) ret = hidpp10_enable_scrolling_acceleration(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) multiplier = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) if (multiplier == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) multiplier = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) hidpp->vertical_wheel_counter.wheel_multiplier = multiplier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) hid_dbg(hidpp->hid_dev, "wheel multiplier = %d\n", multiplier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) /* Generic HID++ devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) /* -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) static u8 *hidpp_report_fixup(struct hid_device *hdev, u8 *rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) unsigned int *rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) if (!hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) return rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) /* For 27 MHz keyboards the quirk gets set after hid_parse. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) if (hdev->group == HID_GROUP_LOGITECH_27MHZ_DEVICE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) rdesc = hidpp10_consumer_keys_report_fixup(hidpp, rdesc, rsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) return rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) if (!hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) return wtp_input_mapping(hdev, hi, field, usage, bit, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) field->application != HID_GD_MOUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) return m560_input_mapping(hdev, hi, field, usage, bit, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) if (hdev->product == DINOVO_MINI_PRODUCT_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) return lg_dinovo_input_mapping(hdev, hi, field, usage, bit, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) static int hidpp_input_mapped(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) if (!hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) /* Ensure that Logitech G920 is not given a default fuzz/flat value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) if (usage->type == EV_ABS && (usage->code == ABS_X ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) usage->code == ABS_Y || usage->code == ABS_Z ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) usage->code == ABS_RZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) field->application = HID_GD_MULTIAXIS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) static void hidpp_populate_input(struct hidpp_device *hidpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) struct input_dev *input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) hidpp->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) wtp_populate_input(hidpp, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) m560_populate_input(hidpp, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) hidpp10_wheel_populate_input(hidpp, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) hidpp10_extra_mouse_buttons_populate_input(hidpp, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) static int hidpp_input_configured(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) struct hid_input *hidinput)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) struct input_dev *input = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) if (!hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) hidpp_populate_input(hidpp, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) struct hidpp_report *question = hidpp->send_receive_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) struct hidpp_report *answer = hidpp->send_receive_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) struct hidpp_report *report = (struct hidpp_report *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) * If the mutex is locked then we have a pending answer from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) * previously sent command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) if (unlikely(mutex_is_locked(&hidpp->send_mutex))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) * Check for a correct hidpp20 answer or the corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) * error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) if (hidpp_match_answer(question, report) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) hidpp_match_error(question, report)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) *answer = *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) hidpp->answer_available = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) wake_up(&hidpp->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) * This was an answer to a command that this driver sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) * We return 1 to hid-core to avoid forwarding the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) * command upstream as it has been treated by the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) if (unlikely(hidpp_report_is_connect_event(hidpp, report))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) atomic_set(&hidpp->connected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) !(report->rap.params[0] & (1 << 6)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) if (schedule_work(&hidpp->work) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) dbg_hid("%s: connect event already queued\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) ret = hidpp20_battery_event(hidpp, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) ret = hidpp_solar_battery_event(hidpp, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) ret = hidpp20_battery_voltage_event(hidpp, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) ret = hidpp10_battery_event(hidpp, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) ret = hidpp10_wheel_raw_event(hidpp, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) ret = hidpp10_extra_mouse_buttons_raw_event(hidpp, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) ret = hidpp10_consumer_keys_raw_event(hidpp, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) static int hidpp_raw_event(struct hid_device *hdev, struct hid_report *report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) if (!hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) /* Generic HID++ processing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) switch (data[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) case REPORT_ID_HIDPP_VERY_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) if (size != hidpp->very_long_report_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) hid_err(hdev, "received hid++ report of bad size (%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) ret = hidpp_raw_hidpp_event(hidpp, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) case REPORT_ID_HIDPP_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) if (size != HIDPP_REPORT_LONG_LENGTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) hid_err(hdev, "received hid++ report of bad size (%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) ret = hidpp_raw_hidpp_event(hidpp, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) case REPORT_ID_HIDPP_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) if (size != HIDPP_REPORT_SHORT_LENGTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) hid_err(hdev, "received hid++ report of bad size (%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) ret = hidpp_raw_hidpp_event(hidpp, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) /* If no report is available for further processing, skip calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) * raw_event of subclasses. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) return wtp_raw_event(hdev, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) return m560_raw_event(hdev, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) static int hidpp_event(struct hid_device *hdev, struct hid_field *field,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) struct hid_usage *usage, __s32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) /* This function will only be called for scroll events, due to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) * restriction imposed in hidpp_usages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) struct hidpp_scroll_counter *counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) if (!hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) counter = &hidpp->vertical_wheel_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) /* A scroll event may occur before the multiplier has been retrieved or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) * the input device set, or high-res scroll enabling may fail. In such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) * cases we must return early (falling back to default behaviour) to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) * avoid a crash in hidpp_scroll_counter_handle_scroll.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) if (!(hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL) || value == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) || hidpp->input == NULL || counter->wheel_multiplier == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) hidpp_scroll_counter_handle_scroll(hidpp->input, counter, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) static int hidpp_initialize_battery(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) static atomic_t battery_no = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) struct power_supply_config cfg = { .drv_data = hidpp };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) struct power_supply_desc *desc = &hidpp->battery.desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) enum power_supply_property *battery_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) struct hidpp_battery *battery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) unsigned int num_battery_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) unsigned long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) if (hidpp->battery.ps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) hidpp->battery.feature_index = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) hidpp->battery.solar_feature_index = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) hidpp->battery.voltage_feature_index = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) if (hidpp->protocol_major >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) if (hidpp->quirks & HIDPP_QUIRK_CLASS_K750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) ret = hidpp_solar_request_battery_event(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) ret = hidpp20_query_battery_voltage_info(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) ret = hidpp20_query_battery_info(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP20_BATTERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) ret = hidpp10_query_battery_status(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) ret = hidpp10_query_battery_mileage(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_MILEAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) hidpp->capabilities |= HIDPP_CAPABILITY_HIDPP10_BATTERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) battery_props = devm_kmemdup(&hidpp->hid_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) hidpp_battery_props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) sizeof(hidpp_battery_props),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) if (!battery_props)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) battery_props[num_battery_props++] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) POWER_SUPPLY_PROP_CAPACITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) battery_props[num_battery_props++] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) POWER_SUPPLY_PROP_CAPACITY_LEVEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) battery_props[num_battery_props++] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) POWER_SUPPLY_PROP_VOLTAGE_NOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) battery = &hidpp->battery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) n = atomic_inc_return(&battery_no) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) desc->properties = battery_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) desc->num_properties = num_battery_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) desc->get_property = hidpp_battery_get_property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) sprintf(battery->name, "hidpp_battery_%ld", n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) desc->name = battery->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) desc->type = POWER_SUPPLY_TYPE_BATTERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) desc->use_for_apm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) battery->ps = devm_power_supply_register(&hidpp->hid_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) &battery->desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) &cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) if (IS_ERR(battery->ps))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) return PTR_ERR(battery->ps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) power_supply_powers(battery->ps, &hidpp->hid_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) static void hidpp_overwrite_name(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) if (hidpp->protocol_major < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) name = hidpp_get_device_name(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) if (!name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) hid_err(hdev, "unable to retrieve the name of the device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) dbg_hid("HID++: Got name: %s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) snprintf(hdev->name, sizeof(hdev->name), "%s", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) static int hidpp_input_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) struct hid_device *hid = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) return hid_hw_open(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) static void hidpp_input_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) struct hid_device *hid = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) hid_hw_close(hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) static struct input_dev *hidpp_allocate_input(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) if (!input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) input_set_drvdata(input_dev, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) input_dev->open = hidpp_input_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) input_dev->close = hidpp_input_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) input_dev->name = hidpp->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) input_dev->phys = hdev->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) input_dev->uniq = hdev->uniq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) input_dev->id.bustype = hdev->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) input_dev->id.vendor = hdev->vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) input_dev->id.product = hdev->product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) input_dev->id.version = hdev->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) input_dev->dev.parent = &hdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) return input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) static void hidpp_connect_event(struct hidpp_device *hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) struct hid_device *hdev = hidpp->hid_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) bool connected = atomic_read(&hidpp->connected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) char *name, *devm_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) if (!connected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) if (hidpp->battery.ps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) hidpp->battery.online = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) hidpp->battery.status = POWER_SUPPLY_STATUS_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) hidpp->battery.level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) power_supply_changed(hidpp->battery.ps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) ret = wtp_connect(hdev, connected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) ret = m560_send_config_command(hdev, connected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) ret = k400_connect(hdev, connected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) ret = hidpp10_wheel_connect(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) if (hidpp->quirks & HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) ret = hidpp10_extra_mouse_buttons_connect(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) if (hidpp->quirks & HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) ret = hidpp10_consumer_keys_connect(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) /* the device is already connected, we can ask for its name and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) * protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) if (!hidpp->protocol_major) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) ret = hidpp_root_get_protocol_version(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) hid_err(hdev, "Can not get the protocol version.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) name = hidpp_get_device_name(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) if (name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) "%s", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) if (!devm_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) hidpp->name = devm_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) hidpp_initialize_battery(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) /* forward current battery state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) hidpp10_enable_battery_reporting(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) hidpp10_query_battery_mileage(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) hidpp10_query_battery_status(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) hidpp20_query_battery_voltage_info(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) hidpp20_query_battery_info(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) if (hidpp->battery.ps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) power_supply_changed(hidpp->battery.ps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) hi_res_scroll_enable(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) if (!(hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) || hidpp->delayed_input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) /* if the input nodes are already created, we can stop now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) input = hidpp_allocate_input(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) if (!input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) hid_err(hdev, "cannot allocate new input device: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) hidpp_populate_input(hidpp, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) ret = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) input_free_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) hidpp->delayed_input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) static DEVICE_ATTR(builtin_power_supply, 0000, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) static struct attribute *sysfs_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) &dev_attr_builtin_power_supply.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) static const struct attribute_group ps_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) .attrs = sysfs_attrs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) static int hidpp_get_report_length(struct hid_device *hdev, int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) struct hid_report_enum *re;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) re = &(hdev->report_enum[HID_OUTPUT_REPORT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) report = re->report_id_hash[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) if (!report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) return report->field[0]->report_count + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) static u8 hidpp_validate_device(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) int id, report_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) u8 supported_reports = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) id = REPORT_ID_HIDPP_SHORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) report_length = hidpp_get_report_length(hdev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) if (report_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) if (report_length < HIDPP_REPORT_SHORT_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) goto bad_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) supported_reports |= HIDPP_REPORT_SHORT_SUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) id = REPORT_ID_HIDPP_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) report_length = hidpp_get_report_length(hdev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) if (report_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) if (report_length < HIDPP_REPORT_LONG_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) goto bad_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) supported_reports |= HIDPP_REPORT_LONG_SUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) id = REPORT_ID_HIDPP_VERY_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) report_length = hidpp_get_report_length(hdev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) if (report_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) if (report_length < HIDPP_REPORT_LONG_LENGTH ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) report_length > HIDPP_REPORT_VERY_LONG_MAX_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) goto bad_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) supported_reports |= HIDPP_REPORT_VERY_LONG_SUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) hidpp->very_long_report_length = report_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) return supported_reports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) bad_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) hid_warn(hdev, "not enough values in hidpp report %d\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) static bool hidpp_application_equals(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) unsigned int application)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) struct list_head *report_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) report_list = &hdev->report_enum[HID_INPUT_REPORT].report_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) report = list_first_entry_or_null(report_list, struct hid_report, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) return report && report->application == application;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) struct hidpp_device *hidpp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) bool connected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) unsigned int connect_mask = HID_CONNECT_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) struct hidpp_ff_private_data data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) /* report_fixup needs drvdata to be set before we call hid_parse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) if (!hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) hidpp->hid_dev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) hidpp->name = hdev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) hidpp->quirks = id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) hid_set_drvdata(hdev, hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) hid_err(hdev, "%s:parse failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) * Make sure the device is HID++ capable, otherwise treat as generic HID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) hidpp->supported_reports = hidpp_validate_device(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) if (!hidpp->supported_reports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) hid_set_drvdata(hdev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) devm_kfree(&hdev->dev, hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) hidpp->quirks |= HIDPP_QUIRK_UNIFYING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) hidpp_application_equals(hdev, HID_GD_MOUSE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) hidpp->quirks |= HIDPP_QUIRK_HIDPP_WHEELS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) if (id->group == HID_GROUP_LOGITECH_27MHZ_DEVICE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) hidpp_application_equals(hdev, HID_GD_KEYBOARD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) hidpp->quirks |= HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) if (disable_raw_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) hidpp->quirks &= ~HIDPP_QUIRK_NO_HIDINPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) ret = wtp_allocate(hdev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) ret = k400_allocate(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) INIT_WORK(&hidpp->work, delayed_work_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) mutex_init(&hidpp->send_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) init_waitqueue_head(&hidpp->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) /* indicates we are handling the battery properties in the kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) ret = sysfs_create_group(&hdev->dev.kobj, &ps_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) hid_warn(hdev, "Cannot allocate sysfs group for %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) * Plain USB connections need to actually call start and open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) * on the transport driver to allow incoming data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) ret = hid_hw_start(hdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) goto hid_hw_start_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) ret = hid_hw_open(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) goto hid_hw_open_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) /* Allow incoming packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) hid_device_io_start(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) if (hidpp->quirks & HIDPP_QUIRK_UNIFYING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) hidpp_unifying_init(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) connected = hidpp_root_get_protocol_version(hidpp) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) atomic_set(&hidpp->connected, connected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) if (!connected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) hid_err(hdev, "Device not connected");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) goto hid_hw_init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) hidpp_overwrite_name(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) if (connected && hidpp->protocol_major >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) ret = hidpp_set_wireless_feature_index(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) if (ret == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) hidpp->wireless_feature_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) else if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) goto hid_hw_init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) ret = wtp_get_config(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) goto hid_hw_init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) ret = g920_get_config(hidpp, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) goto hid_hw_init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) hidpp_connect_event(hidpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) /* Reset the HID node state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) hid_device_io_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) hid_hw_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) connect_mask &= ~HID_CONNECT_HIDINPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) /* Now export the actual inputs and hidraw nodes to the world */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) ret = hid_hw_start(hdev, connect_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) hid_err(hdev, "%s:hid_hw_start returned error\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) goto hid_hw_start_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) ret = hidpp_ff_init(hidpp, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) hid_warn(hidpp->hid_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) "Unable to initialize force feedback support, errno %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) hid_hw_init_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) hid_hw_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) hid_hw_open_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) hid_hw_start_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) cancel_work_sync(&hidpp->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) mutex_destroy(&hidpp->send_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) static void hidpp_remove(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) struct hidpp_device *hidpp = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) if (!hidpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) return hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) cancel_work_sync(&hidpp->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) mutex_destroy(&hidpp->send_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) #define LDJ_DEVICE(product) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) USB_VENDOR_ID_LOGITECH, (product))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) #define L27MHZ_DEVICE(product) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_27MHZ_DEVICE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) USB_VENDOR_ID_LOGITECH, (product))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) static const struct hid_device_id hidpp_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) { /* wireless touchpad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) LDJ_DEVICE(0x4011),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) { /* wireless touchpad T650 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) LDJ_DEVICE(0x4101),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) { /* wireless touchpad T651 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) USB_DEVICE_ID_LOGITECH_T651),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) .driver_data = HIDPP_QUIRK_CLASS_WTP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) { /* Mouse Logitech Anywhere MX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) LDJ_DEVICE(0x1017), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_1P0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) { /* Mouse Logitech Cube */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) LDJ_DEVICE(0x4010), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2120 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) { /* Mouse Logitech M335 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) LDJ_DEVICE(0x4050), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) { /* Mouse Logitech M515 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) LDJ_DEVICE(0x4007), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2120 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) { /* Mouse logitech M560 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) LDJ_DEVICE(0x402d),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) .driver_data = HIDPP_QUIRK_DELAYED_INIT | HIDPP_QUIRK_CLASS_M560
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) | HIDPP_QUIRK_HI_RES_SCROLL_X2120 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) { /* Mouse Logitech M705 (firmware RQM17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) LDJ_DEVICE(0x101b), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_1P0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) { /* Mouse Logitech M705 (firmware RQM67) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) LDJ_DEVICE(0x406d), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) { /* Mouse Logitech M720 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) LDJ_DEVICE(0x405e), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) { /* Mouse Logitech MX Anywhere 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) LDJ_DEVICE(0x404a), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) { LDJ_DEVICE(0x4072), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) { LDJ_DEVICE(0xb013), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) { LDJ_DEVICE(0xb018), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) { LDJ_DEVICE(0xb01f), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) { /* Mouse Logitech MX Anywhere 2S */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) LDJ_DEVICE(0x406a), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) { /* Mouse Logitech MX Master */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) LDJ_DEVICE(0x4041), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) { LDJ_DEVICE(0x4060), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) { LDJ_DEVICE(0x4071), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) { /* Mouse Logitech MX Master 2S */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) LDJ_DEVICE(0x4069), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) { /* Mouse Logitech MX Master 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) LDJ_DEVICE(0x4082), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) { /* Mouse Logitech Performance MX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) LDJ_DEVICE(0x101a), .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_1P0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) { /* Keyboard logitech K400 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) LDJ_DEVICE(0x4024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) .driver_data = HIDPP_QUIRK_CLASS_K400 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) { /* Solar Keyboard Logitech K750 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) LDJ_DEVICE(0x4002),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) .driver_data = HIDPP_QUIRK_CLASS_K750 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) { /* Keyboard MX5000 (Bluetooth-receiver in HID proxy mode) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) LDJ_DEVICE(0xb305),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) { /* Dinovo Edge (Bluetooth-receiver in HID proxy mode) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) LDJ_DEVICE(0xb309),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) { /* Keyboard MX5500 (Bluetooth-receiver in HID proxy mode) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) LDJ_DEVICE(0xb30b),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) { LDJ_DEVICE(HID_ANY_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) { /* Keyboard LX501 (Y-RR53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) L27MHZ_DEVICE(0x0049),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) .driver_data = HIDPP_QUIRK_KBD_ZOOM_WHEEL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) { /* Keyboard MX3000 (Y-RAM74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) L27MHZ_DEVICE(0x0057),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) .driver_data = HIDPP_QUIRK_KBD_SCROLL_WHEEL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) { /* Keyboard MX3200 (Y-RAV80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) L27MHZ_DEVICE(0x005c),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) .driver_data = HIDPP_QUIRK_KBD_ZOOM_WHEEL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) { /* S510 Media Remote */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) L27MHZ_DEVICE(0x00fe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) .driver_data = HIDPP_QUIRK_KBD_SCROLL_WHEEL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) { L27MHZ_DEVICE(HID_ANY_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) { /* Logitech G403 Wireless Gaming Mouse over USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC082) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) { /* Logitech G703 Gaming Mouse over USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC087) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) { /* Logitech G703 Hero Gaming Mouse over USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC090) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) { /* Logitech G900 Gaming Mouse over USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC081) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) { /* Logitech G903 Gaming Mouse over USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC086) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) { /* Logitech G903 Hero Gaming Mouse over USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC091) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) { /* Logitech G920 Wheel over USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) .driver_data = HIDPP_QUIRK_CLASS_G920 | HIDPP_QUIRK_FORCE_OUTPUT_REPORTS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) { /* Logitech G Pro Gaming Mouse over USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC088) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) { /* MX5000 keyboard over Bluetooth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb305),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) { /* Dinovo Edge keyboard over Bluetooth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb309),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) { /* MX5500 keyboard over Bluetooth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb30b),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) { /* MX Master mouse over Bluetooth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb012),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) { /* MX Ergo trackball over Bluetooth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01d) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01e),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) { /* MX Master 3 mouse over Bluetooth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb023),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) MODULE_DEVICE_TABLE(hid, hidpp_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) static const struct hid_usage_id hidpp_usages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) { HID_GD_WHEEL, EV_REL, REL_WHEEL_HI_RES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) static struct hid_driver hidpp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) .name = "logitech-hidpp-device",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) .id_table = hidpp_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) .report_fixup = hidpp_report_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) .probe = hidpp_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) .remove = hidpp_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) .raw_event = hidpp_raw_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) .usage_table = hidpp_usages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) .event = hidpp_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) .input_configured = hidpp_input_configured,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) .input_mapping = hidpp_input_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) .input_mapped = hidpp_input_mapped,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) module_hid_driver(hidpp_driver);