nuttx/drivers/thermal
Justin Hammond 7efdd31994 drivers/thermal: Cool a devfreq device instead of a cpufreq policy.
The cooling device renamed in the previous commit was written against a
cpufreq framework that never landed.  It includes nuttx/cpufreq.h, which
does not exist, and THERMAL_CDEV_CPUFREQ depends on CPUFREQ, which no
Kconfig in the tree defines, so it has never been selectable and has never
been compiled.  The cpufreq half of the dummy driver is orphaned the same
way behind THERMAL_DUMMY_CPUFREQ.  Upstream noticed once already and
dropped cpufreq from the sim thermal configuration in 898a5d501f.

devfreq does the same job and is here.  It carries the frequency table,
arbitrates windows through QoS, and its DEVFREQ_CONFLICT_PREFER_LOW is
documented as the policy for a device protecting a thermal budget, which
is exactly a cooling device's claim on it.  Point the cooling device at
that instead, and the thermal framework can throttle again.

Two things change beyond the API.  The cooling state now names a ceiling
rather than a two entry window, because devfreq resolves a conflicting
floor in the ceiling's favour, and that makes the whole table reachable:
max_state is one less than the number of usable entries, state zero leaves
the top entry available and the highest state holds the device at the
bottom one.  A DEVFREQ_ENTRY_INVALID entry is a hole the driver has
punched and cannot be installed as a ceiling, so it earns no cooling
state; counting it would both advertise a state the device cannot deliver
and, on reaching it, install a ceiling of ~0u, which caps nothing.  And the device is found by name, since devfreq is multi instance
where a cpufreq policy was singular, so THERMAL_CDEV_DEVFREQ_NAME says
which one to cool and what to call the cooling device in a zone's map.

The dummy driver gains a devfreq lower half in place of its cpufreq one,
which gives the tree its first devfreq consumer and makes the whole path
testable without hardware.  On sim, walking the dummy zone from 45 to 90
degrees:

  temp   cooling state   frequency
    60               0         900
    62               1         700
    61               2         500
    72               3         300
    74               4         100

and back down again as it cools.

Also fixes two faults the file could not previously reveal: it called
therr and thinfo without including nuttx/debug.h, and it reached the
driver by casting the policy pointer, which worked only while driver was
the first member.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Justin Hammond <justin@dynam.ac>
2026-08-18 09:46:47 -03:00
..
CMakeLists.txt drivers/thermal: Cool a devfreq device instead of a cpufreq policy. 2026-08-18 09:46:47 -03:00
Kconfig drivers/thermal: Cool a devfreq device instead of a cpufreq policy. 2026-08-18 09:46:47 -03:00
Make.defs drivers/thermal: Cool a devfreq device instead of a cpufreq policy. 2026-08-18 09:46:47 -03:00
thermal_core.c drivers/thermal: Cool a devfreq device instead of a cpufreq policy. 2026-08-18 09:46:47 -03:00
thermal_core.h drivers/thermal: Cool a devfreq device instead of a cpufreq policy. 2026-08-18 09:46:47 -03:00
thermal_devfreq_cooling.c drivers/thermal: Cool a devfreq device instead of a cpufreq policy. 2026-08-18 09:46:47 -03:00
thermal_dummy.c drivers/thermal: Cool a devfreq device instead of a cpufreq policy. 2026-08-18 09:46:47 -03:00
thermal_procfs.c Thermal/procfs: Do not print invalid target cooling state directly 2024-12-26 09:23:10 +08:00
thermal_step_wise.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00