summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Chen <yulunchen@google.com>2023-05-17 03:32:45 +0000
committerIvan Chen <yulunchen@google.com>2023-05-17 03:32:45 +0000
commitd7c9c6beb03ee5725232b9ac3bfe4825e1e227cb (patch)
tree3a0d6776c0e76e325d1b087cd51a850cb871358e
parent8641442366bd7c2c133e302a57f904dfac3c896b (diff)
parentb34dc2ae9022e2fbb57ae6477891ff32954c62fd (diff)
downloadchrome-ec-firmware-brya-14505.B-main.tar.gz
Merge remote-tracking branch cros/main into firmware-brya-14505.B-mainfirmware-brya-14505.B-main
Generated by: util/update_release_branch.py --board brya firmware-brya-14505.B-main Relevant changes: git log --oneline 8641442366..b34dc2ae90 -- board/brya board/brya util/getversion.sh BRANCH=None TEST=`make -j buildall` Force-Relevant-Builds: all Change-Id: I63149b4c1782b3ed57f2556755901c21f5f1e3e9 Signed-off-by: Ivan Chen <yulunchen@google.com>
-rw-r--r--Makefile15
-rw-r--r--PRESUBMIT.cfg1
-rw-r--r--board/agah/board.h3
-rw-r--r--board/hades/board.h3
-rw-r--r--board/hatch_fp/build.mk2
-rw-r--r--board/marasov/board.h2
-rw-r--r--board/marasov/usbc_config.c7
-rw-r--r--board/nocturne_fp/build.mk2
-rw-r--r--board/nucleo-dartmonkey/build.mk1
-rw-r--r--board/nucleo-f412zg/build.mk1
-rw-r--r--board/nucleo-h743zi/build.mk1
-rw-r--r--board/omnigul/board.h13
-rw-r--r--board/taranza/led.c3
-rw-r--r--board/vell/fw_config.c36
-rw-r--r--board/vell/fw_config.h47
-rw-r--r--chip/host/trng.c5
-rw-r--r--chip/npcx/build.mk1
-rw-r--r--chip/npcx/gpio-npcx9.c33
-rw-r--r--chip/npcx/registers.h50
-rw-r--r--chip/npcx/trng.c251
-rw-r--r--chip/stm32/trng.c71
-rw-r--r--common/body_detection.c13
-rw-r--r--common/build.mk3
-rw-r--r--common/charge_state_v2.c6
-rw-r--r--common/motion_sense.c41
-rw-r--r--common/motion_sense_fifo.c5
-rw-r--r--common/trng.c82
-rw-r--r--common/usbc/usb_mode.c4
-rw-r--r--core/cortex-m/cpu.c4
-rw-r--r--core/cortex-m/task.c3
-rw-r--r--core/cortex-m0/task.c3
-rw-r--r--core/minute-ia/task.c3
-rw-r--r--core/nds32/task.c8
-rw-r--r--core/riscv-rv32i/task.c8
-rw-r--r--crypto/build.mk8
-rw-r--r--crypto/elliptic_curve_key.cc24
-rw-r--r--docs/chromeos-ec-firmware-test-requirements.md3
-rw-r--r--docs/zephyr/zephyr_troubleshooting.md14
-rw-r--r--driver/battery/smart.c23
-rw-r--r--driver/ppc/ktu1125.c10
-rw-r--r--driver/ppc/rt1739.c2
-rw-r--r--driver/ppc/rt1739.h2
-rw-r--r--driver/retimer/anx7483.c2
-rw-r--r--driver/retimer/nb7v904m.c2
-rw-r--r--driver/retimer/pi3dpx1207.c2
-rw-r--r--driver/retimer/ps8802.c2
-rw-r--r--driver/retimer/ps8818.c2
-rw-r--r--driver/retimer/tusb544.c2
-rw-r--r--driver/tcpm/anx7447.c2
-rw-r--r--driver/tcpm/anx74xx.c2
-rw-r--r--driver/tcpm/anx7688.c2
-rw-r--r--driver/tcpm/ps8xxx.c2
-rw-r--r--driver/tcpm/rt1718s.c28
-rw-r--r--driver/tcpm/rt1718s.h9
-rw-r--r--driver/tcpm/tcpci.c2
-rw-r--r--driver/usb_mux/amd_fp5.c2
-rw-r--r--driver/usb_mux/amd_fp6.c2
-rw-r--r--driver/usb_mux/anx3443.c2
-rw-r--r--driver/usb_mux/anx7440.c2
-rw-r--r--driver/usb_mux/anx7451.c2
-rw-r--r--driver/usb_mux/it5205.c2
-rw-r--r--driver/usb_mux/pi3usb3x532.c2
-rw-r--r--driver/usb_mux/ps8740.c2
-rw-r--r--driver/usb_mux/ps8743.c2
-rw-r--r--driver/usb_mux/ps8822.c2
-rw-r--r--driver/usb_mux/tusb1064.c2
-rw-r--r--driver/usb_mux/usb_mux.c3
-rw-r--r--include/charge_state.h6
-rw-r--r--include/charge_state_v2.h9
-rw-r--r--include/config.h33
-rw-r--r--include/crypto/elliptic_curve_key.h20
-rw-r--r--include/lid_switch.h6
-rw-r--r--include/system.h6
-rw-r--r--include/test_util.h14
-rw-r--r--include/trng.h7
-rw-r--r--test/boringssl_crypto.cc66
-rw-r--r--test/boringssl_crypto.tasklist9
-rw-r--r--test/build.mk3
-rwxr-xr-xtest/run_device_tests.py2
-rw-r--r--test/sbs_charging_v2.c16
-rw-r--r--test/test_config.h4
-rw-r--r--test/unaligned_access.cc157
-rw-r--r--test/unaligned_access.tasklist9
-rw-r--r--third_party/boringssl/common/build.mk8
-rw-r--r--third_party/boringssl/common/sysrand.c20
-rwxr-xr-xutil/check_low_coverage_reason.py58
-rwxr-xr-xutil/ec_openocd.py13
-rw-r--r--zephyr/Kconfig.battery43
-rw-r--r--zephyr/emul/emul_amd_fp6.c18
-rw-r--r--zephyr/include/cros/thermistor/thermistor.dtsi81
-rw-r--r--zephyr/include/emul/emul_amd_fp6.h9
-rw-r--r--zephyr/program/corsola/include/variant_db_detection.h15
-rw-r--r--zephyr/program/corsola/npcx_adc.dtsi1
-rw-r--r--zephyr/program/corsola/src/npcx_usbc.c10
-rw-r--r--zephyr/program/corsola/src/usb_pd_policy.c13
-rw-r--r--zephyr/program/corsola/src/usbc.c6
-rw-r--r--zephyr/program/corsola/starmie/CMakeLists.txt5
-rw-r--r--zephyr/program/corsola/starmie/project.conf4
-rw-r--r--zephyr/program/corsola/starmie/project.overlay56
-rw-r--r--zephyr/program/corsola/starmie/src/base_detect.c151
-rw-r--r--zephyr/program/corsola/starmie/src/ppc.c8
-rw-r--r--zephyr/program/corsola/voltorb/project.conf1
-rw-r--r--zephyr/program/nissa/CMakeLists.txt1
-rw-r--r--zephyr/program/nissa/craask/src/led.c2
-rw-r--r--zephyr/program/nissa/joxer/cbi.dtsi21
-rw-r--r--zephyr/program/nissa/joxer/motionsense.dtsi6
-rw-r--r--zephyr/program/nissa/joxer/src/form_factor.c39
-rw-r--r--zephyr/program/nissa/uldren/motionsense.dtsi8
-rw-r--r--zephyr/program/nissa/yavilla/gpio.dtsi18
-rw-r--r--zephyr/program/nissa/yavilla/motionsense.dtsi148
-rw-r--r--zephyr/program/nissa/yavilla/overlay.dtsi34
-rw-r--r--zephyr/program/nissa/yavilla/project.conf16
-rw-r--r--zephyr/program/nissa/yavilla/project.overlay1
-rw-r--r--zephyr/program/nissa/yavilla/src/board.c36
-rw-r--r--zephyr/program/skyrim/winterhold/project.conf1
-rw-r--r--zephyr/shim/include/config_chip.h6
-rw-r--r--zephyr/test/drivers/amd_fp6_usb_mux/src/amd_fp6_usb_mux_test.c2
-rw-r--r--zephyr/test/drivers/common_charger/src/test_charge_state_v2.c18
-rw-r--r--zephyr/test/drivers/usbc_usb4_mode/src/usbc_usb4_mode.c38
-rw-r--r--zephyr/test/kingler/CMakeLists.txt65
-rw-r--r--zephyr/test/kingler/Kconfig11
-rw-r--r--zephyr/test/kingler/common.dtsi112
-rw-r--r--zephyr/test/kingler/kingler.default.overlay1
-rw-r--r--zephyr/test/kingler/kingler.usbc.conf28
-rw-r--r--zephyr/test/kingler/kingler.usbc.overlay118
-rw-r--r--zephyr/test/kingler/prj.conf4
-rw-r--r--zephyr/test/kingler/src/fakes.c15
-rw-r--r--zephyr/test/kingler/src/kingler_usbc.c78
-rw-r--r--zephyr/test/kingler/src/usb_port_count.c90
-rw-r--r--zephyr/test/kingler/testcase.yaml13
-rw-r--r--zephyr/test/krabby/src/usbc_config.c23
-rw-r--r--zephyr/zmake/zmake/toolchains.py3
132 files changed, 2324 insertions, 420 deletions
diff --git a/Makefile b/Makefile
index a8b282c613..812b5dc2c4 100644
--- a/Makefile
+++ b/Makefile
@@ -290,6 +290,12 @@ include test/build.mk
include util/build.mk
include util/lock/build.mk
+
+ifeq ($(CONFIG_BORINGSSL_CRYPTO), y)
+include third_party/boringssl/common/build.mk
+include crypto/build.mk
+endif
+
includes+=$(includes-y)
# Wrapper for fetching all the sources relevant to this build
@@ -326,6 +332,11 @@ all-obj-$(1)+=$(call objs_from_dir_p,fuzz,$(PROJECT),$(1))
else
all-obj-$(1)+=$(call objs_from_dir_p,test,$(PROJECT),$(1))
endif
+ifeq ($(CONFIG_BORINGSSL_CRYPTO), y)
+all-obj-$(1)+= \
+ $(call objs_from_dir_p,third_party/boringssl/common,boringssl,$(1))
+all-obj-$(1)+= $(call objs_from_dir_p,crypto,crypto,$(1))
+endif
endef
# Get all sources to build
@@ -372,6 +383,10 @@ dirs+=builtin
else
dirs+=libc
endif
+ifeq ($(CONFIG_BORINGSSL_CRYPTO), y)
+dirs+=third_party/boringssl/common
+dirs+=crypto
+endif
common_dirs=util
ifeq ($(custom-ro_objs-y),)
diff --git a/PRESUBMIT.cfg b/PRESUBMIT.cfg
index 8cc7ddf2cd..c925185270 100644
--- a/PRESUBMIT.cfg
+++ b/PRESUBMIT.cfg
@@ -38,3 +38,4 @@ twister_test_tags = util/twister_tags.py --validate-files ${PRESUBMIT_FILES}
check_zephyr_project_config = util/check_zephyr_project_config.py -d ${PRESUBMIT_FILES}
zephyr_check_compliance = util/zephyr_check_compliance.py ${PRESUBMIT_COMMIT}
zephyr_check_testcase_yaml = ./util/zephyr_check_testcase_yaml.py --commit ${PRESUBMIT_COMMIT} ${PRESUBMIT_FILES}
+low_coverage_reason = ./util/check_low_coverage_reason.py ${PRESUBMIT_COMMIT}
diff --git a/board/agah/board.h b/board/agah/board.h
index ba2889130d..b0a6077f6d 100644
--- a/board/agah/board.h
+++ b/board/agah/board.h
@@ -155,6 +155,9 @@
#define CONFIG_ADC_CHANNELS_RUNTIME_CONFIG
+/* Give SEQ_EC_DSW_PWROK higher priority to reduce latency for PCH_PWROK. */
+#define NPCX_MIWU0_GROUP_F 1
+
#ifndef __ASSEMBLER__
#include "gpio_signal.h" /* needed by registers.h */
diff --git a/board/hades/board.h b/board/hades/board.h
index 31baee2038..86f24eb47c 100644
--- a/board/hades/board.h
+++ b/board/hades/board.h
@@ -160,6 +160,9 @@
#define CONFIG_ADC_CHANNELS_RUNTIME_CONFIG
+/* Give SEQ_EC_DSW_PWROK IRQ higher priority to reduce latency for PCH_PWROK. */
+#define NPCX_MIWU0_GROUP_F 1
+
#ifndef __ASSEMBLER__
#include "gpio_signal.h" /* needed by registers.h */
diff --git a/board/hatch_fp/build.mk b/board/hatch_fp/build.mk
index 7ded3aeb6a..ed9809843b 100644
--- a/board/hatch_fp/build.mk
+++ b/board/hatch_fp/build.mk
@@ -30,6 +30,7 @@ test-list-y=\
aes \
always_memset \
benchmark \
+ boringssl_crypto \
cec \
compile_time_macros \
cortexm_fpu \
@@ -69,6 +70,7 @@ test-list-y=\
timer \
timer_dos \
tpm_seed_clear \
+ unaligned_access \
utils \
utils_str \
diff --git a/board/marasov/board.h b/board/marasov/board.h
index f386087d65..b34e69224b 100644
--- a/board/marasov/board.h
+++ b/board/marasov/board.h
@@ -39,6 +39,8 @@
#define CONFIG_IO_EXPANDER_PORT_COUNT 1
#define CONFIG_USB_PD_FRS_PPC
+#define CONFIG_USB_PD_VBUS_DETECT_PPC
+#undef CONFIG_USB_PD_VBUS_DETECT_TCPC
#define CONFIG_USB_PD_TCPM_PS8815
#define CONFIG_USB_PD_TCPM_PS8815_FORCE_DID
diff --git a/board/marasov/usbc_config.c b/board/marasov/usbc_config.c
index b32421969c..2fa5efea5f 100644
--- a/board/marasov/usbc_config.c
+++ b/board/marasov/usbc_config.c
@@ -318,3 +318,10 @@ __override bool board_is_dts_port(int port)
{
return port == USBC_PORT_C0;
}
+
+#ifdef CONFIG_USB_PD_VBUS_DETECT_PPC
+int pd_snk_is_vbus_provided(int port)
+{
+ return ppc_is_vbus_present(port);
+}
+#endif
diff --git a/board/nocturne_fp/build.mk b/board/nocturne_fp/build.mk
index dc99c72f85..6bf33696d5 100644
--- a/board/nocturne_fp/build.mk
+++ b/board/nocturne_fp/build.mk
@@ -30,6 +30,7 @@ test-list-y=\
aes \
always_memset \
benchmark \
+ boringssl_crypto \
cec \
compile_time_macros \
cortexm_fpu \
@@ -68,6 +69,7 @@ test-list-y=\
timer \
timer_dos \
tpm_seed_clear \
+ unaligned_access \
utils \
utils_str \
diff --git a/board/nucleo-dartmonkey/build.mk b/board/nucleo-dartmonkey/build.mk
index fbf78d16b7..de08959fa9 100644
--- a/board/nucleo-dartmonkey/build.mk
+++ b/board/nucleo-dartmonkey/build.mk
@@ -13,6 +13,7 @@ board-y+=fpsensor_detect.o
test-list-y=\
abort \
aes \
+ boringssl_crypto \
cec \
compile_time_macros \
crc \
diff --git a/board/nucleo-f412zg/build.mk b/board/nucleo-f412zg/build.mk
index 8299781a6f..c31e640099 100644
--- a/board/nucleo-f412zg/build.mk
+++ b/board/nucleo-f412zg/build.mk
@@ -12,6 +12,7 @@ board-y=board.o
test-list-y=\
abort \
aes \
+ boringssl_crypto \
cec \
compile_time_macros \
crc \
diff --git a/board/nucleo-h743zi/build.mk b/board/nucleo-h743zi/build.mk
index 575a6d5da3..932793898a 100644
--- a/board/nucleo-h743zi/build.mk
+++ b/board/nucleo-h743zi/build.mk
@@ -12,6 +12,7 @@ board-y=board.o
test-list-y=\
abort \
aes \
+ boringssl \
cec \
compile_time_macros \
crc \
diff --git a/board/omnigul/board.h b/board/omnigul/board.h
index 76e5c8656f..fa5cc127db 100644
--- a/board/omnigul/board.h
+++ b/board/omnigul/board.h
@@ -33,10 +33,12 @@
#undef CONFIG_LED_PWM_SOC_ON_COLOR
#undef CONFIG_LED_PWM_SOC_SUSPEND_COLOR
#undef CONFIG_LED_PWM_LOW_BATT_COLOR
+#undef CONFIG_LED_PWM_CHARGE_ERROR_COLOR
#define CONFIG_LED_PWM_NEAR_FULL_COLOR EC_LED_COLOR_BLUE
#define CONFIG_LED_PWM_SOC_ON_COLOR EC_LED_COLOR_BLUE
-#define CONFIG_LED_PWM_SOC_SUSPEND_COLOR EC_LED_COLOR_BLUE
+#define CONFIG_LED_PWM_SOC_SUSPEND_COLOR EC_LED_COLOR_AMBER
#define CONFIG_LED_PWM_LOW_BATT_COLOR EC_LED_COLOR_AMBER
+#define CONFIG_LED_PWM_CHARGE_ERROR_COLOR EC_LED_COLOR_AMBER
/* Sensors */
#define CONFIG_ACCELGYRO_LSM6DSO /* Base accel */
@@ -68,8 +70,6 @@
#define CONFIG_USB_PORT_POWER_DUMB
/* USB Type C and USB PD defines */
-#define CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY
-
#define CONFIG_IO_EXPANDER
#define CONFIG_IO_EXPANDER_NCT38XX
#define CONFIG_IO_EXPANDER_PORT_COUNT 1
@@ -167,13 +167,6 @@
#define USBC_PORT_C0_BB_RETIMER_I2C_ADDR 0x56
#define USBC_PORT_C2_BB_RETIMER_I2C_ADDR 0x57
-/* Enabling Thunderbolt-compatible mode */
-#define CONFIG_USB_PD_TBT_COMPAT_MODE
-
-/* Enabling USB4 mode */
-#define CONFIG_USB_PD_USB4
-#define CONFIG_USB_PD_DATA_RESET_MSG
-
/* Retimer */
#define CONFIG_USBC_RETIMER_FW_UPDATE
diff --git a/board/taranza/led.c b/board/taranza/led.c
index 4f41c3c6c1..6101e9a263 100644
--- a/board/taranza/led.c
+++ b/board/taranza/led.c
@@ -59,6 +59,9 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
/* Called by hook task every TICK */
static void led_tick(void)
{
+ if (!led_auto_control_is_enabled(EC_LED_ID_POWER_LED))
+ return;
+
if (chipset_in_state(CHIPSET_STATE_ON))
led_set_color_power(LED_WHITE);
else
diff --git a/board/vell/fw_config.c b/board/vell/fw_config.c
index bf5e29fe05..137c5c9f9a 100644
--- a/board/vell/fw_config.c
+++ b/board/vell/fw_config.c
@@ -12,20 +12,17 @@
#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ##args)
-static union brya_cbi_fw_config fw_config;
+static union vell_cbi_fw_config fw_config;
BUILD_ASSERT(sizeof(fw_config) == sizeof(uint32_t));
/*
- * FW_CONFIG defaults for brya if the CBI.FW_CONFIG data is not
+ * FW_CONFIG defaults for vell if the CBI.FW_CONFIG data is not
* initialized.
*/
-static const union brya_cbi_fw_config fw_config_defaults = {
- .usb_db = DB_USB3_PS8815,
- .kb_bl = KEYBOARD_BACKLIGHT_ENABLED,
-};
+static const union vell_cbi_fw_config fw_config_defaults = {};
/****************************************************************************
- * Brya FW_CONFIG access
+ * Vell FW_CONFIG access
*/
void board_init_fw_config(void)
{
@@ -33,29 +30,4 @@ void board_init_fw_config(void)
CPRINTS("CBI: Read FW_CONFIG failed, using board defaults");
fw_config = fw_config_defaults;
}
-
- if (get_board_id() == 0) {
- /*
- * Early boards have a zero'd out FW_CONFIG, so replace
- * it with a sensible default value. If DB_USB_ABSENT2
- * was used as an alternate encoding of DB_USB_ABSENT to
- * avoid the zero check, then fix it.
- */
- if (fw_config.raw_value == 0) {
- CPRINTS("CBI: FW_CONFIG is zero, using board defaults");
- fw_config = fw_config_defaults;
- } else if (fw_config.usb_db == DB_USB_ABSENT2) {
- fw_config.usb_db = DB_USB_ABSENT;
- }
- }
-}
-
-union brya_cbi_fw_config get_fw_config(void)
-{
- return fw_config;
-}
-
-enum ec_cfg_usb_db_type ec_cfg_usb_db_type(void)
-{
- return fw_config.usb_db;
}
diff --git a/board/vell/fw_config.h b/board/vell/fw_config.h
index fea6c9a8da..324057a8e9 100644
--- a/board/vell/fw_config.h
+++ b/board/vell/fw_config.h
@@ -3,52 +3,25 @@
* found in the LICENSE file.
*/
-#ifndef __BOARD_BRYA_FW_CONFIG_H_
-#define __BOARD_BRYA_FW_CONFIG_H_
+#ifndef __BOARD_VELL_FW_CONFIG_H_
+#define __BOARD_VELL_FW_CONFIG_H_
#include <stdint.h>
/****************************************************************************
- * CBI FW_CONFIG layout for Brya board.
+ * CBI FW_CONFIG layout for Vell board.
*
- * Source of truth is the project/brya/brya/config.star configuration file.
+ * Source of truth is the project/brya/vell/config.star configuration file.
*/
-
-enum ec_cfg_usb_db_type {
- DB_USB_ABSENT = 0,
- DB_USB3_PS8815 = 1,
- DB_USB_ABSENT2 = 15
-};
-
-enum ec_cfg_keyboard_backlight_type {
- KEYBOARD_BACKLIGHT_DISABLED = 0,
- KEYBOARD_BACKLIGHT_ENABLED = 1
-};
-
-union brya_cbi_fw_config {
+union vell_cbi_fw_config {
struct {
- enum ec_cfg_usb_db_type usb_db : 4;
- uint32_t sd_db : 2;
uint32_t lte_db : 1;
- enum ec_cfg_keyboard_backlight_type kb_bl : 1;
- uint32_t audio : 3;
- uint32_t reserved_1 : 21;
+ uint32_t kb_color : 1;
+ uint32_t storage_nand : 1;
+ uint32_t wifi_sar_id : 2;
+ uint32_t reserved_1 : 27;
};
uint32_t raw_value;
};
-/**
- * Read the cached FW_CONFIG. Guaranteed to have valid values.
- *
- * @return the FW_CONFIG for the board.
- */
-union brya_cbi_fw_config get_fw_config(void);
-
-/**
- * Get the USB daughter board type from FW_CONFIG.
- *
- * @return the USB daughter board type.
- */
-enum ec_cfg_usb_db_type ec_cfg_usb_db_type(void);
-
-#endif /* __BOARD_BRYA_FW_CONFIG_H_ */
+#endif /* __BOARD_VELL_FW_CONFIG_H_ */
diff --git a/chip/host/trng.c b/chip/host/trng.c
index d0def66277..f67dd6c4db 100644
--- a/chip/host/trng.c
+++ b/chip/host/trng.c
@@ -31,6 +31,11 @@ test_mockable void trng_exit(void)
{
}
+test_mockable uint32_t trng_rand(void)
+{
+ return (uint32_t)rand_r(&seed);
+}
+
test_mockable void trng_rand_bytes(void *buffer, size_t len)
{
uint8_t *b, *end;
diff --git a/chip/npcx/build.mk b/chip/npcx/build.mk
index 9e046be7ec..11155af9bb 100644
--- a/chip/npcx/build.mk
+++ b/chip/npcx/build.mk
@@ -40,6 +40,7 @@ chip-$(CONFIG_CEC)+=cec.o
# pwm functions are implemented with the fan functions
chip-$(CONFIG_PWM)+=pwm.o
chip-$(CONFIG_SPI)+=spi.o
+chip-$(CONFIG_RNG)+=trng.o
chip-$(CONFIG_WATCHDOG)+=watchdog.o
ifndef CONFIG_KEYBOARD_DISCRETE
chip-$(HAS_TASK_KEYSCAN)+=keyboard_raw.o
diff --git a/chip/npcx/gpio-npcx9.c b/chip/npcx/gpio-npcx9.c
index 5de8ea3b0a..3a7378083c 100644
--- a/chip/npcx/gpio-npcx9.c
+++ b/chip/npcx/gpio-npcx9.c
@@ -181,21 +181,22 @@ GPIO_IRQ_FUNC(__gpio_wk1e_interrupt, WUI_INT(MIWU_TABLE_1, MIWU_GROUP_5));
GPIO_IRQ_FUNC(__gpio_wk1f_interrupt, WUI_INT(MIWU_TABLE_1, MIWU_GROUP_6));
GPIO_IRQ_FUNC(__gpio_wk1g_interrupt, WUI_INT(MIWU_TABLE_1, MIWU_GROUP_7));
-DECLARE_IRQ(NPCX_IRQ_CR_SIN2_WKINTA_0, __gpio_cr_sin2_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_TWD_WKINTB_0, __gpio_wk0b_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_WKINTC_0, __gpio_wk0c_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_MTC_WKINTD_0, __gpio_rtc_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_WKINTE_0, __gpio_host_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_WKINTF_0, __gpio_wk0f_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_WKINTG_0, __gpio_wk0g_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_WKINTH_0, __gpio_wk0h_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_WKINTA_1, __gpio_wk1a_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_WKINTB_1, __gpio_wk1b_interrupt, 3);
+DECLARE_IRQ(NPCX_IRQ_CR_SIN2_WKINTA_0, __gpio_cr_sin2_interrupt,
+ NPCX_MIWU0_GROUP_A);
+DECLARE_IRQ(NPCX_IRQ_TWD_WKINTB_0, __gpio_wk0b_interrupt, NPCX_MIWU0_GROUP_B);
+DECLARE_IRQ(NPCX_IRQ_WKINTC_0, __gpio_wk0c_interrupt, NPCX_MIWU0_GROUP_C);
+DECLARE_IRQ(NPCX_IRQ_MTC_WKINTD_0, __gpio_rtc_interrupt, NPCX_MIWU0_GROUP_D);
+DECLARE_IRQ(NPCX_IRQ_WKINTE_0, __gpio_host_interrupt, NPCX_MIWU0_GROUP_E);
+DECLARE_IRQ(NPCX_IRQ_WKINTF_0, __gpio_wk0f_interrupt, NPCX_MIWU0_GROUP_F);
+DECLARE_IRQ(NPCX_IRQ_WKINTG_0, __gpio_wk0g_interrupt, NPCX_MIWU0_GROUP_G);
+DECLARE_IRQ(NPCX_IRQ_WKINTH_0, __gpio_wk0h_interrupt, NPCX_MIWU0_GROUP_H);
+DECLARE_IRQ(NPCX_IRQ_WKINTA_1, __gpio_wk1a_interrupt, NPCX_MIWU1_GROUP_A);
+DECLARE_IRQ(NPCX_IRQ_WKINTB_1, __gpio_wk1b_interrupt, NPCX_MIWU1_GROUP_B);
#ifdef NPCX_SELECT_KSI_TO_GPIO
-DECLARE_IRQ(NPCX_IRQ_KSI_WKINTC_1, __gpio_wk1c_interrupt, 3);
+DECLARE_IRQ(NPCX_IRQ_KSI_WKINTC_1, __gpio_wk1c_interrupt, NPCX_MIWU1_GROUP_C);
#endif
-DECLARE_IRQ(NPCX_IRQ_WKINTD_1, __gpio_wk1d_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_WKINTE_1, __gpio_wk1e_interrupt, 3);
+DECLARE_IRQ(NPCX_IRQ_WKINTD_1, __gpio_wk1d_interrupt, NPCX_MIWU1_GROUP_D);
+DECLARE_IRQ(NPCX_IRQ_WKINTE_1, __gpio_wk1e_interrupt, NPCX_MIWU1_GROUP_E);
#ifdef CONFIG_HOST_INTERFACE_SHI
/*
* HACK: Make CS GPIO P2 to improve SHI reliability.
@@ -204,10 +205,10 @@ DECLARE_IRQ(NPCX_IRQ_WKINTE_1, __gpio_wk1e_interrupt, 3);
*/
DECLARE_IRQ(NPCX_IRQ_WKINTF_1, __gpio_wk1f_interrupt, 2);
#else
-DECLARE_IRQ(NPCX_IRQ_WKINTF_1, __gpio_wk1f_interrupt, 3);
+DECLARE_IRQ(NPCX_IRQ_WKINTF_1, __gpio_wk1f_interrupt, NPCX_MIWU1_GROUP_F);
#endif
-DECLARE_IRQ(NPCX_IRQ_WKINTG_1, __gpio_wk1g_interrupt, 3);
-DECLARE_IRQ(NPCX_IRQ_WKINTH_1, __gpio_wk1h_interrupt, 3);
+DECLARE_IRQ(NPCX_IRQ_WKINTG_1, __gpio_wk1g_interrupt, NPCX_MIWU1_GROUP_G);
+DECLARE_IRQ(NPCX_IRQ_WKINTH_1, __gpio_wk1h_interrupt, NPCX_MIWU1_GROUP_H);
DECLARE_IRQ(NPCX_IRQ_LCT_WKINTF_2, __gpio_lct_interrupt, 3);
#undef GPIO_IRQ_FUNC
diff --git a/chip/npcx/registers.h b/chip/npcx/registers.h
index a583fb1c64..c99fb76bf3 100644
--- a/chip/npcx/registers.h
+++ b/chip/npcx/registers.h
@@ -275,6 +275,56 @@ enum {
MIWU_EDGE_ANYING,
};
+#define NPCX_MIWU_DEFAULT_PRIORITY 3
+#ifndef NPCX_MIWU0_GROUP_A
+#define NPCX_MIWU0_GROUP_A NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU0_GROUP_B
+#define NPCX_MIWU0_GROUP_B NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU0_GROUP_C
+#define NPCX_MIWU0_GROUP_C NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU0_GROUP_D
+#define NPCX_MIWU0_GROUP_D NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU0_GROUP_E
+#define NPCX_MIWU0_GROUP_E NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU0_GROUP_F
+#define NPCX_MIWU0_GROUP_F NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU0_GROUP_G
+#define NPCX_MIWU0_GROUP_G NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU0_GROUP_H
+#define NPCX_MIWU0_GROUP_H NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU1_GROUP_A
+#define NPCX_MIWU1_GROUP_A NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU1_GROUP_B
+#define NPCX_MIWU1_GROUP_B NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU1_GROUP_C
+#define NPCX_MIWU1_GROUP_C NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU1_GROUP_D
+#define NPCX_MIWU1_GROUP_D NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU1_GROUP_E
+#define NPCX_MIWU1_GROUP_E NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU1_GROUP_F
+#define NPCX_MIWU1_GROUP_F NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU1_GROUP_G
+#define NPCX_MIWU1_GROUP_G NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+#ifndef NPCX_MIWU1_GROUP_H
+#define NPCX_MIWU1_GROUP_H NPCX_MIWU_DEFAULT_PRIORITY
+#endif
+
/* MIWU utilities */
#define MIWU_TABLE_WKKEY MIWU_TABLE_1
#define MIWU_GROUP_WKKEY MIWU_GROUP_3
diff --git a/chip/npcx/trng.c b/chip/npcx/trng.c
new file mode 100644
index 0000000000..a2d7920c14
--- /dev/null
+++ b/chip/npcx/trng.c
@@ -0,0 +1,251 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Hardware Random Number Generator */
+
+#include "common.h"
+#include "console.h"
+#include "host_command.h"
+#include "panic.h"
+#include "printf.h"
+#include "registers.h"
+#include "system.h"
+#include "task.h"
+#include "trng.h"
+#include "util.h"
+
+#define DRBG_CONTEXT_SIZE 240
+
+struct drbg_ctx {
+ union {
+ uint8_t buffer[DRBG_CONTEXT_SIZE];
+ uint32_t buffer32[DRBG_CONTEXT_SIZE / 4];
+ uint64_t buffer64[DRBG_CONTEXT_SIZE / 8];
+ };
+} __aligned(16);
+
+struct drbg_ctx ctx;
+struct drbg_ctx *ctx_p = &ctx;
+
+enum ncl_status {
+ NCL_STATUS_OK = 0xA5A5,
+ NCL_STATUS_FAIL = 0x5A5A,
+ NCL_STATUS_INVALID_PARAM = 0x02,
+ NCL_STATUS_PARAM_NOT_SUPPORTED,
+ NCL_STATUS_SYSTEM_BUSY,
+ NCL_STATUS_AUTHENTICATION_FAIL,
+ NCL_STATUS_NO_RESPONSE,
+ NCL_STATUS_HARDWARE_ERROR,
+};
+
+/*
+ * This enum defines the security strengths supported by this DRBG mechanism.
+ * The internally generated entropy and nonce sizes are derived from these
+ * values. The supported actual sizes:
+ * Security strength (bits) 112 128 192 256 128_Test 256_Test
+ *
+ * Entropy size (Bytes) 32 48 64 96 111 128
+ * Nonce size (Bytes) 16 16 24 32 16 0
+ */
+enum ncl_drbg_security_strength {
+ NCL_DRBG_SECURITY_STRENGTH_112b = 0,
+ NCL_DRBG_SECURITY_STRENGTH_128b,
+ NCL_DRBG_SECURITY_STRENGTH_192b,
+ NCL_DRBG_SECURITY_STRENGTH_256b,
+ NCL_DRBG_SECURITY_STRENGTH_128b_TEST,
+ NCL_DRBG_SECURITY_STRENGTH_256b_TEST,
+ NCL_DRBG_MAX_SECURITY_STRENGTH
+};
+
+/* The actual base address is 13C but we only need the SHA power function */
+#define NCL_SHA_BASE_ADDR 0x0000015CUL
+struct ncl_sha {
+ /* Power on/off SHA module. */
+ enum ncl_status (*power)(void *ctx, uint8_t on);
+};
+#define NCL_SHA ((const struct ncl_sha *)NCL_SHA_BASE_ADDR)
+
+/*
+ * The base address of the table that holds the function pointer for each
+ * DRBG API in ROM.
+ */
+#define NCL_DRBG_BASE_ADDR 0x00000110UL
+struct ncl_drbg {
+ /* Get the DRBG context size required by DRBG APIs. */
+ uint32_t (*get_context_size)(void);
+ /* Initialize DRBG context. */
+ enum ncl_status (*init_context)(void *ctx);
+ /* Power on/off DRBG module. */
+ enum ncl_status (*power)(void *ctx, uint8_t on);
+ /* Finalize DRBG context. */
+ enum ncl_status (*finalize_context)(void *ctx);
+ /* Initialize the DRBG hardware module and enable interrupts. */
+ enum ncl_status (*init)(void *ctx, bool int_enable);
+ /*
+ * Configure DRBG, pres_resistance enables/disables (1/0) prediction
+ * resistance
+ */
+ enum ncl_status (*config)(void *ctx, uint32_t reseed_interval,
+ uint8_t pred_resistance);
+ /*
+ * This routine creates a first instantiation of the DRBG mechanism
+ * parameters. The routine pulls an initial seed from the HW RNG module
+ * and resets the reseed counter. DRBG and SHA modules should be
+ * activated prior to the this operation.
+ */
+ enum ncl_status (*instantiate)(
+ void *ctx, enum ncl_drbg_security_strength sec_strength,
+ const uint8_t *pers_string, uint32_t pers_string_len);
+ /* Uninstantiate DRBG module */
+ enum ncl_status (*uninstantiate)(void *ctx);
+ /* Reseeds the internal state of the given instantce */
+ enum ncl_status (*reseed)(void *ctc, uint8_t *add_data,
+ uint32_t add_data_len);
+ /* Generates a random number from the current internal state. */
+ enum ncl_status (*generate)(void *ctx, const uint8_t *add_data,
+ uint32_t add_data_len, uint8_t *out_buff,
+ uint32_t out_buff_len);
+ /* Clear all DRBG SSPs (Sensitive Security Parameters) in HW & driver */
+ enum ncl_status (*clear)(void *ctx);
+};
+#define NCL_DRBG ((const struct ncl_drbg *)NCL_DRBG_BASE_ADDR)
+
+struct npcx_trng_state {
+ enum ncl_status trng_init;
+};
+struct npcx_trng_state trng_state;
+struct npcx_trng_state *state_p = &trng_state;
+
+test_mockable void trng_init(void)
+{
+#ifndef CHIP_VARIANT_NPCX9M8S
+#error "Please add support for CONFIG_RNG on this chip family."
+#endif
+
+ uint32_t context_size = 0;
+
+ state_p->trng_init = NCL_STATUS_FAIL;
+
+ context_size = NCL_DRBG->get_context_size();
+ if (context_size != DRBG_CONTEXT_SIZE)
+ ccprintf("ERROR! Unexpected NCL DRBG context_size = %d\n",
+ context_size);
+
+ state_p->trng_init = NCL_DRBG->power(ctx_p, true);
+ if (state_p->trng_init != NCL_STATUS_OK) {
+ ccprintf("ERROR! DRBG power returned %x\n", state_p->trng_init);
+ return;
+ }
+
+ state_p->trng_init = NCL_SHA->power(ctx_p, true);
+ if (state_p->trng_init != NCL_STATUS_OK) {
+ ccprintf("ERROR! SHA power returned %x\n", state_p->trng_init);
+ return;
+ }
+
+ state_p->trng_init = NCL_DRBG->init_context(ctx_p);
+ if (state_p->trng_init != NCL_STATUS_OK) {
+ ccprintf("ERROR! DRBG init_context returned %x\r",
+ state_p->trng_init);
+ return;
+ }
+
+ state_p->trng_init = NCL_DRBG->init(ctx_p, 0);
+ if (state_p->trng_init != NCL_STATUS_OK) {
+ ccprintf("ERROR! DRBG init returned %x\r", state_p->trng_init);
+ return;
+ }
+
+ state_p->trng_init = NCL_DRBG->config(ctx_p, 100, false);
+ if (state_p->trng_init != NCL_STATUS_OK) {
+ ccprintf("ERROR! DRBG config returned %x\r",
+ state_p->trng_init);
+ return;
+ }
+
+ state_p->trng_init = NCL_DRBG->instantiate(
+ ctx_p, NCL_DRBG_SECURITY_STRENGTH_128b, NULL, 0);
+ if (state_p->trng_init != NCL_STATUS_OK) {
+ ccprintf("ERROR! DRBG instantiate returned %x\r",
+ state_p->trng_init);
+ return;
+ }
+
+ state_p->trng_init = NCL_DRBG->power(ctx_p, false);
+ if (state_p->trng_init != NCL_STATUS_OK) {
+ ccprintf("ERROR! DRBG power returned %x\n", state_p->trng_init);
+ return;
+ }
+
+ state_p->trng_init = NCL_SHA->power(ctx_p, false);
+ if (state_p->trng_init != NCL_STATUS_OK) {
+ ccprintf("ERROR! SHA power returned %x\n", state_p->trng_init);
+ return;
+ }
+}
+
+uint32_t trng_rand(void)
+{
+ uint32_t return_value;
+ enum ncl_status status = NCL_STATUS_FAIL;
+
+ /* Don't attempt generate and panic if initialization failed */
+ if (state_p->trng_init != NCL_STATUS_OK)
+ software_panic(PANIC_SW_BAD_RNG, task_get_current());
+
+ status = NCL_DRBG->power(ctx_p, true);
+ if (status != NCL_STATUS_OK) {
+ ccprintf("ERROR! DRBG power returned %x\n", status);
+ software_panic(PANIC_SW_BAD_RNG, task_get_current());
+ }
+
+ status = NCL_SHA->power(ctx_p, true);
+ if (status != NCL_STATUS_OK) {
+ ccprintf("ERROR! SHA power returned %x\n", status);
+ software_panic(PANIC_SW_BAD_RNG, task_get_current());
+ }
+
+ status = NCL_DRBG->generate(NULL, NULL, 0, (uint8_t *)&return_value, 4);
+ if (status != NCL_STATUS_OK) {
+ ccprintf("ERROR! DRBG generate returned %x\r", status);
+ software_panic(PANIC_SW_BAD_RNG, task_get_current());
+ }
+
+ /*
+ * Failing to turn off the blocks has power implications but wouldn't
+ * result in feeding the caller a bad result, hence no panics enabled
+ * for failing to turn off the hardware
+ */
+ status = NCL_DRBG->power(ctx_p, false);
+ if (status != NCL_STATUS_OK)
+ ccprintf("ERROR! DRBG power returned %x\n", status);
+
+ status = NCL_SHA->power(ctx_p, false);
+ if (status != NCL_STATUS_OK)
+ ccprintf("ERROR! SHA power returned %x\n", status);
+
+ return return_value;
+}
+
+test_mockable void trng_exit(void)
+{
+ enum ncl_status status = NCL_STATUS_FAIL;
+
+ status = NCL_DRBG->clear(ctx_p);
+ if (status != NCL_STATUS_OK)
+ ccprintf("ERROR! DRBG clear returned %x\r", status);
+
+ status = NCL_DRBG->uninstantiate(ctx_p);
+ if (status != NCL_STATUS_OK)
+ ccprintf("ERROR! DRBG uninstantiate returned %x\r", status);
+
+ status = NCL_DRBG->power(ctx_p, false);
+ if (status != NCL_STATUS_OK)
+ ccprintf("ERROR! DRBG power returned %x\n", status);
+
+ status = NCL_SHA->power(ctx_p, false);
+ if (status != NCL_STATUS_OK)
+ ccprintf("ERROR! SHA power returned %x\n", status);
+}
diff --git a/chip/stm32/trng.c b/chip/stm32/trng.c
index 67d3700cf1..63641741d3 100644
--- a/chip/stm32/trng.c
+++ b/chip/stm32/trng.c
@@ -16,7 +16,7 @@
#include "trng.h"
#include "util.h"
-static uint32_t trng_rand(void)
+uint32_t trng_rand(void)
{
int tries = 300;
/* Wait for a valid random number */
@@ -29,25 +29,6 @@ static uint32_t trng_rand(void)
return STM32_RNG_DR;
}
-test_mockable void trng_rand_bytes(void *buffer, size_t len)
-{
- while (len) {
- uint32_t number = trng_rand();
- size_t cnt = 4;
- /* deal with the lack of alignment guarantee in the API */
- uintptr_t align = (uintptr_t)buffer & 3;
-
- if (len < 4 || align) {
- cnt = MIN(4 - align, len);
- memcpy(buffer, &number, cnt);
- } else {
- *(uint32_t *)buffer = number;
- }
- len -= cnt;
- buffer += cnt;
- }
-}
-
test_mockable void trng_init(void)
{
#ifdef CHIP_FAMILY_STM32L4
@@ -97,53 +78,3 @@ test_mockable void trng_exit(void)
/* Nothing to do */
#endif
}
-
-#if defined(CONFIG_CMD_RAND)
-/*
- * We want to avoid accidentally exposing debug commands in RO since we can't
- * update RO once in production.
- */
-#if defined(SECTION_IS_RW)
-static int command_rand(int argc, const char **argv)
-{
- uint8_t data[32];
- char str_buf[hex_str_buf_size(sizeof(data))];
-
- trng_init();
- trng_rand_bytes(data, sizeof(data));
- trng_exit();
-
- snprintf_hex_buffer(str_buf, sizeof(str_buf),
- HEX_BUF(data, sizeof(data)));
- ccprintf("rand %s\n", str_buf);
-
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(rand, command_rand, NULL,
- "Output random bytes to console.");
-
-static enum ec_status host_command_rand(struct host_cmd_handler_args *args)
-{
- const struct ec_params_rand_num *p = args->params;
- struct ec_response_rand_num *r = args->response;
- uint16_t num_rand_bytes = p->num_rand_bytes;
-
- if (system_is_locked())
- return EC_RES_ACCESS_DENIED;
-
- if (num_rand_bytes > args->response_max)
- return EC_RES_OVERFLOW;
-
- trng_init();
- trng_rand_bytes(r->rand, num_rand_bytes);
- trng_exit();
-
- args->response_size = num_rand_bytes;
-
- return EC_SUCCESS;
-}
-
-DECLARE_HOST_COMMAND(EC_CMD_RAND_NUM, host_command_rand,
- EC_VER_MASK(EC_VER_RAND_NUM));
-#endif /* SECTION_IS_RW */
-#endif /* CONFIG_CMD_RAND */
diff --git a/common/body_detection.c b/common/body_detection.c
index d16e83df00..646bc6d740 100644
--- a/common/body_detection.c
+++ b/common/body_detection.c
@@ -102,6 +102,19 @@ void body_detect_change_state(enum body_detect_states state, bool spoof)
{
if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && spoof_enable && !spoof)
return;
+ if (IS_ENABLED(CONFIG_GESTURE_HOST_DETECTION)) {
+ struct ec_response_motion_sensor_data vector = {
+ .flags = MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO,
+ .activity_data = {
+ .activity = MOTIONSENSE_ACTIVITY_BODY_DETECTION,
+ .state = state,
+ },
+ .sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID,
+ };
+ motion_sense_fifo_stage_data(&vector, NULL, 0,
+ __hw_clock_source_read());
+ motion_sense_fifo_commit_data();
+ }
/* change the motion state */
motion_state = state;
if (state == BODY_DETECTION_ON_BODY) {
diff --git a/common/build.mk b/common/build.mk
index bbc0789f9b..03d1e7bbaf 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -141,8 +141,9 @@ common-$(CONFIG_PWM)+=pwm.o
common-$(CONFIG_PWM_KBLIGHT)+=pwm_kblight.o
common-$(CONFIG_KEYBOARD_BACKLIGHT)+=keyboard_backlight.o
common-$(CONFIG_RGB_KEYBOARD)+=rgb_keyboard.o
-common-$(CONFIG_RSA)+=rsa.o
+common-$(CONFIG_RNG)+=trng.o
common-$(CONFIG_ROLLBACK)+=rollback.o
+common-$(CONFIG_RSA)+=rsa.o
common-$(CONFIG_RWSIG)+=rwsig.o vboot/common.o
common-$(CONFIG_RWSIG_TYPE_RWSIG)+=vboot/vb21_lib.o
common-$(CONFIG_MATH_UTIL)+=math_util.o
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index a603d4f108..abfb6d2dd0 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -80,7 +80,7 @@ static uint8_t battery_level_shutdown;
*/
static const struct battery_info *batt_info;
static struct charge_state_data curr;
-static enum charge_state_v2 prev_state;
+static enum charge_state prev_state;
static int prev_ac, prev_charge, prev_disp_charge;
static enum battery_present prev_bp;
static enum ec_charge_control_mode chg_ctl_mode;
@@ -776,7 +776,7 @@ static void notify_host_of_low_battery_charge(void)
#endif
}
-static void set_charge_state(enum charge_state_v2 state)
+static void set_charge_state(enum charge_state state)
{
prev_state = curr.state;
curr.state = state;
@@ -1026,7 +1026,7 @@ static void wakeup_battery(int *need_static)
}
}
-__test_only enum charge_state_v2 charge_get_state_v2(void)
+__test_only enum charge_state charge_get_state(void)
{
return curr.state;
}
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 16a37d37a5..546034c7e2 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -698,6 +698,26 @@ static void check_and_queue_gestures(uint32_t *event)
if (IS_ENABLED(CONFIG_GESTURE_SENSOR_DOUBLE_TAP) &&
(*event & TASK_EVENT_MOTION_ACTIVITY_INTERRUPT(
MOTIONSENSE_ACTIVITY_DOUBLE_TAP))) {
+ if (IS_ENABLED(CONFIG_GESTURE_HOST_DETECTION)) {
+ struct ec_response_motion_sensor_data vector;
+
+ vector.flags = MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO;
+ /*
+ * Send events to the FIFO
+ * AP is ignoring double tap event, do no wake up and no
+ * automatic disable.
+ */
+ if (IS_ENABLED(
+ CONFIG_GESTURE_SENSOR_DOUBLE_TAP_FOR_HOST))
+ vector.flags |= MOTIONSENSE_SENSOR_FLAG_WAKEUP;
+ vector.activity_data.activity =
+ MOTIONSENSE_ACTIVITY_DOUBLE_TAP;
+ vector.activity_data.state = 1 /* triggered */;
+ vector.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID;
+ motion_sense_fifo_stage_data(&vector, NULL, 0,
+ __hw_clock_source_read());
+ motion_sense_fifo_commit_data();
+ }
/* Call board specific function to process tap */
sensor_board_proc_double_tap();
}
@@ -705,7 +725,20 @@ static void check_and_queue_gestures(uint32_t *event)
(*event & TASK_EVENT_MOTION_ACTIVITY_INTERRUPT(
MOTIONSENSE_ACTIVITY_SIG_MOTION))) {
struct motion_sensor_t *activity_sensor;
-
+ if (IS_ENABLED(CONFIG_GESTURE_HOST_DETECTION)) {
+ struct ec_response_motion_sensor_data vector;
+
+ /* Send events to the FIFO */
+ vector.flags = MOTIONSENSE_SENSOR_FLAG_WAKEUP |
+ MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO;
+ vector.activity_data.activity =
+ MOTIONSENSE_ACTIVITY_SIG_MOTION;
+ vector.activity_data.state = 1 /* triggered */;
+ vector.sensor_num = MOTION_SENSE_ACTIVITY_SENSOR_ID;
+ motion_sense_fifo_stage_data(&vector, NULL, 0,
+ __hw_clock_source_read());
+ motion_sense_fifo_commit_data();
+ }
/* Disable further detection */
activity_sensor = &motion_sensors[CONFIG_GESTURE_SIGMO_SENSOR];
activity_sensor->drv->manage_activity(
@@ -730,6 +763,12 @@ static void check_and_queue_gestures(uint32_t *event)
(*motion_orientation_ptr(sensor) !=
MOTIONSENSE_ORIENTATION_UNKNOWN)) {
motion_orientation_update(sensor);
+ vector.activity_data.state =
+ *motion_orientation_ptr(sensor);
+ motion_sense_fifo_stage_data(
+ &vector, NULL, 0,
+ __hw_clock_source_read());
+ motion_sense_fifo_commit_data();
if (IS_ENABLED(CONFIG_DEBUG_ORIENTATION)) {
static const char *const mode[] = {
"Landscape", "Portrait",
diff --git a/common/motion_sense_fifo.c b/common/motion_sense_fifo.c
index fd1bfda88c..1a7303bc79 100644
--- a/common/motion_sense_fifo.c
+++ b/common/motion_sense_fifo.c
@@ -271,6 +271,9 @@ static void fifo_stage_unit(struct ec_response_motion_sensor_data *data,
struct queue_chunk chunk;
int i;
+ if (valid_data > 0 && !sensor)
+ return;
+
mutex_lock(&g_sensor_mutex);
for (i = 0; i < valid_data; i++)
@@ -460,7 +463,7 @@ void motion_sense_fifo_stage_data(struct ec_response_motion_sensor_data *data,
fifo_staged.read_ts = __hw_clock_source_read();
fifo_stage_timestamp(time, data->sensor_num);
}
- if (sensor->config[SENSOR_CONFIG_AP].ec_rate > 0 &&
+ if (sensor && sensor->config[SENSOR_CONFIG_AP].ec_rate > 0 &&
time_after(time, ts_last_int[id] +
sensor->config[SENSOR_CONFIG_AP].ec_rate -
MOTION_SENSOR_INT_ADJUSTMENT_US)) {
diff --git a/common/trng.c b/common/trng.c
new file mode 100644
index 0000000000..273a078d7a
--- /dev/null
+++ b/common/trng.c
@@ -0,0 +1,82 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Common Random Number Generation (RNG) routines */
+
+#include "common.h"
+#include "console.h"
+#include "cpu.h"
+#include "host_command.h"
+#include "panic.h"
+#include "printf.h"
+#include "registers.h"
+#include "system.h"
+#include "task.h"
+#include "trng.h"
+#include "util.h"
+
+test_mockable void trng_rand_bytes(void *buffer, size_t len)
+{
+ while (len) {
+ uint32_t number = trng_rand();
+ size_t cnt = 4;
+ /* deal with the lack of alignment guarantee in the API */
+ uintptr_t align = (uintptr_t)buffer & 3;
+
+ if (len < 4 || align) {
+ cnt = MIN(4 - align, len);
+ memcpy(buffer, &number, cnt);
+ } else {
+ *(uint32_t *)buffer = number;
+ }
+ len -= cnt;
+ buffer += cnt;
+ }
+}
+
+#if defined(CONFIG_CMD_RAND)
+/*
+ * We want to avoid accidentally exposing debug commands in RO since we can't
+ * update RO once in production.
+ */
+#if defined(SECTION_IS_RW)
+static int command_rand(int argc, const char **argv)
+{
+ uint8_t data[32];
+ char str_buf[hex_str_buf_size(sizeof(data))];
+
+ trng_init();
+ trng_rand_bytes(data, sizeof(data));
+ trng_exit();
+ snprintf_hex_buffer(str_buf, sizeof(str_buf),
+ HEX_BUF(data, sizeof(data)));
+ ccprintf("rand %s\n", str_buf);
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(rand, command_rand, NULL,
+ "Output random bytes to console.");
+
+static enum ec_status host_command_rand(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_rand_num *p = args->params;
+ struct ec_response_rand_num *r = args->response;
+ uint16_t num_rand_bytes = p->num_rand_bytes;
+
+ if (system_is_locked())
+ return EC_RES_ACCESS_DENIED;
+ if (num_rand_bytes > args->response_max)
+ return EC_RES_OVERFLOW;
+ trng_init();
+ trng_rand_bytes(r->rand, num_rand_bytes);
+ trng_exit();
+ args->response_size = num_rand_bytes;
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_RAND_NUM, host_command_rand,
+ EC_VER_MASK(EC_VER_RAND_NUM));
+#endif /* SECTION_IS_RW */
+#endif /* CONFIG_CMD_RAND */
diff --git a/common/usbc/usb_mode.c b/common/usbc/usb_mode.c
index 017f89fc74..157c1b1f04 100644
--- a/common/usbc/usb_mode.c
+++ b/common/usbc/usb_mode.c
@@ -20,6 +20,7 @@
#include "usb_pd_dpm_sm.h"
#include "usb_pd_tcpm.h"
#include "usb_pe_sm.h"
+#include "usb_prl_sm.h"
#include "usb_tbt_alt_mode.h"
#include "usbc_ppc.h"
@@ -169,6 +170,9 @@ bool enter_usb_port_partner_is_capable(int port)
if (usb4_state[port] == USB4_INACTIVE)
return false;
+ if (prl_get_rev(port, TCPCI_MSG_SOP) < PD_REV30)
+ return false;
+
if (!PD_PRODUCT_IS_USB4(disc->identity.product_t1.raw_value))
return false;
diff --git a/core/cortex-m/cpu.c b/core/cortex-m/cpu.c
index 5a882bb532..adcdb4e1a3 100644
--- a/core/cortex-m/cpu.c
+++ b/core/cortex-m/cpu.c
@@ -15,8 +15,8 @@
void cpu_init(void)
{
- /* Catch divide by 0 and unaligned access */
- CPU_NVIC_CCR |= CPU_NVIC_CCR_DIV_0_TRAP | CPU_NVIC_CCR_UNALIGN_TRAP;
+ /* Catch divide by 0 */
+ CPU_NVIC_CCR |= CPU_NVIC_CCR_DIV_0_TRAP;
/* Enable reporting of memory faults, bus faults and usage faults */
CPU_NVIC_SHCSR |= CPU_NVIC_SHCSR_MEMFAULTENA |
diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c
index 336cafc99a..f42b4f9dc0 100644
--- a/core/cortex-m/task.c
+++ b/core/cortex-m/task.c
@@ -301,7 +301,8 @@ void svc_handler(int desched, task_id_t resched)
current = current_task;
#ifdef CONFIG_DEBUG_STACK_OVERFLOW
- if (*current->stack != STACK_UNUSED_VALUE) {
+ if (*current->stack != STACK_UNUSED_VALUE &&
+ task_enabled(current - tasks)) {
panic_printf("\n\nStack overflow in %s task!\n",
task_names[current - tasks]);
software_panic(PANIC_SW_STACK_OVERFLOW, current - tasks);
diff --git a/core/cortex-m0/task.c b/core/cortex-m0/task.c
index f63e9824db..315b8d6d16 100644
--- a/core/cortex-m0/task.c
+++ b/core/cortex-m0/task.c
@@ -231,7 +231,8 @@ task_ __attribute__((noinline)) * __svc_handler(int desched, task_id_t resched)
current = current_task;
#ifdef CONFIG_DEBUG_STACK_OVERFLOW
- if (*current->stack != STACK_UNUSED_VALUE) {
+ if (*current->stack != STACK_UNUSED_VALUE &&
+ task_enabled(current - tasks)) {
panic_printf("\n\nStack overflow in %s task!\n",
task_names[current - tasks]);
software_panic(PANIC_SW_STACK_OVERFLOW, current - tasks);
diff --git a/core/minute-ia/task.c b/core/minute-ia/task.c
index 3e072344df..6322125247 100644
--- a/core/minute-ia/task.c
+++ b/core/minute-ia/task.c
@@ -221,7 +221,8 @@ uint32_t switch_handler(int desched, task_id_t resched)
current = current_task;
if (IS_ENABLED(CONFIG_DEBUG_STACK_OVERFLOW) &&
- *current->stack != STACK_UNUSED_VALUE) {
+ *current->stack != STACK_UNUSED_VALUE &&
+ task_enabled(current - tasks)) {
panic_printf("\n\nStack overflow in %s task!\n",
task_get_name(current - tasks));
diff --git a/core/nds32/task.c b/core/nds32/task.c
index 201c8731fc..bbfc5f79c7 100644
--- a/core/nds32/task.c
+++ b/core/nds32/task.c
@@ -309,9 +309,11 @@ task_ *next_sched_task(void)
#ifdef CONFIG_DEBUG_STACK_OVERFLOW
if (*current_task->stack != STACK_UNUSED_VALUE) {
int i = task_get_current();
-
- panic_printf("\n\nStack overflow in %s task!\n", task_names[i]);
- software_panic(PANIC_SW_STACK_OVERFLOW, i);
+ if (task_enabled(i)) {
+ panic_printf("\n\nStack overflow in %s task!\n",
+ task_names[i]);
+ software_panic(PANIC_SW_STACK_OVERFLOW, i);
+ }
}
#endif
diff --git a/core/riscv-rv32i/task.c b/core/riscv-rv32i/task.c
index 977987277b..48244bc1b2 100644
--- a/core/riscv-rv32i/task.c
+++ b/core/riscv-rv32i/task.c
@@ -289,9 +289,11 @@ task_ *__ram_code next_sched_task(void)
#ifdef CONFIG_DEBUG_STACK_OVERFLOW
if (*current_task->stack != STACK_UNUSED_VALUE) {
int i = task_get_current();
-
- panic_printf("\n\nStack overflow in %s task!\n", task_names[i]);
- software_panic(PANIC_SW_STACK_OVERFLOW, i);
+ if (task_enabled(i)) {
+ panic_printf("\n\nStack overflow in %s task!\n",
+ task_names[i]);
+ software_panic(PANIC_SW_STACK_OVERFLOW, i);
+ }
}
#endif
diff --git a/crypto/build.mk b/crypto/build.mk
new file mode 100644
index 0000000000..fbbfed1ac9
--- /dev/null
+++ b/crypto/build.mk
@@ -0,0 +1,8 @@
+# Copyright 2023 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Crypto related Files
+#
+
+crypto-y+=elliptic_curve_key.o
diff --git a/crypto/elliptic_curve_key.cc b/crypto/elliptic_curve_key.cc
new file mode 100644
index 0000000000..53741d0944
--- /dev/null
+++ b/crypto/elliptic_curve_key.cc
@@ -0,0 +1,24 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "crypto/elliptic_curve_key.h"
+#include "openssl/ec_key.h"
+#include "openssl/mem.h"
+#include "openssl/obj_mac.h"
+
+bssl::UniquePtr<EC_KEY> generate_elliptic_curve_key()
+{
+ bssl::UniquePtr<EC_KEY> key(
+ EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
+ if (key == nullptr) {
+ return nullptr;
+ }
+
+ if (EC_KEY_generate_key(key.get()) != 1) {
+ return nullptr;
+ }
+
+ return key;
+}
diff --git a/docs/chromeos-ec-firmware-test-requirements.md b/docs/chromeos-ec-firmware-test-requirements.md
index 2e8b461eb6..721021275a 100644
--- a/docs/chromeos-ec-firmware-test-requirements.md
+++ b/docs/chromeos-ec-firmware-test-requirements.md
@@ -56,7 +56,8 @@ reports locally on your machine.
In limited cases, you may amend your commit message to include the
`LOW_COVERAGE_REASON` tag. This tag bypasses the code coverage requirement
enforced by Gerrit. Simply add the tag followed by a description to justify
-bypassing code coverage.
+bypassing code coverage. You must include a reference to a bug (in the form
+`b:1234567` or `b/1234567`) that tracks whatever issue is impeding coverage.
```
LOW_COVERAGE_REASON=no emulator for the ANX7483 exists b/248086547
diff --git a/docs/zephyr/zephyr_troubleshooting.md b/docs/zephyr/zephyr_troubleshooting.md
index aa6980a9d5..3f3cc508cc 100644
--- a/docs/zephyr/zephyr_troubleshooting.md
+++ b/docs/zephyr/zephyr_troubleshooting.md
@@ -135,13 +135,23 @@ example a missing `struct device` can show as
/tmp/ccCiGy7c.ltrans0.ltrans.o:(.rodata+0x6a0): undefined reference to `__device_dts_ord_75'
```
-Adding `CONFIG_LTO=n` to the corresponding `prj.conf` usually results in more
-useful error messages, for example:
+Adding `CONFIG_LTO=n` to the corresponding `prj.conf` or building with `zmake
+build <project> -DCONFIG_LTO=n` usually results in more useful error messages,
+for example:
```
modules/ec/libec_shim.a(adc.c.obj):(.rodata.adc_channels+0x58): undefined reference to `__device_dts_ord_75'
```
+## Macro Error Expansion
+
+GCC errors on macros include macro expansion by default. This usually results
+in a wall of errors that makes it very hard to identify the actual problem. For
+these situations it's useful to disable macro expansion entirely by setting
+`CONFIG_COMPILER_TRACK_MACRO_EXPANSION=n`, for example by building with:
+
+`zmake build <project> -DCONFIG_COMPILER_TRACK_MACRO_EXPANSION=n`
+
## Build artifacts
The buildsystem can be configured to leave the build artifact next to the
diff --git a/driver/battery/smart.c b/driver/battery/smart.c
index b3d1787338..4d64c29efa 100644
--- a/driver/battery/smart.c
+++ b/driver/battery/smart.c
@@ -590,14 +590,25 @@ int battery_wait_for_stable(void)
BATTERY_NO_RESPONSE_TIMEOUT);
while (get_time().val < wait_timeout) {
/* Starting pinging battery */
- if (battery_status(&status) == EC_SUCCESS) {
- /* Battery is stable */
- CPRINTS("battery responded with status %x", status);
- return EC_SUCCESS;
+ if (battery_status(&status) != EC_SUCCESS) {
+ msleep(25); /* clock stretching could hold 25ms */
+ continue;
+ }
+
+#ifdef CONFIG_BATTERY_STBL_STAT
+ if (((status & CONFIG_BATT_ALARM_MASK1) ==
+ CONFIG_BATT_ALARM_MASK1) ||
+ ((status & CONFIG_BATT_ALARM_MASK2) ==
+ CONFIG_BATT_ALARM_MASK2)) {
+ msleep(25);
+ continue;
}
- msleep(25); /* clock stretching could hold 25ms */
+#endif
+ /* Battery is stable */
+ CPRINTS("battery responded with status %x", status);
+ return EC_SUCCESS;
}
- CPRINTS("battery not responding");
+ CPRINTS("battery not responding with status %x", status);
return EC_ERROR_NOT_POWERED;
}
diff --git a/driver/ppc/ktu1125.c b/driver/ppc/ktu1125.c
index 647512d801..24b03e8538 100644
--- a/driver/ppc/ktu1125.c
+++ b/driver/ppc/ktu1125.c
@@ -348,11 +348,15 @@ static int ktu1125_set_vconn(int port, int enable)
polarity = polarity_rm_dts(pd_get_polarity(port));
if (enable) {
- flags |= polarity ? KTU1125_CC2S_VCONN : KTU1125_CC1S_VCONN;
- status = set_flags(port, KTU1125_SET_SW_CFG, flags);
+ /*
+ * If polarity is CC1, then apply VCONN on CC2.
+ * else if polarity is CC2, then apply VCONN on CC1
+ */
+ flags |= polarity ? KTU1125_CC1S_VCONN : KTU1125_CC2S_VCONN;
+ status = set_flags(port, KTU1125_CTRL_SW_CFG, flags);
} else {
flags |= KTU1125_CC1S_VCONN | KTU1125_CC2S_VCONN;
- status = clr_flags(port, KTU1125_SET_SW_CFG, flags);
+ status = clr_flags(port, KTU1125_CTRL_SW_CFG, flags);
}
return status;
diff --git a/driver/ppc/rt1739.c b/driver/ppc/rt1739.c
index ffd7760986..4679290b67 100644
--- a/driver/ppc/rt1739.c
+++ b/driver/ppc/rt1739.c
@@ -273,7 +273,7 @@ static int rt1739_set_vbus_source_current_limit(int port, enum tcpc_rp_value rp)
return write_reg(port, RT1739_REG_VBUS_OC_SETTING, reg);
}
-static int rt1739_init(int port)
+int rt1739_init(int port)
{
int device_id, oc_setting, sys_ctrl, vbus_switch_ctrl;
bool batt_connected = false;
diff --git a/driver/ppc/rt1739.h b/driver/ppc/rt1739.h
index f4c5e44354..48256da202 100644
--- a/driver/ppc/rt1739.h
+++ b/driver/ppc/rt1739.h
@@ -134,4 +134,6 @@ extern const struct bc12_drv rt1739_bc12_drv;
void rt1739_interrupt(int port);
+int rt1739_init(int port);
+
#endif /* defined(__CROS_EC_PPC_RT1739_H) */
diff --git a/driver/retimer/anx7483.c b/driver/retimer/anx7483.c
index 4b07848b9e..b4532ee12c 100644
--- a/driver/retimer/anx7483.c
+++ b/driver/retimer/anx7483.c
@@ -232,7 +232,7 @@ test_export_static int anx7483_set(const struct usb_mux *me,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
/*
diff --git a/driver/retimer/nb7v904m.c b/driver/retimer/nb7v904m.c
index 2990a906b5..18fdf3b2ba 100644
--- a/driver/retimer/nb7v904m.c
+++ b/driver/retimer/nb7v904m.c
@@ -154,7 +154,7 @@ static int nb7v904m_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
/* Turn off redriver if it's not needed at all. */
diff --git a/driver/retimer/pi3dpx1207.c b/driver/retimer/pi3dpx1207.c
index e40f269e3b..4a4c180f8c 100644
--- a/driver/retimer/pi3dpx1207.c
+++ b/driver/retimer/pi3dpx1207.c
@@ -102,7 +102,7 @@ static int pi3dpx1207_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
/* USB */
diff --git a/driver/retimer/ps8802.c b/driver/retimer/ps8802.c
index e2d93a25b4..24ad0f290f 100644
--- a/driver/retimer/ps8802.c
+++ b/driver/retimer/ps8802.c
@@ -189,7 +189,7 @@ static int ps8802_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
if (chipset_in_state(CHIPSET_STATE_HARD_OFF))
diff --git a/driver/retimer/ps8818.c b/driver/retimer/ps8818.c
index dff1b33a64..1f17146476 100644
--- a/driver/retimer/ps8818.c
+++ b/driver/retimer/ps8818.c
@@ -90,7 +90,7 @@ static int ps8818_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
if (chipset_in_state(CHIPSET_STATE_HARD_OFF))
diff --git a/driver/retimer/tusb544.c b/driver/retimer/tusb544.c
index c2d617c3be..8bac6cedd6 100644
--- a/driver/retimer/tusb544.c
+++ b/driver/retimer/tusb544.c
@@ -61,7 +61,7 @@ static int tusb544_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
if (mux_state == USB_PD_MUX_NONE)
diff --git a/driver/tcpm/anx7447.c b/driver/tcpm/anx7447.c
index 79f08ee655..4760596eae 100644
--- a/driver/tcpm/anx7447.c
+++ b/driver/tcpm/anx7447.c
@@ -664,7 +664,7 @@ static int anx7447_mux_set(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
cc_direction = mux_state & USB_PD_MUX_POLARITY_INVERTED;
diff --git a/driver/tcpm/anx74xx.c b/driver/tcpm/anx74xx.c
index e6ad23c25a..9e3a975754 100644
--- a/driver/tcpm/anx74xx.c
+++ b/driver/tcpm/anx74xx.c
@@ -400,7 +400,7 @@ static int anx74xx_tcpm_mux_set(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
if (!(mux_state & ~USB_PD_MUX_POLARITY_INVERTED)) {
diff --git a/driver/tcpm/anx7688.c b/driver/tcpm/anx7688.c
index 6ad8a16ff4..277edd0217 100644
--- a/driver/tcpm/anx7688.c
+++ b/driver/tcpm/anx7688.c
@@ -154,7 +154,7 @@ static int anx7688_mux_set(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
rv = mux_read(me, TCPC_REG_CONFIG_STD_OUTPUT, &reg);
diff --git a/driver/tcpm/ps8xxx.c b/driver/tcpm/ps8xxx.c
index 9eb3b40b2b..0818b328bf 100644
--- a/driver/tcpm/ps8xxx.c
+++ b/driver/tcpm/ps8xxx.c
@@ -1118,7 +1118,7 @@ static int ps8xxx_mux_set(const struct usb_mux *me, mux_state_t mux_state,
bool *ack_required)
{
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
if (product_id[me->usb_port] == PS8751_PRODUCT_ID &&
diff --git a/driver/tcpm/rt1718s.c b/driver/tcpm/rt1718s.c
index e8ee85368a..a1cdf06c9a 100644
--- a/driver/tcpm/rt1718s.c
+++ b/driver/tcpm/rt1718s.c
@@ -551,15 +551,37 @@ __overridable int board_rt1718s_set_snk_enable(int port, int enable)
return EC_SUCCESS;
}
+__overridable int board_rt1718s_set_src_enable(int port, int enable)
+{
+ return EC_SUCCESS;
+}
+
static int rt1718s_tcpm_set_snk_ctrl(int port, int enable)
{
int rv;
- rv = board_rt1718s_set_snk_enable(port, enable);
+ /* The order matters. Board hook should run after the tcpm call to
+ * prevent the GPIO config auto-reload overwriting a wrong value.
+ */
+ rv = tcpci_tcpm_set_snk_ctrl(port, enable);
+ if (rv)
+ return rv;
+
+ return board_rt1718s_set_snk_enable(port, enable);
+}
+
+static int rt1718s_tcpm_set_src_ctrl(int port, int enable)
+{
+ int rv;
+
+ /* The order matters. Board hook should run after the tcpm call to
+ * prevent the GPIO config auto-reload overwriting a wrong value.
+ */
+ rv = tcpci_tcpm_set_src_ctrl(port, enable);
if (rv)
return rv;
- return tcpci_tcpm_set_snk_ctrl(port, enable);
+ return board_rt1718s_set_src_enable(port, enable);
}
static void rt1718s_alert(int port)
@@ -806,7 +828,7 @@ const struct tcpm_drv rt1718s_tcpm_drv = {
#endif
.get_chip_info = &tcpci_get_chip_info,
.set_snk_ctrl = &rt1718s_tcpm_set_snk_ctrl,
- .set_src_ctrl = &tcpci_tcpm_set_src_ctrl,
+ .set_src_ctrl = &rt1718s_tcpm_set_src_ctrl,
#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
.enter_low_power_mode = &rt1718s_enter_low_power_mode,
#endif
diff --git a/driver/tcpm/rt1718s.h b/driver/tcpm/rt1718s.h
index d14e2bd498..d036c6901a 100644
--- a/driver/tcpm/rt1718s.h
+++ b/driver/tcpm/rt1718s.h
@@ -274,4 +274,13 @@ int rt1718s_sw_reset(int port);
* @return EC_SUCCESS if success, EC_ERROR_UNKNOWN otherwise.
*/
__override_proto int board_rt1718s_set_snk_enable(int port, int enable);
+
+/**
+ * Board hook for rt1718s_set_src_enable
+ *
+ * @param port USB-C port
+ * @param enable enable/disable source
+ * @return EC_SUCCESS if success, EC_ERROR_UNKNOWN otherwise.
+ */
+__override_proto int board_rt1718s_set_src_enable(int port, int enable);
#endif /* __CROS_EC_USB_PD_TCPM_MT6370_H */
diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c
index b78cfbb74c..ffadcab8c0 100644
--- a/driver/tcpm/tcpci.c
+++ b/driver/tcpm/tcpci.c
@@ -1635,7 +1635,7 @@ int tcpci_tcpm_mux_set(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
/* Parameter is port only */
diff --git a/driver/usb_mux/amd_fp5.c b/driver/usb_mux/amd_fp5.c
index ca042b0fa0..b5aa6d2669 100644
--- a/driver/usb_mux/amd_fp5.c
+++ b/driver/usb_mux/amd_fp5.c
@@ -50,7 +50,7 @@ static int amd_fp5_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
saved_mux_state[me->usb_port] = mux_state;
diff --git a/driver/usb_mux/amd_fp6.c b/driver/usb_mux/amd_fp6.c
index a776a696f7..ff3b6eacb8 100644
--- a/driver/usb_mux/amd_fp6.c
+++ b/driver/usb_mux/amd_fp6.c
@@ -142,7 +142,7 @@ static int amd_fp6_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
if (mux_state == USB_PD_MUX_NONE)
diff --git a/driver/usb_mux/anx3443.c b/driver/usb_mux/anx3443.c
index f3b0b08afd..e8c2621a54 100644
--- a/driver/usb_mux/anx3443.c
+++ b/driver/usb_mux/anx3443.c
@@ -97,7 +97,7 @@ static int anx3443_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
saved_mux_state[me->usb_port].mux_state = mux_state;
diff --git a/driver/usb_mux/anx7440.c b/driver/usb_mux/anx7440.c
index 456eaaa407..5a80487e05 100644
--- a/driver/usb_mux/anx7440.c
+++ b/driver/usb_mux/anx7440.c
@@ -69,7 +69,7 @@ static int anx7440_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
res = anx7440_read(me, ANX7440_REG_CHIP_CTRL, &reg);
diff --git a/driver/usb_mux/anx7451.c b/driver/usb_mux/anx7451.c
index b974128740..127f0b8e67 100644
--- a/driver/usb_mux/anx7451.c
+++ b/driver/usb_mux/anx7451.c
@@ -97,7 +97,7 @@ static int anx7451_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
/*
diff --git a/driver/usb_mux/it5205.c b/driver/usb_mux/it5205.c
index de3d950c86..a773a51d0e 100644
--- a/driver/usb_mux/it5205.c
+++ b/driver/usb_mux/it5205.c
@@ -100,7 +100,7 @@ static int it5205_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
switch (mux_state & MUX_STATE_DP_USB_MASK) {
diff --git a/driver/usb_mux/pi3usb3x532.c b/driver/usb_mux/pi3usb3x532.c
index 54eff928b7..42d13ca835 100644
--- a/driver/usb_mux/pi3usb3x532.c
+++ b/driver/usb_mux/pi3usb3x532.c
@@ -89,7 +89,7 @@ static int pi3usb3x532_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
if (mux_state & USB_PD_MUX_USB_ENABLED)
diff --git a/driver/usb_mux/ps8740.c b/driver/usb_mux/ps8740.c
index 557c4f1976..2b412ac35a 100644
--- a/driver/usb_mux/ps8740.c
+++ b/driver/usb_mux/ps8740.c
@@ -77,7 +77,7 @@ static int ps8740_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
if (mux_state & USB_PD_MUX_USB_ENABLED)
diff --git a/driver/usb_mux/ps8743.c b/driver/usb_mux/ps8743.c
index 86f0a7f9b2..6c123bb50c 100644
--- a/driver/usb_mux/ps8743.c
+++ b/driver/usb_mux/ps8743.c
@@ -126,7 +126,7 @@ static int ps8743_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
if (mux_state & USB_PD_MUX_USB_ENABLED)
diff --git a/driver/usb_mux/ps8822.c b/driver/usb_mux/ps8822.c
index d3ea76965d..97d1158f99 100644
--- a/driver/usb_mux/ps8822.c
+++ b/driver/usb_mux/ps8822.c
@@ -84,7 +84,7 @@ static int ps8822_set_mux(const struct usb_mux *me, mux_state_t mux_state,
*ack_required = false;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
rv = ps8822_read(me, PS8822_REG_PAGE0, PS8822_REG_MODE, &reg);
diff --git a/driver/usb_mux/tusb1064.c b/driver/usb_mux/tusb1064.c
index 9dc25d0d01..266e36a2eb 100644
--- a/driver/usb_mux/tusb1064.c
+++ b/driver/usb_mux/tusb1064.c
@@ -97,7 +97,7 @@ int tusb1064_set_mux(const struct usb_mux *me, mux_state_t mux_state,
int mask;
/* This driver treats safe mode as none */
- if (mux_state == USB_PD_MUX_SAFE_MODE)
+ if (mux_state & USB_PD_MUX_SAFE_MODE)
mux_state = USB_PD_MUX_NONE;
rv = tusb1064_read(me, TUSB1064_REG_GENERAL, &reg);
diff --git a/driver/usb_mux/usb_mux.c b/driver/usb_mux/usb_mux.c
index 334b7f2f2d..ceabe7f8c8 100644
--- a/driver/usb_mux/usb_mux.c
+++ b/driver/usb_mux/usb_mux.c
@@ -514,8 +514,7 @@ static void perform_mux_set(int port, int index, mux_state_t mux_mode,
return;
/* Configure superspeed lanes */
- mux_state = ((mux_mode != USB_PD_MUX_NONE) &&
- (mux_mode != USB_PD_MUX_SAFE_MODE) && polarity) ?
+ mux_state = ((mux_mode != USB_PD_MUX_NONE) && polarity) ?
mux_mode | USB_PD_MUX_POLARITY_INVERTED :
mux_mode;
diff --git a/include/charge_state.h b/include/charge_state.h
index 34576dc333..ed7ca0a4d9 100644
--- a/include/charge_state.h
+++ b/include/charge_state.h
@@ -83,7 +83,7 @@ enum led_pwr_state {
* only to control the LEDs (with one not-quite-correct exception). For V2
* we use a different set of states internally.
*/
-enum charge_state_v2 {
+enum charge_state {
ST_IDLE = 0,
ST_DISCHARGE,
ST_CHARGE,
@@ -98,7 +98,7 @@ struct charge_state_data {
int batt_is_charging;
struct charger_params chg;
struct batt_params batt;
- enum charge_state_v2 state;
+ enum charge_state state;
int requested_voltage;
int requested_current;
int desired_input_current;
@@ -126,7 +126,7 @@ enum led_pwr_state led_pwr_get_state(void);
/**
* Return current charge v2 state.
*/
-__test_only enum charge_state_v2 charge_get_state_v2(void);
+__test_only enum charge_state charge_get_state(void);
/**
* Return non-zero if battery is so low we want to keep AP off.
diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h
deleted file mode 100644
index 72fd8a88ff..0000000000
--- a/include/charge_state_v2.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/* Copyright 2014 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_CHARGE_STATE_V2_H
-#define __CROS_EC_CHARGE_STATE_V2_H
-
-#endif /* __CROS_EC_CHARGE_STATE_V2_H */
diff --git a/include/config.h b/include/config.h
index a3a2edb1ed..dfc684f278 100644
--- a/include/config.h
+++ b/include/config.h
@@ -665,6 +665,12 @@
#undef CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV
/*
+ * Check the specific battery status to judge whether the battery is
+ * initialized and stable when the battery wakes up from ship mode.
+ */
+#undef CONFIG_BATTERY_STBL_STAT
+
+/*
* Some batteries don't update full capacity timely or don't update it at all.
* On such systems, compensation is required to guarantee remaining_capacity
* will be equal to full_capacity eventually. This used to be done in ACPI.
@@ -6411,6 +6417,33 @@
#define CONFIG_BATTERY_V1
#endif
+/*
+ * Check the specific battery status to judge whether the battery is
+ * initialized and stable when the battery wakes up from ship mode.
+ * Use two MASKs to provide logical AND and logical OR options for different
+ * status. For example:
+ *
+ * Logical OR -- just check one of TCA/TDA mask:
+ * #define CONFIG_BATT_ALARM_MASK1 \
+ * (STATUS_TERMINATE_CHARGE_ALARM | STATUS_TERMINATE_DISCHARGE_ALARM)
+ * #define CONFIG_BATT_ALARM_MASK2 0xFFFF
+ *
+ * Logical AND -- check both TCA/TDA mask:
+ * #define CONFIG_BATT_ALARM_MASK1 STATUS_TERMINATE_CHARGE_ALARM
+ * #define CONFIG_BATT_ALARM_MASK2 STATUS_TERMINATE_DISCHARGE_ALARM
+ *
+ * The default configuration is logical OR.
+ */
+#ifdef CONFIG_BATTERY_STBL_STAT
+#ifndef CONFIG_BATT_ALARM_MASK1
+#define CONFIG_BATT_ALARM_MASK1 \
+ (STATUS_TERMINATE_CHARGE_ALARM | STATUS_TERMINATE_DISCHARGE_ALARM)
+#endif
+#ifndef CONFIG_BATT_ALARM_MASK2
+#define CONFIG_BATT_ALARM_MASK2 0xFFFF
+#endif
+#endif
+
/*****************************************************************************/
/* Define derived USB PD Discharge common path */
#if defined(CONFIG_USB_PD_DISCHARGE_GPIO) || \
diff --git a/include/crypto/elliptic_curve_key.h b/include/crypto/elliptic_curve_key.h
new file mode 100644
index 0000000000..1e56f5d428
--- /dev/null
+++ b/include/crypto/elliptic_curve_key.h
@@ -0,0 +1,20 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Helpers for the boringssl elliptic curve key interface. */
+
+#ifndef __CROS_EC_ELLIPTIC_CURVE_KEY_H
+#define __CROS_EC_ELLIPTIC_CURVE_KEY_H
+
+#include "openssl/ec_key.h"
+#include "openssl/mem.h"
+
+/**
+ * Generate a p256 ECC key.
+ * @return key on success, nullptr on failure
+ */
+bssl::UniquePtr<EC_KEY> generate_elliptic_curve_key();
+
+#endif /* __CROS_EC_ELLIPTIC_CURVE_KEY_H */
diff --git a/include/lid_switch.h b/include/lid_switch.h
index 3d639b5782..8b62d89949 100644
--- a/include/lid_switch.h
+++ b/include/lid_switch.h
@@ -5,6 +5,12 @@
/* Lid switch API for Chrome EC */
+/*
+ * TODO(b/272518464): Work around coreboot GCC preprocessor bug.
+ * #line marks the *next* line, so it is off by one.
+ */
+#line 13
+
#ifndef __CROS_EC_LID_SWITCH_H
#define __CROS_EC_LID_SWITCH_H
diff --git a/include/system.h b/include/system.h
index c7884199e1..064656fd5f 100644
--- a/include/system.h
+++ b/include/system.h
@@ -5,6 +5,12 @@
/* System module for Chrome EC */
+/*
+ * TODO(b/272518464): Work around coreboot GCC preprocessor bug.
+ * #line marks the *next* line, so it is off by one.
+ */
+#line 13
+
#ifndef __CROS_EC_SYSTEM_H
#define __CROS_EC_SYSTEM_H
diff --git a/include/test_util.h b/include/test_util.h
index 4f9869ab61..54da6a1d6c 100644
--- a/include/test_util.h
+++ b/include/test_util.h
@@ -19,6 +19,7 @@ extern "C" {
#include "ec_commands.h"
#include "math_util.h"
#include "stack_trace.h"
+#include "string.h"
#ifdef CONFIG_ZTEST
#include "ec_tasks.h"
@@ -115,6 +116,19 @@ extern "C" {
} \
} while (0)
+#define TEST_ASSERT_ARRAY_NE(s, d, n) \
+ do { \
+ if (n < 0) \
+ return EC_ERROR_UNKNOWN; \
+ \
+ if (memcmp(&s[0], &d[0], n) == 0) { \
+ ccprintf("%s:%d: ASSERT_ARRAY_NE failed\n", __FILE__, \
+ __LINE__); \
+ task_dump_trace(); \
+ return EC_ERROR_UNKNOWN; \
+ } \
+ } while (0)
+
#define TEST_ASSERT_MEMSET(d, c, n) \
do { \
if (n < 0) \
diff --git a/include/trng.h b/include/trng.h
index ca8144eeec..06fbcc8544 100644
--- a/include/trng.h
+++ b/include/trng.h
@@ -26,6 +26,13 @@
void trng_init(void);
/**
+ * Generate true random number.
+ *
+ * Not supported by all platforms.
+ **/
+uint32_t trng_rand(void);
+
+/**
* Shutdown the true random number generator.
*
* The opposite operation of trng_init(), disable the hardware resources
diff --git a/test/boringssl_crypto.cc b/test/boringssl_crypto.cc
new file mode 100644
index 0000000000..c04b391854
--- /dev/null
+++ b/test/boringssl_crypto.cc
@@ -0,0 +1,66 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "common.h"
+#include "crypto/elliptic_curve_key.h"
+#include "openssl/bn.h"
+#include "openssl/ec.h"
+#include "openssl/mem.h"
+#include "openssl/obj_mac.h"
+#include "openssl/rand.h"
+#include "test_util.h"
+#include "util.h"
+
+test_static enum ec_error_list test_rand(void)
+{
+ constexpr uint8_t zero[256] = { 0 };
+ uint8_t buf1[256];
+ uint8_t buf2[256];
+
+ RAND_bytes(buf1, sizeof(buf1));
+ RAND_bytes(buf2, sizeof(buf2));
+
+ TEST_ASSERT_ARRAY_NE(buf1, zero, sizeof(zero));
+ TEST_ASSERT_ARRAY_NE(buf2, zero, sizeof(zero));
+ TEST_ASSERT_ARRAY_NE(buf1, buf2, sizeof(buf1));
+
+ return EC_SUCCESS;
+}
+
+test_static enum ec_error_list test_ecc_keygen(void)
+{
+ bssl::UniquePtr<EC_KEY> key1 = generate_elliptic_curve_key();
+
+ TEST_NE(key1.get(), nullptr, "%p");
+
+ /* The generated key should be valid.*/
+ TEST_EQ(EC_KEY_check_key(key1.get()), 1, "%d");
+
+ bssl::UniquePtr<EC_KEY> key2 = generate_elliptic_curve_key();
+
+ TEST_NE(key2.get(), nullptr, "%p");
+
+ /* The generated key should be valid. */
+ TEST_EQ(EC_KEY_check_key(key2.get()), 1, "%d");
+
+ const BIGNUM *priv1 = EC_KEY_get0_private_key(key1.get());
+ const BIGNUM *priv2 = EC_KEY_get0_private_key(key2.get());
+
+ /* The generated keys should not be the same. */
+ TEST_NE(BN_cmp(priv1, priv2), 0, "%d");
+
+ /* The generated keys should not be zero. */
+ TEST_EQ(BN_is_zero(priv1), 0, "%d");
+ TEST_EQ(BN_is_zero(priv2), 0, "%d");
+
+ return EC_SUCCESS;
+}
+
+extern "C" void run_test(int argc, const char **argv)
+{
+ RUN_TEST(test_rand);
+ RUN_TEST(test_ecc_keygen);
+ test_print_result();
+}
diff --git a/test/boringssl_crypto.tasklist b/test/boringssl_crypto.tasklist
new file mode 100644
index 0000000000..d1920322a9
--- /dev/null
+++ b/test/boringssl_crypto.tasklist
@@ -0,0 +1,9 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TEST_TASK_LIST
diff --git a/test/build.mk b/test/build.mk
index 2d2f9341a3..d90e8daf26 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -28,6 +28,7 @@ test-list-host += benchmark
test-list-host += bklight_lid
test-list-host += bklight_passthru
test-list-host += body_detection
+test-list-host += boringssl_crypto
test-list-host += button
test-list-host += cbi
test-list-host += cbi_wp
@@ -181,6 +182,7 @@ benchmark-y=benchmark.o
bklight_lid-y=bklight_lid.o
bklight_passthru-y=bklight_passthru.o
body_detection-y=body_detection.o body_detection_data_literals.o motion_common.o
+boringssl_crypto-y=boringssl_crypto.o
button-y=button.o
cbi-y=cbi.o
cbi_wp-y=cbi_wp.o
@@ -277,6 +279,7 @@ timer_calib-y=timer_calib.o
timer_dos-y=timer_dos.o
timer-y=timer.o
tpm_seed_clear-y=tpm_seed_clear.o
+unaligned_access-y=unaligned_access.o
uptime-y=uptime.o
usb_common-y=usb_common_test.o fake_battery.o
usb_pd_int-y=usb_pd_int.o
diff --git a/test/run_device_tests.py b/test/run_device_tests.py
index f385441f6d..e874d08bb7 100755
--- a/test/run_device_tests.py
+++ b/test/run_device_tests.py
@@ -230,6 +230,7 @@ class AllTests:
TestConfig(test_name="aes"),
TestConfig(test_name="always_memset"),
TestConfig(test_name="benchmark"),
+ TestConfig(test_name="boringssl_crypto"),
TestConfig(test_name="cec"),
TestConfig(test_name="cortexm_fpu"),
TestConfig(test_name="crc"),
@@ -332,6 +333,7 @@ class AllTests:
TestConfig(test_name="timer"),
TestConfig(test_name="timer_dos"),
TestConfig(test_name="tpm_seed_clear"),
+ TestConfig(test_name="unaligned_access"),
TestConfig(test_name="utils", timeout_secs=20),
TestConfig(test_name="utils_str"),
]
diff --git a/test/sbs_charging_v2.c b/test/sbs_charging_v2.c
index 482770ff1c..7c20bbe4ac 100644
--- a/test/sbs_charging_v2.c
+++ b/test/sbs_charging_v2.c
@@ -2,7 +2,7 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
- * Test charge_state_v2 behavior
+ * Test charge_state behavior
*/
#include "battery_smart.h"
@@ -367,7 +367,7 @@ test_static int test_low_battery(void)
test_static int test_deep_charge_battery(void)
{
- enum charge_state_v2 state_v2;
+ enum charge_state state;
const struct battery_info *bat_info = battery_get_info();
test_setup(1);
@@ -375,22 +375,22 @@ test_static int test_deep_charge_battery(void)
/* battery pack voltage bellow voltage_min */
sb_write(SB_VOLTAGE, (bat_info->voltage_min - 200));
wait_charging_state();
- state_v2 = charge_get_state_v2();
- TEST_ASSERT(state_v2 == ST_PRECHARGE);
+ state = charge_get_state();
+ TEST_ASSERT(state == ST_PRECHARGE);
/*
* Battery voltage keep bellow voltage_min,
* precharge over time CONFIG_BATTERY_LOW_VOLTAGE_TIMEOUT
*/
usleep(CONFIG_BATTERY_LOW_VOLTAGE_TIMEOUT);
- state_v2 = charge_get_state_v2();
- TEST_ASSERT(state_v2 == ST_IDLE);
+ state = charge_get_state();
+ TEST_ASSERT(state == ST_IDLE);
/* recovery from a low voltage. */
sb_write(SB_VOLTAGE, (bat_info->voltage_normal));
wait_charging_state();
- state_v2 = charge_get_state_v2();
- TEST_ASSERT(state_v2 == ST_CHARGE);
+ state = charge_get_state();
+ TEST_ASSERT(state == ST_CHARGE);
return EC_SUCCESS;
}
diff --git a/test/test_config.h b/test/test_config.h
index 51c15f4c8c..033ee966b7 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -114,6 +114,10 @@
#define CONFIG_SHA256
#endif
+#if defined(TEST_BORINGSSL_CRYPTO)
+#define CONFIG_BORINGSSL_CRYPTO
+#endif
+
#ifdef TEST_ROLLBACK_SECRET
#define CONFIG_ROLLBACK
#define CONFIG_ROLLBACK_SECRET_SIZE 32
diff --git a/test/unaligned_access.cc b/test/unaligned_access.cc
new file mode 100644
index 0000000000..f3dc99d432
--- /dev/null
+++ b/test/unaligned_access.cc
@@ -0,0 +1,157 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * Test if unaligned access works properly
+ */
+
+#include "common.h"
+#include "console.h"
+#include "test_util.h"
+
+extern "C" {
+#include "shared_mem.h"
+#include "timer.h"
+}
+
+#include <array>
+#include <cstdio>
+#include <cstring>
+
+test_static int test_unaligned_access()
+{
+ /* This is equivalent to {0xff, 0x09, 0x04, 0x06, 0x04, 0x06, 0x07,
+ * 0xed, 0x0a, 0x0b, 0x0d, 0x38, 0xbd, 0x57, 0x59} */
+ alignas(int32_t) constexpr std::array<int8_t, 15> test_array = {
+ -1, 9, 4, 6, 4, 6, 7, -19, 10, 11, 13, 56, -67, 87, 89
+ };
+
+ constexpr std::array<int32_t, 12> expected_results = {
+ 0x060409ff,
+ 0x04060409,
+ 0x06040604,
+ 0x07060406,
+ static_cast<int32_t>(0xed070604),
+ 0x0aed0706,
+ 0x0b0aed07,
+ 0x0d0b0aed,
+ 0x380d0b0a,
+ static_cast<int32_t>(0xbd380d0b),
+ 0x57bd380d,
+ 0x5957bd38
+ };
+
+ /* If i % 4 = 0, we have an aligned access. Otherwise, it is
+ unaligned access. */
+ for (int i = 0; i < expected_results.size(); ++i) {
+ const int32_t *test_array_ptr =
+ reinterpret_cast<const int32_t *>(test_array.data() +
+ i);
+
+ TEST_EQ(*test_array_ptr, expected_results[i], "0x%08x");
+ }
+
+ return EC_SUCCESS;
+}
+
+test_static int benchmark_unaligned_access_memcpy()
+{
+ int i;
+ timestamp_t t0, t1, t2, t3;
+ char *buf;
+ const int buf_size = 1000;
+ const int len = 400;
+ const int dest_offset = 500;
+ const int iteration = 1000;
+
+ TEST_ASSERT(shared_mem_acquire(buf_size, &buf) == EC_SUCCESS);
+
+ for (i = 0; i < len; ++i)
+ buf[i] = i & 0x7f;
+ for (i = len; i < buf_size; ++i)
+ buf[i] = 0;
+
+ t0 = get_time();
+ for (i = 0; i < iteration; ++i) {
+ memcpy(buf + dest_offset + 1, buf, len); /* unaligned */
+ }
+ t1 = get_time();
+ TEST_ASSERT_ARRAY_EQ(buf + dest_offset + 1, buf, len);
+ ccprintf(" (speed gain: %" PRId64 " ->", t1.val - t0.val);
+
+ t2 = get_time();
+ for (i = 0; i < iteration; ++i) {
+ memcpy(buf + dest_offset, buf, len); /* aligned */
+ }
+ t3 = get_time();
+ ccprintf(" %" PRId64 " us) ", t3.val - t2.val);
+ TEST_ASSERT_ARRAY_EQ(buf + dest_offset, buf, len);
+ return EC_SUCCESS;
+}
+
+test_static int benchmark_unaligned_access_array()
+{
+ timestamp_t t0, t1, t2, t3;
+ const int iteration = 1000;
+
+ alignas(int32_t) std::array<int8_t, 100> test_array_1;
+ std::array<int32_t, 20> test_array_2;
+ constexpr std::array<int32_t, 20> test_array_3 = {
+ 67305985, 134678021, 202050057, 269422093, 336794129,
+ 404166165, 471538201, 538910237, 606282273, 673654309,
+ 741026345, 808398381, 875770417, 943142453, 1010514489,
+ 1077886525, 1145258561, 1212630597, 1280002633, 1347374669
+ };
+ constexpr std::array<int32_t, 20> test_array_4 = {
+ 50462976, 117835012, 185207048, 252579084, 319951120,
+ 387323156, 454695192, 522067228, 589439264, 656811300,
+ 724183336, 791555372, 858927408, 926299444, 993671480,
+ 1061043516, 1128415552, 1195787588, 1263159624, 1330531660
+ };
+
+ for (int i = 0; i < test_array_1.size(); ++i) {
+ test_array_1[i] = static_cast<int8_t>(i);
+ }
+
+ t0 = get_time();
+ for (int t = 0; t < iteration; ++t) {
+ const int32_t *test_array_1_ptr =
+ reinterpret_cast<const int32_t *>(test_array_1.data() +
+ 1);
+
+ for (int i = 0; i < test_array_2.size(); ++i) {
+ test_array_2[i] = (*test_array_1_ptr++); /* unaligned */
+ }
+ TEST_ASSERT_ARRAY_EQ(test_array_2.data(), test_array_3.data(),
+ test_array_2.size());
+ }
+ t1 = get_time();
+ ccprintf(" (speed gain: %" PRId64 " ->", t1.val - t0.val);
+
+ t2 = get_time();
+ for (int t = 0; t < iteration; ++t) {
+ const int32_t *test_array_1_ptr =
+ reinterpret_cast<const int32_t *>(test_array_1.data());
+
+ for (int i = 0; i < test_array_2.size(); ++i) {
+ test_array_2[i] = (*test_array_1_ptr++); /* aligned */
+ }
+ TEST_ASSERT_ARRAY_EQ(test_array_2.data(), test_array_4.data(),
+ test_array_2.size());
+ }
+ t3 = get_time();
+ ccprintf(" %" PRId64 " us) ", t3.val - t2.val);
+
+ return EC_SUCCESS;
+}
+
+extern "C" void run_test(int, const char **)
+{
+ test_reset();
+ RUN_TEST(test_unaligned_access);
+ RUN_TEST(benchmark_unaligned_access_memcpy);
+ RUN_TEST(benchmark_unaligned_access_array);
+ test_print_result();
+}
diff --git a/test/unaligned_access.tasklist b/test/unaligned_access.tasklist
new file mode 100644
index 0000000000..2d177cee59
--- /dev/null
+++ b/test/unaligned_access.tasklist
@@ -0,0 +1,9 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TEST_TASK_LIST \ No newline at end of file
diff --git a/third_party/boringssl/common/build.mk b/third_party/boringssl/common/build.mk
new file mode 100644
index 0000000000..b7848d121b
--- /dev/null
+++ b/third_party/boringssl/common/build.mk
@@ -0,0 +1,8 @@
+# Copyright 2023 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# EC OS Support Files for BoringSSL
+#
+
+boringssl-y+=sysrand.o
diff --git a/third_party/boringssl/common/sysrand.c b/third_party/boringssl/common/sysrand.c
new file mode 100644
index 0000000000..74e058f892
--- /dev/null
+++ b/third_party/boringssl/common/sysrand.c
@@ -0,0 +1,20 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Implement the boringssl sysrand from EC TRNG. */
+
+#include "trng.h"
+
+void CRYPTO_sysrand(uint8_t *out, size_t requested)
+{
+ trng_init();
+ trng_rand_bytes(out, requested);
+ trng_exit();
+}
+
+void CRYPTO_sysrand_for_seed(uint8_t *out, size_t requested)
+{
+ return CRYPTO_sysrand(out, requested);
+}
diff --git a/util/check_low_coverage_reason.py b/util/check_low_coverage_reason.py
new file mode 100755
index 0000000000..c6119f6a6a
--- /dev/null
+++ b/util/check_low_coverage_reason.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+# Copyright 2023 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Ensure commit messages using LOW_COVERAGE_REASON include a bug."""
+
+import logging
+import pathlib
+import re
+import sys
+
+from chromite.lib import commandline
+from chromite.lib import cros_build_lib
+from chromite.lib import git
+
+
+# Look for LOW_COVERAGE_REASON and then an optional b{:|/}number bug reference.
+LOW_COV_REGEX = re.compile(
+ r"\s*(LOW_COVERAGE_REASON=)(?:(?!b[/|:][\d]+).)*(b[/|:]([\d]+))?"
+)
+EC_BASE = pathlib.Path(__file__).resolve().parent.parent
+
+
+def main(argv=None):
+ """Check for bug in LOW_COVERAGE_REASON."""
+ parser = commandline.ArgumentParser()
+ parser.add_argument(
+ "commit_id",
+ help="Commit whose message will be checked.",
+ )
+ opts = parser.parse_args(argv)
+
+ if opts.commit_id == "pre-submit":
+ # Only run check if verifying an actual commit.
+ return 0
+
+ try:
+ commit_log = git.Log(EC_BASE, rev=opts.commit_id, max_count=1)
+ except cros_build_lib.RunCommandError as err:
+ logging.error("Unable to query git log: %s", str(err))
+ return 1
+
+ # Search commit message for LOW_COVERAGE_REASON and bug
+ matches = LOW_COV_REGEX.findall(commit_log)
+ if matches and not any({m[2] for m in matches}):
+ # We have LOW_COVERAGE_REASON line(s) but none include a bug
+ logging.error(
+ "LOW_COVERAGE_REASON line must include one or more bugs "
+ "tracking the reason for missing coverage"
+ )
+ return 1
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv[1:]))
diff --git a/util/ec_openocd.py b/util/ec_openocd.py
index 5da0479ed9..b8c9364bd8 100755
--- a/util/ec_openocd.py
+++ b/util/ec_openocd.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
-
# 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.
+
"""
Flashes and debugs the EC through openocd
"""
@@ -123,7 +123,6 @@ def debug(interface, board, port, executable, attach):
stderr=subprocess.STDOUT,
preexec_fn=os.setsid,
) as openocd:
-
# Wait for OpenOCD to start, it'll open a port for GDB connections
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connected = False
@@ -237,10 +236,10 @@ def main():
)
flash_parser.set_defaults(command="flash")
flash_parser.add_argument(
- "--verify",
- "-v",
- default=True,
- help="Verify flash after writing image, defaults to true",
+ "--no-verify",
+ "-n",
+ action="store_true",
+ help="Do not verify flash after writing image",
)
debug_parser = sub_parsers.add_parser(
@@ -279,7 +278,7 @@ def main():
image_file = (
get_flash_file(args.board) if target_file is None else target_file
)
- flash(args.interface, args.board, image_file, args.verify)
+ flash(args.interface, args.board, image_file, not args.no_verify)
elif args.command == "debug":
executable_file = (
get_executable_file(args.board)
diff --git a/zephyr/Kconfig.battery b/zephyr/Kconfig.battery
index 01d42567ab..2247e30cff 100644
--- a/zephyr/Kconfig.battery
+++ b/zephyr/Kconfig.battery
@@ -178,6 +178,49 @@ config PLATFORM_EC_BATTERY_MAX_IMBALANCE_MV
system tolerant of larger values of
CONFIG_PLATFORM_EC_BATTERY_MAX_IMBALANCE_MV.
+config PLATFORM_EC_BATTERY_STBL_STAT
+ bool "Check whether the battery is initialized and stable"
+ help
+ Enables support for checking the specific battery status to
+ judge whether the battery is initialized and stable when the battery
+ wakes up from ship mode. Use two MASKs to provide logical AND and
+ logical OR options for different status.
+
+ For example:
+ STATUS_TERMINATE_CHARGE_ALARM(TCA):0x4000
+ STATUS_TERMINATE_DISCHARGE_ALARM(TDA):0x0800
+
+ Logical OR -- just check one of TCA/TDA mask:
+ CONFIG_PLATFORM_EC_BATT_ALARM_MASK1=(0x4000 | 0x0800)
+ CONFIG_PLATFORM_EC_BATT_ALARM_MASK2=0xFFFF
+
+ Logical AND -- check both TCA/TDA mask:
+ CONFIG_PLATFORM_EC_BATT_ALARM_MASK1=0x4000
+ CONFIG_PLATFORM_EC_BATT_ALARM_MASK2=0x0800
+
+ The default configuration is logical OR.
+
+if PLATFORM_EC_BATTERY_STBL_STAT
+
+config PLATFORM_EC_BATT_ALARM_MASK1
+ hex "The battery status mask"
+ default 0x4800
+ help
+ Use two MASKs to provide logical AND and logical OR options for different
+ status. Default mask 0x4800 means
+ (STATUS_TERMINATE_CHARGE_ALARM | STATUS_TERMINATE_DISCHARGE_ALARM),
+ any one of these two masks is set, the battery state can be considered
+ stable.
+
+config PLATFORM_EC_BATT_ALARM_MASK2
+ hex "The battery status mask"
+ default 0xFFFF
+ help
+ Use two MASKs to provide logical AND and logical OR options for different
+ status. Default mask 0xFFFF means do not use this mask.
+
+endif # PLATFORM_EC_BATTERY_STBL_STAT
+
config PLATFORM_EC_CHARGER_MIN_BAT_PCT_IMBALANCED_POWER_ON
int "Minimum battery percentage for power on with an imbalanced pack"
depends on PLATFORM_EC_BATTERY_MEASURE_IMBALANCE
diff --git a/zephyr/emul/emul_amd_fp6.c b/zephyr/emul/emul_amd_fp6.c
index dfb763e1c8..b0b618fd6a 100644
--- a/zephyr/emul/emul_amd_fp6.c
+++ b/zephyr/emul/emul_amd_fp6.c
@@ -28,8 +28,8 @@ enum amd_fp6_read_bytes {
struct amd_fp6_data {
struct i2c_common_emul_data common;
- int64_t finish_delay; /* How long before mux set "completes"? */
- int64_t set_time; /* Time of last set call */
+ int finish_delay; /* How many reads before mux set "completes"? */
+ int waiting_reads; /* How many reads have we waited to complete? */
uint8_t last_mux_set; /* Last value of mux set call */
uint8_t regs[AMD_FP6_MAX_REG];
};
@@ -58,11 +58,11 @@ void amd_fp6_emul_reset_regs(const struct emul *emul)
data->regs[AMD_FP6_PORT1] = 0;
}
-void amd_fp6_emul_set_delay(const struct emul *emul, int delay_ms)
+void amd_fp6_emul_set_delay(const struct emul *emul, int delay_reads)
{
struct amd_fp6_data *data = (struct amd_fp6_data *)emul->data;
- data->finish_delay = delay_ms;
+ data->finish_delay = delay_reads;
}
void amd_fp6_emul_set_xbar(const struct emul *emul, bool ready)
@@ -87,11 +87,11 @@ static int amd_fp6_emul_read(const struct emul *emul, int reg, uint8_t *val,
/* Decide if we've finally finished our operation */
if (pos == AMD_FP6_PORT0 && data->finish_delay > 0) {
- int64_t uptime = k_uptime_delta(&data->set_time);
+ data->waiting_reads++;
if (((regs[pos] >> AMD_FP6_MUX_PORT_STATUS_OFFSET) ==
AMD_FP6_MUX_PORT_CMD_BUSY) &&
- (uptime >= data->finish_delay))
+ (data->waiting_reads >= data->finish_delay))
regs[pos] =
amd_fp6_emul_mux_complete(data->last_mux_set);
}
@@ -113,11 +113,13 @@ static int amd_fp6_emul_write(const struct emul *emul, int reg, uint8_t val,
data->last_mux_set = val;
- if (data->finish_delay == 0)
+ if (data->finish_delay == 0) {
regs[AMD_FP6_PORT0] = amd_fp6_emul_mux_complete(val);
- else
+ } else {
+ data->waiting_reads = 0;
regs[AMD_FP6_PORT0] = AMD_FP6_MUX_PORT_CMD_BUSY
<< AMD_FP6_MUX_PORT_STATUS_OFFSET;
+ }
return 0;
}
diff --git a/zephyr/include/cros/thermistor/thermistor.dtsi b/zephyr/include/cros/thermistor/thermistor.dtsi
index fb86c4f79a..42eb07f483 100644
--- a/zephyr/include/cros/thermistor/thermistor.dtsi
+++ b/zephyr/include/cros/thermistor/thermistor.dtsi
@@ -386,4 +386,85 @@
sample-index = <12>;
};
};
+
+ /omit-if-no-ref/ thermistor_1V8_100K_100K_4250B:
+ thermistor-1V9-100K-100K-4250B {
+ status = "disabled";
+ compatible = "cros-ec,thermistor";
+ scaling-factor = <7>;
+ num-pairs = <13>;
+ steinhart-reference-mv = <1800>;
+ steinhart-reference-res = <100000>;
+
+ /*
+ * Data derived from Steinhart-Hart equation in a resistor
+ * divider circuit with Vdd=1800mV, R = 100Kohm, and thermistor
+ * (B = 4250, T0 = 357 K, nominal resistance (R0) = 100Kohm).
+ */
+ sample-datum-0 {
+ milivolt = <(1406 / 7)>;
+ temp = <0>;
+ sample-index = <0>;
+ };
+ sample-datum-1 {
+ milivolt = <(1219 / 7)>;
+ temp = <10>;
+ sample-index = <1>;
+ };
+ sample-datum-2 {
+ milivolt = <(1007 / 7)>;
+ temp = <20>;
+ sample-index = <2>;
+ };
+ sample-datum-3 {
+ milivolt = <(796 / 7)>;
+ temp = <30>;
+ sample-index = <3>;
+ };
+ sample-datum-4 {
+ milivolt = <(606 / 7)>;
+ temp = <40>;
+ sample-index = <4>;
+ };
+ sample-datum-5 {
+ milivolt = <( 449 / 7)>;
+ temp = <50>;
+ sample-index = <5>;
+ };
+ sample-datum-6 {
+ milivolt = <( 327 / 7)>;
+ temp = <60>;
+ sample-index = <6>;
+ };
+ sample-datum-7 {
+ milivolt = <( 237 / 7)>;
+ temp = <70>;
+ sample-index = <7>;
+ };
+ sample-datum-8 {
+ milivolt = <( 172 / 7)>;
+ temp = <80>;
+ sample-index = <8>;
+ };
+ sample-datum-9 {
+ milivolt = <( 147 / 7)>;
+ temp = <85>;
+ sample-index = <9>;
+ };
+ sample-datum-10 {
+ milivolt = <( 125 / 7)>;
+ temp = <90>;
+ sample-index = <10>;
+ };
+ sample-datum-11 {
+ milivolt = <( 107 / 7)>;
+ temp = <95>;
+ sample-index = <11>;
+ };
+ sample-datum-12 {
+ milivolt = <( 92 / 7)>;
+ temp = <100>;
+ sample-index = <12>;
+ };
+ };
};
diff --git a/zephyr/include/emul/emul_amd_fp6.h b/zephyr/include/emul/emul_amd_fp6.h
index 6c63a6caab..04dcd5dd31 100644
--- a/zephyr/include/emul/emul_amd_fp6.h
+++ b/zephyr/include/emul/emul_amd_fp6.h
@@ -29,10 +29,13 @@ void amd_fp6_emul_set_xbar(const struct emul *emul, bool ready);
* Set how long a command will take to complete. On a real system this can be
* anywhere from 50-100ms and the datasheet defines it can take up to 250ms.
*
+ * Getting timing to sync consistently in unit testing is difficult, so use the
+ * number of reads to wait instead.
+ *
* @param emul - AMD FP6 emulator data
- * @param delay_ms - how long after a mux set to wait before reporting the
- * status of the set as complete.
+ * @param delay_reads - how long after a mux set to wait before reporting the
+ * status of the set as complete (in number of reads)
*/
-void amd_fp6_emul_set_delay(const struct emul *emul, int delay_ms);
+void amd_fp6_emul_set_delay(const struct emul *emul, int delay_reads);
#endif
diff --git a/zephyr/program/corsola/include/variant_db_detection.h b/zephyr/program/corsola/include/variant_db_detection.h
index e98ba3067d..fb468126ef 100644
--- a/zephyr/program/corsola/include/variant_db_detection.h
+++ b/zephyr/program/corsola/include/variant_db_detection.h
@@ -8,27 +8,32 @@
#ifndef __CROS_EC_CORSOLA_DB_DETECTION_H
#define __CROS_EC_CORSOLA_DB_DETECTION_H
+#include <stdint.h>
+
enum corsola_db_type {
CORSOLA_DB_UNINIT = -1,
+ /* CORSOLA_DB_NO_DETECTION means there is no detection involved in. */
+ CORSOLA_DB_NO_DETECTION,
+ /* CORSOLA_DB_NONE means there is no DB in the design. */
CORSOLA_DB_NONE,
CORSOLA_DB_TYPEC,
CORSOLA_DB_HDMI,
CORSOLA_DB_COUNT,
};
-#ifdef CONFIG_VARIANT_CORSOLA_DB_DETECTION
/*
* Get the connected daughterboard type.
*
* @return The daughterboard type.
*/
+#ifdef CONFIG_VARIANT_CORSOLA_DB_DETECTION
enum corsola_db_type corsola_get_db_type(void);
-#else
+#elif !defined(CONFIG_TEST)
inline enum corsola_db_type corsola_get_db_type(void)
{
- return CORSOLA_DB_NONE;
-};
-#endif /* CONFIG_VARIANT_CORSOLA_DB_DETECTION */
+ return CORSOLA_DB_NO_DETECTION;
+}
+#endif
/* return the adjusted port count for board overridden usbc/charger functions.
*/
diff --git a/zephyr/program/corsola/npcx_adc.dtsi b/zephyr/program/corsola/npcx_adc.dtsi
index 7b69abe48a..cd6a9c1bef 100644
--- a/zephyr/program/corsola/npcx_adc.dtsi
+++ b/zephyr/program/corsola/npcx_adc.dtsi
@@ -7,6 +7,7 @@
* Kingler and Steelix use the same dts, take care of this when modify it.
*/
+
/ {
named-adc-channels {
compatible = "named-adc-channels";
diff --git a/zephyr/program/corsola/src/npcx_usbc.c b/zephyr/program/corsola/src/npcx_usbc.c
index 2e1d8d11c5..8e9cd09e55 100644
--- a/zephyr/program/corsola/src/npcx_usbc.c
+++ b/zephyr/program/corsola/src/npcx_usbc.c
@@ -179,9 +179,13 @@ int board_vbus_source_enabled(int port)
#if CONFIG_USB_PD_PORT_MAX_COUNT > 1
__override int board_rt1718s_set_snk_enable(int port, int enable)
{
- if (port == USBC_PORT_C1) {
- rt1718s_gpio_set_level(port, GPIO_EN_USB_C1_SINK, enable);
- }
+ rt1718s_gpio_set_level(port, GPIO_EN_USB_C1_SINK, enable);
+
+ return EC_SUCCESS;
+}
+__override int board_rt1718s_set_src_enable(int port, int enable)
+{
+ rt1718s_gpio_set_level(port, GPIO_EN_USB_C1_SOURCE, enable);
return EC_SUCCESS;
}
diff --git a/zephyr/program/corsola/src/usb_pd_policy.c b/zephyr/program/corsola/src/usb_pd_policy.c
index 30ded99aba..4b7e46cb74 100644
--- a/zephyr/program/corsola/src/usb_pd_policy.c
+++ b/zephyr/program/corsola/src/usb_pd_policy.c
@@ -229,12 +229,6 @@ void pd_power_supply_reset(int port)
prev_en = ppc_is_sourcing_vbus(port);
-#if defined(CONFIG_USB_PD_TCPM_RT1718S) && CONFIG_USB_PD_PORT_MAX_COUNT > 1
- if (port == USBC_PORT_C1) {
- rt1718s_gpio_set_level(port, GPIO_EN_USB_C1_SOURCE, 0);
- }
-#endif
-
/* Disable VBUS. */
ppc_vbus_source_enable(port, 0);
@@ -254,13 +248,6 @@ int pd_set_power_supply_ready(int port)
pd_set_vbus_discharge(port, 0);
-#if defined(CONFIG_USB_PD_TCPM_RT1718S) && CONFIG_USB_PD_PORT_MAX_COUNT > 1
- /* Provide Vbus. */
- if (port == USBC_PORT_C1) {
- rt1718s_gpio_set_level(port, GPIO_EN_USB_C1_SOURCE, 1);
- }
-#endif
-
RETURN_ERROR(ppc_vbus_source_enable(port, 1));
/* Notify host of power info change. */
diff --git a/zephyr/program/corsola/src/usbc.c b/zephyr/program/corsola/src/usbc.c
index 71c02ff54f..871c84a2e4 100644
--- a/zephyr/program/corsola/src/usbc.c
+++ b/zephyr/program/corsola/src/usbc.c
@@ -45,7 +45,7 @@ DECLARE_HOOK(HOOK_INIT, baseboard_init, HOOK_PRIO_PRE_DEFAULT);
__override uint8_t board_get_usb_pd_port_count(void)
{
- /* This function returns the PORT_COUNT+1 when HDMI db is connected.
+ /* This function returns the PORT_COUNT when HDMI db is connected.
* This is a trick to ensure the usb_mux_set being set properley.
* HDMI display functions using the USB virtual mux to * communicate
* with the DP bridge.
@@ -56,6 +56,8 @@ __override uint8_t board_get_usb_pd_port_count(void)
} else {
return CONFIG_USB_PD_PORT_MAX_COUNT - 1;
}
+ } else if (corsola_get_db_type() == CORSOLA_DB_NONE) {
+ return CONFIG_USB_PD_PORT_MAX_COUNT - 1;
}
return CONFIG_USB_PD_PORT_MAX_COUNT;
@@ -65,7 +67,7 @@ uint8_t board_get_adjusted_usb_pd_port_count(void)
{
const enum corsola_db_type db = corsola_get_db_type();
- if (db == CORSOLA_DB_TYPEC || db == CORSOLA_DB_NONE) {
+ if (db == CORSOLA_DB_TYPEC || db == CORSOLA_DB_NO_DETECTION) {
return CONFIG_USB_PD_PORT_MAX_COUNT;
} else {
return CONFIG_USB_PD_PORT_MAX_COUNT - 1;
diff --git a/zephyr/program/corsola/starmie/CMakeLists.txt b/zephyr/program/corsola/starmie/CMakeLists.txt
index f401c5dd43..dd669ab82c 100644
--- a/zephyr/program/corsola/starmie/CMakeLists.txt
+++ b/zephyr/program/corsola/starmie/CMakeLists.txt
@@ -9,4 +9,7 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_I2C "../src/ite_i2c.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC
"../src/ite_usb_pd_policy.c" "../src/ite_usbc.c")
-zephyr_library_sources("src/ppc.c") \ No newline at end of file
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_DETACHABLE_BASE
+ "src/base_detect.c")
+
+zephyr_library_sources("src/ppc.c")
diff --git a/zephyr/program/corsola/starmie/project.conf b/zephyr/program/corsola/starmie/project.conf
index 70bd94520f..72d18b8e9f 100644
--- a/zephyr/program/corsola/starmie/project.conf
+++ b/zephyr/program/corsola/starmie/project.conf
@@ -40,3 +40,7 @@ CONFIG_PLATFORM_EC_BODY_DETECTION=y
CONFIG_PLATFORM_EC_BODY_DETECTION_ALWAYS_ENABLE_IN_S0=y
CONFIG_PLATFORM_EC_GESTURE_DETECTION=y
CONFIG_PLATFORM_EC_GESTURE_HOST_DETECTION=y
+
+# Detachable
+CONFIG_PLATFORM_EC_DETACHABLE_BASE=y
+CONFIG_PLATFORM_EC_BASE_ATTACHED_SWITCH=y
diff --git a/zephyr/program/corsola/starmie/project.overlay b/zephyr/program/corsola/starmie/project.overlay
index 2358026e2d..de79d92cdb 100644
--- a/zephyr/program/corsola/starmie/project.overlay
+++ b/zephyr/program/corsola/starmie/project.overlay
@@ -43,6 +43,11 @@
handler = "power_signal_interrupt";
};
+ pogo_prsnt_int: pogo-prsnt-int {
+ irq-pin = <&pogo_prsnt_int_l>;
+ flags = <GPIO_INT_EDGE_BOTH>;
+ handler = "base_detect_interrupt";
+ };
/delete-node/ lid_imu;
};
@@ -71,8 +76,8 @@
};
// POGO_PRSNT_INT_L GPI5
- pogo_prsnt_int_l: pogo_prsnt_int_l{
- gpios = <&gpioi 5 GPIO_INPUT_PULL_DOWN>;
+ pogo_prsnt_int_l: pogo_prsnt_int_l {
+ gpios = <&gpioi 5 (GPIO_INPUT | GPIO_ACTIVE_LOW)>;
};
pg_pp4200_s5_od: pg-pp4200-s5-od {
@@ -131,8 +136,8 @@
motionsense-rotation-ref {
compatible = "cros-ec,motionsense-rotation-ref";
lid_rot_ref_bmi: lid-rotation-ref-bmi {
- mat33 = <1 0 0
- 0 1 0
+ mat33 = <(-1) 0 0
+ 0 (-1) 0
0 0 1>;
};
};
@@ -217,6 +222,39 @@
power-gpio-pin = <&pmic_ec_resetb>;
};
};
+
+ named-adc-channels {
+ adc_temp_sensor_1: adc-temp-sensor-1 {
+ enum-name = "ADC_TEMP_SENSOR_1";
+ io-channels = <&adc0 6>;
+ };
+ adc_temp_sensor_2: adc-temp-sensor-2 {
+ enum-name = "ADC_TEMP_SENSOR_2";
+ io-channels = <&adc0 7>;
+ };
+ };
+
+ temp_sensor_1_thermistor: sensor-1-thermistor {
+ compatible = "cros-ec,temp-sensor-thermistor";
+ thermistor = <&thermistor_1V8_100K_100K_4250B>;
+ adc = <&adc_temp_sensor_1>;
+ };
+
+ temp_sensor_2_thermistor: sensor-2-thermistor {
+ compatible = "cros-ec,temp-sensor-thermistor";
+ thermistor = <&thermistor_1V8_100K_100K_4250B>;
+ adc = <&adc_temp_sensor_2>;
+ };
+
+ named-temp-sensors {
+ compatible = "cros-ec,temp-sensors";
+ temp_sensor_1 {
+ sensor = <&temp_sensor_1_thermistor>;
+ };
+ temp_sensor_2 {
+ sensor = <&temp_sensor_2_thermistor>;
+ };
+ };
};
&i2c0{
@@ -231,3 +269,13 @@
reg = <0x10>;
};
};
+
+&adc0{
+ status = "okay";
+ pinctrl-0 = <&adc0_ch6_gpi6_default>;
+ pinctrl-names = "default";
+};
+
+&thermistor_1V8_100K_100K_4250B{
+ status = "okay";
+};
diff --git a/zephyr/program/corsola/starmie/src/base_detect.c b/zephyr/program/corsola/starmie/src/base_detect.c
new file mode 100644
index 0000000000..144b26e3be
--- /dev/null
+++ b/zephyr/program/corsola/starmie/src/base_detect.c
@@ -0,0 +1,151 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "ap_power/ap_power.h"
+#include "base_state.h"
+#include "chipset.h"
+#include "console.h"
+#include "gpio/gpio_int.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "tablet_mode.h"
+
+#include <zephyr/drivers/gpio.h>
+#include <zephyr/kernel.h>
+
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
+
+/* Base detection debouncing */
+#define BASE_DETECT_EN_DEBOUNCE_US (350 * MSEC)
+#define BASE_DETECT_DIS_DEBOUNCE_US (20 * MSEC)
+
+K_MUTEX_DEFINE(modify_base_detection_mutex);
+static bool detect_base_enabled;
+
+static void base_detect_deferred(void);
+DECLARE_DEFERRED(base_detect_deferred);
+
+enum base_status {
+ BASE_UNKNOWN = 0,
+ BASE_DISCONNECTED = 1,
+ BASE_CONNECTED = 2,
+};
+
+static enum base_status current_base_status;
+
+static void base_update(enum base_status specified_status)
+{
+ int connected = (specified_status != BASE_CONNECTED) ? false : true;
+
+ if (current_base_status == specified_status)
+ return;
+
+ current_base_status = specified_status;
+
+ base_set_state(connected);
+ tablet_set_mode(!connected, TABLET_TRIGGER_BASE);
+ gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(en_pp3300_base_x), connected);
+}
+
+void base_detect_interrupt(enum gpio_signal signal)
+{
+ gpio_disable_dt_interrupt(GPIO_INT_FROM_NODELABEL(pogo_prsnt_int));
+ hook_call_deferred(&base_detect_deferred_data,
+ (current_base_status == BASE_CONNECTED) ?
+ BASE_DETECT_DIS_DEBOUNCE_US :
+ BASE_DETECT_EN_DEBOUNCE_US);
+}
+
+static inline void detect_and_update_base_status(void)
+{
+ if (gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(pogo_prsnt_int_l))) {
+ base_update(BASE_CONNECTED);
+ } else {
+ base_update(BASE_DISCONNECTED);
+ }
+}
+
+static void base_detect_deferred(void)
+{
+ k_mutex_lock(&modify_base_detection_mutex, K_FOREVER);
+ /*
+ * If a disable base detection is issued after an ISR, and is before
+ * executing the deferred hook, then we need to check whether the
+ * detection is enabled. If disabled, there is no need to re-enable the
+ * interrupt.
+ */
+ if (detect_base_enabled) {
+ detect_and_update_base_status();
+ gpio_enable_dt_interrupt(
+ GPIO_INT_FROM_NODELABEL(pogo_prsnt_int));
+ }
+ k_mutex_unlock(&modify_base_detection_mutex);
+}
+
+static void base_detect_enable(bool enable)
+{
+ detect_base_enabled = enable;
+ if (enable) {
+ gpio_enable_dt_interrupt(
+ GPIO_INT_FROM_NODELABEL(pogo_prsnt_int));
+ detect_and_update_base_status();
+ } else {
+ gpio_disable_dt_interrupt(
+ GPIO_INT_FROM_NODELABEL(pogo_prsnt_int));
+ base_update(BASE_UNKNOWN);
+ }
+}
+
+static void base_startup_hook(struct ap_power_ev_callback *cb,
+ struct ap_power_ev_data data)
+{
+ switch (data.event) {
+ case AP_POWER_STARTUP:
+ base_detect_enable(true);
+ break;
+ case AP_POWER_SHUTDOWN:
+ base_detect_enable(false);
+ break;
+ default:
+ return;
+ }
+}
+
+static int base_init(void)
+{
+ static struct ap_power_ev_callback cb;
+
+ detect_base_enabled = false;
+ ap_power_ev_init_callback(&cb, base_startup_hook,
+ AP_POWER_STARTUP | AP_POWER_SHUTDOWN);
+ ap_power_ev_add_callback(&cb);
+
+ if (!chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
+ base_detect_enable(true);
+ }
+
+ return 0;
+}
+SYS_INIT(base_init, APPLICATION, 1);
+
+void base_force_state(enum ec_set_base_state_cmd state)
+{
+ k_mutex_lock(&modify_base_detection_mutex, K_FOREVER);
+ switch (state) {
+ case EC_SET_BASE_STATE_ATTACH:
+ base_detect_enable(false);
+ base_update(BASE_CONNECTED);
+ break;
+ case EC_SET_BASE_STATE_DETACH:
+ base_detect_enable(false);
+ base_update(BASE_DISCONNECTED);
+ break;
+ case EC_SET_BASE_STATE_RESET:
+ base_detect_enable(true);
+ break;
+ }
+ k_mutex_unlock(&modify_base_detection_mutex);
+}
diff --git a/zephyr/program/corsola/starmie/src/ppc.c b/zephyr/program/corsola/starmie/src/ppc.c
index 8c1dc2fe7f..505da06473 100644
--- a/zephyr/program/corsola/starmie/src/ppc.c
+++ b/zephyr/program/corsola/starmie/src/ppc.c
@@ -27,3 +27,11 @@ void ppc_interrupt(enum gpio_signal signal)
ppc_chips[0].drv->interrupt(0);
}
}
+
+static int set_rt1739(void)
+{
+ rt1739_init(0);
+ return 0;
+}
+
+SYS_INIT(set_rt1739, POST_KERNEL, 61);
diff --git a/zephyr/program/corsola/voltorb/project.conf b/zephyr/program/corsola/voltorb/project.conf
index d2693d0de8..19348b04cd 100644
--- a/zephyr/program/corsola/voltorb/project.conf
+++ b/zephyr/program/corsola/voltorb/project.conf
@@ -42,6 +42,7 @@ CONFIG_PLATFORM_EC_EXTPOWER_DEBOUNCE_MS=800
# Battery config
CONFIG_PLATFORM_EC_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV=15000
CONFIG_PLATFORM_EC_SMART_BATTERY_OPTIONAL_MFG_FUNC=y
+CONFIG_PLATFORM_EC_BATTERY_STBL_STAT=y
# Remove debug options and features for FW QUAL
CONFIG_PLATFORM_EC_SYSTEM_UNLOCKED=n
diff --git a/zephyr/program/nissa/CMakeLists.txt b/zephyr/program/nissa/CMakeLists.txt
index cd45f00a3a..88e2d1c8a4 100644
--- a/zephyr/program/nissa/CMakeLists.txt
+++ b/zephyr/program/nissa/CMakeLists.txt
@@ -71,6 +71,7 @@ if(DEFINED CONFIG_BOARD_JOXER)
zephyr_library_sources(
"joxer/src/led.c"
"joxer/src/keyboard.c"
+ "joxer/src/form_factor.c"
)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC "joxer/src/usbc.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CHARGER "joxer/src/charger.c")
diff --git a/zephyr/program/nissa/craask/src/led.c b/zephyr/program/nissa/craask/src/led.c
index 0af0202cf4..b3aefa3ab2 100644
--- a/zephyr/program/nissa/craask/src/led.c
+++ b/zephyr/program/nissa/craask/src/led.c
@@ -22,7 +22,7 @@ __override struct led_descriptor
LED_INDEFINITE } },
[STATE_DISCHARGE_S0] = { { EC_LED_COLOR_BLUE,
LED_INDEFINITE } },
- [STATE_DISCHARGE_S0_BAT_LOW] = { { EC_LED_COLOR_AMBER,
+ [STATE_DISCHARGE_S0_BAT_LOW] = { { EC_LED_COLOR_BLUE,
LED_INDEFINITE } },
[STATE_DISCHARGE_S3] = { { EC_LED_COLOR_AMBER,
1 * LED_ONE_SEC },
diff --git a/zephyr/program/nissa/joxer/cbi.dtsi b/zephyr/program/nissa/joxer/cbi.dtsi
index afbd125b32..71424ed681 100644
--- a/zephyr/program/nissa/joxer/cbi.dtsi
+++ b/zephyr/program/nissa/joxer/cbi.dtsi
@@ -28,5 +28,26 @@
value = <1>;
};
};
+
+ /*
+ * FW_CONFIG field to describe lid accelerometer orientation.
+ */
+ lid-inversion {
+ enum-name = "FW_LID_INVERSION";
+ start = <5>;
+ size = <1>;
+
+ default {
+ compatible = "cros-ec,cbi-fw-config-value";
+ enum-name = "SENSOR_DEFAULT";
+ value = <0>;
+ default;
+ };
+ inverted {
+ compatible = "cros-ec,cbi-fw-config-value";
+ enum-name = "SENSOR_INVERTED";
+ value = <1>;
+ };
+ };
};
};
diff --git a/zephyr/program/nissa/joxer/motionsense.dtsi b/zephyr/program/nissa/joxer/motionsense.dtsi
index e9c46a849a..fbac470660 100644
--- a/zephyr/program/nissa/joxer/motionsense.dtsi
+++ b/zephyr/program/nissa/joxer/motionsense.dtsi
@@ -40,6 +40,12 @@
0 0 (-1)>;
};
+ lid_rot_inverted: lid-rotation-inverted {
+ mat33 = <0 1 0
+ (-1) 0 0
+ 0 0 1>;
+ };
+
base_rot_ref: base-rotation-ref {
mat33 = <1 0 0
0 1 0
diff --git a/zephyr/program/nissa/joxer/src/form_factor.c b/zephyr/program/nissa/joxer/src/form_factor.c
new file mode 100644
index 0000000000..1087d7ddca
--- /dev/null
+++ b/zephyr/program/nissa/joxer/src/form_factor.c
@@ -0,0 +1,39 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "accelgyro.h"
+#include "cros_cbi.h"
+#include "hooks.h"
+#include "motionsense_sensors.h"
+
+#include <zephyr/devicetree.h>
+#include <zephyr/logging/log.h>
+
+LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL);
+
+#define ALT_MAT SENSOR_ROT_STD_REF_NAME(DT_NODELABEL(lid_rot_inverted))
+#define LID_ACCEL SENSOR_ID(DT_NODELABEL(lid_accel))
+
+static void form_factor_init(void)
+{
+ int ret;
+ uint32_t val;
+ /*
+ * If the firmware config indicates
+ * an inverted form factor, use the alternative
+ * rotation matrix.
+ */
+ ret = cros_cbi_get_fw_config(FW_LID_INVERSION, &val);
+ if (ret != 0) {
+ LOG_ERR("Error retrieving CBI FW_CONFIG field %d",
+ FW_LID_INVERSION);
+ return;
+ }
+ if (val == SENSOR_INVERTED) {
+ LOG_INF("Switching to inverted lid");
+ motion_sensors[LID_ACCEL].rot_standard_ref = &ALT_MAT;
+ }
+}
+DECLARE_HOOK(HOOK_INIT, form_factor_init, HOOK_PRIO_POST_I2C);
diff --git a/zephyr/program/nissa/uldren/motionsense.dtsi b/zephyr/program/nissa/uldren/motionsense.dtsi
index 70b381b843..baaec61e5e 100644
--- a/zephyr/program/nissa/uldren/motionsense.dtsi
+++ b/zephyr/program/nissa/uldren/motionsense.dtsi
@@ -35,14 +35,14 @@
motionsense-rotation-ref {
compatible = "cros-ec,motionsense-rotation-ref";
lid_rot_ref: lid-rotation-ref {
- mat33 = <0 (-1) 0
+ mat33 = <0 1 0
(-1) 0 0
- 0 0 (-1)>;
+ 0 0 1>;
};
base_rot_ref: base-rotation-ref {
- mat33 = <0 1 0
- (-1) 0 0
+ mat33 = <1 0 0
+ 0 1 0
0 0 1>;
};
};
diff --git a/zephyr/program/nissa/yavilla/gpio.dtsi b/zephyr/program/nissa/yavilla/gpio.dtsi
index a18e674b11..8c76048f25 100644
--- a/zephyr/program/nissa/yavilla/gpio.dtsi
+++ b/zephyr/program/nissa/yavilla/gpio.dtsi
@@ -34,6 +34,9 @@
named-gpios {
compatible = "named-gpios";
+ gpio_acc_int_l: acc_int_l {
+ gpios = <&gpioc 0 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>;
+ };
gpio_all_sys_pwrgd: all_sys_pwrgd {
gpios = <&gpiob 7 GPIO_INPUT>;
};
@@ -134,6 +137,9 @@
gpios = <&gpioe 2 GPIO_INPUT_PULL_UP>;
enum-name = "GPIO_POWER_BUTTON_L";
};
+ gpio_imu_int_l: imu_int_l {
+ gpios = <&gpioj 0 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>;
+ };
gpio_imvp91_vrrdy_od: imvp91_vrrdy_od {
gpios = <&gpioj 4 GPIO_INPUT>;
no-auto-init;
@@ -178,6 +184,10 @@
gpios = <&gpiod 1 GPIO_ODR_HIGH>;
no-auto-init;
};
+ gpio_tablet_mode_l: tablet_mode_l {
+ gpios = <&gpioa 7 GPIO_INPUT>;
+ enum-name = "GPIO_TABLET_MODE_L";
+ };
gpio_usb_a0_ilimit_sdp: usb_a0_ilimit_sdp {
gpios = <&gpiol 5 GPIO_OUTPUT>;
enum-name = "GPIO_USB1_ILIM_SEL";
@@ -216,6 +226,14 @@
gpios = <&gpioksol 2 GPIO_OUTPUT_HIGH>;
enum-name = "GPIO_KBD_KSO2";
};
+ gpio_voldn_btn_odl: voldn_btn_odl {
+ gpios = <&gpioi 6 GPIO_INPUT_PULL_UP>;
+ enum-name = "GPIO_VOLUME_DOWN_L";
+ };
+ gpio_volup_btn_odl: volup_btn_odl {
+ gpios = <&gpioi 7 GPIO_INPUT_PULL_UP>;
+ enum-name = "GPIO_VOLUME_UP_L";
+ };
};
named-i2c-ports {
diff --git a/zephyr/program/nissa/yavilla/motionsense.dtsi b/zephyr/program/nissa/yavilla/motionsense.dtsi
new file mode 100644
index 0000000000..df84c36471
--- /dev/null
+++ b/zephyr/program/nissa/yavilla/motionsense.dtsi
@@ -0,0 +1,148 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <dt-bindings/motionsense/utils.h>
+
+
+/ {
+ aliases {
+ /*
+ * Interrupt bindings for sensor devices.
+ */
+ bmi3xx-int = &base_accel;
+ bma4xx-int = &lid_accel;
+ };
+
+ /*
+ * Declare mutexes used by sensor drivers.
+ * A mutex node is used to create an instance of mutex_t.
+ * A mutex node is referenced by a sensor node if the
+ * corresponding sensor driver needs to use the
+ * instance of the mutex.
+ */
+ motionsense-mutex {
+ compatible = "cros-ec,motionsense-mutex";
+ lid_mutex: lid-mutex {
+ };
+
+ base_mutex: base-mutex {
+ };
+ };
+
+ /* Rotation matrix used by drivers. */
+ motionsense-rotation-ref {
+ compatible = "cros-ec,motionsense-rotation-ref";
+ lid_rot_ref: lid-rotation-ref {
+ mat33 = <1 0 0
+ 0 (-1) 0
+ 0 0 (-1)>;
+ };
+
+ base_rot_ref: base-rotation-ref {
+ mat33 = <0 1 0
+ 1 0 0
+ 0 0 (-1)>;
+ };
+ };
+
+ /*
+ * Driver specific data. A driver-specific data can be shared with
+ * different motion sensors while they are using the same driver.
+ *
+ * If a node's compatible starts with "cros-ec,accelgyro-", it is for
+ * a common structure defined in accelgyro.h.
+ * e.g) compatible = "cros-ec,accelgyro-als-drv-data" is for
+ * "struct als_drv_data_t" in accelgyro.h
+ */
+ motionsense-sensor-data {
+ bmi323_data: bmi323-drv-data {
+ compatible = "cros-ec,drvdata-bmi3xx";
+ status = "okay";
+ };
+
+ bma422_data: bma4xx-drv-data {
+ compatible = "cros-ec,drvdata-bma4xx";
+ status = "okay";
+ };
+ };
+
+ /*
+ * List of motion sensors that creates motion_sensors array.
+ * The nodelabel "lid_accel" and "base_accel" are used to indicate
+ * motion sensor IDs for lid angle calculation.
+ * TODO(b/238139272): The first entries of the array must be
+ * accelerometers,then gyroscope. Fix this dependency in the DTS
+ * processing which makes the devicetree entries independent.
+ */
+ motionsense-sensor {
+ lid_accel: lid-accel {
+ compatible = "cros-ec,bma4xx";
+ status = "okay";
+
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_LID";
+ mutex = <&lid_mutex>;
+ port = <&i2c_ec_i2c_sensor>;
+ rot-standard-ref = <&lid_rot_ref>;
+ default-range = <2>;
+ drv-data = <&bma422_data>;
+ i2c-spi-addr-flags = "BMA4_I2C_ADDR_PRIMARY";
+ configs {
+ compatible =
+ "cros-ec,motionsense-sensor-config";
+ ec-s0 {
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ ec-s3 {
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ };
+ };
+
+ base_accel: base-accel {
+ compatible = "cros-ec,bmi3xx-accel";
+ status = "okay";
+
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_BASE";
+ mutex = <&base_mutex>;
+ port = <&i2c_ec_i2c_sensor>;
+ rot-standard-ref = <&base_rot_ref>;
+ drv-data = <&bmi323_data>;
+ configs {
+ compatible =
+ "cros-ec,motionsense-sensor-config";
+ ec-s0 {
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ ec-s3 {
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ };
+ };
+
+ base_gyro: base-gyro {
+ compatible = "cros-ec,bmi3xx-gyro";
+ status = "okay";
+
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_BASE";
+ mutex = <&base_mutex>;
+ port = <&i2c_ec_i2c_sensor>;
+ rot-standard-ref = <&base_rot_ref>;
+ drv-data = <&bmi323_data>;
+ };
+ };
+
+ motionsense-sensor-info {
+ compatible = "cros-ec,motionsense-sensor-info";
+
+ /*
+ * list of GPIO interrupts that have to
+ * be enabled at initial stage
+ */
+ sensor-irqs = <&int_imu &int_acc>;
+ };
+};
diff --git a/zephyr/program/nissa/yavilla/overlay.dtsi b/zephyr/program/nissa/yavilla/overlay.dtsi
index b60ad2f476..c75ae9dd79 100644
--- a/zephyr/program/nissa/yavilla/overlay.dtsi
+++ b/zephyr/program/nissa/yavilla/overlay.dtsi
@@ -49,6 +49,16 @@
flags = <GPIO_INT_EDGE_BOTH>;
handler = "power_button_interrupt";
};
+ int_vol_down: vol_down {
+ irq-pin = <&gpio_voldn_btn_odl>;
+ flags = <GPIO_INT_EDGE_BOTH>;
+ handler = "button_interrupt";
+ };
+ int_vol_up: vol_up {
+ irq-pin = <&gpio_volup_btn_odl>;
+ flags = <GPIO_INT_EDGE_BOTH>;
+ handler = "button_interrupt";
+ };
int_wp_l: wp_l {
irq-pin = <&gpio_ec_wp_odl>;
flags = <GPIO_INT_EDGE_BOTH>;
@@ -59,6 +69,21 @@
flags = <GPIO_INT_EDGE_BOTH>;
handler = "lid_interrupt";
};
+ int_tablet_mode: tablet_mode {
+ irq-pin = <&gpio_tablet_mode_l>;
+ flags = <GPIO_INT_EDGE_BOTH>;
+ handler = "gmr_tablet_switch_isr";
+ };
+ int_acc: lid_imu {
+ irq-pin = <&gpio_acc_int_l>;
+ flags = <GPIO_INT_EDGE_FALLING>;
+ handler = "bma4xx_interrupt";
+ };
+ int_imu: ec_imu {
+ irq-pin = <&gpio_imu_int_l>;
+ flags = <GPIO_INT_EDGE_FALLING>;
+ handler = "bmi3xx_interrupt";
+ };
int_usb_c0: usb_c0 {
irq-pin = <&gpio_usb_c0_int_odl>;
flags = <GPIO_INT_EDGE_FALLING>;
@@ -73,14 +98,9 @@
unused-pins {
compatible = "unused-gpios";
- unused-gpios = <&gpioa 7 0>,
- <&gpioc 0 0>,
- <&gpioc 6 0>,
+ unused-gpios = <&gpioc 6 0>,
<&gpiod 7 0>,
<&gpioh 2 0>,
- <&gpioi 6 0>,
- <&gpioi 7 0>,
- <&gpioj 0 0>,
<&gpioj 3 0>,
<&gpiok 7 GPIO_OUTPUT>;
};
@@ -292,7 +312,7 @@
&i2c2 {
label = "I2C_SENSOR";
- clock-frequency = <I2C_BITRATE_FAST>;
+ clock-frequency = <I2C_BITRATE_STANDARD>;
pinctrl-0 = <&i2c2_clk_gpf6_default
&i2c2_data_gpf7_default>;
pinctrl-names = "default";
diff --git a/zephyr/program/nissa/yavilla/project.conf b/zephyr/program/nissa/yavilla/project.conf
index 30818c4419..8011391adf 100644
--- a/zephyr/program/nissa/yavilla/project.conf
+++ b/zephyr/program/nissa/yavilla/project.conf
@@ -8,17 +8,11 @@ CONFIG_BOARD_YAVILLA=y
CONFIG_PLATFORM_EC_KEYBOARD_PWRBTN_ASSERTS_KSI3=y
CONFIG_PLATFORM_EC_KEYBOARD_REFRESH_ROW3=y
-# Sensors: disabled; yavilla is clamshell-only
-CONFIG_PLATFORM_EC_LID_ANGLE=n
-CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=n
-CONFIG_PLATFORM_EC_CONSOLE_CMD_ACCELS=n
-CONFIG_PLATFORM_EC_CONSOLE_CMD_ACCEL_INFO=n
-CONFIG_PLATFORM_EC_ACCEL_FIFO=n
-CONFIG_PLATFORM_EC_SENSOR_TIGHT_TIMESTAMPS=n
-CONFIG_PLATFORM_EC_GMR_TABLET_MODE=n
-CONFIG_PLATFORM_EC_TABLET_MODE=n
-CONFIG_PLATFORM_EC_TABLET_MODE_SWITCH=n
-CONFIG_PLATFORM_EC_VOLUME_BUTTONS=n
+# Sensors
+CONFIG_PLATFORM_EC_ACCELGYRO_BMI_COMM_I2C=y
+CONFIG_PLATFORM_EC_ACCELGYRO_BMI3XX=y
+CONFIG_PLATFORM_EC_ACCEL_BMA4XX=y
+CONFIG_PLATFORM_EC_DYNAMIC_MOTION_SENSOR_COUNT=y
CONFIG_PLATFORM_EC_MAX_SENSOR_FREQ_MILLIHZ=100000
# Keyboard
diff --git a/zephyr/program/nissa/yavilla/project.overlay b/zephyr/program/nissa/yavilla/project.overlay
index 97f431022c..40bbaec4bb 100644
--- a/zephyr/program/nissa/yavilla/project.overlay
+++ b/zephyr/program/nissa/yavilla/project.overlay
@@ -9,5 +9,6 @@
#include "fan.dtsi"
#include "gpio.dtsi"
#include "keyboard.dtsi"
+#include "motionsense.dtsi"
#include "overlay.dtsi"
#include "power_signals.dtsi"
diff --git a/zephyr/program/nissa/yavilla/src/board.c b/zephyr/program/nissa/yavilla/src/board.c
index f89b92ebd8..feee5fa91f 100644
--- a/zephyr/program/nissa/yavilla/src/board.c
+++ b/zephyr/program/nissa/yavilla/src/board.c
@@ -3,14 +3,19 @@
* found in the LICENSE file.
*/
/* yavilla hardware configuration */
+#include "cros_cbi.h"
#include "gpio/gpio_int.h"
#include "hooks.h"
+#include "motion_sense.h"
+#include "tablet_mode.h"
#include "task.h"
+#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/init.h>
#include <zephyr/kernel.h>
+#include <zephyr/logging/log.h>
#include <zephyr/sys/printk.h>
LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL);
__override uint8_t board_get_usb_pd_port_count(void)
@@ -22,10 +27,39 @@ __override uint8_t board_get_usb_pd_port_count(void)
*/
static void board_init(void)
{
+ int ret;
+ uint32_t val;
+
+ /*
+ * Retrieve the tablet config.
+ */
+ ret = cros_cbi_get_fw_config(FW_TABLET, &val);
+ if (ret != 0) {
+ LOG_ERR("Error retrieving CBI FW_CONFIG field %d", FW_TABLET);
+ return;
+ }
+
/*
* Enable USB-C interrupts.
*/
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_usb_c0));
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_usb_c1));
+
+ /*
+ * Disable tablet related interrupts for tablet absent DUT.
+ */
+ if (val == FW_TABLET_ABSENT) {
+ motion_sensor_count = 0;
+ gmr_tablet_switch_disable();
+ gpio_disable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_imu));
+ /* Base accel is not stuffed, don't allow line to float */
+ gpio_pin_configure_dt(GPIO_DT_FROM_NODELABEL(gpio_imu_int_l),
+ GPIO_INPUT | GPIO_PULL_DOWN);
+ /* Lid accel is not stuffed, don't allow line to float */
+ gpio_pin_configure_dt(GPIO_DT_FROM_NODELABEL(gpio_acc_int_l),
+ GPIO_INPUT | GPIO_PULL_DOWN);
+ LOG_INF("Clameshell: Disable motion sensors and gmr sensor!");
+ } else
+ LOG_INF("Convertible!!!");
}
-DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_POST_I2C);
diff --git a/zephyr/program/skyrim/winterhold/project.conf b/zephyr/program/skyrim/winterhold/project.conf
index 3521417c68..ef336a4667 100644
--- a/zephyr/program/skyrim/winterhold/project.conf
+++ b/zephyr/program/skyrim/winterhold/project.conf
@@ -16,6 +16,7 @@ CONFIG_PLATFORM_EC_CHARGER_RUNTIME_CONFIG=y
CONFIG_PLATFORM_EC_CHARGER_ISL9238C=y
CONFIG_PLATFORM_EC_ISL9238C_ENABLE_BUCK_MODE=y
CONFIG_PLATFORM_EC_CHARGER_PROFILE_OVERRIDE=y
+CONFIG_PLATFORM_EC_CHARGER_MAINTAIN_VBAT=y
# Forward Buck Phase Comparator bit<15:13> to 100=-2mV
CONFIG_PLATFORM_EC_ISL9238C_BUCK_PHASE_VOLTAGE=6
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index 132494d5f4..fa8e278996 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -297,7 +297,13 @@
CONFIG_PLATFORM_EC_BATTERY_MAX_IMBALANCE_MV
#define CONFIG_CHARGER_MIN_BAT_PCT_IMBALANCED_POWER_ON \
CONFIG_PLATFORM_EC_CHARGER_MIN_BAT_PCT_IMBALANCED_POWER_ON
+#endif
+#undef CONFIG_BATTERY_STBL_STAT
+#ifdef CONFIG_PLATFORM_EC_BATTERY_STBL_STAT
+#define CONFIG_BATTERY_STBL_STAT
+#define CONFIG_BATT_ALARM_MASK1 CONFIG_PLATFORM_EC_BATT_ALARM_MASK1
+#define CONFIG_BATT_ALARM_MASK2 CONFIG_PLATFORM_EC_BATT_ALARM_MASK2
#endif
#undef CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV
diff --git a/zephyr/test/drivers/amd_fp6_usb_mux/src/amd_fp6_usb_mux_test.c b/zephyr/test/drivers/amd_fp6_usb_mux/src/amd_fp6_usb_mux_test.c
index d900b2d3c2..8d8a6982cf 100644
--- a/zephyr/test/drivers/amd_fp6_usb_mux/src/amd_fp6_usb_mux_test.c
+++ b/zephyr/test/drivers/amd_fp6_usb_mux/src/amd_fp6_usb_mux_test.c
@@ -140,7 +140,7 @@ ZTEST_F(amd_fp6_usb_mux, test_chipset_reset)
ZTEST_F(amd_fp6_usb_mux, test_long_command)
{
/* Allow the mux to take a while, like on real systems */
- amd_fp6_emul_set_delay(fixture->amd_fp6_emul, 100);
+ amd_fp6_emul_set_delay(fixture->amd_fp6_emul, 6);
/* Send a basic set to USB mode */
usb_mux_set(TEST_PORT, USB_PD_MUX_USB_ENABLED, USB_SWITCH_CONNECT, 1);
diff --git a/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c b/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c
index a62ec2b0ea..b900e97661 100644
--- a/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c
+++ b/zephyr/test/drivers/common_charger/src/test_charge_state_v2.c
@@ -12,35 +12,35 @@
int battery_outside_charging_temperature(void);
-struct charge_state_v2_fixture {
+struct charge_state_fixture {
struct charge_state_data charge_state_data;
};
static void *setup(void)
{
- static struct charge_state_v2_fixture fixture;
+ static struct charge_state_fixture fixture;
return &fixture;
}
static void before(void *f)
{
- struct charge_state_v2_fixture *fixture = f;
+ struct charge_state_fixture *fixture = f;
fixture->charge_state_data = *charge_get_status();
}
static void after(void *f)
{
- struct charge_state_v2_fixture *fixture = f;
+ struct charge_state_fixture *fixture = f;
*charge_get_status() = fixture->charge_state_data;
}
-ZTEST_SUITE(charge_state_v2, drivers_predicate_post_main, setup, before, after,
+ZTEST_SUITE(charge_state, drivers_predicate_post_main, setup, before, after,
NULL);
-ZTEST(charge_state_v2, test_battery_flag_bad_temperature)
+ZTEST(charge_state, test_battery_flag_bad_temperature)
{
struct charge_state_data *curr = charge_get_status();
@@ -48,7 +48,7 @@ ZTEST(charge_state_v2, test_battery_flag_bad_temperature)
zassert_ok(battery_outside_charging_temperature());
}
-ZTEST(charge_state_v2, test_battery_temperature_range)
+ZTEST(charge_state, test_battery_temperature_range)
{
struct charge_state_data *curr = charge_get_status();
const struct battery_info *batt_info = battery_get_info();
@@ -98,7 +98,7 @@ ZTEST(charge_state_v2, test_battery_temperature_range)
zassert_ok(battery_outside_charging_temperature());
}
-ZTEST(charge_state_v2, test_current_limit_derating)
+ZTEST(charge_state, test_current_limit_derating)
{
int charger_current_limit;
@@ -115,7 +115,7 @@ ZTEST(charge_state_v2, test_current_limit_derating)
charger_current_limit);
}
-ZTEST(charge_state_v2, test_minimum_current_limit)
+ZTEST(charge_state, test_minimum_current_limit)
{
int charger_current_limit;
diff --git a/zephyr/test/drivers/usbc_usb4_mode/src/usbc_usb4_mode.c b/zephyr/test/drivers/usbc_usb4_mode/src/usbc_usb4_mode.c
index 4c21aaeac4..25fcff61e1 100644
--- a/zephyr/test/drivers/usbc_usb4_mode/src/usbc_usb4_mode.c
+++ b/zephyr/test/drivers/usbc_usb4_mode/src/usbc_usb4_mode.c
@@ -259,6 +259,44 @@ ZTEST_F(usbc_usb4_mode, test_verify_usb4_passive_entry_exit)
USB_PD_MUX_USB_ENABLED, "Failed to see USB set");
}
+/* If the partner claims to support USB4, but communication is only PD 2.0, the
+ * EC should disregard a request to enter USB4 from the host.
+ */
+ZTEST_F(usbc_usb4_mode, test_verify_usb4_pd2_no_entry)
+{
+ struct ec_response_typec_status status;
+
+ tcpci_partner_init(&fixture->partner, PD_REV20);
+ fixture->partner.cable = &passive_usb4;
+ connect_sink_to_port(&fixture->partner, fixture->tcpci_emul,
+ fixture->charger_emul);
+
+ /* Instruct partner port to accept Enter_USB message */
+ fixture->partner.enter_usb_accept = true;
+
+ /* Verify that we properly identify a USB4 capable passive cable */
+ verify_cable_found(fixture->partner.cable);
+
+ status = host_cmd_typec_status(TEST_PORT);
+ zassert_equal((status.mux_state & USB_MUX_CHECK_MASK),
+ USB_PD_MUX_USB_ENABLED, "Unexpected starting mux: 0x%02x",
+ status.mux_state);
+
+ host_cmd_typec_control_enter_mode(TEST_PORT, TYPEC_MODE_USB4);
+ k_sleep(K_SECONDS(1));
+
+ /* PD 2.0 doesn't include Enter_USB, so it's not possible to enter USB4
+ * mode. A Discover Identity ACK indicating support for USB4 isn't even
+ * valid under PD 2.0. If the host nevertheless commands the EC to enter
+ * USB4, the EC should not attempt to do so.
+ */
+ status = host_cmd_typec_status(TEST_PORT);
+ zassert_equal((status.mux_state & USB_MUX_CHECK_MASK),
+ USB_PD_MUX_USB_ENABLED, "Failed to see USB still set");
+ zassert_not_equal((status.mux_state & USB_MUX_CHECK_MASK),
+ USB_PD_MUX_USB4_ENABLED, "Unexpected USB4 mode set");
+}
+
/*
* TODO(b/260095516): This test suite is only testing the default good case, and
* one error case where the cable doesn't support USB4. This suite needs to be
diff --git a/zephyr/test/kingler/CMakeLists.txt b/zephyr/test/kingler/CMakeLists.txt
index 0cecc14b8f..31f7b9cc2c 100644
--- a/zephyr/test/kingler/CMakeLists.txt
+++ b/zephyr/test/kingler/CMakeLists.txt
@@ -12,27 +12,44 @@ zephyr_include_directories("${PLATFORM_EC_PROGRAM_DIR}/corsola/include")
target_sources(app PRIVATE src/fakes.c)
-target_sources_ifdef(CONFIG_TEST_STEELIX_RUSTY
-app PRIVATE ${PLATFORM_EC_PROGRAM_DIR}/corsola/steelix/src/board.c)
-target_sources_ifdef(CONFIG_TEST_FORM_FACTOR_CONVERTIBLE
- app PRIVATE src/tablet.c)
-target_sources_ifdef(CONFIG_TEST_FORM_FACTOR_CLAMSHELL
- app PRIVATE src/clamshell.c)
-target_sources_ifdef(CONFIG_VARIANT_CORSOLA_DB_DETECTION
-app PRIVATE ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/variant_db_detection.c)
-target_sources_ifdef(CONFIG_TEST_DB_DETECT_TYPEC
- app PRIVATE src/db_detect_typec.c)
-target_sources_ifdef(CONFIG_TEST_DB_DETECT_HDMI
- app PRIVATE src/db_detect_hdmi.c
- ${PLATFORM_EC}/zephyr/shim/src/usb_muxes.c
- ${PLATFORM_EC}/driver/usb_mux/usb_mux.c
- ${PLATFORM_EC}/driver/usb_mux/virtual.c)
-target_sources_ifdef(CONFIG_TEST_DB_DETECT_NONE
- app PRIVATE src/db_detect_none.c)
-target_sources_ifdef(CONFIG_TEST_ALT_SENSOR_PROBE
- app PRIVATE src/alt_sensor.c)
-target_sources_ifdef(CONFIG_TEST_KINGLER_CCD
-app PRIVATE src/ccd.c ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/board.c)
-target_sources_ifdef(CONFIG_TEST_VOLTORB
- app PRIVATE src/voltorb_usbc.c
- ${PLATFORM_EC_PROGRAM_DIR}/corsola/voltorb/src/usbc.c)
+target_sources_ifdef(
+ CONFIG_TEST_KINGLER_USBC
+ app
+ PRIVATE
+ ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/npcx_usbc.c
+ ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/npcx_usb_pd_policy.c
+ ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/usb_pd_policy.c
+ ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/usbc.c
+ src/kingler_usbc.c)
+target_sources_ifdef(CONFIG_TEST_STEELIX_RUSTY app PRIVATE
+ ${PLATFORM_EC_PROGRAM_DIR}/corsola/steelix/src/board.c)
+target_sources_ifdef(CONFIG_TEST_FORM_FACTOR_CONVERTIBLE app PRIVATE
+ src/tablet.c)
+target_sources_ifdef(CONFIG_TEST_FORM_FACTOR_CLAMSHELL app PRIVATE
+ src/clamshell.c)
+target_sources_ifdef(
+ CONFIG_VARIANT_CORSOLA_DB_DETECTION app PRIVATE
+ ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/variant_db_detection.c)
+target_sources_ifdef(CONFIG_TEST_DB_DETECT_TYPEC app PRIVATE
+ src/db_detect_typec.c)
+target_sources_ifdef(
+ CONFIG_TEST_DB_DETECT_HDMI
+ app
+ PRIVATE
+ src/db_detect_hdmi.c
+ ${PLATFORM_EC}/zephyr/shim/src/usb_muxes.c
+ ${PLATFORM_EC}/driver/usb_mux/usb_mux.c
+ ${PLATFORM_EC}/driver/usb_mux/virtual.c)
+target_sources_ifdef(CONFIG_TEST_DB_DETECT_NONE app PRIVATE
+ src/db_detect_none.c)
+target_sources_ifdef(CONFIG_TEST_ALT_SENSOR_PROBE app PRIVATE src/alt_sensor.c)
+target_sources_ifdef(CONFIG_TEST_KINGLER_CCD app PRIVATE src/ccd.c
+ ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/board.c)
+target_sources_ifdef(CONFIG_TEST_VOLTORB app PRIVATE src/voltorb_usbc.c
+ ${PLATFORM_EC_PROGRAM_DIR}/corsola/voltorb/src/usbc.c)
+target_sources_ifdef(
+ CONFIG_TEST_DB_DETECTION_USB_COUNT
+ app
+ PRIVATE
+ ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/usbc.c
+ src/usb_port_count.c)
diff --git a/zephyr/test/kingler/Kconfig b/zephyr/test/kingler/Kconfig
index a8449fe8c6..77c1f25253 100644
--- a/zephyr/test/kingler/Kconfig
+++ b/zephyr/test/kingler/Kconfig
@@ -2,6 +2,11 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+config TEST_KINGLER_USBC
+ bool "Run the tests intended for kingler"
+ help
+ Include USB-C tests into the binary.
+
config TEST_STEELIX_RUSTY
bool "Run the tests intended for steelix and rusty"
help
@@ -66,4 +71,10 @@ config TEST_USB_PD_POLICY
Include voltorb_usbc.c into the binary to test the type-c output
current limit function.
+config TEST_DB_DETECTION_USB_COUNT
+ bool "Run the tests intended for db detection"
+ help
+ Include USB-C tests into the binary for testing the reported port
+ count with db detection.
+
source "Kconfig.zephyr"
diff --git a/zephyr/test/kingler/common.dtsi b/zephyr/test/kingler/common.dtsi
index c04844f227..e3b03c57a8 100644
--- a/zephyr/test/kingler/common.dtsi
+++ b/zephyr/test/kingler/common.dtsi
@@ -4,7 +4,9 @@
*/
#include <board-overlays/native_posix.dts>
+#include <dt-bindings/usb_pd_tcpm.h>
#include <npcx_emul.dts>
+#include <zephyr/dt-bindings/gpio/gpio.h>
/ {
usbc {
@@ -25,6 +27,11 @@
compatible = "cros-ec,usb-mux-chain";
usb-muxes = <&virtual_mux_1>;
};
+ usb_mux_chain_1_hdmi_db: usb-mux-chain-1-hdmi-db {
+ compatible = "cros-ec,usb-mux-chain";
+ alternative-chain;
+ usb-muxes = <&virtual_mux_1>;
+ };
};
port0-muxes {
virtual_mux_0: virtual-mux-0 {
@@ -38,6 +45,41 @@
};
};
+ adc0: adc {
+ compatible = "zephyr,adc-emul";
+ nchannels = <6>;
+ ref-internal-mv = <3300>;
+ #io-channel-cells = <1>;
+ status = "okay";
+ };
+
+ named-adc-channels {
+ compatible = "named-adc-channels";
+
+ adc_charger_pmon_r {
+ enum-name = "ADC_PSYS";
+ io-channels = <&adc0 0>;
+ /*
+ * ISL9238C PSYS output is 1.44 uA/W over 33K resistor.
+ */
+ mul = <21043>;
+ };
+ adc_ec_id0 {
+ enum-name = "ADC_ID_0";
+ io-channels = <&adc0 1>;
+ };
+ adc_ec_id1 {
+ enum-name = "ADC_ID_1";
+ io-channels = <&adc0 2>;
+ };
+ adc_charger_amon_r {
+ enum-name = "ADC_AMON_BMON";
+ io-channels = <&adc0 3>;
+ mul = <1000>;
+ div = <18>;
+ };
+ };
+
/* These are temporary just to get the test to build.
* Should be replaced with the correct accel drivers,
* but we're not testing that code right now anyway.
@@ -81,36 +123,17 @@
/* list of sensors in force mode */
accel-force-mode-sensors = <&lid_accel>;
};
+
named-i2c-ports {
compatible = "named-i2c-ports";
i2c_sensor: i2c-sensor {
- i2c-port = <&i2c0_0>;
+ i2c-port = <&i2c_ctrl0>;
enum-names = "I2C_PORT_SENSOR";
};
i2c_eeprom: i2c-eeprom {
- i2c-port = <&i2c3_0>;
- enum-names = "I2C_PORT_EEPROM";
- };
- };
- /* TODO(jbettis): Move the i2c ports and pinctrls to npcx_emul.dts,
- * and add all of them instead of just these.
- */
- soc-if {
- i2c0_0: io_i2c_ctrl0_port0 {
- compatible = "nuvoton,npcx-i2c-port";
- #address-cells = <1>;
- #size-cells = <0>;
- port = <0x00>;
- controller = <&i2c_ctrl0>;
- status = "disabled";
- };
- i2c3_0: io_i2c_ctrl3_port0 {
- compatible = "nuvoton,npcx-i2c-port";
- #address-cells = <1>;
- #size-cells = <0>;
- port = <0x30>;
- controller = <&i2c_ctrl3>;
- status = "disabled";
+ i2c-port = <&i2c_ctrl3>;
+ enum-names = "I2C_PORT_EEPROM", "I2C_PORT_BATTERY",
+ "I2C_PORT_CHARGER";
};
};
pinctrl: pinctrl {
@@ -138,43 +161,31 @@
};
};
-&i2c0_0 {
- status = "okay";
- clock-frequency = <I2C_BITRATE_FAST>;
- pinctrl-0 = <&i2c0_0_sda_scl_gpb4_b5>;
- pinctrl-names = "default";
-};
-
&i2c_ctrl0 {
status = "okay";
-};
-&i2c_ctrl2 {
- status = "okay";
-};
-i2c_pwr_cbi: &i2c3_0 {
- status = "okay";
- clock-frequency = <I2C_BITRATE_FAST>;
- pinctrl-0 = <&i2c3_0_sda_scl_gpd0_d1>;
- pinctrl-names = "default";
-
- charger: isl923x@9 {
- compatible = "intersil,isl923x";
+ battery: sb@b {
+ compatible = "zephyr,smart-battery-emul";
status = "okay";
- reg = <0x9>;
+ reg = <0xb>;
+ cycle-count = <99>;
+ version = "BATTERY_SPEC_VER_1_1_WITH_PEC";
+ /* Real battery voltages are multiples of 4.4V. */
+ desired-charg-volt = <5000>;
+ desired-charg-cur = <1000>;
+ mf-name = "LGC";
+ dev-name = "AC17A8M";
};
};
-&i2c_ctrl3 {
+&i2c_ctrl2 {
status = "okay";
};
-&i2c_ctrl5 {
+&i2c_ctrl3 {
status = "okay";
-};
-&i2c_ctrl3 {
cbi_eeprom: eeprom@50 {
compatible = "atmel,at24";
reg = <0x50>;
@@ -184,3 +195,8 @@ i2c_pwr_cbi: &i2c3_0 {
timeout = <5>;
};
};
+
+&i2c_ctrl5 {
+ status = "okay";
+};
+
diff --git a/zephyr/test/kingler/kingler.default.overlay b/zephyr/test/kingler/kingler.default.overlay
index 908022f5e2..adc3f89451 100644
--- a/zephyr/test/kingler/kingler.default.overlay
+++ b/zephyr/test/kingler/kingler.default.overlay
@@ -6,3 +6,4 @@
#include "common.dtsi"
#include "../program/corsola/npcx_interrupts.dtsi"
#include "../program/corsola/npcx_gpio.dtsi"
+#include "../program/corsola/usba.dtsi"
diff --git a/zephyr/test/kingler/kingler.usbc.conf b/zephyr/test/kingler/kingler.usbc.conf
new file mode 100644
index 0000000000..cb04e5c550
--- /dev/null
+++ b/zephyr/test/kingler/kingler.usbc.conf
@@ -0,0 +1,28 @@
+# Copyright 2023 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+CONFIG_PLATFORM_EC_TCPC_INTERRUPT=y
+CONFIG_PLATFORM_EC_USB_PORT_POWER_DUMB=y
+CONFIG_PLATFORM_EC_USBC=y
+CONFIG_PLATFORM_EC_USB_PORT_POWER_DUMB_CUSTOM_HOOK=y
+CONFIG_PLATFORM_EC_USBC_PPC=y
+CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y
+CONFIG_PLATFORM_EC_VBOOT_HASH=n
+CONFIG_PLATFORM_EC_SWITCH=n
+CONFIG_PLATFORM_EC_USB_PD_DISCHARGE_PPC=y
+CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_BY_BOARD=y
+CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR=10
+CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR_AC=20
+CONFIG_PLATFORM_EC_EXTPOWER=y
+CONFIG_PLATFORM_EC_HOSTCMD=y
+CONFIG_PLATFORM_EC_USB_PD_TCPM_ANX7447=y
+CONFIG_VARIANT_CORSOLA_DB_DETECTION=n
+CONFIG_PLATFORM_EC_BACKLIGHT_LID=n
+CONFIG_PLATFORM_EC_CHARGER_ISL9238C=y
+CONFIG_PLATFORM_EC_CHARGE_MANAGER=y
+CONFIG_PLATFORM_EC_CHARGER=y
+CONFIG_PLATFORM_EC_LID_SWITCH=y
+CONFIG_PLATFORM_EC_CHARGE_RAMP_HW=y
+CONFIG_PLATFORM_EC_USB_CHARGER=y
+CONFIG_PLATFORM_EC_USB_PD_TCPM_ANX7447=y
diff --git a/zephyr/test/kingler/kingler.usbc.overlay b/zephyr/test/kingler/kingler.usbc.overlay
new file mode 100644
index 0000000000..b697edf791
--- /dev/null
+++ b/zephyr/test/kingler/kingler.usbc.overlay
@@ -0,0 +1,118 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <zephyr/dt-bindings/gpio/gpio.h>
+#include <dt-bindings/usb_pd_tcpm.h>
+
+#include "common.dtsi"
+#include "../program/corsola/npcx_interrupts.dtsi"
+#include "../program/corsola/npcx_gpio.dtsi"
+#include "../program/corsola/usba.dtsi"
+
+/ {
+ usbc {
+ port0@0 {
+ bc12 = <&pi3usb9201_emul0>;
+ tcpc = <&anx7447_emul0>;
+ ppc = <&nx20p348x_emul0>;
+ chg = <&charger_emul>;
+ usb-mux-chain-0 {
+ compatible = "cros-ec,usb-mux-chain";
+ usb-muxes = <&virtual_mux_0>;
+ };
+ };
+
+ port1@1 {
+ /* We have rt1718s emulator, but use tcpci_emul instead
+ * for better test integration of the GPIO pin control.
+ */
+ tcpc = <&rt1718s_emul1>;
+ ppc = <&nx20p348x_emul1>;
+ usb_mux_chain_1_hdmi_db: usb-mux-chain-1-hdmi-db {
+ compatible = "cros-ec,usb-mux-chain";
+ alternative-chain;
+ usb-muxes = <&virtual_mux_1>;
+ };
+ };
+ };
+
+ batteries {
+ default_battery: lgc_ac17a8m {
+ compatible = "lgc,ac17a8m", "battery-smart";
+ /**
+ * this has to be strictly lower than the desired
+ * voltage in smart battery emulator (5000mV).
+ */
+ voltage_min = <4000>;
+ };
+ };
+};
+
+&i2c_ctrl0 {
+ anx7447_emul0: anx7447_emul@2c {
+ compatible = "cros,anx7447-tcpc-emul";
+ status = "okay";
+ reg = <0x2c>;
+ tcpc-flags = <(
+ TCPC_FLAGS_VBUS_MONITOR |
+ TCPC_FLAGS_ALERT_OD |
+ TCPC_FLAGS_CONTROL_VCONN |
+ TCPC_FLAGS_CONTROL_FRS)>;
+ };
+
+ /* TODO: drop this node when the Kconfig dependency is fixed. */
+ tcpci_emul0: tcpci_emul@82 {
+ compatible = "cros,tcpci-generic-emul";
+ status = "okay";
+ reg = <0x82>;
+ };
+
+ nx20p348x_emul0: nx20p348x_emul@71 {
+ compatible = "nxp,nx20p348x";
+ status = "okay";
+ reg = <0x71>;
+ irq-gpios = < &gpio6 7 GPIO_ACTIVE_HIGH>;
+ };
+
+ pi3usb9201_emul0: pi3usb9201@5d {
+ compatible = "pericom,pi3usb9201";
+ reg = <0x5d>;
+ irq = <&int_usb_c0_bc12>;
+ };
+};
+
+&i2c_ctrl3 {
+ status = "okay";
+
+ charger_emul: isl923x@9 {
+ compatible = "cros,isl923x-emul";
+ status = "okay";
+ reg = <0x9>;
+ battery = <&battery>;
+ };
+
+ rt1718s_emul1: rt1718s_emul@2c {
+ compatible = "cros,rt1718s-tcpc-emul", "richtek,rt1718s-tcpc";
+ status = "okay";
+ reg = <0x2c>;
+ tcpc-flags = <(TCPC_FLAGS_ALERT_OD |
+ TCPC_FLAGS_CONTROL_VCONN |
+ TCPC_FLAGS_CONTROL_FRS)>;
+ };
+
+ /* TODO: drop this node when the Kconfig dependency is fixed. */
+ tcpci_emul1: tcpci_emul@82 {
+ compatible = "cros,tcpci-generic-emul";
+ status = "okay";
+ reg = <0x82>;
+ };
+
+ nx20p348x_emul1: nx20p348x_emul@71 {
+ compatible = "nxp,nx20p348x";
+ status = "okay";
+ reg = <0x71>;
+ irq-gpios = < &gpiod 4 GPIO_ACTIVE_HIGH >;
+ };
+};
diff --git a/zephyr/test/kingler/prj.conf b/zephyr/test/kingler/prj.conf
index 17ffd4fb17..bfa73043cd 100644
--- a/zephyr/test/kingler/prj.conf
+++ b/zephyr/test/kingler/prj.conf
@@ -12,6 +12,7 @@ CONFIG_PLATFORM_EC_HOOKS=y
CONFIG_CROS_EC=y
CONFIG_PLATFORM_EC=y
+CONFIG_PLATFORM_EC_GPIO_INIT_PRIORITY=49
CONFIG_PLATFORM_EC_DYNAMIC_MOTION_SENSOR_COUNT=y
CONFIG_PLATFORM_EC_GMR_TABLET_MODE=y
CONFIG_PLATFORM_EC_TABLET_MODE=y
@@ -23,3 +24,6 @@ CONFIG_PLATFORM_EC_BOARD_VERSION_CBI=y
CONFIG_EEPROM=y
CONFIG_EEPROM_SIMULATOR=n
CONFIG_EMUL_EEPROM_AT2X=y
+
+CONFIG_LOG=y
+CONFIG_LOG_MODE_MINIMAL=y
diff --git a/zephyr/test/kingler/src/fakes.c b/zephyr/test/kingler/src/fakes.c
index 412e02fef9..c4a7cf0a6d 100644
--- a/zephyr/test/kingler/src/fakes.c
+++ b/zephyr/test/kingler/src/fakes.c
@@ -9,16 +9,27 @@
FAKE_VOID_FUNC(power_button_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(button_interrupt, enum gpio_signal);
-FAKE_VOID_FUNC(lid_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(chipset_reset_request_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(power_signal_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(chipset_watchdog_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(extpower_interrupt, enum gpio_signal);
-FAKE_VOID_FUNC(xhci_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(switch_interrupt, enum gpio_signal);
+#if !(defined(CONFIG_TEST_KINGLER_USBC) || \
+ defined(CONFIG_TEST_DB_DETECTION_USB_COUNT))
+FAKE_VOID_FUNC(xhci_interrupt, enum gpio_signal);
+#endif
+#ifndef CONFIG_TEST_KINGLER_USBC
+FAKE_VOID_FUNC(lid_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(usb_a0_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(tcpc_alert_event, enum gpio_signal);
FAKE_VOID_FUNC(ppc_interrupt, enum gpio_signal);
FAKE_VOID_FUNC(bc12_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(pd_power_supply_reset, int);
+FAKE_VOID_FUNC(pd_set_power_supply_ready, int);
+FAKE_VALUE_FUNC(int, board_set_active_charge_port, int);
+FAKE_VALUE_FUNC(int, pd_snk_is_vbus_provided, int);
+FAKE_VALUE_FUNC(int, pd_check_vconn_swap, int);
+#endif
FAKE_VOID_FUNC(chipset_warm_reset_interrupt, enum gpio_signal);
#ifndef CONFIG_TEST_KINGLER_CCD
FAKE_VOID_FUNC(ccd_interrupt, enum gpio_signal);
diff --git a/zephyr/test/kingler/src/kingler_usbc.c b/zephyr/test/kingler/src/kingler_usbc.c
new file mode 100644
index 0000000000..afd8cdbccd
--- /dev/null
+++ b/zephyr/test/kingler/src/kingler_usbc.c
@@ -0,0 +1,78 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "driver/tcpm/tcpm.h"
+#include "ec_app_main.h"
+#include "usb_charge.h"
+#include "usb_pd.h"
+#include "usbc_ppc.h"
+#include "variant_db_detection.h"
+
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/fff.h>
+#include <zephyr/kernel.h>
+#include <zephyr/logging/log.h>
+#include <zephyr/ztest.h>
+
+#define LOG_LEVEL 0
+LOG_MODULE_REGISTER(npcx_usbc);
+
+FAKE_VALUE_FUNC(enum corsola_db_type, corsola_get_db_type);
+FAKE_VALUE_FUNC(bool, in_interrupt_context);
+FAKE_VOID_FUNC(bmi3xx_interrupt);
+FAKE_VOID_FUNC(hdmi_hpd_interrupt);
+FAKE_VOID_FUNC(ps185_hdmi_hpd_mux_set);
+FAKE_VALUE_FUNC(bool, ps8743_field_update, const struct usb_mux *, uint8_t,
+ uint8_t, uint8_t);
+
+#define FFF_FAKES_LIST(FAKE) \
+ FAKE(corsola_get_db_type) \
+ FAKE(in_interrupt_context) \
+ FAKE(bmi3xx_interrupt) \
+ FAKE(hdmi_hpd_interrupt) \
+ FAKE(ps185_hdmi_hpd_mux_set) \
+ FAKE(ps8743_field_update)
+
+struct kingler_usbc_fixture {
+ int place_holder;
+};
+
+static void *kingler_usbc_setup(void)
+{
+ static struct kingler_usbc_fixture f;
+
+ return &f;
+}
+
+static void kingler_usbc_reset_rule_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ FFF_FAKES_LIST(RESET_FAKE);
+ FFF_RESET_HISTORY();
+}
+
+ZTEST_RULE(kingler_usbc_reset_rule, kingler_usbc_reset_rule_before, NULL);
+ZTEST_SUITE(kingler_usbc, NULL, kingler_usbc_setup, NULL, NULL, NULL);
+
+ZTEST_F(kingler_usbc, test_power_supply)
+{
+ pd_power_supply_reset(0);
+ zassert_equal(0, ppc_is_sourcing_vbus(0));
+ zassert_equal(0, ppc_is_sourcing_vbus(1));
+
+ zassert_equal(EC_SUCCESS, pd_set_power_supply_ready(0));
+ zassert_equal(1, ppc_is_sourcing_vbus(0));
+ zassert_equal(0, ppc_is_sourcing_vbus(1));
+
+ pd_power_supply_reset(0);
+ zassert_equal(0, ppc_is_sourcing_vbus(0));
+ zassert_equal(0, ppc_is_sourcing_vbus(1));
+
+ /* TODO: test C1 port after resolve the PPC emulator always accessing
+ * the same one with different index.
+ */
+}
diff --git a/zephyr/test/kingler/src/usb_port_count.c b/zephyr/test/kingler/src/usb_port_count.c
new file mode 100644
index 0000000000..4f55bdc693
--- /dev/null
+++ b/zephyr/test/kingler/src/usb_port_count.c
@@ -0,0 +1,90 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "driver/tcpm/tcpm.h"
+#include "ec_app_main.h"
+#include "usb_charge.h"
+#include "usb_pd.h"
+#include "usbc_ppc.h"
+#include "variant_db_detection.h"
+
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/fff.h>
+#include <zephyr/kernel.h>
+#include <zephyr/logging/log.h>
+#include <zephyr/ztest.h>
+
+#define LOG_LEVEL 0
+LOG_MODULE_REGISTER(usb_port_count);
+
+FAKE_VALUE_FUNC(enum corsola_db_type, corsola_get_db_type);
+FAKE_VALUE_FUNC(bool, in_interrupt_context);
+FAKE_VOID_FUNC(bmi3xx_interrupt);
+FAKE_VOID_FUNC(hdmi_hpd_interrupt);
+FAKE_VOID_FUNC(ps185_hdmi_hpd_mux_set);
+FAKE_VALUE_FUNC(bool, ps8743_field_update, const struct usb_mux *, uint8_t,
+ uint8_t, uint8_t);
+FAKE_VOID_FUNC(pd_set_dual_role, int, enum pd_dual_role_states);
+FAKE_VALUE_FUNC(int, tc_is_attached_src, int);
+
+#define FFF_FAKES_LIST(FAKE) \
+ FAKE(corsola_get_db_type) \
+ FAKE(in_interrupt_context) \
+ FAKE(bmi3xx_interrupt) \
+ FAKE(hdmi_hpd_interrupt) \
+ FAKE(ps185_hdmi_hpd_mux_set) \
+ FAKE(ps8743_field_update) \
+ FAKE(pd_set_dual_role) \
+ FAKE(tc_is_attached_src)
+
+struct usb_port_count_fixture {
+ int place_holder;
+};
+
+static void *usb_port_count_setup(void)
+{
+ static struct usb_port_count_fixture f;
+
+ return &f;
+}
+
+static void usb_port_count_reset_rule_before(const struct ztest_unit_test *test,
+ void *data)
+{
+ ARG_UNUSED(test);
+ ARG_UNUSED(data);
+ FFF_FAKES_LIST(RESET_FAKE);
+ FFF_RESET_HISTORY();
+}
+
+ZTEST_RULE(usb_port_count_reset_rule, usb_port_count_reset_rule_before, NULL);
+ZTEST_SUITE(usb_port_count, NULL, usb_port_count_setup, NULL, NULL, NULL);
+
+ZTEST_F(usb_port_count, test_detect_db)
+{
+ struct {
+ enum corsola_db_type test_type;
+ int expected_board_get_port_count;
+ int expected_board_get_adjusted_port_count;
+ } testdata[] = { { CORSOLA_DB_UNINIT, CONFIG_USB_PD_PORT_MAX_COUNT,
+ CONFIG_USB_PD_PORT_MAX_COUNT - 1 },
+ { CORSOLA_DB_NO_DETECTION,
+ CONFIG_USB_PD_PORT_MAX_COUNT,
+ CONFIG_USB_PD_PORT_MAX_COUNT },
+ { CORSOLA_DB_NONE, CONFIG_USB_PD_PORT_MAX_COUNT - 1,
+ CONFIG_USB_PD_PORT_MAX_COUNT - 1 },
+ { CORSOLA_DB_TYPEC, CONFIG_USB_PD_PORT_MAX_COUNT,
+ CONFIG_USB_PD_PORT_MAX_COUNT },
+ { CORSOLA_DB_HDMI, CONFIG_USB_PD_PORT_MAX_COUNT - 1,
+ CONFIG_USB_PD_PORT_MAX_COUNT - 1 } };
+ for (int i = 0; i < ARRAY_SIZE(testdata); i++) {
+ corsola_get_db_type_fake.return_val = testdata[i].test_type;
+ zassert_equal(board_get_usb_pd_port_count(),
+ testdata[i].expected_board_get_port_count);
+ zassert_equal(
+ board_get_adjusted_usb_pd_port_count(),
+ testdata[i].expected_board_get_adjusted_port_count);
+ }
+}
diff --git a/zephyr/test/kingler/testcase.yaml b/zephyr/test/kingler/testcase.yaml
index 04e580fe22..8012c7dc4f 100644
--- a/zephyr/test/kingler/testcase.yaml
+++ b/zephyr/test/kingler/testcase.yaml
@@ -1,6 +1,14 @@
common:
platform_allow: native_posix
tests:
+ kingler.usbc:
+ extra_configs:
+ - CONFIG_TEST_KINGLER_USBC=y
+ extra_conf_files:
+ - prj.conf
+ - kingler.usbc.conf
+ extra_dtc_overlay_files:
+ - kingler.usbc.overlay
kingler.steelix:
extra_configs:
- CONFIG_TEST_STEELIX_RUSTY=y
@@ -50,3 +58,8 @@ tests:
- CONFIG_TEST_USB_PD_POLICY=y
extra_dtc_overlay_files:
- kingler.default.overlay
+ kingler.usb_port_count:
+ extra_configs:
+ - CONFIG_TEST_DB_DETECTION_USB_COUNT=y
+ extra_dtc_overlay_files:
+ - kingler.default.overlay
diff --git a/zephyr/test/krabby/src/usbc_config.c b/zephyr/test/krabby/src/usbc_config.c
index 909a8f38a7..16d31d20de 100644
--- a/zephyr/test/krabby/src/usbc_config.c
+++ b/zephyr/test/krabby/src/usbc_config.c
@@ -8,10 +8,8 @@
#include "charge_manager.h"
#include "driver/ppc/syv682x.h"
#include "driver/ppc/syv682x_public.h"
-#include "driver/tcpm/rt1718s.h"
#include "emul/emul_common_i2c.h"
#include "emul/emul_syv682x.h"
-#include "emul/tcpc/emul_rt1718s.h"
#include "i2c/i2c.h"
#include "test_state.h"
#include "usb_pd.h"
@@ -33,17 +31,6 @@ static bool ppc_sink_enabled(int port)
return !(val & (SYV682X_CONTROL_1_PWR_ENB | SYV682X_CONTROL_1_HV_DR));
}
-static bool usb_c1_source_gpio_enabled(void)
-{
- const struct emul *emul = EMUL_DT_GET(DT_NODELABEL(rt1718s_emul));
- uint16_t val = 0;
-
- rt1718s_emul_get_reg(emul, RT1718S_GPIO_CTRL(GPIO_EN_USB_C1_SOURCE),
- &val);
-
- return val & RT1718S_GPIO_CTRL_O;
-}
-
ZTEST(usbc_config, test_set_active_charge_port)
{
/* reset ppc state */
@@ -119,16 +106,6 @@ ZTEST(usbc_config, test_set_active_charge_port_fail)
zassert_false(ppc_sink_enabled(1), NULL);
}
-ZTEST(usbc_config, test_rt1718s_gpio_toggle)
-{
- /* toggle sourcing on port 1, expect rt1718s gpio also changes */
- zassert_false(usb_c1_source_gpio_enabled());
- zassert_ok(pd_set_power_supply_ready(1));
- zassert_true(usb_c1_source_gpio_enabled());
- pd_power_supply_reset(1);
- zassert_false(usb_c1_source_gpio_enabled());
-}
-
ZTEST(usbc_config, test_adc_channel)
{
zassert_equal(board_get_vbus_adc(0), ADC_VBUS_C0, NULL);
diff --git a/zephyr/zmake/zmake/toolchains.py b/zephyr/zmake/zmake/toolchains.py
index 2e1458ce5b..a92baf2a3e 100644
--- a/zephyr/zmake/zmake/toolchains.py
+++ b/zephyr/zmake/zmake/toolchains.py
@@ -1,6 +1,7 @@
# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+
"""Definitions of toolchain variables."""
import os
@@ -55,7 +56,7 @@ class CorebootSdkToolchain(GenericToolchain):
"""
path = pathlib.Path(
os.environ.get("COREBOOT_SDK_ROOT", "/opt/coreboot-sdk")
- )
+ ).resolve()
if path.is_dir():
return path
return None