summaryrefslogtreecommitdiff
path: root/include
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
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')
-rw-r--r--include/charge_state.h7
-rw-r--r--include/usb_common.h37
-rw-r--r--include/usb_pd.h4
-rw-r--r--include/usb_tc_sm.h10
4 files changed, 46 insertions, 12 deletions
diff --git a/include/charge_state.h b/include/charge_state.h
index 04ca4c6648..4a152032fc 100644
--- a/include/charge_state.h
+++ b/include/charge_state.h
@@ -86,10 +86,17 @@ int charge_keep_power_off(void);
*/
uint32_t charge_get_flags(void);
+#if defined(CONFIG_CHARGER)
/**
* Return current battery charge percentage.
*/
int charge_get_percent(void);
+#elif defined(CONFIG_BATTERY)
+/**
+ * Return current battery charge if not using charge manager sub-system.
+ */
+int board_get_battery_soc(void);
+#endif
/**
* Return current display charge in 10ths of a percent (e.g. 1000 = 100.0%)
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 */
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 4b36247a94..a1a1c0ba0f 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -1212,8 +1212,8 @@ enum pd_data_msg_type {
/* CC Polarity type */
enum pd_cc_polarity_type {
- POLARITY_CC1,
- POLARITY_CC2
+ POLARITY_CC1 = 0,
+ POLARITY_CC2 = 1,
};
/* Protocol revision */
diff --git a/include/usb_tc_sm.h b/include/usb_tc_sm.h
index 1019bf2c20..39ba6e026d 100644
--- a/include/usb_tc_sm.h
+++ b/include/usb_tc_sm.h
@@ -126,16 +126,6 @@ void set_usb_mux_with_current_data_role(int port);
void tc_set_timeout(int port, uint64_t timeout);
/**
- * 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 connected, else 1 for cc2
- */
-enum pd_cc_polarity_type get_snk_polarity(enum tcpc_cc_voltage_status cc1,
- enum tcpc_cc_voltage_status cc2);
-
-/**
* Restarts the TCPC
*
* @param port USB-C port number