Software APIs
dt_pwrmgr.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 pwrmgr and top darjeeling.
10 */
11
12#include "dt/dt_pwrmgr.h"
13
14#include "dt_pinmux.h"
15#include "dt_aon_timer.h"
16#include "dt_soc_proxy.h"
17
18
19/**
20 * Description of instances.
21 */
22typedef struct dt_desc_pwrmgr {
23 dt_instance_id_t inst_id; /**< Instance ID */
24 uint32_t base_addr[kDtPwrmgrRegBlockCount]; /**< Base address of each register block */
25 /**
26 * PLIC ID of the first IRQ of this instance
27 *
28 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
29 */
31 /**
32 * Alert ID of the first Alert of this instance.
33 *
34 * This value is undefined if the block is not connected to the Alert Handler.
35 */
37 dt_clock_t clock[kDtPwrmgrClockCount]; /**< Clock signal connected to each clock port */
38 dt_reset_t reset[kDtPwrmgrResetCount]; /**< Reset signal connected to each reset port */
39 struct {
40 dt_pwrmgr_wakeup_src_t wakeup_src[4]; /**< List of wakeup sources, in the order of the register fields */
41 dt_pwrmgr_reset_req_src_t rst_reqs[2]; /**< List of reset requests, in the order of the register fields */
42 } ext; /**< Extension */
44
45
46
47
48static const dt_desc_pwrmgr_t pwrmgr_desc[kDtPwrmgrCount] = {
49 [kDtPwrmgrAon] = {
50 .inst_id = kDtInstanceIdPwrmgrAon,
51 .base_addr = {
52 [kDtPwrmgrRegBlockCore] = 0x30400000,
53 },
56 .clock = {
61 },
62 .reset = {
68 },
69 .ext = {
70 .wakeup_src = {
71 [0] = {
72 .inst_id = kDtInstanceIdPinmuxAon,
74 },
75 [1] = {
76 .inst_id = kDtInstanceIdAonTimerAon,
78 },
79 [2] = {
80 .inst_id = kDtInstanceIdSocProxy,
82 },
83 [3] = {
84 .inst_id = kDtInstanceIdSocProxy,
86 },
87 },
88 .rst_reqs = {
89 [0] = {
90 .inst_id = kDtInstanceIdAonTimerAon,
91 .reset_req = kDtAonTimerResetReqAonTimer,
92 },
93 [1] = {
94 .inst_id = kDtInstanceIdSocProxy,
95 .reset_req = kDtSocProxyResetReqExternal,
96 },
97 },
98 },
99 },
100};
101
102/**
103 * Return a pointer to the `dt_pwrmgr_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_pwrmgr_t)0 || (dt) >= kDtPwrmgrCount) return (default); &pwrmgr_desc[dt]; })
108
110 if (inst_id >= kDtInstanceIdPwrmgrAon && inst_id <= kDtInstanceIdPwrmgrAon) {
111 return (dt_pwrmgr_t)(inst_id - kDtInstanceIdPwrmgrAon);
112 }
113 return (dt_pwrmgr_t)0;
114}
115
120
122 dt_pwrmgr_t dt,
123 dt_pwrmgr_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_pwrmgr_t dt,
130 dt_pwrmgr_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_pwrmgr_t dt,
140 dt_plic_irq_id_t irq) {
141 dt_pwrmgr_irq_t count = kDtPwrmgrIrqCount;
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_pwrmgr_irq_t)(irq - first_irq);
150}
151
152
154 dt_pwrmgr_t dt,
155 dt_pwrmgr_alert_t alert) {
156 return (dt_alert_id_t)((uint32_t)pwrmgr_desc[dt].first_alert + (uint32_t)alert);
157}
158
160 dt_pwrmgr_t dt,
161 dt_alert_id_t alert) {
162 dt_pwrmgr_alert_t count = kDtPwrmgrAlertCount;
163 if (alert < pwrmgr_desc[dt].first_alert || alert >= pwrmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
164 return count;
165 }
166 return (dt_pwrmgr_alert_t)(alert - pwrmgr_desc[dt].first_alert);
167}
168
169
170
172 dt_pwrmgr_t dt,
173 dt_pwrmgr_clock_t clk) {
174 // Return the first clock in case of invalid argument.
175 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
176}
177
179 dt_pwrmgr_t dt,
180 dt_pwrmgr_reset_t rst) {
181 const dt_pwrmgr_reset_t count = kDtPwrmgrResetCount;
182 if (rst >= count) {
183 return kDtResetUnknown;
184 }
185 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
186}
187
188
190 return 4;
191}
192
194 dt_pwrmgr_wakeup_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .wakeup = 0};
195 return TRY_GET_DT(dt, invalid)->ext.wakeup_src[idx];
196}
197
199 return 2;
200}
201
203 dt_pwrmgr_reset_req_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .reset_req = 0};
204 return TRY_GET_DT(dt, invalid)->ext.rst_reqs[idx];
205}
206