Skip to contentSkip to conversation

thermal: add brcmstb AVS TMON driver

PATCH Superseded Markus Mayer 3 participants 9 messages Jun 5, 2017 – Jun 9, 2017

Subsystems (4)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover thermal: add brcmstb AVS TMON driver

From: Markus Mayer <[email protected]>

This series adds the brcmstb AVS TMON driver.

The driver was originally written by Brian Norris. I ported it to Linux 4.12-rc1. The series also applies to linux-next as of 20170605.

Brian Norris (2):
Documentation: devicetree: add binding for Broadcom STB AVS TMON
thermal: add brcmstb AVS TMON driver

 .../devicetree/bindings/thermal/brcm,avs-tmon.txt  |  20 ++
 MAINTAINERS                                        |   8 +
 drivers/thermal/broadcom/Kconfig                   |   7 +
 drivers/thermal/broadcom/Makefile                  |   1 +
 drivers/thermal/broadcom/brcmstb_thermal.c         | 361 +++++++++++++++++++++
 5 files changed, 397 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt
 create mode 100644 drivers/thermal/broadcom/brcmstb_thermal.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 Documentation: devicetree: add binding for Broadcom STB AVS TMON

From: Brian Norris <[email protected]>

Add binding for Broadcom STB thermal.

---
 .../devicetree/bindings/thermal/brcm,avs-tmon.txt    | 20 ++++++++++++++++++++
 MAINTAINERS                                          |  8 ++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt
Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt new file +20 -0
new file mode 100644
index 0000000..a538a1b
@@ -0,0 +1,20 @@
+* Broadcom STB thermal management
+
+Thermal management core, provided by the AVS TMON hardware block.
+
+Required properties:
+- compatible: must be one of "brcm,avs-tmon" or "brcm,avs-tmon-bcm7445"
+- reg: address range for the AVS TMON registers
+- interrupts: temperature monitor interrupt, for high/low threshold triggers
+- interrupt-names: should be "tmon"
+- interrupt-parent: the parent interrupt controller
+
+Example:
+
+	thermal at f04d1500 {
+		compatible = "brcm,avs-tmon-bcm7445", "brcm,avs-tmon";
+		reg = <0xf04d1500 0x28>;
+		interrupts = <0x6>;
+		interrupt-names = "tmon";
+		interrupt-parent = <&avs_host_l2_intc>;
+	};
MAINTAINERS +8 -0
index f7d568b..68ee972 100644
@@ -2864,6 +2864,14 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/cpufreq/brcm,stb-avs-cpu-freq.txt
 F:	drivers/cpufreq/brcmstb*
 
+BROADCOM STB AVS TMON DRIVER
+M:	Markus Mayer <[email protected]>
+M:	bcm-kernel-feedback-list at broadcom.com
+L:	linux-pm at vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt
+F:	drivers/thermal/broadcom/brcmstb*
+
 BROADCOM SPECIFIC AMBA DRIVER (BCMA)
 M:	Rafa? Mi?ecki <[email protected]>
 L:	linux-wireless at vger.kernel.org
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/2] Documentation: devicetree: add binding for Broadcom STB AVS TMON

Quoted 10 lines · Markus Mayer
Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt new file +6 -0
@@ -0,0 +1,20 @@
+* Broadcom STB thermal management
+
+Thermal management core, provided by the AVS TMON hardware block.
+
+Required properties:
+- compatible: must be one of "brcm,avs-tmon" or 

"brcm,avs-tmon-bcm7445"

Is the "one of" correct here? I'm not native English but it sounds like setting both is a wrong thing.

Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt line 15

Quoted 10 lines
+- reg: address range for the AVS TMON registers
+- interrupts: temperature monitor interrupt, for high/low threshold 
triggers
+- interrupt-names: should be "tmon"
+- interrupt-parent: the parent interrupt controller
Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt new file +5 -0
+
+Example:
+
+	thermal at f04d1500 {
+		compatible = "brcm,avs-tmon-bcm7445", "brcm,avs-tmon";

Yet here you use both bindings.

#3 lore raw

Re: [PATCH 1/2] Documentation: devicetree: add binding for Broadcom STB AVS TMON

Quoted 15 lines · Rafa? Mi?ecki

Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt line 6

Quoted 10 lines · Markus Mayer
Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt new file +6 -0
@@ -0,0 +1,20 @@
+* Broadcom STB thermal management
+
+Thermal management core, provided by the AVS TMON hardware block.
+
+Required properties:
+- compatible: must be one of "brcm,avs-tmon" or "brcm,avs-tmon-bcm7445"

Is the "one of" correct here? I'm not native English but it sounds like setting both is a wrong thing.

You are right. It should not say "one of". I'll fix the wording.

Quoted 13 lines

Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt line 15

Quoted 10 lines
Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt new file +2 -0
+- reg: address range for the AVS TMON registers
+- interrupts: temperature monitor interrupt, for high/low threshold

triggers

+- interrupt-names: should be "tmon"
+- interrupt-parent: the parent interrupt controller
Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt new file +5 -0
+
+Example:
+
+       thermal at f04d1500 {
+               compatible = "brcm,avs-tmon-bcm7445", "brcm,avs-tmon";

Yet here you use both bindings.

#4 lore raw

PATCH 2/2 thermal: add brcmstb AVS TMON driver

In reply to Markus Mayer

From: Brian Norris <[email protected]>

The AVS TMON core provides temperature readings, a pair of configurable high- and low-temperature threshold interrupts, and an emergency over-temperature chip reset. The driver utilizes the first two to provide temperature readings and high-temperature notifications to applications. The over-temperature reset is not exposed to applications; this reset threshold is critical to the system and should be set with care within the bootloader.

Applications may choose to utilize the notification mechanism, the temperature reading mechanism (e.g., through polling), or both.

---
 drivers/thermal/broadcom/Kconfig           |   7 +
 drivers/thermal/broadcom/Makefile          |   1 +
 drivers/thermal/broadcom/brcmstb_thermal.c | 361 +++++++++++++++++++++++++++++
 3 files changed, 369 insertions(+)
 create mode 100644 drivers/thermal/broadcom/brcmstb_thermal.c
drivers/thermal/broadcom/Kconfig +7 -0
index ab08af4..12e621d 100644
@@ -6,6 +6,13 @@ config BCM2835_THERMAL
 	help
 	  Support for thermal sensors on Broadcom bcm2835 SoCs.
 
+config BRCMSTB_THERMAL
+	tristate "Broadcom STB AVS TMON thermal driver"
+	depends on ARCH_BRCMSTB || COMPILE_TEST
+	help
+	  Enable this driver if you have a Broadcom STB SoC and would like
+	  thermal framework support.
+
 config BCM_NS_THERMAL
 	tristate "Northstar thermal driver"
 	depends on ARCH_BCM_IPROC || COMPILE_TEST
drivers/thermal/broadcom/Makefile +1 -0
index c6f62e4..fae10ec 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_BCM2835_THERMAL)		+= bcm2835_thermal.o
+obj-$(CONFIG_BRCMSTB_THERMAL)		+= brcmstb_thermal.o
 obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/brcmstb_thermal.c new file +361 -0

361 lines not on this page · raw message

Signature · 1 line
2.7.4
#5 lore raw

[PATCH] thermal: fix platform_no_drv_owner.cocci warnings

drivers/thermal/broadcom/brcmstb_thermal.c:353:3-8: No need to set .owner here. The core will do it.

drivers/thermal/broadcom/brcmstb_thermal.c:353:3-8: No need to set .owner here. The core will do it.

Remove .owner field if calls are used which set it automatically

Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci

---

 brcmstb_thermal.c |    1 -
 1 file changed, 1 deletion(-)
drivers/thermal/broadcom/brcmstb_thermal.c +0 -1
@@ -350,7 +350,6 @@ static struct platform_driver brcmstb_th
 	.remove = brcmstb_thermal_exit,
 	.driver = {
 		.name = DRV_NAME,
-		.owner = THIS_MODULE,
 		.of_match_table = brcmstb_thermal_id_table,
 	},
 };
#6 lore raw
In reply to Markus Mayer
coccinelle warnings: (new ones prefixed by >>)

Hi Brian,

[auto build test WARNING on thermal/next]
[also build test WARNING on v4.12-rc4 next-20170606]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Markus-Mayer/Documentation-devicetree-add-binding-for-Broadcom-STB-AVS-TMON/20170606-133113
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git next

coccinelle warnings: (new ones prefixed by >>)

>> drivers/thermal/broadcom/brcmstb_thermal.c:353:3-8: No need to set .owner here. The core will do it.

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#7 lore raw
In reply to Markus Mayer
Quoted 11 lines · Markus Mayer
drivers/thermal/broadcom/brcmstb_thermal.c new file +7 -0
@@ -0,0 +1,361 @@
+/*
+ * Broadcom STB AVS TMON thermal sensor driver
+ *
+ * Copyright (c) 2015-2017 Broadcom
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, 

and

Quoted 8 lines

+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

The headers says GPL v2 but it doesn't match MODULE_LICENSE. Please be consistent.

drivers/thermal/broadcom/brcmstb_thermal.c line 115

Quoted 5 lines
drivers/thermal/broadcom/brcmstb_thermal.c new file +5 -0
+/* Convert a HW code to a temperature reading (millidegree celsius) */
+static inline int avs_tmon_code_to_temp(u32 code)
+{
+	return (410040 - (int)((code & 0x3FF) * 487));
+}

I got similar hardcoded values and Eduardo told me to move them to the DT.
See discussion in: https://patchwork.kernel.org/patch/9642119/

Hint: thermal_zone_get_offset + thermal_zone_get_slope

#8 lore raw
Quoted 15 lines · Rafa? Mi?ecki
Quoted 14 lines · Markus Mayer
drivers/thermal/broadcom/brcmstb_thermal.c new file +10 -0
@@ -0,0 +1,361 @@
+/*
+ * Broadcom STB AVS TMON thermal sensor driver
+ *
+ * Copyright (c) 2015-2017 Broadcom
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
Quoted 8 lines

drivers/thermal/broadcom/brcmstb_thermal.c line 15

Quoted 5 lines
drivers/thermal/broadcom/brcmstb_thermal.c new file +5 -0
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

The headers says GPL v2 but it doesn't match MODULE_LICENSE. Please be consistent.

Fixed.

Quoted 10 lines

drivers/thermal/broadcom/brcmstb_thermal.c line 115

Quoted 5 lines
drivers/thermal/broadcom/brcmstb_thermal.c new file +5 -0
+/* Convert a HW code to a temperature reading (millidegree celsius) */
+static inline int avs_tmon_code_to_temp(u32 code)
+{
+       return (410040 - (int)((code & 0x3FF) * 487));
+}

I got similar hardcoded values and Eduardo told me to move them to the DT. See discussion in: https://patchwork.kernel.org/patch/9642119/

Hint: thermal_zone_get_offset + thermal_zone_get_slope

I implemented this and played around a little bit, and I believe I found a problem with how the framework is initializing the thermal zone. Please bear with my while I try to describe the issue I ran into:

In brcmstb_thermal_probe(), we call

    struct thermal_zone_device *thermal;
    [...]
    thermal = thermal_zone_of_sensor_register(&pdev->dev, 0, priv, &of_ops);

to get the thermal zone for the driver. This is necessary for thermal_zone_get_offset() and thermal_zone_get_slope() to be able to return the proper coefficients, as the thermal zone pointer needs to be passed to both functions.

Now, calling thermal_zone_of_sensor_register() has some side effects that call thermal_zone_get_slope () and thermal_zone_get_offset() via callback function before the "thermal" pointer is assigned, because thermal_zone_of_sensor_register() hasn't returned to the caller yet. Specifically, this call sequence happens:

thermal_zone_of_sensor_register() -> tzd->ops->set_mode [which is of_thermal_set_mode()] -> thermal_zone_device_update() -> update_temperature() -> thermal_zone_get_temp() -> tz->ops->get_temp() [which is brcmstb_get_temp()] -> avs_tmon_code_to_temp() -> avs_tmon_get_coeffs() -> thermal_zone_get_slope() -> *UNDESIRED RESULT*

This is problematic, because thermal_zone_get_slope() is now being called while our thermal pointer inside the driver is still NULL, so it returns its default value of 1 and *NOT* the value that is stored in device tree. The same happens for thermal_zone_get_offset(). This returns the default value of 0.

thermal_zone_get_temp() also calls thermal_zone_set_trips() right after thermal_zone_get_temp(). That call path runs into the exact same issue.

It is only after the call to thermal_zone_of_sensor_register() completes that the "thermal" variable in the driver has the proper value and, thus, thermal_zone_get_temp() and thermal_zone_set_trips() return the device tree values from then on out.

At run time, it looks like this (with some debug output enabled):

[    1.251126] brcmstb_thermal: avs_tmon_code_to_temp, 170: val=773/0x305
[    1.257676] brcmstb_thermal: avs_tmon_get_coeffs, 135: slope=1,
offset=0, tz=  (null)
[    1.265534] brcmstb_thermal: set trips -2147483647 <--> 95000
[    1.271297] brcmstb_thermal: set temp 0 to -2147483647
[    1.276452] brcmstb_thermal: avs_tmon_temp_to_code, 191: temp=-2147483647
[    1.283257] brcmstb_thermal: avs_tmon_set_trip_temp, 276: val=1023
[    1.289457] brcmstb_thermal: enable trip, type 0
[    1.294089] brcmstb_thermal: set temp 1 to 95000
[    1.298721] brcmstb_thermal: avs_tmon_temp_to_code, 191: temp=95000
[    1.305006] brcmstb_thermal: avs_tmon_get_coeffs, 135: slope=1,
offset=0, tz=  (null)
[    1.312859] brcmstb_thermal: avs_tmon_set_trip_temp, 276: val=0
[    1.318797] brcmstb_thermal: enable trip, type 1

Finally inititialization has progressed far enough that our tz pointer is not NULL anymore, and now it returns the proper values:

[    1.323470] brcmstb_thermal: avs_tmon_get_coeffs, 135: slope=-487,

offset=410040, tz=eeb55800

It doesn't seem right to me that the framework calls back into the driver before the driver has had a chance to initialize all data structures it needs. Am I missing anything obvious here that would avoid this issue?

Thanks,
-Markus