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 earlgrey.
10 */
11
12#include "hw/top/dt/pwrmgr.h"
13
14
15#include "hw/top/dt/i3c.h"
17#include "hw/top/dt/adc_ctrl.h"
18#include "hw/top/dt/pinmux.h"
19#include "hw/top/dt/aon_timer.h"
21
22
23
24/**
25 * Description of instances.
26 */
27typedef struct dt_desc_pwrmgr {
28 dt_instance_id_t inst_id; /**< Instance ID */
29 uint32_t reg_addr[kDtPwrmgrRegBlockCount]; /**< Base address of each register block */
30 /**
31 * PLIC ID of the first IRQ of this instance
32 *
33 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
34 */
36 /**
37 * Alert ID of the first Alert of this instance.
38 *
39 * This value is undefined if the block is not connected to the Alert Handler.
40 */
42 dt_clock_t clock[kDtPwrmgrClockCount]; /**< Clock signal connected to each clock port */
43 dt_reset_t reset[kDtPwrmgrResetCount]; /**< Reset signal connected to each reset port */
44 struct {
45 dt_pwrmgr_wakeup_src_t wakeup_src[8]; /**< List of wakeup sources, in the order of the register fields */
46 dt_pwrmgr_reset_req_src_t rst_reqs[2]; /**< List of reset requests, in the order of the register fields */
47 } pwrmgr_ext; /**< Extension */
49
50
51
52
53static const dt_desc_pwrmgr_t pwrmgr_desc[kDtPwrmgrCount] = {
54 [kDtPwrmgr] = {
55 .inst_id = kDtInstanceIdPwrmgr,
56 .reg_addr = {
57 [kDtPwrmgrRegBlockCore] = 0x40400000,
58 },
61 .clock = {
66 },
67 .reset = {
73 },
74 .pwrmgr_ext = {
75 .wakeup_src = {
76 [0] = {
77 .inst_id = kDtInstanceIdI3c0,
79 },
80 [1] = {
81 .inst_id = kDtInstanceIdI3c1,
83 },
84 [2] = {
85 .inst_id = kDtInstanceIdSysrstCtrl,
87 },
88 [3] = {
89 .inst_id = kDtInstanceIdAdcCtrl,
91 },
92 [4] = {
93 .inst_id = kDtInstanceIdPinmux,
95 },
96 [5] = {
97 .inst_id = kDtInstanceIdPinmux,
99 },
100 [6] = {
101 .inst_id = kDtInstanceIdAonTimer,
102 .wakeup = kDtAonTimerWakeupWkupReq,
103 },
104 [7] = {
105 .inst_id = kDtInstanceIdSensorCtrl,
107 },
108 },
109 .rst_reqs = {
110 [0] = {
111 .inst_id = kDtInstanceIdSysrstCtrl,
112 .reset_req = kDtSysrstCtrlResetReqRstReq,
113 },
114 [1] = {
115 .inst_id = kDtInstanceIdAonTimer,
116 .reset_req = kDtAonTimerResetReqAonTimer,
117 },
118 },
119 },
120 },
121};
122
123/**
124 * Return a pointer to the `dt_pwrmgr_desc_t` structure of the requested
125 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
126 * the function) with the provided default value.
127 */
128#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_pwrmgr_t)0 || (int)(dt) >= kDtPwrmgrCount) return (default); &pwrmgr_desc[dt]; })
129
131 if (inst_id >= kDtInstanceIdPwrmgr && inst_id <= kDtInstanceIdPwrmgr) {
132 return (dt_pwrmgr_t)(inst_id - kDtInstanceIdPwrmgr);
133 }
134 return (dt_pwrmgr_t)0;
135}
136
141
143 dt_pwrmgr_t dt,
144 dt_pwrmgr_reg_block_t reg_block) {
145 // Return a recognizable address in case of wrong argument.
146 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
147}
148
150 dt_pwrmgr_t dt,
151 dt_pwrmgr_irq_t irq) {
152 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
153 if (first_irq == kDtPlicIrqIdNone) {
154 return kDtPlicIrqIdNone;
155 }
156 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
157}
158
160 dt_pwrmgr_t dt,
161 dt_plic_irq_id_t irq) {
163 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
164 if (first_irq == kDtPlicIrqIdNone) {
165 return count;
166 }
167 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
168 return count;
169 }
170 return (dt_pwrmgr_irq_t)(irq - first_irq);
171}
172
173
175 dt_pwrmgr_t dt,
176 dt_pwrmgr_alert_t alert) {
177 return (dt_alert_id_t)((uint32_t)pwrmgr_desc[dt].first_alert + (uint32_t)alert);
178}
179
181 dt_pwrmgr_t dt,
182 dt_alert_id_t alert) {
184 if (alert < pwrmgr_desc[dt].first_alert || alert >= pwrmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
185 return count;
186 }
187 return (dt_pwrmgr_alert_t)(alert - pwrmgr_desc[dt].first_alert);
188}
189
190
191
193 dt_pwrmgr_t dt,
194 dt_pwrmgr_clock_t clk) {
195 // Return the first clock in case of invalid argument.
196 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
197}
198
200 dt_pwrmgr_t dt,
201 dt_pwrmgr_reset_t rst) {
203 if (rst >= count) {
204 return kDtResetUnknown;
205 }
206 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
207}
208
209
210
212 return 8;
213}
214
216 dt_pwrmgr_wakeup_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .wakeup = 0};
217 return TRY_GET_DT(dt, invalid)->pwrmgr_ext.wakeup_src[idx];
218}
219
221 return 2;
222}
223
225 dt_pwrmgr_reset_req_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .reset_req = 0};
226 return TRY_GET_DT(dt, invalid)->pwrmgr_ext.rst_reqs[idx];
227}
228
229