Skip to content

Commit 1e2202c

Browse files
committed
iio: adc: ad7768-1: Use new spi-engine implementation
Add support for new spi-engine implementation on ad7768-1 driver. This optimizes the offload transfers by reducing the CS delay and removing the number of commands on offload's FIFO, which makes the low latency mode viable. Without the otimization there's not enough time between the end of a transfer and the start of the next one, reducing the actual sample rate. Signed-off-by: jonathanns <Jonathan.Santos@analog.com>
1 parent b21a7fd commit 1e2202c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

drivers/iio/adc/ad7768-1.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* Copyright 2017 Analog Devices Inc.
66
*/
7+
#include "linux/byteorder/little_endian.h"
78
#include <linux/bitfield.h>
89
#include <linux/clk.h>
910
#include <linux/delay.h>
@@ -20,7 +21,7 @@
2021
#include <linux/regulator/consumer.h>
2122
#include <linux/sysfs.h>
2223
#include <linux/spi/spi.h>
23-
#include <linux/spi/spi-engine.h>
24+
#include <linux/spi/spi-engine-ex.h>
2425
#include <linux/util_macros.h>
2526
#include <linux/units.h>
2627
#include <linux/rational.h>
@@ -444,7 +445,7 @@ struct ad7768_state {
444445
*/
445446
union {
446447
unsigned char buf[6];
447-
__be32 word;
448+
__le32 word;
448449
struct {
449450
__be32 chan;
450451
s64 timestamp;
@@ -458,16 +459,16 @@ static int ad7768_spi_reg_read(struct ad7768_state *st, unsigned int addr,
458459
struct spi_transfer xfer = {
459460
.rx_buf = st->data.buf,
460461
.len = len + 1,
461-
.bits_per_word = (len == 3 ? 32 : 16),
462462
};
463463
unsigned char tx_data[4];
464464
int ret;
465+
465466
tx_data[0] = AD7768_RD_FLAG_MSK(addr);
466467
xfer.tx_buf = tx_data;
467468
ret = spi_sync_transfer(st->spi, &xfer, 1);
468469
if (ret < 0)
469470
return ret;
470-
*data = (len == 1 ? st->data.buf[0] : st->data.word);
471+
*data = (len == 1 ? st->data.buf[1] : cpu_to_be32(st->data.word));
471472
return ret;
472473
}
473474

@@ -478,7 +479,6 @@ static int ad7768_spi_reg_write(struct ad7768_state *st,
478479
struct spi_transfer xfer = {
479480
.rx_buf = st->data.buf,
480481
.len = 2,
481-
.bits_per_word = 16,
482482
};
483483
unsigned char tx_data[2];
484484
tx_data[0] = AD7768_WR_FLAG_MSK(addr);
@@ -1214,12 +1214,16 @@ static int ad7768_buffer_postenable(struct iio_dev *indio_dev)
12141214
st->offload_xfer.rx_buf = rx_data;
12151215
spi_message_init_with_transfers(&st->offload_msg, &st->offload_xfer, 1);
12161216

1217+
ret = spi_optimize_message(st->spi, &st->offload_msg);
1218+
if (ret < 0)
1219+
return ret;
1220+
12171221
spi_bus_lock(st->spi->master);
12181222

1219-
ret = spi_engine_offload_load_msg(st->spi, &st->offload_msg);
1223+
ret = spi_engine_ex_offload_load_msg(st->spi, &st->offload_msg);
12201224
if (ret < 0)
12211225
return ret;
1222-
spi_engine_offload_enable(st->spi, true);
1226+
spi_engine_ex_offload_enable(st->spi, true);
12231227
}
12241228

12251229
return ret;
@@ -1231,9 +1235,10 @@ static int ad7768_buffer_predisable(struct iio_dev *indio_dev)
12311235
unsigned int regval;
12321236

12331237
if (st->spi_is_dma_mapped) {
1234-
spi_engine_offload_enable(st->spi, false);
1238+
spi_engine_ex_offload_enable(st->spi, false);
12351239
spi_bus_unlock(st->spi->master);
12361240
}
1241+
spi_unoptimize_message(&st->offload_msg);
12371242

12381243
/*
12391244
* To exit continuous read mode, perform a single read of the ADC_DATA
@@ -1445,7 +1450,7 @@ static int ad7768_probe(struct spi_device *spi)
14451450
return PTR_ERR(st->mclk);
14461451

14471452
st->mclk_freq = clk_get_rate(st->mclk);
1448-
st->spi_is_dma_mapped = spi_engine_offload_supported(spi);
1453+
st->spi_is_dma_mapped = spi_engine_ex_offload_supported(spi);
14491454
st->irq = spi->irq;
14501455
st->vref = regulator_get_voltage(st->regulator);
14511456

0 commit comments

Comments
 (0)