diff --git a/drivers/power/pmic8058-charger.c b/drivers/power/pmic8058-charger.c index d4239ea6210..d66317e23e7 100644 --- a/drivers/power/pmic8058-charger.c +++ b/drivers/power/pmic8058-charger.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -574,6 +575,16 @@ static int get_fsm_status(void *data, u64 * val) return 0; } +enum pmic8058_chg_state pmic8058_get_fsm_state(void) +{ + if (!pm8058_chg.inited) { + pr_err("%s: called when not inited\n", __func__); + return -EINVAL; + } + + return get_fsm_state(); +} + static int pm_chg_disable(int value) { u8 temp; @@ -720,9 +731,9 @@ static void charging_check_work(struct work_struct *work) switch (fsm_state) { /* We're charging, so disarm alarm */ - case 2: - case 7: - case 8: + case PMIC8058_CHG_STATE_ATC: + case PMIC8058_CHG_STATE_FAST_CHG: + case PMIC8058_CHG_STATE_TRKL_CHG: rc = pm8058_batt_alarm_state_set(0, 0); if (rc) dev_err(pm8058_chg.dev, diff --git a/include/linux/pmic8058-charger.h b/include/linux/pmic8058-charger.h index f1fd25c9d94..0fbc8281645 100644 --- a/include/linux/pmic8058-charger.h +++ b/include/linux/pmic8058-charger.h @@ -12,10 +12,61 @@ #ifndef __PMIC8058_CHARGER_H__ #define __PMIC8058_CHARGER_H__ +/** + * enum pmic8058_chg_state - pmic8058 charging states + * @PMIC8058_CHG_STATE_NONE: Initial off state + * @PMIC8058_CHG_STATE_PWR_CHG: Device powered from charger + * @PMIC8058_CHG_STATE_ATC: Device is Auto Tricke Charged (ATC) + * @PMIC8058_CHG_STATE_PWR_BAT: Device powered from Battery + * @PMIC8058_CHG_STATE_ATC_FAIL: ATC failed + * @PMIC8058_CHG_STATE_AUX_EN: Transient state + * @PMIC8058_CHG_STATE_PON_AFTER_ATC: Power on from battery and chg with limit + * of 90mA + * @PMIC8058_CHG_STATE_FAST_CHG: pmic is fast charging the battery + * @PMIC8058_CHG_STATE_TRKL_CHG: pmic is trck charging the battery + * @PMIC8058_CHG_STATE_CHG_FAIL: charging failed + * @PMIC8058_CHG_STATE_EOC: end of charging reached + * @PMIC8058_CHG_STATE_INRUSH_LIMIT: Brings up Vdd with 90mA max drawn from + * VBUS + * @PMIC8058_CHG_STATE_USB_SUSPENDED: USB supended, no current drawn from VBUS + * @PMIC8058_CHG_STATE_PAUSE_ATC: ATC paused + * @PMIC8058_CHG_STATE_PAUSE_FAST_CHG: FAST charging paused + * @PMIC8058_CHG_STATE_PAUSE_TRKL_CHG: TRLK charging paused + * + * The paused states happen when a unfavourable condition for charging is + * detected. The most common one being the battery gets too hot ot gets + * too cold for charging. + */ +enum pmic8058_chg_state { + PMIC8058_CHG_STATE_NONE, + PMIC8058_CHG_STATE_PWR_CHG, + PMIC8058_CHG_STATE_ATC, + PMIC8058_CHG_STATE_PWR_BAT, + PMIC8058_CHG_STATE_ATC_FAIL, + PMIC8058_CHG_STATE_AUX_EN, + PMIC8058_CHG_STATE_PON_AFTER_ATC, + PMIC8058_CHG_STATE_FAST_CHG, + PMIC8058_CHG_STATE_TRKL_CHG, + PMIC8058_CHG_STATE_CHG_FAIL, + PMIC8058_CHG_STATE_EOC, + PMIC8058_CHG_STATE_INRUSH_LIMIT, + PMIC8058_CHG_STATE_USB_SUSPENDED, + PMIC8058_CHG_STATE_PAUSE_ATC, + PMIC8058_CHG_STATE_PAUSE_FAST_CHG, + PMIC8058_CHG_STATE_PAUSE_TRKL_CHG +}; #if defined(CONFIG_BATTERY_MSM8X60) || defined(CONFIG_BATTERY_MSM8X60_MODULE) int pmic8058_get_charge_batt(void); int pmic8058_set_charge_batt(int); +/** + * pmic8058_get_fsm_state - + * + * CONTEXT: may sleep - should not be called from non-atomic context + * + * RETURNS: The pmic internal state, or error otherwise + */ +enum pmic8058_chg_state pmic8058_get_fsm_state(void); #else int pmic8058_get_charge_batt(void) { @@ -25,5 +76,9 @@ int pmic8058_set_charge_batt(int) { return -ENXIO; } +enum pmic8058_chg_state pmic8058_get_fsm_state(void) +{ + return -ENXIO; +} #endif #endif /* __PMIC8058_CHARGER_H__ */