dm: treewide: Rename auto_alloc_size members to be shorter
[platform/kernel/u-boot.git] / drivers / spi / stm32_qspi.c
index bb1067f..4431778 100644 (file)
@@ -9,8 +9,14 @@
 
 #include <common.h>
 #include <clk.h>
+#include <dm.h>
+#include <log.h>
 #include <reset.h>
+#include <spi.h>
 #include <spi-mem.h>
+#include <dm/device_compat.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
 #include <linux/iopoll.h>
 #include <linux/ioport.h>
 #include <linux/sizes.h>
@@ -361,9 +367,9 @@ static int stm32_qspi_probe(struct udevice *bus)
        }
 
        priv->clock_rate = clk_get_rate(&clk);
-       if (priv->clock_rate < 0) {
+       if (!priv->clock_rate) {
                clk_disable(&clk);
-               return priv->clock_rate;
+               return -EINVAL;
        }
 
        ret = reset_get_by_index(bus, 0, &reset_ctl);
@@ -395,14 +401,15 @@ static int stm32_qspi_claim_bus(struct udevice *dev)
 {
        struct stm32_qspi_priv *priv = dev_get_priv(dev->parent);
        struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
+       int slave_cs = slave_plat->cs;
 
-       if (slave_plat->cs >= STM32_QSPI_MAX_CHIP)
+       if (slave_cs >= STM32_QSPI_MAX_CHIP)
                return -ENODEV;
 
-       if (priv->cs_used != slave_plat->cs) {
-               struct stm32_qspi_flash *flash = &priv->flash[slave_plat->cs];
+       if (priv->cs_used != slave_cs) {
+               struct stm32_qspi_flash *flash = &priv->flash[slave_cs];
 
-               priv->cs_used = slave_plat->cs;
+               priv->cs_used = slave_cs;
 
                if (flash->initialized) {
                        /* Set the configuration: speed + cs */
@@ -444,11 +451,12 @@ static int stm32_qspi_set_speed(struct udevice *bus, uint speed)
        int ret;
 
        if (speed > 0) {
-               prescaler = DIV_ROUND_UP(qspi_clk, speed) - 1;
-               if (prescaler > 255)
-                       prescaler = 255;
-               else if (prescaler < 0)
-                       prescaler = 0;
+               prescaler = 0;
+               if (qspi_clk) {
+                       prescaler = DIV_ROUND_UP(qspi_clk, speed) - 1;
+                       if (prescaler > 255)
+                               prescaler = 255;
+               }
        }
 
        csht = DIV_ROUND_UP((5 * qspi_clk) / (prescaler + 1), 100000000);
@@ -524,7 +532,6 @@ static const struct dm_spi_ops stm32_qspi_ops = {
 };
 
 static const struct udevice_id stm32_qspi_ids[] = {
-       { .compatible = "st,stm32-qspi" },
        { .compatible = "st,stm32f469-qspi" },
        { }
 };
@@ -534,6 +541,6 @@ U_BOOT_DRIVER(stm32_qspi) = {
        .id = UCLASS_SPI,
        .of_match = stm32_qspi_ids,
        .ops = &stm32_qspi_ops,
-       .priv_auto_alloc_size = sizeof(struct stm32_qspi_priv),
+       .priv_auto      = sizeof(struct stm32_qspi_priv),
        .probe = stm32_qspi_probe,
 };