blob: 6d44fe05a3feb00f3ce11877f52b25ed43863926 [file] [log] [blame]
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001/*
Abhijit Pagare8a3ddc72010-01-26 20:12:54 -07002 * OMAP2/3/4 clockdomain framework functions
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03003 *
Paul Walmsley32a363c2011-07-10 05:56:54 -06004 * Copyright (C) 2008-2011 Texas Instruments, Inc.
5 * Copyright (C) 2008-2011 Nokia Corporation
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03006 *
7 * Written by Paul Walmsley and Jouni Högander
Abhijit Pagare8a3ddc72010-01-26 20:12:54 -07008 * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03009 *
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 Walmsley33903eb2009-12-08 16:33:10 -070014#undef DEBUG
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030015
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030016#include <linux/kernel.h>
17#include <linux/device.h>
18#include <linux/list.h>
19#include <linux/errno.h>
Paul Gortmakerd44b28c2011-07-31 10:52:44 -040020#include <linux/string.h>
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030021#include <linux/delay.h>
22#include <linux/clk.h>
23#include <linux/limits.h>
Paul Walmsley5b74c672009-02-03 02:10:03 -070024#include <linux/err.h>
Mike Turquetted043d872012-11-09 11:28:42 -070025#include <linux/clk-provider.h>
Keerthy9bcfb762018-05-16 20:46:59 +053026#include <linux/cpu_pm.h>
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030027
28#include <linux/io.h>
29
30#include <linux/bitops.h>
31
Tony Lindgrene4c060d2012-10-05 13:25:59 -070032#include "soc.h"
Paul Walmsleya135eaa2012-09-27 10:33:34 -060033#include "clock.h"
Paul Walmsley1540f2142010-12-21 21:05:15 -070034#include "clockdomain.h"
Keerthy9bcfb762018-05-16 20:46:59 +053035#include "pm.h"
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030036
37/* clkdm_list contains all registered struct clockdomains */
38static LIST_HEAD(clkdm_list);
39
Paul Walmsley55ed9692010-01-26 20:12:59 -070040/* array of clockdomain deps to be added/removed when clkdm in hwsup mode */
41static struct clkdm_autodep *autodeps;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030042
Rajendra Nayak32d40342011-02-25 16:06:47 -070043static struct clkdm_ops *arch_clkdm;
Keerthy9bcfb762018-05-16 20:46:59 +053044void clkdm_save_context(void);
45void clkdm_restore_context(void);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030046
47/* Private functions */
48
Paul Walmsley55ed9692010-01-26 20:12:59 -070049static struct clockdomain *_clkdm_lookup(const char *name)
50{
51 struct clockdomain *clkdm, *temp_clkdm;
52
53 if (!name)
54 return NULL;
55
56 clkdm = NULL;
57
58 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
59 if (!strcmp(name, temp_clkdm->name)) {
60 clkdm = temp_clkdm;
61 break;
62 }
63 }
64
65 return clkdm;
66}
67
Paul Walmsleye909d62a82010-01-26 20:13:00 -070068/**
69 * _clkdm_register - register a clockdomain
70 * @clkdm: struct clockdomain * to register
71 *
72 * Adds a clockdomain to the internal clockdomain list.
73 * Returns -EINVAL if given a null pointer, -EEXIST if a clockdomain is
74 * already registered by the provided name, or 0 upon success.
75 */
76static int _clkdm_register(struct clockdomain *clkdm)
77{
78 struct powerdomain *pwrdm;
79
80 if (!clkdm || !clkdm->name)
81 return -EINVAL;
82
Paul Walmsleye909d62a82010-01-26 20:13:00 -070083 pwrdm = pwrdm_lookup(clkdm->pwrdm.name);
84 if (!pwrdm) {
85 pr_err("clockdomain: %s: powerdomain %s does not exist\n",
86 clkdm->name, clkdm->pwrdm.name);
87 return -EINVAL;
88 }
89 clkdm->pwrdm.ptr = pwrdm;
90
91 /* Verify that the clockdomain is not already registered */
92 if (_clkdm_lookup(clkdm->name))
93 return -EEXIST;
94
95 list_add(&clkdm->node, &clkdm_list);
96
97 pwrdm_add_clkdm(pwrdm, clkdm);
98
99 pr_debug("clockdomain: registered %s\n", clkdm->name);
100
101 return 0;
102}
103
Paul Walmsley55ed9692010-01-26 20:12:59 -0700104/* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */
105static struct clkdm_dep *_clkdm_deps_lookup(struct clockdomain *clkdm,
106 struct clkdm_dep *deps)
107{
108 struct clkdm_dep *cd;
109
Paul Walmsleya5ffef62011-09-14 16:01:21 -0600110 if (!clkdm || !deps)
Paul Walmsley55ed9692010-01-26 20:12:59 -0700111 return ERR_PTR(-EINVAL);
112
113 for (cd = deps; cd->clkdm_name; cd++) {
Paul Walmsley55ed9692010-01-26 20:12:59 -0700114 if (!cd->clkdm && cd->clkdm_name)
115 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
116
117 if (cd->clkdm == clkdm)
118 break;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700119 }
120
121 if (!cd->clkdm_name)
122 return ERR_PTR(-ENOENT);
123
124 return cd;
125}
126
Paul Walmsley65958fb2013-01-26 00:58:17 -0700127/**
Paul Walmsley55ed9692010-01-26 20:12:59 -0700128 * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store
129 * @autodep: struct clkdm_autodep * to resolve
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300130 *
Paul Walmsley55ed9692010-01-26 20:12:59 -0700131 * Resolve autodep clockdomain names to clockdomain pointers via
132 * clkdm_lookup() and store the pointers in the autodep structure. An
133 * "autodep" is a clockdomain sleep/wakeup dependency that is
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300134 * automatically added and removed whenever clocks in the associated
135 * clockdomain are enabled or disabled (respectively) when the
136 * clockdomain is in hardware-supervised mode. Meant to be called
137 * once at clockdomain layer initialization, since these should remain
138 * fixed for a particular architecture. No return value.
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700139 *
140 * XXX autodeps are deprecated and should be removed at the earliest
141 * opportunity
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300142 */
Paul Walmsley55ed9692010-01-26 20:12:59 -0700143static void _autodep_lookup(struct clkdm_autodep *autodep)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300144{
Paul Walmsley55ed9692010-01-26 20:12:59 -0700145 struct clockdomain *clkdm;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300146
147 if (!autodep)
148 return;
149
Paul Walmsley55ed9692010-01-26 20:12:59 -0700150 clkdm = clkdm_lookup(autodep->clkdm.name);
151 if (!clkdm) {
152 pr_err("clockdomain: autodeps: clockdomain %s does not exist\n",
153 autodep->clkdm.name);
154 clkdm = ERR_PTR(-ENOENT);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300155 }
Paul Walmsley55ed9692010-01-26 20:12:59 -0700156 autodep->clkdm.ptr = clkdm;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300157}
158
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700159/**
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700160 * _resolve_clkdm_deps() - resolve clkdm_names in @clkdm_deps to clkdms
161 * @clkdm: clockdomain that we are resolving dependencies for
162 * @clkdm_deps: ptr to array of struct clkdm_deps to resolve
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600163 *
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700164 * Iterates through @clkdm_deps, looking up the struct clockdomain named by
165 * clkdm_name and storing the clockdomain pointer in the struct clkdm_dep.
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700166 * No return value.
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700167 */
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700168static void _resolve_clkdm_deps(struct clockdomain *clkdm,
169 struct clkdm_dep *clkdm_deps)
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600170{
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700171 struct clkdm_dep *cd;
172
173 for (cd = clkdm_deps; cd && cd->clkdm_name; cd++) {
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700174 if (cd->clkdm)
175 continue;
176 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
177
178 WARN(!cd->clkdm, "clockdomain: %s: could not find clkdm %s while resolving dependencies - should never happen",
179 clkdm->name, cd->clkdm_name);
180 }
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600181}
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300182
Paul Walmsley65958fb2013-01-26 00:58:17 -0700183/**
184 * _clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1 (lockless)
185 * @clkdm1: wake this struct clockdomain * up (dependent)
186 * @clkdm2: when this struct clockdomain * wakes up (source)
187 *
188 * When the clockdomain represented by @clkdm2 wakes up, wake up
189 * @clkdm1. Implemented in hardware on the OMAP, this feature is
190 * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
191 * Returns -EINVAL if presented with invalid clockdomain pointers,
192 * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
193 * success.
194 */
195static int _clkdm_add_wkdep(struct clockdomain *clkdm1,
196 struct clockdomain *clkdm2)
197{
198 struct clkdm_dep *cd;
199 int ret = 0;
200
201 if (!clkdm1 || !clkdm2)
202 return -EINVAL;
203
204 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
205 if (IS_ERR(cd))
206 ret = PTR_ERR(cd);
207
208 if (!arch_clkdm || !arch_clkdm->clkdm_add_wkdep)
209 ret = -EINVAL;
210
211 if (ret) {
212 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
213 clkdm1->name, clkdm2->name);
214 return ret;
215 }
216
Paul Walmsley92493872013-01-26 00:58:17 -0700217 cd->wkdep_usecount++;
218 if (cd->wkdep_usecount == 1) {
Paul Walmsley65958fb2013-01-26 00:58:17 -0700219 pr_debug("clockdomain: hardware will wake up %s when %s wakes up\n",
220 clkdm1->name, clkdm2->name);
221
222 ret = arch_clkdm->clkdm_add_wkdep(clkdm1, clkdm2);
223 }
224
225 return ret;
226}
227
228/**
229 * _clkdm_del_wkdep - remove a wakeup dep from clkdm2 to clkdm1 (lockless)
230 * @clkdm1: wake this struct clockdomain * up (dependent)
231 * @clkdm2: when this struct clockdomain * wakes up (source)
232 *
233 * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
234 * wakes up. Returns -EINVAL if presented with invalid clockdomain
235 * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
236 * 0 upon success.
237 */
238static int _clkdm_del_wkdep(struct clockdomain *clkdm1,
239 struct clockdomain *clkdm2)
240{
241 struct clkdm_dep *cd;
242 int ret = 0;
243
244 if (!clkdm1 || !clkdm2)
245 return -EINVAL;
246
247 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
248 if (IS_ERR(cd))
249 ret = PTR_ERR(cd);
250
251 if (!arch_clkdm || !arch_clkdm->clkdm_del_wkdep)
252 ret = -EINVAL;
253
254 if (ret) {
255 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
256 clkdm1->name, clkdm2->name);
257 return ret;
258 }
259
Paul Walmsley92493872013-01-26 00:58:17 -0700260 cd->wkdep_usecount--;
261 if (cd->wkdep_usecount == 0) {
Paul Walmsley65958fb2013-01-26 00:58:17 -0700262 pr_debug("clockdomain: hardware will no longer wake up %s after %s wakes up\n",
263 clkdm1->name, clkdm2->name);
264
265 ret = arch_clkdm->clkdm_del_wkdep(clkdm1, clkdm2);
266 }
267
268 return ret;
269}
270
271/**
272 * _clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1 (lockless)
273 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
274 * @clkdm2: when this struct clockdomain * is active (source)
275 *
276 * Prevent @clkdm1 from automatically going inactive (and then to
277 * retention or off) if @clkdm2 is active. Returns -EINVAL if
278 * presented with invalid clockdomain pointers or called on a machine
279 * that does not support software-configurable hardware sleep
280 * dependencies, -ENOENT if the specified dependency cannot be set in
281 * hardware, or 0 upon success.
282 */
283static int _clkdm_add_sleepdep(struct clockdomain *clkdm1,
284 struct clockdomain *clkdm2)
285{
286 struct clkdm_dep *cd;
287 int ret = 0;
288
289 if (!clkdm1 || !clkdm2)
290 return -EINVAL;
291
292 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
293 if (IS_ERR(cd))
294 ret = PTR_ERR(cd);
295
296 if (!arch_clkdm || !arch_clkdm->clkdm_add_sleepdep)
297 ret = -EINVAL;
298
299 if (ret) {
300 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
301 clkdm1->name, clkdm2->name);
302 return ret;
303 }
304
Paul Walmsley92493872013-01-26 00:58:17 -0700305 cd->sleepdep_usecount++;
306 if (cd->sleepdep_usecount == 1) {
Paul Walmsley65958fb2013-01-26 00:58:17 -0700307 pr_debug("clockdomain: will prevent %s from sleeping if %s is active\n",
308 clkdm1->name, clkdm2->name);
309
310 ret = arch_clkdm->clkdm_add_sleepdep(clkdm1, clkdm2);
311 }
312
313 return ret;
314}
315
316/**
317 * _clkdm_del_sleepdep - remove a sleep dep from clkdm2 to clkdm1 (lockless)
318 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
319 * @clkdm2: when this struct clockdomain * is active (source)
320 *
321 * Allow @clkdm1 to automatically go inactive (and then to retention or
322 * off), independent of the activity state of @clkdm2. Returns -EINVAL
323 * if presented with invalid clockdomain pointers or called on a machine
324 * that does not support software-configurable hardware sleep dependencies,
325 * -ENOENT if the specified dependency cannot be cleared in hardware, or
326 * 0 upon success.
327 */
328static int _clkdm_del_sleepdep(struct clockdomain *clkdm1,
329 struct clockdomain *clkdm2)
330{
331 struct clkdm_dep *cd;
332 int ret = 0;
333
334 if (!clkdm1 || !clkdm2)
335 return -EINVAL;
336
337 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
338 if (IS_ERR(cd))
339 ret = PTR_ERR(cd);
340
341 if (!arch_clkdm || !arch_clkdm->clkdm_del_sleepdep)
342 ret = -EINVAL;
343
344 if (ret) {
345 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
346 clkdm1->name, clkdm2->name);
347 return ret;
348 }
349
Paul Walmsley92493872013-01-26 00:58:17 -0700350 cd->sleepdep_usecount--;
351 if (cd->sleepdep_usecount == 0) {
Paul Walmsley65958fb2013-01-26 00:58:17 -0700352 pr_debug("clockdomain: will no longer prevent %s from sleeping if %s is active\n",
353 clkdm1->name, clkdm2->name);
354
355 ret = arch_clkdm->clkdm_del_sleepdep(clkdm1, clkdm2);
356 }
357
358 return ret;
359}
360
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300361/* Public functions */
362
363/**
Paul Walmsley08cb9702011-09-14 16:01:20 -0600364 * clkdm_register_platform_funcs - register clockdomain implementation fns
365 * @co: func pointers for arch specific implementations
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300366 *
Paul Walmsley08cb9702011-09-14 16:01:20 -0600367 * Register the list of function pointers used to implement the
368 * clockdomain functions on different OMAP SoCs. Should be called
369 * before any other clkdm_register*() function. Returns -EINVAL if
370 * @co is null, -EEXIST if platform functions have already been
371 * registered, or 0 upon success.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300372 */
Paul Walmsley08cb9702011-09-14 16:01:20 -0600373int clkdm_register_platform_funcs(struct clkdm_ops *co)
374{
375 if (!co)
376 return -EINVAL;
377
378 if (arch_clkdm)
379 return -EEXIST;
380
381 arch_clkdm = co;
382
383 return 0;
384};
385
386/**
387 * clkdm_register_clkdms - register SoC clockdomains
388 * @cs: pointer to an array of struct clockdomain to register
389 *
390 * Register the clockdomains available on a particular OMAP SoC. Must
391 * be called after clkdm_register_platform_funcs(). May be called
392 * multiple times. Returns -EACCES if called before
393 * clkdm_register_platform_funcs(); -EINVAL if the argument @cs is
394 * null; or 0 upon success.
395 */
396int clkdm_register_clkdms(struct clockdomain **cs)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300397{
398 struct clockdomain **c = NULL;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300399
Paul Walmsley08cb9702011-09-14 16:01:20 -0600400 if (!arch_clkdm)
401 return -EACCES;
Rajendra Nayak32d40342011-02-25 16:06:47 -0700402
Paul Walmsley08cb9702011-09-14 16:01:20 -0600403 if (!cs)
404 return -EINVAL;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300405
Paul Walmsley08cb9702011-09-14 16:01:20 -0600406 for (c = cs; *c; c++)
407 _clkdm_register(*c);
408
409 return 0;
410}
411
412/**
413 * clkdm_register_autodeps - register autodeps (if required)
414 * @ia: pointer to a static array of struct clkdm_autodep to register
415 *
416 * Register clockdomain "automatic dependencies." These are
417 * clockdomain wakeup and sleep dependencies that are automatically
418 * added whenever the first clock inside a clockdomain is enabled, and
419 * removed whenever the last clock inside a clockdomain is disabled.
420 * These are currently only used on OMAP3 devices, and are deprecated,
421 * since they waste energy. However, until the OMAP2/3 IP block
422 * enable/disable sequence can be converted to match the OMAP4
423 * sequence, they are needed.
424 *
425 * Must be called only after all of the SoC clockdomains are
426 * registered, since the function will resolve autodep clockdomain
427 * names into clockdomain pointers.
428 *
429 * The struct clkdm_autodep @ia array must be static, as this function
430 * does not copy the array elements.
431 *
432 * Returns -EACCES if called before any clockdomains have been
433 * registered, -EINVAL if called with a null @ia argument, -EEXIST if
434 * autodeps have already been registered, or 0 upon success.
435 */
436int clkdm_register_autodeps(struct clkdm_autodep *ia)
437{
438 struct clkdm_autodep *a = NULL;
439
440 if (list_empty(&clkdm_list))
441 return -EACCES;
442
443 if (!ia)
444 return -EINVAL;
445
Paul Walmsley55ed9692010-01-26 20:12:59 -0700446 if (autodeps)
Paul Walmsley08cb9702011-09-14 16:01:20 -0600447 return -EEXIST;
Paul Walmsley369d5612010-01-26 20:13:01 -0700448
Paul Walmsley08cb9702011-09-14 16:01:20 -0600449 autodeps = ia;
450 for (a = autodeps; a->clkdm.ptr; a++)
451 _autodep_lookup(a);
452
453 return 0;
454}
455
Keerthy9bcfb762018-05-16 20:46:59 +0530456static int cpu_notifier(struct notifier_block *nb, unsigned long cmd, void *v)
457{
458 switch (cmd) {
459 case CPU_CLUSTER_PM_ENTER:
460 if (enable_off_mode)
461 clkdm_save_context();
462 break;
463 case CPU_CLUSTER_PM_EXIT:
464 if (enable_off_mode)
465 clkdm_restore_context();
466 break;
467 }
468
469 return NOTIFY_OK;
470}
471
Paul Walmsley08cb9702011-09-14 16:01:20 -0600472/**
473 * clkdm_complete_init - set up the clockdomain layer
474 *
475 * Put all clockdomains into software-supervised mode; PM code should
476 * later enable hardware-supervised mode as appropriate. Must be
477 * called after clkdm_register_clkdms(). Returns -EACCES if called
478 * before clkdm_register_clkdms(), or 0 upon success.
479 */
480int clkdm_complete_init(void)
481{
482 struct clockdomain *clkdm;
Keerthy9bcfb762018-05-16 20:46:59 +0530483 static struct notifier_block nb;
Paul Walmsley08cb9702011-09-14 16:01:20 -0600484
485 if (list_empty(&clkdm_list))
486 return -EACCES;
487
Paul Walmsley369d5612010-01-26 20:13:01 -0700488 list_for_each_entry(clkdm, &clkdm_list, node) {
Tero Kristo1d9a5422016-06-30 16:15:02 +0300489 clkdm_deny_idle(clkdm);
Paul Walmsley6f7f63c2010-09-14 15:56:53 -0600490
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700491 _resolve_clkdm_deps(clkdm, clkdm->wkdep_srcs);
Paul Walmsley6f7f63c2010-09-14 15:56:53 -0600492 clkdm_clear_all_wkdeps(clkdm);
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700493
494 _resolve_clkdm_deps(clkdm, clkdm->sleepdep_srcs);
Paul Walmsley6f7f63c2010-09-14 15:56:53 -0600495 clkdm_clear_all_sleepdeps(clkdm);
Paul Walmsley369d5612010-01-26 20:13:01 -0700496 }
Paul Walmsley08cb9702011-09-14 16:01:20 -0600497
Keerthy9bcfb762018-05-16 20:46:59 +0530498 /* Only AM43XX can lose clkdm context during rtc-ddr suspend */
499 if (soc_is_am43xx()) {
500 nb.notifier_call = cpu_notifier;
501 cpu_pm_register_notifier(&nb);
502 }
503
Paul Walmsley08cb9702011-09-14 16:01:20 -0600504 return 0;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300505}
506
507/**
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300508 * clkdm_lookup - look up a clockdomain by name, return a pointer
509 * @name: name of clockdomain
510 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700511 * Find a registered clockdomain by its name @name. Returns a pointer
512 * to the struct clockdomain if found, or NULL otherwise.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300513 */
514struct clockdomain *clkdm_lookup(const char *name)
515{
516 struct clockdomain *clkdm, *temp_clkdm;
517
518 if (!name)
519 return NULL;
520
521 clkdm = NULL;
522
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300523 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
524 if (!strcmp(name, temp_clkdm->name)) {
525 clkdm = temp_clkdm;
526 break;
527 }
528 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300529
530 return clkdm;
531}
532
533/**
534 * clkdm_for_each - call function on each registered clockdomain
535 * @fn: callback function *
536 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700537 * Call the supplied function @fn for each registered clockdomain.
538 * The callback function @fn can return anything but 0 to bail
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300539 * out early from the iterator. The callback function is called with
540 * the clkdm_mutex held, so no clockdomain structure manipulation
541 * functions should be called from the callback, although hardware
542 * clockdomain control functions are fine. Returns the last return
543 * value of the callback function, which should be 0 for success or
544 * anything else to indicate failure; or -EINVAL if the function pointer
545 * is null.
546 */
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300547int clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user),
548 void *user)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300549{
550 struct clockdomain *clkdm;
551 int ret = 0;
552
553 if (!fn)
554 return -EINVAL;
555
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300556 list_for_each_entry(clkdm, &clkdm_list, node) {
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300557 ret = (*fn)(clkdm, user);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300558 if (ret)
559 break;
560 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300561
562 return ret;
563}
564
565
Paul Walmsleye89087c2008-05-20 18:41:35 -0600566/**
567 * clkdm_get_pwrdm - return a ptr to the pwrdm that this clkdm resides in
568 * @clkdm: struct clockdomain *
569 *
570 * Return a pointer to the struct powerdomain that the specified clockdomain
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700571 * @clkdm exists in, or returns NULL if @clkdm is NULL.
Paul Walmsleye89087c2008-05-20 18:41:35 -0600572 */
573struct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm)
574{
575 if (!clkdm)
576 return NULL;
577
Paul Walmsley5b74c672009-02-03 02:10:03 -0700578 return clkdm->pwrdm.ptr;
Paul Walmsleye89087c2008-05-20 18:41:35 -0600579}
580
581
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300582/* Hardware clockdomain control */
583
584/**
Paul Walmsley55ed9692010-01-26 20:12:59 -0700585 * clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1
586 * @clkdm1: wake this struct clockdomain * up (dependent)
587 * @clkdm2: when this struct clockdomain * wakes up (source)
588 *
589 * When the clockdomain represented by @clkdm2 wakes up, wake up
590 * @clkdm1. Implemented in hardware on the OMAP, this feature is
591 * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
592 * Returns -EINVAL if presented with invalid clockdomain pointers,
593 * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
594 * success.
595 */
596int clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
597{
Paul Walmsley92493872013-01-26 00:58:17 -0700598 struct clkdm_dep *cd;
599 int ret;
600
601 if (!clkdm1 || !clkdm2)
602 return -EINVAL;
603
604 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
605 if (IS_ERR(cd))
606 return PTR_ERR(cd);
607
608 pwrdm_lock(cd->clkdm->pwrdm.ptr);
609 ret = _clkdm_add_wkdep(clkdm1, clkdm2);
610 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
611
612 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700613}
614
615/**
616 * clkdm_del_wkdep - remove a wakeup dependency from clkdm2 to clkdm1
617 * @clkdm1: wake this struct clockdomain * up (dependent)
618 * @clkdm2: when this struct clockdomain * wakes up (source)
619 *
620 * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
621 * wakes up. Returns -EINVAL if presented with invalid clockdomain
622 * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
623 * 0 upon success.
624 */
625int clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
626{
Paul Walmsley92493872013-01-26 00:58:17 -0700627 struct clkdm_dep *cd;
628 int ret;
629
630 if (!clkdm1 || !clkdm2)
631 return -EINVAL;
632
633 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
634 if (IS_ERR(cd))
635 return PTR_ERR(cd);
636
637 pwrdm_lock(cd->clkdm->pwrdm.ptr);
638 ret = _clkdm_del_wkdep(clkdm1, clkdm2);
639 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
640
641 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700642}
643
644/**
645 * clkdm_read_wkdep - read wakeup dependency state from clkdm2 to clkdm1
646 * @clkdm1: wake this struct clockdomain * up (dependent)
647 * @clkdm2: when this struct clockdomain * wakes up (source)
648 *
649 * Return 1 if a hardware wakeup dependency exists wherein @clkdm1 will be
650 * awoken when @clkdm2 wakes up; 0 if dependency is not set; -EINVAL
651 * if either clockdomain pointer is invalid; or -ENOENT if the hardware
652 * is incapable.
653 *
654 * REVISIT: Currently this function only represents software-controllable
655 * wakeup dependencies. Wakeup dependencies fixed in hardware are not
656 * yet handled here.
657 */
658int clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
659{
660 struct clkdm_dep *cd;
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700661 int ret = 0;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700662
663 if (!clkdm1 || !clkdm2)
664 return -EINVAL;
665
666 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700667 if (IS_ERR(cd))
668 ret = PTR_ERR(cd);
669
670 if (!arch_clkdm || !arch_clkdm->clkdm_read_wkdep)
671 ret = -EINVAL;
672
673 if (ret) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600674 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
675 clkdm1->name, clkdm2->name);
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700676 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700677 }
678
Paul Walmsley92493872013-01-26 00:58:17 -0700679 /* XXX It's faster to return the wkdep_usecount */
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700680 return arch_clkdm->clkdm_read_wkdep(clkdm1, clkdm2);
Paul Walmsley55ed9692010-01-26 20:12:59 -0700681}
682
683/**
Paul Walmsley369d5612010-01-26 20:13:01 -0700684 * clkdm_clear_all_wkdeps - remove all wakeup dependencies from target clkdm
685 * @clkdm: struct clockdomain * to remove all wakeup dependencies from
686 *
687 * Remove all inter-clockdomain wakeup dependencies that could cause
688 * @clkdm to wake. Intended to be used during boot to initialize the
689 * PRCM to a known state, after all clockdomains are put into swsup idle
690 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
691 * 0 upon success.
692 */
693int clkdm_clear_all_wkdeps(struct clockdomain *clkdm)
694{
Paul Walmsley369d5612010-01-26 20:13:01 -0700695 if (!clkdm)
696 return -EINVAL;
697
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700698 if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_wkdeps)
699 return -EINVAL;
Paul Walmsley369d5612010-01-26 20:13:01 -0700700
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700701 return arch_clkdm->clkdm_clear_all_wkdeps(clkdm);
Paul Walmsley369d5612010-01-26 20:13:01 -0700702}
703
704/**
Paul Walmsley55ed9692010-01-26 20:12:59 -0700705 * clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1
706 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
707 * @clkdm2: when this struct clockdomain * is active (source)
708 *
709 * Prevent @clkdm1 from automatically going inactive (and then to
710 * retention or off) if @clkdm2 is active. Returns -EINVAL if
711 * presented with invalid clockdomain pointers or called on a machine
712 * that does not support software-configurable hardware sleep
713 * dependencies, -ENOENT if the specified dependency cannot be set in
714 * hardware, or 0 upon success.
715 */
716int clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
717{
Paul Walmsley92493872013-01-26 00:58:17 -0700718 struct clkdm_dep *cd;
719 int ret;
720
721 if (!clkdm1 || !clkdm2)
722 return -EINVAL;
723
724 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
725 if (IS_ERR(cd))
726 return PTR_ERR(cd);
727
728 pwrdm_lock(cd->clkdm->pwrdm.ptr);
729 ret = _clkdm_add_sleepdep(clkdm1, clkdm2);
730 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
731
732 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700733}
734
735/**
736 * clkdm_del_sleepdep - remove a sleep dependency from clkdm2 to clkdm1
737 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
738 * @clkdm2: when this struct clockdomain * is active (source)
739 *
740 * Allow @clkdm1 to automatically go inactive (and then to retention or
741 * off), independent of the activity state of @clkdm2. Returns -EINVAL
742 * if presented with invalid clockdomain pointers or called on a machine
743 * that does not support software-configurable hardware sleep dependencies,
744 * -ENOENT if the specified dependency cannot be cleared in hardware, or
745 * 0 upon success.
746 */
747int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
748{
Paul Walmsley92493872013-01-26 00:58:17 -0700749 struct clkdm_dep *cd;
750 int ret;
751
752 if (!clkdm1 || !clkdm2)
753 return -EINVAL;
754
755 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
756 if (IS_ERR(cd))
757 return PTR_ERR(cd);
758
759 pwrdm_lock(cd->clkdm->pwrdm.ptr);
760 ret = _clkdm_del_sleepdep(clkdm1, clkdm2);
761 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
762
763 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700764}
765
766/**
767 * clkdm_read_sleepdep - read sleep dependency state from clkdm2 to clkdm1
768 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
769 * @clkdm2: when this struct clockdomain * is active (source)
770 *
771 * Return 1 if a hardware sleep dependency exists wherein @clkdm1 will
772 * not be allowed to automatically go inactive if @clkdm2 is active;
773 * 0 if @clkdm1's automatic power state inactivity transition is independent
774 * of @clkdm2's; -EINVAL if either clockdomain pointer is invalid or called
775 * on a machine that does not support software-configurable hardware sleep
776 * dependencies; or -ENOENT if the hardware is incapable.
777 *
778 * REVISIT: Currently this function only represents software-controllable
779 * sleep dependencies. Sleep dependencies fixed in hardware are not
780 * yet handled here.
781 */
782int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
783{
784 struct clkdm_dep *cd;
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700785 int ret = 0;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700786
787 if (!clkdm1 || !clkdm2)
788 return -EINVAL;
789
790 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700791 if (IS_ERR(cd))
792 ret = PTR_ERR(cd);
793
794 if (!arch_clkdm || !arch_clkdm->clkdm_read_sleepdep)
795 ret = -EINVAL;
796
797 if (ret) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600798 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
799 clkdm1->name, clkdm2->name);
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700800 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700801 }
802
Paul Walmsley92493872013-01-26 00:58:17 -0700803 /* XXX It's faster to return the sleepdep_usecount */
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700804 return arch_clkdm->clkdm_read_sleepdep(clkdm1, clkdm2);
Paul Walmsley55ed9692010-01-26 20:12:59 -0700805}
806
Paul Walmsley369d5612010-01-26 20:13:01 -0700807/**
808 * clkdm_clear_all_sleepdeps - remove all sleep dependencies from target clkdm
809 * @clkdm: struct clockdomain * to remove all sleep dependencies from
810 *
811 * Remove all inter-clockdomain sleep dependencies that could prevent
812 * @clkdm from idling. Intended to be used during boot to initialize the
813 * PRCM to a known state, after all clockdomains are put into swsup idle
814 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
815 * 0 upon success.
816 */
817int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm)
818{
Paul Walmsley369d5612010-01-26 20:13:01 -0700819 if (!clkdm)
820 return -EINVAL;
821
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700822 if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_sleepdeps)
823 return -EINVAL;
Paul Walmsley369d5612010-01-26 20:13:01 -0700824
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700825 return arch_clkdm->clkdm_clear_all_sleepdeps(clkdm);
Paul Walmsley369d5612010-01-26 20:13:01 -0700826}
Paul Walmsley55ed9692010-01-26 20:12:59 -0700827
828/**
Paul Walmsley3a090282013-01-26 00:58:16 -0700829 * clkdm_sleep_nolock - force clockdomain sleep transition (lockless)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300830 * @clkdm: struct clockdomain *
831 *
832 * Instruct the CM to force a sleep transition on the specified
Paul Walmsley3a090282013-01-26 00:58:16 -0700833 * clockdomain @clkdm. Only for use by the powerdomain code. Returns
834 * -EINVAL if @clkdm is NULL or if clockdomain does not support
835 * software-initiated sleep; 0 upon success.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300836 */
Paul Walmsley3a090282013-01-26 00:58:16 -0700837int clkdm_sleep_nolock(struct clockdomain *clkdm)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300838{
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600839 int ret;
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600840
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300841 if (!clkdm)
842 return -EINVAL;
843
844 if (!(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600845 pr_debug("clockdomain: %s does not support forcing sleep via software\n",
846 clkdm->name);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300847 return -EINVAL;
848 }
849
Rajendra Nayak68b921a2011-02-25 16:06:47 -0700850 if (!arch_clkdm || !arch_clkdm->clkdm_sleep)
851 return -EINVAL;
852
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300853 pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name);
854
Paul Walmsley32a363c2011-07-10 05:56:54 -0600855 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600856 ret = arch_clkdm->clkdm_sleep(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -0700857 ret |= pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
858
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600859 return ret;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300860}
861
862/**
Paul Walmsley3a090282013-01-26 00:58:16 -0700863 * clkdm_sleep - force clockdomain sleep transition
864 * @clkdm: struct clockdomain *
865 *
866 * Instruct the CM to force a sleep transition on the specified
867 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if
868 * clockdomain does not support software-initiated sleep; 0 upon
869 * success.
870 */
871int clkdm_sleep(struct clockdomain *clkdm)
872{
873 int ret;
874
875 pwrdm_lock(clkdm->pwrdm.ptr);
876 ret = clkdm_sleep_nolock(clkdm);
877 pwrdm_unlock(clkdm->pwrdm.ptr);
878
879 return ret;
880}
881
882/**
883 * clkdm_wakeup_nolock - force clockdomain wakeup transition (lockless)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300884 * @clkdm: struct clockdomain *
885 *
886 * Instruct the CM to force a wakeup transition on the specified
Paul Walmsley3a090282013-01-26 00:58:16 -0700887 * clockdomain @clkdm. Only for use by the powerdomain code. Returns
888 * -EINVAL if @clkdm is NULL or if the clockdomain does not support
889 * software-controlled wakeup; 0 upon success.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300890 */
Paul Walmsley3a090282013-01-26 00:58:16 -0700891int clkdm_wakeup_nolock(struct clockdomain *clkdm)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300892{
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600893 int ret;
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600894
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300895 if (!clkdm)
896 return -EINVAL;
897
898 if (!(clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600899 pr_debug("clockdomain: %s does not support forcing wakeup via software\n",
900 clkdm->name);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300901 return -EINVAL;
902 }
903
Rajendra Nayak68b921a2011-02-25 16:06:47 -0700904 if (!arch_clkdm || !arch_clkdm->clkdm_wakeup)
905 return -EINVAL;
906
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300907 pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name);
908
Paul Walmsley32a363c2011-07-10 05:56:54 -0600909 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600910 ret = arch_clkdm->clkdm_wakeup(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -0700911 ret |= pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
912
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600913 return ret;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300914}
915
916/**
Paul Walmsley3a090282013-01-26 00:58:16 -0700917 * clkdm_wakeup - force clockdomain wakeup transition
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300918 * @clkdm: struct clockdomain *
919 *
Paul Walmsley3a090282013-01-26 00:58:16 -0700920 * Instruct the CM to force a wakeup transition on the specified
921 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the
922 * clockdomain does not support software-controlled wakeup; 0 upon
923 * success.
924 */
925int clkdm_wakeup(struct clockdomain *clkdm)
926{
927 int ret;
928
929 pwrdm_lock(clkdm->pwrdm.ptr);
930 ret = clkdm_wakeup_nolock(clkdm);
931 pwrdm_unlock(clkdm->pwrdm.ptr);
932
933 return ret;
934}
935
936/**
937 * clkdm_allow_idle_nolock - enable hwsup idle transitions for clkdm
938 * @clkdm: struct clockdomain *
939 *
940 * Allow the hardware to automatically switch the clockdomain @clkdm
941 * into active or idle states, as needed by downstream clocks. If the
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300942 * clockdomain has any downstream clocks enabled in the clock
943 * framework, wkdep/sleepdep autodependencies are added; this is so
Paul Walmsley3a090282013-01-26 00:58:16 -0700944 * device drivers can read and write to the device. Only for use by
945 * the powerdomain code. No return value.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300946 */
Paul Walmsley3a090282013-01-26 00:58:16 -0700947void clkdm_allow_idle_nolock(struct clockdomain *clkdm)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300948{
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300949 if (!clkdm)
950 return;
951
Tero Kristo1d9a5422016-06-30 16:15:02 +0300952 if (!WARN_ON(!clkdm->forcewake_count))
953 clkdm->forcewake_count--;
954
955 if (clkdm->forcewake_count)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300956 return;
Tero Kristo1d9a5422016-06-30 16:15:02 +0300957
958 if (!clkdm->usecount && (clkdm->flags & CLKDM_CAN_FORCE_SLEEP))
959 clkdm_sleep_nolock(clkdm);
960
961 if (!(clkdm->flags & CLKDM_CAN_ENABLE_AUTO))
962 return;
963
964 if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING)
965 return;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300966
Rajendra Nayak5cd19372011-02-25 16:06:48 -0700967 if (!arch_clkdm || !arch_clkdm->clkdm_allow_idle)
968 return;
969
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300970 pr_debug("clockdomain: enabling automatic idle transitions for %s\n",
971 clkdm->name);
972
Paul Walmsley32a363c2011-07-10 05:56:54 -0600973 clkdm->_flags |= _CLKDM_FLAG_HWSUP_ENABLED;
Rajendra Nayak5cd19372011-02-25 16:06:48 -0700974 arch_clkdm->clkdm_allow_idle(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -0700975 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
976}
977
978/**
979 * clkdm_allow_idle - enable hwsup idle transitions for clkdm
980 * @clkdm: struct clockdomain *
981 *
982 * Allow the hardware to automatically switch the clockdomain @clkdm into
983 * active or idle states, as needed by downstream clocks. If the
984 * clockdomain has any downstream clocks enabled in the clock
985 * framework, wkdep/sleepdep autodependencies are added; this is so
986 * device drivers can read and write to the device. No return value.
987 */
988void clkdm_allow_idle(struct clockdomain *clkdm)
989{
990 pwrdm_lock(clkdm->pwrdm.ptr);
991 clkdm_allow_idle_nolock(clkdm);
992 pwrdm_unlock(clkdm->pwrdm.ptr);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300993}
994
995/**
Rajendra Nayak5cd19372011-02-25 16:06:48 -0700996 * clkdm_deny_idle - disable hwsup idle transitions for clkdm
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300997 * @clkdm: struct clockdomain *
998 *
999 * Prevent the hardware from automatically switching the clockdomain
Paul Walmsleyf0271d62010-01-26 20:13:02 -07001000 * @clkdm into inactive or idle states. If the clockdomain has
1001 * downstream clocks enabled in the clock framework, wkdep/sleepdep
Paul Walmsley3a090282013-01-26 00:58:16 -07001002 * autodependencies are removed. Only for use by the powerdomain
1003 * code. No return value.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001004 */
Paul Walmsley3a090282013-01-26 00:58:16 -07001005void clkdm_deny_idle_nolock(struct clockdomain *clkdm)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001006{
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001007 if (!clkdm)
1008 return;
1009
Tero Kristo1d9a5422016-06-30 16:15:02 +03001010 if (clkdm->forcewake_count++)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001011 return;
Tero Kristo1d9a5422016-06-30 16:15:02 +03001012
1013 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
1014 clkdm_wakeup_nolock(clkdm);
1015
1016 if (!(clkdm->flags & CLKDM_CAN_DISABLE_AUTO))
1017 return;
1018
1019 if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING)
1020 return;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001021
Rajendra Nayak5cd19372011-02-25 16:06:48 -07001022 if (!arch_clkdm || !arch_clkdm->clkdm_deny_idle)
1023 return;
1024
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001025 pr_debug("clockdomain: disabling automatic idle transitions for %s\n",
1026 clkdm->name);
1027
Paul Walmsley32a363c2011-07-10 05:56:54 -06001028 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
Rajendra Nayak5cd19372011-02-25 16:06:48 -07001029 arch_clkdm->clkdm_deny_idle(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -07001030 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
1031}
1032
1033/**
1034 * clkdm_deny_idle - disable hwsup idle transitions for clkdm
1035 * @clkdm: struct clockdomain *
1036 *
1037 * Prevent the hardware from automatically switching the clockdomain
1038 * @clkdm into inactive or idle states. If the clockdomain has
1039 * downstream clocks enabled in the clock framework, wkdep/sleepdep
1040 * autodependencies are removed. No return value.
1041 */
1042void clkdm_deny_idle(struct clockdomain *clkdm)
1043{
1044 pwrdm_lock(clkdm->pwrdm.ptr);
1045 clkdm_deny_idle_nolock(clkdm);
1046 pwrdm_unlock(clkdm->pwrdm.ptr);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001047}
1048
Paul Walmsley32a363c2011-07-10 05:56:54 -06001049/**
1050 * clkdm_in_hwsup - is clockdomain @clkdm have hardware-supervised idle enabled?
1051 * @clkdm: struct clockdomain *
1052 *
1053 * Returns true if clockdomain @clkdm currently has
1054 * hardware-supervised idle enabled, or false if it does not or if
1055 * @clkdm is NULL. It is only valid to call this function after
1056 * clkdm_init() has been called. This function does not actually read
1057 * bits from the hardware; it instead tests an in-memory flag that is
1058 * changed whenever the clockdomain code changes the auto-idle mode.
1059 */
1060bool clkdm_in_hwsup(struct clockdomain *clkdm)
1061{
Rajendra Nayak555e74e2011-07-10 05:56:55 -06001062 bool ret;
Rajendra Nayak555e74e2011-07-10 05:56:55 -06001063
Paul Walmsley32a363c2011-07-10 05:56:54 -06001064 if (!clkdm)
1065 return false;
1066
Rajendra Nayak555e74e2011-07-10 05:56:55 -06001067 ret = (clkdm->_flags & _CLKDM_FLAG_HWSUP_ENABLED) ? true : false;
Rajendra Nayak555e74e2011-07-10 05:56:55 -06001068
1069 return ret;
Paul Walmsley32a363c2011-07-10 05:56:54 -06001070}
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001071
Paul Walmsleyb71c7212012-09-23 17:28:28 -06001072/**
1073 * clkdm_missing_idle_reporting - can @clkdm enter autoidle even if in use?
1074 * @clkdm: struct clockdomain *
1075 *
1076 * Returns true if clockdomain @clkdm has the
1077 * CLKDM_MISSING_IDLE_REPORTING flag set, or false if not or @clkdm is
1078 * null. More information is available in the documentation for the
1079 * CLKDM_MISSING_IDLE_REPORTING macro.
1080 */
1081bool clkdm_missing_idle_reporting(struct clockdomain *clkdm)
1082{
1083 if (!clkdm)
1084 return false;
1085
1086 return (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING) ? true : false;
1087}
1088
Paul Walmsley65958fb2013-01-26 00:58:17 -07001089/* Public autodep handling functions (deprecated) */
1090
1091/**
1092 * clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable
1093 * @clkdm: struct clockdomain *
1094 *
1095 * Add the "autodep" sleep & wakeup dependencies to clockdomain 'clkdm'
1096 * in hardware-supervised mode. Meant to be called from clock framework
1097 * when a clock inside clockdomain 'clkdm' is enabled. No return value.
1098 *
1099 * XXX autodeps are deprecated and should be removed at the earliest
1100 * opportunity
1101 */
1102void clkdm_add_autodeps(struct clockdomain *clkdm)
1103{
1104 struct clkdm_autodep *autodep;
1105
1106 if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
1107 return;
1108
1109 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
1110 if (IS_ERR(autodep->clkdm.ptr))
1111 continue;
1112
1113 pr_debug("clockdomain: %s: adding %s sleepdep/wkdep\n",
1114 clkdm->name, autodep->clkdm.ptr->name);
1115
1116 _clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr);
1117 _clkdm_add_wkdep(clkdm, autodep->clkdm.ptr);
1118 }
1119}
1120
1121/**
1122 * clkdm_del_autodeps - remove auto sleepdeps/wkdeps from clkdm
1123 * @clkdm: struct clockdomain *
1124 *
1125 * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm'
1126 * in hardware-supervised mode. Meant to be called from clock framework
1127 * when a clock inside clockdomain 'clkdm' is disabled. No return value.
1128 *
1129 * XXX autodeps are deprecated and should be removed at the earliest
1130 * opportunity
1131 */
1132void clkdm_del_autodeps(struct clockdomain *clkdm)
1133{
1134 struct clkdm_autodep *autodep;
1135
1136 if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
1137 return;
1138
1139 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
1140 if (IS_ERR(autodep->clkdm.ptr))
1141 continue;
1142
1143 pr_debug("clockdomain: %s: removing %s sleepdep/wkdep\n",
1144 clkdm->name, autodep->clkdm.ptr->name);
1145
1146 _clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr);
1147 _clkdm_del_wkdep(clkdm, autodep->clkdm.ptr);
1148 }
1149}
1150
Benoit Cousson113a7412011-07-10 05:56:54 -06001151/* Clockdomain-to-clock/hwmod framework interface code */
1152
1153static int _clkdm_clk_hwmod_enable(struct clockdomain *clkdm)
1154{
1155 if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_enable)
1156 return -EINVAL;
1157
Paul Walmsley3a090282013-01-26 00:58:16 -07001158 pwrdm_lock(clkdm->pwrdm.ptr);
Tero Kristo64e29fd2012-09-25 19:05:32 +03001159
Benoit Cousson113a7412011-07-10 05:56:54 -06001160 /*
1161 * For arch's with no autodeps, clkcm_clk_enable
1162 * should be called for every clock instance or hwmod that is
1163 * enabled, so the clkdm can be force woken up.
1164 */
Paul Walmsley92493872013-01-26 00:58:17 -07001165 clkdm->usecount++;
1166 if (clkdm->usecount > 1 && autodeps) {
Paul Walmsley3a090282013-01-26 00:58:16 -07001167 pwrdm_unlock(clkdm->pwrdm.ptr);
Benoit Cousson113a7412011-07-10 05:56:54 -06001168 return 0;
Tero Kristo64e29fd2012-09-25 19:05:32 +03001169 }
Benoit Cousson113a7412011-07-10 05:56:54 -06001170
1171 arch_clkdm->clkdm_clk_enable(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -07001172 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
1173 pwrdm_unlock(clkdm->pwrdm.ptr);
Benoit Cousson113a7412011-07-10 05:56:54 -06001174
Paul Walmsley7852ec02012-07-26 00:54:26 -06001175 pr_debug("clockdomain: %s: enabled\n", clkdm->name);
Benoit Cousson113a7412011-07-10 05:56:54 -06001176
1177 return 0;
1178}
1179
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001180/**
Rajendra Nayak4da71ae2011-02-25 16:06:48 -07001181 * clkdm_clk_enable - add an enabled downstream clock to this clkdm
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001182 * @clkdm: struct clockdomain *
1183 * @clk: struct clk * of the enabled downstream clock
1184 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -07001185 * Increment the usecount of the clockdomain @clkdm and ensure that it
1186 * is awake before @clk is enabled. Intended to be called by
1187 * clk_enable() code. If the clockdomain is in software-supervised
1188 * idle mode, force the clockdomain to wake. If the clockdomain is in
1189 * hardware-supervised idle mode, add clkdm-pwrdm autodependencies, to
1190 * ensure that devices in the clockdomain can be read from/written to
1191 * by on-chip processors. Returns -EINVAL if passed null pointers;
1192 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001193 */
Rajendra Nayak4da71ae2011-02-25 16:06:48 -07001194int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001195{
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001196 /*
1197 * XXX Rewrite this code to maintain a list of enabled
1198 * downstream clocks for debugging purposes?
1199 */
1200
Benoit Cousson113a7412011-07-10 05:56:54 -06001201 if (!clk)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001202 return -EINVAL;
1203
Benoit Cousson113a7412011-07-10 05:56:54 -06001204 return _clkdm_clk_hwmod_enable(clkdm);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001205}
1206
1207/**
Rajendra Nayak4da71ae2011-02-25 16:06:48 -07001208 * clkdm_clk_disable - remove an enabled downstream clock from this clkdm
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001209 * @clkdm: struct clockdomain *
1210 * @clk: struct clk * of the disabled downstream clock
1211 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -07001212 * Decrement the usecount of this clockdomain @clkdm when @clk is
1213 * disabled. Intended to be called by clk_disable() code. If the
1214 * clockdomain usecount goes to 0, put the clockdomain to sleep
1215 * (software-supervised mode) or remove the clkdm autodependencies
1216 * (hardware-supervised mode). Returns -EINVAL if passed null
Benoit Cousson113a7412011-07-10 05:56:54 -06001217 * pointers; -ERANGE if the @clkdm usecount underflows; or returns 0
1218 * upon success or if the clockdomain is in hwsup idle mode.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001219 */
Rajendra Nayak4da71ae2011-02-25 16:06:48 -07001220int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001221{
Mike Turquetted043d872012-11-09 11:28:42 -07001222 if (!clkdm || !clk || !arch_clkdm || !arch_clkdm->clkdm_clk_disable)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001223 return -EINVAL;
1224
Paul Walmsley3a090282013-01-26 00:58:16 -07001225 pwrdm_lock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001226
Mike Turquetted043d872012-11-09 11:28:42 -07001227 /* corner case: disabling unused clocks */
Paul Walmsley92493872013-01-26 00:58:17 -07001228 if ((__clk_get_enable_count(clk) == 0) && clkdm->usecount == 0)
Mike Turquetted043d872012-11-09 11:28:42 -07001229 goto ccd_exit;
Mike Turquetted043d872012-11-09 11:28:42 -07001230
Paul Walmsley92493872013-01-26 00:58:17 -07001231 if (clkdm->usecount == 0) {
Paul Walmsley3a090282013-01-26 00:58:16 -07001232 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001233 WARN_ON(1); /* underflow */
1234 return -ERANGE;
1235 }
1236
Paul Walmsley92493872013-01-26 00:58:17 -07001237 clkdm->usecount--;
1238 if (clkdm->usecount > 0) {
Paul Walmsley3a090282013-01-26 00:58:16 -07001239 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001240 return 0;
1241 }
1242
1243 arch_clkdm->clkdm_clk_disable(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -07001244 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001245
1246 pr_debug("clockdomain: %s: disabled\n", clkdm->name);
1247
Mike Turquetted043d872012-11-09 11:28:42 -07001248ccd_exit:
Paul Walmsley3a090282013-01-26 00:58:16 -07001249 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001250
1251 return 0;
Benoit Cousson113a7412011-07-10 05:56:54 -06001252}
Rajendra Nayak4da71ae2011-02-25 16:06:48 -07001253
Benoit Cousson113a7412011-07-10 05:56:54 -06001254/**
1255 * clkdm_hwmod_enable - add an enabled downstream hwmod to this clkdm
1256 * @clkdm: struct clockdomain *
1257 * @oh: struct omap_hwmod * of the enabled downstream hwmod
1258 *
1259 * Increment the usecount of the clockdomain @clkdm and ensure that it
1260 * is awake before @oh is enabled. Intended to be called by
1261 * module_enable() code.
1262 * If the clockdomain is in software-supervised idle mode, force the
1263 * clockdomain to wake. If the clockdomain is in hardware-supervised idle
1264 * mode, add clkdm-pwrdm autodependencies, to ensure that devices in the
1265 * clockdomain can be read from/written to by on-chip processors.
1266 * Returns -EINVAL if passed null pointers;
1267 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
1268 */
1269int clkdm_hwmod_enable(struct clockdomain *clkdm, struct omap_hwmod *oh)
1270{
1271 /* The clkdm attribute does not exist yet prior OMAP4 */
1272 if (cpu_is_omap24xx() || cpu_is_omap34xx())
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001273 return 0;
1274
Benoit Cousson113a7412011-07-10 05:56:54 -06001275 /*
1276 * XXX Rewrite this code to maintain a list of enabled
1277 * downstream hwmods for debugging purposes?
1278 */
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001279
Benoit Cousson113a7412011-07-10 05:56:54 -06001280 if (!oh)
1281 return -EINVAL;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001282
Benoit Cousson113a7412011-07-10 05:56:54 -06001283 return _clkdm_clk_hwmod_enable(clkdm);
1284}
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +03001285
Benoit Cousson113a7412011-07-10 05:56:54 -06001286/**
1287 * clkdm_hwmod_disable - remove an enabled downstream hwmod from this clkdm
1288 * @clkdm: struct clockdomain *
1289 * @oh: struct omap_hwmod * of the disabled downstream hwmod
1290 *
1291 * Decrement the usecount of this clockdomain @clkdm when @oh is
1292 * disabled. Intended to be called by module_disable() code.
1293 * If the clockdomain usecount goes to 0, put the clockdomain to sleep
1294 * (software-supervised mode) or remove the clkdm autodependencies
1295 * (hardware-supervised mode).
1296 * Returns -EINVAL if passed null pointers; -ERANGE if the @clkdm usecount
1297 * underflows; or returns 0 upon success or if the clockdomain is in hwsup
1298 * idle mode.
1299 */
1300int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh)
1301{
1302 /* The clkdm attribute does not exist yet prior OMAP4 */
1303 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1304 return 0;
1305
1306 /*
1307 * XXX Rewrite this code to maintain a list of enabled
1308 * downstream hwmods for debugging purposes?
1309 */
1310
Mike Turquetted043d872012-11-09 11:28:42 -07001311 if (!clkdm || !oh || !arch_clkdm || !arch_clkdm->clkdm_clk_disable)
Benoit Cousson113a7412011-07-10 05:56:54 -06001312 return -EINVAL;
1313
Paul Walmsley3a090282013-01-26 00:58:16 -07001314 pwrdm_lock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001315
Paul Walmsley92493872013-01-26 00:58:17 -07001316 if (clkdm->usecount == 0) {
Paul Walmsley3a090282013-01-26 00:58:16 -07001317 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001318 WARN_ON(1); /* underflow */
1319 return -ERANGE;
1320 }
1321
Paul Walmsley92493872013-01-26 00:58:17 -07001322 clkdm->usecount--;
1323 if (clkdm->usecount > 0) {
Paul Walmsley3a090282013-01-26 00:58:16 -07001324 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001325 return 0;
1326 }
1327
1328 arch_clkdm->clkdm_clk_disable(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -07001329 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
1330 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001331
1332 pr_debug("clockdomain: %s: disabled\n", clkdm->name);
1333
1334 return 0;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001335}
1336
Russ Dill1096d1c2018-05-16 20:46:58 +05301337/**
1338 * _clkdm_save_context - save the context for the control of this clkdm
1339 *
1340 * Due to a suspend or hibernation operation, the state of the registers
1341 * controlling this clkdm will be lost, save their context.
1342 */
1343static int _clkdm_save_context(struct clockdomain *clkdm, void *ununsed)
1344{
1345 if (!arch_clkdm || !arch_clkdm->clkdm_save_context)
1346 return -EINVAL;
1347
1348 return arch_clkdm->clkdm_save_context(clkdm);
1349}
1350
1351/**
1352 * _clkdm_restore_context - restore context for control of this clkdm
1353 *
1354 * Restore the register values for this clockdomain.
1355 */
1356static int _clkdm_restore_context(struct clockdomain *clkdm, void *ununsed)
1357{
1358 if (!arch_clkdm || !arch_clkdm->clkdm_restore_context)
1359 return -EINVAL;
1360
1361 return arch_clkdm->clkdm_restore_context(clkdm);
1362}
1363
1364/**
1365 * clkdm_save_context - Saves the context for each registered clkdm
1366 *
1367 * Save the context for each registered clockdomain.
1368 */
1369void clkdm_save_context(void)
1370{
1371 clkdm_for_each(_clkdm_save_context, NULL);
1372}
1373
1374/**
1375 * clkdm_restore_context - Restores the context for each registered clkdm
1376 *
1377 * Restore the context for each registered clockdomain.
1378 */
1379void clkdm_restore_context(void)
1380{
1381 clkdm_for_each(_clkdm_restore_context, NULL);
1382}