Message ID | 20230619155349.3118420-4-miquel.raynal@bootlin.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | spi: Helper for deriving timeout values | expand |
Dne ponedeljek, 19. junij 2023 ob 17:53:49 CEST je Miquel Raynal napisal(a): > A helper was recently added to the core to factorize common code between > drivers, like the amount of time a driver should wait for a transfer to > happen. > > It is of course possible to use a default value (like eg. 1s) but it is > way stronger to adapt this amount of time to the transfer. Indeed, long > transfers (eg. 4MiB) on a slow single-spi bus might take more than the > usual second of timeout and prevent lengthy transfers. > > The core helper was heavily inspired by the logic applied in this > driver, the only difference being the minimum amount of time which was > enlarged from 0.1s to 0.5s. > > Use this helper instead of open-coding it. > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com> Best regards, Jernej > --- > drivers/spi/spi-sun6i.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c > index 23ad052528db..180094dfae19 100644 > --- a/drivers/spi/spi-sun6i.c > +++ b/drivers/spi/spi-sun6i.c > @@ -422,7 +422,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, > reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); > sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg | SUN6I_TFR_CTL_XCH); > > - tx_time = max(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U); > + tx_time = spi_controller_xfer_timeout(master, tfr); > start = jiffies; > timeout = wait_for_completion_timeout(&sspi->done, > msecs_to_jiffies(tx_time)); >
diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c index 23ad052528db..180094dfae19 100644 --- a/drivers/spi/spi-sun6i.c +++ b/drivers/spi/spi-sun6i.c @@ -422,7 +422,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg | SUN6I_TFR_CTL_XCH); - tx_time = max(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U); + tx_time = spi_controller_xfer_timeout(master, tfr); start = jiffies; timeout = wait_for_completion_timeout(&sspi->done, msecs_to_jiffies(tx_time));
A helper was recently added to the core to factorize common code between drivers, like the amount of time a driver should wait for a transfer to happen. It is of course possible to use a default value (like eg. 1s) but it is way stronger to adapt this amount of time to the transfer. Indeed, long transfers (eg. 4MiB) on a slow single-spi bus might take more than the usual second of timeout and prevent lengthy transfers. The core helper was heavily inspired by the logic applied in this driver, the only difference being the minimum amount of time which was enlarged from 0.1s to 0.5s. Use this helper instead of open-coding it. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> --- drivers/spi/spi-sun6i.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)