Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Apple T7000 (A8) die temperature sensors and thermal zones
@ 2026-12-04  7:43 Jeroen Trappers
  2026-12-04  7:43 ` [PATCH v2 1/3] dt-bindings: thermal: Add Apple T7000 die temperature sensors Jeroen Trappers
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jeroen Trappers @ 2026-12-04  7:43 UTC (permalink / raw)
  To: rafael, daniel.lezcano, sven, j, robh, krzk+dt, conor+dt
  Cc: rui.zhang, lukasz.luba, neal, towinchenmi, konradybcio, asahi,
	linux-arm-kernel, linux-pm, devicetree, linux-kernel,
	Jeroen Trappers

The Apple A8 has no thermal zones in Linux today. Unlike Apple Silicon
Macs, it has no SMC doing thermal management in firmware; on iOS the
kernel reads the die sensors itself. With nothing reading them, the
only protection is the hardware failsafe (SoCHOT) at 120 C.

This series adds a binding and a driver for the A8's five die
temperature sensors, in two blocks: two sensors in the power manager
(PMGR) and three in the CPU complex (TCC). It also adds thermal zones
in t7000.dtsi on three of the sensors. The zones throttle the CPUs
from 70 C, with 90 C hot and 100 C critical.

The register interface is the one iOS drives (AppleT700XTempSensor):
 - only 32-bit accesses;
 - a freeze / read / restart of each sensor's accumulator;
 - no writes to calibration, alarm or SoCHOT registers;
 - the per-sensor offsets from the tempsensor0..4 nodes of the iPhone 6
   device tree.
The driver is adapted from Berkay Kösebay's out-of-tree A9 (S8003)
driver for the same block.

Changes in v2 (all from the Sashiko review of v1):
 - Binding: each block is its own node, with its own compatible
   (apple,t7000-pmgr-thermal and apple,t7000-tcc-thermal) and the
   sensor index within the block as the cell. This replaces one node
   with two reg pages, where the TCC page was optional.
 - Driver: an accumulation interval is never cut shorter than 100 ms,
   so fast polling cannot starve the accumulator. In v1, a read that
   found no sample still restarted the interval.
 - Driver: a sensor without a valid sample for 5 s reads -EIO, and one
   disabled since probe reads -ENODEV without being restarted. v1 kept
   returning the last sample forever.
 - Driver: a sensor is only started once a zone using it is
   registered. Sensors no zone uses are not written at all; v1 started
   and then stopped them.
 - DTS: both CPUs are in the cooling maps.
 - DTS: the commit message explains why TCC sensors 0 and 1 get no zone
   yet.

Testing on v2, on an iPhone 6 (N61): the driver is byte-identical on a
7.3-rc1 based kernel, the iPhone 6 port this work comes from. That
kernel's n61 device tree has the same two sensor nodes and zones, plus
a GPU cooling map for a GPU driver that is not upstream. The v7.4-rc5
tree itself was not booted.
 - Both nodes bind after a cold boot. The zones read 31.5 / 29.0 /
   29.8 C idle (CPU complex / SOC0 / SOC1).
 - 2000 back-to-back reads of the CPU zone return no errors.
 - The unused TCC sensors 0 and 1 keep the CTL0 value the boot chain
   left. The three used sensors accumulate while bound, stop on unbind,
   and start again on rebind.
 - Two busy cores take the CPU complex sensor from 33 to 62 C in 5 s.
   It is back at 34 C seconds after the load stops.
The 70 C throttling step was tested on v1, with the same zones and
trips: the CPUs stepped to 1128 MHz and held 67-74 C. It was not
repeated on v2.

On v7.4-rc5, all of these are clean:
 - a W=1 arm64 build;
 - checkpatch --strict;
 - dt_binding_check;
 - CHECK_DTBS for every t7000 board.

v1: https://lore.kernel.org/r/20261203155600.3911447-1-jeroen.trappers@gmail.com

Tool use (Documentation/process/generated-content.rst): the series was
written with an LLM coding assistant over a longer working session. The
assistant drafted:
 - the driver, adapting the A9 driver to the A8 offsets and the iOS
   register sequence;
 - the binding;
 - the device tree nodes;
 - the changelogs.
Under my direction, it also ran the on-device tests and the build and
schema checks, and made the v2 changes. A separate LLM review pass, with
the review prompts Sashiko uses, found an issue that was fixed before
posting. I have reviewed the series and can answer for it.

Jeroen Trappers (3):
  dt-bindings: thermal: Add Apple T7000 die temperature sensors
  thermal/drivers/apple: Add T7000 (A8) on-die temperature sensor driver
  arm64: dts: apple: t7000: Add die temperature sensors and thermal
    zones

 .../bindings/thermal/apple,t7000-thermal.yaml |  57 ++++
 MAINTAINERS                                   |   8 +
 arch/arm64/boot/dts/apple/t7000.dtsi          | 130 ++++++++
 drivers/thermal/Kconfig                       |  13 +
 drivers/thermal/Makefile                      |   1 +
 drivers/thermal/apple_t7000_thermal.c         | 295 ++++++++++++++++++
 6 files changed, 504 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/apple,t7000-thermal.yaml
 create mode 100644 drivers/thermal/apple_t7000_thermal.c


base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
--
2.47.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] dt-bindings: thermal: Add Apple T7000 die temperature sensors
  2026-12-04  7:43 [PATCH v2 0/3] Apple T7000 (A8) die temperature sensors and thermal zones Jeroen Trappers
@ 2026-12-04  7:43 ` Jeroen Trappers
  2026-12-04  7:43 ` [PATCH v2 2/3] thermal/drivers/apple: Add T7000 (A8) on-die temperature sensor driver Jeroen Trappers
  2026-12-04  7:43 ` [PATCH v2 3/3] arm64: dts: apple: t7000: Add die temperature sensors and thermal zones Jeroen Trappers
  2 siblings, 0 replies; 5+ messages in thread
From: Jeroen Trappers @ 2026-12-04  7:43 UTC (permalink / raw)
  To: rafael, daniel.lezcano, sven, j, robh, krzk+dt, conor+dt
  Cc: rui.zhang, lukasz.luba, neal, towinchenmi, konradybcio, asahi,
	linux-arm-kernel, linux-pm, devicetree, linux-kernel,
	Jeroen Trappers

The Apple A8 (T7000) has five die temperature sensors, the tempsensor0..4
nodes of Apple's device tree, in two independent blocks with their own
register pages and layouts: two sensors in the power manager (PMGR) and
three in the CPU complex (TCC). Describe each block as its own thermal
sensor node, with a compatible per block and the sensor within the block
as the cell.

The binding was drafted with an LLM coding assistant and reviewed by me.

Signed-off-by: Jeroen Trappers <jeroen.trappers@gmail.com>
---
 .../bindings/thermal/apple,t7000-thermal.yaml | 57 +++++++++++++++++++
 MAINTAINERS                                   |  7 +++
 2 files changed, 64 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/apple,t7000-thermal.yaml

diff --git a/Documentation/devicetree/bindings/thermal/apple,t7000-thermal.yaml b/Documentation/devicetree/bindings/thermal/apple,t7000-thermal.yaml
new file mode 100644
index 000000000000..1d969a8fbab2
--- /dev/null
+++ b/Documentation/devicetree/bindings/thermal/apple,t7000-thermal.yaml
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/thermal/apple,t7000-thermal.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Apple T7000 (A8) die temperature sensors
+
+maintainers:
+  - Jeroen Trappers <jeroen.trappers@gmail.com>
+
+description:
+  The Apple A8 (T7000) has two blocks of die temperature sensors, each with
+  its own register page and layout. The power manager (PMGR) block has two
+  sensors; the CPU complex (TCC) block has three. Each sensor accumulates
+  samples between a start and a freeze of its control register; the result
+  is a signed fixed-point temperature in degrees Celsius, converted with the
+  calibration the boot chain programs.
+
+$ref: thermal-sensor.yaml#
+
+properties:
+  compatible:
+    enum:
+      - apple,t7000-pmgr-thermal
+      - apple,t7000-tcc-thermal
+
+  reg:
+    maxItems: 1
+
+  "#thermal-sensor-cells":
+    const: 1
+    description:
+      The sensor within the block, 0 to 1 in the power manager block and
+      0 to 2 in the CPU complex block.
+
+required:
+  - compatible
+  - reg
+  - "#thermal-sensor-cells"
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    thermal-sensor@e02b000 {
+        compatible = "apple,t7000-pmgr-thermal";
+        reg = <0x0e02b000 0x1000>;
+        #thermal-sensor-cells = <1>;
+    };
+
+  - |
+    thermal-sensor@2230000 {
+        compatible = "apple,t7000-tcc-thermal";
+        reg = <0x02230000 0x1000>;
+        #thermal-sensor-cells = <1>;
+    };
diff --git a/MAINTAINERS b/MAINTAINERS
index 84cb98ef4c49..667f9f37b824 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2140,6 +2140,13 @@ L:	linux-hwmon@vger.kernel.org
 S:	Odd fixes
 F:	drivers/hwmon/applesmc.c
 
+APPLE T7000 THERMAL DRIVER
+M:	Jeroen Trappers <jeroen.trappers@gmail.com>
+L:	asahi@lists.linux.dev
+L:	linux-pm@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/thermal/apple,t7000-thermal.yaml
+
 APPLETALK NETWORK LAYER
 L:	netdev@vger.kernel.org
 S:	Obsolete
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] thermal/drivers/apple: Add T7000 (A8) on-die temperature sensor driver
  2026-12-04  7:43 [PATCH v2 0/3] Apple T7000 (A8) die temperature sensors and thermal zones Jeroen Trappers
  2026-12-04  7:43 ` [PATCH v2 1/3] dt-bindings: thermal: Add Apple T7000 die temperature sensors Jeroen Trappers
@ 2026-12-04  7:43 ` Jeroen Trappers
  2026-12-04  8:36   ` Uwe Kleine-König
  2026-12-04  7:43 ` [PATCH v2 3/3] arm64: dts: apple: t7000: Add die temperature sensors and thermal zones Jeroen Trappers
  2 siblings, 1 reply; 5+ messages in thread
From: Jeroen Trappers @ 2026-12-04  7:43 UTC (permalink / raw)
  To: rafael, daniel.lezcano, sven, j, robh, krzk+dt, conor+dt
  Cc: rui.zhang, lukasz.luba, neal, towinchenmi, konradybcio, asahi,
	linux-arm-kernel, linux-pm, devicetree, linux-kernel,
	Jeroen Trappers

The Apple A8 (T7000) has the temperature sensor blocks iOS drives with
its AppleT700XTempSensor class. The per-sensor register offsets are the
sensor-offset-* properties of the tempsensor0..4 nodes in the iPhone 6
device tree. Each sensor accumulates samples between a start and a
freeze of CTL0 bit 3; a read freezes it, reads the result word (bit 31
valid, signed Q6 degrees Celsius) and the sample count, and starts the
next interval, as iOS's timer callback does. An interval is never cut
shorter than 100 ms, however often the zone is read; readers in between
get the last sample. A sensor without a valid sample for 5 s is
reported with -EIO, and one disabled since probe with -ENODEV.

Only 32-bit accesses are made. The driver never writes the trims,
CTL1/CTL2, the alarms or the SoCHOT thresholds, never sets a sensor's
enable bit (a sensor the boot chain left disabled is skipped), and only
starts a sensor once a thermal zone using it is registered, stopping it
again on unbind. Sensors no zone uses are left untouched.

It is a thermal driver rather than hwmon because the zones drive CPU
cooling; the readings are also exposed through the thermal hwmon bridge.

Adapted from Berkay Kösebay's out-of-tree driver for the A9 (S8003),
which uses the same block. The driver was drafted with an LLM coding
assistant and reviewed by me.

Signed-off-by: Jeroen Trappers <jeroen.trappers@gmail.com>
---
 MAINTAINERS                           |   1 +
 drivers/thermal/Kconfig               |  13 ++
 drivers/thermal/Makefile              |   1 +
 drivers/thermal/apple_t7000_thermal.c | 295 ++++++++++++++++++++++++++
 4 files changed, 310 insertions(+)
 create mode 100644 drivers/thermal/apple_t7000_thermal.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 667f9f37b824..049c3b8c8377 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2146,6 +2146,7 @@ L:	asahi@lists.linux.dev
 L:	linux-pm@vger.kernel.org
 S:	Maintained
 F:	Documentation/devicetree/bindings/thermal/apple,t7000-thermal.yaml
+F:	drivers/thermal/apple_t7000_thermal.c
 
 APPLETALK NETWORK LAYER
 L:	netdev@vger.kernel.org
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 810eeccedfba..4a2190b9f4a0 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -432,6 +432,19 @@ depends on ARCH_MEDIATEK || COMPILE_TEST
 source "drivers/thermal/mediatek/Kconfig"
 endmenu
 
+config APPLE_T7000_THERMAL
+	tristate "Apple T7000 (A8) on-die temperature sensors"
+	depends on ARCH_APPLE || COMPILE_TEST
+	depends on THERMAL_OF
+	help
+	  Thermal zone sensors for the die temperature sensors of the
+	  Apple A8 (T7000) SoC, as used in the iPhone 6 family and other
+	  2014 / 2015 Apple devices. The sensors are read with the
+	  calibration the boot chain programs.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called apple_t7000_thermal.
+
 config AMLOGIC_THERMAL
 	tristate "Amlogic Thermal Support"
 	default ARCH_MESON
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 3b249195c088..f2b6cbbe3307 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -64,6 +64,7 @@ obj-$(CONFIG_HISI_THERMAL)     += hisi_thermal.o
 obj-y				+= mediatek/
 obj-$(CONFIG_GENERIC_ADC_THERMAL)	+= thermal-generic-adc.o
 obj-$(CONFIG_UNIPHIER_THERMAL)	+= uniphier_thermal.o
+obj-$(CONFIG_APPLE_T7000_THERMAL)	+= apple_t7000_thermal.o
 obj-$(CONFIG_AMLOGIC_THERMAL)     += amlogic_thermal.o
 obj-y				+= spacemit/
 obj-$(CONFIG_SPRD_THERMAL)	+= sprd_thermal.o
diff --git a/drivers/thermal/apple_t7000_thermal.c b/drivers/thermal/apple_t7000_thermal.c
new file mode 100644
index 000000000000..ced00c1b9bbe
--- /dev/null
+++ b/drivers/thermal/apple_t7000_thermal.c
@@ -0,0 +1,295 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Apple T7000 (A8) on-die temperature sensors.
+ *
+ * Copyright (C) 2026 Jeroen Trappers <jeroen.trappers@gmail.com>
+ *
+ * Adapted from the out-of-tree Apple S8003 (A9) temperature sensor driver
+ * by Berkay Kösebay (GPL-2.0), which drives the same block.
+ *
+ * The blocks are the ones iOS drives with its AppleT700XTempSensor class;
+ * the per-sensor register offsets are the "sensor-offset-*" properties of
+ * the tempsensor0..4 nodes in the iPhone 6 device tree: tempsensor0..1 in the
+ * power manager (PMGR) page, tempsensor2..4 in the CPU complex (TCC) page.
+ * The hardware converts with the calibration the boot chain programs: this
+ * driver never writes the trims, CTL1/CTL2, the alarm registers or the
+ * SoCHOT thresholds, and never sets a sensor's enable bit (a sensor the boot
+ * chain left disabled is skipped). Only 32-bit accesses are made.
+ *
+ * Each sensor accumulates samples between a "start" (CTL0 set, bit 3) and a
+ * "freeze" (CTL0 clear, bit 3). A read freezes the accumulator, reads the
+ * result word (bit 31 valid, signed Q6 degrees Celsius in the low bits) and
+ * the sample count, and starts the next interval, as iOS's timer callback
+ * does.
+ */
+
+#include <linux/array_size.h>
+#include <asm/barrier.h>
+#include <linux/bitops.h>
+#include <linux/bits.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/jiffies.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/thermal.h>
+
+#include "thermal_hwmon.h"
+
+#define T7000_CTL0_ENABLE	BIT(0)
+#define T7000_CTL0_ACCUMULATE	BIT(3)
+#define T7000_BK_VALID		BIT(31)
+/*
+ * Every sample restarts the accumulator, and the thermal core, sysfs and
+ * hwmon may all read a zone: an accumulation interval is never cut shorter
+ * than this, so each sample averages over a useful window (about 400
+ * samples a second); readers within it get the last sample.
+ */
+#define T7000_MIN_INTERVAL_MS	100
+/* Without a valid sample for this long, the sensor is reported broken. */
+#define T7000_STALE_MS		5000
+
+/**
+ * struct t7000_sensor_desc - one sensor channel
+ * @ctl_set: CTL0 set register
+ * @ctl_clear: CTL0 clear register
+ * @bk: result register
+ * @count: accumulated sample count
+ */
+struct t7000_sensor_desc {
+	u16 ctl_set;
+	u16 ctl_clear;
+	u16 bk;
+	u16 count;
+};
+
+/**
+ * struct t7000_block - one sensor block (register page)
+ * @sensors: its sensors, by the binding's sensor index
+ * @num_sensors: number of sensors
+ * @sign_bit: sign bit of the Q6 value (14 for sensor-accuracy 2, else 15)
+ */
+struct t7000_block {
+	const struct t7000_sensor_desc *sensors;
+	unsigned int num_sensors;
+	u8 sign_bit;
+};
+
+static const struct t7000_sensor_desc t7000_pmgr_sensors[] = {
+	{ .ctl_set = 0x000, .ctl_clear = 0x004, .bk = 0x018, .count = 0x024 },
+	{ .ctl_set = 0x044, .ctl_clear = 0x048, .bk = 0x05c, .count = 0x068 },
+};
+
+static const struct t7000_sensor_desc t7000_tcc_sensors[] = {
+	{ .ctl_set = 0x000, .ctl_clear = 0x408, .bk = 0x020, .count = 0x038 },
+	{ .ctl_set = 0x040, .ctl_clear = 0x438, .bk = 0x060, .count = 0x078 },
+	{ .ctl_set = 0x200, .ctl_clear = 0x468, .bk = 0x220, .count = 0x238 },
+};
+
+static const struct t7000_block t7000_pmgr = {
+	.sensors = t7000_pmgr_sensors,
+	.num_sensors = ARRAY_SIZE(t7000_pmgr_sensors),
+	.sign_bit = 14,
+};
+
+static const struct t7000_block t7000_tcc = {
+	.sensors = t7000_tcc_sensors,
+	.num_sensors = ARRAY_SIZE(t7000_tcc_sensors),
+	.sign_bit = 15,
+};
+
+/**
+ * struct t7000_sensor - one registered sensor
+ * @base: its block's register page
+ * @desc: its registers
+ * @sign_bit: sign bit of its Q6 value
+ * @started: whether this driver started its accumulation
+ * @restarted: jiffies of the last start of an accumulation interval
+ * @sampled: jiffies of the last valid sample (of the start before the first)
+ * @temp: the last valid sample, millidegrees Celsius
+ * @valid: whether @temp holds a sample
+ *
+ * The thermal core serializes the get_temp() calls of a zone.
+ */
+struct t7000_sensor {
+	void __iomem *base;
+	const struct t7000_sensor_desc *desc;
+	u8 sign_bit;
+	bool started;
+	unsigned long restarted;
+	unsigned long sampled;
+	int temp;
+	bool valid;
+};
+
+/* Start an accumulation interval. */
+static void t7000_start(struct t7000_sensor *s)
+{
+	writel(T7000_CTL0_ACCUMULATE, s->base + s->desc->ctl_set);
+	s->restarted = jiffies;
+}
+
+static int t7000_sample(struct t7000_sensor *s)
+{
+	const struct t7000_sensor_desc *d = s->desc;
+	u32 bk, count;
+	int temp;
+
+	/* Disabled since probe: report it, and do not start it again. */
+	if (!(readl(s->base + d->ctl_set) & T7000_CTL0_ENABLE))
+		return -ENODEV;
+
+	writel(T7000_CTL0_ACCUMULATE, s->base + d->ctl_clear);
+	bk = readl(s->base + d->bk);
+	count = readl(s->base + d->count);
+	t7000_start(s);
+
+	if (!(bk & T7000_BK_VALID) || !count)
+		return -EAGAIN;
+
+	temp = DIV_ROUND_CLOSEST(sign_extend32(bk, s->sign_bit) * 1000, 64);
+	/* An impossible code is a glitch; iOS substitutes 30 C instead. */
+	if (temp < -40000 || temp > 150000)
+		return -EAGAIN;
+
+	s->temp = temp;
+	s->sampled = jiffies;
+	s->valid = true;
+	return 0;
+}
+
+static int t7000_get_temp(struct thermal_zone_device *tz, int *temp)
+{
+	struct t7000_sensor *s = thermal_zone_device_priv(tz);
+	int ret = -EAGAIN;
+
+	/*
+	 * The zone may be read before the sensor is started; the acquire pairs
+	 * with the release in probe, so @restarted and @sampled are seen once @started is.
+	 */
+	if (!smp_load_acquire(&s->started))
+		return -EAGAIN;
+
+	if (time_after_eq(jiffies, s->restarted + msecs_to_jiffies(T7000_MIN_INTERVAL_MS))) {
+		ret = t7000_sample(s);
+		if (ret == -ENODEV)
+			return ret;
+	}
+	if (!ret) {
+		*temp = s->temp;
+		return 0;
+	}
+
+	/*
+	 * No new sample (too early, an interval without one, or a glitch).
+	 * @sampled is the last valid sample, or the start if there was none:
+	 * the sensor reads broken until it delivers again.
+	 */
+	if (time_after(jiffies, s->sampled + msecs_to_jiffies(T7000_STALE_MS)))
+		return -EIO;
+	if (!s->valid)
+		return -EAGAIN;
+	*temp = s->temp;
+	return 0;
+}
+
+static const struct thermal_zone_device_ops t7000_thermal_ops = {
+	.get_temp = t7000_get_temp,
+};
+
+/* On unbind, stop what this driver started: the sensor is left as the boot chain left it. */
+static void t7000_sensor_stop(void *data)
+{
+	struct t7000_sensor *s = data;
+
+	if (s->started)
+		writel(T7000_CTL0_ACCUMULATE, s->base + s->desc->ctl_clear);
+}
+
+static int t7000_thermal_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	const struct t7000_block *block;
+	void __iomem *base;
+	unsigned int i;
+	int ret;
+
+	block = of_device_get_match_data(dev);
+	if (!block)
+		return -EINVAL;
+
+	base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	for (i = 0; i < block->num_sensors; i++) {
+		const struct t7000_sensor_desc *d = &block->sensors[i];
+		struct thermal_zone_device *tz;
+		struct t7000_sensor *s;
+
+		if (!(readl(base + d->ctl_set) & T7000_CTL0_ENABLE)) {
+			dev_dbg(dev, "sensor %u not enabled by the boot chain\n", i);
+			continue;
+		}
+
+		s = devm_kzalloc(dev, sizeof(*s), GFP_KERNEL);
+		if (!s)
+			return -ENOMEM;
+		s->base = base;
+		s->desc = d;
+		s->sign_bit = block->sign_bit;
+
+		/* Added before the zone, so that unbind stops the sensor after the zone is gone. */
+		ret = devm_add_action_or_reset(dev, t7000_sensor_stop, s);
+		if (ret)
+			return ret;
+
+		tz = devm_thermal_of_zone_register(dev, i, s, &t7000_thermal_ops);
+		if (IS_ERR(tz)) {
+			/* No zone uses this sensor: leave it untouched. */
+			if (PTR_ERR(tz) == -ENODEV) {
+				devm_remove_action(dev, t7000_sensor_stop, s);
+				devm_kfree(dev, s);
+				continue;
+			}
+			return dev_err_probe(dev, PTR_ERR(tz),
+					     "failed to register sensor %u\n", i);
+		}
+
+		/* Start accumulating, as iOS does; the zone's first reads see no sample yet. */
+		t7000_start(s);
+		s->sampled = s->restarted;
+		/* Publishes @restarted and @sampled to t7000_get_temp(). */
+		smp_store_release(&s->started, true);
+
+		ret = devm_thermal_add_hwmon_sysfs(dev, tz);
+		if (ret)
+			dev_warn(dev, "failed to add hwmon for sensor %u: %d\n",
+				 i, ret);
+	}
+
+	return 0;
+}
+
+static const struct of_device_id t7000_thermal_of_match[] = {
+	{ .compatible = "apple,t7000-pmgr-thermal", .data = &t7000_pmgr },
+	{ .compatible = "apple,t7000-tcc-thermal", .data = &t7000_tcc },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, t7000_thermal_of_match);
+
+static struct platform_driver t7000_thermal_driver = {
+	.probe = t7000_thermal_probe,
+	.driver = {
+		.name = "apple-t7000-thermal",
+		.of_match_table = t7000_thermal_of_match,
+	},
+};
+module_platform_driver(t7000_thermal_driver);
+
+MODULE_AUTHOR("Jeroen Trappers <jeroen.trappers@gmail.com>");
+MODULE_DESCRIPTION("Apple T7000 on-die temperature sensors");
+MODULE_LICENSE("GPL");
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] arm64: dts: apple: t7000: Add die temperature sensors and thermal zones
  2026-12-04  7:43 [PATCH v2 0/3] Apple T7000 (A8) die temperature sensors and thermal zones Jeroen Trappers
  2026-12-04  7:43 ` [PATCH v2 1/3] dt-bindings: thermal: Add Apple T7000 die temperature sensors Jeroen Trappers
  2026-12-04  7:43 ` [PATCH v2 2/3] thermal/drivers/apple: Add T7000 (A8) on-die temperature sensor driver Jeroen Trappers
@ 2026-12-04  7:43 ` Jeroen Trappers
  2 siblings, 0 replies; 5+ messages in thread
From: Jeroen Trappers @ 2026-12-04  7:43 UTC (permalink / raw)
  To: rafael, daniel.lezcano, sven, j, robh, krzk+dt, conor+dt
  Cc: rui.zhang, lukasz.luba, neal, towinchenmi, konradybcio, asahi,
	linux-arm-kernel, linux-pm, devicetree, linux-kernel,
	Jeroen Trappers

Describe the A8's two die temperature sensor blocks and add three
zones: the CPU complex (TCC sensor 2) and the two power manager
sensors. The CPUs throttle from 70 C (apple-soc-cpufreq is the cooling
device), 90 C is hot and 100 C, the alarm temperature in the boot
chain's device tree, is critical, below the hardware failsafe (SoCHOT)
at 120 / 125 C. The CPUs are the only cooling device, so the power
manager sensors, which also see the GPU's heat, throttle them too. Both
CPUs are listed in the cooling maps, so throttling works whichever CPU
the kernel boots on.

TCC sensors 0 and 1 get no zone yet: sensor 2 is the one checked
against CPU load, and where in the CPU complex the other two sit is not
measured yet.

The power manager page lies after the end of the pmgr node's range
(0x20e000000 + 0x24000), like the watchdog's.

The trips were validated on the iPhone 6 (N61); they are conservative
for the other T7000 devices, which share the SoC.

The nodes were drafted with an LLM coding assistant and reviewed by me.

Signed-off-by: Jeroen Trappers <jeroen.trappers@gmail.com>
---
 arch/arm64/boot/dts/apple/t7000.dtsi | 130 +++++++++++++++++++++++++++
 1 file changed, 130 insertions(+)

diff --git a/arch/arm64/boot/dts/apple/t7000.dtsi b/arch/arm64/boot/dts/apple/t7000.dtsi
index 0342455d3444..529083268524 100644
--- a/arch/arm64/boot/dts/apple/t7000.dtsi
+++ b/arch/arm64/boot/dts/apple/t7000.dtsi
@@ -12,6 +12,7 @@
 #include <dt-bindings/interrupt-controller/apple-aic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/pinctrl/apple.h>
+#include <dt-bindings/thermal/thermal.h>
 
 / {
 	interrupt-parent = <&aic>;
@@ -34,6 +35,7 @@ cpu0: cpu@0 {
 			reg = <0x0 0x0>;
 			cpu-release-addr = <0 0>; /* To be filled in by loader */
 			performance-domains = <&cpufreq>;
+			#cooling-cells = <2>;
 			operating-points-v2 = <&typhoon_opp>;
 			enable-method = "spin-table";
 			device_type = "cpu";
@@ -47,6 +49,7 @@ cpu1: cpu@1 {
 			reg = <0x0 0x1>;
 			cpu-release-addr = <0 0>; /* To be filled in by loader */
 			performance-domains = <&cpufreq>;
+			#cooling-cells = <2>;
 			operating-points-v2 = <&typhoon_opp>;
 			enable-method = "spin-table";
 			device_type = "cpu";
@@ -118,6 +121,12 @@ cpufreq: performance-controller@202220000 {
 			#performance-domain-cells = <0>;
 		};
 
+		tcc_temp: thermal-sensor@202230000 {
+			compatible = "apple,t7000-tcc-thermal";
+			reg = <0x2 0x02230000 0x0 0x1000>;
+			#thermal-sensor-cells = <1>;
+		};
+
 		serial0: serial@20a0c0000 {
 			compatible = "apple,s5l-uart";
 			reg = <0x2 0x0a0c0000 0x0 0x4000>;
@@ -216,6 +225,12 @@ wdt: watchdog@20e027000 {
 			interrupts = <AIC_IRQ 4 IRQ_TYPE_LEVEL_HIGH>;
 		};
 
+		pmgr_temp: thermal-sensor@20e02b000 {
+			compatible = "apple,t7000-pmgr-thermal";
+			reg = <0x2 0x0e02b000 0x0 0x1000>;
+			#thermal-sensor-cells = <1>;
+		};
+
 		aic: interrupt-controller@20e100000 {
 			compatible = "apple,t7000-aic", "apple,aic";
 			reg = <0x2 0x0e100000 0x0 0x100000>;
@@ -274,6 +289,121 @@ i2c3_pins: i2c3-pins {
 		};
 	};
 
+	/*
+	 * The CPUs throttle from 70 C, 90 C is hot and 100 C (the alarm
+	 * temperature in the boot chain's device tree) is critical, below
+	 * the hardware failsafe (SoCHOT) at 120 / 125 C. The CPUs are the
+	 * only cooling device, so the power manager sensors, which also see
+	 * the GPU's heat, throttle them as well.
+	 *
+	 * Of the CPU complex sensors only sensor 2 has a zone: it is the one
+	 * checked against CPU load. Which part of the complex sensors 0 and 1
+	 * sit in is not known yet; they get zones once that is measured.
+	 */
+	thermal-zones {
+		cpu-thermal {
+			polling-delay-passive = <250>;
+			polling-delay = <1000>;
+			thermal-sensors = <&tcc_temp 2>;
+
+			trips {
+				cpu_alert: cpu-alert {
+					temperature = <70000>;
+					hysteresis = <3000>;
+					type = "passive";
+				};
+
+				cpu-hot {
+					temperature = <90000>;
+					hysteresis = <3000>;
+					type = "hot";
+				};
+
+				cpu-crit {
+					temperature = <100000>;
+					hysteresis = <0>;
+					type = "critical";
+				};
+			};
+
+			cooling-maps {
+				map0 {
+					trip = <&cpu_alert>;
+					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+							 <&cpu1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+				};
+			};
+		};
+
+		soc0-thermal {
+			polling-delay-passive = <250>;
+			polling-delay = <1000>;
+			thermal-sensors = <&pmgr_temp 0>;
+
+			trips {
+				soc0_alert: soc0-alert {
+					temperature = <70000>;
+					hysteresis = <3000>;
+					type = "passive";
+				};
+
+				soc0-hot {
+					temperature = <90000>;
+					hysteresis = <3000>;
+					type = "hot";
+				};
+
+				soc0-crit {
+					temperature = <100000>;
+					hysteresis = <0>;
+					type = "critical";
+				};
+			};
+
+			cooling-maps {
+				map0 {
+					trip = <&soc0_alert>;
+					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+							 <&cpu1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+				};
+			};
+		};
+
+		soc1-thermal {
+			polling-delay-passive = <250>;
+			polling-delay = <1000>;
+			thermal-sensors = <&pmgr_temp 1>;
+
+			trips {
+				soc1_alert: soc1-alert {
+					temperature = <70000>;
+					hysteresis = <3000>;
+					type = "passive";
+				};
+
+				soc1-hot {
+					temperature = <90000>;
+					hysteresis = <3000>;
+					type = "hot";
+				};
+
+				soc1-crit {
+					temperature = <100000>;
+					hysteresis = <0>;
+					type = "critical";
+				};
+			};
+
+			cooling-maps {
+				map0 {
+					trip = <&soc1_alert>;
+					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+							 <&cpu1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+				};
+			};
+		};
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupt-parent = <&aic>;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/3] thermal/drivers/apple: Add T7000 (A8) on-die temperature sensor driver
  2026-12-04  7:43 ` [PATCH v2 2/3] thermal/drivers/apple: Add T7000 (A8) on-die temperature sensor driver Jeroen Trappers
@ 2026-12-04  8:36   ` Uwe Kleine-König
  0 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2026-12-04  8:36 UTC (permalink / raw)
  To: Jeroen Trappers
  Cc: rafael, daniel.lezcano, sven, j, robh, krzk+dt, conor+dt,
	rui.zhang, lukasz.luba, neal, towinchenmi, konradybcio, asahi,
	linux-arm-kernel, linux-pm, devicetree, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 649 bytes --]

Hello,

just after replying to (implicit) v1, I found this v2. So I'm repeating
my feedback here to make it easy not to miss it.

On Fri, Dec 04, 2026 at 08:43:27AM +0100, Jeroen Trappers wrote:
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>

Please drop <linux/mod_devicetable.h>. It's not needed here as both
<linux/of.h> and <linux/platform_device.h> already provide of_device_id
in a more effective way (that is without introducing many unneeded
*_device_id and thus useless build dependencies).

I plan to drop <linux/mod_devicetable.h> soon.

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04  8:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  7:43 [PATCH v2 0/3] Apple T7000 (A8) die temperature sensors and thermal zones Jeroen Trappers
2026-12-04  7:43 ` [PATCH v2 1/3] dt-bindings: thermal: Add Apple T7000 die temperature sensors Jeroen Trappers
2026-12-04  7:43 ` [PATCH v2 2/3] thermal/drivers/apple: Add T7000 (A8) on-die temperature sensor driver Jeroen Trappers
2026-12-04  8:36   ` Uwe Kleine-König
2026-12-04  7:43 ` [PATCH v2 3/3] arm64: dts: apple: t7000: Add die temperature sensors and thermal zones Jeroen Trappers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox