summaryrefslogtreecommitdiff
path: root/board/waddledoo/usb_pd_policy.c
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2020-01-14 11:31:25 -0800
committerCommit Bot <commit-bot@chromium.org>2020-01-21 23:55:42 +0000
commitad996f4235597d7a3b64dbfc5c050cc4055a5194 (patch)
treedd41433d0bc3b21dee0e4178d2c2c71fd2215d48 /board/waddledoo/usb_pd_policy.c
parent39b17e1375b5e149cd9807ac826cdf0dddfa9dbb (diff)
downloadchrome-ec-ad996f4235597d7a3b64dbfc5c050cc4055a5194.tar.gz
waddledoo: Add Type-C, PD, and charging support
This commit adds USB Type-C, Power Delivery and charging support to waddledoo. Waddledoo is using the new TCPMv2, low power mode has been disabled for the time being while we sort out issues with the TCPC. Currently in this state, we cannot actually receive any PD messages, but the PD task is running. BUG=b:147257992 BRANCH=None TEST=Build and flash on waddledoo, verify that we can detect Type-C chargers, and that it can charge a battery. Change-Id: Id30218ef685ed27a934bae3a580f47754f659ac6 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2001127 Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'board/waddledoo/usb_pd_policy.c')
-rw-r--r--board/waddledoo/usb_pd_policy.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/board/waddledoo/usb_pd_policy.c b/board/waddledoo/usb_pd_policy.c
new file mode 100644
index 0000000000..bcdf8300c5
--- /dev/null
+++ b/board/waddledoo/usb_pd_policy.c
@@ -0,0 +1,66 @@
+/* Copyright 2020 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.
+ */
+
+#include "charge_manager.h"
+#include "chipset.h"
+#include "common.h"
+#include "console.h"
+#include "driver/tcpm/tcpci.h"
+#include "usb_pd.h"
+
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+
+int pd_check_vconn_swap(int port)
+{
+ /* Allow VCONN swaps if the AP is on. */
+ return chipset_in_state(CHIPSET_STATE_ANY_SUSPEND | CHIPSET_STATE_ON);
+}
+
+void pd_power_supply_reset(int port)
+{
+ /* Disable VBUS */
+ tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SRC_CTRL_LOW);
+
+#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT
+ /* Give back the current quota we are no longer using */
+ charge_manager_source_port(port, 0);
+#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */
+
+ /* Notify host of power info change. */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
+}
+
+int pd_set_power_supply_ready(int port)
+{
+ int rv;
+
+ if (port >= CONFIG_USB_PD_PORT_MAX_COUNT)
+ return EC_ERROR_INVAL;
+
+ /* Disable charging. */
+ rv = tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SNK_CTRL_LOW);
+ if (rv)
+ return rv;
+
+ /* Our policy is not to source VBUS when the AP is off. */
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ return EC_ERROR_NOT_POWERED;
+
+ /* Provide Vbus. */
+ rv = tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SRC_CTRL_HIGH);
+ if (rv)
+ return rv;
+
+#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT
+ /* Ensure we advertise the proper available current quota */
+ charge_manager_source_port(port, 1);
+#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */
+
+ /* Notify host of power info change. */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
+
+ return EC_SUCCESS;
+}