summaryrefslogtreecommitdiff
path: root/driver/battery
diff options
context:
space:
mode:
authorRuben Rodriguez Buchillon <coconutruben@chromium.org>2017-11-28 11:01:47 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-01-16 04:08:26 -0800
commit51e9e69f386366256807e6f4ccdd258821cdcfe0 (patch)
treec6fc8260505edadf8da3e6e0237a7bc6b3906da3 /driver/battery
parentbe1f97a2551549d81f77f0439a23683343234c40 (diff)
downloadchrome-ec-51e9e69f386366256807e6f4ccdd258821cdcfe0.tar.gz
power: introducing pwr_avg console command
pwr_avg provides an average voltage, current, and power over the last 1 minute. It's up to the battery drivers to implement this functionality. This change allows us to have better power tracking while minimizing the power impact on the EC, because - the pwr_avg command only needs to be called once every minute, and is short, thus less expensive to parse on ECs without a UART buffer - the work done to keep the avg is partially done by the batteries already and it's just a question of retrieving it. undefined on wheatley since no power debugging planned on that board. usage: > pwr_avg mv = 7153 ma = -605 mw = -4327 BUG=chromium:752320 BRANCH=None TEST=make buildall -j Change-Id: Id1a3479d277aedf90dfa965afb4ee9136654b1cf Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/823884 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'driver/battery')
-rw-r--r--driver/battery/max17055.c14
-rw-r--r--driver/battery/smart.c24
2 files changed, 38 insertions, 0 deletions
diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c
index cd0a379e8e..1a38c2748f 100644
--- a/driver/battery/max17055.c
+++ b/driver/battery/max17055.c
@@ -263,6 +263,20 @@ void battery_get_params(struct batt_params *batt)
batt->flags |= BATT_FLAG_WANT_CHARGE;
}
+#ifdef CONFIG_CMD_PWR_AVG
+int battery_get_avg_current(void)
+{
+ /* TODO(crbug.com/752320) implement this */
+ return EC_ERROR_UNIMPLEMENTED;
+}
+
+int battery_get_avg_voltage(void)
+{
+ /* TODO(crbug.com/752320) implement this */
+ return -EC_ERROR_UNIMPLEMENTED;
+}
+#endif /* CONFIG_CMD_PWR_AVG */
+
/* Wait until battery is totally stable. */
int battery_wait_for_stable(void)
{
diff --git a/driver/battery/smart.c b/driver/battery/smart.c
index bbbec8f21e..743ebc1ee1 100644
--- a/driver/battery/smart.c
+++ b/driver/battery/smart.c
@@ -283,6 +283,30 @@ test_mockable int battery_device_chemistry(char *dest, int size)
return sb_read_string(SB_DEVICE_CHEMISTRY, dest, size);
}
+#ifdef CONFIG_CMD_PWR_AVG
+int battery_get_avg_current(void)
+{
+ int current;
+
+ /* This is a signed 16-bit value. */
+ sb_read(SB_AVERAGE_CURRENT, &current);
+ return (int16_t)current;
+}
+
+/*
+ * Technically returns only the instantaneous reading, but tests showed that
+ * for the majority of charge states above 3% this varies by less than 40mV
+ * every minute, so we accept the inaccuracy here.
+ */
+int battery_get_avg_voltage(void)
+{
+ int voltage = -EC_ERROR_UNKNOWN;
+
+ sb_read(SB_VOLTAGE, &voltage);
+ return voltage;
+}
+#endif /* CONFIG_CMD_PWR_AVG */
+
void battery_get_params(struct batt_params *batt)
{
struct batt_params batt_new = {0};