1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2015-2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Description:
8  *     System Power Support
9  */
10 
11 #ifndef MOD_SYSTEM_POWER_H
12 #define MOD_SYSTEM_POWER_H
13 
14 #include <mod_power_domain.h>
15 
16 #include <fwk_id.h>
17 #include <fwk_module_idx.h>
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 /*!
23  * \ingroup GroupModules Modules
24  * \defgroup GroupSystemPower System Power Support
25  *
26  * \{
27  */
28 
29 /*! Additional system_power power states */
30 enum mod_system_power_power_states {
31     MOD_SYSTEM_POWER_POWER_STATE_SLEEP0 = MOD_PD_STATE_COUNT,
32     MOD_SYSTEM_POWER_POWER_STATE_SLEEP1,
33     MOD_SYSTEM_POWER_POWER_STATE_COUNT
34 };
35 
36 /*! Extended PPU configuration */
37 struct mod_system_power_ext_ppu_config {
38     /*! PPU identifier */
39     fwk_id_t ppu_id;
40 
41     /*! API identifier */
42     fwk_id_t api_id;
43 };
44 
45 /*! Element configuration */
46 struct mod_system_power_dev_config {
47     /*! Identifier of the system PPU */
48     fwk_id_t sys_ppu_id;
49 
50     /*! System PPU API identifier */
51     fwk_id_t api_id;
52 
53     /*!
54      * \brief Pointer to a table defining the power states this system PPU will
55      *      be set for each system state.
56      */
57     const uint8_t *sys_state_table;
58 };
59 
60 /*! Module configuration */
61 struct mod_system_power_config {
62     /*! SoC wakeup IRQ number */
63     unsigned int soc_wakeup_irq;
64 
65     /*! Number of extended PPUs */
66     size_t ext_ppus_count;
67 
68     /*!
69      * \brief Pointer to array of extended PPU configurations.
70      *
71      * \details These PPUs will be powered on automatically with the rest of the
72      *      system.
73      */
74     const struct mod_system_power_ext_ppu_config *ext_ppus;
75 
76     /*! System shutdown driver identifier */
77     fwk_id_t driver_id;
78 
79     /*! System shutdown driver API identifier */
80     fwk_id_t driver_api_id;
81 
82     /*! Initial System Power state after power-on */
83     enum mod_pd_state initial_system_power_state;
84 };
85 
86 /*! Platform-specific interrupt commands indices */
87 enum mod_system_power_platform_interrupt_cmd {
88     MOD_SYSTEM_POWER_PLATFORM_INTERRUPT_CMD_INIT,
89     MOD_SYSTEM_POWER_PLATFORM_INTERRUPT_CMD_ENABLE,
90     MOD_SYSTEM_POWER_PLATFORM_INTERRUPT_CMD_DISABLE,
91     MOD_SYSTEM_POWER_PLATFORM_INTERRUPT_CMD_CLEAR_PENDING,
92     MOD_SYSTEM_POWER_PLATFORM_INTERRUPT_CMD_COUNT,
93 };
94 
95 /*!
96  * \brief Driver interface.
97  */
98 struct mod_system_power_driver_api {
99     /*!
100      * \brief Pointer to the system shutdown function.
101      *
102      * \note This function is \b mandatory. In case of a successful call the
103      *      function does not return.
104      *
105      * \param system_shutdown Type of system shutdown.
106      *
107      * \retval One of the driver-defined error code.
108      */
109     int (*system_shutdown)(enum mod_pd_system_shutdown system_shutdown);
110 
111     /*!
112      * \brief Pointer to the platform interrupt management function.
113      *
114      * \details This function allows the driver to manage additional
115      *      platform-specific interrupts.
116      *
117      * \note This function is \b optional.
118      *
119      * \param isr_cmd Type of command requested.
120      *
121      * \retval ::FWK_E_PARAM The interrupt command is not valid.
122      * \retval ::FWK_SUCCESS The operation succeeded.
123      * \return One of the standard framework error codes.
124      */
125     int (*platform_interrupts)(enum mod_system_power_platform_interrupt_cmd
126                                isr_cmd);
127 };
128 
129 /*!
130  * \defgroup GroupSystemPowerIds Identifiers
131  * \{
132  */
133 
134 /*!
135  * \brief API indices.
136  */
137 enum mod_system_power_api_idx {
138 #ifdef BUILD_HAS_MOD_SYSTEM_POWER
139     /*! API index for the power domain driver API */
140     MOD_SYSTEM_POWER_API_IDX_PD_DRIVER,
141 
142     /*! API index for the power domain driver input API */
143     MOD_SYSTEM_POWER_API_IDX_PD_DRIVER_INPUT,
144 #endif
145 
146     /*! Number of exposed APIs */
147     MOD_SYSTEM_POWER_API_COUNT
148 };
149 
150 #ifdef BUILD_HAS_MOD_SYSTEM_POWER
151 /*! Identifier of the power domain driver API */
152 static const fwk_id_t mod_system_power_api_id_pd_driver =
153     FWK_ID_API_INIT(FWK_MODULE_IDX_SYSTEM_POWER,
154                     MOD_SYSTEM_POWER_API_IDX_PD_DRIVER);
155 
156 /*! Identifier of the power domain driver input API */
157 static const fwk_id_t mod_system_power_api_id_pd_driver_input =
158     FWK_ID_API_INIT(FWK_MODULE_IDX_SYSTEM_POWER,
159                     MOD_SYSTEM_POWER_API_IDX_PD_DRIVER_INPUT);
160 #endif
161 
162 /*!
163  * \}
164  */
165 
166 /*!
167  * \}
168  */
169 
170 #endif /* MOD_SYSTEM_POWER_H */
171