Skip to contentSkip to conversation

Add Nuvoton MA35D1 thermal sensor support

PATCH In review Zi-Yu Chen 4 participants 9 messages Nov 17 – Nov 23

Subsystems (5)
lore
Share & tools
lore

Zi-Yu Chen

author
#0 lore raw

cover Add Nuvoton MA35D1 thermal sensor support

This series adds support for the on-chip temperature sensor of the Nuvoton MA35D1 SoC.

The sensor has no register region of its own; it is controlled through a single register in the system management (SYS) block, which is already described in DT and bound to the MA35D1 reset driver. Rather than adding a child node that would only exist to instantiate a driver, the SYS node is made the thermal sensor provider, and the reset driver creates an auxiliary device that the thermal driver binds to.

Patch 1 documents #thermal-sensor-cells for the SYS node, patch 2 makes the reset driver create the auxiliary device, patch 3 adds the thermal driver and patch 4 adds the thermal zone to the SoC dtsi.

Tested on the MA35D1-SOM board.

Zi-Yu Chen (4):
dt-bindings: reset: nuvoton,ma35d1-reset: Add #thermal-sensor-cells
reset: ma35d1: Register auxiliary device for the temperature sensor thermal/drivers/ma35d1: Add Nuvoton MA35D1 thermal sensor driver
arm64: dts: nuvoton: ma35d1: Add thermal zone

 .../bindings/reset/nuvoton,ma35d1-reset.yaml  |  13 +-
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi       |  16 ++
 drivers/reset/Kconfig                         |   1 +
 drivers/reset/reset-ma35d1.c                  |  11 +-
 drivers/thermal/Kconfig                       |  11 ++
 drivers/thermal/Makefile                      |   1 +
 drivers/thermal/ma35d1_thermal.c              | 149 ++++++++++++++++++
 7 files changed, 198 insertions(+), 4 deletions(-)
 create mode 100644 drivers/thermal/ma35d1_thermal.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/4 dt-bindings: reset: nuvoton,ma35d1-reset: Add #thermal-sensor-cells

The system management (SYS) block of the MA35D1 SoC also hosts the on-chip temperature sensor. The sensor is controlled through a single SYS register and has no resources of its own.

Allow the SYS node to act as a thermal sensor provider instead of adding a child node that would only exist to instantiate a driver.

Reference the common thermal-sensor schema and update the title to reflect that the node describes the whole SYS block. This makes #thermal-sensor-cells a required property, which is fine as the sensor is always present in the SoC and no driver depends on the property.

---
 .../bindings/reset/nuvoton,ma35d1-reset.yaml        | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml +10 -3
index 3ce7dcecd87a..a0cb0f98c1b1 100644
@@ -4,7 +4,7 @@
 $id: http://devicetree.org/schemas/reset/nuvoton,ma35d1-reset.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Nuvoton MA35D1 Reset Controller
+title: Nuvoton MA35D1 System Management (SYS) Block
 
 maintainers:
   - Chi-Fang Li <[email protected]>
@@ -12,7 +12,10 @@ maintainers:
 
 description:
   The system reset controller can be used to reset various peripheral
-  controllers in MA35D1 SoC.
+  controllers in MA35D1 SoC. It also hosts the on-chip temperature sensor.
+
+allOf:
+  - $ref: /schemas/thermal/thermal-sensor.yaml#
 
 properties:
   compatible:
@@ -26,12 +29,15 @@ properties:
   '#reset-cells':
     const: 1
 
+  '#thermal-sensor-cells':
+    const: 0
+
 required:
   - compatible
   - reg
   - '#reset-cells'
 
-additionalProperties: false
+unevaluatedProperties: false
 
 examples:
   # system reset controller node:
@@ -41,6 +47,7 @@ examples:
         compatible = "nuvoton,ma35d1-reset", "syscon";
         reg = <0x40460000 0x200>;
         #reset-cells = <1>;
+        #thermal-sensor-cells = <0>;
     };
 ...
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] dt-bindings: reset: nuvoton,ma35d1-reset: Add #thermal-sensor-cells

Quoted 12 lines · Zi-Yu Chen

The system management (SYS) block of the MA35D1 SoC also hosts the on-chip temperature sensor. The sensor is controlled through a single SYS register and has no resources of its own.

Allow the SYS node to act as a thermal sensor provider instead of adding a child node that would only exist to instantiate a driver.

Reference the common thermal-sensor schema and update the title to reflect that the node describes the whole SYS block. This makes #thermal-sensor-cells a required property, which is fine as the sensor is always present in the SoC and no driver depends on the property.

Quoted 4 lines
---
 .../bindings/reset/nuvoton,ma35d1-reset.yaml        | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Best regards,
Krzysztof

author
#3 lore raw

PATCH 2/4 reset: ma35d1: Register auxiliary device for the temperature sensor

In reply to Zi-Yu Chen

The on-chip temperature sensor is controlled through a register of the SYS block, which is already bound to this driver. Create an auxiliary device so that a thermal driver can bind to it without a separate devicetree node.

Failing to create the auxiliary device only affects temperature reporting, so warn and continue.

---
 drivers/reset/Kconfig        |  1 +
 drivers/reset/reset-ma35d1.c | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/reset/Kconfig +1 -0
index eda9c698a95f..cf42fd6f7a3c 100644
@@ -220,6 +220,7 @@ config RESET_NUVOTON_MA35D1
 	bool "Nuvoton MA35D1 Reset Driver"
 	depends on ARCH_MA35 || COMPILE_TEST
 	default ARCH_MA35
+	select AUXILIARY_BUS
 	help
 	  This enables the reset controller driver for Nuvoton MA35D1 SoC.
 
drivers/reset/reset-ma35d1.c +10 -1
index d2962c0c80be..8c82175d7466 100644
@@ -4,6 +4,7 @@
  * Author: Chi-Fang Li <[email protected]>
  */
 
+#include <linux/auxiliary_bus.h>
 #include <linux/bits.h>
 #include <linux/container_of.h>
 #include <linux/device.h>
@@ -218,7 +219,15 @@ static int ma35d1_reset_probe(struct platform_device *pdev)
 	if (err)
 		dev_warn(&pdev->dev, "failed to register restart handler\n");
 
-	return devm_reset_controller_register(dev, &reset_data->rcdev);
+	err = devm_reset_controller_register(dev, &reset_data->rcdev);
+	if (err)
+		return err;
+
+	/* The temperature sensor is also controlled through the SYS block */
+	if (!devm_auxiliary_device_create(dev, "thermal", NULL))
+		dev_warn(dev, "failed to create thermal auxiliary device\n");
+
+	return 0;
 }
 
 static struct platform_driver ma35d1_reset_driver = {
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH 3/4 thermal/drivers/ma35d1: Add Nuvoton MA35D1 thermal sensor driver

In reply to Zi-Yu Chen

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.

---
 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
drivers/thermal/Kconfig +11 -0
index 810eeccedfba..571b2c026311 100644
@@ -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
drivers/thermal/Makefile +1 -0
index 3b249195c088..bf2796e3dd3f 100644
@@ -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
drivers/thermal/ma35d1_thermal.c new file +149 -0

149 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 3/4] thermal/drivers/ma35d1: Add Nuvoton MA35D1 thermal sensor driver

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] thermal/ma35d1: undeclared devm_kzalloc_obj() in ma35d1_thermal_probe() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] thermal/ma35d1: undeclared devm_kzalloc_obj() in ma35d1_thermal_probe()
--

commit 7c4743b2d7c9ded9bc14984d2384e4a19e5bfbcd
Author: Zi-Yu Chen <[email protected]>

thermal/drivers/ma35d1: Add Nuvoton MA35D1 thermal sensor driver

This commit adds a thermal sensor driver for the Nuvoton MA35D1 SoC, instantiated as an auxiliary device by the MA35D1 reset driver and accessing the sensor register via a syscon regmap.

Quoted 6 lines
drivers/thermal/ma35d1_thermal.c new file +0 -0
new file mode 100644
index 0000000000000..453f57d236ecc
@@ -0,0 +1,149 @@

[ ... ]

drivers/thermal/ma35d1_thermal.c line 104

Quoted 11 lines
drivers/thermal/ma35d1_thermal.c new file +11 -0
+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;

[Severity: High]
Does this fail to build when CONFIG_MA35D1_THERMAL is enabled? include/linux/slab.h defines kzalloc_obj(), but there is no device-managed devm_kzalloc_obj() helper in the kernel, so compilation fails with an implicit function declaration error. Should this call devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL) instead?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#6 lore raw

Re: [PATCH 3/4] thermal/drivers/ma35d1: Add Nuvoton MA35D1 thermal sensor driver

In reply to Zi-Yu Chen

drivers/thermal/ma35d1_thermal.c line 14

Quoted 3 lines · Zi-Yu Chen
drivers/thermal/ma35d1_thermal.c new file +2 -0
+#include <linux/auxiliary_bus.h>
[...]
+#include <linux/mod_devicetable.h>

<linux/auxiliary_bus.h> already provides auxiliary_device_id, so please drop <linux/mod_devicetable.h>.

Best regards
Uwe

author
#7 lore raw

Re: [PATCH 3/4] thermal/drivers/ma35d1: Add Nuvoton MA35D1 thermal sensor driver

Uwe Kleine-König 於 2026/11/17 下午 10:16 寫道:

Quoted 10 lines · Zi-Yu Chen

drivers/thermal/ma35d1_thermal.c line 14

Quoted 3 lines
drivers/thermal/ma35d1_thermal.c new file +2 -0
+#include <linux/auxiliary_bus.h>
[...]
+#include <linux/mod_devicetable.h>

<linux/auxiliary_bus.h> already provides auxiliary_device_id, so please drop <linux/mod_devicetable.h>.

Best regards
Uwe

Thanks, I'll drop it.

Regards,
Zi-Yu Chen

author
#8 lore raw

PATCH 4/4 arm64: dts: nuvoton: ma35d1: Add thermal zone

In reply to Zi-Yu Chen

Describe the SYS block as the thermal sensor provider and add a thermal zone with a critical trip point for the SoC.

---
 arch/arm64/boot/dts/nuvoton/ma35d1.dtsi | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm64/boot/dts/nuvoton/ma35d1.dtsi +16 -0
index 7228ad4735b5..986f3cc4176b 100644
@@ -63,6 +63,21 @@ gic: interrupt-controller@50801000 {
 			      IRQ_TYPE_LEVEL_HIGH)>;
 	};
 
+	thermal-zones {
+		soc-thermal {
+			polling-delay = <1000>;
+			thermal-sensors = <&sys>;
+
+			trips {
+				soc_crit: soc-crit {
+					temperature = <125000>;
+					hysteresis = <2000>;
+					type = "critical";
+				};
+			};
+		};
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(4) |
@@ -86,6 +101,7 @@ sys: system-management@40460000 {
 			compatible = "nuvoton,ma35d1-reset", "syscon";
 			reg = <0x0 0x40460000 0x0 0x200>;
 			#reset-cells = <1>;
+			#thermal-sensor-cells = <0>;
 		};
 
 		clk: clock-controller@40460200 {
Signature · 1 line
2.34.1