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