mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
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 <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/216879 Reviewed-by: Todd Broch <tbroch@chromium.org>
72 lines
1.8 KiB
C
72 lines
1.8 KiB
C
/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
/* Host command module for PD MCU */
|
|
|
|
#include "charge_state.h"
|
|
#include "common.h"
|
|
#include "console.h"
|
|
#include "host_command.h"
|
|
#include "task.h"
|
|
#include "timer.h"
|
|
#include "util.h"
|
|
|
|
#define CPRINTS(format, args...) cprints(CC_PD_HOST_CMD, format, ## args)
|
|
|
|
#define TASK_EVENT_EXCHANGE_PD_STATUS TASK_EVENT_CUSTOM(1)
|
|
|
|
void host_command_pd_send_status(void)
|
|
{
|
|
task_set_event(TASK_ID_PDCMD, TASK_EVENT_EXCHANGE_PD_STATUS, 0);
|
|
}
|
|
|
|
static void pd_exchange_status(void)
|
|
{
|
|
struct ec_params_pd_status ec_status;
|
|
struct ec_response_pd_status pd_status;
|
|
int rv = 0;
|
|
|
|
/* Send battery state of charge */
|
|
if (charge_get_flags() & CHARGE_FLAG_BATT_RESPONSIVE)
|
|
ec_status.batt_soc = charge_get_percent();
|
|
else
|
|
ec_status.batt_soc = -1;
|
|
|
|
rv = pd_host_command(EC_CMD_PD_EXCHANGE_STATUS, 0, &ec_status,
|
|
sizeof(struct ec_params_pd_status), &pd_status,
|
|
sizeof(struct ec_response_pd_status));
|
|
|
|
if (rv < 0) {
|
|
CPRINTS("Host command to PD MCU failed");
|
|
return;
|
|
}
|
|
|
|
/* Set input current limit */
|
|
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");
|
|
|
|
/* If PD is signalling host event, then pass it up to AP */
|
|
if (pd_status.status & PD_STATUS_HOST_EVENT)
|
|
host_set_single_event(EC_HOST_EVENT_PD_MCU);
|
|
}
|
|
|
|
void pd_command_task(void)
|
|
{
|
|
/* On startup exchange status with the PD */
|
|
pd_exchange_status();
|
|
|
|
while (1) {
|
|
/* Wait for the next command event */
|
|
int evt = task_wait_event(-1);
|
|
|
|
/* Process event to send status to PD */
|
|
if (evt & TASK_EVENT_EXCHANGE_PD_STATUS)
|
|
pd_exchange_status();
|
|
}
|
|
}
|
|
|