diff options
Diffstat (limited to 'include/linux/clk-provider.h')
-rw-r--r-- | include/linux/clk-provider.h | 118 |
1 files changed, 77 insertions, 41 deletions
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 5508897ad376..c1c23b9ec368 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h | |||
@@ -15,19 +15,6 @@ | |||
15 | 15 | ||
16 | #ifdef CONFIG_COMMON_CLK | 16 | #ifdef CONFIG_COMMON_CLK |
17 | 17 | ||
18 | /** | ||
19 | * struct clk_hw - handle for traversing from a struct clk to its corresponding | ||
20 | * hardware-specific structure. struct clk_hw should be declared within struct | ||
21 | * clk_foo and then referenced by the struct clk instance that uses struct | ||
22 | * clk_foo's clk_ops | ||
23 | * | ||
24 | * clk: pointer to the struct clk instance that points back to this struct | ||
25 | * clk_hw instance | ||
26 | */ | ||
27 | struct clk_hw { | ||
28 | struct clk *clk; | ||
29 | }; | ||
30 | |||
31 | /* | 18 | /* |
32 | * flags used across common struct clk. these flags should only affect the | 19 | * flags used across common struct clk. these flags should only affect the |
33 | * top-level framework. custom flags for dealing with hardware specifics | 20 | * top-level framework. custom flags for dealing with hardware specifics |
@@ -39,6 +26,8 @@ struct clk_hw { | |||
39 | #define CLK_IGNORE_UNUSED BIT(3) /* do not gate even if unused */ | 26 | #define CLK_IGNORE_UNUSED BIT(3) /* do not gate even if unused */ |
40 | #define CLK_IS_ROOT BIT(4) /* root clk, has no parent */ | 27 | #define CLK_IS_ROOT BIT(4) /* root clk, has no parent */ |
41 | 28 | ||
29 | struct clk_hw; | ||
30 | |||
42 | /** | 31 | /** |
43 | * struct clk_ops - Callback operations for hardware clocks; these are to | 32 | * struct clk_ops - Callback operations for hardware clocks; these are to |
44 | * be provided by the clock implementation, and will be called by drivers | 33 | * be provided by the clock implementation, and will be called by drivers |
@@ -88,19 +77,11 @@ struct clk_hw { | |||
88 | * array index into the value programmed into the hardware. | 77 | * array index into the value programmed into the hardware. |
89 | * Returns 0 on success, -EERROR otherwise. | 78 | * Returns 0 on success, -EERROR otherwise. |
90 | * | 79 | * |
91 | * @set_rate: Change the rate of this clock. If this callback returns | 80 | * @set_rate: Change the rate of this clock. The requested rate is specified |
92 | * CLK_SET_RATE_PARENT, the rate change will be propagated to the | 81 | * by the second argument, which should typically be the return |
93 | * parent clock (which may propagate again if the parent clock | 82 | * of .round_rate call. The third argument gives the parent rate |
94 | * also sets this flag). The requested rate of the parent is | 83 | * which is likely helpful for most .set_rate implementation. |
95 | * passed back from the callback in the second 'unsigned long *' | 84 | * Returns 0 on success, -EERROR otherwise. |
96 | * argument. Note that it is up to the hardware clock's set_rate | ||
97 | * implementation to insure that clocks do not run out of spec | ||
98 | * when propgating the call to set_rate up to the parent. One way | ||
99 | * to do this is to gate the clock (via clk_disable and/or | ||
100 | * clk_unprepare) before calling clk_set_rate, then ungating it | ||
101 | * afterward. If your clock also has the CLK_GATE_SET_RATE flag | ||
102 | * set then this will insure safety. Returns 0 on success, | ||
103 | * -EERROR otherwise. | ||
104 | * | 85 | * |
105 | * The clk_enable/clk_disable and clk_prepare/clk_unprepare pairs allow | 86 | * The clk_enable/clk_disable and clk_prepare/clk_unprepare pairs allow |
106 | * implementations to split any work between atomic (enable) and sleepable | 87 | * implementations to split any work between atomic (enable) and sleepable |
@@ -125,10 +106,46 @@ struct clk_ops { | |||
125 | unsigned long *); | 106 | unsigned long *); |
126 | int (*set_parent)(struct clk_hw *hw, u8 index); | 107 | int (*set_parent)(struct clk_hw *hw, u8 index); |
127 | u8 (*get_parent)(struct clk_hw *hw); | 108 | u8 (*get_parent)(struct clk_hw *hw); |
128 | int (*set_rate)(struct clk_hw *hw, unsigned long); | 109 | int (*set_rate)(struct clk_hw *hw, unsigned long, |
110 | unsigned long); | ||
129 | void (*init)(struct clk_hw *hw); | 111 | void (*init)(struct clk_hw *hw); |
130 | }; | 112 | }; |
131 | 113 | ||
114 | /** | ||
115 | * struct clk_init_data - holds init data that's common to all clocks and is | ||
116 | * shared between the clock provider and the common clock framework. | ||
117 | * | ||
118 | * @name: clock name | ||
119 | * @ops: operations this clock supports | ||
120 | * @parent_names: array of string names for all possible parents | ||
121 | * @num_parents: number of possible parents | ||
122 | * @flags: framework-level hints and quirks | ||
123 | */ | ||
124 | struct clk_init_data { | ||
125 | const char *name; | ||
126 | const struct clk_ops *ops; | ||
127 | const char **parent_names; | ||
128 | u8 num_parents; | ||
129 | unsigned long flags; | ||
130 | }; | ||
131 | |||
132 | /** | ||
133 | * struct clk_hw - handle for traversing from a struct clk to its corresponding | ||
134 | * hardware-specific structure. struct clk_hw should be declared within struct | ||
135 | * clk_foo and then referenced by the struct clk instance that uses struct | ||
136 | * clk_foo's clk_ops | ||
137 | * | ||
138 | * @clk: pointer to the struct clk instance that points back to this struct | ||
139 | * clk_hw instance | ||
140 | * | ||
141 | * @init: pointer to struct clk_init_data that contains the init data shared | ||
142 | * with the common clock framework. | ||
143 | */ | ||
144 | struct clk_hw { | ||
145 | struct clk *clk; | ||
146 | struct clk_init_data *init; | ||
147 | }; | ||
148 | |||
132 | /* | 149 | /* |
133 | * DOC: Basic clock implementations common to many platforms | 150 | * DOC: Basic clock implementations common to many platforms |
134 | * | 151 | * |
@@ -149,6 +166,7 @@ struct clk_fixed_rate { | |||
149 | u8 flags; | 166 | u8 flags; |
150 | }; | 167 | }; |
151 | 168 | ||
169 | extern const struct clk_ops clk_fixed_rate_ops; | ||
152 | struct clk *clk_register_fixed_rate(struct device *dev, const char *name, | 170 | struct clk *clk_register_fixed_rate(struct device *dev, const char *name, |
153 | const char *parent_name, unsigned long flags, | 171 | const char *parent_name, unsigned long flags, |
154 | unsigned long fixed_rate); | 172 | unsigned long fixed_rate); |
@@ -165,7 +183,7 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name, | |||
165 | * Clock which can gate its output. Implements .enable & .disable | 183 | * Clock which can gate its output. Implements .enable & .disable |
166 | * | 184 | * |
167 | * Flags: | 185 | * Flags: |
168 | * CLK_GATE_SET_DISABLE - by default this clock sets the bit at bit_idx to | 186 | * CLK_GATE_SET_TO_DISABLE - by default this clock sets the bit at bit_idx to |
169 | * enable the clock. Setting this flag does the opposite: setting the bit | 187 | * enable the clock. Setting this flag does the opposite: setting the bit |
170 | * disable the clock and clearing it enables the clock | 188 | * disable the clock and clearing it enables the clock |
171 | */ | 189 | */ |
@@ -175,11 +193,11 @@ struct clk_gate { | |||
175 | u8 bit_idx; | 193 | u8 bit_idx; |
176 | u8 flags; | 194 | u8 flags; |
177 | spinlock_t *lock; | 195 | spinlock_t *lock; |
178 | char *parent[1]; | ||
179 | }; | 196 | }; |
180 | 197 | ||
181 | #define CLK_GATE_SET_TO_DISABLE BIT(0) | 198 | #define CLK_GATE_SET_TO_DISABLE BIT(0) |
182 | 199 | ||
200 | extern const struct clk_ops clk_gate_ops; | ||
183 | struct clk *clk_register_gate(struct device *dev, const char *name, | 201 | struct clk *clk_register_gate(struct device *dev, const char *name, |
184 | const char *parent_name, unsigned long flags, | 202 | const char *parent_name, unsigned long flags, |
185 | void __iomem *reg, u8 bit_idx, | 203 | void __iomem *reg, u8 bit_idx, |
@@ -212,12 +230,12 @@ struct clk_divider { | |||
212 | u8 width; | 230 | u8 width; |
213 | u8 flags; | 231 | u8 flags; |
214 | spinlock_t *lock; | 232 | spinlock_t *lock; |
215 | char *parent[1]; | ||
216 | }; | 233 | }; |
217 | 234 | ||
218 | #define CLK_DIVIDER_ONE_BASED BIT(0) | 235 | #define CLK_DIVIDER_ONE_BASED BIT(0) |
219 | #define CLK_DIVIDER_POWER_OF_TWO BIT(1) | 236 | #define CLK_DIVIDER_POWER_OF_TWO BIT(1) |
220 | 237 | ||
238 | extern const struct clk_ops clk_divider_ops; | ||
221 | struct clk *clk_register_divider(struct device *dev, const char *name, | 239 | struct clk *clk_register_divider(struct device *dev, const char *name, |
222 | const char *parent_name, unsigned long flags, | 240 | const char *parent_name, unsigned long flags, |
223 | void __iomem *reg, u8 shift, u8 width, | 241 | void __iomem *reg, u8 shift, u8 width, |
@@ -238,7 +256,7 @@ struct clk *clk_register_divider(struct device *dev, const char *name, | |||
238 | * | 256 | * |
239 | * Flags: | 257 | * Flags: |
240 | * CLK_MUX_INDEX_ONE - register index starts at 1, not 0 | 258 | * CLK_MUX_INDEX_ONE - register index starts at 1, not 0 |
241 | * CLK_MUX_INDEX_BITWISE - register index is a single bit (power of two) | 259 | * CLK_MUX_INDEX_BIT - register index is a single bit (power of two) |
242 | */ | 260 | */ |
243 | struct clk_mux { | 261 | struct clk_mux { |
244 | struct clk_hw hw; | 262 | struct clk_hw hw; |
@@ -252,29 +270,47 @@ struct clk_mux { | |||
252 | #define CLK_MUX_INDEX_ONE BIT(0) | 270 | #define CLK_MUX_INDEX_ONE BIT(0) |
253 | #define CLK_MUX_INDEX_BIT BIT(1) | 271 | #define CLK_MUX_INDEX_BIT BIT(1) |
254 | 272 | ||
273 | extern const struct clk_ops clk_mux_ops; | ||
255 | struct clk *clk_register_mux(struct device *dev, const char *name, | 274 | struct clk *clk_register_mux(struct device *dev, const char *name, |
256 | char **parent_names, u8 num_parents, unsigned long flags, | 275 | const char **parent_names, u8 num_parents, unsigned long flags, |
257 | void __iomem *reg, u8 shift, u8 width, | 276 | void __iomem *reg, u8 shift, u8 width, |
258 | u8 clk_mux_flags, spinlock_t *lock); | 277 | u8 clk_mux_flags, spinlock_t *lock); |
259 | 278 | ||
260 | /** | 279 | /** |
280 | * struct clk_fixed_factor - fixed multiplier and divider clock | ||
281 | * | ||
282 | * @hw: handle between common and hardware-specific interfaces | ||
283 | * @mult: multiplier | ||
284 | * @div: divider | ||
285 | * | ||
286 | * Clock with a fixed multiplier and divider. The output frequency is the | ||
287 | * parent clock rate divided by div and multiplied by mult. | ||
288 | * Implements .recalc_rate, .set_rate and .round_rate | ||
289 | */ | ||
290 | |||
291 | struct clk_fixed_factor { | ||
292 | struct clk_hw hw; | ||
293 | unsigned int mult; | ||
294 | unsigned int div; | ||
295 | }; | ||
296 | |||
297 | extern struct clk_ops clk_fixed_factor_ops; | ||
298 | struct clk *clk_register_fixed_factor(struct device *dev, const char *name, | ||
299 | const char *parent_name, unsigned long flags, | ||
300 | unsigned int mult, unsigned int div); | ||
301 | |||
302 | /** | ||
261 | * clk_register - allocate a new clock, register it and return an opaque cookie | 303 | * clk_register - allocate a new clock, register it and return an opaque cookie |
262 | * @dev: device that is registering this clock | 304 | * @dev: device that is registering this clock |
263 | * @name: clock name | ||
264 | * @ops: operations this clock supports | ||
265 | * @hw: link to hardware-specific clock data | 305 | * @hw: link to hardware-specific clock data |
266 | * @parent_names: array of string names for all possible parents | ||
267 | * @num_parents: number of possible parents | ||
268 | * @flags: framework-level hints and quirks | ||
269 | * | 306 | * |
270 | * clk_register is the primary interface for populating the clock tree with new | 307 | * clk_register is the primary interface for populating the clock tree with new |
271 | * clock nodes. It returns a pointer to the newly allocated struct clk which | 308 | * clock nodes. It returns a pointer to the newly allocated struct clk which |
272 | * cannot be dereferenced by driver code but may be used in conjuction with the | 309 | * cannot be dereferenced by driver code but may be used in conjuction with the |
273 | * rest of the clock API. | 310 | * rest of the clock API. In the event of an error clk_register will return an |
311 | * error code; drivers must test for an error code after calling clk_register. | ||
274 | */ | 312 | */ |
275 | struct clk *clk_register(struct device *dev, const char *name, | 313 | struct clk *clk_register(struct device *dev, struct clk_hw *hw); |
276 | const struct clk_ops *ops, struct clk_hw *hw, | ||
277 | char **parent_names, u8 num_parents, unsigned long flags); | ||
278 | 314 | ||
279 | /* helper functions */ | 315 | /* helper functions */ |
280 | const char *__clk_get_name(struct clk *clk); | 316 | const char *__clk_get_name(struct clk *clk); |