[U-Boot] [PATCH 1/3] spi: bfin_spi: Use DIV_ROUND_UP instead of open-coded

Axel Lin axel.lin at ingics.com
Fri Jul 12 11:39:41 CEST 2013


Use DIV_ROUND_UP to simplify the code.

Signed-off-by: Axel Lin <axel.lin at ingics.com>
---
 drivers/spi/bfin_spi.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/spi/bfin_spi.c b/drivers/spi/bfin_spi.c
index a9a4d92..f7192c2 100644
--- a/drivers/spi/bfin_spi.c
+++ b/drivers/spi/bfin_spi.c
@@ -144,10 +144,8 @@ void spi_set_speed(struct spi_slave *slave, uint hz)
 	u32 baud;
 
 	sclk = get_sclk();
-	baud = sclk / (2 * hz);
 	/* baud should be rounded up */
-	if (sclk % (2 * hz))
-		baud += 1;
+	baud = DIV_ROUND_UP(sclk, 2 * hz);
 	if (baud < 2)
 		baud = 2;
 	else if (baud > (u16)-1)
-- 
1.8.1.2





More information about the U-Boot mailing list