public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Mike Looijmans <mike.looijmans@topic.nl>,
	devicetree@vger.kernel.org, linux-iio@vger.kernel.org,
	AngeloGioacchino Del Regno 
	<angelogioacchino.delregno@collabora.com>,
	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>,
	Marcus Folkesson <marcus.folkesson@gmail.com>,
	Ramona Bolboaca <ramona.bolboaca@analog.com>,
	William Breathitt Gray <william.gray@linaro.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/2] iio: adc: Add TI ADS1100 and ADS1000
Date: Sun, 12 Mar 2023 14:57:47 +0000	[thread overview]
Message-ID: <20230312145747.268ae10a@jic23-huawei> (raw)
In-Reply-To: <ZActDOEsT+tNMfZ1@smile.fi.intel.com>

On Tue, 7 Mar 2023 14:24:44 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Tue, Mar 07, 2023 at 07:55:34AM +0100, Mike Looijmans wrote:
> > The ADS1100 is a 16-bit ADC (at 8 samples per second).
> > The ADS1000 is similar, but has a fixed data rate.  
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> But see below.

I tidied that up and made a few other trivial whitespace tweaks whilst
applying.

Applied to the togreg branch of iio.git and pushed out as testing for 0-day
to see if it can find anything we missed.

Thanks,

Jonathan

> 
> > Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>

> > +
> > +static int ads1100_set_scale(struct ads1100_data *data, int val, int val2)
> > +{
> > +	int microvolts;
> > +	int gain;
> > +
> > +	/* With Vdd between 2.7 and 5V, the scale is always below 1 */
> > +	if (val)
> > +		return -EINVAL;
> > +
> > +	if (!val2)
> > +		return -EINVAL;
> > +
> > +	microvolts = regulator_get_voltage(data->reg_vdd);
> > +	/*
> > +	 * val2 is in 'micro' units, n = val2 / 1000000
> > +	 * result must be millivolts, d = microvolts / 1000
> > +	 * the full-scale value is d/n, corresponds to 2^15,
> > +	 * hence the gain = (d / n) >> 15, factoring out the 1000 and moving the
> > +	 * bitshift so everything fits in 32-bits yields this formula.
> > +	 */
> > +	gain = DIV_ROUND_CLOSEST(microvolts, BIT(15)) * MILLI / val2;
> > +	if (gain < BIT(0) || gain > BIT(3))
> > +		return -EINVAL;
> > +
> > +	ads1100_set_config_bits(data, ADS1100_PGA_MASK, ffs(gain) - 1);

I added a blank line here and in one other place for consistency + I like
them before simple return statements.

> > +	return 0;
> > +}
> > +
> > +static int ads1100_set_data_rate(struct ads1100_data *data, int chan, int rate)
> > +{
> > +	unsigned int i;
> > +	unsigned int size;
> > +
> > +	size = data->supports_data_rate ? ARRAY_SIZE(ads1100_data_rate) : 1;
> > +	for (i = 0; i < size; i++) {
> > +		if (ads1100_data_rate[i] == rate)
> > +			return ads1100_set_config_bits(data, ADS1100_DR_MASK,  
> 
> > +						       FIELD_PREP
> > +						       (ADS1100_DR_MASK, i));  
> 
> This is better on a single line.

Fixed up whilst applying.

> 
> > +	}
> > +
> > +	return -EINVAL;
> > +}
> > +



      reply	other threads:[~2023-03-12 14:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.5423d502-0a89-419b-9ff2-cfd5bf0311ce@emailsignatures365.codetwo.com>
2023-03-07  6:55 ` [PATCH v5 1/2] dt-bindings: iio: adc: Add TI ADS1100 and ADS1000 Mike Looijmans
2023-03-07  6:55   ` [PATCH v5 2/2] " Mike Looijmans
2023-03-07 12:24     ` Andy Shevchenko
2023-03-12 14:57       ` Jonathan Cameron [this message]

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=20230312145747.268ae10a@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Ibrahim.Tilki@analog.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=angelogioacchino.delregno@collabora.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=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcus.folkesson@gmail.com \
    --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