Commit 9de07a4e authored by John Chen's avatar John Chen Committed by Jiri Kosina

HID: input: map battery capacity (00850065)

This is the capacity in percentage, relative to design capacity.
Specifically, it is present in Apple Magic Mouse 2.

In contrast, usage 00850064 is also the capacity in percentage, but is
relative to full capacity. It is not mapped here because I don't have
such device.
Signed-off-by: default avatarJohn Chen <johnchen902@gmail.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent c0dc5582
...@@ -417,6 +417,7 @@ static const struct hid_usage_entry hid_usage_table[] = { ...@@ -417,6 +417,7 @@ static const struct hid_usage_entry hid_usage_table[] = {
{ 0x85, 0x44, "Charging" }, { 0x85, 0x44, "Charging" },
{ 0x85, 0x45, "Discharging" }, { 0x85, 0x45, "Discharging" },
{ 0x85, 0x4b, "NeedReplacement" }, { 0x85, 0x4b, "NeedReplacement" },
{ 0x85, 0x65, "AbsoluteStateOfCharge" },
{ 0x85, 0x66, "RemainingCapacity" }, { 0x85, 0x66, "RemainingCapacity" },
{ 0x85, 0x68, "RunTimeToEmpty" }, { 0x85, 0x68, "RunTimeToEmpty" },
{ 0x85, 0x6a, "AverageTimeToFull" }, { 0x85, 0x6a, "AverageTimeToFull" },
......
...@@ -435,7 +435,8 @@ static int hidinput_get_battery_property(struct power_supply *psy, ...@@ -435,7 +435,8 @@ static int hidinput_get_battery_property(struct power_supply *psy,
return ret; return ret;
} }
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type, struct hid_field *field) static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
struct hid_field *field, bool is_percentage)
{ {
struct power_supply_desc *psy_desc; struct power_supply_desc *psy_desc;
struct power_supply_config psy_cfg = { .drv_data = dev, }; struct power_supply_config psy_cfg = { .drv_data = dev, };
...@@ -475,7 +476,7 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type, ...@@ -475,7 +476,7 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
min = field->logical_minimum; min = field->logical_minimum;
max = field->logical_maximum; max = field->logical_maximum;
if (quirks & HID_BATTERY_QUIRK_PERCENT) { if (is_percentage || (quirks & HID_BATTERY_QUIRK_PERCENT)) {
min = 0; min = 0;
max = 100; max = 100;
} }
...@@ -552,7 +553,7 @@ static void hidinput_update_battery(struct hid_device *dev, int value) ...@@ -552,7 +553,7 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
} }
#else /* !CONFIG_HID_BATTERY_STRENGTH */ #else /* !CONFIG_HID_BATTERY_STRENGTH */
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type, static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
struct hid_field *field) struct hid_field *field, bool is_percentage)
{ {
return 0; return 0;
} }
...@@ -806,7 +807,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel ...@@ -806,7 +807,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
break; break;
case 0x3b: /* Battery Strength */ case 0x3b: /* Battery Strength */
hidinput_setup_battery(device, HID_INPUT_REPORT, field); hidinput_setup_battery(device, HID_INPUT_REPORT, field, false);
usage->type = EV_PWR; usage->type = EV_PWR;
return; return;
...@@ -1068,7 +1069,16 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel ...@@ -1068,7 +1069,16 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
case HID_UP_GENDEVCTRLS: case HID_UP_GENDEVCTRLS:
switch (usage->hid) { switch (usage->hid) {
case HID_DC_BATTERYSTRENGTH: case HID_DC_BATTERYSTRENGTH:
hidinput_setup_battery(device, HID_INPUT_REPORT, field); hidinput_setup_battery(device, HID_INPUT_REPORT, field, false);
usage->type = EV_PWR;
return;
}
goto unknown;
case HID_UP_BATTERY:
switch (usage->hid) {
case HID_BAT_ABSOLUTESTATEOFCHARGE:
hidinput_setup_battery(device, HID_INPUT_REPORT, field, true);
usage->type = EV_PWR; usage->type = EV_PWR;
return; return;
} }
...@@ -1672,7 +1682,7 @@ static void report_features(struct hid_device *hid) ...@@ -1672,7 +1682,7 @@ static void report_features(struct hid_device *hid)
/* Verify if Battery Strength feature is available */ /* Verify if Battery Strength feature is available */
if (usage->hid == HID_DC_BATTERYSTRENGTH) if (usage->hid == HID_DC_BATTERYSTRENGTH)
hidinput_setup_battery(hid, HID_FEATURE_REPORT, hidinput_setup_battery(hid, HID_FEATURE_REPORT,
rep->field[i]); rep->field[i], false);
if (drv->feature_mapping) if (drv->feature_mapping)
drv->feature_mapping(hid, rep->field[i], usage); drv->feature_mapping(hid, rep->field[i], usage);
......
...@@ -153,6 +153,7 @@ struct hid_item { ...@@ -153,6 +153,7 @@ struct hid_item {
#define HID_UP_CONSUMER 0x000c0000 #define HID_UP_CONSUMER 0x000c0000
#define HID_UP_DIGITIZER 0x000d0000 #define HID_UP_DIGITIZER 0x000d0000
#define HID_UP_PID 0x000f0000 #define HID_UP_PID 0x000f0000
#define HID_UP_BATTERY 0x00850000
#define HID_UP_HPVENDOR 0xff7f0000 #define HID_UP_HPVENDOR 0xff7f0000
#define HID_UP_HPVENDOR2 0xff010000 #define HID_UP_HPVENDOR2 0xff010000
#define HID_UP_MSVENDOR 0xff000000 #define HID_UP_MSVENDOR 0xff000000
...@@ -297,6 +298,8 @@ struct hid_item { ...@@ -297,6 +298,8 @@ struct hid_item {
#define HID_DG_TOOLSERIALNUMBER 0x000d005b #define HID_DG_TOOLSERIALNUMBER 0x000d005b
#define HID_DG_LATENCYMODE 0x000d0060 #define HID_DG_LATENCYMODE 0x000d0060
#define HID_BAT_ABSOLUTESTATEOFCHARGE 0x00850065
#define HID_VD_ASUS_CUSTOM_MEDIA_KEYS 0xff310076 #define HID_VD_ASUS_CUSTOM_MEDIA_KEYS 0xff310076
/* /*
* HID report types --- Ouch! HID spec says 1 2 3! * HID report types --- Ouch! HID spec says 1 2 3!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment