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