From 0a1402492dcce137e63de785e9f4934a30463143 Mon Sep 17 00:00:00 2001 From: Siva Durga Prasad Paladugu Date: Tue, 28 Jan 2020 23:45:01 -0700 Subject: [PATCH] spi: xilinx_spi: Modify transfer logic for quad mode Modify the transfer logic to get it working for both single and quad modes. The controller expects 4 dummy bytes for quad read and also expects the txfifo filled with full command and required args before starting the transfer. This fixes an issue in reading from device using quad read command. Signed-off-by: Siva Durga Prasad Paladugu Signed-off-by: Michal Simek Signed-off-by: Ashok Reddy Soma State: pending --- drivers/spi/xilinx_spi.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c index 81f84a20cf2..1b587f381da 100644 --- a/drivers/spi/xilinx_spi.c +++ b/drivers/spi/xilinx_spi.c @@ -73,7 +73,7 @@ DECLARE_GLOBAL_DATA_PTR; #define XILSPI_MAX_XFER_BITS 8 #define XILSPI_SPICR_DFLT_ON (SPICR_MANUAL_SS | SPICR_MASTER_MODE | \ - SPICR_SPE) + SPICR_SPE | SPICR_MASTER_INHIBIT) #define XILSPI_SPICR_DFLT_OFF (SPICR_MASTER_INHIBIT | SPICR_MANUAL_SS) #ifndef CONFIG_XILINX_SPI_IDLE_VAL @@ -84,6 +84,9 @@ DECLARE_GLOBAL_DATA_PTR; #define XILINX_SPI_QUAD_MODE 2 +#define XILINX_SPI_QUAD_EXTRA_DUMMY 3 +#define SPI_QUAD_OUT_FAST_READ 0x6B + /* xilinx spi register set */ struct xilinx_spi_regs { u32 __space0__[7]; @@ -155,7 +158,10 @@ static void spi_cs_deactivate(struct udevice *dev) struct udevice *bus = dev_get_parent(dev); struct xilinx_spi_priv *priv = dev_get_priv(bus); struct xilinx_spi_regs *regs = priv->regs; + u32 reg; + reg = readl(®s->spicr) | SPICR_RXFIFO_RESEST | SPICR_TXFIFO_RESEST; + writel(reg, ®s->spicr); writel(SPISSR_OFF, ®s->spissr); } @@ -286,8 +292,18 @@ static int xilinx_spi_xfer(struct udevice *dev, unsigned int bitlen, goto done; } - if (flags & SPI_XFER_BEGIN) + if (flags & SPI_XFER_BEGIN) { spi_cs_activate(dev, slave_plat->cs); + /* FIX ME Temporary hack to fix Quad read + * check if the command is Quad out fast read + * and increase dummy bytes by 3 so a total of 4 + * (3 here + 1 from framework) + */ + if (*txp == SPI_QUAD_OUT_FAST_READ) { + txbytes += XILINX_SPI_QUAD_EXTRA_DUMMY; + rxbytes += XILINX_SPI_QUAD_EXTRA_DUMMY; + } + } /* * This is the work around for the startup block issue in