Developer World
Spresense SDK Library v1.4.2-3df2e9d
pm.h
Go to the documentation of this file.
1 /****************************************************************************
2  * bsp/include/arch/chip/pm.h
3  *
4  * Copyright 2018 Sony Semiconductor Solutions Corporation
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17  * the names of its contributors may be used to endorse or promote
18  * products derived from this software without specific prior written
19  * permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ****************************************************************************/
39 #ifndef __ARCH_ARM_INCLUDE_CXD56XX_PM_H
40 #define __ARCH_ARM_INCLUDE_CXD56XX_PM_H
41 
42 /*-----------------------------------------------------------------------------
43  * include files
44  *---------------------------------------------------------------------------*/
45 
46 #include <queue.h>
47 
48 /****************************************************************************
49  * Pre-processor Definitions
50  ****************************************************************************/
51 
52 /* Boot Cause definitions */
53 
54 #define PM_BOOT_POR_NORMAL (0x00000000ul)
55 #define PM_BOOT_POR_DEADBATT (0x00000001ul)
56 #define PM_BOOT_WDT_REBOOT (0x00000002ul)
57 #define PM_BOOT_WDT_RESET (0x00000004ul)
58 #define PM_BOOT_DEEP_WKUPL (0x00000008ul)
59 #define PM_BOOT_DEEP_WKUPS (0x00000010ul)
60 #define PM_BOOT_DEEP_RTC (0x00000020ul)
61 #define PM_BOOT_DEEP_USB_ATTACH (0x00000040ul)
62 #define PM_BOOT_DEEP_OTHERS (0x00000080ul)
63 #define PM_BOOT_COLD_SCU_INT (0x00000100ul)
64 #define PM_BOOT_COLD_RTC (0x00001e00ul)
65 #define PM_BOOT_COLD_RTC_ALM0 (0x00000200ul)
66 #define PM_BOOT_COLD_RTC_ALM1 (0x00000400ul)
67 #define PM_BOOT_COLD_RTC_ALM2 (0x00000800ul)
68 #define PM_BOOT_COLD_RTC_ALMERR (0x00001000ul)
69 #define PM_BOOT_COLD_GPIO (0x0fff0000ul)
70 #define PM_BOOT_COLD_SEN_INT (0x10000000ul)
71 #define PM_BOOT_COLD_PMIC_INT (0x20000000ul)
72 #define PM_BOOT_COLD_USB_DETACH (0x40000000ul)
73 #define PM_BOOT_COLD_USB_ATTACH (0x80000000ul)
75 /* SRAM power status definitions */
76 
77 #define PMCMD_RAM_OFF 0 /* Power off */
78 #define PMCMD_RAM_RET 1 /* Retention */
79 #define PMCMD_RAM_ON 3 /* Power on */
80 
81 /* FrequencyLock request flag definitions */
82 
83 #define PM_CPUFREQLOCK_FLAG_HV (0x0001) /* request HV */
84 #define PM_CPUFREQLOCK_FLAG_LV (0x4000) /* request LV */
85 
86 /* FrequencyLock identifier tag helper macro function */
87 
88 #define PM_CPUFREQLOCK_TAG(prefix1, prefix2, num) \
89  (((prefix1) << 24) + ((prefix2) << 16) + (num))
90 
91 /* FrequencyLock initializer macro function */
92 
93 # define PM_CPUFREQLOCK_INIT(_tag, _flag) \
94 { \
95  .count = 0, \
96  .info = _tag, \
97  .flag = _flag, \
98 }
99 
100 /* WakeLock identifier tag helper macro function */
101 
102 #define PM_CPUWAKELOCK_TAG(prefix1, prefix2, num) \
103  (((prefix1) << 24) + ((prefix2) << 16) + (num))
104 
105 /* WakeLock initializer macro function */
106 
107 #define PM_CPUWAKELOCK_INIT(_tag) \
108 { \
109  .count = 0, \
110  .info = _tag, \
111 }
112 
113 /****************************************************************************
114  * Public Types
115  ****************************************************************************/
116 
117 /* slee mode definitions */
118 
119 enum pm_sleepmode_e
120 {
121  PM_SLEEP_DEEP,
122  PM_SLEEP_COLD,
123 };
124 
125 /* FreqLock structure */
126 
128 {
129  struct sq_entry_s sq_entry;
130  int count;
131  uint32_t info;
132  int flag;
133 };
134 
135 /* WakeLock structure */
136 
138 {
139  struct sq_entry_s sq_entry;
140  int count;
141  uint32_t info;
142 };
143 
144 /* Definitions for pmic notify */
145 
146 enum pmic_notify_e
147 {
148  PMIC_NOTIFY_ALARM = 0,
149  PMIC_NOTIFY_WKUPS,
150  PMIC_NOTIFY_WKUPL,
151  PMIC_NOTIFY_LOWBATT,
152  PMIC_NOTIFY_MAX
153 };
154 
155 /* callback function for pmic notify */
156 
157 typedef void (*pmic_notify_t)(void *arg);
158 
159 /****************************************************************************
160  * Public Function Prototypes
161  ****************************************************************************/
162 
163 #ifdef __cplusplus
164 #define EXTERN extern "C"
165 extern "C"
166 {
167 #else
168 #define EXTERN extern
169 #endif
170 
171 /****************************************************************************
172  * Name: up_pmstatdump
173  *
174  * Description:
175  * Print architecture specific power status
176  *
177  ****************************************************************************/
178 
179 int up_pmramctrl(int cmd, uintptr_t addr, size_t size);
180 
181 #ifdef CONFIG_DEBUG_PM
182 /****************************************************************************
183  * Name: up_pmstatdump
184  *
185  * Description:
186  * Print architecture specific power status
187  *
188  ****************************************************************************/
189 
190 void up_pmstatdump(void);
191 #else
192 # define up_pmstatdump()
193 #endif
194 
195 /****************************************************************************
196  * Name: up_pm_acquire_freqlock
197  *
198  * Description:
199  * Acquire the specified freqlock. If the higher freqlock is acquired, the
200  * system can clockup until it is released.
201  *
202  * Parameter:
203  * lock - the pointer of a wakelock variable
204  *
205  ****************************************************************************/
206 
207 void up_pm_acquire_freqlock(struct pm_cpu_freqlock_s *lock);
208 
209 /****************************************************************************
210  * Name: up_pm_release_freqlock
211  *
212  * Description:
213  * Release the specified freqlock. If the freqlock are released, the system
214  * can drop to the lower clock mode for power saving.
215  *
216  * Parameter:
217  * lock - the pointer of a freqlock variable
218  *
219  ****************************************************************************/
220 
221 void up_pm_release_freqlock(struct pm_cpu_freqlock_s *lock);
222 
223 /****************************************************************************
224  * Name: up_pm_get_freqlock_count
225  *
226  * Description:
227  * Get the locked count of the specified freqlock
228  *
229  * Parameter:
230  * lock - the pointer of a freqlock variable
231  *
232  * Return:
233  * the locked count of the specified freqlock
234  *
235  ****************************************************************************/
236 
237 int up_pm_get_freqlock_count(struct pm_cpu_freqlock_s *lock);
238 
239 /****************************************************************************
240  * Name: up_pm_acquire_wakelock
241  *
242  * Description:
243  * Acquire the specified wakelock. If any wakelock is acquired, CPU can't
244  * enter to the hot sleep state.
245  *
246  * Parameter:
247  * lock - the pointer of a wakelock variable
248  *
249  ****************************************************************************/
250 
251 void up_pm_acquire_wakelock(struct pm_cpu_wakelock_s *lock);
252 
253 /****************************************************************************
254  * Name: up_pm_release_wakelock
255  *
256  * Description:
257  * Release the specified wakelock. If all of the wakelock are released,
258  * CPU can enter to the hot sleep state.
259  *
260  * Parameter:
261  * lock - the pointer of a wakelock variable
262  *
263  ****************************************************************************/
264 
265 void up_pm_release_wakelock(struct pm_cpu_wakelock_s *lock);
266 
267 /****************************************************************************
268  * Name: up_pm_count_acquire_wakelock
269  *
270  * Description:
271  * Count the total number of wakelock
272  *
273  * Return:
274  * the total number of wakelock
275  *
276  ****************************************************************************/
277 
278 int up_pm_count_acquire_wakelock(void);
279 
280 /****************************************************************************
281  * Name: up_pm_get_bootcause
282  *
283  * Description:
284  * Get the system boot cause. This boot cause indicates the cause why the
285  * system is launched from the state of power-off, deep sleep or cold sleep.
286  * Each boot cause is defined as PM_BOOT_XXX.
287  *
288  * Return:
289  * Boot cause
290  *
291  ****************************************************************************/
292 
293 uint32_t up_pm_get_bootcause(void);
294 
295 /****************************************************************************
296  * Name: up_pm_get_bootmask
297  *
298  * Description:
299  * Get the system boot mask. This boot mask indicates whether the specified
300  * bit is enabled or not as the boot cause. If a bit of boot mask is set,
301  * the boot cause is enabled. Each boot mask is defined as PM_BOOT_XXX.
302  *
303  * Return:
304  * Boot mask
305  *
306  ****************************************************************************/
307 
308 uint32_t up_pm_get_bootmask(void);
309 
310 /****************************************************************************
311  * Name: up_pm_set_bootmask
312  *
313  * Description:
314  * Enable the boot cause of the specified bit.
315  *
316  * Parameter:
317  * mask - OR of Boot mask definied as PM_BOOT_XXX
318  *
319  * Return:
320  * Updated boot mask
321  *
322  ****************************************************************************/
323 
324 uint32_t up_pm_set_bootmask(uint32_t mask);
325 
326 /****************************************************************************
327  * Name: up_pm_clr_bootmask
328  *
329  * Description:
330  * Disable the boot cause of the specified bit.
331  *
332  * Parameter:
333  * mask - OR of Boot mask definied as PM_BOOT_XXX
334  *
335  * Return:
336  * Updated boot mask
337  *
338  ****************************************************************************/
339 
340 uint32_t up_pm_clr_bootmask(uint32_t mask);
341 
342 /****************************************************************************
343  * Name: up_pm_sleep
344  *
345  * Description:
346  * Enter sleep mode. This function never returns.
347  *
348  * Parameter:
349  * mode - PM_SLEEP_DEEP or PM_SLEEP_COLD
350  *
351  ****************************************************************************/
352 
353 int up_pm_sleep(enum pm_sleepmode_e mode);
354 
355 /****************************************************************************
356  * Name: up_pm_reboot
357  *
358  * Description:
359  * System reboot. This function never returns.
360  *
361  ****************************************************************************/
362 
363 int up_pm_reboot(void);
364 
365 /****************************************************************************
366  * Name: up_pmic_set_notify
367  *
368  * Description:
369  * Register a callback for pmic interrupt
370  *
371  * Input Parameter:
372  * kind - A kind of pmic interrupt defined as pmic_notify_e
373  * cb - A callback function for a kind of pmic interrupt
374  *
375  * Returned Value:
376  * Return 0 on success. Otherwise, return a negated errno.
377  *
378  ****************************************************************************/
379 
380 #ifdef CONFIG_CXD56_PMIC_INT
381 int up_pmic_set_notify(int kind, pmic_notify_t cb);
382 #else
383 # define up_pmic_set_notify(kind, cb)
384 #endif
385 
386 #undef EXTERN
387 #ifdef __cplusplus
388 }
389 #endif
390 
391 #endif /* __ARCH_ARM_INCLUDE_CXD56XX_PM_H */
Definition: pm.h:127
Definition: pm.h:137
uint16_t size
Definition: video.h:77