Software APIs
dif_i2c_autogen.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
6
7#ifndef OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_I2C_AUTOGEN_H_
8#define OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_I2C_AUTOGEN_H_
9
10// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
11// util/autogen_dif.py -i hw/ip/i2c/data/i2c.hjson -o
12// bazel-out/k8-fastbuild/bin/sw/device/lib/dif/autogen
13
14
15/**
16 * @file
17 * @brief <a href="/book/hw/ip/i2c/">I2C</a> Device Interface Functions
18 */
19
20#include <stdbool.h>
21#include <stdint.h>
22
26#include "hw/top/dt/i2c.h" // Generated.
27
28#ifdef __cplusplus
29extern "C" {
30#endif // __cplusplus
31
32/**
33 * A handle to i2c.
34 *
35 * This type should be treated as opaque by users.
36 */
37typedef struct dif_i2c {
38 /**
39 * The base address for the i2c hardware registers.
40 */
42 /**
43 * The instance, set to `kDtI2cCount` if not initialized
44 * through `dif_i2c_init_from_dt`.
45 */
48
49/**
50 * Creates a new handle for a(n) i2c peripheral.
51 *
52 * This function does not actuate the hardware.
53 *
54 * @param base_addr The MMIO base address of the i2c peripheral.
55 * @param[out] i2c Out param for the initialized handle.
56 * @return The result of the operation.
57 *
58 * DEPRECATED This function exists solely for the transition to
59 * dt-based DIFs and will be removed in the future.
60 */
63 mmio_region_t base_addr,
64 dif_i2c_t *i2c);
65
66/**
67 * Creates a new handle for a(n) i2c peripheral.
68 *
69 * This function does not actuate the hardware.
70 *
71 * @param dt The devicetable description of the device.
72 * @param[out] i2c Out param for the initialized handle.
73 * @return The result of the operation.
74 */
77 dt_i2c_t dt,
78 dif_i2c_t *i2c);
79
80/**
81 * Get the DT handle from this DIF.
82 *
83 * If this DIF was initialized by `dif_i2c_init_from_dt(dt, ..)`
84 * then this function will return `dt`. Otherwise it will return an error.
85 *
86 * @param i2c A i2c handle.
87 * @param[out] dt DT handle.
88 * @return `kDifBadArg` if the DIF has no DT information, `kDifOk` otherwise.
89 */
92 const dif_i2c_t *i2c,
93 dt_i2c_t *dt);
94
95 /**
96 * A i2c alert type.
97 */
98 typedef enum dif_i2c_alert {
99 /**
100 * This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected.
101 */
104
105 /**
106 * Forces a particular alert, causing it to be escalated as if the hardware
107 * had raised it.
108 *
109 * @param i2c A i2c handle.
110 * @param alert The alert to force.
111 * @return The result of the operation.
112 */
115 const dif_i2c_t *i2c,
116 dif_i2c_alert_t alert);
117
118 // DEPRECATED This typedef exists solely for the transition to
119 // dt-based interrupt numbers and will be removed in the future.
120 typedef dt_i2c_irq_t dif_i2c_irq_t;
121
122 /**
123 * A i2c interrupt request type.
124 *
125 * DEPRECATED Use `dt_i2c_irq_t` instead.
126 * This enumeration exists solely for the transition to
127 * dt-based interrupt numbers and will be removed in the future.
128 *
129 * The following are defines to keep the types consistent with DT.
130 */
131 /**
132 * Host mode interrupt: asserted whilst the FMT FIFO level is below the low threshold. This is a level status interrupt.
133 */
134#define kDifI2cIrqFmtThreshold kDtI2cIrqFmtThreshold
135 /**
136 * Host mode interrupt: asserted whilst the RX FIFO level is above the high threshold. This is a level status interrupt.
137 */
138#define kDifI2cIrqRxThreshold kDtI2cIrqRxThreshold
139 /**
140 * Target mode interrupt: asserted whilst the ACQ FIFO level is above the high threshold. This is a level status interrupt.
141 */
142#define kDifI2cIrqAcqThreshold kDtI2cIrqAcqThreshold
143 /**
144 * Host mode interrupt: raised if the RX FIFO has overflowed.
145 */
146#define kDifI2cIrqRxOverflow kDtI2cIrqRxOverflow
147 /**
148 * Host mode interrupt: raised if the controller FSM is halted, such as on an unexpected NACK or lost arbitration. Check !!CONTROLLER_EVENTS for the reason. The interrupt will be released when the bits in !!CONTROLLER_EVENTS are cleared.
149 */
150#define kDifI2cIrqControllerHalt kDtI2cIrqControllerHalt
151 /**
152 * Host mode interrupt: raised if the SCL line drops early (not supported without clock synchronization).
153 */
154#define kDifI2cIrqSclInterference kDtI2cIrqSclInterference
155 /**
156 * Host mode interrupt: raised if the SDA line goes low when host is trying to assert high
157 */
158#define kDifI2cIrqSdaInterference kDtI2cIrqSdaInterference
159 /**
160 * Host mode interrupt: raised if target stretches the clock beyond the allowed timeout period
161 */
162#define kDifI2cIrqStretchTimeout kDtI2cIrqStretchTimeout
163 /**
164 * Host mode interrupt: raised if the target does not assert a constant value of SDA during transmission.
165 */
166#define kDifI2cIrqSdaUnstable kDtI2cIrqSdaUnstable
167 /**
168 * Host and target mode interrupt. In host mode, raised if the host issues a repeated START or terminates the transaction by issuing STOP. In target mode, raised if the external host issues a STOP or repeated START.
169 */
170#define kDifI2cIrqCmdComplete kDtI2cIrqCmdComplete
171 /**
172 * Target mode interrupt: raised if the target is stretching clocks for a read command. This is a level status interrupt.
173 */
174#define kDifI2cIrqTxStretch kDtI2cIrqTxStretch
175 /**
176 * Target mode interrupt: asserted whilst the TX FIFO level is below the low threshold. This is a level status interrupt.
177 */
178#define kDifI2cIrqTxThreshold kDtI2cIrqTxThreshold
179 /**
180 * 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.
181 */
182#define kDifI2cIrqAcqStretch kDtI2cIrqAcqStretch
183 /**
184 * Target mode interrupt: raised if STOP is received without a preceding NACK during an external host read.
185 */
186#define kDifI2cIrqUnexpStop kDtI2cIrqUnexpStop
187 /**
188 * Target mode interrupt: raised if the host stops sending the clock during an ongoing transaction.
189 */
190#define kDifI2cIrqHostTimeout kDtI2cIrqHostTimeout
191
192 /**
193 * A snapshot of the state of the interrupts for this IP.
194 *
195 * This is an opaque type, to be used with the `dif_i2c_irq_get_state()`
196 * and `dif_i2c_irq_acknowledge_state()` functions.
197 */
199
200 /**
201 * Returns the type of a given interrupt (i.e., event or status) for this IP.
202 *
203 * @param i2c A i2c handle.
204 * @param irq An interrupt request.
205 * @param[out] type Out-param for the interrupt type.
206 * @return The result of the operation.
207 */
210 const dif_i2c_t *i2c,
211 dif_i2c_irq_t,
212 dif_irq_type_t *type);
213
214 /**
215 * Returns the state of all interrupts (i.e., pending or not) for this IP.
216 *
217 * @param i2c A i2c handle.
218 * @param[out] snapshot Out-param for interrupt state snapshot.
219 * @return The result of the operation.
220 */
223 const dif_i2c_t *i2c,
225
226 /**
227 * Returns whether a particular interrupt is currently pending.
228 *
229 * @param i2c A i2c handle.
230 * @param irq An interrupt request.
231 * @param[out] is_pending Out-param for whether the interrupt is pending.
232 * @return The result of the operation.
233 */
236 const dif_i2c_t *i2c,
237 dif_i2c_irq_t,
238 bool *is_pending);
239
240 /**
241 * Acknowledges all interrupts that were pending at the time of the state
242 * snapshot.
243 *
244 * @param i2c A i2c handle.
245 * @param snapshot Interrupt state snapshot.
246 * @return The result of the operation.
247 */
250 const dif_i2c_t *i2c,
252
253 /**
254 * Acknowledges all interrupts, indicating to the hardware that all
255 * interrupts have been successfully serviced.
256 *
257 * @param i2c A i2c handle.
258 * @return The result of the operation.
259 */
262 const dif_i2c_t *i2c
263 );
264
265 /**
266 * Acknowledges a particular interrupt, indicating to the hardware that it has
267 * been successfully serviced.
268 *
269 * @param i2c A i2c handle.
270 * @param irq An interrupt request.
271 * @return The result of the operation.
272 */
275 const dif_i2c_t *i2c,
276 dif_i2c_irq_t);
277
278 /**
279 * Forces a particular interrupt, causing it to be serviced as if hardware had
280 * asserted it.
281 *
282 * @param i2c A i2c handle.
283 * @param irq An interrupt request.
284 * @param val Value to be set.
285 * @return The result of the operation.
286 */
289 const dif_i2c_t *i2c,
290 dif_i2c_irq_t,
291 const bool val);
292
293 /**
294 * A snapshot of the enablement state of the interrupts for this IP.
295 *
296 * This is an opaque type, to be used with the
297 * `dif_i2c_irq_disable_all()` and `dif_i2c_irq_restore_all()`
298 * functions.
299 */
301
302 /**
303 * Checks whether a particular interrupt is currently enabled or disabled.
304 *
305 * @param i2c A i2c handle.
306 * @param irq An interrupt request.
307 * @param[out] state Out-param toggle state of the interrupt.
308 * @return The result of the operation.
309 */
312 const dif_i2c_t *i2c,
313 dif_i2c_irq_t,
314 dif_toggle_t *state);
315
316 /**
317 * Sets whether a particular interrupt is currently enabled or disabled.
318 *
319 * @param i2c A i2c handle.
320 * @param irq An interrupt request.
321 * @param state The new toggle state for the interrupt.
322 * @return The result of the operation.
323 */
326 const dif_i2c_t *i2c,
327 dif_i2c_irq_t,
328 dif_toggle_t state);
329
330 /**
331 * Disables all interrupts, optionally snapshotting all enable states for later
332 * restoration.
333 *
334 * @param i2c A i2c handle.
335 * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
336 * @return The result of the operation.
337 */
340 const dif_i2c_t *i2c,
342
343 /**
344 * Restores interrupts from the given (enable) snapshot.
345 *
346 * @param i2c A i2c handle.
347 * @param snapshot A snapshot to restore from.
348 * @return The result of the operation.
349 */
352 const dif_i2c_t *i2c,
353 const dif_i2c_irq_enable_snapshot_t *snapshot);
354
355
356#ifdef __cplusplus
357} // extern "C"
358#endif // __cplusplus
359
360#endif // OPENTITAN_SW_DEVICE_LIB_DIF_AUTOGEN_DIF_I2C_AUTOGEN_H_