The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Cc: "Stefan Popa" <stefan.popa@analog.com>,
	linux-iio@vger.kernel.org,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sa" <nuno.sa@analog.com>, "Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Siratul Islam" <siratul.islam@linux.dev>,
	"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
	"Ciprian Hegbeli" <ciprian.hegbeli@analog.com>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] iio: adc: add MAX40080 current-sense amplifier driver
Date: Mon, 20 Jul 2026 12:08:16 +0100	[thread overview]
Message-ID: <al3-oTXgPQ0eQLF4@nsa> (raw)
In-Reply-To: <20260718004145.079c5262@jic23-huawei>

On Sat, Jul 18, 2026 at 12:41:57AM +0100, Jonathan Cameron wrote:
> On Wed, 15 Jul 2026 16:23:11 +0200
> Nuno Sá <noname.nuno@gmail.com> wrote:
> 
> > Hi Stefan,
> > 
> > Some comments from me
> > 
> > On Wed, Jul 15, 2026 at 09:36:17AM +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.
> > > 
> > > No existing IIO driver covers this device or a register-compatible part.
> > > The closest relatives target different silicon with incompatible register
> > > maps and feature sets: max9611 is a unidirectional high-side sensor with a
> > > die-temperature channel and MUX-selected gain and no FIFO/PEC, while
> > > max34408 is an 8-bit multi-channel current monitor. The MAX40080 has a
> > > device-specific register map with bidirectional 13-bit current, a 64-entry
> > > FIFO, PEC, a single-measurement mode triggered by an SMBus Quick Command,
> > > and two selectable input ranges, so it warrants its own driver.
> > > 
> > > Add a direct-mode IIO driver exposing 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.
> > > 
> > > Link: https://www.analog.com/media/en/technical-documentation/data-sheets/MAX40080.pdf
> > > 
> > > 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>
> 
> A couple of follow ups even though v4 is on list.  
> 
> That should indicate clearly why you should slow down and let people
> get to earlier versions.
> 
> Jonathan
> 
> > > diff --git a/drivers/iio/adc/max40080.c b/drivers/iio/adc/max40080.c
> > > new file mode 100644
> > > index 0000000000000..a0c1144cfda7c
> > > --- /dev/null
> > > +++ b/drivers/iio/adc/max40080.c
> > > @@ -0,0 +1,630 @@
> > > +// SPDX-License-Identifier: GPL-2.0+
> > > +/*
> > > + * MAX40080 Digital Current-Sense Amplifier driver
> > > + *
> > > + * Copyright 2026 Analog Devices, Inc.
> > > + */
> > > +
> > > +#include <linux/bitfield.h>
> > > +#include <linux/bitops.h>
> > > +#include <linux/cleanup.h>
> > > +#include <linux/i2c.h>
> > > +#include <linux/iopoll.h>
> > > +#include <linux/math64.h>
> > > +#include <linux/module.h>  
> > 
> > Typically I would say you're missing mod_devicetable.h but now we have:
> > 
> > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/include/linux/device-id
> > 
> > You might need to base your series on linux-next though.
> 
> I merged rc2 into the IIO togreg (and so testing as well) branches to resolve
> merge conflicts with that series.  Upshot is just don't bother
> including mod_devicetable.h in any new code.  Also don't worry
> about including any of the linux/device-id headers unless you don't
> get them via i2c.h, spi.h etc
> 
> > 
> > > +#include <linux/mutex.h>
> > > +#include <linux/pm.h>
> > > +#include <linux/property.h>
> > > +#include <linux/time.h>
> > > +static int max40080_read_iv_once(struct max40080_state *st, u32 *iv)
> > > +{
> > > +	u8 buf[4];
> > > +	int ret;
> > > +
> > > +	ret = i2c_smbus_read_i2c_block_data(st->client, MAX40080_REG_IV,
> > > +					    sizeof(buf), buf);  
> > 
> > It's not clear to me that i2c will use safe buffer all the time (from a
> > quick look). So I would say to make this DMA safe the usual way we do in
> > IIO.
> 
> I2c always bounces unless you use specific dmasafe functions to indicate
> that your particular buffer is DMA safe.

To me it was not clear because of:

https://elixir.bootlin.com/linux/v7.2-rc3/source/drivers/i2c/i2c-core-smbus.c#L604

In the above case it looks like the buffer is just passed to the
controller and it won't fallback for the emaluted case where
i2c_smbus_try_get_dmabuf() seems to be always called.

Having said the above and looking (briefly)  at the .smbus_xfer_atomic() users, not
sure it will be such an issue.

- Nuno Sá
> 
> > 
> > > +	if (ret < 0)
> > > +		return ret;
> > > +	if (ret != sizeof(buf))
> > > +		return -EIO;
> > > +
> > > +	*iv = get_unaligned_le32(buf);
> > > +
> > > +	return 0;
> > > +}
> > > +  

  reply	other threads:[~2026-07-20 11:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15  6:36 [PATCH v3 0/2] iio: adc: add MAX40080 current-sense amplifier driver Stefan Popa
2026-07-15  6:36 ` [PATCH v3 1/2] dt-bindings: iio: adc: add maxim,max40080 Stefan Popa
2026-07-15  6:36 ` [PATCH v3 2/2] iio: adc: add MAX40080 current-sense amplifier driver Stefan Popa
2026-07-15  8:34   ` Andy Shevchenko
2026-07-15 13:41     ` Nuno Sá
2026-07-15 13:58       ` Andy Shevchenko
2026-07-15 15:09         ` Nuno Sá
2026-07-15 14:23   ` Nuno Sá
2026-07-17 23:41     ` Jonathan Cameron
2026-07-20 11:08       ` Nuno Sá [this message]
2026-07-15  6:51 ` [PATCH v3 0/2] " Andy Shevchenko

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=al3-oTXgPQ0eQLF4@nsa \
    --to=noname.nuno@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ciprian.hegbeli@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jonathan.cameron@oss.qualcomm.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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