linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Baluta <daniel.baluta@intel.com>
To: jic23@kernel.org, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: daniel.baluta@intel.com, irina.tirdea@intel.com
Subject: [RFC PATCH 7/8] iio: dummy: Demonstrate the usage of activity channel
Date: Thu,  2 Oct 2014 16:43:58 +0300	[thread overview]
Message-ID: <1412257439-15683-8-git-send-email-daniel.baluta@intel.com> (raw)
In-Reply-To: <1412257439-15683-1-git-send-email-daniel.baluta@intel.com>

Adds support for the activity channel in the dummy driver:
- a new channel IIO_ACTIVITY
- support for reading and writing pedometer step counter
- step detect event
- motion detect event

Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
---
 drivers/staging/iio/iio_simple_dummy.c        | 87 ++++++++++++++++++++++++---
 drivers/staging/iio/iio_simple_dummy.h        |  2 +
 drivers/staging/iio/iio_simple_dummy_events.c | 14 +++++
 3 files changed, 95 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
index bf78e6f..b3becee 100644
--- a/drivers/staging/iio/iio_simple_dummy.c
+++ b/drivers/staging/iio/iio_simple_dummy.c
@@ -69,6 +69,20 @@ static const struct iio_event_spec iio_dummy_event = {
 	.mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE),
 };
 
+/*
+ * simple activity events:
+ * motion: triggered when an activity (walking, running, etc.) is detected
+ * step detect: triggered when a step is detected
+ */
+static const struct iio_event_spec activity_events[] = {
+	{
+		.type = IIO_EV_TYPE_MOTION,
+		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
+	}, {
+		.type = IIO_EV_TYPE_STEP_DETECT,
+		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
+	},
+};
 #endif
 
 /*
@@ -215,6 +229,20 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
 		.indexed = 1,
 		.channel = 0,
 	},
+	{
+		.type = IIO_ACTIVITY,
+		.modified = 1,
+		.channel2 = IIO_MOD_PED_STEPS,
+		.info_mask_shared_by_type =  BIT(IIO_CHAN_INFO_ENABLE),
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+	},
+#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
+	{
+		.type = IIO_ACTIVITY,
+		.event_spec = activity_events,
+		.num_event_specs = ARRAY_SIZE(activity_events),
+	},
+#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
 };
 
 /**
@@ -259,6 +287,14 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
 			*val = st->accel_val;
 			ret = IIO_VAL_INT;
 			break;
+		case IIO_ACTIVITY:
+			switch (chan->channel2) {
+			case IIO_MOD_PED_STEPS:
+				*val = st->ped_steps;
+				ret = IIO_VAL_INT;
+				break;
+			}
+			break;
 		default:
 			break;
 		}
@@ -298,6 +334,16 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
 		*val2 = 33;
 		ret = IIO_VAL_INT_PLUS_NANO;
 		break;
+	case IIO_CHAN_INFO_ENABLE:
+		switch (chan->type) {
+		case IIO_ACTIVITY:
+			*val = st->ped_enabled;
+			ret = IIO_VAL_INT;
+			break;
+		default:
+			break;
+		}
+		break;
 	default:
 		break;
 	}
@@ -330,14 +376,29 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (chan->output == 0)
+		switch (chan->type) {
+		case IIO_VOLTAGE:
+			if (chan->output == 0)
+				return -EINVAL;
+
+			/* Locking not required as writing single value */
+			mutex_lock(&st->lock);
+			st->dac_val = val;
+			mutex_unlock(&st->lock);
+			return 0;
+		case IIO_ACTIVITY:
+			switch (chan->channel2) {
+			case IIO_MOD_PED_STEPS:
+				mutex_lock(&st->lock);
+				st->ped_steps = val;
+				mutex_unlock(&st->lock);
+				return 0;
+			default:
+				return -EINVAL;
+			}
+		default:
 			return -EINVAL;
-
-		/* Locking not required as writing single value */
-		mutex_lock(&st->lock);
-		st->dac_val = val;
-		mutex_unlock(&st->lock);
-		return 0;
+		}
 	case IIO_CHAN_INFO_CALIBSCALE:
 		mutex_lock(&st->lock);
 		/* Compare against table - hard matching here */
@@ -356,7 +417,16 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
 		st->accel_calibbias = val;
 		mutex_unlock(&st->lock);
 		return 0;
-
+	case IIO_CHAN_INFO_ENABLE:
+		switch (chan->type) {
+		case IIO_ACTIVITY:
+			mutex_lock(&st->lock);
+			st->ped_enabled = val;
+			mutex_unlock(&st->lock);
+			return 0;
+		default:
+			return -EINVAL;
+		}
 	default:
 		return -EINVAL;
 	}
@@ -395,6 +465,7 @@ static int iio_dummy_init_device(struct iio_dev *indio_dev)
 	st->accel_val = 34;
 	st->accel_calibbias = -7;
 	st->accel_calibscale = &dummy_scales[0];
+	st->ped_steps = 47;
 
 	return 0;
 }
diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/staging/iio/iio_simple_dummy.h
index 1a74e26..1996e3f 100644
--- a/drivers/staging/iio/iio_simple_dummy.h
+++ b/drivers/staging/iio/iio_simple_dummy.h
@@ -34,6 +34,8 @@ struct iio_dummy_state {
 	int accel_calibbias;
 	const struct iio_dummy_accel_calibscale *accel_calibscale;
 	struct mutex lock;
+	int ped_enabled;
+	int ped_steps;
 	struct iio_dummy_regs *regs;
 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
 	int event_irq;
diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
index 719dfa5..94de22a 100644
--- a/drivers/staging/iio/iio_simple_dummy_events.c
+++ b/drivers/staging/iio/iio_simple_dummy_events.c
@@ -161,6 +161,20 @@ static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
 					      IIO_EV_TYPE_THRESH, 0, 0, 0),
 			       iio_get_time_ns());
 		break;
+	case 1:
+		iio_push_event(indio_dev,
+			       IIO_EVENT_CODE(IIO_ACTIVITY, 0, IIO_MOD_RUNNING,
+					      IIO_EV_DIR_RISING,
+					      IIO_EV_TYPE_MOTION, 0, 0, 0),
+			       iio_get_time_ns());
+		break;
+	case 2:
+		iio_push_event(indio_dev,
+			       IIO_EVENT_CODE(IIO_ACTIVITY, 0, IIO_NO_MOD,
+					      IIO_EV_DIR_EITHER,
+					      IIO_EV_TYPE_STEP_DETECT, 0, 0, 0),
+			       iio_get_time_ns());
+		break;
 	default:
 		break;
 	}
-- 
1.9.1


  parent reply	other threads:[~2014-10-02 13:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-02 13:43 [RFC PATCH] iio: Introduce activity channel Daniel Baluta
2014-10-02 13:43 ` [RFC PATCH 1/8] iio: dummy: Introduce virtual registers for dummy device Daniel Baluta
2014-10-04 12:48   ` Jonathan Cameron
2014-10-06 11:17     ` Daniel Baluta
2014-10-09 19:28       ` Jonathan Cameron
2014-10-19 20:30   ` Hartmut Knaack
2014-10-19 20:39     ` Daniel Baluta
2014-10-02 13:43 ` [RFC PATCH 2/8] iio: core: Introduce IIO_ACTIVITY channel Daniel Baluta
2014-10-04 13:00   ` Jonathan Cameron
2014-10-02 13:43 ` [RFC PATCH 3/8] iio: core: Introduce new MOTION event Daniel Baluta
2014-10-04 13:12   ` Jonathan Cameron
2014-10-06 14:17     ` Daniel Baluta
2014-10-09 19:31       ` Jonathan Cameron
2014-10-11  9:47         ` Daniel Baluta
2014-10-13  9:46           ` Karol Wrona
2014-10-07 10:48     ` Daniel Baluta
2014-10-09 19:37       ` Jonathan Cameron
2014-10-02 13:43 ` [RFC PATCH 4/8] iio: core: Introduce pedometer STEP counter modifier Daniel Baluta
2014-10-04 12:53   ` Jonathan Cameron
2014-10-06 13:50     ` Tirdea, Irina
2014-10-06 16:31       ` Jonathan Cameron
2014-10-07 13:54         ` Tirdea, Irina
2014-10-02 13:43 ` [RFC PATCH 5/8] iio: core: Introduce ENABLE channel info mask Daniel Baluta
2014-10-02 13:43 ` [RFC PATCH 6/8] iio: core: Introduce new STEP_DETECT event Daniel Baluta
2014-10-04 12:56   ` Jonathan Cameron
2014-10-02 13:43 ` Daniel Baluta [this message]
2014-10-02 13:43 ` [RFC PATCH 8/8] iio: event_monitor: Add support for activity channel Daniel Baluta

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=1412257439-15683-8-git-send-email-daniel.baluta@intel.com \
    --to=daniel.baluta@intel.com \
    --cc=irina.tirdea@intel.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).