From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: John Erasmus Mari Geronimo <johnerasmusmari.geronimo@analog.com>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
krzk+dt@kernel.org, jic23@kernel.org, dlechner@baylibre.com,
nuno.sa@analog.com, Michael.Hennerich@analog.com,
andy@kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 2/2] iio: temperature: add support for Analog Devices MAX30210
Date: Wed, 30 Sep 2026 12:15:48 +0300 [thread overview]
Message-ID: <arzTRNa12TPIj__X@ashevche-desk.local> (raw)
In-Reply-To: <1d3cdd6163923b1c537b8db49b833863ee6bf545.1789032019.git.johnerasmusmari.geronimo@analog.com>
On Fri, Sep 11, 2026 at 06:12:17AM +0800, John Erasmus Mari Geronimo wrote:
> 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.
Datasheet tag?
...
> +#include <linux/bitfield.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>
Better to move this group...
> +#include <linux/regmap.h>
> +#include <linux/unaligned.h>
> +#include <linux/units.h>
> +
...to be here (yes, delimited with a blank line).
...
> +struct max30210_state {
> + struct regmap *regmap;
> + u8 watermark;
> + /* Raw FIFO byte buffer */
> + u8 fifo_buf[MAX30210_FIFO_BYTES_PER_SAMPLE * MAX30210_FIFO_SIZE];
I would swap them so the fifo_buf gets aligned and it might help in some cases.
> +};
...
> +static const struct regmap_config max30210_regmap = {
> + .reg_bits = 8,
> + .val_bits = 8,
> + .max_register = MAX30210_PART_ID_REG,
No cache?
> +};
...
> +static int max30210_read_temp(struct regmap *regmap, unsigned int reg,
> + int *temp)
I would go with a single line.
...
> +static int max30210_write_temp(struct regmap *regmap, unsigned int reg,
> + int temp)
Ditto.
...
> +static void max30210_fifo_read(struct iio_dev *indio_dev)
> +{
> + struct max30210_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + ret = regmap_bulk_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]);
> +
> + if (raw == MAX30210_FIFO_INVAL_DATA) {
> + dev_err_ratelimited(&indio_dev->dev, "Invalid data\n");
> + continue;
> + }
> +
> + s16 temp = (s16)FIELD_GET(MAX30210_FIFO_TEMP_MASK, raw);
No, please declare variable at the top of the scope.
Do you need casting? Why?
> + iio_push_to_buffers(indio_dev, &temp);
> + }
> +}
...
> +static int max30210_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int *val,
> + int *val2, long mask)
Wrap logically
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 = 1000;
KILO? MILLI?
> + return IIO_VAL_FRACTIONAL;
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + ret = regmap_read(st->regmap, MAX30210_TEMP_CONF_2_REG, &uval);
> + if (ret)
> + return ret;
> +
> + uval = 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.
> + */
> + uval = min_t(unsigned int, uval, ARRAY_SIZE(max30210_samp_freq_avail) - 1);
> +
> + *val = max30210_samp_freq_avail[uval][0];
> + *val2 = max30210_samp_freq_avail[uval][1];
> +
> + return IIO_VAL_INT_PLUS_MICRO;
> + case IIO_CHAN_INFO_RAW: {
> + if (iio_buffer_enabled(indio_dev))
> + return -EBUSY;
> +
> + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> + if (IIO_DEV_ACQUIRE_FAILED(claim))
> + return -EBUSY;
> +
> + ret = regmap_write(st->regmap, MAX30210_TEMP_CONV_REG,
> + MAX30210_TEMPCONV_CONV_T_MASK);
> + 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_MASK),
> + 500, /* poll every 500 µs */
> + 10000); /* 10 ms timeout */
10 * USEC_PER_MSEC (and drop both comments).
> + if (ret)
> + return ret;
> +
> + return max30210_read_temp(st->regmap, MAX30210_TEMP_DATA_REG, val);
> + }
> + default:
> + return -EINVAL;
> + }
> +}
...
> +IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max,
> + __stringify(MAX30210_FIFO_SIZE));
Make it a single line, it's fine in this case.
...
> + if (!client->irq)
> + return dev_err_probe(dev, -ENXIO, "Missing interrupt.\n");
Unneeded as the below will fail anyway.
> + ret = devm_request_threaded_irq(dev, client->irq, NULL,
> + max30210_irq_handler, IRQF_ONESHOT,
> + indio_dev->name, indio_dev);
> + if (ret)
> + return ret;
...
> +static const struct i2c_device_id max30210_id[] = {
> + { "max30210" },
C99 initialisers.
> + { }
> +};
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-09-30 9:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 12:25 [PATCH v2 0/2] Add support for Analog Devices MAX30210 John Erasmus Mari Geronimo
2026-03-04 12:25 ` [PATCH v2 1/2] dt-bindings: iio: temperature: add ADI MAX30210 John Erasmus Mari Geronimo
2026-03-05 0:11 ` David Lechner
2026-03-07 12:21 ` Jonathan Cameron
2026-03-05 7:00 ` Krzysztof Kozlowski
2026-03-04 12:25 ` [PATCH v2 2/2] iio: temperature: add support for Analog Devices MAX30210 John Erasmus Mari Geronimo
2026-03-05 0:34 ` kernel test robot
2026-03-05 0:45 ` kernel test robot
2026-03-05 0:56 ` David Lechner
2026-03-07 12:38 ` Jonathan Cameron
2026-03-04 13:42 ` [PATCH v2 0/2] Add " Andy Shevchenko
2026-09-10 22:12 ` [PATCH v3 " John Erasmus Mari Geronimo
2026-09-10 22:12 ` [PATCH v3 1/2] dt-bindings: iio: temperature: add ADI MAX30210 John Erasmus Mari Geronimo
2026-09-13 8:59 ` Krzysztof Kozlowski
2026-09-10 22:12 ` [PATCH v3 2/2] iio: temperature: add support for Analog Devices MAX30210 John Erasmus Mari Geronimo
2026-09-11 8:00 ` Andy Shevchenko
2026-09-13 17:59 ` Jonathan Cameron
2026-09-30 9:15 ` Andy Shevchenko [this message]
2026-09-11 7:45 ` [PATCH v3 0/2] Add " Andy Shevchenko
2026-09-13 17:25 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=arzTRNa12TPIj__X@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=johnerasmusmari.geronimo@analog.com \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox