From e4b2e43c44934b500dbb9dbf7207d9bcd7a2ab77 Mon Sep 17 00:00:00 2001 From: Victor Chong Date: Fri, 12 Apr 2019 15:58:07 +0100 Subject: pl022_spi: simplify receive of remaining data If the expected number of packets are not received during the transmit+receive cycle, just receive the remaining data after the cycle if the Receive FIFO (SSPSR_RNE) is not empty, without depending on the busy (SSPSR_BSY) flag, else we might miss reading some data as indicated in [1]. LINK: [1] https://github.com/OP-TEE/optee_os/issues/1461#issuecomment-306156463 Signed-off-by: Victor Chong Acked-by: Jens Wiklander Acked-by: Etienne Carriere --- core/drivers/pl022_spi.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'core') diff --git a/core/drivers/pl022_spi.c b/core/drivers/pl022_spi.c index c7fc992a..870cd3e6 100644 --- a/core/drivers/pl022_spi.c +++ b/core/drivers/pl022_spi.c @@ -166,11 +166,10 @@ static enum spi_result pl022_txrx8(struct spi_chip *chip, uint8_t *wdat, /* Capture remaining rdat not read above */ if (rdat) { while ((j < num_pkts) && - (io_read8(pd->base + SSPSR) & SSPSR_BSY)) - if (io_read8(pd->base + SSPSR) & SSPSR_RNE) { - /* rx 1 packet */ - rdat[j++] = io_read8(pd->base + SSPDR); - } + (io_read8(pd->base + SSPSR) & SSPSR_RNE)) { + /* rx 1 packet */ + rdat[j++] = io_read8(pd->base + SSPDR); + } if (j < num_pkts) { EMSG("Packets requested %zu, received %zu", @@ -212,11 +211,10 @@ static enum spi_result pl022_txrx16(struct spi_chip *chip, uint16_t *wdat, /* Capture remaining rdat not read above */ if (rdat) { while ((j < num_pkts) && - (io_read8(pd->base + SSPSR) & SSPSR_BSY)) - if (io_read8(pd->base + SSPSR) & SSPSR_RNE) { - /* rx 1 packet */ - rdat[j++] = io_read8(pd->base + SSPDR); - } + (io_read8(pd->base + SSPSR) & SSPSR_RNE)) { + /* rx 1 packet */ + rdat[j++] = io_read8(pd->base + SSPDR); + } if (j < num_pkts) { EMSG("Packets requested %zu, received %zu", -- cgit v1.2.3