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