summaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio/adc/ad7606_ring.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/iio/adc/ad7606_ring.c')
-rw-r--r--drivers/staging/iio/adc/ad7606_ring.c152
1 files changed, 41 insertions, 111 deletions
diff --git a/drivers/staging/iio/adc/ad7606_ring.c b/drivers/staging/iio/adc/ad7606_ring.c
index b32cb0dea6d8..a199bf48396c 100644
--- a/drivers/staging/iio/adc/ad7606_ring.c
+++ b/drivers/staging/iio/adc/ad7606_ring.c
@@ -7,7 +7,6 @@
#include <linux/interrupt.h>
#include <linux/gpio.h>
-#include <linux/workqueue.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/slab.h>
@@ -21,99 +20,19 @@
#include "ad7606.h"
-static IIO_SCAN_EL_C(in0, 0, 0, NULL);
-static IIO_SCAN_EL_C(in1, 1, 0, NULL);
-static IIO_SCAN_EL_C(in2, 2, 0, NULL);
-static IIO_SCAN_EL_C(in3, 3, 0, NULL);
-static IIO_SCAN_EL_C(in4, 4, 0, NULL);
-static IIO_SCAN_EL_C(in5, 5, 0, NULL);
-static IIO_SCAN_EL_C(in6, 6, 0, NULL);
-static IIO_SCAN_EL_C(in7, 7, 0, NULL);
-
-static IIO_SCAN_EL_TIMESTAMP(8);
-static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
-
-static ssize_t ad7606_show_type(struct device *dev,
- struct device_attribute *attr,
- char *buf)
+int ad7606_scan_from_ring(struct iio_dev *indio_dev, unsigned ch)
{
- struct iio_ring_buffer *ring = dev_get_drvdata(dev);
- struct iio_dev *indio_dev = ring->indio_dev;
- struct ad7606_state *st = indio_dev->dev_data;
-
- return sprintf(buf, "%c%d/%d\n", st->chip_info->sign,
- st->chip_info->bits, st->chip_info->bits);
-}
-static IIO_DEVICE_ATTR(in_type, S_IRUGO, ad7606_show_type, NULL, 0);
-
-static struct attribute *ad7606_scan_el_attrs[] = {
- &iio_scan_el_in0.dev_attr.attr,
- &iio_const_attr_in0_index.dev_attr.attr,
- &iio_scan_el_in1.dev_attr.attr,
- &iio_const_attr_in1_index.dev_attr.attr,
- &iio_scan_el_in2.dev_attr.attr,
- &iio_const_attr_in2_index.dev_attr.attr,
- &iio_scan_el_in3.dev_attr.attr,
- &iio_const_attr_in3_index.dev_attr.attr,
- &iio_scan_el_in4.dev_attr.attr,
- &iio_const_attr_in4_index.dev_attr.attr,
- &iio_scan_el_in5.dev_attr.attr,
- &iio_const_attr_in5_index.dev_attr.attr,
- &iio_scan_el_in6.dev_attr.attr,
- &iio_const_attr_in6_index.dev_attr.attr,
- &iio_scan_el_in7.dev_attr.attr,
- &iio_const_attr_in7_index.dev_attr.attr,
- &iio_const_attr_timestamp_index.dev_attr.attr,
- &iio_scan_el_timestamp.dev_attr.attr,
- &iio_const_attr_timestamp_type.dev_attr.attr,
- &iio_dev_attr_in_type.dev_attr.attr,
- NULL,
-};
-
-static mode_t ad7606_scan_el_attr_is_visible(struct kobject *kobj,
- struct attribute *attr, int n)
-{
- struct device *dev = container_of(kobj, struct device, kobj);
- struct iio_ring_buffer *ring = dev_get_drvdata(dev);
- struct iio_dev *indio_dev = ring->indio_dev;
- struct ad7606_state *st = indio_dev->dev_data;
-
- mode_t mode = attr->mode;
-
- if (st->chip_info->num_channels <= 6 &&
- (attr == &iio_scan_el_in7.dev_attr.attr ||
- attr == &iio_const_attr_in7_index.dev_attr.attr ||
- attr == &iio_scan_el_in6.dev_attr.attr ||
- attr == &iio_const_attr_in6_index.dev_attr.attr))
- mode = 0;
- else if (st->chip_info->num_channels <= 4 &&
- (attr == &iio_scan_el_in5.dev_attr.attr ||
- attr == &iio_const_attr_in5_index.dev_attr.attr ||
- attr == &iio_scan_el_in4.dev_attr.attr ||
- attr == &iio_const_attr_in4_index.dev_attr.attr))
- mode = 0;
-
- return mode;
-}
-
-static struct attribute_group ad7606_scan_el_group = {
- .name = "scan_elements",
- .attrs = ad7606_scan_el_attrs,
- .is_visible = ad7606_scan_el_attr_is_visible,
-};
-
-int ad7606_scan_from_ring(struct ad7606_state *st, unsigned ch)
-{
- struct iio_ring_buffer *ring = st->indio_dev->ring;
+ struct iio_ring_buffer *ring = indio_dev->ring;
int ret;
u16 *ring_data;
- ring_data = kmalloc(ring->access.get_bytes_per_datum(ring), GFP_KERNEL);
+ ring_data = kmalloc(ring->access->get_bytes_per_datum(ring),
+ GFP_KERNEL);
if (ring_data == NULL) {
ret = -ENOMEM;
goto error_ret;
}
- ret = ring->access.read_last(ring, (u8 *) ring_data);
+ ret = ring->access->read_last(ring, (u8 *) ring_data);
if (ret)
goto error_free_ring_data;
@@ -134,12 +53,12 @@ error_ret:
**/
static int ad7606_ring_preenable(struct iio_dev *indio_dev)
{
- struct ad7606_state *st = indio_dev->dev_data;
+ struct ad7606_state *st = iio_priv(indio_dev);
struct iio_ring_buffer *ring = indio_dev->ring;
size_t d_size;
d_size = st->chip_info->num_channels *
- st->chip_info->bits / 8;
+ st->chip_info->channels[0].scan_type.storagebits / 8;
if (ring->scan_timestamp) {
d_size += sizeof(s64);
@@ -148,8 +67,8 @@ static int ad7606_ring_preenable(struct iio_dev *indio_dev)
d_size += sizeof(s64) - (d_size % sizeof(s64));
}
- if (ring->access.set_bytes_per_datum)
- ring->access.set_bytes_per_datum(ring, d_size);
+ if (ring->access->set_bytes_per_datum)
+ ring->access->set_bytes_per_datum(ring, d_size);
st->d_size = d_size;
@@ -157,16 +76,20 @@ static int ad7606_ring_preenable(struct iio_dev *indio_dev)
}
/**
- * ad7606_poll_func_th() th of trigger launched polling to ring buffer
+ * ad7606_trigger_handler_th() th/bh of trigger launched polling to ring buffer
*
**/
-static void ad7606_poll_func_th(struct iio_dev *indio_dev, s64 time)
+static irqreturn_t ad7606_trigger_handler_th_bh(int irq, void *p)
{
- struct ad7606_state *st = indio_dev->dev_data;
+ struct iio_poll_func *pf = p;
+ struct iio_dev *indio_dev = pf->private_data;
+ struct ad7606_state *st = iio_priv(indio_dev);
+
gpio_set_value(st->pdata->gpio_convst, 1);
- return;
+ return IRQ_HANDLED;
}
+
/**
* ad7606_poll_bh_to_ring() bh of trigger launched polling to ring buffer
* @work_s: the work struct through which this was scheduled
@@ -180,17 +103,12 @@ 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 = st->indio_dev;
- struct iio_sw_ring_buffer *sw_ring = iio_to_sw_ring(indio_dev->ring);
+ struct iio_dev *indio_dev = iio_priv_to_dev(st);
struct iio_ring_buffer *ring = indio_dev->ring;
s64 time_ns;
__u8 *buf;
int ret;
- /* Ensure only one copy of this function running at a time */
- if (atomic_inc_return(&st->protect_ring) > 1)
- return;
-
buf = kzalloc(st->d_size, GFP_KERNEL);
if (buf == NULL)
return;
@@ -225,16 +143,22 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
memcpy(buf + st->d_size - sizeof(s64),
&time_ns, sizeof(time_ns));
- ring->access.store_to(&sw_ring->buf, buf, time_ns);
+ ring->access->store_to(indio_dev->ring, buf, time_ns);
done:
gpio_set_value(st->pdata->gpio_convst, 0);
+ iio_trigger_notify_done(indio_dev->trig);
kfree(buf);
- atomic_dec(&st->protect_ring);
}
+static const struct iio_ring_setup_ops ad7606_ring_setup_ops = {
+ .preenable = &ad7606_ring_preenable,
+ .postenable = &iio_triggered_ring_postenable,
+ .predisable = &iio_triggered_ring_predisable,
+};
+
int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
{
- struct ad7606_state *st = indio_dev->dev_data;
+ struct ad7606_state *st = iio_priv(indio_dev);
int ret;
indio_dev->ring = iio_sw_rb_allocate(indio_dev);
@@ -244,17 +168,22 @@ int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
}
/* Effectively select the ring buffer implementation */
- iio_ring_sw_register_funcs(&indio_dev->ring->access);
- ret = iio_alloc_pollfunc(indio_dev, NULL, &ad7606_poll_func_th);
- if (ret)
+ indio_dev->ring->access = &ring_sw_access_funcs;
+ indio_dev->pollfunc = iio_alloc_pollfunc(&ad7606_trigger_handler_th_bh,
+ &ad7606_trigger_handler_th_bh,
+ 0,
+ indio_dev,
+ "%s_consumer%d",
+ indio_dev->name,
+ indio_dev->id);
+ if (indio_dev->pollfunc == NULL) {
+ ret = -ENOMEM;
goto error_deallocate_sw_rb;
+ }
/* Ring buffer functions - here trigger setup related */
- indio_dev->ring->preenable = &ad7606_ring_preenable;
- indio_dev->ring->postenable = &iio_triggered_ring_postenable;
- indio_dev->ring->predisable = &iio_triggered_ring_predisable;
- indio_dev->ring->scan_el_attrs = &ad7606_scan_el_group;
+ indio_dev->ring->setup_ops = &ad7606_ring_setup_ops;
indio_dev->ring->scan_timestamp = true ;
INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring);
@@ -262,6 +191,7 @@ int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
/* Flag that polled ring buffering is possible */
indio_dev->modes |= INDIO_RING_TRIGGERED;
return 0;
+
error_deallocate_sw_rb:
iio_sw_rb_free(indio_dev->ring);
error_ret:
@@ -275,6 +205,6 @@ void ad7606_ring_cleanup(struct iio_dev *indio_dev)
iio_trigger_dettach_poll_func(indio_dev->trig,
indio_dev->pollfunc);
}
- kfree(indio_dev->pollfunc);
+ iio_dealloc_pollfunc(indio_dev->pollfunc);
iio_sw_rb_free(indio_dev->ring);
}