Skip to content

Commit

Permalink
ec/system76/ec: Add manual fan control
Browse files Browse the repository at this point in the history
system76/ec#512 added a manual fan control option.

In manual control mode, the system firmware or OS is responsible for
setting the fan target duty percent to manage thermals. Percent is used
rather than raw PWM value (as is returned in GFAN) as the EC may be
configured in such a way that the valid range is not 0-255.

Change-Id: Iba8cd5ac540f9fdc20473831787cafb6c1fd8129
Signed-off-by: Tim Crawford <[email protected]>
  • Loading branch information
crawfxrd committed Dec 31, 2024
1 parent a63b044 commit 71eb135
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ec/system76/ec/acpi/ec_ram.asl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Field (ERAM, ByteAcc, Lock, Preserve)
DUT2, 8, // Fan 2 duty
RPM1, 16, // Fan 1 RPM
RPM2, 16, // Fan 2 RPM
FCTL, 8, // Fan control mode
Offset (0xD9),
AIRP, 8, // Airplane mode LED
WINF, 8, // Enable ACPI brightness controls
Expand Down
60 changes: 59 additions & 1 deletion src/ec/system76/ec/acpi/s76.asl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,36 @@ Device (S76D) {
Return ((Local1 << 8) | Local0)
}

// Set fan duty percent
// - Arg0: Fan select
// - Arg1: PWM duty percent
Method (SFDP, 2, Serialized) {
If (ToInteger (Arg1) > 100) {
Return (0xFF)
}

If (^^PCI0.LPCB.EC0.ECOK) {
// Fail here, but EC will also ignore writes if fan is
// set to automatic control.
If (^^PCI0.LPCB.EC0.FCTL == 0) {
Return (0xFF)
}

If (ToInteger (Arg0) == 0) {
^^PCI0.LPCB.EC0.DUT1 = Arg1
Return (0x00)
}
#if CONFIG(EC_SYSTEM76_EC_FAN2)
If (ToInteger (Arg0) == 1) {
^^PCI0.LPCB.EC0.DUT2 = Arg1
Return (0x00)
}
#endif
}

Return (0xFF)
}

// Temperature names
Method (NTMP, 0, Serialized) {
Return (Package() {
Expand All @@ -166,7 +196,7 @@ Device (S76D) {

// Get temperature
Method (GTMP, 1, Serialized) {
Local0 = 0;
Local0 = 0
If (^^PCI0.LPCB.EC0.ECOK) {
If (Arg0 == 0) {
Local0 = ^^PCI0.LPCB.EC0.TMP1
Expand All @@ -176,4 +206,32 @@ Device (S76D) {
}
Return (Local0)
}

// Get fan control mode
// - 0: EC automatic control
// - 1: EC manual control
Method (GFCM, 0, Serialized) {
Local0 = 0xFF
If (^^PCI0.LPCB.EC0.ECOK) {
Local0 = ^^PCI0.LPCB.EC0.FCTL
}
Return (Local0)
}

// Set fan control mode
// - 0: EC automatic control
// - 1: EC manual control
Method (SFCM, 1, Serialized) {
If (^^PCI0.LPCB.EC0.ECOK) {
Switch (ToInteger (Arg0)) {
Case (0x00) {
^^PCI0.LPCB.EC0.FCTL = Arg0
}

Case (0x01) {
^^PCI0.LPCB.EC0.FCTL = Arg0
}
}
}
}
}

0 comments on commit 71eb135

Please sign in to comment.