Skip to content

Commit

Permalink
staging:iio: rationalization of different buffer implementation hooks.
Browse files Browse the repository at this point in the history
1) move a generic helper function out of ring_sw. It applies to other buffers as well.
2) Get rid of a lot of left over function definitions.
3) Move all the access functions into static structures.
4) Introduce and use a static structure for the setup functions, preenable etc.

Some driver conversions thanks to Michael Hennerich (pulled out of patches
that would otherwise sit after this).

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Jonathan Cameron authored and Greg Kroah-Hartman committed May 19, 2011
1 parent 38d15f0 commit 5565a45
Show file tree
Hide file tree
Showing 23 changed files with 363 additions and 463 deletions.
16 changes: 10 additions & 6 deletions drivers/staging/iio/accel/adis16201_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)

int i = 0;
s16 *data;
size_t datasize = ring->access.get_bytes_per_datum(ring);
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize, GFP_KERNEL);
if (data == NULL) {
Expand All @@ -86,7 +86,7 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)
if (ring->scan_timestamp)
*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;

ring->access.store_to(ring, (u8 *)data, pf->timestamp);
ring->access->store_to(ring, (u8 *)data, pf->timestamp);

iio_trigger_notify_done(st->indio_dev->trig);
kfree(data);
Expand All @@ -101,6 +101,12 @@ void adis16201_unconfigure_ring(struct iio_dev *indio_dev)
iio_sw_rb_free(indio_dev->ring);
}

static const struct iio_ring_setup_ops adis16201_ring_setup_ops = {
.preenable = &iio_sw_ring_preenable,
.postenable = &iio_triggered_ring_postenable,
.predisable = &iio_triggered_ring_predisable,
};

int adis16201_configure_ring(struct iio_dev *indio_dev)
{
int ret = 0;
Expand All @@ -113,12 +119,10 @@ int adis16201_configure_ring(struct iio_dev *indio_dev)
}
indio_dev->ring = ring;
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->bpe = 2;
ring->scan_timestamp = true;
ring->preenable = &iio_sw_ring_preenable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->access = &ring_sw_access_funcs;
ring->setup_ops = &adis16201_ring_setup_ops;
ring->owner = THIS_MODULE;

/* Set default scan mode */
Expand Down
16 changes: 10 additions & 6 deletions drivers/staging/iio/accel/adis16203_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p)

int i = 0;
s16 *data;
size_t datasize = ring->access.get_bytes_per_datum(ring);
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize, GFP_KERNEL);
if (data == NULL) {
Expand All @@ -91,7 +91,7 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p)
if (ring->scan_timestamp)
*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;

ring->access.store_to(ring,
ring->access->store_to(ring,
(u8 *)data,
pf->timestamp);

Expand All @@ -108,6 +108,12 @@ void adis16203_unconfigure_ring(struct iio_dev *indio_dev)
iio_sw_rb_free(indio_dev->ring);
}

static const struct iio_ring_setup_ops adis16203_ring_setup_ops = {
.preenable = &iio_sw_ring_preenable,
.postenable = &iio_triggered_ring_postenable,
.predisable = &iio_triggered_ring_predisable,
};

int adis16203_configure_ring(struct iio_dev *indio_dev)
{
int ret = 0;
Expand All @@ -120,12 +126,10 @@ int adis16203_configure_ring(struct iio_dev *indio_dev)
}
indio_dev->ring = ring;
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->bpe = 2;
ring->scan_timestamp = true;
ring->preenable = &iio_sw_ring_preenable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->access = &ring_sw_access_funcs;
ring->setup_ops = &adis16203_ring_setup_ops;
ring->owner = THIS_MODULE;

/* Set default scan mode */
Expand Down
16 changes: 10 additions & 6 deletions drivers/staging/iio/accel/adis16204_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p)
struct iio_ring_buffer *ring = indio_dev->ring;
int i = 0;
s16 *data;
size_t datasize = ring->access.get_bytes_per_datum(ring);
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize, GFP_KERNEL);
if (data == NULL) {
Expand All @@ -88,7 +88,7 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p)
if (ring->scan_timestamp)
*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;

ring->access.store_to(ring, (u8 *)data, pf->timestamp);
ring->access->store_to(ring, (u8 *)data, pf->timestamp);

iio_trigger_notify_done(st->indio_dev->trig);
kfree(data);
Expand All @@ -103,6 +103,12 @@ void adis16204_unconfigure_ring(struct iio_dev *indio_dev)
iio_sw_rb_free(indio_dev->ring);
}

static const struct iio_ring_setup_ops adis16204_ring_setup_ops = {
.preenable = &iio_sw_ring_preenable,
.postenable = &iio_triggered_ring_postenable,
.predisable = &iio_triggered_ring_predisable,
};

int adis16204_configure_ring(struct iio_dev *indio_dev)
{
int ret = 0;
Expand All @@ -115,12 +121,10 @@ int adis16204_configure_ring(struct iio_dev *indio_dev)
}
indio_dev->ring = ring;
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->access = &ring_sw_access_funcs;
ring->bpe = 2;
ring->scan_timestamp = true;
ring->preenable = &iio_sw_ring_preenable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->setup_ops = &adis16204_ring_setup_ops;
ring->owner = THIS_MODULE;

/* Set default scan mode */
Expand Down
16 changes: 10 additions & 6 deletions drivers/staging/iio/accel/adis16209_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p)

int i = 0;
s16 *data;
size_t datasize = ring->access.get_bytes_per_datum(ring);
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize , GFP_KERNEL);
if (data == NULL) {
Expand All @@ -88,7 +88,7 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p)
if (ring->scan_timestamp)
*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;

ring->access.store_to(ring, (u8 *)data, pf->timestamp);
ring->access->store_to(ring, (u8 *)data, pf->timestamp);

iio_trigger_notify_done(st->indio_dev->trig);
kfree(data);
Expand All @@ -103,6 +103,12 @@ void adis16209_unconfigure_ring(struct iio_dev *indio_dev)
iio_sw_rb_free(indio_dev->ring);
}

static const struct iio_ring_setup_ops adis16209_ring_setup_ops = {
.preenable = &iio_sw_ring_preenable,
.postenable = &iio_triggered_ring_postenable,
.predisable = &iio_triggered_ring_predisable,
};

int adis16209_configure_ring(struct iio_dev *indio_dev)
{
int ret = 0;
Expand All @@ -115,12 +121,10 @@ int adis16209_configure_ring(struct iio_dev *indio_dev)
}
indio_dev->ring = ring;
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->access = &ring_sw_access_funcs;
ring->bpe = 2;
ring->scan_timestamp = true;
ring->preenable = &iio_sw_ring_preenable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->setup_ops = &adis16209_ring_setup_ops;
ring->owner = THIS_MODULE;

/* Set default scan mode */
Expand Down
16 changes: 10 additions & 6 deletions drivers/staging/iio/accel/adis16240_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p)

int i = 0;
s16 *data;
size_t datasize = ring->access.get_bytes_per_datum(ring);
size_t datasize = ring->access->get_bytes_per_datum(ring);

data = kmalloc(datasize, GFP_KERNEL);
if (data == NULL) {
Expand All @@ -85,7 +85,7 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p)
if (ring->scan_timestamp)
*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;

ring->access.store_to(ring, (u8 *)data, pf->timestamp);
ring->access->store_to(ring, (u8 *)data, pf->timestamp);

iio_trigger_notify_done(st->indio_dev->trig);
kfree(data);
Expand All @@ -100,6 +100,12 @@ void adis16240_unconfigure_ring(struct iio_dev *indio_dev)
iio_sw_rb_free(indio_dev->ring);
}

static const struct iio_ring_setup_ops adis16240_ring_setup_ops = {
.preenable = &iio_sw_ring_preenable,
.postenable = &iio_triggered_ring_postenable,
.predisable = &iio_triggered_ring_predisable,
};

int adis16240_configure_ring(struct iio_dev *indio_dev)
{
int ret = 0;
Expand All @@ -112,12 +118,10 @@ int adis16240_configure_ring(struct iio_dev *indio_dev)
}
indio_dev->ring = ring;
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->access = &ring_sw_access_funcs;
ring->bpe = 2;
ring->scan_timestamp = true;
ring->preenable = &iio_sw_ring_preenable;
ring->postenable = &iio_triggered_ring_postenable;
ring->predisable = &iio_triggered_ring_predisable;
ring->setup_ops = &adis16240_ring_setup_ops;
ring->owner = THIS_MODULE;

/* Set default scan mode */
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/iio/accel/lis3l02dq.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ void lis3l02dq_unconfigure_ring(struct iio_dev *indio_dev);
#ifdef CONFIG_LIS3L02DQ_BUF_RING_SW
#define lis3l02dq_free_buf iio_sw_rb_free
#define lis3l02dq_alloc_buf iio_sw_rb_allocate
#define lis3l02dq_register_buf_funcs iio_ring_sw_register_funcs
#define lis3l02dq_access_funcs ring_sw_access_funcs
#endif
#ifdef CONFIG_LIS3L02DQ_BUF_KFIFO
#define lis3l02dq_free_buf iio_kfifo_free
#define lis3l02dq_alloc_buf iio_kfifo_allocate
#define lis3l02dq_register_buf_funcs iio_kfifo_register_funcs
#define lis3l02dq_access_funcs kfifo_access_funcs
#endif
irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private);
#define lis3l02dq_th lis3l02dq_data_rdy_trig_poll
Expand Down
15 changes: 9 additions & 6 deletions drivers/staging/iio/accel/lis3l02dq_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ ssize_t lis3l02dq_read_accel_from_ring(struct iio_ring_buffer *ring,
if (!iio_scan_mask_query(ring, index))
return -EINVAL;

data = kmalloc(ring->access.get_bytes_per_datum(ring),
data = kmalloc(ring->access->get_bytes_per_datum(ring),
GFP_KERNEL);
if (data == NULL)
return -ENOMEM;

ret = ring->access.read_last(ring, (u8 *)data);
ret = ring->access->read_last(ring, (u8 *)data);
if (ret)
goto error_free_data;
*val = data[iio_scan_mask_count_to_right(ring, index)];
Expand Down Expand Up @@ -400,6 +400,11 @@ static int lis3l02dq_ring_predisable(struct iio_dev *indio_dev)
return ret;
}

static const struct iio_ring_setup_ops lis3l02dq_ring_setup_ops = {
.preenable = &iio_sw_ring_preenable,
.postenable = &lis3l02dq_ring_postenable,
.predisable = &lis3l02dq_ring_predisable,
};

int lis3l02dq_configure_ring(struct iio_dev *indio_dev)
{
Expand All @@ -415,13 +420,11 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev)

indio_dev->ring = ring;
/* Effectively select the ring buffer implementation */
lis3l02dq_register_buf_funcs(&ring->access);
indio_dev->ring->access = &lis3l02dq_access_funcs;
ring->bpe = 2;

ring->scan_timestamp = true;
ring->preenable = &iio_sw_ring_preenable;
ring->postenable = &lis3l02dq_ring_postenable;
ring->predisable = &lis3l02dq_ring_predisable;
ring->setup_ops = &lis3l02dq_ring_setup_ops;
ring->owner = THIS_MODULE;

/* Set default scan mode */
Expand Down
19 changes: 13 additions & 6 deletions drivers/staging/iio/accel/sca3000_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,20 @@ static inline void sca3000_rb_free(struct iio_ring_buffer *r)
iio_put_ring_buffer(r);
}

static const struct iio_ring_access_funcs sca3000_ring_access_funcs = {
.read_first_n = &sca3000_read_first_n_hw_rb,
.get_length = &sca3000_ring_get_length,
.get_bytes_per_datum = &sca3000_ring_get_bytes_per_datum,
};

int sca3000_configure_ring(struct iio_dev *indio_dev)
{
indio_dev->ring = sca3000_rb_allocate(indio_dev);
if (indio_dev->ring == NULL)
return -ENOMEM;
indio_dev->modes |= INDIO_RING_HARDWARE_BUFFER;

indio_dev->ring->access.read_first_n = &sca3000_read_first_n_hw_rb;
indio_dev->ring->access.get_length = &sca3000_ring_get_length;
indio_dev->ring->access.get_bytes_per_datum =
&sca3000_ring_get_bytes_per_datum;
indio_dev->ring->access = &sca3000_ring_access_funcs;

iio_scan_mask_set(indio_dev->ring, 0);
iio_scan_mask_set(indio_dev->ring, 1);
Expand Down Expand Up @@ -432,10 +435,14 @@ static int sca3000_hw_ring_postdisable(struct iio_dev *indio_dev)
return __sca3000_hw_ring_state_set(indio_dev, 0);
}

static const struct iio_ring_setup_ops sca3000_ring_setup_ops = {
.preenable = &sca3000_hw_ring_preenable,
.postdisable = &sca3000_hw_ring_postdisable,
};

void sca3000_register_ring_funcs(struct iio_dev *indio_dev)
{
indio_dev->ring->preenable = &sca3000_hw_ring_preenable;
indio_dev->ring->postdisable = &sca3000_hw_ring_postdisable;
indio_dev->ring->setup_ops = &sca3000_ring_setup_ops;
}

/**
Expand Down
23 changes: 13 additions & 10 deletions drivers/staging/iio/adc/ad7298_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ int ad7298_scan_from_ring(struct ad7298_state *st, long ch)
goto error_ret;
}

ring_data = kmalloc(ring->access.get_bytes_per_datum(ring),
ring_data = kmalloc(ring->access->get_bytes_per_datum(ring),
GFP_KERNEL);
if (ring_data == NULL) {
ret = -ENOMEM;
goto error_ret;
}
ret = ring->access.read_last(ring, (u8 *) ring_data);
ret = ring->access->read_last(ring, (u8 *) ring_data);
if (ret)
goto error_free_ring_data;

Expand Down Expand Up @@ -74,8 +74,8 @@ static int ad7298_ring_preenable(struct iio_dev *indio_dev)
d_size += sizeof(s64) - (d_size % sizeof(s64));
}

if (ring->access.set_bytes_per_datum)
ring->access.set_bytes_per_datum(ring, d_size);
if (ring->access->set_bytes_per_datum)
ring->access->set_bytes_per_datum(ring, d_size);

st->d_size = d_size;

Expand Down Expand Up @@ -140,12 +140,18 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
for (i = 0; i < ring->scan_count; i++)
buf[i] = be16_to_cpu(st->rx_buf[i]);

indio_dev->ring->access.store_to(ring, (u8 *)buf, time_ns);
indio_dev->ring->access->store_to(ring, (u8 *)buf, time_ns);
iio_trigger_notify_done(indio_dev->trig);

return IRQ_HANDLED;
}

static const struct iio_ring_setup_ops ad7298_ring_setup_ops = {
.preenable = &ad7298_ring_preenable,
.postenable = &iio_triggered_ring_postenable,
.predisable = &iio_triggered_ring_predisable,
};

int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
{
int ret;
Expand All @@ -156,7 +162,7 @@ int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
goto error_ret;
}
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&indio_dev->ring->access);
indio_dev->ring->access = &ring_sw_access_funcs;

indio_dev->pollfunc = kzalloc(sizeof(*indio_dev->pollfunc), GFP_KERNEL);
if (indio_dev->pollfunc == NULL) {
Expand All @@ -173,10 +179,7 @@ int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
goto error_free_poll_func;
}
/* Ring buffer functions - here trigger setup related */
indio_dev->ring->preenable = &ad7298_ring_preenable;
indio_dev->ring->postenable = &iio_triggered_ring_postenable;
indio_dev->ring->predisable = &iio_triggered_ring_predisable;

indio_dev->ring->setup_ops = &ad7298_ring_setup_ops;
indio_dev->ring->scan_timestamp = true;

/* Flag that polled ring buffering is possible */
Expand Down
Loading

0 comments on commit 5565a45

Please sign in to comment.