2 * OMAP2/3/4 clockdomain framework functions
4 * Copyright (C) 2008-2011 Texas Instruments, Inc.
5 * Copyright (C) 2008-2011 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/string.h>
21 #include <linux/delay.h>
22 #include <linux/clk.h>
23 #include <linux/limits.h>
24 #include <linux/err.h>
28 #include <linux/bitops.h>
32 #include "clockdomain.h"
34 /* clkdm_list contains all registered struct clockdomains */
35 static LIST_HEAD(clkdm_list
);
37 /* array of clockdomain deps to be added/removed when clkdm in hwsup mode */
38 static struct clkdm_autodep
*autodeps
;
40 static struct clkdm_ops
*arch_clkdm
;
42 /* Private functions */
44 static struct clockdomain
*_clkdm_lookup(const char *name
)
46 struct clockdomain
*clkdm
, *temp_clkdm
;
53 list_for_each_entry(temp_clkdm
, &clkdm_list
, node
) {
54 if (!strcmp(name
, temp_clkdm
->name
)) {
64 * _clkdm_register - register a clockdomain
65 * @clkdm: struct clockdomain * to register
67 * Adds a clockdomain to the internal clockdomain list.
68 * Returns -EINVAL if given a null pointer, -EEXIST if a clockdomain is
69 * already registered by the provided name, or 0 upon success.
71 static int _clkdm_register(struct clockdomain
*clkdm
)
73 struct powerdomain
*pwrdm
;
75 if (!clkdm
|| !clkdm
->name
)
78 pwrdm
= pwrdm_lookup(clkdm
->pwrdm
.name
);
80 pr_err("clockdomain: %s: powerdomain %s does not exist\n",
81 clkdm
->name
, clkdm
->pwrdm
.name
);
84 clkdm
->pwrdm
.ptr
= pwrdm
;
86 /* Verify that the clockdomain is not already registered */
87 if (_clkdm_lookup(clkdm
->name
))
90 list_add(&clkdm
->node
, &clkdm_list
);
92 pwrdm_add_clkdm(pwrdm
, clkdm
);
94 spin_lock_init(&clkdm
->lock
);
96 pr_debug("clockdomain: registered %s\n", clkdm
->name
);
101 /* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */
102 static struct clkdm_dep
*_clkdm_deps_lookup(struct clockdomain
*clkdm
,
103 struct clkdm_dep
*deps
)
105 struct clkdm_dep
*cd
;
108 return ERR_PTR(-EINVAL
);
110 for (cd
= deps
; cd
->clkdm_name
; cd
++) {
111 if (!cd
->clkdm
&& cd
->clkdm_name
)
112 cd
->clkdm
= _clkdm_lookup(cd
->clkdm_name
);
114 if (cd
->clkdm
== clkdm
)
119 return ERR_PTR(-ENOENT
);
125 * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store
126 * @autodep: struct clkdm_autodep * to resolve
128 * Resolve autodep clockdomain names to clockdomain pointers via
129 * clkdm_lookup() and store the pointers in the autodep structure. An
130 * "autodep" is a clockdomain sleep/wakeup dependency that is
131 * automatically added and removed whenever clocks in the associated
132 * clockdomain are enabled or disabled (respectively) when the
133 * clockdomain is in hardware-supervised mode. Meant to be called
134 * once at clockdomain layer initialization, since these should remain
135 * fixed for a particular architecture. No return value.
137 * XXX autodeps are deprecated and should be removed at the earliest
140 static void _autodep_lookup(struct clkdm_autodep
*autodep
)
142 struct clockdomain
*clkdm
;
147 clkdm
= clkdm_lookup(autodep
->clkdm
.name
);
149 pr_err("clockdomain: autodeps: clockdomain %s does not exist\n",
150 autodep
->clkdm
.name
);
151 clkdm
= ERR_PTR(-ENOENT
);
153 autodep
->clkdm
.ptr
= clkdm
;
157 * _clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable
158 * @clkdm: struct clockdomain *
160 * Add the "autodep" sleep & wakeup dependencies to clockdomain 'clkdm'
161 * in hardware-supervised mode. Meant to be called from clock framework
162 * when a clock inside clockdomain 'clkdm' is enabled. No return value.
164 * XXX autodeps are deprecated and should be removed at the earliest
167 void _clkdm_add_autodeps(struct clockdomain
*clkdm
)
169 struct clkdm_autodep
*autodep
;
171 if (!autodeps
|| clkdm
->flags
& CLKDM_NO_AUTODEPS
)
174 for (autodep
= autodeps
; autodep
->clkdm
.ptr
; autodep
++) {
175 if (IS_ERR(autodep
->clkdm
.ptr
))
178 pr_debug("clockdomain: %s: adding %s sleepdep/wkdep\n",
179 clkdm
->name
, autodep
->clkdm
.ptr
->name
);
181 clkdm_add_sleepdep(clkdm
, autodep
->clkdm
.ptr
);
182 clkdm_add_wkdep(clkdm
, autodep
->clkdm
.ptr
);
187 * _clkdm_add_autodeps - remove auto sleepdeps/wkdeps from clkdm
188 * @clkdm: struct clockdomain *
190 * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm'
191 * in hardware-supervised mode. Meant to be called from clock framework
192 * when a clock inside clockdomain 'clkdm' is disabled. No return value.
194 * XXX autodeps are deprecated and should be removed at the earliest
197 void _clkdm_del_autodeps(struct clockdomain
*clkdm
)
199 struct clkdm_autodep
*autodep
;
201 if (!autodeps
|| clkdm
->flags
& CLKDM_NO_AUTODEPS
)
204 for (autodep
= autodeps
; autodep
->clkdm
.ptr
; autodep
++) {
205 if (IS_ERR(autodep
->clkdm
.ptr
))
208 pr_debug("clockdomain: %s: removing %s sleepdep/wkdep\n",
209 clkdm
->name
, autodep
->clkdm
.ptr
->name
);
211 clkdm_del_sleepdep(clkdm
, autodep
->clkdm
.ptr
);
212 clkdm_del_wkdep(clkdm
, autodep
->clkdm
.ptr
);
217 * _resolve_clkdm_deps() - resolve clkdm_names in @clkdm_deps to clkdms
218 * @clkdm: clockdomain that we are resolving dependencies for
219 * @clkdm_deps: ptr to array of struct clkdm_deps to resolve
221 * Iterates through @clkdm_deps, looking up the struct clockdomain named by
222 * clkdm_name and storing the clockdomain pointer in the struct clkdm_dep.
225 static void _resolve_clkdm_deps(struct clockdomain
*clkdm
,
226 struct clkdm_dep
*clkdm_deps
)
228 struct clkdm_dep
*cd
;
230 for (cd
= clkdm_deps
; cd
&& cd
->clkdm_name
; cd
++) {
233 cd
->clkdm
= _clkdm_lookup(cd
->clkdm_name
);
235 WARN(!cd
->clkdm
, "clockdomain: %s: could not find clkdm %s while resolving dependencies - should never happen",
236 clkdm
->name
, cd
->clkdm_name
);
240 /* Public functions */
243 * clkdm_register_platform_funcs - register clockdomain implementation fns
244 * @co: func pointers for arch specific implementations
246 * Register the list of function pointers used to implement the
247 * clockdomain functions on different OMAP SoCs. Should be called
248 * before any other clkdm_register*() function. Returns -EINVAL if
249 * @co is null, -EEXIST if platform functions have already been
250 * registered, or 0 upon success.
252 int clkdm_register_platform_funcs(struct clkdm_ops
*co
)
266 * clkdm_register_clkdms - register SoC clockdomains
267 * @cs: pointer to an array of struct clockdomain to register
269 * Register the clockdomains available on a particular OMAP SoC. Must
270 * be called after clkdm_register_platform_funcs(). May be called
271 * multiple times. Returns -EACCES if called before
272 * clkdm_register_platform_funcs(); -EINVAL if the argument @cs is
273 * null; or 0 upon success.
275 int clkdm_register_clkdms(struct clockdomain
**cs
)
277 struct clockdomain
**c
= NULL
;
285 for (c
= cs
; *c
; c
++)
292 * clkdm_register_autodeps - register autodeps (if required)
293 * @ia: pointer to a static array of struct clkdm_autodep to register
295 * Register clockdomain "automatic dependencies." These are
296 * clockdomain wakeup and sleep dependencies that are automatically
297 * added whenever the first clock inside a clockdomain is enabled, and
298 * removed whenever the last clock inside a clockdomain is disabled.
299 * These are currently only used on OMAP3 devices, and are deprecated,
300 * since they waste energy. However, until the OMAP2/3 IP block
301 * enable/disable sequence can be converted to match the OMAP4
302 * sequence, they are needed.
304 * Must be called only after all of the SoC clockdomains are
305 * registered, since the function will resolve autodep clockdomain
306 * names into clockdomain pointers.
308 * The struct clkdm_autodep @ia array must be static, as this function
309 * does not copy the array elements.
311 * Returns -EACCES if called before any clockdomains have been
312 * registered, -EINVAL if called with a null @ia argument, -EEXIST if
313 * autodeps have already been registered, or 0 upon success.
315 int clkdm_register_autodeps(struct clkdm_autodep
*ia
)
317 struct clkdm_autodep
*a
= NULL
;
319 if (list_empty(&clkdm_list
))
329 for (a
= autodeps
; a
->clkdm
.ptr
; a
++)
336 * clkdm_complete_init - set up the clockdomain layer
338 * Put all clockdomains into software-supervised mode; PM code should
339 * later enable hardware-supervised mode as appropriate. Must be
340 * called after clkdm_register_clkdms(). Returns -EACCES if called
341 * before clkdm_register_clkdms(), or 0 upon success.
343 int clkdm_complete_init(void)
345 struct clockdomain
*clkdm
;
347 if (list_empty(&clkdm_list
))
350 list_for_each_entry(clkdm
, &clkdm_list
, node
) {
351 if (clkdm
->flags
& CLKDM_CAN_FORCE_WAKEUP
)
353 else if (clkdm
->flags
& CLKDM_CAN_DISABLE_AUTO
)
354 clkdm_deny_idle(clkdm
);
356 _resolve_clkdm_deps(clkdm
, clkdm
->wkdep_srcs
);
357 clkdm_clear_all_wkdeps(clkdm
);
359 _resolve_clkdm_deps(clkdm
, clkdm
->sleepdep_srcs
);
360 clkdm_clear_all_sleepdeps(clkdm
);
367 * clkdm_lookup - look up a clockdomain by name, return a pointer
368 * @name: name of clockdomain
370 * Find a registered clockdomain by its name @name. Returns a pointer
371 * to the struct clockdomain if found, or NULL otherwise.
373 struct clockdomain
*clkdm_lookup(const char *name
)
375 struct clockdomain
*clkdm
, *temp_clkdm
;
382 list_for_each_entry(temp_clkdm
, &clkdm_list
, node
) {
383 if (!strcmp(name
, temp_clkdm
->name
)) {
393 * clkdm_for_each - call function on each registered clockdomain
394 * @fn: callback function *
396 * Call the supplied function @fn for each registered clockdomain.
397 * The callback function @fn can return anything but 0 to bail
398 * out early from the iterator. The callback function is called with
399 * the clkdm_mutex held, so no clockdomain structure manipulation
400 * functions should be called from the callback, although hardware
401 * clockdomain control functions are fine. Returns the last return
402 * value of the callback function, which should be 0 for success or
403 * anything else to indicate failure; or -EINVAL if the function pointer
406 int clkdm_for_each(int (*fn
)(struct clockdomain
*clkdm
, void *user
),
409 struct clockdomain
*clkdm
;
415 list_for_each_entry(clkdm
, &clkdm_list
, node
) {
416 ret
= (*fn
)(clkdm
, user
);
426 * clkdm_get_pwrdm - return a ptr to the pwrdm that this clkdm resides in
427 * @clkdm: struct clockdomain *
429 * Return a pointer to the struct powerdomain that the specified clockdomain
430 * @clkdm exists in, or returns NULL if @clkdm is NULL.
432 struct powerdomain
*clkdm_get_pwrdm(struct clockdomain
*clkdm
)
437 return clkdm
->pwrdm
.ptr
;
441 /* Hardware clockdomain control */
444 * clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1
445 * @clkdm1: wake this struct clockdomain * up (dependent)
446 * @clkdm2: when this struct clockdomain * wakes up (source)
448 * When the clockdomain represented by @clkdm2 wakes up, wake up
449 * @clkdm1. Implemented in hardware on the OMAP, this feature is
450 * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
451 * Returns -EINVAL if presented with invalid clockdomain pointers,
452 * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
455 int clkdm_add_wkdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
457 struct clkdm_dep
*cd
;
460 if (!clkdm1
|| !clkdm2
)
463 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->wkdep_srcs
);
467 if (!arch_clkdm
|| !arch_clkdm
->clkdm_add_wkdep
)
471 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
472 clkdm1
->name
, clkdm2
->name
);
476 if (atomic_inc_return(&cd
->wkdep_usecount
) == 1) {
477 pr_debug("clockdomain: hardware will wake up %s when %s wakes up\n",
478 clkdm1
->name
, clkdm2
->name
);
480 ret
= arch_clkdm
->clkdm_add_wkdep(clkdm1
, clkdm2
);
487 * clkdm_del_wkdep - remove a wakeup dependency from clkdm2 to clkdm1
488 * @clkdm1: wake this struct clockdomain * up (dependent)
489 * @clkdm2: when this struct clockdomain * wakes up (source)
491 * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
492 * wakes up. Returns -EINVAL if presented with invalid clockdomain
493 * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
496 int clkdm_del_wkdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
498 struct clkdm_dep
*cd
;
501 if (!clkdm1
|| !clkdm2
)
504 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->wkdep_srcs
);
508 if (!arch_clkdm
|| !arch_clkdm
->clkdm_del_wkdep
)
512 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
513 clkdm1
->name
, clkdm2
->name
);
517 if (atomic_dec_return(&cd
->wkdep_usecount
) == 0) {
518 pr_debug("clockdomain: hardware will no longer wake up %s after %s wakes up\n",
519 clkdm1
->name
, clkdm2
->name
);
521 ret
= arch_clkdm
->clkdm_del_wkdep(clkdm1
, clkdm2
);
528 * clkdm_read_wkdep - read wakeup dependency state from clkdm2 to clkdm1
529 * @clkdm1: wake this struct clockdomain * up (dependent)
530 * @clkdm2: when this struct clockdomain * wakes up (source)
532 * Return 1 if a hardware wakeup dependency exists wherein @clkdm1 will be
533 * awoken when @clkdm2 wakes up; 0 if dependency is not set; -EINVAL
534 * if either clockdomain pointer is invalid; or -ENOENT if the hardware
537 * REVISIT: Currently this function only represents software-controllable
538 * wakeup dependencies. Wakeup dependencies fixed in hardware are not
541 int clkdm_read_wkdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
543 struct clkdm_dep
*cd
;
546 if (!clkdm1
|| !clkdm2
)
549 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->wkdep_srcs
);
553 if (!arch_clkdm
|| !arch_clkdm
->clkdm_read_wkdep
)
557 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
558 clkdm1
->name
, clkdm2
->name
);
562 /* XXX It's faster to return the atomic wkdep_usecount */
563 return arch_clkdm
->clkdm_read_wkdep(clkdm1
, clkdm2
);
567 * clkdm_clear_all_wkdeps - remove all wakeup dependencies from target clkdm
568 * @clkdm: struct clockdomain * to remove all wakeup dependencies from
570 * Remove all inter-clockdomain wakeup dependencies that could cause
571 * @clkdm to wake. Intended to be used during boot to initialize the
572 * PRCM to a known state, after all clockdomains are put into swsup idle
573 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
576 int clkdm_clear_all_wkdeps(struct clockdomain
*clkdm
)
581 if (!arch_clkdm
|| !arch_clkdm
->clkdm_clear_all_wkdeps
)
584 return arch_clkdm
->clkdm_clear_all_wkdeps(clkdm
);
588 * clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1
589 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
590 * @clkdm2: when this struct clockdomain * is active (source)
592 * Prevent @clkdm1 from automatically going inactive (and then to
593 * retention or off) if @clkdm2 is active. Returns -EINVAL if
594 * presented with invalid clockdomain pointers or called on a machine
595 * that does not support software-configurable hardware sleep
596 * dependencies, -ENOENT if the specified dependency cannot be set in
597 * hardware, or 0 upon success.
599 int clkdm_add_sleepdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
601 struct clkdm_dep
*cd
;
604 if (!clkdm1
|| !clkdm2
)
607 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->sleepdep_srcs
);
611 if (!arch_clkdm
|| !arch_clkdm
->clkdm_add_sleepdep
)
615 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
616 clkdm1
->name
, clkdm2
->name
);
620 if (atomic_inc_return(&cd
->sleepdep_usecount
) == 1) {
621 pr_debug("clockdomain: will prevent %s from sleeping if %s is active\n",
622 clkdm1
->name
, clkdm2
->name
);
624 ret
= arch_clkdm
->clkdm_add_sleepdep(clkdm1
, clkdm2
);
631 * clkdm_del_sleepdep - remove a sleep dependency from clkdm2 to clkdm1
632 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
633 * @clkdm2: when this struct clockdomain * is active (source)
635 * Allow @clkdm1 to automatically go inactive (and then to retention or
636 * off), independent of the activity state of @clkdm2. Returns -EINVAL
637 * if presented with invalid clockdomain pointers or called on a machine
638 * that does not support software-configurable hardware sleep dependencies,
639 * -ENOENT if the specified dependency cannot be cleared in hardware, or
642 int clkdm_del_sleepdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
644 struct clkdm_dep
*cd
;
647 if (!clkdm1
|| !clkdm2
)
650 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->sleepdep_srcs
);
654 if (!arch_clkdm
|| !arch_clkdm
->clkdm_del_sleepdep
)
658 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
659 clkdm1
->name
, clkdm2
->name
);
663 if (atomic_dec_return(&cd
->sleepdep_usecount
) == 0) {
664 pr_debug("clockdomain: will no longer prevent %s from sleeping if %s is active\n",
665 clkdm1
->name
, clkdm2
->name
);
667 ret
= arch_clkdm
->clkdm_del_sleepdep(clkdm1
, clkdm2
);
674 * clkdm_read_sleepdep - read sleep dependency state from clkdm2 to clkdm1
675 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
676 * @clkdm2: when this struct clockdomain * is active (source)
678 * Return 1 if a hardware sleep dependency exists wherein @clkdm1 will
679 * not be allowed to automatically go inactive if @clkdm2 is active;
680 * 0 if @clkdm1's automatic power state inactivity transition is independent
681 * of @clkdm2's; -EINVAL if either clockdomain pointer is invalid or called
682 * on a machine that does not support software-configurable hardware sleep
683 * dependencies; or -ENOENT if the hardware is incapable.
685 * REVISIT: Currently this function only represents software-controllable
686 * sleep dependencies. Sleep dependencies fixed in hardware are not
689 int clkdm_read_sleepdep(struct clockdomain
*clkdm1
, struct clockdomain
*clkdm2
)
691 struct clkdm_dep
*cd
;
694 if (!clkdm1
|| !clkdm2
)
697 cd
= _clkdm_deps_lookup(clkdm2
, clkdm1
->sleepdep_srcs
);
701 if (!arch_clkdm
|| !arch_clkdm
->clkdm_read_sleepdep
)
705 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
706 clkdm1
->name
, clkdm2
->name
);
710 /* XXX It's faster to return the atomic sleepdep_usecount */
711 return arch_clkdm
->clkdm_read_sleepdep(clkdm1
, clkdm2
);
715 * clkdm_clear_all_sleepdeps - remove all sleep dependencies from target clkdm
716 * @clkdm: struct clockdomain * to remove all sleep dependencies from
718 * Remove all inter-clockdomain sleep dependencies that could prevent
719 * @clkdm from idling. Intended to be used during boot to initialize the
720 * PRCM to a known state, after all clockdomains are put into swsup idle
721 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
724 int clkdm_clear_all_sleepdeps(struct clockdomain
*clkdm
)
729 if (!arch_clkdm
|| !arch_clkdm
->clkdm_clear_all_sleepdeps
)
732 return arch_clkdm
->clkdm_clear_all_sleepdeps(clkdm
);
736 * clkdm_sleep - force clockdomain sleep transition
737 * @clkdm: struct clockdomain *
739 * Instruct the CM to force a sleep transition on the specified
740 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if
741 * clockdomain does not support software-initiated sleep; 0 upon
744 int clkdm_sleep(struct clockdomain
*clkdm
)
752 if (!(clkdm
->flags
& CLKDM_CAN_FORCE_SLEEP
)) {
753 pr_debug("clockdomain: %s does not support forcing sleep via software\n",
758 if (!arch_clkdm
|| !arch_clkdm
->clkdm_sleep
)
761 pr_debug("clockdomain: forcing sleep on %s\n", clkdm
->name
);
763 spin_lock_irqsave(&clkdm
->lock
, flags
);
764 clkdm
->_flags
&= ~_CLKDM_FLAG_HWSUP_ENABLED
;
765 ret
= arch_clkdm
->clkdm_sleep(clkdm
);
766 spin_unlock_irqrestore(&clkdm
->lock
, flags
);
771 * clkdm_wakeup - force clockdomain wakeup transition
772 * @clkdm: struct clockdomain *
774 * Instruct the CM to force a wakeup transition on the specified
775 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the
776 * clockdomain does not support software-controlled wakeup; 0 upon
779 int clkdm_wakeup(struct clockdomain
*clkdm
)
787 if (!(clkdm
->flags
& CLKDM_CAN_FORCE_WAKEUP
)) {
788 pr_debug("clockdomain: %s does not support forcing wakeup via software\n",
793 if (!arch_clkdm
|| !arch_clkdm
->clkdm_wakeup
)
796 pr_debug("clockdomain: forcing wakeup on %s\n", clkdm
->name
);
798 spin_lock_irqsave(&clkdm
->lock
, flags
);
799 clkdm
->_flags
&= ~_CLKDM_FLAG_HWSUP_ENABLED
;
800 ret
= arch_clkdm
->clkdm_wakeup(clkdm
);
801 ret
|= pwrdm_state_switch(clkdm
->pwrdm
.ptr
);
802 spin_unlock_irqrestore(&clkdm
->lock
, flags
);
807 * clkdm_allow_idle - enable hwsup idle transitions for clkdm
808 * @clkdm: struct clockdomain *
810 * Allow the hardware to automatically switch the clockdomain @clkdm into
811 * active or idle states, as needed by downstream clocks. If the
812 * clockdomain has any downstream clocks enabled in the clock
813 * framework, wkdep/sleepdep autodependencies are added; this is so
814 * device drivers can read and write to the device. No return value.
816 void clkdm_allow_idle(struct clockdomain
*clkdm
)
823 if (!(clkdm
->flags
& CLKDM_CAN_ENABLE_AUTO
)) {
824 pr_debug("clock: %s: automatic idle transitions cannot be enabled\n",
829 if (!arch_clkdm
|| !arch_clkdm
->clkdm_allow_idle
)
832 pr_debug("clockdomain: enabling automatic idle transitions for %s\n",
835 spin_lock_irqsave(&clkdm
->lock
, flags
);
836 clkdm
->_flags
|= _CLKDM_FLAG_HWSUP_ENABLED
;
837 arch_clkdm
->clkdm_allow_idle(clkdm
);
838 pwrdm_state_switch(clkdm
->pwrdm
.ptr
);
839 spin_unlock_irqrestore(&clkdm
->lock
, flags
);
843 * clkdm_deny_idle - disable hwsup idle transitions for clkdm
844 * @clkdm: struct clockdomain *
846 * Prevent the hardware from automatically switching the clockdomain
847 * @clkdm into inactive or idle states. If the clockdomain has
848 * downstream clocks enabled in the clock framework, wkdep/sleepdep
849 * autodependencies are removed. No return value.
851 void clkdm_deny_idle(struct clockdomain
*clkdm
)
858 if (!(clkdm
->flags
& CLKDM_CAN_DISABLE_AUTO
)) {
859 pr_debug("clockdomain: %s: automatic idle transitions cannot be disabled\n",
864 if (!arch_clkdm
|| !arch_clkdm
->clkdm_deny_idle
)
867 pr_debug("clockdomain: disabling automatic idle transitions for %s\n",
870 spin_lock_irqsave(&clkdm
->lock
, flags
);
871 clkdm
->_flags
&= ~_CLKDM_FLAG_HWSUP_ENABLED
;
872 arch_clkdm
->clkdm_deny_idle(clkdm
);
873 pwrdm_state_switch(clkdm
->pwrdm
.ptr
);
874 spin_unlock_irqrestore(&clkdm
->lock
, flags
);
878 * clkdm_in_hwsup - is clockdomain @clkdm have hardware-supervised idle enabled?
879 * @clkdm: struct clockdomain *
881 * Returns true if clockdomain @clkdm currently has
882 * hardware-supervised idle enabled, or false if it does not or if
883 * @clkdm is NULL. It is only valid to call this function after
884 * clkdm_init() has been called. This function does not actually read
885 * bits from the hardware; it instead tests an in-memory flag that is
886 * changed whenever the clockdomain code changes the auto-idle mode.
888 bool clkdm_in_hwsup(struct clockdomain
*clkdm
)
896 spin_lock_irqsave(&clkdm
->lock
, flags
);
897 ret
= (clkdm
->_flags
& _CLKDM_FLAG_HWSUP_ENABLED
) ? true : false;
898 spin_unlock_irqrestore(&clkdm
->lock
, flags
);
904 * clkdm_missing_idle_reporting - can @clkdm enter autoidle even if in use?
905 * @clkdm: struct clockdomain *
907 * Returns true if clockdomain @clkdm has the
908 * CLKDM_MISSING_IDLE_REPORTING flag set, or false if not or @clkdm is
909 * null. More information is available in the documentation for the
910 * CLKDM_MISSING_IDLE_REPORTING macro.
912 bool clkdm_missing_idle_reporting(struct clockdomain
*clkdm
)
917 return (clkdm
->flags
& CLKDM_MISSING_IDLE_REPORTING
) ? true : false;
920 /* Clockdomain-to-clock/hwmod framework interface code */
922 static int _clkdm_clk_hwmod_enable(struct clockdomain
*clkdm
)
926 if (!clkdm
|| !arch_clkdm
|| !arch_clkdm
->clkdm_clk_enable
)
930 * For arch's with no autodeps, clkcm_clk_enable
931 * should be called for every clock instance or hwmod that is
932 * enabled, so the clkdm can be force woken up.
934 if ((atomic_inc_return(&clkdm
->usecount
) > 1) && autodeps
)
937 spin_lock_irqsave(&clkdm
->lock
, flags
);
938 arch_clkdm
->clkdm_clk_enable(clkdm
);
939 pwrdm_state_switch(clkdm
->pwrdm
.ptr
);
940 spin_unlock_irqrestore(&clkdm
->lock
, flags
);
942 pr_debug("clockdomain: %s: enabled\n", clkdm
->name
);
947 static int _clkdm_clk_hwmod_disable(struct clockdomain
*clkdm
)
951 if (!clkdm
|| !arch_clkdm
|| !arch_clkdm
->clkdm_clk_disable
)
954 if (atomic_read(&clkdm
->usecount
) == 0) {
955 WARN_ON(1); /* underflow */
959 if (atomic_dec_return(&clkdm
->usecount
) > 0)
962 spin_lock_irqsave(&clkdm
->lock
, flags
);
963 arch_clkdm
->clkdm_clk_disable(clkdm
);
964 pwrdm_state_switch(clkdm
->pwrdm
.ptr
);
965 spin_unlock_irqrestore(&clkdm
->lock
, flags
);
967 pr_debug("clockdomain: %s: disabled\n", clkdm
->name
);
973 * clkdm_clk_enable - add an enabled downstream clock to this clkdm
974 * @clkdm: struct clockdomain *
975 * @clk: struct clk * of the enabled downstream clock
977 * Increment the usecount of the clockdomain @clkdm and ensure that it
978 * is awake before @clk is enabled. Intended to be called by
979 * clk_enable() code. If the clockdomain is in software-supervised
980 * idle mode, force the clockdomain to wake. If the clockdomain is in
981 * hardware-supervised idle mode, add clkdm-pwrdm autodependencies, to
982 * ensure that devices in the clockdomain can be read from/written to
983 * by on-chip processors. Returns -EINVAL if passed null pointers;
984 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
986 int clkdm_clk_enable(struct clockdomain
*clkdm
, struct clk
*clk
)
989 * XXX Rewrite this code to maintain a list of enabled
990 * downstream clocks for debugging purposes?
996 return _clkdm_clk_hwmod_enable(clkdm
);
1000 * clkdm_clk_disable - remove an enabled downstream clock from this clkdm
1001 * @clkdm: struct clockdomain *
1002 * @clk: struct clk * of the disabled downstream clock
1004 * Decrement the usecount of this clockdomain @clkdm when @clk is
1005 * disabled. Intended to be called by clk_disable() code. If the
1006 * clockdomain usecount goes to 0, put the clockdomain to sleep
1007 * (software-supervised mode) or remove the clkdm autodependencies
1008 * (hardware-supervised mode). Returns -EINVAL if passed null
1009 * pointers; -ERANGE if the @clkdm usecount underflows; or returns 0
1010 * upon success or if the clockdomain is in hwsup idle mode.
1012 int clkdm_clk_disable(struct clockdomain
*clkdm
, struct clk
*clk
)
1015 * XXX Rewrite this code to maintain a list of enabled
1016 * downstream clocks for debugging purposes?
1022 return _clkdm_clk_hwmod_disable(clkdm
);
1026 * clkdm_hwmod_enable - add an enabled downstream hwmod to this clkdm
1027 * @clkdm: struct clockdomain *
1028 * @oh: struct omap_hwmod * of the enabled downstream hwmod
1030 * Increment the usecount of the clockdomain @clkdm and ensure that it
1031 * is awake before @oh is enabled. Intended to be called by
1032 * module_enable() code.
1033 * If the clockdomain is in software-supervised idle mode, force the
1034 * clockdomain to wake. If the clockdomain is in hardware-supervised idle
1035 * mode, add clkdm-pwrdm autodependencies, to ensure that devices in the
1036 * clockdomain can be read from/written to by on-chip processors.
1037 * Returns -EINVAL if passed null pointers;
1038 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
1040 int clkdm_hwmod_enable(struct clockdomain
*clkdm
, struct omap_hwmod
*oh
)
1042 /* The clkdm attribute does not exist yet prior OMAP4 */
1043 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1047 * XXX Rewrite this code to maintain a list of enabled
1048 * downstream hwmods for debugging purposes?
1054 return _clkdm_clk_hwmod_enable(clkdm
);
1058 * clkdm_hwmod_disable - remove an enabled downstream hwmod from this clkdm
1059 * @clkdm: struct clockdomain *
1060 * @oh: struct omap_hwmod * of the disabled downstream hwmod
1062 * Decrement the usecount of this clockdomain @clkdm when @oh is
1063 * disabled. Intended to be called by module_disable() code.
1064 * If the clockdomain usecount goes to 0, put the clockdomain to sleep
1065 * (software-supervised mode) or remove the clkdm autodependencies
1066 * (hardware-supervised mode).
1067 * Returns -EINVAL if passed null pointers; -ERANGE if the @clkdm usecount
1068 * underflows; or returns 0 upon success or if the clockdomain is in hwsup
1071 int clkdm_hwmod_disable(struct clockdomain
*clkdm
, struct omap_hwmod
*oh
)
1073 /* The clkdm attribute does not exist yet prior OMAP4 */
1074 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1078 * XXX Rewrite this code to maintain a list of enabled
1079 * downstream hwmods for debugging purposes?
1085 return _clkdm_clk_hwmod_disable(clkdm
);