1
2
3
4
5
6
7
8
9
10
11
12#include <linux/clk-provider.h>
13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/io.h>
16#include <linux/err.h>
17#include <linux/of.h>
18
19
20
21
22
23
24
25
26
27
28
29#define to_clk_fixed_rate(_hw) container_of(_hw, struct clk_fixed_rate, hw)
30
31static unsigned long clk_fixed_rate_recalc_rate(struct clk_hw *hw,
32 unsigned long parent_rate)
33{
34 return to_clk_fixed_rate(hw)->fixed_rate;
35}
36
37static unsigned long clk_fixed_rate_recalc_accuracy(struct clk_hw *hw,
38 unsigned long parent_accuracy)
39{
40 return to_clk_fixed_rate(hw)->fixed_accuracy;
41}
42
43const struct clk_ops clk_fixed_rate_ops = {
44 .recalc_rate = clk_fixed_rate_recalc_rate,
45 .recalc_accuracy = clk_fixed_rate_recalc_accuracy,
46};
47EXPORT_SYMBOL_GPL(clk_fixed_rate_ops);
48
49
50
51
52
53
54
55
56
57
58
59struct clk *clk_register_fixed_rate_with_accuracy(struct device *dev,
60 const char *name, const char *parent_name, unsigned long flags,
61 unsigned long fixed_rate, unsigned long fixed_accuracy)
62{
63 struct clk_fixed_rate *fixed;
64 struct clk *clk;
65 struct clk_init_data init;
66
67
68 fixed = kzalloc(sizeof(*fixed), GFP_KERNEL);
69 if (!fixed)
70 return ERR_PTR(-ENOMEM);
71
72 init.name = name;
73 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);
77
78
79 fixed->fixed_rate = fixed_rate;
80 fixed->fixed_accuracy = fixed_accuracy;
81 fixed->hw.init = &init;
82
83
84 clk = clk_register(dev, &fixed->hw);
85 if (IS_ERR(clk))
86 kfree(fixed);
87
88 return clk;
89}
90EXPORT_SYMBOL_GPL(clk_register_fixed_rate_with_accuracy);
91
92
93
94
95
96
97
98
99
100struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
101 const char *parent_name, unsigned long flags,
102 unsigned long fixed_rate)
103{
104 return clk_register_fixed_rate_with_accuracy(dev, name, parent_name,
105 flags, fixed_rate, 0);
106}
107EXPORT_SYMBOL_GPL(clk_register_fixed_rate);
108
109#ifdef CONFIG_OF
110
111
112
113void of_fixed_clk_setup(struct device_node *node)
114{
115 struct clk *clk;
116 const char *clk_name = node->name;
117 u32 rate;
118 u32 accuracy = 0;
119
120 if (of_property_read_u32(node, "clock-frequency", &rate))
121 return;
122
123 of_property_read_u32(node, "clock-accuracy", &accuracy);
124
125 of_property_read_string(node, "clock-output-names", &clk_name);
126
127 clk = clk_register_fixed_rate_with_accuracy(NULL, clk_name, NULL,
128 CLK_IS_ROOT, rate,
129 accuracy);
130 if (!IS_ERR(clk))
131 of_clk_add_provider(node, of_clk_src_simple_get, clk);
132}
133EXPORT_SYMBOL_GPL(of_fixed_clk_setup);
134CLK_OF_DECLARE(fixed_clk, "fixed-clock", of_fixed_clk_setup);
135#endif
136