diff options
author | Jeremy Bettis <jbettis@google.com> | 2021-04-06 15:02:55 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-04-13 01:36:59 +0000 |
commit | 33d4fba9daf641d8f52171bc1a1de823a1afb650 (patch) | |
tree | 0f815ed6c8e4fe2e614e1c9bd30fe6a25fe52108 /test/usb_pd_pdo_fixed_test.c | |
parent | 882d9d5f607437f8be042df43730c5bdc8c7931e (diff) | |
download | chrome-ec-33d4fba9daf641d8f52171bc1a1de823a1afb650.tar.gz |
ec: Filter non-FIXED PDOs in servo_v4{p1}
Add a new config CONFIG_USB_PD_ONLY_FIXED_PDOS. If that config is
enabled, ignore non-FIXED PDOs in both the console command `ada_srccaps`
and also when selecting the preferred PDO for a voltage.
Enable CONFIG_USB_PD_ONLY_FIXED_PDOS for servo_v4 and servo_v4p1, since
they don't expose non-fixed PDO in their srccaps. Without this change,
there is a risk that the "best" PDO for a given voltage will be
non-FIXED and then that voltage just won't be supported at all.
BRANCH=none
BUG=b:178484932
TEST=added
Change-Id: I0d1187ca372120c7fe21d627e1b82b59f6334add
Signed-off-by: Jeremy Bettis <jbettis@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2809353
Tested-by: Jeremy Bettis <jbettis@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'test/usb_pd_pdo_fixed_test.c')
-rw-r--r-- | test/usb_pd_pdo_fixed_test.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/usb_pd_pdo_fixed_test.c b/test/usb_pd_pdo_fixed_test.c new file mode 100644 index 0000000000..ad247c3ba2 --- /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(int argc, char **argv) +{ + RUN_TEST(test_pd_find_pdo_index); + + test_print_result(); +} |