Page MenuHomeFreeBSD

asmc: add automatic voltage/current/power/ambient sensor detection
Needs ReviewPublic

Authored by guest-seuros on Wed, Mar 11, 11:21 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Mar 12, 10:02 PM
Unknown Object (File)
Thu, Mar 12, 3:44 PM
Subscribers
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Apple SMCs contain numerous undocumented voltage, current, power,
and ambient light sensors. This change adds automatic detection
and registration of these sensors as sysctls.

New sysctl trees:

dev.asmc.0.voltage.*  - Voltage sensors (millivolts)
dev.asmc.0.current.*  - Current sensors (milliamps)
dev.asmc.0.power.*    - Power sensors (milliwatts)
dev.asmc.0.ambient.*  - Ambient light sensors

Implementation:

  • Scans all SMC keys at attach time via asmc_key_dump_by_index()
  • Identifies sensors by key prefix patterns:
    • Voltage: VC*, VD*, VG*, VP*, VI*
    • Current: I{C,D,G,M,N,O,H,P,B,A,L}*
    • Power: P{C,D,N,S,T,H,F,Z,z}*
    • Light: ALV*, ALS*
  • Dynamically creates sysctls for detected sensors
  • Supports 8 fixed-point SMC data types:
    • sp78, sp87, sp4b, sp5a, sp69, sp96, sp2d, ui16
  • Auto-converts all values to milli-units (mV, mA, mW)

On Mac Mini 5,1, detects:

  • 7 voltage sensors
  • 18 current sensors
  • 27 power sensors
  • 2 ambient light sensors

Enables power consumption monitoring, voltage rail debugging,
and ambient light detection without hardcoding model-specific
sensor lists.

Tested on:

  • Mac Mini 5,1 (2011) running FreeBSD 15.0-RELEASE
  • 54 sensors auto-detected and exposed via sysctl
  • All sensor types verified with multimeter readings
  • Fixed-point conversions validated against known values
  • Memory management tested (malloc/free on detach)
Test Plan

I will rebase this diff once D54441 land.
I also adding result of 6 other macs.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 71335
Build 68218: arc lint + arc unit