Commit Graph

3014 Commits

Author SHA1 Message Date
Rafael J. Wysocki
3bc5ed15bd - Add power domain DT bindings for new Amlogic SoCs (Georges Stark)
- Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() in the ST
   driver and add a Kconfig dependency on THERMAL_OF subsystem for the
   STi driver (Raphael Gallais-Pou)
 
 - Simplify with dev_err_probe() the error code path in the probe
   functions for the brcmstb driver (Yan Zhen)
 
 - Remove trailing space after \n newline in the Renesas driver (Colin
   Ian King)
 
 - Add DT binding compatible string for the SA8255p with the tsens
   driver (Nikunj Kela)
 
 - Use the devm_clk_get_enabled() helpers to simplify the init routine
   in the sprd driver (Huan Yang)
 
 - Remove __maybe_unused notations for the functions by using the new
   RUNTIME_PM_OPS() and SYSTEM_SLEEP_PM_OPS() macros on the IMx and
   Qoriq drivers (Fabio Estevam)
 
 - Remove unused declarations in the header file as the functions were
   removed in a previous change on the ti-soc-thermal driver (Zhang
   Zekun)
 
 - Simplify with dev_err_probe()	the error code path in the probe
   functions for the imx_sc_thermal driver (Alexander Stein)
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEGn3N4YVz0WNVyHskqDIjiipP6E8FAmba5PkACgkQqDIjiipP
 6E+8JQgAhaU8DhKMKHDG8sGPC6LSFIrssIZoGJ4T+POEEyHNRFP90f1c+tyO20st
 ScWi6jomj6EySotfs5X6MJzXhIABIw54OArL9sny0xUBC0Y1V008pjq3QJrMICbn
 HWz8OnEcpMh+3d/fsP82vjv59AJp3EJjmOjtg5rTEwNTI4ZkanM7zUoAykCf07Ui
 w3n4IO8Bu6GlU83FtLB72ePmXqggNN0a4pejGxb/vNSB5rwHBWxyBEQRJmcdg9Ic
 ZbFD2Hyr9tNxEJQzqlI6hoqPj25y4SeP61PkWM47S4zW3tXv0oicNFDXj8WJKzpo
 waOg0Q6Igen7hyC2XQzKQ7VSQF07gw==
 =+d7/
 -----END PGP SIGNATURE-----

Merge tag 'thermal-v6.12-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/thermal/linux into

Merge thermal drivers changes for v6.12-rc1 from Daniel Lezcano:

"- Add power domain DT bindings for new Amlogic SoCs (Georges Stark)

 - Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() in the ST
   driver and add a Kconfig dependency on THERMAL_OF subsystem for the
   STi driver (Raphael Gallais-Pou)

 - Simplify with dev_err_probe() the error code path in the probe
   functions for the brcmstb driver (Yan Zhen)

 - Remove trailing space after \n newline in the Renesas driver (Colin
   Ian King)

 - Add DT binding compatible string for the SA8255p with the tsens
   driver (Nikunj Kela)

 - Use the devm_clk_get_enabled() helpers to simplify the init routine
   in the sprd driver (Huan Yang)

 - Remove __maybe_unused notations for the functions by using the new
   RUNTIME_PM_OPS() and SYSTEM_SLEEP_PM_OPS() macros on the IMx and
   Qoriq drivers (Fabio Estevam)

 - Remove unused declarations in the header file as the functions were
   removed in a previous change on the ti-soc-thermal driver (Zhang
   Zekun)

 - Simplify with dev_err_probe()	the error code path in the probe
   functions for the imx_sc_thermal driver (Alexander Stein)"

* tag 'thermal-v6.12-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/thermal/linux:
  thermal/drivers/imx_sc_thermal: Use dev_err_probe
  thermal/drivers/ti-soc-thermal: Remove unused declarations
  thermal/drivers/imx: Remove __maybe_unused notations
  thermal/drivers/qoriq: Remove __maybe_unused notations
  thermal/drivers/sprd: Use devm_clk_get_enabled() helpers
  dt-bindings: thermal: tsens: document support on SA8255p
  thermal/drivers/renesas: Remove trailing space after \n newline
  thermal/drivers/brcmstb_thermal: Simplify with dev_err_probe()
  thermal/drivers/sti: Depend on THERMAL_OF subsystem
  thermal/drivers/st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
  dt-bindings: thermal: amlogic,thermal: add optional power-domains
2024-09-10 10:54:15 +02:00
Rafael J. Wysocki
e3ee4ab0fd Merge branch 'thermal-core'
Merge thermal core fixes and cleanups for 6.12:

 - Refuse to accept trip point temperature or hysteresis that would lead
   to an invalid threshold value when setting them via sysfs (Rafael
   Wysocki).

 - Adjust states of all uninitialized instances in the .manage()
   callback of the Bang-bang thermal governor (Rafael Wysocki).

 - Drop a couple of redundant checks along with the code depending on
   them from the thermal core (Rafael Wysocki).

 - Rearrange the thermal core to avoid redundant checks and simplify
   control flow in a couple of code paths (Rafael Wysocki).

* thermal-core:
  thermal: core: Drop thermal_zone_device_is_enabled()
  thermal: core: Check passive delay in monitor_thermal_zone()
  thermal: core: Drop dead code from monitor_thermal_zone()
  thermal: core: Drop redundant lockdep_assert_held()
  thermal: gov_bang_bang: Adjust states of all uninitialized instances
  thermal: sysfs: Add sanity checks for trip temperature and hysteresis
2024-09-09 18:18:49 +02:00
Rafael J. Wysocki
54fccad63e thermal: core: Drop thermal_zone_device_is_enabled()
There are only two callers of thermal_zone_device_is_enabled()
and one of them call is under the zone lock and the other one uses
lockdep_assert_held() on that lock.  Thus the lockdep_assert_held()
in thermal_zone_device_is_enabled() is redundant and it could be
dropped, but then the function would merely become a wrapper around
a simple tz->mode check that is more convenient to do directly.

Accordingly, drop thermal_zone_device_is_enabled() altogether and update
its callers to check tz->mode directly as appropriate.

While at it, combine the tz->mode and tz->suspended checks in
__thermal_zone_device_update() because they are of a similar category
and if any of them evaluates to "true", the outcome is the same.

No intentinal functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/9353673.CDJkKcVGEf@rjwysocki.net
2024-09-05 12:33:24 +02:00
Rafael J. Wysocki
3c3ee53df4 thermal: core: Check passive delay in monitor_thermal_zone()
The only case in which thermal_zone_device_set_polling() is called
with its second argument equal to zero is when passive cooling is
under way and passive_delay_jiffies is 0, which only happens when
the given thermal zone is not polled at all.

If monitor_thermal_zone() is modified to check passive_delay_jiffies
directly, the check of the thermal_zone_device_set_polling() second
argument against 0 can be dropped and a passive_delay check can be
dropped from thermal_zone_device_register_with_trips(), so change the
code accordingly.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/2004353.PYKUYFuaPT@rjwysocki.net
2024-09-05 12:33:21 +02:00
Rafael J. Wysocki
fcfacd544b thermal: core: Drop dead code from monitor_thermal_zone()
Since monitor_thermal_zone() is only called when the given thermal zone
has been enabled, as per the thermal_zone_device_is_enabled() check in
__thermal_zone_device_update(), the tz->mode check in it always
evaluates to "false" and the thermal_zone_device_set_polling()
invocation depending on it is dead code, so drop it.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/10547425.nUPlyArG6x@rjwysocki.net
2024-09-05 12:33:18 +02:00
Rafael J. Wysocki
49029b507e thermal: core: Drop redundant lockdep_assert_held()
Along the lines of commit 24aad192c6 ("thermal: core: Drop
redundant checks from thermal_bind_cdev_to_trip()") notice that
thermal_unbind_cdev_from_trip() is only called by
thermal_zone_cdev_unbind() under the thermal zone lock, so it
need not use lockdep_assert_held() for that lock.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/3341369.44csPzL39Z@rjwysocki.net
2024-09-05 12:33:15 +02:00
Rafael J. Wysocki
15cb56bd52 thermal: gov_bang_bang: Adjust states of all uninitialized instances
If a cooling device is registered after a thermal zone it should be
bound to and the trip point it should be bound to has already been
crossed by the zone temperature on the way up, the cooling device's
state may need to be adjusted, but the Bang-bang governor will not
do that because its .manage() callback only looks at thermal instances
for trip points whose thresholds are below or at the zone temperature.

Address this by updating bang_bang_manage() to look at all of the
uninitialized thermal instances and setting their target states in
accordance with the position of the zone temperature with respect to
the threshold of the given trip point.

Fixes: 5f64b4a1ab ("thermal: gov_bang_bang: Add .manage() callback")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/6103874.lOV4Wx5bFT@rjwysocki.net
2024-09-05 12:32:54 +02:00
Rafael J. Wysocki
874b6476fa thermal: sysfs: Add sanity checks for trip temperature and hysteresis
Add sanity checks for new trip temperature and hysteresis values to
trip_point_temp_store() and trip_point_hyst_store() to prevent trip
point threshold from falling below THERMAL_TEMP_INVALID.

However, still allow user space to pass THERMAL_TEMP_INVALID as the
new trip temperature value to invalidate the trip if necessary.

Also allow the hysteresis to be updated when the temperature is invalid
to allow user space to avoid having to adjust hysteresis after a valid
temperature has been set, but in that case just change the value and do
nothing else.

Fixes: be0a3600aa ("thermal: sysfs: Rework the handling of trip point updates")
Cc: 6.8+ <stable@vger.kernel.org> # 6.8+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/12528772.O9o76ZdvQC@rjwysocki.net
2024-09-05 12:32:09 +02:00
Alexander Stein
7d8abc5f3b thermal/drivers/imx_sc_thermal: Use dev_err_probe
This adds the error code to the error message and also stores that
message in case of probe deferral.

Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Link: https://lore.kernel.org/r/20240717085517.3333385-1-alexander.stein@ew.tq-group.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2024-09-04 15:31:29 +02:00
Zhang Zekun
14ed0ef0a2 thermal/drivers/ti-soc-thermal: Remove unused declarations
The functions definition of ti_bandgap_read_thot(),
ti_bandgap_write_thot(), ti_bandgap_read_tcold() and
ti_bandgap_write_tcold() has been removed since commit 9bebf3485c
("thermal: ti-soc-thermal: remove dead code"), remain the declarations
untouched in the header files. So, clean up this unused declarations.

Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
Reviewed-by: Dhruva Gole <d-gole@ti.com>
Link: https://lore.kernel.org/r/20240812125210.94280-1-zhangzekun11@huawei.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2024-09-02 13:19:46 +02:00
Fabio Estevam
41df03900d thermal/drivers/imx: Remove __maybe_unused notations
Replace SET_RUNTIME_PM_OPS()/SET SYSTEM_SLEEP_PM_OPS() with their modern
RUNTIME_PM_OPS() and SYSTEM_SLEEP_PM_OPS() alternatives.

The combined usage of pm_ptr() and RUNTIME_PM_OPS/SYSTEM_SLEEP_PM_OPS()
allows the compiler to evaluate if the runtime suspend/resume() functions
are used at build time or are simply dead code.

This allows removing __maybe_unused notations from the suspend/resume()
functions.

Signed-off-by: Fabio Estevam <festevam@denx.de>
Link: https://lore.kernel.org/r/20240820012616.1449210-2-festevam@gmail.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2024-09-02 13:17:53 +02:00
Fabio Estevam
bf2876f6ba thermal/drivers/qoriq: Remove __maybe_unused notations
The combined usage of pm_sleep_ptr() and DEFINE_SIMPLE_DEV_PM_OPS()
allows the compiler to evaluate if the suspend/resume() functions
are used at build time or are simply dead code.

This allows removing __maybe_unused notations from the suspend/resume()
functions.

Signed-off-by: Fabio Estevam <festevam@denx.de>
Link: https://lore.kernel.org/r/20240820012616.1449210-1-festevam@gmail.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2024-09-02 13:17:46 +02:00
Huan Yang
d5714524fc thermal/drivers/sprd: Use devm_clk_get_enabled() helpers
The devm_clk_get_enabled() helpers:
    - call devm_clk_get()
    - call clk_prepare_enable() and register what is needed in order to
     call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

Signed-off-by: Huan Yang <link@vivo.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240820094450.101976-1-link@vivo.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2024-09-02 13:14:23 +02:00
Colin Ian King
b615615e49 thermal/drivers/renesas: Remove trailing space after \n newline
There is a extraneous space after a newline in a dev_err message.
Remove it.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Link: https://lore.kernel.org/r/20240901162719.144406-1-colin.i.king@gmail.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2024-09-02 13:11:07 +02:00
Yan Zhen
b779bbb9df thermal/drivers/brcmstb_thermal: Simplify with dev_err_probe()
dev_err_probe() is used to log an error message during the probe process
of a device.

It can simplify the error path and unify a message template.

Using this helper is totally fine even if err is known to never
be -EPROBE_DEFER.

The benefit compared to a normal dev_err() is the standardized format
of the error code, it being emitted symbolically and the fact that
the error code is returned which allows more compact error paths.

Signed-off-by: Yan Zhen <yanzhen@vivo.com>
Link: https://lore.kernel.org/r/20240830103918.501234-1-yanzhen@vivo.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2024-09-02 13:09:49 +02:00
Raphael Gallais-Pou
8e12f1f881 thermal/drivers/sti: Depend on THERMAL_OF subsystem
Switch to thermal_of_zone to handle thermal-zones. Replace
thermal_zone_device_register() by devm_thermal_of_zone_register() and
remove ops st_thermal_get_trip_type, st_thermal_get_trip_temp.

Signed-off-by: Raphael Gallais-Pou <rgallaispou@gmail.com>
Link: https://lore.kernel.org/r/20240716-thermal-v4-2-947b327e165c@gmail.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2024-09-02 12:43:27 +02:00
Raphael Gallais-Pou
27fec3cc9e thermal/drivers/st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
Letting the compiler remove these functions when the kernel is built
without CONFIG_PM_SLEEP support is simpler and less error prone than the
use of #ifdef based kernel configuration guards.

Remove those guards on every ST thermal related drivers.

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Signed-off-by: Raphael Gallais-Pou <rgallaispou@gmail.com>
Link: https://lore.kernel.org/r/20240716-thermal-v4-1-947b327e165c@gmail.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2024-09-02 12:43:20 +02:00
Rafael J. Wysocki
f5c0597434 Merge branch 'thermal-core'
Merge thermal core updates for 6.12 which, among other things, rework
the thermal driver interface for binding cooling devices to thermal
zones and add a thermal core testing module:

 - Update some thermal drivers to eliminate thermal_zone_get_trip()
   calls from them and get rid of that function (Rafael Wysocki).

 - Update the thermal sysfs code to store trip point attributes in trip
   descriptors and get to trip points via attribute pointers (Rafael
   Wysocki).

 - Move the computation of the low and high boundaries for
   thermal_zone_set_trips() to __thermal_zone_device_update() (Daniel
   Lezcano).

 - Introduce a debugfs-based facility for thermal core testing (Rafael
   Wysocki).

 - Replace the thermal zone .bind() and .unbind() callbacks for binding
   cooling devices to thermal zones with one .should_bind() callback
   used for deciding whether or not a given cooling devices should be
   bound to a given trip point in a given thermal zone (Rafael Wysocki).

 - Eliminate code that has no more users after the other changes, drop
   some redundant checks from the thermal core and clean it up (Rafael
   Wysocki).

 - Fix rounding of delay jiffies in the thermal core (Rafael Wysocki).

* thermal-core: (31 commits)
  thermal: core: Drop tz field from struct thermal_instance
  thermal: core: Drop redundant checks from thermal_bind_cdev_to_trip()
  thermal: core: Rename cdev-to-thermal-zone bind/unbind functions
  thermal: core: Fix rounding of delay jiffies
  thermal: core: Clean up trip bind/unbind functions
  thermal: core: Drop unused bind/unbind functions and callbacks
  thermal/of: Use the .should_bind() thermal zone callback
  thermal: imx: Use the .should_bind() thermal zone callback
  mlxsw: core_thermal: Use the .should_bind() thermal zone callback
  platform/x86: acerhdf: Use the .should_bind() thermal zone callback
  thermal: core: Unexport thermal_bind_cdev_to_trip() and thermal_unbind_cdev_from_trip()
  thermal: ACPI: Use the .should_bind() thermal zone callback
  thermal: core: Introduce .should_bind() thermal zone callback
  thermal: core: Move thermal zone locking out of bind/unbind functions
  thermal: sysfs: Use the dev argument in instance-related show/store
  thermal: core: Drop redundant thermal instance checks
  thermal: core: Rearrange checks in thermal_bind_cdev_to_trip()
  thermal: core: Fold two functions into their respective callers
  thermal: Introduce a debugfs-based testing facility
  thermal/core: Compute low and high boundaries in thermal_zone_device_update()
  ...
2024-08-29 11:45:08 +02:00
Rafael J. Wysocki
e9654659fe thermal: core: Drop tz field from struct thermal_instance
After recent changes, it is only used for printing a debug message
in __thermal_cdev_update() which arguably is not worth preserving.

Drop it along with the dev_dbg() statement using it.

Link: https://lore.kernel.org/linux-pm/4a8d8f5a-122d-4c26-b8d6-76a65e42216b@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/4934182.GXAFRqVoOG@rjwysocki.net
2024-08-23 15:56:29 +02:00
Rafael J. Wysocki
24aad192c6 thermal: core: Drop redundant checks from thermal_bind_cdev_to_trip()
Since thermal_bind_cdev_to_trip() is only called by
thermal_zone_cdev_binding() under the thermal zone lock and the latter
is only called by thermal_zone_device_register_with_trips() and
__thermal_cooling_device_register(), under thermal_list_lock in both
cases, both lockdep_assert_held() assertions can be dropped from it.

Moreover, in both cases thermal_zone_cdev_binding() is called after
both tz and cdev have been added to the global lists of thermal zones
and cooling device, respectively, so the check against their list nodes
in thermal_bind_cdev_to_trip() is redundant and can be dropped either.

Link: https://lore.kernel.org/linux-pm/CAJZ5v0jwkc2PB+osSkkYF9vJ1Vpp3MFE=cGQmQ2Xzjb3yjVfJg@mail.gmail.com/
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/4607540.LvFx2qVVIh@rjwysocki.net
2024-08-23 15:56:29 +02:00
Rafael J. Wysocki
91d7ed957e thermal: core: Rename cdev-to-thermal-zone bind/unbind functions
Rename thermal_zone_cdev_binding() and thermal_zone_cdev_unbinding()
to thermal_zone_cdev_bind() and thermal_zone_cdev_unbind(), respectively,
to make the naming more consistent with the rest of the code.

No functional impact.

Link: https://lore.kernel.org/linux-pm/19beefd9-d3f9-4d43-a45d-d241996de2d0@linaro.org/
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/6093162.lOV4Wx5bFT@rjwysocki.net
2024-08-23 15:56:29 +02:00
Rafael J. Wysocki
8144dbe68c thermal: core: Fix rounding of delay jiffies
Using round_jiffies() in thermal_set_delay_jiffies() is invalid because
its argument should be time in the future in absolute jiffies and it
computes the result with respect to the current jiffies value at the
invocation time.  Fortunately, in the majority of cases it does not
make any difference due to the time_is_after_jiffies() check in
round_jiffies_common().

While using round_jiffies_relative() instead of round_jiffies() might
reflect the intent a bit better, it still would not be defensible
because that function should be called when the timer is about to be
set and it is not suitable for pre-computation of delay values.

Accordingly, drop thermal_set_delay_jiffies() altogether, simply
convert polling_delay and passive_delay to jiffies during thermal
zone initialization and make thermal_zone_device_set_polling() call
round_jiffies_relative() on the delay if it is greather than 1 second.

Fixes: 17d399cd9c ("thermal/core: Precompute the delays from msecs to jiffies")
Fixes: e5f2cda61d ("thermal/core: Move thermal_set_delay_jiffies to static")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/1994438.PYKUYFuaPT@rjwysocki.net
2024-08-23 15:53:53 +02:00
Rafael J. Wysocki
18749317d1 thermal: core: Clean up trip bind/unbind functions
Make thermal_bind_cdev_to_trip() take a struct cooling_spec pointer
to reduce the number of its arguments, change the return type of
thermal_unbind_cdev_from_trip() to void and rearrange the code in
thermal_zone_cdev_binding() to reduce the indentation level.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/1831773.TLkxdtWsSY@rjwysocki.net
[ rjw: Changed the name of a new function argument ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-08-23 15:42:58 +02:00
Rafael J. Wysocki
c579286a51 thermal: core: Drop unused bind/unbind functions and callbacks
There are no more callers of thermal_zone_bind_cooling_device() and
thermal_zone_unbind_cooling_device(), so drop them along with all of
the corresponding headers, code and documentation.

Moreover, because the .bind() and .unbind() thermal zone callbacks would
only be used when the above functions, respectively, were called, drop
them as well along with all of the code related to them.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/4251116.1IzOArtZ34@rjwysocki.net
2024-08-23 15:42:58 +02:00
Rafael J. Wysocki
94c6110b0b thermal/of: Use the .should_bind() thermal zone callback
Make the thermal_of driver use the .should_bind() thermal zone callback
to provide the thermal core with the information on whether or not to
bind the given cooling device to the given trip point in the given
thermal zone.  If it returns 'true', the thermal core will bind the
cooling device to the trip and the corresponding unbinding will be
taken care of automatically by the core on the removal of the involved
thermal zone or cooling device.

This replaces the .bind() and .unbind() thermal zone callbacks which
assumed the same trip points ordering in the driver and in the thermal
core (that may not be true any more in the future).  The .bind()
callback would walk the given thermal zone's cooling maps to find all
of the valid trip point combinations with the given cooling device and
it would call thermal_zone_bind_cooling_device() for all of them using
trip point indices reflecting the ordering of the trips in the DT.

The .should_bind() callback still walks the thermal zone's cooling maps,
but it can use the trip object passed to it by the thermal core to find
the trip in question in the first place and then it uses the
corresponding 'cooling-device' entries to look up the given cooling
device.  To be able to match the trip object provided by the thermal
core to a specific device node, the driver sets the 'priv' field of each
trip to the corresponding device node pointer during initialization.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Daniel Lezcano <daniel.lezcano@linaro.org> # rk3399-rock960
Link: https://patch.msgid.link/2236794.NgBsaNRSFp@rjwysocki.net
[ rjw: Removed excessive of_node_put() ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-08-23 15:42:26 +02:00
Krzysztof Kozlowski
c0a1ef9c5b thermal: of: Fix OF node leak in of_thermal_zone_find() error paths
Terminating for_each_available_child_of_node() loop requires dropping OF
node reference, so bailing out on errors misses this.  Solve the OF node
reference leak with scoped for_each_available_child_of_node_scoped().

Fixes: 3fd6d6e2b4 ("thermal/of: Rework the thermal device tree initialization")
Cc: <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/20240814195823.437597-3-krzysztof.kozlowski@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-08-22 20:58:49 +02:00
Krzysztof Kozlowski
662b52b761 thermal: of: Fix OF node leak in thermal_of_zone_register()
thermal_of_zone_register() calls of_thermal_zone_find() which will
iterate over OF nodes with for_each_available_child_of_node() to find
matching thermal zone node.  When it finds such, it exits the loop and
returns the node.  Prematurely ending for_each_available_child_of_node()
loops requires dropping OF node reference, thus success of
of_thermal_zone_find() means that caller must drop the reference.

Fixes: 3fd6d6e2b4 ("thermal/of: Rework the thermal device tree initialization")
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/20240814195823.437597-2-krzysztof.kozlowski@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-08-22 20:58:49 +02:00
Krzysztof Kozlowski
afc954fd22 thermal: of: Fix OF node leak in thermal_of_trips_init() error path
Terminating for_each_child_of_node() loop requires dropping OF node
reference, so bailing out after thermal_of_populate_trip() error misses
this.  Solve the OF node reference leak with scoped
for_each_child_of_node_scoped().

Fixes: d0c75fa2c1 ("thermal/of: Initialize trip points separately")
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/20240814195823.437597-1-krzysztof.kozlowski@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-08-22 20:58:49 +02:00
Rafael J. Wysocki
a32d621df4 thermal: imx: Use the .should_bind() thermal zone callback
Make the imx_thermal driver use the .should_bind() thermal zone callback
to provide the thermal core with the information on whether or not to
bind the given cooling device to the given trip point in the given
thermal zone.  If it returns 'true', the thermal core will bind the
cooling device to the trip and the corresponding unbinding will be
taken care of automatically by the core on the removal of the involved
thermal zone or cooling device.

In the imx_thermal case, it only needs to return 'true' for the passive
trip point and it will match any cooling device passed to it, in
analogy with the old-style imx_bind() callback function.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/2485070.jE0xQCEvom@rjwysocki.net
2024-08-22 17:43:14 +02:00
Rafael J. Wysocki
2fb8563364 thermal: core: Unexport thermal_bind_cdev_to_trip() and thermal_unbind_cdev_from_trip()
Since thermal_bind_cdev_to_trip() and thermal_unbind_cdev_from_trip()
are only called locally in the thermal core now, they can be static,
so change their definitions accordingly and drop their headers from
the global thermal header file.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/3512161.QJadu78ljV@rjwysocki.net
2024-08-22 17:43:14 +02:00
Rafael J. Wysocki
aa35e56a52 thermal: core: Introduce .should_bind() thermal zone callback
The current design of the code binding cooling devices to trip points in
thermal zones is convoluted and hard to follow.

Namely, a driver that registers a thermal zone can provide .bind()
and .unbind() operations for it, which are required to call either
thermal_bind_cdev_to_trip() and thermal_unbind_cdev_from_trip(),
respectively, or thermal_zone_bind_cooling_device() and
thermal_zone_unbind_cooling_device(), respectively, for every relevant
trip point and the given cooling device.  Moreover, if .bind() is
provided and .unbind() is not, the cleanup necessary during the removal
of a thermal zone or a cooling device may not be carried out.

In other words, the core relies on the thermal zone owners to do the
right thing, which is error prone and far from obvious, even though all
of that is not really necessary.  Specifically, if the core could ask
the thermal zone owner, through a special thermal zone callback, whether
or not a given cooling device should be bound to a given trip point in
the given thermal zone, it might as well carry out all of the binding
and unbinding by itself.  In particular, the unbinding can be done
automatically without involving the thermal zone owner at all because
all of the thermal instances associated with a thermal zone or cooling
device going away must be deleted regardless.

Accordingly, introduce a new thermal zone operation, .should_bind(),
that can be invoked by the thermal core for a given thermal zone,
trip point and cooling device combination in order to check whether
or not the cooling device should be bound to the trip point at hand.
It takes an additional cooling_spec argument allowing the thermal
zone owner to specify the highest and lowest cooling states of the
cooling device and its weight for the given trip point binding.

Make the thermal core use this operation, if present, in the absence of
.bind() and .unbind().  Note that .should_bind() will be called under
the thermal zone lock.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/9334403.CDJkKcVGEf@rjwysocki.net
2024-08-22 17:43:14 +02:00
Rafael J. Wysocki
d48005511a thermal: core: Move thermal zone locking out of bind/unbind functions
Since thermal_bind_cdev_to_trip() and thermal_unbind_cdev_from_trip()
acquire the thermal zone lock, the locking rules for their callers get
complicated.  In particular, the thermal zone lock cannot be acquired
in any code path leading to one of these functions even though it might
be useful to do so.

To address this, remove the thermal zone locking from both these
functions, add lockdep assertions for the thermal zone lock to both
of them and make their callers acquire the thermal zone lock instead.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/3837835.kQq0lBPeGt@rjwysocki.net
2024-08-22 17:43:14 +02:00
Rafael J. Wysocki
0a0a40d71c thermal: sysfs: Use the dev argument in instance-related show/store
Two sysfs show/store functions for attributes representing thermal
instances, trip_point_show() and weight_store(), retrieve the thermal
zone pointer from the instance object at hand, but they may also get
it from their dev argument, which is more consistent with what the
other thermal sysfs functions do, so make them do so.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/1987669.PYKUYFuaPT@rjwysocki.net
2024-08-22 17:43:14 +02:00
Rafael J. Wysocki
eb3591cde1 thermal: core: Drop redundant thermal instance checks
Because the trip and cdev pointers are sufficient to identify a thermal
instance holding them unambiguously, drop the additional thermal zone
checks from two loops walking the list of thermal instances in a
thermal zone.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/10527734.nUPlyArG6x@rjwysocki.net
2024-08-22 17:43:14 +02:00
Rafael J. Wysocki
b4e6d39817 thermal: core: Rearrange checks in thermal_bind_cdev_to_trip()
It is not necessary to look up the thermal zone and the cooling device
in the respective global lists to check whether or not they are
registered.  It is sufficient to check whether or not their respective
list nodes are empty for this purpose.

Use the above observation to simplify thermal_bind_cdev_to_trip().  In
addition, eliminate an unnecessary ternary operator from it.

Moreover, add lockdep_assert_held() for thermal_list_lock to it because
that lock must be held by its callers when it is running.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/3324214.44csPzL39Z@rjwysocki.net
2024-08-22 17:43:14 +02:00
Rafael J. Wysocki
a8bbe6f10f thermal: core: Fold two functions into their respective callers
Fold bind_cdev() into __thermal_cooling_device_register() and bind_tz()
into thermal_zone_device_register_with_trips() to reduce code bloat and
make it somewhat easier to follow the code flow.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/2962184.e9J7NaK4W3@rjwysocki.net
2024-08-22 17:43:13 +02:00
Rafael J. Wysocki
f6a034f2df thermal: Introduce a debugfs-based testing facility
Introduce a facility allowing the thermal core functionality to be
exercised in a controlled way in order to verify its behavior, without
affecting its regular users noticeably.

It is based on the idea of preparing thermal zone templates along with
their trip points by writing to files in debugfs.  When ready, those
templates can be used for registering test thermal zones with the
thermal core.

The temperature of a test thermal zone created this way can be adjusted
via debugfs, which also triggers a __thermal_zone_device_update() call
for it.  By manipulating the temperature of a test thermal zone, one can
check if the thermal core reacts to the changes of it as expected.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/6065927.lOV4Wx5bFT@rjwysocki.net
[ rjw: Fixed ordering of kcalloc() arguments ]
[ rjw: Fixed debugfs_create_dir() return value checks ]
[ rjw: Fixed two kerneldoc comments ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-08-22 17:42:57 +02:00
Yang Ruibin
57df60e1f9 thermal/debugfs: Fix the NULL vs IS_ERR() confusion in debugfs_create_dir()
The debugfs_create_dir() return value is never NULL, it is either a
valid pointer or an error one.

Use IS_ERR() to check it.

Fixes: 7ef01f228c ("thermal/debugfs: Add thermal debugfs information for mitigation episodes")
Fixes: 755113d767 ("thermal/debugfs: Add thermal cooling device debugfs information")
Signed-off-by: Yang Ruibin <11162571@vivo.com>
Link: https://patch.msgid.link/20240821075934.12145-1-11162571@vivo.com
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-08-21 20:38:44 +02:00
Daniel Lezcano
f9ba1e0517 thermal/core: Compute low and high boundaries in thermal_zone_device_update()
In order to set the scene for the thresholds support which have to
manipulate the low and high temperature boundaries for the interrupt
support, we must pass the low and high values to the incoming
thresholds routine.

The variables are set from the thermal_zone_set_trips() where the
function loops the thermal trips to figure out the next and the
previous temperatures to set the interrupt to be triggered when they
are crossed.

These variables will be needed by the function in charge of handling
the thresholds in the incoming changes but they are local to the
aforementioned function thermal_zone_set_trips().

Move the low and high boundaries computation out of the function in
thermal_zone_device_update() so they are accessible from there.

The positive side effect is they are computed in the same loop as
handle_thermal_trip(), so we remove one loop.

Co-developed-by: Rafael J. Wysocki <rjw@rjwysocki.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/20240816081241.1925221-2-daniel.lezcano@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-08-19 16:06:58 +02:00
Rafael J. Wysocki
5ae98b5a9f Merge back thermal core material for 6.12. 2024-08-19 14:42:19 +02:00
Rafael J. Wysocki
6e6f58a170 thermal: gov_bang_bang: Use governor_data to reduce overhead
After running once, the for_each_trip_desc() loop in
bang_bang_manage() is pure needless overhead because it is not going to
make any changes unless a new cooling device has been bound to one of
the trips in the thermal zone or the system is resuming from sleep.

For this reason, make bang_bang_manage() set governor_data for the
thermal zone and check it upfront to decide whether or not it needs to
do anything.

However, governor_data needs to be reset in some cases to let
bang_bang_manage() know that it should walk the trips again, so add an
.update_tz() callback to the governor and make the core additionally
invoke it during system resume.

To avoid affecting the other users of that callback unnecessarily, add
a special notification reason for system resume, THERMAL_TZ_RESUME, and
also pass it to __thermal_zone_device_update() called during system
resume for consistency.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Peter Kästle <peter@piie.net>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Cc: 6.10+ <stable@vger.kernel.org> # 6.10+
Link: https://patch.msgid.link/2285575.iZASKD2KPV@rjwysocki.net
2024-08-16 13:13:59 +02:00
Rafael J. Wysocki
5f64b4a1ab thermal: gov_bang_bang: Add .manage() callback
After recent changes, the Bang-bang governor may not adjust the
initial configuration of cooling devices to the actual situation.

Namely, if a cooling device bound to a certain trip point starts in
the "on" state and the thermal zone temperature is below the threshold
of that trip point, the trip point may never be crossed on the way up
in which case the state of the cooling device will never be adjusted
because the thermal core will never invoke the governor's
.trip_crossed() callback.  [Note that there is no issue if the zone
temperature is at the trip threshold or above it to start with because
.trip_crossed() will be invoked then to indicate the start of thermal
mitigation for the given trip.]

To address this, add a .manage() callback to the Bang-bang governor
and use it to ensure that all of the thermal instances managed by the
governor have been initialized properly and the states of all of the
cooling devices involved have been adjusted to the current zone
temperature as appropriate.

Fixes: 530c932bdf ("thermal: gov_bang_bang: Use .trip_crossed() instead of .throttle()")
Link: https://lore.kernel.org/linux-pm/1bfbbae5-42b0-4c7d-9544-e98855715294@piie.net/
Cc: 6.10+ <stable@vger.kernel.org> # 6.10+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Peter Kästle <peter@piie.net>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Link: https://patch.msgid.link/8419356.T7Z3S40VBb@rjwysocki.net
2024-08-16 13:13:49 +02:00
Rafael J. Wysocki
84248e35d9 thermal: gov_bang_bang: Split bang_bang_control()
Move the setting of the thermal instance target state from
bang_bang_control() into a separate function that will be also called
in a different place going forward.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Peter Kästle <peter@piie.net>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Cc: 6.10+ <stable@vger.kernel.org> # 6.10+
Link: https://patch.msgid.link/3313587.aeNJFYEL58@rjwysocki.net
2024-08-16 13:13:42 +02:00
Rafael J. Wysocki
b9b6ee6fe2 thermal: gov_bang_bang: Call __thermal_cdev_update() directly
Instead of clearing the "updated" flag for each cooling device
affected by the trip point crossing in bang_bang_control() and
walking all thermal instances to run thermal_cdev_update() for all
of the affected cooling devices, call __thermal_cdev_update()
directly for each of them.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Peter Kästle <peter@piie.net>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Cc: 6.10+ <stable@vger.kernel.org> # 6.10+
Link: https://patch.msgid.link/13583081.uLZWGnKmhe@rjwysocki.net
2024-08-16 13:13:33 +02:00
Rafael J. Wysocki
107280e137 thermal: sysfs: Refine the handling of trip hysteresis changes
Change trip_point_hyst_store() and replace thermal_zone_trip_updated()
with thermal_zone_set_trip_hyst() to follow the trip_point_temp_store()
code pattern for more consistency.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/5508466.Sb9uPGUboI@rjwysocki.net
2024-08-13 20:54:17 +02:00
Rafael J. Wysocki
afd84fb10c thermal: sysfs: Get to trips via attribute pointers
The  _store() and _show() functions for sysfs attributes corresponding
to trip point parameters (type, temperature and hysteresis) read the
trip ID from the attribute name and then use the trip ID as the index
in the given thermal zone's trips table to get to the trip object they
want.

Instead of doing this, make them use the attribute pointer they get
as the second argument to get to the trip object embedded in the same
struct thermal_trip_desc as the struct device_attribute pointed to by
it, which is much more straightforward and less overhead.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/114841552.nniJfEyVGO@rjwysocki.net
2024-08-13 20:53:18 +02:00
Rafael J. Wysocki
66b263306a thermal: core: Store trip sysfs attributes in thermal_trip_desc
Instead of allocating memory for trip point sysfs attributes separately,
store them in struct thermal_trip_desc for each trip individually which
allows a few extra memory allocations to be avoided.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/46571375.fMDQidcC6G@rjwysocki.net
2024-08-13 20:50:57 +02:00
Rafael J. Wysocki
8ecd953ca5 thermal: trip: Drop thermal_zone_get_trip()
There are no more callers of thermal_zone_get_trip() in the tree, so
drop it.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/2220301.Mh6RI2rZIc@rjwysocki.net
2024-08-02 14:01:12 +02:00
Rafael J. Wysocki
79f194dd54 thermal: trip: Get rid of thermal_zone_get_num_trips()
The only existing caller of thermal_zone_get_num_trips(), which is
rcar_gen3_thermal_probe(), uses this function to put the number of
trip points into a kernel log message, but this information is also
available from the thermal sysfs interface.

For this reason, remove the thermal_zone_get_num_trips() call from
rcar_gen3_thermal_probe() and drop the former altogether.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/2636988.Lt9SDvczpP@rjwysocki.net
2024-08-02 13:59:50 +02:00
Rafael J. Wysocki
96d819908d thermal: helpers: Drop get_thermal_instance()
There are no more users of get_thermal_instance(), so drop it.

While at it, replace get_instance() returning a pointer to struct
thermal_instance with thermal_instance_present() returning a bool
which is more straightforward.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/2014591.usQuhbGJ8B@rjwysocki.net
[ rjw: Dropped get_thermal_instance() documentation ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2024-08-02 13:57:04 +02:00