Software APIs
dt_spi_device.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_SPI_DEVICE_H_
8#define OPENTITAN_DT_SPI_DEVICE_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP spi_device and top darjeeling.
17 *
18 * This file contains the type definitions and global functions of the spi_device.
19 */
20
21#include "dt_api.h"
22#include <stdint.h>
23
24
25
26/**
27 * List of instances.
28 */
29typedef enum dt_spi_device {
30 kDtSpiDevice = 0, /**< spi_device */
31 kDtSpiDeviceFirst = 0, /**< \internal First instance */
32 kDtSpiDeviceCount = 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 */
41 kDtSpiDeviceRegBlockCore = 0, /**< */
42 kDtSpiDeviceRegBlockCount = 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_spi_device_reg_block_t kDtSpiDeviceRegBlockPrimary = kDtSpiDeviceRegBlockCore;
47
48/**
49 * List of IRQs.
50 *
51 * IRQs are guaranteed to be numbered consecutively from 0.
52 */
53typedef enum dt_spi_device_irq {
54 kDtSpiDeviceIrqUploadCmdfifoNotEmpty = 0, /**< Upload Command FIFO is not empty */
55 kDtSpiDeviceIrqUploadPayloadNotEmpty = 1, /**< Upload payload is not empty.
56
57The event occurs after SPI transaction completed */
58 kDtSpiDeviceIrqUploadPayloadOverflow = 2, /**< Upload payload overflow event.
59
60When a SPI Host system issues a command with payload more than 256B,
61this event is reported. When it happens, SW should read the last
62written payload index CSR to figure out the starting address of the
63last 256B. */
64 kDtSpiDeviceIrqReadbufWatermark = 3, /**< Read Buffer Threshold event.
65
66The host system accesses greater than or equal to the threshold of a
67buffer. */
68 kDtSpiDeviceIrqReadbufFlip = 4, /**< Read buffer flipped event.
69
70The host system accesses other side of buffer. */
71 kDtSpiDeviceIrqTpmHeaderNotEmpty = 5, /**< TPM Header(Command/Address) buffer available */
72 kDtSpiDeviceIrqTpmRdfifoCmdEnd = 6, /**< TPM RdFIFO command ended.
73
74The TPM Read command targeting the RdFIFO ended.
75Check TPM_STATUS.rdfifo_aborted to see if the transaction completed. */
76 kDtSpiDeviceIrqTpmRdfifoDrop = 7, /**< TPM RdFIFO data dropped.
77
78Data was dropped from the RdFIFO.
79Data was written while a read command was not active, and it was not accepted.
80This can occur when the host aborts a read command. */
81 kDtSpiDeviceIrqCount = 8, /**< \internal Number of IRQs */
83
84/**
85 * List of Alerts.
86 *
87 * Alerts are guaranteed to be numbered consecutively from 0.
88 */
89typedef enum dt_spi_device_alert {
90 kDtSpiDeviceAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
91 kDtSpiDeviceAlertCount = 1, /**< \internal Number of Alerts */
93
94/**
95 * List of clock ports.
96 *
97 * Clock ports are guaranteed to be numbered consecutively from 0.
98 */
99typedef enum dt_spi_device_clock {
100 kDtSpiDeviceClockClk = 0, /**< Clock port clk_i */
101 kDtSpiDeviceClockCount = 1, /**< \internal Number of clock ports */
103
104/**
105 * List of reset ports.
106 *
107 * Reset ports are guaranteed to be numbered consecutively from 0.
108 */
110 kDtSpiDeviceResetRst = 0, /**< Reset port rst_ni */
111 kDtSpiDeviceResetCount = 1, /**< \internal Number of reset ports */
113
114/**
115 * List of peripheral I/O.
116 *
117 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
118 */
120 kDtSpiDevicePeriphIoSck = 0, /**< */
121 kDtSpiDevicePeriphIoCsb = 1, /**< */
122 kDtSpiDevicePeriphIoTpmCsb = 2, /**< */
123 kDtSpiDevicePeriphIoSd0 = 3, /**< */
124 kDtSpiDevicePeriphIoSd1 = 4, /**< */
125 kDtSpiDevicePeriphIoSd2 = 5, /**< */
126 kDtSpiDevicePeriphIoSd3 = 6, /**< */
127 kDtSpiDevicePeriphIoCount = 7, /**< \internal Number of peripheral I/O */
129
130/**
131 * List of supported hardware features.
132 */
133#define OPENTITAN_SPI_DEVICE_HAS_MODE_FLASH_EMULATION 1
134#define OPENTITAN_SPI_DEVICE_HAS_MODE_PASSTHROUGH 1
135#define OPENTITAN_SPI_DEVICE_HAS_MODE_TPM 1
136#define OPENTITAN_SPI_DEVICE_HAS_HW_LANES 1
137#define OPENTITAN_SPI_DEVICE_HAS_HW_SERDES_ORDERING 1
138#define OPENTITAN_SPI_DEVICE_HAS_HW_CSB_STATUS 1
139#define OPENTITAN_SPI_DEVICE_HAS_MODE_FLASH_EMULATION_COMMANDS 1
140#define OPENTITAN_SPI_DEVICE_HAS_HW_FLASH_EMULATION_BLOCKS 1
141#define OPENTITAN_SPI_DEVICE_HAS_MODE_FLASH_EMULATION_READ_COMMAND_PROCESSOR 1
142#define OPENTITAN_SPI_DEVICE_HAS_MODE_FLASH_EMULATION_DUMMY_CYCLE 1
143#define OPENTITAN_SPI_DEVICE_HAS_MODE_FLASH_EMULATION_WRITE_ENABLE_DISABLE 1
144#define OPENTITAN_SPI_DEVICE_HAS_HW_LAST_READ_ADDR 1
145#define OPENTITAN_SPI_DEVICE_HAS_HW_CMDINFOS 1
146#define OPENTITAN_SPI_DEVICE_HAS_HW_COMMAND_UPLOAD 1
147#define OPENTITAN_SPI_DEVICE_HAS_HW_3B4B_ADDRESSING 1
148#define OPENTITAN_SPI_DEVICE_HAS_MODE_PASSTHROUGH_CMD_FILTER 1
149#define OPENTITAN_SPI_DEVICE_HAS_MODE_PASSTHROUGH_ADDRESS_MANIPULATION 1
150#define OPENTITAN_SPI_DEVICE_HAS_MODE_PASSTHROUGH_STATUS_MANIPULATION 1
151#define OPENTITAN_SPI_DEVICE_HAS_MODE_PASSTHROUGH_OUTPUT_ENABLE_CONTROL 1
152#define OPENTITAN_SPI_DEVICE_HAS_MODE_PASSTHROUGH_INTERCEPT_EN 1
153#define OPENTITAN_SPI_DEVICE_HAS_MODE_PASSTHROUGH_MAILBOX 1
154#define OPENTITAN_SPI_DEVICE_HAS_MODE_TPM_RETURN_BY_HW_REGS 1
155#define OPENTITAN_SPI_DEVICE_HAS_MODE_TPM_AUTO_WAIT 1
156#define OPENTITAN_SPI_DEVICE_HAS_MODE_TPM_READ_FIFO_MODE 1
157#define OPENTITAN_SPI_DEVICE_HAS_MODE_TPM_CAPABILITY 1
158
159
160
161/**
162 * Get the spi_device instance from an instance ID
163 *
164 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
165 *
166 * @param inst_id Instance ID.
167 * @return A spi_device instance.
168 *
169 * **Note:** This function only makes sense if the instance ID has device type spi_device,
170 * otherwise the returned value is unspecified.
171 */
173
174/**
175 * Get the instance ID of an instance.
176 *
177 * @param dt Instance of spi_device.
178 * @return The instance ID of that instance.
179 */
181
182/**
183 * Get the register base address of an instance.
184 *
185 * @param dt Instance of spi_device.
186 * @param reg_block The register block requested.
187 * @return The register base address of the requested block.
188 */
191 dt_spi_device_reg_block_t reg_block);
192
193/**
194 * Get the primary register base address of an instance.
195 *
196 * This is just a convenience function, equivalent to
197 * `dt_spi_device_reg_block(dt, kDtSpiDeviceRegBlockCore)`
198 *
199 * @param dt Instance of spi_device.
200 * @return The register base address of the primary register block.
201 */
202static inline uint32_t dt_spi_device_primary_reg_block(
203 dt_spi_device_t dt) {
204 return dt_spi_device_reg_block(dt, kDtSpiDeviceRegBlockCore);
205}
206
207/**
208 * Get the PLIC ID of a spi_device IRQ for a given instance.
209 *
210 * If the instance is not connected to the PLIC, this function
211 * will return `kDtPlicIrqIdNone`.
212 *
213 * @param dt Instance of spi_device.
214 * @param irq A spi_device IRQ.
215 * @return The PLIC ID of the IRQ of this instance.
216 */
220
221/**
222 * Convert a global IRQ ID to a local spi_device IRQ type.
223 *
224 * @param dt Instance of spi_device.
225 * @param irq A PLIC ID that belongs to this instance.
226 * @return The spi_device IRQ, or `kDtSpiDeviceIrqCount`.
227 *
228 * **Note:** This function assumes that the PLIC ID belongs to the instance
229 * of spi_device passed in parameter. In other words, it must be the case that
230 * `dt_spi_device_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
231 * will return `kDtSpiDeviceIrqCount`.
232 */
235 dt_plic_irq_id_t irq);
236
237
238/**
239 * Get the alert ID of a spi_device alert for a given instance.
240 *
241 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
242 * instances where the instance is not connected, the return value is unspecified.
243 *
244 * @param dt Instance of spi_device.
245 * @param alert A spi_device alert.
246 * @return The Alert Handler alert ID of the alert of this instance.
247 */
251
252/**
253 * Convert a global alert ID to a local spi_device alert type.
254 *
255 * @param dt Instance of spi_device.
256 * @param alert A global alert ID that belongs to this instance.
257 * @return The spi_device alert, or `kDtSpiDeviceAlertCount`.
258 *
259 * **Note:** This function assumes that the global alert ID belongs to the
260 * instance of spi_device passed in parameter. In other words, it must be the case
261 * that `dt_spi_device_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
262 * this function will return `kDtSpiDeviceAlertCount`.
263 */
266 dt_alert_id_t alert);
267
268
269/**
270 * Get the peripheral I/O description of an instance.
271 *
272 * @param dt Instance of spi_device.
273 * @param sig Requested peripheral I/O.
274 * @return Description of the requested peripheral I/O for this instance.
275 */
279
280/**
281 * Get the clock signal connected to a clock port of an instance.
282 *
283 * @param dt Instance of spi_device.
284 * @param clk Clock port.
285 * @return Clock signal.
286 */
290
291/**
292 * Get the reset signal connected to a reset port of an instance.
293 *
294 * @param dt Instance of spi_device.
295 * @param rst Reset port.
296 * @return Reset signal.
297 */
301
302
303
304#ifdef __cplusplus
305} // extern "C"
306#endif // __cplusplus
307
308#endif // OPENTITAN_DT_SPI_DEVICE_H_