Skip to content

Commit fb507b7

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: Jonathan Santos <Jonathan.Santos@analog.com>
1 parent d16d5bc commit fb507b7

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

drivers/iio/adc/ad7768-1.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <linux/sysfs.h>
2222
#include "linux/util_macros.h"
2323
#include <linux/spi/spi.h>
24-
#include <linux/spi/spi-engine.h>
24+
#include <linux/spi/spi-engine-ex.h>
2525

2626
#include <linux/iio/buffer.h>
2727
#include <linux/iio/buffer-dma.h>
@@ -300,6 +300,8 @@ struct ad7768_state {
300300
struct mutex lock;
301301
struct clk *mclk;
302302
struct gpio_chip gpiochip;
303+
struct spi_transfer offload_xfer;
304+
struct spi_message offload_msg;
303305
unsigned int gpio_avail_map;
304306
unsigned int mclk_freq;
305307
unsigned int samp_freq;
@@ -341,7 +343,7 @@ static int ad7768_spi_reg_read(struct ad7768_state *st, unsigned int addr,
341343
unsigned char tx_data[4];
342344
int ret;
343345

344-
tx_data[0] = AD7768_RD_FLAG_MSK(addr);
346+
tx_data[len] = AD7768_RD_FLAG_MSK(addr);
345347
xfer.tx_buf = tx_data;
346348
ret = spi_sync_transfer(st->spi, &xfer, 1);
347349
if (ret < 0)
@@ -362,8 +364,8 @@ static int ad7768_spi_reg_write(struct ad7768_state *st,
362364
};
363365
unsigned char tx_data[2];
364366

365-
tx_data[0] = AD7768_WR_FLAG_MSK(addr);
366-
tx_data[1] = val & 0xFF;
367+
tx_data[1] = AD7768_WR_FLAG_MSK(addr);
368+
tx_data[0] = val & 0xFF;
367369
xfer.tx_buf = tx_data;
368370
return spi_sync_transfer(st->spi, &xfer, 1);
369371
}
@@ -1040,19 +1042,16 @@ static irqreturn_t ad7768_interrupt(int irq, void *dev_id)
10401042
static int ad7768_buffer_postenable(struct iio_dev *indio_dev)
10411043
{
10421044
struct ad7768_state *st = iio_priv(indio_dev);
1043-
struct spi_transfer xfer = {
1044-
.len = 1,
1045-
};
10461045
unsigned int rx_data[2];
1047-
struct spi_message msg;
10481046
const struct iio_scan_type *scan_type;
10491047
int ret;
10501048

10511049
scan_type = iio_get_current_scan_type(indio_dev, &indio_dev->channels[0]);
10521050
if (IS_ERR(scan_type))
10531051
return PTR_ERR(scan_type);
10541052

1055-
xfer.bits_per_word = scan_type->realbits;
1053+
st->offload_xfer.len = roundup_pow_of_two(BITS_TO_BYTES(scan_type->realbits));
1054+
st->offload_xfer.bits_per_word = scan_type->realbits;
10561055

10571056
/*
10581057
* Write a 1 to the LSB of the INTERFACE_FORMAT register to enter
@@ -1064,14 +1063,19 @@ static int ad7768_buffer_postenable(struct iio_dev *indio_dev)
10641063
return ret;
10651064

10661065
if (st->spi_is_dma_mapped) {
1066+
st->offload_xfer.rx_buf = rx_data;
1067+
spi_message_init_with_transfers(&st->offload_msg, &st->offload_xfer, 1);
1068+
1069+
ret = spi_optimize_message(st->spi, &st->offload_msg);
1070+
if (ret < 0)
1071+
return ret;
1072+
10671073
spi_bus_lock(st->spi->master);
10681074

1069-
xfer.rx_buf = rx_data;
1070-
spi_message_init_with_transfers(&msg, &xfer, 1);
1071-
ret = spi_engine_offload_load_msg(st->spi, &msg);
1075+
ret = spi_engine_ex_offload_load_msg(st->spi, &st->offload_msg);
10721076
if (ret < 0)
10731077
return ret;
1074-
spi_engine_offload_enable(st->spi, true);
1078+
spi_engine_ex_offload_enable(st->spi, true);
10751079
}
10761080

10771081
return ret;
@@ -1083,9 +1087,10 @@ static int ad7768_buffer_predisable(struct iio_dev *indio_dev)
10831087
unsigned int regval;
10841088

10851089
if (st->spi_is_dma_mapped) {
1086-
spi_engine_offload_enable(st->spi, false);
1090+
spi_engine_ex_offload_enable(st->spi, false);
10871091
spi_bus_unlock(st->spi->master);
10881092
}
1093+
spi_unoptimize_message(&st->offload_msg);
10891094

10901095
/*
10911096
* To exit continuous read mode, perform a single read of the ADC_DATA
@@ -1219,7 +1224,7 @@ static int ad7768_probe(struct spi_device *spi)
12191224
return PTR_ERR(st->mclk);
12201225

12211226
st->mclk_freq = clk_get_rate(st->mclk);
1222-
st->spi_is_dma_mapped = spi_engine_offload_supported(spi);
1227+
st->spi_is_dma_mapped = spi_engine_ex_offload_supported(spi);
12231228
st->irq = spi->irq;
12241229

12251230
mutex_init(&st->lock);

0 commit comments

Comments
 (0)