Re: [PATCH v3 0/2] iio: adc: add MAX40080 current-sense amplifier driver
From: Andy Shevchenko
Date: Wed Jul 15 2026 - 02:52:01 EST
On Wed, Jul 15, 2026 at 09:36:15AM +0300, Stefan Popa wrote:
> This series adds support for the Maxim MAX40080, 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.
>
> The driver operates in direct (INDIO_DIRECT_MODE) mode. Each raw read
> triggers a single on-demand conversion (SMBus Quick Command) and reads
> back the matched current/voltage pair, so results are always fresh. It
> exposes the current and voltage channels with raw and scale attributes,
> a configurable oversampling (digital averaging) ratio, and PEC-protected
> register access. The two selectable current-sense ranges are exposed
> through scale/scale_available; the current scale is derived from the
> shunt-resistor-micro-ohms device-tree property.
>
> Tested on hardware with four MAX40080 devices on an I2C bus.
>
> Regarding Andy's question about *iv being updated even on error in
> read_poll_timeout: yes, this is intentional. The poll loop must update
> *iv on each iteration to check the valid bit. On timeout (conversion
> never completes), *iv contains the last-read value with the valid bit
> still clear, but the caller always checks the return value first —
> "if (ret) return ret;" prevents any use of the stale data.
My point also is that we can do it only once. And since the above a comment is
a must. See more in the comment I'm going to give against individual piece of
code.
--
With Best Regards,
Andy Shevchenko