diff options
author | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2016-07-13 18:06:08 +0200 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2016-08-05 13:39:18 +0200 |
commit | 59d69bc8215478af6b89d4ae9ab0baf6d91eb870 (patch) | |
tree | 704ecbae967c3914376213d83376d17fcd96979f /drivers/hid/wacom_sys.c | |
parent | 7c35dc3cd4d114019ed4b26cab313e253396d7c9 (diff) | |
download | linux-59d69bc8215478af6b89d4ae9ab0baf6d91eb870.tar.gz linux-59d69bc8215478af6b89d4ae9ab0baf6d91eb870.tar.bz2 linux-59d69bc8215478af6b89d4ae9ab0baf6d91eb870.zip |
HID: wacom: EKR: have one power_supply per remote
Previously, all the remotes attached to the same receiver would share the
same power_supply. That's not good as the remotes will constantly change
the battery information according to their own state.
To have something generic enough, we introduce struct wacom_battery
which regroups all the information we need for a battery.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Acked-by: Ping Cheng <pingc@wacom.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/wacom_sys.c')
-rw-r--r-- | drivers/hid/wacom_sys.c | 123 |
1 files changed, 67 insertions, 56 deletions
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index f2f5b4b248cb..04f5c753c868 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -1101,27 +1101,26 @@ static int wacom_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { - struct wacom *wacom = power_supply_get_drvdata(psy); + struct wacom_battery *battery = power_supply_get_drvdata(psy); int ret = 0; switch (psp) { case POWER_SUPPLY_PROP_PRESENT: - val->intval = wacom->wacom_wac.bat_connected; + val->intval = battery->bat_connected; break; case POWER_SUPPLY_PROP_SCOPE: val->intval = POWER_SUPPLY_SCOPE_DEVICE; break; case POWER_SUPPLY_PROP_CAPACITY: - val->intval = - wacom->wacom_wac.battery_capacity; + val->intval = battery->battery_capacity; break; case POWER_SUPPLY_PROP_STATUS: - if (wacom->wacom_wac.bat_charging) + if (battery->bat_charging) val->intval = POWER_SUPPLY_STATUS_CHARGING; - else if (wacom->wacom_wac.battery_capacity == 100 && - wacom->wacom_wac.ps_connected) + else if (battery->battery_capacity == 100 && + battery->ps_connected) val->intval = POWER_SUPPLY_STATUS_FULL; - else if (wacom->wacom_wac.ps_connected) + else if (battery->ps_connected) val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; else val->intval = POWER_SUPPLY_STATUS_DISCHARGING; @@ -1138,14 +1137,14 @@ static int wacom_ac_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { - struct wacom *wacom = power_supply_get_drvdata(psy); + struct wacom_battery *battery = power_supply_get_drvdata(psy); int ret = 0; switch (psp) { case POWER_SUPPLY_PROP_PRESENT: /* fall through */ case POWER_SUPPLY_PROP_ONLINE: - val->intval = wacom->wacom_wac.ps_connected; + val->intval = battery->ps_connected; break; case POWER_SUPPLY_PROP_SCOPE: val->intval = POWER_SUPPLY_SCOPE_DEVICE; @@ -1157,58 +1156,56 @@ static int wacom_ac_get_property(struct power_supply *psy, return ret; } -static int wacom_initialize_battery(struct wacom *wacom) +static int __wacom_initialize_battery(struct wacom *wacom, + struct wacom_battery *battery) { static atomic_t battery_no = ATOMIC_INIT(0); struct device *dev = &wacom->hdev->dev; - struct power_supply_config psy_cfg = { .drv_data = wacom, }; - struct power_supply_desc *bat_desc = &wacom->battery_desc; + struct power_supply_config psy_cfg = { .drv_data = battery, }; + struct power_supply *ps_bat, *ps_ac; + struct power_supply_desc *bat_desc = &battery->bat_desc; + struct power_supply_desc *ac_desc = &battery->ac_desc; unsigned long n; int error; if (!devres_open_group(dev, bat_desc, GFP_KERNEL)) return -ENOMEM; - if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) { - struct power_supply_desc *ac_desc = &wacom->ac_desc; - n = atomic_inc_return(&battery_no) - 1; - - bat_desc->properties = wacom_battery_props; - bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props); - bat_desc->get_property = wacom_battery_get_property; - sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n); - bat_desc->name = wacom->wacom_wac.bat_name; - bat_desc->type = POWER_SUPPLY_TYPE_BATTERY; - bat_desc->use_for_apm = 0; - - ac_desc->properties = wacom_ac_props; - ac_desc->num_properties = ARRAY_SIZE(wacom_ac_props); - ac_desc->get_property = wacom_ac_get_property; - sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n); - ac_desc->name = wacom->wacom_wac.ac_name; - ac_desc->type = POWER_SUPPLY_TYPE_MAINS; - ac_desc->use_for_apm = 0; - - wacom->battery = devm_power_supply_register(dev, - &wacom->battery_desc, - &psy_cfg); - if (IS_ERR(wacom->battery)) { - error = PTR_ERR(wacom->battery); - goto err; - } + n = atomic_inc_return(&battery_no) - 1; + + bat_desc->properties = wacom_battery_props; + bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props); + bat_desc->get_property = wacom_battery_get_property; + sprintf(battery->bat_name, "wacom_battery_%ld", n); + bat_desc->name = battery->bat_name; + bat_desc->type = POWER_SUPPLY_TYPE_BATTERY; + bat_desc->use_for_apm = 0; + + ac_desc->properties = wacom_ac_props; + ac_desc->num_properties = ARRAY_SIZE(wacom_ac_props); + ac_desc->get_property = wacom_ac_get_property; + sprintf(battery->ac_name, "wacom_ac_%ld", n); + ac_desc->name = battery->ac_name; + ac_desc->type = POWER_SUPPLY_TYPE_MAINS; + ac_desc->use_for_apm = 0; + + ps_bat = devm_power_supply_register(dev, bat_desc, &psy_cfg); + if (IS_ERR(ps_bat)) { + error = PTR_ERR(ps_bat); + goto err; + } - power_supply_powers(wacom->battery, &wacom->hdev->dev); + ps_ac = devm_power_supply_register(dev, ac_desc, &psy_cfg); + if (IS_ERR(ps_ac)) { + error = PTR_ERR(ps_ac); + goto err; + } - wacom->ac = devm_power_supply_register(dev, - &wacom->ac_desc, - &psy_cfg); - if (IS_ERR(wacom->ac)) { - error = PTR_ERR(wacom->ac); - goto err; - } + power_supply_powers(ps_bat, &wacom->hdev->dev); + power_supply_powers(ps_ac, &wacom->hdev->dev); - power_supply_powers(wacom->ac, &wacom->hdev->dev); - } + battery->battery = ps_bat; + battery->ac = ps_ac; devres_close_group(dev, bat_desc); return 0; @@ -1218,12 +1215,21 @@ err: return error; } +static int wacom_initialize_battery(struct wacom *wacom) +{ + if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) + return __wacom_initialize_battery(wacom, &wacom->battery); + + return 0; +} + static void wacom_destroy_battery(struct wacom *wacom) { - if (wacom->battery) { - devres_release_group(&wacom->hdev->dev, &wacom->battery_desc); - wacom->battery = NULL; - wacom->ac = NULL; + if (wacom->battery.battery) { + devres_release_group(&wacom->hdev->dev, + &wacom->battery.bat_desc); + wacom->battery.battery = NULL; + wacom->battery.ac = NULL; } } @@ -1593,11 +1599,11 @@ void wacom_battery_work(struct work_struct *work) struct wacom *wacom = container_of(work, struct wacom, battery_work); if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && - !wacom->battery) { + !wacom->battery.battery) { wacom_initialize_battery(wacom); } else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && - wacom->battery) { + wacom->battery.battery) { wacom_destroy_battery(wacom); } } @@ -1976,6 +1982,11 @@ static int wacom_remote_create_one(struct wacom *wacom, u32 serial, if (error) goto fail; + error = __wacom_initialize_battery(wacom, + &remote->remotes[index].battery); + if (error) + goto fail; + remote->remotes[index].registered = true; devres_close_group(dev, &remote->remotes[index]); |