aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/wm831x_power.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/wm831x_power.c')
-rw-r--r--drivers/power/wm831x_power.c56
1 files changed, 29 insertions, 27 deletions
diff --git a/drivers/power/wm831x_power.c b/drivers/power/wm831x_power.c
index 6cc2ca6427f3..987332b71d8d 100644
--- a/drivers/power/wm831x_power.c
+++ b/drivers/power/wm831x_power.c
@@ -27,6 +27,7 @@ struct wm831x_power {
27 char wall_name[20]; 27 char wall_name[20];
28 char usb_name[20]; 28 char usb_name[20];
29 char battery_name[20]; 29 char battery_name[20];
30 bool have_battery;
30}; 31};
31 32
32static int wm831x_power_check_online(struct wm831x *wm831x, int supply, 33static int wm831x_power_check_online(struct wm831x *wm831x, int supply,
@@ -449,7 +450,8 @@ static irqreturn_t wm831x_bat_irq(int irq, void *data)
449 450
450 /* The battery charger is autonomous so we don't need to do 451 /* The battery charger is autonomous so we don't need to do
451 * anything except kick user space */ 452 * anything except kick user space */
452 power_supply_changed(&wm831x_power->battery); 453 if (wm831x_power->have_battery)
454 power_supply_changed(&wm831x_power->battery);
453 455
454 return IRQ_HANDLED; 456 return IRQ_HANDLED;
455} 457}
@@ -479,7 +481,8 @@ static irqreturn_t wm831x_pwr_src_irq(int irq, void *data)
479 dev_dbg(wm831x->dev, "Power source changed\n"); 481 dev_dbg(wm831x->dev, "Power source changed\n");
480 482
481 /* Just notify for everything - little harm in overnotifying. */ 483 /* Just notify for everything - little harm in overnotifying. */
482 power_supply_changed(&wm831x_power->battery); 484 if (wm831x_power->have_battery)
485 power_supply_changed(&wm831x_power->battery);
483 power_supply_changed(&wm831x_power->usb); 486 power_supply_changed(&wm831x_power->usb);
484 power_supply_changed(&wm831x_power->wall); 487 power_supply_changed(&wm831x_power->wall);
485 488
@@ -537,15 +540,6 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
537 if (ret) 540 if (ret)
538 goto err_kmalloc; 541 goto err_kmalloc;
539 542
540 battery->name = power->battery_name;
541 battery->properties = wm831x_bat_props;
542 battery->num_properties = ARRAY_SIZE(wm831x_bat_props);
543 battery->get_property = wm831x_bat_get_prop;
544 battery->use_for_apm = 1;
545 ret = power_supply_register(&pdev->dev, battery);
546 if (ret)
547 goto err_wall;
548
549 usb->name = power->usb_name, 543 usb->name = power->usb_name,
550 usb->type = POWER_SUPPLY_TYPE_USB; 544 usb->type = POWER_SUPPLY_TYPE_USB;
551 usb->properties = wm831x_usb_props; 545 usb->properties = wm831x_usb_props;
@@ -553,7 +547,23 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
553 usb->get_property = wm831x_usb_get_prop; 547 usb->get_property = wm831x_usb_get_prop;
554 ret = power_supply_register(&pdev->dev, usb); 548 ret = power_supply_register(&pdev->dev, usb);
555 if (ret) 549 if (ret)
556 goto err_battery; 550 goto err_wall;
551
552 ret = wm831x_reg_read(wm831x, WM831X_CHARGER_CONTROL_1);
553 if (ret < 0)
554 goto err_wall;
555 power->have_battery = ret & WM831X_CHG_ENA;
556
557 if (power->have_battery) {
558 battery->name = power->battery_name;
559 battery->properties = wm831x_bat_props;
560 battery->num_properties = ARRAY_SIZE(wm831x_bat_props);
561 battery->get_property = wm831x_bat_get_prop;
562 battery->use_for_apm = 1;
563 ret = power_supply_register(&pdev->dev, battery);
564 if (ret)
565 goto err_usb;
566 }
557 567
558 irq = platform_get_irq_byname(pdev, "SYSLO"); 568 irq = platform_get_irq_byname(pdev, "SYSLO");
559 ret = request_threaded_irq(irq, NULL, wm831x_syslo_irq, 569 ret = request_threaded_irq(irq, NULL, wm831x_syslo_irq,
@@ -562,7 +572,7 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
562 if (ret != 0) { 572 if (ret != 0) {
563 dev_err(&pdev->dev, "Failed to request SYSLO IRQ %d: %d\n", 573 dev_err(&pdev->dev, "Failed to request SYSLO IRQ %d: %d\n",
564 irq, ret); 574 irq, ret);
565 goto err_usb; 575 goto err_battery;
566 } 576 }
567 577
568 irq = platform_get_irq_byname(pdev, "PWR SRC"); 578 irq = platform_get_irq_byname(pdev, "PWR SRC");
@@ -601,10 +611,11 @@ err_bat_irq:
601err_syslo: 611err_syslo:
602 irq = platform_get_irq_byname(pdev, "SYSLO"); 612 irq = platform_get_irq_byname(pdev, "SYSLO");
603 free_irq(irq, power); 613 free_irq(irq, power);
614err_battery:
615 if (power->have_battery)
616 power_supply_unregister(battery);
604err_usb: 617err_usb:
605 power_supply_unregister(usb); 618 power_supply_unregister(usb);
606err_battery:
607 power_supply_unregister(battery);
608err_wall: 619err_wall:
609 power_supply_unregister(wall); 620 power_supply_unregister(wall);
610err_kmalloc: 621err_kmalloc:
@@ -628,7 +639,8 @@ static __devexit int wm831x_power_remove(struct platform_device *pdev)
628 irq = platform_get_irq_byname(pdev, "SYSLO"); 639 irq = platform_get_irq_byname(pdev, "SYSLO");
629 free_irq(irq, wm831x_power); 640 free_irq(irq, wm831x_power);
630 641
631 power_supply_unregister(&wm831x_power->battery); 642 if (wm831x_power->have_battery)
643 power_supply_unregister(&wm831x_power->battery);
632 power_supply_unregister(&wm831x_power->wall); 644 power_supply_unregister(&wm831x_power->wall);
633 power_supply_unregister(&wm831x_power->usb); 645 power_supply_unregister(&wm831x_power->usb);
634 kfree(wm831x_power); 646 kfree(wm831x_power);
@@ -643,17 +655,7 @@ static struct platform_driver wm831x_power_driver = {
643 }, 655 },
644}; 656};
645 657
646static int __init wm831x_power_init(void) 658module_platform_driver(wm831x_power_driver);
647{
648 return platform_driver_register(&wm831x_power_driver);
649}
650module_init(wm831x_power_init);
651
652static void __exit wm831x_power_exit(void)
653{
654 platform_driver_unregister(&wm831x_power_driver);
655}
656module_exit(wm831x_power_exit);
657 659
658MODULE_DESCRIPTION("Power supply driver for WM831x PMICs"); 660MODULE_DESCRIPTION("Power supply driver for WM831x PMICs");
659MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 661MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");