Developer World
Spresense SDK Library v3.2.0-ebc0364
pm.h
Go to the documentation of this file.
1/****************************************************************************
2 * arch/arm/include/cxd56xx/pm.h
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership. The
7 * ASF licenses this file to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance with the
9 * License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 * License for the specific language governing permissions and limitations
17 * under the License.
18 *
19 ****************************************************************************/
24#ifndef __ARCH_ARM_INCLUDE_CXD56XX_PM_H
25#define __ARCH_ARM_INCLUDE_CXD56XX_PM_H
26
27/****************************************************************************
28 * Included Files
29 ****************************************************************************/
30
31#include <nuttx/config.h>
32#include <nuttx/queue.h>
33
34/****************************************************************************
35 * Pre-processor Prototypes
36 ****************************************************************************/
37
38/* Boot Cause definitions */
39
40#define PM_BOOT_POR_NORMAL (0x00000000ul) /* Power On Reset like as battery attached */
41#define PM_BOOT_POR_DEADBATT (0x00000001ul) /* Battery charged from DeadBattery state */
42#define PM_BOOT_WDT_REBOOT (0x00000002ul) /* System WDT expired or Explicitly Self Reboot */
43#define PM_BOOT_WDT_RESET (0x00000004ul) /* Chip WDT expired (might be used in HV-only system) */
44#define PM_BOOT_DEEP_WKUPL (0x00000008ul) /* In DeepSleep state, Detected WKUPL signal */
45#define PM_BOOT_DEEP_WKUPS (0x00000010ul) /* In DeepSleep state, Detected WKUPS signal */
46#define PM_BOOT_DEEP_RTC (0x00000020ul) /* In DeepSleep state, RTC Alarm expired */
47#define PM_BOOT_DEEP_USB_ATTACH (0x00000040ul) /* In DeepSleep state, USB Connected */
48#define PM_BOOT_DEEP_OTHERS (0x00000080ul) /* In DeepSleep state, Reserved others cause occurred */
49#define PM_BOOT_COLD_SCU_INT (0x00000100ul) /* In ColdSleep state, Detected SCU Interrupt */
50#define PM_BOOT_COLD_RTC (0x00001e00ul) /* In ColdSleep state, RTC Alarm Interrupt */
51#define PM_BOOT_COLD_RTC_ALM0 (0x00000200ul) /* In ColdSleep state, RTC Alarm0 expired */
52#define PM_BOOT_COLD_RTC_ALM1 (0x00000400ul) /* In ColdSleep state, RTC Alarm1 expired */
53#define PM_BOOT_COLD_RTC_ALM2 (0x00000800ul) /* In ColdSleep state, RTC Alarm2 expired */
54#define PM_BOOT_COLD_RTC_ALMERR (0x00001000ul) /* In ColdSleep state, RTC Alarm Error occurred */
55#define PM_BOOT_COLD_GPIO (0x0fff0000ul) /* In ColdSleep state, Detected GPIO interrupt */
56#define PM_BOOT_COLD_SEN_INT (0x10000000ul) /* In ColdSleep state, Detected SEN_INT Interrupt */
57#define PM_BOOT_COLD_PMIC_INT (0x20000000ul) /* In ColdSleep state, Detected PMIC Interrupt */
58#define PM_BOOT_COLD_USB_DETACH (0x40000000ul) /* In ColdSleep state, USB Disconnected */
59#define PM_BOOT_COLD_USB_ATTACH (0x80000000ul) /* In ColdSleep state, USB Connected */
60
61/* SRAM power status definitions */
62
63#define PMCMD_RAM_OFF 0 /* Power off */
64#define PMCMD_RAM_RET 1 /* Retention */
65#define PMCMD_RAM_ON 3 /* Power on */
66
67/* FrequencyLock request flag definitions */
68
69#define PM_CPUFREQLOCK_FLAG_HV (0x0001) /* request HV */
70#define PM_CPUFREQLOCK_FLAG_LV (0x4000) /* request LV */
71#define PM_CPUFREQLOCK_FLAG_HOLD (0x8000) /* hold the current frequency */
72
73/* FrequencyLock identifier tag helper macro function */
74
75#define PM_CPUFREQLOCK_TAG(prefix1, prefix2, num) \
76 (((prefix1) << 24) + ((prefix2) << 16) + (num))
77
78/* FrequencyLock initializer macro function */
79
80# define PM_CPUFREQLOCK_INIT(_tag, _flag) \
81{ \
82 .count = 0, \
83 .info = _tag, \
84 .flag = _flag, \
85}
86
87/* WakeLock identifier tag helper macro function */
88
89#define PM_CPUWAKELOCK_TAG(prefix1, prefix2, num) \
90 (((prefix1) << 24) + ((prefix2) << 16) + (num))
91
92/* WakeLock initializer macro function */
93
94#define PM_CPUWAKELOCK_INIT(_tag) \
95{ \
96 .count = 0, \
97 .info = _tag, \
98}
99
100/****************************************************************************
101 * Public Types
102 ****************************************************************************/
103
104/* slee mode definitions */
105
106enum pm_sleepmode_e
107{
108 PM_SLEEP_DEEP,
109 PM_SLEEP_COLD,
110};
111
112/* FreqLock structure */
113
115{
116 struct sq_entry_s sq_entry;
117 int count;
118 uint32_t info;
119 int flag;
120};
121
122/* WakeLock structure */
123
125{
126 struct sq_entry_s sq_entry;
127 int count;
128 uint32_t info;
129};
130
131/* Prototypes for pmic notify */
132
133enum pmic_notify_e
134{
135 PMIC_NOTIFY_ALARM = 0,
136 PMIC_NOTIFY_WKUPS,
137 PMIC_NOTIFY_WKUPL,
138 PMIC_NOTIFY_LOWBATT,
139 PMIC_NOTIFY_MAX
140};
141
142/* callback function for pmic notify */
143
144typedef void (*pmic_notify_t)(void *arg);
145
146/****************************************************************************
147 * Public Function Prototypes
148 ****************************************************************************/
149
150#ifdef __cplusplus
151#define EXTERN extern "C"
152extern "C"
153{
154#else
155#define EXTERN extern
156#endif
157
158/****************************************************************************
159 * Name: up_pmstatdump
160 *
161 * Description:
162 * Print architecture specific power status
163 *
164 ****************************************************************************/
165
166int up_pmramctrl(int cmd, uintptr_t addr, size_t size);
167
168#ifdef CONFIG_CXD56_PM_DEBUG_INFO
169/****************************************************************************
170 * Name: up_pmstatdump
171 *
172 * Description:
173 * Print architecture specific power status
174 *
175 ****************************************************************************/
176
177void up_pmstatdump(void);
178#else
179# define up_pmstatdump()
180#endif
181
182/****************************************************************************
183 * Name: up_pm_acquire_freqlock
184 *
185 * Description:
186 * Acquire the specified freqlock. If the higher freqlock is acquired, the
187 * system can clockup until it is released.
188 *
189 * Parameter:
190 * lock - the pointer of a wakelock variable
191 *
192 ****************************************************************************/
193
194void up_pm_acquire_freqlock(struct pm_cpu_freqlock_s *lock);
195
196/****************************************************************************
197 * Name: up_pm_release_freqlock
198 *
199 * Description:
200 * Release the specified freqlock. If the freqlock are released, the system
201 * can drop to the lower clock mode for power saving.
202 *
203 * Parameter:
204 * lock - the pointer of a freqlock variable
205 *
206 ****************************************************************************/
207
208void up_pm_release_freqlock(struct pm_cpu_freqlock_s *lock);
209
210/****************************************************************************
211 * Name: up_pm_get_freqlock_count
212 *
213 * Description:
214 * Get the locked count of the specified freqlock
215 *
216 * Parameter:
217 * lock - the pointer of a freqlock variable
218 *
219 * Return:
220 * the locked count of the specified freqlock
221 *
222 ****************************************************************************/
223
224int up_pm_get_freqlock_count(struct pm_cpu_freqlock_s *lock);
225
226/****************************************************************************
227 * Name: up_pm_acquire_wakelock
228 *
229 * Description:
230 * Acquire the specified wakelock. If any wakelock is acquired, CPU can't
231 * enter to the hot sleep state.
232 *
233 * Parameter:
234 * lock - the pointer of a wakelock variable
235 *
236 ****************************************************************************/
237
238void up_pm_acquire_wakelock(struct pm_cpu_wakelock_s *lock);
239
240/****************************************************************************
241 * Name: up_pm_release_wakelock
242 *
243 * Description:
244 * Release the specified wakelock. If all of the wakelock are released,
245 * CPU can enter to the hot sleep state.
246 *
247 * Parameter:
248 * lock - the pointer of a wakelock variable
249 *
250 ****************************************************************************/
251
252void up_pm_release_wakelock(struct pm_cpu_wakelock_s *lock);
253
254/****************************************************************************
255 * Name: up_pm_count_acquire_wakelock
256 *
257 * Description:
258 * Count the total number of wakelock
259 *
260 * Return:
261 * the total number of wakelock
262 *
263 ****************************************************************************/
264
265int up_pm_count_acquire_wakelock(void);
266
267/****************************************************************************
268 * Name: up_pm_get_bootcause
269 *
270 * Description:
271 * Get the system boot cause. This boot cause indicates the cause why the
272 * system is launched from the state of power-off, deep sleep or cold
273 * sleep. Each boot cause is defined as PM_BOOT_XXX.
274 *
275 * Return:
276 * Boot cause
277 *
278 ****************************************************************************/
279
280uint32_t up_pm_get_bootcause(void);
281
282/****************************************************************************
283 * Name: up_pm_get_bootmask
284 *
285 * Description:
286 * Get the system boot mask. This boot mask indicates whether the specified
287 * bit is enabled or not as the boot cause. If a bit of boot mask is set,
288 * the boot cause is enabled. Each boot mask is defined as PM_BOOT_XXX.
289 *
290 * Return:
291 * Boot mask
292 *
293 ****************************************************************************/
294
295uint32_t up_pm_get_bootmask(void);
296
297/****************************************************************************
298 * Name: up_pm_set_bootmask
299 *
300 * Description:
301 * Enable the boot cause of the specified bit.
302 *
303 * Parameter:
304 * mask - OR of Boot mask defined as PM_BOOT_XXX
305 *
306 * Return:
307 * Updated boot mask
308 *
309 ****************************************************************************/
310
311uint32_t up_pm_set_bootmask(uint32_t mask);
312
313/****************************************************************************
314 * Name: up_pm_clr_bootmask
315 *
316 * Description:
317 * Disable the boot cause of the specified bit.
318 *
319 * Parameter:
320 * mask - OR of Boot mask defined as PM_BOOT_XXX
321 *
322 * Return:
323 * Updated boot mask
324 *
325 ****************************************************************************/
326
327uint32_t up_pm_clr_bootmask(uint32_t mask);
328
329/****************************************************************************
330 * Name: up_pm_sleep
331 *
332 * Description:
333 * Enter sleep mode. This function never returns.
334 *
335 * Parameter:
336 * mode - PM_SLEEP_DEEP or PM_SLEEP_COLD
337 *
338 ****************************************************************************/
339
340int up_pm_sleep(enum pm_sleepmode_e mode);
341
342/****************************************************************************
343 * Name: up_pm_reboot
344 *
345 * Description:
346 * System reboot. This function never returns.
347 *
348 ****************************************************************************/
349
350int up_pm_reboot(void);
351
352/****************************************************************************
353 * Name: up_pmic_set_notify
354 *
355 * Description:
356 * Register a callback for pmic interrupt.
357 *
358 * Input Parameter:
359 * kind - A kind of pmic interrupt defined as pmic_notify_e
360 * cb - A callback function for a kind of pmic interrupt
361 *
362 * Returned Value:
363 * Return 0 on success. Otherwise, return a negated errno.
364 *
365 ****************************************************************************/
366
367#ifdef CONFIG_CXD56_PMIC_INT
368int up_pmic_set_notify(int kind, pmic_notify_t cb);
369#else
370# define up_pmic_set_notify(kind, cb)
371#endif
372
373#undef EXTERN
374#ifdef __cplusplus
375}
376#endif
377
378#endif /* __ARCH_ARM_INCLUDE_CXD56XX_PM_H */
Definition: pm.h:115
Definition: pm.h:125