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,
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>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Ibrahim Tilki <Ibrahim.Tilki@analog.com>,
Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Marcelo Schmitt <marcelo.schmitt1@gmail.com>,
Ramona Bolboaca <ramona.bolboaca@analog.com>,
William Breathitt Gray <william.gray@linaro.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: adc: Add driver for TI ADS1100 and ADS1000 chips
Date: Fri, 17 Feb 2023 14:29:59 +0200 [thread overview]
Message-ID: <Y+9zR3bhlEMuma66@smile.fi.intel.com> (raw)
In-Reply-To: <20230217093128.8344-2-mike.looijmans@topic.nl>
On Fri, Feb 17, 2023 at 10:31:28AM +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.
Any Datasheet link available?
> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
...
> +#define ADS1100_DR_MASK (BIT(3) | BIT(2))
GENMASK()
...
> +#define ADS1100_PGA_MASK (BIT(1) | BIT(0))
Ditto.
...
> +static const int ads1100_data_rate[] = {128, 32, 16, 8};
> +static const int ads1100_data_rate_scale[] = {2048, 8192, 16384, 32768};
> +static const int ads1100_gain[] = {1, 2, 4, 8};
Do you need all of them as tables? They all can be derived from a single table
or without any table at all (just three values).
...
> +static const struct iio_chan_spec ads1100_channel = {
> + .type = IIO_VOLTAGE,
> + .differential = 0,
> + .indexed = 0,
No need.
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + .info_mask_shared_by_all =
> + BIT(IIO_CHAN_INFO_SCALE) |
> + BIT(IIO_CHAN_INFO_HARDWAREGAIN) |
> + BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + .info_mask_shared_by_all_available =
> + BIT(IIO_CHAN_INFO_HARDWAREGAIN) |
> + BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + .scan_type = {
> + .sign = 's',
> + .realbits = 16,
> + .storagebits = 16,
> + .shift = 0,
No need.
> + .endianness = IIO_CPU,
> + },
> + .datasheet_name = "AIN",
> +};
...
> + u8 config = (data->config & ~mask) | value;
Traditional pattern is
u8 config = (data->config & ~mask) | (value & mask);
> +#ifdef CONFIG_PM
Why?
> +static int ads1100_set_power_state(struct ads1100_data *data, bool on)
> +{
> + int ret;
> + struct device *dev = &data->client->dev;
> +
> + if (on) {
> + ret = pm_runtime_resume_and_get(dev);
> + } else {
> + pm_runtime_mark_last_busy(dev);
> + ret = pm_runtime_put_autosuspend(dev);
Yes, in !CONFIG_PM this will return an error, but why do you care?
> + }
> +
> + return ret < 0 ? ret : 0;
> +}
> +
> +#else /* !CONFIG_PM */
> +
> +static int ads1100_set_power_state(struct ads1100_data *data, bool on)
> +{
> + return 0;
> +}
> +
> +#endif /* !CONFIG_PM */
...
> +static int ads1100_get_adc_result(struct ads1100_data *data, int chan, int *val)
> +{
> + int ret;
> + u8 buffer[2];
__be16 buffer;
> +
> + if (chan != 0)
> + return -EINVAL;
> +
> + ret = i2c_master_recv(data->client, buffer, sizeof(buffer));
> + if (ret < 0) {
> + dev_err(&data->client->dev, "I2C read fail: %d\n", ret);
> + return ret;
> + }
> +
> + *val = (s16)(((u16)buffer[0] << 8) | buffer[1]);
(s16)be16_to_cpu();
But (s16) looks suspicious. Should you use sign_extend32()?
> + return 0;
> +}
...
> +static int ads1100_set_gain(struct ads1100_data *data, int gain)
> +{
> + int i;
unsigned
> + for (i = 0; i < ARRAY_SIZE(ads1100_gain); ++i) {
Pre-increment in the loops is non-standard in the kernel.
Why do you need that?
> + if (ads1100_gain[i] == gain) {
> + return ads1100_set_config_bits(
> + data, ADS1100_PGA_MASK, i);
Strange indentation.
> + }
> + }
> +
> + return -EINVAL;
> +}
...
> +static int ads1100_set_data_rate(struct ads1100_data *data, int chan, int rate)
Same comments as per above.
...
> + dev_info(&data->client->dev, "%s %ld\n", __func__, mask);
Useless noise in the logs.
...
> + ret = iio_device_register(indio_dev);
> + if (ret < 0) {
> + dev_err(&client->dev, "Failed to register IIO device\n");
> + return ret;
return dev_err_probe();
> + }
...
> +#ifdef CONFIG_PM
Drop it and use proper macros below.
> +#endif
...
> +static const struct dev_pm_ops ads1100_pm_ops = {
> + SET_RUNTIME_PM_OPS(ads1100_runtime_suspend,
> + ads1100_runtime_resume, NULL)
> +};
...here and...
...
> + .pm = &ads1100_pm_ops,
...here.
...
> +
Redundant blank line.
> +module_i2c_driver(ads1100_driver);
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2023-02-17 12:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-17 9:31 [PATCH 1/2] dt-bindings: iio: adc: Add driver for TI ADS1100 and ADS1000 Mike Looijmans
2023-02-17 9:31 ` [PATCH 2/2] iio: adc: Add driver for TI ADS1100 and ADS1000 chips Mike Looijmans
2023-02-17 12:29 ` Andy Shevchenko [this message]
[not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.9c64e84d-a2fd-448c-9100-2fa583a49f45@emailsignatures365.codetwo.com>
2023-02-17 15:10 ` Mike Looijmans
2023-02-18 16:48 ` Jonathan Cameron
[not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.02fda1de-62d6-4f7a-9537-1a2cd4a482bd@emailsignatures365.codetwo.com>
2023-02-25 11:03 ` Mike Looijmans
2023-02-25 17:01 ` Jonathan Cameron
2023-02-26 8:24 ` Mike Looijmans
2023-02-26 12:53 ` Jonathan Cameron
2023-02-17 9:36 ` [PATCH 1/2] dt-bindings: iio: adc: Add driver for TI ADS1100 and ADS1000 Krzysztof Kozlowski
[not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.f5b3563c-3030-4c7b-8162-00135fd9d2e4@emailsignatures365.codetwo.com>
2023-02-17 14:17 ` Mike Looijmans
2023-02-17 13:47 ` Rob Herring
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+9zR3bhlEMuma66@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=Ibrahim.Tilki@analog.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=geert+renesas@glider.be \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@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;
as well as URLs for NNTP newsgroup(s).