Commit | Line | Data |
---|---|---|
d459bfe0 | 1 | /* |
8a3ddc75 | 2 | * OMAP2/3/4 clockdomain framework functions |
d459bfe0 | 3 | * |
32a363c0 PW |
4 | * Copyright (C) 2008-2011 Texas Instruments, Inc. |
5 | * Copyright (C) 2008-2011 Nokia Corporation | |
d459bfe0 PW |
6 | * |
7 | * Written by Paul Walmsley and Jouni Högander | |
8a3ddc75 | 8 | * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com> |
d459bfe0 PW |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License version 2 as | |
12 | * published by the Free Software Foundation. | |
13 | */ | |
33903eb5 | 14 | #undef DEBUG |
d459bfe0 | 15 | |
d459bfe0 PW |
16 | #include <linux/kernel.h> |
17 | #include <linux/device.h> | |
18 | #include <linux/list.h> | |
19 | #include <linux/errno.h> | |
20 | #include <linux/delay.h> | |
21 | #include <linux/clk.h> | |
22 | #include <linux/limits.h> | |
5b74c676 | 23 | #include <linux/err.h> |
d459bfe0 PW |
24 | |
25 | #include <linux/io.h> | |
26 | ||
27 | #include <linux/bitops.h> | |
28 | ||
55ed9694 | 29 | #include <plat/clock.h> |
1540f214 | 30 | #include "clockdomain.h" |
d459bfe0 PW |
31 | |
32 | /* clkdm_list contains all registered struct clockdomains */ | |
33 | static LIST_HEAD(clkdm_list); | |
34 | ||
55ed9694 PW |
35 | /* array of clockdomain deps to be added/removed when clkdm in hwsup mode */ |
36 | static struct clkdm_autodep *autodeps; | |
d459bfe0 | 37 | |
32d4034e | 38 | static struct clkdm_ops *arch_clkdm; |
d459bfe0 PW |
39 | |
40 | /* Private functions */ | |
41 | ||
55ed9694 PW |
42 | static struct clockdomain *_clkdm_lookup(const char *name) |
43 | { | |
44 | struct clockdomain *clkdm, *temp_clkdm; | |
45 | ||
46 | if (!name) | |
47 | return NULL; | |
48 | ||
49 | clkdm = NULL; | |
50 | ||
51 | list_for_each_entry(temp_clkdm, &clkdm_list, node) { | |
52 | if (!strcmp(name, temp_clkdm->name)) { | |
53 | clkdm = temp_clkdm; | |
54 | break; | |
55 | } | |
56 | } | |
57 | ||
58 | return clkdm; | |
59 | } | |
60 | ||
e909d62a PW |
61 | /** |
62 | * _clkdm_register - register a clockdomain | |
63 | * @clkdm: struct clockdomain * to register | |
64 | * | |
65 | * Adds a clockdomain to the internal clockdomain list. | |
66 | * Returns -EINVAL if given a null pointer, -EEXIST if a clockdomain is | |
67 | * already registered by the provided name, or 0 upon success. | |
68 | */ | |
69 | static int _clkdm_register(struct clockdomain *clkdm) | |
70 | { | |
71 | struct powerdomain *pwrdm; | |
72 | ||
73 | if (!clkdm || !clkdm->name) | |
74 | return -EINVAL; | |
75 | ||
76 | if (!omap_chip_is(clkdm->omap_chip)) | |
77 | return -EINVAL; | |
78 | ||
79 | pwrdm = pwrdm_lookup(clkdm->pwrdm.name); | |
80 | if (!pwrdm) { | |
81 | pr_err("clockdomain: %s: powerdomain %s does not exist\n", | |
82 | clkdm->name, clkdm->pwrdm.name); | |
83 | return -EINVAL; | |
84 | } | |
85 | clkdm->pwrdm.ptr = pwrdm; | |
86 | ||
87 | /* Verify that the clockdomain is not already registered */ | |
88 | if (_clkdm_lookup(clkdm->name)) | |
89 | return -EEXIST; | |
90 | ||
91 | list_add(&clkdm->node, &clkdm_list); | |
92 | ||
93 | pwrdm_add_clkdm(pwrdm, clkdm); | |
94 | ||
555e74ea RN |
95 | spin_lock_init(&clkdm->lock); |
96 | ||
e909d62a PW |
97 | pr_debug("clockdomain: registered %s\n", clkdm->name); |
98 | ||
99 | return 0; | |
100 | } | |
101 | ||
55ed9694 PW |
102 | /* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */ |
103 | static struct clkdm_dep *_clkdm_deps_lookup(struct clockdomain *clkdm, | |
104 | struct clkdm_dep *deps) | |
105 | { | |
106 | struct clkdm_dep *cd; | |
107 | ||
108 | if (!clkdm || !deps || !omap_chip_is(clkdm->omap_chip)) | |
109 | return ERR_PTR(-EINVAL); | |
110 | ||
111 | for (cd = deps; cd->clkdm_name; cd++) { | |
55ed9694 PW |
112 | if (!omap_chip_is(cd->omap_chip)) |
113 | continue; | |
114 | ||
115 | if (!cd->clkdm && cd->clkdm_name) | |
116 | cd->clkdm = _clkdm_lookup(cd->clkdm_name); | |
117 | ||
118 | if (cd->clkdm == clkdm) | |
119 | break; | |
55ed9694 PW |
120 | } |
121 | ||
122 | if (!cd->clkdm_name) | |
123 | return ERR_PTR(-ENOENT); | |
124 | ||
125 | return cd; | |
126 | } | |
127 | ||
d459bfe0 | 128 | /* |
55ed9694 PW |
129 | * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store |
130 | * @autodep: struct clkdm_autodep * to resolve | |
d459bfe0 | 131 | * |
55ed9694 PW |
132 | * Resolve autodep clockdomain names to clockdomain pointers via |
133 | * clkdm_lookup() and store the pointers in the autodep structure. An | |
134 | * "autodep" is a clockdomain sleep/wakeup dependency that is | |
d459bfe0 PW |
135 | * automatically added and removed whenever clocks in the associated |
136 | * clockdomain are enabled or disabled (respectively) when the | |
137 | * clockdomain is in hardware-supervised mode. Meant to be called | |
138 | * once at clockdomain layer initialization, since these should remain | |
139 | * fixed for a particular architecture. No return value. | |
b170fbe1 PW |
140 | * |
141 | * XXX autodeps are deprecated and should be removed at the earliest | |
142 | * opportunity | |
d459bfe0 | 143 | */ |
55ed9694 | 144 | static void _autodep_lookup(struct clkdm_autodep *autodep) |
d459bfe0 | 145 | { |
55ed9694 | 146 | struct clockdomain *clkdm; |
d459bfe0 PW |
147 | |
148 | if (!autodep) | |
149 | return; | |
150 | ||
151 | if (!omap_chip_is(autodep->omap_chip)) | |
152 | return; | |
153 | ||
55ed9694 PW |
154 | clkdm = clkdm_lookup(autodep->clkdm.name); |
155 | if (!clkdm) { | |
156 | pr_err("clockdomain: autodeps: clockdomain %s does not exist\n", | |
157 | autodep->clkdm.name); | |
158 | clkdm = ERR_PTR(-ENOENT); | |
d459bfe0 | 159 | } |
55ed9694 | 160 | autodep->clkdm.ptr = clkdm; |
d459bfe0 PW |
161 | } |
162 | ||
163 | /* | |
164 | * _clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable | |
165 | * @clkdm: struct clockdomain * | |
166 | * | |
167 | * Add the "autodep" sleep & wakeup dependencies to clockdomain 'clkdm' | |
168 | * in hardware-supervised mode. Meant to be called from clock framework | |
169 | * when a clock inside clockdomain 'clkdm' is enabled. No return value. | |
b170fbe1 PW |
170 | * |
171 | * XXX autodeps are deprecated and should be removed at the earliest | |
172 | * opportunity | |
d459bfe0 | 173 | */ |
5cd1937b | 174 | void _clkdm_add_autodeps(struct clockdomain *clkdm) |
d459bfe0 | 175 | { |
55ed9694 | 176 | struct clkdm_autodep *autodep; |
d459bfe0 | 177 | |
570b54c7 | 178 | if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS) |
ad956160 PW |
179 | return; |
180 | ||
55ed9694 PW |
181 | for (autodep = autodeps; autodep->clkdm.ptr; autodep++) { |
182 | if (IS_ERR(autodep->clkdm.ptr)) | |
d459bfe0 PW |
183 | continue; |
184 | ||
d96df00d PW |
185 | if (!omap_chip_is(autodep->omap_chip)) |
186 | continue; | |
187 | ||
d459bfe0 | 188 | pr_debug("clockdomain: adding %s sleepdep/wkdep for " |
55ed9694 PW |
189 | "clkdm %s\n", autodep->clkdm.ptr->name, |
190 | clkdm->name); | |
d459bfe0 | 191 | |
55ed9694 PW |
192 | clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr); |
193 | clkdm_add_wkdep(clkdm, autodep->clkdm.ptr); | |
d459bfe0 PW |
194 | } |
195 | } | |
196 | ||
197 | /* | |
198 | * _clkdm_add_autodeps - remove auto sleepdeps/wkdeps from clkdm | |
199 | * @clkdm: struct clockdomain * | |
200 | * | |
201 | * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm' | |
202 | * in hardware-supervised mode. Meant to be called from clock framework | |
203 | * when a clock inside clockdomain 'clkdm' is disabled. No return value. | |
b170fbe1 PW |
204 | * |
205 | * XXX autodeps are deprecated and should be removed at the earliest | |
206 | * opportunity | |
d459bfe0 | 207 | */ |
5cd1937b | 208 | void _clkdm_del_autodeps(struct clockdomain *clkdm) |
d459bfe0 | 209 | { |
55ed9694 | 210 | struct clkdm_autodep *autodep; |
d459bfe0 | 211 | |
570b54c7 | 212 | if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS) |
ad956160 PW |
213 | return; |
214 | ||
55ed9694 PW |
215 | for (autodep = autodeps; autodep->clkdm.ptr; autodep++) { |
216 | if (IS_ERR(autodep->clkdm.ptr)) | |
d459bfe0 PW |
217 | continue; |
218 | ||
d96df00d PW |
219 | if (!omap_chip_is(autodep->omap_chip)) |
220 | continue; | |
221 | ||
d459bfe0 | 222 | pr_debug("clockdomain: removing %s sleepdep/wkdep for " |
55ed9694 PW |
223 | "clkdm %s\n", autodep->clkdm.ptr->name, |
224 | clkdm->name); | |
d459bfe0 | 225 | |
55ed9694 PW |
226 | clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr); |
227 | clkdm_del_wkdep(clkdm, autodep->clkdm.ptr); | |
d459bfe0 PW |
228 | } |
229 | } | |
230 | ||
b170fbe1 | 231 | /** |
4aef7a2a RN |
232 | * _resolve_clkdm_deps() - resolve clkdm_names in @clkdm_deps to clkdms |
233 | * @clkdm: clockdomain that we are resolving dependencies for | |
234 | * @clkdm_deps: ptr to array of struct clkdm_deps to resolve | |
b170fbe1 | 235 | * |
4aef7a2a RN |
236 | * Iterates through @clkdm_deps, looking up the struct clockdomain named by |
237 | * clkdm_name and storing the clockdomain pointer in the struct clkdm_dep. | |
b170fbe1 | 238 | * No return value. |
a0219fbd | 239 | */ |
4aef7a2a RN |
240 | static void _resolve_clkdm_deps(struct clockdomain *clkdm, |
241 | struct clkdm_dep *clkdm_deps) | |
a0219fbd | 242 | { |
4aef7a2a RN |
243 | struct clkdm_dep *cd; |
244 | ||
245 | for (cd = clkdm_deps; cd && cd->clkdm_name; cd++) { | |
246 | if (!omap_chip_is(cd->omap_chip)) | |
247 | continue; | |
248 | if (cd->clkdm) | |
249 | continue; | |
250 | cd->clkdm = _clkdm_lookup(cd->clkdm_name); | |
251 | ||
252 | WARN(!cd->clkdm, "clockdomain: %s: could not find clkdm %s while resolving dependencies - should never happen", | |
253 | clkdm->name, cd->clkdm_name); | |
254 | } | |
a0219fbd | 255 | } |
d459bfe0 | 256 | |
d459bfe0 PW |
257 | /* Public functions */ |
258 | ||
259 | /** | |
260 | * clkdm_init - set up the clockdomain layer | |
261 | * @clkdms: optional pointer to an array of clockdomains to register | |
262 | * @init_autodeps: optional pointer to an array of autodeps to register | |
25985edc | 263 | * @custom_funcs: func pointers for arch specific implementations |
d459bfe0 PW |
264 | * |
265 | * Set up internal state. If a pointer to an array of clockdomains | |
f0271d65 PW |
266 | * @clkdms was supplied, loop through the list of clockdomains, |
267 | * register all that are available on the current platform. Similarly, | |
268 | * if a pointer to an array of clockdomain autodependencies | |
269 | * @init_autodeps was provided, register those. No return value. | |
d459bfe0 PW |
270 | */ |
271 | void clkdm_init(struct clockdomain **clkdms, | |
32d4034e RN |
272 | struct clkdm_autodep *init_autodeps, |
273 | struct clkdm_ops *custom_funcs) | |
d459bfe0 PW |
274 | { |
275 | struct clockdomain **c = NULL; | |
369d5614 | 276 | struct clockdomain *clkdm; |
55ed9694 | 277 | struct clkdm_autodep *autodep = NULL; |
d459bfe0 | 278 | |
32d4034e RN |
279 | if (!custom_funcs) |
280 | WARN(1, "No custom clkdm functions registered\n"); | |
281 | else | |
282 | arch_clkdm = custom_funcs; | |
283 | ||
d459bfe0 PW |
284 | if (clkdms) |
285 | for (c = clkdms; *c; c++) | |
e909d62a | 286 | _clkdm_register(*c); |
d459bfe0 | 287 | |
55ed9694 PW |
288 | autodeps = init_autodeps; |
289 | if (autodeps) | |
290 | for (autodep = autodeps; autodep->clkdm.ptr; autodep++) | |
291 | _autodep_lookup(autodep); | |
369d5614 PW |
292 | |
293 | /* | |
6f7f63cc PW |
294 | * Put all clockdomains into software-supervised mode; PM code |
295 | * should later enable hardware-supervised mode as appropriate | |
369d5614 PW |
296 | */ |
297 | list_for_each_entry(clkdm, &clkdm_list, node) { | |
6f7f63cc | 298 | if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP) |
68b921ad | 299 | clkdm_wakeup(clkdm); |
6f7f63cc | 300 | else if (clkdm->flags & CLKDM_CAN_DISABLE_AUTO) |
5cd1937b | 301 | clkdm_deny_idle(clkdm); |
6f7f63cc | 302 | |
4aef7a2a | 303 | _resolve_clkdm_deps(clkdm, clkdm->wkdep_srcs); |
6f7f63cc | 304 | clkdm_clear_all_wkdeps(clkdm); |
4aef7a2a RN |
305 | |
306 | _resolve_clkdm_deps(clkdm, clkdm->sleepdep_srcs); | |
6f7f63cc | 307 | clkdm_clear_all_sleepdeps(clkdm); |
369d5614 | 308 | } |
d459bfe0 PW |
309 | } |
310 | ||
d459bfe0 PW |
311 | /** |
312 | * clkdm_lookup - look up a clockdomain by name, return a pointer | |
313 | * @name: name of clockdomain | |
314 | * | |
f0271d65 PW |
315 | * Find a registered clockdomain by its name @name. Returns a pointer |
316 | * to the struct clockdomain if found, or NULL otherwise. | |
d459bfe0 PW |
317 | */ |
318 | struct clockdomain *clkdm_lookup(const char *name) | |
319 | { | |
320 | struct clockdomain *clkdm, *temp_clkdm; | |
321 | ||
322 | if (!name) | |
323 | return NULL; | |
324 | ||
325 | clkdm = NULL; | |
326 | ||
d459bfe0 PW |
327 | list_for_each_entry(temp_clkdm, &clkdm_list, node) { |
328 | if (!strcmp(name, temp_clkdm->name)) { | |
329 | clkdm = temp_clkdm; | |
330 | break; | |
331 | } | |
332 | } | |
d459bfe0 PW |
333 | |
334 | return clkdm; | |
335 | } | |
336 | ||
337 | /** | |
338 | * clkdm_for_each - call function on each registered clockdomain | |
339 | * @fn: callback function * | |
340 | * | |
f0271d65 PW |
341 | * Call the supplied function @fn for each registered clockdomain. |
342 | * The callback function @fn can return anything but 0 to bail | |
d459bfe0 PW |
343 | * out early from the iterator. The callback function is called with |
344 | * the clkdm_mutex held, so no clockdomain structure manipulation | |
345 | * functions should be called from the callback, although hardware | |
346 | * clockdomain control functions are fine. Returns the last return | |
347 | * value of the callback function, which should be 0 for success or | |
348 | * anything else to indicate failure; or -EINVAL if the function pointer | |
349 | * is null. | |
350 | */ | |
a23456e9 PDS |
351 | int clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user), |
352 | void *user) | |
d459bfe0 PW |
353 | { |
354 | struct clockdomain *clkdm; | |
355 | int ret = 0; | |
356 | ||
357 | if (!fn) | |
358 | return -EINVAL; | |
359 | ||
d459bfe0 | 360 | list_for_each_entry(clkdm, &clkdm_list, node) { |
a23456e9 | 361 | ret = (*fn)(clkdm, user); |
d459bfe0 PW |
362 | if (ret) |
363 | break; | |
364 | } | |
d459bfe0 PW |
365 | |
366 | return ret; | |
367 | } | |
368 | ||
369 | ||
e89087c9 PW |
370 | /** |
371 | * clkdm_get_pwrdm - return a ptr to the pwrdm that this clkdm resides in | |
372 | * @clkdm: struct clockdomain * | |
373 | * | |
374 | * Return a pointer to the struct powerdomain that the specified clockdomain | |
f0271d65 | 375 | * @clkdm exists in, or returns NULL if @clkdm is NULL. |
e89087c9 PW |
376 | */ |
377 | struct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm) | |
378 | { | |
379 | if (!clkdm) | |
380 | return NULL; | |
381 | ||
5b74c676 | 382 | return clkdm->pwrdm.ptr; |
e89087c9 PW |
383 | } |
384 | ||
385 | ||
d459bfe0 PW |
386 | /* Hardware clockdomain control */ |
387 | ||
55ed9694 PW |
388 | /** |
389 | * clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1 | |
390 | * @clkdm1: wake this struct clockdomain * up (dependent) | |
391 | * @clkdm2: when this struct clockdomain * wakes up (source) | |
392 | * | |
393 | * When the clockdomain represented by @clkdm2 wakes up, wake up | |
394 | * @clkdm1. Implemented in hardware on the OMAP, this feature is | |
395 | * designed to reduce wakeup latency of the dependent clockdomain @clkdm1. | |
396 | * Returns -EINVAL if presented with invalid clockdomain pointers, | |
397 | * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon | |
398 | * success. | |
399 | */ | |
400 | int clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) | |
401 | { | |
402 | struct clkdm_dep *cd; | |
4aef7a2a | 403 | int ret = 0; |
56bc78d4 | 404 | |
55ed9694 PW |
405 | if (!clkdm1 || !clkdm2) |
406 | return -EINVAL; | |
407 | ||
408 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs); | |
4aef7a2a RN |
409 | if (IS_ERR(cd)) |
410 | ret = PTR_ERR(cd); | |
411 | ||
412 | if (!arch_clkdm || !arch_clkdm->clkdm_add_wkdep) | |
413 | ret = -EINVAL; | |
414 | ||
415 | if (ret) { | |
55ed9694 PW |
416 | pr_debug("clockdomain: hardware cannot set/clear wake up of " |
417 | "%s when %s wakes up\n", clkdm1->name, clkdm2->name); | |
4aef7a2a | 418 | return ret; |
55ed9694 PW |
419 | } |
420 | ||
369d5614 PW |
421 | if (atomic_inc_return(&cd->wkdep_usecount) == 1) { |
422 | pr_debug("clockdomain: hardware will wake up %s when %s wakes " | |
423 | "up\n", clkdm1->name, clkdm2->name); | |
55ed9694 | 424 | |
4aef7a2a | 425 | ret = arch_clkdm->clkdm_add_wkdep(clkdm1, clkdm2); |
369d5614 | 426 | } |
55ed9694 | 427 | |
4aef7a2a | 428 | return ret; |
55ed9694 PW |
429 | } |
430 | ||
431 | /** | |
432 | * clkdm_del_wkdep - remove a wakeup dependency from clkdm2 to clkdm1 | |
433 | * @clkdm1: wake this struct clockdomain * up (dependent) | |
434 | * @clkdm2: when this struct clockdomain * wakes up (source) | |
435 | * | |
436 | * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2 | |
437 | * wakes up. Returns -EINVAL if presented with invalid clockdomain | |
438 | * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or | |
439 | * 0 upon success. | |
440 | */ | |
441 | int clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) | |
442 | { | |
443 | struct clkdm_dep *cd; | |
4aef7a2a | 444 | int ret = 0; |
56bc78d4 | 445 | |
55ed9694 PW |
446 | if (!clkdm1 || !clkdm2) |
447 | return -EINVAL; | |
448 | ||
449 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs); | |
4aef7a2a RN |
450 | if (IS_ERR(cd)) |
451 | ret = PTR_ERR(cd); | |
452 | ||
453 | if (!arch_clkdm || !arch_clkdm->clkdm_del_wkdep) | |
454 | ret = -EINVAL; | |
455 | ||
456 | if (ret) { | |
55ed9694 PW |
457 | pr_debug("clockdomain: hardware cannot set/clear wake up of " |
458 | "%s when %s wakes up\n", clkdm1->name, clkdm2->name); | |
4aef7a2a | 459 | return ret; |
55ed9694 PW |
460 | } |
461 | ||
369d5614 PW |
462 | if (atomic_dec_return(&cd->wkdep_usecount) == 0) { |
463 | pr_debug("clockdomain: hardware will no longer wake up %s " | |
464 | "after %s wakes up\n", clkdm1->name, clkdm2->name); | |
55ed9694 | 465 | |
4aef7a2a | 466 | ret = arch_clkdm->clkdm_del_wkdep(clkdm1, clkdm2); |
369d5614 | 467 | } |
55ed9694 | 468 | |
4aef7a2a | 469 | return ret; |
55ed9694 PW |
470 | } |
471 | ||
472 | /** | |
473 | * clkdm_read_wkdep - read wakeup dependency state from clkdm2 to clkdm1 | |
474 | * @clkdm1: wake this struct clockdomain * up (dependent) | |
475 | * @clkdm2: when this struct clockdomain * wakes up (source) | |
476 | * | |
477 | * Return 1 if a hardware wakeup dependency exists wherein @clkdm1 will be | |
478 | * awoken when @clkdm2 wakes up; 0 if dependency is not set; -EINVAL | |
479 | * if either clockdomain pointer is invalid; or -ENOENT if the hardware | |
480 | * is incapable. | |
481 | * | |
482 | * REVISIT: Currently this function only represents software-controllable | |
483 | * wakeup dependencies. Wakeup dependencies fixed in hardware are not | |
484 | * yet handled here. | |
485 | */ | |
486 | int clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) | |
487 | { | |
488 | struct clkdm_dep *cd; | |
4aef7a2a | 489 | int ret = 0; |
55ed9694 PW |
490 | |
491 | if (!clkdm1 || !clkdm2) | |
492 | return -EINVAL; | |
493 | ||
494 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs); | |
4aef7a2a RN |
495 | if (IS_ERR(cd)) |
496 | ret = PTR_ERR(cd); | |
497 | ||
498 | if (!arch_clkdm || !arch_clkdm->clkdm_read_wkdep) | |
499 | ret = -EINVAL; | |
500 | ||
501 | if (ret) { | |
55ed9694 PW |
502 | pr_debug("clockdomain: hardware cannot set/clear wake up of " |
503 | "%s when %s wakes up\n", clkdm1->name, clkdm2->name); | |
4aef7a2a | 504 | return ret; |
55ed9694 PW |
505 | } |
506 | ||
369d5614 | 507 | /* XXX It's faster to return the atomic wkdep_usecount */ |
4aef7a2a | 508 | return arch_clkdm->clkdm_read_wkdep(clkdm1, clkdm2); |
55ed9694 PW |
509 | } |
510 | ||
369d5614 PW |
511 | /** |
512 | * clkdm_clear_all_wkdeps - remove all wakeup dependencies from target clkdm | |
513 | * @clkdm: struct clockdomain * to remove all wakeup dependencies from | |
514 | * | |
515 | * Remove all inter-clockdomain wakeup dependencies that could cause | |
516 | * @clkdm to wake. Intended to be used during boot to initialize the | |
517 | * PRCM to a known state, after all clockdomains are put into swsup idle | |
518 | * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or | |
519 | * 0 upon success. | |
520 | */ | |
521 | int clkdm_clear_all_wkdeps(struct clockdomain *clkdm) | |
522 | { | |
369d5614 PW |
523 | if (!clkdm) |
524 | return -EINVAL; | |
525 | ||
4aef7a2a RN |
526 | if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_wkdeps) |
527 | return -EINVAL; | |
369d5614 | 528 | |
4aef7a2a | 529 | return arch_clkdm->clkdm_clear_all_wkdeps(clkdm); |
369d5614 PW |
530 | } |
531 | ||
55ed9694 PW |
532 | /** |
533 | * clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1 | |
534 | * @clkdm1: prevent this struct clockdomain * from sleeping (dependent) | |
535 | * @clkdm2: when this struct clockdomain * is active (source) | |
536 | * | |
537 | * Prevent @clkdm1 from automatically going inactive (and then to | |
538 | * retention or off) if @clkdm2 is active. Returns -EINVAL if | |
539 | * presented with invalid clockdomain pointers or called on a machine | |
540 | * that does not support software-configurable hardware sleep | |
541 | * dependencies, -ENOENT if the specified dependency cannot be set in | |
542 | * hardware, or 0 upon success. | |
543 | */ | |
544 | int clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) | |
545 | { | |
546 | struct clkdm_dep *cd; | |
4aef7a2a | 547 | int ret = 0; |
55ed9694 PW |
548 | |
549 | if (!clkdm1 || !clkdm2) | |
550 | return -EINVAL; | |
551 | ||
552 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs); | |
4aef7a2a RN |
553 | if (IS_ERR(cd)) |
554 | ret = PTR_ERR(cd); | |
555 | ||
556 | if (!arch_clkdm || !arch_clkdm->clkdm_add_sleepdep) | |
557 | ret = -EINVAL; | |
558 | ||
559 | if (ret) { | |
55ed9694 PW |
560 | pr_debug("clockdomain: hardware cannot set/clear sleep " |
561 | "dependency affecting %s from %s\n", clkdm1->name, | |
562 | clkdm2->name); | |
4aef7a2a | 563 | return ret; |
55ed9694 PW |
564 | } |
565 | ||
369d5614 PW |
566 | if (atomic_inc_return(&cd->sleepdep_usecount) == 1) { |
567 | pr_debug("clockdomain: will prevent %s from sleeping if %s " | |
568 | "is active\n", clkdm1->name, clkdm2->name); | |
55ed9694 | 569 | |
4aef7a2a | 570 | ret = arch_clkdm->clkdm_add_sleepdep(clkdm1, clkdm2); |
369d5614 | 571 | } |
55ed9694 | 572 | |
4aef7a2a | 573 | return ret; |
55ed9694 PW |
574 | } |
575 | ||
576 | /** | |
577 | * clkdm_del_sleepdep - remove a sleep dependency from clkdm2 to clkdm1 | |
578 | * @clkdm1: prevent this struct clockdomain * from sleeping (dependent) | |
579 | * @clkdm2: when this struct clockdomain * is active (source) | |
580 | * | |
581 | * Allow @clkdm1 to automatically go inactive (and then to retention or | |
582 | * off), independent of the activity state of @clkdm2. Returns -EINVAL | |
583 | * if presented with invalid clockdomain pointers or called on a machine | |
584 | * that does not support software-configurable hardware sleep dependencies, | |
585 | * -ENOENT if the specified dependency cannot be cleared in hardware, or | |
586 | * 0 upon success. | |
587 | */ | |
588 | int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) | |
589 | { | |
590 | struct clkdm_dep *cd; | |
4aef7a2a | 591 | int ret = 0; |
55ed9694 PW |
592 | |
593 | if (!clkdm1 || !clkdm2) | |
594 | return -EINVAL; | |
595 | ||
596 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs); | |
4aef7a2a RN |
597 | if (IS_ERR(cd)) |
598 | ret = PTR_ERR(cd); | |
599 | ||
600 | if (!arch_clkdm || !arch_clkdm->clkdm_del_sleepdep) | |
601 | ret = -EINVAL; | |
602 | ||
603 | if (ret) { | |
55ed9694 PW |
604 | pr_debug("clockdomain: hardware cannot set/clear sleep " |
605 | "dependency affecting %s from %s\n", clkdm1->name, | |
606 | clkdm2->name); | |
4aef7a2a | 607 | return ret; |
55ed9694 PW |
608 | } |
609 | ||
369d5614 PW |
610 | if (atomic_dec_return(&cd->sleepdep_usecount) == 0) { |
611 | pr_debug("clockdomain: will no longer prevent %s from " | |
612 | "sleeping if %s is active\n", clkdm1->name, | |
613 | clkdm2->name); | |
55ed9694 | 614 | |
4aef7a2a | 615 | ret = arch_clkdm->clkdm_del_sleepdep(clkdm1, clkdm2); |
369d5614 | 616 | } |
55ed9694 | 617 | |
4aef7a2a | 618 | return ret; |
55ed9694 PW |
619 | } |
620 | ||
621 | /** | |
622 | * clkdm_read_sleepdep - read sleep dependency state from clkdm2 to clkdm1 | |
623 | * @clkdm1: prevent this struct clockdomain * from sleeping (dependent) | |
624 | * @clkdm2: when this struct clockdomain * is active (source) | |
625 | * | |
626 | * Return 1 if a hardware sleep dependency exists wherein @clkdm1 will | |
627 | * not be allowed to automatically go inactive if @clkdm2 is active; | |
628 | * 0 if @clkdm1's automatic power state inactivity transition is independent | |
629 | * of @clkdm2's; -EINVAL if either clockdomain pointer is invalid or called | |
630 | * on a machine that does not support software-configurable hardware sleep | |
631 | * dependencies; or -ENOENT if the hardware is incapable. | |
632 | * | |
633 | * REVISIT: Currently this function only represents software-controllable | |
634 | * sleep dependencies. Sleep dependencies fixed in hardware are not | |
635 | * yet handled here. | |
636 | */ | |
637 | int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) | |
638 | { | |
639 | struct clkdm_dep *cd; | |
4aef7a2a | 640 | int ret = 0; |
55ed9694 PW |
641 | |
642 | if (!clkdm1 || !clkdm2) | |
643 | return -EINVAL; | |
644 | ||
645 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs); | |
4aef7a2a RN |
646 | if (IS_ERR(cd)) |
647 | ret = PTR_ERR(cd); | |
648 | ||
649 | if (!arch_clkdm || !arch_clkdm->clkdm_read_sleepdep) | |
650 | ret = -EINVAL; | |
651 | ||
652 | if (ret) { | |
55ed9694 PW |
653 | pr_debug("clockdomain: hardware cannot set/clear sleep " |
654 | "dependency affecting %s from %s\n", clkdm1->name, | |
655 | clkdm2->name); | |
4aef7a2a | 656 | return ret; |
55ed9694 PW |
657 | } |
658 | ||
369d5614 | 659 | /* XXX It's faster to return the atomic sleepdep_usecount */ |
4aef7a2a | 660 | return arch_clkdm->clkdm_read_sleepdep(clkdm1, clkdm2); |
55ed9694 PW |
661 | } |
662 | ||
369d5614 PW |
663 | /** |
664 | * clkdm_clear_all_sleepdeps - remove all sleep dependencies from target clkdm | |
665 | * @clkdm: struct clockdomain * to remove all sleep dependencies from | |
666 | * | |
667 | * Remove all inter-clockdomain sleep dependencies that could prevent | |
668 | * @clkdm from idling. Intended to be used during boot to initialize the | |
669 | * PRCM to a known state, after all clockdomains are put into swsup idle | |
670 | * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or | |
671 | * 0 upon success. | |
672 | */ | |
673 | int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm) | |
674 | { | |
369d5614 PW |
675 | if (!clkdm) |
676 | return -EINVAL; | |
677 | ||
4aef7a2a RN |
678 | if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_sleepdeps) |
679 | return -EINVAL; | |
369d5614 | 680 | |
4aef7a2a | 681 | return arch_clkdm->clkdm_clear_all_sleepdeps(clkdm); |
369d5614 | 682 | } |
55ed9694 | 683 | |
d459bfe0 | 684 | /** |
68b921ad | 685 | * clkdm_sleep - force clockdomain sleep transition |
d459bfe0 PW |
686 | * @clkdm: struct clockdomain * |
687 | * | |
688 | * Instruct the CM to force a sleep transition on the specified | |
f0271d65 | 689 | * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if |
d459bfe0 PW |
690 | * clockdomain does not support software-initiated sleep; 0 upon |
691 | * success. | |
692 | */ | |
68b921ad | 693 | int clkdm_sleep(struct clockdomain *clkdm) |
d459bfe0 | 694 | { |
555e74ea RN |
695 | int ret; |
696 | unsigned long flags; | |
697 | ||
d459bfe0 PW |
698 | if (!clkdm) |
699 | return -EINVAL; | |
700 | ||
701 | if (!(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) { | |
702 | pr_debug("clockdomain: %s does not support forcing " | |
703 | "sleep via software\n", clkdm->name); | |
704 | return -EINVAL; | |
705 | } | |
706 | ||
68b921ad RN |
707 | if (!arch_clkdm || !arch_clkdm->clkdm_sleep) |
708 | return -EINVAL; | |
bd2122ca | 709 | |
68b921ad | 710 | pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name); |
d459bfe0 | 711 | |
555e74ea | 712 | spin_lock_irqsave(&clkdm->lock, flags); |
32a363c0 | 713 | clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED; |
555e74ea RN |
714 | ret = arch_clkdm->clkdm_sleep(clkdm); |
715 | spin_unlock_irqrestore(&clkdm->lock, flags); | |
716 | return ret; | |
d459bfe0 PW |
717 | } |
718 | ||
719 | /** | |
68b921ad | 720 | * clkdm_wakeup - force clockdomain wakeup transition |
d459bfe0 PW |
721 | * @clkdm: struct clockdomain * |
722 | * | |
723 | * Instruct the CM to force a wakeup transition on the specified | |
f0271d65 | 724 | * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the |
d459bfe0 PW |
725 | * clockdomain does not support software-controlled wakeup; 0 upon |
726 | * success. | |
727 | */ | |
68b921ad | 728 | int clkdm_wakeup(struct clockdomain *clkdm) |
d459bfe0 | 729 | { |
555e74ea RN |
730 | int ret; |
731 | unsigned long flags; | |
732 | ||
d459bfe0 PW |
733 | if (!clkdm) |
734 | return -EINVAL; | |
735 | ||
736 | if (!(clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)) { | |
737 | pr_debug("clockdomain: %s does not support forcing " | |
738 | "wakeup via software\n", clkdm->name); | |
739 | return -EINVAL; | |
740 | } | |
741 | ||
68b921ad RN |
742 | if (!arch_clkdm || !arch_clkdm->clkdm_wakeup) |
743 | return -EINVAL; | |
bd2122ca | 744 | |
68b921ad | 745 | pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name); |
d459bfe0 | 746 | |
555e74ea | 747 | spin_lock_irqsave(&clkdm->lock, flags); |
32a363c0 | 748 | clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED; |
555e74ea | 749 | ret = arch_clkdm->clkdm_wakeup(clkdm); |
b1cbdb00 | 750 | ret |= pwrdm_state_switch(clkdm->pwrdm.ptr); |
555e74ea RN |
751 | spin_unlock_irqrestore(&clkdm->lock, flags); |
752 | return ret; | |
d459bfe0 PW |
753 | } |
754 | ||
755 | /** | |
5cd1937b | 756 | * clkdm_allow_idle - enable hwsup idle transitions for clkdm |
d459bfe0 PW |
757 | * @clkdm: struct clockdomain * |
758 | * | |
f0271d65 | 759 | * Allow the hardware to automatically switch the clockdomain @clkdm into |
d459bfe0 PW |
760 | * active or idle states, as needed by downstream clocks. If the |
761 | * clockdomain has any downstream clocks enabled in the clock | |
762 | * framework, wkdep/sleepdep autodependencies are added; this is so | |
763 | * device drivers can read and write to the device. No return value. | |
764 | */ | |
5cd1937b | 765 | void clkdm_allow_idle(struct clockdomain *clkdm) |
d459bfe0 | 766 | { |
555e74ea RN |
767 | unsigned long flags; |
768 | ||
d459bfe0 PW |
769 | if (!clkdm) |
770 | return; | |
771 | ||
772 | if (!(clkdm->flags & CLKDM_CAN_ENABLE_AUTO)) { | |
773 | pr_debug("clock: automatic idle transitions cannot be enabled " | |
774 | "on clockdomain %s\n", clkdm->name); | |
775 | return; | |
776 | } | |
777 | ||
5cd1937b RN |
778 | if (!arch_clkdm || !arch_clkdm->clkdm_allow_idle) |
779 | return; | |
780 | ||
d459bfe0 PW |
781 | pr_debug("clockdomain: enabling automatic idle transitions for %s\n", |
782 | clkdm->name); | |
783 | ||
555e74ea | 784 | spin_lock_irqsave(&clkdm->lock, flags); |
32a363c0 | 785 | clkdm->_flags |= _CLKDM_FLAG_HWSUP_ENABLED; |
5cd1937b | 786 | arch_clkdm->clkdm_allow_idle(clkdm); |
ba20bb12 | 787 | pwrdm_clkdm_state_switch(clkdm); |
555e74ea | 788 | spin_unlock_irqrestore(&clkdm->lock, flags); |
d459bfe0 PW |
789 | } |
790 | ||
791 | /** | |
5cd1937b | 792 | * clkdm_deny_idle - disable hwsup idle transitions for clkdm |
d459bfe0 PW |
793 | * @clkdm: struct clockdomain * |
794 | * | |
795 | * Prevent the hardware from automatically switching the clockdomain | |
f0271d65 PW |
796 | * @clkdm into inactive or idle states. If the clockdomain has |
797 | * downstream clocks enabled in the clock framework, wkdep/sleepdep | |
d459bfe0 PW |
798 | * autodependencies are removed. No return value. |
799 | */ | |
5cd1937b | 800 | void clkdm_deny_idle(struct clockdomain *clkdm) |
d459bfe0 | 801 | { |
555e74ea RN |
802 | unsigned long flags; |
803 | ||
d459bfe0 PW |
804 | if (!clkdm) |
805 | return; | |
806 | ||
807 | if (!(clkdm->flags & CLKDM_CAN_DISABLE_AUTO)) { | |
808 | pr_debug("clockdomain: automatic idle transitions cannot be " | |
809 | "disabled on %s\n", clkdm->name); | |
810 | return; | |
811 | } | |
812 | ||
5cd1937b RN |
813 | if (!arch_clkdm || !arch_clkdm->clkdm_deny_idle) |
814 | return; | |
815 | ||
d459bfe0 PW |
816 | pr_debug("clockdomain: disabling automatic idle transitions for %s\n", |
817 | clkdm->name); | |
818 | ||
555e74ea | 819 | spin_lock_irqsave(&clkdm->lock, flags); |
32a363c0 | 820 | clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED; |
5cd1937b | 821 | arch_clkdm->clkdm_deny_idle(clkdm); |
b1cbdb00 | 822 | pwrdm_state_switch(clkdm->pwrdm.ptr); |
555e74ea | 823 | spin_unlock_irqrestore(&clkdm->lock, flags); |
d459bfe0 PW |
824 | } |
825 | ||
32a363c0 PW |
826 | /** |
827 | * clkdm_in_hwsup - is clockdomain @clkdm have hardware-supervised idle enabled? | |
828 | * @clkdm: struct clockdomain * | |
829 | * | |
830 | * Returns true if clockdomain @clkdm currently has | |
831 | * hardware-supervised idle enabled, or false if it does not or if | |
832 | * @clkdm is NULL. It is only valid to call this function after | |
833 | * clkdm_init() has been called. This function does not actually read | |
834 | * bits from the hardware; it instead tests an in-memory flag that is | |
835 | * changed whenever the clockdomain code changes the auto-idle mode. | |
836 | */ | |
837 | bool clkdm_in_hwsup(struct clockdomain *clkdm) | |
838 | { | |
555e74ea RN |
839 | bool ret; |
840 | unsigned long flags; | |
841 | ||
32a363c0 PW |
842 | if (!clkdm) |
843 | return false; | |
844 | ||
555e74ea RN |
845 | spin_lock_irqsave(&clkdm->lock, flags); |
846 | ret = (clkdm->_flags & _CLKDM_FLAG_HWSUP_ENABLED) ? true : false; | |
847 | spin_unlock_irqrestore(&clkdm->lock, flags); | |
848 | ||
849 | return ret; | |
32a363c0 | 850 | } |
d459bfe0 | 851 | |
113a7413 BC |
852 | /* Clockdomain-to-clock/hwmod framework interface code */ |
853 | ||
854 | static int _clkdm_clk_hwmod_enable(struct clockdomain *clkdm) | |
855 | { | |
555e74ea RN |
856 | unsigned long flags; |
857 | ||
113a7413 BC |
858 | if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_enable) |
859 | return -EINVAL; | |
860 | ||
861 | /* | |
862 | * For arch's with no autodeps, clkcm_clk_enable | |
863 | * should be called for every clock instance or hwmod that is | |
864 | * enabled, so the clkdm can be force woken up. | |
865 | */ | |
866 | if ((atomic_inc_return(&clkdm->usecount) > 1) && autodeps) | |
867 | return 0; | |
868 | ||
555e74ea | 869 | spin_lock_irqsave(&clkdm->lock, flags); |
113a7413 BC |
870 | arch_clkdm->clkdm_clk_enable(clkdm); |
871 | pwrdm_wait_transition(clkdm->pwrdm.ptr); | |
872 | pwrdm_clkdm_state_switch(clkdm); | |
555e74ea | 873 | spin_unlock_irqrestore(&clkdm->lock, flags); |
113a7413 BC |
874 | |
875 | pr_debug("clockdomain: clkdm %s: enabled\n", clkdm->name); | |
876 | ||
877 | return 0; | |
878 | } | |
879 | ||
880 | static int _clkdm_clk_hwmod_disable(struct clockdomain *clkdm) | |
881 | { | |
555e74ea RN |
882 | unsigned long flags; |
883 | ||
113a7413 BC |
884 | if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_disable) |
885 | return -EINVAL; | |
886 | ||
887 | if (atomic_read(&clkdm->usecount) == 0) { | |
888 | WARN_ON(1); /* underflow */ | |
889 | return -ERANGE; | |
890 | } | |
891 | ||
892 | if (atomic_dec_return(&clkdm->usecount) > 0) | |
893 | return 0; | |
894 | ||
555e74ea | 895 | spin_lock_irqsave(&clkdm->lock, flags); |
113a7413 BC |
896 | arch_clkdm->clkdm_clk_disable(clkdm); |
897 | pwrdm_clkdm_state_switch(clkdm); | |
555e74ea | 898 | spin_unlock_irqrestore(&clkdm->lock, flags); |
113a7413 BC |
899 | |
900 | pr_debug("clockdomain: clkdm %s: disabled\n", clkdm->name); | |
901 | ||
902 | return 0; | |
903 | } | |
d459bfe0 PW |
904 | |
905 | /** | |
4da71ae6 | 906 | * clkdm_clk_enable - add an enabled downstream clock to this clkdm |
d459bfe0 PW |
907 | * @clkdm: struct clockdomain * |
908 | * @clk: struct clk * of the enabled downstream clock | |
909 | * | |
f0271d65 PW |
910 | * Increment the usecount of the clockdomain @clkdm and ensure that it |
911 | * is awake before @clk is enabled. Intended to be called by | |
912 | * clk_enable() code. If the clockdomain is in software-supervised | |
913 | * idle mode, force the clockdomain to wake. If the clockdomain is in | |
914 | * hardware-supervised idle mode, add clkdm-pwrdm autodependencies, to | |
915 | * ensure that devices in the clockdomain can be read from/written to | |
916 | * by on-chip processors. Returns -EINVAL if passed null pointers; | |
917 | * returns 0 upon success or if the clockdomain is in hwsup idle mode. | |
d459bfe0 | 918 | */ |
4da71ae6 | 919 | int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk) |
d459bfe0 | 920 | { |
d459bfe0 PW |
921 | /* |
922 | * XXX Rewrite this code to maintain a list of enabled | |
923 | * downstream clocks for debugging purposes? | |
924 | */ | |
925 | ||
113a7413 | 926 | if (!clk) |
d459bfe0 PW |
927 | return -EINVAL; |
928 | ||
113a7413 | 929 | return _clkdm_clk_hwmod_enable(clkdm); |
d459bfe0 PW |
930 | } |
931 | ||
932 | /** | |
4da71ae6 | 933 | * clkdm_clk_disable - remove an enabled downstream clock from this clkdm |
d459bfe0 PW |
934 | * @clkdm: struct clockdomain * |
935 | * @clk: struct clk * of the disabled downstream clock | |
936 | * | |
f0271d65 PW |
937 | * Decrement the usecount of this clockdomain @clkdm when @clk is |
938 | * disabled. Intended to be called by clk_disable() code. If the | |
939 | * clockdomain usecount goes to 0, put the clockdomain to sleep | |
940 | * (software-supervised mode) or remove the clkdm autodependencies | |
941 | * (hardware-supervised mode). Returns -EINVAL if passed null | |
113a7413 BC |
942 | * pointers; -ERANGE if the @clkdm usecount underflows; or returns 0 |
943 | * upon success or if the clockdomain is in hwsup idle mode. | |
d459bfe0 | 944 | */ |
4da71ae6 | 945 | int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk) |
d459bfe0 | 946 | { |
d459bfe0 PW |
947 | /* |
948 | * XXX Rewrite this code to maintain a list of enabled | |
949 | * downstream clocks for debugging purposes? | |
950 | */ | |
951 | ||
113a7413 | 952 | if (!clk) |
d459bfe0 PW |
953 | return -EINVAL; |
954 | ||
113a7413 BC |
955 | return _clkdm_clk_hwmod_disable(clkdm); |
956 | } | |
957 | ||
958 | /** | |
959 | * clkdm_hwmod_enable - add an enabled downstream hwmod to this clkdm | |
960 | * @clkdm: struct clockdomain * | |
961 | * @oh: struct omap_hwmod * of the enabled downstream hwmod | |
962 | * | |
963 | * Increment the usecount of the clockdomain @clkdm and ensure that it | |
964 | * is awake before @oh is enabled. Intended to be called by | |
965 | * module_enable() code. | |
966 | * If the clockdomain is in software-supervised idle mode, force the | |
967 | * clockdomain to wake. If the clockdomain is in hardware-supervised idle | |
968 | * mode, add clkdm-pwrdm autodependencies, to ensure that devices in the | |
969 | * clockdomain can be read from/written to by on-chip processors. | |
970 | * Returns -EINVAL if passed null pointers; | |
971 | * returns 0 upon success or if the clockdomain is in hwsup idle mode. | |
972 | */ | |
973 | int clkdm_hwmod_enable(struct clockdomain *clkdm, struct omap_hwmod *oh) | |
974 | { | |
975 | /* The clkdm attribute does not exist yet prior OMAP4 */ | |
976 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) | |
977 | return 0; | |
978 | ||
979 | /* | |
980 | * XXX Rewrite this code to maintain a list of enabled | |
981 | * downstream hwmods for debugging purposes? | |
982 | */ | |
983 | ||
984 | if (!oh) | |
4da71ae6 RN |
985 | return -EINVAL; |
986 | ||
113a7413 BC |
987 | return _clkdm_clk_hwmod_enable(clkdm); |
988 | } | |
d459bfe0 | 989 | |
113a7413 BC |
990 | /** |
991 | * clkdm_hwmod_disable - remove an enabled downstream hwmod from this clkdm | |
992 | * @clkdm: struct clockdomain * | |
993 | * @oh: struct omap_hwmod * of the disabled downstream hwmod | |
994 | * | |
995 | * Decrement the usecount of this clockdomain @clkdm when @oh is | |
996 | * disabled. Intended to be called by module_disable() code. | |
997 | * If the clockdomain usecount goes to 0, put the clockdomain to sleep | |
998 | * (software-supervised mode) or remove the clkdm autodependencies | |
999 | * (hardware-supervised mode). | |
1000 | * Returns -EINVAL if passed null pointers; -ERANGE if the @clkdm usecount | |
1001 | * underflows; or returns 0 upon success or if the clockdomain is in hwsup | |
1002 | * idle mode. | |
1003 | */ | |
1004 | int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh) | |
1005 | { | |
1006 | /* The clkdm attribute does not exist yet prior OMAP4 */ | |
1007 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) | |
d459bfe0 PW |
1008 | return 0; |
1009 | ||
113a7413 BC |
1010 | /* |
1011 | * XXX Rewrite this code to maintain a list of enabled | |
1012 | * downstream hwmods for debugging purposes? | |
1013 | */ | |
d459bfe0 | 1014 | |
113a7413 BC |
1015 | if (!oh) |
1016 | return -EINVAL; | |
fe617af7 | 1017 | |
113a7413 | 1018 | return _clkdm_clk_hwmod_disable(clkdm); |
d459bfe0 PW |
1019 | } |
1020 |