Software APIs
api.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_TOP_EARLGREY_DT_API_H_
8#define OPENTITAN_TOP_EARLGREY_DT_API_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) API for top earlgrey
17 *
18 * This file contains the type definitions and global functions of the DT.
19 *
20 * The DT models the chip as a collection of instances. Each instance has
21 * a type (the IP block) and a number of attributes such as I/Os, IRQs
22 * and so on. The DT also provides top-specific lists of global resources
23 * such as I/O pads, clocks and interrupts.
24 */
25
26#include <stddef.h>
27#include <stdint.h>
29
30/**
31 * List of device types.
32 *
33 * Device types are guaranteed to be numbered consecutively from 0.
34 */
35typedef enum dt_device_type {
36 kDtDeviceTypeUnknown = 0, /**< Instance of unknown type */
37 kDtDeviceTypeAdcCtrl = 1, /**< instance of adc_ctrl */
38 kDtDeviceTypeAes = 2, /**< instance of aes */
39 kDtDeviceTypeAlertHandler = 3, /**< instance of alert_handler */
40 kDtDeviceTypeAonTimer = 4, /**< instance of aon_timer */
41 kDtDeviceTypeAst = 5, /**< instance of ast */
42 kDtDeviceTypeClkmgr = 6, /**< instance of clkmgr */
43 kDtDeviceTypeCsrng = 7, /**< instance of csrng */
44 kDtDeviceTypeEdn = 8, /**< instance of edn */
45 kDtDeviceTypeEntropySrc = 9, /**< instance of entropy_src */
46 kDtDeviceTypeFlashCtrl = 10, /**< instance of flash_ctrl */
47 kDtDeviceTypeGpio = 11, /**< instance of gpio */
48 kDtDeviceTypeHmac = 12, /**< instance of hmac */
49 kDtDeviceTypeI2c = 13, /**< instance of i2c */
50 kDtDeviceTypeKeymgr = 14, /**< instance of keymgr */
51 kDtDeviceTypeKmac = 15, /**< instance of kmac */
52 kDtDeviceTypeLcCtrl = 16, /**< instance of lc_ctrl */
53 kDtDeviceTypeOtbn = 17, /**< instance of otbn */
54 kDtDeviceTypeOtpCtrl = 18, /**< instance of otp_ctrl */
55 kDtDeviceTypeOtpMacro = 19, /**< instance of otp_macro */
56 kDtDeviceTypePinmux = 20, /**< instance of pinmux */
57 kDtDeviceTypePwrmgr = 21, /**< instance of pwrmgr */
58 kDtDeviceTypeRomCtrl = 22, /**< instance of rom_ctrl */
59 kDtDeviceTypeRstmgr = 23, /**< instance of rstmgr */
60 kDtDeviceTypeRvCoreIbex = 24, /**< instance of rv_core_ibex */
61 kDtDeviceTypeRvDm = 25, /**< instance of rv_dm */
62 kDtDeviceTypeRvPlic = 26, /**< instance of rv_plic */
63 kDtDeviceTypeRvTimer = 27, /**< instance of rv_timer */
64 kDtDeviceTypeSensorCtrl = 28, /**< instance of sensor_ctrl */
65 kDtDeviceTypeSpiDevice = 29, /**< instance of spi_device */
66 kDtDeviceTypeSpiHost = 30, /**< instance of spi_host */
67 kDtDeviceTypeSramCtrl = 31, /**< instance of sram_ctrl */
68 kDtDeviceTypeSysrstCtrl = 32, /**< instance of sysrst_ctrl */
69 kDtDeviceTypeUart = 33, /**< instance of uart */
70 kDtDeviceTypeUsbdev = 34, /**< instance of usbdev */
72
73enum {
74 kDtDeviceTypeCount = 35, /**< Number of instance types */
75};
76
77
78/**
79 * List of instance IDs.
80 *
81 * Instance IDs are guaranteed to be numbered consecutively from 0.
82 */
83typedef enum dt_instance_id {
84 kDtInstanceIdUnknown = 0, /**< Unknown instance */
85 kDtInstanceIdAdcCtrlAon = 1, /**< instance adc_ctrl_aon of adc_ctrl */
86 kDtInstanceIdAes = 2, /**< instance aes of aes */
87 kDtInstanceIdAlertHandler = 3, /**< instance alert_handler of alert_handler */
88 kDtInstanceIdAonTimerAon = 4, /**< instance aon_timer_aon of aon_timer */
89 kDtInstanceIdAst = 5, /**< instance ast of ast */
90 kDtInstanceIdClkmgrAon = 6, /**< instance clkmgr_aon of clkmgr */
91 kDtInstanceIdCsrng = 7, /**< instance csrng of csrng */
92 kDtInstanceIdEdn0 = 8, /**< instance edn0 of edn */
93 kDtInstanceIdEdn1 = 9, /**< instance edn1 of edn */
94 kDtInstanceIdEntropySrc = 10, /**< instance entropy_src of entropy_src */
95 kDtInstanceIdFlashCtrl = 11, /**< instance flash_ctrl of flash_ctrl */
96 kDtInstanceIdGpio = 12, /**< instance gpio of gpio */
97 kDtInstanceIdHmac = 13, /**< instance hmac of hmac */
98 kDtInstanceIdI2c0 = 14, /**< instance i2c0 of i2c */
99 kDtInstanceIdI2c1 = 15, /**< instance i2c1 of i2c */
100 kDtInstanceIdI2c2 = 16, /**< instance i2c2 of i2c */
101 kDtInstanceIdKeymgr = 17, /**< instance keymgr of keymgr */
102 kDtInstanceIdKmac = 18, /**< instance kmac of kmac */
103 kDtInstanceIdLcCtrl = 19, /**< instance lc_ctrl of lc_ctrl */
104 kDtInstanceIdOtbn = 20, /**< instance otbn of otbn */
105 kDtInstanceIdOtpCtrl = 21, /**< instance otp_ctrl of otp_ctrl */
106 kDtInstanceIdOtpMacro = 22, /**< instance otp_macro of otp_macro */
107 kDtInstanceIdPinmuxAon = 23, /**< instance pinmux_aon of pinmux */
108 kDtInstanceIdPwrmgrAon = 24, /**< instance pwrmgr_aon of pwrmgr */
109 kDtInstanceIdRomCtrl = 25, /**< instance rom_ctrl of rom_ctrl */
110 kDtInstanceIdRstmgrAon = 26, /**< instance rstmgr_aon of rstmgr */
111 kDtInstanceIdRvCoreIbex = 27, /**< instance rv_core_ibex of rv_core_ibex */
112 kDtInstanceIdRvDm = 28, /**< instance rv_dm of rv_dm */
113 kDtInstanceIdRvPlic = 29, /**< instance rv_plic of rv_plic */
114 kDtInstanceIdRvTimer = 30, /**< instance rv_timer of rv_timer */
115 kDtInstanceIdSensorCtrlAon = 31, /**< instance sensor_ctrl_aon of sensor_ctrl */
116 kDtInstanceIdSpiDevice = 32, /**< instance spi_device of spi_device */
117 kDtInstanceIdSpiHost0 = 33, /**< instance spi_host0 of spi_host */
118 kDtInstanceIdSpiHost1 = 34, /**< instance spi_host1 of spi_host */
119 kDtInstanceIdSramCtrlRetAon = 35, /**< instance sram_ctrl_ret_aon of sram_ctrl */
120 kDtInstanceIdSramCtrlMain = 36, /**< instance sram_ctrl_main of sram_ctrl */
121 kDtInstanceIdSysrstCtrlAon = 37, /**< instance sysrst_ctrl_aon of sysrst_ctrl */
122 kDtInstanceIdUart0 = 38, /**< instance uart0 of uart */
123 kDtInstanceIdUart1 = 39, /**< instance uart1 of uart */
124 kDtInstanceIdUart2 = 40, /**< instance uart2 of uart */
125 kDtInstanceIdUart3 = 41, /**< instance uart3 of uart */
126 kDtInstanceIdUsbdev = 42, /**< instance usbdev of usbdev */
128
129enum {
130 kDtInstanceIdCount = 43, /**< Number of instance IDs */
131};
132
133
134/**
135 * Get the instance type of a device instance.
136 *
137 * For example the instance type of `kDtUart0` is `kDtInstanceTypeUart`.
138 *
139 * @param id An instance ID.
140 * @return The instance type, or `kDtInstanceIdUnknown` if the ID is not valid.
141 */
143
144/** PLIC IRQ ID type.
145 *
146 * This type represents a raw IRQ ID from the PLIC.
147 *
148 * This is an alias to the top's `plic_irq_id_t` type for backward compatibility
149 * with existing code.
150 */
152
153/** PLIC IRQ ID for no interrupt. */
154static const dt_plic_irq_id_t kDtPlicIrqIdNone = kTopEarlgreyPlicIrqIdNone;
155
156/**
157 * Get the instance ID for a given PLIC IRQ ID.
158 *
159 * For example, on earlgrey, the instance ID of `kTopEarlgreyPlicIrqIdUart0TxWatermark`
160 * is `kDtInstanceIdUart0`. One can then use the type specific function to retrieve the
161 * IRQ name, for example `dt_uart_irq_from_plic_id` for the UART.
162 *
163 * @param irq A PLIC ID.
164 * @return The instance ID, or `kDtInstanceIdUnknown` if the PLIC ID is not valid.
165 */
167
168/**
169 * Alert ID type.
170 *
171 * This type represents a raw alert ID from the Alert Handler.
172 *
173 * This is an alias to the top's `alert_id_t` type for backward compatibility
174 * with existing code.
175 */
177
178/** Number of alerts. */
179enum {
180 /** Total number of alert IDs. */
181 kDtAlertCount = kTopEarlgreyAlertIdLast + 1,
182};
183
184/**
185 * Get the instance ID for a given alert ID.
186 *
187 * For example, on earlgrey, the instance ID of `kTopEarlgreyAlertIdUart0FatalFault` is
188 * `kDtInstanceIdUart0`. One can then use the type specific function to retrieve the
189 * alert name, for example `dt_uart_alert_from_alert_id` for the UART.
190 *
191 * @param alert An alert ID.
192 * @return The instance ID, or `kDtInstanceIdUnknown` if the alert ID is not valid.
193 */
195
196/**
197 * List of clocks.
198 *
199 * Clocks are guaranteed to be numbered consecutively from 0.
200 */
201typedef enum dt_clock {
202 kDtClockMain = 0, /**< clock main */
203 kDtClockIo = 1, /**< clock io */
204 kDtClockUsb = 2, /**< clock usb */
205 kDtClockAon = 3, /**< clock aon */
206 kDtClockIoDiv2 = 4, /**< clock io_div2 */
207 kDtClockIoDiv4 = 5, /**< clock io_div4 */
209
210enum {
211 kDtClockCount = 6, /**< Number of clocks */
212};
213
214
215/**
216 * Get the frequency of a clock.
217 *
218 * @param clk A clock ID.
219 * @return Clock frequency in Hz.
220 */
222
223/**
224 * List of resets.
225 *
226 * Resets are guaranteed to be numbered consecutively from 0.
227 */
228typedef enum dt_reset {
229 kDtResetUnknown = 0, /**< Unknown reset */
230 kDtResetPorAon = 1, /**< Reset node por_aon */
231 kDtResetLcSrc = 2, /**< Reset node lc_src */
232 kDtResetSysSrc = 3, /**< Reset node sys_src */
233 kDtResetPor = 4, /**< Reset node por */
234 kDtResetPorIo = 5, /**< Reset node por_io */
235 kDtResetPorIoDiv2 = 6, /**< Reset node por_io_div2 */
236 kDtResetPorIoDiv4 = 7, /**< Reset node por_io_div4 */
237 kDtResetPorUsb = 8, /**< Reset node por_usb */
238 kDtResetLc = 9, /**< Reset node lc */
239 kDtResetLcAon = 10, /**< Reset node lc_aon */
240 kDtResetLcIo = 11, /**< Reset node lc_io */
241 kDtResetLcIoDiv2 = 12, /**< Reset node lc_io_div2 */
242 kDtResetLcIoDiv4 = 13, /**< Reset node lc_io_div4 */
243 kDtResetLcUsb = 14, /**< Reset node lc_usb */
244 kDtResetSys = 15, /**< Reset node sys */
245 kDtResetSysIoDiv4 = 16, /**< Reset node sys_io_div4 */
246 kDtResetSpiDevice = 17, /**< Reset node spi_device */
247 kDtResetSpiHost0 = 18, /**< Reset node spi_host0 */
248 kDtResetSpiHost1 = 19, /**< Reset node spi_host1 */
249 kDtResetUsb = 20, /**< Reset node usb */
250 kDtResetUsbAon = 21, /**< Reset node usb_aon */
251 kDtResetI2c0 = 22, /**< Reset node i2c0 */
252 kDtResetI2c1 = 23, /**< Reset node i2c1 */
253 kDtResetI2c2 = 24, /**< Reset node i2c2 */
255
256enum {
257 kDtResetCount = 25, /**< Number of resets */
258};
259
260
261/**
262 * List of pads names.
263 */
264typedef enum dt_pad {
265 kDtPadConstantZero = 0, /**< Pad that is constantly tied to zero (input) */
266 kDtPadConstantOne = 1, /**< Pad that is constantly tied to one (input) */
267 kDtPadIoa0 = 2, /**< Muxed IO pad */
268 kDtPadIoa1 = 3, /**< Muxed IO pad */
269 kDtPadIoa2 = 4, /**< Muxed IO pad */
270 kDtPadIoa3 = 5, /**< Muxed IO pad */
271 kDtPadIoa4 = 6, /**< Muxed IO pad */
272 kDtPadIoa5 = 7, /**< Muxed IO pad */
273 kDtPadIoa6 = 8, /**< Muxed IO pad */
274 kDtPadIoa7 = 9, /**< Muxed IO pad */
275 kDtPadIoa8 = 10, /**< Muxed IO pad */
276 kDtPadIob0 = 11, /**< Muxed IO pad */
277 kDtPadIob1 = 12, /**< Muxed IO pad */
278 kDtPadIob2 = 13, /**< Muxed IO pad */
279 kDtPadIob3 = 14, /**< Muxed IO pad */
280 kDtPadIob4 = 15, /**< Muxed IO pad */
281 kDtPadIob5 = 16, /**< Muxed IO pad */
282 kDtPadIob6 = 17, /**< Muxed IO pad */
283 kDtPadIob7 = 18, /**< Muxed IO pad */
284 kDtPadIob8 = 19, /**< Muxed IO pad */
285 kDtPadIob9 = 20, /**< Muxed IO pad */
286 kDtPadIob10 = 21, /**< Muxed IO pad */
287 kDtPadIob11 = 22, /**< Muxed IO pad */
288 kDtPadIob12 = 23, /**< Muxed IO pad */
289 kDtPadIoc0 = 24, /**< Muxed IO pad */
290 kDtPadIoc1 = 25, /**< Muxed IO pad */
291 kDtPadIoc2 = 26, /**< Muxed IO pad */
292 kDtPadIoc3 = 27, /**< Muxed IO pad */
293 kDtPadIoc4 = 28, /**< Muxed IO pad */
294 kDtPadIoc5 = 29, /**< Muxed IO pad */
295 kDtPadIoc6 = 30, /**< Muxed IO pad */
296 kDtPadIoc7 = 31, /**< Muxed IO pad */
297 kDtPadIoc8 = 32, /**< Muxed IO pad */
298 kDtPadIoc9 = 33, /**< Muxed IO pad */
299 kDtPadIoc10 = 34, /**< Muxed IO pad */
300 kDtPadIoc11 = 35, /**< Muxed IO pad */
301 kDtPadIoc12 = 36, /**< Muxed IO pad */
302 kDtPadIor0 = 37, /**< Muxed IO pad */
303 kDtPadIor1 = 38, /**< Muxed IO pad */
304 kDtPadIor2 = 39, /**< Muxed IO pad */
305 kDtPadIor3 = 40, /**< Muxed IO pad */
306 kDtPadIor4 = 41, /**< Muxed IO pad */
307 kDtPadIor5 = 42, /**< Muxed IO pad */
308 kDtPadIor6 = 43, /**< Muxed IO pad */
309 kDtPadIor7 = 44, /**< Muxed IO pad */
310 kDtPadIor10 = 45, /**< Muxed IO pad */
311 kDtPadIor11 = 46, /**< Muxed IO pad */
312 kDtPadIor12 = 47, /**< Muxed IO pad */
313 kDtPadIor13 = 48, /**< Muxed IO pad */
314 kDtPadUsbdevUsbDp = 49, /**< */
315 kDtPadUsbdevUsbDn = 50, /**< */
316 kDtPadSpiHost0Sd0 = 51, /**< SPI host data */
317 kDtPadSpiHost0Sd1 = 52, /**< SPI host data */
318 kDtPadSpiHost0Sd2 = 53, /**< SPI host data */
319 kDtPadSpiHost0Sd3 = 54, /**< SPI host data */
320 kDtPadSpiDeviceSd0 = 55, /**< SPI device data */
321 kDtPadSpiDeviceSd1 = 56, /**< SPI device data */
322 kDtPadSpiDeviceSd2 = 57, /**< SPI device data */
323 kDtPadSpiDeviceSd3 = 58, /**< SPI device data */
324 kDtPadSysrstCtrlAonEcRstL = 59, /**< Dedicated sysrst_ctrl output (ec_rst_l) */
325 kDtPadSysrstCtrlAonFlashWpL = 60, /**< Dedicated sysrst_ctrl output (flash_wp_l)) */
326 kDtPadSpiDeviceSck = 61, /**< SPI device clock */
327 kDtPadSpiDeviceCsb = 62, /**< SPI device chip select */
328 kDtPadSpiHost0Sck = 63, /**< SPI host clock */
329 kDtPadSpiHost0Csb = 64, /**< SPI host chip select */
331
332enum {
333 kDtPadCount = 65, /**< Number of pads */
334};
335
336
337/** Type of peripheral I/O. */
338typedef enum dt_periph_io_type {
339 /** This peripheral I/O is connected to a muxed IO (MIO). */
341 /** This peripheral I/O is connected to a direct IO (DIO). */
343 /** This peripheral I/O is not connected to either a MIO or a DIO. */
346
347
348/** Direction of a peripheral I/O. */
349typedef enum dt_periph_io_dir {
350 /** This peripheral I/O is an input. */
352 /** This peripheral I/O is an output */
354 /** This peripheral I/O is an input-output */
357
358/** Peripheral I/O description.
359 *
360 * A `dt_periph_io_t` represents a HW IP block peripheral I/O, which can be an input, output or both.
361 * Importantly, this only represents how the block peripheral I/O is wired, i.e.
362 * whether it is connected a MIO or a direct IO on the pinmux, and the relevant information necessary to
363 * configure it.
364 *
365 * **Note:** The fields of this structure are internal, use the dt_periph_io_* functions to access them.
366 */
367typedef struct dt_periph_io {
368 struct {
369 dt_periph_io_type_t type; /**< Peripheral I/O type */
370 dt_periph_io_dir_t dir; /**< Peripheral I/O direction */
371 /**
372 * For `kDtPeriphIoTypeMio`: peripheral input number. This is the index of the MIO_PERIPH_INSEL register
373 * that controls this peripheral I/O.
374 *
375 * For `kDtPeriphIoTypeDio`: DIO pad number. This is the index of the various DIO_PAD_* registers
376 * that control this peripheral I/O.
377 */
378 uint16_t periph_input_or_direct_pad;
379 /**
380 * For `kDtPeriphIoTypeMio`: peripheral output number. This is the value to put in the MIO_OUTSEL registers
381 * to connect an output to this peripheral I/O. For `kDtPeriphIoTypeDio`: the pad index (`dt_pad_t`) to which this I/O is connected.
382 */
383 uint16_t outsel_or_dt_pad;
384 } __internal; /**< Private fields */
386
387
388/* Peripheral I/O that is constantly tied to high-Z (output only) */
389extern const dt_periph_io_t kDtPeriphIoConstantHighZ;
390
391/* Peripheral I/O that is constantly tied to one (output only) */
392extern const dt_periph_io_t kDtPeriphIoConstantZero;
393
394/* Peripheral I/O that is constantly tied to zero (output only) */
395extern const dt_periph_io_t kDtPeriphIoConstantOne;
396
397/**
398 * Return the type of a `dt_periph_io_t`.
399 *
400 * @param periph_io A peripheral I/O description.
401 * @return The peripheral I/O type (MIO, DIO, etc).
402 */
404 return periph_io.__internal.type;
405}
406
407/**
408 * Return the direction of a `dt_periph_io_t`.
409 *
410 * @param periph_io A peripheral I/O description.
411 * @return The peripheral I/O direction.
412 */
413static inline dt_periph_io_dir_t dt_periph_io_dir(dt_periph_io_t periph_io) {
414 return periph_io.__internal.dir;
415}
416
417/**
418 * Pinmux types.
419 *
420 * These types are aliases to top-level types for backward compatibility
421 * with existing code.
422 */
424typedef top_earlgrey_pinmux_insel_t dt_pinmux_insel_t;
425typedef top_earlgrey_pinmux_outsel_t dt_pinmux_outsel_t;
426typedef top_earlgrey_pinmux_mio_out_t dt_pinmux_mio_out_t;
427typedef top_earlgrey_direct_pads_t dt_pinmux_direct_pad_t;
428typedef top_earlgrey_muxed_pads_t dt_pinmux_muxed_pad_t;
429
430/** Tie constantly to zero. */
431static const dt_pinmux_outsel_t kDtPinmuxOutselConstantZero = kTopEarlgreyPinmuxOutselConstantZero;
432
433/** Tie constantly to one. */
434static const dt_pinmux_outsel_t kDtPinmuxOutselConstantOne = kTopEarlgreyPinmuxOutselConstantOne;
435
436/** Tie constantly to high-Z. */
437static const dt_pinmux_outsel_t kDtPinmuxOutselConstantHighZ = kTopEarlgreyPinmuxOutselConstantHighZ;
438
439/**
440 * Return the peripheral input for an MIO peripheral I/O.
441 *
442 * This is the index of the `MIO_PERIPH_INSEL` pinmux register that controls this peripheral I/O.
443 *
444 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
445 * @return The peripheral input number of the MIO that this peripheral I/O is connected to.
446 *
447 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
448 * inputs (`kDtPeriphIoDirIn`). For any other peripheral I/O, the return value is unspecified.
449 */
450static inline dt_pinmux_peripheral_in_t dt_periph_io_mio_periph_input(dt_periph_io_t periph_io) {
451 return (dt_pinmux_peripheral_in_t)periph_io.__internal.periph_input_or_direct_pad;
452}
453
454/**
455 * Return the outsel for an MIO peripheral I/O.
456 *
457 * This is the value to put in the `MIO_OUTSEL` pinmux registers to connect a pad to this peripheral I/O.
458 *
459 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
460 * @return The outsel of the MIO that this peripheral I/O is connected to.
461 *
462 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
463 * outputs (`kDtPeriphIoDirOut`). For any other peripheral I/O, the return value is unspecified.
464 */
465static inline dt_pinmux_outsel_t dt_periph_io_mio_outsel(dt_periph_io_t periph_io) {
466 return (dt_pinmux_outsel_t)periph_io.__internal.outsel_or_dt_pad;
467}
468
469/**
470 * Return the direct pad number of a DIO peripheral I/O.
471 *
472 * This is the index of the various `DIO_PAD_*` pinmux registers that control this peripheral I/O.
473 *
474 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
475 * @return The direct pad number of the DIO that this peripheral I/O is connected to.
476 *
477 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
478 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
479 */
480static inline dt_pinmux_direct_pad_t dt_periph_io_dio_pad_index(dt_periph_io_t periph_io) {
481 return (dt_pinmux_direct_pad_t)periph_io.__internal.periph_input_or_direct_pad;
482}
483
484/**
485 * Return the pad of a DIO peripheral I/O.
486 *
487 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
488 * @return The pad to which this peripheral I/O is connected to.
489 *
490 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
491 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
492 */
493static inline dt_pad_t dt_periph_io_dio_pad(dt_periph_io_t periph_io) {
494 return (dt_pad_t)periph_io.__internal.outsel_or_dt_pad;
495}
496
497/** Type of a pad. */
498typedef enum dt_pad_type {
499 /** This pad is a muxed IO (MIO). */
501 /** This pad is a direct IO (DIO). */
503 /** This pad is not an MIO or a DIO. */
506
507/**
508 * Return the type of a `dt_pad_t`.
509 *
510 * @param pad A pad description.
511 * @return The pad type (MIO, DIO, etc).
512 */
514
515/**
516 * Return the pad out number for an MIO pad.
517 *
518 * This is the index of the `MIO_OUT` registers that control this pad
519 * (or the output part of this pad).
520 *
521 * @param pad A pad of type `kDtPadTypeMio`.
522 * @return The pad out number of the MIO.
523 *
524 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio` which are
525 * either inputs or inouts. For any other pad, the return value is unspecified.
526 */
527dt_pinmux_mio_out_t dt_pad_mio_out(dt_pad_t pad);
528
529/**
530 * Return the pad out number for an MIO pad.
531 *
532 * This is the index of the `MIO_PAD` registers that control this pad
533 * (or the output part of this pad).
534 *
535 * @param pad A pad of type `kDtPadTypeMio`.
536 * @return The pad out number of the MIO.
537 *
538 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
539 * For any other pad, the return value is unspecified.
540 */
541dt_pinmux_muxed_pad_t dt_pad_mio_pad_index(dt_pad_t pad);
542
543/**
544 * Return the insel for an MIO pad.
545 *
546 * This is the value to put in the `MIO_PERIPH_INSEL` registers to connect a peripheral I/O to this pad.
547 *
548 * @param pad A pad of type `kDtPadTypeMio`.
549 * @return The insel of the MIO that this pad is connected to.
550 *
551 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
552 * For any other pad, the return value is unspecified.
553 */
554dt_pinmux_insel_t dt_pad_mio_insel(dt_pad_t pad);
555
556/**
557 * Return the direct pad number of a DIO pad.
558 *
559 * This is the index of the various `DIO_PAD_*` registers that control this pad.
560 *
561 * @param pad A pad of type `kDtPadTypeDio`.
562 * @return The direct pad number of the DID that this pad is connected to.
563 *
564 * **Note:** This function only makes sense for pads of type `kDtPeriphIoTypeDio` which are
565 * either outputs or inouts. For any other pad type, the return value is unspecified.
566 */
567dt_pinmux_direct_pad_t dt_pad_dio_pad_index(dt_pad_t pad);
568
569#ifdef __cplusplus
570} // extern "C"
571#endif // __cplusplus
572
573#endif // OPENTITAN_TOP_EARLGREY_DT_API_H_