From: Cliff Cai <cliff....@analog.com>

If the requested clock cannot be exactly obtained, round it up so that we
err on the side of slightly slower rather than slightly faster.

Signed-off-by: Cliff Cai <cliff....@analog.com>
Signed-off-by: Mike Frysinger <vap...@gentoo.org>
---
 drivers/spi/bfin_spi.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/drivers/spi/bfin_spi.c b/drivers/spi/bfin_spi.c
index 093166e..f28d42b 100644
--- a/drivers/spi/bfin_spi.c
+++ b/drivers/spi/bfin_spi.c
@@ -85,6 +85,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned 
int cs,
                unsigned int max_hz, unsigned int mode)
 {
        struct bfin_spi_slave *bss;
+       ulong sclk;
        u32 mmr_base;
        u32 baud;
 
@@ -105,7 +106,11 @@ struct spi_slave *spi_setup_slave(unsigned int bus, 
unsigned int cs,
                default: return NULL;
        }
 
-       baud = get_sclk() / (2 * max_hz);
+       sclk = get_sclk();
+       baud = sclk / (2 * max_hz);
+       /* baud should be rounded up */
+       if (sclk % (2 * max_hz))
+               baud += 1;
        if (baud < 2)
                baud = 2;
        else if (baud > (u16)-1)
-- 
1.6.5.5

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to