From: Andrea Merello <andrea.merello@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: patrick.havelange@essensium.com,
paresh.chaudhary@rockwellcollins.com, pmeerw@pmeerw.net,
lars@metafoo.de, knaack.h@gmx.de,
Matthew Weber <matthew.weber@rockwellcollins.com>,
Colin King <colin.king@canonical.com>,
linux-iio@vger.kernel.org
Subject: Re: [PATCH 1/3] iio: max31856: add option for setting mains filter rejection frequency
Date: Wed, 16 Oct 2019 15:14:20 +0200 [thread overview]
Message-ID: <CAN8YU5Ogcp8ERkxntTVQH3EoJF7h61VCONPXEaP-kvpx8EmS+g@mail.gmail.com> (raw)
In-Reply-To: <20191006085423.68bcecfd@archlinux>
Il giorno dom 6 ott 2019 alle ore 09:54 Jonathan Cameron
<jic23@kernel.org> ha scritto:
>
> On Mon, 23 Sep 2019 14:17:12 +0200
> Andrea Merello <andrea.merello@gmail.com> wrote:
>
> > This sensor has an embedded notch filter for reducing interferences caused
> > by the power mains. This filter can be tuned to reject either 50Hz or 60Hz
> > (and harmonics).
> >
> > Currently the said setting is left alone (the sensor defaults to 60Hz).
> > This patch introduces a IIO attribute that allows the user to set the said
> > filter to the desired frequency.
> >
> > NOTE: this has been intentionally not tied to any DT property to allow
> > the configuration of this setting from userspace, e.g. with a GUI or by
> > reading a configuration file, or maybe reading a GPIO tied to a physical
> > switch or accessing some device that can autodetect the line frequency.
> >
> > Signed-off-by: Andrea Merello <andrea.merello@gmail.com>
> This one is not something that can be expect to be known from the setup
> of the device as it will depend on local mains frequency.
>
> So fine, to have it as a userspace control, but the name is too generic.
> We already have a number of filter attributes and we should try to
> work out how to bring it inline with them.
Sure
> in_X_filter_low_pass_3db_frequency
> in_X_filter_high_pass_3db_frequency
>
> So would,
> in_X_filter_notch_center_frequency work?
> ( I suppose we should use the American spelling ;)
Yes, it seems OK in this case. I will produce a V2 with this modification.
> This kind of ignores the harmonics aspect but at least documents the
> main frequency being blocked.
I think this is perfectly fine: the user wants to set the notch filter
center frequency to either 60Hz or 50Hz to match the line frequency,
then she/he expects the filter to simply "work" somehow; IMO the
harmonic thing does not needed to be explicit.
> There is a slight complexity that we have devices that have dual
> notchfilters (50 and 60Hz) and ones where you can turn it off entirely.
>
> I suppose no value would count as off and we could perhaps use a list
> for both on at the same time (though that's a bit horrible).
IMHO it seems reasonable. Maybe for all-off and both-on conditions we
could also use magic strings like i.e. "all" and "off".
> > ---
> > drivers/iio/temperature/max31856.c | 49 ++++++++++++++++++++++++++++++
> > 1 file changed, 49 insertions(+)
> >
> > diff --git a/drivers/iio/temperature/max31856.c b/drivers/iio/temperature/max31856.c
> > index 73ed550e3fc9..d12613f7ba3c 100644
> > --- a/drivers/iio/temperature/max31856.c
> > +++ b/drivers/iio/temperature/max31856.c
> > @@ -23,6 +23,7 @@
> > #define MAX31856_CR0_1SHOT BIT(6)
> > #define MAX31856_CR0_OCFAULT BIT(4)
> > #define MAX31856_CR0_OCFAULT_MASK GENMASK(5, 4)
> > +#define MAX31856_CR0_FILTER_50HZ BIT(0)
> > #define MAX31856_TC_TYPE_MASK GENMASK(3, 0)
> > #define MAX31856_FAULT_OVUV BIT(1)
> > #define MAX31856_FAULT_OPEN BIT(0)
> > @@ -63,6 +64,7 @@ static const struct iio_chan_spec max31856_channels[] = {
> > struct max31856_data {
> > struct spi_device *spi;
> > u32 thermocouple_type;
> > + bool filter_50hz;
> > };
> >
> > static int max31856_read(struct max31856_data *data, u8 reg,
> > @@ -123,6 +125,11 @@ static int max31856_init(struct max31856_data *data)
> > reg_cr0_val &= ~MAX31856_CR0_1SHOT;
> > reg_cr0_val |= MAX31856_CR0_AUTOCONVERT;
> >
> > + if (data->filter_50hz)
> > + reg_cr0_val |= MAX31856_CR0_FILTER_50HZ;
> > + else
> > + reg_cr0_val &= ~MAX31856_CR0_FILTER_50HZ;
> > +
> > return max31856_write(data, MAX31856_CR0_REG, reg_cr0_val);
> > }
> >
> > @@ -249,12 +256,53 @@ static ssize_t show_fault_oc(struct device *dev,
> > return show_fault(dev, MAX31856_FAULT_OPEN, buf);
> > }
> >
> > +static ssize_t show_filter(struct device *dev,
> > + struct device_attribute *attr,
> > + char *buf)
> > +{
> > + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> > + struct max31856_data *data = iio_priv(indio_dev);
> > +
> > + return sprintf(buf, "%d\n", data->filter_50hz ? 50 : 60);
> > +}
> > +
> > +static ssize_t set_filter(struct device *dev,
> > + struct device_attribute *attr,
> > + const char *buf,
> > + size_t len)
> > +{
> > + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> > + struct max31856_data *data = iio_priv(indio_dev);
> > + unsigned int freq;
> > + int ret;
> > +
> > + ret = kstrtouint(buf, 10, &freq);
> > + if (ret)
> > + return ret;
> > +
> > + switch (freq) {
> > + case 50:
> > + data->filter_50hz = true;
> > + break;
> > + case 60:
> > + data->filter_50hz = false;
> > + break;
> > + default:
> > + return -EINVAL;
> > + }
> > +
> > + max31856_init(data);
> > + return len;
> > +}
> > +
> > static IIO_DEVICE_ATTR(fault_ovuv, 0444, show_fault_ovuv, NULL, 0);
> > static IIO_DEVICE_ATTR(fault_oc, 0444, show_fault_oc, NULL, 0);
> > +static IIO_DEVICE_ATTR(filter, 0644, show_filter, set_filter, 0);
> >
> > static struct attribute *max31856_attributes[] = {
> > &iio_dev_attr_fault_ovuv.dev_attr.attr,
> > &iio_dev_attr_fault_oc.dev_attr.attr,
> > + &iio_dev_attr_filter.dev_attr.attr,
> > NULL,
> > };
> >
> > @@ -280,6 +328,7 @@ static int max31856_probe(struct spi_device *spi)
> >
> > data = iio_priv(indio_dev);
> > data->spi = spi;
> > + data->filter_50hz = false;
> >
> > spi_set_drvdata(spi, indio_dev);
> >
>
next prev parent reply other threads:[~2019-10-16 13:14 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-23 12:17 [PATCH 0/3] iio: max31856: provide more configuration options Andrea Merello
2019-09-23 12:17 ` [PATCH 1/3] iio: max31856: add option for setting mains filter rejection frequency Andrea Merello
2019-10-06 7:54 ` Jonathan Cameron
2019-10-16 13:14 ` Andrea Merello [this message]
2019-10-17 12:32 ` Jonathan Cameron
2019-10-18 13:46 ` Andrea Merello
2019-10-22 9:34 ` Jonathan Cameron
2019-10-23 8:29 ` Andrea Merello
2019-10-27 9:22 ` Jonathan Cameron
2019-10-28 7:32 ` Andrea Merello
2019-11-02 14:17 ` Jonathan Cameron
2019-11-04 13:51 ` Andrea Merello
2019-09-23 12:17 ` [PATCH 2/3] iio: max31856: add support for configuring the HW averaging Andrea Merello
2019-10-06 7:55 ` Jonathan Cameron
2019-10-16 13:33 ` Andrea Merello
2019-10-17 12:34 ` Jonathan Cameron
2019-10-18 13:47 ` Andrea Merello
2019-09-23 12:17 ` [PATCH 3/3] iio: max31856: add support for runtime-configuring the thermocouple type Andrea Merello
2019-10-06 7:58 ` Jonathan Cameron
2019-10-16 13:43 ` Andrea Merello
2019-10-17 12:35 ` Jonathan Cameron
2019-10-18 13:48 ` Andrea Merello
2019-11-11 15:35 ` [v2 0/9] iio: max31856: provide more configuration options Andrea Merello
2019-11-11 15:35 ` [v2 1/9] iio: max31856: add option for setting mains filter rejection frequency Andrea Merello
2019-11-11 22:59 ` Matt Ranostay
2019-11-16 14:29 ` Jonathan Cameron
2019-11-11 15:35 ` [v2 2/9] Documentation: ABI: document IIO in_temp_filter_notch_center_frequency file Andrea Merello
2019-11-11 15:35 ` [v2 3/9] iio: max31856: add support for configuring the HW averaging Andrea Merello
2019-11-11 23:01 ` Matt Ranostay
2019-11-11 15:35 ` [v2 4/9] RFC: iio: core: add char type for sysfs attributes Andrea Merello
2019-11-16 14:45 ` Jonathan Cameron
2019-11-11 15:35 ` [v2 5/9] iio: core: add thermocouple_type standard attribute Andrea Merello
2019-11-11 15:35 ` [v2 6/9] Documentation: ABI: document IIO thermocouple_type file Andrea Merello
2019-11-16 14:47 ` Jonathan Cameron
2019-11-11 15:35 ` [v2 7/9] iio: max31856: add support for runtime-configuring the thermocouple type Andrea Merello
2019-11-16 14:49 ` Jonathan Cameron
2019-11-11 15:35 ` [v2 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute Andrea Merello
2019-11-16 14:51 ` Jonathan Cameron
2019-11-11 15:35 ` [v2 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings Andrea Merello
2019-11-14 22:12 ` Rob Herring
2019-11-20 14:47 ` [v3 0/9] iio: max31856: provide more configuration options Andrea Merello
2019-11-20 14:47 ` [v3 1/9] iio: max31856: add option for setting mains filter rejection frequency Andrea Merello
2019-11-23 12:30 ` Jonathan Cameron
2019-11-20 14:47 ` [v3 2/9] Documentation: ABI: document IIO in_temp_filter_notch_center_frequency file Andrea Merello
2019-11-23 12:31 ` Jonathan Cameron
2019-11-20 14:47 ` [v3 3/9] iio: max31856: add support for configuring the HW averaging Andrea Merello
2019-11-23 12:32 ` Jonathan Cameron
2019-11-20 14:47 ` [v3 4/9] RFC: iio: core: add char type for sysfs attributes Andrea Merello
2019-11-23 12:33 ` Jonathan Cameron
2019-11-20 14:47 ` [v3 5/9] iio: core: add thermocouple_type standard attribute Andrea Merello
2019-11-23 12:36 ` Jonathan Cameron
2019-11-20 14:47 ` [v3 6/9] Documentation: ABI: document IIO thermocouple_type file Andrea Merello
2019-11-23 12:37 ` Jonathan Cameron
2019-11-20 14:47 ` [v3 7/9] iio: max31856: add support for runtime-configuring the thermocouple type Andrea Merello
2019-11-23 12:40 ` Jonathan Cameron
2019-11-23 12:41 ` Jonathan Cameron
2019-11-20 14:47 ` [v3 8/9] RFC/RFT: iio: maxim_thermocouple: add thermocouple_type sysfs attribute Andrea Merello
2019-11-23 12:46 ` Jonathan Cameron
2019-11-20 14:47 ` [v3 9/9] dt-bindings: iio: maxim_thermocouple: document new 'compatible' strings Andrea Merello
2019-11-23 12:46 ` 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=CAN8YU5Ogcp8ERkxntTVQH3EoJF7h61VCONPXEaP-kvpx8EmS+g@mail.gmail.com \
--to=andrea.merello@gmail.com \
--cc=colin.king@canonical.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=matthew.weber@rockwellcollins.com \
--cc=paresh.chaudhary@rockwellcollins.com \
--cc=patrick.havelange@essensium.com \
--cc=pmeerw@pmeerw.net \
/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).