diff options
-rw-r--r-- | zephyr/dts/it8xxx2_emul.dts | 8 | ||||
-rw-r--r-- | zephyr/projects/corsola/src/krabby/usbc_config.c | 4 | ||||
-rw-r--r-- | zephyr/test/krabby/CMakeLists.txt | 4 | ||||
-rw-r--r-- | zephyr/test/krabby/common.dts | 20 | ||||
-rw-r--r-- | zephyr/test/krabby/prj.conf | 8 | ||||
-rw-r--r-- | zephyr/test/krabby/src/stubs.c | 41 | ||||
-rw-r--r-- | zephyr/test/krabby/src/usb_mux_init.c | 28 |
7 files changed, 110 insertions, 3 deletions
diff --git a/zephyr/dts/it8xxx2_emul.dts b/zephyr/dts/it8xxx2_emul.dts index dcb44aebd2..b22251b67b 100644 --- a/zephyr/dts/it8xxx2_emul.dts +++ b/zephyr/dts/it8xxx2_emul.dts @@ -174,4 +174,12 @@ #size-cells = <0>; reg = <0xf01c40 0x1000>; }; + + i2c_ctrl4: i2c@f03500 { + compatible = "zephyr,i2c-emul-controller"; + clock-frequency = <I2C_BITRATE_STANDARD>; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x00f03500 0x0080>; + }; }; diff --git a/zephyr/projects/corsola/src/krabby/usbc_config.c b/zephyr/projects/corsola/src/krabby/usbc_config.c index 4870b1c98b..7a7f710804 100644 --- a/zephyr/projects/corsola/src/krabby/usbc_config.c +++ b/zephyr/projects/corsola/src/krabby/usbc_config.c @@ -36,6 +36,7 @@ int tusb1064_mux_1_board_init(const struct usb_mux *me) MASK_SET); } +#ifdef CONFIG_USB_PD_TCPM_ITE_ON_CHIP const struct cc_para_t *board_get_cc_tuning_parameter(enum usbpd_port port) { const static struct cc_para_t @@ -56,6 +57,7 @@ const struct cc_para_t *board_get_cc_tuning_parameter(enum usbpd_port port) return &cc_parameter[port]; } +#endif void board_reset_pd_mcu(void) { @@ -65,6 +67,7 @@ void board_reset_pd_mcu(void) */ } +#ifndef CONFIG_TEST int board_set_active_charge_port(int port) { int i; @@ -121,6 +124,7 @@ int board_set_active_charge_port(int port) return EC_SUCCESS; } +#endif #ifdef CONFIG_USB_PD_VBUS_MEASURE_ADC_EACH_PORT enum adc_channel board_get_vbus_adc(int port) diff --git a/zephyr/test/krabby/CMakeLists.txt b/zephyr/test/krabby/CMakeLists.txt index f50aa63d97..639eb858b7 100644 --- a/zephyr/test/krabby/CMakeLists.txt +++ b/zephyr/test/krabby/CMakeLists.txt @@ -13,4 +13,6 @@ zephyr_include_directories("${PLATFORM_EC}/zephyr/projects/corsola/include") target_sources(app PRIVATE src/charger_workaround.c src/stubs.c - ${PLATFORM_EC}/zephyr/projects/corsola/src/krabby/charger_workaround.c) + src/usb_mux_init.c + ${PLATFORM_EC}/zephyr/projects/corsola/src/krabby/charger_workaround.c + ${PLATFORM_EC}/zephyr/projects/corsola/src/krabby/usbc_config.c) diff --git a/zephyr/test/krabby/common.dts b/zephyr/test/krabby/common.dts index d9f1a4f463..b8f1eb0733 100644 --- a/zephyr/test/krabby/common.dts +++ b/zephyr/test/krabby/common.dts @@ -32,6 +32,16 @@ chg = <&charger>; tcpc = <&tcpci_emul>; }; + + port1@1 { + compatible = "named-usbc-port"; + status = "okay"; + reg = <1>; + usb-mux-chain-1 { + compatible = "cros-ec,usb-mux-chain"; + usb-muxes = <&tusb1064_mux_1>; + }; + }; }; batteries { @@ -68,3 +78,13 @@ reg = <0x82>; }; }; + +&i2c_ctrl4 { + status="okay"; + + tusb1064_mux_1: tusb1064-mux-1@44 { + compatible = "zephyr,tusb1064-emul"; + reg = <0x44>; + board-init = "tusb1064_mux_1_board_init"; + }; +}; diff --git a/zephyr/test/krabby/prj.conf b/zephyr/test/krabby/prj.conf index 21a2603db2..ddf5a29c21 100644 --- a/zephyr/test/krabby/prj.conf +++ b/zephyr/test/krabby/prj.conf @@ -6,12 +6,14 @@ CONFIG_ZTEST=y CONFIG_ZTEST_ASSERT_VERBOSE=1 CONFIG_ZTEST_NEW_API=y +CONFIG_ADC=y CONFIG_ASSERT=y CONFIG_CROS_EC=y CONFIG_EMUL=y CONFIG_EMUL_RT9490=y CONFIG_EMUL_SMART_BATTERY=y CONFIG_EMUL_TCPCI=y +CONFIG_EMUL_TUSB1064=y CONFIG_I2C=y CONFIG_I2C_EMUL=y @@ -29,7 +31,9 @@ CONFIG_PLATFORM_EC_HOOKS=y CONFIG_PLATFORM_EC_HOSTCMD=y CONFIG_PLATFORM_EC_LID_SWITCH=n CONFIG_PLATFORM_EC_SWITCH=n -CONFIG_PLATFORM_EC_USBC=n +CONFIG_PLATFORM_EC_USBC=y CONFIG_PLATFORM_EC_USB_CHARGER=n -CONFIG_PLATFORM_EC_USB_POWER_DELIVERY=n +CONFIG_PLATFORM_EC_USB_MUX_TUSB546=y +CONFIG_PLATFORM_EC_USB_PD_DISCHARGE_PPC=y +CONFIG_PLATFORM_EC_USB_POWER_DELIVERY=y CONFIG_PLATFORM_EC_VBOOT_HASH=n diff --git a/zephyr/test/krabby/src/stubs.c b/zephyr/test/krabby/src/stubs.c index b6cc0c5368..e2dfa720b4 100644 --- a/zephyr/test/krabby/src/stubs.c +++ b/zephyr/test/krabby/src/stubs.c @@ -3,6 +3,8 @@ * found in the LICENSE file. */ +#include "adc.h" +#include "usbc_ppc.h" #include "charge_ramp.h" #include "charge_state.h" @@ -27,3 +29,42 @@ const struct batt_params *charger_current_battery_params(void) return ¶ms; } + +int board_get_battery_soc(void) +{ + return 0; +} + +void pd_power_supply_reset(void) +{ +} + +int pd_check_vconn_swap(int port) +{ + return 0; +} + +void pd_set_input_current_limit(int port, uint32_t max_ma, + uint32_t supply_voltage) +{ +} + +int pd_set_power_supply_ready(int port) +{ + return 0; +} + +void usb_charger_vbus_change(int port, int vbus_level) +{ +} + +int charge_manager_get_active_charge_port(void) +{ + return 0; +} + +struct ppc_config_t ppc_chips[] = {}; + +unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); + +const struct adc_t adc_channels[] = {}; diff --git a/zephyr/test/krabby/src/usb_mux_init.c b/zephyr/test/krabby/src/usb_mux_init.c new file mode 100644 index 0000000000..665f1c7b7e --- /dev/null +++ b/zephyr/test/krabby/src/usb_mux_init.c @@ -0,0 +1,28 @@ +/* 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/devicetree.h> +#include <zephyr/drivers/emul.h> +#include <zephyr/ztest.h> + +#include "driver/usb_mux/tusb1064.h" +#include "emul/emul_tusb1064.h" +#include "usb_mux.h" +#include "usbc/usb_muxes.h" + +const static struct emul *emul = EMUL_DT_GET(DT_NODELABEL(tusb1064_mux_1)); + +const static int tusb1064_port = USB_MUX_PORT(DT_NODELABEL(tusb1064_mux_1)); + +ZTEST(usb_mux_init, test_mux_init_value) +{ + usb_mux_set(tusb1064_port, USB_PD_MUX_DP_ENABLED, USB_SWITCH_CONNECT, + 0); + zassert_equal(tusb1064_emul_peek_reg(emul, TUSB1064_REG_DP1DP3EQ_SEL), + TUSB1064_DP1EQ(TUSB1064_DP_EQ_RX_8_9_DB) | + TUSB1064_DP3EQ(TUSB1064_DP_EQ_RX_5_4_DB)); +} + +ZTEST_SUITE(usb_mux_init, NULL, NULL, NULL, NULL, NULL); |