summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@chromium.org>2021-11-05 20:23:05 -0700
committerCommit Bot <commit-bot@chromium.org>2021-11-13 01:21:50 +0000
commitdf56c2b3e8f0e618fdf1175e851acdef4a7b296e (patch)
tree8d42b084b9054a48cfa268692bde1eb3d63c5491
parent91065a8be6d0b7358931535cbb65d7e0b4cc5b8a (diff)
downloadchrome-ec-df56c2b3e8f0e618fdf1175e851acdef4a7b296e.tar.gz
bq25710: Refactor prochot option 1 register initialization
This separates the initialization of the prochot option 1 register into a dedicated function. Multiple bit-fields will need to set in this register based on board configuration, so it's best to group these operations in one place. Also, numeric/boolean values are replaced with symbolic values when setting register fields for clarity where appropriate. BRANCH=none BUG=b:185190976 TEST=buildall passes Signed-off-by: Caveh Jalali <caveh@chromium.org> Change-Id: I73e6bd4f719f19ae21677b9fca90f10cf05665c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3277940 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Boris Mittelberg <bmbm@google.com> Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r--driver/charger/bq25710.c80
-rw-r--r--driver/charger/bq257x0_regs.h6
2 files changed, 55 insertions, 31 deletions
diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c
index f4cff93334..51126d92b3 100644
--- a/driver/charger/bq25710.c
+++ b/driver/charger/bq25710.c
@@ -54,6 +54,14 @@
CHARGE_OPTION_3, \
_field, _v, (_x))
+#define SET_PO1(_field, _v, _x) SET_BQ_FIELD(BQ257X0, \
+ PROCHOT_OPTION_1, \
+ _field, _v, (_x))
+
+#define SET_PO1_BY_NAME(_field, _c, _x) SET_BQ_FIELD_BY_NAME(BQ257X0, \
+ PROCHOT_OPTION_1, \
+ _field, _c, (_x))
+
/*
* Delay required from taking the bq25710 out of low power mode and having the
* correct value in register 0x3E for VSYS_MIN voltage. The length of the delay
@@ -281,6 +289,46 @@ static int bq257x0_init_charge_option_1(int chgnum)
return raw_write16(chgnum, BQ25710_REG_CHARGE_OPTION_1, reg);
}
+static int bq257x0_init_prochot_option_1(int chgnum)
+{
+ int rv;
+ int reg;
+
+ rv = raw_read16(chgnum, BQ25710_REG_PROCHOT_OPTION_1, &reg);
+ if (rv)
+ return rv;
+
+ /* Disable VDPM prochot profile at initialization */
+ reg = SET_PO1_BY_NAME(PP_VDPM, DISABLE, reg);
+
+ /*
+ * Enable PROCHOT to be asserted with VSYS min detection. Note
+ * that when no battery is present, then VSYS will be set to the
+ * value in register 0x3E (MinSysVoltage) which means that when
+ * no battery is present prochot will continuosly be asserted.
+ */
+ reg = SET_PO1_BY_NAME(PP_VSYS, ENABLE, reg);
+
+#ifdef CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA
+ /*
+ * Set the IDCHG limit who's value is defined in the config
+ * option in mA.
+ *
+ * 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
+ * IDCHG_VTH + 128 mA.
+ */
+ reg = SET_PO1(IDCHG_VTH,
+ CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA >> 9,
+ reg);
+
+ /* Enable IDCHG trigger for prochot. */
+ reg = SET_PO1_BY_NAME(PP_IDCHG, ENABLE, reg);
+#endif
+
+ return raw_write16(chgnum, BQ25710_REG_PROCHOT_OPTION_1, reg);
+}
+
static int bq257x0_init_charge_option_2(int chgnum)
{
int reg;
@@ -405,37 +453,7 @@ static void bq25710_init(int chgnum)
bq257x0_init_charge_option_1(chgnum);
- if (!raw_read16(chgnum, BQ25710_REG_PROCHOT_OPTION_1, &reg)) {
- /* Disable VDPM prochot profile at initialization */
- reg = SET_BQ_FIELD(BQ257X0, PROCHOT_OPTION_1, PP_VDPM, false,
- reg);
- /*
- * Enable PROCHOT to be asserted with VSYS min detection. Note
- * that when no battery is present, then VSYS will be set to the
- * value in register 0x3E (MinSysVoltage) which means that when
- * no battery is present prochot will continuosly be asserted.
- */
- reg = SET_BQ_FIELD(BQ257X0, PROCHOT_OPTION_1, PP_VSYS, true,
- reg);
-#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.
- */
- /*
- * 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 = SET_BQ_FIELD(BQ257X0, PROCHOT_OPTION_1, IDCHG_VTH,
- CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA >> 9,
- reg);
- reg = SET_BQ_FIELD(BQ257X0, PROCHOT_OPTION_1, PP_IDCHG, true,
- reg);
-#endif
- raw_write16(chgnum, BQ25710_REG_PROCHOT_OPTION_1, reg);
- }
+ bq257x0_init_prochot_option_1(chgnum);
/* Reduce ILIM from default of 150% to 105% */
if (!raw_read16(chgnum, BQ25710_REG_PROCHOT_OPTION_0, &reg)) {
diff --git a/driver/charger/bq257x0_regs.h b/driver/charger/bq257x0_regs.h
index 0c88735c95..5a8b1fdd96 100644
--- a/driver/charger/bq257x0_regs.h
+++ b/driver/charger/bq257x0_regs.h
@@ -144,12 +144,18 @@
#define BQ257X0_PROCHOT_OPTION_1_PP_IDCHG_SHIFT 3
#define BQ257X0_PROCHOT_OPTION_1_PP_IDCHG_BITS 1
+#define BQ257X0_PROCHOT_OPTION_1_PP_IDCHG__DISABLE 0
+#define BQ257X0_PROCHOT_OPTION_1_PP_IDCHG__ENABLE 1
#define BQ257X0_PROCHOT_OPTION_1_PP_VDPM_SHIFT 7
#define BQ257X0_PROCHOT_OPTION_1_PP_VDPM_BITS 1
+#define BQ257X0_PROCHOT_OPTION_1_PP_VDPM__DISABLE 0
+#define BQ257X0_PROCHOT_OPTION_1_PP_VDPM__ENABLE 1
#define BQ257X0_PROCHOT_OPTION_1_PP_VSYS_SHIFT 2
#define BQ257X0_PROCHOT_OPTION_1_PP_VSYS_BITS 1
+#define BQ257X0_PROCHOT_OPTION_1_PP_VSYS__DISABLE 0
+#define BQ257X0_PROCHOT_OPTION_1_PP_VSYS__ENABLE 1
#define BQ257X0_PROCHOT_OPTION_1_PP_BATPRES_SHIFT 1
#define BQ257X0_PROCHOT_OPTION_1_PP_BATPRES_BITS 1