.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com> |
---|
3 | 4 | * 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. |
---|
8 | 5 | * |
---|
9 | 6 | * Fixed rate clock implementation |
---|
10 | 7 | */ |
---|
.. | .. |
---|
27 | 24 | * parent - fixed parent. No clk_set_parent support |
---|
28 | 25 | */ |
---|
29 | 26 | |
---|
| 27 | +#define to_clk_fixed_rate(_hw) container_of(_hw, struct clk_fixed_rate, hw) |
---|
| 28 | + |
---|
30 | 29 | static unsigned long clk_fixed_rate_recalc_rate(struct clk_hw *hw, |
---|
31 | 30 | unsigned long parent_rate) |
---|
32 | 31 | { |
---|
.. | .. |
---|
36 | 35 | static unsigned long clk_fixed_rate_recalc_accuracy(struct clk_hw *hw, |
---|
37 | 36 | unsigned long parent_accuracy) |
---|
38 | 37 | { |
---|
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; |
---|
40 | 44 | } |
---|
41 | 45 | |
---|
42 | 46 | const struct clk_ops clk_fixed_rate_ops = { |
---|
.. | .. |
---|
45 | 49 | }; |
---|
46 | 50 | EXPORT_SYMBOL_GPL(clk_fixed_rate_ops); |
---|
47 | 51 | |
---|
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) |
---|
61 | 58 | { |
---|
62 | 59 | struct clk_fixed_rate *fixed; |
---|
63 | 60 | struct clk_hw *hw; |
---|
64 | 61 | struct clk_init_data init = {}; |
---|
65 | | - int ret; |
---|
| 62 | + int ret = -EINVAL; |
---|
66 | 63 | |
---|
67 | 64 | /* allocate fixed-rate clock */ |
---|
68 | 65 | fixed = kzalloc(sizeof(*fixed), GFP_KERNEL); |
---|
.. | .. |
---|
71 | 68 | |
---|
72 | 69 | init.name = name; |
---|
73 | 70 | 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; |
---|
77 | 79 | |
---|
78 | 80 | /* struct clk_fixed_rate assignments */ |
---|
| 81 | + fixed->flags = clk_fixed_flags; |
---|
79 | 82 | fixed->fixed_rate = fixed_rate; |
---|
80 | 83 | fixed->fixed_accuracy = fixed_accuracy; |
---|
81 | 84 | fixed->hw.init = &init; |
---|
82 | 85 | |
---|
83 | 86 | /* register the clock */ |
---|
84 | 87 | 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); |
---|
86 | 92 | if (ret) { |
---|
87 | 93 | kfree(fixed); |
---|
88 | 94 | hw = ERR_PTR(ret); |
---|
.. | .. |
---|
90 | 96 | |
---|
91 | 97 | return hw; |
---|
92 | 98 | } |
---|
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); |
---|
126 | 100 | |
---|
127 | 101 | struct clk *clk_register_fixed_rate(struct device *dev, const char *name, |
---|
128 | 102 | const char *parent_name, unsigned long flags, |
---|
129 | 103 | unsigned long fixed_rate) |
---|
130 | 104 | { |
---|
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; |
---|
133 | 112 | } |
---|
134 | 113 | EXPORT_SYMBOL_GPL(clk_register_fixed_rate); |
---|
135 | 114 | |
---|
.. | .. |
---|
158 | 137 | EXPORT_SYMBOL_GPL(clk_hw_unregister_fixed_rate); |
---|
159 | 138 | |
---|
160 | 139 | #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) |
---|
162 | 141 | { |
---|
163 | | - struct clk *clk; |
---|
| 142 | + struct clk_hw *hw; |
---|
164 | 143 | const char *clk_name = node->name; |
---|
165 | 144 | u32 rate; |
---|
166 | 145 | u32 accuracy = 0; |
---|
.. | .. |
---|
173 | 152 | |
---|
174 | 153 | of_property_read_string(node, "clock-output-names", &clk_name); |
---|
175 | 154 | |
---|
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, |
---|
177 | 156 | 0, rate, accuracy); |
---|
178 | | - if (IS_ERR(clk)) |
---|
179 | | - return clk; |
---|
| 157 | + if (IS_ERR(hw)) |
---|
| 158 | + return hw; |
---|
180 | 159 | |
---|
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); |
---|
182 | 161 | if (ret) { |
---|
183 | | - clk_unregister(clk); |
---|
| 162 | + clk_hw_unregister_fixed_rate(hw); |
---|
184 | 163 | return ERR_PTR(ret); |
---|
185 | 164 | } |
---|
186 | 165 | |
---|
187 | | - return clk; |
---|
| 166 | + return hw; |
---|
188 | 167 | } |
---|
189 | 168 | |
---|
190 | 169 | /** |
---|
191 | 170 | * of_fixed_clk_setup() - Setup function for simple fixed rate clock |
---|
| 171 | + * @node: device node for the clock |
---|
192 | 172 | */ |
---|
193 | 173 | void __init of_fixed_clk_setup(struct device_node *node) |
---|
194 | 174 | { |
---|
.. | .. |
---|
198 | 178 | |
---|
199 | 179 | static int of_fixed_clk_remove(struct platform_device *pdev) |
---|
200 | 180 | { |
---|
201 | | - struct clk *clk = platform_get_drvdata(pdev); |
---|
| 181 | + struct clk_hw *hw = platform_get_drvdata(pdev); |
---|
202 | 182 | |
---|
203 | 183 | of_clk_del_provider(pdev->dev.of_node); |
---|
204 | | - clk_unregister_fixed_rate(clk); |
---|
| 184 | + clk_hw_unregister_fixed_rate(hw); |
---|
205 | 185 | |
---|
206 | 186 | return 0; |
---|
207 | 187 | } |
---|
208 | 188 | |
---|
209 | 189 | static int of_fixed_clk_probe(struct platform_device *pdev) |
---|
210 | 190 | { |
---|
211 | | - struct clk *clk; |
---|
| 191 | + struct clk_hw *hw; |
---|
212 | 192 | |
---|
213 | 193 | /* |
---|
214 | 194 | * This function is not executed when of_fixed_clk_setup |
---|
215 | 195 | * succeeded. |
---|
216 | 196 | */ |
---|
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); |
---|
220 | 200 | |
---|
221 | | - platform_set_drvdata(pdev, clk); |
---|
| 201 | + platform_set_drvdata(pdev, hw); |
---|
222 | 202 | |
---|
223 | 203 | return 0; |
---|
224 | 204 | } |
---|
.. | .. |
---|
227 | 207 | { .compatible = "fixed-clock" }, |
---|
228 | 208 | { } |
---|
229 | 209 | }; |
---|
230 | | -MODULE_DEVICE_TABLE(of, of_fixed_clk_ids); |
---|
231 | 210 | |
---|
232 | 211 | static struct platform_driver of_fixed_clk_driver = { |
---|
233 | 212 | .driver = { |
---|