diff options
author | Mike Rapoport <mike@compulab.co.il> | 2009-06-08 17:09:45 -0400 |
---|---|---|
committer | Anton Vorontsov <cbouatmailru@gmail.com> | 2009-06-08 17:12:38 -0400 |
commit | a35d01a5d2ac533edab94a8e3b6749ab213c91c5 (patch) | |
tree | f29c751f52713f826ec9ed00c48f5339a0cd2d9b /drivers | |
parent | c6f4a42de60b981dd210de01cd3e575835e3158e (diff) |
da9030_battery: Fix race between event handler and monitor
There are cases when charging monitor and the event handler try to
change the charger state simultaneously. For instance, a charger is
connected to the system, there's the detection event and the event
handler tries to enable charging. It is possible that the periodic
charging monitor runs at the same time and it still thinks there's
no external charger. So it tries to disable the charging. As the
result, even if the conditions necessary to charge the battery hold,
there will be no actual charging.
The patch changes the event handler so that instead of enabling/
disabling the charger immediately it would rather make the monitor
run. The monitor code then decides what should be the charger state.
Signed-off-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/power/da9030_battery.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/power/da9030_battery.c b/drivers/power/da9030_battery.c index 1662bb0f23a5..3364198134a1 100644 --- a/drivers/power/da9030_battery.c +++ b/drivers/power/da9030_battery.c | |||
@@ -22,8 +22,6 @@ | |||
22 | #include <linux/debugfs.h> | 22 | #include <linux/debugfs.h> |
23 | #include <linux/seq_file.h> | 23 | #include <linux/seq_file.h> |
24 | 24 | ||
25 | #define DA9030_STATUS_CHDET (1 << 3) | ||
26 | |||
27 | #define DA9030_FAULT_LOG 0x0a | 25 | #define DA9030_FAULT_LOG 0x0a |
28 | #define DA9030_FAULT_LOG_OVER_TEMP (1 << 7) | 26 | #define DA9030_FAULT_LOG_OVER_TEMP (1 << 7) |
29 | #define DA9030_FAULT_LOG_VBAT_OVER (1 << 4) | 27 | #define DA9030_FAULT_LOG_VBAT_OVER (1 << 4) |
@@ -244,6 +242,8 @@ static void da9030_set_charge(struct da9030_charger *charger, int on) | |||
244 | } | 242 | } |
245 | 243 | ||
246 | da903x_write(charger->master, DA9030_CHARGE_CONTROL, val); | 244 | da903x_write(charger->master, DA9030_CHARGE_CONTROL, val); |
245 | |||
246 | power_supply_changed(&charger->psy); | ||
247 | } | 247 | } |
248 | 248 | ||
249 | static void da9030_charger_check_state(struct da9030_charger *charger) | 249 | static void da9030_charger_check_state(struct da9030_charger *charger) |
@@ -258,6 +258,12 @@ static void da9030_charger_check_state(struct da9030_charger *charger) | |||
258 | da9030_set_charge(charger, 1); | 258 | da9030_set_charge(charger, 1); |
259 | } | 259 | } |
260 | } else { | 260 | } else { |
261 | /* Charger has been pulled out */ | ||
262 | if (!charger->chdet) { | ||
263 | da9030_set_charge(charger, 0); | ||
264 | return; | ||
265 | } | ||
266 | |||
261 | if (charger->adc.vbat_res >= | 267 | if (charger->adc.vbat_res >= |
262 | charger->thresholds.vbat_charge_stop) { | 268 | charger->thresholds.vbat_charge_stop) { |
263 | da9030_set_charge(charger, 0); | 269 | da9030_set_charge(charger, 0); |
@@ -395,13 +401,11 @@ static int da9030_battery_event(struct notifier_block *nb, unsigned long event, | |||
395 | { | 401 | { |
396 | struct da9030_charger *charger = | 402 | struct da9030_charger *charger = |
397 | container_of(nb, struct da9030_charger, nb); | 403 | container_of(nb, struct da9030_charger, nb); |
398 | int status; | ||
399 | 404 | ||
400 | switch (event) { | 405 | switch (event) { |
401 | case DA9030_EVENT_CHDET: | 406 | case DA9030_EVENT_CHDET: |
402 | status = da903x_query_status(charger->master, | 407 | cancel_delayed_work_sync(&charger->work); |
403 | DA9030_STATUS_CHDET); | 408 | schedule_work(&charger->work.work); |
404 | da9030_set_charge(charger, status); | ||
405 | break; | 409 | break; |
406 | case DA9030_EVENT_VBATMON: | 410 | case DA9030_EVENT_VBATMON: |
407 | da9030_battery_vbat_event(charger); | 411 | da9030_battery_vbat_event(charger); |
@@ -565,7 +569,8 @@ static int da9030_battery_remove(struct platform_device *dev) | |||
565 | da903x_unregister_notifier(charger->master, &charger->nb, | 569 | da903x_unregister_notifier(charger->master, &charger->nb, |
566 | DA9030_EVENT_CHDET | DA9030_EVENT_VBATMON | | 570 | DA9030_EVENT_CHDET | DA9030_EVENT_VBATMON | |
567 | DA9030_EVENT_CHIOVER | DA9030_EVENT_TBAT); | 571 | DA9030_EVENT_CHIOVER | DA9030_EVENT_TBAT); |
568 | cancel_delayed_work(&charger->work); | 572 | cancel_delayed_work_sync(&charger->work); |
573 | da9030_set_charge(charger, 0); | ||
569 | power_supply_unregister(&charger->psy); | 574 | power_supply_unregister(&charger->psy); |
570 | 575 | ||
571 | kfree(charger); | 576 | kfree(charger); |