Software APIs
spi_host.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_HOST_H_
8#define OPENTITAN_DT_SPI_HOST_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP spi_host and top earlgrey.
17 *
18 * This file contains the type definitions and global functions of the spi_host.
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_spi_host {
30 kDtSpiHostFirst = 0, /**< First instance */
31 kDtSpiHost0 = 0, /**< spi_host0 */
32 kDtSpiHost1 = 1, /**< spi_host1 */
34
35enum {
36 kDtSpiHostCount = 2, /**< Number of instances */
37};
38
39
40/**
41 * List of register blocks.
42 *
43 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
44 */
46 kDtSpiHostRegBlockCore = 0, /**< */
48
49enum {
50 kDtSpiHostRegBlockCount = 1, /**< Number of register blocks */
51};
52
53
54/** Primary register block (associated with the "primary" set of registers that control the IP). */
55static const dt_spi_host_reg_block_t kDtSpiHostRegBlockPrimary = kDtSpiHostRegBlockCore;
56
57/**
58 * List of IRQs.
59 *
60 * IRQs are guaranteed to be numbered consecutively from 0.
61 */
62typedef enum dt_spi_host_irq {
63 kDtSpiHostIrqError = 0, /**< Error-related interrupts, see !!ERROR_ENABLE register for more
64 information. */
65 kDtSpiHostIrqSpiEvent = 1, /**< Event-related interrupts, see !!EVENT_ENABLE register for more
66 information. */
68
69enum {
70 kDtSpiHostIrqCount = 2, /**< Number of IRQs */
71};
72
73
74/**
75 * List of Alerts.
76 *
77 * Alerts are guaranteed to be numbered consecutively from 0.
78 */
79typedef enum dt_spi_host_alert {
80 kDtSpiHostAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
82
83enum {
84 kDtSpiHostAlertCount = 1, /**< Number of Alerts */
85};
86
87
88/**
89 * List of clock ports.
90 *
91 * Clock ports are guaranteed to be numbered consecutively from 0.
92 */
93typedef enum dt_spi_host_clock {
94 kDtSpiHostClockClk = 0, /**< Clock port clk_i */
96
97enum {
98 kDtSpiHostClockCount = 1, /**< Number of clock ports */
99};
100
101
102/**
103 * List of reset ports.
104 *
105 * Reset ports are guaranteed to be numbered consecutively from 0.
106 */
107typedef enum dt_spi_host_reset {
108 kDtSpiHostResetRst = 0, /**< Reset port rst_ni */
110
111enum {
112 kDtSpiHostResetCount = 1, /**< Number of reset ports */
113};
114
115
116/**
117 * List of peripheral I/O.
118 *
119 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
120 */
122 kDtSpiHostPeriphIoSck = 0, /**< */
123 kDtSpiHostPeriphIoCsb = 1, /**< */
124 kDtSpiHostPeriphIoSd0 = 2, /**< */
125 kDtSpiHostPeriphIoSd1 = 3, /**< */
126 kDtSpiHostPeriphIoSd2 = 4, /**< */
127 kDtSpiHostPeriphIoSd3 = 5, /**< */
129
130enum {
131 kDtSpiHostPeriphIoCount = 6, /**< Number of peripheral I/O */
132};
133
134
135/**
136 * List of supported hardware features.
137 */
138#define OPENTITAN_SPI_HOST_HAS_USECASE_SERIALNORFLASH 1
139#define OPENTITAN_SPI_HOST_HAS_USECASE_PASSTHROUGH 1
140#define OPENTITAN_SPI_HOST_HAS_RATE_STANDARD 1
141#define OPENTITAN_SPI_HOST_HAS_RATE_DUAL 1
142#define OPENTITAN_SPI_HOST_HAS_RATE_QUAD 1
143#define OPENTITAN_SPI_HOST_HAS_CONFIG_CPOL 1
144#define OPENTITAN_SPI_HOST_HAS_CONFIG_CLOCKDIV 1
145#define OPENTITAN_SPI_HOST_HAS_EVENT_WATERMARK 1
146#define OPENTITAN_SPI_HOST_HAS_EVENT_FULL 1
147#define OPENTITAN_SPI_HOST_HAS_EVENT_EMPTY 1
148
149
150
151/**
152 * Get the spi_host 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 spi_host instance.
158 *
159 * **Note:** This function only makes sense if the instance ID has device type spi_host,
160 * otherwise the returned value is unspecified.
161 */
163
164/**
165 * Get the instance ID of an instance.
166 *
167 * @param dt Instance of spi_host.
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 spi_host.
176 * @param reg_block The register block requested.
177 * @return The register base address of the requested block.
178 */
179uint32_t dt_spi_host_reg_block(
180 dt_spi_host_t dt,
181 dt_spi_host_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_spi_host_reg_block(dt, kDtSpiHostRegBlockCore)`
188 *
189 * @param dt Instance of spi_host.
190 * @return The register base address of the primary register block.
191 */
192static inline uint32_t dt_spi_host_primary_reg_block(
193 dt_spi_host_t dt) {
194 return dt_spi_host_reg_block(dt, kDtSpiHostRegBlockCore);
195}
196
197/**
198 * Get the PLIC ID of a spi_host 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 spi_host.
204 * @param irq A spi_host IRQ.
205 * @return The PLIC ID of the IRQ of this instance.
206 */
208 dt_spi_host_t dt,
210
211/**
212 * Convert a global IRQ ID to a local spi_host IRQ type.
213 *
214 * @param dt Instance of spi_host.
215 * @param irq A PLIC ID that belongs to this instance.
216 * @return The spi_host IRQ, or `kDtSpiHostIrqCount`.
217 *
218 * **Note:** This function assumes that the PLIC ID belongs to the instance
219 * of spi_host passed in parameter. In other words, it must be the case that
220 * `dt_spi_host_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
221 * will return `kDtSpiHostIrqCount`.
222 */
224 dt_spi_host_t dt,
225 dt_plic_irq_id_t irq);
226
227
228/**
229 * Get the alert ID of a spi_host 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 spi_host.
235 * @param alert A spi_host alert.
236 * @return The Alert Handler alert ID of the alert of this instance.
237 */
239 dt_spi_host_t dt,
240 dt_spi_host_alert_t alert);
241
242/**
243 * Convert a global alert ID to a local spi_host alert type.
244 *
245 * @param dt Instance of spi_host.
246 * @param alert A global alert ID that belongs to this instance.
247 * @return The spi_host alert, or `kDtSpiHostAlertCount`.
248 *
249 * **Note:** This function assumes that the global alert ID belongs to the
250 * instance of spi_host passed in parameter. In other words, it must be the case
251 * that `dt_spi_host_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
252 * this function will return `kDtSpiHostAlertCount`.
253 */
255 dt_spi_host_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 spi_host.
263 * @param sig Requested peripheral I/O.
264 * @return Description of the requested peripheral I/O for this instance.
265 */
267 dt_spi_host_t dt,
269
270/**
271 * Get the clock signal connected to a clock port of an instance.
272 *
273 * @param dt Instance of spi_host.
274 * @param clk Clock port.
275 * @return Clock signal.
276 */
278 dt_spi_host_t dt,
280
281/**
282 * Get the reset signal connected to a reset port of an instance.
283 *
284 * @param dt Instance of spi_host.
285 * @param rst Reset port.
286 * @return Reset signal.
287 */
289 dt_spi_host_t dt,
291
292
293
294#ifdef __cplusplus
295} // extern "C"
296#endif // __cplusplus
297
298#endif // OPENTITAN_DT_SPI_HOST_H_