Skip to contentSkip to conversation

thermal: bcm2835: add thermal driver

PATCH Superseded kernel at martin.sperl.org 3 participants 13 messages Sep 9, 2016 – Sep 13, 2016

Subsystems (5)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v4 cover thermal: bcm2835: add thermal driver

From: Martin Sperl <[email protected]>

Add a thermal driver for the TSENSE device of the bcm2835 SOC.

If the firmware enables the HW, then the configuration is not touched. In case the firmware has not enabled the device, then we try to set it up correctly (which unfortunately can not get tested).

It exposes temperature and a critical trip point (using a hardcoded default of 80C or the temperature configured in the control register by the firmware, which reads as 407C currently)

The calibrations are (potentially) different for bcm2835, bcm2836 and bcm2837 and can get selected by the compatible property in the device tree.

The driver also exposes the registers via debugfs.

Possible future enhancements:
* the device has the ability to trigger interrupts on reaching the programmed critical temperature.
I have no knowledge which interrupt could be responsible for this on the ARM side, so if we get to know which irq it is we can implement that.
Instead the driver right now implements polling in 1 second intervals
* the device can also reset the HW after the trip point
has been reached (also with some delay, so that corrective actions can get taken) - this is currently not enabled by the firmware, but could.
* we could define more trip points for THERMAL_TRIP_HOT
* make the trip point limits modifiable (ops.set_trip_temp)

Changelog:
V1 -> V2: renamed dt-binding documentation file
added specific settings depending on compatible added trip point based on register
setting up ctrl-register if HW is not enabled by firmware
as per recommendation of Eric (untested)
check that clock frequency is in range
(1.9 - 5MHz - as per comment in clk-bcm2835.c)
added driver to multi_v7_defconfig
V2 -> V3: made a module in multi_v7_defconfig
fixed typo in dt-binding document
V3 -> V4: moved driver back to thermal (not using bcm sub-directory)
set polling interval to 1second (was 0ms, so interrupt driven)

Martin Sperl (4):
dt: bindings: add thermal device driver for bcm2835
thermal: bcm2835: add thermal driver for bcm2835 soc
ARM: bcm2835: add thermal node to device-tree of bcm283x
ARM: bcm2835: add thermal driver to default_config

 .../bindings/thermal/brcm,bcm2835-thermal.txt      |  17 ++
 arch/arm/boot/dts/bcm283x.dtsi                     |   6 +
 arch/arm/configs/bcm2835_defconfig                 |   2 +
 drivers/thermal/Kconfig                            |   5 +
 drivers/thermal/Makefile                           |   1 +
 drivers/thermal/bcm2835_thermal.c                  | 327 +++++++++++++++++++++
 6 files changed, 358 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,bcm2835-thermal.txt
 create mode 100644 drivers/thermal/bcm2835_thermal.c

--
2.1.4

#1 lore raw

PATCH v4 1/4 dt: bindings: add thermal device driver for bcm2835

From: Martin Sperl <[email protected]>

Add dt-binding documentation for bcm2835 SOC thermal sensor.

Changelog:
V1 -> V2: renamed file to follow naming conventions V2 -> V3: removed 0x in node name

---
 .../bindings/thermal/brcm,bcm2835-thermal.txt           | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,bcm2835-thermal.txt
Documentation/devicetree/bindings/thermal/brcm,bcm2835-thermal.txt new file +17 -0
new file mode 100644
index 0000000..474531d
@@ -0,0 +1,17 @@
+Binding for Thermal Sensor driver for BCM2835 SoCs.
+
+Required parameters:
+-------------------
+
+compatible: 	should be one of: "brcm,bcm2835-thermal",
+		"brcm,bcm2836-thermal" or "brcm,bcm2837-thermal"
+reg:		Address range of the thermal registers.
+clocks: 	Phandle of the clock used by the thermal sensor.
+
+Example:
+
+thermal: thermal at 7e212000 {
+	compatible = "brcm,bcm2835-thermal";
+	reg = <0x7e212000 0x8>;
+	clocks = <&clocks BCM2835_CLOCK_TSENS>;
+};
Signature · 1 line
2.1.4
#2 lore raw

PATCH v4 2/4 thermal: bcm2835: add thermal driver for bcm2835 soc

In reply to kernel at martin.sperl.org

From: Martin Sperl <[email protected]>

Add basic thermal driver for bcm2835 SOC.

This driver currently relies on the firmware setting up the tsense HW block and does not set it up itself.

ChangeLog:
V1 -> V2: added specific settings depending on compatiblity
added trip point based on register
setting up ctrl-register if HW is not enabled by firmware
as per recommendation of Eric (untested)
check that clock frequency is in range
(1.9 - 5MHz - as per comment in clk-bcm2835.c)
V3 -> V4: moved driver back to thermal (not using bcm sub-directory)
set polling interval to 1second (was 0ms, so interrupt driven)

---
 drivers/thermal/Kconfig           |   5 +
 drivers/thermal/Makefile          |   1 +
 drivers/thermal/bcm2835_thermal.c | 327 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 333 insertions(+)
 create mode 100644 drivers/thermal/bcm2835_thermal.c
drivers/thermal/Kconfig +5 -0
index 2d702ca..5e3e4e4 100644
@@ -399,4 +399,9 @@ config GENERIC_ADC_THERMAL
 	  to this driver. This driver reports the temperature by reading ADC
 	  channel and converts it to temperature based on lookup table.
 
+config BCM2835_THERMAL
+       tristate "Thermal sensors on bcm2835 SoC"
+       help
+         Support for thermal sensors on Broadcom bcm2835 SoCs.
+
 endif
drivers/thermal/Makefile +1 -0
index 10b07c1..c26343e 100644
@@ -51,3 +51,4 @@ obj-$(CONFIG_TEGRA_SOCTHERM)	+= tegra/
 obj-$(CONFIG_HISI_THERMAL)     += hisi_thermal.o
 obj-$(CONFIG_MTK_THERMAL)	+= mtk_thermal.o
 obj-$(CONFIG_GENERIC_ADC_THERMAL)	+= thermal-generic-adc.o
+obj-$(CONFIG_BCM2835_THERMAL)	+= bcm2835_thermal.o
drivers/thermal/bcm2835_thermal.c new file +327 -0

327 lines not on this page · raw message

--
2.1.4

#4 lore raw

PATCH v4 3/4 ARM: bcm2835: add thermal node to device-tree of bcm283x

In reply to kernel at martin.sperl.org

From: Martin Sperl <[email protected]>

Add the node for the thermal sensor of the bcm2835-soc to the device tree.

---
 arch/arm/boot/dts/bcm283x.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/boot/dts/bcm283x.dtsi +6 -0
index b982522..e2e3a46 100644
@@ -186,6 +186,12 @@
 			interrupts = <2 14>; /* pwa1 */
 		};
 
+		thermal: thermal at 0x7e212000 {
+			compatible = "brcm,bcm2835-thermal";
+			reg = <0x7e212000 0x8>;
+			clocks = <&clocks BCM2835_CLOCK_TSENS>;
+		};
+
 		aux: aux at 0x7e215000 {
 			compatible = "brcm,bcm2835-aux";
 			#clock-cells = <1>;
Signature · 1 line
2.1.4
#12 lore raw

PATCH v4 4/4 ARM: bcm2835: add thermal driver to default_config

In reply to kernel at martin.sperl.org

From: Martin Sperl <[email protected]>

Add the thermal driver to list of compiled modules in the default config for bcm2835.

---
 arch/arm/configs/bcm2835_defconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/configs/bcm2835_defconfig +2 -0
index 79de828..4b89f4e 100644
@@ -73,6 +73,8 @@ CONFIG_SPI_BCM2835=y
 CONFIG_SPI_BCM2835AUX=y
 CONFIG_GPIO_SYSFS=y
 # CONFIG_HWMON is not set
+CONFIG_THERMAL=y
+CONFIG_BCM2835_THERMAL=y
 CONFIG_WATCHDOG=y
 CONFIG_BCM2835_WDT=y
 CONFIG_DRM=y
Signature · 1 line
2.1.4
#5 lore raw

PATCH v4 3/4 ARM: bcm2835: add thermal node to device-tree of bcm283x

In reply to kernel at martin.sperl.org

Am 09.09.2016 um 09:49 schrieb kernel at martin.sperl.org:

Quoted 16 lines

From: Martin Sperl <[email protected]>

Add the node for the thermal sensor of the bcm2835-soc to the device tree.

---
 arch/arm/boot/dts/bcm283x.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/boot/dts/bcm283x.dtsi +0 -0
index b982522..e2e3a46 100644

arch/arm/boot/dts/bcm283x.dtsi line 194

Quoted 9 lines
arch/arm/boot/dts/bcm283x.dtsi +6 -0
@@ -186,6 +186,12 @@
 			interrupts = <2 14>; /* pwa1 */
 		};
 
+		thermal: thermal at 0x7e212000 {
+			compatible = "brcm,bcm2835-thermal";
+			reg = <0x7e212000 0x8>;
+			clocks = <&clocks BCM2835_CLOCK_TSENS>;
+		};
+

Since the driver handles 3 different SoC (2835, 2836, 2837). This node should be defined in the SoC specific dtsi files, because the BCM2836 includes bcm283x.dtsi too.

Be aware the patch for bcm2837 must go to ARM64.

Quoted 3 lines
arch/arm/boot/dts/bcm283x.dtsi +0 -0
 		aux: aux at 0x7e215000 {
 			compatible = "brcm,bcm2835-aux";
 			#clock-cells = <1>;
#6 lore raw

PATCH v4 3/4 ARM: bcm2835: add thermal node to device-tree of bcm283x

Quoted 34 lines · Stefan Wahren
Quoted 18 lines

Am 09.09.2016 um 09:49 schrieb kernel at martin.sperl.org:
From: Martin Sperl <[email protected]>

Add the node for the thermal sensor of the bcm2835-soc to the device tree.

---
arch/arm/boot/dts/bcm283x.dtsi | 6 ++++++

1 file changed, 6 insertions(+)
arch/arm/boot/dts/bcm283x.dtsi +0 -0
index b982522..e2e3a46 100644

arch/arm/boot/dts/bcm283x.dtsi line 194

Quoted 9 lines
arch/arm/boot/dts/bcm283x.dtsi +6 -0
@@ -186,6 +186,12 @@
           interrupts = <2 14>; /* pwa1 */
       };
 
+        thermal: thermal at 0x7e212000 {
+            compatible = "brcm,bcm2835-thermal";
+            reg = <0x7e212000 0x8>;
+            clocks = <&clocks BCM2835_CLOCK_TSENS>;
+        };
+

Since the driver handles 3 different SoC (2835, 2836, 2837). This node should be defined in the SoC specific dtsi files, because the BCM2836 includes bcm283x.dtsi too.

Quoted 1 line

Be aware the patch for bcm2837 must go to ARM64.

I can not really follow:
* the node is defined in the dtsi included by all 3 soc, and it is available on all so it sits where for example spi0 or uart0 is located
* as for arm64: this describes the registers that are identical for arm and arm64 and the bcm2837.dtsi is also including ../../../../arm/boot/dts/bcm283x.dtsi

So what is the problem?

Martin

P.s the patches apply cleanly against master.

#7 lore raw

PATCH v4 3/4 ARM: bcm2835: add thermal node to device-tree of bcm283x

Quoted 50 lines

Martin Sperl <[email protected]> hat am 9. September 2016 um 16:58 geschrieben:

Quoted 34 lines · Stefan Wahren
Quoted 19 lines

Am 09.09.2016 um 09:49 schrieb kernel at martin.sperl.org:
From: Martin Sperl <[email protected]>

Add the node for the thermal sensor of the bcm2835-soc to the device tree.

---
arch/arm/boot/dts/bcm283x.dtsi | 6 ++++++

1 file changed, 6 insertions(+)
arch/arm/boot/dts/bcm283x.dtsi +0 -0
index b982522..e2e3a46 100644

arch/arm/boot/dts/bcm283x.dtsi line 194

Quoted 9 lines
arch/arm/boot/dts/bcm283x.dtsi +6 -0
@@ -186,6 +186,12 @@
           interrupts = <2 14>; /* pwa1 */
       };
 
+        thermal: thermal at 0x7e212000 {
+            compatible = "brcm,bcm2835-thermal";
+            reg = <0x7e212000 0x8>;
+            clocks = <&clocks BCM2835_CLOCK_TSENS>;
+        };
+

Since the driver handles 3 different SoC (2835, 2836, 2837). This node should be defined in the SoC specific dtsi files, because the BCM2836 includes bcm283x.dtsi too.

Quoted 1 line

Be aware the patch for bcm2837 must go to ARM64.

I can not really follow:
* the node is defined in the dtsi included by all 3 soc, and it is available on all so it sits where for example spi0 or uart0 is located
* as for arm64: this describes the registers that are identical for arm and arm64 and the bcm2837.dtsi is also including ../../../../arm/boot/dts/bcm283x.dtsi

Quoted 1 line

So what is the problem?

The thermal driver specifies 3 different compatibles with partially different settings.
If this patch is applied, all SoC (bcm2835, bcm2836, bcm2837) would use the bcm2835 settings.
I can't believe this is intended.

Why does the binding contains 3 different compatibles if only one is used?

Quoted 5 lines

Martin

P.s the patches apply cleanly against master.

#3 lore raw

PATCH v4 2/4 thermal: bcm2835: add thermal driver for bcm2835 soc

In reply to kernel at martin.sperl.org
Quoted 8 lines · kernel at martin.sperl.org

From: Martin Sperl <[email protected]>

Add basic thermal driver for bcm2835 SOC.

This driver currently relies on the firmware setting up the tsense HW block and does not set it up itself.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160909/324bf9f8/attachment.sig>

#8 lore raw

PATCH v4 3/4 ARM: bcm2835: add thermal node to device-tree of bcm283x

In reply to Stefan Wahren
Quoted 55 lines · Stefan Wahren
Quoted 51 lines

Martin Sperl <[email protected]> hat am 9. September 2016 um 16:58 geschrieben:

Quoted 34 lines
Quoted 20 lines · Stefan Wahren

Am 09.09.2016 um 09:49 schrieb kernel at martin.sperl.org:
From: Martin Sperl <[email protected]>

Add the node for the thermal sensor of the bcm2835-soc to the device tree.

---
arch/arm/boot/dts/bcm283x.dtsi | 6 ++++++

1 file changed, 6 insertions(+)
arch/arm/boot/dts/bcm283x.dtsi +0 -0
index b982522..e2e3a46 100644

arch/arm/boot/dts/bcm283x.dtsi line 194

Quoted 9 lines
arch/arm/boot/dts/bcm283x.dtsi +6 -0
@@ -186,6 +186,12 @@
          interrupts = <2 14>; /* pwa1 */
      };
 
+        thermal: thermal at 0x7e212000 {
+            compatible = "brcm,bcm2835-thermal";
+            reg = <0x7e212000 0x8>;
+            clocks = <&clocks BCM2835_CLOCK_TSENS>;
+        };
+

Since the driver handles 3 different SoC (2835, 2836, 2837). This node should be defined in the SoC specific dtsi files, because the BCM2836 includes bcm283x.dtsi too.

Quoted 1 line

Be aware the patch for bcm2837 must go to ARM64.

I can not really follow:
* the node is defined in the dtsi included by all 3 soc, and it is available on all so it sits where for example spi0 or uart0 is located
* as for arm64: this describes the registers that are identical for arm and arm64 and the bcm2837.dtsi is also including ../../../../arm/boot/dts/bcm283x.dtsi

Quoted 1 line

So what is the problem?

Quoted 7 lines

The thermal driver specifies 3 different compatibles with partially different settings.
If this patch is applied, all SoC (bcm2835, bcm2836, bcm2837) would use the bcm2835 settings.
I can't believe this is intended.

Why does the binding contains 3 different compatibles if only one is used?

Now I understand - did not think of that: good catch!

To minimize the patch: what about setting it to 2837 by default (in 283x.dtsi) and only change compatible in 2835.dtsi and 2836.dtsi - that is 3 files changed instead of 4 or 5...

Or any other ideas how to detect which Soc we run on during runtime? I.e: query the root compatible string in the device-tree?

Just before I create a new patch set to fix that.

Martin

#9 lore raw

PATCH v4 3/4 ARM: bcm2835: add thermal node to device-tree of bcm283x

Hi Martin,

Quoted 36 lines

Martin Sperl <[email protected]> hat am 9. September 2016 um 20:12 geschrieben:

Quoted 31 lines · Stefan Wahren
Quoted 30 lines

Martin Sperl <[email protected]> hat am 9. September 2016 um 16:58 geschrieben:

Quoted 23 lines
Quoted 23 lines · Stefan Wahren

Am 09.09.2016 um 09:49 schrieb kernel at martin.sperl.org:
From: Martin Sperl <[email protected]>

Add the node for the thermal sensor of the bcm2835-soc to the device tree.

---
arch/arm/boot/dts/bcm283x.dtsi | 6 ++++++

1 file changed, 6 insertions(+)
arch/arm/boot/dts/bcm283x.dtsi +0 -0
index b982522..e2e3a46 100644
@@ -186,6 +186,12 @@
          interrupts = <2 14>; /* pwa1 */
      };
 
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

arch/arm/boot/dts/bcm283x.dtsi line 189

Quoted 1 line
arch/arm/boot/dts/bcm283x.dtsi +1 -0
+        thermal: thermal at 0x7e212000 {

please remove 0x here.

Quoted 29 lines
Quoted 29 lines
Quoted 20 lines
Quoted 11 lines

arch/arm/boot/dts/bcm283x.dtsi line 194

Quoted 5 lines
arch/arm/boot/dts/bcm283x.dtsi +5 -0
+            compatible = "brcm,bcm2835-thermal";
+            reg = <0x7e212000 0x8>;
+            clocks = <&clocks BCM2835_CLOCK_TSENS>;
+        };
+

Since the driver handles 3 different SoC (2835, 2836, 2837). This node should be defined in the SoC specific dtsi files, because the BCM2836 includes bcm283x.dtsi too.

Be aware the patch for bcm2837 must go to ARM64.

I can not really follow:
* the node is defined in the dtsi included by all 3 soc, and it is available on all so it sits where for example spi0 or uart0 is located
* as for arm64: this describes the registers that are identical for arm and arm64 and the bcm2837.dtsi is also including ../../../../arm/boot/dts/bcm283x.dtsi

Quoted 1 line

So what is the problem?

The thermal driver specifies 3 different compatibles with partially different
settings.
If this patch is applied, all SoC (bcm2835, bcm2836, bcm2837) would use the bcm2835 settings.
I can't believe this is intended.

Quoted 7 lines
Quoted 1 line

Why does the binding contains 3 different compatibles if only one is used?

Now I understand - did not think of that: good catch!

To minimize the patch: what about setting it to 2837 by default (in 283x.dtsi) and only change compatible in 2835.dtsi and 2836.dtsi - that is 3 files changed instead of 4 or 5...

Please don't do this in order avoid to confusion. We have compatible strings for each SoC and we have dtsi files for each SoC. So i think the right way would be the following:

bcm283x.dtsi

thermal: thermal at 7e212000 {
            reg = <0x7e212000 0x8>;
            clocks = <&clocks BCM2835_CLOCK_TSENS>;
};

bcm2835.dtsi

&thermal {
            compatible = "brcm,bcm2835-thermal";
            status = "okay";
};

bcm2836.dtsi

&thermal {
            compatible = "brcm,bcm2836-thermal";
            status = "okay";
};

bcm2837.dtsi

&thermal {
            compatible = "brcm,bcm2837-thermal";
            status = "okay";
};
Quoted 12 lines

Or any other ideas how to detect which Soc we run on during runtime? I.e: query the root compatible string in the device-tree?

Just before I create a new patch set to fix that.

Martin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#10 lore raw

PATCH v4 3/4 ARM: bcm2835: add thermal node to device-tree of bcm283x

Quoted 6 lines · Stefan Wahren

bcm2837.dtsi

&thermal {
            compatible = "brcm,bcm2837-thermal";
            status = "okay";
};

Note that there is only a bcm2837.dtsi in arm64/boot/dts/broadcom/ but not in arm/boot/dts - at least with the current upstream kernel.

So I will just patch those dtsi that exist right now.

Martin

#11 lore raw

PATCH v4 3/4 ARM: bcm2835: add thermal node to device-tree of bcm283x

Am 13.09.2016 um 11:06 schrieb Martin Sperl:

Quoted 10 lines · Stefan Wahren
Quoted 6 lines

bcm2837.dtsi

&thermal {
            compatible = "brcm,bcm2837-thermal";
            status = "okay";
};
Quoted 4 lines

Note that there is only a bcm2837.dtsi in arm64/boot/dts/broadcom/ but not in arm/boot/dts - at least with the current upstream kernel.

So I will just patch those dtsi that exist right now.

That's correct as long as the bcm2837.dtsi change is a separate patch for ARM64 and this was the reason for my "warning" in my first reply.

Stefan

Quoted 2 lines

Martin