From: Jonathan Cameron <jic23@kernel.org>
To: Martin Fuzzey <mfuzzey@parkeon.com>, linux-iio@vger.kernel.org
Subject: Re: [PATCH 9/9] iio: mma8452: add support for self test.
Date: Mon, 09 Mar 2015 13:37:04 +0000 [thread overview]
Message-ID: <54FDA200.7090209@kernel.org> (raw)
In-Reply-To: <20150219141612.27001.62858.stgit@localhost>
On 19/02/15 14:16, Martin Fuzzey wrote:
> Add a new attribute to activate the self test mode.
>
> When self test is activated, an electrostatic actuation force is
> applied to the sensor, simulating a small acceleration.
>
> Signed-off-by: Martin Fuzzey <mfuzzey@parkeon.com>
The most common option for self tests is to do them on startup
and spit out an error if they fail to give the expected
result. The advantage is that we avoid a little used and
not terribly well defined (in general!) ABI element.
This is far from the only part supporting self tests
so we need to be careful with adding a new ABI.
Would doing it on startup work here?
Clearly you'd have to apply the self test and define some boundaries
on the expected result for correct operation (vs not having it on)
and hope no one starts the device up whilst accelerating a lot.
I guess on this one a warning would be the way to go rather than
an error as huge real accelerations are more than possible.
Jonathan
> ---
> .../ABI/testing/sysfs-bus-iio-accel-mma8452 | 10 ++++
> drivers/iio/accel/mma8452.c | 52 ++++++++++++++++++++
> 2 files changed, 62 insertions(+)
> create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-accel-mma8452
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-accel-mma8452 b/Documentation/ABI/testing/sysfs-bus-iio-accel-mma8452
> new file mode 100644
> index 0000000..387ed38
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-accel-mma8452
> @@ -0,0 +1,10 @@
> +What: /sys/bus/iio/devices/iio:deviceX/self_test
> +KernelVersion: 3.21
> +Contact: linux-iio@vger.kernel.org
> +Description:
> + Allow self test mode to be controlled:
> + "0" = inactive
> + "1" = active
> + When self test is activated, an electrostatic actuation force is
> + applied to the sensor, simulating a small acceleration.
> +
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index 6277b5d..75dcc6e 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -49,6 +49,7 @@
> #define MMA8452_CTRL_REG1 0x2a
> #define MMA8452_CTRL_REG2 0x2b
> #define MMA8452_CTRL_REG2_RST BIT(6)
> +#define MMA8452_CTRL_REG2_SELFTEST BIT(7)
> #define MMA8452_CTRL_REG4 0x2d
> #define MMA8452_CTRL_REG5 0x2e
>
> @@ -639,6 +640,56 @@ static int mma8452_reg_access_dbg(struct iio_dev *indio_dev,
> return ret;
> }
>
> +static ssize_t mma8452_show_selftest(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> + struct mma8452_data *data = iio_priv(indio_dev);
> + int ret;
> +
> + ret = i2c_smbus_read_byte_data(data->client, MMA8452_CTRL_REG2);
> + if (ret < 0)
> + return ret;
> +
> + return sprintf(buf, "%d\n", ret & MMA8452_CTRL_REG2_SELFTEST ? 1 : 0);
> +}
> +
> +static ssize_t mma8452_store_selftest(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> + struct mma8452_data *data = iio_priv(indio_dev);
> + bool state;
> + int ret;
> + u8 val;
> +
> + ret = strtobool(buf, &state);
> + if (ret < 0)
> + return ret;
> +
> + ret = i2c_smbus_read_byte_data(data->client, MMA8452_CTRL_REG2);
> + if (ret < 0)
> + return ret;
> +
> + val = ret;
> + if (state)
> + val |= MMA8452_CTRL_REG2_SELFTEST;
> + else
> + val &= ~MMA8452_CTRL_REG2_SELFTEST;
> +
> + ret = mma8452_change_config(data, MMA8452_CTRL_REG2, val);
> + if (ret)
> + return ret;
> +
> + return len;
> +}
> +
> +static IIO_DEVICE_ATTR(self_test,
> + S_IRUGO | S_IWUSR,
> + mma8452_show_selftest,
> + mma8452_store_selftest, 0);
> +
> static const struct iio_event_spec mma8452_transient_event[] = {
> {
> .type = IIO_EV_TYPE_THRESH,
> @@ -698,6 +749,7 @@ static struct attribute *mma8452_attributes[] = {
> &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
> &iio_dev_attr_in_accel_scale_available.dev_attr.attr,
> &iio_dev_attr_in_accel_filter_high_pass_3db_frequency_available.dev_attr.attr,
> + &iio_dev_attr_self_test.dev_attr.attr,
> NULL
> };
>
>
next prev parent reply other threads:[~2015-03-09 13:37 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-19 14:15 [PATCH V3 0/9] iio: mma8452 enhancements Martin Fuzzey
2015-02-19 14:15 ` [PATCH 1/9] iio: mma8452: Initialise before activating Martin Fuzzey
2015-02-25 12:12 ` Jonathan Cameron
2015-02-25 23:05 ` Peter Meerwald
2015-04-16 20:34 ` Hartmut Knaack
2015-02-19 14:15 ` [PATCH 2/9] iio: mma8452: Add access to registers via DebugFS Martin Fuzzey
2015-04-16 20:50 ` Hartmut Knaack
2015-02-19 14:16 ` [PATCH 3/9] iio: core: add high pass filter attributes Martin Fuzzey
2015-04-16 21:05 ` Hartmut Knaack
2015-02-19 14:16 ` [PATCH 4/9] iio: mma8452: Basic support for transient events Martin Fuzzey
2015-02-25 12:25 ` Jonathan Cameron
2015-04-29 12:52 ` Martin Fuzzey
2015-05-08 13:58 ` Jonathan Cameron
2015-05-12 14:14 ` Martin Fuzzey
2015-05-12 19:08 ` Jonathan Cameron
2015-02-25 23:09 ` Peter Meerwald
2015-04-16 22:30 ` Hartmut Knaack
2015-02-19 14:16 ` [PATCH 5/9] iio: doc: Describe scale attributes for event thresholds Martin Fuzzey
2015-03-09 13:31 ` Jonathan Cameron
2015-04-16 22:36 ` Hartmut Knaack
2015-04-18 11:24 ` Jonathan Cameron
2015-02-19 14:16 ` [PATCH 6/9] iio: mma8452: Add support for transient event debouncing Martin Fuzzey
2015-04-17 21:47 ` Hartmut Knaack
2015-02-19 14:16 ` [PATCH 7/9] iio: mma8452: Add highpass filter configuration Martin Fuzzey
2015-02-25 22:45 ` Peter Meerwald
2015-02-19 14:16 ` [PATCH 8/9] iio: mma8452: Add support for interrupt driven triggers Martin Fuzzey
2015-02-19 14:16 ` [PATCH 9/9] iio: mma8452: add support for self test Martin Fuzzey
2015-02-25 22:54 ` Peter Meerwald
2015-03-09 13:37 ` Jonathan Cameron [this message]
2015-04-29 8:05 ` Martin Fuzzey
2015-05-07 23:13 ` Jonathan Cameron
2015-02-25 23:11 ` [PATCH V3 0/9] iio: mma8452 enhancements Peter Meerwald
2015-03-09 13:49 ` 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=54FDA200.7090209@kernel.org \
--to=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=mfuzzey@parkeon.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).