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/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 spin_lock_init(&clkdm->lock);
97 pr_debug("clockdomain: registered %s\n", clkdm->name);
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)
106 struct clkdm_dep *cd;
108 if (!clkdm || !deps || !omap_chip_is(clkdm->omap_chip))
109 return ERR_PTR(-EINVAL);
111 for (cd = deps; cd->clkdm_name; cd++) {
112 if (!omap_chip_is(cd->omap_chip))
115 if (!cd->clkdm && cd->clkdm_name)
116 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
118 if (cd->clkdm == clkdm)
123 return ERR_PTR(-ENOENT);
129 * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store
130 * @autodep: struct clkdm_autodep * to resolve
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
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.
141 * XXX autodeps are deprecated and should be removed at the earliest
144 static void _autodep_lookup(struct clkdm_autodep *autodep)
146 struct clockdomain *clkdm;
151 if (!omap_chip_is(autodep->omap_chip))
154 clkdm = clkdm_lookup(autodep->clkdm.name);
156 pr_err("clockdomain: autodeps: clockdomain %s does not exist\n",
157 autodep->clkdm.name);
158 clkdm = ERR_PTR(-ENOENT);
160 autodep->clkdm.ptr = clkdm;
164 * _clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable
165 * @clkdm: struct clockdomain *
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.
171 * XXX autodeps are deprecated and should be removed at the earliest
174 void _clkdm_add_autodeps(struct clockdomain *clkdm)
176 struct clkdm_autodep *autodep;
178 if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
181 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
182 if (IS_ERR(autodep->clkdm.ptr))
185 if (!omap_chip_is(autodep->omap_chip))
188 pr_debug("clockdomain: adding %s sleepdep/wkdep for "
189 "clkdm %s\n", autodep->clkdm.ptr->name,
192 clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr);
193 clkdm_add_wkdep(clkdm, autodep->clkdm.ptr);
198 * _clkdm_add_autodeps - remove auto sleepdeps/wkdeps from clkdm
199 * @clkdm: struct clockdomain *
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.
205 * XXX autodeps are deprecated and should be removed at the earliest
208 void _clkdm_del_autodeps(struct clockdomain *clkdm)
210 struct clkdm_autodep *autodep;
212 if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
215 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
216 if (IS_ERR(autodep->clkdm.ptr))
219 if (!omap_chip_is(autodep->omap_chip))
222 pr_debug("clockdomain: removing %s sleepdep/wkdep for "
223 "clkdm %s\n", autodep->clkdm.ptr->name,
226 clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr);
227 clkdm_del_wkdep(clkdm, autodep->clkdm.ptr);
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
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.
240 static void _resolve_clkdm_deps(struct clockdomain *clkdm,
241 struct clkdm_dep *clkdm_deps)
243 struct clkdm_dep *cd;
245 for (cd = clkdm_deps; cd && cd->clkdm_name; cd++) {
246 if (!omap_chip_is(cd->omap_chip))
250 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
252 WARN(!cd->clkdm, "clockdomain: %s: could not find clkdm %s while resolving dependencies - should never happen",
253 clkdm->name, cd->clkdm_name);
257 /* Public functions */
260 * clkdm_register_platform_funcs - register clockdomain implementation fns
261 * @co: func pointers for arch specific implementations
263 * Register the list of function pointers used to implement the
264 * clockdomain functions on different OMAP SoCs. Should be called
265 * before any other clkdm_register*() function. Returns -EINVAL if
266 * @co is null, -EEXIST if platform functions have already been
267 * registered, or 0 upon success.
269 int clkdm_register_platform_funcs(struct clkdm_ops *co)
283 * clkdm_register_clkdms - register SoC clockdomains
284 * @cs: pointer to an array of struct clockdomain to register
286 * Register the clockdomains available on a particular OMAP SoC. Must
287 * be called after clkdm_register_platform_funcs(). May be called
288 * multiple times. Returns -EACCES if called before
289 * clkdm_register_platform_funcs(); -EINVAL if the argument @cs is
290 * null; or 0 upon success.
292 int clkdm_register_clkdms(struct clockdomain **cs)
294 struct clockdomain **c = NULL;
302 for (c = cs; *c; c++)
309 * clkdm_register_autodeps - register autodeps (if required)
310 * @ia: pointer to a static array of struct clkdm_autodep to register
312 * Register clockdomain "automatic dependencies." These are
313 * clockdomain wakeup and sleep dependencies that are automatically
314 * added whenever the first clock inside a clockdomain is enabled, and
315 * removed whenever the last clock inside a clockdomain is disabled.
316 * These are currently only used on OMAP3 devices, and are deprecated,
317 * since they waste energy. However, until the OMAP2/3 IP block
318 * enable/disable sequence can be converted to match the OMAP4
319 * sequence, they are needed.
321 * Must be called only after all of the SoC clockdomains are
322 * registered, since the function will resolve autodep clockdomain
323 * names into clockdomain pointers.
325 * The struct clkdm_autodep @ia array must be static, as this function
326 * does not copy the array elements.
328 * Returns -EACCES if called before any clockdomains have been
329 * registered, -EINVAL if called with a null @ia argument, -EEXIST if
330 * autodeps have already been registered, or 0 upon success.
332 int clkdm_register_autodeps(struct clkdm_autodep *ia)
334 struct clkdm_autodep *a = NULL;
336 if (list_empty(&clkdm_list))
346 for (a = autodeps; a->clkdm.ptr; a++)
353 * clkdm_complete_init - set up the clockdomain layer
355 * Put all clockdomains into software-supervised mode; PM code should
356 * later enable hardware-supervised mode as appropriate. Must be
357 * called after clkdm_register_clkdms(). Returns -EACCES if called
358 * before clkdm_register_clkdms(), or 0 upon success.
360 int clkdm_complete_init(void)
362 struct clockdomain *clkdm;
364 if (list_empty(&clkdm_list))
367 list_for_each_entry(clkdm, &clkdm_list, node) {
368 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
370 else if (clkdm->flags & CLKDM_CAN_DISABLE_AUTO)
371 clkdm_deny_idle(clkdm);
373 _resolve_clkdm_deps(clkdm, clkdm->wkdep_srcs);
374 clkdm_clear_all_wkdeps(clkdm);
376 _resolve_clkdm_deps(clkdm, clkdm->sleepdep_srcs);
377 clkdm_clear_all_sleepdeps(clkdm);
384 * clkdm_lookup - look up a clockdomain by name, return a pointer
385 * @name: name of clockdomain
387 * Find a registered clockdomain by its name @name. Returns a pointer
388 * to the struct clockdomain if found, or NULL otherwise.
390 struct clockdomain *clkdm_lookup(const char *name)
392 struct clockdomain *clkdm, *temp_clkdm;
399 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
400 if (!strcmp(name, temp_clkdm->name)) {
410 * clkdm_for_each - call function on each registered clockdomain
411 * @fn: callback function *
413 * Call the supplied function @fn for each registered clockdomain.
414 * The callback function @fn can return anything but 0 to bail
415 * out early from the iterator. The callback function is called with
416 * the clkdm_mutex held, so no clockdomain structure manipulation
417 * functions should be called from the callback, although hardware
418 * clockdomain control functions are fine. Returns the last return
419 * value of the callback function, which should be 0 for success or
420 * anything else to indicate failure; or -EINVAL if the function pointer
423 int clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user),
426 struct clockdomain *clkdm;
432 list_for_each_entry(clkdm, &clkdm_list, node) {
433 ret = (*fn)(clkdm, user);
443 * clkdm_get_pwrdm - return a ptr to the pwrdm that this clkdm resides in
444 * @clkdm: struct clockdomain *
446 * Return a pointer to the struct powerdomain that the specified clockdomain
447 * @clkdm exists in, or returns NULL if @clkdm is NULL.
449 struct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm)
454 return clkdm->pwrdm.ptr;
458 /* Hardware clockdomain control */
461 * clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1
462 * @clkdm1: wake this struct clockdomain * up (dependent)
463 * @clkdm2: when this struct clockdomain * wakes up (source)
465 * When the clockdomain represented by @clkdm2 wakes up, wake up
466 * @clkdm1. Implemented in hardware on the OMAP, this feature is
467 * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
468 * Returns -EINVAL if presented with invalid clockdomain pointers,
469 * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
472 int clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
474 struct clkdm_dep *cd;
477 if (!clkdm1 || !clkdm2)
480 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
484 if (!arch_clkdm || !arch_clkdm->clkdm_add_wkdep)
488 pr_debug("clockdomain: hardware cannot set/clear wake up of "
489 "%s when %s wakes up\n", clkdm1->name, clkdm2->name);
493 if (atomic_inc_return(&cd->wkdep_usecount) == 1) {
494 pr_debug("clockdomain: hardware will wake up %s when %s wakes "
495 "up\n", clkdm1->name, clkdm2->name);
497 ret = arch_clkdm->clkdm_add_wkdep(clkdm1, clkdm2);
504 * clkdm_del_wkdep - remove a wakeup dependency from clkdm2 to clkdm1
505 * @clkdm1: wake this struct clockdomain * up (dependent)
506 * @clkdm2: when this struct clockdomain * wakes up (source)
508 * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
509 * wakes up. Returns -EINVAL if presented with invalid clockdomain
510 * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
513 int clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
515 struct clkdm_dep *cd;
518 if (!clkdm1 || !clkdm2)
521 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
525 if (!arch_clkdm || !arch_clkdm->clkdm_del_wkdep)
529 pr_debug("clockdomain: hardware cannot set/clear wake up of "
530 "%s when %s wakes up\n", clkdm1->name, clkdm2->name);
534 if (atomic_dec_return(&cd->wkdep_usecount) == 0) {
535 pr_debug("clockdomain: hardware will no longer wake up %s "
536 "after %s wakes up\n", clkdm1->name, clkdm2->name);
538 ret = arch_clkdm->clkdm_del_wkdep(clkdm1, clkdm2);
545 * clkdm_read_wkdep - read wakeup dependency state from clkdm2 to clkdm1
546 * @clkdm1: wake this struct clockdomain * up (dependent)
547 * @clkdm2: when this struct clockdomain * wakes up (source)
549 * Return 1 if a hardware wakeup dependency exists wherein @clkdm1 will be
550 * awoken when @clkdm2 wakes up; 0 if dependency is not set; -EINVAL
551 * if either clockdomain pointer is invalid; or -ENOENT if the hardware
554 * REVISIT: Currently this function only represents software-controllable
555 * wakeup dependencies. Wakeup dependencies fixed in hardware are not
558 int clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
560 struct clkdm_dep *cd;
563 if (!clkdm1 || !clkdm2)
566 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
570 if (!arch_clkdm || !arch_clkdm->clkdm_read_wkdep)
574 pr_debug("clockdomain: hardware cannot set/clear wake up of "
575 "%s when %s wakes up\n", clkdm1->name, clkdm2->name);
579 /* XXX It's faster to return the atomic wkdep_usecount */
580 return arch_clkdm->clkdm_read_wkdep(clkdm1, clkdm2);
584 * clkdm_clear_all_wkdeps - remove all wakeup dependencies from target clkdm
585 * @clkdm: struct clockdomain * to remove all wakeup dependencies from
587 * Remove all inter-clockdomain wakeup dependencies that could cause
588 * @clkdm to wake. Intended to be used during boot to initialize the
589 * PRCM to a known state, after all clockdomains are put into swsup idle
590 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
593 int clkdm_clear_all_wkdeps(struct clockdomain *clkdm)
598 if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_wkdeps)
601 return arch_clkdm->clkdm_clear_all_wkdeps(clkdm);
605 * clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1
606 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
607 * @clkdm2: when this struct clockdomain * is active (source)
609 * Prevent @clkdm1 from automatically going inactive (and then to
610 * retention or off) if @clkdm2 is active. Returns -EINVAL if
611 * presented with invalid clockdomain pointers or called on a machine
612 * that does not support software-configurable hardware sleep
613 * dependencies, -ENOENT if the specified dependency cannot be set in
614 * hardware, or 0 upon success.
616 int clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
618 struct clkdm_dep *cd;
621 if (!clkdm1 || !clkdm2)
624 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
628 if (!arch_clkdm || !arch_clkdm->clkdm_add_sleepdep)
632 pr_debug("clockdomain: hardware cannot set/clear sleep "
633 "dependency affecting %s from %s\n", clkdm1->name,
638 if (atomic_inc_return(&cd->sleepdep_usecount) == 1) {
639 pr_debug("clockdomain: will prevent %s from sleeping if %s "
640 "is active\n", clkdm1->name, clkdm2->name);
642 ret = arch_clkdm->clkdm_add_sleepdep(clkdm1, clkdm2);
649 * clkdm_del_sleepdep - remove a sleep dependency from clkdm2 to clkdm1
650 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
651 * @clkdm2: when this struct clockdomain * is active (source)
653 * Allow @clkdm1 to automatically go inactive (and then to retention or
654 * off), independent of the activity state of @clkdm2. Returns -EINVAL
655 * if presented with invalid clockdomain pointers or called on a machine
656 * that does not support software-configurable hardware sleep dependencies,
657 * -ENOENT if the specified dependency cannot be cleared in hardware, or
660 int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
662 struct clkdm_dep *cd;
665 if (!clkdm1 || !clkdm2)
668 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
672 if (!arch_clkdm || !arch_clkdm->clkdm_del_sleepdep)
676 pr_debug("clockdomain: hardware cannot set/clear sleep "
677 "dependency affecting %s from %s\n", clkdm1->name,
682 if (atomic_dec_return(&cd->sleepdep_usecount) == 0) {
683 pr_debug("clockdomain: will no longer prevent %s from "
684 "sleeping if %s is active\n", clkdm1->name,
687 ret = arch_clkdm->clkdm_del_sleepdep(clkdm1, clkdm2);
694 * clkdm_read_sleepdep - read sleep dependency state from clkdm2 to clkdm1
695 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
696 * @clkdm2: when this struct clockdomain * is active (source)
698 * Return 1 if a hardware sleep dependency exists wherein @clkdm1 will
699 * not be allowed to automatically go inactive if @clkdm2 is active;
700 * 0 if @clkdm1's automatic power state inactivity transition is independent
701 * of @clkdm2's; -EINVAL if either clockdomain pointer is invalid or called
702 * on a machine that does not support software-configurable hardware sleep
703 * dependencies; or -ENOENT if the hardware is incapable.
705 * REVISIT: Currently this function only represents software-controllable
706 * sleep dependencies. Sleep dependencies fixed in hardware are not
709 int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
711 struct clkdm_dep *cd;
714 if (!clkdm1 || !clkdm2)
717 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
721 if (!arch_clkdm || !arch_clkdm->clkdm_read_sleepdep)
725 pr_debug("clockdomain: hardware cannot set/clear sleep "
726 "dependency affecting %s from %s\n", clkdm1->name,
731 /* XXX It's faster to return the atomic sleepdep_usecount */
732 return arch_clkdm->clkdm_read_sleepdep(clkdm1, clkdm2);
736 * clkdm_clear_all_sleepdeps - remove all sleep dependencies from target clkdm
737 * @clkdm: struct clockdomain * to remove all sleep dependencies from
739 * Remove all inter-clockdomain sleep dependencies that could prevent
740 * @clkdm from idling. Intended to be used during boot to initialize the
741 * PRCM to a known state, after all clockdomains are put into swsup idle
742 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
745 int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm)
750 if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_sleepdeps)
753 return arch_clkdm->clkdm_clear_all_sleepdeps(clkdm);
757 * clkdm_sleep - force clockdomain sleep transition
758 * @clkdm: struct clockdomain *
760 * Instruct the CM to force a sleep transition on the specified
761 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if
762 * clockdomain does not support software-initiated sleep; 0 upon
765 int clkdm_sleep(struct clockdomain *clkdm)
773 if (!(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) {
774 pr_debug("clockdomain: %s does not support forcing "
775 "sleep via software\n", clkdm->name);
779 if (!arch_clkdm || !arch_clkdm->clkdm_sleep)
782 pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name);
784 spin_lock_irqsave(&clkdm->lock, flags);
785 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
786 ret = arch_clkdm->clkdm_sleep(clkdm);
787 spin_unlock_irqrestore(&clkdm->lock, flags);
792 * clkdm_wakeup - force clockdomain wakeup transition
793 * @clkdm: struct clockdomain *
795 * Instruct the CM to force a wakeup transition on the specified
796 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the
797 * clockdomain does not support software-controlled wakeup; 0 upon
800 int clkdm_wakeup(struct clockdomain *clkdm)
808 if (!(clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)) {
809 pr_debug("clockdomain: %s does not support forcing "
810 "wakeup via software\n", clkdm->name);
814 if (!arch_clkdm || !arch_clkdm->clkdm_wakeup)
817 pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name);
819 spin_lock_irqsave(&clkdm->lock, flags);
820 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
821 ret = arch_clkdm->clkdm_wakeup(clkdm);
822 ret |= pwrdm_state_switch(clkdm->pwrdm.ptr);
823 spin_unlock_irqrestore(&clkdm->lock, flags);
828 * clkdm_allow_idle - enable hwsup idle transitions for clkdm
829 * @clkdm: struct clockdomain *
831 * Allow the hardware to automatically switch the clockdomain @clkdm into
832 * active or idle states, as needed by downstream clocks. If the
833 * clockdomain has any downstream clocks enabled in the clock
834 * framework, wkdep/sleepdep autodependencies are added; this is so
835 * device drivers can read and write to the device. No return value.
837 void clkdm_allow_idle(struct clockdomain *clkdm)
844 if (!(clkdm->flags & CLKDM_CAN_ENABLE_AUTO)) {
845 pr_debug("clock: automatic idle transitions cannot be enabled "
846 "on clockdomain %s\n", clkdm->name);
850 if (!arch_clkdm || !arch_clkdm->clkdm_allow_idle)
853 pr_debug("clockdomain: enabling automatic idle transitions for %s\n",
856 spin_lock_irqsave(&clkdm->lock, flags);
857 clkdm->_flags |= _CLKDM_FLAG_HWSUP_ENABLED;
858 arch_clkdm->clkdm_allow_idle(clkdm);
859 pwrdm_clkdm_state_switch(clkdm);
860 spin_unlock_irqrestore(&clkdm->lock, flags);
864 * clkdm_deny_idle - disable hwsup idle transitions for clkdm
865 * @clkdm: struct clockdomain *
867 * Prevent the hardware from automatically switching the clockdomain
868 * @clkdm into inactive or idle states. If the clockdomain has
869 * downstream clocks enabled in the clock framework, wkdep/sleepdep
870 * autodependencies are removed. No return value.
872 void clkdm_deny_idle(struct clockdomain *clkdm)
879 if (!(clkdm->flags & CLKDM_CAN_DISABLE_AUTO)) {
880 pr_debug("clockdomain: automatic idle transitions cannot be "
881 "disabled on %s\n", clkdm->name);
885 if (!arch_clkdm || !arch_clkdm->clkdm_deny_idle)
888 pr_debug("clockdomain: disabling automatic idle transitions for %s\n",
891 spin_lock_irqsave(&clkdm->lock, flags);
892 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
893 arch_clkdm->clkdm_deny_idle(clkdm);
894 pwrdm_state_switch(clkdm->pwrdm.ptr);
895 spin_unlock_irqrestore(&clkdm->lock, flags);
899 * clkdm_in_hwsup - is clockdomain @clkdm have hardware-supervised idle enabled?
900 * @clkdm: struct clockdomain *
902 * Returns true if clockdomain @clkdm currently has
903 * hardware-supervised idle enabled, or false if it does not or if
904 * @clkdm is NULL. It is only valid to call this function after
905 * clkdm_init() has been called. This function does not actually read
906 * bits from the hardware; it instead tests an in-memory flag that is
907 * changed whenever the clockdomain code changes the auto-idle mode.
909 bool clkdm_in_hwsup(struct clockdomain *clkdm)
917 spin_lock_irqsave(&clkdm->lock, flags);
918 ret = (clkdm->_flags & _CLKDM_FLAG_HWSUP_ENABLED) ? true : false;
919 spin_unlock_irqrestore(&clkdm->lock, flags);
924 /* Clockdomain-to-clock/hwmod framework interface code */
926 static int _clkdm_clk_hwmod_enable(struct clockdomain *clkdm)
930 if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_enable)
934 * For arch's with no autodeps, clkcm_clk_enable
935 * should be called for every clock instance or hwmod that is
936 * enabled, so the clkdm can be force woken up.
938 if ((atomic_inc_return(&clkdm->usecount) > 1) && autodeps)
941 spin_lock_irqsave(&clkdm->lock, flags);
942 arch_clkdm->clkdm_clk_enable(clkdm);
943 pwrdm_wait_transition(clkdm->pwrdm.ptr);
944 pwrdm_clkdm_state_switch(clkdm);
945 spin_unlock_irqrestore(&clkdm->lock, flags);
947 pr_debug("clockdomain: clkdm %s: enabled\n", clkdm->name);
952 static int _clkdm_clk_hwmod_disable(struct clockdomain *clkdm)
956 if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_disable)
959 if (atomic_read(&clkdm->usecount) == 0) {
960 WARN_ON(1); /* underflow */
964 if (atomic_dec_return(&clkdm->usecount) > 0)
967 spin_lock_irqsave(&clkdm->lock, flags);
968 arch_clkdm->clkdm_clk_disable(clkdm);
969 pwrdm_clkdm_state_switch(clkdm);
970 spin_unlock_irqrestore(&clkdm->lock, flags);
972 pr_debug("clockdomain: clkdm %s: disabled\n", clkdm->name);
978 * clkdm_clk_enable - add an enabled downstream clock to this clkdm
979 * @clkdm: struct clockdomain *
980 * @clk: struct clk * of the enabled downstream clock
982 * Increment the usecount of the clockdomain @clkdm and ensure that it
983 * is awake before @clk is enabled. Intended to be called by
984 * clk_enable() code. If the clockdomain is in software-supervised
985 * idle mode, force the clockdomain to wake. If the clockdomain is in
986 * hardware-supervised idle mode, add clkdm-pwrdm autodependencies, to
987 * ensure that devices in the clockdomain can be read from/written to
988 * by on-chip processors. Returns -EINVAL if passed null pointers;
989 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
991 int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk)
994 * XXX Rewrite this code to maintain a list of enabled
995 * downstream clocks for debugging purposes?
1001 return _clkdm_clk_hwmod_enable(clkdm);
1005 * clkdm_clk_disable - remove an enabled downstream clock from this clkdm
1006 * @clkdm: struct clockdomain *
1007 * @clk: struct clk * of the disabled downstream clock
1009 * Decrement the usecount of this clockdomain @clkdm when @clk is
1010 * disabled. Intended to be called by clk_disable() code. If the
1011 * clockdomain usecount goes to 0, put the clockdomain to sleep
1012 * (software-supervised mode) or remove the clkdm autodependencies
1013 * (hardware-supervised mode). Returns -EINVAL if passed null
1014 * pointers; -ERANGE if the @clkdm usecount underflows; or returns 0
1015 * upon success or if the clockdomain is in hwsup idle mode.
1017 int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk)
1020 * XXX Rewrite this code to maintain a list of enabled
1021 * downstream clocks for debugging purposes?
1027 return _clkdm_clk_hwmod_disable(clkdm);
1031 * clkdm_hwmod_enable - add an enabled downstream hwmod to this clkdm
1032 * @clkdm: struct clockdomain *
1033 * @oh: struct omap_hwmod * of the enabled downstream hwmod
1035 * Increment the usecount of the clockdomain @clkdm and ensure that it
1036 * is awake before @oh is enabled. Intended to be called by
1037 * module_enable() code.
1038 * If the clockdomain is in software-supervised idle mode, force the
1039 * clockdomain to wake. If the clockdomain is in hardware-supervised idle
1040 * mode, add clkdm-pwrdm autodependencies, to ensure that devices in the
1041 * clockdomain can be read from/written to by on-chip processors.
1042 * Returns -EINVAL if passed null pointers;
1043 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
1045 int clkdm_hwmod_enable(struct clockdomain *clkdm, struct omap_hwmod *oh)
1047 /* The clkdm attribute does not exist yet prior OMAP4 */
1048 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1052 * XXX Rewrite this code to maintain a list of enabled
1053 * downstream hwmods for debugging purposes?
1059 return _clkdm_clk_hwmod_enable(clkdm);
1063 * clkdm_hwmod_disable - remove an enabled downstream hwmod from this clkdm
1064 * @clkdm: struct clockdomain *
1065 * @oh: struct omap_hwmod * of the disabled downstream hwmod
1067 * Decrement the usecount of this clockdomain @clkdm when @oh is
1068 * disabled. Intended to be called by module_disable() code.
1069 * If the clockdomain usecount goes to 0, put the clockdomain to sleep
1070 * (software-supervised mode) or remove the clkdm autodependencies
1071 * (hardware-supervised mode).
1072 * Returns -EINVAL if passed null pointers; -ERANGE if the @clkdm usecount
1073 * underflows; or returns 0 upon success or if the clockdomain is in hwsup
1076 int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh)
1078 /* The clkdm attribute does not exist yet prior OMAP4 */
1079 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1083 * XXX Rewrite this code to maintain a list of enabled
1084 * downstream hwmods for debugging purposes?
1090 return _clkdm_clk_hwmod_disable(clkdm);