8d9bd9ce014fb53a35e46fa879bf054f6c394c58
[openwrt/staging/stintel.git] /
1 From 51e32e897539663957f7a0950f66b48f8896efee Mon Sep 17 00:00:00 2001
2 From: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
3 Date: Sat, 19 Oct 2024 14:16:00 +0300
4 Subject: [PATCH] clk: Provide devm_clk_bulk_get_all_enabled() helper
5
6 Commit 265b07df758a ("clk: Provide managed helper to get and enable bulk
7 clocks") added devm_clk_bulk_get_all_enable() function, but missed to
8 return the number of clocks stored in the clk_bulk_data table referenced
9 by the clks argument. Without knowing the number, it's not possible to
10 iterate these clocks when needed, hence the argument is useless and
11 could have been simply removed.
12
13 Introduce devm_clk_bulk_get_all_enabled() variant, which is consistent
14 with devm_clk_bulk_get_all() in terms of the returned value:
15
16 > 0 if one or more clocks have been stored
17 = 0 if there are no clocks
18 < 0 if an error occurred
19
20 Moreover, the naming is consistent with devm_clk_get_enabled(), i.e. use
21 the past form of 'enable'.
22
23 To reduce code duplication and improve patch readability, make
24 devm_clk_bulk_get_all_enable() use the new helper, as suggested by
25 Stephen Boyd.
26
27 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
28 Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
29 Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
30 Link: https://lore.kernel.org/r/20241019-clk_bulk_ena_fix-v4-1-57f108f64e70@collabora.com
31 Signed-off-by: Stephen Boyd <sboyd@kernel.org>
32 ---
33 drivers/clk/clk-devres.c | 9 +++++----
34 include/linux/clk.h | 21 ++++++++++++++++-----
35 2 files changed, 21 insertions(+), 9 deletions(-)
36
37 diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
38 index 82ae1f26e634..5368d92d9b39 100644
39 --- a/drivers/clk/clk-devres.c
40 +++ b/drivers/clk/clk-devres.c
41 @@ -218,8 +218,8 @@ static void devm_clk_bulk_release_all_enable(struct device *dev, void *res)
42 clk_bulk_put_all(devres->num_clks, devres->clks);
43 }
44
45 -int __must_check devm_clk_bulk_get_all_enable(struct device *dev,
46 - struct clk_bulk_data **clks)
47 +int __must_check devm_clk_bulk_get_all_enabled(struct device *dev,
48 + struct clk_bulk_data **clks)
49 {
50 struct clk_bulk_devres *devres;
51 int ret;
52 @@ -244,11 +244,12 @@ int __must_check devm_clk_bulk_get_all_enable(struct device *dev,
53 } else {
54 clk_bulk_put_all(devres->num_clks, devres->clks);
55 devres_free(devres);
56 + return ret;
57 }
58
59 - return ret;
60 + return devres->num_clks;
61 }
62 -EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all_enable);
63 +EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all_enabled);
64
65 static int devm_clk_match(struct device *dev, void *res, void *data)
66 {
67 diff --git a/include/linux/clk.h b/include/linux/clk.h
68 index 851a0f2cf42c..1dcee6d701e4 100644
69 --- a/include/linux/clk.h
70 +++ b/include/linux/clk.h
71 @@ -496,11 +496,13 @@ int __must_check devm_clk_bulk_get_all(struct device *dev,
72 struct clk_bulk_data **clks);
73
74 /**
75 - * devm_clk_bulk_get_all_enable - Get and enable all clocks of the consumer (managed)
76 + * devm_clk_bulk_get_all_enabled - Get and enable all clocks of the consumer (managed)
77 * @dev: device for clock "consumer"
78 * @clks: pointer to the clk_bulk_data table of consumer
79 *
80 - * Returns success (0) or negative errno.
81 + * Returns a positive value for the number of clocks obtained while the
82 + * clock references are stored in the clk_bulk_data table in @clks field.
83 + * Returns 0 if there're none and a negative value if something failed.
84 *
85 * This helper function allows drivers to get all clocks of the
86 * consumer and enables them in one operation with management.
87 @@ -508,8 +510,8 @@ int __must_check devm_clk_bulk_get_all(struct device *dev,
88 * is unbound.
89 */
90
91 -int __must_check devm_clk_bulk_get_all_enable(struct device *dev,
92 - struct clk_bulk_data **clks);
93 +int __must_check devm_clk_bulk_get_all_enabled(struct device *dev,
94 + struct clk_bulk_data **clks);
95
96 /**
97 * devm_clk_get - lookup and obtain a managed reference to a clock producer.
98 @@ -1034,7 +1036,7 @@ static inline int __must_check devm_clk_bulk_get_all(struct device *dev,
99 return 0;
100 }
101
102 -static inline int __must_check devm_clk_bulk_get_all_enable(struct device *dev,
103 +static inline int __must_check devm_clk_bulk_get_all_enabled(struct device *dev,
104 struct clk_bulk_data **clks)
105 {
106 return 0;
107 @@ -1136,6 +1138,15 @@ static inline void clk_restore_context(void) {}
108
109 #endif
110
111 +/* Deprecated. Use devm_clk_bulk_get_all_enabled() */
112 +static inline int __must_check
113 +devm_clk_bulk_get_all_enable(struct device *dev, struct clk_bulk_data **clks)
114 +{
115 + int ret = devm_clk_bulk_get_all_enabled(dev, clks);
116 +
117 + return ret > 0 ? 0 : ret;
118 +}
119 +
120 /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
121 static inline int clk_prepare_enable(struct clk *clk)
122 {
123 --
124 2.45.2
125