Merge https://gitlab.denx.de/u-boot/custodians/u-boot-spi
[platform/kernel/u-boot.git] / drivers / spi / cadence_qspi.c
index 619fff7..994a594 100644 (file)
@@ -6,12 +6,15 @@
 
 #include <common.h>
 #include <clk.h>
+#include <asm-generic/io.h>
 #include <dm.h>
 #include <fdtdec.h>
 #include <malloc.h>
 #include <reset.h>
 #include <spi.h>
 #include <spi-mem.h>
+#include <dm/device_compat.h>
+#include <linux/err.h>
 #include <linux/errno.h>
 #include <linux/sizes.h>
 #include "cadence_qspi.h"
@@ -163,11 +166,28 @@ static int cadence_spi_probe(struct udevice *bus)
 {
        struct cadence_spi_platdata *plat = bus->platdata;
        struct cadence_spi_priv *priv = dev_get_priv(bus);
+       struct clk clk;
        int ret;
 
        priv->regbase = plat->regbase;
        priv->ahbbase = plat->ahbbase;
 
+       if (plat->ref_clk_hz == 0) {
+               ret = clk_get_by_index(bus, 0, &clk);
+               if (ret) {
+#ifdef CONFIG_CQSPI_REF_CLK
+                       plat->ref_clk_hz = CONFIG_CQSPI_REF_CLK;
+#else
+                       return ret;
+#endif
+               } else {
+                       plat->ref_clk_hz = clk_get_rate(&clk);
+                       clk_free(&clk);
+                       if (IS_ERR_VALUE(plat->ref_clk_hz))
+                               return plat->ref_clk_hz;
+               }
+       }
+
        ret = reset_get_bulk(bus, &priv->resets);
        if (ret)
                dev_warn(bus, "Can't get reset: %d\n", ret);
@@ -265,8 +285,6 @@ static int cadence_spi_ofdata_to_platdata(struct udevice *bus)
 {
        struct cadence_spi_platdata *plat = bus->platdata;
        ofnode subnode;
-       struct clk clk;
-       int ret;
 
        plat->regbase = (void *)devfdt_get_addr_index(bus, 0);
        plat->ahbbase = (void *)devfdt_get_addr_size_index(bus, 1,
@@ -302,20 +320,6 @@ static int cadence_spi_ofdata_to_platdata(struct udevice *bus)
        plat->tchsh_ns = ofnode_read_u32_default(subnode, "cdns,tchsh-ns", 20);
        plat->tslch_ns = ofnode_read_u32_default(subnode, "cdns,tslch-ns", 20);
 
-       ret = clk_get_by_index(bus, 0, &clk);
-       if (ret) {
-#ifdef CONFIG_CQSPI_REF_CLK
-               plat->ref_clk_hz = CONFIG_CQSPI_REF_CLK;
-#else
-               return ret;
-#endif
-       } else {
-               plat->ref_clk_hz = clk_get_rate(&clk);
-               clk_free(&clk);
-               if (IS_ERR_VALUE(plat->ref_clk_hz))
-                       return plat->ref_clk_hz;
-       }
-
        debug("%s: regbase=%p ahbbase=%p max-frequency=%d page-size=%d\n",
              __func__, plat->regbase, plat->ahbbase, plat->max_hz,
              plat->page_size);
@@ -339,6 +343,7 @@ static const struct dm_spi_ops cadence_spi_ops = {
 
 static const struct udevice_id cadence_spi_ids[] = {
        { .compatible = "cdns,qspi-nor" },
+       { .compatible = "ti,am654-ospi" },
        { }
 };