summaryrefslogtreecommitdiff
path: root/baseboard
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-08-05 08:46:03 -0600
committerCommit Bot <commit-bot@chromium.org>2019-08-05 21:18:40 +0000
commitba753b782a65b2532a3d4682df76f0fbdbe7e2f5 (patch)
treef3b0e752c8c4e184f37c0e249bb2311efe217b81 /baseboard
parentc5e34fe248736e5a0b2a0d7388d2f996c6b081ff (diff)
downloadchrome-ec-ba753b782a65b2532a3d4682df76f0fbdbe7e2f5.tar.gz
Trembyle: implement board_set_active_charge_port
BUG=b:138599952 BRANCH=none TEST=make buildall -j Change-Id: I82ef7cad0cd6d91d1e4bbcc0d1a2d312dd773e8f Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1736797 Commit-Queue: Edward Hill <ecgh@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'baseboard')
-rw-r--r--baseboard/zork/baseboard.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/baseboard/zork/baseboard.c b/baseboard/zork/baseboard.c
index a1932f0910..213a323c6e 100644
--- a/baseboard/zork/baseboard.c
+++ b/baseboard/zork/baseboard.c
@@ -50,6 +50,9 @@
#include "usbc_ppc.h"
#include "util.h"
+#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
const enum gpio_signal hibernate_wake_pins[] = {
GPIO_LID_OPEN,
GPIO_AC_PRESENT,
@@ -214,6 +217,60 @@ int ppc_get_alert_status(int port)
}
}
+int board_set_active_charge_port(int port)
+{
+ int is_valid_port = (port >= 0 &&
+ port < CONFIG_USB_PD_PORT_COUNT);
+ int i;
+
+ if (port == CHARGE_PORT_NONE) {
+ CPRINTSUSB("Disabling all charger ports");
+
+ /* Disable all ports. */
+ for (i = 0; i < ppc_cnt; i++) {
+ /*
+ * Do not return early if one fails otherwise we can
+ * get into a boot loop assertion failure.
+ */
+ if (ppc_vbus_sink_enable(i, 0))
+ CPRINTSUSB("Disabling C%d as sink failed.", i);
+ }
+
+ return EC_SUCCESS;
+ } else if (!is_valid_port) {
+ return EC_ERROR_INVAL;
+ }
+
+
+ /* Check if the port is sourcing VBUS. */
+ if (ppc_is_sourcing_vbus(port)) {
+ CPRINTFUSB("Skip enable C%d", port);
+ return EC_ERROR_INVAL;
+ }
+
+ CPRINTSUSB("New charge port: C%d", port);
+
+ /*
+ * Turn off the other ports' sink path FETs, before enabling the
+ * requested charge port.
+ */
+ for (i = 0; i < ppc_cnt; i++) {
+ if (i == port)
+ continue;
+
+ if (ppc_vbus_sink_enable(i, 0))
+ CPRINTSUSB("C%d: sink path disable failed.", i);
+ }
+
+ /* Enable requested charge port. */
+ if (ppc_vbus_sink_enable(port, 1)) {
+ CPRINTSUSB("C%d: sink path enable failed.", port);
+ return EC_ERROR_UNKNOWN;
+ }
+
+ return EC_SUCCESS;
+}
+
const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
[USBC_PORT_C0] = {
.bus_type = EC_BUS_TYPE_I2C,