summaryrefslogtreecommitdiff
path: root/include/usb_common.h
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-08-08 10:06:40 -0600
committerCommit Bot <commit-bot@chromium.org>2019-08-19 17:00:54 +0000
commita0ed5aebb22c4d9b83c257b4127a1df372751e14 (patch)
treee66b9f2244ce72ac3be4874cbc8bb24a004a00d2 /include/usb_common.h
parentdf805d082e0272060d2761bfb065b8421a8eabd9 (diff)
downloadchrome-ec-a0ed5aebb22c4d9b83c257b4127a1df372751e14.tar.gz
usb: de-dup common code from old and new PD stack
We still need to pull out more common code between the two stacks, but this is scaffolding with a few examples. BRANCH=none BUG=b:137493121 TEST=unit tests pass Change-Id: Ibd9dda1e544e06f02aa3dde48ca7de1539700cfa Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1744655 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'include/usb_common.h')
-rw-r--r--include/usb_common.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/include/usb_common.h b/include/usb_common.h
new file mode 100644
index 0000000000..1fbaa4bd50
--- /dev/null
+++ b/include/usb_common.h
@@ -0,0 +1,37 @@
+/* Copyright 2019 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.
+ */
+#ifndef __CROS_EC_USB_COMMON_H
+#define __CROS_EC_USB_COMMON_H
+
+/* Functions that are shared between old and new PD stacks */
+#include "usb_pd.h"
+#include "usb_pd_tcpm.h"
+
+/* Returns the battery percentage [0-100] of the system. */
+int usb_get_battery_soc(void);
+
+/*
+ * Returns type C current limit (mA), potentially with the DTS flag, based upon
+ * states of the CC lines on the partner side.
+ *
+ * @param polarity 0 if cc1 is primary, otherwise 1
+ * @param cc1 value of CC1 set by tcpm_get_cc
+ * @param cc2 value of CC2 set by tcpm_get_cc
+ * @return current limit (mA) with DTS flag set if appropriate
+ */
+typec_current_t usb_get_typec_current_limit(enum pd_cc_polarity_type polarity,
+ enum tcpc_cc_voltage_status cc1, enum tcpc_cc_voltage_status cc2);
+
+/**
+ * Returns the polarity of a Sink.
+ *
+ * @param cc1 value of CC1 set by tcpm_get_cc
+ * @param cc2 value of CC2 set by tcpm_get_cc
+ * @return 0 if cc1 is primary, else 1 for cc2 being primary
+ */
+enum pd_cc_polarity_type get_snk_polarity(enum tcpc_cc_voltage_status cc1,
+ enum tcpc_cc_voltage_status cc2);
+
+#endif /* __CROS_EC_USB_COMMON_H */