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 "prm2xxx_3xxx.h"
30 #include "prm-regbits-24xx.h"
31 #include "cm2xxx_3xxx.h"
33 #include <plat/clock.h>
34 #include <plat/powerdomain.h>
35 #include <plat/clockdomain.h>
36 #include <plat/prcm.h>
38 /* clkdm_list contains all registered struct clockdomains */
39 static LIST_HEAD(clkdm_list);
41 /* array of clockdomain deps to be added/removed when clkdm in hwsup mode */
42 static struct clkdm_autodep *autodeps;
45 /* Private functions */
47 static struct clockdomain *_clkdm_lookup(const char *name)
49 struct clockdomain *clkdm, *temp_clkdm;
56 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
57 if (!strcmp(name, temp_clkdm->name)) {
67 * _clkdm_register - register a clockdomain
68 * @clkdm: struct clockdomain * to register
70 * Adds a clockdomain to the internal clockdomain list.
71 * Returns -EINVAL if given a null pointer, -EEXIST if a clockdomain is
72 * already registered by the provided name, or 0 upon success.
74 static int _clkdm_register(struct clockdomain *clkdm)
76 struct powerdomain *pwrdm;
78 if (!clkdm || !clkdm->name)
81 if (!omap_chip_is(clkdm->omap_chip))
84 pwrdm = pwrdm_lookup(clkdm->pwrdm.name);
86 pr_err("clockdomain: %s: powerdomain %s does not exist\n",
87 clkdm->name, clkdm->pwrdm.name);
90 clkdm->pwrdm.ptr = pwrdm;
92 /* Verify that the clockdomain is not already registered */
93 if (_clkdm_lookup(clkdm->name))
96 list_add(&clkdm->node, &clkdm_list);
98 pwrdm_add_clkdm(pwrdm, clkdm);
100 pr_debug("clockdomain: registered %s\n", clkdm->name);
105 /* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */
106 static struct clkdm_dep *_clkdm_deps_lookup(struct clockdomain *clkdm,
107 struct clkdm_dep *deps)
109 struct clkdm_dep *cd;
111 if (!clkdm || !deps || !omap_chip_is(clkdm->omap_chip))
112 return ERR_PTR(-EINVAL);
114 for (cd = deps; cd->clkdm_name; cd++) {
115 if (!omap_chip_is(cd->omap_chip))
118 if (!cd->clkdm && cd->clkdm_name)
119 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
121 if (cd->clkdm == clkdm)
126 return ERR_PTR(-ENOENT);
132 * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store
133 * @autodep: struct clkdm_autodep * to resolve
135 * Resolve autodep clockdomain names to clockdomain pointers via
136 * clkdm_lookup() and store the pointers in the autodep structure. An
137 * "autodep" is a clockdomain sleep/wakeup dependency that is
138 * automatically added and removed whenever clocks in the associated
139 * clockdomain are enabled or disabled (respectively) when the
140 * clockdomain is in hardware-supervised mode. Meant to be called
141 * once at clockdomain layer initialization, since these should remain
142 * fixed for a particular architecture. No return value.
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 static void _clkdm_add_autodeps(struct clockdomain *clkdm)
173 struct clkdm_autodep *autodep;
178 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
179 if (IS_ERR(autodep->clkdm.ptr))
182 if (!omap_chip_is(autodep->omap_chip))
185 pr_debug("clockdomain: adding %s sleepdep/wkdep for "
186 "clkdm %s\n", autodep->clkdm.ptr->name,
189 clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr);
190 clkdm_add_wkdep(clkdm, autodep->clkdm.ptr);
195 * _clkdm_add_autodeps - remove auto sleepdeps/wkdeps from clkdm
196 * @clkdm: struct clockdomain *
198 * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm'
199 * in hardware-supervised mode. Meant to be called from clock framework
200 * when a clock inside clockdomain 'clkdm' is disabled. No return value.
202 static void _clkdm_del_autodeps(struct clockdomain *clkdm)
204 struct clkdm_autodep *autodep;
209 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
210 if (IS_ERR(autodep->clkdm.ptr))
213 if (!omap_chip_is(autodep->omap_chip))
216 pr_debug("clockdomain: removing %s sleepdep/wkdep for "
217 "clkdm %s\n", autodep->clkdm.ptr->name,
220 clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr);
221 clkdm_del_wkdep(clkdm, autodep->clkdm.ptr);
226 * _omap2_clkdm_set_hwsup - set the hwsup idle transition bit
227 * @clkdm: struct clockdomain *
228 * @enable: int 0 to disable, 1 to enable
230 * Internal helper for actually switching the bit that controls hwsup
231 * idle transitions for clkdm.
233 static void _omap2_clkdm_set_hwsup(struct clockdomain *clkdm, int enable)
237 if (cpu_is_omap24xx()) {
239 bits = OMAP24XX_CLKSTCTRL_ENABLE_AUTO;
241 bits = OMAP24XX_CLKSTCTRL_DISABLE_AUTO;
242 } else if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
244 bits = OMAP34XX_CLKSTCTRL_ENABLE_AUTO;
246 bits = OMAP34XX_CLKSTCTRL_DISABLE_AUTO;
251 bits = bits << __ffs(clkdm->clktrctrl_mask);
253 v = __raw_readl(clkdm->clkstctrl_reg);
254 v &= ~(clkdm->clktrctrl_mask);
256 __raw_writel(v, clkdm->clkstctrl_reg);
260 /* Public functions */
263 * clkdm_init - set up the clockdomain layer
264 * @clkdms: optional pointer to an array of clockdomains to register
265 * @init_autodeps: optional pointer to an array of autodeps to register
267 * Set up internal state. If a pointer to an array of clockdomains
268 * @clkdms was supplied, loop through the list of clockdomains,
269 * register all that are available on the current platform. Similarly,
270 * if a pointer to an array of clockdomain autodependencies
271 * @init_autodeps was provided, register those. No return value.
273 void clkdm_init(struct clockdomain **clkdms,
274 struct clkdm_autodep *init_autodeps)
276 struct clockdomain **c = NULL;
277 struct clockdomain *clkdm;
278 struct clkdm_autodep *autodep = NULL;
281 for (c = clkdms; *c; c++)
284 autodeps = init_autodeps;
286 for (autodep = autodeps; autodep->clkdm.ptr; autodep++)
287 _autodep_lookup(autodep);
290 * Put all clockdomains into software-supervised mode; PM code
291 * should later enable hardware-supervised mode as appropriate
293 list_for_each_entry(clkdm, &clkdm_list, node) {
294 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
295 omap2_clkdm_wakeup(clkdm);
296 else if (clkdm->flags & CLKDM_CAN_DISABLE_AUTO)
297 omap2_clkdm_deny_idle(clkdm);
299 clkdm_clear_all_wkdeps(clkdm);
300 clkdm_clear_all_sleepdeps(clkdm);
305 * clkdm_lookup - look up a clockdomain by name, return a pointer
306 * @name: name of clockdomain
308 * Find a registered clockdomain by its name @name. Returns a pointer
309 * to the struct clockdomain if found, or NULL otherwise.
311 struct clockdomain *clkdm_lookup(const char *name)
313 struct clockdomain *clkdm, *temp_clkdm;
320 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
321 if (!strcmp(name, temp_clkdm->name)) {
331 * clkdm_for_each - call function on each registered clockdomain
332 * @fn: callback function *
334 * Call the supplied function @fn for each registered clockdomain.
335 * The callback function @fn can return anything but 0 to bail
336 * out early from the iterator. The callback function is called with
337 * the clkdm_mutex held, so no clockdomain structure manipulation
338 * functions should be called from the callback, although hardware
339 * clockdomain control functions are fine. Returns the last return
340 * value of the callback function, which should be 0 for success or
341 * anything else to indicate failure; or -EINVAL if the function pointer
344 int clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user),
347 struct clockdomain *clkdm;
353 list_for_each_entry(clkdm, &clkdm_list, node) {
354 ret = (*fn)(clkdm, user);
364 * clkdm_get_pwrdm - return a ptr to the pwrdm that this clkdm resides in
365 * @clkdm: struct clockdomain *
367 * Return a pointer to the struct powerdomain that the specified clockdomain
368 * @clkdm exists in, or returns NULL if @clkdm is NULL.
370 struct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm)
375 return clkdm->pwrdm.ptr;
379 /* Hardware clockdomain control */
382 * clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1
383 * @clkdm1: wake this struct clockdomain * up (dependent)
384 * @clkdm2: when this struct clockdomain * wakes up (source)
386 * When the clockdomain represented by @clkdm2 wakes up, wake up
387 * @clkdm1. Implemented in hardware on the OMAP, this feature is
388 * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
389 * Returns -EINVAL if presented with invalid clockdomain pointers,
390 * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
393 int clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
395 struct clkdm_dep *cd;
397 if (!clkdm1 || !clkdm2)
400 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
402 pr_debug("clockdomain: hardware cannot set/clear wake up of "
403 "%s when %s wakes up\n", clkdm1->name, clkdm2->name);
407 if (atomic_inc_return(&cd->wkdep_usecount) == 1) {
408 pr_debug("clockdomain: hardware will wake up %s when %s wakes "
409 "up\n", clkdm1->name, clkdm2->name);
411 omap2_prm_set_mod_reg_bits((1 << clkdm2->dep_bit),
412 clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP);
419 * clkdm_del_wkdep - remove a wakeup dependency from clkdm2 to clkdm1
420 * @clkdm1: wake this struct clockdomain * up (dependent)
421 * @clkdm2: when this struct clockdomain * wakes up (source)
423 * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
424 * wakes up. Returns -EINVAL if presented with invalid clockdomain
425 * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
428 int clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
430 struct clkdm_dep *cd;
432 if (!clkdm1 || !clkdm2)
435 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
437 pr_debug("clockdomain: hardware cannot set/clear wake up of "
438 "%s when %s wakes up\n", clkdm1->name, clkdm2->name);
442 if (atomic_dec_return(&cd->wkdep_usecount) == 0) {
443 pr_debug("clockdomain: hardware will no longer wake up %s "
444 "after %s wakes up\n", clkdm1->name, clkdm2->name);
446 omap2_prm_clear_mod_reg_bits((1 << clkdm2->dep_bit),
447 clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP);
454 * clkdm_read_wkdep - read wakeup dependency state from clkdm2 to clkdm1
455 * @clkdm1: wake this struct clockdomain * up (dependent)
456 * @clkdm2: when this struct clockdomain * wakes up (source)
458 * Return 1 if a hardware wakeup dependency exists wherein @clkdm1 will be
459 * awoken when @clkdm2 wakes up; 0 if dependency is not set; -EINVAL
460 * if either clockdomain pointer is invalid; or -ENOENT if the hardware
463 * REVISIT: Currently this function only represents software-controllable
464 * wakeup dependencies. Wakeup dependencies fixed in hardware are not
467 int clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
469 struct clkdm_dep *cd;
471 if (!clkdm1 || !clkdm2)
474 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
476 pr_debug("clockdomain: hardware cannot set/clear wake up of "
477 "%s when %s wakes up\n", clkdm1->name, clkdm2->name);
481 /* XXX It's faster to return the atomic wkdep_usecount */
482 return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP,
483 (1 << clkdm2->dep_bit));
487 * clkdm_clear_all_wkdeps - remove all wakeup dependencies from target clkdm
488 * @clkdm: struct clockdomain * to remove all wakeup dependencies from
490 * Remove all inter-clockdomain wakeup dependencies that could cause
491 * @clkdm to wake. Intended to be used during boot to initialize the
492 * PRCM to a known state, after all clockdomains are put into swsup idle
493 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
496 int clkdm_clear_all_wkdeps(struct clockdomain *clkdm)
498 struct clkdm_dep *cd;
504 for (cd = clkdm->wkdep_srcs; cd && cd->clkdm_name; cd++) {
505 if (!omap_chip_is(cd->omap_chip))
508 if (!cd->clkdm && cd->clkdm_name)
509 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
511 /* PRM accesses are slow, so minimize them */
512 mask |= 1 << cd->clkdm->dep_bit;
513 atomic_set(&cd->wkdep_usecount, 0);
516 omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs, PM_WKDEP);
522 * clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1
523 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
524 * @clkdm2: when this struct clockdomain * is active (source)
526 * Prevent @clkdm1 from automatically going inactive (and then to
527 * retention or off) if @clkdm2 is active. Returns -EINVAL if
528 * presented with invalid clockdomain pointers or called on a machine
529 * that does not support software-configurable hardware sleep
530 * dependencies, -ENOENT if the specified dependency cannot be set in
531 * hardware, or 0 upon success.
533 int clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
535 struct clkdm_dep *cd;
537 if (!cpu_is_omap34xx())
540 if (!clkdm1 || !clkdm2)
543 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
545 pr_debug("clockdomain: hardware cannot set/clear sleep "
546 "dependency affecting %s from %s\n", clkdm1->name,
551 if (atomic_inc_return(&cd->sleepdep_usecount) == 1) {
552 pr_debug("clockdomain: will prevent %s from sleeping if %s "
553 "is active\n", clkdm1->name, clkdm2->name);
555 omap2_cm_set_mod_reg_bits((1 << clkdm2->dep_bit),
556 clkdm1->pwrdm.ptr->prcm_offs,
557 OMAP3430_CM_SLEEPDEP);
564 * clkdm_del_sleepdep - remove a sleep dependency from clkdm2 to clkdm1
565 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
566 * @clkdm2: when this struct clockdomain * is active (source)
568 * Allow @clkdm1 to automatically go inactive (and then to retention or
569 * off), independent of the activity state of @clkdm2. Returns -EINVAL
570 * if presented with invalid clockdomain pointers or called on a machine
571 * that does not support software-configurable hardware sleep dependencies,
572 * -ENOENT if the specified dependency cannot be cleared in hardware, or
575 int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
577 struct clkdm_dep *cd;
579 if (!cpu_is_omap34xx())
582 if (!clkdm1 || !clkdm2)
585 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
587 pr_debug("clockdomain: hardware cannot set/clear sleep "
588 "dependency affecting %s from %s\n", clkdm1->name,
593 if (atomic_dec_return(&cd->sleepdep_usecount) == 0) {
594 pr_debug("clockdomain: will no longer prevent %s from "
595 "sleeping if %s is active\n", clkdm1->name,
598 omap2_cm_clear_mod_reg_bits((1 << clkdm2->dep_bit),
599 clkdm1->pwrdm.ptr->prcm_offs,
600 OMAP3430_CM_SLEEPDEP);
607 * clkdm_read_sleepdep - read sleep dependency state from clkdm2 to clkdm1
608 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
609 * @clkdm2: when this struct clockdomain * is active (source)
611 * Return 1 if a hardware sleep dependency exists wherein @clkdm1 will
612 * not be allowed to automatically go inactive if @clkdm2 is active;
613 * 0 if @clkdm1's automatic power state inactivity transition is independent
614 * of @clkdm2's; -EINVAL if either clockdomain pointer is invalid or called
615 * on a machine that does not support software-configurable hardware sleep
616 * dependencies; or -ENOENT if the hardware is incapable.
618 * REVISIT: Currently this function only represents software-controllable
619 * sleep dependencies. Sleep dependencies fixed in hardware are not
622 int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
624 struct clkdm_dep *cd;
626 if (!cpu_is_omap34xx())
629 if (!clkdm1 || !clkdm2)
632 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
634 pr_debug("clockdomain: hardware cannot set/clear sleep "
635 "dependency affecting %s from %s\n", clkdm1->name,
640 /* XXX It's faster to return the atomic sleepdep_usecount */
641 return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs,
642 OMAP3430_CM_SLEEPDEP,
643 (1 << clkdm2->dep_bit));
647 * clkdm_clear_all_sleepdeps - remove all sleep dependencies from target clkdm
648 * @clkdm: struct clockdomain * to remove all sleep dependencies from
650 * Remove all inter-clockdomain sleep dependencies that could prevent
651 * @clkdm from idling. Intended to be used during boot to initialize the
652 * PRCM to a known state, after all clockdomains are put into swsup idle
653 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
656 int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm)
658 struct clkdm_dep *cd;
661 if (!cpu_is_omap34xx())
667 for (cd = clkdm->sleepdep_srcs; cd && cd->clkdm_name; cd++) {
668 if (!omap_chip_is(cd->omap_chip))
671 if (!cd->clkdm && cd->clkdm_name)
672 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
674 /* PRM accesses are slow, so minimize them */
675 mask |= 1 << cd->clkdm->dep_bit;
676 atomic_set(&cd->sleepdep_usecount, 0);
679 omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs,
680 OMAP3430_CM_SLEEPDEP);
686 * omap2_clkdm_clktrctrl_read - read the clkdm's current state transition mode
687 * @clkdm: struct clkdm * of a clockdomain
689 * Return the clockdomain @clkdm current state transition mode from the
690 * corresponding domain CM_CLKSTCTRL register. Returns -EINVAL if @clkdm
691 * is NULL or the current mode upon success.
693 static int omap2_clkdm_clktrctrl_read(struct clockdomain *clkdm)
700 v = __raw_readl(clkdm->clkstctrl_reg);
701 v &= clkdm->clktrctrl_mask;
702 v >>= __ffs(clkdm->clktrctrl_mask);
708 * omap2_clkdm_sleep - force clockdomain sleep transition
709 * @clkdm: struct clockdomain *
711 * Instruct the CM to force a sleep transition on the specified
712 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if
713 * clockdomain does not support software-initiated sleep; 0 upon
716 int omap2_clkdm_sleep(struct clockdomain *clkdm)
721 if (!(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) {
722 pr_debug("clockdomain: %s does not support forcing "
723 "sleep via software\n", clkdm->name);
727 pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name);
729 if (cpu_is_omap24xx()) {
731 omap2_cm_set_mod_reg_bits(OMAP24XX_FORCESTATE_MASK,
732 clkdm->pwrdm.ptr->prcm_offs, OMAP2_PM_PWSTCTRL);
734 } else if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
736 u32 bits = (OMAP34XX_CLKSTCTRL_FORCE_SLEEP <<
737 __ffs(clkdm->clktrctrl_mask));
739 u32 v = __raw_readl(clkdm->clkstctrl_reg);
740 v &= ~(clkdm->clktrctrl_mask);
742 __raw_writel(v, clkdm->clkstctrl_reg);
752 * omap2_clkdm_wakeup - force clockdomain wakeup transition
753 * @clkdm: struct clockdomain *
755 * Instruct the CM to force a wakeup transition on the specified
756 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the
757 * clockdomain does not support software-controlled wakeup; 0 upon
760 int omap2_clkdm_wakeup(struct clockdomain *clkdm)
765 if (!(clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)) {
766 pr_debug("clockdomain: %s does not support forcing "
767 "wakeup via software\n", clkdm->name);
771 pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name);
773 if (cpu_is_omap24xx()) {
775 omap2_cm_clear_mod_reg_bits(OMAP24XX_FORCESTATE_MASK,
776 clkdm->pwrdm.ptr->prcm_offs, OMAP2_PM_PWSTCTRL);
778 } else if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
780 u32 bits = (OMAP34XX_CLKSTCTRL_FORCE_WAKEUP <<
781 __ffs(clkdm->clktrctrl_mask));
783 u32 v = __raw_readl(clkdm->clkstctrl_reg);
784 v &= ~(clkdm->clktrctrl_mask);
786 __raw_writel(v, clkdm->clkstctrl_reg);
796 * omap2_clkdm_allow_idle - enable hwsup idle transitions for clkdm
797 * @clkdm: struct clockdomain *
799 * Allow the hardware to automatically switch the clockdomain @clkdm into
800 * active or idle states, as needed by downstream clocks. If the
801 * clockdomain has any downstream clocks enabled in the clock
802 * framework, wkdep/sleepdep autodependencies are added; this is so
803 * device drivers can read and write to the device. No return value.
805 void omap2_clkdm_allow_idle(struct clockdomain *clkdm)
810 if (!(clkdm->flags & CLKDM_CAN_ENABLE_AUTO)) {
811 pr_debug("clock: automatic idle transitions cannot be enabled "
812 "on clockdomain %s\n", clkdm->name);
816 pr_debug("clockdomain: enabling automatic idle transitions for %s\n",
820 * XXX This should be removed once TI adds wakeup/sleep
821 * dependency code and data for OMAP4.
823 if (cpu_is_omap44xx()) {
824 WARN_ONCE(1, "clockdomain: OMAP4 wakeup/sleep dependency "
825 "support is not yet implemented\n");
827 if (atomic_read(&clkdm->usecount) > 0)
828 _clkdm_add_autodeps(clkdm);
831 _omap2_clkdm_set_hwsup(clkdm, 1);
833 pwrdm_clkdm_state_switch(clkdm);
837 * omap2_clkdm_deny_idle - disable hwsup idle transitions for clkdm
838 * @clkdm: struct clockdomain *
840 * Prevent the hardware from automatically switching the clockdomain
841 * @clkdm into inactive or idle states. If the clockdomain has
842 * downstream clocks enabled in the clock framework, wkdep/sleepdep
843 * autodependencies are removed. No return value.
845 void omap2_clkdm_deny_idle(struct clockdomain *clkdm)
850 if (!(clkdm->flags & CLKDM_CAN_DISABLE_AUTO)) {
851 pr_debug("clockdomain: automatic idle transitions cannot be "
852 "disabled on %s\n", clkdm->name);
856 pr_debug("clockdomain: disabling automatic idle transitions for %s\n",
859 _omap2_clkdm_set_hwsup(clkdm, 0);
862 * XXX This should be removed once TI adds wakeup/sleep
863 * dependency code and data for OMAP4.
865 if (cpu_is_omap44xx()) {
866 WARN_ONCE(1, "clockdomain: OMAP4 wakeup/sleep dependency "
867 "support is not yet implemented\n");
869 if (atomic_read(&clkdm->usecount) > 0)
870 _clkdm_del_autodeps(clkdm);
875 /* Clockdomain-to-clock framework interface code */
878 * omap2_clkdm_clk_enable - add an enabled downstream clock to this clkdm
879 * @clkdm: struct clockdomain *
880 * @clk: struct clk * of the enabled downstream clock
882 * Increment the usecount of the clockdomain @clkdm and ensure that it
883 * is awake before @clk is enabled. Intended to be called by
884 * clk_enable() code. If the clockdomain is in software-supervised
885 * idle mode, force the clockdomain to wake. If the clockdomain is in
886 * hardware-supervised idle mode, add clkdm-pwrdm autodependencies, to
887 * ensure that devices in the clockdomain can be read from/written to
888 * by on-chip processors. Returns -EINVAL if passed null pointers;
889 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
891 int omap2_clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk)
896 * XXX Rewrite this code to maintain a list of enabled
897 * downstream clocks for debugging purposes?
903 if (atomic_inc_return(&clkdm->usecount) > 1)
906 /* Clockdomain now has one enabled downstream clock */
908 pr_debug("clockdomain: clkdm %s: clk %s now enabled\n", clkdm->name,
911 if (!clkdm->clkstctrl_reg)
914 v = omap2_clkdm_clktrctrl_read(clkdm);
916 if ((cpu_is_omap34xx() && v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) ||
917 (cpu_is_omap24xx() && v == OMAP24XX_CLKSTCTRL_ENABLE_AUTO)) {
918 /* Disable HW transitions when we are changing deps */
919 _omap2_clkdm_set_hwsup(clkdm, 0);
920 _clkdm_add_autodeps(clkdm);
921 _omap2_clkdm_set_hwsup(clkdm, 1);
923 omap2_clkdm_wakeup(clkdm);
926 pwrdm_wait_transition(clkdm->pwrdm.ptr);
927 pwrdm_clkdm_state_switch(clkdm);
933 * omap2_clkdm_clk_disable - remove an enabled downstream clock from this clkdm
934 * @clkdm: struct clockdomain *
935 * @clk: struct clk * of the disabled downstream clock
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
942 * pointers; -ERANGE if the @clkdm usecount underflows and debugging
943 * is enabled; or returns 0 upon success or if the clockdomain is in
946 int omap2_clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk)
951 * XXX Rewrite this code to maintain a list of enabled
952 * downstream clocks for debugging purposes?
959 if (atomic_read(&clkdm->usecount) == 0) {
960 WARN_ON(1); /* underflow */
965 if (atomic_dec_return(&clkdm->usecount) > 0)
968 /* All downstream clocks of this clockdomain are now disabled */
970 pr_debug("clockdomain: clkdm %s: clk %s now disabled\n", clkdm->name,
973 if (!clkdm->clkstctrl_reg)
976 v = omap2_clkdm_clktrctrl_read(clkdm);
978 if ((cpu_is_omap34xx() && v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) ||
979 (cpu_is_omap24xx() && v == OMAP24XX_CLKSTCTRL_ENABLE_AUTO)) {
980 /* Disable HW transitions when we are changing deps */
981 _omap2_clkdm_set_hwsup(clkdm, 0);
982 _clkdm_del_autodeps(clkdm);
983 _omap2_clkdm_set_hwsup(clkdm, 1);
985 omap2_clkdm_sleep(clkdm);
988 pwrdm_clkdm_state_switch(clkdm);