2 * OMAP powerdomain control
4 * Copyright (C) 2007-2008 Texas Instruments, Inc.
5 * Copyright (C) 2007-2011 Nokia Corporation
7 * Written by Paul Walmsley
8 * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
9 * State counting code by Tero Kristo <tero.kristo@nokia.com>
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.
17 #include <linux/kernel.h>
18 #include <linux/types.h>
19 #include <linux/list.h>
20 #include <linux/errno.h>
21 #include <linux/string.h>
22 #include <trace/events/power.h>
24 #include "cm2xxx_3xxx.h"
27 #include "prm2xxx_3xxx.h"
32 #include "powerdomain.h"
33 #include "clockdomain.h"
34 #include <plat/prcm.h>
38 #define PWRDM_TRACE_STATES_FLAG (1<<31)
46 /* pwrdm_list contains all registered struct powerdomains */
47 static LIST_HEAD(pwrdm_list
);
49 static struct pwrdm_ops
*arch_pwrdm
;
51 /* Private functions */
53 static struct powerdomain
*_pwrdm_lookup(const char *name
)
55 struct powerdomain
*pwrdm
, *temp_pwrdm
;
59 list_for_each_entry(temp_pwrdm
, &pwrdm_list
, node
) {
60 if (!strcmp(name
, temp_pwrdm
->name
)) {
70 * _pwrdm_register - register a powerdomain
71 * @pwrdm: struct powerdomain * to register
73 * Adds a powerdomain to the internal powerdomain list. Returns
74 * -EINVAL if given a null pointer, -EEXIST if a powerdomain is
75 * already registered by the provided name, or 0 upon success.
77 static int _pwrdm_register(struct powerdomain
*pwrdm
)
81 if (!pwrdm
|| !pwrdm
->name
)
84 if (!omap_chip_is(pwrdm
->omap_chip
))
87 if (cpu_is_omap44xx() &&
88 pwrdm
->prcm_partition
== OMAP4430_INVALID_PRCM_PARTITION
) {
89 pr_err("powerdomain: %s: missing OMAP4 PRCM partition ID\n",
94 if (_pwrdm_lookup(pwrdm
->name
))
97 list_add(&pwrdm
->node
, &pwrdm_list
);
99 /* Initialize the powerdomain's state counter */
100 for (i
= 0; i
< PWRDM_MAX_PWRSTS
; i
++)
101 pwrdm
->state_counter
[i
] = 0;
103 pwrdm
->ret_logic_off_counter
= 0;
104 for (i
= 0; i
< pwrdm
->banks
; i
++)
105 pwrdm
->ret_mem_off_counter
[i
] = 0;
107 pwrdm_wait_transition(pwrdm
);
108 pwrdm
->state
= pwrdm_read_pwrst(pwrdm
);
109 pwrdm
->state_counter
[pwrdm
->state
] = 1;
111 pr_debug("powerdomain: registered %s\n", pwrdm
->name
);
116 static void _update_logic_membank_counters(struct powerdomain
*pwrdm
)
119 u8 prev_logic_pwrst
, prev_mem_pwrst
;
121 prev_logic_pwrst
= pwrdm_read_prev_logic_pwrst(pwrdm
);
122 if ((pwrdm
->pwrsts_logic_ret
== PWRSTS_OFF_RET
) &&
123 (prev_logic_pwrst
== PWRDM_POWER_OFF
))
124 pwrdm
->ret_logic_off_counter
++;
126 for (i
= 0; i
< pwrdm
->banks
; i
++) {
127 prev_mem_pwrst
= pwrdm_read_prev_mem_pwrst(pwrdm
, i
);
129 if ((pwrdm
->pwrsts_mem_ret
[i
] == PWRSTS_OFF_RET
) &&
130 (prev_mem_pwrst
== PWRDM_POWER_OFF
))
131 pwrdm
->ret_mem_off_counter
[i
]++;
135 static int _pwrdm_state_switch(struct powerdomain
*pwrdm
, int flag
)
138 int prev
, state
, trace_state
= 0;
143 state
= pwrdm_read_pwrst(pwrdm
);
146 case PWRDM_STATE_NOW
:
149 case PWRDM_STATE_PREV
:
150 prev
= pwrdm_read_prev_pwrst(pwrdm
);
151 if (pwrdm
->state
!= prev
)
152 pwrdm
->state_counter
[prev
]++;
153 if (prev
== PWRDM_POWER_RET
)
154 _update_logic_membank_counters(pwrdm
);
156 * If the power domain did not hit the desired state,
157 * generate a trace event with both the desired and hit states
160 trace_state
= (PWRDM_TRACE_STATES_FLAG
|
161 ((state
& OMAP_POWERSTATE_MASK
) << 8) |
162 ((prev
& OMAP_POWERSTATE_MASK
) << 0));
163 trace_power_domain_target(pwrdm
->name
, trace_state
,
172 pwrdm
->state_counter
[state
]++;
174 pm_dbg_update_time(pwrdm
, prev
);
176 pwrdm
->state
= state
;
181 static int _pwrdm_pre_transition_cb(struct powerdomain
*pwrdm
, void *unused
)
183 pwrdm_clear_all_prev_pwrst(pwrdm
);
184 _pwrdm_state_switch(pwrdm
, PWRDM_STATE_NOW
);
188 static int _pwrdm_post_transition_cb(struct powerdomain
*pwrdm
, void *unused
)
190 _pwrdm_state_switch(pwrdm
, PWRDM_STATE_PREV
);
194 /* Public functions */
197 * pwrdm_init - set up the powerdomain layer
198 * @pwrdms: array of struct powerdomain pointers to register
199 * @custom_funcs: func pointers for arch specific implementations
201 * Loop through the array of powerdomains @pwrdms, registering all
202 * that are available on the current CPU. Also, program all
203 * powerdomain target state as ON; this is to prevent domains from
204 * hitting low power states (if bootloader has target states set to
205 * something other than ON) and potentially even losing context while
206 * PM is not fully initialized. The PM late init code can then program
207 * the desired target state for all the power domains. No return
210 void pwrdm_init(struct powerdomain
**pwrdms
, struct pwrdm_ops
*custom_funcs
)
212 struct powerdomain
**p
= NULL
;
213 struct powerdomain
*temp_p
;
216 WARN(1, "powerdomain: No custom pwrdm functions registered\n");
218 arch_pwrdm
= custom_funcs
;
221 for (p
= pwrdms
; *p
; p
++)
225 list_for_each_entry(temp_p
, &pwrdm_list
, node
)
226 pwrdm_set_next_pwrst(temp_p
, PWRDM_POWER_ON
);
230 * pwrdm_lookup - look up a powerdomain by name, return a pointer
231 * @name: name of powerdomain
233 * Find a registered powerdomain by its name @name. Returns a pointer
234 * to the struct powerdomain if found, or NULL otherwise.
236 struct powerdomain
*pwrdm_lookup(const char *name
)
238 struct powerdomain
*pwrdm
;
243 pwrdm
= _pwrdm_lookup(name
);
249 * pwrdm_for_each - call function on each registered clockdomain
250 * @fn: callback function *
252 * Call the supplied function @fn for each registered powerdomain.
253 * The callback function @fn can return anything but 0 to bail out
254 * early from the iterator. Returns the last return value of the
255 * callback function, which should be 0 for success or anything else
256 * to indicate failure; or -EINVAL if the function pointer is null.
258 int pwrdm_for_each(int (*fn
)(struct powerdomain
*pwrdm
, void *user
),
261 struct powerdomain
*temp_pwrdm
;
267 list_for_each_entry(temp_pwrdm
, &pwrdm_list
, node
) {
268 ret
= (*fn
)(temp_pwrdm
, user
);
277 * pwrdm_add_clkdm - add a clockdomain to a powerdomain
278 * @pwrdm: struct powerdomain * to add the clockdomain to
279 * @clkdm: struct clockdomain * to associate with a powerdomain
281 * Associate the clockdomain @clkdm with a powerdomain @pwrdm. This
282 * enables the use of pwrdm_for_each_clkdm(). Returns -EINVAL if
283 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
286 int pwrdm_add_clkdm(struct powerdomain
*pwrdm
, struct clockdomain
*clkdm
)
291 if (!pwrdm
|| !clkdm
)
294 pr_debug("powerdomain: associating clockdomain %s with powerdomain "
295 "%s\n", clkdm
->name
, pwrdm
->name
);
297 for (i
= 0; i
< PWRDM_MAX_CLKDMS
; i
++) {
298 if (!pwrdm
->pwrdm_clkdms
[i
])
301 if (pwrdm
->pwrdm_clkdms
[i
] == clkdm
) {
308 if (i
== PWRDM_MAX_CLKDMS
) {
309 pr_debug("powerdomain: increase PWRDM_MAX_CLKDMS for "
310 "pwrdm %s clkdm %s\n", pwrdm
->name
, clkdm
->name
);
316 pwrdm
->pwrdm_clkdms
[i
] = clkdm
;
325 * pwrdm_del_clkdm - remove a clockdomain from a powerdomain
326 * @pwrdm: struct powerdomain * to add the clockdomain to
327 * @clkdm: struct clockdomain * to associate with a powerdomain
329 * Dissociate the clockdomain @clkdm from the powerdomain
330 * @pwrdm. Returns -EINVAL if presented with invalid pointers; -ENOENT
331 * if @clkdm was not associated with the powerdomain, or 0 upon
334 int pwrdm_del_clkdm(struct powerdomain
*pwrdm
, struct clockdomain
*clkdm
)
339 if (!pwrdm
|| !clkdm
)
342 pr_debug("powerdomain: dissociating clockdomain %s from powerdomain "
343 "%s\n", clkdm
->name
, pwrdm
->name
);
345 for (i
= 0; i
< PWRDM_MAX_CLKDMS
; i
++)
346 if (pwrdm
->pwrdm_clkdms
[i
] == clkdm
)
349 if (i
== PWRDM_MAX_CLKDMS
) {
350 pr_debug("powerdomain: clkdm %s not associated with pwrdm "
351 "%s ?!\n", clkdm
->name
, pwrdm
->name
);
356 pwrdm
->pwrdm_clkdms
[i
] = NULL
;
365 * pwrdm_for_each_clkdm - call function on each clkdm in a pwrdm
366 * @pwrdm: struct powerdomain * to iterate over
367 * @fn: callback function *
369 * Call the supplied function @fn for each clockdomain in the powerdomain
370 * @pwrdm. The callback function can return anything but 0 to bail
371 * out early from the iterator. Returns -EINVAL if presented with
372 * invalid pointers; or passes along the last return value of the
373 * callback function, which should be 0 for success or anything else
374 * to indicate failure.
376 int pwrdm_for_each_clkdm(struct powerdomain
*pwrdm
,
377 int (*fn
)(struct powerdomain
*pwrdm
,
378 struct clockdomain
*clkdm
))
386 for (i
= 0; i
< PWRDM_MAX_CLKDMS
&& !ret
; i
++)
387 ret
= (*fn
)(pwrdm
, pwrdm
->pwrdm_clkdms
[i
]);
393 * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain
394 * @pwrdm: struct powerdomain *
396 * Return the number of controllable memory banks in powerdomain @pwrdm,
397 * starting with 1. Returns -EINVAL if the powerdomain pointer is null.
399 int pwrdm_get_mem_bank_count(struct powerdomain
*pwrdm
)
408 * pwrdm_set_next_pwrst - set next powerdomain power state
409 * @pwrdm: struct powerdomain * to set
410 * @pwrst: one of the PWRDM_POWER_* macros
412 * Set the powerdomain @pwrdm's next power state to @pwrst. The powerdomain
413 * may not enter this state immediately if the preconditions for this state
414 * have not been satisfied. Returns -EINVAL if the powerdomain pointer is
415 * null or if the power state is invalid for the powerdomin, or returns 0
418 int pwrdm_set_next_pwrst(struct powerdomain
*pwrdm
, u8 pwrst
)
425 if (!(pwrdm
->pwrsts
& (1 << pwrst
)))
428 pr_debug("powerdomain: setting next powerstate for %s to %0x\n",
431 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_set_next_pwrst
) {
432 /* Trace the pwrdm desired target state */
433 trace_power_domain_target(pwrdm
->name
, pwrst
,
435 /* Program the pwrdm desired target state */
436 ret
= arch_pwrdm
->pwrdm_set_next_pwrst(pwrdm
, pwrst
);
443 * pwrdm_read_next_pwrst - get next powerdomain power state
444 * @pwrdm: struct powerdomain * to get power state
446 * Return the powerdomain @pwrdm's next power state. Returns -EINVAL
447 * if the powerdomain pointer is null or returns the next power state
450 int pwrdm_read_next_pwrst(struct powerdomain
*pwrdm
)
457 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_read_next_pwrst
)
458 ret
= arch_pwrdm
->pwrdm_read_next_pwrst(pwrdm
);
464 * pwrdm_read_pwrst - get current powerdomain power state
465 * @pwrdm: struct powerdomain * to get power state
467 * Return the powerdomain @pwrdm's current power state. Returns -EINVAL
468 * if the powerdomain pointer is null or returns the current power state
471 int pwrdm_read_pwrst(struct powerdomain
*pwrdm
)
478 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_read_pwrst
)
479 ret
= arch_pwrdm
->pwrdm_read_pwrst(pwrdm
);
485 * pwrdm_read_prev_pwrst - get previous powerdomain power state
486 * @pwrdm: struct powerdomain * to get previous power state
488 * Return the powerdomain @pwrdm's previous power state. Returns -EINVAL
489 * if the powerdomain pointer is null or returns the previous power state
492 int pwrdm_read_prev_pwrst(struct powerdomain
*pwrdm
)
499 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_read_prev_pwrst
)
500 ret
= arch_pwrdm
->pwrdm_read_prev_pwrst(pwrdm
);
506 * pwrdm_set_logic_retst - set powerdomain logic power state upon retention
507 * @pwrdm: struct powerdomain * to set
508 * @pwrst: one of the PWRDM_POWER_* macros
510 * Set the next power state @pwrst that the logic portion of the
511 * powerdomain @pwrdm will enter when the powerdomain enters retention.
512 * This will be either RETENTION or OFF, if supported. Returns
513 * -EINVAL if the powerdomain pointer is null or the target power
514 * state is not not supported, or returns 0 upon success.
516 int pwrdm_set_logic_retst(struct powerdomain
*pwrdm
, u8 pwrst
)
523 if (!(pwrdm
->pwrsts_logic_ret
& (1 << pwrst
)))
526 pr_debug("powerdomain: setting next logic powerstate for %s to %0x\n",
529 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_set_logic_retst
)
530 ret
= arch_pwrdm
->pwrdm_set_logic_retst(pwrdm
, pwrst
);
536 * pwrdm_set_mem_onst - set memory power state while powerdomain ON
537 * @pwrdm: struct powerdomain * to set
538 * @bank: memory bank number to set (0-3)
539 * @pwrst: one of the PWRDM_POWER_* macros
541 * Set the next power state @pwrst that memory bank @bank of the
542 * powerdomain @pwrdm will enter when the powerdomain enters the ON
543 * state. @bank will be a number from 0 to 3, and represents different
544 * types of memory, depending on the powerdomain. Returns -EINVAL if
545 * the powerdomain pointer is null or the target power state is not
546 * not supported for this memory bank, -EEXIST if the target memory
547 * bank does not exist or is not controllable, or returns 0 upon
550 int pwrdm_set_mem_onst(struct powerdomain
*pwrdm
, u8 bank
, u8 pwrst
)
557 if (pwrdm
->banks
< (bank
+ 1))
560 if (!(pwrdm
->pwrsts_mem_on
[bank
] & (1 << pwrst
)))
563 pr_debug("powerdomain: setting next memory powerstate for domain %s "
564 "bank %0x while pwrdm-ON to %0x\n", pwrdm
->name
, bank
, pwrst
);
566 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_set_mem_onst
)
567 ret
= arch_pwrdm
->pwrdm_set_mem_onst(pwrdm
, bank
, pwrst
);
573 * pwrdm_set_mem_retst - set memory power state while powerdomain in RET
574 * @pwrdm: struct powerdomain * to set
575 * @bank: memory bank number to set (0-3)
576 * @pwrst: one of the PWRDM_POWER_* macros
578 * Set the next power state @pwrst that memory bank @bank of the
579 * powerdomain @pwrdm will enter when the powerdomain enters the
580 * RETENTION state. Bank will be a number from 0 to 3, and represents
581 * different types of memory, depending on the powerdomain. @pwrst
582 * will be either RETENTION or OFF, if supported. Returns -EINVAL if
583 * the powerdomain pointer is null or the target power state is not
584 * not supported for this memory bank, -EEXIST if the target memory
585 * bank does not exist or is not controllable, or returns 0 upon
588 int pwrdm_set_mem_retst(struct powerdomain
*pwrdm
, u8 bank
, u8 pwrst
)
595 if (pwrdm
->banks
< (bank
+ 1))
598 if (!(pwrdm
->pwrsts_mem_ret
[bank
] & (1 << pwrst
)))
601 pr_debug("powerdomain: setting next memory powerstate for domain %s "
602 "bank %0x while pwrdm-RET to %0x\n", pwrdm
->name
, bank
, pwrst
);
604 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_set_mem_retst
)
605 ret
= arch_pwrdm
->pwrdm_set_mem_retst(pwrdm
, bank
, pwrst
);
611 * pwrdm_read_logic_pwrst - get current powerdomain logic retention power state
612 * @pwrdm: struct powerdomain * to get current logic retention power state
614 * Return the power state that the logic portion of powerdomain @pwrdm
615 * will enter when the powerdomain enters retention. Returns -EINVAL
616 * if the powerdomain pointer is null or returns the logic retention
617 * power state upon success.
619 int pwrdm_read_logic_pwrst(struct powerdomain
*pwrdm
)
626 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_read_logic_pwrst
)
627 ret
= arch_pwrdm
->pwrdm_read_logic_pwrst(pwrdm
);
633 * pwrdm_read_prev_logic_pwrst - get previous powerdomain logic power state
634 * @pwrdm: struct powerdomain * to get previous logic power state
636 * Return the powerdomain @pwrdm's previous logic power state. Returns
637 * -EINVAL if the powerdomain pointer is null or returns the previous
638 * logic power state upon success.
640 int pwrdm_read_prev_logic_pwrst(struct powerdomain
*pwrdm
)
647 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_read_prev_logic_pwrst
)
648 ret
= arch_pwrdm
->pwrdm_read_prev_logic_pwrst(pwrdm
);
654 * pwrdm_read_logic_retst - get next powerdomain logic power state
655 * @pwrdm: struct powerdomain * to get next logic power state
657 * Return the powerdomain pwrdm's logic power state. Returns -EINVAL
658 * if the powerdomain pointer is null or returns the next logic
659 * power state upon success.
661 int pwrdm_read_logic_retst(struct powerdomain
*pwrdm
)
668 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_read_logic_retst
)
669 ret
= arch_pwrdm
->pwrdm_read_logic_retst(pwrdm
);
675 * pwrdm_read_mem_pwrst - get current memory bank power state
676 * @pwrdm: struct powerdomain * to get current memory bank power state
677 * @bank: memory bank number (0-3)
679 * Return the powerdomain @pwrdm's current memory power state for bank
680 * @bank. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
681 * the target memory bank does not exist or is not controllable, or
682 * returns the current memory power state upon success.
684 int pwrdm_read_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
691 if (pwrdm
->banks
< (bank
+ 1))
694 if (pwrdm
->flags
& PWRDM_HAS_MPU_QUIRK
)
697 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_read_mem_pwrst
)
698 ret
= arch_pwrdm
->pwrdm_read_mem_pwrst(pwrdm
, bank
);
704 * pwrdm_read_prev_mem_pwrst - get previous memory bank power state
705 * @pwrdm: struct powerdomain * to get previous memory bank power state
706 * @bank: memory bank number (0-3)
708 * Return the powerdomain @pwrdm's previous memory power state for
709 * bank @bank. Returns -EINVAL if the powerdomain pointer is null,
710 * -EEXIST if the target memory bank does not exist or is not
711 * controllable, or returns the previous memory power state upon
714 int pwrdm_read_prev_mem_pwrst(struct powerdomain
*pwrdm
, u8 bank
)
721 if (pwrdm
->banks
< (bank
+ 1))
724 if (pwrdm
->flags
& PWRDM_HAS_MPU_QUIRK
)
727 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_read_prev_mem_pwrst
)
728 ret
= arch_pwrdm
->pwrdm_read_prev_mem_pwrst(pwrdm
, bank
);
734 * pwrdm_read_mem_retst - get next memory bank power state
735 * @pwrdm: struct powerdomain * to get mext memory bank power state
736 * @bank: memory bank number (0-3)
738 * Return the powerdomain pwrdm's next memory power state for bank
739 * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
740 * the target memory bank does not exist or is not controllable, or
741 * returns the next memory power state upon success.
743 int pwrdm_read_mem_retst(struct powerdomain
*pwrdm
, u8 bank
)
750 if (pwrdm
->banks
< (bank
+ 1))
753 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_read_mem_retst
)
754 ret
= arch_pwrdm
->pwrdm_read_mem_retst(pwrdm
, bank
);
760 * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm
761 * @pwrdm: struct powerdomain * to clear
763 * Clear the powerdomain's previous power state register @pwrdm.
764 * Clears the entire register, including logic and memory bank
765 * previous power states. Returns -EINVAL if the powerdomain pointer
766 * is null, or returns 0 upon success.
768 int pwrdm_clear_all_prev_pwrst(struct powerdomain
*pwrdm
)
776 * XXX should get the powerdomain's current state here;
777 * warn & fail if it is not ON.
780 pr_debug("powerdomain: clearing previous power state reg for %s\n",
783 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_clear_all_prev_pwrst
)
784 ret
= arch_pwrdm
->pwrdm_clear_all_prev_pwrst(pwrdm
);
790 * pwrdm_enable_hdwr_sar - enable automatic hardware SAR for a pwrdm
791 * @pwrdm: struct powerdomain *
793 * Enable automatic context save-and-restore upon power state change
794 * for some devices in the powerdomain @pwrdm. Warning: this only
795 * affects a subset of devices in a powerdomain; check the TRM
796 * closely. Returns -EINVAL if the powerdomain pointer is null or if
797 * the powerdomain does not support automatic save-and-restore, or
798 * returns 0 upon success.
800 int pwrdm_enable_hdwr_sar(struct powerdomain
*pwrdm
)
807 if (!(pwrdm
->flags
& PWRDM_HAS_HDWR_SAR
))
810 pr_debug("powerdomain: %s: setting SAVEANDRESTORE bit\n",
813 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_enable_hdwr_sar
)
814 ret
= arch_pwrdm
->pwrdm_enable_hdwr_sar(pwrdm
);
820 * pwrdm_disable_hdwr_sar - disable automatic hardware SAR for a pwrdm
821 * @pwrdm: struct powerdomain *
823 * Disable automatic context save-and-restore upon power state change
824 * for some devices in the powerdomain @pwrdm. Warning: this only
825 * affects a subset of devices in a powerdomain; check the TRM
826 * closely. Returns -EINVAL if the powerdomain pointer is null or if
827 * the powerdomain does not support automatic save-and-restore, or
828 * returns 0 upon success.
830 int pwrdm_disable_hdwr_sar(struct powerdomain
*pwrdm
)
837 if (!(pwrdm
->flags
& PWRDM_HAS_HDWR_SAR
))
840 pr_debug("powerdomain: %s: clearing SAVEANDRESTORE bit\n",
843 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_disable_hdwr_sar
)
844 ret
= arch_pwrdm
->pwrdm_disable_hdwr_sar(pwrdm
);
850 * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR
851 * @pwrdm: struct powerdomain *
853 * Returns 1 if powerdomain @pwrdm supports hardware save-and-restore
854 * for some devices, or 0 if it does not.
856 bool pwrdm_has_hdwr_sar(struct powerdomain
*pwrdm
)
858 return (pwrdm
&& pwrdm
->flags
& PWRDM_HAS_HDWR_SAR
) ? 1 : 0;
862 * pwrdm_set_lowpwrstchange - Request a low power state change
863 * @pwrdm: struct powerdomain *
865 * Allows a powerdomain to transtion to a lower power sleep state
866 * from an existing sleep state without waking up the powerdomain.
867 * Returns -EINVAL if the powerdomain pointer is null or if the
868 * powerdomain does not support LOWPOWERSTATECHANGE, or returns 0
871 int pwrdm_set_lowpwrstchange(struct powerdomain
*pwrdm
)
878 if (!(pwrdm
->flags
& PWRDM_HAS_LOWPOWERSTATECHANGE
))
881 pr_debug("powerdomain: %s: setting LOWPOWERSTATECHANGE bit\n",
884 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_set_lowpwrstchange
)
885 ret
= arch_pwrdm
->pwrdm_set_lowpwrstchange(pwrdm
);
891 * pwrdm_wait_transition - wait for powerdomain power transition to finish
892 * @pwrdm: struct powerdomain * to wait for
894 * If the powerdomain @pwrdm is in the process of a state transition,
895 * spin until it completes the power transition, or until an iteration
896 * bailout value is reached. Returns -EINVAL if the powerdomain
897 * pointer is null, -EAGAIN if the bailout value was reached, or
898 * returns 0 upon success.
900 int pwrdm_wait_transition(struct powerdomain
*pwrdm
)
907 if (arch_pwrdm
&& arch_pwrdm
->pwrdm_wait_transition
)
908 ret
= arch_pwrdm
->pwrdm_wait_transition(pwrdm
);
913 int pwrdm_state_switch(struct powerdomain
*pwrdm
)
915 return _pwrdm_state_switch(pwrdm
, PWRDM_STATE_NOW
);
918 int pwrdm_clkdm_state_switch(struct clockdomain
*clkdm
)
920 if (clkdm
!= NULL
&& clkdm
->pwrdm
.ptr
!= NULL
) {
921 pwrdm_wait_transition(clkdm
->pwrdm
.ptr
);
922 return pwrdm_state_switch(clkdm
->pwrdm
.ptr
);
928 int pwrdm_pre_transition(void)
930 pwrdm_for_each(_pwrdm_pre_transition_cb
, NULL
);
934 int pwrdm_post_transition(void)
936 pwrdm_for_each(_pwrdm_post_transition_cb
, NULL
);
941 * pwrdm_get_context_loss_count - get powerdomain's context loss count
942 * @pwrdm: struct powerdomain * to wait for
944 * Context loss count is the sum of powerdomain off-mode counter, the
945 * logic off counter and the per-bank memory off counter. Returns 0
946 * (and WARNs) upon error, otherwise, returns the context loss count.
948 u32
pwrdm_get_context_loss_count(struct powerdomain
*pwrdm
)
953 WARN(1, "powerdomain: %s: pwrdm is null\n", __func__
);
957 count
= pwrdm
->state_counter
[PWRDM_POWER_OFF
];
958 count
+= pwrdm
->ret_logic_off_counter
;
960 for (i
= 0; i
< pwrdm
->banks
; i
++)
961 count
+= pwrdm
->ret_mem_off_counter
[i
];
963 pr_debug("powerdomain: %s: context loss count = %u\n",
970 * pwrdm_can_ever_lose_context - can this powerdomain ever lose context?
971 * @pwrdm: struct powerdomain *
973 * Given a struct powerdomain * @pwrdm, returns 1 if the powerdomain
974 * can lose either memory or logic context or if @pwrdm is invalid, or
975 * returns 0 otherwise. This function is not concerned with how the
976 * powerdomain registers are programmed (i.e., to go off or not); it's
977 * concerned with whether it's ever possible for this powerdomain to
978 * go off while some other part of the chip is active. This function
979 * assumes that every powerdomain can go to either ON or INACTIVE.
981 bool pwrdm_can_ever_lose_context(struct powerdomain
*pwrdm
)
985 if (IS_ERR_OR_NULL(pwrdm
)) {
986 pr_debug("powerdomain: %s: invalid powerdomain pointer\n",
991 if (pwrdm
->pwrsts
& PWRSTS_OFF
)
994 if (pwrdm
->pwrsts
& PWRSTS_RET
) {
995 if (pwrdm
->pwrsts_logic_ret
& PWRSTS_OFF
)
998 for (i
= 0; i
< pwrdm
->banks
; i
++)
999 if (pwrdm
->pwrsts_mem_ret
[i
] & PWRSTS_OFF
)
1003 for (i
= 0; i
< pwrdm
->banks
; i
++)
1004 if (pwrdm
->pwrsts_mem_on
[i
] & PWRSTS_OFF
)