mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 10:00:51 +00:00
Revert - https://chromium-review.googlesource.com/#/c/205145/2 - https://chromium-review.googlesource.com/#/c/205147/4 Now using the real AC_PRESENT gpio signal instead of whether or not the PD MCU negotiated for 20V. BUG=chrome-os-partner:29841, chrome-os-partner:29842 BRANCH=none TEST=tested on a board with reworked AC_PRESENT signal. Verified that gpio is correctly reporting state of AC and is charging when AC is plugged in. Tested the no battery case to make sure board powers on and stays on with just a charger. Also tested the dead battery case by plugging in a dead battery, then plugging in a charger and making sure system powers on and starts charging. Change-Id: I4424771c91c8a2aa19eda68a8b5194e9265d529c Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/206598 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
68 lines
1.6 KiB
C
68 lines
1.6 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, tries = 0;
|
|
|
|
/*
|
|
* TODO(crosbug.com/p/29499): Change sending state of charge to
|
|
* remaining capacity for finer grained control.
|
|
*/
|
|
/* 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;
|
|
|
|
/* Try 3 times to get the PD MCU status. */
|
|
while (tries++ < 3) {
|
|
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)
|
|
break;
|
|
task_wait_event(500*MSEC);
|
|
}
|
|
|
|
if (rv < 0)
|
|
CPRINTS("Host command to PD MCU failed");
|
|
}
|
|
|
|
void pd_command_task(void)
|
|
{
|
|
|
|
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();
|
|
}
|
|
}
|
|
|