Skip to content

Commit bbd4783

Browse files
committed
ec/system76/ec: Add manual fan control
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. RPM target is not supported. Change-Id: Iba8cd5ac540f9fdc20473831787cafb6c1fd8129 Signed-off-by: Tim Crawford <[email protected]>
1 parent a63b044 commit bbd4783

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

src/ec/system76/ec/acpi/ec_ram.asl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Field (ERAM, ByteAcc, Lock, Preserve)
4242
DUT2, 8, // Fan 2 duty
4343
RPM1, 16, // Fan 1 RPM
4444
RPM2, 16, // Fan 2 RPM
45+
FCTL, 8, // Fan control mode
4546
Offset (0xD9),
4647
AIRP, 8, // Airplane mode LED
4748
WINF, 8, // Enable ACPI brightness controls

src/ec/system76/ec/acpi/s76.asl

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,36 @@ Device (S76D) {
154154
Return ((Local1 << 8) | Local0)
155155
}
156156

157+
// Set fan duty percent
158+
// - Arg0: Fan select
159+
// - Arg1: PWM duty percent
160+
Method (SFDP, 2, Serialized) {
161+
If (ToInteger (Arg1) > 100) {
162+
Return (0xFF)
163+
}
164+
165+
If (^^PCI0.LPCB.EC0.ECOK) {
166+
// Fail here, but EC will also ignore writes if fan is
167+
// set to automatic control.
168+
If (^^PCI0.LPCB.EC0.FCTL == 0) {
169+
Return (0xFF)
170+
}
171+
172+
If (ToInteger (Arg0) == 0) {
173+
^^PCI0.LPCB.EC0.DUT1 = Arg1
174+
Return (0x00)
175+
}
176+
#if CONFIG(EC_SYSTEM76_EC_FAN2)
177+
If (ToInteger (Arg0) == 1) {
178+
^^PCI0.LPCB.EC0.DUT2 = Arg1
179+
Return (0x00)
180+
}
181+
#endif
182+
}
183+
184+
Return (0xFF)
185+
}
186+
157187
// Temperature names
158188
Method (NTMP, 0, Serialized) {
159189
Return (Package() {
@@ -166,7 +196,7 @@ Device (S76D) {
166196

167197
// Get temperature
168198
Method (GTMP, 1, Serialized) {
169-
Local0 = 0;
199+
Local0 = 0
170200
If (^^PCI0.LPCB.EC0.ECOK) {
171201
If (Arg0 == 0) {
172202
Local0 = ^^PCI0.LPCB.EC0.TMP1
@@ -176,4 +206,32 @@ Device (S76D) {
176206
}
177207
Return (Local0)
178208
}
209+
210+
// Get fan control mode
211+
// - 0: EC automatic control
212+
// - 1: EC manual control
213+
Method (GFCM, 0, Serialized) {
214+
Local0 = 0xFF
215+
If (^^PCI0.LPCB.EC0.ECOK) {
216+
Local0 = ^^PCI0.LPCB.EC0.FCTL
217+
}
218+
Return (Local0)
219+
}
220+
221+
// Set fan control mode
222+
// - 0: EC automatic control
223+
// - 1: EC manual control
224+
Method (SFCM, 1, Serialized) {
225+
If (^^PCI0.LPCB.EC0.ECOK) {
226+
Switch (ToInteger (Arg0)) {
227+
Case (0x00) {
228+
^^PCI0.LPCB.EC0.FCTL = Arg0
229+
}
230+
231+
Case (0x01) {
232+
^^PCI0.LPCB.EC0.FCTL = Arg0
233+
}
234+
}
235+
}
236+
}
179237
}

0 commit comments

Comments
 (0)