staging:iio: in kernel push interface
Subsystems (4)
cover staging:iio: in kernel push interface
Dear All,
This is a more developed (though still far from finished) version of the set I sent out last week.
The input driver is very basic, but should show how things fit together. Clearly we need some more boilerplate code to avoid every user having to respin the stuff for breaking up the incoming data stream.
Quick summary.
Mapping to a client is done using the same maps as in the pull interface, but for push there is only the 'get all' option. (see that RFC for this side of things).
Push is done by inserting 'buffer' interfaces (basically data sinks) in and out of a list. Adding a buffer tears down all capture and then builds it up again with the new buffer.
Special call back 'buffer' provided that will get a stream of data aligned and padded as it would be for userspace. As with userspace this can be interpretted using info in the availale chan_spec structures
Lots of interface code needed to make it easy for clients to handle the datastreams without reinventing the wheel in every client driver. This will get written as and when client drivers need it. A very basic 'input' client is provided to motivate what we have here with a real user.
There are some questions raised at the end of this cover letter...
In detail...
Lifting most of the text from the previous RFC
The following is primarily an RFC rather than a firm proposal due to a few things currently not being there.
1) A full interface. This needs quite a few more wrapper functions if we are to keep the underlying IIO stuff as opaque to clients as I would like.
2) A lack of any certainty that I haven't broken 90% of more of the drivers. Hardware buffers for one (sca3000) are going to be interesting with this.
3) Locking missing all over the place. Once I am sure no one has any issues with the basic approach I'll get this cleaned up.
4) No means of doing in kernel trigger configuration at the moment so you'll have have to have a trigger set up BEFORE any driver tries to insert a buffer for it to feed. For devices doing push this is probably a data ready signal anyway and so would be the default trigger.
5) Probably want to separate the bits of preenable functions that deal with setting up scan modes etc from those that run for each buffer. This is the case with max1363 which uses the update_scan_mode callback, but the naming doesn't reflect things well.
6) I've only tested it on the max1363 so far with snoop on in_voltage3_raw and the main buffer set to read in_voltage0_raw and in_voltage2_raw. A sysfs trigger was used and hammered from a tight loop whilst the generic_buffer example was used to read from the iio chrdev. This setup works.
So basically, this 'works', but might eat babies in its current form.
What has changed (from before the first RFC, not since then)
Principally the dataflow has become a little more complex
Before we had
------- -------- ------------ ---------
|Trigger|--->|Device 1| --> |Ring or Fifo| --> |Userspace|
------- -------- ------------ ---------
| -------- ------------ ---------
------->|Device 2| --> |Ring or Fifo| --> |Userspace|
-------- ------------ ---------Now we have
------- -------- ---------- ------ ---------
|Trigger|->|Device 1| -> |BufferList| -> |R/Fifo| -> |Userspace|
------- -------- ---------- ------ ---------
| |
| -------- | -------------------
----->|Device 2| -> -------> |In Kernel interface|
-------- -------------------So we have inserted a bufferlist. If there is nothing in this list (initial state) then the poll function is not attached so the trigger will not cause this device to push to the buffers.
All buffer pushing from the driver is done through iio_push_to_buffers()
Changes to the buffer list are done by calling iio_buffers_update which takes a buffer to add or one to remove (or neither).
This function does the following:
1) Tear down current buffering (including detaching the poll function).
2) Add or remove buffers from the list.
3) Setup the Demux. As a change to any buffer can result in a change to the active scan mask (that may or may not succeed) all demuxes into the buffers must be updated if they are still attached.
4) Bring up buffering (including attaching the pollfunc).
Since the earlier RFC I have added a trivial buffer implementation buffer_cb that as it names suggests just calls an appropriate callback function that is called when the buffer store_to method is called. It has a simple interface and should handle most usecases for push interfaces.
Note that the only overhead on a 'normal' driver over what we had before is a lookup into a list with only one entry + a few pointer copies. (where normal is without in kernel usage and a scan that requires no demux).
Now, there are a few issues that need discussion.
1) Right now pull interface (previously proposed and much simpler) doesn't not play well with the push interface. For existing drivers you can sometimes pull the most recent value back from their IIO buffer (on a read of the sysfs attributes for example) but for elements that are not in the scan and hence not being grabbed on the trigger, we return -EBUSY. The same will hold true here. Iff this is a big issue for usecases people have then we could have a pull channel gets add their own buffer which simply stores one value and have direct reads retrieve that. Unfortunately there are still channel combinations that will fail...
2) Unclear how to handle incompatible scan sets. If one inkernel user requests in_voltage1 and another in_voltage1-in_voltage2 we typically can't service both requests in a remotely efficient manner (using data ready etc). So the question is, when do we fail? On first attempt to set the scan mask element or only when we attempt to insert the buffer? My personal feeling is that, when we have pulled the triggered capture down to add the new buffer, there should be a verification check of the new buffers requested scan, and if it doesn't work the buffer add attempt should be dropped, but the triggered capture restarted for everything else.
Having said that, it also makes sense to verify that a given buffers own requested set are possible and this can occur at time of the scan mask being set. I don't thing verifying against everything is going to fly as it will get racey.
Anyhow, all comments, particularly on the interface welcomed!
Jonathan Cameron (5):
staging:iio: scrap scan_count and ensure all drivers use
active_scan_mask
staging:iio: make all buffer access pass through the buffer_list staging:iio: make update buffers available outside iio. staging:iio: add a callback buffer for in kernel push interface staging:iio: Proof of concept input driver.
drivers/staging/iio/Kconfig | 7 + drivers/staging/iio/Makefile | 3 +- drivers/staging/iio/accel/adis16201_ring.c | 26 +- drivers/staging/iio/accel/adis16203_ring.c | 27 +- drivers/staging/iio/accel/adis16204_ring.c | 25 +- drivers/staging/iio/accel/adis16209_ring.c | 20 +- drivers/staging/iio/accel/adis16240_ring.c | 20 +- drivers/staging/iio/accel/lis3l02dq_ring.c | 41 ++- drivers/staging/iio/adc/ad7192.c | 41 +- drivers/staging/iio/adc/ad7298_ring.c | 46 ++- drivers/staging/iio/adc/ad7476_ring.c | 35 +- drivers/staging/iio/adc/ad7606_ring.c | 20 +- drivers/staging/iio/adc/ad7793.c | 43 +- drivers/staging/iio/adc/ad7887_ring.c | 40 ++- drivers/staging/iio/adc/ad799x_ring.c | 47 ++- drivers/staging/iio/adc/max1363_ring.c | 20 +- drivers/staging/iio/buffer.h | 12 +- drivers/staging/iio/buffer_cb.c | 115 +++++ drivers/staging/iio/gyro/adis16260_ring.c | 23 +- drivers/staging/iio/iio.h | 2 + drivers/staging/iio/iio_input.c | 106 +++++ drivers/staging/iio/iio_simple_dummy_buffer.c | 26 +- drivers/staging/iio/impedance-analyzer/ad5933.c | 27 +- drivers/staging/iio/imu/adis16400_ring.c | 21 +- drivers/staging/iio/industrialio-buffer.c | 544 ++++++++++++++--------- drivers/staging/iio/industrialio-core.c | 1 + drivers/staging/iio/inkern.h | 35 ++ drivers/staging/iio/meter/ade7758_ring.c | 34 +- 28 files changed, 965 insertions(+), 442 deletions(-) create mode 100644 drivers/staging/iio/buffer_cb.c create mode 100644 drivers/staging/iio/iio_input.c
Signature · 1 line
1.7.7
PATCH 2/5 staging:iio: make all buffer access pass through the buffer_list
Crucial step in allowing multiple interfaces.
Main stages:
1) Ensure no trigger_handler touches the buffers directly. They should only care about active_scan_mask and scan_timestamp in indio_dev.
2) Ensure all setup ops for the buffers act on the general mode and the individual buffers in a consistent fashion.
There are almost certainly better ways of doing some of this and I could probably have broken the set up more. That will have to wait for round 3.
--- drivers/staging/iio/accel/adis16201_ring.c | 16 +- drivers/staging/iio/accel/adis16203_ring.c | 17 +- drivers/staging/iio/accel/adis16204_ring.c | 15 +- drivers/staging/iio/accel/adis16209_ring.c | 15 +- drivers/staging/iio/accel/adis16240_ring.c | 15 +- drivers/staging/iio/accel/lis3l02dq_ring.c | 18 +- drivers/staging/iio/adc/ad7192.c | 39 +- drivers/staging/iio/adc/ad7298_ring.c | 42 ++- drivers/staging/iio/adc/ad7476_ring.c | 32 +- drivers/staging/iio/adc/ad7606_ring.c | 20 +- drivers/staging/iio/adc/ad7793.c | 40 +- drivers/staging/iio/adc/ad7887_ring.c | 32 +- drivers/staging/iio/adc/ad799x_ring.c | 34 +- drivers/staging/iio/adc/max1363_ring.c | 20 +- drivers/staging/iio/buffer.h | 6 + drivers/staging/iio/gyro/adis16260_ring.c | 18 +- drivers/staging/iio/iio.h | 2 + drivers/staging/iio/iio_simple_dummy_buffer.c | 26 +- drivers/staging/iio/impedance-analyzer/ad5933.c | 17 +- drivers/staging/iio/imu/adis16400_ring.c | 2 +- drivers/staging/iio/industrialio-buffer.c | 542 ++++++++++++++--------- drivers/staging/iio/industrialio-core.c | 1 + drivers/staging/iio/meter/ade7758_ring.c | 31 +- 23 files changed, 616 insertions(+), 384 deletions(-)
drivers/staging/iio/accel/adis16201_ring.c +12 -4
@@ -61,11 +61,19 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct adis16201_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer;int i =0 ;s16 *data; -size_t datasize = ring->access->get_bytes_per_datum (ring); +size_t datasize; + +/* This is available for them demux unit */ + datasize =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength)*2 ; +if (indio_dev->scan_timestamp) { +if (datasize %sizeof (s64)) + datasize +=sizeof (s64) - datasize %sizeof (s64); + datasize +=sizeof (s64); + } data =kmalloc (datasize,GFP_KERNEL );if (data ==NULL ) {
@@ -80,10 +88,10 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p) data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* 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; - ring->access->store_to (ring, (u8 *)data, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)data, pf->timestamp);iio_trigger_notify_done (indio_dev->trig);kfree (data);
drivers/staging/iio/accel/adis16203_ring.c +11 -6
@@ -61,11 +61,18 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct adis16203_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer;int i =0 ;s16 *data; -size_t datasize = ring->access->get_bytes_per_datum (ring); +size_t datasize; + + datasize =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength)*2 ; +if (indio_dev->scan_timestamp) { +if (datasize %sizeof (s64)) + datasize +=sizeof (s64) - datasize %sizeof (s64); + datasize +=sizeof (s64); + } data =kmalloc (datasize,GFP_KERNEL );if (data ==NULL ) {
@@ -80,12 +87,10 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p) data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* 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; - ring->access->store_to (ring, - (u8 *)data, - pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)data, pf->timestamp);iio_trigger_notify_done (indio_dev->trig);kfree (data);
drivers/staging/iio/accel/adis16204_ring.c +11 -4
@@ -59,10 +59,17 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct adis16204_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer;int i =0 ;s16 *data; -size_t datasize = ring->access->get_bytes_per_datum (ring); +size_t datasize; + + datasize =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength)*2 ; +if (indio_dev->scan_timestamp) { +if (datasize %sizeof (s64)) + datasize +=sizeof (s64) - datasize %sizeof (s64); + datasize +=sizeof (s64); + } data =kmalloc (datasize,GFP_KERNEL );if (data ==NULL ) {
@@ -77,10 +84,10 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p) data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* 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; - ring->access->store_to (ring, (u8 *)data, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)data, pf->timestamp);iio_trigger_notify_done (indio_dev->trig);kfree (data);
drivers/staging/iio/accel/adis16209_ring.c +10 -5
@@ -59,12 +59,17 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct adis16209_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer; -int i =0 ;s16 *data; -size_t datasize = ring->access->get_bytes_per_datum (ring); +size_t datasize; + datasize =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength)*2 ; +if (indio_dev->scan_timestamp) { +if (datasize %sizeof (s64)) + datasize +=sizeof (s64) - datasize %sizeof (s64); + datasize +=sizeof (s64); + } data =kmalloc (datasize ,GFP_KERNEL );if (data ==NULL ) {dev_err (&st->us->dev,"memory alloc failed in ring bh" );
@@ -78,10 +83,10 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p) data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* 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; - ring->access->store_to (ring, (u8 *)data, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)data, pf->timestamp);iio_trigger_notify_done (indio_dev->trig);kfree (data);
drivers/staging/iio/accel/adis16240_ring.c +10 -5
@@ -56,12 +56,17 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct adis16240_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer; -int i =0 ;s16 *data; -size_t datasize = ring->access->get_bytes_per_datum (ring); +size_t datasize; + datasize =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength)*2 ; +if (indio_dev->scan_timestamp) { +if (datasize %sizeof (s64)) + datasize +=sizeof (s64) - datasize %sizeof (s64); + datasize +=sizeof (s64); + } data =kmalloc (datasize,GFP_KERNEL );if (data ==NULL ) {dev_err (&st->us->dev,"memory alloc failed in ring bh" );
@@ -75,10 +80,10 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p) data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* 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; - ring->access->store_to (ring, (u8 *)data, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)data, pf->timestamp);iio_trigger_notify_done (indio_dev->trig);kfree (data);
drivers/staging/iio/accel/lis3l02dq_ring.c +13 -5
@@ -166,11 +166,19 @@ static irqreturn_t lis3l02dq_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;int len =0 ; -size_t datasize = buffer->access->get_bytes_per_datum (buffer); -char *data =kmalloc (datasize,GFP_KERNEL ); +size_t datasize; +char *data; + datasize =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength)*2 ; +if (indio_dev->scan_timestamp) { +if (datasize %sizeof (s64)) + datasize +=sizeof (s64) - datasize %sizeof (s64); + datasize +=sizeof (s64); + } + + data =kmalloc (datasize,GFP_KERNEL );if (data ==NULL ) {dev_err (indio_dev->dev.parent,"memory alloc failed in buffer bh" );
@@ -181,11 +189,11 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p) len =lis3l02dq_get_buffer_element (indio_dev, data);/* Guaranteed to be aligned with 8 byte boundary */ -if (buffer->scan_timestamp) +if (indio_dev->scan_timestamp) *(s64 *)(((phys_addr_t )data + len +sizeof (s64) -1 ) & ~(sizeof (s64) -1 )) = pf->timestamp; - buffer->access->store_to (buffer, (u8 *)data, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)data, pf->timestamp);iio_trigger_notify_done (indio_dev->trig);kfree (data);
drivers/staging/iio/adc/ad7192.c +20 -19
@@ -455,12 +455,14 @@ out:static int ad7192_scan_from_ring (struct ad7192_state *st,unsigned ch,int *val) { -struct iio_buffer *ring =iio_priv_to_dev (st)->buffer; +struct iio_dev *indio_dev =iio_priv_to_dev (st); +struct iio_buffer *ring = indio_dev->buffer;int ret;s64 dat64[2 ];u32 *dat32 = (u32 *)dat64; -if (!(test_bit (ch, ring->scan_mask))) +if (!iio_is_primary_active (indio_dev) || + !(test_bit (ch, ring->scan_mask)))return -EBUSY ; ret = ring->access->read_last (ring, (u8 *) &dat64);
@@ -475,30 +477,30 @@ static int ad7192_scan_from_ring(struct ad7192_state *st, unsigned ch, int *val)static int ad7192_ring_preenable (struct iio_dev *indio_dev) {struct ad7192_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer; +struct iio_buffer *buffer;size_t d_size;unsigned channel;if (bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))return -EINVAL ; - channel =find_first_bit (indio_dev->active_scan_mask, - indio_dev->masklength); - - d_size =bitmap_weight (indio_dev->active_scan_mask, - indio_dev->masklength) * - indio_dev->channels[0 ].scan_type.storagebits /8 ; +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { + d_size =bitmap_weight (buffer->scan_mask, + indio_dev->masklength) * + indio_dev->channels[0 ].scan_type.storagebits /8 ; -if (ring->scan_timestamp) { - d_size +=sizeof (s64); +if (buffer->scan_timestamp) { + d_size +=sizeof (s64); +if (d_size %sizeof (s64)) + d_size +=sizeof (s64) - (d_size %sizeof (s64)); + } -if (d_size %sizeof (s64)) - d_size +=sizeof (s64) - (d_size %sizeof (s64)); +if (buffer->access->set_bytes_per_datum) + buffer->access->set_bytes_per_datum (buffer, d_size); } -if (indio_dev->buffer->access->set_bytes_per_datum) - indio_dev->buffer->access-> -set_bytes_per_datum (indio_dev->buffer, d_size); + channel =find_first_bit (indio_dev->active_scan_mask, + indio_dev->masklength); st->mode = (st->mode & ~AD7192_MODE_SEL (-1 )) |AD7192_MODE_SEL (AD7192_MODE_CONT );
@@ -541,7 +543,6 @@ static irqreturn_t ad7192_trigger_handler(int irq, void *p) {struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev; -struct iio_buffer *ring = indio_dev->buffer;struct ad7192_state *st =iio_priv (indio_dev);s64 dat64[2 ];s32 *dat32 = (s32 *)dat64;
@@ -552,10 +553,10 @@ static irqreturn_t ad7192_trigger_handler(int irq, void *p) indio_dev->channels[0].scan_type.realbits/8);/* Guaranteed to be aligned with 8 byte boundary */ -if (ring->scan_timestamp) +if (indio_dev->scan_timestamp) dat64[1 ] = pf->timestamp; - ring->access->store_to (ring, (u8 *)dat64, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)dat64, pf->timestamp);iio_trigger_notify_done (indio_dev->trig); st->irq_dis = false;
drivers/staging/iio/adc/ad7298_ring.c +28 -14
90 lines not on this page · raw message
drivers/staging/iio/adc/ad7476_ring.c +22 -10
@@ -26,6 +26,9 @@ int ad7476_scan_from_ring(struct iio_dev *indio_dev)int ret;u8 *ring_data; +if (!iio_is_primary_active (indio_dev)) +return -EBUSY ; + ring_data =kmalloc (ring->access->get_bytes_per_datum (ring),GFP_KERNEL );if (ring_data ==NULL ) {
@@ -54,23 +57,32 @@ error_ret:static int ad7476_ring_preenable (struct iio_dev *indio_dev) {struct ad7476_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer; - +struct iio_buffer *buffer; +int d_size; st->d_size =bitmap_weight (indio_dev->active_scan_mask, indio_dev->masklength) * st->chip_info->channel[0 ].scan_type.storagebits /8 ; -if (ring->scan_timestamp) { - st->d_size +=sizeof (s64); - +if (indio_dev->scan_timestamp) { + d_size +=sizeof (s64);if (st->d_size %sizeof (s64)) st->d_size +=sizeof (s64) - (st->d_size %sizeof (s64)); } -if (indio_dev->buffer->access->set_bytes_per_datum) - indio_dev->buffer->access-> -set_bytes_per_datum (indio_dev->buffer, st->d_size); +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { + d_size =bitmap_weight (buffer->scan_mask, + indio_dev->masklength) * + st->chip_info->channel[0 ].scan_type.storagebits /8 ; +if (buffer->scan_timestamp) { + d_size +=sizeof (s64); +if (st->d_size %sizeof (s64)) + d_size +=sizeof (s64) - + (st->d_size %sizeof (s64)); + } +if (buffer->access->set_bytes_per_datum) + buffer->access->set_bytes_per_datum (buffer, st->d_size); + }return 0 ; }
@@ -94,11 +106,11 @@ static irqreturn_t ad7476_trigger_handler(int irq, void *p) time_ns =iio_get_time_ns (); -if (indio_dev->buffer->scan_timestamp) +if (indio_dev->scan_timestamp)memcpy (rxbuf + st->d_size -sizeof (s64), &time_ns,sizeof (time_ns)); - indio_dev->buffer->access->store_to (indio_dev->buffer, rxbuf, time_ns); +iio_push_to_buffers (indio_dev, rxbuf, time_ns); done:iio_trigger_notify_done (indio_dev->trig);kfree (rxbuf);
drivers/staging/iio/adc/ad7606_ring.c +12 -8
@@ -70,13 +70,18 @@ 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); -struct iio_buffer *ring = indio_dev->buffer;s64 time_ns;__u8 *buf; -int ret; +int ret, scan_size; - buf =kzalloc (ring->access->get_bytes_per_datum (ring), -GFP_KERNEL ); + scan_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength)*2 ; +if (indio_dev->scan_timestamp) { +if (scan_size %sizeof (s64)) + scan_size +=sizeof (s64) - scan_size %sizeof (s64); + scan_size +=sizeof (s64); + } + buf =kzalloc (scan_size,GFP_KERNEL );if (buf ==NULL )return ;
@@ -106,11 +111,10 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s) time_ns =iio_get_time_ns (); -if (ring->scan_timestamp) - *((s64 *)(buf + ring->access->get_bytes_per_datum (ring) - -sizeof (s64))) = time_ns; +if (indio_dev->scan_timestamp) + *((s64 *)(buf + scan_size -sizeof (s64))) = time_ns; - ring->access->store_to (indio_dev->buffer, buf, time_ns); +iio_push_to_buffers (indio_dev, buf, time_ns); done:gpio_set_value (st->pdata->gpio_convst,0 );iio_trigger_notify_done (indio_dev->trig);
drivers/staging/iio/adc/ad7793.c +20 -20
@@ -317,12 +317,14 @@ out:static int ad7793_scan_from_ring (struct ad7793_state *st,unsigned ch,int *val) { -struct iio_buffer *ring =iio_priv_to_dev (st)->buffer; +struct iio_dev *indio_dev =iio_priv_to_dev (st); +struct iio_buffer *ring = indio_dev->buffer;int ret;s64 dat64[2 ];u32 *dat32 = (u32 *)dat64; -if (!(test_bit (ch, ring->scan_mask))) +if (!iio_is_primary_active (indio_dev) || + !(test_bit (ch, ring->scan_mask)))return -EBUSY ; ret = ring->access->read_last (ring, (u8 *) &dat64);
@@ -337,30 +339,29 @@ static int ad7793_scan_from_ring(struct ad7793_state *st, unsigned ch, int *val)static int ad7793_ring_preenable (struct iio_dev *indio_dev) {struct ad7793_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer; +struct iio_buffer *buffer;size_t d_size;unsigned channel;if (bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))return -EINVAL ; - channel =find_first_bit (indio_dev->active_scan_mask, - indio_dev->masklength); - - d_size =bitmap_weight (indio_dev->active_scan_mask, - indio_dev->masklength) * - indio_dev->channels[0 ].scan_type.storagebits /8 ; +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { + d_size =bitmap_weight (buffer->scan_mask, + indio_dev->masklength) * + indio_dev->channels[0 ].scan_type.storagebits /8 ; -if (ring->scan_timestamp) { - d_size +=sizeof (s64); - -if (d_size %sizeof (s64)) - d_size +=sizeof (s64) - (d_size %sizeof (s64)); +if (buffer->scan_timestamp) { + d_size +=sizeof (s64); +if (d_size %sizeof (s64)) + d_size +=sizeof (s64) - (d_size %sizeof (s64)); + } +if (buffer->access->set_bytes_per_datum) + buffer->access->set_bytes_per_datum (buffer, d_size); } -if (indio_dev->buffer->access->set_bytes_per_datum) - indio_dev->buffer->access-> -set_bytes_per_datum (indio_dev->buffer, d_size); + channel =find_first_bit (indio_dev->active_scan_mask, + indio_dev->masklength); st->mode = (st->mode & ~AD7793_MODE_SEL (-1 )) |AD7793_MODE_SEL (AD7793_MODE_CONT );
@@ -406,7 +407,6 @@ static irqreturn_t ad7793_trigger_handler(int irq, void *p) {struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev; -struct iio_buffer *ring = indio_dev->buffer;struct ad7793_state *st =iio_priv (indio_dev);s64 dat64[2 ];s32 *dat32 = (s32 *)dat64;
@@ -417,10 +417,10 @@ static irqreturn_t ad7793_trigger_handler(int irq, void *p) indio_dev->channels[0].scan_type.realbits/8);/* Guaranteed to be aligned with 8 byte boundary */ -if (ring->scan_timestamp) +if (indio_dev->scan_timestamp) dat64[1 ] = pf->timestamp; - ring->access->store_to (ring, (u8 *)dat64, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)dat64, pf->timestamp);iio_trigger_notify_done (indio_dev->trig); st->irq_dis = false;
drivers/staging/iio/adc/ad7887_ring.c +21 -11
@@ -21,11 +21,13 @@int ad7887_scan_from_ring (struct ad7887_state *st,int channum) { -struct iio_buffer *ring =iio_priv_to_dev (st)->buffer; +struct iio_dev *indio_dev =iio_priv_to_dev (st); +struct iio_buffer *ring = indio_dev->buffer;int count =0 , ret;u16 *ring_data; -if (!(test_bit (channum, ring->scan_mask))) { +if (!iio_is_primary_active (indio_dev) || + !(test_bit (channum, ring->scan_mask))) { ret = -EBUSY ; goto error_ret; }
@@ -63,23 +65,32 @@ error_ret:static int ad7887_ring_preenable (struct iio_dev *indio_dev) {struct ad7887_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer; - +struct iio_buffer *buffer; +int d_size; st->d_size =bitmap_weight (indio_dev->active_scan_mask, indio_dev->masklength) * st->chip_info->channel[0 ].scan_type.storagebits /8 ; -if (ring->scan_timestamp) { +if (indio_dev->scan_timestamp) { st->d_size +=sizeof (s64);if (st->d_size %sizeof (s64)) st->d_size +=sizeof (s64) - (st->d_size %sizeof (s64)); } -if (indio_dev->buffer->access->set_bytes_per_datum) - indio_dev->buffer->access-> -set_bytes_per_datum (indio_dev->buffer, st->d_size); +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { + d_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) * + st->chip_info->channel[0 ].scan_type.storagebits /8 ; +if (buffer->scan_timestamp) { + d_size +=sizeof (s64); +if (d_size %sizeof (s64)) + d_size +=sizeof (s64) - (d_size %sizeof (s64)); + } +if (buffer->access->set_bytes_per_datum) + buffer->access->set_bytes_per_datum (buffer, d_size); + }/* We know this is a single long so can 'cheat' */ switch (*indio_dev->active_scan_mask) {case (1 <<0 ):
@@ -117,7 +128,6 @@ 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); -struct iio_buffer *ring = indio_dev->buffer;s64 time_ns;__u8 *buf;int b_sent;
@@ -137,11 +147,11 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p) time_ns =iio_get_time_ns ();memcpy (buf, st->data, bytes); -if (ring->scan_timestamp) +if (indio_dev->scan_timestamp)memcpy (buf + st->d_size -sizeof (s64), &time_ns,sizeof (time_ns)); - indio_dev->buffer->access->store_to (indio_dev->buffer, buf, time_ns); +iio_push_to_buffers (indio_dev, buf, time_ns); done:kfree (buf);iio_trigger_notify_done (indio_dev->trig);
drivers/staging/iio/adc/ad799x_ring.c +20 -14
@@ -29,7 +29,8 @@ int ad799x_single_channel_from_ring(struct iio_dev *indio_dev, int channum)int count =0 , ret;u16 *ring_data; -if (!(test_bit (channum, ring->scan_mask))) { +if (!iio_is_primary_active (indio_dev) || + !(test_bit (channum, ring->scan_mask))) { ret = -EBUSY ; goto error_ret; }
@@ -62,9 +63,9 @@ error_ret:**/ static int ad799x_ring_preenable (struct iio_dev *indio_dev) { -struct iio_buffer *ring = indio_dev->buffer; +struct iio_buffer *buffer;struct ad799x_state *st =iio_priv (indio_dev); - +int d_size;/* * Need to figure out the current mode based upon the requested * scan mask in iio_dev
@@ -76,17 +77,23 @@ static int ad799x_ring_preenable(struct iio_dev *indio_dev) st->d_size =bitmap_weight (indio_dev->active_scan_mask, indio_dev->masklength) *2 ; -if (ring->scan_timestamp) { +if (indio_dev->scan_timestamp) { st->d_size +=sizeof (s64); -if (st->d_size %sizeof (s64)) - st->d_size +=sizeof (s64) - (st->d_size %sizeof (s64)); + st->d_size +=sizeof (s64) - + (st->d_size %sizeof (s64)); + } +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { + d_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) *2 ; +if (buffer->scan_timestamp) { + d_size +=sizeof (s64); +if (d_size %sizeof (s64)) + d_size +=sizeof (s64) - (d_size %sizeof (s64)); + } +if (buffer->access->set_bytes_per_datum) + buffer->access->set_bytes_per_datum (buffer, d_size); } - -if (indio_dev->buffer->access->set_bytes_per_datum) - indio_dev->buffer->access-> -set_bytes_per_datum (indio_dev->buffer, st->d_size); -return 0 ; }
@@ -102,7 +109,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); -struct iio_buffer *ring = indio_dev->buffer;s64 time_ns;__u8 *rxbuf;int b_sent;
@@ -141,11 +147,11 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p) time_ns =iio_get_time_ns (); -if (ring->scan_timestamp) +if (indio_dev->scan_timestamp)memcpy (rxbuf + st->d_size -sizeof (s64), &time_ns,sizeof (time_ns)); - ring->access->store_to (indio_dev->buffer, rxbuf, time_ns); +iio_push_to_buffers (indio_dev, rxbuf, time_ns); done:kfree (rxbuf);if (b_sent <0 )
drivers/staging/iio/adc/max1363_ring.c +12 -8
@@ -23,28 +23,32 @@int max1363_single_channel_from_ring (const long *mask,struct max1363_state *st) { -struct iio_buffer *ring =iio_priv_to_dev (st)->buffer; +struct iio_dev *indio_dev =iio_priv_to_dev (st); +struct iio_buffer *buffer = indio_dev->buffer;int count =0 , ret, index;u8 *ring_data; index =find_first_bit (mask,MAX1363_MAX_CHANNELS ); -if (!(test_bit (index, st->current_mode->modemask))) { +if (!iio_is_primary_active (indio_dev)) +return -EBUSY ; +if (!(test_bit (index, indio_dev->buffer->scan_mask))) { ret = -EBUSY ; goto error_ret; } - ring_data =kmalloc (ring->access->get_bytes_per_datum (ring), + ring_data =kmalloc (buffer->access-> +get_bytes_per_datum (indio_dev->buffer),GFP_KERNEL );if (ring_data ==NULL ) { ret = -ENOMEM ; goto error_ret; } - ret = ring->access->read_last (ring, ring_data); + ret = buffer->access->read_last (indio_dev->buffer, ring_data);if (ret) goto error_free_ring_data;/* Need a count of channels prior to this one */ - count =bitmap_weight (mask, index -1 ); + count =bitmap_weight (indio_dev->buffer->scan_mask, index -1 );if (st->chip_info->bits !=8 ) ret = ((int )(ring_data[count*2 +0 ] &0x0F ) <<8 ) + (int )(ring_data[count*2 +1 ]);
@@ -90,7 +94,7 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p) d_size = numvals*2 ; else d_size = numvals; -if (indio_dev->buffer->scan_timestamp) { +if (indio_dev->scan_timestamp) { d_size +=sizeof (s64);if (d_size %sizeof (s64)) d_size +=sizeof (s64) - (d_size %sizeof (s64));
@@ -114,9 +118,9 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p) time_ns =iio_get_time_ns (); -if (indio_dev->buffer->scan_timestamp) +if (indio_dev->scan_timestamp)memcpy (rxbuf + d_size -sizeof (s64), &time_ns,sizeof (time_ns)); -iio_push_to_buffer (indio_dev->buffer, rxbuf, time_ns); +iio_push_to_buffers (indio_dev, rxbuf, time_ns); done:iio_trigger_notify_done (indio_dev->trig);
drivers/staging/iio/buffer.h +6 -0
@@ -99,8 +99,11 @@ struct iio_buffer {const struct attribute_group *attrs;struct list_head demux_list;unsigned char *demux_bounce; +struct list_head buffer_list; }; +bool iio_is_primary_active (struct iio_dev *indio_dev); +/** * iio_buffer_init() - Initialize the buffer structure * @buffer: buffer to be initialized
@@ -145,6 +148,9 @@ int iio_scan_mask_set(struct iio_buffer *buffer, int bit);int iio_push_to_buffer (struct iio_buffer *buffer,unsigned char *data,s64 timestamp); +int iio_push_to_buffers (struct iio_dev *indio_dev,unsigned char *data, +s64 timestamp); +int iio_update_demux (struct iio_dev *indio_dev);/**
drivers/staging/iio/gyro/adis16260_ring.c +13 -5
@@ -62,12 +62,20 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct adis16260_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer;int i =0 ;s16 *data; -size_t datasize = ring->access->get_bytes_per_datum (ring); +size_t data_size; - data =kmalloc (datasize ,GFP_KERNEL ); + data_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength)*2 ; + +if (indio_dev->scan_timestamp) { +if (data_size %sizeof (s64)) + data_size +=sizeof (s64) - data_size %sizeof (s64); + data_size +=sizeof (s64); + } + + data =kmalloc (data_size,GFP_KERNEL );if (data ==NULL ) {dev_err (&st->us->dev,"memory alloc failed in ring bh" );return -ENOMEM ;
@@ -80,10 +88,10 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p) data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* 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; - ring->access->store_to (ring, (u8 *)data, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)data, pf->timestamp);iio_trigger_notify_done (indio_dev->trig);kfree (data);
drivers/staging/iio/iio.h +2 -0
@@ -322,11 +322,13 @@ struct iio_dev {struct iio_event_interface *event_interface;struct iio_buffer *buffer; +struct list_head buffer_list;struct mutex mlock;unsigned long *available_scan_masks;unsigned masklength;unsigned long *active_scan_mask; +bool scan_timestamp;struct iio_trigger *trig;struct iio_poll_func *pollfunc;
drivers/staging/iio/iio_simple_dummy_buffer.c +18 -8
@@ -45,18 +45,26 @@ 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 ;/* * The datasize is obtained from the buffer. It was stored when * the preenable setup function was called. */ -size_t datasize = buffer->access->get_bytes_per_datum (buffer); -u16 *data =kmalloc (datasize,GFP_KERNEL ); +size_t data_size; +u16 *data; + + data_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); +if (indio_dev->scan_timestamp) { +if (data_size %sizeof (s64)) + data_size +=sizeof (s64) - (data_size %sizeof (s64)); + data_size +=sizeof (s64); + } + data =kmalloc (data_size,GFP_KERNEL );if (data ==NULL )return -ENOMEM ; -if (buffer->scan_count) { +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength)) {/* * Three common options here: * hardware scans: certain combinations of channels make
@@ -74,8 +82,10 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)* in the constant table fakedata. */ int i, j; -for (i =0 , j =0 ; i < buffer->scan_count; i++) { - j =find_next_bit (buffer->scan_mask, +for (i =0 , j =0 ; + i <bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); i++) { + j =find_next_bit (indio_dev->active_scan_mask, indio_dev->masklength, j +1 );/* random access read form the 'device' */ data[i] = fakedata[j];
@@ -83,11 +93,11 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p) } }/* Store a timestampe at an 8 byte boundary */ -if (buffer->scan_timestamp) +if (indio_dev->scan_timestamp) *(s64 *)(((phys_addr_t )data + len +sizeof (s64) -1 ) & ~(sizeof (s64) -1 )) =iio_get_time_ns (); - buffer->access->store_to (buffer, (u8 *)data, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)data, pf->timestamp);kfree (data);
drivers/staging/iio/impedance-analyzer/ad5933.c +9 -8
@@ -539,17 +539,19 @@ static int ad5933_ring_preenable(struct iio_dev *indio_dev)struct ad5933_state *st =iio_priv (indio_dev);size_t d_size;int ret; +struct iio_buffer *buffer;if (bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))return -EINVAL ; - d_size =bitmap_weight (indio_dev->active_scan_mask, - indio_dev->masklength) * - ad5933_channels[1 ].scan_type.storagebits /8 ; +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { + d_size =bitmap_weight (buffer->scan_mask, + indio_dev->masklength) * + ad5933_channels[1 ].scan_type.storagebits /8 ; -if (indio_dev->buffer->access->set_bytes_per_datum) - indio_dev->buffer->access-> -set_bytes_per_datum (indio_dev->buffer, d_size); +if (buffer->access->set_bytes_per_datum) + buffer->access->set_bytes_per_datum (buffer, d_size); + } ret =ad5933_reset (st);if (ret <0 )
@@ -623,7 +625,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;
@@ -654,7 +655,7 @@ static void ad5933_work(struct work_struct *work) buf[0 ] =be16_to_cpu (buf[0 ]); }/* save datum to the ring */ - ring->access->store_to (ring, (u8 *)buf,iio_get_time_ns ()); +iio_push_to_buffers (indio_dev, (u8 *)buf,iio_get_time_ns ()); }else {/* no data available - try again later */ schedule_delayed_work (&st->work, st->poll_time_jiffies);
drivers/staging/iio/imu/adis16400_ring.c +1 -1
@@ -151,7 +151,7 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)/* Guaranteed to be aligned with 8 byte boundary */ if (ring->scan_timestamp) *((s64 *)(data + ((i +3 )/4 )*4 )) = pf->timestamp; - ring->access->store_to (indio_dev->buffer, (u8 *) data, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *) data, pf->timestamp);iio_trigger_notify_done (indio_dev->trig);
drivers/staging/iio/industrialio-buffer.c +330 -212
675 lines not on this page · raw message
drivers/staging/iio/industrialio-core.c +1 -0
@@ -1313,6 +1313,7 @@ struct iio_dev *iio_allocate_device(int sizeof_priv)return NULL ; }dev_set_name (&dev->dev,"iio:device%d" , dev->id); +INIT_LIST_HEAD (&dev->buffer_list); }return dev;
drivers/staging/iio/meter/ade7758_ring.c +14 -17
@@ -61,7 +61,6 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p) {struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev; -struct iio_buffer *ring = indio_dev->buffer;struct ade7758_state *st =iio_priv (indio_dev);s64 dat64[2 ];u32 *dat32 = (u32 *)dat64;
@@ -71,10 +70,10 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p) *dat32 =get_unaligned_be32 (&st->rx_buf[5 ]) &0xFFFFFF ;/* Guaranteed to be aligned with 8 byte boundary */ -if (ring->scan_timestamp) +if (indio_dev->scan_timestamp) dat64[1 ] = pf->timestamp; - ring->access->store_to (ring, (u8 *)dat64, pf->timestamp); +iio_push_to_buffers (indio_dev, (u8 *)dat64, pf->timestamp);iio_trigger_notify_done (indio_dev->trig);
@@ -91,28 +90,26 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)static int ade7758_ring_preenable (struct iio_dev *indio_dev) {struct ade7758_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer; +struct iio_buffer *buffer;size_t d_size;unsigned channel;if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))return -EINVAL ; - channel =find_first_bit (indio_dev->active_scan_mask, - indio_dev->masklength); - - d_size = st->ade7758_ring_channels[channel].scan_type.storagebits /8 ; - -if (ring->scan_timestamp) { - d_size +=sizeof (s64); +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { + d_size = st->ade7758_ring_channels[0 ].scan_type.storagebits /8 ; +if (buffer->scan_timestamp) { + d_size +=sizeof (s64); +if (d_size %sizeof (s64)) + d_size +=sizeof (s64) - (d_size %sizeof (s64)); + } -if (d_size %sizeof (s64)) - d_size +=sizeof (s64) - (d_size %sizeof (s64)); +if (buffer->access->set_bytes_per_datum) + buffer->access->set_bytes_per_datum (buffer, d_size); } - -if (indio_dev->buffer->access->set_bytes_per_datum) - indio_dev->buffer->access-> -set_bytes_per_datum (indio_dev->buffer, d_size); + channel =find_first_bit (indio_dev->active_scan_mask, + indio_dev->masklength);ade7758_write_waveform_type (&indio_dev->dev, st->ade7758_ring_channels[channel].address);
Signature · 1 line
1.7.7
PATCH 3/5 staging:iio: make update buffers available outside iio.
In reply to Jonathan CameronThis may well go away depending on exactly what the interfaces we end up on for this are.
--- drivers/staging/iio/buffer.h | 4 ++++ drivers/staging/iio/industrialio-buffer.c | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/staging/iio/buffer.h +4 -0
@@ -104,6 +104,10 @@ struct iio_buffer {bool iio_is_primary_active (struct iio_dev *indio_dev); +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
drivers/staging/iio/industrialio-buffer.c +5 -3
@@ -444,13 +444,14 @@ static unsigned long *iio_scan_mask_match(unsigned long *av_masks,return NULL ; } -static int iio_update_buffers (struct iio_dev *indio_dev, -struct iio_buffer *insert_buffer, -struct iio_buffer *remove_buffer) +int iio_update_buffers (struct iio_dev *indio_dev, +struct iio_buffer *insert_buffer, +struct iio_buffer *remove_buffer) {int ret;struct iio_buffer *buffer;unsigned long *compound_mask; +/* Wind down existing buffers - iff there are any */ if (!list_empty (&indio_dev->buffer_list)) {
@@ -572,6 +573,7 @@ error_free_compound_mask: error_ret:return ret; } +EXPORT_SYMBOL_GPL (iio_update_buffers); ssize_t iio_buffer_store_enable(struct device *dev, struct device_attribute *attr,
Signature · 1 line
1.7.7
PATCH 1/5 staging:iio: scrap scan_count and ensure all drivers use active_scan_mask
In reply to Jonathan CameronObviously drivers should only use this for pushing to buffers. They need buffer->scan_mask for pulling from them post demux.
--- drivers/staging/iio/accel/adis16201_ring.c | 10 +++++----- drivers/staging/iio/accel/adis16203_ring.c | 10 +++++----- drivers/staging/iio/accel/adis16204_ring.c | 10 +++++----- drivers/staging/iio/accel/adis16209_ring.c | 5 +++-- drivers/staging/iio/accel/adis16240_ring.c | 5 +++-- drivers/staging/iio/accel/lis3l02dq_ring.c | 23 +++++++++++++---------- drivers/staging/iio/adc/ad7192.c | 10 ++++++---- drivers/staging/iio/adc/ad7298_ring.c | 12 +++++++----- drivers/staging/iio/adc/ad7476_ring.c | 3 ++- drivers/staging/iio/adc/ad7793.c | 11 ++++++----- drivers/staging/iio/adc/ad7887_ring.c | 8 +++++--- drivers/staging/iio/adc/ad799x_ring.c | 13 ++++++++----- drivers/staging/iio/buffer.h | 2 -- drivers/staging/iio/gyro/adis16260_ring.c | 5 +++-- drivers/staging/iio/impedance-analyzer/ad5933.c | 14 ++++++++------ drivers/staging/iio/imu/adis16400_ring.c | 19 +++++++++++-------- drivers/staging/iio/meter/ade7758_ring.c | 7 ++++--- 17 files changed, 94 insertions(+), 73 deletions(-)
drivers/staging/iio/accel/adis16201_ring.c +5 -5
@@ -73,11 +73,11 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)return -ENOMEM ; } -if (ring->scan_count) -if (adis16201_read_ring_data (indio_dev, st->rx) >=0 ) -for (; i < ring->scan_count; i++) - data[i] =be16_to_cpup ( - (__be16 *)&(st->rx[i*2 ])); +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength) + &&adis16201_read_ring_data (indio_dev, st->rx) >=0 ) +for (; i <bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); i++) + data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* Guaranteed to be aligned with 8 byte boundary */ if (ring->scan_timestamp)
drivers/staging/iio/accel/adis16203_ring.c +5 -5
@@ -73,11 +73,11 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p)return -ENOMEM ; } -if (ring->scan_count) -if (adis16203_read_ring_data (&indio_dev->dev, st->rx) >=0 ) -for (; i < ring->scan_count; i++) - data[i] =be16_to_cpup ( - (__be16 *)&(st->rx[i*2 ])); +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength) && +adis16203_read_ring_data (&indio_dev->dev, st->rx) >=0 ) +for (; i <bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); i++) + data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* Guaranteed to be aligned with 8 byte boundary */ if (ring->scan_timestamp)
drivers/staging/iio/accel/adis16204_ring.c +5 -5
@@ -70,11 +70,11 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p)return -ENOMEM ; } -if (ring->scan_count) -if (adis16204_read_ring_data (&indio_dev->dev, st->rx) >=0 ) -for (; i < ring->scan_count; i++) - data[i] =be16_to_cpup ( - (__be16 *)&(st->rx[i*2 ])); +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength) && +adis16204_read_ring_data (&indio_dev->dev, st->rx) >=0 ) +for (; i <bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); i++) + data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* Guaranteed to be aligned with 8 byte boundary */ if (ring->scan_timestamp)
drivers/staging/iio/accel/adis16209_ring.c +3 -2
@@ -71,9 +71,10 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p)return -ENOMEM ; } -if (ring->scan_count && +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength) &&adis16209_read_ring_data (&indio_dev->dev, st->rx) >=0 ) -for (; i < ring->scan_count; i++) +for (; i <bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); i++) data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* Guaranteed to be aligned with 8 byte boundary */
drivers/staging/iio/accel/adis16240_ring.c +3 -2
@@ -68,9 +68,10 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p)return -ENOMEM ; } -if (ring->scan_count && +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength) &&adis16240_read_ring_data (&indio_dev->dev, st->rx) >=0 ) -for (; i < ring->scan_count; i++) +for (; i <bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); i++) data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* Guaranteed to be aligned with 8 byte boundary */
drivers/staging/iio/accel/lis3l02dq_ring.c +13 -10
@@ -86,13 +86,13 @@ static const u8 read_all_tx_array[] = {**/ static int lis3l02dq_read_all (struct iio_dev *indio_dev,u8 *rx_array) { -struct iio_buffer *buffer = indio_dev->buffer;struct lis3l02dq_state *st =iio_priv (indio_dev);struct spi_transfer *xfers;struct spi_message msg;int ret, i, j =0 ; - xfers =kzalloc ((buffer->scan_count) *2 + xfers =kzalloc (bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) *2 *sizeof (*xfers),GFP_KERNEL );if (!xfers)return -ENOMEM ;
@@ -100,7 +100,7 @@ static int lis3l02dq_read_all(struct iio_dev *indio_dev, u8 *rx_array)mutex_lock (&st->buf_lock);for (i =0 ; i <ARRAY_SIZE (read_all_tx_array)/4 ; i++) -if (test_bit (i, buffer->scan_mask)) { +if (test_bit (i, indio_dev->active_scan_mask)) {/* lower byte */ xfers[j].tx_buf = st->tx +2 *j; st->tx[2 *j] = read_all_tx_array[i*4 ];
@@ -128,7 +128,8 @@ static int lis3l02dq_read_all(struct iio_dev *indio_dev, u8 *rx_array)* values in alternate bytes */ spi_message_init (&msg); -for (j =0 ; j < buffer->scan_count *2 ; j++) +for (j =0 ; j <bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) *2 ; j++)spi_message_add_tail (&xfers[j], &msg); ret =spi_sync (st->us, &msg);
@@ -144,14 +145,16 @@ static int lis3l02dq_get_buffer_element(struct iio_dev *indio_dev,int ret, i;u8 *rx_array ;s16 *data = (s16 *)buf; +int scan_count =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); - rx_array =kzalloc (4 * (indio_dev->buffer->scan_count),GFP_KERNEL ); + rx_array =kzalloc (4 * scan_count,GFP_KERNEL );if (rx_array ==NULL )return -ENOMEM ; ret =lis3l02dq_read_all (indio_dev, rx_array);if (ret <0 )return ret; -for (i =0 ; i < indio_dev->buffer->scan_count; i++) +for (i =0 ; i < scan_count; i++) data[i] =combine_8_to_16 (rx_array[i*4 +1 ], rx_array[i*4 +3 ]);kfree (rx_array);
@@ -174,7 +177,7 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)return -ENOMEM ; } -if (buffer->scan_count) +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 */
@@ -362,17 +365,17 @@ static int lis3l02dq_buffer_postenable(struct iio_dev *indio_dev)if (ret) goto error_ret; -if (iio_scan_mask_query (indio_dev->buffer,0 )) { +if (test_bit (0 , indio_dev->active_scan_mask)) { t |=LIS3L02DQ_REG_CTRL_1_AXES_X_ENABLE ; oneenabled = true; }else t &= ~LIS3L02DQ_REG_CTRL_1_AXES_X_ENABLE ; -if (iio_scan_mask_query (indio_dev->buffer,1 )) { +if (test_bit (1 , indio_dev->active_scan_mask)) { t |=LIS3L02DQ_REG_CTRL_1_AXES_Y_ENABLE ; oneenabled = true; }else t &= ~LIS3L02DQ_REG_CTRL_1_AXES_Y_ENABLE ; -if (iio_scan_mask_query (indio_dev->buffer,2 )) { +if (test_bit (2 , indio_dev->active_scan_mask)) { t |=LIS3L02DQ_REG_CTRL_1_AXES_Z_ENABLE ; oneenabled = true; }else
drivers/staging/iio/adc/ad7192.c +6 -4
@@ -479,12 +479,14 @@ static int ad7192_ring_preenable(struct iio_dev *indio_dev)size_t d_size;unsigned channel; -if (!ring->scan_count) +if (bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))return -EINVAL ; - channel =find_first_bit (ring->scan_mask, indio_dev->masklength); + channel =find_first_bit (indio_dev->active_scan_mask, + indio_dev->masklength); - d_size = ring->scan_count * + d_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) * indio_dev->channels[0 ].scan_type.storagebits /8 ;if (ring->scan_timestamp) {
@@ -544,7 +546,7 @@ static irqreturn_t ad7192_trigger_handler(int irq, void *p)s64 dat64[2 ];s32 *dat32 = (s32 *)dat64; -if (ring->scan_count) +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))__ad7192_read_reg (st,1 ,1 ,AD7192_REG_DATA , dat32, indio_dev->channels[0 ].scan_type.realbits/8 );
drivers/staging/iio/adc/ad7298_ring.c +7 -5
@@ -61,8 +61,9 @@ static int ad7298_ring_preenable(struct iio_dev *indio_dev)size_t d_size;int i, m;unsigned short command; - - d_size = ring->scan_count * (AD7298_STORAGE_BITS /8 ); +int scan_count =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); + d_size = scan_count * (AD7298_STORAGE_BITS /8 );if (ring->scan_timestamp) { d_size +=sizeof (s64);
@@ -79,7 +80,7 @@ static int ad7298_ring_preenable(struct iio_dev *indio_dev) command =AD7298_WRITE | st->ext_ref;for (i =0 , m =AD7298_CH (0 ); i <AD7298_MAX_CHAN ; i++, m >>=1 ) -if (test_bit (i, ring->scan_mask)) +if (test_bit (i, indio_dev->active_scan_mask)) command |= m; st->tx_buf[0 ] =cpu_to_be16 (command);
@@ -96,7 +97,7 @@ static int ad7298_ring_preenable(struct iio_dev *indio_dev)spi_message_add_tail (&st->ring_xfer[0 ], &st->ring_msg);spi_message_add_tail (&st->ring_xfer[1 ], &st->ring_msg); -for (i =0 ; i < ring->scan_count; i++) { +for (i =0 ; i < scan_count; i++) { st->ring_xfer[i +2 ].rx_buf = &st->rx_buf[i]; st->ring_xfer[i +2 ].len =2 ; st->ring_xfer[i +2 ].cs_change =1 ;
@@ -134,7 +135,8 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p) &time_ns, sizeof(time_ns)); } -for (i =0 ; i < ring->scan_count; i++) +for (i =0 ; i <bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); i++) buf[i] =be16_to_cpu (st->rx_buf[i]); indio_dev->buffer->access->store_to (ring, (u8 *)buf, time_ns);
drivers/staging/iio/adc/ad7476_ring.c +2 -1
@@ -56,7 +56,8 @@ static int ad7476_ring_preenable(struct iio_dev *indio_dev)struct ad7476_state *st =iio_priv (indio_dev);struct iio_buffer *ring = indio_dev->buffer; - st->d_size = ring->scan_count * + st->d_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) * st->chip_info->channel[0 ].scan_type.storagebits /8 ;if (ring->scan_timestamp) {
drivers/staging/iio/adc/ad7793.c +6 -5
@@ -341,14 +341,15 @@ static int ad7793_ring_preenable(struct iio_dev *indio_dev)size_t d_size;unsigned channel; -if (!ring->scan_count) +if (bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))return -EINVAL ; - channel =find_first_bit (ring->scan_mask, + channel =find_first_bit (indio_dev->active_scan_mask, indio_dev->masklength); - d_size = ring->scan_count * - indio_dev->channels[0 ].scan_type.storagebits /8 ; + d_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) * + indio_dev->channels[0 ].scan_type.storagebits /8 ;if (ring->scan_timestamp) { d_size +=sizeof (s64);
@@ -410,7 +411,7 @@ static irqreturn_t ad7793_trigger_handler(int irq, void *p)s64 dat64[2 ];s32 *dat32 = (s32 *)dat64; -if (ring->scan_count) +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))__ad7793_read_reg (st,1 ,1 ,AD7793_REG_DATA , dat32, indio_dev->channels[0 ].scan_type.realbits/8 );
drivers/staging/iio/adc/ad7887_ring.c +5 -3
@@ -65,7 +65,8 @@ static int ad7887_ring_preenable(struct iio_dev *indio_dev)struct ad7887_state *st =iio_priv (indio_dev);struct iio_buffer *ring = indio_dev->buffer; - st->d_size = ring->scan_count * + st->d_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) * st->chip_info->channel[0 ].scan_type.storagebits /8 ;if (ring->scan_timestamp) {
@@ -80,7 +81,7 @@ static int ad7887_ring_preenable(struct iio_dev *indio_dev)set_bytes_per_datum (indio_dev->buffer, st->d_size);/* We know this is a single long so can 'cheat' */ -switch (*ring->scan_mask) { +switch (*indio_dev->active_scan_mask) {case (1 <<0 ): st->ring_msg = &st->msg[AD7887_CH0 ];break ;
@@ -121,7 +122,8 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)__u8 *buf;int b_sent; -unsigned int bytes = ring->scan_count * +unsigned int bytes =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) * st->chip_info->channel[0 ].scan_type.storagebits /8 ; buf =kzalloc (st->d_size,GFP_KERNEL );
drivers/staging/iio/adc/ad799x_ring.c +8 -5
@@ -71,9 +71,10 @@ static int ad799x_ring_preenable(struct iio_dev *indio_dev)*/ if (st->id == ad7997 || st->id == ad7998) -ad7997_8_set_scan_mode (st, *ring->scan_mask); +ad7997_8_set_scan_mode (st, *indio_dev->active_scan_mask); - st->d_size = ring->scan_count *2 ; + st->d_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) *2 ;if (ring->scan_timestamp) { st->d_size +=sizeof (s64);
@@ -115,12 +116,13 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)case ad7991:case ad7995:case ad7999: - cmd = st->config | (*ring->scan_mask <<AD799X_CHANNEL_SHIFT ); + cmd = st->config | + (*indio_dev->active_scan_mask <<AD799X_CHANNEL_SHIFT );break ;case ad7992:case ad7993:case ad7994: - cmd = (*ring->scan_mask <<AD799X_CHANNEL_SHIFT ) | + cmd = (*indio_dev->active_scan_mask <<AD799X_CHANNEL_SHIFT ) |AD7998_CONV_RES_REG ;break ;case ad7997:
@@ -132,7 +134,8 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p) } b_sent =i2c_smbus_read_i2c_block_data (st->client, - cmd, ring->scan_count *2 , rxbuf); + cmd,bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) *2 , rxbuf);if (b_sent <0 ) goto done;
drivers/staging/iio/buffer.h +0 -2
@@ -73,7 +73,6 @@ struct iio_buffer_access_funcs {* @bytes_per_datum: [DEVICE] size of individual datum including timestamp * @scan_el_attrs: [DRIVER] control of scan elements if that scan mode * control method is used -* @scan_count: [INTERN] the number of elements in the current scan mode * @scan_mask: [INTERN] bitmask used in masking scan mode elements * @scan_timestamp: [INTERN] does the scan mode include a timestamp * @access: [DRIVER] buffer access functions associated with the
@@ -88,7 +87,6 @@ struct iio_buffer {int length;int bytes_per_datum;struct attribute_group *scan_el_attrs; -int scan_count;long *scan_mask;bool scan_timestamp;unsigned scan_index_timestamp;
drivers/staging/iio/gyro/adis16260_ring.c +3 -2
@@ -73,9 +73,10 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)return -ENOMEM ; } -if (ring->scan_count && +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength) &&adis16260_read_ring_data (&indio_dev->dev, st->rx) >=0 ) -for (; i < ring->scan_count; i++) +for (; i <bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); i++) data[i] =be16_to_cpup ((__be16 *)&(st->rx[i*2 ]));/* Guaranteed to be aligned with 8 byte boundary */
drivers/staging/iio/impedance-analyzer/ad5933.c +8 -6
@@ -537,14 +537,14 @@ static const struct iio_info ad5933_info = {static int ad5933_ring_preenable (struct iio_dev *indio_dev) {struct ad5933_state *st =iio_priv (indio_dev); -struct iio_buffer *ring = indio_dev->buffer;size_t d_size;int ret; -if (!ring->scan_count) +if (bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))return -EINVAL ; - d_size = ring->scan_count * + d_size =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength) * ad5933_channels[1 ].scan_type.storagebits /8 ;if (indio_dev->buffer->access->set_bytes_per_datum)
@@ -640,12 +640,14 @@ static void ad5933_work(struct work_struct *work)ad5933_i2c_read (st->client,AD5933_REG_STATUS ,1 , &status);if (status &AD5933_STAT_DATA_VALID ) { +int scan_count =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength);ad5933_i2c_read (st->client, -test_bit (1 , ring->scan_mask) ? +test_bit (1 , indio_dev->active_scan_mask) ?AD5933_REG_REAL_DATA :AD5933_REG_IMAG_DATA , - ring->scan_count *2 , (u8 *)buf); + scan_count *2 , (u8 *)buf); -if (ring->scan_count ==2 ) { +if (scan_count ==2 ) { buf[0 ] =be16_to_cpu (buf[0 ]); buf[1 ] =be16_to_cpu (buf[1 ]); }else {
drivers/staging/iio/imu/adis16400_ring.c +11 -8
@@ -78,14 +78,16 @@ static int adis16350_spi_read_all(struct device *dev, u8 *rx)struct spi_message msg;int i, j =0 , ret;struct spi_transfer *xfers; +int scan_count =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); - xfers =kzalloc (sizeof (*xfers)*indio_dev->buffer->scan_count +1 , + xfers =kzalloc (sizeof (*xfers)*(scan_count +1 ),GFP_KERNEL );if (xfers ==NULL )return -ENOMEM ;for (i =0 ; i <ARRAY_SIZE (read_all_tx_array); i++) -if (test_bit (i, indio_dev->buffer->scan_mask)) { +if (test_bit (i, indio_dev->active_scan_mask)) { xfers[j].tx_buf = &read_all_tx_array[i]; xfers[j].bits_per_word =16 ; xfers[j].len =2 ;
@@ -96,7 +98,7 @@ static int adis16350_spi_read_all(struct device *dev, u8 *rx) xfers[j].len =2 ;spi_message_init (&msg); -for (j =0 ; j < indio_dev->buffer->scan_count +1 ; j++) +for (j =0 ; j < scan_count +1 ; j++)spi_message_add_tail (&xfers[j], &msg); ret =spi_sync (st->us, &msg);
@@ -118,26 +120,27 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)s16 *data;size_t datasize = ring->access->get_bytes_per_datum (ring);/* Asumption that long is enough for maximum channels */ -unsigned long mask = *ring->scan_mask; - +unsigned long mask = *indio_dev->active_scan_mask; +int scan_count =bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); data =kmalloc (datasize ,GFP_KERNEL );if (data ==NULL ) {dev_err (&st->us->dev,"memory alloc failed in ring bh" );return -ENOMEM ; } -if (ring->scan_count) { +if (scan_count) {if (st->variant->flags &ADIS16400_NO_BURST ) { ret =adis16350_spi_read_all (&indio_dev->dev, st->rx);if (ret <0 ) goto err; -for (; i < ring->scan_count; i++) +for (; i < scan_count; i++) data[i] = *(s16 *)(st->rx + i*2 ); }else { ret =adis16400_spi_read_burst (&indio_dev->dev, st->rx);if (ret <0 ) goto err; -for (; i < indio_dev->buffer->scan_count; i++) { +for (; i < scan_count; i++) { j =__ffs (mask); mask &= ~(1 << j); data[i] = be16_to_cpup(
drivers/staging/iio/meter/ade7758_ring.c +4 -3
@@ -66,7 +66,7 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)s64 dat64[2 ];u32 *dat32 = (u32 *)dat64; -if (ring->scan_count) +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))if (ade7758_spi_read_burst (&indio_dev->dev) >=0 ) *dat32 =get_unaligned_be32 (&st->rx_buf[5 ]) &0xFFFFFF ;
@@ -95,10 +95,11 @@ static int ade7758_ring_preenable(struct iio_dev *indio_dev)size_t d_size;unsigned channel; -if (!ring->scan_count) +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength))return -EINVAL ; - channel =find_first_bit (ring->scan_mask, indio_dev->masklength); + channel =find_first_bit (indio_dev->active_scan_mask, + indio_dev->masklength); d_size = st->ade7758_ring_channels[channel].scan_type.storagebits /8 ;
Signature · 1 line
1.7.7
PATCH 4/5 staging:iio: add a callback buffer for in kernel push interface
In reply to Jonathan CameronThis 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/staging/iio/Makefile | 2 +- drivers/staging/iio/buffer_cb.c | 115 +++++++++++++++++++++++++++++++++++++++ drivers/staging/iio/inkern.h | 35 ++++++++++++ 3 files changed, 151 insertions(+), 1 deletions(-)
drivers/staging/iio/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-y = inkern.o obj-$(CONFIG_IIO) += industrialio.o industrialio-y := industrialio-core.o -industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o +industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o buffer_cb.o industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o obj-$(CONFIG_IIO_SW_RING) += ring_sw.o
drivers/staging/iio/buffer_cb.c new file +115 -0
115 lines not on this page · raw message
drivers/staging/iio/inkern.h +35 -0
@@ -50,6 +50,41 @@ struct iio_channel **iio_st_channel_get_all(const struct device *dev,void iio_st_channel_release_all (struct iio_channel **chan);/** +* iio_st_channel_get_all_cb() - register callback for triggered capture +* @dev: device of client +* @name: name of client device +* @cb: callback +* @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 ; +struct iio_cb_buffer *iio_st_channel_get_all_cb (const struct device *dev, +const char *name, +int (*cb)(u8 *data, +void *private), +void *private); +/** +* iio_st_channel_release_all_cb() - release and unregister the callback. +* @cb_buffer: the callback buffer that was allocated +*/ +void iio_st_channel_release_all_cb (struct iio_cb_buffer *cb_buffer); + +/** +* iio_st_channel_start_all_cb() - start the flow of data through callback +* @cb_buff: the callback buffer that was allocated +*/ +void iio_st_channel_start_all_cb (struct iio_cb_buffer *cb_buff); + +void iio_st_channel_stop_all_cb (struct iio_cb_buffer *cb_buff); + + +struct iio_channel +**iio_st_channel_cb_get_channels (const struct iio_cb_buffer *cb_buffer); + +/** * iio_st_read_channel_raw() - read from a given channel * @channel: the channel being queried. * @val: value read back.
Signature · 1 line
1.7.7
PATCH 5/5 staging:iio: Proof of concept input driver.
In reply to Jonathan CameronThis is no where near ready to merge. Lots of stuff missing.
--- drivers/staging/iio/Kconfig | 7 +++ drivers/staging/iio/Makefile | 1 + drivers/staging/iio/iio_input.c | 106 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 0 deletions(-)
drivers/staging/iio/Kconfig +7 -0
@@ -12,6 +12,13 @@ menuconfig IIO drivers/staging/iio/Documentation for more information. if IIO +config IIO_ST_INPUT + tristate "Input driver that uses channels specified via iio maps" + depends on INPUT + help + Proof of concept user of the in kernel push interface. Not anywhere + near ready for production use. + config IIO_ST_HWMON tristate "Hwmon driver that uses channels specified via iio maps" depends on HWMON
drivers/staging/iio/Makefile +1 -0
@@ -18,6 +18,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 +106 -0
106 lines not on this page · raw message
Signature · 1 line
1.7.7