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