From eff864775f25f16480955ebde7234219c6e03948 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Sat, 6 Sep 2014 22:37:15 -0700 Subject: samus: exchange status with PD MCU on boot On boot, the EC should send host command to exchange status with PD MCU. This allows EC to get the correct input current limit when EC reboots and PD does not. Also had to move some of the charger state machine initialization to run with HOOK_INIT so that it runs before the tasks run. BUG=none BRANCH=none TEST=tested on EVT samus. Without this change, if you reboot EC, and run charger command, the charger input current limit is 512mA. with this change, when the EC reboots, it sends host command to PD MCU to get current limit and sets it appropriately. Change-Id: I5426f0fc3a62b6cd7a73f55cb11b895902a54903 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/216879 Reviewed-by: Todd Broch --- common/charge_state_v2.c | 13 +++++++++---- common/host_command_pd.c | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index c37e8189f1..1b796c9c27 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -457,6 +457,15 @@ const struct batt_params *charger_current_battery_params(void) return &curr.batt; } +void charger_init(void) +{ + /* Initialize current state */ + memset(&curr, 0, sizeof(curr)); + curr.batt.is_present = BP_NOT_SURE; + curr.desired_input_current = CONFIG_CHARGER_INPUT_CURRENT; +} +DECLARE_HOOK(HOOK_INIT, charger_init, HOOK_PRIO_DEFAULT); + /* Main loop */ void charger_task(void) { @@ -466,10 +475,6 @@ void charger_task(void) /* Get the battery-specific values */ batt_info = battery_get_info(); - /* 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; diff --git a/common/host_command_pd.c b/common/host_command_pd.c index 444e9e3288..252ade01b7 100644 --- a/common/host_command_pd.c +++ b/common/host_command_pd.c @@ -56,6 +56,8 @@ static void pd_exchange_status(void) void pd_command_task(void) { + /* On startup exchange status with the PD */ + pd_exchange_status(); while (1) { /* Wait for the next command event */ -- cgit v1.2.1