summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@chromium.org>2021-03-30 02:33:43 -0700
committerCommit Bot <commit-bot@chromium.org>2021-04-06 15:23:50 +0000
commit74a15b6bcacce1926658f81c106ff33054ab5d51 (patch)
tree42c82a07f8a9d477135c59424ca496afe479320f
parent11d2f6db059abdae1801cb6bcc4064d24a950ce3 (diff)
downloadchrome-ec-74a15b6bcacce1926658f81c106ff33054ab5d51.tar.gz
bq25720: Add VSYS_TH2 tuning support
This adds support for tuning the bq25720 VSYS_TH2 threshold so that a custom threshold voltage can be specified. The default 3.2v for 1S batteries and 5.9v for 2S (or more) batteries may need to be adjusted to improve system stability. When VSYS droops to this threshold, PROCHOT is asserted to reduce system power demand. BRANCH=none BUG=b:183474163 TEST=with rest of patch stack, booted brya to the OS without a battery Signed-off-by: Caveh Jalali <caveh@chromium.org> Change-Id: I7f52a369371eb93860b14ad8438b790af231c450 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2798979 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r--driver/charger/bq25710.c19
-rw-r--r--driver/charger/bq25710.h7
-rw-r--r--include/config.h10
-rw-r--r--zephyr/Kconfig.battery22
-rw-r--r--zephyr/shim/include/config_chip.h6
5 files changed, 64 insertions, 0 deletions
diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c
index eea7f2d160..708a2c91ce 100644
--- a/driver/charger/bq25710.c
+++ b/driver/charger/bq25710.c
@@ -51,6 +51,9 @@
((CONFIG_CHARGER_SENSE_RESISTOR) / DEFAULT_SENSE_RESISTOR)
#define REG_TO_CHARGING_CURRENT(REG) ((REG) / CHARGING_RESISTOR_RATIO)
#define CHARGING_CURRENT_TO_REG(CUR) ((CUR) * CHARGING_RESISTOR_RATIO)
+#ifdef CONFIG_CHARGER_BQ25720
+#define VMIN_AP_VSYS_TH2_TO_REG(DV) ((DV) - 32)
+#endif
/* Console output macros */
#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
@@ -256,6 +259,22 @@ static void bq25710_init(int chgnum)
reg |= BQ25710_PROCHOT_PROFILE_IDCHG;
#endif
raw_write16(chgnum, BQ25710_REG_PROCHOT_OPTION_1, reg);
+#ifdef CONFIG_CHARGER_BQ25720_VSYS_TH2_DV
+ /*
+ * The default VSYS_TH2 is 5.9v for a 2S config. Boards
+ * may need to increase this for stability. PROCHOT is
+ * asserted when the threshold is reached.
+ */
+ if (!raw_read16(chgnum, BQ25720_REG_VMIN_ACTIVE_PROTECTION,
+ &reg)) {
+ reg &= ~BQ25720_VMIN_AP_VSYS_TH2_MASK;
+ reg |= VMIN_AP_VSYS_TH2_TO_REG(
+ CONFIG_CHARGER_BQ25720_VSYS_TH2_DV) <<
+ BQ25720_VMIN_AP_VSYS_TH2_SHIFT;
+ raw_write16(chgnum, BQ25720_REG_VMIN_ACTIVE_PROTECTION,
+ reg);
+ }
+#endif
}
/* Reduce ILIM from default of 150% to 105% */
diff --git a/driver/charger/bq25710.h b/driver/charger/bq25710.h
index bb9e390f55..de5db13587 100644
--- a/driver/charger/bq25710.h
+++ b/driver/charger/bq25710.h
@@ -102,6 +102,13 @@
#define BQ25710_IIN_DPM_BIT_SHIFT 8
#define BQ25710_IIN_DPM_STEP_MA 50
+#if defined(CONFIG_CHARGER_BQ25720)
+/* Vmin Active Protection Register */
+#define BQ25720_VMIN_AP_VSYS_TH2_SHIFT 2
+#define BQ25720_VMIN_AP_VSYS_TH2_MASK GENMASK(7, \
+ BQ25720_VMIN_AP_VSYS_TH2_SHIFT)
+#endif
+
extern const struct charger_drv bq25710_drv;
#endif /* __CROS_EC_BQ25710_H */
diff --git a/include/config.h b/include/config.h
index c0a88cda53..8e7db9af9c 100644
--- a/include/config.h
+++ b/include/config.h
@@ -983,6 +983,16 @@
#undef CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA
/*
+ * This config option is used to set the charger's VSYS voltage
+ * threshold. When the voltage drops to this level, PROCHOT is asserted
+ * by the charger to request reduced system power demand and hopefully
+ * avoid a voltage droop leading to system instability. The voltage is
+ * specified in deci-volts, so a value of 80 would set the threshold to
+ * 8.0v.
+ */
+#undef CONFIG_CHARGER_BQ25720_VSYS_TH2_DV
+
+/*
* 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 3959f26aca..52553a0079 100644
--- a/zephyr/Kconfig.battery
+++ b/zephyr/Kconfig.battery
@@ -204,6 +204,28 @@ endchoice # "Discharge control method"
endif # PLATFORM_EC_CHARGER_DISCHARGE_ON_AC
+config PLATFORM_EC_CHARGER_BQ25720_VSYS_TH2_CUSTOM
+ bool "VSYS_TH2 override"
+ depends on PLATFORM_EC_CHARGER_BQ25720
+ help
+ Enable customizing the charger's VSYS_TH2 threshold.
+
+config PLATFORM_EC_CHARGER_BQ25720_VSYS_TH2_DV
+ int "VSYS threshold 2 in deci-volts"
+ range 32 95
+ default 32
+ depends on PLATFORM_EC_CHARGER_BQ25720_VSYS_TH2_CUSTOM
+ help
+ Sets the VSYS threshold 2 in deci volts. This is the first
+ threshold that will be encountered when VSYS droops, typically
+ due to high power demand from the main processor. The charger
+ chip reacts by asserting PROCHOT which the main processor uses
+ as an indication to throttle back and reduce power demand. The
+ charger chip uses default thresholds which may be low enough
+ to cause system instability. The default for 1S batteries is
+ 3.2v and 5.9v for 2S or higher batteries. The valid range is
+ 3.2v - 3.9v for 1S and 3.2 - 9.5v for 2S or higher batteries.
+
config PLATFORM_EC_CHARGER_NARROW_VDC
bool
help
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index 4739bf2ee9..a5a57abf13 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -1348,6 +1348,12 @@
#define CONFIG_CHARGER_BQ25720
#endif
+#undef CONFIG_CHARGER_BQ25720_VSYS_TH2_DV
+#ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25720_VSYS_TH2_CUSTOM
+#define CONFIG_CHARGER_BQ25720_VSYS_TH2_DV \
+ CONFIG_PLATFORM_EC_CHARGER_BQ25720_VSYS_TH2_DV
+#endif
+
#undef CONFIG_HIBERNATE_PSL
#ifdef CONFIG_PLATFORM_EC_HIBERNATE_PSL
#define CONFIG_HIBERNATE_PSL