Software APIs
clkmgr.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_CLKMGR_H_
8#define OPENTITAN_DT_CLKMGR_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP clkmgr and top earlgrey.
17 *
18 * This file contains the type definitions and global functions of the clkmgr.
19 */
20
21#include "hw/top/dt/api.h"
22#include <stdint.h>
23
24
26
27
28/**
29 * List of instances.
30 */
31typedef enum dt_clkmgr {
32 kDtClkmgrFirst = 0, /**< First instance */
33 kDtClkmgrAon = 0, /**< clkmgr_aon */
35
36enum {
37 kDtClkmgrCount = 1, /**< Number of instances */
38};
39
40
41/**
42 * List of register blocks.
43 *
44 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
45 */
46typedef enum dt_clkmgr_reg_block {
47 kDtClkmgrRegBlockCore = 0, /**< */
49
50enum {
51 kDtClkmgrRegBlockCount = 1, /**< Number of register blocks */
52};
53
54
55/** Primary register block (associated with the "primary" set of registers that control the IP). */
56static const dt_clkmgr_reg_block_t kDtClkmgrRegBlockPrimary = kDtClkmgrRegBlockCore;
57
58/**
59 * List of Alerts.
60 *
61 * Alerts are guaranteed to be numbered consecutively from 0.
62 */
63typedef enum dt_clkmgr_alert {
64 kDtClkmgrAlertRecovFault = 0, /**< This recoverable alert is triggered when there are measurement errors. */
65 kDtClkmgrAlertFatalFault = 1, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
67
68enum {
69 kDtClkmgrAlertCount = 2, /**< Number of Alerts */
70};
71
72
73/**
74 * List of clock ports.
75 *
76 * Clock ports are guaranteed to be numbered consecutively from 0.
77 */
78typedef enum dt_clkmgr_clock {
79 kDtClkmgrClockClk = 0, /**< Clock port clk_i */
80 kDtClkmgrClockMain = 1, /**< Clock port clk_main_i */
81 kDtClkmgrClockIo = 2, /**< Clock port clk_io_i */
82 kDtClkmgrClockUsb = 3, /**< Clock port clk_usb_i */
83 kDtClkmgrClockAon = 4, /**< Clock port clk_aon_i */
85
86enum {
87 kDtClkmgrClockCount = 5, /**< Number of clock ports */
88};
89
90
91/**
92 * List of reset ports.
93 *
94 * Reset ports are guaranteed to be numbered consecutively from 0.
95 */
96typedef enum dt_clkmgr_reset {
97 kDtClkmgrResetRst = 0, /**< Reset port rst_ni */
98 kDtClkmgrResetRoot = 1, /**< Reset port rst_root_ni */
99 kDtClkmgrResetMain = 2, /**< Reset port rst_main_ni */
100 kDtClkmgrResetIo = 3, /**< Reset port rst_io_ni */
101 kDtClkmgrResetUsb = 4, /**< Reset port rst_usb_ni */
102 kDtClkmgrResetAon = 5, /**< Reset port rst_aon_ni */
103 kDtClkmgrResetIoDiv2 = 6, /**< Reset port rst_io_div2_ni */
104 kDtClkmgrResetIoDiv4 = 7, /**< Reset port rst_io_div4_ni */
105 kDtClkmgrResetRootMain = 8, /**< Reset port rst_root_main_ni */
106 kDtClkmgrResetRootIo = 9, /**< Reset port rst_root_io_ni */
107 kDtClkmgrResetRootIoDiv2 = 10, /**< Reset port rst_root_io_div2_ni */
108 kDtClkmgrResetRootIoDiv4 = 11, /**< Reset port rst_root_io_div4_ni */
109 kDtClkmgrResetRootUsb = 12, /**< Reset port rst_root_usb_ni */
111
112enum {
113 kDtClkmgrResetCount = 13, /**< Number of reset ports */
114};
115
116
117/**
118 * List of supported hardware features.
119 */
120#define OPENTITAN_CLKMGR_HAS_ENABLE_IO_DIV4 1
121#define OPENTITAN_CLKMGR_HAS_ENABLE_IO_DIV2 1
122#define OPENTITAN_CLKMGR_HAS_ENABLE_IO 1
123#define OPENTITAN_CLKMGR_HAS_ENABLE_USB 1
124#define OPENTITAN_CLKMGR_HAS_HINT_AES 1
125#define OPENTITAN_CLKMGR_HAS_HINT_HMAC 1
126#define OPENTITAN_CLKMGR_HAS_HINT_KMAC 1
127#define OPENTITAN_CLKMGR_HAS_HINT_OTBN 1
128#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_REGWEN 1
129#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_IO 1
130#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_IO_DIV2 1
131#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_IO_DIV4 1
132#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_MAIN 1
133#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_USB 1
134#define OPENTITAN_CLKMGR_HAS_MEAS_CTRL_RECOV_ERR 1
135#define OPENTITAN_CLKMGR_HAS_LC_EXTCLK_SPEED 1
136#define OPENTITAN_CLKMGR_HAS_SW_EXTCLK_REGWEN 1
137#define OPENTITAN_CLKMGR_HAS_SW_EXTCLK_HIGH_SPEED 1
138#define OPENTITAN_CLKMGR_HAS_SW_EXTCLK_LOW_SPEED 1
139#define OPENTITAN_CLKMGR_HAS_JITTER_REGWEN 1
140#define OPENTITAN_CLKMGR_HAS_JITTER_ENABLE 1
141#define OPENTITAN_CLKMGR_HAS_ALERT_HANDLER_CLOCK_STATUS 1
142
143
144
145/**
146 * Get the clkmgr instance from an instance ID
147 *
148 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
149 *
150 * @param inst_id Instance ID.
151 * @return A clkmgr instance.
152 *
153 * **Note:** This function only makes sense if the instance ID has device type clkmgr,
154 * otherwise the returned value is unspecified.
155 */
157
158/**
159 * Get the instance ID of an instance.
160 *
161 * @param dt Instance of clkmgr.
162 * @return The instance ID of that instance.
163 */
165
166/**
167 * Get the register base address of an instance.
168 *
169 * @param dt Instance of clkmgr.
170 * @param reg_block The register block requested.
171 * @return The register base address of the requested block.
172 */
173uint32_t dt_clkmgr_reg_block(
174 dt_clkmgr_t dt,
175 dt_clkmgr_reg_block_t reg_block);
176
177/**
178 * Get the primary register base address of an instance.
179 *
180 * This is just a convenience function, equivalent to
181 * `dt_clkmgr_reg_block(dt, kDtClkmgrRegBlockCore)`
182 *
183 * @param dt Instance of clkmgr.
184 * @return The register base address of the primary register block.
185 */
186static inline uint32_t dt_clkmgr_primary_reg_block(
187 dt_clkmgr_t dt) {
188 return dt_clkmgr_reg_block(dt, kDtClkmgrRegBlockCore);
189}
190
191
192/**
193 * Get the alert ID of a clkmgr alert for a given instance.
194 *
195 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
196 * instances where the instance is not connected, the return value is unspecified.
197 *
198 * @param dt Instance of clkmgr.
199 * @param alert A clkmgr alert.
200 * @return The Alert Handler alert ID of the alert of this instance.
201 */
203 dt_clkmgr_t dt,
204 dt_clkmgr_alert_t alert);
205
206/**
207 * Convert a global alert ID to a local clkmgr alert type.
208 *
209 * @param dt Instance of clkmgr.
210 * @param alert A global alert ID that belongs to this instance.
211 * @return The clkmgr alert, or `kDtClkmgrAlertCount`.
212 *
213 * **Note:** This function assumes that the global alert ID belongs to the
214 * instance of clkmgr passed in parameter. In other words, it must be the case
215 * that `dt_clkmgr_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
216 * this function will return `kDtClkmgrAlertCount`.
217 */
219 dt_clkmgr_t dt,
220 dt_alert_id_t alert);
221
222
223
224/**
225 * Get the clock signal connected to a clock port of an instance.
226 *
227 * @param dt Instance of clkmgr.
228 * @param clk Clock port.
229 * @return Clock signal.
230 */
232 dt_clkmgr_t dt,
234
235/**
236 * Get the reset signal connected to a reset port of an instance.
237 *
238 * @param dt Instance of clkmgr.
239 * @param rst Reset port.
240 * @return Reset signal.
241 */
243 dt_clkmgr_t dt,
245
246
247
248/**
249 * Get the number of software gateable clocks.
250 *
251 * @param dt Instance of clkmgr.
252 * @return Number of gateable clocks.
253 */
255
256/**
257 * Get the instance ID of a gateable clock.
258 *
259 * The clocks are ordered as they appear in the registers.
260 *
261 * @param dt Instance of clkmgr.
262 * @param idx Index of the gateable clock, between 0 and `dt_clkmgr_sw_clock_count(dt)-1`.
263 * @return Instance ID of the device whose clock is gateable.
264 */
266
267/**
268 * Get the number of software hintable clocks.
269 *
270 * @param dt Instance of clkmgr.
271 * @return Number of hintable clocks.
272 */
274
275/**
276 * Get the instance ID of a hintable clock.
277 *
278 * The clocks sources are ordered as they appear in the registers.
279 *
280 * @param dt Instance of clkmgr.
281 * @param idx Index of the hintable clock, between 0 and `dt_clkmgr_hint_clock_count(dt)-1`.
282 * @return Instance ID of the device whose clock is hintable.
283 */
285
286/**
287 * Description of a measurable clock.
288 *
289 */
291 dt_clock_t clock; /**< Clock */
292 uint32_t meas_ctrl_en_off; /**< MEAS_CTRL_EN register offset */
293 bitfield_field32_t meas_ctrl_en_en_field; /**< MEAS_CTRL_EN_EN bitfield */
294 uint32_t meas_ctrl_shadowed_off; /**< CTRL_SHADOWED register offset */
295 bitfield_field32_t meas_ctrl_shadowed_lo_field; /**< CTRL_SHADOWED_LO bitfield */
296 bitfield_field32_t meas_ctrl_shadowed_hi_field; /**< CTRL_SHADOWED_HI bitfield */
298
299
300/**
301 * Get the number of measurable clocks.
302 *
303 * @param dt Instance of clkmgr.
304 * @return Number of measurable clocks.
305 */
307
308/**
309 * Get the description of a measurable clock.
310 *
311 * @param dt Instance of clkmgr.
312 * @param idx Index of the measurable clock, between 0 and
313 * `dt_clkmgr_measurable_clock_count(dt)-1`.
314 * @return Description of the measurable clock.
315 */
317
318
319
320#ifdef __cplusplus
321} // extern "C"
322#endif // __cplusplus
323
324#endif // OPENTITAN_DT_CLKMGR_H_