Linux IIO development
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mike Looijmans <mike.looijmans@topic.nl>
Cc: 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>,
	Jonathan Cameron <jic23@kernel.org>,
	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: Wed, 1 Mar 2023 17:30:03 +0200	[thread overview]
Message-ID: <Y/9vez/fzLD5dRVF@smile.fi.intel.com> (raw)
In-Reply-To: <20230228063151.17598-2-mike.looijmans@topic.nl>

On Tue, Feb 28, 2023 at 07:31:51AM +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.

...

> +	/* 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);

?

(Double check for off-by-one usage)

...

> +	/* Calculate: gain = ((microvolts / 1000) / (val2 / 1000000)) >> 15 */

Can you use more math / plain English to describe the formula? Otherwise we can
see the very same in the code and point of the comment is doubtful.

> +	gain = ((microvolts + BIT(14)) >> 15) * 1000 / val2;

Something from units.h?

...

> +	for (i = 0; i < 4; i++) {
> +		if (BIT(i) == gain) {

ffs()/__ffs() (look at the documentation for the difference and use proper one).

> +			ads1100_set_config_bits(data, ADS1100_PGA_MASK, i);
> +			return 0;
> +		}
> +	}

...

> +	for (i = 0; i < size; ++i) {

Why pre-increment?

> +		if (ads1100_data_rate[i] == rate) {
> +			return ads1100_set_config_bits(
> +					data, ADS1100_DR_MASK,

Strange indentation.

> +					FIELD_PREP(ADS1100_DR_MASK, i));
> +		}

Do you need {} ?

> +	}

...

> +	int millivolts = regulator_get_voltage(data->reg_vdd) / 1000;

units.h?

...

> +		data->scale_avail[i * 2] = millivolts;

I would write ' * 2 + 0]', but it's up to you.

> +		data->scale_avail[i * 2 + 1] = 15 + i;

...

> +		*val = regulator_get_voltage(data->reg_vdd) / 1000;

units.h?

...

> +		*val = ads1100_data_rate[
> +				FIELD_GET(ADS1100_DR_MASK, data->config)];

Strange indentation, just use a single line.

...

> +	ret = devm_iio_device_register(dev, indio_dev);
> +	if (ret < 0)

Why ' < 0'?

> +		return dev_err_probe(dev, ret,
> +				     "Failed to register IIO device\n");

...

> +static int ads1100_runtime_suspend(struct device *dev)
> +{
> +	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> +	struct ads1100_data *data = iio_priv(indio_dev);
> +
> +	ads1100_set_config_bits(data, ADS1100_CFG_SC, ADS1100_SINGLESHOT);
> +	regulator_disable(data->reg_vdd);

Wrong devm / non-devm ordering.

> +	return 0;
> +}

...

> +static const struct i2c_device_id ads1100_id[] = {
> +	{ "ads1100", },
> +	{ "ads1000", },

Inner commas are not needed.

> +	{}
> +};

...

> +static const struct of_device_id ads1100_of_match[] = {
> +	{ .compatible = "ti,ads1100", },
> +	{ .compatible = "ti,ads1000", },

Ditto.

> +	{}
> +};

...

> +

Redundant blank line.

> +module_i2c_driver(ads1100_driver);

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-03-01 15:30 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 [this message]
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
2023-03-04 17:57   ` Jonathan Cameron
2023-03-06  6:31     ` Mike Looijmans
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
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=Y/9vez/fzLD5dRVF@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