power: pm8921-charger: fix end of charging issues
While checking for end of charge current, voltage collapse protection (vcp)
should be 0. If it is 1 end of charging should not happen.
Also the regulation loop sometimes might read back zero. It is okay to
declare eoc in such cases.
The vbatdet_irq may not trigger when charging is enabled and vbat falls
below vbatdet. This is because charging resumes before vbatdet_irq's
debounce time period elapses which causes vbat to increase above vbatdet
as the battery has begun charging. To circumvent this issue disable
charging when the eoc is declared and enable it only upon vbatdet_low_irq.
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/drivers/power/pm8921-charger.c b/drivers/power/pm8921-charger.c
index e3c715d..a6d43fe 100644
--- a/drivers/power/pm8921-charger.c
+++ b/drivers/power/pm8921-charger.c
@@ -1265,6 +1265,9 @@
struct pm8921_chg_chip *chip = data;
pm8921_chg_disable_irq(chip, VBATDET_LOW_IRQ);
+
+ /* enable auto charging */
+ pm_chg_auto_enable(chip, !charging_disabled);
pr_debug("fsm_state=%d\n", pm_chg_get_fsm_state(data));
power_supply_changed(&chip->batt_psy);
@@ -1560,7 +1563,7 @@
vcp = pm_chg_get_rt_status(chip, VCP_IRQ);
pr_debug("vcp = %d\n", vcp);
- if (vcp == 0)
+ if (vcp == 1)
goto reset_and_reschedule;
/* reset count if battery is hot/cold */
@@ -1614,7 +1617,8 @@
goto reset_and_reschedule;
}
pr_debug("regulation_loop=%d\n", regulation_loop);
- if (regulation_loop != VDD_LOOP)
+
+ if (regulation_loop != 0 && regulation_loop != VDD_LOOP)
goto reset_and_reschedule;
count++;
@@ -1623,8 +1627,6 @@
pr_info("End of Charging\n");
pm_chg_auto_enable(chip, 0);
- msleep(CHG_DISABLE_MSLEEP);
- pm_chg_auto_enable(chip, !charging_disabled);
/* declare end of charging by invoking chgdone interrupt */
chgdone_irq_handler(chip->pmic_chg_irq[CHGDONE_IRQ], chip);