summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-06-11 15:38:24 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-12 18:23:28 +0000
commit35fbc972e9dae2fb85cce6837868352ad39aa981 (patch)
tree3aaedb5a90ecbc30e31cd7dbd7368387646cb777
parent3062442361cb1765224a237043db37e6d8ebb762 (diff)
downloadchrome-ec-35fbc972e9dae2fb85cce6837868352ad39aa981.tar.gz
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>
-rw-r--r--common/charge_manager.c26
-rw-r--r--test/charge_manager.c6
2 files changed, 26 insertions, 6 deletions
diff --git a/common/charge_manager.c b/common/charge_manager.c
index 24fbae2d38..a231f0da9e 100644
--- a/common/charge_manager.c
+++ b/common/charge_manager.c
@@ -4,6 +4,7 @@
*/
#include "adc.h"
+#include "battery.h"
#include "charge_manager.h"
#include "charge_ramp.h"
#include "console.h"
@@ -74,12 +75,28 @@ enum charge_manager_change_type {
};
/**
+ * 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.
*/
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 */
diff --git a/test/charge_manager.c b/test/charge_manager.c
index 87ae1c7ede..8bfa8e2646 100644
--- a/test/charge_manager.c
+++ b/test/charge_manager.c
@@ -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;