linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <jic23@kernel.org>, <lars@metafoo.de>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [RFC PATCH 3/4] iio: Allow channels to share storage elements
Date: Fri, 24 Apr 2020 08:18:17 +0300	[thread overview]
Message-ID: <20200424051818.6408-4-alexandru.ardelean@analog.com> (raw)
In-Reply-To: <20200424051818.6408-1-alexandru.ardelean@analog.com>

From: Lars-Peter Clausen <lars@metafoo.de>

Currently each IIO channel has it's own storage element in the data stream
each with its own unique scan index. This works for a lot of use-cases,
but in some is not good enough to represent the hardware accurately. On
those devices multiple separate pieces of information are stored within the
same storage element and the storage element can't be further broken down
into multiple storage elements (e.g. because the data is not aligned).

This can for example be status bits stored in unused data bits. E.g. a
14-bit ADC that stores its data in a 16-bit word and uses the two
additional bits to convey status information like for example whether a
overrange condition has happened. Currently this kind of extra status
information is usually ignored and can only be used by applications that
have special knowledge about the connected device and its data layout.

In addition to that some might also have data channels with less than 8
bits that get packed into the same storage element.

Allow two or more channels to use the same scan index, if they their
storage element does have the same size.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/industrialio-core.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index f4daf19f2a3b..cdf59a51c917 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1651,6 +1651,16 @@ static const struct file_operations iio_buffer_fileops = {
 	.compat_ioctl = compat_ptr_ioctl,
 };
 
+static bool iio_chan_same_size(const struct iio_chan_spec *a,
+	const struct iio_chan_spec *b)
+{
+	if (a->scan_type.storagebits != b->scan_type.storagebits)
+		return false;
+	if (a->scan_type.repeat != b->scan_type.repeat)
+		return false;
+	return true;
+}
+
 static int iio_check_unique_scan_index(struct iio_dev *indio_dev)
 {
 	int i, j;
@@ -1662,13 +1672,16 @@ static int iio_check_unique_scan_index(struct iio_dev *indio_dev)
 	for (i = 0; i < indio_dev->num_channels - 1; i++) {
 		if (channels[i].scan_index < 0)
 			continue;
-		for (j = i + 1; j < indio_dev->num_channels; j++)
-			if (channels[i].scan_index == channels[j].scan_index) {
-				dev_err(&indio_dev->dev,
-					"Duplicate scan index %d\n",
-					channels[i].scan_index);
-				return -EINVAL;
-			}
+		for (j = i + 1; j < indio_dev->num_channels; j++) {
+			if (channels[i].scan_index != channels[j].scan_index)
+				continue;
+			if (iio_chan_same_size(&channels[i], &channels[j]))
+				continue;
+			dev_err(&indio_dev->dev,
+				"Duplicate scan index %d\n",
+				channels[i].scan_index);
+			return -EINVAL;
+		}
 	}
 
 	return 0;
-- 
2.17.1


  parent reply	other threads:[~2020-04-24  5:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24  5:18 [RFC PATCH 0/4] iio: scan_mask rework to track enabled channels on per-channel basis Alexandru Ardelean
2020-04-24  5:18 ` [RFC PATCH 1/4] iio: Move scan mask management to the core Alexandru Ardelean
2020-04-26  9:45   ` Jonathan Cameron
2020-04-26 10:22     ` Jonathan Cameron
2020-04-27  6:25     ` Ardelean, Alexandru
2020-05-02 18:12       ` Jonathan Cameron
2020-04-24  5:18 ` [RFC PATCH 2/4] iio: hw_consumer: use new scanmask functions Alexandru Ardelean
2020-04-24  5:18 ` Alexandru Ardelean [this message]
2020-04-26 10:28   ` [RFC PATCH 3/4] iio: Allow channels to share storage elements Jonathan Cameron
2020-04-24  5:18 ` [RFC PATCH 4/4] iio: Track enabled channels on a per channel basis Alexandru Ardelean
2020-04-24  7:51   ` Sa, Nuno
2020-04-26 10:50     ` Jonathan Cameron
2020-04-27 12:09       ` Sa, Nuno
2020-05-02 17:19         ` Jonathan Cameron
2020-05-04  8:24           ` Sa, Nuno
2020-05-04  9:28             ` Jonathan Cameron
2020-04-26 10:40   ` Jonathan Cameron
2020-04-24  7:51 ` [RFC PATCH 0/4] iio: scan_mask rework to track enabled channels on per-channel basis Sa, Nuno

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=20200424051818.6408-4-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --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).