Page MenuHomeFreeBSD

asmc: add automatic voltage/current/power/ambient sensor detection
ClosedPublic

Authored by guest-seuros on Mar 11 2026, 11:21 AM.
Tags
None
Referenced Files
F154299787: D55807.id173555.diff
Mon, Apr 27, 4:56 PM
F154294811: D55807.id175728.diff
Mon, Apr 27, 4:16 PM
F154277366: D55807.id173555.diff
Mon, Apr 27, 1:34 PM
F154268325: D55807.id.diff
Mon, Apr 27, 12:19 PM
F154241261: D55807.id175532.diff
Mon, Apr 27, 8:45 AM
Unknown Object (File)
Sat, Apr 25, 2:42 PM
Unknown Object (File)
Sat, Apr 18, 7:47 AM
Unknown Object (File)
Sat, Apr 18, 7:47 AM
Subscribers

Details

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 Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Mon, Apr 13, 12:57 AM

Rebased on top of 3e27114a7f96. Fixed style(9) nits: magic numbers, be16dec(), M_WAITOK NULL checks, errno returns, asmc_key_getinfo out of ASMC_DEBUG.

This revision now requires review to proceed.Wed, Apr 15, 4:55 AM

I'll try this change out on my '17 MBP.

This revision is now accepted and ready to land.Fri, Apr 17, 2:30 AM