Software APIs
dt_sysrst_ctrl.c
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/**
8 * @file
9 * @brief Device Tables (DT) for IP sysrst_ctrl and top earlgrey.
10 */
11
12#include "dt/dt_sysrst_ctrl.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_sysrst_ctrl {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t base_addr[kDtSysrstCtrlRegBlockCount]; /**< Base address of each register block */
22 /**
23 * PLIC ID of the first IRQ of this instance
24 *
25 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
26 */
28 /**
29 * Alert ID of the first Alert of this instance.
30 *
31 * This value is undefined if the block is not connected to the Alert Handler.
32 */
34 dt_clock_t clock[kDtSysrstCtrlClockCount]; /**< Clock signal connected to each clock port */
35 dt_reset_t reset[kDtSysrstCtrlResetCount]; /**< Reset signal connected to each reset port */
36 dt_periph_io_t periph_io[kDtSysrstCtrlPeriphIoCount]; /**< Description of each peripheral I/O */
38
39
40
41
42static const dt_desc_sysrst_ctrl_t sysrst_ctrl_desc[kDtSysrstCtrlCount] = {
45 .base_addr = {
46 [kDtSysrstCtrlRegBlockCore] = 0x40430000,
47 },
50 .clock = {
53 },
54 .reset = {
57 },
58 .periph_io = {
59 [kDtSysrstCtrlPeriphIoAcPresent] = {
60 .__internal = {
61 .type = kDtPeriphIoTypeMio,
62 .dir = kDtPeriphIoDirIn,
63 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonAcPresent,
64 .outsel_or_dt_pad = 0,
65 },
66 },
67 [kDtSysrstCtrlPeriphIoKey0In] = {
68 .__internal = {
69 .type = kDtPeriphIoTypeMio,
70 .dir = kDtPeriphIoDirIn,
71 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonKey0In,
72 .outsel_or_dt_pad = 0,
73 },
74 },
75 [kDtSysrstCtrlPeriphIoKey1In] = {
76 .__internal = {
77 .type = kDtPeriphIoTypeMio,
78 .dir = kDtPeriphIoDirIn,
79 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonKey1In,
80 .outsel_or_dt_pad = 0,
81 },
82 },
83 [kDtSysrstCtrlPeriphIoKey2In] = {
84 .__internal = {
85 .type = kDtPeriphIoTypeMio,
86 .dir = kDtPeriphIoDirIn,
87 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonKey2In,
88 .outsel_or_dt_pad = 0,
89 },
90 },
91 [kDtSysrstCtrlPeriphIoPwrbIn] = {
92 .__internal = {
93 .type = kDtPeriphIoTypeMio,
94 .dir = kDtPeriphIoDirIn,
95 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonPwrbIn,
96 .outsel_or_dt_pad = 0,
97 },
98 },
99 [kDtSysrstCtrlPeriphIoLidOpen] = {
100 .__internal = {
101 .type = kDtPeriphIoTypeMio,
102 .dir = kDtPeriphIoDirIn,
103 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonLidOpen,
104 .outsel_or_dt_pad = 0,
105 },
106 },
107 [kDtSysrstCtrlPeriphIoBatDisable] = {
108 .__internal = {
109 .type = kDtPeriphIoTypeMio,
110 .dir = kDtPeriphIoDirOut,
111 .periph_input_or_direct_pad = 0,
113 },
114 },
115 [kDtSysrstCtrlPeriphIoKey0Out] = {
116 .__internal = {
117 .type = kDtPeriphIoTypeMio,
118 .dir = kDtPeriphIoDirOut,
119 .periph_input_or_direct_pad = 0,
121 },
122 },
123 [kDtSysrstCtrlPeriphIoKey1Out] = {
124 .__internal = {
125 .type = kDtPeriphIoTypeMio,
126 .dir = kDtPeriphIoDirOut,
127 .periph_input_or_direct_pad = 0,
129 },
130 },
131 [kDtSysrstCtrlPeriphIoKey2Out] = {
132 .__internal = {
133 .type = kDtPeriphIoTypeMio,
134 .dir = kDtPeriphIoDirOut,
135 .periph_input_or_direct_pad = 0,
137 },
138 },
139 [kDtSysrstCtrlPeriphIoPwrbOut] = {
140 .__internal = {
141 .type = kDtPeriphIoTypeMio,
142 .dir = kDtPeriphIoDirOut,
143 .periph_input_or_direct_pad = 0,
145 },
146 },
147 [kDtSysrstCtrlPeriphIoZ3Wakeup] = {
148 .__internal = {
149 .type = kDtPeriphIoTypeMio,
150 .dir = kDtPeriphIoDirOut,
151 .periph_input_or_direct_pad = 0,
153 },
154 },
155 [kDtSysrstCtrlPeriphIoEcRstL] = {
156 .__internal = {
157 .type = kDtPeriphIoTypeDio,
158 .dir = kDtPeriphIoDirInout,
159 .periph_input_or_direct_pad = kTopEarlgreyDirectPadsSysrstCtrlAonEcRstL,
160 .outsel_or_dt_pad = kDtPadSysrstCtrlAonEcRstL,
161 },
162 },
163 [kDtSysrstCtrlPeriphIoFlashWpL] = {
164 .__internal = {
165 .type = kDtPeriphIoTypeDio,
166 .dir = kDtPeriphIoDirInout,
167 .periph_input_or_direct_pad = kTopEarlgreyDirectPadsSysrstCtrlAonFlashWpL,
168 .outsel_or_dt_pad = kDtPadSysrstCtrlAonFlashWpL,
169 },
170 },
171 },
172 },
173};
174
175/**
176 * Return a pointer to the `dt_sysrst_ctrl_desc_t` structure of the requested
177 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
178 * the function) with the provided default value.
179 */
180#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_sysrst_ctrl_t)0 || (dt) >= kDtSysrstCtrlCount) return (default); &sysrst_ctrl_desc[dt]; })
181
188
193
196 dt_sysrst_ctrl_reg_block_t reg_block) {
197 // Return a recognizable address in case of wrong argument.
198 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
199}
200
204 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
205 if (first_irq == kDtPlicIrqIdNone) {
206 return kDtPlicIrqIdNone;
207 }
208 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
209}
210
213 dt_plic_irq_id_t irq) {
214 dt_sysrst_ctrl_irq_t count = kDtSysrstCtrlIrqCount;
215 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
216 if (first_irq == kDtPlicIrqIdNone) {
217 return count;
218 }
219 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
220 return count;
221 }
222 return (dt_sysrst_ctrl_irq_t)(irq - first_irq);
223}
224
225
229 return (dt_alert_id_t)((uint32_t)sysrst_ctrl_desc[dt].first_alert + (uint32_t)alert);
230}
231
234 dt_alert_id_t alert) {
235 dt_sysrst_ctrl_alert_t count = kDtSysrstCtrlAlertCount;
236 if (alert < sysrst_ctrl_desc[dt].first_alert || alert >= sysrst_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
237 return count;
238 }
239 return (dt_sysrst_ctrl_alert_t)(alert - sysrst_ctrl_desc[dt].first_alert);
240}
241
242
246 // Return a harmless value in case of wrong argument.
247 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
248}
249
253 // Return the first clock in case of invalid argument.
254 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
255}
256
260 const dt_sysrst_ctrl_reset_t count = kDtSysrstCtrlResetCount;
261 if (rst >= count) {
262 return kDtResetUnknown;
263 }
264 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
265}
266
267