diff options
author | Patryk Duda <pdk@semihalf.com> | 2022-06-07 15:26:53 +0200 |
---|---|---|
committer | Patryk Duda <patrykd@google.com> | 2022-06-07 15:52:56 +0200 |
commit | 63a8a1366e390b757c37e167927102be0fc4fb63 (patch) | |
tree | c06f1438b73115db8af42bc05d3df2483c6abf29 /include | |
parent | 6fcfe697803fd4e16e7f9d9c64ac091fa6034efe (diff) | |
parent | 38b9c4b824f34b3aa81f2399ce91b88077197d52 (diff) | |
download | chrome-ec-63a8a1366e390b757c37e167927102be0fc4fb63.tar.gz |
Merge remote-tracking branch cros/main into firmware-fpmcu-dartmonkey-release
Generated by: ./util/update_release_branch.py --board dartmonkey --relevant_paths_file ./util/fingerprint-relevant-paths.txt firmware-fpmcu-dartmonkey-release
Relevant changes:
git log --oneline 6fcfe69780..38b9c4b824 -- board/nocturne_fp
board/dartmonkey common/fpsensor docs/fingerprint driver/fingerprint
util/getversion.sh
42db333f60 docs/fingerprint: Add links to TPM design doc
9f63d3f400 docs/fingerprint: Fix typo
28c0e2d4e0 Docs: Replace Chrome OS with ChromeOS in FP docs
BRANCH=None
BUG=b:200828093
TEST=`make -j buildall`
TEST=`./test/run_device_tests.py --board dartmonkey`
Test "aes": PASSED
Test "cec": PASSED
Test "cortexm_fpu": PASSED
Test "crc": PASSED
Test "flash_physical": PASSED
Test "flash_write_protect": PASSED
Test "fpsensor_hw": PASSED
Test "fpsensor_spi_ro": PASSED
Test "fpsensor_spi_rw": PASSED
Test "fpsensor_uart_ro": PASSED
Test "fpsensor_uart_rw": PASSED
Test "mpu_ro": PASSED
Test "mpu_rw": PASSED
Test "mutex": PASSED
Test "pingpong": PASSED
Test "printf": PASSED
Test "queue": PASSED
Test "rollback_region0": PASSED
Test "rollback_region1": PASSED
Test "rollback_entropy": PASSED
Test "rtc": PASSED
Test "sha256": PASSED
Test "sha256_unrolled": PASSED
Test "static_if": PASSED
Test "system_is_locked_wp_on": PASSED
Test "system_is_locked_wp_off": PASSED
Test "timer_dos": PASSED
Test "utils": PASSED
Test "utils_str": PASSED
Test "panic_data_dartmonkey_v2.0.2887": PASSED
Test "panic_data_nocturne_fp_v2.2.64": PASSED
Test "panic_data_nami_fp_v2.2.144": PASSED
Cq-Include-Trybots: chromeos/cq:cq-orchestrator
Signed-off-by: Patryk Duda <pdk@semihalf.com>
Change-Id: I0863a7a0ac6ffb5db2d9445ed71f2d9a5d24cbb1
Diffstat (limited to 'include')
44 files changed, 788 insertions, 204 deletions
diff --git a/include/atomic_t.h b/include/atomic_t.h index e35fc187bf..d7c1a99147 100644 --- a/include/atomic_t.h +++ b/include/atomic_t.h @@ -16,7 +16,7 @@ typedef long atomic_t; #endif typedef atomic_t atomic_val_t; #else -#include <sys/atomic.h> +#include <zephyr/sys/atomic.h> #endif #endif /* __CROS_EC_ATOMIC_T_H */ diff --git a/include/battery.h b/include/battery.h index 2bf6e7bb06..9daf1ce981 100644 --- a/include/battery.h +++ b/include/battery.h @@ -12,12 +12,15 @@ #include "compiler.h" #include "host_command.h" -/* Battery index, only used with CONFIG_BATTERY_V2. */ -enum battery_index { - BATT_IDX_INVALID = -1, - BATT_IDX_MAIN = 0, - BATT_IDX_BASE = 1, -}; +/* + * If compiling with Zephyr, include the BATTERY_LEVEL_ definitions that are + * shared with device tree + */ +#ifdef CONFIG_ZEPHYR + +#include "dt-bindings/battery.h" + +#else /* !CONFIG_ZEPHYR */ /* Stop charge when charging and battery level >= this percentage */ #define BATTERY_LEVEL_FULL 100 @@ -47,9 +50,18 @@ enum battery_index { */ #define BATTERY_LEVEL_SHUTDOWN 3 +#endif /* CONFIG_ZEPHYR */ + /* Full-capacity change reqd for host event */ #define LFCC_EVENT_THRESH 5 +/* Battery index, only used with CONFIG_BATTERY_V2. */ +enum battery_index { + BATT_IDX_INVALID = -1, + BATT_IDX_MAIN = 0, + BATT_IDX_BASE = 1, +}; + /* * Sometimes we have hardware to detect battery present, sometimes we have to * wait until we've been able to talk to the battery. @@ -404,6 +416,14 @@ int battery_manufacturer_date(int *year, int *month, int *day); int battery_manufacturer_data(char *data, int size); /** + * Write battery manufacturer access. + * + * @param cmd Destiation for battery manufacturer access command. + * @retun non-zeor if error. + */ +int battery_manufacturer_access(int cmd); + +/** * Report the absolute difference between the highest and lowest cell voltage in * the battery pack, in millivolts. On error or unimplemented, returns '0'. */ diff --git a/include/battery_smart.h b/include/battery_smart.h index b97d681223..c37b7c692c 100644 --- a/include/battery_smart.h +++ b/include/battery_smart.h @@ -56,9 +56,14 @@ #define SB_DEVICE_NAME 0x21 #define SB_DEVICE_CHEMISTRY 0x22 #define SB_MANUFACTURER_DATA 0x23 +#define SB_OPTIONAL_MFG_FUNC1 0x3C +#define SB_OPTIONAL_MFG_FUNC2 0x3D +#define SB_OPTIONAL_MFG_FUNC3 0x3E +#define SB_OPTIONAL_MFG_FUNC4 0x3F /* Extension of smart battery spec, may not be supported on all platforms */ #define SB_PACK_STATUS 0x43 #define SB_ALT_MANUFACTURER_ACCESS 0x44 +#define SB_MANUFACTURE_INFO 0x70 /* Battery mode */ #define MODE_INTERNAL_CHARGE_CONTROLLER BIT(0) @@ -152,6 +157,7 @@ /* Manufacturer Access parameters */ #define PARAM_SAFETY_STATUS 0x51 #define PARAM_OPERATION_STATUS 0x54 +#define PARAM_FIRMWARE_RUNTIME 0x62 /* Operation status masks -- 6 byte reply */ /* reply[3] */ #define BATTERY_DISCHARGING_DISABLED 0x20 @@ -165,13 +171,27 @@ #define MANUFACTURE_DATE_YEAR_MASK 0xFE00 #define MANUFACTURE_DATE_YEAR_SHIFT 9 #define MANUFACTURE_DATE_YEAR_OFFSET 1980 +#define MANUFACTURE_RUNTIME_SIZE 4 /* Read from battery */ int sb_read(int cmd, int *param); -/* Read sequence from battery */ +/** + * Read null-terminated string from battery + * @param offset Battery register to read from + * @param data Buffer to hold the string + * @param len Length of data buffer + */ int sb_read_string(int offset, uint8_t *data, int len); +/** + * Read sized block of data from battery + * @param offset Battery register to read from + * @param data Buffer to hold read data + * @param len Length of data buffer + */ +int sb_read_sized_block(int offset, uint8_t *data, int len); + /* Write to battery */ int sb_write(int cmd, int param); diff --git a/include/charge_manager.h b/include/charge_manager.h index 2cded28295..b6d3c235bf 100644 --- a/include/charge_manager.h +++ b/include/charge_manager.h @@ -19,7 +19,8 @@ /* Only track BC1.2 charge current if we support BC1.2 charging */ #if defined(HAS_TASK_USB_CHG) || defined(HAS_TASK_USB_CHG_P0) || \ -defined(TEST_BUILD) + defined(CONFIG_PLATFORM_EC_USB_CHARGER_SINGLE_TASK) || \ + defined(TEST_BUILD) #define CHARGE_MANAGER_BC12 #endif diff --git a/include/chipset.h b/include/chipset.h index 48c65374a2..51a9018dfb 100644 --- a/include/chipset.h +++ b/include/chipset.h @@ -94,6 +94,13 @@ void chipset_throttle_cpu(int throttle); void chipset_force_shutdown(enum chipset_shutdown_reason reason); /** + * Attempt to power on the chipset if it's in S4/S5/G3. + * + * This does nothing if in S3/S0ix/S0. + */ +void chipset_power_on(void); + +/** * Reset the CPU and/or chipset. */ void chipset_reset(enum chipset_shutdown_reason reason); diff --git a/include/common.h b/include/common.h index 391000933b..33c9ab97c2 100644 --- a/include/common.h +++ b/include/common.h @@ -15,8 +15,8 @@ #ifdef CONFIG_ZEPHYR #include <fpu.h> -#include <sys/util.h> -#include <toolchain.h> +#include <zephyr/sys/util.h> +#include <zephyr/toolchain.h> #ifdef CONFIG_ZTEST #define TEST_BUILD #endif /* CONFIG_ZTEST */ diff --git a/include/compile_time_macros.h b/include/compile_time_macros.h index afb2c30d19..0151f1a391 100644 --- a/include/compile_time_macros.h +++ b/include/compile_time_macros.h @@ -14,7 +14,7 @@ /* sys/util.h in zephyr provides equivalents to most of these macros */ #ifdef CONFIG_ZEPHYR -#include <sys/util.h> +#include <zephyr/sys/util.h> #endif #ifdef __cplusplus diff --git a/include/config.h b/include/config.h index 30adc88ce1..b19f76f614 100644 --- a/include/config.h +++ b/include/config.h @@ -112,12 +112,6 @@ #undef CONFIG_ACCEL_LIS2DWL #undef CONFIG_ACCEL_LIS2DW_COMMON -/* lis2dw driver support fifo and interrupt, but letting lid accel sensor work - * at polling mode is a common selection in current usage model. We need get a - * option to be able to select interrupt or polling (foced mode). - */ -#undef CONFIG_ACCEL_LIS2DW_AS_BASE - #undef CONFIG_ACCELGYRO_BMI160 #undef CONFIG_ACCELGYRO_BMI220 #undef CONFIG_ACCELGYRO_BMI260 @@ -375,6 +369,7 @@ #undef CONFIG_ACCELGYRO_BMI260_INT_EVENT #undef CONFIG_ACCELGYRO_BMI3XX_INT_EVENT #undef CONFIG_ACCELGYRO_ICM426XX_INT_EVENT +#undef CONFIG_ACCELGYRO_ICM42607_INT_EVENT #undef CONFIG_ACCEL_LSM6DSM_INT_EVENT #undef CONFIG_ACCEL_LSM6DSO_INT_EVENT #undef CONFIG_ACCEL_LIS2DS_INT_EVENT @@ -918,6 +913,11 @@ /* Compile input current ramping support using software control */ #undef CONFIG_CHARGE_RAMP_SW +/* Enable EC support for charging splashscreen */ +#undef CONFIG_CHARGESPLASH +#undef CONFIG_CHARGESPLASH_PERIOD +#undef CONFIG_CHARGESPLASH_MAX_REQUESTS_PER_PERIOD + /*****************************************************************************/ /* Charger config */ @@ -1336,6 +1336,7 @@ /* Wireless chargers */ #undef CONFIG_WIRELESS_CHARGER_P9221_R7 +#undef CONFIG_CPS8100 /*****************************************************************************/ @@ -1562,6 +1563,7 @@ #undef CONFIG_CMD_BUTTON #define CONFIG_CMD_CBI #undef CONFIG_CMD_PD_SRCCAPS_REDUCED_SIZE +#undef CONFIG_CMD_VBUS /* * HAS_TASK_CHIPSET implies the GSC presence. @@ -2627,6 +2629,12 @@ #undef CONFIG_I2C_VIRTUAL_BATTERY /* + * Define this configuration to support smart battery MFG function + * for virtual battery. + */ +#undef CONFIG_SMART_BATTERY_OPTIONAL_MFG_FUNC + +/* * Define this option if an i2c bus may be unpowered at a certain point during * runtime. An example could be, a sensor bus which is not needed in lower * power states so the power rail for those sensors is completely disabled. @@ -2783,8 +2791,8 @@ /* * Support IT8801 I/O expander. * - * I2C address IT8801_KEYBOARD_PWM_I2C_ADDR_FLAGS and I2C port - * IT8801_KEYBOARD_PWM_I2C_PORT must be defined as well. + * I2C address KB_DISCRETE_I2C_ADDR_FLAGS and I2C port + * I2C_PORT_KB_DISCRETE must be defined as well. * Note: these values are only used when accessing the keyboard and PWM * function of the IT8801 chip. I/O expander functions are accessed using * the ioex_config[] array. @@ -2919,7 +2927,7 @@ * chip. You might want this enabled if the keyboard is indirectly connected * to the EC, perhaps through an I2C controller. */ -#undef CONFIG_KEYBOARD_NOT_RAW +#undef CONFIG_KEYBOARD_DISCRETE /* The board uses a negative edge-triggered GPIO for keyboard interrupts. */ #undef CONFIG_KEYBOARD_IRQ_GPIO @@ -3139,9 +3147,13 @@ #undef CONFIG_LED_DRIVER_LP5562 /* LP5562, on I2C interface */ #undef CONFIG_LED_DRIVER_MP3385 /* MPS MP3385, on I2C */ #undef CONFIG_LED_DRIVER_OZ554 /* O2Micro OZ554, on I2C */ +#undef CONFIG_LED_DRIVER_IS31FL3733B /* Lumissil IS31FL3733B on I2C */ #undef CONFIG_LED_DRIVER_IS31FL3743B /* Lumissil IS31FL3743B on SPI */ #undef CONFIG_LED_DRIVER_AW20198 /* Awinic AW20198 on I2C */ +/* Enable late init for is31fl3743b. Work around b:232443638. */ +#undef CONFIG_IS31FL3743B_LATE_INIT + /* Offset in flash where little firmware will live. */ #undef CONFIG_LFW_OFFSET @@ -3621,6 +3633,14 @@ */ #undef CONFIG_CPU_PROCHOT_ACTIVE_LOW +/* + * When the AP enters C10, the power rails VCCIO, VCCSTG, and VCCPLL_OC may be + * turned off by the board. If the PROCHOT# signal is pulled up by any of + * these rails, PROCHOT cannot be relied upon while C10 is active. + * Enable this option to gate PROCHOT detection when C10 is active. + */ +#undef CONFIG_CPU_PROCHOT_GATE_ON_C10 + /* Support PS/2 interface */ #undef CONFIG_PS2 @@ -4883,6 +4903,13 @@ #undef CONFIG_USB_PD_TCPM_MUX /* + * Some PD chips have integrated port protection for SBU lines. + * If the switches to enable those SBU lines are controlled by the PD + * chip, enable this config. + */ +#undef CONFIG_USB_PD_TCPM_SBU + +/* * The TCPM must know whether VBUS is present in order to make proper state * transitions. In addition, charge_manager must know about VBUS presence in * order to make charging decisions. VBUS state can be determined by various @@ -4925,6 +4952,9 @@ /* Set the default minimum battery percentage for Try.Src to be enabled */ #define CONFIG_USB_PD_TRY_SRC_MIN_BATT_SOC 5 +/* Index for temperature sensor used in PD messages. Defaults to 0. */ +#define CONFIG_USB_PD_TEMP_SENSOR 0 + /* * Set the minimum battery percentage to allow a PD port to send resets as a * sink (and risk a hard reset, losing Vbus). Note this may cause a high-power @@ -5272,6 +5302,9 @@ /* Allow run-time completion of the usb mux driver structure */ #undef CONFIG_USB_MUX_RUNTIME_CONFIG +/* Allow the AP to send commands for mux control */ +#undef CONFIG_USB_MUX_AP_CONTROL + /* Support the AMD FP5 USB/DP Mux */ #undef CONFIG_USB_MUX_AMD_FP5 @@ -5320,6 +5353,12 @@ /* Support the Texas Instrument TUSB1064 Type-C Redriving Switch (UFP) */ #undef CONFIG_USB_MUX_TUSB1064 +/* + * Support TI TUSB546 USB Type-C DP ALT Mode Linear Redriver Crosspoint + * Switch + */ +#undef CONFIG_USB_MUX_TUSB546 + /* Support the Parade PS8822 Type-C Redriving Demux Switch */ #undef CONFIG_USB_MUX_PS8822 @@ -5645,7 +5684,7 @@ * The historical default SCI pulse width to the host is 65 microseconds, but * some chipsets may require different widths. */ -#define CONFIG_ESPI_DEFAULT_SCI_WIDTH_US 65 +#define CONFIG_ESPI_DEFAULT_VW_WIDTH_US 65 /*****************************************************************************/ /* @@ -6040,6 +6079,7 @@ #define CONFIG_USB_PD_DISCHARGE_TCPC #define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE #define CONFIG_USB_PD_PPC +#define CONFIG_USB_PD_TCPM_SBU #define CONFIG_USB_PD_TCPC_LOW_POWER #define CONFIG_USB_PD_TCPM_TCPCI #define CONFIG_USB_PD_VBUS_DETECT_TCPC @@ -6637,6 +6677,16 @@ #endif /* CONFIG_USB_PD_DISCHARGE_GPIO */ #endif /* CONFIG_USB_PD_DISCHARGE */ +/* Chargesplash defaults */ +#ifdef CONFIG_CHARGESPLASH +#ifndef CONFIG_CHARGESPLASH_PERIOD +#define CONFIG_CHARGESPLASH_PERIOD 900 +#endif +#ifndef CONFIG_CHARGESPLASH_MAX_REQUESTS_PER_PERIOD +#define CONFIG_CHARGESPLASH_MAX_REQUESTS_PER_PERIOD 5 +#endif +#endif + /* EC Codec Wake-on-Voice related definitions */ #ifdef CONFIG_AUDIO_CODEC_WOV #define CONFIG_SHA256 diff --git a/include/driver/accel_bma2x2_public.h b/include/driver/accel_bma2x2_public.h index 6b3d366270..731fcebbc9 100644 --- a/include/driver/accel_bma2x2_public.h +++ b/include/driver/accel_bma2x2_public.h @@ -8,6 +8,8 @@ #ifndef __CROS_EC_DRIVER_ACCEL_BMA2x2_PUBLIC_H #define __CROS_EC_DRIVER_ACCEL_BMA2x2_PUBLIC_H +#include "accelgyro.h" + extern const struct accelgyro_drv bma2x2_accel_drv; /* I2C ADDRESS DEFINITIONS */ diff --git a/include/driver/accelgyro_bmi160.h b/include/driver/accelgyro_bmi160.h index 76d24936c6..bd5637c2ba 100644 --- a/include/driver/accelgyro_bmi160.h +++ b/include/driver/accelgyro_bmi160.h @@ -389,7 +389,8 @@ int bmi160_sec_raw_read8(const int port, const uint16_t addr_flags, int bmi160_sec_raw_write8(const int port, const uint16_t addr_flags, const uint8_t reg, int data); -#if defined(CONFIG_ZEPHYR) && defined(CONFIG_ACCEL_INTERRUPTS) +#if defined(CONFIG_ZEPHYR) +#if DT_NODE_EXISTS(DT_ALIAS(bmi160_int)) /* Get the motion sensor ID of the BMI160 sensor that generates the interrupt. * The interrupt is converted to the event and transferred to motion sense task * that actually handles the interrupt. @@ -400,10 +401,9 @@ int bmi160_sec_raw_write8(const int port, const uint16_t addr_flags, * bmi160-int = &base_accel; * }; */ -#if DT_NODE_EXISTS(DT_ALIAS(bmi160_int)) #define CONFIG_ACCELGYRO_BMI160_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(bmi160_int))) #endif -#endif +#endif /* CONFIG_ZEPHYR */ #endif /* __CROS_EC_ACCELGYRO_BMI160_H */ diff --git a/include/driver/accelgyro_bmi260.h b/include/driver/accelgyro_bmi260.h index ae1c0f5777..fb5db82afb 100644 --- a/include/driver/accelgyro_bmi260.h +++ b/include/driver/accelgyro_bmi260.h @@ -328,7 +328,8 @@ /* Root mean square noise of 100Hz accelerometer, units: ug */ #define BMI260_ACCEL_RMS_NOISE_100HZ 1060 -#if defined(CONFIG_ZEPHYR) && defined(CONFIG_ACCEL_INTERRUPTS) +#if defined(CONFIG_ZEPHYR) +#if DT_NODE_EXISTS(DT_ALIAS(bmi260_int)) /* * Get the motion sensor ID of the BMI260 sensor that * generates the interrupt. @@ -342,10 +343,9 @@ * bmi260-int = &base_accel; * }; */ -#if DT_NODE_EXISTS(DT_ALIAS(bmi260_int)) #define CONFIG_ACCELGYRO_BMI260_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(bmi260_int))) #endif -#endif +#endif /* CONFIG_ZEPHYR */ #endif /* __CROS_EC_ACCELGYRO_BMI260_H */ diff --git a/include/driver/als_tcs3400.h b/include/driver/als_tcs3400.h index 0078b90442..0748befa71 100644 --- a/include/driver/als_tcs3400.h +++ b/include/driver/als_tcs3400.h @@ -119,4 +119,24 @@ enum crbg_index { CRGB_COUNT, }; +#if defined(CONFIG_ZEPHYR) +#if DT_NODE_EXISTS(DT_ALIAS(tcs3400_int)) +/* + * Get the mostion sensor ID of the TCS3400 sensor that + * generates the interrupt. + * The interrupt is converted to the event and transferred to motion + * sense task that actually handles the interrupt. + * + * Here, we use alias to get the motion sensor ID + * + * e.g) als_clear below is the label of a child node in /motionsense-sensors + * aliases { + * tcs3400-int = &als_clear; + * }; + */ +#define CONFIG_ALS_TCS3400_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(tcs3400_int))) +#endif +#endif /* CONFIG_ZEPHYR */ + #endif /* __CROS_EC_ALS_TCS3400_H */ diff --git a/include/driver/retimer/anx7483_public.h b/include/driver/retimer/anx7483_public.h index 3d856a3cae..f7654837db 100644 --- a/include/driver/retimer/anx7483_public.h +++ b/include/driver/retimer/anx7483_public.h @@ -18,5 +18,9 @@ #define ANX7483_I2C_ADDR2_FLAGS 0x40 #define ANX7483_I2C_ADDR3_FLAGS 0x44 +/* Configure datasheet defaults for tuning registers at this mux setting */ +enum ec_error_list anx7483_set_default_tuning(const struct usb_mux *me, + mux_state_t mux_state); + extern const struct usb_mux_driver anx7483_usb_retimer_driver; #endif /* __CROS_EC_USB_RETIMER_ANX7483_PUBLIC_H */ diff --git a/include/driver/retimer/bb_retimer.h b/include/driver/retimer/bb_retimer.h index 2bfb806e37..6a311bd2ca 100644 --- a/include/driver/retimer/bb_retimer.h +++ b/include/driver/retimer/bb_retimer.h @@ -17,7 +17,12 @@ #define BB_RETIMER_VENDOR_ID_2 0x8087 #define BB_RETIMER_REG_DEVICE_ID 1 +#ifdef CONFIG_USBC_RETIMER_INTEL_HB +/* HB has no Device ID field instead it is combined with Vendor ID */ +#define BB_RETIMER_DEVICE_ID 0x0D9C8087 +#else #define BB_RETIMER_DEVICE_ID 0x15EE +#endif /* Connection State Register Attributes */ #define BB_RETIMER_REG_CONNECTION_STATE 4 diff --git a/include/driver/tcpm/tcpci.h b/include/driver/tcpm/tcpci.h index 04016d0f06..559b75a14f 100644 --- a/include/driver/tcpm/tcpci.h +++ b/include/driver/tcpm/tcpci.h @@ -281,6 +281,20 @@ #define TCPC_REG_VBUS_VOLTAGE_SCALE_FACTOR GENMASK(11, 10) #define TCPC_REG_VBUS_VOLTAGE_LSB 25 +/* + * 00: the measurement is not scaled + * 01: the measurement is divided by 2 + * 10: the measurement is divided by 4 + * 11: reserved + */ +#define TCPC_REG_VBUS_VOLTAGE_SCALE(x) \ + (1 << (((x) & TCPC_REG_VBUS_VOLTAGE_SCALE_FACTOR) >> 9)) +#define TCPC_REG_VBUS_VOLTAGE_MEASURE(x) \ + ((x) & TCPC_REG_VBUS_VOLTAGE_MEASUREMENT) +#define TCPC_REG_VBUS_VOLTAGE_VBUS(x) \ + (TCPC_REG_VBUS_VOLTAGE_SCALE(x) * TCPC_REG_VBUS_VOLTAGE_MEASURE(x) * \ + TCPC_REG_VBUS_VOLTAGE_LSB) + #define TCPC_REG_VBUS_SINK_DISCONNECT_THRESH 0x72 #define TCPC_REG_VBUS_SINK_DISCONNECT_THRESH_DEFAULT 0x008C /* 3.5 V */ @@ -337,12 +351,10 @@ int tcpci_tcpm_mux_enter_low_power(const struct usb_mux *me); int tcpci_get_chip_info(int port, int live, struct ec_response_pd_chip_info_v1 *chip_info); int tcpci_get_vbus_voltage(int port, int *vbus); -#ifdef CONFIG_USB_PD_PPC bool tcpci_tcpm_get_snk_ctrl(int port); int tcpci_tcpm_set_snk_ctrl(int port, int enable); bool tcpci_tcpm_get_src_ctrl(int port); int tcpci_tcpm_set_src_ctrl(int port, int enable); -#endif int tcpci_tcpc_fast_role_swap_enable(int port, int enable); diff --git a/include/driver/tcpm/tcpm.h b/include/driver/tcpm/tcpm.h index c0a08df300..ef47a3b1e2 100644 --- a/include/driver/tcpm/tcpm.h +++ b/include/driver/tcpm/tcpm.h @@ -278,7 +278,6 @@ static inline int tcpm_transmit(int port, enum tcpci_msg_type type, return tcpc_config[port].drv->transmit(port, type, header, data); } -#ifdef CONFIG_USB_PD_PPC static inline bool tcpm_get_snk_ctrl(int port) { return tcpc_config[port].drv->get_snk_ctrl ? @@ -305,7 +304,6 @@ static inline int tcpm_set_src_ctrl(int port, int enable) else return EC_ERROR_UNIMPLEMENTED; } -#endif static inline void tcpc_alert(int port) { @@ -434,6 +432,23 @@ static inline int tcpm_set_frs_enable(int port, int enable) } #endif /* defined(CONFIG_USB_PD_FRS) */ +#ifdef CONFIG_USB_PD_TCPM_SBU +/** + * Turn on/off the SBU FETs + * + * @param port Type-C port number + * @param enable true:enable, false:disable + * + * @return EC_SUCCESS or error + */ +static inline int tcpc_set_sbu(int port, bool enable) +{ + return tcpc_config[port].drv->set_sbu ? + tcpc_config[port].drv->set_sbu(port, enable) : + EC_SUCCESS; +} +#endif /* CONFIG_USB_PD_TCPM_SBU */ + #else /* CONFIG_USB_PD_TCPC */ /** @@ -566,7 +581,6 @@ int tcpm_transmit(int port, enum tcpci_msg_type type, uint16_t header, * @param port Type-C port number */ void tcpc_alert(int port); - #endif /* CONFIG_USB_PD_TCPC */ /** diff --git a/include/ec_commands.h b/include/ec_commands.h index 1aff487bbe..3755acce19 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -106,10 +106,14 @@ extern "C" { /* * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff * and they tell the kernel that so we have to think of it as two parts. + * + * Other BIOSes report only the I/O port region spanned by the Microchip + * MEC series EC; an attempt to address a larger region may fail. */ -#define EC_HOST_CMD_REGION0 0x800 -#define EC_HOST_CMD_REGION1 0x880 -#define EC_HOST_CMD_REGION_SIZE 0x80 +#define EC_HOST_CMD_REGION0 0x800 +#define EC_HOST_CMD_REGION1 0x880 +#define EC_HOST_CMD_REGION_SIZE 0x80 +#define EC_HOST_CMD_MEC_REGION_SIZE 0x8 /* EC command register bit functions */ #define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */ @@ -825,11 +829,15 @@ struct ec_lpc_host_args { #define EC_SPI_PAST_END 0xed /* - * EC is ready to receive, and has ignored the byte sent by the AP. EC expects + * EC is ready to receive, and has ignored the byte sent by the AP. EC expects * that the AP will send a valid packet header (starting with * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. + * + * NOTE: Some SPI configurations place the Most Significant Bit on SDO when + * CS goes low. This macro has the Most Significant Bit set to zero, + * so SDO will not be driven high when CS goes low. */ -#define EC_SPI_RX_READY 0xf8 +#define EC_SPI_RX_READY 0x78 /* * EC has started receiving the request from the AP, but hasn't started @@ -4716,6 +4724,39 @@ struct ec_params_dedicated_charger_limit { uint16_t voltage_lim; /* in mV */ } __ec_align2; +/* + * Get and set charging splashscreen variables + */ +#define EC_CMD_CHARGESPLASH 0x00A4 + +enum ec_chargesplash_cmd { + /* Get the current state variables */ + EC_CHARGESPLASH_GET_STATE = 0, + + /* Indicate initialization of the display loop */ + EC_CHARGESPLASH_DISPLAY_READY, + + /* Manually put the EC into the requested state */ + EC_CHARGESPLASH_REQUEST, + + /* Reset all state variables */ + EC_CHARGESPLASH_RESET, + + /* Manually trigger a lockout */ + EC_CHARGESPLASH_LOCKOUT, +}; + +struct __ec_align1 ec_params_chargesplash { + /* enum ec_chargesplash_cmd */ + uint8_t cmd; +}; + +struct __ec_align1 ec_response_chargesplash { + uint8_t requested; + uint8_t display_initialized; + uint8_t locked_out; +}; + /*****************************************************************************/ /* Hibernate/Deep Sleep Commands */ @@ -6646,6 +6687,7 @@ enum typec_control_command { TYPEC_CONTROL_COMMAND_CLEAR_EVENTS, TYPEC_CONTROL_COMMAND_ENTER_MODE, TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY, + TYPEC_CONTROL_COMMAND_USB_MUX_SET, }; /* Modes (USB or alternate) that a type-C port may enter. */ @@ -6661,6 +6703,11 @@ enum typec_tbt_ufp_reply { TYPEC_TBT_UFP_REPLY_ACK, }; +struct typec_usb_mux_set { + uint8_t mux_index; /* Index of the mux to set in the chain */ + uint8_t mux_flags; /* USB_PD_MUX_*-encoded USB mux state to set */ +} __ec_align1; + struct ec_params_typec_control { uint8_t port; uint8_t command; /* enum typec_control_command */ @@ -6678,6 +6725,8 @@ struct ec_params_typec_control { uint8_t mode_to_enter; /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */ uint8_t tbt_ufp_reply; + /* Used for USB_MUX_SET */ + struct typec_usb_mux_set mux_params; uint8_t placeholder[128]; }; } __ec_align1; @@ -6765,6 +6814,8 @@ enum tcpc_cc_polarity { #define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1) #define PD_STATUS_EVENT_HARD_RESET BIT(2) #define PD_STATUS_EVENT_DISCONNECTED BIT(3) +#define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4) +#define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5) /* * Encode and decode for BCD revision response @@ -7186,22 +7237,28 @@ struct ec_params_fp_passthru { /* Capture types defined in bits [30..28] */ #define FP_MODE_CAPTURE_TYPE_SHIFT 28 #define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT) -/* - * This enum must remain ordered, if you add new values you must ensure that - * FP_CAPTURE_TYPE_MAX is still the last one. +/** + * enum fp_capture_type - Specifies the "mode" when capturing images. + * + * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality + * image (produces 'frame_size' bytes) + * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x + * bpp bits) + * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard) + * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard) + * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast + * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test + * @FP_CAPTURE_TYPE_MAX: End of enum + * + * @note This enum must remain ordered, if you add new values you must ensure + * that FP_CAPTURE_TYPE_MAX is still the last one. */ enum fp_capture_type { - /* Full blown vendor-defined capture (produces 'frame_size' bytes) */ FP_CAPTURE_VENDOR_FORMAT = 0, - /* Simple raw image capture (produces width x height x bpp bits) */ FP_CAPTURE_SIMPLE_IMAGE = 1, - /* Self test pattern (e.g. checkerboard) */ FP_CAPTURE_PATTERN0 = 2, - /* Self test pattern (e.g. inverted checkerboard) */ FP_CAPTURE_PATTERN1 = 3, - /* Capture for Quality test with fixed contrast */ FP_CAPTURE_QUALITY_TEST = 4, - /* Capture for pixel reset value test */ FP_CAPTURE_RESET_TEST = 5, FP_CAPTURE_TYPE_MAX, }; diff --git a/include/espi.h b/include/espi.h index d1b8af3425..a717e7e414 100644 --- a/include/espi.h +++ b/include/espi.h @@ -93,5 +93,12 @@ const char *espi_vw_get_wire_name(enum espi_vw_signal signal); */ int espi_signal_is_vw(int signal); +/** + * Wait for the specified VW's DIRTY bit to be cleared. + * @param signal VW to poll DIRTY bit for + * @param timeout max time in microseconds to poll. + */ +void espi_wait_vw_not_dirty(enum espi_vw_signal signal, + unsigned int timeout_us); #endif /* __CROS_EC_ESPI_H */ diff --git a/include/fan.h b/include/fan.h index bd92b97254..87c8f4b7a6 100644 --- a/include/fan.h +++ b/include/fan.h @@ -11,16 +11,16 @@ #ifdef CONFIG_ZEPHYR #ifdef CONFIG_PLATFORM_EC_FAN -#include <devicetree.h> +#include <zephyr/devicetree.h> #define NODE_ID_AND_COMMA(node_id) node_id, enum fan_channel { -#if DT_NODE_EXISTS(DT_INST(0, named_fans)) - DT_FOREACH_CHILD(DT_INST(0, named_fans), NODE_ID_AND_COMMA) -#endif /* named_fans */ +#if DT_NODE_EXISTS(DT_INST(0, cros_ec_fans)) + DT_FOREACH_CHILD(DT_INST(0, cros_ec_fans), NODE_ID_AND_COMMA) +#endif /* cros_ec_fans */ FAN_CH_COUNT }; -#define CONFIG_FANS FAN_CH_COUNT +BUILD_ASSERT(FAN_CH_COUNT == CONFIG_PLATFORM_EC_NUM_FANS); #endif /* CONFIG_PLATFORM_EC_FAN */ #endif /* CONFIG_ZEPHYR */ diff --git a/include/fpsensor.h b/include/fpsensor.h index 2c5baa2679..8efc4a7006 100644 --- a/include/fpsensor.h +++ b/include/fpsensor.h @@ -25,21 +25,36 @@ /* --- functions provided by the sensor-specific driver --- */ -/* Initialize the connected sensor hardware and put it in a low power mode. */ +/** + * Initialize the connected sensor hardware and put it in a low power mode. + * + * @return EC_SUCCESS always + */ int fp_sensor_init(void); -/* De-initialize the sensor hardware. */ +/** + * De-initialize the sensor hardware. + * + * @return 0 on success + * @return negative value on error + */ int fp_sensor_deinit(void); -/* - * Fill the 'ec_response_fp_info' buffer with the sensor information +/** + * Fill the @p ec_response_fp_info buffer with the sensor information * as required by the EC_CMD_FP_INFO host command. * - * Put both the static information and the ones read from the sensor at runtime. + * Fills both the static information and information read from the sensor at + * runtime. + * + * @param[out] resp sensor info + * + * @return EC_SUCCESS on success + * @return EC_RES_ERROR on error */ int fp_sensor_get_info(struct ec_response_fp_info *resp); -/* +/** * Put the sensor in its lowest power state. * * fp_sensor_configure_detect needs to be called to restore finger detection @@ -47,7 +62,7 @@ int fp_sensor_get_info(struct ec_response_fp_info *resp); */ void fp_sensor_low_power(void); -/* +/** * Configure finger detection. * * Send the settings to the sensor, so it is properly configured to detect @@ -55,102 +70,130 @@ void fp_sensor_low_power(void); */ void fp_sensor_configure_detect(void); -/* - * Returns the status of the finger on the sensor. - * (assumes fp_sensor_configure_detect was called before) - */ enum finger_state { FINGER_NONE = 0, FINGER_PARTIAL = 1, FINGER_PRESENT = 2, }; + +/** + * Returns the status of the finger on the sensor. + * (assumes fp_sensor_configure_detect was called before) + * + * @return finger_state + */ enum finger_state fp_sensor_finger_status(void); -/* +/** + * Image captured but quality is too low + */ +#define FP_SENSOR_LOW_IMAGE_QUALITY 1 +/** + * Finger removed before image was captured + */ +#define FP_SENSOR_TOO_FAST 2 + +/** + * Sensor not fully covered by finger + */ +#define FP_SENSOR_LOW_SENSOR_COVERAGE 3 + +/** * Acquires a fingerprint image. * * This function is called once the finger has been detected and cover enough - * area of the sensor (ie fp_sensor_finger_status returned FINGER_PRESENT). + * area of the sensor (i.e., fp_sensor_finger_status returned FINGER_PRESENT). * It does the acquisition immediately. - * The image_data parameter points to an image data buffer of size * - * FP_SENSOR_IMAGE_SIZE allocated by the caller. - * Returns: - * - 0 on success - * - negative value on error - * - FP_SENSOR_LOW_IMAGE_QUALITY on image captured but quality is too low - * - FP_SENSOR_TOO_FAST on finger removed before image was captured - * - FP_SENSOR_LOW_SENSOR_COVERAGE on sensor not fully covered by finger + * @param[out] image_data Image from sensor. Buffer must be allocated by + * caller with size FP_SENSOR_IMAGE_SIZE. + * + * @return 0 on success + * @return negative value on error + * @return FP_SENSOR_LOW_IMAGE_QUALITY on image captured but quality is too low + * @return FP_SENSOR_TOO_FAST on finger removed before image was captured + * @return FP_SENSOR_LOW_SENSOR_COVERAGE on sensor not fully covered by finger */ -#define FP_SENSOR_LOW_IMAGE_QUALITY 1 -#define FP_SENSOR_TOO_FAST 2 -#define FP_SENSOR_LOW_SENSOR_COVERAGE 3 int fp_sensor_acquire_image(uint8_t *image_data); -/* +/** * Acquires a fingerprint image with specific capture mode. * - * Same as the fp_sensor_acquire_image function above, - * excepted 'mode' can be set to one of the FP_CAPTURE_ constants + * Same as the fp_sensor_acquire_image function(), + * except @p mode can be set to one of the fp_capture_type constants * to get a specific image type (e.g. a pattern) rather than the default one. + * + * @param[out] image_data Image from sensor. Buffer must be allocated by + * caller with size FP_SENSOR_IMAGE_SIZE. + * @param mode enum fp_capture_type + * + * @return 0 on success + * @return negative value on error */ int fp_sensor_acquire_image_with_mode(uint8_t *image_data, int mode); -/* +/** * Compares given finger image against enrolled templates. * * The matching algorithm can update the template with additional biometric data * from the image, if it chooses to do so. * - * @param templ a pointer to the array of template buffers. + * @param[in,out] templ a pointer to the array of template buffers. * @param templ_count the number of buffers in the array of templates. - * @param image the buffer containing the finger image + * @param[in] image the buffer containing the finger image * @param match_index index of the matched finger in the template array if any. - * @param update_bitmap contains one bit per template, the bit is set if the - * match has updated the given template. - * @return negative value on error, else one of the following code : - * - EC_MKBP_FP_ERR_MATCH_NO on non-match - * - EC_MKBP_FP_ERR_MATCH_YES for match when template was not updated with - * new data - * - EC_MKBP_FP_ERR_MATCH_YES_UPDATED for match when template was updated - * - EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED match, but update failed (not saved) - * - EC_MKBP_FP_ERR_MATCH_LOW_QUALITY when matching could not be performed due - * to low image quality - * - EC_MKBP_FP_ERR_MATCH_LOW_COVERAGE when matching could not be performed - * due to finger covering too little area of the sensor + * @param[out] update_bitmap contains one bit per template, the bit is set if + * the match has updated the given template. + * + * @return EC_MKBP_FP_ERR_MATCH_NO on non-match + * @return EC_MKBP_FP_ERR_MATCH_YES for match when template was not updated with + * new data + * @return EC_MKBP_FP_ERR_MATCH_YES_UPDATED for match when template was updated + * @return EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED match, but update failed (not + * saved) + * @return EC_MKBP_FP_ERR_MATCH_LOW_QUALITY when matching could not be performed + * due to low image quality + * @return EC_MKBP_FP_ERR_MATCH_LOW_COVERAGE when matching could not be + * performed due to finger covering too little area of the sensor + * @return negative value on error */ int fp_finger_match(void *templ, uint32_t templ_count, uint8_t *image, int32_t *match_index, uint32_t *update_bitmap); -/* +/** * Start a finger enrollment session. * - * @return 0 on success or a negative error code. + * @return 0 on success + * @return negative value on error */ int fp_enrollment_begin(void); -/* +/** * Generate a template from the finger whose enrollment has just being * completed. * - * @param templ the buffer which will receive the template. - * templ can be set to NULL to abort the current enrollment process. + * @param[out] templ template buffer, which can be set to NULL to abort current + * enrollment process. * - * @return 0 on success or a negative error code. + * @return 0 on success, negative value on error */ int fp_enrollment_finish(void *templ); -/* +/** * Adds fingerprint image to the current enrollment session. * - * @return a negative value on error or one of the following codes: - * - EC_MKBP_FP_ERR_ENROLL_OK when image was successfully enrolled - * - EC_MKBP_FP_ERR_ENROLL_IMMOBILE when image added, but user should be - * advised to move finger - * - EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY when image could not be used due to low - * image quality - * - EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE when image could not be used due to - * finger covering too little area of the sensor + * @param[in] image Image to add to enrollment + * @param[out] completion The percentage of the enrollment process that is + * complete: [0-100]. + * + * @return 0 on success + * @return EC_MKBP_FP_ERR_ENROLL_OK when image was successfully enrolled + * @return EC_MKBP_FP_ERR_ENROLL_IMMOBILE when image added, but user should be + * advised to move finger + * @return EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY when image could not be used due to + * low image quality + * @return EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE when image could not be used + * due to finger covering too little area of the sensor */ int fp_finger_enroll(uint8_t *image, int *completion); diff --git a/include/gpio.h b/include/gpio.h index c6ff3e049f..4d827eb3cc 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -20,7 +20,7 @@ * conflicts */ #ifdef CONFIG_ZEPHYR -#include <drivers/gpio.h> +#include <zephyr/drivers/gpio.h> /* * Some flag definitions are duplicated by our private devicetree binding @@ -377,6 +377,20 @@ int gpio_or_ioex_get_level(int signal, int *value); */ void gpio_reset(enum gpio_signal signal); +#ifdef CONFIG_ZEPHYR + +/** + * @brief Reset all the GPIOs to default state + * + * This returns all pins from selected port to default state. The default flags + * are specified by the "named-gpios" node in the board devicetree. + * + * @param port Port to reset + */ +void gpio_reset_port(const struct device *port); + +#endif /* CONFIG_ZEPHYR */ + /** * Enable interrupts for the signal. * diff --git a/include/i2c.h b/include/i2c.h index 86c6e24e85..c799b9599d 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -442,6 +442,17 @@ int i2c_is_busy(int port); int i2c_unwedge(int port); /** + * Read read using smbus read block protocol. + * Read bytestream from <addr_flags>:<offset> with format: + * [length_N] [byte_0] [byte_1] ... [byte_N] + * + * <len> : the max length of receiving buffer + */ +int i2c_read_sized_block(const int port, + const uint16_t addr_flags, + int offset, uint8_t *data, int max_len, int *read_len); + +/** * Read ascii string using smbus read block protocol. * Read bytestream from <addr_flags>:<offset> with format: * [length_N] [byte_0] [byte_1] ... [byte_N-1] @@ -450,7 +461,6 @@ int i2c_unwedge(int port); * ascii, len should be at least N+1 to include the * terminating 0. Similar to strlcpy, the terminating null is * always written into the output buffer. - * <len> == 0 : buffer size > 255 */ int i2c_read_string(const int port, const uint16_t addr_flags, diff --git a/include/ioexpander.h b/include/ioexpander.h index c3023a2236..21d7034303 100644 --- a/include/ioexpander.h +++ b/include/ioexpander.h @@ -124,11 +124,6 @@ inline const char *ioex_get_name(enum ioex_signal signal) return gpio_get_name(signal); } -inline int signal_is_ioex(int signal) -{ - return 0; -} - #else /* diff --git a/include/keyboard_8042_sharedlib.h b/include/keyboard_8042_sharedlib.h index 6c2e37fbf4..e4a2e9a77f 100644 --- a/include/keyboard_8042_sharedlib.h +++ b/include/keyboard_8042_sharedlib.h @@ -8,6 +8,8 @@ #ifndef __CROS_EC_KEYBOARD_8042_SHAREDLIB_H #define __CROS_EC_KEYBOARD_8042_SHAREDLIB_H +#include <stddef.h> + #include "button.h" #include "keyboard_config.h" #include "keyboard_protocol.h" @@ -18,6 +20,14 @@ struct button_8042_t { }; /** + * Register scancode set for the standard ChromeOS keyboard matrix set 2. + * + * @param scancode_set Scancode set to register. + * @param size Size of the scancode set in bytes. + */ +void register_scancode_set2(uint16_t *scancode_set, size_t size); + +/** * Get the standard Chrome OS keyboard matrix set 2 scanset * @param row Row number * @param col Column number diff --git a/include/keyboard_backlight.h b/include/keyboard_backlight.h index 96bf69aaae..194bec66f4 100644 --- a/include/keyboard_backlight.h +++ b/include/keyboard_backlight.h @@ -54,7 +54,12 @@ struct kblight_drv { /** * Initialize keyboard backlight per board */ -void board_kblight_init(void); +__override_proto void board_kblight_init(void); + +/** + * Shutdown keyboard backlight + */ +__override_proto void board_kblight_shutdown(void); /** * Set keyboard backlight brightness diff --git a/include/keyboard_mkbp.h b/include/keyboard_mkbp.h index 3d153d63b5..03e84550a7 100644 --- a/include/keyboard_mkbp.h +++ b/include/keyboard_mkbp.h @@ -18,13 +18,4 @@ */ int mkbp_keyboard_add(const uint8_t *buffp); -/** - * Send KEY_BATTERY keystroke. - */ -#ifdef CONFIG_KEYBOARD_PROTOCOL_MKBP -void keyboard_send_battery_key(void); -#else -static inline void keyboard_send_battery_key(void) { } -#endif - #endif /* __CROS_EC_KEYBOARD_MKBP_H */ diff --git a/include/led_pwm.h b/include/led_pwm.h index 7f286130e7..26a44913b8 100644 --- a/include/led_pwm.h +++ b/include/led_pwm.h @@ -9,7 +9,7 @@ #include "ec_commands.h" #ifdef CONFIG_ZEPHYR -#include "drivers/pwm.h" +#include <zephyr/drivers/pwm.h> #endif #ifdef CONFIG_ZEPHYR @@ -20,7 +20,7 @@ struct pwm_led_dt_channel { const struct device *dev; uint32_t channel; pwm_flags_t flags; - uint32_t period_us; + uint32_t period_ns; }; struct pwm_led { diff --git a/include/lid_switch.h b/include/lid_switch.h index 627a41d62c..93d093a21f 100644 --- a/include/lid_switch.h +++ b/include/lid_switch.h @@ -12,6 +12,11 @@ #include "stdbool.h" /** + * Debounce time for lid switch + */ +#define LID_DEBOUNCE_US (30 * MSEC) + +/** * Return non-zero if lid is open. * * Uses the debounced lid state, not the raw signal from the GPIO. diff --git a/include/motion_sense.h b/include/motion_sense.h index 50752ea175..1f2e912ce5 100644 --- a/include/motion_sense.h +++ b/include/motion_sense.h @@ -290,6 +290,14 @@ int sensor_init_done(struct motion_sensor_t *sensor); */ void sensor_board_proc_double_tap(void); +/** + * Commit the data in a sensor's raw_xyz vector. This operation might have + * different meanings depending on the CONFIG_ACCEL_FIFO flag. + * + * @param s Pointer to the sensor. + */ +void motion_sense_push_raw_xyz(struct motion_sensor_t *s); + /* * There are 4 variables that represent the number of sensors: * SENSOR_COUNT: The number of available motion sensors in board. diff --git a/include/panic.h b/include/panic.h index 72a397cb7f..6e4f17fcb9 100644 --- a/include/panic.h +++ b/include/panic.h @@ -73,7 +73,7 @@ struct nds32_n8_panic_data { /* RISC-V RV32I registers saved on panic */ struct rv32i_panic_data { - uint32_t regs[31]; /* sp, ra, gp, tp, a0-a7, t0-t6 s0-s11 */ + uint32_t regs[31]; /* sp, ra, gp, tp, a0-a7, t0-t6, s0-s11 */ uint32_t mepc; /* mepc */ uint32_t mcause; /* mcause */ }; diff --git a/include/peripheral_charger.h b/include/peripheral_charger.h index 09f6fd1ea6..0479b5e7bd 100644 --- a/include/peripheral_charger.h +++ b/include/peripheral_charger.h @@ -260,4 +260,12 @@ void pchg_irq(enum gpio_signal signal); */ void pchg_task(void *u); +/** + * Turn on/off power for a PCHG charger. + * + * @param port Port number of the PCHG charger. + * @param on + */ +__override_proto void board_pchg_power_on(int port, bool on); + #endif /* __CROS_EC_PERIPHERAL_CHARGER_H */ diff --git a/include/rgb_keyboard.h b/include/rgb_keyboard.h index 2c6a550e7b..58dc3c30f6 100644 --- a/include/rgb_keyboard.h +++ b/include/rgb_keyboard.h @@ -13,6 +13,7 @@ #define SIZE_OF_RGB sizeof(struct rgb_s) #define RGBKBD_MAX_GCC_LEVEL 0xff +#define RGBKBD_MAX_SCALE 0xff enum rgbkbd_demo { RGBKBD_DEMO_OFF = 0, @@ -34,13 +35,24 @@ struct rgbkbd_cfg { const uint8_t row_len; }; +struct rgbkbd_init { + /* Global current control */ + const uint8_t gcc; + /* LED brightness */ + const uint8_t scale; + /* Color */ + const struct rgb_s color; +}; + +extern const struct rgbkbd_init rgbkbd_default; + struct rgbkbd { /* Static configuration */ const struct rgbkbd_cfg * const cfg; + /* Start-up settings */ + const struct rgbkbd_init * const init; /* Current state of the port */ enum rgbkbd_state state; - /* Global current control (a.k.a. backlight brightness) */ - uint8_t gcc; /* Buffer containing color info for each dot. */ struct rgb_s *buf; }; @@ -142,11 +154,6 @@ extern const uint8_t rgbkbd_hsize; extern const uint8_t rgbkbd_vsize; /* - * Called to power on or off the RGB keyboard module. - */ -__override_proto void board_enable_rgb_keyboard(bool enable); - -/* * rgbkbd_map describes a mapping from key IDs to LED IDs. * * Multiple keys can be mapped to one LED and one key can be mapped to multiple @@ -178,15 +185,6 @@ __override_proto void board_enable_rgb_keyboard(bool enable); extern const uint8_t rgbkbd_map[]; extern const size_t rgbkbd_map_size; -/** - * Set/get global brightness of the RGB keyboard. - * - * @param gcc Brightness level 0 ~ RGBKBD_MAX_GCC_LEVEL. - * @return enum ec_error_list; - */ -int rgbkbd_set_global_brightness(uint8_t gcc); -int rgbkbd_get_global_brightness(uint8_t *gcc); - /* * Driver for keyboard_backlight. */ diff --git a/include/task.h b/include/task.h index 4e0ff04697..0343644437 100644 --- a/include/task.h +++ b/include/task.h @@ -149,9 +149,8 @@ void set_int_mask(uint32_t val); * * @param tskid Task to set event for * @param event Event bitmap to set (TASK_EVENT_*) - * @return The bitmap of events which occurred if wait!=0, else 0. */ -uint32_t task_set_event(task_id_t tskid, uint32_t event); +void task_set_event(task_id_t tskid, uint32_t event); /** * Wake a task. This sends it the TASK_EVENT_WAKE event. diff --git a/include/throttle_ap.h b/include/throttle_ap.h index fbfa36aed3..09669d70b1 100644 --- a/include/throttle_ap.h +++ b/include/throttle_ap.h @@ -35,6 +35,19 @@ enum throttle_sources { }; /** + * PROCHOT detection GPIOs. PROCHOT in assumed to be active high unless + * CONFIG_CPU_PROCHOT_ACTIVE_LOW is enabled. + * C10 input polarity is explicitly specified in the struct below. + */ +struct prochot_cfg { + enum gpio_signal gpio_prochot_in; +#ifdef CONFIG_CPU_PROCHOT_GATE_ON_C10 + enum gpio_signal gpio_c10_in; + bool c10_active_high; +#endif +}; + +/** * Enable/disable CPU throttling. * * This is a virtual "OR" operation. Any caller can enable CPU throttling of @@ -53,6 +66,14 @@ void throttle_ap(enum throttle_level level, enum throttle_sources source); /** + * Configure the GPIOs used to monitor the PROCHOT signal. + * + * @param cfg GPIO configuration for the PROCHOT and optional C10 + * signals. + */ +void throttle_ap_config_prochot(const struct prochot_cfg *cfg); + +/** * Interrupt handler to monitor PROCHOT input to the EC. The PROCHOT signal * can be asserted by the AP or by other devices on the board, such as chargers * and voltage regulators. @@ -65,6 +86,18 @@ void throttle_ap(enum throttle_level level, */ void throttle_ap_prochot_input_interrupt(enum gpio_signal signal); +/** + * Interrupt handler to monitor the C10 input to the EC. The C10 signal + * can be asserted by the AP when entering an idle state. This interrupt + * is configured for the edge indicating C10 is de-asserting (GPIO_INT_RISING + * if the signal is active low, GPIO_INT_FALLING for an active high signal). + * + * The board initialization is responsible for enabling the interrupt. + * + * @param signal GPIO signal connected to C10 input. + */ +void throttle_ap_c10_input_interrupt(enum gpio_signal signal); + #else static inline void throttle_ap(enum throttle_level level, enum throttle_type type, diff --git a/include/typec_control.h b/include/typec_control.h new file mode 100644 index 0000000000..b162467663 --- /dev/null +++ b/include/typec_control.h @@ -0,0 +1,46 @@ +/* Copyright 2022 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* Type-C control logic header */ + +#ifndef __CROS_EC_TYPEC_CONTROL_H +#define __CROS_EC_TYPEC_CONTROL_H + +#include "usb_pd_tcpm.h" + +/** + * Sets the polarity of the port + * + * @param port USB-C port number + * @param polarity Polarity of CC lines + */ +void typec_set_polarity(int port, enum tcpc_cc_polarity polarity); + +/** + * Turn on/off the SBU FETs. + * + * @param port USB-C port number + * @param enable true:enable, false:disable + */ +void typec_set_sbu(int port, bool enable); + +/** + * Set the type-C current limit when sourcing current + * + * @param port USB-C port number + * @param rp Pull-up values to be aplied as a SRC to advertise current limits + */ +__override_proto void typec_set_source_current_limit(int port, + enum tcpc_rp_value rp); + +/** + * Turn on/off the VCONN FET + * + * @param port USB-C port number + * @param enable true:enable, false:disable + */ +void typec_set_vconn(int port, bool enable); + +#endif /* __CROS_EC_TYPEC_CONTROL_H */ diff --git a/include/usb_charge.h b/include/usb_charge.h index 0dc009721e..135258c7cf 100644 --- a/include/usb_charge.h +++ b/include/usb_charge.h @@ -55,27 +55,26 @@ extern const int usb_port_enable[USB_PORT_ENABLE_COUNT]; int usb_charge_set_mode(int usb_port_id, enum usb_charge_mode mode, enum usb_suspend_charge inhibit_charge); -#define USB_CHG_EVENT_BC12 TASK_EVENT_CUSTOM_BIT(0) -#define USB_CHG_EVENT_VBUS TASK_EVENT_CUSTOM_BIT(1) -#define USB_CHG_EVENT_INTR TASK_EVENT_CUSTOM_BIT(2) -#define USB_CHG_EVENT_DR_UFP TASK_EVENT_CUSTOM_BIT(3) -#define USB_CHG_EVENT_DR_DFP TASK_EVENT_CUSTOM_BIT(4) -#define USB_CHG_EVENT_CC_OPEN TASK_EVENT_CUSTOM_BIT(5) -#define USB_CHG_EVENT_MUX TASK_EVENT_CUSTOM_BIT(6) - -/* Number of USB_CHG_* tasks */ -#ifdef HAS_TASK_USB_CHG_P2 -#define USB_CHG_TASK_COUNT 3 -#elif defined(HAS_TASK_USB_CHG_P1) -#define USB_CHG_TASK_COUNT 2 -#elif defined(HAS_TASK_USB_CHG_P0) || defined(HAS_TASK_USB_CHG) -#define USB_CHG_TASK_COUNT 1 +#ifdef CONFIG_PLATFORM_EC_USB_CHARGER_SINGLE_TASK +/* + * In single task mode we pack the event bits for up to 4 ports in a 32 bit + * atomic, make sure we don't define more than 8 event bits per port. + */ +#define USB_CHARGER_EVENT_BIT(x) BUILD_CHECK_INLINE(BIT(x), BIT(x) & 0xff) #else -#define USB_CHG_TASK_COUNT 0 +#define USB_CHARGER_EVENT_BIT(x) TASK_EVENT_CUSTOM_BIT(x) #endif +#define USB_CHG_EVENT_BC12 USB_CHARGER_EVENT_BIT(0) +#define USB_CHG_EVENT_VBUS USB_CHARGER_EVENT_BIT(1) +#define USB_CHG_EVENT_INTR USB_CHARGER_EVENT_BIT(2) +#define USB_CHG_EVENT_DR_UFP USB_CHARGER_EVENT_BIT(3) +#define USB_CHG_EVENT_DR_DFP USB_CHARGER_EVENT_BIT(4) +#define USB_CHG_EVENT_CC_OPEN USB_CHARGER_EVENT_BIT(5) +#define USB_CHG_EVENT_MUX USB_CHARGER_EVENT_BIT(6) + /* - * Define USB_CHG_PORT_TO_TASK_ID() and TASK_ID_TO_USB_CHG__PORT() macros to + * Define USB_CHG_PORT_TO_TASK_ID() and TASK_ID_TO_USB_CHG_PORT() macros to * go between USB_CHG port number and task ID. Assume that TASK_ID_USB_CHG_P0, * is the lowest task ID and IDs are on a continuous range. */ @@ -104,8 +103,10 @@ enum usb_switch { struct bc12_drv { /* All fields below are optional */ - /* BC1.2 detection task for this chip */ - void (*usb_charger_task)(int port); + /* BC1.2 detection task init for this chip */ + void (*usb_charger_task_init)(int port); + /* BC1.2 detection task process for this chip */ + void (*usb_charger_task_event)(int port, uint32_t evt); /* Configure USB data switches on type-C port */ void (*set_switches)(int port, enum usb_switch setting); /* Check if ramping is allowed for given supplier */ @@ -150,7 +151,7 @@ void usb_charger_vbus_change(int port, int vbus_level); * Check if ramping is allowed for given supplier * * @param port port number. - * @supplier Supplier to check + * @param supplier Supplier to check * * @return Ramping is allowed for given supplier */ @@ -165,8 +166,8 @@ static inline int usb_charger_ramp_allowed(int port, int supplier) * Get the maximum current limit that we are allowed to ramp to * * @param port port number. - * @supplier Active supplier type - * @sup_curr Input current limit based on supplier + * @param supplier Active supplier type + * @param sup_curr Input current limit based on supplier * * @return Maximum current in mA */ @@ -178,7 +179,16 @@ static inline int usb_charger_ramp_max(int port, int supplier, int sup_curr) } /** + * Set a task event for a specific usb charger port + * + * @param port port number + * @param event event bits (USB_CHG_EVENT_*) + */ +void usb_charger_task_set_event(int port, uint8_t event); + +/** * Reset available BC 1.2 chargers on all ports + * * @param port */ void usb_charger_reset_charge(int port); diff --git a/include/usb_common.h b/include/usb_common.h index 5fc215798f..bd779780ee 100644 --- a/include/usb_common.h +++ b/include/usb_common.h @@ -226,14 +226,28 @@ int pd_get_saved_port_flags(int port, uint8_t *flags); void pd_update_saved_port_flags(int port, uint8_t flag, uint8_t do_set); /** - * Build PD alert message + * Sets up and sends PD alert message with given ADO on all ports. * - * @param msg pointer where message is stored - * @param len pointer where length of message is stored in bytes - * @param pr current PD power role + * @param ado - Alert Data Object defining alert sent to the PD partner * @return EC_SUCCESS on success else EC_ERROR_INVAL */ -int pd_build_alert_msg(uint32_t *msg, uint32_t *len, enum pd_power_role pr); +int pd_broadcast_alert_msg(uint32_t ado); + +/** + * Sets up and sends PD alert message with given ADO on one port. + * + * @param port - the port to send the alert message on + * @param ado - Alert Data Object defining alert sent to the PD partner + * @return EC_SUCCESS on success else EC_ERROR_INVAL + */ +int pd_send_alert_msg(int port, uint32_t ado); + +/** + * Sets up a hard reset to send on the port + * + * @param port - the port to send the hard reset on + */ +void pd_send_hard_reset(int port); /** * During USB retimer firmware update, process operation diff --git a/include/usb_mux.h b/include/usb_mux.h index e251d74f4c..0d43257994 100644 --- a/include/usb_mux.h +++ b/include/usb_mux.h @@ -14,11 +14,23 @@ #include "usb_charge.h" #include "usb_pd.h" +/* + * If compiling with Zephyr, include the USB_MUX_FLAG_ definitions that are + * shared with device tree + */ +#ifdef CONFIG_ZEPHYR + +#include "dt-bindings/usbc_mux.h" + +#else /* !CONFIG_ZEPHYR */ + /* Flags used for usb_mux.flags */ #define USB_MUX_FLAG_NOT_TCPC BIT(0) /* TCPC/MUX device used only as MUX */ #define USB_MUX_FLAG_SET_WITHOUT_FLIP BIT(1) /* SET should not flip */ #define USB_MUX_FLAG_RESETS_IN_G3 BIT(2) /* Mux chip will reset in G3 */ +#endif /* CONFIG_ZEPHYR */ + /* * USB-C mux state * @@ -227,6 +239,18 @@ void usb_mux_set(int port, mux_state_t mux_mode, enum usb_switch usb_config, int polarity); /** + * Configure superspeed muxes on type-C port for only one index in the mux + * chain + * + * @param port port number. + * @param index index of mux or retimer to set + * @param mux_mode mux selected function. + * @param usb_config usb2.0 selected function. + * @param polarity plug polarity (0=CC1, 1=CC2). + */ +void usb_mux_set_single(int port, int index, mux_state_t mux_mode, + enum usb_switch usb_mode, int polarity); +/** * Query superspeed mux status on type-C port. * * @param port port number. diff --git a/include/usb_pd.h b/include/usb_pd.h index 8468de814a..d5b6412d69 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -249,7 +249,7 @@ enum pd_rx_errors { #define PD_T_PR_SWAP_WAIT (100*MSEC) /* tPRSwapWait 100ms */ #define PD_T_DATA_RESET (225*MSEC) /* between 200ms and 250ms */ #define PD_T_DATA_RESET_FAIL (300*MSEC) /* 300ms */ -#define PD_T_VCONN_REAPPLIED (15*MSEC) /* between 10ms and 20ms */ +#define PD_T_VCONN_REAPPLIED (10*MSEC) /* between 10ms and 20ms */ #define PD_T_VCONN_DISCHARGE (240*MSEC) /* between 160ms and 240ms */ /* @@ -590,6 +590,18 @@ struct partner_active_modes { #define PD_PRODUCT_PID(vdo) (((vdo) >> 16) & 0xffff) /* + * PD Rev 3.1 Revision Message Data Object (RMDO) + * Only bits 16-31 have data. A uint_16t is used to hold RMDOs upper 16 bits. + */ +struct rmdo { + int reserved : 16; + int minor_ver : 4; + int major_ver : 4; + int minor_rev : 4; + int major_rev : 4; +}; + +/* * Message id starts from 0 to 7. If last_msg_id is initialized to 0, * it will lead to repetitive message id with first received packet, * so initialize it with an invalid value 0xff. @@ -1017,6 +1029,7 @@ enum pd_dpm_request { DPM_REQUEST_FRS_DET_ENABLE = BIT(21), DPM_REQUEST_FRS_DET_DISABLE = BIT(22), DPM_REQUEST_DATA_RESET = BIT(23), + DPM_REQUEST_GET_REVISION = BIT(24), }; /** @@ -1152,7 +1165,11 @@ enum pd_ctrl_msg_type { PD_CTRL_FR_SWAP = 19, PD_CTRL_GET_PPS_STATUS = 20, PD_CTRL_GET_COUNTRY_CODES = 21, - /* 22-31 Reserved */ + PD_CTRL_GET_SINK_CAP_EXT = 22, + /* Used for REV 3.1 */ + PD_CTRL_GET_SOURCE_INFO = 23, + PD_CTRL_GET_REVISION = 24, + /* 25-31 Reserved */ }; /* Control message types which always mark the start of an AMS */ @@ -1190,6 +1207,44 @@ enum pd_ctrl_msg_type { */ #define BATT_CAP_REF(n) (((n) >> 16) & 0xff) +/* SOP SDB fields for PD Rev 3.0 Section 6.5.2.1 */ +enum pd_sdb_temperature_status { + PD_SDB_TEMPERATURE_STATUS_NOT_SUPPORTED = 0, + PD_SDB_TEMPERATURE_STATUS_NORMAL = 2, + PD_SDB_TEMPERATURE_STATUS_WARNING = 4, + PD_SDB_TEMPERATURE_STATUS_OVER_TEMPERATURE = 6, +} __packed; +BUILD_ASSERT(sizeof(enum pd_sdb_temperature_status) == 1); + +struct pd_sdb { + /* SDB Fields for PD REV 3.0 */ + uint8_t internal_temp; + uint8_t present_input; + uint8_t present_battery_input; + uint8_t event_flags; + enum pd_sdb_temperature_status temperature_status; + uint8_t power_status; + /* SDB Fields for PD REV 3.1 */ + uint8_t power_state_change; +}; + +enum pd_sdb_power_state { + PD_SDB_POWER_STATE_NOT_SUPPORTED = 0, + PD_SDB_POWER_STATE_S0 = 1, + PD_SDB_POWER_STATE_MODERN_STANDBY = 2, + PD_SDB_POWER_STATE_S3 = 3, + PD_SDB_POWER_STATE_S4 = 4, + PD_SDB_POWER_STATE_S5 = 5, + PD_SDB_POWER_STATE_G3 = 6, +}; + +enum pd_sdb_power_indicator { + PD_SDB_POWER_INDICATOR_OFF = (0 << 3), + PD_SDB_POWER_INDICATOR_ON = (1 << 3), + PD_SDB_POWER_INDICATOR_BLINKING = (2 << 3), + PD_SDB_POWER_INDICATOR_BREATHING = (3 << 3), +}; + /* Extended message type for REV 3.0 */ enum pd_ext_msg_type { /* 0 Reserved */ @@ -1207,19 +1262,36 @@ enum pd_ext_msg_type { PD_EXT_PPS_STATUS = 12, PD_EXT_COUNTRY_INFO = 13, PD_EXT_COUNTRY_CODES = 14, - /* 15-31 Reserved */ + /* Used for REV 3.1 */ + PD_EXT_SINK_CAP = 15, + PD_EXT_CONTROL = 16, + PD_EXT_EPR_SOURCE_CAP = 17, + PD_EXT_EPR_SINK_CAP = 18, + /* 19-29 Reserved */ + PD_EXT_VENDOR_DEF = 30, + /* 31 Reserved */ }; +/* Alert Data Object fields for REV 3.1 */ +#define ADO_EXTENDED_ALERT_EVENT (BIT(24) << 7) /* Alert Data Object fields for REV 3.0 */ -#define ADO_OVP_EVENT BIT(30) -#define ADO_SOURCE_INPUT_CHANGE BIT(29) -#define ADO_OPERATING_CONDITION_CHANGE BIT(28) -#define ADO_OTP_EVENT BIT(27) -#define ADO_OCP_EVENT BIT(26) -#define ADO_BATTERY_STATUS_CHANGE BIT(25) +#define ADO_OVP_EVENT (BIT(24) << 6) +#define ADO_SOURCE_INPUT_CHANGE (BIT(24) << 5) +#define ADO_OPERATING_CONDITION_CHANGE (BIT(24) << 4) +#define ADO_OTP_EVENT (BIT(24) << 3) +#define ADO_OCP_EVENT (BIT(24) << 2) +#define ADO_BATTERY_STATUS_CHANGE (BIT(24) << 1) #define ADO_FIXED_BATTERIES(n) ((n & 0xf) << 20) #define ADO_HOT_SWAPPABLE_BATTERIES(n) ((n & 0xf) << 16) +/* Extended alert event types for REV 3.1 */ +enum ado_extended_alert_event_type { + ADO_POWER_STATE_CHANGE = 0x1, + ADO_POWER_BUTTON_PRESS = 0x2, + ADO_POWER_BUTTON_RELEASE = 0x3, + ADO_CONTROLLER_INITIATED_WAKE = 0x4, +}; + /* Data message type */ enum pd_data_msg_type { /* 0 Reserved */ @@ -1227,13 +1299,19 @@ enum pd_data_msg_type { PD_DATA_REQUEST = 2, PD_DATA_BIST = 3, PD_DATA_SINK_CAP = 4, - /* 5-14 Reserved for REV 2.0 */ + /* Used for REV 3.0 */ PD_DATA_BATTERY_STATUS = 5, PD_DATA_ALERT = 6, PD_DATA_GET_COUNTRY_INFO = 7, - /* 8-14 Reserved for REV 3.0 */ PD_DATA_ENTER_USB = 8, + /* Used for REV 3.1 */ + PD_DATA_EPR_REQUEST = 9, + PD_DATA_EPR_MODE = 10, + PD_DATA_SOURCE_INFO = 11, + PD_DATA_REVISION = 12, + /* 13-14 Reserved */ PD_DATA_VENDOR_DEF = 15, + /* 16-31 Reserved */ }; @@ -1578,14 +1656,6 @@ __override_proto void typec_set_input_current_limit(int port, uint32_t supply_voltage); /** - * Set the type-C current limit when sourcing current.. - * - * @param port USB-C port number - * @param rp One of enum tcpc_rp_value (eg TYPEC_RP_3A0) defining the limit. - */ -void typec_set_source_current_limit(int port, enum tcpc_rp_value rp); - -/** * Verify board specific health status : current, voltages... * * @return EC_SUCCESS if the board is good, <0 else. @@ -3151,14 +3221,6 @@ void board_reset_pd_mcu(void); */ bool pd_is_debug_acc(int port); -/** - * Sets the polarity of the port - * - * @param port USB-C port number - * @param polarity 0 for CC1, else 1 for CC2 - */ -void pd_set_polarity(int port, enum tcpc_cc_polarity polarity); - /* * Notify the AP that we have entered into DisplayPort Alternate Mode. This * sets a DP_ALT_MODE_ENTERED MKBP event which may wake the AP. @@ -3457,6 +3519,17 @@ void typec_select_src_collision_rp(int port, enum tcpc_rp_value rp); * @return 0 on success else failure */ int typec_update_cc(int port); + +/** + * Defines the New power state indicator bits in the Power State Change + * field of the Status Data Block (SDB) in USB PD Revision 3.1 and above. + * + * @param pd_sdb_power_state enum defining the New Power State field of the SDB + * @return pd_sdb_power_indicator enum for the SDB + */ +__override_proto enum pd_sdb_power_indicator board_get_pd_sdb_power_indicator( +enum pd_sdb_power_state power_state); + /****************************************************************************/ #endif /* __CROS_EC_USB_PD_H */ diff --git a/include/usb_pd_dpm.h b/include/usb_pd_dpm.h index c7ae53340d..391e7ed246 100644 --- a/include/usb_pd_dpm.h +++ b/include/usb_pd_dpm.h @@ -91,6 +91,14 @@ void dpm_evaluate_sink_fixed_pdo(int port, uint32_t vsafe5v_pdo); void dpm_add_non_pd_sink(int port); /* + * Evaluates the request from port partner + * + * @param port USB-C port number + * @param rdo Request from port partner + */ +void dpm_evaluate_request_rdo(int port, uint32_t rdo); + +/* * Remove this port as a sink, and reallocate maximum current as needed. * * @param port USB-C port number @@ -122,6 +130,15 @@ int dpm_get_source_pdo(const uint32_t **src_pdo, const int port); */ int dpm_get_source_current(const int port); +/* + * Build SOP Status Data Block (SDB) + * + * @param port USB-C port number + * @param *msg pointer to pd message + * @param *len pointer to uint32_t holding length of SDB + */ +int dpm_get_status_msg(int port, uint8_t *msg, uint32_t *len); + /* Enum for modules to describe to the DPM their setup status */ enum dpm_msg_setup_status { MSG_SETUP_SUCCESS, diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index c104b3af8f..e34329eb18 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -386,7 +386,6 @@ struct tcpm_drv { int (*get_chip_info)(int port, int live, struct ec_response_pd_chip_info_v1 *info); -#ifdef CONFIG_USB_PD_PPC /** * Request current sinking state of the TCPC * NOTE: this is most useful for PPCs that can not tell on their own @@ -426,7 +425,25 @@ struct tcpm_drv { * @return EC_SUCCESS or error */ int (*set_src_ctrl)(int port, int enable); -#endif + +#ifdef CONFIG_USB_PD_TCPM_SBU + /* + * Enable SBU lines. + * + * Some PD chips have integrated port protection for SBU lines and the + * switches to enable the SBU lines coming out of the PD chips are + * controlled by vendor specific registers. Hence, this function has to + * be written in vendor specific driver code and the board specific + * tcpc_config[] has to initialize the function with vendor specific + * function at board level. + * + * @param port Type-C port number + * @enable true for enable, false for disable + * + * @return EC_SUCCESS or error + */ + int (*set_sbu)(int port, bool enable); +#endif /* CONFIG_USB_PD_TCPM_SBU */ #ifdef CONFIG_USB_PD_TCPC_LOW_POWER /** @@ -497,6 +514,12 @@ struct tcpm_drv { int (*reset_bist_type_2)(int port); }; +#ifdef CONFIG_ZEPHYR + +#include "dt-bindings/usb_pd_tcpm.h" + +#else /* !CONFIG_ZEPHYR */ + /* * Macros for tcpc_config_t flags field. * @@ -521,6 +544,8 @@ struct tcpm_drv { #define TCPC_FLAGS_CONTROL_FRS BIT(7) #define TCPC_FLAGS_VBUS_MONITOR BIT(8) +#endif /* !CONFIG_ZEPHYR */ + struct tcpc_config_t { enum ec_bus_type bus_type; /* enum ec_bus_type */ union { diff --git a/include/usb_pe_sm.h b/include/usb_pe_sm.h index d6ecb4d400..4018f16322 100644 --- a/include/usb_pe_sm.h +++ b/include/usb_pe_sm.h @@ -176,6 +176,30 @@ const char *pe_get_current_state(int port); */ uint32_t pe_get_flags(int port); +/** + * Sets the Alert Data Object (ADO) in the PE state + * + * @param port USB-C port number + * @param data - ADO data sent during alert messages + * @return EC_SUCCESS if successful and EC_ERROR_BUSY if not + */ +int pe_set_ado(int port, uint32_t data); + +/** + * Clears the Alert Data Object (ADO) in the PE state + * + * @param port USB-C port number + */ +void pe_clear_ado(int port); + +/** + * Gets port partner's RMDO from the PE state. + * + * @param port USB-C port number + * @return port partner's Revision Message Data Object (RMDO). + */ +struct rmdo pe_get_partner_rmdo(int port); + #ifdef TEST_BUILD /** * Clears all internal port data, as we would on a detach event diff --git a/include/usbc_ppc.h b/include/usbc_ppc.h index ae7e0fba4c..5377f922ed 100644 --- a/include/usbc_ppc.h +++ b/include/usbc_ppc.h @@ -318,4 +318,17 @@ int ppc_get_alert_status(int port); */ int ppc_set_frs_enable(int port, int enable); +/** + * Board specific function to check if the Type-C port has PPC + * + * Some PD/TCPC chips have integrated power path control. If the board is + * using combination of chips with discrete PPC and integrated PPC add an + * overridable board function to return false for integrated PPC ports and + * true for discrete PPC port. + * + * @param port: The Type-C port number to check + * @return true if Type-C port has PPC else false + */ +__override_proto bool board_port_has_ppc(int port); + #endif /* !defined(__CROS_EC_USBC_PPC_H) */ diff --git a/include/util.h b/include/util.h index 3601ca6668..e39b81ccdf 100644 --- a/include/util.h +++ b/include/util.h @@ -16,7 +16,7 @@ #include <stdbool.h> #include <stddef.h> #ifdef CONFIG_ZEPHYR -#include <sys/util.h> +#include <zephyr/sys/util.h> #endif #ifdef __cplusplus |