From 9ec8f97ebd4239320f04cadf7b65ec0bceda179d Mon Sep 17 00:00:00 2001 From: Molly Sophia Date: Sun, 13 Aug 2023 22:53:38 +0800 Subject: [PATCH] Add support for fan controlling in settings Signed-off-by: Molly Sophia --- .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 17 ++++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 16 +++++ .../RockchipPlatformLib/RockchipPlatformLib.c | 41 +++++++++---- .../Platform/Radxa/ROCK5A/ROCK5A.dsc | 5 ++ .../RockchipPlatformLib/RockchipPlatformLib.c | 32 +++++++--- .../Include/Library/RockchipPlatformLib.h | 12 ++++ .../RK3588/Drivers/RK3588Dxe/FanControl.c | 58 +++++++++++++++++++ .../RK3588/Drivers/RK3588Dxe/FanControl.h | 34 +++++++++++ .../RK3588/Drivers/RK3588Dxe/RK3588Dxe.c | 3 + .../RK3588/Drivers/RK3588Dxe/RK3588Dxe.inf | 6 ++ .../RK3588/Drivers/RK3588Dxe/RK3588DxeHii.uni | 13 +++++ .../RK3588/Drivers/RK3588Dxe/RK3588DxeHii.vfr | 47 +++++++++++++++ .../Rockchip/RK3588/Include/VarStoreData.h | 10 ++++ .../Silicon/Rockchip/RK3588/RK3588.dec | 5 ++ .../Rockchip/RK3588/RK3588Base.dsc.inc | 13 +++++ 25 files changed, 453 insertions(+), 19 deletions(-) create mode 100644 edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/FanControl.c create mode 100644 edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/FanControl.h diff --git a/edk2-rockchip/Platform/Ameridroid/IndiedroidNova/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/Ameridroid/IndiedroidNova/Library/RockchipPlatformLib/RockchipPlatformLib.c index 5b5c9ce4f..f795a27c7 100644 --- a/edk2-rockchip/Platform/Ameridroid/IndiedroidNova/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/Ameridroid/IndiedroidNova/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -249,6 +249,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/Firefly/ROC-RK3588S-PC/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/Firefly/ROC-RK3588S-PC/Library/RockchipPlatformLib/RockchipPlatformLib.c index f23cfc74c..33ae7659f 100644 --- a/edk2-rockchip/Platform/Firefly/ROC-RK3588S-PC/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/Firefly/ROC-RK3588S-PC/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -295,6 +295,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/FriendlyElec/NanoPC-T6/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/FriendlyElec/NanoPC-T6/Library/RockchipPlatformLib/RockchipPlatformLib.c index c7a944b36..1476ae2af 100644 --- a/edk2-rockchip/Platform/FriendlyElec/NanoPC-T6/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/FriendlyElec/NanoPC-T6/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -324,6 +324,23 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/FriendlyElec/NanoPi-R6C/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/FriendlyElec/NanoPi-R6C/Library/RockchipPlatformLib/RockchipPlatformLib.c index 13cd1b638..e41371181 100644 --- a/edk2-rockchip/Platform/FriendlyElec/NanoPi-R6C/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/FriendlyElec/NanoPi-R6C/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -303,6 +303,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/FriendlyElec/NanoPi-R6S/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/FriendlyElec/NanoPi-R6S/Library/RockchipPlatformLib/RockchipPlatformLib.c index 20cf0f5c1..970ce700e 100644 --- a/edk2-rockchip/Platform/FriendlyElec/NanoPi-R6S/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/FriendlyElec/NanoPi-R6S/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -288,6 +288,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/Hinlink/H88K/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/Hinlink/H88K/Library/RockchipPlatformLib/RockchipPlatformLib.c index f9b732280..741614600 100644 --- a/edk2-rockchip/Platform/Hinlink/H88K/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/Hinlink/H88K/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -313,6 +313,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/Khadas/Edge2/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/Khadas/Edge2/Library/RockchipPlatformLib/RockchipPlatformLib.c index a344f875e..c6fbf4e38 100644 --- a/edk2-rockchip/Platform/Khadas/Edge2/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/Khadas/Edge2/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -278,6 +278,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/Mekotronics/R58-Mini/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/Mekotronics/R58-Mini/Library/RockchipPlatformLib/RockchipPlatformLib.c index 7acf78f72..3065c5aca 100644 --- a/edk2-rockchip/Platform/Mekotronics/R58-Mini/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/Mekotronics/R58-Mini/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -299,6 +299,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/Mekotronics/R58X/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/Mekotronics/R58X/Library/RockchipPlatformLib/RockchipPlatformLib.c index b4e1928cb..cb15797a3 100644 --- a/edk2-rockchip/Platform/Mekotronics/R58X/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/Mekotronics/R58X/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -324,6 +324,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/Mixtile/Blade3/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/Mixtile/Blade3/Library/RockchipPlatformLib/RockchipPlatformLib.c index 168e063c3..eb68b8f27 100644 --- a/edk2-rockchip/Platform/Mixtile/Blade3/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/Mixtile/Blade3/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -299,6 +299,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/OrangePi/OrangePi5/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/OrangePi/OrangePi5/Library/RockchipPlatformLib/RockchipPlatformLib.c index 4d921c897..a57eaca5e 100644 --- a/edk2-rockchip/Platform/OrangePi/OrangePi5/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/OrangePi/OrangePi5/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -288,6 +288,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/OrangePi/OrangePi5Plus/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/OrangePi/OrangePi5Plus/Library/RockchipPlatformLib/RockchipPlatformLib.c index c970bee7e..d9de3e0e6 100644 --- a/edk2-rockchip/Platform/OrangePi/OrangePi5Plus/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/OrangePi/OrangePi5Plus/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -327,6 +327,22 @@ PciePeReset ( } } +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Platform/Radxa/ROCK5A/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/Radxa/ROCK5A/Library/RockchipPlatformLib/RockchipPlatformLib.c index f11ad7bed..b9861eb57 100644 --- a/edk2-rockchip/Platform/Radxa/ROCK5A/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/Radxa/ROCK5A/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -270,6 +270,35 @@ PciePeReset ( } } +PWM_DATA pwm_data = { + .ControllerID = PWM_CONTROLLER0, + .ChannelID = PWM_CHANNEL3, + .PeriodNs = 4000000, + .DutyNs = 4000000, + .Polarity = FALSE, +}; // PWM0_CH3 + +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ + GpioPinSetFunction (3, GPIO_PIN_PB2, 0xB); // PWM3_IR_M1 + RkPwmSetConfig(&pwm_data); + RkPwmEnable(&pwm_data); +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ + pwm_data.DutyNs = pwm_data.PeriodNs * Percentage / 100; + RkPwmSetConfig(&pwm_data); +} + VOID EFIAPI PlatformEarlyInit ( @@ -277,17 +306,5 @@ PlatformEarlyInit ( ) { // Configure various things specific to this platform - DEBUG((EFI_D_WARN, "PlatformEarlyInit called\n")); - GpioPinSetFunction (3, GPIO_PIN_PB2, 0xB); // PWM3_IR_M1 - - PWM_DATA pwm_data = { - .ControllerID = PWM_CONTROLLER0, - .ChannelID = PWM_CHANNEL3, - .PeriodNs = 1000000, - .DutyNs = 500000, - .Polarity = FALSE, - }; // PWM0_CH3 - RkPwmSetConfig(&pwm_data); - RkPwmEnable(&pwm_data); } diff --git a/edk2-rockchip/Platform/Radxa/ROCK5A/ROCK5A.dsc b/edk2-rockchip/Platform/Radxa/ROCK5A/ROCK5A.dsc index e5ae981f7..8e6362c8c 100644 --- a/edk2-rockchip/Platform/Radxa/ROCK5A/ROCK5A.dsc +++ b/edk2-rockchip/Platform/Radxa/ROCK5A/ROCK5A.dsc @@ -78,6 +78,11 @@ gRK3588TokenSpaceGuid.PcdComboPhy0ModeDefault|$(COMBO_PHY_MODE_PCIE) gRK3588TokenSpaceGuid.PcdComboPhy2ModeDefault|$(COMBO_PHY_MODE_USB3) + # + # On-Board fan output + # + gRK3588TokenSpaceGuid.PcdHasOnBoardFanOutput|TRUE + ################################################################################ # # Components Section - list of all EDK II Modules needed by this Platform. diff --git a/edk2-rockchip/Platform/Radxa/ROCK5B/Library/RockchipPlatformLib/RockchipPlatformLib.c b/edk2-rockchip/Platform/Radxa/ROCK5B/Library/RockchipPlatformLib/RockchipPlatformLib.c index 5bef97d3a..8c30ce5f9 100644 --- a/edk2-rockchip/Platform/Radxa/ROCK5B/Library/RockchipPlatformLib/RockchipPlatformLib.c +++ b/edk2-rockchip/Platform/Radxa/ROCK5B/Library/RockchipPlatformLib/RockchipPlatformLib.c @@ -322,6 +322,30 @@ PciePeReset ( } } +PWM_DATA pwm_data = { + .ControllerID = PWM_CONTROLLER0, + .ChannelID = PWM_CHANNEL1, + .PeriodNs = 25000, + .DutyNs = 15000, + .Polarity = FALSE, + }; // PWM0_CH1 + +VOID +EFIAPI +PwmFanIoSetup( + VOID +) +{ +} + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +) +{ +} + VOID EFIAPI PlatformEarlyInit ( @@ -332,13 +356,7 @@ PlatformEarlyInit ( DEBUG((EFI_D_WARN, "PlatformEarlyInit called\n")); GpioPinSetFunction (0, GPIO_PIN_PC0, 0x3); // PWM1_M0 - PWM_DATA pwm_data = { - .ControllerID = PWM_CONTROLLER0, - .ChannelID = PWM_CHANNEL1, - .PeriodNs = 25000, - .DutyNs = 15000, - .Polarity = FALSE, - }; // PWM0_CH1 + RkPwmSetConfig(&pwm_data); RkPwmEnable(&pwm_data); diff --git a/edk2-rockchip/Silicon/Rockchip/Include/Library/RockchipPlatformLib.h b/edk2-rockchip/Silicon/Rockchip/Include/Library/RockchipPlatformLib.h index 495ac3059..151fd2a53 100644 --- a/edk2-rockchip/Silicon/Rockchip/Include/Library/RockchipPlatformLib.h +++ b/edk2-rockchip/Silicon/Rockchip/Include/Library/RockchipPlatformLib.h @@ -121,6 +121,18 @@ PciePeReset ( BOOLEAN Enable ); +VOID +EFIAPI +PwmFanIoSetup( + VOID +); + +VOID +EFIAPI +PwmFanSetSpeed( + UINT32 Percentage +); + VOID EFIAPI PlatformEarlyInit ( diff --git a/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/FanControl.c b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/FanControl.c new file mode 100644 index 000000000..378502a2b --- /dev/null +++ b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/FanControl.c @@ -0,0 +1,58 @@ +/** @file + * + * Copyright (c) 2023, Molly Sophia + * + * SPDX-License-Identifier: BSD-2-Clause-Patent + * + **/ + +#include +#include +#include + +#include +#include "RK3588DxeFormSetGuid.h" +#include "FanControl.h" + +VOID +EFIAPI +ApplyCoolingFanVariables ( + VOID + ) +{ + UINT32 Var32 = PcdGet32 (PcdCoolingFanState); + if (Var32 == COOLING_FAN_STATE_ENABLED) { + Var32 = PcdGet32 (PcdCoolingFanSpeed); + PwmFanIoSetup(); + PwmFanSetSpeed(Var32); + } +} + +VOID +EFIAPI +SetupCoolingFanVariables ( + VOID + ) +{ + UINTN Size; + UINT32 Var32; + EFI_STATUS Status; + + Size = sizeof (UINT32); + + Status = gRT->GetVariable (L"CoolingFanState", + &gRK3588DxeFormSetGuid, + NULL, &Size, &Var32); + if (EFI_ERROR (Status)) { + Status = PcdSet32S (PcdCoolingFanState, 1); + ASSERT_EFI_ERROR (Status); + } + + Status = gRT->GetVariable (L"CoolingFanSpeed", + &gRK3588DxeFormSetGuid, + NULL, &Size, &Var32); + if (EFI_ERROR (Status)) { + Status = PcdSet32S (PcdCoolingFanSpeed, 100); + ASSERT_EFI_ERROR (Status); + } +} \ No newline at end of file diff --git a/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/FanControl.h b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/FanControl.h new file mode 100644 index 000000000..c9b25b5b7 --- /dev/null +++ b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/FanControl.h @@ -0,0 +1,34 @@ +/** @file + * + * Copyright (c) 2023, Molly Sophia + * + * SPDX-License-Identifier: BSD-2-Clause-Patent + * + **/ + +#ifndef __RK3588DXE_FANCONTROL_H__ +#define __RK3588DXE_FANCONTROL_H__ + +#define FAN_PERCENTAGE_MIN 0 +#define FAN_PERCENTAGE_MAX 100 +#define FAN_PERCENTAGE_STEP 1 +#define FAN_PERCENTAGE_DEFAULT 100 + +// +// Don't declare these in the VFR file. +// +#ifndef VFR_FILE_INCLUDE +VOID +EFIAPI +ApplyCoolingFanVariables ( + VOID + ); + +VOID +EFIAPI +SetupCoolingFanVariables ( + VOID + ); +#endif // VFR_FILE_INCLUDE + +#endif // __RK3588DXE_FANCONTROL_H__ \ No newline at end of file diff --git a/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588Dxe.c b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588Dxe.c index 38d0d0b1b..8df7d8ac0 100644 --- a/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588Dxe.c +++ b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588Dxe.c @@ -34,6 +34,7 @@ #include "ComboPhy.h" #include "PciExpress30.h" #include "Acpi.h" +#include "FanControl.h" extern UINT8 RK3588DxeHiiBin[]; extern UINT8 RK3588DxeStrings[]; @@ -157,6 +158,7 @@ SetupVariables ( SetupComboPhyVariables (); SetupPcie30Variables (); SetupAcpiVariables (); + SetupCoolingFanVariables(); return EFI_SUCCESS; } @@ -182,6 +184,7 @@ ApplyVariables ( ApplyComboPhyVariables (); ApplyPcie30Variables (); ApplyAcpiVariables (); + ApplyCoolingFanVariables(); AfterApplyVariablesInit (); } diff --git a/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588Dxe.inf b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588Dxe.inf index aeff5e014..24687e42c 100644 --- a/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588Dxe.inf +++ b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588Dxe.inf @@ -19,6 +19,7 @@ ComboPhy.c PciExpress30.c Acpi.c + FanControl.c RK3588DxeHii.uni RK3588DxeHii.vfr @@ -49,6 +50,7 @@ NonDiscoverableDeviceRegistrationLib HiiLib PcdLib + RockchipPlatformLib [Protocols] gRk860xRegulatorProtocolGuid @@ -90,6 +92,10 @@ gRK3588TokenSpaceGuid.PcdAcpiUsb2StateDefault gRK3588TokenSpaceGuid.PcdAcpiUsb2State + gRK3588TokenSpaceGuid.PcdHasOnBoardFanOutput + gRK3588TokenSpaceGuid.PcdCoolingFanState + gRK3588TokenSpaceGuid.PcdCoolingFanSpeed + [Guids] gRK3588DxeFormSetGuid gEfiEndOfDxeEventGroupGuid diff --git a/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588DxeHii.uni b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588DxeHii.uni index 8f7a04934..b9d1141fe 100644 --- a/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588DxeHii.uni +++ b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588DxeHii.uni @@ -120,3 +120,16 @@ #string STR_ACPI_USB2_STATE_PROMPT #language en-US "USB 2.0 Support" #string STR_ACPI_USB2_STATE_HELP #language en-US "Enable or disable the USB 2.0 (EHCI) controllers.\n\nThis option is disabled by default due to compatibility issues with Windows, but it can be enabled for other OSes." + +/* + * Cooling fan configuration + */ + +#string STR_COOLING_FAN_FORM_TITLE #language en-US "Cooling Fan" +#string STR_COOLING_FAN_FORM_HELP #language en-US "Configure the on-board cooling fan." + +#string STR_COOLING_FAN_STATE_PROMPT #language en-US "On-board Fan" +#string STR_COOLING_FAN_STATE_HELP #language en-US "Enable or disable the on-board fan output." + +#string STR_COOLING_FAN_SPEED_PROMPT #language en-US "Fan Speed (%)" +#string STR_COOLING_FAN_SPEED_HELP #language en-US "PWM duty cycle of on-board fan output." \ No newline at end of file diff --git a/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588DxeHii.vfr b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588DxeHii.vfr index fb2abf8f0..c984297c0 100644 --- a/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588DxeHii.vfr +++ b/edk2-rockchip/Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/RK3588DxeHii.vfr @@ -15,6 +15,7 @@ #define VFR_FILE_INCLUDE #include "CpuPerformance.h" +#include "FanControl.h" // // EFI Variable attributes @@ -115,6 +116,16 @@ formset name = AcpiUsb2State, guid = RK3588DXE_FORMSET_GUID; + efivarstore COOLING_FAN_STATE_VARSTORE_DATA, + attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + name = CoolingFanState, + guid = RK3588DXE_FORMSET_GUID; + + efivarstore COOLING_FAN_SPEED_VARSTORE_DATA, + attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + name = CoolingFanSpeed, + guid = RK3588DXE_FORMSET_GUID; + form formid = 1, title = STRING_TOKEN(STR_FORM_SET_TITLE); subtitle text = STRING_TOKEN(STR_FORM_SET_TITLE_SUBTITLE); @@ -138,6 +149,13 @@ formset goto 0x1003, prompt = STRING_TOKEN(STR_ACPI_FORM_TITLE), help = STRING_TOKEN(STR_ACPI_FORM_HELP); + +#if FixedPcdGetBool (PcdHasOnBoardFanOutput) + goto 0x1004, + prompt = STRING_TOKEN(STR_COOLING_FAN_FORM_TITLE), + help = STRING_TOKEN(STR_COOLING_FAN_FORM_HELP); +#endif + endform; form formid = 0x1000, @@ -399,4 +417,33 @@ formset option text = STRING_TOKEN(STR_ENABLED), value = ACPI_USB2_STATE_ENABLED, flags = 0; endoneof; endform; + +#if FixedPcdGetBool (PcdHasOnBoardFanOutput) + form formid = 0x1004, + title = STRING_TOKEN(STR_COOLING_FAN_FORM_TITLE); + + oneof varid = CoolingFanState.State, + prompt = STRING_TOKEN(STR_COOLING_FAN_STATE_PROMPT), + help = STRING_TOKEN(STR_COOLING_FAN_STATE_PROMPT), + flags = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED, + default = COOLING_FAN_STATE_ENABLED, + option text = STRING_TOKEN(STR_DISABLED), value = COOLING_FAN_STATE_DISABLED, flags = 0; + option text = STRING_TOKEN(STR_ENABLED), value = COOLING_FAN_STATE_ENABLED, flags = 0; + endoneof; + + grayoutif NOT ideqval CoolingFanState.State == COOLING_FAN_STATE_ENABLED; + numeric varid = CoolingFanSpeed.Percentage, + prompt = STRING_TOKEN(STR_COOLING_FAN_SPEED_PROMPT), + help = STRING_TOKEN(STR_COOLING_FAN_SPEED_PROMPT), + flags = DISPLAY_UINT_DEC | NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED, + minimum = FAN_PERCENTAGE_MIN, + maximum = FAN_PERCENTAGE_MAX, + step = FAN_PERCENTAGE_STEP, + default = FAN_PERCENTAGE_DEFAULT, + endnumeric; + endif; + endform; + +#endif + endformset; diff --git a/edk2-rockchip/Silicon/Rockchip/RK3588/Include/VarStoreData.h b/edk2-rockchip/Silicon/Rockchip/RK3588/Include/VarStoreData.h index 694111597..b2ecdc726 100644 --- a/edk2-rockchip/Silicon/Rockchip/RK3588/Include/VarStoreData.h +++ b/edk2-rockchip/Silicon/Rockchip/RK3588/Include/VarStoreData.h @@ -51,4 +51,14 @@ typedef struct { UINT32 State; } ACPI_USB2_STATE_VARSTORE_DATA; +#define COOLING_FAN_STATE_DISABLED 0 +#define COOLING_FAN_STATE_ENABLED 1 +typedef struct { + UINT32 State; +} COOLING_FAN_STATE_VARSTORE_DATA; + +typedef struct { + UINT32 Percentage; +} COOLING_FAN_SPEED_VARSTORE_DATA; + #endif // __VARSTORE_DATA_H__ diff --git a/edk2-rockchip/Silicon/Rockchip/RK3588/RK3588.dec b/edk2-rockchip/Silicon/Rockchip/RK3588/RK3588.dec index 67ac67d40..57959dcbc 100644 --- a/edk2-rockchip/Silicon/Rockchip/RK3588/RK3588.dec +++ b/edk2-rockchip/Silicon/Rockchip/RK3588/RK3588.dec @@ -45,6 +45,8 @@ gRK3588TokenSpaceGuid.PcdAcpiUsb2StateDefault|0|UINT32|0x00010301 + gRK3588TokenSpaceGuid.PcdHasOnBoardFanOutput|FALSE|BOOLEAN|0x10401 + [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] gRK3588TokenSpaceGuid.PcdCPULClusterClockPreset|0|UINT32|0x00000001 gRK3588TokenSpaceGuid.PcdCPULClusterClockCustom|0|UINT32|0x00000002 @@ -66,3 +68,6 @@ gRK3588TokenSpaceGuid.PcdPcie30State|0|UINT32|0x00000201 gRK3588TokenSpaceGuid.PcdAcpiUsb2State|0|UINT32|0x00000301 + + gRK3588TokenSpaceGuid.PcdCoolingFanState|0|UINT32|0x00000401 + gRK3588TokenSpaceGuid.PcdCoolingFanSpeed|0|UINT32|0x00000402 diff --git a/edk2-rockchip/Silicon/Rockchip/RK3588/RK3588Base.dsc.inc b/edk2-rockchip/Silicon/Rockchip/RK3588/RK3588Base.dsc.inc index 6273d936d..f0486f5fd 100644 --- a/edk2-rockchip/Silicon/Rockchip/RK3588/RK3588Base.dsc.inc +++ b/edk2-rockchip/Silicon/Rockchip/RK3588/RK3588Base.dsc.inc @@ -38,6 +38,9 @@ DEFINE ACPI_USB2_STATE_DISABLED = 0 DEFINE ACPI_USB2_STATE_ENABLED = 1 + DEFINE COOLING_FAN_STATE_DISABLED = 0 + DEFINE COOLING_FAN_STATE_ENABLED = 1 + # # Silicon/Rockchip/RK3588/Drivers/RK3588Dxe/CpuPerformance.h # @@ -219,6 +222,11 @@ gRK3588TokenSpaceGuid.PcdCPUB01ClusterClockPresetDefault|$(CPU_PERF_CLUSTER_CLOCK_PRESET_BOOTDEFAULT) gRK3588TokenSpaceGuid.PcdCPUB23ClusterClockPresetDefault|$(CPU_PERF_CLUSTER_CLOCK_PRESET_BOOTDEFAULT) + # + # Cooling Fan definitions + # + gRK3588TokenSpaceGuid.PcdHasOnBoardFanOutput|FALSE + # # PCIe/SATA/USB Combo PIPE PHY support flags and default values # @@ -287,6 +295,11 @@ # gRK3588TokenSpaceGuid.PcdAcpiUsb2State|L"AcpiUsb2State"|gRK3588DxeFormSetGuid|0x0|gRK3588TokenSpaceGuid.PcdAcpiUsb2StateDefault + # + # Cooling Fan + # + gRK3588TokenSpaceGuid.PcdCoolingFanState|L"CoolingFanState"|gRK3588DxeFormSetGuid|0x0|1 + gRK3588TokenSpaceGuid.PcdCoolingFanSpeed|L"CoolingFanSpeed"|gRK3588DxeFormSetGuid|0x0|100 ################################################################################ # # Components Section - list of all common EDK II Modules needed by RK3588 platforms.