History

clk: Add clk_bulk_get_optional() function

clk_bulk_get_optional() allows to get a group of clocks where one or more is optional. For a not available clock, e.g. not specifed in the clock consumer node in DT, its respective struct clk pointer will be NULL. This allows for operating on a group of returned clocks (struct clk_bulk_data array) with existing clk_bulk* APIs.

Sylwester Nawrocki committed 7 years ago

Commit 2f255281 parent a1883392 files · +39 −3Browse files

Unified · Split

2 files
  1. drivers/clk/clk-bulk.c +20 −3
  2. include/linux/clk.h +19 −0
drivers/clk/clk-bulk.c+20−3
@@ -75,8 +75,8 @@ void clk_bulk_put(int num_clks, struct clk_bulk_data *clks) · 74 unmodified lines
7575 }
7676 EXPORT_SYMBOL_GPL(clk_bulk_put);
7777
78−int __must_check clk_bulk_get(struct device *dev, int num_clks,
79− struct clk_bulk_data *clks)
78+static int __clk_bulk_get(struct device *dev, int num_clks,
79+ struct clk_bulk_data *clks, bool optional)
8080 {
8181 int ret;
8282 int i;
@@ -88,10 +88,14 @@ int __must_check clk_bulk_get(struct device *dev, int num_clks, · 5 unmodified lines
8888 clks[i].clk = clk_get(dev, clks[i].id);
8989 if (IS_ERR(clks[i].clk)) {
9090 ret = PTR_ERR(clks[i].clk);
91+ clks[i].clk = NULL;
92+
93+ if (ret == -ENOENT && optional)
94+ continue;
95+
9196 if (ret != -EPROBE_DEFER)
9297 dev_err(dev, "Failed to get clk '%s': %d\n",
9398 clks[i].id, ret);
94− clks[i].clk = NULL;
9599 goto err;
96100 }
97101 }
@@ -103,8 +107,21 @@ err: · 5 unmodified lines
103107
104108 return ret;
105109 }
110+
111+int __must_check clk_bulk_get(struct device *dev, int num_clks,
112+ struct clk_bulk_data *clks)
113+{
114+ return __clk_bulk_get(dev, num_clks, clks, false);
115+}
106116 EXPORT_SYMBOL(clk_bulk_get);
107117
118+int __must_check clk_bulk_get_optional(struct device *dev, int num_clks,
119+ struct clk_bulk_data *clks)
120+{
121+ return __clk_bulk_get(dev, num_clks, clks, true);
122+}
123+EXPORT_SYMBOL_GPL(clk_bulk_get_optional);
124+
108125 void clk_bulk_put_all(int num_clks, struct clk_bulk_data *clks)
109126 {
110127 if (IS_ERR_OR_NULL(clks))
include/linux/clk.h+19−0
@@ -332,6 +332,19 @@ int __must_check clk_bulk_get(struct device *dev, int num_clks, · 331 unmodified lines
332332 */
333333 int __must_check clk_bulk_get_all(struct device *dev,
334334 struct clk_bulk_data **clks);
335+
336+/**
337+ * clk_bulk_get_optional - lookup and obtain a number of references to clock producer
338+ * @dev: device for clock "consumer"
339+ * @num_clks: the number of clk_bulk_data
340+ * @clks: the clk_bulk_data table of consumer
341+ *
342+ * Behaves the same as clk_bulk_get() except where there is no clock producer.
343+ * In this case, instead of returning -ENOENT, the function returns 0 and
344+ * NULL for a clk for which a clock producer could not be determined.
345+ */
346+int __must_check clk_bulk_get_optional(struct device *dev, int num_clks,
347+ struct clk_bulk_data *clks);
335348 /**
336349 * devm_clk_bulk_get - managed get multiple clk consumers
337350 * @dev: device for clock "consumer"
@@ -718,6 +731,12 @@ static inline int __must_check clk_bulk_get(struct device *dev, int num_clks, · 380 unmodified lines
718731 return 0;
719732 }
720733
734+static inline int __must_check clk_bulk_get_optional(struct device *dev,
735+ int num_clks, struct clk_bulk_data *clks)
736+{
737+ return 0;
738+}
739+
721740 static inline int __must_check clk_bulk_get_all(struct device *dev,
722741 struct clk_bulk_data **clks)
723742 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t