Skip to contentSkip to conversation

spi: mvebu_a3700_spi: Fix clock prescale computation

PATCH New Marek Behún 3 participants 3 messages Jul 23, 2019 – Aug 14, 2019 SPI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---
 drivers/spi/mvebu_a3700_spi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/spi/mvebu_a3700_spi.c +2 -3
index feeafdceaa..99ad505f24 100644
@@ -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;
Signature · 1 line
2.21.0
#1 lore raw

PATCH v2 1/1 spi: mvebu_a3700_spi: Fix clock prescale computation

Quoted 19 lines · Marek Behún

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.

---
  drivers/spi/mvebu_a3700_spi.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/spi/mvebu_a3700_spi.c +0 -0
index feeafdceaa..99ad505f24 100644
@@ -181,10 +181,9 @@ static int mvebu_spi_set_speed(struct udevice *bus, uint hz)
  	data = readl(&reg->cfg);
 

drivers/spi/mvebu_a3700_spi.c static int mvebu_spi_set_speed(struct udevice *bus, uint hz) · line 189

Quoted 10 lines
drivers/spi/mvebu_a3700_spi.c +2 -3
  	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;

Thanks,
Stefan

#2 lore raw

PATCH v2 1/1 spi: mvebu_a3700_spi: Fix clock prescale computation

In reply to Marek Behún
Quoted 9 lines · Marek Behún

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.

---

Applied to u-boot-spi/master