Add support for Analog Devices MAX30210
Subsystems (4)
v6 cover Add support for Analog Devices MAX30210
This series adds support for the Analog Devices MAX30210 I2C temperature sensor.
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/max30210.pdf
The device provides a 16-bit temperature output and includes features such as a hardware FIFO, programmable sampling rate, threshold alarms, and interrupt support. The FIFO is exposed as an IIO buffered capture (kfifo buffer, fed from the FIFO watermark interrupt) and the threshold alarms as IIO events. As far as I can tell hwmon has no equivalent for streaming samples out of a hardware FIFO, and the related MAX30208 is an IIO driver as well.
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 v5:
https://lore.kernel.org/all/[email protected]/
- Fix the temperature scale: one LSB is 5 milli degrees Celsius, so report 5 (IIO_VAL_INT) instead of 5/1000.
- Mask the interrupt status with the enabled interrupts, so threshold events and the FIFO that are not enabled are not serviced.
- Start the FIFO interrupt and the autonomous conversion in postenable(), after the watermark has been set, and stop them in predisable() followed by synchronize_irq(). This also removes the goto from preenable(), which mixed a guard with a goto.
- Read STATUS before enabling the FIFO interrupt so a stale A_FULL flag does not fire on the freshly flushed FIFO.
- Clamp the hardware FIFO watermark to the FIFO size instead of failing.
- Mark SYS_CONF_REG volatile (its reset bit is self-clearing).
- Use gpiod_set_value_cansleep() for the powerdown GPIO.
- Keep the powerdown GPIO asserted for 10 us before deasserting it, the datasheet lists a CVT/PDB input low-pulse width of 5 us.
- Do not expose the threshold events when there is no interrupt.
- Review cleanups: check the event type first, use a local regmap variable, regmap_test_bits(), simpler set/clear handling in write_event_config(), a logical split of the poll call, and rename the sampling frequency index to freq_idx.
- Not changed: the interrupt is still requested after devm_iio_device_register(), because the event interface is freed in iio_device_unregister_eventset(), and autoconv_put() still drops its reference when the register write fails (a later direct read rewrites TEMP_CONV_REG without AUTO, which stops it).
- Cover letter: removed the incorrect statement about hwmon and interrupts, thanks to Guenter for pointing it out.
Tested on real MAX30210 hardware (Raspberry Pi 4) with a 6.12 based vendor kernel, which has no KASAN or lockdep; this version is only build-tested against mainline. What was run: the sysfs scale against the raw reading, FIFO streaming with a fresh first sample, the watermark clamp, threshold events with the buffer off, disabled events staying silent while the FIFO interrupt runs (checked against v5, which leaked them), 50 buffer enable/disable cycles, 80 rmmod/insmod cycles (20 with armed events and 60 timed to land within about 250 ms of live interrupt traffic), the no-interrupt and the no-powerdown-GPIO configurations, and the INT_EN/TEMP_CONV state the chip is left in after removal.
Changes since v4:
https://lore.kernel.org/all/[email protected]/
- Patch 1: restore Krzysztof's Reviewed-by, which was accidentally left out of v4.
- Add Datasheet: tags and a datasheet link in the driver header.
- Disable interrupt sources and autonomous conversion on removal, independently of whether a powerdown GPIO is present.
- Only take/release an autonomous-conversion reference when an interrupt enable bit really changes; repeated writes of the same value no longer leak a reference.
- buffer_preenable() now unwinds the A_FULL interrupt enable on failure and buffer_postdisable() always clears it.
- Return IRQ_NONE from the interrupt handler when none of the handled status bits is set.
- Wait tPU before the software reset when no powerdown GPIO is used.
- Minor review cleanups: error paths out of line in max30210_autoconv_get(), min() for the period clamp, devm_mutex_init(), designated initializer for i2c_device_id, header grouping, one-line val/val2/mask argument lists.
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).
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 | 853 ++++++++++++++++++ 5 files changed, 936 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
PATCH v6 1/2 dt-bindings: iio: temperature: add ADI MAX30210
Add device tree binding documentation for the Analog Devices MAX30210 temperature sensor.
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/max30210.pdf
--- .../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
@@ -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
@@ -1786,6 +1786,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
PATCH v6 2/2 iio: temperature: add support for Analog Devices MAX30210
In reply to John Erasmus Mari GeronimoAdd 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.
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/max30210.pdf
--- MAINTAINERS | 1 + drivers/iio/temperature/Kconfig | 13 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/max30210.c | 853 +++++++++++++++++++++++++++++ 4 files changed, 868 insertions(+) create mode 100644 drivers/iio/temperature/max30210.c
MAINTAINERS +1 -0
@@ -1792,6 +1792,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
@@ -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
@@ -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 +853 -0
853 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v6 2/2] iio: temperature: add support for Analog Devices MAX30210
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] iio: temperature: max30210: IRQ requested after devm_iio_device_register() - [Medium] iio…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] iio: temperature: max30210: IRQ requested after devm_iio_device_register()
- [Medium] iio: max30210: status bits discarded in max30210_buffer_postenable()
--
commit 421e9f8d7f502a8b5bdb83438a4e54f4019fbac4
Author: John Erasmus Mari Geronimo <[email protected]>
iio: temperature: add support for Analog Devices MAX30210
This commit adds an IIO driver for the Analog Devices MAX30210 I2C temperature sensor with support for direct reads, threshold events, and a hardware FIFO buffer.
Quoted 5 lines
drivers/iio/temperature/max30210.c new file +0
-0
[ ... ]
Quoted 13 lines
drivers/iio/temperature/max30210.c new file +13
-0+/* The core calls this after hwfifo_set_watermark(), so the watermark is stable here. */ +static int max30210_buffer_postenable (struct iio_dev *indio_dev) +{ +struct max30210_state *st =iio_priv (indio_dev); +unsigned int status; +int ret; + +guard (mutex)(&st->lock); + + ret =max30210_autoconv_get (st); +if (ret) +return ret; +
drivers/iio/temperature/max30210.c line 622
Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10
-0+/* Read STATUS to clear a stale A_FULL so it cannot fire on the flushed FIFO. */ + ret =regmap_read (st->regmap,MAX30210_STATUS_REG , &status); +if (!ret) + ret =regmap_set_bits (st->regmap,MAX30210_INT_EN_REG , +MAX30210_STATUS_A_FULL_MASK ); +if (ret) +max30210_autoconv_put (st); + +return ret; +}
[Severity: Medium]
Can reading and discarding MAX30210_STATUS_REG here drop pending temperature threshold events?
MAX30210_STATUS_REG is clear-on-read and shared with MAX30210_STATUS_TEMP_HI_MASK and MAX30210_STATUS_TEMP_LO_MASK. When threshold events are already enabled (st->autoconv_users > 0), reading MAX30210_STATUS_REG without reporting those bits clears any pending alarm in hardware and causes a concurrent max30210_irq_handler() to read 0 and return IRQ_NONE.
In addition, when st->autoconv_users == 0, calling max30210_autoconv_get() before reading MAX30210_STATUS_REG starts autonomous conversions before clearing the stale status byte.
[ ... ]
Quoted 5 lines
drivers/iio/temperature/max30210.c new file +5
-0+ ret =devm_iio_device_register (dev, indio_dev); +if (ret) +return ret; + +if (!client->irq)
drivers/iio/temperature/max30210.c line 827
Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10
-0+return 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); +}
[Severity: Medium]
As reported by Jonathan Cameron on v4 [1], does registering the IIO device before requesting client->irq expose the buffer and event interfaces before the interrupt handler is installed, and invert the teardown order on removal?
During probe, userspace can enable the buffer or threshold events (or disable the buffer and hit synchronize_irq(st->irq) in max30210_buffer_predisable()) before devm_request_threaded_irq() runs. On driver unbind, devres frees client->irq before devm_iio_device_unreg() runs iio_device_unregister() -> iio_disable_all_buffers() -> max30210_buffer_predisable(), which then calls synchronize_irq(st->irq) on the already-freed IRQ, and before max30210_quiesce() disables hardware interrupts.
The event interface is freed in iio_dev_release() (bound to devm_iio_device_alloc()) rather than iio_device_unregister(), so requesting the IRQ and registering max30210_quiesce() before devm_iio_device_register() still tears down the IRQ before the event interface is freed.
[1] https://lore.kernel.org/r/20261017230705.678a791c@jic23-hlaptop
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v6 2/2] iio: temperature: add support for Analog Devices MAX30210
In reply to John Erasmus Mari GeronimoQuoted 14 lines · 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 signalingThe device provides 16-bit signed temperature data and a 64-sample FIFO.
...
drivers/iio/temperature/max30210.c line 186
Quoted 1 line
drivers/iio/temperature/max30210.c new file +1
-0+/* Drop the reference even if the write fails; a later direct read clears AUTO anyway. */
It's a bit too long. Make it multi-line.
...
Quoted 9 lines
drivers/iio/temperature/max30210.c new file +9
-0+static void max30210_fifo_read (struct iio_dev *indio_dev) +{ +struct max30210_state *st =iio_priv (indio_dev); +int ret; + +/* +* FIFO_DATA_REG auto-increments in hardware; bulk_read would treat +* each subsequent byte as a separate cacheable register. +*/
drivers/iio/temperature/max30210.c line 213
Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10
-0+ ret =regmap_noinc_read (st->regmap,MAX30210_FIFO_DATA_REG , + st->fifo_buf, +MAX30210_FIFO_BYTES_PER_SAMPLE * st->watermark); +if (ret) { +dev_err (&indio_dev->dev,"Failed to read from fifo.\n" ); +return ; + } + +for (unsigned int i =0 ; i < st->watermark; i++) { +u32 raw =get_unaligned_be24 (&st->fifo_buf[MAX30210_FIFO_BYTES_PER_SAMPLE * i]);
unsigned int idx = MAX30210_FIFO_BYTES_PER_SAMPLE * i; u32 raw = get_unaligned_be24(&st->fifo_buf[idx]);
Quoted 12 lines
drivers/iio/temperature/max30210.c new file +12
-0+s16 temp; + +if (raw ==MAX30210_FIFO_INVAL_DATA ) { +dev_err_ratelimited (&indio_dev->dev,"Invalid data\n" ); +continue ; + } + + temp =sign_extend32 (FIELD_GET (MAX30210_FIFO_TEMP_MASK , raw),15 ); + +iio_push_to_buffers (indio_dev, &temp); + } +}
...
drivers/iio/temperature/max30210.c line 236
Quoted 10 lines
drivers/iio/temperature/max30210.c new file +10
-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, enabled; +int ret; + + ret =regmap_read (st->regmap,MAX30210_STATUS_REG , &status); +if (ret) { +dev_err (&indio_dev->dev,"Status read failed\n" );
It's always recommended to have the messages to be ratelimited in IRQ handler, that's in case of intermittent problems with reading this may flood the kernel log.
Quoted 35 lines
drivers/iio/temperature/max30210.c new file +35
-0+return IRQ_NONE ; + } + +/* STATUS flags are set whether or not they are enabled in INT_EN. */ + ret =regmap_read (st->regmap,MAX30210_INT_EN_REG , &enabled); +if (ret) { +dev_err (&indio_dev->dev,"Interrupt enable read failed\n" ); +return IRQ_NONE ; + } + + status &= enabled; +if (!(status & (MAX30210_STATUS_A_FULL_MASK | +MAX30210_STATUS_TEMP_HI_MASK | +MAX30210_STATUS_TEMP_LO_MASK ))) +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, +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 ; +}
...
drivers/iio/temperature/max30210.c line 519
Quoted 8 lines
drivers/iio/temperature/max30210.c new file +8
-0+static int max30210_write_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); + +switch (mask) { +case IIO_CHAN_INFO_SAMP_FREQ : {
struct regmap *map = st->regmap;
drivers/iio/temperature/max30210.c line 527
Quoted 8 lines
drivers/iio/temperature/max30210.c new file +8
-0+if (val <0 || val2 <0 ) +return -EINVAL ; + +IIO_DEV_ACQUIRE_DIRECT_MODE (indio_dev, claim); +if (IIO_DEV_ACQUIRE_FAILED (claim)) +return -EBUSY ; + +for (unsigned int i =0 ; i <ARRAY_SIZE (max30210_samp_freq_avail); i++) {
unsigned int mask = MAX30210_TEMPCONF2_TEMP_PERIOD_MASK; unsigned int value = field_prep(mask, i);
drivers/iio/temperature/max30210.c line 534
Quoted 7 lines
drivers/iio/temperature/max30210.c new file +7
-0+if (val != max30210_samp_freq_avail[i][0 ] || + val2 != max30210_samp_freq_avail[i][1 ]) +continue ; + +return regmap_update_bits (st->regmap,MAX30210_TEMP_CONF_2_REG , +MAX30210_TEMPCONF2_TEMP_PERIOD_MASK , +FIELD_PREP (MAX30210_TEMPCONF2_TEMP_PERIOD_MASK , i));
return regmap_update_bits(map, MAX30210_TEMP_CONF_2_REG, mask, value);
Quoted 8 lines
drivers/iio/temperature/max30210.c new file +8
-0+ } + +return -EINVAL ; + } +default : +return -EINVAL ; + } +}
...
drivers/iio/temperature/max30210.c line 552
Quoted 9 lines
drivers/iio/temperature/max30210.c new file +9
-0+static int max30210_set_watermark (struct iio_dev *indio_dev,unsigned int val) +{ +struct max30210_state *st =iio_priv (indio_dev); +int ret; + +if (!val) +return -EINVAL ; + + val =min (val,MAX30210_FIFO_SIZE );
I would put check here to make it look more natural.
val = min(val, MAX30210_FIFO_SIZE); if (!val) return -EINVAL;
Quoted 15 lines
drivers/iio/temperature/max30210.c new file +15
-0+/* +* FIFO_A_FULL sets the number of empty FIFO slots remaining when +* the A_FULL interrupt fires. For a watermark of N samples, set +* FIFO_A_FULL = FIFO_SIZE - N. +*/ + ret =regmap_write (st->regmap,MAX30210_FIFO_CONF_1_REG , +FIELD_PREP (MAX30210_FIFOCONF1_A_FULL_MASK , +MAX30210_FIFO_SIZE - val)); +if (ret) +return ret; + + st->watermark = val; + +return 0 ; +}
...
drivers/iio/temperature/max30210.c line 724
Quoted 13 lines
drivers/iio/temperature/max30210.c new file +13
-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) { +/* CVT/PDB needs a 5 us low pulse; hold it asserted for twice that. */
If I am not mistaken somewhere else you used Greek MU, why not here? Please, check the comments for the consistency.
Quoted 27 lines
drivers/iio/temperature/max30210.c new file +27
-0+fsleep (10 ); + +/* Deassert powerdown to power up device */ +gpiod_set_value_cansleep (powerdown_gpio,0 ); + + ret =devm_add_action_or_reset (dev, max30210_powerdown, powerdown_gpio); +if (ret) +return ret; + }else { +/* The supply was just enabled; the device needs tPU before it accepts I2C. */ +fsleep (700 ); + + ret =regmap_set_bits (st->regmap,MAX30210_SYS_CONF_REG , +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 ); + +/* Clear status byte */ +return regmap_read (st->regmap,MAX30210_STATUS_REG , &val); +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v6 2/2] iio: temperature: add support for Analog Devices MAX30210
Quoted 1 line · Andy Shevchenko
On Tue, Nov 10, 2026 at 10:14:42AM +0800, John Erasmus Mari Geronimo wrote:
...
Quoted 11 lines
drivers/iio/temperature/max30210.c line 519
Quoted 8 lines
drivers/iio/temperature/max30210.c new file +8
-0+static int max30210_write_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); + +switch (mask) { +case IIO_CHAN_INFO_SAMP_FREQ : {struct regmap *map = st->regmap;
Quoted 11 lines
drivers/iio/temperature/max30210.c line 527
Quoted 8 lines
drivers/iio/temperature/max30210.c new file +8
-0+if (val <0 || val2 <0 ) +return -EINVAL ; + +IIO_DEV_ACQUIRE_DIRECT_MODE (indio_dev, claim); +if (IIO_DEV_ACQUIRE_FAILED (claim)) +return -EBUSY ; + +for (unsigned int i =0 ; i <ARRAY_SIZE (max30210_samp_freq_avail); i++) {unsigned int mask = MAX30210_TEMPCONF2_TEMP_PERIOD_MASK; unsigned int value = field_prep(mask, i);
Ah, there is a conflict with above 'mask'. Something like 'm' and 'v' would fit?
Quoted 19 lines
drivers/iio/temperature/max30210.c line 534
Quoted 7 lines
drivers/iio/temperature/max30210.c new file +7
-0+if (val != max30210_samp_freq_avail[i][0 ] || + val2 != max30210_samp_freq_avail[i][1 ]) +continue ; + +return regmap_update_bits (st->regmap,MAX30210_TEMP_CONF_2_REG , +MAX30210_TEMPCONF2_TEMP_PERIOD_MASK , +FIELD_PREP (MAX30210_TEMPCONF2_TEMP_PERIOD_MASK , i));return regmap_update_bits(map, MAX30210_TEMP_CONF_2_REG, mask, value);Quoted 8 lines
drivers/iio/temperature/max30210.c new file +8
-0+ } + +return -EINVAL ; + } +default : +return -EINVAL ; + } +}
Signature · 2 lines
With Best Regards, Andy Shevchenko