thermal: bcm2835: add thermal driver
Subsystems (5)
v5 cover thermal: bcm2835: add thermal driver
From: Martin Sperl <[email protected]>
Add a thermal driver for the TSENSE device of the bcm2835/6/7 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)
Note:
No support for 32-bit arm bcm2837, as there is no arch/arm/boot/dts/bcm2836.dtsi upstream as of now. 64-bit arm support is not tested
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)
V4 -> V5: use correct compatiblity for different soc versions in dt
support ARM64 for bcm2837 in devicetree and defconfig
Martin Sperl (6):
dt: bindings: add thermal device driver for bcm2835
thermal: bcm2835: add thermal driver for bcm2835 soc
ARM: bcm2835: dts: add thermal node to device-tree of bcm283x
ARM64: bcm2835: dts: add thermal node to device-tree of bcm2837
ARM: bcm2835: add thermal driver to default_config
ARM64: bcm2835: add thermal driver to default_config
.../bindings/thermal/brcm,bcm2835-thermal.txt | 17 ++ arch/arm/boot/dts/bcm2835.dtsi | 6 + arch/arm/boot/dts/bcm2836.dtsi | 6 + arch/arm/boot/dts/bcm283x.dtsi | 7 + arch/arm/configs/bcm2835_defconfig | 2 + arch/arm64/boot/dts/broadcom/bcm2837.dtsi | 6 + arch/arm64/configs/defconfig | 1 + drivers/thermal/Kconfig | 5 + drivers/thermal/Makefile | 1 + drivers/thermal/bcm2835_thermal.c | 327 +++++++++++++++++++++ 10 files changed, 378 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/brcm,bcm2835-thermal.txt create mode 100644 drivers/thermal/bcm2835_thermal.c
--
2.1.4
PATCH v5 1/6 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
@@ -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
PATCH v5 2/6 thermal: bcm2835: add thermal driver for bcm2835 soc
In reply to kernel at martin.sperl.orgFrom: 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)
V2 -> V4: moved 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
@@ -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
@@ -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
Signature · 1 line
2.1.4
PATCH v5 2/6 thermal: bcm2835: add thermal driver for bcm2835 soc
Quoted 9 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.
Signed-off-by Martin Sperl <[email protected]>
Quoted 9 lines
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 inclk-bcm2835.c)
V2 -> V4: moved back to thermal (not using bcm sub-directory)
set polling interval to 1second (was 0ms, so interrupt driven)
This is still:
-------------- 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/20160914/703cb871/attachment.sig>
PATCH v5 2/6 thermal: bcm2835: add thermal driver for bcm2835 soc
In reply to kernel at martin.sperl.orgHi Martin,
Quoted 34 lines
kernel at martin.sperl.org hat am 13. September 2016 um 11:34 geschrieben:
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.
Signed-off-by Martin Sperl <[email protected]>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 inclk-bcm2835.c)
V2 -> V4: moved 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.cdrivers/thermal/Kconfig +0
-0
drivers/thermal/Kconfig config GENERIC_ADC_THERMAL · line 403
Quoted 5 lines
drivers/thermal/Kconfig +2
-0@@ -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"
i'm not sure if "depends on ARCH_BCM2835 || COMPILE_TEST" is necessary here, but the following is:
depends on OF
depends on HAS_IOMEM
Quoted 15 lines
drivers/thermal/Kconfig +3
-0+ help + Support for thermal sensors on Broadcom bcm2835 SoCs. + endifdrivers/thermal/Makefile +2
-0@@ -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/Makefile obj-$(CONFIG_TEGRA_SOCTHERM) += tegra/
Quoted 10 lines
drivers/thermal/Makefile +10
-0+static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz, + int *temp) +{ + struct bcm2835_thermal_data *data = tz->devdata; + u32 val = readl(data->regs + BCM2835_TS_TSENSSTAT); + + if (!(val & BCM2835_TS_TSENSSTAT_VALID)) + return -EIO; + + /* mask the relevant bits */
I think this is obvious and could be removed.
Quoted 20 lines
drivers/thermal/Makefile +19
-0+ val &= BCM2835_TS_TSENSSTAT_DATA_MASK; + + *temp = bcm2835_thermal_adc2temp(data->info, val); + + return 0; +} + +static const struct of_device_id bcm2835_thermal_of_match_table[]; +static int bcm2835_thermal_probe(struct platform_device *pdev) +{ + const struct of_device_id *match; + struct thermal_zone_device *tz; + struct bcm2835_thermal_data *data; + struct resource *res; + int err; + u32 val; + unsigned long rate; + + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
drivers/thermal/Makefile
Quoted 10 lines
drivers/thermal/Makefile +10
-0+ if (!data) + return -ENOMEM; + + match = of_match_device(bcm2835_thermal_of_match_table, + &pdev->dev); + if (!match) + return -EINVAL; + data->info = match->data; + + /* get registers */
ditto
drivers/thermal/Makefile
Quoted 9 lines
drivers/thermal/Makefile +9
-0+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + data->regs = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(data->regs)) { + err = PTR_ERR(data->regs); + dev_err(&pdev->dev, "Could not get registers: %d\n", err); + return err; + } + + /* get clock */
ditto
Quoted 5 lines
drivers/thermal/Makefile +5
-0+ data->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(data->clk)) { + err = PTR_ERR(data->clk); + if (err != -EPROBE_DEFER) + dev_err(&pdev->dev, "Could not get clk: %d\n", err);
drivers/thermal/Makefile
Quoted 10 lines
drivers/thermal/Makefile +10
-0+ return err; + } + + /* set up registers if not already done by the fw */ + val = readl(data->regs + BCM2835_TS_TSENSCTL); + if (!(val & BCM2835_TS_TSENSCTL_RSTB)) { + /* the basic required flags */ + val = (BCM2835_TS_TSENSCTL_CTRL_DEFAULT << + BCM2835_TS_TSENSCTL_CTRL_SHIFT) | + BCM2835_TS_TSENSCTL_REGULEN;
The comment above isn't helpful. Could you please write down the intension behind this bit operation?
drivers/thermal/Makefile
Quoted 2 lines
drivers/thermal/Makefile +2
-0+ + /* reset delay */
What is the unit of the delay (seconds, 1/10 seconds)?
drivers/thermal/Makefile
Quoted 1 line
drivers/thermal/Makefile +1
-0+ val |= (BCM2835_TS_TSENSCTL_RSTDELAY_DEFAULT <<
Instead of hiding the value behind a define, please use the number directly and remove this define.
Quoted 5 lines
drivers/thermal/Makefile +5
-0+ BCM2835_TS_TSENSCTL_RSTDELAY_SHIFT); + + /* trip_adc value from info */ + val |= bcm2835_thermal_temp2adc(data->info, + data->info->trip_temp) <<
drivers/thermal/Makefile
Quoted 10 lines
drivers/thermal/Makefile +10
-0+ BCM2835_TS_TSENSCTL_THOLD_SHIFT; + + /* write the value back to the register as 2 steps */ + writel(val, data->regs + BCM2835_TS_TSENSCTL); + val |= BCM2835_TS_TSENSCTL_RSTB; + writel(val, data->regs + BCM2835_TS_TSENSCTL); + } + + /* enable clock and check rate */ + clk_prepare_enable(data->clk);
This could fail. So please check the result and move this call before the register set up.
drivers/thermal/Makefile
Quoted 6 lines
drivers/thermal/Makefile +4
-0+ rate = clk_get_rate(data->clk); + if ((rate < 1920000) || (rate > 5000000)) { + dev_warn(&pdev->dev, + "Clock %pCn is running at %pCr Hz, which is outside the recommended rangeof 1.9 to 5.0 MHz\n",
drivers/thermal/Makefile +1
-0+ data->clk, data->clk);
Instead of printing the clock name twice your intension would be to print the actual clock rate?
Btw the message is very long. Could you please shorten it and make the lower limit more precise 1.92 MHz?
Quoted 21 lines
drivers/thermal/Makefile +21
-0+ } + + /* register thermal zone with 1 trip point an 1s polling */ + tz = thermal_zone_device_register("bcm2835_thermal", + 1, 0, data, + &bcm2835_thermal_ops, + NULL, + 0, 1000); + if (IS_ERR(tz)) { + clk_disable_unprepare(data->clk); + err = PTR_ERR(tz); + dev_err(&pdev->dev, + "Failed to register the thermal device: %d\n", + err); + return err; + } + + platform_set_drvdata(pdev, tz); + + bcm2835_thermal_debugfs(pdev); +
drivers/thermal/Makefile
Quoted 10 lines
drivers/thermal/Makefile +10
-0+ return 0; +} + +static int bcm2835_thermal_remove(struct platform_device *pdev) +{ + struct thermal_zone_device *tz = platform_get_drvdata(pdev); + struct bcm2835_thermal_data *data = tz->devdata; + + debugfs_remove_recursive(data->debugfsdir); + thermal_zone_device_unregister(tz);
clk_disable_unprepare(data->clk)
drivers/thermal/Makefile
Quoted 11 lines
drivers/thermal/Makefile +11
-0+ + return 0; +} + +static const struct of_device_id bcm2835_thermal_of_match_table[] = { + { + .compatible = "brcm,bcm2835-thermal", + .data = &(struct bcm2835_thermal_info) { + .offset = 407000, + .slope = -538, + .trip_temp = 80000
Since the operating temperature of the bcm2835 is only available in the Foundation FAQ. I would suggest to add the recommenend operating temperature range ( -40 C to +85 C ) here as a comment.
Thanks
Stefan
PATCH v5 2/6 thermal: bcm2835: add thermal driver for bcm2835 soc
Hi Stefan!
Quoted 11 lines · Stefan Wahren
drivers/thermal/bcm2835_thermal.c line 249
Quoted 7 lines
drivers/thermal/bcm2835_thermal.c new file +4
-0+ rate =clk_get_rate (data->clk); +if ((rate <1920000 ) || (rate >5000000 )) { + dev_warn(&pdev->dev, + "Clock %pCn is running at %pCr Hz, which is outside the recommended rangeof 1.9 to 5.0 MHz\n",
drivers/thermal/bcm2835_thermal.c new file +1
-0+ data->clk, data->clk);Instead of printing the clock name twice your intension would be to print the actual clock rate?
%pCn (and %pC) prints the clock name
%pCr prints the clock rate - I guess I could use ?%lu? and rate instead
So I do not see an issue here - I will reword the text to shorten it.
Everything else I will fix as mentioned.
Martin
PATCH v5 3/6 ARM: bcm2835: dts: add thermal node to device-tree of bcm283x
In reply to kernel at martin.sperl.orgFrom: Martin Sperl <[email protected]>
Add the node for the thermal sensor of the bcm2835-soc to the device tree.
Changelog:
V1 -> V5: generic settings is shared in bcm283x.dtsi, but disabled
moved the compatible string to the SOC specific dtsi
for arm and arm64
Note: there is no arm/boot/dts/bcm2837.dtsi as of now,
so there is no support for bcm2837 in 32 bit mode.
--- arch/arm/boot/dts/bcm2835.dtsi | 6 ++++++ arch/arm/boot/dts/bcm2836.dtsi | 6 ++++++ arch/arm/boot/dts/bcm283x.dtsi | 7 +++++++ 3 files changed, 19 insertions(+)
arch/arm/boot/dts/bcm2835.dtsi +6 -0
@@ -23,3 +23,9 @@ }; }; }; + +/* enable thermal sensor with the correct compatible property set */ +&thermal { + compatible = "brcm,bcm2835-thermal"; + status = "okay"; +};
arch/arm/boot/dts/bcm2836.dtsi +6 -0
@@ -76,3 +76,9 @@ interrupt-parent = <&local_intc>; interrupts = <8>; }; + +/* enable thermal sensor with the correct compatible property set */ +&thermal { + compatible = "brcm,bcm2836-thermal"; + status = "okay"; +};
arch/arm/boot/dts/bcm283x.dtsi +7 -0
@@ -186,6 +186,13 @@ interrupts = <2 14>; /* pwa1 */ }; + thermal: thermal at 0x7e212000 { + compatible = "brcm,bcm2835-thermal"; + reg = <0x7e212000 0x8>; + clocks = <&clocks BCM2835_CLOCK_TSENS>; + status = "disabled"; + }; + aux: aux at 0x7e215000 { compatible = "brcm,bcm2835-aux"; #clock-cells = <1>;
--
2.1.4
PATCH v5 3/6 ARM: bcm2835: dts: add thermal node to device-tree of bcm283x
Quoted 56 lines
kernel at martin.sperl.org hat am 13. September 2016 um 11:34 geschrieben:
From: Martin Sperl <[email protected]>
Add the node for the thermal sensor of the bcm2835-soc to the device tree.
Signed-off-by Martin Sperl <[email protected]>Changelog:
V1 -> V5: generic settings is shared inbcm283x.dtsi, but disabled
moved the compatible string to the SOC specific dtsi
for arm and arm64Note: there is no
arm/boot/dts/bcm2837.dtsias of now,
so there is no support for bcm2837 in 32 bit mode.--- arch/arm/boot/dts/bcm2835.dtsi | 6 ++++++ arch/arm/boot/dts/bcm2836.dtsi | 6 ++++++ arch/arm/boot/dts/bcm283x.dtsi | 7 +++++++ 3 files changed, 19 insertions(+)arch/arm/boot/dts/bcm2835.dtsi +6
-0@@ -23,3 +23,9 @@ }; }; }; + +/* enable thermal sensor with the correct compatible property set */ +&thermal { + compatible = "brcm,bcm2835-thermal"; + status = "okay"; +};arch/arm/boot/dts/bcm2836.dtsi +6
-0@@ -76,3 +76,9 @@ interrupt-parent = <&local_intc>; interrupts = <8>; }; + +/* enable thermal sensor with the correct compatible property set */ +&thermal { + compatible = "brcm,bcm2836-thermal"; + status = "okay"; +};arch/arm/boot/dts/bcm283x.dtsi +0
-0
arch/arm/boot/dts/bcm283x.dtsi line 189
Quoted 4 lines
arch/arm/boot/dts/bcm283x.dtsi +1
-0@@ -186,6 +186,13 @@ interrupts = <2 14>; /* pwa1 */ }; + thermal: thermal at 0x7e212000 {
After removing 0x here like in the binding doc you can add:
Quoted 16 lines
arch/arm/boot/dts/bcm283x.dtsi +6
-1+ compatible = "brcm,bcm2835-thermal"; + reg = <0x7e212000 0x8>; + clocks = <&clocks BCM2835_CLOCK_TSENS>; + status = "disabled"; + }; + aux: aux at 0x7e215000 { compatible = "brcm,bcm2835-aux"; #clock-cells = <1>; --2.1.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 4/6 ARM64: bcm2835: dts: add thermal node to device-tree of bcm2837
In reply to kernel at martin.sperl.orgFrom: Martin Sperl <[email protected]>
Add the node for the thermal sensor of the bcm2837-soc to the device tree.
--- arch/arm64/boot/dts/broadcom/bcm2837.dtsi | 6 ++++++ 1 file changed, 6 insertions(+)
Note: untested as I have no 64 bit test system.
arch/arm64/boot/dts/broadcom/bcm2837.dtsi +6 -0
@@ -74,3 +74,9 @@ interrupt-parent = <&local_intc>; interrupts = <8>; }; + +/* enable thermal sensor with the correct compatible property set */ +&thermal { + compatible = "brcm,bcm2837-thermal"; + status = "okay"; +};
--
2.1.4
PATCH v5 5/6 ARM: bcm2835: add thermal driver to default_config
In reply to kernel at martin.sperl.orgFrom: 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
@@ -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
PATCH v5 6/6 ARM64: bcm2835: add thermal driver to default_config
In reply to kernel at martin.sperl.orgFrom: Martin Sperl <[email protected]>
Add the thermal driver for bcm2837 to list of compiled modules in the default config.
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
Note: untested as I have no 64 bit test system.
arch/arm64/configs/defconfig +1 -0
@@ -252,6 +252,7 @@ CONFIG_SENSORS_INA2XX=m CONFIG_SENSORS_ARM_SCPI=y CONFIG_THERMAL=y CONFIG_THERMAL_EMULATION=y +CONFIG_BCM2835_THERMAL=y CONFIG_EXYNOS_THERMAL=y CONFIG_WATCHDOG=y CONFIG_RENESAS_WDT=y
--
2.1.4