summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Lu <Devin.Lu@quantatw.com>2020-11-06 10:30:53 +0800
committerCommit Bot <commit-bot@chromium.org>2020-11-12 06:02:00 +0000
commit14f66b993fb5b3a59eb042d9b98566deca68e4b1 (patch)
tree912a1a35d89341ac8fb58825edb7f4fae9fcbe09
parentf4b4cb8ef5f2ce35ada73b35596b699bbb161249 (diff)
downloadchrome-ec-14f66b993fb5b3a59eb042d9b98566deca68e4b1.tar.gz
sm5803: Add hardware charging ramping
This patch add support hardware charging ramp. The hw ramp is implemented by enabling DPM (Dynamic Power Management). Once a DPM Voltage loop regulation is set and the DPM loop is enabled, the DPM guarantees that the Vbus will not go below the threshold voltage limiting the power that can be delivered to the load. BUG=b:172173517 BRANCH=none TEST=On drawcia, i2ctrace to make sure DPM is enabled with 5V source. Signed-off-by: Devin Lu <Devin.Lu@quantatw.com> Change-Id: I0622da35bf57f367b21e97c5e39cb157ef911521 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2521551 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--driver/charger/sm5803.c84
-rw-r--r--driver/charger/sm5803.h11
2 files changed, 69 insertions, 26 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c
index 161da8d6b5..99e4600f7c 100644
--- a/driver/charger/sm5803.c
+++ b/driver/charger/sm5803.c
@@ -127,32 +127,7 @@ static inline enum ec_error_list test_update8(int chgnum, const int offset,
static enum ec_error_list sm5803_flow1_update(int chgnum, const uint8_t mask,
const enum mask_update_action action)
{
- int reg, rv, dev_id;
-
- /*
- * On Si rev 3, confirm that init value in 0x5C is intact before
- * enabling charging.
- */
- rv = sm5803_get_dev_id(chgnum, &dev_id);
- if (rv)
- return rv;
-
- if (dev_id == 0x03) {
- rv = chg_read8(chgnum, 0x5C, &reg);
- if (rv) {
- CPRINTS("%s %d: Failed 0x5C read",
- CHARGER_NAME, chgnum);
- return rv;
- }
-
- if (reg != 0x7A) {
- CPRINTS("%s %d: Unexpected 0x5C reg: 0x%02x. File bug",
- CHARGER_NAME, chgnum, reg);
-
- /* Fix it before enabling charging */
- rv = chg_write8(chgnum, 0x5C, 0x7A);
- }
- }
+ int rv;
/* Safety checks done, onto the actual register update */
mutex_lock(&flow1_access_lock[chgnum]);
@@ -603,6 +578,11 @@ static void sm5803_init(int chgnum)
reg &= ~SM5803_PHOT1_IBUS_PHOT_COMP_EN;
rv |= chg_write8(chgnum, SM5803_REG_PHOT1, reg);
+ /* Set DPM Voltage to 4200 mv, see b:172173517 */
+ reg = SM5803_VOLTAGE_TO_REG(4200);
+ rv = chg_write8(chgnum, SM5803_REG_DPM_VL_SET_MSB, (reg >> 3));
+ rv |= chg_write8(chgnum, SM5803_REG_DPM_VL_SET_LSB, (reg & 0x7));
+
if (chgnum != CHARGER_PRIMARY) {
/*
* Enable the IBAT_CHG adc in order to calculate
@@ -1484,6 +1464,52 @@ static enum ec_error_list sm5803_set_vsys_compensation(int chgnum,
return EC_ERROR_UNIMPLEMENTED;
}
+/* Hardware current ramping (aka DPM: Dynamic Power Management) */
+
+#ifdef CONFIG_CHARGE_RAMP_HW
+static enum ec_error_list sm5803_set_hw_ramp(int chgnum, int enable)
+{
+ enum ec_error_list rv;
+ int reg;
+
+ rv = chg_read8(chgnum, SM5803_REG_CHG_MON_REG, &reg);
+
+ if (enable)
+ reg |= SM5803_DPM_LOOP_EN;
+ else
+ reg &= ~SM5803_DPM_LOOP_EN;
+
+ rv |= chg_write8(chgnum, SM5803_REG_CHG_MON_REG, reg);
+
+ return rv;
+}
+
+static int sm5803_ramp_is_stable(int chgnum)
+{
+ /*
+ * There is no way to read current limit that the ramp has
+ * settled on with sm5803, so we don't consider the ramp stable,
+ * because we never know what the stable limit is.
+ */
+ return 0;
+}
+
+static int sm5803_ramp_is_detected(int chgnum)
+{
+ return 1;
+}
+
+static int sm5803_ramp_get_current_limit(int chgnum)
+{
+ int rv;
+ int input_current = 0;
+
+ rv = sm5803_get_input_current(chgnum, &input_current);
+
+ return rv ? -1 : input_current;
+}
+#endif /* CONFIG_CHARGE_RAMP_HW */
+
#ifdef CONFIG_CMD_CHARGER_DUMP
static int command_sm5803_dump(int argc, char **argv)
{
@@ -1554,4 +1580,10 @@ const struct charger_drv sm5803_drv = {
.enable_otg_power = &sm5803_enable_otg_power,
.is_sourcing_otg_power = &sm5803_is_sourcing_otg_power,
.set_vsys_compensation = &sm5803_set_vsys_compensation,
+#ifdef CONFIG_CHARGE_RAMP_HW
+ .set_hw_ramp = &sm5803_set_hw_ramp,
+ .ramp_is_stable = &sm5803_ramp_is_stable,
+ .ramp_is_detected = &sm5803_ramp_is_detected,
+ .ramp_get_current_limit = &sm5803_ramp_get_current_limit,
+#endif
};
diff --git a/driver/charger/sm5803.h b/driver/charger/sm5803.h
index 08e7494a00..65dc64f34f 100644
--- a/driver/charger/sm5803.h
+++ b/driver/charger/sm5803.h
@@ -229,6 +229,14 @@ enum sm5803_charger_modes {
#define SM5803_CURRENT_TO_REG(c) (c / SM5803_CURRENT_STEP)
/*
+ * DPM Voltage loop regulation contains the 8 bits with MSB register
+ * and the lower 3 bits with LSB register.
+ * The regulation value is 2.72 V + DPM_VL_SET * 10mV
+ */
+#define SM5803_REG_DPM_VL_SET_MSB 0x26
+#define SM5803_REG_DPM_VL_SET_LSB 0x27
+
+/*
* Output voltage uses the same equation as Vsys
* Lower saturation value is 3 V, upper 20.5 V
*/
@@ -324,6 +332,9 @@ enum sm5803_charger_modes {
#define SM5803_STATUS_DISCHG_VBUS_SHORT BIT(6)
#define SM5803_STATUS_DISCHG_OV_ITEMP BIT(7)
+#define SM5803_REG_CHG_MON_REG 0x5C
+#define SM5803_DPM_LOOP_EN BIT(0)
+
#define SM5803_REG_PHOT1 0x72
#define SM5803_PHOT1_IBAT_PHOT_COMP_EN BIT(0)
#define SM5803_PHOT1_IBUS_PHOT_COMP_EN BIT(1)