Skip to content

Commit

Permalink
hid-input/battery: add FEATURE quirk
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jsgf committed Jan 8, 2012
1 parent ce63920 commit 652aa6a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions drivers/hid/hid-ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 17 additions & 10 deletions drivers/hid/hid-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
{}
};

Expand All @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 652aa6a

Please sign in to comment.