-
Notifications
You must be signed in to change notification settings - Fork 792
/
dif_clkmgr.h
408 lines (374 loc) · 12 KB
/
dif_clkmgr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_DIF_CLKMGR_H_
#define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_CLKMGR_H_
/**
* @file
* @brief <a href="/hw/top_earlgrey/ip_autogen/clkmgr/doc/">Clock Manager</a>
* Device Interface Functions
*/
#include <stdint.h>
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_base.h"
#include "sw/device/lib/dif/autogen/dif_clkmgr_autogen.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**
* An Index of a "Gateable" Clock.
*
* "Gateable" clocks are under full software control: they can be enabled and
* disabled by software, which directly starts and stops the identified clock.
*/
typedef uint32_t dif_clkmgr_gateable_clock_t;
/**
* An Index of a "Hintable" Clock.
*
* "Hintable" clocks are under partial software control: software can suggest
* they are stopped, but the clock manager may delay stopping the peripheral, or
* may ignore the request altogether.
*/
typedef uint32_t dif_clkmgr_hintable_clock_t;
typedef enum dif_clkmgr_measure_clock {
/**
* The Io clock.
*/
kDifClkmgrMeasureClockIo,
/**
* The Io_div2 clock.
*/
kDifClkmgrMeasureClockIoDiv2,
/**
* The Io div4 clock.
*/
kDifClkmgrMeasureClockIoDiv4,
/**
* The Main clock.
*/
kDifClkmgrMeasureClockMain,
/**
* The Usb clock.
*/
kDifClkmgrMeasureClockUsb,
} dif_clkmgr_measure_clock_t;
typedef enum dif_clkmgr_recov_err_type {
/**
* A recoverable update error for one of the clocks.
*/
kDifClkmgrRecovErrTypeShadowUpdate = 1u << 0,
/**
* A recoverable measurement error for IO clock.
*/
kDifClkmgrRecovErrTypeIoMeas = 1u << 1,
/**
* A recoverable measurement error for IO_DIV2 clock.
*/
kDifClkmgrRecovErrTypeIoDiv2Meas = 1u << 2,
/**
* A recoverable measurement error for IO_DIV4 clock.
*/
kDifClkmgrRecovErrTypeIoDiv4Meas = 1u << 3,
/**
* A recoverable measurement error for MAIN clock.
*/
kDifClkmgrRecovErrTypeMainMeas = 1u << 4,
/**
* A recoverable measurement error for USB clock.
*/
kDifClkmgrRecovErrTypeUsbMeas = 1u << 5,
/**
* A recoverable timeout error for IO clock.
*/
kDifClkmgrRecovErrTypeIoTimeout = 1u << 6,
/**
* A recoverable timeout error for IO_DIV2 clock.
*/
kDifClkmgrRecovErrTypeIoDiv2Timeout = 1u << 7,
/**
* A recoverable timeout error for IO_DIV4 clock.
*/
kDifClkmgrRecovErrTypeIoDiv4Timeout = 1u << 8,
/**
* A recoverable timeout error for MAIN clock.
*/
kDifClkmgrRecovErrTypeMainTimeout = 1u << 9,
/**
* A recoverable timeout error for USB clock.
*/
kDifClkmgrRecovErrTypeUsbTimeout = 1u << 10,
} dif_clkmgr_recov_err_type_t;
/**
* A set of recoverable errors.
*
* This type is used to clear and read the recoverable error codes.
*/
typedef uint32_t dif_clkmgr_recov_err_codes_t;
typedef enum dif_clkmgr_fatal_err_type {
/**
* A fatal error for regfile integrity.
*/
kDifClkmgrFatalErrTypeRegfileIntegrity = 1u << 0,
/**
* A fatal error for a duplicate idle counter.
*/
kDifClkmgrFatalErrTypeIdleCount = 1u << 1,
/**
* A fatal error for a shadow register storage.
*/
kDifClkmgrFatalErrTypeShadowStorage = 1u << 2,
} dif_clkmgr_fatal_err_type_t;
/**
* A set of fatal errors.
*
* This type is used to read the fatal error codes.
*/
typedef uint32_t dif_clkmgr_fatal_err_codes_t;
/**
* Check if jitter is Enabled.
* @param clkmgr Clock Manager Handle.
* @param[out] is_enabled whether jitter is enabled or not.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_jitter_get_enabled(const dif_clkmgr_t *clkmgr,
dif_toggle_t *state);
/**
* Enable of Disable jitter.
* @param clkmgr Clock Manager Handle.
* @param new_state whether to enable or disable jitter.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_jitter_set_enabled(const dif_clkmgr_t *clkmgr,
dif_toggle_t new_state);
/**
* Check if a Gateable Clock is Enabled or Disabled.
*
* @param clkmgr Clock Manager Handle.
* @param clock Gateable Clock ID.
* @param[out] is_enabled whether the clock is enabled or not.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_gateable_clock_get_enabled(
const dif_clkmgr_t *clkmgr, dif_clkmgr_gateable_clock_t clock,
dif_toggle_t *state);
/**
* Enable or Disable a Gateable Clock.
*
* @param clkmgr Clock Manager Handle.
* @param clock Gateable Clock ID.
* @param new_state whether to enable or disable the clock.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_gateable_clock_set_enabled(
const dif_clkmgr_t *clkmgr, dif_clkmgr_gateable_clock_t clock,
dif_toggle_t new_state);
/**
* Check if a Hintable Clock is Enabled or Disabled.
*
* Hintable clocks are not under full software control, but this operation
* accurately reflects the state of the current clock, regardless of any hint
* requests made by software.
*
* To read what hint the software has given the hardware, use
* #dif_clkmgr_hintable_clock_get_hint.
*
* @param clkmgr Clock Manager Handle.
* @param clock Hintable Clock ID.
* @param[out] is_enabled whether the clock is enabled or not.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_hintable_clock_get_enabled(
const dif_clkmgr_t *clkmgr, dif_clkmgr_hintable_clock_t clock,
dif_toggle_t *state);
/**
* Enable or Disable a Hintable Clock.
*
* This only sets a hint that the clock should be enabled or disabled. The clock
* manager is in control of whether the clock should actually be enabled or
* disabled.
*
* To read what hint the software has given the hardware, use
* #dif_clkmgr_hintable_clock_get_hint. To read whether the clock is currently
* enabled or disabled, use #dif_clkmgr_hintable_clock_get_enabled.
*
* @param clkmgr Clock Manager Handle.
* @param clock Hintable Clock ID.
* @param new_state whether to enable or disable the clock.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_hintable_clock_set_hint(
const dif_clkmgr_t *clkmgr, dif_clkmgr_hintable_clock_t clock,
dif_toggle_t new_state);
/**
* Read the current Hint for a Hintable Clock.
*
* Hintable clocks are not under full software control; this operation
* accurately reflects the current software hint, not the current state of the
* clock.
*
* To read whether the clock is currently enabled or disabled, use
* #dif_clkmgr_hintable_clock_get_enabled.
*
* @param clkmgr Clock Manager Handle.
* @param clock Hintable Clock ID.
* @param[out] hinted_is_enabled the current software request (hint) for this
* clock.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_hintable_clock_get_hint(
const dif_clkmgr_t *clkmgr, dif_clkmgr_hintable_clock_t clock,
dif_toggle_t *state);
/**
* Enable chip to use the external clock.
*
* @param clkmgr Clock Manager Handle.
* @param is_low_speed External clock is low speed or high speed.
* @returns The result of the operation.
* High speed - external clock is close to nominal speeds (e.g. external clock
* is 96MHz and nominal frequency is 96MHz-100MHz). Low speed - external clock
* is half of nominal speeds (e.g. external clock is 48MHz and nominal frequency
* is 96MHz-100MHz).
*
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_external_clock_set_enabled(const dif_clkmgr_t *clkmgr,
bool is_low_speed);
/**
* Disable chip to use the external clock.
*
* @param clkmgr Clock Manager Handle.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_external_clock_set_disabled(const dif_clkmgr_t *clkmgr);
/**
* Determine if the transition to using external clock is complete.
*
* @param clkmgr Clock Manager Handle.
* @param[out] status Set to true if the transition is complete.
* @returns The result of the operation once it completes.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_external_clock_is_settled(const dif_clkmgr_t *clkmgr,
bool *status);
/**
* Disable measurement control updates.
*
* This can only be disabled, and stays disabled until the next POR.
*
* @param clkmgr Clock Manager Handle.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_measure_ctrl_disable(const dif_clkmgr_t *clkmgr);
/**
* Get measurement control state.
*
* @param clkmgr Clock Manager Handle.
* @param[out] state The state of control enable.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_measure_ctrl_get_enable(const dif_clkmgr_t *clkmgr,
dif_toggle_t *state);
/**
* Configure count measurements.
*
* @param clkmgr Clock Manager Handle.
* @param clock A clock to be measured.
* @param min_threshold The smallest permissible cycle count.
* @param max_threshold The largest permissible cycle count.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_enable_measure_counts(const dif_clkmgr_t *clkmgr,
dif_clkmgr_measure_clock_t clock,
uint32_t min_threshold,
uint32_t max_threshold);
/**
* Disable count measurements.
*
* Does not modify the thresholds.
*
* @param clkmgr Clock Manager Handle.
* @param clock A clock to be measured.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_disable_measure_counts(
const dif_clkmgr_t *clkmgr, dif_clkmgr_measure_clock_t clock);
/**
* Get the count measurement enable.
*
* @param clkmgr Clock Manager Handle.
* @param clock A clock to be measured.
* @param[out] state The state of control enable.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_measure_counts_get_enable(
const dif_clkmgr_t *clkmgr, dif_clkmgr_measure_clock_t clock,
dif_toggle_t *state);
/**
* Get the count measurement thresholds.
*
* @param clkmgr Clock Manager Handle.
* @param clock A clock to be measured.
* @param[out] min_threshold The minumum threshold.
* @param[out] max_threshold The maximum threshold.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_measure_counts_get_thresholds(
const dif_clkmgr_t *clkmgr, dif_clkmgr_measure_clock_t clock,
uint32_t *min_threshold, uint32_t *max_threshold);
/**
* Read the recoverable error codes.
*
* @param clkmgr Clock Manager Handle.
* @param[out] codes The recoverable error codes.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_recov_err_code_get_codes(
const dif_clkmgr_t *clkmgr, dif_clkmgr_recov_err_codes_t *codes);
/**
* Clear selected recoverable error codes.
*
* @param clkmgr Clock Manager Handle.
* @param codes The recoverable error codes to be cleared.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_recov_err_code_clear_codes(
const dif_clkmgr_t *clkmgr, dif_clkmgr_recov_err_codes_t codes);
/**
* Read the fatal error codes.
*
* @param clkmgr Clock Manager Handle.
* @param[out] codes The fatal error codes.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_fatal_err_code_get_codes(
const dif_clkmgr_t *clkmgr, dif_clkmgr_fatal_err_codes_t *codes);
/**
* Wait for external clock switch to finish.
*
* @param clkmgr Clock Manager Handle.
* @returns The result of the operation.
*/
OT_WARN_UNUSED_RESULT
dif_result_t dif_clkmgr_wait_for_ext_clk_switch(const dif_clkmgr_t *clkmgr);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_CLKMGR_H_