aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorRamakrishna Pallala <ramakrishna.pallala@intel.com>2012-04-19 00:30:18 -0400
committerAnton Vorontsov <anton.vorontsov@linaro.org>2012-05-05 08:29:00 -0400
commite6fe3597fa17dcd7ee82a5198beadb19a457a478 (patch)
tree8f62622cd7be07ab070cac1e37292e2bbeed60ea /drivers
parent2aac3de19b72608f474c90034185c2be4908728f (diff)
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: Ramakrishna Pallala <ramakrishna.pallala@intel.com> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/power/smb347-charger.c70
1 files changed, 40 insertions, 30 deletions
diff --git a/drivers/power/smb347-charger.c b/drivers/power/smb347-charger.c
index ce1694d1a365..3e9df6ef8537 100644
--- a/drivers/power/smb347-charger.c
+++ b/drivers/power/smb347-charger.c
@@ -816,8 +816,10 @@ static irqreturn_t smb347_interrupt(int irq, void *data)
816 if (irqstat_e & (IRQSTAT_E_USBIN_UV_IRQ | IRQSTAT_E_DCIN_UV_IRQ)) { 816 if (irqstat_e & (IRQSTAT_E_USBIN_UV_IRQ | IRQSTAT_E_DCIN_UV_IRQ)) {
817 if (smb347_update_status(smb) > 0) { 817 if (smb347_update_status(smb) > 0) {
818 smb347_update_online(smb); 818 smb347_update_online(smb);
819 power_supply_changed(&smb->mains); 819 if (smb->pdata->use_mains)
820 power_supply_changed(&smb->usb); 820 power_supply_changed(&smb->mains);
821 if (smb->pdata->use_usb)
822 power_supply_changed(&smb->usb);
821 } 823 }
822 ret = IRQ_HANDLED; 824 ret = IRQ_HANDLED;
823 } 825 }
@@ -1185,21 +1187,34 @@ static int smb347_probe(struct i2c_client *client,
1185 if (ret < 0) 1187 if (ret < 0)
1186 return ret; 1188 return ret;
1187 1189
1188 smb->mains.name = "smb347-mains"; 1190 if (smb->pdata->use_mains) {
1189 smb->mains.type = POWER_SUPPLY_TYPE_MAINS; 1191 smb->mains.name = "smb347-mains";
1190 smb->mains.get_property = smb347_mains_get_property; 1192 smb->mains.type = POWER_SUPPLY_TYPE_MAINS;
1191 smb->mains.properties = smb347_mains_properties; 1193 smb->mains.get_property = smb347_mains_get_property;
1192 smb->mains.num_properties = ARRAY_SIZE(smb347_mains_properties); 1194 smb->mains.properties = smb347_mains_properties;
1193 smb->mains.supplied_to = battery; 1195 smb->mains.num_properties = ARRAY_SIZE(smb347_mains_properties);
1194 smb->mains.num_supplicants = ARRAY_SIZE(battery); 1196 smb->mains.supplied_to = battery;
1195 1197 smb->mains.num_supplicants = ARRAY_SIZE(battery);
1196 smb->usb.name = "smb347-usb"; 1198 ret = power_supply_register(dev, &smb->mains);
1197 smb->usb.type = POWER_SUPPLY_TYPE_USB; 1199 if (ret < 0)
1198 smb->usb.get_property = smb347_usb_get_property; 1200 return ret;
1199 smb->usb.properties = smb347_usb_properties; 1201 }
1200 smb->usb.num_properties = ARRAY_SIZE(smb347_usb_properties); 1202
1201 smb->usb.supplied_to = battery; 1203 if (smb->pdata->use_usb) {
1202 smb->usb.num_supplicants = ARRAY_SIZE(battery); 1204 smb->usb.name = "smb347-usb";
1205 smb->usb.type = POWER_SUPPLY_TYPE_USB;
1206 smb->usb.get_property = smb347_usb_get_property;
1207 smb->usb.properties = smb347_usb_properties;
1208 smb->usb.num_properties = ARRAY_SIZE(smb347_usb_properties);
1209 smb->usb.supplied_to = battery;
1210 smb->usb.num_supplicants = ARRAY_SIZE(battery);
1211 ret = power_supply_register(dev, &smb->usb);
1212 if (ret < 0) {
1213 if (smb->pdata->use_mains)
1214 power_supply_unregister(&smb->mains);
1215 return ret;
1216 }
1217 }
1203 1218
1204 smb->battery.name = "smb347-battery"; 1219 smb->battery.name = "smb347-battery";
1205 smb->battery.type = POWER_SUPPLY_TYPE_BATTERY; 1220 smb->battery.type = POWER_SUPPLY_TYPE_BATTERY;
@@ -1207,20 +1222,13 @@ static int smb347_probe(struct i2c_client *client,
1207 smb->battery.properties = smb347_battery_properties; 1222 smb->battery.properties = smb347_battery_properties;
1208 smb->battery.num_properties = ARRAY_SIZE(smb347_battery_properties); 1223 smb->battery.num_properties = ARRAY_SIZE(smb347_battery_properties);
1209 1224
1210 ret = power_supply_register(dev, &smb->mains);
1211 if (ret < 0)
1212 return ret;
1213
1214 ret = power_supply_register(dev, &smb->usb);
1215 if (ret < 0) {
1216 power_supply_unregister(&smb->mains);
1217 return ret;
1218 }
1219 1225
1220 ret = power_supply_register(dev, &smb->battery); 1226 ret = power_supply_register(dev, &smb->battery);
1221 if (ret < 0) { 1227 if (ret < 0) {
1222 power_supply_unregister(&smb->usb); 1228 if (smb->pdata->use_usb)
1223 power_supply_unregister(&smb->mains); 1229 power_supply_unregister(&smb->usb);
1230 if (smb->pdata->use_mains)
1231 power_supply_unregister(&smb->mains);
1224 return ret; 1232 return ret;
1225 } 1233 }
1226 1234
@@ -1255,8 +1263,10 @@ static int smb347_remove(struct i2c_client *client)
1255 } 1263 }
1256 1264
1257 power_supply_unregister(&smb->battery); 1265 power_supply_unregister(&smb->battery);
1258 power_supply_unregister(&smb->usb); 1266 if (smb->pdata->use_usb)
1259 power_supply_unregister(&smb->mains); 1267 power_supply_unregister(&smb->usb);
1268 if (smb->pdata->use_mains)
1269 power_supply_unregister(&smb->mains);
1260 return 0; 1270 return 0;
1261} 1271}
1262 1272