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