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