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