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