blob: a8805cfc347cd30e29be9ca4e3223cc55d37a93f [file] [log] [blame]
Srikrishna Iyer0e687042021-10-23 14:53:47 -07001// Copyright lowRISC contributors.
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_DIF_SYSRST_CTRL_H_
6#define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_SYSRST_CTRL_H_
7
8/**
9 * @file
10 * @brief <a href="/hw/ip/sysrst_ctrl/doc/">System Reset Controller</a> Device
11 * Interface Functions
12 */
13
14#include "sw/device/lib/dif/autogen/dif_sysrst_ctrl_autogen.h"
Abdullah Varicie7b94fb2022-10-17 14:47:23 +010015#include "sysrst_ctrl_regs.h" // Generated.
Srikrishna Iyer0e687042021-10-23 14:53:47 -070016
17#ifdef __cplusplus
18extern "C" {
19#endif // __cplusplus
20
Timothy Trippelb665bea2022-04-22 15:19:01 -070021/**
22 * A System Reset Controller key combination.
23 */
24typedef enum dif_sysrst_ctrl_key_combo {
25 /**
26 * Key combination 0.
27 */
28 kDifSysrstCtrlKeyCombo0 = 1U << 0,
29 /**
30 * Key combination 1.
31 */
32 kDifSysrstCtrlKeyCombo1 = 1U << 1,
33 /**
34 * Key combination 2.
35 */
36 kDifSysrstCtrlKeyCombo2 = 1U << 2,
37 /**
38 * Key combination 3.
39 */
40 kDifSysrstCtrlKeyCombo3 = 1U << 3,
41 /**
42 * All key combination ORed together.
43 *
44 * This is useful when clearing all key combination IRQ causes at once, e.g.,
45 * when initializing the System Reset Controller.
46 */
47 kDifSysrstCtrlKeyComboAll = (1U << 4) - 1,
48} dif_sysrst_ctrl_key_combo_t;
49
50/**
51 * System Reset Controller keys that can form a key combination.
52 */
53typedef enum dif_sysrst_ctrl_key {
54 /**
55 * Key 0.
56 */
57 kDifSysrstCtrlKey0 = 1U << 0,
58 /**
59 * Key 1.
60 */
61 kDifSysrstCtrlKey1 = 1U << 1,
62 /**
63 * Key 2.
64 */
65 kDifSysrstCtrlKey2 = 1U << 2,
66 /**
67 * Power button key.
68 */
69 kDifSysrstCtrlKeyPowerButton = 1U << 3,
70 /**
71 * AC power preset key.
72 */
73 kDifSysrstCtrlKeyAcPowerPresent = 1U << 4,
Timothy Trippel50e6d102022-04-27 14:50:42 -070074 /**
75 * All keys ORed together.
76 */
77 kDifSysrstCtrlKeyAll = (1U << 5) - 1,
Timothy Trippelb665bea2022-04-22 15:19:01 -070078} dif_sysrst_ctrl_key_t;
79
80/**
81 * System Reset Controller key combination detection actions.
82 */
83typedef enum dif_sysrst_ctrl_key_combo_action {
84 /**
85 * Disable / disconnect battery.
86 */
87 kDifSysrstCtrlKeyComboActionBatteryDisable = 1U << 0,
88 /**
89 * Issue an interrupt to the processor.
90 */
91 kDifSysrstCtrlKeyComboActionInterrupt = 1U << 1,
92 /**
93 * Assert the embedded controller reset for a specified duration.
94 */
95 kDifSysrstCtrlKeyComboActionEcReset = 1U << 2,
96 /**
97 * Issue a reset request to the reset manager block.
98 */
99 kDifSysrstCtrlKeyComboActionSelfReset = 1U << 3,
Timothy Trippel50e6d102022-04-27 14:50:42 -0700100 /**
101 * All actions.
102 */
103 kDifSysrstCtrlKeyComboActionAll = (1U << 4) - 1,
Timothy Trippelb665bea2022-04-22 15:19:01 -0700104} dif_sysrst_ctrl_key_combo_action_t;
105
106/**
107 * Runtime configuration for the System Reset Controller key combination
108 * detection feature.
109 */
110typedef struct dif_sysrst_ctrl_key_combo_config {
111 /**
Timothy Trippelb665bea2022-04-22 15:19:01 -0700112 * The keys that comprise the key combination to detect (i.e., one or more
113 * `dif_sysrst_ctrl_key_t`s ORed together).
114 */
115 uint32_t keys;
116 /**
117 * The duration the key combination should be pressed to trigger an action.
118 *
119 * Units: increments of 5us; [0, 2^32) represents [0, 60) seconds.
120 */
121 uint32_t detection_time_threshold;
122 /**
123 * The actions to trigger after detecting the key press combination (one or
124 * more `dif_sysrst_ctrl_key_combo_action_t`s ORed together).
125 */
126 uint32_t actions;
127 /**
128 * The embedded controller's reset pulse width.
129 *
130 * Note: only applicable if the `kDifSysrstCtrlKeyComboActionEcReset` action
131 * is enabled for the key combination.
132 *
133 * Units: increments of 5us; [0, 2^16) represents [10, 200) milliseconds.
134 */
Timothy Trippel50e6d102022-04-27 14:50:42 -0700135 uint16_t embedded_controller_reset_duration;
Timothy Trippelb665bea2022-04-22 15:19:01 -0700136} dif_sysrst_ctrl_key_combo_config_t;
137
138/**
139 * System Reset Controller input signal changes that may be detected.
140 */
141typedef enum dif_sysrst_ctrl_input_change {
142 /**
143 * Power button input signal high-to-low.
144 */
145 kDifSysrstCtrlInputPowerButtonH2L = 1U << 0,
146 /**
147 * Key 0 input signal high-to-low.
148 */
149 kDifSysrstCtrlInputKey0H2L = 1U << 1,
150 /**
151 * Key 1 input signal high-to-low.
152 */
153 kDifSysrstCtrlInputKey1H2L = 1U << 2,
154 /**
155 * Key 2 input signal high-to-low.
156 */
157 kDifSysrstCtrlInputKey2H2L = 1U << 3,
158 /**
159 * AC power present input signal high-to-low.
160 */
161 kDifSysrstCtrlInputAcPowerPresetH2L = 1U << 4,
162 /**
163 * Embedded controller reset input signal high-to-low.
164 */
165 kDifSysrstCtrlInputEcResetH2L = 1U << 5,
166 /**
167 * Flash write protect input signal high-to-low.
168 */
169 kDifSysrstCtrlInputFlashWriteProtectH2L = 1U << 6,
170 /**
171 * Power button input signal low-to-high.
172 */
Abdullah Varici3bb4b9c2022-12-06 16:18:12 +0000173 kDifSysrstCtrlInputPowerButtonL2H = 1U << 7,
Timothy Trippelb665bea2022-04-22 15:19:01 -0700174 /**
175 * Key 0 input signal low-to-high.
176 */
Abdullah Varici3bb4b9c2022-12-06 16:18:12 +0000177 kDifSysrstCtrlInputKey0L2H = 1U << 8,
Timothy Trippelb665bea2022-04-22 15:19:01 -0700178 /**
179 * Key 1 input signal low-to-high.
180 */
Abdullah Varici3bb4b9c2022-12-06 16:18:12 +0000181 kDifSysrstCtrlInputKey1L2H = 1U << 9,
Timothy Trippelb665bea2022-04-22 15:19:01 -0700182 /**
183 * Key 2 input signal low-to-high.
184 */
Abdullah Varici3bb4b9c2022-12-06 16:18:12 +0000185 kDifSysrstCtrlInputKey2L2H = 1U << 10,
Timothy Trippelb665bea2022-04-22 15:19:01 -0700186 /**
187 * AC power present input signal low-to-high.
188 */
Abdullah Varici3bb4b9c2022-12-06 16:18:12 +0000189 kDifSysrstCtrlInputAcPowerPresetL2H = 1U << 11,
Timothy Trippelb665bea2022-04-22 15:19:01 -0700190 /**
191 * Embedded controller reset input signal low-to-high.
192 */
Abdullah Varici3bb4b9c2022-12-06 16:18:12 +0000193 kDifSysrstCtrlInputEcResetL2H = 1U << 12,
Timothy Trippelb665bea2022-04-22 15:19:01 -0700194 /**
195 * Flash write protect input signal low-to-high.
196 */
Abdullah Varici3bb4b9c2022-12-06 16:18:12 +0000197 kDifSysrstCtrlInputFlashWriteProtectL2H = 1U << 13,
Timothy Trippel0c1cf2d2022-04-27 17:18:22 -0700198 /**
199 * All input signal transitions.
200 */
Abdullah Varici3bb4b9c2022-12-06 16:18:12 +0000201 kDifSysrstCtrlInputAll = ((1U << 14) - 1),
Timothy Trippelb665bea2022-04-22 15:19:01 -0700202} dif_sysrst_ctrl_input_change_t;
203
204/**
Abdullah Varicie7b94fb2022-10-17 14:47:23 +0100205 * System Reset Controller key interrupt sources.
206 */
207typedef enum dif_sysrst_ctrl_key_intr_src {
208 /**
209 * Power button input signal high-to-low.
210 */
211 kDifSysrstCtrlKeyIntrStatusInputPowerButtonH2L =
212 1U << SYSRST_CTRL_KEY_INTR_STATUS_PWRB_H2L_BIT,
213 /**
214 * Key 0 input signal high-to-low.
215 */
216 kDifSysrstCtrlKeyIntrStatusInputKey0H2L =
217 1U << SYSRST_CTRL_KEY_INTR_STATUS_KEY0_IN_H2L_BIT,
218 /**
219 * Key 1 input signal high-to-low.
220 */
221 kDifSysrstCtrlKeyIntrStatusInputKey1H2L =
222 1U << SYSRST_CTRL_KEY_INTR_STATUS_KEY1_IN_H2L_BIT,
223 /**
224 * Key 2 input signal high-to-low.
225 */
226 kDifSysrstCtrlKeyIntrStatusInputKey2H2L =
227 1U << SYSRST_CTRL_KEY_INTR_STATUS_KEY2_IN_H2L_BIT,
228 /**
229 * AC power present input signal high-to-low.
230 */
231 kDifSysrstCtrlKeyIntrStatusInputAcPowerPresetH2L =
232 1U << SYSRST_CTRL_KEY_INTR_STATUS_AC_PRESENT_H2L_BIT,
233 /**
234 * Embedded controller reset input signal high-to-low.
235 */
236 kDifSysrstCtrlKeyIntrStatusInputEcResetH2L =
237 1U << SYSRST_CTRL_KEY_INTR_STATUS_EC_RST_L_H2L_BIT,
238 /**
239 * Flash write protect input signal high-to-low.
240 */
241 kDifSysrstCtrlKeyIntrStatusInputFlashWriteProtectH2L =
242 1U << SYSRST_CTRL_KEY_INTR_STATUS_FLASH_WP_L_H2L_BIT,
243 /**
244 * Power button input signal low-to-high.
245 */
246 kDifSysrstCtrlKeyIntrStatusInputPowerButtonL2H =
247 1U << SYSRST_CTRL_KEY_INTR_STATUS_PWRB_L2H_BIT,
248 /**
249 * Key 0 input signal low-to-high.
250 */
251 kDifSysrstCtrlKeyIntrStatusInputKey0L2H =
252 1U << SYSRST_CTRL_KEY_INTR_STATUS_KEY0_IN_L2H_BIT,
253 /**
254 * Key 1 input signal low-to-high.
255 */
256 kDifSysrstCtrlKeyIntrStatusInputKey1L2H =
257 1U << SYSRST_CTRL_KEY_INTR_STATUS_KEY1_IN_L2H_BIT,
258 /**
259 * Key 2 input signal low-to-high.
260 */
261 kDifSysrstCtrlKeyIntrStatusInputKey2L2H =
262 1U << SYSRST_CTRL_KEY_INTR_STATUS_KEY2_IN_L2H_BIT,
263 /**
264 * AC power present input signal low-to-high.
265 */
266 kDifSysrstCtrlKeyIntrStatusInputAcPowerPresetL2H =
267 1U << SYSRST_CTRL_KEY_INTR_STATUS_AC_PRESENT_L2H_BIT,
268 /**
269 * Embedded controller reset input signal low-to-high.
270 */
271 kDifSysrstCtrlKeyIntrStatusInputEcResetL2H =
272 1U << SYSRST_CTRL_KEY_INTR_STATUS_EC_RST_L_L2H_BIT,
273 /**
274 * Flash write protect input signal low-to-high.
275 */
276 kDifSysrstCtrlKeyIntrStatusInputFlashWriteProtectL2H =
277 1U << SYSRST_CTRL_KEY_INTR_STATUS_FLASH_WP_L_L2H_BIT,
278} dif_sysrst_ctrl_key_intr_src_t;
279
280/**
281 * System Reset Controller combo interrupt sources.
282 */
283typedef enum dif_sysrst_ctrl_combo_intr_src {
284 /**
285 * Power button input signal high-to-low.
286 */
287 kDifSysrstCtrlComboIntrStatusCombo0H2L =
288 1U << SYSRST_CTRL_COMBO_INTR_STATUS_COMBO0_H2L_BIT,
289 /**
290 * Key 0 input signal high-to-low.
291 */
292 kDifSysrstCtrlComboIntrStatusCombo1H2L =
293 1U << SYSRST_CTRL_COMBO_INTR_STATUS_COMBO1_H2L_BIT,
294 /**
295 * Key 1 input signal high-to-low.
296 */
297 kDifSysrstCtrlComboIntrStatusCombo2H2L =
298 1U << SYSRST_CTRL_COMBO_INTR_STATUS_COMBO2_H2L_BIT,
299 /**
300 * Key 2 input signal high-to-low.
301 */
302 kDifSysrstCtrlComboIntrStatusCombo3H2L =
303 1U << SYSRST_CTRL_COMBO_INTR_STATUS_COMBO3_H2L_BIT,
304} dif_sysrst_ctrl_combo_intr_src_t;
305
306/**
Timothy Trippelb665bea2022-04-22 15:19:01 -0700307 * Runtime configuration for the System Reset Controller input signal change
308 * detection feature.
309 */
310typedef struct dif_sysrst_ctrl_input_change_config {
311 /**
312 * A combination of input signal changes to detect (one or more
313 * `dif_sysrst_ctrl_input_change_t`s ORed together).
314 */
315 uint32_t input_changes;
316 /**
317 * The time to allow the input signal to stabilize before reevaluating its
318 * value to decide whether to trigger an interrupt.
319 *
320 * Units: increments of 5us; [0, 2^16) represents [0, 200) milliseconds.
321 */
322 uint16_t debounce_time_threshold;
323} dif_sysrst_ctrl_input_change_config_t;
324
325/**
326 * Runtime configuration for the System Reset Controller key signal
327 * auto-override feature.
328 *
329 * Upon detection of a Power Button high-to-low transition, the signals from
330 * generic keys 0 through 2 may be overriden with specified values.
331 */
332typedef struct dif_sysrst_ctrl_auto_override_config {
333 /**
334 * The time to allow the Power Button signal to stabilize before reevaluating
335 * its value to decide whether it was pressed.
336 *
337 * Units: increments of 5us; [0, 2^16) represents [0, 200) milliseconds.
338 */
339 uint16_t debounce_time_threshold;
340 /**
341 * Whether to override the key 0 signal.
342 */
343 dif_toggle_t override_key_0;
344 /**
345 * The value to override onto the key 0 signal.
346 */
347 bool key_0_override_value;
348 /**
349 * Whether to override the key 1 signal.
350 */
351 dif_toggle_t override_key_1;
352 /**
353 * The value to override onto the key 1 signal.
354 */
355 bool key_1_override_value;
356 /**
357 * Whether to override the key 2 signal.
358 */
359 dif_toggle_t override_key_2;
360 /**
361 * The value to override onto the key 2 signal.
362 */
363 bool key_2_override_value;
364} dif_sysrst_ctrl_auto_override_config_t;
365
366/**
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700367 * System Reset Controller pins that can be inverted, read, or overridden.
368 */
369typedef enum dif_sysrst_ctrl_pin {
370 /**
371 * Key 0 input.
372 */
373 kDifSysrstCtrlPinKey0In = 1U << 0,
374 /**
375 * Key 0 output.
376 */
377 kDifSysrstCtrlPinKey0Out = 1U << 1,
378 /**
379 * Key 1 input.
380 */
381 kDifSysrstCtrlPinKey1In = 1U << 2,
382 /**
383 * Key 1 output.
384 */
385 kDifSysrstCtrlPinKey1Out = 1U << 3,
386 /**
387 * Key 2 input.
388 */
389 kDifSysrstCtrlPinKey2In = 1U << 4,
390 /**
391 * Key 2 output.
392 */
393 kDifSysrstCtrlPinKey2Out = 1U << 5,
394 /**
395 * Power button input.
396 */
397 kDifSysrstCtrlPinPowerButtonIn = 1U << 6,
398 /**
399 * Power button output.
400 */
401 kDifSysrstCtrlPinPowerButtonOut = 1U << 7,
402 /**
403 * AC power preset input.
404 */
405 kDifSysrstCtrlPinAcPowerPresentIn = 1U << 8,
406 /**
407 * Battery disable output.
408 */
409 kDifSysrstCtrlPinBatteryDisableOut = 1U << 9,
410 /**
411 * Lid open input.
412 */
413 kDifSysrstCtrlPinLidOpenIn = 1U << 10,
414 /**
415 * Z3 Wakeup output.
416 */
417 kDifSysrstCtrlPinZ3WakeupOut = 1U << 11,
418 /**
419 * Embedded controller reset inout.
420 */
421 kDifSysrstCtrlPinEcResetInOut = 1U << 12,
422 /**
423 * Flash write protect inout.
424 */
Timothy Trippel0c1cf2d2022-04-27 17:18:22 -0700425 kDifSysrstCtrlPinFlashWriteProtectInOut = 1U << 13,
Timothy Trippela5dd3392022-04-29 18:03:44 -0700426 /**
427 * All non open drain pins.
428 */
429 kDifSysrstCtrlPinAllNonOpenDrain = (1U << 12) - 1,
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700430} dif_sysrst_ctrl_pin_t;
431
432/**
433 * Runtime configuration for the System Reset Controller output pin override
434 * feature.
435 */
436typedef struct dif_sysrst_ctrl_pin_config_t {
437 /**
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700438 * The enablement of the output pin's override feature.
439 */
Timothy Trippel0c1cf2d2022-04-27 17:18:22 -0700440 dif_toggle_t enabled;
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700441 /**
442 * Whether to allow overriding the output pin with a value of 0.
443 */
444 bool allow_zero;
445 /**
446 * Whether to allow overriding the output pin with a value of 1.
447 */
448 bool allow_one;
449 /**
450 * The override value to write.
451 *
452 * Note: writing a non-allowable value will cause
453 * `dif_sysrst_ctrl_output_pin_override_configure()` to return `kDifBadArg`.
454 */
455 bool override_value;
456} dif_sysrst_ctrl_pin_config_t;
457
458/**
459 * Runtime configuration for the System Reset Controller ultra-low-power (ULP)
460 * wakeup feature.
461 *
462 * When enabled, detection of any of the following conditions:
463 *
464 * 1. HIGH level on the AC Power present signal, or
465 * 2. HIGH --> LOW transition on the Power Button signal, or
466 * 3. LOW --> HIGH transition on the Lid Open signal,
467 *
468 * will cause the System Reset Controller to assert the Z3 Wakeup output signal
469 * and trigger an interrupt, which will also issue a wakeup request to the power
470 * manager.
471 */
472typedef struct dif_sysrst_ctrl_ulp_wakeup_config_t {
473 /**
Timothy Trippel0c1cf2d2022-04-27 17:18:22 -0700474 * The enablement of the ULP wakeup feature.
475 */
476 dif_toggle_t enabled;
477 /**
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700478 * The time to allow the AC Power present signal to stabilize before
479 * reevaluating its value to decide whether it was activated.
480 *
481 * Units: increments of 5us; [0, 2^16) represents [10, 200) milliseconds.
482 */
483 uint16_t ac_power_debounce_time_threshold;
484 /**
485 * The time to allow the Lid Open signal to stabilize before reevaluating its
486 * value to decide whether it was activated.
487 *
488 * Units: increments of 5us; [0, 2^16) represents [10, 200) milliseconds.
489 */
Timothy Trippel0c1cf2d2022-04-27 17:18:22 -0700490 uint16_t lid_open_debounce_time_threshold;
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700491 /**
492 * The time to allow the Power Button signal to stabilize before reevaluating
493 * its value to decide whether it was pressed.
494 *
495 * Units: increments of 5us; [0, 2^16) represents [10, 200) milliseconds.
496 */
497 uint16_t power_button_debounce_time_threshold;
498} dif_sysrst_ctrl_ulp_wakeup_config_t;
499
500/**
Timothy Trippelb665bea2022-04-22 15:19:01 -0700501 * Configures a System Reset Controller's key combination detection feature.
502 *
503 * @param sysrst_ctrl A System Reset Controller handle.
Timothy Trippel50e6d102022-04-27 14:50:42 -0700504 * @param key_combo Key combination to configure.
Timothy Trippelb665bea2022-04-22 15:19:01 -0700505 * @param config Runtime configuration parameters.
506 * @return The result of the operation.
507 */
508OT_WARN_UNUSED_RESULT
509dif_result_t dif_sysrst_ctrl_key_combo_detect_configure(
Timothy Trippel50e6d102022-04-27 14:50:42 -0700510 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_key_combo_t key_combo,
Timothy Trippelb665bea2022-04-22 15:19:01 -0700511 dif_sysrst_ctrl_key_combo_config_t config);
512
513/**
514 * Configures a System Reset Controller's input signal change detection feature.
515 *
516 * @param sysrst_ctrl A System Reset Controller handle.
517 * @param config Runtime configuration parameters.
518 * @return The result of the operation.
519 */
520OT_WARN_UNUSED_RESULT
521dif_result_t dif_sysrst_ctrl_input_change_detect_configure(
522 const dif_sysrst_ctrl_t *sysrst_ctrl,
523 dif_sysrst_ctrl_input_change_config_t config);
524
525/**
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700526 * Configures a System Reset Controller's output pin override feature.
527 *
528 * Note, only output (or inout) pins may be overriden, i.e., set to a specific
529 * value. Attempting to configure the override feature for input pins will
Timothy Trippel0c1cf2d2022-04-27 17:18:22 -0700530 * return `kDifBadArg`.
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700531 *
532 * @param sysrst_ctrl A System Reset Controller handle.
Timothy Trippel0c1cf2d2022-04-27 17:18:22 -0700533 * @param output_pin Output pin to configure.
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700534 * @param config Output pin override configuration parameters.
535 * @return The result of the operation.
536 */
537OT_WARN_UNUSED_RESULT
538dif_result_t dif_sysrst_ctrl_output_pin_override_configure(
Timothy Trippel0c1cf2d2022-04-27 17:18:22 -0700539 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_pin_t output_pin,
540 dif_sysrst_ctrl_pin_config_t config);
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700541
542/**
Timothy Trippelfea9dea2022-05-02 16:01:21 -0700543 * Configures a System Reset Controller's key signal auto-override feature.
544 *
545 * Upon detection of a Power Button high-to-low transition, the signals from
546 * generic keys 0 through 2 may be overriden with specified values.
547 *
548 * @param sysrst_ctrl A System Reset Controller handle.
549 * @param config Runtime configuration parameters.
550 * @param enabled Whether to enable the feature or not.
551 * @return The result of the operation.
552 */
553OT_WARN_UNUSED_RESULT
554dif_result_t dif_sysrst_ctrl_auto_override_configure(
555 const dif_sysrst_ctrl_t *sysrst_ctrl,
556 dif_sysrst_ctrl_auto_override_config_t config, dif_toggle_t enabled);
557
558/**
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700559 * Configures a System Reset Controller's ultra-low-power (ULP) wakeup feature.
560 *
561 * @param sysrst_ctrl A System Reset Controller handle.
562 * @param config Runtime configuration parameters.
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700563 * @return The result of the operation.
564 */
565OT_WARN_UNUSED_RESULT
566dif_result_t dif_sysrst_ctrl_ulp_wakeup_configure(
567 const dif_sysrst_ctrl_t *sysrst_ctrl,
Timothy Trippel0c1cf2d2022-04-27 17:18:22 -0700568 dif_sysrst_ctrl_ulp_wakeup_config_t config);
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700569
570/**
571 * Sets the enablement state of a System Reset Controller's ultra-low-power
572 * (ULP) wakeup feature.
573 *
574 * @param sysrst_ctrl A System Reset Controller handle.
575 * @param enabled The enablement state to configure the ULP wakeup feature in.
576 * @return The result of the operation.
577 */
578OT_WARN_UNUSED_RESULT
579dif_result_t dif_sysrst_ctrl_ulp_wakeup_set_enabled(
580 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_toggle_t enabled);
581
582/**
583 * Gets the enablement state of a System Reset Controller's ultra-low-power
584 * (ULP) wakeup feature.
585 *
586 * @param sysrst_ctrl A System Reset Controller handle.
587 * @param[out] is_enabled The enablement state of the ULP wakeup feature.
588 * @return The result of the operation.
589 */
590OT_WARN_UNUSED_RESULT
591dif_result_t dif_sysrst_ctrl_ulp_wakeup_get_enabled(
592 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_toggle_t *is_enabled);
593
594/**
595 * Sets the inversion state a System Reset Controller's input and output pins.
596 *
597 * Note, only input and output (NOT inout) pins may be inverted. Attempting
598 * to set the inversion state of inout pins will return `kDifBadArg`.
599 *
600 * @param sysrst_ctrl A System Reset Controller handle.
601 * @param pins The input and output pins to set the inverted state of (i.e., one
602 * or more `dif_sysrst_ctrl_pin_t`s ORed together).
603 * @param inverted The inverted state to configure for the pins.
604 * @return The result of the operation.
605 */
606OT_WARN_UNUSED_RESULT
607dif_result_t dif_sysrst_ctrl_pins_set_inverted(
608 const dif_sysrst_ctrl_t *sysrst_ctrl, uint32_t pins, bool inverted);
609
610/**
611 * Gets the inversion state a System Reset Controller's input and output pins.
612 *
613 * @param sysrst_ctrl A System Reset Controller handle.
614 * @param[out] inverted_pins The input and output pins that are inverted (i.e.,
615 * one or more `dif_sysrst_ctrl_pin_t`s ORed
616 * together).
617 * @return The result of the operation.
618 */
619OT_WARN_UNUSED_RESULT
620dif_result_t dif_sysrst_ctrl_pins_get_inverted(
621 const dif_sysrst_ctrl_t *sysrst_ctrl, uint32_t *inverted_pins);
622
623/**
624 * Sets allowable override values for a System Reset Controller's output pin.
625 *
626 * Note, only output (or inout) pins may be overriden, i.e., set to a specific
627 * value. Attempting to set the allowable override values for input pins will
628 * return `kDifBadArg`.
629 *
630 * @param sysrst_ctrl A System Reset Controller handle.
631 * @param pin The output pin whose allowable override values should be set.
632 * @param allow_zero Whether to allow overriding the pin's value to 0.
633 * @param allow_one Whether to allow overriding the pin's value to 1.
634 * @return The result of the operation.
635 */
636OT_WARN_UNUSED_RESULT
637dif_result_t dif_sysrst_ctrl_output_pin_override_set_allowed(
638 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_pin_t pin,
639 bool allow_zero, bool allow_one);
640
641/**
642 * Gets allowable override values for a System Reset Controller's output pin.
643 *
644 * Note, only output (or inout) pins may be overriden, i.e., set to a specific
645 * value. Attempting to get the allowable override values for input pins will
646 * return `kDifBadArg`.
647 *
648 * @param sysrst_ctrl A System Reset Controller handle.
649 * @param pin The allowable override values to get for an output pin.
650 * @param[out] allow_zero Whether overriding the pin's value to 0 is allowed.
651 * @param[out] allow_one Whether overriding the pin's value to 1 is allowed.
652 * @return The result of the operation.
653 */
654OT_WARN_UNUSED_RESULT
655dif_result_t dif_sysrst_ctrl_output_pin_override_get_allowed(
656 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_pin_t pin,
657 bool *allow_zero, bool *allow_one);
658
659/**
660 * Sets the enablement of a System Reset Controller's output pin override
661 * feature.
662 *
663 * Note, only output (or inout) pins may be overriden, i.e., set to a specific
664 * value. Attempting to set the enablement of the override feature for input
665 * pins will return `kDifBadArg`.
666 *
667 * @param sysrst_ctrl A System Reset Controller handle.
668 * @param pin The output pin whose override feature should be set.
669 * @param enabled The enablement state to configure the override feature in.
670 * @return The result of the operation.
671 */
672OT_WARN_UNUSED_RESULT
673dif_result_t dif_sysrst_ctrl_output_pin_override_set_enabled(
674 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_pin_t pin,
675 dif_toggle_t enabled);
676
677/**
678 * Gets the enablement of a System Reset Controller's output pin override
679 * feature.
680 *
681 * Note, only output (or inout) pins may be overriden, i.e., set to a specific
682 * value. Attempting to get the enablement of the override feature for input
683 * pins will return `kDifBadArg`.
684 *
685 * @param sysrst_ctrl A System Reset Controller handle.
686 * @param pin The output pin whose override feature should be set.
687 * @param[out] is_enabled The enablement state the override feature is
688 * configured in.
689 * @return The result of the operation.
690 */
691OT_WARN_UNUSED_RESULT
692dif_result_t dif_sysrst_ctrl_output_pin_override_get_enabled(
693 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_pin_t pin,
694 dif_toggle_t *is_enabled);
695
696/**
697 * Sets the override value of a System Reset Controller's output pin (like
698 * writing to a GPIO pin).
699 *
700 * Note, only output (or inout) pins may be overriden, i.e., set to a specific
701 * value. Attempting to set the override value of an input pin will return
702 * `kDifBadArg`.
703 *
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700704 * @param sysrst_ctrl A System Reset Controller handle.
705 * @param pin The output pin to override.
706 * @param value The override value to set on the pin.
707 * @return The result of the operation.
708 */
709OT_WARN_UNUSED_RESULT
710dif_result_t dif_sysrst_ctrl_output_pin_set_override(
711 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_pin_t pin,
712 bool value);
713
714/**
715 * Gets the override value of a System Reset Controller's output pin (like
716 * writing to a GPIO pin).
717 *
718 * Note, only output (or inout) pins may be overriden, i.e., set to a specific
719 * value. Attempting to get the override value of an input pin will return
720 * `kDifBadArg`.
721 *
722 * Additionally, this will return the configured override value of an output pin
723 * regardless if the override function is enabled or the override value is
724 * allowed.
725 *
726 * @param sysrst_ctrl A System Reset Controller handle.
727 * @param pin The output pin to override.
728 * @param[out] value The override value set on the pin.
729 * @return The result of the operation.
730 */
731OT_WARN_UNUSED_RESULT
732dif_result_t dif_sysrst_ctrl_output_pin_get_override(
733 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_pin_t pin,
734 bool *value);
735
736/**
737 * Reads a System Reset Controller's input pin (like a GPIO pin).
738 *
739 * Note, only input (or inout) pins may be read. Attempting to read the value of
Timothy Trippel078b7232022-05-01 23:38:46 -0700740 * an output pin will return `kDifBadArg`.
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700741 *
742 * @param sysrst_ctrl A System Reset Controller handle.
743 * @param pin The pin to read.
Timothy Trippel078b7232022-05-01 23:38:46 -0700744 * @param[out] value The value set on the pin.
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700745 * @return The result of the operation.
746 */
747OT_WARN_UNUSED_RESULT
748dif_result_t dif_sysrst_ctrl_input_pin_read(
Timothy Trippel078b7232022-05-01 23:38:46 -0700749 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_pin_t pin,
750 bool *value);
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700751
752/**
Timothy Trippelb665bea2022-04-22 15:19:01 -0700753 * Sets the enablement of a System Reset Controller's key signal auto-override
754 * feature.
755 *
Timothy Trippelfea9dea2022-05-02 16:01:21 -0700756 * Note, this feature is only available for keys 0, 1, and 2. Attempting to
757 * enable the auto-override feature on non-supported keys will return
758 * `kDifBadArg`.
759 *
Timothy Trippelb665bea2022-04-22 15:19:01 -0700760 * @param sysrst_ctrl A System Reset Controller handle.
Timothy Trippelfea9dea2022-05-02 16:01:21 -0700761 * @param key The key to enable the override feature for.
Timothy Trippelb665bea2022-04-22 15:19:01 -0700762 * @param enabled Whether to enable the feature or not.
763 * @return The result of the operation.
764 */
765OT_WARN_UNUSED_RESULT
766dif_result_t dif_sysrst_ctrl_auto_override_set_enabled(
Timothy Trippelfea9dea2022-05-02 16:01:21 -0700767 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_key_t key,
768 dif_toggle_t enabled);
Timothy Trippelb665bea2022-04-22 15:19:01 -0700769
770/**
771 * Gets the enablement of a System Reset Controller's key signal auto-override
772 * feature.
773 *
Timothy Trippelfea9dea2022-05-02 16:01:21 -0700774 * Note, this feature is only available for keys 0, 1, and 2. Attempting to
775 * check whether the auto-override feature is enabled non-supported keys will
776 * return `kDifBadArg`.
777 *
Timothy Trippelb665bea2022-04-22 15:19:01 -0700778 * @param sysrst_ctrl A System Reset Controller handle.
Timothy Trippelfea9dea2022-05-02 16:01:21 -0700779 * @param key The key the override feature is enabled for.
Timothy Trippelb665bea2022-04-22 15:19:01 -0700780 * @param[out] is_enabled Whether the feature is enabled or not.
781 * @return The result of the operation.
782 */
783OT_WARN_UNUSED_RESULT
784dif_result_t dif_sysrst_ctrl_auto_override_get_enabled(
Timothy Trippelfea9dea2022-05-02 16:01:21 -0700785 const dif_sysrst_ctrl_t *sysrst_ctrl, dif_sysrst_ctrl_key_t key,
786 dif_toggle_t *is_enabled);
Timothy Trippelb665bea2022-04-22 15:19:01 -0700787
788/**
789 * Gets the cause(s) of a key combination detection IRQ.
790 *
791 * @param sysrst_ctrl An sysrst_ctrl handle.
792 * @param[out] causes The causes of the IRQ (one or more
793 * `dif_sysrst_ctrl_key_combo_t`s ORed together).
794 * @return The result of the operation.
795 */
796OT_WARN_UNUSED_RESULT
797dif_result_t dif_sysrst_ctrl_key_combo_irq_get_causes(
798 const dif_sysrst_ctrl_t *sysrst_ctrl, uint32_t *causes);
799
800/**
801 * Clears the cause(s) of a key combination detection IRQ.
802 *
803 * @param sysrst_ctrl An sysrst_ctrl handle.
804 * @param causes The causes of the IRQ (one or more
805 * `dif_sysrst_ctrl_key_combo_t`s ORed together).
806 * @return The result of the operation.
807 */
808OT_WARN_UNUSED_RESULT
809dif_result_t dif_sysrst_ctrl_key_combo_irq_clear_causes(
810 const dif_sysrst_ctrl_t *sysrst_ctrl, uint32_t causes);
811
812/**
813 * Gets the cause(s) of an input signal change detection IRQ.
814 *
815 * @param sysrst_ctrl An sysrst_ctrl handle.
816 * @param[out] causes The causes of the IRQ (one or more
817 * `dif_sysrst_ctrl_input_change_t`s ORed together).
818 * @return The result of the operation.
819 */
820OT_WARN_UNUSED_RESULT
821dif_result_t dif_sysrst_ctrl_input_change_irq_get_causes(
822 const dif_sysrst_ctrl_t *sysrst_ctrl, uint32_t *causes);
823
824/**
825 * Clears the cause(s) of an input signal change detection IRQ.
826 *
827 * @param sysrst_ctrl An sysrst_ctrl handle.
828 * @param causes The causes of the IRQ (one or more
829 * `dif_sysrst_ctrl_input_change_t`s ORed together).
830 * @return The result of the operation.
831 */
832OT_WARN_UNUSED_RESULT
833dif_result_t dif_sysrst_ctrl_input_change_irq_clear_causes(
834 const dif_sysrst_ctrl_t *sysrst_ctrl, uint32_t causes);
835
836/**
Timothy Trippelb37c11e2022-04-23 17:29:38 -0700837 * Gets the ultra-low-power wakeup status.
838 *
839 * @param sysrst_ctrl An sysrst_ctrl handle.
840 * @param[out] wakeup_detected The ULP wakeup detection state.
841 * @return The result of the operation.
842 */
843OT_WARN_UNUSED_RESULT
844dif_result_t dif_sysrst_ctrl_ulp_wakeup_get_status(
845 const dif_sysrst_ctrl_t *sysrst_ctrl, bool *wakeup_detected);
846
847/**
848 * Clears the ultra-low-power wakeup status.
849 *
850 * @param sysrst_ctrl An sysrst_ctrl handle.
851 * @return The result of the operation.
852 */
853OT_WARN_UNUSED_RESULT
854dif_result_t dif_sysrst_ctrl_ulp_wakeup_clear_status(
855 const dif_sysrst_ctrl_t *sysrst_ctrl);
856
857/**
Timothy Trippelb665bea2022-04-22 15:19:01 -0700858 * Locks System Reset Controller configurations.
859 *
860 * This function is reentrant: calling it while locked will have no effect and
861 * return `kDifOk`.
862 *
863 * @param sysrst_ctrl A System Reset Controller handle.
864 * @return The result of the operation.
865 */
866OT_WARN_UNUSED_RESULT
867dif_result_t dif_sysrst_ctrl_lock(const dif_sysrst_ctrl_t *sysrst_ctrl);
868
869/**
870 * Checks whether System Reset Controller configurations are locked.
871 *
872 * @param sysrst_ctrl A System Reset Controller handle.
873 * @param[out] is_locked Out-param for the locked state.
874 * @return The result of the operation.
875 */
876OT_WARN_UNUSED_RESULT
877dif_result_t dif_sysrst_ctrl_is_locked(const dif_sysrst_ctrl_t *sysrst_ctrl,
878 bool *is_locked);
Srikrishna Iyer0e687042021-10-23 14:53:47 -0700879
880#ifdef __cplusplus
881} // extern "C"
882#endif // __cplusplus
883
884#endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_SYSRST_CTRL_H_