diff options
Diffstat (limited to 'drivers/staging/iio/imu/adis16400_ring.c')
-rw-r--r-- | drivers/staging/iio/imu/adis16400_ring.c | 137 |
1 files changed, 62 insertions, 75 deletions
diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c index 5529b32..949db76 100644 --- a/drivers/staging/iio/imu/adis16400_ring.c +++ b/drivers/staging/iio/imu/adis16400_ring.c @@ -6,6 +6,7 @@ #include <linux/device.h> #include <linux/kernel.h> #include <linux/spi/spi.h> +#include <linux/slab.h> #include <linux/sysfs.h> #include <linux/list.h> @@ -16,16 +17,6 @@ #include "../trigger.h" #include "adis16400.h" -/** - * combine_8_to_16() utility function to munge to u8s into u16 - **/ -static inline u16 combine_8_to_16(u8 lower, u8 upper) -{ - u16 _lower = lower; - u16 _upper = upper; - return _lower | (_upper << 8); -} - static IIO_SCAN_EL_C(supply, ADIS16400_SCAN_SUPPLY, IIO_SIGNED(14), ADIS16400_SUPPLY_OUT, NULL); @@ -83,10 +74,10 @@ static struct attribute_group adis16400_scan_el_group = { * 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) +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 = indio_dev->trig->timestamp; + st->last_timestamp = time; schedule_work(&st->work_trigger_to_ring); /* Indicate that this interrupt is being handled */ @@ -96,6 +87,54 @@ static void adis16400_poll_func_th(struct iio_dev *indio_dev) */ } +/** + * adis16400_spi_read_burst() - read all data registers + * @dev: device associated with child of actual device (iio_dev or iio_trig) + * @rx: somewhere to pass back the value read (min size is 24 bytes) + **/ +static int adis16400_spi_read_burst(struct device *dev, u8 *rx) +{ + struct spi_message msg; + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct adis16400_state *st = iio_dev_get_devdata(indio_dev); + u32 old_speed_hz = st->us->max_speed_hz; + int ret; + + struct spi_transfer xfers[] = { + { + .tx_buf = st->tx, + .bits_per_word = 8, + .len = 2, + .cs_change = 0, + }, { + .rx_buf = rx, + .bits_per_word = 8, + .len = 24, + .cs_change = 1, + }, + }; + + mutex_lock(&st->buf_lock); + st->tx[0] = ADIS16400_READ_REG(ADIS16400_GLOB_CMD); + st->tx[1] = 0; + + spi_message_init(&msg); + spi_message_add_tail(&xfers[0], &msg); + spi_message_add_tail(&xfers[1], &msg); + + st->us->max_speed_hz = min(ADIS16400_SPI_BURST, old_speed_hz); + spi_setup(st->us); + + ret = spi_sync(st->us, &msg); + if (ret) + dev_err(&st->us->dev, "problem when burst reading"); + + st->us->max_speed_hz = old_speed_hz; + spi_setup(st->us); + mutex_unlock(&st->buf_lock); + return ret; +} + /* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device * specific to be rolled into the core. */ @@ -118,10 +157,9 @@ static void adis16400_trigger_bh_to_ring(struct work_struct *work_s) if (st->indio_dev->scan_count) if (adis16400_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0) - for (; i < st->indio_dev->scan_count; i++) { - data[i] = combine_8_to_16(st->rx[i*2+1], - st->rx[i*2]); - } + for (; i < st->indio_dev->scan_count; i++) + data[i] = be16_to_cpup( + (__be16 *)&(st->rx[i*2])); /* Guaranteed to be aligned with 8 byte boundary */ if (st->indio_dev->scan_timestamp) @@ -136,45 +174,6 @@ static void adis16400_trigger_bh_to_ring(struct work_struct *work_s) return; } -/* in these circumstances is it better to go with unaligned packing and - * deal with the cost?*/ -static int adis16400_data_rdy_ring_preenable(struct iio_dev *indio_dev) -{ - size_t size; - dev_dbg(&indio_dev->dev, "%s\n", __func__); - /* Check if there are any scan elements enabled, if not fail*/ - if (!(indio_dev->scan_count || indio_dev->scan_timestamp)) - return -EINVAL; - - if (indio_dev->ring->access.set_bpd) { - if (indio_dev->scan_timestamp) - if (indio_dev->scan_count) /* Timestamp and data */ - size = 6*sizeof(s64); - else /* Timestamp only */ - size = sizeof(s64); - else /* Data only */ - size = indio_dev->scan_count*sizeof(s16); - indio_dev->ring->access.set_bpd(indio_dev->ring, size); - } - - return 0; -} - -static int adis16400_data_rdy_ring_postenable(struct iio_dev *indio_dev) -{ - return indio_dev->trig - ? iio_trigger_attach_poll_func(indio_dev->trig, - indio_dev->pollfunc) - : 0; -} - -static int adis16400_data_rdy_ring_predisable(struct iio_dev *indio_dev) -{ - return indio_dev->trig - ? iio_trigger_dettach_poll_func(indio_dev->trig, - indio_dev->pollfunc) - : 0; -} void adis16400_unconfigure_ring(struct iio_dev *indio_dev) { @@ -214,18 +213,16 @@ int adis16400_configure_ring(struct iio_dev *indio_dev) indio_dev->ring = ring; /* Effectively select the ring buffer implementation */ iio_ring_sw_register_funcs(&ring->access); - ring->preenable = &adis16400_data_rdy_ring_preenable; - ring->postenable = &adis16400_data_rdy_ring_postenable; - ring->predisable = &adis16400_data_rdy_ring_predisable; + ring->bpe = 2; + ring->preenable = &iio_sw_ring_preenable; + ring->postenable = &iio_triggered_ring_postenable; + ring->predisable = &iio_triggered_ring_predisable; ring->owner = THIS_MODULE; - 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->poll_func_main = &adis16400_poll_func_th; - indio_dev->pollfunc->private_data = indio_dev; + ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16400_poll_func_th); + if (ret) + goto error_iio_sw_rb_free; + indio_dev->modes |= INDIO_RING_TRIGGERED; return 0; @@ -233,13 +230,3 @@ error_iio_sw_rb_free: iio_sw_rb_free(indio_dev->ring); return ret; } - -int adis16400_initialize_ring(struct iio_ring_buffer *ring) -{ - return iio_ring_buffer_register(ring, 0); -} - -void adis16400_uninitialize_ring(struct iio_ring_buffer *ring) -{ - iio_ring_buffer_unregister(ring); -} |