Software APIs
dt_spi_device.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_device and top englishbreakfast.
10 */
11
12#include "hw/top/dt/dt_spi_device.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_spi_device {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtSpiDeviceRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtSpiDeviceMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtSpiDeviceMemoryCount]; /**< 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[kDtSpiDeviceClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtSpiDeviceResetCount]; /**< Reset signal connected to each reset port */
32 dt_periph_io_t periph_io[kDtSpiDevicePeriphIoCount]; /**< Description of each peripheral I/O */
34
35
36
37
38static const dt_desc_spi_device_t spi_device_desc[kDtSpiDeviceCount] = {
39 [kDtSpiDevice] = {
40 .inst_id = kDtInstanceIdSpiDevice,
41 .reg_addr = {
42 [kDtSpiDeviceRegBlockCore] = 0x40050000,
43 },
44 .mem_addr = {
45 },
46 .mem_size = {
47 },
49 .clock = {
51 },
52 .reset = {
54 },
55 .periph_io = {
56 [kDtSpiDevicePeriphIoSck] = {
57 .__internal = {
58 .type = kDtPeriphIoTypeDio,
59 .dir = kDtPeriphIoDirIn,
60 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSck,
61 .outsel_or_dt_pad = kDtPadSpiDeviceSck,
62 },
63 },
64 [kDtSpiDevicePeriphIoCsb] = {
65 .__internal = {
66 .type = kDtPeriphIoTypeDio,
67 .dir = kDtPeriphIoDirIn,
68 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceCsb,
69 .outsel_or_dt_pad = kDtPadSpiDeviceCsb,
70 },
71 },
72 [kDtSpiDevicePeriphIoTpmCsb] = {
73 .__internal = {
76 .periph_input_or_direct_pad = 0,
77 .outsel_or_dt_pad = 0,
78 },
79 },
80 [kDtSpiDevicePeriphIoSd0] = {
81 .__internal = {
82 .type = kDtPeriphIoTypeDio,
84 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd0,
85 .outsel_or_dt_pad = kDtPadSpiDeviceSd0,
86 },
87 },
88 [kDtSpiDevicePeriphIoSd1] = {
89 .__internal = {
90 .type = kDtPeriphIoTypeDio,
92 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd1,
93 .outsel_or_dt_pad = kDtPadSpiDeviceSd1,
94 },
95 },
96 [kDtSpiDevicePeriphIoSd2] = {
97 .__internal = {
98 .type = kDtPeriphIoTypeDio,
100 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd2,
101 .outsel_or_dt_pad = kDtPadSpiDeviceSd2,
102 },
103 },
104 [kDtSpiDevicePeriphIoSd3] = {
105 .__internal = {
106 .type = kDtPeriphIoTypeDio,
107 .dir = kDtPeriphIoDirInout,
108 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiDeviceSd3,
109 .outsel_or_dt_pad = kDtPadSpiDeviceSd3,
110 },
111 },
112 },
113 },
114};
115
116/**
117 * Return a pointer to the `dt_spi_device_desc_t` structure of the requested
118 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
119 * the function) with the provided default value.
120 */
121#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_spi_device_t)0 || (dt) >= kDtSpiDeviceCount) return (default); &spi_device_desc[dt]; })
122
129
134
137 dt_spi_device_reg_block_t reg_block) {
138 // Return a recognizable address in case of wrong argument.
139 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
140}
141
145 // Return a recognizable address in case of wrong argument.
146 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
147}
148
152 // Return an empty size in case of wrong argument.
153 return TRY_GET_DT(dt, 0)->mem_size[mem];
154}
155
159 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
160 if (first_irq == kDtPlicIrqIdNone) {
161 return kDtPlicIrqIdNone;
162 }
163 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
164}
165
168 dt_plic_irq_id_t irq) {
169 dt_spi_device_irq_t count = kDtSpiDeviceIrqCount;
170 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
171 if (first_irq == kDtPlicIrqIdNone) {
172 return count;
173 }
174 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
175 return count;
176 }
177 return (dt_spi_device_irq_t)(irq - first_irq);
178}
179
180
181
185 // Return a harmless value in case of wrong argument.
186 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
187}
188
192 // Return the first clock in case of invalid argument.
193 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
194}
195
199 const dt_spi_device_reset_t count = kDtSpiDeviceResetCount;
200 if (rst >= count) {
201 return kDtResetUnknown;
202 }
203 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
204}
205
206