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 englishbreakfast.
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 clock ports.
105 *
106 * Clock ports are guaranteed to be numbered consecutively from 0.
107 */
108typedef enum dt_gpio_clock {
109 kDtGpioClockClk = 0, /**< Clock port clk_i */
111
112enum {
113 kDtGpioClockCount = 1, /**< Number of clock ports */
114};
115
116
117/**
118 * List of reset ports.
119 *
120 * Reset ports are guaranteed to be numbered consecutively from 0.
121 */
122typedef enum dt_gpio_reset {
123 kDtGpioResetRst = 0, /**< Reset port rst_ni */
125
126enum {
127 kDtGpioResetCount = 1, /**< Number of reset ports */
128};
129
130
131/**
132 * List of peripheral I/O.
133 *
134 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
135 */
136typedef enum dt_gpio_periph_io {
137 kDtGpioPeriphIoGpio0 = 0, /**< */
138 kDtGpioPeriphIoGpio1 = 1, /**< */
139 kDtGpioPeriphIoGpio2 = 2, /**< */
140 kDtGpioPeriphIoGpio3 = 3, /**< */
141 kDtGpioPeriphIoGpio4 = 4, /**< */
142 kDtGpioPeriphIoGpio5 = 5, /**< */
143 kDtGpioPeriphIoGpio6 = 6, /**< */
144 kDtGpioPeriphIoGpio7 = 7, /**< */
145 kDtGpioPeriphIoGpio8 = 8, /**< */
146 kDtGpioPeriphIoGpio9 = 9, /**< */
147 kDtGpioPeriphIoGpio10 = 10, /**< */
148 kDtGpioPeriphIoGpio11 = 11, /**< */
149 kDtGpioPeriphIoGpio12 = 12, /**< */
150 kDtGpioPeriphIoGpio13 = 13, /**< */
151 kDtGpioPeriphIoGpio14 = 14, /**< */
152 kDtGpioPeriphIoGpio15 = 15, /**< */
153 kDtGpioPeriphIoGpio16 = 16, /**< */
154 kDtGpioPeriphIoGpio17 = 17, /**< */
155 kDtGpioPeriphIoGpio18 = 18, /**< */
156 kDtGpioPeriphIoGpio19 = 19, /**< */
157 kDtGpioPeriphIoGpio20 = 20, /**< */
158 kDtGpioPeriphIoGpio21 = 21, /**< */
159 kDtGpioPeriphIoGpio22 = 22, /**< */
160 kDtGpioPeriphIoGpio23 = 23, /**< */
161 kDtGpioPeriphIoGpio24 = 24, /**< */
162 kDtGpioPeriphIoGpio25 = 25, /**< */
163 kDtGpioPeriphIoGpio26 = 26, /**< */
164 kDtGpioPeriphIoGpio27 = 27, /**< */
165 kDtGpioPeriphIoGpio28 = 28, /**< */
166 kDtGpioPeriphIoGpio29 = 29, /**< */
167 kDtGpioPeriphIoGpio30 = 30, /**< */
168 kDtGpioPeriphIoGpio31 = 31, /**< */
170
171enum {
172 kDtGpioPeriphIoCount = 32, /**< Number of peripheral I/O */
173};
174
175
176/**
177 * List of supported hardware features.
178 */
179#define OPENTITAN_GPIO_HAS_IN_INTR_CTRL 1
180#define OPENTITAN_GPIO_HAS_IN_FILTER 1
181#define OPENTITAN_GPIO_HAS_OUT_MASK 1
182
183
184
185/**
186 * Get the gpio instance from an instance ID
187 *
188 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
189 *
190 * @param inst_id Instance ID.
191 * @return A gpio instance.
192 *
193 * **Note:** This function only makes sense if the instance ID has device type gpio,
194 * otherwise the returned value is unspecified.
195 */
197
198/**
199 * Get the instance ID of an instance.
200 *
201 * @param dt Instance of gpio.
202 * @return The instance ID of that instance.
203 */
205
206/**
207 * Get the register base address of an instance.
208 *
209 * @param dt Instance of gpio.
210 * @param reg_block The register block requested.
211 * @return The register base address of the requested block.
212 */
213uint32_t dt_gpio_reg_block(
214 dt_gpio_t dt,
215 dt_gpio_reg_block_t reg_block);
216
217/**
218 * Get the primary register base address of an instance.
219 *
220 * This is just a convenience function, equivalent to
221 * `dt_gpio_reg_block(dt, kDtGpioRegBlockCore)`
222 *
223 * @param dt Instance of gpio.
224 * @return The register base address of the primary register block.
225 */
226static inline uint32_t dt_gpio_primary_reg_block(
227 dt_gpio_t dt) {
228 return dt_gpio_reg_block(dt, kDtGpioRegBlockCore);
229}
230
231/**
232 * Get the PLIC ID of a gpio IRQ for a given instance.
233 *
234 * If the instance is not connected to the PLIC, this function
235 * will return `kDtPlicIrqIdNone`.
236 *
237 * @param dt Instance of gpio.
238 * @param irq A gpio IRQ.
239 * @return The PLIC ID of the IRQ of this instance.
240 */
242 dt_gpio_t dt,
243 dt_gpio_irq_t irq);
244
245/**
246 * Convert a global IRQ ID to a local gpio IRQ type.
247 *
248 * @param dt Instance of gpio.
249 * @param irq A PLIC ID that belongs to this instance.
250 * @return The gpio IRQ, or `kDtGpioIrqCount`.
251 *
252 * **Note:** This function assumes that the PLIC ID belongs to the instance
253 * of gpio passed in parameter. In other words, it must be the case that
254 * `dt_gpio_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
255 * will return `kDtGpioIrqCount`.
256 */
258 dt_gpio_t dt,
259 dt_plic_irq_id_t irq);
260
261
262
263/**
264 * Get the peripheral I/O description of an instance.
265 *
266 * @param dt Instance of gpio.
267 * @param sig Requested peripheral I/O.
268 * @return Description of the requested peripheral I/O for this instance.
269 */
271 dt_gpio_t dt,
273
274/**
275 * Get the clock signal connected to a clock port of an instance.
276 *
277 * @param dt Instance of gpio.
278 * @param clk Clock port.
279 * @return Clock signal.
280 */
282 dt_gpio_t dt,
283 dt_gpio_clock_t clk);
284
285/**
286 * Get the reset signal connected to a reset port of an instance.
287 *
288 * @param dt Instance of gpio.
289 * @param rst Reset port.
290 * @return Reset signal.
291 */
293 dt_gpio_t dt,
294 dt_gpio_reset_t rst);
295
296
297
298/**
299 * Get the number of input period counters.
300 *
301 * @param dt Instance of gpio.
302 * @return number of input period counters.
303 */
305
306
307
308#ifdef __cplusplus
309} // extern "C"
310#endif // __cplusplus
311
312#endif // OPENTITAN_DT_GPIO_H_