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