[PATCH] clk: implement clk_bulk_get_optional()

Sascha Hauer s.hauer at pengutronix.de
Wed Jun 9 04:53:16 PDT 2021


Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/clk/clk-bulk.c | 25 ++++++++++++++++++++++---
 include/linux/clk.h    | 20 ++++++++++++++++++++
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-bulk.c b/drivers/clk/clk-bulk.c
index b8db60dcbc..0a0d0f2cb2 100644
--- a/drivers/clk/clk-bulk.c
+++ b/drivers/clk/clk-bulk.c
@@ -23,8 +23,9 @@ void clk_bulk_put(int num_clks, struct clk_bulk_data *clks)
 }
 EXPORT_SYMBOL_GPL(clk_bulk_put);
 
-int __must_check clk_bulk_get(struct device_d *dev, int num_clks,
-			      struct clk_bulk_data *clks)
+static int __clk_bulk_get(struct device_d *dev, int num_clks,
+			      struct clk_bulk_data *clks,
+			      bool optional)
 {
 	int ret;
 	int i;
@@ -36,10 +37,15 @@ int __must_check clk_bulk_get(struct device_d *dev, int num_clks,
 		clks[i].clk = clk_get(dev, clks[i].id);
 		if (IS_ERR(clks[i].clk)) {
 			ret = PTR_ERR(clks[i].clk);
+			clks[i].clk = NULL;
+
+			if (ret == -ENOENT && optional)
+				continue;
+
 			if (ret != -EPROBE_DEFER)
 				dev_err(dev, "Failed to get clk '%s': %d\n",
 					clks[i].id, ret);
-			clks[i].clk = NULL;
+
 			goto err;
 		}
 	}
@@ -51,8 +57,21 @@ err:
 
 	return ret;
 }
+
+int __must_check clk_bulk_get(struct device_d *dev, int num_clks,
+			      struct clk_bulk_data *clks)
+{
+	return __clk_bulk_get(dev, num_clks, clks, false);
+}
 EXPORT_SYMBOL(clk_bulk_get);
 
+int __must_check clk_bulk_get_optional(struct device_d *dev, int num_clks,
+				       struct clk_bulk_data *clks)
+{
+	return __clk_bulk_get(dev, num_clks, clks, true);
+}
+EXPORT_SYMBOL(clk_bulk_get_optional);
+
 static int __must_check of_clk_bulk_get(struct device_node *np, int num_clks,
 					struct clk_bulk_data *clks)
 {
diff --git a/include/linux/clk.h b/include/linux/clk.h
index c49fe9a54c..134585f371 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -82,6 +82,19 @@ struct clk *clk_get(struct device_d *dev, const char *id);
 int __must_check clk_bulk_get(struct device_d *dev, int num_clks,
 			      struct clk_bulk_data *clks);
 
+/**
+ * clk_bulk_get_optional - lookup and obtain a number of references to clock producer
+ * @dev: device for clock "consumer"
+ * @num_clks: the number of clk_bulk_data
+ * @clks: the clk_bulk_data table of consumer
+ *
+ * Behaves the same as clk_bulk_get() except where there is no clock producer.
+ * In this case, instead of returning -ENOENT, the function returns 0 and
+ * NULL for a clk for which a clock producer could not be determined.
+ */
+int __must_check clk_bulk_get_optional(struct device_d *dev, int num_clks,
+				       struct clk_bulk_data *clks);
+
 /**
  * clk_bulk_get_all - lookup and obtain all available references to clock
  *                    producer.
@@ -274,6 +287,13 @@ static inline int __must_check clk_bulk_get(struct device_d *dev, int num_clks,
 	return 0;
 }
 
+static inline int __must_check clk_bulk_get_optional(struct device_d *dev,
+						     int num_clks,
+						     struct clk_bulk_data *clks)
+{
+	return 0;
+}
+
 static inline int __must_check clk_bulk_get_all(struct device_d *dev,
 						struct clk_bulk_data **clks)
 {
-- 
2.29.2




More information about the barebox mailing list