devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Stefan Popa <stefan.popa@analog.com>
Cc: broonie@kernel.org, lars@metafoo.de,
	Michael.Hennerich@analog.com, knaack.h@gmx.de, pmeerw@pmeerw.net,
	mark.rutland@arm.com, davem@davemloft.net,
	mchehab+samsung@kernel.org, gregkh@linuxfoundation.org,
	akpm@linux-foundation.org, robh+dt@kernel.org,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 6/6] iio:adxl372: Add filter bandwidth support
Date: Fri, 3 Aug 2018 22:32:33 +0100	[thread overview]
Message-ID: <20180803223233.13641247@archlinux> (raw)
In-Reply-To: <1533301341-26560-7-git-send-email-stefan.popa@analog.com>

On Fri, 3 Aug 2018 16:02:21 +0300
Stefan Popa <stefan.popa@analog.com> wrote:

> This patch adds the option for the user to select the filter bandwidth. The
> user can also read the available bandwidths which are always adjusted to be
> at most half of the sampling frequency. Furthermore, the currently selected
> bandwidth can be read via the read_raw function, while the write_raw sets a
> new bandwidth value.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Another good one.  Same comment as previous :)

Jonathan

> ---
>  drivers/iio/accel/adxl372.c | 38 ++++++++++++++++++++++++++++++++++++--
>  1 file changed, 36 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
> index 80b1838..3a9d55a 100644
> --- a/drivers/iio/accel/adxl372.c
> +++ b/drivers/iio/accel/adxl372.c
> @@ -196,6 +196,10 @@ static const int adxl372_samp_freq_tbl[5] = {
>  	400, 800, 1600, 3200, 6400,
>  };
>  
> +static const int adxl372_bw_freq_tbl[5] = {
> +	200, 400, 800, 1600, 3200,
> +};
> +
>  struct adxl372_axis_lookup {
>  	unsigned int bits;
>  	enum adxl372_fifo_format fifo_format;
> @@ -218,7 +222,8 @@ static const struct adxl372_axis_lookup adxl372_axis_lookup_table[] = {
>  	.channel2 = IIO_MOD_##axis,					\
>  	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
>  	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |		\
> -				    BIT(IIO_CHAN_INFO_SAMP_FREQ),	\
> +				    BIT(IIO_CHAN_INFO_SAMP_FREQ) |	\
> +		BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),	\
>  	.scan_index = index,						\
>  	.scan_type = {							\
>  		.sign = 's',						\
> @@ -656,6 +661,9 @@ static int adxl372_read_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_SAMP_FREQ:
>  		*val = adxl372_samp_freq_tbl[st->odr];
>  		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> +		*val = adxl372_bw_freq_tbl[st->bw];
> +		return IIO_VAL_INT;
>  	}
>  
>  	return -EINVAL;
> @@ -666,7 +674,7 @@ static int adxl372_write_raw(struct iio_dev *indio_dev,
>  			     int val, int val2, long info)
>  {
>  	struct adxl372_state *st = iio_priv(indio_dev);
> -	int odr_index, ret;
> +	int odr_index, bw_index, ret;
>  
>  	switch (info) {
>  	case IIO_CHAN_INFO_SAMP_FREQ:
> @@ -698,11 +706,34 @@ static int adxl372_write_raw(struct iio_dev *indio_dev,
>  			ret = adxl372_set_bandwidth(st, odr_index);
>  
>  		return ret;
> +	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> +		bw_index = adxl372_find_closest_match(adxl372_bw_freq_tbl,
> +					ARRAY_SIZE(adxl372_bw_freq_tbl),
> +					val);
> +		return adxl372_set_bandwidth(st, bw_index);
>  	default:
>  		return -EINVAL;
>  	}
>  }
>  
> +static ssize_t adxl372_show_filter_freq_avail(struct device *dev,
> +					      struct device_attribute *attr,
> +					      char *buf)
> +{
> +	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> +	struct adxl372_state *st = iio_priv(indio_dev);
> +	int i;
> +	size_t len = 0;
> +
> +	for (i = 0; i <= st->odr; i++)
> +		len += scnprintf(buf + len, PAGE_SIZE - len,
> +				 "%d ", adxl372_bw_freq_tbl[i]);
> +
> +	buf[len - 1] = '\n';
> +
> +	return len;
> +}
> +
>  static ssize_t adxl372_get_fifo_enabled(struct device *dev,
>  					  struct device_attribute *attr,
>  					  char *buf)
> @@ -826,9 +857,12 @@ static const struct iio_trigger_ops adxl372_trigger_ops = {
>  };
>  
>  static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("400 800 1600 3200 6400");
> +static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available,
> +		       0444, adxl372_show_filter_freq_avail, NULL, 0);
>  
>  static struct attribute *adxl372_attributes[] = {
>  	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
> +	&iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr,
>  	NULL,
>  };
>  

      reply	other threads:[~2018-08-03 21:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-03 13:02 [PATCH v3 0/6] iio: accel: Add adxl372 driver Stefan Popa
2018-08-03 13:02 ` [PATCH v3 1/6] iio: adxl372: New driver for Analog Devices ADXL372 Accelerometer Stefan Popa
2018-08-03 21:22   ` Jonathan Cameron
2018-08-03 13:02 ` [PATCH v3 2/6] dt-bindings: iio: accel: Add docs for ADXL372 Stefan Popa
2018-08-03 21:23   ` Jonathan Cameron
2018-08-03 13:02 ` [PATCH v3 3/6] regmap: Add regmap_noinc_read API Stefan Popa
2018-08-03 21:26   ` Jonathan Cameron
2018-08-06 10:25   ` Charles Keepax
2018-08-03 13:02 ` [PATCH v3 4/6] iio:adxl372: Add FIFO and interrupts support Stefan Popa
2018-08-03 21:30   ` Jonathan Cameron
2018-08-03 13:02 ` [PATCH v3 5/6] iio:adxl372: Add sampling frequency support Stefan Popa
2018-08-03 21:31   ` Jonathan Cameron
2018-08-03 13:02 ` [PATCH v3 6/6] iio:adxl372: Add filter bandwidth support Stefan Popa
2018-08-03 21:32   ` Jonathan Cameron [this message]

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=20180803223233.13641247@archlinux \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=akpm@linux-foundation.org \
    --cc=broonie@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mchehab+samsung@kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=stefan.popa@analog.com \
    /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).