public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Julien Stephan <jstephan@baylibre.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, "kernel test robot" <lkp@intel.com>
Subject: Re: [PATCH v5 5/7] iio: adc: ad7380: prepare for parts with more channels
Date: Sun, 24 Mar 2024 13:07:56 +0000	[thread overview]
Message-ID: <20240324130756.598a4b36@jic23-huawei> (raw)
In-Reply-To: <20240319-adding-new-ad738x-driver-v5-5-ce7df004ceb3@baylibre.com>

On Tue, 19 Mar 2024 11:11:26 +0100
Julien Stephan <jstephan@baylibre.com> wrote:

> The current driver supports only parts with 2 channels.
> In order to prepare the support of new compatible ADCs with more
> channels, this commit:
>   - defines MAX_NUM_CHANNEL to specify the maximum number of
>     channels currently supported by the driver
>   - adds available_scan_mask member in ad7380_chip_info structure
>   - fixes spi xfer struct len depending on number of channels
>   - fixes scan_data.raw buffer size to handle more channels
>   - adds a timing specifications structure in ad7380_chip_info structure
> 
> Signed-off-by: Julien Stephan <jstephan@baylibre.com>

>  struct ad7380_state {
> @@ -148,15 +168,15 @@ struct ad7380_state {
>  	struct spi_device *spi;
>  	struct regmap *regmap;
>  	unsigned int vref_mv;
> -	unsigned int vcm_mv[2];
> +	unsigned int vcm_mv[MAX_NUM_CHANNELS];
>  	/*
>  	 * DMA (thus cache coherency maintenance) requires the
>  	 * transfer buffers to live in their own cache lines.
> -	 * Make the buffer large enough for 2 16-bit samples and one 64-bit
> +	 * Make the buffer large enough for MAX_NUM_CHANNELS 16-bit samples and one 64-bit
>  	 * aligned 64 bit timestamp.
>  	 */
>  	struct {
> -		u16 raw[2];
> +		u16 raw[MAX_NUM_CHANNELS];

This can get problematic for drivers supporting devices with varying numbers of channels.
You are fine up to 4 channels as the structure layout isn't changing.  The reason is that
it implies the timestamp location, which if you were for instance to support 8 channels
would be incorrect if only 4 of them were enabled.
Now the timestamp location is only used implicitly in the driver (as the IIO core
handles the actual insertion of the data) so it's not a bug as such to do this, but it
can give people the wrong impression during testing etc.

As such, I'd like to see the comment mention that "as MAX_NUM_CHANNELS is 4
the layout of the structure is the same for all parts".

Note I've reviewed one driver today that did have different layouts depending on
which device was in use and ended up falsely indicating the timestamp was later
than it actually was in the buffer.  Hence my request for a defensive comment!

>  
>  		s64 ts __aligned(8);
>  	} scan_data __aligned(IIO_DMA_MINALIGN);



  reply	other threads:[~2024-03-24 13:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 10:11 [PATCH v5 0/7] iio: adc: add new ad7380 driver Julien Stephan
2024-03-19 10:11 ` [PATCH v5 1/7] dt-bindings: iio: adc: Add binding for AD7380 ADCs Julien Stephan
2024-03-19 10:11 ` [PATCH v5 2/7] iio: adc: ad7380: new driver " Julien Stephan
2024-03-24 12:42   ` Jonathan Cameron
2024-03-19 10:11 ` [PATCH v5 3/7] dt-bindings: iio: adc: ad7380: add pseudo-differential parts Julien Stephan
2024-03-19 17:10   ` Conor Dooley
2024-03-19 10:11 ` [PATCH v5 4/7] iio: adc: ad7380: add support for " Julien Stephan
2024-03-24 13:01   ` Jonathan Cameron
2024-03-25 14:08     ` David Lechner
2024-03-25 20:06       ` Jonathan Cameron
2024-03-25 20:14         ` David Lechner
2024-03-19 10:11 ` [PATCH v5 5/7] iio: adc: ad7380: prepare for parts with more channels Julien Stephan
2024-03-24 13:07   ` Jonathan Cameron [this message]
2024-03-19 10:11 ` [PATCH v5 6/7] dt-bindings: iio: adc: ad7380: add support for ad738x-4 4 channels variants Julien Stephan
2024-03-19 17:24   ` Conor Dooley
2024-03-19 10:11 ` [PATCH v5 7/7] " Julien Stephan
2024-03-24 13:10   ` Jonathan Cameron
2024-03-25 15:01     ` David Lechner
2024-03-25 19:04       ` 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=20240324130756.598a4b36@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jstephan@baylibre.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=nuno.sa@analog.com \
    --cc=robh+dt@kernel.org \
    /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