lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ee77ab3014c367243a553dd4e814378804aaeb6e.1757061697.git.michal.simek@amd.com>
Date: Fri, 5 Sep 2025 10:41:48 +0200
From: Michal Simek <michal.simek@....com>
To: <linux-kernel@...r.kernel.org>, <monstr@...str.eu>,
	<michal.simek@...inx.com>, <git@...inx.com>
CC: Salih Erim <salih.erim@....com>, Daniel Lezcano
	<daniel.lezcano@...aro.org>, Lukasz Luba <lukasz.luba@....com>, "Rafael J.
 Wysocki" <rafael@...nel.org>, Zhang Rui <rui.zhang@...el.com>, "open
 list:THERMAL" <linux-pm@...r.kernel.org>
Subject: [PATCH 5/6] thermal: versal-thermal: Add Versal thermal driver

From: Salih Erim <salih.erim@....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@....com>
Signed-off-by: Michal Simek <michal.simek@....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@....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@...site.dk>
 L:	linux-serial@...r.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ