[PATCH 3/4] thermal/drivers/ma35d1: Add Nuvoton MA35D1 thermal sensor driver
From: Zi-Yu Chen
Date: Tue Nov 17 2026 - 01:06:25 EST
Add a driver for the on-chip temperature sensor of the Nuvoton MA35D1
SoC. The sensor is controlled through a register in the system
management (SYS) block and is instantiated as an auxiliary device by
the MA35D1 reset driver.
The sensor converts continuously while powered on. The 12-bit result
is converted to millidegrees Celsius using a linear fit of the
temperature table from the sensor datasheet.
Signed-off-by: Zi-Yu Chen <zychennvt@xxxxxxxxx>
---
drivers/thermal/Kconfig | 11 +++
drivers/thermal/Makefile | 1 +
drivers/thermal/ma35d1_thermal.c | 149 +++++++++++++++++++++++++++++++
3 files changed, 161 insertions(+)
create mode 100644 drivers/thermal/ma35d1_thermal.c
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 810eeccedfba..571b2c026311 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -530,4 +530,15 @@ config LOONGSON2_THERMAL
is higher than the high temperature threshold or lower than the low
temperature threshold, the interrupt will occur.
+config MA35D1_THERMAL
+ tristate "Nuvoton MA35D1 thermal sensor"
+ depends on RESET_NUVOTON_MA35D1
+ depends on THERMAL_OF
+ select MFD_SYSCON
+ help
+ Support for the on-chip temperature sensor found on Nuvoton
+ MA35D1 SoCs. The driver provides temperature readings through the
+ Linux thermal framework. The sensor registers are accessed through
+ the system register block.
+
endif
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 3b249195c088..bf2796e3dd3f 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -70,3 +70,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_MA35D1_THERMAL) += ma35d1_thermal.o
diff --git a/drivers/thermal/ma35d1_thermal.c b/drivers/thermal/ma35d1_thermal.c
new file mode 100644
index 000000000000..453f57d236ec
--- /dev/null
+++ b/drivers/thermal/ma35d1_thermal.c
@@ -0,0 +1,149 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Nuvoton Technology Corp.
+ *
+ * Author: Zi-Yu Chen <zychennvt@xxxxxxxxx>
+ */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/mfd/syscon.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/thermal.h>
+
+#include "thermal_hwmon.h"
+
+#define MA35_SYS_TSENSRFCR 0x104
+#define MA35_TSEN_DATA_VALID BIT(31)
+#define MA35_TSEN_POWER_DOWN BIT(28)
+#define MA35_TSEN_DATA GENMASK(27, 16)
+
+/*
+ * Conversion from the 12-bit sensor data to millidegrees Celsius:
+ * temp (mC) = data * MA35_TS_CAL_A / 4096 - MA35_TS_CAL_B
+ * A and B come from a linear fit of the S40LLV33_TEMPSENSOR temperature table.
+ */
+#define MA35_TS_CAL_A 274350
+#define MA35_TS_CAL_B 93330
+
+struct ma35d1_thermal {
+ struct device *dev;
+ struct regmap *regmap;
+};
+
+static int ma35d1_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
+{
+ struct ma35d1_thermal *sensor = thermal_zone_device_priv(tzd);
+ unsigned int reg;
+ int data, ret;
+
+ ret = regmap_read(sensor->regmap, MA35_SYS_TSENSRFCR, ®);
+ if (ret)
+ return ret;
+
+ if (!(reg & MA35_TSEN_DATA_VALID))
+ return -EAGAIN;
+
+ data = FIELD_GET(MA35_TSEN_DATA, reg);
+ *temp = data * MA35_TS_CAL_A / 4096 - MA35_TS_CAL_B;
+
+ return 0;
+}
+
+static int ma35d1_thermal_power_on(struct ma35d1_thermal *sensor)
+{
+ return regmap_clear_bits(sensor->regmap, MA35_SYS_TSENSRFCR,
+ MA35_TSEN_POWER_DOWN);
+}
+
+static int ma35d1_thermal_power_off(struct ma35d1_thermal *sensor)
+{
+ return regmap_set_bits(sensor->regmap, MA35_SYS_TSENSRFCR,
+ MA35_TSEN_POWER_DOWN);
+}
+
+static int ma35d1_thermal_change_mode(struct thermal_zone_device *tzd,
+ enum thermal_device_mode mode)
+{
+ struct ma35d1_thermal *sensor = thermal_zone_device_priv(tzd);
+
+ if (mode == THERMAL_DEVICE_ENABLED)
+ return ma35d1_thermal_power_on(sensor);
+
+ return ma35d1_thermal_power_off(sensor);
+}
+
+static void ma35d1_thermal_power_off_action(void *data)
+{
+ struct ma35d1_thermal *sensor = data;
+
+ if (ma35d1_thermal_power_off(sensor))
+ dev_warn(sensor->dev, "failed to power off sensor\n");
+}
+
+static const struct thermal_zone_device_ops ma35d1_tz_ops = {
+ .get_temp = ma35d1_thermal_get_temp,
+ .change_mode = ma35d1_thermal_change_mode,
+};
+
+static int ma35d1_thermal_probe(struct auxiliary_device *adev,
+ const struct auxiliary_device_id *id)
+{
+ struct device *dev = &adev->dev;
+ struct thermal_zone_device *tzd;
+ struct ma35d1_thermal *sensor;
+ int ret;
+
+ sensor = devm_kzalloc_obj(dev, *sensor);
+ if (!sensor)
+ return -ENOMEM;
+
+ sensor->dev = dev;
+
+ sensor->regmap = syscon_node_to_regmap(dev->parent->of_node);
+ if (IS_ERR(sensor->regmap))
+ return dev_err_probe(dev, PTR_ERR(sensor->regmap),
+ "failed to get SYS regmap\n");
+
+ /*
+ * Registered before the thermal zone so that the sensor is powered
+ * off only after the zone has been unregistered.
+ */
+ ret = devm_add_action_or_reset(dev, ma35d1_thermal_power_off_action,
+ sensor);
+ if (ret)
+ return ret;
+
+ tzd = devm_thermal_of_zone_register(dev, 0, sensor, &ma35d1_tz_ops);
+ if (IS_ERR(tzd))
+ return dev_err_probe(dev, PTR_ERR(tzd),
+ "failed to register thermal zone\n");
+
+ /* thermal_of disables hwmon by default */
+ ret = devm_thermal_add_hwmon_sysfs(dev, tzd);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to add hwmon sysfs\n");
+
+ return 0;
+}
+
+static const struct auxiliary_device_id ma35d1_thermal_id_table[] = {
+ { .name = "reset_ma35d1.thermal" },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(auxiliary, ma35d1_thermal_id_table);
+
+static struct auxiliary_driver ma35d1_thermal_driver = {
+ .probe = ma35d1_thermal_probe,
+ .id_table = ma35d1_thermal_id_table,
+};
+module_auxiliary_driver(ma35d1_thermal_driver);
+
+MODULE_AUTHOR("Zi-Yu Chen <zychennvt@xxxxxxxxx>");
+MODULE_DESCRIPTION("Nuvoton MA35D1 Temperature Sensor Driver");
+MODULE_LICENSE("GPL");
--
2.34.1