summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-04-09 16:48:41 -0600
committerCommit Bot <commit-bot@chromium.org>2020-04-21 07:12:23 +0000
commit82065675d1a81520fe093db90257889711780911 (patch)
treee369cbebde068190c49f9b26dc69d82c18932222
parentd174f05944c3d80125aac081682e703ed0c22f0d (diff)
downloadchrome-ec-82065675d1a81520fe093db90257889711780911.tar.gz
SM5803: Add new init parameters
Add parameters for initialization needed for 3S batteries on this revision of silicon. BRANCH=None BUG=b:153922818 TEST=on waddledee, battery is able to charge through motherboard without noticeable noise Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I1f74d7929fa273cdd8ab0e195e6dca8c6cfa2c91 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2145075 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--driver/charger/sm5803.c76
-rw-r--r--driver/charger/sm5803.h8
2 files changed, 82 insertions, 2 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c
index 78b42579bc..1eb23e6d3c 100644
--- a/driver/charger/sm5803.c
+++ b/driver/charger/sm5803.c
@@ -12,6 +12,7 @@
#include "i2c.h"
#include "sm5803.h"
#include "throttle_ap.h"
+#include "timer.h"
#include "usb_charge.h"
#ifndef CONFIG_CHARGER_NARROW_VDC
@@ -176,6 +177,75 @@ static void sm5803_init(int chgnum)
enum ec_error_list rv;
int reg;
+ /* --- Special register init ---
+ * Only for early silicon, and can be removed later
+ *
+ * Can be run with CHG_EN set to 1 if Vbus is present and Vsys is
+ * stable. Otherwise, clear CHG_EN for init process.
+ */
+ rv = main_read8(chgnum, SM5803_REG_STATUS1, &reg);
+ if (rv == EC_SUCCESS) {
+ if (!(reg & SM5803_STATUS1_CHG_DET)) {
+ /*
+ * No charger connected, disable CHG_EN
+ * (note other bits default to 0)
+ */
+ rv = chg_write8(chgnum, SM5803_FLOW1_CHG_EN,
+ 0);
+ }
+ } else {
+ CPRINTS("%s %d: Failed to read status during init",
+ CHARGER_NAME, chgnum);
+ return;
+ }
+
+ rv |= main_write8(chgnum, 0x20, 0x08);
+ rv |= main_write8(chgnum, 0x30, 0xC0);
+ rv |= main_write8(chgnum, 0x80, 0x01);
+
+ rv |= meas_write8(chgnum, 0x08, 0xC2);
+
+ rv |= chg_write8(chgnum, 0x1D, 0x40);
+ rv |= chg_write8(chgnum, 0x1F, 0x09);
+
+ rv |= chg_write8(chgnum, 0x22, 0xB3);
+ rv |= chg_write8(chgnum, 0x23, 0x81);
+ rv |= chg_write8(chgnum, 0x28, 0xB7);
+
+ rv |= chg_write8(chgnum, 0x4A, 0x82);
+ rv |= chg_write8(chgnum, 0x4B, 0xA3);
+ rv |= chg_write8(chgnum, 0x4C, 0xA8);
+ rv |= chg_write8(chgnum, 0x4D, 0xCA);
+ rv |= chg_write8(chgnum, 0x4E, 0x07);
+ rv |= chg_write8(chgnum, 0x4F, 0xFF);
+
+ rv |= chg_write8(chgnum, 0x50, 0x98);
+ rv |= chg_write8(chgnum, 0x51, 0x80);
+ rv |= chg_write8(chgnum, 0x52, 0x77);
+ rv |= chg_write8(chgnum, 0x53, 0xD0);
+ rv |= chg_write8(chgnum, 0x54, 0x03);
+ rv |= chg_write8(chgnum, 0x55, 0xF1);
+ rv |= chg_write8(chgnum, 0x56, 0xFF);
+ rv |= chg_write8(chgnum, 0x57, 0x03);
+ rv |= chg_write8(chgnum, 0x58, 0xF1);
+ rv |= chg_write8(chgnum, 0x59, 0xFF);
+ rv |= chg_write8(chgnum, 0x5A, 0x10);
+ rv |= chg_write8(chgnum, 0x5B, 0x00);
+ rv |= chg_write8(chgnum, 0x5C, 0x5B);
+ rv |= chg_write8(chgnum, 0x5D, 0xB0);
+ rv |= chg_write8(chgnum, 0x5E, 0x3C);
+ rv |= chg_write8(chgnum, 0x5F, 0x3C);
+
+ rv |= chg_write8(chgnum, 0x60, 0xAA);
+ rv |= chg_write8(chgnum, 0x61, 0x20);
+ rv |= chg_write8(chgnum, 0x65, 0x3E);
+ rv |= chg_write8(chgnum, 0x66, 0x36);
+ rv |= chg_write8(chgnum, 0x67, 0x64);
+ rv |= chg_write8(chgnum, 0x68, 0x88);
+ rv |= chg_write8(chgnum, 0x69, 0xC7);
+
+ /* --- End special register init section --- */
+
/* Set default input current */
reg = SM5803_CURRENT_TO_REG(CONFIG_CHARGER_INPUT_CURRENT)
& SM5803_CHG_ILIM_RAW;
@@ -197,6 +267,12 @@ static void sm5803_init(int chgnum)
rv |= meas_write8(chgnum, SM5803_REG_TINT_LOW_TH,
SM5803_TINT_LOW_LEVEL);
+ /*
+ * Configure CHG_ENABLE to only be set through I2C by setting
+ * HOST_MODE_EN bit (all other register bits are 0 by default)
+ */
+ rv |= chg_write8(chgnum, SM5803_REG_FLOW2, SM5803_FLOW2_HOST_MODE_EN);
+
if (rv)
CPRINTS("%s %d: Failed initialization", CHARGER_NAME, chgnum);
}
diff --git a/driver/charger/sm5803.h b/driver/charger/sm5803.h
index bd34fd0630..ae93b7e814 100644
--- a/driver/charger/sm5803.h
+++ b/driver/charger/sm5803.h
@@ -98,14 +98,18 @@ enum sm5803_gpio0_modes {
/* ADC Registers (address 0x31) */
+/*
+ * Note: Some register bits must be enabled for the DC-DC converter to properly
+ * handle transitions.
+ */
#define SM5803_REG_GPADC_CONFIG1 0x01
#define SM5803_GPADCC1_VBATSNSP_EN BIT(0)
#define SM5803_GPADCC1_IBAT_DIS_EN BIT(1)
#define SM5803_GPADCC1_IBAT_CHG_EN BIT(2)
#define SM5803_GPADCC1_IBUS_EN BIT(3)
#define SM5803_GPADCC1_VBUS_EN BIT(4)
-#define SM5803_GPADCC1_VCHGPWR_EN BIT(5)
-#define SM5803_GPADCC1_VSYS_EN BIT(6)
+#define SM5803_GPADCC1_VCHGPWR_EN BIT(5) /* NOTE: DO NOT CLEAR */
+#define SM5803_GPADCC1_VSYS_EN BIT(6) /* NOTE: DO NOT CLEAR */
#define SM5803_GPADCC1_TINT_EN BIT(7)
/* Note: Threshold registers all assume lower 2 bits are 0 */