forked from mirrors/linux
		
	spi: Deal with slaves that return from transfer_one() unfinished
Some drivers, such as spi-pxa2xx return from the transfer_one callback immediately, idicating that the transfer will be finished asynchronously. Normally, spi_transfer_one_message() synchronously waits for the transfer to finish with wait_for_completion_timeout(). For slaves, we don't want the transaction to time out as it can complete in a long time in future. Use wait_for_completion_interruptible() instead. Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> Acked-by: Pavel Machek <pavel@ucw.cz> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
		
							parent
							
								
									aa66478aa5
								
							
						
					
					
						commit
						810923f3bf
					
				
					 1 changed files with 39 additions and 23 deletions
				
			
		| 
						 | 
					@ -1037,6 +1037,42 @@ static int spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
 | 
				
			||||||
	return __spi_map_msg(ctlr, msg);
 | 
						return __spi_map_msg(ctlr, msg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int spi_transfer_wait(struct spi_controller *ctlr,
 | 
				
			||||||
 | 
								     struct spi_message *msg,
 | 
				
			||||||
 | 
								     struct spi_transfer *xfer)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct spi_statistics *statm = &ctlr->statistics;
 | 
				
			||||||
 | 
						struct spi_statistics *stats = &msg->spi->statistics;
 | 
				
			||||||
 | 
						unsigned long long ms = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (spi_controller_is_slave(ctlr)) {
 | 
				
			||||||
 | 
							if (wait_for_completion_interruptible(&ctlr->xfer_completion)) {
 | 
				
			||||||
 | 
								dev_dbg(&msg->spi->dev, "SPI transfer interrupted\n");
 | 
				
			||||||
 | 
								return -EINTR;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							ms = 8LL * 1000LL * xfer->len;
 | 
				
			||||||
 | 
							do_div(ms, xfer->speed_hz);
 | 
				
			||||||
 | 
							ms += ms + 200; /* some tolerance */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (ms > UINT_MAX)
 | 
				
			||||||
 | 
								ms = UINT_MAX;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ms = wait_for_completion_timeout(&ctlr->xfer_completion,
 | 
				
			||||||
 | 
											 msecs_to_jiffies(ms));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (ms == 0) {
 | 
				
			||||||
 | 
								SPI_STATISTICS_INCREMENT_FIELD(statm, timedout);
 | 
				
			||||||
 | 
								SPI_STATISTICS_INCREMENT_FIELD(stats, timedout);
 | 
				
			||||||
 | 
								dev_err(&msg->spi->dev,
 | 
				
			||||||
 | 
									"SPI transfer timed out\n");
 | 
				
			||||||
 | 
								return -ETIMEDOUT;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * spi_transfer_one_message - Default implementation of transfer_one_message()
 | 
					 * spi_transfer_one_message - Default implementation of transfer_one_message()
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -1050,7 +1086,6 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
 | 
				
			||||||
	struct spi_transfer *xfer;
 | 
						struct spi_transfer *xfer;
 | 
				
			||||||
	bool keep_cs = false;
 | 
						bool keep_cs = false;
 | 
				
			||||||
	int ret = 0;
 | 
						int ret = 0;
 | 
				
			||||||
	unsigned long long ms = 1;
 | 
					 | 
				
			||||||
	struct spi_statistics *statm = &ctlr->statistics;
 | 
						struct spi_statistics *statm = &ctlr->statistics;
 | 
				
			||||||
	struct spi_statistics *stats = &msg->spi->statistics;
 | 
						struct spi_statistics *stats = &msg->spi->statistics;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1079,28 +1114,9 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
 | 
				
			||||||
				goto out;
 | 
									goto out;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (ret > 0) {
 | 
								ret = spi_transfer_wait(ctlr, msg, xfer);
 | 
				
			||||||
				ret = 0;
 | 
								if (ret < 0)
 | 
				
			||||||
				ms = 8LL * 1000LL * xfer->len;
 | 
									msg->status = ret;
 | 
				
			||||||
				do_div(ms, xfer->speed_hz);
 | 
					 | 
				
			||||||
				ms += ms + 200; /* some tolerance */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if (ms > UINT_MAX)
 | 
					 | 
				
			||||||
					ms = UINT_MAX;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				ms = wait_for_completion_timeout(&ctlr->xfer_completion,
 | 
					 | 
				
			||||||
								 msecs_to_jiffies(ms));
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (ms == 0) {
 | 
					 | 
				
			||||||
				SPI_STATISTICS_INCREMENT_FIELD(statm,
 | 
					 | 
				
			||||||
							       timedout);
 | 
					 | 
				
			||||||
				SPI_STATISTICS_INCREMENT_FIELD(stats,
 | 
					 | 
				
			||||||
							       timedout);
 | 
					 | 
				
			||||||
				dev_err(&msg->spi->dev,
 | 
					 | 
				
			||||||
					"SPI transfer timed out\n");
 | 
					 | 
				
			||||||
				msg->status = -ETIMEDOUT;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if (xfer->len)
 | 
								if (xfer->len)
 | 
				
			||||||
				dev_err(&msg->spi->dev,
 | 
									dev_err(&msg->spi->dev,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue