Software APIs
dt_pwrmgr.h
Go to the documentation of this file.
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4//
5// Device table API auto-generated by `dtgen`
6
7#ifndef OPENTITAN_DT_PWRMGR_H_
8#define OPENTITAN_DT_PWRMGR_H_
9
10/**
11 * @file
12 * @brief Device Tables (DT) for IP pwrmgr and top darjeeling.
13 *
14 * This file contains the type definitions and global functions of the pwrmgr.
15 */
16
17#include "dt_api.h"
18#include <stdint.h>
19
20/**
21 * List of instances.
22 */
23typedef enum dt_pwrmgr {
24 kDtPwrmgrAon = 0, /**< pwrmgr_aon */
25 kDtPwrmgrFirst = 0, /**< \internal First instance */
26 kDtPwrmgrCount = 1, /**< \internal Number of instances */
28
29/**
30 * List of register blocks.
31 *
32 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
33 */
34typedef enum dt_pwrmgr_reg_block {
35 kDtPwrmgrRegBlockCore = 0, /**< */
36 kDtPwrmgrRegBlockCount = 1, /**< \internal Number of register blocks */
38
39/** Primary register block (associated with the "primary" set of registers that control the IP). */
40static const dt_pwrmgr_reg_block_t kDtPwrmgrRegBlockPrimary = kDtPwrmgrRegBlockCore;
41
42/**
43 * List of IRQs.
44 *
45 * IRQs are guaranteed to be numbered consecutively from 0.
46 */
47typedef enum dt_pwrmgr_irq {
48 kDtPwrmgrIrqWakeup = 0, /**< Wake from low power state. See wake info for more details */
49 kDtPwrmgrIrqCount = 1, /**< \internal Number of IRQs */
51
52/**
53 * List of Alerts.
54 *
55 * Alerts are guaranteed to be numbered consecutively from 0.
56 */
57typedef enum dt_pwrmgr_alert {
58 kDtPwrmgrAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
59 kDtPwrmgrAlertCount = 1, /**< \internal Number of Alerts */
61
62/**
63 * List of clock ports.
64 *
65 * Clock ports are guaranteed to be numbered consecutively from 0.
66 */
67typedef enum dt_pwrmgr_clock {
68 kDtPwrmgrClockClk = 0, /**< Clock port clk_i */
69 kDtPwrmgrClockSlow = 1, /**< Clock port clk_slow_i */
70 kDtPwrmgrClockLc = 2, /**< Clock port clk_lc_i */
71 kDtPwrmgrClockEsc = 3, /**< Clock port clk_esc_i */
72 kDtPwrmgrClockCount = 4, /**< \internal Number of clock ports */
74
75/**
76 * List of reset ports.
77 *
78 * Reset ports are guaranteed to be numbered consecutively from 0.
79 */
80typedef enum dt_pwrmgr_reset {
81 kDtPwrmgrResetRst = 0, /**< Reset port rst_ni */
82 kDtPwrmgrResetMain = 1, /**< Reset port rst_main_ni */
83 kDtPwrmgrResetSlow = 2, /**< Reset port rst_slow_ni */
84 kDtPwrmgrResetLc = 3, /**< Reset port rst_lc_ni */
85 kDtPwrmgrResetEsc = 4, /**< Reset port rst_esc_ni */
86 kDtPwrmgrResetCount = 5, /**< \internal Number of reset ports */
88
89/**
90 * List of supported hardware features.
91 */
92#define OPENTITAN_PWRMGR_HAS_STARTUP_LIFE_CYCLE_INITIALIZATION 1
93#define OPENTITAN_PWRMGR_HAS_CLOCK_CONTROL_IO_IN_LOW_POWER 1
94#define OPENTITAN_PWRMGR_HAS_CLOCK_CONTROL_MAIN_IN_LOW_POWER 1
95#define OPENTITAN_PWRMGR_HAS_CLOCK_CONTROL_USB_IN_LOW_POWER 1
96#define OPENTITAN_PWRMGR_HAS_CLOCK_CONTROL_USB_WHEN_ACTIVE 1
97#define OPENTITAN_PWRMGR_HAS_LOW_POWER_ENTRY 1
98#define OPENTITAN_PWRMGR_HAS_LOW_POWER_DISABLE_POWER 1
99#define OPENTITAN_PWRMGR_HAS_LOW_POWER_PINMUX_AON_PIN_WKUP_REQ_WAKEUP_ENABLE 1
100#define OPENTITAN_PWRMGR_HAS_LOW_POWER_PINMUX_AON_PIN_WKUP_REQ_WAKEUP_REQUEST 1
101#define OPENTITAN_PWRMGR_HAS_LOW_POWER_AON_TIMER_AON_WKUP_REQ_WAKEUP_ENABLE 1
102#define OPENTITAN_PWRMGR_HAS_LOW_POWER_AON_TIMER_AON_WKUP_REQ_WAKEUP_REQUEST 1
103#define OPENTITAN_PWRMGR_HAS_LOW_POWER_SOC_PROXY_WKUP_INTERNAL_REQ_WAKEUP_ENABLE 1
104#define OPENTITAN_PWRMGR_HAS_LOW_POWER_SOC_PROXY_WKUP_INTERNAL_REQ_WAKEUP_REQUEST 1
105#define OPENTITAN_PWRMGR_HAS_LOW_POWER_SOC_PROXY_WKUP_EXTERNAL_REQ_WAKEUP_ENABLE 1
106#define OPENTITAN_PWRMGR_HAS_LOW_POWER_SOC_PROXY_WKUP_EXTERNAL_REQ_WAKEUP_REQUEST 1
107#define OPENTITAN_PWRMGR_HAS_LOW_POWER_WAKE_INFO 1
108#define OPENTITAN_PWRMGR_HAS_RESET_CHECK_ROM_INTEGRITY 1
109#define OPENTITAN_PWRMGR_HAS_RESET_AON_TIMER_AON_AON_TIMER_RST_REQ_ENABLE 1
110#define OPENTITAN_PWRMGR_HAS_RESET_AON_TIMER_AON_AON_TIMER_RST_REQ_REQUEST 1
111#define OPENTITAN_PWRMGR_HAS_RESET_SOC_PROXY_RST_REQ_EXTERNAL_ENABLE 1
112#define OPENTITAN_PWRMGR_HAS_RESET_SOC_PROXY_RST_REQ_EXTERNAL_REQUEST 1
113#define OPENTITAN_PWRMGR_HAS_RESET_ESCALATION_REQUEST 1
114#define OPENTITAN_PWRMGR_HAS_RESET_ESCALATION_TIMEOUT 1
115#define OPENTITAN_PWRMGR_HAS_RESET_SW_RST_REQUEST 1
116#define OPENTITAN_PWRMGR_HAS_RESET_MAIN_POWER_GLITCH_RESET 1
117#define OPENTITAN_PWRMGR_HAS_RESET_NDM_RESET_REQUEST 1
118#define OPENTITAN_PWRMGR_HAS_RESET_POR_REQUEST 1
119
120
121
122/**
123 * Get the pwrmgr instance from an instance ID
124 *
125 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
126 *
127 * @param inst_id Instance ID.
128 * @return A pwrmgr instance.
129 *
130 * **Note:** This function only makes sense if the instance ID has device type pwrmgr,
131 * otherwise the returned value is unspecified.
132 */
134
135/**
136 * Get the instance ID of an instance.
137 *
138 * @param dt Instance of pwrmgr.
139 * @return The instance ID of that instance.
140 */
142
143/**
144 * Get the register base address of an instance.
145 *
146 * @param dt Instance of pwrmgr.
147 * @param reg_block The register block requested.
148 * @return The register base address of the requested block.
149 */
150uint32_t dt_pwrmgr_reg_block(
151 dt_pwrmgr_t dt,
152 dt_pwrmgr_reg_block_t reg_block);
153
154/**
155 * Get the primary register base address of an instance.
156 *
157 * This is just a convenience function, equivalent to
158 * `dt_pwrmgr_reg_block(dt, kDtPwrmgrRegBlockCore)`
159 *
160 * @param dt Instance of pwrmgr.
161 * @return The register base address of the primary register block.
162 */
163static inline uint32_t dt_pwrmgr_primary_reg_block(
164 dt_pwrmgr_t dt) {
165 return dt_pwrmgr_reg_block(dt, kDtPwrmgrRegBlockCore);
166}
167
168/**
169 * Get the PLIC ID of a pwrmgr IRQ for a given instance.
170 *
171 * If the instance is not connected to the PLIC, this function
172 * will return `kDtPlicIrqIdNone`.
173 *
174 * @param dt Instance of pwrmgr.
175 * @param irq A pwrmgr IRQ.
176 * @return The PLIC ID of the IRQ of this instance.
177 */
179 dt_pwrmgr_t dt,
180 dt_pwrmgr_irq_t irq);
181
182/**
183 * Convert a global IRQ ID to a local pwrmgr IRQ type.
184 *
185 * @param dt Instance of pwrmgr.
186 * @param irq A PLIC ID that belongs to this instance.
187 * @return The pwrmgr IRQ, or `kDtPwrmgrIrqCount`.
188 *
189 * **Note:** This function assumes that the PLIC ID belongs to the instance
190 * of pwrmgr passed in parameter. In other words, it must be the case that
191 * `dt_pwrmgr_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
192 * will return `kDtPwrmgrIrqCount`.
193 */
195 dt_pwrmgr_t dt,
196 dt_plic_irq_id_t irq);
197
198
199/**
200 * Get the alert ID of a pwrmgr alert for a given instance.
201 *
202 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
203 * instances where the instance is not connected, the return value is unspecified.
204 *
205 * @param dt Instance of pwrmgr.
206 * @param alert A pwrmgr alert.
207 * @return The Alert Handler alert ID of the alert of this instance.
208 */
210 dt_pwrmgr_t dt,
211 dt_pwrmgr_alert_t alert);
212
213/**
214 * Convert a global alert ID to a local pwrmgr alert type.
215 *
216 * @param dt Instance of pwrmgr.
217 * @param alert A global alert ID that belongs to this instance.
218 * @return The pwrmgr alert, or `kDtPwrmgrAlertCount`.
219 *
220 * **Note:** This function assumes that the global alert ID belongs to the
221 * instance of pwrmgr passed in parameter. In other words, it must be the case
222 * that `dt_pwrmgr_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
223 * this function will return `kDtPwrmgrAlertCount`.
224 */
226 dt_pwrmgr_t dt,
227 dt_alert_id_t alert);
228
229
230
231/**
232 * Get the clock signal connected to a clock port of an instance.
233 *
234 * @param dt Instance of pwrmgr.
235 * @param clk Clock port.
236 * @return Clock signal.
237 */
239 dt_pwrmgr_t dt,
241
242/**
243 * Get the reset signal connected to a reset port of an instance.
244 *
245 * @param dt Instance of pwrmgr.
246 * @param rst Reset port.
247 * @return Reset signal.
248 */
250 dt_pwrmgr_t dt,
252
253
254/**
255 * Description of a wakeup source.
256 *
257 * A wakeup source is always identified by the instance ID of the module where it comes from.
258 * Some instances can have several wakeup signals, e.g. the pinmux has two (`pin` and `usb`).
259 * For such IPs, it is not sufficient to know the instance, we also need to know which
260 * signal triggered the wakeup. The `wakeup` index can be used to distinguish between those.
261 * This value should be casted to the `dt_<ip>_wakeup_t` type of the corresponding IP.
262 * For example, if the `pwrmgr` has two `pinmux` wakeup sources as described above, it's
263 * two wakeup sources will be described as follows:
264 * ```c
265 * {.inst_id = kDtInstanceIdPinmux, .wakeup = kDtPinmuxWakeupPinWkupReq}, // for `pin`
266 * {.inst_id = kDtInstanceIdPinmux, .wakeup = kDtPinmuxWakeupUsbWkupReq}, // for `usb`
267 * ```
268 */
269typedef struct dt_pwrmgr_wakeup_src {
270 dt_instance_id_t inst_id; /**< Instance ID of the source of this wakeup. */
271 size_t wakeup; /**< Index of the wakeup signal for that instance. */
273
274
275/**
276 * Get the number of wakeup sources.
277 *
278 * @param dt Instance of pwrmgr.
279 * @return Number of wakeup sources.
280 */
282
283/**
284 * Get the description of a wakeup source.
285 *
286 * The wakeup sources are ordered as they appear in the registers.
287 *
288 * @param dt Instance of pwrmgr.
289 * @param idx Index of the wakeup source, between 0 and `dt_pwrmgr_wakeup_src_count(dt)-1`.
290 * @return Description of the source.
291 */
293
294/**
295 * Description of a reset request source.
296 *
297 * A reset request source is always identified by the instance ID of the module where it comes
298 * from. In principle, some instances could have several reset requests. If this is the case,
299 * the `rst_req` can be used to distinguish between those. It should be cast to the
300 * `dt_<ip>_reset_req_t` type of the corresponding IP.
301 */
302typedef struct dt_pwrmgr_reset_req_src {
303 dt_instance_id_t inst_id; /**< Instance ID of the source of this reset request. */
304 size_t reset_req; /**< Index of the reset request signal for that instance. */
306
307
308/**
309 * Get the number of peripheral reset requests.
310 *
311 * @param dt Instance of pwrmgr.
312 * @return Number of reset requests.
313 */
315
316/**
317 * Get the description of a reset request.
318 *
319 * The reset requests are ordered as they appear in the registers.
320 *
321 * @param dt Instance of pwrmgr.
322 * @param idx Index of the reset request source, between 0 and
323 * `dt_pwrmgr_reset_request_src_count(dt)-1`.
324 * @return Description of the reset.
325 */
327
328
329#endif // OPENTITAN_DT_PWRMGR_H_