aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/wacom_wac.c
diff options
context:
space:
mode:
authorJason Gerecke <killertofu@gmail.com>2015-03-06 14:47:39 -0500
committerJiri Kosina <jkosina@suse.cz>2015-03-11 11:46:11 -0400
commit953f2c5f716305a5c2ebea935f410ee7aa439159 (patch)
tree02bae448ca0617d4d8cb471b11256eb976cfd95a /drivers/hid/wacom_wac.c
parent4ca4ec71c84e4ede2b34d2dcf49e7935c735ad6c (diff)
HID: wacom: Centralize updating of wacom_wac battery status
Has the 'wacom_notify_battery' function take on the job of detecting if updating the power supply is necessary to remove multiple nearly-identical 'if' blocks. Signed-off-by: Jason Gerecke <killertofu@gmail.com> Acked-by: Ping Cheng <pingc@wacom.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/wacom_wac.c')
-rw-r--r--drivers/hid/wacom_wac.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index cb308c5f441a..5d57fec177a8 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -45,6 +45,24 @@ static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
45 */ 45 */
46static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 }; 46static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
47 47
48static void wacom_notify_battery(struct wacom_wac *wacom_wac,
49 int bat_capacity, bool bat_charging, bool ps_connected)
50{
51 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
52 bool changed = wacom_wac->battery_capacity != bat_capacity ||
53 wacom_wac->bat_charging != bat_charging ||
54 wacom_wac->ps_connected != ps_connected;
55
56 if (changed) {
57 wacom_wac->battery_capacity = bat_capacity;
58 wacom_wac->bat_charging = bat_charging;
59 wacom_wac->ps_connected = ps_connected;
60
61 if (wacom->battery.dev)
62 power_supply_changed(&wacom->battery);
63 }
64}
65
48static int wacom_penpartner_irq(struct wacom_wac *wacom) 66static int wacom_penpartner_irq(struct wacom_wac *wacom)
49{ 67{
50 unsigned char *data = wacom->data; 68 unsigned char *data = wacom->data;
@@ -419,12 +437,8 @@ static int wacom_graphire_irq(struct wacom_wac *wacom)
419 rw = (data[7] >> 2 & 0x07); 437 rw = (data[7] >> 2 & 0x07);
420 battery_capacity = batcap_gr[rw]; 438 battery_capacity = batcap_gr[rw];
421 ps_connected = rw == 7; 439 ps_connected = rw == 7;
422 if ((wacom->battery_capacity != battery_capacity) || 440 wacom_notify_battery(wacom, battery_capacity, ps_connected,
423 (wacom->ps_connected != ps_connected)) { 441 ps_connected);
424 wacom->battery_capacity = battery_capacity;
425 wacom->ps_connected = ps_connected;
426 wacom_notify_battery(wacom);
427 }
428 } 442 }
429exit: 443exit:
430 return retval; 444 return retval;
@@ -1014,15 +1028,8 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
1014 bat_charging = (power_raw & 0x08) ? 1 : 0; 1028 bat_charging = (power_raw & 0x08) ? 1 : 0;
1015 ps_connected = (power_raw & 0x10) ? 1 : 0; 1029 ps_connected = (power_raw & 0x10) ? 1 : 0;
1016 battery_capacity = batcap_i4[power_raw & 0x07]; 1030 battery_capacity = batcap_i4[power_raw & 0x07];
1017 if ((wacom->battery_capacity != battery_capacity) || 1031 wacom_notify_battery(wacom, battery_capacity, bat_charging,
1018 (wacom->bat_charging != bat_charging) || 1032 ps_connected);
1019 (wacom->ps_connected != ps_connected)) {
1020 wacom->battery_capacity = battery_capacity;
1021 wacom->bat_charging = bat_charging;
1022 wacom->ps_connected = ps_connected;
1023 wacom_notify_battery(wacom);
1024 }
1025
1026 break; 1033 break;
1027 default: 1034 default:
1028 dev_dbg(wacom->input->dev.parent, 1035 dev_dbg(wacom->input->dev.parent,
@@ -1910,7 +1917,7 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
1910 1917
1911 connected = data[1] & 0x01; 1918 connected = data[1] & 0x01;
1912 if (connected) { 1919 if (connected) {
1913 int pid, battery, ps_connected; 1920 int pid, battery, ps_connected, charging;
1914 1921
1915 if ((wacom->shared->type == INTUOSHT) && 1922 if ((wacom->shared->type == INTUOSHT) &&
1916 wacom->shared->touch_input && 1923 wacom->shared->touch_input &&
@@ -1923,27 +1930,21 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
1923 pid = get_unaligned_be16(&data[6]); 1930 pid = get_unaligned_be16(&data[6]);
1924 battery = (data[5] & 0x3f) * 100 / 31; 1931 battery = (data[5] & 0x3f) * 100 / 31;
1925 ps_connected = !!(data[5] & 0x80); 1932 ps_connected = !!(data[5] & 0x80);
1933 charging = ps_connected && wacom->battery_capacity < 100;
1926 if (wacom->pid != pid) { 1934 if (wacom->pid != pid) {
1927 wacom->pid = pid; 1935 wacom->pid = pid;
1928 wacom_schedule_work(wacom); 1936 wacom_schedule_work(wacom);
1929 } 1937 }
1930 1938
1931 if (wacom->shared->type && 1939 if (wacom->shared->type)
1932 (battery != wacom->battery_capacity || 1940 wacom_notify_battery(wacom, battery, charging,
1933 ps_connected != wacom->ps_connected)) { 1941 ps_connected);
1934 wacom->battery_capacity = battery; 1942
1935 wacom->ps_connected = ps_connected;
1936 wacom->bat_charging = ps_connected &&
1937 wacom->battery_capacity < 100;
1938 wacom_notify_battery(wacom);
1939 }
1940 } else if (wacom->pid != 0) { 1943 } else if (wacom->pid != 0) {
1941 /* disconnected while previously connected */ 1944 /* disconnected while previously connected */
1942 wacom->pid = 0; 1945 wacom->pid = 0;
1943 wacom_schedule_work(wacom); 1946 wacom_schedule_work(wacom);
1944 wacom->battery_capacity = 0; 1947 wacom_notify_battery(wacom, 0, 0, 0);
1945 wacom->bat_charging = 0;
1946 wacom->ps_connected = 0;
1947 } 1948 }
1948 1949
1949 return 0; 1950 return 0;