Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2860041ybl; Sun, 2 Feb 2020 08:23:34 -0800 (PST) X-Google-Smtp-Source: APXvYqwyODMBAl2rQcuHL5rRL7XqY/48pkC64cIH2qP551XwdIKt7hGmqTxNU3TqP0ng8Y71XVR9 X-Received: by 2002:a05:6830:1db3:: with SMTP id z19mr15134864oti.292.1580660614718; Sun, 02 Feb 2020 08:23:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580660614; cv=none; d=google.com; s=arc-20160816; b=bjJ0JIXgDfCtFP2PDFC/CuoYttq6THPiIC0au2vcxAPMfHAPhNcEhHHHlfTETh1mpi MxOk1Bkd0aCJCoHcH2p85TDNBQVeuKHNoSEz9CnQdVvH1Zqd73ONkLs0zdDSZBZ37W27 XI/QlVXBOCU6Smd5qknR1ypvkRsJJuxLjvEFo5OdS0Ufke4pa+Ewn138MG9TG+kTyCvR vb4EuYeJBCvNroiFKA5QewT+r8JL+LKJO4UknBoTd+fxL4NKeCI95WxJSLFjbGwEBb/j x9/umrkeUIVoqgewh8H5HI1K/OP1pNfaRfNyQ92dWxEdmPJS7/h4gnklRbJX1712B3si CLuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=WXb6YgKScCh8iM6U64JEQKLXe3j73ujHZbXOcZvrQQ4=; b=IIqvjx+35peS9prb/STpa3eooLkqLLGMCqcrKh6kikzaol2gYWkzb+1QylbgiSPa2p xUFXvTSUFm4KLUbeRWj/U2Ao+edjnN+jBLilwReZKnjkEnzfgowDh3FZRFt4CkjvhhX6 eIh4Ofwc+BgCBvucKjCkOU025EKjDwDgm2BqP6N2vUokU8lkoCUO7AlA5XFGdlK6BieW e3Y26jSv1rxw4AZ0eNmNpJoU87oAJsj7oNHxGi5ycwCe/O+vDwgNhGXWM7KmY7R7GbOj eOFQun0yDD4N/cGA1NvBl3TABafOQfociT9Vv3z/MXJ9SbIW05H7wO+nzUBLc+sjQohx 2TGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wssfoGoR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v76si6755693oif.207.2020.02.02.08.23.23; Sun, 02 Feb 2020 08:23:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wssfoGoR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727039AbgBBQWU (ORCPT + 99 others); Sun, 2 Feb 2020 11:22:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:57708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726907AbgBBQWU (ORCPT ); Sun, 2 Feb 2020 11:22:20 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BB36920679; Sun, 2 Feb 2020 16:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580660539; bh=KNdyhD3w4yCdwrz3wHVgo4rj2j28SvdHOaIBi+5JM3A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=wssfoGoRbDyGixeBuWYuQH5ygKNexFHrJzjYiVGaa//0uwq4zMSakCBYAS/pItZHi Zn3hin+BVfJ8RhmFeMH9Ter6c/W0acHW+WHlDbXkAOJwbVtJix6P0PZh0ks0wRWi8F n1KirtMK4D4mKlE1SUyrp/U0RTm2kbTrNuHTNRCc= Date: Sun, 2 Feb 2020 16:22:15 +0000 From: Jonathan Cameron To: Alexandru Tachici Cc: , Subject: Re: [PATCH] iio: adc: ad7124: add 3db filter Message-ID: <20200202162215.50915c83@archlinux> In-Reply-To: <20200122085414.16950-1-alexandru.tachici@analog.com> References: <20200122085414.16950-1-alexandru.tachici@analog.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 22 Jan 2020 10:54:14 +0200 Alexandru Tachici 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 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; > }