Skip to content

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

Draft
RyanTheTide wants to merge 3 commits into
integration/aurorafrom
powerctl/hwmon-fan-control-v2
Draft

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

Conversation

@RyanTheTide

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 #2304 (SMC key inventory and sensor key checks on every SoC) because both change the same lines at the top of the file. Review only the last commit, adcfa5c.

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

  • macsmc-hwmon.ko with W=1 against the fleet75 configuration on this stack: 0 warnings. Earlier, 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 (hwmon: macsmc: SMC key inventory and sensor key checks on every SoC #2304 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)

Commit 2604bb0 ("hwmon: macsmc: expose read-only SMC key inventory
on T6050") enabled the debugfs "keys" listing on T6050 next to the M3
SoCs. The listing only queries key metadata through the SMC's own key
enumeration and reads readable 32-bit float T*/P* keys; it writes
nothing, and it does its work only when root reads the file. None of
that depends on the SoC, and the listing is how the keys a machine has
are found for its device tree, on every SMC.

Create it on every SoC.

Fixes: 2604bb0 ("hwmon: macsmc: expose read-only SMC key inventory on T6050")
Suggested-by: Satya Benson <satya@benson.earth>
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Commit c91c5f4 ("hwmon: macsmc: preserve the legacy sensor export
policy") limited the key checks in macsmc_hwmon_create_sensor() to the
M3 SoCs: a device tree sensor is set up only if the SMC reports its key
as readable and as a 4-byte "flt " or an 8-byte "ioft". Elsewhere a
sensor whose key fails those checks still got a channel.

macsmc_hwmon_read_key() decodes only those two types and returns
-EOPNOTSUPP for any other, so such a channel can only ever return an
error, whatever the SoC. Apply the checks on every SoC and drop
macsmc_hwmon_is_m3(), which has no other user.

A temperature node of a thermal sensor provider (#thermal-sensor-cells)
keeps its channel slot when it fails, as before, so thermal zones that
refer to channels by index are not renumbered.

Fixes: c91c5f4 ("hwmon: macsmc: preserve the legacy sensor export policy")
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>
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