aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2011-08-15 19:37:42 -0400
committerAnton Vorontsov <cbouatmailru@gmail.com>2011-08-19 13:03:23 -0400
commit35c3ae5eef3fc641c75c5e1e4307835c8efa5f6b (patch)
tree0fbd69761ff8080bb2d5615073f486612a1a7464
parent9ad63986c606c60e2e916b1b96f22991f966d9cc (diff)
wm831x_power: Only register WM831x battery charger if enabled
Don't tell the system about the battery charger if it's not enabled, we can reasonably assume that if the charger is not enabled then no battery will ever be connected so reporting state is at best going to waste time and at worst going to cause confusing information in the UI. For simplicity and robustness we continue to register and handle interrupts from the charger. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
-rw-r--r--drivers/power/power_supply_sysfs.c4
-rw-r--r--drivers/power/wm831x_power.c44
2 files changed, 30 insertions, 18 deletions
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index 605514afc29f..eb9a986c4f9f 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -77,8 +77,8 @@ static ssize_t power_supply_show_property(struct device *dev,
77 dev_dbg(dev, "driver has no data for `%s' property\n", 77 dev_dbg(dev, "driver has no data for `%s' property\n",
78 attr->attr.name); 78 attr->attr.name);
79 else if (ret != -ENODEV) 79 else if (ret != -ENODEV)
80 dev_err(dev, "driver failed to report `%s' property\n", 80 dev_err(dev, "driver failed to report `%s' property: %d\n",
81 attr->attr.name); 81 attr->attr.name, ret);
82 return ret; 82 return ret;
83 } 83 }
84 84
diff --git a/drivers/power/wm831x_power.c b/drivers/power/wm831x_power.c
index 6cc2ca6427f3..c32e6f83c7a8 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);