aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/wacom_sys.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hid/wacom_sys.c')
-rw-r--r--drivers/hid/wacom_sys.c74
1 files changed, 39 insertions, 35 deletions
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 1b00d8d4466c..e8607d096138 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -961,7 +961,7 @@ static int wacom_battery_get_property(struct power_supply *psy,
961 enum power_supply_property psp, 961 enum power_supply_property psp,
962 union power_supply_propval *val) 962 union power_supply_propval *val)
963{ 963{
964 struct wacom *wacom = container_of(psy, struct wacom, battery); 964 struct wacom *wacom = power_supply_get_drvdata(psy);
965 int ret = 0; 965 int ret = 0;
966 966
967 switch (psp) { 967 switch (psp) {
@@ -998,7 +998,7 @@ static int wacom_ac_get_property(struct power_supply *psy,
998 enum power_supply_property psp, 998 enum power_supply_property psp,
999 union power_supply_propval *val) 999 union power_supply_propval *val)
1000{ 1000{
1001 struct wacom *wacom = container_of(psy, struct wacom, ac); 1001 struct wacom *wacom = power_supply_get_drvdata(psy);
1002 int ret = 0; 1002 int ret = 0;
1003 1003
1004 switch (psp) { 1004 switch (psp) {
@@ -1020,42 +1020,46 @@ static int wacom_ac_get_property(struct power_supply *psy,
1020static int wacom_initialize_battery(struct wacom *wacom) 1020static int wacom_initialize_battery(struct wacom *wacom)
1021{ 1021{
1022 static atomic_t battery_no = ATOMIC_INIT(0); 1022 static atomic_t battery_no = ATOMIC_INIT(0);
1023 int error; 1023 struct power_supply_config psy_cfg = { .drv_data = wacom, };
1024 unsigned long n; 1024 unsigned long n;
1025 1025
1026 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) { 1026 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) {
1027 struct power_supply_desc *bat_desc = &wacom->battery_desc;
1028 struct power_supply_desc *ac_desc = &wacom->ac_desc;
1027 n = atomic_inc_return(&battery_no) - 1; 1029 n = atomic_inc_return(&battery_no) - 1;
1028 1030
1029 wacom->battery.properties = wacom_battery_props; 1031 bat_desc->properties = wacom_battery_props;
1030 wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props); 1032 bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);
1031 wacom->battery.get_property = wacom_battery_get_property; 1033 bat_desc->get_property = wacom_battery_get_property;
1032 sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n); 1034 sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n);
1033 wacom->battery.name = wacom->wacom_wac.bat_name; 1035 bat_desc->name = wacom->wacom_wac.bat_name;
1034 wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY; 1036 bat_desc->type = POWER_SUPPLY_TYPE_BATTERY;
1035 wacom->battery.use_for_apm = 0; 1037 bat_desc->use_for_apm = 0;
1036 1038
1037 wacom->ac.properties = wacom_ac_props; 1039 ac_desc->properties = wacom_ac_props;
1038 wacom->ac.num_properties = ARRAY_SIZE(wacom_ac_props); 1040 ac_desc->num_properties = ARRAY_SIZE(wacom_ac_props);
1039 wacom->ac.get_property = wacom_ac_get_property; 1041 ac_desc->get_property = wacom_ac_get_property;
1040 sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n); 1042 sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n);
1041 wacom->ac.name = wacom->wacom_wac.ac_name; 1043 ac_desc->name = wacom->wacom_wac.ac_name;
1042 wacom->ac.type = POWER_SUPPLY_TYPE_MAINS; 1044 ac_desc->type = POWER_SUPPLY_TYPE_MAINS;
1043 wacom->ac.use_for_apm = 0; 1045 ac_desc->use_for_apm = 0;
1044 1046
1045 error = power_supply_register(&wacom->hdev->dev, 1047 wacom->battery = power_supply_register(&wacom->hdev->dev,
1046 &wacom->battery); 1048 &wacom->battery_desc, &psy_cfg);
1047 if (error) 1049 if (IS_ERR(wacom->battery))
1048 return error; 1050 return PTR_ERR(wacom->battery);
1049 1051
1050 power_supply_powers(&wacom->battery, &wacom->hdev->dev); 1052 power_supply_powers(wacom->battery, &wacom->hdev->dev);
1051 1053
1052 error = power_supply_register(&wacom->hdev->dev, &wacom->ac); 1054 wacom->ac = power_supply_register(&wacom->hdev->dev,
1053 if (error) { 1055 &wacom->ac_desc,
1054 power_supply_unregister(&wacom->battery); 1056 &psy_cfg);
1055 return error; 1057 if (IS_ERR(wacom->ac)) {
1058 power_supply_unregister(wacom->battery);
1059 return PTR_ERR(wacom->ac);
1056 } 1060 }
1057 1061
1058 power_supply_powers(&wacom->ac, &wacom->hdev->dev); 1062 power_supply_powers(wacom->ac, &wacom->hdev->dev);
1059 } 1063 }
1060 1064
1061 return 0; 1065 return 0;
@@ -1063,11 +1067,11 @@ static int wacom_initialize_battery(struct wacom *wacom)
1063 1067
1064static void wacom_destroy_battery(struct wacom *wacom) 1068static void wacom_destroy_battery(struct wacom *wacom)
1065{ 1069{
1066 if (wacom->battery.dev) { 1070 if (wacom->battery) {
1067 power_supply_unregister(&wacom->battery); 1071 power_supply_unregister(wacom->battery);
1068 wacom->battery.dev = NULL; 1072 wacom->battery = NULL;
1069 power_supply_unregister(&wacom->ac); 1073 power_supply_unregister(wacom->ac);
1070 wacom->ac.dev = NULL; 1074 wacom->ac = NULL;
1071 } 1075 }
1072} 1076}
1073 1077
@@ -1339,11 +1343,11 @@ void wacom_battery_work(struct work_struct *work)
1339 struct wacom *wacom = container_of(work, struct wacom, work); 1343 struct wacom *wacom = container_of(work, struct wacom, work);
1340 1344
1341 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && 1345 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
1342 !wacom->battery.dev) { 1346 !wacom->battery) {
1343 wacom_initialize_battery(wacom); 1347 wacom_initialize_battery(wacom);
1344 } 1348 }
1345 else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && 1349 else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
1346 wacom->battery.dev) { 1350 wacom->battery) {
1347 wacom_destroy_battery(wacom); 1351 wacom_destroy_battery(wacom);
1348 } 1352 }
1349} 1353}