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/**
11 * @file
12 * @brief Device Tables (DT) for IP spi_host and top darjeeling.
13 *
14 * This file contains the type definitions and global functions of the spi_host.
15 */
16
17#include "dt_api.h"
18#include <stdint.h>
19
20
21
22/**
23 * List of instances.
24 */
25typedef enum dt_spi_host {
26 kDtSpiHost0 = 0, /**< spi_host0 */
27 kDtSpiHostFirst = 0, /**< \internal First instance */
28 kDtSpiHostCount = 1, /**< \internal Number of instances */
30
31/**
32 * List of register blocks.
33 *
34 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
35 */
37 kDtSpiHostRegBlockCore = 0, /**< */
38 kDtSpiHostRegBlockCount = 1, /**< \internal Number of register blocks */
40
41/** Primary register block (associated with the "primary" set of registers that control the IP). */
42static const dt_spi_host_reg_block_t kDtSpiHostRegBlockPrimary = kDtSpiHostRegBlockCore;
43
44/**
45 * List of IRQs.
46 *
47 * IRQs are guaranteed to be numbered consecutively from 0.
48 */
49typedef enum dt_spi_host_irq {
50 kDtSpiHostIrqError = 0, /**< Error-related interrupts, see !!ERROR_ENABLE register for more
51 information. */
52 kDtSpiHostIrqSpiEvent = 1, /**< Event-related interrupts, see !!EVENT_ENABLE register for more
53 information. */
54 kDtSpiHostIrqCount = 2, /**< \internal Number of IRQs */
56
57/**
58 * List of Alerts.
59 *
60 * Alerts are guaranteed to be numbered consecutively from 0.
61 */
62typedef enum dt_spi_host_alert {
63 kDtSpiHostAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
64 kDtSpiHostAlertCount = 1, /**< \internal Number of Alerts */
66
67/**
68 * List of clock ports.
69 *
70 * Clock ports are guaranteed to be numbered consecutively from 0.
71 */
72typedef enum dt_spi_host_clock {
73 kDtSpiHostClockClk = 0, /**< Clock port clk_i */
74 kDtSpiHostClockCount = 1, /**< \internal Number of clock ports */
76
77/**
78 * List of reset ports.
79 *
80 * Reset ports are guaranteed to be numbered consecutively from 0.
81 */
82typedef enum dt_spi_host_reset {
83 kDtSpiHostResetRst = 0, /**< Reset port rst_ni */
84 kDtSpiHostResetCount = 1, /**< \internal Number of reset ports */
86
87/**
88 * List of peripheral I/O.
89 *
90 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
91 */
93 kDtSpiHostPeriphIoSck = 0, /**< */
94 kDtSpiHostPeriphIoCsb = 1, /**< */
95 kDtSpiHostPeriphIoSd0 = 2, /**< */
96 kDtSpiHostPeriphIoSd1 = 3, /**< */
97 kDtSpiHostPeriphIoSd2 = 4, /**< */
98 kDtSpiHostPeriphIoSd3 = 5, /**< */
99 kDtSpiHostPeriphIoCount = 6, /**< \internal Number of peripheral I/O */
101
102/**
103 * List of supported hardware features.
104 */
105#define OPENTITAN_SPI_HOST_HAS_USECASE_SERIALNORFLASH 1
106#define OPENTITAN_SPI_HOST_HAS_USECASE_PASSTHROUGH 1
107#define OPENTITAN_SPI_HOST_HAS_RATE_STANDARD 1
108#define OPENTITAN_SPI_HOST_HAS_RATE_DUAL 1
109#define OPENTITAN_SPI_HOST_HAS_RATE_QUAD 1
110#define OPENTITAN_SPI_HOST_HAS_CONFIG_CPOL 1
111#define OPENTITAN_SPI_HOST_HAS_CONFIG_CLOCKDIV 1
112#define OPENTITAN_SPI_HOST_HAS_EVENT_WATERMARK 1
113#define OPENTITAN_SPI_HOST_HAS_EVENT_FULL 1
114#define OPENTITAN_SPI_HOST_HAS_EVENT_EMPTY 1
115
116
117
118/**
119 * Get the spi_host instance from an instance ID
120 *
121 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
122 *
123 * @param inst_id Instance ID.
124 * @return A spi_host instance.
125 *
126 * **Note:** This function only makes sense if the instance ID has device type spi_host,
127 * otherwise the returned value is unspecified.
128 */
130
131/**
132 * Get the instance ID of an instance.
133 *
134 * @param dt Instance of spi_host.
135 * @return The instance ID of that instance.
136 */
138
139/**
140 * Get the register base address of an instance.
141 *
142 * @param dt Instance of spi_host.
143 * @param reg_block The register block requested.
144 * @return The register base address of the requested block.
145 */
146uint32_t dt_spi_host_reg_block(
147 dt_spi_host_t dt,
148 dt_spi_host_reg_block_t reg_block);
149
150/**
151 * Get the primary register base address of an instance.
152 *
153 * This is just a convenience function, equivalent to
154 * `dt_spi_host_reg_block(dt, kDtSpiHostRegBlockCore)`
155 *
156 * @param dt Instance of spi_host.
157 * @return The register base address of the primary register block.
158 */
159static inline uint32_t dt_spi_host_primary_reg_block(
160 dt_spi_host_t dt) {
161 return dt_spi_host_reg_block(dt, kDtSpiHostRegBlockCore);
162}
163
164/**
165 * Get the PLIC ID of a spi_host IRQ for a given instance.
166 *
167 * If the instance is not connected to the PLIC, this function
168 * will return `kDtPlicIrqIdNone`.
169 *
170 * @param dt Instance of spi_host.
171 * @param irq A spi_host IRQ.
172 * @return The PLIC ID of the IRQ of this instance.
173 */
175 dt_spi_host_t dt,
177
178/**
179 * Convert a global IRQ ID to a local spi_host IRQ type.
180 *
181 * @param dt Instance of spi_host.
182 * @param irq A PLIC ID that belongs to this instance.
183 * @return The spi_host IRQ, or `kDtSpiHostIrqCount`.
184 *
185 * **Note:** This function assumes that the PLIC ID belongs to the instance
186 * of spi_host passed in parameter. In other words, it must be the case that
187 * `dt_spi_host_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
188 * will return `kDtSpiHostIrqCount`.
189 */
191 dt_spi_host_t dt,
192 dt_plic_irq_id_t irq);
193
194
195/**
196 * Get the alert ID of a spi_host alert for a given instance.
197 *
198 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
199 * instances where the instance is not connected, the return value is unspecified.
200 *
201 * @param dt Instance of spi_host.
202 * @param alert A spi_host alert.
203 * @return The Alert Handler alert ID of the alert of this instance.
204 */
206 dt_spi_host_t dt,
207 dt_spi_host_alert_t alert);
208
209/**
210 * Convert a global alert ID to a local spi_host alert type.
211 *
212 * @param dt Instance of spi_host.
213 * @param alert A global alert ID that belongs to this instance.
214 * @return The spi_host alert, or `kDtSpiHostAlertCount`.
215 *
216 * **Note:** This function assumes that the global alert ID belongs to the
217 * instance of spi_host passed in parameter. In other words, it must be the case
218 * that `dt_spi_host_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
219 * this function will return `kDtSpiHostAlertCount`.
220 */
222 dt_spi_host_t dt,
223 dt_alert_id_t alert);
224
225
226/**
227 * Get the peripheral I/O description of an instance.
228 *
229 * @param dt Instance of spi_host.
230 * @param sig Requested peripheral I/O.
231 * @return Description of the requested peripheral I/O for this instance.
232 */
234 dt_spi_host_t dt,
236
237/**
238 * Get the clock signal connected to a clock port of an instance.
239 *
240 * @param dt Instance of spi_host.
241 * @param clk Clock port.
242 * @return Clock signal.
243 */
245 dt_spi_host_t dt,
247
248/**
249 * Get the reset signal connected to a reset port of an instance.
250 *
251 * @param dt Instance of spi_host.
252 * @param rst Reset port.
253 * @return Reset signal.
254 */
256 dt_spi_host_t dt,
258
259
260
261#endif // OPENTITAN_DT_SPI_HOST_H_