2 * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
3 * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
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.
9 * Fixed rate clock implementation
12 #include <linux/clk-provider.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
16 #include <linux/err.h>
20 * DOC: basic fixed-rate clock that cannot gate
22 * Traits of this clock:
23 * prepare - clk_(un)prepare only ensures parents are prepared
24 * enable - clk_enable only ensures parents are enabled
25 * rate - rate is always a fixed value. No clk_set_rate support
26 * parent - fixed parent. No clk_set_parent support
29 #define to_clk_fixed_rate(_hw) container_of(_hw, struct clk_fixed_rate, hw)
31 static unsigned long clk_fixed_rate_recalc_rate(struct clk_hw
*hw
,
32 unsigned long parent_rate
)
34 return to_clk_fixed_rate(hw
)->fixed_rate
;
37 static unsigned long clk_fixed_rate_recalc_accuracy(struct clk_hw
*hw
,
38 unsigned long parent_accuracy
)
40 return to_clk_fixed_rate(hw
)->fixed_accuracy
;
43 const struct clk_ops clk_fixed_rate_ops
= {
44 .recalc_rate
= clk_fixed_rate_recalc_rate
,
45 .recalc_accuracy
= clk_fixed_rate_recalc_accuracy
,
47 EXPORT_SYMBOL_GPL(clk_fixed_rate_ops
);
50 * clk_register_fixed_rate_with_accuracy - register fixed-rate clock with the
52 * @dev: device that is registering this clock
53 * @name: name of this clock
54 * @parent_name: name of clock's parent
55 * @flags: framework-specific flags
56 * @fixed_rate: non-adjustable clock rate
57 * @fixed_accuracy: non-adjustable clock rate
59 struct 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
)
63 struct clk_fixed_rate
*fixed
;
65 struct clk_init_data init
;
67 /* allocate fixed-rate clock */
68 fixed
= kzalloc(sizeof(*fixed
), GFP_KERNEL
);
70 return ERR_PTR(-ENOMEM
);
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);
78 /* struct clk_fixed_rate assignments */
79 fixed
->fixed_rate
= fixed_rate
;
80 fixed
->fixed_accuracy
= fixed_accuracy
;
81 fixed
->hw
.init
= &init
;
83 /* register the clock */
84 clk
= clk_register(dev
, &fixed
->hw
);
90 EXPORT_SYMBOL_GPL(clk_register_fixed_rate_with_accuracy
);
93 * clk_register_fixed_rate - register fixed-rate clock with the clock framework
94 * @dev: device that is registering this clock
95 * @name: name of this clock
96 * @parent_name: name of clock's parent
97 * @flags: framework-specific flags
98 * @fixed_rate: non-adjustable clock rate
100 struct clk
*clk_register_fixed_rate(struct device
*dev
, const char *name
,
101 const char *parent_name
, unsigned long flags
,
102 unsigned long fixed_rate
)
104 return clk_register_fixed_rate_with_accuracy(dev
, name
, parent_name
,
105 flags
, fixed_rate
, 0);
107 EXPORT_SYMBOL_GPL(clk_register_fixed_rate
);
111 * of_fixed_clk_setup() - Setup function for simple fixed rate clock
113 void of_fixed_clk_setup(struct device_node
*node
)
116 const char *clk_name
= node
->name
;
120 if (of_property_read_u32(node
, "clock-frequency", &rate
))
123 of_property_read_u32(node
, "clock-accuracy", &accuracy
);
125 of_property_read_string(node
, "clock-output-names", &clk_name
);
127 clk
= clk_register_fixed_rate_with_accuracy(NULL
, clk_name
, NULL
,
131 of_clk_add_provider(node
, of_clk_src_simple_get
, clk
);
133 EXPORT_SYMBOL_GPL(of_fixed_clk_setup
);
134 CLK_OF_DECLARE(fixed_clk
, "fixed-clock", of_fixed_clk_setup
);