summaryrefslogtreecommitdiff
path: root/common/charger.c
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2021-03-10 18:59:35 -0800
committerCommit Bot <commit-bot@chromium.org>2021-03-11 20:11:44 +0000
commit7ad578bfb93e995b59841417f98dc693fa81e9a3 (patch)
tree1945f29c920ee0680e8c8cd9853be162c2f2266c /common/charger.c
parente8cb700579e12ddb0c0f2cda784f04adb6de40f8 (diff)
downloadchrome-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 'common/charger.c')
-rw-r--r--common/charger.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/common/charger.c b/common/charger.c
index f9fd1c4640..e3d77976ae 100644
--- a/common/charger.c
+++ b/common/charger.c
@@ -359,6 +359,23 @@ int charger_is_sourcing_otg_power(int port)
return chg_chips[chgnum].drv->is_sourcing_otg_power(chgnum, port);
}
+enum ec_error_list charger_get_actual_current(int chgnum, int *current)
+{
+ /* Note: chgnum may be -1 if no active port is selected */
+ if (chgnum < 0)
+ return EC_ERROR_INVAL;
+
+ if (chgnum >= board_get_charger_chip_count()) {
+ CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
+ return EC_ERROR_INVAL;
+ }
+
+ if (!chg_chips[chgnum].drv->get_actual_current)
+ return EC_ERROR_UNIMPLEMENTED;
+
+ return chg_chips[chgnum].drv->get_actual_current(chgnum, current);
+}
+
enum ec_error_list charger_get_current(int chgnum, int *current)
{
/* Note: chgnum may be -1 if no active port is selected */
@@ -389,6 +406,22 @@ enum ec_error_list charger_set_current(int chgnum, int current)
return chg_chips[chgnum].drv->set_current(chgnum, current);
}
+enum ec_error_list charger_get_actual_voltage(int chgnum, int *voltage)
+{
+ if (chgnum < 0)
+ return EC_ERROR_INVAL;
+
+ if (chgnum >= board_get_charger_chip_count()) {
+ CPRINTS("%s(%d) Invalid charger!", __func__, chgnum);
+ return EC_ERROR_INVAL;
+ }
+
+ if (!chg_chips[chgnum].drv->get_actual_voltage)
+ return EC_ERROR_UNIMPLEMENTED;
+
+ return chg_chips[chgnum].drv->get_actual_voltage(chgnum, voltage);
+}
+
enum ec_error_list charger_get_voltage(int chgnum, int *voltage)
{
if (chgnum < 0)