From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 1/6] iio: Add callback to check whether a scan mask is valid
Date: Mon, 09 Jul 2012 18:30:14 +0100 [thread overview]
Message-ID: <4FFB1526.3010808@kernel.org> (raw)
In-Reply-To: <1341824452-28803-1-git-send-email-lars@metafoo.de>
On 07/09/2012 10:00 AM, Lars-Peter Clausen wrote:
> This is useful for cases where the number of valid scan masks grows
> exponentially, but it is rather easy to check whether a mask is valid or not
> programmatically.
>
> An example of such a case is a device with multiple ADCs where each ADC has a
> upstream MUX, which allows to select from a number of physical channels.
>
> +-------+ +-------+
> | | | | --- Channel 1
> | ADC 1 |---| MUX 1 | --- ...
> | | | | --- Channel M
> +-------+ +-------+
>
> . . .
> . . .
> . . .
>
> +-------+ +-------+
> | | | | --- Channel M * N + 1
> | ADC N |---| MUX N | --- ...
> | | | | --- Channel M * N + M
> +-------+ +-------+
>
> The number of necessary scan masks for this case is (M+1)**N - 1, on the other
> hand it is easy to check whether subsets for each ADC of the scanmask have only
> one bit set.
>
merged first 5 to togreg branch. Pull request may be a few days.
Jonathan
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>
> ---
> No changes since v1
> ---
> drivers/iio/industrialio-buffer.c | 27 ++++++++++++++++++++-------
> include/linux/iio/iio.h | 4 ++++
> 2 files changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 3d8d187..cc5db36 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -570,6 +570,15 @@ int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
> }
> EXPORT_SYMBOL(iio_sw_buffer_preenable);
>
> +static bool iio_validate_scan_mask(struct iio_dev *indio_dev,
> + const unsigned long *mask)
> +{
> + if (!indio_dev->setup_ops->validate_scan_mask)
> + return true;
> +
> + return indio_dev->setup_ops->validate_scan_mask(indio_dev, mask);
> +}
> +
> /**
> * iio_scan_mask_set() - set particular bit in the scan mask
> * @buffer: the buffer whose scan mask we are interested in
> @@ -589,27 +598,31 @@ int iio_scan_mask_set(struct iio_dev *indio_dev,
> return -ENOMEM;
> if (!indio_dev->masklength) {
> WARN_ON("trying to set scanmask prior to registering buffer\n");
> - kfree(trialmask);
> - return -EINVAL;
> + goto err_invalid_mask;
> }
> bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength);
> set_bit(bit, trialmask);
>
> + if (!iio_validate_scan_mask(indio_dev, trialmask))
> + goto err_invalid_mask;
> +
> if (indio_dev->available_scan_masks) {
> mask = iio_scan_mask_match(indio_dev->available_scan_masks,
> indio_dev->masklength,
> trialmask);
> - if (!mask) {
> - kfree(trialmask);
> - return -EINVAL;
> - }
> + if (!mask)
> + goto err_invalid_mask;
> }
> bitmap_copy(buffer->scan_mask, trialmask, indio_dev->masklength);
>
> kfree(trialmask);
>
> return 0;
> -};
> +
> +err_invalid_mask:
> + kfree(trialmask);
> + return -EINVAL;
> +}
> EXPORT_SYMBOL_GPL(iio_scan_mask_set);
>
> int iio_scan_mask_query(struct iio_dev *indio_dev,
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 2afbb6f..be82936 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -363,12 +363,16 @@ struct iio_info {
> * @predisable: [DRIVER] function to run prior to marking buffer
> * disabled
> * @postdisable: [DRIVER] function to run after marking buffer disabled
> + * @validate_scan_mask: [DRIVER] function callback to check whether a given
> + * scan mask is valid for the device.
> */
> struct iio_buffer_setup_ops {
> int (*preenable)(struct iio_dev *);
> int (*postenable)(struct iio_dev *);
> int (*predisable)(struct iio_dev *);
> int (*postdisable)(struct iio_dev *);
> + bool (*validate_scan_mask)(struct iio_dev *indio_dev,
> + const unsigned long *scan_mask);
> };
>
> /**
>
prev parent reply other threads:[~2012-07-09 17:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-09 9:00 [PATCH v2 1/6] iio: Add callback to check whether a scan mask is valid Lars-Peter Clausen
2012-07-09 9:00 ` [PATCH v2 2/6] iio: Introduce iio_validate_scan_mask_onehot Lars-Peter Clausen
2012-07-09 9:00 ` [PATCH v2 3/6] staging:iio:ad7192: Use iio_validate_scan_mask_onehot Lars-Peter Clausen
2012-07-09 9:00 ` [PATCH v2 4/6] staging:iio:ad7793: " Lars-Peter Clausen
2012-07-09 9:00 ` [PATCH v2 5/6] staging:iio:ade7758: " Lars-Peter Clausen
2012-07-09 9:00 ` [PATCH v2 6/6] iio: iio_buffer_register: Use correct channel when calculating masklength Lars-Peter Clausen
2012-07-09 9:09 ` Lars-Peter Clausen
2012-07-09 17:30 ` Jonathan Cameron [this message]
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=4FFB1526.3010808@kernel.org \
--to=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.