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