1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include "cc_pal_types.h"
8 
9 int32_t g_pmCntr;
10 
CC_PalPowerSaveModeInit(void)11 void CC_PalPowerSaveModeInit(void)
12 {
13     g_pmCntr = 0;
14     return;
15 }
16 
CC_PalPowerSaveModeStatus(void)17 int32_t CC_PalPowerSaveModeStatus(void)
18 {
19     return g_pmCntr;
20 }
21 
CC_PalPowerSaveModeSelect(CCBool isPowerSaveMode)22 CCError_t CC_PalPowerSaveModeSelect(CCBool isPowerSaveMode)
23 {
24     CCError_t rc = CC_OK;
25     switch (isPowerSaveMode){
26     case CC_FALSE:
27          __atomic_fetch_add(&g_pmCntr, 1, __ATOMIC_SEQ_CST);
28         break;
29     case CC_TRUE:
30         __atomic_fetch_sub(&g_pmCntr, 1, __ATOMIC_SEQ_CST);
31         break;
32     default:
33         return -1;
34     }
35 
36     if(g_pmCntr == 0){
37         /* once the counter is zero,
38          * an external callback shall be called to notify the PMU that ARM Cerberus might be powered down. */
39     }
40 
41     if(g_pmCntr < 0 ){
42         /* illegal state - exit with error */
43         return 1;
44     }
45 
46     return rc;
47 }
48