diff options
author | YH Lin <yueherngl@google.com> | 2022-10-21 19:42:31 +0000 |
---|---|---|
committer | YH Lin <yueherngl@google.com> | 2022-10-21 19:42:31 +0000 |
commit | 1afa995cc54968d86bec8a23bab66bb07742dbdf (patch) | |
tree | 05312290a753b197be054f5f77d49819f2991ecc | |
parent | 03fdd0082ca2be6b86214b677ac629a558feb722 (diff) | |
parent | fae6145045a7bb060c00de1a1fafe506267159e5 (diff) | |
download | chrome-ec-1afa995cc54968d86bec8a23bab66bb07742dbdf.tar.gz |
Merge remote-tracking branch cros/main into factory-brya-14909.124.B-main
Generated by: util/update_release_branch.py --baseboard brya --relevant_paths_file
baseboard/brya/relevant-paths.txt factory-brya-14909.124.B-main
Relevant changes:
git log --oneline 03fdd0082c..fae6145045 -- baseboard/brya board/agah
board/anahera board/banshee board/brya board/crota board/felwinter
board/gimble board/kano board/mithrax board/osiris board/primus
board/redrix board/taeko board/taniks board/vell board/volmar
driver/bc12/pi3usb9201_public.* driver/charger/bq25710.*
driver/ppc/nx20p348x.* driver/ppc/syv682x_public.*
driver/retimer/bb_retimer_public.* driver/tcpm/nct38xx.*
driver/tcpm/ps8xxx_public.* driver/tcpm/tcpci.* include/power/alderlake*
include/intel_x86.h power/alderlake* power/intel_x86.c
util/getversion.sh
b65e11f66f crota: sync FW_CONFIG form_factor
0d1b98c718 tree: Enable warning for fallthrough in switch statements
93684a594f crota: configure GPIOD2 as PMU alternate function
2fdea49d04 tcpc: modify nct38xx and fusb302 get vbus voltage function
d0307eb698 board/vell: Fix compilation with clang
BRANCH=None
BUG=b:252974232 b:172020503 b:202062363 b:253644823 b:254402731
BUG=b:254401750
TEST=`emerge-brya chromeos-ec`
Force-Relevant-Builds: all
Signed-off-by: YH Lin <yueherngl@google.com>
Change-Id: I74add4a9f4d30822118607765065857ed9753bb3
171 files changed, 2996 insertions, 724 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index acdba815ba..d6f218c8cc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -134,8 +134,14 @@ before_script: --modules-dir "${MODULES_DIR}" -l DEBUG build --coverage -B "${BUILD_DIR}" -t ${TOOLCHAIN:-zephyr} "${PROJECT}" - - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/${PROJECT}/output/merged_twister.info" -a "${BUILD_DIR}/${PROJECT}/output/zephyr.info" -a "${BUILD_DIR}/zephyr_codecov/fixed.info" - - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/${PROJECT}/output/merged_twister_no_ec.info" -e "${BUILD_DIR}/${PROJECT}/output/merged_twister.info" "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**" + - lcov --rc lcov_branch_coverage=1 + -o "${BUILD_DIR}/${PROJECT}/output/merged_twister.info" + -a "${BUILD_DIR}/${PROJECT}/output/zephyr.info" + -a "${BUILD_DIR}/zephyr_codecov/fixed.info" + - lcov --rc lcov_branch_coverage=1 + -o "${BUILD_DIR}/${PROJECT}/output/merged_twister_no_ec.info" + -e "${BUILD_DIR}/${PROJECT}/output/merged_twister.info" + "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**" - grep "SF:" "${BUILD_DIR}/${PROJECT}/output/zephyr.info" | sort -u | sed -e 's|^SF:||' | xargs lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/${PROJECT}/output/filtered_twister.info" @@ -145,14 +151,17 @@ before_script: -t "${PROJECT} coverage of twister tests" -s "${BUILD_DIR}/${PROJECT}/output/filtered_twister.info" - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/${PROJECT}/output/merged.info" - -a "${BUILD_DIR}/${PROJECT}/output/zephyr.info" -a build/merged.info - - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/${PROJECT}/output/no_zephyr.info" + -a "${BUILD_DIR}/${PROJECT}/output/zephyr.info" + -a "${BUILD_DIR}/merged.info" + - lcov --rc lcov_branch_coverage=1 + -o "${BUILD_DIR}/${PROJECT}/output/no_zephyr.info" -r "${BUILD_DIR}/${PROJECT}/output/zephyr.info" "${ZEPHYR_BASE}/**" - "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**" + "${MODULES_DIR}/**" "${EC_DIR}/zephyr/drivers/**" "${EC_DIR}/zephyr/include/drivers/**" "${EC_DIR}/zephyr/shim/chip/**" "${EC_DIR}/zephyr/shim/core/**" - "${EC_DIR}/zephyr/projects/**" "/usr/include/x86_64-linux-gnu/**" - "${EC_DIR}/build/*/build-*/zephyr/*/generated/**" "${EC_DIR}/test/**" + "${EC_DIR}/zephyr/projects/**" "/usr/include/**" + "${EC_DIR}/build/**" "${EC_DIR}/twister-out*/**" + "${EC_DIR}/test/**" "${EC_DIR}/zephyr/shim/chip/npcx/npcx_monitor/**" "${EC_DIR}/zephyr/emul/**" "${EC_DIR}/zephyr/test/**" "**/testsuite/**" "**/subsys/emul/**" @@ -165,8 +174,8 @@ before_script: "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**" "${EC_DIR}/zephyr/drivers/**" "${EC_DIR}/zephyr/include/drivers/**" "${EC_DIR}/zephyr/shim/chip/**" "${EC_DIR}/zephyr/shim/core/**" - "${EC_DIR}/zephyr/projects/**" "/usr/include/x86_64-linux-gnu/**" - "${EC_DIR}/build/*/build-*/zephyr/*/generated/**" + "${EC_DIR}/zephyr/projects/**" "/usr/include/**" + "${EC_DIR}/build/**" "${EC_DIR}/twister-out*/**" "${EC_DIR}/zephyr/shim/chip/npcx/npcx_monitor/**" "${EC_DIR}/test/**" "${EC_DIR}/include/tests/**" @@ -319,33 +328,23 @@ merged_coverage: stage: test needs: ["ec_coverage", "zephyr_coverage", "zephyr_boards_coverage"] script: - - lcov --rc lcov_branch_coverage=1 -o ${BUILD_DIR}/merged.info - -a ${BUILD_DIR}/coverage/lcov.info -a "${TWISTER_OUT_DIR}/coverage.info" - - lcov --rc lcov_branch_coverage=1 -o ${BUILD_DIR}/merged_no_zephyr.info - -r ${BUILD_DIR}/merged.info - "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**" - "${EC_DIR}/zephyr/drivers/**" "${EC_DIR}/zephyr/include/drivers/**" - "${EC_DIR}/zephyr/shim/chip/**" "${EC_DIR}/zephyr/shim/core/**" - "${EC_DIR}/zephyr/projects/**" "/usr/include/x86_64-linux-gnu/**" - "${EC_DIR}/build/*/build-*/zephyr/*/generated/**" "${EC_DIR}/test/**" - "${EC_DIR}/zephyr/shim/chip/npcx/npcx_monitor/**" - "${EC_DIR}/zephyr/emul/**" "${EC_DIR}/zephyr/test/**" - "**/testsuite/**" "**/subsys/emul/**" - - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/all_builds_merged.info" - -a ${BUILD_DIR}/merged.info $(printf ' -a %s' ${BUILD_DIR}/zephyr/all_builds[0-9]*.info) - - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/all_builds_no_zephyr.info" - -r "${BUILD_DIR}/all_builds_merged.info" "${ZEPHYR_BASE}/**" - "${ZEPHYR_BASE}/**" "${MODULES_DIR}/**" - "${EC_DIR}/zephyr/drivers/**" "${EC_DIR}/zephyr/include/drivers/**" - "${EC_DIR}/zephyr/shim/chip/**" "${EC_DIR}/zephyr/shim/core/**" - "${EC_DIR}/zephyr/projects/**" "/usr/include/x86_64-linux-gnu/**" - "${EC_DIR}/build/*/build-*/zephyr/*/generated/**" - "${EC_DIR}/zephyr/shim/chip/npcx/npcx_monitor/**" + # build_dir / "all_tests.info" -> "${BUILD_DIR}/merged.info" + - lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/merged.info" + -a "${BUILD_DIR}/coverage/lcov.info" -a "${TWISTER_OUT_DIR}/coverage.info" + - printf ' -a %s' ${BUILD_DIR}/zephyr/all_builds[0-9]*.info | xargs -x + lcov --rc lcov_branch_coverage=1 -o "${BUILD_DIR}/zephyr/zephyr_merged.info" + -a "${BUILD_DIR}/merged.info" + - lcov --rc lcov_branch_coverage=1 + -o "${BUILD_DIR}/all_builds_filtered.info" + -r "${BUILD_DIR}/zephyr/zephyr_merged.info" + "${EC_DIR}/build/**" "${EC_DIR}/twister-out*/**" "/usr/include/**" + "/usr/lib/**" "${EC_DIR}/test/**" "${EC_DIR}/include/tests/**" "${EC_DIR}/private/test/**" "${EC_DIR}/private/fingerprint/*/mcutest/**" "${EC_DIR}/zephyr/test/**" + "${ZEPHYR_BASE}/main/subsys/testsuite/**" "${EC_DIR}/include/mock/**" "${EC_DIR}/common/mock/**" "${EC_DIR}/board/host/**" @@ -353,6 +352,7 @@ merged_coverage: "${EC_DIR}/core/host/**" "${EC_DIR}/zephyr/emul/**" "${EC_DIR}/zephyr/mock/**" + "${ZEPHYR_BASE}/main/subsys/emul/**" "**/*_test.c" "**/*_test.h" "**/*_emul.c" @@ -361,13 +361,9 @@ merged_coverage: "${EC_DIR}/common/test_util.c" "${EC_DIR}/zephyr/shim/src/test_util.c" "${EC_DIR}/zephyr/shim/src/ztest_system.c" - - grep -h "SF:" ${BUILD_DIR}/zephyr/all_builds[0-9]*.info | sort -u | - sed -e 's|^SF:||' | xargs lcov --rc lcov_branch_coverage=1 - -o "${BUILD_DIR}/all_builds_filtered.info" - -e "${BUILD_DIR}/all_builds_no_zephyr.info" - /usr/bin/genhtml --branch-coverage -q -o "${BUILD_DIR}/all_builds_filtered_rpt" - -t "All boards coverage w/o zephyr" + -t "All boards and tests merged" -p ${EC_DIR} -s "${BUILD_DIR}/all_builds_filtered.info" artifacts: @@ -272,6 +272,7 @@ else include libc/build.mk endif include chip/$(CHIP)/build.mk +include core/build.mk include core/$(CORE)/build.mk include common/build.mk include driver/build.mk diff --git a/Makefile.rules b/Makefile.rules index 860d032981..8b52882635 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -101,6 +101,8 @@ cmd_run_fuzz = build/host/$*/$*.exe -seed=1 -runs=1 $(silent) \ cmd_exe = $(CXX) $(ro-objs) $(HOST_TEST_LDFLAGS) $(LDFLAGS_EXTRA) -o $@ cmd_c_to_o = $(CC) -std=gnu11 $(C_WARN) $(CFLAGS) -MMD -MP -MF $@.d -c $< \ -MT $(@D)/$(@F) -o $(@D)/$(@F) +cmd_c_to_s = $(CC) -S $(C_WARN) $(CFLAGS) -fno-lto -MMD -MP -MF $@.d -c $< \ + -MT $(@D)/$(@F) -o $(@D)/$(@F) cmd_cxx_to_o = $(CXX) -std=gnu++17 $(CFLAGS) $(CXXFLAGS) -MMD -MP -MF $@.d -c $< \ -MT $(@D)/$(@F) -o $(@D)/$(@F) cmd_c_to_build = $(BUILDCC) $(BUILD_CFLAGS) \ @@ -618,6 +620,11 @@ $(out)/RO/%.o:%.c $(out)/RW/%.o:%.c $(call quiet,c_to_o,CC ) +$(out)/RO/%.s:%.c + $(call quiet,c_to_s,CC ) +$(out)/RW/%.s:%.c + $(call quiet,c_to_s,CC ) + $(out)/RO/%.o:%.cc $(call quiet,cxx_to_o,CXX ) $(out)/RW/%.o:%.cc diff --git a/Makefile.toolchain b/Makefile.toolchain index 3c93d774d4..c2612d260c 100644 --- a/Makefile.toolchain +++ b/Makefile.toolchain @@ -115,7 +115,7 @@ C_WARN = -Wstrict-prototypes -Wdeclaration-after-statement -Wno-pointer-sign C_WARN += -Werror-implicit-function-declaration COMMON_WARN = -Wall -Wundef \ -Wno-trigraphs -Wno-format-security -Wno-address-of-packed-member \ - -fno-common -fno-strict-aliasing -fno-strict-overflow + -fno-common -fno-strict-aliasing -fno-strict-overflow -Wimplicit-fallthrough # See https://www.chromium.org/chromium-os/build/c-exception-support COMMON_WARN+=-fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables diff --git a/baseboard/intelrvp/led_states.c b/baseboard/intelrvp/led_states.c index 8629085c4f..6bcee159a3 100644 --- a/baseboard/intelrvp/led_states.c +++ b/baseboard/intelrvp/led_states.c @@ -39,7 +39,7 @@ static enum led_states led_get_state(void) new_state = STATE_CHARGING_FULL_CHARGE; break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE /* and PWR_STATE_DISCHARGE_FULL */: if (chipset_in_state(CHIPSET_STATE_ON)) new_state = STATE_DISCHARGE_S0; diff --git a/board/boldar/board.c b/board/boldar/board.c index 19b8f44020..1076ccc040 100644 --- a/board/boldar/board.c +++ b/board/boldar/board.c @@ -474,6 +474,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/burnet/led.c b/board/burnet/led.c index 4aa91c63e2..68c4c9e839 100644 --- a/board/burnet/led.c +++ b/board/burnet/led.c @@ -147,7 +147,7 @@ static void led_set_battery(void) led_set_color_battery(LED_WHITE); break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE: /* * Blink white light (1 sec on, 1 sec off) diff --git a/board/careena/led.c b/board/careena/led.c index 48a065fdb9..9a280a011b 100644 --- a/board/careena/led.c +++ b/board/careena/led.c @@ -110,7 +110,7 @@ static void led_set_battery(void) led_set_color_battery(LED_WHITE); break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE: /* * Blink white light (1 sec on, 1 sec off) diff --git a/board/chronicler/usbc_config.c b/board/chronicler/usbc_config.c index b05cd4ecfd..85c40e93e1 100644 --- a/board/chronicler/usbc_config.c +++ b/board/chronicler/usbc_config.c @@ -68,6 +68,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/collis/board.c b/board/collis/board.c index 6b2c81bc02..56c67989a5 100644 --- a/board/collis/board.c +++ b/board/collis/board.c @@ -270,6 +270,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/copano/board.c b/board/copano/board.c index b4a8c5eb20..8d58fa1101 100644 --- a/board/copano/board.c +++ b/board/copano/board.c @@ -310,6 +310,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/coral/led.c b/board/coral/led.c index 8af0f6f3e2..b8515c14c7 100644 --- a/board/coral/led.c +++ b/board/coral/led.c @@ -188,7 +188,7 @@ static enum led_states led_get_state(void) new_state = STATE_CHARGING_LVL_3; break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE /* and PWR_STATE_DISCHARGE_FULL */: if (chipset_in_state(CHIPSET_STATE_ON)) new_state = STATE_DISCHARGE_S0; diff --git a/board/corori/led.c b/board/corori/led.c index 89799c8e74..f47871a4ed 100644 --- a/board/corori/led.c +++ b/board/corori/led.c @@ -127,7 +127,7 @@ static enum led_states led_get_state(void) new_state = STATE_CHARGING_FULL_CHARGE; break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE /* and PWR_STATE_DISCHARGE_FULL */: if (chipset_in_state(CHIPSET_STATE_ON)) new_state = (led_get_charge_percent() < 10) ? diff --git a/board/corori2/board.h b/board/corori2/board.h index 0fc4423020..3483d96f88 100644 --- a/board/corori2/board.h +++ b/board/corori2/board.h @@ -21,7 +21,7 @@ #define CONFIG_CHIP_INIT_ROM_REGION #undef CONFIG_CONSOLE_CMDHELP #define CONFIG_DEBUG_ASSERT_BRIEF -#define CONFIG_USB_PD_DEBUG_LEVEL 2 +#define CONFIG_USB_PD_DEBUG_LEVEL 0 /* EC console commands */ #define CONFIG_CMD_CHARGER_DUMP @@ -29,6 +29,8 @@ /* Remove default commands to free flash space */ #undef CONFIG_CMD_ACCELSPOOF #undef CONFIG_CMD_BATTFAKE +#undef CONFIG_CMD_GETTIME +#undef CONFIG_CMD_MEM /* Battery */ #define CONFIG_BATTERY_FUEL_GAUGE diff --git a/board/crota/board.c b/board/crota/board.c index fbcb6c7865..cb3e79ee56 100644 --- a/board/crota/board.c +++ b/board/crota/board.c @@ -53,7 +53,11 @@ DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); static bool board_is_convertible(void) { - return !!get_fw_config().form_factor; + /* + * convertible = 0 + * clamshell = 1 + */ + return !get_fw_config().form_factor; } int board_sensor_at_360(void) diff --git a/board/crota/gpio.inc b/board/crota/gpio.inc index 7668442b7b..0a3471b5c0 100644 --- a/board/crota/gpio.inc +++ b/board/crota/gpio.inc @@ -104,6 +104,7 @@ ALTERNATE(PIN_MASK(8, 0x04), 0, MODULE_KB, GPIO_ODR_HIGH) /* KSO14/GPIO82 */ /* PMU alternate functions */ ALTERNATE(PIN_MASK(0, 0x01), 0, MODULE_PMU, GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH) /* PSL_IN2_L&GPI00/GPIO00 */ ALTERNATE(PIN_MASK(0, 0x02), 0, MODULE_PMU, GPIO_INT_BOTH | GPIO_HIB_WAKE_LOW) /* GPIO01/PSL_IN3_L&GPI01 */ +ALTERNATE(PIN_MASK(D, 0x04), 0, MODULE_PMU, GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH) /* PSL_IN1_L&GPID2/GPIOD2 */ /* Unused Pins */ UNUSED(PIN(D, 6)) /* GPOD6/CR_SOUT3/SHDF_ESPI_L */ diff --git a/board/delbin/board.c b/board/delbin/board.c index 1cdb42d954..28a0c929e2 100644 --- a/board/delbin/board.c +++ b/board/delbin/board.c @@ -370,6 +370,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/dojo/board.c b/board/dojo/board.c index 65a1635111..62f2e6ac09 100644 --- a/board/dojo/board.c +++ b/board/dojo/board.c @@ -24,6 +24,7 @@ #include "hooks.h" #include "keyboard_scan.h" #include "motion_sense.h" +#include "power.h" #include "pwm.h" #include "pwm_chip.h" #include "system.h" @@ -476,6 +477,24 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma, MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv); } +/* NVME */ +static void nvme_enable(int enable) +{ + gpio_set_level(GPIO_EN_PP3300_SSD, enable); +} + +void suspend_resume_power_signal_interrupt(enum gpio_signal signal) +{ + /* AP resume */ + if (gpio_get_level(signal) == GPIO_SIGNAL_RESUME) + nvme_enable(1); + /* AP suspend */ + else + nvme_enable(0); + + power_signal_interrupt(signal); +} + /* Initialize board. */ static void board_init(void) { @@ -489,23 +508,17 @@ static void board_init(void) /* Store base sensor to recognize which base sensor we are using */ base_sensor = get_cbi_ssfc_base_sensor(); + /* Make sure that nvme can be enabled/disabled when board init */ + if (gpio_get_level(GPIO_AP_IN_SLEEP_L) == GPIO_SIGNAL_RESUME) + nvme_enable(1); + else + nvme_enable(0); + board_update_motion_sensor_config(); board_update_vol_up_key(); } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); -static void enable_nvme(void) -{ - gpio_set_level(GPIO_EN_PP3300_SSD, 1); -} -DECLARE_HOOK(HOOK_CHIPSET_RESUME_INIT, enable_nvme, HOOK_PRIO_FIRST); - -static void disable_nvme(void) -{ - gpio_set_level(GPIO_EN_PP3300_SSD, 0); -} -DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, disable_nvme, HOOK_PRIO_DEFAULT); - static void board_do_chipset_resume(void) { gpio_set_level(GPIO_EN_KB_BL, 1); diff --git a/board/dojo/board.h b/board/dojo/board.h index cc2d5eba2f..ad34d7679c 100644 --- a/board/dojo/board.h +++ b/board/dojo/board.h @@ -154,6 +154,13 @@ struct vol_up_key { uint8_t col; }; +/* AP in sleep power signal */ +enum ap_in_sleep_l_signal { + GPIO_SIGNAL_SUSPEND = 0, + GPIO_SIGNAL_RESUME, +}; +void suspend_resume_power_signal_interrupt(enum gpio_signal signal); + int board_accel_force_mode_mask(void); void motion_interrupt(enum gpio_signal signal); diff --git a/board/dojo/gpio.inc b/board/dojo/gpio.inc index 0fb85b47b7..35a0fa0eae 100644 --- a/board/dojo/gpio.inc +++ b/board/dojo/gpio.inc @@ -24,7 +24,8 @@ GPIO_INT(AP_EC_WARM_RST_REQ, PIN(D, 3), GPIO_INT_RISING | GPIO_SEL_1P8V, GPIO_INT(AP_EC_WATCHDOG_L, PIN(C, 7), GPIO_INT_BOTH | GPIO_SEL_1P8V, chipset_watchdog_interrupt) GPIO_INT(AP_IN_SLEEP_L, PIN(F, 2), - GPIO_INT_BOTH | GPIO_PULL_DOWN | GPIO_SEL_1P8V, power_signal_interrupt) + GPIO_INT_BOTH | GPIO_PULL_DOWN | GPIO_SEL_1P8V, + suspend_resume_power_signal_interrupt) GPIO_INT(PMIC_EC_PWRGD, PIN(F, 3), GPIO_INT_BOTH | GPIO_PULL_DOWN | GPIO_SEL_1P8V, power_signal_interrupt) diff --git a/board/drawcia/led.c b/board/drawcia/led.c index 8e6263fbbc..0fee248506 100644 --- a/board/drawcia/led.c +++ b/board/drawcia/led.c @@ -142,7 +142,7 @@ static void led_set_battery(void) led_set_color_battery(LED_WHITE); break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE: /* * Blink white light (1 sec on, 1 sec off) diff --git a/board/drawcia_riscv/led.c b/board/drawcia_riscv/led.c index 3cb7cb835e..d72626b2a2 100644 --- a/board/drawcia_riscv/led.c +++ b/board/drawcia_riscv/led.c @@ -142,7 +142,7 @@ static void led_set_battery(void) led_set_color_battery(LED_WHITE); break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE: /* * Blink white light (1 sec on, 1 sec off) diff --git a/board/drobit/board.c b/board/drobit/board.c index 19b5162092..1a20870d1f 100644 --- a/board/drobit/board.c +++ b/board/drobit/board.c @@ -303,6 +303,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/eldrid/board.c b/board/eldrid/board.c index 717878bc95..81fdf22ffc 100644 --- a/board/eldrid/board.c +++ b/board/eldrid/board.c @@ -516,6 +516,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/elemi/board.c b/board/elemi/board.c index 6b166e1206..96860d2335 100644 --- a/board/elemi/board.c +++ b/board/elemi/board.c @@ -347,6 +347,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/haboki/led.c b/board/haboki/led.c index b31d4fab75..c6e481e285 100644 --- a/board/haboki/led.c +++ b/board/haboki/led.c @@ -142,7 +142,7 @@ static void led_set_battery(void) led_set_color_battery(LED_WHITE); break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE: /* * Blink white light (1 sec on, 1 sec off) diff --git a/board/hatch_fp/build.mk b/board/hatch_fp/build.mk index 4afdb1c1c3..828e7523b3 100644 --- a/board/hatch_fp/build.mk +++ b/board/hatch_fp/build.mk @@ -55,6 +55,7 @@ test-list-y=\ sha256_unrolled \ static_if \ stdlib \ + std_vector \ stm32f_rtc \ system_is_locked \ timer_dos \ diff --git a/board/kappa/led.c b/board/kappa/led.c index 1c7979eac0..1dc86013d7 100644 --- a/board/kappa/led.c +++ b/board/kappa/led.c @@ -104,7 +104,7 @@ static void led_set_battery(void) led_set_color_battery(LED_WHITE); break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE: /* * Blink white light (1 sec on, 1 sec off) diff --git a/board/kuldax/led.c b/board/kuldax/led.c index 8da760193b..39b79e2196 100644 --- a/board/kuldax/led.c +++ b/board/kuldax/led.c @@ -182,6 +182,16 @@ static void led_resume(void) } DECLARE_HOOK(HOOK_CHIPSET_RESUME, led_resume, HOOK_PRIO_DEFAULT); +void board_led_auto_control(void) +{ + if (chipset_in_state(CHIPSET_STATE_ON)) + led_resume(); + else if (chipset_in_state(CHIPSET_STATE_SUSPEND)) + led_suspend_hook(); + else if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + led_shutdown_hook(); +} + void led_alert(int enable) { if (enable) { diff --git a/board/lantis/led.c b/board/lantis/led.c index d6dbc929a8..3b66ad6d6b 100644 --- a/board/lantis/led.c +++ b/board/lantis/led.c @@ -199,7 +199,7 @@ static void led_set_battery(void) set_active_port_color(LED_WHITE); break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE: /* * Blink white/amber light (1 sec on, 1 sec off) diff --git a/board/lindar/board.c b/board/lindar/board.c index 5bb155550e..e3ee0ff9c4 100644 --- a/board/lindar/board.c +++ b/board/lindar/board.c @@ -479,6 +479,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/moli/thermal.c b/board/moli/thermal.c index 110d8ae2db..16aaa5c069 100644 --- a/board/moli/thermal.c +++ b/board/moli/thermal.c @@ -52,21 +52,21 @@ static const struct fan_step fan_table[] = { }, { /* level 3 */ - .on = { -1, 70, -1 }, - .off = { -1, 67, -1 }, - .rpm = { 3500 }, + .on = { -1, 64, -1 }, + .off = { -1, 61, -1 }, + .rpm = { 3700 }, }, { /* level 4 */ - .on = { -1, 80, -1 }, - .off = { -1, 77, -1 }, - .rpm = { 4000 }, + .on = { -1, 67, -1 }, + .off = { -1, 64, -1 }, + .rpm = { 4400 }, }, { /* level 5 */ - .on = { -1, 90, -1 }, - .off = { -1, 87, -1 }, - .rpm = { 4500 }, + .on = { -1, 70, -1 }, + .off = { -1, 67, -1 }, + .rpm = { 5000 }, }, }; const int num_fan_levels = ARRAY_SIZE(fan_table); diff --git a/board/nocturne_fp/build.mk b/board/nocturne_fp/build.mk index c15535555e..65ffd6c096 100644 --- a/board/nocturne_fp/build.mk +++ b/board/nocturne_fp/build.mk @@ -55,6 +55,7 @@ test-list-y=\ sha256_unrolled \ static_if \ stdlib \ + std_vector \ system_is_locked \ timer_dos \ utils \ diff --git a/board/reef/led.c b/board/reef/led.c index 95db062d10..8bc52dbc75 100644 --- a/board/reef/led.c +++ b/board/reef/led.c @@ -104,7 +104,7 @@ static void led_set_battery(void) led_set_color_battery(LED_BLUE); break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE /* and PWR_STATE_DISCHARGE_FULL */: if (chipset_in_state(CHIPSET_STATE_ON)) { led_set_color_battery(LED_BLUE); diff --git a/board/reef_it8320/led.c b/board/reef_it8320/led.c index 1b521b9409..630fdf336d 100644 --- a/board/reef_it8320/led.c +++ b/board/reef_it8320/led.c @@ -105,7 +105,7 @@ static void led_set_battery(void) led_set_color_battery(LED_BLUE); break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE /* and PWR_STATE_DISCHARGE_FULL */: if (chipset_in_state(CHIPSET_STATE_ON)) { led_set_color_battery(LED_BLUE); diff --git a/board/reef_mchp/led.c b/board/reef_mchp/led.c index 469758dc26..96ea6bb958 100644 --- a/board/reef_mchp/led.c +++ b/board/reef_mchp/led.c @@ -105,7 +105,7 @@ static void led_set_battery(void) led_set_color_battery(LED_BLUE); break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE /* and PWR_STATE_DISCHARGE_FULL */: if (chipset_in_state(CHIPSET_STATE_ON)) { led_set_color_battery(LED_BLUE); diff --git a/board/vell/sensors.c b/board/vell/sensors.c index f088fc8867..4957055a7d 100644 --- a/board/vell/sensors.c +++ b/board/vell/sensors.c @@ -217,7 +217,6 @@ BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); [EC_TEMP_THRESH_HIGH] = C_TO_K(85), \ }, \ } -__maybe_unused static const struct ec_thermal_config thermal_cpu = THERMAL_CPU; /* * TODO(b/203839956): update for Alder Lake/vell @@ -235,8 +234,6 @@ __maybe_unused static const struct ec_thermal_config thermal_cpu = THERMAL_CPU; [EC_TEMP_THRESH_HIGH] = C_TO_K(85), \ }, \ } -__maybe_unused static const struct ec_thermal_config thermal_charger = - THERMAL_CHARGER; /* * TODO(b/203839956): update for vell WWAN module @@ -254,8 +251,6 @@ __maybe_unused static const struct ec_thermal_config thermal_charger = [EC_TEMP_THRESH_HIGH] = C_TO_K(65), \ }, \ } -__maybe_unused static const struct ec_thermal_config thermal_wwan = - THERMAL_WWAN; /* * TODO(b/203839956): update for Alder Lake/vell @@ -274,7 +269,6 @@ __maybe_unused static const struct ec_thermal_config thermal_wwan = [EC_TEMP_THRESH_HIGH] = C_TO_K(75), \ }, \ } -__maybe_unused static const struct ec_thermal_config thermal_ddr = THERMAL_DDR; /* * TODO(b/203839956): update for Alder Lake/vell @@ -293,13 +287,11 @@ __maybe_unused static const struct ec_thermal_config thermal_ddr = THERMAL_DDR; [EC_TEMP_THRESH_HIGH] = C_TO_K(75), \ }, \ } -__maybe_unused static const struct ec_thermal_config thermal_regulator = - THERMAL_REGULATOR; struct ec_thermal_config thermal_params[] = { - [TEMP_SENSOR_1_SOC] = thermal_cpu, - [TEMP_SENSOR_2_CHARGER] = thermal_charger, - [TEMP_SENSOR_3_WWAN] = thermal_wwan, - [TEMP_SENSOR_4_DDR] = thermal_ddr, - [TEMP_SENSOR_5_REGULATOR] = thermal_regulator, + [TEMP_SENSOR_1_SOC] = THERMAL_CPU, + [TEMP_SENSOR_2_CHARGER] = THERMAL_CHARGER, + [TEMP_SENSOR_3_WWAN] = THERMAL_WWAN, + [TEMP_SENSOR_4_DDR] = THERMAL_DDR, + [TEMP_SENSOR_5_REGULATOR] = THERMAL_REGULATOR, }; diff --git a/board/voema/board.c b/board/voema/board.c index c4563df105..363cc603ad 100644 --- a/board/voema/board.c +++ b/board/voema/board.c @@ -309,6 +309,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/volet/board.c b/board/volet/board.c index 474ec9cb0e..47140464b6 100644 --- a/board/volet/board.c +++ b/board/volet/board.c @@ -369,6 +369,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/board/voxel/board.c b/board/voxel/board.c index 40dfbe8dc4..4c8badeb1c 100644 --- a/board/voxel/board.c +++ b/board/voxel/board.c @@ -367,6 +367,7 @@ void ppc_interrupt(enum gpio_signal signal) break; case GPIO_USB_C1_PPC_INT_ODL: syv682x_interrupt(USBC_PORT_C1); + break; default: break; } diff --git a/chip/npcx/system.c b/chip/npcx/system.c index 958d873401..9ce043354f 100644 --- a/chip/npcx/system.c +++ b/chip/npcx/system.c @@ -1410,6 +1410,7 @@ void system_set_image_copy(enum ec_image copy) "Change it to %d.", copy, EC_IMAGE_RO); /* Fall through to EC_IMAGE_RO */ + __fallthrough; case EC_IMAGE_RO: SET_BIT(NPCX_FWCTRL, NPCX_FWCTRL_RO_REGION); SET_BIT(NPCX_FWCTRL, NPCX_FWCTRL_FW_SLOT); diff --git a/chip/npcx/wov.c b/chip/npcx/wov.c index 1ae1afe71d..8616cdd001 100644 --- a/chip/npcx/wov.c +++ b/chip/npcx/wov.c @@ -836,6 +836,7 @@ enum ec_error_list wov_set_mode(enum wov_modes wov_mode) case WOV_MODE_RAM_AND_I2S: if ((wov_conf.bit_depth != 16) && (wov_conf.bit_depth != 24)) return EC_ERROR_INVAL; + __fallthrough; case WOV_MODE_I2S: if (apm_get_adc_i2s_dmic_rate() == APM_DMIC_RATE_0_75) wov_dmic_clk_config(1, WOV_DMIC_DIV_BY_4); diff --git a/common/asm_define.h b/common/asm_define.h new file mode 100644 index 0000000000..b47bae067f --- /dev/null +++ b/common/asm_define.h @@ -0,0 +1,25 @@ +/* Copyright 2021 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_COMMON_ASM_DEFINE_H +#define __CROS_EC_COMMON_ASM_DEFINE_H + +#include "stddef.h" + +/* + * Use an immediate integer constraint + * (https://gcc.gnu.org/onlinedocs/gcc/Simple-Constraints.html) to write the + * value. This file is compiled with the "-S" flag, which stops the compiler + * after generating assembly. The resulting assembly is then grepped for the + * "__ASM_DEFINE__" strings, which is used to create a header file with the + * value. + */ +#define ASM_DEFINE(NAME, VAL) \ + __asm__ volatile(".ascii \" __ASM_DEFINE__ " NAME " %0\"" : : "i"(VAL)) + +#define ASM_DEFINE_OFFSET(NAME, TYPE, MEMBER) \ + ASM_DEFINE(NAME, offsetof(TYPE, MEMBER)) + +#endif /* __CROS_EC_COMMON_ASM_DEFINE_H */ diff --git a/common/battery_fuel_gauge.c b/common/battery_fuel_gauge.c index 0382abca26..88f941f194 100644 --- a/common/battery_fuel_gauge.c +++ b/common/battery_fuel_gauge.c @@ -150,7 +150,13 @@ const struct battery_info *battery_get_info(void) return &get_batt_params()->batt_info; } -int cut_off_battery_block_write(const struct ship_mode_info *ship_mode) +/** + * Battery cut off command via SMBus write block. + * + * @param ship_mode Battery ship mode information + * @return non-zero if error + */ +static int cut_off_battery_block_write(const struct ship_mode_info *ship_mode) { int rv; @@ -177,7 +183,13 @@ int cut_off_battery_block_write(const struct ship_mode_info *ship_mode) return sb_write_block(ship_mode->reg_addr, cutdata, sizeof(cutdata)); } -int cut_off_battery_sb_write(const struct ship_mode_info *ship_mode) +/** + * Battery cut off command via SMBus write word. + * + * @param ship_mode Battery ship mode information + * @return non-zero if error + */ +static int cut_off_battery_sb_write(const struct ship_mode_info *ship_mode) { int rv; diff --git a/common/charge_ramp_sw.c b/common/charge_ramp_sw.c index 4c09a94a8d..4e5bdc8149 100644 --- a/common/charge_ramp_sw.c +++ b/common/charge_ramp_sw.c @@ -214,6 +214,7 @@ void chg_ramp_task(void *u) ramp_st_new = CHG_RAMP_OVERCURRENT_DETECT; /* notify host of power info change */ pd_send_host_event(PD_EVENT_POWER_CHANGE); + __fallthrough; case CHG_RAMP_OVERCURRENT_DETECT: /* Check if we should ramp or go straight to stable */ task_wait_time = SECOND; diff --git a/common/console.c b/common/console.c index 9e7d6ad036..b045af1ddf 100644 --- a/common/console.c +++ b/common/console.c @@ -507,6 +507,7 @@ static void console_handle_char(int c) move_cursor_right(); /* Drop through to backspace handling */ + __fallthrough; case '\b': case 0x7f: handle_backspace(); diff --git a/common/dps.c b/common/dps.c index 13f551a95d..c5a8ba4045 100644 --- a/common/dps.c +++ b/common/dps.c @@ -16,6 +16,7 @@ #include "charge_manager.h" #include "charge_state.h" #include "ec_commands.h" +#include "hooks.h" #include "math_util.h" #include "task.h" #include "timer.h" @@ -30,13 +31,8 @@ #define T_REQUEST_STABLE_TIME (10 * SECOND) #define T_NEXT_CHECK_TIME (5 * SECOND) -#define DPS_FLAG_DISABLED BIT(0) -#define DPS_FLAG_NO_SRCCAP BIT(1) -#define DPS_FLAG_WAITING BIT(2) -#define DPS_FLAG_SAMPLED BIT(3) -#define DPS_FLAG_NEED_MORE_PWR BIT(4) - -#define DPS_FLAG_STOP_EVENTS (DPS_FLAG_DISABLED | DPS_FLAG_NO_SRCCAP) +#define DPS_FLAG_STOP_EVENTS \ + (DPS_FLAG_DISABLED | DPS_FLAG_NO_SRCCAP | DPS_FLAG_NO_BATTERY) #define DPS_FLAG_ALL GENMASK(31, 0) #define MAX_MOVING_AVG_WINDOW 5 @@ -52,7 +48,7 @@ static bool fake_enabled; static int fake_mv, fake_ma; static int dynamic_mv; static int dps_port = CHARGE_PORT_NONE; -static uint32_t flag; +static atomic_t flag; #define CPRINTF(format, args...) cprintf(CC_USBPD, "DPS " format, ##args) #define CPRINTS(format, args...) cprints(CC_USBPD, "DPS " format, ##args) @@ -370,18 +366,18 @@ __maybe_unused static bool has_new_power_request(struct pdo_candidate *cand) */ if (is_near_limit(input_pwr_avg, req_pwr) || is_near_limit(input_curr_avg, MIN(req_ma, input_curr_limit))) { - flag |= DPS_FLAG_NEED_MORE_PWR; + atomic_or(&flag, DPS_FLAG_NEED_MORE_PWR); if (!fake_enabled) input_pwr_avg = req_pwr + 1; } else { - flag &= ~DPS_FLAG_NEED_MORE_PWR; + atomic_clear_bits(&flag, DPS_FLAG_NEED_MORE_PWR); } if (debug_level) CPRINTS("C%d 0x%x last (%dmW %dmV) input (%dmW %dmV %dmA) " "avg (%dmW, %dmA)", - active_port, flag, req_pwr, req_mv, input_pwr, vbus, - input_curr, input_pwr_avg, input_curr_avg); + active_port, (int)flag, req_pwr, req_mv, input_pwr, + vbus, input_curr, input_pwr_avg, input_curr_avg); for (int i = 0; i < board_get_usb_pd_port_count(); ++i) { const uint32_t *const src_caps = pd_get_src_caps(i); @@ -498,29 +494,34 @@ void dps_task(void *u) dps_reset(); task_wait_event(-1); /* clear flags after wake up. */ - flag = 0; + atomic_clear(&flag); update_timeout(dps_config.t_check); continue; } else if (now.val < timeout.val) { - flag |= DPS_FLAG_WAITING; + atomic_or(&flag, DPS_FLAG_WAITING); task_wait_event(timeout.val - now.val); - flag &= ~DPS_FLAG_WAITING; + atomic_clear_bits(&flag, DPS_FLAG_WAITING); continue; } if (!is_enabled) { - flag |= DPS_FLAG_DISABLED; + atomic_or(&flag, DPS_FLAG_DISABLED); continue; } if (!has_srccap()) { - flag |= DPS_FLAG_NO_SRCCAP; + atomic_or(&flag, DPS_FLAG_NO_SRCCAP); + continue; + } + + if (battery_is_present() != BP_YES) { + atomic_or(&flag, DPS_FLAG_NO_BATTERY); continue; } if (!has_new_power_request(&curr_cand)) { sample_count = 0; - flag &= ~DPS_FLAG_SAMPLED; + atomic_clear_bits(&flag, DPS_FLAG_SAMPLED); } else { if (last_cand.port == curr_cand.port && last_cand.mv == curr_cand.mv && @@ -528,7 +529,7 @@ void dps_task(void *u) sample_count++; else sample_count = 1; - flag |= DPS_FLAG_SAMPLED; + atomic_or(&flag, DPS_FLAG_SAMPLED); } if (sample_count == dps_config.k_sample) { @@ -536,17 +537,28 @@ void dps_task(void *u) dps_port = curr_cand.port; pd_dpm_request(dps_port, DPM_REQUEST_NEW_POWER_LEVEL); sample_count = 0; - flag &= ~(DPS_FLAG_SAMPLED | DPS_FLAG_NEED_MORE_PWR); + atomic_clear_bits(&flag, (DPS_FLAG_SAMPLED | + DPS_FLAG_NEED_MORE_PWR)); } last_cand.port = curr_cand.port; last_cand.mv = curr_cand.mv; last_cand.mw = curr_cand.mw; - update_timeout(dps_config.t_check); } } +void check_battery_present(void) +{ + const struct batt_params *batt = charger_current_battery_params(); + + if (batt->is_present == BP_YES && (flag & DPS_FLAG_NO_BATTERY)) { + atomic_clear_bits(&flag, DPS_FLAG_NO_BATTERY); + task_wake(TASK_ID_DPS); + } +} +DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, check_battery_present, HOOK_PRIO_DEFAULT); + static int command_dps(int argc, const char **argv) { int port = charge_manager_get_active_charge_port(); @@ -558,8 +570,9 @@ static int command_dps(int argc, const char **argv) int batt_mv; ccprintf("flag=0x%x k_more=%d k_less=%d k_sample=%d k_win=%d\n", - flag, dps_config.k_more_pwr, dps_config.k_less_pwr, - dps_config.k_sample, dps_config.k_window); + (int)flag, dps_config.k_more_pwr, + dps_config.k_less_pwr, dps_config.k_sample, + dps_config.k_window); ccprintf("t_stable=%d t_check=%d\n", dps_config.t_stable / SECOND, dps_config.t_check / SECOND); @@ -703,4 +716,8 @@ __test_only int *dps_get_debug_level(void) { return &debug_level; } +__test_only int dps_get_flag(void) +{ + return flag; +} #endif /* TEST_BUILD */ diff --git a/common/host_command.c b/common/host_command.c index 89a835a1aa..c66a2b91d2 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -492,27 +492,6 @@ static enum ec_status host_command_hello(struct host_cmd_handler_args *args) } DECLARE_HOST_COMMAND(EC_CMD_HELLO, host_command_hello, EC_VER_MASK(0)); -static enum ec_status host_command_read_test(struct host_cmd_handler_args *args) -{ - const struct ec_params_read_test *p = args->params; - struct ec_response_read_test *r = args->response; - - int offset = p->offset; - int size = p->size / sizeof(uint32_t); - int i; - - if (size > ARRAY_SIZE(r->data) || p->size > args->response_size) - return EC_RES_ERROR; - - for (i = 0; i < size; i++) - r->data[i] = offset + i; - - args->response_size = size * sizeof(uint32_t); - - return EC_RES_SUCCESS; -} -DECLARE_HOST_COMMAND(EC_CMD_READ_TEST, host_command_read_test, EC_VER_MASK(0)); - #ifndef CONFIG_HOSTCMD_X86 /* * Host command to read memory map is not needed on LPC, because LPC can diff --git a/common/led_onoff_states.c b/common/led_onoff_states.c index 244257cf1d..404ae06cd9 100644 --- a/common/led_onoff_states.c +++ b/common/led_onoff_states.c @@ -71,7 +71,7 @@ static enum led_states led_get_state(void) new_state = STATE_CHARGING_FULL_CHARGE; break; } - /* Intentional fall-through */ + __fallthrough; case PWR_STATE_DISCHARGE /* and PWR_STATE_DISCHARGE_FULL */: if (chipset_in_state(CHIPSET_STATE_ON)) { #ifdef CONFIG_LED_ONOFF_STATES_BAT_LOW diff --git a/common/motion_sense.c b/common/motion_sense.c index f326259497..38bc5ab702 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -1320,7 +1320,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args) task_set_event(TASK_ID_MOTIONSENSE, TASK_EVENT_MOTION_FLUSH_PENDING); - /* pass-through */ + __fallthrough; case MOTIONSENSE_CMD_FIFO_INFO: if (!IS_ENABLED(CONFIG_ACCEL_FIFO)) { /* @@ -1352,7 +1352,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args) case 0: case 1: fifo_int_enabled = in->fifo_int_enable.enable; - /* fallthrough */ + __fallthrough; case EC_MOTION_SENSE_NO_VALUE: out->fifo_int_enable.ret = fifo_int_enabled; args->response_size = sizeof(out->fifo_int_enable); diff --git a/common/motion_sense_fifo.c b/common/motion_sense_fifo.c index 672b328420..15db978a0b 100644 --- a/common/motion_sense_fifo.c +++ b/common/motion_sense_fifo.c @@ -381,30 +381,18 @@ void motion_sense_fifo_init(void) int motion_sense_fifo_bypass_needed(void) { - int res; - - mutex_lock(&g_sensor_mutex); - res = bypass_needed; - mutex_unlock(&g_sensor_mutex); - return res; + return bypass_needed; } int motion_sense_fifo_wake_up_needed(void) { - int res; - - mutex_lock(&g_sensor_mutex); - res = wake_up_needed; - mutex_unlock(&g_sensor_mutex); - return res; + return wake_up_needed; } void motion_sense_fifo_reset_needed_flags(void) { - mutex_lock(&g_sensor_mutex); wake_up_needed = 0; bypass_needed = 0; - mutex_unlock(&g_sensor_mutex); } void motion_sense_fifo_insert_async_event(struct motion_sensor_t *sensor, diff --git a/common/system.c b/common/system.c index 047b96e799..6f64960170 100644 --- a/common/system.c +++ b/common/system.c @@ -1020,7 +1020,7 @@ static int handle_pending_reboot(enum ec_reboot_cmd cmd) chip_save_reset_flags(chip_read_reset_flags() & ~EC_RESET_FLAG_AP_IDLE); } - /* Intentional fall-through */ + __fallthrough; case EC_REBOOT_HIBERNATE: if (!IS_ENABLED(CONFIG_HIBERNATE)) return EC_ERROR_INVAL; @@ -1739,7 +1739,7 @@ static enum ec_status host_command_reboot(struct host_cmd_handler_args *args) } DECLARE_HOST_COMMAND(EC_CMD_REBOOT_EC, host_command_reboot, EC_VER_MASK(0)); -int system_can_boot_ap(void) +test_mockable int system_can_boot_ap(void) { int soc = -1; int pow = -1; diff --git a/common/usb_common.c b/common/usb_common.c index dec17cad6b..b4fefb6cf7 100644 --- a/common/usb_common.c +++ b/common/usb_common.c @@ -800,7 +800,7 @@ void pd_srccaps_dump(int port) #else const uint32_t pdo = srccaps[i]; const uint32_t pdo_mask = pdo & PDO_TYPE_MASK; - const char *pdo_type; + const char *pdo_type = "?"; bool range_flag = true; pd_extract_pdo_power(pdo, &max_ma, &max_mv, &min_mv); @@ -823,9 +823,6 @@ void pd_srccaps_dump(int port) range_flag = false; } break; - default: - pdo_type = "?"; - break; } ccprintf("Src %d: (%s) %dmV", i, pdo_type, max_mv); diff --git a/common/usb_port_power_dumb.c b/common/usb_port_power_dumb.c index 10eca3ffb7..cfdc016662 100644 --- a/common/usb_port_power_dumb.c +++ b/common/usb_port_power_dumb.c @@ -104,7 +104,7 @@ static int command_set_mode(int argc, const char **argv) return EC_ERROR_PARAM2; usb_port_set_enabled(port_id, mode); - /* fallthrough */ + __fallthrough; case 1: for (i = 0; i < USB_PORT_COUNT; i++) ccprintf("Port %d: %s\n", i, diff --git a/common/usbc/dp_alt_mode.c b/common/usbc/dp_alt_mode.c index 0f2a42ec2a..f53d212b91 100644 --- a/common/usbc/dp_alt_mode.c +++ b/common/usbc/dp_alt_mode.c @@ -283,6 +283,7 @@ enum dpm_msg_setup_status dp_setup_next_vdm(int port, int *vdo_count, return MSG_SETUP_MUX_WAIT; } /* Fall through if no mux set is needed */ + __fallthrough; case DP_PREPARE_CONFIG: vdo_count_ret = modep->fx->config(port, vdm); if (vdo_count_ret == 0) @@ -293,6 +294,7 @@ enum dpm_msg_setup_status dp_setup_next_vdm(int port, int *vdo_count, case DP_ENTER_NAKED: DP_SET_FLAG(port, DP_FLAG_RETRY); /* Fall through to send exit mode */ + __fallthrough; case DP_ACTIVE: /* * Called to exit DP alt mode, either when the mode diff --git a/common/usbc/tbt_alt_mode.c b/common/usbc/tbt_alt_mode.c index d1ad031fad..c0e4e172cc 100644 --- a/common/usbc/tbt_alt_mode.c +++ b/common/usbc/tbt_alt_mode.c @@ -514,7 +514,7 @@ enum dpm_msg_setup_status tbt_setup_next_vdm(int port, int *vdo_count, * done with any retires. */ TBT_SET_FLAG(port, TBT_FLAG_RETRY_DONE); - /* Fall through */ + __fallthrough; case TBT_PREPARE_EXIT_MODE: /* * Called to exit Thunderbolt alt mode, either when the mode is diff --git a/common/usbc/usb_pd_dpm.c b/common/usbc/usb_pd_dpm.c index 3af3ac3dbe..2538ef0be6 100644 --- a/common/usbc/usb_pd_dpm.c +++ b/common/usbc/usb_pd_dpm.c @@ -243,6 +243,7 @@ void dpm_vdm_acked(int port, enum tcpci_msg_type type, int vdo_count, intel_vdm_acked(port, type, vdo_count, vdm); break; } + __fallthrough; default: CPRINTS("C%d: Received unexpected VDM ACK for SVID %d", port, svid); @@ -261,6 +262,7 @@ void dpm_vdm_naked(int port, enum tcpci_msg_type type, uint16_t svid, intel_vdm_naked(port, type, vdm_cmd); break; } + __fallthrough; default: CPRINTS("C%d: Received unexpected VDM NAK for SVID %d", port, svid); diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index 2e3bffbf68..5a5aebc4b4 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -817,11 +817,11 @@ void pe_run(int port, int evt, int en) case SM_PAUSED: if (!en) break; - /* fall through */ + __fallthrough; case SM_INIT: pe_init(port); local_state[port] = SM_RUN; - /* fall through */ + __fallthrough; case SM_RUN: if (!en) { local_state[port] = SM_PAUSED; @@ -5997,8 +5997,8 @@ static void pe_init_vdm_modes_request_run(int port) dfp_consume_modes(port, sop, cnt, payload); break; } + __fallthrough; } - /* Fall Through */ case VDM_RESULT_NAK: /* PE_INIT_VDM_Modes_NAKed embedded here */ pd_set_modes_discovery(port, pe[port].tx_type, requested_svid, diff --git a/common/usbc/usb_prl_sm.c b/common/usbc/usb_prl_sm.c index d4bd5b9a6e..db9f460e61 100644 --- a/common/usbc/usb_prl_sm.c +++ b/common/usbc/usb_prl_sm.c @@ -696,11 +696,11 @@ void prl_run(int port, int evt, int en) case SM_PAUSED: if (!en) break; - /* fall through */ + __fallthrough; case SM_INIT: prl_init(port); local_state[port] = SM_RUN; - /* fall through */ + __fallthrough; case SM_RUN: if (!en) { /* Disable RX */ diff --git a/common/usbc/usb_retimer_fw_update.c b/common/usbc/usb_retimer_fw_update.c index 3f9b1b4c72..9b581ea872 100644 --- a/common/usbc/usb_retimer_fw_update.c +++ b/common/usbc/usb_retimer_fw_update.c @@ -116,7 +116,7 @@ int usb_retimer_fw_update_get_result(void) result = last_result; break; } - /* fall through */ + __fallthrough; case USB_RETIMER_FW_UPDATE_RESUME_PD: result = pd_is_port_enabled(cur_port); break; diff --git a/core/build.mk b/core/build.mk new file mode 100644 index 0000000000..407550bf7c --- /dev/null +++ b/core/build.mk @@ -0,0 +1,20 @@ +# Copyright 2021 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +CORE_RW_OUT:=$(out)/RW/core/$(CORE) +CORE_RO_OUT:=$(out)/RO/core/$(CORE) + +cmd_asm_define_to_h = grep ASM_DEFINE $< \ + | sed 's/.*__ASM_DEFINE__\s\(.*\)\s\#\(.*\)"/\#define \1 \2/g' > $@ + +$(CORE_RO_OUT)/asm_offsets.h:$(CORE_RO_OUT)/asm_offsets.s + $(call quiet,asm_define_to_h, ) +$(CORE_RW_OUT)/asm_offsets.h:$(CORE_RW_OUT)/asm_offsets.s + $(call quiet,asm_define_to_h, ) + +$(CORE_RW_OUT)/asm_offsets.s: core/$(CORE)/asm_offsets.c +$(CORE_RW_OUT)/asm_offsets.h: $(CORE_RW_OUT)/asm_offsets.s + +$(CORE_RO_OUT)/asm_offsets.s: core/$(CORE)/asm_offsets.c +$(CORE_RO_OUT)/asm_offsets.h: $(CORE_RO_OUT)/asm_offsets.s diff --git a/core/cortex-m0/asm_offsets.c b/core/cortex-m0/asm_offsets.c new file mode 100644 index 0000000000..8bf44007bc --- /dev/null +++ b/core/cortex-m0/asm_offsets.c @@ -0,0 +1,16 @@ +/* Copyright 2021 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "asm_define.h" +#include "config.h" +#include "panic.h" + +void unused(void) +{ + ASM_DEFINE_OFFSET("ASM_PANIC_DATA_CM_REGS_OFFSET", struct panic_data, + cm.regs); + ASM_DEFINE("ASM_PANIC_DATA_PTR", PANIC_DATA_PTR); + ASM_DEFINE("ASM_PANIC_STACK_ADDR", ((uint32_t)PANIC_DATA_PTR) & ~7); +} diff --git a/core/cortex-m0/build.mk b/core/cortex-m0/build.mk index 0bea9d09ab..7de8956a4d 100644 --- a/core/cortex-m0/build.mk +++ b/core/cortex-m0/build.mk @@ -46,3 +46,11 @@ core-$(CONFIG_CURVE25519)+=curve25519/scalarmult.o core-$(CONFIG_CURVE25519)+=curve25519/sqr.o core-$(CONFIG_WATCHDOG)+=watchdog.o + +core-$(CONFIG_COMMON_PANIC_OUTPUT)+=exception_panic.o + +$(CORE_RW_OUT)/exception_panic.o: $(CORE_RW_OUT)/asm_offsets.h +$(CORE_RW_OUT)/exception_panic.o: CFLAGS+=-I$(CORE_RW_OUT) + +$(CORE_RO_OUT)/exception_panic.o: $(CORE_RO_OUT)/asm_offsets.h +$(CORE_RO_OUT)/exception_panic.o: CFLAGS+=-I$(CORE_RO_OUT) diff --git a/core/cortex-m0/exception_panic.S b/core/cortex-m0/exception_panic.S new file mode 100644 index 0000000000..73585bb6d9 --- /dev/null +++ b/core/cortex-m0/exception_panic.S @@ -0,0 +1,38 @@ +/* Copyright 2021 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "asm_offsets.h" + +.syntax unified +.text +.thumb +.cpu cortex-m0 + +.global exception_panic +.thumb_func +.align 2 +exception_panic: + ldr r3, pstack + ldr r0, pregs + mov ip, r3 + mrs r1, psp + mrs r2, ipsr + mov r3, sp + stmia r0!, {r1-r7} + mov r1, r8 + mov r2, r9 + mov r3, r10 + mov r4, r11 + mov r5, lr + stmia r0!, {r1-r5} + mov sp, ip + bl report_panic + +pstack: + .word ASM_PANIC_STACK_ADDR + +.equ PREGS, (ASM_PANIC_DATA_CM_REGS_OFFSET + ASM_PANIC_DATA_PTR) +pregs: + .word PREGS diff --git a/core/cortex-m0/panic.c b/core/cortex-m0/panic.c index 3714d771a2..3e4c1eb3be 100644 --- a/core/cortex-m0/panic.c +++ b/core/cortex-m0/panic.c @@ -22,9 +22,6 @@ static int bus_fault_ignored; /* Panic data goes at the end of RAM. */ static struct panic_data *const pdata_ptr = PANIC_DATA_PTR; -/* Preceded by stack, rounded down to nearest 64-bit-aligned boundary */ -static const uint32_t pstack_addr = ((uint32_t)pdata_ptr) & ~7; - /** * Print the name and value of a register * @@ -140,45 +137,6 @@ void __keep report_panic(void) panic_reboot(); } -/** - * Default exception handler, which reports a panic. - * - * Declare this as a naked call so we can extract raw LR and IPSR values. - */ -void exception_panic(void) -{ - /* Save registers and branch directly to panic handler */ - asm volatile( - "mrs r1, psp\n" - "mrs r2, ipsr\n" - "mov r3, sp\n" - "stmia %[pregs]!, {r1-r7}\n" - "mov r1, r8\n" - "mov r2, r9\n" - "mov r3, r10\n" - "mov r4, r11\n" - "mov r5, lr\n" - "stmia %[pregs]!, {r1-r5}\n" - "mov sp, %[pstack]\n" - "bl report_panic\n" - : - : [pregs] "r"(pdata_ptr->cm.regs), [pstack] "r"(pstack_addr) - : - /* Constraints protecting these from being clobbered. - * Gcc should be using r0 & r12 for pregs and pstack. */ - "r1", "r2", "r3", "r4", "r5", "r6", - /* clang warns that we're clobbering a reserved register: - * inline asm clobber list contains reserved registers: R7 - * [-Werror,-Winline-asm]. The intent of the clobber list is - * to force pregs and pstack to be in R0 and R12, which - * still holds. - */ -#ifndef __clang__ - "r7", -#endif - "r8", "r9", "r10", "r11", "cc", "memory"); -} - void software_panic(uint32_t reason, uint32_t info) { __asm__("mov " STRINGIFY( diff --git a/driver/als_si114x.c b/driver/als_si114x.c index 30f92e23d1..eba613be8b 100644 --- a/driver/als_si114x.c +++ b/driver/als_si114x.c @@ -317,10 +317,13 @@ static int si114x_set_chlist(const struct motion_sensor_t *s) switch (SI114X_NUM_LEDS) { case 3: reg |= SI114X_PARAM_CHLIST_EN_PS3; + __fallthrough; case 2: reg |= SI114X_PARAM_CHLIST_EN_PS2; + __fallthrough; case 1: reg |= SI114X_PARAM_CHLIST_EN_PS1; + __fallthrough; case 0: break; } diff --git a/driver/charger/bd9995x.c b/driver/charger/bd9995x.c index a6303d41b4..aa37bf4e8a 100644 --- a/driver/charger/bd9995x.c +++ b/driver/charger/bd9995x.c @@ -758,6 +758,7 @@ static enum ec_error_list bd9995x_get_status(int chgnum, int *status) break; case BD9995X_CMD_CHGOP_STATUS_BATTEMP_BATOPEN: *status &= ~CHARGER_BATTERY_PRESENT; + break; default: break; } diff --git a/driver/charger/rt946x.c b/driver/charger/rt946x.c index acf5dc012d..58b5c1adb4 100644 --- a/driver/charger/rt946x.c +++ b/driver/charger/rt946x.c @@ -1233,7 +1233,7 @@ static int rt946x_get_bc12_ilim(int charge_supplier) IS_ENABLED(CONFIG_CHARGE_RAMP_HW)) /* A conservative value to prevent a bad charger. */ return RT946X_AICR_TYP2MAX(USB_CHARGER_MAX_CURR_MA); - /* fallback */ + __fallthrough; case CHARGE_SUPPLIER_BC12_CDP: return USB_CHARGER_MAX_CURR_MA; case CHARGE_SUPPLIER_BC12_SDP: diff --git a/driver/tcpm/fusb302.c b/driver/tcpm/fusb302.c index 780e5b2cfe..4b4a15c711 100644 --- a/driver/tcpm/fusb302.c +++ b/driver/tcpm/fusb302.c @@ -1154,7 +1154,7 @@ static int fusb302_compare_mdac(int port, int mdac) return status0 & TCPC_REG_STATUS0_COMP; } -int tcpc_get_vbus_voltage(int port) +int fusb302_get_vbus_voltage(int port, int *vbus) { int mdac = 0, i; @@ -1170,7 +1170,9 @@ int tcpc_get_vbus_voltage(int port) mdac |= BIT(i); } - return (mdac + 1) * 420; + *vbus = (mdac + 1) * 420; + + return EC_SUCCESS; } const struct tcpm_drv fusb302_tcpm_drv = { @@ -1180,6 +1182,7 @@ const struct tcpm_drv fusb302_tcpm_drv = { #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC .check_vbus_level = &fusb302_tcpm_check_vbus_level, #endif + .get_vbus_voltage = &fusb302_get_vbus_voltage, .select_rp_value = &fusb302_tcpm_select_rp_value, .set_cc = &fusb302_tcpm_set_cc, .set_polarity = &fusb302_tcpm_set_polarity, diff --git a/driver/tcpm/nct38xx.c b/driver/tcpm/nct38xx.c index f6184b21e4..e3a9fc04a2 100644 --- a/driver/tcpm/nct38xx.c +++ b/driver/tcpm/nct38xx.c @@ -358,6 +358,7 @@ const struct tcpm_drv nct38xx_tcpm_drv = { #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC .check_vbus_level = &tcpci_tcpm_check_vbus_level, #endif + .get_vbus_voltage = &tcpci_get_vbus_voltage, .select_rp_value = &tcpci_tcpm_select_rp_value, .set_cc = &nct38xx_tcpm_set_cc, .set_polarity = &tcpci_tcpm_set_polarity, diff --git a/driver/tcpm/rt1718s.c b/driver/tcpm/rt1718s.c index a009e33323..07c14f7dd5 100644 --- a/driver/tcpm/rt1718s.c +++ b/driver/tcpm/rt1718s.c @@ -196,7 +196,7 @@ static int rt1718s_workaround(int port) RETURN_ERROR(rt1718s_update_bits8( port, RT1718S_VCONN_CONTROL_3, RT1718S_VCONN_CONTROL_3_VCONN_OVP_DEG, 0xFF)); - /* fallthrough */ + __fallthrough; case RT1718S_DEVICE_ID_ES2: RETURN_ERROR(rt1718s_update_bits8( port, TCPC_REG_FAULT_CTRL, diff --git a/extra/ftdi_hostcmd/test_cmds.c b/extra/ftdi_hostcmd/test_cmds.c index 7bd3413032..748b862b56 100644 --- a/extra/ftdi_hostcmd/test_cmds.c +++ b/extra/ftdi_hostcmd/test_cmds.c @@ -378,7 +378,6 @@ static struct lookup cmd_table[] = { { 0x00, "EC_CMD_PROTO_VERSION" }, { 0x01, "EC_CMD_HELLO" }, { 0x02, "EC_CMD_GET_VERSION" }, - { 0x03, "EC_CMD_READ_TEST" }, { 0x04, "EC_CMD_GET_BUILD_INFO" }, { 0x05, "EC_CMD_GET_CHIP_INFO" }, { 0x06, "EC_CMD_GET_BOARD_VERSION" }, diff --git a/include/battery_fuel_gauge.h b/include/battery_fuel_gauge.h index b3fbb035e7..0a2a4064bb 100644 --- a/include/battery_fuel_gauge.h +++ b/include/battery_fuel_gauge.h @@ -103,22 +103,6 @@ __override_proto int board_get_default_battery_type(void); int battery_is_charge_fet_disabled(void); /** - * Battery cut off command via SMBus write block. - * - * @param ship_mode Battery ship mode information - * @return non-zero if error - */ -int cut_off_battery_block_write(const struct ship_mode_info *ship_mode); - -/** - * Battery cut off command via SMBus write word. - * - * @param ship_mode Battery ship mode information - * @return non-zero if error - */ -int cut_off_battery_sb_write(const struct ship_mode_info *ship_mode); - -/** * Send the fuel gauge sleep command through SMBus. * * @return 0 if successful, non-zero if error occurred diff --git a/include/common.h b/include/common.h index 72553161f5..97dddfc03f 100644 --- a/include/common.h +++ b/include/common.h @@ -192,6 +192,15 @@ */ #define __warn_unused_result __attribute__((warn_unused_result)) +/** + * @brief Attribute used to annotate intentional fallthrough between switch + * labels. + * + * See https://clang.llvm.org/docs/AttributeReference.html#fallthrough and + * https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html. + */ +#define __fallthrough __attribute__((fallthrough)) + /* * Macros for combining bytes into larger integers. _LE and _BE signify little * and big endian versions respectively. diff --git a/include/dps.h b/include/dps.h index 0cb2a9455b..8794220ab2 100644 --- a/include/dps.h +++ b/include/dps.h @@ -10,6 +10,13 @@ #include "common.h" +#define DPS_FLAG_DISABLED BIT(0) +#define DPS_FLAG_NO_SRCCAP BIT(1) +#define DPS_FLAG_WAITING BIT(2) +#define DPS_FLAG_SAMPLED BIT(3) +#define DPS_FLAG_NEED_MORE_PWR BIT(4) +#define DPS_FLAG_NO_BATTERY BIT(5) + /* Dynamic PDO Selection config. */ struct dps_config_t { /* (0, 100) coeff for transition to a lower power PDO*/ @@ -76,6 +83,8 @@ __test_only bool dps_is_fake_enabled(void); __test_only int dps_get_fake_mv(void); __test_only int dps_get_fake_ma(void); __test_only int *dps_get_debug_level(void); +__test_only int dps_get_flag(void); + #endif #endif /* __CROS_EC_DPS__H */ diff --git a/include/driver/tcpm/tcpm.h b/include/driver/tcpm/tcpm.h index 8352423d9d..1ad324bf72 100644 --- a/include/driver/tcpm/tcpm.h +++ b/include/driver/tcpm/tcpm.h @@ -300,6 +300,17 @@ static inline int tcpm_set_src_ctrl(int port, int enable) return EC_ERROR_UNIMPLEMENTED; } +static inline int tcpc_get_vbus_voltage(int port) +{ + int vbus; + + if (tcpc_config[port].drv->get_vbus_voltage != NULL) + tcpc_config[port].drv->get_vbus_voltage(port, &vbus); + else + return 0; + return vbus; +} + static inline void tcpc_alert(int port) { tcpc_config[port].drv->tcpc_alert(port); diff --git a/include/ec_commands.h b/include/ec_commands.h index acb502ca99..ebabf1f304 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -1253,27 +1253,9 @@ struct ec_response_get_version_v1 { char cros_fwid_rw[32]; /* Added in version 1 */ } __ec_align4; -/* Read test */ +/* Read test - DEPRECATED */ #define EC_CMD_READ_TEST 0x0003 -/** - * struct ec_params_read_test - Parameters for the read test command. - * @offset: Starting value for read buffer. - * @size: Size to read in bytes. - */ -struct ec_params_read_test { - uint32_t offset; - uint32_t size; -} __ec_align4; - -/** - * struct ec_response_read_test - Response to the read test command. - * @data: Data returned by the read test command. - */ -struct ec_response_read_test { - uint32_t data[32]; -} __ec_align4; - /* * Get build information * diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index 9a78754a0d..f3f449721e 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -644,15 +644,6 @@ int board_tcpc_post_init(int port) __attribute__((weak)); */ void board_pd_vconn_ctrl(int port, enum usbpd_cc_pin cc_pin, int enabled); -/** - * Get the VBUS voltage from TCPC - * - * @param port Type-C port number - * - * @return VBUS voltage in mV. - */ -int tcpc_get_vbus_voltage(int port); - #ifdef CONFIG_CMD_TCPC_DUMP struct tcpc_reg_dump_map { uint8_t addr; diff --git a/power/common.c b/power/common.c index c1675d31f2..65c1cf0779 100644 --- a/power/common.c +++ b/power/common.c @@ -521,12 +521,12 @@ static enum power_state power_common_state(void) break; case POWER_S4: - /* fallthrough */ + __fallthrough; case POWER_S3: - /* fallthrough */ + __fallthrough; case POWER_S0: #ifdef CONFIG_POWER_S0IX - /* fallthrough */ + __fallthrough; case POWER_S0ix: #endif /* Wait for a message */ diff --git a/power/host_sleep.c b/power/host_sleep.c index b97fb904c1..7dc83ca8e9 100644 --- a/power/host_sleep.c +++ b/power/host_sleep.c @@ -18,12 +18,15 @@ /* Track last reported sleep event */ static enum host_sleep_event host_sleep_state; +/* LCOV_EXCL_START */ +/* Function stub that has no behavior, so ignoring for coverage */ __overridable void power_chipset_handle_host_sleep_event(enum host_sleep_event state, struct host_sleep_event_context *ctx) { /* Default weak implementation -- no action required. */ } +/* LCOV_EXCL_STOP */ static enum ec_status host_command_host_sleep_event(struct host_cmd_handler_args *args) @@ -116,16 +119,22 @@ static enum sleep_hang_type timeout_hang_type; static void sleep_transition_timeout(void); DECLARE_DEFERRED(sleep_transition_timeout); +/* LCOV_EXCL_START */ +/* Function stub that has no behavior, so ignoring for coverage */ __overridable void power_board_handle_sleep_hang(enum sleep_hang_type hang_type) { /* Default empty implementation */ } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ +/* Function stub that has no behavior, so ignoring for coverage */ __overridable void power_chipset_handle_sleep_hang(enum sleep_hang_type hang_type) { /* Default empty implementation */ } +/* LCOV_EXCL_STOP */ static void sleep_increment_transition(void) { diff --git a/power/intel_x86.c b/power/intel_x86.c index 1c9f2ef8c8..4fa3aa3c8e 100644 --- a/power/intel_x86.c +++ b/power/intel_x86.c @@ -381,7 +381,7 @@ enum power_state common_intel_x86_power_handle_state(enum power_state state) return POWER_S4; /* Power down to the next state */ case POWER_S5S3: - /* fallthrough */ + __fallthrough; case POWER_S4S3: if (!power_has_signals(IN_PGOOD_ALL_CORE)) { /* Required rail went away */ diff --git a/power/qcom.c b/power/qcom.c index 418f2b3136..30374cd330 100644 --- a/power/qcom.c +++ b/power/qcom.c @@ -896,46 +896,10 @@ test_mockable void chipset_reset(enum chipset_shutdown_reason reason) task_wake(TASK_ID_CHIPSET); } -/* - * Flag to fake the suspend signal to 1 or 0, or -1 means not fake it. - * - * TODO(waihong): Remove this flag and debug command when the AP_SUSPEND - * signal is working. - */ -static int fake_suspend = -1; - -static int command_fake_suspend(int argc, const char **argv) -{ - int v; - - if (argc < 2) { - ccprintf("fake_suspend: %s\n", - fake_suspend == -1 ? "reset" : - (fake_suspend ? "on" : "off")); - return EC_SUCCESS; - } - - if (!strcasecmp(argv[1], "reset")) - fake_suspend = -1; - else if (parse_bool(argv[1], &v)) - fake_suspend = v; - else - return EC_ERROR_PARAM1; - - task_wake(TASK_ID_CHIPSET); - - return EC_SUCCESS; -} -DECLARE_CONSOLE_COMMAND(fakesuspend, command_fake_suspend, "on/off/reset", - "Fake the AP_SUSPEND signal"); - /* Get system sleep state through GPIOs */ static inline int chipset_get_sleep_signal(void) { - if (fake_suspend == -1) - return (power_get_signals() & IN_SUSPEND) == IN_SUSPEND; - else - return fake_suspend; + return (power_get_signals() & IN_SUSPEND) == IN_SUSPEND; } __override void power_chipset_handle_sleep_hang(enum sleep_hang_type hang_type) diff --git a/test/build.mk b/test/build.mk index 4f9674b306..08e2d15c9f 100644 --- a/test/build.mk +++ b/test/build.mk @@ -98,6 +98,7 @@ test-list-host += static_if_error # toolchain's C standard library, so these tests are actually testing the # toolchain's C standard library. test-list-host += stdlib +test-list-host += std_vector test-list-host += system test-list-host += thermal test-list-host += timer_dos @@ -244,6 +245,7 @@ sha256_unrolled-y=sha256.o shmalloc-y=shmalloc.o static_if-y=static_if.o stdlib-y=stdlib.o +std_vector-y=std_vector.o stm32f_rtc-y=stm32f_rtc.o stress-y=stress.o system-y=system.o diff --git a/test/run_device_tests.py b/test/run_device_tests.py index 66109cbf93..4e0b0127e3 100755 --- a/test/run_device_tests.py +++ b/test/run_device_tests.py @@ -268,6 +268,7 @@ class AllTests: TestConfig(test_name="sha256_unrolled"), TestConfig(test_name="static_if"), TestConfig(test_name="stdlib"), + TestConfig(test_name="std_vector"), TestConfig( config_name="system_is_locked_wp_on", test_name="system_is_locked", diff --git a/test/std_vector.cc b/test/std_vector.cc new file mode 100644 index 0000000000..5873b416b6 --- /dev/null +++ b/test/std_vector.cc @@ -0,0 +1,84 @@ +/* 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. + * + * Basic test of std::vector and dynamic memory allocation. + */ + +#include <array> +#include <vector> + +extern "C" { +#include "common.h" +#include "console.h" +#include "test_util.h" +} + +test_static int push_back_elements() +{ + std::vector<int32_t> vec; + + vec.push_back(0); + vec.push_back(1); + vec.push_back(2); + vec.push_back(3); + + TEST_EQ(static_cast<int32_t>(vec.size()), 4, "%d"); + TEST_EQ(vec[0], 0, "%d"); + TEST_EQ(vec[1], 1, "%d"); + TEST_EQ(vec[2], 2, "%d"); + TEST_EQ(vec[3], 3, "%d"); + + return EC_SUCCESS; +} + +test_static int fill_one_vector() +{ + // This test allocates 64kB of memory in total in a single std::vector + constexpr int num_elements = 16 * 1024; + std::vector<int32_t> vec; + + for (int i = 0; i < num_elements; ++i) + vec.push_back(i); + + TEST_EQ(static_cast<int>(vec.size()), num_elements, "%d"); + for (int i = 0; i < num_elements; ++i) { + TEST_ASSERT(vec[i] == i); + // Using TEST_EQ floods the console and trigger the watchdog + // TEST_EQ(vec[i], i, "%d"); + // cflush(); + } + + return EC_SUCCESS; +} + +test_static int fill_multiple_vectors() +{ + // This test allocates 64kB of memory in total split in 8 std::vectors + constexpr int num_elements = 2 * 1024; + std::array<std::vector<int32_t>, 8> vecs; + + for (int i = 0; i < num_elements; ++i) + for (auto &vec : vecs) + vec.push_back(i); + + for (auto &vec : vecs) { + TEST_EQ(static_cast<int>(vec.size()), num_elements, "%d"); + for (int i = 0; i < num_elements; ++i) { + TEST_ASSERT(vec[i] == i); + } + } + + return EC_SUCCESS; +} + +extern "C" void run_test(int argc, const char **argv) +{ + test_reset(); + + RUN_TEST(push_back_elements); + RUN_TEST(fill_one_vector); + RUN_TEST(fill_multiple_vectors); + + test_print_result(); +} diff --git a/test/std_vector.tasklist b/test/std_vector.tasklist new file mode 100644 index 0000000000..6d43377af5 --- /dev/null +++ b/test/std_vector.tasklist @@ -0,0 +1,9 @@ +/* Copyright 2022 The ChromiumOS 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/util/build_with_clang.py b/util/build_with_clang.py index 4951c53f30..71957107a0 100755 --- a/util/build_with_clang.py +++ b/util/build_with_clang.py @@ -51,7 +51,7 @@ BOARDS_THAT_COMPILE_SUCCESSFULLY_WITH_CLANG = [ "max32660-eval", # Boards that use CHIP:=npcx # git grep --name-only 'CHIP:=npcx' | sed 's#^board/\(.*\)/build.mk#"\1",#' - # "adlrvpp_npcx", + "adlrvpp_npcx", "agah", "akemi", "aleena", @@ -75,7 +75,7 @@ BOARDS_THAT_COMPILE_SUCCESSFULLY_WITH_CLANG = [ "copano", "coral", "corori", - # "corori2", + "corori2", "cret", "crota", "dalboz", @@ -89,7 +89,7 @@ BOARDS_THAT_COMPILE_SUCCESSFULLY_WITH_CLANG = [ "eldrid", "elemi", "endeavour", - # "eve", + "eve", "ezkinil", "felwinter", "fizz", @@ -144,7 +144,7 @@ BOARDS_THAT_COMPILE_SUCCESSFULLY_WITH_CLANG = [ "pazquel", "phaser", "pompom", - # "poppy", + "poppy", "primus", "puff", "quackingstick", @@ -161,7 +161,7 @@ BOARDS_THAT_COMPILE_SUCCESSFULLY_WITH_CLANG = [ "treeya", "trembyle", "trogdor", - # "vell", + "vell", "vilboz", "voema", "volet", diff --git a/util/clangd_config.py b/util/clangd_config.py index 96bcb7ebf1..2553707c43 100755 --- a/util/clangd_config.py +++ b/util/clangd_config.py @@ -65,7 +65,38 @@ def ec_build(ec_root: Path, board: str, image: str) -> Optional[Path]: def zephyr_build(ec_root: Path, board: str, image: str) -> Optional[Path]: """Build the correct compile_commands.json for Zephyr board/image""" - raise NotImplementedError("Zephyr is currently unsupported.") + target = Path( + f"build/zephyr/{board}/build-{image.lower()}/compile_commands.json" + ) + cmd = ["zmake", "configure", board] + + print(" ".join(cmd)) + status = subprocess.run(cmd, check=False, cwd=ec_root) + + if status.returncode != 0: + return None + + # Replace /mnt/host/source with path of chromiumos outside chroot + default_chromiumos_path_outside_chroot = os.path.join( + Path.home(), "chromiumos" + ) + chromiumos_path_outside_chroot = os.environ.get( + "EXTERNAL_TRUNK_PATH", default_chromiumos_path_outside_chroot + ) + chromiumos_path_inside_chroot = "/mnt/host/source" + + print( + f"Replacing '{chromiumos_path_inside_chroot}' with " + + f"'{chromiumos_path_outside_chroot}' in file {target}" + ) + + target.write_text( + target.read_text().replace( + chromiumos_path_inside_chroot, chromiumos_path_outside_chroot + ) + ) + + return target def copy(ec_root: Path, target: Path) -> None: diff --git a/util/crash_analyzer.py b/util/crash_analyzer.py index 2e51511461..c2e07face2 100755 --- a/util/crash_analyzer.py +++ b/util/crash_analyzer.py @@ -10,9 +10,8 @@ import pathlib import re import sys -# Regex tested here: https://regex101.com/r/K5S8cB/1 -# This Regex has only been tested in Cortex-M0+ crash reporter. # TODO(b/253492108): Add regexp for missing architectures. +# Regex tested here: https://regex101.com/r/K5S8cB/1 _REGEX_CORTEX_M0 = ( r"^Saved.*$\n=== .* EXCEPTION: (.*) ====== xPSR: (.*) ===$\n" r"r0 :(.*) r1 :(.*) r2 :(.*) r3 :(.*)$\n" @@ -22,10 +21,152 @@ _REGEX_CORTEX_M0 = ( r"\n" r"^.*cfsr=(.*), shcsr=(.*), hfsr=(.*), dfsr=(.*), ipsr=(.*)$" ) + +# Regex tested here: https://regex101.com/r/FL7T0n/1 +_REGEX_NDS32 = ( + r"^Saved.*$\n===.*ITYPE=(.*) ===$\n" + r"R0 (.*) R1 (.*) R2 (.*) R3 (.*)$\n" + r"R4 (.*) R5 (.*) R6 (.*) R7 (.*)$\n" + r"R8 (.*) R9 (.*) R10 (.*) R15 (.*)$\n" + r"FP (.*) GP (.*) LP (.*) SP (.*)$\n" + r"IPC (.*) IPSW (.*)$\n" +) + + +# List of symbols. Each entry is tuple: address, name _symbols = [] +# List of crashes. Each entry is dictionary. +# Contains all crashes found. _entries = [] +# This is function, and not a global dictionary, so that +# we can reference the different functions without placing +# the functions above the dictionary. +def get_architectures() -> list: + """Returns a dictionary with the supported architectures""" + + archs = { + "cm0": { + "regex": _REGEX_CORTEX_M0, + "parser": cm0_parse, + "extra_regs": [ + "sp", + "lr", + "pc", + "cfsr", + "chcsr", + "hfsr", + "dfsr", + "ipsr", + ], + }, + "nds32": { + "regex": _REGEX_NDS32, + "parser": nds32_parse, + "extra_regs": ["fp", "gp", "lp", "sp", "ipc", "ipsw"], + }, + } + return archs + + +def get_crash_cause(cause: int) -> str: + """Returns the cause of crash in human-readable format""" + causes = { + 0xDEAD6660: "div-by-0", + 0xDEAD6661: "stack-overflow", + 0xDEAD6662: "pd-crash", + 0xDEAD6663: "assert", + 0xDEAD6664: "watchdog", + 0xDEAD6665: "bad-rng", + 0xDEAD6666: "pmic-fault", + 0xDEAD6667: "exit", + } + + if cause in causes: + return causes[cause] + return f"unknown-cause-{format(cause, '#x')}" + + +def cm0_parse(match) -> dict: + """Regex parser for Cortex-M0+ architecture""" + + # Expecting something like: + # Saved panic data: (NEW) + # === PROCESS EXCEPTION: ff ====== xPSR: ffffffff === + # r0 : r1 : r2 : r3 : + # r4 :dead6664 r5 :10092632 r6 :00000000 r7 :00000000 + # r8 :00000000 r9 :00000000 r10:00000000 r11:00000000 + # r12: sp :00000000 lr : pc : + # + # cfsr=00000000, shcsr=00000000, hfsr=00000000, dfsr=00000000, ipsr=000000ff + regs = {} + values = [] + + for i in match.groups(): + try: + val = int(i, 16) + except ValueError: + # Value might be empty, so we must handle the exception + val = -1 + values.append(val) + + regs["task"] = values[0] + regs["xPSR"] = values[1] + regs["regs"] = values[3:15] + regs["sp"] = values[15] + regs["lr"] = values[16] + regs["pc"] = values[17] + regs["cfsr"] = values[18] + regs["chcsr"] = values[19] + regs["hfsr"] = values[20] + regs["dfsr"] = values[21] + regs["ipsr"] = values[22] + + regs["cause"] = get_crash_cause(values[6]) # r4 + regs["symbol"] = get_symbol(values[7]) # r5 + + return regs + + +def nds32_parse(match) -> dict: + """Regex parser for Andes (NDS32) architecture""" + + # Expecting something like: + # Saved panic data: (NEW) + # === EXCEP: ITYPE=0 === + # R0 00000000 R1 00000000 R2 00000000 R3 00000000 + # R4 00000000 R5 00000000 R6 dead6664 R7 00000000 + # R8 00000000 R9 00000000 R10 00000000 R15 00000000 + # FP 00000000 GP 00000000 LP 00000000 SP 00000000 + # IPC 00050d5e IPSW 00000 + # SWID of ITYPE: 0 + regs = {} + values = [] + + for i in match.groups(): + try: + val = int(i, 16) + except ValueError: + # Value might be empty, so we must handle the exception + val = -1 + values.append(val) + + # NDS32 is not reporting task info. + regs["task"] = -1 + regs["regs"] = values[1:13] + regs["fp"] = values[13] + regs["gp"] = values[14] + regs["lp"] = values[15] + regs["sp"] = values[16] + regs["ipc"] = values[17] + regs["ipsw"] = values[18] + + regs["cause"] = get_crash_cause(values[7]) # r6 + regs["symbol"] = get_symbol(regs["ipc"]) + return regs + + def read_map_file(map_file): """Reads the map file, and populates the _symbols list with the tuple address/name""" lines = map_file.readlines() @@ -51,8 +192,8 @@ def get_symbol_bisec(addr: int, low: int, high: int) -> str: if _symbols[mid][0] <= addr < _symbols[mid + 1][0]: symbol = _symbols[mid][1] - # Start of a sequence of Thumb instructions. When this happens, query - # for the next address. + # Start of a sequence of Thumb instructions. When this happens, return + # the next address. if symbol == "$t": symbol = _symbols[mid + 1][1] return symbol @@ -73,8 +214,10 @@ def get_symbol(addr: int) -> str: return symbol -def process_log_file(file_name: str) -> str: - """Reads a .log file and extracts the FW version""" +def process_log_file(file_name: str) -> tuple: + """Reads a .log file and extracts the EC and BIOS versions""" + ec_ver = None + bios_ver = None try: with open(file_name, "r") as log_file: lines = log_file.readlines() @@ -84,64 +227,62 @@ def process_log_file(file_name: str) -> str: # vendor | Nuvoton # name | NPCX586G # fw_version | rammus_v2.0.460-d1d2aeb01f - if line.startswith("fw_version"): - _, value = line.split("|") - return value.strip() + # ... + # ===bios_info=== + # fwid = Google_Rammus.11275.193.0 # [RO/str] ... + # ro_fwid = Google_Rammus.11275.28.0 # [RO/str] ... + + # Get EC version. + # There could be more than one "fw_version". Only the first one + # corresponds to the EC version. + if line.startswith("fw_version") and ec_ver is None: + _, ec_ver = line.split("|") + ec_ver = ec_ver.strip(" \n") + + # Get BIOS version. + if line.startswith("fwid"): + _, value = line.split("=") + # Only get the first element. + bios_ver, _ = value.split("#") + bios_ver = bios_ver.strip() + + if ec_ver is not None and bios_ver is not None: + return ec_ver, bios_ver + except FileNotFoundError: - return ".log file not found" - return "unknown fw version" + return ".log file not found", "not found" + return ( + "unknown fw version" if ec_ver is None else ec_ver, + "unknown BIOS version" if bios_ver is None else bios_ver, + ) -def process_crash_file(file_name: str) -> dict: +def process_crash_file(filename: str) -> dict: """Process a single crash report, and convert it to a dictionary""" - regs = {} - with open(file_name, "r") as crash_file: + + with open(filename, "r") as crash_file: content = crash_file.read() - # TODO(b/253492108): This is hardcoded to Cortex-M0+ crash reports. - # New ones (Risc-V, NDS32, etc.) will be added on demand. - # - # Expecting something like: - # Saved panic data: (NEW) - # === PROCESS EXCEPTION: ff ====== xPSR: ffffffff === - # r0 : r1 : r2 : r3 : - # r4 :dead6664 r5 :10092632 r6 :00000000 r7 :00000000 - # r8 :00000000 r9 :00000000 r10:00000000 r11:00000000 - # r12: sp :00000000 lr : pc : - # - # cfsr=00000000, shcsr=00000000, hfsr=00000000, dfsr=00000000, ipsr=000000ff - - match = re.match(_REGEX_CORTEX_M0, content, re.MULTILINE) - values = [] - # Convert the values to numbers, invalid the invalid ones. - # Cannot use list comprehension due to possible invalid values - if match is not None: - for i in match.groups(): - try: - val = int(i, 16) - except ValueError: - # Value might be empty, so we must handle the exception - val = -1 - values.append(val) - - regs["exp"] = values[0] - regs["xPSR"] = values[1] - regs["regs"] = values[2:15] - regs["sp"] = values[15] - regs["lr"] = values[16] - regs["pc"] = values[17] - regs["cfsr"] = values[18] - regs["chcsr"] = values[19] - regs["hfsr"] = values[20] - regs["dfsr"] = values[21] - regs["ipsr"] = values[22] - regs["symbol"] = get_symbol(regs["regs"][5]) - return regs + for key, arch in get_architectures().items(): + regex = arch["regex"] + match = re.match(regex, content, re.MULTILINE) + if match is None: + continue + entry = arch["parser"](match) + + # Add "arch" entry since it is needed to process + # the "extra_regs", among other things. + entry["arch"] = key + return entry + return {} -def process_crash_files(crash_folder): + +def process_crash_files(crash_folder: pathlib.Path) -> None: """Process the crash reports that are in the crash_folder""" - processed = 0 + total = 0 + failed = 0 + good = 0 for file in crash_folder.iterdir(): # .log and .upload_file_eccrash might not be in order. # To avoid processing it more than once, only process the @@ -150,65 +291,87 @@ def process_crash_files(crash_folder): continue entry = process_crash_file(file) if len(entry) != 0: - fw_ver = process_log_file(file.parent.joinpath(file.stem + ".log")) - entry["fw_version"] = fw_ver + ec_ver, bios_ver = process_log_file( + file.parent.joinpath(file.stem + ".log") + ) + entry["ec_version"] = ec_ver + entry["bios_version"] = bios_ver + entry["filename"] = file.stem if len(entry) != 0: _entries.append(entry) - processed += 1 - print(f"Processed: {processed}", file=sys.stderr) + good += 1 + else: + failed += 1 + total += 1 + print(f"Total: {total}, OK: {good}, Failed: {failed}", file=sys.stderr) -def cmd_report_lite(crash_folder): +def cmd_report_lite(crash_folder: pathlib.Path, with_filename: bool) -> None: """Generates a 'lite' report that only contains a few fields""" process_crash_files(crash_folder) for entry in _entries: print( - f"Task: {format(entry['exp'],'#04x')} - " - f"cause: {format(entry['regs'][4], '#x')} - " + f"Task: {format(entry['task'],'#04x')} - " + f"cause: {entry['cause']} - " f"PC: {entry['symbol']} - " - f"EC ver:{entry['fw_version']}" + f"{entry['ec_version']} - " + f"{entry['bios_version']}", + end="", ) + if with_filename: + print(f" - {entry['filename']}", end="") + + print() + -def cmd_report_full(crash_folder): +def cmd_report_full(crash_folder: pathlib.Path, with_filename: bool) -> None: """Generates a full report in .cvs format""" process_crash_files(crash_folder) # Print header - print( - "Task,xPSR,r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12," - "sp,lr,pc,cfsr,chcsr,hfsr,dfsr,ipsr,symbol,fw_version" - ) for entry in _entries: print( - f"{format(entry['exp'],'#04x')},{format(entry['xPSR'],'#x')}", + f"Task: {format(entry['task'],'#04x')} - " + f"cause: {entry['cause']} - " + f"PC: {entry['symbol']} - ", end="", ) - for i in range(12): - print(f",{format(entry['regs'][i],'#x')}", end="") + # Print registers + hex_regs = [hex(x) for x in entry["regs"]] + print(f"{hex_regs} - ", end="") + + # Print extra registers. Varies from architecture to architecture. + arch = get_architectures()[entry["arch"]] + for reg in arch["extra_regs"]: + print(f"{reg}: {format(entry[reg], '#x')} ", end="") + + # Print EC & BIOS info print( - f",{format(entry['sp'],'#x')}" - f",{format(entry['lr'],'#x')}" - f",{format(entry['pc'],'#x')}" - f",{format(entry['cfsr'],'#x')}" - f",{format(entry['hfsr'],'#x')}" - f",{format(entry['dfsr'],'#x')}" - f",{format(entry['ipsr'],'#x')}" - f",\"{(entry['symbol'])}\"" - f",\"{(entry['fw_version'])}\"" + f"{entry['ec_version']} - {entry['bios_version']}", + end="", ) + # Finally the filename. Useful for debugging. + if with_filename: + print(f" - {entry['filename']}", end="") + + print() + def main(argv): """Main entry point""" example_text = """Example: +# For further details see: go/cros-ec-crash-analyzer +# +# Summary: # 1st: # Collect the crash reports using this script: -# https://source.corp.google.com/piper///depot/google3/experimental/users/ricardoq/crashpad/main.py +# https://source.corp.google.com/piper///depot/google3/experimental/users/ricardoq/ec_crash_report_fetcher # MUST be run within a Google3 Workspace. E.g: -(google3) blaze run //experimental/users/ricardoq/crashpad:main -- --outdir=/tmp/dumps/ --limit=3000 --offset=15000 --hwclass=shyvana --milestone=105 +(google3) blaze run //experimental/users/ricardoq/ec_crash_report_fetcher:main -- --outdir=/tmp/dumps/ --limit=3000 --offset=15000 --hwclass=shyvana --milestone=105 # 2nd: # Assuming that you don't have the .map file of the EC image, you can download the EC image from LUCI @@ -244,12 +407,18 @@ crash_analyzer.py lite -m /tmp/rammus_193.map -f /tmp/dumps | sort | uniq -c | l ) parser.add_argument( "-f", - "--crash_folder", + "--crash-folder", type=pathlib.Path, required=True, help="Folder with the EC crash report files", ) parser.add_argument( + "-n", + "--with-filename", + action="store_true", + help="Includes the filename in the report. Useful for debugging.", + ) + parser.add_argument( "command", choices=["lite", "full"], help="Command to run." ) args = parser.parse_args(argv) @@ -258,9 +427,9 @@ crash_analyzer.py lite -m /tmp/rammus_193.map -f /tmp/dumps | sort | uniq -c | l read_map_file(args.map_file) if args.command == "lite": - cmd_report_lite(args.crash_folder) + cmd_report_lite(args.crash_folder, args.with_filename) elif args.command == "full": - cmd_report_full(args.crash_folder) + cmd_report_full(args.crash_folder, args.with_filename) else: print(f"Unsupported command: {args.command}") diff --git a/util/ec_panicinfo_fuzzer.cc b/util/ec_panicinfo_fuzzer.cc new file mode 100644 index 0000000000..95f1871837 --- /dev/null +++ b/util/ec_panicinfo_fuzzer.cc @@ -0,0 +1,22 @@ +/* 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 "ec_panicinfo.h" + +/* Fuzzing Build command: + * $ clang++ ec_panicinfo_fuzzer.cc ec_panicinfo.cc -g -fsanitize=address,fuzzer + * -o ec_panicinfo_fuzzer + * -I../include/ -I../chip/host/ -I../board/host/ -I../fuzz -I../test + * + * Run Fuzzing: + * $ ./ec_panicinfo_fuzzer -runs=5000 + */ + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, unsigned int size) +{ + parse_panic_info((const char *)data, size); + + return 0; +} diff --git a/util/ectool.cc b/util/ectool.cc index c116b35fcc..844fa15ac6 100644 --- a/util/ectool.cc +++ b/util/ectool.cc @@ -273,8 +273,6 @@ const char help_str[] = " Set 16 bit duty cycle of given PWM\n" " rand <num_bytes>\n" " generate <num_bytes> of random numbers\n" - " readtest <patternoffset> <size>\n" - " Reads a pattern from the EC via LPC\n" " reboot_ec <RO|RW|cold|hibernate|hibernate-clear-ap-off|disable-jump|cold-ap-off>" " [at-shutdown|switch-slot]\n" " Reboot EC to RO or RW\n" @@ -1228,70 +1226,6 @@ exit: return rv; } -int cmd_read_test(int argc, char *argv[]) -{ - struct ec_params_read_test p; - struct ec_response_read_test r; - int offset, size; - int errors = 0; - int rv; - int i; - char *e; - char *buf; - uint32_t *b; - - if (argc < 3) { - fprintf(stderr, "Usage: %s <pattern_offset> <size>\n", argv[0]); - return -1; - } - offset = strtol(argv[1], &e, 0); - size = strtol(argv[2], &e, 0); - if ((e && *e) || size <= 0 || size > MAX_FLASH_SIZE) { - fprintf(stderr, "Bad size.\n"); - return -1; - } - printf("Reading %d bytes with pattern offset 0x%x...\n", size, offset); - - buf = (char *)malloc(size); - if (!buf) { - fprintf(stderr, "Unable to allocate buffer.\n"); - return -1; - } - - /* Read data in chunks */ - for (i = 0; i < size; i += sizeof(r.data)) { - p.offset = offset + i / sizeof(uint32_t); - p.size = MIN(size - i, sizeof(r.data)); - rv = ec_command(EC_CMD_READ_TEST, 0, &p, sizeof(p), &r, - sizeof(r)); - if (rv < 0) { - fprintf(stderr, "Read error at offset %d\n", i); - free(buf); - return rv; - } - memcpy(buf + i, r.data, p.size); - } - - /* Check data */ - for (i = 0, b = (uint32_t *)buf; i < size / 4; i++, b++) { - if (*b != i + offset) { - printf("Mismatch at byte offset 0x%x: " - "expected 0x%08x, got 0x%08x\n", - (int)(i * sizeof(uint32_t)), i + offset, *b); - errors++; - } - } - - free(buf); - if (errors) { - printf("Found %d errors\n", errors); - return -1; - } - - printf("done.\n"); - return 0; -} - int cmd_reboot_ec(int argc, char *argv[]) { struct ec_params_reboot_ec p; @@ -11002,7 +10936,6 @@ const struct command commands[] = { { "pwmsetkblight", cmd_pwm_set_keyboard_backlight }, { "pwmsetduty", cmd_pwm_set_duty }, { "rand", cmd_rand }, - { "readtest", cmd_read_test }, { "reboot_ec", cmd_reboot_ec }, { "rgbkbd", cmd_rgbkbd }, { "rollbackinfo", cmd_rollback_info }, diff --git a/util/stm32mon.cc b/util/stm32mon.cc index 352158ae73..39837bd3dd 100644 --- a/util/stm32mon.cc +++ b/util/stm32mon.cc @@ -633,6 +633,7 @@ int wait_for_ack(int fd) } /* Do not break so that it can be handled as junk */ + __attribute__((fallthrough)); default: stat_resp[JUNK_IDX].event_count++; if (mode == MODE_SERIAL) diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 84f5aeb97f..ae882e5640 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -56,6 +56,7 @@ endif() # Set extra compiler flags. zephyr_cc_option(-mno-unaligned-access) zephyr_cc_option(-fno-PIC) +zephyr_cc_option(-Wimplicit-fallthrough) if (DEFINED CONFIG_RISCV) zephyr_cc_option(-fsanitize=integer-divide-by-zero) diff --git a/zephyr/Kconfig.defaults b/zephyr/Kconfig.defaults index ded7516748..e0992f91fa 100644 --- a/zephyr/Kconfig.defaults +++ b/zephyr/Kconfig.defaults @@ -29,7 +29,7 @@ config SHELL_THREAD_PRIORITY_OVERRIDE default y config SHELL_THREAD_PRIORITY - default 12 # track EC_SHELL_PRIO + default 20 config EXTRA_EXCEPTION_INFO default y if ARCH_HAS_EXTRA_EXCEPTION_INFO diff --git a/zephyr/boards/arm/mec1727/mec1727.dts b/zephyr/boards/arm/mec1727/mec1727.dts index 3852f35fa8..ab3097660e 100644 --- a/zephyr/boards/arm/mec1727/mec1727.dts +++ b/zephyr/boards/arm/mec1727/mec1727.dts @@ -21,35 +21,6 @@ zephyr,flash-controller = &int_flash; }; - pinmux: pinmux { - compatible = "microchip,xec-pinmux"; - - pinmux_000_036: pinmux-0 { - ph-reg = <&gpio_000_036>; - port-num = <0>; - }; - pinmux_040_076: pinmux-1 { - ph-reg = <&gpio_040_076>; - port-num = <1>; - }; - pinmux_100_136: pinmux-2 { - ph-reg = <&gpio_100_136>; - port-num = <2>; - }; - pinmux_140_176: pinmux-3 { - ph-reg = <&gpio_140_176>; - port-num = <3>; - }; - pinmux_200_236: pinmux-4 { - ph-reg = <&gpio_200_236>; - port-num = <4>; - }; - pinmux_240_276: pinmux-5 { - ph-reg = <&gpio_240_276>; - port-num = <5>; - }; - }; - named-pwms { compatible = "named-pwms"; }; @@ -162,6 +133,7 @@ &spi0 { status = "okay"; + compatible = "microchip,xec-qmspi-full-duplex"; clock-frequency = <12000000>; lines = <2>; port-sel = <2>; diff --git a/zephyr/boards/arm/mec1727/mec1727_defconfig b/zephyr/boards/arm/mec1727/mec1727_defconfig index b6aa0dd1e9..e8c189750e 100644 --- a/zephyr/boards/arm/mec1727/mec1727_defconfig +++ b/zephyr/boards/arm/mec1727/mec1727_defconfig @@ -25,7 +25,7 @@ CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y # Pinmux Driver -CONFIG_PINMUX=y +CONFIG_PINMUX=n # Pinctrl Driver CONFIG_PINCTRL=y diff --git a/zephyr/dts/bindings/battery/battery-smart.yaml b/zephyr/dts/bindings/battery/battery-smart.yaml index a2cc299034..1d0c9786eb 100644 --- a/zephyr/dts/bindings/battery/battery-smart.yaml +++ b/zephyr/dts/bindings/battery/battery-smart.yaml @@ -55,7 +55,7 @@ properties: - "smp,cosxdy9k" - "smp,highpower_gh02047xl" - "smp,highpower_si03058xl" - - "sunwoda,atl3rr09" - - "sunwoda,cos3rr09" + - "sunwoda,atlvkyjx" + - "sunwoda,cosvkyjx" - "sunwoda,l22d3pg0" - "sunwoda,l22d3pg1" diff --git a/zephyr/dts/bindings/battery/sunwoda,atl3rr09.yaml b/zephyr/dts/bindings/battery/sunwoda,atlvkyjx.yaml index 5ca2477f87..91e2f6c1d0 100644 --- a/zephyr/dts/bindings/battery/sunwoda,atl3rr09.yaml +++ b/zephyr/dts/bindings/battery/sunwoda,atlvkyjx.yaml @@ -1,18 +1,18 @@ -description: "SUNWODA SWD-ATL4.242" -compatible: "sunwoda,atl3rr09" +description: "SUNWODA SWD-ATL3.660" +compatible: "sunwoda,atlvkyjx" include: battery-smart.yaml properties: enum-name: type: string - default: "sunwoda,atl3rr09" + default: "sunwoda,atlvkyjx" # Fuel Gauge manuf_name: - default: "SWD-ATL4.242" + default: "SWD-ATL3.660" device_name: - default: "DELL 3RR09" + default: "DELL VKYJX" ship_mode_reg_addr: default: 0x00 ship_mode_reg_data: @@ -32,9 +32,9 @@ properties: # Battery info voltage_max: - default: 17800 + default: 17600 voltage_normal: - default: 15200 + default: 15000 voltage_min: default: 12000 precharge_current: diff --git a/zephyr/dts/bindings/battery/sunwoda,cos3rr09.yaml b/zephyr/dts/bindings/battery/sunwoda,cosvkyjx.yaml index 58d6b7d635..d849d3344f 100644 --- a/zephyr/dts/bindings/battery/sunwoda,cos3rr09.yaml +++ b/zephyr/dts/bindings/battery/sunwoda,cosvkyjx.yaml @@ -1,18 +1,18 @@ -description: "SUNWODA SWD-COS4.264" -compatible: "sunwoda,cos3rr09" +description: "SUNWODA SWD-COS3.661" +compatible: "sunwoda,cosvkyjx" include: battery-smart.yaml properties: enum-name: type: string - default: "sunwoda,cos3rr09" + default: "sunwoda,cosvkyjx" # Fuel Gauge manuf_name: - default: "SWD-COS4.264" + default: "SWD-COS3.661" device_name: - default: "DELL 3RR09YMD" + default: "DELL VKYJX" ship_mode_reg_addr: default: 0x00 ship_mode_reg_data: @@ -32,9 +32,9 @@ properties: # Battery info voltage_max: - default: 17800 + default: 17600 voltage_normal: - default: 15200 + default: 15000 voltage_min: default: 12000 precharge_current: diff --git a/zephyr/dts/bindings/emul/zephyr,tusb1064.yaml b/zephyr/dts/bindings/emul/zephyr,tusb1064.yaml new file mode 100644 index 0000000000..3cab1dd5a6 --- /dev/null +++ b/zephyr/dts/bindings/emul/zephyr,tusb1064.yaml @@ -0,0 +1,9 @@ +# 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. +# +description: Zephyr TUSB1064 Emulator + +compatible: "zephyr,tusb1064-emul" + +include: "ti,tusb1064.yaml" 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/emul/CMakeLists.txt b/zephyr/emul/CMakeLists.txt index f8e4bae15b..377be11792 100644 --- a/zephyr/emul/CMakeLists.txt +++ b/zephyr/emul/CMakeLists.txt @@ -13,6 +13,7 @@ zephyr_library_sources_ifdef(CONFIG_EMUL_BMI emul_bmi.c) zephyr_library_sources_ifdef(CONFIG_EMUL_BMI emul_bmi160.c) zephyr_library_sources_ifdef(CONFIG_EMUL_BMI emul_bmi260.c) zephyr_library_sources_ifdef(CONFIG_EMUL_TCS3400 emul_tcs3400.c) +zephyr_library_sources_ifdef(CONFIG_EMUL_TUSB1064 emul_tusb1064.c) zephyr_library_sources_ifdef(CONFIG_EMUL_BB_RETIMER emul_bb_retimer.c) zephyr_library_sources_ifdef(CONFIG_EMUL_LN9310 emul_ln9310.c) zephyr_library_sources_ifdef(CONFIG_EMUL_LIS2DW12 emul_lis2dw12.c) diff --git a/zephyr/emul/Kconfig b/zephyr/emul/Kconfig index 3cabd96b6f..e445e30154 100644 --- a/zephyr/emul/Kconfig +++ b/zephyr/emul/Kconfig @@ -60,6 +60,13 @@ config EMUL_TCS3400 of proper access to reserved bits. Emulators API is available in zephyr/include/emul/emul_tcs3400.h +config EMUL_TUSB1064 + bool "TCS3400 emulator" + select EMUL_COMMON_I2C + help + Enable the TUSB1064 usb mux. This driver use emulated I2C bus. + Emulator API is available in zephyr/include/emul/emul_tusb1064.h. + config EMUL_BB_RETIMER bool "BB retimer emulator" select EMUL_COMMON_I2C diff --git a/zephyr/emul/emul_sn5s330.c b/zephyr/emul/emul_sn5s330.c index f957cd9e05..6a520ed195 100644 --- a/zephyr/emul/emul_sn5s330.c +++ b/zephyr/emul/emul_sn5s330.c @@ -227,15 +227,15 @@ static int sn5s330_emul_write_byte(const struct emul *emul, int reg, /* Specially check for read-only reg */ switch (reg) { case SN5S330_INT_TRIP_RISE_REG1: - /* fallthrough */ + __fallthrough; case SN5S330_INT_TRIP_RISE_REG2: - /* fallthrough */ + __fallthrough; case SN5S330_INT_TRIP_RISE_REG3: - /* fallthrough */ + __fallthrough; case SN5S330_INT_TRIP_FALL_REG1: - /* fallthrough */ + __fallthrough; case SN5S330_INT_TRIP_FALL_REG2: - /* fallthrough */ + __fallthrough; case SN5S330_INT_TRIP_FALL_REG3: reg_to_write = sn5s330_emul_get_reg_ptr(data, reg); /* Clearing any bit deasserts /INT interrupt signal */ @@ -245,15 +245,15 @@ static int sn5s330_emul_write_byte(const struct emul *emul, int reg, *reg_to_write = val; break; case SN5S330_INT_STATUS_REG1: - /* fallthrough */ + __fallthrough; case SN5S330_INT_STATUS_REG2: - /* fallthrough */ + __fallthrough; case SN5S330_INT_STATUS_REG3: __ASSERT(false, "Write to an unverified-as-safe read-only register on " "0x%x", reg); - /* fallthrough for checkpath */ + __fallthrough; default: reg_to_write = sn5s330_emul_get_reg_ptr(data, reg); *reg_to_write = val; diff --git a/zephyr/emul/emul_tusb1064.c b/zephyr/emul/emul_tusb1064.c new file mode 100644 index 0000000000..4396cc5fc5 --- /dev/null +++ b/zephyr/emul/emul_tusb1064.c @@ -0,0 +1,108 @@ +/* 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/device.h> + +#include "driver/usb_mux/tusb1064.h" +#include "emul/emul_common_i2c.h" +#include "emul/emul_stub_device.h" +#include "util.h" + +#define DT_DRV_COMPAT zephyr_tusb1064_emul + +#define TUSB1064_REG_MAX 255 + +struct tusb1064_data { + struct i2c_common_emul_data common; + uint8_t regs[TUSB1064_REG_MAX + 1]; +}; + +static const uint8_t default_values[TUSB1064_REG_MAX + 1] = { + [TUSB1064_REG_GENERAL] = 0x01, + [TUSB1064_REG_DP1DP3EQ_SEL] = 0x00, + [TUSB1064_REG_DP0DP2EQ_SEL] = 0x00, +}; + +void tusb1064_emul_reset_regs(const struct emul *emul) +{ + struct tusb1064_data *data = (struct tusb1064_data *)emul->data; + + memcpy(data->regs, default_values, TUSB1064_REG_MAX + 1); +} + +int tusb1064_emul_peek_reg(const struct emul *emul, int reg) +{ + struct tusb1064_data *data = (struct tusb1064_data *)emul->data; + uint8_t *regs = data->regs; + + if (!IN_RANGE(reg, 0, TUSB1064_REG_MAX)) { + return -1; + } + return regs[reg]; +} + +static int tusb1064_emul_read(const struct emul *emul, int reg, uint8_t *val, + int bytes, void *unused_data) +{ + struct tusb1064_data *data = (struct tusb1064_data *)emul->data; + uint8_t *regs = data->regs; + int pos = reg + bytes; + + if (!IN_RANGE(pos, 0, TUSB1064_REG_MAX)) { + return -1; + } + *val = regs[pos]; + + return 0; +} + +static int tusb1064_emul_write(const struct emul *emul, int reg, uint8_t val, + int bytes, void *unused_data) +{ + struct tusb1064_data *data = (struct tusb1064_data *)emul->data; + uint8_t *regs = data->regs; + int pos = reg + bytes - 1; + + if (!IN_RANGE(pos, 0, TUSB1064_REG_MAX) || + !IN_RANGE(val, 0, UINT8_MAX)) { + return -1; + } + regs[pos] = val; + + return 0; +} + +static int tusb1064_emul_init(const struct emul *emul, + const struct device *parent) +{ + struct tusb1064_data *data = (struct tusb1064_data *)emul->data; + struct i2c_common_emul_data *common_data = &data->common; + + i2c_common_emul_init(common_data); + i2c_common_emul_set_read_func(common_data, tusb1064_emul_read, NULL); + i2c_common_emul_set_write_func(common_data, tusb1064_emul_write, NULL); + + tusb1064_emul_reset_regs(emul); + + return 0; +} + +#define INIT_TUSB1064_EMUL(n) \ + static struct i2c_common_emul_cfg common_cfg_##n; \ + static struct tusb1064_data tusb1064_data_##n; \ + static struct i2c_common_emul_cfg common_cfg_##n = { \ + .dev_label = DT_NODE_FULL_NAME(DT_DRV_INST(n)), \ + .data = &tusb1064_data_##n.common, \ + .addr = DT_INST_REG_ADDR(n) \ + }; \ + static struct tusb1064_data tusb1064_data_##n = { \ + .common = { .cfg = &common_cfg_##n } \ + }; \ + EMUL_DT_INST_DEFINE(n, tusb1064_emul_init, &tusb1064_data_##n, \ + &common_cfg_##n, &i2c_common_emul_api) + +DT_INST_FOREACH_STATUS_OKAY(INIT_TUSB1064_EMUL) + +DT_INST_FOREACH_STATUS_OKAY(EMUL_STUB_DEVICE); diff --git a/zephyr/emul/tcpc/emul_ps8xxx.c b/zephyr/emul/tcpc/emul_ps8xxx.c index 22972bf084..57cc2c85f5 100644 --- a/zephyr/emul/tcpc/emul_ps8xxx.c +++ b/zephyr/emul/tcpc/emul_ps8xxx.c @@ -235,6 +235,7 @@ static int ps8xxx_emul_tcpc_write_byte(const struct emul *emul, int reg, if (prod_id != PS8815_PRODUCT_ID) { break; } + __fallthrough; case PS8XXX_REG_I2C_DEBUGGING_ENABLE: case PS8XXX_REG_MUX_IN_HPD_ASSERTION: case PS8XXX_REG_BIST_CONT_MODE_BYTE0: @@ -282,6 +283,7 @@ static int ps8xxx_emul_tcpc_finish_write(const struct emul *emul, int reg, if (prod_id != PS8815_PRODUCT_ID) { break; } + __fallthrough; case PS8XXX_REG_I2C_DEBUGGING_ENABLE: case PS8XXX_REG_MUX_IN_HPD_ASSERTION: case PS8XXX_REG_BIST_CONT_MODE_BYTE0: @@ -399,11 +401,13 @@ static int ps8xxx_emul_read_byte_workhorse(const struct emul *emul, int reg, *val = data->dci_cfg; return 0; } + __fallthrough; case PS8XXX_EMUL_PORT_GPIO: if (reg == PS8805_REG_GPIO_CONTROL) { *val = data->gpio_ctrl; return 0; } + __fallthrough; case PS8XXX_EMUL_PORT_INVAL: LOG_ERR("Invalid I2C address"); return -EIO; @@ -481,11 +485,13 @@ static int ps8xxx_emul_write_byte_workhorse(const struct emul *emul, int reg, data->dci_cfg = val; return 0; } + __fallthrough; case PS8XXX_EMUL_PORT_GPIO: if (reg == PS8805_REG_GPIO_CONTROL) { data->gpio_ctrl = val; return 0; } + __fallthrough; case PS8XXX_EMUL_PORT_INVAL: LOG_ERR("Invalid I2C address"); return -EIO; diff --git a/zephyr/emul/tcpc/emul_tcpci.c b/zephyr/emul/tcpc/emul_tcpci.c index e19f7a2726..aa4e508489 100644 --- a/zephyr/emul/tcpc/emul_tcpci.c +++ b/zephyr/emul/tcpc/emul_tcpci.c @@ -1211,7 +1211,7 @@ static int tcpci_emul_handle_transmit(const struct emul *emul) case TCPCI_MSG_TX_HARD_RESET: tcpci_emul_disable_pd_msg_delivery(emul); tcpci_emul_reset_mask_regs(ctx); - /* fallthrough */ + __fallthrough; case TCPCI_MSG_CABLE_RESET: /* * Cable and Hard reset are special and set success and fail @@ -1259,13 +1259,13 @@ int tcpci_emul_handle_write(const struct emul *emul, int reg, int msg_len) ctx->write_data &= ~TCPC_REG_ALERT_RX_STATUS; } } - /* fallthrough */ + __fallthrough; case TCPC_REG_FAULT_STATUS: case TCPC_REG_ALERT_EXT: /* Clear bits where TCPM set 1 */ get_reg(ctx, reg, &alert_val); ctx->write_data = alert_val & (~ctx->write_data); - /* fallthrough */ + __fallthrough; case TCPC_REG_ALERT_MASK: case TCPC_REG_POWER_STATUS_MASK: case TCPC_REG_FAULT_STATUS_MASK: @@ -1344,6 +1344,7 @@ int tcpci_emul_handle_write(const struct emul *emul, int reg, int msg_len) switch (reg_bytes) { case 2: rsvd_mask = tcpci_emul_rsvd_mask[reg + 1]; + __fallthrough; case 1: rsvd_mask <<= 8; rsvd_mask |= tcpci_emul_rsvd_mask[reg]; diff --git a/zephyr/emul/tcpc/emul_tcpci_partner_common.c b/zephyr/emul/tcpc/emul_tcpci_partner_common.c index 1785acda51..22a9ddb91e 100644 --- a/zephyr/emul/tcpc/emul_tcpci_partner_common.c +++ b/zephyr/emul/tcpc/emul_tcpci_partner_common.c @@ -1076,7 +1076,7 @@ tcpci_partner_common_sop_msg_handler(struct tcpci_partner_data *data, tcpci_partner_common_clear_ams_ctrl_msg(data); - /* Fall through */ + __fallthrough; case PD_CTRL_ACCEPT: if (data->wait_for_response) { if (data->in_soft_reset) { diff --git a/zephyr/firmware_builder.py b/zephyr/firmware_builder.py index 1cba339d5e..545d31312d 100755 --- a/zephyr/firmware_builder.py +++ b/zephyr/firmware_builder.py @@ -326,25 +326,6 @@ def test(opts): ).stdout _extract_lcov_summary("EC_ZEPHYR_MERGED", metrics, output) - cmd = [ - "/usr/bin/lcov", - "-o", - build_dir / "lcov_unfiltered.info", - "--rc", - "lcov_branch_coverage=1", - "-a", - build_dir / "zephyr_merged.info", - "-a", - platform_ec / "build/coverage/lcov.info", - ] - log_cmd(cmd) - subprocess.run( - cmd, - cwd=zephyr_dir, - check=True, - stdin=subprocess.DEVNULL, - ) - test_patterns = [ # Exclude tests platform_ec / "test/**", @@ -388,7 +369,7 @@ def test(opts): "--rc", "lcov_branch_coverage=1", "-r", - build_dir / "lcov_unfiltered.info", + build_dir / "zephyr_merged.info", ] + generated_and_system_patterns log_cmd(cmd) output = subprocess.run( diff --git a/zephyr/include/emul/emul_tusb1064.h b/zephyr/include/emul/emul_tusb1064.h new file mode 100644 index 0000000000..99732e36c9 --- /dev/null +++ b/zephyr/include/emul/emul_tusb1064.h @@ -0,0 +1,13 @@ +/* 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. + */ + +#ifndef EMUL_TUSB1064_H +#define EMUL_TUSB1064_H + +#include <zephyr/drivers/emul.h> + +int tusb1064_emul_peek_reg(const struct emul *emul, int reg); + +#endif diff --git a/zephyr/projects/.pylintrc b/zephyr/projects/.pylintrc index f4609e3781..8bdb6378e4 100644 --- a/zephyr/projects/.pylintrc +++ b/zephyr/projects/.pylintrc @@ -4,6 +4,7 @@ additional-builtins= register_binman_project, register_host_project, register_host_test, + register_mchp_project, register_npcx_project, register_raw_project, good-names=BUILD diff --git a/zephyr/projects/corsola/BUILD.py b/zephyr/projects/corsola/BUILD.py index 382de1d038..4e82ab7926 100644 --- a/zephyr/projects/corsola/BUILD.py +++ b/zephyr/projects/corsola/BUILD.py @@ -1,4 +1,4 @@ -# Copyright 2021 The ChromiumOS Authors. +# Copyright 2021 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/zephyr/projects/corsola/i2c_krabby.dts b/zephyr/projects/corsola/i2c_krabby.dts index 4b3c46ffe4..a5dc03b655 100644 --- a/zephyr/projects/corsola/i2c_krabby.dts +++ b/zephyr/projects/corsola/i2c_krabby.dts @@ -17,5 +17,6 @@ tusb1064_mux_1: tusb1064-mux-1@44 { compatible = "ti,tusb1064"; reg = <0x44>; + board-init = "tusb1064_mux_1_board_init"; }; }; diff --git a/zephyr/projects/corsola/i2c_krabby_tentacruel.dtsi b/zephyr/projects/corsola/i2c_krabby_tentacruel.dtsi index 377eaafbca..6fd153e1fa 100644 --- a/zephyr/projects/corsola/i2c_krabby_tentacruel.dtsi +++ b/zephyr/projects/corsola/i2c_krabby_tentacruel.dtsi @@ -79,6 +79,7 @@ pinctrl-0 = <&i2c1_clk_gpc1_default &i2c1_data_gpc2_default>; pinctrl-names = "default"; + fifo-enable; }; &i2c2 { @@ -89,6 +90,7 @@ pinctrl-0 = <&i2c2_clk_gpf6_default &i2c2_data_gpf7_default>; pinctrl-names = "default"; + /delete-property/ fifo-enable; bc12_ppc_port0: rt1739@70 { compatible = "richtek,rt1739"; diff --git a/zephyr/projects/corsola/interrupts_steelix.dts b/zephyr/projects/corsola/interrupts_steelix.dts index 2949972c0b..816beb95f4 100644 --- a/zephyr/projects/corsola/interrupts_steelix.dts +++ b/zephyr/projects/corsola/interrupts_steelix.dts @@ -1,4 +1,4 @@ -/* Copyright 2022 The ChromiumOS Authors. +/* 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. */ diff --git a/zephyr/projects/corsola/prj_it81202_base.conf b/zephyr/projects/corsola/prj_it81202_base.conf index 6c7df90ef5..82f4e3cc3b 100644 --- a/zephyr/projects/corsola/prj_it81202_base.conf +++ b/zephyr/projects/corsola/prj_it81202_base.conf @@ -68,7 +68,6 @@ CONFIG_PLATFORM_EC_USBA=y # USB-C CONFIG_PLATFORM_EC_BC12_SINGLE_DRIVER=n -CONFIG_PLATFORM_EC_SMBUS_PEC=y CONFIG_PLATFORM_EC_USBC_PPC_RT1739=y CONFIG_PLATFORM_EC_USBC_PPC_SYV682C=y CONFIG_PLATFORM_EC_USBC_PPC_SYV682X=y diff --git a/zephyr/projects/corsola/prj_magikarp.conf b/zephyr/projects/corsola/prj_magikarp.conf index 04c07f2573..a5ec9ede3b 100644 --- a/zephyr/projects/corsola/prj_magikarp.conf +++ b/zephyr/projects/corsola/prj_magikarp.conf @@ -9,6 +9,7 @@ CONFIG_BOARD_MAGIKARP=y CONFIG_PLATFORM_EC_BC12_DETECT_PI3USB9201=y CONFIG_PLATFORM_EC_USB_MUX_TUSB546=n CONFIG_PLATFORM_EC_USB_MUX_PS8743=y +CONFIG_PLATFORM_EC_PD_MAX_POWER_MW=45000 # Keyboard CONFIG_PLATFORM_EC_KEYBOARD_REFRESH_ROW3=y @@ -22,5 +23,5 @@ CONFIG_PLATFORM_EC_ACCELGYRO_BMI_COMM_I2C=y CONFIG_PLATFORM_EC_TEMP_SENSOR=y CONFIG_PLATFORM_EC_THERMISTOR=y -# USBC -CONFIG_PLATFORM_EC_PD_MAX_POWER_MW=45000 +# Battery +CONFIG_PLATFORM_EC_BATTERY_REVIVE_DISCONNECT=y diff --git a/zephyr/projects/corsola/prj_npcx993_base.conf b/zephyr/projects/corsola/prj_npcx993_base.conf index f3b220898e..0642bcd331 100644 --- a/zephyr/projects/corsola/prj_npcx993_base.conf +++ b/zephyr/projects/corsola/prj_npcx993_base.conf @@ -1,4 +1,4 @@ -# Copyright 2022 The ChromiumOS Authors. +# 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. diff --git a/zephyr/projects/corsola/prj_steelix.conf b/zephyr/projects/corsola/prj_steelix.conf index 09414f1a26..f7cdfb0477 100644 --- a/zephyr/projects/corsola/prj_steelix.conf +++ b/zephyr/projects/corsola/prj_steelix.conf @@ -1,4 +1,4 @@ -# Copyright 2022 The ChromiumOS Authors. +# 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. diff --git a/zephyr/projects/corsola/src/kingler/board_steelix.c b/zephyr/projects/corsola/src/kingler/board_steelix.c index d615be05a1..8b88a6d7c7 100644 --- a/zephyr/projects/corsola/src/kingler/board_steelix.c +++ b/zephyr/projects/corsola/src/kingler/board_steelix.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The ChromiumOS Authors. +/* 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. */ diff --git a/zephyr/projects/corsola/src/krabby/usbc_config.c b/zephyr/projects/corsola/src/krabby/usbc_config.c index 3ef9052e05..7a7f710804 100644 --- a/zephyr/projects/corsola/src/krabby/usbc_config.c +++ b/zephyr/projects/corsola/src/krabby/usbc_config.c @@ -10,6 +10,8 @@ #include "charge_manager.h" #include "console.h" #include "driver/tcpm/it83xx_pd.h" +#include "driver/usb_mux/tusb1064.h" +#include "i2c.h" #include "usb_pd.h" #include "usbc_ppc.h" @@ -17,6 +19,24 @@ #define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args) #define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args) +int tusb1064_mux_1_board_init(const struct usb_mux *me) +{ + int rv; + + rv = i2c_write8(me->i2c_port, me->i2c_addr_flags, + TUSB1064_REG_DP1DP3EQ_SEL, + TUSB1064_DP1EQ(TUSB1064_DP_EQ_RX_8_9_DB) | + TUSB1064_DP3EQ(TUSB1064_DP_EQ_RX_5_4_DB)); + if (rv) + return rv; + + /* Enable EQ_OVERRIDE so the gain registers are used */ + return i2c_update8(me->i2c_port, me->i2c_addr_flags, + TUSB1064_REG_GENERAL, REG_GENERAL_EQ_OVERRIDE, + 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 @@ -37,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) { @@ -46,6 +67,7 @@ void board_reset_pd_mcu(void) */ } +#ifndef CONFIG_TEST int board_set_active_charge_port(int port) { int i; @@ -102,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/projects/herobrine/include/board_chipset.h b/zephyr/projects/herobrine/include/board_chipset.h index 8350ef10ff..81c0dd1a40 100644 --- a/zephyr/projects/herobrine/include/board_chipset.h +++ b/zephyr/projects/herobrine/include/board_chipset.h @@ -1,4 +1,4 @@ -/* Copyright 2022 The ChromiumOS Authors. +/* 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. */ diff --git a/zephyr/projects/herobrine/src/board_chipset.c b/zephyr/projects/herobrine/src/board_chipset.c index 6a58eee99e..2312bdb1c4 100644 --- a/zephyr/projects/herobrine/src/board_chipset.c +++ b/zephyr/projects/herobrine/src/board_chipset.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The ChromiumOS Authors. +/* 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. */ diff --git a/zephyr/projects/intelrvp/BUILD.py b/zephyr/projects/intelrvp/BUILD.py index e6e617ea23..f129b3d2d2 100644 --- a/zephyr/projects/intelrvp/BUILD.py +++ b/zephyr/projects/intelrvp/BUILD.py @@ -15,7 +15,9 @@ def register_intelrvp_project( ): """Register a variant of intelrvp.""" register_func = register_binman_project - if chip.startswith("npcx"): + if chip.startswith("mec1727"): + register_func = register_mchp_project + elif chip.startswith("npcx"): register_func = register_npcx_project kconfig_files = [here / "prj.conf"] @@ -39,6 +41,23 @@ def register_intelrvp_project( register_intelrvp_project( + project_name="adlrvp_mchp", + chip="mec1727", + extra_dts_overlays=[ + here / "adlrvp/adlrvp_mchp/adlrvp_mchp.dts", + here / "adlrvp/adlrvp_mchp/gpio.dts", + here / "adlrvp/adlrvp_mchp/interrupts.dts", + here / "adlrvp/adlrvp_mchp/keyboard.dts", + here / "adlrvp/adlrvp_mchp/usbc.dts", + ], + extra_kconfig_files=[ + here / "legacy_ec_pwrseq.conf", + here / "adlrvp/adlrvp_mchp/prj.conf", + ], +) + + +register_intelrvp_project( project_name="adlrvp_npcx", chip="npcx9m7f", extra_dts_overlays=[ @@ -57,6 +76,7 @@ register_intelrvp_project( ], ) + register_intelrvp_project( project_name="mtlrvpp_npcx", chip="npcx9m3f", diff --git a/zephyr/projects/intelrvp/CMakeLists.txt b/zephyr/projects/intelrvp/CMakeLists.txt index 25b3af3931..039627dec6 100644 --- a/zephyr/projects/intelrvp/CMakeLists.txt +++ b/zephyr/projects/intelrvp/CMakeLists.txt @@ -14,7 +14,7 @@ cros_ec_library_include_directories("${PLATFORM_EC}/driver/tcpm") cros_ec_library_include_directories("${PLATFORM_EC}/driver/usb_mux") zephyr_library_sources("src/intel_rvp_board_id.c") -if(DEFINED CONFIG_BOARD_ADLRVP_NPCX) +if((DEFINED CONFIG_BOARD_ADLRVP_MCHP) OR (DEFINED CONFIG_BOARD_ADLRVP_NPCX)) add_subdirectory(adlrvp) zephyr_library_sources("src/intelrvp.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC "${PLATFORM_EC}/baseboard/intelrvp/usb_pd_policy_mecc_1_0.c") diff --git a/zephyr/projects/intelrvp/Kconfig b/zephyr/projects/intelrvp/Kconfig index c51c54847b..605f57c054 100644 --- a/zephyr/projects/intelrvp/Kconfig +++ b/zephyr/projects/intelrvp/Kconfig @@ -2,6 +2,13 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +config BOARD_ADLRVP_MCHP + bool "Intel ADLRVP_MCHP board" + depends on SOC_MEC172X_NSZ + help + Build Intel ADLRVP_MCHP reference board. This board has Intel ADL RVP + SoC with MEC1727 EC. + config BOARD_ADLRVP_NPCX bool "Intel ADLRVP_NPCX board" depends on SOC_NPCX9M7F diff --git a/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/adlrvp_mchp.dts b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/adlrvp_mchp.dts new file mode 100644 index 0000000000..527a62e776 --- /dev/null +++ b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/adlrvp_mchp.dts @@ -0,0 +1,201 @@ +/* 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. + */ + +/ { + hibernate-wake-pins { + compatible = "cros-ec,hibernate-wake-pins"; + wakeup-irqs = < + &int_ac_present + &int_lid_open + &int_power_button + >; + }; + + named-i2c-ports { + compatible = "named-i2c-ports"; + + i2c_charger: charger { + i2c-port = <&i2c_smb_0>; + enum-names = "I2C_PORT_BATTERY", + "I2C_PORT_CHARGER", + "I2C_PORT_EEPROM", + "I2C_PORT_PORT80"; + }; + typec_0: typec-0 { + i2c-port = <&i2c_smb_1>; + enum-names = "I2C_PORT_TYPEC_0"; + }; + typec_1: typec-1 { + i2c-port = <&i2c_smb_2>; + enum-names = "I2C_PORT_TYPEC_1"; + }; + typec_2: typec-2 { + i2c-port = <&i2c_smb_3>; + enum-names = "I2C_PORT_TYPEC_2"; + }; + typec_3: typec-3 { + i2c-port = <&i2c_smb_4>; + enum-names = "I2C_PORT_TYPEC_3"; + }; + }; +}; + +/* charger */ +&i2c_smb_0 { + status = "okay"; + clock-frequency = <I2C_BITRATE_STANDARD>; + port_sel = <0>; + pinctrl-0 = <&i2c00_scl_gpio004 &i2c00_sda_gpio003>; + pinctrl-names = "default"; + + pca95xx: pca95xx@22 { + compatible = "nxp,pca95xx"; + label = "PCA95XX"; + reg = <0x22>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <16>; + }; + + rvp_board_id: rvp-board-id { + compatible = "intel,rvp-board-id"; + + /* + * BOM ID [2] : IOEX[0] + * BOM ID [1:0] : IOEX[15:14] + */ + bom-gpios = <&pca95xx 0 0>, <&pca95xx 15 0>, <&pca95xx 14 0>; + + /* + * FAB ID [1:0] : IOEX[2:1] + */ + fab-gpios = <&pca95xx 2 0>, <&pca95xx 1 0>; + + /* + * BOARD ID[5:0] : IOEX[13:8] + */ + board-gpios = <&pca95xx 13 0>, <&pca95xx 12 0>, <&pca95xx 11 0>, + <&pca95xx 10 0>, <&pca95xx 9 0>, <&pca95xx 8 0>; + }; + + seven_seg_display: max695x-seven-seg-display@38 { + compatible = "maxim,seven-seg-display"; + reg = <0x38>; + label = "MAX695X_SEVEN_SEG_DISPLAY"; + }; + + charger: isl9241@9 { + compatible = "intersil,isl9241"; + status = "okay"; + reg = <0x9>; + }; + + cbi_eeprom: eeprom@50 { + compatible = "atmel,at24"; + reg = <0x50>; + size = <2048>; + pagesize = <16>; + address-width = <8>; + timeout = <5>; + }; +}; + +/* typec_0 */ +&i2c_smb_1 { + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST>; + port_sel = <6>; + pinctrl-0 = <&i2c06_scl_gpio140 &i2c06_sda_gpio132>; + pinctrl-names = "default"; + + tcpc_port0: fusb302@22 { + compatible = "fairchild,fusb302"; + reg = <0x22>; + }; + + usb_c0_soc_side_bb_retimer: jhl8040r-c0-soc-side@54 { + compatible = "intel,jhl8040r"; + reg = <0x54>; + reset-pin = <&usb_c0_bb_retimer_rst>; + ls-en-pin = <&usb_c0_bb_retimer_ls_en>; + }; + + usb_c0_bb_retimer: jhl8040r-c0@56 { + compatible = "intel,jhl8040r"; + reg = <0x56>; + reset-pin = <&usb_c0_bb_retimer_rst>; + ls-en-pin = <&usb_c0_bb_retimer_ls_en>; + }; +}; + +/* typec_1 */ +&i2c_smb_2 { + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST>; + port_sel = <3>; + pinctrl-0 = <&i2c03_scl_gpio010 &i2c03_sda_gpio007>; + pinctrl-names = "default"; + + tcpc_port1: fusb302@22 { + compatible = "fairchild,fusb302"; + reg = <0x22>; + }; + + usb_c1_soc_side_bb_retimer: jhl8040r-c1-soc-side@55 { + compatible = "intel,jhl8040r"; + reg = <0x55>; + reset-pin = <&usb_c1_bb_retimer_rst>; + ls-en-pin = <&usb_c1_bb_retimer_ls_en>; + }; + + usb_c1_bb_retimer: jhl8040r-c1@57 { + compatible = "intel,jhl8040r"; + reg = <0x57>; + reset-pin = <&usb_c1_bb_retimer_rst>; + ls-en-pin = <&usb_c1_bb_retimer_ls_en>; + }; +}; + +/* typec_2 */ +&i2c_smb_3 { + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST>; + port_sel = <7>; + pinctrl-0 = <&i2c07_scl_gpio013 &i2c07_sda_gpio012>; + pinctrl-names = "default"; + + tcpc_port2: fusb302@22 { + compatible = "fairchild,fusb302"; + reg = <0x22>; + }; + + usb_c2_bb_retimer: jhl8040r-c2@58 { + compatible = "intel,jhl8040r"; + reg = <0x58>; + reset-pin = <&usb_c2_bb_retimer_rst>; + ls-en-pin = <&usb_c2_bb_retimer_ls_en>; + }; +}; + +/* typec_3 */ +&i2c_smb_4 { + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST>; + port_sel = <2>; + pinctrl-0 = <&i2c02_scl_gpio155 &i2c02_sda_gpio154>; + pinctrl-names = "default"; + + tcpc_port3: fusb302@22 { + compatible = "fairchild,fusb302"; + reg = <0x22>; + }; + + usb_c3_bb_retimer: jhl8040r-c3@59 { + compatible = "intel,jhl8040r"; + reg = <0x59>; + reset-pin = <&usb_c3_bb_retimer_rst>; + ls-en-pin = <&usb_c3_bb_retimer_ls_en>; + }; +}; diff --git a/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/bb_retimer.dts b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/bb_retimer.dts new file mode 100644 index 0000000000..1c760120f1 --- /dev/null +++ b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/bb_retimer.dts @@ -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. + */ + +&i2c_smb_1 { + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST>; + + usb_c0_bb_retimer: jhl8040r@56 { + compatible = "intel,jhl8040r"; + reg = <0x56>; + label = "USB_C0_BB_RETIMER"; + reset-pin = <&usb_c0_bb_retimer_rst>; + }; +}; + +&i2c_smb_2 { + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST>; + + usb_c1_bb_retimer: jhl8040r@57 { + compatible = "intel,jhl8040r"; + reg = <0x57>; + label = "USB_C1_BB_RETIMER"; + reset-pin = <&usb_c1_bb_retimer_rst>; + }; +}; diff --git a/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/gpio.dts b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/gpio.dts new file mode 100644 index 0000000000..d526fdcb3b --- /dev/null +++ b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/gpio.dts @@ -0,0 +1,299 @@ +/* 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. + */ + +/ { + aliases { + gpio-wp = &gpio_wp; + gpio-kbd-kso2 = &gpio_ec_kso_02_inv; + }; + + named-gpios { + compatible = "named-gpios"; + + all_sys_pwrgd: all-sys-pwrgd { + gpios = <&gpio_040_076 15 GPIO_INPUT>; + enum-name = "GPIO_PG_EC_ALL_SYS_PWRGD"; + }; /* GPIO057 */ + rsmrst_pwrgd: rsmrst-pwrgd { + gpios = <&gpio_200_236 17 GPIO_INPUT>; + enum-name = "GPIO_PG_EC_RSMRST_ODL"; + }; /* GPIO221 */ + pch_slp_s0_n: pch-slp-s0-n { + gpios = <&gpio_240_276 3 GPIO_INPUT>; + enum-name = "GPIO_PCH_SLP_S0_L"; + }; /* GPIO243 */ + vccpdsw_3p3: vccpdsw-3p3 { + gpios = <&gpio_200_236 1 GPIO_INPUT>; + enum-name = "GPIO_PG_EC_DSW_PWROK"; + }; /* GPIO201 */ + pm_slp_sus_ec_n: pm-slp-sus-ec-n { + gpios = <&gpio_200_236 23 GPIO_INPUT>; + enum-name = "GPIO_SLP_SUS_L"; + }; /* GPIO227 */ + pm_slp_s3_n: pm-slp-s3-n { + gpios = <&gpio_140_176 17 GPIO_INPUT>; + enum-name = "GPIO_PCH_SLP_S3_L"; + }; /* GPIO161 */ + pm_slp_s4_n: pm-slp-s4-n { + gpios = <&gpio_140_176 18 GPIO_INPUT>; + }; /* GPIO162 */ + volume_up { + gpios = <&gpio_000_036 30 GPIO_INPUT_PULL_UP>; + enum-name = "GPIO_VOLUME_UP_L"; + }; /* GPIO036 */ + vol_dn_ec { + gpios = <&gpio_240_276 12 GPIO_INPUT_PULL_UP>; + enum-name = "GPIO_VOLUME_DOWN_L"; + }; /* GPIO254 */ + smc_lid: smc-lid { + gpios = <&gpio_200_236 22 GPIO_INPUT_PULL_UP>; + enum-name = "GPIO_LID_OPEN"; + }; /* GPIO226 */ + mech_pwr_btn_odl: mech-pwr-btn-odl { + gpios = <&gpio_100_136 13 GPIO_INPUT>; + enum-name = "GPIO_POWER_BUTTON_L"; + }; /* GPIO115 */ + std_adp_prsnt: std-adp-prsnt { + gpios = <&gpio_040_076 3 GPIO_INPUT>; + enum-name= "GPIO_DC_JACK_PRESENT"; + }; /* GPIO043 */ + bc_acok: bc-acok { + gpios = <&gpio_140_176 14 GPIO_INPUT>; + enum-name = "GPIO_AC_PRESENT"; + }; /* GPIO156 */ + usbc_tcpc_alrt_p0: usbc-tcpc-alrt-p0 { + gpios = <&gpio_140_176 3 GPIO_INPUT>; + }; /* GPIO143 */ + usbc_tcpc_alrt_p1: usbc-tcpc-alrt-p1 { + gpios = <&gpio_240_276 1 GPIO_INPUT>; + }; /* GPIO241 */ + usbc_tcpc_alrt_p2: usbc-tcpc-alrt-p2 { + gpios = <&gpio_100_136 24 GPIO_INPUT>; + }; /* GPIO130 */ + usbc_tcpc_alrt_p3: usbc-tcpc-alrt-p3 { + gpios = <&gpio_240_276 2 GPIO_INPUT>; + }; /* GPIO242 */ + usbc_tcpc_ppc_alrt_p0: usbc-tcpc-ppc-alrt-p0 { + gpios = <&gpio_240_276 0 GPIO_INPUT>; + }; /* GPIO240 */ + usbc_tcpc_ppc_alrt_p1: usbc-tcpc-ppc-alrt-p1 { + gpios = <&gpio_100_136 1 GPIO_INPUT>; + }; /* GPIO101 */ + usbc_tcpc_ppc_alrt_p2: usbc-tcpc-ppc-alrt-p2 { + gpios = <&gpio_140_176 4 GPIO_INPUT>; + }; /* GPIO144 */ + usbc_tcpc_ppc_alrt_p3: usbc-tcpc-ppc-alrt-p3 { + gpios = <&gpio_140_176 2 GPIO_INPUT>; + }; /* GPIO142 */ + gpio_ec_pch_wake_odl: smc-wake-sci-n-mecc { + gpios = <&gpio_040_076 9 GPIO_ODR_HIGH>; + }; /* GPIO051 */ + ec_pch_mkbp_int_odl { + gpios = <&gpio_100_136 23 GPIO_ODR_HIGH>; + }; /* GPIO127 */ + lpc_espi_rst_n { + gpios = <&gpio_040_076 17 GPIO_INPUT>; + }; /* GPIO061 NANA */ + plt_rst_l { + gpios = <&gpio_040_076 10 GPIO_INPUT>; + }; /* GPIO052 NANA */ + slate_mode_indication { + gpios = <&gpio_200_236 18 GPIO_INPUT>; + }; /* GPIO222 */ + prochot_ec_n { + gpios = <&gpio_000_036 2 GPIO_INPUT>; + enum-name = "GPIO_CPU_PROCHOT"; + }; /* GPIO002 ???? */ + sys_rst_odl { + gpios = <&gpio_040_076 16 GPIO_ODR_HIGH>; + enum-name = "GPIO_SYS_RESET_L"; + }; /* GPIO060 */ + pm_rsmrst_n { + gpios = <&gpio_040_076 12 GPIO_OUTPUT_LOW>; + enum-name = "GPIO_PCH_RSMRST_L"; + }; /* GPIO054 */ + pm_pwrbtn_n { + gpios = <&gpio_000_036 14 GPIO_ODR_HIGH>; + enum-name = "GPIO_PCH_PWRBTN_L"; + }; /* GPIO016 */ + ec_spi_oe_mecc: ec-spi-oe-mecc { + gpios = <&gpio_040_076 2 GPIO_OUTPUT_LOW>; + }; /* GPIO042 */ + ec_ds3 { + gpios = <&gpio_000_036 21 GPIO_OUTPUT_LOW>; + enum-name = "GPIO_EN_PP3300_A"; + }; /* GPIO025 */ + pch_pwrok_ec { + gpios = <&gpio_100_136 6 GPIO_INPUT>; + enum-name = "GPIO_PCH_PWROK"; + }; /* GPIO106 */ + sys_pwrok { + gpios = <&gpio_200_236 2 GPIO_OUTPUT_LOW>; + enum-name = "GPIO_PCH_SYS_PWROK"; + }; /* GPIO202 */ + ec_dsw_pwrok { + gpios = <&gpio_000_036 28 GPIO_OUTPUT_LOW>; + enum-name = "GPIO_PCH_DSW_PWROK"; + }; /* GPIO034 */ + gpio_wp: ec-flash-wp-odl { + gpios = <&gpio_000_036 12 GPIO_INPUT>; + }; /* GPIO014 */ + ec_h1_packet_mode { + gpios = <&gpio_000_036 29 GPIO_OUTPUT_LOW>; + enum-name = "GPIO_PACKET_MODE_EN"; + }; /* GPIO035 */ + ec_entering_rw { + gpios = <&gpio_100_136 2 GPIO_OUTPUT_LOW>; + enum-name = "GPIO_ENTERING_RW"; + }; /* GPIO102 */ + ccd_mode_odl: ccd-mode-odl { + gpios = <&gpio_140_176 29 GPIO_INPUT>; + enum-name = "GPIO_CCD_MODE_ODL"; + }; /* GPIO175 */ + bat_det { + gpios = <&gpio_200_236 6 GPIO_INPUT>; + enum-name = "GPIO_BATT_PRES_ODL"; + }; /* GPIO206 */ + edp_bklt_en_mecc { + gpios = <&gpio_000_036 18 GPIO_OUTPUT_HIGH>; + }; /* GPIO022 */ + led_1_l { + gpios = <&gpio_140_176 15 GPIO_OUTPUT_HIGH>; + }; /* GPIO157 */ + led_2_l { + gpios = <&gpio_140_176 11 GPIO_OUTPUT_HIGH>; + }; /* GPIO153 */ + therm_sen_mecc { + gpios = <&gpio_140_176 1 GPIO_OUTPUT_LOW>; + }; /* GPIO141 */ + smb_bs_clk { + gpios = <&gpio_000_036 4 GPIO_INPUT>; + }; /* GPIO004 */ + smb_bs_data { + gpios = <&gpio_000_036 3 GPIO_INPUT>; + }; /* GPIO003 */ + usbc_tcpc_i2c_clk_p0 { + gpios = <&gpio_140_176 0 GPIO_INPUT>; + }; /* GPIO140 */ + usbc_tcpc_i2c_data_p0 { + gpios = <&gpio_100_136 26 GPIO_INPUT>; + }; /* GPIO132 */ + usbc_tcpc_i2c_clk_p2 { + gpios = <&gpio_000_036 8 GPIO_INPUT>; + }; /* GPIO010 */ + usbc_tcpc_i2c_data_p2 { + gpios = <&gpio_000_036 7 GPIO_INPUT>; + }; /* GPIO007 */ + usbc_tcpc_i2c_clk_p1 { + gpios = <&gpio_000_036 11 GPIO_INPUT>; + }; /* GPIO013 */ + usbc_tcpc_i2c_data_p1 { + gpios = <&gpio_000_036 10 GPIO_INPUT>; + }; /* GPIO012 */ + usbc_tcpc_i2c_clk_p3 { + gpios = <&gpio_140_176 13 GPIO_INPUT>; + }; /* GPIO155 */ + usbc_tcpc_i2c_data_p3 { + gpios = <&gpio_140_176 12 GPIO_INPUT>; + }; /* GPIO154 */ + sml1_clk_mecc { + gpios = <&gpio_100_136 25 GPIO_INPUT>; + }; /* GPIO131 */ + cpu_cat_err_mecc { + gpios = <&gpio_000_036 0 GPIO_INPUT>; + }; /* GPIO000 */ + espi_alert0_n { + gpios = <&gpio_040_076 19 GPIO_INPUT>; + }; /* GPIO063 NANA */ + batt_disable_ec { + gpios = <&gpio_040_076 23 GPIO_INPUT>; + }; /* GPIO067 */ + cpu_c10_gate_mecc { + gpios = <&gpio_000_036 19 GPIO_INPUT>; + }; /* GPIO023 */ + smc_sdown_mecc { + gpios = <&gpio_240_276 13 GPIO_INPUT>; + }; /* GPIO255 */ + std_adpt_cntrl_gpio { + gpios = <&gpio_240_276 4 GPIO_INPUT>; + }; /* GPIO244 */ + smc_onoff_n { + gpios = <&gpio_100_136 12 GPIO_INPUT>; + }; /* GPIO114 */ + suswarn { + gpios = <&gpio_000_036 20 GPIO_INPUT>; + }; /* GPIO024 */ + me_g3_to_m3_ec { + gpios = <&gpio_000_036 27 GPIO_INPUT>; + }; /* GPIO033 */ + gpio_ec_kso_02_inv: ec-kso-02-inv { + gpios = <&gpio_040_076 6 (GPIO_OUTPUT_LOW + | GPIO_ACTIVE_LOW)>; + }; /* GPIO046 */ + + usb_c0_bb_retimer_rst: usb-c0-bb-retimer-rst { + gpios = <&ioex_c0_port 0 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C0_BB_RETIMER_RST"; + }; + usb_c0_bb_retimer_ls_en: usb-c0-bb-retimer-ls-en { + gpios = <&ioex_c0_port 1 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C0_BB_RETIMER_LS_EN"; + }; + usb-c0-usb-mux-cntrl-1 { + gpios = <&ioex_c0_port 4 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C0_USB_MUX_CNTRL_1"; + }; + usb-c0-usb-mux-cntrl-0 { + gpios = <&ioex_c0_port 5 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C0_USB_MUX_CNTRL_0"; + }; + usb_c1_bb_retimer_rst: usb-c1-bb-retimer-rst { + gpios = <&ioex_c1_port 0 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C1_BB_RETIMER_RST"; + }; + usb_c1_bb_retimer_ls_en: usb-c1-bb-retimer-ls-en { + gpios = <&ioex_c1_port 1 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C1_BB_RETIMER_LS_EN"; + }; + usb-c1-hpd { + gpios = <&ioex_c1_port 2 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C1_HPD"; + }; + usb-c0-c1-oc { + gpios = <&ioex_c1_port 8 GPIO_OUTPUT_HIGH>; + enum-name = "IOEX_USB_C0_C1_OC"; + }; + usb_c2_bb_retimer_rst: usb-c2-bb-retimer-rst { + gpios = <&ioex_c2_port 0 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C2_BB_RETIMER_RST"; + }; + usb_c2_bb_retimer_ls_en: usb-c2-bb-retimer-ls-en { + gpios = <&ioex_c2_port 1 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C2_BB_RETIMER_LS_EN"; + }; + usb-c2-usb-mux-cntrl-1 { + gpios = <&ioex_c2_port 4 GPIO_OUTPUT_LOW>; + }; + usb-c2-usb-mux-cntrl-0 { + gpios = <&ioex_c2_port 5 GPIO_OUTPUT_LOW>; + }; + usb_c3_bb_retimer_rst: usb-c3-bb-retimer-rst { + gpios = <&ioex_c3_port 0 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C3_BB_RETIMER_RST"; + }; + usb_c3_bb_retimer_ls_en: usb-c3-bb-retimer-ls-en { + gpios = <&ioex_c3_port 1 GPIO_OUTPUT_LOW>; + enum-name = "IOEX_USB_C3_BB_RETIMER_LS_EN"; + }; + usb-c2-c3-oc { + gpios = <&ioex_c3_port 8 GPIO_OUTPUT_HIGH>; + enum-name = "IOEX_USB_C2_C3_OC"; + }; + /* unimplemented GPIOs */ + en-pp5000 { + enum-name = "GPIO_EN_PP5000"; + }; + }; +}; diff --git a/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/interrupts.dts b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/interrupts.dts new file mode 100644 index 0000000000..17986fe2c7 --- /dev/null +++ b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/interrupts.dts @@ -0,0 +1,80 @@ +/* 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. + */ +/ { + gpio-interrupts { + compatible = "cros-ec,gpio-interrupts"; + + int_lid_open: lid-open { + irq-pin = <&smc_lid>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "lid_interrupt"; + }; + int_power_button: power-button { + irq-pin = <&mech_pwr_btn_odl>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "power_button_interrupt"; + }; + int_ac_present: ac-present { + irq-pin = <&bc_acok>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "extpower_interrupt"; + }; + int_slp_s0: slp-s0 { + irq-pin = <&pch_slp_s0_n>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "power_signal_interrupt"; + }; + int_slp_sus: slp-sus { + irq-pin = <&pm_slp_sus_ec_n>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "power_signal_interrupt"; + }; + int_pg_dsw_pwrok: pg-dsw-pwrok { + irq-pin = <&vccpdsw_3p3>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "power_signal_interrupt"; + }; + int_rsmrst_pwrgd: rsmrst-pwrgd { + irq-pin = <&rsmrst_pwrgd>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "power_signal_interrupt"; + }; + int_all_sys_pwrgd: all-sys-pwrgd { + irq-pin = <&all_sys_pwrgd>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "power_signal_interrupt"; + }; + int_usbc_tcpc_alrt_p0: usbc-tcpc-alrt-p0 { + irq-pin = <&usbc_tcpc_alrt_p0>; + flags = <GPIO_INT_EDGE_FALLING>; + handler = "tcpc_alert_event"; + }; + int_usbc_tcpc_alrt_p1: usbc-tcpc-alrt-p1 { + irq-pin = <&usbc_tcpc_alrt_p1>; + flags = <GPIO_INT_EDGE_FALLING>; + handler = "tcpc_alert_event"; + }; + int_usbc_tcpc_ppc_alrt_p0: usbc-tcpc-ppc-alrt-p0 { + irq-pin = <&usbc_tcpc_ppc_alrt_p0>; + flags = <GPIO_INT_EDGE_FALLING>; + handler = "ppc_interrupt"; + }; + int_usbc_tcpc_ppc_alrt_p1: usbc-tcpc-ppc-alrt-p1 { + irq-pin = <&usbc_tcpc_ppc_alrt_p1>; + flags = <GPIO_INT_EDGE_FALLING>; + handler = "ppc_interrupt"; + }; + int_std_adp_prsnt: std-adp-prsnt { + irq-pin = <&std_adp_prsnt>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "board_dc_jack_interrupt"; + }; + int_ccd_mode_odl: ccd-mode-odl { + irq-pin = <&ccd_mode_odl>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "board_connect_c0_sbu"; + }; + }; +}; diff --git a/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/keyboard.dts b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/keyboard.dts new file mode 100644 index 0000000000..b3577e6afd --- /dev/null +++ b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/keyboard.dts @@ -0,0 +1,31 @@ +/* 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. + */ + +/ { + cros-keyscan { + compatible = "cros-keyscan"; + + output-settle = <80>; + debounce-down = <9000>; + debounce-up = <30000>; + poll-timeout = <100000>; + + actual-key-mask = < + 0x14 /* C0 */ + 0xff /* C1 */ + 0xff /* C2 */ + 0xff /* C3 */ + 0xff /* C4 */ + 0xf5 /* C5 */ + 0xff /* C6 */ + 0xa4 /* C7 */ + 0xff /* C8 */ + 0xfe /* C9 */ + 0x55 /* C10 */ + 0xfa /* C11 */ + 0xca /* C12 */ + >; + }; +}; diff --git a/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/prj.conf b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/prj.conf new file mode 100644 index 0000000000..083530c858 --- /dev/null +++ b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/prj.conf @@ -0,0 +1,84 @@ +# 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. + +CONFIG_BOARD_ADLRVP_MCHP=y +CONFIG_CROS_FLASH_XEC=y +CONFIG_CROS_SYSTEM_XEC=y +CONFIG_CROS_KB_RAW_XEC=y + +# For MCHP ESPI Drivers +CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD=y +CONFIG_ESPI_PERIPHERAL_ACPI_SHM_REGION=y +CONFIG_ESPI_PERIPHERAL_CUSTOM_OPCODE=y +CONFIG_ESPI_PERIPHERAL_XEC_EMI0=y +CONFIG_ESPI_PERIPHERAL_ACPI_EC_IBF_EVT_DATA=y +CONFIG_ESPI_PERIPHERAL_KBC_OBE_CBK=y +CONFIG_ESPI_PERIPHERAL_KBC_IBF_EVT_DATA=y + +# Invoke SoC Python script to create zephyr.mchp.bin which +# is zephyr.bin processed for Boot-ROM loading. +CONFIG_MCHP_MEC_UNSIGNED_HEADER=y +CONFIG_MCHP_MEC_HEADER_FLASH_SIZE_256K=y + +# Support Zephyr SPI NOR driver to work with MCHP SPI driver +CONFIG_SPI_NOR=y +CONFIG_SPI_XEC_QMSPI_FULL_DUPLEX=y + +# Sensors - MCHP TACH driver under sensor +CONFIG_SENSOR=n +CONFIG_SENSOR_SHELL=n + +# Debug option +# Enable flash console commands +CONFIG_PLATFORM_EC_CONSOLE_CMD_FLASH=y + + +## TODO - support following features next +# Fan +CONFIG_PLATFORM_EC_FAN=n + +# RTC +CONFIG_PLATFORM_EC_RTC=n + +# PWM +CONFIG_PWM=n +CONFIG_PWM_SHELL=n + +## INTEL RVP +# Host command +CONFIG_PLATFORM_EC_HOSTCMD_AP_RESET=n + +# Power Sequencing +CONFIG_PLATFORM_EC_THROTTLE_AP=n + +## ADL RVP +# CBI +CONFIG_EEPROM=n +CONFIG_EEPROM_AT24=n +CONFIG_EEPROM_SHELL=n +CONFIG_PLATFORM_EC_CBI_EEPROM=n + +# LED +CONFIG_PLATFORM_EC_LED_COMMON=n +CONFIG_PLATFORM_EC_LED_PWM=n +CONFIG_PLATFORM_EC_LED_PWM_TASK_DISABLED=n + +# Temperature sensors +CONFIG_PLATFORM_EC_TEMP_SENSOR=n +CONFIG_PLATFORM_EC_THERMISTOR=n +CONFIG_PLATFORM_EC_TEMP_SENSOR_POWER=n + +# Charger +CONFIG_PLATFORM_EC_DEDICATED_CHARGE_PORT=y + +# H1 issues second reset +CONFIG_PLATFORM_EC_BOARD_RESET_AFTER_POWER_ON=n + +# 7-Segment Display +CONFIG_PLATFORM_EC_MAX695X_SEVEN_SEGMENT_DISPLAY=n + +# Debug options +# Enable flash console commands +CONFIG_PLATFORM_EC_CONSOLE_CMD_FLASH=y +CONFIG_WDT_DISABLE_AT_BOOT=y diff --git a/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/usbc.dts b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/usbc.dts new file mode 100644 index 0000000000..471a1f52e9 --- /dev/null +++ b/zephyr/projects/intelrvp/adlrvp/adlrvp_mchp/usbc.dts @@ -0,0 +1,89 @@ +/* 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. + */ + +/ { + usbc { + #address-cells = <1>; + #size-cells = <0>; + usbc_port0: port0@0 { + compatible = "named-usbc-port"; + reg = <0>; + tcpc = <&tcpc_port0>; + chg = <&charger>; + usb_mux_chain_0: usb-mux-chain-0 { + compatible = "cros-ec,usb-mux-chain"; + usb-muxes = <&usb_c0_bb_retimer + &virtual_mux_c0>; + }; + usb_mux_alt_chain_0: usb-mux-alt-chain-0 { + compatible = "cros-ec,usb-mux-chain"; + alternative-chain; + usb-muxes = <&usb_c0_bb_retimer + &usb_c0_soc_side_bb_retimer + &virtual_mux_c0>; + }; + }; + port0-muxes { + virtual_mux_c0: virtual-mux-c0 { + compatible = "cros-ec,usbc-mux-virtual"; + }; + }; + + usbc_port1: port1@1 { + compatible = "named-usbc-port"; + reg = <1>; + tcpc = <&tcpc_port1>; + usb_mux_chain_1: usb-mux-chain-1 { + compatible = "cros-ec,usb-mux-chain"; + usb-muxes = <&usb_c1_bb_retimer + &virtual_mux_c1>; + }; + usb_mux_alt_chain_1: usb-mux-alt-chain-1 { + compatible = "cros-ec,usb-mux-chain"; + alternative-chain; + usb-muxes = <&usb_c1_bb_retimer + &usb_c1_soc_side_bb_retimer + &virtual_mux_c1>; + }; + }; + port1-muxes { + virtual_mux_c1: virtual-mux-c1 { + compatible = "cros-ec,usbc-mux-virtual"; + }; + }; + + port2@2 { + compatible = "named-usbc-port"; + reg = <2>; + tcpc = <&tcpc_port2>; + usb_mux_chain_2: usb-mux-chain-2 { + compatible = "cros-ec,usb-mux-chain"; + usb-muxes = <&usb_c2_bb_retimer + &virtual_mux_c2>; + }; + }; + port2-muxes { + virtual_mux_c2: virtual-mux-c2 { + compatible = "cros-ec,usbc-mux-virtual"; + }; + }; + + port3@3 { + compatible = "named-usbc-port"; + reg = <3>; + tcpc = <&tcpc_port3>; + usb_mux_chain_3: usb-mux-chain-3 { + compatible = "cros-ec,usb-mux-chain"; + usb-muxes = <&usb_c3_bb_retimer + &virtual_mux_c3>; + }; + }; + port3-muxes { + virtual_mux_c3: virtual-mux-c3 { + compatible = "cros-ec,usbc-mux-virtual"; + }; + }; + }; +}; diff --git a/zephyr/projects/nissa/BUILD.py b/zephyr/projects/nissa/BUILD.py index e162bc2b96..dbb427bcc5 100644 --- a/zephyr/projects/nissa/BUILD.py +++ b/zephyr/projects/nissa/BUILD.py @@ -119,6 +119,7 @@ yaviks = register_nissa_project( project_name="yaviks", chip="it81302bx", extra_dts_overlays=[ + "cbi.dts", "gpio.dts", "overlay.dts", "keyboard.dts", diff --git a/zephyr/projects/nissa/pujjo/motionsense.dts b/zephyr/projects/nissa/pujjo/motionsense.dts index ce4a6babe0..2dfca337c4 100644 --- a/zephyr/projects/nissa/pujjo/motionsense.dts +++ b/zephyr/projects/nissa/pujjo/motionsense.dts @@ -1,4 +1,4 @@ -/* Copyright 2022 The ChromiumOS Authors. +/* 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. */ diff --git a/zephyr/projects/nissa/pujjo/prj.conf b/zephyr/projects/nissa/pujjo/prj.conf index 12b8649c44..bb4081acbe 100644 --- a/zephyr/projects/nissa/pujjo/prj.conf +++ b/zephyr/projects/nissa/pujjo/prj.conf @@ -21,4 +21,7 @@ CONFIG_PLATFORM_EC_LED_COMMON=y # CBI CONFIG_PLATFORM_EC_BYPASS_CBI_EEPROM_WP_CHECK=y -CONFIG_PLATFORM_EC_SYSTEM_UNLOCKED=y
\ No newline at end of file +CONFIG_PLATFORM_EC_SYSTEM_UNLOCKED=y + +# DPS +CONFIG_PLATFORM_EC_USB_PD_DPS=n
\ No newline at end of file diff --git a/zephyr/projects/nissa/yaviks/cbi.dts b/zephyr/projects/nissa/yaviks/cbi.dts new file mode 100644 index 0000000000..c5716cbd37 --- /dev/null +++ b/zephyr/projects/nissa/yaviks/cbi.dts @@ -0,0 +1,99 @@ +/* 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. + */ + +/ { + /* Yaviks-specific fw_config fields. */ + nissa-fw-config { + /* + * FW_CONFIG field for multiple wi-fi SAR. + * + * start = <2>; + * size = <2>; + */ + + /* + * FW_CONFIG field to enable fan or not. + */ + fan { + enum-name = "FW_FAN"; + start = <4>; + size = <1>; + + no-fan { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_FAN_NOT_PRESENT"; + value = <0>; + }; + fan-present { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_FAN_PRESENT"; + value = <1>; + /* + * Set as default so that unprovisioned + * configs will run the fan regardless. + */ + default; + }; + }; + + /* + * FW_CONFIG field to indicate which keyboard layout + * should be used. + */ + keyboard { + enum-name = "FW_KB_LAYOUT"; + start = <5>; + size = <1>; + + layout-1 { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_KB_LAYOUT_DEFAULT"; + value = <0>; + default; + }; + layout-2 { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_KB_LAYOUT_US2"; + value = <1>; + }; + }; + + /* + * FW_CONFIG field to indicate which keyboard layout + * should be used. + */ + keyboard-backlight { + enum-name = "FW_KB_BACKLIGHT"; + start = <6>; + size = <1>; + + without-keyboard-backlight { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_KB_BACKLIGHT_OFF"; + value = <1>; + }; + with-keyboard-backlight { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_KB_BACKLIGHT_ON"; + value = <0>; + default; + }; + }; + + /* + * FW_CONFIG field for multiple touch panel. + * + * start = <7>; + * size = <2>; + */ + + /* + * FW_CONFIG field for multiple storage. + * + * start = <31>; + * size = <1>; + */ + }; +}; diff --git a/zephyr/projects/nissa/yaviks/src/fan.c b/zephyr/projects/nissa/yaviks/src/fan.c index e1f909e6bf..23c3ec1143 100644 --- a/zephyr/projects/nissa/yaviks/src/fan.c +++ b/zephyr/projects/nissa/yaviks/src/fan.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The ChromiumOS Authors. +/* 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. */ diff --git a/zephyr/projects/nissa/yaviks/src/keyboard.c b/zephyr/projects/nissa/yaviks/src/keyboard.c index 1e5ac7a953..46d6083dbf 100644 --- a/zephyr/projects/nissa/yaviks/src/keyboard.c +++ b/zephyr/projects/nissa/yaviks/src/keyboard.c @@ -2,11 +2,17 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#include <zephyr/logging/log.h> +#include "cros_cbi.h" #include "ec_commands.h" +#include "hooks.h" +#include "keyboard_8042_sharedlib.h" #include "keyboard_scan.h" #include "timer.h" +LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); + /* Keyboard scan setting */ __override struct keyboard_scan_config keyscan_config = { /* Increase from 50 us, because KSO_02 passes through the H1. */ @@ -23,7 +29,7 @@ __override struct keyboard_scan_config keyscan_config = { }, }; -static const struct ec_response_keybd_config yaviks_kb_legacy = { +static const struct ec_response_keybd_config yaviks_kb_w_kb_light = { .num_top_row_keys = 13, .action_keys = { TK_BACK, /* T1 */ @@ -43,8 +49,58 @@ static const struct ec_response_keybd_config yaviks_kb_legacy = { .capabilities = KEYBD_CAP_NUMERIC_KEYPAD, }; +static const struct ec_response_keybd_config yaviks_kb_wo_kb_light = { + .num_top_row_keys = 13, + .action_keys = { + TK_BACK, /* T1 */ + TK_REFRESH, /* T2 */ + TK_FULLSCREEN, /* T3 */ + TK_OVERVIEW, /* T4 */ + TK_SNAPSHOT, /* T5 */ + TK_BRIGHTNESS_DOWN, /* T6 */ + TK_BRIGHTNESS_UP, /* T7 */ + TK_PLAY_PAUSE, /* T8 */ + TK_MICMUTE, /* T9 */ + TK_VOL_MUTE, /* T10 */ + TK_VOL_DOWN, /* T11 */ + TK_VOL_UP, /* T12 */ + TK_MENU, /* T13 */ + }, + .capabilities = KEYBD_CAP_NUMERIC_KEYPAD, +}; + __override const struct ec_response_keybd_config * board_vivaldi_keybd_config(void) { - return &yaviks_kb_legacy; + uint32_t val; + + cros_cbi_get_fw_config(FW_KB_BACKLIGHT, &val); + + if (val == FW_KB_BACKLIGHT_OFF) + return &yaviks_kb_wo_kb_light; + else + return &yaviks_kb_w_kb_light; +} + +/* + * Keyboard layout decided by FW config. + */ +static void kb_layout_init(void) +{ + int ret; + uint32_t val; + + ret = cros_cbi_get_fw_config(FW_KB_LAYOUT, &val); + if (ret != 0) { + LOG_ERR("Error retrieving CBI FW_CONFIG field %d", + FW_KB_LAYOUT); + return; + } + /* + * If keyboard is US2(FW_KB_LAYOUT_US2), we need translate right ctrl + * to backslash(\|) key. + */ + if (val == FW_KB_LAYOUT_US2) + set_scancode_set2(4, 0, get_scancode_set2(2, 7)); } +DECLARE_HOOK(HOOK_INIT, kb_layout_init, HOOK_PRIO_POST_FIRST); diff --git a/zephyr/projects/nissa/yaviks/src/led.c b/zephyr/projects/nissa/yaviks/src/led.c index e4f49dc9ad..88a476f1b0 100644 --- a/zephyr/projects/nissa/yaviks/src/led.c +++ b/zephyr/projects/nissa/yaviks/src/led.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The ChromiumOS Authors. +/* 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. */ diff --git a/zephyr/projects/skyrim/CMakeLists.txt b/zephyr/projects/skyrim/CMakeLists.txt index 14a86bed70..71b8427aa1 100644 --- a/zephyr/projects/skyrim/CMakeLists.txt +++ b/zephyr/projects/skyrim/CMakeLists.txt @@ -44,6 +44,7 @@ if(DEFINED CONFIG_BOARD_WINTERHOLD) "src/winterhold/usb_mux_config.c" "src/winterhold/ppc_config.c" "src/winterhold/kb_backlight.c" + "src/winterhold/keyboard.c" ) endif() diff --git a/zephyr/projects/skyrim/Kconfig b/zephyr/projects/skyrim/Kconfig index 77c073a691..fbb797f6fc 100644 --- a/zephyr/projects/skyrim/Kconfig +++ b/zephyr/projects/skyrim/Kconfig @@ -32,6 +32,13 @@ config BOARD_INPUT_CURRENT_SCALE_FACTOR help Limit input current to fraction of negotiated limit. +config BOARD_USB_HUB_RESET + bool "Support USB hub reset or not" + default y + help + Enable this if your board has a USB hub reset GPIO connect to EC to + reset the USB hub. + module = SKYRIM module-str = Skyrim board-specific code source "subsys/logging/Kconfig.template.log_config" diff --git a/zephyr/projects/skyrim/battery_winterhold.dts b/zephyr/projects/skyrim/battery_winterhold.dts index 776d74cdff..d923243d45 100644 --- a/zephyr/projects/skyrim/battery_winterhold.dts +++ b/zephyr/projects/skyrim/battery_winterhold.dts @@ -20,11 +20,11 @@ cosmx_mvk11{ compatible = "cosmx,mvk11", "battery-smart"; }; - sunwoda_atl3rr09{ - compatible = "sunwoda,atl3rr09", "battery-smart"; + sunwoda_atlvkyjx{ + compatible = "sunwoda,atlvkyjx", "battery-smart"; }; - sunwoda_cos3rr09{ - compatible = "sunwoda,cos3rr09", "battery-smart"; + sunwoda_cosvkyjx{ + compatible = "sunwoda,cosvkyjx", "battery-smart"; }; atl_cfd72{ compatible = "atl,cfd72", "battery-smart"; diff --git a/zephyr/projects/skyrim/prj.conf b/zephyr/projects/skyrim/prj.conf index 2c8bc999fb..a0085258e4 100644 --- a/zephyr/projects/skyrim/prj.conf +++ b/zephyr/projects/skyrim/prj.conf @@ -110,7 +110,7 @@ CONFIG_PLATFORM_EC_USBC_SS_MUX_DFP_ONLY=y CONFIG_PLATFORM_EC_USB_MUX_AMD_FP6=y CONFIG_PLATFORM_EC_USB_MUX_RUNTIME_CONFIG=y CONFIG_PLATFORM_EC_USB_DRP_ACC_TRYSRC=y -CONFIG_PLATFORM_EC_USB_PID=0x504D +CONFIG_PLATFORM_EC_USB_PID=0x505F CONFIG_PLATFORM_EC_USB_PD_5V_EN_CUSTOM=y CONFIG_PLATFORM_EC_USB_PD_VBUS_DETECT_TCPC=y CONFIG_PLATFORM_EC_USB_PD_DISCHARGE_TCPC=y diff --git a/zephyr/projects/skyrim/prj_frostflow.conf b/zephyr/projects/skyrim/prj_frostflow.conf index 6372bae444..29931de4d4 100644 --- a/zephyr/projects/skyrim/prj_frostflow.conf +++ b/zephyr/projects/skyrim/prj_frostflow.conf @@ -25,3 +25,6 @@ CONFIG_PLATFORM_EC_USBC_RETIMER_ANX7483=y # Keyboard CONFIG_PLATFORM_EC_KEYBOARD_CUSTOMIZATION=y + +# Frostflow not have the USB HUB +CONFIG_BOARD_USB_HUB_RESET=n diff --git a/zephyr/projects/skyrim/prj_winterhold.conf b/zephyr/projects/skyrim/prj_winterhold.conf index 6057770cf8..2ccd195a72 100644 --- a/zephyr/projects/skyrim/prj_winterhold.conf +++ b/zephyr/projects/skyrim/prj_winterhold.conf @@ -19,4 +19,8 @@ CONFIG_PLATFORM_EC_USBC_RETIMER_ANX7483=y # Enable charger chip CONFIG_PLATFORM_EC_CHARGER_ISL9238=y -CONFIG_PLATFORM_EC_CHARGER_ISL9241=n
\ No newline at end of file +CONFIG_PLATFORM_EC_CHARGER_ISL9241=n + +# Get the vbus voltage from TCPC +CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=n +CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_TCPC=y
\ No newline at end of file diff --git a/zephyr/projects/skyrim/src/power_signals.c b/zephyr/projects/skyrim/src/power_signals.c index 1f72d482b9..5d372d35ae 100644 --- a/zephyr/projects/skyrim/src/power_signals.c +++ b/zephyr/projects/skyrim/src/power_signals.c @@ -200,20 +200,23 @@ void baseboard_en_pwr_s0(enum gpio_signal signal) /* Now chain off to the normal power signal interrupt handler. */ power_signal_interrupt(signal); } - +#ifdef CONFIG_BOARD_USB_HUB_RESET void baseboard_enable_hub(void) { gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_rst), 0); } DECLARE_DEFERRED(baseboard_enable_hub); +#endif /* CONFIG_BOARD_USB_HUB_RESET */ void baseboard_s5_pgood(enum gpio_signal signal) { +#ifdef CONFIG_BOARD_USB_HUB_RESET /* We must enable the USB hub at least 30ms after S5 PGOOD */ if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_pg_pwr_s5))) hook_call_deferred(&baseboard_enable_hub_data, 30 * MSEC); else gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_rst), 1); +#endif /* CONFIG_BOARD_USB_HUB_RESET */ /* Continue to our signal AND-ing and power interrupt */ baseboard_en_pwr_s0(signal); diff --git a/zephyr/projects/skyrim/src/winterhold/keyboard.c b/zephyr/projects/skyrim/src/winterhold/keyboard.c new file mode 100644 index 0000000000..d3aebe0f2e --- /dev/null +++ b/zephyr/projects/skyrim/src/winterhold/keyboard.c @@ -0,0 +1,29 @@ +/* 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 "ec_commands.h" + +static const struct ec_response_keybd_config winterhold_kb = { + .num_top_row_keys = 10, + .action_keys = { + TK_BACK, /* T1 */ + TK_REFRESH, /* T2 */ + TK_FULLSCREEN, /* T3 */ + TK_OVERVIEW, /* T4 */ + TK_SNAPSHOT, /* T5 */ + TK_BRIGHTNESS_DOWN, /* T6 */ + TK_BRIGHTNESS_UP, /* T7 */ + TK_VOL_MUTE, /* T8 */ + TK_VOL_DOWN, /* T9 */ + TK_VOL_UP, /* T10 */ + }, + .capabilities = KEYBD_CAP_SCRNLOCK_KEY, +}; + +__override const struct ec_response_keybd_config * +board_vivaldi_keybd_config(void) +{ + return &winterhold_kb; +} diff --git a/zephyr/shim/chip/mchp/system_download_from_flash.c b/zephyr/shim/chip/mchp/system_download_from_flash.c index ced7f4d89c..51cdc5aab6 100644 --- a/zephyr/shim/chip/mchp/system_download_from_flash.c +++ b/zephyr/shim/chip/mchp/system_download_from_flash.c @@ -17,7 +17,7 @@ #define STRUCT_PCR_REG_BASE_ADDR \ ((struct pcr_regs *)DT_REG_ADDR_BY_IDX(PCR_NODE, 0)) -#define QSPI_NODE DT_INST(0, microchip_xec_qmspi_ldma) +#define QSPI_NODE DT_INST(0, microchip_xec_qmspi_full_duplex) #define STRUCT_QSPI_REG_BASE_ADDR \ ((struct qmspi_regs *)(DT_REG_ADDR(QSPI_NODE))) diff --git a/zephyr/shim/include/usbc/tusb1064_usb_mux.h b/zephyr/shim/include/usbc/tusb1064_usb_mux.h index 55dc8d4645..4dfdcaff18 100644 --- a/zephyr/shim/include/usbc/tusb1064_usb_mux.h +++ b/zephyr/shim/include/usbc/tusb1064_usb_mux.h @@ -9,6 +9,7 @@ #include "driver/usb_mux/tusb1064.h" #define TUSB1064_USB_MUX_COMPAT ti_tusb1064 +#define TUSB1064_EMUL_COMPAT zephyr_tusb1064_emul #if defined(CONFIG_USB_MUX_TUSB1044) #define USB_MUX_CONFIG_TUSB1064(mux_id) \ diff --git a/zephyr/shim/include/usbc/usb_muxes.h b/zephyr/shim/include/usbc/usb_muxes.h index d161b72b08..f94aed488d 100644 --- a/zephyr/shim/include/usbc/usb_muxes.h +++ b/zephyr/shim/include/usbc/usb_muxes.h @@ -36,6 +36,7 @@ (PS8XXX_USB_MUX_COMPAT, USB_MUX_CONFIG_TCPCI_TCPM), \ (TCPCI_TCPM_USB_MUX_COMPAT, USB_MUX_CONFIG_TCPCI_TCPM), \ (TUSB1064_USB_MUX_COMPAT, USB_MUX_CONFIG_TUSB1064), \ + (TUSB1064_EMUL_COMPAT, USB_MUX_CONFIG_TUSB1064), \ (VIRTUAL_USB_MUX_COMPAT, USB_MUX_CONFIG_VIRTUAL) /** diff --git a/zephyr/shim/src/console.c b/zephyr/shim/src/console.c index 2d0476149c..91f9014dac 100644 --- a/zephyr/shim/src/console.c +++ b/zephyr/shim/src/console.c @@ -40,9 +40,6 @@ #error Must select only one shell backend #endif -BUILD_ASSERT(EC_TASK_PRIORITY(EC_SHELL_PRIO) == CONFIG_SHELL_THREAD_PRIORITY, - "EC_SHELL_PRIO does not match CONFIG_SHELL_THREAD_PRIORITY."); - LOG_MODULE_REGISTER(shim_console, LOG_LEVEL_ERR); static const struct device *uart_shell_dev = @@ -169,13 +166,6 @@ static void shell_init_from_work(struct k_work *work) shell_init(shell_zephyr, uart_shell_dev, shell_cfg_flags, log_backend, level); - /* - * shell_init() always resets the priority back to the default. - * Update the priority as setup by the shimmed task code. - */ - k_thread_priority_set(shell_zephyr->ctx->tid, - EC_TASK_PRIORITY(EC_SHELL_PRIO)); - #if defined(CONFIG_UART_INTERRUPT_DRIVEN) uart_irq_rx_enable(uart_shell_dev); uart_irq_tx_enable(uart_shell_dev); diff --git a/zephyr/shim/src/hooks.c b/zephyr/shim/src/hooks.c index da981dea6b..3f11a578c5 100644 --- a/zephyr/shim/src/hooks.c +++ b/zephyr/shim/src/hooks.c @@ -165,17 +165,14 @@ int hook_call_deferred(const struct deferred_data *data, int us) k_work_cancel_delayable(work); } else if (us >= 0) { rv = k_work_reschedule(work, K_USEC(us)); - if (rv == -EINVAL) { - /* Already processing or completed. */ - return 0; - } else if (rv < 0) { + if (rv < 0) { work_queue_error(data, rv); } } else { return EC_ERROR_PARAM2; } - return rv; + return rv >= 0 ? EC_SUCCESS : rv; } /* diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig index 17cc06055d..d49577ac9b 100644 --- a/zephyr/test/drivers/Kconfig +++ b/zephyr/test/drivers/Kconfig @@ -17,6 +17,9 @@ config LINK_TEST_SUITE_AP_MUX_CONTROL config LINK_TEST_SUITE_AP_VDM_CONTROL bool "Link and test the ap_vdm_control tests" +config LINK_TEST_SUITE_BUTTON + bool "Link tests for common/button.c" + config LINK_TEST_SUITE_CHARGESPLASH bool "Link and test the chargesplash tests" @@ -35,18 +38,24 @@ config LINK_TEST_SUITE_KEYBOARD_SCAN config LINK_TEST_SUITE_LED_DRIVER bool "Link and test the led_driver tests" +config LINK_TEST_SUITE_LOCATE_CHIP_ALTS + bool "Link tests for alternate operations of the locate chip host cmd" + help + Compile a binary that allows the non herobrine paths of the locate + chip command to execute + config LINK_TEST_SUITE_MKBP bool "Link and test the mkbp tests" -config LINK_TEST_SUITE_SHIM_PWM_HC - bool "Link and run the shim pwm_hc tests" - config LINK_TEST_SUITE_POWER_HOST_SLEEP bool "Link and run the power/host_sleep.c specific tests" config LINK_TEST_SUITE_RT9490 bool "Link and test the rt9490 tests" +config LINK_TEST_SUITE_SHIM_PWM_HC + bool "Link and run the shim pwm_hc tests" + config LINK_TEST_SUITE_SHIM_RTC bool "Link and run the shim rtc tests" @@ -59,18 +68,24 @@ config LINK_TEST_SUITE_TIMER config LINK_TEST_SUITE_USB_MALFUNCTION_SINK bool "Link and test the usb_malfunction_sink tests" -config LINK_TEST_SUITE_USB_PORT_POWER_DUMB - bool "Link and test the usb_port_power_dumb tests" - config LINK_TEST_SUITE_USB_PD_DPS bool "Link and test the dps tests" +config LINK_TEST_SUITE_USB_PORT_POWER_DUMB + bool "Link and test the usb_port_power_dumb tests" + config LINK_TEST_SUITE_USB_RETIMER_FW_UPDATE bool "Link and test the usb_retimer_fw_update tests" config LINK_TEST_SUITE_USBC_ALT_MODE bool "Link and test the usbc_alt_mode tests" +config LINK_TEST_SUITE_USBC_OCP + bool "Link tests for common USBC OCP code" + +config LINK_TEST_SUITE_USBC_PPC + bool "Link tests for common USBC PPC code" + config LINK_TEST_SUITE_USBC_SVDM_DFP_ONLY bool "Link and test the usbc_svdm_dfp_only tests" @@ -82,19 +97,4 @@ config LINK_TEST_SUITE_USBC_VCONN_SWAP help Include the test suite exercising VCONN Swap behaviors in the binary. -config LINK_TEST_SUITE_USBC_OCP - bool "Link tests for common USBC OCP code" - -config LINK_TEST_SUITE_USBC_PPC - bool "Link tests for common USBC PPC code" - -config LINK_TEST_SUITE_LOCATE_CHIP_ALTS - bool "Link tests for alternate operations of the locate chip host cmd" - help - Compile a binary that allows the non herobrine paths of the locate - chip command to execute - -config LINK_TEST_SUITE_BUTTON - bool "Link tests for common/button.c" - source "Kconfig.zephyr" diff --git a/zephyr/test/drivers/button/src/main.c b/zephyr/test/drivers/button/src/main.c index 16591b7189..c26a62dfa1 100644 --- a/zephyr/test/drivers/button/src/main.c +++ b/zephyr/test/drivers/button/src/main.c @@ -3,6 +3,7 @@ * found in the LICENSE file. */ +#include <zephyr/fff.h> #include <zephyr/kernel.h> #include <zephyr/shell/shell.h> #include <zephyr/ztest.h> @@ -10,9 +11,19 @@ #include "button.h" #include "console.h" #include "hooks.h" +#include "mkbp_fifo.h" +#include "power.h" #include "test/drivers/test_state.h" #include "timer.h" +/* + * TODO (b/b/253284635) Timeouts here don't quite align with the button press + * duration. This is caused by an issue with the Zephyr scheduling for delayed + * work that's causing us to need to sleep longer than "reasonable". + */ + +FAKE_VOID_FUNC(chipset_reset, enum chipset_shutdown_reason); + static char *button_debug_state_strings[] = { "STATE_DEBUG_NONE", "STATE_DEBUG_CHECK", "STATE_STAGING", "STATE_DEBUG_MODE_ACTIVE", @@ -48,6 +59,11 @@ static void button_before(void *f) ((struct button_fixture *)f)->fake_time.val = 0; reset_button_debug_state(); button_init(); + /* Sleep for 30s to flush any pending tasks */ + k_sleep(K_SECONDS(30)); + mkbp_clear_fifo(); + + RESET_FAKE(chipset_reset); } ZTEST_SUITE(button, drivers_predicate_post_main, button_setup, button_before, @@ -106,3 +122,228 @@ ZTEST(button, test_fail_check_button_released_too_soon) pass_time(11000); ASSERT_DEBUG_STATE(STATE_DEBUG_NONE); } + +ZTEST(button, test_fail_check_button_stuck) +{ + /* Press both volume-up and volume-down for 0.9 seconds */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 30000")); + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 30000")); + + /* Let the deferred calls get run (800ms) */ + pass_time(800); + ASSERT_DEBUG_STATE(STATE_DEBUG_CHECK); + + /* Wait for the timeout, should put us in staging */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Do a plain sleep to force the error condition of waking up the + * handler too early (since the time isn't moving forward). + */ + k_msleep(11000); + + /* Now sleep and move the clock forward to timeout the debug process */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_NONE); +} + +ZTEST(button, test_activate_sysrq_path_then_timeout) +{ + /* Press both volume-up and volume-down for 1/2 second */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 10500")); + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 10500")); + + /* Let the deferred calls get run (800ms) */ + pass_time(800); + ASSERT_DEBUG_STATE(STATE_DEBUG_CHECK); + + /* Wait for the buttons to be released */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait a bit and check that we activated debug mode */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_MODE_ACTIVE); + + /* Press volume up button to put in sysrq_path */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 500")); + pass_time(800); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait for timeout and go into sysrq_path */ + pass_time(500); + ASSERT_DEBUG_STATE(STATE_SYSRQ_PATH); + + /* Now sleep and move the clock forward to timeout the debug process */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_NONE); +} + +ZTEST(button, test_activate_sysrq_path_4_times) +{ + /* Press both volume-up and volume-down for 1/2 second */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 10500")); + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 10500")); + + /* Let the deferred calls get run (800ms) */ + pass_time(800); + ASSERT_DEBUG_STATE(STATE_DEBUG_CHECK); + + /* Wait for the buttons to be released */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait a bit and check that we activated debug mode */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_MODE_ACTIVE); + + /* Press volume up button to put in sysrq_path */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 500")); + pass_time(800); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait for timeout and go into sysrq_path */ + pass_time(500); + ASSERT_DEBUG_STATE(STATE_SYSRQ_PATH); + + /* Press vup again (#2) */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 500")); + pass_time(800); + pass_time(500); + + /* Press vup again (#3) */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 500")); + pass_time(800); + pass_time(500); + + /* Press vup again (#4) */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 500")); + pass_time(800); + pass_time(500); + ASSERT_DEBUG_STATE(STATE_DEBUG_NONE); +} + +ZTEST(button, test_activate_sysrq_exec) +{ + uint32_t event_data = 0; + + /* Press both volume-up and volume-down for 1/2 second */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 10500")); + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 10500")); + + /* Let the deferred calls get run (800ms) */ + pass_time(800); + ASSERT_DEBUG_STATE(STATE_DEBUG_CHECK); + + /* Wait for the buttons to be released */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait a bit and check that we activated debug mode */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_MODE_ACTIVE); + + /* Press volume up button to put in sysrq_path */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 500")); + pass_time(800); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait for timeout and go into sysrq_path */ + pass_time(500); + ASSERT_DEBUG_STATE(STATE_SYSRQ_PATH); + + /* Now sleep and move the clock forward to timeout the debug process */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 500")); + pass_time(800); + pass_time(500); + ASSERT_DEBUG_STATE(STATE_DEBUG_NONE); + + /* Flush all the button events */ + while (mkbp_fifo_get_next_event((uint8_t *)&event_data, + EC_MKBP_EVENT_BUTTON) > 0) + ; + + /* Check for sysrq event */ + zassert_equal(4, mkbp_fifo_get_next_event((uint8_t *)&event_data, + EC_MKBP_EVENT_SYSRQ)); + zassert_equal((uint32_t)'x', event_data); +} + +ZTEST(button, test_activate_warm_reset_then_timeout) +{ + /* Press both volume-up and volume-down for 1/2 second */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 10500")); + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 10500")); + + /* Let the deferred calls get run (800ms) */ + pass_time(800); + ASSERT_DEBUG_STATE(STATE_DEBUG_CHECK); + + /* Wait for the buttons to be released */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait a bit and check that we activated debug mode */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_MODE_ACTIVE); + + /* Press volume down button to put in warm_reset_path */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 500")); + pass_time(800); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait for timeout and go into warm_reset_path */ + pass_time(500); + ASSERT_DEBUG_STATE(STATE_WARM_RESET_PATH); + + /* Now sleep and move the clock forward to timeout the debug process */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_NONE); +} + +ZTEST(button, test_activate_warm_reset_exec) +{ + /* Press both volume-up and volume-down for 1/2 second */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 10500")); + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 10500")); + + /* Let the deferred calls get run (800ms) */ + pass_time(800); + ASSERT_DEBUG_STATE(STATE_DEBUG_CHECK); + + /* Wait for the buttons to be released */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait a bit and check that we activated debug mode */ + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_MODE_ACTIVE); + + /* Press volume down button to put in warm_reset_path */ + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vdown 500")); + pass_time(800); + ASSERT_DEBUG_STATE(STATE_STAGING); + + /* Wait for timeout and go into warm_reset_path */ + pass_time(500); + ASSERT_DEBUG_STATE(STATE_WARM_RESET_PATH); + + /* Now sleep and move the clock forward to timeout the debug process. + * Doing this in two steps verifies that even after the handler executes + * "too early" we can still recover via the vup button that's coming + * next. This is caused by effectively, sleeping so the scheduler runs, + * but not ticking the clock forward yet until the next sleep. + */ + k_msleep(11000); + pass_time(11000); + + zassert_ok(shell_execute_cmd(get_ec_shell(), "button vup 500")); + pass_time(800); + ASSERT_DEBUG_STATE(STATE_STAGING); + + pass_time(11000); + ASSERT_DEBUG_STATE(STATE_DEBUG_NONE); + zassert_equal(1, chipset_reset_fake.call_count); + zassert_equal(CHIPSET_RESET_DBG_WARM_REBOOT, + chipset_reset_fake.arg0_val); +} diff --git a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c index fcc213d252..c73cf26f37 100644 --- a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c +++ b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c @@ -7,17 +7,23 @@ #include <zephyr/sys/slist.h> #include <zephyr/ztest.h> +#include "battery.h" #include "battery_smart.h" +#include "dps.h" #include "emul/emul_isl923x.h" #include "emul/emul_smart_battery.h" #include "emul/tcpc/emul_tcpci_partner_src.h" #include "system.h" +#include "task.h" #include "test/drivers/test_state.h" #include "test/drivers/utils.h" #include "usb_pd.h" #define BATTERY_NODE DT_NODELABEL(battery) +#define GPIO_BATT_PRES_ODL_PATH DT_PATH(named_gpios, ec_batt_pres_odl) +#define GPIO_BATT_PRES_ODL_PORT DT_GPIO_PIN(GPIO_BATT_PRES_ODL_PATH, gpios) + struct usb_attach_5v_3a_pd_source_fixture { struct tcpci_partner_data source_5v_3a; struct tcpci_src_emul_data src_ext; @@ -58,6 +64,15 @@ static void usb_attach_5v_3a_pd_source_after(void *data) disconnect_source_from_port(fixture->tcpci_emul, fixture->charger_emul); } +static void control_battery_present(bool present) +{ + const struct device *dev = + DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_BATT_PRES_ODL_PATH, gpios)); + + /* 0 means battery present */ + zassume_ok(gpio_emul_input_set(dev, GPIO_BATT_PRES_ODL_PORT, !present)); +} + ZTEST_SUITE(usb_attach_5v_3a_pd_source, drivers_predicate_post_main, usb_attach_5v_3a_pd_source_setup, usb_attach_5v_3a_pd_source_before, usb_attach_5v_3a_pd_source_after, NULL); @@ -68,8 +83,7 @@ ZTEST(usb_attach_5v_3a_pd_source, test_battery_is_charging) uint16_t battery_status; zassume_ok(sbat_emul_get_word_val(emul, SB_BATTERY_STATUS, - &battery_status), - NULL); + &battery_status)); zassert_equal(battery_status & STATUS_DISCHARGING, 0, "Battery is discharging: %d", battery_status); } @@ -137,8 +151,7 @@ ZTEST_F(usb_attach_5v_3a_pd_source, test_disconnect_battery_not_charging) disconnect_source_from_port(fixture->tcpci_emul, fixture->charger_emul); zassert_ok(sbat_emul_get_word_val(emul, SB_BATTERY_STATUS, - &battery_status), - NULL); + &battery_status)); zassert_equal(battery_status & STATUS_DISCHARGING, STATUS_DISCHARGING, "Battery is not discharging: %d", battery_status); } @@ -225,7 +238,7 @@ ZTEST(usb_attach_5v_3a_pd_source, batt_data->design_cap / 100) - 1; - zassert_true(system_can_boot_ap(), NULL); + zassert_true(system_can_boot_ap()); } ZTEST_F(usb_attach_5v_3a_pd_source, @@ -246,7 +259,7 @@ ZTEST_F(usb_attach_5v_3a_pd_source, disconnect_source_from_port(fixture->tcpci_emul, fixture->charger_emul); - zassert_false(system_can_boot_ap(), NULL); + zassert_false(system_can_boot_ap()); } ZTEST_F(usb_attach_5v_3a_pd_source, test_uvdm_ignored) @@ -282,3 +295,29 @@ ZTEST_F(usb_attach_5v_3a_pd_source, test_uvdm_ignored) zassert_false(tcpm_response, "Sent unstructured VDM to TCPM; TCPM did not ignore"); } + +ZTEST_F(usb_attach_5v_3a_pd_source, test_dps_battery_absent) +{ + control_battery_present(false); + zassert_false(battery_is_present(), "dps battery is present"); + task_wake(TASK_ID_DPS); + /* wait dps_config.t_check*/ + k_sleep(K_MSEC(5000)); + zassert_true(dps_get_flag() & DPS_FLAG_NO_BATTERY, + "DPS_FLAG_NO_BATTERY is set"); + control_battery_present(true); + zassert_true(battery_is_present(), "dps battery is not present"); +} + +ZTEST_F(usb_attach_5v_3a_pd_source, test_dps_enable) +{ + dps_enable(false); + zassert_false(dps_is_enabled()); + task_wake(TASK_ID_DPS); + /* wait dps_config.t_check*/ + k_sleep(K_MSEC(5000)); + zassert_true(dps_get_flag() & DPS_FLAG_DISABLED, + "DPS_FLAG_DISABLED is set"); + dps_enable(true); + zassert_true(dps_is_enabled()); +} diff --git a/zephyr/test/drivers/host_cmd/CMakeLists.txt b/zephyr/test/drivers/host_cmd/CMakeLists.txt index 286685089b..3ea78731f7 100644 --- a/zephyr/test/drivers/host_cmd/CMakeLists.txt +++ b/zephyr/test/drivers/host_cmd/CMakeLists.txt @@ -5,14 +5,18 @@ target_sources(app PRIVATE src/adc.c src/battery_cut_off.c + src/battery_display_soc.c + src/get_cmd_versions.c src/get_panic_info.c src/get_pd_port_caps.c + src/host_command_test_protocol.c src/host_event_commands.c src/host_event_commands_deprecated.c + src/host_request_expected_size.c src/keyboard_mkbp.c src/motion_sense.c - src/pd_control.c src/pd_chip_info.c + src/pd_control.c src/pd_log.c src/usb_pd_control.c src/usb_pd_host_cmd.c diff --git a/zephyr/test/drivers/host_cmd/src/battery_display_soc.c b/zephyr/test/drivers/host_cmd/src/battery_display_soc.c new file mode 100644 index 0000000000..029551a49b --- /dev/null +++ b/zephyr/test/drivers/host_cmd/src/battery_display_soc.c @@ -0,0 +1,32 @@ +/* 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/ztest.h> + +#include "battery.h" +#include "charge_state.h" +#include "host_command.h" +#include "test/drivers/test_state.h" + +ZTEST_USER(battery_display_soc, happy_path) +{ + const uint32_t full_charge_as_tenths = + CONFIG_BATT_HOST_FULL_FACTOR * 10; + const uint32_t host_shutdown_charge_as_tenths = + CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE * 10; + struct ec_response_display_soc response; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_RESPONSE(EC_CMD_DISPLAY_SOC, 0, response); + + zassert_ok(host_command_process(&args)); + + zassert_equal(args.response_size, sizeof(response)); + zassert_equal(response.display_soc, charge_get_display_charge()); + zassert_equal(response.full_factor, full_charge_as_tenths); + zassert_equal(response.shutdown_soc, host_shutdown_charge_as_tenths); +} + +ZTEST_SUITE(battery_display_soc, drivers_predicate_post_main, NULL, NULL, NULL, + NULL); diff --git a/zephyr/test/drivers/host_cmd/src/get_cmd_versions.c b/zephyr/test/drivers/host_cmd/src/get_cmd_versions.c new file mode 100644 index 0000000000..b935b69e46 --- /dev/null +++ b/zephyr/test/drivers/host_cmd/src/get_cmd_versions.c @@ -0,0 +1,55 @@ +/* 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/ztest.h> + +#include "battery.h" +#include "charge_state.h" +#include "host_command.h" +#include "test/drivers/test_state.h" + +ZTEST_USER(hc_get_cmd_versions, test_v0__both_versions) +{ + struct ec_params_get_cmd_versions params = { + .cmd = EC_CMD_GET_CMD_VERSIONS, + }; + struct ec_response_get_cmd_versions response; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_GET_CMD_VERSIONS, 0, response, params); + + zassert_ok(host_command_process(&args)); + zassert_equal(args.response_size, sizeof(response)); + zassert_equal(response.version_mask, EC_VER_MASK(0) | EC_VER_MASK(1)); +} + +ZTEST_USER(hc_get_cmd_versions, test_v1__only_v0) +{ + struct ec_params_get_cmd_versions_v1 params = { + .cmd = EC_CMD_HELLO, + }; + struct ec_response_get_cmd_versions response; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_GET_CMD_VERSIONS, 1, response, params); + + zassert_ok(host_command_process(&args)); + zassert_equal(args.response_size, sizeof(response)); + zassert_equal(response.version_mask, EC_VER_MASK(0)); +} + +ZTEST_USER(hc_get_cmd_versions, test_v1__bad_cmd) +{ + struct ec_params_get_cmd_versions_v1 params = { + /* Non-existent host-command */ + .cmd = UINT16_MAX, + }; + struct ec_response_get_cmd_versions response; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_GET_CMD_VERSIONS, 1, response, params); + + zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM); +} + +ZTEST_SUITE(hc_get_cmd_versions, drivers_predicate_post_main, NULL, NULL, NULL, + NULL); diff --git a/zephyr/test/drivers/host_cmd/src/host_command_test_protocol.c b/zephyr/test/drivers/host_cmd/src/host_command_test_protocol.c new file mode 100644 index 0000000000..9d29aeb7de --- /dev/null +++ b/zephyr/test/drivers/host_cmd/src/host_command_test_protocol.c @@ -0,0 +1,63 @@ +/* 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/ztest.h> + +#include "host_command.h" +#include "test/drivers/test_state.h" + +ZTEST_USER(hc_test_protocol, test_echo_max_buffer_size) +{ + struct ec_params_test_protocol params = { + /* Actual return length will only be sizeof(response) */ + .ret_len = UINT32_MAX, + .buf = { 0 }, + .ec_result = EC_SUCCESS, + }; + struct ec_response_test_protocol response; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND(EC_CMD_TEST_PROTOCOL, 0, response, params); + + /* Set first and last bytes of input array */ + params.buf[0] = 0x1; + params.buf[ARRAY_SIZE(params.buf) - 1] = 0x2; + + zassert_ok(host_command_process(&args)); + zassert_equal(args.response_size, sizeof(response)); + + /* Check contents are echoed back in response */ + zassert_mem_equal(params.buf, response.buf, sizeof(params.buf)); +} + +ZTEST_USER(hc_test_protocol, test_echo_min_buffer_size_failing_command) +{ + struct ec_params_test_protocol params = { + /* Don't want to have anything echoed back to us */ + .ret_len = 0, + .buf = { 0 }, + .ec_result = EC_ERROR_TRY_AGAIN, + }; + struct ec_response_test_protocol response; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND(EC_CMD_TEST_PROTOCOL, 0, response, params); + + /* + * Set first and last bytes of input array, neither will be written to + * response + */ + params.buf[0] = 0x1; + params.buf[ARRAY_SIZE(params.buf) - 1] = 0x2; + + zassert_equal(host_command_process(&args), params.ec_result); + zassert_equal(args.response_size, params.ret_len); + + /* Check contents were never echoed back as intended */ + zassert_not_equal(response.buf[0], params.buf[0]); + zassert_not_equal(response.buf[ARRAY_SIZE(response.buf) - 1], + params.buf[ARRAY_SIZE(params.buf) - 1]); +} + +ZTEST_SUITE(hc_test_protocol, drivers_predicate_post_main, NULL, NULL, NULL, + NULL); diff --git a/zephyr/test/drivers/host_cmd/src/host_request_expected_size.c b/zephyr/test/drivers/host_cmd/src/host_request_expected_size.c new file mode 100644 index 0000000000..30ff8c11b2 --- /dev/null +++ b/zephyr/test/drivers/host_cmd/src/host_request_expected_size.c @@ -0,0 +1,51 @@ +/* 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/ztest.h> + +#include "host_command.h" +#include "test/drivers/test_state.h" + +ZTEST(host_request_expected_size, test_mismatched_host_request_version) +{ + const struct ec_host_request request = { + /* Make version mismatch */ + .struct_version = EC_HOST_REQUEST_VERSION + 1, + }; + int ret = host_request_expected_size(&request); + + zassert_equal(ret, 0); +} + +ZTEST(host_request_expected_size, test_nonzero_reserved_bytes) +{ + const struct ec_host_request request = { + /* Make version match */ + .struct_version = EC_HOST_REQUEST_VERSION, + /* Set lsb to reserved bytes */ + .reserved = 1, + }; + int ret = host_request_expected_size(&request); + + zassert_equal(ret, 0); +} + +ZTEST(host_request_expected_size, test_data_len_added_to_response_size) +{ + const struct ec_host_request request = { + /* Make version match */ + .struct_version = EC_HOST_REQUEST_VERSION, + /* Set reserved bytes to 0 (required) */ + .reserved = 0, + /* Test data length max value to see changes in M/LSB */ + .data_len = UINT16_MAX, + }; + int ret = host_request_expected_size(&request); + + zassert_equal(ret, sizeof(request) + request.data_len); +} + +ZTEST_SUITE(host_request_expected_size, drivers_predicate_post_main, NULL, NULL, + NULL, NULL); diff --git a/zephyr/test/drivers/host_cmd/src/usb_pd_host_cmd.c b/zephyr/test/drivers/host_cmd/src/usb_pd_host_cmd.c index 5ff41da4bc..3afc90760a 100644 --- a/zephyr/test/drivers/host_cmd/src/usb_pd_host_cmd.c +++ b/zephyr/test/drivers/host_cmd/src/usb_pd_host_cmd.c @@ -138,5 +138,43 @@ ZTEST_USER(usb_pd_host_cmd, test_typec_discovery_invalid_args) zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM); } +ZTEST_USER(usb_pd_host_cmd, test_typec_control_invalid_args) +{ + struct ec_params_typec_control params = { + .port = 0, + .command = TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY, + }; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_TYPEC_CONTROL, 0, params); + + /* Setting the TBT UFP responses is not supported by default. */ + zassert_equal(host_command_process(&args), EC_RES_UNAVAILABLE); + + /* Neither is mux setting. */ + params.command = TYPEC_CONTROL_COMMAND_USB_MUX_SET; + zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM); + + /* This is not a valid enum value but should be representable. */ + params.command = 0xff; + zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM); +} + +ZTEST_USER(usb_pd_host_cmd, test_typec_status_invalid_args) +{ + struct ec_params_typec_status params = { + .port = 100, + }; + struct ec_response_typec_status response; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND(EC_CMD_TYPEC_STATUS, 0, response, params); + + /* An invalid port should result in an error. */ + zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM); + + params.port = 0; + args.response_max = sizeof(struct ec_response_typec_status) - 1; + zassert_equal(host_command_process(&args), EC_RES_RESPONSE_TOO_BIG); +} + ZTEST_SUITE(usb_pd_host_cmd, drivers_predicate_post_main, NULL, NULL, NULL, NULL); diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index 4518aa13cf..a7826df213 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -10,6 +10,7 @@ tests: - CONFIG_PLATFORM_EC_BATTERY_CUT_OFF=y - CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=y - CONFIG_PLATFORM_EC_CBI_EEPROM=y + - CONFIG_PLATFORM_EC_USB_PD_DPS=y drivers.default.mock_power: timeout: 240 extra_args: CONF_FILE="prj.conf;default/prj.conf" @@ -20,25 +21,11 @@ tests: - CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=y - CONFIG_POWER_SEQUENCE_MOCK=y - CONFIG_PLATFORM_EC_CBI_EEPROM=y - drivers.button: - extra_configs: - - CONFIG_LINK_TEST_SUITE_BUTTON=y - - CONFIG_PLATFORM_EC_CMD_BUTTON=y - - CONFIG_PLATFORM_EC_VOLUME_BUTTONS=y - - CONFIG_PLATFORM_EC_EMULATED_SYSRQ=y + - CONFIG_PLATFORM_EC_USB_PD_DPS=y drivers.anx7447: extra_args: CONF_FILE="prj.conf;anx7447/prj.conf" DTC_OVERLAY_FILE="./boards/native_posix.overlay;./anx7447/tcpc_policy.dts" extra_configs: - CONFIG_LINK_TEST_SUITE_ANX7447=y - drivers.host_cmd: - extra_configs: - - CONFIG_LINK_TEST_SUITE_HOST_COMMANDS=y - - CONFIG_PLATFORM_EC_BATTERY_CUT_OFF=y - - CONFIG_PLATFORM_EC_USB_PD_LOGGING=y - - CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=y - drivers.locate_chip: - extra_configs: - - CONFIG_LINK_TEST_SUITE_LOCATE_CHIP_ALTS=y drivers.ap_mux_control: extra_args: CONF_FILE="prj.conf;ap_mux_control/prj.conf" extra_configs: @@ -47,6 +34,13 @@ tests: extra_args: CONF_FILE="prj.conf;ap_vdm_control/prj.conf" extra_configs: - CONFIG_LINK_TEST_SUITE_AP_VDM_CONTROL=y + drivers.button: + timeout: 240 + extra_configs: + - CONFIG_LINK_TEST_SUITE_BUTTON=y + - CONFIG_PLATFORM_EC_CMD_BUTTON=y + - CONFIG_PLATFORM_EC_VOLUME_BUTTONS=y + - CONFIG_PLATFORM_EC_EMULATED_SYSRQ=y drivers.chargesplash: timeout: 240 extra_configs: @@ -60,6 +54,13 @@ tests: extra_args: CONF_FILE="prj.conf;dps/prj.conf" extra_configs: - CONFIG_LINK_TEST_SUITE_USB_PD_DPS=y + drivers.host_cmd: + extra_configs: + - CONFIG_LINK_TEST_SUITE_HOST_COMMANDS=y + - CONFIG_PLATFORM_EC_BATTERY_CUT_OFF=y + - CONFIG_PLATFORM_EC_USB_PD_LOGGING=y + - CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=y + - CONFIG_PLATFORM_EC_HOST_COMMAND_STATUS=y drivers.isl923x: extra_configs: - CONFIG_LINK_TEST_SUITE_ISL923X=y @@ -79,6 +80,9 @@ tests: extra_args: CONF_FILE="prj.conf;led_driver/prj.conf" DTC_OVERLAY_FILE="./boards/native_posix.overlay;./led_driver/led_pins.dts;./led_driver/led_policy.dts" extra_configs: - CONFIG_LINK_TEST_SUITE_LED_DRIVER=y + drivers.locate_chip: + extra_configs: + - CONFIG_LINK_TEST_SUITE_LOCATE_CHIP_ALTS=y drivers.mkbp: extra_configs: - CONFIG_LINK_TEST_SUITE_MKBP=y @@ -89,9 +93,6 @@ tests: tags: common mkbp - drivers.shim_pwm_hc: - extra_configs: - - CONFIG_LINK_TEST_SUITE_SHIM_PWM_HC=y drivers.power_host_sleep: extra_configs: - CONFIG_LINK_TEST_SUITE_POWER_HOST_SLEEP=y @@ -105,6 +106,9 @@ tests: extra_args: CONF_FILE="prj.conf;rt9490/prj.conf" DTC_OVERLAY_FILE="./boards/native_posix.overlay;./rt9490/charger.dts" extra_configs: - CONFIG_LINK_TEST_SUITE_RT9490=y + drivers.shim_pwm_hc: + extra_configs: + - CONFIG_LINK_TEST_SUITE_SHIM_PWM_HC=y drivers.shim_rtc: extra_configs: - CONFIG_LINK_TEST_SUITE_SHIM_RTC=y @@ -150,6 +154,12 @@ tests: - CONFIG_PLATFORM_EC_USB_PD_REQUIRE_AP_MODE_ENTRY=n - CONFIG_LINK_TEST_SUITE_USBC_ALT_MODE=y - CONFIG_POWER_SEQUENCE_MOCK=y + drivers.usbc_ocp: + extra_configs: + - CONFIG_LINK_TEST_SUITE_USBC_OCP=y + drivers.usbc_ppc: + extra_configs: + - CONFIG_LINK_TEST_SUITE_USBC_PPC=y drivers.usbc_svdm_dfp_only: extra_args: CONF_FILE="prj.conf;usbc_svdm_dfp_only/prj.conf" extra_configs: @@ -160,9 +170,3 @@ tests: drivers.usbc_vconn_swap: extra_configs: - CONFIG_LINK_TEST_SUITE_USBC_VCONN_SWAP=y - drivers.usbc_ocp: - extra_configs: - - CONFIG_LINK_TEST_SUITE_USBC_OCP=y - drivers.usbc_ppc: - extra_configs: - - CONFIG_LINK_TEST_SUITE_USBC_PPC=y 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); diff --git a/zephyr/test/qcom_power/boards/native_posix.overlay b/zephyr/test/qcom_power/boards/native_posix.overlay index cda68b4b4c..820db360b7 100644 --- a/zephyr/test/qcom_power/boards/native_posix.overlay +++ b/zephyr/test/qcom_power/boards/native_posix.overlay @@ -113,6 +113,11 @@ flags = <GPIO_INT_EDGE_BOTH>; handler = "power_signal_interrupt"; }; + int_power_button: power_button { + irq-pin = <&gpio_ec_pwr_btn_odl>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "power_button_interrupt"; + }; }; gpio1: gpio@101 { diff --git a/zephyr/test/qcom_power/prj.conf b/zephyr/test/qcom_power/prj.conf index 0fb49fdf7c..d741784117 100644 --- a/zephyr/test/qcom_power/prj.conf +++ b/zephyr/test/qcom_power/prj.conf @@ -2,38 +2,40 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +CONFIG_ASSERT=y +CONFIG_TEST=y CONFIG_ZTEST=y CONFIG_ZTEST_ASSERT_VERBOSE=1 CONFIG_ZTEST_MOCKING=y CONFIG_ZTEST_NEW_API=y -CONFIG_TEST=y -CONFIG_ASSERT=y # Print logs from Zephyr LOG_MODULE to stdout CONFIG_NATIVE_UART_0_ON_STDINOUT=y -CONFIG_PLATFORM_EC=y CONFIG_CROS_EC=y -CONFIG_SHIMMED_TASKS=y -CONFIG_LOG=y CONFIG_EMUL=y -CONFIG_GPIO=y -CONFIG_GPIO_EMUL=y CONFIG_EMUL_CROS_FLASH=y CONFIG_FLASH=y +CONFIG_GPIO=y +CONFIG_GPIO_EMUL=y +CONFIG_LOG=y +CONFIG_PLATFORM_EC=y +CONFIG_SERIAL=y CONFIG_SHELL_BACKEND_DUMMY=y CONFIG_SHELL_BACKEND_DUMMY_BUF_SIZE=2000 CONFIG_SHELL_BACKEND_SERIAL=n -CONFIG_SERIAL=y +CONFIG_SHIMMED_TASKS=y # QCom power sequencing -CONFIG_PLATFORM_EC_POWERSEQ=y CONFIG_AP_ARM_QUALCOMM_SC7280=y -CONFIG_PLATFORM_EC_POWERSEQ_SC7280=y -CONFIG_PLATFORM_EC_POWERSEQ_HOST_SLEEP=y +CONFIG_PLATFORM_EC_CHIPSET_RESUME_INIT_HOOK=y +CONFIG_PLATFORM_EC_EXTPOWER=y +CONFIG_PLATFORM_EC_EXTPOWER_GPIO=y +CONFIG_PLATFORM_EC_HOSTCMD=y CONFIG_PLATFORM_EC_LID_SWITCH=y -CONFIG_PLATFORM_EC_SWITCHCAP_GPIO=y +CONFIG_PLATFORM_EC_POWERSEQ=y +CONFIG_PLATFORM_EC_POWERSEQ_HOST_SLEEP=y +CONFIG_PLATFORM_EC_POWERSEQ_SC7280=y CONFIG_PLATFORM_EC_POWER_BUTTON=y -CONFIG_PLATFORM_EC_HOSTCMD=y -CONFIG_PLATFORM_EC_EXTPOWER_GPIO=y -CONFIG_PLATFORM_EC_EXTPOWER=y +CONFIG_PLATFORM_EC_POWER_SLEEP_FAILURE_DETECTION=y +CONFIG_PLATFORM_EC_SWITCHCAP_GPIO=y diff --git a/zephyr/test/qcom_power/src/main.c b/zephyr/test/qcom_power/src/main.c index 97743c90bf..92bbe851c9 100644 --- a/zephyr/test/qcom_power/src/main.c +++ b/zephyr/test/qcom_power/src/main.c @@ -10,6 +10,9 @@ #include <zephyr/drivers/gpio/gpio_emul.h> #include <zephyr/drivers/gpio.h> #include <zephyr/shell/shell_dummy.h> +#include <zephyr/fff.h> + +#include <setjmp.h> #include "gpio_signal.h" #include "power/qcom.h" @@ -19,12 +22,14 @@ #include "console.h" #include "task.h" #include "hooks.h" +#include "host_command.h" #define AP_RST_L_NODE DT_PATH(named_gpios, ap_rst_l) #define POWER_GOOD_NODE DT_PATH(named_gpios, mb_power_good) #define AP_SUSPEND_NODE DT_PATH(named_gpios, ap_suspend) #define SWITCHCAP_PG_NODE DT_PATH(named_gpios, switchcap_pg_int_l) #define PMIC_RESIN_L_NODE DT_PATH(named_gpios, pmic_resin_l) +#define EC_PWR_BTN_ODL_NODE DT_PATH(named_gpios, ec_pwr_btn_odl) static int chipset_reset_count; @@ -34,6 +39,11 @@ static void do_chipset_reset(void) } DECLARE_HOOK(HOOK_CHIPSET_RESET, do_chipset_reset, HOOK_PRIO_DEFAULT); +DEFINE_FFF_GLOBALS; + +FAKE_VALUE_FUNC(int, system_can_boot_ap); +FAKE_VALUE_FUNC(int, battery_wait_for_stable); + /* Tests the chipset_ap_rst_interrupt() handler when in S3. * * When the system is in S3, and ap_rst_l is pulsed 1-3 times then @@ -45,16 +55,11 @@ static void do_chipset_ap_rst_interrupt_in_s3(int times) { static const struct device *ap_rst_dev = DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios)); - static const struct device *power_good_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); static const struct device *ap_suspend_dev = DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); /* Preconditions */ power_signal_enable_interrupt(GPIO_AP_SUSPEND); - power_signal_enable_interrupt(GPIO_AP_RST_L); - zassert_ok(gpio_emul_input_set(power_good_dev, - DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1)); zassert_ok(gpio_emul_input_set(ap_suspend_dev, DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 1)); power_set_state(POWER_S3); @@ -122,22 +127,6 @@ static void do_chipset_ap_rst_interrupt_in_s0(int times) { static const struct device *ap_rst_dev = DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios)); - static const struct device *power_good_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); - static const struct device *ap_suspend_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); - - /* Preconditions */ - zassert_ok(gpio_emul_input_set(power_good_dev, - DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1)); - zassert_ok(gpio_emul_input_set(ap_suspend_dev, - DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0)); - power_set_state(POWER_S0); - power_signal_disable_interrupt(GPIO_AP_SUSPEND); - power_signal_enable_interrupt(GPIO_AP_RST_L); - task_wake(TASK_ID_CHIPSET); - k_sleep(K_MSEC(10)); - zassert_equal(power_get_state(), POWER_S0); shell_backend_dummy_clear_output(get_ec_shell()); chipset_reset_count = 0; @@ -188,35 +177,9 @@ ZTEST(qcom_power, test_notify_chipset_reset_s0) /* Call chipset_reset, don't provide signals from AP. Verify logs. */ ZTEST(qcom_power, test_chipset_reset_timeout) { - static const struct device *ap_rst_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios)); - static const struct device *power_good_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); - static const struct device *ap_suspend_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); - static const struct device *switchcap_pg_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(SWITCHCAP_PG_NODE, gpios)); const char *buffer; size_t buffer_size; - /* Preconditions */ - power_signal_disable_interrupt(GPIO_AP_SUSPEND); - power_signal_enable_interrupt(GPIO_AP_RST_L); - zassert_ok(gpio_emul_input_set(power_good_dev, - DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1)); - zassert_ok(gpio_emul_input_set(ap_suspend_dev, - DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0)); - zassert_ok(gpio_emul_input_set(ap_rst_dev, - DT_GPIO_PIN(AP_RST_L_NODE, gpios), 1)); - zassert_ok(gpio_emul_input_set( - switchcap_pg_dev, DT_GPIO_PIN(SWITCHCAP_PG_NODE, gpios), 1)); - power_set_state(POWER_S0); - task_wake(TASK_ID_CHIPSET); - /* Wait for timeout AP_RST_TRANSITION_TIMEOUT. */ - k_sleep(K_MSEC(500)); - zassert_equal(power_get_state(), POWER_S0); - zassert_equal(power_has_signals(POWER_SIGNAL_MASK(0)), 0); - /* Reset. The reason doesn't really matter. */ shell_backend_dummy_clear_output(get_ec_shell()); chipset_reset(CHIPSET_RESET_KB_WARM_REBOOT); @@ -258,37 +221,11 @@ ZTEST(qcom_power, test_chipset_reset_success) { static const struct device *ap_rst_dev = DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios)); - static const struct device *power_good_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); - static const struct device *ap_suspend_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); - static const struct device *switchcap_pg_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(SWITCHCAP_PG_NODE, gpios)); static const struct device *pmic_resin_l_dev = DEVICE_DT_GET(DT_GPIO_CTLR(PMIC_RESIN_L_NODE, gpios)); const char *buffer; size_t buffer_size; - /* Preconditions */ - power_signal_disable_interrupt(GPIO_AP_SUSPEND); - power_signal_enable_interrupt(GPIO_AP_RST_L); - zassert_ok(gpio_emul_input_set(power_good_dev, - DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1)); - zassert_ok(gpio_emul_input_set(ap_suspend_dev, - DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0)); - zassert_ok(gpio_emul_input_set(ap_rst_dev, - DT_GPIO_PIN(AP_RST_L_NODE, gpios), 1)); - zassert_ok(gpio_emul_input_set( - switchcap_pg_dev, DT_GPIO_PIN(SWITCHCAP_PG_NODE, gpios), 1)); - zassert_ok(gpio_pin_set(pmic_resin_l_dev, - DT_GPIO_PIN(PMIC_RESIN_L_NODE, gpios), 1)); - power_set_state(POWER_S0); - task_wake(TASK_ID_CHIPSET); - /* Wait for timeout AP_RST_TRANSITION_TIMEOUT. */ - k_sleep(K_MSEC(500)); - zassert_equal(power_get_state(), POWER_S0); - zassert_equal(power_has_signals(POWER_SIGNAL_MASK(0)), 0); - /* Setup callback. */ gpio_init_callback(&gpio_callback, warm_reset_callback, BIT(DT_GPIO_PIN(PMIC_RESIN_L_NODE, gpios))); @@ -313,6 +250,217 @@ ZTEST(qcom_power, test_chipset_reset_success) zassert_equal(power_get_state(), POWER_S0); } +/* Sent the host command, set the gpio, wait for transition to S3. */ +ZTEST(qcom_power, test_request_sleep) +{ + static const struct device *ap_suspend_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); + struct ec_params_host_sleep_event params = { + .sleep_event = HOST_SLEEP_EVENT_S3_SUSPEND, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS( + EC_CMD_HOST_SLEEP_EVENT, UINT8_C(0), params); + + zassert_ok(host_command_process(&args)); + zassert_ok(gpio_emul_input_set(ap_suspend_dev, + DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 1)); + k_sleep(K_SECONDS(16)); + zassert_equal(power_get_state(), POWER_S3); + zassert_false(host_is_event_set(EC_HOST_EVENT_HANG_DETECT)); +} + +/* Sent the host command, don't set the gpio, look for host event. */ +ZTEST(qcom_power, test_request_sleep_timeout) +{ + const char *buffer; + size_t buffer_size; + struct ec_params_host_sleep_event params = { + .sleep_event = HOST_SLEEP_EVENT_S3_SUSPEND, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS( + EC_CMD_HOST_SLEEP_EVENT, UINT8_C(0), params); + + shell_backend_dummy_clear_output(get_ec_shell()); + zassert_ok(host_command_process(&args)); + k_sleep(K_SECONDS(16)); + zassert_equal(power_get_state(), POWER_S0); + buffer = shell_backend_dummy_get_output(get_ec_shell(), &buffer_size); + zassert_true(strstr(buffer, "Detected sleep hang!") != NULL, + "Invalid console output %s", buffer); + zassert_true(host_is_event_set(EC_HOST_EVENT_HANG_DETECT)); +} + +ZTEST(qcom_power, test_chipset_force_shutdown) +{ + chipset_force_shutdown(CHIPSET_SHUTDOWN_G3); + k_sleep(K_SECONDS(11)); + zassert_equal(power_get_state(), POWER_G3); +} + +ZTEST(qcom_power, test_power_button) +{ + static const struct device *ec_pwr_btn_odl_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(EC_PWR_BTN_ODL_NODE, gpios)); + + power_set_state(POWER_G3); + k_sleep(K_MSEC(10)); + zassert_equal(power_get_state(), POWER_G3); + + zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev, + DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios), + 0)); + k_sleep(K_MSEC(100)); + zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev, + DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios), + 1)); + k_sleep(K_MSEC(500)); + zassert_equal(power_get_state(), POWER_S0); +} + +ZTEST(qcom_power, test_power_button_no_power_good) +{ + static const struct device *ec_pwr_btn_odl_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(EC_PWR_BTN_ODL_NODE, gpios)); + static const struct device *power_good_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); + + zassert_ok(gpio_emul_input_set(power_good_dev, + DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 0)); + power_set_state(POWER_G3); + k_sleep(K_MSEC(10)); + zassert_equal(power_get_state(), POWER_G3); + + zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev, + DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios), + 0)); + k_sleep(K_MSEC(100)); + zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev, + DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios), + 1)); + k_sleep(K_MSEC(900)); + zassert_equal(power_get_state(), POWER_S5, "power_state=%d", + power_get_state()); +} + +ZTEST(qcom_power, test_power_button_battery_low) +{ + static const struct device *ec_pwr_btn_odl_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(EC_PWR_BTN_ODL_NODE, gpios)); + + RESET_FAKE(system_can_boot_ap); + system_can_boot_ap_fake.return_val = 0; + + power_set_state(POWER_G3); + k_sleep(K_MSEC(10)); + zassert_equal(power_get_state(), POWER_G3); + + zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev, + DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios), + 0)); + k_sleep(K_MSEC(100)); + zassert_ok(gpio_emul_input_set(ec_pwr_btn_odl_dev, + DT_GPIO_PIN(EC_PWR_BTN_ODL_NODE, gpios), + 1)); + /* > CAN_BOOT_AP_CHECK_TIMEOUT + CAN_BOOT_AP_CHECK_WAIT */ + k_sleep(K_MSEC(1800)); + zassert_equal(power_get_state(), POWER_S5); +} + +ZTEST(qcom_power, test_host_sleep_event_resume) +{ + static const struct device *ap_suspend_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); + struct ec_params_host_sleep_event params = { + .sleep_event = HOST_SLEEP_EVENT_S3_RESUME, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS( + EC_CMD_HOST_SLEEP_EVENT, UINT8_C(0), params); + + /* Get into S3 first */ + power_signal_enable_interrupt(GPIO_AP_SUSPEND); + zassert_ok(gpio_emul_input_set(ap_suspend_dev, + DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 1)); + power_set_state(POWER_S3); + task_wake(TASK_ID_CHIPSET); + k_sleep(K_MSEC(10)); + zassert_equal(power_get_state(), POWER_S3); + + /* Exit suspend via gpio. */ + zassert_ok(gpio_emul_input_set(ap_suspend_dev, + DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0)); + k_sleep(K_MSEC(100)); + zassert_equal(power_get_state(), POWER_S0, "power_state=%d", + power_get_state()); + + /* Call host command to notify ec resume is done. */ + zassert_ok(host_command_process(&args)); + k_sleep(K_MSEC(10)); + zassert_equal(power_get_state(), POWER_S0, "power_state=%d", + power_get_state()); + + /* Check that AP_SUSPEND interrupts are disabled & we are in S0. */ + zassert_ok(gpio_emul_input_set(ap_suspend_dev, + DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 1)); + k_sleep(K_MSEC(100)); + zassert_equal(power_get_state(), POWER_S0); +} + +static jmp_buf assert_jumpdata; +static int num_asserts; + +void assert_post_action(const char *file, unsigned int line) +{ + ++num_asserts; + longjmp(assert_jumpdata, 1); +} + +ZTEST(qcom_power, test_invalid_power_state) +{ + if (setjmp(assert_jumpdata) == 0) { + power_handle_state(POWER_S4); + zassert_unreachable(); + } + zassert_equal(num_asserts, 1); +} + +void start_in_s0(void *fixture) +{ + static const struct device *ap_rst_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios)); + static const struct device *power_good_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); + static const struct device *ap_suspend_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); + static const struct device *switchcap_pg_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(SWITCHCAP_PG_NODE, gpios)); + static const struct device *pmic_resin_l_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(PMIC_RESIN_L_NODE, gpios)); + + RESET_FAKE(system_can_boot_ap); + system_can_boot_ap_fake.return_val = 1; + + power_signal_disable_interrupt(GPIO_AP_SUSPEND); + power_signal_enable_interrupt(GPIO_AP_RST_L); + zassert_ok(gpio_emul_input_set(power_good_dev, + DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1)); + zassert_ok(gpio_emul_input_set(ap_suspend_dev, + DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0)); + zassert_ok(gpio_emul_input_set(ap_rst_dev, + DT_GPIO_PIN(AP_RST_L_NODE, gpios), 1)); + zassert_ok(gpio_emul_input_set( + switchcap_pg_dev, DT_GPIO_PIN(SWITCHCAP_PG_NODE, gpios), 1)); + zassert_ok(gpio_pin_set(pmic_resin_l_dev, + DT_GPIO_PIN(PMIC_RESIN_L_NODE, gpios), 1)); + power_set_state(POWER_S0); + power_signal_interrupt(GPIO_AP_SUSPEND); + task_wake(TASK_ID_CHIPSET); + /* Wait for timeout AP_RST_TRANSITION_TIMEOUT. */ + k_sleep(K_MSEC(500)); + zassert_equal(power_get_state(), POWER_S0, "power_state=%d", + power_get_state()); + zassert_equal(power_has_signals(POWER_SIGNAL_MASK(0)), 0); +} + void qcom_cleanup(void *fixture) { if (gpio_callback.handler != NULL) { @@ -321,15 +469,10 @@ void qcom_cleanup(void *fixture) gpio_remove_callback(pmic_resin_l_dev, &gpio_callback); gpio_callback.handler = NULL; } + host_clear_events(EC_HOST_EVENT_MASK(EC_HOST_EVENT_HANG_DETECT)); } -ZTEST_SUITE(qcom_power, NULL, NULL, NULL, qcom_cleanup, NULL); - -/* Wait until battery is totally stable */ -int battery_wait_for_stable(void) -{ - return EC_SUCCESS; -} +ZTEST_SUITE(qcom_power, NULL, NULL, start_in_s0, qcom_cleanup, NULL); void test_main(void) { |