common: Move clock functions into a new file
[oweals/u-boot.git] / drivers / spi / designware_spi.c
index 02d93763d42d8003e485dfaa16ce3f4ea91e0e24..66ff8eeccdebde3da7980b2006a9d8fe5c70d04c 100644 (file)
@@ -9,8 +9,8 @@
  * Copyright (c) 2009, Intel Corporation.
  */
 
-#include <asm-generic/gpio.h>
 #include <common.h>
+#include <asm-generic/gpio.h>
 #include <clk.h>
 #include <dm.h>
 #include <errno.h>
@@ -22,8 +22,6 @@
 #include <linux/iopoll.h>
 #include <asm/io.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 /* Register offsets */
 #define DW_SPI_CTRL0                   0x00
 #define DW_SPI_CTRL1                   0x04
@@ -128,7 +126,7 @@ static inline void dw_write(struct dw_spi_priv *priv, u32 offset, u32 val)
 
 static int request_gpio_cs(struct udevice *bus)
 {
-#if defined(CONFIG_DM_GPIO) && !defined(CONFIG_SPL_BUILD)
+#if CONFIG_IS_ENABLED(DM_GPIO) && !defined(CONFIG_SPL_BUILD)
        struct dw_spi_priv *priv = dev_get_priv(bus);
        int ret;
 
@@ -155,14 +153,12 @@ static int request_gpio_cs(struct udevice *bus)
 static int dw_spi_ofdata_to_platdata(struct udevice *bus)
 {
        struct dw_spi_platdata *plat = bus->platdata;
-       const void *blob = gd->fdt_blob;
-       int node = dev_of_offset(bus);
 
        plat->regs = (struct dw_spi *)devfdt_get_addr(bus);
 
        /* Use 500KHz as a suitable default */
-       plat->frequency = fdtdec_get_int(blob, node, "spi-max-frequency",
-                                       500000);
+       plat->frequency = dev_read_u32_default(bus, "spi-max-frequency",
+                                              500000);
        debug("%s: regs=%p max-frequency=%d\n", __func__, plat->regs,
              plat->frequency);
 
@@ -377,7 +373,7 @@ static int poll_transfer(struct dw_spi_priv *priv)
  */
 __weak void external_cs_manage(struct udevice *dev, bool on)
 {
-#if defined(CONFIG_DM_GPIO) && !defined(CONFIG_SPL_BUILD)
+#if CONFIG_IS_ENABLED(DM_GPIO) && !defined(CONFIG_SPL_BUILD)
        struct dw_spi_priv *priv = dev_get_priv(dev->parent);
 
        if (!dm_gpio_is_valid(&priv->cs_gpio))
@@ -522,8 +518,22 @@ static int dw_spi_set_mode(struct udevice *bus, uint mode)
 static int dw_spi_remove(struct udevice *bus)
 {
        struct dw_spi_priv *priv = dev_get_priv(bus);
+       int ret;
+
+       ret = reset_release_bulk(&priv->resets);
+       if (ret)
+               return ret;
 
-       return reset_release_bulk(&priv->resets);
+#if CONFIG_IS_ENABLED(CLK)
+       ret = clk_disable(&priv->clk);
+       if (ret)
+               return ret;
+
+       ret = clk_free(&priv->clk);
+       if (ret)
+               return ret;
+#endif
+       return 0;
 }
 
 static const struct dm_spi_ops dw_spi_ops = {