summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2020-07-15 21:05:06 -0700
committerCommit Bot <commit-bot@chromium.org>2020-07-21 01:34:55 +0000
commit1df7e6e4c100d1463624ca8f21707bd79457e533 (patch)
tree4618d2ebc984ee9642aa2cae5ee0551401e05002 /driver
parentb72dd67b84b8b122a880b59b0a10455baf93fb62 (diff)
downloadchrome-ec-1df7e6e4c100d1463624ca8f21707bd79457e533.tar.gz
sm5803: Set precharge termination threshold
The default precharge termination threshold is set by default to 4V/cell. This is not suitable for all batteries and would often be too high resulting in a reduced charging rate for the batteries. This commit changes the SM5803 driver to use the battery's defined minimum voltage as the precharge threshold. This will be determined when the system decides to charge the battery. BUG=b:161408901 BRANCH=None TEST=Build and flash waddledee rev 1, plug in battery with 1% SOC, verify that the DUT ends up charging the battery at the desired current rate instead of just 500mA. TEST=Cut battery off, plug in charger, verify that when battery wakes up, it is charging at the desired current rate. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: I363cf09bf43c4078234f49a3c67d0a953c4e255a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2300845 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/charger/sm5803.c18
-rw-r--r--driver/charger/sm5803.h10
2 files changed, 28 insertions, 0 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c
index 132e2e5a9c..37c055bef5 100644
--- a/driver/charger/sm5803.c
+++ b/driver/charger/sm5803.c
@@ -16,6 +16,7 @@
#include "timer.h"
#include "usb_charge.h"
#include "usb_pd.h"
+#include "util.h"
#ifndef CONFIG_CHARGER_NARROW_VDC
#error "SM5803 is a NVDC charger, please enable CONFIG_CHARGER_NARROW_VDC."
@@ -207,6 +208,9 @@ static void sm5803_init(int chgnum)
enum ec_error_list rv;
int reg;
int vbus_mv;
+ const struct battery_info *batt_info;
+ int pre_term;
+ int cells;
/*
* If a charger is not currently present, disable switching per OCPC
@@ -404,6 +408,20 @@ static void sm5803_init(int chgnum)
*/
rv |= chg_write8(chgnum, SM5803_REG_FLOW2, SM5803_FLOW2_HOST_MODE_EN);
+ /* Setup the proper precharge thresholds. */
+ batt_info = battery_get_info();
+ cells = batt_info->voltage_max / 4;
+ pre_term = batt_info->voltage_min / cells;
+ pre_term /= 100; /* Convert to decivolts. */
+ pre_term = CLAMP(pre_term, SM5803_VBAT_PRE_TERM_MIN_DV,
+ SM5803_VBAT_PRE_TERM_MAX_DV);
+ pre_term -= SM5803_VBAT_PRE_TERM_MIN_DV; /* Convert to regval */
+
+ rv |= chg_read8(chgnum, SM5803_REG_PRE_FAST_CONF_REG1, &reg);
+ reg &= ~SM5803_VBAT_PRE_TERM;
+ reg |= pre_term << SM5803_VBAT_PRE_TERM_SHIFT;
+ rv |= chg_write8(chgnum, SM5803_REG_PRE_FAST_CONF_REG1, reg);
+
if (rv)
CPRINTS("%s %d: Failed initialization", CHARGER_NAME, chgnum);
}
diff --git a/driver/charger/sm5803.h b/driver/charger/sm5803.h
index 5067863bf1..f2791edca3 100644
--- a/driver/charger/sm5803.h
+++ b/driver/charger/sm5803.h
@@ -215,6 +215,16 @@ enum sm5803_gpio0_modes {
/ SM5803_VOLTAGE_STEP)
/*
+ * Precharge Termination threshold.
+ */
+#define SM5803_REG_PRE_FAST_CONF_REG1 0x39
+#define SM5803_VBAT_PRE_TERM_MIN_DV 23
+/* 3.8V+ gets rounded to 4V */
+#define SM5803_VBAT_PRE_TERM_MAX_DV 38
+#define SM5803_VBAT_PRE_TERM GENMASK(7, 4)
+#define SM5803_VBAT_PRE_TERM_SHIFT 4
+
+/*
* Vbat for fast charge uses the same equation as Vsys
* Lower saturation value is 3V, upper is dependent on number of cells
*/