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