All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-05 21:09 ` Markus Mayer
  0 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-05 21:09 UTC (permalink / raw)
  To: Zhang Rui, Eduardo Valentin, Rob Herring, Mark Rutland,
	Doug Berger, Brian Norris, Gregory Fong, Florian Fainelli,
	Rafał Miłecki
  Cc: Markus Mayer, Broadcom Kernel List, Power Management List,
	Device Tree List, ARM Kernel List, Linux Kernel Mailing List

From: Markus Mayer <mmayer@broadcom.com>

This series adds the brcmstb AVS TMON driver.

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

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

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

-- 
2.7.4

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 0/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-05 21:09 ` Markus Mayer
  0 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-05 21:09 UTC (permalink / raw)
  To: Zhang Rui, Eduardo Valentin, Rob Herring, Mark Rutland,
	Doug Berger, Brian Norris, Gregory Fong, Florian Fainelli,
	Rafał Miłecki
  Cc: Markus Mayer, Broadcom Kernel List, Power Management List,
	Device Tree List, ARM Kernel List, Linux Kernel Mailing List

From: Markus Mayer <mmayer-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>

This series adds the brcmstb AVS TMON driver.

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

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

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

-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 0/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-05 21:09 ` Markus Mayer
  0 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-05 21:09 UTC (permalink / raw)
  To: linux-arm-kernel

From: Markus Mayer <mmayer@broadcom.com>

This series adds the brcmstb AVS TMON driver.

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

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

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

-- 
2.7.4

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 1/2] Documentation: devicetree: add binding for Broadcom STB AVS TMON
  2017-06-05 21:09 ` Markus Mayer
@ 2017-06-05 21:09   ` Markus Mayer
  -1 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-05 21:09 UTC (permalink / raw)
  To: Zhang Rui, Eduardo Valentin, Rob Herring, Mark Rutland,
	Doug Berger, Brian Norris, Gregory Fong, Florian Fainelli,
	Rafał Miłecki
  Cc: Broadcom Kernel List, Power Management List, Device Tree List,
	ARM Kernel List, Linux Kernel Mailing List, Markus Mayer

From: Brian Norris <computersforpeace@gmail.com>

Add binding for Broadcom STB thermal.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Markus Mayer <mmayer@broadcom.com>
---
 .../devicetree/bindings/thermal/brcm,avs-tmon.txt    | 20 ++++++++++++++++++++
 MAINTAINERS                                          |  8 ++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt

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

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 1/2] Documentation: devicetree: add binding for Broadcom STB AVS TMON
@ 2017-06-05 21:09   ` Markus Mayer
  0 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-05 21:09 UTC (permalink / raw)
  To: linux-arm-kernel

From: Brian Norris <computersforpeace@gmail.com>

Add binding for Broadcom STB thermal.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Markus Mayer <mmayer@broadcom.com>
---
 .../devicetree/bindings/thermal/brcm,avs-tmon.txt    | 20 ++++++++++++++++++++
 MAINTAINERS                                          |  8 ++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt

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

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 2/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-05 21:09   ` Markus Mayer
  0 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-05 21:09 UTC (permalink / raw)
  To: Zhang Rui, Eduardo Valentin, Rob Herring, Mark Rutland,
	Doug Berger, Brian Norris, Gregory Fong, Florian Fainelli,
	Rafał Miłecki
  Cc: Broadcom Kernel List, Power Management List, Device Tree List,
	ARM Kernel List, Linux Kernel Mailing List, Markus Mayer

From: Brian Norris <computersforpeace@gmail.com>

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

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

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Doug Berger <opendmb@gmail.com>
Signed-off-by: Markus Mayer <mmayer@broadcom.com>
---
 drivers/thermal/broadcom/Kconfig           |   7 +
 drivers/thermal/broadcom/Makefile          |   1 +
 drivers/thermal/broadcom/brcmstb_thermal.c | 361 +++++++++++++++++++++++++++++
 3 files changed, 369 insertions(+)
 create mode 100644 drivers/thermal/broadcom/brcmstb_thermal.c

diff --git a/drivers/thermal/broadcom/Kconfig b/drivers/thermal/broadcom/Kconfig
index ab08af4..12e621d 100644
--- a/drivers/thermal/broadcom/Kconfig
+++ b/drivers/thermal/broadcom/Kconfig
@@ -6,6 +6,13 @@ config BCM2835_THERMAL
 	help
 	  Support for thermal sensors on Broadcom bcm2835 SoCs.
 
+config BRCMSTB_THERMAL
+	tristate "Broadcom STB AVS TMON thermal driver"
+	depends on ARCH_BRCMSTB || COMPILE_TEST
+	help
+	  Enable this driver if you have a Broadcom STB SoC and would like
+	  thermal framework support.
+
 config BCM_NS_THERMAL
 	tristate "Northstar thermal driver"
 	depends on ARCH_BCM_IPROC || COMPILE_TEST
diff --git a/drivers/thermal/broadcom/Makefile b/drivers/thermal/broadcom/Makefile
index c6f62e4..fae10ec 100644
--- a/drivers/thermal/broadcom/Makefile
+++ b/drivers/thermal/broadcom/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_BCM2835_THERMAL)		+= bcm2835_thermal.o
+obj-$(CONFIG_BRCMSTB_THERMAL)		+= brcmstb_thermal.o
 obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
diff --git a/drivers/thermal/broadcom/brcmstb_thermal.c b/drivers/thermal/broadcom/brcmstb_thermal.c
new file mode 100644
index 0000000..027648c
--- /dev/null
+++ b/drivers/thermal/broadcom/brcmstb_thermal.c
@@ -0,0 +1,361 @@
+/*
+ * Broadcom STB AVS TMON thermal sensor driver
+ *
+ * Copyright (c) 2015-2017 Broadcom
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#define DRV_NAME	"brcmstb_thermal"
+
+#define pr_fmt(fmt)	DRV_NAME ": " fmt
+
+#include <linux/bitops.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/irqreturn.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of_device.h>
+#include <linux/thermal.h>
+
+#define AVS_TMON_STATUS			0x00
+ #define AVS_TMON_STATUS_valid_msk	BIT(11)
+ #define AVS_TMON_STATUS_data_msk	GENMASK(10, 1)
+ #define AVS_TMON_STATUS_data_shift	1
+
+#define AVS_TMON_EN_OVERTEMP_RESET	0x04
+ #define AVS_TMON_EN_OVERTEMP_RESET_msk	BIT(0)
+
+#define AVS_TMON_RESET_THRESH		0x08
+ #define AVS_TMON_RESET_THRESH_msk	GENMASK(10, 1)
+ #define AVS_TMON_RESET_THRESH_shift	1
+
+#define AVS_TMON_INT_IDLE_TIME		0x10
+
+#define AVS_TMON_EN_TEMP_INT_SRCS	0x14
+ #define AVS_TMON_EN_TEMP_INT_SRCS_high	BIT(1)
+ #define AVS_TMON_EN_TEMP_INT_SRCS_low	BIT(0)
+
+#define AVS_TMON_INT_THRESH		0x18
+ #define AVS_TMON_INT_THRESH_high_msk	GENMASK(26, 17)
+ #define AVS_TMON_INT_THRESH_high_shift	17
+ #define AVS_TMON_INT_THRESH_low_msk	GENMASK(10, 1)
+ #define AVS_TMON_INT_THRESH_low_shift	1
+
+#define AVS_TMON_TEMP_INT_CODE		0x1c
+#define AVS_TMON_TP_TEST_ENABLE		0x20
+
+enum avs_tmon_trip_type {
+	TMON_TRIP_TYPE_LOW = 0,
+	TMON_TRIP_TYPE_HIGH,
+	TMON_TRIP_TYPE_RESET,
+	TMON_TRIP_TYPE_MAX,
+};
+
+struct avs_tmon_trip {
+	/* HW bit to enable the trip */
+	u32 enable_offs;
+	u32 enable_mask;
+
+	/* HW field to read the trip temperature */
+	u32 reg_offs;
+	u32 reg_msk;
+	int reg_shift;
+};
+
+static struct avs_tmon_trip avs_tmon_trips[] = {
+	/* Trips when temperature is below threshold */
+	[TMON_TRIP_TYPE_LOW] = {
+		.enable_offs	= AVS_TMON_EN_TEMP_INT_SRCS,
+		.enable_mask	= AVS_TMON_EN_TEMP_INT_SRCS_low,
+		.reg_offs	= AVS_TMON_INT_THRESH,
+		.reg_msk	= AVS_TMON_INT_THRESH_low_msk,
+		.reg_shift	= AVS_TMON_INT_THRESH_low_shift,
+	},
+	/* Trips when temperature is above threshold */
+	[TMON_TRIP_TYPE_HIGH] = {
+		.enable_offs	= AVS_TMON_EN_TEMP_INT_SRCS,
+		.enable_mask	= AVS_TMON_EN_TEMP_INT_SRCS_high,
+		.reg_offs	= AVS_TMON_INT_THRESH,
+		.reg_msk	= AVS_TMON_INT_THRESH_high_msk,
+		.reg_shift	= AVS_TMON_INT_THRESH_high_shift,
+	},
+	/* Automatically resets chip when above threshold */
+	[TMON_TRIP_TYPE_RESET] = {
+		.enable_offs	= AVS_TMON_EN_OVERTEMP_RESET,
+		.enable_mask	= AVS_TMON_EN_OVERTEMP_RESET_msk,
+		.reg_offs	= AVS_TMON_RESET_THRESH,
+		.reg_msk	= AVS_TMON_RESET_THRESH_msk,
+		.reg_shift	= AVS_TMON_RESET_THRESH_shift,
+	},
+};
+
+struct brcmstb_thermal_priv {
+	void __iomem *tmon_base;
+	struct device *dev;
+	struct thermal_zone_device *thermal;
+};
+
+/* Convert a HW code to a temperature reading (millidegree celsius) */
+static inline int avs_tmon_code_to_temp(u32 code)
+{
+	return (410040 - (int)((code & 0x3FF) * 487));
+}
+
+/*
+ * Convert a temperature value (millidegree celsius) to a HW code
+ *
+ * @temp: temperature to convert
+ * @low: if true, round toward the low side
+ */
+static inline u32 avs_tmon_temp_to_code(int temp, bool low)
+{
+	if (temp < -88161)
+		return 0x3FF;	/* Maximum code value */
+
+	if (temp >= 410040)
+		return 0;	/* Minimum code value */
+
+	if (low)
+		return (u32)(DIV_ROUND_UP(410040 - temp, 487));
+	else
+		return (u32)((410040 - temp) / 487);
+}
+
+static int brcmstb_get_temp(void *data, int *temp)
+{
+	struct brcmstb_thermal_priv *priv = data;
+	u32 val;
+	long t;
+
+	val = __raw_readl(priv->tmon_base + AVS_TMON_STATUS);
+
+	if (!(val & AVS_TMON_STATUS_valid_msk)) {
+		dev_err(priv->dev, "reading not valid\n");
+
+		return -EIO;
+	}
+
+	val = (val & AVS_TMON_STATUS_data_msk) >> AVS_TMON_STATUS_data_shift;
+
+	t = avs_tmon_code_to_temp(val);
+	if (t < 0)
+		*temp = 0;
+	else
+		*temp = t;
+
+	return 0;
+}
+
+static void avs_tmon_trip_enable(struct brcmstb_thermal_priv *priv,
+				 enum avs_tmon_trip_type type, int en)
+{
+	struct avs_tmon_trip *trip = &avs_tmon_trips[type];
+	u32 val = __raw_readl(priv->tmon_base + trip->enable_offs);
+
+	pr_debug("%s trip, type %d\n", en ? "enable" : "disable", type);
+
+	if (en)
+		val |= trip->enable_mask;
+	else
+		val &= ~trip->enable_mask;
+
+	__raw_writel(val, priv->tmon_base + trip->enable_offs);
+}
+
+static int avs_tmon_get_trip_temp(struct brcmstb_thermal_priv *priv,
+				  enum avs_tmon_trip_type type)
+{
+	struct avs_tmon_trip *trip = &avs_tmon_trips[type];
+	u32 val = __raw_readl(priv->tmon_base + trip->reg_offs);
+
+	val &= trip->reg_msk;
+	val >>= trip->reg_shift;
+
+	return avs_tmon_code_to_temp(val);
+}
+
+static void avs_tmon_set_trip_temp(struct brcmstb_thermal_priv *priv,
+				   enum avs_tmon_trip_type type,
+				   int temp)
+{
+	struct avs_tmon_trip *trip = &avs_tmon_trips[type];
+	u32 val, orig;
+
+	pr_debug("set temp %d to %d\n", type, temp);
+
+	/* round toward low temp for the low interrupt */
+	val = avs_tmon_temp_to_code(temp, type == TMON_TRIP_TYPE_LOW);
+
+	/* TODO: Check for overflow? */
+	val <<= trip->reg_shift;
+	val &= trip->reg_msk;
+
+	orig = __raw_readl(priv->tmon_base + trip->reg_offs);
+	orig &= ~trip->reg_msk;
+	orig |= val;
+	__raw_writel(orig, priv->tmon_base + trip->reg_offs);
+}
+
+static int avs_tmon_get_intr_temp(struct brcmstb_thermal_priv *priv)
+{
+	u32 val;
+
+	val = __raw_readl(priv->tmon_base + AVS_TMON_TEMP_INT_CODE);
+	return avs_tmon_code_to_temp(val);
+}
+
+static irqreturn_t brcmstb_tmon_irq_thread(int irq, void *data)
+{
+	struct brcmstb_thermal_priv *priv = data;
+	int low, high, intr;
+
+	low = avs_tmon_get_trip_temp(priv, TMON_TRIP_TYPE_LOW);
+	high = avs_tmon_get_trip_temp(priv, TMON_TRIP_TYPE_HIGH);
+	intr = avs_tmon_get_intr_temp(priv);
+
+	dev_dbg(priv->dev, "low/intr/high: %d/%d/%d\n",
+			low, intr, high);
+
+	/* Disable high-temp until next threshold shift */
+	if (intr >= high)
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_HIGH, 0);
+	/* Disable low-temp until next threshold shift */
+	if (intr <= low)
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_LOW, 0);
+
+	/*
+	 * Notify using the interrupt temperature, in case the temperature
+	 * changes before it can next be read out
+	 */
+	thermal_zone_device_update(priv->thermal, intr);
+
+	return IRQ_HANDLED;
+}
+
+static int brcmstb_set_trips(void *data, int low, int high)
+{
+	struct brcmstb_thermal_priv *priv = data;
+
+	pr_debug("set trips %d <--> %d\n", low, high);
+
+	if (low) {
+		if (low > INT_MAX)
+			low = INT_MAX;
+		avs_tmon_set_trip_temp(priv, TMON_TRIP_TYPE_LOW, (int)low);
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_LOW, 1);
+	} else {
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_LOW, 0);
+	}
+
+	if (high < ULONG_MAX) {
+		if (high > INT_MAX)
+			high = INT_MAX;
+		avs_tmon_set_trip_temp(priv, TMON_TRIP_TYPE_HIGH, (int)high);
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_HIGH, 1);
+	} else {
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_HIGH, 0);
+	}
+
+	return 0;
+}
+
+static struct thermal_zone_of_device_ops of_ops = {
+	.get_temp	= brcmstb_get_temp,
+	.set_trips	= brcmstb_set_trips,
+};
+
+static const struct of_device_id brcmstb_thermal_id_table[] = {
+	{ .compatible = "brcm,avs-tmon" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, brcmstb_thermal_id_table);
+
+static int brcmstb_thermal_probe(struct platform_device *pdev)
+{
+	struct thermal_zone_device *thermal;
+	struct brcmstb_thermal_priv *priv;
+	struct resource *res;
+	int irq, ret;
+
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	priv->tmon_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(priv->tmon_base))
+		return PTR_ERR(priv->tmon_base);
+
+	priv->dev = &pdev->dev;
+	platform_set_drvdata(pdev, priv);
+
+	thermal = thermal_zone_of_sensor_register(&pdev->dev, 0, priv, &of_ops);
+	if (IS_ERR(thermal)) {
+		ret = PTR_ERR(thermal);
+		dev_err(&pdev->dev, "could not register sensor: %d\n", ret);
+		goto err;
+	}
+
+	priv->thermal = thermal;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "could not get IRQ\n");
+		ret = irq;
+		goto err;
+	}
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+					brcmstb_tmon_irq_thread, IRQF_ONESHOT,
+					DRV_NAME, priv);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "could not request IRQ: %d\n", ret);
+		goto err;
+	}
+
+	dev_info(&pdev->dev, "registered AVS TMON of-sensor driver\n");
+
+	return 0;
+
+err:
+	thermal_zone_of_sensor_unregister(&pdev->dev, priv->thermal);
+	return ret;
+}
+
+static int brcmstb_thermal_exit(struct platform_device *pdev)
+{
+	struct brcmstb_thermal_priv *priv = platform_get_drvdata(pdev);
+	struct thermal_zone_device *thermal = priv->thermal;
+
+	if (thermal)
+		thermal_zone_of_sensor_unregister(&pdev->dev, priv->thermal);
+
+	return 0;
+}
+
+static struct platform_driver brcmstb_thermal_driver = {
+	.probe = brcmstb_thermal_probe,
+	.remove = brcmstb_thermal_exit,
+	.driver = {
+		.name = DRV_NAME,
+		.owner = THIS_MODULE,
+		.of_match_table = brcmstb_thermal_id_table,
+	},
+};
+module_platform_driver(brcmstb_thermal_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Brian Norris");
+MODULE_DESCRIPTION("Broadcom STB AVS TMON thermal driver");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 2/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-05 21:09   ` Markus Mayer
  0 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-05 21:09 UTC (permalink / raw)
  To: Zhang Rui, Eduardo Valentin, Rob Herring, Mark Rutland,
	Doug Berger, Brian Norris, Gregory Fong, Florian Fainelli,
	Rafał Miłecki
  Cc: Broadcom Kernel List, Power Management List, Device Tree List,
	ARM Kernel List, Linux Kernel Mailing List, Markus Mayer

From: Brian Norris <computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

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

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

Signed-off-by: Brian Norris <computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Doug Berger <opendmb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Markus Mayer <mmayer-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
---
 drivers/thermal/broadcom/Kconfig           |   7 +
 drivers/thermal/broadcom/Makefile          |   1 +
 drivers/thermal/broadcom/brcmstb_thermal.c | 361 +++++++++++++++++++++++++++++
 3 files changed, 369 insertions(+)
 create mode 100644 drivers/thermal/broadcom/brcmstb_thermal.c

diff --git a/drivers/thermal/broadcom/Kconfig b/drivers/thermal/broadcom/Kconfig
index ab08af4..12e621d 100644
--- a/drivers/thermal/broadcom/Kconfig
+++ b/drivers/thermal/broadcom/Kconfig
@@ -6,6 +6,13 @@ config BCM2835_THERMAL
 	help
 	  Support for thermal sensors on Broadcom bcm2835 SoCs.
 
+config BRCMSTB_THERMAL
+	tristate "Broadcom STB AVS TMON thermal driver"
+	depends on ARCH_BRCMSTB || COMPILE_TEST
+	help
+	  Enable this driver if you have a Broadcom STB SoC and would like
+	  thermal framework support.
+
 config BCM_NS_THERMAL
 	tristate "Northstar thermal driver"
 	depends on ARCH_BCM_IPROC || COMPILE_TEST
diff --git a/drivers/thermal/broadcom/Makefile b/drivers/thermal/broadcom/Makefile
index c6f62e4..fae10ec 100644
--- a/drivers/thermal/broadcom/Makefile
+++ b/drivers/thermal/broadcom/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_BCM2835_THERMAL)		+= bcm2835_thermal.o
+obj-$(CONFIG_BRCMSTB_THERMAL)		+= brcmstb_thermal.o
 obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
diff --git a/drivers/thermal/broadcom/brcmstb_thermal.c b/drivers/thermal/broadcom/brcmstb_thermal.c
new file mode 100644
index 0000000..027648c
--- /dev/null
+++ b/drivers/thermal/broadcom/brcmstb_thermal.c
@@ -0,0 +1,361 @@
+/*
+ * Broadcom STB AVS TMON thermal sensor driver
+ *
+ * Copyright (c) 2015-2017 Broadcom
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#define DRV_NAME	"brcmstb_thermal"
+
+#define pr_fmt(fmt)	DRV_NAME ": " fmt
+
+#include <linux/bitops.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/irqreturn.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of_device.h>
+#include <linux/thermal.h>
+
+#define AVS_TMON_STATUS			0x00
+ #define AVS_TMON_STATUS_valid_msk	BIT(11)
+ #define AVS_TMON_STATUS_data_msk	GENMASK(10, 1)
+ #define AVS_TMON_STATUS_data_shift	1
+
+#define AVS_TMON_EN_OVERTEMP_RESET	0x04
+ #define AVS_TMON_EN_OVERTEMP_RESET_msk	BIT(0)
+
+#define AVS_TMON_RESET_THRESH		0x08
+ #define AVS_TMON_RESET_THRESH_msk	GENMASK(10, 1)
+ #define AVS_TMON_RESET_THRESH_shift	1
+
+#define AVS_TMON_INT_IDLE_TIME		0x10
+
+#define AVS_TMON_EN_TEMP_INT_SRCS	0x14
+ #define AVS_TMON_EN_TEMP_INT_SRCS_high	BIT(1)
+ #define AVS_TMON_EN_TEMP_INT_SRCS_low	BIT(0)
+
+#define AVS_TMON_INT_THRESH		0x18
+ #define AVS_TMON_INT_THRESH_high_msk	GENMASK(26, 17)
+ #define AVS_TMON_INT_THRESH_high_shift	17
+ #define AVS_TMON_INT_THRESH_low_msk	GENMASK(10, 1)
+ #define AVS_TMON_INT_THRESH_low_shift	1
+
+#define AVS_TMON_TEMP_INT_CODE		0x1c
+#define AVS_TMON_TP_TEST_ENABLE		0x20
+
+enum avs_tmon_trip_type {
+	TMON_TRIP_TYPE_LOW = 0,
+	TMON_TRIP_TYPE_HIGH,
+	TMON_TRIP_TYPE_RESET,
+	TMON_TRIP_TYPE_MAX,
+};
+
+struct avs_tmon_trip {
+	/* HW bit to enable the trip */
+	u32 enable_offs;
+	u32 enable_mask;
+
+	/* HW field to read the trip temperature */
+	u32 reg_offs;
+	u32 reg_msk;
+	int reg_shift;
+};
+
+static struct avs_tmon_trip avs_tmon_trips[] = {
+	/* Trips when temperature is below threshold */
+	[TMON_TRIP_TYPE_LOW] = {
+		.enable_offs	= AVS_TMON_EN_TEMP_INT_SRCS,
+		.enable_mask	= AVS_TMON_EN_TEMP_INT_SRCS_low,
+		.reg_offs	= AVS_TMON_INT_THRESH,
+		.reg_msk	= AVS_TMON_INT_THRESH_low_msk,
+		.reg_shift	= AVS_TMON_INT_THRESH_low_shift,
+	},
+	/* Trips when temperature is above threshold */
+	[TMON_TRIP_TYPE_HIGH] = {
+		.enable_offs	= AVS_TMON_EN_TEMP_INT_SRCS,
+		.enable_mask	= AVS_TMON_EN_TEMP_INT_SRCS_high,
+		.reg_offs	= AVS_TMON_INT_THRESH,
+		.reg_msk	= AVS_TMON_INT_THRESH_high_msk,
+		.reg_shift	= AVS_TMON_INT_THRESH_high_shift,
+	},
+	/* Automatically resets chip when above threshold */
+	[TMON_TRIP_TYPE_RESET] = {
+		.enable_offs	= AVS_TMON_EN_OVERTEMP_RESET,
+		.enable_mask	= AVS_TMON_EN_OVERTEMP_RESET_msk,
+		.reg_offs	= AVS_TMON_RESET_THRESH,
+		.reg_msk	= AVS_TMON_RESET_THRESH_msk,
+		.reg_shift	= AVS_TMON_RESET_THRESH_shift,
+	},
+};
+
+struct brcmstb_thermal_priv {
+	void __iomem *tmon_base;
+	struct device *dev;
+	struct thermal_zone_device *thermal;
+};
+
+/* Convert a HW code to a temperature reading (millidegree celsius) */
+static inline int avs_tmon_code_to_temp(u32 code)
+{
+	return (410040 - (int)((code & 0x3FF) * 487));
+}
+
+/*
+ * Convert a temperature value (millidegree celsius) to a HW code
+ *
+ * @temp: temperature to convert
+ * @low: if true, round toward the low side
+ */
+static inline u32 avs_tmon_temp_to_code(int temp, bool low)
+{
+	if (temp < -88161)
+		return 0x3FF;	/* Maximum code value */
+
+	if (temp >= 410040)
+		return 0;	/* Minimum code value */
+
+	if (low)
+		return (u32)(DIV_ROUND_UP(410040 - temp, 487));
+	else
+		return (u32)((410040 - temp) / 487);
+}
+
+static int brcmstb_get_temp(void *data, int *temp)
+{
+	struct brcmstb_thermal_priv *priv = data;
+	u32 val;
+	long t;
+
+	val = __raw_readl(priv->tmon_base + AVS_TMON_STATUS);
+
+	if (!(val & AVS_TMON_STATUS_valid_msk)) {
+		dev_err(priv->dev, "reading not valid\n");
+
+		return -EIO;
+	}
+
+	val = (val & AVS_TMON_STATUS_data_msk) >> AVS_TMON_STATUS_data_shift;
+
+	t = avs_tmon_code_to_temp(val);
+	if (t < 0)
+		*temp = 0;
+	else
+		*temp = t;
+
+	return 0;
+}
+
+static void avs_tmon_trip_enable(struct brcmstb_thermal_priv *priv,
+				 enum avs_tmon_trip_type type, int en)
+{
+	struct avs_tmon_trip *trip = &avs_tmon_trips[type];
+	u32 val = __raw_readl(priv->tmon_base + trip->enable_offs);
+
+	pr_debug("%s trip, type %d\n", en ? "enable" : "disable", type);
+
+	if (en)
+		val |= trip->enable_mask;
+	else
+		val &= ~trip->enable_mask;
+
+	__raw_writel(val, priv->tmon_base + trip->enable_offs);
+}
+
+static int avs_tmon_get_trip_temp(struct brcmstb_thermal_priv *priv,
+				  enum avs_tmon_trip_type type)
+{
+	struct avs_tmon_trip *trip = &avs_tmon_trips[type];
+	u32 val = __raw_readl(priv->tmon_base + trip->reg_offs);
+
+	val &= trip->reg_msk;
+	val >>= trip->reg_shift;
+
+	return avs_tmon_code_to_temp(val);
+}
+
+static void avs_tmon_set_trip_temp(struct brcmstb_thermal_priv *priv,
+				   enum avs_tmon_trip_type type,
+				   int temp)
+{
+	struct avs_tmon_trip *trip = &avs_tmon_trips[type];
+	u32 val, orig;
+
+	pr_debug("set temp %d to %d\n", type, temp);
+
+	/* round toward low temp for the low interrupt */
+	val = avs_tmon_temp_to_code(temp, type == TMON_TRIP_TYPE_LOW);
+
+	/* TODO: Check for overflow? */
+	val <<= trip->reg_shift;
+	val &= trip->reg_msk;
+
+	orig = __raw_readl(priv->tmon_base + trip->reg_offs);
+	orig &= ~trip->reg_msk;
+	orig |= val;
+	__raw_writel(orig, priv->tmon_base + trip->reg_offs);
+}
+
+static int avs_tmon_get_intr_temp(struct brcmstb_thermal_priv *priv)
+{
+	u32 val;
+
+	val = __raw_readl(priv->tmon_base + AVS_TMON_TEMP_INT_CODE);
+	return avs_tmon_code_to_temp(val);
+}
+
+static irqreturn_t brcmstb_tmon_irq_thread(int irq, void *data)
+{
+	struct brcmstb_thermal_priv *priv = data;
+	int low, high, intr;
+
+	low = avs_tmon_get_trip_temp(priv, TMON_TRIP_TYPE_LOW);
+	high = avs_tmon_get_trip_temp(priv, TMON_TRIP_TYPE_HIGH);
+	intr = avs_tmon_get_intr_temp(priv);
+
+	dev_dbg(priv->dev, "low/intr/high: %d/%d/%d\n",
+			low, intr, high);
+
+	/* Disable high-temp until next threshold shift */
+	if (intr >= high)
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_HIGH, 0);
+	/* Disable low-temp until next threshold shift */
+	if (intr <= low)
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_LOW, 0);
+
+	/*
+	 * Notify using the interrupt temperature, in case the temperature
+	 * changes before it can next be read out
+	 */
+	thermal_zone_device_update(priv->thermal, intr);
+
+	return IRQ_HANDLED;
+}
+
+static int brcmstb_set_trips(void *data, int low, int high)
+{
+	struct brcmstb_thermal_priv *priv = data;
+
+	pr_debug("set trips %d <--> %d\n", low, high);
+
+	if (low) {
+		if (low > INT_MAX)
+			low = INT_MAX;
+		avs_tmon_set_trip_temp(priv, TMON_TRIP_TYPE_LOW, (int)low);
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_LOW, 1);
+	} else {
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_LOW, 0);
+	}
+
+	if (high < ULONG_MAX) {
+		if (high > INT_MAX)
+			high = INT_MAX;
+		avs_tmon_set_trip_temp(priv, TMON_TRIP_TYPE_HIGH, (int)high);
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_HIGH, 1);
+	} else {
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_HIGH, 0);
+	}
+
+	return 0;
+}
+
+static struct thermal_zone_of_device_ops of_ops = {
+	.get_temp	= brcmstb_get_temp,
+	.set_trips	= brcmstb_set_trips,
+};
+
+static const struct of_device_id brcmstb_thermal_id_table[] = {
+	{ .compatible = "brcm,avs-tmon" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, brcmstb_thermal_id_table);
+
+static int brcmstb_thermal_probe(struct platform_device *pdev)
+{
+	struct thermal_zone_device *thermal;
+	struct brcmstb_thermal_priv *priv;
+	struct resource *res;
+	int irq, ret;
+
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	priv->tmon_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(priv->tmon_base))
+		return PTR_ERR(priv->tmon_base);
+
+	priv->dev = &pdev->dev;
+	platform_set_drvdata(pdev, priv);
+
+	thermal = thermal_zone_of_sensor_register(&pdev->dev, 0, priv, &of_ops);
+	if (IS_ERR(thermal)) {
+		ret = PTR_ERR(thermal);
+		dev_err(&pdev->dev, "could not register sensor: %d\n", ret);
+		goto err;
+	}
+
+	priv->thermal = thermal;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "could not get IRQ\n");
+		ret = irq;
+		goto err;
+	}
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+					brcmstb_tmon_irq_thread, IRQF_ONESHOT,
+					DRV_NAME, priv);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "could not request IRQ: %d\n", ret);
+		goto err;
+	}
+
+	dev_info(&pdev->dev, "registered AVS TMON of-sensor driver\n");
+
+	return 0;
+
+err:
+	thermal_zone_of_sensor_unregister(&pdev->dev, priv->thermal);
+	return ret;
+}
+
+static int brcmstb_thermal_exit(struct platform_device *pdev)
+{
+	struct brcmstb_thermal_priv *priv = platform_get_drvdata(pdev);
+	struct thermal_zone_device *thermal = priv->thermal;
+
+	if (thermal)
+		thermal_zone_of_sensor_unregister(&pdev->dev, priv->thermal);
+
+	return 0;
+}
+
+static struct platform_driver brcmstb_thermal_driver = {
+	.probe = brcmstb_thermal_probe,
+	.remove = brcmstb_thermal_exit,
+	.driver = {
+		.name = DRV_NAME,
+		.owner = THIS_MODULE,
+		.of_match_table = brcmstb_thermal_id_table,
+	},
+};
+module_platform_driver(brcmstb_thermal_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Brian Norris");
+MODULE_DESCRIPTION("Broadcom STB AVS TMON thermal driver");
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH 2/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-05 21:09   ` Markus Mayer
  0 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-05 21:09 UTC (permalink / raw)
  To: linux-arm-kernel

From: Brian Norris <computersforpeace@gmail.com>

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

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

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Doug Berger <opendmb@gmail.com>
Signed-off-by: Markus Mayer <mmayer@broadcom.com>
---
 drivers/thermal/broadcom/Kconfig           |   7 +
 drivers/thermal/broadcom/Makefile          |   1 +
 drivers/thermal/broadcom/brcmstb_thermal.c | 361 +++++++++++++++++++++++++++++
 3 files changed, 369 insertions(+)
 create mode 100644 drivers/thermal/broadcom/brcmstb_thermal.c

diff --git a/drivers/thermal/broadcom/Kconfig b/drivers/thermal/broadcom/Kconfig
index ab08af4..12e621d 100644
--- a/drivers/thermal/broadcom/Kconfig
+++ b/drivers/thermal/broadcom/Kconfig
@@ -6,6 +6,13 @@ config BCM2835_THERMAL
 	help
 	  Support for thermal sensors on Broadcom bcm2835 SoCs.
 
+config BRCMSTB_THERMAL
+	tristate "Broadcom STB AVS TMON thermal driver"
+	depends on ARCH_BRCMSTB || COMPILE_TEST
+	help
+	  Enable this driver if you have a Broadcom STB SoC and would like
+	  thermal framework support.
+
 config BCM_NS_THERMAL
 	tristate "Northstar thermal driver"
 	depends on ARCH_BCM_IPROC || COMPILE_TEST
diff --git a/drivers/thermal/broadcom/Makefile b/drivers/thermal/broadcom/Makefile
index c6f62e4..fae10ec 100644
--- a/drivers/thermal/broadcom/Makefile
+++ b/drivers/thermal/broadcom/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_BCM2835_THERMAL)		+= bcm2835_thermal.o
+obj-$(CONFIG_BRCMSTB_THERMAL)		+= brcmstb_thermal.o
 obj-$(CONFIG_BCM_NS_THERMAL)		+= ns-thermal.o
diff --git a/drivers/thermal/broadcom/brcmstb_thermal.c b/drivers/thermal/broadcom/brcmstb_thermal.c
new file mode 100644
index 0000000..027648c
--- /dev/null
+++ b/drivers/thermal/broadcom/brcmstb_thermal.c
@@ -0,0 +1,361 @@
+/*
+ * Broadcom STB AVS TMON thermal sensor driver
+ *
+ * Copyright (c) 2015-2017 Broadcom
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#define DRV_NAME	"brcmstb_thermal"
+
+#define pr_fmt(fmt)	DRV_NAME ": " fmt
+
+#include <linux/bitops.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/irqreturn.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of_device.h>
+#include <linux/thermal.h>
+
+#define AVS_TMON_STATUS			0x00
+ #define AVS_TMON_STATUS_valid_msk	BIT(11)
+ #define AVS_TMON_STATUS_data_msk	GENMASK(10, 1)
+ #define AVS_TMON_STATUS_data_shift	1
+
+#define AVS_TMON_EN_OVERTEMP_RESET	0x04
+ #define AVS_TMON_EN_OVERTEMP_RESET_msk	BIT(0)
+
+#define AVS_TMON_RESET_THRESH		0x08
+ #define AVS_TMON_RESET_THRESH_msk	GENMASK(10, 1)
+ #define AVS_TMON_RESET_THRESH_shift	1
+
+#define AVS_TMON_INT_IDLE_TIME		0x10
+
+#define AVS_TMON_EN_TEMP_INT_SRCS	0x14
+ #define AVS_TMON_EN_TEMP_INT_SRCS_high	BIT(1)
+ #define AVS_TMON_EN_TEMP_INT_SRCS_low	BIT(0)
+
+#define AVS_TMON_INT_THRESH		0x18
+ #define AVS_TMON_INT_THRESH_high_msk	GENMASK(26, 17)
+ #define AVS_TMON_INT_THRESH_high_shift	17
+ #define AVS_TMON_INT_THRESH_low_msk	GENMASK(10, 1)
+ #define AVS_TMON_INT_THRESH_low_shift	1
+
+#define AVS_TMON_TEMP_INT_CODE		0x1c
+#define AVS_TMON_TP_TEST_ENABLE		0x20
+
+enum avs_tmon_trip_type {
+	TMON_TRIP_TYPE_LOW = 0,
+	TMON_TRIP_TYPE_HIGH,
+	TMON_TRIP_TYPE_RESET,
+	TMON_TRIP_TYPE_MAX,
+};
+
+struct avs_tmon_trip {
+	/* HW bit to enable the trip */
+	u32 enable_offs;
+	u32 enable_mask;
+
+	/* HW field to read the trip temperature */
+	u32 reg_offs;
+	u32 reg_msk;
+	int reg_shift;
+};
+
+static struct avs_tmon_trip avs_tmon_trips[] = {
+	/* Trips when temperature is below threshold */
+	[TMON_TRIP_TYPE_LOW] = {
+		.enable_offs	= AVS_TMON_EN_TEMP_INT_SRCS,
+		.enable_mask	= AVS_TMON_EN_TEMP_INT_SRCS_low,
+		.reg_offs	= AVS_TMON_INT_THRESH,
+		.reg_msk	= AVS_TMON_INT_THRESH_low_msk,
+		.reg_shift	= AVS_TMON_INT_THRESH_low_shift,
+	},
+	/* Trips when temperature is above threshold */
+	[TMON_TRIP_TYPE_HIGH] = {
+		.enable_offs	= AVS_TMON_EN_TEMP_INT_SRCS,
+		.enable_mask	= AVS_TMON_EN_TEMP_INT_SRCS_high,
+		.reg_offs	= AVS_TMON_INT_THRESH,
+		.reg_msk	= AVS_TMON_INT_THRESH_high_msk,
+		.reg_shift	= AVS_TMON_INT_THRESH_high_shift,
+	},
+	/* Automatically resets chip when above threshold */
+	[TMON_TRIP_TYPE_RESET] = {
+		.enable_offs	= AVS_TMON_EN_OVERTEMP_RESET,
+		.enable_mask	= AVS_TMON_EN_OVERTEMP_RESET_msk,
+		.reg_offs	= AVS_TMON_RESET_THRESH,
+		.reg_msk	= AVS_TMON_RESET_THRESH_msk,
+		.reg_shift	= AVS_TMON_RESET_THRESH_shift,
+	},
+};
+
+struct brcmstb_thermal_priv {
+	void __iomem *tmon_base;
+	struct device *dev;
+	struct thermal_zone_device *thermal;
+};
+
+/* Convert a HW code to a temperature reading (millidegree celsius) */
+static inline int avs_tmon_code_to_temp(u32 code)
+{
+	return (410040 - (int)((code & 0x3FF) * 487));
+}
+
+/*
+ * Convert a temperature value (millidegree celsius) to a HW code
+ *
+ * @temp: temperature to convert
+ * @low: if true, round toward the low side
+ */
+static inline u32 avs_tmon_temp_to_code(int temp, bool low)
+{
+	if (temp < -88161)
+		return 0x3FF;	/* Maximum code value */
+
+	if (temp >= 410040)
+		return 0;	/* Minimum code value */
+
+	if (low)
+		return (u32)(DIV_ROUND_UP(410040 - temp, 487));
+	else
+		return (u32)((410040 - temp) / 487);
+}
+
+static int brcmstb_get_temp(void *data, int *temp)
+{
+	struct brcmstb_thermal_priv *priv = data;
+	u32 val;
+	long t;
+
+	val = __raw_readl(priv->tmon_base + AVS_TMON_STATUS);
+
+	if (!(val & AVS_TMON_STATUS_valid_msk)) {
+		dev_err(priv->dev, "reading not valid\n");
+
+		return -EIO;
+	}
+
+	val = (val & AVS_TMON_STATUS_data_msk) >> AVS_TMON_STATUS_data_shift;
+
+	t = avs_tmon_code_to_temp(val);
+	if (t < 0)
+		*temp = 0;
+	else
+		*temp = t;
+
+	return 0;
+}
+
+static void avs_tmon_trip_enable(struct brcmstb_thermal_priv *priv,
+				 enum avs_tmon_trip_type type, int en)
+{
+	struct avs_tmon_trip *trip = &avs_tmon_trips[type];
+	u32 val = __raw_readl(priv->tmon_base + trip->enable_offs);
+
+	pr_debug("%s trip, type %d\n", en ? "enable" : "disable", type);
+
+	if (en)
+		val |= trip->enable_mask;
+	else
+		val &= ~trip->enable_mask;
+
+	__raw_writel(val, priv->tmon_base + trip->enable_offs);
+}
+
+static int avs_tmon_get_trip_temp(struct brcmstb_thermal_priv *priv,
+				  enum avs_tmon_trip_type type)
+{
+	struct avs_tmon_trip *trip = &avs_tmon_trips[type];
+	u32 val = __raw_readl(priv->tmon_base + trip->reg_offs);
+
+	val &= trip->reg_msk;
+	val >>= trip->reg_shift;
+
+	return avs_tmon_code_to_temp(val);
+}
+
+static void avs_tmon_set_trip_temp(struct brcmstb_thermal_priv *priv,
+				   enum avs_tmon_trip_type type,
+				   int temp)
+{
+	struct avs_tmon_trip *trip = &avs_tmon_trips[type];
+	u32 val, orig;
+
+	pr_debug("set temp %d to %d\n", type, temp);
+
+	/* round toward low temp for the low interrupt */
+	val = avs_tmon_temp_to_code(temp, type == TMON_TRIP_TYPE_LOW);
+
+	/* TODO: Check for overflow? */
+	val <<= trip->reg_shift;
+	val &= trip->reg_msk;
+
+	orig = __raw_readl(priv->tmon_base + trip->reg_offs);
+	orig &= ~trip->reg_msk;
+	orig |= val;
+	__raw_writel(orig, priv->tmon_base + trip->reg_offs);
+}
+
+static int avs_tmon_get_intr_temp(struct brcmstb_thermal_priv *priv)
+{
+	u32 val;
+
+	val = __raw_readl(priv->tmon_base + AVS_TMON_TEMP_INT_CODE);
+	return avs_tmon_code_to_temp(val);
+}
+
+static irqreturn_t brcmstb_tmon_irq_thread(int irq, void *data)
+{
+	struct brcmstb_thermal_priv *priv = data;
+	int low, high, intr;
+
+	low = avs_tmon_get_trip_temp(priv, TMON_TRIP_TYPE_LOW);
+	high = avs_tmon_get_trip_temp(priv, TMON_TRIP_TYPE_HIGH);
+	intr = avs_tmon_get_intr_temp(priv);
+
+	dev_dbg(priv->dev, "low/intr/high: %d/%d/%d\n",
+			low, intr, high);
+
+	/* Disable high-temp until next threshold shift */
+	if (intr >= high)
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_HIGH, 0);
+	/* Disable low-temp until next threshold shift */
+	if (intr <= low)
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_LOW, 0);
+
+	/*
+	 * Notify using the interrupt temperature, in case the temperature
+	 * changes before it can next be read out
+	 */
+	thermal_zone_device_update(priv->thermal, intr);
+
+	return IRQ_HANDLED;
+}
+
+static int brcmstb_set_trips(void *data, int low, int high)
+{
+	struct brcmstb_thermal_priv *priv = data;
+
+	pr_debug("set trips %d <--> %d\n", low, high);
+
+	if (low) {
+		if (low > INT_MAX)
+			low = INT_MAX;
+		avs_tmon_set_trip_temp(priv, TMON_TRIP_TYPE_LOW, (int)low);
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_LOW, 1);
+	} else {
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_LOW, 0);
+	}
+
+	if (high < ULONG_MAX) {
+		if (high > INT_MAX)
+			high = INT_MAX;
+		avs_tmon_set_trip_temp(priv, TMON_TRIP_TYPE_HIGH, (int)high);
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_HIGH, 1);
+	} else {
+		avs_tmon_trip_enable(priv, TMON_TRIP_TYPE_HIGH, 0);
+	}
+
+	return 0;
+}
+
+static struct thermal_zone_of_device_ops of_ops = {
+	.get_temp	= brcmstb_get_temp,
+	.set_trips	= brcmstb_set_trips,
+};
+
+static const struct of_device_id brcmstb_thermal_id_table[] = {
+	{ .compatible = "brcm,avs-tmon" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, brcmstb_thermal_id_table);
+
+static int brcmstb_thermal_probe(struct platform_device *pdev)
+{
+	struct thermal_zone_device *thermal;
+	struct brcmstb_thermal_priv *priv;
+	struct resource *res;
+	int irq, ret;
+
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	priv->tmon_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(priv->tmon_base))
+		return PTR_ERR(priv->tmon_base);
+
+	priv->dev = &pdev->dev;
+	platform_set_drvdata(pdev, priv);
+
+	thermal = thermal_zone_of_sensor_register(&pdev->dev, 0, priv, &of_ops);
+	if (IS_ERR(thermal)) {
+		ret = PTR_ERR(thermal);
+		dev_err(&pdev->dev, "could not register sensor: %d\n", ret);
+		goto err;
+	}
+
+	priv->thermal = thermal;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "could not get IRQ\n");
+		ret = irq;
+		goto err;
+	}
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+					brcmstb_tmon_irq_thread, IRQF_ONESHOT,
+					DRV_NAME, priv);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "could not request IRQ: %d\n", ret);
+		goto err;
+	}
+
+	dev_info(&pdev->dev, "registered AVS TMON of-sensor driver\n");
+
+	return 0;
+
+err:
+	thermal_zone_of_sensor_unregister(&pdev->dev, priv->thermal);
+	return ret;
+}
+
+static int brcmstb_thermal_exit(struct platform_device *pdev)
+{
+	struct brcmstb_thermal_priv *priv = platform_get_drvdata(pdev);
+	struct thermal_zone_device *thermal = priv->thermal;
+
+	if (thermal)
+		thermal_zone_of_sensor_unregister(&pdev->dev, priv->thermal);
+
+	return 0;
+}
+
+static struct platform_driver brcmstb_thermal_driver = {
+	.probe = brcmstb_thermal_probe,
+	.remove = brcmstb_thermal_exit,
+	.driver = {
+		.name = DRV_NAME,
+		.owner = THIS_MODULE,
+		.of_match_table = brcmstb_thermal_id_table,
+	},
+};
+module_platform_driver(brcmstb_thermal_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Brian Norris");
+MODULE_DESCRIPTION("Broadcom STB AVS TMON thermal driver");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH 2/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-06  7:50     ` kbuild test robot
  0 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2017-06-06  7:50 UTC (permalink / raw)
  To: Markus Mayer
  Cc: kbuild-all, Zhang Rui, Eduardo Valentin, Rob Herring,
	Mark Rutland, Doug Berger, Brian Norris, Gregory Fong,
	Florian Fainelli, Rafał Miłecki, Broadcom Kernel List,
	Power Management List, Device Tree List, ARM Kernel List,
	Linux Kernel Mailing List, Markus Mayer

Hi Brian,

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

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


coccinelle warnings: (new ones prefixed by >>)

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

Please review and possibly fold the followup patch.

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

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH] thermal: fix platform_no_drv_owner.cocci warnings
@ 2017-06-06  7:50     ` kbuild test robot
  0 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2017-06-06  7:50 UTC (permalink / raw)
  To: Markus Mayer
  Cc: kbuild-all, Zhang Rui, Eduardo Valentin, Rob Herring,
	Mark Rutland, Doug Berger, Brian Norris, Gregory Fong,
	Florian Fainelli, Rafał Miłecki, Broadcom Kernel List,
	Power Management List, Device Tree List, ARM Kernel List,
	Linux Kernel Mailing List, Markus Mayer

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

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

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

CC: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---

 brcmstb_thermal.c |    1 -
 1 file changed, 1 deletion(-)

--- a/drivers/thermal/broadcom/brcmstb_thermal.c
+++ b/drivers/thermal/broadcom/brcmstb_thermal.c
@@ -350,7 +350,6 @@ static struct platform_driver brcmstb_th
 	.remove = brcmstb_thermal_exit,
 	.driver = {
 		.name = DRV_NAME,
-		.owner = THIS_MODULE,
 		.of_match_table = brcmstb_thermal_id_table,
 	},
 };

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 2/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-06  7:50     ` kbuild test robot
  0 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2017-06-06  7:50 UTC (permalink / raw)
  To: Markus Mayer
  Cc: kbuild-all-JC7UmRfGjtg, Zhang Rui, Eduardo Valentin, Rob Herring,
	Mark Rutland, Doug Berger, Brian Norris, Gregory Fong,
	Florian Fainelli, Rafał Miłecki, Broadcom Kernel List,
	Power Management List, Device Tree List, ARM Kernel List,
	Linux Kernel Mailing List, Markus Mayer

Hi Brian,

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

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


coccinelle warnings: (new ones prefixed by >>)

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

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH] thermal: fix platform_no_drv_owner.cocci warnings
@ 2017-06-06  7:50     ` kbuild test robot
  0 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2017-06-06  7:50 UTC (permalink / raw)
  To: Markus Mayer
  Cc: kbuild-all-JC7UmRfGjtg, Zhang Rui, Eduardo Valentin, Rob Herring,
	Mark Rutland, Doug Berger, Brian Norris, Gregory Fong,
	Florian Fainelli, Rafał Miłecki, Broadcom Kernel List,
	Power Management List, Device Tree List, ARM Kernel List,
	Linux Kernel Mailing List, Markus Mayer

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

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

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

CC: Brian Norris <computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Fengguang Wu <fengguang.wu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---

 brcmstb_thermal.c |    1 -
 1 file changed, 1 deletion(-)

--- a/drivers/thermal/broadcom/brcmstb_thermal.c
+++ b/drivers/thermal/broadcom/brcmstb_thermal.c
@@ -350,7 +350,6 @@ static struct platform_driver brcmstb_th
 	.remove = brcmstb_thermal_exit,
 	.driver = {
 		.name = DRV_NAME,
-		.owner = THIS_MODULE,
 		.of_match_table = brcmstb_thermal_id_table,
 	},
 };
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 2/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-06  7:50     ` kbuild test robot
  0 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2017-06-06  7:50 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Brian,

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

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


coccinelle warnings: (new ones prefixed by >>)

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

Please review and possibly fold the followup patch.

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

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH] thermal: fix platform_no_drv_owner.cocci warnings
@ 2017-06-06  7:50     ` kbuild test robot
  0 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2017-06-06  7:50 UTC (permalink / raw)
  To: linux-arm-kernel

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

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

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

CC: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---

 brcmstb_thermal.c |    1 -
 1 file changed, 1 deletion(-)

--- a/drivers/thermal/broadcom/brcmstb_thermal.c
+++ b/drivers/thermal/broadcom/brcmstb_thermal.c
@@ -350,7 +350,6 @@ static struct platform_driver brcmstb_th
 	.remove = brcmstb_thermal_exit,
 	.driver = {
 		.name = DRV_NAME,
-		.owner = THIS_MODULE,
 		.of_match_table = brcmstb_thermal_id_table,
 	},
 };

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 1/2] Documentation: devicetree: add binding for Broadcom STB AVS TMON
  2017-06-05 21:09   ` Markus Mayer
  (?)
@ 2017-06-06 12:21     ` Rafał Miłecki
  -1 siblings, 0 replies; 30+ messages in thread
From: Rafał Miłecki @ 2017-06-06 12:21 UTC (permalink / raw)
  To: Markus Mayer
  Cc: Zhang Rui, Eduardo Valentin, Rob Herring, Mark Rutland,
	Doug Berger, Brian Norris, Gregory Fong, Florian Fainelli,
	Broadcom Kernel List, Power Management List, Device Tree List,
	ARM Kernel List, Linux Kernel Mailing List, Markus Mayer

On 2017-06-05 23:09, Markus Mayer wrote:
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt
> @@ -0,0 +1,20 @@
> +* Broadcom STB thermal management
> +
> +Thermal management core, provided by the AVS TMON hardware block.
> +
> +Required properties:
> +- compatible: must be one of "brcm,avs-tmon" or 
> "brcm,avs-tmon-bcm7445"

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


> +- reg: address range for the AVS TMON registers
> +- interrupts: temperature monitor interrupt, for high/low threshold 
> triggers
> +- interrupt-names: should be "tmon"
> +- interrupt-parent: the parent interrupt controller
> +
> +Example:
> +
> +	thermal@f04d1500 {
> +		compatible = "brcm,avs-tmon-bcm7445", "brcm,avs-tmon";

Yet here you use both bindings.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 1/2] Documentation: devicetree: add binding for Broadcom STB AVS TMON
@ 2017-06-06 12:21     ` Rafał Miłecki
  0 siblings, 0 replies; 30+ messages in thread
From: Rafał Miłecki @ 2017-06-06 12:21 UTC (permalink / raw)
  To: Markus Mayer
  Cc: Mark Rutland, Device Tree List, Doug Berger, Markus Mayer,
	Power Management List, Linux Kernel Mailing List,
	Eduardo Valentin, Rob Herring, Broadcom Kernel List,
	Gregory Fong, Florian Fainelli, Zhang Rui, Brian Norris,
	ARM Kernel List

On 2017-06-05 23:09, Markus Mayer wrote:
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt
> @@ -0,0 +1,20 @@
> +* Broadcom STB thermal management
> +
> +Thermal management core, provided by the AVS TMON hardware block.
> +
> +Required properties:
> +- compatible: must be one of "brcm,avs-tmon" or 
> "brcm,avs-tmon-bcm7445"

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


> +- reg: address range for the AVS TMON registers
> +- interrupts: temperature monitor interrupt, for high/low threshold 
> triggers
> +- interrupt-names: should be "tmon"
> +- interrupt-parent: the parent interrupt controller
> +
> +Example:
> +
> +	thermal@f04d1500 {
> +		compatible = "brcm,avs-tmon-bcm7445", "brcm,avs-tmon";

Yet here you use both bindings.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 1/2] Documentation: devicetree: add binding for Broadcom STB AVS TMON
@ 2017-06-06 12:21     ` Rafał Miłecki
  0 siblings, 0 replies; 30+ messages in thread
From: Rafał Miłecki @ 2017-06-06 12:21 UTC (permalink / raw)
  To: linux-arm-kernel

On 2017-06-05 23:09, Markus Mayer wrote:
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt
> @@ -0,0 +1,20 @@
> +* Broadcom STB thermal management
> +
> +Thermal management core, provided by the AVS TMON hardware block.
> +
> +Required properties:
> +- compatible: must be one of "brcm,avs-tmon" or 
> "brcm,avs-tmon-bcm7445"

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


> +- reg: address range for the AVS TMON registers
> +- interrupts: temperature monitor interrupt, for high/low threshold 
> triggers
> +- interrupt-names: should be "tmon"
> +- interrupt-parent: the parent interrupt controller
> +
> +Example:
> +
> +	thermal at f04d1500 {
> +		compatible = "brcm,avs-tmon-bcm7445", "brcm,avs-tmon";

Yet here you use both bindings.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 2/2] thermal: add brcmstb AVS TMON driver
  2017-06-05 21:09   ` Markus Mayer
  (?)
@ 2017-06-06 12:27     ` Rafał Miłecki
  -1 siblings, 0 replies; 30+ messages in thread
From: Rafał Miłecki @ 2017-06-06 12:27 UTC (permalink / raw)
  To: Markus Mayer
  Cc: Zhang Rui, Eduardo Valentin, Rob Herring, Mark Rutland,
	Doug Berger, Brian Norris, Gregory Fong, Florian Fainelli,
	Broadcom Kernel List, Power Management List, Device Tree List,
	ARM Kernel List, Linux Kernel Mailing List, Markus Mayer

On 2017-06-05 23:09, Markus Mayer wrote:
> --- /dev/null
> +++ b/drivers/thermal/broadcom/brcmstb_thermal.c
> @@ -0,0 +1,361 @@
> +/*
> + * Broadcom STB AVS TMON thermal sensor driver
> + *
> + * Copyright (c) 2015-2017 Broadcom
> + *
> + * This software is licensed under the terms of the GNU General Public
> + * License version 2, as published by the Free Software Foundation, 
> and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */

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


> +/* Convert a HW code to a temperature reading (millidegree celsius) */
> +static inline int avs_tmon_code_to_temp(u32 code)
> +{
> +	return (410040 - (int)((code & 0x3FF) * 487));
> +}

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

Hint: thermal_zone_get_offset + thermal_zone_get_slope

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 2/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-06 12:27     ` Rafał Miłecki
  0 siblings, 0 replies; 30+ messages in thread
From: Rafał Miłecki @ 2017-06-06 12:27 UTC (permalink / raw)
  To: Markus Mayer
  Cc: Mark Rutland, Device Tree List, Doug Berger, Markus Mayer,
	Power Management List, Linux Kernel Mailing List,
	Eduardo Valentin, Rob Herring, Broadcom Kernel List,
	Gregory Fong, Florian Fainelli, Zhang Rui, Brian Norris,
	ARM Kernel List

On 2017-06-05 23:09, Markus Mayer wrote:
> --- /dev/null
> +++ b/drivers/thermal/broadcom/brcmstb_thermal.c
> @@ -0,0 +1,361 @@
> +/*
> + * Broadcom STB AVS TMON thermal sensor driver
> + *
> + * Copyright (c) 2015-2017 Broadcom
> + *
> + * This software is licensed under the terms of the GNU General Public
> + * License version 2, as published by the Free Software Foundation, 
> and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */

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


> +/* Convert a HW code to a temperature reading (millidegree celsius) */
> +static inline int avs_tmon_code_to_temp(u32 code)
> +{
> +	return (410040 - (int)((code & 0x3FF) * 487));
> +}

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

Hint: thermal_zone_get_offset + thermal_zone_get_slope

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 2/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-06 12:27     ` Rafał Miłecki
  0 siblings, 0 replies; 30+ messages in thread
From: Rafał Miłecki @ 2017-06-06 12:27 UTC (permalink / raw)
  To: linux-arm-kernel

On 2017-06-05 23:09, Markus Mayer wrote:
> --- /dev/null
> +++ b/drivers/thermal/broadcom/brcmstb_thermal.c
> @@ -0,0 +1,361 @@
> +/*
> + * Broadcom STB AVS TMON thermal sensor driver
> + *
> + * Copyright (c) 2015-2017 Broadcom
> + *
> + * This software is licensed under the terms of the GNU General Public
> + * License version 2, as published by the Free Software Foundation, 
> and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */

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


> +/* Convert a HW code to a temperature reading (millidegree celsius) */
> +static inline int avs_tmon_code_to_temp(u32 code)
> +{
> +	return (410040 - (int)((code & 0x3FF) * 487));
> +}

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

Hint: thermal_zone_get_offset + thermal_zone_get_slope

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 1/2] Documentation: devicetree: add binding for Broadcom STB AVS TMON
  2017-06-06 12:21     ` Rafał Miłecki
@ 2017-06-06 17:07       ` Markus Mayer
  -1 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-06 17:07 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Markus Mayer, Zhang Rui, Eduardo Valentin, Rob Herring,
	Mark Rutland, Doug Berger, Brian Norris, Gregory Fong,
	Florian Fainelli, Broadcom Kernel List, Power Management List,
	Device Tree List, ARM Kernel List, Linux Kernel Mailing List,
	Markus Mayer

On 6 June 2017 at 05:21, Rafał Miłecki <rafal@milecki.pl> wrote:
> On 2017-06-05 23:09, Markus Mayer wrote:
>>
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt
>> @@ -0,0 +1,20 @@
>> +* Broadcom STB thermal management
>> +
>> +Thermal management core, provided by the AVS TMON hardware block.
>> +
>> +Required properties:
>> +- compatible: must be one of "brcm,avs-tmon" or "brcm,avs-tmon-bcm7445"
>
>
> Is the "one of" correct here? I'm not native English but it sounds like
> setting both is a wrong thing.

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

>> +- reg: address range for the AVS TMON registers
>> +- interrupts: temperature monitor interrupt, for high/low threshold
>> triggers
>> +- interrupt-names: should be "tmon"
>> +- interrupt-parent: the parent interrupt controller
>> +
>> +Example:
>> +
>> +       thermal@f04d1500 {
>> +               compatible = "brcm,avs-tmon-bcm7445", "brcm,avs-tmon";
>
>
> Yet here you use both bindings.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 1/2] Documentation: devicetree: add binding for Broadcom STB AVS TMON
@ 2017-06-06 17:07       ` Markus Mayer
  0 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-06 17:07 UTC (permalink / raw)
  To: linux-arm-kernel

On 6 June 2017 at 05:21, Rafa? Mi?ecki <rafal@milecki.pl> wrote:
> On 2017-06-05 23:09, Markus Mayer wrote:
>>
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/thermal/brcm,avs-tmon.txt
>> @@ -0,0 +1,20 @@
>> +* Broadcom STB thermal management
>> +
>> +Thermal management core, provided by the AVS TMON hardware block.
>> +
>> +Required properties:
>> +- compatible: must be one of "brcm,avs-tmon" or "brcm,avs-tmon-bcm7445"
>
>
> Is the "one of" correct here? I'm not native English but it sounds like
> setting both is a wrong thing.

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

>> +- reg: address range for the AVS TMON registers
>> +- interrupts: temperature monitor interrupt, for high/low threshold
>> triggers
>> +- interrupt-names: should be "tmon"
>> +- interrupt-parent: the parent interrupt controller
>> +
>> +Example:
>> +
>> +       thermal at f04d1500 {
>> +               compatible = "brcm,avs-tmon-bcm7445", "brcm,avs-tmon";
>
>
> Yet here you use both bindings.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH 2/2] thermal: add brcmstb AVS TMON driver
  2017-06-06 12:27     ` Rafał Miłecki
@ 2017-06-09 23:07       ` Markus Mayer
  -1 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-09 23:07 UTC (permalink / raw)
  To: Rafał Miłecki, Eduardo Valentin, Zhang Rui
  Cc: Markus Mayer, Rob Herring, Mark Rutland, Doug Berger,
	Brian Norris, Gregory Fong, Florian Fainelli,
	Broadcom Kernel List, Power Management List, Device Tree List,
	ARM Kernel List, Linux Kernel Mailing List, Markus Mayer

On 6 June 2017 at 05:27, Rafał Miłecki <rafal@milecki.pl> wrote:
> On 2017-06-05 23:09, Markus Mayer wrote:
>>
>> --- /dev/null
>> +++ b/drivers/thermal/broadcom/brcmstb_thermal.c
>> @@ -0,0 +1,361 @@
>> +/*
>> + * Broadcom STB AVS TMON thermal sensor driver
>> + *
>> + * Copyright (c) 2015-2017 Broadcom
>> + *
>> + * This software is licensed under the terms of the GNU General Public
>> + * License version 2, as published by the Free Software Foundation, and
>> + * may be copied, distributed, and modified under those terms.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + */
>
> The headers says GPL v2 but it doesn't match MODULE_LICENSE. Please be
> consistent.

Fixed.

>> +/* Convert a HW code to a temperature reading (millidegree celsius) */
>> +static inline int avs_tmon_code_to_temp(u32 code)
>> +{
>> +       return (410040 - (int)((code & 0x3FF) * 487));
>> +}
>
> I got similar hardcoded values and Eduardo told me to move them to the DT.
> See discussion in: https://patchwork.kernel.org/patch/9642119/
>
> Hint: thermal_zone_get_offset + thermal_zone_get_slope

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

In brcmstb_thermal_probe(), we call

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

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

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

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

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

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

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

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

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

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

[    1.323470] brcmstb_thermal: avs_tmon_get_coeffs, 135: slope=-487,
offset=410040, tz=eeb55800

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

Thanks,
-Markus

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH 2/2] thermal: add brcmstb AVS TMON driver
@ 2017-06-09 23:07       ` Markus Mayer
  0 siblings, 0 replies; 30+ messages in thread
From: Markus Mayer @ 2017-06-09 23:07 UTC (permalink / raw)
  To: linux-arm-kernel

On 6 June 2017 at 05:27, Rafa? Mi?ecki <rafal@milecki.pl> wrote:
> On 2017-06-05 23:09, Markus Mayer wrote:
>>
>> --- /dev/null
>> +++ b/drivers/thermal/broadcom/brcmstb_thermal.c
>> @@ -0,0 +1,361 @@
>> +/*
>> + * Broadcom STB AVS TMON thermal sensor driver
>> + *
>> + * Copyright (c) 2015-2017 Broadcom
>> + *
>> + * This software is licensed under the terms of the GNU General Public
>> + * License version 2, as published by the Free Software Foundation, and
>> + * may be copied, distributed, and modified under those terms.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + */
>
> The headers says GPL v2 but it doesn't match MODULE_LICENSE. Please be
> consistent.

Fixed.

>> +/* Convert a HW code to a temperature reading (millidegree celsius) */
>> +static inline int avs_tmon_code_to_temp(u32 code)
>> +{
>> +       return (410040 - (int)((code & 0x3FF) * 487));
>> +}
>
> I got similar hardcoded values and Eduardo told me to move them to the DT.
> See discussion in: https://patchwork.kernel.org/patch/9642119/
>
> Hint: thermal_zone_get_offset + thermal_zone_get_slope

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

In brcmstb_thermal_probe(), we call

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

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

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

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

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

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

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

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

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

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

[    1.323470] brcmstb_thermal: avs_tmon_get_coeffs, 135: slope=-487,
offset=410040, tz=eeb55800

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

Thanks,
-Markus

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] thermal: fix platform_no_drv_owner.cocci warnings
  2019-04-23 19:32 ` [PATCH] thermal: fix platform_no_drv_owner.cocci warnings kbuild test robot
@ 2019-04-28 11:24   ` Shenhar, Talel
  0 siblings, 0 replies; 30+ messages in thread
From: Shenhar, Talel @ 2019-04-28 11:24 UTC (permalink / raw)
  To: kbuild test robot, Eduardo Valentin
  Cc: kbuild-all, linux-pm, David Woodhouse, Daniel Lezcano

Acked-by: Talel Shenhar <talel@amazon.com>


On 4/23/2019 10:32 PM, kbuild test robot wrote:
> From: kbuild test robot <lkp@intel.com>
>
> drivers/thermal/thermal_mmio.c:120:3-8: No need to set .owner here. The core will do it.
>
>   Remove .owner field if calls are used which set it automatically
>
> Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci
>
> Fixes: 35838aa51cd6 ("thermal: Introduce Amazon's Annapurna Labs Thermal Driver")
> CC: Talel Shenhar <talel@amazon.com>
> Signed-off-by: kbuild test robot <lkp@intel.com>
> ---
>
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git for-kernelci
> head:   0e50a5ee6b8a23c6798aae23efcd4b8e055c06ef
> commit: 35838aa51cd6dbf5ae2c78ecd1d1df0cc0324256 [34/35] thermal: Introduce Amazon's Annapurna Labs Thermal Driver
>
>   thermal_mmio.c |    1 -
>   1 file changed, 1 deletion(-)
>
> --- a/drivers/thermal/thermal_mmio.c
> +++ b/drivers/thermal/thermal_mmio.c
> @@ -117,7 +117,6 @@ static struct platform_driver thermal_mm
>   	.probe = thermal_mmio_probe,
>   	.driver = {
>   		.name = "thermal-mmio",
> -		.owner = THIS_MODULE,
>   		.of_match_table = of_match_ptr(thermal_mmio_id_table),
>   	},
>   };

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH] thermal: fix platform_no_drv_owner.cocci warnings
  2019-04-23 19:32 [soc-thermal:for-kernelci 34/35] drivers/thermal/thermal_mmio.c:120:3-8: No need to set .owner here. The core will do it kbuild test robot
@ 2019-04-23 19:32 ` kbuild test robot
  2019-04-28 11:24   ` Shenhar, Talel
  0 siblings, 1 reply; 30+ messages in thread
From: kbuild test robot @ 2019-04-23 19:32 UTC (permalink / raw)
  To: Talel Shenhar
  Cc: kbuild-all, linux-pm, Eduardo Valentin, David Woodhouse, Daniel Lezcano

From: kbuild test robot <lkp@intel.com>

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

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

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

Fixes: 35838aa51cd6 ("thermal: Introduce Amazon's Annapurna Labs Thermal Driver")
CC: Talel Shenhar <talel@amazon.com>
Signed-off-by: kbuild test robot <lkp@intel.com>
---

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git for-kernelci
head:   0e50a5ee6b8a23c6798aae23efcd4b8e055c06ef
commit: 35838aa51cd6dbf5ae2c78ecd1d1df0cc0324256 [34/35] thermal: Introduce Amazon's Annapurna Labs Thermal Driver

 thermal_mmio.c |    1 -
 1 file changed, 1 deletion(-)

--- a/drivers/thermal/thermal_mmio.c
+++ b/drivers/thermal/thermal_mmio.c
@@ -117,7 +117,6 @@ static struct platform_driver thermal_mm
 	.probe = thermal_mmio_probe,
 	.driver = {
 		.name = "thermal-mmio",
-		.owner = THIS_MODULE,
 		.of_match_table = of_match_ptr(thermal_mmio_id_table),
 	},
 };

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] Thermal: fix platform_no_drv_owner.cocci warnings
  2014-12-21 14:21 ` [PATCH] Thermal: " kbuild test robot
@ 2014-12-22  1:54   ` Aaron Lu
  0 siblings, 0 replies; 30+ messages in thread
From: Aaron Lu @ 2014-12-22  1:54 UTC (permalink / raw)
  To: kbuild test robot
  Cc: kbuild-all, Zhang Rui, Eduardo Valentin, linux-pm, linux-kernel

On 12/21/2014 10:21 PM, kbuild test robot wrote:
> drivers/thermal/int340x_thermal/int3402_thermal.c:234:6-11: No need to set .owner here. The core will do it.
> 
>  Remove .owner field if calls are used which set it automatically
> 
> Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci
> 
> CC: Aaron Lu <aaron.lu@intel.com>
> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>

Looks good to me, thanks!

-Aaron

> ---
> 
>  int3402_thermal.c |    1 -
>  1 file changed, 1 deletion(-)
> 
> --- a/drivers/thermal/int340x_thermal/int3402_thermal.c
> +++ b/drivers/thermal/int340x_thermal/int3402_thermal.c
> @@ -231,7 +231,6 @@ static struct platform_driver int3402_th
>  	.remove = int3402_thermal_remove,
>  	.driver = {
>  		   .name = "int3402 thermal",
> -		   .owner = THIS_MODULE,
>  		   .acpi_match_table = int3402_thermal_match,
>  		   },
>  };
> 


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH] Thermal: fix platform_no_drv_owner.cocci warnings
       [not found] <201412212210.5BfVGAAA%fengguang.wu@intel.com>
@ 2014-12-21 14:21 ` kbuild test robot
  2014-12-22  1:54   ` Aaron Lu
  0 siblings, 1 reply; 30+ messages in thread
From: kbuild test robot @ 2014-12-21 14:21 UTC (permalink / raw)
  To: Aaron Lu; +Cc: kbuild-all, Zhang Rui, Eduardo Valentin, linux-pm, linux-kernel

drivers/thermal/int340x_thermal/int3402_thermal.c:234:6-11: No need to set .owner here. The core will do it.

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

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

CC: Aaron Lu <aaron.lu@intel.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---

 int3402_thermal.c |    1 -
 1 file changed, 1 deletion(-)

--- a/drivers/thermal/int340x_thermal/int3402_thermal.c
+++ b/drivers/thermal/int340x_thermal/int3402_thermal.c
@@ -231,7 +231,6 @@ static struct platform_driver int3402_th
 	.remove = int3402_thermal_remove,
 	.driver = {
 		   .name = "int3402 thermal",
-		   .owner = THIS_MODULE,
 		   .acpi_match_table = int3402_thermal_match,
 		   },
 };

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] Thermal: fix platform_no_drv_owner.cocci warnings
  2014-11-17  6:24 ` Fengguang Wu
@ 2014-11-17  7:57   ` Zhang Rui
  0 siblings, 0 replies; 30+ messages in thread
From: Zhang Rui @ 2014-11-17  7:57 UTC (permalink / raw)
  To: Fengguang Wu; +Cc: linux-pm, Lan Tianyu, LKML

On 一, 2014-11-17 at 14:24 +0800, Fengguang Wu wrote:
> drivers/thermal/int340x_thermal/int3403_thermal.c:468:3-8: No need to set .owner here. The core will do it.
> 
>  Remove .owner field if calls are used which set it automatically
> 
> Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci
> 
> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>

Acked-by: Zhang Rui <rui.zhang@intel.com>

thanks,
rui
> ---
> 
>  int3403_thermal.c |    1 -
>  1 file changed, 1 deletion(-)
> 
> --- a/drivers/thermal/int340x_thermal/int3403_thermal.c
> +++ b/drivers/thermal/int340x_thermal/int3403_thermal.c
> @@ -465,7 +465,6 @@ static struct platform_driver int3403_dr
>  	.remove = int3403_remove,
>  	.driver = {
>  		.name = "int3403 thermal",
> -		.owner  = THIS_MODULE,
>  		.acpi_match_table = int3403_device_ids,
>  	},
>  };



^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH] Thermal: fix platform_no_drv_owner.cocci warnings
       [not found] <201411161721.jEzvtBAi%fengguang.wu@intel.com>
@ 2014-11-17  6:24 ` Fengguang Wu
  2014-11-17  7:57   ` Zhang Rui
  0 siblings, 1 reply; 30+ messages in thread
From: Fengguang Wu @ 2014-11-17  6:24 UTC (permalink / raw)
  To: linux-pm; +Cc: Lan Tianyu, Zhang Rui, LKML

drivers/thermal/int340x_thermal/int3403_thermal.c:468:3-8: No need to set .owner here. The core will do it.

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

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

Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---

 int3403_thermal.c |    1 -
 1 file changed, 1 deletion(-)

--- a/drivers/thermal/int340x_thermal/int3403_thermal.c
+++ b/drivers/thermal/int340x_thermal/int3403_thermal.c
@@ -465,7 +465,6 @@ static struct platform_driver int3403_dr
 	.remove = int3403_remove,
 	.driver = {
 		.name = "int3403 thermal",
-		.owner  = THIS_MODULE,
 		.acpi_match_table = int3403_device_ids,
 	},
 };

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2019-04-28 11:24 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-05 21:09 [PATCH 0/2] thermal: add brcmstb AVS TMON driver Markus Mayer
2017-06-05 21:09 ` Markus Mayer
2017-06-05 21:09 ` Markus Mayer
2017-06-05 21:09 ` [PATCH 1/2] Documentation: devicetree: add binding for Broadcom STB AVS TMON Markus Mayer
2017-06-05 21:09   ` Markus Mayer
2017-06-06 12:21   ` Rafał Miłecki
2017-06-06 12:21     ` Rafał Miłecki
2017-06-06 12:21     ` Rafał Miłecki
2017-06-06 17:07     ` Markus Mayer
2017-06-06 17:07       ` Markus Mayer
2017-06-05 21:09 ` [PATCH 2/2] thermal: add brcmstb AVS TMON driver Markus Mayer
2017-06-05 21:09   ` Markus Mayer
2017-06-05 21:09   ` Markus Mayer
2017-06-06  7:50   ` [PATCH] thermal: fix platform_no_drv_owner.cocci warnings kbuild test robot
2017-06-06  7:50     ` kbuild test robot
2017-06-06  7:50     ` kbuild test robot
2017-06-06  7:50   ` [PATCH 2/2] thermal: add brcmstb AVS TMON driver kbuild test robot
2017-06-06  7:50     ` kbuild test robot
2017-06-06  7:50     ` kbuild test robot
2017-06-06 12:27   ` Rafał Miłecki
2017-06-06 12:27     ` Rafał Miłecki
2017-06-06 12:27     ` Rafał Miłecki
2017-06-09 23:07     ` Markus Mayer
2017-06-09 23:07       ` Markus Mayer
  -- strict thread matches above, loose matches on Subject: below --
2019-04-23 19:32 [soc-thermal:for-kernelci 34/35] drivers/thermal/thermal_mmio.c:120:3-8: No need to set .owner here. The core will do it kbuild test robot
2019-04-23 19:32 ` [PATCH] thermal: fix platform_no_drv_owner.cocci warnings kbuild test robot
2019-04-28 11:24   ` Shenhar, Talel
     [not found] <201412212210.5BfVGAAA%fengguang.wu@intel.com>
2014-12-21 14:21 ` [PATCH] Thermal: " kbuild test robot
2014-12-22  1:54   ` Aaron Lu
     [not found] <201411161721.jEzvtBAi%fengguang.wu@intel.com>
2014-11-17  6:24 ` Fengguang Wu
2014-11-17  7:57   ` Zhang Rui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.