diff options
author | Sean McNeil <sean@mcneil.com> | 2009-11-04 16:24:54 -0500 |
---|---|---|
committer | Anton Vorontsov <cbouatmailru@gmail.com> | 2009-11-15 19:28:06 -0500 |
commit | 7677f33f0a813e98612dce97d5342c1f5046878a (patch) | |
tree | 67272ce97c5eb0aa63bf63c4c4720f6adead4ffe /drivers/power | |
parent | c26964ead57f0aa1dff4926aae2982b174798e7b (diff) |
pcf50633: Add ac power supply class to the charger
This adds an appropriate ac power_supply class and shows usb only when
at the appropriate current limit.
Signed-off-by: Sean McNeil <sean@mcneil.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/pcf50633-charger.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/drivers/power/pcf50633-charger.c b/drivers/power/pcf50633-charger.c index e8b278f71781..48e92c020f4b 100644 --- a/drivers/power/pcf50633-charger.c +++ b/drivers/power/pcf50633-charger.c | |||
@@ -36,6 +36,7 @@ struct pcf50633_mbc { | |||
36 | 36 | ||
37 | struct power_supply usb; | 37 | struct power_supply usb; |
38 | struct power_supply adapter; | 38 | struct power_supply adapter; |
39 | struct power_supply ac; | ||
39 | 40 | ||
40 | struct delayed_work charging_restart_work; | 41 | struct delayed_work charging_restart_work; |
41 | }; | 42 | }; |
@@ -237,6 +238,7 @@ pcf50633_mbc_irq_handler(int irq, void *data) | |||
237 | else if (irq == PCF50633_IRQ_USBLIMOFF) | 238 | else if (irq == PCF50633_IRQ_USBLIMOFF) |
238 | mbc->usb_active = 1; | 239 | mbc->usb_active = 1; |
239 | 240 | ||
241 | power_supply_changed(&mbc->ac); | ||
240 | power_supply_changed(&mbc->usb); | 242 | power_supply_changed(&mbc->usb); |
241 | power_supply_changed(&mbc->adapter); | 243 | power_supply_changed(&mbc->adapter); |
242 | 244 | ||
@@ -269,10 +271,34 @@ static int usb_get_property(struct power_supply *psy, | |||
269 | { | 271 | { |
270 | struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, usb); | 272 | struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, usb); |
271 | int ret = 0; | 273 | int ret = 0; |
274 | u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) & | ||
275 | PCF50633_MBCC7_USB_MASK; | ||
276 | |||
277 | switch (psp) { | ||
278 | case POWER_SUPPLY_PROP_ONLINE: | ||
279 | val->intval = mbc->usb_online && | ||
280 | (usblim <= PCF50633_MBCC7_USB_500mA); | ||
281 | break; | ||
282 | default: | ||
283 | ret = -EINVAL; | ||
284 | break; | ||
285 | } | ||
286 | return ret; | ||
287 | } | ||
288 | |||
289 | static int ac_get_property(struct power_supply *psy, | ||
290 | enum power_supply_property psp, | ||
291 | union power_supply_propval *val) | ||
292 | { | ||
293 | struct pcf50633_mbc *mbc = container_of(psy, struct pcf50633_mbc, ac); | ||
294 | int ret = 0; | ||
295 | u8 usblim = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCC7) & | ||
296 | PCF50633_MBCC7_USB_MASK; | ||
272 | 297 | ||
273 | switch (psp) { | 298 | switch (psp) { |
274 | case POWER_SUPPLY_PROP_ONLINE: | 299 | case POWER_SUPPLY_PROP_ONLINE: |
275 | val->intval = mbc->usb_online; | 300 | val->intval = mbc->usb_online && |
301 | (usblim == PCF50633_MBCC7_USB_1000mA); | ||
276 | break; | 302 | break; |
277 | default: | 303 | default: |
278 | ret = -EINVAL; | 304 | ret = -EINVAL; |
@@ -337,6 +363,14 @@ static int __devinit pcf50633_mbc_probe(struct platform_device *pdev) | |||
337 | mbc->usb.supplied_to = mbc->pcf->pdata->batteries; | 363 | mbc->usb.supplied_to = mbc->pcf->pdata->batteries; |
338 | mbc->usb.num_supplicants = mbc->pcf->pdata->num_batteries; | 364 | mbc->usb.num_supplicants = mbc->pcf->pdata->num_batteries; |
339 | 365 | ||
366 | mbc->ac.name = "ac"; | ||
367 | mbc->ac.type = POWER_SUPPLY_TYPE_MAINS; | ||
368 | mbc->ac.properties = power_props; | ||
369 | mbc->ac.num_properties = ARRAY_SIZE(power_props); | ||
370 | mbc->ac.get_property = ac_get_property; | ||
371 | mbc->ac.supplied_to = mbc->pcf->pdata->batteries; | ||
372 | mbc->ac.num_supplicants = mbc->pcf->pdata->num_batteries; | ||
373 | |||
340 | ret = power_supply_register(&pdev->dev, &mbc->adapter); | 374 | ret = power_supply_register(&pdev->dev, &mbc->adapter); |
341 | if (ret) { | 375 | if (ret) { |
342 | dev_err(mbc->pcf->dev, "failed to register adapter\n"); | 376 | dev_err(mbc->pcf->dev, "failed to register adapter\n"); |
@@ -352,6 +386,15 @@ static int __devinit pcf50633_mbc_probe(struct platform_device *pdev) | |||
352 | return ret; | 386 | return ret; |
353 | } | 387 | } |
354 | 388 | ||
389 | ret = power_supply_register(&pdev->dev, &mbc->ac); | ||
390 | if (ret) { | ||
391 | dev_err(mbc->pcf->dev, "failed to register ac\n"); | ||
392 | power_supply_unregister(&mbc->adapter); | ||
393 | power_supply_unregister(&mbc->usb); | ||
394 | kfree(mbc); | ||
395 | return ret; | ||
396 | } | ||
397 | |||
355 | INIT_DELAYED_WORK(&mbc->charging_restart_work, | 398 | INIT_DELAYED_WORK(&mbc->charging_restart_work, |
356 | pcf50633_mbc_charging_restart); | 399 | pcf50633_mbc_charging_restart); |
357 | 400 | ||
@@ -379,6 +422,7 @@ static int __devexit pcf50633_mbc_remove(struct platform_device *pdev) | |||
379 | 422 | ||
380 | power_supply_unregister(&mbc->usb); | 423 | power_supply_unregister(&mbc->usb); |
381 | power_supply_unregister(&mbc->adapter); | 424 | power_supply_unregister(&mbc->adapter); |
425 | power_supply_unregister(&mbc->ac); | ||
382 | 426 | ||
383 | cancel_delayed_work_sync(&mbc->charging_restart_work); | 427 | cancel_delayed_work_sync(&mbc->charging_restart_work); |
384 | 428 | ||