Skip to content

Commit 9b32c86

Browse files
Sean Andersonbroonie
authored andcommitted
spi: zynqmp-gqspi: Clean up fillgenfifo
This function does a lot more work (assigning things multiple times, masking unnecessarily, comparing to zero, using superfluous parentheses) than it needs to. This makes it difficult to understand and modify. Clean it up. No functional change intended. Signed-off-by: Sean Anderson <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent d2ead60 commit 9b32c86

File tree

1 file changed

+28
-50
lines changed

1 file changed

+28
-50
lines changed

drivers/spi/spi-zynqmp-gqspi.c

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
#define GQSPI_GENFIFO_RX 0x00020000
8383
#define GQSPI_GENFIFO_STRIPE 0x00040000
8484
#define GQSPI_GENFIFO_POLL 0x00080000
85-
#define GQSPI_GENFIFO_EXP_START 0x00000100
8685
#define GQSPI_FIFO_CTRL_RST_RX_FIFO_MASK 0x00000004
8786
#define GQSPI_FIFO_CTRL_RST_TX_FIFO_MASK 0x00000002
8887
#define GQSPI_FIFO_CTRL_RST_GEN_FIFO_MASK 0x00000001
@@ -672,71 +671,50 @@ static void zynqmp_qspi_readrxfifo(struct zynqmp_qspi *xqspi, u32 size)
672671
static void zynqmp_qspi_fillgenfifo(struct zynqmp_qspi *xqspi, u8 nbits,
673672
u32 genfifoentry)
674673
{
675-
u32 transfer_len = 0;
674+
u32 transfer_len, tempcount, exponent;
675+
u8 imm_data;
676676

677-
if (xqspi->txbuf) {
678-
genfifoentry &= ~GQSPI_GENFIFO_RX;
679-
genfifoentry |= GQSPI_GENFIFO_DATA_XFER;
680-
genfifoentry |= GQSPI_GENFIFO_TX;
681-
transfer_len = xqspi->bytes_to_transfer;
682-
} else if (xqspi->rxbuf) {
683-
genfifoentry &= ~GQSPI_GENFIFO_TX;
684-
genfifoentry |= GQSPI_GENFIFO_DATA_XFER;
677+
genfifoentry |= GQSPI_GENFIFO_DATA_XFER;
678+
if (xqspi->rxbuf) {
685679
genfifoentry |= GQSPI_GENFIFO_RX;
686680
if (xqspi->mode == GQSPI_MODE_DMA)
687681
transfer_len = xqspi->dma_rx_bytes;
688682
else
689683
transfer_len = xqspi->bytes_to_receive;
690684
} else {
691-
/* Sending dummy circles here */
692-
genfifoentry &= ~(GQSPI_GENFIFO_TX | GQSPI_GENFIFO_RX);
693-
genfifoentry |= GQSPI_GENFIFO_DATA_XFER;
694685
transfer_len = xqspi->bytes_to_transfer;
695686
}
687+
688+
if (xqspi->txbuf)
689+
genfifoentry |= GQSPI_GENFIFO_TX;
690+
696691
genfifoentry |= zynqmp_qspi_selectspimode(xqspi, nbits);
697692
xqspi->genfifoentry = genfifoentry;
698693
dev_dbg(xqspi->dev, "genfifo %05x transfer_len %u\n",
699694
genfifoentry, transfer_len);
700695

701-
if ((transfer_len) < GQSPI_GENFIFO_IMM_DATA_MASK) {
702-
genfifoentry &= ~GQSPI_GENFIFO_IMM_DATA_MASK;
703-
genfifoentry |= transfer_len;
704-
zynqmp_gqspi_write(xqspi, GQSPI_GEN_FIFO_OFST, genfifoentry);
705-
} else {
706-
int tempcount = transfer_len;
707-
u32 exponent = 8; /* 2^8 = 256 */
708-
u8 imm_data = tempcount & 0xFF;
709-
710-
tempcount &= ~(tempcount & 0xFF);
711-
/* Immediate entry */
712-
if (tempcount != 0) {
713-
/* Exponent entries */
714-
genfifoentry |= GQSPI_GENFIFO_EXP;
715-
while (tempcount != 0) {
716-
if (tempcount & GQSPI_GENFIFO_EXP_START) {
717-
genfifoentry &=
718-
~GQSPI_GENFIFO_IMM_DATA_MASK;
719-
genfifoentry |= exponent;
720-
zynqmp_gqspi_write(xqspi,
721-
GQSPI_GEN_FIFO_OFST,
722-
genfifoentry);
723-
}
724-
tempcount = tempcount >> 1;
725-
exponent++;
726-
}
727-
}
728-
if (imm_data != 0) {
729-
genfifoentry &= ~GQSPI_GENFIFO_EXP;
730-
genfifoentry &= ~GQSPI_GENFIFO_IMM_DATA_MASK;
731-
genfifoentry |= (u8)(imm_data & 0xFF);
696+
/* Exponent entries */
697+
imm_data = transfer_len;
698+
tempcount = transfer_len >> 8;
699+
exponent = 8;
700+
genfifoentry |= GQSPI_GENFIFO_EXP;
701+
while (tempcount) {
702+
if (tempcount & 1)
732703
zynqmp_gqspi_write(xqspi, GQSPI_GEN_FIFO_OFST,
733-
genfifoentry);
734-
}
735-
}
736-
if (xqspi->mode == GQSPI_MODE_IO && xqspi->rxbuf) {
737-
/* Dummy generic FIFO entry */
738-
zynqmp_gqspi_write(xqspi, GQSPI_GEN_FIFO_OFST, 0x0);
704+
genfifoentry | exponent);
705+
tempcount >>= 1;
706+
exponent++;
739707
}
708+
709+
/* Immediate entry */
710+
genfifoentry &= ~GQSPI_GENFIFO_EXP;
711+
if (imm_data)
712+
zynqmp_gqspi_write(xqspi, GQSPI_GEN_FIFO_OFST,
713+
genfifoentry | imm_data);
714+
715+
/* Dummy generic FIFO entry */
716+
if (xqspi->mode == GQSPI_MODE_IO && xqspi->rxbuf)
717+
zynqmp_gqspi_write(xqspi, GQSPI_GEN_FIFO_OFST, 0);
740718
}
741719

742720
/**

0 commit comments

Comments
 (0)