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 earlgrey.
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 kDtGpio0 = 0, /**< gpio0 */
34 kDtGpio1 = 1, /**< gpio1 */
36
37enum {
38 kDtGpioCount = 2, /**< Number of instances */
39};
40
41
42/**
43 * List of register blocks.
44 *
45 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
46 */
47typedef enum dt_gpio_reg_block {
48 kDtGpioRegBlockCore = 0, /**< */
50
51enum {
52 kDtGpioRegBlockCount = 1, /**< Number of register blocks */
53};
54
55
56/** Primary register block (associated with the "primary" set of registers that control the IP). */
57static const dt_gpio_reg_block_t kDtGpioRegBlockPrimary = kDtGpioRegBlockCore;
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 */
98
99enum {
100 kDtGpioIrqCount = 32, /**< Number of IRQs */
101};
102
103
104/**
105 * List of Alerts.
106 *
107 * Alerts are guaranteed to be numbered consecutively from 0.
108 */
109typedef enum dt_gpio_alert {
110 kDtGpioAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
112
113enum {
114 kDtGpioAlertCount = 1, /**< Number of Alerts */
115};
116
117
118/**
119 * List of clock ports.
120 *
121 * Clock ports are guaranteed to be numbered consecutively from 0.
122 */
123typedef enum dt_gpio_clock {
124 kDtGpioClockClk = 0, /**< Clock port clk_i */
126
127enum {
128 kDtGpioClockCount = 1, /**< Number of clock ports */
129};
130
131
132/**
133 * List of reset ports.
134 *
135 * Reset ports are guaranteed to be numbered consecutively from 0.
136 */
137typedef enum dt_gpio_reset {
138 kDtGpioResetRst = 0, /**< Reset port rst_ni */
140
141enum {
142 kDtGpioResetCount = 1, /**< Number of reset ports */
143};
144
145
146/**
147 * List of peripheral I/O.
148 *
149 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
150 */
151typedef enum dt_gpio_periph_io {
152 kDtGpioPeriphIoGpio0 = 0, /**< */
153 kDtGpioPeriphIoGpio1 = 1, /**< */
154 kDtGpioPeriphIoGpio2 = 2, /**< */
155 kDtGpioPeriphIoGpio3 = 3, /**< */
156 kDtGpioPeriphIoGpio4 = 4, /**< */
157 kDtGpioPeriphIoGpio5 = 5, /**< */
158 kDtGpioPeriphIoGpio6 = 6, /**< */
159 kDtGpioPeriphIoGpio7 = 7, /**< */
160 kDtGpioPeriphIoGpio8 = 8, /**< */
161 kDtGpioPeriphIoGpio9 = 9, /**< */
162 kDtGpioPeriphIoGpio10 = 10, /**< */
163 kDtGpioPeriphIoGpio11 = 11, /**< */
164 kDtGpioPeriphIoGpio12 = 12, /**< */
165 kDtGpioPeriphIoGpio13 = 13, /**< */
166 kDtGpioPeriphIoGpio14 = 14, /**< */
167 kDtGpioPeriphIoGpio15 = 15, /**< */
168 kDtGpioPeriphIoGpio16 = 16, /**< */
169 kDtGpioPeriphIoGpio17 = 17, /**< */
170 kDtGpioPeriphIoGpio18 = 18, /**< */
171 kDtGpioPeriphIoGpio19 = 19, /**< */
172 kDtGpioPeriphIoGpio20 = 20, /**< */
173 kDtGpioPeriphIoGpio21 = 21, /**< */
174 kDtGpioPeriphIoGpio22 = 22, /**< */
175 kDtGpioPeriphIoGpio23 = 23, /**< */
176 kDtGpioPeriphIoGpio24 = 24, /**< */
177 kDtGpioPeriphIoGpio25 = 25, /**< */
178 kDtGpioPeriphIoGpio26 = 26, /**< */
179 kDtGpioPeriphIoGpio27 = 27, /**< */
180 kDtGpioPeriphIoGpio28 = 28, /**< */
181 kDtGpioPeriphIoGpio29 = 29, /**< */
182 kDtGpioPeriphIoGpio30 = 30, /**< */
183 kDtGpioPeriphIoGpio31 = 31, /**< */
185
186enum {
187 kDtGpioPeriphIoCount = 32, /**< Number of peripheral I/O */
188};
189
190
191/**
192 * List of supported hardware features.
193 */
194#define OPENTITAN_GPIO_HAS_IN_INTR_CTRL 1
195#define OPENTITAN_GPIO_HAS_IN_FILTER 1
196#define OPENTITAN_GPIO_HAS_OUT_MASK 1
197
198
199
200/**
201 * Get the gpio instance from an instance ID
202 *
203 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
204 *
205 * @param inst_id Instance ID.
206 * @return A gpio instance.
207 *
208 * **Note:** This function only makes sense if the instance ID has device type gpio,
209 * otherwise the returned value is unspecified.
210 */
212
213/**
214 * Get the instance ID of an instance.
215 *
216 * @param dt Instance of gpio.
217 * @return The instance ID of that instance.
218 */
220
221/**
222 * Get the register base address of an instance.
223 *
224 * @param dt Instance of gpio.
225 * @param reg_block The register block requested.
226 * @return The register base address of the requested block.
227 */
228uint32_t dt_gpio_reg_block(
229 dt_gpio_t dt,
230 dt_gpio_reg_block_t reg_block);
231
232/**
233 * Get the primary register base address of an instance.
234 *
235 * This is just a convenience function, equivalent to
236 * `dt_gpio_reg_block(dt, kDtGpioRegBlockCore)`
237 *
238 * @param dt Instance of gpio.
239 * @return The register base address of the primary register block.
240 */
241static inline uint32_t dt_gpio_primary_reg_block(
242 dt_gpio_t dt) {
243 return dt_gpio_reg_block(dt, kDtGpioRegBlockCore);
244}
245
246/**
247 * Get the PLIC ID of a gpio IRQ for a given instance.
248 *
249 * If the instance is not connected to the PLIC, this function
250 * will return `kDtPlicIrqIdNone`.
251 *
252 * @param dt Instance of gpio.
253 * @param irq A gpio IRQ.
254 * @return The PLIC ID of the IRQ of this instance.
255 */
257 dt_gpio_t dt,
258 dt_gpio_irq_t irq);
259
260/**
261 * Convert a global IRQ ID to a local gpio IRQ type.
262 *
263 * @param dt Instance of gpio.
264 * @param irq A PLIC ID that belongs to this instance.
265 * @return The gpio IRQ, or `kDtGpioIrqCount`.
266 *
267 * **Note:** This function assumes that the PLIC ID belongs to the instance
268 * of gpio passed in parameter. In other words, it must be the case that
269 * `dt_gpio_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
270 * will return `kDtGpioIrqCount`.
271 */
273 dt_gpio_t dt,
274 dt_plic_irq_id_t irq);
275
276
277/**
278 * Get the alert ID of a gpio alert for a given instance.
279 *
280 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
281 * instances where the instance is not connected, the return value is unspecified.
282 *
283 * @param dt Instance of gpio.
284 * @param alert A gpio alert.
285 * @return The Alert Handler alert ID of the alert of this instance.
286 */
288 dt_gpio_t dt,
289 dt_gpio_alert_t alert);
290
291/**
292 * Convert a global alert ID to a local gpio alert type.
293 *
294 * @param dt Instance of gpio.
295 * @param alert A global alert ID that belongs to this instance.
296 * @return The gpio alert, or `kDtGpioAlertCount`.
297 *
298 * **Note:** This function assumes that the global alert ID belongs to the
299 * instance of gpio passed in parameter. In other words, it must be the case
300 * that `dt_gpio_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
301 * this function will return `kDtGpioAlertCount`.
302 */
304 dt_gpio_t dt,
305 dt_alert_id_t alert);
306
307
308/**
309 * Get the peripheral I/O description of an instance.
310 *
311 * @param dt Instance of gpio.
312 * @param sig Requested peripheral I/O.
313 * @return Description of the requested peripheral I/O for this instance.
314 */
316 dt_gpio_t dt,
318
319/**
320 * Get the clock signal connected to a clock port of an instance.
321 *
322 * @param dt Instance of gpio.
323 * @param clk Clock port.
324 * @return Clock signal.
325 */
327 dt_gpio_t dt,
328 dt_gpio_clock_t clk);
329
330/**
331 * Get the reset signal connected to a reset port of an instance.
332 *
333 * @param dt Instance of gpio.
334 * @param rst Reset port.
335 * @return Reset signal.
336 */
338 dt_gpio_t dt,
339 dt_gpio_reset_t rst);
340
341
342
343/**
344 * Get the number of input period counters.
345 *
346 * @param dt Instance of gpio.
347 * @return number of input period counters.
348 */
350
351
352
353#ifdef __cplusplus
354} // extern "C"
355#endif // __cplusplus
356
357#endif // OPENTITAN_DT_GPIO_H_