All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support
@ 2022-04-12 10:14 Keerthy
  2022-04-12 10:14 ` [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation Keerthy
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Keerthy @ 2022-04-12 10:14 UTC (permalink / raw)
  To: robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: j-keerthy, linux-pm, vigneshr, devicetree, linux-kernel

Add VTM thermal support. In the Voltage Thermal Management
Module(VTM), K3 J72XX supplies a voltage reference and a temperature
sensor feature that are gathered in the band gap voltage and
temperature sensor (VBGAPTS) module. The band gap provides current and
voltage reference for its internal circuits and other analog IP
blocks. The analog-to-digital converter (ADC) produces an output value
that is proportional to the silicon temperature.

Currently reading temperatures only is supported.  There are no
active/passive cooling agent supported.

J721e SoCs have errata i2128: https://www.ti.com/lit/pdf/sprz455

The series also incorporates workaround for Errata i2128.

Daniel,

Apologies for the long silence on this!

- Keerthy

Changes in v5:

  * Fixed all the comments on v4.
  * Simplified the computation of the table.
  * Removed unnecessary members in the structures.

Changes in v4:

  * Fixed compilation warning with W=1.

Changes in v3:

  * Removed static look up tables & added functions to dynamically generate them.

Changes in v2:

  * Fixed DT binding errors.

Keerthy (4):
  dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation
  arm64: dts: ti: j721e: Add VTM node
  arm64: dts: ti: j7200: Add VTM node
  thermal: k3_j72xx_bandgap: Add the bandgap driver support

 .../bindings/thermal/ti,j72xx-thermal.yaml    |  62 ++
 .../boot/dts/ti/k3-j7200-mcu-wakeup.dtsi      |   9 +
 arch/arm64/boot/dts/ti/k3-j7200-thermal.dtsi  |  45 ++
 arch/arm64/boot/dts/ti/k3-j7200.dtsi          |   4 +
 .../boot/dts/ti/k3-j721e-mcu-wakeup.dtsi      |   9 +
 arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi  |  73 ++
 arch/arm64/boot/dts/ti/k3-j721e.dtsi          |   4 +
 drivers/thermal/Makefile                      |   2 +-
 drivers/thermal/k3_j72xx_bandgap.c            | 623 ++++++++++++++++++
 9 files changed, 830 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
 create mode 100644 arch/arm64/boot/dts/ti/k3-j7200-thermal.dtsi
 create mode 100644 arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi
 create mode 100644 drivers/thermal/k3_j72xx_bandgap.c

-- 
2.17.1


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

* [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation
  2022-04-12 10:14 [PATCH v5 0/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
@ 2022-04-12 10:14 ` Keerthy
  2022-04-13  8:07   ` Daniel Lezcano
  2022-04-13 10:13   ` Krzysztof Kozlowski
  2022-04-12 10:14 ` [PATCH v5 2/4] arm64: dts: ti: j721e: Add VTM node Keerthy
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 20+ messages in thread
From: Keerthy @ 2022-04-12 10:14 UTC (permalink / raw)
  To: robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: j-keerthy, linux-pm, vigneshr, devicetree, linux-kernel

Add VTM bindings documentation. In the Voltage Thermal
Management Module(VTM), K3 J72XX supplies a voltage
reference and a temperature sensor feature that are gathered in the band
gap voltage and temperature sensor (VBGAPTS) module. The band
gap provides current and voltage reference for its internal
circuits and other analog IP blocks. The analog-to-digital
converter (ADC) produces an output value that is proportional
to the silicon temperature.

Signed-off-by: Keerthy <j-keerthy@ti.com>
---
 .../bindings/thermal/ti,j72xx-thermal.yaml    | 62 +++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml

diff --git a/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml b/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
new file mode 100644
index 000000000000..8483c495cb9a
--- /dev/null
+++ b/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/thermal/ti,j72xx-thermal.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments J72XX VTM (DTS) binding
+
+maintainers:
+  - Keerthy <j-keerthy@ti.com>
+
+properties:
+  compatible:
+    const: ti,j721e-vtm
+    oneOf:
+      - enum:
+          - ti,j721e-vtm
+          - ti,j7200-vtm
+
+  reg:
+    maxItems: 3
+
+  power-domains:
+    maxItems: 1
+
+  "#thermal-sensor-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - power-domains
+  - "#thermal-sensor-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/soc/ti,sci_pm_domain.h>
+    wkup_vtm0: wkup_vtm0@42040000 {
+        compatible = "ti,j721e-vtm";
+        reg = <0x42040000 0x350>,
+            <0x42050000 0x350>,
+            <0x43000300 0x10>;
+        power-domains = <&k3_pds 154 TI_SCI_PD_EXCLUSIVE>;
+        #thermal-sensor-cells = <1>;
+    };
+
+    mpu_thermal: mpu_thermal {
+        polling-delay-passive = <250>; /* milliseconds */
+        polling-delay = <500>; /* milliseconds */
+        thermal-sensors = <&wkup_vtm0 0>;
+
+        trips {
+                mpu_crit: mpu_crit {
+                        temperature = <125000>; /* milliCelsius */
+                        hysteresis = <2000>; /* milliCelsius */
+                        type = "critical";
+                };
+        };
+    };
+...
-- 
2.17.1


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

* [PATCH v5 2/4] arm64: dts: ti: j721e: Add VTM node
  2022-04-12 10:14 [PATCH v5 0/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
  2022-04-12 10:14 ` [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation Keerthy
@ 2022-04-12 10:14 ` Keerthy
  2022-04-12 17:09   ` Vignesh Raghavendra
  2022-04-13 10:14   ` Krzysztof Kozlowski
  2022-04-12 10:14 ` [PATCH v5 3/4] arm64: dts: ti: j7200: " Keerthy
  2022-04-12 10:14 ` [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
  3 siblings, 2 replies; 20+ messages in thread
From: Keerthy @ 2022-04-12 10:14 UTC (permalink / raw)
  To: robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: j-keerthy, linux-pm, vigneshr, devicetree, linux-kernel

VTM stands for Voltage Thermal Management

Signed-off-by: Keerthy <j-keerthy@ti.com>
---
 .../boot/dts/ti/k3-j721e-mcu-wakeup.dtsi      |  9 +++
 arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi  | 73 +++++++++++++++++++
 arch/arm64/boot/dts/ti/k3-j721e.dtsi          |  4 +
 3 files changed, 86 insertions(+)
 create mode 100644 arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi

diff --git a/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi b/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
index b4972dfb7da8..6290f563b8e7 100644
--- a/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
@@ -418,4 +418,13 @@
 		interrupt-names = "int0", "int1";
 		bosch,mram-cfg = <0x0 128 64 64 64 64 32 32>;
 	};
+
+	wkup_vtm0: wkup_vtm0@42040000 {
+		compatible = "ti,j721e-vtm";
+		reg = <0x0 0x42040000 0x0 0x350>,
+			<0x0 0x42050000 0x0 0x350>,
+			<0x0 0x43000300 0x0 0x10>;
+		power-domains = <&k3_pds 154 TI_SCI_PD_EXCLUSIVE>;
+		#thermal-sensor-cells = <1>;
+	};
 };
diff --git a/arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi b/arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi
new file mode 100644
index 000000000000..e922042f356f
--- /dev/null
+++ b/arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <dt-bindings/thermal/thermal.h>
+
+wkup_thermal: wkup_thermal {
+	polling-delay-passive = <250>; /* milliseconds */
+	polling-delay = <500>; /* milliseconds */
+	thermal-sensors = <&wkup_vtm0 0>;
+
+	trips {
+		wkup_crit: wkup_crit {
+			temperature = <125000>; /* milliCelsius */
+			hysteresis = <2000>; /* milliCelsius */
+			type = "critical";
+		};
+	};
+};
+
+mpu_thermal: mpu_thermal {
+	polling-delay-passive = <250>; /* milliseconds */
+	polling-delay = <500>; /* milliseconds */
+	thermal-sensors = <&wkup_vtm0 1>;
+
+	trips {
+		mpu_crit: mpu_crit {
+			temperature = <125000>; /* milliCelsius */
+			hysteresis = <2000>; /* milliCelsius */
+			type = "critical";
+		};
+	};
+};
+
+c7x_thermal: c7x_thermal {
+	polling-delay-passive = <250>; /* milliseconds */
+	polling-delay = <500>; /* milliseconds */
+	thermal-sensors = <&wkup_vtm0 2>;
+
+	trips {
+		c7x_crit: c7x_crit {
+			temperature = <125000>; /* milliCelsius */
+			hysteresis = <2000>; /* milliCelsius */
+			type = "critical";
+		};
+	};
+};
+
+gpu_thermal: gpu_thermal {
+	polling-delay-passive = <250>; /* milliseconds */
+	polling-delay = <500>; /* milliseconds */
+	thermal-sensors = <&wkup_vtm0 3>;
+
+	trips {
+		gpu_crit: gpu_crit {
+			temperature = <125000>; /* milliCelsius */
+			hysteresis = <2000>; /* milliCelsius */
+			type = "critical";
+		};
+	};
+};
+
+r5f_thermal: r5f_thermal {
+	polling-delay-passive = <250>; /* milliseconds */
+	polling-delay = <500>; /* milliseconds */
+	thermal-sensors = <&wkup_vtm0 4>;
+
+	trips {
+		r5f_crit: r5f_crit {
+			temperature = <125000>; /* milliCelsius */
+			hysteresis = <2000>; /* milliCelsius */
+			type = "critical";
+		};
+	};
+};
diff --git a/arch/arm64/boot/dts/ti/k3-j721e.dtsi b/arch/arm64/boot/dts/ti/k3-j721e.dtsi
index 0e23886c9fd1..6979863eb500 100644
--- a/arch/arm64/boot/dts/ti/k3-j721e.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-j721e.dtsi
@@ -181,6 +181,10 @@
 				 <0x07 0x00000000 0x07 0x00000000 0x01 0x00000000>; /* FSS OSPI1 data region 3*/
 		};
 	};
+
+	thermal_zones: thermal-zones {
+		#include "k3-j721e-thermal.dtsi"
+	};
 };
 
 /* Now include the peripherals for each bus segments */
-- 
2.17.1


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

* [PATCH v5 3/4] arm64: dts: ti: j7200: Add VTM node
  2022-04-12 10:14 [PATCH v5 0/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
  2022-04-12 10:14 ` [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation Keerthy
  2022-04-12 10:14 ` [PATCH v5 2/4] arm64: dts: ti: j721e: Add VTM node Keerthy
@ 2022-04-12 10:14 ` Keerthy
  2022-04-13 10:14   ` Krzysztof Kozlowski
  2022-04-12 10:14 ` [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
  3 siblings, 1 reply; 20+ messages in thread
From: Keerthy @ 2022-04-12 10:14 UTC (permalink / raw)
  To: robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: j-keerthy, linux-pm, vigneshr, devicetree, linux-kernel

VTM stands for Voltage Thermal Management

Signed-off-by: Keerthy <j-keerthy@ti.com>
---
 .../boot/dts/ti/k3-j7200-mcu-wakeup.dtsi      |  9 ++++
 arch/arm64/boot/dts/ti/k3-j7200-thermal.dtsi  | 45 +++++++++++++++++++
 arch/arm64/boot/dts/ti/k3-j7200.dtsi          |  4 ++
 3 files changed, 58 insertions(+)
 create mode 100644 arch/arm64/boot/dts/ti/k3-j7200-thermal.dtsi

diff --git a/arch/arm64/boot/dts/ti/k3-j7200-mcu-wakeup.dtsi b/arch/arm64/boot/dts/ti/k3-j7200-mcu-wakeup.dtsi
index 1044ec6c4b0d..2b5c570253cc 100644
--- a/arch/arm64/boot/dts/ti/k3-j7200-mcu-wakeup.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-j7200-mcu-wakeup.dtsi
@@ -375,4 +375,13 @@
 			ti,loczrama = <1>;
 		};
 	};
+
+	wkup_vtm0: wkup_vtm0@42040000 {
+		compatible = "ti,j7200-vtm";
+		reg = <0x0 0x42040000 0x0 0x350>,
+			<0x0 0x42050000 0x0 0x350>,
+			<0x0 0x43000300 0x0 0x10>;
+		power-domains = <&k3_pds 154 TI_SCI_PD_EXCLUSIVE>;
+		#thermal-sensor-cells = <1>;
+	};
 };
diff --git a/arch/arm64/boot/dts/ti/k3-j7200-thermal.dtsi b/arch/arm64/boot/dts/ti/k3-j7200-thermal.dtsi
new file mode 100644
index 000000000000..1f18f9dcd3e9
--- /dev/null
+++ b/arch/arm64/boot/dts/ti/k3-j7200-thermal.dtsi
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <dt-bindings/thermal/thermal.h>
+
+mcu_thermal: mcu_thermal {
+	polling-delay-passive = <250>; /* milliseconds */
+	polling-delay = <500>; /* milliseconds */
+	thermal-sensors = <&wkup_vtm0 0>;
+
+	trips {
+		wkup_crit: wkup_crit {
+			temperature = <125000>; /* milliCelsius */
+			hysteresis = <2000>; /* milliCelsius */
+			type = "critical";
+		};
+	};
+};
+
+mpu_thermal: mpu_thermal {
+	polling-delay-passive = <250>; /* milliseconds */
+	polling-delay = <500>; /* milliseconds */
+	thermal-sensors = <&wkup_vtm0 1>;
+
+	trips {
+		mpu_crit: mpu_crit {
+			temperature = <125000>; /* milliCelsius */
+			hysteresis = <2000>; /* milliCelsius */
+			type = "critical";
+		};
+	};
+};
+
+main_thermal: main_thermal {
+	polling-delay-passive = <250>; /* milliseconds */
+	polling-delay = <500>; /* milliseconds */
+	thermal-sensors = <&wkup_vtm0 2>;
+
+	trips {
+		c7x_crit: c7x_crit {
+			temperature = <125000>; /* milliCelsius */
+			hysteresis = <2000>; /* milliCelsius */
+			type = "critical";
+		};
+	};
+};
diff --git a/arch/arm64/boot/dts/ti/k3-j7200.dtsi b/arch/arm64/boot/dts/ti/k3-j7200.dtsi
index b6da0454cc5b..9ca60a4f03da 100644
--- a/arch/arm64/boot/dts/ti/k3-j7200.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-j7200.dtsi
@@ -168,6 +168,10 @@
 				 <0x07 0x00000000 0x07 0x00000000 0x01 0x00000000>; /* FSS OSPI1 data region 3 */
 		};
 	};
+
+	thermal_zones: thermal-zones {
+		#include "k3-j7200-thermal.dtsi"
+	};
 };
 
 /* Now include the peripherals for each bus segments */
-- 
2.17.1


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

* [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support
  2022-04-12 10:14 [PATCH v5 0/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
                   ` (2 preceding siblings ...)
  2022-04-12 10:14 ` [PATCH v5 3/4] arm64: dts: ti: j7200: " Keerthy
@ 2022-04-12 10:14 ` Keerthy
  2022-04-12 17:00   ` kernel test robot
                     ` (2 more replies)
  3 siblings, 3 replies; 20+ messages in thread
From: Keerthy @ 2022-04-12 10:14 UTC (permalink / raw)
  To: robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: j-keerthy, linux-pm, vigneshr, devicetree, linux-kernel

Add VTM thermal support. In the Voltage Thermal Management
Module(VTM), K3 J72XX supplies a voltage reference and a temperature
sensor feature that are gathered in the band gap voltage and
temperature sensor (VBGAPTS) module. The band gap provides current and
voltage reference for its internal circuits and other analog IP
blocks. The analog-to-digital converter (ADC) produces an output value
that is proportional to the silicon temperature.

Currently reading temperatures only is supported.  There are no
active/passive cooling agent supported.

J721e SoCs have errata i2128: https://www.ti.com/lit/pdf/sprz455

The VTM Temperature Monitors (TEMPSENSORs) are trimmed during production,
with the resulting values stored in software-readable registers. Software
should use these  register values when translating the Temperature
Monitor output codes to temperature values.

It has an involved workaround. Software needs to read the error codes for
-40C, 30C, 125C from the efuse for each device & derive a new look up table
for adc to temperature conversion. Involved calculating slopes & constants
using 3 different straight line equations with adc refernce codes as the
y-axis & error codes in the x-axis.

-40C to 30C
30C to 125C
125C to 150C

With the above 2 line equations we derive the full look-up table to
workaround the errata i2128 for j721e SoC.

Tested temperature reading on J721e SoC & J7200 SoC.

[daniel.lezcano@linaro.org: Generate look-up tables run-time]
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Keerthy <j-keerthy@ti.com>
---

Changes from v4:

  * Fixed all the comments on v4.
  * Simplified the computation of the table.
  * Removed unnecessary members in the structures.
  * int_pow in the math.h is for unsigned. Keeping the definition for signed

 drivers/thermal/Makefile           |   2 +-
 drivers/thermal/k3_j72xx_bandgap.c | 623 +++++++++++++++++++++++++++++
 2 files changed, 624 insertions(+), 1 deletion(-)
 create mode 100644 drivers/thermal/k3_j72xx_bandgap.c

diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index f0c36a1530d5..def8e1a0399c 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -28,7 +28,7 @@ thermal_sys-$(CONFIG_CPU_IDLE_THERMAL)	+= cpuidle_cooling.o
 # devfreq cooling
 thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
 
-obj-$(CONFIG_K3_THERMAL)	+= k3_bandgap.o
+obj-$(CONFIG_K3_THERMAL)	+= k3_bandgap.o k3_j72xx_bandgap.o
 # platform thermal drivers
 obj-y				+= broadcom/
 obj-$(CONFIG_THERMAL_MMIO)		+= thermal_mmio.o
diff --git a/drivers/thermal/k3_j72xx_bandgap.c b/drivers/thermal/k3_j72xx_bandgap.c
new file mode 100644
index 000000000000..28f3a8e5d6cd
--- /dev/null
+++ b/drivers/thermal/k3_j72xx_bandgap.c
@@ -0,0 +1,623 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * TI Bandgap temperature sensor driver for J72XX SoC Family
+ *
+ * Copyright (C) 2021 Texas Instruments Incorporated - http://www.ti.com/
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/pm_runtime.h>
+#include <linux/err.h>
+#include <linux/types.h>
+#include <linux/of_platform.h>
+#include <linux/io.h>
+#include <linux/thermal.h>
+#include <linux/of.h>
+#include <linux/delay.h>
+#include <linux/math.h>
+#include <linux/slab.h>
+
+#define K3_VTM_DEVINFO_PWR0_OFFSET		0x4
+#define K3_VTM_DEVINFO_PWR0_CVD_CT_MASK		0xf
+#define K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK	0xf0
+#define K3_VTM_TMPSENS0_CTRL_OFFSET		0x300
+#define K3_VTM_MISC_CTRL_OFFSET			0xc
+#define K3_VTM_TMPSENS_STAT_OFFSET		0x8
+#define K3_VTM_ANYMAXT_OUTRG_ALERT_EN		0x1
+#define K3_VTM_MISC_CTRL2_OFFSET		0x10
+#define K3_VTM_REGS_PER_TS			0x10
+#define K3_VTM_TS_STAT_DTEMP_MASK		0x3ff
+#define K3_VTM_MAX_NUM_TS			8
+#define K3_VTM_TMPSENS_CTRL_CBIASSEL		BIT(0)
+#define K3_VTM_TMPSENS_CTRL_SOC			BIT(5)
+#define K3_VTM_TMPSENS_CTRL_CLRZ		BIT(6)
+#define K3_VTM_TMPSENS_CTRL_CLKON_REQ		BIT(7)
+#define K3_VTM_TMPSENS_CTRL_MAXT_OUTRG_EN	BIT(11)
+
+#define K3_VTM_CORRECTION_TEMP_CNT		3
+
+#define K3_VTM_ADC_BEGIN_VAL			6
+#define K3_VTM_ADC_END_VAL			944
+
+#define MINUS40CREF				5
+#define PLUS30CREF				253
+#define PLUS125CREF				730
+#define PLUS150CREF				940
+
+#define MAX_TEMP				123000
+#define COOL_DOWN_TEMP				105000
+
+#define FACTORS_REDUCTION			13
+static int *derived_table;
+
+static s64 int_power(unsigned long long base, unsigned int exp)
+{
+	s64 result = 1;
+
+	while (exp) {
+		if (exp & 1)
+			result *= base;
+		exp >>= 1;
+		base *= base;
+	}
+
+	return result;
+}
+
+static int compute_value(int index, s64 *factors, int nr_factors, int reduction)
+{
+	s64 value = 0;
+	int i;
+
+	for (i = 0; i < nr_factors; i++)
+		value += factors[i] * int_power(index, i);
+
+	return (int)(value / int_power(10, reduction));
+}
+
+static void init_table(int factors_size, int *table, s64 *factors)
+{
+	const int size = 1024;
+	int i;
+
+	for (i = 0; i < size; i++)
+		table[i] = compute_value(i, factors, factors_size,
+					 FACTORS_REDUCTION);
+}
+
+/**
+ * struct err_values - structure containing error/reference values
+ * @refs: reference error values for -40C, 30C, 125C & 150C
+ * @errs: Actual error values for -40C, 30C, 125C & 150C read from the efuse
+ */
+struct err_values {
+	int refs[4];
+	int errs[4];
+};
+
+static void create_table_segments(struct err_values *err_vals, int seg,
+				  int *ref_table)
+{
+	int m = 0, c, num, den, i, err, idx1, idx2, err1, err2, ref1, ref2;
+
+	if (seg == 0)
+		idx1 = 0;
+	else
+		idx1 = err_vals->refs[seg];
+
+	idx2 = err_vals->refs[seg + 1];
+	err1 = err_vals->errs[seg];
+	err2 = err_vals->errs[seg + 1];
+	ref1 = err_vals->refs[seg];
+	ref2 = err_vals->refs[seg + 1];
+
+	/*
+	 * Calculate the slope with adc values read from the register
+	 * as the y-axis param and err in adc value as x-axis param
+	 */
+	num = ref2 - ref1;
+	den = err2 - err1;
+	if (den)
+		m = num / den;
+	c = ref2 - m * err2;
+
+	/*
+	 * Take care of divide by zero error if error values are same
+	 * Or when the slope is 0
+	 */
+	if (den != 0 && m != 0) {
+		for (i = idx1; i <= idx2; i++) {
+			err = (i - c) / m;
+			if (((i + err1) < 0) || ((i + err1) > 1023))
+				continue;
+			derived_table[i] = ref_table[i + err];
+		}
+	} else { /* Constant error take care of divide by zero */
+		for (i = idx1; i <= idx2; i++) {
+			if (((i + err1) < 0) || ((i + err1) > 1023))
+				continue;
+			derived_table[i] = ref_table[i + err1];
+		}
+	}
+}
+
+static int prep_lookup_table(struct err_values *err_vals, int *ref_table)
+{
+	int inc, i, seg;
+
+	/*
+	 * Fill up the lookup table under 3 segments
+	 * region -40C to +30C
+	 * region +30C to +125C
+	 * region +125C to +150C
+	 */
+	for (seg = 0; seg < 3; seg++)
+		create_table_segments(err_vals, seg, ref_table);
+
+	/* Get to the first valid temperature */
+	i = 0;
+	while (!derived_table[i])
+		i++;
+
+	/*
+	 * Get to the last zero index and back fill the temperature for
+	 * sake of continuity
+	 */
+	if (i) {
+		/* 300 milli celsius steps */
+		while (i--)
+			derived_table[i] = derived_table[i + 1] - 300;
+		/* case 0 */
+		derived_table[i] = derived_table[i + 1] - 300;
+	}
+
+	/*
+	 * Fill the last trailing 0s which are unfilled with increments of
+	 * 100 milli celsius till 1023 code
+	 */
+	i = 1023;
+	while (!derived_table[i])
+		i--;
+
+	i++;
+	inc = 1;
+	while (i < 1024) {
+		derived_table[i] = derived_table[i - 1] + inc * 100;
+		i++;
+	}
+
+	return 0;
+}
+
+struct k3_thermal_data;
+
+struct k3_j72xx_bandgap {
+	struct device *dev;
+	void __iomem *base;
+	void __iomem *cfg2_base;
+	void __iomem *fuse_base;
+	struct k3_thermal_data *ts_data[K3_VTM_MAX_NUM_TS];
+};
+
+/* common data structures */
+struct k3_thermal_data {
+	struct k3_j72xx_bandgap *bgp;
+	u32 ctrl_offset;
+	u32 stat_offset;
+};
+
+static int two_cmp(int tmp, int mask)
+{
+	tmp = ~(tmp);
+	tmp &= mask;
+	tmp += 1;
+
+	/* Return negative value */
+	return (0 - tmp);
+}
+
+static unsigned int vtm_get_best_value(unsigned int s0, unsigned int s1,
+				       unsigned int s2)
+{
+	int d01 = abs(s0 - s1);
+	int d02 = abs(s0 - s2);
+	int d12 = abs(s1 - s2);
+
+	if (d01 <= d02 && d01 <= d12)
+		return (s0 + s1) / 2;
+
+	if (d02 <= d01 && d02 <= d12)
+		return (s0 + s2) / 2;
+
+	return (s1 + s2) / 2;
+}
+
+static inline int k3_bgp_read_temp(struct k3_thermal_data *devdata,
+				   int *temp)
+{
+	struct k3_j72xx_bandgap *bgp;
+	unsigned int dtemp, s0, s1, s2;
+
+	bgp = devdata->bgp;
+	/*
+	 * Errata is applicable for am654 pg 1.0 silicon/J7ES. There
+	 * is a variation of the order for certain degree centigrade on AM654.
+	 * Work around that by getting the average of two closest
+	 * readings out of three readings everytime we want to
+	 * report temperatures.
+	 *
+	 * Errata workaround.
+	 */
+	s0 = readl(bgp->base + devdata->stat_offset) &
+		K3_VTM_TS_STAT_DTEMP_MASK;
+	s1 = readl(bgp->base + devdata->stat_offset) &
+		K3_VTM_TS_STAT_DTEMP_MASK;
+	s2 = readl(bgp->base + devdata->stat_offset) &
+		K3_VTM_TS_STAT_DTEMP_MASK;
+	dtemp = vtm_get_best_value(s0, s1, s2);
+
+	if (dtemp < 0 || dtemp > 1023)
+		return -EINVAL;
+
+	*temp = derived_table[dtemp];
+
+	return 0;
+}
+
+/* Get temperature callback function for thermal zone */
+static int k3_thermal_get_temp(void *devdata, int *temp)
+{
+	struct k3_thermal_data *data = devdata;
+	int ret = 0;
+
+	ret = k3_bgp_read_temp(data, temp);
+	if (ret)
+		return ret;
+
+	return ret;
+}
+
+static const struct thermal_zone_of_device_ops k3_of_thermal_ops = {
+	.get_temp = k3_thermal_get_temp,
+};
+
+static int k3_j72xx_bandgap_temp_to_adc_code(int temp)
+{
+	int low = 0, high = 1023, mid;
+
+	if (temp > 160000 || temp < -50000)
+		return -EINVAL;
+
+	/* Binary search to find the adc code */
+	while (low < (high - 1)) {
+		mid = (low + high) / 2;
+		if (temp <= derived_table[mid])
+			high = mid;
+		else
+			low = mid;
+	}
+
+	return mid;
+}
+
+static void get_efuse_values(int id, struct k3_thermal_data *data, int *err,
+			     struct k3_j72xx_bandgap *bgp)
+{
+	int i, tmp, pow;
+	int ct_offsets[K3_VTM_CORRECTION_TEMP_CNT];
+	int ct_bm[K3_VTM_CORRECTION_TEMP_CNT];
+
+	/* Populate efuse reg offsets & Bit masks for -40C, 30C, 125C */
+	switch (id) {
+	case 0:
+		ct_offsets[0] = 0x0;
+		ct_offsets[1] = 0x8;
+		ct_offsets[2] = 0x4;
+		ct_bm[0] = 0x3f;
+		ct_bm[1] = 0x1fe000;
+		ct_bm[2] = 0x1ff;
+		break;
+
+	case 1:
+		ct_offsets[0] = 0x0;
+		ct_offsets[1] = 0x8;
+		ct_offsets[2] = 0x4;
+		ct_bm[0] = 0xfc0;
+		ct_bm[1] = 0x1fe00000;
+		ct_bm[2] = 0x3fe00;
+		break;
+
+	case 2:
+		ct_offsets[0] = 0x0;
+		ct_offsets[1] = -1;
+		ct_offsets[2] = 0x4;
+		ct_bm[0] = 0x3f000;
+		ct_bm[1] = 0x7f800000;
+		ct_bm[2] = 0x7fc0000;
+		break;
+
+	case 3:
+		ct_offsets[0] = 0x0;
+		ct_offsets[1] = 0xC;
+		ct_offsets[2] = -1; /* Spread across 2 registers */
+		ct_bm[0] = 0xfc0000;
+		ct_bm[1] = 0x1fe0;
+		ct_bm[2] = 0x1f800000;
+		break;
+
+	case 4:
+		ct_offsets[0] = 0x0;
+		ct_offsets[1] = 0xc;
+		ct_offsets[2] = 0x8;
+		ct_bm[0] = 0x3f000000;
+		ct_bm[1] = 0x1fe000;
+		ct_bm[2] = 0x1ff0;
+		break;
+	}
+
+	for (i = 0; i < 3; i++) {
+		/* Extract the offset value using bit-mask */
+		if (ct_offsets[i] == -1 && i == 1) {
+			/* 25C offset Case of Sensor 2 split between 2 regs */
+			tmp = (readl(bgp->fuse_base + 0x8) & 0xE0000000) >> (29);
+			tmp |= ((readl(bgp->fuse_base + 0xC) & 0x1F) << 3);
+			pow = tmp & 0x80;
+		} else if (ct_offsets[i] == -1 && i == 2) {
+			/* 125C Case of Sensor 3 split between 2 regs */
+			tmp = (readl(bgp->fuse_base + 0x4) & 0xF8000000) >> (27);
+			tmp |= ((readl(bgp->fuse_base + 0x8) & 0xF) << 5);
+			pow = tmp & 0x100;
+		} else {
+			tmp = readl(bgp->fuse_base + ct_offsets[i]);
+			tmp &= ct_bm[i];
+			tmp = tmp >> __ffs(ct_bm[i]);
+
+			/* Obtain the sign bit pow*/
+			pow = ct_bm[i] >> __ffs(ct_bm[i]);
+			pow += 1;
+			pow /= 2;
+		}
+
+		/* Check for negative value */
+		if (tmp & pow) {
+			/* 2's complement value */
+			tmp = two_cmp(tmp, ct_bm[i] >> __ffs(ct_bm[i]));
+		}
+		err[i] = tmp;
+	}
+
+	/* Err value for 150C is set to 0 */
+	err[i] = 0;
+}
+
+static void print_look_up_table(struct device *dev, int *ref_table)
+{
+	int i;
+
+	dev_dbg(dev, "The contents of derived array\n");
+	dev_dbg(dev, "Code   Temperaturei\n");
+	for (i = 0; i <= 1023; i++)
+		dev_dbg(dev, "%d       %d %d\n", i, derived_table[i], ref_table[i]);
+}
+
+static const struct of_device_id of_k3_j72xx_bandgap_match[];
+
+struct k3_j72xx_bandgap_data {
+	unsigned int has_errata_i2128;
+};
+
+static int k3_j72xx_bandgap_probe(struct platform_device *pdev)
+{
+	int ret = 0, cnt, val, id, table_size = 1024;
+	int high_max, low_temp;
+	struct resource *res;
+	struct device *dev = &pdev->dev;
+	struct k3_j72xx_bandgap *bgp;
+	struct k3_thermal_data *data;
+	int workaround_needed = 0;
+	const struct k3_j72xx_bandgap_data *driver_data;
+	struct thermal_zone_device *ti_thermal;
+	int *ref_table;
+	struct err_values err_vals;
+
+	s64 golden_factors[] = {
+		-490019999999999936,
+		3251200000000000,
+		-1705800000000,
+		603730000,
+		-92627,
+	};
+
+	s64 pvt_wa_factors[] = {
+		-415230000000000000,
+		3126600000000000,
+		-1157800000000,
+	};
+
+	bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL);
+	if (!bgp)
+		return -ENOMEM;
+
+	bgp->dev = dev;
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	bgp->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(bgp->base))
+		return PTR_ERR(bgp->base);
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	bgp->cfg2_base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(bgp->cfg2_base))
+		return PTR_ERR(bgp->cfg2_base);
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
+	bgp->fuse_base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(bgp->fuse_base))
+		return PTR_ERR(bgp->fuse_base);
+
+	driver_data = of_device_get_match_data(dev);
+	if (driver_data)
+		workaround_needed = driver_data->has_errata_i2128;
+
+	pm_runtime_enable(dev);
+	ret = pm_runtime_get_sync(dev);
+	if (ret < 0) {
+		pm_runtime_put_noidle(dev);
+		pm_runtime_disable(dev);
+		return ret;
+	}
+
+	/* Get the sensor count in the VTM */
+	val = readl(bgp->base + K3_VTM_DEVINFO_PWR0_OFFSET);
+	cnt = val & K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK;
+	cnt >>= __ffs(K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK);
+
+	data = devm_kcalloc(bgp->dev, cnt, sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		ret = -ENOMEM;
+		goto err_alloc;
+	}
+
+	ref_table = devm_kzalloc(bgp->dev, sizeof(*ref_table) * table_size,
+				 GFP_KERNEL);
+	if (!ref_table) {
+		ret = -ENOMEM;
+		goto err_alloc;
+	}
+
+	derived_table = devm_kzalloc(bgp->dev, sizeof(*derived_table) * table_size,
+				     GFP_KERNEL);
+	if (!derived_table) {
+		ret = -ENOMEM;
+		goto err_alloc;
+	}
+
+	/* Workaround not needed if bit30/bit31 is set even for J721e */
+	if (workaround_needed && (readl(bgp->fuse_base + 0x0) & 0xc0000000) == 0xc0000000)
+		workaround_needed = false;
+
+	dev_dbg(bgp->dev, "Work around %sneeded\n",
+		workaround_needed ? "not " : "");
+
+	if (!workaround_needed)
+		init_table(5, ref_table, golden_factors);
+	else
+		init_table(3, ref_table, pvt_wa_factors);
+
+	/* Register the thermal sensors */
+	for (id = 0; id < cnt; id++) {
+		data[id].bgp = bgp;
+		data[id].ctrl_offset = K3_VTM_TMPSENS0_CTRL_OFFSET + id * 0x20;
+		data[id].stat_offset = data[id].ctrl_offset +
+					K3_VTM_TMPSENS_STAT_OFFSET;
+
+		if (workaround_needed) {
+			/* ref adc values for -40C, 30C & 125C respectively */
+			err_vals.refs[0] = MINUS40CREF;
+			err_vals.refs[1] = PLUS30CREF;
+			err_vals.refs[2] = PLUS125CREF;
+			err_vals.refs[3] = PLUS150CREF;
+			get_efuse_values(id, &data[id], err_vals.errs, bgp);
+		}
+
+		if (id == 0 && workaround_needed)
+			prep_lookup_table(&err_vals, ref_table);
+		else if (id == 0 && !workaround_needed)
+			memcpy(derived_table, ref_table, table_size * 4);
+
+		val = readl(data[id].bgp->cfg2_base + data[id].ctrl_offset);
+		val |= (K3_VTM_TMPSENS_CTRL_MAXT_OUTRG_EN |
+			K3_VTM_TMPSENS_CTRL_SOC |
+			K3_VTM_TMPSENS_CTRL_CLRZ | BIT(4));
+		writel(val, data[id].bgp->cfg2_base + data[id].ctrl_offset);
+
+		bgp->ts_data[id] = &data[id];
+		ti_thermal =
+		devm_thermal_zone_of_sensor_register(bgp->dev, id,
+						     &data[id],
+						     &k3_of_thermal_ops);
+		if (IS_ERR(ti_thermal)) {
+			dev_err(bgp->dev, "thermal zone device is NULL\n");
+			ret = PTR_ERR(ti_thermal);
+			goto err_alloc;
+		}
+	}
+
+	/*
+	 * Program TSHUT thresholds
+	 * Step 1: set the thresholds to ~123C and 105C WKUP_VTM_MISC_CTRL2
+	 * Step 2: WKUP_VTM_TMPSENS_CTRL_j set the MAXT_OUTRG_EN  bit
+	 *         This is already taken care as per of init
+	 * Step 3: WKUP_VTM_MISC_CTRL set the ANYMAXT_OUTRG_ALERT_EN  bit
+	 */
+	high_max = k3_j72xx_bandgap_temp_to_adc_code(MAX_TEMP);
+	low_temp = k3_j72xx_bandgap_temp_to_adc_code(COOL_DOWN_TEMP);
+
+	writel((low_temp << 16) | high_max, data[0].bgp->cfg2_base +
+	       K3_VTM_MISC_CTRL2_OFFSET);
+	mdelay(100);
+	writel(K3_VTM_ANYMAXT_OUTRG_ALERT_EN, data[0].bgp->cfg2_base +
+	       K3_VTM_MISC_CTRL_OFFSET);
+
+	platform_set_drvdata(pdev, bgp);
+
+	print_look_up_table(dev, ref_table);
+	/*
+	 * Now that the derived_table has the appropriate look up values
+	 * Free up the ref_table
+	 */
+	kfree(ref_table);
+
+	return 0;
+
+err_alloc:
+	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+
+	return ret;
+}
+
+static int k3_j72xx_bandgap_remove(struct platform_device *pdev)
+{
+	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+
+	return 0;
+}
+
+const struct k3_j72xx_bandgap_data k3_j72xx_bandgap_j721e_data = {
+	.has_errata_i2128 = 1,
+};
+
+const struct k3_j72xx_bandgap_data k3_j72xx_bandgap_j7200_data = {
+	.has_errata_i2128 = 0,
+};
+
+static const struct of_device_id of_k3_j72xx_bandgap_match[] = {
+	{
+		.compatible = "ti,j721e-vtm",
+		.data = (void *)&k3_j72xx_bandgap_j721e_data,
+	},
+	{
+		.compatible = "ti,j7200-vtm",
+		.data = (void *)&k3_j72xx_bandgap_j7200_data,
+	},
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, of_k3_j72xx_bandgap_match);
+
+static struct platform_driver k3_j72xx_bandgap_sensor_driver = {
+	.probe = k3_j72xx_bandgap_probe,
+	.remove = k3_j72xx_bandgap_remove,
+	.driver = {
+		.name = "k3-j72xx-soc-thermal",
+		.of_match_table	= of_k3_j72xx_bandgap_match,
+	},
+};
+
+module_platform_driver(k3_j72xx_bandgap_sensor_driver);
+
+MODULE_DESCRIPTION("K3 bandgap temperature sensor driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
-- 
2.17.1


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

* Re: [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support
  2022-04-12 10:14 ` [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
@ 2022-04-12 17:00   ` kernel test robot
  2022-04-13 10:17   ` Krzysztof Kozlowski
  2022-04-19 17:23   ` Daniel Lezcano
  2 siblings, 0 replies; 20+ messages in thread
From: kernel test robot @ 2022-04-12 17:00 UTC (permalink / raw)
  To: Keerthy, robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: kbuild-all, j-keerthy, linux-pm, vigneshr, devicetree, linux-kernel

Hi Keerthy,

I love your patch! Yet something to improve:

[auto build test ERROR on robh/for-next]
[also build test ERROR on rafael-pm/thermal v5.18-rc2 next-20220412]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Keerthy/thermal-k3_j72xx_bandgap-Add-the-bandgap-driver-support/20220412-193526
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: microblaze-buildonly-randconfig-r002-20220411 (https://download.01.org/0day-ci/archive/20220413/202204130043.PiaWoNtR-lkp@intel.com/config)
compiler: microblaze-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/de47884b9759d99f1971558a45283b912efbf22a
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Keerthy/thermal-k3_j72xx_bandgap-Add-the-bandgap-driver-support/20220412-193526
        git checkout de47884b9759d99f1971558a45283b912efbf22a
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=microblaze SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   microblaze-linux-ld: drivers/thermal/k3_j72xx_bandgap.o: in function `init_table':
>> .tmp_gl_k3_j72xx_bandgap.o:(.text+0x69c): undefined reference to `__divdi3'

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* Re: [PATCH v5 2/4] arm64: dts: ti: j721e: Add VTM node
  2022-04-12 10:14 ` [PATCH v5 2/4] arm64: dts: ti: j721e: Add VTM node Keerthy
@ 2022-04-12 17:09   ` Vignesh Raghavendra
  2022-04-12 23:43     ` J, KEERTHY
  2022-04-13 10:14   ` Krzysztof Kozlowski
  1 sibling, 1 reply; 20+ messages in thread
From: Vignesh Raghavendra @ 2022-04-12 17:09 UTC (permalink / raw)
  To: Keerthy, robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: linux-pm, devicetree, linux-kernel

Hi Keerthy

On 12/04/22 3:44 pm, Keerthy wrote:
> VTM stands for Voltage Thermal Management
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> ---
>  .../boot/dts/ti/k3-j721e-mcu-wakeup.dtsi      |  9 +++
>  arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi  | 73 +++++++++++++++++++
>  arch/arm64/boot/dts/ti/k3-j721e.dtsi          |  4 +
>  3 files changed, 86 insertions(+)
>  create mode 100644 arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi
> 
> diff --git a/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi b/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
> index b4972dfb7da8..6290f563b8e7 100644
> --- a/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
> +++ b/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
> @@ -418,4 +418,13 @@
>  		interrupt-names = "int0", "int1";
>  		bosch,mram-cfg = <0x0 128 64 64 64 64 32 32>;
>  	};
> +
> +	wkup_vtm0: wkup_vtm0@42040000 {
> +		compatible = "ti,j721e-vtm";
> +		reg = <0x0 0x42040000 0x0 0x350>,
> +			<0x0 0x42050000 0x0 0x350>,
> +			<0x0 0x43000300 0x0 0x10>;

Please follow convention of using 0x00 as rest of the file:

		reg = <0x00 0x42040000 0x00 0x350>,
		....

> +		power-domains = <&k3_pds 154 TI_SCI_PD_EXCLUSIVE>;
> +		#thermal-sensor-cells = <1>;
> +	};
>  };
> diff --git a/arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi b/arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi
> new file mode 100644
> index 000000000000..e922042f356f
> --- /dev/null
> +++ b/arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi
> @@ -0,0 +1,73 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <dt-bindings/thermal/thermal.h>
> +
> +wkup_thermal: wkup_thermal {
> +	polling-delay-passive = <250>; /* milliseconds */
> +	polling-delay = <500>; /* milliseconds */
> +	thermal-sensors = <&wkup_vtm0 0>;
> +
> +	trips {
> +		wkup_crit: wkup_crit {


Here and elsewhere no "-" in node names please.

You can use:

https://github.com/nmenon/kernel_patch_verify
kpv -C -n <no of commits>

This catches most issues like above

> +			temperature = <125000>; /* milliCelsius */
> +			hysteresis = <2000>; /* milliCelsius */
> +			type = "critical";
> +		};
> +	};
> +};
> +
> +mpu_thermal: mpu_thermal {
> +	polling-delay-passive = <250>; /* milliseconds */
> +	polling-delay = <500>; /* milliseconds */
> +	thermal-sensors = <&wkup_vtm0 1>;
> +
> +	trips {
> +		mpu_crit: mpu_crit {
> +			temperature = <125000>; /* milliCelsius */
> +			hysteresis = <2000>; /* milliCelsius */
> +			type = "critical";
> +		};
> +	};
> +};
> +
> +c7x_thermal: c7x_thermal {
> +	polling-delay-passive = <250>; /* milliseconds */
> +	polling-delay = <500>; /* milliseconds */
> +	thermal-sensors = <&wkup_vtm0 2>;
> +
> +	trips {
> +		c7x_crit: c7x_crit {
> +			temperature = <125000>; /* milliCelsius */
> +			hysteresis = <2000>; /* milliCelsius */
> +			type = "critical";
> +		};
> +	};
> +};
> +
> +gpu_thermal: gpu_thermal {
> +	polling-delay-passive = <250>; /* milliseconds */
> +	polling-delay = <500>; /* milliseconds */
> +	thermal-sensors = <&wkup_vtm0 3>;
> +
> +	trips {
> +		gpu_crit: gpu_crit {
> +			temperature = <125000>; /* milliCelsius */
> +			hysteresis = <2000>; /* milliCelsius */
> +			type = "critical";
> +		};
> +	};
> +};
> +
> +r5f_thermal: r5f_thermal {
> +	polling-delay-passive = <250>; /* milliseconds */
> +	polling-delay = <500>; /* milliseconds */
> +	thermal-sensors = <&wkup_vtm0 4>;
> +
> +	trips {
> +		r5f_crit: r5f_crit {
> +			temperature = <125000>; /* milliCelsius */
> +			hysteresis = <2000>; /* milliCelsius */
> +			type = "critical";
> +		};
> +	};
> +};
> diff --git a/arch/arm64/boot/dts/ti/k3-j721e.dtsi b/arch/arm64/boot/dts/ti/k3-j721e.dtsi
> index 0e23886c9fd1..6979863eb500 100644
> --- a/arch/arm64/boot/dts/ti/k3-j721e.dtsi
> +++ b/arch/arm64/boot/dts/ti/k3-j721e.dtsi
> @@ -181,6 +181,10 @@
>  				 <0x07 0x00000000 0x07 0x00000000 0x01 0x00000000>; /* FSS OSPI1 data region 3*/
>  		};
>  	};
> +
> +	thermal_zones: thermal-zones {
> +		#include "k3-j721e-thermal.dtsi"
> +	};

Bit weird representation, any reason why thermal-zones {} cannot be
moved into k3-j721e-thermal.dtsi?

>  };
>  
>  /* Now include the peripherals for each bus segments */


Regards
Vignesh

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

* Re: [PATCH v5 2/4] arm64: dts: ti: j721e: Add VTM node
  2022-04-12 17:09   ` Vignesh Raghavendra
@ 2022-04-12 23:43     ` J, KEERTHY
  0 siblings, 0 replies; 20+ messages in thread
From: J, KEERTHY @ 2022-04-12 23:43 UTC (permalink / raw)
  To: Vignesh Raghavendra, robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: linux-pm, devicetree, linux-kernel



On 4/12/2022 10:39 PM, Vignesh Raghavendra wrote:
> Hi Keerthy
> 
> On 12/04/22 3:44 pm, Keerthy wrote:
>> VTM stands for Voltage Thermal Management
>>
>> Signed-off-by: Keerthy <j-keerthy@ti.com>
>> ---
>>   .../boot/dts/ti/k3-j721e-mcu-wakeup.dtsi      |  9 +++
>>   arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi  | 73 +++++++++++++++++++
>>   arch/arm64/boot/dts/ti/k3-j721e.dtsi          |  4 +
>>   3 files changed, 86 insertions(+)
>>   create mode 100644 arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi
>>
>> diff --git a/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi b/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
>> index b4972dfb7da8..6290f563b8e7 100644
>> --- a/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
>> +++ b/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
>> @@ -418,4 +418,13 @@
>>   		interrupt-names = "int0", "int1";
>>   		bosch,mram-cfg = <0x0 128 64 64 64 64 32 32>;
>>   	};
>> +
>> +	wkup_vtm0: wkup_vtm0@42040000 {
>> +		compatible = "ti,j721e-vtm";
>> +		reg = <0x0 0x42040000 0x0 0x350>,
>> +			<0x0 0x42050000 0x0 0x350>,
>> +			<0x0 0x43000300 0x0 0x10>;
> 
> Please follow convention of using 0x00 as rest of the file:

Okay.

> 
> 		reg = <0x00 0x42040000 0x00 0x350>,
> 		....
> 
>> +		power-domains = <&k3_pds 154 TI_SCI_PD_EXCLUSIVE>;
>> +		#thermal-sensor-cells = <1>;
>> +	};
>>   };
>> diff --git a/arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi b/arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi
>> new file mode 100644
>> index 000000000000..e922042f356f
>> --- /dev/null
>> +++ b/arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi
>> @@ -0,0 +1,73 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +#include <dt-bindings/thermal/thermal.h>
>> +
>> +wkup_thermal: wkup_thermal {
>> +	polling-delay-passive = <250>; /* milliseconds */
>> +	polling-delay = <500>; /* milliseconds */
>> +	thermal-sensors = <&wkup_vtm0 0>;
>> +
>> +	trips {
>> +		wkup_crit: wkup_crit {
> 
> 
> Here and elsewhere no "-" in node names please.

I believe you meant no "_" ?

> 
> You can use:
> 
> https://github.com/nmenon/kernel_patch_verify
> kpv -C -n <no of commits>
> 
> This catches most issues like above

Okay

> 
>> +			temperature = <125000>; /* milliCelsius */
>> +			hysteresis = <2000>; /* milliCelsius */
>> +			type = "critical";
>> +		};
>> +	};
>> +};
>> +
>> +mpu_thermal: mpu_thermal {
>> +	polling-delay-passive = <250>; /* milliseconds */
>> +	polling-delay = <500>; /* milliseconds */
>> +	thermal-sensors = <&wkup_vtm0 1>;
>> +
>> +	trips {
>> +		mpu_crit: mpu_crit {
>> +			temperature = <125000>; /* milliCelsius */
>> +			hysteresis = <2000>; /* milliCelsius */
>> +			type = "critical";
>> +		};
>> +	};
>> +};
>> +
>> +c7x_thermal: c7x_thermal {
>> +	polling-delay-passive = <250>; /* milliseconds */
>> +	polling-delay = <500>; /* milliseconds */
>> +	thermal-sensors = <&wkup_vtm0 2>;
>> +
>> +	trips {
>> +		c7x_crit: c7x_crit {
>> +			temperature = <125000>; /* milliCelsius */
>> +			hysteresis = <2000>; /* milliCelsius */
>> +			type = "critical";
>> +		};
>> +	};
>> +};
>> +
>> +gpu_thermal: gpu_thermal {
>> +	polling-delay-passive = <250>; /* milliseconds */
>> +	polling-delay = <500>; /* milliseconds */
>> +	thermal-sensors = <&wkup_vtm0 3>;
>> +
>> +	trips {
>> +		gpu_crit: gpu_crit {
>> +			temperature = <125000>; /* milliCelsius */
>> +			hysteresis = <2000>; /* milliCelsius */
>> +			type = "critical";
>> +		};
>> +	};
>> +};
>> +
>> +r5f_thermal: r5f_thermal {
>> +	polling-delay-passive = <250>; /* milliseconds */
>> +	polling-delay = <500>; /* milliseconds */
>> +	thermal-sensors = <&wkup_vtm0 4>;
>> +
>> +	trips {
>> +		r5f_crit: r5f_crit {
>> +			temperature = <125000>; /* milliCelsius */
>> +			hysteresis = <2000>; /* milliCelsius */
>> +			type = "critical";
>> +		};
>> +	};
>> +};
>> diff --git a/arch/arm64/boot/dts/ti/k3-j721e.dtsi b/arch/arm64/boot/dts/ti/k3-j721e.dtsi
>> index 0e23886c9fd1..6979863eb500 100644
>> --- a/arch/arm64/boot/dts/ti/k3-j721e.dtsi
>> +++ b/arch/arm64/boot/dts/ti/k3-j721e.dtsi
>> @@ -181,6 +181,10 @@
>>   				 <0x07 0x00000000 0x07 0x00000000 0x01 0x00000000>; /* FSS OSPI1 data region 3*/
>>   		};
>>   	};
>> +
>> +	thermal_zones: thermal-zones {
>> +		#include "k3-j721e-thermal.dtsi"
>> +	};
> 
> Bit weird representation, any reason why thermal-zones {} cannot be
> moved into k3-j721e-thermal.dtsi?

Okay. This could be moved. This is typically done when we have different 
zones defined under different dtsi files. Like in the case of 
omap5/dra7. The same was followed here. You are right this could be 
moved as we have all the zones under one dtsi.

Regards,
Keerthy

> 
>>   };
>>   
>>   /* Now include the peripherals for each bus segments */
> 
> 
> Regards
> Vignesh

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

* Re: [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation
  2022-04-12 10:14 ` [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation Keerthy
@ 2022-04-13  8:07   ` Daniel Lezcano
  2022-04-13 10:13   ` Krzysztof Kozlowski
  1 sibling, 0 replies; 20+ messages in thread
From: Daniel Lezcano @ 2022-04-13  8:07 UTC (permalink / raw)
  To: Keerthy, robh+dt, rui.zhang, amitk, kristo, Krzysztof Kozlowski
  Cc: linux-pm, vigneshr, devicetree, linux-kernel


Adding Krzysztof

On 12/04/2022 12:14, Keerthy wrote:
> Add VTM bindings documentation. In the Voltage Thermal
> Management Module(VTM), K3 J72XX supplies a voltage
> reference and a temperature sensor feature that are gathered in the band
> gap voltage and temperature sensor (VBGAPTS) module. The band
> gap provides current and voltage reference for its internal
> circuits and other analog IP blocks. The analog-to-digital
> converter (ADC) produces an output value that is proportional
> to the silicon temperature.
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> ---
>   .../bindings/thermal/ti,j72xx-thermal.yaml    | 62 +++++++++++++++++++
>   1 file changed, 62 insertions(+)
>   create mode 100644 Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
> 
> diff --git a/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml b/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
> new file mode 100644
> index 000000000000..8483c495cb9a
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
> @@ -0,0 +1,62 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/thermal/ti,j72xx-thermal.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Texas Instruments J72XX VTM (DTS) binding
> +
> +maintainers:
> +  - Keerthy <j-keerthy@ti.com>
> +
> +properties:
> +  compatible:
> +    const: ti,j721e-vtm
> +    oneOf:
> +      - enum:
> +          - ti,j721e-vtm
> +          - ti,j7200-vtm
> +
> +  reg:
> +    maxItems: 3
> +
> +  power-domains:
> +    maxItems: 1
> +
> +  "#thermal-sensor-cells":
> +    const: 1
> +
> +required:
> +  - compatible
> +  - reg
> +  - power-domains
> +  - "#thermal-sensor-cells"
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/soc/ti,sci_pm_domain.h>
> +    wkup_vtm0: wkup_vtm0@42040000 {
> +        compatible = "ti,j721e-vtm";
> +        reg = <0x42040000 0x350>,
> +            <0x42050000 0x350>,
> +            <0x43000300 0x10>;
> +        power-domains = <&k3_pds 154 TI_SCI_PD_EXCLUSIVE>;
> +        #thermal-sensor-cells = <1>;
> +    };
> +
> +    mpu_thermal: mpu_thermal {
> +        polling-delay-passive = <250>; /* milliseconds */
> +        polling-delay = <500>; /* milliseconds */
> +        thermal-sensors = <&wkup_vtm0 0>;
> +
> +        trips {
> +                mpu_crit: mpu_crit {
> +                        temperature = <125000>; /* milliCelsius */
> +                        hysteresis = <2000>; /* milliCelsius */
> +                        type = "critical";
> +                };
> +        };
> +    };
> +...


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

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

* Re: [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation
  2022-04-12 10:14 ` [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation Keerthy
  2022-04-13  8:07   ` Daniel Lezcano
@ 2022-04-13 10:13   ` Krzysztof Kozlowski
  2022-04-13 12:04     ` J, KEERTHY
  1 sibling, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-13 10:13 UTC (permalink / raw)
  To: Keerthy, robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: linux-pm, vigneshr, devicetree, linux-kernel

On 12/04/2022 12:14, Keerthy wrote:
> Add VTM bindings documentation. In the Voltage Thermal
> Management Module(VTM), K3 J72XX supplies a voltage
> reference and a temperature sensor feature that are gathered in the band
> gap voltage and temperature sensor (VBGAPTS) module. The band
> gap provides current and voltage reference for its internal
> circuits and other analog IP blocks. The analog-to-digital
> converter (ADC) produces an output value that is proportional
> to the silicon temperature.
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> ---
>  .../bindings/thermal/ti,j72xx-thermal.yaml    | 62 +++++++++++++++++++
>  1 file changed, 62 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
> 
> diff --git a/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml b/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
> new file mode 100644
> index 000000000000..8483c495cb9a
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
> @@ -0,0 +1,62 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/thermal/ti,j72xx-thermal.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Texas Instruments J72XX VTM (DTS) binding
> +
> +maintainers:
> +  - Keerthy <j-keerthy@ti.com>
> +
> +properties:
> +  compatible:
> +    const: ti,j721e-vtm
> +    oneOf:
> +      - enum:
> +          - ti,j721e-vtm
> +          - ti,j7200-vtm

It seems you resent this ignoring all of Rob's comments. In changelog of
cover letter you wrote "Fixed all the comments on v4" but it's not true.
Maybe you sent us old patch?

Anyway, you need to follow Rob's comments.


Best regards,
Krzysztof

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

* Re: [PATCH v5 2/4] arm64: dts: ti: j721e: Add VTM node
  2022-04-12 10:14 ` [PATCH v5 2/4] arm64: dts: ti: j721e: Add VTM node Keerthy
  2022-04-12 17:09   ` Vignesh Raghavendra
@ 2022-04-13 10:14   ` Krzysztof Kozlowski
  1 sibling, 0 replies; 20+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-13 10:14 UTC (permalink / raw)
  To: Keerthy, robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: linux-pm, vigneshr, devicetree, linux-kernel

On 12/04/2022 12:14, Keerthy wrote:
> VTM stands for Voltage Thermal Management
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> ---
>  .../boot/dts/ti/k3-j721e-mcu-wakeup.dtsi      |  9 +++
>  arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi  | 73 +++++++++++++++++++
>  arch/arm64/boot/dts/ti/k3-j721e.dtsi          |  4 +
>  3 files changed, 86 insertions(+)
>  create mode 100644 arch/arm64/boot/dts/ti/k3-j721e-thermal.dtsi
> 
> diff --git a/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi b/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
> index b4972dfb7da8..6290f563b8e7 100644
> --- a/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
> +++ b/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
> @@ -418,4 +418,13 @@
>  		interrupt-names = "int0", "int1";
>  		bosch,mram-cfg = <0x0 128 64 64 64 64 32 32>;
>  	};
> +
> +	wkup_vtm0: wkup_vtm0@42040000 {

No, same comments as Rob gave you for bindings patch.

Please fix them in entire patchset, instead of ignoring.


Best regards,
Krzysztof

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

* Re: [PATCH v5 3/4] arm64: dts: ti: j7200: Add VTM node
  2022-04-12 10:14 ` [PATCH v5 3/4] arm64: dts: ti: j7200: " Keerthy
@ 2022-04-13 10:14   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 20+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-13 10:14 UTC (permalink / raw)
  To: Keerthy, robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: linux-pm, vigneshr, devicetree, linux-kernel

On 12/04/2022 12:14, Keerthy wrote:
> VTM stands for Voltage Thermal Management
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> ---
>  .../boot/dts/ti/k3-j7200-mcu-wakeup.dtsi      |  9 ++++
>  arch/arm64/boot/dts/ti/k3-j7200-thermal.dtsi  | 45 +++++++++++++++++++
>  arch/arm64/boot/dts/ti/k3-j7200.dtsi          |  4 ++
>  3 files changed, 58 insertions(+)
>  create mode 100644 arch/arm64/boot/dts/ti/k3-j7200-thermal.dtsi
> 
> diff --git a/arch/arm64/boot/dts/ti/k3-j7200-mcu-wakeup.dtsi b/arch/arm64/boot/dts/ti/k3-j7200-mcu-wakeup.dtsi
> index 1044ec6c4b0d..2b5c570253cc 100644
> --- a/arch/arm64/boot/dts/ti/k3-j7200-mcu-wakeup.dtsi
> +++ b/arch/arm64/boot/dts/ti/k3-j7200-mcu-wakeup.dtsi
> @@ -375,4 +375,13 @@
>  			ti,loczrama = <1>;
>  		};
>  	};
> +
> +	wkup_vtm0: wkup_vtm0@42040000 {

Same issues as in other patches.


Best regards,
Krzysztof

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

* Re: [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support
  2022-04-12 10:14 ` [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
  2022-04-12 17:00   ` kernel test robot
@ 2022-04-13 10:17   ` Krzysztof Kozlowski
  2022-04-19 17:23   ` Daniel Lezcano
  2 siblings, 0 replies; 20+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-13 10:17 UTC (permalink / raw)
  To: Keerthy, robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: linux-pm, vigneshr, devicetree, linux-kernel

On 12/04/2022 12:14, Keerthy wrote:
> Add VTM thermal support. In the Voltage Thermal Management
> Module(VTM), K3 J72XX supplies a voltage reference and a temperature
> sensor feature that are gathered in the band gap voltage and
> temperature sensor (VBGAPTS) module. The band gap provides current and
> voltage reference for its internal circuits and other analog IP
> blocks. The analog-to-digital converter (ADC) produces an output value
> that is proportional to the silicon temperature.


(...)

> +
> +static void print_look_up_table(struct device *dev, int *ref_table)

Here and everywhere else in such cases - you do not modify pointed data,
so pointers to const please.

> +{
> +	int i;
> +
> +	dev_dbg(dev, "The contents of derived array\n");
> +	dev_dbg(dev, "Code   Temperaturei\n");
> +	for (i = 0; i <= 1023; i++)
> +		dev_dbg(dev, "%d       %d %d\n", i, derived_table[i], ref_table[i]);
> +}
> +
> +static const struct of_device_id of_k3_j72xx_bandgap_match[];
> +

Why do you need forward declaration?

(....)

> +
> +static const struct of_device_id of_k3_j72xx_bandgap_match[] = {
> +	{
> +		.compatible = "ti,j721e-vtm",
> +		.data = (void *)&k3_j72xx_bandgap_j721e_data,

Why do you need the cast?


Best regards,
Krzysztof

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

* Re: [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation
  2022-04-13 10:13   ` Krzysztof Kozlowski
@ 2022-04-13 12:04     ` J, KEERTHY
  2022-04-13 12:25       ` Krzysztof Kozlowski
  2022-04-14 15:57       ` Rob Herring
  0 siblings, 2 replies; 20+ messages in thread
From: J, KEERTHY @ 2022-04-13 12:04 UTC (permalink / raw)
  To: Krzysztof Kozlowski, robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: linux-pm, vigneshr, devicetree, linux-kernel



On 4/13/2022 3:43 PM, Krzysztof Kozlowski wrote:
> On 12/04/2022 12:14, Keerthy wrote:
>> Add VTM bindings documentation. In the Voltage Thermal
>> Management Module(VTM), K3 J72XX supplies a voltage
>> reference and a temperature sensor feature that are gathered in the band
>> gap voltage and temperature sensor (VBGAPTS) module. The band
>> gap provides current and voltage reference for its internal
>> circuits and other analog IP blocks. The analog-to-digital
>> converter (ADC) produces an output value that is proportional
>> to the silicon temperature.
>>
>> Signed-off-by: Keerthy <j-keerthy@ti.com>
>> ---
>>   .../bindings/thermal/ti,j72xx-thermal.yaml    | 62 +++++++++++++++++++
>>   1 file changed, 62 insertions(+)
>>   create mode 100644 Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
>>
>> diff --git a/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml b/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
>> new file mode 100644
>> index 000000000000..8483c495cb9a
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
>> @@ -0,0 +1,62 @@
>> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
>> +%YAML 1.2
>> +---
>> +$id: http://devicetree.org/schemas/thermal/ti,j72xx-thermal.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: Texas Instruments J72XX VTM (DTS) binding
>> +
>> +maintainers:
>> +  - Keerthy <j-keerthy@ti.com>
>> +
>> +properties:
>> +  compatible:
>> +    const: ti,j721e-vtm
>> +    oneOf:
>> +      - enum:
>> +          - ti,j721e-vtm
>> +          - ti,j7200-vtm
> 
> It seems you resent this ignoring all of Rob's comments. In changelog of
> cover letter you wrote "Fixed all the comments on v4" but it's not true.
> Maybe you sent us old patch?
> 
> Anyway, you need to follow Rob's comments.

Krzysztof,

Apologies. Some issues with my mailbox. Rob's response didn't reach me 
for some reason.

I am now seeing them on the web: 
https://lore.kernel.org/lkml/YY7HvCyJ90Ge8mr7@robh.at.kernel.org/

It wasn't deliberate to ignore comments. Apologies.

I will fix them in v6.

Thanks for the quick feedback.

- Keerthy


> 
> 
> Best regards,
> Krzysztof

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

* Re: [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation
  2022-04-13 12:04     ` J, KEERTHY
@ 2022-04-13 12:25       ` Krzysztof Kozlowski
  2022-04-14 15:57       ` Rob Herring
  1 sibling, 0 replies; 20+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-13 12:25 UTC (permalink / raw)
  To: J, KEERTHY, robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: linux-pm, vigneshr, devicetree, linux-kernel

On 13/04/2022 14:04, J, KEERTHY wrote:
> Apologies. Some issues with my mailbox. Rob's response didn't reach me 
> for some reason.
> 
> I am now seeing them on the web: 
> https://lore.kernel.org/lkml/YY7HvCyJ90Ge8mr7@robh.at.kernel.org/
> 
> It wasn't deliberate to ignore comments. Apologies.
> 
> I will fix them in v6.

Sure :)


Best regards,
Krzysztof

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

* Re: [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation
  2022-04-13 12:04     ` J, KEERTHY
  2022-04-13 12:25       ` Krzysztof Kozlowski
@ 2022-04-14 15:57       ` Rob Herring
  1 sibling, 0 replies; 20+ messages in thread
From: Rob Herring @ 2022-04-14 15:57 UTC (permalink / raw)
  To: J, KEERTHY
  Cc: Krzysztof Kozlowski, daniel.lezcano, rui.zhang, amitk, kristo,
	linux-pm, vigneshr, devicetree, linux-kernel

On Wed, Apr 13, 2022 at 05:34:20PM +0530, J, KEERTHY wrote:
> 
> 
> On 4/13/2022 3:43 PM, Krzysztof Kozlowski wrote:
> > On 12/04/2022 12:14, Keerthy wrote:
> > > Add VTM bindings documentation. In the Voltage Thermal
> > > Management Module(VTM), K3 J72XX supplies a voltage
> > > reference and a temperature sensor feature that are gathered in the band
> > > gap voltage and temperature sensor (VBGAPTS) module. The band
> > > gap provides current and voltage reference for its internal
> > > circuits and other analog IP blocks. The analog-to-digital
> > > converter (ADC) produces an output value that is proportional
> > > to the silicon temperature.
> > > 
> > > Signed-off-by: Keerthy <j-keerthy@ti.com>
> > > ---
> > >   .../bindings/thermal/ti,j72xx-thermal.yaml    | 62 +++++++++++++++++++
> > >   1 file changed, 62 insertions(+)
> > >   create mode 100644 Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
> > > 
> > > diff --git a/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml b/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
> > > new file mode 100644
> > > index 000000000000..8483c495cb9a
> > > --- /dev/null
> > > +++ b/Documentation/devicetree/bindings/thermal/ti,j72xx-thermal.yaml
> > > @@ -0,0 +1,62 @@
> > > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > > +%YAML 1.2
> > > +---
> > > +$id: http://devicetree.org/schemas/thermal/ti,j72xx-thermal.yaml#
> > > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > > +
> > > +title: Texas Instruments J72XX VTM (DTS) binding
> > > +
> > > +maintainers:
> > > +  - Keerthy <j-keerthy@ti.com>
> > > +
> > > +properties:
> > > +  compatible:
> > > +    const: ti,j721e-vtm
> > > +    oneOf:
> > > +      - enum:
> > > +          - ti,j721e-vtm
> > > +          - ti,j7200-vtm
> > 
> > It seems you resent this ignoring all of Rob's comments. In changelog of
> > cover letter you wrote "Fixed all the comments on v4" but it's not true.
> > Maybe you sent us old patch?
> > 
> > Anyway, you need to follow Rob's comments.
> 
> Krzysztof,
> 
> Apologies. Some issues with my mailbox. Rob's response didn't reach me for
> some reason.

Maybe because I'm still banned by TI. Just had another bounce a few days 
ago.

Rob

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

* Re: [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support
  2022-04-12 10:14 ` [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
  2022-04-12 17:00   ` kernel test robot
@ 2022-04-20  7:01 ` Dan Carpenter
  2022-04-19 17:23   ` Daniel Lezcano
  2 siblings, 0 replies; 20+ messages in thread
From: kernel test robot @ 2022-04-15  3:58 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 13406 bytes --]

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220412101409.7980-5-j-keerthy@ti.com>
References: <20220412101409.7980-5-j-keerthy@ti.com>
TO: Keerthy <j-keerthy@ti.com>
TO: robh+dt(a)kernel.org
TO: daniel.lezcano(a)linaro.org
TO: rui.zhang(a)intel.com
TO: amitk(a)kernel.org
TO: kristo(a)kernel.org
CC: j-keerthy(a)ti.com
CC: linux-pm(a)vger.kernel.org
CC: vigneshr(a)ti.com
CC: devicetree(a)vger.kernel.org
CC: linux-kernel(a)vger.kernel.org

Hi Keerthy,

I love your patch! Perhaps something to improve:

[auto build test WARNING on robh/for-next]
[also build test WARNING on rafael-pm/thermal v5.18-rc2 next-20220414]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Keerthy/thermal-k3_j72xx_bandgap-Add-the-bandgap-driver-support/20220412-193526
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
config: arc-randconfig-m031-20220411 (https://download.01.org/0day-ci/archive/20220415/202204151117.NLsoANXl-lkp(a)intel.com/config)
compiler: arc-elf-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/thermal/k3_j72xx_bandgap.c:570 k3_j72xx_bandgap_probe() warn: passing devm_ allocated variable to kfree. 'ref_table'

vim +/ref_table +570 drivers/thermal/k3_j72xx_bandgap.c

de47884b9759d9 Keerthy 2022-04-12  410  
de47884b9759d9 Keerthy 2022-04-12  411  static int k3_j72xx_bandgap_probe(struct platform_device *pdev)
de47884b9759d9 Keerthy 2022-04-12  412  {
de47884b9759d9 Keerthy 2022-04-12  413  	int ret = 0, cnt, val, id, table_size = 1024;
de47884b9759d9 Keerthy 2022-04-12  414  	int high_max, low_temp;
de47884b9759d9 Keerthy 2022-04-12  415  	struct resource *res;
de47884b9759d9 Keerthy 2022-04-12  416  	struct device *dev = &pdev->dev;
de47884b9759d9 Keerthy 2022-04-12  417  	struct k3_j72xx_bandgap *bgp;
de47884b9759d9 Keerthy 2022-04-12  418  	struct k3_thermal_data *data;
de47884b9759d9 Keerthy 2022-04-12  419  	int workaround_needed = 0;
de47884b9759d9 Keerthy 2022-04-12  420  	const struct k3_j72xx_bandgap_data *driver_data;
de47884b9759d9 Keerthy 2022-04-12  421  	struct thermal_zone_device *ti_thermal;
de47884b9759d9 Keerthy 2022-04-12  422  	int *ref_table;
de47884b9759d9 Keerthy 2022-04-12  423  	struct err_values err_vals;
de47884b9759d9 Keerthy 2022-04-12  424  
de47884b9759d9 Keerthy 2022-04-12  425  	s64 golden_factors[] = {
de47884b9759d9 Keerthy 2022-04-12  426  		-490019999999999936,
de47884b9759d9 Keerthy 2022-04-12  427  		3251200000000000,
de47884b9759d9 Keerthy 2022-04-12  428  		-1705800000000,
de47884b9759d9 Keerthy 2022-04-12  429  		603730000,
de47884b9759d9 Keerthy 2022-04-12  430  		-92627,
de47884b9759d9 Keerthy 2022-04-12  431  	};
de47884b9759d9 Keerthy 2022-04-12  432  
de47884b9759d9 Keerthy 2022-04-12  433  	s64 pvt_wa_factors[] = {
de47884b9759d9 Keerthy 2022-04-12  434  		-415230000000000000,
de47884b9759d9 Keerthy 2022-04-12  435  		3126600000000000,
de47884b9759d9 Keerthy 2022-04-12  436  		-1157800000000,
de47884b9759d9 Keerthy 2022-04-12  437  	};
de47884b9759d9 Keerthy 2022-04-12  438  
de47884b9759d9 Keerthy 2022-04-12  439  	bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL);
de47884b9759d9 Keerthy 2022-04-12  440  	if (!bgp)
de47884b9759d9 Keerthy 2022-04-12  441  		return -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  442  
de47884b9759d9 Keerthy 2022-04-12  443  	bgp->dev = dev;
de47884b9759d9 Keerthy 2022-04-12  444  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
de47884b9759d9 Keerthy 2022-04-12  445  	bgp->base = devm_ioremap_resource(dev, res);
de47884b9759d9 Keerthy 2022-04-12  446  	if (IS_ERR(bgp->base))
de47884b9759d9 Keerthy 2022-04-12  447  		return PTR_ERR(bgp->base);
de47884b9759d9 Keerthy 2022-04-12  448  
de47884b9759d9 Keerthy 2022-04-12  449  	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
de47884b9759d9 Keerthy 2022-04-12  450  	bgp->cfg2_base = devm_ioremap_resource(dev, res);
de47884b9759d9 Keerthy 2022-04-12  451  	if (IS_ERR(bgp->cfg2_base))
de47884b9759d9 Keerthy 2022-04-12  452  		return PTR_ERR(bgp->cfg2_base);
de47884b9759d9 Keerthy 2022-04-12  453  
de47884b9759d9 Keerthy 2022-04-12  454  	res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
de47884b9759d9 Keerthy 2022-04-12  455  	bgp->fuse_base = devm_ioremap_resource(dev, res);
de47884b9759d9 Keerthy 2022-04-12  456  	if (IS_ERR(bgp->fuse_base))
de47884b9759d9 Keerthy 2022-04-12  457  		return PTR_ERR(bgp->fuse_base);
de47884b9759d9 Keerthy 2022-04-12  458  
de47884b9759d9 Keerthy 2022-04-12  459  	driver_data = of_device_get_match_data(dev);
de47884b9759d9 Keerthy 2022-04-12  460  	if (driver_data)
de47884b9759d9 Keerthy 2022-04-12  461  		workaround_needed = driver_data->has_errata_i2128;
de47884b9759d9 Keerthy 2022-04-12  462  
de47884b9759d9 Keerthy 2022-04-12  463  	pm_runtime_enable(dev);
de47884b9759d9 Keerthy 2022-04-12  464  	ret = pm_runtime_get_sync(dev);
de47884b9759d9 Keerthy 2022-04-12  465  	if (ret < 0) {
de47884b9759d9 Keerthy 2022-04-12  466  		pm_runtime_put_noidle(dev);
de47884b9759d9 Keerthy 2022-04-12  467  		pm_runtime_disable(dev);
de47884b9759d9 Keerthy 2022-04-12  468  		return ret;
de47884b9759d9 Keerthy 2022-04-12  469  	}
de47884b9759d9 Keerthy 2022-04-12  470  
de47884b9759d9 Keerthy 2022-04-12  471  	/* Get the sensor count in the VTM */
de47884b9759d9 Keerthy 2022-04-12  472  	val = readl(bgp->base + K3_VTM_DEVINFO_PWR0_OFFSET);
de47884b9759d9 Keerthy 2022-04-12  473  	cnt = val & K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK;
de47884b9759d9 Keerthy 2022-04-12  474  	cnt >>= __ffs(K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK);
de47884b9759d9 Keerthy 2022-04-12  475  
de47884b9759d9 Keerthy 2022-04-12  476  	data = devm_kcalloc(bgp->dev, cnt, sizeof(*data), GFP_KERNEL);
de47884b9759d9 Keerthy 2022-04-12  477  	if (!data) {
de47884b9759d9 Keerthy 2022-04-12  478  		ret = -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  479  		goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  480  	}
de47884b9759d9 Keerthy 2022-04-12  481  
de47884b9759d9 Keerthy 2022-04-12  482  	ref_table = devm_kzalloc(bgp->dev, sizeof(*ref_table) * table_size,
de47884b9759d9 Keerthy 2022-04-12  483  				 GFP_KERNEL);
de47884b9759d9 Keerthy 2022-04-12  484  	if (!ref_table) {
de47884b9759d9 Keerthy 2022-04-12  485  		ret = -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  486  		goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  487  	}
de47884b9759d9 Keerthy 2022-04-12  488  
de47884b9759d9 Keerthy 2022-04-12  489  	derived_table = devm_kzalloc(bgp->dev, sizeof(*derived_table) * table_size,
de47884b9759d9 Keerthy 2022-04-12  490  				     GFP_KERNEL);
de47884b9759d9 Keerthy 2022-04-12  491  	if (!derived_table) {
de47884b9759d9 Keerthy 2022-04-12  492  		ret = -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  493  		goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  494  	}
de47884b9759d9 Keerthy 2022-04-12  495  
de47884b9759d9 Keerthy 2022-04-12  496  	/* Workaround not needed if bit30/bit31 is set even for J721e */
de47884b9759d9 Keerthy 2022-04-12  497  	if (workaround_needed && (readl(bgp->fuse_base + 0x0) & 0xc0000000) == 0xc0000000)
de47884b9759d9 Keerthy 2022-04-12  498  		workaround_needed = false;
de47884b9759d9 Keerthy 2022-04-12  499  
de47884b9759d9 Keerthy 2022-04-12  500  	dev_dbg(bgp->dev, "Work around %sneeded\n",
de47884b9759d9 Keerthy 2022-04-12  501  		workaround_needed ? "not " : "");
de47884b9759d9 Keerthy 2022-04-12  502  
de47884b9759d9 Keerthy 2022-04-12  503  	if (!workaround_needed)
de47884b9759d9 Keerthy 2022-04-12  504  		init_table(5, ref_table, golden_factors);
de47884b9759d9 Keerthy 2022-04-12  505  	else
de47884b9759d9 Keerthy 2022-04-12  506  		init_table(3, ref_table, pvt_wa_factors);
de47884b9759d9 Keerthy 2022-04-12  507  
de47884b9759d9 Keerthy 2022-04-12  508  	/* Register the thermal sensors */
de47884b9759d9 Keerthy 2022-04-12  509  	for (id = 0; id < cnt; id++) {
de47884b9759d9 Keerthy 2022-04-12  510  		data[id].bgp = bgp;
de47884b9759d9 Keerthy 2022-04-12  511  		data[id].ctrl_offset = K3_VTM_TMPSENS0_CTRL_OFFSET + id * 0x20;
de47884b9759d9 Keerthy 2022-04-12  512  		data[id].stat_offset = data[id].ctrl_offset +
de47884b9759d9 Keerthy 2022-04-12  513  					K3_VTM_TMPSENS_STAT_OFFSET;
de47884b9759d9 Keerthy 2022-04-12  514  
de47884b9759d9 Keerthy 2022-04-12  515  		if (workaround_needed) {
de47884b9759d9 Keerthy 2022-04-12  516  			/* ref adc values for -40C, 30C & 125C respectively */
de47884b9759d9 Keerthy 2022-04-12  517  			err_vals.refs[0] = MINUS40CREF;
de47884b9759d9 Keerthy 2022-04-12  518  			err_vals.refs[1] = PLUS30CREF;
de47884b9759d9 Keerthy 2022-04-12  519  			err_vals.refs[2] = PLUS125CREF;
de47884b9759d9 Keerthy 2022-04-12  520  			err_vals.refs[3] = PLUS150CREF;
de47884b9759d9 Keerthy 2022-04-12  521  			get_efuse_values(id, &data[id], err_vals.errs, bgp);
de47884b9759d9 Keerthy 2022-04-12  522  		}
de47884b9759d9 Keerthy 2022-04-12  523  
de47884b9759d9 Keerthy 2022-04-12  524  		if (id == 0 && workaround_needed)
de47884b9759d9 Keerthy 2022-04-12  525  			prep_lookup_table(&err_vals, ref_table);
de47884b9759d9 Keerthy 2022-04-12  526  		else if (id == 0 && !workaround_needed)
de47884b9759d9 Keerthy 2022-04-12  527  			memcpy(derived_table, ref_table, table_size * 4);
de47884b9759d9 Keerthy 2022-04-12  528  
de47884b9759d9 Keerthy 2022-04-12  529  		val = readl(data[id].bgp->cfg2_base + data[id].ctrl_offset);
de47884b9759d9 Keerthy 2022-04-12  530  		val |= (K3_VTM_TMPSENS_CTRL_MAXT_OUTRG_EN |
de47884b9759d9 Keerthy 2022-04-12  531  			K3_VTM_TMPSENS_CTRL_SOC |
de47884b9759d9 Keerthy 2022-04-12  532  			K3_VTM_TMPSENS_CTRL_CLRZ | BIT(4));
de47884b9759d9 Keerthy 2022-04-12  533  		writel(val, data[id].bgp->cfg2_base + data[id].ctrl_offset);
de47884b9759d9 Keerthy 2022-04-12  534  
de47884b9759d9 Keerthy 2022-04-12  535  		bgp->ts_data[id] = &data[id];
de47884b9759d9 Keerthy 2022-04-12  536  		ti_thermal =
de47884b9759d9 Keerthy 2022-04-12  537  		devm_thermal_zone_of_sensor_register(bgp->dev, id,
de47884b9759d9 Keerthy 2022-04-12  538  						     &data[id],
de47884b9759d9 Keerthy 2022-04-12  539  						     &k3_of_thermal_ops);
de47884b9759d9 Keerthy 2022-04-12  540  		if (IS_ERR(ti_thermal)) {
de47884b9759d9 Keerthy 2022-04-12  541  			dev_err(bgp->dev, "thermal zone device is NULL\n");
de47884b9759d9 Keerthy 2022-04-12  542  			ret = PTR_ERR(ti_thermal);
de47884b9759d9 Keerthy 2022-04-12  543  			goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  544  		}
de47884b9759d9 Keerthy 2022-04-12  545  	}
de47884b9759d9 Keerthy 2022-04-12  546  
de47884b9759d9 Keerthy 2022-04-12  547  	/*
de47884b9759d9 Keerthy 2022-04-12  548  	 * Program TSHUT thresholds
de47884b9759d9 Keerthy 2022-04-12  549  	 * Step 1: set the thresholds to ~123C and 105C WKUP_VTM_MISC_CTRL2
de47884b9759d9 Keerthy 2022-04-12  550  	 * Step 2: WKUP_VTM_TMPSENS_CTRL_j set the MAXT_OUTRG_EN  bit
de47884b9759d9 Keerthy 2022-04-12  551  	 *         This is already taken care as per of init
de47884b9759d9 Keerthy 2022-04-12  552  	 * Step 3: WKUP_VTM_MISC_CTRL set the ANYMAXT_OUTRG_ALERT_EN  bit
de47884b9759d9 Keerthy 2022-04-12  553  	 */
de47884b9759d9 Keerthy 2022-04-12  554  	high_max = k3_j72xx_bandgap_temp_to_adc_code(MAX_TEMP);
de47884b9759d9 Keerthy 2022-04-12  555  	low_temp = k3_j72xx_bandgap_temp_to_adc_code(COOL_DOWN_TEMP);
de47884b9759d9 Keerthy 2022-04-12  556  
de47884b9759d9 Keerthy 2022-04-12  557  	writel((low_temp << 16) | high_max, data[0].bgp->cfg2_base +
de47884b9759d9 Keerthy 2022-04-12  558  	       K3_VTM_MISC_CTRL2_OFFSET);
de47884b9759d9 Keerthy 2022-04-12  559  	mdelay(100);
de47884b9759d9 Keerthy 2022-04-12  560  	writel(K3_VTM_ANYMAXT_OUTRG_ALERT_EN, data[0].bgp->cfg2_base +
de47884b9759d9 Keerthy 2022-04-12  561  	       K3_VTM_MISC_CTRL_OFFSET);
de47884b9759d9 Keerthy 2022-04-12  562  
de47884b9759d9 Keerthy 2022-04-12  563  	platform_set_drvdata(pdev, bgp);
de47884b9759d9 Keerthy 2022-04-12  564  
de47884b9759d9 Keerthy 2022-04-12  565  	print_look_up_table(dev, ref_table);
de47884b9759d9 Keerthy 2022-04-12  566  	/*
de47884b9759d9 Keerthy 2022-04-12  567  	 * Now that the derived_table has the appropriate look up values
de47884b9759d9 Keerthy 2022-04-12  568  	 * Free up the ref_table
de47884b9759d9 Keerthy 2022-04-12  569  	 */
de47884b9759d9 Keerthy 2022-04-12 @570  	kfree(ref_table);
de47884b9759d9 Keerthy 2022-04-12  571  
de47884b9759d9 Keerthy 2022-04-12  572  	return 0;
de47884b9759d9 Keerthy 2022-04-12  573  
de47884b9759d9 Keerthy 2022-04-12  574  err_alloc:
de47884b9759d9 Keerthy 2022-04-12  575  	pm_runtime_put_sync(&pdev->dev);
de47884b9759d9 Keerthy 2022-04-12  576  	pm_runtime_disable(&pdev->dev);
de47884b9759d9 Keerthy 2022-04-12  577  
de47884b9759d9 Keerthy 2022-04-12  578  	return ret;
de47884b9759d9 Keerthy 2022-04-12  579  }
de47884b9759d9 Keerthy 2022-04-12  580  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* Re: [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support
  2022-04-12 10:14 ` [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
  2022-04-12 17:00   ` kernel test robot
  2022-04-13 10:17   ` Krzysztof Kozlowski
@ 2022-04-19 17:23   ` Daniel Lezcano
  2 siblings, 0 replies; 20+ messages in thread
From: Daniel Lezcano @ 2022-04-19 17:23 UTC (permalink / raw)
  To: Keerthy, robh+dt, rui.zhang, amitk, kristo
  Cc: linux-pm, vigneshr, devicetree, linux-kernel


Hi Kheerty,

On 12/04/2022 12:14, Keerthy wrote:


[ ... ]

> +/**
> + * struct err_values - structure containing error/reference values
> + * @refs: reference error values for -40C, 30C, 125C & 150C
> + * @errs: Actual error values for -40C, 30C, 125C & 150C read from the efuse
> + */
> +struct err_values {
> +	int refs[4];
> +	int errs[4];
> +};
> +
> +static void create_table_segments(struct err_values *err_vals, int seg,
> +				  int *ref_table)
> +{
> +	int m = 0, c, num, den, i, err, idx1, idx2, err1, err2, ref1, ref2;
> +
> +	if (seg == 0)
> +		idx1 = 0;
> +	else
> +		idx1 = err_vals->refs[seg];
> +
> +	idx2 = err_vals->refs[seg + 1];
> +	err1 = err_vals->errs[seg];
> +	err2 = err_vals->errs[seg + 1];
> +	ref1 = err_vals->refs[seg];
> +	ref2 = err_vals->refs[seg + 1];
> +
> +	/*
> +	 * Calculate the slope with adc values read from the register
> +	 * as the y-axis param and err in adc value as x-axis param
> +	 */
> +	num = ref2 - ref1;
> +	den = err2 - err1;
> +	if (den)
> +		m = num / den;
> +	c = ref2 - m * err2;
> +
> +	/*
> +	 * Take care of divide by zero error if error values are same
> +	 * Or when the slope is 0
> +	 */
> +	if (den != 0 && m != 0) {
> +		for (i = idx1; i <= idx2; i++) {
> +			err = (i - c) / m;
> +			if (((i + err1) < 0) || ((i + err1) > 1023))
> +				continue;

Should the test being against 'err' not 'err1' ?

> +			derived_table[i] = ref_table[i + err];
> +		}
> +	} else { /* Constant error take care of divide by zero */
> +		for (i = idx1; i <= idx2; i++) {
> +			if (((i + err1) < 0) || ((i + err1) > 1023))
> +				continue;
> +			derived_table[i] = ref_table[i + err1];
> +		}
> +	}
> +}
> +
> +static int prep_lookup_table(struct err_values *err_vals, int *ref_table)
> +{
> +	int inc, i, seg;
> +
> +	/*
> +	 * Fill up the lookup table under 3 segments
> +	 * region -40C to +30C
> +	 * region +30C to +125C
> +	 * region +125C to +150C
> +	 */
> +	for (seg = 0; seg < 3; seg++)
> +		create_table_segments(err_vals, seg, ref_table);
> +
> +	/* Get to the first valid temperature */
> +	i = 0;
> +	while (!derived_table[i])
> +		i++;
> +
> +	/*
> +	 * Get to the last zero index and back fill the temperature for
> +	 * sake of continuity
> +	 */
> +	if (i) {
> +		/* 300 milli celsius steps */
> +		while (i--)
> +			derived_table[i] = derived_table[i + 1] - 300;
> +		/* case 0 */
> +		derived_table[i] = derived_table[i + 1] - 300;
> +	}

memset ?

> +
> +	/*
> +	 * Fill the last trailing 0s which are unfilled with increments of
> +	 * 100 milli celsius till 1023 code
> +	 */
> +	i = 1023;
> +	while (!derived_table[i])
> +		i--;

All those loop can be replaced by addresses variant IMO. Up to you if 
you want to use mem* variants.

eg. void *flz = memrchr(derived_table, 0, size); /* find last zero */

> +
> +	i++;
> +	inc = 1;
> +	while (i < 1024) {
> +		derived_table[i] = derived_table[i - 1] + inc * 100;
> +		i++;
> +	}
> +
> +	return 0;
> +}

Please replace all the 1024-ish literals everywhere by a macro

> +struct k3_thermal_data;
> +
> +struct k3_j72xx_bandgap {
> +	struct device *dev;
> +	void __iomem *base;
> +	void __iomem *cfg2_base;
> +	void __iomem *fuse_base;
> +	struct k3_thermal_data *ts_data[K3_VTM_MAX_NUM_TS];
> +};
> +
> +/* common data structures */
> +struct k3_thermal_data {
> +	struct k3_j72xx_bandgap *bgp;
> +	u32 ctrl_offset;
> +	u32 stat_offset;
> +};
> +
> +static int two_cmp(int tmp, int mask)
> +{
> +	tmp = ~(tmp);
> +	tmp &= mask;
> +	tmp += 1;
> +
> +	/* Return negative value */
> +	return (0 - tmp);
> +}
> +
> +static unsigned int vtm_get_best_value(unsigned int s0, unsigned int s1,
> +				       unsigned int s2)
> +{
> +	int d01 = abs(s0 - s1);
> +	int d02 = abs(s0 - s2);
> +	int d12 = abs(s1 - s2);
> +
> +	if (d01 <= d02 && d01 <= d12)
> +		return (s0 + s1) / 2;
> +
> +	if (d02 <= d01 && d02 <= d12)
> +		return (s0 + s2) / 2;
> +
> +	return (s1 + s2) / 2;
> +}
> +
> +static inline int k3_bgp_read_temp(struct k3_thermal_data *devdata,
> +				   int *temp)
> +{
> +	struct k3_j72xx_bandgap *bgp;
> +	unsigned int dtemp, s0, s1, s2;
> +
> +	bgp = devdata->bgp;
> +	/*
> +	 * Errata is applicable for am654 pg 1.0 silicon/J7ES. There
> +	 * is a variation of the order for certain degree centigrade on AM654.
> +	 * Work around that by getting the average of two closest
> +	 * readings out of three readings everytime we want to
> +	 * report temperatures.
> +	 *
> +	 * Errata workaround.
> +	 */
> +	s0 = readl(bgp->base + devdata->stat_offset) &
> +		K3_VTM_TS_STAT_DTEMP_MASK;
> +	s1 = readl(bgp->base + devdata->stat_offset) &
> +		K3_VTM_TS_STAT_DTEMP_MASK;
> +	s2 = readl(bgp->base + devdata->stat_offset) &
> +		K3_VTM_TS_STAT_DTEMP_MASK;
> +	dtemp = vtm_get_best_value(s0, s1, s2);
> +
> +	if (dtemp < 0 || dtemp > 1023)
> +		return -EINVAL;
> +
> +	*temp = derived_table[dtemp];
> +
> +	return 0;
> +}
> +
> +/* Get temperature callback function for thermal zone */
> +static int k3_thermal_get_temp(void *devdata, int *temp)
> +{
> +	struct k3_thermal_data *data = devdata;
> +	int ret = 0;
> +
> +	ret = k3_bgp_read_temp(data, temp);
> +	if (ret)
> +		return ret;
> +
> +	return ret;
> +}
> +
> +static const struct thermal_zone_of_device_ops k3_of_thermal_ops = {
> +	.get_temp = k3_thermal_get_temp,
> +};
> +
> +static int k3_j72xx_bandgap_temp_to_adc_code(int temp)
> +{
> +	int low = 0, high = 1023, mid;
> +
> +	if (temp > 160000 || temp < -50000)
> +		return -EINVAL;
> +
> +	/* Binary search to find the adc code */
> +	while (low < (high - 1)) {
> +		mid = (low + high) / 2;
> +		if (temp <= derived_table[mid])
> +			high = mid;
> +		else
> +			low = mid;
> +	}
> +
> +	return mid;
> +}
> +
> +static void get_efuse_values(int id, struct k3_thermal_data *data, int *err,
> +			     struct k3_j72xx_bandgap *bgp)
> +{
> +	int i, tmp, pow;
> +	int ct_offsets[K3_VTM_CORRECTION_TEMP_CNT];
> +	int ct_bm[K3_VTM_CORRECTION_TEMP_CNT];
> +
> +	/* Populate efuse reg offsets & Bit masks for -40C, 30C, 125C */
> +	switch (id) {
> +	case 0:
> +		ct_offsets[0] = 0x0;
> +		ct_offsets[1] = 0x8;
> +		ct_offsets[2] = 0x4;
> +		ct_bm[0] = 0x3f;
> +		ct_bm[1] = 0x1fe000;
> +		ct_bm[2] = 0x1ff;
> +		break;
> +
> +	case 1:
> +		ct_offsets[0] = 0x0;
> +		ct_offsets[1] = 0x8;
> +		ct_offsets[2] = 0x4;
> +		ct_bm[0] = 0xfc0;
> +		ct_bm[1] = 0x1fe00000;
> +		ct_bm[2] = 0x3fe00;
> +		break;
> +
> +	case 2:
> +		ct_offsets[0] = 0x0;
> +		ct_offsets[1] = -1;
> +		ct_offsets[2] = 0x4;
> +		ct_bm[0] = 0x3f000;
> +		ct_bm[1] = 0x7f800000;
> +		ct_bm[2] = 0x7fc0000;
> +		break;
> +
> +	case 3:
> +		ct_offsets[0] = 0x0;
> +		ct_offsets[1] = 0xC;
> +		ct_offsets[2] = -1; /* Spread across 2 registers */
> +		ct_bm[0] = 0xfc0000;
> +		ct_bm[1] = 0x1fe0;
> +		ct_bm[2] = 0x1f800000;
> +		break;
> +
> +	case 4:
> +		ct_offsets[0] = 0x0;
> +		ct_offsets[1] = 0xc;
> +		ct_offsets[2] = 0x8;
> +		ct_bm[0] = 0x3f000000;
> +		ct_bm[1] = 0x1fe000;
> +		ct_bm[2] = 0x1ff0;
> +		break;
> +	}

The way this is initialized looks strange to me

Why not:

int ct_offsets[][] = {
	{ 0x0, 0x8, 0x4 },
	{ 0x0, 0x8, 0x4 },
	{ 0x0, -1,  0x4 },
	{ 0x0, 0xC, -1 }
	{ 0x0, 0xc, 0x8 }
  };

int ct_bm[][] = {
	{ 0x3f, 0x1fe000, 0x1ff },
	{ 0xfc0, 0x1fe000, 0x3fe00 },
	{ 0x3f000, 0x7f800000, 0x7fc0000 },
	{ 0xfc0000, 0x1fe0, 0x1f800000 },
	{ 0x3f000000, 0x1fe000, 0x1ff0 }
};

And then : ct_offsets[id][i] below ?

> +	for (i = 0; i < 3; i++) {

ARRAY_SIZE on ct_offsets ?

> +		/* Extract the offset value using bit-mask */
> +		if (ct_offsets[i] == -1 && i == 1) {
> +			/* 25C offset Case of Sensor 2 split between 2 regs */
> +			tmp = (readl(bgp->fuse_base + 0x8) & 0xE0000000) >> (29);
> +			tmp |= ((readl(bgp->fuse_base + 0xC) & 0x1F) << 3);
> +			pow = tmp & 0x80;
> +		} else if (ct_offsets[i] == -1 && i == 2) {
> +			/* 125C Case of Sensor 3 split between 2 regs */
> +			tmp = (readl(bgp->fuse_base + 0x4) & 0xF8000000) >> (27);
> +			tmp |= ((readl(bgp->fuse_base + 0x8) & 0xF) << 5);
> +			pow = tmp & 0x100;
> +		} else {
> +			tmp = readl(bgp->fuse_base + ct_offsets[i]);
> +			tmp &= ct_bm[i];
> +			tmp = tmp >> __ffs(ct_bm[i]);
> +
> +			/* Obtain the sign bit pow*/
> +			pow = ct_bm[i] >> __ffs(ct_bm[i]);
> +			pow += 1;
> +			pow /= 2;
> +		}
> +
> +		/* Check for negative value */
> +		if (tmp & pow) {
> +			/* 2's complement value */
> +			tmp = two_cmp(tmp, ct_bm[i] >> __ffs(ct_bm[i]));
> +		}
> +		err[i] = tmp;
> +	}
> +
> +	/* Err value for 150C is set to 0 */
> +	err[i] = 0;
> +}
> +
> +static void print_look_up_table(struct device *dev, int *ref_table)
> +{
> +	int i;
> +
> +	dev_dbg(dev, "The contents of derived array\n");
> +	dev_dbg(dev, "Code   Temperaturei\n");

Typo: "Temperaturei"

> +	for (i = 0; i <= 1023; i++)
> +		dev_dbg(dev, "%d       %d %d\n", i, derived_table[i], ref_table[i]);
> +}
> +
> +static const struct of_device_id of_k3_j72xx_bandgap_match[];

Pointless forward declaration

> +
> +struct k3_j72xx_bandgap_data {
> +	unsigned int has_errata_i2128;
> +};
> +
> +static int k3_j72xx_bandgap_probe(struct platform_device *pdev)
> +{
> +	int ret = 0, cnt, val, id, table_size = 1024;

table_size to be replaced by the macro mentioned above

> +	int high_max, low_temp;
> +	struct resource *res;
> +	struct device *dev = &pdev->dev;
> +	struct k3_j72xx_bandgap *bgp;
> +	struct k3_thermal_data *data;
> +	int workaround_needed = 0;
> +	const struct k3_j72xx_bandgap_data *driver_data;
> +	struct thermal_zone_device *ti_thermal;
> +	int *ref_table;
> +	struct err_values err_vals;

[ ... ]


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

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

* Re: [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support
@ 2022-04-20  7:01 ` Dan Carpenter
  0 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2022-04-20  7:01 UTC (permalink / raw)
  To: kbuild, Keerthy, robh+dt, daniel.lezcano, rui.zhang, amitk, kristo
  Cc: lkp, kbuild-all, j-keerthy, linux-pm, vigneshr, devicetree, linux-kernel

Hi Keerthy,

url:    https://github.com/intel-lab-lkp/linux/commits/Keerthy/thermal-k3_j72xx_bandgap-Add-the-bandgap-driver-support/20220412-193526
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: arc-randconfig-m031-20220411 (https://download.01.org/0day-ci/archive/20220415/202204151117.NLsoANXl-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/thermal/k3_j72xx_bandgap.c:570 k3_j72xx_bandgap_probe() warn: passing devm_ allocated variable to kfree. 'ref_table'

vim +/ref_table +570 drivers/thermal/k3_j72xx_bandgap.c

de47884b9759d9 Keerthy 2022-04-12  411  static int k3_j72xx_bandgap_probe(struct platform_device *pdev)
de47884b9759d9 Keerthy 2022-04-12  412  {
de47884b9759d9 Keerthy 2022-04-12  413  	int ret = 0, cnt, val, id, table_size = 1024;
de47884b9759d9 Keerthy 2022-04-12  414  	int high_max, low_temp;
de47884b9759d9 Keerthy 2022-04-12  415  	struct resource *res;
de47884b9759d9 Keerthy 2022-04-12  416  	struct device *dev = &pdev->dev;
de47884b9759d9 Keerthy 2022-04-12  417  	struct k3_j72xx_bandgap *bgp;
de47884b9759d9 Keerthy 2022-04-12  418  	struct k3_thermal_data *data;
de47884b9759d9 Keerthy 2022-04-12  419  	int workaround_needed = 0;
de47884b9759d9 Keerthy 2022-04-12  420  	const struct k3_j72xx_bandgap_data *driver_data;
de47884b9759d9 Keerthy 2022-04-12  421  	struct thermal_zone_device *ti_thermal;
de47884b9759d9 Keerthy 2022-04-12  422  	int *ref_table;
de47884b9759d9 Keerthy 2022-04-12  423  	struct err_values err_vals;
de47884b9759d9 Keerthy 2022-04-12  424  
de47884b9759d9 Keerthy 2022-04-12  425  	s64 golden_factors[] = {
de47884b9759d9 Keerthy 2022-04-12  426  		-490019999999999936,
de47884b9759d9 Keerthy 2022-04-12  427  		3251200000000000,
de47884b9759d9 Keerthy 2022-04-12  428  		-1705800000000,
de47884b9759d9 Keerthy 2022-04-12  429  		603730000,
de47884b9759d9 Keerthy 2022-04-12  430  		-92627,
de47884b9759d9 Keerthy 2022-04-12  431  	};
de47884b9759d9 Keerthy 2022-04-12  432  
de47884b9759d9 Keerthy 2022-04-12  433  	s64 pvt_wa_factors[] = {
de47884b9759d9 Keerthy 2022-04-12  434  		-415230000000000000,
de47884b9759d9 Keerthy 2022-04-12  435  		3126600000000000,
de47884b9759d9 Keerthy 2022-04-12  436  		-1157800000000,
de47884b9759d9 Keerthy 2022-04-12  437  	};
de47884b9759d9 Keerthy 2022-04-12  438  
de47884b9759d9 Keerthy 2022-04-12  439  	bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL);
de47884b9759d9 Keerthy 2022-04-12  440  	if (!bgp)
de47884b9759d9 Keerthy 2022-04-12  441  		return -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  442  
de47884b9759d9 Keerthy 2022-04-12  443  	bgp->dev = dev;
de47884b9759d9 Keerthy 2022-04-12  444  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
de47884b9759d9 Keerthy 2022-04-12  445  	bgp->base = devm_ioremap_resource(dev, res);
de47884b9759d9 Keerthy 2022-04-12  446  	if (IS_ERR(bgp->base))
de47884b9759d9 Keerthy 2022-04-12  447  		return PTR_ERR(bgp->base);
de47884b9759d9 Keerthy 2022-04-12  448  
de47884b9759d9 Keerthy 2022-04-12  449  	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
de47884b9759d9 Keerthy 2022-04-12  450  	bgp->cfg2_base = devm_ioremap_resource(dev, res);
de47884b9759d9 Keerthy 2022-04-12  451  	if (IS_ERR(bgp->cfg2_base))
de47884b9759d9 Keerthy 2022-04-12  452  		return PTR_ERR(bgp->cfg2_base);
de47884b9759d9 Keerthy 2022-04-12  453  
de47884b9759d9 Keerthy 2022-04-12  454  	res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
de47884b9759d9 Keerthy 2022-04-12  455  	bgp->fuse_base = devm_ioremap_resource(dev, res);
de47884b9759d9 Keerthy 2022-04-12  456  	if (IS_ERR(bgp->fuse_base))
de47884b9759d9 Keerthy 2022-04-12  457  		return PTR_ERR(bgp->fuse_base);
de47884b9759d9 Keerthy 2022-04-12  458  
de47884b9759d9 Keerthy 2022-04-12  459  	driver_data = of_device_get_match_data(dev);
de47884b9759d9 Keerthy 2022-04-12  460  	if (driver_data)
de47884b9759d9 Keerthy 2022-04-12  461  		workaround_needed = driver_data->has_errata_i2128;
de47884b9759d9 Keerthy 2022-04-12  462  
de47884b9759d9 Keerthy 2022-04-12  463  	pm_runtime_enable(dev);
de47884b9759d9 Keerthy 2022-04-12  464  	ret = pm_runtime_get_sync(dev);
de47884b9759d9 Keerthy 2022-04-12  465  	if (ret < 0) {
de47884b9759d9 Keerthy 2022-04-12  466  		pm_runtime_put_noidle(dev);
de47884b9759d9 Keerthy 2022-04-12  467  		pm_runtime_disable(dev);
de47884b9759d9 Keerthy 2022-04-12  468  		return ret;
de47884b9759d9 Keerthy 2022-04-12  469  	}
de47884b9759d9 Keerthy 2022-04-12  470  
de47884b9759d9 Keerthy 2022-04-12  471  	/* Get the sensor count in the VTM */
de47884b9759d9 Keerthy 2022-04-12  472  	val = readl(bgp->base + K3_VTM_DEVINFO_PWR0_OFFSET);
de47884b9759d9 Keerthy 2022-04-12  473  	cnt = val & K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK;
de47884b9759d9 Keerthy 2022-04-12  474  	cnt >>= __ffs(K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK);
de47884b9759d9 Keerthy 2022-04-12  475  
de47884b9759d9 Keerthy 2022-04-12  476  	data = devm_kcalloc(bgp->dev, cnt, sizeof(*data), GFP_KERNEL);
de47884b9759d9 Keerthy 2022-04-12  477  	if (!data) {
de47884b9759d9 Keerthy 2022-04-12  478  		ret = -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  479  		goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  480  	}
de47884b9759d9 Keerthy 2022-04-12  481  
de47884b9759d9 Keerthy 2022-04-12  482  	ref_table = devm_kzalloc(bgp->dev, sizeof(*ref_table) * table_size,
de47884b9759d9 Keerthy 2022-04-12  483  				 GFP_KERNEL);

This should be allocated with regular kzalloc() because it's freed at
the end of the function.  It doesn't stay for the life of the device.

de47884b9759d9 Keerthy 2022-04-12  484  	if (!ref_table) {
de47884b9759d9 Keerthy 2022-04-12  485  		ret = -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  486  		goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  487  	}
de47884b9759d9 Keerthy 2022-04-12  488  
de47884b9759d9 Keerthy 2022-04-12  489  	derived_table = devm_kzalloc(bgp->dev, sizeof(*derived_table) * table_size,
de47884b9759d9 Keerthy 2022-04-12  490  				     GFP_KERNEL);
de47884b9759d9 Keerthy 2022-04-12  491  	if (!derived_table) {
de47884b9759d9 Keerthy 2022-04-12  492  		ret = -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  493  		goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  494  	}
de47884b9759d9 Keerthy 2022-04-12  495  
de47884b9759d9 Keerthy 2022-04-12  496  	/* Workaround not needed if bit30/bit31 is set even for J721e */
de47884b9759d9 Keerthy 2022-04-12  497  	if (workaround_needed && (readl(bgp->fuse_base + 0x0) & 0xc0000000) == 0xc0000000)
de47884b9759d9 Keerthy 2022-04-12  498  		workaround_needed = false;
de47884b9759d9 Keerthy 2022-04-12  499  
de47884b9759d9 Keerthy 2022-04-12  500  	dev_dbg(bgp->dev, "Work around %sneeded\n",
de47884b9759d9 Keerthy 2022-04-12  501  		workaround_needed ? "not " : "");
de47884b9759d9 Keerthy 2022-04-12  502  
de47884b9759d9 Keerthy 2022-04-12  503  	if (!workaround_needed)
de47884b9759d9 Keerthy 2022-04-12  504  		init_table(5, ref_table, golden_factors);
de47884b9759d9 Keerthy 2022-04-12  505  	else
de47884b9759d9 Keerthy 2022-04-12  506  		init_table(3, ref_table, pvt_wa_factors);
de47884b9759d9 Keerthy 2022-04-12  507  
de47884b9759d9 Keerthy 2022-04-12  508  	/* Register the thermal sensors */
de47884b9759d9 Keerthy 2022-04-12  509  	for (id = 0; id < cnt; id++) {
de47884b9759d9 Keerthy 2022-04-12  510  		data[id].bgp = bgp;
de47884b9759d9 Keerthy 2022-04-12  511  		data[id].ctrl_offset = K3_VTM_TMPSENS0_CTRL_OFFSET + id * 0x20;
de47884b9759d9 Keerthy 2022-04-12  512  		data[id].stat_offset = data[id].ctrl_offset +
de47884b9759d9 Keerthy 2022-04-12  513  					K3_VTM_TMPSENS_STAT_OFFSET;
de47884b9759d9 Keerthy 2022-04-12  514  
de47884b9759d9 Keerthy 2022-04-12  515  		if (workaround_needed) {
de47884b9759d9 Keerthy 2022-04-12  516  			/* ref adc values for -40C, 30C & 125C respectively */
de47884b9759d9 Keerthy 2022-04-12  517  			err_vals.refs[0] = MINUS40CREF;
de47884b9759d9 Keerthy 2022-04-12  518  			err_vals.refs[1] = PLUS30CREF;
de47884b9759d9 Keerthy 2022-04-12  519  			err_vals.refs[2] = PLUS125CREF;
de47884b9759d9 Keerthy 2022-04-12  520  			err_vals.refs[3] = PLUS150CREF;
de47884b9759d9 Keerthy 2022-04-12  521  			get_efuse_values(id, &data[id], err_vals.errs, bgp);
de47884b9759d9 Keerthy 2022-04-12  522  		}
de47884b9759d9 Keerthy 2022-04-12  523  
de47884b9759d9 Keerthy 2022-04-12  524  		if (id == 0 && workaround_needed)
de47884b9759d9 Keerthy 2022-04-12  525  			prep_lookup_table(&err_vals, ref_table);
de47884b9759d9 Keerthy 2022-04-12  526  		else if (id == 0 && !workaround_needed)
de47884b9759d9 Keerthy 2022-04-12  527  			memcpy(derived_table, ref_table, table_size * 4);
de47884b9759d9 Keerthy 2022-04-12  528  
de47884b9759d9 Keerthy 2022-04-12  529  		val = readl(data[id].bgp->cfg2_base + data[id].ctrl_offset);
de47884b9759d9 Keerthy 2022-04-12  530  		val |= (K3_VTM_TMPSENS_CTRL_MAXT_OUTRG_EN |
de47884b9759d9 Keerthy 2022-04-12  531  			K3_VTM_TMPSENS_CTRL_SOC |
de47884b9759d9 Keerthy 2022-04-12  532  			K3_VTM_TMPSENS_CTRL_CLRZ | BIT(4));
de47884b9759d9 Keerthy 2022-04-12  533  		writel(val, data[id].bgp->cfg2_base + data[id].ctrl_offset);
de47884b9759d9 Keerthy 2022-04-12  534  
de47884b9759d9 Keerthy 2022-04-12  535  		bgp->ts_data[id] = &data[id];
de47884b9759d9 Keerthy 2022-04-12  536  		ti_thermal =
de47884b9759d9 Keerthy 2022-04-12  537  		devm_thermal_zone_of_sensor_register(bgp->dev, id,
de47884b9759d9 Keerthy 2022-04-12  538  						     &data[id],
de47884b9759d9 Keerthy 2022-04-12  539  						     &k3_of_thermal_ops);
de47884b9759d9 Keerthy 2022-04-12  540  		if (IS_ERR(ti_thermal)) {
de47884b9759d9 Keerthy 2022-04-12  541  			dev_err(bgp->dev, "thermal zone device is NULL\n");
de47884b9759d9 Keerthy 2022-04-12  542  			ret = PTR_ERR(ti_thermal);
de47884b9759d9 Keerthy 2022-04-12  543  			goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  544  		}
de47884b9759d9 Keerthy 2022-04-12  545  	}
de47884b9759d9 Keerthy 2022-04-12  546  
de47884b9759d9 Keerthy 2022-04-12  547  	/*
de47884b9759d9 Keerthy 2022-04-12  548  	 * Program TSHUT thresholds
de47884b9759d9 Keerthy 2022-04-12  549  	 * Step 1: set the thresholds to ~123C and 105C WKUP_VTM_MISC_CTRL2
de47884b9759d9 Keerthy 2022-04-12  550  	 * Step 2: WKUP_VTM_TMPSENS_CTRL_j set the MAXT_OUTRG_EN  bit
de47884b9759d9 Keerthy 2022-04-12  551  	 *         This is already taken care as per of init
de47884b9759d9 Keerthy 2022-04-12  552  	 * Step 3: WKUP_VTM_MISC_CTRL set the ANYMAXT_OUTRG_ALERT_EN  bit
de47884b9759d9 Keerthy 2022-04-12  553  	 */
de47884b9759d9 Keerthy 2022-04-12  554  	high_max = k3_j72xx_bandgap_temp_to_adc_code(MAX_TEMP);
de47884b9759d9 Keerthy 2022-04-12  555  	low_temp = k3_j72xx_bandgap_temp_to_adc_code(COOL_DOWN_TEMP);
de47884b9759d9 Keerthy 2022-04-12  556  
de47884b9759d9 Keerthy 2022-04-12  557  	writel((low_temp << 16) | high_max, data[0].bgp->cfg2_base +
de47884b9759d9 Keerthy 2022-04-12  558  	       K3_VTM_MISC_CTRL2_OFFSET);
de47884b9759d9 Keerthy 2022-04-12  559  	mdelay(100);
de47884b9759d9 Keerthy 2022-04-12  560  	writel(K3_VTM_ANYMAXT_OUTRG_ALERT_EN, data[0].bgp->cfg2_base +
de47884b9759d9 Keerthy 2022-04-12  561  	       K3_VTM_MISC_CTRL_OFFSET);
de47884b9759d9 Keerthy 2022-04-12  562  
de47884b9759d9 Keerthy 2022-04-12  563  	platform_set_drvdata(pdev, bgp);
de47884b9759d9 Keerthy 2022-04-12  564  
de47884b9759d9 Keerthy 2022-04-12  565  	print_look_up_table(dev, ref_table);
de47884b9759d9 Keerthy 2022-04-12  566  	/*
de47884b9759d9 Keerthy 2022-04-12  567  	 * Now that the derived_table has the appropriate look up values
de47884b9759d9 Keerthy 2022-04-12  568  	 * Free up the ref_table
de47884b9759d9 Keerthy 2022-04-12  569  	 */
de47884b9759d9 Keerthy 2022-04-12 @570  	kfree(ref_table);

The first free of a double free.  Get rid of the devm_ and add kfrees
on the error path.

de47884b9759d9 Keerthy 2022-04-12  571  
de47884b9759d9 Keerthy 2022-04-12  572  	return 0;
de47884b9759d9 Keerthy 2022-04-12  573  
de47884b9759d9 Keerthy 2022-04-12  574  err_alloc:
de47884b9759d9 Keerthy 2022-04-12  575  	pm_runtime_put_sync(&pdev->dev);
de47884b9759d9 Keerthy 2022-04-12  576  	pm_runtime_disable(&pdev->dev);
de47884b9759d9 Keerthy 2022-04-12  577  
de47884b9759d9 Keerthy 2022-04-12  578  	return ret;
de47884b9759d9 Keerthy 2022-04-12  579  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


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

* Re: [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support
@ 2022-04-20  7:01 ` Dan Carpenter
  0 siblings, 0 replies; 20+ messages in thread
From: Dan Carpenter @ 2022-04-20  7:01 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 12662 bytes --]

Hi Keerthy,

url:    https://github.com/intel-lab-lkp/linux/commits/Keerthy/thermal-k3_j72xx_bandgap-Add-the-bandgap-driver-support/20220412-193526
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: arc-randconfig-m031-20220411 (https://download.01.org/0day-ci/archive/20220415/202204151117.NLsoANXl-lkp(a)intel.com/config)
compiler: arc-elf-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/thermal/k3_j72xx_bandgap.c:570 k3_j72xx_bandgap_probe() warn: passing devm_ allocated variable to kfree. 'ref_table'

vim +/ref_table +570 drivers/thermal/k3_j72xx_bandgap.c

de47884b9759d9 Keerthy 2022-04-12  411  static int k3_j72xx_bandgap_probe(struct platform_device *pdev)
de47884b9759d9 Keerthy 2022-04-12  412  {
de47884b9759d9 Keerthy 2022-04-12  413  	int ret = 0, cnt, val, id, table_size = 1024;
de47884b9759d9 Keerthy 2022-04-12  414  	int high_max, low_temp;
de47884b9759d9 Keerthy 2022-04-12  415  	struct resource *res;
de47884b9759d9 Keerthy 2022-04-12  416  	struct device *dev = &pdev->dev;
de47884b9759d9 Keerthy 2022-04-12  417  	struct k3_j72xx_bandgap *bgp;
de47884b9759d9 Keerthy 2022-04-12  418  	struct k3_thermal_data *data;
de47884b9759d9 Keerthy 2022-04-12  419  	int workaround_needed = 0;
de47884b9759d9 Keerthy 2022-04-12  420  	const struct k3_j72xx_bandgap_data *driver_data;
de47884b9759d9 Keerthy 2022-04-12  421  	struct thermal_zone_device *ti_thermal;
de47884b9759d9 Keerthy 2022-04-12  422  	int *ref_table;
de47884b9759d9 Keerthy 2022-04-12  423  	struct err_values err_vals;
de47884b9759d9 Keerthy 2022-04-12  424  
de47884b9759d9 Keerthy 2022-04-12  425  	s64 golden_factors[] = {
de47884b9759d9 Keerthy 2022-04-12  426  		-490019999999999936,
de47884b9759d9 Keerthy 2022-04-12  427  		3251200000000000,
de47884b9759d9 Keerthy 2022-04-12  428  		-1705800000000,
de47884b9759d9 Keerthy 2022-04-12  429  		603730000,
de47884b9759d9 Keerthy 2022-04-12  430  		-92627,
de47884b9759d9 Keerthy 2022-04-12  431  	};
de47884b9759d9 Keerthy 2022-04-12  432  
de47884b9759d9 Keerthy 2022-04-12  433  	s64 pvt_wa_factors[] = {
de47884b9759d9 Keerthy 2022-04-12  434  		-415230000000000000,
de47884b9759d9 Keerthy 2022-04-12  435  		3126600000000000,
de47884b9759d9 Keerthy 2022-04-12  436  		-1157800000000,
de47884b9759d9 Keerthy 2022-04-12  437  	};
de47884b9759d9 Keerthy 2022-04-12  438  
de47884b9759d9 Keerthy 2022-04-12  439  	bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL);
de47884b9759d9 Keerthy 2022-04-12  440  	if (!bgp)
de47884b9759d9 Keerthy 2022-04-12  441  		return -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  442  
de47884b9759d9 Keerthy 2022-04-12  443  	bgp->dev = dev;
de47884b9759d9 Keerthy 2022-04-12  444  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
de47884b9759d9 Keerthy 2022-04-12  445  	bgp->base = devm_ioremap_resource(dev, res);
de47884b9759d9 Keerthy 2022-04-12  446  	if (IS_ERR(bgp->base))
de47884b9759d9 Keerthy 2022-04-12  447  		return PTR_ERR(bgp->base);
de47884b9759d9 Keerthy 2022-04-12  448  
de47884b9759d9 Keerthy 2022-04-12  449  	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
de47884b9759d9 Keerthy 2022-04-12  450  	bgp->cfg2_base = devm_ioremap_resource(dev, res);
de47884b9759d9 Keerthy 2022-04-12  451  	if (IS_ERR(bgp->cfg2_base))
de47884b9759d9 Keerthy 2022-04-12  452  		return PTR_ERR(bgp->cfg2_base);
de47884b9759d9 Keerthy 2022-04-12  453  
de47884b9759d9 Keerthy 2022-04-12  454  	res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
de47884b9759d9 Keerthy 2022-04-12  455  	bgp->fuse_base = devm_ioremap_resource(dev, res);
de47884b9759d9 Keerthy 2022-04-12  456  	if (IS_ERR(bgp->fuse_base))
de47884b9759d9 Keerthy 2022-04-12  457  		return PTR_ERR(bgp->fuse_base);
de47884b9759d9 Keerthy 2022-04-12  458  
de47884b9759d9 Keerthy 2022-04-12  459  	driver_data = of_device_get_match_data(dev);
de47884b9759d9 Keerthy 2022-04-12  460  	if (driver_data)
de47884b9759d9 Keerthy 2022-04-12  461  		workaround_needed = driver_data->has_errata_i2128;
de47884b9759d9 Keerthy 2022-04-12  462  
de47884b9759d9 Keerthy 2022-04-12  463  	pm_runtime_enable(dev);
de47884b9759d9 Keerthy 2022-04-12  464  	ret = pm_runtime_get_sync(dev);
de47884b9759d9 Keerthy 2022-04-12  465  	if (ret < 0) {
de47884b9759d9 Keerthy 2022-04-12  466  		pm_runtime_put_noidle(dev);
de47884b9759d9 Keerthy 2022-04-12  467  		pm_runtime_disable(dev);
de47884b9759d9 Keerthy 2022-04-12  468  		return ret;
de47884b9759d9 Keerthy 2022-04-12  469  	}
de47884b9759d9 Keerthy 2022-04-12  470  
de47884b9759d9 Keerthy 2022-04-12  471  	/* Get the sensor count in the VTM */
de47884b9759d9 Keerthy 2022-04-12  472  	val = readl(bgp->base + K3_VTM_DEVINFO_PWR0_OFFSET);
de47884b9759d9 Keerthy 2022-04-12  473  	cnt = val & K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK;
de47884b9759d9 Keerthy 2022-04-12  474  	cnt >>= __ffs(K3_VTM_DEVINFO_PWR0_TEMPSENS_CT_MASK);
de47884b9759d9 Keerthy 2022-04-12  475  
de47884b9759d9 Keerthy 2022-04-12  476  	data = devm_kcalloc(bgp->dev, cnt, sizeof(*data), GFP_KERNEL);
de47884b9759d9 Keerthy 2022-04-12  477  	if (!data) {
de47884b9759d9 Keerthy 2022-04-12  478  		ret = -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  479  		goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  480  	}
de47884b9759d9 Keerthy 2022-04-12  481  
de47884b9759d9 Keerthy 2022-04-12  482  	ref_table = devm_kzalloc(bgp->dev, sizeof(*ref_table) * table_size,
de47884b9759d9 Keerthy 2022-04-12  483  				 GFP_KERNEL);

This should be allocated with regular kzalloc() because it's freed at
the end of the function.  It doesn't stay for the life of the device.

de47884b9759d9 Keerthy 2022-04-12  484  	if (!ref_table) {
de47884b9759d9 Keerthy 2022-04-12  485  		ret = -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  486  		goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  487  	}
de47884b9759d9 Keerthy 2022-04-12  488  
de47884b9759d9 Keerthy 2022-04-12  489  	derived_table = devm_kzalloc(bgp->dev, sizeof(*derived_table) * table_size,
de47884b9759d9 Keerthy 2022-04-12  490  				     GFP_KERNEL);
de47884b9759d9 Keerthy 2022-04-12  491  	if (!derived_table) {
de47884b9759d9 Keerthy 2022-04-12  492  		ret = -ENOMEM;
de47884b9759d9 Keerthy 2022-04-12  493  		goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  494  	}
de47884b9759d9 Keerthy 2022-04-12  495  
de47884b9759d9 Keerthy 2022-04-12  496  	/* Workaround not needed if bit30/bit31 is set even for J721e */
de47884b9759d9 Keerthy 2022-04-12  497  	if (workaround_needed && (readl(bgp->fuse_base + 0x0) & 0xc0000000) == 0xc0000000)
de47884b9759d9 Keerthy 2022-04-12  498  		workaround_needed = false;
de47884b9759d9 Keerthy 2022-04-12  499  
de47884b9759d9 Keerthy 2022-04-12  500  	dev_dbg(bgp->dev, "Work around %sneeded\n",
de47884b9759d9 Keerthy 2022-04-12  501  		workaround_needed ? "not " : "");
de47884b9759d9 Keerthy 2022-04-12  502  
de47884b9759d9 Keerthy 2022-04-12  503  	if (!workaround_needed)
de47884b9759d9 Keerthy 2022-04-12  504  		init_table(5, ref_table, golden_factors);
de47884b9759d9 Keerthy 2022-04-12  505  	else
de47884b9759d9 Keerthy 2022-04-12  506  		init_table(3, ref_table, pvt_wa_factors);
de47884b9759d9 Keerthy 2022-04-12  507  
de47884b9759d9 Keerthy 2022-04-12  508  	/* Register the thermal sensors */
de47884b9759d9 Keerthy 2022-04-12  509  	for (id = 0; id < cnt; id++) {
de47884b9759d9 Keerthy 2022-04-12  510  		data[id].bgp = bgp;
de47884b9759d9 Keerthy 2022-04-12  511  		data[id].ctrl_offset = K3_VTM_TMPSENS0_CTRL_OFFSET + id * 0x20;
de47884b9759d9 Keerthy 2022-04-12  512  		data[id].stat_offset = data[id].ctrl_offset +
de47884b9759d9 Keerthy 2022-04-12  513  					K3_VTM_TMPSENS_STAT_OFFSET;
de47884b9759d9 Keerthy 2022-04-12  514  
de47884b9759d9 Keerthy 2022-04-12  515  		if (workaround_needed) {
de47884b9759d9 Keerthy 2022-04-12  516  			/* ref adc values for -40C, 30C & 125C respectively */
de47884b9759d9 Keerthy 2022-04-12  517  			err_vals.refs[0] = MINUS40CREF;
de47884b9759d9 Keerthy 2022-04-12  518  			err_vals.refs[1] = PLUS30CREF;
de47884b9759d9 Keerthy 2022-04-12  519  			err_vals.refs[2] = PLUS125CREF;
de47884b9759d9 Keerthy 2022-04-12  520  			err_vals.refs[3] = PLUS150CREF;
de47884b9759d9 Keerthy 2022-04-12  521  			get_efuse_values(id, &data[id], err_vals.errs, bgp);
de47884b9759d9 Keerthy 2022-04-12  522  		}
de47884b9759d9 Keerthy 2022-04-12  523  
de47884b9759d9 Keerthy 2022-04-12  524  		if (id == 0 && workaround_needed)
de47884b9759d9 Keerthy 2022-04-12  525  			prep_lookup_table(&err_vals, ref_table);
de47884b9759d9 Keerthy 2022-04-12  526  		else if (id == 0 && !workaround_needed)
de47884b9759d9 Keerthy 2022-04-12  527  			memcpy(derived_table, ref_table, table_size * 4);
de47884b9759d9 Keerthy 2022-04-12  528  
de47884b9759d9 Keerthy 2022-04-12  529  		val = readl(data[id].bgp->cfg2_base + data[id].ctrl_offset);
de47884b9759d9 Keerthy 2022-04-12  530  		val |= (K3_VTM_TMPSENS_CTRL_MAXT_OUTRG_EN |
de47884b9759d9 Keerthy 2022-04-12  531  			K3_VTM_TMPSENS_CTRL_SOC |
de47884b9759d9 Keerthy 2022-04-12  532  			K3_VTM_TMPSENS_CTRL_CLRZ | BIT(4));
de47884b9759d9 Keerthy 2022-04-12  533  		writel(val, data[id].bgp->cfg2_base + data[id].ctrl_offset);
de47884b9759d9 Keerthy 2022-04-12  534  
de47884b9759d9 Keerthy 2022-04-12  535  		bgp->ts_data[id] = &data[id];
de47884b9759d9 Keerthy 2022-04-12  536  		ti_thermal =
de47884b9759d9 Keerthy 2022-04-12  537  		devm_thermal_zone_of_sensor_register(bgp->dev, id,
de47884b9759d9 Keerthy 2022-04-12  538  						     &data[id],
de47884b9759d9 Keerthy 2022-04-12  539  						     &k3_of_thermal_ops);
de47884b9759d9 Keerthy 2022-04-12  540  		if (IS_ERR(ti_thermal)) {
de47884b9759d9 Keerthy 2022-04-12  541  			dev_err(bgp->dev, "thermal zone device is NULL\n");
de47884b9759d9 Keerthy 2022-04-12  542  			ret = PTR_ERR(ti_thermal);
de47884b9759d9 Keerthy 2022-04-12  543  			goto err_alloc;
de47884b9759d9 Keerthy 2022-04-12  544  		}
de47884b9759d9 Keerthy 2022-04-12  545  	}
de47884b9759d9 Keerthy 2022-04-12  546  
de47884b9759d9 Keerthy 2022-04-12  547  	/*
de47884b9759d9 Keerthy 2022-04-12  548  	 * Program TSHUT thresholds
de47884b9759d9 Keerthy 2022-04-12  549  	 * Step 1: set the thresholds to ~123C and 105C WKUP_VTM_MISC_CTRL2
de47884b9759d9 Keerthy 2022-04-12  550  	 * Step 2: WKUP_VTM_TMPSENS_CTRL_j set the MAXT_OUTRG_EN  bit
de47884b9759d9 Keerthy 2022-04-12  551  	 *         This is already taken care as per of init
de47884b9759d9 Keerthy 2022-04-12  552  	 * Step 3: WKUP_VTM_MISC_CTRL set the ANYMAXT_OUTRG_ALERT_EN  bit
de47884b9759d9 Keerthy 2022-04-12  553  	 */
de47884b9759d9 Keerthy 2022-04-12  554  	high_max = k3_j72xx_bandgap_temp_to_adc_code(MAX_TEMP);
de47884b9759d9 Keerthy 2022-04-12  555  	low_temp = k3_j72xx_bandgap_temp_to_adc_code(COOL_DOWN_TEMP);
de47884b9759d9 Keerthy 2022-04-12  556  
de47884b9759d9 Keerthy 2022-04-12  557  	writel((low_temp << 16) | high_max, data[0].bgp->cfg2_base +
de47884b9759d9 Keerthy 2022-04-12  558  	       K3_VTM_MISC_CTRL2_OFFSET);
de47884b9759d9 Keerthy 2022-04-12  559  	mdelay(100);
de47884b9759d9 Keerthy 2022-04-12  560  	writel(K3_VTM_ANYMAXT_OUTRG_ALERT_EN, data[0].bgp->cfg2_base +
de47884b9759d9 Keerthy 2022-04-12  561  	       K3_VTM_MISC_CTRL_OFFSET);
de47884b9759d9 Keerthy 2022-04-12  562  
de47884b9759d9 Keerthy 2022-04-12  563  	platform_set_drvdata(pdev, bgp);
de47884b9759d9 Keerthy 2022-04-12  564  
de47884b9759d9 Keerthy 2022-04-12  565  	print_look_up_table(dev, ref_table);
de47884b9759d9 Keerthy 2022-04-12  566  	/*
de47884b9759d9 Keerthy 2022-04-12  567  	 * Now that the derived_table has the appropriate look up values
de47884b9759d9 Keerthy 2022-04-12  568  	 * Free up the ref_table
de47884b9759d9 Keerthy 2022-04-12  569  	 */
de47884b9759d9 Keerthy 2022-04-12 @570  	kfree(ref_table);

The first free of a double free.  Get rid of the devm_ and add kfrees
on the error path.

de47884b9759d9 Keerthy 2022-04-12  571  
de47884b9759d9 Keerthy 2022-04-12  572  	return 0;
de47884b9759d9 Keerthy 2022-04-12  573  
de47884b9759d9 Keerthy 2022-04-12  574  err_alloc:
de47884b9759d9 Keerthy 2022-04-12  575  	pm_runtime_put_sync(&pdev->dev);
de47884b9759d9 Keerthy 2022-04-12  576  	pm_runtime_disable(&pdev->dev);
de47884b9759d9 Keerthy 2022-04-12  577  
de47884b9759d9 Keerthy 2022-04-12  578  	return ret;
de47884b9759d9 Keerthy 2022-04-12  579  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

end of thread, other threads:[~2022-04-20  7:02 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 10:14 [PATCH v5 0/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
2022-04-12 10:14 ` [PATCH v5 1/4] dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation Keerthy
2022-04-13  8:07   ` Daniel Lezcano
2022-04-13 10:13   ` Krzysztof Kozlowski
2022-04-13 12:04     ` J, KEERTHY
2022-04-13 12:25       ` Krzysztof Kozlowski
2022-04-14 15:57       ` Rob Herring
2022-04-12 10:14 ` [PATCH v5 2/4] arm64: dts: ti: j721e: Add VTM node Keerthy
2022-04-12 17:09   ` Vignesh Raghavendra
2022-04-12 23:43     ` J, KEERTHY
2022-04-13 10:14   ` Krzysztof Kozlowski
2022-04-12 10:14 ` [PATCH v5 3/4] arm64: dts: ti: j7200: " Keerthy
2022-04-13 10:14   ` Krzysztof Kozlowski
2022-04-12 10:14 ` [PATCH v5 4/4] thermal: k3_j72xx_bandgap: Add the bandgap driver support Keerthy
2022-04-12 17:00   ` kernel test robot
2022-04-13 10:17   ` Krzysztof Kozlowski
2022-04-19 17:23   ` Daniel Lezcano
2022-04-15  3:58 kernel test robot
2022-04-20  7:01 ` Dan Carpenter
2022-04-20  7:01 ` Dan Carpenter

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.