Software APIs
dt_flash_ctrl.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 flash_ctrl and top earlgrey.
10 */
11
12#include "dt/dt_flash_ctrl.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_flash_ctrl {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t base_addr[kDtFlashCtrlRegBlockCount]; /**< 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[kDtFlashCtrlClockCount]; /**< Clock signal connected to each clock port */
35 dt_reset_t reset[kDtFlashCtrlResetCount]; /**< Reset signal connected to each reset port */
36 dt_periph_io_t periph_io[kDtFlashCtrlPeriphIoCount]; /**< Description of each peripheral I/O */
38
39
40
41
42static const dt_desc_flash_ctrl_t flash_ctrl_desc[kDtFlashCtrlCount] = {
43 [kDtFlashCtrl] = {
44 .inst_id = kDtInstanceIdFlashCtrl,
45 .base_addr = {
46 [kDtFlashCtrlRegBlockCore] = 0x41000000,
47 [kDtFlashCtrlRegBlockPrim] = 0x41008000,
48 [kDtFlashCtrlRegBlockMem] = 0x20000000,
49 },
52 .clock = {
55 },
56 .reset = {
59 },
60 .periph_io = {
61 [kDtFlashCtrlPeriphIoTck] = {
62 .__internal = {
63 .type = kDtPeriphIoTypeMio,
64 .dir = kDtPeriphIoDirIn,
65 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInFlashCtrlTck,
66 .outsel_or_dt_pad = 0,
67 },
68 },
69 [kDtFlashCtrlPeriphIoTms] = {
70 .__internal = {
71 .type = kDtPeriphIoTypeMio,
72 .dir = kDtPeriphIoDirIn,
73 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInFlashCtrlTms,
74 .outsel_or_dt_pad = 0,
75 },
76 },
77 [kDtFlashCtrlPeriphIoTdi] = {
78 .__internal = {
79 .type = kDtPeriphIoTypeMio,
80 .dir = kDtPeriphIoDirIn,
81 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInFlashCtrlTdi,
82 .outsel_or_dt_pad = 0,
83 },
84 },
85 [kDtFlashCtrlPeriphIoTdo] = {
86 .__internal = {
87 .type = kDtPeriphIoTypeMio,
88 .dir = kDtPeriphIoDirOut,
89 .periph_input_or_direct_pad = 0,
90 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselFlashCtrlTdo,
91 },
92 },
93 },
94 },
95};
96
97/**
98 * Return a pointer to the `dt_flash_ctrl_desc_t` structure of the requested
99 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
100 * the function) with the provided default value.
101 */
102#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_flash_ctrl_t)0 || (dt) >= kDtFlashCtrlCount) return (default); &flash_ctrl_desc[dt]; })
103
110
115
118 dt_flash_ctrl_reg_block_t reg_block) {
119 // Return a recognizable address in case of wrong argument.
120 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
121}
122
126 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
127 if (first_irq == kDtPlicIrqIdNone) {
128 return kDtPlicIrqIdNone;
129 }
130 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
131}
132
135 dt_plic_irq_id_t irq) {
136 dt_flash_ctrl_irq_t count = kDtFlashCtrlIrqCount;
137 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
138 if (first_irq == kDtPlicIrqIdNone) {
139 return count;
140 }
141 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
142 return count;
143 }
144 return (dt_flash_ctrl_irq_t)(irq - first_irq);
145}
146
147
150 dt_flash_ctrl_alert_t alert) {
151 return (dt_alert_id_t)((uint32_t)flash_ctrl_desc[dt].first_alert + (uint32_t)alert);
152}
153
156 dt_alert_id_t alert) {
157 dt_flash_ctrl_alert_t count = kDtFlashCtrlAlertCount;
158 if (alert < flash_ctrl_desc[dt].first_alert || alert >= flash_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
159 return count;
160 }
161 return (dt_flash_ctrl_alert_t)(alert - flash_ctrl_desc[dt].first_alert);
162}
163
164
168 // Return a harmless value in case of wrong argument.
169 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
170}
171
175 // Return the first clock in case of invalid argument.
176 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
177}
178
182 const dt_flash_ctrl_reset_t count = kDtFlashCtrlResetCount;
183 if (rst >= count) {
184 return kDtResetUnknown;
185 }
186 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
187}
188
189