diff options
Diffstat (limited to 'include/linux/clk.h')
-rw-r--r-- | include/linux/clk.h | 192 |
1 files changed, 131 insertions, 61 deletions
diff --git a/include/linux/clk.h b/include/linux/clk.h index ad5c43e8ae8a..b3ac22d0fc1f 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h | |||
@@ -12,6 +12,7 @@ | |||
12 | #ifndef __LINUX_CLK_H | 12 | #ifndef __LINUX_CLK_H |
13 | #define __LINUX_CLK_H | 13 | #define __LINUX_CLK_H |
14 | 14 | ||
15 | #include <linux/err.h> | ||
15 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
16 | #include <linux/notifier.h> | 17 | #include <linux/notifier.h> |
17 | 18 | ||
@@ -84,9 +85,46 @@ int clk_notifier_unregister(struct clk *clk, struct notifier_block *nb); | |||
84 | #endif | 85 | #endif |
85 | 86 | ||
86 | /** | 87 | /** |
88 | * clk_prepare - prepare a clock source | ||
89 | * @clk: clock source | ||
90 | * | ||
91 | * This prepares the clock source for use. | ||
92 | * | ||
93 | * Must not be called from within atomic context. | ||
94 | */ | ||
95 | #ifdef CONFIG_HAVE_CLK_PREPARE | ||
96 | int clk_prepare(struct clk *clk); | ||
97 | #else | ||
98 | static inline int clk_prepare(struct clk *clk) | ||
99 | { | ||
100 | might_sleep(); | ||
101 | return 0; | ||
102 | } | ||
103 | #endif | ||
104 | |||
105 | /** | ||
106 | * clk_unprepare - undo preparation of a clock source | ||
107 | * @clk: clock source | ||
108 | * | ||
109 | * This undoes a previously prepared clock. The caller must balance | ||
110 | * the number of prepare and unprepare calls. | ||
111 | * | ||
112 | * Must not be called from within atomic context. | ||
113 | */ | ||
114 | #ifdef CONFIG_HAVE_CLK_PREPARE | ||
115 | void clk_unprepare(struct clk *clk); | ||
116 | #else | ||
117 | static inline void clk_unprepare(struct clk *clk) | ||
118 | { | ||
119 | might_sleep(); | ||
120 | } | ||
121 | #endif | ||
122 | |||
123 | #ifdef CONFIG_HAVE_CLK | ||
124 | /** | ||
87 | * clk_get - lookup and obtain a reference to a clock producer. | 125 | * clk_get - lookup and obtain a reference to a clock producer. |
88 | * @dev: device for clock "consumer" | 126 | * @dev: device for clock "consumer" |
89 | * @id: clock comsumer ID | 127 | * @id: clock consumer ID |
90 | * | 128 | * |
91 | * Returns a struct clk corresponding to the clock producer, or | 129 | * Returns a struct clk corresponding to the clock producer, or |
92 | * valid IS_ERR() condition containing errno. The implementation | 130 | * valid IS_ERR() condition containing errno. The implementation |
@@ -103,7 +141,7 @@ struct clk *clk_get(struct device *dev, const char *id); | |||
103 | /** | 141 | /** |
104 | * devm_clk_get - lookup and obtain a managed reference to a clock producer. | 142 | * devm_clk_get - lookup and obtain a managed reference to a clock producer. |
105 | * @dev: device for clock "consumer" | 143 | * @dev: device for clock "consumer" |
106 | * @id: clock comsumer ID | 144 | * @id: clock consumer ID |
107 | * | 145 | * |
108 | * Returns a struct clk corresponding to the clock producer, or | 146 | * Returns a struct clk corresponding to the clock producer, or |
109 | * valid IS_ERR() condition containing errno. The implementation | 147 | * valid IS_ERR() condition containing errno. The implementation |
@@ -121,24 +159,6 @@ struct clk *clk_get(struct device *dev, const char *id); | |||
121 | struct clk *devm_clk_get(struct device *dev, const char *id); | 159 | struct clk *devm_clk_get(struct device *dev, const char *id); |
122 | 160 | ||
123 | /** | 161 | /** |
124 | * clk_prepare - prepare a clock source | ||
125 | * @clk: clock source | ||
126 | * | ||
127 | * This prepares the clock source for use. | ||
128 | * | ||
129 | * Must not be called from within atomic context. | ||
130 | */ | ||
131 | #ifdef CONFIG_HAVE_CLK_PREPARE | ||
132 | int clk_prepare(struct clk *clk); | ||
133 | #else | ||
134 | static inline int clk_prepare(struct clk *clk) | ||
135 | { | ||
136 | might_sleep(); | ||
137 | return 0; | ||
138 | } | ||
139 | #endif | ||
140 | |||
141 | /** | ||
142 | * clk_enable - inform the system when the clock source should be running. | 162 | * clk_enable - inform the system when the clock source should be running. |
143 | * @clk: clock source | 163 | * @clk: clock source |
144 | * | 164 | * |
@@ -166,47 +186,6 @@ int clk_enable(struct clk *clk); | |||
166 | */ | 186 | */ |
167 | void clk_disable(struct clk *clk); | 187 | void clk_disable(struct clk *clk); |
168 | 188 | ||
169 | |||
170 | /** | ||
171 | * clk_unprepare - undo preparation of a clock source | ||
172 | * @clk: clock source | ||
173 | * | ||
174 | * This undoes a previously prepared clock. The caller must balance | ||
175 | * the number of prepare and unprepare calls. | ||
176 | * | ||
177 | * Must not be called from within atomic context. | ||
178 | */ | ||
179 | #ifdef CONFIG_HAVE_CLK_PREPARE | ||
180 | void clk_unprepare(struct clk *clk); | ||
181 | #else | ||
182 | static inline void clk_unprepare(struct clk *clk) | ||
183 | { | ||
184 | might_sleep(); | ||
185 | } | ||
186 | #endif | ||
187 | |||
188 | /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */ | ||
189 | static inline int clk_prepare_enable(struct clk *clk) | ||
190 | { | ||
191 | int ret; | ||
192 | |||
193 | ret = clk_prepare(clk); | ||
194 | if (ret) | ||
195 | return ret; | ||
196 | ret = clk_enable(clk); | ||
197 | if (ret) | ||
198 | clk_unprepare(clk); | ||
199 | |||
200 | return ret; | ||
201 | } | ||
202 | |||
203 | /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */ | ||
204 | static inline void clk_disable_unprepare(struct clk *clk) | ||
205 | { | ||
206 | clk_disable(clk); | ||
207 | clk_unprepare(clk); | ||
208 | } | ||
209 | |||
210 | /** | 189 | /** |
211 | * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. | 190 | * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. |
212 | * This is only valid once the clock source has been enabled. | 191 | * This is only valid once the clock source has been enabled. |
@@ -297,6 +276,78 @@ struct clk *clk_get_parent(struct clk *clk); | |||
297 | */ | 276 | */ |
298 | struct clk *clk_get_sys(const char *dev_id, const char *con_id); | 277 | struct clk *clk_get_sys(const char *dev_id, const char *con_id); |
299 | 278 | ||
279 | #else /* !CONFIG_HAVE_CLK */ | ||
280 | |||
281 | static inline struct clk *clk_get(struct device *dev, const char *id) | ||
282 | { | ||
283 | return NULL; | ||
284 | } | ||
285 | |||
286 | static inline struct clk *devm_clk_get(struct device *dev, const char *id) | ||
287 | { | ||
288 | return NULL; | ||
289 | } | ||
290 | |||
291 | static inline void clk_put(struct clk *clk) {} | ||
292 | |||
293 | static inline void devm_clk_put(struct device *dev, struct clk *clk) {} | ||
294 | |||
295 | static inline int clk_enable(struct clk *clk) | ||
296 | { | ||
297 | return 0; | ||
298 | } | ||
299 | |||
300 | static inline void clk_disable(struct clk *clk) {} | ||
301 | |||
302 | static inline unsigned long clk_get_rate(struct clk *clk) | ||
303 | { | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | static inline int clk_set_rate(struct clk *clk, unsigned long rate) | ||
308 | { | ||
309 | return 0; | ||
310 | } | ||
311 | |||
312 | static inline long clk_round_rate(struct clk *clk, unsigned long rate) | ||
313 | { | ||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | static inline int clk_set_parent(struct clk *clk, struct clk *parent) | ||
318 | { | ||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | static inline struct clk *clk_get_parent(struct clk *clk) | ||
323 | { | ||
324 | return NULL; | ||
325 | } | ||
326 | |||
327 | #endif | ||
328 | |||
329 | /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */ | ||
330 | static inline int clk_prepare_enable(struct clk *clk) | ||
331 | { | ||
332 | int ret; | ||
333 | |||
334 | ret = clk_prepare(clk); | ||
335 | if (ret) | ||
336 | return ret; | ||
337 | ret = clk_enable(clk); | ||
338 | if (ret) | ||
339 | clk_unprepare(clk); | ||
340 | |||
341 | return ret; | ||
342 | } | ||
343 | |||
344 | /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */ | ||
345 | static inline void clk_disable_unprepare(struct clk *clk) | ||
346 | { | ||
347 | clk_disable(clk); | ||
348 | clk_unprepare(clk); | ||
349 | } | ||
350 | |||
300 | /** | 351 | /** |
301 | * clk_add_alias - add a new clock alias | 352 | * clk_add_alias - add a new clock alias |
302 | * @alias: name for clock alias | 353 | * @alias: name for clock alias |
@@ -310,4 +361,23 @@ struct clk *clk_get_sys(const char *dev_id, const char *con_id); | |||
310 | int clk_add_alias(const char *alias, const char *alias_dev_name, char *id, | 361 | int clk_add_alias(const char *alias, const char *alias_dev_name, char *id, |
311 | struct device *dev); | 362 | struct device *dev); |
312 | 363 | ||
364 | struct device_node; | ||
365 | struct of_phandle_args; | ||
366 | |||
367 | #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK) | ||
368 | struct clk *of_clk_get(struct device_node *np, int index); | ||
369 | struct clk *of_clk_get_by_name(struct device_node *np, const char *name); | ||
370 | struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec); | ||
371 | #else | ||
372 | static inline struct clk *of_clk_get(struct device_node *np, int index) | ||
373 | { | ||
374 | return ERR_PTR(-ENOENT); | ||
375 | } | ||
376 | static inline struct clk *of_clk_get_by_name(struct device_node *np, | ||
377 | const char *name) | ||
378 | { | ||
379 | return ERR_PTR(-ENOENT); | ||
380 | } | ||
381 | #endif | ||
382 | |||
313 | #endif | 383 | #endif |