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