summaryrefslogtreecommitdiff
path: root/driver/ln9310.c
diff options
context:
space:
mode:
authorWai-Hong Tam <waihong@google.com>2020-09-03 11:49:38 -0700
committerCommit Bot <commit-bot@chromium.org>2020-09-04 02:07:51 +0000
commita0695f17ca648883717bebfd1afeaaaf29d78e9d (patch)
tree90b4a3a94ca0b8654543437ee9aa803c7f2751a0 /driver/ln9310.c
parentf067a2682cb87cdacc890f82579120208913d2a6 (diff)
downloadchrome-ec-a0695f17ca648883717bebfd1afeaaaf29d78e9d.tar.gz
ln9310: Move battery cell type to board customization
Checking the input voltage to make the decision of 2S battery or 3S battery is not reliable. The 3S battery with very low charge might be under 10V that we initialized the switchcap to 2:1 mode. When the battery was then charged up to 12V, VOUT would go to 6 V which would be a problem. This change moves the decision to board customization. It checks the SKU ID. It can be extended to other ways, like checking the battery manufacturer and device names. To prevent any damage when attaching a 3S battery to a 2S-SKU board, add a check before configuring the switchcap to 2:1 mode. BRANCH=None BUG=b:163867792, b:151393598 TEST=Built successfully. Change-Id: I3f69132bc00b13ec39b229e98a34a5f7f75008f1 Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2391210 Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Diffstat (limited to 'driver/ln9310.c')
-rw-r--r--driver/ln9310.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/driver/ln9310.c b/driver/ln9310.c
index 5a82f3fa28..0bbf130683 100644
--- a/driver/ln9310.c
+++ b/driver/ln9310.c
@@ -76,11 +76,11 @@ void ln9310_interrupt(enum gpio_signal signal)
hook_call_deferred(&ln9310_irq_deferred_data, 0);
}
-static int is_battery_3s(void)
+static int is_battery_gt_10v(void)
{
- int status, val, batt3s;
+ int status, val, gt_10v;
- CPRINTS("LN9310 checking input voltage (2S/3S), threshold=10V");
+ CPRINTS("LN9310 checking input voltage, threshold=10V");
/*
* Turn on INFET_OUT_SWITCH_OK comparator;
* configure INFET_OUT_SWITCH_OK to 10V.
@@ -100,21 +100,21 @@ static int is_battery_3s(void)
CPRINTS("LN9310 BC_STS_B: 0x%x", val);
/*
- * If INFET_OUT_SWITCH_OK=0, VIN < 10V --> 2S battery
- * If INFET_OUT_SWITCH_OK=1, VIN > 10V --> 3S battery
+ * If INFET_OUT_SWITCH_OK=0, VIN < 10V
+ * If INFET_OUT_SWITCH_OK=1, VIN > 10V
*/
- batt3s = !!(val & LN9310_BC_STS_B_INFET_OUT_SWITCH_OK);
- CPRINTS("LN9310 %s battery detected", batt3s ? "3S" : "2S");
+ gt_10v = !!(val & LN9310_BC_STS_B_INFET_OUT_SWITCH_OK);
+ CPRINTS("LN9310 battery %s 10V", gt_10v ? ">" : "<");
/* Turn off INFET_OUT_SWITCH_OK comparator */
field_update8(LN9310_REG_TRACK_CTRL,
LN9310_TRACK_INFET_OUT_SWITCH_OK_EN_MASK,
LN9310_TRACK_INFET_OUT_SWITCH_OK_EN_OFF);
- return batt3s;
+ return gt_10v;
}
-static void ln9310_init_3to1(void)
+static int ln9310_init_3to1(void)
{
CPRINTS("LN9310 init (3:1 operation)");
@@ -136,12 +136,19 @@ static void ln9310_init_3to1(void)
field_update8(LN9310_REG_SYS_CTRL,
LN9310_SYS_CTRL_LB_DELTA_MASK,
LN9310_SYS_CTRL_LB_DELTA_3S);
+
+ return EC_SUCCESS;
}
-static void ln9310_init_2to1(void)
+static int ln9310_init_2to1(void)
{
CPRINTS("LN9310 init (2:1 operation)");
+ if (is_battery_gt_10v()) {
+ CPRINTS("LN9310 init stop. Input voltage is too high.");
+ return EC_ERROR_UNKNOWN;
+ }
+
/* Enable track protection and SC_OUT configs for 2:1 switching */
field_update8(LN9310_REG_MODE_CHANGE_CFG,
LN9310_MODE_TM_TRACK_MASK |
@@ -158,19 +165,27 @@ static void ln9310_init_2to1(void)
field_update8(LN9310_REG_SYS_CTRL,
LN9310_SYS_CTRL_LB_DELTA_MASK,
LN9310_SYS_CTRL_LB_DELTA_2S);
+
+ return EC_SUCCESS;
}
void ln9310_init(void)
{
- int status, val, batt3s;
+ int status, val;
+ enum battery_cell_type batt;
+
+ batt = board_get_battery_cell_type();
+ if (batt == BATTERY_CELL_TYPE_3S) {
+ status = ln9310_init_3to1();
+ } else if (batt == BATTERY_CELL_TYPE_2S) {
+ status = ln9310_init_2to1();
+ } else {
+ CPRINTS("LN9310 not supported battery type: %d", batt);
+ return;
+ }
- batt3s = is_battery_3s();
- if (batt3s == -1)
+ if (status != EC_SUCCESS)
return;
- else if (batt3s)
- ln9310_init_3to1();
- else
- ln9310_init_2to1();
/* Unmask the MODE change interrupt */
field_update8(LN9310_REG_INT1_MSK,