Skip to contentSkip to conversation

Add driver for NVIDIA Tegra30 SoC Thermal sensor

PATCH Superseded Dmitry Osipenko 1 participant 8 messages May 23, 2021

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add driver for NVIDIA Tegra30 SoC Thermal sensor

Hi,

This series adds support for the thermal sensor that is found on NVIDIA Tegra30 SoC. Sensor monitors temperature and voltage of the SoC, it also emits signals to the power management and clock controllers that are performing the emergency shut down and the CPU frequency throttling when a pre-programmed temperature levels are reached.

Please note that this series is made on top of ACMTON patches! [1]. Otherwise tegra30.dtsi will fail to compile.

[1] https://patchwork.ozlabs.org/project/linux-tegra/list/?series=243115

Changelog:

v2: - Made a very minor improvement to one error message, it now prints
number of channel at which error occurred.

- Added r-b from Rob Herring to the binding.

Dmitry Osipenko (7):
dt-bindings: thermal: Add binding for Tegra30 thermal sensor
thermal: thermal_of: Stop zone device before unregistering it thermal/core: Export thermal_cooling_device_stats_update() thermal/drivers/tegra: Add driver for Tegra30 thermal sensor
ARM: tegra_defconfig: Enable CONFIG_TEGRA30_TSENSOR
ARM: multi_v7_defconfig: Enable CONFIG_TEGRA30_TSENSOR
ARM: tegra: Add SoC thermal sensor to Tegra30 device-trees

 .../thermal/nvidia,tegra30-tsensor.yaml       |  78 ++
 arch/arm/boot/dts/tegra30-ouya.dts            |  16 +
 arch/arm/boot/dts/tegra30.dtsi                |  93 ++-
 arch/arm/configs/multi_v7_defconfig           |   1 +
 arch/arm/configs/tegra_defconfig              |   1 +
 drivers/thermal/tegra/Kconfig                 |   7 +
 drivers/thermal/tegra/Makefile                |   1 +
 drivers/thermal/tegra/tegra30-tsensor.c       | 736 ++++++++++++++++++
 drivers/thermal/thermal_of.c                  |   3 +
 drivers/thermal/thermal_sysfs.c               |   1 +
 10 files changed, 933 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/thermal/nvidia,tegra30-tsensor.yaml
 create mode 100644 drivers/thermal/tegra/tegra30-tsensor.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/7 dt-bindings: thermal: Add binding for Tegra30 thermal sensor

All NVIDIA Tegra30 SoCs have on-chip sensors which monitor temperature and voltage of the SoC. Sensors also controls CPU x2 freq throttle and emits emergency shutdown signal. TSENSOR has has two separate channels for each sensor placed in a different parts of the SoC. Add binding for the sensor hardware.

---
 .../thermal/nvidia,tegra30-tsensor.yaml       | 78 +++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/nvidia,tegra30-tsensor.yaml
Documentation/devicetree/bindings/thermal/nvidia,tegra30-tsensor.yaml new file +78 -0
new file mode 100644
index 000000000000..6182090d313c
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/thermal/nvidia,tegra30-tsensor.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NVIDIA Tegra30 Thermal Sensor
+
+maintainers:
+  - Dmitry Osipenko <[email protected]>
+  - Jon Hunter <[email protected]>
+  - Thierry Reding <[email protected]>
+
+description: |
+  TSENSOR provides thermal and voltage sensors which monitor temperature
+  and voltage of the chip. Sensors are placed across the die to gauge the
+  temperature of the whole chip. The TSENSOR module:
+
+    Generates an interrupt to SW to lower temperature via DVFS on reaching
+    a certain thermal/voltage threshold.
+
+    Generates a signal to the CAR to reduce CPU frequency by half on reaching
+    a certain thermal/voltage threshold.
+
+    Generates a signal to the PMC when the temperature reaches dangerously high
+    levels to reset the chip and sets a flag in the PMC.
+
+  TSENSOR has two channels which monitor two different spots of the SoC.
+
+properties:
+  compatible:
+    const: nvidia,tegra30-tsensor
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  "#thermal-sensor-cells":
+    const: 1
+
+  "#cooling-cells":
+    const: 2
+
+  assigned-clock-parents: true
+  assigned-clock-rates: true
+  assigned-clocks: true
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - resets
+  - interrupts
+  - "#thermal-sensor-cells"
+  - "#cooling-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    thermal-sensor@70014000 {
+      compatible = "nvidia,tegra30-tsensor";
+      reg = <0x70014000 0x500>;
+      interrupts = <0 102 4>;
+      clocks = <&clk 100>;
+      resets = <&rst 100>;
+
+      #thermal-sensor-cells = <1>;
+      #cooling-cells = <2>;
+    };
Signature · 1 line
2.30.2
#2 lore raw

PATCH v2 2/7 thermal: thermal_of: Stop zone device before unregistering it

In reply to Dmitry Osipenko

Zone device is enabled after thermal_zone_of_sensor_register() completion, but it's not disabled before senors if unregistered, leaving temperature polling active. This results in accessing a disabled zone device and produces a warning about this problem. Stop zone device before unregistering it in order to fix this "use-after-free" problem.

---
 drivers/thermal/thermal_of.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/thermal/thermal_of.c +3 -0
index 5b76f9a1280d..6379f26a335f 100644
@@ -559,6 +559,9 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
 	if (!tz)
 		return;
 
+	/* stop temperature polling */
+	thermal_zone_device_disable(tzd);
+
 	mutex_lock(&tzd->lock);
 	tzd->ops->get_temp = NULL;
 	tzd->ops->get_trend = NULL;
Signature · 1 line
2.30.2
#3 lore raw

PATCH v2 3/7 thermal/core: Export thermal_cooling_device_stats_update()

In reply to Dmitry Osipenko

NVIDIA Tegra30 thermal sensor driver has a hardware-controlled CPU cooling feature that halves CPU frequency once a specified trip point is breached. In order to account the hardware state transitions, which are reported by interrupt, the sensor driver needs to report the cooling state transition and this is done by thermal_cooling_device_stats_update(). The sensor driver could be compiled as a loadable driver module, but this API function isn't exported, hence export it.

---
 drivers/thermal/thermal_sysfs.c | 1 +
 1 file changed, 1 insertion(+)
drivers/thermal/thermal_sysfs.c +1 -0
index 1c4aac8464a7..ab373280f853 100644
@@ -690,6 +690,7 @@ void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
 unlock:
 	spin_unlock(&stats->lock);
 }
+EXPORT_SYMBOL_GPL(thermal_cooling_device_stats_update);
 
 static ssize_t total_trans_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
Signature · 1 line
2.30.2
#4 lore raw

PATCH v2 4/7 thermal/drivers/tegra: Add driver for Tegra30 thermal sensor

In reply to Dmitry Osipenko

All NVIDIA Tegra30 SoCs have a two-channel on-chip sensor unit which monitors temperature and voltage of the SoC. Sensors control CPU frequency throttling, which is activated by hardware once preprogrammed temperature level is breached, they also send signal to Power Management controller to perform emergency shutdown on a critical overheat of the SoC die. Add driver for the Tegra30 TSENSOR module, exposing it as a thermal sensor and a cooling device.

---
 drivers/thermal/tegra/Kconfig           |   7 +
 drivers/thermal/tegra/Makefile          |   1 +
 drivers/thermal/tegra/tegra30-tsensor.c | 736 ++++++++++++++++++++++++
 3 files changed, 744 insertions(+)
 create mode 100644 drivers/thermal/tegra/tegra30-tsensor.c
drivers/thermal/tegra/Kconfig +7 -0
index 46c2215867cd..019e3a2eb69e 100644
@@ -18,4 +18,11 @@ config TEGRA_BPMP_THERMAL
 	  Enable this option for support for sensing system temperature of NVIDIA
 	  Tegra systems-on-chip with the BPMP coprocessor (Tegra186).
 
+config TEGRA30_TSENSOR
+	tristate "Tegra30 Thermal Sensor"
+	depends on ARCH_TEGRA_3x_SOC || COMPILE_TEST
+	help
+	  Enable this option to support thermal management of NVIDIA Tegra30
+	  system-on-chip.
+
 endmenu
drivers/thermal/tegra/Makefile +1 -0
index 0f2b66edf0d2..eb27d194c583 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_TEGRA_SOCTHERM)		+= tegra-soctherm.o
 obj-$(CONFIG_TEGRA_BPMP_THERMAL)	+= tegra-bpmp-thermal.o
+obj-$(CONFIG_TEGRA30_TSENSOR)		+= tegra30-tsensor.o
 
 tegra-soctherm-y				:= soctherm.o soctherm-fuse.o
 tegra-soctherm-$(CONFIG_ARCH_TEGRA_124_SOC)	+= tegra124-soctherm.o
drivers/thermal/tegra/tegra30-tsensor.c new file +736 -0

736 lines not on this page · raw message

Signature · 1 line
2.30.2
#5 lore raw

PATCH v2 5/7 ARM: tegra_defconfig: Enable CONFIG_TEGRA30_TSENSOR

In reply to Dmitry Osipenko

Enable NVIDIA Tegra30 SoC thermal sensor driver in tegra_defconfig.

---
 arch/arm/configs/tegra_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/tegra_defconfig +1 -0
index 3d8d8af9524d..63e7f3261e6d 100644
@@ -169,6 +169,7 @@ CONFIG_THERMAL_STATISTICS=y
 CONFIG_CPU_THERMAL=y
 CONFIG_DEVFREQ_THERMAL=y
 CONFIG_TEGRA_SOCTHERM=m
+CONFIG_TEGRA30_TSENSOR=m
 CONFIG_WATCHDOG=y
 CONFIG_MAX77620_WATCHDOG=y
 CONFIG_TEGRA_WATCHDOG=y
Signature · 1 line
2.30.2
#6 lore raw

PATCH v2 6/7 ARM: multi_v7_defconfig: Enable CONFIG_TEGRA30_TSENSOR

In reply to Dmitry Osipenko

Enable NVIDIA Tegra30 SoC thermal sensor driver in multi_v7_defconfig.

---
 arch/arm/configs/multi_v7_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/multi_v7_defconfig +1 -0
index 52a0400fdd92..fc346f87d7f9 100644
@@ -523,6 +523,7 @@ CONFIG_BRCMSTB_THERMAL=m
 CONFIG_GENERIC_ADC_THERMAL=m
 CONFIG_ST_THERMAL_MEMMAP=y
 CONFIG_TEGRA_SOCTHERM=m
+CONFIG_TEGRA30_TSENSOR=m
 CONFIG_UNIPHIER_THERMAL=y
 CONFIG_DA9063_WATCHDOG=m
 CONFIG_XILINX_WATCHDOG=y
Signature · 1 line
2.30.2
#7 lore raw

PATCH v2 7/7 ARM: tegra: Add SoC thermal sensor to Tegra30 device-trees

In reply to Dmitry Osipenko

Add the on-chip SoC thermal sensor to Tegra30 device-trees. Now CPU temperature reporting and thermal throttling is available on all Tegra30 devices universally.

---
 arch/arm/boot/dts/tegra30-ouya.dts | 16 +++++
 arch/arm/boot/dts/tegra30.dtsi     | 93 ++++++++++++++++++++++++++++--
 2 files changed, 105 insertions(+), 4 deletions(-)
arch/arm/boot/dts/tegra30-ouya.dts +16 -0
index e767ac227a81..d792ce5c64c0 100644
@@ -468,6 +468,22 @@ map1 {
 				};
 			};
 		};
+
+		tsensor-channel0 {
+			trips {
+				dvfs-alert {
+					temperature = <70000>;
+				};
+
+				cpu-div2-throttle {
+					temperature = <75000>;
+				};
+
+				soc-critical {
+					temperature = <90000>;
+				};
+			};
+		};
 	};
 
 	vdd_12v_in: vdd_12v_in {
arch/arm/boot/dts/tegra30.dtsi +89 -4

137 lines not on this page · raw message

Signature · 1 line
2.30.2