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