diff options
Diffstat (limited to 'zephyr')
45 files changed, 1206 insertions, 171 deletions
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 |