Skip to contentSkip to conversation

staging:iio: Add support for multiple buffers (testing required!)

PATCH Superseded Jonathan Cameron 4 participants 12 messages Oct 13, 2012 – Oct 20, 2012

Subsystems (7)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

v5 cover staging:iio: Add support for multiple buffers (testing required!)

In quick summary this is needed to do interrupt driven in kernel clients as it adds the option to push to multiple 'buffer' interfaces. Note that some of these may not actually do any buffering but rather push directly into another subsytem (the example is input).

I would like to merge at least the first 3 patches early in this cycle. What I need is some testing across a reasonable range of devices. Review is welcome of course as well!

The complexity in this set is entirely in the changes to industrialio-buffer.c concerning how we go about adding and removing client buffers. To do this we need to work out which scan mask is appropriate given the requests of all the given buffers (and whether we can satisfy it). I've been testing with the max1363 driver which probably has the most complex set of available scan masks. Thus when a new buffer is added or one is removed the whole buffer set are torn down and built up again. This may be undesirable for some applications but should occur only rarely.

The example driver is for bridging to the input subsystem and still needs some work, but that can occur later in this merge cycle whereas the changes to the core really want to go in asap.

Changes since v3

Rebased and added other drivers that have occured whilst this patch series has been languishing in my local tree.

Changes since V2.

Improved handling of error conditions in the buffer insertion and removal code. (suggested by Lars-Peter). I want to take another look at these, but didn't want to keep people from testing this in the meantime.

Also a number of minor fixes that came up during testing.

Thanks,

Jonathan

Jonathan Cameron (4):
staging:iio: Add support for multiple buffers staging:iio:in kernel users: Add a data field for channel specific
info.
staging:iio: add a callback buffer for in kernel push interface staging:iio: Proof of concept input driver.

 drivers/iio/Kconfig                             |   6 +
 drivers/iio/Makefile                            |   1 +
 drivers/iio/accel/hid-sensor-accel-3d.c         |  15 +-
 drivers/iio/adc/ad7266.c                        |   3 +-
 drivers/iio/adc/ad7476.c                        |   2 +-
 drivers/iio/adc/ad_sigma_delta.c                |   2 +-
 drivers/iio/adc/at91_adc.c                      |   3 +-
 drivers/iio/buffer_cb.c                         | 113 +++++++
 drivers/iio/gyro/hid-sensor-gyro-3d.c           |  15 +-
 drivers/iio/industrialio-buffer.c               | 377 ++++++++++++++++--------
 drivers/iio/industrialio-core.c                 |   1 +
 drivers/iio/inkern.c                            |   1 +
 drivers/iio/light/adjd_s311.c                   |   3 +-
 drivers/iio/light/hid-sensor-als.c              |  15 +-
 drivers/iio/magnetometer/hid-sensor-magn-3d.c   |  15 +-
 drivers/staging/iio/Kconfig                     |  11 +
 drivers/staging/iio/Makefile                    |   1 +
 drivers/staging/iio/accel/adis16201_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16203_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16204_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16209_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16240_ring.c      |   2 +-
 drivers/staging/iio/accel/lis3l02dq_ring.c      |   2 +-
 drivers/staging/iio/adc/ad7298_ring.c           |   2 +-
 drivers/staging/iio/adc/ad7606_ring.c           |   2 +-
 drivers/staging/iio/adc/ad7887_ring.c           |   2 +-
 drivers/staging/iio/adc/ad799x_ring.c           |   2 +-
 drivers/staging/iio/adc/max1363_ring.c          |   2 +-
 drivers/staging/iio/gyro/adis16260_ring.c       |   2 +-
 drivers/staging/iio/iio_input.c                 | 225 ++++++++++++++
 drivers/staging/iio/iio_input.h                 |  23 ++
 drivers/staging/iio/iio_simple_dummy_buffer.c   |   5 +-
 drivers/staging/iio/impedance-analyzer/ad5933.c |   4 +-
 drivers/staging/iio/imu/adis16400_ring.c        |   5 +-
 drivers/staging/iio/meter/ade7758_ring.c        |   2 +-
 include/linux/iio/buffer.h                      |  24 +-
 include/linux/iio/consumer.h                    |  48 +++
 include/linux/iio/iio.h                         |   2 +
 include/linux/iio/machine.h                     |   2 +
 39 files changed, 740 insertions(+), 208 deletions(-)
 create mode 100644 drivers/iio/buffer_cb.c
 create mode 100644 drivers/staging/iio/iio_input.c
 create mode 100644 drivers/staging/iio/iio_input.h
Signature · 1 line
1.7.12.2
author maintainer
#1 lore raw

PATCH v5 1/4 staging:iio: Add support for multiple buffers

Route all buffer writes through the demux. Addition or removal of a buffer results in tear down and setup of all the buffers for a given device.

---
 drivers/iio/accel/hid-sensor-accel-3d.c         |  15 +-
 drivers/iio/adc/ad7266.c                        |   3 +-
 drivers/iio/adc/ad7476.c                        |   2 +-
 drivers/iio/adc/ad_sigma_delta.c                |   2 +-
 drivers/iio/adc/at91_adc.c                      |   3 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c           |  15 +-
 drivers/iio/industrialio-buffer.c               | 377 ++++++++++++++++--------
 drivers/iio/industrialio-core.c                 |   1 +
 drivers/iio/light/adjd_s311.c                   |   3 +-
 drivers/iio/light/hid-sensor-als.c              |  15 +-
 drivers/iio/magnetometer/hid-sensor-magn-3d.c   |  15 +-
 drivers/staging/iio/accel/adis16201_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16203_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16204_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16209_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16240_ring.c      |   2 +-
 drivers/staging/iio/accel/lis3l02dq_ring.c      |   2 +-
 drivers/staging/iio/adc/ad7298_ring.c           |   2 +-
 drivers/staging/iio/adc/ad7606_ring.c           |   2 +-
 drivers/staging/iio/adc/ad7887_ring.c           |   2 +-
 drivers/staging/iio/adc/ad799x_ring.c           |   2 +-
 drivers/staging/iio/adc/max1363_ring.c          |   2 +-
 drivers/staging/iio/gyro/adis16260_ring.c       |   2 +-
 drivers/staging/iio/iio_simple_dummy_buffer.c   |   5 +-
 drivers/staging/iio/impedance-analyzer/ad5933.c |   4 +-
 drivers/staging/iio/imu/adis16400_ring.c        |   5 +-
 drivers/staging/iio/meter/ade7758_ring.c        |   2 +-
 include/linux/iio/buffer.h                      |  24 +-
 include/linux/iio/iio.h                         |   2 +
 29 files changed, 309 insertions(+), 208 deletions(-)
drivers/iio/accel/hid-sensor-accel-3d.c +1 -14
index 314a405..a95cda0 100644
@@ -197,21 +197,8 @@ static const struct iio_info accel_3d_info = {
 /* Function to push data to buffer */
 static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len)
 {
-	struct iio_buffer *buffer = indio_dev->buffer;
-	int datum_sz;
-
 	dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n");
-	if (!buffer) {
-		dev_err(&indio_dev->dev, "Buffer == NULL\n");
-		return;
-	}
-	datum_sz = buffer->access->get_bytes_per_datum(buffer);
-	if (len > datum_sz) {
-		dev_err(&indio_dev->dev, "Datum size mismatch %d:%d\n", len,
-				datum_sz);
-		return;
-	}
-	iio_push_to_buffer(buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 }
 
 /* Callback handler to send event after all samples are received and captured */
drivers/iio/adc/ad7266.c +1 -2
index b11f214..a6f4fc5 100644
@@ -91,7 +91,6 @@ static irqreturn_t ad7266_trigger_handler(int irq, void *p)
 {
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
-	struct iio_buffer *buffer = indio_dev->buffer;
 	struct ad7266_state *st = iio_priv(indio_dev);
 	int ret;
 
@@ -99,7 +98,7 @@ static irqreturn_t ad7266_trigger_handler(int irq, void *p)
 	if (ret == 0) {
 		if (indio_dev->scan_timestamp)
 			((s64 *)st->data)[1] = pf->timestamp;
-		iio_push_to_buffer(buffer, (u8 *)st->data);
+		iio_push_to_buffers(indio_dev, (u8 *)st->data);
 	}
 
 	iio_trigger_notify_done(indio_dev->trig);
drivers/iio/adc/ad7476.c +1 -1
index 7f2f45a..330248b 100644
@@ -76,7 +76,7 @@ static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
 	if (indio_dev->scan_timestamp)
 		((s64 *)st->data)[1] = time_ns;
 
-	iio_push_to_buffer(indio_dev->buffer, st->data);
+	iio_push_to_buffers(indio_dev, st->data);
 done:
 	iio_trigger_notify_done(indio_dev->trig);
 
drivers/iio/adc/ad_sigma_delta.c +1 -1
index 67baa13..afe6d78 100644
@@ -391,7 +391,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 		break;
 	}
 
-	iio_push_to_buffer(indio_dev->buffer, (uint8_t *)data);
+	iio_push_to_buffers(indio_dev, (uint8_t *)data);
 
 	iio_trigger_notify_done(indio_dev->trig);
 	sigma_delta->irq_dis = false;
drivers/iio/adc/at91_adc.c +1 -2
index 3ed94bf..1f9e70e 100644
@@ -66,7 +66,6 @@ static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *idev = pf->indio_dev;
 	struct at91_adc_state *st = iio_priv(idev);
-	struct iio_buffer *buffer = idev->buffer;
 	int i, j = 0;
 
 	for (i = 0; i < idev->masklength; i++) {
@@ -82,7 +81,7 @@ static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
 		*timestamp = pf->timestamp;
 	}
 
-	buffer->access->store_to(buffer, (u8 *)st->buffer);
+	iio_push_to_buffers(indio_dev, (u8 *)st->buffer);
 
 	iio_trigger_notify_done(idev->trig);
 	st->irq_enabled = true;
drivers/iio/gyro/hid-sensor-gyro-3d.c +1 -14
index 4c56ada..02ef989 100644
@@ -197,21 +197,8 @@ static const struct iio_info gyro_3d_info = {
 /* Function to push data to buffer */
 static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len)
 {
-	struct iio_buffer *buffer = indio_dev->buffer;
-	int datum_sz;
-
 	dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n");
-	if (!buffer) {
-		dev_err(&indio_dev->dev, "Buffer == NULL\n");
-		return;
-	}
-	datum_sz = buffer->access->get_bytes_per_datum(buffer);
-	if (len > datum_sz) {
-		dev_err(&indio_dev->dev, "Datum size mismatch %d:%d\n", len,
-				datum_sz);
-		return;
-	}
-	iio_push_to_buffer(buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 }
 
 /* Callback handler to send event after all samples are received and captured */
drivers/iio/industrialio-buffer.c +260 -117

463 lines not on this page · raw message

drivers/iio/industrialio-core.c +1 -0
index 6eb24db..1bcaabf 100644
@@ -851,6 +851,7 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
 			return NULL;
 		}
 		dev_set_name(&dev->dev, "iio:device%d", dev->id);
+		INIT_LIST_HEAD(&dev->buffer_list);
 	}
 
 	return dev;
drivers/iio/light/adjd_s311.c +1 -2
index 164b62b..36d210a 100644
@@ -164,7 +164,6 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct adjd_s311_data *data = iio_priv(indio_dev);
-	struct iio_buffer *buffer = indio_dev->buffer;
 	s64 time_ns = iio_get_time_ns();
 	int len = 0;
 	int i, j = 0;
@@ -187,7 +186,7 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p)
 	if (indio_dev->scan_timestamp)
 		*(s64 *)((u8 *)data->buffer + ALIGN(len, sizeof(s64)))
 			= time_ns;
-	iio_push_to_buffer(buffer, (u8 *)data->buffer);
+	iio_push_to_buffers(indio_dev, (u8 *)data->buffer);
 
 done:
 	iio_trigger_notify_done(indio_dev->trig);
drivers/iio/light/hid-sensor-als.c +1 -14
index 96e3691..8e1f698 100644
@@ -176,21 +176,8 @@ static const struct iio_info als_info = {
 /* Function to push data to buffer */
 static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len)
 {
-	struct iio_buffer *buffer = indio_dev->buffer;
-	int datum_sz;
-
 	dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n");
-	if (!buffer) {
-		dev_err(&indio_dev->dev, "Buffer == NULL\n");
-		return;
-	}
-	datum_sz = buffer->access->get_bytes_per_datum(buffer);
-	if (len > datum_sz) {
-		dev_err(&indio_dev->dev, "Datum size mismatch %d:%d\n", len,
-				datum_sz);
-		return;
-	}
-	iio_push_to_buffer(buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 }
 
 /* Callback handler to send event after all samples are received and captured */
drivers/iio/magnetometer/hid-sensor-magn-3d.c +1 -14
index c4f0d27..d1b5fb7 100644
@@ -198,21 +198,8 @@ static const struct iio_info magn_3d_info = {
 /* Function to push data to buffer */
 static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len)
 {
-	struct iio_buffer *buffer = indio_dev->buffer;
-	int datum_sz;
-
 	dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n");
-	if (!buffer) {
-		dev_err(&indio_dev->dev, "Buffer == NULL\n");
-		return;
-	}
-	datum_sz = buffer->access->get_bytes_per_datum(buffer);
-	if (len > datum_sz) {
-		dev_err(&indio_dev->dev, "Datum size mismatch %d:%d\n", len,
-				datum_sz);
-		return;
-	}
-	iio_push_to_buffer(buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 }
 
 /* Callback handler to send event after all samples are received and captured */
drivers/staging/iio/accel/adis16201_ring.c +1 -1
index 97c09f0..e14ca60 100644
@@ -82,7 +82,7 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)
 	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
-	iio_push_to_buffer(indio_dev->buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 
 	kfree(data);
 done:
drivers/staging/iio/accel/adis16203_ring.c +1 -1
index 7507e1a..eba2e28 100644
@@ -81,7 +81,7 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p)
 	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
-	iio_push_to_buffer(indio_dev->buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 
 	kfree(data);
 done:
drivers/staging/iio/accel/adis16204_ring.c +1 -1
index 4c976be..3611a13 100644
@@ -78,7 +78,7 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p)
 	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
-	iio_push_to_buffer(indio_dev->buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 
 	kfree(data);
 done:
drivers/staging/iio/accel/adis16209_ring.c +1 -1
index f939e29..6af9a5d 100644
@@ -78,7 +78,7 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p)
 	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
-	iio_push_to_buffer(indio_dev->buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 
 	kfree(data);
 done:
drivers/staging/iio/accel/adis16240_ring.c +1 -1
index caff8e2..e2ac8a8 100644
@@ -76,7 +76,7 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p)
 	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
-	iio_push_to_buffer(indio_dev->buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 
 	kfree(data);
 done:
drivers/staging/iio/accel/lis3l02dq_ring.c +1 -1
index fa4190d..d59abd3 100644
@@ -154,7 +154,7 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
 	if (indio_dev->scan_timestamp)
 		*(s64 *)((u8 *)data + ALIGN(len, sizeof(s64)))
 			= pf->timestamp;
-	iio_push_to_buffer(indio_dev->buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 
 	kfree(data);
 done:
drivers/staging/iio/adc/ad7298_ring.c +1 -1
index c2906a8..b3dd514 100644
@@ -93,7 +93,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
 						 indio_dev->masklength); i++)
 		buf[i] = be16_to_cpu(st->rx_buf[i]);
 
-	iio_push_to_buffer(indio_dev->buffer, (u8 *)buf);
+	iio_push_to_buffers(indio_dev, (u8 *)buf);
 
 done:
 	iio_trigger_notify_done(indio_dev->trig);
drivers/staging/iio/adc/ad7606_ring.c +1 -1
index ba04d0f..2b25cb0 100644
@@ -83,7 +83,7 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
 	if (indio_dev->scan_timestamp)
 		*((s64 *)(buf + indio_dev->scan_bytes - sizeof(s64))) = time_ns;
 
-	iio_push_to_buffer(indio_dev->buffer, buf);
+	iio_push_to_buffers(indio_dev, buf);
 done:
 	gpio_set_value(st->pdata->gpio_convst, 0);
 	iio_trigger_notify_done(indio_dev->trig);
drivers/staging/iio/adc/ad7887_ring.c +1 -1
index b39923b..ccb8d4d 100644
@@ -95,7 +95,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
 		memcpy(buf + indio_dev->scan_bytes - sizeof(s64),
 		       &time_ns, sizeof(time_ns));
 
-	iio_push_to_buffer(indio_dev->buffer, buf);
+	iio_push_to_buffers(indio_dev, buf);
 done:
 	kfree(buf);
 	iio_trigger_notify_done(indio_dev->trig);
drivers/staging/iio/adc/ad799x_ring.c +1 -1
index 86026d9..2c5f384 100644
@@ -77,7 +77,7 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
 		memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64),
 			&time_ns, sizeof(time_ns));
 
-	iio_push_to_buffer(indio_dev->buffer, rxbuf);
+	iio_push_to_buffers(indio_dev, rxbuf);
 done:
 	kfree(rxbuf);
 out:
drivers/staging/iio/adc/max1363_ring.c +1 -1
index 5f74f3b..688304b 100644
@@ -80,7 +80,7 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p)
 
 	if (indio_dev->scan_timestamp)
 		memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
-	iio_push_to_buffer(indio_dev->buffer, rxbuf);
+	iio_push_to_buffers(indio_dev, rxbuf);
 
 done_free:
 	kfree(rxbuf);
drivers/staging/iio/gyro/adis16260_ring.c +1 -1
index e294cb4..d6c48f8 100644
@@ -81,7 +81,7 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)
 	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
-	iio_push_to_buffer(indio_dev->buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 
 	kfree(data);
 done:
drivers/staging/iio/iio_simple_dummy_buffer.c +2 -3
index 697d970..dee16f0 100644
@@ -46,7 +46,6 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
 {
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
-	struct iio_buffer *buffer = indio_dev->buffer;
 	int len = 0;
 	u16 *data;
 
@@ -76,7 +75,7 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
 		     i < bitmap_weight(indio_dev->active_scan_mask,
 				       indio_dev->masklength);
 		     i++, j++) {
-			j = find_next_bit(buffer->scan_mask,
+			j = find_next_bit(indio_dev->active_scan_mask,
 					  indio_dev->masklength, j);
 			/* random access read from the 'device' */
 			data[i] = fakedata[j];
@@ -87,7 +86,7 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
 	if (indio_dev->scan_timestamp)
 		*(s64 *)((u8 *)data + ALIGN(len, sizeof(s64)))
 			= iio_get_time_ns();
-	iio_push_to_buffer(buffer, (u8 *)data);
+	iio_push_to_buffers(indio_dev, (u8 *)data);
 
 	kfree(data);
 
drivers/staging/iio/impedance-analyzer/ad5933.c +1 -3
index de21d47..b1fef14 100644
@@ -647,7 +647,6 @@ static void ad5933_work(struct work_struct *work)
 	struct ad5933_state *st = container_of(work,
 		struct ad5933_state, work.work);
 	struct iio_dev *indio_dev = i2c_get_clientdata(st->client);
-	struct iio_buffer *ring = indio_dev->buffer;
 	signed short buf[2];
 	unsigned char status;
 
@@ -677,8 +676,7 @@ static void ad5933_work(struct work_struct *work)
 		} else {
 			buf[0] = be16_to_cpu(buf[0]);
 		}
-		/* save datum to the ring */
-		iio_push_to_buffer(ring, (u8 *)buf);
+		iio_push_to_buffers(indio_dev, (u8 *)buf);
 	} else {
 		/* no data available - try again later */
 		schedule_delayed_work(&st->work, st->poll_time_jiffies);
drivers/staging/iio/imu/adis16400_ring.c +2 -3
index 260bdd1..d46c1e3 100644
@@ -114,7 +114,6 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct adis16400_state *st = iio_priv(indio_dev);
-	struct iio_buffer *ring = indio_dev->buffer;
 	int i = 0, j, ret = 0;
 	s16 *data;
 
@@ -148,9 +147,9 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
 		}
 	}
 	/* Guaranteed to be aligned with 8 byte boundary */
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
-	iio_push_to_buffer(ring, (u8 *) data);
+	iio_push_to_buffers(indio_dev, (u8 *) data);
 
 done:
 	kfree(data);
drivers/staging/iio/meter/ade7758_ring.c +1 -1
index 9e49bac..4552a4c 100644
@@ -73,7 +73,7 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
 	if (indio_dev->scan_timestamp)
 		dat64[1] = pf->timestamp;
 
-	iio_push_to_buffer(indio_dev->buffer, (u8 *)dat64);
+	iio_push_to_buffers(indio_dev, (u8 *)dat64);
 
 	iio_trigger_notify_done(indio_dev->trig);
 
include/linux/iio/buffer.h +19 -5
index c629b3a..0270405 100644
@@ -66,7 +66,8 @@ struct iio_buffer_access_funcs {
  * @stufftoread:	[INTERN] flag to indicate new data.
  * @demux_list:		[INTERN] list of operations required to demux the scan.
  * @demux_bounce:	[INTERN] buffer for doing gather from incoming scan.
- **/
+ * @buffer_list:	[INTERN] entry in the devices list of current buffers.
+ */
 struct iio_buffer {
 	int					length;
 	int					bytes_per_datum;
@@ -81,9 +82,22 @@ struct iio_buffer {
 	const struct attribute_group *attrs;
 	struct list_head			demux_list;
 	unsigned char				*demux_bounce;
+	struct list_head			buffer_list;
 };
 
 /**
+ * iio_update_buffers() - add or remove buffer from active list
+ * @indio_dev:		device to add buffer to
+ * @insert_buffer:	buffer to insert
+ * @remove_buffer:	buffer_to_remove
+ *
+ * Note this will tear down the all buffering and build it up again
+ */
+int iio_update_buffers(struct iio_dev *indio_dev,
+		       struct iio_buffer *insert_buffer,
+		       struct iio_buffer *remove_buffer);
+
+/**
  * iio_buffer_init() - Initialize the buffer structure
  * @buffer:		buffer to be initialized
  **/
@@ -115,11 +129,11 @@ int iio_scan_mask_set(struct iio_dev *indio_dev,
 		      struct iio_buffer *buffer, int bit);
 
 /**
- * iio_push_to_buffer() - push to a registered buffer.
- * @buffer:		IIO buffer structure for device
- * @data:		the data to push to the buffer
+ * iio_push_to_buffers() - push to a registered buffer.
+ * @indio_dev:		iio_dev structure for device.
+ * @data:		Full scan.
  */
-int iio_push_to_buffer(struct iio_buffer *buffer, unsigned char *data);
+int iio_push_to_buffers(struct iio_dev *indio_dev, unsigned char *data);
 
 int iio_update_demux(struct iio_dev *indio_dev);
 
include/linux/iio/iio.h +2 -0
index c0ae76a..0ff0e66 100644
@@ -410,6 +410,7 @@ struct iio_buffer_setup_ops {
  *			and owner
  * @event_interface:	[INTERN] event chrdevs associated with interrupt lines
  * @buffer:		[DRIVER] any buffer present
+ * @buffer_list:	[INTERN] list of all buffers currently attached
  * @scan_bytes:		[INTERN] num bytes captured to be fed to buffer demux
  * @mlock:		[INTERN] lock used to prevent simultaneous device state
  *			changes
@@ -448,6 +449,7 @@ struct iio_dev {
 	struct iio_event_interface	*event_interface;
 
 	struct iio_buffer		*buffer;
+	struct list_head		buffer_list;
 	int				scan_bytes;
 	struct mutex			mlock;
 
Signature · 1 line
1.7.12.2
#2 lore raw

Re: [PATCH 1/4] staging:iio: Add support for multiple buffers

Quoted 209 lines · Jonathan Cameron

Route all buffer writes through the demux. Addition or removal of a buffer results in tear down and setup of all the buffers for a given device.

---
[...]
/* Callback handler to send event after all samples are received and captured */

drivers/iio/industrialio-buffer.c +44 -103
index d4ad374..8caa0d7 100644
@@ -31,6 +31,18 @@ static const char * const iio_endian_prefix[] = {
 	[IIO_LE] = "le",
 };
 
+static bool iio_buffer_is_active(struct iio_dev *indio_dev,
+				 struct iio_buffer *buf)
+{
+	struct list_head *p;
+
+	list_for_each(p, &indio_dev->buffer_list)
+		if (p == &buf->buffer_list)
+			return true;
+
+	return false;
+}
+
 /**
  * iio_buffer_read_first_n_outer() - chrdev read for buffer access
  *
@@ -134,7 +146,7 @@ static ssize_t iio_scan_el_store(struct device *dev,
 	if (ret < 0)
 		return ret;
 	mutex_lock(&indio_dev->mlock);
-	if (iio_buffer_enabled(indio_dev)) {
+	if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) {
 		ret = -EBUSY;
 		goto error_ret;
 	}
@@ -180,12 +192,11 @@ static ssize_t iio_scan_el_ts_store(struct device *dev,
 		return ret;
 
 	mutex_lock(&indio_dev->mlock);
-	if (iio_buffer_enabled(indio_dev)) {
+	if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) {
 		ret = -EBUSY;
 		goto error_ret;
 	}
 	indio_dev->buffer->scan_timestamp = state;
-	indio_dev->scan_timestamp = state;
 error_ret:
 	mutex_unlock(&indio_dev->mlock);
 
@@ -385,7 +396,7 @@ ssize_t iio_buffer_write_length(struct device *dev,
 			return len;
 
 	mutex_lock(&indio_dev->mlock);
-	if (iio_buffer_enabled(indio_dev)) {
+	if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) {
 		ret = -EBUSY;
 	} else {
 		if (buffer->access->set_length)
@@ -398,102 +409,14 @@ ssize_t iio_buffer_write_length(struct device *dev,
 }
 EXPORT_SYMBOL(iio_buffer_write_length);
 
-ssize_t iio_buffer_store_enable(struct device *dev,
-				struct device_attribute *attr,
-				const char *buf,
-				size_t len)
-{
-	int ret;
-	bool requested_state, current_state;
-	int previous_mode;
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct iio_buffer *buffer = indio_dev->buffer;
-
-	mutex_lock(&indio_dev->mlock);
-	previous_mode = indio_dev->currentmode;
-	requested_state = !(buf[0] == '0');
-	current_state = iio_buffer_enabled(indio_dev);
-	if (current_state == requested_state) {
-		printk(KERN_INFO "iio-buffer, current state requested again\n");
-		goto done;
-	}
-	if (requested_state) {
-		if (indio_dev->setup_ops->preenable) {
-			ret = indio_dev->setup_ops->preenable(indio_dev);
-			if (ret) {
-				printk(KERN_ERR
-				       "Buffer not started: "
-				       "buffer preenable failed\n");
-				goto error_ret;
-			}
-		}
-		if (buffer->access->request_update) {
-			ret = buffer->access->request_update(buffer);
-			if (ret) {
-				printk(KERN_INFO
-				       "Buffer not started: "
-				       "buffer parameter update failed\n");
-				goto error_ret;
-			}
-		}
-		/* Definitely possible for devices to support both of these. */
-		if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) {
-			if (!indio_dev->trig) {
-				printk(KERN_INFO
-				       "Buffer not started: no trigger\n");
-				ret = -EINVAL;
-				goto error_ret;
-			}
-			indio_dev->currentmode = INDIO_BUFFER_TRIGGERED;
-		} else if (indio_dev->modes & INDIO_BUFFER_HARDWARE)
-			indio_dev->currentmode = INDIO_BUFFER_HARDWARE;
-		else { /* should never be reached */
-			ret = -EINVAL;
-			goto error_ret;
-		}
-
-		if (indio_dev->setup_ops->postenable) {
-			ret = indio_dev->setup_ops->postenable(indio_dev);
-			if (ret) {
-				printk(KERN_INFO
-				       "Buffer not started: "
-				       "postenable failed\n");
-				indio_dev->currentmode = previous_mode;
-				if (indio_dev->setup_ops->postdisable)
-					indio_dev->setup_ops->
-						postdisable(indio_dev);
-				goto error_ret;
-			}
-		}
-	} else {
-		if (indio_dev->setup_ops->predisable) {
-			ret = indio_dev->setup_ops->predisable(indio_dev);
-			if (ret)
-				goto error_ret;
-		}
-		indio_dev->currentmode = INDIO_DIRECT_MODE;
-		if (indio_dev->setup_ops->postdisable) {
-			ret = indio_dev->setup_ops->postdisable(indio_dev);
-			if (ret)
-				goto error_ret;
-		}
-	}
-done:
-	mutex_unlock(&indio_dev->mlock);
-	return len;
-
-error_ret:
-	mutex_unlock(&indio_dev->mlock);
-	return ret;
-}
-EXPORT_SYMBOL(iio_buffer_store_enable);
-
 ssize_t iio_buffer_show_enable(struct device *dev,
 			       struct device_attribute *attr,
 			       char *buf)
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	return sprintf(buf, "%d\n", iio_buffer_enabled(indio_dev));
+	return sprintf(buf, "%d\n",
+		       iio_buffer_is_active(indio_dev,
+					    indio_dev->buffer));
 }
 EXPORT_SYMBOL(iio_buffer_show_enable);
 
@@ -537,35 +460,217 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask,
 	return bytes;
 }
 
-int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
+int iio_update_buffers(struct iio_dev *indio_dev,
+		       struct iio_buffer *insert_buffer,
+		       struct iio_buffer *remove_buffer)
 {
-	struct iio_buffer *buffer = indio_dev->buffer;
-	dev_dbg(&indio_dev->dev, "%s\n", __func__);
+	int ret;
+	int success = 0;
+	struct iio_buffer *buffer;
+	unsigned long *compound_mask;
+	const unsigned long *old_mask;
 
-	/* How much space will the demuxed element take? */
-	indio_dev->scan_bytes =
-		iio_compute_scan_bytes(indio_dev, buffer->scan_mask,
-				       buffer->scan_timestamp);
-	buffer->access->set_bytes_per_datum(buffer, indio_dev->scan_bytes);
+	/* Wind down existing buffers - iff there are any */
+	if (!list_empty(&indio_dev->buffer_list)) {
+		if (indio_dev->setup_ops->predisable) {
+			ret = indio_dev->setup_ops->predisable(indio_dev);
+			if (ret)
+				goto error_ret;
+		}
+		indio_dev->currentmode = INDIO_DIRECT_MODE;
+		if (indio_dev->setup_ops->postdisable) {
+			ret = indio_dev->setup_ops->postdisable(indio_dev);
+			if (ret)
+				goto error_ret;
+		}
+	}
+	/* Keep a copy of current setup to allow roll back */
+	old_mask = indio_dev->active_scan_mask;
+	if (!indio_dev->available_scan_masks)
+		indio_dev->active_scan_mask = NULL;

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 500

Quoted 10 lines
drivers/iio/industrialio-buffer.c +10 -0
+
+	if (remove_buffer)
+		list_del(&remove_buffer->buffer_list);
+	if (insert_buffer)
+		list_add(&insert_buffer->buffer_list, &indio_dev->buffer_list);
+
+	/* If no buffers in list, we are done */
+	if (list_empty(&indio_dev->buffer_list)) {
+		indio_dev->currentmode = INDIO_DIRECT_MODE;
+		return 0;

You leak old mask here, if indio_dev->available_scan_masks == NULL

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 505

Quoted 6 lines
drivers/iio/industrialio-buffer.c +3 -1
+	}
 
 	/* What scan mask do we actually have ?*/
-	if (indio_dev->available_scan_masks)
+	compound_mask = kzalloc(BITS_TO_LONGS(indio_dev->masklength)
+				*sizeof(long), GFP_KERNEL);

kcalloc

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 507

Quoted 2 lines
drivers/iio/industrialio-buffer.c +2 -0
+	if (compound_mask == NULL)
+		return -ENOMEM;

Also leaks oldmask

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 512

Quoted 5 lines
drivers/iio/industrialio-buffer.c +5 -0
+
+	list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
+		bitmap_or(compound_mask, compound_mask, buffer->scan_mask,
+			  indio_dev->masklength);
+		indio_dev->scan_timestamp |= buffer->scan_timestamp;

As far as I can see indio_dev->scan_timestamp is never set to 0, so once enabled it stays enabled.

Quoted 8 lines
drivers/iio/industrialio-buffer.c +2 -3
+	}
+	if (indio_dev->available_scan_masks) {
 		indio_dev->active_scan_mask =
 			iio_scan_mask_match(indio_dev->available_scan_masks,
 					    indio_dev->masklength,
-					    buffer->scan_mask);
-	else
-		indio_dev->active_scan_mask = buffer->scan_mask;

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 524

Quoted 10 lines
drivers/iio/industrialio-buffer.c +7 -3
-
-	if (indio_dev->active_scan_mask == NULL)
-		return -EINVAL;
+					    compound_mask);
+		if (indio_dev->active_scan_mask == NULL) {
+			/*
+			 * Roll back.
+			 * Note can only occur when adding a buffer.
+			 */
+			list_del(&insert_buffer->buffer_list);

What if insert buffer is NULL? Is it possible that we end up in this path if it is NULL?

Quoted 94 lines
drivers/iio/industrialio-buffer.c +87 -2
+			indio_dev->active_scan_mask = old_mask;
+			success = -EINVAL;
+		}
+	} else {
+		indio_dev->active_scan_mask = compound_mask;
+	}
 
 	iio_update_demux(indio_dev);
 
-	if (indio_dev->info->update_scan_mode)
-		return indio_dev->info
+	/* Wind up again */
+	if (indio_dev->setup_ops->preenable) {
+		ret = indio_dev->setup_ops->preenable(indio_dev);
+		if (ret) {
+			printk(KERN_ERR
+			       "Buffer not started:"
+			       "buffer preenable failed\n");
+			goto error_remove_inserted;
+		}
+	}
+	indio_dev->scan_bytes =
+		iio_compute_scan_bytes(indio_dev,
+				       indio_dev->active_scan_mask,
+				       indio_dev->scan_timestamp);
+	list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list)
+		if (buffer->access->request_update) {
+			ret = buffer->access->request_update(buffer);
+			if (ret) {
+				printk(KERN_INFO
+				       "Buffer not started:"
+				       "buffer parameter update failed\n");
+				goto error_run_postdisable;
+			}
+		}
+	if (indio_dev->info->update_scan_mode) {
+		ret = indio_dev->info
 			->update_scan_mode(indio_dev,
 					   indio_dev->active_scan_mask);
+		if (ret < 0) {
+			printk(KERN_INFO "update scan mode failed\n");
+			goto error_run_postdisable;
+		}
+	}
+	/* Definitely possible for devices to support both of these.*/
+	if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) {
+		if (!indio_dev->trig) {
+			printk(KERN_INFO "Buffer not started: no trigger\n");
+			ret = -EINVAL;
+			/* Can only occur on first buffer */
+			goto error_run_postdisable;
+		}
+		indio_dev->currentmode = INDIO_BUFFER_TRIGGERED;
+	} else if (indio_dev->modes & INDIO_BUFFER_HARDWARE) {
+		indio_dev->currentmode = INDIO_BUFFER_HARDWARE;
+	} else { /* should never be reached */
+		ret = -EINVAL;
+		goto error_run_postdisable;
+	}
+
+	if (indio_dev->setup_ops->postenable) {
+		ret = indio_dev->setup_ops->postenable(indio_dev);
+		if (ret) {
+			printk(KERN_INFO
+			       "Buffer not started: postenable failed\n");
+			indio_dev->currentmode = INDIO_DIRECT_MODE;
+			if (indio_dev->setup_ops->postdisable)
+				indio_dev->setup_ops->postdisable(indio_dev);
+			goto error_disable_all_buffers;
+		}
+	}
+
+	if (indio_dev->available_scan_masks)
+		kfree(compound_mask);
+	else
+		kfree(old_mask);
+
+	return success;
+
+error_disable_all_buffers:
+	indio_dev->currentmode = INDIO_DIRECT_MODE;
+error_run_postdisable:
+	if (indio_dev->setup_ops->postdisable)
+		indio_dev->setup_ops->postdisable(indio_dev);
+error_remove_inserted:
+
+	if (insert_buffer)
+		list_del(&insert_buffer->buffer_list);
+	indio_dev->active_scan_mask = old_mask;
+	kfree(compound_mask);
+error_ret:
+
+	return ret;
+}

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 626

Quoted 10 lines
drivers/iio/industrialio-buffer.c +10 -0
+EXPORT_SYMBOL_GPL(iio_update_buffers);
+
+ssize_t iio_buffer_store_enable(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf,
+				size_t len)
+{
+	int ret;
+	bool requested_state;
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);

dev_to_iio_dev

I don't think dev_get_drvdata works anymore

Quoted 7 lines
drivers/iio/industrialio-buffer.c +7 -0
+	struct iio_buffer *pbuf = indio_dev->buffer;
+	bool inlist;
+
+	ret = strtobool(buf, &requested_state);
+	if (ret < 0)
+		return ret;
+

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 643

Quoted 10 lines
drivers/iio/industrialio-buffer.c +10 -0
+	mutex_lock(&indio_dev->mlock);
+
+	/* Find out if it is in the list */
+	inlist = iio_buffer_is_active(indio_dev, pbuf);
+	/* Already enabled */
+	if (inlist && requested_state)
+		goto done;
+	/* Already disabled */
+	if (!inlist && !requested_state)
+		goto done;

if (inlist == requested_state)

	goto done;
Quoted 55 lines
drivers/iio/industrialio-buffer.c +30 -0
+
+	if (requested_state)
+		ret = iio_update_buffers(indio_dev,
+					 indio_dev->buffer, NULL);
+	else
+		ret = iio_update_buffers(indio_dev,
+					 NULL, indio_dev->buffer);
+
+	if (ret < 0)
+		goto done;
+done:
+	mutex_unlock(&indio_dev->mlock);
+	return (ret < 0) ? ret : len;
+}
+EXPORT_SYMBOL(iio_buffer_store_enable);
+
+int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
+{
+	struct iio_buffer *buffer;
+	unsigned bytes;
+	dev_dbg(&indio_dev->dev, "%s\n", __func__);
+
+	list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list)
+		if (buffer->access->set_bytes_per_datum) {
+			bytes = iio_compute_scan_bytes(indio_dev,
+						       buffer->scan_mask,
+						       buffer->scan_timestamp);
+
+			buffer->access->set_bytes_per_datum(buffer, bytes);
+		}
 	return 0;
 }
 EXPORT_SYMBOL(iio_sw_buffer_preenable);
[...]
include/linux/iio/iio.h +2 -0
index c0ae76a..0ff0e66 100644
@@ -410,6 +410,7 @@ struct iio_buffer_setup_ops {
  *			and owner
  * @event_interface:	[INTERN] event chrdevs associated with interrupt lines
  * @buffer:		[DRIVER] any buffer present
+ * @buffer_list:	[INTERN] list of all buffers currently attached
  * @scan_bytes:		[INTERN] num bytes captured to be fed to buffer demux
  * @mlock:		[INTERN] lock used to prevent simultaneous device state
  *			changes
@@ -448,6 +449,7 @@ struct iio_dev {
 	struct iio_event_interface	*event_interface;
 
 	struct iio_buffer		*buffer;
+	struct list_head		buffer_list;
 	int				scan_bytes;
 	struct mutex			mlock;
 
author maintainer
#3 lore raw

Re: [PATCH 1/4] staging:iio: Add support for multiple buffers

Quoted 5 lines · Lars-Peter Clausen
Quoted 4 lines · Jonathan Cameron

Route all buffer writes through the demux. Addition or removal of a buffer results in tear down and setup of all the buffers for a given device.

Thanks Lars!

All fixed except the case commented below where unless something really weird is going on it can't get there on removal.

Maybe it's safer to have the check anyway, but that might in turn make people think it is possible when it shouldn't be!)

Jonathan

Quoted 254 lines
Quoted 205 lines

---
[...]
/* Callback handler to send event after all samples are received and captured */

drivers/iio/industrialio-buffer.c +44 -103
index d4ad374..8caa0d7 100644
@@ -31,6 +31,18 @@ static const char * const iio_endian_prefix[] = {
 	[IIO_LE] = "le",
 };
 
+static bool iio_buffer_is_active(struct iio_dev *indio_dev,
+				 struct iio_buffer *buf)
+{
+	struct list_head *p;
+
+	list_for_each(p, &indio_dev->buffer_list)
+		if (p == &buf->buffer_list)
+			return true;
+
+	return false;
+}
+
 /**
  * iio_buffer_read_first_n_outer() - chrdev read for buffer access
  *
@@ -134,7 +146,7 @@ static ssize_t iio_scan_el_store(struct device *dev,
 	if (ret < 0)
 		return ret;
 	mutex_lock(&indio_dev->mlock);
-	if (iio_buffer_enabled(indio_dev)) {
+	if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) {
 		ret = -EBUSY;
 		goto error_ret;
 	}
@@ -180,12 +192,11 @@ static ssize_t iio_scan_el_ts_store(struct device *dev,
 		return ret;
 
 	mutex_lock(&indio_dev->mlock);
-	if (iio_buffer_enabled(indio_dev)) {
+	if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) {
 		ret = -EBUSY;
 		goto error_ret;
 	}
 	indio_dev->buffer->scan_timestamp = state;
-	indio_dev->scan_timestamp = state;
 error_ret:
 	mutex_unlock(&indio_dev->mlock);
 
@@ -385,7 +396,7 @@ ssize_t iio_buffer_write_length(struct device *dev,
 			return len;
 
 	mutex_lock(&indio_dev->mlock);
-	if (iio_buffer_enabled(indio_dev)) {
+	if (iio_buffer_is_active(indio_dev, indio_dev->buffer)) {
 		ret = -EBUSY;
 	} else {
 		if (buffer->access->set_length)
@@ -398,102 +409,14 @@ ssize_t iio_buffer_write_length(struct device *dev,
 }
 EXPORT_SYMBOL(iio_buffer_write_length);
 
-ssize_t iio_buffer_store_enable(struct device *dev,
-				struct device_attribute *attr,
-				const char *buf,
-				size_t len)
-{
-	int ret;
-	bool requested_state, current_state;
-	int previous_mode;
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct iio_buffer *buffer = indio_dev->buffer;
-
-	mutex_lock(&indio_dev->mlock);
-	previous_mode = indio_dev->currentmode;
-	requested_state = !(buf[0] == '0');
-	current_state = iio_buffer_enabled(indio_dev);
-	if (current_state == requested_state) {
-		printk(KERN_INFO "iio-buffer, current state requested again\n");
-		goto done;
-	}
-	if (requested_state) {
-		if (indio_dev->setup_ops->preenable) {
-			ret = indio_dev->setup_ops->preenable(indio_dev);
-			if (ret) {
-				printk(KERN_ERR
-				       "Buffer not started: "
-				       "buffer preenable failed\n");
-				goto error_ret;
-			}
-		}
-		if (buffer->access->request_update) {
-			ret = buffer->access->request_update(buffer);
-			if (ret) {
-				printk(KERN_INFO
-				       "Buffer not started: "
-				       "buffer parameter update failed\n");
-				goto error_ret;
-			}
-		}
-		/* Definitely possible for devices to support both of these. */
-		if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) {
-			if (!indio_dev->trig) {
-				printk(KERN_INFO
-				       "Buffer not started: no trigger\n");
-				ret = -EINVAL;
-				goto error_ret;
-			}
-			indio_dev->currentmode = INDIO_BUFFER_TRIGGERED;
-		} else if (indio_dev->modes & INDIO_BUFFER_HARDWARE)
-			indio_dev->currentmode = INDIO_BUFFER_HARDWARE;
-		else { /* should never be reached */
-			ret = -EINVAL;
-			goto error_ret;
-		}
-
-		if (indio_dev->setup_ops->postenable) {
-			ret = indio_dev->setup_ops->postenable(indio_dev);
-			if (ret) {
-				printk(KERN_INFO
-				       "Buffer not started: "
-				       "postenable failed\n");
-				indio_dev->currentmode = previous_mode;
-				if (indio_dev->setup_ops->postdisable)
-					indio_dev->setup_ops->
-						postdisable(indio_dev);
-				goto error_ret;
-			}
-		}
-	} else {
-		if (indio_dev->setup_ops->predisable) {
-			ret = indio_dev->setup_ops->predisable(indio_dev);
-			if (ret)
-				goto error_ret;
-		}
-		indio_dev->currentmode = INDIO_DIRECT_MODE;
-		if (indio_dev->setup_ops->postdisable) {
-			ret = indio_dev->setup_ops->postdisable(indio_dev);
-			if (ret)
-				goto error_ret;
-		}
-	}
-done:
-	mutex_unlock(&indio_dev->mlock);
-	return len;
-
-error_ret:
-	mutex_unlock(&indio_dev->mlock);
-	return ret;
-}
-EXPORT_SYMBOL(iio_buffer_store_enable);
-
 ssize_t iio_buffer_show_enable(struct device *dev,
 			       struct device_attribute *attr,
 			       char *buf)
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	return sprintf(buf, "%d\n", iio_buffer_enabled(indio_dev));
+	return sprintf(buf, "%d\n",
+		       iio_buffer_is_active(indio_dev,
+					    indio_dev->buffer));
 }
 EXPORT_SYMBOL(iio_buffer_show_enable);
 
@@ -537,35 +460,217 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask,
 	return bytes;
 }
 
-int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
+int iio_update_buffers(struct iio_dev *indio_dev,
+		       struct iio_buffer *insert_buffer,
+		       struct iio_buffer *remove_buffer)
 {
-	struct iio_buffer *buffer = indio_dev->buffer;
-	dev_dbg(&indio_dev->dev, "%s\n", __func__);
+	int ret;
+	int success = 0;
+	struct iio_buffer *buffer;
+	unsigned long *compound_mask;
+	const unsigned long *old_mask;
 
-	/* How much space will the demuxed element take? */
-	indio_dev->scan_bytes =
-		iio_compute_scan_bytes(indio_dev, buffer->scan_mask,
-				       buffer->scan_timestamp);
-	buffer->access->set_bytes_per_datum(buffer, indio_dev->scan_bytes);
+	/* Wind down existing buffers - iff there are any */
+	if (!list_empty(&indio_dev->buffer_list)) {
+		if (indio_dev->setup_ops->predisable) {
+			ret = indio_dev->setup_ops->predisable(indio_dev);
+			if (ret)
+				goto error_ret;
+		}
+		indio_dev->currentmode = INDIO_DIRECT_MODE;
+		if (indio_dev->setup_ops->postdisable) {
+			ret = indio_dev->setup_ops->postdisable(indio_dev);
+			if (ret)
+				goto error_ret;
+		}
+	}
+	/* Keep a copy of current setup to allow roll back */
+	old_mask = indio_dev->active_scan_mask;
+	if (!indio_dev->available_scan_masks)
+		indio_dev->active_scan_mask = NULL;

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 500

Quoted 10 lines
drivers/iio/industrialio-buffer.c +10 -0
+
+	if (remove_buffer)
+		list_del(&remove_buffer->buffer_list);
+	if (insert_buffer)
+		list_add(&insert_buffer->buffer_list, &indio_dev->buffer_list);
+
+	/* If no buffers in list, we are done */
+	if (list_empty(&indio_dev->buffer_list)) {
+		indio_dev->currentmode = INDIO_DIRECT_MODE;
+		return 0;

You leak old mask here, if indio_dev->available_scan_masks == NULL

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 505

Quoted 6 lines
drivers/iio/industrialio-buffer.c +3 -1
+	}
 
 	/* What scan mask do we actually have ?*/
-	if (indio_dev->available_scan_masks)
+	compound_mask = kzalloc(BITS_TO_LONGS(indio_dev->masklength)
+				*sizeof(long), GFP_KERNEL);

kcalloc

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 507

Quoted 2 lines
drivers/iio/industrialio-buffer.c +2 -0
+	if (compound_mask == NULL)
+		return -ENOMEM;

Also leaks oldmask

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 512

Quoted 5 lines
drivers/iio/industrialio-buffer.c +5 -0
+
+	list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
+		bitmap_or(compound_mask, compound_mask, buffer->scan_mask,
+			  indio_dev->masklength);
+		indio_dev->scan_timestamp |= buffer->scan_timestamp;

As far as I can see indio_dev->scan_timestamp is never set to 0, so once enabled it stays enabled.

Quoted 13 lines
drivers/iio/industrialio-buffer.c +4 -6
+	}
+	if (indio_dev->available_scan_masks) {
 		indio_dev->active_scan_mask =
 			iio_scan_mask_match(indio_dev->available_scan_masks,
 					    indio_dev->masklength,
-					    buffer->scan_mask);
-	else
-		indio_dev->active_scan_mask = buffer->scan_mask;
-
-	if (indio_dev->active_scan_mask == NULL)
-		return -EINVAL;
+					    compound_mask);
+		if (indio_dev->active_scan_mask == NULL) {
Quoted 8 lines

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 524

Quoted 5 lines
drivers/iio/industrialio-buffer.c +5 -0
+			/*
+			 * Roll back.
+			 * Note can only occur when adding a buffer.
+			 */
+			list_del(&insert_buffer->buffer_list);

What if insert buffer is NULL? Is it possible that we end up in this path if it is NULL?

I don't think there is anyway we could go from a valid scan mask to there not being one that exists (e.g. on removal of a buffer). Afterall the scan mask with the buffer there covers all desired channels so it still will after the buffer is removed.

Quoted 108 lines
Quoted 95 lines
drivers/iio/industrialio-buffer.c +87 -2
+			indio_dev->active_scan_mask = old_mask;
+			success = -EINVAL;
+		}
+	} else {
+		indio_dev->active_scan_mask = compound_mask;
+	}
 
 	iio_update_demux(indio_dev);
 
-	if (indio_dev->info->update_scan_mode)
-		return indio_dev->info
+	/* Wind up again */
+	if (indio_dev->setup_ops->preenable) {
+		ret = indio_dev->setup_ops->preenable(indio_dev);
+		if (ret) {
+			printk(KERN_ERR
+			       "Buffer not started:"
+			       "buffer preenable failed\n");
+			goto error_remove_inserted;
+		}
+	}
+	indio_dev->scan_bytes =
+		iio_compute_scan_bytes(indio_dev,
+				       indio_dev->active_scan_mask,
+				       indio_dev->scan_timestamp);
+	list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list)
+		if (buffer->access->request_update) {
+			ret = buffer->access->request_update(buffer);
+			if (ret) {
+				printk(KERN_INFO
+				       "Buffer not started:"
+				       "buffer parameter update failed\n");
+				goto error_run_postdisable;
+			}
+		}
+	if (indio_dev->info->update_scan_mode) {
+		ret = indio_dev->info
 			->update_scan_mode(indio_dev,
 					   indio_dev->active_scan_mask);
+		if (ret < 0) {
+			printk(KERN_INFO "update scan mode failed\n");
+			goto error_run_postdisable;
+		}
+	}
+	/* Definitely possible for devices to support both of these.*/
+	if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) {
+		if (!indio_dev->trig) {
+			printk(KERN_INFO "Buffer not started: no trigger\n");
+			ret = -EINVAL;
+			/* Can only occur on first buffer */
+			goto error_run_postdisable;
+		}
+		indio_dev->currentmode = INDIO_BUFFER_TRIGGERED;
+	} else if (indio_dev->modes & INDIO_BUFFER_HARDWARE) {
+		indio_dev->currentmode = INDIO_BUFFER_HARDWARE;
+	} else { /* should never be reached */
+		ret = -EINVAL;
+		goto error_run_postdisable;
+	}
+
+	if (indio_dev->setup_ops->postenable) {
+		ret = indio_dev->setup_ops->postenable(indio_dev);
+		if (ret) {
+			printk(KERN_INFO
+			       "Buffer not started: postenable failed\n");
+			indio_dev->currentmode = INDIO_DIRECT_MODE;
+			if (indio_dev->setup_ops->postdisable)
+				indio_dev->setup_ops->postdisable(indio_dev);
+			goto error_disable_all_buffers;
+		}
+	}
+
+	if (indio_dev->available_scan_masks)
+		kfree(compound_mask);
+	else
+		kfree(old_mask);
+
+	return success;
+
+error_disable_all_buffers:
+	indio_dev->currentmode = INDIO_DIRECT_MODE;
+error_run_postdisable:
+	if (indio_dev->setup_ops->postdisable)
+		indio_dev->setup_ops->postdisable(indio_dev);
+error_remove_inserted:
+
+	if (insert_buffer)
+		list_del(&insert_buffer->buffer_list);
+	indio_dev->active_scan_mask = old_mask;
+	kfree(compound_mask);
+error_ret:
+
+	return ret;
+}

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 626

Quoted 10 lines
drivers/iio/industrialio-buffer.c +10 -0
+EXPORT_SYMBOL_GPL(iio_update_buffers);
+
+ssize_t iio_buffer_store_enable(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf,
+				size_t len)
+{
+	int ret;
+	bool requested_state;
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);

dev_to_iio_dev

Quoted 1 line

I don't think dev_get_drvdata works anymore

oops.. :)

Quoted 20 lines
Quoted 8 lines
drivers/iio/industrialio-buffer.c +7 -0
+	struct iio_buffer *pbuf = indio_dev->buffer;
+	bool inlist;
+
+	ret = strtobool(buf, &requested_state);
+	if (ret < 0)
+		return ret;
+

drivers/iio/industrialio-buffer.c static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, · line 643

Quoted 10 lines
drivers/iio/industrialio-buffer.c +10 -0
+	mutex_lock(&indio_dev->mlock);
+
+	/* Find out if it is in the list */
+	inlist = iio_buffer_is_active(indio_dev, pbuf);
+	/* Already enabled */
+	if (inlist && requested_state)
+		goto done;
+	/* Already disabled */
+	if (!inlist && !requested_state)
+		goto done;

if (inlist == requested_state)

Quoted 1 line
	goto done;

oops again. I like to think it evolved to this state, but maybe I was just being an idiot ;)

Quoted 62 lines
Quoted 49 lines
drivers/iio/industrialio-buffer.c +30 -0
+
+	if (requested_state)
+		ret = iio_update_buffers(indio_dev,
+					 indio_dev->buffer, NULL);
+	else
+		ret = iio_update_buffers(indio_dev,
+					 NULL, indio_dev->buffer);
+
+	if (ret < 0)
+		goto done;
+done:
+	mutex_unlock(&indio_dev->mlock);
+	return (ret < 0) ? ret : len;
+}
+EXPORT_SYMBOL(iio_buffer_store_enable);
+
+int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
+{
+	struct iio_buffer *buffer;
+	unsigned bytes;
+	dev_dbg(&indio_dev->dev, "%s\n", __func__);
+
+	list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list)
+		if (buffer->access->set_bytes_per_datum) {
+			bytes = iio_compute_scan_bytes(indio_dev,
+						       buffer->scan_mask,
+						       buffer->scan_timestamp);
+
+			buffer->access->set_bytes_per_datum(buffer, bytes);
+		}
 	return 0;
 }
 EXPORT_SYMBOL(iio_sw_buffer_preenable);
[...]
include/linux/iio/iio.h +1 -0
index c0ae76a..0ff0e66 100644
@@ -410,6 +410,7 @@ struct iio_buffer_setup_ops {
  *			and owner
  * @event_interface:	[INTERN] event chrdevs associated with interrupt lines
  * @buffer:		[DRIVER] any buffer present
+ * @buffer_list:	[INTERN] list of all buffers currently attached
  * @scan_bytes:		[INTERN] num bytes captured to be fed to buffer demux
  * @mlock:		[INTERN] lock used to prevent simultaneous device state
  *			changes

include/linux/iio/iio.h struct iio_dev { · line 455

Quoted 7 lines
include/linux/iio/iio.h +1 -0
@@ -448,6 +449,7 @@ struct iio_dev {
 	struct iio_event_interface	*event_interface;
 
 	struct iio_buffer		*buffer;
+	struct list_head		buffer_list;
 	int				scan_bytes;
 	struct mutex			mlock;
 

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#4 lore raw

PATCH v5 2/4 staging:iio:in kernel users: Add a data field for channel specific info.

In reply to Jonathan Cameron

Used to allow information about a given channel mapping to be passed through from board files to the consumer drivers.

---
 drivers/iio/inkern.c         | 1 +
 include/linux/iio/consumer.h | 2 ++
 include/linux/iio/machine.h  | 2 ++
 3 files changed, 5 insertions(+)
drivers/iio/inkern.c +1 -0
index f2b78d4..4113105 100644
@@ -203,6 +203,7 @@ struct iio_channel *iio_channel_get_all(const char *name)
 		if (name && strcmp(name, c->map->consumer_dev_name) != 0)
 			continue;
 		chans[mapind].indio_dev = c->indio_dev;
+		chans[mapind].data = c->map->consumer_data;
 		chans[mapind].channel =
 			iio_chan_spec_from_name(chans[mapind].indio_dev,
 						c->map->adc_channel_label);
include/linux/iio/consumer.h +2 -0
index e875bcf..57efee6 100644
@@ -18,10 +18,12 @@ struct iio_chan_spec;
  * struct iio_channel - everything needed for a consumer to use a channel
  * @indio_dev:		Device on which the channel exists.
  * @channel:		Full description of the channel.
+ * @data:		Data about the channel used by consumer.
  */
 struct iio_channel {
 	struct iio_dev *indio_dev;
 	const struct iio_chan_spec *channel;
+	void *data;
 };
 
 /**
include/linux/iio/machine.h +2 -0
index 809a3f0..1601a2a 100644
@@ -19,11 +19,13 @@
  * @consumer_dev_name:	Name to uniquely identify the consumer device.
  * @consumer_channel:	Unique name used to identify the channel on the
  *			consumer side.
+ * @consumer_data:	Data about the channel for use by the consumer driver.
  */
 struct iio_map {
 	const char *adc_channel_label;
 	const char *consumer_dev_name;
 	const char *consumer_channel;
+	void *consumer_data;
 };
 
 #endif
Signature · 1 line
1.7.12.2
author maintainer
#5 lore raw

PATCH v5 3/4 staging:iio: add a callback buffer for in kernel push interface

In reply to Jonathan Cameron

This callback buffer is meant to be opaque to users, but basically adds a very simple pass through buffer to which data may be pushed when it is inserted into the buffer list.

---
 drivers/iio/Kconfig          |   6 +++
 drivers/iio/Makefile         |   1 +
 drivers/iio/buffer_cb.c      | 113 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/iio/consumer.h |  46 ++++++++++++++++++
 4 files changed, 166 insertions(+)
drivers/iio/Kconfig +6 -0
index 6e3f143..0aad08a 100644
@@ -20,6 +20,12 @@ config IIO_BUFFER
 
 if IIO_BUFFER
 
+config IIO_BUFFER_CB
+       boolean "IIO callback buffer used for push in kernel interfaces"
+       help
+         Should be selected by any drivers that do inkernel push
+	 usage.  That is, those where the data is pushed to the consumer.
+
 config IIO_KFIFO_BUF
 	select IIO_TRIGGER
 	tristate "Industrial I/O buffering based on kfifo"
drivers/iio/Makefile +1 -0
index f7fa3c0..a27ec1c 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_IIO) += industrialio.o
 industrialio-y := industrialio-core.o industrialio-event.o inkern.o
 industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
 industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
+industrialio-$(CONFIG_IIO_BUFFER_CB) += buffer_cb.o
 
 obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
 obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
drivers/iio/buffer_cb.c new file +113 -0

113 lines not on this page · raw message

include/linux/iio/consumer.h +46 -0

52 lines not on this page · raw message

Signature · 1 line
1.7.12.2
#6 lore raw

Re: [PATCH 3/4] staging:iio: add a callback buffer for in kernel push interface

Quoted 17 lines · Jonathan Cameron

This callback buffer is meant to be opaque to users, but basically adds a very simple pass through buffer to which data may be pushed when it is inserted into the buffer list.

---
 drivers/iio/Kconfig          |   6 +++
 drivers/iio/Makefile         |   1 +
 drivers/iio/buffer_cb.c      | 113 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/iio/consumer.h |  46 ++++++++++++++++++
 4 files changed, 166 insertions(+)
drivers/iio/Kconfig +0 -0
index 6e3f143..0aad08a 100644

drivers/iio/Kconfig config IIO_BUFFER · line 24

Quoted 5 lines
drivers/iio/Kconfig +2 -0
@@ -20,6 +20,12 @@ config IIO_BUFFER
 
 if IIO_BUFFER
 
+config IIO_BUFFER_CB
+       boolean "IIO callback buffer used for push in kernel interfaces"

Any specific reason why this has to be bool?

Quoted 53 lines
drivers/iio/Kconfig +4 -0
+       help
+         Should be selected by any drivers that do inkernel push
+	 usage.  That is, those where the data is pushed to the consumer.
+
 config IIO_KFIFO_BUF
 	select IIO_TRIGGER
 	tristate "Industrial I/O buffering based on kfifo"
drivers/iio/Makefile +1 -0
index f7fa3c0..a27ec1c 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_IIO) += industrialio.o
 industrialio-y := industrialio-core.o industrialio-event.o inkern.o
 industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
 industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
+industrialio-$(CONFIG_IIO_BUFFER_CB) += buffer_cb.o
 
 obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
 obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
drivers/iio/buffer_cb.c new file +28 -0
new file mode 100644
index 0000000..d1e4881
@@ -0,0 +1,113 @@
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/consumer.h>
+
+struct iio_cb_buffer {
+	struct iio_buffer buffer;
+	int (*cb)(u8 *data, void *private);
+	void *private;
+	struct iio_channel *channels;
+};
+
+static int iio_buffer_cb_store_to(struct iio_buffer *buffer, u8 *data)
+{
+	struct iio_cb_buffer *cb_buff = container_of(buffer,
+						     struct iio_cb_buffer,
+						     buffer);
+
+	return cb_buff->cb(data, cb_buff->private);
+}
+
+static struct iio_buffer_access_funcs iio_cb_access = {
+	.store_to = &iio_buffer_cb_store_to,
+};
+
+struct iio_cb_buffer *iio_channel_get_all_cb(const char *name,

drivers/iio/buffer_cb.c line 38

Quoted 10 lines
drivers/iio/buffer_cb.c new file +10 -0
+					     int (*cb)(u8 *data,
+						       void *private),
+					     void *private)
+{
+	int ret;
+	struct iio_cb_buffer *cb_buff;
+	struct iio_dev *indio_dev;
+	struct iio_channel *chan;
+
+	cb_buff = kzalloc(sizeof *cb_buff, GFP_KERNEL);

sizeof(*cb_buff)

drivers/iio/buffer_cb.c line 47

Quoted 9 lines
drivers/iio/buffer_cb.c new file +9 -0
+	if (cb_buff == NULL) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+
+	cb_buff->private = private;
+	cb_buff->cb = cb;
+	cb_buff->buffer.access = &iio_cb_access;
+	INIT_LIST_HEAD(&cb_buff->buffer.demux_list);

It probably makes sense to have some kind of iio_buffer_init(...) for this

drivers/iio/buffer_cb.c line 58

Quoted 11 lines
drivers/iio/buffer_cb.c new file +11 -0
+
+	cb_buff->channels = iio_channel_get_all(name);
+	if (IS_ERR(cb_buff->channels)) {
+		ret = PTR_ERR(cb_buff->channels);
+		goto error_free_cb_buff;
+	}
+
+	indio_dev = cb_buff->channels[0].indio_dev;
+	cb_buff->buffer.scan_mask
+		= kzalloc(sizeof(long)*BITS_TO_LONGS(indio_dev->masklength),
+			  GFP_KERNEL);

kcalloc

Quoted 112 lines
drivers/iio/buffer_cb.c new file +55 -0
+	if (cb_buff->buffer.scan_mask == NULL) {
+		ret = -ENOMEM;
+		goto error_release_channels;
+	}
+	chan = &cb_buff->channels[0];
+	while (chan->indio_dev) {
+		if (chan->indio_dev != indio_dev) {
+			ret = -EINVAL;
+			goto error_release_channels;
+		}
+		set_bit(chan->channel->scan_index,
+			cb_buff->buffer.scan_mask);
+		chan++;
+	}
+
+	return cb_buff;
+
+error_release_channels:
+	iio_channel_release_all(cb_buff->channels);
+error_free_cb_buff:
+	kfree(cb_buff);
+error_ret:
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(iio_channel_get_all_cb);
+
+int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff)
+{
+	return iio_update_buffers(cb_buff->channels[0].indio_dev,
+				  &cb_buff->buffer,
+				  NULL);
+}
+EXPORT_SYMBOL_GPL(iio_channel_start_all_cb);
+
+void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff)
+{
+	iio_update_buffers(cb_buff->channels[0].indio_dev,
+			   NULL,
+			   &cb_buff->buffer);
+}
+EXPORT_SYMBOL_GPL(iio_channel_stop_all_cb);
+
+void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buff)
+{
+	iio_channel_release_all(cb_buff->channels);
+	kfree(cb_buff);
+}
+EXPORT_SYMBOL_GPL(iio_channel_release_all_cb);
+
+struct iio_channel
+*iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer)
+{
+	return cb_buffer->channels;
+}
+EXPORT_SYMBOL_GPL(iio_channel_cb_get_channels);
include/linux/iio/consumer.h +46 -0
index 57efee6..caf103b 100644
@@ -61,6 +61,52 @@ struct iio_channel *iio_channel_get_all(const char *name);
  */
 void iio_channel_release_all(struct iio_channel *chan);
 
+struct iio_cb_buffer;
+/**
+ * iio_channel_get_all_cb() - register callback for triggered capture
+ * @name:		Name of client device.
+ * @cb:			Callback function.
+ * @private:		Private data passed to callback.
+ *
+ * NB right now we have no ability to mux data from multiple devices.
+ * So if the channels requested come from different devices this will
+ * fail.
+ */
+struct iio_cb_buffer *iio_channel_get_all_cb(const char *name,
+					     int (*cb)(u8 *data,
+						       void *private),
+					     void *private);
+/**
+ * iio_channel_release_all_cb() - release and unregister the callback.
+ * @cb_buffer:		The callback buffer that was allocated.
+ */
+void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buffer);
+
+/**
+ * iio_channel_start_all_cb() - start the flow of data through callback.
+ * @cb_buff:		The callback buffer we are starting.
+ */
+int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff);
+
+/**
+ * iio_channel_stop_all_cb() - stop the flow of data through the callback.
+ * @cb_buff:		The callback buffer we are stopping.
+ */
+void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff);
+
+/**
+ * iio_channel_cb_get_channels() - get access to the underlying channels.
+ * @cb_buff:		The callback buffers from whom we want the channel
+ *			information.
+ *
+ * This function allows one to obtain information about the channels.
+ * Whilst this may allow direct reading if all buffers are disabled, the
+ * primary aim is to allow drivers that are consuming a channel to query
+ * things like scaling of the channel.
+ */
+struct iio_channel
+*iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer);
+
 /**
  * iio_read_channel_raw() - read from a given channel
  * @chan:		The channel being queried.
#7 lore raw

Re: [PATCH 3/4] staging:iio: add a callback buffer for in kernel push interface

Quoted 19 lines · Lars-Peter Clausen
Quoted 18 lines · Jonathan Cameron

This callback buffer is meant to be opaque to users, but basically adds a very simple pass through buffer to which data may be pushed when it is inserted into the buffer list.

---
  drivers/iio/Kconfig          |   6 +++
  drivers/iio/Makefile         |   1 +
  drivers/iio/buffer_cb.c      | 113 +++++++++++++++++++++++++++++++++++++++++++
  include/linux/iio/consumer.h |  46 ++++++++++++++++++
  4 files changed, 166 insertions(+)
drivers/iio/Kconfig +0 -0
index 6e3f143..0aad08a 100644
@@ -20,6 +20,12 @@ config IIO_BUFFER
 
Quoted 6 lines

drivers/iio/Kconfig config IIO_BUFFER · line 24

Quoted 4 lines
drivers/iio/Kconfig +2 -0
  if IIO_BUFFER
 
+config IIO_BUFFER_CB
+       boolean "IIO callback buffer used for push in kernel interfaces"

Any specific reason why this has to be bool?

Doesn't have it's own module as it's so small. Gets built in to the core.

Agreed to all the rest. Thanks for looking at these.

Quoted 211 lines
Quoted 54 lines
drivers/iio/Kconfig +4 -0
+       help
+         Should be selected by any drivers that do inkernel push
+	 usage.  That is, those where the data is pushed to the consumer.
+
  config IIO_KFIFO_BUF
  	select IIO_TRIGGER
  	tristate "Industrial I/O buffering based on kfifo"
drivers/iio/Makefile +1 -0
index f7fa3c0..a27ec1c 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_IIO) += industrialio.o
  industrialio-y := industrialio-core.o industrialio-event.o inkern.o
  industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
  industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
+industrialio-$(CONFIG_IIO_BUFFER_CB) += buffer_cb.o
 
  obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
  obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
drivers/iio/buffer_cb.c new file +28 -0
new file mode 100644
index 0000000..d1e4881
@@ -0,0 +1,113 @@
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/consumer.h>
+
+struct iio_cb_buffer {
+	struct iio_buffer buffer;
+	int (*cb)(u8 *data, void *private);
+	void *private;
+	struct iio_channel *channels;
+};
+
+static int iio_buffer_cb_store_to(struct iio_buffer *buffer, u8 *data)
+{
+	struct iio_cb_buffer *cb_buff = container_of(buffer,
+						     struct iio_cb_buffer,
+						     buffer);
+
+	return cb_buff->cb(data, cb_buff->private);
+}
+
+static struct iio_buffer_access_funcs iio_cb_access = {
+	.store_to = &iio_buffer_cb_store_to,
+};
+
+struct iio_cb_buffer *iio_channel_get_all_cb(const char *name,

drivers/iio/buffer_cb.c line 38

Quoted 10 lines
drivers/iio/buffer_cb.c new file +10 -0
+					     int (*cb)(u8 *data,
+						       void *private),
+					     void *private)
+{
+	int ret;
+	struct iio_cb_buffer *cb_buff;
+	struct iio_dev *indio_dev;
+	struct iio_channel *chan;
+
+	cb_buff = kzalloc(sizeof *cb_buff, GFP_KERNEL);

sizeof(*cb_buff)

drivers/iio/buffer_cb.c line 47

Quoted 9 lines
drivers/iio/buffer_cb.c new file +9 -0
+	if (cb_buff == NULL) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+
+	cb_buff->private = private;
+	cb_buff->cb = cb;
+	cb_buff->buffer.access = &iio_cb_access;
+	INIT_LIST_HEAD(&cb_buff->buffer.demux_list);

It probably makes sense to have some kind of iio_buffer_init(...) for this

drivers/iio/buffer_cb.c line 58

Quoted 11 lines
drivers/iio/buffer_cb.c new file +11 -0
+
+	cb_buff->channels = iio_channel_get_all(name);
+	if (IS_ERR(cb_buff->channels)) {
+		ret = PTR_ERR(cb_buff->channels);
+		goto error_free_cb_buff;
+	}
+
+	indio_dev = cb_buff->channels[0].indio_dev;
+	cb_buff->buffer.scan_mask
+		= kzalloc(sizeof(long)*BITS_TO_LONGS(indio_dev->masklength),
+			  GFP_KERNEL);

kcalloc

Quoted 102 lines
drivers/iio/buffer_cb.c new file +55 -0
+	if (cb_buff->buffer.scan_mask == NULL) {
+		ret = -ENOMEM;
+		goto error_release_channels;
+	}
+	chan = &cb_buff->channels[0];
+	while (chan->indio_dev) {
+		if (chan->indio_dev != indio_dev) {
+			ret = -EINVAL;
+			goto error_release_channels;
+		}
+		set_bit(chan->channel->scan_index,
+			cb_buff->buffer.scan_mask);
+		chan++;
+	}
+
+	return cb_buff;
+
+error_release_channels:
+	iio_channel_release_all(cb_buff->channels);
+error_free_cb_buff:
+	kfree(cb_buff);
+error_ret:
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(iio_channel_get_all_cb);
+
+int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff)
+{
+	return iio_update_buffers(cb_buff->channels[0].indio_dev,
+				  &cb_buff->buffer,
+				  NULL);
+}
+EXPORT_SYMBOL_GPL(iio_channel_start_all_cb);
+
+void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff)
+{
+	iio_update_buffers(cb_buff->channels[0].indio_dev,
+			   NULL,
+			   &cb_buff->buffer);
+}
+EXPORT_SYMBOL_GPL(iio_channel_stop_all_cb);
+
+void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buff)
+{
+	iio_channel_release_all(cb_buff->channels);
+	kfree(cb_buff);
+}
+EXPORT_SYMBOL_GPL(iio_channel_release_all_cb);
+
+struct iio_channel
+*iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer)
+{
+	return cb_buffer->channels;
+}
+EXPORT_SYMBOL_GPL(iio_channel_cb_get_channels);
include/linux/iio/consumer.h +39 -0
index 57efee6..caf103b 100644
@@ -61,6 +61,52 @@ struct iio_channel *iio_channel_get_all(const char *name);
   */
  void iio_channel_release_all(struct iio_channel *chan);
 
+struct iio_cb_buffer;
+/**
+ * iio_channel_get_all_cb() - register callback for triggered capture
+ * @name:		Name of client device.
+ * @cb:			Callback function.
+ * @private:		Private data passed to callback.
+ *
+ * NB right now we have no ability to mux data from multiple devices.
+ * So if the channels requested come from different devices this will
+ * fail.
+ */
+struct iio_cb_buffer *iio_channel_get_all_cb(const char *name,
+					     int (*cb)(u8 *data,
+						       void *private),
+					     void *private);
+/**
+ * iio_channel_release_all_cb() - release and unregister the callback.
+ * @cb_buffer:		The callback buffer that was allocated.
+ */
+void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buffer);
+
+/**
+ * iio_channel_start_all_cb() - start the flow of data through callback.
+ * @cb_buff:		The callback buffer we are starting.
+ */
+int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff);
+
+/**
+ * iio_channel_stop_all_cb() - stop the flow of data through the callback.
+ * @cb_buff:		The callback buffer we are stopping.
+ */
+void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff);
+
+/**
+ * iio_channel_cb_get_channels() - get access to the underlying channels.
+ * @cb_buff:		The callback buffers from whom we want the channel
+ *			information.
+ *
+ * This function allows one to obtain information about the channels.

include/linux/iio/consumer.h struct iio_channel *iio_channel_get_all(const char *name); · line 112

Quoted 10 lines
include/linux/iio/consumer.h +7 -0
+ * Whilst this may allow direct reading if all buffers are disabled, the
+ * primary aim is to allow drivers that are consuming a channel to query
+ * things like scaling of the channel.
+ */
+struct iio_channel
+*iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer);
+
  /**
   * iio_read_channel_raw() - read from a given channel
   * @chan:		The channel being queried.

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#8 lore raw

PATCH v5 4/4 staging:iio: Proof of concept input driver.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This is no where near ready to merge. Lots of stuff missing.

---
 drivers/staging/iio/Kconfig     |  11 ++
 drivers/staging/iio/Makefile    |   1 +
 drivers/staging/iio/iio_input.c | 225 ++++++++++++++++++++++++++++++++++++++++
 drivers/staging/iio/iio_input.h |  23 ++++
 4 files changed, 260 insertions(+)
drivers/staging/iio/Kconfig +11 -0
index ca56c75..3d21f6d 100644
@@ -4,6 +4,17 @@
 menu "IIO staging drivers"
 	depends on IIO
 
+config IIO_ST_INPUT
+	tristate "Input driver that uses channels specified via iio maps"
+	depends on INPUT
+	depends on IIO_BUFFER
+	select IIO_BUFFER_CB
+	help
+	  Client driver for IIO via the push interfaces.  Used to provide
+	  and input interface for IIO devices that can feed a buffer on
+	  a trigger interrupt.  Note that all channels must come from a
+	  single IIO supported device.
+
 config IIO_ST_HWMON
 	tristate "Hwmon driver that uses channels specified via iio maps"
 	depends on HWMON
drivers/staging/iio/Makefile +1 -0
index fa6937d..9e71498 100644
@@ -12,6 +12,7 @@ iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_BUFFER) += iio_simple_dummy_buffer.o
 obj-$(CONFIG_IIO_DUMMY_EVGEN) += iio_dummy_evgen.o
 
 obj-$(CONFIG_IIO_ST_HWMON) += iio_hwmon.o
+obj-$(CONFIG_IIO_ST_INPUT) += iio_input.o
 
 obj-y += accel/
 obj-y += adc/
drivers/staging/iio/iio_input.c new file +225 -0

225 lines not on this page · raw message

drivers/staging/iio/iio_input.h new file +23 -0
new file mode 100644
index 0000000..cfd1d34
@@ -0,0 +1,23 @@
+/*
+ * The industrial I/O input client driver
+ *
+ * Copyright (c) 2011 Jonathan Cameron
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+/**
+ * iio_input_channel_data - description of the channel for input subsystem
+ * @code:	Absolute axis.
+ * @min:	Minimum value.
+ * @max:	Maximum value.
+ * @fuzz:	Used to filter noise from the event stream.
+ * @flat:	Values within this value will be discarded by joydev
+ *		and reported as 0 instead.
+ */
+struct iio_input_channel_data {
+	unsigned int code;
+	int min, max, fuzz, flat;
+};
Signature · 1 line
1.7.12.2
author maintainer
#9 lore raw

Re: [PATCH 4/4] staging:iio: Proof of concept input driver.

Quoted 3 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

This is no where near ready to merge. Lots of stuff missing.

It also contains an issue with using the input dev after freeing that has already been reported. Naughty me - I forgot about that one.

Doesn't effect the usefulness of this as a test tool though!

Quoted 304 lines
---
 drivers/staging/iio/Kconfig     |  11 ++
 drivers/staging/iio/Makefile    |   1 +
 drivers/staging/iio/iio_input.c | 225 ++++++++++++++++++++++++++++++++++++++++
 drivers/staging/iio/iio_input.h |  23 ++++
 4 files changed, 260 insertions(+)
drivers/staging/iio/Kconfig +11 -0
index ca56c75..3d21f6d 100644
@@ -4,6 +4,17 @@
 menu "IIO staging drivers"
 	depends on IIO
 
+config IIO_ST_INPUT
+	tristate "Input driver that uses channels specified via iio maps"
+	depends on INPUT
+	depends on IIO_BUFFER
+	select IIO_BUFFER_CB
+	help
+	  Client driver for IIO via the push interfaces.  Used to provide
+	  and input interface for IIO devices that can feed a buffer on
+	  a trigger interrupt.  Note that all channels must come from a
+	  single IIO supported device.
+
 config IIO_ST_HWMON
 	tristate "Hwmon driver that uses channels specified via iio maps"
 	depends on HWMON
drivers/staging/iio/Makefile +1 -0
index fa6937d..9e71498 100644
@@ -12,6 +12,7 @@ iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_BUFFER) += iio_simple_dummy_buffer.o
 obj-$(CONFIG_IIO_DUMMY_EVGEN) += iio_dummy_evgen.o
 
 obj-$(CONFIG_IIO_ST_HWMON) += iio_hwmon.o
+obj-$(CONFIG_IIO_ST_INPUT) += iio_input.o
 
 obj-y += accel/
 obj-y += adc/
drivers/staging/iio/iio_input.c new file +225 -0
new file mode 100644
index 0000000..c34b325
@@ -0,0 +1,225 @@
+/*
+ * The industrial I/O input client driver
+ *
+ * Copyright (c) 2011 Jonathan Cameron
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/input.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/consumer.h>
+#include "iio_input.h"
+
+struct iio_input_state {
+	struct iio_cb_buffer *buff;
+	struct input_dev *idev;
+};
+
+static int iio_channel_value(u8 *data,
+			     const struct iio_chan_spec *chan,
+			     s32 *val)
+{
+	u32 value = 0;
+
+	if (chan->scan_type.sign == 's') {
+		switch (chan->scan_type.storagebits) {
+		case 8:
+			value = *(s8 *)(data);
+			break;
+		case 16:
+			switch (chan->scan_type.endianness) {
+			case IIO_CPU:
+				value = *(s16 *)(data);
+				break;
+			case IIO_BE:
+				value = be16_to_cpu(*(__be16 *)data);
+				break;
+			case IIO_LE:
+				value = le16_to_cpu(*(__le16 *)data);
+				break;
+			}
+			break;
+		case 32:
+			switch (chan->scan_type.endianness) {
+			case IIO_CPU:
+				value = *(s32 *)(data);
+				break;
+			case IIO_BE:
+				value = be32_to_cpu(*(__be32 *)data);
+				break;
+			case IIO_LE:
+				value = le32_to_cpu(*(__le32  *)data);
+				break;
+			}
+			break;
+		default:
+			return -EINVAL;
+		}
+		*val = sign_extend32(value, chan->scan_type.storagebits);
+	} else {
+		switch (chan->scan_type.storagebits) {
+		case 8:
+			value = *(u8 *)(data);
+			break;
+		case 16:
+			switch (chan->scan_type.endianness) {
+			case IIO_CPU:
+				value = *(u16 *)(data);
+				break;
+			case IIO_BE:
+				value = be16_to_cpu(*(__be16 *)data);
+				break;
+			case IIO_LE:
+				value = le16_to_cpu(*(__le16 *)data);
+				break;
+			}
+			break;
+		case 32:
+			switch (chan->scan_type.endianness) {
+			case IIO_CPU:
+				value = *(u32 *)(data);
+				break;
+			case IIO_BE:
+				value = be32_to_cpu(*(__be32 *)data);
+				break;
+			case IIO_LE:
+				value = le32_to_cpu(*(__le32 *)data);
+				break;
+			}
+			break;
+		default:
+			return -EINVAL;
+		}
+		value >>= chan->scan_type.shift;
+		value &= (1 << chan->scan_type.realbits) - 1;
+		*val = value;
+	}
+
+	return 0;
+}
+
+static int iio_input_store_to(u8 *data, void *private)
+{
+	struct iio_input_state *st = private;
+	struct iio_channel *channel;
+	struct iio_input_channel_data *input_data;
+	int offset = 0;
+	s32 value;
+	int ret;
+
+	channel = iio_channel_cb_get_channels(st->buff);
+	while (channel->indio_dev) {
+		input_data = channel->data;
+		offset = ALIGN(offset,
+			       channel->channel->scan_type.storagebits/8);
+		ret = iio_channel_value(&data[offset],
+					channel->channel,
+					&value);
+		if (ret < 0)
+			return ret;
+		offset += channel->channel->scan_type.storagebits/8;
+
+		input_report_abs(st->idev, input_data->code, value);
+		channel++;
+	}
+	input_sync(st->idev);
+
+	return 0;
+}
+
+static int __devinit iio_input_probe(struct platform_device *pdev)
+{
+	struct iio_input_state *st;
+	int ret;
+	bool registered;
+	struct iio_channel *channel;
+	struct iio_input_channel_data *input_data;
+
+	registered = false;
+	st = kzalloc(sizeof(*st), GFP_KERNEL);
+	if (st == NULL)
+		return -ENOMEM;
+	platform_set_drvdata(pdev, st);
+	st->buff = iio_channel_get_all_cb(dev_name(&pdev->dev),
+					  &iio_input_store_to,
+					  st);
+	if (IS_ERR(st->buff)) {
+		ret = PTR_ERR(st->buff);
+		goto error_free_state;
+	}
+
+	st->idev = input_allocate_device();
+	if (!st->idev) {
+		ret = -ENOMEM;
+		goto error_channels_release_all;
+	}
+
+	__set_bit(EV_ABS, st->idev->evbit);
+	channel = iio_channel_cb_get_channels(st->buff);
+	while (channel->indio_dev) {
+		input_data = channel->data;
+		input_set_abs_params(st->idev, input_data->code,
+				     input_data->min,
+				     input_data->max,
+				     input_data->fuzz,
+				     input_data->flat);
+		channel++;
+	}
+
+	ret = input_register_device(st->idev);
+	if (ret < 0)
+		goto error_free_idev;
+	registered = true;
+	/* NORMALLY IN THE OPEN */
+	ret = iio_channel_start_all_cb(st->buff);
+	if (ret < 0)
+		goto error_unregister_input;
+
+	return 0;
+error_unregister_input:
+	if (registered)
+		input_unregister_device(st->idev);
+error_free_idev:
+	if (!registered)
+		input_free_device(st->idev);
+error_channels_release_all:
+	iio_channel_release_all_cb(st->buff);
+error_free_state:
+	kfree(st);
+	return ret;
+}
+
+static int __devexit iio_input_remove(struct platform_device *pdev)
+{
+	struct iio_input_state *st = platform_get_drvdata(pdev);
+	/* NORMALLY IN THE CLOSE */
+	iio_channel_stop_all_cb(st->buff);
+	input_unregister_device(st->idev);
+	iio_channel_release_all_cb(st->buff);
+
+	kfree(st);
+	return 0;
+}
+
+static struct platform_driver iio_input_driver = {
+	.driver = {
+		.name = "iio_input_bridge",
+		.owner = THIS_MODULE,
+	},
+	.probe = iio_input_probe,
+	.remove = __devexit_p(iio_input_remove),
+};
+
+module_platform_driver(iio_input_driver);
+
+MODULE_AUTHOR("Jonathan Cameron <[email protected]>");
+MODULE_DESCRIPTION("IIO input buffer driver");
+MODULE_LICENSE("GPL v2");
drivers/staging/iio/iio_input.h new file +23 -0
new file mode 100644
index 0000000..cfd1d34
@@ -0,0 +1,23 @@
+/*
+ * The industrial I/O input client driver
+ *
+ * Copyright (c) 2011 Jonathan Cameron
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+/**
+ * iio_input_channel_data - description of the channel for input subsystem
+ * @code:	Absolute axis.
+ * @min:	Minimum value.
+ * @max:	Maximum value.
+ * @fuzz:	Used to filter noise from the event stream.
+ * @flat:	Values within this value will be discarded by joydev
+ *		and reported as 0 instead.
+ */
+struct iio_input_channel_data {
+	unsigned int code;
+	int min, max, fuzz, flat;
+};
#10 lore raw
In reply to Jonathan Cameron

Hi Jonathan,

Tested hid sensor changes. They still work with this patchset.

Thanks,
Srinivas

-----Original Message-----
From: J.I. Cameron [mailto:[email protected]] On Behalf Of Jonathan Ca= meron
Sent: Saturday, October 13, 2012 2:25 AM
To: [email protected]
Cc: [email protected]; [email protected]; Pandruvada, Srinivas; Jo= nathan Cameron
Subject: [PATCH 0/4 V5] staging:iio: Add support for multiple buffers (test= ing required!)

In quick summary this is needed to do interrupt driven in kernel clients as=
it adds the option to push to multiple 'buffer' interfaces.
Note that some of these may not actually do any buffering but rather push d= irectly into another subsytem (the example is input).

I would like to merge at least the first 3 patches early in this cycle. What I need is some testing across a reasonable range of devices. Review i= s welcome of course as well!

The complexity in this set is entirely in the changes to industrialio-buffe= r.c concerning how we go about adding and removing client buffers. To do t= his we need to work out which scan mask is appropriate given the requests o= f all the given buffers (and whether we can satisfy it). I've been testing=
with the max1363 driver which probably has the most complex set of availab=
le scan masks. Thus when a new buffer is added or one is removed the whole=
buffer set are torn down and built up again. This may be undesirable for =
some applications but should occur only rarely.

The example driver is for bridging to the input subsystem and still needs s= ome work, but that can occur later in this merge cycle whereas the changes = to the core really want to go in asap.

Changes since v3=20

Rebased and added other drivers that have occured whilst this patch series = has been languishing in my local tree.

Changes since V2.

Improved handling of error conditions in the buffer insertion and removal c= ode. (suggested by Lars-Peter). I want to take another look at these, but=
didn't want to keep people from testing this in the meantime.

Also a number of minor fixes that came up during testing.

Thanks,

Jonathan

Jonathan Cameron (4):
staging:iio: Add support for multiple buffers staging:iio:in kernel users: Add a data field for channel specific
info.
staging:iio: add a callback buffer for in kernel push interface staging:iio: Proof of concept input driver.

 drivers/iio/Kconfig                             |   6 +
 drivers/iio/Makefile                            |   1 +
 drivers/iio/accel/hid-sensor-accel-3d.c         |  15 +-
 drivers/iio/adc/ad7266.c                        |   3 +-
 drivers/iio/adc/ad7476.c                        |   2 +-
 drivers/iio/adc/ad_sigma_delta.c                |   2 +-
 drivers/iio/adc/at91_adc.c                      |   3 +-
 drivers/iio/buffer_cb.c                         | 113 +++++++
 drivers/iio/gyro/hid-sensor-gyro-3d.c           |  15 +-
 drivers/iio/industrialio-buffer.c               | 377 ++++++++++++++++----=
----
 drivers/iio/industrialio-core.c                 |   1 +
 drivers/iio/inkern.c                            |   1 +
 drivers/iio/light/adjd_s311.c                   |   3 +-
 drivers/iio/light/hid-sensor-als.c              |  15 +-
 drivers/iio/magnetometer/hid-sensor-magn-3d.c   |  15 +-
 drivers/staging/iio/Kconfig                     |  11 +
 drivers/staging/iio/Makefile                    |   1 +
 drivers/staging/iio/accel/adis16201_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16203_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16204_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16209_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16240_ring.c      |   2 +-
 drivers/staging/iio/accel/lis3l02dq_ring.c      |   2 +-
 drivers/staging/iio/adc/ad7298_ring.c           |   2 +-
 drivers/staging/iio/adc/ad7606_ring.c           |   2 +-
 drivers/staging/iio/adc/ad7887_ring.c           |   2 +-
 drivers/staging/iio/adc/ad799x_ring.c           |   2 +-
 drivers/staging/iio/adc/max1363_ring.c          |   2 +-
 drivers/staging/iio/gyro/adis16260_ring.c       |   2 +-
 drivers/staging/iio/iio_input.c                 | 225 ++++++++++++++
 drivers/staging/iio/iio_input.h                 |  23 ++
 drivers/staging/iio/iio_simple_dummy_buffer.c   |   5 +-
 drivers/staging/iio/impedance-analyzer/ad5933.c |   4 +-
 drivers/staging/iio/imu/adis16400_ring.c        |   5 +-
 drivers/staging/iio/meter/ade7758_ring.c        |   2 +-
 include/linux/iio/buffer.h                      |  24 +-
 include/linux/iio/consumer.h                    |  48 +++
 include/linux/iio/iio.h                         |   2 +
 include/linux/iio/machine.h                     |   2 +
 39 files changed, 740 insertions(+), 208 deletions(-)  create mode 100644 =

drivers/iio/buffer_cb.c create mode 100644 drivers/staging/iio/iio_input.c=
create mode 100644 drivers/staging/iio/iio_input.h

--
1.7.12.2

author maintainer
#11 lore raw

Thanks, I've added a tested-by tag for patch 0. The others shouldn't have any effect at all on your drivers (or any others!)

Quoted 89 lines

Hi Jonathan,

Tested hid sensor changes. They still work with this patchset.

Thanks,
Srinivas

-----Original Message-----
From: J.I. Cameron [mailto:[email protected]] On Behalf Of Jonathan Cameron
Sent: Saturday, October 13, 2012 2:25 AM
To: [email protected]
Cc: [email protected]; [email protected]; Pandruvada, Srinivas; Jonathan Cameron
Subject: [PATCH 0/4 V5] staging:iio: Add support for multiple buffers (testing required!)

In quick summary this is needed to do interrupt driven in kernel clients as it adds the option to push to multiple 'buffer' interfaces. Note that some of these may not actually do any buffering but rather push directly into another subsytem (the example is input).

I would like to merge at least the first 3 patches early in this cycle.
What I need is some testing across a reasonable range of devices. Review is welcome of course as well!

The complexity in this set is entirely in the changes to industrialio-buffer.c concerning how we go about adding and removing client buffers. To do this we need to work out which scan mask is appropriate given the requests of all the given buffers (and whether we can satisfy it). I've been testing with the max1363 driver which probably has the most complex set of available scan masks. Thus when a new buffer is added or one is removed the whole buffer set are torn down and built up again. This may be undesirable for some applications but should occur only rarely.

The example driver is for bridging to the input subsystem and still needs some work, but that can occur later in this merge cycle whereas the changes to the core really want to go in asap.

Changes since v3

Rebased and added other drivers that have occured whilst this patch series has been languishing in my local tree.

Changes since V2.

Improved handling of error conditions in the buffer insertion and removal code. (suggested by Lars-Peter). I want to take another look at these, but didn't want to keep people from testing this in the meantime.

Also a number of minor fixes that came up during testing.

Thanks,

Jonathan

Jonathan Cameron (4):
staging:iio: Add support for multiple buffers staging:iio:in kernel users: Add a data field for channel specific
info.
staging:iio: add a callback buffer for in kernel push interface staging:iio: Proof of concept input driver.

 drivers/iio/Kconfig                             |   6 +
 drivers/iio/Makefile                            |   1 +
 drivers/iio/accel/hid-sensor-accel-3d.c         |  15 +-
 drivers/iio/adc/ad7266.c                        |   3 +-
 drivers/iio/adc/ad7476.c                        |   2 +-
 drivers/iio/adc/ad_sigma_delta.c                |   2 +-
 drivers/iio/adc/at91_adc.c                      |   3 +-
 drivers/iio/buffer_cb.c                         | 113 +++++++
 drivers/iio/gyro/hid-sensor-gyro-3d.c           |  15 +-
 drivers/iio/industrialio-buffer.c               | 377 ++++++++++++++++--------
 drivers/iio/industrialio-core.c                 |   1 +
 drivers/iio/inkern.c                            |   1 +
 drivers/iio/light/adjd_s311.c                   |   3 +-
 drivers/iio/light/hid-sensor-als.c              |  15 +-
 drivers/iio/magnetometer/hid-sensor-magn-3d.c   |  15 +-
 drivers/staging/iio/Kconfig                     |  11 +
 drivers/staging/iio/Makefile                    |   1 +
 drivers/staging/iio/accel/adis16201_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16203_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16204_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16209_ring.c      |   2 +-
 drivers/staging/iio/accel/adis16240_ring.c      |   2 +-
 drivers/staging/iio/accel/lis3l02dq_ring.c      |   2 +-
 drivers/staging/iio/adc/ad7298_ring.c           |   2 +-
 drivers/staging/iio/adc/ad7606_ring.c           |   2 +-
 drivers/staging/iio/adc/ad7887_ring.c           |   2 +-
 drivers/staging/iio/adc/ad799x_ring.c           |   2 +-
 drivers/staging/iio/adc/max1363_ring.c          |   2 +-
 drivers/staging/iio/gyro/adis16260_ring.c       |   2 +-
 drivers/staging/iio/iio_input.c                 | 225 ++++++++++++++
 drivers/staging/iio/iio_input.h                 |  23 ++
 drivers/staging/iio/iio_simple_dummy_buffer.c   |   5 +-
 drivers/staging/iio/impedance-analyzer/ad5933.c |   4 +-
 drivers/staging/iio/imu/adis16400_ring.c        |   5 +-
 drivers/staging/iio/meter/ade7758_ring.c        |   2 +-
 include/linux/iio/buffer.h                      |  24 +-
 include/linux/iio/consumer.h                    |  48 +++
 include/linux/iio/iio.h                         |   2 +
 include/linux/iio/machine.h                     |   2 +
 39 files changed, 740 insertions(+), 208 deletions(-)  create mode 100644 drivers/iio/buffer_cb.c  create mode 100644 drivers/staging/iio/iio_input.c  create mode 100644 drivers/staging/iio/iio_input.h

--
1.7.12.2