Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Eddie James and committed by
Mark Brown
40308f96 26f30e3e

+11 -8
+11 -8
drivers/spi/spi-fsi.c
··· 24 24 #define FSI2SPI_IRQ 0x20 25 25 26 26 #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 29 28 #define SPI_FSI_MAX_RX_SIZE 8 30 29 #define SPI_FSI_MAX_TX_SIZE 40 31 30 ··· 298 299 static int fsi_spi_transfer_data(struct fsi_spi *ctx, 299 300 struct spi_transfer *transfer) 300 301 { 302 + int loops; 301 303 int rc = 0; 302 304 unsigned long end; 303 305 u64 status = 0ULL; ··· 317 317 if (rc) 318 318 return rc; 319 319 320 - end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS); 320 + loops = 0; 321 + end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS); 321 322 do { 322 - if (time_after(jiffies, end)) 323 + if (loops++ && time_after(jiffies, end)) 323 324 return -ETIMEDOUT; 324 325 325 326 rc = fsi_spi_status(ctx, &status, "TX"); ··· 336 335 u8 *rx = transfer->rx_buf; 337 336 338 337 while (transfer->len > recv) { 339 - end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS); 338 + loops = 0; 339 + end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS); 340 340 do { 341 - if (time_after(jiffies, end)) 341 + if (loops++ && time_after(jiffies, end)) 342 342 return -ETIMEDOUT; 343 343 344 344 rc = fsi_spi_status(ctx, &status, "RX"); ··· 361 359 362 360 static int fsi_spi_transfer_init(struct fsi_spi *ctx) 363 361 { 362 + int loops = 0; 364 363 int rc; 365 364 bool reset = false; 366 365 unsigned long end; ··· 372 369 SPI_FSI_CLOCK_CFG_SCK_NO_DEL | 373 370 FIELD_PREP(SPI_FSI_CLOCK_CFG_SCK_DIV, 19); 374 371 375 - end = jiffies + msecs_to_jiffies(SPI_FSI_INIT_TIMEOUT_MS); 372 + end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS); 376 373 do { 377 - if (time_after(jiffies, end)) 374 + if (loops++ && time_after(jiffies, end)) 378 375 return -ETIMEDOUT; 379 376 380 377 rc = fsi_spi_read_reg(ctx, SPI_FSI_STATUS, &status);