Merge branch 'ttm-fixes-3.13' of git://people.freedesktop.org/~thomash/linux into...
[deliverable/linux.git] / arch / arm / mach-omap2 / powerdomain.c
CommitLineData
ad67ef68
PW
1/*
2 * OMAP powerdomain control
3 *
129c65ee 4 * Copyright (C) 2007-2008, 2011 Texas Instruments, Inc.
694606c4 5 * Copyright (C) 2007-2011 Nokia Corporation
ad67ef68
PW
6 *
7 * Written by Paul Walmsley
3a759f09 8 * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
4788da26 9 * State counting code by Tero Kristo <tero.kristo@nokia.com>
3a759f09 10 *
ad67ef68
PW
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
33903eb5 15#undef DEBUG
ad67ef68
PW
16
17#include <linux/kernel.h>
ad67ef68 18#include <linux/types.h>
ad67ef68
PW
19#include <linux/list.h>
20#include <linux/errno.h>
9b7fc907 21#include <linux/string.h>
3a090284 22#include <linux/spinlock.h>
5e7c58dc
JP
23#include <trace/events/power.h>
24
59fb659b 25#include "cm2xxx_3xxx.h"
a64bb9cd 26#include "prcm44xx.h"
59fb659b
PW
27#include "cm44xx.h"
28#include "prm2xxx_3xxx.h"
d198b514 29#include "prm44xx.h"
ad67ef68 30
5e7c58dc 31#include <asm/cpu.h>
dbc04161 32
72e06d08 33#include "powerdomain.h"
1540f214 34#include "clockdomain.h"
ad67ef68 35
dbc04161 36#include "soc.h"
6199ab26
PDS
37#include "pm.h"
38
5e7c58dc
JP
39#define PWRDM_TRACE_STATES_FLAG (1<<31)
40
ba20bb12
PDS
41enum {
42 PWRDM_STATE_NOW = 0,
43 PWRDM_STATE_PREV,
44};
45
c4978fba
PW
46/*
47 * Types of sleep_switch used internally in omap_set_pwrdm_state()
48 * and its associated static functions
49 *
50 * XXX Better documentation is needed here
51 */
52#define ALREADYACTIVE_SWITCH 0
53#define FORCEWAKEUP_SWITCH 1
54#define LOWPOWERSTATE_SWITCH 2
3a759f09 55
ad67ef68
PW
56/* pwrdm_list contains all registered struct powerdomains */
57static LIST_HEAD(pwrdm_list);
58
3b1e8b21
RN
59static struct pwrdm_ops *arch_pwrdm;
60
ad67ef68
PW
61/* Private functions */
62
ad67ef68
PW
63static struct powerdomain *_pwrdm_lookup(const char *name)
64{
65 struct powerdomain *pwrdm, *temp_pwrdm;
66
67 pwrdm = NULL;
68
69 list_for_each_entry(temp_pwrdm, &pwrdm_list, node) {
70 if (!strcmp(name, temp_pwrdm->name)) {
71 pwrdm = temp_pwrdm;
72 break;
73 }
74 }
75
76 return pwrdm;
77}
78
e909d62a
PW
79/**
80 * _pwrdm_register - register a powerdomain
81 * @pwrdm: struct powerdomain * to register
82 *
83 * Adds a powerdomain to the internal powerdomain list. Returns
84 * -EINVAL if given a null pointer, -EEXIST if a powerdomain is
85 * already registered by the provided name, or 0 upon success.
86 */
87static int _pwrdm_register(struct powerdomain *pwrdm)
88{
89 int i;
048a7034 90 struct voltagedomain *voltdm;
e909d62a 91
a64bb9cd 92 if (!pwrdm || !pwrdm->name)
e909d62a
PW
93 return -EINVAL;
94
a64bb9cd
PW
95 if (cpu_is_omap44xx() &&
96 pwrdm->prcm_partition == OMAP4430_INVALID_PRCM_PARTITION) {
97 pr_err("powerdomain: %s: missing OMAP4 PRCM partition ID\n",
98 pwrdm->name);
99 return -EINVAL;
100 }
101
e909d62a
PW
102 if (_pwrdm_lookup(pwrdm->name))
103 return -EEXIST;
104
cd8abed1
RN
105 if (arch_pwrdm && arch_pwrdm->pwrdm_has_voltdm)
106 if (!arch_pwrdm->pwrdm_has_voltdm())
107 goto skip_voltdm;
108
048a7034
KH
109 voltdm = voltdm_lookup(pwrdm->voltdm.name);
110 if (!voltdm) {
111 pr_err("powerdomain: %s: voltagedomain %s does not exist\n",
112 pwrdm->name, pwrdm->voltdm.name);
113 return -EINVAL;
114 }
115 pwrdm->voltdm.ptr = voltdm;
e69c22b1
KH
116 INIT_LIST_HEAD(&pwrdm->voltdm_node);
117 voltdm_add_pwrdm(voltdm, pwrdm);
cd8abed1 118skip_voltdm:
3a090284 119 spin_lock_init(&pwrdm->_lock);
048a7034 120
e909d62a
PW
121 list_add(&pwrdm->node, &pwrdm_list);
122
123 /* Initialize the powerdomain's state counter */
cf57aa7c 124 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
e909d62a
PW
125 pwrdm->state_counter[i] = 0;
126
cde08f81
TG
127 pwrdm->ret_logic_off_counter = 0;
128 for (i = 0; i < pwrdm->banks; i++)
129 pwrdm->ret_mem_off_counter[i] = 0;
130
f8457c2d 131 arch_pwrdm->pwrdm_wait_transition(pwrdm);
e909d62a
PW
132 pwrdm->state = pwrdm_read_pwrst(pwrdm);
133 pwrdm->state_counter[pwrdm->state] = 1;
134
135 pr_debug("powerdomain: registered %s\n", pwrdm->name);
136
137 return 0;
138}
139
cde08f81
TG
140static void _update_logic_membank_counters(struct powerdomain *pwrdm)
141{
142 int i;
143 u8 prev_logic_pwrst, prev_mem_pwrst;
144
145 prev_logic_pwrst = pwrdm_read_prev_logic_pwrst(pwrdm);
146 if ((pwrdm->pwrsts_logic_ret == PWRSTS_OFF_RET) &&
147 (prev_logic_pwrst == PWRDM_POWER_OFF))
148 pwrdm->ret_logic_off_counter++;
149
150 for (i = 0; i < pwrdm->banks; i++) {
151 prev_mem_pwrst = pwrdm_read_prev_mem_pwrst(pwrdm, i);
152
153 if ((pwrdm->pwrsts_mem_ret[i] == PWRSTS_OFF_RET) &&
154 (prev_mem_pwrst == PWRDM_POWER_OFF))
155 pwrdm->ret_mem_off_counter[i]++;
156 }
157}
158
ba20bb12
PDS
159static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)
160{
161
c165a140 162 int prev, next, state, trace_state = 0;
ba20bb12
PDS
163
164 if (pwrdm == NULL)
165 return -EINVAL;
166
167 state = pwrdm_read_pwrst(pwrdm);
168
169 switch (flag) {
170 case PWRDM_STATE_NOW:
171 prev = pwrdm->state;
172 break;
173 case PWRDM_STATE_PREV:
174 prev = pwrdm_read_prev_pwrst(pwrdm);
175 if (pwrdm->state != prev)
176 pwrdm->state_counter[prev]++;
cde08f81
TG
177 if (prev == PWRDM_POWER_RET)
178 _update_logic_membank_counters(pwrdm);
5e7c58dc
JP
179 /*
180 * If the power domain did not hit the desired state,
181 * generate a trace event with both the desired and hit states
182 */
c165a140
JP
183 next = pwrdm_read_next_pwrst(pwrdm);
184 if (next != prev) {
5e7c58dc 185 trace_state = (PWRDM_TRACE_STATES_FLAG |
c165a140 186 ((next & OMAP_POWERSTATE_MASK) << 8) |
5e7c58dc
JP
187 ((prev & OMAP_POWERSTATE_MASK) << 0));
188 trace_power_domain_target(pwrdm->name, trace_state,
189 smp_processor_id());
190 }
ba20bb12
PDS
191 break;
192 default:
193 return -EINVAL;
194 }
195
196 if (state != prev)
197 pwrdm->state_counter[state]++;
198
6199ab26
PDS
199 pm_dbg_update_time(pwrdm, prev);
200
ba20bb12
PDS
201 pwrdm->state = state;
202
203 return 0;
204}
205
6199ab26 206static int _pwrdm_pre_transition_cb(struct powerdomain *pwrdm, void *unused)
ba20bb12
PDS
207{
208 pwrdm_clear_all_prev_pwrst(pwrdm);
209 _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
210 return 0;
211}
212
6199ab26 213static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused)
ba20bb12
PDS
214{
215 _pwrdm_state_switch(pwrdm, PWRDM_STATE_PREV);
216 return 0;
217}
218
c4978fba
PW
219/**
220 * _pwrdm_save_clkdm_state_and_activate - prepare for power state change
221 * @pwrdm: struct powerdomain * to operate on
222 * @curr_pwrst: current power state of @pwrdm
223 * @pwrst: power state to switch to
224 * @hwsup: ptr to a bool to return whether the clkdm is hardware-supervised
225 *
226 * Determine whether the powerdomain needs to be turned on before
227 * attempting to switch power states. Called by
228 * omap_set_pwrdm_state(). NOTE that if the powerdomain contains
229 * multiple clockdomains, this code assumes that the first clockdomain
230 * supports software-supervised wakeup mode - potentially a problem.
231 * Returns the power state switch mode currently in use (see the
232 * "Types of sleep_switch" comment above).
233 */
234static u8 _pwrdm_save_clkdm_state_and_activate(struct powerdomain *pwrdm,
235 u8 curr_pwrst, u8 pwrst,
236 bool *hwsup)
237{
238 u8 sleep_switch;
239
bd70f6eb 240 if (curr_pwrst < PWRDM_POWER_ON) {
c4978fba
PW
241 if (curr_pwrst > pwrst &&
242 pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE &&
243 arch_pwrdm->pwrdm_set_lowpwrstchange) {
244 sleep_switch = LOWPOWERSTATE_SWITCH;
245 } else {
246 *hwsup = clkdm_in_hwsup(pwrdm->pwrdm_clkdms[0]);
3a090284 247 clkdm_wakeup_nolock(pwrdm->pwrdm_clkdms[0]);
c4978fba
PW
248 sleep_switch = FORCEWAKEUP_SWITCH;
249 }
250 } else {
251 sleep_switch = ALREADYACTIVE_SWITCH;
252 }
253
254 return sleep_switch;
255}
256
257/**
258 * _pwrdm_restore_clkdm_state - restore the clkdm hwsup state after pwrst change
259 * @pwrdm: struct powerdomain * to operate on
260 * @sleep_switch: return value from _pwrdm_save_clkdm_state_and_activate()
261 * @hwsup: should @pwrdm's first clockdomain be set to hardware-supervised mode?
262 *
263 * Restore the clockdomain state perturbed by
264 * _pwrdm_save_clkdm_state_and_activate(), and call the power state
265 * bookkeeping code. Called by omap_set_pwrdm_state(). NOTE that if
266 * the powerdomain contains multiple clockdomains, this assumes that
267 * the first associated clockdomain supports either
268 * hardware-supervised idle control in the register, or
269 * software-supervised sleep. No return value.
270 */
271static void _pwrdm_restore_clkdm_state(struct powerdomain *pwrdm,
272 u8 sleep_switch, bool hwsup)
273{
274 switch (sleep_switch) {
275 case FORCEWAKEUP_SWITCH:
276 if (hwsup)
3a090284 277 clkdm_allow_idle_nolock(pwrdm->pwrdm_clkdms[0]);
c4978fba 278 else
3a090284 279 clkdm_sleep_nolock(pwrdm->pwrdm_clkdms[0]);
c4978fba
PW
280 break;
281 case LOWPOWERSTATE_SWITCH:
282 if (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE &&
283 arch_pwrdm->pwrdm_set_lowpwrstchange)
284 arch_pwrdm->pwrdm_set_lowpwrstchange(pwrdm);
3a090284 285 pwrdm_state_switch_nolock(pwrdm);
c4978fba
PW
286 break;
287 }
288}
289
ad67ef68
PW
290/* Public functions */
291
292/**
129c65ee
PW
293 * pwrdm_register_platform_funcs - register powerdomain implementation fns
294 * @po: func pointers for arch specific implementations
ad67ef68 295 *
129c65ee
PW
296 * Register the list of function pointers used to implement the
297 * powerdomain functions on different OMAP SoCs. Should be called
298 * before any other pwrdm_register*() function. Returns -EINVAL if
299 * @po is null, -EEXIST if platform functions have already been
300 * registered, or 0 upon success.
ad67ef68 301 */
129c65ee
PW
302int pwrdm_register_platform_funcs(struct pwrdm_ops *po)
303{
304 if (!po)
305 return -EINVAL;
306
307 if (arch_pwrdm)
308 return -EEXIST;
309
310 arch_pwrdm = po;
311
312 return 0;
313}
314
315/**
316 * pwrdm_register_pwrdms - register SoC powerdomains
317 * @ps: pointer to an array of struct powerdomain to register
318 *
319 * Register the powerdomains available on a particular OMAP SoC. Must
320 * be called after pwrdm_register_platform_funcs(). May be called
321 * multiple times. Returns -EACCES if called before
322 * pwrdm_register_platform_funcs(); -EINVAL if the argument @ps is
323 * null; or 0 upon success.
324 */
325int pwrdm_register_pwrdms(struct powerdomain **ps)
ad67ef68
PW
326{
327 struct powerdomain **p = NULL;
328
129c65ee
PW
329 if (!arch_pwrdm)
330 return -EEXIST;
3b1e8b21 331
129c65ee
PW
332 if (!ps)
333 return -EINVAL;
334
335 for (p = ps; *p; p++)
336 _pwrdm_register(*p);
337
338 return 0;
339}
340
341/**
342 * pwrdm_complete_init - set up the powerdomain layer
343 *
344 * Do whatever is necessary to initialize registered powerdomains and
345 * powerdomain code. Currently, this programs the next power state
346 * for each powerdomain to ON. This prevents powerdomains from
347 * unexpectedly losing context or entering high wakeup latency modes
348 * with non-power-management-enabled kernels. Must be called after
349 * pwrdm_register_pwrdms(). Returns -EACCES if called before
350 * pwrdm_register_pwrdms(), or 0 upon success.
351 */
352int pwrdm_complete_init(void)
353{
354 struct powerdomain *temp_p;
355
356 if (list_empty(&pwrdm_list))
357 return -EACCES;
c956b753
RN
358
359 list_for_each_entry(temp_p, &pwrdm_list, node)
360 pwrdm_set_next_pwrst(temp_p, PWRDM_POWER_ON);
129c65ee
PW
361
362 return 0;
ad67ef68
PW
363}
364
3a090284
PW
365/**
366 * pwrdm_lock - acquire a Linux spinlock on a powerdomain
367 * @pwrdm: struct powerdomain * to lock
368 *
369 * Acquire the powerdomain spinlock on @pwrdm. No return value.
370 */
371void pwrdm_lock(struct powerdomain *pwrdm)
372 __acquires(&pwrdm->_lock)
373{
374 spin_lock_irqsave(&pwrdm->_lock, pwrdm->_lock_flags);
375}
376
377/**
378 * pwrdm_unlock - release a Linux spinlock on a powerdomain
379 * @pwrdm: struct powerdomain * to unlock
380 *
381 * Release the powerdomain spinlock on @pwrdm. No return value.
382 */
383void pwrdm_unlock(struct powerdomain *pwrdm)
384 __releases(&pwrdm->_lock)
385{
386 spin_unlock_irqrestore(&pwrdm->_lock, pwrdm->_lock_flags);
387}
388
ad67ef68
PW
389/**
390 * pwrdm_lookup - look up a powerdomain by name, return a pointer
391 * @name: name of powerdomain
392 *
f0271d65
PW
393 * Find a registered powerdomain by its name @name. Returns a pointer
394 * to the struct powerdomain if found, or NULL otherwise.
ad67ef68
PW
395 */
396struct powerdomain *pwrdm_lookup(const char *name)
397{
398 struct powerdomain *pwrdm;
ad67ef68
PW
399
400 if (!name)
401 return NULL;
402
ad67ef68 403 pwrdm = _pwrdm_lookup(name);
ad67ef68
PW
404
405 return pwrdm;
406}
407
408/**
e909d62a 409 * pwrdm_for_each - call function on each registered clockdomain
ad67ef68
PW
410 * @fn: callback function *
411 *
f0271d65
PW
412 * Call the supplied function @fn for each registered powerdomain.
413 * The callback function @fn can return anything but 0 to bail out
414 * early from the iterator. Returns the last return value of the
415 * callback function, which should be 0 for success or anything else
416 * to indicate failure; or -EINVAL if the function pointer is null.
ad67ef68 417 */
e909d62a
PW
418int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user),
419 void *user)
ad67ef68
PW
420{
421 struct powerdomain *temp_pwrdm;
ad67ef68
PW
422 int ret = 0;
423
424 if (!fn)
425 return -EINVAL;
426
ad67ef68 427 list_for_each_entry(temp_pwrdm, &pwrdm_list, node) {
6199ab26 428 ret = (*fn)(temp_pwrdm, user);
ad67ef68
PW
429 if (ret)
430 break;
431 }
ee894b18
AB
432
433 return ret;
434}
435
8420bb13
PW
436/**
437 * pwrdm_add_clkdm - add a clockdomain to a powerdomain
438 * @pwrdm: struct powerdomain * to add the clockdomain to
439 * @clkdm: struct clockdomain * to associate with a powerdomain
440 *
f0271d65 441 * Associate the clockdomain @clkdm with a powerdomain @pwrdm. This
8420bb13
PW
442 * enables the use of pwrdm_for_each_clkdm(). Returns -EINVAL if
443 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
444 * or 0 upon success.
445 */
446int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
447{
8420bb13
PW
448 int i;
449 int ret = -EINVAL;
450
451 if (!pwrdm || !clkdm)
452 return -EINVAL;
453
7852ec05
PW
454 pr_debug("powerdomain: %s: associating clockdomain %s\n",
455 pwrdm->name, clkdm->name);
8420bb13 456
8420bb13
PW
457 for (i = 0; i < PWRDM_MAX_CLKDMS; i++) {
458 if (!pwrdm->pwrdm_clkdms[i])
459 break;
460#ifdef DEBUG
461 if (pwrdm->pwrdm_clkdms[i] == clkdm) {
462 ret = -EINVAL;
463 goto pac_exit;
464 }
465#endif
466 }
467
468 if (i == PWRDM_MAX_CLKDMS) {
7852ec05
PW
469 pr_debug("powerdomain: %s: increase PWRDM_MAX_CLKDMS for clkdm %s\n",
470 pwrdm->name, clkdm->name);
8420bb13
PW
471 WARN_ON(1);
472 ret = -ENOMEM;
473 goto pac_exit;
474 }
475
476 pwrdm->pwrdm_clkdms[i] = clkdm;
477
478 ret = 0;
479
480pac_exit:
8420bb13
PW
481 return ret;
482}
483
484/**
485 * pwrdm_del_clkdm - remove a clockdomain from a powerdomain
486 * @pwrdm: struct powerdomain * to add the clockdomain to
487 * @clkdm: struct clockdomain * to associate with a powerdomain
488 *
f0271d65
PW
489 * Dissociate the clockdomain @clkdm from the powerdomain
490 * @pwrdm. Returns -EINVAL if presented with invalid pointers; -ENOENT
491 * if @clkdm was not associated with the powerdomain, or 0 upon
492 * success.
8420bb13
PW
493 */
494int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
495{
8420bb13
PW
496 int ret = -EINVAL;
497 int i;
498
499 if (!pwrdm || !clkdm)
500 return -EINVAL;
501
7852ec05
PW
502 pr_debug("powerdomain: %s: dissociating clockdomain %s\n",
503 pwrdm->name, clkdm->name);
8420bb13 504
8420bb13
PW
505 for (i = 0; i < PWRDM_MAX_CLKDMS; i++)
506 if (pwrdm->pwrdm_clkdms[i] == clkdm)
507 break;
508
509 if (i == PWRDM_MAX_CLKDMS) {
7852ec05
PW
510 pr_debug("powerdomain: %s: clkdm %s not associated?!\n",
511 pwrdm->name, clkdm->name);
8420bb13
PW
512 ret = -ENOENT;
513 goto pdc_exit;
514 }
515
516 pwrdm->pwrdm_clkdms[i] = NULL;
517
518 ret = 0;
519
520pdc_exit:
8420bb13
PW
521 return ret;
522}
523
524/**
525 * pwrdm_for_each_clkdm - call function on each clkdm in a pwrdm
526 * @pwrdm: struct powerdomain * to iterate over
527 * @fn: callback function *
528 *
f0271d65
PW
529 * Call the supplied function @fn for each clockdomain in the powerdomain
530 * @pwrdm. The callback function can return anything but 0 to bail
e909d62a
PW
531 * out early from the iterator. Returns -EINVAL if presented with
532 * invalid pointers; or passes along the last return value of the
533 * callback function, which should be 0 for success or anything else
534 * to indicate failure.
8420bb13
PW
535 */
536int pwrdm_for_each_clkdm(struct powerdomain *pwrdm,
537 int (*fn)(struct powerdomain *pwrdm,
538 struct clockdomain *clkdm))
539{
8420bb13
PW
540 int ret = 0;
541 int i;
542
543 if (!fn)
544 return -EINVAL;
545
8420bb13
PW
546 for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++)
547 ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]);
548
8420bb13
PW
549 return ret;
550}
551
048a7034
KH
552/**
553 * pwrdm_get_voltdm - return a ptr to the voltdm that this pwrdm resides in
554 * @pwrdm: struct powerdomain *
555 *
556 * Return a pointer to the struct voltageomain that the specified powerdomain
557 * @pwrdm exists in.
558 */
559struct voltagedomain *pwrdm_get_voltdm(struct powerdomain *pwrdm)
560{
561 return pwrdm->voltdm.ptr;
562}
563
ad67ef68
PW
564/**
565 * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain
566 * @pwrdm: struct powerdomain *
567 *
f0271d65 568 * Return the number of controllable memory banks in powerdomain @pwrdm,
ad67ef68
PW
569 * starting with 1. Returns -EINVAL if the powerdomain pointer is null.
570 */
571int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm)
572{
573 if (!pwrdm)
574 return -EINVAL;
575
576 return pwrdm->banks;
577}
578
579/**
580 * pwrdm_set_next_pwrst - set next powerdomain power state
581 * @pwrdm: struct powerdomain * to set
582 * @pwrst: one of the PWRDM_POWER_* macros
583 *
f0271d65 584 * Set the powerdomain @pwrdm's next power state to @pwrst. The powerdomain
ad67ef68
PW
585 * may not enter this state immediately if the preconditions for this state
586 * have not been satisfied. Returns -EINVAL if the powerdomain pointer is
587 * null or if the power state is invalid for the powerdomin, or returns 0
588 * upon success.
589 */
590int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
591{
f327e07b
RN
592 int ret = -EINVAL;
593
ad67ef68
PW
594 if (!pwrdm)
595 return -EINVAL;
596
597 if (!(pwrdm->pwrsts & (1 << pwrst)))
598 return -EINVAL;
599
7852ec05 600 pr_debug("powerdomain: %s: setting next powerstate to %0x\n",
ad67ef68
PW
601 pwrdm->name, pwrst);
602
5e7c58dc
JP
603 if (arch_pwrdm && arch_pwrdm->pwrdm_set_next_pwrst) {
604 /* Trace the pwrdm desired target state */
605 trace_power_domain_target(pwrdm->name, pwrst,
606 smp_processor_id());
607 /* Program the pwrdm desired target state */
f327e07b 608 ret = arch_pwrdm->pwrdm_set_next_pwrst(pwrdm, pwrst);
5e7c58dc 609 }
ad67ef68 610
f327e07b 611 return ret;
ad67ef68
PW
612}
613
614/**
615 * pwrdm_read_next_pwrst - get next powerdomain power state
616 * @pwrdm: struct powerdomain * to get power state
617 *
f0271d65 618 * Return the powerdomain @pwrdm's next power state. Returns -EINVAL
ad67ef68
PW
619 * if the powerdomain pointer is null or returns the next power state
620 * upon success.
621 */
622int pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
623{
f327e07b
RN
624 int ret = -EINVAL;
625
ad67ef68
PW
626 if (!pwrdm)
627 return -EINVAL;
628
f327e07b
RN
629 if (arch_pwrdm && arch_pwrdm->pwrdm_read_next_pwrst)
630 ret = arch_pwrdm->pwrdm_read_next_pwrst(pwrdm);
631
632 return ret;
ad67ef68
PW
633}
634
635/**
636 * pwrdm_read_pwrst - get current powerdomain power state
637 * @pwrdm: struct powerdomain * to get power state
638 *
f0271d65 639 * Return the powerdomain @pwrdm's current power state. Returns -EINVAL
ad67ef68 640 * if the powerdomain pointer is null or returns the current power state
d49cae92
JH
641 * upon success. Note that if the power domain only supports the ON state
642 * then just return ON as the current state.
ad67ef68
PW
643 */
644int pwrdm_read_pwrst(struct powerdomain *pwrdm)
645{
f327e07b
RN
646 int ret = -EINVAL;
647
ad67ef68
PW
648 if (!pwrdm)
649 return -EINVAL;
650
d49cae92
JH
651 if (pwrdm->pwrsts == PWRSTS_ON)
652 return PWRDM_POWER_ON;
653
f327e07b
RN
654 if (arch_pwrdm && arch_pwrdm->pwrdm_read_pwrst)
655 ret = arch_pwrdm->pwrdm_read_pwrst(pwrdm);
656
657 return ret;
ad67ef68
PW
658}
659
660/**
661 * pwrdm_read_prev_pwrst - get previous powerdomain power state
662 * @pwrdm: struct powerdomain * to get previous power state
663 *
f0271d65 664 * Return the powerdomain @pwrdm's previous power state. Returns -EINVAL
ad67ef68
PW
665 * if the powerdomain pointer is null or returns the previous power state
666 * upon success.
667 */
668int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
669{
f327e07b
RN
670 int ret = -EINVAL;
671
ad67ef68
PW
672 if (!pwrdm)
673 return -EINVAL;
674
f327e07b
RN
675 if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_pwrst)
676 ret = arch_pwrdm->pwrdm_read_prev_pwrst(pwrdm);
677
678 return ret;
ad67ef68
PW
679}
680
681/**
682 * pwrdm_set_logic_retst - set powerdomain logic power state upon retention
683 * @pwrdm: struct powerdomain * to set
684 * @pwrst: one of the PWRDM_POWER_* macros
685 *
f0271d65
PW
686 * Set the next power state @pwrst that the logic portion of the
687 * powerdomain @pwrdm will enter when the powerdomain enters retention.
688 * This will be either RETENTION or OFF, if supported. Returns
689 * -EINVAL if the powerdomain pointer is null or the target power
690 * state is not not supported, or returns 0 upon success.
ad67ef68
PW
691 */
692int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
693{
12627578 694 int ret = -EINVAL;
2bc4ef71 695
ad67ef68
PW
696 if (!pwrdm)
697 return -EINVAL;
698
699 if (!(pwrdm->pwrsts_logic_ret & (1 << pwrst)))
700 return -EINVAL;
701
7852ec05 702 pr_debug("powerdomain: %s: setting next logic powerstate to %0x\n",
ad67ef68
PW
703 pwrdm->name, pwrst);
704
12627578
RN
705 if (arch_pwrdm && arch_pwrdm->pwrdm_set_logic_retst)
706 ret = arch_pwrdm->pwrdm_set_logic_retst(pwrdm, pwrst);
ad67ef68 707
12627578 708 return ret;
ad67ef68
PW
709}
710
711/**
712 * pwrdm_set_mem_onst - set memory power state while powerdomain ON
713 * @pwrdm: struct powerdomain * to set
714 * @bank: memory bank number to set (0-3)
715 * @pwrst: one of the PWRDM_POWER_* macros
716 *
f0271d65
PW
717 * Set the next power state @pwrst that memory bank @bank of the
718 * powerdomain @pwrdm will enter when the powerdomain enters the ON
719 * state. @bank will be a number from 0 to 3, and represents different
720 * types of memory, depending on the powerdomain. Returns -EINVAL if
721 * the powerdomain pointer is null or the target power state is not
722 * not supported for this memory bank, -EEXIST if the target memory
723 * bank does not exist or is not controllable, or returns 0 upon
724 * success.
ad67ef68
PW
725 */
726int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst)
727{
9b7fc907 728 int ret = -EINVAL;
ad67ef68
PW
729
730 if (!pwrdm)
731 return -EINVAL;
732
733 if (pwrdm->banks < (bank + 1))
734 return -EEXIST;
735
736 if (!(pwrdm->pwrsts_mem_on[bank] & (1 << pwrst)))
737 return -EINVAL;
738
7852ec05
PW
739 pr_debug("powerdomain: %s: setting next memory powerstate for bank %0x while pwrdm-ON to %0x\n",
740 pwrdm->name, bank, pwrst);
ad67ef68 741
9b7fc907
RN
742 if (arch_pwrdm && arch_pwrdm->pwrdm_set_mem_onst)
743 ret = arch_pwrdm->pwrdm_set_mem_onst(pwrdm, bank, pwrst);
ad67ef68 744
9b7fc907 745 return ret;
ad67ef68
PW
746}
747
748/**
749 * pwrdm_set_mem_retst - set memory power state while powerdomain in RET
750 * @pwrdm: struct powerdomain * to set
751 * @bank: memory bank number to set (0-3)
752 * @pwrst: one of the PWRDM_POWER_* macros
753 *
f0271d65
PW
754 * Set the next power state @pwrst that memory bank @bank of the
755 * powerdomain @pwrdm will enter when the powerdomain enters the
756 * RETENTION state. Bank will be a number from 0 to 3, and represents
757 * different types of memory, depending on the powerdomain. @pwrst
758 * will be either RETENTION or OFF, if supported. Returns -EINVAL if
759 * the powerdomain pointer is null or the target power state is not
760 * not supported for this memory bank, -EEXIST if the target memory
761 * bank does not exist or is not controllable, or returns 0 upon
762 * success.
ad67ef68
PW
763 */
764int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst)
765{
9b7fc907 766 int ret = -EINVAL;
ad67ef68
PW
767
768 if (!pwrdm)
769 return -EINVAL;
770
771 if (pwrdm->banks < (bank + 1))
772 return -EEXIST;
773
774 if (!(pwrdm->pwrsts_mem_ret[bank] & (1 << pwrst)))
775 return -EINVAL;
776
7852ec05
PW
777 pr_debug("powerdomain: %s: setting next memory powerstate for bank %0x while pwrdm-RET to %0x\n",
778 pwrdm->name, bank, pwrst);
ad67ef68 779
9b7fc907
RN
780 if (arch_pwrdm && arch_pwrdm->pwrdm_set_mem_retst)
781 ret = arch_pwrdm->pwrdm_set_mem_retst(pwrdm, bank, pwrst);
ad67ef68 782
9b7fc907 783 return ret;
ad67ef68
PW
784}
785
786/**
787 * pwrdm_read_logic_pwrst - get current powerdomain logic retention power state
788 * @pwrdm: struct powerdomain * to get current logic retention power state
789 *
f0271d65
PW
790 * Return the power state that the logic portion of powerdomain @pwrdm
791 * will enter when the powerdomain enters retention. Returns -EINVAL
792 * if the powerdomain pointer is null or returns the logic retention
793 * power state upon success.
ad67ef68
PW
794 */
795int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
796{
12627578
RN
797 int ret = -EINVAL;
798
ad67ef68
PW
799 if (!pwrdm)
800 return -EINVAL;
801
12627578
RN
802 if (arch_pwrdm && arch_pwrdm->pwrdm_read_logic_pwrst)
803 ret = arch_pwrdm->pwrdm_read_logic_pwrst(pwrdm);
804
805 return ret;
ad67ef68
PW
806}
807
808/**
809 * pwrdm_read_prev_logic_pwrst - get previous powerdomain logic power state
810 * @pwrdm: struct powerdomain * to get previous logic power state
811 *
f0271d65
PW
812 * Return the powerdomain @pwrdm's previous logic power state. Returns
813 * -EINVAL if the powerdomain pointer is null or returns the previous
814 * logic power state upon success.
ad67ef68
PW
815 */
816int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
817{
12627578
RN
818 int ret = -EINVAL;
819
ad67ef68
PW
820 if (!pwrdm)
821 return -EINVAL;
822
12627578
RN
823 if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_logic_pwrst)
824 ret = arch_pwrdm->pwrdm_read_prev_logic_pwrst(pwrdm);
825
826 return ret;
ad67ef68
PW
827}
828
1e3d0d2b
TG
829/**
830 * pwrdm_read_logic_retst - get next powerdomain logic power state
831 * @pwrdm: struct powerdomain * to get next logic power state
832 *
833 * Return the powerdomain pwrdm's logic power state. Returns -EINVAL
834 * if the powerdomain pointer is null or returns the next logic
835 * power state upon success.
836 */
837int pwrdm_read_logic_retst(struct powerdomain *pwrdm)
838{
12627578
RN
839 int ret = -EINVAL;
840
1e3d0d2b
TG
841 if (!pwrdm)
842 return -EINVAL;
843
12627578
RN
844 if (arch_pwrdm && arch_pwrdm->pwrdm_read_logic_retst)
845 ret = arch_pwrdm->pwrdm_read_logic_retst(pwrdm);
846
847 return ret;
1e3d0d2b
TG
848}
849
ad67ef68
PW
850/**
851 * pwrdm_read_mem_pwrst - get current memory bank power state
852 * @pwrdm: struct powerdomain * to get current memory bank power state
853 * @bank: memory bank number (0-3)
854 *
f0271d65
PW
855 * Return the powerdomain @pwrdm's current memory power state for bank
856 * @bank. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
ad67ef68
PW
857 * the target memory bank does not exist or is not controllable, or
858 * returns the current memory power state upon success.
859 */
860int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
861{
9b7fc907 862 int ret = -EINVAL;
ad67ef68
PW
863
864 if (!pwrdm)
9b7fc907 865 return ret;
ad67ef68
PW
866
867 if (pwrdm->banks < (bank + 1))
9b7fc907 868 return ret;
ad67ef68 869
3863c74b
TG
870 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
871 bank = 1;
872
9b7fc907
RN
873 if (arch_pwrdm && arch_pwrdm->pwrdm_read_mem_pwrst)
874 ret = arch_pwrdm->pwrdm_read_mem_pwrst(pwrdm, bank);
ad67ef68 875
9b7fc907 876 return ret;
ad67ef68
PW
877}
878
879/**
880 * pwrdm_read_prev_mem_pwrst - get previous memory bank power state
881 * @pwrdm: struct powerdomain * to get previous memory bank power state
882 * @bank: memory bank number (0-3)
883 *
f0271d65
PW
884 * Return the powerdomain @pwrdm's previous memory power state for
885 * bank @bank. Returns -EINVAL if the powerdomain pointer is null,
886 * -EEXIST if the target memory bank does not exist or is not
887 * controllable, or returns the previous memory power state upon
888 * success.
ad67ef68
PW
889 */
890int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
891{
9b7fc907 892 int ret = -EINVAL;
ad67ef68
PW
893
894 if (!pwrdm)
9b7fc907 895 return ret;
ad67ef68
PW
896
897 if (pwrdm->banks < (bank + 1))
9b7fc907 898 return ret;
ad67ef68 899
3863c74b
TG
900 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
901 bank = 1;
902
9b7fc907
RN
903 if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_mem_pwrst)
904 ret = arch_pwrdm->pwrdm_read_prev_mem_pwrst(pwrdm, bank);
ad67ef68 905
9b7fc907 906 return ret;
ad67ef68
PW
907}
908
1e3d0d2b
TG
909/**
910 * pwrdm_read_mem_retst - get next memory bank power state
911 * @pwrdm: struct powerdomain * to get mext memory bank power state
912 * @bank: memory bank number (0-3)
913 *
914 * Return the powerdomain pwrdm's next memory power state for bank
915 * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
916 * the target memory bank does not exist or is not controllable, or
917 * returns the next memory power state upon success.
918 */
919int pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
920{
9b7fc907 921 int ret = -EINVAL;
1e3d0d2b
TG
922
923 if (!pwrdm)
9b7fc907 924 return ret;
1e3d0d2b
TG
925
926 if (pwrdm->banks < (bank + 1))
9b7fc907 927 return ret;
1e3d0d2b 928
9b7fc907
RN
929 if (arch_pwrdm && arch_pwrdm->pwrdm_read_mem_retst)
930 ret = arch_pwrdm->pwrdm_read_mem_retst(pwrdm, bank);
1e3d0d2b 931
9b7fc907 932 return ret;
1e3d0d2b
TG
933}
934
ad67ef68
PW
935/**
936 * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm
937 * @pwrdm: struct powerdomain * to clear
938 *
f0271d65
PW
939 * Clear the powerdomain's previous power state register @pwrdm.
940 * Clears the entire register, including logic and memory bank
941 * previous power states. Returns -EINVAL if the powerdomain pointer
942 * is null, or returns 0 upon success.
ad67ef68
PW
943 */
944int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
945{
9b7fc907
RN
946 int ret = -EINVAL;
947
ad67ef68 948 if (!pwrdm)
9b7fc907 949 return ret;
ad67ef68
PW
950
951 /*
952 * XXX should get the powerdomain's current state here;
953 * warn & fail if it is not ON.
954 */
955
7852ec05 956 pr_debug("powerdomain: %s: clearing previous power state reg\n",
ad67ef68
PW
957 pwrdm->name);
958
9b7fc907
RN
959 if (arch_pwrdm && arch_pwrdm->pwrdm_clear_all_prev_pwrst)
960 ret = arch_pwrdm->pwrdm_clear_all_prev_pwrst(pwrdm);
ad67ef68 961
9b7fc907 962 return ret;
ad67ef68
PW
963}
964
0b7cbfb5
PW
965/**
966 * pwrdm_enable_hdwr_sar - enable automatic hardware SAR for a pwrdm
967 * @pwrdm: struct powerdomain *
968 *
969 * Enable automatic context save-and-restore upon power state change
f0271d65
PW
970 * for some devices in the powerdomain @pwrdm. Warning: this only
971 * affects a subset of devices in a powerdomain; check the TRM
972 * closely. Returns -EINVAL if the powerdomain pointer is null or if
973 * the powerdomain does not support automatic save-and-restore, or
974 * returns 0 upon success.
0b7cbfb5
PW
975 */
976int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm)
977{
9b7fc907
RN
978 int ret = -EINVAL;
979
0b7cbfb5 980 if (!pwrdm)
9b7fc907 981 return ret;
0b7cbfb5
PW
982
983 if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR))
9b7fc907 984 return ret;
0b7cbfb5 985
7852ec05 986 pr_debug("powerdomain: %s: setting SAVEANDRESTORE bit\n", pwrdm->name);
0b7cbfb5 987
9b7fc907
RN
988 if (arch_pwrdm && arch_pwrdm->pwrdm_enable_hdwr_sar)
989 ret = arch_pwrdm->pwrdm_enable_hdwr_sar(pwrdm);
0b7cbfb5 990
9b7fc907 991 return ret;
0b7cbfb5
PW
992}
993
994/**
995 * pwrdm_disable_hdwr_sar - disable automatic hardware SAR for a pwrdm
996 * @pwrdm: struct powerdomain *
997 *
998 * Disable automatic context save-and-restore upon power state change
f0271d65
PW
999 * for some devices in the powerdomain @pwrdm. Warning: this only
1000 * affects a subset of devices in a powerdomain; check the TRM
1001 * closely. Returns -EINVAL if the powerdomain pointer is null or if
1002 * the powerdomain does not support automatic save-and-restore, or
1003 * returns 0 upon success.
0b7cbfb5
PW
1004 */
1005int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm)
1006{
9b7fc907
RN
1007 int ret = -EINVAL;
1008
0b7cbfb5 1009 if (!pwrdm)
9b7fc907 1010 return ret;
0b7cbfb5
PW
1011
1012 if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR))
9b7fc907 1013 return ret;
0b7cbfb5 1014
7852ec05 1015 pr_debug("powerdomain: %s: clearing SAVEANDRESTORE bit\n", pwrdm->name);
0b7cbfb5 1016
9b7fc907
RN
1017 if (arch_pwrdm && arch_pwrdm->pwrdm_disable_hdwr_sar)
1018 ret = arch_pwrdm->pwrdm_disable_hdwr_sar(pwrdm);
0b7cbfb5 1019
9b7fc907 1020 return ret;
0b7cbfb5
PW
1021}
1022
1023/**
1024 * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR
1025 * @pwrdm: struct powerdomain *
1026 *
f0271d65 1027 * Returns 1 if powerdomain @pwrdm supports hardware save-and-restore
0b7cbfb5
PW
1028 * for some devices, or 0 if it does not.
1029 */
1030bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm)
1031{
1032 return (pwrdm && pwrdm->flags & PWRDM_HAS_HDWR_SAR) ? 1 : 0;
1033}
1034
3a090284 1035int pwrdm_state_switch_nolock(struct powerdomain *pwrdm)
ba20bb12 1036{
8b8c3c78
SS
1037 int ret;
1038
f8457c2d
PW
1039 if (!pwrdm || !arch_pwrdm)
1040 return -EINVAL;
1041
1042 ret = arch_pwrdm->pwrdm_wait_transition(pwrdm);
8b8c3c78
SS
1043 if (!ret)
1044 ret = _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
1045
1046 return ret;
ba20bb12
PDS
1047}
1048
3a090284
PW
1049int __deprecated pwrdm_state_switch(struct powerdomain *pwrdm)
1050{
1051 int ret;
1052
1053 pwrdm_lock(pwrdm);
1054 ret = pwrdm_state_switch_nolock(pwrdm);
1055 pwrdm_unlock(pwrdm);
1056
1057 return ret;
1058}
1059
e0555489 1060int pwrdm_pre_transition(struct powerdomain *pwrdm)
ba20bb12 1061{
e0555489
KH
1062 if (pwrdm)
1063 _pwrdm_pre_transition_cb(pwrdm, NULL);
1064 else
1065 pwrdm_for_each(_pwrdm_pre_transition_cb, NULL);
1066
ba20bb12
PDS
1067 return 0;
1068}
1069
e0555489 1070int pwrdm_post_transition(struct powerdomain *pwrdm)
ba20bb12 1071{
e0555489
KH
1072 if (pwrdm)
1073 _pwrdm_post_transition_cb(pwrdm, NULL);
1074 else
1075 pwrdm_for_each(_pwrdm_post_transition_cb, NULL);
1076
ba20bb12
PDS
1077 return 0;
1078}
7f595674 1079
c4978fba
PW
1080/**
1081 * omap_set_pwrdm_state - change a powerdomain's current power state
1082 * @pwrdm: struct powerdomain * to change the power state of
1083 * @pwrst: power state to change to
1084 *
1085 * Change the current hardware power state of the powerdomain
1086 * represented by @pwrdm to the power state represented by @pwrst.
1087 * Returns -EINVAL if @pwrdm is null or invalid or if the
1088 * powerdomain's current power state could not be read, or returns 0
1089 * upon success or if @pwrdm does not support @pwrst or any
1090 * lower-power state. XXX Should not return 0 if the @pwrdm does not
1091 * support @pwrst or any lower-power state: this should be an error.
1092 */
1093int omap_set_pwrdm_state(struct powerdomain *pwrdm, u8 pwrst)
1094{
bd70f6eb
PW
1095 u8 next_pwrst, sleep_switch;
1096 int curr_pwrst;
c4978fba
PW
1097 int ret = 0;
1098 bool hwsup = false;
1099
1100 if (!pwrdm || IS_ERR(pwrdm))
1101 return -EINVAL;
1102
1103 while (!(pwrdm->pwrsts & (1 << pwrst))) {
1104 if (pwrst == PWRDM_POWER_OFF)
1105 return ret;
1106 pwrst--;
1107 }
1108
3a090284
PW
1109 pwrdm_lock(pwrdm);
1110
c4978fba 1111 curr_pwrst = pwrdm_read_pwrst(pwrdm);
bd70f6eb
PW
1112 if (curr_pwrst < 0) {
1113 ret = -EINVAL;
1114 goto osps_out;
1115 }
1116
c4978fba
PW
1117 next_pwrst = pwrdm_read_next_pwrst(pwrdm);
1118 if (curr_pwrst == pwrst && next_pwrst == pwrst)
3a090284 1119 goto osps_out;
c4978fba
PW
1120
1121 sleep_switch = _pwrdm_save_clkdm_state_and_activate(pwrdm, curr_pwrst,
1122 pwrst, &hwsup);
c4978fba
PW
1123
1124 ret = pwrdm_set_next_pwrst(pwrdm, pwrst);
1125 if (ret)
1126 pr_err("%s: unable to set power state of powerdomain: %s\n",
1127 __func__, pwrdm->name);
1128
1129 _pwrdm_restore_clkdm_state(pwrdm, sleep_switch, hwsup);
1130
3a090284
PW
1131osps_out:
1132 pwrdm_unlock(pwrdm);
1133
c4978fba
PW
1134 return ret;
1135}
1136
7f595674
KH
1137/**
1138 * pwrdm_get_context_loss_count - get powerdomain's context loss count
1139 * @pwrdm: struct powerdomain * to wait for
1140 *
1141 * Context loss count is the sum of powerdomain off-mode counter, the
fc013873 1142 * logic off counter and the per-bank memory off counter. Returns negative
7f595674
KH
1143 * (and WARNs) upon error, otherwise, returns the context loss count.
1144 */
fc013873 1145int pwrdm_get_context_loss_count(struct powerdomain *pwrdm)
7f595674
KH
1146{
1147 int i, count;
1148
1149 if (!pwrdm) {
1150 WARN(1, "powerdomain: %s: pwrdm is null\n", __func__);
fc013873 1151 return -ENODEV;
7f595674
KH
1152 }
1153
1154 count = pwrdm->state_counter[PWRDM_POWER_OFF];
1155 count += pwrdm->ret_logic_off_counter;
1156
1157 for (i = 0; i < pwrdm->banks; i++)
1158 count += pwrdm->ret_mem_off_counter[i];
1159
fc013873
TV
1160 /*
1161 * Context loss count has to be a non-negative value. Clear the sign
1162 * bit to get a value range from 0 to INT_MAX.
1163 */
1164 count &= INT_MAX;
1165
1166 pr_debug("powerdomain: %s: context loss count = %d\n",
7f595674
KH
1167 pwrdm->name, count);
1168
1169 return count;
1170}
694606c4
PW
1171
1172/**
1173 * pwrdm_can_ever_lose_context - can this powerdomain ever lose context?
1174 * @pwrdm: struct powerdomain *
1175 *
1176 * Given a struct powerdomain * @pwrdm, returns 1 if the powerdomain
1177 * can lose either memory or logic context or if @pwrdm is invalid, or
1178 * returns 0 otherwise. This function is not concerned with how the
1179 * powerdomain registers are programmed (i.e., to go off or not); it's
1180 * concerned with whether it's ever possible for this powerdomain to
1181 * go off while some other part of the chip is active. This function
1182 * assumes that every powerdomain can go to either ON or INACTIVE.
1183 */
1184bool pwrdm_can_ever_lose_context(struct powerdomain *pwrdm)
1185{
1186 int i;
1187
62f0f39b 1188 if (!pwrdm) {
694606c4
PW
1189 pr_debug("powerdomain: %s: invalid powerdomain pointer\n",
1190 __func__);
1191 return 1;
1192 }
1193
1194 if (pwrdm->pwrsts & PWRSTS_OFF)
1195 return 1;
1196
1197 if (pwrdm->pwrsts & PWRSTS_RET) {
1198 if (pwrdm->pwrsts_logic_ret & PWRSTS_OFF)
1199 return 1;
1200
1201 for (i = 0; i < pwrdm->banks; i++)
1202 if (pwrdm->pwrsts_mem_ret[i] & PWRSTS_OFF)
1203 return 1;
1204 }
1205
1206 for (i = 0; i < pwrdm->banks; i++)
1207 if (pwrdm->pwrsts_mem_on[i] & PWRSTS_OFF)
1208 return 1;
1209
1210 return 0;
1211}
This page took 0.352695 seconds and 5 git commands to generate.