From c08629e3b1e89c10eac782aa1bf4e16acbd23bc1 Mon Sep 17 00:00:00 2001 From: tao89959 <1036524114@qq.com> Date: Mon, 2 Feb 2026 10:26:11 +0800 Subject: [PATCH] loongson: drivers: spi: fix spi bus freq error bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changelog: 修复loongson spi的总线频率错误的问题 Signed-off-by: maoxiaochuan --- drivers/spi/spi-loongson-core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-loongson-core.c b/drivers/spi/spi-loongson-core.c index f34eb10da..3de7e9016 100644 --- a/drivers/spi/spi-loongson-core.c +++ b/drivers/spi/spi-loongson-core.c @@ -42,12 +42,16 @@ static void loongson_spi_set_clk(struct loongson_spi *loongson_spi, unsigned int { unsigned char val; unsigned int div, div_tmp; - static const char rdiv[12] = {0, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10, 11}; + // 第一个元素是无效的,肯定不会进来的 + static const char spre[13] = {0, 0, 0, 1, 0, 0, 1, 1, 1, 2, 2, 2, 2}; + static const char spr[13] = {0, 0, 1, 0, 2, 3, 1, 2, 3, 0, 1, 2, 3}; div = clamp_val(DIV_ROUND_UP_ULL(loongson_spi->clk_rate, hz), 2, 4096); - div_tmp = rdiv[fls(div - 1)]; - loongson_spi->spcr = (div_tmp & GENMASK(1, 0)) >> 0; - loongson_spi->sper = (div_tmp & GENMASK(3, 2)) >> 2; + div_tmp = fls(div - 1); + + loongson_spi->spcr = spr[div_tmp]; + loongson_spi->sper = spre[div_tmp]; + val = loongson_spi_read_reg(loongson_spi, LOONGSON_SPI_SPCR_REG); val &= ~GENMASK(1, 0); loongson_spi_write_reg(loongson_spi, LOONGSON_SPI_SPCR_REG, val |