diff options
-rw-r--r-- | board/servo_v4/board.h | 1 | ||||
-rw-r--r-- | board/servo_v4/usb_pd_policy.c | 4 | ||||
-rw-r--r-- | board/servo_v4p1/board.h | 1 | ||||
-rw-r--r-- | board/servo_v4p1/usb_pd_policy.c | 4 | ||||
-rw-r--r-- | common/usb_common.c | 3 | ||||
-rw-r--r-- | include/config.h | 6 | ||||
-rw-r--r-- | test/build.mk | 2 | ||||
-rw-r--r-- | test/test_config.h | 10 | ||||
-rw-r--r-- | test/usb_pd_pdo_fixed.tasklist | 10 | ||||
-rw-r--r-- | test/usb_pd_pdo_fixed_test.c | 47 |
10 files changed, 84 insertions, 4 deletions
diff --git a/board/servo_v4/board.h b/board/servo_v4/board.h index 0d9d5d465b..0fd7d4639a 100644 --- a/board/servo_v4/board.h +++ b/board/servo_v4/board.h @@ -126,6 +126,7 @@ #undef CONFIG_USB_PD_PULLUP #define CONFIG_USB_PD_PULLUP TYPEC_RP_USB #define CONFIG_USB_PD_VBUS_MEASURE_NOT_PRESENT +#define CONFIG_USB_PD_ONLY_FIXED_PDOS /* Don't automatically change roles */ #undef CONFIG_USB_PD_INITIAL_DRP_STATE diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c index d0983cd39a..a54393d9b5 100644 --- a/board/servo_v4/usb_pd_policy.c +++ b/board/servo_v4/usb_pd_policy.c @@ -1208,8 +1208,8 @@ static int cmd_ada_srccaps(int argc, char *argv[]) for (i = 0; i < pd_get_src_cap_cnt(CHG); ++i) { uint32_t max_ma, max_mv, unused; - /* It's an supported Augmented PDO (PD3.0) */ - if ((ada_srccaps[i] & PDO_TYPE_MASK) == PDO_TYPE_AUGMENTED) + if (IS_ENABLED(CONFIG_USB_PD_ONLY_FIXED_PDOS) && + (ada_srccaps[i] & PDO_TYPE_MASK) != PDO_TYPE_FIXED) continue; pd_extract_pdo_power(ada_srccaps[i], &max_ma, &max_mv, &unused); diff --git a/board/servo_v4p1/board.h b/board/servo_v4p1/board.h index 471dd93177..77750a31c8 100644 --- a/board/servo_v4p1/board.h +++ b/board/servo_v4p1/board.h @@ -188,6 +188,7 @@ #undef CONFIG_USB_PD_PULLUP #define CONFIG_USB_PD_PULLUP TYPEC_RP_USB #define CONFIG_USB_PD_VBUS_MEASURE_NOT_PRESENT +#define CONFIG_USB_PD_ONLY_FIXED_PDOS #define CONFIG_USB_PD_ALT_MODE /* Don't automatically change roles */ diff --git a/board/servo_v4p1/usb_pd_policy.c b/board/servo_v4p1/usb_pd_policy.c index 640adcd026..f9fc723217 100644 --- a/board/servo_v4p1/usb_pd_policy.c +++ b/board/servo_v4p1/usb_pd_policy.c @@ -1282,8 +1282,8 @@ static int cmd_ada_srccaps(int argc, char *argv[]) for (i = 0; i < pd_get_src_cap_cnt(CHG); ++i) { uint32_t max_ma, max_mv, unused; - /* It's an supported Augmented PDO (PD3.0) */ - if ((ada_srccaps[i] & PDO_TYPE_MASK) == PDO_TYPE_AUGMENTED) + if (IS_ENABLED(CONFIG_USB_PD_ONLY_FIXED_PDOS) && + (ada_srccaps[i] & PDO_TYPE_MASK) != PDO_TYPE_FIXED) continue; pd_extract_pdo_power(ada_srccaps[i], &max_ma, &max_mv, &unused); diff --git a/common/usb_common.c b/common/usb_common.c index a00a85e469..38cd3e41ba 100644 --- a/common/usb_common.c +++ b/common/usb_common.c @@ -160,6 +160,9 @@ int pd_find_pdo_index(uint32_t src_cap_cnt, const uint32_t * const src_caps, /* Get max power that is under our max voltage input */ for (i = 0; i < src_cap_cnt; i++) { + if (IS_ENABLED(CONFIG_USB_PD_ONLY_FIXED_PDOS) && + (src_caps[i] & PDO_TYPE_MASK) != PDO_TYPE_FIXED) + continue; /* its an unsupported Augmented PDO (PD3.0) */ if ((src_caps[i] & PDO_TYPE_MASK) == PDO_TYPE_AUGMENTED) continue; diff --git a/include/config.h b/include/config.h index 77358fe319..946f270926 100644 --- a/include/config.h +++ b/include/config.h @@ -4232,6 +4232,12 @@ #undef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT /* + * Ignore all non-fixed PDOs received from a src_caps message. Enable this for + * boards (like servo_v4) which only support FIXED PDO types. + */ +#undef CONFIG_USB_PD_ONLY_FIXED_PDOS + +/* * Total current in mA the board can supply to external devices through * USB-C ports * diff --git a/test/build.mk b/test/build.mk index aa6b6b4483..0908f5f9a3 100644 --- a/test/build.mk +++ b/test/build.mk @@ -75,6 +75,7 @@ test-list-host += usb_pd_int test-list-host += usb_pd test-list-host += usb_pd_giveback test-list-host += usb_pd_rev30 +test-list-host += usb_pd_pdo_fixed test-list-host += usb_ppc test-list-host += usb_sm_framework_h3 test-list-host += usb_sm_framework_h2 @@ -156,6 +157,7 @@ usb_pd_int-y=usb_pd_int.o usb_pd-y=usb_pd.o usb_pd_giveback-y=usb_pd.o usb_pd_rev30-y=usb_pd.o +usb_pd_pdo_fixed-y=usb_pd_pdo_fixed_test.o usb_ppc-y=usb_ppc.o usb_sm_framework_h3-y=usb_sm_framework_h3.o usb_sm_framework_h2-y=usb_sm_framework_h3.o diff --git a/test/test_config.h b/test/test_config.h index c757c233d3..160097b6e0 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -250,6 +250,16 @@ int ncp15wb_calculate_temp(uint16_t adc); #define CONFIG_SW_CRC #endif +#ifdef TEST_USB_PD_PDO_FIXED +#define CONFIG_USB_POWER_DELIVERY +#define CONFIG_USB_PD_PORT_MAX_COUNT 1 +#define CONFIG_USB_PD_TCPC +#define CONFIG_USB_PD_TCPM_STUB +#define CONFIG_SHA256 +#define CONFIG_SW_CRC +#define CONFIG_USB_PD_ONLY_FIXED_PDOS +#endif + #if defined(TEST_USB_SM_FRAMEWORK_H3) #define CONFIG_USB_PD_PORT_MAX_COUNT 1 #undef CONFIG_USB_PRL_SM diff --git a/test/usb_pd_pdo_fixed.tasklist b/test/usb_pd_pdo_fixed.tasklist new file mode 100644 index 0000000000..9a1e6b3e08 --- /dev/null +++ b/test/usb_pd_pdo_fixed.tasklist @@ -0,0 +1,10 @@ +/* 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. + */ + +/** + * See CONFIG_TASK_LIST in config.h for details. + */ +#define CONFIG_TEST_TASK_LIST + diff --git a/test/usb_pd_pdo_fixed_test.c b/test/usb_pd_pdo_fixed_test.c new file mode 100644 index 0000000000..d79970d6b3 --- /dev/null +++ b/test/usb_pd_pdo_fixed_test.c @@ -0,0 +1,47 @@ +/* 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. + * + * Test USB common module. + */ +#include "test_util.h" +#include "usb_common.h" + +#define PDO_FIXED_FLAGS \ + (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP | PDO_FIXED_COMM_CAP) + +/* Test that a non-fixed PDO will never be selected by pd_find_pdo_index. */ +test_static int test_pd_find_pdo_index(void) +{ + const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), + PDO_VAR(4750, PD_MAX_VOLTAGE_MV, PD_MAX_CURRENT_MA), + PDO_BATT(4750, PD_MAX_VOLTAGE_MV, PD_MAX_POWER_MW), + PDO_FIXED(9000, 3000, PDO_FIXED_FLAGS), + PDO_FIXED(12000, 3000, PDO_FIXED_FLAGS), + PDO_FIXED(20000, 3000, PDO_FIXED_FLAGS), + }; + const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); + uint32_t pdo; + + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 5000, &pdo), 0, + "%d"); + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 9000, &pdo), 3, + "%d"); + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 10000, &pdo), 3, + "%d"); + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 12000, &pdo), 4, + "%d"); + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 15000, &pdo), 4, + "%d"); + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 20000, &pdo), 5, + "%d"); + return EC_SUCCESS; +} + +void run_test(void) +{ + RUN_TEST(test_pd_find_pdo_index); + + test_print_result(); +} |