diff options
author | Aseda Aboagye <aaboagye@google.com> | 2021-03-10 18:59:35 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-03-11 20:11:44 +0000 |
commit | 7ad578bfb93e995b59841417f98dc693fa81e9a3 (patch) | |
tree | 1945f29c920ee0680e8c8cd9853be162c2f2266c /driver/charger/sm5803.c | |
parent | e8cb700579e12ddb0c0f2cda784f04adb6de40f8 (diff) | |
download | chrome-ec-7ad578bfb93e995b59841417f98dc693fa81e9a3.tar.gz |
charger: Add new APIs for measured charge values
Some of the charger ICs can provide measurements for the charge
voltage and the charge current. This information is needed by the
OCPC module. Previously, the charge_get_current() and
charge_get_voltage() functions were modified to provide this
information. However, those functions are intended to provide the set
voltage and current targets for the charger IC.
This commit adds a new set of APIs, charge_get_actual_current() and
charge_get_actual_voltage() which provides the actual charge current
and voltage if the charger IC is able to provide that information.
BUG=b:182018616
BRANCH=dedede
TEST=Build and flash madoo, verify that `charger` EC console command
shows the set current and voltage targets instead of the measured
values. Check that the `chgstate` command shows the measured values
for use with the OCPC module.
TEST=Verify that charging from the sub board works.
TEST=Verify that resistances are still calculated and seem reasonable.
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Change-Id: I82565d18908d9ea0f54934787897937488e280e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2750866
Reviewed-by: Diana Z <dzigterman@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/charger/sm5803.c')
-rw-r--r-- | driver/charger/sm5803.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c index 7997dc09d8..7c635ddb93 100644 --- a/driver/charger/sm5803.c +++ b/driver/charger/sm5803.c @@ -1212,7 +1212,7 @@ static enum ec_error_list sm5803_set_mode(int chgnum, int mode) return rv; } -static enum ec_error_list sm5803_get_current(int chgnum, int *current) +static enum ec_error_list sm5803_get_actual_current(int chgnum, int *current) { enum ec_error_list rv; int reg; @@ -1233,6 +1233,21 @@ static enum ec_error_list sm5803_get_current(int chgnum, int *current) return EC_SUCCESS; } +static enum ec_error_list sm5803_get_current(int chgnum, int *current) +{ + enum ec_error_list rv; + int reg; + + rv = chg_read8(chgnum, SM5803_REG_FAST_CONF4, ®); + if (rv) + return rv; + + reg &= SM5803_CONF4_ICHG_FAST; + *current = SM5803_REG_TO_CURRENT(reg); + + return EC_SUCCESS; +} + static enum ec_error_list sm5803_set_current(int chgnum, int current) { enum ec_error_list rv; @@ -1249,7 +1264,7 @@ static enum ec_error_list sm5803_set_current(int chgnum, int current) return rv; } -static enum ec_error_list sm5803_get_voltage(int chgnum, int *voltage) +static enum ec_error_list sm5803_get_actual_voltage(int chgnum, int *voltage) { enum ec_error_list rv; int reg; @@ -1271,6 +1286,25 @@ static enum ec_error_list sm5803_get_voltage(int chgnum, int *voltage) return EC_SUCCESS; } +static enum ec_error_list sm5803_get_voltage(int chgnum, int *voltage) +{ + enum ec_error_list rv; + int regval; + int v; + + rv = chg_read8(chgnum, SM5803_REG_VBAT_FAST_MSB, ®val); + v = regval << 3; + rv |= chg_read8(chgnum, SM5803_REG_VBAT_FAST_LSB, ®val); + v |= (regval & 0x3); + + *voltage = SM5803_REG_TO_VOLTAGE(v); + + if (rv) + return EC_ERROR_UNKNOWN; + + return EC_SUCCESS; +} + static enum ec_error_list sm5803_set_voltage(int chgnum, int voltage) { enum ec_error_list rv; @@ -1716,8 +1750,10 @@ const struct charger_drv sm5803_drv = { .get_info = &sm5803_get_info, .get_status = &sm5803_get_status, .set_mode = &sm5803_set_mode, + .get_actual_current = &sm5803_get_actual_current, .get_current = &sm5803_get_current, .set_current = &sm5803_set_current, + .get_actual_voltage = &sm5803_get_actual_voltage, .get_voltage = &sm5803_get_voltage, .set_voltage = &sm5803_set_voltage, .discharge_on_ac = &sm5803_discharge_on_ac, |