summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2021-11-18 16:17:51 -0600
committerAseda Aboagye <aaboagye@google.com>2021-11-18 16:17:51 -0600
commitc5bd23a4b204565dab616f7fa4ee8a0b7b433d4c (patch)
treee0c957fe0bc99144057c50b2bff004a1c9a1fe45
parenteff51ca60572c33a4abf9390798de8e684d1469c (diff)
parent904255ef8d8c694fd21addc39ab3648178e5b354 (diff)
downloadchrome-ec-c5bd23a4b204565dab616f7fa4ee8a0b7b433d4c.tar.gz
Merge remote-tracking branch cros/main into firmware-keeby-14119.B-main
Relevant changes: git log --oneline eff51ca60..904255ef8 -- baseboard/dedede board/cappy2 board/corori board/driblee board/gooey board/haboki board/lalala board/waddledoo2 common/charge_state_v2.c common/mkbp_* common/ocpc.c common/usbc/usb_tc_drp_acc_trysrc_sm.c common/usbc/usb_sm.c common/usbc/*_pd_* common/usbc/dp_alt_mode.c common/usbc/usb_prl_sm.c common/usbc/usb_pe_drp_sm.c common/usb_charger.c common/usb_common.c common/usbc_ocp.c driver/charger/sm5803.* driver/charger/isl923x.* driver/tcpm/raa489000.* driver/tcpm/it83* include/power/icelake.h include/intel_x86.h power/icelake.c power/intel_x86.c util/getversion.sh 904255ef8 TCPMv2: Ensure modes are exited on hard reset BRANCH=None BUG=b:206745483 TEST=`make -j buildall` Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: I70eff1ad825526634dc9fd5ed17ae4746b0d9636
-rw-r--r--.gitlab-ci.yml21
-rw-r--r--baseboard/goroh/baseboard.c78
-rw-r--r--baseboard/goroh/baseboard.h12
-rw-r--r--baseboard/goroh/baseboard_usbc_config.h15
-rw-r--r--baseboard/goroh/board_id.c2
-rw-r--r--baseboard/goroh/build.mk4
-rw-r--r--baseboard/goroh/usbc_config.c131
-rw-r--r--board/boten/board.c83
-rw-r--r--board/boten/board.h2
-rw-r--r--board/brya/led.c6
-rw-r--r--board/brya/pwm.c10
-rw-r--r--board/bugzzy/board.c2
-rw-r--r--board/bugzzy/board.h1
-rw-r--r--board/dewatt/battery.c86
-rw-r--r--board/dewatt/board.h4
-rw-r--r--board/gimble/thermal.c46
-rw-r--r--board/goroh/board.c165
-rw-r--r--board/goroh/board.h65
-rw-r--r--board/goroh/build.mk6
-rw-r--r--board/goroh/fans.c91
-rw-r--r--board/goroh/gpio.inc14
-rw-r--r--board/goroh/led.c77
-rw-r--r--board/goroh/sensors.c124
-rw-r--r--board/goroh/usbc_confg.c33
-rw-r--r--board/kano/board.h6
-rw-r--r--board/kano/i2c.c2
-rw-r--r--board/kano/sensors.c142
-rw-r--r--board/primus/board.h1
-rw-r--r--board/vell/board.c5
-rw-r--r--board/vell/usbc_config.c52
-rw-r--r--board/vell/usbc_config.h4
-rw-r--r--board/volteer/board.h8
l---------board/volteer_apmodeentry1
-rw-r--r--chip/npcx/build.mk3
-rw-r--r--common/uart_printf.c6
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c20
-rw-r--r--core/cortex-m0/ec.lds.S4
-rw-r--r--docs/zephyr_build.md2
-rw-r--r--driver/charger/bq25710.c83
-rw-r--r--driver/charger/bq25710.h8
-rw-r--r--driver/charger/bq257x0_regs.h18
-rw-r--r--driver/usb_mux/virtual.c13
-rw-r--r--include/config.h35
-rw-r--r--include/power/falconlite.h1
-rw-r--r--power/falconlite.c11
-rw-r--r--zephyr/Kconfig.battery56
-rw-r--r--zephyr/Kconfig.console6
-rw-r--r--zephyr/emul/CMakeLists.txt1
-rw-r--r--zephyr/emul/Kconfig.tcpci7
-rw-r--r--zephyr/emul/emul_charger.c355
-rw-r--r--zephyr/emul/emul_sn5s330.c10
-rw-r--r--zephyr/emul/emul_tcpci.c222
-rw-r--r--zephyr/include/emul/emul_charger.h66
-rw-r--r--zephyr/include/emul/emul_sn5s330.h7
-rw-r--r--zephyr/include/emul/emul_tcpci.h68
-rw-r--r--zephyr/projects/herobrine/herobrine_npcx9/prj.conf3
-rw-r--r--zephyr/shim/include/config_chip.h33
-rw-r--r--zephyr/shim/src/console.c2
-rw-r--r--zephyr/test/drivers/src/cros_cbi.c16
-rw-r--r--zephyr/test/drivers/src/ppc_sn5s330.c12
-rw-r--r--zephyr/zmake/tests/test_project.py39
-rw-r--r--zephyr/zmake/zmake/project.py8
-rw-r--r--zephyr/zmake/zmake/zmake.py7
63 files changed, 1846 insertions, 575 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index dc2ad48535..8936070470 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -68,8 +68,7 @@ seed_cache:
- ls "${MODULES_DIR}" "${ZEPHYR_ROOT}"
# Users of this template must set:
-# $PROJECT to the project to build in zephyr/projects. E.g. "lazor")
-# $PROJECT_SUBDIR if it is in a subdirectory. E.g. "trogdor/"
+# $PROJECT to the project to build. E.g., "lazor"
.build_template: &build_template
stage: build
needs: ["seed_cache"]
@@ -77,7 +76,7 @@ seed_cache:
- zmake --zephyr-root "${ZEPHYR_ROOT}"
--modules-dir "${MODULES_DIR}" -l DEBUG configure -b
-B "${BUILD_DIR}/${PROJECT}" -t ${TOOLCHAIN:-zephyr}
- zephyr/projects/${PROJECT_SUBDIR}${PROJECT}
+ "${PROJECT}"
- for b in "${BUILD_DIR}/${PROJECT}"/build-* ; do
bdir=$(basename ${b}) ;
ninja -C ${b} ram_report >"${BUILD_DIR}/${PROJECT}/output/${bdir}_ram_report.txt" ;
@@ -92,15 +91,13 @@ seed_cache:
expire_in: 1 week
# Users of this template must set:
-# $PROJECT to the project to build in zephyr/projects. E.g. "lazor")
-# $PROJECT_SUBDIR if it is in a subdirectory. E.g. "trogdor/"
+# $PROJECT to the project to build. E.g., "lazor"
.coverage_template: &coverage_template
stage: test
needs: ["merged_coverage", "zephyr_coverage"]
script:
- - PROJECT_NAME=$(echo ${PROJECT_SUBDIR}${PROJECT} | tr '/' '_')
- - grep "SF:" "build/zcoverage/projects_${PROJECT_NAME}.info" | sort -u | sed -e 's|^SF:||' | xargs lcov -o build/no_zephyr_${PROJECT_NAME}.info -e build/merged_no_zephyr.info
- - /usr/bin/genhtml -q -o build/no_zephyr_${PROJECT_NAME}_rpt -t "${PROJECT} coverage w/o zephyr" -p ${EC_DIR} -s build/no_zephyr_${PROJECT_NAME}.info
+ - grep "SF:" "build/zcoverage/${PROJECT}.info" | sort -u | sed -e 's|^SF:||' | xargs lcov -o build/no_zephyr_${PROJECT}.info -e build/merged_no_zephyr.info
+ - /usr/bin/genhtml -q -o build/no_zephyr_${PROJECT}_rpt -t "${PROJECT} coverage w/o zephyr" -p ${EC_DIR} -s build/no_zephyr_${PROJECT}.info
artifacts:
paths:
- build/*.info
@@ -111,25 +108,21 @@ seed_cache:
delbin:
variables:
PROJECT: "delbin"
- PROJECT_SUBDIR: "volteer/"
<<: *build_template
hayato:
variables:
PROJECT: "hayato"
- PROJECT_SUBDIR: "asurada/"
<<: *build_template
herobrine_npcx9:
variables:
PROJECT: "herobrine_npcx9"
- PROJECT_SUBDIR: "herobrine/"
<<: *build_template
herobrine_npcx9_coverage:
variables:
PROJECT: "herobrine_npcx9"
- PROJECT_SUBDIR: "herobrine/"
<<: *coverage_template
it8xxx2_evb:
@@ -140,7 +133,6 @@ it8xxx2_evb:
lazor:
variables:
PROJECT: "lazor"
- PROJECT_SUBDIR: "trogdor/"
<<: *build_template
native_posix:
@@ -152,7 +144,6 @@ native_posix:
volteer:
variables:
PROJECT: "volteer"
- PROJECT_SUBDIR: "volteer/"
<<: *build_template
ec_coverage:
@@ -189,7 +180,7 @@ merged_coverage:
needs: ["ec_coverage", "zephyr_coverage"]
script:
- lcov -o build/merged.info -a build/coverage/lcov.info -a build/zcoverage/lcov.info
- - lcov -o build/merged_no_zephyr.info -r build/merged.info "${ZEPHYR_ROOT}/*" "${MODULES_DIR}/*" '/usr/include/x86_64-linux-gnu/*'
+ - lcov -o build/merged_no_zephyr.info -r build/merged.info "${ZEPHYR_ROOT}/*" "${MODULES_DIR}/*" "zephyr/drivers/*" '/usr/include/x86_64-linux-gnu/*'
artifacts:
paths:
- build/*.info
diff --git a/baseboard/goroh/baseboard.c b/baseboard/goroh/baseboard.c
index ba4f452289..ee88d1e713 100644
--- a/baseboard/goroh/baseboard.c
+++ b/baseboard/goroh/baseboard.c
@@ -6,6 +6,8 @@
/* Goroh baseboard-specific configuration */
#include "adc.h"
+#include "adc_chip.h"
+#include "baseboard_usbc_config.h"
#include "button.h"
#include "charge_manager.h"
#include "charger.h"
@@ -44,8 +46,6 @@
#include "usb_pd.h"
#include "usb_pd_tcpm.h"
-static void ppc_interrupt(enum gpio_signal signal);
-
#include "gpio_list.h"
#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
@@ -74,40 +74,6 @@ struct bc12_config bc12_ports[CHARGE_PORT_COUNT] = {
const int usb_port_enable[USB_PORT_COUNT] = {
};
-/* Detect subboard */
-static void board_tcpc_init(void)
-{
- gpio_enable_interrupt(GPIO_USB_C0_FAULT_ODL);
- gpio_enable_interrupt(GPIO_USB_C1_FAULT_ODL);
-}
-/* Must be done after I2C and subboard */
-DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_I2C + 1);
-
-/* PPC */
-struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_MAX_COUNT] = {
- {
- .i2c_port = I2C_PORT_PPC0,
- .i2c_addr_flags = SYV682X_ADDR0_FLAGS,
- .drv = &syv682x_drv,
- },
- {
- .i2c_port = I2C_PORT_PPC1,
- .i2c_addr_flags = SYV682X_ADDR0_FLAGS,
- .drv = &syv682x_drv,
- },
-};
-unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips);
-
-static void ppc_interrupt(enum gpio_signal signal)
-{
- if (signal == GPIO_USB_C0_FAULT_ODL)
- /* C0: PPC interrupt */
- syv682x_interrupt(0);
- else
- /* C1: PPC interrupt */
- syv682x_interrupt(1);
-}
-
/* Called on AP S3 -> S0 transition */
static void board_chipset_resume(void)
{
@@ -124,11 +90,6 @@ DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT);
/* USB Mux */
-/* TODO(yllin): configure USB mux */
-
-const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = {
-};
-
/*
* I2C channels (A, B, and C) are using the same timing registers (00h~07h)
* at default.
@@ -166,24 +127,6 @@ void board_overcurrent_event(int port, int is_overcurrented)
/* TODO: check correct operation for GOROH */
}
-/* TCPC */
-const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
- {
- .bus_type = EC_BUS_TYPE_EMBEDDED,
- /* TCPC is embedded within EC so no i2c config needed */
- .drv = &it8xxx2_tcpm_drv,
- /* Alert is active-low, push-pull */
- .flags = 0,
- },
- {
- .bus_type = EC_BUS_TYPE_EMBEDDED,
- /* TCPC is embedded within EC so no i2c config needed */
- .drv = &it8xxx2_tcpm_drv,
- /* Alert is active-low, push-pull */
- .flags = 0,
- },
-};
-
const struct cc_para_t *board_get_cc_tuning_parameter(enum usbpd_port port)
{
const static struct cc_para_t
@@ -201,23 +144,6 @@ const struct cc_para_t *board_get_cc_tuning_parameter(enum usbpd_port port)
return &cc_parameter[port];
}
-uint16_t tcpc_get_alert_status(void)
-{
- /*
- * C0 & C1: TCPC is embedded in the EC and processes interrupts in the
- * chip code (it83xx/intc.c)
- */
- return 0;
-}
-
-void board_reset_pd_mcu(void)
-{
- /*
- * C0 & C1: TCPC is embedded in the EC and processes interrupts in the
- * chip code (it83xx/intc.c)
- */
-}
-
void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
diff --git a/baseboard/goroh/baseboard.h b/baseboard/goroh/baseboard.h
index 18bb27c244..812d102d74 100644
--- a/baseboard/goroh/baseboard.h
+++ b/baseboard/goroh/baseboard.h
@@ -68,6 +68,9 @@
#define CONFIG_KEYBOARD_COL2_INVERTED
#define CONFIG_KEYBOARD_PROTOCOL_MKBP
#define CONFIG_MKBP_USE_GPIO
+#define CONFIG_KEYBOARD_BACKLIGHT
+#define CONFIG_PWM_KBLIGHT
+#define GPIO_EN_KEYBOARD_BACKLIGHT GPIO_EN_PPVAR_KB_BL_X
/* I2C */
#define CONFIG_I2C
@@ -79,10 +82,8 @@
#define I2C_PORT_CHARGER IT83XX_I2C_CH_A
#define I2C_PORT_BATTERY IT83XX_I2C_CH_A
#define I2C_PORT_ACCEL IT83XX_I2C_CH_B
-#define I2C_PORT_PPC0 IT83XX_I2C_CH_C
-#define I2C_PORT_PPC1 IT83XX_I2C_CH_E
-#define I2C_PORT_USB_MUX0 IT83XX_I2C_CH_C
-#define I2C_PORT_USB_MUX1 IT83XX_I2C_CH_E
+#define I2C_PORT_USB_C0 IT83XX_I2C_CH_C
+#define I2C_PORT_USB_C1 IT83XX_I2C_CH_E
#define I2C_PORT_VIRTUAL_BATTERY I2C_PORT_BATTERY
#define CONFIG_SMBUS_PEC
@@ -155,6 +156,9 @@
#endif
#define CONFIG_LID_SWITCH
+/* Fan */
+#define CONFIG_FANS 1
+
/* SPI / Host Command */
#define CONFIG_SPI
diff --git a/baseboard/goroh/baseboard_usbc_config.h b/baseboard/goroh/baseboard_usbc_config.h
new file mode 100644
index 0000000000..b5e76644ee
--- /dev/null
+++ b/baseboard/goroh/baseboard_usbc_config.h
@@ -0,0 +1,15 @@
+/* Copyright 2021 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.
+ */
+
+/* goroh family-specific USB-C configuration */
+
+#ifndef __CROS_EC_BASEBOARD_USBC_CONFIG_H
+#define __CROS_EC_BASEBOARD_USBC_CONFIG_H
+
+#include "gpio_signal.h"
+
+/* Common definition for the USB PD interrupt handlers. */
+void ppc_interrupt(enum gpio_signal signal);
+#endif /* __CROS_EC_BASEBOARD_USBC_CONFIG_H */
diff --git a/baseboard/goroh/board_id.c b/baseboard/goroh/board_id.c
index a8bee6d412..e90da11f57 100644
--- a/baseboard/goroh/board_id.c
+++ b/baseboard/goroh/board_id.c
@@ -91,7 +91,7 @@ static int version = -1;
/* b/163963220: Cache ADC value before board_hibernate_late() reads it */
static void board_version_init(void)
{
- version = adc_value_to_numeric_id(ADC_BOARD_ID_0);
+ version = adc_value_to_numeric_id(ADC_BOARD_ID);
if (version < 0) {
ccprints("WARN:BOARD_ID_0");
ccprints("Assuming board id = 0");
diff --git a/baseboard/goroh/build.mk b/baseboard/goroh/build.mk
index 58e9934bc0..4488c4b395 100644
--- a/baseboard/goroh/build.mk
+++ b/baseboard/goroh/build.mk
@@ -6,5 +6,7 @@
# Baseboard specific files build
#
-baseboard-y=baseboard.o board_id.o
+baseboard-y+=baseboard.o
+baseboard-y+=board_id.o
+baseboard-y+=usbc_config.o
baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
diff --git a/baseboard/goroh/usbc_config.c b/baseboard/goroh/usbc_config.c
new file mode 100644
index 0000000000..4c02528285
--- /dev/null
+++ b/baseboard/goroh/usbc_config.c
@@ -0,0 +1,131 @@
+/* Copyright 2021 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.
+ */
+
+/* Goroh family-specific USB-C configuration */
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "common.h"
+#include "compile_time_macros.h"
+#include "config.h"
+#include "console.h"
+#include "hooks.h"
+#include "driver/tcpm/it8xxx2_pd_public.h"
+#include "driver/ppc/syv682x_public.h"
+#include "driver/retimer/ps8818.h"
+#include "driver/tcpm/tcpci.h"
+#include "usb_pd.h"
+#include "usbc_ppc.h"
+#include "gpio.h"
+#include "gpio_signal.h"
+
+#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args)
+
+#ifdef CONFIG_BRINGUP
+#define GPIO_SET_LEVEL(pin, lvl) gpio_set_level_verbose(CC_USBPD, pin, lvl)
+#else
+#define GPIO_SET_LEVEL(pin, lvl) gpio_set_level(pin, lvl)
+#endif
+
+/* PPC */
+struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+ {
+ .i2c_port = I2C_PORT_USB_C0,
+ .i2c_addr_flags = SYV682X_ADDR0_FLAGS,
+ .drv = &syv682x_drv,
+ },
+ {
+ .i2c_port = I2C_PORT_USB_C1,
+ .i2c_addr_flags = SYV682X_ADDR0_FLAGS,
+ .drv = &syv682x_drv,
+ },
+};
+unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips);
+
+/* USB Mux */
+
+__overridable int board_c1_ps8818_mux_init(const struct usb_mux *me)
+{
+ /* enable C1 mux power */
+ GPIO_SET_LEVEL(GPIO_EN_USB_C1_MUX_PWR, 1);
+ return 0;
+}
+
+__overridable int board_c1_ps8818_mux_set(const struct usb_mux *me,
+ mux_state_t mux_state)
+{
+ if (mux_state == USB_PD_MUX_NONE)
+ GPIO_SET_LEVEL(GPIO_EN_USB_C1_MUX_PWR, 0);
+
+ return 0;
+}
+
+const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+ {
+ /* C0 no mux */
+ },
+ {
+ .usb_port = USBC_PORT_C1,
+ .i2c_port = I2C_PORT_USB_C1,
+ .i2c_addr_flags = PS8818_I2C_ADDR_FLAGS,
+ .driver = &ps8818_usb_retimer_driver,
+ .board_init = &board_c1_ps8818_mux_init,
+ .board_set = &board_c1_ps8818_mux_set,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(usb_muxes) == USBC_PORT_COUNT);
+
+/* TCPC */
+const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+ {
+ .bus_type = EC_BUS_TYPE_EMBEDDED,
+ /* TCPC is embedded within EC so no i2c config needed */
+ .drv = &it8xxx2_tcpm_drv,
+ /* Alert is active-low, push-pull */
+ .flags = 0,
+ },
+ {
+ .bus_type = EC_BUS_TYPE_EMBEDDED,
+ /* TCPC is embedded within EC so no i2c config needed */
+ .drv = &it8xxx2_tcpm_drv,
+ /* Alert is active-low, push-pull */
+ .flags = 0,
+ },
+};
+
+void ppc_interrupt(enum gpio_signal signal)
+{
+ if (signal == GPIO_USB_C0_FAULT_ODL)
+ /* C0: PPC interrupt */
+ syv682x_interrupt(0);
+ else
+ /* C1: PPC interrupt */
+ syv682x_interrupt(1);
+}
+
+
+static void board_tcpc_init(void)
+{
+ gpio_enable_interrupt(GPIO_USB_C0_FAULT_ODL);
+ gpio_enable_interrupt(GPIO_USB_C1_FAULT_ODL);
+}
+DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_I2C + 1);
+
+void board_reset_pd_mcu(void)
+{
+ /*
+ * C0 & C1: TCPC is embedded in the EC and processes interrupts in the
+ * chip code (it83xx/intc.c)
+ */
+}
+
+uint16_t tcpc_get_alert_status(void)
+{
+ /*
+ * C0 & C1: TCPC is embedded in the EC and processes interrupts in the
+ * chip code (it83xx/intc.c)
+ */
+ return 0;
+}
diff --git a/board/boten/board.c b/board/boten/board.c
index b6301834bf..17436a0091 100644
--- a/board/boten/board.c
+++ b/board/boten/board.c
@@ -7,6 +7,7 @@
#include "adc_chip.h"
#include "button.h"
+#include "cbi_fw_config.h"
#include "charge_manager.h"
#include "charge_state_v2.h"
#include "charger.h"
@@ -216,37 +217,6 @@ const int usb_port_enable[USB_PORT_COUNT] = {
GPIO_EN_USB_A0_VBUS,
};
-void board_init(void)
-{
- gpio_enable_interrupt(GPIO_USB_C0_INT_ODL);
- gpio_enable_interrupt(GPIO_USB_C0_CCSBU_OVP_ODL);
- /* Enable gpio interrupt for base accelgyro sensor */
- gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
- gpio_enable_interrupt(GPIO_HDMI_HPD_SUB_ODL);
- /* Enable gpio interrupt for pen detect */
- gpio_enable_interrupt(GPIO_PEN_DET_ODL);
-
- /* Make sure pen detection is triggered or not at sysjump */
- if (!gpio_get_level(GPIO_PEN_DET_ODL))
- gpio_set_level(GPIO_EN_PP5000_PEN, 1);
-
- if (gpio_get_level(GPIO_PEN_DET_ODL))
- gpio_set_level(GPIO_PEN_DET_PCH, 1);
-
- /* Set LEDs luminance */
- pwm_set_duty(PWM_CH_LED_RED, 70);
- pwm_set_duty(PWM_CH_LED_GREEN, 70);
- pwm_set_duty(PWM_CH_LED_WHITE, 70);
-
- /*
- * If interrupt lines are already low, schedule them to be processed
- * after inits are completed.
- */
- if (!gpio_get_level(GPIO_USB_C0_INT_ODL))
- hook_call_deferred(&check_c0_line_data, 0);
-}
-DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
-
void board_reset_pd_mcu(void)
{
/*
@@ -467,7 +437,56 @@ struct motion_sensor_t motion_sensors[] = {
},
};
-const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+void board_init(void)
+{
+ gpio_enable_interrupt(GPIO_USB_C0_INT_ODL);
+ gpio_enable_interrupt(GPIO_USB_C0_CCSBU_OVP_ODL);
+ gpio_enable_interrupt(GPIO_HDMI_HPD_SUB_ODL);
+ if (get_cbi_fw_config_tablet_mode() == TABLET_MODE_PRESENT) {
+ motion_sensor_count = ARRAY_SIZE(motion_sensors);
+ /* Enable gpio interrupt for base accelgyro sensor */
+ gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
+
+ /* Enable gpio interrupt for pen detect */
+ gpio_enable_interrupt(GPIO_PEN_DET_ODL);
+
+ /* Make sure pen detection is triggered or not at sysjump */
+ if (!gpio_get_level(GPIO_PEN_DET_ODL))
+ gpio_set_level(GPIO_EN_PP5000_PEN, 1);
+
+ if (gpio_get_level(GPIO_PEN_DET_ODL))
+ gpio_set_level(GPIO_PEN_DET_PCH, 1);
+ } else {
+ motion_sensor_count = 0;
+ gmr_tablet_switch_disable();
+ /* Base accel is not stuffed, don't allow line to float */
+ gpio_set_flags(GPIO_BASE_SIXAXIS_INT_L,
+ GPIO_INPUT | GPIO_PULL_DOWN);
+
+ /* only clamshell sku todo */
+ gpio_set_flags(GPIO_PEN_DET_ODL, GPIO_INPUT | GPIO_PULL_DOWN);
+ gpio_set_flags(GPIO_PEN_DET_PCH, GPIO_INPUT | GPIO_PULL_DOWN);
+ gpio_set_flags(GPIO_EN_PP5000_PEN, GPIO_INPUT | GPIO_PULL_DOWN);
+ gpio_set_flags(GPIO_LID_360_L, GPIO_INPUT | GPIO_PULL_DOWN);
+ gpio_set_flags(GPIO_VOLUP_BTN_ODL, GPIO_INPUT | GPIO_PULL_DOWN);
+ gpio_set_flags(GPIO_VOLDN_BTN_ODL, GPIO_INPUT | GPIO_PULL_DOWN);
+ }
+
+ /* Set LEDs luminance */
+ pwm_set_duty(PWM_CH_LED_RED, 70);
+ pwm_set_duty(PWM_CH_LED_GREEN, 70);
+ pwm_set_duty(PWM_CH_LED_WHITE, 70);
+
+ /*
+ * If interrupt lines are already low, schedule them to be processed
+ * after inits are completed.
+ */
+ if (!gpio_get_level(GPIO_USB_C0_INT_ODL))
+ hook_call_deferred(&check_c0_line_data, 0);
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
/* Thermistors */
const struct temp_sensor_t temp_sensors[] = {
diff --git a/board/boten/board.h b/board/boten/board.h
index 0e2a72015c..8c2b1d4417 100644
--- a/board/boten/board.h
+++ b/board/boten/board.h
@@ -93,6 +93,8 @@
#define USB_PORT_COUNT 1
#define CONFIG_USB_PORT_POWER_DUMB
+#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT
+
#ifndef __ASSEMBLER__
#include "gpio_signal.h"
diff --git a/board/brya/led.c b/board/brya/led.c
index 68945ec79e..78c10e65b8 100644
--- a/board/brya/led.c
+++ b/board/brya/led.c
@@ -27,7 +27,7 @@ const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
/*
* We only have a white and an amber LED, so setting any other color results in
- * both LEDs being off.
+ * both LEDs being off. Cap at 50% to save power.
*/
struct pwm_led_color_map led_color_map[EC_LED_COLOR_COUNT] = {
/* Amber, White */
@@ -35,8 +35,8 @@ struct pwm_led_color_map led_color_map[EC_LED_COLOR_COUNT] = {
[EC_LED_COLOR_GREEN] = { 0, 0 },
[EC_LED_COLOR_BLUE] = { 0, 0 },
[EC_LED_COLOR_YELLOW] = { 0, 0 },
- [EC_LED_COLOR_WHITE] = { 0, 100 },
- [EC_LED_COLOR_AMBER] = { 100, 0 },
+ [EC_LED_COLOR_WHITE] = { 0, 50 },
+ [EC_LED_COLOR_AMBER] = { 50, 0 },
};
/* Two logical LEDs with amber and white channels. */
diff --git a/board/brya/pwm.c b/board/brya/pwm.c
index 6e662f8e7d..2203f14c8d 100644
--- a/board/brya/pwm.c
+++ b/board/brya/pwm.c
@@ -53,17 +53,17 @@ BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
static void board_pwm_init(void)
{
/*
- * Turn on all the LED at 50%.
+ * Turn off all the LEDs.
* Turn on the fan at 100%.
*/
pwm_enable(PWM_CH_LED1, 1);
- pwm_set_duty(PWM_CH_LED1, 50);
+ pwm_set_duty(PWM_CH_LED1, 0);
pwm_enable(PWM_CH_LED2, 1);
- pwm_set_duty(PWM_CH_LED2, 50);
+ pwm_set_duty(PWM_CH_LED2, 0);
pwm_enable(PWM_CH_LED3, 1);
- pwm_set_duty(PWM_CH_LED3, 50);
+ pwm_set_duty(PWM_CH_LED3, 0);
pwm_enable(PWM_CH_LED4, 1);
- pwm_set_duty(PWM_CH_LED4, 50);
+ pwm_set_duty(PWM_CH_LED4, 0);
pwm_enable(PWM_CH_KBLIGHT, 1);
pwm_set_duty(PWM_CH_KBLIGHT, 50);
diff --git a/board/bugzzy/board.c b/board/bugzzy/board.c
index ab0f8563c8..315f3a738b 100644
--- a/board/bugzzy/board.c
+++ b/board/bugzzy/board.c
@@ -921,7 +921,7 @@ void backlit_gpio_tick(void)
if (board_id >= 4 && signal == 1)
i2c_write16(I2C_PORT_LCD, I2C_ADDR_MP3372_FLAGS,
MP3372_REG_ISET_CHEN,
- MP3372_ISET_21P8_CHEN_ALL);
+ MP3372_ISET_19P4_CHEN_ALL);
}
DECLARE_HOOK(HOOK_TICK, backlit_gpio_tick, HOOK_PRIO_DEFAULT);
diff --git a/board/bugzzy/board.h b/board/bugzzy/board.h
index d33cd879c9..9b9f6cf015 100644
--- a/board/bugzzy/board.h
+++ b/board/bugzzy/board.h
@@ -146,6 +146,7 @@
/* ISET & CHEN */
#define MP3372_REG_ISET_CHEN 0x00
#define MP3372_ISET_21P8_CHEN_ALL 0x70ff
+#define MP3372_ISET_19P4_CHEN_ALL 0x63ff
/*
* I2C pin names for baseboard
*
diff --git a/board/dewatt/battery.c b/board/dewatt/battery.c
index ddf3adff50..40d5f930e3 100644
--- a/board/dewatt/battery.c
+++ b/board/dewatt/battery.c
@@ -30,57 +30,25 @@
* address, mask, and disconnect value need to be provided.
*/
const struct board_batt_params board_battery_info[] = {
- /* AEC 5477109 */
- [BATTERY_AEC] = {
+ /* AP19B8M */
+ [BATTERY_AP19B8M] = {
.fuel_gauge = {
- .manuf_name = "AEC",
- .ship_mode = {
- .reg_addr = 0x00,
- .reg_data = { 0x0010, 0x0010 },
- },
- .sleep_mode = {
- .sleep_supported = true,
- .reg_addr = 0x00,
- .reg_data = 0x0011,
- },
- .fet = {
- .reg_addr = 0x0,
- .reg_mask = 0x2000,
- .disconnect_val = 0x2000,
- }
- },
- .batt_info = {
- .voltage_max = 8700, /* mV */
- .voltage_normal = 7600,
- .voltage_min = 6000,
- .precharge_current = 100, /* mA */
- .start_charging_min_c = 0,
- .start_charging_max_c = 45,
- .charging_min_c = 0,
- .charging_max_c = 50,
- .discharging_min_c = -20,
- .discharging_max_c = 60,
- },
- },
- /* AP18F4M / LIS4163ACPC */
- [BATTERY_AP18F4M] = {
- .fuel_gauge = {
- .manuf_name = "Murata KT00404001",
+ .manuf_name = "LGC KT0030G024",
.ship_mode = {
.reg_addr = 0x3A,
.reg_data = { 0xC574, 0xC574 },
},
.fet = {
- .reg_addr = 0x0,
- .reg_mask = 0x2000,
- .disconnect_val = 0x2000,
+ .reg_addr = 0x43,
+ .reg_mask = 0x0001,
+ .disconnect_val = 0x0,
}
},
.batt_info = {
- .voltage_max = 8700, /* mV */
- .voltage_normal = 7600,
- .voltage_min = 5500,
- .precharge_current = 256, /* mA */
+ .voltage_max = 13350,
+ .voltage_normal = 11610,
+ .voltage_min = 9000,
+ .precharge_current = 256,
.start_charging_min_c = 0,
.start_charging_max_c = 50,
.charging_min_c = 0,
@@ -89,39 +57,7 @@ const struct board_batt_params board_battery_info[] = {
.discharging_max_c = 75,
},
},
- /* POW-TECH Battery Information */
- [BATTERY_POWER_TECH] = {
- .fuel_gauge = {
- .manuf_name = "POW-TECH",
- .ship_mode = {
- .reg_addr = 0x0,
- .reg_data = { 0x10, 0x10 },
- },
- .sleep_mode = {
- .sleep_supported = true,
- .reg_addr = 0x00,
- .reg_data = 0x0011,
- },
- .fet = {
- .reg_addr = 0x00,
- .reg_mask = 0x2000,
- .disconnect_val = 0x2000,
- }
- },
- .batt_info = {
- .voltage_max = 8800, /* mV */
- .voltage_normal = 7700,
- .voltage_min = 6000,
- .precharge_current = 88, /* mA */
- .start_charging_min_c = 0,
- .start_charging_max_c = 45,
- .charging_min_c = 0,
- .charging_max_c = 45,
- .discharging_min_c = -20,
- .discharging_max_c = 60,
- },
- },
};
BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
-const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_AP18F4M;
+const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_AP19B8M;
diff --git a/board/dewatt/board.h b/board/dewatt/board.h
index fa04e1bd89..0743103a66 100644
--- a/board/dewatt/board.h
+++ b/board/dewatt/board.h
@@ -66,9 +66,7 @@ void motion_interrupt(enum gpio_signal signal);
/* Battery Types */
enum battery_type {
- BATTERY_AEC,
- BATTERY_AP18F4M,
- BATTERY_POWER_TECH,
+ BATTERY_AP19B8M,
BATTERY_TYPE_COUNT,
};
diff --git a/board/gimble/thermal.c b/board/gimble/thermal.c
index 101c436886..25e7bf2c00 100644
--- a/board/gimble/thermal.c
+++ b/board/gimble/thermal.c
@@ -9,6 +9,7 @@
#include "fan.h"
#include "hooks.h"
#include "host_command.h"
+#include "tablet_mode.h"
#include "temp_sensor.h"
#include "thermal.h"
#include "util.h"
@@ -31,6 +32,8 @@ struct fan_step {
int8_t off[TEMP_SENSOR_COUNT];
/* Fan rpm */
uint16_t rpm[FAN_CH_COUNT];
+ /* Fan rpm for tablet mode */
+ uint16_t rpm_tablet[FAN_CH_COUNT];
};
/*
* TODO(b/167931578) Only monitor sensor3 for now.
@@ -39,39 +42,45 @@ struct fan_step {
static const struct fan_step fan_table[] = {
{
/* level 0 */
- .on = {44, -1, -1},
+ .on = {43, -1, -1},
.off = {0, -1, -1},
.rpm = {0},
+ .rpm_tablet = {0},
},
{
/* level 1 */
- .on = {46, -1, -1},
- .off = {44, -1, -1},
- .rpm = {3200},
+ .on = {45, -1, -1},
+ .off = {43, -1, -1},
+ .rpm = {3400},
+ .rpm_tablet = {3400},
},
{
/* level 2 */
- .on = {50, -1, -1},
- .off = {45, -1, -1},
- .rpm = {3600},
+ .on = {46, -1, -1},
+ .off = {44, -1, -1},
+ .rpm = {3800},
+ .rpm_tablet = {3700},
},
{
/* level 3 */
- .on = {54, -1, -1},
- .off = {49, -1, -1},
- .rpm = {4100},
+ .on = {48, -1, -1},
+ .off = {45, -1, -1},
+ .rpm = {4200},
+ .rpm_tablet = {4100},
},
{
/* level 4 */
- .on = {58, -1, -1},
- .off = {53, -1, -1},
- .rpm = {4900},
+ .on = {50, -1, -1},
+ .off = {47, -1, -1},
+ .rpm = {4800},
+ .rpm_tablet = {4800},
},
{
/* level 5 */
- .on = {60, -1, -1},
- .off = {57, -1, -1},
- .rpm = {5200},
+ .on = {52, -1, -1},
+ .off = {49, -1, -1},
+ .rpm = {5400},
+ .rpm_tablet = {5200},
},
};
const int num_fan_levels = ARRAY_SIZE(fan_table);
@@ -127,7 +136,10 @@ int fan_table_to_rpm(int fan, int *temp, enum temp_sensor_id temp_sensor)
switch (fan) {
case FAN_CH_0:
- new_rpm = fan_table[current_level].rpm[FAN_CH_0];
+ if (tablet_get_mode())
+ new_rpm = fan_table[current_level].rpm_tablet[FAN_CH_0];
+ else
+ new_rpm = fan_table[current_level].rpm[FAN_CH_0];
break;
default:
break;
diff --git a/board/goroh/board.c b/board/goroh/board.c
index 9354dec618..c99b0deff6 100644
--- a/board/goroh/board.c
+++ b/board/goroh/board.c
@@ -50,172 +50,49 @@ static void board_init(void)
{
/* Enable motion sensor interrupt */
gpio_enable_interrupt(GPIO_BASE_IMU_INT_L);
- gpio_enable_interrupt(GPIO_LID_ACCEL_INT_L);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
-/* Sensor */
-static struct mutex g_base_mutex;
-static struct mutex g_lid_mutex;
-
-static struct bmi_drv_data_t g_bmi160_data;
-static struct stprivate_data g_lis2dwl_data;
-
-/* Matrix to rotate accelerometer into standard reference frame */
-static const mat33_fp_t base_standard_ref = {
- {0, FLOAT_TO_FP(1), 0},
- {FLOAT_TO_FP(-1), 0, 0},
- {0, 0, FLOAT_TO_FP(1)},
-};
-
-static void update_rotation_matrix(void)
-{
- if (board_get_version() >= 2) {
- motion_sensors[BASE_ACCEL].rot_standard_ref =
- &base_standard_ref;
- motion_sensors[BASE_GYRO].rot_standard_ref =
- &base_standard_ref;
- }
-}
-DECLARE_HOOK(HOOK_INIT, update_rotation_matrix, HOOK_PRIO_INIT_ADC + 2);
-
-struct motion_sensor_t motion_sensors[] = {
- /*
- * Note: bmi160: supports accelerometer and gyro sensor
- * Requirement: accelerometer sensor must init before gyro sensor
- * DO NOT change the order of the following table.
- */
- [BASE_ACCEL] = {
- .name = "Base Accel",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_BMI160,
- .type = MOTIONSENSE_TYPE_ACCEL,
- .location = MOTIONSENSE_LOC_BASE,
- .drv = &bmi160_drv,
- .mutex = &g_base_mutex,
- .drv_data = &g_bmi160_data,
- .port = I2C_PORT_ACCEL,
- .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
- .rot_standard_ref = NULL, /* identity matrix */
- .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */
- .min_frequency = BMI_ACCEL_MIN_FREQ,
- .max_frequency = BMI_ACCEL_MAX_FREQ,
- .config = {
- /* Sensor on for angle detection */
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 10000 | ROUND_UP_FLAG,
- .ec_rate = 100 * MSEC,
- },
- /* Sensor on for angle detection */
- [SENSOR_CONFIG_EC_S3] = {
- .odr = 10000 | ROUND_UP_FLAG,
- .ec_rate = 100 * MSEC,
- },
- },
- },
- [BASE_GYRO] = {
- .name = "Base Gyro",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_BMI160,
- .type = MOTIONSENSE_TYPE_GYRO,
- .location = MOTIONSENSE_LOC_BASE,
- .drv = &bmi160_drv,
- .mutex = &g_base_mutex,
- .drv_data = &g_bmi160_data,
- .port = I2C_PORT_ACCEL,
- .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
- .default_range = 1000, /* dps */
- .rot_standard_ref = NULL, /* identity matrix */
- .min_frequency = BMI_GYRO_MIN_FREQ,
- .max_frequency = BMI_GYRO_MAX_FREQ,
- },
- [LID_ACCEL] = {
- .name = "Lid Accel",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_LIS2DWL,
- .type = MOTIONSENSE_TYPE_ACCEL,
- .location = MOTIONSENSE_LOC_LID,
- .drv = &lis2dw12_drv,
- .mutex = &g_lid_mutex,
- .drv_data = &g_lis2dwl_data,
- .int_signal = GPIO_LID_ACCEL_INT_L,
- .port = I2C_PORT_ACCEL,
- .i2c_spi_addr_flags = LIS2DWL_ADDR1_FLAGS,
- .flags = MOTIONSENSE_FLAG_INT_SIGNAL,
- .rot_standard_ref = NULL, /* identity matrix */
- .default_range = 2, /* g */
- .min_frequency = LIS2DW12_ODR_MIN_VAL,
- .max_frequency = LIS2DW12_ODR_MAX_VAL,
- .config = {
- /* EC use accel for angle detection */
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 12500 | ROUND_UP_FLAG,
- },
- /* Sensor on for lid angle detection */
- [SENSOR_CONFIG_EC_S3] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- },
- },
-};
-const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
-
/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
const struct adc_t adc_channels[] = {
- {"VBUS", ADC_MAX_MVOLT * 10, ADC_READ_MAX + 1, 0, CHIP_ADC_CH0},
- {"BOARD_ID_0", ADC_MAX_MVOLT, ADC_READ_MAX + 1, 0, CHIP_ADC_CH1},
- {"TEMP_VDD_CPU", ADC_MAX_MVOLT, ADC_READ_MAX + 1, 0, CHIP_ADC_CH2},
- {"TEMP_VDD_GPU", ADC_MAX_MVOLT, ADC_READ_MAX + 1, 0, CHIP_ADC_CH3},
+ { "BOARD_ID", ADC_MAX_MVOLT, ADC_READ_MAX + 1, 0, CHIP_ADC_CH1 },
+ { "TEMP_CPU", ADC_MAX_MVOLT, ADC_READ_MAX + 1, 0, CHIP_ADC_CH2 },
+ { "TEMP_GPU", ADC_MAX_MVOLT, ADC_READ_MAX + 1, 0, CHIP_ADC_CH3 },
+ { "TEMP_CHARGER", ADC_MAX_MVOLT, ADC_READ_MAX + 1, 0, CHIP_ADC_CH5 },
};
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
-/* PWM */
-
-/*
- * PWM channels. Must be in the exactly same order as in enum pwm_channel.
- * There total three 16 bits clock prescaler registers for all pwm channels,
- * so use the same frequency and prescaler register setting is required if
- * number of pwm channel greater than three.
- *
- * TODO(yllin): configure PWM
- */
+/* PWM channels. */
const struct pwm_t pwm_channels[] = {
- [PWM_CH_LED1] = {
- .channel = 0,
- .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW,
+ [PWM_CH_LED_GREEN] = {
+ .channel = PWM_HW_CH_DCR0,
+ .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_OPEN_DRAIN |
+ PWM_CONFIG_ACTIVE_LOW,
.freq_hz = 324, /* maximum supported frequency */
.pcfsr_sel = PWM_PRESCALER_C4
},
- [PWM_CH_LED2] = {
- .channel = 1,
- .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW,
+ [PWM_CH_LED_RED] = {
+ .channel = PWM_HW_CH_DCR1,
+ .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_OPEN_DRAIN |
+ PWM_CONFIG_ACTIVE_LOW,
.freq_hz = 324, /* maximum supported frequency */
.pcfsr_sel = PWM_PRESCALER_C4
},
[PWM_CH_FAN] = {
- .channel = 2,
- .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW,
- .freq_hz = 324, /* maximum supported frequency */
+ .channel = PWM_HW_CH_DCR2,
+ .flags = PWM_CONFIG_OPEN_DRAIN,
+ .freq_hz = 25000, /* maximum supported frequency */
.pcfsr_sel = PWM_PRESCALER_C4
},
- [PWM_CH_KB_BL] = {
- .channel = 3,
- .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW,
- .freq_hz = 324, /* maximum supported frequency */
+ [PWM_CH_KBLIGHT] = {
+ .channel = PWM_HW_CH_DCR3,
+ .flags = PWM_CONFIG_DSLEEP,
+ .freq_hz = 25000,
.pcfsr_sel = PWM_PRESCALER_C4
},
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
-int board_accel_force_mode_mask(void)
-{
- int version = board_get_version();
-
- if (version == -1 || version >= 2)
- return 0;
- return BIT(LID_ACCEL);
-}
-
static void board_suspend(void)
{
}
@@ -225,5 +102,3 @@ static void board_resume(void)
{
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_resume, HOOK_PRIO_DEFAULT);
-
-
diff --git a/board/goroh/board.h b/board/goroh/board.h
index 33c6ca901e..dec936adb7 100644
--- a/board/goroh/board.h
+++ b/board/goroh/board.h
@@ -22,9 +22,21 @@
#define CONFIG_IT83XX_RESET_PD_CONTRACT_IN_BRAM
/* LED */
+#define CONFIG_LED_PWM_COUNT 1
+#define CONFIG_LED_PWM
#define CONFIG_LED_POWER_LED
-#define CONFIG_LED_ONOFF_STATES
-#define CONFIG_LED_ONOFF_STATES_BAT_LOW 10
+#undef CONFIG_LED_PWM_NEAR_FULL_COLOR
+#undef CONFIG_LED_PWM_CHARGE_COLOR
+#undef CONFIG_LED_PWM_CHARGE_ERROR_COLOR
+#undef CONFIG_LED_PWM_LOW_BATT_COLOR
+#undef CONFIG_LED_PWM_SOC_ON_COLOR
+#undef CONFIG_LED_PWM_SOC_SUSPEND_COLOR
+#define CONFIG_LED_PWM_NEAR_FULL_COLOR EC_LED_COLOR_GREEN
+#define CONFIG_LED_PWM_CHARGE_COLOR EC_LED_COLOR_GREEN
+#define CONFIG_LED_PWM_CHARGE_ERROR_COLOR EC_LED_COLOR_RED
+#define CONFIG_LED_PWM_LOW_BATT_COLOR EC_LED_COLOR_RED
+#define CONFIG_LED_PWM_SOC_ON_COLOR EC_LED_COLOR_COUNT /* OFF */
+#define CONFIG_LED_PWM_SOC_SUSPEND_COLOR EC_LED_COLOR_COUNT /* OFF */
/* PD / USB-C / PPC */
#define CONFIG_USB_PD_DEBUG_LEVEL 3
@@ -46,18 +58,21 @@
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
-#define CONFIG_ACCEL_LIS2DWL
-#define CONFIG_ACCEL_LIS2DW_AS_BASE
-#define CONFIG_ACCEL_LIS2DW12_INT_EVENT \
- TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL)
-
#define CONFIG_LID_ANGLE
#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
#define CONFIG_LID_ANGLE_UPDATE
-/* TODO(b/171931139): remove this after rev1 board deprecated */
-#define CONFIG_ACCEL_FORCE_MODE_MASK (board_accel_force_mode_mask())
+#define CONFIG_ACCEL_BMA255 /* Lid accel BMA253 */
+
+/* Sensors without hardware FIFO are in forced mode */
+#define CONFIG_ACCEL_FORCE_MODE_MASK \
+ (BIT(LID_ACCEL) | BIT(BASE_GYRO) | BIT(BASE_ACCEL))
+
+/* Thermistors */
+#define CONFIG_TEMP_SENSOR
+#define CONFIG_THERMISTOR
+#define CONFIG_STEINHART_HART_3V3_51K1_47K_4050B
/* SPI / Host Command */
#undef CONFIG_HOSTCMD_DEBUG_MODE
@@ -85,24 +100,40 @@ enum sensor_id {
};
enum adc_channel {
- ADC_BOARD_ID_0, /* ADC 1 */
- ADC_TEMP_VDD_CPU, /* ADC 2 */
- ADC_TEMP_VDD_GPU, /* ADC 3 */
- ADC_TEMP_CHARGER, /* ADC 5 */
+ ADC_BOARD_ID, /* ADC 1 */
+ ADC_TEMP_SENSOR_CPU, /* ADC 2 */
+ ADC_TEMP_SENSOR_GPU, /* ADC 3 */
+ ADC_TEMP_SENSOR_CHARGER, /* ADC 5 */
/* Number of ADC channels */
ADC_CH_COUNT,
};
+enum usbc_port {
+ USBC_PORT_C0 = 0,
+ USBC_PORT_C1,
+ USBC_PORT_COUNT
+};
+
enum pwm_channel {
- PWM_CH_LED1,
- PWM_CH_LED2,
+ PWM_CH_LED_GREEN,
+ PWM_CH_LED_RED,
PWM_CH_FAN,
- PWM_CH_KB_BL,
+ PWM_CH_KBLIGHT,
PWM_CH_COUNT,
};
-int board_accel_force_mode_mask(void);
+enum fan_channel {
+ FAN_CH_0,
+ FAN_CH_COUNT
+};
+
+enum temp_sensor_id {
+ TEMP_SENSOR_CPU,
+ TEMP_SENSOR_GPU,
+ TEMP_SENSOR_CHARGER,
+ TEMP_SENSOR_COUNT,
+};
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/goroh/build.mk b/board/goroh/build.mk
index 468d9ad365..4bc0561678 100644
--- a/board/goroh/build.mk
+++ b/board/goroh/build.mk
@@ -11,4 +11,8 @@ CHIP_FAMILY:=it8xxx2
CHIP_VARIANT:=it81202bx_1024
BASEBOARD:=goroh
-board-y+=battery.o board.o led.o
+board-y+=battery.o
+board-y+=board.o
+board-y+=fans.o
+board-y+=led.o
+board-y+=sensors.o
diff --git a/board/goroh/fans.c b/board/goroh/fans.c
new file mode 100644
index 0000000000..415eb9681d
--- /dev/null
+++ b/board/goroh/fans.c
@@ -0,0 +1,91 @@
+/* Copyright 2021 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.
+ */
+
+/* Physical fans. These are logically separate from pwm_channels. */
+
+#include "common.h"
+#include "compile_time_macros.h"
+#include "console.h"
+#include "fan.h"
+#include "hooks.h"
+#include "pwm.h"
+#include "pwm_chip.h"
+
+const struct fan_conf fan_conf_0 = {
+ .flags = FAN_USE_RPM_MODE,
+ .ch = PWM_CH_FAN,
+ .pgood_gpio = -1,
+ .enable_gpio = GPIO_EN_PP5000_FAN_X,
+};
+
+const struct fan_rpm fan_rpm_0 = {
+ .rpm_min = 2400,
+ .rpm_start = 2400,
+ .rpm_max = 5700,
+};
+
+const struct fan_t fans[] = {
+ [FAN_CH_0] = {
+ .conf = &fan_conf_0,
+ .rpm = &fan_rpm_0,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(fans) == CONFIG_FANS);
+/*
+ * PWM HW channelx binding tachometer channelx for fan control.
+ * Four tachometer input pins but two tachometer modules only,
+ * so always binding [TACH_CH_TACH0A | TACH_CH_TACH0B] and/or
+ * [TACH_CH_TACH1A | TACH_CH_TACH1B]
+ */
+const struct fan_tach_t fan_tach[] = {
+ [PWM_HW_CH_DCR0] = {
+ .ch_tach = TACH_CH_NULL,
+ .fan_p = -1,
+ .rpm_re = -1,
+ .s_duty = -1,
+ },
+ [PWM_HW_CH_DCR1] = {
+ .ch_tach = TACH_CH_NULL,
+ .fan_p = -1,
+ .rpm_re = -1,
+ .s_duty = -1,
+ },
+ [PWM_HW_CH_DCR2] = {
+ .ch_tach = TACH_CH_TACH0A,
+ .fan_p = 2,
+ .rpm_re = 50,
+ .s_duty = 30,
+ },
+ [PWM_HW_CH_DCR3] = {
+ .ch_tach = TACH_CH_NULL,
+ .fan_p = -1,
+ .rpm_re = -1,
+ .s_duty = -1,
+ },
+ [PWM_HW_CH_DCR4] = {
+ .ch_tach = TACH_CH_NULL,
+ .fan_p = -1,
+ .rpm_re = -1,
+ .s_duty = -1,
+ },
+ [PWM_HW_CH_DCR5] = {
+ .ch_tach = TACH_CH_NULL,
+ .fan_p = -1,
+ .rpm_re = -1,
+ .s_duty = -1,
+ },
+ [PWM_HW_CH_DCR6] = {
+ .ch_tach = TACH_CH_NULL,
+ .fan_p = -1,
+ .rpm_re = -1,
+ .s_duty = -1,
+ },
+ [PWM_HW_CH_DCR7] = {
+ .ch_tach = TACH_CH_NULL,
+ .fan_p = -1,
+ .rpm_re = -1,
+ .s_duty = -1,
+ },
+};
diff --git a/board/goroh/gpio.inc b/board/goroh/gpio.inc
index 503c506014..fe454d035e 100644
--- a/board/goroh/gpio.inc
+++ b/board/goroh/gpio.inc
@@ -22,6 +22,8 @@ GPIO_INT(AP_EC_WARM_RST_REQ, PIN(D, 3), GPIO_INT_RISING | GPIO_SEL_1P8V,
GPIO_INT(AP_EC_SHUTDOWN_REQ_L, PIN(F, 2),
GPIO_INT_BOTH | GPIO_PULL_DOWN | GPIO_SEL_1P8V,
chipset_reset_request_interrupt)
+GPIO_INT(AP_EC_WATCHDOG_L, PIN(C, 7), GPIO_INT_BOTH | GPIO_SEL_1P8V,
+ power_signal_interrupt)
GPIO_INT(PG_S5_PWR_OD, PIN(A, 6), GPIO_INT_BOTH,
power_signal_interrupt)
GPIO_INT(PG_VDD1_VDD2_OD, PIN(M, 6), GPIO_INT_BOTH | GPIO_SEL_1P8V,
@@ -36,8 +38,6 @@ GPIO_INT(PG_VDD_DDR_OD, PIN(J, 5), GPIO_INT_BOTH,
/* Sensor Interrupts */
GPIO_INT(BASE_IMU_INT_L, PIN(M, 2), GPIO_INT_FALLING | GPIO_SEL_1P8V,
bmi160_interrupt)
-GPIO_INT(LID_ACCEL_INT_L, PIN(G, 0), GPIO_INT_FALLING | GPIO_SEL_1P8V,
- lis2dw12_interrupt)
/* USB-C interrupts */
GPIO_INT(USB_C0_FAULT_ODL, PIN(D, 1), GPIO_INT_BOTH, ppc_interrupt)
@@ -59,7 +59,7 @@ GPIO_INT(SPI0_CS, PIN(M, 5), GPIO_INT_FALLING,
/* Power Sequencing Signals */
GPIO(EN_PP1800_S5, PIN(H, 0), GPIO_OUT_LOW)
-GPIO(EN_PP5000_S5, PIN(C, 6), GPIO_OUT_LOW)
+GPIO(EN_PP5000_S5, PIN(C, 6), GPIO_OUT_HIGH) /* default high for PPC init on start up. */
GPIO(EN_VDD_SOC, PIN(E, 1), GPIO_OUT_LOW)
GPIO(EN_VDD_MEDIA_ML, PIN(F, 1), GPIO_OUT_LOW)
GPIO(SYS_RST_ODL, PIN(B, 6), GPIO_ODR_LOW)
@@ -91,7 +91,6 @@ GPIO(USB_C0_SBU2_DC, PIN(H, 5), GPIO_OUT_LOW)
/* Misc Signals */
GPIO(EC_BATT_PRES_ODL, PIN(C, 0), GPIO_INPUT)
GPIO(ENTERING_RW, PIN(C, 5), GPIO_OUT_LOW) /* EC_ENTERING_RW */
-GPIO(FAN_SPEED_TACH_1, PIN(D, 6), GPIO_INPUT)
GPIO(EN_EC_ID_ODL, PIN(C, 3), GPIO_OUT_LOW)
GPIO(EN_PP5000_FAN_X, PIN(E, 3), GPIO_OUT_LOW)
GPIO(EN_PPVAR_KB_BL_X, PIN(H, 3), GPIO_OUT_LOW)
@@ -126,15 +125,16 @@ ALTERNATE(PIN_MASK(B, 0x03), 1, MODULE_UART, 0) /* EC to Servo */
/* PWM */
ALTERNATE(PIN_MASK(A, 0x0F), 1, MODULE_PWM, 0) /* PWM 0~3 */
+ALTERNATE(PIN_MASK(D, 0x40), 3, MODULE_PWM, GPIO_PULL_UP) /* TACH0A for FAN1 */
/* ADC */
-ALTERNATE(PIN_MASK(I, 0x6E), 0, MODULE_ADC, 0) /* ADC 1,2,3,5,6 */
+ALTERNATE(PIN_MASK(I, 0x2E), 0, MODULE_ADC, 0) /* ADC 1,2,3,5 */
/* SPI */
ALTERNATE(PIN_MASK(M, 0x33), 0, MODULE_SPI, 0) /* SPI */
-/* Unimplemented Pins */
-UNIMPLEMENTED(AP_EC_WATCHDOG_L)
+/* unused, configure as input pin */
+GPIO(LID_ACCEL_INT_L, PIN(G, 0), GPIO_INPUT | GPIO_SEL_1P8V)
/* *_ODL pin has external pullup so don't pull it down. */
diff --git a/board/goroh/led.c b/board/goroh/led.c
index 012b4d7320..63f00ef82e 100644
--- a/board/goroh/led.c
+++ b/board/goroh/led.c
@@ -4,39 +4,30 @@
*/
#include "ec_commands.h"
-#include "gpio.h"
#include "led_common.h"
-#include "led_onoff_states.h"
-#include "chipset.h"
-
-const int led_charge_lvl_1 = 5;
-const int led_charge_lvl_2 = 95;
-
-struct led_descriptor led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = {
- [STATE_CHARGING_LVL_1] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} },
- [STATE_CHARGING_LVL_2] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} },
- [STATE_CHARGING_FULL_CHARGE] = {{EC_LED_COLOR_WHITE, LED_INDEFINITE} },
- [STATE_DISCHARGE_S0] = {{LED_OFF, LED_INDEFINITE} },
- [STATE_DISCHARGE_S0_BAT_LOW] = {{EC_LED_COLOR_AMBER, 1 * LED_ONE_SEC},
- {LED_OFF, 3 * LED_ONE_SEC} },
- [STATE_DISCHARGE_S3] = {{LED_OFF, LED_INDEFINITE} },
- [STATE_DISCHARGE_S5] = {{LED_OFF, LED_INDEFINITE} },
- [STATE_BATTERY_ERROR] = {{EC_LED_COLOR_AMBER, 1 * LED_ONE_SEC},
- {LED_OFF, 1 * LED_ONE_SEC} },
- [STATE_FACTORY_TEST] = {{EC_LED_COLOR_WHITE, 2 * LED_ONE_SEC},
- {EC_LED_COLOR_AMBER, 2 * LED_ONE_SEC} },
-};
+#include "led_pwm.h"
+#include "pwm.h"
-const struct led_descriptor
- led_pwr_state_table[PWR_LED_NUM_STATES][LED_NUM_PHASES] = {
- [PWR_LED_STATE_ON] = {{EC_LED_COLOR_WHITE, LED_INDEFINITE} },
- [PWR_LED_STATE_SUSPEND_AC] = {{EC_LED_COLOR_WHITE, 1 * LED_ONE_SEC},
- {LED_OFF, 3 * LED_ONE_SEC} },
- [PWR_LED_STATE_SUSPEND_NO_AC] = {{EC_LED_COLOR_WHITE, 1 * LED_ONE_SEC},
- {LED_OFF, 3 * LED_ONE_SEC} },
- [PWR_LED_STATE_OFF] = {{LED_OFF, LED_INDEFINITE} },
+struct pwm_led_color_map led_color_map[EC_LED_COLOR_COUNT] = {
+ /* Green, Red */
+ [EC_LED_COLOR_RED] = { 0, 100 },
+ [EC_LED_COLOR_GREEN] = { 100, 0 },
+ [EC_LED_COLOR_BLUE] = { 0, 0 },
+ [EC_LED_COLOR_YELLOW] = { 0, 0 },
+ [EC_LED_COLOR_WHITE] = { 0, 0 },
+ [EC_LED_COLOR_AMBER] = { 0, 0 },
};
+struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = {
+ [PWM_LED0] = {
+ /* left port LEDs */
+ .ch0 = PWM_CH_LED_GREEN,
+ .ch1 = PWM_CH_LED_RED,
+ .ch2 = PWM_LED_NO_CHANNEL,
+ .enable = &pwm_enable,
+ .set_duty = &pwm_set_duty,
+ },
+};
const enum ec_led_id supported_led_ids[] = {
EC_LED_ID_BATTERY_LED,
@@ -45,19 +36,31 @@ const enum ec_led_id supported_led_ids[] = {
const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
-void led_set_color_battery(enum ec_led_colors color)
-{
-}
-
-void led_set_color_power(enum ec_led_colors color)
-{
-}
-
void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
{
+ if (led_id == EC_LED_ID_BATTERY_LED)
+ brightness_range[EC_LED_COLOR_RED] = 100;
+ else if (led_id == EC_LED_ID_POWER_LED)
+ brightness_range[EC_LED_COLOR_GREEN] = 100;
}
int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
{
+ enum pwm_led_id pwm_id;
+
+ /* Convert ec_led_id to pwm_led_id. */
+ if (led_id == EC_LED_ID_POWER_LED || led_id == EC_LED_ID_BATTERY_LED)
+ pwm_id = PWM_LED0;
+ else
+ return EC_ERROR_UNKNOWN;
+
+ if (brightness[EC_LED_COLOR_RED])
+ set_pwm_led_color(pwm_id, EC_LED_COLOR_RED);
+ else if (brightness[EC_LED_COLOR_GREEN])
+ set_pwm_led_color(pwm_id, EC_LED_COLOR_GREEN);
+ else
+ /* Otherwise, the "color" is "off". */
+ set_pwm_led_color(pwm_id, -1);
+
return EC_SUCCESS;
}
diff --git a/board/goroh/sensors.c b/board/goroh/sensors.c
new file mode 100644
index 0000000000..fe0a50b762
--- /dev/null
+++ b/board/goroh/sensors.c
@@ -0,0 +1,124 @@
+/* Copyright 2021 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.
+ */
+/* Goroh sensors configuration */
+
+#include "driver/accel_bma2x2.h"
+#include "driver/accelgyro_bmi_common.h"
+#include "driver/als_tcs3400.h"
+#include "driver/temp_sensor/thermistor.h"
+#include "lid_switch.h"
+#include "motion_sense.h"
+#include "spi.h"
+#include "thermal.h"
+#include "temp_sensor.h"
+
+static struct mutex g_base_mutex;
+static struct mutex g_lid_mutex;
+
+static struct bmi_drv_data_t g_bmi160_data;
+static struct accelgyro_saved_data_t g_bma253_data;
+
+struct motion_sensor_t motion_sensors[] = {
+ /*
+ * Note: bmi160: supports accelerometer and gyro sensor
+ * Requirement: accelerometer sensor must init before gyro sensor
+ * DO NOT change the order of the following table.
+ */
+ [BASE_ACCEL] = {
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi160_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
+ .rot_standard_ref = NULL, /* identity matrix */
+ .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */
+ .min_frequency = BMI_ACCEL_MIN_FREQ,
+ .max_frequency = BMI_ACCEL_MAX_FREQ,
+ .config = {
+ /* Sensor on for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on for angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ },
+ },
+ [BASE_GYRO] = {
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi160_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = NULL, /* identity matrix */
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .max_frequency = BMI_GYRO_MAX_FREQ,
+ },
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMA255,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &bma2x2_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_bma253_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = BMA2x2_I2C_ADDR1_FLAGS,
+ .rot_standard_ref = NULL, /* identity matrix */
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .min_frequency = BMA255_ACCEL_MIN_FREQ,
+ .max_frequency = BMA255_ACCEL_MAX_FREQ,
+ .default_range = 2, /* g, to support tablet mode */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+};
+const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+/* Temperature sensor configuration */
+const struct temp_sensor_t temp_sensors[] = {
+ [TEMP_SENSOR_CPU] = {
+ .name = "CPU",
+ .type = TEMP_SENSOR_TYPE_CPU,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_CPU,
+ },
+ [TEMP_SENSOR_GPU] = {
+ .name = "GPU",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_GPU,
+ },
+ [TEMP_SENSOR_CHARGER] = {
+ .name = "Charger",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_CHARGER,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
diff --git a/board/goroh/usbc_confg.c b/board/goroh/usbc_confg.c
new file mode 100644
index 0000000000..57a52da986
--- /dev/null
+++ b/board/goroh/usbc_confg.c
@@ -0,0 +1,33 @@
+/* Copyright 2021 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.
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "common.h"
+#include "compile_time_macros.h"
+#include "console.h"
+#include "driver/bc12/pi3usb9201_public.h"
+#include "driver/ppc/nx20p348x.h"
+#include "driver/ppc/syv682x_public.h"
+#include "driver/retimer/bb_retimer_public.h"
+#include "driver/tcpm/nct38xx.h"
+#include "driver/tcpm/ps8xxx_public.h"
+#include "driver/tcpm/tcpci.h"
+#include "ec_commands.h"
+#include "fw_config.h"
+#include "gpio.h"
+
+static void board_tcpc_init(void)
+{
+ /* Don't reset TCPCs after initial reset */
+ if (!system_jumped_late())
+ board_reset_pd_mcu();
+
+ /* Enable PPC interrupts. */
+ gpio_enable_interrupt(GPIO_USB_C0_FAULT_ODL);
+ gpio_enable_interrupt(GPIO_USB_C1_FAULT_ODL);
+}
+DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_CHIPSET);
diff --git a/board/kano/board.h b/board/kano/board.h
index c42ea9b7ab..6b65edf174 100644
--- a/board/kano/board.h
+++ b/board/kano/board.h
@@ -34,6 +34,9 @@
#define CONFIG_ACCELGYRO_ICM_COMM_I2C
#define CONFIG_ACCELGYRO_ICM426XX_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
+#define CONFIG_ACCELGYRO_BMI260
+#define CONFIG_ACCELGYRO_BMI260_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
/* Enable sensor fifo, must also define the _SIZE and _THRES */
#define CONFIG_ACCEL_FIFO
@@ -51,6 +54,7 @@
#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
#define CONFIG_ACCEL_KX022
+#define CONFIG_ACCEL_BMA4XX
#define CONFIG_ACCEL_INTERRUPTS
@@ -129,7 +133,7 @@
/* I2C Bus Configuration */
-#define I2C_PORT_SENSOR NPCX_I2C_PORT0_0
+#define I2C_PORT_ACCEL NPCX_I2C_PORT0_0
#define I2C_PORT_USB_C0_C2_TCPC NPCX_I2C_PORT1_0
#define I2C_PORT_USB_C1_TCPC NPCX_I2C_PORT4_1
diff --git a/board/kano/i2c.c b/board/kano/i2c.c
index bb55b13d0c..e779e119e3 100644
--- a/board/kano/i2c.c
+++ b/board/kano/i2c.c
@@ -13,7 +13,7 @@ const struct i2c_port_t i2c_ports[] = {
{
/* I2C0 */
.name = "sensor",
- .port = I2C_PORT_SENSOR,
+ .port = I2C_PORT_ACCEL,
.kbps = 400,
.scl = GPIO_EC_I2C_SENSOR_SCL,
.sda = GPIO_EC_I2C_SENSOR_SDA,
diff --git a/board/kano/sensors.c b/board/kano/sensors.c
index 9ad2ff8108..9a5812a9be 100644
--- a/board/kano/sensors.c
+++ b/board/kano/sensors.c
@@ -6,6 +6,9 @@
#include "common.h"
#include "accelgyro.h"
#include "adc_chip.h"
+#include "driver/accelgyro_bmi_common.h"
+#include "driver/accelgyro_bmi260.h"
+#include "driver/accel_bma422.h"
#include "driver/accelgyro_icm426xx.h"
#include "driver/accelgyro_icm_common.h"
#include "driver/accel_kionix.h"
@@ -45,6 +48,16 @@ K_MUTEX_DEFINE(g_lid_accel_mutex);
K_MUTEX_DEFINE(g_base_accel_mutex);
static struct kionix_accel_data g_kx022_data;
static struct icm_drv_data_t g_icm426xx_data;
+static struct bmi_drv_data_t g_bmi260_data;
+static struct accelgyro_saved_data_t g_bma422_data;
+
+enum base_accelgyro_type {
+ BASE_GYRO_NONE = 0,
+ BASE_GYRO_BMI260 = 1,
+ BASE_GYRO_ICM426XX = 2,
+};
+
+static enum base_accelgyro_type base_accelgyro_config;
/*
* TODO:(b/197200940): Verify lid and base orientation
@@ -61,6 +74,92 @@ static const mat33_fp_t base_standard_ref = {
{ 0, 0, FLOAT_TO_FP(1)}
};
+static const mat33_fp_t lid_bma422_standard_ref = {
+ { 0, FLOAT_TO_FP(-1), 0},
+ { FLOAT_TO_FP(-1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(-1)}
+};
+static const mat33_fp_t base_bmi260_standard_ref = {
+ { 0, FLOAT_TO_FP(-1), 0},
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
+static struct motion_sensor_t bmi260_base_accel = {
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI260,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi260_drv,
+ .mutex = &g_base_accel_mutex,
+ .drv_data = &g_bmi260_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = BMI260_ADDR0_FLAGS,
+ .rot_standard_ref = &base_bmi260_standard_ref,
+ .min_frequency = BMI_ACCEL_MIN_FREQ,
+ .max_frequency = BMI_ACCEL_MAX_FREQ,
+ .default_range = 4, /* g */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ },
+};
+
+static struct motion_sensor_t bmi260_base_gyro = {
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI260,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi260_drv,
+ .mutex = &g_base_accel_mutex,
+ .drv_data = &g_bmi260_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = BMI260_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_bmi260_standard_ref,
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .max_frequency = BMI_GYRO_MAX_FREQ,
+};
+
+static struct motion_sensor_t bma422_lid_accel = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMA422,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &bma4_accel_drv,
+ .mutex = &g_lid_accel_mutex,
+ .drv_data = &g_bma422_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = BMA4_I2C_ADDR_SECONDARY,
+ .rot_standard_ref = &lid_bma422_standard_ref,
+ .min_frequency = BMA4_ACCEL_MIN_FREQ,
+ .max_frequency = BMA4_ACCEL_MAX_FREQ,
+ .default_range = 2, /* g, enough for laptop. */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 12500 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 12500 | ROUND_UP_FLAG,
+ .ec_rate = 0,
+ },
+ },
+};
+
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
.name = "Lid Accel",
@@ -71,7 +170,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &kionix_accel_drv,
.mutex = &g_lid_accel_mutex,
.drv_data = &g_kx022_data,
- .port = I2C_PORT_SENSOR,
+ .port = I2C_PORT_ACCEL,
.i2c_spi_addr_flags = KX022_ADDR1_FLAGS,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
.rot_standard_ref = &lid_standard_ref, /* identity matrix */
@@ -101,7 +200,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv_data = &g_icm426xx_data,
.int_signal = GPIO_EC_IMU_INT_R_L,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
- .port = I2C_PORT_SENSOR,
+ .port = I2C_PORT_ACCEL,
.i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS,
.rot_standard_ref = &base_standard_ref,
.default_range = 4, /* g */
@@ -130,7 +229,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv_data = &g_icm426xx_data,
.int_signal = GPIO_EC_IMU_INT_R_L,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
- .port = I2C_PORT_SENSOR,
+ .port = I2C_PORT_ACCEL,
.i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS,
.default_range = 1000 | ROUND_UP_FLAG, /* dps */
.rot_standard_ref = &base_standard_ref,
@@ -140,6 +239,36 @@ struct motion_sensor_t motion_sensors[] = {
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+static void baseboard_sensors_detect(void)
+{
+ int ret, val;
+
+ if (base_accelgyro_config != BASE_GYRO_NONE)
+ return;
+
+ ret = i2c_read8(I2C_PORT_ACCEL, BMA4_I2C_ADDR_SECONDARY,
+ BMA4_CHIP_ID_ADDR, &val);
+ if (ret == 0 && val == BMA422_CHIP_ID) {
+ motion_sensors[LID_ACCEL] = bma422_lid_accel;
+ ccprints("LID_ACCEL is BMA422");
+ } else
+ ccprints("LID_ACCEL is KX022");
+
+ ret = bmi_read8(I2C_PORT_ACCEL, BMI260_ADDR0_FLAGS,
+ BMI260_CHIP_ID, &val);
+ if (ret == 0 && val == BMI260_CHIP_ID_MAJOR) {
+ motion_sensors[BASE_ACCEL] = bmi260_base_accel;
+ motion_sensors[BASE_GYRO] = bmi260_base_gyro;
+ base_accelgyro_config = BASE_GYRO_BMI260;
+ ccprints("BASE ACCEL is BMI260");
+ } else {
+ base_accelgyro_config = BASE_GYRO_ICM426XX;
+ ccprints("BASE ACCEL IS ICM426XX");
+ }
+}
+DECLARE_HOOK(HOOK_CHIPSET_STARTUP, baseboard_sensors_detect,
+ HOOK_PRIO_DEFAULT);
+
static void baseboard_sensors_init(void)
{
/* Enable gpio interrupt for base accelgyro sensor */
@@ -149,7 +278,12 @@ DECLARE_HOOK(HOOK_INIT, baseboard_sensors_init, HOOK_PRIO_INIT_I2C + 1);
void motion_interrupt(enum gpio_signal signal)
{
- icm426xx_interrupt(signal);
+ if (base_accelgyro_config == BASE_GYRO_NONE)
+ return;
+ if (base_accelgyro_config == BASE_GYRO_BMI260)
+ bmi260_interrupt(signal);
+ else
+ icm426xx_interrupt(signal);
}
/* Temperature sensor configuration */
diff --git a/board/primus/board.h b/board/primus/board.h
index 22ee215aca..5b87eb6477 100644
--- a/board/primus/board.h
+++ b/board/primus/board.h
@@ -131,6 +131,7 @@
#define CONFIG_BATTERY_LEVEL_NEAR_FULL 91
#define CONFIG_FANS FAN_CH_COUNT
+#define RPM_DEVIATION 1
/* Charger defines */
#define CONFIG_CHARGER_BQ25720
diff --git a/board/vell/board.c b/board/vell/board.c
index fd31401495..cb060442a2 100644
--- a/board/vell/board.c
+++ b/board/vell/board.c
@@ -33,11 +33,6 @@
#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
-__override void board_cbi_init(void)
-{
- config_usb_db_type();
-}
-
/* Called on AP S3 -> S0 transition */
static void board_chipset_resume(void)
{
diff --git a/board/vell/usbc_config.c b/board/vell/usbc_config.c
index 81c1a28959..ba50928dd2 100644
--- a/board/vell/usbc_config.c
+++ b/board/vell/usbc_config.c
@@ -250,17 +250,6 @@ int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state)
#endif /* CONFIG_CHARGE_RAMP_SW */
-void config_usb_db_type(void)
-{
- enum ec_cfg_usb_db_type db_type = ec_cfg_usb_db_type();
-
- /*
- * TODO(b/180434685): implement multiple DB types
- */
-
- CPRINTS("Configured USB DB type number is %d", db_type);
-}
-
__override int bb_retimer_power_enable(const struct usb_mux *me, bool enable)
{
enum ioex_signal rst_signal;
@@ -300,14 +289,12 @@ __override int bb_retimer_power_enable(const struct usb_mux *me, bool enable)
void board_reset_pd_mcu(void)
{
/*
- * TODO(b/179648104): figure out correct timing
+ * TODO(b/203371200): figure out correct timing
*/
gpio_set_level(GPIO_USB_C0_C2_TCPC_RST_ODL, 0);
- if (ec_cfg_usb_db_type() != DB_USB_ABSENT) {
- gpio_set_level(GPIO_USB_C1_RST_ODL, 0);
- gpio_set_level(GPIO_USB_C1_RT_RST_R_ODL, 0);
- }
+ gpio_set_level(GPIO_USB_C1_RST_ODL, 0);
+ gpio_set_level(GPIO_USB_C1_RT_RST_R_ODL, 0);
/*
* delay for power-on to reset-off and min. assertion time
@@ -316,10 +303,8 @@ void board_reset_pd_mcu(void)
msleep(20);
gpio_set_level(GPIO_USB_C0_C2_TCPC_RST_ODL, 1);
- if (ec_cfg_usb_db_type() != DB_USB_ABSENT) {
- gpio_set_level(GPIO_USB_C1_RST_ODL, 1);
- gpio_set_level(GPIO_USB_C1_RT_RST_R_ODL, 1);
- }
+ gpio_set_level(GPIO_USB_C1_RST_ODL, 1);
+ gpio_set_level(GPIO_USB_C1_RT_RST_R_ODL, 1);
/* wait for chips to come up */
@@ -357,11 +342,9 @@ static void board_tcpc_init(void)
gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_ODL);
gpio_enable_interrupt(GPIO_USB_C2_BC12_INT_ODL);
- if (ec_cfg_usb_db_type() != DB_USB_ABSENT) {
- gpio_enable_interrupt(GPIO_USB_C1_PPC_INT_ODL);
- gpio_enable_interrupt(GPIO_USB_C1_TCPC_INT_ODL);
- gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_ODL);
- }
+ gpio_enable_interrupt(GPIO_USB_C1_PPC_INT_ODL);
+ gpio_enable_interrupt(GPIO_USB_C1_TCPC_INT_ODL);
+ gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_ODL);
}
DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_CHIPSET);
@@ -372,8 +355,7 @@ uint16_t tcpc_get_alert_status(void)
if (gpio_get_level(GPIO_USB_C0_C2_TCPC_INT_ODL) == 0)
status |= PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_2;
- if ((ec_cfg_usb_db_type() != DB_USB_ABSENT) &&
- gpio_get_level(GPIO_USB_C1_TCPC_INT_ODL) == 0)
+ if (gpio_get_level(GPIO_USB_C1_TCPC_INT_ODL) == 0)
status |= PD_STATUS_TCPC_ALERT_1;
return status;
@@ -383,8 +365,7 @@ int ppc_get_alert_status(int port)
{
if (port == USBC_PORT_C0)
return gpio_get_level(GPIO_USB_C0_PPC_INT_ODL) == 0;
- else if ((port == USBC_PORT_C1) &&
- (ec_cfg_usb_db_type() != DB_USB_ABSENT))
+ else if (port == USBC_PORT_C1)
return gpio_get_level(GPIO_USB_C1_PPC_INT_ODL) == 0;
else if (port == USBC_PORT_C2)
return gpio_get_level(GPIO_USB_C2_PPC_INT_ODL) == 0;
@@ -398,8 +379,6 @@ void tcpc_alert_event(enum gpio_signal signal)
schedule_deferred_pd_interrupt(USBC_PORT_C0);
break;
case GPIO_USB_C1_TCPC_INT_ODL:
- if (ec_cfg_usb_db_type() == DB_USB_ABSENT)
- break;
schedule_deferred_pd_interrupt(USBC_PORT_C1);
break;
default:
@@ -414,8 +393,6 @@ void bc12_interrupt(enum gpio_signal signal)
task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_BC12);
break;
case GPIO_USB_C1_BC12_INT_ODL:
- if (ec_cfg_usb_db_type() == DB_USB_ABSENT)
- break;
task_set_event(TASK_ID_USB_CHG_P1, USB_CHG_EVENT_BC12);
break;
case GPIO_USB_C2_BC12_INT_ODL:
@@ -433,14 +410,7 @@ void ppc_interrupt(enum gpio_signal signal)
syv682x_interrupt(USBC_PORT_C0);
break;
case GPIO_USB_C1_PPC_INT_ODL:
- switch (ec_cfg_usb_db_type()) {
- case DB_USB_ABSENT:
- case DB_USB_ABSENT2:
- break;
- case DB_USB3_PS8815:
- nx20p348x_interrupt(USBC_PORT_C1);
- break;
- }
+ nx20p348x_interrupt(USBC_PORT_C1);
break;
case GPIO_USB_C2_PPC_INT_ODL:
syv682x_interrupt(USBC_PORT_C2);
diff --git a/board/vell/usbc_config.h b/board/vell/usbc_config.h
index 5d08a446fb..f21e2c17dc 100644
--- a/board/vell/usbc_config.h
+++ b/board/vell/usbc_config.h
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* Brya board-specific USB-C configuration */
+/* Vell board-specific USB-C configuration */
#ifndef __CROS_EC_USBC_CONFIG_H
#define __CROS_EC_USBC_CONFIG_H
@@ -17,6 +17,4 @@ enum usbc_port {
USBC_PORT_COUNT
};
-void config_usb_db_type(void);
-
#endif /* __CROS_EC_USBC_CONFIG_H */
diff --git a/board/volteer/board.h b/board/volteer/board.h
index 6a186bd894..2d941549c5 100644
--- a/board/volteer/board.h
+++ b/board/volteer/board.h
@@ -11,14 +11,6 @@
/* Baseboard features */
#include "baseboard.h"
-/*
- * Create an EC build that requires AP-driven mode entry to facilitate debugging
- * b/177105656.
- */
-#ifdef BOARD_VOLTEER_APMODEENTRY
-#define CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY
-#endif
-
#ifdef BOARD_VOLTEER_NPCX797FC
/*
* The RAM and flash size combination on the the NPCX797FC does not leave
diff --git a/board/volteer_apmodeentry b/board/volteer_apmodeentry
deleted file mode 120000
index f2f3e1d253..0000000000
--- a/board/volteer_apmodeentry
+++ /dev/null
@@ -1 +0,0 @@
-volteer \ No newline at end of file
diff --git a/chip/npcx/build.mk b/chip/npcx/build.mk
index 1de37f6b0a..3a41cfbd53 100644
--- a/chip/npcx/build.mk
+++ b/chip/npcx/build.mk
@@ -11,6 +11,9 @@ CORE:=cortex-m
# Allow the full Cortex-M4 instruction set
CFLAGS_CPU+=-march=armv7e-m -mcpu=cortex-m4
+# Disable overlapping section warning that linker emits due to NPCX_RO_HEADER.
+LDFLAGS_EXTRA+=-Wl,--no-check-sections
+
# Assign default CHIP_FAMILY as npcx5 for old boards used npcx5 series
ifeq ($(CHIP_FAMILY),)
CHIP_FAMILY:=npcx5
diff --git a/common/uart_printf.c b/common/uart_printf.c
index ae6f79bf79..198d076971 100644
--- a/common/uart_printf.c
+++ b/common/uart_printf.c
@@ -12,11 +12,9 @@
static int __tx_char(void *context, int c)
{
/*
- * Translate '\n' to '\r\n', bypass on Zephyr because printk also
- * does this translation.
+ * Translate '\n' to '\r\n'.
*/
- if (!IS_ENABLED(CONFIG_ZEPHYR) && c == '\n' &&
- uart_tx_char_raw(context, '\r'))
+ if (c == '\n' && uart_tx_char_raw(context, '\r'))
return 1;
return uart_tx_char_raw(context, c);
}
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index b8e3fc712b..3fa9528699 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -700,9 +700,11 @@ __maybe_unused static void tc_enable_try_src(int en)
}
/*
- * Exit all modes due to a detach event
+ * Exit all modes due to a detach event or hard reset
+ *
* Note: this skips the ExitMode VDM steps in the PE because it is assumed the
- * partner is not present to receive them, and the PE will no longer be running.
+ * partner is not present to receive them, and the PE will no longer be running,
+ * or we've forced an abrupt mode exit through a hard reset.
*/
static void tc_set_modes_exit(int port)
{
@@ -1304,6 +1306,13 @@ static bool tc_perform_src_hard_reset(int port)
/* Set role to DFP */
tc_set_data_role(port, PD_ROLE_DFP);
+ /*
+ * USB PD Rev 3.0 Ver 2.0 6.8.3.2: "A Hard Reset Shall cause
+ * all Active Modes to be exited by both Port Partners and any
+ * Cable Plugs"
+ */
+ tc_set_modes_exit(port);
+
tc[port].ps_reset_state = PS_STATE1;
pd_timer_enable(port, TC_TIMER_TIMEOUT, PD_T_SRC_RECOVER);
return false;
@@ -1349,6 +1358,13 @@ static bool tc_perform_snk_hard_reset(int port)
tc_set_data_role(port, PD_ROLE_UFP);
/*
+ * USB PD Rev 3.0 Ver 2.0 6.8.3.2: "A Hard Reset Shall cause
+ * all Active Modes to be exited by both Port Partners and any
+ * Cable Plugs"
+ */
+ tc_set_modes_exit(port);
+
+ /*
* When VCONN is supported, the Hard Reset Shall cause
* the Port with the Rd resistor asserted to turn off
* VCONN.
diff --git a/core/cortex-m0/ec.lds.S b/core/cortex-m0/ec.lds.S
index a04b92f5ff..ce67760cf2 100644
--- a/core/cortex-m0/ec.lds.S
+++ b/core/cortex-m0/ec.lds.S
@@ -263,7 +263,7 @@ SECTIONS
. = ALIGN(8);
*(.bss.system_stack)
/* Rest of .bss takes care of its own alignment */
- *(.bss)
+ *(.bss*)
/*
* Reserve space for deferred function firing times.
@@ -284,7 +284,7 @@ SECTIONS
. = ALIGN(4);
__data_start = .;
*(.data.tasks)
- *(.data)
+ *(.data*)
. = ALIGN(4);
*(.iram.text)
. = ALIGN(4);
diff --git a/docs/zephyr_build.md b/docs/zephyr_build.md
index 1ca7030ed0..60a9e1d97e 100644
--- a/docs/zephyr_build.md
+++ b/docs/zephyr_build.md
@@ -132,7 +132,7 @@ zmake configure -B /tmp/z/vol zephyr/projects/volteer/volteer/ -t zephyr
```
If you are building for posix-ec, change the default toolchain to host to make
-it use the native system one instead of llvm. Make sure to start with a clean
+it use the system toolchain instead of llvm. Make sure to start with a clean
build directory if zmake returns any build error:
```bash
diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c
index 913e51d215..d3aeb354af 100644
--- a/driver/charger/bq25710.c
+++ b/driver/charger/bq25710.c
@@ -38,8 +38,20 @@
UINT16_MAX)
#endif
-#ifndef CONFIG_BQ25720_VSYS_UVP_CUSTOM
-#define CONFIG_BQ25720_VSYS_UVP 0
+#ifndef CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_CUSTOM
+#define CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_MV 0
+#endif
+
+#ifndef CONFIG_CHARGER_BQ25720_VSYS_UVP_CUSTOM
+#define CONFIG_CHARGER_BQ25720_VSYS_UVP 0
+#endif
+
+#ifndef CONFIG_CHARGER_BQ25720_IDCHG_DEG2_CUSTOM
+#define CONFIG_CHARGER_BQ25720_IDCHG_DEG2 1
+#endif
+
+#ifndef CONFIG_CHARGER_BQ25720_IDCHG_TH2_CUSTOM
+#define CONFIG_CHARGER_BQ25720_IDCHG_TH2 1
#endif
/*
@@ -58,6 +70,10 @@
CHARGE_OPTION_3, \
_field, _v, (_x))
+#define SET_CO3_BY_NAME(_field, _c, _x) SET_BQ_FIELD_BY_NAME(BQ257X0, \
+ CHARGE_OPTION_3, \
+ _field, _c, (_x))
+
#define SET_CO4(_field, _v, _x) SET_BQ_FIELD(BQ25720, \
CHARGE_OPTION_4, \
_field, _v, (_x))
@@ -142,8 +158,17 @@ static inline enum ec_error_list raw_read16(int chgnum, int offset, int *value)
static inline int min_system_voltage_to_reg(int voltage_mv)
{
- return (voltage_mv / BQ25710_MIN_SYSTEM_VOLTAGE_STEP_MV) <<
- BQ25710_MIN_SYSTEM_VOLTAGE_SHIFT;
+ int steps;
+ int reg;
+
+ if (IS_ENABLED(CONFIG_CHARGER_BQ25720)) {
+ steps = voltage_mv / BQ25720_VSYS_MIN_VOLTAGE_STEP_MV;
+ reg = SET_BQ_FIELD(BQ25720, VSYS_MIN, VOLTAGE, steps, 0);
+ } else {
+ steps = voltage_mv / BQ25710_MIN_SYSTEM_VOLTAGE_STEP_MV;
+ reg = SET_BQ_FIELD(BQ25710, MIN_SYSTEM, VOLTAGE, steps, 0);
+ }
+ return reg;
}
static inline enum ec_error_list raw_write16(int chgnum, int offset, int value)
@@ -397,11 +422,7 @@ static int bq257x0_init_charge_option_3(int chgnum)
if (rv)
return rv;
- /*
- * The bq25720 defaults to 15 A while the bq25710
- * defaults to 10A. Set the bq25720 to 10A as well.
- */
- reg = SET_CO3(IL_AVG, BQ25720_CHARGE_OPTION_3_IL_AVG__10A, reg);
+ reg = SET_CO3_BY_NAME(IL_AVG, 10A, reg);
return raw_write16(chgnum, BQ25710_REG_CHARGE_OPTION_3, reg);
}
@@ -414,15 +435,24 @@ static int bq257x0_init_charge_option_4(int chgnum)
if (!IS_ENABLED(CONFIG_CHARGER_BQ25720))
return EC_SUCCESS;
- if (!IS_ENABLED(CONFIG_BQ25720_VSYS_UVP_CUSTOM))
+ if (!IS_ENABLED(CONFIG_CHARGER_BQ25720_VSYS_UVP_CUSTOM) &&
+ !IS_ENABLED(CONFIG_CHARGER_BQ25720_IDCHG_DEG2_CUSTOM) &&
+ !IS_ENABLED(CONFIG_CHARGER_BQ25720_IDCHG_TH2_CUSTOM))
return EC_SUCCESS;
rv = raw_read16(chgnum, BQ25720_REG_CHARGE_OPTION_4, &reg);
if (rv)
return rv;
- if (IS_ENABLED(CONFIG_BQ25720_VSYS_UVP_CUSTOM))
- reg = SET_CO4(VSYS_UVP, CONFIG_BQ25720_VSYS_UVP, reg);
+ if (IS_ENABLED(CONFIG_CHARGER_BQ25720_VSYS_UVP_CUSTOM))
+ reg = SET_CO4(VSYS_UVP, CONFIG_CHARGER_BQ25720_VSYS_UVP, reg);
+
+ if (IS_ENABLED(CONFIG_CHARGER_BQ25720_IDCHG_DEG2_CUSTOM))
+ reg = SET_CO4(IDCHG_DEG2, CONFIG_CHARGER_BQ25720_IDCHG_DEG2,
+ reg);
+
+ if (IS_ENABLED(CONFIG_CHARGER_BQ25720_IDCHG_TH2_CUSTOM))
+ reg = SET_CO4(IDCHG_TH2, CONFIG_CHARGER_BQ25720_IDCHG_TH2, reg);
return raw_write16(chgnum, BQ25720_REG_CHARGE_OPTION_4, reg);
}
@@ -461,20 +491,31 @@ static void bq25710_init(int chgnum)
int rv;
/*
- * Reset registers to their default settings. There is no reset pin for
- * this chip so without a full power cycle, some registers may not be at
- * their default values. Note, need to save the POR value of
- * MIN_SYSTEM_VOLTAGE register prior to setting the reset so that the
- * correct value is preserved. In order to have the correct value read,
- * the bq25710 must not be in low power mode, otherwise the VDDA rail
- * may not be powered if AC is not connected. Note, this reset is only
- * required when running out of RO and not following sysjump to RW.
+ * Reset registers to their default settings. There is no reset
+ * pin for this chip so without a full power cycle, some
+ * registers may not be at their default values. Note, need to
+ * save the POR value of MIN_SYSTEM_VOLTAGE/VSYS_MIN register
+ * prior to setting the reset so that the correct value is
+ * preserved. In order to have the correct value read, the
+ * bq25710 must not be in low power mode, otherwise the VDDA
+ * rail may not be powered if AC is not connected. Note, this
+ * reset is only required when running out of RO and not
+ * following sysjump to RW.
*/
if (!system_jumped_late()) {
rv = bq25710_set_low_power_mode(chgnum, 0);
/* Allow enough time for VDDA to be powered */
msleep(BQ25710_VDDA_STARTUP_DELAY_MSEC);
- rv |= raw_read16(chgnum, BQ25710_REG_MIN_SYSTEM_VOLTAGE, &vsys);
+
+ if (IS_ENABLED(
+ CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_CUSTOM)) {
+ vsys = min_system_voltage_to_reg(
+ CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_MV);
+ } else {
+ rv |= raw_read16(chgnum,
+ BQ25710_REG_MIN_SYSTEM_VOLTAGE, &vsys);
+ }
+
rv |= raw_read16(chgnum, BQ25710_REG_CHARGE_OPTION_3, &reg);
if (!rv) {
reg = SET_BQ_FIELD(BQ257X0, CHARGE_OPTION_3, RESET_REG,
diff --git a/driver/charger/bq25710.h b/driver/charger/bq25710.h
index 3357a3fc4f..603f3bf140 100644
--- a/driver/charger/bq25710.h
+++ b/driver/charger/bq25710.h
@@ -60,14 +60,8 @@
#endif
/* Min System Voltage Register */
-#if defined(CONFIG_CHARGER_BQ25720)
#define BQ25710_MIN_SYSTEM_VOLTAGE_STEP_MV 100
-#elif defined(CONFIG_CHARGER_BQ25710)
-#define BQ25710_MIN_SYSTEM_VOLTAGE_STEP_MV 256
-#else
-#error Only the BQ25720 and BQ25710 are supported by bq25710 driver.
-#endif
-#define BQ25710_MIN_SYSTEM_VOLTAGE_SHIFT 8
+#define BQ25720_VSYS_MIN_VOLTAGE_STEP_MV 256
extern const struct charger_drv bq25710_drv;
diff --git a/driver/charger/bq257x0_regs.h b/driver/charger/bq257x0_regs.h
index 5a8b1fdd96..0df033f535 100644
--- a/driver/charger/bq257x0_regs.h
+++ b/driver/charger/bq257x0_regs.h
@@ -99,7 +99,7 @@
#define BQ257X0_CHARGE_OPTION_3_IL_AVG_SHIFT 3
#define BQ257X0_CHARGE_OPTION_3_IL_AVG_BITS 2
-#define BQ25720_CHARGE_OPTION_3_IL_AVG__10A 1
+#define BQ257X0_CHARGE_OPTION_3_IL_AVG__10A 1
/*
* ChargeOption4 Register (0x36)
@@ -202,10 +202,18 @@
/*
* ADCVBUS/PSYS Register (0x23)
*/
-#define BQ257X0_ADC_VBUS_PSYS_VBUS_SHIFT 8
-#define BQ257X0_ADC_VBUS_PSYS_VBUS_BITS 8
-#define BQ257X0_ADC_VBUS_PSYS_PSYS_SHIFT 0
-#define BQ257X0_ADC_VBUS_PSYS_PSYS_BITS 8
+#define BQ257X0_ADC_VBUS_PSYS_VBUS_SHIFT 8
+#define BQ257X0_ADC_VBUS_PSYS_VBUS_BITS 8
+#define BQ257X0_ADC_VBUS_PSYS_PSYS_SHIFT 0
+#define BQ257X0_ADC_VBUS_PSYS_PSYS_BITS 8
+
+/*
+ * VSYS_MIN Register (0x3e)
+ */
+#define BQ25710_MIN_SYSTEM_VOLTAGE_SHIFT 8
+#define BQ25710_MIN_SYSTEM_VOLTAGE_BITS 6
+#define BQ25720_VSYS_MIN_VOLTAGE_SHIFT 8
+#define BQ25720_VSYS_MIN_VOLTAGE_BITS 8
/*
* BQ257x0 register field accessor macros.
diff --git a/driver/usb_mux/virtual.c b/driver/usb_mux/virtual.c
index dbece4faf9..4388bb485a 100644
--- a/driver/usb_mux/virtual.c
+++ b/driver/usb_mux/virtual.c
@@ -81,10 +81,17 @@ static int virtual_set_mux(const struct usb_mux *me, mux_state_t mux_state,
bool *ack_required)
{
int port = me->usb_port;
+ mux_state_t new_mux_state;
- /* Current USB & DP mux status + existing HPD related mux status */
- mux_state_t new_mux_state = (mux_state & ~USB_PD_MUX_HPD_STATE) |
- (virtual_mux_state[port] & USB_PD_MUX_HPD_STATE);
+ /*
+ * Current USB & DP mux status + existing HPD related mux status if DP
+ * is still active. Otherwise, don't preserve HPD state.
+ */
+ if (mux_state & USB_PD_MUX_DP_ENABLED)
+ new_mux_state = (mux_state & ~USB_PD_MUX_HPD_STATE) |
+ (virtual_mux_state[port] & USB_PD_MUX_HPD_STATE);
+ else
+ new_mux_state = mux_state;
virtual_mux_update_state(port, new_mux_state, ack_required);
diff --git a/include/config.h b/include/config.h
index 0f1de0954f..7fc59ac4a1 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1061,6 +1061,28 @@
*/
#undef CONFIG_CHARGER_BQ25720_VSYS_UVP
+/* Enable if CONFIG_CHARGER_BQ25720_IDCHG_DEG2 should be applied */
+#undef CONFIG_CHARGER_BQ25720_IDCHG_DEG2_CUSTOM
+
+/*
+ * This config option is used to set the 2nd battery discharge current
+ * limit (IDCHG_TH2) deglitch time (IDCHG_DEG2). This is a 2 bit field
+ * with default value 1 (1.6 ms). The encoded value ranges from 100 us
+ * to 12 ms.
+ */
+#undef CONFIG_CHARGER_BQ25720_IDCHG_DEG2
+
+/* Enable if CONFIG_CHARGER_BQ25720_IDCHG_TH2 should be applied */
+#undef CONFIG_CHARGER_BQ25720_IDCHG_TH2_CUSTOM
+
+/*
+ * This config option is used to set the charger's 2nd battery discharge
+ * current limit (IDCHG_TH2) as a percentage of IDCHG_TH1. This is a 3
+ * bit field with default value 1 (150%). The encoded value ranges from
+ * 125% to 400%.
+ */
+#undef CONFIG_CHARGER_BQ25720_IDCHG_TH2
+
/* Value of the bq25710 charge sense resistor, in mOhms */
#undef CONFIG_CHARGER_BQ25710_SENSE_RESISTOR
@@ -1128,6 +1150,19 @@
*/
#undef CONFIG_CHARGER_BQ25710_PP_ACOK
+/* Enable if CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_MV should be applied */
+#undef CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_CUSTOM
+
+/*
+ * This config option sets the minimum system voltage in
+ * milli-volts. The bq25710 uses 6 bits of resolution and can be
+ * configured from 1.024 V to 16.128 V in 256 mV increments. The bq25720
+ * uses 8 bits of resolution and can be set from 1.0 V to 19.2 V in 100
+ * mV increments. The default value depends on configured number of
+ * battery cells connected in series using the CELL_BATPRESZ strap.
+ */
+#undef CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_MV
+
/*
* Board specific maximum input current limit, in mA.
*/
diff --git a/include/power/falconlite.h b/include/power/falconlite.h
index a2ad54bdd1..3c0baeff66 100644
--- a/include/power/falconlite.h
+++ b/include/power/falconlite.h
@@ -9,6 +9,7 @@
enum power_signal_falconlite {
FCL_AP_WARM_RST_REQ,
FCL_AP_SHUTDOWN_REQ,
+ FCL_AP_WATCHDOG,
FCL_PG_S5,
FCL_PG_VDD1_VDD2,
FCL_PG_VDD_MEDIA_ML,
diff --git a/power/falconlite.c b/power/falconlite.c
index 087b952e19..d2f8e5952a 100644
--- a/power/falconlite.c
+++ b/power/falconlite.c
@@ -61,6 +61,11 @@ const struct power_signal_info power_signal_list[] = {
POWER_SIGNAL_ACTIVE_LOW,
"AP_SHUTDOWN_REQ"
},
+ [FCL_AP_WATCHDOG] = {
+ GPIO_AP_EC_WATCHDOG_L,
+ POWER_SIGNAL_ACTIVE_LOW,
+ "AP_WDT"
+ },
[FCL_PG_S5] = {
GPIO_PG_S5_PWR_OD,
POWER_SIGNAL_ACTIVE_HIGH,
@@ -229,9 +234,11 @@ void chipset_reset_request_interrupt(enum gpio_signal signal)
* When AP_SHUTDOWN_REQ_L is asserted, we have to check if
* there is a AP_EC_WARM_RST_REQ interrupt prior to this one,
* and that would be a reboot request, rather than a
- * shutdown.
+ * shutdown. In the meantime, the WDT should not be asserted,
+ * or this is a WDT reset, which will be handled by AP.
*/
- if (!gpio_get_level(signal) && !want_reboot) {
+ if (gpio_get_level(GPIO_AP_EC_WATCHDOG_L) &&
+ !gpio_get_level(signal) && !want_reboot) {
CPRINTS("AP wants shutdown");
ap_shutdown = 1;
}
diff --git a/zephyr/Kconfig.battery b/zephyr/Kconfig.battery
index 24c3710170..16664d20cf 100644
--- a/zephyr/Kconfig.battery
+++ b/zephyr/Kconfig.battery
@@ -381,6 +381,62 @@ config PLATFORM_EC_CHARGER_BQ25720_VSYS_UVP
encoded is (0.8 * <value> + 2.4), allowing a threshold in the
range of 2.4 V to 8.0 V to be specified.
+config PLATFORM_EC_CHARGER_BQ25720_IDCHG_DEG2_CUSTOM
+ bool "IDCHG_TH2 deglitch time override"
+ depends on PLATFORM_EC_CHARGER_BQ25720
+ help
+ Enable customizing the charger's 2nd battery discharge current
+ limit (IDCHG_TH2) deglitch time (IDCHG_DEG2).
+
+config PLATFORM_EC_CHARGER_BQ25720_IDCHG_DEG2
+ int "IDCHG_TH2 deglitch time"
+ range 0 3
+ default 1
+ depends on PLATFORM_EC_CHARGER_BQ25720_IDCHG_DEG2_CUSTOM
+ help
+ Sets the 2nd battery discharge current limit (IDCHG_TH2)
+ deglitch time (IDCHG_DEG2). This is a 2 bit field with default
+ value 1 (1.6 ms). The encoded value ranges from 100 us to 12
+ ms.
+
+config PLATFORM_EC_CHARGER_BQ25720_IDCHG_TH2_CUSTOM
+ bool "IDCHG_TH2 override"
+ depends on PLATFORM_EC_CHARGER_BQ25720
+ help
+ Enable customizing the charger's 2nd battery discharge current
+ limit (IDCHG_TH2).
+
+config PLATFORM_EC_CHARGER_BQ25720_IDCHG_TH2
+ int "IDCHG threshold 2"
+ range 0 7
+ default 1
+ depends on PLATFORM_EC_CHARGER_BQ25720_IDCHG_TH2_CUSTOM
+ help
+ Sets the charger's 2nd battery discharge current limit
+ (IDCHG_TH2) as a percentage of IDCHG_TH1. This is a 3 bit
+ field with default value 1 (150%). The encoded value ranges
+ from 125% to 400%.
+
+config PLATFORM_EC_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_CUSTOM
+ bool "Enable minimum system voltage override"
+ depends on PLATFORM_EC_CHARGER_BQ25710 || PLATFORM_EC_CHARGER_BQ25720
+ help
+ Enable customizing the charger's 2nd battery discharge current
+ limit (IDCHG_TH2).
+
+config PLATFORM_EC_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_MV
+ int "Minimum system voltage in milli-volts"
+ default 0
+ depends on PLATFORM_EC_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_CUSTOM
+ help
+ Sets the minimum system voltage in milli-volts. The bq25710
+ uses 6 bits of resolution and can be configured from 1.024 V
+ to 16.128 V in 256 mV increments. The bq25720 uses 8 bits of
+ resolution and can be set from 1.0 V to 19.2 V in 100 mV
+ increments. The default value depends on configured number of
+ battery cells connected in series using the CELL_BATPRESZ
+ strap.
+
config PLATFORM_EC_CHARGER_MAINTAIN_VBAT
bool "Maintain VBAT voltage regardless of AC state"
help
diff --git a/zephyr/Kconfig.console b/zephyr/Kconfig.console
index 602a2ea26a..809c03c1e0 100644
--- a/zephyr/Kconfig.console
+++ b/zephyr/Kconfig.console
@@ -21,9 +21,11 @@ config PLATFORM_EC_CONSOLE_CHANNEL
Boards may #undef this to reduce image size.
-# Adjusted to the longest print message from the timer_info command
+# Adjusted to the account for the build_info[] string (about 160 bytes) plus
+# the image type (about 16 bytes).
+# printed by the banner.
config SHELL_PRINTF_BUFF_SIZE
- default 130
+ default 180
# Some boards may need to increase the size, depending on the amount of output
config SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE
diff --git a/zephyr/emul/CMakeLists.txt b/zephyr/emul/CMakeLists.txt
index 95eb1dd483..030ae7cc51 100644
--- a/zephyr/emul/CMakeLists.txt
+++ b/zephyr/emul/CMakeLists.txt
@@ -20,3 +20,4 @@ zephyr_library_sources_ifdef(CONFIG_EMUL_CLOCK_CONTROL emul_clock_control.c)
zephyr_library_sources_ifdef(CONFIG_EMUL_TCPCI emul_tcpci.c)
zephyr_library_sources_ifdef(CONFIG_EMUL_SN5S330 emul_sn5s330.c)
zephyr_library_sources_ifdef(CONFIG_EMUL_PS8XXX emul_ps8xxx.c)
+zephyr_library_sources_ifdef(CONFIG_EMUL_CHARGER emul_charger.c)
diff --git a/zephyr/emul/Kconfig.tcpci b/zephyr/emul/Kconfig.tcpci
index 88a3fe1044..fc4b1bcda4 100644
--- a/zephyr/emul/Kconfig.tcpci
+++ b/zephyr/emul/Kconfig.tcpci
@@ -28,4 +28,11 @@ config EMUL_PS8XXX
for TCPCI emulator. PS8XXX specific API is available in
zephyr/include/emul/emul_tcpci.h
+config EMUL_CHARGER
+ bool "USB-C charger emulator"
+ help
+ Enable USB-C charger emulator which may be attached to TCPCI emulator.
+ API of charger emulator is available in
+ zephyr/include/emul/emul_charger.h
+
endif # EMUL_TCPCI
diff --git a/zephyr/emul/emul_charger.c b/zephyr/emul/emul_charger.c
new file mode 100644
index 0000000000..d584ab882b
--- /dev/null
+++ b/zephyr/emul/emul_charger.c
@@ -0,0 +1,355 @@
+/* Copyright 2021 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.
+ */
+
+#include <logging/log.h>
+LOG_MODULE_REGISTER(charger_emul, CONFIG_TCPCI_EMUL_LOG_LEVEL);
+
+#include <zephyr.h>
+
+#include "common.h"
+#include "emul/emul_charger.h"
+#include "emul/emul_tcpci.h"
+#include "usb_pd.h"
+
+/** Structure of message used by USB-C charger emulator */
+struct charger_emul_msg {
+ /** Reserved for k_fifo_* usage */
+ void *fifo_reserved;
+ /** TCPCI emulator message */
+ struct tcpci_emul_msg msg;
+ /** Time when message should be sent if message is delayed */
+ uint64_t time;
+};
+
+/**
+ * @brief Allocate message
+ *
+ * @param size Size of message buffer
+ *
+ * @return Pointer to new message on success
+ * @return NULL on error
+ */
+static struct charger_emul_msg *charger_emul_alloc_msg(size_t size)
+{
+ struct charger_emul_msg *new_msg;
+
+ new_msg = k_malloc(sizeof(struct charger_emul_msg));
+ if (new_msg == NULL) {
+ return NULL;
+ }
+
+ new_msg->msg.buf = k_malloc(size);
+ if (new_msg->msg.buf == NULL) {
+ k_free(new_msg);
+ return NULL;
+ }
+
+ /* TCPCI message size count include type byte */
+ new_msg->msg.cnt = size + 1;
+
+ return new_msg;
+}
+
+/**
+ * @brief Free message's memory
+ *
+ * @param msg Pointer to message
+ */
+static void charger_emul_free_msg(struct charger_emul_msg *msg)
+{
+ k_free(msg->msg.buf);
+ k_free(msg);
+}
+
+/**
+ * @brief Set header of the message
+ *
+ * @param data Pointer to USB-C charger emulator
+ * @param msg Pointer to message
+ * @param type Type of message
+ * @param cnt Number of data objects
+ */
+static void charger_emul_set_header(struct charger_emul_data *data,
+ struct charger_emul_msg *msg,
+ int type, int cnt)
+{
+ /* Header msg id has only 3 bits and wraps around after 8 messages */
+ uint16_t msg_id = data->msg_id & 0x7;
+ uint16_t header = PD_HEADER(type, PD_ROLE_SOURCE, PD_ROLE_UFP, msg_id,
+ cnt, PD_REV20, 0 /* ext */);
+ data->msg_id++;
+
+ msg->msg.buf[1] = (header >> 8) & 0xff;
+ msg->msg.buf[0] = header & 0xff;
+}
+
+/**
+ * @brief Work function which sends delayed messages
+ *
+ * @param work Pointer to work structure
+ */
+static void charger_emul_delayed_send(struct k_work *work)
+{
+ struct k_work_delayable *kwd = k_work_delayable_from_work(work);
+ struct charger_emul_data *data = CONTAINER_OF(kwd,
+ struct charger_emul_data,
+ delayed_send);
+ struct charger_emul_msg *msg;
+ uint64_t now;
+ int ec;
+
+ while (!k_fifo_is_empty(&data->to_send)) {
+ /*
+ * It is safe to not check msg == NULL, because this thread is
+ * the only one consumer
+ */
+ msg = k_fifo_peek_head(&data->to_send);
+
+ now = k_uptime_get();
+ if (now >= msg->time) {
+ k_fifo_get(&data->to_send, K_FOREVER);
+ ec = tcpci_emul_add_rx_msg(data->tcpci_emul, &msg->msg,
+ true /* send alert */);
+ if (ec) {
+ charger_emul_free_msg(msg);
+ }
+ } else {
+ k_work_reschedule(kwd, K_MSEC(msg->time - now));
+ break;
+ }
+ }
+}
+
+/**
+ * @brief Send message to TCPCI emulator or schedule message
+ *
+ * @param data Pointer to USB-C charger emulator
+ * @param msg Pointer to message to send
+ * @param delay Optional delay
+ *
+ * @return 0 on success
+ * @return -EINVAL on TCPCI emulator add RX message error
+ */
+static int charger_emul_send_msg(struct charger_emul_data *data,
+ struct charger_emul_msg *msg, uint64_t delay)
+{
+ uint64_t now;
+ int ec;
+
+ if (delay == 0) {
+ ec = tcpci_emul_add_rx_msg(data->tcpci_emul, &msg->msg, true);
+ if (ec) {
+ charger_emul_free_msg(msg);
+ }
+
+ return ec;
+ }
+
+ now = k_uptime_get();
+ msg->time = now + delay;
+ k_fifo_put(&data->to_send, msg);
+ /*
+ * This will change execution time of delayed_send only if it is not
+ * already scheduled
+ */
+ k_work_schedule(&data->delayed_send, K_MSEC(delay));
+
+ return 0;
+}
+
+/**
+ * @brief Send capability message which for now is hardcoded
+ *
+ * @param data Pointer to USB-C charger emulator
+ * @param delay Optional delay
+ *
+ * @return 0 on success
+ * @return -ENOMEM when there is no free memory for message
+ * @return -EINVAL on TCPCI emulator add RX message error
+ */
+static int charger_emul_send_capability_msg(struct charger_emul_data *data,
+ uint64_t delay)
+{
+ struct charger_emul_msg *msg;
+
+ msg = charger_emul_alloc_msg(6);
+ if (msg == NULL) {
+ return -ENOMEM;
+ }
+
+ /* Capability with 5v@3A */
+ charger_emul_set_header(data, msg, PD_DATA_SOURCE_CAP, 1);
+
+ /* Fixed supply (type of supply) 0xc0 */
+ msg->msg.buf[5] = 0x00;
+ /* Dual role capable 0x20 */
+ msg->msg.buf[5] |= 0x00;
+ /* Unconstrained power 0x08 */
+ msg->msg.buf[5] |= 0x08;
+
+ /* 5V on bits 19-10 */
+ msg->msg.buf[4] = 0x1;
+ msg->msg.buf[3] = 0x90;
+ /* 3A on bits 9-0 */
+ msg->msg.buf[3] |= 0x1;
+ msg->msg.buf[2] = 0x2c;
+
+ /* Fill tcpci message structure */
+ msg->msg.type = TCPCI_MSG_SOP;
+
+ return charger_emul_send_msg(data, msg, delay);
+}
+
+/**
+ * @brief Send control message with optional delay
+ *
+ * @param data Pointer to USB-C charger emulator
+ * @param type Type of message
+ * @param delay Optional delay
+ *
+ * @return 0 on success
+ * @return -ENOMEM when there is no free memory for message
+ * @return -EINVAL on TCPCI emulator add RX message error
+ */
+static int charger_emul_send_control_msg(struct charger_emul_data *data,
+ enum pd_ctrl_msg_type type,
+ uint64_t delay)
+{
+ struct charger_emul_msg *msg;
+
+ msg = charger_emul_alloc_msg(2);
+ if (msg == NULL) {
+ return -ENOMEM;
+ }
+
+ charger_emul_set_header(data, msg, type, 0);
+
+ /* Fill tcpci message structure */
+ msg->msg.type = TCPCI_MSG_SOP;
+
+ return charger_emul_send_msg(data, msg, delay);
+}
+
+/**
+ * @brief Function called when TCPM wants to transmit message. Accept received
+ * message and generate response.
+ *
+ * @param emul Pointer to TCPCI emulator
+ * @param ops Pointer to partner operations structure
+ * @param tx_msg Pointer to TX message buffer
+ * @param type Type of message
+ * @param retry Count of retries
+ */
+static void charger_emul_transmit_op(const struct emul *emul,
+ const struct tcpci_emul_partner_ops *ops,
+ const struct tcpci_emul_msg *tx_msg,
+ enum tcpci_msg_type type,
+ int retry)
+{
+ struct charger_emul_data *data = CONTAINER_OF(ops,
+ struct charger_emul_data,
+ ops);
+ uint16_t header;
+
+ /* Acknowledge that message was sent successfully */
+ tcpci_emul_partner_msg_status(emul, TCPCI_EMUL_TX_SUCCESS);
+
+ /* Handle only SOP messages */
+ if (type != TCPCI_MSG_SOP) {
+ return;
+ }
+
+ LOG_HEXDUMP_DBG(tx_msg->buf, tx_msg->cnt, "Charger received message");
+
+ header = (tx_msg->buf[1] << 8) | tx_msg->buf[0];
+
+ if (PD_HEADER_CNT(header)) {
+ /* Handle data message */
+ switch (PD_HEADER_TYPE(header)) {
+ case PD_DATA_REQUEST:
+ charger_emul_send_control_msg(data, PD_CTRL_ACCEPT, 0);
+ /* PS ready after 15 ms */
+ charger_emul_send_control_msg(data, PD_CTRL_PS_RDY, 15);
+ break;
+ case PD_DATA_VENDOR_DEF:
+ /* VDM (vendor defined message) - ignore */
+ break;
+ default:
+ charger_emul_send_control_msg(data, PD_CTRL_REJECT, 0);
+ break;
+ }
+ } else {
+ /* Handle control message */
+ switch (PD_HEADER_TYPE(header)) {
+ case PD_CTRL_GET_SOURCE_CAP:
+ charger_emul_send_capability_msg(data, 0);
+ break;
+ case PD_CTRL_GET_SINK_CAP:
+ charger_emul_send_control_msg(data, PD_CTRL_REJECT, 0);
+ break;
+ case PD_CTRL_DR_SWAP:
+ charger_emul_send_control_msg(data, PD_CTRL_REJECT, 0);
+ break;
+ case PD_CTRL_SOFT_RESET:
+ data->msg_id = 0;
+ charger_emul_send_control_msg(data, PD_CTRL_ACCEPT, 0);
+ /* Send capability after 15 ms to establish PD again */
+ charger_emul_send_capability_msg(data, 15);
+ break;
+ default:
+ charger_emul_send_control_msg(data, PD_CTRL_REJECT, 0);
+ break;
+ }
+ }
+}
+
+/**
+ * @brief Function called when TCPM consumes message. Free message that is no
+ * longer needed.
+ *
+ * @param emul Pointer to TCPCI emulator
+ * @param ops Pointer to partner operations structure
+ * @param rx_msg Message that was consumed by TCPM
+ */
+static void charger_emul_rx_consumed_op(
+ const struct emul *emul,
+ const struct tcpci_emul_partner_ops *ops,
+ const struct tcpci_emul_msg *rx_msg)
+{
+ struct charger_emul_msg *msg = CONTAINER_OF(rx_msg,
+ struct charger_emul_msg,
+ msg);
+
+ charger_emul_free_msg(msg);
+}
+
+/** Check description in emul_charger.h */
+int charger_emul_connect_to_tcpci(struct charger_emul_data *data,
+ const struct emul *tcpci_emul)
+{
+ int ec;
+
+ tcpci_emul_set_partner_ops(tcpci_emul, &data->ops);
+ ec = tcpci_emul_connect_partner(tcpci_emul, PD_ROLE_SOURCE,
+ TYPEC_CC_VOLT_RP_3_0,
+ TYPEC_CC_VOLT_OPEN, POLARITY_CC1);
+ if (ec) {
+ return ec;
+ }
+
+ data->tcpci_emul = tcpci_emul;
+
+ return charger_emul_send_capability_msg(data, 0);
+}
+
+/** Check description in emul_charger.h */
+void charger_emul_init(struct charger_emul_data *data)
+{
+ k_work_init_delayable(&data->delayed_send, charger_emul_delayed_send);
+ k_fifo_init(&data->to_send);
+
+ data->ops.transmit = charger_emul_transmit_op;
+ data->ops.rx_consumed = charger_emul_rx_consumed_op;
+}
diff --git a/zephyr/emul/emul_sn5s330.c b/zephyr/emul/emul_sn5s330.c
index 0fcb9bd78c..f6b3217372 100644
--- a/zephyr/emul/emul_sn5s330.c
+++ b/zephyr/emul/emul_sn5s330.c
@@ -316,6 +316,16 @@ static int sn5s330_emul_write_byte(struct i2c_emul *emul, int reg, uint8_t val,
return 0;
}
+void sn5s330_emul_reset(const struct emul *emul)
+{
+ struct sn5s330_emul_data *data = emul->data;
+ struct i2c_common_emul_data common = data->common;
+
+ /* Only Reset the sn5s330 Register Data */
+ memset(data, 0, sizeof(struct sn5s330_emul_data));
+ data->common = common;
+}
+
static int emul_sn5s330_init(const struct emul *emul,
const struct device *parent)
{
diff --git a/zephyr/emul/emul_tcpci.c b/zephyr/emul/emul_tcpci.c
index ad630820c4..b2c21c2ec4 100644
--- a/zephyr/emul/emul_tcpci.c
+++ b/zephyr/emul/emul_tcpci.c
@@ -315,6 +315,152 @@ void tcpci_emul_set_dev_ops(const struct emul *emul,
data->dev_ops = dev_ops;
}
+/** Check description in emul_tcpci.h */
+void tcpci_emul_set_alert_callback(const struct emul *emul,
+ tcpci_emul_alert_state_func alert_callback,
+ void *alert_callback_data)
+{
+ struct tcpci_emul_data *data = emul->data;
+
+ data->alert_callback = alert_callback;
+ data->alert_callback_data = alert_callback_data;
+}
+
+/** Check description in emul_tcpci.h */
+void tcpci_emul_set_partner_ops(const struct emul *emul,
+ struct tcpci_emul_partner_ops *partner)
+{
+ struct tcpci_emul_data *data = emul->data;
+
+ data->partner = partner;
+}
+
+/**
+ * @brief Get detected voltage for given CC resistor
+ *
+ * @param res CC pull resistor value
+ * @param volt Voltage applied by port partner
+ *
+ * @return Voltage visible at CC resistor side
+ */
+static enum tcpc_cc_voltage_status tcpci_emul_detected_volt_for_res(
+ enum tcpc_cc_pull res,
+ enum tcpc_cc_voltage_status volt)
+{
+ switch (res) {
+ case TYPEC_CC_RD:
+ switch (volt) {
+ /* As Rd we cannot detect another Rd or Ra */
+ case TYPEC_CC_VOLT_RA:
+ case TYPEC_CC_VOLT_RD:
+ return TYPEC_CC_VOLT_OPEN;
+ default:
+ return volt;
+ }
+ case TYPEC_CC_RP:
+ switch (volt) {
+ /* As Rp we cannot detect another Rp */
+ case TYPEC_CC_VOLT_RP_DEF:
+ case TYPEC_CC_VOLT_RP_1_5:
+ case TYPEC_CC_VOLT_RP_3_0:
+ return TYPEC_CC_VOLT_OPEN;
+ default:
+ return volt;
+ }
+ default:
+ /* As Ra or open we cannot detect anything */
+ return TYPEC_CC_VOLT_OPEN;
+ }
+}
+
+/** Check description in emul_tcpci.h */
+int tcpci_emul_connect_partner(const struct emul *emul,
+ enum pd_power_role partner_power_role,
+ enum tcpc_cc_voltage_status partner_cc1,
+ enum tcpc_cc_voltage_status partner_cc2,
+ enum tcpc_cc_polarity polarity)
+{
+ enum tcpc_cc_voltage_status cc1_v, cc2_v;
+ uint16_t cc_status, alert, role_ctrl;
+ enum tcpc_cc_pull cc1_r, cc2_r;
+
+ if (polarity == POLARITY_CC1) {
+ cc1_v = partner_cc1;
+ cc2_v = partner_cc2;
+ } else {
+ cc1_v = partner_cc2;
+ cc2_v = partner_cc1;
+ }
+
+ tcpci_emul_get_reg(emul, TCPC_REG_CC_STATUS, &cc_status);
+ if (TCPC_REG_CC_STATUS_LOOK4CONNECTION(cc_status)) {
+ /* Change resistors values in case of DRP toggling */
+ if (partner_power_role == PD_ROLE_SOURCE) {
+ /* TCPCI is sink */
+ cc1_r = TYPEC_CC_RD;
+ cc2_r = TYPEC_CC_RD;
+ } else {
+ /* TCPCI is src */
+ cc1_r = TYPEC_CC_RP;
+ cc2_r = TYPEC_CC_RP;
+ }
+ } else {
+ /* Use role control resistors values otherwise */
+ tcpci_emul_get_reg(emul, TCPC_REG_ROLE_CTRL, &role_ctrl);
+ cc1_r = TCPC_REG_ROLE_CTRL_CC1(role_ctrl);
+ cc2_r = TCPC_REG_ROLE_CTRL_CC2(role_ctrl);
+ }
+
+ cc1_v = tcpci_emul_detected_volt_for_res(cc1_r, cc1_v);
+ cc2_v = tcpci_emul_detected_volt_for_res(cc2_r, cc2_v);
+
+ /* If CC status is TYPEC_CC_VOLT_RP_*, then BIT(2) is ignored */
+ cc_status = TCPC_REG_CC_STATUS_SET(
+ partner_power_role == PD_ROLE_SOURCE ? 1 : 0,
+ cc2_v, cc1_v);
+ tcpci_emul_set_reg(emul, TCPC_REG_CC_STATUS, cc_status);
+ tcpci_emul_get_reg(emul, TCPC_REG_ALERT, &alert);
+ tcpci_emul_set_reg(emul, TCPC_REG_ALERT,
+ alert | TCPC_REG_ALERT_CC_STATUS);
+
+ if (partner_power_role == PD_ROLE_SOURCE) {
+ /* Set TCPCI emulator VBUS to present (connected, above 4V) */
+ tcpci_emul_set_reg(emul, TCPC_REG_POWER_STATUS,
+ TCPC_REG_POWER_STATUS_VBUS_PRES |
+ TCPC_REG_POWER_STATUS_VBUS_DET);
+ }
+
+ tcpci_emul_alert_changed(emul);
+
+ return 0;
+}
+
+/** Check description in emul_tcpci.h */
+void tcpci_emul_partner_msg_status(const struct emul *emul,
+ enum tcpci_emul_tx_status status)
+{
+ uint16_t alert;
+ uint16_t tx_status_alert;
+
+ switch (status) {
+ case TCPCI_EMUL_TX_SUCCESS:
+ tx_status_alert = TCPC_REG_ALERT_TX_SUCCESS;
+ break;
+ case TCPCI_EMUL_TX_DISCARDED:
+ tx_status_alert = TCPC_REG_ALERT_TX_DISCARDED;
+ break;
+ case TCPCI_EMUL_TX_FAILED:
+ tx_status_alert = TCPC_REG_ALERT_TX_FAILED;
+ break;
+ default:
+ __ASSERT(0, "Invalid partner TX status 0x%x", status);
+ return;
+ }
+
+ tcpci_emul_get_reg(emul, TCPC_REG_ALERT, &alert);
+ tcpci_emul_set_reg(emul, TCPC_REG_ALERT, alert | tx_status_alert);
+ tcpci_emul_alert_changed(emul);
+}
/** Mask reserved bits in each register of TCPCI */
static const uint8_t tcpci_emul_rsvd_mask[] = {
@@ -615,6 +761,8 @@ static int tcpci_emul_read_byte(struct i2c_emul *i2c_emul, int reg,
emul = i2c_emul->parent;
data = TCPCI_DATA_FROM_I2C_EMUL(i2c_emul);
+ LOG_DBG("TCPCI 0x%x: read reg 0x%x", i2c_emul->addr, reg);
+
if (data->dev_ops && data->dev_ops->read_byte) {
switch (data->dev_ops->read_byte(emul, data->dev_ops, reg, val,
bytes)) {
@@ -823,6 +971,8 @@ static int tcpci_emul_write_byte(struct i2c_emul *i2c_emul, int reg,
static int tcpci_emul_handle_command(const struct emul *emul)
{
struct tcpci_emul_data *data = emul->data;
+ uint16_t role_ctrl;
+ uint16_t pwr_ctrl;
switch (data->write_data & 0xff) {
case TCPC_REG_COMMAND_RESET_TRANSMIT_BUF:
@@ -833,12 +983,31 @@ static int tcpci_emul_handle_command(const struct emul *emul)
data->rx_msg->idx = 0;
}
break;
+ case TCPC_REG_COMMAND_LOOK4CONNECTION:
+ tcpci_emul_get_reg(emul, TCPC_REG_ROLE_CTRL, &role_ctrl);
+ tcpci_emul_get_reg(emul, TCPC_REG_POWER_CTRL, &pwr_ctrl);
+
+ /*
+ * Start DRP toggling only if auto discharge is disabled,
+ * DRP is enabled and CC1/2 are both Rp or Rd
+ */
+ if (!(pwr_ctrl & TCPC_REG_POWER_CTRL_AUTO_DISCHARGE_DISCONNECT)
+ && TCPC_REG_ROLE_CTRL_DRP(role_ctrl) &&
+ (TCPC_REG_ROLE_CTRL_CC1(role_ctrl) ==
+ TCPC_REG_ROLE_CTRL_CC2(role_ctrl)) &&
+ (TCPC_REG_ROLE_CTRL_CC1(role_ctrl) == TYPEC_CC_RP ||
+ TCPC_REG_ROLE_CTRL_CC1(role_ctrl) == TYPEC_CC_RD)) {
+ /* Set Look4Connection and clear CC1/2 state */
+ tcpci_emul_set_reg(
+ emul, TCPC_REG_CC_STATUS,
+ TCPC_REG_CC_STATUS_LOOK4CONNECTION_MASK);
+ }
+ break;
case TCPC_REG_COMMAND_ENABLE_VBUS_DETECT:
case TCPC_REG_COMMAND_SNK_CTRL_LOW:
case TCPC_REG_COMMAND_SNK_CTRL_HIGH:
case TCPC_REG_COMMAND_SRC_CTRL_LOW:
case TCPC_REG_COMMAND_SRC_CTRL_HIGH:
- case TCPC_REG_COMMAND_LOOK4CONNECTION:
case TCPC_REG_COMMAND_I2CIDLE:
break;
default:
@@ -879,6 +1048,42 @@ static int tcpci_emul_handle_transmit(const struct emul *emul)
}
/**
+ * @brief Load next rx message and inform partner which message was consumed
+ * by TCPC
+ *
+ * @param emul Pointer to TCPCI emulator
+ *
+ * @return 0 when there is no new message to load
+ * @return 1 when new rx message is loaded
+ */
+static int tcpci_emul_get_next_rx_msg(const struct emul *emul)
+{
+ struct tcpci_emul_data *data = emul->data;
+ struct tcpci_emul_msg *consumed_msg;
+
+ if (data->rx_msg == NULL) {
+ return 0;
+ }
+
+ consumed_msg = data->rx_msg;
+ data->rx_msg = consumed_msg->next;
+
+ /* Inform partner */
+ if (data->partner && data->partner->rx_consumed) {
+ data->partner->rx_consumed(emul, data->partner, consumed_msg);
+ }
+
+ /* Prepare new loaded message */
+ if (data->rx_msg) {
+ data->rx_msg->idx = 0;
+
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
* @brief Handle I2C write message. It is checked if accessed register isn't RO
* and reserved bits are set to 0.
*
@@ -912,6 +1117,9 @@ static int tcpci_emul_handle_write(struct i2c_emul *i2c_emul, int reg,
emul = i2c_emul->parent;
data = TCPCI_DATA_FROM_I2C_EMUL(i2c_emul);
+ LOG_DBG("TCPCI 0x%x: write reg 0x%x val 0x%x", i2c_emul->addr, reg,
+ data->write_data);
+
if (data->dev_ops && data->dev_ops->handle_write) {
switch (data->dev_ops->handle_write(emul, data->dev_ops, reg,
msg_len)) {
@@ -932,13 +1140,9 @@ static int tcpci_emul_handle_write(struct i2c_emul *i2c_emul, int reg,
data->write_data &= ~TCPC_REG_ALERT_RX_BUF_OVF;
if (data->write_data & TCPC_REG_ALERT_RX_STATUS) {
data->write_data |= TCPC_REG_ALERT_RX_BUF_OVF;
- /* Load next message if possible */
- if (data->rx_msg && data->rx_msg->next) {
+ /* Do not clear RX status if there is new message */
+ if (tcpci_emul_get_next_rx_msg(emul)) {
data->write_data &= ~TCPC_REG_ALERT_RX_STATUS;
- data->rx_msg = data->rx_msg->next;
- data->rx_msg->idx = 0;
- } else {
- data->rx_msg = NULL;
}
}
/* fallthrough */
@@ -1139,12 +1343,12 @@ static int tcpci_emul_init(const struct emul *emul, const struct device *parent)
.access_reg = tcpci_emul_access_reg, \
}, \
.alert_gpio_port = COND_CODE_1( \
- DT_NODE_HAS_PROP(n, alert_gpio), \
+ DT_INST_NODE_HAS_PROP(n, alert_gpio), \
(DEVICE_DT_GET(DT_GPIO_CTLR( \
DT_INST_PROP(n, alert_gpio), gpios))), \
(NULL)), \
.alert_gpio_pin = COND_CODE_1( \
- DT_NODE_HAS_PROP(n, alert_gpio), \
+ DT_INST_NODE_HAS_PROP(n, alert_gpio), \
(DT_GPIO_PIN(DT_INST_PROP(n, alert_gpio), \
gpios)), \
(0)), \
diff --git a/zephyr/include/emul/emul_charger.h b/zephyr/include/emul/emul_charger.h
new file mode 100644
index 0000000000..87303181e8
--- /dev/null
+++ b/zephyr/include/emul/emul_charger.h
@@ -0,0 +1,66 @@
+/* Copyright 2021 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.
+ */
+
+/**
+ * @file
+ *
+ * @brief Backend API for USB-C charger emulator
+ */
+
+#ifndef __EMUL_CHARGER_H
+#define __EMUL_CHARGER_H
+
+#include <emul.h>
+#include "emul/emul_tcpci.h"
+
+/**
+ * @brief USB-C charger emulator backend API
+ * @defgroup charger_emul USB-C charger emulator
+ * @{
+ *
+ * USB-C charger emulator can be attached to TCPCI emulator. It is able to
+ * respond to some TCPM messages. It always attach as source and present
+ * hardcoded set of source capabilities.
+ */
+
+/** Structure describing charger emulator */
+struct charger_emul_data {
+ /** Operations used by TCPCI emulator */
+ struct tcpci_emul_partner_ops ops;
+ /** Work used to send message with delay */
+ struct k_work_delayable delayed_send;
+ /** Pointer to connected TCPCI emulator */
+ const struct emul *tcpci_emul;
+ /** Queue for delayed messages */
+ struct k_fifo to_send;
+ /** Next SOP message id */
+ int msg_id;
+};
+
+/**
+ * @brief Initialise USB-C charger emulator. Need to be called before any other
+ * function.
+ *
+ * @param data Pointer to USB-C charger emulator
+ */
+void charger_emul_init(struct charger_emul_data *data);
+
+/**
+ * @brief Connect emulated device to TCPCI
+ *
+ * @param data Pointer to USB-C charger emulator
+ * @param tcpci_emul Poinetr to TCPCI emulator to connect
+ *
+ * @return 0 on success
+ * @return negative on TCPCI connect error or send source capabilities error
+ */
+int charger_emul_connect_to_tcpci(struct charger_emul_data *data,
+ const struct emul *tcpci_emul);
+
+/**
+ * @}
+ */
+
+#endif /* __EMUL_CHARGER */
diff --git a/zephyr/include/emul/emul_sn5s330.h b/zephyr/include/emul/emul_sn5s330.h
index ad6d0f04c1..00b473e206 100644
--- a/zephyr/include/emul/emul_sn5s330.h
+++ b/zephyr/include/emul/emul_sn5s330.h
@@ -27,4 +27,11 @@ struct i2c_emul *sn5s330_emul_to_i2c_emul(const struct emul *emul);
*/
int sn5s330_emul_peek_reg(const struct emul *emul, uint32_t reg, uint32_t *val);
+/**
+ * @brief Reset the sn5s330 emulator
+ *
+ * @param emul The emulator to reset
+ */
+void sn5s330_emul_reset(const struct emul *emul);
+
#endif /* ZEPHYR_INCLUDE_EMUL_EMUL_SN5S330_H_ */
diff --git a/zephyr/include/emul/emul_tcpci.h b/zephyr/include/emul/emul_tcpci.h
index b4b6bbb9ca..7be5b2711c 100644
--- a/zephyr/include/emul/emul_tcpci.h
+++ b/zephyr/include/emul/emul_tcpci.h
@@ -77,6 +77,13 @@ enum tcpci_emul_rev {
TCPCI_EMUL_REV2_0_VER1_1
};
+/** Status of TX message send to TCPCI emulator partner */
+enum tcpci_emul_tx_status {
+ TCPCI_EMUL_TX_SUCCESS,
+ TCPCI_EMUL_TX_DISCARDED,
+ TCPCI_EMUL_TX_FAILED
+};
+
/** TCPCI specific device operations. Not all of them need to be implemented. */
struct tcpci_emul_dev_ops {
/**
@@ -165,6 +172,17 @@ struct tcpci_emul_partner_ops {
*/
void (*control_change)(const struct emul *emul,
const struct tcpci_emul_partner_ops *ops);
+
+ /**
+ * @brief Function called when TCPM consumes message send by partner
+ *
+ * @param emul Pointer to TCPCI emulator
+ * @param ops Pointer to partner operations structure
+ * @param rx_msg Message that was consumed by TCPM
+ */
+ void (*rx_consumed)(const struct emul *emul,
+ const struct tcpci_emul_partner_ops *ops,
+ const struct tcpci_emul_msg *rx_msg);
};
/**
@@ -241,6 +259,56 @@ void tcpci_emul_set_dev_ops(const struct emul *emul,
struct tcpci_emul_dev_ops *dev_ops);
/**
+ * @brief Set callback which is called when alert register is changed
+ *
+ * @param emul Pointer to TCPCI emulator
+ * @param alert_callback Pointer to callback
+ * @param alert_callback_data Pointer to data passed to callback as an argument
+ */
+void tcpci_emul_set_alert_callback(const struct emul *emul,
+ tcpci_emul_alert_state_func alert_callback,
+ void *alert_callback_data);
+
+/**
+ * @brief Set callbacks for port partner device emulator
+ *
+ * @param emul Pointer to TCPCI emulator
+ * @param partner Pointer to callbacks
+ */
+void tcpci_emul_set_partner_ops(const struct emul *emul,
+ struct tcpci_emul_partner_ops *partner);
+
+/**
+ * @brief Emulate connection of specific device to emulated TCPCI
+ *
+ * @param emul Pointer to TCPCI emulator
+ * @param partner_power_role Power role of connected partner (sink or source)
+ * @param partner_cc1 Voltage on partner CC1 line (usually Rd or Rp)
+ * @param partner_cc2 Voltage on partner CC2 line (usually open or Ra if active
+ * cable is emulated)
+ * @param polarity Polarity of plug. If POLARITY_CC1 then partner_cc1 is
+ * connected to TCPCI CC1 line. Otherwise partner_cc1 is
+ * connected to TCPCI CC2 line.
+ *
+ * @return 0 on success
+ * @return negative on error
+ */
+int tcpci_emul_connect_partner(const struct emul *emul,
+ enum pd_power_role partner_power_role,
+ enum tcpc_cc_voltage_status partner_cc1,
+ enum tcpc_cc_voltage_status partner_cc2,
+ enum tcpc_cc_polarity polarity);
+
+/**
+ * @brief Allows port partner to select if message was received correctly
+ *
+ * @param emul Pointer to TCPCI emulator
+ * @param status Status of sended message
+ */
+void tcpci_emul_partner_msg_status(const struct emul *emul,
+ enum tcpci_emul_tx_status status);
+
+/**
* @}
*/
diff --git a/zephyr/projects/herobrine/herobrine_npcx9/prj.conf b/zephyr/projects/herobrine/herobrine_npcx9/prj.conf
index 44b1f0e831..aeb9f6e36f 100644
--- a/zephyr/projects/herobrine/herobrine_npcx9/prj.conf
+++ b/zephyr/projects/herobrine/herobrine_npcx9/prj.conf
@@ -51,9 +51,6 @@ CONFIG_PLATFORM_EC_POWER_SLEEP_FAILURE_DETECTION=y
CONFIG_PLATFORM_EC_CHIPSET_RESET_HOOK=y
CONFIG_PLATFORM_EC_CHIPSET_RESUME_INIT_HOOK=y
-# TODO(b:193719620): Enable EC EFS2.
-CONFIG_PLATFORM_EC_VBOOT_EFS2=n
-
# MKBP event mask
CONFIG_PLATFORM_EC_MKBP_EVENT_WAKEUP_MASK=y
CONFIG_PLATFORM_EC_MKBP_HOST_EVENT_WAKEUP_MASK=y
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index 7891ac79ad..9598e2cf5a 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -1736,6 +1736,39 @@
CONFIG_PLATFORM_EC_CHARGER_BQ25720_VSYS_UVP
#endif
+#undef CONFIG_CHARGER_BQ25720_IDCHG_DEG2_CUSTOM
+#ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25720_IDCHG_DEG2_CUSTOM
+#define CONFIG_CHARGER_BQ25720_IDCHG_DEG2_CUSTOM
+#endif
+
+#undef CONFIG_CHARGER_BQ25720_IDCHG_DEG2
+#ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25720_IDCHG_DEG2
+#define CONFIG_CHARGER_BQ25720_IDCHG_DEG2 \
+ CONFIG_PLATFORM_EC_CHARGER_BQ25720_IDCHG_DEG2
+#endif
+
+#undef CONFIG_CHARGER_BQ25720_IDCHG_TH2_CUSTOM
+#ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25720_IDCHG_TH2_CUSTOM
+#define CONFIG_CHARGER_BQ25720_IDCHG_TH2_CUSTOM
+#endif
+
+#undef CONFIG_CHARGER_BQ25720_IDCHG_TH2
+#ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25720_IDCHG_TH2
+#define CONFIG_CHARGER_BQ25720_IDCHG_TH2 \
+ CONFIG_PLATFORM_EC_CHARGER_BQ25720_IDCHG_TH2
+#endif
+
+#undef CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_CUSTOM
+#ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_CUSTOM
+#define CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_CUSTOM
+#endif
+
+#undef CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_MV
+#ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_MV
+#define CONFIG_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_MV \
+ CONFIG_PLATFORM_EC_CHARGER_BQ25710_VSYS_MIN_VOLTAGE_MV
+#endif
+
#undef CONFIG_HIBERNATE_PSL
#ifdef CONFIG_PLATFORM_EC_HIBERNATE_PSL
#define CONFIG_HIBERNATE_PSL
diff --git a/zephyr/shim/src/console.c b/zephyr/shim/src/console.c
index 41e138b50c..5a465b2fd4 100644
--- a/zephyr/shim/src/console.c
+++ b/zephyr/shim/src/console.c
@@ -217,7 +217,7 @@ int uart_tx_char_raw(void *context, int c)
void uart_write_char(char c)
{
- printk("%c", c);
+ uart_poll_out(uart_shell_dev, c);
if (IS_ENABLED(CONFIG_PLATFORM_EC_HOSTCMD_CONSOLE))
console_buf_notify_chars(&c, 1);
diff --git a/zephyr/test/drivers/src/cros_cbi.c b/zephyr/test/drivers/src/cros_cbi.c
index dde215f6a1..ee3666f3f0 100644
--- a/zephyr/test/drivers/src/cros_cbi.c
+++ b/zephyr/test/drivers/src/cros_cbi.c
@@ -27,8 +27,22 @@ static void test_check_match(void)
zassert_false(value, "Expected cbi ssfc to fail on invalid enum");
}
+static void test_fail_check_match(void)
+{
+ const struct device *dev = device_get_binding(CROS_CBI_LABEL);
+ int value;
+
+ zassert_not_null(dev, NULL);
+
+ value = cros_cbi_ssfc_check_match(dev, CBI_SSFC_VALUE_COUNT);
+ zassert_false(value,
+ "Expected cbi ssfc to never match CBI_SSFC_VALUE_COUNT");
+}
+
void test_suite_cros_cbi(void)
{
- ztest_test_suite(cros_cbi, ztest_unit_test(test_check_match));
+ ztest_test_suite(cros_cbi,
+ ztest_unit_test(test_check_match),
+ ztest_unit_test(test_fail_check_match));
ztest_run_test_suite(cros_cbi);
}
diff --git a/zephyr/test/drivers/src/ppc_sn5s330.c b/zephyr/test/drivers/src/ppc_sn5s330.c
index 3cabfc43c9..95556e28cf 100644
--- a/zephyr/test/drivers/src/ppc_sn5s330.c
+++ b/zephyr/test/drivers/src/ppc_sn5s330.c
@@ -53,10 +53,16 @@ static void test_fail_once_func_set1(void)
i2c_common_emul_set_write_func(i2c_emul, NULL, NULL);
}
+static void reset_sn5s330_state(void)
+{
+ sn5s330_emul_reset(EMUL);
+}
+
void test_suite_ppc_sn5s330(void)
{
- ztest_test_suite(
- ppc_sn5s330,
- ztest_unit_test(test_fail_once_func_set1));
+ ztest_test_suite(ppc_sn5s330,
+ ztest_unit_test_setup_teardown(
+ test_fail_once_func_set1, reset_sn5s330_state,
+ reset_sn5s330_state));
ztest_run_test_suite(ppc_sn5s330);
}
diff --git a/zephyr/zmake/tests/test_project.py b/zephyr/zmake/tests/test_project.py
index 2797a1bc92..4d9994a108 100644
--- a/zephyr/zmake/tests/test_project.py
+++ b/zephyr/zmake/tests/test_project.py
@@ -193,3 +193,42 @@ def test_find_projects_name_conflict(tmp_path):
with pytest.raises(KeyError):
zmake.project.find_projects(tmp_path)
+
+
+@pytest.mark.parametrize(
+ ("actual_files", "config_files", "expected_files"),
+ [
+ (["prj_link.conf"], [], []),
+ (["prj.conf"], [], ["prj.conf"]),
+ (
+ ["prj.conf", "cfg.conf"],
+ ["prj.conf", "cfg.conf"],
+ ["prj.conf", "cfg.conf"],
+ ),
+ (
+ ["prj.conf", "prj_samus.conf", "prj_link.conf"],
+ ["prj_link.conf"],
+ ["prj.conf", "prj_link.conf"],
+ ),
+ ],
+)
+def test_kconfig_files(tmp_path, actual_files, config_files, expected_files):
+ for name in actual_files:
+ (tmp_path / name).write_text("")
+
+ project = zmake.project.Project(
+ zmake.project.ProjectConfig(
+ project_name="samus",
+ zephyr_board="lm4",
+ output_packer=zmake.output_packers.RawBinPacker,
+ supported_toolchains=["coreboot-sdk"],
+ project_dir=tmp_path,
+ kconfig_files=[tmp_path / name for name in config_files],
+ ),
+ )
+
+ builds = list(project.iter_builds())
+ assert len(builds) == 1
+
+ _, config = builds[0]
+ assert sorted(f.name for f in config.kconfig_files) == sorted(expected_files)
diff --git a/zephyr/zmake/zmake/project.py b/zephyr/zmake/zmake/project.py
index 60f2ecf6ec..de3bc8413b 100644
--- a/zephyr/zmake/zmake/project.py
+++ b/zephyr/zmake/zmake/project.py
@@ -97,6 +97,7 @@ class ProjectConfig:
)
is_test: bool = dataclasses.field(default=False)
dts_overlays: "list[str]" = dataclasses.field(default_factory=list)
+ kconfig_files: "list[pathlib.Path]" = dataclasses.field(default_factory=list)
project_dir: pathlib.Path = dataclasses.field(default_factory=pathlib.Path)
@@ -114,9 +115,14 @@ class Project:
2-tuples of a build configuration name and a BuildConfig.
"""
conf = build_config.BuildConfig(cmake_defs={"BOARD": self.config.zephyr_board})
+
+ kconfig_files = []
prj_conf = self.config.project_dir / "prj.conf"
if prj_conf.is_file():
- conf |= build_config.BuildConfig(kconfig_files=[prj_conf])
+ kconfig_files.append(prj_conf)
+ kconfig_files.extend(self.config.kconfig_files)
+ conf |= build_config.BuildConfig(kconfig_files=kconfig_files)
+
for build_name, packer_config in self.packer.configs():
yield build_name, conf | packer_config
diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py
index a5c3cb62a5..8fc9542dca 100644
--- a/zephyr/zmake/zmake/zmake.py
+++ b/zephyr/zmake/zmake/zmake.py
@@ -756,10 +756,9 @@ class Zmake:
root_dir = self.module_paths["ec"] / "zephyr"
for project in zmake.project.find_projects(root_dir).values():
is_test = project.config.is_test
- rel_path = project.config.project_dir.relative_to(root_dir)
- project_build_dir = pathlib.Path(build_dir).joinpath(rel_path)
- lcov_file = pathlib.Path(build_dir).joinpath(
- str(rel_path).replace("/", "_") + ".info"
+ project_build_dir = pathlib.Path(build_dir) / project.config.project_name
+ lcov_file = pathlib.Path(build_dir) / "{}.info".format(
+ project.config.project_name
)
all_lcov_files.append(lcov_file)
if is_test: