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 PWM control mode, the system firmware or OS is responsible for
setting the fan target duty to manage thermals. CTR0 in the EC code
determines the maximum valid PWM duty, which is hard-coded to 255.

RPM target is not supported.

Change-Id: Iba8cd5ac540f9fdc20473831787cafb6c1fd8129
Signed-off-by: Tim Crawford <[email protected]>
  • Loading branch information
crawfxrd committed Jan 2, 2025
1 parent db5909d commit 911711e
Show file tree
Hide file tree
Showing 2 changed files with 58 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
58 changes: 57 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,32 @@ Device (S76D) {
Return ((Local1 << 8) | Local0)
}

// Set fan duty
// - Arg0: Fan select
// - Arg1: PWM duty (0-255)
Method (_SFD, 2, Serialized) {
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 +192,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 +202,34 @@ Device (S76D) {
}
Return (Local0)
}

// Get fan control mode
// - 0: EC automatic control
// - 1: Host control via target PWM
// - 2: Host control via target RPM
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: Host control via target PWM
// - 2: Host control via target RPM
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 911711e

Please sign in to comment.