summaryrefslogtreecommitdiff
path: root/zephyr/program
diff options
context:
space:
mode:
authorYH Lin <yueherngl@google.com>2023-05-11 20:47:00 +0000
committerYH Lin <yueherngl@google.com>2023-05-11 20:47:00 +0000
commit8641442366bd7c2c133e302a57f904dfac3c896b (patch)
treed0dca100ca02a89210decc54b7124d26bb75ef6a /zephyr/program
parente79a9dab1721c3d7da1475f3f802c4ea871a48ec (diff)
parent5df400b0377c9e1b5bb6cfc53ba7dfedde91f944 (diff)
downloadchrome-ec-8641442366bd7c2c133e302a57f904dfac3c896b.tar.gz
Merge remote-tracking branch cros/main into firmware-brya-14505.B-main
Generated by: util/update_release_branch.py --baseboard brya --relevant_paths_file baseboard/brya/relevant-paths.txt firmware-brya-14505.B-main Relevant changes: git log --oneline e79a9dab17..5df400b037 -- baseboard/brya board/agah board/anahera board/banshee board/brya board/crota board/felwinter board/gimble board/hades board/kano board/marasov board/mithrax board/omnigul board/osiris board/primus board/redrix board/taeko board/taniks board/vell board/volmar driver/bc12/pi3usb9201_public.* driver/charger/bq25710.* driver/ppc/nx20p348x.* driver/ppc/syv682x_public.* driver/retimer/bb_retimer_public.* driver/tcpm/nct38xx.* driver/tcpm/ps8xxx_public.* driver/tcpm/tcpci.* include/power/alderlake* include/intel_x86.h power/alderlake* power/intel_x86.c util/getversion.sh 76d2b9b1e4 battery: Deprecate CONFIG_BATTERY_LEVEL_NEAR_FULL 3d5b996f73 Hades: Fast forward DSW_PWROK to PCH_PWROK 56af450c1a Agah: Fast forward DSW_PWROK to PCH_PWROK b729eab7c7 charger: Move charger_state_v2.h into charge_state.h 47acf64182 charger: Rename charge_get_state() to led_pwr_get_state() 632c7c935a power/x86: Add dedicated interrupt handler for pwrok 0fff3a0bd4 omnigul: Add condition use Accel and Gyro by FWCONFIG. 7540daff3f driver/tcpm/nct38xx: Remove write to RO register 3f279f30d4 GPU: Rename DC_ATLEAST_SOC to DC_ATMOST_SOC BRANCH=None BUG=b:218332694 b:216485035 b:280818345 b:280351196 b:280001153 BUG=b:279918234 TEST=`emerge-[brya,hades,draco] chromeos-ec` Force-Relevant-Builds: all Change-Id: I19f2f6c5573d8c748ac63b488a808f10de352b1d Signed-off-by: YH Lin <yueherngl@google.com>
Diffstat (limited to 'zephyr/program')
-rw-r--r--zephyr/program/corsola/magikarp/project.overlay6
-rw-r--r--zephyr/program/corsola/src/npcx_usbc.c30
-rw-r--r--zephyr/program/corsola/src/usbc.c2
-rw-r--r--zephyr/program/corsola/starmie/project.overlay4
-rw-r--r--zephyr/program/corsola/tentacruel/project.overlay6
-rw-r--r--zephyr/program/corsola/tentacruel/src/temp.c2
-rw-r--r--zephyr/program/corsola/voltorb/project.conf1
-rw-r--r--zephyr/program/corsola/voltorb/project.overlay15
-rw-r--r--zephyr/program/geralt/src/usbc_config.c2
-rw-r--r--zephyr/program/intelrvp/adlrvp/prj.conf1
-rw-r--r--zephyr/program/intelrvp/mtlrvp/prj.conf1
-rw-r--r--zephyr/program/intelrvp/src/chg_usb_pd.c2
-rw-r--r--zephyr/program/intelrvp/src/intel_rvp_led.c2
-rw-r--r--zephyr/program/myst/CMakeLists.txt1
-rw-r--r--zephyr/program/myst/i2c.dtsi28
-rw-r--r--zephyr/program/myst/include/usbc_config.h20
-rw-r--r--zephyr/program/myst/myst/CMakeLists.txt2
-rw-r--r--zephyr/program/myst/myst/src/ppc_config.c29
-rw-r--r--zephyr/program/myst/myst/src/usb_mux_config.c92
-rw-r--r--zephyr/program/myst/program.conf8
-rw-r--r--zephyr/program/myst/src/usbc_config.c15
-rw-r--r--zephyr/program/myst/usbc.dtsi2
-rw-r--r--zephyr/program/nissa/CMakeLists.txt1
-rw-r--r--zephyr/program/nissa/craask/src/usbc.c2
-rw-r--r--zephyr/program/nissa/joxer/src/usbc.c2
-rw-r--r--zephyr/program/nissa/nereid/src/usbc.c2
-rw-r--r--zephyr/program/nissa/nivviks/src/usbc.c2
-rw-r--r--zephyr/program/nissa/pujjo/src/usbc.c2
-rw-r--r--zephyr/program/nissa/src/common.c2
-rw-r--r--zephyr/program/nissa/uldren/cbi.dtsi46
-rw-r--r--zephyr/program/nissa/uldren/led_policy.dtsi2
-rw-r--r--zephyr/program/nissa/uldren/src/fan.c41
-rw-r--r--zephyr/program/nissa/uldren/src/usbc.c2
-rw-r--r--zephyr/program/nissa/xivu/led_policy.dtsi4
-rw-r--r--zephyr/program/nissa/xivu/src/usbc.c2
-rw-r--r--zephyr/program/nissa/xivur/src/usbc.c2
-rw-r--r--zephyr/program/nissa/yaviks/project.conf3
-rw-r--r--zephyr/program/nissa/yaviks/src/led.c4
-rw-r--r--zephyr/program/nissa/yaviks/src/usbc.c21
-rw-r--r--zephyr/program/nissa/yavilla/gpio.dtsi3
-rw-r--r--zephyr/program/nissa/yavilla/project.conf4
-rw-r--r--zephyr/program/nissa/yavilla/src/keyboard.c72
-rw-r--r--zephyr/program/nissa/yavilla/src/led.c98
-rw-r--r--zephyr/program/nissa/yavilla/src/usbc.c21
-rw-r--r--zephyr/program/rex/program.conf3
-rw-r--r--zephyr/program/rex/src/usbc_config.c1
-rw-r--r--zephyr/program/skyrim/frostflow/led_policy.dtsi4
-rw-r--r--zephyr/program/skyrim/frostflow/src/usb_mux_config.c25
-rw-r--r--zephyr/program/skyrim/markarth/led_policy.dtsi6
-rw-r--r--zephyr/program/skyrim/markarth/project.conf4
-rw-r--r--zephyr/program/skyrim/src/power_signals.c12
-rw-r--r--zephyr/program/skyrim/src/usbc_config.c1
-rw-r--r--zephyr/program/skyrim/winterhold/CMakeLists.txt3
-rw-r--r--zephyr/program/skyrim/winterhold/src/fan.c90
-rw-r--r--zephyr/program/skyrim/winterhold/src/thermal.c81
55 files changed, 534 insertions, 305 deletions
diff --git a/zephyr/program/corsola/magikarp/project.overlay b/zephyr/program/corsola/magikarp/project.overlay
index 3628f6770d..349e066f07 100644
--- a/zephyr/program/corsola/magikarp/project.overlay
+++ b/zephyr/program/corsola/magikarp/project.overlay
@@ -224,8 +224,7 @@
bat-power-state-charge {
charge-state = "PWR_STATE_CHARGE";
/* Battery percent range (>= Empty, <= 94%) */
- batt-lvl = <BATTERY_LEVEL_EMPTY
- (BATTERY_LEVEL_NEAR_FULL - 3)>;
+ batt-lvl = <BATTERY_LEVEL_EMPTY 94>;
color-0 {
led-color = <&color_battery_amber>;
};
@@ -234,8 +233,7 @@
bat-power-state-charge-near-full {
charge-state = "PWR_STATE_CHARGE";
/* Battery percent range (>= 95%, <= Full) */
- batt-lvl = <(BATTERY_LEVEL_NEAR_FULL - 2)
- BATTERY_LEVEL_FULL>;
+ batt-lvl = <95 BATTERY_LEVEL_FULL>;
color-0 {
led-color = <&color_battery_white>;
};
diff --git a/zephyr/program/corsola/src/npcx_usbc.c b/zephyr/program/corsola/src/npcx_usbc.c
index 10a977696e..2e1d8d11c5 100644
--- a/zephyr/program/corsola/src/npcx_usbc.c
+++ b/zephyr/program/corsola/src/npcx_usbc.c
@@ -11,6 +11,7 @@
#endif
#include "baseboard_usbc_config.h"
+#include "battery.h"
#include "console.h"
#include "driver/ppc/nx20p348x.h"
#include "driver/tcpm/anx7447.h"
@@ -53,8 +54,10 @@ DECLARE_HOOK(HOOK_INIT, board_usb_mux_init, HOOK_PRIO_INIT_I2C + 1);
void board_tcpc_init(void)
{
- /* Only reset TCPC if not sysjump */
- if (!system_jumped_late()) {
+ /* Reset TCPC if we only we have a battery connected, or the SINK
+ * gpio to the PPC might be reset and cause brown-out.
+ */
+ if (!system_jumped_late() && battery_is_present() == BP_YES) {
/* TODO(crosbug.com/p/61098): How long do we need to wait? */
board_reset_pd_mcu();
}
@@ -84,7 +87,13 @@ __override int board_rt1718s_init(int port)
{
static bool gpio_initialized;
- if (!system_jumped_late() && !gpio_initialized) {
+ /* Reset TCPC sink/source control when it's a power-on reset or has a
+ * battery. Do not alter the carried GPIO status or this might stop PPC
+ * sinking and brown-out the system when battery disconnected.
+ */
+ if (!system_jumped_late() && !gpio_initialized &&
+ (battery_is_present() == BP_YES ||
+ (system_get_reset_flags() & EC_RESET_FLAG_POWER_ON))) {
/* set GPIO 1~3 as push pull, as output, output low. */
rt1718s_gpio_set_flags(port, RT1718S_GPIO1, GPIO_OUT_LOW);
rt1718s_gpio_set_flags(port, RT1718S_GPIO2, GPIO_OUT_LOW);
@@ -94,11 +103,18 @@ __override int board_rt1718s_init(int port)
/* gpio1 low, gpio2 output high when receiving frs signal */
RETURN_ERROR(rt1718s_update_bits8(port, RT1718S_GPIO1_VBUS_CTRL,
- RT1718S_GPIO1_VBUS_CTRL_FRS_RX_VBUS,
+ RT1718S_GPIO_VBUS_CTRL_FRS_RX_VBUS,
0));
- RETURN_ERROR(rt1718s_update_bits8(port, RT1718S_GPIO2_VBUS_CTRL,
- RT1718S_GPIO2_VBUS_CTRL_FRS_RX_VBUS,
- 0xFF));
+ /* GPIO1 EN_SNK high when received TCPCI SNK enabled command */
+ RETURN_ERROR(rt1718s_update_bits8(
+ port, RT1718S_GPIO1_VBUS_CTRL,
+ RT1718S_GPIO_VBUS_CTRL_ENA_SNK_VBUS_GPIO, 0xFF));
+ /* GPIO2 EN_SRC high when received TCPCI SRC enabled command */
+ RETURN_ERROR(rt1718s_update_bits8(
+ port, RT1718S_GPIO2_VBUS_CTRL,
+ RT1718S_GPIO_VBUS_CTRL_FRS_RX_VBUS |
+ RT1718S_GPIO_VBUS_CTRL_ENA_SRC_VBUS_GPIO,
+ 0xFF));
/* Trigger GPIO 1/2 change when FRS signal received */
RETURN_ERROR(rt1718s_update_bits8(
diff --git a/zephyr/program/corsola/src/usbc.c b/zephyr/program/corsola/src/usbc.c
index 181b3df141..71c02ff54f 100644
--- a/zephyr/program/corsola/src/usbc.c
+++ b/zephyr/program/corsola/src/usbc.c
@@ -6,7 +6,7 @@
/* Corsola baseboard-specific USB-C configuration */
#include "baseboard_usbc_config.h"
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "console.h"
#include "ec_commands.h"
#include "extpower.h"
diff --git a/zephyr/program/corsola/starmie/project.overlay b/zephyr/program/corsola/starmie/project.overlay
index d8c6a48631..2358026e2d 100644
--- a/zephyr/program/corsola/starmie/project.overlay
+++ b/zephyr/program/corsola/starmie/project.overlay
@@ -20,8 +20,8 @@
/ {
batteries {
- default_battery: c235 {
- compatible = "celxpert,c235-41", "battery-smart";
+ default_battery: b300049 {
+ compatible = "celxpert,b300049", "battery-smart";
};
};
gpio-interrupts {
diff --git a/zephyr/program/corsola/tentacruel/project.overlay b/zephyr/program/corsola/tentacruel/project.overlay
index 79e8f4a05b..e23d3561e8 100644
--- a/zephyr/program/corsola/tentacruel/project.overlay
+++ b/zephyr/program/corsola/tentacruel/project.overlay
@@ -270,8 +270,7 @@
bat-power-state-charge {
charge-state = "PWR_STATE_CHARGE";
/* Battery percent range (>= Empty, <= 94%) */
- batt-lvl = <BATTERY_LEVEL_EMPTY
- (BATTERY_LEVEL_NEAR_FULL - 3)>;
+ batt-lvl = <BATTERY_LEVEL_EMPTY 94>;
color-0 {
led-color = <&color_battery_amber>;
};
@@ -280,8 +279,7 @@
bat-power-state-charge-near-full {
charge-state = "PWR_STATE_CHARGE";
/* Battery percent range (>= 95%, <= Full) */
- batt-lvl = <(BATTERY_LEVEL_NEAR_FULL - 2)
- BATTERY_LEVEL_FULL>;
+ batt-lvl = <95 BATTERY_LEVEL_FULL>;
color-0 {
led-color = <&color_battery_white>;
};
diff --git a/zephyr/program/corsola/tentacruel/src/temp.c b/zephyr/program/corsola/tentacruel/src/temp.c
index 2e584640be..72fcc526bd 100644
--- a/zephyr/program/corsola/tentacruel/src/temp.c
+++ b/zephyr/program/corsola/tentacruel/src/temp.c
@@ -62,7 +62,7 @@ static void current_update(void)
temp = average_tempature();
#ifndef CONFIG_TEST
- if (charge_get_state() == PWR_STATE_DISCHARGE) {
+ if (led_pwr_get_state() == PWR_STATE_DISCHARGE) {
current_level = 0;
uptime = 0;
dntime = 0;
diff --git a/zephyr/program/corsola/voltorb/project.conf b/zephyr/program/corsola/voltorb/project.conf
index 3cb4f46e06..d2693d0de8 100644
--- a/zephyr/program/corsola/voltorb/project.conf
+++ b/zephyr/program/corsola/voltorb/project.conf
@@ -41,6 +41,7 @@ CONFIG_PLATFORM_EC_EXTPOWER_DEBOUNCE_MS=800
# Battery config
CONFIG_PLATFORM_EC_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV=15000
+CONFIG_PLATFORM_EC_SMART_BATTERY_OPTIONAL_MFG_FUNC=y
# Remove debug options and features for FW QUAL
CONFIG_PLATFORM_EC_SYSTEM_UNLOCKED=n
diff --git a/zephyr/program/corsola/voltorb/project.overlay b/zephyr/program/corsola/voltorb/project.overlay
index 7ae230a47e..e5c5df3ab7 100644
--- a/zephyr/program/corsola/voltorb/project.overlay
+++ b/zephyr/program/corsola/voltorb/project.overlay
@@ -81,17 +81,26 @@
compatible = "cros-ec,led-policy";
/* Voltorb LED bat charge */
- bat-power-state-charge {
+ bat-power-state-charge-lvl-1 {
charge-state = "PWR_STATE_CHARGE";
/* Battery percent range (>= Empty, <= 96%) */
- batt-lvl = <BATTERY_LEVEL_EMPTY
- (BATTERY_LEVEL_NEAR_FULL - 1)>;
+ batt-lvl = <BATTERY_LEVEL_EMPTY 96>;
color-0 {
led-color = <&color_amber>;
};
};
+ bat-power-state-charge-lvl-2 {
+ charge-state = "PWR_STATE_CHARGE";
+ /* Battery percent range (>= 97, <= 100%) */
+ batt-lvl = <97 100>;
+
+ color-0 {
+ led-color = <&color_blue>;
+ };
+ };
+
/* Voltorb LED bat charge near full */
bat-power-state-charge-near-full {
charge-state = "PWR_STATE_CHARGE_NEAR_FULL";
diff --git a/zephyr/program/geralt/src/usbc_config.c b/zephyr/program/geralt/src/usbc_config.c
index 64a55ffb75..f0c56c5a8b 100644
--- a/zephyr/program/geralt/src/usbc_config.c
+++ b/zephyr/program/geralt/src/usbc_config.c
@@ -6,7 +6,7 @@
/* Geralt baseboard-specific USB-C configuration */
#include "charge_manager.h"
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "console.h"
#include "driver/tcpm/it83xx_pd.h"
#include "gpio.h"
diff --git a/zephyr/program/intelrvp/adlrvp/prj.conf b/zephyr/program/intelrvp/adlrvp/prj.conf
index 9c372bc9ae..ef0584c4bd 100644
--- a/zephyr/program/intelrvp/adlrvp/prj.conf
+++ b/zephyr/program/intelrvp/adlrvp/prj.conf
@@ -40,7 +40,6 @@ CONFIG_PLATFORM_EC_TEMP_SENSOR_POWER=y
CONFIG_PLATFORM_EC_USB_DRP_ACC_TRYSRC=y
CONFIG_PLATFORM_EC_USB_PD_DUAL_ROLE_AUTO_TOGGLE=n
CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=y
-CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_TCPC=y
CONFIG_PLATFORM_EC_USB_PD_TCPC_RUNTIME_CONFIG=n
CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB_RUNTIME_CONFIG=n
CONFIG_PLATFORM_EC_USB_MUX_TUSB1044=y
diff --git a/zephyr/program/intelrvp/mtlrvp/prj.conf b/zephyr/program/intelrvp/mtlrvp/prj.conf
index ccc27e04f7..8fe89d712a 100644
--- a/zephyr/program/intelrvp/mtlrvp/prj.conf
+++ b/zephyr/program/intelrvp/mtlrvp/prj.conf
@@ -46,6 +46,7 @@ CONFIG_PLATFORM_EC_USBC_PPC=y
CONFIG_PLATFORM_EC_USB_PD_PPC=y
CONFIG_PLATFORM_EC_USB_PD_VBUS_DETECT_PPC=y
CONFIG_PLATFORM_EC_USB_PD_VBUS_DETECT_TCPC=y
+CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=y
CONFIG_PLATFORM_EC_USB_PD_DISCHARGE_PPC=y
CONFIG_PLATFORM_EC_USB_PD_DISCHARGE_TCPC=y
CONFIG_PLATFORM_EC_USB_PD_TCPC_LOW_POWER=y
diff --git a/zephyr/program/intelrvp/src/chg_usb_pd.c b/zephyr/program/intelrvp/src/chg_usb_pd.c
index 084617cb98..1b2c1a8736 100644
--- a/zephyr/program/intelrvp/src/chg_usb_pd.c
+++ b/zephyr/program/intelrvp/src/chg_usb_pd.c
@@ -6,7 +6,7 @@
/* Common USB PD charge configuration */
#include "charge_manager.h"
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "gpio.h"
#include "hooks.h"
#include "intelrvp.h"
diff --git a/zephyr/program/intelrvp/src/intel_rvp_led.c b/zephyr/program/intelrvp/src/intel_rvp_led.c
index 0e4d872963..91af0dfb55 100644
--- a/zephyr/program/intelrvp/src/intel_rvp_led.c
+++ b/zephyr/program/intelrvp/src/intel_rvp_led.c
@@ -80,7 +80,7 @@ static void pulse_leds(enum pwm_led_id id, int period)
static void update_charger_led(enum pwm_led_id id)
{
- enum charge_state chg_st = charge_get_state();
+ enum led_pwr_state chg_st = led_pwr_get_state();
/*
* The colors listed below are the default, but can be overridden.
diff --git a/zephyr/program/myst/CMakeLists.txt b/zephyr/program/myst/CMakeLists.txt
index c339dbeef7..ece440da75 100644
--- a/zephyr/program/myst/CMakeLists.txt
+++ b/zephyr/program/myst/CMakeLists.txt
@@ -5,6 +5,7 @@
cmake_minimum_required(VERSION 3.20.5)
find_package(Zephyr REQUIRED HINTS "${ZEPHYR_BASE}")
+cros_ec_library_include_directories(include)
zephyr_library_sources("src/common.c")
zephyr_library_sources("src/power_signals.c")
diff --git a/zephyr/program/myst/i2c.dtsi b/zephyr/program/myst/i2c.dtsi
index 58ba31911b..905cbc7f80 100644
--- a/zephyr/program/myst/i2c.dtsi
+++ b/zephyr/program/myst/i2c.dtsi
@@ -76,15 +76,16 @@
tcpc_port0: rt1716@70 {
compatible = "richtek,rt1716";
reg = <0x70>;
- tcpc-flags = <(TCPC_FLAGS_TCPCI_REV2_0)>;
- /* TBD */
+ tcpc-flags = <(
+ TCPC_FLAGS_TCPCI_REV2_0 |
+ TCPC_FLAGS_TCPCI_REV2_0_NO_VSAFE0V)>;
irq-gpios = <&gpioe 0 GPIO_ACTIVE_LOW>;
};
- ppc_port0: ktu1125@78 {
+ ppc_port0: ktu1125@38 {
compatible = "kinetic,ktu1125";
status = "okay";
- reg = <0x78>;
+ reg = <0x38>;
};
};
@@ -105,7 +106,7 @@
reg = <0x40>;
};
- tcpc_port1: rt1718s-tcpc@40 {
+ tcpc_rt1718_port1: rt1718s-tcpc@40 {
compatible = "richtek,rt1718s-tcpc";
reg = <0x40>;
tcpc-flags = <(
@@ -117,15 +118,28 @@
* the "named-gpios" node will be dealt with at a later date.
*/
irq-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>;
+ is-alt;
};
- ppc_port1: nx20p348x@71 {
+ ppc_nx20p_port1: nx20p348x@71 {
compatible = "nxp,nx20p348x";
status = "okay";
reg = <0x71>;
+ is-alt;
+ };
+
+ tcpc_ps8815_port1: ps8xxx@b {
+ compatible = "parade,ps8xxx";
+ reg = <0xb>;
+ is-alt;
};
- /* TODO: add SKU-B DB b/275610001 */
+ ppc_ktu1125_port1: ktu1125@38 {
+ compatible = "kinetic,ktu1125";
+ status = "okay";
+ reg = <0x38>;
+ is-alt;
+ };
};
&i2c_ctrl1 {
diff --git a/zephyr/program/myst/include/usbc_config.h b/zephyr/program/myst/include/usbc_config.h
new file mode 100644
index 0000000000..1c983ba8e9
--- /dev/null
+++ b/zephyr/program/myst/include/usbc_config.h
@@ -0,0 +1,20 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Myst type-c definitions */
+
+#ifndef __CROS_EC_USBC_CONFIG_H
+#define __CROS_EC_USBC_CONFIG_H
+
+void ppc_interrupt(enum gpio_signal signal);
+
+/* USB-A ports */
+enum usba_port { USBA_PORT_A0 = 0, USBA_PORT_A1, USBA_PORT_COUNT };
+
+/* USB-C ports */
+enum usbc_port { USBC_PORT_C0 = 0, USBC_PORT_C1, USBC_PORT_COUNT };
+BUILD_ASSERT(USBC_PORT_COUNT == CONFIG_USB_PD_PORT_MAX_COUNT);
+
+#endif /* __CROS_EC_USBC_CONFIG_H */
diff --git a/zephyr/program/myst/myst/CMakeLists.txt b/zephyr/program/myst/myst/CMakeLists.txt
index 9dc79f913e..09e319e8c4 100644
--- a/zephyr/program/myst/myst/CMakeLists.txt
+++ b/zephyr/program/myst/myst/CMakeLists.txt
@@ -4,6 +4,6 @@
cros_ec_library_include_directories_ifdef(CONFIG_BOARD_MYST include)
zephyr_library_sources(
- "src/ppc_config.c"
"src/keyboard.c"
+ "src/usb_mux_config.c"
)
diff --git a/zephyr/program/myst/myst/src/ppc_config.c b/zephyr/program/myst/myst/src/ppc_config.c
deleted file mode 100644
index a16e38a25d..0000000000
--- a/zephyr/program/myst/myst/src/ppc_config.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* Copyright 2023 The ChromiumOS Authors
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Myst board-specific PPC code */
-
-#include "driver/ppc/aoz1380_public.h"
-#include "driver/ppc/nx20p348x.h"
-#include "usbc_ppc.h"
-
-#include <zephyr/drivers/gpio.h>
-
-#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ##args)
-#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ##args)
-
-void ppc_interrupt(enum gpio_signal signal)
-{
- switch (signal) {
- case GPIO_USB_C0_PPC_INT_ODL:
- break;
-
- case GPIO_USB_C1_PPC_INT_ODL:
- break;
-
- default:
- break;
- }
-}
diff --git a/zephyr/program/myst/myst/src/usb_mux_config.c b/zephyr/program/myst/myst/src/usb_mux_config.c
new file mode 100644
index 0000000000..561202fd23
--- /dev/null
+++ b/zephyr/program/myst/myst/src/usb_mux_config.c
@@ -0,0 +1,92 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Myst board-specific USB-C mux configuration */
+
+#include "console.h"
+#include "cros_board_info.h"
+#include "cros_cbi.h"
+#include "hooks.h"
+#include "usb_mux.h"
+#include "usbc/ppc.h"
+#include "usbc/tcpci.h"
+#include "usbc/usb_muxes.h"
+#include "usbc_config.h"
+
+#include <zephyr/drivers/gpio.h>
+#include <zephyr/logging/log.h>
+
+LOG_MODULE_DECLARE(myst, CONFIG_MYST_LOG_LEVEL);
+
+uint32_t get_io_db_type_from_cached_cbi(void)
+{
+ uint32_t io_db_type;
+ int ret = cros_cbi_get_fw_config(FW_IO_DB, &io_db_type);
+
+ if (ret != 0) {
+ io_db_type = FW_IO_DB_NONE;
+ LOG_ERR("Failed to get IO_DB value: %d", ret);
+ }
+
+ return io_db_type;
+}
+
+__override uint8_t board_get_usb_pd_port_count(void)
+{
+ if (get_io_db_type_from_cached_cbi() == FW_IO_DB_NONE)
+ return CONFIG_USB_PD_PORT_MAX_COUNT - 1;
+ else
+ return CONFIG_USB_PD_PORT_MAX_COUNT;
+}
+
+void ppc_interrupt(enum gpio_signal signal)
+{
+ uint32_t io_db_type = get_io_db_type_from_cached_cbi();
+
+ switch (signal) {
+ case GPIO_USB_C0_PPC_INT_ODL:
+ ktu1125_interrupt(USBC_PORT_C0);
+ break;
+
+ case GPIO_USB_C1_PPC_INT_ODL:
+ if (io_db_type == FW_IO_DB_SKU_A) {
+ nx20p348x_interrupt(USBC_PORT_C1);
+ }
+ if (io_db_type == FW_IO_DB_SKU_B) {
+ ktu1125_interrupt(USBC_PORT_C1);
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void setup_mux(void)
+{
+ switch (get_io_db_type_from_cached_cbi()) {
+ default:
+ case FW_IO_DB_NONE:
+ LOG_INF("USB DB: not connected");
+ break;
+
+ case FW_IO_DB_SKU_A:
+ LOG_INF("USB DB: Setting SKU_A DB");
+ TCPC_ENABLE_ALTERNATE_BY_NODELABEL(USBC_PORT_C1,
+ tcpc_rt1718_port1);
+ PPC_ENABLE_ALTERNATE_BY_NODELABEL(USBC_PORT_C1,
+ ppc_nx20p_port1);
+ break;
+
+ case FW_IO_DB_SKU_B:
+ LOG_INF("USB DB: Setting SKU_B DB");
+ TCPC_ENABLE_ALTERNATE_BY_NODELABEL(USBC_PORT_C1,
+ tcpc_ps8815_port1);
+ PPC_ENABLE_ALTERNATE_BY_NODELABEL(USBC_PORT_C1,
+ ppc_ktu1125_port1);
+ break;
+ }
+}
+DECLARE_HOOK(HOOK_INIT, setup_mux, HOOK_PRIO_INIT_I2C);
diff --git a/zephyr/program/myst/program.conf b/zephyr/program/myst/program.conf
index 49d4cc00ad..e96b2580f4 100644
--- a/zephyr/program/myst/program.conf
+++ b/zephyr/program/myst/program.conf
@@ -78,6 +78,7 @@ CONFIG_PLATFORM_EC_CHARGER_MIN_POWER_MW_FOR_POWER_ON=50000
# USB-C
CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8815=y
+CONFIG_PLATFORM_EC_USBC_PPC=y
CONFIG_PLATFORM_EC_USBC_SS_MUX_DFP_ONLY=y
CONFIG_PLATFORM_EC_USB_MUX_RUNTIME_CONFIG=y
CONFIG_PLATFORM_EC_USB_DRP_ACC_TRYSRC=y
@@ -90,10 +91,15 @@ CONFIG_PLATFORM_EC_USB_PD_LOGGING=y
CONFIG_PLATFORM_EC_USB_PD_REV30=y
CONFIG_PLATFORM_EC_USB_PD_TBT_COMPAT_MODE=n
CONFIG_PLATFORM_EC_USB_PD_TCPC_LOW_POWER=y
-CONFIG_PLATFORM_EC_USB_PD_TCPC_RUNTIME_CONFIG=n
+CONFIG_PLATFORM_EC_USB_PD_TCPC_RUNTIME_CONFIG=y
CONFIG_PLATFORM_EC_USB_PD_USB4=n
CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=y
+# Bring up configs
+CONFIG_SHELL_HISTORY_BUFFER=256
+CONFIG_PLATFORM_EC_SYSTEM_UNLOCKED=y
+CONFIG_PLATFORM_EC_BRINGUP=y
+
# Disable FRS for bringup
CONFIG_PLATFORM_EC_USB_PD_FRS=n
CONFIG_PLATFORM_EC_USB_PD_FRS_TCPC=n
diff --git a/zephyr/program/myst/src/usbc_config.c b/zephyr/program/myst/src/usbc_config.c
index c3aafd9da9..5d2401a6af 100644
--- a/zephyr/program/myst/src/usbc_config.c
+++ b/zephyr/program/myst/src/usbc_config.c
@@ -9,11 +9,12 @@
#include "charge_manager.h"
#include "charge_ramp.h"
#include "charge_state.h"
-#include "charge_state_v2.h"
#include "charger.h"
#include "cros_board_info.h"
#include "cros_cbi.h"
#include "driver/charger/isl9241.h"
+#include "driver/ppc/ktu1125_public.h"
+#include "driver/ppc/nx20p348x.h"
#include "driver/tcpm/rt1718s.h"
#include "driver/usb_mux/amd_fp6.h"
#include "gpio/gpio_int.h"
@@ -22,6 +23,7 @@
#include "usb_mux.h"
#include "usb_pd_tcpm.h"
#include "usbc/usb_muxes.h"
+#include "usbc_config.h"
#include "usbc_ppc.h"
#include <zephyr/drivers/gpio.h>
@@ -29,13 +31,6 @@
#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ##args)
#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ##args)
-/* USB-A ports */
-enum usba_port { USBA_PORT_A0 = 0, USBA_PORT_A1, USBA_PORT_COUNT };
-
-/* USB-C ports */
-enum usbc_port { USBC_PORT_C0 = 0, USBC_PORT_C1, USBC_PORT_COUNT };
-BUILD_ASSERT(USBC_PORT_COUNT == CONFIG_USB_PD_PORT_MAX_COUNT);
-
static void usbc_interrupt_init(void)
{
/* Enable PPC interrupts. */
@@ -57,7 +52,7 @@ int board_set_active_charge_port(int port)
CPRINTSUSB("Disabling all charger ports");
/* Disable all ports. */
- for (i = 0; i < ppc_cnt; i++) {
+ for (i = 0; i < board_get_usb_pd_port_count(); i++) {
/*
* Do not return early if one fails otherwise we can
* get into a boot loop assertion failure.
@@ -83,7 +78,7 @@ int board_set_active_charge_port(int port)
* Turn off the other ports' sink path FETs, before enabling the
* requested charge port.
*/
- for (i = 0; i < ppc_cnt; i++) {
+ for (i = 0; i < board_get_usb_pd_port_count(); i++) {
if (i == port)
continue;
diff --git a/zephyr/program/myst/usbc.dtsi b/zephyr/program/myst/usbc.dtsi
index 8e8579d328..b63c0347bd 100644
--- a/zephyr/program/myst/usbc.dtsi
+++ b/zephyr/program/myst/usbc.dtsi
@@ -24,8 +24,6 @@
compatible = "named-usbc-port";
reg = <1>;
bc12 = <&bc12_port1>;
- tcpc = <&tcpc_port1>;
- ppc = <&ppc_port1>;
usb-mux-chain-1-anx {
compatible = "cros-ec,usb-mux-chain";
usb-muxes = <&amd_fp6_port1>;
diff --git a/zephyr/program/nissa/CMakeLists.txt b/zephyr/program/nissa/CMakeLists.txt
index e2f85139bf..cd45f00a3a 100644
--- a/zephyr/program/nissa/CMakeLists.txt
+++ b/zephyr/program/nissa/CMakeLists.txt
@@ -118,7 +118,6 @@ if(DEFINED CONFIG_BOARD_ULDREN)
"uldren/src/kb_backlight.c"
"uldren/src/keyboard.c"
)
- zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_FAN "uldren/src/fan.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC "uldren/src/usbc.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CHARGER "uldren/src/charger.c")
endif()
diff --git a/zephyr/program/nissa/craask/src/usbc.c b/zephyr/program/nissa/craask/src/usbc.c
index 88fc54d3a3..5df3a09bb8 100644
--- a/zephyr/program/nissa/craask/src/usbc.c
+++ b/zephyr/program/nissa/craask/src/usbc.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "chipset.h"
#include "driver/charger/isl923x_public.h"
#include "driver/retimer/anx7483_public.h"
diff --git a/zephyr/program/nissa/joxer/src/usbc.c b/zephyr/program/nissa/joxer/src/usbc.c
index e3e18e0f33..54fea2f663 100644
--- a/zephyr/program/nissa/joxer/src/usbc.c
+++ b/zephyr/program/nissa/joxer/src/usbc.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "chipset.h"
#include "driver/charger/sm5803.h"
#include "driver/tcpm/it83xx_pd.h"
diff --git a/zephyr/program/nissa/nereid/src/usbc.c b/zephyr/program/nissa/nereid/src/usbc.c
index e3e18e0f33..54fea2f663 100644
--- a/zephyr/program/nissa/nereid/src/usbc.c
+++ b/zephyr/program/nissa/nereid/src/usbc.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "chipset.h"
#include "driver/charger/sm5803.h"
#include "driver/tcpm/it83xx_pd.h"
diff --git a/zephyr/program/nissa/nivviks/src/usbc.c b/zephyr/program/nissa/nivviks/src/usbc.c
index 88fc54d3a3..5df3a09bb8 100644
--- a/zephyr/program/nissa/nivviks/src/usbc.c
+++ b/zephyr/program/nissa/nivviks/src/usbc.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "chipset.h"
#include "driver/charger/isl923x_public.h"
#include "driver/retimer/anx7483_public.h"
diff --git a/zephyr/program/nissa/pujjo/src/usbc.c b/zephyr/program/nissa/pujjo/src/usbc.c
index 59d876c4db..0b5fe3b809 100644
--- a/zephyr/program/nissa/pujjo/src/usbc.c
+++ b/zephyr/program/nissa/pujjo/src/usbc.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "chipset.h"
#include "driver/charger/isl923x_public.h"
#include "driver/retimer/anx7483_public.h"
diff --git a/zephyr/program/nissa/src/common.c b/zephyr/program/nissa/src/common.c
index def29ccd02..aaca2ecc6b 100644
--- a/zephyr/program/nissa/src/common.c
+++ b/zephyr/program/nissa/src/common.c
@@ -4,7 +4,7 @@
*/
#include "battery.h"
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "charger.h"
#include "chipset.h"
#include "hooks.h"
diff --git a/zephyr/program/nissa/uldren/cbi.dtsi b/zephyr/program/nissa/uldren/cbi.dtsi
index 9d865a38bb..02aa0607f9 100644
--- a/zephyr/program/nissa/uldren/cbi.dtsi
+++ b/zephyr/program/nissa/uldren/cbi.dtsi
@@ -7,44 +7,47 @@
/* Uldren-specific fw_config fields. */
nissa-fw-config {
/*
- * FW_CONFIG field to enable KB back light or not.
+ * FW_CONFIG field to enable USB DB.
*/
- kb-bl {
- enum-name = "FW_KB_BL";
- start = <4>;
- size = <1>;
+ sub-board {
+ enum-name = "FW_SUB_BOARD";
+ start = <1>;
+ size = <2>;
- no-kb-bl {
+ sub-board-1 {
compatible = "cros-ec,cbi-fw-config-value";
- enum-name = "FW_KB_BL_NOT_PRESENT";
+ enum-name = "FW_SUB_BOARD_1";
value = <0>;
- default;
};
- kb-bl-present {
+ sub-board-2 {
compatible = "cros-ec,cbi-fw-config-value";
- enum-name = "FW_KB_BL_PRESENT";
- value = <1>;
+ enum-name = "FW_SUB_BOARD_2";
+ value = <3>;
+ };
+ sub-board-3 {
+ compatible = "cros-ec,cbi-fw-config-value";
+ enum-name = "FW_SUB_BOARD_3";
+ value = <2>;
};
};
-
/*
- * FW_CONFIG field to enable USB DB.
+ * FW_CONFIG field to enable KB back light or not.
*/
- db-usb {
- enum-name = "FW_DB_USB";
- start = <6>;
+ kb-bl {
+ enum-name = "FW_KB_BL";
+ start = <5>;
size = <1>;
- no-db-usb {
+ no-kb-bl {
compatible = "cros-ec,cbi-fw-config-value";
- enum-name = "FW_DB_USB_NOT_PRESENT";
+ enum-name = "FW_KB_BL_NOT_PRESENT";
value = <0>;
+ default;
};
- db-usb-present {
+ kb-bl-present {
compatible = "cros-ec,cbi-fw-config-value";
- enum-name = "FW_DB_USB_PRESENT";
+ enum-name = "FW_KB_BL_PRESENT";
value = <1>;
- default;
};
};
@@ -67,5 +70,6 @@
value = <1>;
};
};
+/delete-node/ fan;
};
};
diff --git a/zephyr/program/nissa/uldren/led_policy.dtsi b/zephyr/program/nissa/uldren/led_policy.dtsi
index 95c614cafc..afc4e25f71 100644
--- a/zephyr/program/nissa/uldren/led_policy.dtsi
+++ b/zephyr/program/nissa/uldren/led_policy.dtsi
@@ -7,7 +7,7 @@
power-state-charge {
charge-state = "PWR_STATE_CHARGE";
batt-lvl = <BATTERY_LEVEL_EMPTY
- BATTERY_LEVEL_NEAR_FULL>;
+ BATTERY_LEVEL_FULL>;
color-0 {
led-color = <&color_white>;
diff --git a/zephyr/program/nissa/uldren/src/fan.c b/zephyr/program/nissa/uldren/src/fan.c
deleted file mode 100644
index 32f9d3c65e..0000000000
--- a/zephyr/program/nissa/uldren/src/fan.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Copyright 2023 The ChromiumOS Authors
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "cros_cbi.h"
-#include "fan.h"
-#include "gpio/gpio.h"
-#include "hooks.h"
-
-#include <zephyr/devicetree.h>
-#include <zephyr/drivers/gpio.h>
-#include <zephyr/logging/log.h>
-
-LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL);
-
-/*
- * Nirwen fan support
- */
-static void fan_init(void)
-{
- int ret;
- uint32_t val;
- /*
- * Retrieve the fan config.
- */
- ret = cros_cbi_get_fw_config(FW_FAN, &val);
- if (ret != 0) {
- LOG_ERR("Error retrieving CBI FW_CONFIG field %d", FW_FAN);
- return;
- }
- if (val != FW_FAN_PRESENT) {
- /* Disable the fan */
- fan_set_count(0);
- } else {
- /* Configure the fan enable GPIO */
- gpio_pin_configure_dt(GPIO_DT_FROM_NODELABEL(gpio_fan_enable),
- GPIO_OUTPUT);
- }
-}
-DECLARE_HOOK(HOOK_INIT, fan_init, HOOK_PRIO_POST_FIRST);
diff --git a/zephyr/program/nissa/uldren/src/usbc.c b/zephyr/program/nissa/uldren/src/usbc.c
index aaba5492dd..33c63472e8 100644
--- a/zephyr/program/nissa/uldren/src/usbc.c
+++ b/zephyr/program/nissa/uldren/src/usbc.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "chipset.h"
#include "driver/charger/isl923x_public.h"
#include "driver/retimer/anx7483_public.h"
diff --git a/zephyr/program/nissa/xivu/led_policy.dtsi b/zephyr/program/nissa/xivu/led_policy.dtsi
index 562e361ec5..598480f865 100644
--- a/zephyr/program/nissa/xivu/led_policy.dtsi
+++ b/zephyr/program/nissa/xivu/led_policy.dtsi
@@ -14,8 +14,8 @@
power-state-charge-lvl-2 {
charge-state = "PWR_STATE_CHARGE";
- /* Battery percent range (>= 95%, <= Near Full) */
- batt-lvl = <95 97>;
+ /* Battery percent range (>= 95%, <= 100%) */
+ batt-lvl = <95 100>;
color-0 {
led-color = <&color_white>;
diff --git a/zephyr/program/nissa/xivu/src/usbc.c b/zephyr/program/nissa/xivu/src/usbc.c
index 6b95a3b1f4..d77abf37db 100644
--- a/zephyr/program/nissa/xivu/src/usbc.c
+++ b/zephyr/program/nissa/xivu/src/usbc.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "chipset.h"
#include "driver/charger/isl923x_public.h"
#include "driver/retimer/anx7483_public.h"
diff --git a/zephyr/program/nissa/xivur/src/usbc.c b/zephyr/program/nissa/xivur/src/usbc.c
index 639bd3adbb..a0bd74b3a6 100644
--- a/zephyr/program/nissa/xivur/src/usbc.c
+++ b/zephyr/program/nissa/xivur/src/usbc.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "chipset.h"
#include "driver/charger/isl923x_public.h"
#include "driver/retimer/anx7483_public.h"
diff --git a/zephyr/program/nissa/yaviks/project.conf b/zephyr/program/nissa/yaviks/project.conf
index 2e52005cad..06c63967c6 100644
--- a/zephyr/program/nissa/yaviks/project.conf
+++ b/zephyr/program/nissa/yaviks/project.conf
@@ -45,3 +45,6 @@ CONFIG_PLATFORM_EC_USB_PORT_POWER_SMART=y
CONFIG_PLATFORM_EC_USB_PORT_POWER_SMART_CDP_SDP_ONLY=y
CONFIG_PLATFORM_EC_USB_PORT_POWER_SMART_DEFAULT_CDP=y
CONFIG_PLATFORM_EC_USB_PORT_POWER_SMART_INVERTED=y
+
+# Charger
+CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT=0
diff --git a/zephyr/program/nissa/yaviks/src/led.c b/zephyr/program/nissa/yaviks/src/led.c
index 7671bd3a92..db93ae4b47 100644
--- a/zephyr/program/nissa/yaviks/src/led.c
+++ b/zephyr/program/nissa/yaviks/src/led.c
@@ -140,7 +140,7 @@ static void led_set_battery(void)
* system suspend with non-charging state.
*/
if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) &&
- charge_get_state() != PWR_STATE_CHARGE) {
+ led_pwr_get_state() != PWR_STATE_CHARGE) {
suspend_ticks++;
led_set_color_battery(RIGHT_PORT,
@@ -158,7 +158,7 @@ static void led_set_battery(void)
suspend_ticks = 0;
- switch (charge_get_state()) {
+ switch (led_pwr_get_state()) {
case PWR_STATE_CHARGE:
/* Always indicate when charging, even in suspend. */
set_active_port_color(LED_AMBER);
diff --git a/zephyr/program/nissa/yaviks/src/usbc.c b/zephyr/program/nissa/yaviks/src/usbc.c
index c9950ae73b..307109fa9d 100644
--- a/zephyr/program/nissa/yaviks/src/usbc.c
+++ b/zephyr/program/nissa/yaviks/src/usbc.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "chipset.h"
#include "driver/charger/sm5803.h"
#include "driver/tcpm/it83xx_pd.h"
@@ -235,6 +235,25 @@ __override void typec_set_source_current_limit(int port, enum tcpc_rp_value rp)
}
}
+__override void board_set_charge_limit(int port, int supplier, int charge_ma,
+ int max_ma, int charge_mv)
+{
+ /*
+ * b:213937755: Yaviks C1 port is OCPC (One Charger IC Per Type-C)
+ * architecture, The charging current is controlled by increasing Vsys.
+ * However, the charger SM5803 is not limit current while Vsys
+ * increasing, we can see the current overshoot to ~3.6A to cause
+ * C1 port brownout with low power charger (5V). To avoid C1 port
+ * brownout at low power charger connected. Limit charge current to 2A.
+ */
+ if (charge_mv <= 5000 && port == 1)
+ charge_ma = MIN(charge_ma, 2000);
+ else
+ charge_ma = charge_ma * 96 / 100;
+
+ charge_set_input_current_limit(charge_ma, charge_mv);
+}
+
void board_reset_pd_mcu(void)
{
/*
diff --git a/zephyr/program/nissa/yavilla/gpio.dtsi b/zephyr/program/nissa/yavilla/gpio.dtsi
index d063b897d9..a18e674b11 100644
--- a/zephyr/program/nissa/yavilla/gpio.dtsi
+++ b/zephyr/program/nissa/yavilla/gpio.dtsi
@@ -209,6 +209,9 @@
gpio_c0_charger_led_amber_l: c0_charger_led_amber_l {
gpios = <&gpioj 7 GPIO_OUTPUT_HIGH>;
};
+ gpio_power_led_white_l: power_led_white_l {
+ gpios = <&gpioa 3 GPIO_OUTPUT_HIGH>;
+ };
gpio_ec_kso_02_inv: ec_kso_02_inv {
gpios = <&gpioksol 2 GPIO_OUTPUT_HIGH>;
enum-name = "GPIO_KBD_KSO2";
diff --git a/zephyr/program/nissa/yavilla/project.conf b/zephyr/program/nissa/yavilla/project.conf
index bbabd05b37..30818c4419 100644
--- a/zephyr/program/nissa/yavilla/project.conf
+++ b/zephyr/program/nissa/yavilla/project.conf
@@ -31,6 +31,7 @@ CONFIG_PLATFORM_EC_CUSTOM_FAN_CONTROL=y
# LED
CONFIG_PLATFORM_EC_LED_PWM=n
+CONFIG_PLATFORM_EC_LED_ONOFF_STATES=n
CONFIG_NISSA_SUB_BOARD=n
@@ -40,3 +41,6 @@ CONFIG_PLATFORM_EC_USB_PORT_POWER_SMART=y
CONFIG_PLATFORM_EC_USB_PORT_POWER_SMART_CDP_SDP_ONLY=y
CONFIG_PLATFORM_EC_USB_PORT_POWER_SMART_DEFAULT_CDP=y
CONFIG_PLATFORM_EC_USB_PORT_POWER_SMART_INVERTED=y
+
+# Charger
+CONFIG_PLATFORM_EC_CHARGER_INPUT_CURRENT_DERATE_PCT=0
diff --git a/zephyr/program/nissa/yavilla/src/keyboard.c b/zephyr/program/nissa/yavilla/src/keyboard.c
index 93db22132f..d942405faa 100644
--- a/zephyr/program/nissa/yavilla/src/keyboard.c
+++ b/zephyr/program/nissa/yavilla/src/keyboard.c
@@ -1,4 +1,4 @@
-/* Copyright 2022 The ChromiumOS Authors
+/* Copyright 2023 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -14,24 +14,8 @@
LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL);
-/* Keyboard scan setting */
-__override struct keyboard_scan_config keyscan_config = {
- /* Increase from 50 us, because KSO_02 passes through the H1. */
- .output_settle_us = 80,
- /* Other values should be the same as the default configuration. */
- .debounce_down_us = 9 * MSEC,
- .debounce_up_us = 30 * MSEC,
- .scan_period_us = 3 * MSEC,
- .min_post_scan_delay_us = 1000,
- .poll_timeout_us = 100 * MSEC,
- .actual_key_mask = {
- 0x1c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xa4, 0xff, 0xf6, 0x55, 0xfe, 0xff, 0xff, 0xff, /* full set */
- },
-};
-
-static const struct ec_response_keybd_config yavilla_kb_w_kb_light = {
- .num_top_row_keys = 13,
+static const struct ec_response_keybd_config kb_tablet_present = {
+ .num_top_row_keys = 10,
.action_keys = {
TK_BACK, /* T1 */
TK_REFRESH, /* T2 */
@@ -40,18 +24,16 @@ static const struct ec_response_keybd_config yavilla_kb_w_kb_light = {
TK_SNAPSHOT, /* T5 */
TK_BRIGHTNESS_DOWN, /* T6 */
TK_BRIGHTNESS_UP, /* T7 */
- TK_KBD_BKLIGHT_TOGGLE, /* T8 */
- TK_PLAY_PAUSE, /* T9 */
- TK_MICMUTE, /* T10 */
- TK_VOL_MUTE, /* T11 */
- TK_VOL_DOWN, /* T12 */
- TK_VOL_UP, /* T13 */
+ TK_VOL_MUTE, /* T8 */
+ TK_VOL_DOWN, /* T9 */
+ TK_VOL_UP, /* T10 */
},
- .capabilities = KEYBD_CAP_NUMERIC_KEYPAD,
+ .capabilities = KEYBD_CAP_SCRNLOCK_KEY,
+ /* No function keys, no numeric keypad */
};
-static const struct ec_response_keybd_config yavilla_kb_wo_kb_light = {
- .num_top_row_keys = 13,
+static const struct ec_response_keybd_config kb_tablet_absent = {
+ .num_top_row_keys = 10,
.action_keys = {
TK_BACK, /* T1 */
TK_REFRESH, /* T2 */
@@ -60,14 +42,11 @@ static const struct ec_response_keybd_config yavilla_kb_wo_kb_light = {
TK_SNAPSHOT, /* T5 */
TK_BRIGHTNESS_DOWN, /* T6 */
TK_BRIGHTNESS_UP, /* T7 */
- TK_PLAY_PAUSE, /* T8 */
- TK_MICMUTE, /* T9 */
- TK_VOL_MUTE, /* T10 */
- TK_VOL_DOWN, /* T11 */
- TK_VOL_UP, /* T12 */
- TK_MENU, /* T13 */
+ TK_VOL_MUTE, /* T8 */
+ TK_VOL_DOWN, /* T9 */
+ TK_VOL_UP, /* T10 */
},
- .capabilities = KEYBD_CAP_NUMERIC_KEYPAD,
+ /* No function keys, no numeric keypad and no screenlock key */
};
__override const struct ec_response_keybd_config *
@@ -75,12 +54,12 @@ board_vivaldi_keybd_config(void)
{
uint32_t val;
- cros_cbi_get_fw_config(FW_KB_BACKLIGHT, &val);
+ cros_cbi_get_fw_config(FW_TABLET, &val);
- if (val == FW_KB_BACKLIGHT_OFF)
- return &yavilla_kb_wo_kb_light;
+ if (val == FW_TABLET_PRESENT)
+ return &kb_tablet_present;
else
- return &yavilla_kb_w_kb_light;
+ return &kb_tablet_absent;
}
/*
@@ -109,17 +88,16 @@ DECLARE_HOOK(HOOK_INIT, kb_layout_init, HOOK_PRIO_POST_FIRST);
/*
* Map keyboard connector pins to EC GPIO pins for factory test.
* Pins mapped to {-1, -1} are skipped.
- * The connector has 30 pins total, and there is no pin 0.
+ * The connector has 24 pins total, and there is no pin 0.
*/
const int keyboard_factory_scan_pins[][2] = {
{ -1, -1 }, { GPIO_KSOH, 4 }, { GPIO_KSOH, 0 }, { GPIO_KSOH, 1 },
- { GPIO_KSOH, 3 }, { GPIO_KSOH, 2 }, { -1, -1 }, { -1, -1 },
- { GPIO_KSOL, 5 }, { GPIO_KSOL, 6 }, { -1, -1 }, { GPIO_KSOL, 3 },
- { GPIO_KSOL, 2 }, { GPIO_KSI, 0 }, { GPIO_KSOL, 1 }, { GPIO_KSOL, 4 },
- { GPIO_KSI, 3 }, { GPIO_KSI, 2 }, { GPIO_KSOL, 0 }, { GPIO_KSI, 5 },
- { GPIO_KSI, 4 }, { GPIO_KSOL, 7 }, { GPIO_KSI, 6 }, { GPIO_KSI, 7 },
- { GPIO_KSI, 1 }, { -1, -1 }, { GPIO_KSOH, 5 }, { -1, -1 },
- { GPIO_KSOH, 6 }, { -1, -1 }, { -1, -1 },
+ { GPIO_KSOH, 3 }, { GPIO_KSOH, 2 }, { GPIO_KSOL, 5 }, { GPIO_KSOL, 6 },
+ { GPIO_KSOL, 3 }, { GPIO_KSOL, 2 }, { GPIO_KSI, 0 }, { GPIO_KSOL, 1 },
+ { GPIO_KSOL, 4 }, { GPIO_KSI, 3 }, { GPIO_KSI, 2 }, { GPIO_KSOL, 0 },
+ { GPIO_KSI, 5 }, { GPIO_KSI, 4 }, { GPIO_KSOL, 7 }, { GPIO_KSI, 6 },
+ { GPIO_KSI, 7 }, { GPIO_KSI, 1 }, { -1, -1 }, { -1, -1 },
+ { -1, -1 },
};
const int keyboard_factory_scan_pins_used =
ARRAY_SIZE(keyboard_factory_scan_pins);
diff --git a/zephyr/program/nissa/yavilla/src/led.c b/zephyr/program/nissa/yavilla/src/led.c
index a1ae6b24cf..d123af8142 100644
--- a/zephyr/program/nissa/yavilla/src/led.c
+++ b/zephyr/program/nissa/yavilla/src/led.c
@@ -7,6 +7,7 @@
#include "charge_manager.h"
#include "charge_state.h"
#include "chipset.h"
+#include "cros_cbi.h"
#include "ec_commands.h"
#include "gpio.h"
#include "hooks.h"
@@ -15,9 +16,16 @@
#include <stdint.h>
+#include <zephyr/logging/log.h>
+
+LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL);
+
#define BAT_LED_ON 0
#define BAT_LED_OFF 1
+#define PWR_LED_ON 0
+#define PWR_LED_OFF 1
+
#define BATT_LOW_BCT 10
#define LED_TICKS_PER_CYCLE 4
@@ -25,8 +33,11 @@
#define LED_ON_TICKS 2
#define POWER_LED_ON_S3_TICKS 2
-const enum ec_led_id supported_led_ids[] = { EC_LED_ID_LEFT_LED,
- EC_LED_ID_RIGHT_LED };
+static bool power_led_support;
+
+const enum ec_led_id supported_led_ids[] = { EC_LED_ID_RIGHT_LED,
+ EC_LED_ID_LEFT_LED,
+ EC_LED_ID_POWER_LED };
const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
@@ -37,16 +48,16 @@ enum led_color {
LED_COLOR_COUNT /* Number of colors, not a color itself */
};
-enum led_port { LEFT_PORT = 0, RIGHT_PORT };
+enum led_port { RIGHT_PORT = 0, LEFT_PORT };
static void led_set_color_battery(int port, enum led_color color)
{
const struct gpio_dt_spec *amber_led, *white_led;
- if (port == LEFT_PORT) {
+ if (port == RIGHT_PORT) {
amber_led = GPIO_DT_FROM_NODELABEL(gpio_c0_charger_led_amber_l);
white_led = GPIO_DT_FROM_NODELABEL(gpio_c0_charger_led_white_l);
- } else if (port == RIGHT_PORT) {
+ } else if (port == LEFT_PORT) {
amber_led = GPIO_DT_FROM_NODELABEL(gpio_c1_charger_led_amber_l);
white_led = GPIO_DT_FROM_NODELABEL(gpio_c1_charger_led_white_l);
}
@@ -69,6 +80,22 @@ static void led_set_color_battery(int port, enum led_color color)
}
}
+static void led_set_color_power(enum led_color color)
+{
+ switch (color) {
+ case LED_OFF:
+ gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_power_led_white_l),
+ PWR_LED_OFF);
+ break;
+ case LED_WHITE:
+ gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_power_led_white_l),
+ PWR_LED_ON);
+ break;
+ default:
+ break;
+ }
+}
+
void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
{
switch (led_id) {
@@ -80,6 +107,9 @@ void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
brightness_range[EC_LED_COLOR_WHITE] = 1;
brightness_range[EC_LED_COLOR_AMBER] = 1;
break;
+ case EC_LED_ID_POWER_LED:
+ brightness_range[EC_LED_COLOR_WHITE] = 1;
+ break;
default:
break;
}
@@ -104,6 +134,12 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
else
led_set_color_battery(RIGHT_PORT, LED_OFF);
break;
+ case EC_LED_ID_POWER_LED:
+ if (brightness[EC_LED_COLOR_WHITE] != 0)
+ led_set_color_power(LED_WHITE);
+ else
+ led_set_color_power(LED_OFF);
+ break;
default:
return EC_ERROR_PARAM1;
}
@@ -135,12 +171,12 @@ static void led_set_battery(void)
battery_ticks++;
/*
- * Override battery LEDs for Yavilla, Yavilla is non-power LED
- * design, blinking both two side battery white LEDs to indicate
+ * Override battery LEDs for Yavilla without power led support,
+ * blinking both two side battery white LEDs to indicate
* system suspend with non-charging state.
*/
- if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) &&
- charge_get_state() != PWR_STATE_CHARGE) {
+ if (!power_led_support && chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) &&
+ led_pwr_get_state() != PWR_STATE_CHARGE) {
suspend_ticks++;
led_set_color_battery(RIGHT_PORT,
@@ -158,7 +194,7 @@ static void led_set_battery(void)
suspend_ticks = 0;
- switch (charge_get_state()) {
+ switch (led_pwr_get_state()) {
case PWR_STATE_CHARGE:
/* Always indicate when charging, even in suspend. */
set_active_port_color(LED_AMBER);
@@ -223,9 +259,51 @@ static void led_set_battery(void)
}
}
+static void led_set_power(void)
+{
+ static int power_ticks;
+
+ power_ticks++;
+
+ if (chipset_in_state(CHIPSET_STATE_ON))
+ led_set_color_power(LED_WHITE);
+ else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND))
+ led_set_color_power((power_ticks % LED_TICKS_PER_CYCLE_S3 <
+ POWER_LED_ON_S3_TICKS) ?
+ LED_WHITE :
+ LED_OFF);
+ else
+ led_set_color_power(LED_OFF);
+}
+
+static void power_led_check(void)
+{
+ int ret;
+ uint32_t val;
+
+ /*
+ * Retrieve the tablet config.
+ */
+ ret = cros_cbi_get_fw_config(FW_TABLET, &val);
+ if (ret != 0) {
+ LOG_ERR("Error retrieving CBI FW_CONFIG field %d", FW_TABLET);
+ return;
+ }
+
+ if (val == FW_TABLET_PRESENT)
+ power_led_support = true;
+ else /* Clameshell */
+ power_led_support = false;
+}
+DECLARE_HOOK(HOOK_INIT, power_led_check, HOOK_PRIO_DEFAULT);
+
/* Called by hook task every TICK(IT83xx 500ms) */
static void led_tick(void)
{
led_set_battery();
+
+ if (power_led_support &&
+ led_auto_control_is_enabled(EC_LED_ID_POWER_LED))
+ led_set_power();
}
DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);
diff --git a/zephyr/program/nissa/yavilla/src/usbc.c b/zephyr/program/nissa/yavilla/src/usbc.c
index c9950ae73b..3cbdd23625 100644
--- a/zephyr/program/nissa/yavilla/src/usbc.c
+++ b/zephyr/program/nissa/yavilla/src/usbc.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-#include "charge_state_v2.h"
+#include "charge_state.h"
#include "chipset.h"
#include "driver/charger/sm5803.h"
#include "driver/tcpm/it83xx_pd.h"
@@ -235,6 +235,25 @@ __override void typec_set_source_current_limit(int port, enum tcpc_rp_value rp)
}
}
+__override void board_set_charge_limit(int port, int supplier, int charge_ma,
+ int max_ma, int charge_mv)
+{
+ /*
+ * b:213937755: Yavilla C1 port is OCPC (One Charger IC Per Type-C)
+ * architecture, The charging current is controlled by increasing Vsys.
+ * However, the charger SM5803 is not limit current while Vsys
+ * increasing, we can see the current overshoot to ~3.6A to cause
+ * C1 port brownout with low power charger (5V). To avoid C1 port
+ * brownout at low power charger connected. Limit charge current to 2A.
+ */
+ if (charge_mv <= 5000 && port == 1)
+ charge_ma = MIN(charge_ma, 2000);
+ else
+ charge_ma = charge_ma * 96 / 100;
+
+ charge_set_input_current_limit(charge_ma, charge_mv);
+}
+
void board_reset_pd_mcu(void)
{
/*
diff --git a/zephyr/program/rex/program.conf b/zephyr/program/rex/program.conf
index 0e572e373c..0dd7f48994 100644
--- a/zephyr/program/rex/program.conf
+++ b/zephyr/program/rex/program.conf
@@ -137,3 +137,6 @@ CONFIG_PLATFORM_EC_TABLET_MODE_SWITCH=y
CONFIG_PLATFORM_EC_ACCELGYRO_LSM6DSO=y
CONFIG_PLATFORM_EC_ACCEL_LIS2DW12=y
CONFIG_PLATFORM_EC_ALS_TCS3400=y
+
+# System Boot Time
+CONFIG_SYSTEM_BOOT_TIME_LOGGING=y
diff --git a/zephyr/program/rex/src/usbc_config.c b/zephyr/program/rex/src/usbc_config.c
index d2471c3daf..115d010ff5 100644
--- a/zephyr/program/rex/src/usbc_config.c
+++ b/zephyr/program/rex/src/usbc_config.c
@@ -7,7 +7,6 @@
#include "charge_manager.h"
#include "charge_ramp.h"
#include "charge_state.h"
-#include "charge_state_v2.h"
#include "charger.h"
#include "driver/charger/isl9241.h"
#include "driver/ppc/nx20p348x.h"
diff --git a/zephyr/program/skyrim/frostflow/led_policy.dtsi b/zephyr/program/skyrim/frostflow/led_policy.dtsi
index 28e33219a0..178ba9085a 100644
--- a/zephyr/program/skyrim/frostflow/led_policy.dtsi
+++ b/zephyr/program/skyrim/frostflow/led_policy.dtsi
@@ -14,8 +14,8 @@
power-state-charge-lvl-2 {
charge-state = "PWR_STATE_CHARGE";
- /* Battery percent range (>= 95%, <= Near Full) */
- batt-lvl = <95 97>;
+ /* Battery percent range (>= 95%, <= 100%) */
+ batt-lvl = <95 100>;
color-0 {
led-color = <&color_white>;
diff --git a/zephyr/program/skyrim/frostflow/src/usb_mux_config.c b/zephyr/program/skyrim/frostflow/src/usb_mux_config.c
index b73c6370b8..c7c03bc8cb 100644
--- a/zephyr/program/skyrim/frostflow/src/usb_mux_config.c
+++ b/zephyr/program/skyrim/frostflow/src/usb_mux_config.c
@@ -5,6 +5,7 @@
/* Frostflow board-specific USB-C mux configuration */
+#include "ap_power/ap_power.h"
#include "chipset.h"
#include "common.h"
#include "console.h"
@@ -175,8 +176,26 @@ void baseboard_a1_retimer_setup(void)
}
DECLARE_DEFERRED(baseboard_a1_retimer_setup);
-void board_chipset_startup(void)
+test_export_static void board_resume_change(struct ap_power_ev_callback *cb,
+ struct ap_power_ev_data data)
{
- hook_call_deferred(&baseboard_a1_retimer_setup_data, 500 * MSEC);
+ switch (data.event) {
+ default:
+ return;
+
+ case AP_POWER_STARTUP:
+ /* Any retimer tuning can be done after the retimer turns on */
+ hook_call_deferred(&baseboard_a1_retimer_setup_data, 20 * MSEC);
+ break;
+ }
+}
+
+void board_callback_init(void)
+{
+ static struct ap_power_ev_callback cb;
+
+ /* Setup a resume callback */
+ ap_power_ev_init_callback(&cb, board_resume_change, AP_POWER_STARTUP);
+ ap_power_ev_add_callback(&cb);
}
-DECLARE_HOOK(HOOK_INIT, board_chipset_startup, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_INIT, board_callback_init, HOOK_PRIO_DEFAULT);
diff --git a/zephyr/program/skyrim/markarth/led_policy.dtsi b/zephyr/program/skyrim/markarth/led_policy.dtsi
index 07354d3060..78a6488d7a 100644
--- a/zephyr/program/skyrim/markarth/led_policy.dtsi
+++ b/zephyr/program/skyrim/markarth/led_policy.dtsi
@@ -44,14 +44,14 @@
charge-state = "PWR_STATE_DISCHARGE";
chipset-state = "POWER_S3";
- /* Blue 1 sec, off 1 sec */
+ /* Amber 1 sec, off 3 sec */
color-0 {
- led-color = <&color_blue>;
+ led-color = <&color_amber>;
period-ms = <1000>;
};
color-1 {
led-color = <&color_off>;
- period-ms = <1000>;
+ period-ms = <3000>;
};
};
diff --git a/zephyr/program/skyrim/markarth/project.conf b/zephyr/program/skyrim/markarth/project.conf
index 4f00aa256c..4e9e437875 100644
--- a/zephyr/program/skyrim/markarth/project.conf
+++ b/zephyr/program/skyrim/markarth/project.conf
@@ -27,3 +27,7 @@ CONFIG_PLATFORM_EC_DYNAMIC_MOTION_SENSOR_COUNT=y
# Fan
CONFIG_PLATFORM_EC_CUSTOM_FAN_CONTROL=y
+
+# Markarth modify monitor VBUS from TCPC
+CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=n
+CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_TCPC=y
diff --git a/zephyr/program/skyrim/src/power_signals.c b/zephyr/program/skyrim/src/power_signals.c
index 5814359606..ede5d1ec75 100644
--- a/zephyr/program/skyrim/src/power_signals.c
+++ b/zephyr/program/skyrim/src/power_signals.c
@@ -65,9 +65,13 @@ baseboard_suspend_change(struct ap_power_ev_callback *cb,
return;
case AP_POWER_SUSPEND:
- /* Disable display backlight and retimer */
+ /* Disable display backlight */
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_ec_disable_disp_bl),
1);
+ break;
+
+ case AP_POWER_SHUTDOWN:
+ /* Retimer disable */
ioex_set_level(IOEX_USB_A1_RETIMER_EN, 0);
break;
@@ -75,6 +79,9 @@ baseboard_suspend_change(struct ap_power_ev_callback *cb,
/* Enable retimer and display backlight */
gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_ec_disable_disp_bl),
0);
+ break;
+
+ case AP_POWER_STARTUP:
ioex_set_level(IOEX_USB_A1_RETIMER_EN, 1);
/* Any retimer tuning can be done after the retimer turns on */
break;
@@ -106,7 +113,8 @@ test_export_static void baseboard_init(void)
/* Setup a suspend/resume callback */
ap_power_ev_init_callback(&cb, baseboard_suspend_change,
- AP_POWER_RESUME | AP_POWER_SUSPEND);
+ AP_POWER_STARTUP | AP_POWER_SHUTDOWN |
+ AP_POWER_RESUME | AP_POWER_SUSPEND);
ap_power_ev_add_callback(&cb);
/* Enable Power Group interrupts. */
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_pg_groupc_s0));
diff --git a/zephyr/program/skyrim/src/usbc_config.c b/zephyr/program/skyrim/src/usbc_config.c
index ab1d444df8..922e863027 100644
--- a/zephyr/program/skyrim/src/usbc_config.c
+++ b/zephyr/program/skyrim/src/usbc_config.c
@@ -9,7 +9,6 @@
#include "charge_manager.h"
#include "charge_ramp.h"
#include "charge_state.h"
-#include "charge_state_v2.h"
#include "charger.h"
#include "cros_board_info.h"
#include "cros_cbi.h"
diff --git a/zephyr/program/skyrim/winterhold/CMakeLists.txt b/zephyr/program/skyrim/winterhold/CMakeLists.txt
index 0596978c05..632f11d8f1 100644
--- a/zephyr/program/skyrim/winterhold/CMakeLists.txt
+++ b/zephyr/program/skyrim/winterhold/CMakeLists.txt
@@ -12,3 +12,6 @@ zephyr_library_sources(
"src/alt_charger.c"
"src/thermal.c"
)
+
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CUSTOM_FAN_DUTY_CONTROL
+ "src/fan.c")
diff --git a/zephyr/program/skyrim/winterhold/src/fan.c b/zephyr/program/skyrim/winterhold/src/fan.c
new file mode 100644
index 0000000000..a5061a660f
--- /dev/null
+++ b/zephyr/program/skyrim/winterhold/src/fan.c
@@ -0,0 +1,90 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "console.h"
+#include "fan.h"
+#include "math_util.h"
+#include "thermal.h"
+
+#include <zephyr/kernel.h>
+
+#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_THERMAL, format, ##args)
+
+K_TIMER_DEFINE(grace_period_timer, NULL, NULL);
+
+enum fan_status board_override_fan_control_duty(int ch)
+{
+ int duty, rpm_diff, deviation, duty_step;
+ struct fan_data *data = &fan_data[ch];
+ int rpm_actual = data->rpm_actual;
+ int rpm_target = data->rpm_target;
+
+ /* This works with one fan only. */
+ if (ch != 0) {
+ CPRINTS("Only FAN0 is supported!");
+ return FAN_STATUS_FRUSTRATED;
+ }
+
+ /* Wait for fan RPM to catch up after its duty has been changed. */
+ if (k_timer_remaining_ticks(&grace_period_timer) != 0)
+ return FAN_STATUS_LOCKED;
+
+ duty = fan_get_duty(ch);
+ if (duty == 0 && rpm_target == 0)
+ return FAN_STATUS_STOPPED;
+
+ /*
+ * If the current RPM is close enough to the target just leave it.
+ * It's always going to fluctuate a bit anyway.
+ */
+ deviation = fans[ch].rpm->rpm_deviation * rpm_target / 100;
+ rpm_diff = rpm_target - rpm_actual;
+ if (rpm_diff > deviation) {
+ /* Can't set duty higher than 100%... */
+ if (duty == 100)
+ return FAN_STATUS_FRUSTRATED;
+ } else if (rpm_diff < -deviation) {
+ /* Can't set duty lower than 1%... */
+ if (duty == 1 && rpm_target != 0)
+ return FAN_STATUS_FRUSTRATED;
+ } else {
+ return FAN_STATUS_LOCKED;
+ }
+
+ /*
+ * The rpm_diff -> duty_step conversion is specific to a specific
+ * whiterun fan.
+ * It has been determined empirically.
+ */
+ if (ABS(rpm_diff) >= 2500) {
+ duty_step = 35;
+ k_timer_start(&grace_period_timer, K_MSEC(800), K_NO_WAIT);
+ } else if (ABS(rpm_diff) >= 2000) {
+ duty_step = 28;
+ k_timer_start(&grace_period_timer, K_MSEC(800), K_NO_WAIT);
+ } else if (ABS(rpm_diff) >= 1000) {
+ duty_step = 14;
+ k_timer_start(&grace_period_timer, K_MSEC(800), K_NO_WAIT);
+ } else if (ABS(rpm_diff) >= 500) {
+ duty_step = 6;
+ k_timer_start(&grace_period_timer, K_MSEC(800), K_NO_WAIT);
+ } else if (ABS(rpm_diff) >= 250) {
+ duty_step = 3;
+ k_timer_start(&grace_period_timer, K_MSEC(600), K_NO_WAIT);
+ } else {
+ duty_step = 1;
+ k_timer_start(&grace_period_timer, K_MSEC(600), K_NO_WAIT);
+ }
+
+ if (rpm_diff > 0)
+ duty = MIN(duty + duty_step, 100);
+ else
+ duty = MAX(duty - duty_step, 1);
+
+ fan_set_duty(ch, duty);
+
+ return FAN_STATUS_CHANGING;
+}
diff --git a/zephyr/program/skyrim/winterhold/src/thermal.c b/zephyr/program/skyrim/winterhold/src/thermal.c
index 00e162e45a..0ccd9dd9e2 100644
--- a/zephyr/program/skyrim/winterhold/src/thermal.c
+++ b/zephyr/program/skyrim/winterhold/src/thermal.c
@@ -4,11 +4,9 @@
*/
#include "body_detection.h"
-#include "fan.h"
#include "hooks.h"
#include "host_command.h"
#include "lid_switch.h"
-#include "math_util.h"
#include "temp_sensor/temp_sensor.h"
#include "thermal.h"
@@ -211,82 +209,3 @@ static void detect_temp_change(void)
}
}
DECLARE_HOOK(HOOK_SECOND, detect_temp_change, HOOK_PRIO_TEMP_SENSOR_DONE);
-
-#ifdef CONFIG_PLATFORM_EC_CUSTOM_FAN_DUTY_CONTROL
-
-K_TIMER_DEFINE(grace_period_timer, NULL, NULL);
-
-enum fan_status board_override_fan_control_duty(int ch)
-{
- int duty, rpm_diff, deviation, duty_step;
- struct fan_data *data = &fan_data[ch];
- int rpm_actual = data->rpm_actual;
- int rpm_target = data->rpm_target;
-
- /* This works with one fan only. */
- if (ch != 0) {
- CPRINTS("Only FAN0 is supported!");
- return FAN_STATUS_FRUSTRATED;
- }
-
- /* Wait for fan RPM to catch up after its duty has been changed. */
- if (k_timer_remaining_ticks(&grace_period_timer) != 0)
- return FAN_STATUS_LOCKED;
-
- duty = fan_get_duty(ch);
- if (duty == 0 && rpm_target == 0)
- return FAN_STATUS_STOPPED;
-
- /*
- * If the current RPM is close enough to the target just leave it.
- * It's always going to fluctuate a bit anyway.
- */
- deviation = fans[ch].rpm->rpm_deviation * rpm_target / 100;
- rpm_diff = rpm_target - rpm_actual;
- if (rpm_diff > deviation) {
- /* Can't set duty higher than 100%... */
- if (duty == 100)
- return FAN_STATUS_FRUSTRATED;
- } else if (rpm_diff < -deviation) {
- /* Can't set duty lower than 1%... */
- if (duty == 1 && rpm_target != 0)
- return FAN_STATUS_FRUSTRATED;
- } else {
- return FAN_STATUS_LOCKED;
- }
-
- /*
- * The rpm_diff -> duty_step conversion is specific to a specific
- * whiterun fan.
- * It has been determined empirically.
- */
- if (ABS(rpm_diff) >= 2500) {
- duty_step = 35;
- k_timer_start(&grace_period_timer, K_MSEC(800), K_NO_WAIT);
- } else if (ABS(rpm_diff) >= 2000) {
- duty_step = 28;
- k_timer_start(&grace_period_timer, K_MSEC(800), K_NO_WAIT);
- } else if (ABS(rpm_diff) >= 1000) {
- duty_step = 14;
- k_timer_start(&grace_period_timer, K_MSEC(800), K_NO_WAIT);
- } else if (ABS(rpm_diff) >= 500) {
- duty_step = 6;
- k_timer_start(&grace_period_timer, K_MSEC(800), K_NO_WAIT);
- } else if (ABS(rpm_diff) >= 250) {
- duty_step = 3;
- k_timer_start(&grace_period_timer, K_MSEC(600), K_NO_WAIT);
- } else {
- duty_step = 1;
- k_timer_start(&grace_period_timer, K_MSEC(600), K_NO_WAIT);
- }
-
- if (rpm_diff > 0)
- duty = MIN(duty + duty_step, 100);
- else
- duty = MAX(duty - duty_step, 1);
-
- fan_set_duty(ch, duty);
-
- return FAN_STATUS_CHANGING;
-}
-#endif