hid-input/battery: add FEATURE quirk
Apple keyboards require a FEATURE report to query the battery state, even though they list as an input. Without this, it returns an error. Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
This commit is contained in:
parent
ce63920b39
commit
652aa6a9ac
|
@ -124,6 +124,7 @@
|
|||
#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239
|
||||
#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a
|
||||
#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b
|
||||
#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI 0x0255
|
||||
#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256
|
||||
#define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a
|
||||
#define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b
|
||||
|
|
|
@ -283,12 +283,12 @@ static enum power_supply_property hidinput_battery_props[] = {
|
|||
};
|
||||
|
||||
#define HID_BATTERY_QUIRK_PERCENT (1 << 0) /* always reports percent */
|
||||
#define HID_BATTERY_QUIRK_FEATURE (1 << 1) /* ask for feature report */
|
||||
|
||||
static const struct hid_device_id hid_battery_quirks[] = {
|
||||
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE),
|
||||
HID_BATTERY_QUIRK_PERCENT },
|
||||
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD),
|
||||
HID_BATTERY_QUIRK_PERCENT },
|
||||
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
|
||||
USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI),
|
||||
HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE },
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -310,7 +310,6 @@ static int hidinput_get_battery_property(struct power_supply *psy,
|
|||
{
|
||||
struct hid_device *dev = container_of(psy, struct hid_device, battery);
|
||||
int ret = 0;
|
||||
int ret_rep;
|
||||
__u8 buf[2] = {};
|
||||
|
||||
switch (prop) {
|
||||
|
@ -320,11 +319,13 @@ static int hidinput_get_battery_property(struct power_supply *psy,
|
|||
break;
|
||||
|
||||
case POWER_SUPPLY_PROP_CAPACITY:
|
||||
ret_rep = dev->hid_get_raw_report(dev, dev->battery_report_id,
|
||||
buf, sizeof(buf),
|
||||
dev->battery_report_type);
|
||||
if (ret_rep != 2) {
|
||||
ret = -EINVAL;
|
||||
ret = dev->hid_get_raw_report(dev, dev->battery_report_id,
|
||||
buf, sizeof(buf),
|
||||
dev->battery_report_type);
|
||||
|
||||
if (ret != 2) {
|
||||
if (ret >= 0)
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -376,6 +377,9 @@ static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
|
|||
|
||||
quirks = find_battery_quirk(dev);
|
||||
|
||||
hid_dbg(dev, "device %x:%x:%x %d quirks %d\n",
|
||||
dev->bus, dev->vendor, dev->product, dev->version, quirks);
|
||||
|
||||
min = field->logical_minimum;
|
||||
max = field->logical_maximum;
|
||||
|
||||
|
@ -384,6 +388,9 @@ static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
|
|||
max = 100;
|
||||
}
|
||||
|
||||
if (quirks & HID_BATTERY_QUIRK_FEATURE)
|
||||
report_type = HID_FEATURE_REPORT;
|
||||
|
||||
dev->battery_min = min;
|
||||
dev->battery_max = max;
|
||||
dev->battery_report_type = report_type;
|
||||
|
|
Loading…
Reference in a new issue