OMAP4: PRCM: rename _MOD macros to _INST
[deliverable/linux.git] / arch / arm / mach-omap2 / powerdomain.c
CommitLineData
ad67ef68
PW
1/*
2 * OMAP powerdomain control
3 *
4 * Copyright (C) 2007-2008 Texas Instruments, Inc.
55ed9694 5 * Copyright (C) 2007-2009 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>
d198b514 22#include "prm44xx.h"
ad67ef68 23
ce491cf8
TL
24#include <plat/cpu.h>
25#include <plat/powerdomain.h>
26#include <plat/clockdomain.h>
55ed9694 27#include <plat/prcm.h>
ad67ef68 28
6199ab26
PDS
29#include "pm.h"
30
ba20bb12
PDS
31enum {
32 PWRDM_STATE_NOW = 0,
33 PWRDM_STATE_PREV,
34};
35
3a759f09 36
ad67ef68
PW
37/* pwrdm_list contains all registered struct powerdomains */
38static LIST_HEAD(pwrdm_list);
39
3b1e8b21
RN
40static struct pwrdm_ops *arch_pwrdm;
41
ad67ef68
PW
42/* Private functions */
43
ad67ef68
PW
44static struct powerdomain *_pwrdm_lookup(const char *name)
45{
46 struct powerdomain *pwrdm, *temp_pwrdm;
47
48 pwrdm = NULL;
49
50 list_for_each_entry(temp_pwrdm, &pwrdm_list, node) {
51 if (!strcmp(name, temp_pwrdm->name)) {
52 pwrdm = temp_pwrdm;
53 break;
54 }
55 }
56
57 return pwrdm;
58}
59
e909d62a
PW
60/**
61 * _pwrdm_register - register a powerdomain
62 * @pwrdm: struct powerdomain * to register
63 *
64 * Adds a powerdomain to the internal powerdomain list. Returns
65 * -EINVAL if given a null pointer, -EEXIST if a powerdomain is
66 * already registered by the provided name, or 0 upon success.
67 */
68static int _pwrdm_register(struct powerdomain *pwrdm)
69{
70 int i;
71
72 if (!pwrdm)
73 return -EINVAL;
74
75 if (!omap_chip_is(pwrdm->omap_chip))
76 return -EINVAL;
77
78 if (_pwrdm_lookup(pwrdm->name))
79 return -EEXIST;
80
81 list_add(&pwrdm->node, &pwrdm_list);
82
83 /* Initialize the powerdomain's state counter */
cf57aa7c 84 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
e909d62a
PW
85 pwrdm->state_counter[i] = 0;
86
cde08f81
TG
87 pwrdm->ret_logic_off_counter = 0;
88 for (i = 0; i < pwrdm->banks; i++)
89 pwrdm->ret_mem_off_counter[i] = 0;
90
e909d62a
PW
91 pwrdm_wait_transition(pwrdm);
92 pwrdm->state = pwrdm_read_pwrst(pwrdm);
93 pwrdm->state_counter[pwrdm->state] = 1;
94
95 pr_debug("powerdomain: registered %s\n", pwrdm->name);
96
97 return 0;
98}
99
cde08f81
TG
100static void _update_logic_membank_counters(struct powerdomain *pwrdm)
101{
102 int i;
103 u8 prev_logic_pwrst, prev_mem_pwrst;
104
105 prev_logic_pwrst = pwrdm_read_prev_logic_pwrst(pwrdm);
106 if ((pwrdm->pwrsts_logic_ret == PWRSTS_OFF_RET) &&
107 (prev_logic_pwrst == PWRDM_POWER_OFF))
108 pwrdm->ret_logic_off_counter++;
109
110 for (i = 0; i < pwrdm->banks; i++) {
111 prev_mem_pwrst = pwrdm_read_prev_mem_pwrst(pwrdm, i);
112
113 if ((pwrdm->pwrsts_mem_ret[i] == PWRSTS_OFF_RET) &&
114 (prev_mem_pwrst == PWRDM_POWER_OFF))
115 pwrdm->ret_mem_off_counter[i]++;
116 }
117}
118
ba20bb12
PDS
119static int _pwrdm_state_switch(struct powerdomain *pwrdm, int flag)
120{
121
122 int prev;
123 int state;
124
125 if (pwrdm == NULL)
126 return -EINVAL;
127
128 state = pwrdm_read_pwrst(pwrdm);
129
130 switch (flag) {
131 case PWRDM_STATE_NOW:
132 prev = pwrdm->state;
133 break;
134 case PWRDM_STATE_PREV:
135 prev = pwrdm_read_prev_pwrst(pwrdm);
136 if (pwrdm->state != prev)
137 pwrdm->state_counter[prev]++;
cde08f81
TG
138 if (prev == PWRDM_POWER_RET)
139 _update_logic_membank_counters(pwrdm);
ba20bb12
PDS
140 break;
141 default:
142 return -EINVAL;
143 }
144
145 if (state != prev)
146 pwrdm->state_counter[state]++;
147
6199ab26
PDS
148 pm_dbg_update_time(pwrdm, prev);
149
ba20bb12
PDS
150 pwrdm->state = state;
151
152 return 0;
153}
154
6199ab26 155static int _pwrdm_pre_transition_cb(struct powerdomain *pwrdm, void *unused)
ba20bb12
PDS
156{
157 pwrdm_clear_all_prev_pwrst(pwrdm);
158 _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
159 return 0;
160}
161
6199ab26 162static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused)
ba20bb12
PDS
163{
164 _pwrdm_state_switch(pwrdm, PWRDM_STATE_PREV);
165 return 0;
166}
167
ad67ef68
PW
168/* Public functions */
169
170/**
171 * pwrdm_init - set up the powerdomain layer
f0271d65 172 * @pwrdm_list: array of struct powerdomain pointers to register
3b1e8b21 173 * @custom_funcs: func pointers for arch specfic implementations
ad67ef68 174 *
f0271d65
PW
175 * Loop through the array of powerdomains @pwrdm_list, registering all
176 * that are available on the current CPU. If pwrdm_list is supplied
177 * and not null, all of the referenced powerdomains will be
178 * registered. No return value. XXX pwrdm_list is not really a
179 * "list"; it is an array. Rename appropriately.
ad67ef68 180 */
3b1e8b21 181void pwrdm_init(struct powerdomain **pwrdm_list, struct pwrdm_ops *custom_funcs)
ad67ef68
PW
182{
183 struct powerdomain **p = NULL;
184
3b1e8b21
RN
185 if (!custom_funcs)
186 WARN(1, "powerdomain: No custom pwrdm functions registered\n");
187 else
188 arch_pwrdm = custom_funcs;
189
ba20bb12 190 if (pwrdm_list) {
e909d62a
PW
191 for (p = pwrdm_list; *p; p++)
192 _pwrdm_register(*p);
ad67ef68 193 }
ad67ef68
PW
194}
195
196/**
197 * pwrdm_lookup - look up a powerdomain by name, return a pointer
198 * @name: name of powerdomain
199 *
f0271d65
PW
200 * Find a registered powerdomain by its name @name. Returns a pointer
201 * to the struct powerdomain if found, or NULL otherwise.
ad67ef68
PW
202 */
203struct powerdomain *pwrdm_lookup(const char *name)
204{
205 struct powerdomain *pwrdm;
ad67ef68
PW
206
207 if (!name)
208 return NULL;
209
ad67ef68 210 pwrdm = _pwrdm_lookup(name);
ad67ef68
PW
211
212 return pwrdm;
213}
214
215/**
e909d62a 216 * pwrdm_for_each - call function on each registered clockdomain
ad67ef68
PW
217 * @fn: callback function *
218 *
f0271d65
PW
219 * Call the supplied function @fn for each registered powerdomain.
220 * The callback function @fn can return anything but 0 to bail out
221 * early from the iterator. Returns the last return value of the
222 * callback function, which should be 0 for success or anything else
223 * to indicate failure; or -EINVAL if the function pointer is null.
ad67ef68 224 */
e909d62a
PW
225int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user),
226 void *user)
ad67ef68
PW
227{
228 struct powerdomain *temp_pwrdm;
ad67ef68
PW
229 int ret = 0;
230
231 if (!fn)
232 return -EINVAL;
233
ad67ef68 234 list_for_each_entry(temp_pwrdm, &pwrdm_list, node) {
6199ab26 235 ret = (*fn)(temp_pwrdm, user);
ad67ef68
PW
236 if (ret)
237 break;
238 }
ee894b18
AB
239
240 return ret;
241}
242
8420bb13
PW
243/**
244 * pwrdm_add_clkdm - add a clockdomain to a powerdomain
245 * @pwrdm: struct powerdomain * to add the clockdomain to
246 * @clkdm: struct clockdomain * to associate with a powerdomain
247 *
f0271d65 248 * Associate the clockdomain @clkdm with a powerdomain @pwrdm. This
8420bb13
PW
249 * enables the use of pwrdm_for_each_clkdm(). Returns -EINVAL if
250 * presented with invalid pointers; -ENOMEM if memory could not be allocated;
251 * or 0 upon success.
252 */
253int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
254{
8420bb13
PW
255 int i;
256 int ret = -EINVAL;
257
258 if (!pwrdm || !clkdm)
259 return -EINVAL;
260
261 pr_debug("powerdomain: associating clockdomain %s with powerdomain "
262 "%s\n", clkdm->name, pwrdm->name);
263
8420bb13
PW
264 for (i = 0; i < PWRDM_MAX_CLKDMS; i++) {
265 if (!pwrdm->pwrdm_clkdms[i])
266 break;
267#ifdef DEBUG
268 if (pwrdm->pwrdm_clkdms[i] == clkdm) {
269 ret = -EINVAL;
270 goto pac_exit;
271 }
272#endif
273 }
274
275 if (i == PWRDM_MAX_CLKDMS) {
276 pr_debug("powerdomain: increase PWRDM_MAX_CLKDMS for "
277 "pwrdm %s clkdm %s\n", pwrdm->name, clkdm->name);
278 WARN_ON(1);
279 ret = -ENOMEM;
280 goto pac_exit;
281 }
282
283 pwrdm->pwrdm_clkdms[i] = clkdm;
284
285 ret = 0;
286
287pac_exit:
8420bb13
PW
288 return ret;
289}
290
291/**
292 * pwrdm_del_clkdm - remove a clockdomain from a powerdomain
293 * @pwrdm: struct powerdomain * to add the clockdomain to
294 * @clkdm: struct clockdomain * to associate with a powerdomain
295 *
f0271d65
PW
296 * Dissociate the clockdomain @clkdm from the powerdomain
297 * @pwrdm. Returns -EINVAL if presented with invalid pointers; -ENOENT
298 * if @clkdm was not associated with the powerdomain, or 0 upon
299 * success.
8420bb13
PW
300 */
301int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm)
302{
8420bb13
PW
303 int ret = -EINVAL;
304 int i;
305
306 if (!pwrdm || !clkdm)
307 return -EINVAL;
308
309 pr_debug("powerdomain: dissociating clockdomain %s from powerdomain "
310 "%s\n", clkdm->name, pwrdm->name);
311
8420bb13
PW
312 for (i = 0; i < PWRDM_MAX_CLKDMS; i++)
313 if (pwrdm->pwrdm_clkdms[i] == clkdm)
314 break;
315
316 if (i == PWRDM_MAX_CLKDMS) {
317 pr_debug("powerdomain: clkdm %s not associated with pwrdm "
318 "%s ?!\n", clkdm->name, pwrdm->name);
319 ret = -ENOENT;
320 goto pdc_exit;
321 }
322
323 pwrdm->pwrdm_clkdms[i] = NULL;
324
325 ret = 0;
326
327pdc_exit:
8420bb13
PW
328 return ret;
329}
330
331/**
332 * pwrdm_for_each_clkdm - call function on each clkdm in a pwrdm
333 * @pwrdm: struct powerdomain * to iterate over
334 * @fn: callback function *
335 *
f0271d65
PW
336 * Call the supplied function @fn for each clockdomain in the powerdomain
337 * @pwrdm. The callback function can return anything but 0 to bail
e909d62a
PW
338 * out early from the iterator. Returns -EINVAL if presented with
339 * invalid pointers; or passes along the last return value of the
340 * callback function, which should be 0 for success or anything else
341 * to indicate failure.
8420bb13
PW
342 */
343int pwrdm_for_each_clkdm(struct powerdomain *pwrdm,
344 int (*fn)(struct powerdomain *pwrdm,
345 struct clockdomain *clkdm))
346{
8420bb13
PW
347 int ret = 0;
348 int i;
349
350 if (!fn)
351 return -EINVAL;
352
8420bb13
PW
353 for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++)
354 ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]);
355
8420bb13
PW
356 return ret;
357}
358
ad67ef68
PW
359/**
360 * pwrdm_get_mem_bank_count - get number of memory banks in this powerdomain
361 * @pwrdm: struct powerdomain *
362 *
f0271d65 363 * Return the number of controllable memory banks in powerdomain @pwrdm,
ad67ef68
PW
364 * starting with 1. Returns -EINVAL if the powerdomain pointer is null.
365 */
366int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm)
367{
368 if (!pwrdm)
369 return -EINVAL;
370
371 return pwrdm->banks;
372}
373
374/**
375 * pwrdm_set_next_pwrst - set next powerdomain power state
376 * @pwrdm: struct powerdomain * to set
377 * @pwrst: one of the PWRDM_POWER_* macros
378 *
f0271d65 379 * Set the powerdomain @pwrdm's next power state to @pwrst. The powerdomain
ad67ef68
PW
380 * may not enter this state immediately if the preconditions for this state
381 * have not been satisfied. Returns -EINVAL if the powerdomain pointer is
382 * null or if the power state is invalid for the powerdomin, or returns 0
383 * upon success.
384 */
385int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
386{
f327e07b
RN
387 int ret = -EINVAL;
388
ad67ef68
PW
389 if (!pwrdm)
390 return -EINVAL;
391
392 if (!(pwrdm->pwrsts & (1 << pwrst)))
393 return -EINVAL;
394
395 pr_debug("powerdomain: setting next powerstate for %s to %0x\n",
396 pwrdm->name, pwrst);
397
f327e07b
RN
398 if (arch_pwrdm && arch_pwrdm->pwrdm_set_next_pwrst)
399 ret = arch_pwrdm->pwrdm_set_next_pwrst(pwrdm, pwrst);
ad67ef68 400
f327e07b 401 return ret;
ad67ef68
PW
402}
403
404/**
405 * pwrdm_read_next_pwrst - get next powerdomain power state
406 * @pwrdm: struct powerdomain * to get power state
407 *
f0271d65 408 * Return the powerdomain @pwrdm's next power state. Returns -EINVAL
ad67ef68
PW
409 * if the powerdomain pointer is null or returns the next power state
410 * upon success.
411 */
412int pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
413{
f327e07b
RN
414 int ret = -EINVAL;
415
ad67ef68
PW
416 if (!pwrdm)
417 return -EINVAL;
418
f327e07b
RN
419 if (arch_pwrdm && arch_pwrdm->pwrdm_read_next_pwrst)
420 ret = arch_pwrdm->pwrdm_read_next_pwrst(pwrdm);
421
422 return ret;
ad67ef68
PW
423}
424
425/**
426 * pwrdm_read_pwrst - get current powerdomain power state
427 * @pwrdm: struct powerdomain * to get power state
428 *
f0271d65 429 * Return the powerdomain @pwrdm's current power state. Returns -EINVAL
ad67ef68
PW
430 * if the powerdomain pointer is null or returns the current power state
431 * upon success.
432 */
433int pwrdm_read_pwrst(struct powerdomain *pwrdm)
434{
f327e07b
RN
435 int ret = -EINVAL;
436
ad67ef68
PW
437 if (!pwrdm)
438 return -EINVAL;
439
f327e07b
RN
440 if (arch_pwrdm && arch_pwrdm->pwrdm_read_pwrst)
441 ret = arch_pwrdm->pwrdm_read_pwrst(pwrdm);
442
443 return ret;
ad67ef68
PW
444}
445
446/**
447 * pwrdm_read_prev_pwrst - get previous powerdomain power state
448 * @pwrdm: struct powerdomain * to get previous power state
449 *
f0271d65 450 * Return the powerdomain @pwrdm's previous power state. Returns -EINVAL
ad67ef68
PW
451 * if the powerdomain pointer is null or returns the previous power state
452 * upon success.
453 */
454int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
455{
f327e07b
RN
456 int ret = -EINVAL;
457
ad67ef68
PW
458 if (!pwrdm)
459 return -EINVAL;
460
f327e07b
RN
461 if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_pwrst)
462 ret = arch_pwrdm->pwrdm_read_prev_pwrst(pwrdm);
463
464 return ret;
ad67ef68
PW
465}
466
467/**
468 * pwrdm_set_logic_retst - set powerdomain logic power state upon retention
469 * @pwrdm: struct powerdomain * to set
470 * @pwrst: one of the PWRDM_POWER_* macros
471 *
f0271d65
PW
472 * Set the next power state @pwrst that the logic portion of the
473 * powerdomain @pwrdm will enter when the powerdomain enters retention.
474 * This will be either RETENTION or OFF, if supported. Returns
475 * -EINVAL if the powerdomain pointer is null or the target power
476 * state is not not supported, or returns 0 upon success.
ad67ef68
PW
477 */
478int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
479{
12627578 480 int ret = -EINVAL;
2bc4ef71 481
ad67ef68
PW
482 if (!pwrdm)
483 return -EINVAL;
484
485 if (!(pwrdm->pwrsts_logic_ret & (1 << pwrst)))
486 return -EINVAL;
487
488 pr_debug("powerdomain: setting next logic powerstate for %s to %0x\n",
489 pwrdm->name, pwrst);
490
12627578
RN
491 if (arch_pwrdm && arch_pwrdm->pwrdm_set_logic_retst)
492 ret = arch_pwrdm->pwrdm_set_logic_retst(pwrdm, pwrst);
ad67ef68 493
12627578 494 return ret;
ad67ef68
PW
495}
496
497/**
498 * pwrdm_set_mem_onst - set memory power state while powerdomain ON
499 * @pwrdm: struct powerdomain * to set
500 * @bank: memory bank number to set (0-3)
501 * @pwrst: one of the PWRDM_POWER_* macros
502 *
f0271d65
PW
503 * Set the next power state @pwrst that memory bank @bank of the
504 * powerdomain @pwrdm will enter when the powerdomain enters the ON
505 * state. @bank will be a number from 0 to 3, and represents different
506 * types of memory, depending on the powerdomain. Returns -EINVAL if
507 * the powerdomain pointer is null or the target power state is not
508 * not supported for this memory bank, -EEXIST if the target memory
509 * bank does not exist or is not controllable, or returns 0 upon
510 * success.
ad67ef68
PW
511 */
512int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst)
513{
9b7fc907 514 int ret = -EINVAL;
ad67ef68
PW
515
516 if (!pwrdm)
517 return -EINVAL;
518
519 if (pwrdm->banks < (bank + 1))
520 return -EEXIST;
521
522 if (!(pwrdm->pwrsts_mem_on[bank] & (1 << pwrst)))
523 return -EINVAL;
524
525 pr_debug("powerdomain: setting next memory powerstate for domain %s "
526 "bank %0x while pwrdm-ON to %0x\n", pwrdm->name, bank, pwrst);
527
9b7fc907
RN
528 if (arch_pwrdm && arch_pwrdm->pwrdm_set_mem_onst)
529 ret = arch_pwrdm->pwrdm_set_mem_onst(pwrdm, bank, pwrst);
ad67ef68 530
9b7fc907 531 return ret;
ad67ef68
PW
532}
533
534/**
535 * pwrdm_set_mem_retst - set memory power state while powerdomain in RET
536 * @pwrdm: struct powerdomain * to set
537 * @bank: memory bank number to set (0-3)
538 * @pwrst: one of the PWRDM_POWER_* macros
539 *
f0271d65
PW
540 * Set the next power state @pwrst that memory bank @bank of the
541 * powerdomain @pwrdm will enter when the powerdomain enters the
542 * RETENTION state. Bank will be a number from 0 to 3, and represents
543 * different types of memory, depending on the powerdomain. @pwrst
544 * will be either RETENTION or OFF, if supported. 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
548 * success.
ad67ef68
PW
549 */
550int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst)
551{
9b7fc907 552 int ret = -EINVAL;
ad67ef68
PW
553
554 if (!pwrdm)
555 return -EINVAL;
556
557 if (pwrdm->banks < (bank + 1))
558 return -EEXIST;
559
560 if (!(pwrdm->pwrsts_mem_ret[bank] & (1 << pwrst)))
561 return -EINVAL;
562
563 pr_debug("powerdomain: setting next memory powerstate for domain %s "
564 "bank %0x while pwrdm-RET to %0x\n", pwrdm->name, bank, pwrst);
565
9b7fc907
RN
566 if (arch_pwrdm && arch_pwrdm->pwrdm_set_mem_retst)
567 ret = arch_pwrdm->pwrdm_set_mem_retst(pwrdm, bank, pwrst);
ad67ef68 568
9b7fc907 569 return ret;
ad67ef68
PW
570}
571
572/**
573 * pwrdm_read_logic_pwrst - get current powerdomain logic retention power state
574 * @pwrdm: struct powerdomain * to get current logic retention power state
575 *
f0271d65
PW
576 * Return the power state that the logic portion of powerdomain @pwrdm
577 * will enter when the powerdomain enters retention. Returns -EINVAL
578 * if the powerdomain pointer is null or returns the logic retention
579 * power state upon success.
ad67ef68
PW
580 */
581int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
582{
12627578
RN
583 int ret = -EINVAL;
584
ad67ef68
PW
585 if (!pwrdm)
586 return -EINVAL;
587
12627578
RN
588 if (arch_pwrdm && arch_pwrdm->pwrdm_read_logic_pwrst)
589 ret = arch_pwrdm->pwrdm_read_logic_pwrst(pwrdm);
590
591 return ret;
ad67ef68
PW
592}
593
594/**
595 * pwrdm_read_prev_logic_pwrst - get previous powerdomain logic power state
596 * @pwrdm: struct powerdomain * to get previous logic power state
597 *
f0271d65
PW
598 * Return the powerdomain @pwrdm's previous logic power state. Returns
599 * -EINVAL if the powerdomain pointer is null or returns the previous
600 * logic power state upon success.
ad67ef68
PW
601 */
602int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm)
603{
12627578
RN
604 int ret = -EINVAL;
605
ad67ef68
PW
606 if (!pwrdm)
607 return -EINVAL;
608
12627578
RN
609 if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_logic_pwrst)
610 ret = arch_pwrdm->pwrdm_read_prev_logic_pwrst(pwrdm);
611
612 return ret;
ad67ef68
PW
613}
614
1e3d0d2b
TG
615/**
616 * pwrdm_read_logic_retst - get next powerdomain logic power state
617 * @pwrdm: struct powerdomain * to get next logic power state
618 *
619 * Return the powerdomain pwrdm's logic power state. Returns -EINVAL
620 * if the powerdomain pointer is null or returns the next logic
621 * power state upon success.
622 */
623int pwrdm_read_logic_retst(struct powerdomain *pwrdm)
624{
12627578
RN
625 int ret = -EINVAL;
626
1e3d0d2b
TG
627 if (!pwrdm)
628 return -EINVAL;
629
12627578
RN
630 if (arch_pwrdm && arch_pwrdm->pwrdm_read_logic_retst)
631 ret = arch_pwrdm->pwrdm_read_logic_retst(pwrdm);
632
633 return ret;
1e3d0d2b
TG
634}
635
ad67ef68
PW
636/**
637 * pwrdm_read_mem_pwrst - get current memory bank power state
638 * @pwrdm: struct powerdomain * to get current memory bank power state
639 * @bank: memory bank number (0-3)
640 *
f0271d65
PW
641 * Return the powerdomain @pwrdm's current memory power state for bank
642 * @bank. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
ad67ef68
PW
643 * the target memory bank does not exist or is not controllable, or
644 * returns the current memory power state upon success.
645 */
646int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
647{
9b7fc907 648 int ret = -EINVAL;
ad67ef68
PW
649
650 if (!pwrdm)
9b7fc907 651 return ret;
ad67ef68
PW
652
653 if (pwrdm->banks < (bank + 1))
9b7fc907 654 return ret;
ad67ef68 655
3863c74b
TG
656 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
657 bank = 1;
658
9b7fc907
RN
659 if (arch_pwrdm && arch_pwrdm->pwrdm_read_mem_pwrst)
660 ret = arch_pwrdm->pwrdm_read_mem_pwrst(pwrdm, bank);
ad67ef68 661
9b7fc907 662 return ret;
ad67ef68
PW
663}
664
665/**
666 * pwrdm_read_prev_mem_pwrst - get previous memory bank power state
667 * @pwrdm: struct powerdomain * to get previous memory bank power state
668 * @bank: memory bank number (0-3)
669 *
f0271d65
PW
670 * Return the powerdomain @pwrdm's previous memory power state for
671 * bank @bank. Returns -EINVAL if the powerdomain pointer is null,
672 * -EEXIST if the target memory bank does not exist or is not
673 * controllable, or returns the previous memory power state upon
674 * success.
ad67ef68
PW
675 */
676int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
677{
9b7fc907 678 int ret = -EINVAL;
ad67ef68
PW
679
680 if (!pwrdm)
9b7fc907 681 return ret;
ad67ef68
PW
682
683 if (pwrdm->banks < (bank + 1))
9b7fc907 684 return ret;
ad67ef68 685
3863c74b
TG
686 if (pwrdm->flags & PWRDM_HAS_MPU_QUIRK)
687 bank = 1;
688
9b7fc907
RN
689 if (arch_pwrdm && arch_pwrdm->pwrdm_read_prev_mem_pwrst)
690 ret = arch_pwrdm->pwrdm_read_prev_mem_pwrst(pwrdm, bank);
ad67ef68 691
9b7fc907 692 return ret;
ad67ef68
PW
693}
694
1e3d0d2b
TG
695/**
696 * pwrdm_read_mem_retst - get next memory bank power state
697 * @pwrdm: struct powerdomain * to get mext memory bank power state
698 * @bank: memory bank number (0-3)
699 *
700 * Return the powerdomain pwrdm's next memory power state for bank
701 * x. Returns -EINVAL if the powerdomain pointer is null, -EEXIST if
702 * the target memory bank does not exist or is not controllable, or
703 * returns the next memory power state upon success.
704 */
705int pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
706{
9b7fc907 707 int ret = -EINVAL;
1e3d0d2b
TG
708
709 if (!pwrdm)
9b7fc907 710 return ret;
1e3d0d2b
TG
711
712 if (pwrdm->banks < (bank + 1))
9b7fc907 713 return ret;
1e3d0d2b 714
9b7fc907
RN
715 if (arch_pwrdm && arch_pwrdm->pwrdm_read_mem_retst)
716 ret = arch_pwrdm->pwrdm_read_mem_retst(pwrdm, bank);
1e3d0d2b 717
9b7fc907 718 return ret;
1e3d0d2b
TG
719}
720
ad67ef68
PW
721/**
722 * pwrdm_clear_all_prev_pwrst - clear previous powerstate register for a pwrdm
723 * @pwrdm: struct powerdomain * to clear
724 *
f0271d65
PW
725 * Clear the powerdomain's previous power state register @pwrdm.
726 * Clears the entire register, including logic and memory bank
727 * previous power states. Returns -EINVAL if the powerdomain pointer
728 * is null, or returns 0 upon success.
ad67ef68
PW
729 */
730int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
731{
9b7fc907
RN
732 int ret = -EINVAL;
733
ad67ef68 734 if (!pwrdm)
9b7fc907 735 return ret;
ad67ef68
PW
736
737 /*
738 * XXX should get the powerdomain's current state here;
739 * warn & fail if it is not ON.
740 */
741
742 pr_debug("powerdomain: clearing previous power state reg for %s\n",
743 pwrdm->name);
744
9b7fc907
RN
745 if (arch_pwrdm && arch_pwrdm->pwrdm_clear_all_prev_pwrst)
746 ret = arch_pwrdm->pwrdm_clear_all_prev_pwrst(pwrdm);
ad67ef68 747
9b7fc907 748 return ret;
ad67ef68
PW
749}
750
0b7cbfb5
PW
751/**
752 * pwrdm_enable_hdwr_sar - enable automatic hardware SAR for a pwrdm
753 * @pwrdm: struct powerdomain *
754 *
755 * Enable automatic context save-and-restore upon power state change
f0271d65
PW
756 * for some devices in the powerdomain @pwrdm. Warning: this only
757 * affects a subset of devices in a powerdomain; check the TRM
758 * closely. Returns -EINVAL if the powerdomain pointer is null or if
759 * the powerdomain does not support automatic save-and-restore, or
760 * returns 0 upon success.
0b7cbfb5
PW
761 */
762int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm)
763{
9b7fc907
RN
764 int ret = -EINVAL;
765
0b7cbfb5 766 if (!pwrdm)
9b7fc907 767 return ret;
0b7cbfb5
PW
768
769 if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR))
9b7fc907 770 return ret;
0b7cbfb5
PW
771
772 pr_debug("powerdomain: %s: setting SAVEANDRESTORE bit\n",
773 pwrdm->name);
774
9b7fc907
RN
775 if (arch_pwrdm && arch_pwrdm->pwrdm_enable_hdwr_sar)
776 ret = arch_pwrdm->pwrdm_enable_hdwr_sar(pwrdm);
0b7cbfb5 777
9b7fc907 778 return ret;
0b7cbfb5
PW
779}
780
781/**
782 * pwrdm_disable_hdwr_sar - disable automatic hardware SAR for a pwrdm
783 * @pwrdm: struct powerdomain *
784 *
785 * Disable automatic context save-and-restore upon power state change
f0271d65
PW
786 * for some devices in the powerdomain @pwrdm. Warning: this only
787 * affects a subset of devices in a powerdomain; check the TRM
788 * closely. Returns -EINVAL if the powerdomain pointer is null or if
789 * the powerdomain does not support automatic save-and-restore, or
790 * returns 0 upon success.
0b7cbfb5
PW
791 */
792int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm)
793{
9b7fc907
RN
794 int ret = -EINVAL;
795
0b7cbfb5 796 if (!pwrdm)
9b7fc907 797 return ret;
0b7cbfb5
PW
798
799 if (!(pwrdm->flags & PWRDM_HAS_HDWR_SAR))
9b7fc907 800 return ret;
0b7cbfb5
PW
801
802 pr_debug("powerdomain: %s: clearing SAVEANDRESTORE bit\n",
803 pwrdm->name);
804
9b7fc907
RN
805 if (arch_pwrdm && arch_pwrdm->pwrdm_disable_hdwr_sar)
806 ret = arch_pwrdm->pwrdm_disable_hdwr_sar(pwrdm);
0b7cbfb5 807
9b7fc907 808 return ret;
0b7cbfb5
PW
809}
810
811/**
812 * pwrdm_has_hdwr_sar - test whether powerdomain supports hardware SAR
813 * @pwrdm: struct powerdomain *
814 *
f0271d65 815 * Returns 1 if powerdomain @pwrdm supports hardware save-and-restore
0b7cbfb5
PW
816 * for some devices, or 0 if it does not.
817 */
818bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm)
819{
820 return (pwrdm && pwrdm->flags & PWRDM_HAS_HDWR_SAR) ? 1 : 0;
821}
822
90dbc7b0
RN
823/**
824 * pwrdm_set_lowpwrstchange - Request a low power state change
825 * @pwrdm: struct powerdomain *
826 *
827 * Allows a powerdomain to transtion to a lower power sleep state
828 * from an existing sleep state without waking up the powerdomain.
829 * Returns -EINVAL if the powerdomain pointer is null or if the
830 * powerdomain does not support LOWPOWERSTATECHANGE, or returns 0
831 * upon success.
832 */
833int pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm)
834{
9b7fc907
RN
835 int ret = -EINVAL;
836
90dbc7b0
RN
837 if (!pwrdm)
838 return -EINVAL;
839
840 if (!(pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE))
841 return -EINVAL;
842
843 pr_debug("powerdomain: %s: setting LOWPOWERSTATECHANGE bit\n",
844 pwrdm->name);
845
9b7fc907
RN
846 if (arch_pwrdm && arch_pwrdm->pwrdm_set_lowpwrstchange)
847 ret = arch_pwrdm->pwrdm_set_lowpwrstchange(pwrdm);
90dbc7b0 848
9b7fc907 849 return ret;
90dbc7b0
RN
850}
851
ad67ef68
PW
852/**
853 * pwrdm_wait_transition - wait for powerdomain power transition to finish
854 * @pwrdm: struct powerdomain * to wait for
855 *
f0271d65 856 * If the powerdomain @pwrdm is in the process of a state transition,
ad67ef68
PW
857 * spin until it completes the power transition, or until an iteration
858 * bailout value is reached. Returns -EINVAL if the powerdomain
859 * pointer is null, -EAGAIN if the bailout value was reached, or
860 * returns 0 upon success.
861 */
862int pwrdm_wait_transition(struct powerdomain *pwrdm)
863{
9b7fc907 864 int ret = -EINVAL;
ad67ef68
PW
865
866 if (!pwrdm)
867 return -EINVAL;
868
9b7fc907
RN
869 if (arch_pwrdm && arch_pwrdm->pwrdm_wait_transition)
870 ret = arch_pwrdm->pwrdm_wait_transition(pwrdm);
ad67ef68 871
9b7fc907 872 return ret;
ad67ef68
PW
873}
874
ba20bb12
PDS
875int pwrdm_state_switch(struct powerdomain *pwrdm)
876{
877 return _pwrdm_state_switch(pwrdm, PWRDM_STATE_NOW);
878}
879
880int pwrdm_clkdm_state_switch(struct clockdomain *clkdm)
881{
882 if (clkdm != NULL && clkdm->pwrdm.ptr != NULL) {
883 pwrdm_wait_transition(clkdm->pwrdm.ptr);
884 return pwrdm_state_switch(clkdm->pwrdm.ptr);
885 }
886
887 return -EINVAL;
888}
ba20bb12
PDS
889
890int pwrdm_pre_transition(void)
891{
6199ab26 892 pwrdm_for_each(_pwrdm_pre_transition_cb, NULL);
ba20bb12
PDS
893 return 0;
894}
895
896int pwrdm_post_transition(void)
897{
6199ab26 898 pwrdm_for_each(_pwrdm_post_transition_cb, NULL);
ba20bb12
PDS
899 return 0;
900}
This page took 0.219194 seconds and 5 git commands to generate.