Software APIs
i3c.c
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/**
8 * @file
9 * @brief Device Tables (DT) for IP i3c and top earlgrey.
10 */
11
12#include "hw/top/dt/i3c.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_i3c {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtI3cRegBlockCount]; /**< Base address of each register block */
22 /**
23 * PLIC ID of the first IRQ of this instance
24 *
25 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
26 */
28 /**
29 * Alert ID of the first Alert of this instance.
30 *
31 * This value is undefined if the block is not connected to the Alert Handler.
32 */
34 dt_clock_t clock[kDtI3cClockCount]; /**< Clock signal connected to each clock port */
35 dt_reset_t reset[kDtI3cResetCount]; /**< Reset signal connected to each reset port */
36 dt_periph_io_t periph_io[kDtI3cPeriphIoCount]; /**< Description of each peripheral I/O */
38
39
40
41
42static const dt_desc_i3c_t i3c_desc[kDtI3cCount] = {
43 [kDtI3c0] = {
44 .inst_id = kDtInstanceIdI3c0,
45 .reg_addr = {
46 [kDtI3cRegBlockCore] = 0x40330000,
47 },
50 .clock = {
53 },
54 .reset = {
57 },
58 .periph_io = {
59 [kDtI3cPeriphIoRstdetScl] = {
60 .__internal = {
61 .type = kDtPeriphIoTypeMio,
62 .dir = kDtPeriphIoDirIn,
63 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInI3c0RstdetScl,
64 .outsel_or_dt_pad = 0,
65 },
66 },
67 [kDtI3cPeriphIoRstdetSda] = {
68 .__internal = {
69 .type = kDtPeriphIoTypeMio,
70 .dir = kDtPeriphIoDirIn,
71 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInI3c0RstdetSda,
72 .outsel_or_dt_pad = 0,
73 },
74 },
75 [kDtI3cPeriphIoCtrlSdaPu] = {
76 .__internal = {
77 .type = kDtPeriphIoTypeMio,
78 .dir = kDtPeriphIoDirOut,
79 .periph_input_or_direct_pad = 0,
80 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselI3c0CtrlSdaPu,
81 },
82 },
83 [kDtI3cPeriphIoScl] = {
84 .__internal = {
85 .type = kDtPeriphIoTypeMio,
87 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInI3c0Scl,
88 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselI3c0Scl,
89 },
90 },
91 [kDtI3cPeriphIoSda] = {
92 .__internal = {
93 .type = kDtPeriphIoTypeMio,
95 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInI3c0Sda,
96 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselI3c0Sda,
97 },
98 },
99 },
100 },
101 [kDtI3c1] = {
102 .inst_id = kDtInstanceIdI3c1,
103 .reg_addr = {
104 [kDtI3cRegBlockCore] = 0x40340000,
105 },
106 .first_irq = kTopEarlgreyPlicIrqIdI3c1Hci,
108 .clock = {
111 },
112 .reset = {
115 },
116 .periph_io = {
117 [kDtI3cPeriphIoRstdetScl] = {
118 .__internal = {
119 .type = kDtPeriphIoTypeMio,
120 .dir = kDtPeriphIoDirIn,
121 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInI3c1RstdetScl,
122 .outsel_or_dt_pad = 0,
123 },
124 },
125 [kDtI3cPeriphIoRstdetSda] = {
126 .__internal = {
127 .type = kDtPeriphIoTypeMio,
128 .dir = kDtPeriphIoDirIn,
129 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInI3c1RstdetSda,
130 .outsel_or_dt_pad = 0,
131 },
132 },
133 [kDtI3cPeriphIoCtrlSdaPu] = {
134 .__internal = {
135 .type = kDtPeriphIoTypeMio,
136 .dir = kDtPeriphIoDirOut,
137 .periph_input_or_direct_pad = 0,
138 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselI3c1CtrlSdaPu,
139 },
140 },
141 [kDtI3cPeriphIoScl] = {
142 .__internal = {
143 .type = kDtPeriphIoTypeMio,
144 .dir = kDtPeriphIoDirInout,
145 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInI3c1Scl,
146 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselI3c1Scl,
147 },
148 },
149 [kDtI3cPeriphIoSda] = {
150 .__internal = {
151 .type = kDtPeriphIoTypeMio,
152 .dir = kDtPeriphIoDirInout,
153 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInI3c1Sda,
154 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselI3c1Sda,
155 },
156 },
157 },
158 },
159};
160
161/**
162 * Return a pointer to the `dt_i3c_desc_t` structure of the requested
163 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
164 * the function) with the provided default value.
165 */
166#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_i3c_t)0 || (int)(dt) >= kDtI3cCount) return (default); &i3c_desc[dt]; })
167
169 if (inst_id >= kDtInstanceIdI3c0 && inst_id <= kDtInstanceIdI3c1) {
170 return (dt_i3c_t)(inst_id - kDtInstanceIdI3c0);
171 }
172 return (dt_i3c_t)0;
173}
174
179
181 dt_i3c_t dt,
182 dt_i3c_reg_block_t reg_block) {
183 // Return a recognizable address in case of wrong argument.
184 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
185}
186
188 dt_i3c_t dt,
189 dt_i3c_irq_t irq) {
190 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
191 if (first_irq == kDtPlicIrqIdNone) {
192 return kDtPlicIrqIdNone;
193 }
194 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
195}
196
198 dt_i3c_t dt,
199 dt_plic_irq_id_t irq) {
201 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
202 if (first_irq == kDtPlicIrqIdNone) {
203 return count;
204 }
205 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
206 return count;
207 }
208 return (dt_i3c_irq_t)(irq - first_irq);
209}
210
211
213 dt_i3c_t dt,
214 dt_i3c_alert_t alert) {
215 return (dt_alert_id_t)((uint32_t)i3c_desc[dt].first_alert + (uint32_t)alert);
216}
217
219 dt_i3c_t dt,
220 dt_alert_id_t alert) {
222 if (alert < i3c_desc[dt].first_alert || alert >= i3c_desc[dt].first_alert + (dt_alert_id_t)count) {
223 return count;
224 }
225 return (dt_i3c_alert_t)(alert - i3c_desc[dt].first_alert);
226}
227
228
230 dt_i3c_t dt,
231 dt_i3c_periph_io_t sig) {
232 // Return a harmless value in case of wrong argument.
233 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
234}
235
237 dt_i3c_t dt,
238 dt_i3c_clock_t clk) {
239 // Return the first clock in case of invalid argument.
240 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
241}
242
244 dt_i3c_t dt,
245 dt_i3c_reset_t rst) {
246 const dt_i3c_reset_t count = kDtI3cResetCount;
247 if (rst >= count) {
248 return kDtResetUnknown;
249 }
250 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
251}
252
253