hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/clk/clk-fixed-rate.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
34 * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
85 *
96 * Fixed rate clock implementation
107 */
....@@ -27,6 +24,8 @@
2724 * parent - fixed parent. No clk_set_parent support
2825 */
2926
27
+#define to_clk_fixed_rate(_hw) container_of(_hw, struct clk_fixed_rate, hw)
28
+
3029 static unsigned long clk_fixed_rate_recalc_rate(struct clk_hw *hw,
3130 unsigned long parent_rate)
3231 {
....@@ -36,7 +35,12 @@
3635 static unsigned long clk_fixed_rate_recalc_accuracy(struct clk_hw *hw,
3736 unsigned long parent_accuracy)
3837 {
39
- return to_clk_fixed_rate(hw)->fixed_accuracy;
38
+ struct clk_fixed_rate *fixed = to_clk_fixed_rate(hw);
39
+
40
+ if (fixed->flags & CLK_FIXED_RATE_PARENT_ACCURACY)
41
+ return parent_accuracy;
42
+
43
+ return fixed->fixed_accuracy;
4044 }
4145
4246 const struct clk_ops clk_fixed_rate_ops = {
....@@ -45,24 +49,17 @@
4549 };
4650 EXPORT_SYMBOL_GPL(clk_fixed_rate_ops);
4751
48
-/**
49
- * clk_hw_register_fixed_rate_with_accuracy - register fixed-rate clock with
50
- * the clock framework
51
- * @dev: device that is registering this clock
52
- * @name: name of this clock
53
- * @parent_name: name of clock's parent
54
- * @flags: framework-specific flags
55
- * @fixed_rate: non-adjustable clock rate
56
- * @fixed_accuracy: non-adjustable clock rate
57
- */
58
-struct clk_hw *clk_hw_register_fixed_rate_with_accuracy(struct device *dev,
59
- const char *name, const char *parent_name, unsigned long flags,
60
- unsigned long fixed_rate, unsigned long fixed_accuracy)
52
+struct clk_hw *__clk_hw_register_fixed_rate(struct device *dev,
53
+ struct device_node *np, const char *name,
54
+ const char *parent_name, const struct clk_hw *parent_hw,
55
+ const struct clk_parent_data *parent_data, unsigned long flags,
56
+ unsigned long fixed_rate, unsigned long fixed_accuracy,
57
+ unsigned long clk_fixed_flags)
6158 {
6259 struct clk_fixed_rate *fixed;
6360 struct clk_hw *hw;
6461 struct clk_init_data init = {};
65
- int ret;
62
+ int ret = -EINVAL;
6663
6764 /* allocate fixed-rate clock */
6865 fixed = kzalloc(sizeof(*fixed), GFP_KERNEL);
....@@ -71,18 +68,27 @@
7168
7269 init.name = name;
7370 init.ops = &clk_fixed_rate_ops;
74
- init.flags = flags | CLK_IS_BASIC;
75
- init.parent_names = (parent_name ? &parent_name: NULL);
76
- init.num_parents = (parent_name ? 1 : 0);
71
+ init.flags = flags;
72
+ init.parent_names = parent_name ? &parent_name : NULL;
73
+ init.parent_hws = parent_hw ? &parent_hw : NULL;
74
+ init.parent_data = parent_data;
75
+ if (parent_name || parent_hw || parent_data)
76
+ init.num_parents = 1;
77
+ else
78
+ init.num_parents = 0;
7779
7880 /* struct clk_fixed_rate assignments */
81
+ fixed->flags = clk_fixed_flags;
7982 fixed->fixed_rate = fixed_rate;
8083 fixed->fixed_accuracy = fixed_accuracy;
8184 fixed->hw.init = &init;
8285
8386 /* register the clock */
8487 hw = &fixed->hw;
85
- ret = clk_hw_register(dev, hw);
88
+ if (dev || !np)
89
+ ret = clk_hw_register(dev, hw);
90
+ else if (np)
91
+ ret = of_clk_hw_register(np, hw);
8692 if (ret) {
8793 kfree(fixed);
8894 hw = ERR_PTR(ret);
....@@ -90,46 +96,19 @@
9096
9197 return hw;
9298 }
93
-EXPORT_SYMBOL_GPL(clk_hw_register_fixed_rate_with_accuracy);
94
-
95
-struct clk *clk_register_fixed_rate_with_accuracy(struct device *dev,
96
- const char *name, const char *parent_name, unsigned long flags,
97
- unsigned long fixed_rate, unsigned long fixed_accuracy)
98
-{
99
- struct clk_hw *hw;
100
-
101
- hw = clk_hw_register_fixed_rate_with_accuracy(dev, name, parent_name,
102
- flags, fixed_rate, fixed_accuracy);
103
- if (IS_ERR(hw))
104
- return ERR_CAST(hw);
105
- return hw->clk;
106
-}
107
-EXPORT_SYMBOL_GPL(clk_register_fixed_rate_with_accuracy);
108
-
109
-/**
110
- * clk_hw_register_fixed_rate - register fixed-rate clock with the clock
111
- * framework
112
- * @dev: device that is registering this clock
113
- * @name: name of this clock
114
- * @parent_name: name of clock's parent
115
- * @flags: framework-specific flags
116
- * @fixed_rate: non-adjustable clock rate
117
- */
118
-struct clk_hw *clk_hw_register_fixed_rate(struct device *dev, const char *name,
119
- const char *parent_name, unsigned long flags,
120
- unsigned long fixed_rate)
121
-{
122
- return clk_hw_register_fixed_rate_with_accuracy(dev, name, parent_name,
123
- flags, fixed_rate, 0);
124
-}
125
-EXPORT_SYMBOL_GPL(clk_hw_register_fixed_rate);
99
+EXPORT_SYMBOL_GPL(__clk_hw_register_fixed_rate);
126100
127101 struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
128102 const char *parent_name, unsigned long flags,
129103 unsigned long fixed_rate)
130104 {
131
- return clk_register_fixed_rate_with_accuracy(dev, name, parent_name,
132
- flags, fixed_rate, 0);
105
+ struct clk_hw *hw;
106
+
107
+ hw = clk_hw_register_fixed_rate_with_accuracy(dev, name, parent_name,
108
+ flags, fixed_rate, 0);
109
+ if (IS_ERR(hw))
110
+ return ERR_CAST(hw);
111
+ return hw->clk;
133112 }
134113 EXPORT_SYMBOL_GPL(clk_register_fixed_rate);
135114
....@@ -158,9 +137,9 @@
158137 EXPORT_SYMBOL_GPL(clk_hw_unregister_fixed_rate);
159138
160139 #ifdef CONFIG_OF
161
-static struct clk *_of_fixed_clk_setup(struct device_node *node)
140
+static struct clk_hw *_of_fixed_clk_setup(struct device_node *node)
162141 {
163
- struct clk *clk;
142
+ struct clk_hw *hw;
164143 const char *clk_name = node->name;
165144 u32 rate;
166145 u32 accuracy = 0;
....@@ -173,22 +152,23 @@
173152
174153 of_property_read_string(node, "clock-output-names", &clk_name);
175154
176
- clk = clk_register_fixed_rate_with_accuracy(NULL, clk_name, NULL,
155
+ hw = clk_hw_register_fixed_rate_with_accuracy(NULL, clk_name, NULL,
177156 0, rate, accuracy);
178
- if (IS_ERR(clk))
179
- return clk;
157
+ if (IS_ERR(hw))
158
+ return hw;
180159
181
- ret = of_clk_add_provider(node, of_clk_src_simple_get, clk);
160
+ ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, hw);
182161 if (ret) {
183
- clk_unregister(clk);
162
+ clk_hw_unregister_fixed_rate(hw);
184163 return ERR_PTR(ret);
185164 }
186165
187
- return clk;
166
+ return hw;
188167 }
189168
190169 /**
191170 * of_fixed_clk_setup() - Setup function for simple fixed rate clock
171
+ * @node: device node for the clock
192172 */
193173 void __init of_fixed_clk_setup(struct device_node *node)
194174 {
....@@ -198,27 +178,27 @@
198178
199179 static int of_fixed_clk_remove(struct platform_device *pdev)
200180 {
201
- struct clk *clk = platform_get_drvdata(pdev);
181
+ struct clk_hw *hw = platform_get_drvdata(pdev);
202182
203183 of_clk_del_provider(pdev->dev.of_node);
204
- clk_unregister_fixed_rate(clk);
184
+ clk_hw_unregister_fixed_rate(hw);
205185
206186 return 0;
207187 }
208188
209189 static int of_fixed_clk_probe(struct platform_device *pdev)
210190 {
211
- struct clk *clk;
191
+ struct clk_hw *hw;
212192
213193 /*
214194 * This function is not executed when of_fixed_clk_setup
215195 * succeeded.
216196 */
217
- clk = _of_fixed_clk_setup(pdev->dev.of_node);
218
- if (IS_ERR(clk))
219
- return PTR_ERR(clk);
197
+ hw = _of_fixed_clk_setup(pdev->dev.of_node);
198
+ if (IS_ERR(hw))
199
+ return PTR_ERR(hw);
220200
221
- platform_set_drvdata(pdev, clk);
201
+ platform_set_drvdata(pdev, hw);
222202
223203 return 0;
224204 }
....@@ -227,7 +207,6 @@
227207 { .compatible = "fixed-clock" },
228208 { }
229209 };
230
-MODULE_DEVICE_TABLE(of, of_fixed_clk_ids);
231210
232211 static struct platform_driver of_fixed_clk_driver = {
233212 .driver = {