diff options
author | Chris Bagwell <chris@cnpbagwell.com> | 2012-03-26 02:26:30 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-03-26 02:33:17 -0400 |
commit | a1d552cc15b0be9124ccba593f99f59c4ec1e153 (patch) | |
tree | bae307464abfba32dfc3a4c19bbe38c1106746fe /drivers/input | |
parent | 16bf288c4be67b68c3fcb6561ff145702cb7bd22 (diff) |
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>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/tablet/Kconfig | 1 | ||||
-rw-r--r-- | drivers/input/tablet/wacom.h | 2 | ||||
-rw-r--r-- | drivers/input/tablet/wacom_sys.c | 57 | ||||
-rw-r--r-- | drivers/input/tablet/wacom_wac.c | 5 | ||||
-rw-r--r-- | drivers/input/tablet/wacom_wac.h | 1 |
5 files changed, 64 insertions, 2 deletions
diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig index 58a87755b936..0edeb949109b 100644 --- a/drivers/input/tablet/Kconfig +++ b/drivers/input/tablet/Kconfig | |||
@@ -76,6 +76,7 @@ config TABLET_USB_KBTAB | |||
76 | config TABLET_USB_WACOM | 76 | config TABLET_USB_WACOM |
77 | tristate "Wacom Intuos/Graphire tablet support (USB)" | 77 | tristate "Wacom Intuos/Graphire tablet support (USB)" |
78 | depends on USB_ARCH_HAS_HCD | 78 | depends on USB_ARCH_HAS_HCD |
79 | select POWER_SUPPLY | ||
79 | select USB | 80 | select USB |
80 | help | 81 | help |
81 | Say Y here if you want to use the USB version of the Wacom Intuos | 82 | Say Y here if you want to use the USB version of the Wacom Intuos |
diff --git a/drivers/input/tablet/wacom.h b/drivers/input/tablet/wacom.h index febbfd9f3a84..b4842d0e61dd 100644 --- a/drivers/input/tablet/wacom.h +++ b/drivers/input/tablet/wacom.h | |||
@@ -88,6 +88,7 @@ | |||
88 | #include <linux/mod_devicetable.h> | 88 | #include <linux/mod_devicetable.h> |
89 | #include <linux/init.h> | 89 | #include <linux/init.h> |
90 | #include <linux/usb/input.h> | 90 | #include <linux/usb/input.h> |
91 | #include <linux/power_supply.h> | ||
91 | #include <asm/unaligned.h> | 92 | #include <asm/unaligned.h> |
92 | 93 | ||
93 | /* | 94 | /* |
@@ -121,6 +122,7 @@ struct wacom { | |||
121 | u8 hlv; /* status led brightness button pressed (1..127) */ | 122 | u8 hlv; /* status led brightness button pressed (1..127) */ |
122 | u8 img_lum; /* OLED matrix display brightness */ | 123 | u8 img_lum; /* OLED matrix display brightness */ |
123 | } led; | 124 | } led; |
125 | struct power_supply battery; | ||
124 | }; | 126 | }; |
125 | 127 | ||
126 | static inline void wacom_schedule_work(struct wacom_wac *wacom_wac) | 128 | static inline void wacom_schedule_work(struct wacom_wac *wacom_wac) |
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c index 2fc77053960f..19ba58640dc2 100644 --- a/drivers/input/tablet/wacom_sys.c +++ b/drivers/input/tablet/wacom_sys.c | |||
@@ -843,6 +843,55 @@ static void wacom_destroy_leds(struct wacom *wacom) | |||
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 | static int wacom_register_input(struct wacom *wacom) | 895 | static int wacom_register_input(struct wacom *wacom) |
847 | { | 896 | { |
848 | struct input_dev *input_dev; | 897 | struct input_dev *input_dev; |
@@ -1016,10 +1065,14 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i | |||
1016 | if (error) | 1065 | if (error) |
1017 | goto fail4; | 1066 | goto fail4; |
1018 | 1067 | ||
1068 | error = wacom_initialize_battery(wacom); | ||
1069 | if (error) | ||
1070 | goto fail5; | ||
1071 | |||
1019 | if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) { | 1072 | if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) { |
1020 | error = wacom_register_input(wacom); | 1073 | error = wacom_register_input(wacom); |
1021 | if (error) | 1074 | if (error) |
1022 | goto fail5; | 1075 | goto fail6; |
1023 | } | 1076 | } |
1024 | 1077 | ||
1025 | /* Note that if query fails it is not a hard failure */ | 1078 | /* Note that if query fails it is not a hard failure */ |
@@ -1034,6 +1087,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i | |||
1034 | 1087 | ||
1035 | return 0; | 1088 | return 0; |
1036 | 1089 | ||
1090 | fail6: wacom_destroy_battery(wacom); | ||
1037 | fail5: wacom_destroy_leds(wacom); | 1091 | fail5: wacom_destroy_leds(wacom); |
1038 | fail4: wacom_remove_shared_data(wacom_wac); | 1092 | fail4: wacom_remove_shared_data(wacom_wac); |
1039 | fail3: usb_free_urb(wacom->irq); | 1093 | fail3: usb_free_urb(wacom->irq); |
@@ -1052,6 +1106,7 @@ static void wacom_disconnect(struct usb_interface *intf) | |||
1052 | cancel_work_sync(&wacom->work); | 1106 | cancel_work_sync(&wacom->work); |
1053 | if (wacom->wacom_wac.input) | 1107 | if (wacom->wacom_wac.input) |
1054 | input_unregister_device(wacom->wacom_wac.input); | 1108 | input_unregister_device(wacom->wacom_wac.input); |
1109 | wacom_destroy_battery(wacom); | ||
1055 | wacom_destroy_leds(wacom); | 1110 | wacom_destroy_leds(wacom); |
1056 | usb_free_urb(wacom->irq); | 1111 | usb_free_urb(wacom->irq); |
1057 | usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX, | 1112 | usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX, |
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c index fce7a09fb5db..99fb6fed2bf3 100644 --- a/drivers/input/tablet/wacom_wac.c +++ b/drivers/input/tablet/wacom_wac.c | |||
@@ -1054,17 +1054,20 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len) | |||
1054 | 1054 | ||
1055 | connected = data[1] & 0x01; | 1055 | connected = data[1] & 0x01; |
1056 | if (connected) { | 1056 | if (connected) { |
1057 | int pid; | 1057 | int pid, battery; |
1058 | 1058 | ||
1059 | pid = get_unaligned_be16(&data[6]); | 1059 | pid = get_unaligned_be16(&data[6]); |
1060 | battery = data[5] & 0x3f; | ||
1060 | if (wacom->pid != pid) { | 1061 | if (wacom->pid != pid) { |
1061 | wacom->pid = pid; | 1062 | wacom->pid = pid; |
1062 | wacom_schedule_work(wacom); | 1063 | wacom_schedule_work(wacom); |
1063 | } | 1064 | } |
1065 | wacom->battery_capacity = battery; | ||
1064 | } else if (wacom->pid != 0) { | 1066 | } else if (wacom->pid != 0) { |
1065 | /* disconnected while previously connected */ | 1067 | /* disconnected while previously connected */ |
1066 | wacom->pid = 0; | 1068 | wacom->pid = 0; |
1067 | wacom_schedule_work(wacom); | 1069 | wacom_schedule_work(wacom); |
1070 | wacom->battery_capacity = 0; | ||
1068 | } | 1071 | } |
1069 | 1072 | ||
1070 | return 0; | 1073 | return 0; |
diff --git a/drivers/input/tablet/wacom_wac.h b/drivers/input/tablet/wacom_wac.h index cffaf6b7e6e9..ba5a334e54d6 100644 --- a/drivers/input/tablet/wacom_wac.h +++ b/drivers/input/tablet/wacom_wac.h | |||
@@ -112,6 +112,7 @@ struct wacom_wac { | |||
112 | struct wacom_shared *shared; | 112 | struct wacom_shared *shared; |
113 | struct input_dev *input; | 113 | struct input_dev *input; |
114 | int pid; | 114 | int pid; |
115 | int battery_capacity; | ||
115 | }; | 116 | }; |
116 | 117 | ||
117 | #endif | 118 | #endif |