* [PATCH 0/4] bcm2835: add thermal driver
@ 2016-05-12 14:35 kernel
2016-05-12 14:35 ` [PATCH 1/4] dt: bindings: add thermal device driver for bcm2835 kernel
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: kernel @ 2016-05-12 14:35 UTC (permalink / raw)
To: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Eric Anholt,
Russell King, linux-pm, devicetree, linux-rpi-kernel,
linux-arm-kernel
Cc: Martin Sperl
From: Martin Sperl <kernel@martin.sperl.org>
Add thermal driver for the bcm2835 SOC.
Right now this driver does not set up the thermal device
itself, but relies on the fact that the firmware is setting
the device up correctly.
Also it is currently only reading from the register-set.
The driver also exposes the registers via debugfs.
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/bcm2835-thermal.txt | 16 ++
arch/arm/boot/dts/bcm283x.dtsi | 6 +
arch/arm/configs/bcm2835_defconfig | 2 +
drivers/thermal/Kconfig | 5 +
drivers/thermal/Makefile | 1 +
drivers/thermal/bcm/Kconfig | 4 +
drivers/thermal/bcm/Makefile | 1 +
drivers/thermal/bcm/bcm2835_thermal.c | 205 +++++++++++++++++++++
8 files changed, 240 insertions(+)
create mode 100644 Documentation/devicetree/bindings/thermal/bcm2835-thermal.txt
create mode 100644 drivers/thermal/bcm/Kconfig
create mode 100644 drivers/thermal/bcm/Makefile
create mode 100644 drivers/thermal/bcm/bcm2835_thermal.c
--
2.1.4
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/4] dt: bindings: add thermal device driver for bcm2835
2016-05-12 14:35 [PATCH 0/4] bcm2835: add thermal driver kernel
@ 2016-05-12 14:35 ` kernel
[not found] ` <1463063738-11506-2-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-12 14:35 ` [PATCH 3/4] ARM: bcm2835: add thermal node to device-tree of bcm283x kernel
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: kernel @ 2016-05-12 14:35 UTC (permalink / raw)
To: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Eric Anholt,
Russell King, linux-pm, devicetree, linux-rpi-kernel,
linux-arm-kernel
Cc: Martin Sperl
From: Martin Sperl <kernel@martin.sperl.org>
Add documentation for bcm2835 SOC thermal sensor.
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
---
.../devicetree/bindings/thermal/bcm2835-thermal.txt | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 Documentation/devicetree/bindings/thermal/bcm2835-thermal.txt
diff --git a/Documentation/devicetree/bindings/thermal/bcm2835-thermal.txt b/Documentation/devicetree/bindings/thermal/bcm2835-thermal.txt
new file mode 100644
index 0000000..607519a
--- /dev/null
+++ b/Documentation/devicetree/bindings/thermal/bcm2835-thermal.txt
@@ -0,0 +1,16 @@
+Binding for Thermal Sensor driver for BCM2835 SoCs.
+
+Required parameters:
+-------------------
+
+compatible : should be: "brcm,bcm2835-thermal"
+reg : Address range of the thermal registers.
+clocks : Phandle of the clock used by the thermal sensor.
+
+Example:
+
+thermal: thermal@0x7e212000 {
+ compatible = "brcm,bcm2835-thermal";
+ reg = <0x7e212000 0x8>;
+ clocks = <&clocks BCM2835_CLOCK_TSENS>;
+};
--
2.1.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/4] thermal: bcm2835: add thermal driver for bcm2835 soc
[not found] ` <1463063738-11506-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
@ 2016-05-12 14:35 ` kernel-TqfNSX0MhmxHKSADF0wUEw
[not found] ` <1463063738-11506-3-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-12 22:58 ` [PATCH 0/4] bcm2835: add thermal driver Eric Anholt
1 sibling, 1 reply; 11+ messages in thread
From: kernel-TqfNSX0MhmxHKSADF0wUEw @ 2016-05-12 14:35 UTC (permalink / raw)
To: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Eric Anholt,
Russell King, linux-pm-u79uwXL29TY76Z2rM5mHXA,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: Martin Sperl
From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
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 <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
---
drivers/thermal/Kconfig | 5 +
drivers/thermal/Makefile | 1 +
drivers/thermal/bcm/Kconfig | 4 +
drivers/thermal/bcm/Makefile | 1 +
drivers/thermal/bcm/bcm2835_thermal.c | 205 ++++++++++++++++++++++++++++++++++
5 files changed, 216 insertions(+)
create mode 100644 drivers/thermal/bcm/Kconfig
create mode 100644 drivers/thermal/bcm/Makefile
create mode 100644 drivers/thermal/bcm/bcm2835_thermal.c
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index c37eedc..10f92c6 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -381,6 +381,11 @@ config MTK_THERMAL
Enable this option if you want to have support for thermal management
controller present in Mediatek SoCs
+menu "Broadcom thermal drivers"
+depends on ARCH_BCM || COMPILE_TEST
+source "drivers/thermal/bcm/Kconfig"
+endmenu
+
menu "Texas Instruments thermal drivers"
depends on ARCH_HAS_BANDGAP || COMPILE_TEST
depends on HAS_IOMEM
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 8e9cbc3..6df1aa3 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -49,3 +49,4 @@ obj-$(CONFIG_ST_THERMAL) += st/
obj-$(CONFIG_TEGRA_SOCTHERM) += tegra_soctherm.o
obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o
obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o
+obj-y += bcm/
diff --git a/drivers/thermal/bcm/Kconfig b/drivers/thermal/bcm/Kconfig
new file mode 100644
index 0000000..62245ae
--- /dev/null
+++ b/drivers/thermal/bcm/Kconfig
@@ -0,0 +1,4 @@
+config BCM2835_THERMAL
+ tristate "Thermal sensors on bcm2835 SoC"
+ help
+ Support for thermal sensors on Broadcom bcm2835 SoCs.
diff --git a/drivers/thermal/bcm/Makefile b/drivers/thermal/bcm/Makefile
new file mode 100644
index 0000000..13456d2
--- /dev/null
+++ b/drivers/thermal/bcm/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM2835_THERMAL) := bcm2835_thermal.o
diff --git a/drivers/thermal/bcm/bcm2835_thermal.c b/drivers/thermal/bcm/bcm2835_thermal.c
new file mode 100644
index 0000000..a1fdc84
--- /dev/null
+++ b/drivers/thermal/bcm/bcm2835_thermal.c
@@ -0,0 +1,205 @@
+/*
+ * Driver for Broadcom BCM2835 soc temperature sensor
+ *
+ * Copyright (C) 2015 Martin Sperl
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ */
+
+#include <linux/clk.h>
+#include <linux/debugfs.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define BCM2835_TS_TSENSCTL 0x00
+#define BCM2835_TS_TSENSSTAT 0x04
+
+#define BCM2835_TS_TSENSCTL_PRWDW BIT(0)
+#define BCM2835_TS_TSENSCTL_RSTB BIT(1)
+#define BCM2835_TS_TSENSCTL_CTRL BIT(0)
+#define BCM2835_TS_TSENSCTL_EN_INT BIT(0)
+#define BCM2835_TS_TSENSCTL_DIRECT BIT(0)
+#define BCM2835_TS_TSENSCTL_CLR_INT BIT(0)
+#define BCM2835_TS_TSENSCTL_THOLD_SHIFT 8
+#define BCM2835_TS_TSENSCTL_THOLD_BITS 10
+#define BCM2835_TS_TSENSCTL_THOLD_MASK \
+ GENMASK(BCM2835_TS_TSENSCTL_THOLD_BITS + \
+ BCM2835_TS_TSENSCTL_THOLD_SHIFT - 1, \
+ BCM2835_TS_TSENSCTL_THOLD_SHIFT)
+#define BCM2835_TS_TSENSCTL_RSTDELAY_SHIFT 18
+#define BCM2835_TS_TSENSCTL_RSTDELAY_BITS 8
+#define BCM2835_TS_TSENSCTL_REGULEN BIT(26)
+
+#define BCM2835_TS_TSENSSTAT_DATA_BITS 10
+#define BCM2835_TS_TSENSSTAT_DATA_SHIFT 0
+#define BCM2835_TS_TSENSSTAT_DATA_MASK \
+ GENMASK(BCM2835_TS_TSENSSTAT_DATA_BITS + \
+ BCM2835_TS_TSENSSTAT_DATA_SHIFT - 1, \
+ BCM2835_TS_TSENSSTAT_DATA_SHIFT)
+#define BCM2835_TS_TSENSSTAT_VALID BIT(10)
+#define BCM2835_TS_TSENSSTAT_INTERRUPT BIT(11)
+
+/* empirical linear approximation for conversion to temperature */
+#define BCM2835_TS_VALUE_OFFSET 407000
+#define BCM2835_TS_VALUE_SLOPE -538
+
+struct bcm2835_thermal_data {
+ void __iomem *regs;
+ struct clk *clk;
+ struct dentry *debugfsdir;
+};
+
+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);
+
+ /* mask the relevant bits */
+ val &= BCM2835_TS_TSENSSTAT_DATA_MASK;
+
+ /* linear approximation */
+ *temp = BCM2835_TS_VALUE_OFFSET +
+ (val * BCM2835_TS_VALUE_SLOPE);
+
+ return 0;
+}
+
+static const struct debugfs_reg32 bcm2835_thermal_regs[] = {
+ {
+ .name = "ctl",
+ .offset = 0
+ },
+ {
+ .name = "stat",
+ .offset = 4
+ }
+};
+
+static void bcm2835_thermal_debugfs(struct platform_device *pdev)
+{
+ struct thermal_zone_device *tz = platform_get_drvdata(pdev);
+ struct bcm2835_thermal_data *data = tz->devdata;
+ struct debugfs_regset32 *regset;
+
+ data->debugfsdir = debugfs_create_dir("bcm2835_thermal", NULL);
+ if (!data->debugfsdir)
+ return;
+
+ regset = devm_kzalloc(&pdev->dev, sizeof(*regset), GFP_KERNEL);
+ if (!regset)
+ return;
+
+ regset->regs = bcm2835_thermal_regs;
+ regset->nregs = ARRAY_SIZE(bcm2835_thermal_regs);
+ regset->base = data->regs;
+
+ debugfs_create_regset32("regset", S_IRUGO,
+ data->debugfsdir, regset);
+}
+
+static struct thermal_zone_device_ops bcm2835_thermal_ops = {
+ .get_temp = bcm2835_thermal_get_temp,
+};
+
+static int bcm2835_thermal_probe(struct platform_device *pdev)
+{
+ struct thermal_zone_device *tz;
+ struct bcm2835_thermal_data *data;
+ struct resource *res;
+ int err;
+
+ data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ /* get registers */
+ 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 */
+ 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);
+ return err;
+ }
+
+ /*
+ * for now we assume the firmware sets up the device,
+ * so we will not write to ctl, we just prepare the clock
+ */
+ clk_prepare_enable(data->clk);
+
+ /* register it */
+ tz = thermal_zone_device_register("bcm2835_thermal",
+ 0, 0, data,
+ &bcm2835_thermal_ops,
+ NULL, 0, 0);
+ 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);
+
+ 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);
+
+ return 0;
+}
+
+static const struct of_device_id bcm2835_thermal_of_match_table[] = {
+ { .compatible = "brcm,bcm2835-thermal", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, bcm2835_thermal_of_match_table);
+
+static struct platform_driver bcm2835_thermal_driver = {
+ .probe = bcm2835_thermal_probe,
+ .remove = bcm2835_thermal_remove,
+ .driver = {
+ .name = "bcm2835_thermal",
+ .of_match_table = bcm2835_thermal_of_match_table,
+ },
+};
+module_platform_driver(bcm2835_thermal_driver);
+
+MODULE_AUTHOR("Martin Sperl");
+MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
+MODULE_LICENSE("GPL");
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/4] ARM: bcm2835: add thermal node to device-tree of bcm283x
2016-05-12 14:35 [PATCH 0/4] bcm2835: add thermal driver kernel
2016-05-12 14:35 ` [PATCH 1/4] dt: bindings: add thermal device driver for bcm2835 kernel
@ 2016-05-12 14:35 ` kernel
[not found] ` <1463063738-11506-4-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-12 14:35 ` [PATCH 4/4] ARM: bcm2835: add thermal driver to default_config kernel
[not found] ` <1463063738-11506-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
3 siblings, 1 reply; 11+ messages in thread
From: kernel @ 2016-05-12 14:35 UTC (permalink / raw)
To: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Eric Anholt,
Russell King, linux-pm, devicetree, linux-rpi-kernel,
linux-arm-kernel
Cc: Martin Sperl
From: Martin Sperl <kernel@martin.sperl.org>
Add the node for the thermal sensor of the bcm2835-soc
to the device tree.
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
---
arch/arm/boot/dts/bcm283x.dtsi | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/arm/boot/dts/bcm283x.dtsi b/arch/arm/boot/dts/bcm283x.dtsi
index 9db9d97..525f1f2 100644
--- a/arch/arm/boot/dts/bcm283x.dtsi
+++ b/arch/arm/boot/dts/bcm283x.dtsi
@@ -159,6 +159,12 @@
status = "disabled";
};
+ thermal: thermal@0x7e212000 {
+ compatible = "brcm,bcm2835-thermal";
+ reg = <0x7e212000 0x8>;
+ clocks = <&clocks BCM2835_CLOCK_TSENS>;
+ };
+
aux: aux@0x7e215000 {
compatible = "brcm,bcm2835-aux";
#clock-cells = <1>;
--
2.1.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/4] ARM: bcm2835: add thermal driver to default_config
2016-05-12 14:35 [PATCH 0/4] bcm2835: add thermal driver kernel
2016-05-12 14:35 ` [PATCH 1/4] dt: bindings: add thermal device driver for bcm2835 kernel
2016-05-12 14:35 ` [PATCH 3/4] ARM: bcm2835: add thermal node to device-tree of bcm283x kernel
@ 2016-05-12 14:35 ` kernel
[not found] ` <1463063738-11506-5-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
[not found] ` <1463063738-11506-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
3 siblings, 1 reply; 11+ messages in thread
From: kernel @ 2016-05-12 14:35 UTC (permalink / raw)
To: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Eric Anholt,
Russell King, linux-pm, devicetree, linux-rpi-kernel,
linux-arm-kernel
Cc: Martin Sperl
From: Martin Sperl <kernel@martin.sperl.org>
Add the thermal driver to list of compiled modules
in the default config for bcm2835.
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
---
arch/arm/configs/bcm2835_defconfig | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/arm/configs/bcm2835_defconfig b/arch/arm/configs/bcm2835_defconfig
index 29a44bd..634e07e 100644
--- a/arch/arm/configs/bcm2835_defconfig
+++ b/arch/arm/configs/bcm2835_defconfig
@@ -71,6 +71,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_FB=y
--
2.1.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 0/4] bcm2835: add thermal driver
[not found] ` <1463063738-11506-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-12 14:35 ` [PATCH 2/4] thermal: bcm2835: add thermal driver for bcm2835 soc kernel-TqfNSX0MhmxHKSADF0wUEw
@ 2016-05-12 22:58 ` Eric Anholt
1 sibling, 0 replies; 11+ messages in thread
From: Eric Anholt @ 2016-05-12 22:58 UTC (permalink / raw)
To: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Russell King,
linux-pm-u79uwXL29TY76Z2rM5mHXA,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: Martin Sperl
[-- Attachment #1: Type: text/plain, Size: 704 bytes --]
kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org writes:
> From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
>
> Add thermal driver for the bcm2835 SOC.
>
> Right now this driver does not set up the thermal device
> itself, but relies on the fact that the firmware is setting
> the device up correctly.
>
> Also it is currently only reading from the register-set.
>
> The driver also exposes the registers via debugfs.
I had looked through before and decided that the FW was turning the
tempsens clock on and off at runtime so we'd have to go through it for
checking temperature. Looking at it now, though, it keeps the clock
running the entire time and just does a read periodically.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/4] dt: bindings: add thermal device driver for bcm2835
[not found] ` <1463063738-11506-2-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
@ 2016-05-12 23:03 ` Eric Anholt
0 siblings, 0 replies; 11+ messages in thread
From: Eric Anholt @ 2016-05-12 23:03 UTC (permalink / raw)
To: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Russell King,
linux-pm-u79uwXL29TY76Z2rM5mHXA,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: Martin Sperl
[-- Attachment #1: Type: text/plain, Size: 1847 bytes --]
kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org writes:
> From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
>
> Add documentation for bcm2835 SOC thermal sensor.
>
> Signed-off-by: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
> ---
> .../devicetree/bindings/thermal/bcm2835-thermal.txt | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/thermal/bcm2835-thermal.txt
>
> diff --git a/Documentation/devicetree/bindings/thermal/bcm2835-thermal.txt b/Documentation/devicetree/bindings/thermal/bcm2835-thermal.txt
> new file mode 100644
> index 0000000..607519a
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/thermal/bcm2835-thermal.txt
There's a naming convention for the BCM DT bindings these days where you
basically name it after the compatible string, so this file should be
moved to "brcm,bcm2835-thermal.txt" (yes, even though it's inconsistent
with the rest of the files in the directory).
> @@ -0,0 +1,16 @@
> +Binding for Thermal Sensor driver for BCM2835 SoCs.
> +
> +Required parameters:
> +-------------------
> +
> +compatible : should be: "brcm,bcm2835-thermal"
Optional: change to 'should be: "brcm,bcm2835-thermal" or
"brcm,bcm2837-thermal"' (see next review for explanation).
I would also drop the space before the colons on the parameters, but as
long as the filename is changed this patch is:
Acked-by: Eric Anholt <eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
> +reg : Address range of the thermal registers.
> +clocks : Phandle of the clock used by the thermal sensor.
> +
> +Example:
> +
> +thermal: thermal@0x7e212000 {
> + compatible = "brcm,bcm2835-thermal";
> + reg = <0x7e212000 0x8>;
> + clocks = <&clocks BCM2835_CLOCK_TSENS>;
> +};
> --
> 2.1.4
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/4] thermal: bcm2835: add thermal driver for bcm2835 soc
[not found] ` <1463063738-11506-3-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
@ 2016-05-12 23:23 ` Eric Anholt
0 siblings, 0 replies; 11+ messages in thread
From: Eric Anholt @ 2016-05-12 23:23 UTC (permalink / raw)
To: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Russell King,
linux-pm-u79uwXL29TY76Z2rM5mHXA,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: Martin Sperl
[-- Attachment #1: Type: text/plain, Size: 5116 bytes --]
kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org writes:
> From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
>
> 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 <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
> ---
> drivers/thermal/Kconfig | 5 +
> drivers/thermal/Makefile | 1 +
> drivers/thermal/bcm/Kconfig | 4 +
> drivers/thermal/bcm/Makefile | 1 +
> drivers/thermal/bcm/bcm2835_thermal.c | 205 ++++++++++++++++++++++++++++++++++
> 5 files changed, 216 insertions(+)
> create mode 100644 drivers/thermal/bcm/Kconfig
> create mode 100644 drivers/thermal/bcm/Makefile
> create mode 100644 drivers/thermal/bcm/bcm2835_thermal.c
>
> diff --git a/drivers/thermal/bcm/bcm2835_thermal.c b/drivers/thermal/bcm/bcm2835_thermal.c
> new file mode 100644
> index 0000000..a1fdc84
> --- /dev/null
> +++ b/drivers/thermal/bcm/bcm2835_thermal.c
> @@ -0,0 +1,205 @@
> +/*
> + * Driver for Broadcom BCM2835 soc temperature sensor
> + *
> + * Copyright (C) 2015 Martin Sperl
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * 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.
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/debugfs.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/io.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/platform_device.h>
> +#include <linux/thermal.h>
> +
> +#define BCM2835_TS_TSENSCTL 0x00
> +#define BCM2835_TS_TSENSSTAT 0x04
> +
> +#define BCM2835_TS_TSENSCTL_PRWDW BIT(0)
> +#define BCM2835_TS_TSENSCTL_RSTB BIT(1)
> +#define BCM2835_TS_TSENSCTL_CTRL BIT(0)
> +#define BCM2835_TS_TSENSCTL_EN_INT BIT(0)
> +#define BCM2835_TS_TSENSCTL_DIRECT BIT(0)
> +#define BCM2835_TS_TSENSCTL_CLR_INT BIT(0)
Bad bit definitions here. CTRL is a field from 2:4, en_int is bit 5,
direct is bit 6, clr is bit 7.
> +#define BCM2835_TS_TSENSCTL_THOLD_SHIFT 8
> +#define BCM2835_TS_TSENSCTL_THOLD_BITS 10
> +#define BCM2835_TS_TSENSCTL_THOLD_MASK \
> + GENMASK(BCM2835_TS_TSENSCTL_THOLD_BITS + \
> + BCM2835_TS_TSENSCTL_THOLD_SHIFT - 1, \
> + BCM2835_TS_TSENSCTL_THOLD_SHIFT)
> +#define BCM2835_TS_TSENSCTL_RSTDELAY_SHIFT 18
> +#define BCM2835_TS_TSENSCTL_RSTDELAY_BITS 8
> +#define BCM2835_TS_TSENSCTL_REGULEN BIT(26)
> +
> +#define BCM2835_TS_TSENSSTAT_DATA_BITS 10
> +#define BCM2835_TS_TSENSSTAT_DATA_SHIFT 0
> +#define BCM2835_TS_TSENSSTAT_DATA_MASK \
> + GENMASK(BCM2835_TS_TSENSSTAT_DATA_BITS + \
> + BCM2835_TS_TSENSSTAT_DATA_SHIFT - 1, \
> + BCM2835_TS_TSENSSTAT_DATA_SHIFT)
Optional: Just use GENMASK with the bit numbers and drop the BITS/SHIFT
definitions, since they aren't used.
> +#define BCM2835_TS_TSENSSTAT_VALID BIT(10)
> +#define BCM2835_TS_TSENSSTAT_INTERRUPT BIT(11)
> +
> +/* empirical linear approximation for conversion to temperature */
> +#define BCM2835_TS_VALUE_OFFSET 407000
> +#define BCM2835_TS_VALUE_SLOPE -538
This matches for pi1/2. However, apparently on Pi3 the sensor was
reporting low so the firmware adjusts the answer it up by 5C. Not
required, but it would be nice to have a brcm,bcm2837-thermal compatible
string that increased the offset by 5C, so that we can enable this
driver right away for pi3.
> +struct bcm2835_thermal_data {
> + void __iomem *regs;
> + struct clk *clk;
> + struct dentry *debugfsdir;
> +};
> +
> +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);
> +
> + /* mask the relevant bits */
> + val &= BCM2835_TS_TSENSSTAT_DATA_MASK;
> +
> + /* linear approximation */
> + *temp = BCM2835_TS_VALUE_OFFSET +
> + (val * BCM2835_TS_VALUE_SLOPE);
> +
> + return 0;
> +}
You need to check if the VALID bit is set and do something appropriate
(I suspect just throw an error) if unset.
> + /*
> + * for now we assume the firmware sets up the device,
> + * so we will not write to ctl, we just prepare the clock
> + */
> + clk_prepare_enable(data->clk);
Optional setup: given the values you can read out of tsensctl set up by
the firmware currently, if at boot RSTB isn't set, then set the values
except for rstb in one writel, then OR in rstb in in the next writel.
Then the driver should be ready in case we ever get a firmware that does
less work.
Thanks for writing the driver! With the bit definition fix and the
VALID check, I'll be ready to add a reviewed-by.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/4] ARM: bcm2835: add thermal node to device-tree of bcm283x
[not found] ` <1463063738-11506-4-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
@ 2016-05-12 23:24 ` Eric Anholt
2016-05-13 6:29 ` Martin Sperl
0 siblings, 1 reply; 11+ messages in thread
From: Eric Anholt @ 2016-05-12 23:24 UTC (permalink / raw)
To: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Russell King,
linux-pm-u79uwXL29TY76Z2rM5mHXA,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: Martin Sperl
[-- Attachment #1: Type: text/plain, Size: 975 bytes --]
kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org writes:
> From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
>
> Add the node for the thermal sensor of the bcm2835-soc
> to the device tree.
>
> Signed-off-by: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
> ---
> arch/arm/boot/dts/bcm283x.dtsi | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/arch/arm/boot/dts/bcm283x.dtsi b/arch/arm/boot/dts/bcm283x.dtsi
> index 9db9d97..525f1f2 100644
> --- a/arch/arm/boot/dts/bcm283x.dtsi
> +++ b/arch/arm/boot/dts/bcm283x.dtsi
> @@ -159,6 +159,12 @@
> status = "disabled";
> };
>
> + thermal: thermal@0x7e212000 {
> + compatible = "brcm,bcm2835-thermal";
> + reg = <0x7e212000 0x8>;
> + clocks = <&clocks BCM2835_CLOCK_TSENS>;
> + };
> +
You could drop the "thermal: " here since nothing refers to it. Either
way,
Reviewed-by: Eric Anholt <eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 4/4] ARM: bcm2835: add thermal driver to default_config
[not found] ` <1463063738-11506-5-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
@ 2016-05-12 23:26 ` Eric Anholt
0 siblings, 0 replies; 11+ messages in thread
From: Eric Anholt @ 2016-05-12 23:26 UTC (permalink / raw)
To: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Russell King,
linux-pm-u79uwXL29TY76Z2rM5mHXA,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: Martin Sperl
[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]
kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org writes:
> From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
>
> Add the thermal driver to list of compiled modules
> in the default config for bcm2835.
>
> Signed-off-by: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
> ---
> arch/arm/configs/bcm2835_defconfig | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/arm/configs/bcm2835_defconfig b/arch/arm/configs/bcm2835_defconfig
> index 29a44bd..634e07e 100644
> --- a/arch/arm/configs/bcm2835_defconfig
> +++ b/arch/arm/configs/bcm2835_defconfig
> @@ -71,6 +71,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_FB=y
> --
> 2.1.4
It would be nice to see multi_v7_defconfig changed, too, since that's
what we expect people to be actually using
This patch is: Reviewed-by: Eric Anholt <eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/4] ARM: bcm2835: add thermal node to device-tree of bcm283x
2016-05-12 23:24 ` Eric Anholt
@ 2016-05-13 6:29 ` Martin Sperl
0 siblings, 0 replies; 11+ messages in thread
From: Martin Sperl @ 2016-05-13 6:29 UTC (permalink / raw)
To: Eric Anholt
Cc: Zhang Rui, Eduardo Valentin, Rob Herring, Pawel Moll,
Mark Rutland, Stephen Warren, Lee Jones, Russell King, linux-pm,
devicetree, linux-rpi-kernel, linux-arm-kernel
> On 13.05.2016, at 01:24, Eric Anholt <eric@anholt.net> wrote:
>
> kernel@martin.sperl.org writes:
>
>> From: Martin Sperl <kernel@martin.sperl.org>
>>
>> Add the node for the thermal sensor of the bcm2835-soc
>> to the device tree.
>>
>> Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
>> ---
>> arch/arm/boot/dts/bcm283x.dtsi | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/arch/arm/boot/dts/bcm283x.dtsi b/arch/arm/boot/dts/bcm283x.dtsi
>> index 9db9d97..525f1f2 100644
>> --- a/arch/arm/boot/dts/bcm283x.dtsi
>> +++ b/arch/arm/boot/dts/bcm283x.dtsi
>> @@ -159,6 +159,12 @@
>> status = "disabled";
>> };
>>
>> + thermal: thermal@0x7e212000 {
>> + compatible = "brcm,bcm2835-thermal";
>> + reg = <0x7e212000 0x8>;
>> + clocks = <&clocks BCM2835_CLOCK_TSENS>;
>> + };
>> +
>
> You could drop the "thermal: " here since nothing refers to it. Either
> way,
Actually you will refer to it in the device tree for the bcm2837
so that you can set a different compatible string.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2016-05-13 6:29 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-12 14:35 [PATCH 0/4] bcm2835: add thermal driver kernel
2016-05-12 14:35 ` [PATCH 1/4] dt: bindings: add thermal device driver for bcm2835 kernel
[not found] ` <1463063738-11506-2-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-12 23:03 ` Eric Anholt
2016-05-12 14:35 ` [PATCH 3/4] ARM: bcm2835: add thermal node to device-tree of bcm283x kernel
[not found] ` <1463063738-11506-4-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-12 23:24 ` Eric Anholt
2016-05-13 6:29 ` Martin Sperl
2016-05-12 14:35 ` [PATCH 4/4] ARM: bcm2835: add thermal driver to default_config kernel
[not found] ` <1463063738-11506-5-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-12 23:26 ` Eric Anholt
[not found] ` <1463063738-11506-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-12 14:35 ` [PATCH 2/4] thermal: bcm2835: add thermal driver for bcm2835 soc kernel-TqfNSX0MhmxHKSADF0wUEw
[not found] ` <1463063738-11506-3-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-12 23:23 ` Eric Anholt
2016-05-12 22:58 ` [PATCH 0/4] bcm2835: add thermal driver Eric Anholt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).