summaryrefslogtreecommitdiff
path: root/common
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
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')
-rw-r--r--common/build.mk2
-rw-r--r--common/charge_state_v2.c2
-rw-r--r--common/host_command_pd.c52
-rw-r--r--common/usb_pd_protocol.c10
4 files changed, 65 insertions, 1 deletions
diff --git a/common/build.mk b/common/build.mk
index 18c1c47579..09bbfe2564 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -43,7 +43,6 @@ common-$(CONFIG_EXTPOWER_SPRING)+=extpower_spring.o
common-$(CONFIG_FANS)+=fan.o
common-$(CONFIG_FLASH)+=flash.o
common-$(CONFIG_FMAP)+=fmap.o
-common-$(CONFIG_HOST_CMD_MASTER)+=host_command_master.o
common-$(CONFIG_I2C)+=i2c.o
common-$(CONFIG_I2C_ARBITRATION)+=i2c_arbitration.o
common-$(CONFIG_KEYBOARD_PROTOCOL_8042)+=keyboard_8042.o
@@ -72,6 +71,7 @@ common-$(HAS_TASK_CHIPSET)+=chipset.o throttle_ap.o
common-$(HAS_TASK_CONSOLE)+=console.o console_output.o uart_buffering.o
common-$(HAS_TASK_CONSOLE)+=memory_commands.o
common-$(HAS_TASK_HOSTCMD)+=acpi.o host_command.o host_event_commands.o
+common-$(HAS_TASK_PDCMD)+=host_command_master.o host_command_pd.o
common-$(HAS_TASK_KEYSCAN)+=keyboard_scan.o
common-$(HAS_TASK_LIGHTBAR)+=lb_common.o lightbar.o
common-$(HAS_TASK_MOTIONSENSE)+=motion_sense.o math_util.o
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 87ad28561b..6a6a93765d 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -744,6 +744,8 @@ uint32_t charge_get_flags(void)
flags |= CHARGE_FLAG_FORCE_IDLE;
if (curr.ac)
flags |= CHARGE_FLAG_EXTERNAL_POWER;
+ if (curr.batt.flags & BATT_FLAG_RESPONSIVE)
+ flags |= CHARGE_FLAG_BATT_RESPONSIVE;
return flags;
}
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();
+ }
+}
+
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 214d5f15a0..34a6183cd2 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -495,6 +495,10 @@ static void handle_data_request(void *ctxt, uint16_t head, uint32_t *payload)
*/
pd_task_state = PD_STATE_SNK_REQUESTED;
}
+ /*
+ * TODO(crosbug.com/p/28332): if pd_choose_voltage
+ * returns an error, ignore failure for now.
+ */
}
break;
#endif /* CONFIG_USB_PD_DUAL_ROLE */
@@ -886,6 +890,12 @@ void pd_task(void)
break;
}
+ /* Don't continue if power negotiation is not allowed */
+ if (!pd_power_negotiation_allowed()) {
+ timeout = PD_T_GET_SOURCE_CAP;
+ break;
+ }
+
res = send_control(ctxt, PD_CTRL_GET_SOURCE_CAP);
/* packet was acked => PD capable device) */
if (res >= 0) {