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 englishbreakfast.
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 dt_clock_t clock[kDtSpiHostClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtSpiHostResetCount]; /**< Reset signal connected to each reset port */
32 dt_periph_io_t periph_io[kDtSpiHostPeriphIoCount]; /**< Description of each peripheral I/O */
34
35
36
37
38static const dt_desc_spi_host_t spi_host_desc[kDtSpiHostCount] = {
39 [kDtSpiHost0] = {
40 .inst_id = kDtInstanceIdSpiHost0,
41 .reg_addr = {
42 [kDtSpiHostRegBlockCore] = 0x40060000,
43 },
44 .mem_addr = {
45 },
46 .mem_size = {
47 },
49 .clock = {
51 },
52 .reset = {
54 },
55 .periph_io = {
56 [kDtSpiHostPeriphIoSck] = {
57 .__internal = {
58 .type = kDtPeriphIoTypeDio,
59 .dir = kDtPeriphIoDirOut,
60 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sck,
61 .outsel_or_dt_pad = kDtPadSpiHost0Sck,
62 },
63 },
64 [kDtSpiHostPeriphIoCsb] = {
65 .__internal = {
66 .type = kDtPeriphIoTypeDio,
67 .dir = kDtPeriphIoDirOut,
68 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Csb,
69 .outsel_or_dt_pad = kDtPadSpiHost0Csb,
70 },
71 },
72 [kDtSpiHostPeriphIoSd0] = {
73 .__internal = {
74 .type = kDtPeriphIoTypeDio,
76 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd0,
77 .outsel_or_dt_pad = kDtPadSpiHost0Sd0,
78 },
79 },
80 [kDtSpiHostPeriphIoSd1] = {
81 .__internal = {
82 .type = kDtPeriphIoTypeDio,
84 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd1,
85 .outsel_or_dt_pad = kDtPadSpiHost0Sd1,
86 },
87 },
88 [kDtSpiHostPeriphIoSd2] = {
89 .__internal = {
90 .type = kDtPeriphIoTypeDio,
92 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd2,
93 .outsel_or_dt_pad = kDtPadSpiHost0Sd2,
94 },
95 },
96 [kDtSpiHostPeriphIoSd3] = {
97 .__internal = {
98 .type = kDtPeriphIoTypeDio,
100 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd3,
101 .outsel_or_dt_pad = kDtPadSpiHost0Sd3,
102 },
103 },
104 },
105 },
106};
107
108/**
109 * Return a pointer to the `dt_spi_host_desc_t` structure of the requested
110 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
111 * the function) with the provided default value.
112 */
113#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_spi_host_t)0 || (dt) >= kDtSpiHostCount) return (default); &spi_host_desc[dt]; })
114
116 if (inst_id >= kDtInstanceIdSpiHost0 && inst_id <= kDtInstanceIdSpiHost0) {
117 return (dt_spi_host_t)(inst_id - kDtInstanceIdSpiHost0);
118 }
119 return (dt_spi_host_t)0;
120}
121
126
128 dt_spi_host_t dt,
129 dt_spi_host_reg_block_t reg_block) {
130 // Return a recognizable address in case of wrong argument.
131 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
132}
133
135 dt_spi_host_t dt,
137 // Return a recognizable address in case of wrong argument.
138 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
139}
140
142 dt_spi_host_t dt,
144 // Return an empty size in case of wrong argument.
145 return TRY_GET_DT(dt, 0)->mem_size[mem];
146}
147
149 dt_spi_host_t dt,
150 dt_spi_host_irq_t irq) {
151 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
152 if (first_irq == kDtPlicIrqIdNone) {
153 return kDtPlicIrqIdNone;
154 }
155 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
156}
157
159 dt_spi_host_t dt,
160 dt_plic_irq_id_t irq) {
161 dt_spi_host_irq_t count = kDtSpiHostIrqCount;
162 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
163 if (first_irq == kDtPlicIrqIdNone) {
164 return count;
165 }
166 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
167 return count;
168 }
169 return (dt_spi_host_irq_t)(irq - first_irq);
170}
171
172
173
175 dt_spi_host_t dt,
177 // Return a harmless value in case of wrong argument.
178 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
179}
180
182 dt_spi_host_t dt,
184 // Return the first clock in case of invalid argument.
185 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
186}
187
189 dt_spi_host_t dt,
191 const dt_spi_host_reset_t count = kDtSpiHostResetCount;
192 if (rst >= count) {
193 return kDtResetUnknown;
194 }
195 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
196}
197
198