[PATCH] spi: meson-spifc: round the clock divider up
Igor Velkov via B4 Relay
devnull+iav.iav.lv at kernel.org
Thu Nov 26 18:55:38 PST 2026
From: Igor Velkov <iav at iav.lv>
meson_spifc_setup_speed() computes the divider as parent / speed - 1,
which rounds the divisor down and makes SCLK faster than requested.
On ODROID-N2+ (clk81 222.2 MHz) a 104 MHz spi-max-frequency gives
n = 1 and SCLK = 111.1 MHz.
Round the divisor up so SCLK does not exceed the requested rate, and
round min_speed_hz and max_speed_hz up to match: with an odd parent
rate, rate >> 1 would need n = 2 instead of 1, and rate >> 6 would
need n = 64, which does not fit the 6-bit divider field.
Fixes: c3e4bc5434d2 ("spi: meson: Add support for Amlogic Meson SPIFC")
Signed-off-by: Igor Velkov <iav at iav.lv>
---
Tested on ODROID-N2+ with the patch on 7.3.6: for 104 MHz REG_CLOCK
goes from 0x1001 to 0x2002 (SCLK 111 -> 74 MHz). The board's
MX25U6435F read with READ (03h) misread 36 of 50 4 KiB blocks before,
0 of 200 after.
---
drivers/spi/spi-meson-spifc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi-meson-spifc.c b/drivers/spi/spi-meson-spifc.c
index 1580797f4a84..865440793a8b 100644
--- a/drivers/spi/spi-meson-spifc.c
+++ b/drivers/spi/spi-meson-spifc.c
@@ -168,7 +168,7 @@ static void meson_spifc_setup_speed(struct meson_spifc *spifc, u32 speed)
int n;
parent = clk_get_rate(spifc->clk);
- n = max_t(int, parent / speed - 1, 1);
+ n = max_t(int, DIV_ROUND_UP(parent, speed) - 1, 1);
dev_dbg(spifc->dev, "parent %lu, speed %u, n %d\n", parent,
speed, n);
@@ -320,8 +320,8 @@ static int meson_spifc_probe(struct platform_device *pdev)
host->bits_per_word_mask = SPI_BPW_MASK(8);
host->auto_runtime_pm = true;
host->transfer_one = meson_spifc_transfer_one;
- host->min_speed_hz = rate >> 6;
- host->max_speed_hz = rate >> 1;
+ host->min_speed_hz = DIV_ROUND_UP(rate, 64);
+ host->max_speed_hz = DIV_ROUND_UP(rate, 2);
meson_spifc_hw_init(spifc);
---
base-commit: 63083539d2bf955ccf84042d4b044d1133752bed
change-id: 20261127-b4-meson-spifc-div-round-up-adb97c1960ae
Best regards,
--
Igor Velkov <iav at iav.lv>
More information about the linux-arm-kernel
mailing list