Skip to content

Commit 700a522

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 af7d935 commit 700a522

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

drivers/iio/adc/ad7768-1.c

Lines changed: 20 additions & 12 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;
@@ -343,7 +345,7 @@ static int ad7768_spi_reg_read(struct ad7768_state *st, unsigned int addr,
343345
unsigned char tx_data[4];
344346
int ret;
345347

346-
tx_data[0] = AD7768_RD_FLAG_MSK(addr);
348+
tx_data[len] = AD7768_RD_FLAG_MSK(addr);
347349
xfer.tx_buf = tx_data;
348350
ret = spi_sync_transfer(st->spi, &xfer, 1);
349351
if (ret < 0)
@@ -364,8 +366,8 @@ static int ad7768_spi_reg_write(struct ad7768_state *st,
364366
};
365367
unsigned char tx_data[2];
366368

367-
tx_data[0] = AD7768_WR_FLAG_MSK(addr);
368-
tx_data[1] = val & 0xFF;
369+
tx_data[1] = AD7768_WR_FLAG_MSK(addr);
370+
tx_data[0] = val & 0xFF;
369371
xfer.tx_buf = tx_data;
370372
return spi_sync_transfer(st->spi, &xfer, 1);
371373
}
@@ -1067,14 +1069,14 @@ static int ad7768_buffer_postenable(struct iio_dev *indio_dev)
10671069
.len = 1,
10681070
};
10691071
unsigned int rx_data[2];
1070-
struct spi_message msg;
10711072
int ret;
10721073

10731074
scan_type = iio_get_current_scan_type(indio_dev, &indio_dev->channels[0]);
10741075
if (IS_ERR(scan_type))
10751076
return PTR_ERR(scan_type);
10761077

1077-
xfer.bits_per_word = scan_type->realbits;
1078+
st->offload_xfer.len = roundup_pow_of_two(BITS_TO_BYTES(scan_type->realbits));
1079+
st->offload_xfer.bits_per_word = scan_type->realbits;
10781080

10791081
/*
10801082
* Write a 1 to the LSB of the INTERFACE_FORMAT register to enter
@@ -1086,14 +1088,19 @@ static int ad7768_buffer_postenable(struct iio_dev *indio_dev)
10861088
return ret;
10871089

10881090
if (st->spi_is_dma_mapped) {
1091+
st->offload_xfer.rx_buf = rx_data;
1092+
spi_message_init_with_transfers(&st->offload_msg, &st->offload_xfer, 1);
1093+
1094+
ret = spi_optimize_message(st->spi, &st->offload_msg);
1095+
if (ret < 0)
1096+
return ret;
1097+
10891098
spi_bus_lock(st->spi->master);
10901099

1091-
xfer.rx_buf = rx_data;
1092-
spi_message_init_with_transfers(&msg, &xfer, 1);
1093-
ret = spi_engine_offload_load_msg(st->spi, &msg);
1100+
ret = spi_engine_ex_offload_load_msg(st->spi, &st->offload_msg);
10941101
if (ret < 0)
10951102
return ret;
1096-
spi_engine_offload_enable(st->spi, true);
1103+
spi_engine_ex_offload_enable(st->spi, true);
10971104
}
10981105

10991106
return ret;
@@ -1105,9 +1112,10 @@ static int ad7768_buffer_predisable(struct iio_dev *indio_dev)
11051112
unsigned int regval;
11061113

11071114
if (st->spi_is_dma_mapped) {
1108-
spi_engine_offload_enable(st->spi, false);
1115+
spi_engine_ex_offload_enable(st->spi, false);
11091116
spi_bus_unlock(st->spi->master);
11101117
}
1118+
spi_unoptimize_message(&st->offload_msg);
11111119

11121120
/*
11131121
* To exit continuous read mode, perform a single read of the ADC_DATA
@@ -1241,7 +1249,7 @@ static int ad7768_probe(struct spi_device *spi)
12411249
return PTR_ERR(st->mclk);
12421250

12431251
st->mclk_freq = clk_get_rate(st->mclk);
1244-
st->spi_is_dma_mapped = spi_engine_offload_supported(spi);
1252+
st->spi_is_dma_mapped = spi_engine_ex_offload_supported(spi);
12451253
st->irq = spi->irq;
12461254

12471255
mutex_init(&st->lock);

0 commit comments

Comments
 (0)