131-spi-mtk_spim-prevent-global-pll-clock-override.patch 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. From 41f225dae30ea6ddcff10f120a9e732f994d3a07 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Nicol=C3=B2=20Veronese?= <[email protected]>
  3. Date: Tue, 3 Oct 2023 23:46:52 +0200
  4. Subject: [PATCH] spi: mtk_spim: prevent global pll clock override
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. With commit 793e6230118032a099ec42a1ea67f434721edcc0
  9. a new system to calculate the SPI clocks has been added.
  10. Unfortunately, the do_div macro overrides the global
  11. priv->pll_clk_rate field. This will cause to have a reduced
  12. clock rate on each subsequent SPI call.
  13. Signed-off-by: Valerio 'ftp21' Mancini <[email protected]>
  14. Signed-off-by: Nicolò Veronese <[email protected]>
  15. ---
  16. drivers/spi/mtk_spim.c | 7 ++++---
  17. 1 file changed, 4 insertions(+), 3 deletions(-)
  18. --- a/drivers/spi/mtk_spim.c
  19. +++ b/drivers/spi/mtk_spim.c
  20. @@ -409,7 +409,7 @@ static int mtk_spim_transfer_wait(struct
  21. {
  22. struct udevice *bus = dev_get_parent(slave->dev);
  23. struct mtk_spim_priv *priv = dev_get_priv(bus);
  24. - u32 sck_l, sck_h, clk_count, reg;
  25. + u32 pll_clk, sck_l, sck_h, clk_count, reg;
  26. ulong us = 1;
  27. int ret = 0;
  28. @@ -418,11 +418,12 @@ static int mtk_spim_transfer_wait(struct
  29. else
  30. clk_count = op->data.nbytes;
  31. + pll_clk = priv->pll_clk_rate;
  32. sck_l = readl(priv->base + SPI_CFG2_REG) >> SPI_CFG2_SCK_LOW_OFFSET;
  33. sck_h = readl(priv->base + SPI_CFG2_REG) & SPI_CFG2_SCK_HIGH_MASK;
  34. - do_div(priv->pll_clk_rate, sck_l + sck_h + 2);
  35. + do_div(pll_clk, sck_l + sck_h + 2);
  36. - us = CLK_TO_US(priv->pll_clk_rate, clk_count * 8);
  37. + us = CLK_TO_US(pll_clk, clk_count * 8);
  38. us += 1000 * 1000; /* 1s tolerance */
  39. if (us > UINT_MAX)