Diff
Modified: trunk/drivers/staging/iio/accel/adis16209.h (8690 => 8691)
--- trunk/drivers/staging/iio/accel/adis16209.h 2010-05-06 04:50:04 UTC (rev 8690)
+++ trunk/drivers/staging/iio/accel/adis16209.h 2010-05-06 10:10:36 UTC (rev 8691)
@@ -61,8 +61,7 @@
#define ADIS16209_MAX_TX 24
#define ADIS16209_MAX_RX 24
-#define ADIS16209_SPI_BURST (u32)(1000 * 1000)
-#define ADIS16209_SPI_FAST (u32)(2000 * 1000)
+#define ADIS16209_ERROR_ACTIVE (1<<14)
/**
* struct adis16209_state - device instance specific data
@@ -89,23 +88,8 @@
struct mutex buf_lock;
};
-int adis16209_spi_write_reg_8(struct device *dev,
- u8 reg_address,
- u8 val);
-
-int adis16209_spi_read_burst(struct device *dev, u8 *rx);
-
-int adis16209_spi_read_sequence(struct device *dev,
- u8 *tx, u8 *rx, int num);
-
int adis16209_set_irq(struct device *dev, bool enable);
-int adis16209_reset(struct device *dev);
-
-int adis16209_stop_device(struct device *dev);
-
-int adis16209_check_status(struct device *dev);
-
#ifdef CONFIG_IIO_RING_BUFFER
enum adis16209_scan {
ADIS16209_SCAN_SUPPLY,
Modified: trunk/drivers/staging/iio/accel/adis16209_core.c (8690 => 8691)
--- trunk/drivers/staging/iio/accel/adis16209_core.c 2010-05-06 04:50:04 UTC (rev 8690)
+++ trunk/drivers/staging/iio/accel/adis16209_core.c 2010-05-06 10:10:36 UTC (rev 8691)
@@ -29,13 +29,15 @@
#define DRIVER_NAME "adis16209"
+static int adis16209_check_status(struct device *dev);
+
/**
* adis16209_spi_write_reg_8() - write single byte to a register
* @dev: device associated with child of actual device (iio_dev or iio_trig)
* @reg_address: the address of the register to be written
* @val: the value to write
**/
-int adis16209_spi_write_reg_8(struct device *dev,
+static int adis16209_spi_write_reg_8(struct device *dev,
u8 reg_address,
u8 val)
{
@@ -148,65 +150,6 @@
return ret;
}
-/**
- * adis16209_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
- **/
-int adis16209_spi_read_burst(struct device *dev, u8 *rx)
-{
- struct spi_message msg;
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct adis16209_state *st = iio_dev_get_devdata(indio_dev);
- struct spi_transfer xfers[ADIS16209_OUTPUTS + 1];
- int ret;
- int i;
-
- mutex_lock(&st->buf_lock);
-
- spi_message_init(&msg);
-
- memset(xfers, 0, sizeof(xfers));
- for (i = 0; i <= ADIS16209_OUTPUTS; i++) {
- xfers[i].bits_per_word = 8;
- xfers[i].cs_change = 1;
- xfers[i].len = 2;
- xfers[i].delay_usecs = 20;
- xfers[i].tx_buf = st->tx + 2 * i;
- st->tx[2 * i] = ADIS16209_READ_REG(ADIS16209_SUPPLY_OUT + 2 * i);
- 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;
-}
-
-static ssize_t adis16209_spi_read_signed(struct device *dev,
- struct device_attribute *attr,
- char *buf,
- unsigned bits)
-{
- int ret;
- s16 val = 0;
- unsigned shift = 16 - bits;
- struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-
- ret = adis16209_spi_read_reg_16(dev, this_attr->address, (u16 *)&val);
- if (ret)
- return ret;
-
- val = ((s16)(val << shift) >> shift);
- return sprintf(buf, "%d\n", val);
-}
-
static ssize_t adis16209_read_12bit_unsigned(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -219,6 +162,9 @@
if (ret)
return ret;
+ if (val & ADIS16209_ERROR_ACTIVE)
+ adis16209_check_status(dev);
+
return sprintf(buf, "%u\n", val & 0x0FFF);
}
@@ -234,6 +180,9 @@
if (ret)
return ret;
+ if (val & ADIS16209_ERROR_ACTIVE)
+ adis16209_check_status(dev);
+
return sprintf(buf, "%u\n", val & 0x3FFF);
}
@@ -243,7 +192,7 @@
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
ssize_t ret;
- s16 val;
+ u16 val;
/* Take the iio_dev status lock */
mutex_lock(&indio_dev->mlock);
@@ -252,7 +201,10 @@
if (ret)
goto error_ret;
- val = ((s16)(val << 4) >> 4);
+ if (val & ADIS16209_ERROR_ACTIVE)
+ adis16209_check_status(dev);
+
+ val &= 0xFFF;
ret = sprintf(buf, "%d\n", val);
error_ret:
@@ -265,11 +217,21 @@
char *buf)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+ s16 val = 0;
ssize_t ret;
- /* Take the iio_dev status lock */
mutex_lock(&indio_dev->mlock);
- ret = adis16209_spi_read_signed(dev, attr, buf, 14);
+
+ ret = adis16209_spi_read_reg_16(dev, this_attr->address, (u16 *)&val);
+ if (!ret) {
+ if (val & ADIS16209_ERROR_ACTIVE)
+ adis16209_check_status(dev);
+
+ val = ((s16)(val << 2) >> 2);
+ ret = sprintf(buf, "%d\n", val);
+ }
+
mutex_unlock(&indio_dev->mlock);
return ret;
@@ -293,25 +255,38 @@
return ret ? ret : len;
}
+static int adis16209_reset(struct device *dev)
+{
+ int ret;
+ ret = adis16209_spi_write_reg_8(dev,
+ ADIS16209_GLOB_CMD,
+ ADIS16209_GLOB_CMD_SW_RESET);
+ if (ret)
+ dev_err(dev, "problem resetting device");
+
+ return ret;
+}
+
static ssize_t adis16209_write_reset(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
{
if (len < 1)
- return -1;
+ return -EINVAL;
switch (buf[0]) {
case '1':
case 'y':
case 'Y':
return adis16209_reset(dev);
}
- return -1;
+ return -EINVAL;
}
int adis16209_set_irq(struct device *dev, bool enable)
{
- int ret;
+ int ret = 0;
u16 msc;
+
ret = adis16209_spi_read_reg_16(dev, ADIS16209_MSC_CTRL, &msc);
if (ret)
goto error_ret;
@@ -324,44 +299,13 @@
msc &= ~ADIS16209_MSC_CTRL_DATA_RDY_EN;
ret = adis16209_spi_write_reg_16(dev, ADIS16209_MSC_CTRL, msc);
- if (ret)
- goto error_ret;
error_ret:
return ret;
}
-int adis16209_reset(struct device *dev)
+static int adis16209_check_status(struct device *dev)
{
- int ret;
- ret = adis16209_spi_write_reg_8(dev,
- ADIS16209_GLOB_CMD,
- ADIS16209_GLOB_CMD_SW_RESET);
- if (ret)
- dev_err(dev, "problem resetting device");
-
- return ret;
-}
-
-int adis16209_self_test(struct device *dev)
-{
- int ret;
- ret = adis16209_spi_write_reg_16(dev,
- ADIS16209_MSC_CTRL,
- ADIS16209_MSC_CTRL_SELF_TEST_EN);
- if (ret) {
- dev_err(dev, "problem starting self test");
- goto err_ret;
- }
-
- adis16209_check_status(dev);
-
-err_ret:
- return ret;
-}
-
-int adis16209_check_status(struct device *dev)
-{
u16 status;
int ret;
@@ -387,6 +331,23 @@
return ret;
}
+static int adis16209_self_test(struct device *dev)
+{
+ int ret;
+ ret = adis16209_spi_write_reg_16(dev,
+ ADIS16209_MSC_CTRL,
+ ADIS16209_MSC_CTRL_SELF_TEST_EN);
+ if (ret) {
+ dev_err(dev, "problem starting self test");
+ goto err_ret;
+ }
+
+ adis16209_check_status(dev);
+
+err_ret:
+ return ret;
+}
+
static int adis16209_initial_setup(struct adis16209_state *st)
{
int ret;
@@ -428,10 +389,10 @@
static IIO_DEV_ATTR_VOLT(supply, adis16209_read_14bit_unsigned,
ADIS16209_SUPPLY_OUT);
-static IIO_CONST_ATTR(volt_supply_scale, "0.30518 mV");
+static IIO_CONST_ATTR(volt_supply_scale, "0.30518");
static IIO_DEV_ATTR_VOLT(aux, adis16209_read_12bit_unsigned,
ADIS16209_AUX_ADC);
-static IIO_CONST_ATTR(volt_aux_scale, "0.6105 mV");
+static IIO_CONST_ATTR(volt_aux_scale, "0.6105");
static IIO_DEV_ATTR_ACCEL_X(adis16209_read_14bit_signed,
ADIS16209_XACCL_OUT);
@@ -445,7 +406,7 @@
adis16209_read_14bit_signed,
adis16209_write_16bit,
ADIS16209_YACCL_NULL);
-static IIO_CONST_ATTR(accel_scale, "0.24414 mg");
+static IIO_CONST_ATTR(accel_scale, "0.24414");
static IIO_DEV_ATTR_INCLI_X(adis16209_read_14bit_signed,
ADIS16209_XINCL_OUT);
@@ -459,14 +420,14 @@
adis16209_read_14bit_signed,
adis16209_write_16bit,
ADIS16209_YACCL_NULL);
-static IIO_CONST_ATTR(incli_scale, "0.025 D");
+static IIO_CONST_ATTR(incli_scale, "0.025");
static IIO_DEV_ATTR_ROT(adis16209_read_14bit_signed,
ADIS16209_ROT_OUT);
static IIO_DEV_ATTR_TEMP(adis16209_read_temp);
-static IIO_CONST_ATTR(temp_offset, "25 K");
-static IIO_CONST_ATTR(temp_scale, "-0.47 K");
+static IIO_CONST_ATTR(temp_offset, "25");
+static IIO_CONST_ATTR(temp_scale, "-0.47");
static IIO_DEV_ATTR_RESET(adis16209_write_reset);
@@ -562,7 +523,7 @@
goto error_unreg_ring_funcs;
}
- if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) {
+ if (spi->irq) {
ret = iio_register_interrupt_line(spi->irq,
st->indio_dev,
0,
@@ -583,10 +544,9 @@
return 0;
error_remove_trigger:
- if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
- adis16209_remove_trigger(st->indio_dev);
+ adis16209_remove_trigger(st->indio_dev);
error_unregister_line:
- if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
+ if (spi->irq)
iio_unregister_interrupt_line(st->indio_dev, 0);
error_uninitialize_ring:
adis16209_uninitialize_ring(st->indio_dev->ring);
@@ -607,7 +567,6 @@
return ret;
}
-/* fixme, confirm ordering in this function */
static int adis16209_remove(struct spi_device *spi)
{
struct adis16209_state *st = spi_get_drvdata(spi);
@@ -616,12 +575,12 @@
flush_scheduled_work();
adis16209_remove_trigger(indio_dev);
- if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
+ if (spi->irq)
iio_unregister_interrupt_line(indio_dev, 0);
adis16209_uninitialize_ring(indio_dev->ring);
- adis16209_unconfigure_ring(indio_dev);
iio_device_unregister(indio_dev);
+ adis16209_unconfigure_ring(indio_dev);
kfree(st->tx);
kfree(st->rx);
kfree(st);
Modified: trunk/drivers/staging/iio/accel/adis16209_ring.c (8690 => 8691)
--- trunk/drivers/staging/iio/accel/adis16209_ring.c 2010-05-06 04:50:04 UTC (rev 8690)
+++ trunk/drivers/staging/iio/accel/adis16209_ring.c 2010-05-06 10:10:36 UTC (rev 8691)
@@ -34,7 +34,7 @@
ADIS16209_YACCL_OUT, NULL);
static IIO_SCAN_EL_C(aux_adc, ADIS16209_SCAN_AUX_ADC, IIO_UNSIGNED(12),
ADIS16209_AUX_ADC, NULL);
-static IIO_SCAN_EL_C(temp, ADIS16209_SCAN_TEMP, IIO_SIGNED(12),
+static IIO_SCAN_EL_C(temp, ADIS16209_SCAN_TEMP, IIO_UNSIGNED(12),
ADIS16209_TEMP_OUT, NULL);
static IIO_SCAN_EL_C(incli_x, ADIS16209_SCAN_INCLI_X, IIO_SIGNED(14),
ADIS16209_XINCL_OUT, NULL);
@@ -74,6 +74,47 @@
schedule_work(&st->work_trigger_to_ring);
}
+/**
+ * adis16209_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 adis16209_read_ring_data(struct device *dev, u8 *rx)
+{
+ struct spi_message msg;
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct adis16209_state *st = iio_dev_get_devdata(indio_dev);
+ struct spi_transfer xfers[ADIS16209_OUTPUTS + 1];
+ int ret;
+ int i;
+
+ mutex_lock(&st->buf_lock);
+
+ spi_message_init(&msg);
+
+ memset(xfers, 0, sizeof(xfers));
+ for (i = 0; i <= ADIS16209_OUTPUTS; i++) {
+ xfers[i].bits_per_word = 8;
+ xfers[i].cs_change = 1;
+ xfers[i].len = 2;
+ xfers[i].delay_usecs = 20;
+ xfers[i].tx_buf = st->tx + 2 * i;
+ st->tx[2 * i] = ADIS16209_READ_REG(ADIS16209_SUPPLY_OUT + 2 * i);
+ 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;
+}
+
/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
* specific to be rolled into the core.
*/
@@ -95,7 +136,7 @@
}
if (st->indio_dev->scan_count)
- if (adis16209_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0)
+ if (adis16209_read_ring_data(&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]);
@@ -114,6 +155,7 @@
return;
}
+
/* in these circumstances is it better to go with unaligned packing and
* deal with the cost?*/
static int adis16209_data_rdy_ring_preenable(struct iio_dev *indio_dev)
@@ -126,8 +168,10 @@
if (indio_dev->ring->access.set_bpd) {
if (indio_dev->scan_timestamp)
- if (indio_dev->scan_count) /* Timestamp and data */
- size = 3*sizeof(s64);
+ if (indio_dev->scan_count)
+ /* Timestamp and data, let timestamp aligned with sizeof(s64) */
+ size = (((indio_dev->scan_count * sizeof(s16)) + sizeof(s64) - 1) & ~(sizeof(s64) - 1))
+ + sizeof(s64);
else /* Timestamp only */
size = sizeof(s64);
else /* Data only */
Modified: trunk/drivers/staging/iio/accel/adis16240.h (8690 => 8691)
--- trunk/drivers/staging/iio/accel/adis16240.h 2010-05-06 04:50:04 UTC (rev 8690)
+++ trunk/drivers/staging/iio/accel/adis16240.h 2010-05-06 10:10:36 UTC (rev 8691)
@@ -100,12 +100,6 @@
struct mutex buf_lock;
};
-int adis16240_spi_write_reg_8(struct device *dev,
- u8 reg_address,
- u8 val);
-
-int adis16240_spi_read_burst(struct device *dev, u8 *rx);
-
int adis16240_set_irq(struct device *dev, bool enable);
#ifdef CONFIG_IIO_RING_BUFFER
Modified: trunk/drivers/staging/iio/accel/adis16240_core.c (8690 => 8691)
--- trunk/drivers/staging/iio/accel/adis16240_core.c 2010-05-06 04:50:04 UTC (rev 8690)
+++ trunk/drivers/staging/iio/accel/adis16240_core.c 2010-05-06 10:10:36 UTC (rev 8691)
@@ -36,7 +36,7 @@
* @reg_address: the address of the register to be written
* @val: the value to write
**/
-int adis16240_spi_write_reg_8(struct device *dev,
+static int adis16240_spi_write_reg_8(struct device *dev,
u8 reg_address,
u8 val)
{
@@ -153,47 +153,6 @@
return ret;
}
-/**
- * adis16240_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
- **/
-int adis16240_spi_read_burst(struct device *dev, u8 *rx)
-{
- struct spi_message msg;
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct adis16240_state *st = iio_dev_get_devdata(indio_dev);
- struct spi_transfer xfers[ADIS16240_OUTPUTS + 1];
- int ret;
- int i;
-
- mutex_lock(&st->buf_lock);
-
- spi_message_init(&msg);
-
- memset(xfers, 0, sizeof(xfers));
- for (i = 0; i <= ADIS16240_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;
- st->tx[2 * i] = ADIS16240_READ_REG(ADIS16240_SUPPLY_OUT + 2 * i);
- 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;
-}
-
static ssize_t adis16240_spi_read_signed(struct device *dev,
struct device_attribute *attr,
char *buf,
@@ -227,6 +186,9 @@
if (ret)
return ret;
+ if (val & ADIS16240_ERROR_ACTIVE)
+ adis16240_check_status(dev);
+
return sprintf(buf, "%u\n", val & 0x03FF);
}
@@ -295,20 +257,21 @@
const char *buf, size_t len)
{
if (len < 1)
- return -1;
+ return -EINVAL;
switch (buf[0]) {
case '1':
case 'y':
case 'Y':
return adis16240_reset(dev);
}
- return -1;
+ return -EINVAL;
}
int adis16240_set_irq(struct device *dev, bool enable)
{
- int ret;
+ int ret = 0;
u16 msc;
+
ret = adis16240_spi_read_reg_16(dev, ADIS16240_MSC_CTRL, &msc);
if (ret)
goto error_ret;
@@ -321,8 +284,6 @@
msc &= ~ADIS16240_MSC_CTRL_DATA_RDY_EN;
ret = adis16240_spi_write_reg_16(dev, ADIS16240_MSC_CTRL, msc);
- if (ret)
- goto error_ret;
error_ret:
return ret;
@@ -445,8 +406,8 @@
adis16240_read_10bit_signed,
adis16240_write_16bit,
ADIS16240_ZACCL_OFF);
-static IIO_DEV_ATTR_TEMP(adis16240_read_10bit_signed);
-static IIO_CONST_ATTR(temp_scale, "0.244 K");
+static IIO_DEV_ATTR_TEMP(adis16240_read_10bit_unsigned);
+static IIO_CONST_ATTR(temp_scale, "0.244");
static IIO_DEV_ATTR_RESET(adis16240_write_reset);
@@ -542,7 +503,7 @@
goto error_unreg_ring_funcs;
}
- if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) {
+ if (spi->irq) {
ret = iio_register_interrupt_line(spi->irq,
st->indio_dev,
0,
@@ -563,10 +524,9 @@
return 0;
error_remove_trigger:
- if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
- adis16240_remove_trigger(st->indio_dev);
+ adis16240_remove_trigger(st->indio_dev);
error_unregister_line:
- if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
+ if (spi->irq)
iio_unregister_interrupt_line(st->indio_dev, 0);
error_uninitialize_ring:
adis16240_uninitialize_ring(st->indio_dev->ring);
@@ -587,7 +547,6 @@
return ret;
}
-/* fixme, confirm ordering in this function */
static int adis16240_remove(struct spi_device *spi)
{
struct adis16240_state *st = spi_get_drvdata(spi);
@@ -596,12 +555,12 @@
flush_scheduled_work();
adis16240_remove_trigger(indio_dev);
- if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
+ if (spi->irq)
iio_unregister_interrupt_line(indio_dev, 0);
adis16240_uninitialize_ring(indio_dev->ring);
- adis16240_unconfigure_ring(indio_dev);
iio_device_unregister(indio_dev);
+ adis16240_unconfigure_ring(indio_dev);
kfree(st->tx);
kfree(st->rx);
kfree(st);
Modified: trunk/drivers/staging/iio/accel/adis16240_ring.c (8690 => 8691)
--- trunk/drivers/staging/iio/accel/adis16240_ring.c 2010-05-06 04:50:04 UTC (rev 8690)
+++ trunk/drivers/staging/iio/accel/adis16240_ring.c 2010-05-06 10:10:36 UTC (rev 8691)
@@ -27,17 +27,17 @@
}
static IIO_SCAN_EL_C(supply, ADIS16240_SCAN_SUPPLY, IIO_UNSIGNED(10),
- ADIS16240_SUPPLY_OUT, NULL);
+ ADIS16240_SUPPLY_OUT, NULL);
static IIO_SCAN_EL_C(accel_x, ADIS16240_SCAN_ACC_X, IIO_SIGNED(10),
- ADIS16240_XACCL_OUT, NULL);
+ ADIS16240_XACCL_OUT, NULL);
static IIO_SCAN_EL_C(accel_y, ADIS16240_SCAN_ACC_Y, IIO_SIGNED(10),
- ADIS16240_YACCL_OUT, NULL);
+ ADIS16240_YACCL_OUT, NULL);
static IIO_SCAN_EL_C(accel_z, ADIS16240_SCAN_ACC_Z, IIO_SIGNED(10),
- ADIS16240_ZACCL_OUT, NULL);
+ ADIS16240_ZACCL_OUT, NULL);
static IIO_SCAN_EL_C(aux_adc, ADIS16240_SCAN_AUX_ADC, IIO_UNSIGNED(10),
- ADIS16240_AUX_ADC, NULL);
-static IIO_SCAN_EL_C(temp, ADIS16240_SCAN_TEMP, IIO_SIGNED(10),
- ADIS16240_TEMP_OUT, NULL);
+ ADIS16240_AUX_ADC, NULL);
+static IIO_SCAN_EL_C(temp, ADIS16240_SCAN_TEMP, IIO_UNSIGNED(10),
+ ADIS16240_TEMP_OUT, NULL);
static IIO_SCAN_EL_TIMESTAMP;
@@ -68,14 +68,53 @@
schedule_work(&st->work_trigger_to_ring);
}
-/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
- * specific to be rolled into the core.
- */
+/**
+ * adis16240_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 adis16240_read_ring_data(struct device *dev, u8 *rx)
+{
+ struct spi_message msg;
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct adis16240_state *st = iio_dev_get_devdata(indio_dev);
+ struct spi_transfer xfers[ADIS16240_OUTPUTS + 1];
+ int ret;
+ int i;
+
+ mutex_lock(&st->buf_lock);
+
+ spi_message_init(&msg);
+
+ memset(xfers, 0, sizeof(xfers));
+ for (i = 0; i <= ADIS16240_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;
+ st->tx[2 * i] = ADIS16240_READ_REG(ADIS16240_SUPPLY_OUT + 2 * i);
+ 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;
+}
+
+
static void adis16240_trigger_bh_to_ring(struct work_struct *work_s)
{
struct adis16240_state *st
= container_of(work_s, struct adis16240_state,
- work_trigger_to_ring);
+ work_trigger_to_ring);
int i = 0;
s16 *data;
@@ -89,10 +128,10 @@
}
if (st->indio_dev->scan_count)
- if (adis16240_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0)
+ if (adis16240_read_ring_data(&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]);
+ st->rx[i*2]);
}
/* Guaranteed to be aligned with 8 byte boundary */
@@ -100,16 +139,15 @@
*((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp;
st->indio_dev->ring->access.store_to(st->indio_dev->ring,
- (u8 *)data,
- st->last_timestamp);
+ (u8 *)data,
+ st->last_timestamp);
iio_trigger_notify_done(st->indio_dev->trig);
kfree(data);
return;
}
-/* in these circumstances is it better to go with unaligned packing and
- * deal with the cost?*/
+
static int adis16240_data_rdy_ring_preenable(struct iio_dev *indio_dev)
{
size_t size;
@@ -120,8 +158,10 @@
if (indio_dev->ring->access.set_bpd) {
if (indio_dev->scan_timestamp)
- if (indio_dev->scan_count) /* Timestamp and data */
- size = 3*sizeof(s64);
+ if (indio_dev->scan_count)
+ /* Timestamp and data, let timestamp aligned with sizeof(s64) */
+ size = (((indio_dev->scan_count * sizeof(s16)) + sizeof(s64) - 1) & ~(sizeof(s64) - 1))
+ + sizeof(s64);
else /* Timestamp only */
size = sizeof(s64);
else /* Data only */
@@ -136,7 +176,7 @@
{
return indio_dev->trig
? iio_trigger_attach_poll_func(indio_dev->trig,
- indio_dev->pollfunc)
+ indio_dev->pollfunc)
: 0;
}
@@ -144,7 +184,7 @@
{
return indio_dev->trig
? iio_trigger_dettach_poll_func(indio_dev->trig,
- indio_dev->pollfunc)
+ indio_dev->pollfunc)
: 0;
}