summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2020-08-27 17:23:06 -0700
committerCommit Bot <commit-bot@chromium.org>2020-08-29 22:42:41 +0000
commitb2630346db6abaa115db405be3665304c3565b48 (patch)
treebdaadd90866a19282ad01597be2869c131677ef8
parentdc52b5b9c097da9620fede757e5e23fae2de7a7e (diff)
downloadchrome-ec-b2630346db6abaa115db405be3665304c3565b48.tar.gz
sm5803: Configure BFET alerts
The SM5803 has the capability to monitor to the power burnt across the BFET. There are two thresholds that can be configured: an early threshold, and a fatal threshold in which the charger automatically disables the BFET. This commit configures the BFET alerts to fire at 1.5W for the early threshold and 6.5W for the fatal threshold. The full scale is 7.5W, the lsb is 7.5W/256 ~= 29.2mW. BUG=b:159376384 BRANCH=None TEST=Build and flash waddledee, charge from sub board, verify that no alerts are seen. TEST=Configure the thresholds significantly lower, charge from sub board, verify that the alerts do fire and logging information is printed on the EC console. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: I17b3876bc5ed4b41d2378600a8b8bf639f9757ce Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2380404 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Auto-Submit: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: David Schneider <dnschneid@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2383914 Reviewed-by: Edward Hill <ecgh@chromium.org> Commit-Queue: Edward Hill <ecgh@chromium.org> Tested-by: Edward Hill <ecgh@chromium.org>
-rw-r--r--driver/charger/sm5803.c43
-rw-r--r--driver/charger/sm5803.h19
2 files changed, 54 insertions, 8 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c
index 63ad62ab16..17343fb3e2 100644
--- a/driver/charger/sm5803.c
+++ b/driver/charger/sm5803.c
@@ -603,6 +603,23 @@ static void sm5803_init(int chgnum)
reg = SM5803_CURRENT_TO_REG(batt_info->precharge_current);
reg = MIN(reg, SM5803_PRECHG_ICHG_PRE_SET);
rv |= chg_write8(chgnum, SM5803_REG_PRECHG, reg);
+
+ /*
+ * Set up BFET alerts
+ *
+ * We'll set the soft limit at 1.5W and the hard limit at 6W.
+ *
+ * The register is 29.2 mW per bit.
+ */
+ reg = (1500 * 10) / 292;
+ rv |= meas_write8(chgnum, SM5803_REG_BFET_PWR_MAX_TH, reg);
+ reg = (6000 * 10) / 292;
+ rv |= meas_write8(chgnum, SM5803_REG_BFET_PWR_HWSAFE_MAX_TH,
+ reg);
+ rv |= main_read8(chgnum, SM5803_REG_INT3_EN, &reg);
+ reg |= SM5803_INT3_BFET_PWR_LIMIT |
+ SM5803_INT3_BFET_PWR_HWSAFE_LIMIT;
+ rv |= main_write8(chgnum, SM5803_REG_INT3_EN, reg);
}
if (rv)
@@ -624,6 +641,8 @@ void sm5803_handle_interrupt(int chgnum)
enum ec_error_list rv;
int int_reg, meas_reg;
static bool throttled;
+ struct batt_params bp;
+ int act_chg, val;
/* Note: Interrupt registers are clear on read */
rv = main_read8(chgnum, SM5803_REG_INT1_REQ, &int_reg);
@@ -678,6 +697,30 @@ void sm5803_handle_interrupt(int chgnum)
*/
}
+ /* TODO(b/159376384): Take action on fatal BFET power alert. */
+ rv = main_read8(chgnum, SM5803_REG_INT3_REQ, &int_reg);
+ if (rv) {
+ CPRINTS("%s %d: Failed to read int3 register", CHARGER_NAME,
+ chgnum);
+ return;
+ }
+
+ if ((int_reg & SM5803_INT3_BFET_PWR_LIMIT) ||
+ (int_reg & SM5803_INT3_BFET_PWR_HWSAFE_LIMIT)) {
+ battery_get_params(&bp);
+ act_chg = charge_manager_get_active_charge_port();
+ CPRINTS("%s BFET power limit reached! (%s)", CHARGER_NAME,
+ (int_reg & SM5803_INT3_BFET_PWR_LIMIT) ? "warn" :
+ "FATAL");
+ CPRINTS("\tVbat: %dmV", bp.voltage);
+ CPRINTS("\tIbat: %dmA", bp.current);
+ charger_get_voltage(act_chg, &val);
+ CPRINTS("\tVsys(aux): %dmV", val);
+ charger_get_current(act_chg, &val);
+ CPRINTS("\tIsys: %dmA", val);
+ cflush();
+ }
+
rv = main_read8(chgnum, SM5803_REG_INT4_REQ, &int_reg);
if (rv) {
CPRINTS("%s %d: Failed to read int4 register", CHARGER_NAME,
diff --git a/driver/charger/sm5803.h b/driver/charger/sm5803.h
index 75e4885cbc..7c0eaca78b 100644
--- a/driver/charger/sm5803.h
+++ b/driver/charger/sm5803.h
@@ -52,14 +52,14 @@
#define SM5803_INT2_VSYS BIT(6)
#define SM5803_INT2_TINT BIT(7)
-#define SM5803_REG_INT3_REQ 0x07
-#define SM5803_REG_INT3_EN 0x0C
-#define SM5803_INT3_GPADC0 BIT(0)
-#define SM5803_INT3_VBATC1 BIT(1)
-#define SM5803_INT3_VBATC2 BIT(2)
-#define SM5803_INT3_SPARE BIT(3)
-#define SM5803_INT3_VBUS_PWR_LIMIT BIT(4)
-#define SM5803_INT3_IBAT BIT(5)
+#define SM5803_REG_INT3_REQ 0x07
+#define SM5803_REG_INT3_EN 0x0C
+#define SM5803_INT3_GPADC0 BIT(0)
+#define SM5803_INT3_BFET_PWR_LIMIT BIT(1)
+#define SM5803_INT3_BFET_PWR_HWSAFE_LIMIT BIT(2)
+#define SM5803_INT3_SPARE BIT(3)
+#define SM5803_INT3_VBUS_PWR_LIMIT BIT(4)
+#define SM5803_INT3_IBAT BIT(5)
#define SM5803_REG_INT4_REQ 0x08
#define SM5803_REG_INT4_EN 0x0D
@@ -96,6 +96,9 @@ enum sm5803_gpio0_modes {
GPIO0_MODE_INPUT
};
+#define SM5803_REG_BFET_PWR_MAX_TH 0x35
+#define SM5803_REG_BFET_PWR_HWSAFE_MAX_TH 0x36
+
#define SM5803_REG_PORTS_CTRL 0x40
#define SM5803_PORTS_VBUS_DISCH BIT(0)
#define SM5803_PORTS_VBUS_PULLDOWN BIT(1)