summaryrefslogtreecommitdiff
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
parentadbd5a0c9a6749468b7c085029cf5e5a41595dbf (diff)
downloadchrome-ec-stabilize-6146.B.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>
-rw-r--r--board/ryu/usb_pd_policy.c4
-rw-r--r--common/charge_state_v2.c24
-rw-r--r--common/host_command_pd.c2
-rw-r--r--driver/charger/bq24773.c13
-rw-r--r--include/charge_state_v2.h10
5 files changed, 37 insertions, 16 deletions
diff --git a/board/ryu/usb_pd_policy.c b/board/ryu/usb_pd_policy.c
index f202b31e24..453e463d59 100644
--- a/board/ryu/usb_pd_policy.c
+++ b/board/ryu/usb_pd_policy.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charger.h"
+#include "charge_state.h"
#include "common.h"
#include "console.h"
#include "gpio.h"
@@ -80,7 +80,7 @@ int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo)
void pd_set_input_current_limit(uint32_t max_ma)
{
- int rv = charger_set_input_current(MAX(max_ma,
+ int rv = charge_set_input_current_limit(MAX(max_ma,
CONFIG_CHARGER_INPUT_CURRENT));
if (rv < 0)
CPRINTS("Failed to set input current limit for PD");
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");
diff --git a/driver/charger/bq24773.c b/driver/charger/bq24773.c
index da2bc93909..5ea62d7e4b 100644
--- a/driver/charger/bq24773.c
+++ b/driver/charger/bq24773.c
@@ -169,18 +169,12 @@ int charger_set_voltage(int voltage)
/* Charging power state initialization */
int charger_post_init(void)
{
- int rv;
#ifdef CONFIG_CHARGER_ILIM_PIN_DISABLED
+ int rv;
int option2;
#endif
- /* Set charger input current limit */
- rv = charger_set_input_current(CONFIG_CHARGER_INPUT_CURRENT);
-
#ifdef CONFIG_CHARGER_ILIM_PIN_DISABLED
- if (rv)
- return rv;
-
/* Read the external ILIM pin enabled flag. */
rv = i2c_read16(I2C_PORT_CHARGER, BQ24773_ADDR,
BQ24773_CHARGE_OPTION2, &option2);
@@ -193,9 +187,10 @@ int charger_post_init(void)
rv = i2c_write16(I2C_PORT_CHARGER, BQ24773_ADDR,
BQ24773_CHARGE_OPTION2, option2);
}
-#endif
-
return rv;
+#else
+ return EC_SUCCESS;
+#endif
}
int charger_discharge_on_ac(int enable)
diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h
index 7f2015dc74..b8503fcc9c 100644
--- a/include/charge_state_v2.h
+++ b/include/charge_state_v2.h
@@ -32,6 +32,7 @@ struct charge_state_data {
enum charge_state_v2 state;
int requested_voltage;
int requested_current;
+ int desired_input_current;
};
/*
@@ -57,5 +58,14 @@ enum ec_status charger_profile_override_get_param(uint32_t param,
enum ec_status charger_profile_override_set_param(uint32_t param,
uint32_t value);
+/**
+ * Set the charge input current limit. This value is stored and sent every
+ * time AC is applied.
+ *
+ * @param ma New input current limit in mA
+ * @return EC_SUCCESS or error
+ */
+int charge_set_input_current_limit(int ma);
+
#endif /* __CROS_EC_CHARGE_STATE_V2_H */