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_ENGLISHBREAKFAST_DT_API_H_
8#define OPENTITAN_TOP_ENGLISHBREAKFAST_DT_API_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) API for top englishbreakfast
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 kDtDeviceTypeAes = 1, /**< instance of aes */
38 kDtDeviceTypeAonTimer = 2, /**< instance of aon_timer */
39 kDtDeviceTypeAst = 3, /**< instance of ast */
40 kDtDeviceTypeClkmgr = 4, /**< instance of clkmgr */
41 kDtDeviceTypeFlashCtrl = 5, /**< instance of flash_ctrl */
42 kDtDeviceTypeGpio = 6, /**< instance of gpio */
43 kDtDeviceTypePinmux = 7, /**< instance of pinmux */
44 kDtDeviceTypePwrmgr = 8, /**< instance of pwrmgr */
45 kDtDeviceTypeRomCtrl = 9, /**< instance of rom_ctrl */
46 kDtDeviceTypeRstmgr = 10, /**< instance of rstmgr */
47 kDtDeviceTypeRvCoreIbex = 11, /**< instance of rv_core_ibex */
48 kDtDeviceTypeRvPlic = 12, /**< instance of rv_plic */
49 kDtDeviceTypeRvTimer = 13, /**< instance of rv_timer */
50 kDtDeviceTypeSpiDevice = 14, /**< instance of spi_device */
51 kDtDeviceTypeSpiHost = 15, /**< instance of spi_host */
52 kDtDeviceTypeSramCtrl = 16, /**< instance of sram_ctrl */
53 kDtDeviceTypeUart = 17, /**< instance of uart */
54 kDtDeviceTypeUsbdev = 18, /**< instance of usbdev */
55 kDtDeviceTypeCount = 19, /**< \internal Number of instance types */
57
58/**
59 * List of instance IDs.
60 *
61 * Instance IDs are guaranteed to be numbered consecutively from 0.
62 */
63typedef enum dt_instance_id {
64 kDtInstanceIdUnknown = 0, /**< Unknown instance */
65 kDtInstanceIdAes = 1, /**< instance aes of aes */
66 kDtInstanceIdAonTimerAon = 2, /**< instance aon_timer_aon of aon_timer */
67 kDtInstanceIdAst = 3, /**< instance ast of ast */
68 kDtInstanceIdClkmgrAon = 4, /**< instance clkmgr_aon of clkmgr */
69 kDtInstanceIdFlashCtrl = 5, /**< instance flash_ctrl of flash_ctrl */
70 kDtInstanceIdGpio = 6, /**< instance gpio of gpio */
71 kDtInstanceIdPinmuxAon = 7, /**< instance pinmux_aon of pinmux */
72 kDtInstanceIdPwrmgrAon = 8, /**< instance pwrmgr_aon of pwrmgr */
73 kDtInstanceIdRomCtrl = 9, /**< instance rom_ctrl of rom_ctrl */
74 kDtInstanceIdRstmgrAon = 10, /**< instance rstmgr_aon of rstmgr */
75 kDtInstanceIdRvCoreIbex = 11, /**< instance rv_core_ibex of rv_core_ibex */
76 kDtInstanceIdRvPlic = 12, /**< instance rv_plic of rv_plic */
77 kDtInstanceIdRvTimer = 13, /**< instance rv_timer of rv_timer */
78 kDtInstanceIdSpiDevice = 14, /**< instance spi_device of spi_device */
79 kDtInstanceIdSpiHost0 = 15, /**< instance spi_host0 of spi_host */
80 kDtInstanceIdSramCtrlMain = 16, /**< instance sram_ctrl_main of sram_ctrl */
81 kDtInstanceIdUart0 = 17, /**< instance uart0 of uart */
82 kDtInstanceIdUart1 = 18, /**< instance uart1 of uart */
83 kDtInstanceIdUsbdev = 19, /**< instance usbdev of usbdev */
84 kDtInstanceIdCount = 20, /**< \internal Number of instance IDs */
86
87/**
88 * Get the instance type of a device instance.
89 *
90 * For example the instance type of `kDtUart0` is `kDtInstanceTypeUart`.
91 *
92 * @param id An instance ID.
93 * @return The instance type, or `kDtInstanceIdUnknown` if the ID is not valid.
94 */
96
97/** PLIC IRQ ID type.
98 *
99 * This type represents a raw IRQ ID from the PLIC.
100 *
101 * This is an alias to the top's `plic_irq_id_t` type for backward compatibility
102 * with existing code.
103 */
105
106/** PLIC IRQ ID for no interrupt. */
107static const dt_plic_irq_id_t kDtPlicIrqIdNone = kTopEnglishbreakfastPlicIrqIdNone;
108
109/**
110 * Get the instance ID for a given PLIC IRQ ID.
111 *
112 * For example, on earlgrey, the instance ID of `kTopEarlgreyPlicIrqIdUart0TxWatermark`
113 * is `kDtInstanceIdUart0`. One can then use the type specific function to retrieve the
114 * IRQ name, for example `dt_uart_irq_from_plic_id` for the UART.
115 *
116 * @param irq A PLIC ID.
117 * @return The instance ID, or `kDtInstanceIdUnknown` if the PLIC ID is not valid.
118 */
120
121/**
122 * List of clocks.
123 *
124 * Clocks are guaranteed to be numbered consecutively from 0.
125 */
126typedef enum dt_clock {
127 kDtClockMain = 0, /**< clock main */
128 kDtClockIo = 1, /**< clock io */
129 kDtClockUsb = 2, /**< clock usb */
130 kDtClockAon = 3, /**< clock aon */
131 kDtClockIoDiv2 = 4, /**< clock io_div2 */
132 kDtClockIoDiv4 = 5, /**< clock io_div4 */
133 kDtClockCount = 6, /**< \internal Number of clocks */
135
136/**
137 * Get the frequency of a clock.
138 *
139 * @param clk A clock ID.
140 * @return Clock frequency in Hz.
141 */
143
144/**
145 * List of resets.
146 *
147 * Resets are guaranteed to be numbered consecutively from 0.
148 */
149typedef enum dt_reset {
150 kDtResetUnknown = 0, /**< Unknown reset */
151 kDtResetPorAon = 1, /**< Reset node por_aon */
152 kDtResetLcSrc = 2, /**< Reset node lc_src */
153 kDtResetSysSrc = 3, /**< Reset node sys_src */
154 kDtResetPor = 4, /**< Reset node por */
155 kDtResetPorIo = 5, /**< Reset node por_io */
156 kDtResetPorIoDiv2 = 6, /**< Reset node por_io_div2 */
157 kDtResetPorIoDiv4 = 7, /**< Reset node por_io_div4 */
158 kDtResetPorUsb = 8, /**< Reset node por_usb */
159 kDtResetLc = 9, /**< Reset node lc */
160 kDtResetLcIoDiv4 = 10, /**< Reset node lc_io_div4 */
161 kDtResetSys = 11, /**< Reset node sys */
162 kDtResetSysIoDiv4 = 12, /**< Reset node sys_io_div4 */
163 kDtResetSysAon = 13, /**< Reset node sys_aon */
164 kDtResetSpiDevice = 14, /**< Reset node spi_device */
165 kDtResetSpiHost0 = 15, /**< Reset node spi_host0 */
166 kDtResetUsb = 16, /**< Reset node usb */
167 kDtResetCount = 17, /**< \internal Number of resets */
169
170/**
171 * List of pads names.
172 */
173typedef enum dt_pad {
174 kDtPadConstantZero = 0, /**< Pad that is constantly tied to zero (input) */
175 kDtPadConstantOne = 1, /**< Pad that is constantly tied to one (input) */
176 kDtPadIoa0 = 2, /**< Muxed IO pad */
177 kDtPadIoa1 = 3, /**< Muxed IO pad */
178 kDtPadIoa2 = 4, /**< Muxed IO pad */
179 kDtPadIoa3 = 5, /**< Muxed IO pad */
180 kDtPadIoa4 = 6, /**< Muxed IO pad */
181 kDtPadIoa5 = 7, /**< Muxed IO pad */
182 kDtPadIoa6 = 8, /**< Muxed IO pad */
183 kDtPadIoa7 = 9, /**< Muxed IO pad */
184 kDtPadIoa8 = 10, /**< Muxed IO pad */
185 kDtPadIob0 = 11, /**< Muxed IO pad */
186 kDtPadIob1 = 12, /**< Muxed IO pad */
187 kDtPadIob2 = 13, /**< Muxed IO pad */
188 kDtPadIob3 = 14, /**< Muxed IO pad */
189 kDtPadIob4 = 15, /**< Muxed IO pad */
190 kDtPadIob5 = 16, /**< Muxed IO pad */
191 kDtPadIob6 = 17, /**< Muxed IO pad */
192 kDtPadIob7 = 18, /**< Muxed IO pad */
193 kDtPadIob8 = 19, /**< Muxed IO pad */
194 kDtPadIob9 = 20, /**< Muxed IO pad */
195 kDtPadIob10 = 21, /**< Muxed IO pad */
196 kDtPadIob11 = 22, /**< Muxed IO pad */
197 kDtPadIob12 = 23, /**< Muxed IO pad */
198 kDtPadIoc0 = 24, /**< Muxed IO pad */
199 kDtPadIoc1 = 25, /**< Muxed IO pad */
200 kDtPadIoc2 = 26, /**< Muxed IO pad */
201 kDtPadIoc3 = 27, /**< Muxed IO pad */
202 kDtPadIoc4 = 28, /**< Muxed IO pad */
203 kDtPadIoc5 = 29, /**< Muxed IO pad */
204 kDtPadIoc6 = 30, /**< Muxed IO pad */
205 kDtPadIoc7 = 31, /**< Muxed IO pad */
206 kDtPadIoc8 = 32, /**< Muxed IO pad */
207 kDtPadIoc9 = 33, /**< Muxed IO pad */
208 kDtPadIoc10 = 34, /**< Muxed IO pad */
209 kDtPadIoc11 = 35, /**< Muxed IO pad */
210 kDtPadIoc12 = 36, /**< Muxed IO pad */
211 kDtPadIor0 = 37, /**< Muxed IO pad */
212 kDtPadIor1 = 38, /**< Muxed IO pad */
213 kDtPadIor2 = 39, /**< Muxed IO pad */
214 kDtPadIor3 = 40, /**< Muxed IO pad */
215 kDtPadIor4 = 41, /**< Muxed IO pad */
216 kDtPadIor5 = 42, /**< Muxed IO pad */
217 kDtPadIor6 = 43, /**< Muxed IO pad */
218 kDtPadIor7 = 44, /**< Muxed IO pad */
219 kDtPadIor10 = 45, /**< Muxed IO pad */
220 kDtPadIor11 = 46, /**< Muxed IO pad */
221 kDtPadIor12 = 47, /**< Muxed IO pad */
222 kDtPadIor13 = 48, /**< Muxed IO pad */
223 kDtPadSpiHost0Sd0 = 49, /**< SPI host data */
224 kDtPadSpiHost0Sd1 = 50, /**< SPI host data */
225 kDtPadSpiHost0Sd2 = 51, /**< SPI host data */
226 kDtPadSpiHost0Sd3 = 52, /**< SPI host data */
227 kDtPadSpiDeviceSd0 = 53, /**< SPI device data */
228 kDtPadSpiDeviceSd1 = 54, /**< SPI device data */
229 kDtPadSpiDeviceSd2 = 55, /**< SPI device data */
230 kDtPadSpiDeviceSd3 = 56, /**< SPI device data */
231 kDtPadUsbdevUsbDp = 57, /**< */
232 kDtPadUsbdevUsbDn = 58, /**< */
233 kDtPadSpiDeviceSck = 59, /**< SPI device clock */
234 kDtPadSpiDeviceCsb = 60, /**< SPI device chip select */
235 kDtPadSpiHost0Sck = 61, /**< SPI host clock */
236 kDtPadSpiHost0Csb = 62, /**< SPI host chip select */
237 kDtPadCount = 63, /**< \internal Number of pads */
239
240/** Type of peripheral I/O. */
241typedef enum dt_periph_io_type {
242 /** This peripheral I/O is connected to a muxed IO (MIO). */
244 /** This peripheral I/O is connected to a direct IO (DIO). */
246 /** This peripheral I/O is not connected to either a MIO or a DIO. */
249
250
251/** Direction of a peripheral I/O. */
252typedef enum dt_periph_io_dir {
253 /** This peripheral I/O is an input. */
255 /** This peripheral I/O is an output */
257 /** This peripheral I/O is an input-output */
260
261/** Peripheral I/O description.
262 *
263 * A `dt_periph_io_t` represents a HW IP block peripheral I/O, which can be an input, output or both.
264 * Importantly, this only represents how the block peripheral I/O is wired, i.e.
265 * whether it is connected a MIO or a direct IO on the pinmux, and the relevant information necessary to
266 * configure it.
267 *
268 * **Note:** The fields of this structure are internal, use the dt_periph_io_* functions to access them.
269 */
270typedef struct dt_periph_io {
271 struct {
272 dt_periph_io_type_t type; /**< Peripheral I/O type */
273 dt_periph_io_dir_t dir; /**< Peripheral I/O direction */
274 /**
275 * For `kDtPeriphIoTypeMio`: peripheral input number. This is the index of the MIO_PERIPH_INSEL register
276 * that controls this peripheral I/O.
277 *
278 * For `kDtPeriphIoTypeDio`: DIO pad number. This is the index of the various DIO_PAD_* registers
279 * that control this peripheral I/O.
280 */
282 /**
283 * For `kDtPeriphIoTypeMio`: peripheral output number. This is the value to put in the MIO_OUTSEL registers
284 * to connect an output to this peripheral I/O. For `kDtPeriphIoTypeDio`: the pad index (`dt_pad_t`) to which this I/O is connected.
285 */
286 uint16_t outsel_or_dt_pad;
287 } __internal; /**< Private fields */
289
290
291/* Peripheral I/O that is constantly tied to high-Z (output only) */
292extern const dt_periph_io_t kDtPeriphIoConstantHighZ;
293
294/* Peripheral I/O that is constantly tied to one (output only) */
295extern const dt_periph_io_t kDtPeriphIoConstantZero;
296
297/* Peripheral I/O that is constantly tied to zero (output only) */
298extern const dt_periph_io_t kDtPeriphIoConstantOne;
299
300/**
301 * Return the type of a `dt_periph_io_t`.
302 *
303 * @param periph_io A peripheral I/O description.
304 * @return The peripheral I/O type (MIO, DIO, etc).
305 */
307 return periph_io.__internal.type;
308}
309
310/**
311 * Return the direction of a `dt_periph_io_t`.
312 *
313 * @param periph_io A peripheral I/O description.
314 * @return The peripheral I/O direction.
315 */
316static inline dt_periph_io_dir_t dt_periph_io_dir(dt_periph_io_t periph_io) {
317 return periph_io.__internal.dir;
318}
319
320/**
321 * Pinmux types.
322 *
323 * These types are aliases to top-level types for backward compatibility
324 * with existing code.
325 */
327typedef top_englishbreakfast_pinmux_insel_t dt_pinmux_insel_t;
328typedef top_englishbreakfast_pinmux_outsel_t dt_pinmux_outsel_t;
329typedef top_englishbreakfast_pinmux_mio_out_t dt_pinmux_mio_out_t;
330typedef top_englishbreakfast_direct_pads_t dt_pinmux_direct_pad_t;
331typedef top_englishbreakfast_muxed_pads_t dt_pinmux_muxed_pad_t;
332
333/** Tie constantly to zero. */
334static const dt_pinmux_outsel_t kDtPinmuxOutselConstantZero = kTopEnglishbreakfastPinmuxOutselConstantZero;
335
336/** Tie constantly to one. */
337static const dt_pinmux_outsel_t kDtPinmuxOutselConstantOne = kTopEnglishbreakfastPinmuxOutselConstantOne;
338
339/** Tie constantly to high-Z. */
340static const dt_pinmux_outsel_t kDtPinmuxOutselConstantHighZ = kTopEnglishbreakfastPinmuxOutselConstantHighZ;
341
342/**
343 * Return the peripheral input for an MIO peripheral I/O.
344 *
345 * This is the index of the `MIO_PERIPH_INSEL` pinmux register that controls this peripheral I/O.
346 *
347 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
348 * @return The peripheral input number of the MIO that this peripheral I/O is connected to.
349 *
350 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
351 * inputs (`kDtPeriphIoDirIn`). For any other peripheral I/O, the return value is unspecified.
352 */
353static inline dt_pinmux_peripheral_in_t dt_periph_io_mio_periph_input(dt_periph_io_t periph_io) {
354 return (dt_pinmux_peripheral_in_t)periph_io.__internal.periph_input_or_direct_pad;
355}
356
357/**
358 * Return the outsel for an MIO peripheral I/O.
359 *
360 * This is the value to put in the `MIO_OUTSEL` pinmux registers to connect a pad to this peripheral I/O.
361 *
362 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
363 * @return The outsel of the MIO that this peripheral I/O is connected to.
364 *
365 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
366 * outputs (`kDtPeriphIoDirOut`). For any other peripheral I/O, the return value is unspecified.
367 */
368static inline dt_pinmux_outsel_t dt_periph_io_mio_outsel(dt_periph_io_t periph_io) {
369 return (dt_pinmux_outsel_t)periph_io.__internal.outsel_or_dt_pad;
370}
371
372/**
373 * Return the direct pad number of a DIO peripheral I/O.
374 *
375 * This is the index of the various `DIO_PAD_*` pinmux registers that control this peripheral I/O.
376 *
377 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
378 * @return The direct pad number of the DIO that this peripheral I/O is connected to.
379 *
380 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
381 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
382 */
383static inline dt_pinmux_direct_pad_t dt_periph_io_dio_pad_index(dt_periph_io_t periph_io) {
384 return (dt_pinmux_direct_pad_t)periph_io.__internal.periph_input_or_direct_pad;
385}
386
387/**
388 * Return the pad of a DIO peripheral I/O.
389 *
390 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
391 * @return The pad to which this peripheral I/O is connected to.
392 *
393 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
394 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
395 */
396static inline dt_pad_t dt_periph_io_dio_pad(dt_periph_io_t periph_io) {
397 return (dt_pad_t)periph_io.__internal.outsel_or_dt_pad;
398}
399
400/** Type of a pad. */
401typedef enum dt_pad_type {
402 /** This pad is a muxed IO (MIO). */
404 /** This pad is a direct IO (DIO). */
406 /** This pad is not an MIO or a DIO. */
409
410/**
411 * Return the type of a `dt_pad_t`.
412 *
413 * @param pad A pad description.
414 * @return The pad type (MIO, DIO, etc).
415 */
417
418/**
419 * Return the pad out number for an MIO pad.
420 *
421 * This is the index of the `MIO_OUT` registers that control this pad
422 * (or the output part of this pad).
423 *
424 * @param pad A pad of type `kDtPadTypeMio`.
425 * @return The pad out number of the MIO.
426 *
427 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio` which are
428 * either inputs or inouts. For any other pad, the return value is unspecified.
429 */
430dt_pinmux_mio_out_t dt_pad_mio_out(dt_pad_t pad);
431
432/**
433 * Return the pad out number for an MIO pad.
434 *
435 * This is the index of the `MIO_PAD` registers that control this pad
436 * (or the output part of this pad).
437 *
438 * @param pad A pad of type `kDtPadTypeMio`.
439 * @return The pad out number of the MIO.
440 *
441 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
442 * For any other pad, the return value is unspecified.
443 */
444dt_pinmux_muxed_pad_t dt_pad_mio_pad_index(dt_pad_t pad);
445
446/**
447 * Return the insel for an MIO pad.
448 *
449 * This is the value to put in the `MIO_PERIPH_INSEL` registers to connect a peripheral I/O to this pad.
450 *
451 * @param pad A pad of type `kDtPadTypeMio`.
452 * @return The insel of the MIO that this pad is connected to.
453 *
454 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
455 * For any other pad, the return value is unspecified.
456 */
457dt_pinmux_insel_t dt_pad_mio_insel(dt_pad_t pad);
458
459/**
460 * Return the direct pad number of a DIO pad.
461 *
462 * This is the index of the various `DIO_PAD_*` registers that control this pad.
463 *
464 * @param pad A pad of type `kDtPadTypeDio`.
465 * @return The direct pad number of the DID that this pad is connected to.
466 *
467 * **Note:** This function only makes sense for pads of type `kDtPeriphIoTypeDio` which are
468 * either outputs or inouts. For any other pad type, the return value is unspecified.
469 */
470dt_pinmux_direct_pad_t dt_pad_dio_pad_index(dt_pad_t pad);
471
472#ifdef __cplusplus
473} // extern "C"
474#endif // __cplusplus
475
476#endif // OPENTITAN_TOP_ENGLISHBREAKFAST_DT_API_H_