Skip to contentSkip to conversation

iio: Add iio_push_buffers_with_timestamp() helper

PATCH Applied Lars-Peter Clausen 2 participants 48 messages Sep 19, 2013 – Sep 21, 2013

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

PATCH 1/24 iio: Add iio_push_buffers_with_timestamp() helper

Drivers using software buffers often store the timestamp in their data buffer before calling iio_push_to_buffers() with that data buffer. Storing the timestamp in the buffer usually involves some ugly pointer arithmetic. This patch adds a new helper function called iio_push_buffers_with_timestamp() which is similar to iio_push_to_buffers but takes an additional timestamp parameter. The function will help to hide to uglyness in one central place instead of exposing it in every driver. If timestamps are enabled for the IIO device iio_push_buffers_with_timestamp() will store the timestamp as the last element in buffer, before passing the buffer on to iio_push_buffers(). The buffer needs large enough to hold the timestamp in this case. If timestamps are disabled iio_push_buffers_with_timestamp() will behave just like iio_push_buffers().

Cc Oleksandr Kravchenko <[email protected]>
Cc Josh Wu <[email protected]>
Cc Denis Ciocca <[email protected]>
Cc Manuel Stahl <[email protected]>
Cc Ge Gao <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Marek Vasut <[email protected]>
---
 include/linux/iio/buffer.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
include/linux/iio/buffer.h +25 -0
index e5507e9..a1124bd 100644
@@ -122,6 +122,31 @@ int iio_scan_mask_set(struct iio_dev *indio_dev,
  */
 int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data);
 
+/*
+ * iio_push_to_buffers_with_timestamp() - push data and timestamp to buffers
+ * @indio_dev:		iio_dev structure for device.
+ * @data:		sample data
+ * @timestamp:		timestamp for the sample data
+ *
+ * Pushes data to the IIO device's buffers. If timestamps are enabled for the
+ * device the function will store the supplied timestamp as the last element in
+ * the sample data buffer before pushing it to the device buffers. The sample
+ * data buffer needs to be large enough to hold the additional timestamp
+ * (usually the buffer should be indio->scan_bytes bytes large).
+ *
+ * Returns 0 on success, a negative error code otherwise.
+ */
+static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev,
+	void *data, int64_t timestamp)
+{
+	if (indio_dev->scan_timestamp) {
+		size_t ts_offset = indio_dev->scan_bytes / sizeof(int64_t) - 1;
+		((int64_t *)data)[ts_offset] = timestamp;
+	}
+
+	return iio_push_to_buffers(indio_dev, data);
+}
+
 int iio_update_demux(struct iio_dev *indio_dev);
 
 /**
Signature · 1 line
1.8.0
#1 lore raw

PATCH 2/24 iio:bma180: Use iio_push_buffers_with_timestamp()

Makes the code shorter and a bit less ugly.

Cc Oleksandr Kravchenko <[email protected]>
---
 drivers/iio/accel/bma180.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/accel/bma180.c +2 -5
index 3eff246..bda7a83 100644
@@ -471,13 +471,10 @@ static irqreturn_t bma180_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct bma180_data *data = iio_priv(indio_dev);
+	int64_t time_ns = iio_get_time_ns();
 	int bit, ret, i = 0;
 
 	mutex_lock(&data->mutex);
-	if (indio_dev->scan_timestamp) {
-		ret = indio_dev->scan_bytes / sizeof(s64) - 1;
-		((s64 *)data->buff)[ret] = iio_get_time_ns();
-	}
 
 	for_each_set_bit(bit, indio_dev->buffer->scan_mask,
 			 indio_dev->masklength) {
@@ -490,7 +487,7 @@ static irqreturn_t bma180_trigger_handler(int irq, void *p)
 	}
 	mutex_unlock(&data->mutex);
 
-	iio_push_to_buffers(indio_dev, data->buff);
+	iio_push_to_buffers_with_timestamp(indio_dev, data->buff, time_ns);
 err:
 	iio_trigger_notify_done(indio_dev->trig);
 
Signature · 1 line
1.8.0
maintainer Applied
#2 lore raw

Re: [PATCH 02/24] iio:bma180: Use iio_push_buffers_with_timestamp()

Quoted 4 lines · Lars-Peter Clausen

Makes the code shorter and a bit less ugly.

Cc Oleksandr Kravchenko <[email protected]>

Applied to the togreg branch of iio.git

Quoted 33 lines
---
 drivers/iio/accel/bma180.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/accel/bma180.c +2 -5
index 3eff246..bda7a83 100644
@@ -471,13 +471,10 @@ static irqreturn_t bma180_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct bma180_data *data = iio_priv(indio_dev);
+	int64_t time_ns = iio_get_time_ns();
 	int bit, ret, i = 0;
 
 	mutex_lock(&data->mutex);
-	if (indio_dev->scan_timestamp) {
-		ret = indio_dev->scan_bytes / sizeof(s64) - 1;
-		((s64 *)data->buff)[ret] = iio_get_time_ns();
-	}
 
 	for_each_set_bit(bit, indio_dev->buffer->scan_mask,
 			 indio_dev->masklength) {
@@ -490,7 +487,7 @@ static irqreturn_t bma180_trigger_handler(int irq, void *p)
 	}
 	mutex_unlock(&data->mutex);
 
-	iio_push_to_buffers(indio_dev, data->buff);
+	iio_push_to_buffers_with_timestamp(indio_dev, data->buff, time_ns);
 err:
 	iio_trigger_notify_done(indio_dev->trig);
 
#3 lore raw

PATCH 3/24 iio:ad7266: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/adc/ad7266.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/adc/ad7266.c +2 -3
index c304966..656aa3e 100644
@@ -96,9 +96,8 @@ static irqreturn_t ad7266_trigger_handler(int irq, void *p)
 
 	ret = spi_read(st->spi, st->data, 4);
 	if (ret == 0) {
-		if (indio_dev->scan_timestamp)
-			((s64 *)st->data)[1] = pf->timestamp;
-		iio_push_to_buffers(indio_dev, st->data);
+		iio_push_to_buffers_with_timestamp(indio_dev, st->data,
+			    pf->timestamp);
 	}
 
 	iio_trigger_notify_done(indio_dev->trig);
Signature · 1 line
1.8.0
maintainer Applied
#4 lore raw

Re: [PATCH 03/24] iio:ad7266: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 21 lines
---
 drivers/iio/adc/ad7266.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/adc/ad7266.c +2 -3
index c304966..656aa3e 100644
@@ -96,9 +96,8 @@ static irqreturn_t ad7266_trigger_handler(int irq, void *p)
 
 	ret = spi_read(st->spi, st->data, 4);
 	if (ret == 0) {
-		if (indio_dev->scan_timestamp)
-			((s64 *)st->data)[1] = pf->timestamp;
-		iio_push_to_buffers(indio_dev, st->data);
+		iio_push_to_buffers_with_timestamp(indio_dev, st->data,
+			    pf->timestamp);
 	}
 
 	iio_trigger_notify_done(indio_dev->trig);
#5 lore raw

PATCH 4/24 iio:ad7298: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/adc/ad7298.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7298.c +2 -8
index 0812556..2a3b65c 100644
@@ -159,20 +159,14 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7298_state *st = iio_priv(indio_dev);
-	s64 time_ns = 0;
 	int b_sent;
 
 	b_sent = spi_sync(st->spi, &st->ring_msg);
 	if (b_sent)
 		goto done;
 
-	if (indio_dev->scan_timestamp) {
-		time_ns = iio_get_time_ns();
-		memcpy((u8 *)st->rx_buf + indio_dev->scan_bytes - sizeof(s64),
-			&time_ns, sizeof(time_ns));
-	}
-
-	iio_push_to_buffers(indio_dev, st->rx_buf);
+	iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
+		iio_get_time_ns());
 
 done:
 	iio_trigger_notify_done(indio_dev->trig);
Signature · 1 line
1.8.0
maintainer Applied
#6 lore raw

Re: [PATCH 04/24] iio:ad7298: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 32 lines
---
 drivers/iio/adc/ad7298.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7298.c +2 -8
index 0812556..2a3b65c 100644
@@ -159,20 +159,14 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7298_state *st = iio_priv(indio_dev);
-	s64 time_ns = 0;
 	int b_sent;
 
 	b_sent = spi_sync(st->spi, &st->ring_msg);
 	if (b_sent)
 		goto done;
 
-	if (indio_dev->scan_timestamp) {
-		time_ns = iio_get_time_ns();
-		memcpy((u8 *)st->rx_buf + indio_dev->scan_bytes - sizeof(s64),
-			&time_ns, sizeof(time_ns));
-	}
-
-	iio_push_to_buffers(indio_dev, st->rx_buf);
+	iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
+		iio_get_time_ns());
 
 done:
 	iio_trigger_notify_done(indio_dev->trig);
#7 lore raw

PATCH 5/24 iio:ad7476: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/adc/ad7476.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/iio/adc/ad7476.c +2 -7
index 6d2b1d8..8d808b9 100644
@@ -64,19 +64,14 @@ static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7476_state *st = iio_priv(indio_dev);
-	s64 time_ns;
 	int b_sent;
 
 	b_sent = spi_sync(st->spi, &st->msg);
 	if (b_sent < 0)
 		goto done;
 
-	time_ns = iio_get_time_ns();
-
-	if (indio_dev->scan_timestamp)
-		((s64 *)st->data)[1] = time_ns;
-
-	iio_push_to_buffers(indio_dev, st->data);
+	iio_push_to_buffers_with_timestamp(indio_dev, st->data,
+		iio_get_time_ns());
 done:
 	iio_trigger_notify_done(indio_dev->trig);
 
Signature · 1 line
1.8.0
maintainer Applied
#8 lore raw

Re: [PATCH 05/24] iio:ad7476: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 31 lines
---
 drivers/iio/adc/ad7476.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/iio/adc/ad7476.c +2 -7
index 6d2b1d8..8d808b9 100644
@@ -64,19 +64,14 @@ static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7476_state *st = iio_priv(indio_dev);
-	s64 time_ns;
 	int b_sent;
 
 	b_sent = spi_sync(st->spi, &st->msg);
 	if (b_sent < 0)
 		goto done;
 
-	time_ns = iio_get_time_ns();
-
-	if (indio_dev->scan_timestamp)
-		((s64 *)st->data)[1] = time_ns;
-
-	iio_push_to_buffers(indio_dev, st->data);
+	iio_push_to_buffers_with_timestamp(indio_dev, st->data,
+		iio_get_time_ns());
 done:
 	iio_trigger_notify_done(indio_dev->trig);
 
#9 lore raw

PATCH 6/24 iio:ad7887: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/adc/ad7887.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7887.c +2 -8
index 9dd077b..faedd0e 100644
@@ -121,20 +121,14 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7887_state *st = iio_priv(indio_dev);
-	s64 time_ns;
 	int b_sent;
 
 	b_sent = spi_sync(st->spi, st->ring_msg);
 	if (b_sent)
 		goto done;
 
-	time_ns = iio_get_time_ns();
-
-	if (indio_dev->scan_timestamp)
-		memcpy(st->data + indio_dev->scan_bytes - sizeof(s64),
-		       &time_ns, sizeof(time_ns));
-
-	iio_push_to_buffers(indio_dev, st->data);
+	iio_push_to_buffers_with_timestamp(indio_dev, st->data,
+		iio_get_time_ns());
 done:
 	iio_trigger_notify_done(indio_dev->trig);
 
Signature · 1 line
1.8.0
maintainer Applied
#10 lore raw

Re: [PATCH 06/24] iio:ad7887: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 32 lines
---
 drivers/iio/adc/ad7887.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7887.c +2 -8
index 9dd077b..faedd0e 100644
@@ -121,20 +121,14 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7887_state *st = iio_priv(indio_dev);
-	s64 time_ns;
 	int b_sent;
 
 	b_sent = spi_sync(st->spi, st->ring_msg);
 	if (b_sent)
 		goto done;
 
-	time_ns = iio_get_time_ns();
-
-	if (indio_dev->scan_timestamp)
-		memcpy(st->data + indio_dev->scan_bytes - sizeof(s64),
-		       &time_ns, sizeof(time_ns));
-
-	iio_push_to_buffers(indio_dev, st->data);
+	iio_push_to_buffers_with_timestamp(indio_dev, st->data,
+		iio_get_time_ns());
 done:
 	iio_trigger_notify_done(indio_dev->trig);
 
#11 lore raw

PATCH 7/24 iio:ad7923: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/adc/ad7923.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7923.c +2 -8
index 7eb4cb5..28732c2 100644
@@ -174,20 +174,14 @@ static irqreturn_t ad7923_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7923_state *st = iio_priv(indio_dev);
-	s64 time_ns = 0;
 	int b_sent;
 
 	b_sent = spi_sync(st->spi, &st->ring_msg);
 	if (b_sent)
 		goto done;
 
-	if (indio_dev->scan_timestamp) {
-		time_ns = iio_get_time_ns();
-		memcpy((u8 *)st->rx_buf + indio_dev->scan_bytes - sizeof(s64),
-			&time_ns, sizeof(time_ns));
-	}
-
-	iio_push_to_buffers(indio_dev, st->rx_buf);
+	iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
+		iio_get_time_ns());
 
 done:
 	iio_trigger_notify_done(indio_dev->trig);
Signature · 1 line
1.8.0
maintainer Applied
#12 lore raw

Re: [PATCH 07/24] iio:ad7923: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 32 lines
---
 drivers/iio/adc/ad7923.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7923.c +2 -8
index 7eb4cb5..28732c2 100644
@@ -174,20 +174,14 @@ static irqreturn_t ad7923_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7923_state *st = iio_priv(indio_dev);
-	s64 time_ns = 0;
 	int b_sent;
 
 	b_sent = spi_sync(st->spi, &st->ring_msg);
 	if (b_sent)
 		goto done;
 
-	if (indio_dev->scan_timestamp) {
-		time_ns = iio_get_time_ns();
-		memcpy((u8 *)st->rx_buf + indio_dev->scan_bytes - sizeof(s64),
-			&time_ns, sizeof(time_ns));
-	}
-
-	iio_push_to_buffers(indio_dev, st->rx_buf);
+	iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
+		iio_get_time_ns());
 
 done:
 	iio_trigger_notify_done(indio_dev->trig);
#13 lore raw

PATCH 8/24 iio:ad_sigma_delta: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/adc/ad_sigma_delta.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/iio/adc/ad_sigma_delta.c +1 -5
index 78d276f..2b59112 100644
@@ -368,10 +368,6 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 
 	memset(data, 0x00, 16);
 
-	/* Guaranteed to be aligned with 8 byte boundary */
-	if (indio_dev->scan_timestamp)
-		((s64 *)data)[1] = pf->timestamp;
-
 	reg_size = indio_dev->channels[0].scan_type.realbits +
 			indio_dev->channels[0].scan_type.shift;
 	reg_size = DIV_ROUND_UP(reg_size, 8);
@@ -391,7 +387,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 		break;
 	}
 
-	iio_push_to_buffers(indio_dev, data);
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp);
 
 	iio_trigger_notify_done(indio_dev->trig);
 	sigma_delta->irq_dis = false;
Signature · 1 line
1.8.0
maintainer Applied
#14 lore raw

Re: [PATCH 08/24] iio:ad_sigma_delta: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 29 lines
---
 drivers/iio/adc/ad_sigma_delta.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/iio/adc/ad_sigma_delta.c +1 -5
index 78d276f..2b59112 100644
@@ -368,10 +368,6 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 
 	memset(data, 0x00, 16);
 
-	/* Guaranteed to be aligned with 8 byte boundary */
-	if (indio_dev->scan_timestamp)
-		((s64 *)data)[1] = pf->timestamp;
-
 	reg_size = indio_dev->channels[0].scan_type.realbits +
 			indio_dev->channels[0].scan_type.shift;
 	reg_size = DIV_ROUND_UP(reg_size, 8);
@@ -391,7 +387,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 		break;
 	}
 
-	iio_push_to_buffers(indio_dev, data);
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp);
 
 	iio_trigger_notify_done(indio_dev->trig);
 	sigma_delta->irq_dis = false;
#15 lore raw

PATCH 9/24 iio:at91_adc: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/adc/at91_adc.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/iio/adc/at91_adc.c +1 -7
index 6da5ebb..ee5f51ca 100644
@@ -83,13 +83,7 @@ static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
 		j++;
 	}
 
-	if (idev->scan_timestamp) {
-		s64 *timestamp = (s64 *)((u8 *)st->buffer +
-					ALIGN(j, sizeof(s64)));
-		*timestamp = pf->timestamp;
-	}
-
-	iio_push_to_buffers(idev, st->buffer);
+	iio_push_to_buffers_with_timestamp(idev, st->buffer, pf->timestamp);
 
 	iio_trigger_notify_done(idev->trig);
 
Signature · 1 line
1.8.0
maintainer Applied
#16 lore raw

Re: [PATCH 09/24] iio:at91_adc: Use iio_push_to_buffers_with_timestamp()

Quoted 4 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 24 lines
---
 drivers/iio/adc/at91_adc.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/iio/adc/at91_adc.c +1 -7
index 6da5ebb..ee5f51ca 100644
@@ -83,13 +83,7 @@ static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
 		j++;
 	}
 
-	if (idev->scan_timestamp) {
-		s64 *timestamp = (s64 *)((u8 *)st->buffer +
-					ALIGN(j, sizeof(s64)));
-		*timestamp = pf->timestamp;
-	}
-
-	iio_push_to_buffers(idev, st->buffer);
+	iio_push_to_buffers_with_timestamp(idev, st->buffer, pf->timestamp);
 
 	iio_trigger_notify_done(idev->trig);
 
#17 lore raw

PATCH 10/24 iio:max1363: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/adc/max1363.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/iio/adc/max1363.c +1 -6
index 1e7160d..b4bc166 100644
@@ -1436,7 +1436,6 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct max1363_state *st = iio_priv(indio_dev);
-	s64 time_ns;
 	__u8 *rxbuf;
 	int b_sent;
 	size_t d_size;
@@ -1470,11 +1469,7 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p)
 	if (b_sent < 0)
 		goto done_free;
 
-	time_ns = iio_get_time_ns();
-
-	if (indio_dev->scan_timestamp)
-		memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
-	iio_push_to_buffers(indio_dev, rxbuf);
+	iio_push_to_buffers_with_timestamp(indio_dev, rxbuf, iio_get_time_ns());
 
 done_free:
 	kfree(rxbuf);
Signature · 1 line
1.8.0
maintainer Applied
#18 lore raw

Re: [PATCH 10/24] iio:max1363: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 30 lines
---
 drivers/iio/adc/max1363.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/iio/adc/max1363.c +1 -6
index 1e7160d..b4bc166 100644
@@ -1436,7 +1436,6 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct max1363_state *st = iio_priv(indio_dev);
-	s64 time_ns;
 	__u8 *rxbuf;
 	int b_sent;
 	size_t d_size;
@@ -1470,11 +1469,7 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p)
 	if (b_sent < 0)
 		goto done_free;
 
-	time_ns = iio_get_time_ns();
-
-	if (indio_dev->scan_timestamp)
-		memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
-	iio_push_to_buffers(indio_dev, rxbuf);
+	iio_push_to_buffers_with_timestamp(indio_dev, rxbuf, iio_get_time_ns());
 
 done_free:
 	kfree(rxbuf);
#19 lore raw

PATCH 11/24 iio:st_sensors: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/common/st_sensors/st_sensors_buffer.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/common/st_sensors/st_sensors_buffer.c +2 -5
index 71a2c5f..1665c8e 100644
@@ -113,11 +113,8 @@ irqreturn_t st_sensors_trigger_handler(int irq, void *p)
 	if (len < 0)
 		goto st_sensors_get_buffer_element_error;
 
-	if (indio_dev->scan_timestamp)
-		*(s64 *)((u8 *)sdata->buffer_data +
-				ALIGN(len, sizeof(s64))) = pf->timestamp;
-
-	iio_push_to_buffers(indio_dev, sdata->buffer_data);
+	iio_push_to_buffers_with_timestamp(indio_dev, sdata->buffer_data,
+		pf->timestamp);
 
 st_sensors_get_buffer_element_error:
 	iio_trigger_notify_done(indio_dev->trig);
Signature · 1 line
1.8.0
maintainer Applied
#20 lore raw

Re: [PATCH 11/24] iio:st_sensors: Use iio_push_to_buffers_with_timestamp()

Quoted 4 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 23 lines
---
 drivers/iio/common/st_sensors/st_sensors_buffer.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iio/common/st_sensors/st_sensors_buffer.c +2 -5
index 71a2c5f..1665c8e 100644
@@ -113,11 +113,8 @@ irqreturn_t st_sensors_trigger_handler(int irq, void *p)
 	if (len < 0)
 		goto st_sensors_get_buffer_element_error;
 
-	if (indio_dev->scan_timestamp)
-		*(s64 *)((u8 *)sdata->buffer_data +
-				ALIGN(len, sizeof(s64))) = pf->timestamp;
-
-	iio_push_to_buffers(indio_dev, sdata->buffer_data);
+	iio_push_to_buffers_with_timestamp(indio_dev, sdata->buffer_data,
+		pf->timestamp);
 
 st_sensors_get_buffer_element_error:
 	iio_trigger_notify_done(indio_dev->trig);
#21 lore raw

PATCH 12/24 iio:itg3200: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/gyro/itg3200_buffer.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/iio/gyro/itg3200_buffer.c +1 -4
index 6b3c301..e3b3c50 100644
@@ -55,11 +55,8 @@ static irqreturn_t itg3200_trigger_handler(int irq, void *p)
 	if (ret < 0)
 		goto error_ret;
 
-	if (indio_dev->scan_timestamp)
-		memcpy(buf + indio_dev->scan_bytes - sizeof(s64),
-				&pf->timestamp, sizeof(pf->timestamp));
+	iio_push_to_buffers_with_timestamp(indio_dev, buf, pf->timestamp);
 
-	iio_push_to_buffers(indio_dev, buf);
 	iio_trigger_notify_done(indio_dev->trig);
 
 error_ret:
Signature · 1 line
1.8.0
maintainer Applied
#22 lore raw

Re: [PATCH 12/24] iio:itg3200: Use iio_push_to_buffers_with_timestamp()

Quoted 4 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 22 lines
---
 drivers/iio/gyro/itg3200_buffer.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/iio/gyro/itg3200_buffer.c +1 -4
index 6b3c301..e3b3c50 100644
@@ -55,11 +55,8 @@ static irqreturn_t itg3200_trigger_handler(int irq, void *p)
 	if (ret < 0)
 		goto error_ret;
 
-	if (indio_dev->scan_timestamp)
-		memcpy(buf + indio_dev->scan_bytes - sizeof(s64),
-				&pf->timestamp, sizeof(pf->timestamp));
+	iio_push_to_buffers_with_timestamp(indio_dev, buf, pf->timestamp);
 
-	iio_push_to_buffers(indio_dev, buf);
 	iio_trigger_notify_done(indio_dev->trig);
 
 error_ret:
#23 lore raw

PATCH 13/24 iio:adis16400: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/imu/adis16400_buffer.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/iio/imu/adis16400_buffer.c +2 -7
index 054c01d..f2cf829 100644
@@ -82,13 +82,8 @@ irqreturn_t adis16400_trigger_handler(int irq, void *p)
 		spi_setup(st->adis.spi);
 	}
 
-	/* Guaranteed to be aligned with 8 byte boundary */
-	if (indio_dev->scan_timestamp) {
-		void *b = adis->buffer + indio_dev->scan_bytes - sizeof(s64);
-		*(s64 *)b = pf->timestamp;
-	}
-
-	iio_push_to_buffers(indio_dev, adis->buffer);
+	iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
+		pf->timestamp);
 
 	iio_trigger_notify_done(indio_dev->trig);
 
Signature · 1 line
1.8.0
maintainer Applied
#24 lore raw

Re: [PATCH 13/24] iio:adis16400: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 25 lines
---
 drivers/iio/imu/adis16400_buffer.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/iio/imu/adis16400_buffer.c +2 -7
index 054c01d..f2cf829 100644
@@ -82,13 +82,8 @@ irqreturn_t adis16400_trigger_handler(int irq, void *p)
 		spi_setup(st->adis.spi);
 	}
 
-	/* Guaranteed to be aligned with 8 byte boundary */
-	if (indio_dev->scan_timestamp) {
-		void *b = adis->buffer + indio_dev->scan_bytes - sizeof(s64);
-		*(s64 *)b = pf->timestamp;
-	}
-
-	iio_push_to_buffers(indio_dev, adis->buffer);
+	iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
+		pf->timestamp);
 
 	iio_trigger_notify_done(indio_dev->trig);
 
#25 lore raw

PATCH 14/24 iio:adis_lib: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/imu/adis_buffer.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/iio/imu/adis_buffer.c +2 -7
index 99d8e0b..cb32b59 100644
@@ -102,13 +102,8 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
 		mutex_unlock(&adis->txrx_lock);
 	}
 
-	/* Guaranteed to be aligned with 8 byte boundary */
-	if (indio_dev->scan_timestamp) {
-		void *b = adis->buffer + indio_dev->scan_bytes - sizeof(s64);
-		*(s64 *)b = pf->timestamp;
-	}
-
-	iio_push_to_buffers(indio_dev, adis->buffer);
+	iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
+		pf->timestamp);
 
 	iio_trigger_notify_done(indio_dev->trig);
 
Signature · 1 line
1.8.0
maintainer Applied
#26 lore raw

Re: [PATCH 14/24] iio:adis_lib: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 25 lines
---
 drivers/iio/imu/adis_buffer.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/iio/imu/adis_buffer.c +2 -7
index 99d8e0b..cb32b59 100644
@@ -102,13 +102,8 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
 		mutex_unlock(&adis->txrx_lock);
 	}
 
-	/* Guaranteed to be aligned with 8 byte boundary */
-	if (indio_dev->scan_timestamp) {
-		void *b = adis->buffer + indio_dev->scan_bytes - sizeof(s64);
-		*(s64 *)b = pf->timestamp;
-	}
-
-	iio_push_to_buffers(indio_dev, adis->buffer);
+	iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
+		pf->timestamp);
 
 	iio_trigger_notify_done(indio_dev->trig);
 
#27 lore raw

PATCH 15/24 iio:mpu6050: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +2 -4
index 7da0832..4295171 100644
@@ -124,7 +124,6 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
 	u8 data[INV_MPU6050_OUTPUT_DATA_SIZE];
 	u16 fifo_count;
 	s64 timestamp;
-	u64 *tmp;
 
 	mutex_lock(&indio_dev->mlock);
 	if (!(st->chip_config.accl_fifo_enable |
@@ -170,9 +169,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
 		if (0 == result)
 			timestamp = 0;
 
-		tmp = (u64 *)data;
-		tmp[DIV_ROUND_UP(bytes_per_datum, 8)] = timestamp;
-		result = iio_push_to_buffers(indio_dev, data);
+		result = iio_push_to_buffers_with_timestamp(indio_dev, data,
+			timestamp);
 		if (result)
 			goto flush_fifo;
 		fifo_count -= bytes_per_datum;
Signature · 1 line
1.8.0
maintainer Applied
#28 lore raw

Re: [PATCH 15/24] iio:mpu6050: Use iio_push_to_buffers_with_timestamp()

Quoted 4 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 29 lines
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +2 -4
index 7da0832..4295171 100644
@@ -124,7 +124,6 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
 	u8 data[INV_MPU6050_OUTPUT_DATA_SIZE];
 	u16 fifo_count;
 	s64 timestamp;
-	u64 *tmp;
 
 	mutex_lock(&indio_dev->mlock);
 	if (!(st->chip_config.accl_fifo_enable |
@@ -170,9 +169,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
 		if (0 == result)
 			timestamp = 0;
 
-		tmp = (u64 *)data;
-		tmp[DIV_ROUND_UP(bytes_per_datum, 8)] = timestamp;
-		result = iio_push_to_buffers(indio_dev, data);
+		result = iio_push_to_buffers_with_timestamp(indio_dev, data,
+			timestamp);
 		if (result)
 			goto flush_fifo;
 		fifo_count -= bytes_per_datum;
#29 lore raw

PATCH 16/24 iio:adjd_s311: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/light/adjd_s311.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/iio/light/adjd_s311.c +1 -4
index c9c8b00..39f6392 100644
@@ -138,10 +138,7 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p)
 		len += 2;
 	}
 
-	if (indio_dev->scan_timestamp)
-		*(s64 *)((u8 *)data->buffer + ALIGN(len, sizeof(s64)))
-			= time_ns;
-	iio_push_to_buffers(indio_dev, data->buffer);
+	iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, time_ns);
 
 done:
 	iio_trigger_notify_done(indio_dev->trig);
Signature · 1 line
1.8.0
maintainer Applied
#30 lore raw

Re: [PATCH 16/24] iio:adjd_s311: Use iio_push_to_buffers_with_timestamp()

Quoted 4 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 21 lines
---
 drivers/iio/light/adjd_s311.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/iio/light/adjd_s311.c +1 -4
index c9c8b00..39f6392 100644
@@ -138,10 +138,7 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p)
 		len += 2;
 	}
 
-	if (indio_dev->scan_timestamp)
-		*(s64 *)((u8 *)data->buffer + ALIGN(len, sizeof(s64)))
-			= time_ns;
-	iio_push_to_buffers(indio_dev, data->buffer);
+	iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, time_ns);
 
 done:
 	iio_trigger_notify_done(indio_dev->trig);
#31 lore raw

PATCH 17/24 iio:tcs3472: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/light/tcs3472.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/light/tcs3472.c +2 -4
index 7bf2969..0bc15cf 100644
@@ -192,10 +192,8 @@ static irqreturn_t tcs3472_trigger_handler(int irq, void *p)
 		len += 2;
 	}
 
-	if (indio_dev->scan_timestamp)
-		*(s64 *)((u8 *)data->buffer + ALIGN(len, sizeof(s64)))
-			= iio_get_time_ns();
-	iio_push_to_buffers(indio_dev, data->buffer);
+	iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
+		iio_get_time_ns());
 
 done:
 	iio_trigger_notify_done(indio_dev->trig);
Signature · 1 line
1.8.0
maintainer Applied
#32 lore raw

Re: [PATCH 17/24] iio:tcs3472: Use iio_push_to_buffers_with_timestamp()

Quoted 4 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Thanks

Quoted 22 lines
---
 drivers/iio/light/tcs3472.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/light/tcs3472.c +2 -4
index 7bf2969..0bc15cf 100644
@@ -192,10 +192,8 @@ static irqreturn_t tcs3472_trigger_handler(int irq, void *p)
 		len += 2;
 	}
 
-	if (indio_dev->scan_timestamp)
-		*(s64 *)((u8 *)data->buffer + ALIGN(len, sizeof(s64)))
-			= iio_get_time_ns();
-	iio_push_to_buffers(indio_dev, data->buffer);
+	iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
+		iio_get_time_ns());
 
 done:
 	iio_trigger_notify_done(indio_dev->trig);
#33 lore raw

PATCH 18/24 iio:gp2ap020a00f: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/iio/light/gp2ap020a00f.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/iio/light/gp2ap020a00f.c +2 -7
index 62809b5..b1e4615 100644
@@ -988,13 +988,8 @@ static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data)
 		}
 	}
 
-	if (indio_dev->scan_timestamp) {
-		s64 *timestamp = (s64 *)((u8 *)priv->buffer +
-						ALIGN(d_size, sizeof(s64)));
-		*timestamp = pf->timestamp;
-	}
-
-	iio_push_to_buffers(indio_dev, priv->buffer);
+	iio_push_to_buffers_with_timestamp(indio_dev, priv->buffer,
+		pf->timestamp);
 done:
 	iio_trigger_notify_done(indio_dev->trig);
 
Signature · 1 line
1.8.0
maintainer Applied
#34 lore raw

Re: [PATCH 18/24] iio:gp2ap020a00f: Use iio_push_to_buffers_with_timestamp()

Quoted 4 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 25 lines
---
 drivers/iio/light/gp2ap020a00f.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/iio/light/gp2ap020a00f.c +2 -7
index 62809b5..b1e4615 100644
@@ -988,13 +988,8 @@ static irqreturn_t gp2ap020a00f_trigger_handler(int irq, void *data)
 		}
 	}
 
-	if (indio_dev->scan_timestamp) {
-		s64 *timestamp = (s64 *)((u8 *)priv->buffer +
-						ALIGN(d_size, sizeof(s64)));
-		*timestamp = pf->timestamp;
-	}
-
-	iio_push_to_buffers(indio_dev, priv->buffer);
+	iio_push_to_buffers_with_timestamp(indio_dev, priv->buffer,
+		pf->timestamp);
 done:
 	iio_trigger_notify_done(indio_dev->trig);
 
#35 lore raw

PATCH 19/24 staging:iio:lis3l02dq: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/staging/iio/accel/lis3l02dq_ring.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/iio/accel/lis3l02dq_ring.c +1 -5
index 36dcc7e..aae86dd 100644
@@ -146,11 +146,7 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
 	if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
 		len = lis3l02dq_get_buffer_element(indio_dev, data);
 
-	  /* Guaranteed to be aligned with 8 byte boundary */
-	if (indio_dev->scan_timestamp)
-		*(s64 *)((u8 *)data + ALIGN(len, sizeof(s64)))
-			= pf->timestamp;
-	iio_push_to_buffers(indio_dev, data);
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp);
 
 	kfree(data);
 done:
Signature · 1 line
1.8.0
maintainer
#36 lore raw

Re: [PATCH 19/24] staging:iio:lis3l02dq: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied ot the togreg branch of iio.git

Quoted 22 lines
---
 drivers/staging/iio/accel/lis3l02dq_ring.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/iio/accel/lis3l02dq_ring.c +1 -5
index 36dcc7e..aae86dd 100644
@@ -146,11 +146,7 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
 	if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
 		len = lis3l02dq_get_buffer_element(indio_dev, data);
 
-	  /* Guaranteed to be aligned with 8 byte boundary */
-	if (indio_dev->scan_timestamp)
-		*(s64 *)((u8 *)data + ALIGN(len, sizeof(s64)))
-			= pf->timestamp;
-	iio_push_to_buffers(indio_dev, data);
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp);
 
 	kfree(data);
 done:
#37 lore raw

PATCH 20/24 staging:iio:ad7606: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/staging/iio/adc/ad7606_ring.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/staging/iio/adc/ad7606_ring.c +1 -7
index 2b25cb0..3bf174c 100644
@@ -46,7 +46,6 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
 	struct ad7606_state *st = container_of(work_s, struct ad7606_state,
 						poll_work);
 	struct iio_dev *indio_dev = iio_priv_to_dev(st);
-	s64 time_ns;
 	__u8 *buf;
 	int ret;
 
@@ -78,12 +77,7 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
 			goto done;
 	}
 
-	time_ns = iio_get_time_ns();
-
-	if (indio_dev->scan_timestamp)
-		*((s64 *)(buf + indio_dev->scan_bytes - sizeof(s64))) = time_ns;
-
-	iio_push_to_buffers(indio_dev, buf);
+	iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
 done:
 	gpio_set_value(st->pdata->gpio_convst, 0);
 	iio_trigger_notify_done(indio_dev->trig);
Signature · 1 line
1.8.0
maintainer Applied
#38 lore raw

Re: [PATCH 20/24] staging:iio:ad7606: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 31 lines
---
 drivers/staging/iio/adc/ad7606_ring.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/staging/iio/adc/ad7606_ring.c +1 -7
index 2b25cb0..3bf174c 100644
@@ -46,7 +46,6 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
 	struct ad7606_state *st = container_of(work_s, struct ad7606_state,
 						poll_work);
 	struct iio_dev *indio_dev = iio_priv_to_dev(st);
-	s64 time_ns;
 	__u8 *buf;
 	int ret;
 
@@ -78,12 +77,7 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
 			goto done;
 	}
 
-	time_ns = iio_get_time_ns();
-
-	if (indio_dev->scan_timestamp)
-		*((s64 *)(buf + indio_dev->scan_bytes - sizeof(s64))) = time_ns;
-
-	iio_push_to_buffers(indio_dev, buf);
+	iio_push_to_buffers_with_timestamp(indio_dev, buf, iio_get_time_ns());
 done:
 	gpio_set_value(st->pdata->gpio_convst, 0);
 	iio_trigger_notify_done(indio_dev->trig);
#39 lore raw

PATCH 21/24 staging:iio:ad799x: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/staging/iio/adc/ad799x_ring.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/staging/iio/adc/ad799x_ring.c +2 -8
index c2ebae1..0ff6c03 100644
@@ -35,7 +35,6 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad799x_state *st = iio_priv(indio_dev);
-	s64 time_ns;
 	int b_sent;
 	u8 cmd;
 
@@ -65,13 +64,8 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
 	if (b_sent < 0)
 		goto out;
 
-	time_ns = iio_get_time_ns();
-
-	if (indio_dev->scan_timestamp)
-		memcpy(st->rx_buf + indio_dev->scan_bytes - sizeof(s64),
-			&time_ns, sizeof(time_ns));
-
-	iio_push_to_buffers(indio_dev, st->rx_buf);
+	iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
+			iio_get_time_ns());
 out:
 	iio_trigger_notify_done(indio_dev->trig);
 
Signature · 1 line
1.8.0
maintainer Applied
#40 lore raw

Re: [PATCH 21/24] staging:iio:ad799x: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Thanks

Quoted 33 lines
---
 drivers/staging/iio/adc/ad799x_ring.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/staging/iio/adc/ad799x_ring.c +2 -8
index c2ebae1..0ff6c03 100644
@@ -35,7 +35,6 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad799x_state *st = iio_priv(indio_dev);
-	s64 time_ns;
 	int b_sent;
 	u8 cmd;
 
@@ -65,13 +64,8 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
 	if (b_sent < 0)
 		goto out;
 
-	time_ns = iio_get_time_ns();
-
-	if (indio_dev->scan_timestamp)
-		memcpy(st->rx_buf + indio_dev->scan_bytes - sizeof(s64),
-			&time_ns, sizeof(time_ns));
-
-	iio_push_to_buffers(indio_dev, st->rx_buf);
+	iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
+			iio_get_time_ns());
 out:
 	iio_trigger_notify_done(indio_dev->trig);
 
#41 lore raw

PATCH 22/24 staging:iio:mxs-lradc: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/staging/iio/adc/mxs-lradc.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/staging/iio/adc/mxs-lradc.c +1 -7
index 7401230..9da64bf 100644
@@ -625,13 +625,7 @@ static irqreturn_t mxs_lradc_trigger_handler(int irq, void *p)
 		j++;
 	}
 
-	if (iio->scan_timestamp) {
-		s64 *timestamp = (s64 *)((u8 *)lradc->buffer +
-					ALIGN(j, sizeof(s64)));
-		*timestamp = pf->timestamp;
-	}
-
-	iio_push_to_buffers(iio, lradc->buffer);
+	iio_push_to_buffers_with_timestamp(iio, lradc->buffer, pf->timestamp);
 
 	iio_trigger_notify_done(iio->trig);
 
Signature · 1 line
1.8.0
maintainer Applied
#42 lore raw

Re: [PATCH 22/24] staging:iio:mxs-lradc: Use iio_push_to_buffers_with_timestamp()

Quoted 5 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Quoted 24 lines
---
 drivers/staging/iio/adc/mxs-lradc.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/staging/iio/adc/mxs-lradc.c +1 -7
index 7401230..9da64bf 100644
@@ -625,13 +625,7 @@ static irqreturn_t mxs_lradc_trigger_handler(int irq, void *p)
 		j++;
 	}
 
-	if (iio->scan_timestamp) {
-		s64 *timestamp = (s64 *)((u8 *)lradc->buffer +
-					ALIGN(j, sizeof(s64)));
-		*timestamp = pf->timestamp;
-	}
-
-	iio_push_to_buffers(iio, lradc->buffer);
+	iio_push_to_buffers_with_timestamp(iio, lradc->buffer, pf->timestamp);
 
 	iio_trigger_notify_done(iio->trig);
 
#43 lore raw

PATCH 23/24 staging:iio:dummy: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/staging/iio/iio_simple_dummy_buffer.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/staging/iio/iio_simple_dummy_buffer.c +2 -5
index 3921865..09c93ac 100644
@@ -82,11 +82,8 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
 			len += 2;
 		}
 	}
-	/* Store the timestamp at an 8 byte aligned offset */
-	if (indio_dev->scan_timestamp)
-		*(s64 *)((u8 *)data + ALIGN(len, sizeof(s64)))
-			= iio_get_time_ns();
-	iio_push_to_buffers(indio_dev, data);
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, iio_get_time_ns());
 
 	kfree(data);
 
Signature · 1 line
1.8.0
maintainer Applied
#44 lore raw

Re: [PATCH 23/24] staging:iio:dummy: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Thanks,

Quoted 23 lines
---
 drivers/staging/iio/iio_simple_dummy_buffer.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/staging/iio/iio_simple_dummy_buffer.c +2 -5
index 3921865..09c93ac 100644
@@ -82,11 +82,8 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
 			len += 2;
 		}
 	}
-	/* Store the timestamp at an 8 byte aligned offset */
-	if (indio_dev->scan_timestamp)
-		*(s64 *)((u8 *)data + ALIGN(len, sizeof(s64)))
-			= iio_get_time_ns();
-	iio_push_to_buffers(indio_dev, data);
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, iio_get_time_ns());
 
 	kfree(data);
 
#45 lore raw

PATCH 24/24 staging:iio:ade7758: Use iio_push_to_buffers_with_timestamp()

In reply to Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

---
 drivers/staging/iio/meter/ade7758_ring.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/iio/meter/ade7758_ring.c +1 -5
index 3d8bc2d..4080995 100644
@@ -69,11 +69,7 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
 		if (ade7758_spi_read_burst(indio_dev) >= 0)
 			*dat32 = get_unaligned_be32(&st->rx_buf[5]) & 0xFFFFFF;
 
-	/* Guaranteed to be aligned with 8 byte boundary */
-	if (indio_dev->scan_timestamp)
-		dat64[1] = pf->timestamp;
-
-	iio_push_to_buffers(indio_dev, dat64);
+	iio_push_to_buffers_with_timestamp(indio_dev, dat64, pf->timestamp);
 
 	iio_trigger_notify_done(indio_dev->trig);
 
Signature · 1 line
1.8.0
maintainer Applied
#46 lore raw

Re: [PATCH 24/24] staging:iio:ade7758: Use iio_push_to_buffers_with_timestamp()

Quoted 3 lines · Lars-Peter Clausen

Makes the code a bit shorter and less ugly.

Applied to the togreg branch of iio.git

Thanks

Quoted 22 lines
---
 drivers/staging/iio/meter/ade7758_ring.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/iio/meter/ade7758_ring.c +1 -5
index 3d8bc2d..4080995 100644
@@ -69,11 +69,7 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
 		if (ade7758_spi_read_burst(indio_dev) >= 0)
 			*dat32 = get_unaligned_be32(&st->rx_buf[5]) & 0xFFFFFF;
 
-	/* Guaranteed to be aligned with 8 byte boundary */
-	if (indio_dev->scan_timestamp)
-		dat64[1] = pf->timestamp;
-
-	iio_push_to_buffers(indio_dev, dat64);
+	iio_push_to_buffers_with_timestamp(indio_dev, dat64, pf->timestamp);
 
 	iio_trigger_notify_done(indio_dev->trig);
 
maintainer Applied
#47 lore raw
In reply to Lars-Peter Clausen
Quoted 12 lines · Lars-Peter Clausen

Drivers using software buffers often store the timestamp in their data buffer before calling iio_push_to_buffers() with that data buffer. Storing the timestamp in the buffer usually involves some ugly pointer arithmetic. This patch adds a new helper function called iio_push_buffers_with_timestamp() which is similar to iio_push_to_buffers but takes an additional timestamp parameter. The function will help to hide to uglyness in one central place instead of exposing it in every driver. If timestamps are enabled for the IIO device iio_push_buffers_with_timestamp() will store the timestamp as the last element in buffer, before passing the buffer on to iio_push_buffers(). The buffer needs large enough to hold the timestamp in this case. If timestamps are disabled iio_push_buffers_with_timestamp() will behave just like iio_push_buffers().

Quoted 10 lines
Cc Oleksandr Kravchenko <[email protected]>
Cc Josh Wu <[email protected]>
Cc Denis Ciocca <[email protected]>
Cc Manuel Stahl <[email protected]>
Cc Ge Gao <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc Jacek Anaszewski <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Marek Vasut <[email protected]>

Applied to the togreg branch of iio.git

Thanks

Quoted 41 lines
---
 include/linux/iio/buffer.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
include/linux/iio/buffer.h +25 -0
index e5507e9..a1124bd 100644
@@ -122,6 +122,31 @@ int iio_scan_mask_set(struct iio_dev *indio_dev,
  */
 int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data);
 
+/*
+ * iio_push_to_buffers_with_timestamp() - push data and timestamp to buffers
+ * @indio_dev:		iio_dev structure for device.
+ * @data:		sample data
+ * @timestamp:		timestamp for the sample data
+ *
+ * Pushes data to the IIO device's buffers. If timestamps are enabled for the
+ * device the function will store the supplied timestamp as the last element in
+ * the sample data buffer before pushing it to the device buffers. The sample
+ * data buffer needs to be large enough to hold the additional timestamp
+ * (usually the buffer should be indio->scan_bytes bytes large).
+ *
+ * Returns 0 on success, a negative error code otherwise.
+ */
+static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev,
+	void *data, int64_t timestamp)
+{
+	if (indio_dev->scan_timestamp) {
+		size_t ts_offset = indio_dev->scan_bytes / sizeof(int64_t) - 1;
+		((int64_t *)data)[ts_offset] = timestamp;
+	}
+
+	return iio_push_to_buffers(indio_dev, data);
+}
+
 int iio_update_demux(struct iio_dev *indio_dev);
 
 /**