staging: iio: Add iio_triggered_ring postenable and predisable + use in drivers

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Barry Song <21cnbao@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Jonathan Cameron 2010-07-11 16:39:10 +01:00 committed by Greg Kroah-Hartman
parent 15744090c5
commit c3db00cc80
10 changed files with 41 additions and 158 deletions

View file

@ -186,22 +186,6 @@ static int adis16209_data_rdy_ring_preenable(struct iio_dev *indio_dev)
return 0;
}
static int adis16209_data_rdy_ring_postenable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
static int adis16209_data_rdy_ring_predisable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_dettach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
void adis16209_unconfigure_ring(struct iio_dev *indio_dev)
{
kfree(indio_dev->pollfunc);
@ -237,8 +221,8 @@ int adis16209_configure_ring(struct iio_dev *indio_dev)
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->preenable = &adis16209_data_rdy_ring_preenable;
ring->postenable = &adis16209_data_rdy_ring_postenable;
ring->predisable = &adis16209_data_rdy_ring_predisable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->owner = THIS_MODULE;
ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16209_poll_func_th);

View file

@ -176,22 +176,6 @@ static int adis16240_data_rdy_ring_preenable(struct iio_dev *indio_dev)
return 0;
}
static int adis16240_data_rdy_ring_postenable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
static int adis16240_data_rdy_ring_predisable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_dettach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
void adis16240_unconfigure_ring(struct iio_dev *indio_dev)
{
kfree(indio_dev->pollfunc);
@ -225,8 +209,8 @@ int adis16240_configure_ring(struct iio_dev *indio_dev)
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->preenable = &adis16240_data_rdy_ring_preenable;
ring->postenable = &adis16240_data_rdy_ring_postenable;
ring->predisable = &adis16240_data_rdy_ring_predisable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->owner = THIS_MODULE;
ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16240_poll_func_th);

View file

@ -339,23 +339,6 @@ static int lis3l02dq_data_rdy_ring_preenable(struct iio_dev *indio_dev)
return 0;
}
static int lis3l02dq_data_rdy_ring_postenable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
static int lis3l02dq_data_rdy_ring_predisable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_dettach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
/* Caller responsible for locking as necessary. */
static int
__lis3l02dq_write_data_ready_config(struct device *dev,
@ -562,8 +545,8 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev)
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->preenable = &lis3l02dq_data_rdy_ring_preenable;
ring->postenable = &lis3l02dq_data_rdy_ring_postenable;
ring->predisable = &lis3l02dq_data_rdy_ring_predisable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->owner = THIS_MODULE;
ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th);

View file

@ -105,35 +105,6 @@ static int max1363_ring_preenable(struct iio_dev *indio_dev)
return 0;
}
/**
* max1363_ring_postenable() - typical ring post enable
*
* Only not moved into the core for the hardware ring buffer cases
* that are more sophisticated.
**/
static int max1363_ring_postenable(struct iio_dev *indio_dev)
{
if (indio_dev->trig == NULL)
return 0;
return iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc);
}
/**
* max1363_ring_predisable() - runs just prior to ring buffer being disabled
*
* Typical predisable function which ensures that no trigger events can
* occur before we disable the ring buffer (and hence would have no idea
* what to do with them)
**/
static int max1363_ring_predisable(struct iio_dev *indio_dev)
{
if (indio_dev->trig)
return iio_trigger_dettach_poll_func(indio_dev->trig,
indio_dev->pollfunc);
else
return 0;
}
/**
* max1363_poll_func_th() - th of trigger launched polling to ring buffer
@ -228,9 +199,9 @@ int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
goto error_deallocate_sw_rb;
/* Ring buffer functions - here trigger setup related */
indio_dev->ring->postenable = &max1363_ring_postenable;
indio_dev->ring->postenable = &iio_triggered_ring_postenable;
indio_dev->ring->preenable = &max1363_ring_preenable;
indio_dev->ring->predisable = &max1363_ring_predisable;
indio_dev->ring->predisable = &iio_triggered_ring_predisable;
INIT_WORK(&st->poll_work, &max1363_poll_bh_to_ring);
/* Flag that polled ring buffering is possible */

View file

@ -179,22 +179,6 @@ static int adis16260_data_rdy_ring_preenable(struct iio_dev *indio_dev)
return 0;
}
static int adis16260_data_rdy_ring_postenable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
static int adis16260_data_rdy_ring_predisable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_dettach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
void adis16260_unconfigure_ring(struct iio_dev *indio_dev)
{
kfree(indio_dev->pollfunc);
@ -227,8 +211,8 @@ int adis16260_configure_ring(struct iio_dev *indio_dev)
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->preenable = &adis16260_data_rdy_ring_preenable;
ring->postenable = &adis16260_data_rdy_ring_postenable;
ring->predisable = &adis16260_data_rdy_ring_predisable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->owner = THIS_MODULE;
ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16260_poll_func_th);

View file

@ -200,22 +200,6 @@ static int adis16300_data_rdy_ring_preenable(struct iio_dev *indio_dev)
return 0;
}
static int adis16300_data_rdy_ring_postenable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
static int adis16300_data_rdy_ring_predisable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_dettach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
void adis16300_unconfigure_ring(struct iio_dev *indio_dev)
{
kfree(indio_dev->pollfunc);
@ -252,8 +236,8 @@ int adis16300_configure_ring(struct iio_dev *indio_dev)
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->preenable = &adis16300_data_rdy_ring_preenable;
ring->postenable = &adis16300_data_rdy_ring_postenable;
ring->predisable = &adis16300_data_rdy_ring_predisable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->owner = THIS_MODULE;
ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16300_poll_func_th);

View file

@ -203,22 +203,6 @@ static int adis16350_data_rdy_ring_preenable(struct iio_dev *indio_dev)
return 0;
}
static int adis16350_data_rdy_ring_postenable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
static int adis16350_data_rdy_ring_predisable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_dettach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
void adis16350_unconfigure_ring(struct iio_dev *indio_dev)
{
kfree(indio_dev->pollfunc);
@ -257,8 +241,8 @@ int adis16350_configure_ring(struct iio_dev *indio_dev)
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->preenable = &adis16350_data_rdy_ring_preenable;
ring->postenable = &adis16350_data_rdy_ring_postenable;
ring->predisable = &adis16350_data_rdy_ring_predisable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->owner = THIS_MODULE;
ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16350_poll_func_th);

View file

@ -209,22 +209,6 @@ static int adis16400_data_rdy_ring_preenable(struct iio_dev *indio_dev)
return 0;
}
static int adis16400_data_rdy_ring_postenable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
static int adis16400_data_rdy_ring_predisable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_dettach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
{
kfree(indio_dev->pollfunc);
@ -264,8 +248,8 @@ int adis16400_configure_ring(struct iio_dev *indio_dev)
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->preenable = &adis16400_data_rdy_ring_preenable;
ring->postenable = &adis16400_data_rdy_ring_postenable;
ring->predisable = &adis16400_data_rdy_ring_predisable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->owner = THIS_MODULE;
ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16400_poll_func_th);

View file

@ -411,3 +411,21 @@ int iio_alloc_pollfunc(struct iio_dev *indio_dev,
return 0;
}
EXPORT_SYMBOL(iio_alloc_pollfunc);
int iio_triggered_ring_postenable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_attach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
EXPORT_SYMBOL(iio_triggered_ring_postenable);
int iio_triggered_ring_predisable(struct iio_dev *indio_dev)
{
return indio_dev->trig
? iio_trigger_dettach_poll_func(indio_dev->trig,
indio_dev->pollfunc)
: 0;
}
EXPORT_SYMBOL(iio_triggered_ring_predisable);

View file

@ -152,6 +152,13 @@ int iio_alloc_pollfunc(struct iio_dev *indio_dev,
void (*immediate)(struct iio_dev *indio_dev),
void (*main)(struct iio_dev *private_data));
/*
* Two functions for common case where all that happens is a pollfunc
* is attached and detached form a trigger
*/
int iio_triggered_ring_postenable(struct iio_dev *indio_dev);
int iio_triggered_ring_predisable(struct iio_dev *indio_dev);
struct iio_trigger *iio_allocate_trigger(void);
void iio_free_trigger(struct iio_trigger *trig);