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 darjeeling.
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 kDtSpiHostFirst = 0, /**< \internal First instance */
32 kDtSpiHostCount = 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 kDtSpiHostRegBlockCore = 0, /**< */
42 kDtSpiHostRegBlockCount = 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_host_reg_block_t kDtSpiHostRegBlockPrimary = kDtSpiHostRegBlockCore;
47
48/**
49 * List of memories.
50 *
51 * Memories are guaranteed to start at 0 and to be consecutively numbered.
52 */
53typedef enum dt_spi_host_memory {
54 kDtSpiHostMemoryCount = 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_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. */
67 kDtSpiHostIrqCount = 2, /**< \internal Number of IRQs */
69
70/**
71 * List of Alerts.
72 *
73 * Alerts are guaranteed to be numbered consecutively from 0.
74 */
75typedef enum dt_spi_host_alert {
76 kDtSpiHostAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
77 kDtSpiHostAlertCount = 1, /**< \internal Number of Alerts */
79
80/**
81 * List of clock ports.
82 *
83 * Clock ports are guaranteed to be numbered consecutively from 0.
84 */
85typedef enum dt_spi_host_clock {
86 kDtSpiHostClockClk = 0, /**< Clock port clk_i */
87 kDtSpiHostClockCount = 1, /**< \internal Number of clock ports */
89
90/**
91 * List of reset ports.
92 *
93 * Reset ports are guaranteed to be numbered consecutively from 0.
94 */
95typedef enum dt_spi_host_reset {
96 kDtSpiHostResetRst = 0, /**< Reset port rst_ni */
97 kDtSpiHostResetCount = 1, /**< \internal Number of reset ports */
99
100/**
101 * List of peripheral I/O.
102 *
103 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
104 */
106 kDtSpiHostPeriphIoSck = 0, /**< */
107 kDtSpiHostPeriphIoCsb = 1, /**< */
108 kDtSpiHostPeriphIoSd0 = 2, /**< */
109 kDtSpiHostPeriphIoSd1 = 3, /**< */
110 kDtSpiHostPeriphIoSd2 = 4, /**< */
111 kDtSpiHostPeriphIoSd3 = 5, /**< */
112 kDtSpiHostPeriphIoCount = 6, /**< \internal Number of peripheral I/O */
114
115/**
116 * List of supported hardware features.
117 */
118#define OPENTITAN_SPI_HOST_HAS_USECASE_SERIALNORFLASH 1
119#define OPENTITAN_SPI_HOST_HAS_USECASE_PASSTHROUGH 1
120#define OPENTITAN_SPI_HOST_HAS_RATE_STANDARD 1
121#define OPENTITAN_SPI_HOST_HAS_RATE_DUAL 1
122#define OPENTITAN_SPI_HOST_HAS_RATE_QUAD 1
123#define OPENTITAN_SPI_HOST_HAS_CONFIG_CPOL 1
124#define OPENTITAN_SPI_HOST_HAS_CONFIG_CLOCKDIV 1
125#define OPENTITAN_SPI_HOST_HAS_EVENT_WATERMARK 1
126#define OPENTITAN_SPI_HOST_HAS_EVENT_FULL 1
127#define OPENTITAN_SPI_HOST_HAS_EVENT_EMPTY 1
128
129
130
131/**
132 * Get the spi_host instance from an instance ID
133 *
134 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
135 *
136 * @param inst_id Instance ID.
137 * @return A spi_host instance.
138 *
139 * **Note:** This function only makes sense if the instance ID has device type spi_host,
140 * otherwise the returned value is unspecified.
141 */
143
144/**
145 * Get the instance ID of an instance.
146 *
147 * @param dt Instance of spi_host.
148 * @return The instance ID of that instance.
149 */
151
152/**
153 * Get the register base address of an instance.
154 *
155 * @param dt Instance of spi_host.
156 * @param reg_block The register block requested.
157 * @return The register base address of the requested block.
158 */
159uint32_t dt_spi_host_reg_block(
160 dt_spi_host_t dt,
161 dt_spi_host_reg_block_t reg_block);
162
163/**
164 * Get the primary register base address of an instance.
165 *
166 * This is just a convenience function, equivalent to
167 * `dt_spi_host_reg_block(dt, kDtSpiHostRegBlockCore)`
168 *
169 * @param dt Instance of spi_host.
170 * @return The register base address of the primary register block.
171 */
172static inline uint32_t dt_spi_host_primary_reg_block(
173 dt_spi_host_t dt) {
174 return dt_spi_host_reg_block(dt, kDtSpiHostRegBlockCore);
175}
176
177/**
178 * Get the base address of a memory.
179 *
180 * @param dt Instance of spi_host.
181 * @param mem The memory requested.
182 * @return The base address of the requested memory.
183 */
185 dt_spi_host_t dt,
187
188/**
189 * Get the size of a memory.
190 *
191 * @param dt Instance of spi_host.
192 * @param mem The memory requested.
193 * @return The size of the requested memory.
194 */
196 dt_spi_host_t dt,
198
199/**
200 * Get the PLIC ID of a spi_host IRQ for a given instance.
201 *
202 * If the instance is not connected to the PLIC, this function
203 * will return `kDtPlicIrqIdNone`.
204 *
205 * @param dt Instance of spi_host.
206 * @param irq A spi_host IRQ.
207 * @return The PLIC ID of the IRQ of this instance.
208 */
210 dt_spi_host_t dt,
212
213/**
214 * Convert a global IRQ ID to a local spi_host IRQ type.
215 *
216 * @param dt Instance of spi_host.
217 * @param irq A PLIC ID that belongs to this instance.
218 * @return The spi_host IRQ, or `kDtSpiHostIrqCount`.
219 *
220 * **Note:** This function assumes that the PLIC ID belongs to the instance
221 * of spi_host passed in parameter. In other words, it must be the case that
222 * `dt_spi_host_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
223 * will return `kDtSpiHostIrqCount`.
224 */
226 dt_spi_host_t dt,
227 dt_plic_irq_id_t irq);
228
229
230/**
231 * Get the alert ID of a spi_host alert for a given instance.
232 *
233 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
234 * instances where the instance is not connected, the return value is unspecified.
235 *
236 * @param dt Instance of spi_host.
237 * @param alert A spi_host alert.
238 * @return The Alert Handler alert ID of the alert of this instance.
239 */
241 dt_spi_host_t dt,
242 dt_spi_host_alert_t alert);
243
244/**
245 * Convert a global alert ID to a local spi_host alert type.
246 *
247 * @param dt Instance of spi_host.
248 * @param alert A global alert ID that belongs to this instance.
249 * @return The spi_host alert, or `kDtSpiHostAlertCount`.
250 *
251 * **Note:** This function assumes that the global alert ID belongs to the
252 * instance of spi_host passed in parameter. In other words, it must be the case
253 * that `dt_spi_host_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
254 * this function will return `kDtSpiHostAlertCount`.
255 */
257 dt_spi_host_t dt,
258 dt_alert_id_t alert);
259
260
261/**
262 * Get the peripheral I/O description of an instance.
263 *
264 * @param dt Instance of spi_host.
265 * @param sig Requested peripheral I/O.
266 * @return Description of the requested peripheral I/O for this instance.
267 */
269 dt_spi_host_t dt,
271
272/**
273 * Get the clock signal connected to a clock port of an instance.
274 *
275 * @param dt Instance of spi_host.
276 * @param clk Clock port.
277 * @return Clock signal.
278 */
280 dt_spi_host_t dt,
282
283/**
284 * Get the reset signal connected to a reset port of an instance.
285 *
286 * @param dt Instance of spi_host.
287 * @param rst Reset port.
288 * @return Reset signal.
289 */
291 dt_spi_host_t dt,
293
294
295
296#ifdef __cplusplus
297} // extern "C"
298#endif // __cplusplus
299
300#endif // OPENTITAN_DT_SPI_HOST_H_