* [PATCH] IIO: ADC: AD7887: Update timestamp handling
2011-02-24 19:09 [PATCH] IIO: ADC: AD7476: Update timestamp handling michael.hennerich
@ 2011-02-24 19:09 ` michael.hennerich
2011-02-24 19:54 ` Jonathan Cameron
2011-02-24 19:09 ` [PATCH] IIO: ADC: AD7606: " michael.hennerich
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: michael.hennerich @ 2011-02-24 19:09 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, drivers, device-drivers-devel, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Add timestamp attributes.
Revise timestamp handling accordingly.
Preset timestamp generation.
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7887.h | 1 +
drivers/staging/iio/adc/ad7887_ring.c | 36 +++++++++++++++++++-------------
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7887.h b/drivers/staging/iio/adc/ad7887.h
index 8c2a218..439c802 100644
--- a/drivers/staging/iio/adc/ad7887.h
+++ b/drivers/staging/iio/adc/ad7887.h
@@ -63,6 +63,7 @@ struct ad7887_state {
struct regulator *reg;
struct work_struct poll_work;
atomic_t protect_ring;
+ size_t d_size;
u16 int_vref_mv;
bool en_dual;
struct spi_transfer xfer[4];
diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
index 6b9cb1f..2d7fe65 100644
--- a/drivers/staging/iio/adc/ad7887_ring.c
+++ b/drivers/staging/iio/adc/ad7887_ring.c
@@ -27,6 +27,8 @@
static IIO_SCAN_EL_C(in0, 0, 0, NULL);
static IIO_SCAN_EL_C(in1, 1, 0, NULL);
+static IIO_SCAN_EL_TIMESTAMP(2);
+static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
static ssize_t ad7887_show_type(struct device *dev,
struct device_attribute *attr,
@@ -47,6 +49,9 @@ static struct attribute *ad7887_scan_el_attrs[] = {
&iio_const_attr_in0_index.dev_attr.attr,
&iio_scan_el_in1.dev_attr.attr,
&iio_const_attr_in1_index.dev_attr.attr,
+ &iio_const_attr_timestamp_index.dev_attr.attr,
+ &iio_scan_el_timestamp.dev_attr.attr,
+ &iio_const_attr_timestamp_type.dev_attr.attr,
&iio_dev_attr_in_type.dev_attr.attr,
NULL,
};
@@ -118,16 +123,20 @@ static int ad7887_ring_preenable(struct iio_dev *indio_dev)
{
struct ad7887_state *st = indio_dev->dev_data;
struct iio_ring_buffer *ring = indio_dev->ring;
- size_t d_size;
- if (indio_dev->ring->access.set_bytes_per_datum) {
- d_size = st->chip_info->storagebits / 8 + sizeof(s64);
- if (d_size % 8)
- d_size += 8 - (d_size % 8);
- indio_dev->ring->access.set_bytes_per_datum(indio_dev->ring,
- d_size);
+ st->d_size = ring->scan_count * st->chip_info->storagebits / 8;
+
+ 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);
+
switch (ring->scan_mask) {
case (1 << 0):
st->ring_msg = &st->msg[AD7887_CH0];
@@ -186,20 +195,14 @@ static void ad7887_poll_bh_to_ring(struct work_struct *work_s)
s64 time_ns;
__u8 *buf;
int b_sent;
- size_t d_size;
unsigned int bytes = ring->scan_count * st->chip_info->storagebits / 8;
- /* Ensure the timestamp is 8 byte aligned */
- d_size = bytes + 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;
- buf = kzalloc(d_size, GFP_KERNEL);
+ buf = kzalloc(st->d_size, GFP_KERNEL);
if (buf == NULL)
return;
@@ -210,7 +213,9 @@ static void ad7887_poll_bh_to_ring(struct work_struct *work_s)
time_ns = iio_get_time_ns();
memcpy(buf, st->data, bytes);
- memcpy(buf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
+ if (ring->scan_timestamp)
+ memcpy(buf + st->d_size - sizeof(s64),
+ &time_ns, sizeof(time_ns));
indio_dev->ring->access.store_to(&sw_ring->buf, buf, time_ns);
done:
@@ -241,6 +246,7 @@ int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
indio_dev->ring->predisable = &iio_triggered_ring_predisable;
indio_dev->ring->postdisable = &ad7887_ring_postdisable;
indio_dev->ring->scan_el_attrs = &ad7887_scan_el_group;
+ indio_dev->ring->scan_timestamp = true;
INIT_WORK(&st->poll_work, &ad7887_poll_bh_to_ring);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] IIO: ADC: AD7887: Update timestamp handling
2011-02-24 19:09 ` [PATCH] IIO: ADC: AD7887: " michael.hennerich
@ 2011-02-24 19:54 ` Jonathan Cameron
0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2011-02-24 19:54 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, drivers, device-drivers-devel
On 02/24/11 19:09, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> Add timestamp attributes.
> Revise timestamp handling accordingly.
> Preset timestamp generation.
Could group these patches as a series with the explanation of why these are
needed in a cover letter. Would provide explanation to Greg for what
otherwise just looks like adding functionality.
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
> drivers/staging/iio/adc/ad7887.h | 1 +
> drivers/staging/iio/adc/ad7887_ring.c | 36 +++++++++++++++++++-------------
> 2 files changed, 22 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7887.h b/drivers/staging/iio/adc/ad7887.h
> index 8c2a218..439c802 100644
> --- a/drivers/staging/iio/adc/ad7887.h
> +++ b/drivers/staging/iio/adc/ad7887.h
> @@ -63,6 +63,7 @@ struct ad7887_state {
> struct regulator *reg;
> struct work_struct poll_work;
> atomic_t protect_ring;
> + size_t d_size;
> u16 int_vref_mv;
> bool en_dual;
> struct spi_transfer xfer[4];
> diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
> index 6b9cb1f..2d7fe65 100644
> --- a/drivers/staging/iio/adc/ad7887_ring.c
> +++ b/drivers/staging/iio/adc/ad7887_ring.c
> @@ -27,6 +27,8 @@
>
> static IIO_SCAN_EL_C(in0, 0, 0, NULL);
> static IIO_SCAN_EL_C(in1, 1, 0, NULL);
> +static IIO_SCAN_EL_TIMESTAMP(2);
> +static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
>
> static ssize_t ad7887_show_type(struct device *dev,
> struct device_attribute *attr,
> @@ -47,6 +49,9 @@ static struct attribute *ad7887_scan_el_attrs[] = {
> &iio_const_attr_in0_index.dev_attr.attr,
> &iio_scan_el_in1.dev_attr.attr,
> &iio_const_attr_in1_index.dev_attr.attr,
> + &iio_const_attr_timestamp_index.dev_attr.attr,
> + &iio_scan_el_timestamp.dev_attr.attr,
> + &iio_const_attr_timestamp_type.dev_attr.attr,
> &iio_dev_attr_in_type.dev_attr.attr,
> NULL,
> };
> @@ -118,16 +123,20 @@ static int ad7887_ring_preenable(struct iio_dev *indio_dev)
> {
> struct ad7887_state *st = indio_dev->dev_data;
> struct iio_ring_buffer *ring = indio_dev->ring;
> - size_t d_size;
>
> - if (indio_dev->ring->access.set_bytes_per_datum) {
> - d_size = st->chip_info->storagebits / 8 + sizeof(s64);
> - if (d_size % 8)
> - d_size += 8 - (d_size % 8);
> - indio_dev->ring->access.set_bytes_per_datum(indio_dev->ring,
> - d_size);
> + st->d_size = ring->scan_count * st->chip_info->storagebits / 8;
> +
> + 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);
> +
> switch (ring->scan_mask) {
> case (1 << 0):
> st->ring_msg = &st->msg[AD7887_CH0];
> @@ -186,20 +195,14 @@ static void ad7887_poll_bh_to_ring(struct work_struct *work_s)
> s64 time_ns;
> __u8 *buf;
> int b_sent;
> - size_t d_size;
>
> unsigned int bytes = ring->scan_count * st->chip_info->storagebits / 8;
>
> - /* Ensure the timestamp is 8 byte aligned */
> - d_size = bytes + 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;
>
> - buf = kzalloc(d_size, GFP_KERNEL);
> + buf = kzalloc(st->d_size, GFP_KERNEL);
> if (buf == NULL)
> return;
>
> @@ -210,7 +213,9 @@ static void ad7887_poll_bh_to_ring(struct work_struct *work_s)
> time_ns = iio_get_time_ns();
>
> memcpy(buf, st->data, bytes);
> - memcpy(buf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
> + if (ring->scan_timestamp)
> + memcpy(buf + st->d_size - sizeof(s64),
> + &time_ns, sizeof(time_ns));
>
> indio_dev->ring->access.store_to(&sw_ring->buf, buf, time_ns);
> done:
> @@ -241,6 +246,7 @@ int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
> indio_dev->ring->predisable = &iio_triggered_ring_predisable;
> indio_dev->ring->postdisable = &ad7887_ring_postdisable;
> indio_dev->ring->scan_el_attrs = &ad7887_scan_el_group;
> + indio_dev->ring->scan_timestamp = true;
>
> INIT_WORK(&st->poll_work, &ad7887_poll_bh_to_ring);
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] IIO: ADC: AD7606: Update timestamp handling
2011-02-24 19:09 [PATCH] IIO: ADC: AD7476: Update timestamp handling michael.hennerich
2011-02-24 19:09 ` [PATCH] IIO: ADC: AD7887: " michael.hennerich
@ 2011-02-24 19:09 ` michael.hennerich
2011-02-24 19:55 ` Jonathan Cameron
2011-02-24 19:09 ` [PATCH] IIO: ADC: AD799x: " michael.hennerich
2011-02-24 19:51 ` [PATCH] IIO: ADC: AD7476: " Jonathan Cameron
3 siblings, 1 reply; 9+ messages in thread
From: michael.hennerich @ 2011-02-24 19:09 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, drivers, device-drivers-devel, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Add timestamp attributes.
Revise timestamp handling accordingly.
Preset timestamp generation.
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad7606_ring.c | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7606_ring.c b/drivers/staging/iio/adc/ad7606_ring.c
index 9889680..b32cb0d 100644
--- a/drivers/staging/iio/adc/ad7606_ring.c
+++ b/drivers/staging/iio/adc/ad7606_ring.c
@@ -30,6 +30,9 @@ static IIO_SCAN_EL_C(in5, 5, 0, NULL);
static IIO_SCAN_EL_C(in6, 6, 0, NULL);
static IIO_SCAN_EL_C(in7, 7, 0, NULL);
+static IIO_SCAN_EL_TIMESTAMP(8);
+static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
+
static ssize_t ad7606_show_type(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -60,6 +63,9 @@ static struct attribute *ad7606_scan_el_attrs[] = {
&iio_const_attr_in6_index.dev_attr.attr,
&iio_scan_el_in7.dev_attr.attr,
&iio_const_attr_in7_index.dev_attr.attr,
+ &iio_const_attr_timestamp_index.dev_attr.attr,
+ &iio_scan_el_timestamp.dev_attr.attr,
+ &iio_const_attr_timestamp_type.dev_attr.attr,
&iio_dev_attr_in_type.dev_attr.attr,
NULL,
};
@@ -133,10 +139,14 @@ static int ad7606_ring_preenable(struct iio_dev *indio_dev)
size_t d_size;
d_size = st->chip_info->num_channels *
- st->chip_info->bits / 8 + sizeof(s64);
+ st->chip_info->bits / 8;
+
+ if (ring->scan_timestamp) {
+ d_size += sizeof(s64);
- if (d_size % sizeof(s64))
- d_size += sizeof(s64) - (d_size % sizeof(s64));
+ if (d_size % sizeof(s64))
+ d_size += sizeof(s64) - (d_size % sizeof(s64));
+ }
if (ring->access.set_bytes_per_datum)
ring->access.set_bytes_per_datum(ring, d_size);
@@ -210,7 +220,10 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
}
time_ns = iio_get_time_ns();
- memcpy(buf + st->d_size - sizeof(s64), &time_ns, sizeof(time_ns));
+
+ if (ring->scan_timestamp)
+ memcpy(buf + st->d_size - sizeof(s64),
+ &time_ns, sizeof(time_ns));
ring->access.store_to(&sw_ring->buf, buf, time_ns);
done:
@@ -242,6 +255,7 @@ int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
indio_dev->ring->postenable = &iio_triggered_ring_postenable;
indio_dev->ring->predisable = &iio_triggered_ring_predisable;
indio_dev->ring->scan_el_attrs = &ad7606_scan_el_group;
+ indio_dev->ring->scan_timestamp = true ;
INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] IIO: ADC: AD7606: Update timestamp handling
2011-02-24 19:09 ` [PATCH] IIO: ADC: AD7606: " michael.hennerich
@ 2011-02-24 19:55 ` Jonathan Cameron
0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2011-02-24 19:55 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, drivers, device-drivers-devel
On 02/24/11 19:09, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> 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>
> ---
> drivers/staging/iio/adc/ad7606_ring.c | 22 ++++++++++++++++++----
> 1 files changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7606_ring.c b/drivers/staging/iio/adc/ad7606_ring.c
> index 9889680..b32cb0d 100644
> --- a/drivers/staging/iio/adc/ad7606_ring.c
> +++ b/drivers/staging/iio/adc/ad7606_ring.c
> @@ -30,6 +30,9 @@ static IIO_SCAN_EL_C(in5, 5, 0, NULL);
> static IIO_SCAN_EL_C(in6, 6, 0, NULL);
> static IIO_SCAN_EL_C(in7, 7, 0, NULL);
>
> +static IIO_SCAN_EL_TIMESTAMP(8);
> +static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
> +
> static ssize_t ad7606_show_type(struct device *dev,
> struct device_attribute *attr,
> char *buf)
> @@ -60,6 +63,9 @@ static struct attribute *ad7606_scan_el_attrs[] = {
> &iio_const_attr_in6_index.dev_attr.attr,
> &iio_scan_el_in7.dev_attr.attr,
> &iio_const_attr_in7_index.dev_attr.attr,
> + &iio_const_attr_timestamp_index.dev_attr.attr,
> + &iio_scan_el_timestamp.dev_attr.attr,
> + &iio_const_attr_timestamp_type.dev_attr.attr,
> &iio_dev_attr_in_type.dev_attr.attr,
> NULL,
> };
> @@ -133,10 +139,14 @@ static int ad7606_ring_preenable(struct iio_dev *indio_dev)
> size_t d_size;
>
> d_size = st->chip_info->num_channels *
> - st->chip_info->bits / 8 + sizeof(s64);
> + st->chip_info->bits / 8;
> +
> + if (ring->scan_timestamp) {
> + d_size += sizeof(s64);
>
> - if (d_size % sizeof(s64))
> - d_size += sizeof(s64) - (d_size % sizeof(s64));
> + if (d_size % sizeof(s64))
> + d_size += sizeof(s64) - (d_size % sizeof(s64));
> + }
>
> if (ring->access.set_bytes_per_datum)
> ring->access.set_bytes_per_datum(ring, d_size);
> @@ -210,7 +220,10 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
> }
>
> time_ns = iio_get_time_ns();
> - memcpy(buf + st->d_size - sizeof(s64), &time_ns, sizeof(time_ns));
> +
> + if (ring->scan_timestamp)
> + memcpy(buf + st->d_size - sizeof(s64),
> + &time_ns, sizeof(time_ns));
>
> ring->access.store_to(&sw_ring->buf, buf, time_ns);
> done:
> @@ -242,6 +255,7 @@ int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
> indio_dev->ring->postenable = &iio_triggered_ring_postenable;
> indio_dev->ring->predisable = &iio_triggered_ring_predisable;
> indio_dev->ring->scan_el_attrs = &ad7606_scan_el_group;
> + indio_dev->ring->scan_timestamp = true ;
>
> INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring);
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] IIO: ADC: AD799x: Update timestamp handling
2011-02-24 19:09 [PATCH] IIO: ADC: AD7476: Update timestamp handling michael.hennerich
2011-02-24 19:09 ` [PATCH] IIO: ADC: AD7887: " michael.hennerich
2011-02-24 19:09 ` [PATCH] IIO: ADC: AD7606: " michael.hennerich
@ 2011-02-24 19:09 ` michael.hennerich
2011-02-24 19:55 ` Jonathan Cameron
2011-02-24 19:51 ` [PATCH] IIO: ADC: AD7476: " Jonathan Cameron
3 siblings, 1 reply; 9+ messages in thread
From: michael.hennerich @ 2011-02-24 19:09 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, drivers, device-drivers-devel, Michael Hennerich
From: Michael Hennerich <michael.hennerich@analog.com>
Add timestamp attributes.
Revise timestamp handling accordingly.
Preset timestamp generation.
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
---
drivers/staging/iio/adc/ad799x.h | 1 +
drivers/staging/iio/adc/ad799x_core.c | 12 +++++++++
drivers/staging/iio/adc/ad799x_ring.c | 43 ++++++++++++--------------------
3 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
index 81a20d5..a421362 100644
--- a/drivers/staging/iio/adc/ad799x.h
+++ b/drivers/staging/iio/adc/ad799x.h
@@ -116,6 +116,7 @@ struct ad799x_state {
struct work_struct poll_work;
struct work_struct work_thresh;
atomic_t protect_ring;
+ size_t d_size;
struct iio_trigger *trig;
struct regulator *reg;
s64 last_timestamp;
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index 89ccf37..e50841b 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -123,6 +123,9 @@ static AD799X_SCAN_EL(5);
static AD799X_SCAN_EL(6);
static AD799X_SCAN_EL(7);
+static IIO_SCAN_EL_TIMESTAMP(8);
+static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64)
+
static ssize_t ad799x_show_type(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -471,6 +474,9 @@ static struct attribute *ad7991_5_9_3_4_scan_el_attrs[] = {
&iio_const_attr_in2_index.dev_attr.attr,
&iio_scan_el_in3.dev_attr.attr,
&iio_const_attr_in3_index.dev_attr.attr,
+ &iio_const_attr_timestamp_index.dev_attr.attr,
+ &iio_scan_el_timestamp.dev_attr.attr,
+ &iio_const_attr_timestamp_type.dev_attr.attr,
&iio_dev_attr_in_type.dev_attr.attr,
NULL,
};
@@ -497,6 +503,9 @@ static struct attribute *ad7992_scan_el_attrs[] = {
&iio_const_attr_in0_index.dev_attr.attr,
&iio_scan_el_in1.dev_attr.attr,
&iio_const_attr_in1_index.dev_attr.attr,
+ &iio_const_attr_timestamp_index.dev_attr.attr,
+ &iio_scan_el_timestamp.dev_attr.attr,
+ &iio_const_attr_timestamp_type.dev_attr.attr,
&iio_dev_attr_in_type.dev_attr.attr,
NULL,
};
@@ -541,6 +550,9 @@ static struct attribute *ad7997_8_scan_el_attrs[] = {
&iio_const_attr_in6_index.dev_attr.attr,
&iio_scan_el_in7.dev_attr.attr,
&iio_const_attr_in7_index.dev_attr.attr,
+ &iio_const_attr_timestamp_index.dev_attr.attr,
+ &iio_scan_el_timestamp.dev_attr.attr,
+ &iio_const_attr_timestamp_type.dev_attr.attr,
&iio_dev_attr_in_type.dev_attr.attr,
NULL,
};
diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c
index 975cdcb..56abc39 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);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] IIO: ADC: AD799x: Update timestamp handling
2011-02-24 19:09 ` [PATCH] IIO: ADC: AD799x: " michael.hennerich
@ 2011-02-24 19:55 ` Jonathan Cameron
2011-02-24 20:31 ` Hennerich, Michael
0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2011-02-24 19:55 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, drivers, device-drivers-devel
On 02/24/11 19:09, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> 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>
Thanks for doing these so fast.
> ---
> drivers/staging/iio/adc/ad799x.h | 1 +
> drivers/staging/iio/adc/ad799x_core.c | 12 +++++++++
> drivers/staging/iio/adc/ad799x_ring.c | 43 ++++++++++++--------------------
> 3 files changed, 29 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
> index 81a20d5..a421362 100644
> --- a/drivers/staging/iio/adc/ad799x.h
> +++ b/drivers/staging/iio/adc/ad799x.h
> @@ -116,6 +116,7 @@ struct ad799x_state {
> struct work_struct poll_work;
> struct work_struct work_thresh;
> atomic_t protect_ring;
> + size_t d_size;
> struct iio_trigger *trig;
> struct regulator *reg;
> s64 last_timestamp;
> diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
> index 89ccf37..e50841b 100644
> --- a/drivers/staging/iio/adc/ad799x_core.c
> +++ b/drivers/staging/iio/adc/ad799x_core.c
> @@ -123,6 +123,9 @@ static AD799X_SCAN_EL(5);
> static AD799X_SCAN_EL(6);
> static AD799X_SCAN_EL(7);
>
> +static IIO_SCAN_EL_TIMESTAMP(8);
> +static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64)
> +
> static ssize_t ad799x_show_type(struct device *dev,
> struct device_attribute *attr,
> char *buf)
> @@ -471,6 +474,9 @@ static struct attribute *ad7991_5_9_3_4_scan_el_attrs[] = {
> &iio_const_attr_in2_index.dev_attr.attr,
> &iio_scan_el_in3.dev_attr.attr,
> &iio_const_attr_in3_index.dev_attr.attr,
> + &iio_const_attr_timestamp_index.dev_attr.attr,
> + &iio_scan_el_timestamp.dev_attr.attr,
> + &iio_const_attr_timestamp_type.dev_attr.attr,
> &iio_dev_attr_in_type.dev_attr.attr,
> NULL,
> };
> @@ -497,6 +503,9 @@ static struct attribute *ad7992_scan_el_attrs[] = {
> &iio_const_attr_in0_index.dev_attr.attr,
> &iio_scan_el_in1.dev_attr.attr,
> &iio_const_attr_in1_index.dev_attr.attr,
> + &iio_const_attr_timestamp_index.dev_attr.attr,
> + &iio_scan_el_timestamp.dev_attr.attr,
> + &iio_const_attr_timestamp_type.dev_attr.attr,
> &iio_dev_attr_in_type.dev_attr.attr,
> NULL,
> };
> @@ -541,6 +550,9 @@ static struct attribute *ad7997_8_scan_el_attrs[] = {
> &iio_const_attr_in6_index.dev_attr.attr,
> &iio_scan_el_in7.dev_attr.attr,
> &iio_const_attr_in7_index.dev_attr.attr,
> + &iio_const_attr_timestamp_index.dev_attr.attr,
> + &iio_scan_el_timestamp.dev_attr.attr,
> + &iio_const_attr_timestamp_type.dev_attr.attr,
> &iio_dev_attr_in_type.dev_attr.attr,
> NULL,
> };
> diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c
> index 975cdcb..56abc39 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);
>
^ permalink raw reply [flat|nested] 9+ messages in thread* RE: [PATCH] IIO: ADC: AD799x: Update timestamp handling
2011-02-24 19:55 ` Jonathan Cameron
@ 2011-02-24 20:31 ` Hennerich, Michael
0 siblings, 0 replies; 9+ messages in thread
From: Hennerich, Michael @ 2011-02-24 20:31 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio@vger.kernel.org, Drivers,
device-drivers-devel@blackfin.uclinux.org
Jonathan Cameron wrote on 2011-02-24:
> On 02/24/11 19:09, michael.hennerich@analog.com wrote:
>> From: Michael Hennerich <michael.hennerich@analog.com>
>>
>> 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>
>
> Thanks for doing these so fast.
My todo list is constantly growing, while I have to prioritize.
Time to get things pushed out without deferring.
Greetings,
Michael
--
Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen
Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368; Gesch=
aeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret=
Seif
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] IIO: ADC: AD7476: Update timestamp handling
2011-02-24 19:09 [PATCH] IIO: ADC: AD7476: Update timestamp handling michael.hennerich
` (2 preceding siblings ...)
2011-02-24 19:09 ` [PATCH] IIO: ADC: AD799x: " michael.hennerich
@ 2011-02-24 19:51 ` Jonathan Cameron
3 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2011-02-24 19:51 UTC (permalink / raw)
To: michael.hennerich; +Cc: linux-iio, drivers, device-drivers-devel
On 02/24/11 19:09, michael.hennerich@analog.com wrote:
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> Add timestamp attributes.
> Revise timestamp handling accordingly.
> Preset timestamp generation.
As an aside:
An alternative would be to define an always on version of IIO_SCAN_EL_TIMESTAMP.
That would lead to smaller changes. This way means we can turn it off though, which
on simple devices like this one means a big saving in 'ring_buffer' usage.
Patch is good, thanks. Technically this fixes a bug (by conforming to the abi)
as you pointed out the other day so could go to stable. Up to you...
>
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
> drivers/staging/iio/adc/ad7476.h | 1 +
> drivers/staging/iio/adc/ad7476_ring.c | 37 +++++++++++++++++++-------------
> 2 files changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7476.h b/drivers/staging/iio/adc/ad7476.h
> index b51b49e..f917e9c 100644
> --- a/drivers/staging/iio/adc/ad7476.h
> +++ b/drivers/staging/iio/adc/ad7476.h
> @@ -33,6 +33,7 @@ struct ad7476_state {
> struct regulator *reg;
> struct work_struct poll_work;
> atomic_t protect_ring;
> + size_t d_size;
> u16 int_vref_mv;
> struct spi_transfer xfer;
> struct spi_message msg;
> diff --git a/drivers/staging/iio/adc/ad7476_ring.c b/drivers/staging/iio/adc/ad7476_ring.c
> index 85de142..1d654c8 100644
> --- a/drivers/staging/iio/adc/ad7476_ring.c
> +++ b/drivers/staging/iio/adc/ad7476_ring.c
> @@ -26,6 +26,8 @@
> #include "ad7476.h"
>
> static IIO_SCAN_EL_C(in0, 0, 0, NULL);
> +static IIO_SCAN_EL_TIMESTAMP(1);
> +static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
>
> static ssize_t ad7476_show_type(struct device *dev,
> struct device_attribute *attr,
> @@ -44,6 +46,9 @@ static IIO_DEVICE_ATTR(in_type, S_IRUGO, ad7476_show_type, NULL, 0);
> static struct attribute *ad7476_scan_el_attrs[] = {
> &iio_scan_el_in0.dev_attr.attr,
> &iio_const_attr_in0_index.dev_attr.attr,
> + &iio_const_attr_timestamp_index.dev_attr.attr,
> + &iio_scan_el_timestamp.dev_attr.attr,
> + &iio_const_attr_timestamp_type.dev_attr.attr,
> &iio_dev_attr_in_type.dev_attr.attr,
> NULL,
> };
> @@ -86,16 +91,21 @@ error_ret:
> static int ad7476_ring_preenable(struct iio_dev *indio_dev)
> {
> struct ad7476_state *st = indio_dev->dev_data;
> - size_t d_size;
> + struct iio_ring_buffer *ring = indio_dev->ring;
>
> - if (indio_dev->ring->access.set_bytes_per_datum) {
> - d_size = st->chip_info->storagebits / 8 + sizeof(s64);
> - if (d_size % 8)
> - d_size += 8 - (d_size % 8);
> - indio_dev->ring->access.set_bytes_per_datum(indio_dev->ring,
> - d_size);
> + st->d_size = ring->scan_count * st->chip_info->storagebits / 8;
> +
> + 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;
> }
>
> @@ -131,18 +141,12 @@ static void ad7476_poll_bh_to_ring(struct work_struct *work_s)
> s64 time_ns;
> __u8 *rxbuf;
> int b_sent;
> - size_t d_size;
> -
> - /* Ensure the timestamp is 8 byte aligned */
> - d_size = st->chip_info->storagebits / 8 + 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;
>
> - rxbuf = kzalloc(d_size, GFP_KERNEL);
> + rxbuf = kzalloc(st->d_size, GFP_KERNEL);
> if (rxbuf == NULL)
> return;
>
> @@ -152,7 +156,9 @@ static void ad7476_poll_bh_to_ring(struct work_struct *work_s)
>
> time_ns = iio_get_time_ns();
>
> - memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
> + if (indio_dev->ring->scan_timestamp)
> + memcpy(rxbuf + st->d_size - sizeof(s64),
> + &time_ns, sizeof(time_ns));
>
> indio_dev->ring->access.store_to(&sw_ring->buf, rxbuf, time_ns);
> done:
> @@ -182,6 +188,7 @@ int ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev)
> indio_dev->ring->postenable = &iio_triggered_ring_postenable;
> indio_dev->ring->predisable = &iio_triggered_ring_predisable;
> indio_dev->ring->scan_el_attrs = &ad7476_scan_el_group;
> + indio_dev->ring->scan_timestamp = true;
>
> INIT_WORK(&st->poll_work, &ad7476_poll_bh_to_ring);
>
^ permalink raw reply [flat|nested] 9+ messages in thread