summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMarek BehĂșn <marek.behun@nic.cz>2019-07-23 17:49:32 +0300
committerJagan Teki <jagan@amarulasolutions.com>2019-09-16 05:39:22 +0300
commit07a5cb9d3b9bf9bca9ca207b82f92eac73cbdda8 (patch)
tree3f2db1a85c43f293b5cd76444118a12943bbcbc2 /drivers
parent23b93e33adde0a8313388eda7c78d1d0786e3c92 (diff)
downloadu-boot-07a5cb9d3b9bf9bca9ca207b82f92eac73cbdda8.tar.xz
spi: mvebu_a3700_spi: Fix clock prescale computation
The prescaler value computation can yield wrong result if given 0x1f at the beginning: the value is computed to be 0x20, but the maximum value the register can hold 0x1f, so the actual stored value in this case is 0, which is obviously wrong. Set the upper bound of the value to 0x1f with the min macro. Signed-off-by: Marek BehĂșn <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de> Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/spi/mvebu_a3700_spi.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/spi/mvebu_a3700_spi.c b/drivers/spi/mvebu_a3700_spi.c
index feeafdceaa..99ad505f24 100644
--- a/drivers/spi/mvebu_a3700_spi.c
+++ b/drivers/spi/mvebu_a3700_spi.c
@@ -181,10 +181,9 @@ static int mvebu_spi_set_speed(struct udevice *bus, uint hz)
data = readl(&reg->cfg);
prescale = DIV_ROUND_UP(clk_get_rate(&plat->clk), hz);
- if (prescale > 0x1f)
- prescale = 0x1f;
- else if (prescale > 0xf)
+ if (prescale > 0xf)
prescale = 0x10 + (prescale + 1) / 2;
+ prescale = min(prescale, 0x1fu);
data &= ~MVEBU_SPI_A3700_CLK_PRESCALE_MASK;
data |= prescale & MVEBU_SPI_A3700_CLK_PRESCALE_MASK;