From: Jonathan Cameron <jic23@cam.ac.uk>
To: iio-linux@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, gregkh@suse.de,
Jonathan Cameron <jic23@cam.ac.uk>
Subject: [PATCH 04/19] staging:iio: Support functions for scan mask matching
Date: Mon, 26 Apr 2010 20:31:06 +0100 [thread overview]
Message-ID: <1272310281-7418-5-git-send-email-jic23@cam.ac.uk> (raw)
In-Reply-To: <1272310281-7418-4-git-send-email-jic23@cam.ac.uk>
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
drivers/staging/iio/iio.h | 45 +++++++++++++++++++++++++++++++++++++++++----
1 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/iio/iio.h b/drivers/staging/iio/iio.h
index 71dbfe1..a12072a 100644
--- a/drivers/staging/iio/iio.h
+++ b/drivers/staging/iio/iio.h
@@ -96,6 +96,7 @@ void iio_remove_event_from_list(struct iio_event_handler_list *el,
* control method is used
* @scan_count: [INTERN] the number of elements in the current scan mode
* @scan_mask: [INTERN] bitmask used in masking scan mode elements
+ * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
* @scan_timestamp: [INTERN] does the scan mode include a timestamp
* @trig: [INTERN] current device trigger (ring buffer modes)
* @pollfunc: [DRIVER] function run on trigger being recieved
@@ -122,7 +123,8 @@ struct iio_dev {
struct attribute_group *scan_el_attrs;
int scan_count;
- u16 scan_mask;
+ u32 scan_mask;
+ u32 *available_scan_masks;
bool scan_timestamp;
struct iio_trigger *trig;
struct iio_poll_func *pollfunc;
@@ -132,22 +134,57 @@ struct iio_dev {
* These are mainly provided to allow for a change of implementation if a device
* has a large number of scan elements
*/
-#define IIO_MAX_SCAN_LENGTH 15
+#define IIO_MAX_SCAN_LENGTH 31
+
+/* note 0 used as error indicator as it doesn't make sense. */
+static inline u32 iio_scan_mask_match(u32 *av_masks, u32 mask)
+{
+ while (*av_masks) {
+ if (!(~*av_masks & mask))
+ return *av_masks;
+ av_masks++;
+ }
+ return 0;
+}
static inline int iio_scan_mask_query(struct iio_dev *dev_info, int bit)
{
+ u32 mask;
+
if (bit > IIO_MAX_SCAN_LENGTH)
return -EINVAL;
+
+ if (!dev_info->scan_mask)
+ return 0;
+
+ if (dev_info->available_scan_masks)
+ mask = iio_scan_mask_match(dev_info->available_scan_masks,
+ dev_info->scan_mask);
else
- return !!(dev_info->scan_mask & (1 << bit));
+ mask = dev_info->scan_mask;
+
+ if (!mask)
+ return -EINVAL;
+
+ return !!(mask & (1 << bit));
};
static inline int iio_scan_mask_set(struct iio_dev *dev_info, int bit)
{
+ u32 mask;
+ u32 trialmask = dev_info->scan_mask | (1 << bit);
+
if (bit > IIO_MAX_SCAN_LENGTH)
return -EINVAL;
- dev_info->scan_mask |= (1 << bit);
+ if (dev_info->available_scan_masks) {
+ mask = iio_scan_mask_match(dev_info->available_scan_masks,
+ trialmask);
+ if (!mask)
+ return -EINVAL;
+ }
+ dev_info->scan_mask = trialmask;
dev_info->scan_count++;
+
return 0;
};
--
1.6.4.4
next prev parent reply other threads:[~2010-04-26 19:32 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-26 19:31 [PATCH 00/19 V2] staging:iio: ABi changes round 1 Jonathan Cameron
2010-04-26 19:31 ` [PATCH 01/19] staging:iio: Add new in_raw definitions for adc channels Jonathan Cameron
2010-04-26 19:31 ` [PATCH 02/19] staging:iio: Add new attrs for sampling frequency available and temp_raw Jonathan Cameron
2010-04-26 19:31 ` [PATCH 03/19] iio:staging:accelerometers move towards the new abi Jonathan Cameron
2010-04-26 19:31 ` Jonathan Cameron [this message]
2010-04-26 19:31 ` [PATCH 05/19] staging: iio: Move from class to bus Jonathan Cameron
2010-04-26 19:31 ` [PATCH 06/19] staging:iio: Move event attributes into the event[n] device in sysfs Jonathan Cameron
2010-04-26 19:31 ` [PATCH 07/19] staging:iio: Clean out unused IIO_SCAN_EL and add IIO_SCAN_NAMED_EL_C Jonathan Cameron
2010-04-26 19:31 ` [PATCH 08/19] staging:iio:max1363 move to new abi Jonathan Cameron
2010-04-26 19:31 ` [PATCH 09/19] staging:iio: Documentation, update iio_utils.h for the move to a bus Jonathan Cameron
2010-04-26 19:31 ` [PATCH 10/19] staging:iio: ABI documentation (partial) Jonathan Cameron
2010-04-26 19:31 ` [PATCH 11/19] staging:iio: Directory name changes to match new ABI Jonathan Cameron
2010-04-26 19:31 ` [PATCH 12/19] staging:iio:tsl2563: change lux to illuminanc0_input to match new abi Jonathan Cameron
2010-04-26 19:31 ` [PATCH 13/19] staging:iio: Remove naming via IDR's where no longer necessary under " Jonathan Cameron
2010-04-26 19:31 ` [PATCH 14/19] staging:iio:max1363 add support for max11606-max11617 Jonathan Cameron
2010-04-26 19:31 ` [PATCH 15/19] staging:iio:max1363 add support for 8 bit equivalent devices, max1036-9, max11600-5 Jonathan Cameron
2010-04-26 19:31 ` [PATCH 16/19] Staging: IIO: Fix uses of spinlocks prior to init in ring implementations Jonathan Cameron
2010-04-26 19:31 ` [PATCH 17/19] staging:iio:ring_sw: Fix incorrect test on successful read of last value, causes infinite loop Jonathan Cameron
2010-04-26 19:31 ` [PATCH 18/19] staging:iio:tsl2563 add a name attribute under the iio Jonathan Cameron
2010-04-26 19:31 ` [PATCH 19/19] staging:iio:Documentation: Rewrite example for new abi Jonathan Cameron
2010-04-26 20:10 ` [PATCH 00/19 V2] staging:iio: ABi changes round 1 Jonathan Cameron
2010-04-26 21:30 ` Greg KH
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=1272310281-7418-5-git-send-email-jic23@cam.ac.uk \
--to=jic23@cam.ac.uk \
--cc=gregkh@suse.de \
--cc=iio-linux@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
all inboxes | Powered by JetHome®