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
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 reg_addr[kDtSysrstCtrlRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtSysrstCtrlMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtSysrstCtrlMemoryCount]; /**< Size in bytes of each memory */
24 /**
25 * PLIC ID of the first IRQ of this instance
26 *
27 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
28 */
30 /**
31 * Alert ID of the first Alert of this instance.
32 *
33 * This value is undefined if the block is not connected to the Alert Handler.
34 */
36 dt_clock_t clock[kDtSysrstCtrlClockCount]; /**< Clock signal connected to each clock port */
37 dt_reset_t reset[kDtSysrstCtrlResetCount]; /**< Reset signal connected to each reset port */
38 dt_periph_io_t periph_io[kDtSysrstCtrlPeriphIoCount]; /**< Description of each peripheral I/O */
40
41
42
43
44static const dt_desc_sysrst_ctrl_t sysrst_ctrl_desc[kDtSysrstCtrlCount] = {
47 .reg_addr = {
48 [kDtSysrstCtrlRegBlockCore] = 0x40430000,
49 },
50 .mem_addr = {
51 },
52 .mem_size = {
53 },
56 .clock = {
59 },
60 .reset = {
63 },
64 .periph_io = {
65 [kDtSysrstCtrlPeriphIoAcPresent] = {
66 .__internal = {
67 .type = kDtPeriphIoTypeMio,
68 .dir = kDtPeriphIoDirIn,
69 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonAcPresent,
70 .outsel_or_dt_pad = 0,
71 },
72 },
73 [kDtSysrstCtrlPeriphIoKey0In] = {
74 .__internal = {
75 .type = kDtPeriphIoTypeMio,
76 .dir = kDtPeriphIoDirIn,
77 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonKey0In,
78 .outsel_or_dt_pad = 0,
79 },
80 },
81 [kDtSysrstCtrlPeriphIoKey1In] = {
82 .__internal = {
83 .type = kDtPeriphIoTypeMio,
84 .dir = kDtPeriphIoDirIn,
85 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonKey1In,
86 .outsel_or_dt_pad = 0,
87 },
88 },
89 [kDtSysrstCtrlPeriphIoKey2In] = {
90 .__internal = {
91 .type = kDtPeriphIoTypeMio,
92 .dir = kDtPeriphIoDirIn,
93 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonKey2In,
94 .outsel_or_dt_pad = 0,
95 },
96 },
97 [kDtSysrstCtrlPeriphIoPwrbIn] = {
98 .__internal = {
99 .type = kDtPeriphIoTypeMio,
100 .dir = kDtPeriphIoDirIn,
101 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonPwrbIn,
102 .outsel_or_dt_pad = 0,
103 },
104 },
105 [kDtSysrstCtrlPeriphIoLidOpen] = {
106 .__internal = {
107 .type = kDtPeriphIoTypeMio,
108 .dir = kDtPeriphIoDirIn,
109 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInSysrstCtrlAonLidOpen,
110 .outsel_or_dt_pad = 0,
111 },
112 },
113 [kDtSysrstCtrlPeriphIoBatDisable] = {
114 .__internal = {
115 .type = kDtPeriphIoTypeMio,
116 .dir = kDtPeriphIoDirOut,
117 .periph_input_or_direct_pad = 0,
119 },
120 },
121 [kDtSysrstCtrlPeriphIoKey0Out] = {
122 .__internal = {
123 .type = kDtPeriphIoTypeMio,
124 .dir = kDtPeriphIoDirOut,
125 .periph_input_or_direct_pad = 0,
127 },
128 },
129 [kDtSysrstCtrlPeriphIoKey1Out] = {
130 .__internal = {
131 .type = kDtPeriphIoTypeMio,
132 .dir = kDtPeriphIoDirOut,
133 .periph_input_or_direct_pad = 0,
135 },
136 },
137 [kDtSysrstCtrlPeriphIoKey2Out] = {
138 .__internal = {
139 .type = kDtPeriphIoTypeMio,
140 .dir = kDtPeriphIoDirOut,
141 .periph_input_or_direct_pad = 0,
143 },
144 },
145 [kDtSysrstCtrlPeriphIoPwrbOut] = {
146 .__internal = {
147 .type = kDtPeriphIoTypeMio,
148 .dir = kDtPeriphIoDirOut,
149 .periph_input_or_direct_pad = 0,
151 },
152 },
153 [kDtSysrstCtrlPeriphIoZ3Wakeup] = {
154 .__internal = {
155 .type = kDtPeriphIoTypeMio,
156 .dir = kDtPeriphIoDirOut,
157 .periph_input_or_direct_pad = 0,
159 },
160 },
161 [kDtSysrstCtrlPeriphIoEcRstL] = {
162 .__internal = {
163 .type = kDtPeriphIoTypeDio,
164 .dir = kDtPeriphIoDirInout,
165 .periph_input_or_direct_pad = kTopEarlgreyDirectPadsSysrstCtrlAonEcRstL,
166 .outsel_or_dt_pad = kDtPadSysrstCtrlAonEcRstL,
167 },
168 },
169 [kDtSysrstCtrlPeriphIoFlashWpL] = {
170 .__internal = {
171 .type = kDtPeriphIoTypeDio,
172 .dir = kDtPeriphIoDirInout,
173 .periph_input_or_direct_pad = kTopEarlgreyDirectPadsSysrstCtrlAonFlashWpL,
174 .outsel_or_dt_pad = kDtPadSysrstCtrlAonFlashWpL,
175 },
176 },
177 },
178 },
179};
180
181/**
182 * Return a pointer to the `dt_sysrst_ctrl_desc_t` structure of the requested
183 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
184 * the function) with the provided default value.
185 */
186#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_sysrst_ctrl_t)0 || (dt) >= kDtSysrstCtrlCount) return (default); &sysrst_ctrl_desc[dt]; })
187
194
199
202 dt_sysrst_ctrl_reg_block_t reg_block) {
203 // Return a recognizable address in case of wrong argument.
204 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
205}
206
210 // Return a recognizable address in case of wrong argument.
211 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
212}
213
217 // Return an empty size in case of wrong argument.
218 return TRY_GET_DT(dt, 0)->mem_size[mem];
219}
220
224 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
225 if (first_irq == kDtPlicIrqIdNone) {
226 return kDtPlicIrqIdNone;
227 }
228 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
229}
230
233 dt_plic_irq_id_t irq) {
234 dt_sysrst_ctrl_irq_t count = kDtSysrstCtrlIrqCount;
235 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
236 if (first_irq == kDtPlicIrqIdNone) {
237 return count;
238 }
239 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
240 return count;
241 }
242 return (dt_sysrst_ctrl_irq_t)(irq - first_irq);
243}
244
245
249 return (dt_alert_id_t)((uint32_t)sysrst_ctrl_desc[dt].first_alert + (uint32_t)alert);
250}
251
254 dt_alert_id_t alert) {
255 dt_sysrst_ctrl_alert_t count = kDtSysrstCtrlAlertCount;
256 if (alert < sysrst_ctrl_desc[dt].first_alert || alert >= sysrst_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
257 return count;
258 }
259 return (dt_sysrst_ctrl_alert_t)(alert - sysrst_ctrl_desc[dt].first_alert);
260}
261
262
266 // Return a harmless value in case of wrong argument.
267 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
268}
269
273 // Return the first clock in case of invalid argument.
274 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
275}
276
280 const dt_sysrst_ctrl_reset_t count = kDtSysrstCtrlResetCount;
281 if (rst >= count) {
282 return kDtResetUnknown;
283 }
284 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
285}
286
287