public inbox for linux-doc@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Marcelo Schmitt <marcelo.schmitt@analog.com>,
	broonie@kernel.org, lars@metafoo.de,
	Michael.Hennerich@analog.com, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
	nuno.sa@analog.com, dlechner@baylibre.com, corbet@lwn.net,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-spi@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 6/7] iio: adc: Add support for AD4000
Date: Mon, 1 Jul 2024 15:10:54 -0300	[thread overview]
Message-ID: <ZoLxLgpy44S38nSe@debian-BULLSEYE-live-builder-AMD64> (raw)
In-Reply-To: <20240630121726.5d75578e@jic23-huawei>

On 06/30, Jonathan Cameron wrote:
> On Sat, 29 Jun 2024 16:06:59 -0300
> Marcelo Schmitt <marcelo.schmitt@analog.com> wrote:
> 
> > Add support for AD4000 series of low noise, low power, high speed,
> > successive approximation register (SAR) ADCs.
> > 
> > Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
> 
> Hi Marcelo
> 
> A few comments inline. However, the spi_w8r8 etc can easily be a follow up
> optimization patch (if you agree it's a good improvement) and the
> other changes are so trivial I could tweak whilst applying.
> 
...
> > +	/*
> > +	 * The gain is stored as a fraction of 1000 and, as we need to
> > +	 * divide vref_mv by the gain, we invert the gain/1000 fraction.
> > +	 * Also multiply by an extra MILLI to preserve precision.
> > +	 * Thus, we have MILLI * MILLI equals MICRO as fraction numerator.
> > +	 */
> > +	val = mult_frac(st->vref_mv, MICRO, st->gain_milli);
> 
> If you are rolling a v7 for other reasons, stick some line breaks in here!
> It's a bit of a mass of text that is hard for my eyes to parse!
> 
Ack

...

> 
> > +static int ad4000_read_reg(struct ad4000_state *st, unsigned int *val)
> > +{
> > +	struct spi_transfer t = {
> > +		.tx_buf = st->tx_buf,
> > +		.rx_buf = st->rx_buf,
> > +		.len = 2,
> > +	};
> > +	int ret;
> > +
> > +	st->tx_buf[0] = AD4000_READ_COMMAND;
> > +	ret = spi_sync_transfer(st->spi, &t, 1);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	*val = st->rx_buf[1];
> > +	return ret;
> 
> I'd be tempted to do
> 
> 	ssize_t ret;
> 
> 	ret = spi_w8r8(AD4000_READ_COMMAND);
> 	if (ret < 0)
> 		return ret;
> 	*val = ret;
> 	
> 	return 0;
> 
I tried this when working on v6. Only difference was I had declared ret as int.
Then reg values were not read correctly with spi_w8r8().
I'm either missing something or reg access must be 16-bit transfer.
Datasheet sais:
"The AD4000/AD4004/AD4008 configuration register is read from and written to
with a 16-bit SPI instruction."
Yet, besides possible delay between first and last 8 SCLK pulses, I don't see
any transfer level differences between current and spi_w8r8() versions.

> 
> 
...
> > +			ret = ad4000_write_reg(st, reg_val);
> > +			if (ret < 0)
> > +				return ret;
> > +
> > +			st->span_comp = span_comp_en;
> > +			return ret;
> 
> If you are spinning for another reason, make it clear this is always good.
> The spi_write() never returns positive so current code is correct but I had
> to go check which this would have avoided.
> 
> 			return 0;

Ack
> 
> If nothing else comes up, I'll probably tweak whilst applying.
> 
> J
> 
> > +		}
> > +		unreachable();
> > +	default:
> > +		return -EINVAL;
> > +	}
> > +}
> 

  reply	other threads:[~2024-07-01 18:09 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-29 19:04 [PATCH v6 0/7] Add support for AD4000 series of ADCs Marcelo Schmitt
2024-06-29 19:04 ` [PATCH v6 1/7] spi: Enable controllers to extend the SPI protocol with MOSI idle configuration Marcelo Schmitt
2024-06-30 10:47   ` Jonathan Cameron
2024-07-01 17:30     ` Marcelo Schmitt
2024-07-08 21:15   ` David Lechner
2024-06-29 19:05 ` [PATCH v6 2/7] spi: bitbang: Implement support for MOSI idle state configuration Marcelo Schmitt
2024-06-30 10:52   ` Jonathan Cameron
2024-07-08 21:19   ` David Lechner
2024-06-29 19:05 ` [PATCH v6 3/7] spi: spi-gpio: Add " Marcelo Schmitt
2024-06-30 10:53   ` Jonathan Cameron
2024-06-29 19:06 ` [PATCH v6 4/7] spi: spi-axi-spi-engine: Add support for MOSI idle configuration Marcelo Schmitt
2024-06-29 19:06 ` [PATCH v6 5/7] dt-bindings: iio: adc: Add AD4000 Marcelo Schmitt
2024-06-29 19:06 ` [PATCH v6 6/7] iio: adc: Add support for AD4000 Marcelo Schmitt
2024-06-30 11:17   ` Jonathan Cameron
2024-07-01 18:10     ` Marcelo Schmitt [this message]
2024-07-01 18:38       ` Mark Brown
2024-07-01 18:47       ` Jonathan Cameron
2024-07-08 21:34   ` David Lechner
2024-07-09  7:41   ` Nuno Sá
2024-06-29 19:07 ` [PATCH v6 7/7] docs: iio: Add documentation " Marcelo Schmitt
2024-07-08 21:25   ` David Lechner
2024-07-29 18:02 ` (subset) [PATCH v6 0/7] Add support for AD4000 series of ADCs Mark Brown
2024-07-29 19:40   ` 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=ZoLxLgpy44S38nSe@debian-BULLSEYE-live-builder-AMD64 \
    --to=marcelo.schmitt1@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=marcelo.schmitt@analog.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