public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2] spi: spi-mtk-nor: Optimize timeout for dma read
@ 2022-11-14  8:13 Bayi Cheng
  2022-11-14 11:32 ` AngeloGioacchino Del Regno
  2022-11-15  9:57 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Bayi Cheng @ 2022-11-14  8:13 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 timeout value of the current dma read is unreasonable. For example,
If the spi flash clock is 26Mhz, It will takes about 1.3ms to read a
4KB data in spi mode. But the actual measurement exceeds 50s when a
dma read timeout is encountered.

In order to be more accurately, It is necessary to use usecs_to_jiffies,
After modification, the measured timeout value is about 130ms.

Signed-off-by: bayi cheng <bayi.cheng@mediatek.com>
---
Change in v2:
  -Change the type of "timeout" from ulong to u32.
  -Replace max_t with max.
  -Replace msecs_to_jiffies with usecs_to_jiffies.
---
---
 drivers/spi/spi-mtk-nor.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
index d167699a1a96..58eca18b28b0 100644
--- a/drivers/spi/spi-mtk-nor.c
+++ b/drivers/spi/spi-mtk-nor.c
@@ -354,7 +354,7 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length,
 			    dma_addr_t dma_addr)
 {
 	int ret = 0;
-	ulong delay;
+	u32 delay, timeout;
 	u32 reg;
 
 	writel(from, sp->base + MTK_NOR_REG_DMA_FADR);
@@ -376,15 +376,16 @@ static int mtk_nor_dma_exec(struct mtk_nor *sp, u32 from, unsigned int length,
 	mtk_nor_rmw(sp, MTK_NOR_REG_DMA_CTL, MTK_NOR_DMA_START, 0);
 
 	delay = CLK_TO_US(sp, (length + 5) * BITS_PER_BYTE);
+	timeout = (delay + 1) * 100;
 
 	if (sp->has_irq) {
 		if (!wait_for_completion_timeout(&sp->op_done,
-						 (delay + 1) * 100))
+		    usecs_to_jiffies(max(timeout, 10000U))))
 			ret = -ETIMEDOUT;
 	} else {
 		ret = readl_poll_timeout(sp->base + MTK_NOR_REG_DMA_CTL, reg,
 					 !(reg & MTK_NOR_DMA_START), delay / 3,
-					 (delay + 1) * 100);
+					 timeout);
 	}
 
 	if (ret < 0)
-- 
2.25.1



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

* Re: [PATCH v2] spi: spi-mtk-nor: Optimize timeout for dma read
  2022-11-14  8:13 [PATCH v2] spi: spi-mtk-nor: Optimize timeout for dma read Bayi Cheng
@ 2022-11-14 11:32 ` AngeloGioacchino Del Regno
  2022-11-15  9:57 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-11-14 11:32 UTC (permalink / raw)
  To: Bayi Cheng, Mark Brown, Matthias Brugger, Ikjoon Jang
  Cc: linux-spi, linux-arm-kernel, linux-mediatek, linux-kernel,
	Project_Global_Chrome_Upstream_Group

Il 14/11/22 09:13, Bayi Cheng ha scritto:
> From: bayi cheng <bayi.cheng@mediatek.com>
> 
> The timeout value of the current dma read is unreasonable. For example,
> If the spi flash clock is 26Mhz, It will takes about 1.3ms to read a
> 4KB data in spi mode. But the actual measurement exceeds 50s when a
> dma read timeout is encountered.
> 
> In order to be more accurately, It is necessary to use usecs_to_jiffies,
> After modification, the measured timeout value is about 130ms.
> 
> Signed-off-by: bayi cheng <bayi.cheng@mediatek.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>




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

* Re: [PATCH v2] spi: spi-mtk-nor: Optimize timeout for dma read
  2022-11-14  8:13 [PATCH v2] spi: spi-mtk-nor: Optimize timeout for dma read Bayi Cheng
  2022-11-14 11:32 ` AngeloGioacchino Del Regno
@ 2022-11-15  9:57 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2022-11-15  9:57 UTC (permalink / raw)
  To: Ikjoon Jang, Bayi Cheng, Matthias Brugger
  Cc: Project_Global_Chrome_Upstream_Group, linux-mediatek,
	linux-kernel, linux-arm-kernel, linux-spi

On Mon, 14 Nov 2022 16:13:27 +0800, Bayi Cheng wrote:
> From: bayi cheng <bayi.cheng@mediatek.com>
> 
> The timeout value of the current dma read is unreasonable. For example,
> If the spi flash clock is 26Mhz, It will takes about 1.3ms to read a
> 4KB data in spi mode. But the actual measurement exceeds 50s when a
> dma read timeout is encountered.
> 
> [...]

Applied to

   broonie/spi.git for-next

Thanks!

[1/1] spi: spi-mtk-nor: Optimize timeout for dma read
      commit: d52a826b40604387d3e24b54e12e404867902fbb

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-15 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-14  8:13 [PATCH v2] spi: spi-mtk-nor: Optimize timeout for dma read Bayi Cheng
2022-11-14 11:32 ` AngeloGioacchino Del Regno
2022-11-15  9:57 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox