summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlschyi <lschyi@google.com>2023-05-15 15:37:12 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-16 01:49:13 +0000
commitefe0fbc416966340abae6539df8b2ab5a7e5a219 (patch)
tree83cc915ecea5236754a8f5433e93b970c323b5c8
parent69f476737a9167bd5d650d74d2f2e809ef203275 (diff)
downloadchrome-ec-efe0fbc416966340abae6539df8b2ab5a7e5a219.tar.gz
corsola: Fix reported USB-C ports for no DB design with DB detection on
The definition of `CORSOLA_DB_NONE` was settled to no DB in the project in the previous CL "corsola: Update implementation for no daughter board ", and the USB-C counts is determined by dts settings in previous CL " corosla: Improve USB-C port configuration". This introduces a reported port number mismatch when the DB detection is enabled, and the desired detection result is no DB in the design. Extend the DB status enum with `CORSOLA_DB_NO_DETECTION` to properly describe the different DB status, and fix the reported USB-C port logic. BUG=b:282625153 TEST=`zmake build <all board> --clobber` Change-Id: Idd55381759677272e0bfc7b270647d759642ce01 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4530326 Reviewed-by: Ting Shen <phoenixshen@chromium.org> Tested-by: Sung-Chi Li <lschyi@chromium.org> Commit-Queue: Sung-Chi Li <lschyi@chromium.org>
-rw-r--r--zephyr/program/corsola/include/variant_db_detection.h5
-rw-r--r--zephyr/program/corsola/src/usbc.c6
-rw-r--r--zephyr/test/kingler/CMakeLists.txt6
-rw-r--r--zephyr/test/kingler/Kconfig6
-rw-r--r--zephyr/test/kingler/src/fakes.c5
-rw-r--r--zephyr/test/kingler/src/usb_port_count.c90
-rw-r--r--zephyr/test/kingler/testcase.yaml5
7 files changed, 119 insertions, 4 deletions
diff --git a/zephyr/program/corsola/include/variant_db_detection.h b/zephyr/program/corsola/include/variant_db_detection.h
index cf86e1ae1c..fb468126ef 100644
--- a/zephyr/program/corsola/include/variant_db_detection.h
+++ b/zephyr/program/corsola/include/variant_db_detection.h
@@ -12,6 +12,9 @@
enum corsola_db_type {
CORSOLA_DB_UNINIT = -1,
+ /* CORSOLA_DB_NO_DETECTION means there is no detection involved in. */
+ CORSOLA_DB_NO_DETECTION,
+ /* CORSOLA_DB_NONE means there is no DB in the design. */
CORSOLA_DB_NONE,
CORSOLA_DB_TYPEC,
CORSOLA_DB_HDMI,
@@ -28,7 +31,7 @@ enum corsola_db_type corsola_get_db_type(void);
#elif !defined(CONFIG_TEST)
inline enum corsola_db_type corsola_get_db_type(void)
{
- return CORSOLA_DB_NONE;
+ return CORSOLA_DB_NO_DETECTION;
}
#endif
diff --git a/zephyr/program/corsola/src/usbc.c b/zephyr/program/corsola/src/usbc.c
index 71c02ff54f..871c84a2e4 100644
--- a/zephyr/program/corsola/src/usbc.c
+++ b/zephyr/program/corsola/src/usbc.c
@@ -45,7 +45,7 @@ DECLARE_HOOK(HOOK_INIT, baseboard_init, HOOK_PRIO_PRE_DEFAULT);
__override uint8_t board_get_usb_pd_port_count(void)
{
- /* This function returns the PORT_COUNT+1 when HDMI db is connected.
+ /* This function returns the PORT_COUNT when HDMI db is connected.
* This is a trick to ensure the usb_mux_set being set properley.
* HDMI display functions using the USB virtual mux to * communicate
* with the DP bridge.
@@ -56,6 +56,8 @@ __override uint8_t board_get_usb_pd_port_count(void)
} else {
return CONFIG_USB_PD_PORT_MAX_COUNT - 1;
}
+ } else if (corsola_get_db_type() == CORSOLA_DB_NONE) {
+ return CONFIG_USB_PD_PORT_MAX_COUNT - 1;
}
return CONFIG_USB_PD_PORT_MAX_COUNT;
@@ -65,7 +67,7 @@ uint8_t board_get_adjusted_usb_pd_port_count(void)
{
const enum corsola_db_type db = corsola_get_db_type();
- if (db == CORSOLA_DB_TYPEC || db == CORSOLA_DB_NONE) {
+ if (db == CORSOLA_DB_TYPEC || db == CORSOLA_DB_NO_DETECTION) {
return CONFIG_USB_PD_PORT_MAX_COUNT;
} else {
return CONFIG_USB_PD_PORT_MAX_COUNT - 1;
diff --git a/zephyr/test/kingler/CMakeLists.txt b/zephyr/test/kingler/CMakeLists.txt
index f361e6eb3e..31f7b9cc2c 100644
--- a/zephyr/test/kingler/CMakeLists.txt
+++ b/zephyr/test/kingler/CMakeLists.txt
@@ -47,3 +47,9 @@ target_sources_ifdef(CONFIG_TEST_KINGLER_CCD app PRIVATE src/ccd.c
${PLATFORM_EC_PROGRAM_DIR}/corsola/src/board.c)
target_sources_ifdef(CONFIG_TEST_VOLTORB app PRIVATE src/voltorb_usbc.c
${PLATFORM_EC_PROGRAM_DIR}/corsola/voltorb/src/usbc.c)
+target_sources_ifdef(
+ CONFIG_TEST_DB_DETECTION_USB_COUNT
+ app
+ PRIVATE
+ ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/usbc.c
+ src/usb_port_count.c)
diff --git a/zephyr/test/kingler/Kconfig b/zephyr/test/kingler/Kconfig
index 4cde54ce6d..77c1f25253 100644
--- a/zephyr/test/kingler/Kconfig
+++ b/zephyr/test/kingler/Kconfig
@@ -71,4 +71,10 @@ config TEST_USB_PD_POLICY
Include voltorb_usbc.c into the binary to test the type-c output
current limit function.
+config TEST_DB_DETECTION_USB_COUNT
+ bool "Run the tests intended for db detection"
+ help
+ Include USB-C tests into the binary for testing the reported port
+ count with db detection.
+
source "Kconfig.zephyr"
diff --git a/zephyr/test/kingler/src/fakes.c b/zephyr/test/kingler/src/fakes.c
index 6c67447e88..c4a7cf0a6d 100644
--- a/zephyr/test/kingler/src/fakes.c
+++ b/zephyr/test/kingler/src/fakes.c
@@ -14,8 +14,11 @@ FAKE_VOID_FUNC(power_signal_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(chipset_watchdog_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(extpower_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(switch_interrupt, enum gpio_signal);
-#ifndef CONFIG_TEST_KINGLER_USBC
+#if !(defined(CONFIG_TEST_KINGLER_USBC) || \
+ defined(CONFIG_TEST_DB_DETECTION_USB_COUNT))
FAKE_VOID_FUNC(xhci_interrupt, enum gpio_signal);
+#endif
+#ifndef CONFIG_TEST_KINGLER_USBC
FAKE_VOID_FUNC(lid_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(usb_a0_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(tcpc_alert_event, enum gpio_signal);
diff --git a/zephyr/test/kingler/src/usb_port_count.c b/zephyr/test/kingler/src/usb_port_count.c
new file mode 100644
index 0000000000..4f55bdc693
--- /dev/null
+++ b/zephyr/test/kingler/src/usb_port_count.c
@@ -0,0 +1,90 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "driver/tcpm/tcpm.h"
+#include "ec_app_main.h"
+#include "usb_charge.h"
+#include "usb_pd.h"
+#include "usbc_ppc.h"
+#include "variant_db_detection.h"
+
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/fff.h>
+#include <zephyr/kernel.h>
+#include <zephyr/logging/log.h>
+#include <zephyr/ztest.h>
+
+#define LOG_LEVEL 0
+LOG_MODULE_REGISTER(usb_port_count);
+
+FAKE_VALUE_FUNC(enum corsola_db_type, corsola_get_db_type);
+FAKE_VALUE_FUNC(bool, in_interrupt_context);
+FAKE_VOID_FUNC(bmi3xx_interrupt);
+FAKE_VOID_FUNC(hdmi_hpd_interrupt);
+FAKE_VOID_FUNC(ps185_hdmi_hpd_mux_set);
+FAKE_VALUE_FUNC(bool, ps8743_field_update, const struct usb_mux *, uint8_t,
+ uint8_t, uint8_t);
+FAKE_VOID_FUNC(pd_set_dual_role, int, enum pd_dual_role_states);
+FAKE_VALUE_FUNC(int, tc_is_attached_src, int);
+
+#define FFF_FAKES_LIST(FAKE) \
+ FAKE(corsola_get_db_type) \
+ FAKE(in_interrupt_context) \
+ FAKE(bmi3xx_interrupt) \
+ FAKE(hdmi_hpd_interrupt) \
+ FAKE(ps185_hdmi_hpd_mux_set) \
+ FAKE(ps8743_field_update) \
+ FAKE(pd_set_dual_role) \
+ FAKE(tc_is_attached_src)
+
+struct usb_port_count_fixture {
+ int place_holder;
+};
+
+static void *usb_port_count_setup(void)
+{
+ static struct usb_port_count_fixture f;
+
+ return &f;
+}
+
+static void usb_port_count_reset_rule_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ FFF_FAKES_LIST(RESET_FAKE);
+ FFF_RESET_HISTORY();
+}
+
+ZTEST_RULE(usb_port_count_reset_rule, usb_port_count_reset_rule_before, NULL);
+ZTEST_SUITE(usb_port_count, NULL, usb_port_count_setup, NULL, NULL, NULL);
+
+ZTEST_F(usb_port_count, test_detect_db)
+{
+ struct {
+ enum corsola_db_type test_type;
+ int expected_board_get_port_count;
+ int expected_board_get_adjusted_port_count;
+ } testdata[] = { { CORSOLA_DB_UNINIT, CONFIG_USB_PD_PORT_MAX_COUNT,
+ CONFIG_USB_PD_PORT_MAX_COUNT - 1 },
+ { CORSOLA_DB_NO_DETECTION,
+ CONFIG_USB_PD_PORT_MAX_COUNT,
+ CONFIG_USB_PD_PORT_MAX_COUNT },
+ { CORSOLA_DB_NONE, CONFIG_USB_PD_PORT_MAX_COUNT - 1,
+ CONFIG_USB_PD_PORT_MAX_COUNT - 1 },
+ { CORSOLA_DB_TYPEC, CONFIG_USB_PD_PORT_MAX_COUNT,
+ CONFIG_USB_PD_PORT_MAX_COUNT },
+ { CORSOLA_DB_HDMI, CONFIG_USB_PD_PORT_MAX_COUNT - 1,
+ CONFIG_USB_PD_PORT_MAX_COUNT - 1 } };
+ for (int i = 0; i < ARRAY_SIZE(testdata); i++) {
+ corsola_get_db_type_fake.return_val = testdata[i].test_type;
+ zassert_equal(board_get_usb_pd_port_count(),
+ testdata[i].expected_board_get_port_count);
+ zassert_equal(
+ board_get_adjusted_usb_pd_port_count(),
+ testdata[i].expected_board_get_adjusted_port_count);
+ }
+}
diff --git a/zephyr/test/kingler/testcase.yaml b/zephyr/test/kingler/testcase.yaml
index 6bfa6f7b7e..8012c7dc4f 100644
--- a/zephyr/test/kingler/testcase.yaml
+++ b/zephyr/test/kingler/testcase.yaml
@@ -58,3 +58,8 @@ tests:
- CONFIG_TEST_USB_PD_POLICY=y
extra_dtc_overlay_files:
- kingler.default.overlay
+ kingler.usb_port_count:
+ extra_configs:
+ - CONFIG_TEST_DB_DETECTION_USB_COUNT=y
+ extra_dtc_overlay_files:
+ - kingler.default.overlay