Skip to content

Commit cb5c2eb

Browse files
andy-shevbroonie
authored andcommitted
spi: microchip-core: Refactor FIFO read and write handlers
Make both handlers to be shorter and easier to understand. While at it, unify their style. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Prajna Rajendra Kumar <prajna.rajendrakumar@microchip.com> Link: https://patch.msgid.link/20251127190031.2998705-3-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 545d128 commit cb5c2eb

1 file changed

Lines changed: 12 additions & 19 deletions

File tree

drivers/spi/spi-microchip-core-spi.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,12 @@ static inline void mchp_corespi_read_fifo(struct mchp_corespi *spi, u32 fifo_max
9797
MCHP_CORESPI_STATUS_RXFIFO_EMPTY)
9898
;
9999

100+
/* On TX-only transfers always perform a dummy read */
100101
data = readb(spi->regs + MCHP_CORESPI_REG_RXDATA);
102+
if (spi->rx_buf)
103+
*spi->rx_buf++ = data;
101104

102105
spi->rx_len--;
103-
if (!spi->rx_buf)
104-
continue;
105-
106-
*spi->rx_buf = data;
107-
108-
spi->rx_buf++;
109106
}
110107
}
111108

@@ -127,23 +124,19 @@ static void mchp_corespi_disable_ints(struct mchp_corespi *spi)
127124

128125
static inline void mchp_corespi_write_fifo(struct mchp_corespi *spi, u32 fifo_max)
129126
{
130-
int i = 0;
131-
132-
while ((i < fifo_max) &&
133-
!(readb(spi->regs + MCHP_CORESPI_REG_STAT) &
134-
MCHP_CORESPI_STATUS_TXFIFO_FULL)) {
135-
u32 word;
136-
137-
word = spi->tx_buf ? *spi->tx_buf : 0xaa;
138-
writeb(word, spi->regs + MCHP_CORESPI_REG_TXDATA);
127+
for (int i = 0; i < fifo_max; i++) {
128+
if (readb(spi->regs + MCHP_CORESPI_REG_STAT) &
129+
MCHP_CORESPI_STATUS_TXFIFO_FULL)
130+
break;
139131

132+
/* On RX-only transfers always perform a dummy write */
140133
if (spi->tx_buf)
141-
spi->tx_buf++;
134+
writeb(*spi->tx_buf++, spi->regs + MCHP_CORESPI_REG_TXDATA);
135+
else
136+
writeb(0xaa, spi->regs + MCHP_CORESPI_REG_TXDATA);
142137

143-
i++;
138+
spi->tx_len--;
144139
}
145-
146-
spi->tx_len -= i;
147140
}
148141

149142
static void mchp_corespi_set_cs(struct spi_device *spi, bool disable)

0 commit comments

Comments
 (0)