Skip to content

hwmon: macsmc: Drop the fan_control module parameter - #2354

Closed
RyanTheTide wants to merge 2 commits into
integration/aurorafrom
powerctl/hwmon-fan-control
Closed

RyanTheTide wants to merge 2 commits into
integration/aurorafrom
powerctl/hwmon-fan-control

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

macsmc_hwmon.fan_control (module_param_unsafe, off by default) makes fanX_target writable on every fan that has mode, target, minimum and maximum keys, whatever the device tree says. It came with the original driver by James Calligeros (785205f). Since 65f0c0f ("hwmon: macsmc: let the device tree allow manual fan speeds"), the hardware-described path is the apple,fan-manual-control property on a fan node. A machine's device tree sets it where the SMC firmware is known to accept a manual speed and to take the fan back. The parameter is now only a way to force manual speeds on fans whose firmware behaviour is not described. Nothing in our kits, scripts or device trees sets it.

Change

  • Remove the parameter. fanX_target is writable exactly on fans whose node has apple,fan-manual-control. It is read-only on all other fans.
  • A leftover macsmc_hwmon.fan_control=1 on the command line or in modprobe options is reported as an unknown parameter and ignored. The driver still loads.
  • Kernel thermal requests through macsmc_hwmon_fans_request() never used the parameter and are unchanged. So are the unlock, restore, suspend and shutdown paths.
  • The fan KUnit suite now sets the per-fan device tree flag instead of the parameter. A new case checks that a fan without the flag refuses a target and writes nothing to the SMC.
  • Documentation/hwmon/macsmc-hwmon.rst is updated.

This diverges from mainline, which still has the parameter.

This PR sits on top of #2353 because both PRs change the same lines at the top of the file. Review only the last commit, ff5baa7. If #2353 is dropped, this commit rebases on its own with a trivial conflict.

Which machines this reaches: every machine with a fan node. On fans that have apple,fan-manual-control (T6040/T6041 MacBook Pro, T6050 J714s, T8142 J704), nothing changes. On every other fanned machine, manual speed is no longer possible through the parameter. Those fans stay under SMC control, which is the default today.

Testing

  • drivers/hwmon/macsmc-hwmon.o with W=1 (clang, LLVM=1, release config): 0 warnings, both with and without the KUnit code compiled in. The new test case is present in the object.
  • KUnit on arm64 (kunit.py, qemu virt, LLVM): macsmc-hwmon 4/4 and macsmc-hwmon-fan 14/14 passed on the head of this stack (with the fan_control removal on top); 52 tests run in total, 51 passed, 1 skipped (a GPU test that needs CONFIG_UCLAMP_TASK). The kunitconfig enables MFD_MACSMC, MACSMC_POWER and SENSORS_MACSMC_HWMON with their KUnit options under COMPILE_TEST.
  • J616s (T6040, apple,fan-manual-control on both fans), on the production kernel, whose DT-flag path this PR leaves as it is: fan1_target is 644; writing 2000 moved fan1 to 1977-2020 rpm within 10 s (the SMC brought fan2 to its own 1458 rpm), and writing 0 returned both fans to the SMC, which stopped them at idle.
  • Production baselines for the rows below: the J316s has fan_control in /sys/module/macsmc_hwmon/parameters/ and fan1_target/fan2_target at 444.

Still to run

  • J316s (T6000, no apple,fan-manual-control): stat -c %a fan1_target should give 444, and a write should be refused. Boot once with macsmc_hwmon.fan_control=1: dmesg should show the unknown parameter, the files should still be 444, and the fans should run under the SMC.
  • Both, on a kernel with this PR: ls /sys/module/macsmc_hwmon/parameters/ should list no fan_control.
Fanned boards and apple,fan-manual-control (from the compiled DTBs)
SoC boards fans manual control
T8103 J274 mini, J293 MBP13, J456 iMac (2), J457 iMac (1) 1-2 no
T600x J314s/J316s, J314c/J316c MBP, J375c/J375d Studio 2 no
T8112 J473 mini, J493 MBP13 1 no
T602x J414s/J416s, J414c/J416c MBP, J474s mini (1), J475c/J475d Studio 1-2 no
T603x J514s/J516s, J514c/J516c, J514m/J516m MBP, J575d Studio 2 no
T8122 J433/J434 iMac, J504 MBP14 2 no
T604x J614s/J616s, J614c/J616c MBP 2 yes
T604x J773s mini (1), J575c Studio 1-2 no
T8132 J604 MBP14, J623/J624 iMac, J773g mini (1) 1-2 no
T6050 J714s MBP14 2 yes
T6050 J716s, K116s MBP16, J775d Studio 2 no
T8142 J704 MBP14 1 yes
T8152 J873g mini 1 (monitor only, no mode/target keys) no

Assisted-by: LLM (Claude:Opus 5.5)

macsmc_hwmon_is_m3() matched apple,t6030/t6031/t6032/t6034/t8122 and
gated two things that do not depend on the SoC:

1. The key check in macsmc_hwmon_create_sensor(). A sensor node was
   admitted only if the SMC reports its key readable and as a 4-byte
   "flt " or 8-byte "ioft" value, but only on those five SoCs. The gate
   was added to keep the earlier admission policy on other machines,
   not because of a firmware difference. Every SMC reports a key's
   type, size and flags (apple_smc_get_key_info()), and
   macsmc_hwmon_read_key() decodes only those two formats on every SoC,
   so a key that fails the check can only fail every read. The die
   sensor, thermal pressure and temperature discovery paths already
   apply the same check without a SoC gate. Apply it to every sensor
   node. On a node that is a thermal sensor provider
   (#thermal-sensor-cells, used today by the T600x MacBook Pro, T604x,
   T8112, T8122 and T8140 trees) a rejected temperature node keeps its
   hidden channel, so zone indices do not move; elsewhere the unusable
   channel is no longer registered.

2. The debugfs "keys" inventory, enabled on the same SoCs and T6050.
   It only walks the SMC key index and key info and reads readable
   4-byte float T* and P* keys on demand, which every SMC supports.
   It is debugfs, root only, and reads nothing at probe. Create it on
   every machine.

No SMC write and no probe-time key read is added on any SoC. The key
check and the inventory were written by Chris Kearney for T6030.

Fixes: c91c5f4 ("hwmon: macsmc: preserve the legacy sensor export policy")
Fixes: 2604bb0 ("hwmon: macsmc: expose read-only SMC key inventory on T6050")
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
fan_control (module_param_unsafe, default off) made fanX_target writable
on every fan with mode, target, minimum and maximum keys, whatever the
device tree says. Since commit 65f0c0f ("hwmon: macsmc: let the
device tree allow manual fan speeds") the hardware-described path is the
apple,fan-manual-control property on a fan node, set in a machine's
device tree where its SMC firmware is known to accept a manual speed and
to take the fan back. The parameter was kept then as the mainline
interface. It is now the only way left to force manual speeds on a fan
whose firmware behaviour is not described, and nothing in this tree's
kits, scripts or device trees sets it.

Remove it. fanX_target is writable exactly on the fans whose node has
apple,fan-manual-control. A leftover macsmc_hwmon.fan_control=1 on the
command line or in modprobe options is reported as an unknown parameter
and ignored; the driver still loads. Kernel thermal requests through
macsmc_hwmon_fans_request() never depended on the parameter and are
unchanged, as is the unlock and restore sequence.

The fan KUnit suite now sets the per-fan device tree flag instead of the
parameter, and a new case checks that a fan without it refuses a target
without writing to the SMC.

The parameter came with the original driver by James Calligeros.

Fixes: 65f0c0f ("hwmon: macsmc: let the device tree allow manual fan speeds")
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #2448: the same commit, now on top of #2304 instead of #2353.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant