Commit graph

2376 commits

Author SHA1 Message Date
Niklas Söderlund
1c63f8cd01 thermal/drivers/rcar_gen3_thermal: Do not call set_trips() when resuming
There is no need to explicitly call set_trips() when resuming from
suspend. The thermal framework calls thermal_zone_device_update() that
restores the trip points.

Suggested-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Link: https://lore.kernel.org/r/20230208190333.3159879-2-niklas.soderlund+renesas@ragnatech.se
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-15 17:29:07 +01:00
Geert Uytterhoeven
883d155299 thermal/drivers/rcar_gen3: Add support for R-Car V4H
Add support for the Thermal Sensor/Chip Internal Voltage Monitor/Core
Voltage Monitor (THS/CIVM/CVM) on the Renesas R-Car V4H (R8A779G0) SoC.

According to the R-Car V4H Hardware User's Manual Rev. 0.70, the
(preliminary) conversion formula for the thermal sensor is the same as
for most other R-Car Gen3 and Gen4 SoCs, while the (preliminary)
conversion formula for the chip internal voltage monitor differs.
As the driver only uses the former, no further changes are needed.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Link: https://lore.kernel.org/r/852048eb5f4cc001be7a97744f4c5caea912d071.1675958665.git.geert+renesas@glider.be
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-15 17:28:58 +01:00
Balsam CHIHI
f5f633b182 thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver
The Low Voltage Thermal Sensor (LVTS) is a multiple sensors, multi
controllers contained in a thermal domain.

A thermal domains can be the MCU or the AP.

Each thermal domains contain up to seven controllers, each thermal
controller handle up to four thermal sensors.

The LVTS has two Finite State Machines (FSM), one to handle the
functionin temperatures range like hot or cold temperature and another
one to handle monitoring trip point. The FSM notifies via interrupts
when a trip point is crossed.

The interrupt is managed at the thermal controller level, so when an
interrupt occurs, the driver has to find out which sensor triggered
such an interrupt.

The sampling of the thermal can be filtered or immediate. For the
former, the LVTS measures several points and applies a low pass
filter.

Signed-off-by: Balsam CHIHI <bchihi@baylibre.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

On MT8195 Tomato Chromebook:

Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20230209105628.50294-5-bchihi@baylibre.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-15 17:28:42 +01:00
Balsam CHIHI
fad399ebdd thermal/drivers/mediatek: Relocate driver to mediatek folder
Add MediaTek proprietary folder to upstream more thermal zone and cooler
drivers, relocate the original thermal controller driver to it, and rename it
as "auxadc_thermal.c" to show its purpose more clearly.

Signed-off-by: Balsam CHIHI <bchihi@baylibre.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20230209105628.50294-2-bchihi@baylibre.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-15 17:28:25 +01:00
Rafael J. Wysocki
badf1f9050 Merge branch 'thermal-intel'
Merge thermal control changes related to Intel platforms for 6.3-rc1:

 - Rework ACPI helper functions for thermal control to retrieve a trip
   point temperature instead of initializing a trip point objetc (Rafael
   Wysocki).

 - Clean up and improve the int340x thermal driver ((Rafael Wysocki).

 - Simplify and clean up the intel_pch thermal driver ((Rafael Wysocki).

 - Fix the Intel powerclamp thermal driver and make it use the common
   idle injection framework (Srinivas Pandruvada).

 - Add two module parameters, cpumask and max_idle, to the Intel powerclamp
   thermal driver to allow it to affect only a specific subset of CPUs
   instead of all of them (Srinivas Pandruvada).

 - Make the Intel quark_dts thermal driver Use generic trip point
   objects instead of its own trip point representation (Daniel
   Lezcano).

 - Add toctree entry for thermal documents and fix two issues in the
   Intel powerclamp driver documentation (Bagas Sanjaya).

* thermal-intel: (25 commits)
  Documentation: powerclamp: Fix numbered lists formatting
  Documentation: powerclamp: Escape wildcard in cpumask description
  Documentation: admin-guide: Add toctree entry for thermal docs
  thermal: intel: powerclamp: Add two module parameters
  Documentation: admin-guide: Move intel_powerclamp documentation
  thermal: intel: powerclamp: Fix duration module parameter
  thermal: intel: powerclamp: Return last requested state as cur_state
  thermal: intel: quark_dts: Use generic trip points
  thermal: intel: powerclamp: Use powercap idle-inject feature
  powercap: idle_inject: Add update callback
  powercap: idle_inject: Export symbols
  thermal: intel: powerclamp: Fix cur_state for multi package system
  thermal: intel: intel_pch: Drop struct board_info
  thermal: intel: intel_pch: Rename board ID symbols
  thermal: intel: intel_pch: Fold suspend and resume routines into their callers
  thermal: intel: intel_pch: Fold two functions into their callers
  thermal: intel: intel_pch: Eliminate device operations object
  thermal: intel: intel_pch: Rename device operations callbacks
  thermal: intel: intel_pch: Eliminate redundant return pointers
  thermal: intel: intel_pch: Make pch_wpt_add_acpi_psv_trip() return int
  ...
2023-02-15 17:18:08 +01:00
Rafael J. Wysocki
c3bd6d539f Merge branch 'thermal-core'
Merge thermal control core changes for 6.3-rc1:

 - Clean up thermal device unregistration code (Viresh Kumar).

 - Fix and clean up thermal control core initialization error code
   paths (Daniel Lezcano).

 - Relocate the trip points handling code into a separate file (Daniel
   Lezcano).

 - Make the thermal core fail registration of thermal zones and cooling
   devices if the thermal class has not been registered (Rafael Wysocki).

 - Make the core thermal control code use sysfs_emit_at() instead of
   scnprintf() where applicable (ye xingchen).

* thermal-core:
  thermal: core: Use sysfs_emit_at() instead of scnprintf()
  thermal: Fail object registration if thermal class is not registered
  thermal/core: Move the thermal trip code to a dedicated file
  thermal/core: Remove unneeded ida_destroy()
  thermal/core: Fix unregistering netlink at thermal init time
  thermal: core: Use device_unregister() instead of device_del/put()
  thermal: core: Move cdev cleanup to thermal_release()
2023-02-15 17:08:30 +01:00
Srinivas Pandruvada
ebf5197102 thermal: intel: powerclamp: Add two module parameters
In some use cases, it is desirable to only inject idle on certain set
of CPUs. For example on Alder Lake systems, it is possible that we force
idle only on P-Cores for thermal reasons. Also the idle percent can be
more than 50% if we only choose partial set of CPUs in the system.

Introduce 2 new module parameters for this purpose. They can be only
changed when the cooling device is inactive.

cpumask (Read/Write): A bit mask of CPUs to inject idle. The format of
this bitmask is same as used in other subsystems like in
/proc/irq/*/smp_affinity. The mask is comma separated 32 bit groups.
Each CPU is one bit. For example for 256 CPU system the full mask is:
ffffffff,ffffffff,ffffffff,ffffffff,ffffffff,ffffffff,ffffffff,ffffffff
The rightmost mask is for CPU 0-32.

max_idle (Read/Write): Maximum injected idle time to the total CPU time
ratio in percent range from 1 to 100. Even if the cooling device max_state
is always 100 (100%), this parameter allows to add a max idle percent
limit. The default is 50, to match the current implementation of powerclamp
driver. Also doesn't allow value more than 75, if the cpumask includes
every CPU present in the system.

Also when the cpumask doesn't include every CPU, there is no use of
compensation using package C-state idle counters. Hence don't start
package C-state polling thread even for a single package or a single die
system in this case.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-09 21:01:06 +01:00
ye xingchen
5bbafd4362 thermal: core: Use sysfs_emit_at() instead of scnprintf()
Follow the advice in Documentation/filesystems/sysfs.rst that show()
should only use sysfs_emit() or sysfs_emit_at() when formatting the
value to be returned to user space.

Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-09 20:39:48 +01:00
Srinivas Pandruvada
966d0ab673 thermal: intel: powerclamp: Fix duration module parameter
After the switch to use the powercap/idle-inject framework in the Intel
powerclamp driver, the idle duration unit is microsecond.

However, the module parameter for idle duration is in milliseconds, so
convert it to microseconds in the "set" callback and back to milliseconds
in a new "get" callback.

While here, also use mutex protection for setting and getting "duration".

The other uses of "duration" are already protected by the mutex.

Fixes: 8526eb7fc7 ("thermal: intel: powerclamp: Use powercap idle-inject feature")
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-09 19:57:35 +01:00
Srinivas Pandruvada
6210849654 thermal: intel: powerclamp: Return last requested state as cur_state
When the user is reading cur_state from the thermal cooling device for
Intel powerclamp device:
 - It returns the idle ratio from Package C-state counters when
   there is active idle injection session.
 - -1, when there is no active idle injection session.

This information is not very useful as the package C-state counters vary
a lot from read to read. Instead just return the last requested cur_state.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-07 20:51:15 +01:00
Daniel Lezcano
72ffc28f2f thermal: intel: quark_dts: Use generic trip points
Make the intel_quark_dts_thermal driver register an array of generic
trip points along with the thermal zone and drop the trip points
thermal zone callbacks that are not used any more from it.

Signed-off-by: Daniel Lezcano <daniel.lezcano@kernel.org>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-03 14:49:26 +01:00
Srinivas Pandruvada
8526eb7fc7 thermal: intel: powerclamp: Use powercap idle-inject feature
There are two idle injection implementation in the Linux kernel. One
via intel_powerclamp and the other using powercap/idle_inject. Both
implementation end up in calling play_idle* function from a FIFO
priority thread. Both can't be used at the same time.

It is better to use one idle injection framework for better
maintainability. In this way, there is only one caller for play_idle.

Here powercap/idle_inject can be used for both per-core and for system
wide idle injection. This framework has a well defined interface which
allow registry for per-core or for all CPUs (system wide).

This reduces code complexity in the intel powerclamp driver as all the
per CPU kthreads, delayed work and calls to play_idle can be removed.

The changes include:
 - Remove unneeded include files
 - Remove per CPU kthread workers: balancing_work and idle_injection_work.
 - Reuse the compensation related code by moving from previous worker
   thread to idle_injection callback.
 - Adjust the idle_duration and runtime by using powercap/idle_inject
   interface.
 - Remove all variables, which are not required once powercap/idle_inject
   is used.
 - Add mutex to avoid race during removal of idle injection during module
   unload and user action to change idle inject percent. Also for
   protection during dynamic adjustment of run and idle time from
   update() callback.
 - Remove online/offline callbacks to designate control CPU
 - Use cpu_present_mask global variable for CPU mask
 - Remove hot plug locks

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-03 14:48:34 +01:00
Srinivas Pandruvada
8e47363588 thermal: intel: powerclamp: Fix cur_state for multi package system
The powerclamp cooling device cur_state shows actual idle observed by
package C-state idle counters. But the implementation is not sufficient
for multi package or multi die system. The cur_state value is incorrect.
On these systems, these counters must be read from each package/die and
somehow aggregate them. But there is no good method for aggregation.

It was not a problem when explicit CPU model addition was required to
enable intel powerclamp. In this way certain CPU models could have
been avoided. But with the removal of CPU model check with the
availability of Package C-state counters, the driver is loaded on most
of the recent systems.

For multi package/die systems, just show the actual target idle state,
the system is trying to achieve. In powerclamp this is the user set
state minus one.

Also there is no use of starting a worker thread for polling package
C-state counters and applying any compensation for multiple package
or multiple die systems.

Fixes: b721ca0d19 ("thermal/powerclamp: remove cpu whitelist")
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: 4.14+ <stable@vger.kernel.org> # 4.14+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-02-02 21:08:32 +01:00
Rafael J. Wysocki
2153a87ff9 thermal: intel: intel_pch: Drop struct board_info
Because the only member of struct board_info is the name, the
board_info[] array of struct board_info elements can be replaced with
an array of strings.

Modify the code accordingly and drop struct board_info.

No intentional functional impact.

Suggested-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 21:06:24 +01:00
Rafael J. Wysocki
ae98e57a6e thermal: intel: intel_pch: Rename board ID symbols
Use capitals in the names of the board ID symbols and add the PCH_
prefix to each of them for consistency.

Also rename the board_ids enum accordingly.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 21:06:15 +01:00
Rafael J. Wysocki
c5f43242f4 thermal: intel: intel_pch: Fold suspend and resume routines into their callers
Fold pch_suspend() and pch_resume(), that each have only one caller,
into their respective callers to make the code somewhat easier to
follow.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 21:06:09 +01:00
Rafael J. Wysocki
35c87f948d thermal: intel: intel_pch: Fold two functions into their callers
Fold two functions, pch_hw_init() and pch_get_temp(), that each have
only one caller, into their respective callers to make the code somewhat
easier to follow.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 21:04:01 +01:00
Rafael J. Wysocki
86cb1004b6 thermal: intel: intel_pch: Eliminate device operations object
The same device operations object is pointed to by all of the board
configurations in the driver, so effectively the same operations
callbacks are used by all of them which only adds overhead (that can
be significant due to retpolines) for no real purpose.

For this reason, drop the device operations object and replace the
respective callback invocations by direct calls to the specific
functions that were previously pointed to by callback pointers.

No intentional change in behavior.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 15:40:39 +01:00
Rafael J. Wysocki
1aa4f925d8 thermal: intel: intel_pch: Rename device operations callbacks
Because the same device operations callbacks are used for all supported
boards, they are in fact generic, so rename them to reflect that.

Also rename the operations object itself for consistency.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 15:40:39 +01:00
Rafael J. Wysocki
558718f4d3 thermal: intel: intel_pch: Eliminate redundant return pointers
Both pch_wpt_init() and pch_wpt_get_temp() can return the proper
result via their return values, so they do not need to use return
pointers.

Modify them accordingly.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 15:40:39 +01:00
Rafael J. Wysocki
2cee73568e thermal: intel: intel_pch: Make pch_wpt_add_acpi_psv_trip() return int
Modify pch_wpt_add_acpi_psv_trip() to return an int value instead of
using a return pointer for that.

While at it, drop an excessive empty code line.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 15:40:39 +01:00
Rafael J. Wysocki
1bcebcab88 thermal: intel: int340x: Improve int340x_thermal_set_trip_temp()
Instead of using snprintf() to populate the ACPI object name in
int340x_thermal_set_trip_temp(), use an appropriate initializer
and make the function fail if its trip argument is greater than 9,
because ACPI object names can only be 4 characters long and it does
not make sense to even try to evaluate objects with longer names (that
argument is guaranteed to be non-negative, because it comes from the
thermal code that will not pass negative trip numbers to zone
callbacks).

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 15:31:04 +01:00
Rafael J. Wysocki
d0009d14e9 thermal: intel: int340x: Drop pointless cast to unsigned long
The explicit casting from int to unsigned long in
int340x_thermal_get_zone_temp() is pointless, becuase the multiplication
result is cast back to int by the assignment in the same statement, so
drop it.

No expected functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 15:31:04 +01:00
Rafael J. Wysocki
67c6945867 thermal: intel: int340x: Rename variable in int340x_thermal_zone_add()
Rename local variables int34x_thermal_zone in int340x_thermal_zone_add()
and int340x_thermal_zone_remove() to int34x_zone which allows a number
of code lines to be shorter and easier to read and adjust some white
space for consistency.

No intentional 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-02-02 15:31:04 +01:00
Rafael J. Wysocki
be014c789c thermal: intel: int340x: Assorted minor cleanups
Improve some inconsistent usage of white space in int340x_thermal_zone.c,
fix up one coding style issue in it (missing braces around an else
branch of a conditional) and while at it replace a !ACPI_FAILURE()
check with an equivalent ACPI_SUCCESS() one.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
2023-02-02 15:31:04 +01:00
Rafael J. Wysocki
dd3b3d160e thermal: ACPI: Make helpers retrieve temperature only
It is slightly better to make the ACPI thermal helper functions retrieve
the trip point temperature only instead of doing the full trip point
initialization, because they are also used for updating some already
registered trip points, in which case initializing a new trip just
in order to update the temperature of an existing one is somewhat
wasteful.

Modify the ACPI thermal helpers accordingly and update their users.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-02-02 15:26:45 +01:00
Rafael J. Wysocki
f364beb5b6 Merge branch 'thermal-intel'
Merge changes affecting thermal control on Intel platforms for 6.3-rc1:

 - Consolidate code accessing the Intel TCC (Thermal Control Circuitry)
   MSRs by introducing library functions for that and making the
   TCC-related code in thermal drivers use them (Zhang Rui).

 - Enhance the x86_pkg_temp_thermal driver to support dynamic tjmax
   changes (Zhang Rui).

 - Address an "unsigned expression compared with zero" warning in the
   intel_soc_dts_iosf thermal driver (Yang Li).

 - Update comments regarding two functions in the Intel Menlow thermal
   driver (Deming Wang).

 - Use sysfs_emit_at() instead of scnprintf() in the int340x thermal
   driver (ye xingchen).

 - Make the intel_pch thermal driver support the Wellsburg PCH (Tim
   Zimmermann).

 - Add trip point initialization helper functions for ACPI-defined trip
   points and modify two thermal drivers to use them (Rafael Wysocki,
   Daniel Lezcano).

 - Modify the intel_pch and processor_thermal_device_pci thermal drivers
   use generic trip point tables instead of thermal zone trip point
   callbacks (Daniel Lezcano).

 - Add production mode attribute sysfs attribute to the int340x thermal
   driver (Srinivas Pandruvada).

 - Rework dynamic trip point updates handling and locking in the int340x
   thermal driver (Rafael Wysocki).

 - Make the int340x thermal driver use a generic trip points table
   instead of thermal zone trip point callbacks (Rafael Wysocki, Daniel
   Lezcano).

* thermal-intel:
  thermal: intel: int340x: Use generic trip points table
  thermal: intel: int340x: Use zone lock for synchronization
  thermal: intel: int340x: Rework updating trip points
  thermal: ACPI: Initialize trips if temperature is out of range
  thermal: intel: processor_thermal_device_pci: Use generic trip point
  thermal: intel: int340x: Add production mode attribute
  thermal: intel: intel_pch: Use generic trip points
  thermal: ACPI: Add ACPI trip point routines
  thermal: intel: intel_pch: Add support for Wellsburg PCH
  thermal: int340x_thermal: Use sysfs_emit_at() instead of scnprintf()
  thermal: intel: menlow: Update function descriptions
  thermal: intel: Fix unsigned comparison with less than zero
  thermal/x86_pkg_temp_thermal: Add support for handling dynamic tjmax
  thermal/x86_pkg_temp_thermal: Use Intel TCC library
  thermal/intel/intel_tcc_cooling: Use Intel TCC library
  thermal/intel/intel_soc_dts_iosf: Use Intel TCC library
  thermal/int340x/processor_thermal: Use Intel TCC library
  thermal/intel: Introduce Intel TCC library
2023-01-30 14:13:26 +01:00
Rafael J. Wysocki
79b2027097 Merge back thermal control material for 6.3. 2023-01-27 15:55:23 +01:00
Rafael J. Wysocki
f4118dbe61 thermal: intel: int340x: Use generic trip points table
Modify int340x_thermal_zone_add() to register the thermal zone along
with a trip points table, which allows the trip-related zone callbacks
to be dropped, because they are not needed any more.

In order to consolidate the code, use ACPI trip library functions to
populate generic trip points in int340x_thermal_read_trips() and to
update them in int340x_thermal_update_trips().

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Co-developed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-27 15:11:12 +01:00
Rafael J. Wysocki
9e9b7e182c thermal: intel: int340x: Use zone lock for synchronization
Because the ->get_trip_temp() and ->get_trip_type() thermal zone
callbacks are only invoked from __thermal_zone_get_trip() which is
always called by the thermal core under the zone lock, it is sufficient
for int340x_thermal_update_trips() to acquire the zone lock for mutual
exclusion with those callbacks.

Accordingly, modify int340x_thermal_update_trips() to use the zone lock
instead of the internal trip_mutex and drop the latter which is not
necessary any more.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-27 15:11:12 +01:00
Rafael J. Wysocki
b1bf9dbffc thermal: intel: int340x: Rework updating trip points
It is generally invalid to change the trip point indices after they have
been exposed via sysfs.

Moreover, the thermal objects in the ACPI namespace cannot go away and
appear on the fly.  In practice, the only thing that can happen when the
INT3403_PERF_TRIP_POINT_CHANGED notification is sent by the platform
firmware is a change of the return values of those thermal objects.

For this reason, add a special function for updating the trip point
temperatures after re-evaluating the respective ACPI thermal objects
and change int3403_notify() to invoke it instead of
int340x_thermal_read_trips() that would change the trip point indices
on errors.  Also remove the locking from the latter, because it is only
called before registering the thermal zone and it cannot race with the
zone's callbacks.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-27 15:11:12 +01:00
Rafael J. Wysocki
97efecfdbf thermal: ACPI: Initialize trips if temperature is out of range
In some cases it is still useful to register a trip point if the
temperature returned by the corresponding ACPI thermal object (for
example, _HOT) is invalid to start with, because the same ACPI
thermal object may start to return a valid temperature after a
system configuration change (for example, from an AC power source
to battery an vice versa).

For this reason, if the ACPI thermal object evaluated by
thermal_acpi_trip_init() successfully returns a temperature value that
is out of the range of values taken into account, initialize the trip
point using THERMAL_TEMP_INVALID as the temperature value instead of
returning an error to allow the user of the trip point to decide what
to do with it.

Also update pch_wpt_add_acpi_psv_trip() to reject trip points with
invalid temperature values.

Fixes: 7a0e397488 ("thermal: ACPI: Add ACPI trip point routines")
Reported-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-27 15:09:47 +01:00
Rafael J. Wysocki
a5c926acd0 Merge back Intel thermal control changes for 6.3. 2023-01-27 15:08:08 +01:00
Rafael J. Wysocki
02be605946 - Fix kerneldoc format errors for Rockchip, Mediatek and Uniphier
(Randy Dunlap)
 
 - Add the missing 'qcom,adc-tm7' compatible string in the dt-bindings
   (Krzysztof Kozlowski)
 
 - Improve the calibration routine by relying on the nvmem to read the
   values and provide a set of fixes for the QCom tsens driver (Dmitry
   Baryshkov)
 
 - Remove the duplicate interrupt setting routine in the QCom tsens
   driver (Daniel Lezcano)
 
 - Fix a wrong loop condition in the i.MX SC thermal driver and add the
   iMX8QM sensors (Viorel Suman)
 
 - Fix header inclusion asm-generic.h by asm.h for the
   qcom-spmi-adc-tm5 driver (Andy Shevchenko)
 
 - Use the devm_platform_get_and_ioremap_resource() combo function in
   all the drivers where the conversion applies (Ye Xingchen)
 
 - Replace a literal mask by an existing corresponding macro (Yangtao
   Li)
 
 - Add support for MT7986 and MT7981 (Daniel Golle)
 
 - Use thermal_zone_get_crit_temp() for the Armada thermal driver
   (Daniel Lezcano)
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEGn3N4YVz0WNVyHskqDIjiipP6E8FAmPSo/wACgkQqDIjiipP
 6E8jPAf/dSGd92V/BEbPDNL3OvhW7duX1g05HLwnjSLo4r2W/I+YFsmLkaJ81iPj
 E/gC29jHw6TAQN9DrEMRnjmHGH8SBPrphfZMM7Sbh3pgzTPGW5tXQln8ysbh+JUr
 0Aj4O6sA5mvcjd7r7u5JITGUHzZCm3L4Gv9bzr6O8M425u3di1PlI8XMsdaKBy5q
 N4zYR8yFCgbgM3ujjy/J4fYWRRTcYQ9kExa/OxvMDtZS4shBK34VN9IVt3z/W+Vs
 zNxKRynUZcVYddEZwYcBV+aTVAyFGLr5s5y6dzPo33h4M+Rl6reNE86el28fglu0
 diZK79mef3KtV8Dn6lw9r+Fd/6heHw==
 =ZJEq
 -----END PGP SIGNATURE-----

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

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

"- Fix kerneldoc format errors for Rockchip, Mediatek and Uniphier
   (Randy Dunlap)

 - Add the missing 'qcom,adc-tm7' compatible string in the dt-bindings
   (Krzysztof Kozlowski)

 - Improve the calibration routine by relying on the nvmem to read the
   values and provide a set of fixes for the QCom tsens driver (Dmitry
   Baryshkov)

 - Remove the duplicate interrupt setting routine in the QCom tsens
   driver (Daniel Lezcano)

 - Fix a wrong loop condition in the i.MX SC thermal driver and add the
   iMX8QM sensors (Viorel Suman)

 - Fix header inclusion asm-generic.h by asm.h for the
   qcom-spmi-adc-tm5 driver (Andy Shevchenko)

 - Use the devm_platform_get_and_ioremap_resource() combo function in
   all the drivers where the conversion applies (Ye Xingchen)

 - Replace a literal mask by an existing corresponding macro (Yangtao
   Li)

 - Add support for MT7986 and MT7981 (Daniel Golle)

 - Use thermal_zone_get_crit_temp() for the Armada thermal driver
   (Daniel Lezcano)"

* tag 'thermal-v6.3-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/thermal/linux: (35 commits)
  thermal/drivers/armada: Use the thermal_zone_get_crit_temp()
  thermal/drivers/mtk: Add support for MT7986 and MT7981
  thermal/drivers/mtk: Use function pointer for raw_to_mcelsius
  thermal/drivers/sun8i: Convert to use macro
  thermal/drivers/spear: Use devm_platform_get_and_ioremap_resource()
  thermal/drivers/kirkwood: Use devm_platform_get_and_ioremap_resource()
  thermal/drivers/thermal_mmio: Use devm_platform_get_and_ioremap_resource()
  thermal/drivers/rockchip: Use devm_platform_get_and_ioremap_resource()
  thermal/drivers/mtk_thermal: Use devm_platform_get_and_ioremap_resource()
  thermal/drivers/armada: Use devm_platform_get_and_ioremap_resource()
  thermal/drivers/dove: Use devm_platform_get_and_ioremap_resource()
  thermal/drivers/bcm2835: Use devm_platform_get_and_ioremap_resource()
  thermal/drivers/brcmstb_thermal: Use devm_platform_get_and_ioremap_resource()
  thermal/drivers/qcom-spmi-adc-tm5: Use asm intead of asm-generic
  thermal/drivers/imx_sc_thermal: Add iMX8QM sensors
  thermal/drivers/imx_sc_thermal: Fix the loop condition
  thermal/drivers/qcom: Remove duplicate set next trip point interrupt code
  thermal/drivers/tsens: Drop single-cell code for msm8976/msm8956
  thermal/drivers/tsens: Drop single-cell code for msm8939
  thermal/drivers/tsens: Drop single-cell code for mdm9607
  ...
2023-01-26 17:21:24 +01:00
Daniel Lezcano
e90eb1df70 thermal: intel: processor_thermal_device_pci: Use generic trip point
Make proc_thermal_pci_probe() register the TCPU_PCI thermal zone along
with the trip point used by it and drop the zone callbacks related to
this trip point that are not needed any more.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-26 16:17:28 +01:00
Srinivas Pandruvada
5c36cf2784 thermal: intel: int340x: Add production mode attribute
It is possible that the system manufacturer locks down thermal tuning
beyond what is usually done on the given platform. In that case user
space calibration tools should not try to adjust the thermal
configuration of the system.

To allow user space to check if that is the case, add a new sysfs
attribute "production_mode" that will be present when the ACPI DCFG
method is present under the INT3400 device object in the ACPI Namespace.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-26 14:47:16 +01:00
Rafael J. Wysocki
9e0a9be24b thermal: Fail object registration if thermal class is not registered
If thermal_class is not registered with the driver core, there is no way
to expose the interfaces used by the thermal control framework, so
prevent thermal zones and cooling devices from being registered in
that case by returning an error from object registration functions.

For this purpose, use a thermal_class pointer that will be NULL if the
class is not registered.  To avoid wasting memory in that case, allocate
the thermal class object dynamically and if it fails to register, free
it and clear the thermal_class pointer to NULL.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-01-25 16:51:19 +01:00
Daniel Lezcano
5b8de18ee9 thermal/core: Move the thermal trip code to a dedicated file
The thermal_core.c files contains a lot of functions handling
different thermal components like the governors, the trip points, the
cooling device, the OF cooling device, etc ...

This organization does not help to migrate to a more sane code where
there is a better self-encapsulation as all the components' internals
can be directly accessed from a single file.

For the sake of clarity, let's move the thermal trip points code in a
dedicated thermal_trip.c file and add a function to browse all the
trip points like we do with the thermal zones, the govenors and the
cooling devices.

The same can be done for the cooling devices and the governor code but
that will come later as the current work in the thermal framework is
to fix the trip point handling and use a generic trip point structure.

No functional changes intended.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-25 16:40:39 +01:00
Daniel Lezcano
b57d62862d thermal/core: Remove unneeded ida_destroy()
As per documentation for the ida_destroy() function: "If the IDA is
already empty, there is no need to call this function."

The thermal framework is in the init sequence, so the ida was not yet
used and consequently it is empty in case of error.

There is no need to call ida_destroy(), let's remove the calls.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-25 16:40:39 +01:00
Daniel Lezcano
58d1c9fd0e thermal/core: Fix unregistering netlink at thermal init time
The thermal subsystem initialization miss an netlink unregistering
function in the error. Add it.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-25 16:40:39 +01:00
Rafael J. Wysocki
acd7e9ee57 thermal: intel: int340x: Add locking to int340x_thermal_get_trip_type()
In order to prevent int340x_thermal_get_trip_type() from possibly
racing with int340x_thermal_read_trips() invoked by int3403_notify()
add locking to it in analogy with int340x_thermal_get_trip_temp().

Fixes: 6757a7abe4 ("thermal: intel: int340x: Protect trip temperature from concurrent updates")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-25 15:37:21 +01:00
Srinivas Pandruvada
6757a7abe4 thermal: intel: int340x: Protect trip temperature from concurrent updates
Trip temperatures are read using ACPI methods and stored in the memory
during zone initializtion and when the firmware sends a notification for
change. This trip temperature is returned when the thermal core calls via
callback get_trip_temp().

But it is possible that while updating the memory copy of the trips when
the firmware sends a notification for change, thermal core is reading the
trip temperature via the callback get_trip_temp(). This may return invalid
trip temperature.

To address this add a mutex to protect the invalid temperature reads in
the callback get_trip_temp() and int340x_thermal_read_trips().

Fixes: 5fbf7f27fa ("Thermal/int340x: Add common thermal zone handler")
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: 5.0+ <stable@vger.kernel.org> # 5.0+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-24 21:28:19 +01:00
Daniel Lezcano
fee19c6921 thermal: intel: intel_pch: Use generic trip points
The thermal framework gives the possibility to register the trip
points along with the thermal zone.  When that is done, no get_trip_*
callbacks are needed and they can be removed.

Convert the existing callbacks content logic into generic trip points
initialization code and register them along with the thermal zone.

In order to consolidate the code, use an ACPI trip library function
to populate a generic trip point.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
[ rjw: Subject and changelog edits, rebase ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
2023-01-24 21:13:42 +01:00
Rafael J. Wysocki
7a0e397488 thermal: ACPI: Add ACPI trip point routines
Add library routines to populate a generic thermal trip point
structure with data obtained by evaluating a specific object in the
ACPI Namespace.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Co-developed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
2023-01-24 21:13:42 +01:00
Tim Zimmermann
40dc192908 thermal: intel: intel_pch: Add support for Wellsburg PCH
Add the PCI ID for the Wellsburg C610 series chipset PCH.

The driver can read the temperature from the Wellsburg PCH with only
the PCI ID added and no other modifications.

Signed-off-by: Tim Zimmermann <tim@linux4.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-24 21:13:25 +01:00
Rafael J. Wysocki
8ef0ca4a17 Merge back other thermal control material for 6.3.
* thermal: (734 commits)
  thermal: core: call put_device() only after device_register() fails
  Linux 6.2-rc4
  kbuild: Fix CFI hash randomization with KASAN
  firmware: coreboot: Check size of table entry and use flex-array
  kallsyms: Fix scheduling with interrupts disabled in self-test
  ata: pata_cs5535: Don't build on UML
  lockref: stop doing cpu_relax in the cmpxchg loop
  x86/pci: Treat EfiMemoryMappedIO as reservation of ECAM space
  efi: tpm: Avoid READ_ONCE() for accessing the event log
  io_uring: lock overflowing for IOPOLL
  ALSA: pcm: Move rwsem lock inside snd_ctl_elem_read to prevent UAF
  iommu/mediatek-v1: Fix an error handling path in mtk_iommu_v1_probe()
  iommu/iova: Fix alloc iova overflows issue
  iommu: Fix refcount leak in iommu_device_claim_dma_owner
  iommu/arm-smmu-v3: Don't unregister on shutdown
  iommu/arm-smmu: Don't unregister on shutdown
  iommu/arm-smmu: Report IOMMU_CAP_CACHE_COHERENCY even betterer
  platform/x86: thinkpad_acpi: Fix profile mode display in AMT mode
  ALSA: usb-audio: Fix possible NULL pointer dereference in snd_usb_pcm_has_fixed_rate()
  platform/x86: int3472/discrete: Ensure the clk/power enable pins are in output mode
  ...
2023-01-24 21:12:49 +01:00
Viresh Kumar
47e3f00074 thermal: core: Use device_unregister() instead of device_del/put()
Lets not open code device_unregister() unnecessarily.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-24 20:22:55 +01:00
Viresh Kumar
e398421fd0 thermal: core: Move cdev cleanup to thermal_release()
thermal_release() already frees cdev, let it do rest of the cleanup as
well in order to simplify the error paths in
__thermal_cooling_device_register().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2023-01-24 20:21:49 +01:00
Daniel Lezcano
8c5ee9155f thermal/drivers/armada: Use the thermal_zone_get_crit_temp()
The driver browses the trip point to find out the critical trip
temperature. However the function thermal_zone_get_crit_temp() does
already that, so the routine is pointless in the driver.

Use thermal_zone_get_crit_temp() instead of inspecting all the trip
points.

In addition, the hysteresis value is set to zero. A critical trip
point does not have a hysteresis.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20230118222610.186088-1-daniel.lezcano@linaro.org
2023-01-24 12:37:56 +01:00
Daniel Golle
248da1fc84 thermal/drivers/mtk: Add support for MT7986 and MT7981
Add support for V3 generation thermal found in MT7986 and MT7981 SoCs.
Brings code to assign values from efuse as well as new function to
convert raw temperature to millidegree celsius, as found in MediaTek's
SDK sources (but cleaned up and de-duplicated)

[1]: baf36c7eef

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/2d341fc45266217249586eb4bd3be3ac4ca83a12.1674055882.git.daniel@makrotopia.org
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2023-01-24 11:44:01 +01:00