From 87d694a9064350ddfa961fbafff1a41e67620f33 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Fri, 13 Sep 2013 09:26:06 -0700 Subject: Falco: Always update charger's input current limit. I was just updating the input current limit when turbo mode was enabled and disabled. However, it turns out that the charger can decide to change the setting all by itself if the inrush current is too high. This happens pretty much every time that the AC is applied. We didn't notice this while the AP was on, but when the AP was off we were exiting the watch_adapter_closely() function too soon and so we missed the transition. This CL fixes that. But just to be safe, instead of only updating when we think we need to, we're going to just update the value every time we check on the adapter. That way if we happen to miss a change due to a race condition or transient, we'll catch it the next time through the loop. BUG=chrome-os-partner:20739 BRANCH=Falco,ToT TEST=manual Before this CL, you can run "sbc 0x3f" on the EC console while plugging and unplugging the AC adapter. When the AP is off and AC is reapplied, you'd see the reported value mysteriously change. After this CL, it doesn't. Change-Id: I5661c548cccd4eb24ba4d8a0b8cd070acc2e49ef Signed-off-by: Bill Richardson Reviewed-on: https://chromium-review.googlesource.com/169322 Reviewed-by: Randall Spangler (cherry picked from commit 1bcdd0eb6ff353a7215efe0b24630148ea7a9f28) Reviewed-on: https://chromium-review.googlesource.com/169391 --- common/extpower_falco.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/common/extpower_falco.c b/common/extpower_falco.c index ff1166f778..2eef487e9e 100644 --- a/common/extpower_falco.c +++ b/common/extpower_falco.c @@ -165,10 +165,8 @@ static void set_turbo(int on) { int tmp, r; - if (ac_turbo == on) - return; - - CPRINTF("[%T turbo mode => %d]\n", on); + if (ac_turbo != on) + CPRINTF("[%T turbo mode => %d]\n", on); /* Set/clear turbo mode in charger */ r = charger_get_option(&tmp); @@ -184,7 +182,9 @@ static void set_turbo(int on) if (r != EC_SUCCESS) goto bad; - /* Set allowed Io based on adapter */ + /* Set allowed Io based on adapter. The charger will sometimes change + * this setting all by itself due to inrush current limiting, so we + * can't assume it stays where we put it. */ r = charger_set_input_current(ad_input_current[ac_adapter][on]); if (r != EC_SUCCESS) goto bad; @@ -287,6 +287,11 @@ void watch_adapter_closely(struct power_state_context *ctx) } else if (ctx->curr.batt.state_of_charge > 15) { set_turbo(1); } + } else { + /* If we're not on AC, we can't monitor the current, + * so watch for its return. + */ + ac_turbo = -1; } /* If the AP is off, we won't need to throttle it. */ @@ -294,12 +299,6 @@ void watch_adapter_closely(struct power_state_context *ctx) CHIPSET_STATE_SUSPEND)) return; - /* And if we're not on AC, we can't monitor the current. */ - if (!extpower_is_present()) { - ac_turbo = -1; /* watch for its return */ - return; - } - /* Check all the thresholds. */ current = adc_read_channel(ADC_CH_CHARGER_CURRENT); for (i = 0; i < NUM_AC_THRESHOLDS; i++) -- cgit v1.2.1