diff options
author | Jason Gerecke <killertofu@gmail.com> | 2015-03-11 13:25:41 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2015-03-11 13:50:04 -0400 |
commit | 71fa641ebbfd2402bdb76d3c6ba7e4a2d1eb2dfc (patch) | |
tree | 98f85a9921254a670904652bdf10205a5b1a149a /drivers/hid | |
parent | 8fac1722140019d6a53f7b280f8b785707a16f66 (diff) |
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 <killertofu@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/wacom_sys.c | 4 | ||||
-rw-r--r-- | drivers/hid/wacom_wac.c | 16 | ||||
-rw-r--r-- | drivers/hid/wacom_wac.h | 1 |
3 files changed, 15 insertions, 6 deletions
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 955ce7ceda89..ab7bf84c1ca7 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c | |||
@@ -945,6 +945,7 @@ static void wacom_destroy_leds(struct wacom *wacom) | |||
945 | } | 945 | } |
946 | 946 | ||
947 | static enum power_supply_property wacom_battery_props[] = { | 947 | static enum power_supply_property wacom_battery_props[] = { |
948 | POWER_SUPPLY_PROP_PRESENT, | ||
948 | POWER_SUPPLY_PROP_STATUS, | 949 | POWER_SUPPLY_PROP_STATUS, |
949 | POWER_SUPPLY_PROP_SCOPE, | 950 | POWER_SUPPLY_PROP_SCOPE, |
950 | POWER_SUPPLY_PROP_CAPACITY | 951 | POWER_SUPPLY_PROP_CAPACITY |
@@ -964,6 +965,9 @@ static int wacom_battery_get_property(struct power_supply *psy, | |||
964 | int ret = 0; | 965 | int ret = 0; |
965 | 966 | ||
966 | switch (psp) { | 967 | switch (psp) { |
968 | case POWER_SUPPLY_PROP_PRESENT: | ||
969 | val->intval = wacom->wacom_wac.bat_connected; | ||
970 | break; | ||
967 | case POWER_SUPPLY_PROP_SCOPE: | 971 | case POWER_SUPPLY_PROP_SCOPE: |
968 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; | 972 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
969 | break; | 973 | break; |
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 57faf5b68b3d..92626228d7b5 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c | |||
@@ -46,16 +46,19 @@ static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 }; | |||
46 | static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 }; | 46 | static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 }; |
47 | 47 | ||
48 | static void wacom_notify_battery(struct wacom_wac *wacom_wac, | 48 | 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) | ||
50 | { | 51 | { |
51 | struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); | 52 | struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); |
52 | bool changed = wacom_wac->battery_capacity != bat_capacity || | 53 | bool changed = wacom_wac->battery_capacity != bat_capacity || |
53 | wacom_wac->bat_charging != bat_charging || | 54 | wacom_wac->bat_charging != bat_charging || |
55 | wacom_wac->bat_connected != bat_connected || | ||
54 | wacom_wac->ps_connected != ps_connected; | 56 | wacom_wac->ps_connected != ps_connected; |
55 | 57 | ||
56 | if (changed) { | 58 | if (changed) { |
57 | wacom_wac->battery_capacity = bat_capacity; | 59 | wacom_wac->battery_capacity = bat_capacity; |
58 | wacom_wac->bat_charging = bat_charging; | 60 | wacom_wac->bat_charging = bat_charging; |
61 | wacom_wac->bat_connected = bat_connected; | ||
59 | wacom_wac->ps_connected = ps_connected; | 62 | wacom_wac->ps_connected = ps_connected; |
60 | 63 | ||
61 | if (wacom->battery.dev) | 64 | if (wacom->battery.dev) |
@@ -438,7 +441,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom) | |||
438 | battery_capacity = batcap_gr[rw]; | 441 | battery_capacity = batcap_gr[rw]; |
439 | ps_connected = rw == 7; | 442 | ps_connected = rw == 7; |
440 | wacom_notify_battery(wacom, battery_capacity, ps_connected, | 443 | wacom_notify_battery(wacom, battery_capacity, ps_connected, |
441 | ps_connected); | 444 | 1, ps_connected); |
442 | } | 445 | } |
443 | exit: | 446 | exit: |
444 | return retval; | 447 | return retval; |
@@ -1029,6 +1032,7 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len) | |||
1029 | ps_connected = (power_raw & 0x10) ? 1 : 0; | 1032 | ps_connected = (power_raw & 0x10) ? 1 : 0; |
1030 | battery_capacity = batcap_i4[power_raw & 0x07]; | 1033 | battery_capacity = batcap_i4[power_raw & 0x07]; |
1031 | wacom_notify_battery(wacom, battery_capacity, bat_charging, | 1034 | wacom_notify_battery(wacom, battery_capacity, bat_charging, |
1035 | battery_capacity || bat_charging, | ||
1032 | ps_connected); | 1036 | ps_connected); |
1033 | break; | 1037 | break; |
1034 | default: | 1038 | default: |
@@ -1936,13 +1940,13 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len) | |||
1936 | } | 1940 | } |
1937 | 1941 | ||
1938 | if (wacom->shared->type) | 1942 | if (wacom->shared->type) |
1939 | wacom_notify_battery(wacom, battery, charging, 0); | 1943 | wacom_notify_battery(wacom, battery, charging, 1, 0); |
1940 | 1944 | ||
1941 | } else if (wacom->pid != 0) { | 1945 | } else if (wacom->pid != 0) { |
1942 | /* disconnected while previously connected */ | 1946 | /* disconnected while previously connected */ |
1943 | wacom->pid = 0; | 1947 | wacom->pid = 0; |
1944 | wacom_schedule_work(wacom); | 1948 | wacom_schedule_work(wacom); |
1945 | wacom_notify_battery(wacom, 0, 0, 0); | 1949 | wacom_notify_battery(wacom, 0, 0, 0, 0); |
1946 | } | 1950 | } |
1947 | 1951 | ||
1948 | return 0; | 1952 | return 0; |
@@ -1970,7 +1974,7 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len) | |||
1970 | bool charging = !!(data[8] & 0x80); | 1974 | bool charging = !!(data[8] & 0x80); |
1971 | 1975 | ||
1972 | wacom_notify_battery(wacom_wac, battery, charging, | 1976 | wacom_notify_battery(wacom_wac, battery, charging, |
1973 | 1); | 1977 | battery || charging, 1); |
1974 | 1978 | ||
1975 | if (!wacom->battery.dev && | 1979 | if (!wacom->battery.dev && |
1976 | !(features->quirks & WACOM_QUIRK_BATTERY)) { | 1980 | !(features->quirks & WACOM_QUIRK_BATTERY)) { |
@@ -1984,7 +1988,7 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len) | |||
1984 | features->quirks &= ~WACOM_QUIRK_BATTERY; | 1988 | features->quirks &= ~WACOM_QUIRK_BATTERY; |
1985 | INIT_WORK(&wacom->work, wacom_battery_work); | 1989 | INIT_WORK(&wacom->work, wacom_battery_work); |
1986 | wacom_schedule_work(wacom_wac); | 1990 | wacom_schedule_work(wacom_wac); |
1987 | wacom_notify_battery(wacom_wac, 0, 0, 0); | 1991 | wacom_notify_battery(wacom_wac, 0, 0, 0, 0); |
1988 | } | 1992 | } |
1989 | return 0; | 1993 | return 0; |
1990 | } | 1994 | } |
diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h index a3d0828ff8b1..1c7d8931f1fa 100644 --- a/drivers/hid/wacom_wac.h +++ b/drivers/hid/wacom_wac.h | |||
@@ -212,6 +212,7 @@ struct wacom_wac { | |||
212 | int battery_capacity; | 212 | int battery_capacity; |
213 | int num_contacts_left; | 213 | int num_contacts_left; |
214 | int bat_charging; | 214 | int bat_charging; |
215 | int bat_connected; | ||
215 | int ps_connected; | 216 | int ps_connected; |
216 | u8 bt_features; | 217 | u8 bt_features; |
217 | u8 bt_high_speed; | 218 | u8 bt_high_speed; |