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
37const struct clk_ops clk_fixed_rate_ops = {
38 .recalc_rate = clk_fixed_rate_recalc_rate,
39};
40EXPORT_SYMBOL_GPL(clk_fixed_rate_ops);
41
42
43
44
45
46
47
48
49
50struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
51 const char *parent_name, unsigned long flags,
52 unsigned long fixed_rate)
53{
54 struct clk_fixed_rate *fixed;
55 struct clk *clk;
56 struct clk_init_data init;
57
58
59 fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
60 if (!fixed) {
61 pr_err("%s: could not allocate fixed clk\n", __func__);
62 return ERR_PTR(-ENOMEM);
63 }
64
65 init.name = name;
66 init.ops = &clk_fixed_rate_ops;
67 init.flags = flags | CLK_IS_BASIC;
68 init.parent_names = (parent_name ? &parent_name: NULL);
69 init.num_parents = (parent_name ? 1 : 0);
70
71
72 fixed->fixed_rate = fixed_rate;
73 fixed->hw.init = &init;
74
75
76 clk = clk_register(dev, &fixed->hw);
77
78 if (IS_ERR(clk))
79 kfree(fixed);
80
81 return clk;
82}
83EXPORT_SYMBOL_GPL(clk_register_fixed_rate);
84
85#ifdef CONFIG_OF
86
87
88
89void of_fixed_clk_setup(struct device_node *node)
90{
91 struct clk *clk;
92 const char *clk_name = node->name;
93 u32 rate;
94
95 if (of_property_read_u32(node, "clock-frequency", &rate))
96 return;
97
98 of_property_read_string(node, "clock-output-names", &clk_name);
99
100 clk = clk_register_fixed_rate(NULL, clk_name, NULL, CLK_IS_ROOT, rate);
101 if (!IS_ERR(clk))
102 of_clk_add_provider(node, of_clk_src_simple_get, clk);
103}
104EXPORT_SYMBOL_GPL(of_fixed_clk_setup);
105CLK_OF_DECLARE(fixed_clk, "fixed-clock", of_fixed_clk_setup);
106#endif
107