This function will be called from the upcoming bfetch command to
determine whether the running barebox has a CCF clock tree that goes
beyond fixed clocks for board-level oscillators.

Signed-off-by: Ahmad Fatoum <a.fat...@barebox.org>
---
v1 -> v2:
  - fix typo in commit message s/regulators/clocks/
---
 drivers/clk/clk-fixed.c |  7 +++++++
 drivers/clk/clk-fixed.h | 11 +++++++++++
 drivers/clk/clk.c       | 14 ++++++++++++++
 include/linux/clk.h     |  9 +++++++++
 4 files changed, 41 insertions(+)
 create mode 100644 drivers/clk/clk-fixed.h

diff --git a/drivers/clk/clk-fixed.c b/drivers/clk/clk-fixed.c
index 6ec2feb84f9e..ea081d0f22de 100644
--- a/drivers/clk/clk-fixed.c
+++ b/drivers/clk/clk-fixed.c
@@ -9,6 +9,8 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 
+#include "clk-fixed.h"
+
 struct clk_fixed {
        struct clk_hw hw;
        unsigned long rate;
@@ -27,6 +29,11 @@ static struct clk_ops clk_fixed_ops = {
        .is_enabled = clk_is_enabled_always,
 };
 
+bool clk_is_fixed(struct clk *clk)
+{
+       return clk->ops == &clk_fixed_ops;
+}
+
 struct clk *clk_register_fixed_rate(const char *name,
                                    const char *parent_name, unsigned long 
flags,
                                    unsigned long rate)
diff --git a/drivers/clk/clk-fixed.h b/drivers/clk/clk-fixed.h
new file mode 100644
index 000000000000..d7f7a12cb60d
--- /dev/null
+++ b/drivers/clk/clk-fixed.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _CLK_FIXED_H
+#define _CLK_FIXED_H
+
+#include <linux/types.h>
+
+struct clk;
+
+bool clk_is_fixed(struct clk *clk);
+
+#endif
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 1fa9027bc6cd..89a007a12c5b 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -14,8 +14,22 @@
 #include <linux/clk/clk-conf.h>
 #include <pinctrl.h>
 
+#include "clk-fixed.h"
+
 static LIST_HEAD(clks);
 
+bool clk_have_nonfixed_providers(void)
+{
+       struct clk *c;
+
+       list_for_each_entry(c, &clks, list) {
+               if (!clk_is_fixed(c))
+                       return true;
+       }
+
+       return false;
+}
+
 static int clk_parent_enable(struct clk *clk)
 {
        struct clk *parent = clk_get_parent(clk);
diff --git a/include/linux/clk.h b/include/linux/clk.h
index f893d9071371..526641927754 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -11,6 +11,7 @@
 #define __LINUX_CLK_H
 
 #include <linux/err.h>
+#include <linux/types.h>
 #include <linux/spinlock.h>
 #include <linux/stringify.h>
 #include <linux/string.h>
@@ -971,6 +972,9 @@ static inline void clk_hw_unregister(struct clk_hw *hw)
 
 #ifdef CONFIG_COMMON_CLK
 
+bool clk_have_nonfixed_providers(void);
+
+
 /**
  * clk_bulk_get - lookup and obtain a number of references to clock producer.
  * @dev: device for clock "consumer"
@@ -1085,6 +1089,11 @@ int __must_check clk_bulk_enable(int num_clks,
 void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks);
 
 #else
+static inline bool clk_have_nonfixed_providers(void)
+{
+       return false;
+}
+
 static inline int __must_check clk_bulk_get(struct device *dev, int num_clks,
                                            struct clk_bulk_data *clks)
 {
-- 
2.39.5


Reply via email to