1 /*
2  * Copyright (C) 2017-2020 Alibaba Group Holding Limited
3  */
4 
5 /******************************************************************************
6  * @file     drv/pm.h
7  * @brief    Header File for PM Driver
8  * @version  V1.0
9  * @date     10. Oct 2020
10  * @model    pm
11  ******************************************************************************/
12 
13 #ifndef _DRV_PM_H_
14 #define _DRV_PM_H_
15 
16 #include <stdint.h>
17 #include <drv/common.h>
18 #include <soc.h>
19 #include <csi_core.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26   \brief       Initialize PM module
27   \return      Error code \ref csi_error_t
28 */
29 csi_error_t csi_pm_init(void);
30 
31 /**
32   \brief       De-initialize PM module
33   \return      None
34 */
35 void csi_pm_uninit(void);
36 
37 /**
38   \brief       Set the retention memory used to save registers
39   \param[in]   mem    Retention memory(word align)
40   \param[in]   num    Number of memory(1: 1 word)
41   \return      Error code \ref csi_error_t
42 */
43 csi_error_t csi_pm_set_reten_mem(uint32_t *mem, uint32_t num);
44 
45 /**
46   \brief       Config the wakeup source
47   \param[in]   wakeup_num    Wakeup source num
48   \param[in]   enable        Flag control the wakeup source is enable or not
49   \return      Error code \ref csi_error_t
50 */
51 csi_error_t csi_pm_config_wakeup_source(uint32_t wakeup_num, bool enable);
52 
53 /**
54   \brief       System enter low-power mode
55   \param[in]   mode    Low-power mode, \ref csi_pm_mode_t
56   \return      Error code \ref csi_error_t
57 */
58 csi_error_t csi_pm_enter_sleep(csi_pm_mode_t mode);
59 
60 /**
61   \brief       Register device to the PM list
62   \param[in]   dev          Csi dev
63   \param[in]   pm_action    PM action function
64   \param[in]   mem_size     Size of memory for saving registers
65   \param[in]   priority     PM dev priority(0-3), The smaller the value,
66                             the last execution before entering low power consumption,
67                             the first execution after exiting low power consumption
68   \return      Error code \ref csi_error_t
69 */
70 csi_error_t csi_pm_dev_register(csi_dev_t *dev, void *pm_action, uint32_t mem_size, uint8_t priority);
71 
72 /**
73   \brief       Deregister device to the PM list
74   \param[in]   dev    Csi dev
75   \return      None
76 */
77 void csi_pm_dev_unregister(csi_dev_t *dev);
78 
79 /**
80   \brief       Save registers to memory
81   \param[in]   mem     Mem to store registers
82   \param[in]   addr    Registers address
83   \param[in]   num     Number of memory(1: 1 word)
84   \return      None
85 */
86 void csi_pm_dev_save_regs(uint32_t *mem, uint32_t *addr, uint32_t num);
87 
88 /**
89   \brief       Save registers to memory
90   \param[in]   mem     Mem to store registers
91   \param[in]   addr    Registers address
92   \param[in]   num     Number of memory(1: 1 word)
93   \return      None
94 */
95 void csi_pm_dev_restore_regs(uint32_t *mem, uint32_t *addr, uint32_t num);
96 
97 /**
98   \brief       Notify devices enter low-power states
99   \param[in]   action    Device low-power action
100   \return      Error code \ref csi_error_t
101 */
102 csi_error_t csi_pm_dev_notify(csi_pm_dev_action_t action);
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif /* _DRV_PM_H_ */
109