1  /*
2  * Copyright (C) 2017-2024 Alibaba Group Holding Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /******************************************************************************
20  * @file     drv/pm.h
21  * @brief    Header File for PM Driver
22  * @version  V1.0
23  * @date     10. Oct 2020
24  * @model    pm
25  ******************************************************************************/
26 
27 #ifndef _DRV_PM_H_
28 #define _DRV_PM_H_
29 
30 #include <stdint.h>
31 #include <drv/common.h>
32 #include <soc.h>
33 #include <csi_core.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /**
40   \brief       Initialize PM module
41   \return      Error code \ref csi_error_t
42 */
43 csi_error_t csi_pm_init(void);
44 
45 /**
46   \brief       De-initialize PM module
47   \return      None
48 */
49 void csi_pm_uninit(void);
50 
51 /**
52   \brief       Set the retention memory used to save registers
53   \param[in]   mem    Retention memory(word align)
54   \param[in]   num    Number of memory(1: 1 word)
55   \return      Error code \ref csi_error_t
56 */
57 csi_error_t csi_pm_set_reten_mem(uint32_t *mem, uint32_t num);
58 
59 /**
60   \brief       Config the wakeup source
61   \param[in]   wakeup_num    Wakeup source num
62   \param[in]   enable        Flag control the wakeup source is enable or not
63   \return      Error code \ref csi_error_t
64 */
65 csi_error_t csi_pm_config_wakeup_source(uint32_t wakeup_num, bool enable);
66 
67 /**
68   \brief       System enter low-power mode
69   \param[in]   mode    Low-power mode, \ref csi_pm_mode_t
70   \return      Error code \ref csi_error_t
71 */
72 csi_error_t csi_pm_enter_sleep(csi_pm_mode_t mode);
73 
74 /**
75   \brief       Register device to the PM list
76   \param[in]   dev          Csi dev
77   \param[in]   pm_action    PM action function
78   \param[in]   mem_size     Size of memory for saving registers
79   \param[in]   priority     PM dev priority(0-3), The smaller the value,
80                             the last execution before entering low power consumption,
81                             the first execution after exiting low power consumption
82   \return      Error code \ref csi_error_t
83 */
84 csi_error_t csi_pm_dev_register(csi_dev_t *dev, void *pm_action, uint32_t mem_size, uint8_t priority);
85 
86 /**
87   \brief       Deregister device to the PM list
88   \param[in]   dev    Csi dev
89   \return      None
90 */
91 void csi_pm_dev_unregister(csi_dev_t *dev);
92 
93 /**
94   \brief       Save registers to memory
95   \param[in]   mem     Mem to store registers
96   \param[in]   addr    Registers address
97   \param[in]   num     Number of memory(1: 1 word)
98   \return      None
99 */
100 void csi_pm_dev_save_regs(uint32_t *mem, uint32_t *addr, uint32_t num);
101 
102 /**
103   \brief       Save registers to memory
104   \param[in]   mem     Mem to store registers
105   \param[in]   addr    Registers address
106   \param[in]   num     Number of memory(1: 1 word)
107   \return      None
108 */
109 void csi_pm_dev_restore_regs(uint32_t *mem, uint32_t *addr, uint32_t num);
110 
111 /**
112   \brief       Notify devices enter low-power states
113   \param[in]   action    Device low-power action
114   \return      Error code \ref csi_error_t
115 */
116 csi_error_t csi_pm_dev_notify(csi_pm_dev_action_t action);
117 
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #endif /* _DRV_PM_H_ */
123