Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: wacom - wireless battery status

Signed-off-by: Chris Bagwell <chris@cnpbagwell.com>
Tested-by: Jason Gerecke <killertofu@gmail.com>
Acked-by: Ping Cheng <pingc@wacom.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

authored by

Chris Bagwell and committed by
Dmitry Torokhov
a1d552cc 16bf288c

+64 -2
+1
drivers/input/tablet/Kconfig
··· 76 76 config TABLET_USB_WACOM 77 77 tristate "Wacom Intuos/Graphire tablet support (USB)" 78 78 depends on USB_ARCH_HAS_HCD 79 + select POWER_SUPPLY 79 80 select USB 80 81 help 81 82 Say Y here if you want to use the USB version of the Wacom Intuos
+2
drivers/input/tablet/wacom.h
··· 88 88 #include <linux/mod_devicetable.h> 89 89 #include <linux/init.h> 90 90 #include <linux/usb/input.h> 91 + #include <linux/power_supply.h> 91 92 #include <asm/unaligned.h> 92 93 93 94 /* ··· 122 121 u8 hlv; /* status led brightness button pressed (1..127) */ 123 122 u8 img_lum; /* OLED matrix display brightness */ 124 123 } led; 124 + struct power_supply battery; 125 125 }; 126 126 127 127 static inline void wacom_schedule_work(struct wacom_wac *wacom_wac)
+56 -1
drivers/input/tablet/wacom_sys.c
··· 843 843 } 844 844 } 845 845 846 + static enum power_supply_property wacom_battery_props[] = { 847 + POWER_SUPPLY_PROP_CAPACITY 848 + }; 849 + 850 + static int wacom_battery_get_property(struct power_supply *psy, 851 + enum power_supply_property psp, 852 + union power_supply_propval *val) 853 + { 854 + struct wacom *wacom = container_of(psy, struct wacom, battery); 855 + int ret = 0; 856 + 857 + switch (psp) { 858 + case POWER_SUPPLY_PROP_CAPACITY: 859 + val->intval = 860 + wacom->wacom_wac.battery_capacity * 100 / 31; 861 + break; 862 + default: 863 + ret = -EINVAL; 864 + break; 865 + } 866 + 867 + return ret; 868 + } 869 + 870 + static int wacom_initialize_battery(struct wacom *wacom) 871 + { 872 + int error = 0; 873 + 874 + if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) { 875 + wacom->battery.properties = wacom_battery_props; 876 + wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props); 877 + wacom->battery.get_property = wacom_battery_get_property; 878 + wacom->battery.name = "wacom_battery"; 879 + wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY; 880 + wacom->battery.use_for_apm = 0; 881 + 882 + error = power_supply_register(&wacom->usbdev->dev, 883 + &wacom->battery); 884 + } 885 + 886 + return error; 887 + } 888 + 889 + static void wacom_destroy_battery(struct wacom *wacom) 890 + { 891 + if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) 892 + power_supply_unregister(&wacom->battery); 893 + } 894 + 846 895 static int wacom_register_input(struct wacom *wacom) 847 896 { 848 897 struct input_dev *input_dev; ··· 1065 1016 if (error) 1066 1017 goto fail4; 1067 1018 1019 + error = wacom_initialize_battery(wacom); 1020 + if (error) 1021 + goto fail5; 1022 + 1068 1023 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) { 1069 1024 error = wacom_register_input(wacom); 1070 1025 if (error) 1071 - goto fail5; 1026 + goto fail6; 1072 1027 } 1073 1028 1074 1029 /* Note that if query fails it is not a hard failure */ ··· 1087 1034 1088 1035 return 0; 1089 1036 1037 + fail6: wacom_destroy_battery(wacom); 1090 1038 fail5: wacom_destroy_leds(wacom); 1091 1039 fail4: wacom_remove_shared_data(wacom_wac); 1092 1040 fail3: usb_free_urb(wacom->irq); ··· 1106 1052 cancel_work_sync(&wacom->work); 1107 1053 if (wacom->wacom_wac.input) 1108 1054 input_unregister_device(wacom->wacom_wac.input); 1055 + wacom_destroy_battery(wacom); 1109 1056 wacom_destroy_leds(wacom); 1110 1057 usb_free_urb(wacom->irq); 1111 1058 usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
+4 -1
drivers/input/tablet/wacom_wac.c
··· 1054 1054 1055 1055 connected = data[1] & 0x01; 1056 1056 if (connected) { 1057 - int pid; 1057 + int pid, battery; 1058 1058 1059 1059 pid = get_unaligned_be16(&data[6]); 1060 + battery = data[5] & 0x3f; 1060 1061 if (wacom->pid != pid) { 1061 1062 wacom->pid = pid; 1062 1063 wacom_schedule_work(wacom); 1063 1064 } 1065 + wacom->battery_capacity = battery; 1064 1066 } else if (wacom->pid != 0) { 1065 1067 /* disconnected while previously connected */ 1066 1068 wacom->pid = 0; 1067 1069 wacom_schedule_work(wacom); 1070 + wacom->battery_capacity = 0; 1068 1071 } 1069 1072 1070 1073 return 0;
+1
drivers/input/tablet/wacom_wac.h
··· 112 112 struct wacom_shared *shared; 113 113 struct input_dev *input; 114 114 int pid; 115 + int battery_capacity; 115 116 }; 116 117 117 118 #endif