Software APIs
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 "hw/top/dt/pwrmgr.h"
13
14
15#include "hw/top/dt/pinmux.h"
16#include "hw/top/dt/aon_timer.h"
17#include "hw/top/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 reg_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[3]; /**< 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 .reg_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 },
86 .rst_reqs = {
87 [0] = {
88 .inst_id = kDtInstanceIdAonTimerAon,
89 .reset_req = kDtAonTimerResetReqAonTimer,
90 },
91 [1] = {
92 .inst_id = kDtInstanceIdSocProxy,
93 .reset_req = kDtSocProxyResetReqExternal,
94 },
95 },
96 },
97 },
98};
99
100/**
101 * Return a pointer to the `dt_pwrmgr_desc_t` structure of the requested
102 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
103 * the function) with the provided default value.
104 */
105#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_pwrmgr_t)0 || (dt) >= kDtPwrmgrCount) return (default); &pwrmgr_desc[dt]; })
106
108 if (inst_id >= kDtInstanceIdPwrmgrAon && inst_id <= kDtInstanceIdPwrmgrAon) {
109 return (dt_pwrmgr_t)(inst_id - kDtInstanceIdPwrmgrAon);
110 }
111 return (dt_pwrmgr_t)0;
112}
113
118
120 dt_pwrmgr_t dt,
121 dt_pwrmgr_reg_block_t reg_block) {
122 // Return a recognizable address in case of wrong argument.
123 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
124}
125
127 dt_pwrmgr_t dt,
128 dt_pwrmgr_irq_t irq) {
129 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
130 if (first_irq == kDtPlicIrqIdNone) {
131 return kDtPlicIrqIdNone;
132 }
133 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
134}
135
137 dt_pwrmgr_t dt,
138 dt_plic_irq_id_t irq) {
139 dt_pwrmgr_irq_t count = kDtPwrmgrIrqCount;
140 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
141 if (first_irq == kDtPlicIrqIdNone) {
142 return count;
143 }
144 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
145 return count;
146 }
147 return (dt_pwrmgr_irq_t)(irq - first_irq);
148}
149
150
152 dt_pwrmgr_t dt,
153 dt_pwrmgr_alert_t alert) {
154 return (dt_alert_id_t)((uint32_t)pwrmgr_desc[dt].first_alert + (uint32_t)alert);
155}
156
158 dt_pwrmgr_t dt,
159 dt_alert_id_t alert) {
160 dt_pwrmgr_alert_t count = kDtPwrmgrAlertCount;
161 if (alert < pwrmgr_desc[dt].first_alert || alert >= pwrmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
162 return count;
163 }
164 return (dt_pwrmgr_alert_t)(alert - pwrmgr_desc[dt].first_alert);
165}
166
167
168
170 dt_pwrmgr_t dt,
171 dt_pwrmgr_clock_t clk) {
172 // Return the first clock in case of invalid argument.
173 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
174}
175
177 dt_pwrmgr_t dt,
178 dt_pwrmgr_reset_t rst) {
179 const dt_pwrmgr_reset_t count = kDtPwrmgrResetCount;
180 if (rst >= count) {
181 return kDtResetUnknown;
182 }
183 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
184}
185
186
187
189 return 3;
190}
191
193 dt_pwrmgr_wakeup_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .wakeup = 0};
194 return TRY_GET_DT(dt, invalid)->pwrmgr_ext.wakeup_src[idx];
195}
196
198 return 2;
199}
200
202 dt_pwrmgr_reset_req_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .reset_req = 0};
203 return TRY_GET_DT(dt, invalid)->pwrmgr_ext.rst_reqs[idx];
204}
205
206