summaryrefslogtreecommitdiff
path: root/common/host_command_pd.c
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-05-28 18:10:25 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-06-09 22:20:48 +0000
commit72357cd1edf885e559dbb715b33cfb861a0a3265 (patch)
tree48e3181ecd32c2124d80b50b39a965c2f6ac1893 /common/host_command_pd.c
parentf7ae0fb81b4b43c939ec1be674e940377b8c8d64 (diff)
downloadchrome-ec-72357cd1edf885e559dbb715b33cfb861a0a3265.tar.gz
samus: Allow samus to charge w/o battery or with dead batterystabilize-5942.B
Use a EC to PD host command to notify the PD MCU when a battery is present and charged enough that it is ok to negotiate for a higher power. The PD MCU will not negotiate until the host command is received, which allows the system to be powered without a battery or with a dead battery with 5V. BUG=chrome-os-partner:28611 BRANCH=none TEST=Tested on a samus: 1) Tested the normal case of battery charged and plugged in. When charger is plugged in, the device immediately starts negotiating for 20V and starts charging. 2) Tested with no battery. Plug in a charger, samus boots and stays alive. VBUS measured at 5V. When a battery is plugged in, device negotiates for 20V and starts charging. 3) Tested dead battery by taking a battery with no charge, and plugging in zinger. Everything boots, but PD does not negotiate for power. Then when battery reaches 1%, PD negotiates and zinger switches to 20V without causing a reboot. Change-Id: Iaa451403674e86cddbd3fe80e9503584910be576 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/201958 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common/host_command_pd.c')
-rw-r--r--common/host_command_pd.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/common/host_command_pd.c b/common/host_command_pd.c
new file mode 100644
index 0000000000..5d9a3adf6d
--- /dev/null
+++ b/common/host_command_pd.c
@@ -0,0 +1,52 @@
+/* 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 "host_command.h"
+#include "task.h"
+#include "timer.h"
+#include "util.h"
+
+#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;
+
+ /*
+ * 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;
+
+ pd_host_command(EC_CMD_PD_EXCHANGE_STATUS, 0, &ec_status,
+ sizeof(struct ec_params_pd_status), NULL, 0);
+}
+
+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();
+ }
+}
+