spi: imx: Use clock framework if enabled
authorMarek Vasut <marex@denx.de>
Mon, 18 Jan 2021 23:58:33 +0000 (00:58 +0100)
committerStefano Babic <sbabic@denx.de>
Sat, 23 Jan 2021 12:40:29 +0000 (13:40 +0100)
In case the clock framework is enabled, enable the SPI controller clock
and obtain max frequency from the clock framework.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Jagan Teki <jagan@amarulasolutions.com>
Cc: Stefano Babic <sbabic@denx.de>
drivers/spi/mxc_spi.c

index c61ab74..553a031 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <clk.h>
 #include <dm.h>
 #include <log.h>
 #include <malloc.h>
@@ -617,8 +618,19 @@ static int mxc_spi_probe(struct udevice *bus)
        if (mxcs->base == FDT_ADDR_T_NONE)
                return -ENODEV;
 
+#if CONFIG_IS_ENABLED(CLK)
+       struct clk clk;
+       ret = clk_get_by_index(bus, 0, &clk);
+       if (ret)
+               return ret;
+
+       clk_enable(&clk);
+
+       mxcs->max_hz = clk_get_rate(&clk);
+#else
        mxcs->max_hz = fdtdec_get_int(blob, node, "spi-max-frequency",
                                      20000000);
+#endif
 
        return 0;
 }