summaryrefslogtreecommitdiff
path: root/board/servo_v4
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2021-10-18 23:03:09 +0000
committerCommit Bot <commit-bot@chromium.org>2021-11-05 19:24:34 +0000
commita311557a3165950a5ef3d0a36e46764ecb428f32 (patch)
treebad21b73cb0cf601d06e1913a1d209096bdbb69e /board/servo_v4
parentc1c881e4c88b298f34a5e776ec2bb1291a4c3d4d (diff)
downloadchrome-ec-a311557a3165950a5ef3d0a36e46764ecb428f32.tar.gz
tree: Create usb_pd_pdo.c
genvif depends on usb_pd_policy.c. However, the usb_pd_policy.c files often depend on other symbols that are not included when building genvif. genvif only needs the pd_src_pdo and pd_src_pdo_count variables (and charge_manager_get_source_pdo() in one case). Extract these variables into their own files. BRANCH=none BUG=b:172020503 TEST=CC=clang make BOARD=zinger -j TEST=make buildall TEST=compare generated *_vif.xml files before and after change: => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I765750cd86243a0a355dcc6a29b80fc23403d99f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3231026 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'board/servo_v4')
-rw-r--r--board/servo_v4/build.mk2
-rw-r--r--board/servo_v4/usb_pd_pdo.c56
-rw-r--r--board/servo_v4/usb_pd_pdo.h30
-rw-r--r--board/servo_v4/usb_pd_policy.c50
4 files changed, 88 insertions, 50 deletions
diff --git a/board/servo_v4/build.mk b/board/servo_v4/build.mk
index 6336bbfab6..6c39be0475 100644
--- a/board/servo_v4/build.mk
+++ b/board/servo_v4/build.mk
@@ -14,6 +14,6 @@ CHIP_VARIANT:=stm32f07x
test-list-y=
board-y=board.o
-board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
+board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o usb_pd_pdo.o
all_deps=$(patsubst ro,,$(def_all_deps))
diff --git a/board/servo_v4/usb_pd_pdo.c b/board/servo_v4/usb_pd_pdo.c
new file mode 100644
index 0000000000..8df0eac2c2
--- /dev/null
+++ b/board/servo_v4/usb_pd_pdo.c
@@ -0,0 +1,56 @@
+/* Copyright 2021 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 "compile_time_macros.h"
+#include "usb_pd.h"
+#include "usb_pd_config.h"
+#include "usb_pd_pdo.h"
+
+#define CHG_PDO_FIXED_FLAGS (PDO_FIXED_DATA_SWAP)
+
+const uint32_t pd_snk_pdo[] = {
+ PDO_FIXED(5000, 500, CHG_PDO_FIXED_FLAGS),
+ PDO_BATT(4750, 21000, 15000),
+ PDO_VAR(4750, 21000, 3000),
+};
+const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo);
+
+/*
+ * Dynamic PDO that reflects capabilities present on the CHG port. Allow for
+ * multiple entries so that we can offer greater than 5V charging. The 1st
+ * entry will be fixed 5V, but its current value may change based on the CHG
+ * port vbus info. Subsequent entries are used for when offering vbus greater
+ * than 5V.
+ */
+const uint16_t pd_src_voltages_mv[] = {
+ 5000, 9000, 10000, 12000, 15000, 20000,
+};
+uint32_t pd_src_chg_pdo[ARRAY_SIZE(pd_src_voltages_mv)];
+uint8_t chg_pdo_cnt;
+
+int active_charge_port = CHARGE_PORT_NONE;
+struct vbus_prop vbus[CONFIG_USB_PD_PORT_MAX_COUNT];
+
+int charge_port_is_active(void)
+{
+ return active_charge_port == CHG && vbus[CHG].mv > 0;
+}
+
+int charge_manager_get_source_pdo(const uint32_t **src_pdo, const int port)
+{
+ int pdo_cnt = 0;
+
+ /*
+ * If CHG is providing VBUS, then advertise what's available on the CHG
+ * port, otherwise we provide no power.
+ */
+ if (charge_port_is_active()) {
+ *src_pdo = pd_src_chg_pdo;
+ pdo_cnt = chg_pdo_cnt;
+ }
+
+ return pdo_cnt;
+}
diff --git a/board/servo_v4/usb_pd_pdo.h b/board/servo_v4/usb_pd_pdo.h
new file mode 100644
index 0000000000..bb9d8adca6
--- /dev/null
+++ b/board/servo_v4/usb_pd_pdo.h
@@ -0,0 +1,30 @@
+/* Copyright 2021 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_BOARD_SERVO_V4_USB_PD_PDO_H
+#define __CROS_EC_BOARD_SERVO_V4_USB_PD_PDO_H
+
+#include "compile_time_macros.h"
+#include "stdint.h"
+
+extern const uint32_t pd_snk_pdo[3];
+extern const int pd_snk_pdo_cnt;
+
+extern const uint16_t pd_src_voltages_mv[6];
+extern uint32_t pd_src_chg_pdo[ARRAY_SIZE(pd_src_voltages_mv)];
+extern uint8_t chg_pdo_cnt;
+
+extern int active_charge_port;
+
+struct vbus_prop {
+ int mv;
+ int ma;
+};
+extern struct vbus_prop vbus[CONFIG_USB_PD_PORT_MAX_COUNT];
+
+int charge_port_is_active(void);
+int charge_manager_get_source_pdo(const uint32_t **src_pdo, const int port);
+
+#endif /* __CROS_EC_BOARD_SERVO_V4_USB_PD_PDO_H */
diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c
index 00eaa1e628..61931cda8b 100644
--- a/board/servo_v4/usb_pd_policy.c
+++ b/board/servo_v4/usb_pd_policy.c
@@ -25,6 +25,7 @@
#include "usb_mux.h"
#include "usb_pd.h"
#include "usb_pd_config.h"
+#include "usb_pd_pdo.h"
#include "usb_pd_tcpm.h"
#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
@@ -33,8 +34,6 @@
#define DUT_PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\
PDO_FIXED_COMM_CAP)
-#define CHG_PDO_FIXED_FLAGS (PDO_FIXED_DATA_SWAP)
-
#define VBUS_UNCHANGED(curr, pend, new) (curr == new && pend == new)
/* Macros to config the PD role */
@@ -88,32 +87,6 @@
#define DUT_BOTH_CC_PD(r) DUT_BOTH_CC_SET(r, GPIO_OUT_LOW)
#define DUT_BOTH_CC_OPEN(r) DUT_BOTH_CC_SET(r, GPIO_INPUT)
-/*
- * Dynamic PDO that reflects capabilities present on the CHG port. Allow for
- * multiple entries so that we can offer greater than 5V charging. The 1st
- * entry will be fixed 5V, but its current value may change based on the CHG
- * port vbus info. Subsequent entries are used for when offering vbus greater
- * than 5V.
- */
-static const uint16_t pd_src_voltages_mv[] = {
- 5000, 9000, 10000, 12000, 15000, 20000,
-};
-static uint32_t pd_src_chg_pdo[ARRAY_SIZE(pd_src_voltages_mv)];
-static uint8_t chg_pdo_cnt;
-
-const uint32_t pd_snk_pdo[] = {
- PDO_FIXED(5000, 500, CHG_PDO_FIXED_FLAGS),
- PDO_BATT(4750, 21000, 15000),
- PDO_VAR(4750, 21000, 3000),
-};
-const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo);
-
-struct vbus_prop {
- int mv;
- int ma;
-};
-static struct vbus_prop vbus[CONFIG_USB_PD_PORT_MAX_COUNT];
-static int active_charge_port = CHARGE_PORT_NONE;
static enum charge_supplier active_charge_supplier;
static uint8_t vbus_rp = TYPEC_RP_RESERVED;
@@ -172,11 +145,6 @@ static uint32_t max_supported_voltage(void)
user_limited_max_mv;
}
-static int charge_port_is_active(void)
-{
- return active_charge_port == CHG && vbus[CHG].mv > 0;
-}
-
static int is_charge_through_allowed(void)
{
return charge_port_is_active() && cc_config & CC_ALLOW_SRC;
@@ -606,22 +574,6 @@ int board_select_rp_value(int port, int rp)
return EC_SUCCESS;
}
-int charge_manager_get_source_pdo(const uint32_t **src_pdo, const int port)
-{
- int pdo_cnt = 0;
-
- /*
- * If CHG is providing VBUS, then advertise what's available on the CHG
- * port, otherwise we provide no power.
- */
- if (charge_port_is_active()) {
- *src_pdo = pd_src_chg_pdo;
- pdo_cnt = chg_pdo_cnt;
- }
-
- return pdo_cnt;
-}
-
__override void pd_transition_voltage(int idx)
{
timestamp_t deadline;