Skip to content

Commit 40308f9

Browse files
Eddie Jamesbroonie
authored andcommitted
spi: fsi: Increase timeout and ensure status is checked
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>
1 parent 26f30e3 commit 40308f9

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/spi/spi-fsi.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
#define FSI2SPI_IRQ 0x20
2525

2626
#define SPI_FSI_BASE 0x70000
27-
#define SPI_FSI_INIT_TIMEOUT_MS 1000
28-
#define SPI_FSI_STATUS_TIMEOUT_MS 100
27+
#define SPI_FSI_TIMEOUT_MS 1000
2928
#define SPI_FSI_MAX_RX_SIZE 8
3029
#define SPI_FSI_MAX_TX_SIZE 40
3130

@@ -299,6 +298,7 @@ static void fsi_spi_sequence_init(struct fsi_spi_sequence *seq)
299298
static int fsi_spi_transfer_data(struct fsi_spi *ctx,
300299
struct spi_transfer *transfer)
301300
{
301+
int loops;
302302
int rc = 0;
303303
unsigned long end;
304304
u64 status = 0ULL;
@@ -317,9 +317,10 @@ static int fsi_spi_transfer_data(struct fsi_spi *ctx,
317317
if (rc)
318318
return rc;
319319

320-
end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS);
320+
loops = 0;
321+
end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS);
321322
do {
322-
if (time_after(jiffies, end))
323+
if (loops++ && time_after(jiffies, end))
323324
return -ETIMEDOUT;
324325

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

337338
while (transfer->len > recv) {
338-
end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS);
339+
loops = 0;
340+
end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS);
339341
do {
340-
if (time_after(jiffies, end))
342+
if (loops++ && time_after(jiffies, end))
341343
return -ETIMEDOUT;
342344

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

360362
static int fsi_spi_transfer_init(struct fsi_spi *ctx)
361363
{
364+
int loops = 0;
362365
int rc;
363366
bool reset = false;
364367
unsigned long end;
@@ -369,9 +372,9 @@ static int fsi_spi_transfer_init(struct fsi_spi *ctx)
369372
SPI_FSI_CLOCK_CFG_SCK_NO_DEL |
370373
FIELD_PREP(SPI_FSI_CLOCK_CFG_SCK_DIV, 19);
371374

372-
end = jiffies + msecs_to_jiffies(SPI_FSI_INIT_TIMEOUT_MS);
375+
end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS);
373376
do {
374-
if (time_after(jiffies, end))
377+
if (loops++ && time_after(jiffies, end))
375378
return -ETIMEDOUT;
376379

377380
rc = fsi_spi_read_reg(ctx, SPI_FSI_STATUS, &status);

0 commit comments

Comments
 (0)