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