summaryrefslogtreecommitdiff
path: root/drivers/staging/iio/adc/ad799x_ring.c
diff options
context:
space:
mode:
authorMichael Hennerich <michael.hennerich@analog.com>2011-02-24 22:19:50 +0100
committerGreg Kroah-Hartman <gregkh@suse.de>2011-02-28 14:40:56 -0800
commita2396dfc63d4b133d0b820db978065367529f6ac (patch)
treea37304276cccd6f55bb5ab975c3088a66dee6db1 /drivers/staging/iio/adc/ad799x_ring.c
parentdcfb0863eec8ff0a3b2cee13e4f0e5bb5f0c3122 (diff)
IIO: ADC: AD799x: Update timestamp handling
Add timestamp attributes. Revise timestamp handling accordingly. Preset timestamp generation. Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Acked-by: Jonathan Cameron <jic23@cam.ac.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/iio/adc/ad799x_ring.c')
-rw-r--r--drivers/staging/iio/adc/ad799x_ring.c43
1 files changed, 16 insertions, 27 deletions
diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c
index 975cdcbf0830..56abc395f177 100644
--- a/drivers/staging/iio/adc/ad799x_ring.c
+++ b/drivers/staging/iio/adc/ad799x_ring.c
@@ -73,8 +73,6 @@ static int ad799x_ring_preenable(struct iio_dev *indio_dev)
{
struct iio_ring_buffer *ring = indio_dev->ring;
struct ad799x_state *st = indio_dev->dev_data;
- size_t d_size;
- unsigned long numvals;
/*
* Need to figure out the current mode based upon the requested
@@ -84,15 +82,19 @@ static int ad799x_ring_preenable(struct iio_dev *indio_dev)
if (st->id == ad7997 || st->id == ad7998)
ad799x_set_scan_mode(st, ring->scan_mask);
- numvals = ring->scan_count;
+ st->d_size = ring->scan_count * 2;
- if (ring->access.set_bytes_per_datum) {
- d_size = numvals*2 + sizeof(s64);
- if (d_size % 8)
- d_size += 8 - (d_size % 8);
- ring->access.set_bytes_per_datum(ring, d_size);
+ if (ring->scan_timestamp) {
+ st->d_size += sizeof(s64);
+
+ if (st->d_size % sizeof(s64))
+ st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
}
+ if (indio_dev->ring->access.set_bytes_per_datum)
+ indio_dev->ring->access.set_bytes_per_datum(indio_dev->ring,
+ st->d_size);
+
return 0;
}
@@ -130,29 +132,13 @@ static void ad799x_poll_bh_to_ring(struct work_struct *work_s)
s64 time_ns;
__u8 *rxbuf;
int b_sent;
- size_t d_size;
u8 cmd;
- unsigned long numvals = ring->scan_count;
-
- /* Ensure the timestamp is 8 byte aligned */
- d_size = numvals*2 + sizeof(s64);
-
- if (d_size % sizeof(s64))
- d_size += sizeof(s64) - (d_size % sizeof(s64));
-
/* Ensure only one copy of this function running at a time */
if (atomic_inc_return(&st->protect_ring) > 1)
return;
- /* Monitor mode prevents reading. Whilst not currently implemented
- * might as well have this test in here in the meantime as it does
- * no harm.
- */
- if (numvals == 0)
- return;
-
- rxbuf = kmalloc(d_size, GFP_KERNEL);
+ rxbuf = kmalloc(st->d_size, GFP_KERNEL);
if (rxbuf == NULL)
return;
@@ -177,13 +163,15 @@ static void ad799x_poll_bh_to_ring(struct work_struct *work_s)
}
b_sent = i2c_smbus_read_i2c_block_data(st->client,
- cmd, numvals*2, rxbuf);
+ cmd, ring->scan_count * 2, rxbuf);
if (b_sent < 0)
goto done;
time_ns = iio_get_time_ns();
- memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
+ if (ring->scan_timestamp)
+ memcpy(rxbuf + st->d_size - sizeof(s64),
+ &time_ns, sizeof(time_ns));
ring->access.store_to(&ring_sw->buf, rxbuf, time_ns);
done:
@@ -213,6 +201,7 @@ int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
indio_dev->ring->preenable = &ad799x_ring_preenable;
indio_dev->ring->postenable = &iio_triggered_ring_postenable;
indio_dev->ring->predisable = &iio_triggered_ring_predisable;
+ indio_dev->ring->scan_timestamp = true;
INIT_WORK(&st->poll_work, &ad799x_poll_bh_to_ring);