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 "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 base_addr[kDtSpiHostRegBlockCount]; /**< 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 dt_clock_t clock[kDtSpiHostClockCount]; /**< Clock signal connected to each clock port */
29 dt_reset_t reset[kDtSpiHostResetCount]; /**< Reset signal connected to each reset port */
30 dt_periph_io_t periph_io[kDtSpiHostPeriphIoCount]; /**< Description of each peripheral I/O */
32
33
34
35
36static const dt_desc_spi_host_t spi_host_desc[kDtSpiHostCount] = {
37 [kDtSpiHost0] = {
38 .inst_id = kDtInstanceIdSpiHost0,
39 .base_addr = {
40 [kDtSpiHostRegBlockCore] = 0x40060000,
41 },
43 .clock = {
45 },
46 .reset = {
48 },
49 .periph_io = {
50 [kDtSpiHostPeriphIoSck] = {
51 .__internal = {
52 .type = kDtPeriphIoTypeDio,
53 .dir = kDtPeriphIoDirOut,
54 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sck,
55 .outsel_or_dt_pad = kDtPadSpiHost0Sck,
56 },
57 },
58 [kDtSpiHostPeriphIoCsb] = {
59 .__internal = {
60 .type = kDtPeriphIoTypeDio,
61 .dir = kDtPeriphIoDirOut,
62 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Csb,
63 .outsel_or_dt_pad = kDtPadSpiHost0Csb,
64 },
65 },
66 [kDtSpiHostPeriphIoSd0] = {
67 .__internal = {
68 .type = kDtPeriphIoTypeDio,
70 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd0,
71 .outsel_or_dt_pad = kDtPadSpiHost0Sd0,
72 },
73 },
74 [kDtSpiHostPeriphIoSd1] = {
75 .__internal = {
76 .type = kDtPeriphIoTypeDio,
78 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd1,
79 .outsel_or_dt_pad = kDtPadSpiHost0Sd1,
80 },
81 },
82 [kDtSpiHostPeriphIoSd2] = {
83 .__internal = {
84 .type = kDtPeriphIoTypeDio,
86 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd2,
87 .outsel_or_dt_pad = kDtPadSpiHost0Sd2,
88 },
89 },
90 [kDtSpiHostPeriphIoSd3] = {
91 .__internal = {
92 .type = kDtPeriphIoTypeDio,
94 .periph_input_or_direct_pad = kTopEnglishbreakfastDirectPadsSpiHost0Sd3,
95 .outsel_or_dt_pad = kDtPadSpiHost0Sd3,
96 },
97 },
98 },
99 },
100};
101
102/**
103 * Return a pointer to the `dt_spi_host_desc_t` structure of the requested
104 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
105 * the function) with the provided default value.
106 */
107#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_spi_host_t)0 || (dt) >= kDtSpiHostCount) return (default); &spi_host_desc[dt]; })
108
110 if (inst_id >= kDtInstanceIdSpiHost0 && inst_id <= kDtInstanceIdSpiHost0) {
111 return (dt_spi_host_t)(inst_id - kDtInstanceIdSpiHost0);
112 }
113 return (dt_spi_host_t)0;
114}
115
120
122 dt_spi_host_t dt,
123 dt_spi_host_reg_block_t reg_block) {
124 // Return a recognizable address in case of wrong argument.
125 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
126}
127
129 dt_spi_host_t dt,
130 dt_spi_host_irq_t irq) {
131 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
132 if (first_irq == kDtPlicIrqIdNone) {
133 return kDtPlicIrqIdNone;
134 }
135 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
136}
137
139 dt_spi_host_t dt,
140 dt_plic_irq_id_t irq) {
141 dt_spi_host_irq_t count = kDtSpiHostIrqCount;
142 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
143 if (first_irq == kDtPlicIrqIdNone) {
144 return count;
145 }
146 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
147 return count;
148 }
149 return (dt_spi_host_irq_t)(irq - first_irq);
150}
151
152
153
155 dt_spi_host_t dt,
157 // Return a harmless value in case of wrong argument.
158 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
159}
160
162 dt_spi_host_t dt,
164 // Return the first clock in case of invalid argument.
165 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
166}
167
169 dt_spi_host_t dt,
171 const dt_spi_host_reset_t count = kDtSpiHostResetCount;
172 if (rst >= count) {
173 return kDtResetUnknown;
174 }
175 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
176}
177
178