From: Jonathan Cameron <jic23@kernel.org>
To: Stefan Popa <stefan.popa@analog.com>
Cc: <linux-iio@vger.kernel.org>, <lars@metafoo.de>,
<Michael.Hennerich@analog.com>, <robh@kernel.org>,
<krzk+dt@kernel.org>, <conor+dt@kernel.org>, <andy@kernel.org>,
<dlechner@baylibre.com>, <nuno.sa@analog.com>,
<siratul.islam@linux.dev>, <u.kleine-koenig@baylibre.com>,
<linux@roeck-us.net>, <joshua.crofts1@gmail.com>,
<ciprian.hegbeli@analog.com>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v7 2/2] iio: adc: add MAX40080 current-sense amplifier driver
Date: Tue, 18 Aug 2026 17:38:09 +0100 [thread overview]
Message-ID: <20260818173809.76a05ac4@jic23-huawei> (raw)
In-Reply-To: <20260818142928.8244-3-stefan.popa@analog.com>
On Tue, 18 Aug 2026 17:29:28 +0300
Stefan Popa <stefan.popa@analog.com> wrote:
> The MAX40080 is a bidirectional current-sense amplifier with an
> integrated 12-bit ADC and an I2C/SMBus interface. It measures the
> voltage across an external shunt resistor and the input bus voltage,
> storing the results in an internal FIFO.
>
> Add a direct-mode IIO driver exposing the current and voltage channels
> with raw, scale and hardware-gain attributes, a configurable
> oversampling (digital averaging) ratio, and PEC-protected register
> access. The current scale is derived from the shunt resistor value
> described in the device tree.
>
> The driver operates in single-measurement mode: each raw read triggers
> an on-demand conversion via SMBus Quick Command and returns a matched
> current/voltage pair. This avoids the latency and complexity of the
> continuous FIFO mode while ensuring each read reflects the current
> state. The two selectable current-sense ranges are exposed through
> scale/scale_available.
>
> Continuous FIFO buffering, threshold events and the alert interrupt are
> intentionally left out of this initial submission and may be added
> later.
https://sashiko.dev/#/patchset/20260818142928.8244-1-stefan.popa%40analog.com
The copy being optimized out is likely complier optimization so I think
sashiko is correct that you need READ_ONCE() (and probably the WRITE_ONCE()
as well)
>
> Co-developed-by: Ciprian Hegbeli <ciprian.hegbeli@analog.com>
> Signed-off-by: Ciprian Hegbeli <ciprian.hegbeli@analog.com>
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Otherwise, just trivial stuff from me. Andy caught a lot more than me!
Given this seems to be coming to a point where it is ready to be applied
(hopefully v8) feel free to send a new version out in a day or two rather
than waiting a week.
Thanks
Jonathan
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index 7cc8f9a12f763..9245a337dd935 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -166,3 +166,4 @@ obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
> obj-$(CONFIG_XILINX_AMS) += xilinx-ams.o
> xilinx-xadc-y := xilinx-xadc-core.o xilinx-xadc-events.o
> obj-$(CONFIG_XILINX_XADC) += xilinx-xadc.o
> +obj-$(CONFIG_MAX40080) += max40080.o
> diff --git a/drivers/iio/adc/max40080.c b/drivers/iio/adc/max40080.c
> new file mode 100644
> index 0000000000000..4b397bcd145b2
> --- /dev/null
> +++ b/drivers/iio/adc/max40080.c
> +/*
> + * Configure the device from the cached state. The device powers up in standby
> + * with PEC enabled (CFG POR = 0x0060), so PEC is kept enabled throughout.
> + */
> +static int max40080_init(struct max40080_state *st)
> +{
> + u16 fifo_cfg, cfg;
> + int ret, filter;
> +
> + filter = max40080_oversampling_to_filter(st->oversampling_ratio);
> + if (filter < 0)
> + return filter;
> +
> + /*
> + * Put the device in standby before (re)configuring the FIFO: the FIFO
> + * configuration register can only be written while the device is not
> + * converting.
> + */
> + cfg = FIELD_PREP(MAX40080_CFG_MODE_MSK, MAX40080_CFG_MODE_STDBY) |
> + FIELD_PREP(MAX40080_CFG_PEC_EN_MSK, 1);
> +
As below.
> + ret = i2c_smbus_write_word_data(st->client, MAX40080_REG_CFG, cfg);
> + if (ret)
> + return ret;
> +
> + /* Store a matched current+voltage pair per conversion. */
> + fifo_cfg = FIELD_PREP(MAX40080_FIFO_CFG_STORE_IV_MSK, MAX40080_FIFO_CFG_STORE_IV);
> +
Where you have pairs like this of setting local and using it, drop the blank line.
We want those to be visually closely coupled.
> + ret = i2c_smbus_write_word_data(st->client, MAX40080_REG_FIFO_CFG,
> + fifo_cfg);
> + if (ret)
> + return ret;
next prev parent reply other threads:[~2026-08-18 16:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 14:29 [PATCH v7 0/2] iio: adc: add MAX40080 current-sense amplifier driver Stefan Popa
2026-08-18 14:29 ` [PATCH v7 1/2] dt-bindings: iio: adc: add adi,max40080 Stefan Popa
2026-08-18 14:29 ` [PATCH v7 2/2] iio: adc: add MAX40080 current-sense amplifier driver Stefan Popa
2026-08-18 15:44 ` Andy Shevchenko
2026-08-18 16:19 ` Jonathan Cameron
2026-08-19 6:51 ` Andy Shevchenko
2026-08-18 16:38 ` Jonathan Cameron [this message]
2026-08-19 8:00 ` Siratul Islam
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=20260818173809.76a05ac4@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=ciprian.hegbeli@analog.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=joshua.crofts1@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=siratul.islam@linux.dev \
--cc=stefan.popa@analog.com \
--cc=u.kleine-koenig@baylibre.com \
/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