Skip to content

Commit 9de07a4

Browse files
johnchen902Jiri Kosina
authored andcommitted
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: John Chen <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent c0dc558 commit 9de07a4

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

drivers/hid/hid-debug.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ static const struct hid_usage_entry hid_usage_table[] = {
417417
{ 0x85, 0x44, "Charging" },
418418
{ 0x85, 0x45, "Discharging" },
419419
{ 0x85, 0x4b, "NeedReplacement" },
420+
{ 0x85, 0x65, "AbsoluteStateOfCharge" },
420421
{ 0x85, 0x66, "RemainingCapacity" },
421422
{ 0x85, 0x68, "RunTimeToEmpty" },
422423
{ 0x85, 0x6a, "AverageTimeToFull" },

drivers/hid/hid-input.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ static int hidinput_get_battery_property(struct power_supply *psy,
435435
return ret;
436436
}
437437

438-
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type, struct hid_field *field)
438+
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
439+
struct hid_field *field, bool is_percentage)
439440
{
440441
struct power_supply_desc *psy_desc;
441442
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,
475476
min = field->logical_minimum;
476477
max = field->logical_maximum;
477478

478-
if (quirks & HID_BATTERY_QUIRK_PERCENT) {
479+
if (is_percentage || (quirks & HID_BATTERY_QUIRK_PERCENT)) {
479480
min = 0;
480481
max = 100;
481482
}
@@ -552,7 +553,7 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
552553
}
553554
#else /* !CONFIG_HID_BATTERY_STRENGTH */
554555
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
555-
struct hid_field *field)
556+
struct hid_field *field, bool is_percentage)
556557
{
557558
return 0;
558559
}
@@ -806,7 +807,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
806807
break;
807808

808809
case 0x3b: /* Battery Strength */
809-
hidinput_setup_battery(device, HID_INPUT_REPORT, field);
810+
hidinput_setup_battery(device, HID_INPUT_REPORT, field, false);
810811
usage->type = EV_PWR;
811812
return;
812813

@@ -1068,7 +1069,16 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
10681069
case HID_UP_GENDEVCTRLS:
10691070
switch (usage->hid) {
10701071
case HID_DC_BATTERYSTRENGTH:
1071-
hidinput_setup_battery(device, HID_INPUT_REPORT, field);
1072+
hidinput_setup_battery(device, HID_INPUT_REPORT, field, false);
1073+
usage->type = EV_PWR;
1074+
return;
1075+
}
1076+
goto unknown;
1077+
1078+
case HID_UP_BATTERY:
1079+
switch (usage->hid) {
1080+
case HID_BAT_ABSOLUTESTATEOFCHARGE:
1081+
hidinput_setup_battery(device, HID_INPUT_REPORT, field, true);
10721082
usage->type = EV_PWR;
10731083
return;
10741084
}
@@ -1672,7 +1682,7 @@ static void report_features(struct hid_device *hid)
16721682
/* Verify if Battery Strength feature is available */
16731683
if (usage->hid == HID_DC_BATTERYSTRENGTH)
16741684
hidinput_setup_battery(hid, HID_FEATURE_REPORT,
1675-
rep->field[i]);
1685+
rep->field[i], false);
16761686

16771687
if (drv->feature_mapping)
16781688
drv->feature_mapping(hid, rep->field[i], usage);

include/linux/hid.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ struct hid_item {
153153
#define HID_UP_CONSUMER 0x000c0000
154154
#define HID_UP_DIGITIZER 0x000d0000
155155
#define HID_UP_PID 0x000f0000
156+
#define HID_UP_BATTERY 0x00850000
156157
#define HID_UP_HPVENDOR 0xff7f0000
157158
#define HID_UP_HPVENDOR2 0xff010000
158159
#define HID_UP_MSVENDOR 0xff000000
@@ -297,6 +298,8 @@ struct hid_item {
297298
#define HID_DG_TOOLSERIALNUMBER 0x000d005b
298299
#define HID_DG_LATENCYMODE 0x000d0060
299300

301+
#define HID_BAT_ABSOLUTESTATEOFCHARGE 0x00850065
302+
300303
#define HID_VD_ASUS_CUSTOM_MEDIA_KEYS 0xff310076
301304
/*
302305
* HID report types --- Ouch! HID spec says 1 2 3!

0 commit comments

Comments
 (0)