mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 12:11:40 +00:00
spi: ath79: add mem_ops for fast-read
Reading from memory is 3x faster than bit-bang read operation. Also, for tl-wr2543nd, the bit-bang read was sporadically returning random data, possibly a HW defect, while fast-read works as expected. Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com> Link: https://lore.kernel.org/r/20220129040453.8476-1-luizluca@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
47e8fe57a6
commit
d08de0259d
@ -15,6 +15,7 @@
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#include <linux/spi/spi-mem.h>
|
||||
#include <linux/spi/spi_bitbang.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/clk.h>
|
||||
@ -133,6 +134,38 @@ static u32 ath79_spi_txrx_mode0(struct spi_device *spi, unsigned int nsecs,
|
||||
return ath79_spi_rr(sp, AR71XX_SPI_REG_RDS);
|
||||
}
|
||||
|
||||
static int ath79_exec_mem_op(struct spi_mem *mem,
|
||||
const struct spi_mem_op *op)
|
||||
{
|
||||
struct ath79_spi *sp = ath79_spidev_to_sp(mem->spi);
|
||||
|
||||
/* Ensures that reading is performed on device connected to hardware cs0 */
|
||||
if (mem->spi->chip_select || mem->spi->cs_gpiod)
|
||||
return -ENOTSUPP;
|
||||
|
||||
/* Only use for fast-read op. */
|
||||
if (op->cmd.opcode != 0x0b || op->data.dir != SPI_MEM_DATA_IN ||
|
||||
op->addr.nbytes != 3 || op->dummy.nbytes != 1)
|
||||
return -ENOTSUPP;
|
||||
|
||||
/* disable GPIO mode */
|
||||
ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
|
||||
|
||||
memcpy_fromio(op->data.buf.in, sp->base + op->addr.val, op->data.nbytes);
|
||||
|
||||
/* enable GPIO mode */
|
||||
ath79_spi_wr(sp, AR71XX_SPI_REG_FS, AR71XX_SPI_FS_GPIO);
|
||||
|
||||
/* restore IOC register */
|
||||
ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct spi_controller_mem_ops ath79_mem_ops = {
|
||||
.exec_op = ath79_exec_mem_op,
|
||||
};
|
||||
|
||||
static int ath79_spi_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct spi_master *master;
|
||||
@ -154,6 +187,7 @@ static int ath79_spi_probe(struct platform_device *pdev)
|
||||
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
|
||||
master->flags = SPI_MASTER_GPIO_SS;
|
||||
master->num_chipselect = 3;
|
||||
master->mem_ops = &ath79_mem_ops;
|
||||
|
||||
sp->bitbang.master = master;
|
||||
sp->bitbang.chipselect = ath79_spi_chipselect;
|
||||
|
Loading…
Reference in New Issue
Block a user