diff options
-rw-r--r-- | driver/charger/bq25710.c | 43 | ||||
-rw-r--r-- | driver/charger/bq25710.h | 15 | ||||
-rw-r--r-- | include/config.h | 9 | ||||
-rw-r--r-- | zephyr/Kconfig.battery | 11 | ||||
-rw-r--r-- | zephyr/shim/include/config_chip.h | 5 |
5 files changed, 83 insertions, 0 deletions
diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c index 13da37ab65..096d15ed1c 100644 --- a/driver/charger/bq25710.c +++ b/driver/charger/bq25710.c @@ -5,6 +5,8 @@ * TI bq25710 battery charger driver. */ +#include <stdbool.h> + #include "battery.h" #include "battery_smart.h" #include "bq25710.h" @@ -20,6 +22,11 @@ #include "timer.h" #include "util.h" +#if !defined(CONFIG_CHARGER_BQ25710) && \ + !defined(CONFIG_CHARGER_BQ25720) +#error Only the BQ25720 and BQ25710 are supported by bq25710 driver. +#endif + #ifndef CONFIG_CHARGER_NARROW_VDC #error "BQ25710 is a NVDC charger, please enable CONFIG_CHARGER_NARROW_VDC." #endif @@ -164,6 +171,39 @@ static int bq25710_set_low_power_mode(int chgnum, int enable) return EC_SUCCESS; } +static int bq25710_set_psys_sensing(int chgnum, bool enable) +{ + int rv; + int reg; + int mask, on, off; + + rv = raw_read16(chgnum, BQ25710_REG_CHARGE_OPTION_1, ®); + if (rv) + return rv; + + if (IS_ENABLED(CONFIG_CHARGER_BQ25720)) { + mask = BQ25720_CHARGE_OPTION_1_PSYS_MASK; + on = BQ25720_CHARGE_OPTION_1_PSYS_ON; + off = BQ25720_CHARGE_OPTION_1_PSYS_OFF; + } else if (IS_ENABLED(CONFIG_CHARGER_BQ25710)) { + mask = BQ25710_CHARGE_OPTION_1_PSYS_MASK; + on = BQ25710_CHARGE_OPTION_1_PSYS_ON; + off = BQ25710_CHARGE_OPTION_1_PSYS_OFF; + } + + reg &= ~mask; + if (enable) + reg |= on; + else + reg |= off; + + rv = raw_write16(chgnum, BQ25710_REG_CHARGE_OPTION_1, reg); + if (rv) + return rv; + + return EC_SUCCESS; +} + static int bq25710_adc_start(int chgnum, int adc_en_mask) { int reg; @@ -245,6 +285,9 @@ static void bq25710_init(int chgnum) bq25710_set_low_power_mode(chgnum, 1); } + if (IS_ENABLED(CONFIG_CHARGER_BQ25710_PSYS_SENSING)) + bq25710_set_psys_sensing(chgnum, true); + if (!raw_read16(chgnum, BQ25710_REG_PROCHOT_OPTION_1, ®)) { /* Disable VDPM prochot profile at initialization */ reg &= ~BQ25710_PROCHOT_PROFILE_VDPM; diff --git a/driver/charger/bq25710.h b/driver/charger/bq25710.h index 68c7619ceb..eafd3883a8 100644 --- a/driver/charger/bq25710.h +++ b/driver/charger/bq25710.h @@ -50,6 +50,21 @@ #define BQ25710_CHARGE_OPTION_0_EN_IDPM BIT(1) #define BQ25710_CHARGE_OPTION_0_CHRG_INHIBIT BIT(0) +/* ChargeOption1 Register */ +#define BQ25710_CHARGE_OPTION_1_PSYS_SHIFT 12 +#define BQ25720_CHARGE_OPTION_1_PSYS_MASK (0x03 << \ + BQ25710_CHARGE_OPTION_1_PSYS_SHIFT) +#define BQ25720_CHARGE_OPTION_1_PSYS_ON (0 << \ + BQ25710_CHARGE_OPTION_1_PSYS_SHIFT) +#define BQ25720_CHARGE_OPTION_1_PSYS_OFF (3 << \ + BQ25710_CHARGE_OPTION_1_PSYS_SHIFT) +#define BQ25710_CHARGE_OPTION_1_PSYS_MASK \ + BIT(BQ25710_CHARGE_OPTION_1_PSYS_SHIFT) +#define BQ25710_CHARGE_OPTION_1_PSYS_ON (1 << \ + BQ25710_CHARGE_OPTION_1_PSYS_SHIFT) +#define BQ25710_CHARGE_OPTION_1_PSYS_OFF (0 << \ + BQ25710_CHARGE_OPTION_1_PSYS_SHIFT) + /* ChargeOption2 Register */ #define BQ25710_CHARGE_OPTION_2_EN_EXTILIM BIT(7) #define BQ25710_CHARGE_OPTION_2_TMAX_SHIFT 8 diff --git a/include/config.h b/include/config.h index ce5fa5c25e..8ad208c5f3 100644 --- a/include/config.h +++ b/include/config.h @@ -1054,6 +1054,15 @@ #undef CONFIG_CHARGER_BQ25710_SENSE_RESISTOR_AC /* + * This config option is used to enable the PSYS sensing circuit on the + * BQ25710 and BQ25720 chargers. This is used for system power + * monitoring on board designs that support this capability. This + * circuit is disabled by default (reset) and needs to be explicitly + * enabled for meaningful results. + */ +#undef CONFIG_CHARGER_BQ25710_PSYS_SENSING + +/* * Board specific maximum input current limit, in mA. */ #undef CONFIG_CHARGER_MAX_INPUT_CURRENT diff --git a/zephyr/Kconfig.battery b/zephyr/Kconfig.battery index d7e5e459da..feddbc421b 100644 --- a/zephyr/Kconfig.battery +++ b/zephyr/Kconfig.battery @@ -250,6 +250,17 @@ endchoice # "Discharge control method" endif # PLATFORM_EC_CHARGER_DISCHARGE_ON_AC +config CONFIG_PLATFORM_EC_CHARGER_BQ25710_PSYS_SENSING + bool "Charger monitors PSYS" + default n + depends on PLATFORM_EC_CHARGER_BQ25710 || PLATFORM_EC_CHARGER_BQ25720 + help + This enables the PSYS sensing circuit on the BQ25710 and + BQ25720 chargers. This is used for system power monitoring on + board designs that support this capability. This circuit is + disabled by default (reset) and needs to be explicitly enabled + for meaningful results. + config PLATFORM_EC_CHARGER_BQ25710_SENSE_RESISTOR int "Value of the charge sense-resistor, in mOhms" default 10 diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index 8cb5b3b4af..59593665c1 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -1705,6 +1705,11 @@ CONFIG_PLATFORM_EC_BATTERY_DEVICE_CHEMISTRY #endif +#undef CONFIG_CHARGER_BQ25710_PSYS_SENSING +#ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25710_PSYS_SENSING +#define CONFIG_CHARGER_BQ25710_PSYS_SENSING +#endif + #undef CONFIG_CHARGER_BQ25710_SENSE_RESISTOR #ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25710_SENSE_RESISTOR #define CONFIG_CHARGER_BQ25710_SENSE_RESISTOR \ |