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