blob: f98c8ecc9ca2a3524cab51c3f9a937399f73e16a [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03002/*
Abhijit Pagare8a3ddc72010-01-26 20:12:54 -07003 * OMAP2/3/4 clockdomain framework functions
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03004 *
Paul Walmsley32a363c2011-07-10 05:56:54 -06005 * Copyright (C) 2008-2011 Texas Instruments, Inc.
6 * Copyright (C) 2008-2011 Nokia Corporation
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03007 *
8 * Written by Paul Walmsley and Jouni Högander
Abhijit Pagare8a3ddc72010-01-26 20:12:54 -07009 * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030010 */
Paul Walmsley33903eb2009-12-08 16:33:10 -070011#undef DEBUG
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030012
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030013#include <linux/kernel.h>
14#include <linux/device.h>
15#include <linux/list.h>
16#include <linux/errno.h>
Paul Gortmakerd44b28c2011-07-31 10:52:44 -040017#include <linux/string.h>
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030018#include <linux/delay.h>
19#include <linux/clk.h>
20#include <linux/limits.h>
Paul Walmsley5b74c672009-02-03 02:10:03 -070021#include <linux/err.h>
Mike Turquetted043d872012-11-09 11:28:42 -070022#include <linux/clk-provider.h>
Keerthy9bcfb762018-05-16 20:46:59 +053023#include <linux/cpu_pm.h>
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030024
25#include <linux/io.h>
26
27#include <linux/bitops.h>
28
Tony Lindgrene4c060d2012-10-05 13:25:59 -070029#include "soc.h"
Paul Walmsleya135eaa2012-09-27 10:33:34 -060030#include "clock.h"
Paul Walmsley1540f2142010-12-21 21:05:15 -070031#include "clockdomain.h"
Keerthy9bcfb762018-05-16 20:46:59 +053032#include "pm.h"
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030033
34/* clkdm_list contains all registered struct clockdomains */
35static LIST_HEAD(clkdm_list);
36
Paul Walmsley55ed9692010-01-26 20:12:59 -070037/* array of clockdomain deps to be added/removed when clkdm in hwsup mode */
38static struct clkdm_autodep *autodeps;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030039
Rajendra Nayak32d40342011-02-25 16:06:47 -070040static struct clkdm_ops *arch_clkdm;
Keerthy9bcfb762018-05-16 20:46:59 +053041void clkdm_save_context(void);
42void clkdm_restore_context(void);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030043
44/* Private functions */
45
Paul Walmsley55ed9692010-01-26 20:12:59 -070046static struct clockdomain *_clkdm_lookup(const char *name)
47{
48 struct clockdomain *clkdm, *temp_clkdm;
49
50 if (!name)
51 return NULL;
52
53 clkdm = NULL;
54
55 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
56 if (!strcmp(name, temp_clkdm->name)) {
57 clkdm = temp_clkdm;
58 break;
59 }
60 }
61
62 return clkdm;
63}
64
Paul Walmsleye909d62a82010-01-26 20:13:00 -070065/**
66 * _clkdm_register - register a clockdomain
67 * @clkdm: struct clockdomain * to register
68 *
69 * Adds a clockdomain to the internal clockdomain list.
70 * Returns -EINVAL if given a null pointer, -EEXIST if a clockdomain is
71 * already registered by the provided name, or 0 upon success.
72 */
73static int _clkdm_register(struct clockdomain *clkdm)
74{
75 struct powerdomain *pwrdm;
76
77 if (!clkdm || !clkdm->name)
78 return -EINVAL;
79
Paul Walmsleye909d62a82010-01-26 20:13:00 -070080 pwrdm = pwrdm_lookup(clkdm->pwrdm.name);
81 if (!pwrdm) {
82 pr_err("clockdomain: %s: powerdomain %s does not exist\n",
83 clkdm->name, clkdm->pwrdm.name);
84 return -EINVAL;
85 }
86 clkdm->pwrdm.ptr = pwrdm;
87
88 /* Verify that the clockdomain is not already registered */
89 if (_clkdm_lookup(clkdm->name))
90 return -EEXIST;
91
92 list_add(&clkdm->node, &clkdm_list);
93
94 pwrdm_add_clkdm(pwrdm, clkdm);
95
96 pr_debug("clockdomain: registered %s\n", clkdm->name);
97
98 return 0;
99}
100
Paul Walmsley55ed9692010-01-26 20:12:59 -0700101/* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */
102static struct clkdm_dep *_clkdm_deps_lookup(struct clockdomain *clkdm,
103 struct clkdm_dep *deps)
104{
105 struct clkdm_dep *cd;
106
Paul Walmsleya5ffef62011-09-14 16:01:21 -0600107 if (!clkdm || !deps)
Paul Walmsley55ed9692010-01-26 20:12:59 -0700108 return ERR_PTR(-EINVAL);
109
110 for (cd = deps; cd->clkdm_name; cd++) {
Paul Walmsley55ed9692010-01-26 20:12:59 -0700111 if (!cd->clkdm && cd->clkdm_name)
112 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
113
114 if (cd->clkdm == clkdm)
115 break;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700116 }
117
118 if (!cd->clkdm_name)
119 return ERR_PTR(-ENOENT);
120
121 return cd;
122}
123
Paul Walmsley65958fb2013-01-26 00:58:17 -0700124/**
Paul Walmsley55ed9692010-01-26 20:12:59 -0700125 * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store
126 * @autodep: struct clkdm_autodep * to resolve
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300127 *
Paul Walmsley55ed9692010-01-26 20:12:59 -0700128 * Resolve autodep clockdomain names to clockdomain pointers via
129 * clkdm_lookup() and store the pointers in the autodep structure. An
130 * "autodep" is a clockdomain sleep/wakeup dependency that is
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300131 * automatically added and removed whenever clocks in the associated
132 * clockdomain are enabled or disabled (respectively) when the
133 * clockdomain is in hardware-supervised mode. Meant to be called
134 * once at clockdomain layer initialization, since these should remain
135 * fixed for a particular architecture. No return value.
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700136 *
137 * XXX autodeps are deprecated and should be removed at the earliest
138 * opportunity
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300139 */
Paul Walmsley55ed9692010-01-26 20:12:59 -0700140static void _autodep_lookup(struct clkdm_autodep *autodep)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300141{
Paul Walmsley55ed9692010-01-26 20:12:59 -0700142 struct clockdomain *clkdm;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300143
144 if (!autodep)
145 return;
146
Paul Walmsley55ed9692010-01-26 20:12:59 -0700147 clkdm = clkdm_lookup(autodep->clkdm.name);
148 if (!clkdm) {
149 pr_err("clockdomain: autodeps: clockdomain %s does not exist\n",
150 autodep->clkdm.name);
151 clkdm = ERR_PTR(-ENOENT);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300152 }
Paul Walmsley55ed9692010-01-26 20:12:59 -0700153 autodep->clkdm.ptr = clkdm;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300154}
155
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700156/**
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700157 * _resolve_clkdm_deps() - resolve clkdm_names in @clkdm_deps to clkdms
158 * @clkdm: clockdomain that we are resolving dependencies for
159 * @clkdm_deps: ptr to array of struct clkdm_deps to resolve
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600160 *
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700161 * Iterates through @clkdm_deps, looking up the struct clockdomain named by
162 * clkdm_name and storing the clockdomain pointer in the struct clkdm_dep.
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700163 * No return value.
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700164 */
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700165static void _resolve_clkdm_deps(struct clockdomain *clkdm,
166 struct clkdm_dep *clkdm_deps)
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600167{
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700168 struct clkdm_dep *cd;
169
170 for (cd = clkdm_deps; cd && cd->clkdm_name; cd++) {
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700171 if (cd->clkdm)
172 continue;
173 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
174
175 WARN(!cd->clkdm, "clockdomain: %s: could not find clkdm %s while resolving dependencies - should never happen",
176 clkdm->name, cd->clkdm_name);
177 }
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600178}
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300179
Paul Walmsley65958fb2013-01-26 00:58:17 -0700180/**
181 * _clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1 (lockless)
182 * @clkdm1: wake this struct clockdomain * up (dependent)
183 * @clkdm2: when this struct clockdomain * wakes up (source)
184 *
185 * When the clockdomain represented by @clkdm2 wakes up, wake up
186 * @clkdm1. Implemented in hardware on the OMAP, this feature is
187 * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
188 * Returns -EINVAL if presented with invalid clockdomain pointers,
189 * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
190 * success.
191 */
192static int _clkdm_add_wkdep(struct clockdomain *clkdm1,
193 struct clockdomain *clkdm2)
194{
195 struct clkdm_dep *cd;
196 int ret = 0;
197
198 if (!clkdm1 || !clkdm2)
199 return -EINVAL;
200
201 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
202 if (IS_ERR(cd))
203 ret = PTR_ERR(cd);
204
205 if (!arch_clkdm || !arch_clkdm->clkdm_add_wkdep)
206 ret = -EINVAL;
207
208 if (ret) {
209 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
210 clkdm1->name, clkdm2->name);
211 return ret;
212 }
213
Paul Walmsley92493872013-01-26 00:58:17 -0700214 cd->wkdep_usecount++;
215 if (cd->wkdep_usecount == 1) {
Paul Walmsley65958fb2013-01-26 00:58:17 -0700216 pr_debug("clockdomain: hardware will wake up %s when %s wakes up\n",
217 clkdm1->name, clkdm2->name);
218
219 ret = arch_clkdm->clkdm_add_wkdep(clkdm1, clkdm2);
220 }
221
222 return ret;
223}
224
225/**
226 * _clkdm_del_wkdep - remove a wakeup dep from clkdm2 to clkdm1 (lockless)
227 * @clkdm1: wake this struct clockdomain * up (dependent)
228 * @clkdm2: when this struct clockdomain * wakes up (source)
229 *
230 * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
231 * wakes up. Returns -EINVAL if presented with invalid clockdomain
232 * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
233 * 0 upon success.
234 */
235static int _clkdm_del_wkdep(struct clockdomain *clkdm1,
236 struct clockdomain *clkdm2)
237{
238 struct clkdm_dep *cd;
239 int ret = 0;
240
241 if (!clkdm1 || !clkdm2)
242 return -EINVAL;
243
244 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
245 if (IS_ERR(cd))
246 ret = PTR_ERR(cd);
247
248 if (!arch_clkdm || !arch_clkdm->clkdm_del_wkdep)
249 ret = -EINVAL;
250
251 if (ret) {
252 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
253 clkdm1->name, clkdm2->name);
254 return ret;
255 }
256
Paul Walmsley92493872013-01-26 00:58:17 -0700257 cd->wkdep_usecount--;
258 if (cd->wkdep_usecount == 0) {
Paul Walmsley65958fb2013-01-26 00:58:17 -0700259 pr_debug("clockdomain: hardware will no longer wake up %s after %s wakes up\n",
260 clkdm1->name, clkdm2->name);
261
262 ret = arch_clkdm->clkdm_del_wkdep(clkdm1, clkdm2);
263 }
264
265 return ret;
266}
267
268/**
269 * _clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1 (lockless)
270 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
271 * @clkdm2: when this struct clockdomain * is active (source)
272 *
273 * Prevent @clkdm1 from automatically going inactive (and then to
274 * retention or off) if @clkdm2 is active. Returns -EINVAL if
275 * presented with invalid clockdomain pointers or called on a machine
276 * that does not support software-configurable hardware sleep
277 * dependencies, -ENOENT if the specified dependency cannot be set in
278 * hardware, or 0 upon success.
279 */
280static int _clkdm_add_sleepdep(struct clockdomain *clkdm1,
281 struct clockdomain *clkdm2)
282{
283 struct clkdm_dep *cd;
284 int ret = 0;
285
286 if (!clkdm1 || !clkdm2)
287 return -EINVAL;
288
289 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
290 if (IS_ERR(cd))
291 ret = PTR_ERR(cd);
292
293 if (!arch_clkdm || !arch_clkdm->clkdm_add_sleepdep)
294 ret = -EINVAL;
295
296 if (ret) {
297 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
298 clkdm1->name, clkdm2->name);
299 return ret;
300 }
301
Paul Walmsley92493872013-01-26 00:58:17 -0700302 cd->sleepdep_usecount++;
303 if (cd->sleepdep_usecount == 1) {
Paul Walmsley65958fb2013-01-26 00:58:17 -0700304 pr_debug("clockdomain: will prevent %s from sleeping if %s is active\n",
305 clkdm1->name, clkdm2->name);
306
307 ret = arch_clkdm->clkdm_add_sleepdep(clkdm1, clkdm2);
308 }
309
310 return ret;
311}
312
313/**
314 * _clkdm_del_sleepdep - remove a sleep dep from clkdm2 to clkdm1 (lockless)
315 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
316 * @clkdm2: when this struct clockdomain * is active (source)
317 *
318 * Allow @clkdm1 to automatically go inactive (and then to retention or
319 * off), independent of the activity state of @clkdm2. Returns -EINVAL
320 * if presented with invalid clockdomain pointers or called on a machine
321 * that does not support software-configurable hardware sleep dependencies,
322 * -ENOENT if the specified dependency cannot be cleared in hardware, or
323 * 0 upon success.
324 */
325static int _clkdm_del_sleepdep(struct clockdomain *clkdm1,
326 struct clockdomain *clkdm2)
327{
328 struct clkdm_dep *cd;
329 int ret = 0;
330
331 if (!clkdm1 || !clkdm2)
332 return -EINVAL;
333
334 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
335 if (IS_ERR(cd))
336 ret = PTR_ERR(cd);
337
338 if (!arch_clkdm || !arch_clkdm->clkdm_del_sleepdep)
339 ret = -EINVAL;
340
341 if (ret) {
342 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
343 clkdm1->name, clkdm2->name);
344 return ret;
345 }
346
Paul Walmsley92493872013-01-26 00:58:17 -0700347 cd->sleepdep_usecount--;
348 if (cd->sleepdep_usecount == 0) {
Paul Walmsley65958fb2013-01-26 00:58:17 -0700349 pr_debug("clockdomain: will no longer prevent %s from sleeping if %s is active\n",
350 clkdm1->name, clkdm2->name);
351
352 ret = arch_clkdm->clkdm_del_sleepdep(clkdm1, clkdm2);
353 }
354
355 return ret;
356}
357
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300358/* Public functions */
359
360/**
Paul Walmsley08cb9702011-09-14 16:01:20 -0600361 * clkdm_register_platform_funcs - register clockdomain implementation fns
362 * @co: func pointers for arch specific implementations
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300363 *
Paul Walmsley08cb9702011-09-14 16:01:20 -0600364 * Register the list of function pointers used to implement the
365 * clockdomain functions on different OMAP SoCs. Should be called
366 * before any other clkdm_register*() function. Returns -EINVAL if
367 * @co is null, -EEXIST if platform functions have already been
368 * registered, or 0 upon success.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300369 */
Paul Walmsley08cb9702011-09-14 16:01:20 -0600370int clkdm_register_platform_funcs(struct clkdm_ops *co)
371{
372 if (!co)
373 return -EINVAL;
374
375 if (arch_clkdm)
376 return -EEXIST;
377
378 arch_clkdm = co;
379
380 return 0;
381};
382
383/**
384 * clkdm_register_clkdms - register SoC clockdomains
385 * @cs: pointer to an array of struct clockdomain to register
386 *
387 * Register the clockdomains available on a particular OMAP SoC. Must
388 * be called after clkdm_register_platform_funcs(). May be called
389 * multiple times. Returns -EACCES if called before
390 * clkdm_register_platform_funcs(); -EINVAL if the argument @cs is
391 * null; or 0 upon success.
392 */
393int clkdm_register_clkdms(struct clockdomain **cs)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300394{
395 struct clockdomain **c = NULL;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300396
Paul Walmsley08cb9702011-09-14 16:01:20 -0600397 if (!arch_clkdm)
398 return -EACCES;
Rajendra Nayak32d40342011-02-25 16:06:47 -0700399
Paul Walmsley08cb9702011-09-14 16:01:20 -0600400 if (!cs)
401 return -EINVAL;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300402
Paul Walmsley08cb9702011-09-14 16:01:20 -0600403 for (c = cs; *c; c++)
404 _clkdm_register(*c);
405
406 return 0;
407}
408
409/**
410 * clkdm_register_autodeps - register autodeps (if required)
411 * @ia: pointer to a static array of struct clkdm_autodep to register
412 *
413 * Register clockdomain "automatic dependencies." These are
414 * clockdomain wakeup and sleep dependencies that are automatically
415 * added whenever the first clock inside a clockdomain is enabled, and
416 * removed whenever the last clock inside a clockdomain is disabled.
417 * These are currently only used on OMAP3 devices, and are deprecated,
418 * since they waste energy. However, until the OMAP2/3 IP block
419 * enable/disable sequence can be converted to match the OMAP4
420 * sequence, they are needed.
421 *
422 * Must be called only after all of the SoC clockdomains are
423 * registered, since the function will resolve autodep clockdomain
424 * names into clockdomain pointers.
425 *
426 * The struct clkdm_autodep @ia array must be static, as this function
427 * does not copy the array elements.
428 *
429 * Returns -EACCES if called before any clockdomains have been
430 * registered, -EINVAL if called with a null @ia argument, -EEXIST if
431 * autodeps have already been registered, or 0 upon success.
432 */
433int clkdm_register_autodeps(struct clkdm_autodep *ia)
434{
435 struct clkdm_autodep *a = NULL;
436
437 if (list_empty(&clkdm_list))
438 return -EACCES;
439
440 if (!ia)
441 return -EINVAL;
442
Paul Walmsley55ed9692010-01-26 20:12:59 -0700443 if (autodeps)
Paul Walmsley08cb9702011-09-14 16:01:20 -0600444 return -EEXIST;
Paul Walmsley369d5612010-01-26 20:13:01 -0700445
Paul Walmsley08cb9702011-09-14 16:01:20 -0600446 autodeps = ia;
447 for (a = autodeps; a->clkdm.ptr; a++)
448 _autodep_lookup(a);
449
450 return 0;
451}
452
Keerthy9bcfb762018-05-16 20:46:59 +0530453static int cpu_notifier(struct notifier_block *nb, unsigned long cmd, void *v)
454{
455 switch (cmd) {
456 case CPU_CLUSTER_PM_ENTER:
457 if (enable_off_mode)
458 clkdm_save_context();
459 break;
460 case CPU_CLUSTER_PM_EXIT:
461 if (enable_off_mode)
462 clkdm_restore_context();
463 break;
464 }
465
466 return NOTIFY_OK;
467}
468
Paul Walmsley08cb9702011-09-14 16:01:20 -0600469/**
470 * clkdm_complete_init - set up the clockdomain layer
471 *
472 * Put all clockdomains into software-supervised mode; PM code should
473 * later enable hardware-supervised mode as appropriate. Must be
474 * called after clkdm_register_clkdms(). Returns -EACCES if called
475 * before clkdm_register_clkdms(), or 0 upon success.
476 */
477int clkdm_complete_init(void)
478{
479 struct clockdomain *clkdm;
Keerthy9bcfb762018-05-16 20:46:59 +0530480 static struct notifier_block nb;
Paul Walmsley08cb9702011-09-14 16:01:20 -0600481
482 if (list_empty(&clkdm_list))
483 return -EACCES;
484
Paul Walmsley369d5612010-01-26 20:13:01 -0700485 list_for_each_entry(clkdm, &clkdm_list, node) {
Tero Kristo1d9a5422016-06-30 16:15:02 +0300486 clkdm_deny_idle(clkdm);
Paul Walmsley6f7f63c2010-09-14 15:56:53 -0600487
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700488 _resolve_clkdm_deps(clkdm, clkdm->wkdep_srcs);
Paul Walmsley6f7f63c2010-09-14 15:56:53 -0600489 clkdm_clear_all_wkdeps(clkdm);
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700490
491 _resolve_clkdm_deps(clkdm, clkdm->sleepdep_srcs);
Paul Walmsley6f7f63c2010-09-14 15:56:53 -0600492 clkdm_clear_all_sleepdeps(clkdm);
Paul Walmsley369d5612010-01-26 20:13:01 -0700493 }
Paul Walmsley08cb9702011-09-14 16:01:20 -0600494
Keerthy9bcfb762018-05-16 20:46:59 +0530495 /* Only AM43XX can lose clkdm context during rtc-ddr suspend */
496 if (soc_is_am43xx()) {
497 nb.notifier_call = cpu_notifier;
498 cpu_pm_register_notifier(&nb);
499 }
500
Paul Walmsley08cb9702011-09-14 16:01:20 -0600501 return 0;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300502}
503
504/**
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300505 * clkdm_lookup - look up a clockdomain by name, return a pointer
506 * @name: name of clockdomain
507 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700508 * Find a registered clockdomain by its name @name. Returns a pointer
509 * to the struct clockdomain if found, or NULL otherwise.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300510 */
511struct clockdomain *clkdm_lookup(const char *name)
512{
513 struct clockdomain *clkdm, *temp_clkdm;
514
515 if (!name)
516 return NULL;
517
518 clkdm = NULL;
519
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300520 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
521 if (!strcmp(name, temp_clkdm->name)) {
522 clkdm = temp_clkdm;
523 break;
524 }
525 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300526
527 return clkdm;
528}
529
530/**
531 * clkdm_for_each - call function on each registered clockdomain
532 * @fn: callback function *
533 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700534 * Call the supplied function @fn for each registered clockdomain.
535 * The callback function @fn can return anything but 0 to bail
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300536 * out early from the iterator. The callback function is called with
537 * the clkdm_mutex held, so no clockdomain structure manipulation
538 * functions should be called from the callback, although hardware
539 * clockdomain control functions are fine. Returns the last return
540 * value of the callback function, which should be 0 for success or
541 * anything else to indicate failure; or -EINVAL if the function pointer
542 * is null.
543 */
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300544int clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user),
545 void *user)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300546{
547 struct clockdomain *clkdm;
548 int ret = 0;
549
550 if (!fn)
551 return -EINVAL;
552
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300553 list_for_each_entry(clkdm, &clkdm_list, node) {
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300554 ret = (*fn)(clkdm, user);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300555 if (ret)
556 break;
557 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300558
559 return ret;
560}
561
562
Paul Walmsleye89087c2008-05-20 18:41:35 -0600563/**
564 * clkdm_get_pwrdm - return a ptr to the pwrdm that this clkdm resides in
565 * @clkdm: struct clockdomain *
566 *
567 * Return a pointer to the struct powerdomain that the specified clockdomain
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700568 * @clkdm exists in, or returns NULL if @clkdm is NULL.
Paul Walmsleye89087c2008-05-20 18:41:35 -0600569 */
570struct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm)
571{
572 if (!clkdm)
573 return NULL;
574
Paul Walmsley5b74c672009-02-03 02:10:03 -0700575 return clkdm->pwrdm.ptr;
Paul Walmsleye89087c2008-05-20 18:41:35 -0600576}
577
578
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300579/* Hardware clockdomain control */
580
581/**
Paul Walmsley55ed9692010-01-26 20:12:59 -0700582 * clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1
583 * @clkdm1: wake this struct clockdomain * up (dependent)
584 * @clkdm2: when this struct clockdomain * wakes up (source)
585 *
586 * When the clockdomain represented by @clkdm2 wakes up, wake up
587 * @clkdm1. Implemented in hardware on the OMAP, this feature is
588 * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
589 * Returns -EINVAL if presented with invalid clockdomain pointers,
590 * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
591 * success.
592 */
593int clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
594{
Paul Walmsley92493872013-01-26 00:58:17 -0700595 struct clkdm_dep *cd;
596 int ret;
597
598 if (!clkdm1 || !clkdm2)
599 return -EINVAL;
600
601 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
602 if (IS_ERR(cd))
603 return PTR_ERR(cd);
604
605 pwrdm_lock(cd->clkdm->pwrdm.ptr);
606 ret = _clkdm_add_wkdep(clkdm1, clkdm2);
607 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
608
609 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700610}
611
612/**
613 * clkdm_del_wkdep - remove a wakeup dependency from clkdm2 to clkdm1
614 * @clkdm1: wake this struct clockdomain * up (dependent)
615 * @clkdm2: when this struct clockdomain * wakes up (source)
616 *
617 * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
618 * wakes up. Returns -EINVAL if presented with invalid clockdomain
619 * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
620 * 0 upon success.
621 */
622int clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
623{
Paul Walmsley92493872013-01-26 00:58:17 -0700624 struct clkdm_dep *cd;
625 int ret;
626
627 if (!clkdm1 || !clkdm2)
628 return -EINVAL;
629
630 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
631 if (IS_ERR(cd))
632 return PTR_ERR(cd);
633
634 pwrdm_lock(cd->clkdm->pwrdm.ptr);
635 ret = _clkdm_del_wkdep(clkdm1, clkdm2);
636 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
637
638 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700639}
640
641/**
642 * clkdm_read_wkdep - read wakeup dependency state from clkdm2 to clkdm1
643 * @clkdm1: wake this struct clockdomain * up (dependent)
644 * @clkdm2: when this struct clockdomain * wakes up (source)
645 *
646 * Return 1 if a hardware wakeup dependency exists wherein @clkdm1 will be
647 * awoken when @clkdm2 wakes up; 0 if dependency is not set; -EINVAL
648 * if either clockdomain pointer is invalid; or -ENOENT if the hardware
649 * is incapable.
650 *
651 * REVISIT: Currently this function only represents software-controllable
652 * wakeup dependencies. Wakeup dependencies fixed in hardware are not
653 * yet handled here.
654 */
655int clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
656{
657 struct clkdm_dep *cd;
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700658 int ret = 0;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700659
660 if (!clkdm1 || !clkdm2)
661 return -EINVAL;
662
663 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700664 if (IS_ERR(cd))
665 ret = PTR_ERR(cd);
666
667 if (!arch_clkdm || !arch_clkdm->clkdm_read_wkdep)
668 ret = -EINVAL;
669
670 if (ret) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600671 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
672 clkdm1->name, clkdm2->name);
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700673 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700674 }
675
Paul Walmsley92493872013-01-26 00:58:17 -0700676 /* XXX It's faster to return the wkdep_usecount */
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700677 return arch_clkdm->clkdm_read_wkdep(clkdm1, clkdm2);
Paul Walmsley55ed9692010-01-26 20:12:59 -0700678}
679
680/**
Paul Walmsley369d5612010-01-26 20:13:01 -0700681 * clkdm_clear_all_wkdeps - remove all wakeup dependencies from target clkdm
682 * @clkdm: struct clockdomain * to remove all wakeup dependencies from
683 *
684 * Remove all inter-clockdomain wakeup dependencies that could cause
685 * @clkdm to wake. Intended to be used during boot to initialize the
686 * PRCM to a known state, after all clockdomains are put into swsup idle
687 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
688 * 0 upon success.
689 */
690int clkdm_clear_all_wkdeps(struct clockdomain *clkdm)
691{
Paul Walmsley369d5612010-01-26 20:13:01 -0700692 if (!clkdm)
693 return -EINVAL;
694
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700695 if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_wkdeps)
696 return -EINVAL;
Paul Walmsley369d5612010-01-26 20:13:01 -0700697
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700698 return arch_clkdm->clkdm_clear_all_wkdeps(clkdm);
Paul Walmsley369d5612010-01-26 20:13:01 -0700699}
700
701/**
Paul Walmsley55ed9692010-01-26 20:12:59 -0700702 * clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1
703 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
704 * @clkdm2: when this struct clockdomain * is active (source)
705 *
706 * Prevent @clkdm1 from automatically going inactive (and then to
707 * retention or off) if @clkdm2 is active. Returns -EINVAL if
708 * presented with invalid clockdomain pointers or called on a machine
709 * that does not support software-configurable hardware sleep
710 * dependencies, -ENOENT if the specified dependency cannot be set in
711 * hardware, or 0 upon success.
712 */
713int clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
714{
Paul Walmsley92493872013-01-26 00:58:17 -0700715 struct clkdm_dep *cd;
716 int ret;
717
718 if (!clkdm1 || !clkdm2)
719 return -EINVAL;
720
721 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
722 if (IS_ERR(cd))
723 return PTR_ERR(cd);
724
725 pwrdm_lock(cd->clkdm->pwrdm.ptr);
726 ret = _clkdm_add_sleepdep(clkdm1, clkdm2);
727 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
728
729 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700730}
731
732/**
733 * clkdm_del_sleepdep - remove a sleep dependency from clkdm2 to clkdm1
734 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
735 * @clkdm2: when this struct clockdomain * is active (source)
736 *
737 * Allow @clkdm1 to automatically go inactive (and then to retention or
738 * off), independent of the activity state of @clkdm2. Returns -EINVAL
739 * if presented with invalid clockdomain pointers or called on a machine
740 * that does not support software-configurable hardware sleep dependencies,
741 * -ENOENT if the specified dependency cannot be cleared in hardware, or
742 * 0 upon success.
743 */
744int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
745{
Paul Walmsley92493872013-01-26 00:58:17 -0700746 struct clkdm_dep *cd;
747 int ret;
748
749 if (!clkdm1 || !clkdm2)
750 return -EINVAL;
751
752 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
753 if (IS_ERR(cd))
754 return PTR_ERR(cd);
755
756 pwrdm_lock(cd->clkdm->pwrdm.ptr);
757 ret = _clkdm_del_sleepdep(clkdm1, clkdm2);
758 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
759
760 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700761}
762
763/**
764 * clkdm_read_sleepdep - read sleep dependency state from clkdm2 to clkdm1
765 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
766 * @clkdm2: when this struct clockdomain * is active (source)
767 *
768 * Return 1 if a hardware sleep dependency exists wherein @clkdm1 will
769 * not be allowed to automatically go inactive if @clkdm2 is active;
770 * 0 if @clkdm1's automatic power state inactivity transition is independent
771 * of @clkdm2's; -EINVAL if either clockdomain pointer is invalid or called
772 * on a machine that does not support software-configurable hardware sleep
773 * dependencies; or -ENOENT if the hardware is incapable.
774 *
775 * REVISIT: Currently this function only represents software-controllable
776 * sleep dependencies. Sleep dependencies fixed in hardware are not
777 * yet handled here.
778 */
779int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
780{
781 struct clkdm_dep *cd;
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700782 int ret = 0;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700783
784 if (!clkdm1 || !clkdm2)
785 return -EINVAL;
786
787 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700788 if (IS_ERR(cd))
789 ret = PTR_ERR(cd);
790
791 if (!arch_clkdm || !arch_clkdm->clkdm_read_sleepdep)
792 ret = -EINVAL;
793
794 if (ret) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600795 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
796 clkdm1->name, clkdm2->name);
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700797 return ret;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700798 }
799
Paul Walmsley92493872013-01-26 00:58:17 -0700800 /* XXX It's faster to return the sleepdep_usecount */
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700801 return arch_clkdm->clkdm_read_sleepdep(clkdm1, clkdm2);
Paul Walmsley55ed9692010-01-26 20:12:59 -0700802}
803
Paul Walmsley369d5612010-01-26 20:13:01 -0700804/**
805 * clkdm_clear_all_sleepdeps - remove all sleep dependencies from target clkdm
806 * @clkdm: struct clockdomain * to remove all sleep dependencies from
807 *
808 * Remove all inter-clockdomain sleep dependencies that could prevent
809 * @clkdm from idling. Intended to be used during boot to initialize the
810 * PRCM to a known state, after all clockdomains are put into swsup idle
811 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
812 * 0 upon success.
813 */
814int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm)
815{
Paul Walmsley369d5612010-01-26 20:13:01 -0700816 if (!clkdm)
817 return -EINVAL;
818
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700819 if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_sleepdeps)
820 return -EINVAL;
Paul Walmsley369d5612010-01-26 20:13:01 -0700821
Rajendra Nayak4aef7a22011-02-25 16:06:47 -0700822 return arch_clkdm->clkdm_clear_all_sleepdeps(clkdm);
Paul Walmsley369d5612010-01-26 20:13:01 -0700823}
Paul Walmsley55ed9692010-01-26 20:12:59 -0700824
825/**
Paul Walmsley3a090282013-01-26 00:58:16 -0700826 * clkdm_sleep_nolock - force clockdomain sleep transition (lockless)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300827 * @clkdm: struct clockdomain *
828 *
829 * Instruct the CM to force a sleep transition on the specified
Paul Walmsley3a090282013-01-26 00:58:16 -0700830 * clockdomain @clkdm. Only for use by the powerdomain code. Returns
831 * -EINVAL if @clkdm is NULL or if clockdomain does not support
832 * software-initiated sleep; 0 upon success.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300833 */
Paul Walmsley3a090282013-01-26 00:58:16 -0700834int clkdm_sleep_nolock(struct clockdomain *clkdm)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300835{
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600836 int ret;
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600837
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300838 if (!clkdm)
839 return -EINVAL;
840
841 if (!(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600842 pr_debug("clockdomain: %s does not support forcing sleep via software\n",
843 clkdm->name);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300844 return -EINVAL;
845 }
846
Rajendra Nayak68b921a2011-02-25 16:06:47 -0700847 if (!arch_clkdm || !arch_clkdm->clkdm_sleep)
848 return -EINVAL;
849
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300850 pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name);
851
Paul Walmsley32a363c2011-07-10 05:56:54 -0600852 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600853 ret = arch_clkdm->clkdm_sleep(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -0700854 ret |= pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
855
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600856 return ret;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300857}
858
859/**
Paul Walmsley3a090282013-01-26 00:58:16 -0700860 * clkdm_sleep - force clockdomain sleep transition
861 * @clkdm: struct clockdomain *
862 *
863 * Instruct the CM to force a sleep transition on the specified
864 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if
865 * clockdomain does not support software-initiated sleep; 0 upon
866 * success.
867 */
868int clkdm_sleep(struct clockdomain *clkdm)
869{
870 int ret;
871
872 pwrdm_lock(clkdm->pwrdm.ptr);
873 ret = clkdm_sleep_nolock(clkdm);
874 pwrdm_unlock(clkdm->pwrdm.ptr);
875
876 return ret;
877}
878
879/**
880 * clkdm_wakeup_nolock - force clockdomain wakeup transition (lockless)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300881 * @clkdm: struct clockdomain *
882 *
883 * Instruct the CM to force a wakeup transition on the specified
Paul Walmsley3a090282013-01-26 00:58:16 -0700884 * clockdomain @clkdm. Only for use by the powerdomain code. Returns
885 * -EINVAL if @clkdm is NULL or if the clockdomain does not support
886 * software-controlled wakeup; 0 upon success.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300887 */
Paul Walmsley3a090282013-01-26 00:58:16 -0700888int clkdm_wakeup_nolock(struct clockdomain *clkdm)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300889{
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600890 int ret;
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600891
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300892 if (!clkdm)
893 return -EINVAL;
894
895 if (!(clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)) {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600896 pr_debug("clockdomain: %s does not support forcing wakeup via software\n",
897 clkdm->name);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300898 return -EINVAL;
899 }
900
Rajendra Nayak68b921a2011-02-25 16:06:47 -0700901 if (!arch_clkdm || !arch_clkdm->clkdm_wakeup)
902 return -EINVAL;
903
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300904 pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name);
905
Paul Walmsley32a363c2011-07-10 05:56:54 -0600906 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600907 ret = arch_clkdm->clkdm_wakeup(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -0700908 ret |= pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
909
Rajendra Nayak555e74e2011-07-10 05:56:55 -0600910 return ret;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300911}
912
913/**
Paul Walmsley3a090282013-01-26 00:58:16 -0700914 * clkdm_wakeup - force clockdomain wakeup transition
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300915 * @clkdm: struct clockdomain *
916 *
Paul Walmsley3a090282013-01-26 00:58:16 -0700917 * Instruct the CM to force a wakeup transition on the specified
918 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the
919 * clockdomain does not support software-controlled wakeup; 0 upon
920 * success.
921 */
922int clkdm_wakeup(struct clockdomain *clkdm)
923{
924 int ret;
925
926 pwrdm_lock(clkdm->pwrdm.ptr);
927 ret = clkdm_wakeup_nolock(clkdm);
928 pwrdm_unlock(clkdm->pwrdm.ptr);
929
930 return ret;
931}
932
933/**
934 * clkdm_allow_idle_nolock - enable hwsup idle transitions for clkdm
935 * @clkdm: struct clockdomain *
936 *
937 * Allow the hardware to automatically switch the clockdomain @clkdm
938 * into active or idle states, as needed by downstream clocks. If the
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300939 * clockdomain has any downstream clocks enabled in the clock
940 * framework, wkdep/sleepdep autodependencies are added; this is so
Paul Walmsley3a090282013-01-26 00:58:16 -0700941 * device drivers can read and write to the device. Only for use by
942 * the powerdomain code. No return value.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300943 */
Paul Walmsley3a090282013-01-26 00:58:16 -0700944void clkdm_allow_idle_nolock(struct clockdomain *clkdm)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300945{
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300946 if (!clkdm)
947 return;
948
Tero Kristo1d9a5422016-06-30 16:15:02 +0300949 if (!WARN_ON(!clkdm->forcewake_count))
950 clkdm->forcewake_count--;
951
952 if (clkdm->forcewake_count)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300953 return;
Tero Kristo1d9a5422016-06-30 16:15:02 +0300954
955 if (!clkdm->usecount && (clkdm->flags & CLKDM_CAN_FORCE_SLEEP))
956 clkdm_sleep_nolock(clkdm);
957
958 if (!(clkdm->flags & CLKDM_CAN_ENABLE_AUTO))
959 return;
960
961 if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING)
962 return;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300963
Rajendra Nayak5cd19372011-02-25 16:06:48 -0700964 if (!arch_clkdm || !arch_clkdm->clkdm_allow_idle)
965 return;
966
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300967 pr_debug("clockdomain: enabling automatic idle transitions for %s\n",
968 clkdm->name);
969
Paul Walmsley32a363c2011-07-10 05:56:54 -0600970 clkdm->_flags |= _CLKDM_FLAG_HWSUP_ENABLED;
Rajendra Nayak5cd19372011-02-25 16:06:48 -0700971 arch_clkdm->clkdm_allow_idle(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -0700972 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
973}
974
975/**
976 * clkdm_allow_idle - enable hwsup idle transitions for clkdm
977 * @clkdm: struct clockdomain *
978 *
979 * Allow the hardware to automatically switch the clockdomain @clkdm into
980 * active or idle states, as needed by downstream clocks. If the
981 * clockdomain has any downstream clocks enabled in the clock
982 * framework, wkdep/sleepdep autodependencies are added; this is so
983 * device drivers can read and write to the device. No return value.
984 */
985void clkdm_allow_idle(struct clockdomain *clkdm)
986{
987 pwrdm_lock(clkdm->pwrdm.ptr);
988 clkdm_allow_idle_nolock(clkdm);
989 pwrdm_unlock(clkdm->pwrdm.ptr);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300990}
991
992/**
Rajendra Nayak5cd19372011-02-25 16:06:48 -0700993 * clkdm_deny_idle - disable hwsup idle transitions for clkdm
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300994 * @clkdm: struct clockdomain *
995 *
996 * Prevent the hardware from automatically switching the clockdomain
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700997 * @clkdm into inactive or idle states. If the clockdomain has
998 * downstream clocks enabled in the clock framework, wkdep/sleepdep
Paul Walmsley3a090282013-01-26 00:58:16 -0700999 * autodependencies are removed. Only for use by the powerdomain
1000 * code. No return value.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001001 */
Paul Walmsley3a090282013-01-26 00:58:16 -07001002void clkdm_deny_idle_nolock(struct clockdomain *clkdm)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001003{
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001004 if (!clkdm)
1005 return;
1006
Tero Kristo1d9a5422016-06-30 16:15:02 +03001007 if (clkdm->forcewake_count++)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001008 return;
Tero Kristo1d9a5422016-06-30 16:15:02 +03001009
1010 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
1011 clkdm_wakeup_nolock(clkdm);
1012
1013 if (!(clkdm->flags & CLKDM_CAN_DISABLE_AUTO))
1014 return;
1015
1016 if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING)
1017 return;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001018
Rajendra Nayak5cd19372011-02-25 16:06:48 -07001019 if (!arch_clkdm || !arch_clkdm->clkdm_deny_idle)
1020 return;
1021
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001022 pr_debug("clockdomain: disabling automatic idle transitions for %s\n",
1023 clkdm->name);
1024
Paul Walmsley32a363c2011-07-10 05:56:54 -06001025 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
Rajendra Nayak5cd19372011-02-25 16:06:48 -07001026 arch_clkdm->clkdm_deny_idle(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -07001027 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
1028}
1029
1030/**
1031 * clkdm_deny_idle - disable hwsup idle transitions for clkdm
1032 * @clkdm: struct clockdomain *
1033 *
1034 * Prevent the hardware from automatically switching the clockdomain
1035 * @clkdm into inactive or idle states. If the clockdomain has
1036 * downstream clocks enabled in the clock framework, wkdep/sleepdep
1037 * autodependencies are removed. No return value.
1038 */
1039void clkdm_deny_idle(struct clockdomain *clkdm)
1040{
1041 pwrdm_lock(clkdm->pwrdm.ptr);
1042 clkdm_deny_idle_nolock(clkdm);
1043 pwrdm_unlock(clkdm->pwrdm.ptr);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001044}
1045
Paul Walmsley32a363c2011-07-10 05:56:54 -06001046/**
1047 * clkdm_in_hwsup - is clockdomain @clkdm have hardware-supervised idle enabled?
1048 * @clkdm: struct clockdomain *
1049 *
1050 * Returns true if clockdomain @clkdm currently has
1051 * hardware-supervised idle enabled, or false if it does not or if
1052 * @clkdm is NULL. It is only valid to call this function after
1053 * clkdm_init() has been called. This function does not actually read
1054 * bits from the hardware; it instead tests an in-memory flag that is
1055 * changed whenever the clockdomain code changes the auto-idle mode.
1056 */
1057bool clkdm_in_hwsup(struct clockdomain *clkdm)
1058{
Rajendra Nayak555e74e2011-07-10 05:56:55 -06001059 bool ret;
Rajendra Nayak555e74e2011-07-10 05:56:55 -06001060
Paul Walmsley32a363c2011-07-10 05:56:54 -06001061 if (!clkdm)
1062 return false;
1063
Rajendra Nayak555e74e2011-07-10 05:56:55 -06001064 ret = (clkdm->_flags & _CLKDM_FLAG_HWSUP_ENABLED) ? true : false;
Rajendra Nayak555e74e2011-07-10 05:56:55 -06001065
1066 return ret;
Paul Walmsley32a363c2011-07-10 05:56:54 -06001067}
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001068
Paul Walmsleyb71c7212012-09-23 17:28:28 -06001069/**
1070 * clkdm_missing_idle_reporting - can @clkdm enter autoidle even if in use?
1071 * @clkdm: struct clockdomain *
1072 *
1073 * Returns true if clockdomain @clkdm has the
1074 * CLKDM_MISSING_IDLE_REPORTING flag set, or false if not or @clkdm is
1075 * null. More information is available in the documentation for the
1076 * CLKDM_MISSING_IDLE_REPORTING macro.
1077 */
1078bool clkdm_missing_idle_reporting(struct clockdomain *clkdm)
1079{
1080 if (!clkdm)
1081 return false;
1082
1083 return (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING) ? true : false;
1084}
1085
Paul Walmsley65958fb2013-01-26 00:58:17 -07001086/* Public autodep handling functions (deprecated) */
1087
1088/**
1089 * clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable
1090 * @clkdm: struct clockdomain *
1091 *
1092 * Add the "autodep" sleep & wakeup dependencies to clockdomain 'clkdm'
1093 * in hardware-supervised mode. Meant to be called from clock framework
1094 * when a clock inside clockdomain 'clkdm' is enabled. No return value.
1095 *
1096 * XXX autodeps are deprecated and should be removed at the earliest
1097 * opportunity
1098 */
1099void clkdm_add_autodeps(struct clockdomain *clkdm)
1100{
1101 struct clkdm_autodep *autodep;
1102
1103 if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
1104 return;
1105
1106 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
1107 if (IS_ERR(autodep->clkdm.ptr))
1108 continue;
1109
1110 pr_debug("clockdomain: %s: adding %s sleepdep/wkdep\n",
1111 clkdm->name, autodep->clkdm.ptr->name);
1112
1113 _clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr);
1114 _clkdm_add_wkdep(clkdm, autodep->clkdm.ptr);
1115 }
1116}
1117
1118/**
1119 * clkdm_del_autodeps - remove auto sleepdeps/wkdeps from clkdm
1120 * @clkdm: struct clockdomain *
1121 *
1122 * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm'
1123 * in hardware-supervised mode. Meant to be called from clock framework
1124 * when a clock inside clockdomain 'clkdm' is disabled. No return value.
1125 *
1126 * XXX autodeps are deprecated and should be removed at the earliest
1127 * opportunity
1128 */
1129void clkdm_del_autodeps(struct clockdomain *clkdm)
1130{
1131 struct clkdm_autodep *autodep;
1132
1133 if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
1134 return;
1135
1136 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
1137 if (IS_ERR(autodep->clkdm.ptr))
1138 continue;
1139
1140 pr_debug("clockdomain: %s: removing %s sleepdep/wkdep\n",
1141 clkdm->name, autodep->clkdm.ptr->name);
1142
1143 _clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr);
1144 _clkdm_del_wkdep(clkdm, autodep->clkdm.ptr);
1145 }
1146}
1147
Benoit Cousson113a7412011-07-10 05:56:54 -06001148/* Clockdomain-to-clock/hwmod framework interface code */
1149
1150static int _clkdm_clk_hwmod_enable(struct clockdomain *clkdm)
1151{
1152 if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_enable)
1153 return -EINVAL;
1154
Paul Walmsley3a090282013-01-26 00:58:16 -07001155 pwrdm_lock(clkdm->pwrdm.ptr);
Tero Kristo64e29fd2012-09-25 19:05:32 +03001156
Benoit Cousson113a7412011-07-10 05:56:54 -06001157 /*
1158 * For arch's with no autodeps, clkcm_clk_enable
1159 * should be called for every clock instance or hwmod that is
1160 * enabled, so the clkdm can be force woken up.
1161 */
Paul Walmsley92493872013-01-26 00:58:17 -07001162 clkdm->usecount++;
1163 if (clkdm->usecount > 1 && autodeps) {
Paul Walmsley3a090282013-01-26 00:58:16 -07001164 pwrdm_unlock(clkdm->pwrdm.ptr);
Benoit Cousson113a7412011-07-10 05:56:54 -06001165 return 0;
Tero Kristo64e29fd2012-09-25 19:05:32 +03001166 }
Benoit Cousson113a7412011-07-10 05:56:54 -06001167
1168 arch_clkdm->clkdm_clk_enable(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -07001169 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
1170 pwrdm_unlock(clkdm->pwrdm.ptr);
Benoit Cousson113a7412011-07-10 05:56:54 -06001171
Paul Walmsley7852ec02012-07-26 00:54:26 -06001172 pr_debug("clockdomain: %s: enabled\n", clkdm->name);
Benoit Cousson113a7412011-07-10 05:56:54 -06001173
1174 return 0;
1175}
1176
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001177/**
Rajendra Nayak4da71ae2011-02-25 16:06:48 -07001178 * clkdm_clk_enable - add an enabled downstream clock to this clkdm
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001179 * @clkdm: struct clockdomain *
1180 * @clk: struct clk * of the enabled downstream clock
1181 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -07001182 * Increment the usecount of the clockdomain @clkdm and ensure that it
1183 * is awake before @clk is enabled. Intended to be called by
1184 * clk_enable() code. If the clockdomain is in software-supervised
1185 * idle mode, force the clockdomain to wake. If the clockdomain is in
1186 * hardware-supervised idle mode, add clkdm-pwrdm autodependencies, to
1187 * ensure that devices in the clockdomain can be read from/written to
1188 * by on-chip processors. Returns -EINVAL if passed null pointers;
1189 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001190 */
Rajendra Nayak4da71ae2011-02-25 16:06:48 -07001191int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001192{
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001193 /*
1194 * XXX Rewrite this code to maintain a list of enabled
1195 * downstream clocks for debugging purposes?
1196 */
1197
Benoit Cousson113a7412011-07-10 05:56:54 -06001198 if (!clk)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001199 return -EINVAL;
1200
Benoit Cousson113a7412011-07-10 05:56:54 -06001201 return _clkdm_clk_hwmod_enable(clkdm);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001202}
1203
1204/**
Rajendra Nayak4da71ae2011-02-25 16:06:48 -07001205 * clkdm_clk_disable - remove an enabled downstream clock from this clkdm
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001206 * @clkdm: struct clockdomain *
1207 * @clk: struct clk * of the disabled downstream clock
1208 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -07001209 * Decrement the usecount of this clockdomain @clkdm when @clk is
1210 * disabled. Intended to be called by clk_disable() code. If the
1211 * clockdomain usecount goes to 0, put the clockdomain to sleep
1212 * (software-supervised mode) or remove the clkdm autodependencies
1213 * (hardware-supervised mode). Returns -EINVAL if passed null
Benoit Cousson113a7412011-07-10 05:56:54 -06001214 * pointers; -ERANGE if the @clkdm usecount underflows; or returns 0
1215 * upon success or if the clockdomain is in hwsup idle mode.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001216 */
Rajendra Nayak4da71ae2011-02-25 16:06:48 -07001217int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001218{
Mike Turquetted043d872012-11-09 11:28:42 -07001219 if (!clkdm || !clk || !arch_clkdm || !arch_clkdm->clkdm_clk_disable)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001220 return -EINVAL;
1221
Paul Walmsley3a090282013-01-26 00:58:16 -07001222 pwrdm_lock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001223
Mike Turquetted043d872012-11-09 11:28:42 -07001224 /* corner case: disabling unused clocks */
Paul Walmsley92493872013-01-26 00:58:17 -07001225 if ((__clk_get_enable_count(clk) == 0) && clkdm->usecount == 0)
Mike Turquetted043d872012-11-09 11:28:42 -07001226 goto ccd_exit;
Mike Turquetted043d872012-11-09 11:28:42 -07001227
Paul Walmsley92493872013-01-26 00:58:17 -07001228 if (clkdm->usecount == 0) {
Paul Walmsley3a090282013-01-26 00:58:16 -07001229 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001230 WARN_ON(1); /* underflow */
1231 return -ERANGE;
1232 }
1233
Paul Walmsley92493872013-01-26 00:58:17 -07001234 clkdm->usecount--;
1235 if (clkdm->usecount > 0) {
Paul Walmsley3a090282013-01-26 00:58:16 -07001236 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001237 return 0;
1238 }
1239
1240 arch_clkdm->clkdm_clk_disable(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -07001241 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001242
1243 pr_debug("clockdomain: %s: disabled\n", clkdm->name);
1244
Mike Turquetted043d872012-11-09 11:28:42 -07001245ccd_exit:
Paul Walmsley3a090282013-01-26 00:58:16 -07001246 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001247
1248 return 0;
Benoit Cousson113a7412011-07-10 05:56:54 -06001249}
Rajendra Nayak4da71ae2011-02-25 16:06:48 -07001250
Benoit Cousson113a7412011-07-10 05:56:54 -06001251/**
1252 * clkdm_hwmod_enable - add an enabled downstream hwmod to this clkdm
1253 * @clkdm: struct clockdomain *
1254 * @oh: struct omap_hwmod * of the enabled downstream hwmod
1255 *
1256 * Increment the usecount of the clockdomain @clkdm and ensure that it
1257 * is awake before @oh is enabled. Intended to be called by
1258 * module_enable() code.
1259 * If the clockdomain is in software-supervised idle mode, force the
1260 * clockdomain to wake. If the clockdomain is in hardware-supervised idle
1261 * mode, add clkdm-pwrdm autodependencies, to ensure that devices in the
1262 * clockdomain can be read from/written to by on-chip processors.
1263 * Returns -EINVAL if passed null pointers;
1264 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
1265 */
1266int clkdm_hwmod_enable(struct clockdomain *clkdm, struct omap_hwmod *oh)
1267{
1268 /* The clkdm attribute does not exist yet prior OMAP4 */
1269 if (cpu_is_omap24xx() || cpu_is_omap34xx())
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001270 return 0;
1271
Benoit Cousson113a7412011-07-10 05:56:54 -06001272 /*
1273 * XXX Rewrite this code to maintain a list of enabled
1274 * downstream hwmods for debugging purposes?
1275 */
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001276
Benoit Cousson113a7412011-07-10 05:56:54 -06001277 if (!oh)
1278 return -EINVAL;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001279
Benoit Cousson113a7412011-07-10 05:56:54 -06001280 return _clkdm_clk_hwmod_enable(clkdm);
1281}
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +03001282
Benoit Cousson113a7412011-07-10 05:56:54 -06001283/**
1284 * clkdm_hwmod_disable - remove an enabled downstream hwmod from this clkdm
1285 * @clkdm: struct clockdomain *
1286 * @oh: struct omap_hwmod * of the disabled downstream hwmod
1287 *
1288 * Decrement the usecount of this clockdomain @clkdm when @oh is
1289 * disabled. Intended to be called by module_disable() code.
1290 * If the clockdomain usecount goes to 0, put the clockdomain to sleep
1291 * (software-supervised mode) or remove the clkdm autodependencies
1292 * (hardware-supervised mode).
1293 * Returns -EINVAL if passed null pointers; -ERANGE if the @clkdm usecount
1294 * underflows; or returns 0 upon success or if the clockdomain is in hwsup
1295 * idle mode.
1296 */
1297int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh)
1298{
1299 /* The clkdm attribute does not exist yet prior OMAP4 */
1300 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1301 return 0;
1302
1303 /*
1304 * XXX Rewrite this code to maintain a list of enabled
1305 * downstream hwmods for debugging purposes?
1306 */
1307
Mike Turquetted043d872012-11-09 11:28:42 -07001308 if (!clkdm || !oh || !arch_clkdm || !arch_clkdm->clkdm_clk_disable)
Benoit Cousson113a7412011-07-10 05:56:54 -06001309 return -EINVAL;
1310
Paul Walmsley3a090282013-01-26 00:58:16 -07001311 pwrdm_lock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001312
Paul Walmsley92493872013-01-26 00:58:17 -07001313 if (clkdm->usecount == 0) {
Paul Walmsley3a090282013-01-26 00:58:16 -07001314 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001315 WARN_ON(1); /* underflow */
1316 return -ERANGE;
1317 }
1318
Paul Walmsley92493872013-01-26 00:58:17 -07001319 clkdm->usecount--;
1320 if (clkdm->usecount > 0) {
Paul Walmsley3a090282013-01-26 00:58:16 -07001321 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001322 return 0;
1323 }
1324
1325 arch_clkdm->clkdm_clk_disable(clkdm);
Paul Walmsley3a090282013-01-26 00:58:16 -07001326 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
1327 pwrdm_unlock(clkdm->pwrdm.ptr);
Mike Turquetted043d872012-11-09 11:28:42 -07001328
1329 pr_debug("clockdomain: %s: disabled\n", clkdm->name);
1330
1331 return 0;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001332}
1333
Russ Dill1096d1c2018-05-16 20:46:58 +05301334/**
1335 * _clkdm_save_context - save the context for the control of this clkdm
1336 *
1337 * Due to a suspend or hibernation operation, the state of the registers
1338 * controlling this clkdm will be lost, save their context.
1339 */
1340static int _clkdm_save_context(struct clockdomain *clkdm, void *ununsed)
1341{
1342 if (!arch_clkdm || !arch_clkdm->clkdm_save_context)
1343 return -EINVAL;
1344
1345 return arch_clkdm->clkdm_save_context(clkdm);
1346}
1347
1348/**
1349 * _clkdm_restore_context - restore context for control of this clkdm
1350 *
1351 * Restore the register values for this clockdomain.
1352 */
1353static int _clkdm_restore_context(struct clockdomain *clkdm, void *ununsed)
1354{
1355 if (!arch_clkdm || !arch_clkdm->clkdm_restore_context)
1356 return -EINVAL;
1357
1358 return arch_clkdm->clkdm_restore_context(clkdm);
1359}
1360
1361/**
1362 * clkdm_save_context - Saves the context for each registered clkdm
1363 *
1364 * Save the context for each registered clockdomain.
1365 */
1366void clkdm_save_context(void)
1367{
1368 clkdm_for_each(_clkdm_save_context, NULL);
1369}
1370
1371/**
1372 * clkdm_restore_context - Restores the context for each registered clkdm
1373 *
1374 * Restore the context for each registered clockdomain.
1375 */
1376void clkdm_restore_context(void)
1377{
1378 clkdm_for_each(_clkdm_restore_context, NULL);
1379}