60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/interrupt.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/spi/spi.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/iio/iio.h>
|
|
#include <linux/iio/buffer.h>
|
|
#include <linux/iio/triggered_buffer.h>
|
|
#include <linux/iio/trigger_consumer.h>
|
|
|
|
#include "adis16400.h"
|
|
|
|
int adis16400_update_scan_mode(struct iio_dev *indio_dev,
|
|
const unsigned long *scan_mask)
|
|
{
|
|
struct adis16400_state *st = iio_priv(indio_dev);
|
|
struct adis *adis = &st->adis;
|
|
unsigned int burst_length;
|
|
u8 *tx;
|
|
|
|
if (!adis->burst || !adis->burst->en)
|
|
return adis_update_scan_mode(indio_dev, scan_mask);
|
|
|
|
kfree(adis->xfer);
|
|
kfree(adis->buffer);
|
|
|
|
/* All but the timestamp channel */
|
|
burst_length = (indio_dev->num_channels - 1) * sizeof(u16);
|
|
burst_length += adis->burst->extra_len;
|
|
|
|
adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL);
|
|
if (!adis->xfer)
|
|
return -ENOMEM;
|
|
|
|
adis->buffer = kzalloc(burst_length + sizeof(u16), GFP_KERNEL);
|
|
if (!adis->buffer)
|
|
return -ENOMEM;
|
|
|
|
tx = adis->buffer + burst_length;
|
|
tx[0] = ADIS_READ_REG(adis->burst->reg_cmd);
|
|
tx[1] = 0;
|
|
|
|
adis->xfer[0].tx_buf = tx;
|
|
adis->xfer[0].bits_per_word = 8;
|
|
adis->xfer[0].len = 2;
|
|
adis->xfer[1].rx_buf = adis->buffer;
|
|
adis->xfer[1].bits_per_word = 8;
|
|
adis->xfer[1].len = burst_length;
|
|
|
|
spi_message_init(&adis->msg);
|
|
spi_message_add_tail(&adis->xfer[0], &adis->msg);
|
|
spi_message_add_tail(&adis->xfer[1], &adis->msg);
|
|
|
|
return 0;
|
|
}
|