Page MenuHomeFreeBSD

asmc: add per-fan manual mode control via sysctl
ClosedPublic

Authored by guest-seuros on Wed, Dec 31, 3:11 PM.
Tags
None
Referenced Files
F141774797: D54437.diff
Sat, Jan 10, 5:22 AM
Unknown Object (File)
Fri, Jan 9, 11:07 PM
Unknown Object (File)
Fri, Jan 9, 3:05 AM
Unknown Object (File)
Thu, Jan 8, 12:15 AM
Unknown Object (File)
Wed, Jan 7, 7:43 PM
Unknown Object (File)
Wed, Jan 7, 3:19 PM
Unknown Object (File)
Wed, Jan 7, 6:13 AM
Unknown Object (File)
Wed, Jan 7, 2:57 AM
Subscribers

Details

Summary

Add per-fan manual mode control via dev.asmc.0.fan.N.manual sysctl.

Apple SMCs support manual fan control via the FS! SMC key,
a 16-bit bitmask where each bit controls one fan (0=auto, 1=manual).

This change adds a new sysctl per fan:

dev.asmc.0.fan.N.manual (0=auto, 1=manual)

When set to manual mode (1), the fan runs at the speed set via

dev.asmc.0.fan.N.targetspeed instead of automatic thermal control.

When set to auto mode (0), the SMC controls fan speed automatically.

The FS! key was already defined in asmcvar.h but not accessible.
This exposes it for debugging, testing, and advanced fan control.

Implementation uses read-modify-write to allow independent control of each fan without affecting others.

Test Plan

Tested on Mac Mini 5,1 and MacBook Pro 11,5 (FreeBSD 16.0-CURRENT):

  1. Check initial state (auto mode): sysctl dev.asmc.0.fan.0.manual Expected: 0 (auto)
  2. Check current fan speed: sysctl dev.asmc.0.fan.0.speed dev.asmc.0.fan.0.targetspeed Note initial values (e.g., 1800 RPM)
  3. Enable manual mode: sudo sysctl dev.asmc.0.fan.0.manual=1 Expected: Returns 1, no errors
  4. Set custom fan speed: sudo sysctl dev.asmc.0.fan.0.targetspeed=3000 Wait 5-10 seconds, check actual speed: sysctl dev.asmc.0.fan.0.speed Expected: Fan speed ramps to ~3000 RPM, audible increase
  5. Return to auto mode: sudo sysctl dev.asmc.0.fan.0.manual=0 Expected: Fan returns to automatic control, speed decreases
  6. Test invalid input: sudo sysctl dev.asmc.0.fan.0.manual=2 Expected: Error (EINVAL), value did not chang
  7. Multi-fan systems (MacBook Pro): Verify fan.1.manual controls second fan independently

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

guest-seuros created this revision.

Looks ok to me.

sys/dev/asmc/asmc.c
1377

Extra newline here.

This revision is now accepted and ready to land.Wed, Dec 31, 4:34 PM
This revision now requires review to proceed.Wed, Dec 31, 4:55 PM
guest-seuros added inline comments.
sys/dev/asmc/asmc.c
1377

Done, but the review got invalidated.

This revision is now accepted and ready to land.Fri, Jan 2, 7:13 PM

@adrian would you like to land these asmc patches? I can handle it otherwise.

This revision was automatically updated to reflect the committed changes.
ngie added inline comments.
sys/dev/asmc/asmc.c
664

@guest-seuros : is there a reason why CTLFLAG_NEEDGIANT is needed here, or is this mostly a copy-paste of prior OIDs?

sys/dev/asmc/asmc.c
664

It's pretty clearly just copied from existing sysctls.

guest-seuros added inline comments.
sys/dev/asmc/asmc.c
664

Yes! it copied from the prior OID in L657.

I kept the same structure because when previously when i was omitting something, i get kernel panics.