Skip to content

Commit

Permalink
Add fan control for more platforms
Browse files Browse the repository at this point in the history
- Indiedroid Nova (GPIO4_B4)
- ROC-RK3588S-PC / Station M3 (fan header)
- Blade 3 (fan header)
- Orange Pi 5 (GPIO4_B2)
- Orange Pi 5 Plus (fan header)
- ROCK 5B (fan header)
  • Loading branch information
mariobalanica committed Sep 14, 2023
1 parent 1a9dc82 commit 3154f14
Show file tree
Hide file tree
Showing 24 changed files with 184 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
gRK3588TokenSpaceGuid.PcdUsbDpPhy0Supported|TRUE
gRK3588TokenSpaceGuid.PcdDp0LaneMux|{ 0x2, 0x3 }

#
# On-Board fan output
#
gRK3588TokenSpaceGuid.PcdHasOnBoardFanOutput|TRUE

################################################################################
#
# Components Section - list of all EDK II Modules needed by this Platform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Library/GpioLib.h>
#include <Library/RK806.h>
#include <Library/Rk3588Pcie.h>
#include <Library/PWMLib.h>
#include <Soc.h>

static struct regulator_init_data rk806_init_data[] = {
Expand Down Expand Up @@ -237,20 +238,33 @@ PciePeReset (
}
}

PWM_DATA pwm_data = {
.ControllerID = PWM_CONTROLLER2,
.ChannelID = PWM_CHANNEL3,
.PeriodNs = 4000000,
.DutyNs = 4000000,
.Polarity = FALSE,
}; // PWM2_CH3

VOID
EFIAPI
PwmFanIoSetup(
PwmFanIoSetup (
VOID
)
)
{
GpioPinSetFunction (4, GPIO_PIN_PB4, 0xB); // PWM11_IR_M1
RkPwmSetConfig (&pwm_data);
RkPwmEnable (&pwm_data);
}

VOID
EFIAPI
PwmFanSetSpeed(
UINT32 Percentage
)
PwmFanSetSpeed (
IN UINT32 Percentage
)
{
pwm_data.DutyNs = pwm_data.PeriodNs * Percentage / 100;
RkPwmSetConfig (&pwm_data);
}

VOID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
SerialPortLib
CruLib
GpioLib
PWMLib

[Sources.common]
RockchipPlatformLib.c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Library/GpioLib.h>
#include <Library/RK806.h>
#include <Library/Rk3588Pcie.h>
#include <Library/PWMLib.h>
#include <Soc.h>
#include <Library/UefiBootServicesTableLib.h>

Expand Down Expand Up @@ -299,20 +300,33 @@ PciePeReset (
}
}

PWM_DATA pwm_data = {
.ControllerID = PWM_CONTROLLER2,
.ChannelID = PWM_CHANNEL3,
.PeriodNs = 50000,
.DutyNs = 50000,
.Polarity = TRUE,
}; // PWM2_CH3

VOID
EFIAPI
PwmFanIoSetup(
PwmFanIoSetup (
VOID
)
)
{
GpioPinSetFunction (3, GPIO_PIN_PD5, 0xB); // PWM11_IR_M3
RkPwmSetConfig (&pwm_data);
RkPwmEnable (&pwm_data);
}

VOID
EFIAPI
PwmFanSetSpeed(
UINT32 Percentage
)
PwmFanSetSpeed (
IN UINT32 Percentage
)
{
pwm_data.DutyNs = pwm_data.PeriodNs * Percentage / 100;
RkPwmSetConfig (&pwm_data);
}

VOID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
SerialPortLib
CruLib
GpioLib
PWMLib

[Sources.common]
RockchipPlatformLib.c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
gRK3588TokenSpaceGuid.PcdGmac1Supported|TRUE
gRK3588TokenSpaceGuid.PcdGmac1TxDelay|0x43

#
# On-Board fan output
#
gRK3588TokenSpaceGuid.PcdHasOnBoardFanOutput|TRUE

################################################################################
#
# Components Section - list of all EDK II Modules needed by this Platform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,17 @@ PciePeReset (

VOID
EFIAPI
PwmFanIoSetup(
PwmFanIoSetup (
VOID
)
)
{
}

VOID
EFIAPI
PwmFanSetSpeed(
UINT32 Percentage
)
PwmFanSetSpeed (
IN UINT32 Percentage
)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,17 @@ PciePeReset (

VOID
EFIAPI
PwmFanIoSetup(
PwmFanIoSetup (
VOID
)
)
{
}

VOID
EFIAPI
PwmFanSetSpeed(
UINT32 Percentage
)
PwmFanSetSpeed (
IN UINT32 Percentage
)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,17 @@ PciePeReset (

VOID
EFIAPI
PwmFanIoSetup(
PwmFanIoSetup (
VOID
)
)
{
}

VOID
EFIAPI
PwmFanSetSpeed(
UINT32 Percentage
)
PwmFanSetSpeed (
IN UINT32 Percentage
)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,17 @@ PciePeReset (

VOID
EFIAPI
PwmFanIoSetup(
PwmFanIoSetup (
VOID
)
)
{
}

VOID
EFIAPI
PwmFanSetSpeed(
UINT32 Percentage
)
PwmFanSetSpeed (
IN UINT32 Percentage
)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,17 @@ PciePeReset (

VOID
EFIAPI
PwmFanIoSetup(
PwmFanIoSetup (
VOID
)
)
{
}

VOID
EFIAPI
PwmFanSetSpeed(
UINT32 Percentage
)
PwmFanSetSpeed (
IN UINT32 Percentage
)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,17 +343,17 @@ PciePeReset (

VOID
EFIAPI
PwmFanIoSetup(
PwmFanIoSetup (
VOID
)
)
{
}

VOID
EFIAPI
PwmFanSetSpeed(
UINT32 Percentage
)
PwmFanSetSpeed (
IN UINT32 Percentage
)
{
}

Expand Down
5 changes: 5 additions & 0 deletions edk2-rockchip/Platform/Mixtile/Blade3/Blade3.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
gRK3588TokenSpaceGuid.PcdDp0LaneMux|{ 0x2, 0x3 }
gRK3588TokenSpaceGuid.PcdDp1LaneMux|{ 0x2, 0x3 }

#
# On-Board fan output
#
gRK3588TokenSpaceGuid.PcdHasOnBoardFanOutput|TRUE

################################################################################
#
# Components Section - list of all EDK II Modules needed by this Platform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Library/GpioLib.h>
#include <Library/RK806.h>
#include <Library/Rk3588Pcie.h>
#include <Library/PWMLib.h>
#include <Soc.h>

static struct regulator_init_data rk806_init_data[] = {
Expand Down Expand Up @@ -284,20 +285,33 @@ PciePeReset (
}
}

PWM_DATA pwm_data = {
.ControllerID = PWM_CONTROLLER2,
.ChannelID = PWM_CHANNEL0,
.PeriodNs = 4000000,
.DutyNs = 4000000,
.Polarity = FALSE,
}; // PWM2_CH0

VOID
EFIAPI
PwmFanIoSetup(
PwmFanIoSetup (
VOID
)
)
{
GpioPinSetFunction (3, GPIO_PIN_PD0, 0xB); // PWM8_M2
RkPwmSetConfig (&pwm_data);
RkPwmEnable (&pwm_data);
}

VOID
EFIAPI
PwmFanSetSpeed(
UINT32 Percentage
)
PwmFanSetSpeed (
IN UINT32 Percentage
)
{
pwm_data.DutyNs = pwm_data.PeriodNs * Percentage / 100;
RkPwmSetConfig (&pwm_data);
}

VOID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
SerialPortLib
CruLib
GpioLib
PWMLib

[Sources.common]
RockchipPlatformLib.c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Library/GpioLib.h>
#include <Library/RK806.h>
#include <Library/Rk3588Pcie.h>
#include <Library/PWMLib.h>
#include <Soc.h>

static struct regulator_init_data rk806_init_data[] = {
Expand Down Expand Up @@ -272,20 +273,33 @@ PciePeReset (
}
}

PWM_DATA pwm_data = {
.ControllerID = PWM_CONTROLLER3,
.ChannelID = PWM_CHANNEL2,
.PeriodNs = 4000000,
.DutyNs = 4000000,
.Polarity = FALSE,
}; // PWM3_CH2

VOID
EFIAPI
PwmFanIoSetup(
PwmFanIoSetup (
VOID
)
)
{
GpioPinSetFunction (4, GPIO_PIN_PB2, 0xB); // PWM14_M1
RkPwmSetConfig (&pwm_data);
RkPwmEnable (&pwm_data);
}

VOID
EFIAPI
PwmFanSetSpeed(
UINT32 Percentage
)
PwmFanSetSpeed (
IN UINT32 Percentage
)
{
pwm_data.DutyNs = pwm_data.PeriodNs * Percentage / 100;
RkPwmSetConfig (&pwm_data);
}

VOID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
SerialPortLib
CruLib
GpioLib
PWMLib

[Sources.common]
RockchipPlatformLib.c
Expand Down
Loading

0 comments on commit 3154f14

Please sign in to comment.