clk: stm32mp1: move oscillator functions to generic file
authorYann Gautier <yann.gautier@st.com>
Fri, 17 May 2019 13:57:56 +0000 (15:57 +0200)
committerYann Gautier <yann.gautier@st.com>
Mon, 17 Jun 2019 12:03:51 +0000 (14:03 +0200)
Those functions are generic for parsing nodes from device tree
hence could be located in generic source file.

The oscillators description structure is also moved to STM32MP1 clock
driver, as it is no more used in stm32mp1_clkfunc and cannot be in a
generic file.

Change-Id: I93ba74f4eea916440fef9b160d306af1b39f17c6
Signed-off-by: Yann Gautier <yann.gautier@st.com>
drivers/st/clk/stm32mp1_clk.c
drivers/st/clk/stm32mp1_clkfunc.c [deleted file]
drivers/st/clk/stm32mp_clkfunc.c
include/drivers/st/stm32mp1_clk.h
include/drivers/st/stm32mp1_clkfunc.h [deleted file]
include/drivers/st/stm32mp_clkfunc.h
plat/st/stm32mp1/platform.mk

index eb252872705256bf6287233ddf58378881f1292b..e05a7ba45b8f55b21758b086c88ade9710c1bcd6 100644 (file)
@@ -20,7 +20,6 @@
 #include <drivers/generic_delay_timer.h>
 #include <drivers/st/stm32mp_clkfunc.h>
 #include <drivers/st/stm32mp1_clk.h>
-#include <drivers/st/stm32mp1_clkfunc.h>
 #include <drivers/st/stm32mp1_rcc.h>
 #include <dt-bindings/clock/stm32mp1-clksrc.h>
 #include <lib/mmio.h>
 #define HSIDIV_TIMEOUT         TIMEOUT_US_200MS
 #define OSCRDY_TIMEOUT         TIMEOUT_US_1S
 
+const char *stm32mp_osc_node_label[NB_OSC] = {
+       [_LSI] = "clk-lsi",
+       [_LSE] = "clk-lse",
+       [_HSI] = "clk-hsi",
+       [_HSE] = "clk-hse",
+       [_CSI] = "clk-csi",
+       [_I2S_CKIN] = "i2s_ckin",
+};
+
 enum stm32mp1_parent_id {
 /* Oscillators are defined in enum stm32mp_osc_id */
 
diff --git a/drivers/st/clk/stm32mp1_clkfunc.c b/drivers/st/clk/stm32mp1_clkfunc.c
deleted file mode 100644 (file)
index 1aa05bf..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 2017-2019, STMicroelectronics - All Rights Reserved
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <errno.h>
-
-#include <libfdt.h>
-
-#include <platform_def.h>
-
-#include <drivers/st/stm32_gpio.h>
-#include <drivers/st/stm32mp_clkfunc.h>
-#include <drivers/st/stm32mp1_clk.h>
-#include <drivers/st/stm32mp1_clkfunc.h>
-#include <dt-bindings/clock/stm32mp1-clksrc.h>
-
-const char *stm32mp_osc_node_label[NB_OSC] = {
-       [_LSI] = "clk-lsi",
-       [_LSE] = "clk-lse",
-       [_HSI] = "clk-hsi",
-       [_HSE] = "clk-hse",
-       [_CSI] = "clk-csi",
-       [_I2S_CKIN] = "i2s_ckin",
-};
-
-/*
- * Get the frequency of an oscillator from its name in device tree.
- * @param name: oscillator name
- * @param freq: stores the frequency of the oscillator
- * @return: 0 on success, and a negative FDT/ERRNO error code on failure.
- */
-int fdt_osc_read_freq(const char *name, uint32_t *freq)
-{
-       int node, subnode;
-       void *fdt;
-
-       if (fdt_get_address(&fdt) == 0) {
-               return -ENOENT;
-       }
-
-       node = fdt_path_offset(fdt, "/clocks");
-       if (node < 0) {
-               return -FDT_ERR_NOTFOUND;
-       }
-
-       fdt_for_each_subnode(subnode, fdt, node) {
-               const char *cchar;
-               int ret;
-
-               cchar = fdt_get_name(fdt, subnode, &ret);
-               if (cchar == NULL) {
-                       return ret;
-               }
-
-               if (strncmp(cchar, name, (size_t)ret) == 0) {
-                       const fdt32_t *cuint;
-
-                       cuint = fdt_getprop(fdt, subnode, "clock-frequency",
-                                           &ret);
-                       if (cuint == NULL) {
-                               return ret;
-                       }
-
-                       *freq = fdt32_to_cpu(*cuint);
-
-                       return 0;
-               }
-       }
-
-       /* Oscillator not found, freq=0 */
-       *freq = 0;
-       return 0;
-}
-
-/*
- * Check the presence of an oscillator property from its id.
- * @param osc_id: oscillator ID
- * @param prop_name: property name
- * @return: true/false regarding search result.
- */
-bool fdt_osc_read_bool(enum stm32mp_osc_id osc_id, const char *prop_name)
-{
-       int node, subnode;
-       void *fdt;
-
-       if (fdt_get_address(&fdt) == 0) {
-               return false;
-       }
-
-       if (osc_id >= NB_OSC) {
-               return false;
-       }
-
-       node = fdt_path_offset(fdt, "/clocks");
-       if (node < 0) {
-               return false;
-       }
-
-       fdt_for_each_subnode(subnode, fdt, node) {
-               const char *cchar;
-               int ret;
-
-               cchar = fdt_get_name(fdt, subnode, &ret);
-               if (cchar == NULL) {
-                       return false;
-               }
-
-               if (strncmp(cchar, stm32mp_osc_node_label[osc_id],
-                           (size_t)ret) != 0) {
-                       continue;
-               }
-
-               if (fdt_getprop(fdt, subnode, prop_name, NULL) != NULL) {
-                       return true;
-               }
-       }
-
-       return false;
-}
-
-/*
- * Get the value of a oscillator property from its ID.
- * @param osc_id: oscillator ID
- * @param prop_name: property name
- * @param dflt_value: default value
- * @return oscillator value on success, default value if property not found.
- */
-uint32_t fdt_osc_read_uint32_default(enum stm32mp_osc_id osc_id,
-                                    const char *prop_name, uint32_t dflt_value)
-{
-       int node, subnode;
-       void *fdt;
-
-       if (fdt_get_address(&fdt) == 0) {
-               return dflt_value;
-       }
-
-       if (osc_id >= NB_OSC) {
-               return dflt_value;
-       }
-
-       node = fdt_path_offset(fdt, "/clocks");
-       if (node < 0) {
-               return dflt_value;
-       }
-
-       fdt_for_each_subnode(subnode, fdt, node) {
-               const char *cchar;
-               int ret;
-
-               cchar = fdt_get_name(fdt, subnode, &ret);
-               if (cchar == NULL) {
-                       return dflt_value;
-               }
-
-               if (strncmp(cchar, stm32mp_osc_node_label[osc_id],
-                           (size_t)ret) != 0) {
-                       continue;
-               }
-
-               return fdt_read_uint32_default(subnode, prop_name, dflt_value);
-       }
-
-       return dflt_value;
-}
index 16acef07bea1d9c70d44d9cdf48da2e1fa6fc540..87c8e2b840be6f86a11ad61cd6ce144db5f48944 100644 (file)
 
 #define DT_STGEN_COMPAT                "st,stm32-stgen"
 
+/*
+ * Get the frequency of an oscillator from its name in device tree.
+ * @param name: oscillator name
+ * @param freq: stores the frequency of the oscillator
+ * @return: 0 on success, and a negative FDT/ERRNO error code on failure.
+ */
+int fdt_osc_read_freq(const char *name, uint32_t *freq)
+{
+       int node, subnode;
+       void *fdt;
+
+       if (fdt_get_address(&fdt) == 0) {
+               return -ENOENT;
+       }
+
+       node = fdt_path_offset(fdt, "/clocks");
+       if (node < 0) {
+               return -FDT_ERR_NOTFOUND;
+       }
+
+       fdt_for_each_subnode(subnode, fdt, node) {
+               const char *cchar;
+               int ret;
+
+               cchar = fdt_get_name(fdt, subnode, &ret);
+               if (cchar == NULL) {
+                       return ret;
+               }
+
+               if (strncmp(cchar, name, (size_t)ret) == 0) {
+                       const fdt32_t *cuint;
+
+                       cuint = fdt_getprop(fdt, subnode, "clock-frequency",
+                                           &ret);
+                       if (cuint == NULL) {
+                               return ret;
+                       }
+
+                       *freq = fdt32_to_cpu(*cuint);
+
+                       return 0;
+               }
+       }
+
+       /* Oscillator not found, freq=0 */
+       *freq = 0;
+       return 0;
+}
+
+/*
+ * Check the presence of an oscillator property from its id.
+ * @param osc_id: oscillator ID
+ * @param prop_name: property name
+ * @return: true/false regarding search result.
+ */
+bool fdt_osc_read_bool(enum stm32mp_osc_id osc_id, const char *prop_name)
+{
+       int node, subnode;
+       void *fdt;
+
+       if (fdt_get_address(&fdt) == 0) {
+               return false;
+       }
+
+       if (osc_id >= NB_OSC) {
+               return false;
+       }
+
+       node = fdt_path_offset(fdt, "/clocks");
+       if (node < 0) {
+               return false;
+       }
+
+       fdt_for_each_subnode(subnode, fdt, node) {
+               const char *cchar;
+               int ret;
+
+               cchar = fdt_get_name(fdt, subnode, &ret);
+               if (cchar == NULL) {
+                       return false;
+               }
+
+               if (strncmp(cchar, stm32mp_osc_node_label[osc_id],
+                           (size_t)ret) != 0) {
+                       continue;
+               }
+
+               if (fdt_getprop(fdt, subnode, prop_name, NULL) != NULL) {
+                       return true;
+               }
+       }
+
+       return false;
+}
+
+/*
+ * Get the value of a oscillator property from its ID.
+ * @param osc_id: oscillator ID
+ * @param prop_name: property name
+ * @param dflt_value: default value
+ * @return oscillator value on success, default value if property not found.
+ */
+uint32_t fdt_osc_read_uint32_default(enum stm32mp_osc_id osc_id,
+                                    const char *prop_name, uint32_t dflt_value)
+{
+       int node, subnode;
+       void *fdt;
+
+       if (fdt_get_address(&fdt) == 0) {
+               return dflt_value;
+       }
+
+       if (osc_id >= NB_OSC) {
+               return dflt_value;
+       }
+
+       node = fdt_path_offset(fdt, "/clocks");
+       if (node < 0) {
+               return dflt_value;
+       }
+
+       fdt_for_each_subnode(subnode, fdt, node) {
+               const char *cchar;
+               int ret;
+
+               cchar = fdt_get_name(fdt, subnode, &ret);
+               if (cchar == NULL) {
+                       return dflt_value;
+               }
+
+               if (strncmp(cchar, stm32mp_osc_node_label[osc_id],
+                           (size_t)ret) != 0) {
+                       continue;
+               }
+
+               return fdt_read_uint32_default(subnode, prop_name, dflt_value);
+       }
+
+       return dflt_value;
+}
+
 /*
  * Get the RCC node offset from the device tree
  * @param fdt: Device tree reference
index 7afa5ad84528309d98bd71c9ded6bb71ab28e898..1ebd39ff7f5a27aa8eda6c7be2fd1cc59e567e66 100644 (file)
@@ -9,6 +9,19 @@
 
 #include <arch_helpers.h>
 
+enum stm32mp_osc_id {
+       _HSI,
+       _HSE,
+       _CSI,
+       _LSI,
+       _LSE,
+       _I2S_CKIN,
+       NB_OSC,
+       _UNKNOWN_OSC_ID = 0xFF
+};
+
+extern const char *stm32mp_osc_node_label[NB_OSC];
+
 int stm32mp1_clk_probe(void);
 int stm32mp1_clk_init(void);
 
diff --git a/include/drivers/st/stm32mp1_clkfunc.h b/include/drivers/st/stm32mp1_clkfunc.h
deleted file mode 100644 (file)
index f303937..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2017-2019, STMicroelectronics - All Rights Reserved
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef STM32MP1_CLKFUNC_H
-#define STM32MP1_CLKFUNC_H
-
-#include <stdbool.h>
-
-#include <libfdt.h>
-
-enum stm32mp_osc_id {
-       _HSI,
-       _HSE,
-       _CSI,
-       _LSI,
-       _LSE,
-       _I2S_CKIN,
-       NB_OSC,
-       _UNKNOWN_OSC_ID = 0xFF
-};
-
-extern const char *stm32mp_osc_node_label[NB_OSC];
-
-int fdt_osc_read_freq(const char *name, uint32_t *freq);
-bool fdt_osc_read_bool(enum stm32mp_osc_id osc_id, const char *prop_name);
-uint32_t fdt_osc_read_uint32_default(enum stm32mp_osc_id osc_id,
-                                    const char *prop_name,
-                                    uint32_t dflt_value);
-
-#endif /* STM32MP1_CLKFUNC_H */
index 5beb06bb2afa9fa31e46a359629798d31fb00f09..076916730410aee57c9d3f00cabf6213c8674d96 100644 (file)
 
 #include <libfdt.h>
 
+#include <platform_def.h>
+
+int fdt_osc_read_freq(const char *name, uint32_t *freq);
+bool fdt_osc_read_bool(enum stm32mp_osc_id osc_id, const char *prop_name);
+uint32_t fdt_osc_read_uint32_default(enum stm32mp_osc_id osc_id,
+                                    const char *prop_name,
+                                    uint32_t dflt_value);
+
 int fdt_get_rcc_node(void *fdt);
 uint32_t fdt_rcc_read_addr(void);
 int fdt_rcc_read_uint32_array(const char *prop_name,
index 4796e91f0850582784e4571fd57e69b6d6d0709e..ffe0cc643417967792f166ec55a188bab63dd7e4 100644 (file)
@@ -56,7 +56,6 @@ PLAT_BL_COMMON_SOURCES        +=      ${LIBFDT_SRCS}                                          \
                                drivers/st/bsec/bsec.c                                  \
                                drivers/st/clk/stm32mp_clkfunc.c                        \
                                drivers/st/clk/stm32mp1_clk.c                           \
-                               drivers/st/clk/stm32mp1_clkfunc.c                       \
                                drivers/st/ddr/stm32mp1_ddr_helpers.c                   \
                                drivers/st/gpio/stm32_gpio.c                            \
                                drivers/st/i2c/stm32_i2c.c                              \