Software APIs
dt_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/dt_api.h"
22#include <stdint.h>
23
24
25
26/**
27 * List of instances.
28 */
29typedef enum dt_spi_host {
30 kDtSpiHost0 = 0, /**< spi_host0 */
31 kDtSpiHost1 = 1, /**< spi_host1 */
32 kDtSpiHostFirst = 0, /**< \internal First instance */
33 kDtSpiHostCount = 2, /**< \internal Number of instances */
35
36/**
37 * List of register blocks.
38 *
39 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
40 */
42 kDtSpiHostRegBlockCore = 0, /**< */
43 kDtSpiHostRegBlockCount = 1, /**< \internal Number of register blocks */
45
46/** Primary register block (associated with the "primary" set of registers that control the IP). */
47static const dt_spi_host_reg_block_t kDtSpiHostRegBlockPrimary = kDtSpiHostRegBlockCore;
48
49/**
50 * List of memories.
51 *
52 * Memories are guaranteed to start at 0 and to be consecutively numbered.
53 */
54typedef enum dt_spi_host_memory {
55 kDtSpiHostMemoryCount = 0, /**< \internal Number of memories */
57
58/**
59 * List of IRQs.
60 *
61 * IRQs are guaranteed to be numbered consecutively from 0.
62 */
63typedef enum dt_spi_host_irq {
64 kDtSpiHostIrqError = 0, /**< Error-related interrupts, see !!ERROR_ENABLE register for more
65 information. */
66 kDtSpiHostIrqSpiEvent = 1, /**< Event-related interrupts, see !!EVENT_ENABLE register for more
67 information. */
68 kDtSpiHostIrqCount = 2, /**< \internal Number of IRQs */
70
71/**
72 * List of Alerts.
73 *
74 * Alerts are guaranteed to be numbered consecutively from 0.
75 */
76typedef enum dt_spi_host_alert {
77 kDtSpiHostAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
78 kDtSpiHostAlertCount = 1, /**< \internal Number of Alerts */
80
81/**
82 * List of clock ports.
83 *
84 * Clock ports are guaranteed to be numbered consecutively from 0.
85 */
86typedef enum dt_spi_host_clock {
87 kDtSpiHostClockClk = 0, /**< Clock port clk_i */
88 kDtSpiHostClockCount = 1, /**< \internal Number of clock ports */
90
91/**
92 * List of reset ports.
93 *
94 * Reset ports are guaranteed to be numbered consecutively from 0.
95 */
96typedef enum dt_spi_host_reset {
97 kDtSpiHostResetRst = 0, /**< Reset port rst_ni */
98 kDtSpiHostResetCount = 1, /**< \internal Number of reset ports */
100
101/**
102 * List of peripheral I/O.
103 *
104 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
105 */
107 kDtSpiHostPeriphIoSck = 0, /**< */
108 kDtSpiHostPeriphIoCsb = 1, /**< */
109 kDtSpiHostPeriphIoSd0 = 2, /**< */
110 kDtSpiHostPeriphIoSd1 = 3, /**< */
111 kDtSpiHostPeriphIoSd2 = 4, /**< */
112 kDtSpiHostPeriphIoSd3 = 5, /**< */
113 kDtSpiHostPeriphIoCount = 6, /**< \internal Number of peripheral I/O */
115
116/**
117 * List of supported hardware features.
118 */
119#define OPENTITAN_SPI_HOST_HAS_USECASE_SERIALNORFLASH 1
120#define OPENTITAN_SPI_HOST_HAS_USECASE_PASSTHROUGH 1
121#define OPENTITAN_SPI_HOST_HAS_RATE_STANDARD 1
122#define OPENTITAN_SPI_HOST_HAS_RATE_DUAL 1
123#define OPENTITAN_SPI_HOST_HAS_RATE_QUAD 1
124#define OPENTITAN_SPI_HOST_HAS_CONFIG_CPOL 1
125#define OPENTITAN_SPI_HOST_HAS_CONFIG_CLOCKDIV 1
126#define OPENTITAN_SPI_HOST_HAS_EVENT_WATERMARK 1
127#define OPENTITAN_SPI_HOST_HAS_EVENT_FULL 1
128#define OPENTITAN_SPI_HOST_HAS_EVENT_EMPTY 1
129
130
131
132/**
133 * Get the spi_host instance from an instance ID
134 *
135 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
136 *
137 * @param inst_id Instance ID.
138 * @return A spi_host instance.
139 *
140 * **Note:** This function only makes sense if the instance ID has device type spi_host,
141 * otherwise the returned value is unspecified.
142 */
144
145/**
146 * Get the instance ID of an instance.
147 *
148 * @param dt Instance of spi_host.
149 * @return The instance ID of that instance.
150 */
152
153/**
154 * Get the register base address of an instance.
155 *
156 * @param dt Instance of spi_host.
157 * @param reg_block The register block requested.
158 * @return The register base address of the requested block.
159 */
160uint32_t dt_spi_host_reg_block(
161 dt_spi_host_t dt,
162 dt_spi_host_reg_block_t reg_block);
163
164/**
165 * Get the primary register base address of an instance.
166 *
167 * This is just a convenience function, equivalent to
168 * `dt_spi_host_reg_block(dt, kDtSpiHostRegBlockCore)`
169 *
170 * @param dt Instance of spi_host.
171 * @return The register base address of the primary register block.
172 */
173static inline uint32_t dt_spi_host_primary_reg_block(
174 dt_spi_host_t dt) {
175 return dt_spi_host_reg_block(dt, kDtSpiHostRegBlockCore);
176}
177
178/**
179 * Get the base address of a memory.
180 *
181 * @param dt Instance of spi_host.
182 * @param mem The memory requested.
183 * @return The base address of the requested memory.
184 */
186 dt_spi_host_t dt,
188
189/**
190 * Get the size of a memory.
191 *
192 * @param dt Instance of spi_host.
193 * @param mem The memory requested.
194 * @return The size of the requested memory.
195 */
197 dt_spi_host_t dt,
199
200/**
201 * Get the PLIC ID of a spi_host IRQ for a given instance.
202 *
203 * If the instance is not connected to the PLIC, this function
204 * will return `kDtPlicIrqIdNone`.
205 *
206 * @param dt Instance of spi_host.
207 * @param irq A spi_host IRQ.
208 * @return The PLIC ID of the IRQ of this instance.
209 */
211 dt_spi_host_t dt,
213
214/**
215 * Convert a global IRQ ID to a local spi_host IRQ type.
216 *
217 * @param dt Instance of spi_host.
218 * @param irq A PLIC ID that belongs to this instance.
219 * @return The spi_host IRQ, or `kDtSpiHostIrqCount`.
220 *
221 * **Note:** This function assumes that the PLIC ID belongs to the instance
222 * of spi_host passed in parameter. In other words, it must be the case that
223 * `dt_spi_host_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
224 * will return `kDtSpiHostIrqCount`.
225 */
227 dt_spi_host_t dt,
228 dt_plic_irq_id_t irq);
229
230
231/**
232 * Get the alert ID of a spi_host alert for a given instance.
233 *
234 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
235 * instances where the instance is not connected, the return value is unspecified.
236 *
237 * @param dt Instance of spi_host.
238 * @param alert A spi_host alert.
239 * @return The Alert Handler alert ID of the alert of this instance.
240 */
242 dt_spi_host_t dt,
243 dt_spi_host_alert_t alert);
244
245/**
246 * Convert a global alert ID to a local spi_host alert type.
247 *
248 * @param dt Instance of spi_host.
249 * @param alert A global alert ID that belongs to this instance.
250 * @return The spi_host alert, or `kDtSpiHostAlertCount`.
251 *
252 * **Note:** This function assumes that the global alert ID belongs to the
253 * instance of spi_host passed in parameter. In other words, it must be the case
254 * that `dt_spi_host_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
255 * this function will return `kDtSpiHostAlertCount`.
256 */
258 dt_spi_host_t dt,
259 dt_alert_id_t alert);
260
261
262/**
263 * Get the peripheral I/O description of an instance.
264 *
265 * @param dt Instance of spi_host.
266 * @param sig Requested peripheral I/O.
267 * @return Description of the requested peripheral I/O for this instance.
268 */
270 dt_spi_host_t dt,
272
273/**
274 * Get the clock signal connected to a clock port of an instance.
275 *
276 * @param dt Instance of spi_host.
277 * @param clk Clock port.
278 * @return Clock signal.
279 */
281 dt_spi_host_t dt,
283
284/**
285 * Get the reset signal connected to a reset port of an instance.
286 *
287 * @param dt Instance of spi_host.
288 * @param rst Reset port.
289 * @return Reset signal.
290 */
292 dt_spi_host_t dt,
294
295
296
297#ifdef __cplusplus
298} // extern "C"
299#endif // __cplusplus
300
301#endif // OPENTITAN_DT_SPI_HOST_H_