summaryrefslogtreecommitdiff
path: root/include/charge_state_v2.h
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2014-03-26 16:56:38 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-04-01 21:37:32 +0000
commit9f40d3f90e7373b96256033b3ec7b4b8e5140881 (patch)
treebb2f4dc8742f869667938f8ee7a2ad4fb9cb38f8 /include/charge_state_v2.h
parent71766a39262b6ed4fec51cba19f10c6bec7e9f19 (diff)
downloadchrome-ec-9f40d3f90e7373b96256033b3ec7b4b8e5140881.tar.gz
Add charge_state_v2 algorithm for use by Samus
This is a complete rewrite of the charge_state task used by x86 platforms. Rather than having a bunch of state-specific functions, each with their own error handling and special cases, this is organized like so: Forever: 1. Read everything we can from the battery and charger. 2. Figure out what we'd like to do (including error handling). 3. Allow for customization to override that. 4. Do it. Things I need to file bugs for are marked with "TODO(wfrichar)". I'll file the bugs after this CL goes in, so that they'll have something relevant to refer to. BUG=chrome-os-partner:20881 BRANCH=ToT TEST=manual make buildall -j Try it on Samus, watch it charge from nearly empty to full, both with and without fastcharge enabled. Also undefine CONFIG_BATTERY_PRESENT_CUSTOM, plug and unplug the battery to be sure the trickle charging logic is correct when it can't tell if the battery is present. Change-Id: I3935cd3b87f322eb52178f8a675a886c16b75d58 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/191767 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'include/charge_state_v2.h')
-rw-r--r--include/charge_state_v2.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h
index 085f2a2047..16d8ee61ad 100644
--- a/include/charge_state_v2.h
+++ b/include/charge_state_v2.h
@@ -4,11 +4,49 @@
*/
#include "battery.h"
+#include "charger.h"
#include "timer.h"
#ifndef __CROS_EC_CHARGE_STATE_V2_H
#define __CROS_EC_CHARGE_STATE_V2_H
+/*
+ * The values exported by charge_get_state() and charge_get_flags() are used
+ * only to control the LEDs (with one not-quite-correct exception). For V2
+ * we use a different set of states internally.
+ */
+enum charge_state_v2 {
+ ST_IDLE = 0,
+ ST_DISCHARGE,
+ ST_CHARGE,
+ ST_PRECHARGE,
+
+ NUM_STATES_V2
+};
+
+struct charge_state_data {
+ timestamp_t ts;
+ int ac;
+ struct charger_params chg;
+ struct batt_params batt;
+ enum charge_state_v2 state;
+ int requested_voltage;
+ int requested_current;
+};
+
+/*
+ * Optional customization.
+ *
+ * On input, the struct reflects the default behavior. The function can make
+ * changes to the state, requested_voltage, or requested_current.
+ *
+ * Return value:
+ * >0 Desired time in usec for this poll period.
+ * 0 Use the default poll period (which varies with the state).
+ * <0 An error occurred. The poll time will be shorter than usual. Too
+ * many errors in a row may trigger some corrective action.
+ */
+int charger_profile_override(struct charge_state_data *);
#endif /* __CROS_EC_CHARGE_STATE_V2_H */