Skip to content

Commit

Permalink
pl022_spi: simplify receive of remaining data
Browse files Browse the repository at this point in the history
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] OP-TEE#1461 (comment)

Signed-off-by: Victor Chong <victor.chong@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
  • Loading branch information
Victor Chong authored and andyzsh68 committed Jul 5, 2019
1 parent 677ec7f commit 747a6c5
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions core/drivers/pl022_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 747a6c5

Please sign in to comment.