Developer World
Spresense SDK Library v3.3.0-375c679
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/* Get bootmask from GPIO IRQ number */
62
63#define PM_BOOT_GPIO_MASK(irq) (1 << ((irq) - CXD56_IRQ_EXDEVICE_0 + 16))
64
65/* SRAM power status definitions */
66
67#define PMCMD_RAM_OFF 0 /* Power off */
68#define PMCMD_RAM_RET 1 /* Retention */
69#define PMCMD_RAM_ON 3 /* Power on */
70
71/* FrequencyLock request flag definitions */
72
73#define PM_CPUFREQLOCK_FLAG_HV (0x0001) /* request HV */
74#define PM_CPUFREQLOCK_FLAG_LV (0x4000) /* request LV */
75#define PM_CPUFREQLOCK_FLAG_HOLD (0x8000) /* hold the current frequency */
76
77/* FrequencyLock identifier tag helper macro function */
78
79#define PM_CPUFREQLOCK_TAG(prefix1, prefix2, num) \
80 (((prefix1) << 24) + ((prefix2) << 16) + (num))
81
82/* FrequencyLock initializer macro function */
83
84# define PM_CPUFREQLOCK_INIT(_tag, _flag) \
85{ \
86 .count = 0, \
87 .info = _tag, \
88 .flag = _flag, \
89}
90
91/* WakeLock identifier tag helper macro function */
92
93#define PM_CPUWAKELOCK_TAG(prefix1, prefix2, num) \
94 (((prefix1) << 24) + ((prefix2) << 16) + (num))
95
96/* WakeLock initializer macro function */
97
98#define PM_CPUWAKELOCK_INIT(_tag) \
99{ \
100 .count = 0, \
101 .info = _tag, \
102}
103
104/****************************************************************************
105 * Public Types
106 ****************************************************************************/
107
108/* slee mode definitions */
109
110enum pm_sleepmode_e
111{
112 PM_SLEEP_DEEP,
113 PM_SLEEP_COLD,
114};
115
116/* FreqLock structure */
117
119{
120 struct sq_entry_s sq_entry;
121 int count;
122 uint32_t info;
123 int flag;
124};
125
126/* WakeLock structure */
127
129{
130 struct sq_entry_s sq_entry;
131 int count;
132 uint32_t info;
133};
134
135/* Prototypes for pmic notify */
136
137enum pmic_notify_e
138{
139 PMIC_NOTIFY_ALARM = 0,
140 PMIC_NOTIFY_WKUPS,
141 PMIC_NOTIFY_WKUPL,
142 PMIC_NOTIFY_LOWBATT,
143 PMIC_NOTIFY_MAX
144};
145
146/* callback function for pmic notify */
147
148typedef void (*pmic_notify_t)(void *arg);
149
150/****************************************************************************
151 * Public Function Prototypes
152 ****************************************************************************/
153
154#ifdef __cplusplus
155#define EXTERN extern "C"
156extern "C"
157{
158#else
159#define EXTERN extern
160#endif
161
162/****************************************************************************
163 * Name: up_pmstatdump
164 *
165 * Description:
166 * Print architecture specific power status
167 *
168 ****************************************************************************/
169
170int up_pmramctrl(int cmd, uintptr_t addr, size_t size);
171
172#ifdef CONFIG_CXD56_PM_DEBUG_INFO
173/****************************************************************************
174 * Name: up_pmstatdump
175 *
176 * Description:
177 * Print architecture specific power status
178 *
179 ****************************************************************************/
180
181void up_pmstatdump(void);
182#else
183# define up_pmstatdump()
184#endif
185
186/****************************************************************************
187 * Name: up_pm_acquire_freqlock
188 *
189 * Description:
190 * Acquire the specified freqlock. If the higher freqlock is acquired, the
191 * system can clockup until it is released.
192 *
193 * Parameter:
194 * lock - the pointer of a wakelock variable
195 *
196 ****************************************************************************/
197
198void up_pm_acquire_freqlock(struct pm_cpu_freqlock_s *lock);
199
200/****************************************************************************
201 * Name: up_pm_release_freqlock
202 *
203 * Description:
204 * Release the specified freqlock. If the freqlock are released, the system
205 * can drop to the lower clock mode for power saving.
206 *
207 * Parameter:
208 * lock - the pointer of a freqlock variable
209 *
210 ****************************************************************************/
211
212void up_pm_release_freqlock(struct pm_cpu_freqlock_s *lock);
213
214/****************************************************************************
215 * Name: up_pm_get_freqlock_count
216 *
217 * Description:
218 * Get the locked count of the specified freqlock
219 *
220 * Parameter:
221 * lock - the pointer of a freqlock variable
222 *
223 * Return:
224 * the locked count of the specified freqlock
225 *
226 ****************************************************************************/
227
228int up_pm_get_freqlock_count(struct pm_cpu_freqlock_s *lock);
229
230/****************************************************************************
231 * Name: up_pm_acquire_wakelock
232 *
233 * Description:
234 * Acquire the specified wakelock. If any wakelock is acquired, CPU can't
235 * enter to the hot sleep state.
236 *
237 * Parameter:
238 * lock - the pointer of a wakelock variable
239 *
240 ****************************************************************************/
241
242void up_pm_acquire_wakelock(struct pm_cpu_wakelock_s *lock);
243
244/****************************************************************************
245 * Name: up_pm_release_wakelock
246 *
247 * Description:
248 * Release the specified wakelock. If all of the wakelock are released,
249 * CPU can enter to the hot sleep state.
250 *
251 * Parameter:
252 * lock - the pointer of a wakelock variable
253 *
254 ****************************************************************************/
255
256void up_pm_release_wakelock(struct pm_cpu_wakelock_s *lock);
257
258/****************************************************************************
259 * Name: up_pm_count_acquire_wakelock
260 *
261 * Description:
262 * Count the total number of wakelock
263 *
264 * Return:
265 * the total number of wakelock
266 *
267 ****************************************************************************/
268
269int up_pm_count_acquire_wakelock(void);
270
271/****************************************************************************
272 * Name: up_pm_get_bootcause
273 *
274 * Description:
275 * Get the system boot cause. This boot cause indicates the cause why the
276 * system is launched from the state of power-off, deep sleep or cold
277 * sleep. Each boot cause is defined as PM_BOOT_XXX.
278 *
279 * Return:
280 * Boot cause
281 *
282 ****************************************************************************/
283
284uint32_t up_pm_get_bootcause(void);
285
286/****************************************************************************
287 * Name: up_pm_get_bootmask
288 *
289 * Description:
290 * Get the system boot mask. This boot mask indicates whether the specified
291 * bit is enabled or not as the boot cause. If a bit of boot mask is set,
292 * the boot cause is enabled. Each boot mask is defined as PM_BOOT_XXX.
293 *
294 * Return:
295 * Boot mask
296 *
297 ****************************************************************************/
298
299uint32_t up_pm_get_bootmask(void);
300
301/****************************************************************************
302 * Name: up_pm_set_bootmask
303 *
304 * Description:
305 * Enable the boot cause of the specified bit.
306 *
307 * Parameter:
308 * mask - OR of Boot mask defined as PM_BOOT_XXX
309 *
310 * Return:
311 * Updated boot mask
312 *
313 ****************************************************************************/
314
315uint32_t up_pm_set_bootmask(uint32_t mask);
316
317/****************************************************************************
318 * Name: up_pm_clr_bootmask
319 *
320 * Description:
321 * Disable the boot cause of the specified bit.
322 *
323 * Parameter:
324 * mask - OR of Boot mask defined as PM_BOOT_XXX
325 *
326 * Return:
327 * Updated boot mask
328 *
329 ****************************************************************************/
330
331uint32_t up_pm_clr_bootmask(uint32_t mask);
332
333/****************************************************************************
334 * Name: up_pm_sleep
335 *
336 * Description:
337 * Enter sleep mode. This function never returns.
338 *
339 * Parameter:
340 * mode - PM_SLEEP_DEEP or PM_SLEEP_COLD
341 *
342 ****************************************************************************/
343
344int up_pm_sleep(enum pm_sleepmode_e mode);
345
346/****************************************************************************
347 * Name: up_pm_reboot
348 *
349 * Description:
350 * System reboot. This function never returns.
351 *
352 ****************************************************************************/
353
354int up_pm_reboot(void);
355
356/****************************************************************************
357 * Name: up_pmic_set_notify
358 *
359 * Description:
360 * Register a callback for pmic interrupt.
361 *
362 * Input Parameter:
363 * kind - A kind of pmic interrupt defined as pmic_notify_e
364 * cb - A callback function for a kind of pmic interrupt
365 *
366 * Returned Value:
367 * Return 0 on success. Otherwise, return a negated errno.
368 *
369 ****************************************************************************/
370
371#ifdef CONFIG_CXD56_PMIC_INT
372int up_pmic_set_notify(int kind, pmic_notify_t cb);
373#else
374# define up_pmic_set_notify(kind, cb)
375#endif
376
377#undef EXTERN
378#ifdef __cplusplus
379}
380#endif
381
382#endif /* __ARCH_ARM_INCLUDE_CXD56XX_PM_H */
Definition: pm.h:119
Definition: pm.h:129