* [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