public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Pete Batard" <pete@akeo.ie>
To: Jeremy Linton <jeremy.linton@arm.com>, devel@edk2.groups.io
Cc: Leif Lindholm <leif@nuviainc.com>,
	Andrei Warkentin <awarkentin@vmware.com>,
	Ard Biesheuvel <ard.biesheuvel@arm.com>,
	Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Subject: Re: [PATCH v3 3/5] Platform/RaspberryPi: Add entry for user fan control
Date: Mon, 31 Aug 2020 14:17:22 +0100	[thread overview]
Message-ID: <43e63291-2eb3-114a-28b0-8d025950e7b4@akeo.ie> (raw)
In-Reply-To: <20200828220215.101919-4-jeremy.linton@arm.com>

On 2020.08.28 23:02, Jeremy Linton wrote:
> 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 <leif@nuviainc.com>
> Cc: Pete Batard <pete@akeo.ie>
> Cc: Andrei Warkentin <awarkentin@vmware.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
> 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 <Library/AcpiLib.h>
> 
>   #include <Library/DebugLib.h>
> 
>   #include <Library/DevicePathLib.h>
> 
> +#include <Library/DxeServicesLib.h>
> 
>   #include <Library/DxeServicesTableLib.h>
> 
>   #include <Library/GpioLib.h>
> 
>   #include <Library/HiiLib.h>
> 
> @@ -22,6 +23,7 @@
>   #include <Library/NetLib.h>
> 
>   #include <Library/UefiBootServicesTableLib.h>
> 
>   #include <Library/UefiRuntimeServicesTableLib.h>
> 
> +#include <Protocol/AcpiTable.h>
> 
>   #include <Protocol/BcmGenetPlatformDevice.h>
> 
>   #include <Protocol/RpiFirmware.h>
> 
>   #include <ConfigVars.h>
> 
> @@ -246,6 +248,14 @@ SetupVariables (
>       ASSERT_EFI_ERROR (Status);
> 
>     }
> 
>   
> 
> +  Size = sizeof (UINT32);
> 
> +  Status = gRT->GetVariable (L"FanOnGpio",
> 
> +                  &gConfigDxeFormSetGuid,
> 
> +                  NULL, &Size, &Var32);
> 
> +  if (EFI_ERROR (Status)) {
> 
> +    PcdSet32 (PcdFanOnGpio, PcdGet32 (PcdFanOnGpio));
> 
> +  }
> 
> +
> 
>     Size = sizeof(AssetTagVar);
> 
>   
> 
>     Status = gRT->GetVariable(L"AssetTag",
> 
> @@ -368,6 +378,7 @@ ApplyVariables (
>     UINT32 CpuClock = PcdGet32 (PcdCpuClock);
> 
>     UINT32 CustomCpuClock = PcdGet32 (PcdCustomCpuClock);
> 
>     UINT32 Rate = 0;
> 
> +  UINT32 FanOnGpio = PcdGet32 (PcdFanOnGpio);
> 
>   
> 
>     switch (CpuClock) {
> 
>     case CHIPSET_CPU_CLOCK_LOW:
> 
> @@ -565,6 +576,11 @@ ApplyVariables (
>       GpioPinFuncSet (23, GPIO_FSEL_INPUT);
> 
>       GpioPinFuncSet (24, GPIO_FSEL_INPUT);
> 
>     }
> 
> +
> 
> +  if (FanOnGpio) {
> 
> +    DEBUG ((DEBUG_INFO, "Fan enabled on GPIO %d\n", FanOnGpio));
> 
> +    GpioPinFuncSet (FanOnGpio, GPIO_FSEL_OUTPUT);
> 
> +  }
> 
>   }
> 
>   
> 
>   
> 
> @@ -679,8 +695,18 @@ VerifyUpdateTable(
>   }
> 
>   
> 
>   
> 
> +STATIC AML_NAME_OP_REPLACE SsdtNameOpReplace[] = {
> 
> +  {"GIOP", PcdToken(PcdFanOnGpio)},
> 
> +  {}
> 
> +};
> 
> +
> 
>   STATIC NAMESPACE_TABLES SdtTables[] = {
> 
>     {
> 
> +    SIGNATURE_64 ('R', 'P', 'I', 'T', 'H', 'F', 'A', 'N'),
> 
> +    PcdToken(PcdFanOnGpio),
> 
> +    SsdtNameOpReplace
> 
> +  },
> 
> +  {
> 
>       SIGNATURE_64 ('R', 'P', 'I', 0, 0, 0, 0, 0),
> 
>       0,
> 
>       NULL
> 
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platform/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
> 
>     BaseLib
> 
>     DebugLib
> 
> +  DxeServicesLib
> 
>     DxeServicesTableLib
> 
>     GpioLib
> 
>     HiiLib
> 
> @@ -89,6 +90,7 @@
>     gRaspberryPiTokenSpaceGuid.PcdSystemTableMode
> 
>     gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB
> 
>     gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB
> 
> +  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio
> 
>   
> 
>   [Depex]
> 
>     gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid
> 
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Platform/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"
> 
>   #string STR_ADVANCED_SYSTAB_DT       #language en-US "Devicetree"
> 
>   
> 
> +#string STR_ADVANCED_FANONGPIO_PROMPT #language en-US "ACPI fan control"
> 
> +#string STR_ADVANCED_FANONGPIO_HELP   #language en-US "Cycle a fan via GPIO if temp exceeds 60C"
> 
> +#string STR_ADVANCED_FANONGPIO_OFF    #language en-US "Disabled"
> 
> +#string STR_ADVANCED_FANONGPIO_18     #language en-US "Fan Shim/GPIO-18"
> 
> +#string STR_ADVANCED_FANONGPIO_19     #language en-US "GPIO-19"
> 
> +
> 
>   #string STR_ADVANCED_ASSET_TAG_PROMPT #language en-US "Asset Tag"
> 
>   #string STR_ADVANCED_ASSET_TAG_HELP   #language en-US "Set the system Asset Tag"
> 
>   
> 
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Platform/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 <Guid/HiiPlatformSetupFormset.h>
> 
>   #include "ConfigDxeFormSetGuid.h"
> 
>   #include <ConfigVars.h>
> 
> +#include <IndustryStandard/Bcm2711.h>
> 
>   
> 
>   //
> 
>   // EFI Variable attributes
> 
> @@ -45,6 +46,11 @@ formset
>         name  = RamLimitTo3GB,
> 
>         guid  = CONFIGDXE_FORM_SET_GUID;
> 
>   
> 
> +    efivarstore ADVANCED_FAN_ON_GPIO_VARSTORE_DATA,
> 
> +      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
> 
> +      name  = FanOnGpio,
> 
> +      guid  = CONFIGDXE_FORM_SET_GUID;
> 
> +
> 
>       efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA,
> 
>         attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
> 
>         name  = SystemTableMode,
> 
> @@ -174,6 +180,18 @@ formset
>               option text = STRING_TOKEN(STR_ADVANCED_SYSTAB_DT), value = SYSTEM_TABLE_MODE_DT, flags = DEFAULT;
> 
>           endoneof;
> 
>   
> 
> +#if (RPI_MODEL == 4)
> 
> +        grayoutif NOT ideqval SystemTableMode.Mode == SYSTEM_TABLE_MODE_ACPI;
> 
> +          oneof varid = FanOnGpio.Enabled,
> 
> +              prompt      = STRING_TOKEN(STR_ADVANCED_FANONGPIO_PROMPT),
> 
> +              help        = STRING_TOKEN(STR_ADVANCED_FANONGPIO_HELP),
> 
> +              flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
> 
> +              option text = STRING_TOKEN(STR_ADVANCED_FANONGPIO_OFF), value = 0, flags = DEFAULT;
> 
> +              option text = STRING_TOKEN(STR_ADVANCED_FANONGPIO_18), value = 18, flags = 0;
> 
> +              option text = STRING_TOKEN(STR_ADVANCED_FANONGPIO_19), value = 19, flags = 0;
> 
> +          endoneof;
> 
> +        endif;
> 
> +#endif
> 
>           string varid = AssetTag.AssetTag,
> 
>               prompt  = STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT),
> 
>               help    = STRING_TOKEN(STR_ADVANCED_ASSET_TAG_HELP),
> 
> diff --git a/Platform/RaspberryPi/Include/ConfigVars.h b/Platform/RaspberryPi/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;
> 
>   
> 
>   typedef struct {
> 
> +  UINT32 Enabled;
> 
> +} ADVANCED_FAN_ON_GPIO_VARSTORE_DATA;
> 
> +
> 
> +typedef struct {
> 
>   #define SYSTEM_TABLE_MODE_ACPI 0
> 
>   #define SYSTEM_TABLE_MODE_BOTH 1
> 
>   #define SYSTEM_TABLE_MODE_DT   2
> 
> 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"|gConfigDxeFormSetGuid|0x0|1
> 
>   
> 
>     #
> 
> +  # Enable a fan in the ACPI thermal zone on GPIO pin #
> 
> +  #
> 
> +  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGuid|0x0|0
> 
> +
> 
> +  #
> 
>     # Common UEFI ones.
> 
>     #
> 
>   
> 
> 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"|gConfigDxeFormSetGuid|0x0|0
> 
>   
> 
>     #
> 
> +  # Enable a fan in the ACPI thermal zone on GPIO pin #
> 
> +  #
> 
> +  # 0  - DISABLED
> 
> +  # 19 - Enabled on pin 19
> 
> +  #
> 
> +  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGuid|0x0|0
> 
> +
> 
> +  #
> 
>     # Common UEFI ones.
> 
>     #
> 
>   
> 
> diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec
> index c71177a2f7..a73650f2c3 100644
> --- a/Platform/RaspberryPi/RaspberryPi.dec
> +++ b/Platform/RaspberryPi/RaspberryPi.dec
> @@ -66,3 +66,4 @@
>     gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|1|UINT32|0x0000001B
> 
>     gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|0|UINT32|0x00000019
> 
>     gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|0|UINT32|0x0000001A
> 
> +  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|0|UINT32|0x0000001C
> 

Reviewed-by: Pete Batard <pete@akeo.ie>

  reply	other threads:[~2020-08-31 13:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-28 22:02 [PATCH v3 0/5] Platform/RasberryPi: Thermal zone Jeremy Linton
2020-08-28 22:02 ` [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone Jeremy Linton
2020-08-31 13:15   ` Pete Batard
2020-08-31 15:13     ` Jeremy Linton
2020-08-31 15:33       ` Ard Biesheuvel
2020-08-31 15:49         ` Jeremy Linton
2020-08-28 22:02 ` [PATCH v3 2/5] Platform/RaspberryPi: Monitor ACPI Table installs Jeremy Linton
2020-08-31 13:17   ` Pete Batard
2020-08-28 22:02 ` [PATCH v3 3/5] Platform/RaspberryPi: Add entry for user fan control Jeremy Linton
2020-08-31 13:17   ` Pete Batard [this message]
2020-08-28 22:02 ` [PATCH v3 4/5] Platform/RaspberryPi4: Create ACPI fan object Jeremy Linton
2020-08-31 13:17   ` Pete Batard
2020-08-28 22:02 ` [PATCH v3 5/5] Platform/RaspberryPi: Trivial whitespace cleanup Jeremy Linton
2020-08-31 13:17   ` Pete Batard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43e63291-2eb3-114a-28b0-8d025950e7b4@akeo.ie \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox