charge_manager: Don't cutoff charger when no battery is attached

We normally do not charge from non-dedicated chargers. The process of
determining whether a charger is dedicated or not involves PD protocol
communication, so it can take some time to reach a determination. If no
battery is attached, the charger is likely our only source of power, so
don't cut it off.

BUG=chrome-os-partner:41258
TEST=Attach donette to glados system with no battery, verify that glados
boots to EC console and doesn't reset or panic.
BRANCH=None

Change-Id: I7c9cfcbd37b37ef16010cf1f246d8fddba6f6283
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/277074
Reviewed-by: Alec Berg <alecaberg@chromium.org>
This commit is contained in:
Shawn Nematbakhsh
2015-06-11 15:38:24 -07:00
committed by ChromeOS Commit Bot
parent 3062442361
commit 35fbc972e9
2 changed files with 26 additions and 6 deletions

View File

@@ -4,6 +4,7 @@
*/
#include "adc.h"
#include "battery.h"
#include "charge_manager.h"
#include "charge_ramp.h"
#include "console.h"
@@ -73,6 +74,21 @@ enum charge_manager_change_type {
CHANGE_DUALROLE,
};
/**
* In certain cases we need to override the default behavior of not charging
* from non-dedicated chargers. If the system is in RO and locked, we have no
* way of determining the actual dualrole capability of the charger because
* PD communication is not allowed, so we must assume that it is dedicated.
* Also, if no battery is present, the charger may be our only source of power,
* so again we must assume that the charger is dedicated.
*/
static int charge_manager_spoof_dualrole_capability(void)
{
return (system_get_image_copy() == SYSTEM_IMAGE_RO &&
system_is_locked()) ||
(battery_is_present() != BP_YES);
}
/**
* Initialize available charge. Run before board init, so board init can
* initialize data, if needed.
@@ -80,6 +96,7 @@ enum charge_manager_change_type {
static void charge_manager_init(void)
{
int i, j;
int spoof_capability = charge_manager_spoof_dualrole_capability();
for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; ++i) {
for (j = 0; j < CHARGE_SUPPLIER_COUNT; ++j) {
@@ -89,7 +106,8 @@ static void charge_manager_init(void)
CHARGE_VOLTAGE_UNINITIALIZED;
}
charge_ceil[i] = CHARGE_CEIL_NONE;
dualrole_capability[i] = CAP_UNKNOWN;
dualrole_capability[i] = spoof_capability ? CAP_DEDICATED :
CAP_UNKNOWN;
}
}
DECLARE_HOOK(HOOK_INIT, charge_manager_init, HOOK_PRIO_DEFAULT-1);
@@ -629,11 +647,7 @@ void charge_manager_update_dualrole(int port, enum dualrole_capabilities cap)
{
ASSERT(port >= 0 && port < CONFIG_USB_PD_PORT_COUNT);
/*
* We have no way of determining the charger dualrole capability in
* locked RO, so just assume we always have a dedicated charger.
*/
if (system_get_image_copy() == SYSTEM_IMAGE_RO && system_is_locked())
if (charge_manager_spoof_dualrole_capability())
cap = CAP_DEDICATED;
/* Ignore when capability is unchanged */

View File

@@ -5,6 +5,7 @@
* Test charge manager module.
*/
#include "battery.h"
#include "charge_manager.h"
#include "common.h"
#include "ec_commands.h"
@@ -66,6 +67,11 @@ void pd_set_new_power_request(int port)
new_power_request[port] = 1;
}
enum battery_present battery_is_present(void)
{
return BP_YES;
}
static void clear_new_power_requests(void)
{
int i;