Software APIs
dt_gpio.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_GPIO_H_
8#define OPENTITAN_DT_GPIO_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP gpio and top darjeeling.
17 *
18 * This file contains the type definitions and global functions of the gpio.
19 */
20
21#include "hw/top/dt/dt_api.h"
22#include <stdint.h>
23
24
25
26
27
28/**
29 * List of instances.
30 */
31typedef enum dt_gpio {
32 kDtGpio = 0, /**< gpio */
33 kDtGpioFirst = 0, /**< \internal First instance */
34 kDtGpioCount = 1, /**< \internal Number of instances */
36
37/**
38 * List of register blocks.
39 *
40 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
41 */
42typedef enum dt_gpio_reg_block {
43 kDtGpioRegBlockCore = 0, /**< */
44 kDtGpioRegBlockCount = 1, /**< \internal Number of register blocks */
46
47/** Primary register block (associated with the "primary" set of registers that control the IP). */
48static const dt_gpio_reg_block_t kDtGpioRegBlockPrimary = kDtGpioRegBlockCore;
49
50/**
51 * List of memories.
52 *
53 * Memories are guaranteed to start at 0 and to be consecutively numbered.
54 */
55typedef enum dt_gpio_memory {
56 kDtGpioMemoryCount = 0, /**< \internal Number of memories */
58
59/**
60 * List of IRQs.
61 *
62 * IRQs are guaranteed to be numbered consecutively from 0.
63 */
64typedef enum dt_gpio_irq {
65 kDtGpioIrqGpio0 = 0, /**< raised if any of GPIO pin detects configured interrupt mode */
66 kDtGpioIrqGpio1 = 1, /**< raised if any of GPIO pin detects configured interrupt mode */
67 kDtGpioIrqGpio2 = 2, /**< raised if any of GPIO pin detects configured interrupt mode */
68 kDtGpioIrqGpio3 = 3, /**< raised if any of GPIO pin detects configured interrupt mode */
69 kDtGpioIrqGpio4 = 4, /**< raised if any of GPIO pin detects configured interrupt mode */
70 kDtGpioIrqGpio5 = 5, /**< raised if any of GPIO pin detects configured interrupt mode */
71 kDtGpioIrqGpio6 = 6, /**< raised if any of GPIO pin detects configured interrupt mode */
72 kDtGpioIrqGpio7 = 7, /**< raised if any of GPIO pin detects configured interrupt mode */
73 kDtGpioIrqGpio8 = 8, /**< raised if any of GPIO pin detects configured interrupt mode */
74 kDtGpioIrqGpio9 = 9, /**< raised if any of GPIO pin detects configured interrupt mode */
75 kDtGpioIrqGpio10 = 10, /**< raised if any of GPIO pin detects configured interrupt mode */
76 kDtGpioIrqGpio11 = 11, /**< raised if any of GPIO pin detects configured interrupt mode */
77 kDtGpioIrqGpio12 = 12, /**< raised if any of GPIO pin detects configured interrupt mode */
78 kDtGpioIrqGpio13 = 13, /**< raised if any of GPIO pin detects configured interrupt mode */
79 kDtGpioIrqGpio14 = 14, /**< raised if any of GPIO pin detects configured interrupt mode */
80 kDtGpioIrqGpio15 = 15, /**< raised if any of GPIO pin detects configured interrupt mode */
81 kDtGpioIrqGpio16 = 16, /**< raised if any of GPIO pin detects configured interrupt mode */
82 kDtGpioIrqGpio17 = 17, /**< raised if any of GPIO pin detects configured interrupt mode */
83 kDtGpioIrqGpio18 = 18, /**< raised if any of GPIO pin detects configured interrupt mode */
84 kDtGpioIrqGpio19 = 19, /**< raised if any of GPIO pin detects configured interrupt mode */
85 kDtGpioIrqGpio20 = 20, /**< raised if any of GPIO pin detects configured interrupt mode */
86 kDtGpioIrqGpio21 = 21, /**< raised if any of GPIO pin detects configured interrupt mode */
87 kDtGpioIrqGpio22 = 22, /**< raised if any of GPIO pin detects configured interrupt mode */
88 kDtGpioIrqGpio23 = 23, /**< raised if any of GPIO pin detects configured interrupt mode */
89 kDtGpioIrqGpio24 = 24, /**< raised if any of GPIO pin detects configured interrupt mode */
90 kDtGpioIrqGpio25 = 25, /**< raised if any of GPIO pin detects configured interrupt mode */
91 kDtGpioIrqGpio26 = 26, /**< raised if any of GPIO pin detects configured interrupt mode */
92 kDtGpioIrqGpio27 = 27, /**< raised if any of GPIO pin detects configured interrupt mode */
93 kDtGpioIrqGpio28 = 28, /**< raised if any of GPIO pin detects configured interrupt mode */
94 kDtGpioIrqGpio29 = 29, /**< raised if any of GPIO pin detects configured interrupt mode */
95 kDtGpioIrqGpio30 = 30, /**< raised if any of GPIO pin detects configured interrupt mode */
96 kDtGpioIrqGpio31 = 31, /**< raised if any of GPIO pin detects configured interrupt mode */
97 kDtGpioIrqCount = 32, /**< \internal Number of IRQs */
99
100/**
101 * List of Alerts.
102 *
103 * Alerts are guaranteed to be numbered consecutively from 0.
104 */
105typedef enum dt_gpio_alert {
106 kDtGpioAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
107 kDtGpioAlertCount = 1, /**< \internal Number of Alerts */
109
110/**
111 * List of clock ports.
112 *
113 * Clock ports are guaranteed to be numbered consecutively from 0.
114 */
115typedef enum dt_gpio_clock {
116 kDtGpioClockClk = 0, /**< Clock port clk_i */
117 kDtGpioClockCount = 1, /**< \internal Number of clock ports */
119
120/**
121 * List of reset ports.
122 *
123 * Reset ports are guaranteed to be numbered consecutively from 0.
124 */
125typedef enum dt_gpio_reset {
126 kDtGpioResetRst = 0, /**< Reset port rst_ni */
127 kDtGpioResetCount = 1, /**< \internal Number of reset ports */
129
130/**
131 * List of peripheral I/O.
132 *
133 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
134 */
135typedef enum dt_gpio_periph_io {
136 kDtGpioPeriphIoGpio0 = 0, /**< */
137 kDtGpioPeriphIoGpio1 = 1, /**< */
138 kDtGpioPeriphIoGpio2 = 2, /**< */
139 kDtGpioPeriphIoGpio3 = 3, /**< */
140 kDtGpioPeriphIoGpio4 = 4, /**< */
141 kDtGpioPeriphIoGpio5 = 5, /**< */
142 kDtGpioPeriphIoGpio6 = 6, /**< */
143 kDtGpioPeriphIoGpio7 = 7, /**< */
144 kDtGpioPeriphIoGpio8 = 8, /**< */
145 kDtGpioPeriphIoGpio9 = 9, /**< */
146 kDtGpioPeriphIoGpio10 = 10, /**< */
147 kDtGpioPeriphIoGpio11 = 11, /**< */
148 kDtGpioPeriphIoGpio12 = 12, /**< */
149 kDtGpioPeriphIoGpio13 = 13, /**< */
150 kDtGpioPeriphIoGpio14 = 14, /**< */
151 kDtGpioPeriphIoGpio15 = 15, /**< */
152 kDtGpioPeriphIoGpio16 = 16, /**< */
153 kDtGpioPeriphIoGpio17 = 17, /**< */
154 kDtGpioPeriphIoGpio18 = 18, /**< */
155 kDtGpioPeriphIoGpio19 = 19, /**< */
156 kDtGpioPeriphIoGpio20 = 20, /**< */
157 kDtGpioPeriphIoGpio21 = 21, /**< */
158 kDtGpioPeriphIoGpio22 = 22, /**< */
159 kDtGpioPeriphIoGpio23 = 23, /**< */
160 kDtGpioPeriphIoGpio24 = 24, /**< */
161 kDtGpioPeriphIoGpio25 = 25, /**< */
162 kDtGpioPeriphIoGpio26 = 26, /**< */
163 kDtGpioPeriphIoGpio27 = 27, /**< */
164 kDtGpioPeriphIoGpio28 = 28, /**< */
165 kDtGpioPeriphIoGpio29 = 29, /**< */
166 kDtGpioPeriphIoGpio30 = 30, /**< */
167 kDtGpioPeriphIoGpio31 = 31, /**< */
168 kDtGpioPeriphIoCount = 32, /**< \internal Number of peripheral I/O */
170
171/**
172 * List of supported hardware features.
173 */
174#define OPENTITAN_GPIO_HAS_IN_INTR_CTRL 1
175#define OPENTITAN_GPIO_HAS_IN_FILTER 1
176#define OPENTITAN_GPIO_HAS_OUT_MASK 1
177
178
179
180/**
181 * Get the gpio instance from an instance ID
182 *
183 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
184 *
185 * @param inst_id Instance ID.
186 * @return A gpio instance.
187 *
188 * **Note:** This function only makes sense if the instance ID has device type gpio,
189 * otherwise the returned value is unspecified.
190 */
192
193/**
194 * Get the instance ID of an instance.
195 *
196 * @param dt Instance of gpio.
197 * @return The instance ID of that instance.
198 */
200
201/**
202 * Get the register base address of an instance.
203 *
204 * @param dt Instance of gpio.
205 * @param reg_block The register block requested.
206 * @return The register base address of the requested block.
207 */
208uint32_t dt_gpio_reg_block(
209 dt_gpio_t dt,
210 dt_gpio_reg_block_t reg_block);
211
212/**
213 * Get the primary register base address of an instance.
214 *
215 * This is just a convenience function, equivalent to
216 * `dt_gpio_reg_block(dt, kDtGpioRegBlockCore)`
217 *
218 * @param dt Instance of gpio.
219 * @return The register base address of the primary register block.
220 */
221static inline uint32_t dt_gpio_primary_reg_block(
222 dt_gpio_t dt) {
223 return dt_gpio_reg_block(dt, kDtGpioRegBlockCore);
224}
225
226/**
227 * Get the base address of a memory.
228 *
229 * @param dt Instance of gpio.
230 * @param mem The memory requested.
231 * @return The base address of the requested memory.
232 */
233uint32_t dt_gpio_memory_base(
234 dt_gpio_t dt,
235 dt_gpio_memory_t mem);
236
237/**
238 * Get the size of a memory.
239 *
240 * @param dt Instance of gpio.
241 * @param mem The memory requested.
242 * @return The size of the requested memory.
243 */
244uint32_t dt_gpio_memory_size(
245 dt_gpio_t dt,
246 dt_gpio_memory_t mem);
247
248/**
249 * Get the PLIC ID of a gpio IRQ for a given instance.
250 *
251 * If the instance is not connected to the PLIC, this function
252 * will return `kDtPlicIrqIdNone`.
253 *
254 * @param dt Instance of gpio.
255 * @param irq A gpio IRQ.
256 * @return The PLIC ID of the IRQ of this instance.
257 */
259 dt_gpio_t dt,
260 dt_gpio_irq_t irq);
261
262/**
263 * Convert a global IRQ ID to a local gpio IRQ type.
264 *
265 * @param dt Instance of gpio.
266 * @param irq A PLIC ID that belongs to this instance.
267 * @return The gpio IRQ, or `kDtGpioIrqCount`.
268 *
269 * **Note:** This function assumes that the PLIC ID belongs to the instance
270 * of gpio passed in parameter. In other words, it must be the case that
271 * `dt_gpio_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
272 * will return `kDtGpioIrqCount`.
273 */
275 dt_gpio_t dt,
276 dt_plic_irq_id_t irq);
277
278
279/**
280 * Get the alert ID of a gpio alert for a given instance.
281 *
282 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
283 * instances where the instance is not connected, the return value is unspecified.
284 *
285 * @param dt Instance of gpio.
286 * @param alert A gpio alert.
287 * @return The Alert Handler alert ID of the alert of this instance.
288 */
290 dt_gpio_t dt,
291 dt_gpio_alert_t alert);
292
293/**
294 * Convert a global alert ID to a local gpio alert type.
295 *
296 * @param dt Instance of gpio.
297 * @param alert A global alert ID that belongs to this instance.
298 * @return The gpio alert, or `kDtGpioAlertCount`.
299 *
300 * **Note:** This function assumes that the global alert ID belongs to the
301 * instance of gpio passed in parameter. In other words, it must be the case
302 * that `dt_gpio_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
303 * this function will return `kDtGpioAlertCount`.
304 */
306 dt_gpio_t dt,
307 dt_alert_id_t alert);
308
309
310/**
311 * Get the peripheral I/O description of an instance.
312 *
313 * @param dt Instance of gpio.
314 * @param sig Requested peripheral I/O.
315 * @return Description of the requested peripheral I/O for this instance.
316 */
318 dt_gpio_t dt,
320
321/**
322 * Get the clock signal connected to a clock port of an instance.
323 *
324 * @param dt Instance of gpio.
325 * @param clk Clock port.
326 * @return Clock signal.
327 */
329 dt_gpio_t dt,
330 dt_gpio_clock_t clk);
331
332/**
333 * Get the reset signal connected to a reset port of an instance.
334 *
335 * @param dt Instance of gpio.
336 * @param rst Reset port.
337 * @return Reset signal.
338 */
340 dt_gpio_t dt,
341 dt_gpio_reset_t rst);
342
343
344
345/**
346 * Get the number of input period counters.
347 *
348 * @param dt Instance of gpio.
349 * @return number of input period counters.
350 */
352
353
354
355#ifdef __cplusplus
356} // extern "C"
357#endif // __cplusplus
358
359#endif // OPENTITAN_DT_GPIO_H_