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

Input: wacom - battery reporting improvements

Do not register battery device until connected to a tablet.
This prevents an empty battery icon from being shown when tablet is
connected using USB cable.

Also, call power_supply_powers() for apps that can make use of that
info.

And stop ignoring input registration failures.

Signed-off-by: Chris Bagwell <chris@cnpbagwell.com>
Reviewed-by: Ping Cheng <pingc@wacom.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

authored by

Chris Bagwell and committed by
Dmitry Torokhov
b7af2bb8 ac173837

+53 -29
+53 -29
drivers/input/tablet/wacom_sys.c
··· 963 963 964 964 error = power_supply_register(&wacom->usbdev->dev, 965 965 &wacom->battery); 966 + 967 + if (!error) 968 + power_supply_powers(&wacom->battery, 969 + &wacom->usbdev->dev); 966 970 } 967 971 968 972 return error; ··· 974 970 975 971 static void wacom_destroy_battery(struct wacom *wacom) 976 972 { 977 - if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) 973 + if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR && 974 + wacom->battery.dev) { 978 975 power_supply_unregister(&wacom->battery); 976 + wacom->battery.dev = NULL; 977 + } 979 978 } 980 979 981 980 static int wacom_register_input(struct wacom *wacom) ··· 1025 1018 struct wacom *wacom = container_of(work, struct wacom, work); 1026 1019 struct usb_device *usbdev = wacom->usbdev; 1027 1020 struct wacom_wac *wacom_wac = &wacom->wacom_wac; 1021 + struct wacom *wacom1, *wacom2; 1022 + struct wacom_wac *wacom_wac1, *wacom_wac2; 1023 + int error; 1028 1024 1029 1025 /* 1030 1026 * Regardless if this is a disconnect or a new tablet, 1031 - * remove any existing input devices. 1027 + * remove any existing input and battery devices. 1032 1028 */ 1033 1029 1030 + wacom_destroy_battery(wacom); 1031 + 1034 1032 /* Stylus interface */ 1035 - wacom = usb_get_intfdata(usbdev->config->interface[1]); 1036 - if (wacom->wacom_wac.input) 1037 - input_unregister_device(wacom->wacom_wac.input); 1038 - wacom->wacom_wac.input = NULL; 1033 + wacom1 = usb_get_intfdata(usbdev->config->interface[1]); 1034 + wacom_wac1 = &(wacom1->wacom_wac); 1035 + if (wacom_wac1->input) 1036 + input_unregister_device(wacom_wac1->input); 1037 + wacom_wac1->input = NULL; 1039 1038 1040 1039 /* Touch interface */ 1041 - wacom = usb_get_intfdata(usbdev->config->interface[2]); 1042 - if (wacom->wacom_wac.input) 1043 - input_unregister_device(wacom->wacom_wac.input); 1044 - wacom->wacom_wac.input = NULL; 1040 + wacom2 = usb_get_intfdata(usbdev->config->interface[2]); 1041 + wacom_wac2 = &(wacom2->wacom_wac); 1042 + if (wacom_wac2->input) 1043 + input_unregister_device(wacom_wac2->input); 1044 + wacom_wac2->input = NULL; 1045 1045 1046 1046 if (wacom_wac->pid == 0) { 1047 1047 dev_info(&wacom->intf->dev, "wireless tablet disconnected\n"); ··· 1073 1059 } 1074 1060 1075 1061 /* Stylus interface */ 1076 - wacom = usb_get_intfdata(usbdev->config->interface[1]); 1077 - wacom_wac = &wacom->wacom_wac; 1078 - wacom_wac->features = 1062 + wacom_wac1->features = 1079 1063 *((struct wacom_features *)id->driver_info); 1080 - wacom_wac->features.device_type = BTN_TOOL_PEN; 1081 - wacom_register_input(wacom); 1064 + wacom_wac1->features.device_type = BTN_TOOL_PEN; 1065 + error = wacom_register_input(wacom1); 1066 + if (error) 1067 + goto fail1; 1082 1068 1083 1069 /* Touch interface */ 1084 - wacom = usb_get_intfdata(usbdev->config->interface[2]); 1085 - wacom_wac = &wacom->wacom_wac; 1086 - wacom_wac->features = 1070 + wacom_wac2->features = 1087 1071 *((struct wacom_features *)id->driver_info); 1088 - wacom_wac->features.pktlen = WACOM_PKGLEN_BBTOUCH3; 1089 - wacom_wac->features.device_type = BTN_TOOL_FINGER; 1090 - wacom_set_phy_from_res(&wacom_wac->features); 1091 - wacom_wac->features.x_max = wacom_wac->features.y_max = 4096; 1092 - wacom_register_input(wacom); 1072 + wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3; 1073 + wacom_wac2->features.device_type = BTN_TOOL_FINGER; 1074 + wacom_set_phy_from_res(&wacom_wac2->features); 1075 + wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096; 1076 + error = wacom_register_input(wacom2); 1077 + if (error) 1078 + goto fail2; 1079 + 1080 + error = wacom_initialize_battery(wacom); 1081 + if (error) 1082 + goto fail3; 1093 1083 } 1084 + 1085 + return; 1086 + 1087 + fail3: 1088 + input_unregister_device(wacom_wac2->input); 1089 + wacom_wac2->input = NULL; 1090 + fail2: 1091 + input_unregister_device(wacom_wac1->input); 1092 + wacom_wac1->input = NULL; 1093 + fail1: 1094 + return; 1094 1095 } 1095 1096 1096 1097 static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) ··· 1208 1179 if (error) 1209 1180 goto fail4; 1210 1181 1211 - error = wacom_initialize_battery(wacom); 1212 - if (error) 1213 - goto fail5; 1214 - 1215 1182 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) { 1216 1183 error = wacom_register_input(wacom); 1217 1184 if (error) 1218 - goto fail6; 1185 + goto fail5; 1219 1186 } 1220 1187 1221 1188 /* Note that if query fails it is not a hard failure */ ··· 1226 1201 1227 1202 return 0; 1228 1203 1229 - fail6: wacom_destroy_battery(wacom); 1230 1204 fail5: wacom_destroy_leds(wacom); 1231 1205 fail4: wacom_remove_shared_data(wacom_wac); 1232 1206 fail3: usb_free_urb(wacom->irq);