Skip to contentSkip to conversation

Add support for Analog Devices MAX30210

PATCH Superseded John Erasmus Mari Geronimo 5 participants 9 messages Oct 15 – Oct 17

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add support for Analog Devices MAX30210

This series adds support for the Analog Devices MAX30210 I2C temperature sensor.

The device provides a 16-bit temperature output and includes features such as a hardware FIFO, programmable sampling rate, threshold alarms, and interrupt support. These capabilities map naturally to the IIO subsystem, particularly the buffered interface and event framework -- hwmon has no equivalent buffered-capture framework, and its alarm attributes are polled rather than interrupt-driven, so there is no path to supporting the FIFO or the autonomous threshold comparators there.

Although the MAX30210 belongs to the same device family as the MAX30208, it is implemented as a separate driver. The MAX30210 has a significantly different feature set, including a 64-sample hardware FIFO with configurable watermark interrupts, programmable sampling rates, and event support. These features require buffered operation and IRQ-driven data handling which are not present in the MAX30208 driver (which talks to the device directly via i2c_smbus_*() calls with no regmap, and has no IIO buffer or event interface at all).

In addition, the MAX30210 uses a different register map and a more flexible I2C address selection scheme. Supporting both devices in a single driver would introduce substantial conditional logic, so a separate driver keeps the implementation simpler and easier to maintain.

Patch 1 adds the devicetree binding.
Patch 2 adds the IIO driver implementation.

Changes since v3:
https://lore.kernel.org/all/[email protected]/
- regmap_noinc_read() for FIFO reads instead of regmap_bulk_read(), which (combined with regmap caching) could silently return stale cached values of unrelated registers instead of real FIFO data.
- Mark both bytes of TEMP_DATA_REG volatile for the same reason.
- Decouple threshold events from the buffer via a refcounted autoconv_get()/autoconv_put() pair, so either can be used independently or concurrently.
- Don't let a single-shot direct-mode read race with/clobber autonomous conversion mode if a threshold event or the buffer is already using it -- return -EBUSY instead.
- Don't hard-fail probe when there is no interrupt; fall back to direct-mode-only operation.
- Fix devm teardown ordering so an in-flight interrupt can't use a freed event interface on removal.
- Re-assert the powerdown GPIO on removal so the device reaches standby instead of staying powered indefinitely.
- Style/API fixes from review (register/field grouping, _MASK naming, FIELD_PREP/regmap_assign_bits usage, C99 initializers, dropped redundant i2c_check_functionality() check, comment cleanup).

All of the above have been verified on real MAX30210 hardware (Raspberry Pi 4 test rig), including the no-IRQ fallback, buffer and event refcounting (independently and concurrently), rmmod/insmod under live interrupts, powerdown GPIO assertion on removal, and FIFO flush correctness.

Changes since v2:
https://lore.kernel.org/all/[email protected]/
- Fix FIFO byte-count handling and sample decoding.
- Fix IIO debug register read/write access.
- Validate event threshold values and sampling-frequency register values.
- Return the correct sampling-frequency format and reject direct reads while buffered capture is enabled.
- Clean up the Kconfig entry and device-tree supply declaration.

John Erasmus Mari Geronimo (2):
dt-bindings: iio: temperature: add ADI MAX30210
iio: temperature: add support for Analog Devices MAX30210

 .../iio/temperature/adi,max30210.yaml         |  61 ++
 MAINTAINERS                                   |   8 +
 drivers/iio/temperature/Kconfig               |  13 +
 drivers/iio/temperature/Makefile              |   1 +
 drivers/iio/temperature/max30210.c            | 788 ++++++++++++++++++
 5 files changed, 871 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/temperature/adi,max30210.yaml
 create mode 100644 drivers/iio/temperature/max30210.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/2 dt-bindings: iio: temperature: add ADI MAX30210

Add device tree binding documentation for the Analog Devices MAX30210 temperature sensor.

---
 .../iio/temperature/adi,max30210.yaml         | 61 +++++++++++++++++++
 MAINTAINERS                                   |  7 +++
 2 files changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/temperature/adi,max30210.yaml
Documentation/devicetree/bindings/iio/temperature/adi,max30210.yaml new file +61 -0
new file mode 100644
index 0000000000000..8bfd154bbc438
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright 2026 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/temperature/adi,max30210.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX30210 Temperature Sensor
+
+maintainers:
+  - John Erasmus Mari Geronimo <[email protected]>
+
+description: |
+  The MAX30210 is a temperature sensor with an I2C interface.
+  https://www.analog.com/media/en/technical-documentation/data-sheets/max30210.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,max30210
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+
+  powerdown-gpios:
+    description: GPIO connected to the CVT/PDB pin (active low).
+    maxItems: 1
+
+  interrupts:
+    description: Connected to INT pin. Interrupt triggered on both rising and falling edges.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        temperature-sensor@40 {
+            compatible = "adi,max30210";
+            reg = <0x40>;
+            vdd-supply = <&vdd>;
+            powerdown-gpios = <&gpio 12 GPIO_ACTIVE_LOW>;
+
+            interrupt-parent = <&gpio>;
+            interrupts = <17 IRQ_TYPE_EDGE_BOTH>;
+        };
+    };
+...
MAINTAINERS +7 -0
index 396d4e76dccc2..6eb3cf66f431c 100644
@@ -1653,6 +1653,13 @@ W:	https://ez.analog.com/linux-software-drivers
 F:	Documentation/devicetree/bindings/iio/dac/adi,max22007.yaml
 F:	drivers/iio/dac/max22007.c
 
+ANALOG DEVICES INC MAX30210 DRIVER
+M:	John Erasmus Mari Geronimo <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/iio/temperature/adi,max30210.yaml
+
 ANALOG DEVICES INC ADA4250 DRIVER
 M:	Antoniu Miclaus <[email protected]>
 L:	[email protected]
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH v4 1/2] dt-bindings: iio: temperature: add ADI MAX30210

Quoted 4 lines · John Erasmus Mari Geronimo

Add device tree binding documentation for the Analog Devices MAX30210 temperature sensor.

Missing Krzysztof's Reviewed-by.

#3 lore raw

PATCH v4 2/2 iio: temperature: add support for Analog Devices MAX30210

In reply to John Erasmus Mari Geronimo

Add support for the Analog Devices MAX30210 I2C temperature sensor.

The driver uses regmap for register access and integrates with the IIO framework. It supports:

- Direct mode temperature conversion
- Configurable sampling frequency
- Threshold events
- FIFO operation with IIO kfifo buffer support
- Optional interrupt-driven data ready signaling

The device provides 16-bit signed temperature data and a 64-sample FIFO.

---
 MAINTAINERS                        |   1 +
 drivers/iio/temperature/Kconfig    |  13 +
 drivers/iio/temperature/Makefile   |   1 +
 drivers/iio/temperature/max30210.c | 788 +++++++++++++++++++++++++++++
 4 files changed, 803 insertions(+)
 create mode 100644 drivers/iio/temperature/max30210.c
MAINTAINERS +1 -0
index 6eb3cf66f431c..e479c64a284e0 100644
@@ -1659,6 +1659,7 @@ L:	[email protected]
 S:	Supported
 W:	https://ez.analog.com/linux-software-drivers
 F:	Documentation/devicetree/bindings/iio/temperature/adi,max30210.yaml
+F:	drivers/iio/temperature/max30210.c
 
 ANALOG DEVICES INC ADA4250 DRIVER
 M:	Antoniu Miclaus <[email protected]>
drivers/iio/temperature/Kconfig +13 -0
index 9328b2250aced..05b3af6872b31 100644
@@ -152,6 +152,19 @@ config MAX30208
 	  This driver can also be built as a module. If so, the module
 	  will be called max30208.
 
+config MAX30210
+	tristate "Analog Devices MAX30210 temperature sensor"
+	depends on I2C
+	select REGMAP_I2C
+	select IIO_BUFFER
+	select IIO_KFIFO_BUF
+	help
+	  If you say yes here you get support for MAX30210 low-power digital
+	  temperature sensor chip connected via I2C.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called max30210.
+
 config MAX31856
 	tristate "MAX31856 thermocouple sensor"
 	depends on SPI
drivers/iio/temperature/Makefile +1 -0
index 07d6e65709f7f..e5aad14dc09b9 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_LTC2983) += ltc2983.o
 obj-$(CONFIG_HID_SENSOR_TEMP) += hid-sensor-temperature.o
 obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o
 obj-$(CONFIG_MAX30208) += max30208.o
+obj-$(CONFIG_MAX30210) += max30210.o
 obj-$(CONFIG_MAX31856) += max31856.o
 obj-$(CONFIG_MAX31865) += max31865.o
 obj-$(CONFIG_MCP9600) += mcp9600.o
drivers/iio/temperature/max30210.c new file +788 -0

788 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v4 2/2] iio: temperature: add support for Analog Devices MAX30210

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [Medium] iio: max30210: missing power-up delay before first I2C transaction - [Medium] iio: max30210…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Medium] iio: max30210: missing power-up delay before first I2C transaction
- [Medium] iio: max30210: autoconv_users reference count leak on duplicate sysfs writes
- [Medium] iio: max30210: hardware interrupt left enabled on buffer preenable/postdisable failure
- [Low] iio: max30210: unconditional IRQ_HANDLED return breaks shared interrupt lines --

commit 296957e73a12ca35c9045876e136385ab80ca00e
Author: John Erasmus Mari Geronimo <[email protected]>

iio: temperature: add support for Analog Devices MAX30210

This commit adds support for the Analog Devices MAX30210 I2C temperature sensor. It introduces a driver using regmap for register access, supporting direct mode, configurable sampling, threshold events, and FIFO buffer operation.

Quoted 5 lines
drivers/iio/temperature/max30210.c new file +0 -0
new file mode 100644
index 0000000000000..04123d51c6da4

[ ... ]

Quoted 6 lines
drivers/iio/temperature/max30210.c new file +6 -0
+static irqreturn_t max30210_irq_handler(int irq, void *dev_id)
+{
+	struct iio_dev *indio_dev = dev_id;
+	struct max30210_state *st = iio_priv(indio_dev);
+	unsigned int status;
+	int ret;

[ ... ]

drivers/iio/temperature/max30210.c line 246

Quoted 9 lines
drivers/iio/temperature/max30210.c new file +9 -0
+	if (status & MAX30210_STATUS_TEMP_LO_MASK)
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_FALLING),
+			       iio_get_time_ns(indio_dev));
+
+	return IRQ_HANDLED;
+}

[Severity: Low]
Does this unconditional return defeat the kernel's spurious interrupt detection? If a shared interrupt line gets stuck or stormy from another device, the kernel might not detect it because this driver claims to have handled every interrupt even when no relevant status bits were set. Should this return IRQ_NONE if no active interrupts were serviced?

[ ... ]

Quoted 8 lines
drivers/iio/temperature/max30210.c new file +8 -0
+static int max30210_write_event_config(struct iio_dev *indio_dev,
+				       const struct iio_chan_spec *chan,
+				       enum iio_event_type type,
+				       enum iio_event_direction dir, bool state)
+{
+	struct max30210_state *st = iio_priv(indio_dev);
+	unsigned int mask;
+	int ret;

[ ... ]

drivers/iio/temperature/max30210.c line 388

Quoted 9 lines
drivers/iio/temperature/max30210.c new file +9 -0
+	/*
+	 * Threshold events need the device sampling autonomously, independent
+	 * of whether the FIFO buffer is also enabled.
+	 */
+	if (state) {
+		ret = max30210_autoconv_get(st);
+		if (ret)
+			return ret;
+	}

[Severity: Medium]
Could this leak the st->autoconv_users reference count? If userspace repeatedly writes '1' to an already-enabled threshold event attribute in sysfs, or '0' to an already-disabled event, the IIO core's iio_ev_state_store() passes the boolean state here without caching or deduplicating.

The driver then blindly increments or decrements st->autoconv_users via max30210_autoconv_get() or max30210_autoconv_put(). This could permanently inflate the counter, leaving the device stuck in autonomous conversion mode and causing direct mode reads to fail with -EBUSY.

[ ... ]

Quoted 9 lines
drivers/iio/temperature/max30210.c new file +9 -0
+static int max30210_buffer_preenable(struct iio_dev *indio_dev)
+{
+	struct max30210_state *st = iio_priv(indio_dev);
+	int ret;
+
+	/* Enable FIFO-full interrupt */
+	ret = regmap_set_bits(st->regmap, MAX30210_INT_EN_REG,
+			      MAX30210_STATUS_A_FULL_MASK);
+	if (ret)

drivers/iio/temperature/max30210.c line 593

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+		return ret;
+
+	/* Flush FIFO before starting autonomous conversions */
+	ret = regmap_set_bits(st->regmap, MAX30210_FIFO_CONF_2_REG,
+			      MAX30210_FIFOCONF2_FLUSH_FIFO);
+	if (ret)
+		return ret;
+
+	return max30210_autoconv_get(st);
+}

[Severity: Medium]
If the I2C transaction for flushing the FIFO or starting the autonomous conversions fails, does this leave the hardware interrupt enabled?

The MAX30210_STATUS_A_FULL_MASK interrupt is enabled earlier in this function, but early error returns do not revert it. The IIO core aborts the setup and will not call max30210_buffer_postdisable(), which could lead to an unhandled interrupt storm.

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+
+static int max30210_buffer_postdisable(struct iio_dev *indio_dev)
+{
+	struct max30210_state *st = iio_priv(indio_dev);
+	int ret;
+
+	ret = max30210_autoconv_put(st);
+	if (ret)
+		return ret;
+

drivers/iio/temperature/max30210.c line 613

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+	/* Flush FIFO */
+	ret = regmap_set_bits(st->regmap, MAX30210_FIFO_CONF_2_REG,
+			      MAX30210_FIFOCONF2_FLUSH_FIFO);
+	if (ret)
+		return ret;
+
+	/* Disable FIFO-full interrupt */
+	return regmap_clear_bits(st->regmap, MAX30210_INT_EN_REG,
+				 MAX30210_STATUS_A_FULL_MASK);
+}

[Severity: Medium]
Similarly, if max30210_autoconv_put() or the FIFO flush fails here, this aborts early and skips disabling the FIFO-full interrupt. Could this leave the hardware asserting the interrupt line while the software considers the buffer disabled?

[ ... ]

Quoted 21 lines
drivers/iio/temperature/max30210.c new file +21 -0
+static int max30210_setup(struct max30210_state *st, struct device *dev)
+{
+	struct gpio_desc *powerdown_gpio;
+	unsigned int val;
+	int ret;
+
+	powerdown_gpio = devm_gpiod_get_optional(dev, "powerdown",
+						 GPIOD_OUT_HIGH);
+	if (IS_ERR(powerdown_gpio))
+		return dev_err_probe(dev, PTR_ERR(powerdown_gpio),
+				     "failed to request powerdown GPIO\n");
+
+	if (powerdown_gpio) {
+		/* Deassert powerdown to power up device */
+		gpiod_set_value(powerdown_gpio, 0);
+
+		ret = devm_add_action_or_reset(dev, max30210_powerdown, powerdown_gpio);
+		if (ret)
+			return ret;
+	} else {
+		ret = regmap_set_bits(st->regmap, MAX30210_SYS_CONF_REG,

drivers/iio/temperature/max30210.c line 698

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+				      MAX30210_SYSCONF_RESET);
+		if (ret)
+			return ret;
+	}
+
+	/*
+	 * Datasheet Figure 6:
+	 * tPU max = 700 µs after power-up or reset before device is ready.
+	 */
+	fsleep(700);

[Severity: Medium]
Is a delay required before issuing this initial software reset over I2C?

During probe, devm_regulator_get_enable() enables the vdd regulator. Immediately after, max30210_setup() attempts to issue a software reset via regmap_set_bits(). The datasheet states tPU max = 700 us after power-up or reset before the device is ready.

The driver correctly implements the delay after the reset, but appears to miss the required 700 us sleep before the reset following a cold power-up via the regulator. This might cause the initial I2C transaction to fail with a NACK.

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

Re: [PATCH v4 2/2] iio: temperature: add support for Analog Devices MAX30210

In reply to John Erasmus Mari Geronimo
Quoted 12 lines · On Thu, 15 Oct 2026 09:21:59 +0800 John Erasmus Mari Geronimo…

Add support for the Analog Devices MAX30210 I2C temperature sensor.

The driver uses regmap for register access and integrates with the IIO framework. It supports:

- Direct mode temperature conversion
- Configurable sampling frequency
- Threshold events
- FIFO operation with IIO kfifo buffer support
- Optional interrupt-driven data ready signaling

Quoted 5 lines

The device provides 16-bit signed temperature data and a 64-sample FIFO.

---

Hi, quick review from me. Please also check out Sashiko's remarks:

https://sashiko.dev/#/patchset/20261015012159.44-1-johnerasmusmari.geronimo%40analog.com

Josh

drivers/iio/temperature/max30210.c line 5

Quoted 5 lines
drivers/iio/temperature/max30210.c new file +5 -0
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Analog Devices MAX30210 I2C Temperature Sensor driver
+ *
+ * Copyright 2026 Analog Devices Inc.

Adding a link to the datasheet here would be good.

drivers/iio/temperature/max30210.c line 18

Quoted 13 lines

+ */

drivers/iio/temperature/max30210.c new file +12 -0
+
+#include <linux/array_size.h>
+#include <linux/bitfield.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/events.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/kfifo_buf.h>
+#include <linux/iio/sysfs.h>

Please separate the <linux/iio/*> specific headers from the generic linux headers.

drivers/iio/temperature/max30210.c line 25

Quoted 7 lines
drivers/iio/temperature/max30210.c new file +7 -0
+#include <linux/mutex.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/time.h>
+#include <linux/types.h>
+#include <linux/unaligned.h>
+#include <linux/units.h>

Missing cleanup.h, sysfs.h and asm/byteorder.h.

Quoted 49 lines
drivers/iio/temperature/max30210.c new file +49 -0
+
+#define MAX30210_STATUS_REG			0x00
+#define   MAX30210_STATUS_A_FULL_MASK		BIT(7)
+#define   MAX30210_STATUS_TEMP_RDY_MASK	BIT(6)
+#define   MAX30210_STATUS_TEMP_DEC_MASK	BIT(5)
+#define   MAX30210_STATUS_TEMP_INC_MASK	BIT(4)
+#define   MAX30210_STATUS_TEMP_LO_MASK		BIT(3)
+#define   MAX30210_STATUS_TEMP_HI_MASK		BIT(2)
+#define   MAX30210_STATUS_PWR_RDY		BIT(0)
+#define MAX30210_INT_EN_REG			0x02
+#define MAX30210_FIFO_DATA_REG			0x08
+#define MAX30210_FIFO_CONF_1_REG		0x09
+#define   MAX30210_FIFOCONF1_A_FULL_MASK	GENMASK(5, 0)
+#define MAX30210_FIFO_CONF_2_REG		0x0A
+#define   MAX30210_FIFOCONF2_FLUSH_FIFO		BIT(4)
+#define MAX30210_SYS_CONF_REG			0x11
+#define   MAX30210_SYSCONF_RESET		BIT(0)
+#define MAX30210_PIN_CONF_REG			0x12
+#define   MAX30210_PINCONF_EXT_CNV_EN		BIT(7)
+#define   MAX30210_PINCONF_EXT_CVT_ICFG		BIT(6)
+#define   MAX30210_PINCONF_INT_FCFG_MASK	GENMASK(3, 2)
+#define   MAX30210_PINCONF_INT_OCFG_MASK	GENMASK(1, 0)
+#define MAX30210_TEMP_ALM_HI_REG		0x22
+#define MAX30210_TEMP_ALM_LO_REG		0x24
+#define MAX30210_TEMP_INC_THRESH_REG		0x26
+#define MAX30210_TEMP_DEC_THRESH_REG		0x27
+#define MAX30210_TEMP_CONF_1_REG		0x28
+#define   MAX30210_TEMPCONF1_CHG_DET_EN		BIT(3)
+#define   MAX30210_TEMPCONF1_RATE_CHG_FILTER_MASK	GENMASK(2, 0)
+#define MAX30210_TEMP_CONF_2_REG		0x29
+#define   MAX30210_TEMPCONF2_TEMP_PERIOD_MASK	GENMASK(3, 0)
+#define   MAX30210_TEMPCONF2_ALERT_MODE		BIT(7)
+#define MAX30210_TEMP_CONV_REG			0x2A
+#define   MAX30210_TEMPCONV_CONV_T		BIT(0)
+#define   MAX30210_TEMPCONV_AUTO		BIT(1)
+#define MAX30210_TEMP_DATA_REG			0x2B
+#define MAX30210_TEMP_SLOPE_REG			0x2D
+#define MAX30210_UNIQUE_ID_REG			0x30
+#define MAX30210_PART_ID_REG			0xFF
+
+#define MAX30210_PART_ID			0x45
+#define MAX30210_FIFO_SIZE			64
+#define MAX30210_FIFO_BYTES_PER_SAMPLE		3
+#define MAX30210_FIFO_TEMP_MASK			GENMASK(15, 0)
+#define MAX30210_FIFO_INVAL_DATA		GENMASK(23, 0)
+#define MAX30210_WATERMARK_DEFAULT		(0x40 - 0x1F)
+
+#define MAX30210_UNIQUE_ID_LEN			6
+#define MAX30210_EXT_CVT_FREQ_MIN		1

drivers/iio/temperature/max30210.c line 84

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+#define MAX30210_EXT_CVT_FREQ_MAX		20
+
+struct max30210_state {
+	struct regmap *regmap;
+	/* Raw FIFO byte buffer */
+	u8 fifo_buf[MAX30210_FIFO_BYTES_PER_SAMPLE * MAX30210_FIFO_SIZE];
+	/* Protects autoconv_users and the autonomous-conversion enable bit */
+	struct mutex lock;
+	unsigned int autoconv_users;
+	u8 watermark;

Does pahole agree with this layout?

Quoted 15 lines
drivers/iio/temperature/max30210.c new file +15 -0
+};
+
+static const int max30210_samp_freq_avail[][2] = {
+	{ 0, 15625 },
+	{ 0, 31250 },
+	{ 0, 62500 },
+	{ 0, 125000 },
+	{ 0, 250000 },
+	{ 0, 500000 },
+	{ 1, 0 },
+	{ 2, 0 },
+	{ 4, 0 },
+	{ 8, 0 },
+};
+

...

drivers/iio/temperature/max30210.c line 401

Quoted 2 lines
drivers/iio/temperature/max30210.c new file +2 -0
+static int max30210_read_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan, int *val,

Small nit, but ideally have val, val2 and mask on the same line for readability reasons. This goes for all instances of this in the driver.

Quoted 33 lines
drivers/iio/temperature/max30210.c new file +33 -0
+			     int *val2, long mask)
+{
+	struct max30210_state *st = iio_priv(indio_dev);
+	unsigned int uval;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		*val = 5;
+		*val2 = MILLI;
+
+		return IIO_VAL_FRACTIONAL;
+	case IIO_CHAN_INFO_SAMP_FREQ: {
+		unsigned int period;
+
+		ret = regmap_read(st->regmap, MAX30210_TEMP_CONF_2_REG, &uval);
+		if (ret)
+			return ret;
+
+		period = FIELD_GET(MAX30210_TEMPCONF2_TEMP_PERIOD_MASK, uval);
+
+		/*
+		 * TEMP_PERIOD is an index into the sampling frequency lookup
+		 * table. Clamp in case the register holds a reserved value.
+		 */
+		if (period >= ARRAY_SIZE(max30210_samp_freq_avail))
+			period = ARRAY_SIZE(max30210_samp_freq_avail) - 1;
+
+		*val = max30210_samp_freq_avail[period][0];
+		*val2 = max30210_samp_freq_avail[period][1];
+
+		return IIO_VAL_INT_PLUS_MICRO;
+	}

...

Quoted 4 lines
drivers/iio/temperature/max30210.c new file +4 -0
+
+static int max30210_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;

drivers/iio/temperature/max30210.c line 716

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+	struct iio_dev *indio_dev;
+	struct max30210_state *st;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+	mutex_init(&st->lock);

devm_mutex_init() + check return value.

Quoted 39 lines
drivers/iio/temperature/max30210.c new file +39 -0
+
+	ret = devm_regulator_get_enable(dev, "vdd");
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to enable vdd regulator.\n");
+
+	st->regmap = devm_regmap_init_i2c(client, &max30210_regmap);
+	if (IS_ERR(st->regmap))
+		return dev_err_probe(dev, PTR_ERR(st->regmap),
+				     "Failed to allocate regmap.\n");
+
+	st->watermark = MAX30210_WATERMARK_DEFAULT;
+
+	ret = max30210_setup(st, dev);
+	if (ret)
+		return ret;
+
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = &max30210_channel;
+	indio_dev->num_channels = 1;
+	indio_dev->name = "max30210";
+	indio_dev->info = &max30210_info;
+
+	/* Without an interrupt there is no way to drain the FIFO into the buffer */
+	if (client->irq) {
+		ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev, &max30210_buffer_ops,
+						      max30210_fifo_attributes);
+		if (ret)
+			return ret;
+	}
+
+	ret = devm_iio_device_register(dev, indio_dev);
+	if (ret)
+		return ret;
+
+	if (!client->irq)
+		return 0;
+
+	/*

drivers/iio/temperature/max30210.c line 765

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+	 * Request the IRQ after registering the IIO device so devm tears it
+	 * down first on removal, before the event interface is freed.
+	 */
+	return devm_request_threaded_irq(dev, client->irq, NULL,
+					 max30210_irq_handler, IRQF_ONESHOT,
+					 indio_dev->name, indio_dev);
+}
+
+static const struct i2c_device_id max30210_id[] = {
+	{ "max30210" },

C99 initializers please.

Signature · 2 lines
Kind regards,
Joshua Crofts
maintainer
#6 lore raw

Re: [PATCH v4 2/2] iio: temperature: add support for Analog Devices MAX30210

In reply to John Erasmus Mari Geronimo
Quoted 12 lines · On Thu, 15 Oct 2026 09:21:59 +0800 John Erasmus Mari Geronimo…

Add support for the Analog Devices MAX30210 I2C temperature sensor.

The driver uses regmap for register access and integrates with the IIO framework. It supports:

- Direct mode temperature conversion
- Configurable sampling frequency
- Threshold events
- FIFO operation with IIO kfifo buffer support
- Optional interrupt-driven data ready signaling

Quoted 4 lines

The device provides 16-bit signed temperature data and a 64-sample FIFO.

Josh already pointed out the sashiko feedback so I'll just assume you'll either fix that or reply with why you disagree.

This is showing up just how bad our event handling infrastructure is wrt to lifetimes. Anyhow, I took a look at that and think the right solution is to just not worry so much about a bit of expansion in struct iio_dev_opaque and just always embed the iio_event_interface.

That way we need much simpler ordering guarantee that interrupts are disable before the iio_dev is freed. That should always be the case.

Jonathan

Quoted 8 lines
drivers/iio/temperature/max30210.c new file +1 -0
new file mode 100644
index 0000000000000..04123d51c6da4
@@ -0,0 +1,788 @@
 
+

drivers/iio/temperature/max30210.c

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+/* Keeps the device sampling autonomously while buffer and/or events need it. */
+static int max30210_autoconv_get(struct max30210_state *st)
+{
+	int ret = 0;
+
+	guard(mutex)(&st->lock);
+
+	if (st->autoconv_users == 0)
+		ret = regmap_write(st->regmap, MAX30210_TEMP_CONV_REG,
+				   MAX30210_TEMPCONV_AUTO | MAX30210_TEMPCONV_CONV_T);

Errors out of line where ever possible.

	if (ret)
		return ret;

	st->autconv_users++;

	return 0;

Though note sashiko raised some concerns around this. I haven't looked closely at whether it is right that you can increment this for ever.

Quoted 15 lines
drivers/iio/temperature/max30210.c new file +14 -0
+	if (!ret)
+		st->autoconv_users++;
+
+	return ret;
+}
 
+
+static irqreturn_t max30210_irq_handler(int irq, void *dev_id)
+{
+	struct iio_dev *indio_dev = dev_id;
+	struct max30210_state *st = iio_priv(indio_dev);
+	unsigned int status;
+	int ret;
+
+	ret = regmap_read(st->regmap, MAX30210_STATUS_REG, &status);

drivers/iio/temperature/max30210.c

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+	if (ret) {
+		dev_err(&indio_dev->dev, "Status read failed\n");
+		return IRQ_NONE;
+	}
+
+	if (status & MAX30210_STATUS_A_FULL_MASK)
+		max30210_fifo_read(indio_dev);
+
+	if (status & MAX30210_STATUS_TEMP_HI_MASK)
+		iio_push_event(indio_dev,

So it's this call I assume is the root of the issue with events due to interrupts in the tear down path.

I think we need to fix the core lifetime issue rather than making it a driver problem to paper over it. Note however that drivers should still be doing what ever is necessary to disable interrupts at source. Sometimes that happens naturally due to power down. Other times you have to register specific cleanup routines to do that.

I'm not sure which is true here.

Quoted 36 lines
drivers/iio/temperature/max30210.c new file +34 -0
+			       IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_RISING),
+			       iio_get_time_ns(indio_dev));
+
+	if (status & MAX30210_STATUS_TEMP_LO_MASK)
+		iio_push_event(indio_dev,
+			       IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
+						    IIO_EV_TYPE_THRESH,
+						    IIO_EV_DIR_FALLING),
+			       iio_get_time_ns(indio_dev));
+
+	return IRQ_HANDLED;
+}
 
 
+
+static int max30210_read_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan, int *val,
+			     int *val2, long mask)
+{
+	struct max30210_state *st = iio_priv(indio_dev);
+	unsigned int uval;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		*val = 5;
+		*val2 = MILLI;
+
+		return IIO_VAL_FRACTIONAL;
+	case IIO_CHAN_INFO_SAMP_FREQ: {
+		unsigned int period;
+
+		ret = regmap_read(st->regmap, MAX30210_TEMP_CONF_2_REG, &uval);
+		if (ret)

drivers/iio/temperature/max30210.c

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+			return ret;
+
+		period = FIELD_GET(MAX30210_TEMPCONF2_TEMP_PERIOD_MASK, uval);
+
+		/*
+		 * TEMP_PERIOD is an index into the sampling frequency lookup
+		 * table. Clamp in case the register holds a reserved value.
+		 */
+		if (period >= ARRAY_SIZE(max30210_samp_freq_avail))
+			period = ARRAY_SIZE(max30210_samp_freq_avail) - 1;
		period = min(period, ARRAY_SIZE(max30210_samp_freq_avail) - 1);
Quoted 56 lines
drivers/iio/temperature/max30210.c new file +55 -0
+
+		*val = max30210_samp_freq_avail[period][0];
+		*val2 = max30210_samp_freq_avail[period][1];
+
+		return IIO_VAL_INT_PLUS_MICRO;
+	}
+	case IIO_CHAN_INFO_RAW: {
+		IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
+		if (IIO_DEV_ACQUIRE_FAILED(claim))
+			return -EBUSY;
+
+		guard(mutex)(&st->lock);
+
+		/*
+		 * TEMP_DATA_REG is only refreshed by a single-shot
+		 * conversion; the buffer/FIFO path is the only thing that
+		 * gets updated during AUTO mode. If AUTO is already running
+		 * for the buffer and/or events, triggering a one-off
+		 * conversion here would stomp the AUTO bit out from under
+		 * whoever enabled it, and there is no way to get a fresh
+		 * single-shot value without doing so -- refuse instead of
+		 * returning stale data.
+		 */
+		if (st->autoconv_users > 0)
+			return -EBUSY;
+
+		ret = regmap_write(st->regmap, MAX30210_TEMP_CONV_REG,
+				   MAX30210_TEMPCONV_CONV_T);
+		if (ret)
+			return ret;
+
+		/*
+		 * Wait until CONVERT_T auto-clears.
+		 * Datasheet:
+		 *   tBIAS_WU = 260 µs
+		 *   tINT     = 8 ms
+		 *
+		 * Worst-case conversion ≈ 8.26 ms.
+		 * Use 10 ms timeout for margin.
+		 */
+		ret = regmap_read_poll_timeout(st->regmap, MAX30210_TEMP_CONV_REG, uval,
+					       !(uval & MAX30210_TEMPCONV_CONV_T),
+					       500, 10 * USEC_PER_MSEC);
+		if (ret)
+			return ret;
+
+		return max30210_read_temp(st->regmap, MAX30210_TEMP_DATA_REG, val);
+	}
+	default:
+		return -EINVAL;
+	}
+}
 
+static int max30210_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;

drivers/iio/temperature/max30210.c

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+	struct iio_dev *indio_dev;
+	struct max30210_state *st;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+	mutex_init(&st->lock);

For a modern driver we pretty much always do

	ret = devm_mutex_init(dev, &st->lock);
	if (ret)
		return ret;

It only brings a bit of extra lock debug but it's simple so why not.

Quoted 14 lines
drivers/iio/temperature/max30210.c new file +14 -0
+
+	ret = devm_regulator_get_enable(dev, "vdd");
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to enable vdd regulator.\n");
+
+	st->regmap = devm_regmap_init_i2c(client, &max30210_regmap);
+	if (IS_ERR(st->regmap))
+		return dev_err_probe(dev, PTR_ERR(st->regmap),
+				     "Failed to allocate regmap.\n");
+
+	st->watermark = MAX30210_WATERMARK_DEFAULT;
+
+	ret = max30210_setup(st, dev);

drivers/iio/temperature/max30210.c

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+	if (ret)
+		return ret;
+
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = &max30210_channel;
+	indio_dev->num_channels = 1;
+	indio_dev->name = "max30210";
+	indio_dev->info = &max30210_info;
+
+	/* Without an interrupt there is no way to drain the FIFO into the buffer */

Maybe stick "currently" in that statement given you can just poll.

Quoted 7 lines
drivers/iio/temperature/max30210.c new file +7 -0
+	if (client->irq) {
+		ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev, &max30210_buffer_ops,
+						      max30210_fifo_attributes);
+		if (ret)
+			return ret;
+	}
+

drivers/iio/temperature/max30210.c

Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10 -0
+	ret = devm_iio_device_register(dev, indio_dev);
+	if (ret)
+		return ret;
+
+	if (!client->irq)
+		return 0;
+
+	/*
+	 * Request the IRQ after registering the IIO device so devm tears it
+	 * down first on removal, before the event interface is freed.

Ok. I can see the logic in this, but I'm not particularly keen on the position where we have a device up with exposed interfaces, some of which would expect to generate interrupts, but we don't have interrupt support.

I think it is worth looking at whether we can solve this cleanly in the IIO core. As you observe, the issue is that event_interface is allocated and freed as part of the device_register() on basis we don't need it if there are no events. That smells to me like a design error (mine
long ago!). Maybe we should just make it a part of the iio_dev_opaque?
Small amount of bloat as a result but it isn't huge.

That way, it's lifetime matches the device and it will
be around much longer. Once that is true we can add a flag that indicates the device is being torn down and short cut dropping events (as by definition they aren't going anywhere) but not worry if we race because it should be harmless to carry on using the event interface.

We can't use the info_exist_lock here as the events might be pushed from an interrupt so fixing this up in similar fashion to the buffer state management doesn't work.

Note drivers should still be disabling their interrupts at source even if becomes safer to not do so.

I hacked something up to get an idea of how bad this would be to actually do. The header dependencies will require yet another header which is a bit annoying but such is life. This is build tested only. If you want to
give it a spin that would be great. The new header naming needs some more thought. At somepoint I should also fix up that iio_opaque is currently extremely ordering dependent as it doesn't include headers needed for the stuff it defines. That was kind of intentional but now perhaps we need to rethink.

From 6c3ac6b288db7d5840298649d34bf289be2a5a74 Mon Sep 17 00:00:00 2001
From: Jonathan Cameron <[email protected]>
Date: Sat, 17 Oct 2026 22:52:57 +0100
Subject: [PATCH] TEMP HACK

Stop allocating the event_interface independently of the device as it makes for some annoying lifetime issues.

Note that until someone actually attaches to the kfifo no events get stored anyway.

---
 drivers/iio/iio_core.h           |  8 ++---
 drivers/iio/industrialio-core.c  | 11 +++---
 drivers/iio/industrialio-event.c | 57 ++++++++------------------------
 drivers/iio/inkern.c             |  2 ++
 include/linux/iio/iio-opaque.h   | 28 +++++++++++++++-
 include/linux/iio/iio-types.h    | 14 ++++++++
 6 files changed, 65 insertions(+), 55 deletions(-)
drivers/iio/iio_core.h +3 -5
index 59fa1bd9924b..92fa47f74393 100644
@@ -12,6 +12,8 @@
 #include <linux/kernel.h>
 #include <linux/device.h>
 
+#include <linux/iio/iio-types.h>
+
 struct iio_buffer;
 struct iio_chan_spec;
 struct iio_dev;
@@ -24,11 +26,6 @@ struct iio_dev_buffer_pair {
 };
 
 #define IIO_IOCTL_UNHANDLED	1
-struct iio_ioctl_handler {
-	struct list_head entry;
-	long (*ioctl)(struct iio_dev *indio_dev, struct file *filp,
-		      unsigned int cmd, unsigned long arg);
-};
 
 void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
 				       struct iio_ioctl_handler *h);
@@ -61,6 +58,7 @@ ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals);
 
 /* Event interface flags */
 #define IIO_BUSY_BIT_POS 1
+#define IIO_EVENTS_PRESENT 2
 
 #ifdef CONFIG_IIO_BUFFER
 struct poll_table_struct;
drivers/iio/industrialio-core.c +5 -6
index d73f2541375f..e109bc190716 100644
@@ -345,13 +345,12 @@ int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
 {
 	int ret;
 	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
-	const struct iio_event_interface *ev_int = iio_dev_opaque->event_interface;
+	const struct iio_event_interface *ev_int = &iio_dev_opaque->event_interface;
 
 	ret = mutex_lock_interruptible(&iio_dev_opaque->mlock);
 	if (ret)
 		return ret;
-	if ((ev_int && iio_event_enabled(ev_int)) ||
-	    iio_buffer_enabled(indio_dev)) {
+	if (iio_event_enabled(ev_int) || iio_buffer_enabled(indio_dev)) {
 		mutex_unlock(&iio_dev_opaque->mlock);
 		return -EBUSY;
 	}
@@ -1640,7 +1639,7 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
 			attrcount += ret;
 		}
 
-	if (iio_dev_opaque->event_interface)
+	if (test_bit(IIO_EVENTS_PRESENT, &iio_dev_opaque->event_interface.flags))
 		clk = &dev_attr_current_timestamp_clock.attr;
 
 	if (indio_dev->name)
@@ -2165,10 +2164,10 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
 
 	if (iio_dev_opaque->attached_buffers_cnt)
 		cdev_init(&iio_dev_opaque->chrdev, &iio_buffer_fileops);
-	else if (iio_dev_opaque->event_interface)
+	else if (test_bit(IIO_EVENTS_PRESENT, &iio_dev_opaque->event_interface.flags))
 		cdev_init(&iio_dev_opaque->chrdev, &iio_event_fileops);
 
-	if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) {
+	if (iio_dev_opaque->attached_buffers_cnt || test_bit(IIO_EVENTS_PRESENT, &iio_dev_opaque->event_interface.flags)) {
 		indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id);
 		iio_dev_opaque->chrdev.owner = this_mod;
 	}
drivers/iio/industrialio-event.c +14 -43

146 lines not on this page · raw message

drivers/iio/inkern.c +2 -0
index 1f22275de55c..a97fb9aded8e 100644
@@ -14,6 +14,8 @@
 #include <linux/units.h>
 
 #include <linux/iio/iio.h>
+#include <linux/iio/events.h>
+/* ordering matters */
 #include <linux/iio/iio-opaque.h>
 #include "iio_core.h"
 #include <linux/iio/machine.h>
include/linux/iio/iio-opaque.h +27 -1
index 98330385e08d..91934621326b 100644
@@ -3,6 +3,32 @@
 #ifndef _INDUSTRIAL_IO_OPAQUE_H_
 #define _INDUSTRIAL_IO_OPAQUE_H_
 
+
+#include <linux/kfifo.h>
+#include <linux/iio/iio-types.h>
+#include <linux/iio/events.h>
+
+/**
+ * struct iio_event_interface - chrdev interface for an event line
+ * @wait:		wait queue to allow blocking reads of events
+ * @det_events:		list of detected events
+ * @dev_attr_list:	list of event interface sysfs attribute
+ * @flags:		file operations related flags including busy flag.
+ * @group:		event interface sysfs attribute group
+ * @read_lock:		lock to protect kfifo read operations
+ * @ioctl_handler:	handler for event ioctl() calls
+ */
+struct iio_event_interface {
+	wait_queue_head_t	wait;
+	DECLARE_KFIFO(det_events, struct iio_event_data, 16);
+
+	struct list_head	dev_attr_list;
+	unsigned long		flags;
+	struct attribute_group	group;
+	struct mutex		read_lock;
+	struct iio_ioctl_handler	ioctl_handler;
+};
+
 /**
  * struct iio_dev_opaque - industrial I/O device opaque information
  * @indio_dev:			public industrial I/O device information
@@ -42,6 +68,7 @@
  */
 struct iio_dev_opaque {
 	struct iio_dev			indio_dev;
+	struct iio_event_interface	event_interface;
 	int				currentmode;
 	int				id;
 	struct module			*driver_module;
@@ -50,7 +77,6 @@ struct iio_dev_opaque {
 	struct mutex			info_exist_lock;
 	struct lock_class_key		info_exist_key;
 	bool				trig_readonly;
-	struct iio_event_interface	*event_interface;
 	struct iio_buffer		**attached_buffers;
 	unsigned int			attached_buffers_cnt;
 	struct iio_ioctl_handler	*buffer_ioctl_handler;
include/linux/iio/iio-types.h new file +14 -0
new file mode 100644
index 000000000000..b18a1f29a936
@@ -0,0 +1,14 @@
+#ifndef _IIO_INTERNAL_TYPES_H_
+#define  _IIO_INTERNAL_TYPES_H_
+#include <linux/list.h>
+
+struct iio_dev;
+struct file;
+
+struct iio_ioctl_handler {
+	struct list_head entry;
+	long (*ioctl)(struct iio_dev *indio_dev, struct file *filp,
+		      unsigned int cmd, unsigned long arg);
+};
+
+#endif /* _IIO_INTERNAL_TYPES_H_ */
Signature · 1 line
2.56.0
Quoted 5 lines
drivers/iio/temperature/max30210.c new file +5 -0
+	 */
+	return devm_request_threaded_irq(dev, client->irq, NULL,
+					 max30210_irq_handler, IRQF_ONESHOT,
+					 indio_dev->name, indio_dev);
+}
#7 lore raw
In reply to John Erasmus Mari Geronimo
Quoted 21 lines · On Thu, 15 Oct 2026 09:21:57 +0800 John Erasmus Mari Geronimo…

This series adds support for the Analog Devices MAX30210 I2C temperature sensor.

The device provides a 16-bit temperature output and includes features such as a hardware FIFO, programmable sampling rate, threshold alarms, and interrupt support. These capabilities map naturally to the IIO subsystem, particularly the buffered interface and event framework -- hwmon has no equivalent buffered-capture framework, and its alarm attributes are polled rather than interrupt-driven, so there is no path to supporting the FIFO or the autonomous threshold comparators there.

Although the MAX30210 belongs to the same device family as the MAX30208, it is implemented as a separate driver. The MAX30210 has a significantly different feature set, including a 64-sample hardware FIFO with configurable watermark interrupts, programmable sampling rates, and event support. These features require buffered operation and IRQ-driven data handling which are not present in the MAX30208 driver (which talks to the device directly via i2c_smbus_*() calls with no regmap, and has no IIO buffer or event interface at all).

Quoted 8 lines

In addition, the MAX30210 uses a different register map and a more flexible I2C address selection scheme. Supporting both devices in a single driver would introduce substantial conditional logic, so a separate driver keeps the implementation simpler and easier to maintain.

Patch 1 adds the devicetree binding.
Patch 2 adds the IIO driver implementation.

Please send a link to the datasheet next time, it saves time and at least we know which version to base reviews on.

I believe Andy also asked to to add a Datasheet tag to the commits.

Q to others: should we try to make the Datasheet tag official?

Signature · 2 lines
Kind regards,
Joshua Crofts
maintainer
#8 lore raw
In reply to John Erasmus Mari Geronimo
Quoted 12 lines · On Thu, 15 Oct 2026 09:21:57 +0800 John Erasmus Mari Geronimo…

This series adds support for the Analog Devices MAX30210 I2C temperature sensor.

The device provides a 16-bit temperature output and includes features such as a hardware FIFO, programmable sampling rate, threshold alarms, and interrupt support. These capabilities map naturally to the IIO subsystem, particularly the buffered interface and event framework -- hwmon has no equivalent buffered-capture framework, and its alarm attributes are polled rather than interrupt-driven, so there is no path to supporting the FIFO or the autonomous threshold comparators there.

Thanks for the explanation. Just to make sure
+CC Guenter and hwmon list.

Quoted 69 lines

Although the MAX30210 belongs to the same device family as the MAX30208, it is implemented as a separate driver. The MAX30210 has a significantly different feature set, including a 64-sample hardware FIFO with configurable watermark interrupts, programmable sampling rates, and event support. These features require buffered operation and IRQ-driven data handling which are not present in the MAX30208 driver (which talks to the device directly via i2c_smbus_*() calls with no regmap, and has no IIO buffer or event interface at all).

In addition, the MAX30210 uses a different register map and a more flexible I2C address selection scheme. Supporting both devices in a single driver would introduce substantial conditional logic, so a separate driver keeps the implementation simpler and easier to maintain.

Patch 1 adds the devicetree binding.
Patch 2 adds the IIO driver implementation.

Changes since v3:
https://lore.kernel.org/all/[email protected]/
- regmap_noinc_read() for FIFO reads instead of regmap_bulk_read(), which (combined with regmap caching) could silently return stale cached values of unrelated registers instead of real FIFO data.
- Mark both bytes of TEMP_DATA_REG volatile for the same reason.
- Decouple threshold events from the buffer via a refcounted autoconv_get()/autoconv_put() pair, so either can be used independently or concurrently.
- Don't let a single-shot direct-mode read race with/clobber autonomous conversion mode if a threshold event or the buffer is already using it -- return -EBUSY instead.
- Don't hard-fail probe when there is no interrupt; fall back to direct-mode-only operation.
- Fix devm teardown ordering so an in-flight interrupt can't use a freed event interface on removal.
- Re-assert the powerdown GPIO on removal so the device reaches standby instead of staying powered indefinitely.
- Style/API fixes from review (register/field grouping, _MASK naming, FIELD_PREP/regmap_assign_bits usage, C99 initializers, dropped redundant i2c_check_functionality() check, comment cleanup).

All of the above have been verified on real MAX30210 hardware (Raspberry Pi 4 test rig), including the no-IRQ fallback, buffer and event refcounting (independently and concurrently), rmmod/insmod under live interrupts, powerdown GPIO assertion on removal, and FIFO flush correctness.

Changes since v2:
https://lore.kernel.org/all/[email protected]/
- Fix FIFO byte-count handling and sample decoding.
- Fix IIO debug register read/write access.
- Validate event threshold values and sampling-frequency register values.
- Return the correct sampling-frequency format and reject direct reads while buffered capture is enabled.
- Clean up the Kconfig entry and device-tree supply declaration.

John Erasmus Mari Geronimo (2):
dt-bindings: iio: temperature: add ADI MAX30210
iio: temperature: add support for Analog Devices MAX30210

 .../iio/temperature/adi,max30210.yaml         |  61 ++
 MAINTAINERS                                   |   8 +
 drivers/iio/temperature/Kconfig               |  13 +
 drivers/iio/temperature/Makefile              |   1 +
 drivers/iio/temperature/max30210.c            | 788 ++++++++++++++++++
 5 files changed, 871 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/temperature/adi,max30210.yaml
 create mode 100644 drivers/iio/temperature/max30210.c