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