linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Jonathan Cameron <jic23@cam.ac.uk>,
	Michael Hennerich <michael.hennerich@analog.com>,
	linux-iio@vger.kernel.org,
	device-drivers-devel@blackfin.uclinux.org, drivers@analog.com
Subject: Re: [PATCH v2 01/13] staging:iio:ring_sw: Add helper function for initializing simple setups
Date: Tue, 13 Dec 2011 15:55:02 +0100	[thread overview]
Message-ID: <4EE76746.5020501@metafoo.de> (raw)
In-Reply-To: <1323686585-15181-1-git-send-email-lars@metafoo.de>

On 12/12/2011 11:42 AM, Lars-Peter Clausen wrote:
> Add a helper function for executing the common tasks which are usually involved
> in setting up a simple software ringbuffer. It will allocate the buffer,
> allocate the pollfunc and register the buffer.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> 
> ---
> Changes since v1:
> 	Added an optional setup_ops parameter to iio_sw_rb_simple_setup which allows
> 	a driver to provide it's own setup_ops which is sometimes necessary if for
> 	example the device needs to enter a special mode before the conversions
> 	starts and should leave after the conversions are done. This change allows
> 	to convert some more drivers. Infact now almost all users of the ring_sw
> 	buffer use this helper function.


I've reworked this another time, so no need to review/ack this series.

I've renamed iio_sw_rb_simple_setup to iio_triggered_buffer_setup because
that's what it more or less is. I've also added another parameter to pass the
buffer allocate function, so this can also be used with the kfifo buffer
implementation. Will send out the updated patches later.

> ---
>  drivers/staging/iio/ring_sw.c |   88 +++++++++++++++++++++++++++++++++++++++++
>  drivers/staging/iio/ring_sw.h |    9 ++++
>  2 files changed, 97 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
> index 98b66a0..9b57ced 100644
> --- a/drivers/staging/iio/ring_sw.c
> +++ b/drivers/staging/iio/ring_sw.c
> @@ -16,6 +16,7 @@
>  #include <linux/poll.h>
>  #include "ring_sw.h"
>  #include "trigger.h"
> +#include "trigger_consumer.h"
>  
>  /**
>   * struct iio_sw_ring_buffer - software ring buffer
> @@ -402,5 +403,92 @@ const struct iio_buffer_access_funcs ring_sw_access_funcs = {
>  };
>  EXPORT_SYMBOL(ring_sw_access_funcs);
>  
> +static const struct iio_buffer_setup_ops iio_sw_rb_simple_setup_ops = {
> +	.preenable = &iio_sw_buffer_preenable,
> +	.postenable = &iio_triggered_buffer_postenable,
> +	.predisable = &iio_triggered_buffer_predisable,
> +};
> +
> +/**
> + * iio_sw_rb_simple_setup() - Setup simple software ringbuffer and pollfunc
> + * @indio_dev:		IIO device structure
> + * @pollfunc_bh:	Function which will be used as pollfunc bottom half
> + * @pollfunc_th:	Function which will be used as pollfunc top half
> + * @setup_ops:		Buffer setup functions to use for this device.
> + *			If NULL the default setup functions for triggered
> + *			buffers will be used.
> + *
> + * This function combines some common tasks which will normally be performed
> + * when setting up a simple software ringbuffer. It will allocate the ringbuffer
> + * and the pollfunc, as well as register the buffer with IIO core.
> + * Before calling this function the indio_dev structure should already be
> + * completly initzialized but not yet registered.
> + *
> + * To free the resources allocated by this function iio_sw_rb_simple_cleanup
> + * should be called.
> + */
> +int iio_sw_rb_simple_setup(struct iio_dev *indio_dev,
> +	irqreturn_t (*pollfunc_bh)(int irq, void *p),
> +	irqreturn_t (*pollfunc_th)(int irq, void *p),
> +	const struct iio_buffer_setup_ops *setup_ops)
> +{
> +	int ret;
> +
> +	indio_dev->buffer = iio_sw_rb_allocate(indio_dev);
> +	if (!indio_dev->buffer) {
> +		ret = -ENOMEM;
> +		goto error_ret;
> +	}
> +
> +	indio_dev->pollfunc = iio_alloc_pollfunc(pollfunc_bh,
> +						 pollfunc_th,
> +						 IRQF_ONESHOT,
> +						 indio_dev,
> +						 "%s_consumer%d",
> +						 indio_dev->name,
> +						 indio_dev->id);
> +	if (indio_dev->pollfunc == NULL) {
> +		ret = -ENOMEM;
> +		goto error_deallocate_sw_rb;
> +	}
> +
> +	/* Ring buffer functions - here trigger setup related */
> +	if (setup_ops)
> +		indio_dev->setup_ops = setup_ops;
> +	else
> +		indio_dev->setup_ops = &iio_sw_rb_simple_setup_ops;
> +
> +	/* Flag that polled ring buffering is possible */
> +	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
> +
> +	ret = iio_buffer_register(indio_dev,
> +				  indio_dev->channels,
> +				  indio_dev->num_channels);
> +	if (ret)
> +		goto error_dealloc_pollfunc;
> +
> +	return 0;
> +
> +error_dealloc_pollfunc:
> +	iio_dealloc_pollfunc(indio_dev->pollfunc);
> +error_deallocate_sw_rb:
> +	iio_sw_rb_free(indio_dev->buffer);
> +error_ret:
> +	return ret;
> +}
> +EXPORT_SYMBOL(iio_sw_rb_simple_setup);
> +
> +/**
> + * iio_sw_rb_simple_cleanup() - Free resources allocated by iio_sw_rb_simple_setup
> + * @indio_dev:		IIO device structure
> + */
> +void iio_sw_rb_simple_cleanup(struct iio_dev *indio_dev)
> +{
> +	iio_buffer_unregister(indio_dev);
> +	iio_dealloc_pollfunc(indio_dev->pollfunc);
> +	iio_sw_rb_free(indio_dev->buffer);
> +}
> +EXPORT_SYMBOL(iio_sw_rb_simple_cleanup);
> +
>  MODULE_DESCRIPTION("Industrialio I/O software ring buffer");
>  MODULE_LICENSE("GPL");
> diff --git a/drivers/staging/iio/ring_sw.h b/drivers/staging/iio/ring_sw.h
> index e6a6e2c..3a61fe3 100644
> --- a/drivers/staging/iio/ring_sw.h
> +++ b/drivers/staging/iio/ring_sw.h
> @@ -23,6 +23,8 @@
>  
>  #ifndef _IIO_RING_SW_H_
>  #define _IIO_RING_SW_H_
> +
> +#include <linux/interrupt.h>
>  #include "buffer.h"
>  
>  /**
> @@ -32,4 +34,11 @@ extern const struct iio_buffer_access_funcs ring_sw_access_funcs;
>  
>  struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev);
>  void iio_sw_rb_free(struct iio_buffer *ring);
> +
> +int iio_sw_rb_simple_setup(struct iio_dev *indio_dev,
> +	irqreturn_t (*pollfunc_bh)(int irq, void *p),
> +	irqreturn_t (*pollfunc_th)(int irq, void *p),
> +	const struct iio_buffer_setup_ops *setup_ops);
> +void iio_sw_rb_simple_cleanup(struct iio_dev *indio_dev);
> +
>  #endif /* _IIO_RING_SW_H_ */


      parent reply	other threads:[~2011-12-13 14:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12 10:42 [PATCH v2 01/13] staging:iio:ring_sw: Add helper function for initializing simple setups Lars-Peter Clausen
2011-12-12 10:42 ` [PATCH v2 02/13] staging:iio:accel:adis16201: Use new ringbuffer setup helper function Lars-Peter Clausen
2011-12-12 10:42 ` [PATCH v2 03/13] staging:iio:adc:ad7192: " Lars-Peter Clausen
2011-12-12 10:42 ` [PATCH v2 04/13] staging:iio:adc:ad7298: " Lars-Peter Clausen
2011-12-12 10:42 ` [PATCH v2 05/13] staging:iio:adc:ad7476: " Lars-Peter Clausen
2011-12-12 10:42 ` [PATCH v2 06/13] staging:iio:adc:ad7606: " Lars-Peter Clausen
2011-12-12 10:42 ` [PATCH v2 07/13] staging:iio:adc:ad7793: " Lars-Peter Clausen
2011-12-12 10:43 ` [PATCH v2 08/13] staging:iio:adc:ad7887: " Lars-Peter Clausen
2011-12-12 10:43 ` [PATCH v2 09/13] staging:iio:adc:ad799x: " Lars-Peter Clausen
2011-12-12 10:43 ` [PATCH v2 10/13] staging:iio:adc:max1363: " Lars-Peter Clausen
2011-12-12 10:43 ` [PATCH v2 11/13] staging:iio:gyro:adis16260: " Lars-Peter Clausen
2011-12-12 10:43 ` [PATCH v2 12/13] staging:iio:imu:adis16400: " Lars-Peter Clausen
2011-12-12 10:43 ` [PATCH v2 13/13] staging:iio:meter:ade7758: " Lars-Peter Clausen
2011-12-13 14:55 ` Lars-Peter Clausen [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=4EE76746.5020501@metafoo.de \
    --to=lars@metafoo.de \
    --cc=device-drivers-devel@blackfin.uclinux.org \
    --cc=drivers@analog.com \
    --cc=jic23@cam.ac.uk \
    --cc=linux-iio@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    /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).