Commit f73cd9c9 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull thermal control updates from Rafael Wysocki:
 "These extend the thermal trip point crossing notifications sent via
  netlink to contain the temperature causing the trip point to be
  crossed, deprecate the user space thermal governor, add new DT
  bindings to drivers, move ABI documentation to Documentation/ABI, fix
  assorted issues and clean up code.

  Specifics:

   - Constify a variable in thermal MMIO driver (Rikard Falkeborn).

   - Add the current temperature in the netlink message when crossing a
     trip point in order to prevent useless back and forth reading from
     userspace (Daniel Lezcano).

   - Add support for the 'HC' variant on PM8998 PMIC in order to support
     VADC channels on recent QCom boards (Bjorn Andersson).

   - Add support for calibration values from hardware when they are
     fused (Niklas Söderlund).

   - Fix NULL pointer dereference in the thermal_release callback when
     an error occurs in the thermal_zone_device_register() (Yuanzheng
     Song).

   - Fix use-after-free in __thermal_cooling_device_register() in the
     error path (Ziyang Xuan).

   - Fix compilation of the LMh driver when CONFIG_QCOM_SCM is not set
     (Jackie Liu).

   - Add timeout when reading a register that can block forever in
     certain circumstances in the tsens driver (Ansuel Smith).

   - Add DT binding for the reset lines and use them in the rockchip
     sensor driver (Johan Jonker).

   - Add new uniphier NX1 SoC temperature sensor (Kunihiko Hayashi).

   - Save and restore the TCC value in the int340x driver (Antoine
     Tenart).

   - Deprecate the writability of the cooling device state sysfs file
     and the user space governor (Daniel Lezcano).

   - Delete bogus length check in int340x (Dan Carpenter).

   - Use bitmap_zalloc/bitmap_free when applicable in intel_powerclamp
     (Christophe JAILLET).

   - Move thermal ABI documentation to Documentation/ABI (Mauro Carvalho
     Chehab)"

* tag 'thermal-5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (21 commits)
  thermal/core: Deprecate changing cooling device state from userspace
  thermal/core: Make the userspace governor deprecated
  thermal/drivers/int340x: Improve the tcc offset saving for suspend/resume
  thermal/drivers/uniphier: Add compatible string for NX1 SoC
  dt-bindings: thermal: uniphier: Add binding for NX1 SoC
  thermal/drivers/rockchip_thermal: Allow more resets for tsadc node
  dt-bindings: thermal: remove redundant comments from rockchip-thermal.yaml
  dt-bindings: thermal: allow more resets for tsadc node in rockchip-thermal.yaml
  thermal/drivers/tsens: Add timeout to get_temp_tsens_valid
  thermal/drivers/qcom/lmh: make QCOM_LMH depends on QCOM_SCM
  thermal/core: fix a UAF bug in __thermal_cooling_device_register()
  thermal/core: Fix null pointer dereference in thermal_release()
  thermal: rcar_gen3_thermal: Read calibration from hardware
  thermal: rcar_gen3_thermal: Store thcode and ptat in priv data
  thermal/drivers/qcom/spmi-adc-tm5: Add support for HC variant
  dt-bindings: thermal: qcom: add HC variant of adc-thermal monitor bindings
  thermal: Move ABI documentation to Documentation/ABI
  thermal/drivers/netlink: Add the temperature when crossing a trip point
  thermal/drivers/thermal_mmio: Constify static struct thermal_mmio_ops
  thermal: int340x: delete bogus length check
  ...
parents 833db721 46e9f92f
Loading
Loading
Loading
Loading
+259 −0
Original line number Diff line number Diff line
What:		/sys/class/thermal/thermal_zoneX/type
Description:
		Strings which represent the thermal zone type.
		This is given by thermal zone driver as part of registration.
		E.g: "acpitz" indicates it's an ACPI thermal device.
		In order to keep it consistent with hwmon sys attribute; this
		shouldbe a short, lowercase string, not containing spaces nor
		dashes.

		RO, Required

What:		/sys/class/thermal/thermal_zoneX/temp
Description:
		Current temperature as reported by thermal zone (sensor).

		Unit: millidegree Celsius

		RO, Required

What:		/sys/class/thermal/thermal_zoneX/mode
Description:
		One of the predefined values in [enabled, disabled].
		This file gives information about the algorithm that is
		currently managing the thermal zone. It can be either default
		kernel based algorithm or user space application.

		enabled
				enable Kernel Thermal management.
		disabled
				Preventing kernel thermal zone driver actions upon
				trip points so that user application can take full
				charge of the thermal management.

		RW, Optional

What:		/sys/class/thermal/thermal_zoneX/policy
Description:
		One of the various thermal governors used for a particular zone.

		RW, Required

What:		/sys/class/thermal/thermal_zoneX/available_policies
Description:
		Available thermal governors which can be used for a
		particular zone.

		RO, Required

What:		/sys/class/thermal/thermal_zoneX/trip_point_Y_temp
Description:
		The temperature above which trip point will be fired.

		Unit: millidegree Celsius

		RO, Optional

What:		/sys/class/thermal/thermal_zoneX/trip_point_Y_type
Description:
		Strings which indicate the type of the trip point.

		E.g. it can be one of critical, hot, passive, `active[0-*]`
		for ACPI thermal zone.

		RO, Optional

What:		/sys/class/thermal/thermal_zoneX/trip_point_Y_hyst
Description:
		The hysteresis value for a trip point, represented as an
		integer.

		Unit: Celsius

		RW, Optional

What:		/sys/class/thermal/thermal_zoneX/cdevY
Description:
	Sysfs link to the thermal cooling device node where the sys I/F
	for cooling device throttling control represents.

	RO, Optional

What:		/sys/class/thermal/thermal_zoneX/cdevY_trip_point
Description:
		The trip point in this thermal zone which `cdev[0-*]` is
		associated with; -1 means the cooling device is not
		associated with any trip point.

		RO, Optional

What:		/sys/class/thermal/thermal_zoneX/cdevY_weight
Description:
		The influence of `cdev[0-*]` in this thermal zone. This value
		is relative to the rest of cooling devices in the thermal
		zone. For example, if a cooling device has a weight double
		than that of other, it's twice as effective in cooling the
		thermal zone.

		RW, Optional

What:		/sys/class/thermal/thermal_zoneX/emul_temp
Description:
		Interface to set the emulated temperature method in thermal zone
		(sensor). After setting this temperature, the thermal zone may
		pass this temperature to platform emulation function if
		registered or cache it locally. This is useful in debugging
		different temperature threshold and its associated cooling
		action. This is write only node and writing 0 on this node
		should disable emulation.

		Unit: millidegree Celsius

		WO, Optional

		WARNING:
		    Be careful while enabling this option on production systems,
		    because userland can easily disable the thermal policy by simply
		    flooding this sysfs node with low temperature values.


What:		/sys/class/thermal/thermal_zoneX/k_d
Description:
		The derivative term of the power allocator governor's PID
		controller. For more information see
		Documentation/driver-api/thermal/power_allocator.rst

		RW, Optional

What:		/sys/class/thermal/thermal_zoneX/k_i
Description:
		The integral term of the power allocator governor's PID
		controller. This term allows the PID controller to compensate
		for long term drift. For more information see
		Documentation/driver-api/thermal/power_allocator.rst

		RW, Optional

What:		/sys/class/thermal/thermal_zoneX/k_po
Description:
		The proportional term of the power allocator governor's PID
		controller during temperature overshoot. Temperature overshoot
		is when the current temperature is above the "desired
		temperature" trip point. For more information see
		Documentation/driver-api/thermal/power_allocator.rst

		RW, Optional

What:		/sys/class/thermal/thermal_zoneX/k_pu
Description:
		The proportional term of the power allocator governor's PID
		controller during temperature undershoot. Temperature undershoot
		is when the current temperature is below the "desired
		temperature" trip point. For more information see
		Documentation/driver-api/thermal/power_allocator.rst

		RW, Optional

What:		/sys/class/thermal/thermal_zoneX/integral_cutoff
Description:
		Temperature offset from the desired temperature trip point
		above which the integral term of the power allocator
		governor's PID controller starts accumulating errors. For
		example, if integral_cutoff is 0, then the integral term only
		accumulates error when temperature is above the desired
		temperature trip point. For more information see
		Documentation/driver-api/thermal/power_allocator.rst

		Unit: millidegree Celsius

		RW, Optional

What:		/sys/class/thermal/thermal_zoneX/slope
Description:
		The slope constant used in a linear extrapolation model
		to determine a hotspot temperature based off the sensor's
		raw readings. It is up to the device driver to determine
		the usage of these values.

		RW, Optional

What:		/sys/class/thermal/thermal_zoneX/offset
Description:
		The offset constant used in a linear extrapolation model
		to determine a hotspot temperature based off the sensor's
		raw readings. It is up to the device driver to determine
		the usage of these values.

		RW, Optional

What:		/sys/class/thermal/thermal_zoneX/sustainable_power
Description:
		An estimate of the sustained power that can be dissipated by
		the thermal zone. Used by the power allocator governor. For
		more information see
		Documentation/driver-api/thermal/power_allocator.rst

		Unit: milliwatts

		RW, Optional

What:		/sys/class/thermal/cooling_deviceX/type
Description:
		String which represents the type of device, e.g:

		- for generic ACPI: should be "Fan", "Processor" or "LCD"
		- for memory controller device on intel_menlow platform:
		should be "Memory controller".

		RO, Required

What:		/sys/class/thermal/cooling_deviceX/max_state
Description:
		The maximum permissible cooling state of this cooling device.

		RO, Required

What:		/sys/class/thermal/cooling_deviceX/cur_state
Description:
		The current cooling state of this cooling device.
		The value can any integer numbers between 0 and max_state:

		- cur_state == 0 means no cooling
		- cur_state == max_state means the maximum cooling.

		RW, Required

What:		/sys/class/thermal/cooling_deviceX/stats/reset
Description:
		Writing any value resets the cooling device's statistics.

		WO, Required

What:		/sys/class/thermal/cooling_deviceX/stats/time_in_state_ms:
Description:
		The amount of time spent by the cooling device in various
		cooling states. The output will have "<state> <time>" pair
		in each line, which will mean this cooling device spent <time>
		msec of time at <state>.

		Output will have one line for each of the supported states.

		RO, Required

What:		/sys/class/thermal/cooling_deviceX/stats/total_trans
Description:
		A single positive value showing the total number of times
		the state of a cooling device is changed.

		RO, Required

What:		/sys/class/thermal/cooling_deviceX/stats/trans_table
Description:
		This gives fine grained information about all the cooling state
		transitions. The cat output here is a two dimensional matrix,
		where an entry <i,j> (row i, column j) represents the number
		of transitions from State_i to State_j. If the transition
		table is bigger than PAGE_SIZE, reading this will return
		an -EFBIG error.

		RO, Required
+149 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/thermal/qcom-spmi-adc-tm-hc.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Qualcomm's SPMI PMIC ADC HC Thermal Monitoring
maintainers:
  - Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

properties:
  compatible:
    const: qcom,spmi-adc-tm-hc

  reg:
    maxItems: 1

  interrupts:
    maxItems: 1

  "#thermal-sensor-cells":
    const: 1
    description:
      Number of cells required to uniquely identify the thermal sensors. Since
      we have multiple sensors this is set to 1

  "#address-cells":
    const: 1

  "#size-cells":
    const: 0

  qcom,avg-samples:
    $ref: /schemas/types.yaml#/definitions/uint32
    description: Number of samples to be used for measurement.
    enum:
      - 1
      - 2
      - 4
      - 8
      - 16
    default: 1

  qcom,decimation:
    $ref: /schemas/types.yaml#/definitions/uint32
    description: This parameter is used to decrease ADC sampling rate.
            Quicker measurements can be made by reducing decimation ratio.
    enum:
      - 256
      - 512
      - 1024
    default: 1024

patternProperties:
  "^([-a-z0-9]*)@[0-7]$":
    type: object
    description:
      Represent one thermal sensor.

    properties:
      reg:
        description: Specify the sensor channel. There are 8 channels in PMIC5's ADC TM
        minimum: 0
        maximum: 7

      io-channels:
        description:
          From common IIO binding. Used to pipe PMIC ADC channel to thermal monitor

      qcom,ratiometric:
        $ref: /schemas/types.yaml#/definitions/flag
        description:
          Channel calibration type.
          If this property is specified VADC will use the VDD reference
          (1.875V) and GND for channel calibration. If property is not found,
          channel will be calibrated with 0V and 1.25V reference channels,
          also known as absolute calibration.

      qcom,hw-settle-time-us:
        description: Time between AMUX getting configured and the ADC starting conversion.
        enum: [0, 100, 200, 300, 400, 500, 600, 700, 1000, 2000, 4000, 6000, 8000, 10000]

      qcom,pre-scaling:
        $ref: /schemas/types.yaml#/definitions/uint32-array
        description: Used for scaling the channel input signal before the
          signal is fed to VADC. The configuration for this node is to know the
          pre-determined ratio and use it for post scaling. It is a pair of
          integers, denoting the numerator and denominator of the fraction by
          which input signal is multiplied. For example, <1 3> indicates the
          signal is scaled down to 1/3 of its value before ADC measurement.  If
          property is not found default value depending on chip will be used.
        items:
          - const: 1
          - enum: [ 1, 3, 4, 6, 20, 8, 10 ]

    required:
      - reg
      - io-channels

    additionalProperties:
      false

required:
  - compatible
  - reg
  - interrupts
  - "#address-cells"
  - "#size-cells"
  - "#thermal-sensor-cells"

additionalProperties: false

examples:
  - |
    #include <dt-bindings/iio/qcom,spmi-vadc.h>
    #include <dt-bindings/interrupt-controller/irq.h>
    spmi_bus {
        #address-cells = <1>;
        #size-cells = <0>;
        pm8998_adc: adc@3100 {
            reg = <0x3100>;
            compatible = "qcom,spmi-adc-rev2";
            #address-cells = <1>;
            #size-cells = <0>;
            #io-channel-cells = <1>;

            /* Other propreties are omitted */
            adc-chan@4c {
                reg = <ADC5_XO_THERM_100K_PU>;
            };
        };

        pm8998_adc_tm: adc-tm@3400 {
            compatible = "qcom,spmi-adc-tm-hc";
            reg = <0x3400>;
            interrupts = <0x2 0x34 0x0 IRQ_TYPE_EDGE_RISING>;
            #thermal-sensor-cells = <1>;
            #address-cells = <1>;
            #size-cells = <0>;

            thermistor@1 {
                reg = <1>;
                io-channels = <&pm8998_adc ADC5_XO_THERM_100K_PU>;
                qcom,ratiometric;
                qcom,hw-settle-time-us = <200>;
            };
        };
    };
...
+13 −10
Original line number Diff line number Diff line
@@ -12,14 +12,14 @@ maintainers:
properties:
  compatible:
    enum:
      - rockchip,px30-tsadc # PX30 SoCs
      - rockchip,rv1108-tsadc # RV1108 SoCs
      - rockchip,rk3228-tsadc # RK3228 SoCs
      - rockchip,rk3288-tsadc # RK3288 SoCs
      - rockchip,rk3328-tsadc # RK3328 SoCs
      - rockchip,rk3368-tsadc # RK3368 SoCs
      - rockchip,rk3399-tsadc # RK3399 SoCs
      - rockchip,rk3568-tsadc # RK3568 SoCs
      - rockchip,px30-tsadc
      - rockchip,rk3228-tsadc
      - rockchip,rk3288-tsadc
      - rockchip,rk3328-tsadc
      - rockchip,rk3368-tsadc
      - rockchip,rk3399-tsadc
      - rockchip,rk3568-tsadc
      - rockchip,rv1108-tsadc

  reg:
    maxItems: 1
@@ -37,11 +37,15 @@ properties:
      - const: apb_pclk

  resets:
    maxItems: 1
    minItems: 1
    maxItems: 3

  reset-names:
    minItems: 1
    items:
      - const: tsadc-apb
      - const: tsadc
      - const: tsadc-phy

  "#thermal-sensor-cells":
    const: 1
@@ -71,7 +75,6 @@ required:
  - clocks
  - clock-names
  - resets
  - reset-names
  - "#thermal-sensor-cells"

additionalProperties: false
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ properties:
      - socionext,uniphier-pxs2-thermal
      - socionext,uniphier-ld20-thermal
      - socionext,uniphier-pxs3-thermal
      - socionext,uniphier-nx1-thermal

  interrupts:
    maxItems: 1
+3 −222
Original line number Diff line number Diff line
@@ -428,6 +428,9 @@ of thermal zone device. E.g. the generic thermal driver registers one hwmon
class device and build the associated hwmon sysfs I/F for all the registered
ACPI thermal zones.

Please read Documentation/ABI/testing/sysfs-class-thermal for thermal
zone and cooling device attribute details.

::

  /sys/class/hwmon/hwmon[0-*]:
@@ -437,228 +440,6 @@ ACPI thermal zones.

Please read Documentation/hwmon/sysfs-interface.rst for additional information.

Thermal zone attributes
-----------------------

type
	Strings which represent the thermal zone type.
	This is given by thermal zone driver as part of registration.
	E.g: "acpitz" indicates it's an ACPI thermal device.
	In order to keep it consistent with hwmon sys attribute; this should
	be a short, lowercase string, not containing spaces nor dashes.
	RO, Required

temp
	Current temperature as reported by thermal zone (sensor).
	Unit: millidegree Celsius
	RO, Required

mode
	One of the predefined values in [enabled, disabled].
	This file gives information about the algorithm that is currently
	managing the thermal zone. It can be either default kernel based
	algorithm or user space application.

	enabled
			  enable Kernel Thermal management.
	disabled
			  Preventing kernel thermal zone driver actions upon
			  trip points so that user application can take full
			  charge of the thermal management.

	RW, Optional

policy
	One of the various thermal governors used for a particular zone.

	RW, Required

available_policies
	Available thermal governors which can be used for a particular zone.

	RO, Required

`trip_point_[0-*]_temp`
	The temperature above which trip point will be fired.

	Unit: millidegree Celsius

	RO, Optional

`trip_point_[0-*]_type`
	Strings which indicate the type of the trip point.

	E.g. it can be one of critical, hot, passive, `active[0-*]` for ACPI
	thermal zone.

	RO, Optional

`trip_point_[0-*]_hyst`
	The hysteresis value for a trip point, represented as an integer
	Unit: Celsius
	RW, Optional

`cdev[0-*]`
	Sysfs link to the thermal cooling device node where the sys I/F
	for cooling device throttling control represents.

	RO, Optional

`cdev[0-*]_trip_point`
	The trip point in this thermal zone which `cdev[0-*]` is associated
	with; -1 means the cooling device is not associated with any trip
	point.

	RO, Optional

`cdev[0-*]_weight`
	The influence of `cdev[0-*]` in this thermal zone. This value
	is relative to the rest of cooling devices in the thermal
	zone. For example, if a cooling device has a weight double
	than that of other, it's twice as effective in cooling the
	thermal zone.

	RW, Optional

emul_temp
	Interface to set the emulated temperature method in thermal zone
	(sensor). After setting this temperature, the thermal zone may pass
	this temperature to platform emulation function if registered or
	cache it locally. This is useful in debugging different temperature
	threshold and its associated cooling action. This is write only node
	and writing 0 on this node should disable emulation.
	Unit: millidegree Celsius

	WO, Optional

	  WARNING:
	    Be careful while enabling this option on production systems,
	    because userland can easily disable the thermal policy by simply
	    flooding this sysfs node with low temperature values.

sustainable_power
	An estimate of the sustained power that can be dissipated by
	the thermal zone. Used by the power allocator governor. For
	more information see Documentation/driver-api/thermal/power_allocator.rst

	Unit: milliwatts

	RW, Optional

k_po
	The proportional term of the power allocator governor's PID
	controller during temperature overshoot. Temperature overshoot
	is when the current temperature is above the "desired
	temperature" trip point. For more information see
	Documentation/driver-api/thermal/power_allocator.rst

	RW, Optional

k_pu
	The proportional term of the power allocator governor's PID
	controller during temperature undershoot. Temperature undershoot
	is when the current temperature is below the "desired
	temperature" trip point. For more information see
	Documentation/driver-api/thermal/power_allocator.rst

	RW, Optional

k_i
	The integral term of the power allocator governor's PID
	controller. This term allows the PID controller to compensate
	for long term drift. For more information see
	Documentation/driver-api/thermal/power_allocator.rst

	RW, Optional

k_d
	The derivative term of the power allocator governor's PID
	controller. For more information see
	Documentation/driver-api/thermal/power_allocator.rst

	RW, Optional

integral_cutoff
	Temperature offset from the desired temperature trip point
	above which the integral term of the power allocator
	governor's PID controller starts accumulating errors. For
	example, if integral_cutoff is 0, then the integral term only
	accumulates error when temperature is above the desired
	temperature trip point. For more information see
	Documentation/driver-api/thermal/power_allocator.rst

	Unit: millidegree Celsius

	RW, Optional

slope
	The slope constant used in a linear extrapolation model
	to determine a hotspot temperature based off the sensor's
	raw readings. It is up to the device driver to determine
	the usage of these values.

	RW, Optional

offset
	The offset constant used in a linear extrapolation model
	to determine a hotspot temperature based off the sensor's
	raw readings. It is up to the device driver to determine
	the usage of these values.

	RW, Optional

Cooling device attributes
-------------------------

type
	String which represents the type of device, e.g:

	- for generic ACPI: should be "Fan", "Processor" or "LCD"
	- for memory controller device on intel_menlow platform:
	  should be "Memory controller".

	RO, Required

max_state
	The maximum permissible cooling state of this cooling device.

	RO, Required

cur_state
	The current cooling state of this cooling device.
	The value can any integer numbers between 0 and max_state:

	- cur_state == 0 means no cooling
	- cur_state == max_state means the maximum cooling.

	RW, Required

stats/reset
	Writing any value resets the cooling device's statistics.
	WO, Required

stats/time_in_state_ms:
	The amount of time spent by the cooling device in various cooling
	states. The output will have "<state> <time>" pair in each line, which
	will mean this cooling device spent <time> msec of time at <state>.
	Output will have one line for each of the supported states.
	RO, Required


stats/total_trans:
	A single positive value showing the total number of times the state of a
	cooling device is changed.

	RO, Required

stats/trans_table:
	This gives fine grained information about all the cooling state
	transitions. The cat output here is a two dimensional matrix, where an
	entry <i,j> (row i, column j) represents the number of transitions from
	State_i to State_j. If the transition table is bigger than PAGE_SIZE,
	reading this will return an -EFBIG error.
	RO, Required

3. A simple implementation
==========================

Loading