linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Cosmin Tanislav <demonsingur@gmail.com>
Cc: Rob Herring <robh+dt@kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-iio@vger.kernel.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	Cosmin Tanislav <cosmin.tanislav@analog.com>
Subject: Re: [PATCH v3 2/2] iio: adc: ad4130: add AD4130 driver
Date: Sat, 7 May 2022 17:35:51 +0100	[thread overview]
Message-ID: <20220507173551.1bc45a82@jic23-huawei> (raw)
In-Reply-To: <5d932a4a-790e-ca95-c5de-c2267e1f365c@gmail.com>


> >   
> >> +static int ad4130_set_fifo_watermark(struct iio_dev *indio_dev, unsigned int val)
> >> +{
> >> +	struct ad4130_state *st = iio_priv(indio_dev);
> >> +	unsigned int eff;
> >> +	int ret;
> >> +
> >> +	if (val > AD4130_FIFO_SIZE)
> >> +		return -EINVAL;
> >> +
> >> +	/*
> >> +	 * Always set watermark to a multiple of the number of enabled channels
> >> +	 * to avoid making the FIFO unaligned.
> >> +	 */
> >> +	eff = rounddown(val, st->num_enabled_channels);
> >> +
> >> +	mutex_lock(&st->lock);
> >> +
> >> +	ret = regmap_update_bits(st->regmap, AD4130_REG_FIFO_CONTROL,
> >> +				 AD4130_WATERMARK_MASK,
> >> +				 FIELD_PREP(AD4130_WATERMARK_MASK,
> >> +					    ad4130_watermark_reg_val(eff)));
> >> +	if (ret)
> >> +		goto out;
> >> +
> >> +	st->effective_watermark = eff;
> >> +	st->watermark = val;  
> > 
> > Hmm this is a potential inconsistency in the IIO ABI.
> > ABI docs describes watermark as being number of 'scan elements' which is
> > not the clearest text we could have gone with...
> > 
> > Now I may well have made a mistake in the following as it's rather a long time
> > since I last looked at the core handling for this...
> > 
> > The core treats it as number datum (which is same as a scan) when using
> > it for the main watermark attribute and also when using watermarks with the
> > kfifo (the IIO fifo is made up of objects each of which is a scan. So kfifo_len()
> > returns the number of scans.
> >   
> > Looking very quickly at a few other drivers
> > adxl367 seems to use number of samples.
> > adxl372 is using number of scans.
> > bmc150 hardware seems to work on basis of frame count which I 'think' is probably scans.
> > fxls8962 uses 'samples count' which is not clearly defined in the datasheet but there
> > is an example showing that it's scans (I think)...
> > lsm6dsx - some of the fifos used with this are based on tagged data so the connection to
> > what hits the front end buffers is non obvious.
> > 
> > So, not great for consistency :(
> > 
> > Going forwards i think we should standardize the hardware fifo watermark on what is being
> > used for the software watermark which I believe is number of scans.
> > Not necessary much we can do about old drivers though due to risk of breaking ABI...
> > We should make the documentation clearer though.
> >   
> 
> I was confused too, but this seemed more logical to me at the time, and
> since you didn't say anything regarding it on ADXL367, I did it the same
> way here. I guess we can't go back and change it now on ADXL367, I'm
> sorry for this. I'll fix it.

I missed it.  Review is never perfect (mine definitely aren't!)

Thinking more on the adxl367. We still have a window to  fix that as
the driver isn't yet in a release kernel.  Would you mind spinning a
patch to fix that one?  Even if we miss the rc cycle (it's a bit tight
timing wise) we can sneak it in as an early fix in stable without
significant risk of breaking anyone's userspace.

There might be other drivers that have that interpretation we can't
fix but if we can reduce the scope of the problem by changing the adxl367
that would be great.

We should also definitely improve the docs and perhaps add a note to say
that due to need to maintain ABI, a few drivers use scans * number of channels
rather than scans.

> 
> >> +
> >> +out:
> >> +	mutex_unlock(&st->lock);
> >> +
> >> +	return ret;
> >> +}
> >> +  
> > 
> > 
> > ...
> >   
> >> +
> >> +static int ad4130_parse_fw_channel(struct iio_dev *indio_dev,
> >> +				   struct fwnode_handle *child)
> >> +{
> >> +	struct ad4130_state *st = iio_priv(indio_dev);
> >> +	unsigned int index = indio_dev->num_channels++;
> >> +	struct device *dev = &st->spi->dev;
> >> +	struct ad4130_chan_info *chan_info;
> >> +	struct iio_chan_spec *chan;
> >> +	u32 pins[2];
> >> +	int ret;
> >> +
> >> +	if (index >= AD4130_MAX_CHANNELS)
> >> +		return dev_err_probe(dev, -EINVAL, "Too many channels\n");
> >> +
> >> +	chan = &st->chans[index];
> >> +	chan_info = &st->chans_info[index];
> >> +
> >> +	*chan = ad4130_channel_template;
> >> +	chan->scan_type.realbits = st->chip_info->resolution;
> >> +	chan->scan_type.storagebits = st->chip_info->resolution;
> >> +	chan->scan_index = index;
> >> +
> >> +	chan_info->slot = AD4130_INVALID_SLOT;
> >> +	chan_info->setup.fs = AD4130_FS_MIN;
> >> +	chan_info->initialized = true;
> >> +
> >> +	ret = fwnode_property_read_u32_array(child, "diff-channels", pins,
> >> +					     ARRAY_SIZE(pins));
> >> +	if (ret)
> >> +		return ret;
> >> +
> >> +	ret = ad4130_validate_diff_channels(st, pins, ARRAY_SIZE(pins));
> >> +	if (ret)
> >> +		return ret;
> >> +
> >> +	chan->channel = pins[0];
> >> +	chan->channel2 = pins[1];
> >> +
> >> +	ret = ad4130_parse_fw_setup(st, child, &chan_info->setup);
> >> +	if (ret)
> >> +		return ret;
> >> +
> >> +	fwnode_property_read_u32(child, "adi,excitation-pin-0",
> >> +				 &chan_info->iout0);
> >> +	if (chan_info->setup.iout0_val != AD4130_IOUT_OFF) {  
> > 
> > It would be slightly better to set an explicit default value here as the fact it
> > is 0 is hidden by the enum. e.g.
> > 	chan_info->iout0 = AD4130_IOUT_OFF;
> > 	fwnode_property_read_u32(child, "adi,excitation-pin-0",
> > 			 	 &chan_info->iout0);
> > 	if (chan_info->....
> > That would save reviewers wondering what the default is and having to go
> > check the enum (and I'm lazy :)  
> 
> I understand the idea, but the default value for iout0 is not
> AD4130_IOUT_OFF. iout0 is the pin that iout0_val current is
> applied to, and AD4130_IOUT_OFF is a value for iout0_val.
> Look at ad4130_parse_fw_setup.
> 
> For iout0, I guess I could do
> #define AD4130_AIN0	0x0
> ...
> chan_info->iout0 = AD4130_AIN0;

Oops.  I got confused.  Code is fine as it is.  Adding the define isn't going to make
it much clearer.
 
> 
> >> +		}
> >> +	}
> >> +
> >> +	return ret;
> >> +}
> >> +


  reply	other threads:[~2022-05-07 16:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19 15:08 [PATCH v3 0/2] AD4130 Cosmin Tanislav
2022-04-19 15:08 ` [PATCH v3 1/2] dt-bindings: iio: adc: add AD4130 Cosmin Tanislav
2022-04-26  0:37   ` Rob Herring
2022-04-27 12:47     ` Cosmin Tanislav
2022-04-27 21:41       ` Rob Herring
2022-06-08  8:31     ` Cosmin Tanislav
2022-05-01 16:09   ` Jonathan Cameron
2022-04-19 15:08 ` [PATCH v3 2/2] iio: adc: ad4130: add AD4130 driver Cosmin Tanislav
2022-05-01 16:08   ` Jonathan Cameron
2022-05-02  8:53     ` Cosmin Tanislav
2022-05-07 16:35       ` Jonathan Cameron [this message]
2022-05-07 16:49         ` Cosmin Tanislav
2022-05-07 17:04           ` Jonathan Cameron
2022-05-14 13:32             ` Cosmin Tanislav
2022-05-14 16:24               ` Jonathan Cameron

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=20220507173551.1bc45a82@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=cosmin.tanislav@analog.com \
    --cc=demonsingur@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.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).