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