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_pmu.h
21  * @brief    header file for pmu driver
22  * @version  V1.0
23  * @date     02. June 2017
24  * @model    pmu
25  ******************************************************************************/
26 
27 #ifndef _DRV_PMU_H_
28 #define _DRV_PMU_H_
29 
30 
31 #include <drv/common.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 /// definition for pmu handle.
37 typedef void *pmu_handle_t;
38 
39 /****** PMU specific error codes *****/
40 typedef enum {
41     EDRV_PMU_MODE  = (1),      ///< Specified Mode not supported
42 } pmu_error_e;
43 
44 /*----- PMU Control Codes: Mode -----*/
45 typedef enum {
46     PMU_MODE_RUN                  = 0,   ///< Running mode
47     PMU_MODE_SLEEP,                      ///< Sleep mode
48     PMU_MODE_DOZE,                       ///< Doze mode
49     PMU_MODE_DORMANT,                    ///< Dormant mode
50     PMU_MODE_STANDBY,                    ///< Standby mode
51     PMU_MODE_SHUTDOWN                    ///< Shutdown mode
52 } pmu_mode_e;
53 
54 /*----- PMU Control Codes: Wakeup type -----*/
55 typedef enum {
56     PMU_WAKEUP_TYPE_PULSE   = 0,    ///< Pulse interrupt
57     PMU_WAKEUP_TYPE_LEVEL           ///< Level interrupt
58 } pmu_wakeup_type_e;
59 
60 /*----- PMU Control Codes: Wakeup polarity -----*/
61 typedef enum {
62     PMU_WAKEUP_POL_LOW      = 0,       ///< Low or negedge
63     PMU_WAKEUP_POL_HIGH                ///< High or posedge
64 } pmu_wakeup_pol_e;
65 
66 /****** PMU Event *****/
67 typedef enum {
68     PMU_EVENT_SLEEP_DONE        = 0,  ///< Send completed; however PMU may still transmit data
69     PMU_EVENT_PREPARE_SLEEP     = 1
70 } pmu_event_e;
71 
72 typedef void (*pmu_event_cb_t)(int32_t idx, pmu_event_e event, pmu_mode_e mode);   ///< Pointer to \ref pmu_event_cb_t : PMU Event call back.
73 
74 /**
75   \brief       Initialize PMU Interface. 1. Initializes the resources needed for the PMU interface 2.registers event callback function
76   \param[in]   idx the id of the pmu
77   \param[in]   cb_event  Pointer to \ref pmu_event_cb_t
78   \return      return pmu handle if success
79 */
80 pmu_handle_t csi_pmu_initialize(int32_t idx, pmu_event_cb_t cb_event);
81 
82 /**
83   \brief       De-initialize PMU Interface. stops operation and releases the software resources used by the interface
84   \param[in]   handle  pmu handle to operate.
85   \return      error code
86 */
87 int32_t csi_pmu_uninitialize(pmu_handle_t handle);
88 
89 /**
90   \brief       choose the pmu mode to enter
91   \param[in]   handle  pmu handle to operate.
92   \param[in]   mode    \ref pmu_mode_e
93   \return      error code
94 */
95 int32_t csi_pmu_enter_sleep(pmu_handle_t handle, pmu_mode_e mode);
96 
97 /**
98   \brief       control pmu power.
99   \param[in]   handle  pmu handle to operate.
100   \param[in]   state   power state.\ref csi_power_stat_e.
101   \return      error code
102 */
103 /**
104   \brief       Config the wakeup source.
105   \param[in]   handle  pmu handle to operate
106   \param[in]   wakeup_num wakeup source num
107   \param[in]   type    \ref pmu_wakeup_type
108   \param[in]   pol     \ref pmu_wakeup_pol
109   \param[in]   enable  flag control the wakeup source is enable or not
110   \return      error code
111 */
112 int32_t csi_pmu_config_wakeup_source(pmu_handle_t handle, uint32_t wakeup_num, pmu_wakeup_type_e type, pmu_wakeup_pol_e pol, uint8_t enable);
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* _CSI_PMU_H_ */
119