2 * OMAP powerdomain control
4 * Copyright (C) 2007-2008, 2011 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 <plat/prcm.h>
34 #include "powerdomain.h"
35 #include "clockdomain.h"
40 #define PWRDM_TRACE_STATES_FLAG (1<<31)
48 /* pwrdm_list contains all registered struct powerdomains */
49 static LIST_HEAD(pwrdm_list);
51 static struct pwrdm_ops *arch_pwrdm;
53 /* Private functions */
55 static struct powerdomain *_pwrdm_lookup(const char *name)
57 struct powerdomain *pwrdm, *temp_pwrdm;
61 list_for_each_entry(temp_pwrdm, &pwrdm_list, node) {
62 if (!strcmp(name, temp_pwrdm->name)) {
72 * _pwrdm_register - register a powerdomain
73 * @pwrdm: struct powerdomain * to register
75 * Adds a powerdomain to the internal powerdomain list. Returns
76 * -EINVAL if given a null pointer, -EEXIST if a powerdomain is
77 * already registered by the provided name, or 0 upon success.
79 static int _pwrdm_register(struct powerdomain *pwrdm)
82 struct voltagedomain *voltdm;
84 if (!pwrdm || !pwrdm->name)
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 voltdm = voltdm_lookup(pwrdm->voltdm.name);
99 pr_err("powerdomain: %s: voltagedomain %s does not exist\n",
100 pwrdm->name, pwrdm->voltdm.name);
103 pwrdm->voltdm.ptr = voltdm;
104 INIT_LIST_HEAD(&pwrdm->voltdm_node);
105 voltdm_add_pwrdm(voltdm, pwrdm);
107 list_add(&pwrdm->node, &pwrdm_list);
109 /* Initialize the powerdomain's state counter */
110 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
111 pwrdm->state_counter[i] = 0;
113 pwrdm->ret_logic_off_counter = 0;
114 for (i = 0; i < pwrdm->banks; i++)
115 pwrdm->ret_mem_off_counter[i] = 0;
117 pwrdm_wait_transition(pwrdm);
118 pwrdm->state = pwrdm_read_pwrst(pwrdm);
119 pwrdm->state_counter[pwrdm->state] = 1;
121 pr_debug("powerdomain: registered %s\n", pwrdm->name);
126 static void _update_logic_membank_counters(struct powerdomain *pwrdm)
129 u8 prev_logic_pwrst, prev_mem_pwrst;
131 prev_logic_pwrst = pwrdm_read_prev_logic_pwrst(pwrdm);
132 if ((pwrdm->pwrsts_logic_ret == PWRSTS_OFF_RET) &&
133 (prev_logic_pwrst == PWRDM_POWER_OFF))
134 pwrdm->ret_logic_off_counter++;
136 for (i = 0; i < pwrdm->banks; i++) {
137 prev_mem_pwrst = pwrdm_read_prev_mem_pwrst(pwrdm, i);
139 if ((pwrdm->pwrsts_mem_ret[i] == PWRSTS_OFF_RET) &&
140 (prev_mem_pwrst == PWRDM_POWER_OFF))
141 pwrdm->ret_mem_off_counter[i]++;
145 static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)
148 int prev, state, trace_state = 0;
153 state = pwrdm_read_pwrst(pwrdm);
156 case PWRDM_STATE_NOW:
159 case PWRDM_STATE_PREV:
160 prev = pwrdm_read_prev_pwrst(pwrdm);
161 if (pwrdm->state != prev)
162 pwrdm->state_counter[prev]++;
163 if (prev == PWRDM_POWER_RET)
164 _update_logic_membank_counters(pwrdm);
166 * If the power domain did not hit the desired state,
167 * generate a trace event with both the desired and hit states
170 trace_state = (PWRDM_TRACE_STATES_FLAG |
171 ((state & OMAP_POWERSTATE_MASK) << 8) |
172 ((prev & OMAP_POWERSTATE_MASK) << 0));
173 trace_power_domain_target(pwrdm->name, trace_state,
182 pwrdm->state_counter[state]++;
184 pm_dbg_update_time(pwrdm, prev);
186 pwrdm->state = state;
191 static int _pwrdm_pre_transition_cb(struct powerdomain *pwrdm, void *unused)
193 pwrdm_clear_all_prev_pwrst(pwrdm);
194 _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
198 static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused)
200 _pwrdm_state_switch(pwrdm, PWRDM_STATE_PREV);
204 /* Public functions */
207 * pwrdm_register_platform_funcs - register powerdomain implementation fns
208 * @po: func pointers for arch specific implementations
210 * Register the list of function pointers used to implement the
211 * powerdomain functions on different OMAP SoCs. Should be called
212 * before any other pwrdm_register*() function. Returns -EINVAL if
213 * @po is null, -EEXIST if platform functions have already been
214 * registered, or 0 upon success.
216 int pwrdm_register_platform_funcs(struct pwrdm_ops *po)
230 * pwrdm_register_pwrdms - register SoC powerdomains
231 * @ps: pointer to an array of struct powerdomain to register
233 * Register the powerdomains available on a particular OMAP SoC. Must
234 * be called after pwrdm_register_platform_funcs(). May be called
235 * multiple times. Returns -EACCES if called before
236 * pwrdm_register_platform_funcs(); -EINVAL if the argument @ps is
237 * null; or 0 upon success.
239 int pwrdm_register_pwrdms(struct powerdomain **ps)
241 struct powerdomain **p = NULL;
249 for (p = ps; *p; p++)
256 * pwrdm_complete_init - set up the powerdomain layer
258 * Do whatever is necessary to initialize registered powerdomains and
259 * powerdomain code. Currently, this programs the next power state
260 * for each powerdomain to ON. This prevents powerdomains from
261 * unexpectedly losing context or entering high wakeup latency modes
262 * with non-power-management-enabled kernels. Must be called after
263 * pwrdm_register_pwrdms(). Returns -EACCES if called before
264 * pwrdm_register_pwrdms(), or 0 upon success.
266 int pwrdm_complete_init(void)
268 struct powerdomain *temp_p;
270 if (list_empty(&pwrdm_list))
273 list_for_each_entry(temp_p, &pwrdm_list, node)
274 pwrdm_set_next_pwrst(temp_p, PWRDM_POWER_ON);
280 * pwrdm_lookup - look up a powerdomain by name, return a pointer
281 * @name: name of powerdomain
283 * Find a registered powerdomain by its name @name. Returns a pointer
284 * to the struct powerdomain if found, or NULL otherwise.
286 struct powerdomain *pwrdm_lookup(const char *name)
288 struct powerdomain *pwrdm;
293 pwrdm = _pwrdm_lookup(name);
299 * pwrdm_for_each - call function on each registered clockdomain
300 * @fn: callback function *
302 * Call the supplied function @fn for each registered powerdomain.
303 * The callback function @fn can return anything but 0 to bail out
304 * early from the iterator. Returns the last return value of the
305 * callback function, which should be 0 for success or anything else
306 * to indicate failure; or -EINVAL if the function pointer is null.
308 int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user),
311 struct powerdomain *temp_pwrdm;
317 list_for_each_entry(temp_pwrdm, &pwrdm_list, node) {
318 ret = (*fn)(temp_pwrdm, user);
327 * pwrdm_add_clkdm - add a clockdomain to a powerdomain
328 * @pwrdm: struct powerdomain * to add the clockdomain to
329 * @clkdm: struct clockdomain * to associate with a powerdomain
331 * Associate the clockdomain @clkdm with a powerdomain @pwrdm. This
332 * enables the use of pwrdm_for_each_clkdm(). Returns -EINVAL if
333 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
336 int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
341 if (!pwrdm || !clkdm)
344 pr_debug("powerdomain: %s: associating clockdomain %s\n",
345 pwrdm->name, clkdm->name);
347 for (i = 0; i < PWRDM_MAX_CLKDMS; i++) {
348 if (!pwrdm->pwrdm_clkdms[i])
351 if (pwrdm->pwrdm_clkdms[i] == clkdm) {
358 if (i == PWRDM_MAX_CLKDMS) {
359 pr_debug("powerdomain: %s: increase PWRDM_MAX_CLKDMS for clkdm %s\n",
360 pwrdm->name, clkdm->name);
366 pwrdm->pwrdm_clkdms[i] = clkdm;
375 * pwrdm_del_clkdm - remove a clockdomain from a powerdomain
376 * @pwrdm: struct powerdomain * to add the clockdomain to
377 * @clkdm: struct clockdomain * to associate with a powerdomain
379 * Dissociate the clockdomain @clkdm from the powerdomain
380 * @pwrdm. Returns -EINVAL if presented with invalid pointers; -ENOENT
381 * if @clkdm was not associated with the powerdomain, or 0 upon
384 int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
389 if (!pwrdm || !clkdm)
392 pr_debug("powerdomain: %s: dissociating clockdomain %s\n",
393 pwrdm->name, clkdm->name);
395 for (i = 0; i < PWRDM_MAX_CLKDMS; i++)
396 if (pwrdm->pwrdm_clkdms[i] == clkdm)
399 if (i == PWRDM_MAX_CLKDMS) {
400 pr_debug("powerdomain: %s: clkdm %s not associated?!\n",
401 pwrdm->name, clkdm->name);
406 pwrdm->pwrdm_clkdms[i] = NULL;
415 * pwrdm_for_each_clkdm - call function on each clkdm in a pwrdm
416 * @pwrdm: struct powerdomain * to iterate over
417 * @fn: callback function *
419 * Call the supplied function @fn for each clockdomain in the powerdomain
420 * @pwrdm. The callback function can return anything but 0 to bail
421 * out early from the iterator. Returns -EINVAL if presented with
422 * invalid pointers; or passes along the last return value of the
423 * callback function, which should be 0 for success or anything else
424 * to indicate failure.
426 int pwrdm_for_each_clkdm(struct powerdomain *pwrdm,
427 int (*fn)(struct powerdomain *pwrdm,
428 struct clockdomain *clkdm))
436 for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++)
437 ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]);
443 * pwrdm_get_voltdm - return a ptr to the voltdm that this pwrdm resides in
444 * @pwrdm: struct powerdomain *
446 * Return a pointer to the struct voltageomain that the specified powerdomain
449 struct voltagedomain *pwrdm_get_voltdm(struct powerdomain *pwrdm)
451 return pwrdm->voltdm.ptr;
455 * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain
456 * @pwrdm: struct powerdomain *
458 * Return the number of controllable memory banks in powerdomain @pwrdm,
459 * starting with 1. Returns -EINVAL if the powerdomain pointer is null.
461 int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm)
470 * pwrdm_set_next_pwrst - set next powerdomain power state
471 * @pwrdm: struct powerdomain * to set
472 * @pwrst: one of the PWRDM_POWER_* macros
474 * Set the powerdomain @pwrdm's next power state to @pwrst. The powerdomain
475 * may not enter this state immediately if the preconditions for this state
476 * have not been satisfied. Returns -EINVAL if the powerdomain pointer is
477 * null or if the power state is invalid for the powerdomin, or returns 0
480 int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
487 if (!(pwrdm->pwrsts & (1 << pwrst)))
490 pr_debug("powerdomain: %s: setting next powerstate to %0x\n",
493 if (arch_pwrdm && arch_pwrdm->pwrdm_set_next_pwrst) {
494 /* Trace the pwrdm desired target state */
495 trace_power_domain_target(pwrdm->name, pwrst,
497 /* Program the pwrdm desired target state */
498 ret = arch_pwrdm->pwrdm_set_next_pwrst(pwrdm, pwrst);
505 * pwrdm_read_next_pwrst - get next powerdomain power state
506 * @pwrdm: struct powerdomain * to get power state
508 * Return the powerdomain @pwrdm's next power state. Returns -EINVAL
509 * if the powerdomain pointer is null or returns the next power state
512 int pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
519 if (arch_pwrdm && arch_pwrdm->pwrdm_read_next_pwrst)
520 ret = arch_pwrdm->pwrdm_read_next_pwrst(pwrdm);
526 * pwrdm_read_pwrst - get current powerdomain power state
527 * @pwrdm: struct powerdomain * to get power state
529 * Return the powerdomain @pwrdm's current power state. Returns -EINVAL
530 * if the powerdomain pointer is null or returns the current power state
531 * upon success. Note that if the power domain only supports the ON state
532 * then just return ON as the current state.
534 int pwrdm_read_pwrst(struct powerdomain *pwrdm)
541 if (pwrdm->pwrsts == PWRSTS_ON)
542 return PWRDM_POWER_ON;
544 if (arch_pwrdm && arch_pwrdm->pwrdm_read_pwrst)
545 ret = arch_pwrdm->pwrdm_read_pwrst(pwrdm);
551 * pwrdm_read_prev_pwrst - get previous powerdomain power state
552 * @pwrdm: struct powerdomain * to get previous power state
554 * Return the powerdomain @pwrdm's previous power state. Returns -EINVAL
555 * if the powerdomain pointer is null or returns the previous power state
558 int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
565 if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_pwrst)
566 ret = arch_pwrdm->pwrdm_read_prev_pwrst(pwrdm);
572 * pwrdm_set_logic_retst - set powerdomain logic power state upon retention
573 * @pwrdm: struct powerdomain * to set
574 * @pwrst: one of the PWRDM_POWER_* macros
576 * Set the next power state @pwrst that the logic portion of the
577 * powerdomain @pwrdm will enter when the powerdomain enters retention.
578 * This will be either RETENTION or OFF, if supported. Returns
579 * -EINVAL if the powerdomain pointer is null or the target power
580 * state is not not supported, or returns 0 upon success.
582 int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
589 if (!(pwrdm->pwrsts_logic_ret & (1 << pwrst)))
592 pr_debug("powerdomain: %s: setting next logic powerstate to %0x\n",
595 if (arch_pwrdm && arch_pwrdm->pwrdm_set_logic_retst)
596 ret = arch_pwrdm->pwrdm_set_logic_retst(pwrdm, pwrst);
602 * pwrdm_set_mem_onst - set memory power state while powerdomain ON
603 * @pwrdm: struct powerdomain * to set
604 * @bank: memory bank number to set (0-3)
605 * @pwrst: one of the PWRDM_POWER_* macros
607 * Set the next power state @pwrst that memory bank @bank of the
608 * powerdomain @pwrdm will enter when the powerdomain enters the ON
609 * state. @bank will be a number from 0 to 3, and represents different
610 * types of memory, depending on the powerdomain. Returns -EINVAL if
611 * the powerdomain pointer is null or the target power state is not
612 * not supported for this memory bank, -EEXIST if the target memory
613 * bank does not exist or is not controllable, or returns 0 upon
616 int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst)
623 if (pwrdm->banks < (bank + 1))
626 if (!(pwrdm->pwrsts_mem_on[bank] & (1 << pwrst)))
629 pr_debug("powerdomain: %s: setting next memory powerstate for bank %0x while pwrdm-ON to %0x\n",
630 pwrdm->name, bank, pwrst);
632 if (arch_pwrdm && arch_pwrdm->pwrdm_set_mem_onst)
633 ret = arch_pwrdm->pwrdm_set_mem_onst(pwrdm, bank, pwrst);
639 * pwrdm_set_mem_retst - set memory power state while powerdomain in RET
640 * @pwrdm: struct powerdomain * to set
641 * @bank: memory bank number to set (0-3)
642 * @pwrst: one of the PWRDM_POWER_* macros
644 * Set the next power state @pwrst that memory bank @bank of the
645 * powerdomain @pwrdm will enter when the powerdomain enters the
646 * RETENTION state. Bank will be a number from 0 to 3, and represents
647 * different types of memory, depending on the powerdomain. @pwrst
648 * will be either RETENTION or OFF, if supported. Returns -EINVAL if
649 * the powerdomain pointer is null or the target power state is not
650 * not supported for this memory bank, -EEXIST if the target memory
651 * bank does not exist or is not controllable, or returns 0 upon
654 int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst)
661 if (pwrdm->banks < (bank + 1))
664 if (!(pwrdm->pwrsts_mem_ret[bank] & (1 << pwrst)))
667 pr_debug("powerdomain: %s: setting next memory powerstate for bank %0x while pwrdm-RET to %0x\n",
668 pwrdm->name, bank, pwrst);
670 if (arch_pwrdm && arch_pwrdm->pwrdm_set_mem_retst)
671 ret = arch_pwrdm->pwrdm_set_mem_retst(pwrdm, bank, pwrst);
677 * pwrdm_read_logic_pwrst - get current powerdomain logic retention power state
678 * @pwrdm: struct powerdomain * to get current logic retention power state
680 * Return the power state that the logic portion of powerdomain @pwrdm
681 * will enter when the powerdomain enters retention. Returns -EINVAL
682 * if the powerdomain pointer is null or returns the logic retention
683 * power state upon success.
685 int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
692 if (arch_pwrdm && arch_pwrdm->pwrdm_read_logic_pwrst)
693 ret = arch_pwrdm->pwrdm_read_logic_pwrst(pwrdm);
699 * pwrdm_read_prev_logic_pwrst - get previous powerdomain logic power state
700 * @pwrdm: struct powerdomain * to get previous logic power state
702 * Return the powerdomain @pwrdm's previous logic power state. Returns
703 * -EINVAL if the powerdomain pointer is null or returns the previous
704 * logic power state upon success.
706 int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
713 if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_logic_pwrst)
714 ret = arch_pwrdm->pwrdm_read_prev_logic_pwrst(pwrdm);
720 * pwrdm_read_logic_retst - get next powerdomain logic power state
721 * @pwrdm: struct powerdomain * to get next logic power state
723 * Return the powerdomain pwrdm's logic power state. Returns -EINVAL
724 * if the powerdomain pointer is null or returns the next logic
725 * power state upon success.
727 int pwrdm_read_logic_retst(struct powerdomain *pwrdm)
734 if (arch_pwrdm && arch_pwrdm->pwrdm_read_logic_retst)
735 ret = arch_pwrdm->pwrdm_read_logic_retst(pwrdm);
741 * pwrdm_read_mem_pwrst - get current memory bank power state
742 * @pwrdm: struct powerdomain * to get current memory bank power state
743 * @bank: memory bank number (0-3)
745 * Return the powerdomain @pwrdm's current memory power state for bank
746 * @bank. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
747 * the target memory bank does not exist or is not controllable, or
748 * returns the current memory power state upon success.
750 int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
757 if (pwrdm->banks < (bank + 1))
760 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
763 if (arch_pwrdm && arch_pwrdm->pwrdm_read_mem_pwrst)
764 ret = arch_pwrdm->pwrdm_read_mem_pwrst(pwrdm, bank);
770 * pwrdm_read_prev_mem_pwrst - get previous memory bank power state
771 * @pwrdm: struct powerdomain * to get previous memory bank power state
772 * @bank: memory bank number (0-3)
774 * Return the powerdomain @pwrdm's previous memory power state for
775 * bank @bank. Returns -EINVAL if the powerdomain pointer is null,
776 * -EEXIST if the target memory bank does not exist or is not
777 * controllable, or returns the previous memory power state upon
780 int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
787 if (pwrdm->banks < (bank + 1))
790 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
793 if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_mem_pwrst)
794 ret = arch_pwrdm->pwrdm_read_prev_mem_pwrst(pwrdm, bank);
800 * pwrdm_read_mem_retst - get next memory bank power state
801 * @pwrdm: struct powerdomain * to get mext memory bank power state
802 * @bank: memory bank number (0-3)
804 * Return the powerdomain pwrdm's next memory power state for bank
805 * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
806 * the target memory bank does not exist or is not controllable, or
807 * returns the next memory power state upon success.
809 int pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
816 if (pwrdm->banks < (bank + 1))
819 if (arch_pwrdm && arch_pwrdm->pwrdm_read_mem_retst)
820 ret = arch_pwrdm->pwrdm_read_mem_retst(pwrdm, bank);
826 * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm
827 * @pwrdm: struct powerdomain * to clear
829 * Clear the powerdomain's previous power state register @pwrdm.
830 * Clears the entire register, including logic and memory bank
831 * previous power states. Returns -EINVAL if the powerdomain pointer
832 * is null, or returns 0 upon success.
834 int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
842 * XXX should get the powerdomain's current state here;
843 * warn & fail if it is not ON.
846 pr_debug("powerdomain: %s: clearing previous power state reg\n",
849 if (arch_pwrdm && arch_pwrdm->pwrdm_clear_all_prev_pwrst)
850 ret = arch_pwrdm->pwrdm_clear_all_prev_pwrst(pwrdm);
856 * pwrdm_enable_hdwr_sar - enable automatic hardware SAR for a pwrdm
857 * @pwrdm: struct powerdomain *
859 * Enable automatic context save-and-restore upon power state change
860 * for some devices in the powerdomain @pwrdm. Warning: this only
861 * affects a subset of devices in a powerdomain; check the TRM
862 * closely. Returns -EINVAL if the powerdomain pointer is null or if
863 * the powerdomain does not support automatic save-and-restore, or
864 * returns 0 upon success.
866 int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm)
873 if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR))
876 pr_debug("powerdomain: %s: setting SAVEANDRESTORE bit\n", pwrdm->name);
878 if (arch_pwrdm && arch_pwrdm->pwrdm_enable_hdwr_sar)
879 ret = arch_pwrdm->pwrdm_enable_hdwr_sar(pwrdm);
885 * pwrdm_disable_hdwr_sar - disable automatic hardware SAR for a pwrdm
886 * @pwrdm: struct powerdomain *
888 * Disable automatic context save-and-restore upon power state change
889 * for some devices in the powerdomain @pwrdm. Warning: this only
890 * affects a subset of devices in a powerdomain; check the TRM
891 * closely. Returns -EINVAL if the powerdomain pointer is null or if
892 * the powerdomain does not support automatic save-and-restore, or
893 * returns 0 upon success.
895 int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm)
902 if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR))
905 pr_debug("powerdomain: %s: clearing SAVEANDRESTORE bit\n", pwrdm->name);
907 if (arch_pwrdm && arch_pwrdm->pwrdm_disable_hdwr_sar)
908 ret = arch_pwrdm->pwrdm_disable_hdwr_sar(pwrdm);
914 * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR
915 * @pwrdm: struct powerdomain *
917 * Returns 1 if powerdomain @pwrdm supports hardware save-and-restore
918 * for some devices, or 0 if it does not.
920 bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm)
922 return (pwrdm && pwrdm->flags & PWRDM_HAS_HDWR_SAR) ? 1 : 0;
926 * pwrdm_set_lowpwrstchange - Request a low power state change
927 * @pwrdm: struct powerdomain *
929 * Allows a powerdomain to transtion to a lower power sleep state
930 * from an existing sleep state without waking up the powerdomain.
931 * Returns -EINVAL if the powerdomain pointer is null or if the
932 * powerdomain does not support LOWPOWERSTATECHANGE, or returns 0
935 int pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm)
942 if (!(pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE))
945 pr_debug("powerdomain: %s: setting LOWPOWERSTATECHANGE bit\n",
948 if (arch_pwrdm && arch_pwrdm->pwrdm_set_lowpwrstchange)
949 ret = arch_pwrdm->pwrdm_set_lowpwrstchange(pwrdm);
955 * pwrdm_wait_transition - wait for powerdomain power transition to finish
956 * @pwrdm: struct powerdomain * to wait for
958 * If the powerdomain @pwrdm is in the process of a state transition,
959 * spin until it completes the power transition, or until an iteration
960 * bailout value is reached. Returns -EINVAL if the powerdomain
961 * pointer is null, -EAGAIN if the bailout value was reached, or
962 * returns 0 upon success.
964 int pwrdm_wait_transition(struct powerdomain *pwrdm)
971 if (arch_pwrdm && arch_pwrdm->pwrdm_wait_transition)
972 ret = arch_pwrdm->pwrdm_wait_transition(pwrdm);
977 int pwrdm_state_switch(struct powerdomain *pwrdm)
981 ret = pwrdm_wait_transition(pwrdm);
983 ret = _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
988 int pwrdm_pre_transition(struct powerdomain *pwrdm)
991 _pwrdm_pre_transition_cb(pwrdm, NULL);
993 pwrdm_for_each(_pwrdm_pre_transition_cb, NULL);
998 int pwrdm_post_transition(struct powerdomain *pwrdm)
1001 _pwrdm_post_transition_cb(pwrdm, NULL);
1003 pwrdm_for_each(_pwrdm_post_transition_cb, NULL);
1009 * pwrdm_get_context_loss_count - get powerdomain's context loss count
1010 * @pwrdm: struct powerdomain * to wait for
1012 * Context loss count is the sum of powerdomain off-mode counter, the
1013 * logic off counter and the per-bank memory off counter. Returns negative
1014 * (and WARNs) upon error, otherwise, returns the context loss count.
1016 int pwrdm_get_context_loss_count(struct powerdomain *pwrdm)
1021 WARN(1, "powerdomain: %s: pwrdm is null\n", __func__);
1025 count = pwrdm->state_counter[PWRDM_POWER_OFF];
1026 count += pwrdm->ret_logic_off_counter;
1028 for (i = 0; i < pwrdm->banks; i++)
1029 count += pwrdm->ret_mem_off_counter[i];
1032 * Context loss count has to be a non-negative value. Clear the sign
1033 * bit to get a value range from 0 to INT_MAX.
1037 pr_debug("powerdomain: %s: context loss count = %d\n",
1038 pwrdm->name, count);
1044 * pwrdm_can_ever_lose_context - can this powerdomain ever lose context?
1045 * @pwrdm: struct powerdomain *
1047 * Given a struct powerdomain * @pwrdm, returns 1 if the powerdomain
1048 * can lose either memory or logic context or if @pwrdm is invalid, or
1049 * returns 0 otherwise. This function is not concerned with how the
1050 * powerdomain registers are programmed (i.e., to go off or not); it's
1051 * concerned with whether it's ever possible for this powerdomain to
1052 * go off while some other part of the chip is active. This function
1053 * assumes that every powerdomain can go to either ON or INACTIVE.
1055 bool pwrdm_can_ever_lose_context(struct powerdomain *pwrdm)
1059 if (IS_ERR_OR_NULL(pwrdm)) {
1060 pr_debug("powerdomain: %s: invalid powerdomain pointer\n",
1065 if (pwrdm->pwrsts & PWRSTS_OFF)
1068 if (pwrdm->pwrsts & PWRSTS_RET) {
1069 if (pwrdm->pwrsts_logic_ret & PWRSTS_OFF)
1072 for (i = 0; i < pwrdm->banks; i++)
1073 if (pwrdm->pwrsts_mem_ret[i] & PWRSTS_OFF)
1077 for (i = 0; i < pwrdm->banks; i++)
1078 if (pwrdm->pwrsts_mem_on[i] & PWRSTS_OFF)