Commit e31e3832 authored by Przemo Firszt's avatar Przemo Firszt Committed by Jiri Kosina

HID: wacom: Refactor battery/ac reporting for Graphire

This patch doesn't change the way battery/ac is reported, but the changes are
required to facilitate battery reporting for Intuos4 WL.
wdata->battery_capacity now stores actual battery capacity as opposed to raw
value reported by wacom graphire previously. Power supply state is now stored
in a separate variable - it used to be calculated on-the-fly in
wacom_ac_get_property function. The raw value has to be stored as well to be
able to determine if it has changed.
Signed-off-by: default avatarPrzemo Firszt <przemo@firszt.eu>
Reviewed-by: default avatarChris Bagwell <chris@cnpbagwell.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 7e551abb
...@@ -39,13 +39,16 @@ struct wacom_data { ...@@ -39,13 +39,16 @@ struct wacom_data {
__u32 id; __u32 id;
__u32 serial; __u32 serial;
unsigned char high_speed; unsigned char high_speed;
int battery_capacity; __u8 battery_capacity;
__u8 power_raw;
__u8 ps_connected;
struct power_supply battery; struct power_supply battery;
struct power_supply ac; struct power_supply ac;
}; };
/*percent of battery capacity, 0 means AC online*/ /*percent of battery capacity for Graphire
static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 }; 8th value means AC online and show 100% capacity */
static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
static enum power_supply_property wacom_battery_props[] = { static enum power_supply_property wacom_battery_props[] = {
POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_PRESENT,
...@@ -65,7 +68,6 @@ static int wacom_battery_get_property(struct power_supply *psy, ...@@ -65,7 +68,6 @@ static int wacom_battery_get_property(struct power_supply *psy,
{ {
struct wacom_data *wdata = container_of(psy, struct wacom_data *wdata = container_of(psy,
struct wacom_data, battery); struct wacom_data, battery);
int power_state = batcap[wdata->battery_capacity];
int ret = 0; int ret = 0;
switch (psp) { switch (psp) {
...@@ -76,11 +78,7 @@ static int wacom_battery_get_property(struct power_supply *psy, ...@@ -76,11 +78,7 @@ static int wacom_battery_get_property(struct power_supply *psy,
val->intval = POWER_SUPPLY_SCOPE_DEVICE; val->intval = POWER_SUPPLY_SCOPE_DEVICE;
break; break;
case POWER_SUPPLY_PROP_CAPACITY: case POWER_SUPPLY_PROP_CAPACITY:
/* show 100% battery capacity when charging */ val->intval = wdata->battery_capacity;
if (power_state == 0)
val->intval = 100;
else
val->intval = power_state;
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -94,17 +92,13 @@ static int wacom_ac_get_property(struct power_supply *psy, ...@@ -94,17 +92,13 @@ static int wacom_ac_get_property(struct power_supply *psy,
union power_supply_propval *val) union power_supply_propval *val)
{ {
struct wacom_data *wdata = container_of(psy, struct wacom_data, ac); struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
int power_state = batcap[wdata->battery_capacity];
int ret = 0; int ret = 0;
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_PRESENT: case POWER_SUPPLY_PROP_PRESENT:
/* fall through */ /* fall through */
case POWER_SUPPLY_PROP_ONLINE: case POWER_SUPPLY_PROP_ONLINE:
if (power_state == 0) val->intval = wdata->ps_connected;
val->intval = 1;
else
val->intval = 0;
break; break;
case POWER_SUPPLY_PROP_SCOPE: case POWER_SUPPLY_PROP_SCOPE:
val->intval = POWER_SUPPLY_SCOPE_DEVICE; val->intval = POWER_SUPPLY_SCOPE_DEVICE;
...@@ -304,10 +298,16 @@ static int wacom_gr_parse_report(struct hid_device *hdev, ...@@ -304,10 +298,16 @@ static int wacom_gr_parse_report(struct hid_device *hdev,
input_sync(input); input_sync(input);
} }
/* Store current battery capacity */ /* Store current battery capacity and power supply state*/
rw = (data[7] >> 2 & 0x07); rw = (data[7] >> 2 & 0x07);
if (rw != wdata->battery_capacity) if (rw != wdata->power_raw) {
wdata->battery_capacity = rw; wdata->power_raw = rw;
wdata->battery_capacity = batcap_gr[rw];
if (rw == 7)
wdata->ps_connected = 1;
else
wdata->ps_connected = 0;
}
return 1; return 1;
} }
......
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