Software APIs
dt_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_DARJEELING_DT_API_H_
8#define OPENTITAN_TOP_DARJEELING_DT_API_H_
9
10/**
11 * @file
12 * @brief Device Tables (DT) API for top darjeeling
13 *
14 * This file contains the type definitions and global functions of the DT.
15 *
16 * The DT models the chip as a collection of instances. Each instance has
17 * a type (the IP block) and a number of attributes such as I/Os, IRQs
18 * and so on. The DT also provides top-specific lists of global resources
19 * such as I/O pads, clocks and interrupts.
20 */
21
22#include <stddef.h>
23#include <stdint.h>
25
26/**
27 * List of device types.
28 *
29 * Device types are guaranteed to be numbered consecutively from 0.
30 */
31typedef enum dt_device_type {
32 kDtDeviceTypeUnknown = 0, /**< Instance of unknown type */
33 kDtDeviceTypeAcRangeCheck = 1, /**< instance of ac_range_check */
34 kDtDeviceTypeAes = 2, /**< instance of aes */
35 kDtDeviceTypeAlertHandler = 3, /**< instance of alert_handler */
36 kDtDeviceTypeAonTimer = 4, /**< instance of aon_timer */
37 kDtDeviceTypeAst = 5, /**< instance of ast */
38 kDtDeviceTypeClkmgr = 6, /**< instance of clkmgr */
39 kDtDeviceTypeCsrng = 7, /**< instance of csrng */
40 kDtDeviceTypeDma = 8, /**< instance of dma */
41 kDtDeviceTypeEdn = 9, /**< instance of edn */
42 kDtDeviceTypeGpio = 10, /**< instance of gpio */
43 kDtDeviceTypeHmac = 11, /**< instance of hmac */
44 kDtDeviceTypeI2c = 12, /**< instance of i2c */
45 kDtDeviceTypeKeymgrDpe = 13, /**< instance of keymgr_dpe */
46 kDtDeviceTypeKmac = 14, /**< instance of kmac */
47 kDtDeviceTypeLcCtrl = 15, /**< instance of lc_ctrl */
48 kDtDeviceTypeMbx = 16, /**< instance of mbx */
49 kDtDeviceTypeOtbn = 17, /**< instance of otbn */
50 kDtDeviceTypeOtpCtrl = 18, /**< instance of otp_ctrl */
51 kDtDeviceTypeOtpMacro = 19, /**< instance of otp_macro */
52 kDtDeviceTypePinmux = 20, /**< instance of pinmux */
53 kDtDeviceTypePwrmgr = 21, /**< instance of pwrmgr */
54 kDtDeviceTypeRaclCtrl = 22, /**< instance of racl_ctrl */
55 kDtDeviceTypeRomCtrl = 23, /**< instance of rom_ctrl */
56 kDtDeviceTypeRstmgr = 24, /**< instance of rstmgr */
57 kDtDeviceTypeRvCoreIbex = 25, /**< instance of rv_core_ibex */
58 kDtDeviceTypeRvDm = 26, /**< instance of rv_dm */
59 kDtDeviceTypeRvPlic = 27, /**< instance of rv_plic */
60 kDtDeviceTypeRvTimer = 28, /**< instance of rv_timer */
61 kDtDeviceTypeSocDbgCtrl = 29, /**< instance of soc_dbg_ctrl */
62 kDtDeviceTypeSocProxy = 30, /**< instance of soc_proxy */
63 kDtDeviceTypeSpiDevice = 31, /**< instance of spi_device */
64 kDtDeviceTypeSpiHost = 32, /**< instance of spi_host */
65 kDtDeviceTypeSramCtrl = 33, /**< instance of sram_ctrl */
66 kDtDeviceTypeUart = 34, /**< instance of uart */
67 kDtDeviceTypeCount = 35, /**< \internal Number of instance types */
69
70/**
71 * List of instance IDs.
72 *
73 * Instance IDs are guaranteed to be numbered consecutively from 0.
74 */
75typedef enum dt_instance_id {
76 kDtInstanceIdUnknown = 0, /**< Unknown instance */
77 kDtInstanceIdAcRangeCheck = 1, /**< instance ac_range_check of ac_range_check */
78 kDtInstanceIdAes = 2, /**< instance aes of aes */
79 kDtInstanceIdAlertHandler = 3, /**< instance alert_handler of alert_handler */
80 kDtInstanceIdAonTimerAon = 4, /**< instance aon_timer_aon of aon_timer */
81 kDtInstanceIdAst = 5, /**< instance ast of ast */
82 kDtInstanceIdClkmgrAon = 6, /**< instance clkmgr_aon of clkmgr */
83 kDtInstanceIdCsrng = 7, /**< instance csrng of csrng */
84 kDtInstanceIdDma = 8, /**< instance dma of dma */
85 kDtInstanceIdEdn0 = 9, /**< instance edn0 of edn */
86 kDtInstanceIdEdn1 = 10, /**< instance edn1 of edn */
87 kDtInstanceIdGpio = 11, /**< instance gpio of gpio */
88 kDtInstanceIdHmac = 12, /**< instance hmac of hmac */
89 kDtInstanceIdI2c0 = 13, /**< instance i2c0 of i2c */
90 kDtInstanceIdKeymgrDpe = 14, /**< instance keymgr_dpe of keymgr_dpe */
91 kDtInstanceIdKmac = 15, /**< instance kmac of kmac */
92 kDtInstanceIdLcCtrl = 16, /**< instance lc_ctrl of lc_ctrl */
93 kDtInstanceIdMbx0 = 17, /**< instance mbx0 of mbx */
94 kDtInstanceIdMbx1 = 18, /**< instance mbx1 of mbx */
95 kDtInstanceIdMbx2 = 19, /**< instance mbx2 of mbx */
96 kDtInstanceIdMbx3 = 20, /**< instance mbx3 of mbx */
97 kDtInstanceIdMbx4 = 21, /**< instance mbx4 of mbx */
98 kDtInstanceIdMbx5 = 22, /**< instance mbx5 of mbx */
99 kDtInstanceIdMbx6 = 23, /**< instance mbx6 of mbx */
100 kDtInstanceIdMbxJtag = 24, /**< instance mbx_jtag of mbx */
101 kDtInstanceIdMbxPcie0 = 25, /**< instance mbx_pcie0 of mbx */
102 kDtInstanceIdMbxPcie1 = 26, /**< instance mbx_pcie1 of mbx */
103 kDtInstanceIdOtbn = 27, /**< instance otbn of otbn */
104 kDtInstanceIdOtpCtrl = 28, /**< instance otp_ctrl of otp_ctrl */
105 kDtInstanceIdOtpMacro = 29, /**< instance otp_macro of otp_macro */
106 kDtInstanceIdPinmuxAon = 30, /**< instance pinmux_aon of pinmux */
107 kDtInstanceIdPwrmgrAon = 31, /**< instance pwrmgr_aon of pwrmgr */
108 kDtInstanceIdRaclCtrl = 32, /**< instance racl_ctrl of racl_ctrl */
109 kDtInstanceIdRomCtrl0 = 33, /**< instance rom_ctrl0 of rom_ctrl */
110 kDtInstanceIdRomCtrl1 = 34, /**< instance rom_ctrl1 of rom_ctrl */
111 kDtInstanceIdRstmgrAon = 35, /**< instance rstmgr_aon of rstmgr */
112 kDtInstanceIdRvCoreIbex = 36, /**< instance rv_core_ibex of rv_core_ibex */
113 kDtInstanceIdRvDm = 37, /**< instance rv_dm of rv_dm */
114 kDtInstanceIdRvPlic = 38, /**< instance rv_plic of rv_plic */
115 kDtInstanceIdRvTimer = 39, /**< instance rv_timer of rv_timer */
116 kDtInstanceIdSocDbgCtrl = 40, /**< instance soc_dbg_ctrl of soc_dbg_ctrl */
117 kDtInstanceIdSocProxy = 41, /**< instance soc_proxy of soc_proxy */
118 kDtInstanceIdSpiDevice = 42, /**< instance spi_device of spi_device */
119 kDtInstanceIdSpiHost0 = 43, /**< instance spi_host0 of spi_host */
120 kDtInstanceIdSramCtrlRetAon = 44, /**< instance sram_ctrl_ret_aon of sram_ctrl */
121 kDtInstanceIdSramCtrlMain = 45, /**< instance sram_ctrl_main of sram_ctrl */
122 kDtInstanceIdSramCtrlMbox = 46, /**< instance sram_ctrl_mbox of sram_ctrl */
123 kDtInstanceIdUart0 = 47, /**< instance uart0 of uart */
124 kDtInstanceIdCount = 48, /**< \internal Number of instance IDs */
126
127/**
128 * Get the instance type of a device instance.
129 *
130 * For example the instance type of `kDtUart0` is `kDtInstanceTypeUart`.
131 *
132 * @param id An instance ID.
133 * @return The instance type, or `kDtInstanceIdUnknown` if the ID is not valid.
134 */
136
137/** PLIC IRQ ID type.
138 *
139 * This type represents a raw IRQ ID from the PLIC.
140 *
141 * This is an alias to the top's `plic_irq_id_t` type for backward compatibility
142 * with existing code.
143 */
145
146/** PLIC IRQ ID for no interrupt. */
147static const dt_plic_irq_id_t kDtPlicIrqIdNone=kTopDarjeelingPlicIrqIdNone;
148
149/**
150 * Get the instance ID for a given PLIC IRQ ID.
151 *
152 * For example, on earlgrey, the instance ID of `kTopEarlgreyPlicIrqIdUart0TxWatermark`
153 * is `kDtInstanceIdUart0`. One can then use the type specific function to retrieve the
154 * IRQ name, for example `dt_uart_irq_from_plic_id` for the UART.
155 *
156 * @param irq A PLIC ID.
157 * @return The instance ID, or `kDtInstanceIdUnknown` if the PLIC ID is not valid.
158 */
160
161/**
162 * Alert ID type.
163 *
164 * This type represents a raw alert ID from the Alert Handler.
165 *
166 * This is an alias to the top's `alert_id_t` type for backward compatability
167 * with existing code.
168 */
170
171/** Number of alerts. */
172enum {
173 /** Total number of alert IDs. */
174 kDtAlertCount = kTopDarjeelingAlertIdLast + 1,
175};
176
177/**
178 * Get the instance ID for a given alert ID.
179 *
180 * For example, on earlgrey, the instance ID of `kTopEarlgreyAlertIdUart0FatalFault` is
181 * `kDtInstanceIdUart0`. One can then use the type specific function to retrieve the
182 * alert name, for example `dt_uart_alert_from_alert_id` for the UART.
183 *
184 * @param alert An alert ID.
185 * @return The instance ID, or `kDtInstanceIdUnknown` if the alert ID is not valid.
186 */
188
189/**
190 * List of clocks.
191 *
192 * Clocks are guaranteed to be numbered consecutively from 0.
193 */
194typedef enum dt_clock {
195 kDtClockMain = 0, /**< clock main */
196 kDtClockIo = 1, /**< clock io */
197 kDtClockAon = 2, /**< clock aon */
198 kDtClockIoDiv2 = 3, /**< clock io_div2 */
199 kDtClockIoDiv4 = 4, /**< clock io_div4 */
200 kDtClockCount = 5, /**< \internal Number of clocks */
202
203/**
204 * Get the frequency of a clock.
205 *
206 * @param clk A clock ID.
207 * @return Clock frequency in Hz.
208 */
210
211/**
212 * List of resets.
213 *
214 * Resets are guaranteed to be numbered consecutively from 0.
215 */
216typedef enum dt_reset {
217 kDtResetUnknown = 0, /**< Unknown reset */
218 kDtResetPorAon = 1, /**< Reset node por_aon */
219 kDtResetLcSrc = 2, /**< Reset node lc_src */
220 kDtResetSysSrc = 3, /**< Reset node sys_src */
221 kDtResetPor = 4, /**< Reset node por */
222 kDtResetPorIo = 5, /**< Reset node por_io */
223 kDtResetPorIoDiv2 = 6, /**< Reset node por_io_div2 */
224 kDtResetPorIoDiv4 = 7, /**< Reset node por_io_div4 */
225 kDtResetLc = 8, /**< Reset node lc */
226 kDtResetLcAon = 9, /**< Reset node lc_aon */
227 kDtResetLcIo = 10, /**< Reset node lc_io */
228 kDtResetLcIoDiv2 = 11, /**< Reset node lc_io_div2 */
229 kDtResetLcIoDiv4 = 12, /**< Reset node lc_io_div4 */
230 kDtResetSys = 13, /**< Reset node sys */
231 kDtResetSysIoDiv4 = 14, /**< Reset node sys_io_div4 */
232 kDtResetSpiDevice = 15, /**< Reset node spi_device */
233 kDtResetSpiHost0 = 16, /**< Reset node spi_host0 */
234 kDtResetI2c0 = 17, /**< Reset node i2c0 */
235 kDtResetCount = 18, /**< \internal Number of resets */
237
238/**
239 * List of pads names.
240 */
241typedef enum dt_pad {
242 kDtPadMio0 = 0, /**< Muxed IO pad */
243 kDtPadMio1 = 1, /**< Muxed IO pad */
244 kDtPadMio2 = 2, /**< Muxed IO pad */
245 kDtPadMio3 = 3, /**< Muxed IO pad */
246 kDtPadMio4 = 4, /**< Muxed IO pad */
247 kDtPadMio5 = 5, /**< Muxed IO pad */
248 kDtPadMio6 = 6, /**< Muxed IO pad */
249 kDtPadMio7 = 7, /**< Muxed IO pad */
250 kDtPadMio8 = 8, /**< Muxed IO pad */
251 kDtPadMio9 = 9, /**< Muxed IO pad */
252 kDtPadMio10 = 10, /**< Muxed IO pad */
253 kDtPadMio11 = 11, /**< Muxed IO pad */
254 kDtPadSpiHost0Sd0 = 12, /**< SPI host data */
255 kDtPadSpiHost0Sd1 = 13, /**< SPI host data */
256 kDtPadSpiHost0Sd2 = 14, /**< SPI host data */
257 kDtPadSpiHost0Sd3 = 15, /**< SPI host data */
258 kDtPadSpiDeviceSd0 = 16, /**< SPI device data */
259 kDtPadSpiDeviceSd1 = 17, /**< SPI device data */
260 kDtPadSpiDeviceSd2 = 18, /**< SPI device data */
261 kDtPadSpiDeviceSd3 = 19, /**< SPI device data */
262 kDtPadI2c0Scl = 20, /**< I2C clock */
263 kDtPadI2c0Sda = 21, /**< I2C data */
264 kDtPadGpioGpio0 = 22, /**< GPIO pad */
265 kDtPadGpioGpio1 = 23, /**< GPIO pad */
266 kDtPadGpioGpio2 = 24, /**< GPIO pad */
267 kDtPadGpioGpio3 = 25, /**< GPIO pad */
268 kDtPadGpioGpio4 = 26, /**< GPIO pad */
269 kDtPadGpioGpio5 = 27, /**< GPIO pad */
270 kDtPadGpioGpio6 = 28, /**< GPIO pad */
271 kDtPadGpioGpio7 = 29, /**< GPIO pad */
272 kDtPadGpioGpio8 = 30, /**< GPIO pad */
273 kDtPadGpioGpio9 = 31, /**< GPIO pad */
274 kDtPadGpioGpio10 = 32, /**< GPIO pad */
275 kDtPadGpioGpio11 = 33, /**< GPIO pad */
276 kDtPadGpioGpio12 = 34, /**< GPIO pad */
277 kDtPadGpioGpio13 = 35, /**< GPIO pad */
278 kDtPadGpioGpio14 = 36, /**< GPIO pad */
279 kDtPadGpioGpio15 = 37, /**< GPIO pad */
280 kDtPadGpioGpio16 = 38, /**< GPIO pad */
281 kDtPadGpioGpio17 = 39, /**< GPIO pad */
282 kDtPadGpioGpio18 = 40, /**< GPIO pad */
283 kDtPadGpioGpio19 = 41, /**< GPIO pad */
284 kDtPadGpioGpio20 = 42, /**< GPIO pad */
285 kDtPadGpioGpio21 = 43, /**< GPIO pad */
286 kDtPadGpioGpio22 = 44, /**< GPIO pad */
287 kDtPadGpioGpio23 = 45, /**< GPIO pad */
288 kDtPadGpioGpio24 = 46, /**< GPIO pad */
289 kDtPadGpioGpio25 = 47, /**< GPIO pad */
290 kDtPadGpioGpio26 = 48, /**< GPIO pad */
291 kDtPadGpioGpio27 = 49, /**< GPIO pad */
292 kDtPadGpioGpio28 = 50, /**< GPIO pad */
293 kDtPadGpioGpio29 = 51, /**< GPIO pad */
294 kDtPadGpioGpio30 = 52, /**< GPIO pad */
295 kDtPadGpioGpio31 = 53, /**< GPIO pad */
296 kDtPadSpiDeviceSck = 54, /**< SPI device clock */
297 kDtPadSpiDeviceCsb = 55, /**< SPI device chip select */
298 kDtPadSpiDeviceTpmCsb = 56, /**< SPI device TPM chip select */
299 kDtPadUart0Rx = 57, /**< UART receive */
300 kDtPadSocProxySocGpi0 = 58, /**< SoC general purpose input */
301 kDtPadSocProxySocGpi1 = 59, /**< SoC general purpose input */
302 kDtPadSocProxySocGpi2 = 60, /**< SoC general purpose input */
303 kDtPadSocProxySocGpi3 = 61, /**< SoC general purpose input */
304 kDtPadSocProxySocGpi4 = 62, /**< SoC general purpose input */
305 kDtPadSocProxySocGpi5 = 63, /**< SoC general purpose input */
306 kDtPadSocProxySocGpi6 = 64, /**< SoC general purpose input */
307 kDtPadSocProxySocGpi7 = 65, /**< SoC general purpose input */
308 kDtPadSocProxySocGpi8 = 66, /**< SoC general purpose input */
309 kDtPadSocProxySocGpi9 = 67, /**< SoC general purpose input */
310 kDtPadSocProxySocGpi10 = 68, /**< SoC general purpose input */
311 kDtPadSocProxySocGpi11 = 69, /**< SoC general purpose input */
312 kDtPadSpiHost0Sck = 70, /**< SPI host clock */
313 kDtPadSpiHost0Csb = 71, /**< SPI host chip select */
314 kDtPadUart0Tx = 72, /**< UART transmit */
315 kDtPadSocProxySocGpo0 = 73, /**< SoC general purpose output */
316 kDtPadSocProxySocGpo1 = 74, /**< SoC general purpose output */
317 kDtPadSocProxySocGpo2 = 75, /**< SoC general purpose output */
318 kDtPadSocProxySocGpo3 = 76, /**< SoC general purpose output */
319 kDtPadSocProxySocGpo4 = 77, /**< SoC general purpose output */
320 kDtPadSocProxySocGpo5 = 78, /**< SoC general purpose output */
321 kDtPadSocProxySocGpo6 = 79, /**< SoC general purpose output */
322 kDtPadSocProxySocGpo7 = 80, /**< SoC general purpose output */
323 kDtPadSocProxySocGpo8 = 81, /**< SoC general purpose output */
324 kDtPadSocProxySocGpo9 = 82, /**< SoC general purpose output */
325 kDtPadSocProxySocGpo10 = 83, /**< SoC general purpose output */
326 kDtPadSocProxySocGpo11 = 84, /**< SoC general purpose output */
327 kDtPadCount = 85, /**< \internal Number of pads */
329
330/**
331 * Pinmux types.
332 *
333 * These types are aliases to top-level types for backward compatibility
334 * with existing code.
335 */
337typedef top_darjeeling_pinmux_insel_t dt_pinmux_insel_t;
338typedef top_darjeeling_pinmux_outsel_t dt_pinmux_outsel_t;
339typedef top_darjeeling_pinmux_mio_out_t dt_pinmux_mio_out_t;
340typedef top_darjeeling_direct_pads_t dt_pinmux_direct_pad_t;
341typedef top_darjeeling_muxed_pads_t dt_pinmux_muxed_pad_t;
342
343/** Type of peripheral I/O. */
344typedef enum dt_periph_io_type {
345 /** This peripheral I/O is connected to a muxed IO (MIO). */
347 /** This peripheral I/O is connected to a direct IO (DIO). */
349 /** This peripheral I/O is not connected to either a MIO or a DIO. */
352
353
354/** Direction of a peripheral I/O. */
355typedef enum dt_periph_io_dir {
356 /** This peripheral I/O is an input. */
358 /** This peripheral I/O is an output */
360 /** This peripheral I/O is an input-output */
363
364/** Peripheral I/O description.
365 *
366 * A `dt_periph_io_t` represents a HW IP block peripheral I/O, which can be an input, output or both.
367 * Importantly, this only represents how the block peripheral I/O is wired, i.e.
368 * whether it is connected a MIO or a direct IO on the pinmux, and the relevant information necessary to
369 * configure it.
370 *
371 * **Note:** The fields of this structure are internal, use the dt_periph_io_* functions to access them.
372 */
373typedef struct dt_periph_io {
374 struct {
375 dt_periph_io_type_t type; /**< Peripheral I/O type */
376 dt_periph_io_dir_t dir; /**< Peripheral I/O direction */
377 /**
378 * For `kDtPeriphIoTypeMio`: peripheral input number. This is the index of the MIO_PERIPH_INSEL register
379 * that controls this peripheral I/O.
380 *
381 * For `kDtPeriphIoTypeDio`: DIO pad number. This is the index of the various DIO_PAD_* registers
382 * that control this peripheral I/O.
383 */
384 uint16_t periph_input_or_direct_pad;
385 /**
386 * For `kDtPeriphIoTypeMio`: peripheral output number. This is the value to put in the MIO_OUTSEL registers
387 * to connect an output to this peripheral I/O. For `kDtPeriphIoTypeDio`: the pad index (`dt_pad_t`) to which this I/O is connected.
388 */
389 uint16_t outsel_or_dt_pad;
390 } __internal; /**< Private fields */
392
393
394/** Tie constantly to zero. */
395static const dt_pinmux_outsel_t kDtPinmuxOutselConstantZero = kTopDarjeelingPinmuxOutselConstantZero;
396
397/** Tie constantly to one. */
398static const dt_pinmux_outsel_t kDtPinmuxOutselConstantOne = kTopDarjeelingPinmuxOutselConstantOne;
399
400/** Tie constantly to high-Z. */
401static const dt_pinmux_outsel_t kDtPinmuxOutselConstantHighZ = kTopDarjeelingPinmuxOutselConstantHighZ;
402
403/* Peripheral I/O that is constantly tied to high-Z (output only) */
404extern const dt_periph_io_t kDtPeriphIoConstantHighZ;
405
406/* Peripheral I/O that is constantly tied to one (output only) */
407extern const dt_periph_io_t kDtPeriphIoConstantZero;
408
409/* Peripheral I/O that is constantly tied to zero (output only) */
410extern const dt_periph_io_t kDtPeriphIoConstantOne;
411
412/**
413 * Return the type of a `dt_periph_io_t`.
414 *
415 * @param periph_io A peripheral I/O description.
416 * @return The peripheral I/O type (MIO, DIO, etc).
417 */
419 return periph_io.__internal.type;
420}
421
422/**
423 * Return the direction of a `dt_periph_io_t`.
424 *
425 * @param periph_io A peripheral I/O description.
426 * @return The peripheral I/O direction.
427 */
428static inline dt_periph_io_dir_t dt_periph_io_dir(dt_periph_io_t periph_io) {
429 return periph_io.__internal.dir;
430}
431
432/**
433 * Return the peripheral input for an MIO peripheral I/O.
434 *
435 * This is the index of the `MIO_PERIPH_INSEL` pinmux register that controls this peripheral I/O.
436 *
437 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
438 * @return The peripheral input number of the MIO that this peripheral I/O is connected to.
439 *
440 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
441 * inputs (`kDtPeriphIoDirIn`). For any other peripheral I/O, the return value is unspecified.
442 */
443static inline dt_pinmux_peripheral_in_t dt_periph_io_mio_periph_input(dt_periph_io_t periph_io) {
444 return (dt_pinmux_peripheral_in_t)periph_io.__internal.periph_input_or_direct_pad;
445}
446
447/**
448 * Return the outsel for an MIO peripheral I/O.
449 *
450 * This is the value to put in the `MIO_OUTSEL` pinmux registers to connect a pad to this peripheral I/O.
451 *
452 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
453 * @return The outsel of the MIO that this peripheral I/O is connected to.
454 *
455 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
456 * outputs (`kDtPeriphIoDirOut`). For any other peripheral I/O, the return value is unspecified.
457 */
458static inline dt_pinmux_outsel_t dt_periph_io_mio_outsel(dt_periph_io_t periph_io) {
459 return (dt_pinmux_outsel_t)periph_io.__internal.outsel_or_dt_pad;
460}
461
462/**
463 * Return the direct pad number of a DIO peripheral I/O.
464 *
465 * This is the index of the various `DIO_PAD_*` pinmux registers that control this peripheral I/O.
466 *
467 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
468 * @return The direct pad number of the DIO that this peripheral I/O is connected to.
469 *
470 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
471 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
472 */
473static inline dt_pinmux_direct_pad_t dt_periph_io_dio_pad_index(dt_periph_io_t periph_io) {
474 return (dt_pinmux_direct_pad_t)periph_io.__internal.periph_input_or_direct_pad;
475}
476
477/**
478 * Return the pad of a DIO peripheral I/O.
479 *
480 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
481 * @return The pad to which this peripheral I/O is connected to.
482 *
483 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
484 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
485 */
486static inline dt_pad_t dt_periph_io_dio_pad(dt_periph_io_t periph_io) {
487 return (dt_pad_t)periph_io.__internal.outsel_or_dt_pad;
488}
489
490/** Type of a pad. */
491typedef enum dt_pad_type {
492 /** This pad is a muxed IO (MIO). */
494 /** This pad is a direct IO (DIO). */
496 /** This pad is not an MIO or a DIO. */
499
500/**
501 * Return the type of a `dt_pad_t`.
502 *
503 * @param pad A pad description.
504 * @return The pad type (MIO, DIO, etc).
505 */
507
508/**
509 * Return the pad out number for an MIO pad.
510 *
511 * This is the index of the `MIO_OUT` registers that control this pad
512 * (or the output part of this pad).
513 *
514 * @param pad A pad of type `kDtPadTypeMio`.
515 * @return The pad out number of the MIO.
516 *
517 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio` which are
518 * either inputs or inouts. For any other pad, the return value is unspecified.
519 */
520dt_pinmux_mio_out_t dt_pad_mio_out(dt_pad_t pad);
521
522/**
523 * Return the pad out number for an MIO pad.
524 *
525 * This is the index of the `MIO_PAD` registers that control this pad
526 * (or the output part of this pad).
527 *
528 * @param pad A pad of type `kDtPadTypeMio`.
529 * @return The pad out number of the MIO.
530 *
531 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
532 * For any other pad, the return value is unspecified.
533 */
534dt_pinmux_muxed_pad_t dt_pad_mio_pad_index(dt_pad_t pad);
535
536/**
537 * Return the insel for an MIO pad.
538 *
539 * This is the value to put in the `MIO_PERIPH_INSEL` registers to connect a peripheral I/O to this pad.
540 *
541 * @param pad A pad of type `kDtPadTypeMio`.
542 * @return The insel of the MIO that this pad is connected to.
543 *
544 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
545 * For any other pad, the return value is unspecified.
546 */
547dt_pinmux_insel_t dt_pad_mio_insel(dt_pad_t pad);
548
549/**
550 * Return the direct pad number of a DIO pad.
551 *
552 * This is the index of the various `DIO_PAD_*` registers that control this pad.
553 *
554 * @param pad A pad of type `kDtPadTypeDio`.
555 * @return The direct pad number of the DID that this pad is connected to.
556 *
557 * **Note:** This function only makes sense for pads of type `kDtPeriphIoTypeDio` which are
558 * either outputs or inouts. For any other pad type, the return value is unspecified.
559 */
560dt_pinmux_direct_pad_t dt_pad_dio_pad_index(dt_pad_t pad);
561
562#endif // OPENTITAN_TOP_DARJEELING_DT_API_H_