diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2016-12-08 10:05:43 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-01-10 08:27:53 +0100 |
commit | 1548f21bd239946ae40ed81f1e07fe5b62f69586 (patch) | |
tree | 6e855529be2400d563c879416aa7271648ca1b6d | |
parent | 84d7f7d8774ca98ff5fa406994852430cf499abf (diff) | |
download | barebox-1548f21bd239946ae40ed81f1e07fe5b62f69586.tar.gz barebox-1548f21bd239946ae40ed81f1e07fe5b62f69586.tar.xz |
spi: mvebu: make sure the value calculated for PSCL is also used
The function used a separate variable to hold the value calculated and
only used it for range checking but then didn't use it.
This fixes calculation for slow baud rate that require a divider > 15.
Additionally fix the rounding.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/spi/mvebu_spi.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/drivers/spi/mvebu_spi.c b/drivers/spi/mvebu_spi.c index 785dec2e56..3298b608fb 100644 --- a/drivers/spi/mvebu_spi.c +++ b/drivers/spi/mvebu_spi.c @@ -128,22 +128,22 @@ static int mvebu_spi_set_baudrate(struct mvebu_spi *p, u32 speed) #if defined(CONFIG_ARCH_ARMADA_370) || defined(CONFIG_ARCH_ARMADA_XP) static int armada_370_xp_spi_set_baudrate(struct mvebu_spi *p, u32 speed) { - u32 pscl, pdiv, rate, val; + u32 pscl, pdiv, val; /* prescaler values: 1,2,3,...,15 */ pscl = DIV_ROUND_UP(clk_get_rate(p->clk), speed); /* additional prescaler divider: 1, 2, 4, 8, 16, 32, 64, 128 */ - pdiv = 0; rate = pscl; - while (rate > 15 && pdiv <= 7) { - rate /= 2; + pdiv = 0; + while (pscl > 15 && pdiv <= 7) { + pscl = DIV_ROUND_UP(pscl, 2); pdiv++; } dev_dbg(p->master.dev, "%s: clk = %lu, speed = %u, pscl = %d, pdiv = %d\n", __func__, clk_get_rate(p->clk), speed, pscl, pdiv); - if (rate > 15 || pdiv > 7) + if (pscl > 15 || pdiv > 7) return -EINVAL; val = readl(p->base + SPI_IF_CONFIG) & ~(IF_CLK_PRESCALE_MASK); |