Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Jonathan Santos <jonath4nns@gmail.com>
Cc: 111f571d-1d88-42f7-b9a5-4b1cb328e26b@baylibre.com,
	David Lechner <dlechner@baylibre.com>,
	Jonathan Santos <Jonathan.Santos@analog.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, lars@metafoo.de,
	Michael.Hennerich@analog.com, robh@kernel.org,
	krzk+dt@kernel.org, conor+dt@kernel.org,
	marcelo.schmitt1@gmail.com
Subject: Re: [PATCH v1 13/15] iio: adc: ad7768-1: add multiple scan types to support 16-bits mode
Date: Sun, 12 Jan 2025 12:50:37 +0000	[thread overview]
Message-ID: <20250112125037.442c56c9@jic23-huawei> (raw)
In-Reply-To: <Z4M1QU8XQjAKqI4W@JSANTO12-L01.ad.analog.com>

On Sun, 12 Jan 2025 00:21:37 -0300
Jonathan Santos <jonath4nns@gmail.com> wrote:

> On 01/07, David Lechner wrote:
> > On 1/7/25 9:26 AM, Jonathan Santos wrote:  
> > > When the device is configured to Sinc5 filter and decimation x8,
> > > output data is reduced to 16-bits in order to support 1 MHz of
> > > sampling frequency due to clock limitation.  
> > 
> > We aren't going to get a 1 MHz sample rate without SPI offload support so maybe
> > we should save this patch until then?
> > 
> > In this patch, we are still reading 24-bits per sample, so we aren't really
> > getting any benefit. It is probably fine for now to leave it as 24-bit even if
> > the last 8 bits are all 0 or just noise.  
> 
> Indeed we cannot achieve 1 MHz yet, but I believe it is good have this
> now so it is more mature for the time SPI offload is supported. Also, will
> allow us to backport this patch to other repos.
> 
> > 
> > Also, the datasheet says:
> > 
> > 	this path allows viewing of wider bandwidth; however, it is quantization
> > 	noise limited so that output data is reduced to 16 bits
> > 
> > So this doesn't actually seem related to higher sample rates. There is a CONVLEN
> > bit in the INTERFACE_FORMAT register that globally reduces the output size to
> > 16-bit, which I suspect would be what we will need for achieving the highest
> > sample rate when we add SPI offload support.
> >   
> 
> Right, that is true, but the reason we did this patch was to fix the
> output size when we configure the filter to sinc5 decx8. The datasheet
> says:
> 
> 	To configure the sinc5 filter for 1.024 MSPS output data rate,
> 	write 001 to the FILTER bits [6:4] of the DIGITAL_FILTER register
> 	(Register 0x19). The ADAQ7768-1 automatically changes the decimation
> 	rate to 8 and output data length is reduced to 16 bits from 24 bits 
> 	due to the maximum speed limitation of the digital serial interface.
> 
> In this case we don't even need to change the value of CONVLEN
> 
> > > 
> > > Use multiple scan types feature to enable the driver to switch
> > > scan type in runtime, making possible to support both 24-bit and
> > > 16-bit resolution.
> > > 
> > > Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
> > > ---
> > >  drivers/iio/adc/ad7768-1.c | 65 ++++++++++++++++++++++++++++++++------
> > >  1 file changed, 56 insertions(+), 9 deletions(-)
> > > 
> > > diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
> > > index 9741a6d47942..5e4e7d387f9a 100644
> > > --- a/drivers/iio/adc/ad7768-1.c
> > > +++ b/drivers/iio/adc/ad7768-1.c
> > > @@ -134,6 +134,11 @@ struct ad7768_clk_configuration {
> > >  	enum ad7768_pwrmode pwrmode;
> > >  };
> > >  
> > > +enum ad7768_scan_type {
> > > +	AD7768_SCAN_TYPE_NORMAL,
> > > +	AD7768_SCAN_TYPE_HIGH_SPEED,
> > > +};
> > > +
> > >  static const char * const ad7768_vcm_modes[] = {
> > >  	"(AVDD1-AVSS)/2",
> > >  	"2V5",
> > > @@ -145,6 +150,10 @@ static const char * const ad7768_vcm_modes[] = {
> > >  	"OFF",
> > >  };
> > >  
> > > +static const int ad7768_mclk_div_rates[4] = {
> > > +	16, 8, 4, 2,
> > > +};
> > > +
> > >  static const struct ad7768_clk_configuration ad7768_clk_config[] = {
> > >  	{ AD7768_MCLK_DIV_2, AD7768_DEC_RATE_8, 16,  AD7768_FAST_MODE },
> > >  	{ AD7768_MCLK_DIV_2, AD7768_DEC_RATE_16, 32,  AD7768_FAST_MODE },
> > > @@ -159,6 +168,21 @@ static const struct ad7768_clk_configuration ad7768_clk_config[] = {
> > >  	{ AD7768_MCLK_DIV_16, AD7768_DEC_RATE_1024, 16384, AD7768_ECO_MODE },
> > >  };
> > >  
> > > +static const struct iio_scan_type ad7768_scan_type[] = {
> > > +	[AD7768_SCAN_TYPE_NORMAL] = {
> > > +		.sign = 's',
> > > +		.realbits = 24,
> > > +		.storagebits = 32,  
> > 
> > What happened to .shift = 8, ? If there is a reason for removing it, please add
> > that to the commit description.
> >   
> 
> Sorry, will fix this
> 
> > > +		.endianness = IIO_BE,
> > > +	},
> > > +	[AD7768_SCAN_TYPE_HIGH_SPEED] = {
> > > +		.sign = 's',
> > > +		.realbits = 16,
> > > +		.storagebits = 32,  
> > 
> > I guess it doesn't matter much since we are reading one sample at a time, but
> > I would expect storagebits to be 16 instead of 32. Or if it really needs to be
> > 32, does it need shift = 16?
> >   
> 
> This is because the hw is configured to return the samples in a 32 bits
> format, so if storage is 16 we will get wrong data.

Currently we only support one channel (daisy chain mode support might change
that). Not particularly painful to repack and it doubles the data we can fit
in a fifo of a given size.

If this is tricky because of later patches, throw in a common on why.


> 
> > > +		.endianness = IIO_BE,
> > > +	},
> > > +};
> > > +
> > >  static int ad7768_get_vcm(struct iio_dev *dev, const struct iio_chan_spec *chan);
> > >  static int ad7768_set_vcm(struct iio_dev *dev, const struct iio_chan_spec *chan,
> > >  			  unsigned int mode);  
> > 
> > ...
> >   
> > > @@ -308,6 +329,15 @@ static int ad7768_scan_direct(struct iio_dev *indio_dev)
> > >  	ret = ad7768_spi_reg_read(st, AD7768_REG_ADC_DATA, &readval, 3);
> > >  	if (ret < 0)
> > >  		return ret;
> > > +
> > > +	/*
> > > +	 * When the decimation rate is set to x8, the ADC data precision is reduced
> > > +	 * from 24 bits to 16 bits. Since the AD7768_REG_ADC_DATA register provides
> > > +	 * 24-bit data, the precision is reduced by right-shifting the read value
> > > +	 * by 8 bits.
> > > +	 */
> > > +	if (st->dec_rate == 8)
> > > +		readval = readval >> 8;  
> > 
> > Why not change size of ad7768_spi_reg_read() instead of reading 3 bytes and
> > throwing one away?
> >   
> 
> Right, i will check this and fix in the next version
> 
> > >  	/*
> > >  	 * Any SPI configuration of the AD7768-1 can only be
> > >  	 * performed in continuous conversion mode.  


  reply	other threads:[~2025-01-12 12:50 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07 15:23 [PATCH v1 00/15] iio: adc: ad7768-1: Add features, improvements, and fixes Jonathan Santos
2025-01-07 15:24 ` [PATCH v1 01/15] dt-bindings: iio: adc: ad7768-1: add synchronization over SPI property Jonathan Santos
2025-01-07 23:35   ` David Lechner
2025-01-11 22:34     ` Jonathan Santos
2025-01-12 12:12       ` Jonathan Cameron
2025-01-14  0:18         ` Jonathan Santos
2025-01-14 16:05           ` David Lechner
2025-01-18 11:58             ` Jonathan Cameron
2025-01-12 17:14       ` David Lechner
2025-01-10 21:51   ` Marcelo Schmitt
2025-01-12 12:05     ` Jonathan Cameron
2025-01-14  0:41       ` Jonathan Santos
2025-01-18 12:00         ` Jonathan Cameron
2025-01-07 15:24 ` [PATCH v1 02/15] Documentation: ABI: add wideband filter type to sysfs-bus-iio Jonathan Santos
2025-01-07 23:38   ` David Lechner
2025-01-11 22:50     ` Jonathan Santos
2025-01-12 12:16       ` Jonathan Cameron
2025-01-14  0:44         ` Jonathan Santos
2025-01-12 17:39       ` David Lechner
2025-01-12 17:41         ` David Lechner
2025-01-07 15:24 ` [PATCH v1 03/15] Documentation: ABI: testing: ad7768-1: Add device specific ABI documentation Jonathan Santos
2025-01-07 23:38   ` David Lechner
2025-01-11 23:22     ` Jonathan Santos
2025-01-12 12:20       ` Jonathan Cameron
2025-01-12 13:10         ` Jonathan Cameron
2025-01-14  1:06           ` Jonathan Santos
2025-01-07 15:25 ` [PATCH v1 04/15] iio: adc: ad7768-1: Fix conversion result sign Jonathan Santos
2025-01-07 23:39   ` David Lechner
2025-01-10 21:52   ` Marcelo Schmitt
2025-01-12  0:00     ` Jonathan Santos
2025-01-12 12:22   ` Jonathan Cameron
2025-01-07 15:25 ` [PATCH v1 05/15] iio: adc: ad7768-1: set MOSI idle state to high Jonathan Santos
2025-01-07 23:40   ` David Lechner
2025-01-10 21:56     ` Marcelo Schmitt
2025-01-12 12:30       ` Jonathan Cameron
2025-01-13 12:19         ` Marcelo Schmitt
2025-01-18 12:09           ` Jonathan Cameron
2025-01-18 13:17             ` Marcelo Schmitt
2025-01-07 15:25 ` [PATCH v1 06/15] iio: adc: ad7768-1: Update reg_read function Jonathan Santos
2025-01-10 21:57   ` Marcelo Schmitt
2025-01-07 15:25 ` [PATCH v1 07/15] iio: adc: ad7768-1: Add reset gpio Jonathan Santos
2025-01-07 23:40   ` David Lechner
2025-01-12 12:35     ` Jonathan Cameron
2025-01-07 15:25 ` [PATCH v1 08/15] iio: adc: ad7768-1: use guard(mutex) to simplify code Jonathan Santos
2025-01-07 23:42   ` David Lechner
2025-01-12  0:26     ` Jonathan Santos
2025-01-07 15:26 ` [PATCH v1 09/15] iio: adc: ad7768-1: Move buffer allocation to a separate function Jonathan Santos
2025-01-10 22:01   ` Marcelo Schmitt
2025-01-12 12:39     ` Jonathan Cameron
2025-01-12 12:40   ` Jonathan Cameron
2025-01-14  1:14     ` Jonathan Santos
2025-01-07 15:26 ` [PATCH v1 10/15] iio: adc: ad7768-1: Add support for variable VCM Jonathan Santos
2025-01-07 23:46   ` David Lechner
2025-01-12  2:37     ` Jonathan Santos
2025-01-12 12:45       ` Jonathan Cameron
2025-01-07 15:26 ` [PATCH v1 11/15] iio: adc: ad7768-1: Add reg_write_masked function Jonathan Santos
2025-01-07 23:46   ` David Lechner
2025-01-10 22:34   ` Marcelo Schmitt
2025-01-12  2:42     ` Jonathan Santos
2025-01-07 15:26 ` [PATCH v1 12/15] iio: adc: ad7768-1: Add GPIO controller support Jonathan Santos
2025-01-07 23:48   ` David Lechner
2025-01-07 15:26 ` [PATCH v1 13/15] iio: adc: ad7768-1: add multiple scan types to support 16-bits mode Jonathan Santos
2025-01-07 23:49   ` David Lechner
2025-01-12  3:21     ` Jonathan Santos
2025-01-12 12:50       ` Jonathan Cameron [this message]
2025-01-12 17:51         ` David Lechner
2025-01-07 15:27 ` [PATCH v1 14/15] iio: adc: ad7768-1: add support for Synchronization over SPI Jonathan Santos
2025-01-07 23:50   ` David Lechner
2025-01-12 12:59     ` Jonathan Cameron
2025-01-14  1:27       ` Jonathan Santos
2025-01-07 15:27 ` [PATCH v1 15/15] iio: adc: ad7768-1: add filter type and decimation rate attributes Jonathan Santos
2025-01-07 23:50   ` David Lechner
2025-01-12 13:04     ` Jonathan Cameron
2025-01-14  1:39       ` Jonathan Santos
2025-01-10 22:32   ` Marcelo Schmitt
2025-01-07 23:33 ` [PATCH v1 00/15] iio: adc: ad7768-1: Add features, improvements, and fixes David Lechner
2025-01-11 21:56   ` Jonathan Santos

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=20250112125037.442c56c9@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=111f571d-1d88-42f7-b9a5-4b1cb328e26b@baylibre.com \
    --cc=Jonathan.Santos@analog.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jonath4nns@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=robh@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