All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Sean Nyekjaer <sean.nyekjaer@prevas.dk>
Cc: pmeerw@pmeerw.net, linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: adc: ti-ads8688: use the auto sequence feature
Date: Sun, 3 Jun 2018 16:28:35 +0100	[thread overview]
Message-ID: <20180603162835.59676a01@archlinux> (raw)
In-Reply-To: <20180530211821.8496-1-sean.nyekjaer@prevas.dk>

On Wed, 30 May 2018 23:18:21 +0200
Sean Nyekjaer <sean.nyekjaer@prevas.dk> wrote:

> The TI ADS8688 have a auto sequence feature that allows
> to continuesly reading new values from the chosen channels.
> Lets enable it and we will be able to sample at the double speed
> vs the old implementation
> 
> Signed-off-by: Sean Nyekjaer <sean.nyekjaer@prevas.dk>

hmm. Technically it's an ABI change as someone may be relying on the
ability to do sysfs reads whilst we are also using the chardev interface.
However, I doubt anyone is so lest see if anyone notices ;)

One comment inline. Otherwise looks fine to me.

With care, we could gotten the speed up without using autosequencing
but that doesn't really matter as that isn't what we were doing previously.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/ti-ads8688.c | 60 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 59 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c
> index 184d686ebd99..8e18c0caa1d7 100644
> --- a/drivers/iio/adc/ti-ads8688.c
> +++ b/drivers/iio/adc/ti-ads8688.c
> @@ -25,10 +25,12 @@
>  #define ADS8688_CMD_REG(x)		(x << 8)
>  #define ADS8688_CMD_REG_NOOP		0x00
>  #define ADS8688_CMD_REG_RST		0x85
> +#define ADS8688_CMD_REG_AUTO_RST	0xA0
>  #define ADS8688_CMD_REG_MAN_CH(chan)	(0xC0 | (4 * chan))
>  #define ADS8688_CMD_DONT_CARE_BITS	16
>  
>  #define ADS8688_PROG_REG(x)		(x << 9)
> +#define ADS8688_AUTO_SEQ_EN		0x01
>  #define ADS8688_PROG_REG_RANGE_CH(chan)	(0x05 + chan)
>  #define ADS8688_PROG_WR_BIT		BIT(8)
>  #define ADS8688_PROG_DONT_CARE_BITS	8
> @@ -210,6 +212,39 @@ static int ads8688_reset(struct iio_dev *indio_dev)
>  	return spi_write(st->spi, &st->data[0].d8[0], 4);
>  }
>  
> +static int ads8688_start_autoseq(struct iio_dev *indio_dev)
> +{
> +	struct ads8688_state *st = iio_priv(indio_dev);
> +	u32 tmp;
> +
> +	tmp = ADS8688_CMD_REG(ADS8688_CMD_REG_AUTO_RST);
> +	tmp <<= ADS8688_CMD_DONT_CARE_BITS;
> +	st->data[0].d32 = cpu_to_be32(tmp);
> +
> +	return spi_write(st->spi, &st->data[0].d8[0], 4);
> +}
> +
> +static int ads8688_read_autoseq(struct iio_dev *indio_dev)
> +{
> +	struct ads8688_state *st = iio_priv(indio_dev);
> +	int ret;
> +	u32 tmp;
> +	struct spi_transfer t = {
> +		.tx_buf = &st->data[0].d8[0],
> +		.len = 4,
> +	};
> +
> +	tmp = ADS8688_CMD_REG(ADS8688_CMD_REG_NOOP);
> +	tmp <<= ADS8688_CMD_DONT_CARE_BITS;
> +	st->data[0].d32 = cpu_to_be32(tmp);
> +
> +	ret = spi_sync_transfer(st->spi, &t, 1);
> +	if (ret < 0)
> +		return ret;
> +
> +	return be32_to_cpu(st->data[0].d32) & 0xffff;
> +}
> +
>  static int ads8688_read(struct iio_dev *indio_dev, unsigned int chan)
>  {
>  	struct ads8688_state *st = iio_priv(indio_dev);
> @@ -251,6 +286,10 @@ static int ads8688_read_raw(struct iio_dev *indio_dev,
>  
>  	struct ads8688_state *st = iio_priv(indio_dev);
>  
> +	/* Block raw reading when in triggered mode */
> +	if (iio_buffer_enabled(indio_dev))
> +		return -EBUSY;
> +
>  	mutex_lock(&st->lock);
>  	switch (m) {
>  	case IIO_CHAN_INFO_RAW:
> @@ -299,6 +338,10 @@ static int ads8688_write_raw(struct iio_dev *indio_dev,
>  	unsigned int scale = 0;
>  	int ret = -EINVAL, i, offset = 0;
>  
> +	/* Block setup when in triggered mode */
> +	if (iio_buffer_enabled(indio_dev))
> +		return -EBUSY;
> +
>  	mutex_lock(&st->lock);
>  	switch (mask) {
>  	case IIO_CHAN_INFO_SCALE:
> @@ -374,10 +417,25 @@ static int ads8688_write_raw_get_fmt(struct iio_dev *indio_dev,
>  	return -EINVAL;
>  }
>  
> +static int ads8688_update_scan_mode(struct iio_dev *indio_dev,
> +	const unsigned long *active_scan_mask)
> +{
> +	int scan_count;
> +
> +	scan_count = bitmap_weight(active_scan_mask, indio_dev->masklength);

What is scan_count for?

> +
> +	ads8688_prog_write(indio_dev, ADS8688_AUTO_SEQ_EN, (int)active_scan_mask);
> +
> +	ads8688_start_autoseq(indio_dev);
> +
> +	return 0;
> +}
> +
>  static const struct iio_info ads8688_info = {
>  	.read_raw = &ads8688_read_raw,
>  	.write_raw = &ads8688_write_raw,
>  	.write_raw_get_fmt = &ads8688_write_raw_get_fmt,
> +	.update_scan_mode = ads8688_update_scan_mode,
>  	.attrs = &ads8688_attribute_group,
>  };
>  
> @@ -391,7 +449,7 @@ static irqreturn_t ads8688_trigger_handler(int irq, void *p)
>  	for (i = 0; i < indio_dev->masklength; i++) {
>  		if (!test_bit(i, indio_dev->active_scan_mask))
>  			continue;
> -		buffer[j] = ads8688_read(indio_dev, i);
> +		buffer[j] = ads8688_read_autoseq(indio_dev);

>  		j++;
>  	}
>  


  reply	other threads:[~2018-06-03 15:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-30 21:18 [PATCH] iio: adc: ti-ads8688: use the auto sequence feature Sean Nyekjaer
2018-06-03 15:28 ` Jonathan Cameron [this message]
2018-06-04  5:21   ` Sean Nyekjær
2018-06-04 12:38     ` 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=20180603162835.59676a01@archlinux \
    --to=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=sean.nyekjaer@prevas.dk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.