linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] spi: spi-mtk-nor: Unify write buffer on/off
@ 2022-11-15 12:46 Bayi Cheng
  2022-11-21  8:28 ` Bayi Cheng (程八意)
  2022-11-28 16:19 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Bayi Cheng @ 2022-11-15 12:46 UTC (permalink / raw)
  To: Mark Brown, Matthias Brugger, Ikjoon Jang
  Cc: linux-spi, linux-arm-kernel, linux-mediatek, linux-kernel,
	Project_Global_Chrome_Upstream_Group, bayi cheng

From: bayi cheng <bayi.cheng@mediatek.com>

The logical structures of mtk_nor_write_buffer_enable and
mtk_nor_write_buffer_disable are very similar, So it is necessary to
combine them into one.

Signed-off-by: bayi cheng <bayi.cheng@mediatek.com>
---
Change in v1:
  -Delete mtk_nor_write_buffer_enable.
  -Delete mtk_nor_write_buffer_disable.
  -Add mtk_nor_setup_write_buffer.
---
---
 drivers/spi/spi-mtk-nor.c | 40 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
index d167699a1a96..e8b355f5be56 100644
--- a/drivers/spi/spi-mtk-nor.c
+++ b/drivers/spi/spi-mtk-nor.c
@@ -443,36 +443,28 @@ static int mtk_nor_read_pio(struct mtk_nor *sp, const struct spi_mem_op *op)
 	return ret;
 }
 
-static int mtk_nor_write_buffer_enable(struct mtk_nor *sp)
+static int mtk_nor_setup_write_buffer(struct mtk_nor *sp, bool on)
 {
 	int ret;
 	u32 val;
 
-	if (sp->wbuf_en)
+	if (!(sp->wbuf_en ^ on))
 		return 0;
 
 	val = readl(sp->base + MTK_NOR_REG_CFG2);
-	writel(val | MTK_NOR_WR_BUF_EN, sp->base + MTK_NOR_REG_CFG2);
-	ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2, val,
-				 val & MTK_NOR_WR_BUF_EN, 0, 10000);
-	if (!ret)
-		sp->wbuf_en = true;
-	return ret;
-}
-
-static int mtk_nor_write_buffer_disable(struct mtk_nor *sp)
-{
-	int ret;
-	u32 val;
+	if (on) {
+		writel(val | MTK_NOR_WR_BUF_EN, sp->base + MTK_NOR_REG_CFG2);
+		ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2, val,
+					 val & MTK_NOR_WR_BUF_EN, 0, 10000);
+	} else {
+		writel(val & ~MTK_NOR_WR_BUF_EN, sp->base + MTK_NOR_REG_CFG2);
+		ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2, val,
+					 !(val & MTK_NOR_WR_BUF_EN), 0, 10000);
+	}
 
-	if (!sp->wbuf_en)
-		return 0;
-	val = readl(sp->base + MTK_NOR_REG_CFG2);
-	writel(val & ~MTK_NOR_WR_BUF_EN, sp->base + MTK_NOR_REG_CFG2);
-	ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2, val,
-				 !(val & MTK_NOR_WR_BUF_EN), 0, 10000);
 	if (!ret)
-		sp->wbuf_en = false;
+		sp->wbuf_en = on;
+
 	return ret;
 }
 
@@ -482,7 +474,7 @@ static int mtk_nor_pp_buffered(struct mtk_nor *sp, const struct spi_mem_op *op)
 	u32 val;
 	int ret, i;
 
-	ret = mtk_nor_write_buffer_enable(sp);
+	ret = mtk_nor_setup_write_buffer(sp, true);
 	if (ret < 0)
 		return ret;
 
@@ -501,7 +493,7 @@ static int mtk_nor_pp_unbuffered(struct mtk_nor *sp,
 	const u8 *buf = op->data.buf.out;
 	int ret;
 
-	ret = mtk_nor_write_buffer_disable(sp);
+	ret = mtk_nor_setup_write_buffer(sp, false);
 	if (ret < 0)
 		return ret;
 	writeb(buf[0], sp->base + MTK_NOR_REG_WDATA);
@@ -608,7 +600,7 @@ static int mtk_nor_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
 	}
 
 	if ((op->data.dir == SPI_MEM_DATA_IN) && mtk_nor_match_read(op)) {
-		ret = mtk_nor_write_buffer_disable(sp);
+		ret = mtk_nor_setup_write_buffer(sp, false);
 		if (ret < 0)
 			return ret;
 		mtk_nor_setup_bus(sp, op);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] spi: spi-mtk-nor: Unify write buffer on/off
  2022-11-15 12:46 [PATCH v1] spi: spi-mtk-nor: Unify write buffer on/off Bayi Cheng
@ 2022-11-21  8:28 ` Bayi Cheng (程八意)
  2022-11-28 16:19 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Bayi Cheng (程八意) @ 2022-11-21  8:28 UTC (permalink / raw)
  To: matthias.bgg, broonie, ikjn
  Cc: linux-spi, linux-arm-kernel, linux-mediatek, linux-kernel,
	Project_Global_Chrome_Upstream_Group

On Tue, 2022-11-15 at 20:46 +0800, Bayi Cheng wrote:
> From: bayi cheng <bayi.cheng@mediatek.com>
> 
> The logical structures of mtk_nor_write_buffer_enable and
> mtk_nor_write_buffer_disable are very similar, So it is necessary to
> combine them into one.
> 
> Signed-off-by: bayi cheng <bayi.cheng@mediatek.com>
> ---
> Change in v1:
>   -Delete mtk_nor_write_buffer_enable.
>   -Delete mtk_nor_write_buffer_disable.
>   -Add mtk_nor_setup_write_buffer.
> ---
> ---
>  drivers/spi/spi-mtk-nor.c | 40 ++++++++++++++++---------------------
> --
>  1 file changed, 16 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
> index d167699a1a96..e8b355f5be56 100644
> --- a/drivers/spi/spi-mtk-nor.c
> +++ b/drivers/spi/spi-mtk-nor.c
> @@ -443,36 +443,28 @@ static int mtk_nor_read_pio(struct mtk_nor *sp,
> const struct spi_mem_op *op)
>  	return ret;
>  }
>  
> -static int mtk_nor_write_buffer_enable(struct mtk_nor *sp)
> +static int mtk_nor_setup_write_buffer(struct mtk_nor *sp, bool on)
>  {
>  	int ret;
>  	u32 val;
>  
> -	if (sp->wbuf_en)
> +	if (!(sp->wbuf_en ^ on))
>  		return 0;
>  
>  	val = readl(sp->base + MTK_NOR_REG_CFG2);
> -	writel(val | MTK_NOR_WR_BUF_EN, sp->base + MTK_NOR_REG_CFG2);
> -	ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2, val,
> -				 val & MTK_NOR_WR_BUF_EN, 0, 10000);
> -	if (!ret)
> -		sp->wbuf_en = true;
> -	return ret;
> -}
> -
> -static int mtk_nor_write_buffer_disable(struct mtk_nor *sp)
> -{
> -	int ret;
> -	u32 val;
> +	if (on) {
> +		writel(val | MTK_NOR_WR_BUF_EN, sp->base +
> MTK_NOR_REG_CFG2);
> +		ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2,
> val,
> +					 val & MTK_NOR_WR_BUF_EN, 0,
> 10000);
> +	} else {
> +		writel(val & ~MTK_NOR_WR_BUF_EN, sp->base +
> MTK_NOR_REG_CFG2);
> +		ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2,
> val,
> +					 !(val & MTK_NOR_WR_BUF_EN), 0,
> 10000);
> +	}
>  
> -	if (!sp->wbuf_en)
> -		return 0;
> -	val = readl(sp->base + MTK_NOR_REG_CFG2);
> -	writel(val & ~MTK_NOR_WR_BUF_EN, sp->base + MTK_NOR_REG_CFG2);
> -	ret = readl_poll_timeout(sp->base + MTK_NOR_REG_CFG2, val,
> -				 !(val & MTK_NOR_WR_BUF_EN), 0, 10000);
>  	if (!ret)
> -		sp->wbuf_en = false;
> +		sp->wbuf_en = on;
> +
>  	return ret;
>  }
>  
> @@ -482,7 +474,7 @@ static int mtk_nor_pp_buffered(struct mtk_nor
> *sp, const struct spi_mem_op *op)
>  	u32 val;
>  	int ret, i;
>  
> -	ret = mtk_nor_write_buffer_enable(sp);
> +	ret = mtk_nor_setup_write_buffer(sp, true);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -501,7 +493,7 @@ static int mtk_nor_pp_unbuffered(struct mtk_nor
> *sp,
>  	const u8 *buf = op->data.buf.out;
>  	int ret;
>  
> -	ret = mtk_nor_write_buffer_disable(sp);
> +	ret = mtk_nor_setup_write_buffer(sp, false);
>  	if (ret < 0)
>  		return ret;
>  	writeb(buf[0], sp->base + MTK_NOR_REG_WDATA);
> @@ -608,7 +600,7 @@ static int mtk_nor_exec_op(struct spi_mem *mem,
> const struct spi_mem_op *op)
>  	}
>  
>  	if ((op->data.dir == SPI_MEM_DATA_IN) &&
> mtk_nor_match_read(op)) {
> -		ret = mtk_nor_write_buffer_disable(sp);
> +		ret = mtk_nor_setup_write_buffer(sp, false);
>  		if (ret < 0)
>  			return ret;
>  		mtk_nor_setup_bus(sp, op);

Hi Angelo, Hi David, Hi Matthias,

Just a gentle ping on this.
Could you please review this patch and give us some suggestion?

Thanks,
Bayi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] spi: spi-mtk-nor: Unify write buffer on/off
  2022-11-15 12:46 [PATCH v1] spi: spi-mtk-nor: Unify write buffer on/off Bayi Cheng
  2022-11-21  8:28 ` Bayi Cheng (程八意)
@ 2022-11-28 16:19 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2022-11-28 16:19 UTC (permalink / raw)
  To: Ikjoon Jang, Matthias Brugger, Bayi Cheng
  Cc: linux-spi, linux-arm-kernel,
	Project_Global_Chrome_Upstream_Group, linux-mediatek,
	linux-kernel

On Tue, 15 Nov 2022 20:46:55 +0800, Bayi Cheng wrote:
> From: bayi cheng <bayi.cheng@mediatek.com>
> 
> The logical structures of mtk_nor_write_buffer_enable and
> mtk_nor_write_buffer_disable are very similar, So it is necessary to
> combine them into one.
> 
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: spi-mtk-nor: Unify write buffer on/off
      commit: 63d9a4d88499569210c445a862209515207c2732

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-28 16:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 12:46 [PATCH v1] spi: spi-mtk-nor: Unify write buffer on/off Bayi Cheng
2022-11-21  8:28 ` Bayi Cheng (程八意)
2022-11-28 16:19 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).