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