Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1755387ybz; Sun, 26 Apr 2020 03:33:24 -0700 (PDT) X-Google-Smtp-Source: APiQypJVSOgeybRLttDbJePLYmSg3bYjf6VzHGSptyWm5TQxEnW2ku3cQf99V4eYgzBeyLKsgXWx X-Received: by 2002:a05:6402:4ce:: with SMTP id n14mr15600193edw.32.1587897204563; Sun, 26 Apr 2020 03:33:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587897204; cv=none; d=google.com; s=arc-20160816; b=oza5QJGhKi6XebtBerfYH44KlDzW55w14V8eFoXAlA5ls/AsLBTAyEhuTQLYs4pZFM 2mZ5OSSKU5WPR+4tpXddNBxQlipdjPlgitl1Lb6DBi8WgpX02xZbAdWLC7Bdj2dZophM 8grlJA0rSMKglRQcBSN+s4w+Z28kqkiLpLuNAVcy2lCnaDt9FHpj2DjhTZBuSh79yWQD J2m/h73lolWfRxUxzC8CZeZgAYNnuxMSaSk3ETNq6CzYR/n9z8B8qCYw78ws0TXXb4dn 44fTvnphWGxztv/ms2e7WY+4OSg21zlarN8Ey2LbEF+yWrncX73qEAhGjoEilpOAq4P9 WmMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=OTu083HP6YeZOIslfSzvF/Oe1bTrgtL0krcaJ7LE/Fo=; b=rpc3E5PMiBzBDDRi6HBDQn5oB72MfZO+LkrgA0HJtLYMadZ1M6HCH6/LuI801jJ9qZ UqhU00vJz1B8Hr8na+vrbJPCaAUKLVMz+EnVaF5cNFDsw3hijUiH47Rp31CsPHvQYsv8 GneQed99zNm6zi94x33rwdcPYVA3ozQWEwhlUDKpaZyKhsx98K23mCooUL6cqKUTfIyf BdPBVmlShnmuX55vsPh7LjXkcmsM8HfC7Vl2NQc/JWz/BEgb1Q8fWpcrKrALFtQDpShr 08A5vybDe8Wjo+Uqqi0T205uJioSkAmEvM7XdEHTb0es+RaEXwjSuawRHefUJhvzGq8A 5exA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="YgD3/h4W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si6389210eja.20.2020.04.26.03.33.00; Sun, 26 Apr 2020 03:33:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="YgD3/h4W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726140AbgDZK24 (ORCPT + 99 others); Sun, 26 Apr 2020 06:28:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:57314 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726116AbgDZK2z (ORCPT ); Sun, 26 Apr 2020 06:28:55 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 316E0206B6; Sun, 26 Apr 2020 10:28:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587896934; bh=pn5qHg+Pn44zc/IxGMp8ZLIkBtQLw6+PAtpwlocbLF0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=YgD3/h4WC3J4acQyimUkxzGdYUHVcmqK9SZDPUOM6+Csq+N7XM2Zq4DM/KPLNNfjP tPfkR6JlaUuVwAQQD37Vqh+SCwQCJgkSXoJ9+3cJZu+2IRcjrwxOAXUMMK+bn42dYk O9bMe267usJ5sarWZ1uRSpKWB/lXby8jzaAldggI= Date: Sun, 26 Apr 2020 11:28:51 +0100 From: Jonathan Cameron To: Alexandru Ardelean Cc: , , Subject: Re: [RFC PATCH 3/4] iio: Allow channels to share storage elements Message-ID: <20200426112851.65001a89@archlinux> In-Reply-To: <20200424051818.6408-4-alexandru.ardelean@analog.com> References: <20200424051818.6408-1-alexandru.ardelean@analog.com> <20200424051818.6408-4-alexandru.ardelean@analog.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 24 Apr 2020 08:18:17 +0300 Alexandru Ardelean wrote: > From: Lars-Peter Clausen > > 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. Hmm. The problem with this (and the reason I have resisted this in the past) is that this fundamentally breaks the existing ABI. Whilst we have never explicitly stated that this can't be done (I think) a lot of code may assume it. Are we sure this doesn't break existing userspace in weird and wonderful ways? I'm sure someone does stuff 'in place' on the incoming data streams for example which this would break. Also does the demux work with these if we have multiple consumers? Seems unlikely that it will do it efficiently if at all. J > > 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 > Signed-off-by: Alexandru Ardelean > --- > 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;