Commit 35c3ae5e authored by Mark Brown's avatar Mark Brown Committed by Anton Vorontsov

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: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: default avatarAnton Vorontsov <cbouatmailru@gmail.com>
parent 9ad63986
...@@ -77,8 +77,8 @@ static ssize_t power_supply_show_property(struct device *dev, ...@@ -77,8 +77,8 @@ static ssize_t power_supply_show_property(struct device *dev,
dev_dbg(dev, "driver has no data for `%s' property\n", dev_dbg(dev, "driver has no data for `%s' property\n",
attr->attr.name); attr->attr.name);
else if (ret != -ENODEV) else if (ret != -ENODEV)
dev_err(dev, "driver failed to report `%s' property\n", dev_err(dev, "driver failed to report `%s' property: %d\n",
attr->attr.name); attr->attr.name, ret);
return ret; return ret;
} }
......
...@@ -27,6 +27,7 @@ struct wm831x_power { ...@@ -27,6 +27,7 @@ struct wm831x_power {
char wall_name[20]; char wall_name[20];
char usb_name[20]; char usb_name[20];
char battery_name[20]; char battery_name[20];
bool have_battery;
}; };
static int wm831x_power_check_online(struct wm831x *wm831x, int supply, static int wm831x_power_check_online(struct wm831x *wm831x, int supply,
...@@ -449,6 +450,7 @@ static irqreturn_t wm831x_bat_irq(int irq, void *data) ...@@ -449,6 +450,7 @@ static irqreturn_t wm831x_bat_irq(int irq, void *data)
/* The battery charger is autonomous so we don't need to do /* The battery charger is autonomous so we don't need to do
* anything except kick user space */ * anything except kick user space */
if (wm831x_power->have_battery)
power_supply_changed(&wm831x_power->battery); power_supply_changed(&wm831x_power->battery);
return IRQ_HANDLED; return IRQ_HANDLED;
...@@ -479,6 +481,7 @@ static irqreturn_t wm831x_pwr_src_irq(int irq, void *data) ...@@ -479,6 +481,7 @@ static irqreturn_t wm831x_pwr_src_irq(int irq, void *data)
dev_dbg(wm831x->dev, "Power source changed\n"); dev_dbg(wm831x->dev, "Power source changed\n");
/* Just notify for everything - little harm in overnotifying. */ /* Just notify for everything - little harm in overnotifying. */
if (wm831x_power->have_battery)
power_supply_changed(&wm831x_power->battery); power_supply_changed(&wm831x_power->battery);
power_supply_changed(&wm831x_power->usb); power_supply_changed(&wm831x_power->usb);
power_supply_changed(&wm831x_power->wall); power_supply_changed(&wm831x_power->wall);
...@@ -537,15 +540,6 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev) ...@@ -537,15 +540,6 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
if (ret) if (ret)
goto err_kmalloc; goto err_kmalloc;
battery->name = power->battery_name;
battery->properties = wm831x_bat_props;
battery->num_properties = ARRAY_SIZE(wm831x_bat_props);
battery->get_property = wm831x_bat_get_prop;
battery->use_for_apm = 1;
ret = power_supply_register(&pdev->dev, battery);
if (ret)
goto err_wall;
usb->name = power->usb_name, usb->name = power->usb_name,
usb->type = POWER_SUPPLY_TYPE_USB; usb->type = POWER_SUPPLY_TYPE_USB;
usb->properties = wm831x_usb_props; usb->properties = wm831x_usb_props;
...@@ -553,7 +547,23 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev) ...@@ -553,7 +547,23 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
usb->get_property = wm831x_usb_get_prop; usb->get_property = wm831x_usb_get_prop;
ret = power_supply_register(&pdev->dev, usb); ret = power_supply_register(&pdev->dev, usb);
if (ret) if (ret)
goto err_battery; goto err_wall;
ret = wm831x_reg_read(wm831x, WM831X_CHARGER_CONTROL_1);
if (ret < 0)
goto err_wall;
power->have_battery = ret & WM831X_CHG_ENA;
if (power->have_battery) {
battery->name = power->battery_name;
battery->properties = wm831x_bat_props;
battery->num_properties = ARRAY_SIZE(wm831x_bat_props);
battery->get_property = wm831x_bat_get_prop;
battery->use_for_apm = 1;
ret = power_supply_register(&pdev->dev, battery);
if (ret)
goto err_usb;
}
irq = platform_get_irq_byname(pdev, "SYSLO"); irq = platform_get_irq_byname(pdev, "SYSLO");
ret = request_threaded_irq(irq, NULL, wm831x_syslo_irq, ret = request_threaded_irq(irq, NULL, wm831x_syslo_irq,
...@@ -562,7 +572,7 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev) ...@@ -562,7 +572,7 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
if (ret != 0) { if (ret != 0) {
dev_err(&pdev->dev, "Failed to request SYSLO IRQ %d: %d\n", dev_err(&pdev->dev, "Failed to request SYSLO IRQ %d: %d\n",
irq, ret); irq, ret);
goto err_usb; goto err_battery;
} }
irq = platform_get_irq_byname(pdev, "PWR SRC"); irq = platform_get_irq_byname(pdev, "PWR SRC");
...@@ -601,10 +611,11 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev) ...@@ -601,10 +611,11 @@ static __devinit int wm831x_power_probe(struct platform_device *pdev)
err_syslo: err_syslo:
irq = platform_get_irq_byname(pdev, "SYSLO"); irq = platform_get_irq_byname(pdev, "SYSLO");
free_irq(irq, power); free_irq(irq, power);
err_usb:
power_supply_unregister(usb);
err_battery: err_battery:
if (power->have_battery)
power_supply_unregister(battery); power_supply_unregister(battery);
err_usb:
power_supply_unregister(usb);
err_wall: err_wall:
power_supply_unregister(wall); power_supply_unregister(wall);
err_kmalloc: err_kmalloc:
...@@ -628,6 +639,7 @@ static __devexit int wm831x_power_remove(struct platform_device *pdev) ...@@ -628,6 +639,7 @@ static __devexit int wm831x_power_remove(struct platform_device *pdev)
irq = platform_get_irq_byname(pdev, "SYSLO"); irq = platform_get_irq_byname(pdev, "SYSLO");
free_irq(irq, wm831x_power); free_irq(irq, wm831x_power);
if (wm831x_power->have_battery)
power_supply_unregister(&wm831x_power->battery); power_supply_unregister(&wm831x_power->battery);
power_supply_unregister(&wm831x_power->wall); power_supply_unregister(&wm831x_power->wall);
power_supply_unregister(&wm831x_power->usb); power_supply_unregister(&wm831x_power->usb);
......
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