Software APIs
dt_usbdev.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_DT_USBDEV_H_
8#define OPENTITAN_DT_USBDEV_H_
9
10/**
11 * @file
12 * @brief Device Tables (DT) for IP usbdev and top earlgrey.
13 *
14 * This file contains the type definitions and global functions of the usbdev.
15 */
16
17#include "dt_api.h"
18#include <stdint.h>
19
20/**
21 * List of instances.
22 */
23typedef enum dt_usbdev {
24 kDtUsbdev = 0, /**< usbdev */
25 kDtUsbdevFirst = 0, /**< \internal First instance */
26 kDtUsbdevCount = 1, /**< \internal Number of instances */
28
29/**
30 * List of register blocks.
31 *
32 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
33 */
34typedef enum dt_usbdev_reg_block {
35 kDtUsbdevRegBlockCore = 0, /**< */
36 kDtUsbdevRegBlockCount = 1, /**< \internal Number of register blocks */
38
39/** Primary register block (associated with the "primary" set of registers that control the IP). */
40static const dt_usbdev_reg_block_t kDtUsbdevRegBlockPrimary = kDtUsbdevRegBlockCore;
41
42/**
43 * List of IRQs.
44 *
45 * IRQs are guaranteed to be numbered consecutively from 0.
46 */
47typedef enum dt_usbdev_irq {
48 kDtUsbdevIrqPktReceived = 0, /**< Raised if a packet was received using an OUT or SETUP transaction.
49This interrupt is directly tied to whether the RX FIFO is empty, so it should be cleared only after handling the FIFO entry. */
50 kDtUsbdevIrqPktSent = 1, /**< Raised if a packet was sent as part of an IN transaction.
51This interrupt is directly tied to whether a sent packet has not been acknowledged in the !!in_sent register.
52It should be cleared only after clearing all bits in the !!in_sent register. */
53 kDtUsbdevIrqDisconnected = 2, /**< Raised if VBUS is lost, thus the link is disconnected. */
54 kDtUsbdevIrqHostLost = 3, /**< Raised if link is active but SOF was not received from host for 4.096 ms. The SOF should be every 1 ms. */
55 kDtUsbdevIrqLinkReset = 4, /**< Raised if the link is at SE0 longer than 3 us indicating a link reset (host asserts for min 10 ms, device can react after 2.5 us). */
56 kDtUsbdevIrqLinkSuspend = 5, /**< Raised if the line has signaled J for longer than 3ms and is therefore in suspend state. */
57 kDtUsbdevIrqLinkResume = 6, /**< Raised when the link becomes active again after being suspended. */
58 kDtUsbdevIrqAvOutEmpty = 7, /**< Raised when the Available OUT Buffer FIFO is empty and the device interface is enabled.
59This interrupt is directly tied to the FIFO status, so the Available OUT Buffer FIFO must be provided with a free buffer before the interrupt can be cleared. */
60 kDtUsbdevIrqRxFull = 8, /**< Raised when the RX FIFO is full and the device interface is enabled.
61This interrupt is directly tied to the FIFO status, so the RX FIFO must have an entry removed before the interrupt is cleared.
62If the condition is not cleared, the interrupt can re-assert. */
63 kDtUsbdevIrqAvOverflow = 9, /**< Raised if a write was done to either the Available OUT Buffer FIFO or the Available SETUP Buffer FIFO when the FIFO was full. */
64 kDtUsbdevIrqLinkInErr = 10, /**< Raised if a packet to an IN endpoint started to be received but was
65then dropped due to an error. After transmitting the IN payload,
66the USB device expects a valid ACK handshake packet. This error is
67raised if either the packet or CRC is invalid, leading to a NAK instead,
68or if a different token was received. */
69 kDtUsbdevIrqRxCrcErr = 11, /**< Raised if a CRC error occurred on a received packet. */
70 kDtUsbdevIrqRxPidErr = 12, /**< Raised if an invalid Packet IDentifier (PID) was received. */
71 kDtUsbdevIrqRxBitstuffErr = 13, /**< Raised if an invalid bitstuffing was received. */
72 kDtUsbdevIrqFrame = 14, /**< Raised when the USB frame number is updated with a valid SOF. */
73 kDtUsbdevIrqPowered = 15, /**< Raised if VBUS is applied. */
74 kDtUsbdevIrqLinkOutErr = 16, /**< Raised if a packet to an OUT endpoint started to be received but was then dropped due to an error.
75This error is raised if the data toggle, token, packet and/or CRC are invalid, or if the appropriate Available OUT Buffer FIFO is empty and/or the Received Buffer FIFO is full when a packet should have been received. */
76 kDtUsbdevIrqAvSetupEmpty = 17, /**< Raised when the Available SETUP Buffer FIFO is empty and the device interface is enabled.
77This interrupt is directly tied to the FIFO status, so the Available SETUP Buffer FIFO must be provided with a free buffer before the interrupt can be cleared. */
78 kDtUsbdevIrqCount = 18, /**< \internal Number of IRQs */
80
81/**
82 * List of Alerts.
83 *
84 * Alerts are guaranteed to be numbered consecutively from 0.
85 */
86typedef enum dt_usbdev_alert {
87 kDtUsbdevAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
88 kDtUsbdevAlertCount = 1, /**< \internal Number of Alerts */
90
91/**
92 * List of clock ports.
93 *
94 * Clock ports are guaranteed to be numbered consecutively from 0.
95 */
96typedef enum dt_usbdev_clock {
97 kDtUsbdevClockClk = 0, /**< Clock port clk_i */
98 kDtUsbdevClockAon = 1, /**< Clock port clk_aon_i */
99 kDtUsbdevClockCount = 2, /**< \internal Number of clock ports */
101
102/**
103 * List of reset ports.
104 *
105 * Reset ports are guaranteed to be numbered consecutively from 0.
106 */
107typedef enum dt_usbdev_reset {
108 kDtUsbdevResetRst = 0, /**< Reset port rst_ni */
109 kDtUsbdevResetAon = 1, /**< Reset port rst_aon_ni */
110 kDtUsbdevResetCount = 2, /**< \internal Number of reset ports */
112
113/**
114 * List of peripheral I/O.
115 *
116 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
117 */
119 kDtUsbdevPeriphIoSense = 0, /**< */
120 kDtUsbdevPeriphIoUsbDp = 1, /**< */
121 kDtUsbdevPeriphIoUsbDn = 2, /**< */
122 kDtUsbdevPeriphIoCount = 3, /**< \internal Number of peripheral I/O */
124
125/**
126 * List of supported hardware features.
127 */
128#define OPENTITAN_USBDEV_HAS_CONN_VBUS 1
129#define OPENTITAN_USBDEV_HAS_CONN_PULLUP 1
130#define OPENTITAN_USBDEV_HAS_CONN_REF_PULSE 1
131#define OPENTITAN_USBDEV_HAS_CONN_PIN_CONFIG 1
132#define OPENTITAN_USBDEV_HAS_CONN_RESET 1
133#define OPENTITAN_USBDEV_HAS_BUFFER_MEMORY 1
134#define OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL_RX 1
135#define OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL_TX 1
136#define OPENTITAN_USBDEV_HAS_TRANSFER_ENDPOINTS 1
137#define OPENTITAN_USBDEV_HAS_TRANSFER_BULK 1
138#define OPENTITAN_USBDEV_HAS_TRANSFER_ISOCHRONOUS 1
139#define OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL 1
140#define OPENTITAN_USBDEV_HAS_TRANSFER_INTERRUPT 1
141#define OPENTITAN_USBDEV_HAS_POWER_SUSPEND 1
142#define OPENTITAN_USBDEV_HAS_POWER_RESUME 1
143#define OPENTITAN_USBDEV_HAS_POWER_AON 1
144#define OPENTITAN_USBDEV_HAS_POWER_WAKE_DISCONNECT 1
145#define OPENTITAN_USBDEV_HAS_POWER_WAKE_RESUME 1
146#define OPENTITAN_USBDEV_HAS_POWER_WAKE_BUS_RESET 1
147#define OPENTITAN_USBDEV_HAS_POWER_TOGGLE_RESTORE 1
148
149
150
151/**
152 * Get the usbdev instance from an instance ID
153 *
154 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
155 *
156 * @param inst_id Instance ID.
157 * @return A usbdev instance.
158 *
159 * **Note:** This function only makes sense if the instance ID has device type usbdev,
160 * otherwise the returned value is unspecified.
161 */
163
164/**
165 * Get the instance ID of an instance.
166 *
167 * @param dt Instance of usbdev.
168 * @return The instance ID of that instance.
169 */
171
172/**
173 * Get the register base address of an instance.
174 *
175 * @param dt Instance of usbdev.
176 * @param reg_block The register block requested.
177 * @return The register base address of the requested block.
178 */
179uint32_t dt_usbdev_reg_block(
180 dt_usbdev_t dt,
181 dt_usbdev_reg_block_t reg_block);
182
183/**
184 * Get the primary register base address of an instance.
185 *
186 * This is just a convenience function, equivalent to
187 * `dt_usbdev_reg_block(dt, kDtUsbdevRegBlockCore)`
188 *
189 * @param dt Instance of usbdev.
190 * @return The register base address of the primary register block.
191 */
192static inline uint32_t dt_usbdev_primary_reg_block(
193 dt_usbdev_t dt) {
194 return dt_usbdev_reg_block(dt, kDtUsbdevRegBlockCore);
195}
196
197/**
198 * Get the PLIC ID of a usbdev IRQ for a given instance.
199 *
200 * If the instance is not connected to the PLIC, this function
201 * will return `kDtPlicIrqIdNone`.
202 *
203 * @param dt Instance of usbdev.
204 * @param irq A usbdev IRQ.
205 * @return The PLIC ID of the IRQ of this instance.
206 */
208 dt_usbdev_t dt,
209 dt_usbdev_irq_t irq);
210
211/**
212 * Convert a global IRQ ID to a local usbdev IRQ type.
213 *
214 * @param dt Instance of usbdev.
215 * @param irq A PLIC ID that belongs to this instance.
216 * @return The usbdev IRQ, or `kDtUsbdevIrqCount`.
217 *
218 * **Note:** This function assumes that the PLIC ID belongs to the instance
219 * of usbdev passed in parameter. In other words, it must be the case that
220 * `dt_usbdev_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
221 * will return `kDtUsbdevIrqCount`.
222 */
224 dt_usbdev_t dt,
225 dt_plic_irq_id_t irq);
226
227
228/**
229 * Get the alert ID of a usbdev alert for a given instance.
230 *
231 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
232 * instances where the instance is not connected, the return value is unspecified.
233 *
234 * @param dt Instance of usbdev.
235 * @param alert A usbdev alert.
236 * @return The Alert Handler alert ID of the alert of this instance.
237 */
239 dt_usbdev_t dt,
240 dt_usbdev_alert_t alert);
241
242/**
243 * Convert a global alert ID to a local usbdev alert type.
244 *
245 * @param dt Instance of usbdev.
246 * @param alert A global alert ID that belongs to this instance.
247 * @return The usbdev alert, or `kDtUsbdevAlertCount`.
248 *
249 * **Note:** This function assumes that the global alert ID belongs to the
250 * instance of usbdev passed in parameter. In other words, it must be the case
251 * that `dt_usbdev_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
252 * this function will return `kDtUsbdevAlertCount`.
253 */
255 dt_usbdev_t dt,
256 dt_alert_id_t alert);
257
258
259/**
260 * Get the peripheral I/O description of an instance.
261 *
262 * @param dt Instance of usbdev.
263 * @param sig Requested peripheral I/O.
264 * @return Description of the requested peripheral I/O for this instance.
265 */
267 dt_usbdev_t dt,
269
270/**
271 * Get the clock signal connected to a clock port of an instance.
272 *
273 * @param dt Instance of usbdev.
274 * @param clk Clock port.
275 * @return Clock signal.
276 */
278 dt_usbdev_t dt,
280
281/**
282 * Get the reset signal connected to a reset port of an instance.
283 *
284 * @param dt Instance of usbdev.
285 * @param rst Reset port.
286 * @return Reset signal.
287 */
289 dt_usbdev_t dt,
291
292
293
294#endif // OPENTITAN_DT_USBDEV_H_