hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/clk/clk-fixed-factor.c
....@@ -1,11 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 as
6
- * published by the Free Software Foundation.
7
- *
8
- * Standard functionality for the common clock API.
94 */
105 #include <linux/module.h>
116 #include <linux/clk-provider.h>
....@@ -69,12 +64,14 @@
6964 };
7065 EXPORT_SYMBOL_GPL(clk_fixed_factor_ops);
7166
72
-struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
73
- const char *name, const char *parent_name, unsigned long flags,
74
- unsigned int mult, unsigned int div)
67
+static struct clk_hw *
68
+__clk_hw_register_fixed_factor(struct device *dev, struct device_node *np,
69
+ const char *name, const char *parent_name, int index,
70
+ unsigned long flags, unsigned int mult, unsigned int div)
7571 {
7672 struct clk_fixed_factor *fix;
77
- struct clk_init_data init = {};
73
+ struct clk_init_data init = { };
74
+ struct clk_parent_data pdata = { .index = index };
7875 struct clk_hw *hw;
7976 int ret;
8077
....@@ -89,18 +86,32 @@
8986
9087 init.name = name;
9188 init.ops = &clk_fixed_factor_ops;
92
- init.flags = flags | CLK_IS_BASIC;
93
- init.parent_names = &parent_name;
89
+ init.flags = flags;
90
+ if (parent_name)
91
+ init.parent_names = &parent_name;
92
+ else
93
+ init.parent_data = &pdata;
9494 init.num_parents = 1;
9595
9696 hw = &fix->hw;
97
- ret = clk_hw_register(dev, hw);
97
+ if (dev)
98
+ ret = clk_hw_register(dev, hw);
99
+ else
100
+ ret = of_clk_hw_register(np, hw);
98101 if (ret) {
99102 kfree(fix);
100103 hw = ERR_PTR(ret);
101104 }
102105
103106 return hw;
107
+}
108
+
109
+struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
110
+ const char *name, const char *parent_name, unsigned long flags,
111
+ unsigned int mult, unsigned int div)
112
+{
113
+ return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, -1,
114
+ flags, mult, div);
104115 }
105116 EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor);
106117
....@@ -148,56 +159,54 @@
148159 { /* Sentinel */ },
149160 };
150161
151
-static struct clk *_of_fixed_factor_clk_setup(struct device_node *node)
162
+static struct clk_hw *_of_fixed_factor_clk_setup(struct device_node *node)
152163 {
153
- struct clk *clk;
164
+ struct clk_hw *hw;
154165 const char *clk_name = node->name;
155
- const char *parent_name;
156166 unsigned long flags = 0;
157167 u32 div, mult;
158168 int ret;
159169
160170 if (of_property_read_u32(node, "clock-div", &div)) {
161
- pr_err("%s Fixed factor clock <%s> must have a clock-div property\n",
162
- __func__, node->name);
171
+ pr_err("%s Fixed factor clock <%pOFn> must have a clock-div property\n",
172
+ __func__, node);
163173 return ERR_PTR(-EIO);
164174 }
165175
166176 if (of_property_read_u32(node, "clock-mult", &mult)) {
167
- pr_err("%s Fixed factor clock <%s> must have a clock-mult property\n",
168
- __func__, node->name);
177
+ pr_err("%s Fixed factor clock <%pOFn> must have a clock-mult property\n",
178
+ __func__, node);
169179 return ERR_PTR(-EIO);
170180 }
171181
172182 of_property_read_string(node, "clock-output-names", &clk_name);
173
- parent_name = of_clk_get_parent_name(node, 0);
174183
175184 if (of_match_node(set_rate_parent_matches, node))
176185 flags |= CLK_SET_RATE_PARENT;
177186
178
- clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags,
179
- mult, div);
180
- if (IS_ERR(clk)) {
187
+ hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, 0,
188
+ flags, mult, div);
189
+ if (IS_ERR(hw)) {
181190 /*
182
- * If parent clock is not registered, registration would fail.
183191 * Clear OF_POPULATED flag so that clock registration can be
184192 * attempted again from probe function.
185193 */
186194 of_node_clear_flag(node, OF_POPULATED);
187
- return clk;
195
+ return ERR_CAST(hw);
188196 }
189197
190
- ret = of_clk_add_provider(node, of_clk_src_simple_get, clk);
198
+ ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, hw);
191199 if (ret) {
192
- clk_unregister(clk);
200
+ clk_hw_unregister_fixed_factor(hw);
193201 return ERR_PTR(ret);
194202 }
195203
196
- return clk;
204
+ return hw;
197205 }
198206
199207 /**
200208 * of_fixed_factor_clk_setup() - Setup function for simple fixed factor clock
209
+ * @node: device node for the clock
201210 */
202211 void __init of_fixed_factor_clk_setup(struct device_node *node)
203212 {
....@@ -208,17 +217,17 @@
208217
209218 static int of_fixed_factor_clk_remove(struct platform_device *pdev)
210219 {
211
- struct clk *clk = platform_get_drvdata(pdev);
220
+ struct clk_hw *clk = platform_get_drvdata(pdev);
212221
213222 of_clk_del_provider(pdev->dev.of_node);
214
- clk_unregister_fixed_factor(clk);
223
+ clk_hw_unregister_fixed_factor(clk);
215224
216225 return 0;
217226 }
218227
219228 static int of_fixed_factor_clk_probe(struct platform_device *pdev)
220229 {
221
- struct clk *clk;
230
+ struct clk_hw *clk;
222231
223232 /*
224233 * This function is not executed when of_fixed_factor_clk_setup