diff options
-rw-r--r-- | driver/charger/bq25710.c | 63 | ||||
-rw-r--r-- | driver/charger/bq25710.h | 2 | ||||
-rw-r--r-- | include/config.h | 10 |
3 files changed, 75 insertions, 0 deletions
diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c index 5deb59328b..5700a0325b 100644 --- a/driver/charger/bq25710.c +++ b/driver/charger/bq25710.c @@ -13,6 +13,7 @@ #include "console.h" #include "hooks.h" #include "i2c.h" +#include "task.h" #include "timer.h" #ifndef CONFIG_CHARGER_NARROW_VDC @@ -35,6 +36,16 @@ /* Console output macros */ #define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args) +#ifdef CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA +/* + * If this config option is defined, then the bq25710 needs to remain in + * performance mode when the AP is in S0. Performance mode is active whenever AC + * power is connected or when the EN_LWPWR bit in ChargeOption0 is clear. + */ +static uint32_t bq25710_perf_mode_req; +static struct mutex bq25710_perf_mode_mutex; +#endif + /* Charger parameters */ static const struct charger_info bq25710_charger_info = { .name = "bq25710", @@ -85,12 +96,30 @@ static int bq25710_set_low_power_mode(int enable) if (rv) return rv; +#ifdef CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA + mutex_lock(&bq25710_perf_mode_mutex); + /* + * Performance mode means not in low power mode. The bit that controls + * this is EN_LWPWR in ChargeOption0. The 'enable' param in this + * function is refeerring to low power mode, so enabling low power mode + * means disabling performance mode and vice versa. + */ + if (enable) + bq25710_perf_mode_req &= ~(1 << task_get_current()); + else + bq25710_perf_mode_req |= (1 << task_get_current()); + enable = !bq25710_perf_mode_req; +#endif + if (enable) reg |= BQ25710_CHARGE_OPTION_0_LOW_POWER_MODE; else reg &= ~BQ25710_CHARGE_OPTION_0_LOW_POWER_MODE; rv = raw_write16(BQ25710_REG_CHARGE_OPTION_0, reg); +#ifdef CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA + mutex_unlock(&bq25710_perf_mode_mutex); +#endif if (rv) return rv; @@ -175,6 +204,21 @@ static void bq25710_init(void) * no battery is present prochot will continuosly be asserted. */ reg |= BQ25710_PROCHOT_PROFILE_VSYS; +#ifdef CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA + /* + * Set the IDCHG limit who's value is defined in the config + * option in mA. Also, enable IDCHG trigger for prochot. + */ + reg &= ~BQ25710_PROCHOT_IDCHG_VTH_MASK; + /* + * IDCHG limit is in 512 mA steps. Note there is a 128 mA offset + * so the actual IDCHG limit will be the value stored in bits + * 15:10 + 128 mA. + */ + reg |= ((CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA << 1) & + BQ25710_PROCHOT_IDCHG_VTH_MASK); + reg |= BQ25710_PROCHOT_PROFILE_IDCHG; +#endif raw_write16(BQ25710_REG_PROCHOT_OPTION_1, reg); } @@ -484,6 +528,25 @@ error: } #endif /* CONFIG_CHARGE_RAMP_HW */ +#ifdef CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA +/* Called on AP S5 -> S3 and S3/S0iX -> S0 transition */ +static void bq25710_chipset_startup(void) +{ + bq25710_set_low_power_mode(0); +} +DECLARE_HOOK(HOOK_CHIPSET_STARTUP, bq25710_chipset_startup, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_CHIPSET_RESUME, bq25710_chipset_startup, HOOK_PRIO_DEFAULT); + + +/* Called on AP S0 -> S0iX/S3 or S3 -> S5 transition */ +static void bq25710_chipset_suspend(void) +{ + bq25710_set_low_power_mode(1); +} +DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, bq25710_chipset_suspend, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, bq25710_chipset_suspend, HOOK_PRIO_DEFAULT); +#endif + #ifdef CONFIG_CMD_CHARGER_DUMP static int console_bq25710_dump_regs(int argc, char **argv) { diff --git a/driver/charger/bq25710.h b/driver/charger/bq25710.h index 3b31c88bdb..448e24bad0 100644 --- a/driver/charger/bq25710.h +++ b/driver/charger/bq25710.h @@ -85,6 +85,8 @@ /* ProchotOption1 Register */ #define BQ25710_PROCHOT_PROFILE_VDPM BIT(7) +#define BQ25710_PROCHOT_PROFILE_IDCHG BIT(3) #define BQ25710_PROCHOT_PROFILE_VSYS BIT(2) +#define BQ25710_PROCHOT_IDCHG_VTH_MASK 0xFC00 #endif /* __CROS_EC_BQ25710_H */ diff --git a/include/config.h b/include/config.h index 5975df08a4..ca441d17cf 100644 --- a/include/config.h +++ b/include/config.h @@ -817,6 +817,16 @@ */ #undef CONFIG_CHARGER_INPUT_CURRENT +/* + * This config option is used to enable IDCHG trigger for prochot. This macro + * should be set to the desired current limit to draw from the battery before + * triggering prochot. Note that is has a 512 mA granularity. The function that + * sets the limit will mask of the lower 10 bits. For this check to be active + * the bq25710 must be in performance mode and this config option is also used + * to keep the bq25710 in performance mode when the AP is in S0. + */ +#undef CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA + /* Define to use Power Delivery State Machine Framework */ #undef CONFIG_USB_SM_FRAMEWORK |