Skip to content

Commit d2ead60

Browse files
Sean Andersonbroonie
authored andcommitted
spi: zynqmp-gqspi: Add helpers for enabling/disabling DMA
DMA is enabled and disabled several times in the driver. Add some helper functions for this task. Signed-off-by: Sean Anderson <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent ba54629 commit d2ead60

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

drivers/spi/spi-zynqmp-gqspi.c

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,33 @@ static void zynqmp_qspi_fillgenfifo(struct zynqmp_qspi *xqspi, u8 nbits,
739739
}
740740
}
741741

742+
/**
743+
* zynqmp_qspi_disable_dma() - Disable DMA mode
744+
* @xqspi: GQSPI instance
745+
*/
746+
static void zynqmp_qspi_disable_dma(struct zynqmp_qspi *xqspi)
747+
{
748+
u32 config_reg = zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST);
749+
750+
config_reg &= ~GQSPI_CFG_MODE_EN_MASK;
751+
zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, config_reg);
752+
xqspi->mode = GQSPI_MODE_IO;
753+
}
754+
755+
/**
756+
* zynqmp_qspi_enable_dma() - Enable DMA mode
757+
* @xqspi: GQSPI instance
758+
*/
759+
static void zynqmp_qspi_enable_dma(struct zynqmp_qspi *xqspi)
760+
{
761+
u32 config_reg = zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST);
762+
763+
config_reg &= ~GQSPI_CFG_MODE_EN_MASK;
764+
config_reg |= GQSPI_CFG_MODE_EN_DMA_MASK;
765+
zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, config_reg);
766+
xqspi->mode = GQSPI_MODE_DMA;
767+
}
768+
742769
/**
743770
* zynqmp_process_dma_irq - Handler for DMA done interrupt of QSPI
744771
* controller
@@ -748,7 +775,7 @@ static void zynqmp_qspi_fillgenfifo(struct zynqmp_qspi *xqspi, u8 nbits,
748775
*/
749776
static void zynqmp_process_dma_irq(struct zynqmp_qspi *xqspi)
750777
{
751-
u32 config_reg, genfifoentry;
778+
u32 genfifoentry;
752779

753780
dma_unmap_single(xqspi->dev, xqspi->dma_addr,
754781
xqspi->dma_rx_bytes, DMA_FROM_DEVICE);
@@ -762,9 +789,7 @@ static void zynqmp_process_dma_irq(struct zynqmp_qspi *xqspi)
762789

763790
if (xqspi->bytes_to_receive > 0) {
764791
/* Switch to IO mode,for remaining bytes to receive */
765-
config_reg = zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST);
766-
config_reg &= ~GQSPI_CFG_MODE_EN_MASK;
767-
zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, config_reg);
792+
zynqmp_qspi_disable_dma(xqspi);
768793

769794
/* Initiate the transfer of remaining bytes */
770795
genfifoentry = xqspi->genfifoentry;
@@ -849,17 +874,14 @@ static irqreturn_t zynqmp_qspi_irq(int irq, void *dev_id)
849874
*/
850875
static int zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi)
851876
{
852-
u32 rx_bytes, rx_rem, config_reg;
877+
u32 rx_bytes, rx_rem;
853878
dma_addr_t addr;
854879
u64 dma_align = (u64)(uintptr_t)xqspi->rxbuf;
855880

856881
if (xqspi->bytes_to_receive < 8 ||
857882
((dma_align & GQSPI_DMA_UNALIGN) != 0x0)) {
858883
/* Setting to IO mode */
859-
config_reg = zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST);
860-
config_reg &= ~GQSPI_CFG_MODE_EN_MASK;
861-
zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, config_reg);
862-
xqspi->mode = GQSPI_MODE_IO;
884+
zynqmp_qspi_disable_dma(xqspi);
863885
xqspi->dma_rx_bytes = 0;
864886
return 0;
865887
}
@@ -882,14 +904,7 @@ static int zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi)
882904
zynqmp_gqspi_write(xqspi, GQSPI_QSPIDMA_DST_ADDR_MSB_OFST,
883905
((u32)addr) & 0xfff);
884906

885-
/* Enabling the DMA mode */
886-
config_reg = zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST);
887-
config_reg &= ~GQSPI_CFG_MODE_EN_MASK;
888-
config_reg |= GQSPI_CFG_MODE_EN_DMA_MASK;
889-
zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, config_reg);
890-
891-
/* Switch to DMA mode */
892-
xqspi->mode = GQSPI_MODE_DMA;
907+
zynqmp_qspi_enable_dma(xqspi);
893908

894909
/* Write the number of bytes to transfer */
895910
zynqmp_gqspi_write(xqspi, GQSPI_QSPIDMA_DST_SIZE_OFST, rx_bytes);
@@ -909,18 +924,10 @@ static int zynqmp_qspi_setuprxdma(struct zynqmp_qspi *xqspi)
909924
static void zynqmp_qspi_write_op(struct zynqmp_qspi *xqspi, u8 tx_nbits,
910925
u32 genfifoentry)
911926
{
912-
u32 config_reg;
913-
914927
zynqmp_qspi_fillgenfifo(xqspi, tx_nbits, genfifoentry);
915928
zynqmp_qspi_filltxfifo(xqspi, GQSPI_TXD_DEPTH);
916-
if (xqspi->mode == GQSPI_MODE_DMA) {
917-
config_reg = zynqmp_gqspi_read(xqspi,
918-
GQSPI_CONFIG_OFST);
919-
config_reg &= ~GQSPI_CFG_MODE_EN_MASK;
920-
zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
921-
config_reg);
922-
xqspi->mode = GQSPI_MODE_IO;
923-
}
929+
if (xqspi->mode == GQSPI_MODE_DMA)
930+
zynqmp_qspi_disable_dma(xqspi);
924931
}
925932

926933
/**

0 commit comments

Comments
 (0)