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
15#include "dt_pinmux.h"
16#include "dt_aon_timer.h"
17#include "dt_soc_proxy.h"
18
19
20
21/**
22 * Description of instances.
23 */
24typedef struct dt_desc_pwrmgr {
25 dt_instance_id_t inst_id; /**< Instance ID */
26 uint32_t base_addr[kDtPwrmgrRegBlockCount]; /**< Base address of each register block */
27 /**
28 * PLIC ID of the first IRQ of this instance
29 *
30 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
31 */
33 /**
34 * Alert ID of the first Alert of this instance.
35 *
36 * This value is undefined if the block is not connected to the Alert Handler.
37 */
39 dt_clock_t clock[kDtPwrmgrClockCount]; /**< Clock signal connected to each clock port */
40 dt_reset_t reset[kDtPwrmgrResetCount]; /**< Reset signal connected to each reset port */
41 struct {
42 dt_pwrmgr_wakeup_src_t wakeup_src[4]; /**< List of wakeup sources, in the order of the register fields */
43 dt_pwrmgr_reset_req_src_t rst_reqs[2]; /**< List of reset requests, in the order of the register fields */
44 } pwrmgr_ext; /**< Extension */
46
47
48
49
50static const dt_desc_pwrmgr_t pwrmgr_desc[kDtPwrmgrCount] = {
51 [kDtPwrmgrAon] = {
52 .inst_id = kDtInstanceIdPwrmgrAon,
53 .base_addr = {
54 [kDtPwrmgrRegBlockCore] = 0x30400000,
55 },
58 .clock = {
63 },
64 .reset = {
70 },
71 .pwrmgr_ext = {
72 .wakeup_src = {
73 [0] = {
74 .inst_id = kDtInstanceIdPinmuxAon,
76 },
77 [1] = {
78 .inst_id = kDtInstanceIdAonTimerAon,
80 },
81 [2] = {
82 .inst_id = kDtInstanceIdSocProxy,
84 },
85 [3] = {
86 .inst_id = kDtInstanceIdSocProxy,
88 },
89 },
90 .rst_reqs = {
91 [0] = {
92 .inst_id = kDtInstanceIdAonTimerAon,
93 .reset_req = kDtAonTimerResetReqAonTimer,
94 },
95 [1] = {
96 .inst_id = kDtInstanceIdSocProxy,
97 .reset_req = kDtSocProxyResetReqExternal,
98 },
99 },
100 },
101 },
102};
103
104/**
105 * Return a pointer to the `dt_pwrmgr_desc_t` structure of the requested
106 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
107 * the function) with the provided default value.
108 */
109#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_pwrmgr_t)0 || (dt) >= kDtPwrmgrCount) return (default); &pwrmgr_desc[dt]; })
110
112 if (inst_id >= kDtInstanceIdPwrmgrAon && inst_id <= kDtInstanceIdPwrmgrAon) {
113 return (dt_pwrmgr_t)(inst_id - kDtInstanceIdPwrmgrAon);
114 }
115 return (dt_pwrmgr_t)0;
116}
117
122
124 dt_pwrmgr_t dt,
125 dt_pwrmgr_reg_block_t reg_block) {
126 // Return a recognizable address in case of wrong argument.
127 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
128}
129
131 dt_pwrmgr_t dt,
132 dt_pwrmgr_irq_t irq) {
133 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
134 if (first_irq == kDtPlicIrqIdNone) {
135 return kDtPlicIrqIdNone;
136 }
137 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
138}
139
141 dt_pwrmgr_t dt,
142 dt_plic_irq_id_t irq) {
143 dt_pwrmgr_irq_t count = kDtPwrmgrIrqCount;
144 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
145 if (first_irq == kDtPlicIrqIdNone) {
146 return count;
147 }
148 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
149 return count;
150 }
151 return (dt_pwrmgr_irq_t)(irq - first_irq);
152}
153
154
156 dt_pwrmgr_t dt,
157 dt_pwrmgr_alert_t alert) {
158 return (dt_alert_id_t)((uint32_t)pwrmgr_desc[dt].first_alert + (uint32_t)alert);
159}
160
162 dt_pwrmgr_t dt,
163 dt_alert_id_t alert) {
164 dt_pwrmgr_alert_t count = kDtPwrmgrAlertCount;
165 if (alert < pwrmgr_desc[dt].first_alert || alert >= pwrmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
166 return count;
167 }
168 return (dt_pwrmgr_alert_t)(alert - pwrmgr_desc[dt].first_alert);
169}
170
171
172
174 dt_pwrmgr_t dt,
175 dt_pwrmgr_clock_t clk) {
176 // Return the first clock in case of invalid argument.
177 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
178}
179
181 dt_pwrmgr_t dt,
182 dt_pwrmgr_reset_t rst) {
183 const dt_pwrmgr_reset_t count = kDtPwrmgrResetCount;
184 if (rst >= count) {
185 return kDtResetUnknown;
186 }
187 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
188}
189
190
191
193 return 4;
194}
195
197 dt_pwrmgr_wakeup_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .wakeup = 0};
198 return TRY_GET_DT(dt, invalid)->pwrmgr_ext.wakeup_src[idx];
199}
200
202 return 2;
203}
204
206 dt_pwrmgr_reset_req_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .reset_req = 0};
207 return TRY_GET_DT(dt, invalid)->pwrmgr_ext.rst_reqs[idx];
208}
209
210