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

staging:iio:imu:adis16400 move to irq based triggers and channel spec channel registration.

V2: rebase fixup.
Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 3f00ca47
......@@ -126,9 +126,6 @@
/**
* struct adis16400_state - device instance specific data
* @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
* @trig: data ready trigger registered with iio
* @tx: transmit buffer
......@@ -137,8 +134,6 @@
**/
struct adis16400_state {
struct spi_device *us;
struct work_struct work_trigger_to_ring;
s64 last_timestamp;
struct iio_dev *indio_dev;
struct iio_trigger *trig;
u8 *tx;
......@@ -146,7 +141,7 @@ struct adis16400_state {
struct mutex buf_lock;
};
int adis16400_set_irq(struct device *dev, bool enable);
int adis16400_set_irq(struct iio_dev *indio_dev, bool enable);
#ifdef CONFIG_IIO_RING_BUFFER
/* At the moment triggers are only used for ring buffer
......
This diff is collapsed.
......@@ -17,93 +17,6 @@
#include "../trigger.h"
#include "adis16400.h"
static IIO_SCAN_EL_C(in0_supply, ADIS16400_SCAN_SUPPLY,
ADIS16400_SUPPLY_OUT, NULL);
static IIO_CONST_ATTR_SCAN_EL_TYPE(in0_supply, u, 14, 16);
static IIO_SCAN_EL_C(gyro_x, ADIS16400_SCAN_GYRO_X, ADIS16400_XGYRO_OUT, NULL);
static IIO_SCAN_EL_C(gyro_y, ADIS16400_SCAN_GYRO_Y, ADIS16400_YGYRO_OUT, NULL);
static IIO_SCAN_EL_C(gyro_z, ADIS16400_SCAN_GYRO_Z, ADIS16400_ZGYRO_OUT, NULL);
static IIO_CONST_ATTR_SCAN_EL_TYPE(gyro, s, 14, 16);
static IIO_SCAN_EL_C(accel_x, ADIS16400_SCAN_ACC_X, ADIS16400_XACCL_OUT, NULL);
static IIO_SCAN_EL_C(accel_y, ADIS16400_SCAN_ACC_Y, ADIS16400_YACCL_OUT, NULL);
static IIO_SCAN_EL_C(accel_z, ADIS16400_SCAN_ACC_Z, ADIS16400_ZACCL_OUT, NULL);
static IIO_CONST_ATTR_SCAN_EL_TYPE(accel, s, 14, 16);
static IIO_SCAN_EL_C(magn_x, ADIS16400_SCAN_MAGN_X, ADIS16400_XMAGN_OUT, NULL);
static IIO_SCAN_EL_C(magn_y, ADIS16400_SCAN_MAGN_Y, ADIS16400_YMAGN_OUT, NULL);
static IIO_SCAN_EL_C(magn_z, ADIS16400_SCAN_MAGN_Z, ADIS16400_ZMAGN_OUT, NULL);
static IIO_CONST_ATTR_SCAN_EL_TYPE(magn, s, 14, 16);
static IIO_SCAN_EL_C(temp, ADIS16400_SCAN_TEMP, ADIS16400_TEMP_OUT, NULL);
static IIO_CONST_ATTR_SCAN_EL_TYPE(temp, s, 12, 16);
static IIO_SCAN_EL_C(in1, ADIS16400_SCAN_ADC_0, ADIS16400_AUX_ADC, NULL);
static IIO_CONST_ATTR_SCAN_EL_TYPE(in1, u, 12, 16);
static IIO_SCAN_EL_TIMESTAMP(12);
static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
static struct attribute *adis16400_scan_el_attrs[] = {
&iio_scan_el_in0_supply.dev_attr.attr,
&iio_const_attr_in0_supply_index.dev_attr.attr,
&iio_const_attr_in0_supply_type.dev_attr.attr,
&iio_scan_el_gyro_x.dev_attr.attr,
&iio_const_attr_gyro_x_index.dev_attr.attr,
&iio_scan_el_gyro_y.dev_attr.attr,
&iio_const_attr_gyro_y_index.dev_attr.attr,
&iio_scan_el_gyro_z.dev_attr.attr,
&iio_const_attr_gyro_z_index.dev_attr.attr,
&iio_const_attr_gyro_type.dev_attr.attr,
&iio_scan_el_accel_x.dev_attr.attr,
&iio_const_attr_accel_x_index.dev_attr.attr,
&iio_scan_el_accel_y.dev_attr.attr,
&iio_const_attr_accel_y_index.dev_attr.attr,
&iio_scan_el_accel_z.dev_attr.attr,
&iio_const_attr_accel_z_index.dev_attr.attr,
&iio_const_attr_accel_type.dev_attr.attr,
&iio_scan_el_magn_x.dev_attr.attr,
&iio_const_attr_magn_x_index.dev_attr.attr,
&iio_scan_el_magn_y.dev_attr.attr,
&iio_const_attr_magn_y_index.dev_attr.attr,
&iio_scan_el_magn_z.dev_attr.attr,
&iio_const_attr_magn_z_index.dev_attr.attr,
&iio_const_attr_magn_type.dev_attr.attr,
&iio_scan_el_temp.dev_attr.attr,
&iio_const_attr_temp_index.dev_attr.attr,
&iio_const_attr_temp_type.dev_attr.attr,
&iio_scan_el_in1.dev_attr.attr,
&iio_const_attr_in1_index.dev_attr.attr,
&iio_const_attr_in1_type.dev_attr.attr,
&iio_scan_el_timestamp.dev_attr.attr,
&iio_const_attr_timestamp_index.dev_attr.attr,
&iio_const_attr_timestamp_type.dev_attr.attr,
NULL,
};
static struct attribute_group adis16400_scan_el_group = {
.attrs = adis16400_scan_el_attrs,
.name = "scan_elements",
};
/**
* adis16400_poll_func_th() top half interrupt handler called by trigger
* @private_data: iio_dev
**/
static void adis16400_poll_func_th(struct iio_dev *indio_dev, s64 time)
{
struct adis16400_state *st = iio_dev_get_devdata(indio_dev);
st->last_timestamp = time;
schedule_work(&st->work_trigger_to_ring);
/* Indicate that this interrupt is being handled */
/* Technically this is trigger related, but without this
* handler running there is currently no way for the interrupt
* to clear.
*/
}
/**
* adis16400_spi_read_burst() - read all data registers
* @dev: device associated with child of actual device (iio_dev or iio_trig)
......@@ -153,13 +66,12 @@ static int adis16400_spi_read_burst(struct device *dev, u8 *rx)
/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
* specific to be rolled into the core.
*/
static void adis16400_trigger_bh_to_ring(struct work_struct *work_s)
static irqreturn_t adis16400_trigger_handler(int irq, void *p)
{
struct adis16400_state *st
= container_of(work_s, struct adis16400_state,
work_trigger_to_ring);
struct iio_ring_buffer *ring = st->indio_dev->ring;
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->private_data;
struct adis16400_state *st = iio_dev_get_devdata(indio_dev);
struct iio_ring_buffer *ring = indio_dev->ring;
int i = 0, j;
s16 *data;
size_t datasize = ring->access.get_bytes_per_datum(ring);
......@@ -168,11 +80,11 @@ static void adis16400_trigger_bh_to_ring(struct work_struct *work_s)
data = kmalloc(datasize , GFP_KERNEL);
if (data == NULL) {
dev_err(&st->us->dev, "memory alloc failed in ring bh");
return;
return -ENOMEM;
}
if (ring->scan_count)
if (adis16400_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0)
if (adis16400_spi_read_burst(&indio_dev->dev, st->rx) >= 0)
for (; i < ring->scan_count; i++) {
j = __ffs(mask);
mask &= ~(1 << j);
......@@ -182,20 +94,18 @@ static void adis16400_trigger_bh_to_ring(struct work_struct *work_s)
/* Guaranteed to be aligned with 8 byte boundary */
if (ring->scan_timestamp)
*((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp;
ring->access.store_to(ring,
(u8 *) data,
st->last_timestamp);
*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
ring->access.store_to(indio_dev->ring, (u8 *) data, pf->timestamp);
iio_trigger_notify_done(st->indio_dev->trig);
iio_trigger_notify_done(indio_dev->trig);
kfree(data);
return;
return IRQ_HANDLED;
}
void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
{
kfree(indio_dev->pollfunc->name);
kfree(indio_dev->pollfunc);
iio_sw_rb_free(indio_dev->ring);
}
......@@ -203,9 +113,7 @@ void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
int adis16400_configure_ring(struct iio_dev *indio_dev)
{
int ret = 0;
struct adis16400_state *st = indio_dev->dev_data;
struct iio_ring_buffer *ring;
INIT_WORK(&st->work_trigger_to_ring, adis16400_trigger_bh_to_ring);
ring = iio_sw_rb_allocate(indio_dev);
if (!ring) {
......@@ -216,7 +124,6 @@ int adis16400_configure_ring(struct iio_dev *indio_dev)
/* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&ring->access);
ring->bpe = 2;
ring->scan_el_attrs = &adis16400_scan_el_group;
ring->scan_timestamp = true;
ring->preenable = &iio_sw_ring_preenable;
ring->postenable = &iio_triggered_ring_postenable;
......@@ -224,26 +131,37 @@ int adis16400_configure_ring(struct iio_dev *indio_dev)
ring->owner = THIS_MODULE;
/* Set default scan mode */
iio_scan_mask_set(ring, iio_scan_el_in0_supply.number);
iio_scan_mask_set(ring, iio_scan_el_gyro_x.number);
iio_scan_mask_set(ring, iio_scan_el_gyro_y.number);
iio_scan_mask_set(ring, iio_scan_el_gyro_z.number);
iio_scan_mask_set(ring, iio_scan_el_accel_x.number);
iio_scan_mask_set(ring, iio_scan_el_accel_y.number);
iio_scan_mask_set(ring, iio_scan_el_accel_z.number);
iio_scan_mask_set(ring, iio_scan_el_magn_x.number);
iio_scan_mask_set(ring, iio_scan_el_magn_y.number);
iio_scan_mask_set(ring, iio_scan_el_magn_z.number);
iio_scan_mask_set(ring, iio_scan_el_temp.number);
iio_scan_mask_set(ring, iio_scan_el_in1.number);
ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16400_poll_func_th);
if (ret)
iio_scan_mask_set(ring, ADIS16400_SCAN_SUPPLY);
iio_scan_mask_set(ring, ADIS16400_SCAN_GYRO_X);
iio_scan_mask_set(ring, ADIS16400_SCAN_GYRO_Y);
iio_scan_mask_set(ring, ADIS16400_SCAN_GYRO_Z);
iio_scan_mask_set(ring, ADIS16400_SCAN_ACC_X);
iio_scan_mask_set(ring, ADIS16400_SCAN_ACC_Y);
iio_scan_mask_set(ring, ADIS16400_SCAN_ACC_Z);
iio_scan_mask_set(ring, ADIS16400_SCAN_MAGN_X);
iio_scan_mask_set(ring, ADIS16400_SCAN_MAGN_Y);
iio_scan_mask_set(ring, ADIS16400_SCAN_MAGN_Z);
iio_scan_mask_set(ring, ADIS16400_SCAN_TEMP);
iio_scan_mask_set(ring, ADIS16400_SCAN_ADC_0);
indio_dev->pollfunc = kzalloc(sizeof(*indio_dev->pollfunc), GFP_KERNEL);
if (indio_dev->pollfunc == NULL) {
ret = -ENOMEM;
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 = &adis16400_trigger_handler;
indio_dev->pollfunc->type = IRQF_ONESHOT;
indio_dev->pollfunc->name =
kasprintf(GFP_KERNEL, "adis16400_consumer%d", indio_dev->id);
if (ret)
goto error_iio_free_pollfunc;
indio_dev->modes |= INDIO_RING_TRIGGERED;
return 0;
error_iio_free_pollfunc:
kfree(indio_dev->pollfunc);
error_iio_sw_rb_free:
iio_sw_rb_free(indio_dev->ring);
return ret;
......
......@@ -12,16 +12,6 @@
#include "../trigger.h"
#include "adis16400.h"
/**
* adis16400_data_rdy_trig_poll() the event handler for the data rdy trig
**/
static irqreturn_t adis16400_data_rdy_trig_poll(int irq, void *private)
{
disable_irq_nosync(irq);
iio_trigger_poll(private, iio_get_time_ns());
return IRQ_HANDLED;
}
static IIO_TRIGGER_NAME_ATTR;
static struct attribute *adis16400_trigger_attrs[] = {
......@@ -43,66 +33,58 @@ static int adis16400_data_rdy_trigger_set_state(struct iio_trigger *trig,
struct iio_dev *indio_dev = st->indio_dev;
dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
return adis16400_set_irq(&st->indio_dev->dev, state);
}
/**
* adis16400_trig_try_reen() try renabling irq for data rdy trigger
* @trig: the datardy trigger
**/
static int adis16400_trig_try_reen(struct iio_trigger *trig)
{
struct adis16400_state *st = trig->private_data;
enable_irq(st->us->irq);
/* irq reenabled so success! */
return 0;
return adis16400_set_irq(st->indio_dev, state);
}
int adis16400_probe_trigger(struct iio_dev *indio_dev)
{
int ret;
struct adis16400_state *st = indio_dev->dev_data;
char *name;
st->trig = iio_allocate_trigger();
if (st->trig == NULL) {
name = kasprintf(GFP_KERNEL,
"%s-dev%d",
spi_get_device_id(st->us)->name,
indio_dev->id);
if (name == NULL) {
ret = -ENOMEM;
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,
adis16400_data_rdy_trig_poll,
&iio_trigger_generic_data_rdy_poll,
IRQF_TRIGGER_RISING,
"adis16400",
st->trig);
if (ret)
goto error_free_trig;
st->trig->name = kasprintf(GFP_KERNEL,
"adis16400-dev%d",
indio_dev->id);
if (!st->trig->name) {
ret = -ENOMEM;
goto error_free_irq;
}
st->trig->dev.parent = &st->us->dev;
st->trig->owner = THIS_MODULE;
st->trig->private_data = st;
st->trig->set_trigger_state = &adis16400_data_rdy_trigger_set_state;
st->trig->try_reenable = &adis16400_trig_try_reen;
st->trig->control_attrs = &adis16400_trigger_attr_group;
ret = iio_trigger_register(st->trig);
/* select default trigger */
indio_dev->trig = st->trig;
if (ret)
goto error_free_trig_name;
goto error_free_irq;
return 0;
error_free_trig_name:
kfree(st->trig->name);
error_free_irq:
free_irq(st->us->irq, st->trig);
error_free_trig:
iio_free_trigger(st->trig);
error_free_name:
kfree(name);
error_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