2011-07-10 19:09:12 +02:00
|
|
|
#include <linux/export.h>
|
2010-05-12 20:34:06 +02:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/spi/spi.h>
|
2010-05-23 09:10:35 +02:00
|
|
|
#include <linux/slab.h>
|
2010-05-12 20:34:06 +02:00
|
|
|
|
|
|
|
#include "../iio.h"
|
|
|
|
#include "../ring_sw.h"
|
2011-08-24 18:28:39 +02:00
|
|
|
#include "../trigger_consumer.h"
|
2010-05-12 20:34:06 +02:00
|
|
|
#include "adis16260.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* adis16260_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)
|
|
|
|
* @rx: somewhere to pass back the value read
|
|
|
|
**/
|
|
|
|
static int adis16260_read_ring_data(struct device *dev, u8 *rx)
|
|
|
|
{
|
|
|
|
struct spi_message msg;
|
|
|
|
struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
2011-06-27 14:07:46 +02:00
|
|
|
struct adis16260_state *st = iio_priv(indio_dev);
|
2010-05-12 20:34:06 +02:00
|
|
|
struct spi_transfer xfers[ADIS16260_OUTPUTS + 1];
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mutex_lock(&st->buf_lock);
|
|
|
|
|
|
|
|
spi_message_init(&msg);
|
|
|
|
|
|
|
|
memset(xfers, 0, sizeof(xfers));
|
|
|
|
for (i = 0; i <= ADIS16260_OUTPUTS; i++) {
|
|
|
|
xfers[i].bits_per_word = 8;
|
|
|
|
xfers[i].cs_change = 1;
|
|
|
|
xfers[i].len = 2;
|
|
|
|
xfers[i].delay_usecs = 30;
|
|
|
|
xfers[i].tx_buf = st->tx + 2 * i;
|
|
|
|
if (i < 2) /* SUPPLY_OUT:0x02 GYRO_OUT:0x04 */
|
|
|
|
st->tx[2 * i]
|
|
|
|
= ADIS16260_READ_REG(ADIS16260_SUPPLY_OUT
|
|
|
|
+ 2 * i);
|
|
|
|
else /* 0x06 to 0x09 is reserved */
|
|
|
|
st->tx[2 * i]
|
|
|
|
= ADIS16260_READ_REG(ADIS16260_SUPPLY_OUT
|
|
|
|
+ 2 * i + 4);
|
|
|
|
st->tx[2 * i + 1] = 0;
|
|
|
|
if (i >= 1)
|
|
|
|
xfers[i].rx_buf = rx + 2 * (i - 1);
|
|
|
|
spi_message_add_tail(&xfers[i], &msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = spi_sync(st->us, &msg);
|
|
|
|
if (ret)
|
|
|
|
dev_err(&st->us->dev, "problem when burst reading");
|
|
|
|
|
|
|
|
mutex_unlock(&st->buf_lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-18 15:41:41 +02:00
|
|
|
static irqreturn_t adis16260_trigger_handler(int irq, void *p)
|
2010-05-12 20:34:06 +02:00
|
|
|
{
|
2011-05-18 15:41:41 +02:00
|
|
|
struct iio_poll_func *pf = p;
|
2011-08-24 18:28:36 +02:00
|
|
|
struct iio_dev *indio_dev = pf->indio_dev;
|
2011-06-27 14:07:46 +02:00
|
|
|
struct adis16260_state *st = iio_priv(indio_dev);
|
2011-09-21 12:15:57 +02:00
|
|
|
struct iio_buffer *ring = indio_dev->buffer;
|
2010-05-12 20:34:06 +02:00
|
|
|
int i = 0;
|
|
|
|
s16 *data;
|
2011-05-18 15:42:24 +02:00
|
|
|
size_t datasize = ring->access->get_bytes_per_datum(ring);
|
2010-05-12 20:34:06 +02:00
|
|
|
|
|
|
|
data = kmalloc(datasize , GFP_KERNEL);
|
|
|
|
if (data == NULL) {
|
|
|
|
dev_err(&st->us->dev, "memory alloc failed in ring bh");
|
2011-05-18 15:41:41 +02:00
|
|
|
return -ENOMEM;
|
2010-05-12 20:34:06 +02:00
|
|
|
}
|
|
|
|
|
2011-05-18 15:41:41 +02:00
|
|
|
if (ring->scan_count &&
|
2011-06-27 14:07:46 +02:00
|
|
|
adis16260_read_ring_data(&indio_dev->dev, st->rx) >= 0)
|
2011-05-18 15:41:41 +02:00
|
|
|
for (; i < ring->scan_count; i++)
|
|
|
|
data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
|
2010-05-12 20:34:06 +02:00
|
|
|
|
|
|
|
/* Guaranteed to be aligned with 8 byte boundary */
|
2010-08-31 11:32:52 +02:00
|
|
|
if (ring->scan_timestamp)
|
2011-05-18 15:41:41 +02:00
|
|
|
*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
|
2010-05-12 20:34:06 +02:00
|
|
|
|
2011-05-18 15:42:24 +02:00
|
|
|
ring->access->store_to(ring, (u8 *)data, pf->timestamp);
|
2010-05-12 20:34:06 +02:00
|
|
|
|
2011-06-27 14:07:46 +02:00
|
|
|
iio_trigger_notify_done(indio_dev->trig);
|
2010-05-12 20:34:06 +02:00
|
|
|
kfree(data);
|
|
|
|
|
2011-05-18 15:41:41 +02:00
|
|
|
return IRQ_HANDLED;
|
2010-05-12 20:34:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void adis16260_unconfigure_ring(struct iio_dev *indio_dev)
|
|
|
|
{
|
2011-05-18 15:42:39 +02:00
|
|
|
iio_dealloc_pollfunc(indio_dev->pollfunc);
|
2011-09-21 12:15:57 +02:00
|
|
|
iio_sw_rb_free(indio_dev->buffer);
|
2010-05-12 20:34:06 +02:00
|
|
|
}
|
|
|
|
|
2011-09-21 12:15:57 +02:00
|
|
|
static const struct iio_buffer_setup_ops adis16260_ring_setup_ops = {
|
|
|
|
.preenable = &iio_sw_buffer_preenable,
|
2011-09-21 12:15:53 +02:00
|
|
|
.postenable = &iio_triggered_buffer_postenable,
|
|
|
|
.predisable = &iio_triggered_buffer_predisable,
|
2011-05-18 15:42:24 +02:00
|
|
|
};
|
|
|
|
|
2010-05-12 20:34:06 +02:00
|
|
|
int adis16260_configure_ring(struct iio_dev *indio_dev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2011-09-21 12:15:57 +02:00
|
|
|
struct iio_buffer *ring;
|
2010-05-12 20:34:06 +02:00
|
|
|
|
|
|
|
ring = iio_sw_rb_allocate(indio_dev);
|
|
|
|
if (!ring) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
return ret;
|
|
|
|
}
|
2011-09-21 12:15:57 +02:00
|
|
|
indio_dev->buffer = ring;
|
2010-05-12 20:34:06 +02:00
|
|
|
/* Effectively select the ring buffer implementation */
|
2011-05-18 15:42:24 +02:00
|
|
|
ring->access = &ring_sw_access_funcs;
|
2010-07-11 17:39:17 +02:00
|
|
|
ring->bpe = 2;
|
2010-08-31 11:32:52 +02:00
|
|
|
ring->scan_timestamp = true;
|
2011-05-18 15:42:24 +02:00
|
|
|
ring->setup_ops = &adis16260_ring_setup_ops;
|
2010-05-12 20:34:06 +02:00
|
|
|
ring->owner = THIS_MODULE;
|
|
|
|
|
2011-05-18 15:42:39 +02:00
|
|
|
indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
|
|
|
|
&adis16260_trigger_handler,
|
|
|
|
IRQF_ONESHOT,
|
|
|
|
indio_dev,
|
|
|
|
"adis16260_consumer%d",
|
|
|
|
indio_dev->id);
|
2011-05-18 15:41:41 +02:00
|
|
|
if (indio_dev->pollfunc == NULL) {
|
|
|
|
ret = -ENOMEM;
|
2010-07-11 17:39:09 +02:00
|
|
|
goto error_iio_sw_rb_free;
|
2011-05-18 15:41:41 +02:00
|
|
|
}
|
2010-07-11 17:39:09 +02:00
|
|
|
|
2011-09-21 12:15:54 +02:00
|
|
|
indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
|
2010-05-12 20:34:06 +02:00
|
|
|
return 0;
|
2011-05-18 15:42:39 +02:00
|
|
|
|
2010-05-12 20:34:06 +02:00
|
|
|
error_iio_sw_rb_free:
|
2011-09-21 12:15:57 +02:00
|
|
|
iio_sw_rb_free(indio_dev->buffer);
|
2010-05-12 20:34:06 +02:00
|
|
|
return ret;
|
|
|
|
}
|