[edk2-devel] [PATCH 2/3] Platform/RaspberryPi4: Create ACPI fan object

Jeremy Linton posted 3 patches 5 years, 6 months ago
There is a newer version of this series
[edk2-devel] [PATCH 2/3] Platform/RaspberryPi4: Create ACPI fan object
Posted by Jeremy Linton 5 years, 6 months ago
Now that we have a thermal zone we can add active cooling
by specifying active cooling points (_ACx) which can
be tied to fan objects that turn fans on/off using GPIO
pins.

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>
---
 .../RaspberryPi/Drivers/ConfigDxe/SsdtThermal.asl  | 83 ++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 Platform/RaspberryPi/Drivers/ConfigDxe/SsdtThermal.asl

diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/SsdtThermal.asl b/Platform/RaspberryPi/Drivers/ConfigDxe/SsdtThermal.asl
new file mode 100644
index 0000000000..c87bda6dbc
--- /dev/null
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/SsdtThermal.asl
@@ -0,0 +1,83 @@
+/** @file
+ *
+ *  Secondary System Description Table (SSDT) for active (fan) cooling
+ *
+ *  Copyright (c) 2020, Arm Ltd. All rights reserved.
+ *
+ *  SPDX-License-Identifier: BSD-2-Clause-Patent
+ *
+ **/
+
+#include <IndustryStandard/Bcm2711.h>
+#include <IndustryStandard/Bcm2836.h>
+#include <IndustryStandard/Bcm2836Gpio.h>
+
+#include <IndustryStandard/Acpi.h>
+
+DefinitionBlock(__FILE__, "SSDT", 5, "RPIFDN", "RPITHFAN", 2)
+{
+#if (GPIO_FAN_PIN != 0)
+  External(\_SB_.EC0, DeviceObj)
+  External(\_SB_.EC0.TZ0, DeviceObj)
+
+  Scope (\_SB_.EC0)
+  {
+      // Describe a fan
+      PowerResource(PFAN, 0, 0) {
+        OperationRegion (GPIO, SystemMemory, GPIO_BASE_ADDRESS, 0x1000)
+        Field (GPIO, DWordAcc, NoLock, Preserve) {
+          Offset(0x1C),
+          GPS0, 32,
+          GPS1, 32,
+          RES1, 32,
+          GPC0, 32,
+          GPC1, 32,
+          RES2, 32,
+          GPL1, 32,
+          GPL2, 32
+        }
+        // We are hitting a GPIO pin to on/off the fan
+        // this assumes that UEFI has programmed the
+        // direction as OUT.
+        // (search "rpi gpio fan controller" for how to
+        // wire this up if your not electrically inclined
+        // the basic idea is to use a BJT/etc to switch a
+        // larger voltage through a fan where the GPIO pin
+        // feeds a NPN/PNP base. Thats because its unlikly
+        // that the fan can be driven directly from the GPIO
+        // pin due to hitting the current limit on the pins.
+        // Matching a resistor between the GPIO->Base can
+        // allow pretty much any random NPN with a reasonable
+        // EC current to work (to limit the GPIO current).)
+        Method (_STA) {
+          if ( GPL1 & (1 << GPIO_FAN_PIN) ) {
+            Return ( 1 )               // present and enabled
+          }
+          Return ( 0 )
+        }
+        Method (_ON)  {                //turn fan on
+          Store((1 << GPIO_FAN_PIN), GPS0)
+        }
+        Method (_OFF) {                //turn fan off
+          Store((1 << GPIO_FAN_PIN), GPC0)
+        }
+      }
+      Device(FAN) {
+        // Note, not currently an ACPIv4 fan
+        // the latter adds speed control/detection
+        // but in the case of linux needs FIF, FPS, FSL, and FST
+        Name(_HID, EISAID("PNP0C0B"))
+        Name(_PR0, Package() {PFAN})
+      }
+  }
+
+  // merge in an active cooling point.
+  Scope (\_SB_.EC0.TZ0)
+  {
+    Method(_AC0) { return(3332) }        // (60K) active cooling trip point,
+                                         // if this is lower than PSV then we
+                                         // prefer active cooling
+    Name(_AL0, Package(){\_SB_.EC0.FAN}) // the fan used for AC0 above
+  }
+#endif
+}
-- 
2.13.7


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#64258): https://edk2.groups.io/g/devel/message/64258
Mute This Topic: https://groups.io/mt/76178275/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH 2/3] Platform/RaspberryPi4: Create ACPI fan object
Posted by Pete Batard 5 years, 5 months ago
Whitespace/style and typos:

On 2020.08.14 00:00, Jeremy Linton wrote:
> Now that we have a thermal zone we can add active cooling
> by specifying active cooling points (_ACx) which can
> be tied to fan objects that turn fans on/off using GPIO
> pins.
> 
> 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>
> ---
>   .../RaspberryPi/Drivers/ConfigDxe/SsdtThermal.asl  | 83 ++++++++++++++++++++++
>   1 file changed, 83 insertions(+)
>   create mode 100644 Platform/RaspberryPi/Drivers/ConfigDxe/SsdtThermal.asl
> 
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/SsdtThermal.asl b/Platform/RaspberryPi/Drivers/ConfigDxe/SsdtThermal.asl
> new file mode 100644
> index 0000000000..c87bda6dbc
> --- /dev/null
> +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/SsdtThermal.asl
> @@ -0,0 +1,83 @@
> +/** @file
> + *
> + *  Secondary System Description Table (SSDT) for active (fan) cooling
> + *
> + *  Copyright (c) 2020, Arm Ltd. All rights reserved.
> + *
> + *  SPDX-License-Identifier: BSD-2-Clause-Patent
> + *
> + **/
> +
> +#include <IndustryStandard/Bcm2711.h>
> +#include <IndustryStandard/Bcm2836.h>
> +#include <IndustryStandard/Bcm2836Gpio.h>
> +
> +#include <IndustryStandard/Acpi.h>
> +
> +DefinitionBlock(__FILE__, "SSDT", 5, "RPIFDN", "RPITHFAN", 2)

Space before '('

> +{
> +#if (GPIO_FAN_PIN != 0)
> +  External(\_SB_.EC0, DeviceObj)
> +  External(\_SB_.EC0.TZ0, DeviceObj)
> +
> +  Scope (\_SB_.EC0)

3 x Space before '('

> +  {
> +      // Describe a fan
> +      PowerResource(PFAN, 0, 0) {

Space before '('

> +        OperationRegion (GPIO, SystemMemory, GPIO_BASE_ADDRESS, 0x1000)
> +        Field (GPIO, DWordAcc, NoLock, Preserve) {
> +          Offset(0x1C),

Space before '('

> +          GPS0, 32,
> +          GPS1, 32,
> +          RES1, 32,
> +          GPC0, 32,
> +          GPC1, 32,
> +          RES2, 32,
> +          GPL1, 32,
> +          GPL2, 32
> +        }
> +        // We are hitting a GPIO pin to on/off the fan
> +        // this assumes that UEFI has programmed the
> +        // direction as OUT.
> +        // (search "rpi gpio fan controller" for how to
> +        // wire this up if your not electrically inclined

"your" -> "you're"

> +        // the basic idea is to use a BJT/etc to switch a
> +        // larger voltage through a fan where the GPIO pin
> +        // feeds a NPN/PNP base. Thats because its unlikly

"Thats" -> "That's", "unlikly" -> "unlikely"

> +        // that the fan can be driven directly from the GPIO
> +        // pin due to hitting the current limit on the pins.
> +        // Matching a resistor between the GPIO->Base can
> +        // allow pretty much any random NPN with a reasonable
> +        // EC current to work (to limit the GPIO current).)
> +        Method (_STA) {
> +          if ( GPL1 & (1 << GPIO_FAN_PIN) ) {

No space between '(' and 'GPL1', as well as between the last 2 ')'

> +            Return ( 1 )               // present and enabled

No spaces inside the parenthesis

> +          }
> +          Return ( 0 )

No spaces inside the parenthesis

> +        }
> +        Method (_ON)  {                //turn fan on
> +          Store((1 << GPIO_FAN_PIN), GPS0)

Space before '('

> +        }
> +        Method (_OFF) {                //turn fan off
> +          Store((1 << GPIO_FAN_PIN), GPC0)

Space before '('

> +        }
> +      }
> +      Device(FAN) {

Space before '('

> +        // Note, not currently an ACPIv4 fan
> +        // the latter adds speed control/detection
> +        // but in the case of linux needs FIF, FPS, FSL, and FST
> +        Name(_HID, EISAID("PNP0C0B"))
> +        Name(_PR0, Package() {PFAN})

2 x Space before '(', space after '{' and before '}'

> +      }
> +  }
> +
> +  // merge in an active cooling point.
> +  Scope (\_SB_.EC0.TZ0)
> +  {
> +    Method(_AC0) { return(3332) }        // (60K) active cooling trip point,

Space before '('

> +                                         // if this is lower than PSV then we
> +                                         // prefer active cooling
> +    Name(_AL0, Package(){\_SB_.EC0.FAN}) // the fan used for AC0 above

Space before '(' for 'Name' and 'Package', space after () of 'Package', 
space after '{' and before '}'

> +  }
> +#endif
> +}
> 

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

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#64313): https://edk2.groups.io/g/devel/message/64313
Mute This Topic: https://groups.io/mt/76178275/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-