• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  ****************************************************************************************
17  *
18  * @file sleep_api.h
19  *
20  * @brief SLEEP utility functions
21  *
22  ****************************************************************************************
23  */
24 
25 #ifndef _SLEEP_API_H_
26 #define _SLEEP_API_H_
27 
28 #include "plf.h"
29 
30 /*
31  * ENUMS
32  ****************************************************************************************
33  */
34 typedef enum {
35     PM_LEVEL_ACTIVE       = 0,  // cpu active/wfi,              peripheral active,              dig_top power up
36     PM_LEVEL_LIGHT_SLEEP  = 1,  // cpu active/wfi/clock gating, peripheral active/clock gating, dig_top power up
37     PM_LEVEL_DEEP_SLEEP   = 2,  // cpu active/wfi/power down,   peripheral active/power down,   dig_top power up
38     PM_LEVEL_HIBERNATE    = 3,  // cpu active/wfi/power down,   peripheral active/power down,   dig_top power up/power down
39     PM_LEVEL_ULP_0        = 4,  // dig_top power up/power down, aon_sys power up/power down, pmic power up
40     PM_LEVEL_ULP_1        = 5,  // dig_top power up/power down, aon_sys power up/power down, pmic power up/deep sleep
41     PM_LEVEL_POWER_OFF    = 6,  // dig_top power up/power down, aon_sys power up/power down, pmic power up/power down
42     PM_LEVEL_LEVEL_NUM
43 } POWER_MODE_LEVEL_T;
44 
45 typedef enum {
46     WAKESRC_UART    = 0,
47     WAKESRC_GPIO    = 1,
48     WAKESRC_TIMER   = 2,
49     WAKESRC_NUM_MAX
50 } WAKEUP_SOURCE_T;
51 
52 typedef enum {
53     SLEEP_PREVENT_WPAS_ASSOC    = (0x1UL << 0),
54     SLEEP_PREVENT_LWIP_DHCP     = (0x1UL << 1),
55     SLEEP_PREVENT_MSG           = (0x1UL << 2),
56 } SLEEP_PREVENT_T;
57 
58 typedef struct {
59     void (*set_sleep_level) (POWER_MODE_LEVEL_T level);
60     int  (*is_sleep_allowed)(void);
61     void (*indicate_sleep) (POWER_MODE_LEVEL_T level);
62     void (*indicate_wakeup) (void);
63 } sleep_entry_t;
64 
65 /**
66  * register sleep entry
67  */
68 void sleep_entry_register(sleep_entry_t *entry);
69 
70 #if PLF_PMIC
71 /**
72  * set pmic dcdc vcore
73  */
74 void pmic_dcdc_vcore_set(POWER_MODE_LEVEL_T level);
75 void pmic_dcdc_rf_set(POWER_MODE_LEVEL_T level);
76 void pmic_ldo_vrtc09_set(POWER_MODE_LEVEL_T level);
77 void pmic_ldo_vcore09_set(POWER_MODE_LEVEL_T level);
78 
79 /**
80  * set pmic sleep level
81  */
82 void pmic_sleep_level_set(POWER_MODE_LEVEL_T level);
83 #endif
84 
85 /**
86  * sleep manager
87  */
88 int sleep_management(unsigned int time_ms);
89 
90 /**
91  * get sleep level
92  */
93 POWER_MODE_LEVEL_T sleep_level_get(void);
94 
95 /**
96  * set sleep level
97  */
98 void sleep_level_set(POWER_MODE_LEVEL_T level);
99 
100 /**
101  * get sleep prevent bits
102  */
103 unsigned int sleep_prevent_get(void);
104 
105 /**
106  * set sleep prevent bits
107  */
108 void sleep_prevent_set(SLEEP_PREVENT_T flag);
109 
110 /**
111  * clear sleep prevent bits
112  */
113 void sleep_prevent_clr(SLEEP_PREVENT_T flag);
114 
115 /**
116  * allow user sleep or not
117  */
118 void user_sleep_allow(int yes);
119 
120 /**
121  * indicate powerkey is pressed
122  */
123 void user_powerkey_pressed(void);
124 
125 /**
126  * set user wakeup source
127  * @param src  The wakeup source type, UART/GPIO/TIMER supported
128  * @param en   To enable or not, non-zero means enable
129  * @param src  The input argument, GPIO index or time interval
130  */
131 void user_sleep_wakesrc_set(WAKEUP_SOURCE_T src, int en, unsigned int arg);
132 
133 void sleep_data_save(void);
134 
135 void sleep_data_restore(void);
136 
137 void sys_wakeup_indicate(void);
138 
139 #endif /* _SLEEP_API_H_ */
140