devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Mike Looijmans <mike.looijmans@topic.nl>,
	devicetree@vger.kernel.org, linux-iio@vger.kernel.org,
	Caleb Connolly <caleb.connolly@linaro.org>,
	ChiYuan Huang <cy_huang@richtek.com>,
	ChiaEn Wu <chiaen_wu@richtek.com>,
	Cosmin Tanislav <demonsingur@gmail.com>,
	Ibrahim Tilki <Ibrahim.Tilki@analog.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Ramona Bolboaca <ramona.bolboaca@analog.com>,
	William Breathitt Gray <william.gray@linaro.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] iio: adc: Add TI ADS1100 and ADS1000
Date: Mon, 6 Mar 2023 14:09:19 +0200	[thread overview]
Message-ID: <ZAXX79Mix85gv0eA@smile.fi.intel.com> (raw)
In-Reply-To: <20230304172618.37f448d0@jic23-huawei>

On Sat, Mar 04, 2023 at 05:26:18PM +0000, Jonathan Cameron wrote:
> On Thu, 2 Mar 2023 16:23:14 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > On Thu, Mar 02, 2023 at 08:49:22AM +0100, Mike Looijmans wrote:
> > > On 01-03-2023 16:30, Andy Shevchenko wrote:  
> > > > On Tue, Feb 28, 2023 at 07:31:51AM +0100, Mike Looijmans wrote:  

...

> > > > > +	/* Shift result to compensate for bit resolution vs. sample rate */
> > > > > +	value <<= 16 - ads1100_data_bits(data);
> > > > > +	*val = sign_extend32(value, 15);  
> > > > Why not simply
> > > > 
> > > > 	*val = sign_extend32(value, ads1100_data_bits(data) - 1);
> > > > 
> > > > ?  
> > > 
> > > As discussed with  Jonathan Cameron, the register is right-justified and the
> > > number of bits depend on the data rate. Rather than having the "scale"
> > > change when the sample rate changes, we chose to adjust the sample result so
> > > it's always left-justified.  
> > 
> > Hmm... OK, but it adds unneeded code I think.
> 
> There isn't a way to do it in one go that I can think of.
> The first statement is multiplying the value by a power of 2, not just sign extending it.
> You could sign extend first then shift to do the multiply, but ends up same amount
> of code.
> 
> It does look a bit like a weird open coded sign extension though so I can see where
> the confusion came from!

I see, for the negative value both approaches will work, for the positive
the original one will provide a multiplied value.

Yeah, doesn't seem to be a subject to the (micro-)optimizations.

...

> > > > > +	for (i = 0; i < 4; i++) {
> > > > > +		if (BIT(i) == gain) {  
> > > > ffs()/__ffs() (look at the documentation for the difference and use proper one).  
> > > 
> > > Thought of it, but I'd rather have it return EINVAL for attempting to set
> > > the analog gain to "7" (0nly 1,2,4,8 allowed).  
> > 
> > I'm not sure what you are implying.
> > 
> > You have open coded something that has already to be a function which on some
> > architectures become a single assembly instruction.
> > 
> > That said, drop your for-loop if-cond and use one of the proposed directly.
> > Then you may compare the result to what ever you want to be a limit and return
> > whatever error code you want to
> 
> Agreed, could do it with appropriate ffs() followed by if (BIT(i) != gain) return -EINVAL;

I meant something different.

	i = ffs(gain); // or __ffs(gain)?
	if (i >= 4)
		return -EINVAL;

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-03-06 12:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28  6:31 [PATCH v3 1/2] dt-bindings: iio: adc: Add TI ADS1100 and ADS1000 Mike Looijmans
2023-02-28  6:31 ` [PATCH v3 2/2] " Mike Looijmans
2023-03-01 15:30   ` Andy Shevchenko
     [not found]     ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.0685d97e-4a28-499e-a9e3-3bafec126832@emailsignatures365.codetwo.com>
2023-03-02  7:49       ` Mike Looijmans
2023-03-02 13:16         ` Lars-Peter Clausen
2023-03-02 13:20           ` Lars-Peter Clausen
2023-03-02 14:24             ` Andy Shevchenko
2023-03-04 17:19             ` Jonathan Cameron
2023-03-02 14:23         ` Andy Shevchenko
2023-03-04 17:26           ` Jonathan Cameron
2023-03-06 12:09             ` Andy Shevchenko [this message]
2023-03-04 17:57   ` Jonathan Cameron
     [not found]     ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.1e5d3371-10e4-4627-b16c-6b250afbb522@emailsignatures365.codetwo.com>
2023-03-06  6:31       ` Mike Looijmans
     [not found]     ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.c6259f01-fccb-4a0c-a50a-69f2dcd4ea5b@emailsignatures365.codetwo.com>
2023-03-06 11:21       ` Mike Looijmans
2023-03-12 14:53         ` Jonathan Cameron
2023-03-06 12:11     ` Andy Shevchenko
2023-03-06 12:16       ` Andy Shevchenko
2023-03-06 12:20         ` Andy Shevchenko
     [not found]       ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.be34025c-a863-4735-b566-67fda50f37f8@emailsignatures365.codetwo.com>
2023-03-06 12:56         ` Mike Looijmans
2023-03-06 13:19           ` Andy Shevchenko
2023-02-28 10:34 ` [PATCH v3 1/2] dt-bindings: " Krzysztof Kozlowski

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=ZAXX79Mix85gv0eA@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=Ibrahim.Tilki@analog.com \
    --cc=caleb.connolly@linaro.org \
    --cc=chiaen_wu@richtek.com \
    --cc=cy_huang@richtek.com \
    --cc=demonsingur@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mike.looijmans@topic.nl \
    --cc=ramona.bolboaca@analog.com \
    --cc=william.gray@linaro.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;
as well as URLs for NNTP newsgroup(s).