[v4,3/3] fpga: microchip-spi: separate data frame write routine

Message ID 20221229104604.2496-4-i.bornyakov@metrotek.ru
State New
Headers
Series Reliability improvements for Microchip MPF FPGA manager |

Commit Message

Ivan Bornyakov Dec. 29, 2022, 10:46 a.m. UTC
  mpf_ops_write() function writes bitstream data to the FPGA by a smaller
frames. Introduce mpf_spi_frame_write() function which is for writing a
single data frame and use it in mpf_ops_write().

No functional changes intended.

Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Conor Dooley <conor.dooley@microchip.com>
---
 drivers/fpga/microchip-spi.c | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)
  

Comments

Xu Yilun Dec. 30, 2022, 7:51 a.m. UTC | #1
On 2022-12-29 at 13:46:04 +0300, Ivan Bornyakov wrote:
> mpf_ops_write() function writes bitstream data to the FPGA by a smaller
> frames. Introduce mpf_spi_frame_write() function which is for writing a
> single data frame and use it in mpf_ops_write().
> 
> No functional changes intended.
> 
> Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
> Acked-by: Conor Dooley <conor.dooley@microchip.com>

Acked-by: Xu Yilun <yilun.xu@intel.com>

> ---
>  drivers/fpga/microchip-spi.c | 36 +++++++++++++++++++++++-------------
>  1 file changed, 23 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/fpga/microchip-spi.c b/drivers/fpga/microchip-spi.c
> index 995b1964e0fe..8a541986f6f2 100644
> --- a/drivers/fpga/microchip-spi.c
> +++ b/drivers/fpga/microchip-spi.c
> @@ -280,9 +280,30 @@ static int mpf_ops_write_init(struct fpga_manager *mgr,
>  	return 0;
>  }
>  
> +static int mpf_spi_frame_write(struct mpf_priv *priv, const char *buf)
> +{
> +	struct spi_transfer xfers[2] = {
> +		{
> +			.tx_buf = &priv->tx,
> +			.len = 1,
> +		}, {
> +			.tx_buf = buf,
> +			.len = MPF_SPI_FRAME_SIZE,
> +		},
> +	};
> +	int ret;
> +
> +	ret = mpf_poll_status(priv, 0);
> +	if (ret < 0)
> +		return ret;
> +
> +	priv->tx = MPF_SPI_FRAME;
> +
> +	return spi_sync_transfer(priv->spi, xfers, ARRAY_SIZE(xfers));
> +}
> +
>  static int mpf_ops_write(struct fpga_manager *mgr, const char *buf, size_t count)
>  {
> -	struct spi_transfer xfers[2] = { 0 };
>  	struct mpf_priv *priv = mgr->priv;
>  	struct device *dev = &mgr->dev;
>  	int ret, i;
> @@ -293,19 +314,8 @@ static int mpf_ops_write(struct fpga_manager *mgr, const char *buf, size_t count
>  		return -EINVAL;
>  	}
>  
> -	xfers[0].tx_buf = &priv->tx;
> -	xfers[0].len = 1;
> -
>  	for (i = 0; i < count / MPF_SPI_FRAME_SIZE; i++) {
> -		xfers[1].tx_buf = buf + i * MPF_SPI_FRAME_SIZE;
> -		xfers[1].len = MPF_SPI_FRAME_SIZE;
> -
> -		ret = mpf_poll_status(priv, 0);
> -		if (ret >= 0) {
> -			priv->tx = MPF_SPI_FRAME;
> -			ret = spi_sync_transfer(priv->spi, xfers, ARRAY_SIZE(xfers));
> -		}
> -
> +		ret = mpf_spi_frame_write(priv, buf + i * MPF_SPI_FRAME_SIZE);
>  		if (ret) {
>  			dev_err(dev, "Failed to write bitstream frame %d/%zu\n",
>  				i, count / MPF_SPI_FRAME_SIZE);
> -- 
> 2.39.0
> 
>
  

Patch

diff --git a/drivers/fpga/microchip-spi.c b/drivers/fpga/microchip-spi.c
index 995b1964e0fe..8a541986f6f2 100644
--- a/drivers/fpga/microchip-spi.c
+++ b/drivers/fpga/microchip-spi.c
@@ -280,9 +280,30 @@  static int mpf_ops_write_init(struct fpga_manager *mgr,
 	return 0;
 }
 
+static int mpf_spi_frame_write(struct mpf_priv *priv, const char *buf)
+{
+	struct spi_transfer xfers[2] = {
+		{
+			.tx_buf = &priv->tx,
+			.len = 1,
+		}, {
+			.tx_buf = buf,
+			.len = MPF_SPI_FRAME_SIZE,
+		},
+	};
+	int ret;
+
+	ret = mpf_poll_status(priv, 0);
+	if (ret < 0)
+		return ret;
+
+	priv->tx = MPF_SPI_FRAME;
+
+	return spi_sync_transfer(priv->spi, xfers, ARRAY_SIZE(xfers));
+}
+
 static int mpf_ops_write(struct fpga_manager *mgr, const char *buf, size_t count)
 {
-	struct spi_transfer xfers[2] = { 0 };
 	struct mpf_priv *priv = mgr->priv;
 	struct device *dev = &mgr->dev;
 	int ret, i;
@@ -293,19 +314,8 @@  static int mpf_ops_write(struct fpga_manager *mgr, const char *buf, size_t count
 		return -EINVAL;
 	}
 
-	xfers[0].tx_buf = &priv->tx;
-	xfers[0].len = 1;
-
 	for (i = 0; i < count / MPF_SPI_FRAME_SIZE; i++) {
-		xfers[1].tx_buf = buf + i * MPF_SPI_FRAME_SIZE;
-		xfers[1].len = MPF_SPI_FRAME_SIZE;
-
-		ret = mpf_poll_status(priv, 0);
-		if (ret >= 0) {
-			priv->tx = MPF_SPI_FRAME;
-			ret = spi_sync_transfer(priv->spi, xfers, ARRAY_SIZE(xfers));
-		}
-
+		ret = mpf_spi_frame_write(priv, buf + i * MPF_SPI_FRAME_SIZE);
 		if (ret) {
 			dev_err(dev, "Failed to write bitstream frame %d/%zu\n",
 				i, count / MPF_SPI_FRAME_SIZE);