diff mbox series

spi: rspi: Fix handling of QSPI code when transmit and receive

Message ID 1554443953-30588-1-git-send-email-na-hoan@jinso.co.jp (mailing list archive)
State Superseded
Headers show
Series spi: rspi: Fix handling of QSPI code when transmit and receive | expand

Commit Message

グェン・アン・ホァン April 5, 2019, 5:59 a.m. UTC
From: Hoan Nguyen An <na-hoan@jinso.co.jp>

Process handling QSPI when transmit/receive at qspi_trigger_transfer_out_in() as follows:
Setting the trigger, is the number of bytes in the FIFO buffer to determine
when there is an interrupt. Then check if the value of triggering number is
32bits (4 bytes) or 1bytes, there will be corresponding processing
(if (n == QSPI_BUFFER_SIZE statement))
Handling (if (n == QSPI_BUFFER_SIZE) esle) this is unnecessary, we only need to
calculate triggering number to reduce the number of interrupts that occur
if the data is larger than 32 bits (4bytes), while the transfer to handle
that call to rspi_pio_transfer() is not necessary. The code will become
confusing and difficult to read.
The same with handling in qspi_transfer_out()/qspi_transfer_in().

Signed-off-by: Hoan Nguyen An <na-hoan@jinso.co.jp>
---
 drivers/spi/spi-rspi.c | 71 ++++++++++++++++++++------------------------------
 1 file changed, 28 insertions(+), 43 deletions(-)

Comments

グェン・アン・ホァン April 9, 2019, 9:21 a.m. UTC | #1
Dear every one,

On 2019/04/05 14:59, Nguyen An Hoan wrote:
> From: Hoan Nguyen An <na-hoan@jinso.co.jp>
>
> Process handling QSPI when transmit/receive at qspi_trigger_transfer_out_in() as follows:
> Setting the trigger, is the number of bytes in the FIFO buffer to determine
> when there is an interrupt. Then check if the value of triggering number is
> 32bits (4 bytes) or 1bytes, there will be corresponding processing
> (if (n == QSPI_BUFFER_SIZE statement))
> Handling (if (n == QSPI_BUFFER_SIZE) esle) this is unnecessary, we only need to
> calculate triggering number to reduce the number of interrupts that occur
> if the data is larger than 32 bits (4bytes), while the transfer to handle
> that call to rspi_pio_transfer() is not necessary. The code will become
> confusing and difficult to read.
> The same with handling in qspi_transfer_out()/qspi_transfer_in().
There is a bit of confusion here (in a hurry) for the explanation of 
this patch.
QSPI has a buffer of 32 bytes, so a maximum of 32 bytes will be 
transmitted/received.

And so will be explained again as follows:

Process handling QSPI when transmit/receive at 
qspi_trigger_transfer_out_in() as follows:
Setting the trigger, is the number of bytes in the FIFO buffer to determine
when there is an interrupt. Then check if the value of triggering number is
32-bytes or 1-byte, there will be corresponding processing
(if (n == QSPI_BUFFER_SIZE statement))
Handling (if (n == QSPI_BUFFER_SIZE) esle) this is unnecessary, we only 
need to
calculate triggering number to reduce the number of interrupts that occur
if the data is larger than 32-bytes, while the transfer to handle
that call to rspi_pio_transfer() is not necessary. The code will become
confusing and difficult to read.
The same with handling in qspi_transfer_out()/qspi_transfer_in().

Thank you!

Hoan.

> Signed-off-by: Hoan Nguyen An <na-hoan@jinso.co.jp>
> ---
>   drivers/spi/spi-rspi.c | 71 ++++++++++++++++++++------------------------------
>   1 file changed, 28 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
> index 3be8fbe..15f5723 100644
> --- a/drivers/spi/spi-rspi.c
> +++ b/drivers/spi/spi-rspi.c
> @@ -739,27 +739,22 @@ static int qspi_trigger_transfer_out_in(struct rspi_data *rspi, const u8 *tx,
>   	while (len > 0) {
>   		n = qspi_set_send_trigger(rspi, len);
>   		qspi_set_receive_trigger(rspi, len);
> -		if (n == QSPI_BUFFER_SIZE) {
> -			ret = rspi_wait_for_tx_empty(rspi);
> -			if (ret < 0) {
> -				dev_err(&rspi->ctlr->dev, "transmit timeout\n");
> -				return ret;
> -			}
> -			for (i = 0; i < n; i++)
> -				rspi_write_data(rspi, *tx++);
> +		ret = rspi_wait_for_tx_empty(rspi);
> +		if (ret < 0) {
> +			dev_err(&rspi->ctlr->dev, "transmit timeout\n");
> +			return ret;
> +		}
> +		for (i = 0; i < n; i++)
> +			rspi_write_data(rspi, *tx++);
>   
> -			ret = rspi_wait_for_rx_full(rspi);
> -			if (ret < 0) {
> -				dev_err(&rspi->ctlr->dev, "receive timeout\n");
> -				return ret;
> -			}
> -			for (i = 0; i < n; i++)
> -				*rx++ = rspi_read_data(rspi);
> -		} else {
> -			ret = rspi_pio_transfer(rspi, tx, rx, n);
> -			if (ret < 0)
> -				return ret;
> +		ret = rspi_wait_for_rx_full(rspi);
> +		if (ret < 0) {
> +			dev_err(&rspi->ctlr->dev, "receive timeout\n");
> +			return ret;
>   		}
> +		for (i = 0; i < n; i++)
> +			*rx++ = rspi_read_data(rspi);
> +
>   		len -= n;
>   	}
>   
> @@ -796,19 +791,14 @@ static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer)
>   
>   	while (n > 0) {
>   		len = qspi_set_send_trigger(rspi, n);
> -		if (len == QSPI_BUFFER_SIZE) {
> -			ret = rspi_wait_for_tx_empty(rspi);
> -			if (ret < 0) {
> -				dev_err(&rspi->ctlr->dev, "transmit timeout\n");
> -				return ret;
> -			}
> -			for (i = 0; i < len; i++)
> -				rspi_write_data(rspi, *tx++);
> -		} else {
> -			ret = rspi_pio_transfer(rspi, tx, NULL, len);
> -			if (ret < 0)
> -				return ret;
> +		ret = rspi_wait_for_tx_empty(rspi);
> +		if (ret < 0) {
> +			dev_err(&rspi->ctlr->dev, "transmit timeout\n");
> +			return ret;
>   		}
> +		for (i = 0; i < len; i++)
> +			rspi_write_data(rspi, *tx++);
> +
>   		n -= len;
>   	}
>   
> @@ -833,19 +823,14 @@ static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer)
>   
>   	while (n > 0) {
>   		len = qspi_set_receive_trigger(rspi, n);
> -		if (len == QSPI_BUFFER_SIZE) {
> -			ret = rspi_wait_for_rx_full(rspi);
> -			if (ret < 0) {
> -				dev_err(&rspi->ctlr->dev, "receive timeout\n");
> -				return ret;
> -			}
> -			for (i = 0; i < len; i++)
> -				*rx++ = rspi_read_data(rspi);
> -		} else {
> -			ret = rspi_pio_transfer(rspi, NULL, rx, len);
> -			if (ret < 0)
> -				return ret;
> +		ret = rspi_wait_for_rx_full(rspi);
> +		if (ret < 0) {
> +			dev_err(&rspi->ctlr->dev, "receive timeout\n");
> +			return ret;
>   		}
> +		for (i = 0; i < len; i++)
> +			*rx++ = rspi_read_data(rspi);
> +
>   		n -= len;
>   	}
>
diff mbox series

Patch

diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
index 3be8fbe..15f5723 100644
--- a/drivers/spi/spi-rspi.c
+++ b/drivers/spi/spi-rspi.c
@@ -739,27 +739,22 @@  static int qspi_trigger_transfer_out_in(struct rspi_data *rspi, const u8 *tx,
 	while (len > 0) {
 		n = qspi_set_send_trigger(rspi, len);
 		qspi_set_receive_trigger(rspi, len);
-		if (n == QSPI_BUFFER_SIZE) {
-			ret = rspi_wait_for_tx_empty(rspi);
-			if (ret < 0) {
-				dev_err(&rspi->ctlr->dev, "transmit timeout\n");
-				return ret;
-			}
-			for (i = 0; i < n; i++)
-				rspi_write_data(rspi, *tx++);
+		ret = rspi_wait_for_tx_empty(rspi);
+		if (ret < 0) {
+			dev_err(&rspi->ctlr->dev, "transmit timeout\n");
+			return ret;
+		}
+		for (i = 0; i < n; i++)
+			rspi_write_data(rspi, *tx++);
 
-			ret = rspi_wait_for_rx_full(rspi);
-			if (ret < 0) {
-				dev_err(&rspi->ctlr->dev, "receive timeout\n");
-				return ret;
-			}
-			for (i = 0; i < n; i++)
-				*rx++ = rspi_read_data(rspi);
-		} else {
-			ret = rspi_pio_transfer(rspi, tx, rx, n);
-			if (ret < 0)
-				return ret;
+		ret = rspi_wait_for_rx_full(rspi);
+		if (ret < 0) {
+			dev_err(&rspi->ctlr->dev, "receive timeout\n");
+			return ret;
 		}
+		for (i = 0; i < n; i++)
+			*rx++ = rspi_read_data(rspi);
+
 		len -= n;
 	}
 
@@ -796,19 +791,14 @@  static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer)
 
 	while (n > 0) {
 		len = qspi_set_send_trigger(rspi, n);
-		if (len == QSPI_BUFFER_SIZE) {
-			ret = rspi_wait_for_tx_empty(rspi);
-			if (ret < 0) {
-				dev_err(&rspi->ctlr->dev, "transmit timeout\n");
-				return ret;
-			}
-			for (i = 0; i < len; i++)
-				rspi_write_data(rspi, *tx++);
-		} else {
-			ret = rspi_pio_transfer(rspi, tx, NULL, len);
-			if (ret < 0)
-				return ret;
+		ret = rspi_wait_for_tx_empty(rspi);
+		if (ret < 0) {
+			dev_err(&rspi->ctlr->dev, "transmit timeout\n");
+			return ret;
 		}
+		for (i = 0; i < len; i++)
+			rspi_write_data(rspi, *tx++);
+
 		n -= len;
 	}
 
@@ -833,19 +823,14 @@  static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer)
 
 	while (n > 0) {
 		len = qspi_set_receive_trigger(rspi, n);
-		if (len == QSPI_BUFFER_SIZE) {
-			ret = rspi_wait_for_rx_full(rspi);
-			if (ret < 0) {
-				dev_err(&rspi->ctlr->dev, "receive timeout\n");
-				return ret;
-			}
-			for (i = 0; i < len; i++)
-				*rx++ = rspi_read_data(rspi);
-		} else {
-			ret = rspi_pio_transfer(rspi, NULL, rx, len);
-			if (ret < 0)
-				return ret;
+		ret = rspi_wait_for_rx_full(rspi);
+		if (ret < 0) {
+			dev_err(&rspi->ctlr->dev, "receive timeout\n");
+			return ret;
 		}
+		for (i = 0; i < len; i++)
+			*rx++ = rspi_read_data(rspi);
+
 		n -= len;
 	}