summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-08-08 10:54:08 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-12 05:11:39 +0000
commit283fe98939fa56c61280529e2f933bedb122a52a (patch)
tree9f23119e61da776c19363b572204071549ae2b0b /common
parentadbd5a0c9a6749468b7c085029cf5e5a41595dbf (diff)
downloadchrome-ec-283fe98939fa56c61280529e2f933bedb122a52a.tar.gz
samus: ryu: fix charge state machine init of input currentstabilize-6146.B
Currently charge state machine resets input current limit to default every time AC is connected. Problem is by the time charge state machine gets around to setting input current, it could have already been set by successful PD negotiation, and this ends up overriding that value. This fix has the state machine store desired input current limit, as determined from PD negotation or any other place, and send last desired input current limit on AC connect. BUG=chrome-os-partner:24461 BRANCH=none TEST=load on samus, test toggling between "pd 0 dev 5" and "pd 0 dev 20", and test plugging and unplugging zinger numerous times, and verify charger command always gives the expected input current limit based on PD negotiation. Change-Id: I18d8acc9e2085739e783c9c70c682d46bcce7fdb Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/211639 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/charge_state_v2.c24
-rw-r--r--common/host_command_pd.c2
2 files changed, 21 insertions, 5 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 9505194720..f51a03f185 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -53,6 +53,7 @@ enum problem_type {
PR_SET_VOLTAGE,
PR_SET_CURRENT,
PR_SET_MODE,
+ PR_SET_INPUT_CURR,
PR_POST_INIT,
PR_CHG_FLAGS,
PR_BATT_FLAGS,
@@ -65,6 +66,7 @@ static const char * const prob_text[] = {
"set voltage",
"set current",
"set mode",
+ "set input current",
"post init",
"chg params",
"batt params",
@@ -464,6 +466,7 @@ void charger_task(void)
/* Initialize all the state */
memset(&curr, 0, sizeof(curr));
curr.batt.is_present = BP_NOT_SURE;
+ curr.desired_input_current = CONFIG_CHARGER_INPUT_CURRENT;
prev_ac = prev_charge = -1;
state_machine_force_idle = 0;
shutdown_warning_time.val = 0UL;
@@ -481,13 +484,20 @@ void charger_task(void)
/*
* Some chargers are unpowered when the AC is
* off, so we'll reinitialize it when AC
- * comes back. Try again if it fails.
+ * comes back and set the input current limit.
+ * Try again if it fails.
*/
int rv = charger_post_init();
- if (rv != EC_SUCCESS)
+ if (rv != EC_SUCCESS) {
problem(PR_POST_INIT, rv);
- else
- prev_ac = curr.ac;
+ } else {
+ rv = charger_set_input_current(
+ curr.desired_input_current);
+ if (rv != EC_SUCCESS)
+ problem(PR_SET_INPUT_CURR, rv);
+ else
+ prev_ac = curr.ac;
+ }
} else {
/* Some things are only meaningful on AC */
state_machine_force_idle = 0;
@@ -811,6 +821,12 @@ int charge_temp_sensor_get_val(int idx, int *temp_ptr)
return EC_SUCCESS;
}
+int charge_set_input_current_limit(int ma)
+{
+ curr.desired_input_current = ma;
+ return charger_set_input_current(ma);
+}
+
/*****************************************************************************/
/* Hooks */
diff --git a/common/host_command_pd.c b/common/host_command_pd.c
index 1216d28ae3..82d58f79aa 100644
--- a/common/host_command_pd.c
+++ b/common/host_command_pd.c
@@ -57,7 +57,7 @@ static void pd_exchange_status(void)
*/
pd_status.curr_lim_ma = pd_status.curr_lim_ma * 2 / 3;
#endif
- rv = charger_set_input_current(MAX(pd_status.curr_lim_ma,
+ rv = charge_set_input_current_limit(MAX(pd_status.curr_lim_ma,
CONFIG_CHARGER_INPUT_CURRENT));
if (rv < 0)
CPRINTS("Failed to set input current limit from PD MCU");