Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / drivers / spi / stm32_spi.c
index 34b217584dd1e5d009484f69df0ffc8870e80cfb..4a0833b6fa949cb00b89af3d6f20b0562086cd93 100644 (file)
@@ -8,8 +8,13 @@
 #include <clk.h>
 #include <dm.h>
 #include <errno.h>
+#include <log.h>
+#include <malloc.h>
 #include <reset.h>
 #include <spi.h>
+#include <dm/device_compat.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
 
 #include <asm/io.h>
 #include <asm/gpio.h>
@@ -99,8 +104,8 @@ struct stm32_spi_priv {
        unsigned int cur_bpw;
        unsigned int cur_hz;
        unsigned int cur_xferlen; /* current transfer length in bytes */
-       int tx_len;               /* number of data to be written in bytes */
-       int rx_len;               /* number of data to be read in bytes */
+       unsigned int tx_len;      /* number of data to be written in bytes */
+       unsigned int rx_len;      /* number of data to be read in bytes */
        const void *tx_buf;       /* data to be written, or NULL */
        void *rx_buf;             /* data to be read, or NULL */
        u32 cur_mode;
@@ -322,7 +327,8 @@ static int stm32_spi_set_fthlv(struct udevice *dev, u32 xfer_len)
 static int stm32_spi_set_speed(struct udevice *bus, uint hz)
 {
        struct stm32_spi_priv *priv = dev_get_priv(bus);
-       u32 div, mbrdiv;
+       u32 mbrdiv;
+       long div;
 
        debug("%s: hz=%d\n", __func__, hz);
 
@@ -341,7 +347,7 @@ static int stm32_spi_set_speed(struct udevice *bus, uint hz)
        else
                mbrdiv = fls(div) - 1;
 
-       if ((mbrdiv - 1) < 0)
+       if (!mbrdiv)
                return -EINVAL;
 
        clrsetbits_le32(priv->base + STM32_SPI_CFG1, SPI_CFG1_MBR,
@@ -481,7 +487,7 @@ static int stm32_spi_probe(struct udevice *dev)
        struct stm32_spi_priv *priv = dev_get_priv(dev);
        unsigned long clk_rate;
        int ret;
-       int i;
+       unsigned int i;
 
        priv->base = dev_remap_addr(dev);
        if (!priv->base)