Software APIs
dt_i2c.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_I2C_H_
8#define OPENTITAN_DT_I2C_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP i2c and top earlgrey.
17 *
18 * This file contains the type definitions and global functions of the i2c.
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_i2c {
30 kDtI2c0 = 0, /**< i2c0 */
31 kDtI2c1 = 1, /**< i2c1 */
32 kDtI2c2 = 2, /**< i2c2 */
33 kDtI2cFirst = 0, /**< \internal First instance */
34 kDtI2cCount = 3, /**< \internal Number of instances */
36
37/**
38 * List of register blocks.
39 *
40 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
41 */
42typedef enum dt_i2c_reg_block {
43 kDtI2cRegBlockCore = 0, /**< */
44 kDtI2cRegBlockCount = 1, /**< \internal Number of register blocks */
46
47/** Primary register block (associated with the "primary" set of registers that control the IP). */
48static const dt_i2c_reg_block_t kDtI2cRegBlockPrimary = kDtI2cRegBlockCore;
49
50/**
51 * List of memories.
52 *
53 * Memories are guaranteed to start at 0 and to be consecutively numbered.
54 */
55typedef enum dt_i2c_memory {
56 kDtI2cMemoryCount = 0, /**< \internal Number of memories */
58
59/**
60 * List of IRQs.
61 *
62 * IRQs are guaranteed to be numbered consecutively from 0.
63 */
64typedef enum dt_i2c_irq {
65 kDtI2cIrqFmtThreshold = 0, /**< host mode interrupt: asserted whilst the FMT FIFO level is below the low threshold. This is a level status interrupt. */
66 kDtI2cIrqRxThreshold = 1, /**< host mode interrupt: asserted whilst the RX FIFO level is above the high threshold. This is a level status interrupt. */
67 kDtI2cIrqAcqThreshold = 2, /**< target mode interrupt: asserted whilst the ACQ FIFO level is above the high threshold. This is a level status interrupt. */
68 kDtI2cIrqRxOverflow = 3, /**< host mode interrupt: raised if the RX FIFO has overflowed. */
69 kDtI2cIrqControllerHalt = 4, /**< host mode interrupt: raised if the controller FSM is halted, such as on an unexpected NACK or lost arbitration.
70Check !!CONTROLLER_EVENTS for the reason.
71The interrupt will be released when the bits in !!CONTROLLER_EVENTS are cleared. */
72 kDtI2cIrqSclInterference = 5, /**< host mode interrupt: raised if the SCL line drops early (not supported without clock synchronization). */
73 kDtI2cIrqSdaInterference = 6, /**< host mode interrupt: raised if the SDA line goes low when host is trying to assert high */
74 kDtI2cIrqStretchTimeout = 7, /**< host mode interrupt: raised if target stretches the clock beyond the allowed timeout period */
75 kDtI2cIrqSdaUnstable = 8, /**< host mode interrupt: raised if the target does not assert a constant value of SDA during transmission. */
76 kDtI2cIrqCmdComplete = 9, /**< host and target mode interrupt.
77In host mode, raised if the host issues a repeated START or terminates the transaction by issuing STOP.
78In target mode, raised if the external host issues a STOP or repeated START. */
79 kDtI2cIrqTxStretch = 10, /**< target mode interrupt: raised if the target is stretching clocks for a read command. This is a level status interrupt. */
80 kDtI2cIrqTxThreshold = 11, /**< target mode interrupt: asserted whilst the TX FIFO level is below the low threshold. This is a level status interrupt. */
81 kDtI2cIrqAcqStretch = 12, /**< target mode interrupt: raised if the target is stretching clocks due to full ACQ FIFO or zero count in !!TARGET_ACK_CTRL.NBYTES (if enabled). This is a level status interrupt. */
82 kDtI2cIrqUnexpStop = 13, /**< target mode interrupt: raised if STOP is received without a preceding NACK during an external host read. */
83 kDtI2cIrqHostTimeout = 14, /**< target mode interrupt: raised if the host stops sending the clock during an ongoing transaction. */
84 kDtI2cIrqCount = 15, /**< \internal Number of IRQs */
86
87/**
88 * List of Alerts.
89 *
90 * Alerts are guaranteed to be numbered consecutively from 0.
91 */
92typedef enum dt_i2c_alert {
93 kDtI2cAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
94 kDtI2cAlertCount = 1, /**< \internal Number of Alerts */
96
97/**
98 * List of clock ports.
99 *
100 * Clock ports are guaranteed to be numbered consecutively from 0.
101 */
102typedef enum dt_i2c_clock {
103 kDtI2cClockClk = 0, /**< Clock port clk_i */
104 kDtI2cClockCount = 1, /**< \internal Number of clock ports */
106
107/**
108 * List of reset ports.
109 *
110 * Reset ports are guaranteed to be numbered consecutively from 0.
111 */
112typedef enum dt_i2c_reset {
113 kDtI2cResetRst = 0, /**< Reset port rst_ni */
114 kDtI2cResetCount = 1, /**< \internal Number of reset ports */
116
117/**
118 * List of peripheral I/O.
119 *
120 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
121 */
122typedef enum dt_i2c_periph_io {
123 kDtI2cPeriphIoSda = 0, /**< */
124 kDtI2cPeriphIoScl = 1, /**< */
125 kDtI2cPeriphIoCount = 2, /**< \internal Number of peripheral I/O */
127
128/**
129 * List of supported hardware features.
130 */
131#define OPENTITAN_I2C_HAS_MODE_HOST 1
132#define OPENTITAN_I2C_HAS_MODE_TARGET 1
133#define OPENTITAN_I2C_HAS_MODE_ACKCONTROL 1
134#define OPENTITAN_I2C_HAS_SPEED_STANDARD 1
135#define OPENTITAN_I2C_HAS_SPEED_FAST 1
136#define OPENTITAN_I2C_HAS_SPEED_FASTPLUS 1
137#define OPENTITAN_I2C_HAS_OVERRIDE 1
138#define OPENTITAN_I2C_HAS_OPERATION_READ 1
139#define OPENTITAN_I2C_HAS_OPERATION_WRITE 1
140#define OPENTITAN_I2C_HAS_PROTOCOL_CLOCKSTRETCHING 1
141#define OPENTITAN_I2C_HAS_PROTOCOL_NACK 1
142#define OPENTITAN_I2C_HAS_PROTOCOL_REPEATEDSTART 1
143
144
145
146/**
147 * Get the i2c instance from an instance ID
148 *
149 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
150 *
151 * @param inst_id Instance ID.
152 * @return A i2c instance.
153 *
154 * **Note:** This function only makes sense if the instance ID has device type i2c,
155 * otherwise the returned value is unspecified.
156 */
158
159/**
160 * Get the instance ID of an instance.
161 *
162 * @param dt Instance of i2c.
163 * @return The instance ID of that instance.
164 */
166
167/**
168 * Get the register base address of an instance.
169 *
170 * @param dt Instance of i2c.
171 * @param reg_block The register block requested.
172 * @return The register base address of the requested block.
173 */
174uint32_t dt_i2c_reg_block(
175 dt_i2c_t dt,
176 dt_i2c_reg_block_t reg_block);
177
178/**
179 * Get the primary register base address of an instance.
180 *
181 * This is just a convenience function, equivalent to
182 * `dt_i2c_reg_block(dt, kDtI2cRegBlockCore)`
183 *
184 * @param dt Instance of i2c.
185 * @return The register base address of the primary register block.
186 */
187static inline uint32_t dt_i2c_primary_reg_block(
188 dt_i2c_t dt) {
189 return dt_i2c_reg_block(dt, kDtI2cRegBlockCore);
190}
191
192/**
193 * Get the base address of a memory.
194 *
195 * @param dt Instance of i2c.
196 * @param mem The memory requested.
197 * @return The base address of the requested memory.
198 */
199uint32_t dt_i2c_memory_base(
200 dt_i2c_t dt,
201 dt_i2c_memory_t mem);
202
203/**
204 * Get the size of a memory.
205 *
206 * @param dt Instance of i2c.
207 * @param mem The memory requested.
208 * @return The size of the requested memory.
209 */
210uint32_t dt_i2c_memory_size(
211 dt_i2c_t dt,
212 dt_i2c_memory_t mem);
213
214/**
215 * Get the PLIC ID of a i2c IRQ for a given instance.
216 *
217 * If the instance is not connected to the PLIC, this function
218 * will return `kDtPlicIrqIdNone`.
219 *
220 * @param dt Instance of i2c.
221 * @param irq A i2c IRQ.
222 * @return The PLIC ID of the IRQ of this instance.
223 */
225 dt_i2c_t dt,
226 dt_i2c_irq_t irq);
227
228/**
229 * Convert a global IRQ ID to a local i2c IRQ type.
230 *
231 * @param dt Instance of i2c.
232 * @param irq A PLIC ID that belongs to this instance.
233 * @return The i2c IRQ, or `kDtI2cIrqCount`.
234 *
235 * **Note:** This function assumes that the PLIC ID belongs to the instance
236 * of i2c passed in parameter. In other words, it must be the case that
237 * `dt_i2c_instance_id(dt) == dt_plic_id_to_instance_id(irq)`. Otherwise, this function
238 * will return `kDtI2cIrqCount`.
239 */
241 dt_i2c_t dt,
242 dt_plic_irq_id_t irq);
243
244
245/**
246 * Get the alert ID of a i2c alert for a given instance.
247 *
248 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
249 * instances where the instance is not connected, the return value is unspecified.
250 *
251 * @param dt Instance of i2c.
252 * @param alert A i2c alert.
253 * @return The Alert Handler alert ID of the alert of this instance.
254 */
256 dt_i2c_t dt,
257 dt_i2c_alert_t alert);
258
259/**
260 * Convert a global alert ID to a local i2c alert type.
261 *
262 * @param dt Instance of i2c.
263 * @param alert A global alert ID that belongs to this instance.
264 * @return The i2c alert, or `kDtI2cAlertCount`.
265 *
266 * **Note:** This function assumes that the global alert ID belongs to the
267 * instance of i2c passed in parameter. In other words, it must be the case
268 * that `dt_i2c_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
269 * this function will return `kDtI2cAlertCount`.
270 */
272 dt_i2c_t dt,
273 dt_alert_id_t alert);
274
275
276/**
277 * Get the peripheral I/O description of an instance.
278 *
279 * @param dt Instance of i2c.
280 * @param sig Requested peripheral I/O.
281 * @return Description of the requested peripheral I/O for this instance.
282 */
284 dt_i2c_t dt,
286
287/**
288 * Get the clock signal connected to a clock port of an instance.
289 *
290 * @param dt Instance of i2c.
291 * @param clk Clock port.
292 * @return Clock signal.
293 */
295 dt_i2c_t dt,
296 dt_i2c_clock_t clk);
297
298/**
299 * Get the reset signal connected to a reset port of an instance.
300 *
301 * @param dt Instance of i2c.
302 * @param rst Reset port.
303 * @return Reset signal.
304 */
306 dt_i2c_t dt,
307 dt_i2c_reset_t rst);
308
309
310
311#ifdef __cplusplus
312} // extern "C"
313#endif // __cplusplus
314
315#endif // OPENTITAN_DT_I2C_H_