Commit Graph

2456 Commits

Author SHA1 Message Date
Daniel Lezcano
ba7894be5e thermal: intel: pch_thermal: Use thermal driver device to write a trace
The pch_critical() callback accesses the thermal zone device structure
internals, it dereferences the thermal zone struct device and the 'type'.

Use the available accessors instead of accessing the structure directly.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-04-27 19:20:12 +02:00
Daniel Lezcano
7cefbaf081 thermal: core: Encapsulate tz->device field
There are still some drivers needing to play with the thermal zone
device internals. That is not the best but until we can figure out if
the information is really needed, let's encapsulate the field used in
the thermal zone device structure, so we can move forward relocating
the thermal zone device structure definition in the thermal framework
private headers.

Some drivers are accessing tz->device, that implies they need to have
the knowledge of the thermal_zone_device structure but we want to
self-encapsulate this structure and reduce the scope of the structure
to the thermal core only.

By adding this wrapper, these drivers won't need the thermal zone
device structure definition and are no longer an obstacle to its
relocation to the private thermal core headers.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-04-27 19:20:12 +02:00
Zhang Rui
e4006bfec1 thermal: gov_step_wise: Adjust code logic to match comment
For the algorithm of choosing the next target state in step_wise
governor, the code does the right thing but is implemented in a
way different from what the comment describes. And this hurts the code
readability.

As the logic in the comment is simpler, adjust the code logic to align
with the comment.

No functional change.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
[ rjw: Subject edit ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-04-27 19:17:11 +02:00
Zhang Rui
cead266cdb thermal: gov_step_wise: Delete obsolete comment
Commit 4102c4042a ("thermal/core: Remove DROP_FULL and RAISE_FULL")
removes support for THERMAL_TREND_RAISE_FULL/DROP_FULL but leaves the
comment unchanged.

Delete the obsolte comment about THERMAL_TREND_RAISE_FULL/DROP_FULL.

Fixes: 4102c4042a ("thermal/core: Remove DROP_FULL and RAISE_FULL")
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-04-27 19:17:11 +02:00
Srinivas Pandruvada
5bc6b1df65 thermal: intel: int340x: Add DLVR support for RFIM control
Add support for DLVR (Digital Linear Voltage Regulator) attributes,
which can be used to control RFIM.

Here instead of "fivr" another directory "dlvr" is created with DLVR
attributes:

/sys/bus/pci/devices/0000:00:04.0/dlvr
├── dlvr_freq_mhz
├── dlvr_freq_select
├── dlvr_hardware_rev
├── dlvr_pll_busy
├── dlvr_rfim_enable
└── dlvr_spread_spectrum_pct
└── dlvr_control_mode
└── dlvr_control_lock

Attributes
dlvr_freq_mhz (RO):
Current DLVR PLL frequency in MHz.

dlvr_freq_select (RW):
Sets DLVR PLL clock frequency.

dlvr_hardware_rev (RO):
DLVR hardware revision.

dlvr_pll_busy (RO):
PLL can't accept frequency change when set.

dlvr_rfim_enable (RW):
0: Disable RF frequency hopping, 1: Enable RF frequency hopping.

dlvr_control_mode (RW):
Specifies how frequencies are spread. 0: Down spread, 1: Spread in Center.

dlvr_control_lock (RW):
1: future writes are ignored.

dlvr_spread_spectrum_pct (RW)
A write to this register updates the DLVR spread spectrum percent value.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
[ rjw: Subject edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-04-18 15:24:40 +02:00
Rafael J. Wysocki
51699e4c05 - Do preparating cleaning and DT bindings for RK3588 support
(Sebastian Reichel)
 
 - Add driver support for RK3588 (Finley Xiao)
 
 - Use devm_reset_control_array_get_exclusive() for the Rockchip driver
   (Ye Xingchen)
 
 - Detect power gated thermal zones and return -EAGAIN when reading the
   temperature (Mikko Perttunen)
 
 - Remove thermal_bind_params structure as it is unused (Zhang Rui)
 
 - Drop unneeded quotes in DT bindings allowing to run yamllint (Rob
   Herring)
 
 - Update the power allocator documentation according to the thermal
   trace relocation (Lukas Bulwahn)
 
 - Fix sensor 1 interrupt status bitmask for the Mediatek LVTS sensor
   (Chen-Yu Tsai)
 
 - Use the dev_err_probe() helper in the Amlogic driver (Ye Xingchen)
 
 - Add AP domain support to LVTS thermal controllers for mt8195
   (Balsam CHIHI)
 
 - Remove buggy call to thermal_of_zone_unregister() (Daniel Lezcano)
 
 - Make thermal_of_zone_[un]register() private to the thermal OF code
   (Daniel Lezcano)
 
 - Create a private copy of the thermal zone device parameters
   structure when registering a thermal zone (Daniel Lezcano)
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEGn3N4YVz0WNVyHskqDIjiipP6E8FAmQ5RcEACgkQqDIjiipP
 6E+jqAf/Zl/FYMwkyfnnbB1PVG1u2IuJMFYrpRK8rCl+WLgcM3FXqsUaQaKhwdvM
 9+qNtmCVRPPvDIkLpcwnD/bzJJfWW40NwFTEpGHf06LztGBXzqvbyKZjlMO9CeON
 jfxAf/s2xuX0bCRFE+x8BX4WHRir7j7Ivw6ATk40mvgZsedAwnMI6L5P6Mw7gIu3
 cpYGvM8rt0By+5VndVbuEDm9GRcOVd7ZgIFUMNUGvHBZ8IltkWmovmqWjeVIkW7Q
 5gWwspSWPfe4o4RB0oUMNWNtqFOps06n+sURvrP1q8Nv9KcK5rL4ricDXoZK6eqk
 IbdHvP19rPscVdN3VpbFBBt2Dm3KQA==
 =yfad
 -----END PGP SIGNATURE-----

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

Pull more thermal control changes for 6.4-rc1 from Daniel Lezcano:

"- Do preparating cleaning and DT bindings for RK3588 support
   (Sebastian Reichel)

 - Add driver support for RK3588 (Finley Xiao)

 - Use devm_reset_control_array_get_exclusive() for the Rockchip driver
   (Ye Xingchen)

 - Detect power gated thermal zones and return -EAGAIN when reading the
   temperature (Mikko Perttunen)

 - Remove thermal_bind_params structure as it is unused (Zhang Rui)

 - Drop unneeded quotes in DT bindings allowing to run yamllint (Rob
   Herring)

 - Update the power allocator documentation according to the thermal
   trace relocation (Lukas Bulwahn)

 - Fix sensor 1 interrupt status bitmask for the Mediatek LVTS sensor
   (Chen-Yu Tsai)

 - Use the dev_err_probe() helper in the Amlogic driver (Ye Xingchen)

 - Add AP domain support to LVTS thermal controllers for mt8195
   (Balsam CHIHI)

 - Remove buggy call to thermal_of_zone_unregister() (Daniel Lezcano)

 - Make thermal_of_zone_[un]register() private to the thermal OF code
   (Daniel Lezcano)

 - Create a private copy of the thermal zone device parameters
   structure when registering a thermal zone (Daniel Lezcano)"

* tag 'thermal-v6.4-rc1-2' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/thermal/linux:
  thermal/core: Alloc-copy-free the thermal zone parameters structure
  thermal/of: Unexport unused OF functions
  thermal/drivers/bcm2835: Remove buggy call to thermal_of_zone_unregister
  thermal/drivers/mediatek/lvts_thermal: Add AP domain for mt8195
  dt-bindings: thermal: mediatek: Add AP domain to LVTS thermal controllers for mt8195
  thermal: amlogic: Use dev_err_probe()
  thermal/drivers/mediatek/lvts_thermal: Fix sensor 1 interrupt status bitmask
  MAINTAINERS: adjust entry in THERMAL/POWER_ALLOCATOR after header movement
  dt-bindings: thermal: Drop unneeded quotes
  thermal/core: Remove thermal_bind_params structure
  thermal/drivers/tegra-bpmp: Handle offline zones
  thermal/drivers/rockchip: use devm_reset_control_array_get_exclusive()
  dt-bindings: rockchip-thermal: Support the RK3588 SoC compatible
  thermal/drivers/rockchip: Support RK3588 SoC in the thermal driver
  thermal/drivers/rockchip: Support dynamic sized sensor array
  thermal/drivers/rockchip: Simplify channel id logic
  thermal/drivers/rockchip: Use dev_err_probe
  thermal/drivers/rockchip: Simplify clock logic
  thermal/drivers/rockchip: Simplify getting match data
2023-04-17 15:52:27 +02:00
Rafael J. Wysocki
cfeeb7d37d Merge back general thermal control changes for 6.4-rc1. 2023-04-14 17:16:28 +02:00
Rafael J. Wysocki
065ca2a8c6 Merge back Intel thermal control material for 6.4-rc1. 2023-04-14 17:14:02 +02:00
Srinivas Pandruvada
117e4e5bd9 thermal: intel: Avoid updating unsupported THERM_STATUS_CLEAR mask bits
Some older processors don't allow BIT(13) and BIT(15) in the current
mask set by "THERM_STATUS_CLEAR_CORE_MASK". This results in:

unchecked MSR access error: WRMSR to 0x19c (tried to
write 0x000000000000aaa8) at rIP: 0xffffffff816f66a6
(throttle_active_work+0xa6/0x1d0)

To avoid unchecked MSR issues, check CPUID for each relevant feature and
use that information to set the supported feature bits only in the
"clear" mask for cores. Do the same for the analogous package mask set
by "THERM_STATUS_CLEAR_PKG_MASK".

Introduce functions thermal_intr_init_core_clear_mask() and
thermal_intr_init_pkg_clear_mask() to set core and package mask bits,
respectively. These functions are called during initialization.

Fixes: 6fe1e64b60 ("thermal: intel: Prevent accidental clearing of HFI status")
Reported-by: Rui Salvaterra <rsalvaterra@gmail.com>
Link: https://lore.kernel.org/lkml/cdf43fb423368ee3994124a9e8c9b4f8d00712c6.camel@linux.intel.com/T/
Tested-by: Rui Salvaterra <rsalvaterra@gmail.com>
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: 6.2+ <stable@kernel.org> # 6.2+
[ rjw: Renamed 2 funtions and 2 static variables, edited subject and
  changelog ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-04-11 18:12:19 +02:00
Daniel Lezcano
3d439b1a2a thermal/core: Alloc-copy-free the thermal zone parameters structure
The caller of the function thermal_zone_device_register_with_trips()
can pass a thermal_zone_params structure parameter.

This one is used by the thermal core code until the thermal zone is
destroyed. That forces the caller, so the driver, to keep the pointer
valid until it unregisters the thermal zone if we want to make the
thermal zone device structure private the core code.

As the thermal zone device structure would be private, the driver can
not access to thermal zone device structure to retrieve the tzp field
after it passed it to register the thermal zone.

So instead of forcing the users of the function to deal with the tzp
structure life cycle, make the usage easier by allocating our own
thermal zone params, copying the parameter content and by freeing at
unregister time. The user can then create the parameters on the stack,
pass it to the registering function and forget about it.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230404075138.2914680-3-daniel.lezcano@linaro.org
2023-04-07 18:36:28 +02:00
Daniel Lezcano
ac614a9b4c thermal/of: Unexport unused OF functions
The functions thermal_of_zone_register() and
thermal_of_zone_unregister() are no longer needed from the drivers as
the devm_ variant is always used.

Make them static in the C file and remove their declaration from thermal.h

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230404075138.2914680-2-daniel.lezcano@linaro.org
2023-04-07 18:36:28 +02:00
Daniel Lezcano
8454c8c09c thermal/drivers/bcm2835: Remove buggy call to thermal_of_zone_unregister
The driver is using the devm_thermal_of_zone_device_register().

In the error path of the function calling
devm_thermal_of_zone_device_register(), the function
devm_thermal_of_zone_unregister() should be called instead of
thermal_of_zone_unregister(), otherwise this one will be called twice
when the device is freed.

The same happens for the remove function where the devm_ guarantee the
thermal_of_zone_unregister() will be called, so adding this call in
the remove function will lead to a double free also.

Use devm_ variant in the error path of the probe function.

Remove thermal_of_zone_unregister() in the remove function.

Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230404075138.2914680-1-daniel.lezcano@linaro.org
2023-04-07 18:36:28 +02:00
Balsam CHIHI
561538f770 thermal/drivers/mediatek/lvts_thermal: Add AP domain for mt8195
Add MT8195 AP Domain support to LVTS Driver.

Take the opportunity to update the comments to show calibration data
information related to the new domain.

[dlezcano]: Massaged a bit the changelog

Signed-off-by: Balsam CHIHI <bchihi@baylibre.com>
Tested-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230307154524.118541-3-bchihi@baylibre.com
2023-04-07 11:18:28 +02:00
Ye Xingchen
46d6cbb820 thermal: amlogic: Use dev_err_probe()
Replace the open-code with dev_err_probe() to simplify the code.

Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/202303241020110014476@zte.com.cn
2023-04-07 11:18:28 +02:00
Chen-Yu Tsai
13f03bcd02 thermal/drivers/mediatek/lvts_thermal: Fix sensor 1 interrupt status bitmask
The binary representation for sensor 1 interrupt status was incorrectly
assembled, when compared to the full table given in the same comment
section. The conversion into hex was also incorrect, leading to
incorrect interrupt status bitmask for sensor 1. This would cause the
driver to incorrectly identify changes for sensor 1, when in fact it
was sensor 0, or a sensor access time out.

Fix the binary and hex representations in the comments, and the actual
bitmask macro.

Fixes: f5f633b182 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230328031017.1360976-1-wenst@chromium.org
2023-04-07 11:18:28 +02:00
Zhang Rui
ded2d383b1 thermal/core: Remove thermal_bind_params structure
Remove struct thermal_bind_params because no one is using it for thermal
binding now.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230330104526.3196-1-rui.zhang@intel.com
2023-04-07 11:18:22 +02:00
Mikko Perttunen
cdd6076b0a thermal/drivers/tegra-bpmp: Handle offline zones
Thermal zones located in power domains may not be accessible when
the domain is powergated. In this situation, reading the temperature
will return -BPMP_EFAULT. When evaluating trips, BPMP will internally
use -256C as the temperature for offline zones.

For smooth operation, for offline zones, return -EAGAIN when reading
the temperature and allow registration of zones even if they are
offline during probe.

Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
Acked-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230330094904.2589428-1-cyndis@kapsi.fi
2023-04-07 10:31:33 +02:00
Ye Xingchen
fee5caec88 thermal/drivers/rockchip: use devm_reset_control_array_get_exclusive()
Switch devm_reset_control_array_get() to
devm_reset_control_array_get_exclusive().

Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/202303241108553006227@zte.com.cn
2023-04-07 10:31:33 +02:00
Finley Xiao
45d7b3867a thermal/drivers/rockchip: Support RK3588 SoC in the thermal driver
The RK3588 SoC has seven temperature sensor ADC channels:

- Chip Center
- CPU Cluster 1 (Dual A76 "Big" Cores)
- CPU Cluster 2 (Dual A76 "Big" Cores)
- CPU Cluster 0 (Quad A55 "Little" Cores)
- Power Domain Center
- Graphics Processing Unit
- Neural Processing Unit

Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
[rebase, squash fixes]
Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230308112253.15659-7-sebastian.reichel@collabora.com
2023-04-07 10:31:33 +02:00
Sebastian Reichel
267f596585 thermal/drivers/rockchip: Support dynamic sized sensor array
Dynamically allocate the sensors array based on the amount
of platform sensors in preparation for rk3588 support, which
needs 7 sensors.

Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230308112253.15659-6-sebastian.reichel@collabora.com
2023-04-07 10:31:33 +02:00
Sebastian Reichel
f7cef1b743 thermal/drivers/rockchip: Simplify channel id logic
Replace the channel ID lookup table by a simple offset, since
the channel IDs are consecutive.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Link: https://lore.kernel.org/r/20230308112253.15659-5-sebastian.reichel@collabora.com
2023-04-07 10:31:33 +02:00
Sebastian Reichel
cb71c5f904 thermal/drivers/rockchip: Use dev_err_probe
Use dev_err_probe to simplify error printing in the driver's probe
routine.

Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230308112253.15659-4-sebastian.reichel@collabora.com
2023-04-07 10:31:32 +02:00
Sebastian Reichel
2f6916f12c thermal/drivers/rockchip: Simplify clock logic
By using devm_clk_get_enabled() the clock acquisition and
enabling can be done in one step with automatic error
handling.

Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230308112253.15659-3-sebastian.reichel@collabora.com
2023-04-07 10:31:32 +02:00
Sebastian Reichel
f1d2427cb4 thermal/drivers/rockchip: Simplify getting match data
It's possible to directly get the match data in a generic
way nowadays.

Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230308112253.15659-2-sebastian.reichel@collabora.com
2023-04-07 10:31:32 +02:00
Rafael J. Wysocki
75f74a9071 - Add more thermal zone device encapsulation: prevent setting
structure field directly, access the sensor device instead the
   thermal zone's device for trace, relocate the traces in
   drivers/thermal (Daniel Lezcano)
 
 - Use the generic trip point for the i.MX and remove the get_trip_temp
   ops (Daniel Lezcano)
 
 - Use the devm_platform_ioremap_resource() in the Hisilicon driver
   (Yang Li)
 
 - Remove R-Car H3 ES1.* handling as public has only access to the ES2
   version and the upstream support for the ES1 has been shutdown (Wolfram Sang)
 
 - Add a delay after initializing the bank in order to let the time to
   the hardware to initialze itself before reading the temperature
   (Amjad Ouled-Ameur)
 
 - Add MT8365 support (Amjad Ouled-Ameur)
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEGn3N4YVz0WNVyHskqDIjiipP6E8FAmQof0cACgkQqDIjiipP
 6E/tXQgArKKlM52mo3pg880JsiWOWGrS7pJN0x9MR0nqUm83sLTDf21fPoYmn+EJ
 wrzClIX1iHCDVCWCVxao7OIT1mxez9L2NAHseXDSDQJcZ0fflTE8wZ8xeLr6q5GN
 /ifHfCqiC98yejPcKIf2TqdGgqpCzyQ++sZoc3H6/jwysSkFlBc+YgKx+XasQR6k
 5swQ3E81zx0ouB+t1GDieXB6YRsjZzR2KQbbExoHexPue1DTIuuumz8M1Fgz4a4b
 gXRHbrGp3vmLORIAOZiVDyjzC7jwy7oN552g16yZLGDUdLaJ03gRRx7fvNzDUEMW
 mBzxak4WnNWEatCh691X6W5MdPO/uQ==
 =naJV
 -----END PGP SIGNATURE-----

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

Pull thermal control material for 6.4-rc1 from Daniel Lezcano:

"- Add more thermal zone device encapsulation: prevent setting
   structure field directly, access the sensor device instead the
   thermal zone's device for trace, relocate the traces in
   drivers/thermal (Daniel Lezcano)

 - Use the generic trip point for the i.MX and remove the get_trip_temp
   ops (Daniel Lezcano)

 - Use the devm_platform_ioremap_resource() in the Hisilicon driver
   (Yang Li)

 - Remove R-Car H3 ES1.* handling as public has only access to the ES2
   version and the upstream support for the ES1 has been shutdown (Wolfram
   Sang)

 - Add a delay after initializing the bank in order to let the time to
   the hardware to initialze itself before reading the temperature
   (Amjad Ouled-Ameur)

 - Add MT8365 support (Amjad Ouled-Ameur)"

* tag 'thermal-v6.4-rc1-1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/thermal/linux:
  thermal/drivers/ti: Use fixed update interval
  thermal/drivers/stm: Don't set no_hwmon to false
  thermal/drivers/db8500: Use driver dev instead of tz->device
  thermal/core: Relocate the traces definition in thermal directory
  thermal/drivers/hisi: Use devm_platform_ioremap_resource()
  thermal/drivers/imx: Use the thermal framework for the trip point
  thermal/drivers/imx: Remove get_trip_temp ops
  thermal/drivers/rcar_gen3_thermal: Remove R-Car H3 ES1.* handling
  thermal/drivers/mediatek: Add delay after thermal banks initialization
  thermal/drivers/mediatek: Add support for MT8365 SoC
  thermal/drivers/mediatek: Control buffer enablement tweaks
  dt-bindings: thermal: mediatek: Add binding documentation for MT8365 SoC
2023-04-03 20:43:32 +02:00
Rafael J. Wysocki
cd246fa969 thermal: core: Clean up thermal_list_lock locking
Once thermal_list_lock has been acquired in
__thermal_cooling_device_register(), it is not necessary to drop it
and take it again until all of the thermal zones have been updated,
so change the code accordingly.

No expected functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-04-03 20:40:21 +02:00
Daniel Lezcano
0c492be400 thermal/drivers/ti: Use fixed update interval
Currently the TI thermal driver sets the sensor update interval based
on the polling of the thermal zone. In order to get the polling rate,
the code inspects the thermal zone device structure internals, thus
breaking the self-encapsulation of the thermal framework core
framework.

On the other side, we see the common polling rates set in the device
tree for the platforms using this driver are 500 or 1000 ms.

Setting the polling rate to 250 ms would be far enough to cover the
combination we found in the device tree.

Instead of accessing the thermal zone device structure polling rate,
let's use a common update interval of 250 ms for the driver.

Cc: Keerthy <j-keerthy@ti.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Dhruva Gole <d-gole@ti.com>
Acked-by: Keerthy <j-keerthy@ti.com>
Link: https://lore.kernel.org/r/20230307133735.90772-7-daniel.lezcano@linaro.org
2023-04-01 20:51:45 +02:00
Daniel Lezcano
0fb6c6493f thermal/drivers/stm: Don't set no_hwmon to false
The thermal->tzp->no_hwmon parameter is only used when calling
thermal_zone_device_register().

Setting it to 'false' before calling thermal_add_hwmon_sysfs() has no
effect.

Remove the call and again prevent the drivers to access the thermal
internals.

Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230307133735.90772-6-daniel.lezcano@linaro.org
2023-04-01 20:51:45 +02:00
Daniel Lezcano
311526b7e3 thermal/drivers/db8500: Use driver dev instead of tz->device
The db8500 driver uses the thermal zone device instead of the device
attached to it. In order to prevent the drivers to access the thermal
zone device structure, replace the thermal zone device by the driver
to show the debug message.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20230307133735.90772-5-daniel.lezcano@linaro.org
2023-04-01 20:51:45 +02:00
Daniel Lezcano
32a7a02117 thermal/core: Relocate the traces definition in thermal directory
The traces are exported but only local to the thermal core code. On
the other side, the traces take the thermal zone device structure as
argument, thus they have to rely on the exported thermal.h header
file. As we want to move the structure to the private thermal core
header, first we have to relocate those traces to the same place as
many drivers do.

Cc: Steven Rostedt <rostedt@goodmis.org>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Link: https://lore.kernel.org/r/20230307133735.90772-2-daniel.lezcano@linaro.org
2023-04-01 20:51:45 +02:00
Yang Li
e45c9a2fc5 thermal/drivers/hisi: Use devm_platform_ioremap_resource()
According to commit 7945f929f1 ("drivers: provide
devm_platform_ioremap_resource()"), convert platform_get_resource(),
devm_ioremap_resource() to a single call to Use
devm_platform_ioremap_resource(), as this is exactly what this
function does.

Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230308062719.79522-1-yang.lee@linux.alibaba.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-04-01 20:51:45 +02:00
Daniel Lezcano
ed4b51b8fd thermal/drivers/imx: Use the thermal framework for the trip point
The thermal framework provides an API to get the trip related to a
trip point id. We want to consolidate the generic trip points code,
thus preventing the different drivers to deal with the trip points
after they registered them.

The set_trip_temp ops will be changed regarding the above changes but
first we need to rework a bit the different implementation in the
drivers.

The goal is to prevent using the trip id but use a trip point passed
as parameter which will contain all the needed information.

As we don't have the trip point passed as parameter yet, we get the
trip point using the generic trip thermal framewrok APIs and use it to
take exactly the same decisions.

The difference with this change and the previous code is from where we
get the thermal trip point (which is the same).

No functional change intended.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/20230309092821.1590586-2-daniel.lezcano@linaro.org
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-04-01 20:51:45 +02:00
Daniel Lezcano
53c9ce497d thermal/drivers/imx: Remove get_trip_temp ops
The i.MX thermal sensor uses the generic trip points. The thermal
framework can return the critical temperature directly.

Remove the pointless get_trip_temp ops.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/20230309092821.1590586-1-daniel.lezcano@linaro.org
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-04-01 20:51:45 +02:00
Wolfram Sang
3f2f689559 thermal/drivers/rcar_gen3_thermal: Remove R-Car H3 ES1.* handling
R-Car H3 ES1.* was only available to an internal development group and
needed a lot of quirks and workarounds. These become a maintenance
burden now, so our development group decided to remove upstream support
and disable booting for this SoC. Public users only have ES2 onwards.

Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Link: https://lore.kernel.org/r/20230307163041.3815-7-wsa+renesas@sang-engineering.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-04-01 20:51:45 +02:00
Amjad Ouled-Ameur
10debf8c2d thermal/drivers/mediatek: Add delay after thermal banks initialization
Thermal sensor reads performed immediately after thermal bank
initialization returns bogus values. This is currently tackled by returning
0 if the temperature is bogus (exceeding 200000).

Instead, add a delay between the bank init and the thermal zone device
register to properly fix this.

Signed-off-by: Michael Kao <michael.kao@mediatek.com>
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20221018-up-i350-thermal-bringup-v9-5-55a1ae14af74@baylibre.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-04-01 20:51:29 +02:00
Rafael J. Wysocki
d4d8516624 Merge back Intel thermal driver changes for 6.4-rc1. 2023-03-31 19:32:43 +02:00
Rafael J. Wysocki
0c7d069297 Merge back thermal control material for 6.4-rc1. 2023-03-31 19:31:56 +02:00
Rafael J. Wysocki
896c5150ed Merge branch 'thermal-intel-fixes'
Merge Intel thermal driver fixes for 6.3-rc5:

 - Fix handling of two recently added module parameters in the Intel
   powerclamp thermal driver (David Arcari).

 - Fix one more deadlock in the int340x thermal driver (Srinivas
   Pandruvada).

* thermal-intel-fixes:
  thermal: intel: powerclamp: Fix cpumask and max_idle module parameters
  thermal: intel: int340x: processor_thermal: Fix additional deadlock
2023-03-31 12:02:46 +02:00
David Arcari
ae817e618d thermal: intel: powerclamp: Fix cpumask and max_idle module parameters
When cpumask is specified as a module parameter the value is
overwritten by the module init routine.  This can easily be fixed
by checking to see if the mask has already been allocated in the
init routine.

When max_idle is specified as a module parameter a panic will occur.
The problem is that the idle_injection_cpu_mask is not allocated until
the module init routine executes. This can easily be fixed by allocating
the cpumask if it's not already allocated.

Fixes: ebf5197102 ("thermal: intel: powerclamp: Add two module parameters")
Signed-off-by: David Arcari <darcari@redhat.com>
Reviewed-by: Srinivas Pandruvada<srinivas.pandruvada@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-03-30 20:04:29 +02:00
Rob Herring
86df7d1908 thermal: Use of_property_present() for testing DT property presence
It is preferred to use typed property access functions (i.e.
of_property_read_<type> functions) rather than low-level
of_get_property/of_find_property functions for reading properties. As
part of this, convert of_get_property/of_find_property calls to the
recently added of_property_present() helper when we just want to test
for presence of a property and nothing more.

Signed-off-by: Rob Herring <robh@kernel.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-03-30 19:26:44 +02:00
Rafael J. Wysocki
d9dc06009b thermal: thermal_hwmon: Revert recent message adjustment
For the sake of consistency, revert the second part of the
thermal_hwmon.c hunk from commit dec07d399c ("thermal: Don't use
'device' internal thermal zone structure field") after the first
part of it has been reverted.

Link: https://lore.kernel.org/linux-pm/5b084360-898b-aad0-0b8e-33acc585d71d@linaro.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-03-29 20:40:10 +02:00
Srinivas Pandruvada
a57cc2dbb3 thermal: intel: int340x: processor_thermal: Fix additional deadlock
Commit 52f04f10b9 ("thermal: intel: int340x: processor_thermal: Fix
deadlock") addressed deadlock issue during user space trip update. But it
missed a case when thermal zone device is disabled when user writes 0.

Call to thermal_zone_device_disable() also causes deadlock as it also
tries to lock tz->lock, which is already claimed by trip_point_temp_store()
in the thermal core code.

Remove call to thermal_zone_device_disable() in the function
sys_set_trip_temp(), which is called from trip_point_temp_store().

Fixes: 52f04f10b9 ("thermal: intel: int340x: processor_thermal: Fix deadlock")
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: 6.2+ <stable@vger.kernel.org> # 6.2+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-03-29 20:36:35 +02:00
Zhang Rui
4eb7c2f3a3 thermal: thermal_hwmon: Fix a kernel NULL pointer dereference
When the hwmon device node of a thermal zone device is not found,
using hwmon->device causes a kernel NULL pointer dereference.

Fixes: dec07d399c ("thermal: Don't use 'device' internal thermal zone structure field")
Reported-by: Preble Adam C <adam.c.preble@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-03-29 18:07:14 +02:00
Rafael J. Wysocki
b57841fb0b thermal: core: Drop excessive lockdep_assert_held() calls
The lockdep_assert_held() calls added to cooling_device_stats_setup()
and cooling_device_stats_destroy() by commit 790930f442 ("thermal:
core: Introduce thermal_cooling_device_update()") trigger false-positive
lockdep reports in code paths that are not subject to race conditions
(before cooling device registration and after cooling device removal).

For this reason, remove the lockdep_assert_held() calls from both
cooling_device_stats_setup() and cooling_device_stats_destroy() and
add one to thermal_cooling_device_stats_reinit() that has to be called
under the cdev lock.

Fixes: 790930f442 ("thermal: core: Introduce thermal_cooling_device_update()")
Link: https://lore.kernel.org/linux-acpi/ZCIDTLFt27Ei7+V6@ideak-desk.fi.intel.com
Reported-by: Imre Deak <imre.deak@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-03-28 20:49:47 +02:00
Rafael J. Wysocki
85b52122e5 Merge branch 'thermal-intel'
Merge an x86_pkg_temp_thermal Intel thermal driver fix (Zhang Rui).

* thermal-intel:
  thermal: intel: x86_pkg_temp_thermal: Add lower bound check for sysfs input
2023-03-27 13:47:11 +02:00
Rafael J. Wysocki
ce07727aff Merge back thermal control material for 6.4-rc1. 2023-03-27 13:46:13 +02:00
Rafael J. Wysocki
6babf38d89 Merge branch 'thermal-acpi'
Merge a fix for a recent thermal-related regression in the ACPI
processor driver.

* thermal-acpi:
  ACPI: processor: thermal: Update CPU cooling devices on cpufreq policy changes
  thermal: core: Introduce thermal_cooling_device_update()
  thermal: core: Introduce thermal_cooling_device_present()
  ACPI: processor: Reorder acpi_processor_driver_init()
2023-03-24 17:11:27 +01:00
Ido Schimmel
f1b80a3878 thermal: core: Restore behavior regarding invalid trip points
Commit 7c3d5c20dc ("thermal/core: Add a generic thermal_zone_get_trip()
function") stopped marking trip points with a zero temperature as
disabled, behavior that was originally introduced in commit 81ad4276b5
("Thermal: Ignore invalid trip points").

When using the mlxsw driver we see that when such trip points are not
disabled, the thermal subsystem repeatedly tries to set the state of the
associated cooling devices to the maximum state.

Address this by restoring the original behavior and mark trip points
with a zero temperature as disabled.

Fixes: 7c3d5c20dc ("thermal/core: Add a generic thermal_zone_get_trip() function")
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-03-22 19:59:08 +01:00
Rafael J. Wysocki
790930f442 thermal: core: Introduce thermal_cooling_device_update()
Introduce a core thermal API function, thermal_cooling_device_update(),
for updating the max_state value for a cooling device and rearranging
its statistics in sysfs after a possible change of its ->get_max_state()
callback return value.

That callback is now invoked only once, during cooling device
registration, to populate the max_state field in the cooling device
object, so if its return value changes, it needs to be invoked again
and the new return value needs to be stored as max_state.  Moreover,
the statistics presented in sysfs need to be rearranged in general,
because there may not be enough room in them to store data for all
of the possible states (in the case when max_state grows).

The new function takes care of that (and some other minor things
related to it), but some extra locking and lockdep annotations are
added in several places too to protect against crashes in the cases
when the statistics are not present or when a stale max_state value
might be used by sysfs attributes.

Note that the actual user of the new function will be added separately.

Link: https://lore.kernel.org/linux-pm/53ec1f06f61c984100868926f282647e57ecfb2d.camel@intel.com/
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-03-22 15:20:38 +01:00
Rafael J. Wysocki
c43198af05 thermal: core: Introduce thermal_cooling_device_present()
Introduce a helper function, thermal_cooling_device_present(), for
checking if the given cooling device is in the list of registered
cooling devices to avoid some code duplication in a subsequent
patch.

No expected functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-03-22 15:20:38 +01:00