From: Jonathan Cameron <jic23@kernel.org>
To: Alexandru Tachici <alexandru.tachici@analog.com>
Cc: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio: adc: ad7124: add 3db filter
Date: Sun, 2 Feb 2020 16:22:15 +0000 [thread overview]
Message-ID: <20200202162215.50915c83@archlinux> (raw)
In-Reply-To: <20200122085414.16950-1-alexandru.tachici@analog.com>
On Wed, 22 Jan 2020 10:54:14 +0200
Alexandru Tachici <alexandru.tachici@analog.com> wrote:
> This patch adds the LOW_PASS_FILTER_3DB_FREQUENCY attribute
> in iio_chan_spec for each channel. The used filters are sinc3
> or sinc4. The filter type with the highest output data rate
> is used when setting a low pass frequency in the channel's sysfs.
>
> Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.
thanks,
Jonathan
> ---
> drivers/iio/adc/ad7124.c | 69 +++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 68 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> index 52f45b13da4a..8f48c0581f02 100644
> --- a/drivers/iio/adc/ad7124.c
> +++ b/drivers/iio/adc/ad7124.c
> @@ -70,6 +70,11 @@
> /* AD7124_FILTER_X */
> #define AD7124_FILTER_FS_MSK GENMASK(10, 0)
> #define AD7124_FILTER_FS(x) FIELD_PREP(AD7124_FILTER_FS_MSK, x)
> +#define AD7124_FILTER_TYPE_MSK GENMASK(23, 21)
> +#define AD7124_FILTER_TYPE_SEL(x) FIELD_PREP(AD7124_FILTER_TYPE_MSK, x)
> +
> +#define AD7124_SINC3_FILTER 2
> +#define AD7124_SINC4_FILTER 0
>
> enum ad7124_ids {
> ID_AD7124_4,
> @@ -119,6 +124,7 @@ struct ad7124_channel_config {
> unsigned int vref_mv;
> unsigned int pga_bits;
> unsigned int odr;
> + unsigned int filter_type;
> };
>
> struct ad7124_state {
> @@ -138,7 +144,8 @@ static const struct iio_chan_spec ad7124_channel_template = {
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> BIT(IIO_CHAN_INFO_SCALE) |
> BIT(IIO_CHAN_INFO_OFFSET) |
> - BIT(IIO_CHAN_INFO_SAMP_FREQ),
> + BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),
> .scan_type = {
> .sign = 'u',
> .realbits = 24,
> @@ -281,6 +288,58 @@ static int ad7124_set_channel_gain(struct ad7124_state *st,
> return 0;
> }
>
> +static int ad7124_get_3db_filter_freq(struct ad7124_state *st,
> + unsigned int channel)
> +{
> + unsigned int fadc;
> +
> + fadc = st->channel_config[channel].odr;
> +
> + switch (st->channel_config[channel].filter_type) {
> + case AD7124_SINC3_FILTER:
> + return DIV_ROUND_CLOSEST(fadc * 230, 1000);
> + case AD7124_SINC4_FILTER:
> + return DIV_ROUND_CLOSEST(fadc * 262, 1000);
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int ad7124_set_3db_filter_freq(struct ad7124_state *st,
> + unsigned int channel,
> + unsigned int freq)
> +{
> + unsigned int sinc4_3db_odr;
> + unsigned int sinc3_3db_odr;
> + unsigned int new_filter;
> + unsigned int new_odr;
> +
> + sinc4_3db_odr = DIV_ROUND_CLOSEST(freq * 1000, 230);
> + sinc3_3db_odr = DIV_ROUND_CLOSEST(freq * 1000, 262);
> +
> + if (sinc4_3db_odr > sinc3_3db_odr) {
> + new_filter = AD7124_SINC3_FILTER;
> + new_odr = sinc4_3db_odr;
> + } else {
> + new_filter = AD7124_SINC4_FILTER;
> + new_odr = sinc3_3db_odr;
> + }
> +
> + if (st->channel_config[channel].filter_type != new_filter) {
> + int ret;
> +
> + st->channel_config[channel].filter_type = new_filter;
> + ret = ad7124_spi_write_mask(st, AD7124_FILTER(channel),
> + AD7124_FILTER_TYPE_MSK,
> + AD7124_FILTER_TYPE_SEL(new_filter),
> + 3);
> + if (ret < 0)
> + return ret;
> + }
> +
> + return ad7124_set_channel_odr(st, channel, new_odr);
> +}
> +
> static int ad7124_read_raw(struct iio_dev *indio_dev,
> struct iio_chan_spec const *chan,
> int *val, int *val2, long info)
> @@ -322,6 +381,9 @@ static int ad7124_read_raw(struct iio_dev *indio_dev,
> case IIO_CHAN_INFO_SAMP_FREQ:
> *val = st->channel_config[chan->address].odr;
>
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> + *val = ad7124_get_3db_filter_freq(st, chan->scan_index);
> return IIO_VAL_INT;
> default:
> return -EINVAL;
> @@ -355,6 +417,11 @@ static int ad7124_write_raw(struct iio_dev *indio_dev,
> gain = DIV_ROUND_CLOSEST(res, val2);
>
> return ad7124_set_channel_gain(st, chan->address, gain);
> + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> + if (val2 != 0)
> + return -EINVAL;
> +
> + return ad7124_set_3db_filter_freq(st, chan->address, val);
> default:
> return -EINVAL;
> }
next prev parent reply other threads:[~2020-02-02 16:22 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-22 8:54 [PATCH] iio: adc: ad7124: add 3db filter Alexandru Tachici
2020-02-02 16:22 ` Jonathan Cameron [this message]
2020-02-05 17:15 ` [PATCH 0/5 V2] iio: adc: ad7192: move out of staging Alexandru Tachici
2020-02-05 17:15 ` [PATCH 1/5 V2] staging: iio: adc: ad7192: fail probe on get_voltage Alexandru Tachici
2020-02-06 9:56 ` Jonathan Cameron
2020-02-05 17:15 ` [PATCH 2/5 V2] staging: iio: adc: ad7192: modify iio_chan_spec array Alexandru Tachici
2020-02-06 10:01 ` Jonathan Cameron
2020-02-05 17:15 ` [PATCH 3/5 V2] staging: iio: adc: ad7192: removed spi_device_id Alexandru Tachici
2020-02-06 10:03 ` Jonathan Cameron
2020-02-05 17:15 ` [PATCH 4/5 V2] Documentation: ABI: testing: ad7192: update sysfs docs Alexandru Tachici
2020-02-06 10:05 ` Jonathan Cameron
2020-02-05 17:15 ` [PATCH 5/5 V2] staging: iio: adc: ad7192: move out of staging Alexandru Tachici
2020-02-06 10:10 ` Jonathan Cameron
2020-02-06 10:20 ` Jonathan Cameron
2020-02-10 6:43 ` Ardelean, Alexandru
2020-02-14 13:03 ` Jonathan Cameron
2020-02-06 9:47 ` [PATCH 0/5 V2] " 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=20200202162215.50915c83@archlinux \
--to=jic23@kernel.org \
--cc=alexandru.tachici@analog.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.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).