Merge branch 'master' of git://git.denx.de/u-boot-sunxi
[oweals/u-boot.git] / drivers / spi / bfin_spi.c
index a9a4d92c3e719b0a1f215393ac7fc22de6cae8cf..9a6fc781515ac9016c7c791712395ae8d2396a95 100644 (file)
@@ -3,16 +3,18 @@
  *
  * Copyright (c) 2005-2010 Analog Devices Inc.
  *
- * Licensed under the GPL-2 or later.
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*#define DEBUG*/
 
 #include <common.h>
+#include <console.h>
 #include <malloc.h>
 #include <spi.h>
 
 #include <asm/blackfin.h>
+#include <asm/clock.h>
 #include <asm/gpio.h>
 #include <asm/portmux.h>
 #include <asm/mach-common/bits/spi.h>
@@ -140,14 +142,12 @@ static const unsigned short cs_pins[][7] = {
 void spi_set_speed(struct spi_slave *slave, uint hz)
 {
        struct bfin_spi_slave *bss = to_bfin_spi_slave(slave);
-       ulong sclk;
+       ulong clk;
        u32 baud;
 
-       sclk = get_sclk();
-       baud = sclk / (2 * hz);
+       clk = get_spi_clk();
        /* baud should be rounded up */
-       if (sclk % (2 * hz))
-               baud += 1;
+       baud = DIV_ROUND_UP(clk, 2 * hz);
        if (baud < 2)
                baud = 2;
        else if (baud > (u16)-1)
@@ -164,21 +164,22 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
        if (!spi_cs_is_valid(bus, cs))
                return NULL;
 
-       if (bus >= ARRAY_SIZE(pins) || pins[bus] == NULL) {
-               debug("%s: invalid bus %u\n", __func__, bus);
-               return NULL;
-       }
        switch (bus) {
 #ifdef SPI0_CTL
-               case 0: mmr_base = SPI0_CTL; break;
+       case 0:
+               mmr_base = SPI0_CTL; break;
 #endif
 #ifdef SPI1_CTL
-               case 1: mmr_base = SPI1_CTL; break;
+       case 1:
+               mmr_base = SPI1_CTL; break;
 #endif
 #ifdef SPI2_CTL
-               case 2: mmr_base = SPI2_CTL; break;
+       case 2:
+               mmr_base = SPI2_CTL; break;
 #endif
-               default: return NULL;
+       default:
+               debug("%s: invalid bus %u\n", __func__, bus);
+               return NULL;
        }
 
        bss = spi_alloc_slave(struct bfin_spi_slave, bus, cs);