2 * OMAP2/3/4 clockdomain framework functions
4 * Copyright (C) 2008-2010 Texas Instruments, Inc.
5 * Copyright (C) 2008-2010 Nokia Corporation
7 * Written by Paul Walmsley and Jouni Högander
8 * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
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.
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>
23 #include <linux/err.h>
27 #include <linux/bitops.h>
29 #include <plat/clock.h>
30 #include "clockdomain.h"
32 /* clkdm_list contains all registered struct clockdomains */
33 static LIST_HEAD(clkdm_list
);
35 /* array of clockdomain deps to be added/removed when clkdm in hwsup mode */
36 static struct clkdm_autodep
*autodeps
;
38 static struct clkdm_ops
*arch_clkdm
;
40 /* Private functions */
42 static struct clockdomain
*_clkdm_lookup(const char *name
)
44 struct clockdomain
*clkdm
, *temp_clkdm
;
51 list_for_each_entry(temp_clkdm
, &clkdm_list
, node
) {
52 if (!strcmp(name
, temp_clkdm
->name
)) {
62 * _clkdm_register - register a clockdomain
63 * @clkdm: struct clockdomain * to register
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.
69 static int _clkdm_register(struct clockdomain
*clkdm
)
71 struct powerdomain
*pwrdm
;
73 if (!clkdm
|| !clkdm
->name
)
76 if (!omap_chip_is(clkdm
->omap_chip
))
79 pwrdm
= pwrdm_lookup(clkdm
->pwrdm
.name
);
81 pr_err("clockdomain: %s: powerdomain %s does not exist\n",
82 clkdm
->name
, clkdm
->pwrdm
.name
);
85 clkdm
->pwrdm
.ptr
= pwrdm
;
87 /* Verify that the clockdomain is not already registered */
88 if (_clkdm_lookup(clkdm
->name
))
91 list_add(&clkdm
->node
, &clkdm_list
);
93 pwrdm_add_clkdm(pwrdm
, clkdm
);
95 pr_debug("clockdomain: registered %s\n", clkdm
->name
);
100 /* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */
101 static struct clkdm_dep
*_clkdm_deps_lookup(struct clockdomain
*clkdm
,
102 struct clkdm_dep
*deps
)
104 struct clkdm_dep
*cd
;
106 if (!clkdm
|| !deps
|| !omap_chip_is(clkdm
->omap_chip
))
107 return ERR_PTR(-EINVAL
);
109 for (cd
= deps
; cd
->clkdm_name
; cd
++) {
110 if (!omap_chip_is(cd
->omap_chip
))
113 if (!cd
->clkdm
&& cd
->clkdm_name
)
114 cd
->clkdm
= _clkdm_lookup(cd
->clkdm_name
);
116 if (cd
->clkdm
== clkdm
)
121 return ERR_PTR(-ENOENT
);
127 * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store
128 * @autodep: struct clkdm_autodep * to resolve
130 * Resolve autodep clockdomain names to clockdomain pointers via
131 * clkdm_lookup() and store the pointers in the autodep structure. An
132 * "autodep" is a clockdomain sleep/wakeup dependency that is
133 * automatically added and removed whenever clocks in the associated
134 * clockdomain are enabled or disabled (respectively) when the
135 * clockdomain is in hardware-supervised mode. Meant to be called
136 * once at clockdomain layer initialization, since these should remain
137 * fixed for a particular architecture. No return value.
139 * XXX autodeps are deprecated and should be removed at the earliest
142 static void _autodep_lookup(struct clkdm_autodep
*autodep
)
144 struct clockdomain
*clkdm
;
149 if (!omap_chip_is(autodep
->omap_chip
))
152 clkdm
= clkdm_lookup(autodep
->clkdm
.name
);
154 pr_err("clockdomain: autodeps: clockdomain %s does not exist\n",
155 autodep
->clkdm
.name
);
156 clkdm
= ERR_PTR(-ENOENT
);
158 autodep
->clkdm
.ptr
= clkdm
;
162 * _clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable
163 * @clkdm: struct clockdomain *
165 * Add the "autodep" sleep & wakeup dependencies to clockdomain 'clkdm'
166 * in hardware-supervised mode. Meant to be called from clock framework
167 * when a clock inside clockdomain 'clkdm' is enabled. No return value.
169 * XXX autodeps are deprecated and should be removed at the earliest
172 void _clkdm_add_autodeps(struct clockdomain
*clkdm
)
174 struct clkdm_autodep
*autodep
;
176 if (!autodeps
|| clkdm
->flags
& CLKDM_NO_AUTODEPS
)
179 for (autodep
= autodeps
; autodep
->clkdm
.ptr
; autodep
++) {
180 if (IS_ERR(autodep
->clkdm
.ptr
))
183 if (!omap_chip_is(autodep
->omap_chip
))
186 pr_debug("clockdomain: adding %s sleepdep/wkdep for "
187 "clkdm %s\n", autodep
->clkdm
.ptr
->name
,
190 clkdm_add_sleepdep(clkdm
, autodep
->clkdm
.ptr
);
191 clkdm_add_wkdep(clkdm
, autodep
->clkdm
.ptr
);
196 * _clkdm_add_autodeps - remove auto sleepdeps/wkdeps from clkdm
197 * @clkdm: struct clockdomain *
199 * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm'
200 * in hardware-supervised mode. Meant to be called from clock framework
201 * when a clock inside clockdomain 'clkdm' is disabled. No return value.
203 * XXX autodeps are deprecated and should be removed at the earliest
206 void _clkdm_del_autodeps(struct clockdomain
*clkdm
)
208 struct clkdm_autodep
*autodep
;
210 if (!autodeps
|| clkdm
->flags
& CLKDM_NO_AUTODEPS
)
213 for (autodep
= autodeps
; autodep
->clkdm
.ptr
; autodep
++) {
214 if (IS_ERR(autodep
->clkdm
.ptr
))
217 if (!omap_chip_is(autodep
->omap_chip
))
220 pr_debug("clockdomain: removing %s sleepdep/wkdep for "
221 "clkdm %s\n", autodep
->clkdm
.ptr
->name
,
224 clkdm_del_sleepdep(clkdm
, autodep
->clkdm
.ptr
);
225 clkdm_del_wkdep(clkdm
, autodep
->clkdm
.ptr
);
230 * _resolve_clkdm_deps() - resolve clkdm_names in @clkdm_deps to clkdms
231 * @clkdm: clockdomain that we are resolving dependencies for
232 * @clkdm_deps: ptr to array of struct clkdm_deps to resolve
234 * Iterates through @clkdm_deps, looking up the struct clockdomain named by
235 * clkdm_name and storing the clockdomain pointer in the struct clkdm_dep.
238 static void _resolve_clkdm_deps(struct clockdomain
*clkdm
,
239 struct clkdm_dep
*clkdm_deps
)
241 struct clkdm_dep
*cd
;
243 for (cd
= clkdm_deps
; cd
&& cd
->clkdm_name
; cd
++) {
244 if (!omap_chip_is(cd
->omap_chip
))
248 cd
->clkdm
= _clkdm_lookup(cd
->clkdm_name
);
250 WARN(!cd
->clkdm
, "clockdomain: %s: could not find clkdm %s while resolving dependencies - should never happen",
251 clkdm
->name
, cd
->clkdm_name
);
255 /* Public functions */
258 * clkdm_init - set up the clockdomain layer
259 * @clkdms: optional pointer to an array of clockdomains to register
260 * @init_autodeps: optional pointer to an array of autodeps to register
261 * @custom_funcs: func pointers for arch specific implementations
263 * Set up internal state. If a pointer to an array of clockdomains
264 * @clkdms was supplied, loop through the list of clockdomains,
265 * register all that are available on the current platform. Similarly,
266 * if a pointer to an array of clockdomain autodependencies
267 * @init_autodeps was provided, register those. No return value.
269 void clkdm_init(struct clockdomain
**clkdms
,
270 struct clkdm_autodep
*init_autodeps
,
271 struct clkdm_ops
*custom_funcs
)
273 struct clockdomain
**c
= NULL
;
274 struct clockdomain
*clkdm
;
275 struct clkdm_autodep
*autodep
= NULL
;
278 WARN(1, "No custom clkdm functions registered\n");
280 arch_clkdm
= custom_funcs
;
283 for (c
= clkdms
; *c
; c
++)
286 autodeps
= init_autodeps
;
288 for (autodep
= autodeps
; autodep
->clkdm
.ptr
; autodep
++)
289 _autodep_lookup(autodep
);
292 * Put all clockdomains into software-supervised mode; PM code
293 * should later enable hardware-supervised mode as appropriate
295 list_for_each_entry(clkdm
, &clkdm_list
, node
) {
296 if (clkdm
->flags
& CLKDM_CAN_FORCE_WAKEUP
)
298 else if (clkdm
->flags
& CLKDM_CAN_DISABLE_AUTO
)
299 clkdm_deny_idle(clkdm
);
301 _resolve_clkdm_deps(clkdm
, clkdm
->wkdep_srcs
);
302 clkdm_clear_all_wkdeps(clkdm
);
304 _resolve_clkdm_deps(clkdm
, clkdm
->sleepdep_srcs
);
305 clkdm_clear_all_sleepdeps(clkdm
);
310 * clkdm_lookup - look up a clockdomain by name, return a pointer
311 * @name: name of clockdomain
313 * Find a registered clockdomain by its name @name. Returns a pointer
314 * to the struct clockdomain if found, or NULL otherwise.
316 struct clockdomain
*clkdm_lookup(const char *name
)
318 struct clockdomain
*clkdm
, *temp_clkdm
;
325 list_for_each_entry(temp_clkdm
, &clkdm_list
, node
) {
326 if (!strcmp(name
, temp_clkdm
->name
)) {
336 * clkdm_for_each - call function on each registered clockdomain
337 * @fn: callback function *
339 * Call the supplied function @fn for each registered clockdomain.
340 * The callback function @fn can return anything but 0 to bail
341 * out early from the iterator. The callback function is called with
342 * the clkdm_mutex held, so no clockdomain structure manipulation
343 * functions should be called from the callback, although hardware
344 * clockdomain control functions are fine. Returns the last return
345 * value of the callback function, which should be 0 for success or
346 * anything else to indicate failure; or -EINVAL if the function pointer
349 int clkdm_for_each(int (*fn
)(struct clockdomain
*clkdm
, void *user
),
352 struct clockdomain
*clkdm
;
358 list_for_each_entry(clkdm
, &clkdm_list
, node
) {
359 ret
= (*fn
)(clkdm
, user
);
369 * clkdm_get_pwrdm - return a ptr to the pwrdm that this clkdm resides in
370 * @clkdm: struct clockdomain *
372 * Return a pointer to the struct powerdomain that the specified clockdomain
373 * @clkdm exists in, or returns NULL if @clkdm is NULL.
375 struct powerdomain
*clkdm_get_pwrdm(struct clockdomain
*clkdm
)
380 return clkdm
->pwrdm
.ptr
;
384 /* Hardware clockdomain control */
387 * clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1
388 * @clkdm1: wake this struct clockdomain * up (dependent)
389 * @clkdm2: when this struct clockdomain * wakes up (source)
391 * When the clockdomain represented by @clkdm2 wakes up, wake up
392 * @clkdm1. Implemented in hardware on the OMAP, this feature is
393 * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
394 * Returns -EINVAL if presented with invalid clockdomain pointers,
395 * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
398 int clkdm_add_wkdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
400 struct clkdm_dep
*cd
;
403 if (!clkdm1
|| !clkdm2
)
406 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->wkdep_srcs
);
410 if (!arch_clkdm
|| !arch_clkdm
->clkdm_add_wkdep
)
414 pr_debug("clockdomain: hardware cannot set/clear wake up of "
415 "%s when %s wakes up\n", clkdm1
->name
, clkdm2
->name
);
419 if (atomic_inc_return(&cd
->wkdep_usecount
) == 1) {
420 pr_debug("clockdomain: hardware will wake up %s when %s wakes "
421 "up\n", clkdm1
->name
, clkdm2
->name
);
423 ret
= arch_clkdm
->clkdm_add_wkdep(clkdm1
, clkdm2
);
430 * clkdm_del_wkdep - remove a wakeup dependency from clkdm2 to clkdm1
431 * @clkdm1: wake this struct clockdomain * up (dependent)
432 * @clkdm2: when this struct clockdomain * wakes up (source)
434 * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
435 * wakes up. Returns -EINVAL if presented with invalid clockdomain
436 * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
439 int clkdm_del_wkdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
441 struct clkdm_dep
*cd
;
444 if (!clkdm1
|| !clkdm2
)
447 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->wkdep_srcs
);
451 if (!arch_clkdm
|| !arch_clkdm
->clkdm_del_wkdep
)
455 pr_debug("clockdomain: hardware cannot set/clear wake up of "
456 "%s when %s wakes up\n", clkdm1
->name
, clkdm2
->name
);
460 if (atomic_dec_return(&cd
->wkdep_usecount
) == 0) {
461 pr_debug("clockdomain: hardware will no longer wake up %s "
462 "after %s wakes up\n", clkdm1
->name
, clkdm2
->name
);
464 ret
= arch_clkdm
->clkdm_del_wkdep(clkdm1
, clkdm2
);
471 * clkdm_read_wkdep - read wakeup dependency state from clkdm2 to clkdm1
472 * @clkdm1: wake this struct clockdomain * up (dependent)
473 * @clkdm2: when this struct clockdomain * wakes up (source)
475 * Return 1 if a hardware wakeup dependency exists wherein @clkdm1 will be
476 * awoken when @clkdm2 wakes up; 0 if dependency is not set; -EINVAL
477 * if either clockdomain pointer is invalid; or -ENOENT if the hardware
480 * REVISIT: Currently this function only represents software-controllable
481 * wakeup dependencies. Wakeup dependencies fixed in hardware are not
484 int clkdm_read_wkdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
486 struct clkdm_dep
*cd
;
489 if (!clkdm1
|| !clkdm2
)
492 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->wkdep_srcs
);
496 if (!arch_clkdm
|| !arch_clkdm
->clkdm_read_wkdep
)
500 pr_debug("clockdomain: hardware cannot set/clear wake up of "
501 "%s when %s wakes up\n", clkdm1
->name
, clkdm2
->name
);
505 /* XXX It's faster to return the atomic wkdep_usecount */
506 return arch_clkdm
->clkdm_read_wkdep(clkdm1
, clkdm2
);
510 * clkdm_clear_all_wkdeps - remove all wakeup dependencies from target clkdm
511 * @clkdm: struct clockdomain * to remove all wakeup dependencies from
513 * Remove all inter-clockdomain wakeup dependencies that could cause
514 * @clkdm to wake. Intended to be used during boot to initialize the
515 * PRCM to a known state, after all clockdomains are put into swsup idle
516 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
519 int clkdm_clear_all_wkdeps(struct clockdomain
*clkdm
)
524 if (!arch_clkdm
|| !arch_clkdm
->clkdm_clear_all_wkdeps
)
527 return arch_clkdm
->clkdm_clear_all_wkdeps(clkdm
);
531 * clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1
532 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
533 * @clkdm2: when this struct clockdomain * is active (source)
535 * Prevent @clkdm1 from automatically going inactive (and then to
536 * retention or off) if @clkdm2 is active. Returns -EINVAL if
537 * presented with invalid clockdomain pointers or called on a machine
538 * that does not support software-configurable hardware sleep
539 * dependencies, -ENOENT if the specified dependency cannot be set in
540 * hardware, or 0 upon success.
542 int clkdm_add_sleepdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
544 struct clkdm_dep
*cd
;
547 if (!clkdm1
|| !clkdm2
)
550 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->sleepdep_srcs
);
554 if (!arch_clkdm
|| !arch_clkdm
->clkdm_add_sleepdep
)
558 pr_debug("clockdomain: hardware cannot set/clear sleep "
559 "dependency affecting %s from %s\n", clkdm1
->name
,
564 if (atomic_inc_return(&cd
->sleepdep_usecount
) == 1) {
565 pr_debug("clockdomain: will prevent %s from sleeping if %s "
566 "is active\n", clkdm1
->name
, clkdm2
->name
);
568 ret
= arch_clkdm
->clkdm_add_sleepdep(clkdm1
, clkdm2
);
575 * clkdm_del_sleepdep - remove a sleep dependency from clkdm2 to clkdm1
576 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
577 * @clkdm2: when this struct clockdomain * is active (source)
579 * Allow @clkdm1 to automatically go inactive (and then to retention or
580 * off), independent of the activity state of @clkdm2. Returns -EINVAL
581 * if presented with invalid clockdomain pointers or called on a machine
582 * that does not support software-configurable hardware sleep dependencies,
583 * -ENOENT if the specified dependency cannot be cleared in hardware, or
586 int clkdm_del_sleepdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
588 struct clkdm_dep
*cd
;
591 if (!clkdm1
|| !clkdm2
)
594 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->sleepdep_srcs
);
598 if (!arch_clkdm
|| !arch_clkdm
->clkdm_del_sleepdep
)
602 pr_debug("clockdomain: hardware cannot set/clear sleep "
603 "dependency affecting %s from %s\n", clkdm1
->name
,
608 if (atomic_dec_return(&cd
->sleepdep_usecount
) == 0) {
609 pr_debug("clockdomain: will no longer prevent %s from "
610 "sleeping if %s is active\n", clkdm1
->name
,
613 ret
= arch_clkdm
->clkdm_del_sleepdep(clkdm1
, clkdm2
);
620 * clkdm_read_sleepdep - read sleep dependency state from clkdm2 to clkdm1
621 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
622 * @clkdm2: when this struct clockdomain * is active (source)
624 * Return 1 if a hardware sleep dependency exists wherein @clkdm1 will
625 * not be allowed to automatically go inactive if @clkdm2 is active;
626 * 0 if @clkdm1's automatic power state inactivity transition is independent
627 * of @clkdm2's; -EINVAL if either clockdomain pointer is invalid or called
628 * on a machine that does not support software-configurable hardware sleep
629 * dependencies; or -ENOENT if the hardware is incapable.
631 * REVISIT: Currently this function only represents software-controllable
632 * sleep dependencies. Sleep dependencies fixed in hardware are not
635 int clkdm_read_sleepdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
637 struct clkdm_dep
*cd
;
640 if (!clkdm1
|| !clkdm2
)
643 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->sleepdep_srcs
);
647 if (!arch_clkdm
|| !arch_clkdm
->clkdm_read_sleepdep
)
651 pr_debug("clockdomain: hardware cannot set/clear sleep "
652 "dependency affecting %s from %s\n", clkdm1
->name
,
657 /* XXX It's faster to return the atomic sleepdep_usecount */
658 return arch_clkdm
->clkdm_read_sleepdep(clkdm1
, clkdm2
);
662 * clkdm_clear_all_sleepdeps - remove all sleep dependencies from target clkdm
663 * @clkdm: struct clockdomain * to remove all sleep dependencies from
665 * Remove all inter-clockdomain sleep dependencies that could prevent
666 * @clkdm from idling. Intended to be used during boot to initialize the
667 * PRCM to a known state, after all clockdomains are put into swsup idle
668 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
671 int clkdm_clear_all_sleepdeps(struct clockdomain
*clkdm
)
676 if (!arch_clkdm
|| !arch_clkdm
->clkdm_clear_all_sleepdeps
)
679 return arch_clkdm
->clkdm_clear_all_sleepdeps(clkdm
);
683 * clkdm_sleep - force clockdomain sleep transition
684 * @clkdm: struct clockdomain *
686 * Instruct the CM to force a sleep transition on the specified
687 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if
688 * clockdomain does not support software-initiated sleep; 0 upon
691 int clkdm_sleep(struct clockdomain
*clkdm
)
696 if (!(clkdm
->flags
& CLKDM_CAN_FORCE_SLEEP
)) {
697 pr_debug("clockdomain: %s does not support forcing "
698 "sleep via software\n", clkdm
->name
);
702 if (!arch_clkdm
|| !arch_clkdm
->clkdm_sleep
)
705 pr_debug("clockdomain: forcing sleep on %s\n", clkdm
->name
);
707 return arch_clkdm
->clkdm_sleep(clkdm
);
711 * clkdm_wakeup - force clockdomain wakeup transition
712 * @clkdm: struct clockdomain *
714 * Instruct the CM to force a wakeup transition on the specified
715 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the
716 * clockdomain does not support software-controlled wakeup; 0 upon
719 int clkdm_wakeup(struct clockdomain
*clkdm
)
726 if (!(clkdm
->flags
& CLKDM_CAN_FORCE_WAKEUP
)) {
727 pr_debug("clockdomain: %s does not support forcing "
728 "wakeup via software\n", clkdm
->name
);
732 if (!arch_clkdm
|| !arch_clkdm
->clkdm_wakeup
)
735 pr_debug("clockdomain: forcing wakeup on %s\n", clkdm
->name
);
737 ret
= arch_clkdm
->clkdm_wakeup(clkdm
);
738 ret
|= pwrdm_wait_transition(clkdm
->pwrdm
.ptr
);
744 * clkdm_allow_idle - enable hwsup idle transitions for clkdm
745 * @clkdm: struct clockdomain *
747 * Allow the hardware to automatically switch the clockdomain @clkdm into
748 * active or idle states, as needed by downstream clocks. If the
749 * clockdomain has any downstream clocks enabled in the clock
750 * framework, wkdep/sleepdep autodependencies are added; this is so
751 * device drivers can read and write to the device. No return value.
753 void clkdm_allow_idle(struct clockdomain
*clkdm
)
758 if (!(clkdm
->flags
& CLKDM_CAN_ENABLE_AUTO
)) {
759 pr_debug("clock: automatic idle transitions cannot be enabled "
760 "on clockdomain %s\n", clkdm
->name
);
764 if (!arch_clkdm
|| !arch_clkdm
->clkdm_allow_idle
)
767 pr_debug("clockdomain: enabling automatic idle transitions for %s\n",
770 arch_clkdm
->clkdm_allow_idle(clkdm
);
771 pwrdm_clkdm_state_switch(clkdm
);
775 * clkdm_deny_idle - disable hwsup idle transitions for clkdm
776 * @clkdm: struct clockdomain *
778 * Prevent the hardware from automatically switching the clockdomain
779 * @clkdm into inactive or idle states. If the clockdomain has
780 * downstream clocks enabled in the clock framework, wkdep/sleepdep
781 * autodependencies are removed. No return value.
783 void clkdm_deny_idle(struct clockdomain
*clkdm
)
788 if (!(clkdm
->flags
& CLKDM_CAN_DISABLE_AUTO
)) {
789 pr_debug("clockdomain: automatic idle transitions cannot be "
790 "disabled on %s\n", clkdm
->name
);
794 if (!arch_clkdm
|| !arch_clkdm
->clkdm_deny_idle
)
797 pr_debug("clockdomain: disabling automatic idle transitions for %s\n",
800 arch_clkdm
->clkdm_deny_idle(clkdm
);
804 * clkdm_is_idle - Check if the clkdm hwsup/autoidle is enabled
805 * @clkdm: struct clockdomain *
807 * Returns true if the clockdomain is in hardware-supervised
808 * idle mode, or 0 otherwise.
811 int clkdm_is_idle(struct clockdomain
*clkdm
)
816 if (!arch_clkdm
|| !arch_clkdm
->clkdm_is_idle
)
819 pr_debug("clockdomain: reading idle state for %s\n", clkdm
->name
);
821 return arch_clkdm
->clkdm_is_idle(clkdm
);
825 /* Clockdomain-to-clock framework interface code */
828 * clkdm_clk_enable - add an enabled downstream clock to this clkdm
829 * @clkdm: struct clockdomain *
830 * @clk: struct clk * of the enabled downstream clock
832 * Increment the usecount of the clockdomain @clkdm and ensure that it
833 * is awake before @clk is enabled. Intended to be called by
834 * clk_enable() code. If the clockdomain is in software-supervised
835 * idle mode, force the clockdomain to wake. If the clockdomain is in
836 * hardware-supervised idle mode, add clkdm-pwrdm autodependencies, to
837 * ensure that devices in the clockdomain can be read from/written to
838 * by on-chip processors. Returns -EINVAL if passed null pointers;
839 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
841 int clkdm_clk_enable(struct clockdomain
*clkdm
, struct clk
*clk
)
844 * XXX Rewrite this code to maintain a list of enabled
845 * downstream clocks for debugging purposes?
851 if (!arch_clkdm
|| !arch_clkdm
->clkdm_clk_enable
)
855 * For arch's with no autodeps, clkcm_clk_enable
856 * should be called for every clock instance that is
857 * enabled, so the clkdm can be force woken up.
859 if ((atomic_inc_return(&clkdm
->usecount
) > 1) && autodeps
)
862 /* Clockdomain now has one enabled downstream clock */
864 pr_debug("clockdomain: clkdm %s: clk %s now enabled\n", clkdm
->name
,
867 arch_clkdm
->clkdm_clk_enable(clkdm
);
868 pwrdm_wait_transition(clkdm
->pwrdm
.ptr
);
869 pwrdm_clkdm_state_switch(clkdm
);
875 * clkdm_clk_disable - remove an enabled downstream clock from this clkdm
876 * @clkdm: struct clockdomain *
877 * @clk: struct clk * of the disabled downstream clock
879 * Decrement the usecount of this clockdomain @clkdm when @clk is
880 * disabled. Intended to be called by clk_disable() code. If the
881 * clockdomain usecount goes to 0, put the clockdomain to sleep
882 * (software-supervised mode) or remove the clkdm autodependencies
883 * (hardware-supervised mode). Returns -EINVAL if passed null
884 * pointers; -ERANGE if the @clkdm usecount underflows and debugging
885 * is enabled; or returns 0 upon success or if the clockdomain is in
888 int clkdm_clk_disable(struct clockdomain
*clkdm
, struct clk
*clk
)
891 * XXX Rewrite this code to maintain a list of enabled
892 * downstream clocks for debugging purposes?
898 if (!arch_clkdm
|| !arch_clkdm
->clkdm_clk_disable
)
902 if (atomic_read(&clkdm
->usecount
) == 0) {
903 WARN_ON(1); /* underflow */
908 if (atomic_dec_return(&clkdm
->usecount
) > 0)
911 /* All downstream clocks of this clockdomain are now disabled */
913 pr_debug("clockdomain: clkdm %s: clk %s now disabled\n", clkdm
->name
,
916 arch_clkdm
->clkdm_clk_disable(clkdm
);
917 pwrdm_clkdm_state_switch(clkdm
);