diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-11-06 13:13:37 -0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-12-02 22:03:51 +0000 |
commit | c0ec787ba10dd3ef5fc089cf1449468ec45ff668 (patch) | |
tree | 23c74570671da8750b1f299b6c9c7df1fe032943 /common/charger.c | |
parent | 5a3c90d5db8ce869cad977ed143a198e221689ae (diff) | |
download | chrome-ec-c0ec787ba10dd3ef5fc089cf1449468ec45ff668.tar.gz |
Add battery_get_params()
The charge state machine asks for all of this stuff at the same time
anyway. Bundling it into a single function removes a number of
redundant (and painfully slow) I2C reads.
Also refactor the battery debug command so it doesn't have so many
local variables all in one function; it was consuming considerably
more stack space than any other debug command.
Spring still needs low-level access to the smart battery, so move the
two functions it needs directly into the Spring implementation.
BUG=chrome-os-partner:20881
BRANCH=none
TEST=charge/discharge rambi, pit and spring; watch debug messages and
LED and output of 'battery' debug command. All should behave the
same as before. Then run 'taskinfo' and see that the console task
has at least 20 bytes unused.
Change-Id: I951b569542e28bbbb58853d62b57b0aaaf183e3f
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/177797
Diffstat (limited to 'common/charger.c')
-rw-r--r-- | common/charger.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/common/charger.c b/common/charger.c index 15bdf8f73c..ebac3896c1 100644 --- a/common/charger.c +++ b/common/charger.c @@ -18,9 +18,20 @@ int charger_closest_voltage(int voltage) { - const struct charger_info *info; + const struct charger_info *info = charger_get_info(); + + /* + * If the requested voltage is non-zero but below our minimum, + * return the minimum. See crosbug.com/p/8662. + */ + if (voltage > 0 && voltage < info->voltage_min) + return info->voltage_min; + + /* Clip to max */ + if (voltage > info->voltage_max) + return info->voltage_max; - info = charger_get_info(); + /* Otherwise round down to nearest voltage step */ return voltage - (voltage % info->voltage_step); } |