[PATCH v2 5/6] iio: accel: adxl372: add additional events ABIs

Alexandru Tachici
2020-02-25T12:09:37Z

Adxl372 uses the standard event interface. The additional
ABIs aim to explain to the user that the values set in
./events/thresh_falling_period and ./events/thresh_rising_period
control the state of the device, not just the events timings.

Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>
---
drivers/iio/accel/adxl372.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index e669eaaaa07e..9a7fa0d796f8 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -236,6 +236,29 @@ static const struct adxl372_axis_lookup adxl372_axis_lookup_table[] = {
{ BIT(0) | BIT(1) | BIT(2), ADXL372_XYZ_FIFO },
};

+static ssize_t adxl372_read_detect_event(struct iio_dev *indio_dev, uintptr_t p,
+ const struct iio_chan_spec *chan,
+ char *buf)
+{
+ return sprintf(buf, "%s", (const char *)p);
+}
+
+static const struct iio_chan_spec_ext_info adxl372_ext_info[] = {
+ {
+ .name = "activity_detect_event",
+ .shared = IIO_SHARED_BY_ALL,
+ .read = adxl372_read_detect_event,
+ .private = (uintptr_t)"in_accel_thresh_x_rising\n",
+ },
+ {
+ .name = "inactivity_detect_event",
+ .shared = IIO_SHARED_BY_ALL,
+ .read = adxl372_read_detect_event,
+ .private = (uintptr_t)"in_accel_thresh_x_falling\n",
+ },
+ {},
+};
+
static const struct iio_event_spec adxl372_events[] = {
{
.type = IIO_EV_TYPE_THRESH,
@@ -267,7 +290,8 @@ static const struct iio_event_spec adxl372_events[] = {
.shift = 4, \
}, \
.event_spec = adxl372_events, \
- .num_event_specs = 2 \
+ .num_event_specs = 2, \
+ .ext_info = adxl372_ext_info, \
}

static const struct iio_chan_spec adxl372_channels[] = {
--
2.20.1