Skip to contentSkip to conversation

dt-bindings: thermal: add support for Broadcom's Northstar thermal

PATCH In review Rafał Miłecki 8 participants 35 messages Mar 18, 2017 – Apr 17, 2017 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

From: Rafał Miłecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
 .../devicetree/bindings/thermal/brcm,ns-thermal         | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +17 -0
new file mode 100644
index 000000000000..9a22dd76ec01
@@ -0,0 +1,17 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU (Device
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal {
+	compatible = "brcm,ns-thermal";
+	reg = <0x1800c2c0 0x10>;
+	#thermal-sensor-cells = <0>;
+};
Signature · 6 lines
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20170318155632.18099-1-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 2/2 thermal: broadcom: add Northstar thermal driver

From: Rafał Miłecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature.

---
 drivers/thermal/Kconfig               |  5 ++
 drivers/thermal/Makefile              |  1 +
 drivers/thermal/broadcom/Kconfig      |  7 +++
 drivers/thermal/broadcom/Makefile     |  1 +
 drivers/thermal/broadcom/ns-thermal.c | 93 +++++++++++++++++++++++++++++++++++
 5 files changed, 107 insertions(+)
 create mode 100644 drivers/thermal/broadcom/Kconfig
 create mode 100644 drivers/thermal/broadcom/Makefile
 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
drivers/thermal/Kconfig +5 -0
index 776b34396144..008e173ec825 100644
@@ -392,6 +392,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/broadcom/Kconfig"
+endmenu
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
drivers/thermal/Makefile +1 -0
index 7adae2029355..549d81b6363c 100644
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL)	+= clock_cooling.o
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
 # platform thermal drivers
+obj-y				+= broadcom/
 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
drivers/thermal/broadcom/Kconfig new file +7 -0
new file mode 100644
index 000000000000..08457a461794
@@ -0,0 +1,7 @@
+config BCM_NS_THERMAL
+	tristate "Northstar thermal driver"
+	depends on ARCH_BCM_5301X || COMPILE_TEST
+	help
+	  Northstar's DMU (Device Management Unit) block contains a thermal
+	  sensor that allows checking CPU temperature. This driver provides
+	  support for it.
drivers/thermal/broadcom/Makefile new file +1 -0
new file mode 100644
index 000000000000..059df9a0ed69
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/ns-thermal.c new file +93 -0

93 lines not on this page · raw message

Signature · 6 lines
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

Re: [PATCH 2/2] thermal: broadcom: add Northstar thermal driver

Quoted 51 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature.

---
 drivers/thermal/Kconfig               |  5 ++
 drivers/thermal/Makefile              |  1 +
 drivers/thermal/broadcom/Kconfig      |  7 +++
 drivers/thermal/broadcom/Makefile     |  1 +
 drivers/thermal/broadcom/ns-thermal.c | 93 +++++++++++++++++++++++++++++++++++
 5 files changed, 107 insertions(+)
 create mode 100644 drivers/thermal/broadcom/Kconfig
 create mode 100644 drivers/thermal/broadcom/Makefile
 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
drivers/thermal/Kconfig +5 -0
index 776b34396144..008e173ec825 100644
@@ -392,6 +392,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/broadcom/Kconfig"
+endmenu
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
drivers/thermal/Makefile +1 -0
index 7adae2029355..549d81b6363c 100644
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL)	+= clock_cooling.o
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
 # platform thermal drivers
+obj-y				+= broadcom/
 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
drivers/thermal/broadcom/Kconfig new file +0 -0
new file mode 100644
index 000000000000..08457a461794

drivers/thermal/broadcom/Kconfig line 7

Quoted 7 lines
drivers/thermal/broadcom/Kconfig new file +7 -0
@@ -0,0 +1,7 @@
+config BCM_NS_THERMAL
+	tristate "Northstar thermal driver"
+	depends on ARCH_BCM_5301X || COMPILE_TEST
+	help
+	  Northstar's DMU (Device Management Unit) block contains a thermal
+	  sensor that allows checking CPU temperature. This driver provides
+	  support for it.

The register layout for the NS PVTMON is the same for NSP and NS2. So, you might want to make this more generic. Perhaps iProc or Northstar family. I did a quick look, and I didn't see PVTMON registers in Cygnus, so maybe the latter is better. Also, the depends should be tweaked to have NSP, etc.

Quoted 56 lines
drivers/thermal/broadcom/Makefile new file +1 -0
new file mode 100644
index 000000000000..059df9a0ed69
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/ns-thermal.c new file +43 -0
new file mode 100644
index 000000000000..1ec710febc55
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2017 Rafał Miłecki <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define PVTMON_CONTROL0		0x00
+#define PVTMON_STATUS		0x08
+
+struct ns_thermal {
+	void __iomem *pvtmon;
+};
+
+static int ns_thermal_get_temp(void *data, int *temp)
+{
+	struct ns_thermal *ns_thermal = data;
+	u32 val;
+
+	val = readl(ns_thermal->pvtmon + PVTMON_STATUS);
+	*temp = 418000 - (val * 556);
+
+	return 0;
+}
+
+const struct thermal_zone_of_device_ops ns_thermal_ops = {
+	.get_temp = ns_thermal_get_temp,
+};
+
+static int ns_thermal_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ns_thermal *ns_thermal;
+	struct thermal_zone_device *tzd;
+	u32 val;
+
+	ns_thermal = devm_kzalloc(dev, sizeof(*ns_thermal), GFP_KERNEL);

drivers/thermal/broadcom/ns-thermal.c line 53

Quoted 10 lines
drivers/thermal/broadcom/ns-thermal.c new file +10 -0
+	if (!ns_thermal)
+		return -ENOMEM;
+
+	ns_thermal->pvtmon = of_iomap(dev_of_node(dev), 0);
+	if (WARN_ON(!ns_thermal->pvtmon))
+		return -ENOENT;
+
+	val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
+	if (val & 0xf)
+		writel(val & ~0xf, ns_thermal->pvtmon + PVTMON_CONTROL0);

This appears to be zeroing the register. You are either intentionally excluding the Voltage DAC (bits 4-13) or don't know it is there. I do not know this IP block well enough to know if there are negative consiquences from zeroing this, but the power on default is 0 (assording to the spec).

FYI, writing a 1 to bit 0 will "power down" PVTMON.

Also, PVTMON Select (bits 1-3):
0 - Temp Monitor Enable
1-6 - Various Voltage Monitoring Settings
7 - Test mode

So, if this driver is ever expanded to do voltage too, then the setting of PVTMON_CONTROL0 will need to move to the ns_thermal_get_temp above.

Thanks,
Jon

Quoted 43 lines
drivers/thermal/broadcom/ns-thermal.c new file +40 -0
+
+	tzd = devm_thermal_zone_of_sensor_register(dev, 0, ns_thermal,
+						   &ns_thermal_ops);
+	if (IS_ERR(tzd)) {
+		iounmap(ns_thermal->pvtmon);
+		return PTR_ERR(tzd);
+	}
+
+	platform_set_drvdata(pdev, ns_thermal);
+
+	return 0;
+}
+
+static int ns_thermal_remove(struct platform_device *pdev)
+{
+	struct ns_thermal *ns_thermal = platform_get_drvdata(pdev);
+
+	iounmap(ns_thermal->pvtmon);
+
+	return 0;
+}
+
+static const struct of_device_id ns_thermal_of_match[] = {
+	{ .compatible = "brcm,ns-thermal", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, ns_thermal_of_match);
+
+static struct platform_driver ns_thermal_driver = {
+	.probe		= ns_thermal_probe,
+	.remove		= ns_thermal_remove,
+	.driver = {
+		.name = "ns-thermal",
+		.of_match_table = ns_thermal_of_match,
+	},
+};
+module_platform_driver(ns_thermal_driver);
+
+MODULE_DESCRIPTION("Northstar thermal driver");
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.11.0
#4 lore raw

PATCH v2 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

In reply to Rafał Miłecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
 .../devicetree/bindings/thermal/brcm,ns-thermal         | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +17 -0
new file mode 100644
index 000000000000..9a22dd76ec01
@@ -0,0 +1,17 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU (Device
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal {
+	compatible = "brcm,ns-thermal";
+	reg = <0x1800c2c0 0x10>;
+	#thermal-sensor-cells = <0>;
+};
Signature · 1 line
2.11.0
#5 lore raw

PATCH v2 2/2 thermal: broadcom: add Northstar thermal driver

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

---
V2: Make it iProc specific as NSP can also use this driver
Select proper symbols in config ARCH_BCM_IPROC Define PVTMON register bits
Update code selecting temperature monitor mode Thank you Jon!

---
 arch/arm/mach-bcm/Kconfig             |  2 +
 drivers/thermal/Kconfig               |  5 ++
 drivers/thermal/Makefile              |  1 +
 drivers/thermal/broadcom/Kconfig      |  7 +++
 drivers/thermal/broadcom/Makefile     |  1 +
 drivers/thermal/broadcom/ns-thermal.c | 98 +++++++++++++++++++++++++++++++++++
 6 files changed, 114 insertions(+)
 create mode 100644 drivers/thermal/broadcom/Kconfig
 create mode 100644 drivers/thermal/broadcom/Makefile
 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
arch/arm/mach-bcm/Kconfig +2 -0
index a0e66d8200c5..da2bfeb8e390 100644
@@ -19,6 +19,8 @@ config ARCH_BCM_IPROC
 	select GPIOLIB
 	select ARM_AMBA
 	select PINCTRL
+	select THERMAL
+	select THERMAL_OF
 	help
 	  This enables support for systems based on Broadcom IPROC architected SoCs.
 	  The IPROC complex contains one or more ARM CPUs along with common
drivers/thermal/Kconfig +5 -0
index 776b34396144..008e173ec825 100644
@@ -392,6 +392,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/broadcom/Kconfig"
+endmenu
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
drivers/thermal/Makefile +1 -0
index 7adae2029355..549d81b6363c 100644
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL)	+= clock_cooling.o
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
 # platform thermal drivers
+obj-y				+= broadcom/
 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
drivers/thermal/broadcom/Kconfig new file +7 -0
new file mode 100644
index 000000000000..39b92a1f3584
@@ -0,0 +1,7 @@
+config BCM_NS_THERMAL
+	tristate "Northstar thermal driver"
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	help
+	  Northstar's DMU (Device Management Unit) block contains a thermal
+	  sensor that allows checking CPU temperature. This driver provides
+	  support for it.
drivers/thermal/broadcom/Makefile new file +1 -0
new file mode 100644
index 000000000000..059df9a0ed69
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/ns-thermal.c new file +98 -0

98 lines not on this page · raw message

Signature · 1 line
2.11.0
#6 lore raw

PATCH v2 2/2 thermal: broadcom: add Northstar thermal driver

Quoted 115 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

---
V2: Make it iProc specific as NSP can also use this driver
Select proper symbols in config ARCH_BCM_IPROC Define PVTMON register bits
Update code selecting temperature monitor mode Thank you Jon!

---
 arch/arm/mach-bcm/Kconfig             |  2 +
 drivers/thermal/Kconfig               |  5 ++
 drivers/thermal/Makefile              |  1 +
 drivers/thermal/broadcom/Kconfig      |  7 +++
 drivers/thermal/broadcom/Makefile     |  1 +
 drivers/thermal/broadcom/ns-thermal.c | 98 +++++++++++++++++++++++++++++++++++
 6 files changed, 114 insertions(+)
 create mode 100644 drivers/thermal/broadcom/Kconfig
 create mode 100644 drivers/thermal/broadcom/Makefile
 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
arch/arm/mach-bcm/Kconfig +2 -0
index a0e66d8200c5..da2bfeb8e390 100644
@@ -19,6 +19,8 @@ config ARCH_BCM_IPROC
 	select GPIOLIB
 	select ARM_AMBA
 	select PINCTRL
+	select THERMAL
+	select THERMAL_OF
 	help
 	  This enables support for systems based on Broadcom IPROC architected SoCs.
 	  The IPROC complex contains one or more ARM CPUs along with common
drivers/thermal/Kconfig +5 -0
index 776b34396144..008e173ec825 100644
@@ -392,6 +392,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/broadcom/Kconfig"
+endmenu
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
drivers/thermal/Makefile +1 -0
index 7adae2029355..549d81b6363c 100644
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL)	+= clock_cooling.o
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
 # platform thermal drivers
+obj-y				+= broadcom/
 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
drivers/thermal/broadcom/Kconfig new file +7 -0
new file mode 100644
index 000000000000..39b92a1f3584
@@ -0,0 +1,7 @@
+config BCM_NS_THERMAL
+	tristate "Northstar thermal driver"
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	help
+	  Northstar's DMU (Device Management Unit) block contains a thermal
+	  sensor that allows checking CPU temperature. This driver provides
+	  support for it.
drivers/thermal/broadcom/Makefile new file +1 -0
new file mode 100644
index 000000000000..059df9a0ed69
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/ns-thermal.c new file +22 -0
new file mode 100644
index 000000000000..acf3a4de62a4
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 Rafa? Mi?ecki <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define PVTMON_CONTROL0					0x00
+#define PVTMON_CONTROL0_SEL_MASK			0x0000000e
+#define PVTMON_CONTROL0_SEL_TEMP_MONITOR		0x00000000
+#define PVTMON_CONTROL0_SEL_TEST_MODE			0x0000000e
+#define PVTMON_STATUS					0x08
+
+struct ns_thermal {
+	void __iomem *pvtmon;
+};

drivers/thermal/broadcom/ns-thermal.c line 32

Quoted 10 lines
drivers/thermal/broadcom/ns-thermal.c new file +10 -0
+
+static int ns_thermal_get_temp(void *data, int *temp)
+{
+	struct ns_thermal *ns_thermal = data;
+	u32 val;
+
+	val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
+	if ((val & PVTMON_CONTROL0_SEL_MASK) != PVTMON_CONTROL0_SEL_TEMP_MONITOR) {
+		val &= ~PVTMON_CONTROL0_SEL_MASK;
+		val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;

I think this is slightly confusing here. If this was off, ORing in 0 will not enable it. I think we need to flip the #define to make it PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE (or a less crappy name). then use this line here to toggle it. Something like

                val &= ~PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE;

Thanks,
Jon

Quoted 69 lines
drivers/thermal/broadcom/ns-thermal.c new file +66 -0
+		writel(val, ns_thermal->pvtmon + PVTMON_CONTROL0);
+	}
+
+	val = readl(ns_thermal->pvtmon + PVTMON_STATUS);
+	*temp = (418 - (val * 5556 / 10000)) * 1000;
+
+	return 0;
+}
+
+const struct thermal_zone_of_device_ops ns_thermal_ops = {
+	.get_temp = ns_thermal_get_temp,
+};
+
+static int ns_thermal_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ns_thermal *ns_thermal;
+	struct thermal_zone_device *tzd;
+
+	ns_thermal = devm_kzalloc(dev, sizeof(*ns_thermal), GFP_KERNEL);
+	if (!ns_thermal)
+		return -ENOMEM;
+
+	ns_thermal->pvtmon = of_iomap(dev_of_node(dev), 0);
+	if (WARN_ON(!ns_thermal->pvtmon))
+		return -ENOENT;
+
+	tzd = devm_thermal_zone_of_sensor_register(dev, 0, ns_thermal,
+						   &ns_thermal_ops);
+	if (IS_ERR(tzd)) {
+		iounmap(ns_thermal->pvtmon);
+		return PTR_ERR(tzd);
+	}
+
+	platform_set_drvdata(pdev, ns_thermal);
+
+	return 0;
+}
+
+static int ns_thermal_remove(struct platform_device *pdev)
+{
+	struct ns_thermal *ns_thermal = platform_get_drvdata(pdev);
+
+	iounmap(ns_thermal->pvtmon);
+
+	return 0;
+}
+
+static const struct of_device_id ns_thermal_of_match[] = {
+	{ .compatible = "brcm,ns-thermal", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, ns_thermal_of_match);
+
+static struct platform_driver ns_thermal_driver = {
+	.probe		= ns_thermal_probe,
+	.remove		= ns_thermal_remove,
+	.driver = {
+		.name = "ns-thermal",
+		.of_match_table = ns_thermal_of_match,
+	},
+};
+module_platform_driver(ns_thermal_driver);
+
+MODULE_DESCRIPTION("Northstar thermal driver");
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.11.0
#7 lore raw

PATCH v2 2/2 thermal: broadcom: add Northstar thermal driver

Quoted 45 lines · Jon Mason
Quoted 28 lines · Rafa? Mi?ecki
drivers/thermal/broadcom/ns-thermal.c new file +22 -0
new file mode 100644
index 000000000000..acf3a4de62a4
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 Rafa? Mi?ecki <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define PVTMON_CONTROL0					0x00
+#define PVTMON_CONTROL0_SEL_MASK			0x0000000e
+#define PVTMON_CONTROL0_SEL_TEMP_MONITOR		0x00000000
+#define PVTMON_CONTROL0_SEL_TEST_MODE			0x0000000e
+#define PVTMON_STATUS					0x08
+
+struct ns_thermal {
+	void __iomem *pvtmon;
+};

drivers/thermal/broadcom/ns-thermal.c line 32

Quoted 10 lines
drivers/thermal/broadcom/ns-thermal.c new file +10 -0
+
+static int ns_thermal_get_temp(void *data, int *temp)
+{
+	struct ns_thermal *ns_thermal = data;
+	u32 val;
+
+	val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
+	if ((val & PVTMON_CONTROL0_SEL_MASK) != PVTMON_CONTROL0_SEL_TEMP_MONITOR) {
+		val &= ~PVTMON_CONTROL0_SEL_MASK;
+		val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;

I think this is slightly confusing here. If this was off, ORing in 0 will not enable it. I think we need to flip the #define to make it PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE (or a less crappy name). then use this line here to toggle it. Something like

Quoted 1 line
                val &= ~PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE;

I don't understand this, can you help me further?

OR-ing with 0 is only a cosmetic thing obviously - just to make it clear which value we expect to be set in bits 1:3. The important part is:
val &= ~PVTMON_CONTROL0_SEL_MASK;

AFAIU selecting any mode other than TEMP_MONITOR will disable monitor access. AFAIU even switchint to TEST_MODE will prevent access to temp, so I don't see how we could use PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE. It could be any value other than 0.

#8 lore raw

PATCH v2 2/2 thermal: broadcom: add Northstar thermal driver

Quoted 54 lines · Rafa? Mi?ecki
Quoted 50 lines · Jon Mason
Quoted 39 lines · Rafa? Mi?ecki
drivers/thermal/broadcom/ns-thermal.c new file +30 -0
new file mode 100644
index 000000000000..acf3a4de62a4
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 Rafa? Mi?ecki <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define PVTMON_CONTROL0                                        0x00
+#define PVTMON_CONTROL0_SEL_MASK                       0x0000000e
+#define PVTMON_CONTROL0_SEL_TEMP_MONITOR               0x00000000
+#define PVTMON_CONTROL0_SEL_TEST_MODE                  0x0000000e
+#define PVTMON_STATUS                                  0x08
+
+struct ns_thermal {
+       void __iomem *pvtmon;
+};
+
+static int ns_thermal_get_temp(void *data, int *temp)
+{
+       struct ns_thermal *ns_thermal = data;
+       u32 val;
+
+       val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
+       if ((val & PVTMON_CONTROL0_SEL_MASK) !=

PVTMON_CONTROL0_SEL_TEMP_MONITOR) {

drivers/thermal/broadcom/ns-thermal.c line 32

Quoted 2 lines
drivers/thermal/broadcom/ns-thermal.c new file +2 -0
+               val &= ~PVTMON_CONTROL0_SEL_MASK;
+               val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;

I think this is slightly confusing here. If this was off, ORing in 0 will not enable it. I think we need to flip the #define to make it PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE (or a less crappy name). then use this line here to toggle it. Something like

Quoted 1 line
                val &= ~PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE;
Quoted 6 lines

I don't understand this, can you help me further?

OR-ing with 0 is only a cosmetic thing obviously - just to make it clear which
value we expect to be set in bits 1:3. The important part is:
val &= ~PVTMON_CONTROL0_SEL_MASK;

You are using a side effect of the masking to clear/enable the block. I'm simply saying that we should be explicit about enabling it. My concern is that using the side effect hides what is being done and could result in a bug somewhere down the line. I think this is improbable based on the code, but wanted to err on the side of caution.

Quoted 7 lines

AFAIU selecting any mode other than TEMP_MONITOR will disable monitor access.
AFAIU even switchint to TEST_MODE will prevent access to temp, so I don't see
how we could use PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE. It could be any value other than 0.

#9 lore raw

PATCH v2 2/2 thermal: broadcom: add Northstar thermal driver

Quoted 62 lines · Jon Mason
Quoted 54 lines · Rafa? Mi?ecki
Quoted 50 lines · Jon Mason
Quoted 39 lines · Rafa? Mi?ecki
drivers/thermal/broadcom/ns-thermal.c new file +30 -0
new file mode 100644
index 000000000000..acf3a4de62a4
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 Rafa? Mi?ecki <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define PVTMON_CONTROL0                                        0x00
+#define PVTMON_CONTROL0_SEL_MASK                       0x0000000e
+#define PVTMON_CONTROL0_SEL_TEMP_MONITOR               0x00000000
+#define PVTMON_CONTROL0_SEL_TEST_MODE                  0x0000000e
+#define PVTMON_STATUS                                  0x08
+
+struct ns_thermal {
+       void __iomem *pvtmon;
+};
+
+static int ns_thermal_get_temp(void *data, int *temp)
+{
+       struct ns_thermal *ns_thermal = data;
+       u32 val;
+
+       val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
+       if ((val & PVTMON_CONTROL0_SEL_MASK) !=

PVTMON_CONTROL0_SEL_TEMP_MONITOR) {

drivers/thermal/broadcom/ns-thermal.c line 32

Quoted 2 lines
drivers/thermal/broadcom/ns-thermal.c new file +2 -0
+               val &= ~PVTMON_CONTROL0_SEL_MASK;
+               val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;

I think this is slightly confusing here. If this was off, ORing in 0 will not enable it. I think we need to flip the #define to make it PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE (or a less crappy name). then use this line here to toggle it. Something like

Quoted 1 line
                val &= ~PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE;
Quoted 6 lines

I don't understand this, can you help me further?

OR-ing with 0 is only a cosmetic thing obviously - just to make it clear which
value we expect to be set in bits 1:3. The important part is:
val &= ~PVTMON_CONTROL0_SEL_MASK;

Quoted 6 lines

You are using a side effect of the masking to clear/enable the block. I'm simply saying that we should be explicit about enabling it. My concern is that using the side effect hides what is being done and could result in a bug somewhere down the line. I think this is improbable based on the code, but wanted to err on the side of caution.

Well, I'm clearing current mode selection and "selecting" the mode I want. By OR-ing PVTMON_CONTROL0_SEL_TEMP_MONITOR I'm clearly indicating I want temp monitor more.

How else I could make it more obvious? Should I add some comment maybe?

#10 lore raw

PATCH v2 2/2 thermal: broadcom: add Northstar thermal driver

Quoted 79 lines · Rafa? Mi?ecki
Quoted 70 lines · Jon Mason
Quoted 60 lines · Rafa? Mi?ecki
Quoted 54 lines · Jon Mason
Quoted 41 lines · Rafa? Mi?ecki
drivers/thermal/broadcom/ns-thermal.c new file +4 -0
new file mode 100644
index 000000000000..acf3a4de62a4
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 Rafa? Mi?ecki <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or

modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */

drivers/thermal/broadcom/ns-thermal.c new file +23 -0
+
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define PVTMON_CONTROL0                                        0x00
+#define PVTMON_CONTROL0_SEL_MASK                       0x0000000e
+#define PVTMON_CONTROL0_SEL_TEMP_MONITOR               0x00000000
+#define PVTMON_CONTROL0_SEL_TEST_MODE                  0x0000000e
+#define PVTMON_STATUS                                  0x08
+
+struct ns_thermal {
+       void __iomem *pvtmon;
+};
+
+static int ns_thermal_get_temp(void *data, int *temp)
+{
+       struct ns_thermal *ns_thermal = data;
+       u32 val;
+
+       val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
+       if ((val & PVTMON_CONTROL0_SEL_MASK) !=

PVTMON_CONTROL0_SEL_TEMP_MONITOR) {

drivers/thermal/broadcom/ns-thermal.c line 32

Quoted 2 lines
drivers/thermal/broadcom/ns-thermal.c new file +2 -0
+               val &= ~PVTMON_CONTROL0_SEL_MASK;
+               val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;

I think this is slightly confusing here. If this was off, ORing in 0 will not enable it. I think we need to flip the #define to make it PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE (or a less crappy name). then use this line here to toggle it. Something like

Quoted 1 line
                val &= ~PVTMON_CONTROL0_SEL_TEMP_MONITOR_DISABLE;
Quoted 6 lines

I don't understand this, can you help me further?

OR-ing with 0 is only a cosmetic thing obviously - just to make it clear which
value we expect to be set in bits 1:3. The important part is:
val &= ~PVTMON_CONTROL0_SEL_MASK;

Quoted 6 lines

You are using a side effect of the masking to clear/enable the block. I'm simply saying that we should be explicit about enabling it. My concern is that using the side effect hides what is being done and could result in a bug somewhere down the line. I think this is improbable based on the code, but wanted to err on the side of caution.

Quoted 6 lines

Well, I'm clearing current mode selection and "selecting" the mode I want. By
OR-ing PVTMON_CONTROL0_SEL_TEMP_MONITOR I'm clearly indicating I want temp monitor more.

How else I could make it more obvious? Should I add some comment maybe?

I think it would be acceptable to remove the ORing of the 0, and simply put a comment there that the masking of it is clearing the 0th bit, thus enabling the IP block.

#11 lore raw

PATCH v2 2/2 thermal: broadcom: add Northstar thermal driver

In reply to Rafał Miłecki

Hello,

Quoted 6 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

Can you please educate me on how different this driver is from
https://patchwork.kernel.org/patch/9619579/

?

Quoted 8 lines

---
V2: Make it iProc specific as NSP can also use this driver
Select proper symbols in config ARCH_BCM_IPROC Define PVTMON register bits
Update code selecting temperature monitor mode Thank you Jon!

Quoted 7 lines
---
 arch/arm/mach-bcm/Kconfig             |  2 +
 drivers/thermal/Kconfig               |  5 ++
 drivers/thermal/Makefile              |  1 +
 drivers/thermal/broadcom/Kconfig      |  7 +++
 drivers/thermal/broadcom/Makefile     |  1 +
 drivers/thermal/broadcom/ns-thermal.c | 98 +++++++++++++++++++++++++++++++++++

Ok. This driver attempts to create a common place for broadcom thermal drivers, which is good, but..

Quoted 10 lines
 6 files changed, 114 insertions(+)
 create mode 100644 drivers/thermal/broadcom/Kconfig
 create mode 100644 drivers/thermal/broadcom/Makefile
 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
arch/arm/mach-bcm/Kconfig +0 -0
index a0e66d8200c5..da2bfeb8e390 100644

arch/arm/mach-bcm/Kconfig config ARCH_BCM_IPROC · line 26

Quoted 8 lines
arch/arm/mach-bcm/Kconfig +2 -0
@@ -19,6 +19,8 @@ config ARCH_BCM_IPROC
 	select GPIOLIB
 	select ARM_AMBA
 	select PINCTRL
+	select THERMAL
+	select THERMAL_OF
 	help
 	  This enables support for systems based on Broadcom IPROC architected SoCs.
 	  The IPROC complex contains one or more ARM CPUs along with common

To avoid conflicts I would suggest getting this patch split into driver and arch code changes.

drivers/thermal/Kconfig config MTK_THERMAL · line 396

Quoted 10 lines
drivers/thermal/Kconfig +2 -0
index 776b34396144..008e173ec825 100644
@@ -392,6 +392,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

Does the above dependency also work for other BCM chips?

Quoted 24 lines
drivers/thermal/Kconfig +3 -0
+source "drivers/thermal/broadcom/Kconfig"
+endmenu
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
drivers/thermal/Makefile +1 -0
index 7adae2029355..549d81b6363c 100644
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL)	+= clock_cooling.o
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
 # platform thermal drivers
+obj-y				+= broadcom/
 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
drivers/thermal/broadcom/Kconfig new file +0 -0
new file mode 100644
index 000000000000..39b92a1f3584

drivers/thermal/broadcom/Kconfig line 7

Quoted 7 lines
drivers/thermal/broadcom/Kconfig new file +7 -0
@@ -0,0 +1,7 @@
+config BCM_NS_THERMAL
+	tristate "Northstar thermal driver"
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	help
+	  Northstar's DMU (Device Management Unit) block contains a thermal
+	  sensor that allows checking CPU temperature. This driver provides
+	  support for it.

It would be good if you could include a list of socs that have DMUs.

Quoted 41 lines
drivers/thermal/broadcom/Makefile new file +1 -0
new file mode 100644
index 000000000000..059df9a0ed69
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/ns-thermal.c new file +28 -0
new file mode 100644
index 000000000000..acf3a4de62a4
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 Rafa? Mi?ecki <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define PVTMON_CONTROL0					0x00
+#define PVTMON_CONTROL0_SEL_MASK			0x0000000e
+#define PVTMON_CONTROL0_SEL_TEMP_MONITOR		0x00000000
+#define PVTMON_CONTROL0_SEL_TEST_MODE			0x0000000e
+#define PVTMON_STATUS					0x08
+
+struct ns_thermal {
+	void __iomem *pvtmon;
+};
+
+static int ns_thermal_get_temp(void *data, int *temp)
+{
+	struct ns_thermal *ns_thermal = data;
+	u32 val;
+

drivers/thermal/broadcom/ns-thermal.c line 38

Quoted 10 lines
drivers/thermal/broadcom/ns-thermal.c new file +10 -0
+	val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
+	if ((val & PVTMON_CONTROL0_SEL_MASK) != PVTMON_CONTROL0_SEL_TEMP_MONITOR) {
+		val &= ~PVTMON_CONTROL0_SEL_MASK;
+		val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;
+		writel(val, ns_thermal->pvtmon + PVTMON_CONTROL0);
+	}
+
+	val = readl(ns_thermal->pvtmon + PVTMON_STATUS);
+	*temp = (418 - (val * 5556 / 10000)) * 1000;
+

Could you move the above equation to DT? The other BCM driver I posted the link above just went through the same process.

Quoted 63 lines
drivers/thermal/broadcom/ns-thermal.c new file +60 -0
+	return 0;
+}
+
+const struct thermal_zone_of_device_ops ns_thermal_ops = {
+	.get_temp = ns_thermal_get_temp,
+};
+
+static int ns_thermal_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ns_thermal *ns_thermal;
+	struct thermal_zone_device *tzd;
+
+	ns_thermal = devm_kzalloc(dev, sizeof(*ns_thermal), GFP_KERNEL);
+	if (!ns_thermal)
+		return -ENOMEM;
+
+	ns_thermal->pvtmon = of_iomap(dev_of_node(dev), 0);
+	if (WARN_ON(!ns_thermal->pvtmon))
+		return -ENOENT;
+
+	tzd = devm_thermal_zone_of_sensor_register(dev, 0, ns_thermal,
+						   &ns_thermal_ops);
+	if (IS_ERR(tzd)) {
+		iounmap(ns_thermal->pvtmon);
+		return PTR_ERR(tzd);
+	}
+
+	platform_set_drvdata(pdev, ns_thermal);
+
+	return 0;
+}
+
+static int ns_thermal_remove(struct platform_device *pdev)
+{
+	struct ns_thermal *ns_thermal = platform_get_drvdata(pdev);
+
+	iounmap(ns_thermal->pvtmon);
+
+	return 0;
+}
+
+static const struct of_device_id ns_thermal_of_match[] = {
+	{ .compatible = "brcm,ns-thermal", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, ns_thermal_of_match);
+
+static struct platform_driver ns_thermal_driver = {
+	.probe		= ns_thermal_probe,
+	.remove		= ns_thermal_remove,
+	.driver = {
+		.name = "ns-thermal",
+		.of_match_table = ns_thermal_of_match,
+	},
+};
+module_platform_driver(ns_thermal_driver);
+
+MODULE_DESCRIPTION("Northstar thermal driver");
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.11.0
#12 lore raw

PATCH v2 2/2 thermal: broadcom: add Northstar thermal driver

Thanks for your review!

Quoted 8 lines · Eduardo Valentin
Quoted 6 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

Quoted 4 lines

Can you please educate me on how different this driver is from
https://patchwork.kernel.org/patch/9619579/

?

This is a different hardware block. Northstar and BCM283x are totally different SoCs. Northstar is mostly used in home routers, BCM283x mostly in Rasperry Pi.

Quoted 8 lines
Quoted 8 lines
drivers/thermal/Kconfig +0 -0
index 776b34396144..008e173ec825 100644
@@ -392,6 +392,11 @@ config MTK_THERMAL
 	  Enable this option if you want to have support for thermal management
 	  controller present in Mediatek SoCs
 
Quoted 4 lines

drivers/thermal/Kconfig config MTK_THERMAL · line 396

Quoted 2 lines
drivers/thermal/Kconfig +2 -0
+menu "Broadcom thermal drivers"
+depends on ARCH_BCM || COMPILE_TEST

Does the above dependency also work for other BCM chips?

I believe so. If there ever appears a driver in drivers/thermal/broadcom/ that can't be freely compiled with COMPILE_TEST, it can just have a proper dependency.

#13 lore raw

PATCH v2 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

In reply to Rafał Miłecki

Hello Rafal,

Quoted 23 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
 .../devicetree/bindings/thermal/brcm,ns-thermal         | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +7 -0
new file mode 100644
index 000000000000..9a22dd76ec01
@@ -0,0 +1,17 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU (Device
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"

Documentation/devicetree/bindings/thermal/brcm,ns-thermal line 17

Quoted 10 lines
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +10 -0
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal {
+	compatible = "brcm,ns-thermal";
+	reg = <0x1800c2c0 0x10>;
+	#thermal-sensor-cells = <0>;
+};

Could you please also include an example of the thermal zone one should include in the board/cpu DTS while using this sensor?

Besides, based on what I saw you in your driver, you could also describe your offset and slope in DT, and read them using thermal helpers.

BR,

Quoted 3 lines
Signature · 1 line
2.11.0
#14 lore raw

PATCH v3 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

In reply to Rafał Miłecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
V3: Add thermal-zones to the example
Rob: Because of this update, I didn't include Acked-by I got for V2

---
 .../devicetree/bindings/thermal/brcm,ns-thermal    | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +26 -0
new file mode 100644
index 000000000000..c561c7349f17
@@ -0,0 +1,26 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU (Device
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal: thermal at 1800c2c0 {
+	compatible = "brcm,ns-thermal";
+	reg = <0x1800c2c0 0x10>;
+	#thermal-sensor-cells = <0>;
+};
+
+thermal-zones {
+	cpu_thermal: cpu-thermal {
+		polling-delay-passive = <0>;
+		polling-delay = <1000>;
+		coefficients = <(-556) 418000>;
+		thermal-sensors = <&thermal>;
+	};
+};
Signature · 1 line
2.11.0
#15 lore raw

PATCH v3 2/2 thermal: broadcom: add Northstar thermal driver

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

---
V2: Make it iProc specific as NSP can also use this driver
Select proper symbols in config ARCH_BCM_IPROC Define PVTMON register bits
Update code selecting temperature monitor mode Thank you Jon!
V3: More details in help message for BCM_NS_THERMAL
Use slope & offset
Drop arch code change (I'll be submitted using a proper tree) Thank you Eduardo!

---
 drivers/thermal/Kconfig               |   5 ++
 drivers/thermal/Makefile              |   1 +
 drivers/thermal/broadcom/Kconfig      |   8 +++
 drivers/thermal/broadcom/Makefile     |   1 +
 drivers/thermal/broadcom/ns-thermal.c | 101 ++++++++++++++++++++++++++++++++++
 5 files changed, 116 insertions(+)
 create mode 100644 drivers/thermal/broadcom/Kconfig
 create mode 100644 drivers/thermal/broadcom/Makefile
 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
drivers/thermal/Kconfig +5 -0
index 776b34396144..008e173ec825 100644
@@ -392,6 +392,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/broadcom/Kconfig"
+endmenu
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
drivers/thermal/Makefile +1 -0
index 7adae2029355..549d81b6363c 100644
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL)	+= clock_cooling.o
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
 # platform thermal drivers
+obj-y				+= broadcom/
 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
drivers/thermal/broadcom/Kconfig new file +8 -0
new file mode 100644
index 000000000000..f0dea8a8e002
@@ -0,0 +1,8 @@
+config BCM_NS_THERMAL
+	tristate "Northstar thermal driver"
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	help
+	  Northstar is a family of SoCs that includes e.g. BCM4708, BCM47081,
+	  BCM4709 and BCM47094. It contains DMU (Device Management Unit) block
+	  with a thermal sensor that allows checking CPU temperature. This
+	  driver provides support for it.
drivers/thermal/broadcom/Makefile new file +1 -0
new file mode 100644
index 000000000000..059df9a0ed69
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/ns-thermal.c new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
2.11.0
#16 lore raw

PATCH v4 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
V3: Add thermal-zones to the example
Rob: Because of this update, I didn't include Acked-by I got for V2

---
 .../devicetree/bindings/thermal/brcm,ns-thermal    | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +26 -0
new file mode 100644
index 000000000000..c561c7349f17
@@ -0,0 +1,26 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU (Device
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal: thermal at 1800c2c0 {
+	compatible = "brcm,ns-thermal";
+	reg = <0x1800c2c0 0x10>;
+	#thermal-sensor-cells = <0>;
+};
+
+thermal-zones {
+	cpu_thermal: cpu-thermal {
+		polling-delay-passive = <0>;
+		polling-delay = <1000>;
+		coefficients = <(-556) 418000>;
+		thermal-sensors = <&thermal>;
+	};
+};
Signature · 1 line
2.11.0
#17 lore raw

PATCH v4 2/2 thermal: broadcom: add Northstar thermal driver

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

---
V2: Make it iProc specific as NSP can also use this driver
Select proper symbols in config ARCH_BCM_IPROC Define PVTMON register bits
Update code selecting temperature monitor mode Thank you Jon!
V3: More details in help message for BCM_NS_THERMAL
Use slope & offset
Drop arch code change (I'll be submitted using a proper tree) Thank you Eduardo!
V4: Comment operations on PVTMON_CONTROL0 register

---
 drivers/thermal/Kconfig               |   5 ++
 drivers/thermal/Makefile              |   1 +
 drivers/thermal/broadcom/Kconfig      |   8 +++
 drivers/thermal/broadcom/Makefile     |   1 +
 drivers/thermal/broadcom/ns-thermal.c | 105 ++++++++++++++++++++++++++++++++++
 5 files changed, 120 insertions(+)
 create mode 100644 drivers/thermal/broadcom/Kconfig
 create mode 100644 drivers/thermal/broadcom/Makefile
 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
drivers/thermal/Kconfig +5 -0
index 776b34396144..008e173ec825 100644
@@ -392,6 +392,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/broadcom/Kconfig"
+endmenu
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
drivers/thermal/Makefile +1 -0
index 7adae2029355..549d81b6363c 100644
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL)	+= clock_cooling.o
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
 # platform thermal drivers
+obj-y				+= broadcom/
 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
drivers/thermal/broadcom/Kconfig new file +8 -0
new file mode 100644
index 000000000000..f0dea8a8e002
@@ -0,0 +1,8 @@
+config BCM_NS_THERMAL
+	tristate "Northstar thermal driver"
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	help
+	  Northstar is a family of SoCs that includes e.g. BCM4708, BCM47081,
+	  BCM4709 and BCM47094. It contains DMU (Device Management Unit) block
+	  with a thermal sensor that allows checking CPU temperature. This
+	  driver provides support for it.
drivers/thermal/broadcom/Makefile new file +1 -0
new file mode 100644
index 000000000000..059df9a0ed69
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/ns-thermal.c new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
2.11.0
#18 lore raw

PATCH v4 2/2 thermal: broadcom: add Northstar thermal driver

Quoted 9 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

---

This driver looks fine from what concerns the of thermal usage. I had only one request on the DT bindings example. I believe better to get the example fixed so bad DTs does not get copied.

Quoted 10 lines

V2: Make it iProc specific as NSP can also use this driver
Select proper symbols in config ARCH_BCM_IPROC Define PVTMON register bits
Update code selecting temperature monitor mode Thank you Jon!
V3: More details in help message for BCM_NS_THERMAL
Use slope & offset
Drop arch code change (I'll be submitted using a proper tree) Thank you Eduardo!
V4: Comment operations on PVTMON_CONTROL0 register

Quoted 6 lines
---
 drivers/thermal/Kconfig               |   5 ++
 drivers/thermal/Makefile              |   1 +
 drivers/thermal/broadcom/Kconfig      |   8 +++
 drivers/thermal/broadcom/Makefile     |   1 +
 drivers/thermal/broadcom/ns-thermal.c | 105 ++++++++++++++++++++++++++++++++++

Also, I have just merged a BRCM driver. Does it make sense to move it here too?

It does not need to be a blocking request for this driver though.

Quoted 168 lines
 5 files changed, 120 insertions(+)
 create mode 100644 drivers/thermal/broadcom/Kconfig
 create mode 100644 drivers/thermal/broadcom/Makefile
 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
drivers/thermal/Kconfig +5 -0
index 776b34396144..008e173ec825 100644
@@ -392,6 +392,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/broadcom/Kconfig"
+endmenu
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
drivers/thermal/Makefile +1 -0
index 7adae2029355..549d81b6363c 100644
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL)	+= clock_cooling.o
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
 # platform thermal drivers
+obj-y				+= broadcom/
 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
drivers/thermal/broadcom/Kconfig new file +8 -0
new file mode 100644
index 000000000000..f0dea8a8e002
@@ -0,0 +1,8 @@
+config BCM_NS_THERMAL
+	tristate "Northstar thermal driver"
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	help
+	  Northstar is a family of SoCs that includes e.g. BCM4708, BCM47081,
+	  BCM4709 and BCM47094. It contains DMU (Device Management Unit) block
+	  with a thermal sensor that allows checking CPU temperature. This
+	  driver provides support for it.
drivers/thermal/broadcom/Makefile new file +1 -0
new file mode 100644
index 000000000000..059df9a0ed69
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/ns-thermal.c new file +105 -0
new file mode 100644
index 000000000000..eab96b3572b9
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2017 Rafa? Mi?ecki <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define PVTMON_CONTROL0					0x00
+#define PVTMON_CONTROL0_SEL_MASK			0x0000000e
+#define PVTMON_CONTROL0_SEL_TEMP_MONITOR		0x00000000
+#define PVTMON_CONTROL0_SEL_TEST_MODE			0x0000000e
+#define PVTMON_STATUS					0x08
+
+struct ns_thermal {
+	struct thermal_zone_device *tz;
+	void __iomem *pvtmon;
+};
+
+static int ns_thermal_get_temp(void *data, int *temp)
+{
+	struct ns_thermal *ns_thermal = data;
+	int offset = thermal_zone_get_offset(ns_thermal->tz);
+	int slope = thermal_zone_get_slope(ns_thermal->tz);
+	u32 val;
+
+	val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
+	if ((val & PVTMON_CONTROL0_SEL_MASK) != PVTMON_CONTROL0_SEL_TEMP_MONITOR) {
+		/* Clear current mode selection */
+		val &= ~PVTMON_CONTROL0_SEL_MASK;
+
+		/* Set temp monitor mode (it's the default actually) */
+		val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;
+
+		writel(val, ns_thermal->pvtmon + PVTMON_CONTROL0);
+	}
+
+	val = readl(ns_thermal->pvtmon + PVTMON_STATUS);
+	*temp = slope * val + offset;
+
+	return 0;
+}
+
+const struct thermal_zone_of_device_ops ns_thermal_ops = {
+	.get_temp = ns_thermal_get_temp,
+};
+
+static int ns_thermal_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ns_thermal *ns_thermal;
+
+	ns_thermal = devm_kzalloc(dev, sizeof(*ns_thermal), GFP_KERNEL);
+	if (!ns_thermal)
+		return -ENOMEM;
+
+	ns_thermal->pvtmon = of_iomap(dev_of_node(dev), 0);
+	if (WARN_ON(!ns_thermal->pvtmon))
+		return -ENOENT;
+
+	ns_thermal->tz = devm_thermal_zone_of_sensor_register(dev, 0,
+							      ns_thermal,
+							      &ns_thermal_ops);
+	if (IS_ERR(ns_thermal->tz)) {
+		iounmap(ns_thermal->pvtmon);
+		return PTR_ERR(ns_thermal->tz);
+	}
+
+	platform_set_drvdata(pdev, ns_thermal);
+
+	return 0;
+}
+
+static int ns_thermal_remove(struct platform_device *pdev)
+{
+	struct ns_thermal *ns_thermal = platform_get_drvdata(pdev);
+
+	iounmap(ns_thermal->pvtmon);
+
+	return 0;
+}
+
+static const struct of_device_id ns_thermal_of_match[] = {
+	{ .compatible = "brcm,ns-thermal", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, ns_thermal_of_match);
+
+static struct platform_driver ns_thermal_driver = {
+	.probe		= ns_thermal_probe,
+	.remove		= ns_thermal_remove,
+	.driver = {
+		.name = "ns-thermal",
+		.of_match_table = ns_thermal_of_match,
+	},
+};
+module_platform_driver(ns_thermal_driver);
+
+MODULE_DESCRIPTION("Northstar thermal driver");
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.11.0
#19 lore raw

PATCH v4 2/2 thermal: broadcom: add Northstar thermal driver

Quoted 2 lines · Eduardo Valentin

Also, I have just merged a BRCM driver. Does it make sense to move it here too?

I think it does make sense to have all Broadcom SoCs thermal drivers under a broadcom/ directory. As a matter of fact, I will be submitting another one (for brcmstb SoCs) shortly. Hi Eduardo,

Signature · 1 line
Florian
#20 lore raw

PATCH v4 2/2 thermal: broadcom: add Northstar thermal driver

In reply to Eduardo Valentin
Quoted 7 lines · Eduardo Valentin
Quoted 6 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

Quoted 7 lines
Quoted 3 lines

---

This driver looks fine from what concerns the of thermal usage. I had only one request on the DT bindings example. I believe better to get the example fixed so bad DTs does not get copied.

Thanks! I'll comment on this in a reply to patch 1/2.

Quoted 17 lines
Quoted 10 lines

V2: Make it iProc specific as NSP can also use this driver
Select proper symbols in config ARCH_BCM_IPROC Define PVTMON register bits
Update code selecting temperature monitor mode Thank you Jon!
V3: More details in help message for BCM_NS_THERMAL
Use slope & offset
Drop arch code change (I'll be submitted using a proper tree) Thank you Eduardo!
V4: Comment operations on PVTMON_CONTROL0 register

Quoted 6 lines
---
 drivers/thermal/Kconfig               |   5 ++
 drivers/thermal/Makefile              |   1 +
 drivers/thermal/broadcom/Kconfig      |   8 +++
 drivers/thermal/broadcom/Makefile     |   1 +
 drivers/thermal/broadcom/ns-thermal.c | 105 ++++++++++++++++++++++++++++++++++
Quoted 4 lines

Also, I have just merged a BRCM driver. Does it make sense to move it here too?

It does not need to be a blocking request for this driver though.

Yes, I plan to send a patch for that after getting this one accepted.

#21 lore raw

PATCH v4 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

In reply to Rafał Miłecki

Rafal,

Quoted 33 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
V3: Add thermal-zones to the example
Rob: Because of this update, I didn't include Acked-by I got for V2

---
 .../devicetree/bindings/thermal/brcm,ns-thermal    | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +14 -0
new file mode 100644
index 000000000000..c561c7349f17
@@ -0,0 +1,26 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU (Device
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal: thermal at 1800c2c0 {
+	compatible = "brcm,ns-thermal";

Documentation/devicetree/bindings/thermal/brcm,ns-thermal line 24

Quoted 10 lines
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +10 -0
+	reg = <0x1800c2c0 0x10>;
+	#thermal-sensor-cells = <0>;
+};
+
+thermal-zones {
+	cpu_thermal: cpu-thermal {
+		polling-delay-passive = <0>;
+		polling-delay = <1000>;
+		coefficients = <(-556) 418000>;
+		thermal-sensors = <&thermal>;

You need to define trips and cooling devices here. Otherwise, makes little sense to have this device in thermal subsystem. Here is an example of minimal set:
https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/commit/?h=linus&id=1e2ac9821de6a85d3e8358f238436708d1d46869

The above has no passive action. It is just gonna shutdown the system if temperature crosses a threshold.

But, a typical cooling device would be CPU frequency throttling. Do you have that up and running in your routers?

Quoted 5 lines
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +2 -0
+	};
+};
Signature · 1 line
2.11.0
#22 lore raw

PATCH v4 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

Quoted 50 lines · Eduardo Valentin
Quoted 33 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
V3: Add thermal-zones to the example
Rob: Because of this update, I didn't include Acked-by I got for V2

---
 .../devicetree/bindings/thermal/brcm,ns-thermal    | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +14 -0
new file mode 100644
index 000000000000..c561c7349f17
@@ -0,0 +1,26 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU (Device
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal: thermal at 1800c2c0 {
+	compatible = "brcm,ns-thermal";

Documentation/devicetree/bindings/thermal/brcm,ns-thermal line 24

Quoted 10 lines
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +10 -0
+	reg = <0x1800c2c0 0x10>;
+	#thermal-sensor-cells = <0>;
+};
+
+thermal-zones {
+	cpu_thermal: cpu-thermal {
+		polling-delay-passive = <0>;
+		polling-delay = <1000>;
+		coefficients = <(-556) 418000>;
+		thermal-sensors = <&thermal>;

You need to define trips and cooling devices here. Otherwise, makes little sense to have this device in thermal subsystem. Here is an example of minimal set:
https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/commit/?h=linus&id=1e2ac9821de6a85d3e8358f238436708d1d46869

Quoted 5 lines

The above has no passive action. It is just gonna shutdown the system if temperature crosses a threshold.

But, a typical cooling device would be CPU frequency throttling. Do you have that up and running in your routers?

I don't have CPU freq throttling, so shutdown will be the only solution for critical temp right now.

I know I should have at least a trip for critical temperature, but the problem is I don't know what value to use. There isn't any info about this in public datasheets. Broadcom's SDK doesn't mention it. Vendors share only the max environment temp, not the max CPU temp.

So for now I only meant to provide user space access to reading current CPU temperature. I could do some stress tests and ask other users to do it as well.

Or maybe I could just put in Documentation some round value that makes more or less sense and then work on a proper content of real DTS files?

Unless we can get some hint from Broadcom people. Jon? Florian? Anyone?

#23 lore raw

PATCH v4 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

Hey,

Quoted 51 lines · Rafa? Mi?ecki
Quoted 50 lines · Eduardo Valentin
Quoted 33 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
V3: Add thermal-zones to the example
Rob: Because of this update, I didn't include Acked-by I got for V2
---
.../devicetree/bindings/thermal/brcm,ns-thermal | 26 ++++++++++++++++++++++

1 file changed, 26 insertions(+)

create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal

Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +14 -0
new file mode 100644
index 000000000000..c561c7349f17
@@ -0,0 +1,26 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU (Device
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal: thermal at 1800c2c0 {
+	compatible = "brcm,ns-thermal";

Documentation/devicetree/bindings/thermal/brcm,ns-thermal line 24

Quoted 10 lines
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +10 -0
+	reg = <0x1800c2c0 0x10>;
+	#thermal-sensor-cells = <0>;
+};
+
+thermal-zones {
+	cpu_thermal: cpu-thermal {
+		polling-delay-passive = <0>;
+		polling-delay = <1000>;
+		coefficients = <(-556) 418000>;
+		thermal-sensors = <&thermal>;

You need to define trips and cooling devices here. Otherwise, makes little sense to have this device in thermal subsystem. Here is an example of minimal set:
https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/commit/?h=linus&id=1e2ac9821de6a85d3e8358f238436708d1d46869

Quoted 8 lines
Quoted 5 lines

The above has no passive action. It is just gonna shutdown the system if temperature crosses a threshold.

But, a typical cooling device would be CPU frequency throttling. Do you have that up and running in your routers?

I don't have CPU freq throttling, so shutdown will be the only solution for critical temp right now.

OK. Is there any plans to get cpu cooling / DVFS working on your boards?

Quoted 3 lines

I know I should have at least a trip for critical temperature, but the problem is I don't know what value to use. There isn't any info about this in public

And that is enough justification to block this to go upstream. We need the correct shutdown threshold value to put as example. If we don't, users of this drivers will be pretty much guessing.

Quoted 2 lines

datasheets. Broadcom's SDK doesn't mention it. Vendors share only the max environment temp, not the max CPU temp.

Silicon goes bad typically at 125C. But that also typically requires a good extrapolation of hotspot(s). Some drivers prefer to play safer and use lower numbers (100C).

Quoted 4 lines

So for now I only meant to provide user space access to reading current CPU temperature. I could do some stress tests and ask other users to do it as well.

I see..

Quoted 3 lines

Or maybe I could just put in Documentation some round value that makes more or less sense and then work on a proper content of real DTS files?

The problem with the above is that I see very commonly examples being copied into DTS. So, better to have a good binding example/documentation. That is what they are for anyway.

Quoted 2 lines

Unless we can get some hint from Broadcom people. Jon? Florian? Anyone?

Yeah, that would be probably best.

#24 lore raw

PATCH v4 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

In reply to Rafał Miłecki
Quoted 80 lines · Rafa? Mi?ecki
Quoted 56 lines · Eduardo Valentin
Quoted 38 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
V3: Add thermal-zones to the example
Rob: Because of this update, I didn't include Acked-by I got for V2

---
 .../devicetree/bindings/thermal/brcm,ns-thermal    | 26
++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/thermal/brcm,ns-thermal

Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +3 -0
new file mode 100644
index 000000000000..c561c7349f17
@@ -0,0 +1,26 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU

(Device

Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +11 -0
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal: thermal at 1800c2c0 {
+       compatible = "brcm,ns-thermal";

Documentation/devicetree/bindings/thermal/brcm,ns-thermal line 24

Quoted 10 lines
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +10 -0
+       reg = <0x1800c2c0 0x10>;
+       #thermal-sensor-cells = <0>;
+};
+
+thermal-zones {
+       cpu_thermal: cpu-thermal {
+               polling-delay-passive = <0>;
+               polling-delay = <1000>;
+               coefficients = <(-556) 418000>;
+               thermal-sensors = <&thermal>;

You need to define trips and cooling devices here. Otherwise, makes little sense to have this device in thermal subsystem. Here is an example of minimal set:

Quoted 8 lines

https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/commit/?h=linus&id=1e2ac9821de6a85d3e8358f238436708d1d46869

The above has no passive action. It is just gonna shutdown the system if temperature crosses a threshold.

But, a typical cooling device would be CPU frequency throttling. Do you have
that up and running in your routers?

I don't have CPU freq throttling, so shutdown will be the only solution for critical temp right now.

I know I should have at least a trip for critical temperature, but the problem
is I don't know what value to use. There isn't any info about this in public datasheets. Broadcom's SDK doesn't mention it. Vendors share only the max environment temp, not the max CPU temp.

So for now I only meant to provide user space access to reading current CPU temperature. I could do some stress tests and ask other users to do it as well.

Quoted 5 lines

Or maybe I could just put in Documentation some round value that makes more or
less sense and then work on a proper content of real DTS files?

Unless we can get some hint from Broadcom people. Jon? Florian? Anyone?

I'll poke around and see if I can find a datasheet for NS/NSP. Worst case, I can ask one of the HW engineers for NSP, and we can use the same value for NS.

#25 lore raw

PATCH v4 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

Quoted 85 lines · Jon Mason
Quoted 84 lines · Rafa? Mi?ecki
Quoted 56 lines · Eduardo Valentin
Quoted 38 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
V3: Add thermal-zones to the example
Rob: Because of this update, I didn't include Acked-by I got for V2

---
 .../devicetree/bindings/thermal/brcm,ns-thermal    | 26
++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/thermal/brcm,ns-thermal

Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +3 -0
new file mode 100644
index 000000000000..c561c7349f17
@@ -0,0 +1,26 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU

(Device

Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +11 -0
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal: thermal at 1800c2c0 {
+       compatible = "brcm,ns-thermal";

Documentation/devicetree/bindings/thermal/brcm,ns-thermal line 24

Quoted 10 lines
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +10 -0
+       reg = <0x1800c2c0 0x10>;
+       #thermal-sensor-cells = <0>;
+};
+
+thermal-zones {
+       cpu_thermal: cpu-thermal {
+               polling-delay-passive = <0>;
+               polling-delay = <1000>;
+               coefficients = <(-556) 418000>;
+               thermal-sensors = <&thermal>;

You need to define trips and cooling devices here. Otherwise, makes little sense to have this device in thermal subsystem. Here is an example of minimal set:

Quoted 8 lines

https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/commit/?h=linus&id=1e2ac9821de6a85d3e8358f238436708d1d46869

The above has no passive action. It is just gonna shutdown the system if temperature crosses a threshold.

But, a typical cooling device would be CPU frequency throttling. Do you have
that up and running in your routers?

I don't have CPU freq throttling, so shutdown will be the only solution for critical temp right now.

I know I should have at least a trip for critical temperature, but the problem
is I don't know what value to use. There isn't any info about this in public datasheets. Broadcom's SDK doesn't mention it. Vendors share only the max environment temp, not the max CPU temp.

So for now I only meant to provide user space access to reading current CPU temperature. I could do some stress tests and ask other users to do it as well.

Or maybe I could just put in Documentation some round value that makes more or
less sense and then work on a proper content of real DTS files?

Quoted 5 lines
Quoted 1 line

Unless we can get some hint from Broadcom people. Jon? Florian? Anyone?

I'll poke around and see if I can find a datasheet for NS/NSP. Worst case, I can ask one of the HW engineers for NSP, and we can use the same value for NS.

In the NS documentation, under "Absolute Maximum Ratings":

The "Maximum Junction Temperature" is 125 C
The "Commercial Ambient Temperature (Operating)" range is 0 to 75 C The "Industrial Ambient Temperature (Operating)" range is -40 to 85 C The "Storage Temperature" range is -40 to 125 C

In the NSP documentation, under "Absolute Maximum Ratings":

The "Maximum Junction Temperature" is 110 C
The "Commercial Ambient Temperature (Operating)" range is 0 to 75 C The "Industrial Ambient Temperature (Operating)" range is -40 to 85 C The "Storage Temperature" range is -40 to 125 C

I believe the first one is the number you are looking for.

Thanks,
Jon

#26 lore raw

PATCH v4 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

Quoted 99 lines · Jon Mason
Quoted 85 lines · Jon Mason
Quoted 84 lines · Rafa? Mi?ecki
Quoted 56 lines · Eduardo Valentin
Quoted 38 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
V3: Add thermal-zones to the example
Rob: Because of this update, I didn't include Acked-by I got for V2

---
 .../devicetree/bindings/thermal/brcm,ns-thermal    | 26
++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/thermal/brcm,ns-thermal

Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +3 -0
new file mode 100644
index 000000000000..c561c7349f17
@@ -0,0 +1,26 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU

(Device

Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +11 -0
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal: thermal at 1800c2c0 {
+       compatible = "brcm,ns-thermal";

Documentation/devicetree/bindings/thermal/brcm,ns-thermal line 24

Quoted 10 lines
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +10 -0
+       reg = <0x1800c2c0 0x10>;
+       #thermal-sensor-cells = <0>;
+};
+
+thermal-zones {
+       cpu_thermal: cpu-thermal {
+               polling-delay-passive = <0>;
+               polling-delay = <1000>;
+               coefficients = <(-556) 418000>;
+               thermal-sensors = <&thermal>;

You need to define trips and cooling devices here. Otherwise, makes little sense to have this device in thermal subsystem. Here is an example of minimal set:

Quoted 8 lines

https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/commit/?h=linus&id=1e2ac9821de6a85d3e8358f238436708d1d46869

The above has no passive action. It is just gonna shutdown the system if temperature crosses a threshold.

But, a typical cooling device would be CPU frequency throttling. Do you have
that up and running in your routers?

I don't have CPU freq throttling, so shutdown will be the only solution for critical temp right now.

I know I should have at least a trip for critical temperature, but the problem
is I don't know what value to use. There isn't any info about this in public datasheets. Broadcom's SDK doesn't mention it. Vendors share only the max environment temp, not the max CPU temp.

So for now I only meant to provide user space access to reading current CPU temperature. I could do some stress tests and ask other users to do it as well.

Or maybe I could just put in Documentation some round value that makes more or
less sense and then work on a proper content of real DTS files?

Quoted 5 lines
Quoted 1 line

Unless we can get some hint from Broadcom people. Jon? Florian? Anyone?

I'll poke around and see if I can find a datasheet for NS/NSP. Worst case, I can ask one of the HW engineers for NSP, and we can use the same value for NS.

In the NS documentation, under "Absolute Maximum Ratings":

The "Maximum Junction Temperature" is 125 C
The "Commercial Ambient Temperature (Operating)" range is 0 to 75 C The "Industrial Ambient Temperature (Operating)" range is -40 to 85 C The "Storage Temperature" range is -40 to 125 C

Quoted 8 lines

In the NSP documentation, under "Absolute Maximum Ratings":

The "Maximum Junction Temperature" is 110 C
The "Commercial Ambient Temperature (Operating)" range is 0 to 75 C The "Industrial Ambient Temperature (Operating)" range is -40 to 85 C The "Storage Temperature" range is -40 to 125 C

I believe the first one is the number you are looking for.

Thanks a lot for this valuable info! I'll send next version today.

#27 lore raw

PATCH v5 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

In reply to Rafał Miłecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

There isn't any known Northstar device with active cooling system so DT example has empty cooling-maps node. There is also no support for CPU frequency throttling so I put only a critical trip in the example.

---
V3: Add thermal-zones to the example
V5: Extend example by including trips and cooling-maps. Update commit message

---
 .../devicetree/bindings/thermal/brcm,ns-thermal    | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal
Documentation/devicetree/bindings/thermal/brcm,ns-thermal new file +37 -0
new file mode 100644
index 000000000000..68e047170039
@@ -0,0 +1,37 @@
+* Broadcom Northstar Thermal
+
+This binding describes thermal sensor that is part of Northstar's DMU (Device
+Management Unit).
+
+Required properties:
+- compatible : Must be "brcm,ns-thermal"
+- reg : iomem address range of PVTMON registers
+- #thermal-sensor-cells : Should be <0>
+
+Example:
+
+thermal: thermal at 1800c2c0 {
+	compatible = "brcm,ns-thermal";
+	reg = <0x1800c2c0 0x10>;
+	#thermal-sensor-cells = <0>;
+};
+
+thermal-zones {
+	cpu_thermal: cpu-thermal {
+		polling-delay-passive = <0>;
+		polling-delay = <1000>;
+		coefficients = <(-556) 418000>;
+		thermal-sensors = <&thermal>;
+
+		trips {
+			cpu-crit {
+				temperature	= <125000>;
+				hysteresis	= <0>;
+				type		= "critical";
+			};
+		};
+
+		cooling-maps {
+		};
+	};
+};
Signature · 1 line
2.11.0
#28 lore raw

PATCH v5 2/2 thermal: broadcom: add Northstar thermal driver

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

---
V2: Make it iProc specific as NSP can also use this driver
Select proper symbols in config ARCH_BCM_IPROC Define PVTMON register bits
Update code selecting temperature monitor mode Thank you Jon!
V3: More details in help message for BCM_NS_THERMAL
Use slope & offset
Drop arch code change (I'll be submitted using a proper tree) Thank you Eduardo!
V4: Comment operations on PVTMON_CONTROL0 register

---
 drivers/thermal/Kconfig               |   5 ++
 drivers/thermal/Makefile              |   1 +
 drivers/thermal/broadcom/Kconfig      |   8 +++
 drivers/thermal/broadcom/Makefile     |   1 +
 drivers/thermal/broadcom/ns-thermal.c | 105 ++++++++++++++++++++++++++++++++++
 5 files changed, 120 insertions(+)
 create mode 100644 drivers/thermal/broadcom/Kconfig
 create mode 100644 drivers/thermal/broadcom/Makefile
 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
drivers/thermal/Kconfig +5 -0
index 3bd24063375e..ac7301703d03 100644
@@ -392,6 +392,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/broadcom/Kconfig"
+endmenu
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
drivers/thermal/Makefile +1 -0
index f23cde05dac6..6b7706b9f27c 100644
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL)	+= clock_cooling.o
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
 # platform thermal drivers
+obj-y				+= broadcom/
 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
drivers/thermal/broadcom/Kconfig new file +8 -0
new file mode 100644
index 000000000000..f0dea8a8e002
@@ -0,0 +1,8 @@
+config BCM_NS_THERMAL
+	tristate "Northstar thermal driver"
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	help
+	  Northstar is a family of SoCs that includes e.g. BCM4708, BCM47081,
+	  BCM4709 and BCM47094. It contains DMU (Device Management Unit) block
+	  with a thermal sensor that allows checking CPU temperature. This
+	  driver provides support for it.
drivers/thermal/broadcom/Makefile new file +1 -0
new file mode 100644
index 000000000000..059df9a0ed69
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/ns-thermal.c new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
2.11.0
#29 lore raw

PATCH v5 2/2 thermal: broadcom: add Northstar thermal driver

Quoted 8 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

If no objection, I am applying this series.

Quoted 116 lines

---
V2: Make it iProc specific as NSP can also use this driver
Select proper symbols in config ARCH_BCM_IPROC Define PVTMON register bits
Update code selecting temperature monitor mode Thank you Jon!
V3: More details in help message for BCM_NS_THERMAL
Use slope & offset
Drop arch code change (I'll be submitted using a proper tree) Thank you Eduardo!
V4: Comment operations on PVTMON_CONTROL0 register

---
 drivers/thermal/Kconfig               |   5 ++
 drivers/thermal/Makefile              |   1 +
 drivers/thermal/broadcom/Kconfig      |   8 +++
 drivers/thermal/broadcom/Makefile     |   1 +
 drivers/thermal/broadcom/ns-thermal.c | 105 ++++++++++++++++++++++++++++++++++
 5 files changed, 120 insertions(+)
 create mode 100644 drivers/thermal/broadcom/Kconfig
 create mode 100644 drivers/thermal/broadcom/Makefile
 create mode 100644 drivers/thermal/broadcom/ns-thermal.c
drivers/thermal/Kconfig +5 -0
index 3bd24063375e..ac7301703d03 100644
@@ -392,6 +392,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/broadcom/Kconfig"
+endmenu
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
drivers/thermal/Makefile +1 -0
index f23cde05dac6..6b7706b9f27c 100644
@@ -27,6 +27,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL)	+= clock_cooling.o
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
 # platform thermal drivers
+obj-y				+= broadcom/
 obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
drivers/thermal/broadcom/Kconfig new file +8 -0
new file mode 100644
index 000000000000..f0dea8a8e002
@@ -0,0 +1,8 @@
+config BCM_NS_THERMAL
+	tristate "Northstar thermal driver"
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	help
+	  Northstar is a family of SoCs that includes e.g. BCM4708, BCM47081,
+	  BCM4709 and BCM47094. It contains DMU (Device Management Unit) block
+	  with a thermal sensor that allows checking CPU temperature. This
+	  driver provides support for it.
drivers/thermal/broadcom/Makefile new file +1 -0
new file mode 100644
index 000000000000..059df9a0ed69
@@ -0,0 +1 @@
+obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
drivers/thermal/broadcom/ns-thermal.c new file +39 -0
new file mode 100644
index 000000000000..eab96b3572b9
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2017 Rafa? Mi?ecki <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#define PVTMON_CONTROL0					0x00
+#define PVTMON_CONTROL0_SEL_MASK			0x0000000e
+#define PVTMON_CONTROL0_SEL_TEMP_MONITOR		0x00000000
+#define PVTMON_CONTROL0_SEL_TEST_MODE			0x0000000e
+#define PVTMON_STATUS					0x08
+
+struct ns_thermal {
+	struct thermal_zone_device *tz;
+	void __iomem *pvtmon;
+};
+
+static int ns_thermal_get_temp(void *data, int *temp)
+{
+	struct ns_thermal *ns_thermal = data;
+	int offset = thermal_zone_get_offset(ns_thermal->tz);
+	int slope = thermal_zone_get_slope(ns_thermal->tz);
+	u32 val;
+
+	val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
+	if ((val & PVTMON_CONTROL0_SEL_MASK) != PVTMON_CONTROL0_SEL_TEMP_MONITOR) {
+		/* Clear current mode selection */
+		val &= ~PVTMON_CONTROL0_SEL_MASK;
+
+		/* Set temp monitor mode (it's the default actually) */
+		val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;
+

drivers/thermal/broadcom/ns-thermal.c line 49

Quoted 10 lines
drivers/thermal/broadcom/ns-thermal.c new file +10 -0
+		writel(val, ns_thermal->pvtmon + PVTMON_CONTROL0);
+	}
+
+	val = readl(ns_thermal->pvtmon + PVTMON_STATUS);
+	*temp = slope * val + offset;
+
+	return 0;
+}
+
+const struct thermal_zone_of_device_ops ns_thermal_ops = {

minor correction here:

-const struct thermal_zone_of_device_ops ns_thermal_ops = { +static const struct thermal_zone_of_device_ops ns_thermal_ops = {

but I am applying this already in my tree.

Quoted 59 lines
drivers/thermal/broadcom/ns-thermal.c new file +56 -0
+	.get_temp = ns_thermal_get_temp,
+};
+
+static int ns_thermal_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ns_thermal *ns_thermal;
+
+	ns_thermal = devm_kzalloc(dev, sizeof(*ns_thermal), GFP_KERNEL);
+	if (!ns_thermal)
+		return -ENOMEM;
+
+	ns_thermal->pvtmon = of_iomap(dev_of_node(dev), 0);
+	if (WARN_ON(!ns_thermal->pvtmon))
+		return -ENOENT;
+
+	ns_thermal->tz = devm_thermal_zone_of_sensor_register(dev, 0,
+							      ns_thermal,
+							      &ns_thermal_ops);
+	if (IS_ERR(ns_thermal->tz)) {
+		iounmap(ns_thermal->pvtmon);
+		return PTR_ERR(ns_thermal->tz);
+	}
+
+	platform_set_drvdata(pdev, ns_thermal);
+
+	return 0;
+}
+
+static int ns_thermal_remove(struct platform_device *pdev)
+{
+	struct ns_thermal *ns_thermal = platform_get_drvdata(pdev);
+
+	iounmap(ns_thermal->pvtmon);
+
+	return 0;
+}
+
+static const struct of_device_id ns_thermal_of_match[] = {
+	{ .compatible = "brcm,ns-thermal", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, ns_thermal_of_match);
+
+static struct platform_driver ns_thermal_driver = {
+	.probe		= ns_thermal_probe,
+	.remove		= ns_thermal_remove,
+	.driver = {
+		.name = "ns-thermal",
+		.of_match_table = ns_thermal_of_match,
+	},
+};
+module_platform_driver(ns_thermal_driver);
+
+MODULE_DESCRIPTION("Northstar thermal driver");
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.11.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170406/53f45255/attachment.sig>

#30 lore raw

PATCH v5 2/2 thermal: broadcom: add Northstar thermal driver

Quoted 11 lines · Eduardo Valentin
Quoted 8 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

If no objection, I am applying this series.

Cool, hopefully there aren't any more objections :) Once applied should I expect this in
https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/log/?h=next
?

That would allow me to move bcm2835_thermal.c to the broadcom subdir.

Quoted 11 lines
Quoted 1 line

+const struct thermal_zone_of_device_ops ns_thermal_ops = {

minor correction here:

(quoted diff) +1 -1
-const struct thermal_zone_of_device_ops ns_thermal_ops = {
+static const struct thermal_zone_of_device_ops ns_thermal_ops = {

but I am applying this already in my tree.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	.get_temp = ns_thermal_get_temp,
+};

Thank you!

#31 lore raw

PATCH v5 2/2 thermal: broadcom: add Northstar thermal driver

Hello Rafal,

Quoted 11 lines · Rafa? Mi?ecki
Quoted 10 lines · Eduardo Valentin
Quoted 8 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

Quoted 6 lines
Quoted 1 line

If no objection, I am applying this series.

Cool, hopefully there aren't any more objections :) Once applied should I expect this in
https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/log/?h=next
?

They were already applied, but in my #linus branch. Now they are also in my #next branch. The #linus branch goes to the coming merge window. The #next branch goes to linux-next testing. Your change is now on linux-next test, kernelci testing, and for the coming merge windown.

Quoted 4 lines

That would allow me to move bcm2835_thermal.c to the broadcom subdir.

Please send the patch.

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

+const struct thermal_zone_of_device_ops ns_thermal_ops = {

minor correction here:

(quoted diff) +1 -1
-const struct thermal_zone_of_device_ops ns_thermal_ops = {
+static const struct thermal_zone_of_device_ops ns_thermal_ops = {
Quoted 6 lines
Quoted 4 lines

but I am applying this already in my tree.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	.get_temp = ns_thermal_get_temp,
+};

Thank you!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170414/d7a4f133/attachment.sig>

#32 lore raw

PATCH v5 2/2 thermal: broadcom: add Northstar thermal driver

Quoted 21 lines · Eduardo Valentin

Hello Rafal,

Quoted 11 lines · Rafa? Mi?ecki
Quoted 10 lines · Eduardo Valentin
Quoted 8 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

Quoted 6 lines
Quoted 1 line

If no objection, I am applying this series.

Cool, hopefully there aren't any more objections :) Once applied should I expect this in
https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/log/?h=next
?

Quoted 4 lines

They were already applied, but in my #linus branch. Now they are also in my #next branch. The #linus branch goes to the coming merge window. The #next branch goes to linux-next testing. Your change is now on linux-next test, kernelci testing, and for the coming merge windown.

I got it, thank you!

Signature · 1 line
Rafa?
#33 lore raw

PATCH v5 2/2 thermal: broadcom: add Northstar thermal driver

In reply to Rafał Miłecki
Quoted 14 lines

Rafa? Mi?ecki <[email protected]> hat am 14. April 2017 um 14:16 geschrieben:

Quoted 10 lines · Eduardo Valentin
Quoted 8 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

Northstar is a SoC family commonly used in home routers. This commit adds a driver for checking CPU temperature. As Northstar Plus seems to also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.

Quoted 8 lines
Quoted 1 line

If no objection, I am applying this series.

Cool, hopefully there aren't any more objections :) Once applied should I expect this in
https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git/log/?h=next
?

That would allow me to move bcm2835_thermal.c to the broadcom subdir.

Thanks for doing this. Btw Northstar thermal driver misses a MODULE_AUTHOR.

Regards
Stefan

maintainer
#34 lore raw

PATCH v5 1/2 dt-bindings: thermal: add support for Broadcom's Northstar thermal

In reply to Rafał Miłecki
Quoted 8 lines · Rafa? Mi?ecki

From: Rafa? Mi?ecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

There isn't any known Northstar device with active cooling system so DT example has empty cooling-maps node. There is also no support for CPU frequency throttling so I put only a critical trip in the example.

Quoted 8 lines

---
V3: Add thermal-zones to the example
V5: Extend example by including trips and cooling-maps. Update commit message

---
 .../devicetree/bindings/thermal/brcm,ns-thermal    | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal
maintainer Acked-by on v1 1/2
#35 lore raw
In reply to Rafał Miłecki
Quoted 9 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This commit documents binding for thermal used in Northstar family SoCs.

---
 .../devicetree/bindings/thermal/brcm,ns-thermal         | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,ns-thermal