Software APIs
dt_spi_host.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 spi_host and top darjeeling.
10 */
11
12#include "hw/top/dt/dt_spi_host.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_spi_host {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtSpiHostRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtSpiHostMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtSpiHostMemoryCount]; /**< Size in bytes of each memory */
24 /**
25 * PLIC ID of the first IRQ of this instance
26 *
27 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
28 */
30 /**
31 * Alert ID of the first Alert of this instance.
32 *
33 * This value is undefined if the block is not connected to the Alert Handler.
34 */
36 dt_clock_t clock[kDtSpiHostClockCount]; /**< Clock signal connected to each clock port */
37 dt_reset_t reset[kDtSpiHostResetCount]; /**< Reset signal connected to each reset port */
38 dt_periph_io_t periph_io[kDtSpiHostPeriphIoCount]; /**< Description of each peripheral I/O */
40
41
42
43
44static const dt_desc_spi_host_t spi_host_desc[kDtSpiHostCount] = {
45 [kDtSpiHost0] = {
46 .inst_id = kDtInstanceIdSpiHost0,
47 .reg_addr = {
48 [kDtSpiHostRegBlockCore] = 0x30300000,
49 },
50 .mem_addr = {
51 },
52 .mem_size = {
53 },
56 .clock = {
58 },
59 .reset = {
61 },
62 .periph_io = {
63 [kDtSpiHostPeriphIoSck] = {
64 .__internal = {
65 .type = kDtPeriphIoTypeDio,
66 .dir = kDtPeriphIoDirOut,
67 .periph_input_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Sck,
68 .outsel_or_dt_pad = kDtPadSpiHost0Sck,
69 },
70 },
71 [kDtSpiHostPeriphIoCsb] = {
72 .__internal = {
73 .type = kDtPeriphIoTypeDio,
74 .dir = kDtPeriphIoDirOut,
75 .periph_input_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Csb,
76 .outsel_or_dt_pad = kDtPadSpiHost0Csb,
77 },
78 },
79 [kDtSpiHostPeriphIoSd0] = {
80 .__internal = {
81 .type = kDtPeriphIoTypeDio,
83 .periph_input_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Sd0,
84 .outsel_or_dt_pad = kDtPadSpiHost0Sd0,
85 },
86 },
87 [kDtSpiHostPeriphIoSd1] = {
88 .__internal = {
89 .type = kDtPeriphIoTypeDio,
91 .periph_input_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Sd1,
92 .outsel_or_dt_pad = kDtPadSpiHost0Sd1,
93 },
94 },
95 [kDtSpiHostPeriphIoSd2] = {
96 .__internal = {
97 .type = kDtPeriphIoTypeDio,
99 .periph_input_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Sd2,
100 .outsel_or_dt_pad = kDtPadSpiHost0Sd2,
101 },
102 },
103 [kDtSpiHostPeriphIoSd3] = {
104 .__internal = {
105 .type = kDtPeriphIoTypeDio,
106 .dir = kDtPeriphIoDirInout,
107 .periph_input_or_direct_pad = kTopDarjeelingDirectPadsSpiHost0Sd3,
108 .outsel_or_dt_pad = kDtPadSpiHost0Sd3,
109 },
110 },
111 },
112 },
113};
114
115/**
116 * Return a pointer to the `dt_spi_host_desc_t` structure of the requested
117 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
118 * the function) with the provided default value.
119 */
120#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_spi_host_t)0 || (dt) >= kDtSpiHostCount) return (default); &spi_host_desc[dt]; })
121
123 if (inst_id >= kDtInstanceIdSpiHost0 && inst_id <= kDtInstanceIdSpiHost0) {
124 return (dt_spi_host_t)(inst_id - kDtInstanceIdSpiHost0);
125 }
126 return (dt_spi_host_t)0;
127}
128
133
135 dt_spi_host_t dt,
136 dt_spi_host_reg_block_t reg_block) {
137 // Return a recognizable address in case of wrong argument.
138 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
139}
140
142 dt_spi_host_t dt,
144 // Return a recognizable address in case of wrong argument.
145 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
146}
147
149 dt_spi_host_t dt,
151 // Return an empty size in case of wrong argument.
152 return TRY_GET_DT(dt, 0)->mem_size[mem];
153}
154
156 dt_spi_host_t dt,
157 dt_spi_host_irq_t irq) {
158 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
159 if (first_irq == kDtPlicIrqIdNone) {
160 return kDtPlicIrqIdNone;
161 }
162 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
163}
164
166 dt_spi_host_t dt,
167 dt_plic_irq_id_t irq) {
168 dt_spi_host_irq_t count = kDtSpiHostIrqCount;
169 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
170 if (first_irq == kDtPlicIrqIdNone) {
171 return count;
172 }
173 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
174 return count;
175 }
176 return (dt_spi_host_irq_t)(irq - first_irq);
177}
178
179
181 dt_spi_host_t dt,
182 dt_spi_host_alert_t alert) {
183 return (dt_alert_id_t)((uint32_t)spi_host_desc[dt].first_alert + (uint32_t)alert);
184}
185
187 dt_spi_host_t dt,
188 dt_alert_id_t alert) {
189 dt_spi_host_alert_t count = kDtSpiHostAlertCount;
190 if (alert < spi_host_desc[dt].first_alert || alert >= spi_host_desc[dt].first_alert + (dt_alert_id_t)count) {
191 return count;
192 }
193 return (dt_spi_host_alert_t)(alert - spi_host_desc[dt].first_alert);
194}
195
196
198 dt_spi_host_t dt,
200 // Return a harmless value in case of wrong argument.
201 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
202}
203
205 dt_spi_host_t dt,
207 // Return the first clock in case of invalid argument.
208 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
209}
210
212 dt_spi_host_t dt,
214 const dt_spi_host_reset_t count = kDtSpiHostResetCount;
215 if (rst >= count) {
216 return kDtResetUnknown;
217 }
218 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
219}
220
221