From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.58533.1598894765966778529 for ; Mon, 31 Aug 2020 10:26:06 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: jeremy.linton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9269030E; Mon, 31 Aug 2020 10:26:05 -0700 (PDT) Received: from mammon-tx2.austin.arm.com (mammon-tx2.austin.arm.com [10.118.28.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8A61D3F66F; Mon, 31 Aug 2020 10:26:05 -0700 (PDT) From: "Jeremy Linton" To: devel@edk2.groups.io Cc: Jeremy Linton , Leif Lindholm , Pete Batard , Andrei Warkentin , Ard Biesheuvel , Samer El-Haj-Mahmoud Subject: [PATCH v4 3/6] Platform/RaspberryPi: Add entry for user fan control Date: Mon, 31 Aug 2020 12:25:46 -0500 Message-Id: <20200831172549.24079-4-jeremy.linton@arm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200831172549.24079-1-jeremy.linton@arm.com> References: <20200831172549.24079-1-jeremy.linton@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Add a menu item that allows the user to enable GPIO based fan control via SSDT and the previous NameObj replacement commit. This should only be seen/enabled on RPI4 because that is what its been tested with. Given GPIO pin current limitations its likely that a bit of additional circuitry is required to drive a fan, and the GPIO high/low signal can only be used as a enable/disable signal. A search for "rpi npn gpio fan" or similar should turn up some hits for how to do this. Alternatively there are some commercial boards (FAN SHIM) which operate via simple GPIO control. Cc: Leif Lindholm Cc: Pete Batard Cc: Andrei Warkentin Cc: Ard Biesheuvel Cc: Samer El-Haj-Mahmoud Signed-off-by: Jeremy Linton Reviewed-by: Pete Batard <@pbatard> --- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 26 ++++++++++++++++++= ++++ .../RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf | 2 ++ .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni | 6 +++++ .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr | 18 +++++++++++++++ Platform/RaspberryPi/Include/ConfigVars.h | 4 ++++ Platform/RaspberryPi/RPi3/RPi3.dsc | 5 +++++ Platform/RaspberryPi/RPi4/RPi4.dsc | 8 +++++++ Platform/RaspberryPi/RaspberryPi.dec | 1 + 8 files changed, 70 insertions(+) diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/= RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c index 9e5d9734ca..d58cbbdfe7 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c @@ -15,6 +15,7 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -22,6 +23,7 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -246,6 +248,14 @@ SetupVariables ( ASSERT_EFI_ERROR (Status);=0D }=0D =0D + Size =3D sizeof (UINT32);=0D + Status =3D gRT->GetVariable (L"FanOnGpio",=0D + &gConfigDxeFormSetGuid,=0D + NULL, &Size, &Var32);=0D + if (EFI_ERROR (Status)) {=0D + PcdSet32 (PcdFanOnGpio, PcdGet32 (PcdFanOnGpio));=0D + }=0D +=0D Size =3D sizeof(AssetTagVar);=0D =0D Status =3D gRT->GetVariable(L"AssetTag",=0D @@ -368,6 +378,7 @@ ApplyVariables ( UINT32 CpuClock =3D PcdGet32 (PcdCpuClock);=0D UINT32 CustomCpuClock =3D PcdGet32 (PcdCustomCpuClock);=0D UINT32 Rate =3D 0;=0D + UINT32 FanOnGpio =3D PcdGet32 (PcdFanOnGpio);=0D =0D switch (CpuClock) {=0D case CHIPSET_CPU_CLOCK_LOW:=0D @@ -565,6 +576,11 @@ ApplyVariables ( GpioPinFuncSet (23, GPIO_FSEL_INPUT);=0D GpioPinFuncSet (24, GPIO_FSEL_INPUT);=0D }=0D +=0D + if (FanOnGpio) {=0D + DEBUG ((DEBUG_INFO, "Fan enabled on GPIO %d\n", FanOnGpio));=0D + GpioPinFuncSet (FanOnGpio, GPIO_FSEL_OUTPUT);=0D + }=0D }=0D =0D =0D @@ -679,8 +695,18 @@ VerifyUpdateTable( }=0D =0D =0D +STATIC AML_NAME_OP_REPLACE SsdtNameOpReplace[] =3D {=0D + {"GIOP", PcdToken(PcdFanOnGpio)},=0D + {}=0D +};=0D +=0D STATIC NAMESPACE_TABLES SdtTables[] =3D {=0D {=0D + SIGNATURE_64 ('R', 'P', 'I', 'T', 'H', 'F', 'A', 'N'),=0D + PcdToken(PcdFanOnGpio),=0D + SsdtNameOpReplace=0D + },=0D + {=0D SIGNATURE_64 ('R', 'P', 'I', 0, 0, 0, 0, 0),=0D 0,=0D NULL=0D diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platfor= m/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf index cdce35bc74..321e402e65 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf @@ -46,6 +46,7 @@ AcpiLib=0D BaseLib=0D DebugLib=0D + DxeServicesLib=0D DxeServicesTableLib=0D GpioLib=0D HiiLib=0D @@ -89,6 +90,7 @@ gRaspberryPiTokenSpaceGuid.PcdSystemTableMode=0D gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB=0D gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB=0D + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio=0D =0D [Depex]=0D gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid=0D diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni index 03763710a1..e2d1bb4b39 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni @@ -48,6 +48,12 @@ #string STR_ADVANCED_SYSTAB_BOTH #language en-US "ACPI + Devicetree"=0D #string STR_ADVANCED_SYSTAB_DT #language en-US "Devicetree"=0D =0D +#string STR_ADVANCED_FANONGPIO_PROMPT #language en-US "ACPI fan control"=0D +#string STR_ADVANCED_FANONGPIO_HELP #language en-US "Cycle a fan via GPI= O if temp exceeds 60C"=0D +#string STR_ADVANCED_FANONGPIO_OFF #language en-US "Disabled"=0D +#string STR_ADVANCED_FANONGPIO_18 #language en-US "Fan Shim/GPIO-18"=0D +#string STR_ADVANCED_FANONGPIO_19 #language en-US "GPIO-19"=0D +=0D #string STR_ADVANCED_ASSET_TAG_PROMPT #language en-US "Asset Tag"=0D #string STR_ADVANCED_ASSET_TAG_HELP #language en-US "Set the system Asse= t Tag"=0D =0D diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr index d5615d7af0..94332caab3 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr @@ -10,6 +10,7 @@ #include =0D #include "ConfigDxeFormSetGuid.h"=0D #include =0D +#include =0D =0D //=0D // EFI Variable attributes=0D @@ -45,6 +46,11 @@ formset name =3D RamLimitTo3GB,=0D guid =3D CONFIGDXE_FORM_SET_GUID;=0D =0D + efivarstore ADVANCED_FAN_ON_GPIO_VARSTORE_DATA,=0D + attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE,=0D + name =3D FanOnGpio,=0D + guid =3D CONFIGDXE_FORM_SET_GUID;=0D +=0D efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA,=0D attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE,=0D name =3D SystemTableMode,=0D @@ -174,6 +180,18 @@ formset option text =3D STRING_TOKEN(STR_ADVANCED_SYSTAB_DT), value = =3D SYSTEM_TABLE_MODE_DT, flags =3D DEFAULT;=0D endoneof;=0D =0D +#if (RPI_MODEL =3D=3D 4)=0D + grayoutif NOT ideqval SystemTableMode.Mode =3D=3D SYSTEM_TABLE_MOD= E_ACPI;=0D + oneof varid =3D FanOnGpio.Enabled,=0D + prompt =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_PROMPT),= =0D + help =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_HELP),=0D + flags =3D NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRE= D,=0D + option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_OFF), va= lue =3D 0, flags =3D DEFAULT;=0D + option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_18), val= ue =3D 18, flags =3D 0;=0D + option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_19), val= ue =3D 19, flags =3D 0;=0D + endoneof;=0D + endif;=0D +#endif=0D string varid =3D AssetTag.AssetTag,=0D prompt =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT),=0D help =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_HELP),=0D diff --git a/Platform/RaspberryPi/Include/ConfigVars.h b/Platform/Raspberry= Pi/Include/ConfigVars.h index b1689b004d..1a40469bfa 100644 --- a/Platform/RaspberryPi/Include/ConfigVars.h +++ b/Platform/RaspberryPi/Include/ConfigVars.h @@ -69,6 +69,10 @@ typedef struct { } ADVANCED_RAM_LIMIT_TO_3GB_VARSTORE_DATA;=0D =0D typedef struct {=0D + UINT32 Enabled;=0D +} ADVANCED_FAN_ON_GPIO_VARSTORE_DATA;=0D +=0D +typedef struct {=0D #define SYSTEM_TABLE_MODE_ACPI 0=0D #define SYSTEM_TABLE_MODE_BOTH 1=0D #define SYSTEM_TABLE_MODE_DT 2=0D diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3= /RPi3.dsc index 0998d8366c..cef8932ca2 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dsc +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc @@ -499,6 +499,11 @@ gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|L"SystemTableMode"|gConfig= DxeFormSetGuid|0x0|1=0D =0D #=0D + # Enable a fan in the ACPI thermal zone on GPIO pin #=0D + #=0D + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGu= id|0x0|0=0D +=0D + #=0D # Common UEFI ones.=0D #=0D =0D diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc index baa7e63483..9d0eaf10a1 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -510,6 +510,14 @@ gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|L"SystemTableMode"|gConfig= DxeFormSetGuid|0x0|0=0D =0D #=0D + # Enable a fan in the ACPI thermal zone on GPIO pin #=0D + #=0D + # 0 - DISABLED=0D + # 19 - Enabled on pin 19=0D + #=0D + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGu= id|0x0|0=0D +=0D + #=0D # Common UEFI ones.=0D #=0D =0D diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/Ra= spberryPi.dec index c71177a2f7..a73650f2c3 100644 --- a/Platform/RaspberryPi/RaspberryPi.dec +++ b/Platform/RaspberryPi/RaspberryPi.dec @@ -66,3 +66,4 @@ gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|1|UINT32|0x0000001B=0D gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|0|UINT32|0x00000019=0D gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|0|UINT32|0x0000001A=0D + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|0|UINT32|0x0000001C=0D --=20 2.13.7