summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@chromium.org>2021-11-11 17:48:26 -0800
committerCommit Bot <commit-bot@chromium.org>2021-11-13 00:24:04 +0000
commit91065a8be6d0b7358931535cbb65d7e0b4cc5b8a (patch)
tree5e4a8537740ebf42065af931ee0710e146c11d00 /driver
parent062f33658aabdfb9255a0deda301e88b09d04804 (diff)
downloadchrome-ec-91065a8be6d0b7358931535cbb65d7e0b4cc5b8a.tar.gz
bq25710: Refactor Vmin Active Protection register initialization
This separates the initialization of the Vmin Active Protection register into a dedicated function. BRANCH=none BUG=b:185190976 TEST=buildall passes Signed-off-by: Caveh Jalali <caveh@chromium.org> Change-Id: Ib75d028c0a5bb5982fe34bf756a68f942769fad1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3277939 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Boris Mittelberg <bmbm@google.com> Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/charger/bq25710.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c
index c8e0efd6ee..f4cff93334 100644
--- a/driver/charger/bq25710.c
+++ b/driver/charger/bq25710.c
@@ -341,6 +341,33 @@ static int bq257x0_init_charge_option_3(int chgnum)
return raw_write16(chgnum, BQ25710_REG_CHARGE_OPTION_3, reg);
}
+static int bq25720_init_vmin_active_protection(int chgnum)
+{
+ int reg;
+ int rv;
+ int th2_dv;
+
+ if (!IS_ENABLED(CONFIG_CHARGER_BQ25720))
+ return EC_SUCCESS;
+
+ if (!IS_ENABLED(CONFIG_CHARGER_BQ25720_VSYS_TH2_CUSTOM))
+ return EC_SUCCESS;
+
+ rv = raw_read16(chgnum, BQ25720_REG_VMIN_ACTIVE_PROTECTION, &reg);
+ if (rv)
+ return rv;
+
+ /*
+ * 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.
+ */
+ th2_dv = VMIN_AP_VSYS_TH2_TO_REG(CONFIG_CHARGER_BQ25720_VSYS_TH2_DV);
+ reg = SET_BQ_FIELD(BQ25720, VMIN_AP, VSYS_TH2, th2_dv, reg);
+
+ return raw_write16(chgnum, BQ25720_REG_VMIN_ACTIVE_PROTECTION, reg);
+}
+
static void bq25710_init(int chgnum)
{
int reg;
@@ -410,24 +437,6 @@ static void bq25710_init(int chgnum)
raw_write16(chgnum, BQ25710_REG_PROCHOT_OPTION_1, reg);
}
- if (IS_ENABLED(CONFIG_CHARGER_BQ25720_VSYS_TH2_CUSTOM)) {
- /*
- * 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)) {
- int th2_dv = VMIN_AP_VSYS_TH2_TO_REG(
- CONFIG_CHARGER_BQ25720_VSYS_TH2_DV);
-
- reg = SET_BQ_FIELD(BQ25720, VMIN_AP, VSYS_TH2,
- th2_dv, reg);
- raw_write16(chgnum, BQ25720_REG_VMIN_ACTIVE_PROTECTION,
- reg);
- }
- }
-
/* Reduce ILIM from default of 150% to 105% */
if (!raw_read16(chgnum, BQ25710_REG_PROCHOT_OPTION_0, &reg)) {
reg = SET_BQ_FIELD(BQ257X0, PROCHOT_OPTION_0, ILIM2_VTH, 0,
@@ -438,6 +447,8 @@ static void bq25710_init(int chgnum)
bq257x0_init_charge_option_2(chgnum);
bq257x0_init_charge_option_3(chgnum);
+
+ bq25720_init_vmin_active_protection(chgnum);
}
/* Charger interfaces */