public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] xilinx: Add support for Xilinx Sysmon IP
@ 2025-09-05  8:41 Michal Simek
  2025-09-05  8:41 ` [PATCH 4/6] dt-bindings: thermal: versal: Add description for Versal Thermal Michal Simek
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Michal Simek @ 2025-09-05  8:41 UTC (permalink / raw)
  To: linux-kernel, monstr, michal.simek, git
  Cc: Andy Shevchenko, Conor Dooley, Daniel Lezcano, David Lechner,
	Jonathan Cameron, Krzysztof Kozlowski, Lukasz Luba, Nuno Sá,
	Rafael J. Wysocki, Rob Herring, Salih Erim, Zhang Rui,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	open list:IIO SUBSYSTEM AND DRIVERS, open list:THERMAL

Hi,

the series is adding support for Xilinx Sysmon IP available on Versal SOCs.
The series also contains thermal driver which is using Sysmon for providing
temperature information.
As the part of it is also monitoring AI engine.

Thanks,
Michal


Anish Kadamathikuttiyil Karthikeyan Pillai (2):
  iio: adc: versal-sysmon: Support AI Engine thermal monitoring
  thermal: versal-thermal: Support thermal management in AI Engine

Salih Erim (4):
  dt-bindings: iio: xilinx: Add Documentation for Sysmon
  iio: versal-sysmon: add driver for Versal Sysmon
  dt-bindings: thermal: versal: Add description for Versal Thermal
  thermal: versal-thermal: Add Versal thermal driver

 .../bindings/iio/adc/xlnx,versal-sysmon.yaml  |  235 +++
 .../bindings/thermal/xlnx,versal-thermal.yaml |   45 +
 MAINTAINERS                                   |   13 +
 drivers/iio/adc/Kconfig                       |   15 +
 drivers/iio/adc/Makefile                      |    2 +
 drivers/iio/adc/versal-sysmon-core.c          | 1379 +++++++++++++++++
 drivers/iio/adc/versal-sysmon.c               |  297 ++++
 drivers/iio/adc/versal-sysmon.h               |  278 ++++
 drivers/thermal/Kconfig                       |   12 +
 drivers/thermal/Makefile                      |    1 +
 drivers/thermal/versal_thermal.c              |  221 +++
 include/linux/iio/adc/versal-sysmon-events.h  |   56 +
 12 files changed, 2554 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml
 create mode 100644 Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
 create mode 100644 drivers/iio/adc/versal-sysmon-core.c
 create mode 100644 drivers/iio/adc/versal-sysmon.c
 create mode 100644 drivers/iio/adc/versal-sysmon.h
 create mode 100644 drivers/thermal/versal_thermal.c
 create mode 100644 include/linux/iio/adc/versal-sysmon-events.h

-- 
2.43.0


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

* [PATCH 4/6] dt-bindings: thermal: versal: Add description for Versal Thermal
  2025-09-05  8:41 [PATCH 0/6] xilinx: Add support for Xilinx Sysmon IP Michal Simek
@ 2025-09-05  8:41 ` Michal Simek
  2025-09-05 18:30   ` Conor Dooley
  2025-09-05  8:41 ` [PATCH 5/6] thermal: versal-thermal: Add Versal thermal driver Michal Simek
  2025-09-05  8:41 ` [PATCH 6/6] thermal: versal-thermal: Support thermal management in AI Engine Michal Simek
  2 siblings, 1 reply; 7+ messages in thread
From: Michal Simek @ 2025-09-05  8:41 UTC (permalink / raw)
  To: linux-kernel, monstr, michal.simek, git
  Cc: Salih Erim, Anish Kadamathikuttiyil Karthikeyan Pillai,
	Conor Dooley, Daniel Lezcano, Krzysztof Kozlowski, Lukasz Luba,
	Rafael J. Wysocki, Rob Herring, Zhang Rui,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	open list:THERMAL

From: Salih Erim <salih.erim@amd.com>

Add description of Versal Thermal which describes IO channels to
be binded to thermal. Constant channel of "sysmon-temp-channel" used as
mapped iio channel.

One temperature zone is used for the AI Engine temperature monitoring.

Signed-off-by: Salih Erim <salih.erim@amd.com>
Co-developed-by: Anish Kadamathikuttiyil Karthikeyan Pillai <anish.kadamathikuttiyil-karthikeyan-pillai@amd.com>
Signed-off-by: Anish Kadamathikuttiyil Karthikeyan Pillai <anish.kadamathikuttiyil-karthikeyan-pillai@amd.com>
Signed-off-by: Michal Simek <michal.simek@amd.com>
---

 .../bindings/thermal/xlnx,versal-thermal.yaml | 45 +++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml

diff --git a/Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml b/Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
new file mode 100644
index 000000000000..c374d7ae2d2a
--- /dev/null
+++ b/Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/thermal/xlnx,versal-thermal.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Xilinx Versal Thermal
+
+maintainers:
+  - Salih Erim <salih.erim@amd.com>
+
+description:
+  Versal Thermal uses Versal Sysmon hardware for temperature reading.
+  It works as sensor interface to be defined in thermal zones.
+
+properties:
+  compatible:
+    const: xlnx,versal-thermal
+
+  '#thermal-sensor-cells':
+    const: 1
+
+  io-channels:
+    maxItems: 1
+
+  io-channel-names:
+    const: sysmon-temp-channel
+
+required:
+  - compatible
+  - '#thermal-sensor-cells'
+  - io-channels
+  - io-channel-names
+
+additionalProperties: false
+
+examples:
+  - |
+    versal-thermal-sensor {
+        compatible = "xlnx,versal-thermal";
+        #thermal-sensor-cells = <1>;
+        io-channels = <&sysmon0>;
+        io-channel-names = "sysmon-temp-channel";
+    };
+...
-- 
2.43.0


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

* [PATCH 5/6] thermal: versal-thermal: Add Versal thermal driver
  2025-09-05  8:41 [PATCH 0/6] xilinx: Add support for Xilinx Sysmon IP Michal Simek
  2025-09-05  8:41 ` [PATCH 4/6] dt-bindings: thermal: versal: Add description for Versal Thermal Michal Simek
@ 2025-09-05  8:41 ` Michal Simek
  2025-09-05  8:41 ` [PATCH 6/6] thermal: versal-thermal: Support thermal management in AI Engine Michal Simek
  2 siblings, 0 replies; 7+ messages in thread
From: Michal Simek @ 2025-09-05  8:41 UTC (permalink / raw)
  To: linux-kernel, monstr, michal.simek, git
  Cc: Salih Erim, Daniel Lezcano, Lukasz Luba, Rafael J. Wysocki,
	Zhang Rui, open list:THERMAL

From: Salih Erim <salih.erim@amd.com>

This patch adds the Versal thermal driver based
on Versal Sysmon as thermal infrastructure sensor.

Sysmon devices use IIO framework to expose temperature
information to system.
This driver connects to the sysmon temp channel by iio
binding mapping defined on the sysmon driver.

This is initial work for defining thermal sensor driver and
thermal infrastructure for Versal devices. Single thermal zone
has to be defined and no cooling devices and maps are supported
at this point.

Sysmon devices default temperature event thresholds can be used as
temperature ranges.

Updates the maintainer file accordingly to this driver.

Signed-off-by: Salih Erim <salih.erim@amd.com>
Signed-off-by: Michal Simek <michal.simek@amd.com>
---

 MAINTAINERS                      |  6 +++
 drivers/thermal/Kconfig          | 12 +++++
 drivers/thermal/Makefile         |  1 +
 drivers/thermal/versal_thermal.c | 87 ++++++++++++++++++++++++++++++++
 4 files changed, 106 insertions(+)
 create mode 100644 drivers/thermal/versal_thermal.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 1a9c5549d0dc..907a6c193fb7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -27609,6 +27609,12 @@ F:	Documentation/devicetree/bindings/iio/adc/xlnx,versal-sysmon.yaml
 F:	drivers/iio/adc/versal-sysmon*
 F:	include/linux/iio/adc/versal-sysmon-events.h
 
+XILINX VERSAL THERMAL DRIVER
+M:	Salih Erim <salih.erim@amd.com>
+S:	Maintained
+F:	Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
+F:	drivers/thermal/versal_thermal.c
+
 XILINX UARTLITE SERIAL DRIVER
 M:	Peter Korsgaard <jacmet@sunsite.dk>
 L:	linux-serial@vger.kernel.org
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index a09c188b9ad1..9695ecec8f04 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -517,4 +517,16 @@ config LOONGSON2_THERMAL
 	  is higher than the high temperature threshold or lower than the low
 	  temperature threshold, the interrupt will occur.
 
+config VERSAL_THERMAL
+	tristate "Versal thermal sensor driver"
+	depends on OF
+	depends on VERSAL_SYSMON
+	help
+	  This adds support for Versal thermal driver as thermal zone sensor
+	  The thermal driver is connected to Versal Sysmon for the temperature
+	  channel via iio binding. The Sysmon channel is read via IIO framework
+	  and the channel information is provided to driver.
+	  The driver can also be build as a module. If so, the module will be called
+	  versal_thermal
+
 endif
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index d7718978db24..407c84aa2691 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -68,3 +68,4 @@ obj-$(CONFIG_SPRD_THERMAL)	+= sprd_thermal.o
 obj-$(CONFIG_KHADAS_MCU_FAN_THERMAL)	+= khadas_mcu_fan.o
 obj-$(CONFIG_LOONGSON2_THERMAL)	+= loongson2_thermal.o
 obj-$(CONFIG_THERMAL_CORE_TESTING)	+= testing/
+obj-$(CONFIG_VERSAL_THERMAL)	+= versal_thermal.o
diff --git a/drivers/thermal/versal_thermal.c b/drivers/thermal/versal_thermal.c
new file mode 100644
index 000000000000..51c8586af5a4
--- /dev/null
+++ b/drivers/thermal/versal_thermal.c
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD Versal Thermal Driver for Versal Devices
+ *
+ * Copyright (C) 2024 - 2025 Advanced Micro Devices, Inc.
+ */
+
+#include <linux/iio/consumer.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#include "thermal_hwmon.h"
+
+#define SYSMON_TEMP_CH_NAME "sysmon-temp-channel"
+#define SYSMON_FRACTIONAL_DENOM		128
+
+struct versal_thermal_info {
+	struct device *dev;
+	struct thermal_zone_device *tzd;
+	struct iio_channel *channel;
+};
+
+static int temperature_sensor_get_temp(struct thermal_zone_device *tz, int *temp)
+{
+	struct versal_thermal_info *vti = thermal_zone_device_priv(tz);
+	int ret, val;
+
+	ret = iio_read_channel_processed(vti->channel, &val);
+	if (ret == IIO_VAL_FRACTIONAL) {
+		/* Convert raw value to temperature in millidegrees Celsius */
+		*temp = val * 1000;
+		*temp /= SYSMON_FRACTIONAL_DENOM;
+	} else if (ret == IIO_VAL_INT) {
+		*temp = val;
+	} else {
+		dev_err(vti->dev, "iio_read_channel_processed failed, ret code = %d\n", ret);
+		return ret;
+	}
+	return 0;
+}
+
+static const struct thermal_zone_device_ops thermal_zone_ops = {
+	.get_temp = temperature_sensor_get_temp,
+};
+
+static int versal_thermal_probe(struct platform_device *pdev)
+{
+	struct versal_thermal_info *vti;
+
+	vti = devm_kzalloc(&pdev->dev, sizeof(struct versal_thermal_info), GFP_KERNEL);
+	if (!vti)
+		return -ENOMEM;
+
+	vti->channel = devm_iio_channel_get(&pdev->dev, SYSMON_TEMP_CH_NAME);
+	if (IS_ERR(vti->channel))
+		return dev_err_probe(&pdev->dev, PTR_ERR(vti->channel),
+				     "IIO channel not found\n");
+
+	vti->dev = &pdev->dev;
+
+	vti->tzd = devm_thermal_of_zone_register(&pdev->dev, 0, vti, &thermal_zone_ops);
+	if (IS_ERR(vti->tzd))
+		return dev_err_probe(&pdev->dev, PTR_ERR(vti->tzd),
+				     "Thermal zone sensor register failed\n");
+
+	return devm_thermal_add_hwmon_sysfs(&pdev->dev, vti->tzd);
+}
+
+static const struct of_device_id versal_thermal_of_match[] = {
+	{ .compatible = "xlnx,versal-thermal", },
+	{ /* end of list */ },
+};
+MODULE_DEVICE_TABLE(of, versal_thermal_of_match);
+
+static struct platform_driver versal_thermal_driver = {
+	.driver = {
+		.name = "versal-thermal",
+		.of_match_table = versal_thermal_of_match,
+	},
+	.probe = versal_thermal_probe,
+};
+
+module_platform_driver(versal_thermal_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("XILINX Versal Thermal Driver");
+MODULE_AUTHOR("Advanced Micro Devices, Inc");
-- 
2.43.0


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

* [PATCH 6/6] thermal: versal-thermal: Support thermal management in AI Engine
  2025-09-05  8:41 [PATCH 0/6] xilinx: Add support for Xilinx Sysmon IP Michal Simek
  2025-09-05  8:41 ` [PATCH 4/6] dt-bindings: thermal: versal: Add description for Versal Thermal Michal Simek
  2025-09-05  8:41 ` [PATCH 5/6] thermal: versal-thermal: Add Versal thermal driver Michal Simek
@ 2025-09-05  8:41 ` Michal Simek
  2025-09-05 10:48   ` Krzysztof Kozlowski
  2 siblings, 1 reply; 7+ messages in thread
From: Michal Simek @ 2025-09-05  8:41 UTC (permalink / raw)
  To: linux-kernel, monstr, michal.simek, git
  Cc: Anish Kadamathikuttiyil Karthikeyan Pillai, Daniel Lezcano,
	Lukasz Luba, Rafael J. Wysocki, Salih Erim, Zhang Rui,
	open list:THERMAL

From: Anish Kadamathikuttiyil Karthikeyan Pillai <anish.kadamathikuttiyil-karthikeyan-pillai@amd.com>

For AI Engine thermal monitoring, through the thermal framework,
a new temperature zone is added. The temperature of versal sysmon
satellites near to AI Engine is read from the mapped IIO channels.
The maximum value of temperature from versal sysmon satellites
near AI Engine will be reported.

In versal thermal driver iio channel names are read from versal
sysmon temp child node. The reason is we cannot specify the
iio-channel-names in versal thermal sensor node, as it can change from
board to board and versal_thermal node which is not related
to any hardware.

Passing NULL is not be supported by devm_ API for getting IIO
channel names. So we moved from this approach to iio_channel_get approach.

Signed-off-by: Anish Kadamathikuttiyil Karthikeyan Pillai <anish.kadamathikuttiyil-karthikeyan-pillai@amd.com>
Signed-off-by: Michal Simek <michal.simek@amd.com>
---

 drivers/thermal/versal_thermal.c | 146 +++++++++++++++++++++++++++++--
 1 file changed, 140 insertions(+), 6 deletions(-)

diff --git a/drivers/thermal/versal_thermal.c b/drivers/thermal/versal_thermal.c
index 51c8586af5a4..e2e201c5c955 100644
--- a/drivers/thermal/versal_thermal.c
+++ b/drivers/thermal/versal_thermal.c
@@ -13,11 +13,17 @@
 
 #define SYSMON_TEMP_CH_NAME "sysmon-temp-channel"
 #define SYSMON_FRACTIONAL_DENOM		128
+#define SYSMON_STATIC_IIO_CH_COUNT	1
+#define SYSMON_AIE_TEMP_CH		200
+#define TEMP_MAX			160
 
 struct versal_thermal_info {
 	struct device *dev;
 	struct thermal_zone_device *tzd;
+	struct thermal_zone_device *tzd_aie;
 	struct iio_channel *channel;
+	struct iio_channel **channel_aie;
+	u32 num_aie_channels;
 };
 
 static int temperature_sensor_get_temp(struct thermal_zone_device *tz, int *temp)
@@ -39,31 +45,158 @@ static int temperature_sensor_get_temp(struct thermal_zone_device *tz, int *temp
 	return 0;
 }
 
+static int temperature_sensor_get_temp_aie(struct thermal_zone_device *tz,
+					   int *temp)
+{
+	struct versal_thermal_info *vti = thermal_zone_device_priv(tz);
+	int ret, val;
+	int max_temp = INT_MIN;
+	u32 aie_ch_index;
+
+	for (aie_ch_index = 0; aie_ch_index < vti->num_aie_channels;
+		 aie_ch_index++) {
+		ret = iio_read_channel_processed(vti->channel_aie[aie_ch_index], &val);
+		if (ret == IIO_VAL_FRACTIONAL) {
+			/* Convert raw value to temperature in millidegrees Celsius */
+			*temp = val * 1000;
+			*temp /= SYSMON_FRACTIONAL_DENOM;
+		} else if (ret == IIO_VAL_INT) {
+			*temp = val;
+		} else {
+			dev_err(vti->dev, "iio_read_channel_processed failed aie ch%d, ret = %d\n",
+				aie_ch_index, ret);
+			return ret;
+		}
+		if (*temp > max_temp)
+			max_temp = *temp;
+	}
+	*temp = max_temp;
+	return 0;
+}
+
 static const struct thermal_zone_device_ops thermal_zone_ops = {
 	.get_temp = temperature_sensor_get_temp,
 };
 
+static const struct thermal_zone_device_ops thermal_zone_ops_aie = {
+	.get_temp = temperature_sensor_get_temp_aie,
+};
+
+static void versal_thermal_iio_chan_release(struct versal_thermal_info *vti)
+{
+	int aie_ch_index;
+
+	if (!IS_ERR_OR_NULL(vti->channel))
+		iio_channel_release(vti->channel);
+	for (aie_ch_index = 0; aie_ch_index < vti->num_aie_channels; aie_ch_index++)
+		if (!IS_ERR_OR_NULL(vti->channel_aie[aie_ch_index]))
+			iio_channel_release(vti->channel_aie[aie_ch_index]);
+}
+
 static int versal_thermal_probe(struct platform_device *pdev)
 {
 	struct versal_thermal_info *vti;
+	struct device_node *sysmon_node;
+	struct device_node *child_node = NULL;
+	int aie_ch_index = 0;
+	int ret = 0;
+	u32 num_aie_channels = 0;
+	const char **aie_temp_chan_names;
+	const char *aie_temp_chan_name;
 
 	vti = devm_kzalloc(&pdev->dev, sizeof(struct versal_thermal_info), GFP_KERNEL);
 	if (!vti)
 		return -ENOMEM;
 
-	vti->channel = devm_iio_channel_get(&pdev->dev, SYSMON_TEMP_CH_NAME);
-	if (IS_ERR(vti->channel))
-		return dev_err_probe(&pdev->dev, PTR_ERR(vti->channel),
-				     "IIO channel not found\n");
-
 	vti->dev = &pdev->dev;
 
+	vti->channel = iio_channel_get(NULL, SYSMON_TEMP_CH_NAME);
+	if (IS_ERR(vti->channel)) {
+		vti->num_aie_channels = 0;
+		versal_thermal_iio_chan_release(vti);
+		return dev_err_probe(&pdev->dev, PTR_ERR(vti->channel),
+							"IIO channel %s not found\n",
+							SYSMON_TEMP_CH_NAME);
+	}
+
 	vti->tzd = devm_thermal_of_zone_register(&pdev->dev, 0, vti, &thermal_zone_ops);
 	if (IS_ERR(vti->tzd))
 		return dev_err_probe(&pdev->dev, PTR_ERR(vti->tzd),
 				     "Thermal zone sensor register failed\n");
 
-	return devm_thermal_add_hwmon_sysfs(&pdev->dev, vti->tzd);
+	ret = devm_thermal_add_hwmon_sysfs(&pdev->dev, vti->tzd);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to add hwmon sysfs for sysmon temp\n");
+
+	sysmon_node = of_find_node_by_name(NULL, "sysmon");
+	if (sysmon_node) {
+		ret = of_property_read_u32(sysmon_node, "xlnx,numaiechannels",
+					   &num_aie_channels);
+		if (ret < 0)
+			num_aie_channels = 0;
+	}
+
+	if (num_aie_channels > 0) {
+		aie_temp_chan_names = devm_kcalloc(&pdev->dev, num_aie_channels,
+						   sizeof(*aie_temp_chan_names),
+						   GFP_KERNEL);
+		if (!aie_temp_chan_names)
+			return -ENOMEM;
+
+		for_each_child_of_node(sysmon_node, child_node) {
+			if (of_property_present(child_node, "xlnx,aie-temp")) {
+				ret = of_property_read_string(child_node, "xlnx,name",
+							      &aie_temp_chan_name);
+				if (ret < 0) {
+					of_node_put(child_node);
+					return ret;
+				}
+				aie_temp_chan_names[aie_ch_index] = aie_temp_chan_name;
+				aie_ch_index++;
+			}
+		}
+
+		/* Allocate memory for the dynamic aie temperature channels */
+		vti->channel_aie = devm_kcalloc(&pdev->dev, num_aie_channels,
+						sizeof(*vti->channel_aie), GFP_KERNEL);
+		if (!vti->channel_aie)
+			return -ENOMEM;
+
+		for (aie_ch_index = 0; aie_ch_index < num_aie_channels; aie_ch_index++) {
+			vti->channel_aie[aie_ch_index] =
+			    iio_channel_get(NULL, aie_temp_chan_names[aie_ch_index]);
+			if (IS_ERR(vti->channel_aie[aie_ch_index])) {
+				vti->num_aie_channels = aie_ch_index + 1;
+				versal_thermal_iio_chan_release(vti);
+				return dev_err_probe(&pdev->dev,
+						     PTR_ERR(vti->channel_aie[aie_ch_index]),
+						     "IIO AIE TEMP channel %s not found\n",
+						     aie_temp_chan_names[aie_ch_index]);
+			}
+		}
+
+		vti->tzd_aie = devm_thermal_of_zone_register(&pdev->dev, 1, vti,
+							     &thermal_zone_ops_aie);
+		if (IS_ERR(vti->tzd_aie))
+			return dev_err_probe(&pdev->dev, PTR_ERR(vti->tzd_aie),
+					      "Failed to register thermal zone aie temp\n");
+
+		ret = devm_thermal_add_hwmon_sysfs(&pdev->dev, vti->tzd_aie);
+		if (ret)
+			return dev_err_probe(&pdev->dev, ret,
+					     "Failed to add hwmon sysfs for aie temp\n");
+	}
+	vti->num_aie_channels = num_aie_channels;
+	platform_set_drvdata(pdev, vti);
+	return 0;
+}
+
+static void versal_thermal_remove(struct platform_device *pdev)
+{
+	struct versal_thermal_info *vti = platform_get_drvdata(pdev);
+
+	versal_thermal_iio_chan_release(vti);
 }
 
 static const struct of_device_id versal_thermal_of_match[] = {
@@ -78,6 +211,7 @@ static struct platform_driver versal_thermal_driver = {
 		.of_match_table = versal_thermal_of_match,
 	},
 	.probe = versal_thermal_probe,
+	.remove = versal_thermal_remove,
 };
 
 module_platform_driver(versal_thermal_driver);
-- 
2.43.0


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

* Re: [PATCH 6/6] thermal: versal-thermal: Support thermal management in AI Engine
  2025-09-05  8:41 ` [PATCH 6/6] thermal: versal-thermal: Support thermal management in AI Engine Michal Simek
@ 2025-09-05 10:48   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2025-09-05 10:48 UTC (permalink / raw)
  To: Michal Simek, linux-kernel, monstr, michal.simek, git
  Cc: Anish Kadamathikuttiyil Karthikeyan Pillai, Daniel Lezcano,
	Lukasz Luba, Rafael J. Wysocki, Salih Erim, Zhang Rui,
	open list:THERMAL

On 05/09/2025 10:41, Michal Simek wrote:
> +	vti->channel = iio_channel_get(NULL, SYSMON_TEMP_CH_NAME);
> +	if (IS_ERR(vti->channel)) {
> +		vti->num_aie_channels = 0;
> +		versal_thermal_iio_chan_release(vti);
> +		return dev_err_probe(&pdev->dev, PTR_ERR(vti->channel),
> +							"IIO channel %s not found\n",
> +							SYSMON_TEMP_CH_NAME);
> +	}
> +
>  	vti->tzd = devm_thermal_of_zone_register(&pdev->dev, 0, vti, &thermal_zone_ops);
>  	if (IS_ERR(vti->tzd))
>  		return dev_err_probe(&pdev->dev, PTR_ERR(vti->tzd),
>  				     "Thermal zone sensor register failed\n");
>  
> -	return devm_thermal_add_hwmon_sysfs(&pdev->dev, vti->tzd);
> +	ret = devm_thermal_add_hwmon_sysfs(&pdev->dev, vti->tzd);
> +	if (ret)
> +		return dev_err_probe(&pdev->dev, ret,
> +				     "Failed to add hwmon sysfs for sysmon temp\n");
> +
> +	sysmon_node = of_find_node_by_name(NULL, "sysmon");

Undocumented ABI. Please don't do that. sysmon is not an approved name
and for sure can be changed anytime to anything.

Phandles express relationships usually.


> +	if (sysmon_node) {
> +		ret = of_property_read_u32(sysmon_node, "xlnx,numaiechannels",
> +					   &num_aie_channels);
> +		if (ret < 0)
> +			num_aie_channels = 0;
> +	}
> +
> +	if (num_aie_channels > 0) {
> +		aie_temp_chan_names = devm_kcalloc(&pdev->dev, num_aie_channels,
> +						   sizeof(*aie_temp_chan_names),
> +						   GFP_KERNEL);
> +		if (!aie_temp_chan_names)
> +			return -ENOMEM;
> +
> +		for_each_child_of_node(sysmon_node, child_node) {
> +			if (of_property_present(child_node, "xlnx,aie-temp")) {
> +				ret = of_property_read_string(child_node, "xlnx,name",
> +							      &aie_temp_chan_name);
> +				if (ret < 0) {
> +					of_node_put(child_node);
> +					return ret;
> +				}
> +				aie_temp_chan_names[aie_ch_index] = aie_temp_chan_name;
> +				aie_ch_index++;
> +			}
> +		}
> +
> +		/* Allocate memory for the dynamic aie temperature channels */
> +		vti->channel_aie = devm_kcalloc(&pdev->dev, num_aie_channels,
> +						sizeof(*vti->channel_aie), GFP_KERNEL);
> +		if (!vti->channel_aie)
> +			return -ENOMEM;
> +
> +		for (aie_ch_index = 0; aie_ch_index < num_aie_channels; aie_ch_index++) {
> +			vti->channel_aie[aie_ch_index] =
> +			    iio_channel_get(NULL, aie_temp_chan_names[aie_ch_index]);
> +			if (IS_ERR(vti->channel_aie[aie_ch_index])) {
> +				vti->num_aie_channels = aie_ch_index + 1;
> +				versal_thermal_iio_chan_release(vti);
> +				return dev_err_probe(&pdev->dev,
> +						     PTR_ERR(vti->channel_aie[aie_ch_index]),
> +						     "IIO AIE TEMP channel %s not found\n",
> +						     aie_temp_chan_names[aie_ch_index]);
> +			}
> +		}
> +
> +		vti->tzd_aie = devm_thermal_of_zone_register(&pdev->dev, 1, vti,
> +							     &thermal_zone_ops_aie);
> +		if (IS_ERR(vti->tzd_aie))
> +			return dev_err_probe(&pdev->dev, PTR_ERR(vti->tzd_aie),
> +					      "Failed to register thermal zone aie temp\n");
> +
> +		ret = devm_thermal_add_hwmon_sysfs(&pdev->dev, vti->tzd_aie);
> +		if (ret)
> +			return dev_err_probe(&pdev->dev, ret,
> +					     "Failed to add hwmon sysfs for aie temp\n");
> +	}
> +	vti->num_aie_channels = num_aie_channels;
> +	platform_set_drvdata(pdev, vti);
> +	return 0;
> +}
> +
> +static void versal_thermal_remove(struct platform_device *pdev)
> +{
> +	struct versal_thermal_info *vti = platform_get_drvdata(pdev);
> +
> +	versal_thermal_iio_chan_release(vti);

Don't mix non-devm with devm. This should be a proper devm cleanup action.



Best regards,
Krzysztof

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

* Re: [PATCH 4/6] dt-bindings: thermal: versal: Add description for Versal Thermal
  2025-09-05  8:41 ` [PATCH 4/6] dt-bindings: thermal: versal: Add description for Versal Thermal Michal Simek
@ 2025-09-05 18:30   ` Conor Dooley
  2025-09-08  6:39     ` Michal Simek
  0 siblings, 1 reply; 7+ messages in thread
From: Conor Dooley @ 2025-09-05 18:30 UTC (permalink / raw)
  To: Michal Simek
  Cc: linux-kernel, monstr, michal.simek, git, Salih Erim,
	Anish Kadamathikuttiyil Karthikeyan Pillai, Conor Dooley,
	Daniel Lezcano, Krzysztof Kozlowski, Lukasz Luba,
	Rafael J. Wysocki, Rob Herring, Zhang Rui,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	open list:THERMAL

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

On Fri, Sep 05, 2025 at 10:41:47AM +0200, Michal Simek wrote:
> From: Salih Erim <salih.erim@amd.com>
> 
> Add description of Versal Thermal which describes IO channels to
> be binded to thermal. Constant channel of "sysmon-temp-channel" used as
> mapped iio channel.
> 
> One temperature zone is used for the AI Engine temperature monitoring.
> 
> Signed-off-by: Salih Erim <salih.erim@amd.com>
> Co-developed-by: Anish Kadamathikuttiyil Karthikeyan Pillai <anish.kadamathikuttiyil-karthikeyan-pillai@amd.com>
> Signed-off-by: Anish Kadamathikuttiyil Karthikeyan Pillai <anish.kadamathikuttiyil-karthikeyan-pillai@amd.com>
> Signed-off-by: Michal Simek <michal.simek@amd.com>
> ---
> 
>  .../bindings/thermal/xlnx,versal-thermal.yaml | 45 +++++++++++++++++++
>  1 file changed, 45 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
> 
> diff --git a/Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml b/Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
> new file mode 100644
> index 000000000000..c374d7ae2d2a
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
> @@ -0,0 +1,45 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/thermal/xlnx,versal-thermal.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Xilinx Versal Thermal
> +
> +maintainers:
> +  - Salih Erim <salih.erim@amd.com>
> +
> +description:
> +  Versal Thermal uses Versal Sysmon hardware for temperature reading.
> +  It works as sensor interface to be defined in thermal zones.
> +
> +properties:
> +  compatible:
> +    const: xlnx,versal-thermal

BTW Michal, what's the story with using amd v xlnx for bindings?
Planning to use amd for new devices and xlnx for stuff sold before the
purchase or something like that?

> +
> +  '#thermal-sensor-cells':
> +    const: 1
> +
> +  io-channels:
> +    maxItems: 1
> +
> +  io-channel-names:
> +    const: sysmon-temp-channel
> +
> +required:
> +  - compatible
> +  - '#thermal-sensor-cells'
> +  - io-channels
> +  - io-channel-names
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    versal-thermal-sensor {

Drop the versal from the node name here please.
With that,
Acked-by: Conor Dooley <conor.dooley@microchip.com>

> +        compatible = "xlnx,versal-thermal";
> +        #thermal-sensor-cells = <1>;
> +        io-channels = <&sysmon0>;
> +        io-channel-names = "sysmon-temp-channel";
> +    };
> +...
> -- 
> 2.43.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH 4/6] dt-bindings: thermal: versal: Add description for Versal Thermal
  2025-09-05 18:30   ` Conor Dooley
@ 2025-09-08  6:39     ` Michal Simek
  0 siblings, 0 replies; 7+ messages in thread
From: Michal Simek @ 2025-09-08  6:39 UTC (permalink / raw)
  To: Conor Dooley
  Cc: linux-kernel, monstr, michal.simek, git, Salih Erim,
	Anish Kadamathikuttiyil Karthikeyan Pillai, Conor Dooley,
	Daniel Lezcano, Krzysztof Kozlowski, Lukasz Luba,
	Rafael J. Wysocki, Rob Herring, Zhang Rui,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	open list:THERMAL



On 9/5/25 20:30, Conor Dooley wrote:
> On Fri, Sep 05, 2025 at 10:41:47AM +0200, Michal Simek wrote:
>> From: Salih Erim <salih.erim@amd.com>
>>
>> Add description of Versal Thermal which describes IO channels to
>> be binded to thermal. Constant channel of "sysmon-temp-channel" used as
>> mapped iio channel.
>>
>> One temperature zone is used for the AI Engine temperature monitoring.
>>
>> Signed-off-by: Salih Erim <salih.erim@amd.com>
>> Co-developed-by: Anish Kadamathikuttiyil Karthikeyan Pillai <anish.kadamathikuttiyil-karthikeyan-pillai@amd.com>
>> Signed-off-by: Anish Kadamathikuttiyil Karthikeyan Pillai <anish.kadamathikuttiyil-karthikeyan-pillai@amd.com>
>> Signed-off-by: Michal Simek <michal.simek@amd.com>
>> ---
>>
>>   .../bindings/thermal/xlnx,versal-thermal.yaml | 45 +++++++++++++++++++
>>   1 file changed, 45 insertions(+)
>>   create mode 100644 Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
>>
>> diff --git a/Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml b/Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
>> new file mode 100644
>> index 000000000000..c374d7ae2d2a
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/thermal/xlnx,versal-thermal.yaml
>> @@ -0,0 +1,45 @@
>> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
>> +%YAML 1.2
>> +---
>> +$id: http://devicetree.org/schemas/thermal/xlnx,versal-thermal.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: Xilinx Versal Thermal
>> +
>> +maintainers:
>> +  - Salih Erim <salih.erim@amd.com>
>> +
>> +description:
>> +  Versal Thermal uses Versal Sysmon hardware for temperature reading.
>> +  It works as sensor interface to be defined in thermal zones.
>> +
>> +properties:
>> +  compatible:
>> +    const: xlnx,versal-thermal
> 
> BTW Michal, what's the story with using amd v xlnx for bindings?
> Planning to use amd for new devices and xlnx for stuff sold before the
> purchase or something like that?

yes exactly that is the plan. Newly developed drivers or SOC will start to use 
amd prefixes instead of xlnx.
This is the IP which is around for a while that's why xlnx is still used.

> 
>> +
>> +  '#thermal-sensor-cells':
>> +    const: 1
>> +
>> +  io-channels:
>> +    maxItems: 1
>> +
>> +  io-channel-names:
>> +    const: sysmon-temp-channel
>> +
>> +required:
>> +  - compatible
>> +  - '#thermal-sensor-cells'
>> +  - io-channels
>> +  - io-channel-names
>> +
>> +additionalProperties: false
>> +
>> +examples:
>> +  - |
>> +    versal-thermal-sensor {
> 
> Drop the versal from the node name here please.
> With that,

will do.

> Acked-by: Conor Dooley <conor.dooley@microchip.com>

Thanks,
Michal


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

end of thread, other threads:[~2025-09-08  6:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-05  8:41 [PATCH 0/6] xilinx: Add support for Xilinx Sysmon IP Michal Simek
2025-09-05  8:41 ` [PATCH 4/6] dt-bindings: thermal: versal: Add description for Versal Thermal Michal Simek
2025-09-05 18:30   ` Conor Dooley
2025-09-08  6:39     ` Michal Simek
2025-09-05  8:41 ` [PATCH 5/6] thermal: versal-thermal: Add Versal thermal driver Michal Simek
2025-09-05  8:41 ` [PATCH 6/6] thermal: versal-thermal: Support thermal management in AI Engine Michal Simek
2025-09-05 10:48   ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox