hid-input/battery: add quirks for battery
Some devices always report percentage, despite having 0/255 as their min/max, so add a quirk for them. Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
This commit is contained in:
parent
ef5251993c
commit
bbc21cfd55
3 changed files with 40 additions and 5 deletions
|
@ -1157,7 +1157,7 @@ static bool hid_match_one_id(struct hid_device *hdev,
|
||||||
(id->product == HID_ANY_ID || id->product == hdev->product);
|
(id->product == HID_ANY_ID || id->product == hdev->product);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct hid_device_id *hid_match_id(struct hid_device *hdev,
|
const struct hid_device_id *hid_match_id(struct hid_device *hdev,
|
||||||
const struct hid_device_id *id)
|
const struct hid_device_id *id)
|
||||||
{
|
{
|
||||||
for (; id->bus; id++)
|
for (; id->bus; id++)
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include <linux/hid.h>
|
#include <linux/hid.h>
|
||||||
#include <linux/hid-debug.h>
|
#include <linux/hid-debug.h>
|
||||||
|
|
||||||
|
#include "hid-ids.h"
|
||||||
|
|
||||||
#define unk KEY_UNKNOWN
|
#define unk KEY_UNKNOWN
|
||||||
|
|
||||||
static const unsigned char hid_keyboard[256] = {
|
static const unsigned char hid_keyboard[256] = {
|
||||||
|
@ -280,6 +282,28 @@ static enum power_supply_property hidinput_battery_props[] = {
|
||||||
POWER_SUPPLY_PROP_STATUS
|
POWER_SUPPLY_PROP_STATUS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define HID_BATTERY_QUIRK_PERCENT (1 << 0) /* always reports percent */
|
||||||
|
|
||||||
|
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 },
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
static unsigned find_battery_quirk(struct hid_device *hdev)
|
||||||
|
{
|
||||||
|
unsigned quirks = 0;
|
||||||
|
const struct hid_device_id *match;
|
||||||
|
|
||||||
|
match = hid_match_id(hdev, hid_battery_quirks);
|
||||||
|
if (match != NULL)
|
||||||
|
quirks = match->driver_data;
|
||||||
|
|
||||||
|
return quirks;
|
||||||
|
}
|
||||||
|
|
||||||
static int hidinput_get_battery_property(struct power_supply *psy,
|
static int hidinput_get_battery_property(struct power_supply *psy,
|
||||||
enum power_supply_property prop,
|
enum power_supply_property prop,
|
||||||
union power_supply_propval *val)
|
union power_supply_propval *val)
|
||||||
|
@ -304,10 +328,11 @@ static int hidinput_get_battery_property(struct power_supply *psy,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* store the returned value */
|
if (dev->battery_min < dev->battery_max &&
|
||||||
/* I'm not calculating this using the logical_minimum and maximum */
|
buf[1] >= dev->battery_min &&
|
||||||
/* because my device returns 0-100 even though the min and max are 0-255 */
|
buf[1] <= dev->battery_max)
|
||||||
val->intval = buf[1];
|
val->intval = (100 * (buf[1] - dev->battery_min)) /
|
||||||
|
(dev->battery_max - dev->battery_min);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POWER_SUPPLY_PROP_MODEL_NAME:
|
case POWER_SUPPLY_PROP_MODEL_NAME:
|
||||||
|
@ -330,6 +355,7 @@ static void hidinput_setup_battery(struct hid_device *dev, unsigned id, s32 min,
|
||||||
{
|
{
|
||||||
struct power_supply *battery = &dev->battery;
|
struct power_supply *battery = &dev->battery;
|
||||||
int ret;
|
int ret;
|
||||||
|
unsigned quirks;
|
||||||
|
|
||||||
if (battery->name != NULL)
|
if (battery->name != NULL)
|
||||||
return; /* already initialized? */
|
return; /* already initialized? */
|
||||||
|
@ -344,6 +370,13 @@ static void hidinput_setup_battery(struct hid_device *dev, unsigned id, s32 min,
|
||||||
battery->use_for_apm = 0;
|
battery->use_for_apm = 0;
|
||||||
battery->get_property = hidinput_get_battery_property;
|
battery->get_property = hidinput_get_battery_property;
|
||||||
|
|
||||||
|
quirks = find_battery_quirk(dev);
|
||||||
|
|
||||||
|
if (quirks & HID_BATTERY_QUIRK_PERCENT) {
|
||||||
|
min = 0;
|
||||||
|
max = 100;
|
||||||
|
}
|
||||||
|
|
||||||
dev->battery_min = min;
|
dev->battery_min = min;
|
||||||
dev->battery_max = max;
|
dev->battery_max = max;
|
||||||
dev->battery_report_id = id;
|
dev->battery_report_id = id;
|
||||||
|
|
|
@ -735,6 +735,8 @@ int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size);
|
||||||
int hid_check_keys_pressed(struct hid_device *hid);
|
int hid_check_keys_pressed(struct hid_device *hid);
|
||||||
int hid_connect(struct hid_device *hid, unsigned int connect_mask);
|
int hid_connect(struct hid_device *hid, unsigned int connect_mask);
|
||||||
void hid_disconnect(struct hid_device *hid);
|
void hid_disconnect(struct hid_device *hid);
|
||||||
|
const struct hid_device_id *hid_match_id(struct hid_device *hdev,
|
||||||
|
const struct hid_device_id *id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hid_map_usage - map usage input bits
|
* hid_map_usage - map usage input bits
|
||||||
|
|
Reference in a new issue