summaryrefslogtreecommitdiff
path: root/zephyr/test/kingler/src/db_detect_typec.c
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/kingler/src/db_detect_typec.c')
-rw-r--r--zephyr/test/kingler/src/db_detect_typec.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/zephyr/test/kingler/src/db_detect_typec.c b/zephyr/test/kingler/src/db_detect_typec.c
new file mode 100644
index 0000000000..53716fe552
--- /dev/null
+++ b/zephyr/test/kingler/src/db_detect_typec.c
@@ -0,0 +1,85 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "zephyr/kernel.h"
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/ztest.h>
+
+#include "gpio_signal.h"
+#include "hooks.h"
+#include "variant_db_detection.h"
+
+static void *db_detection_setup(void)
+{
+ const struct device *hdmi_prsnt_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_hdmi_prsnt_odl), gpios));
+ const gpio_port_pins_t hdmi_prsnt_pin =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_hdmi_prsnt_odl), gpios);
+ /* Set the GPIO to high to indicate the DB is type-c */
+ zassert_ok(gpio_emul_input_set(hdmi_prsnt_gpio, hdmi_prsnt_pin, 1),
+ NULL);
+
+ hook_notify(HOOK_INIT);
+
+ return NULL;
+}
+
+ZTEST_SUITE(db_detection, NULL, db_detection_setup, NULL, NULL, NULL);
+
+static int interrupt_count;
+void x_ec_interrupt(enum gpio_signal signal)
+{
+ interrupt_count++;
+}
+
+/* test typec db case */
+ZTEST(db_detection, test_db_detect_typec)
+{
+ const struct device *en_frs_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_ALIAS(gpio_usb_c1_frs_en), gpios));
+ const gpio_port_pins_t en_frs_pin =
+ DT_GPIO_PIN(DT_ALIAS(gpio_usb_c1_frs_en), gpios);
+ const struct device *c1_dp_in_hpd_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_ALIAS(gpio_usb_c1_dp_in_hpd), gpios));
+ const gpio_port_pins_t c1_dp_in_hpd_pin =
+ DT_GPIO_PIN(DT_ALIAS(gpio_usb_c1_dp_in_hpd), gpios);
+ const struct device *int_x_ec_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_x_ec_gpio2), gpios));
+ const gpio_port_pins_t int_x_ec_pin =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_x_ec_gpio2), gpios);
+
+ /* Check the DB type is type-c */
+ zassert_equal(CORSOLA_DB_TYPEC, corsola_get_db_type(), NULL);
+
+ /* Verify we can enable or disable FRS by setting gpio_usb_c1_frs_en */
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_frs_en), 1),
+ NULL);
+ zassert_equal(1, gpio_emul_output_get(en_frs_gpio, en_frs_pin), NULL);
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_frs_en), 0),
+ NULL);
+ zassert_equal(0, gpio_emul_output_get(en_frs_gpio, en_frs_pin), NULL);
+
+ /* Verify we can change the gpio_usb_c1_dp_in_hpd state */
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_dp_in_hpd),
+ 1),
+ NULL);
+ zassert_equal(1,
+ gpio_emul_output_get(c1_dp_in_hpd_gpio, c1_dp_in_hpd_pin),
+ NULL);
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_dp_in_hpd),
+ 0),
+ NULL);
+ zassert_equal(0,
+ gpio_emul_output_get(c1_dp_in_hpd_gpio, c1_dp_in_hpd_pin),
+ NULL);
+
+ /* Verify x_ec_interrupt is enabled */
+ interrupt_count = 0;
+ zassert_ok(gpio_emul_input_set(int_x_ec_gpio, int_x_ec_pin, 0), NULL);
+ k_sleep(K_MSEC(100));
+
+ zassert_equal(interrupt_count, 1, "interrupt_count=%d",
+ interrupt_count);
+}