Skip to content

Commit 71fa641

Browse files
jigpuJiri Kosina
authored andcommitted
HID: wacom: Add battery presence indicator to wireless tablets
Declare the POWER_SUPPLY_PROP_PRESENT property to provide userspace with a way to determine if the battery on a wireless tablet is plugged in. Although current wireless tablets do not explicitly report this information, it can be inferred from other state information. In particular, a battery is assumed to be present if any of the following are true: a non-zero battery level reported, the battery is reported as charging, or the tablet is operating wirelessly. Note: The last condition above may not strictly hold for the Graphire Wireless (it charges from a DC barrel jack instead of a USB port), but I do not know what is reported in the no-battery condition. Signed-off-by: Jason Gerecke <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 8fac172 commit 71fa641

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

drivers/hid/wacom_sys.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ static void wacom_destroy_leds(struct wacom *wacom)
945945
}
946946

947947
static enum power_supply_property wacom_battery_props[] = {
948+
POWER_SUPPLY_PROP_PRESENT,
948949
POWER_SUPPLY_PROP_STATUS,
949950
POWER_SUPPLY_PROP_SCOPE,
950951
POWER_SUPPLY_PROP_CAPACITY
@@ -964,6 +965,9 @@ static int wacom_battery_get_property(struct power_supply *psy,
964965
int ret = 0;
965966

966967
switch (psp) {
968+
case POWER_SUPPLY_PROP_PRESENT:
969+
val->intval = wacom->wacom_wac.bat_connected;
970+
break;
967971
case POWER_SUPPLY_PROP_SCOPE:
968972
val->intval = POWER_SUPPLY_SCOPE_DEVICE;
969973
break;

drivers/hid/wacom_wac.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,19 @@ static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
4646
static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
4747

4848
static void wacom_notify_battery(struct wacom_wac *wacom_wac,
49-
int bat_capacity, bool bat_charging, bool ps_connected)
49+
int bat_capacity, bool bat_charging, bool bat_connected,
50+
bool ps_connected)
5051
{
5152
struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
5253
bool changed = wacom_wac->battery_capacity != bat_capacity ||
5354
wacom_wac->bat_charging != bat_charging ||
55+
wacom_wac->bat_connected != bat_connected ||
5456
wacom_wac->ps_connected != ps_connected;
5557

5658
if (changed) {
5759
wacom_wac->battery_capacity = bat_capacity;
5860
wacom_wac->bat_charging = bat_charging;
61+
wacom_wac->bat_connected = bat_connected;
5962
wacom_wac->ps_connected = ps_connected;
6063

6164
if (wacom->battery.dev)
@@ -438,7 +441,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom)
438441
battery_capacity = batcap_gr[rw];
439442
ps_connected = rw == 7;
440443
wacom_notify_battery(wacom, battery_capacity, ps_connected,
441-
ps_connected);
444+
1, ps_connected);
442445
}
443446
exit:
444447
return retval;
@@ -1029,6 +1032,7 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
10291032
ps_connected = (power_raw & 0x10) ? 1 : 0;
10301033
battery_capacity = batcap_i4[power_raw & 0x07];
10311034
wacom_notify_battery(wacom, battery_capacity, bat_charging,
1035+
battery_capacity || bat_charging,
10321036
ps_connected);
10331037
break;
10341038
default:
@@ -1936,13 +1940,13 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
19361940
}
19371941

19381942
if (wacom->shared->type)
1939-
wacom_notify_battery(wacom, battery, charging, 0);
1943+
wacom_notify_battery(wacom, battery, charging, 1, 0);
19401944

19411945
} else if (wacom->pid != 0) {
19421946
/* disconnected while previously connected */
19431947
wacom->pid = 0;
19441948
wacom_schedule_work(wacom);
1945-
wacom_notify_battery(wacom, 0, 0, 0);
1949+
wacom_notify_battery(wacom, 0, 0, 0, 0);
19461950
}
19471951

19481952
return 0;
@@ -1970,7 +1974,7 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
19701974
bool charging = !!(data[8] & 0x80);
19711975

19721976
wacom_notify_battery(wacom_wac, battery, charging,
1973-
1);
1977+
battery || charging, 1);
19741978

19751979
if (!wacom->battery.dev &&
19761980
!(features->quirks & WACOM_QUIRK_BATTERY)) {
@@ -1984,7 +1988,7 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
19841988
features->quirks &= ~WACOM_QUIRK_BATTERY;
19851989
INIT_WORK(&wacom->work, wacom_battery_work);
19861990
wacom_schedule_work(wacom_wac);
1987-
wacom_notify_battery(wacom_wac, 0, 0, 0);
1991+
wacom_notify_battery(wacom_wac, 0, 0, 0, 0);
19881992
}
19891993
return 0;
19901994
}

drivers/hid/wacom_wac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ struct wacom_wac {
212212
int battery_capacity;
213213
int num_contacts_left;
214214
int bat_charging;
215+
int bat_connected;
215216
int ps_connected;
216217
u8 bt_features;
217218
u8 bt_high_speed;

0 commit comments

Comments
 (0)