From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH 12/18] staging:iio:accel:sca3000 Add write support to the low pass filter control
Date: Sat, 8 Oct 2016 17:39:12 +0100 [thread overview]
Message-ID: <20161008163918.18758-13-jic23@kernel.org> (raw)
In-Reply-To: <20161008163918.18758-1-jic23@kernel.org>
Also includes an available attribute. The ordering of values appears
a bit random, but as the ABI doesn't specify this and we already have
both rising and falling lists I think this is fine.
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
drivers/staging/iio/accel/sca3000.c | 55 +++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 859394f8d8af..8212e1c7e91d 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -432,6 +432,26 @@ error_ret:
return ret ? ret : len;
}
+static ssize_t
+sca3000_show_available_3db_freqs(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+ struct sca3000_state *st = iio_priv(indio_dev);
+ int len;
+
+ len = sprintf(buf, "%d", st->info->measurement_mode_3db_freq);
+ if (st->info->option_mode_1)
+ len += sprintf(buf + len, " %d",
+ st->info->option_mode_1_3db_freq);
+ if (st->info->option_mode_2)
+ len += sprintf(buf + len, " %d",
+ st->info->option_mode_2_3db_freq);
+ len += sprintf(buf + len, "\n");
+
+ return len;
+}
/**
* sca3000_show_available_measurement_modes() display available modes
*
@@ -570,6 +590,9 @@ static IIO_DEVICE_ATTR(measurement_mode, S_IRUGO | S_IWUSR,
sca3000_store_measurement_mode,
0);
+static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available,
+ S_IRUGO, sca3000_show_available_3db_freqs,
+ NULL, 0);
/* More standard attributes */
static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0);
@@ -778,6 +801,31 @@ static int sca3000_read_3db_freq(struct sca3000_state *st, int *val)
}
}
+static int sca3000_write_3db_freq(struct sca3000_state *st, int val)
+{
+ int ret;
+ int mode;
+
+ if (val == st->info->measurement_mode_3db_freq)
+ mode = SCA3000_REG_MODE_MEAS_MODE_NORMAL;
+ else if (st->info->option_mode_1 &&
+ (val == st->info->option_mode_1_3db_freq))
+ mode = SCA3000_REG_MODE_MEAS_MODE_OP_1;
+ else if (st->info->option_mode_2 &&
+ (val == st->info->option_mode_2_3db_freq))
+ mode = SCA3000_REG_MODE_MEAS_MODE_OP_2;
+ else
+ return -EINVAL;
+ ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
+ if (ret)
+ return ret;
+
+ st->rx[0] &= ~SCA3000_REG_MODE_MODE_MASK;
+ st->rx[0] |= (mode & SCA3000_REG_MODE_MODE_MASK);
+
+ return sca3000_write_reg(st, SCA3000_REG_MODE_ADDR, st->rx[0]);
+}
+
static int sca3000_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
@@ -860,6 +908,12 @@ static int sca3000_write_raw(struct iio_dev *indio_dev,
ret = write_raw_samp_freq(st, val);
mutex_unlock(&st->lock);
return ret;
+ case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
+ if (val2)
+ return -EINVAL;
+ mutex_lock(&st->lock);
+ ret = sca3000_write_3db_freq(st, val);
+ mutex_unlock(&st->lock);
default:
return -EINVAL;
}
@@ -1006,6 +1060,7 @@ static struct attribute *sca3000_attributes[] = {
&iio_dev_attr_revision.dev_attr.attr,
&iio_dev_attr_measurement_mode_available.dev_attr.attr,
&iio_dev_attr_measurement_mode.dev_attr.attr,
+ &iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr,
&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
NULL,
};
--
2.10.0
next prev parent reply other threads:[~2016-10-08 16:39 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-08 16:39 [PATCH 00/18 V2] staging:iio:accel rework driver and move out of staging Jonathan Cameron
2016-10-08 16:39 ` [PATCH 01/18] staging:iio:accel:sca3000 Fix a use before setting of the indio_dev->buffer pointer Jonathan Cameron
2016-10-15 16:45 ` Jonathan Cameron
2016-10-08 16:39 ` [PATCH 02/18] staging:iio:accel:sca3000 merge files into one Jonathan Cameron
2016-10-08 16:39 ` [PATCH 03/18] staging:iio:accel:sca3000 drop sca3000_register_ring_funcs Jonathan Cameron
2016-10-08 16:39 ` [PATCH 04/18] staging:iio:accel:sca3000 Fix clearing of flag + setting of size of scan Jonathan Cameron
2016-10-08 16:39 ` [PATCH 05/18] staging:iio:accel:sca3000 Drop custom ABI for watersheds Jonathan Cameron
2016-10-08 16:39 ` [PATCH 06/18] staging:iio:accel:sca3000 move to hybrid hard / soft buffer design Jonathan Cameron
2016-10-08 16:39 ` [PATCH 07/18] staging:iio:accel:sca3000 drop some unused variables Jonathan Cameron
2016-10-08 16:39 ` [PATCH 08/18] staging:iio:accel:sca3000 use a 'fake' channel to handle freefall event registration Jonathan Cameron
2016-10-15 16:59 ` Jonathan Cameron
2016-10-08 16:39 ` [PATCH 09/18] staging:iio:accel:sca3000 Clean up register defines Jonathan Cameron
2016-10-08 16:39 ` [PATCH 10/18] staging:iio:accel:sca3000 add readback of the 3db low pass filter frequency Jonathan Cameron
2016-10-08 16:39 ` [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD Jonathan Cameron
2016-10-08 16:39 ` Jonathan Cameron [this message]
2016-10-08 16:39 ` [PATCH 13/18] staging:iio:accel:sca3000 Drop custom measurement mode attributes Jonathan Cameron
2016-10-08 16:39 ` [PATCH 14/18] staging:iio:accel:sca3000 replace non standard revision attr with dev_info on probe Jonathan Cameron
2016-10-08 16:39 ` [PATCH 15/18] staging:iio:accel:sca3000 Tidy up probe order to avoid a race Jonathan Cameron
2016-10-08 16:39 ` [PATCH 16/18] staging:iio:accel:sca3000 small checkpatch fixes (alignment etc) Jonathan Cameron
2016-10-08 16:39 ` [PATCH 17/18] staging:iio:accel:sca3000 kernel docify comments that were nearly kernel doc Jonathan Cameron
2016-10-08 16:39 ` [PATCH 18/18] staging:iio:accel:sca3000 Move out of staging Jonathan Cameron
2016-10-15 15:17 ` [PATCH 00/18 V2] staging:iio:accel rework driver and move " Jonathan Cameron
2016-10-15 15:58 ` Lars-Peter Clausen
2016-10-15 16:42 ` Jonathan Cameron
2016-10-15 17:13 ` Jonathan Cameron
-- strict thread matches above, loose matches on Subject: below --
2016-10-03 19:26 [PATCH 00/18] " Jonathan Cameron
2016-10-03 19:26 ` [PATCH 12/18] staging:iio:accel:sca3000 Add write support to the low pass filter control 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=20161008163918.18758-13-jic23@kernel.org \
--to=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--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).