[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y+9zR3bhlEMuma66@smile.fi.intel.com>
Date: Fri, 17 Feb 2023 14:29:59 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Mike Looijmans <mike.looijmans@...ic.nl>
Cc: devicetree@...r.kernel.org, linux-iio@...r.kernel.org,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@...labora.com>,
Caleb Connolly <caleb.connolly@...aro.org>,
ChiYuan Huang <cy_huang@...htek.com>,
ChiaEn Wu <chiaen_wu@...htek.com>,
Cosmin Tanislav <demonsingur@...il.com>,
Geert Uytterhoeven <geert+renesas@...der.be>,
Ibrahim Tilki <Ibrahim.Tilki@...log.com>,
Jonathan Cameron <jic23@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>,
Marcelo Schmitt <marcelo.schmitt1@...il.com>,
Ramona Bolboaca <ramona.bolboaca@...log.com>,
William Breathitt Gray <william.gray@...aro.org>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] iio: adc: Add driver for TI ADS1100 and ADS1000 chips
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@...ic.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
Powered by blists - more mailing lists