From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Stefan Popa <stefan.popa@analog.com>
Cc: linux-iio@vger.kernel.org, jic23@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, krzysztof.kozlowski@oss.qualcomm.com,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 2/2] iio: adc: add MAX40080 current-sense amplifier driver
Date: Fri, 28 Aug 2026 12:41:43 +0300 [thread overview]
Message-ID: <apFX16p9OGwA5cjB@ashevche-desk.local> (raw)
In-Reply-To: <20260828083119.54495-3-stefan.popa@analog.com>
On Fri, Aug 28, 2026 at 11:31:18AM +0300, Stefan Popa 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.
...
> +#include <linux/array_size.h>
> +#include <linux/bitfield.h>
> +#include <linux/bitops.h>
> +#include <linux/cleanup.h>
> +#include <linux/i2c.h>
> +#include <linux/types.h>
> +#include <linux/iopoll.h>
> +#include <linux/math64.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/property.h>
+ types.h // uXX
> +#include <linux/units.h>
...
> +static int max40080_read_iv(struct max40080_state *st, u32 *iv)
> +{
> + u32 tmp = 0;
> + int ret, io_ret;
> +
> + guard(mutex)(&st->lock);
> +
> + ret = max40080_trigger_measurement(st);
> + if (ret < 0)
> + return ret;
> +
> + /*
> + * Wait for the conversion to complete by polling the FIFO valid bit
> + * (or bail out on an I2C error). Polling the device's own status makes
> + * this independent of the actual conversion time, which varies with the
> + * oversampling ratio and the bus speed. The timeout is only a safety
> + * ceiling: the worst case is the maximum 128x averaging on both the
> + * current and voltage channels at the slowest 15 ksps base rate plus the
> + * inter-channel switching time, i.e. roughly 20 ms; 50 ms leaves ample
> + * margin.
> + */
> + ret = read_poll_timeout(max40080_read_iv_once, io_ret,
> + io_ret || (tmp & MAX40080_IV_VALID_MSK),
> + 500, 50000, false, st, &tmp);
50 * USEC_PER_MSEC
(needs time.h)
> + /*
> + * Propagate the last-read value even on timeout so the caller can
> + * inspect it for debugging.
> + */
> + *iv = tmp;
But would it make sense when IO error happened?
> + if (ret)
> + return ret;
> + return io_ret;
Actually IO error might have a precedence over timeout. I would check for it
first.
> +}
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-08-28 9:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 8:31 [PATCH v8 0/2] " Stefan Popa
2026-08-28 8:31 ` [PATCH v8 1/2] dt-bindings: iio: adc: add adi,max40080 Stefan Popa
2026-08-28 8:31 ` [PATCH v8 2/2] iio: adc: add MAX40080 current-sense amplifier driver Stefan Popa
2026-08-28 9:41 ` Andy Shevchenko [this message]
2026-08-30 0:51 ` Jonathan Cameron
2026-08-30 0:51 ` [PATCH v8 0/2] " Jonathan Cameron
2026-08-30 0:59 ` 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=apFX16p9OGwA5cjB@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--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=jic23@kernel.org \
--cc=joshua.crofts1@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=krzysztof.kozlowski@oss.qualcomm.com \
--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
all inboxes | Powered by JetHome®