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 englishbreakfast.
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 */
33
34enum {
35 kDtSpiHostCount = 1, /**< Number of instances */
36};
37
38
39/**
40 * List of register blocks.
41 *
42 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
43 */
45 kDtSpiHostRegBlockCore = 0, /**< */
47
48enum {
49 kDtSpiHostRegBlockCount = 1, /**< Number of register blocks */
50};
51
52
53/** Primary register block (associated with the "primary" set of registers that control the IP). */
54static const dt_spi_host_reg_block_t kDtSpiHostRegBlockPrimary = kDtSpiHostRegBlockCore;
55
56/**
57 * List of IRQs.
58 *
59 * IRQs are guaranteed to be numbered consecutively from 0.
60 */
61typedef enum dt_spi_host_irq {
62 kDtSpiHostIrqError = 0, /**< Error-related interrupts, see !!ERROR_ENABLE register for more
63 information. */
64 kDtSpiHostIrqSpiEvent = 1, /**< Event-related interrupts, see !!EVENT_ENABLE register for more
65 information. */
67
68enum {
69 kDtSpiHostIrqCount = 2, /**< Number of IRQs */
70};
71
72
73/**
74 * List of clock ports.
75 *
76 * Clock ports are guaranteed to be numbered consecutively from 0.
77 */
78typedef enum dt_spi_host_clock {
79 kDtSpiHostClockClk = 0, /**< Clock port clk_i */
81
82enum {
83 kDtSpiHostClockCount = 1, /**< Number of clock ports */
84};
85
86
87/**
88 * List of reset ports.
89 *
90 * Reset ports are guaranteed to be numbered consecutively from 0.
91 */
92typedef enum dt_spi_host_reset {
93 kDtSpiHostResetRst = 0, /**< Reset port rst_ni */
95
96enum {
97 kDtSpiHostResetCount = 1, /**< Number of reset ports */
98};
99
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, /**< */
114
115enum {
116 kDtSpiHostPeriphIoCount = 6, /**< Number of peripheral I/O */
117};
118
119
120/**
121 * List of supported hardware features.
122 */
123#define OPENTITAN_SPI_HOST_HAS_USECASE_SERIALNORFLASH 1
124#define OPENTITAN_SPI_HOST_HAS_USECASE_PASSTHROUGH 1
125#define OPENTITAN_SPI_HOST_HAS_RATE_STANDARD 1
126#define OPENTITAN_SPI_HOST_HAS_RATE_DUAL 1
127#define OPENTITAN_SPI_HOST_HAS_RATE_QUAD 1
128#define OPENTITAN_SPI_HOST_HAS_CONFIG_CPOL 1
129#define OPENTITAN_SPI_HOST_HAS_CONFIG_CLOCKDIV 1
130#define OPENTITAN_SPI_HOST_HAS_EVENT_WATERMARK 1
131#define OPENTITAN_SPI_HOST_HAS_EVENT_FULL 1
132#define OPENTITAN_SPI_HOST_HAS_EVENT_EMPTY 1
133
134
135
136/**
137 * Get the spi_host instance from an instance ID
138 *
139 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
140 *
141 * @param inst_id Instance ID.
142 * @return A spi_host instance.
143 *
144 * **Note:** This function only makes sense if the instance ID has device type spi_host,
145 * otherwise the returned value is unspecified.
146 */
148
149/**
150 * Get the instance ID of an instance.
151 *
152 * @param dt Instance of spi_host.
153 * @return The instance ID of that instance.
154 */
156
157/**
158 * Get the register base address of an instance.
159 *
160 * @param dt Instance of spi_host.
161 * @param reg_block The register block requested.
162 * @return The register base address of the requested block.
163 */
164uint32_t dt_spi_host_reg_block(
165 dt_spi_host_t dt,
166 dt_spi_host_reg_block_t reg_block);
167
168/**
169 * Get the primary register base address of an instance.
170 *
171 * This is just a convenience function, equivalent to
172 * `dt_spi_host_reg_block(dt, kDtSpiHostRegBlockCore)`
173 *
174 * @param dt Instance of spi_host.
175 * @return The register base address of the primary register block.
176 */
177static inline uint32_t dt_spi_host_primary_reg_block(
178 dt_spi_host_t dt) {
179 return dt_spi_host_reg_block(dt, kDtSpiHostRegBlockCore);
180}
181
182/**
183 * Get the PLIC ID of a spi_host IRQ for a given instance.
184 *
185 * If the instance is not connected to the PLIC, this function
186 * will return `kDtPlicIrqIdNone`.
187 *
188 * @param dt Instance of spi_host.
189 * @param irq A spi_host IRQ.
190 * @return The PLIC ID of the IRQ of this instance.
191 */
193 dt_spi_host_t dt,
195
196/**
197 * Convert a global IRQ ID to a local spi_host IRQ type.
198 *
199 * @param dt Instance of spi_host.
200 * @param irq A PLIC ID that belongs to this instance.
201 * @return The spi_host IRQ, or `kDtSpiHostIrqCount`.
202 *
203 * **Note:** This function assumes that the PLIC ID belongs to the instance
204 * of spi_host passed in parameter. In other words, it must be the case that
205 * `dt_spi_host_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
206 * will return `kDtSpiHostIrqCount`.
207 */
209 dt_spi_host_t dt,
210 dt_plic_irq_id_t irq);
211
212
213
214/**
215 * Get the peripheral I/O description of an instance.
216 *
217 * @param dt Instance of spi_host.
218 * @param sig Requested peripheral I/O.
219 * @return Description of the requested peripheral I/O for this instance.
220 */
222 dt_spi_host_t dt,
224
225/**
226 * Get the clock signal connected to a clock port of an instance.
227 *
228 * @param dt Instance of spi_host.
229 * @param clk Clock port.
230 * @return Clock signal.
231 */
233 dt_spi_host_t dt,
235
236/**
237 * Get the reset signal connected to a reset port of an instance.
238 *
239 * @param dt Instance of spi_host.
240 * @param rst Reset port.
241 * @return Reset signal.
242 */
244 dt_spi_host_t dt,
246
247
248
249#ifdef __cplusplus
250} // extern "C"
251#endif // __cplusplus
252
253#endif // OPENTITAN_DT_SPI_HOST_H_