diff options
Diffstat (limited to 'zephyr/program/skyrim')
-rw-r--r-- | zephyr/program/skyrim/frostflow/led_policy.dtsi | 4 | ||||
-rw-r--r-- | zephyr/program/skyrim/frostflow/src/usb_mux_config.c | 25 | ||||
-rw-r--r-- | zephyr/program/skyrim/markarth/led_policy.dtsi | 6 | ||||
-rw-r--r-- | zephyr/program/skyrim/markarth/project.conf | 4 | ||||
-rw-r--r-- | zephyr/program/skyrim/src/power_signals.c | 12 | ||||
-rw-r--r-- | zephyr/program/skyrim/src/usbc_config.c | 1 | ||||
-rw-r--r-- | zephyr/program/skyrim/winterhold/CMakeLists.txt | 3 | ||||
-rw-r--r-- | zephyr/program/skyrim/winterhold/src/fan.c | 90 | ||||
-rw-r--r-- | zephyr/program/skyrim/winterhold/src/thermal.c | 81 |
9 files changed, 134 insertions, 92 deletions
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 |