Commit 05c2858d authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:accel:adis16201 move to irqchip based trigger handling.

Untested.
Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 20e79c51
...@@ -64,9 +64,6 @@ ...@@ -64,9 +64,6 @@
/** /**
* struct adis16201_state - device instance specific data * struct adis16201_state - device instance specific data
* @us: actual spi_device * @us: actual spi_device
* @work_trigger_to_ring: bh for triggered event handling
* @inter: used to check if new interrupt has been triggered
* @last_timestamp: passing timestamp from th to bh of interrupt handler
* @indio_dev: industrial I/O device structure * @indio_dev: industrial I/O device structure
* @trig: data ready trigger registered with iio * @trig: data ready trigger registered with iio
* @tx: transmit buffer * @tx: transmit buffer
...@@ -75,8 +72,6 @@ ...@@ -75,8 +72,6 @@
**/ **/
struct adis16201_state { struct adis16201_state {
struct spi_device *us; struct spi_device *us;
struct work_struct work_trigger_to_ring;
s64 last_timestamp;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct iio_trigger *trig; struct iio_trigger *trig;
u8 *tx; u8 *tx;
......
...@@ -65,17 +65,6 @@ static struct attribute_group adis16201_scan_el_group = { ...@@ -65,17 +65,6 @@ static struct attribute_group adis16201_scan_el_group = {
.name = "scan_elements", .name = "scan_elements",
}; };
/**
* adis16201_poll_func_th() top half interrupt handler called by trigger
* @private_data: iio_dev
**/
static void adis16201_poll_func_th(struct iio_dev *indio_dev, s64 time)
{
struct adis16201_state *st = iio_dev_get_devdata(indio_dev);
st->last_timestamp = time;
schedule_work(&st->work_trigger_to_ring);
}
/** /**
* adis16201_read_ring_data() read data registers which will be placed into ring * adis16201_read_ring_data() read data registers which will be placed into ring
* @dev: device associated with child of actual device (iio_dev or iio_trig) * @dev: device associated with child of actual device (iio_dev or iio_trig)
...@@ -120,12 +109,12 @@ static int adis16201_read_ring_data(struct device *dev, u8 *rx) ...@@ -120,12 +109,12 @@ static int adis16201_read_ring_data(struct device *dev, u8 *rx)
/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device /* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
* specific to be rolled into the core. * specific to be rolled into the core.
*/ */
static void adis16201_trigger_bh_to_ring(struct work_struct *work_s) static irqreturn_t adis16201_trigger_handler(int irq, void *p)
{ {
struct adis16201_state *st struct iio_poll_func *pf = p;
= container_of(work_s, struct adis16201_state, struct iio_dev *indio_dev = pf->private_data;
work_trigger_to_ring); struct adis16201_state *st = iio_dev_get_devdata(indio_dev);
struct iio_ring_buffer *ring = st->indio_dev->ring; struct iio_ring_buffer *ring = indio_dev->ring;
int i = 0; int i = 0;
s16 *data; s16 *data;
...@@ -134,7 +123,7 @@ static void adis16201_trigger_bh_to_ring(struct work_struct *work_s) ...@@ -134,7 +123,7 @@ static void adis16201_trigger_bh_to_ring(struct work_struct *work_s)
data = kmalloc(datasize, GFP_KERNEL); data = kmalloc(datasize, GFP_KERNEL);
if (data == NULL) { if (data == NULL) {
dev_err(&st->us->dev, "memory alloc failed in ring bh"); dev_err(&st->us->dev, "memory alloc failed in ring bh");
return; return -ENOMEM;
} }
if (ring->scan_count) if (ring->scan_count)
...@@ -145,20 +134,21 @@ static void adis16201_trigger_bh_to_ring(struct work_struct *work_s) ...@@ -145,20 +134,21 @@ static void adis16201_trigger_bh_to_ring(struct work_struct *work_s)
/* Guaranteed to be aligned with 8 byte boundary */ /* Guaranteed to be aligned with 8 byte boundary */
if (ring->scan_timestamp) if (ring->scan_timestamp)
*((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
ring->access.store_to(ring, ring->access.store_to(ring,
(u8 *)data, (u8 *)data,
st->last_timestamp); pf->timestamp);
iio_trigger_notify_done(st->indio_dev->trig); iio_trigger_notify_done(st->indio_dev->trig);
kfree(data); kfree(data);
return; return IRQ_HANDLED;
} }
void adis16201_unconfigure_ring(struct iio_dev *indio_dev) void adis16201_unconfigure_ring(struct iio_dev *indio_dev)
{ {
kfree(indio_dev->pollfunc->name);
kfree(indio_dev->pollfunc); kfree(indio_dev->pollfunc);
iio_sw_rb_free(indio_dev->ring); iio_sw_rb_free(indio_dev->ring);
} }
...@@ -166,9 +156,7 @@ void adis16201_unconfigure_ring(struct iio_dev *indio_dev) ...@@ -166,9 +156,7 @@ void adis16201_unconfigure_ring(struct iio_dev *indio_dev)
int adis16201_configure_ring(struct iio_dev *indio_dev) int adis16201_configure_ring(struct iio_dev *indio_dev)
{ {
int ret = 0; int ret = 0;
struct adis16201_state *st = indio_dev->dev_data;
struct iio_ring_buffer *ring; struct iio_ring_buffer *ring;
INIT_WORK(&st->work_trigger_to_ring, adis16201_trigger_bh_to_ring);
ring = iio_sw_rb_allocate(indio_dev); ring = iio_sw_rb_allocate(indio_dev);
if (!ring) { if (!ring) {
...@@ -195,13 +183,26 @@ int adis16201_configure_ring(struct iio_dev *indio_dev) ...@@ -195,13 +183,26 @@ int adis16201_configure_ring(struct iio_dev *indio_dev)
iio_scan_mask_set(ring, iio_scan_el_incli_x.number); iio_scan_mask_set(ring, iio_scan_el_incli_x.number);
iio_scan_mask_set(ring, iio_scan_el_incli_y.number); iio_scan_mask_set(ring, iio_scan_el_incli_y.number);
ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16201_poll_func_th); indio_dev->pollfunc = kzalloc(sizeof(*indio_dev->pollfunc), GFP_KERNEL);
if (ret) if (indio_dev->pollfunc == NULL) {
ret = -ENOMEM;
goto error_iio_sw_rb_free; goto error_iio_sw_rb_free;
}
indio_dev->pollfunc->private_data = indio_dev;
indio_dev->pollfunc->h = &iio_pollfunc_store_time;
indio_dev->pollfunc->thread = &adis16201_trigger_handler;
indio_dev->pollfunc->type = IRQF_ONESHOT;
indio_dev->pollfunc->name =
kasprintf(GFP_KERNEL, "adis16201_consumer%d", indio_dev->id);
if (indio_dev->pollfunc->name == NULL) {
ret = -ENOMEM;
goto error_free_poll_func;
}
indio_dev->modes |= INDIO_RING_TRIGGERED; indio_dev->modes |= INDIO_RING_TRIGGERED;
return 0; return 0;
error_free_poll_func:
kfree(indio_dev->pollfunc);
error_iio_sw_rb_free: error_iio_sw_rb_free:
iio_sw_rb_free(indio_dev->ring); iio_sw_rb_free(indio_dev->ring);
return ret; return ret;
......
...@@ -12,16 +12,6 @@ ...@@ -12,16 +12,6 @@
#include "../trigger.h" #include "../trigger.h"
#include "adis16201.h" #include "adis16201.h"
/**
* adis16201_data_rdy_trig_poll() the event handler for the data rdy trig
**/
static irqreturn_t adis16201_data_rdy_trig_poll(int irq, void *private)
{
disable_irq_nosync(irq);
iio_trigger_poll(private, iio_get_time_ns());
return IRQ_HANDLED;
}
static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL); static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);
static struct attribute *adis16201_trigger_attrs[] = { static struct attribute *adis16201_trigger_attrs[] = {
...@@ -46,62 +36,51 @@ static int adis16201_data_rdy_trigger_set_state(struct iio_trigger *trig, ...@@ -46,62 +36,51 @@ static int adis16201_data_rdy_trigger_set_state(struct iio_trigger *trig,
return adis16201_set_irq(&st->indio_dev->dev, state); return adis16201_set_irq(&st->indio_dev->dev, state);
} }
/**
* adis16201_trig_try_reen() try renabling irq for data rdy trigger
* @trig: the datardy trigger
**/
static int adis16201_trig_try_reen(struct iio_trigger *trig)
{
struct adis16201_state *st = trig->private_data;
enable_irq(st->us->irq);
return 0;
}
int adis16201_probe_trigger(struct iio_dev *indio_dev) int adis16201_probe_trigger(struct iio_dev *indio_dev)
{ {
int ret; int ret;
struct adis16201_state *st = indio_dev->dev_data; struct adis16201_state *st = indio_dev->dev_data;
char *name;
st->trig = iio_allocate_trigger(); name = kasprintf(GFP_KERNEL,
if (st->trig == NULL) { "adis16201-dev%d",
indio_dev->id);
if (name == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_ret; goto error_ret;
} }
st->trig = iio_allocate_trigger_named(name);
if (st->trig == NULL) {
ret = -ENOMEM;
goto error_free_name;
}
ret = request_irq(st->us->irq, ret = request_irq(st->us->irq,
adis16201_data_rdy_trig_poll, &iio_trigger_generic_data_rdy_poll,
IRQF_TRIGGER_RISING, IRQF_TRIGGER_RISING,
"adis16201", "adis16201",
st->trig); st->trig);
if (ret) if (ret)
goto error_free_trig; goto error_free_trig;
st->trig->name = kasprintf(GFP_KERNEL,
"adis16201-dev%d",
indio_dev->id);
if (!st->trig->name) {
ret = -ENOMEM;
goto error_free_irq;
}
st->trig->dev.parent = &st->us->dev; st->trig->dev.parent = &st->us->dev;
st->trig->owner = THIS_MODULE; st->trig->owner = THIS_MODULE;
st->trig->private_data = st; st->trig->private_data = st;
st->trig->set_trigger_state = &adis16201_data_rdy_trigger_set_state; st->trig->set_trigger_state = &adis16201_data_rdy_trigger_set_state;
st->trig->try_reenable = &adis16201_trig_try_reen;
st->trig->control_attrs = &adis16201_trigger_attr_group; st->trig->control_attrs = &adis16201_trigger_attr_group;
ret = iio_trigger_register(st->trig); ret = iio_trigger_register(st->trig);
/* select default trigger */ /* select default trigger */
indio_dev->trig = st->trig; indio_dev->trig = st->trig;
if (ret) if (ret)
goto error_free_trig_name; goto error_free_irq;
return 0; return 0;
error_free_trig_name:
kfree(st->trig->name);
error_free_irq: error_free_irq:
free_irq(st->us->irq, st->trig); free_irq(st->us->irq, st->trig);
error_free_trig: error_free_trig:
iio_free_trigger(st->trig); iio_free_trigger(st->trig);
error_free_name:
kfree(name);
error_ret: error_ret:
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment