[PATCH 5/6] thermal: versal-thermal: Add Versal thermal driver

Michal Simek
2025-09-05T08:42:29Z

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