Skip to content

Commit

Permalink
spi: fsi: Increase timeout and ensure status is checked
Browse files Browse the repository at this point in the history
Only timeout after at least one iteration of checking the
status registers. In addition, increase the transfer timeout
to 1 second.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
Link: https://lore.kernel.org/r/20220623140547.71762-1-eajames@linux.ibm.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Eddie James authored and Mark Brown committed Jun 23, 2022
1 parent 26f30e3 commit 40308f9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions drivers/spi/spi-fsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#define FSI2SPI_IRQ 0x20

#define SPI_FSI_BASE 0x70000
#define SPI_FSI_INIT_TIMEOUT_MS 1000
#define SPI_FSI_STATUS_TIMEOUT_MS 100
#define SPI_FSI_TIMEOUT_MS 1000
#define SPI_FSI_MAX_RX_SIZE 8
#define SPI_FSI_MAX_TX_SIZE 40

Expand Down Expand Up @@ -299,6 +298,7 @@ static void fsi_spi_sequence_init(struct fsi_spi_sequence *seq)
static int fsi_spi_transfer_data(struct fsi_spi *ctx,
struct spi_transfer *transfer)
{
int loops;
int rc = 0;
unsigned long end;
u64 status = 0ULL;
Expand All @@ -317,9 +317,10 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
if (rc)
return rc;

end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS);
loops = 0;
end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS);
do {
if (time_after(jiffies, end))
if (loops++ && time_after(jiffies, end))
return -ETIMEDOUT;

rc = fsi_spi_status(ctx, &status, "TX");
Expand All @@ -335,9 +336,10 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
u8 *rx = transfer->rx_buf;

while (transfer->len > recv) {
end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS);
loops = 0;
end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS);
do {
if (time_after(jiffies, end))
if (loops++ && time_after(jiffies, end))
return -ETIMEDOUT;

rc = fsi_spi_status(ctx, &status, "RX");
Expand All @@ -359,6 +361,7 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,

static int fsi_spi_transfer_init(struct fsi_spi *ctx)
{
int loops = 0;
int rc;
bool reset = false;
unsigned long end;
Expand All @@ -369,9 +372,9 @@ static int fsi_spi_transfer_init(struct fsi_spi *ctx)
SPI_FSI_CLOCK_CFG_SCK_NO_DEL |
FIELD_PREP(SPI_FSI_CLOCK_CFG_SCK_DIV, 19);

end = jiffies + msecs_to_jiffies(SPI_FSI_INIT_TIMEOUT_MS);
end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS);
do {
if (time_after(jiffies, end))
if (loops++ && time_after(jiffies, end))
return -ETIMEDOUT;

rc = fsi_spi_read_reg(ctx, SPI_FSI_STATUS, &status);
Expand Down

0 comments on commit 40308f9

Please sign in to comment.