Re: [PATCH v1 2/2] iio: adc: add MAX40080 current-sense amplifier driver

From: Jonathan Cameron

Date: Fri Jul 03 2026 - 19:53:33 EST


On Fri, 3 Jul 2026 13:29:32 +0300
Stefan Popa <stefan.popa@xxxxxxxxxx> 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.
>
> Signed-off-by: Ciprian Hegbeli <ciprian.hegbeli@xxxxxxxxxx>
> Signed-off-by: Stefan Popa <stefan.popa@xxxxxxxxxx>

You have some thorough reviews already but who can resist
a new driver on a Friday afternoon ;)

I tried to avoid repetition with existing reviews so didn't have
much to add.

Thanks,

Jonathan

> diff --git a/drivers/iio/adc/max40080.c b/drivers/iio/adc/max40080.c
> new file mode 100644
> index 0000000000000..441e1ce3dcffd
> --- /dev/null
> +++ b/drivers/iio/adc/max40080.c


> +
> +static int max40080_probe(struct i2c_client *client)
> +{
> + struct device *dev = &client->dev;
> + struct iio_dev *indio_dev;
> + struct max40080_state *st;
> + int ret;
> +
> + if (!i2c_check_functionality(client->adapter,
> + I2C_FUNC_SMBUS_WORD_DATA |
> + I2C_FUNC_SMBUS_I2C_BLOCK |
> + I2C_FUNC_SMBUS_QUICK))
> + return -EOPNOTSUPP;
> +
> + client->flags |= I2C_CLIENT_PEC;

> + if (device_property_read_u32(dev, "shunt-resistor-micro-ohms",
> + &st->shunt_resistor_uohm))
> + st->shunt_resistor_uohm = 1000000; /* default 1 ohm */

Over time we've evolved our preferences for this based on what ends up
readable. For new code something like
if (device_property_present(dev, "shunt-resistor-micro-ohms)) {
ret = device_property_read_u32(dev, "shunt-resistor-micro-ohms",
&st->shunt_resistor_uohm);
if (ret)
return ret;
} else {
st->shunt_resistor_uohm = 1 * MICRO; /* default 1 ohm */
}

> +
> + if (!st->shunt_resistor_uohm)
> + return dev_err_probe(dev, -EINVAL,
> + "shunt-resistor-micro-ohms must be non-zero\n");
> +
> + max40080_calc_current_scale(st);