Commit e6fe3597 authored by Ramakrishna Pallala's avatar Ramakrishna Pallala Committed by Anton Vorontsov

smb347_charger: Cleanup power supply registration code in probe

This patch checks if the usb or mains charging is enabled by the
platform before registering with the power supply class.
Signed-off-by: default avatarRamakrishna Pallala <ramakrishna.pallala@intel.com>
Signed-off-by: default avatarAnton Vorontsov <anton.vorontsov@linaro.org>
parent 2aac3de1
......@@ -816,7 +816,9 @@ static irqreturn_t smb347_interrupt(int irq, void *data)
if (irqstat_e & (IRQSTAT_E_USBIN_UV_IRQ | IRQSTAT_E_DCIN_UV_IRQ)) {
if (smb347_update_status(smb) > 0) {
smb347_update_online(smb);
if (smb->pdata->use_mains)
power_supply_changed(&smb->mains);
if (smb->pdata->use_usb)
power_supply_changed(&smb->usb);
}
ret = IRQ_HANDLED;
......@@ -1185,6 +1187,7 @@ static int smb347_probe(struct i2c_client *client,
if (ret < 0)
return ret;
if (smb->pdata->use_mains) {
smb->mains.name = "smb347-mains";
smb->mains.type = POWER_SUPPLY_TYPE_MAINS;
smb->mains.get_property = smb347_mains_get_property;
......@@ -1192,7 +1195,12 @@ static int smb347_probe(struct i2c_client *client,
smb->mains.num_properties = ARRAY_SIZE(smb347_mains_properties);
smb->mains.supplied_to = battery;
smb->mains.num_supplicants = ARRAY_SIZE(battery);
ret = power_supply_register(dev, &smb->mains);
if (ret < 0)
return ret;
}
if (smb->pdata->use_usb) {
smb->usb.name = "smb347-usb";
smb->usb.type = POWER_SUPPLY_TYPE_USB;
smb->usb.get_property = smb347_usb_get_property;
......@@ -1200,6 +1208,13 @@ static int smb347_probe(struct i2c_client *client,
smb->usb.num_properties = ARRAY_SIZE(smb347_usb_properties);
smb->usb.supplied_to = battery;
smb->usb.num_supplicants = ARRAY_SIZE(battery);
ret = power_supply_register(dev, &smb->usb);
if (ret < 0) {
if (smb->pdata->use_mains)
power_supply_unregister(&smb->mains);
return ret;
}
}
smb->battery.name = "smb347-battery";
smb->battery.type = POWER_SUPPLY_TYPE_BATTERY;
......@@ -1207,19 +1222,12 @@ static int smb347_probe(struct i2c_client *client,
smb->battery.properties = smb347_battery_properties;
smb->battery.num_properties = ARRAY_SIZE(smb347_battery_properties);
ret = power_supply_register(dev, &smb->mains);
if (ret < 0)
return ret;
ret = power_supply_register(dev, &smb->usb);
if (ret < 0) {
power_supply_unregister(&smb->mains);
return ret;
}
ret = power_supply_register(dev, &smb->battery);
if (ret < 0) {
if (smb->pdata->use_usb)
power_supply_unregister(&smb->usb);
if (smb->pdata->use_mains)
power_supply_unregister(&smb->mains);
return ret;
}
......@@ -1255,7 +1263,9 @@ static int smb347_remove(struct i2c_client *client)
}
power_supply_unregister(&smb->battery);
if (smb->pdata->use_usb)
power_supply_unregister(&smb->usb);
if (smb->pdata->use_mains)
power_supply_unregister(&smb->mains);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment