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