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 kDtInstanceIdAonTimer = 2, /**< instance aon_timer of aon_timer */
71 kDtInstanceIdAst = 3, /**< instance ast of ast */
72 kDtInstanceIdClkmgr = 4, /**< instance clkmgr of clkmgr */
73 kDtInstanceIdFlashCtrl = 5, /**< instance flash_ctrl of flash_ctrl */
74 kDtInstanceIdGpio0 = 6, /**< instance gpio0 of gpio */
75 kDtInstanceIdPinmux = 7, /**< instance pinmux of pinmux */
76 kDtInstanceIdPwrmgr = 8, /**< instance pwrmgr of pwrmgr */
77 kDtInstanceIdRomCtrl = 9, /**< instance rom_ctrl of rom_ctrl */
78 kDtInstanceIdRstmgr = 10, /**< instance rstmgr 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 kDtClockIoDiv4 = 4, /**< clock io_div4 */
141
142enum {
143 kDtClockCount = 5, /**< Number of clocks */
144};
145
146
147/**
148 * Get the frequency of a clock.
149 *
150 * @param clk A clock ID.
151 * @return Clock frequency in Hz.
152 */
154
155/**
156 * List of resets.
157 *
158 * Resets are guaranteed to be numbered consecutively from 0.
159 */
160typedef enum dt_reset {
161 kDtResetUnknown = 0, /**< Unknown reset */
162 kDtResetPorAon = 1, /**< Reset node por_aon */
163 kDtResetLcSrc = 2, /**< Reset node lc_src */
164 kDtResetSysSrc = 3, /**< Reset node sys_src */
165 kDtResetPor = 4, /**< Reset node por */
166 kDtResetPorIo = 5, /**< Reset node por_io */
167 kDtResetPorIoDiv4 = 6, /**< Reset node por_io_div4 */
168 kDtResetPorUsb = 7, /**< Reset node por_usb */
169 kDtResetLc = 8, /**< Reset node lc */
170 kDtResetLcIoDiv4 = 9, /**< Reset node lc_io_div4 */
171 kDtResetSys = 10, /**< Reset node sys */
172 kDtResetSysIoDiv4 = 11, /**< Reset node sys_io_div4 */
173 kDtResetSysAon = 12, /**< Reset node sys_aon */
174 kDtResetSpiDevice = 13, /**< Reset node spi_device */
175 kDtResetSpiHost0 = 14, /**< Reset node spi_host0 */
176 kDtResetUsb = 15, /**< Reset node usb */
178
179enum {
180 kDtResetCount = 16, /**< Number of resets */
181};
182
183
184/**
185 * List of pads names.
186 */
187typedef enum dt_pad {
188 kDtPadConstantZero = 0, /**< Pad that is constantly tied to zero (input) */
189 kDtPadConstantOne = 1, /**< Pad that is constantly tied to one (input) */
190 kDtPadIoa0 = 2, /**< Muxed IO pad */
191 kDtPadIoa1 = 3, /**< Muxed IO pad */
192 kDtPadIoa2 = 4, /**< Muxed IO pad */
193 kDtPadIoa3 = 5, /**< Muxed IO pad */
194 kDtPadIoa4 = 6, /**< Muxed IO pad */
195 kDtPadIoa5 = 7, /**< Muxed IO pad */
196 kDtPadIoa6 = 8, /**< Muxed IO pad */
197 kDtPadIoa7 = 9, /**< Muxed IO pad */
198 kDtPadIoa8 = 10, /**< Muxed IO pad */
199 kDtPadIob0 = 11, /**< Muxed IO pad */
200 kDtPadIob1 = 12, /**< Muxed IO pad */
201 kDtPadIob2 = 13, /**< Muxed IO pad */
202 kDtPadIob3 = 14, /**< Muxed IO pad */
203 kDtPadIob4 = 15, /**< Muxed IO pad */
204 kDtPadIob5 = 16, /**< Muxed IO pad */
205 kDtPadIob6 = 17, /**< Muxed IO pad */
206 kDtPadIob7 = 18, /**< Muxed IO pad */
207 kDtPadIob8 = 19, /**< Muxed IO pad */
208 kDtPadIob9 = 20, /**< Muxed IO pad */
209 kDtPadIob10 = 21, /**< Muxed IO pad */
210 kDtPadIob11 = 22, /**< Muxed IO pad */
211 kDtPadIob12 = 23, /**< Muxed IO pad */
212 kDtPadIoc0 = 24, /**< Muxed IO pad */
213 kDtPadIoc1 = 25, /**< Muxed IO pad */
214 kDtPadIoc2 = 26, /**< Muxed IO pad */
215 kDtPadIoc3 = 27, /**< Muxed IO pad */
216 kDtPadIoc4 = 28, /**< Muxed IO pad */
217 kDtPadIoc5 = 29, /**< Muxed IO pad */
218 kDtPadIoc6 = 30, /**< Muxed IO pad */
219 kDtPadIoc7 = 31, /**< Muxed IO pad */
220 kDtPadIoc8 = 32, /**< Muxed IO pad */
221 kDtPadIoc9 = 33, /**< Muxed IO pad */
222 kDtPadIoc10 = 34, /**< Muxed IO pad */
223 kDtPadIoc11 = 35, /**< Muxed IO pad */
224 kDtPadIoc12 = 36, /**< Muxed IO pad */
225 kDtPadIor0 = 37, /**< Muxed IO pad */
226 kDtPadIor1 = 38, /**< Muxed IO pad */
227 kDtPadIor2 = 39, /**< Muxed IO pad */
228 kDtPadIor3 = 40, /**< Muxed IO pad */
229 kDtPadIor4 = 41, /**< Muxed IO pad */
230 kDtPadIor5 = 42, /**< Muxed IO pad */
231 kDtPadIor6 = 43, /**< Muxed IO pad */
232 kDtPadIor7 = 44, /**< Muxed IO pad */
233 kDtPadIor10 = 45, /**< Muxed IO pad */
234 kDtPadIor11 = 46, /**< Muxed IO pad */
235 kDtPadIor12 = 47, /**< Muxed IO pad */
236 kDtPadIor13 = 48, /**< Muxed IO pad */
237 kDtPadSpiHost0Sd0 = 49, /**< SPI host data */
238 kDtPadSpiHost0Sd1 = 50, /**< SPI host data */
239 kDtPadSpiHost0Sd2 = 51, /**< SPI host data */
240 kDtPadSpiHost0Sd3 = 52, /**< SPI host data */
241 kDtPadSpiDeviceSd0 = 53, /**< SPI device data */
242 kDtPadSpiDeviceSd1 = 54, /**< SPI device data */
243 kDtPadSpiDeviceSd2 = 55, /**< SPI device data */
244 kDtPadSpiDeviceSd3 = 56, /**< SPI device data */
245 kDtPadUsbdevUsbDp = 57, /**< */
246 kDtPadUsbdevUsbDn = 58, /**< */
247 kDtPadSpiDeviceSck = 59, /**< SPI device clock */
248 kDtPadSpiDeviceCsb = 60, /**< SPI device chip select */
249 kDtPadSpiHost0Sck = 61, /**< SPI host clock */
250 kDtPadSpiHost0Csb = 62, /**< SPI host chip select */
252
253enum {
254 kDtPadCount = 63, /**< Number of pads */
255};
256
257
258/** Type of peripheral I/O. */
259typedef enum dt_periph_io_type {
260 /** This peripheral I/O is connected to a muxed IO (MIO). */
262 /** This peripheral I/O is connected to a direct IO (DIO). */
264 /** This peripheral I/O is not connected to either a MIO or a DIO. */
267
268
269/** Direction of a peripheral I/O. */
270typedef enum dt_periph_io_dir {
271 /** This peripheral I/O is an input. */
273 /** This peripheral I/O is an output */
275 /** This peripheral I/O is an input-output */
278
279/** Peripheral I/O description.
280 *
281 * A `dt_periph_io_t` represents a HW IP block peripheral I/O, which can be an input, output or both.
282 * Importantly, this only represents how the block peripheral I/O is wired, i.e.
283 * whether it is connected a MIO or a direct IO on the pinmux, and the relevant information necessary to
284 * configure it.
285 *
286 * **Note:** The fields of this structure are internal, use the dt_periph_io_* functions to access them.
287 */
288typedef struct dt_periph_io {
289 struct {
290 dt_periph_io_type_t type; /**< Peripheral I/O type */
291 dt_periph_io_dir_t dir; /**< Peripheral I/O direction */
292 /**
293 * For `kDtPeriphIoTypeMio`: peripheral input number. This is the index of the MIO_PERIPH_INSEL register
294 * that controls this peripheral I/O.
295 *
296 * For `kDtPeriphIoTypeDio`: DIO pad number. This is the index of the various DIO_PAD_* registers
297 * that control this peripheral I/O.
298 */
300 /**
301 * For `kDtPeriphIoTypeMio`: peripheral output number. This is the value to put in the MIO_OUTSEL registers
302 * to connect an output to this peripheral I/O. For `kDtPeriphIoTypeDio`: the pad index (`dt_pad_t`) to which this I/O is connected.
303 */
304 uint16_t outsel_or_dt_pad;
305 } __internal; /**< Private fields */
307
308
309/* Peripheral I/O that is constantly tied to high-Z (output only) */
310extern const dt_periph_io_t kDtPeriphIoConstantHighZ;
311
312/* Peripheral I/O that is constantly tied to one (output only) */
313extern const dt_periph_io_t kDtPeriphIoConstantZero;
314
315/* Peripheral I/O that is constantly tied to zero (output only) */
316extern const dt_periph_io_t kDtPeriphIoConstantOne;
317
318/**
319 * Return the type of a `dt_periph_io_t`.
320 *
321 * @param periph_io A peripheral I/O description.
322 * @return The peripheral I/O type (MIO, DIO, etc).
323 */
325 return periph_io.__internal.type;
326}
327
328/**
329 * Return the direction of a `dt_periph_io_t`.
330 *
331 * @param periph_io A peripheral I/O description.
332 * @return The peripheral I/O direction.
333 */
334static inline dt_periph_io_dir_t dt_periph_io_dir(dt_periph_io_t periph_io) {
335 return periph_io.__internal.dir;
336}
337
338/**
339 * Pinmux types.
340 *
341 * These types are aliases to top-level types for backward compatibility
342 * with existing code.
343 */
345typedef top_englishbreakfast_pinmux_insel_t dt_pinmux_insel_t;
346typedef top_englishbreakfast_pinmux_outsel_t dt_pinmux_outsel_t;
347typedef top_englishbreakfast_pinmux_mio_out_t dt_pinmux_mio_out_t;
348typedef top_englishbreakfast_direct_pads_t dt_pinmux_direct_pad_t;
349typedef top_englishbreakfast_muxed_pads_t dt_pinmux_muxed_pad_t;
350
351/** Tie constantly to zero. */
352static const dt_pinmux_outsel_t kDtPinmuxOutselConstantZero = kTopEnglishbreakfastPinmuxOutselConstantZero;
353
354/** Tie constantly to one. */
355static const dt_pinmux_outsel_t kDtPinmuxOutselConstantOne = kTopEnglishbreakfastPinmuxOutselConstantOne;
356
357/** Tie constantly to high-Z. */
358static const dt_pinmux_outsel_t kDtPinmuxOutselConstantHighZ = kTopEnglishbreakfastPinmuxOutselConstantHighZ;
359
360/**
361 * Return the peripheral input for an MIO peripheral I/O.
362 *
363 * This is the index of the `MIO_PERIPH_INSEL` pinmux register that controls this peripheral I/O.
364 *
365 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
366 * @return The peripheral input number of the MIO that this peripheral I/O is connected to.
367 *
368 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
369 * inputs (`kDtPeriphIoDirIn`). For any other peripheral I/O, the return value is unspecified.
370 */
371static inline dt_pinmux_peripheral_in_t dt_periph_io_mio_periph_input(dt_periph_io_t periph_io) {
372 return (dt_pinmux_peripheral_in_t)periph_io.__internal.periph_input_or_direct_pad;
373}
374
375/**
376 * Return the outsel for an MIO peripheral I/O.
377 *
378 * This is the value to put in the `MIO_OUTSEL` pinmux registers to connect a pad to this peripheral I/O.
379 *
380 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeMio`.
381 * @return The outsel of the MIO that this peripheral I/O is connected to.
382 *
383 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeMio` which are
384 * outputs (`kDtPeriphIoDirOut`). For any other peripheral I/O, the return value is unspecified.
385 */
386static inline dt_pinmux_outsel_t dt_periph_io_mio_outsel(dt_periph_io_t periph_io) {
387 return (dt_pinmux_outsel_t)periph_io.__internal.outsel_or_dt_pad;
388}
389
390/**
391 * Return the direct pad number of a DIO peripheral I/O.
392 *
393 * This is the index of the various `DIO_PAD_*` pinmux registers that control this peripheral I/O.
394 *
395 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
396 * @return The direct pad number of the DIO that this peripheral I/O is connected to.
397 *
398 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
399 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
400 */
401static inline dt_pinmux_direct_pad_t dt_periph_io_dio_pad_index(dt_periph_io_t periph_io) {
402 return (dt_pinmux_direct_pad_t)periph_io.__internal.periph_input_or_direct_pad;
403}
404
405/**
406 * Return the pad of a DIO peripheral I/O.
407 *
408 * @param periph_io A peripheral I/O of type `kDtPeriphIoTypeDio`.
409 * @return The pad to which this peripheral I/O is connected to.
410 *
411 * **Note:** This function only makes sense for peripheral I/Os of type `kDtPeriphIoTypeDio` which are
412 * either outputs or inouts. For any other peripheral I/O type, the return value is unspecified.
413 */
414static inline dt_pad_t dt_periph_io_dio_pad(dt_periph_io_t periph_io) {
415 return (dt_pad_t)periph_io.__internal.outsel_or_dt_pad;
416}
417
418/** Type of a pad. */
419typedef enum dt_pad_type {
420 /** This pad is a muxed IO (MIO). */
422 /** This pad is a direct IO (DIO). */
424 /** This pad is not an MIO or a DIO. */
427
428/**
429 * Return the type of a `dt_pad_t`.
430 *
431 * @param pad A pad description.
432 * @return The pad type (MIO, DIO, etc).
433 */
435
436/**
437 * Return the pad out number for an MIO pad.
438 *
439 * This is the index of the `MIO_OUT` registers that control this pad
440 * (or the output part of this pad).
441 *
442 * @param pad A pad of type `kDtPadTypeMio`.
443 * @return The pad out number of the MIO.
444 *
445 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio` which are
446 * either inputs or inouts. For any other pad, the return value is unspecified.
447 */
448dt_pinmux_mio_out_t dt_pad_mio_out(dt_pad_t pad);
449
450/**
451 * Return the pad out number for an MIO pad.
452 *
453 * This is the index of the `MIO_PAD` registers that control this pad
454 * (or the output part of this pad).
455 *
456 * @param pad A pad of type `kDtPadTypeMio`.
457 * @return The pad out number of the MIO.
458 *
459 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
460 * For any other pad, the return value is unspecified.
461 */
462dt_pinmux_muxed_pad_t dt_pad_mio_pad_index(dt_pad_t pad);
463
464/**
465 * Return the insel for an MIO pad.
466 *
467 * This is the value to put in the `MIO_PERIPH_INSEL` registers to connect a peripheral I/O to this pad.
468 *
469 * @param pad A pad of type `kDtPadTypeMio`.
470 * @return The insel of the MIO that this pad is connected to.
471 *
472 * **Note:** This function only makes sense for pads of type `kDtPadTypeMio`.
473 * For any other pad, the return value is unspecified.
474 */
475dt_pinmux_insel_t dt_pad_mio_insel(dt_pad_t pad);
476
477/**
478 * Return the direct pad number of a DIO pad.
479 *
480 * This is the index of the various `DIO_PAD_*` registers that control this pad.
481 *
482 * @param pad A pad of type `kDtPadTypeDio`.
483 * @return The direct pad number of the DID that this pad is connected to.
484 *
485 * **Note:** This function only makes sense for pads of type `kDtPeriphIoTypeDio` which are
486 * either outputs or inouts. For any other pad type, the return value is unspecified.
487 */
488dt_pinmux_direct_pad_t dt_pad_dio_pad_index(dt_pad_t pad);
489
490#ifdef __cplusplus
491} // extern "C"
492#endif // __cplusplus
493
494#endif // OPENTITAN_TOP_ENGLISHBREAKFAST_DT_API_H_