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 earlgrey.
10 */
11
12#include "dt/dt_pwrmgr.h"
13
14#include "dt_sysrst_ctrl.h"
15#include "dt_adc_ctrl.h"
16#include "dt_pinmux.h"
17#include "dt_aon_timer.h"
18#include "dt_sensor_ctrl.h"
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[6]; /**< 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 } 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] = 0x40400000,
55 },
58 .clock = {
63 },
64 .reset = {
70 },
71 .ext = {
72 .wakeup_src = {
73 [0] = {
76 },
77 [1] = {
78 .inst_id = kDtInstanceIdAdcCtrlAon,
80 },
81 [2] = {
82 .inst_id = kDtInstanceIdPinmuxAon,
84 },
85 [3] = {
86 .inst_id = kDtInstanceIdPinmuxAon,
88 },
89 [4] = {
90 .inst_id = kDtInstanceIdAonTimerAon,
92 },
93 [5] = {
96 },
97 },
98 .rst_reqs = {
99 [0] = {
101 .reset_req = kDtSysrstCtrlResetReqRstReq,
102 },
103 [1] = {
104 .inst_id = kDtInstanceIdAonTimerAon,
105 .reset_req = kDtAonTimerResetReqAonTimer,
106 },
107 },
108 },
109 },
110};
111
112/**
113 * Return a pointer to the `dt_pwrmgr_desc_t` structure of the requested
114 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
115 * the function) with the provided default value.
116 */
117#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_pwrmgr_t)0 || (dt) >= kDtPwrmgrCount) return (default); &pwrmgr_desc[dt]; })
118
120 if (inst_id >= kDtInstanceIdPwrmgrAon && inst_id <= kDtInstanceIdPwrmgrAon) {
121 return (dt_pwrmgr_t)(inst_id - kDtInstanceIdPwrmgrAon);
122 }
123 return (dt_pwrmgr_t)0;
124}
125
130
132 dt_pwrmgr_t dt,
133 dt_pwrmgr_reg_block_t reg_block) {
134 // Return a recognizable address in case of wrong argument.
135 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
136}
137
139 dt_pwrmgr_t dt,
140 dt_pwrmgr_irq_t irq) {
141 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
142 if (first_irq == kDtPlicIrqIdNone) {
143 return kDtPlicIrqIdNone;
144 }
145 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
146}
147
149 dt_pwrmgr_t dt,
150 dt_plic_irq_id_t irq) {
151 dt_pwrmgr_irq_t count = kDtPwrmgrIrqCount;
152 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
153 if (first_irq == kDtPlicIrqIdNone) {
154 return count;
155 }
156 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
157 return count;
158 }
159 return (dt_pwrmgr_irq_t)(irq - first_irq);
160}
161
162
164 dt_pwrmgr_t dt,
165 dt_pwrmgr_alert_t alert) {
166 return (dt_alert_id_t)((uint32_t)pwrmgr_desc[dt].first_alert + (uint32_t)alert);
167}
168
170 dt_pwrmgr_t dt,
171 dt_alert_id_t alert) {
172 dt_pwrmgr_alert_t count = kDtPwrmgrAlertCount;
173 if (alert < pwrmgr_desc[dt].first_alert || alert >= pwrmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
174 return count;
175 }
176 return (dt_pwrmgr_alert_t)(alert - pwrmgr_desc[dt].first_alert);
177}
178
179
180
182 dt_pwrmgr_t dt,
183 dt_pwrmgr_clock_t clk) {
184 // Return the first clock in case of invalid argument.
185 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
186}
187
189 dt_pwrmgr_t dt,
190 dt_pwrmgr_reset_t rst) {
191 const dt_pwrmgr_reset_t count = kDtPwrmgrResetCount;
192 if (rst >= count) {
193 return kDtResetUnknown;
194 }
195 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
196}
197
198
200 return 6;
201}
202
204 dt_pwrmgr_wakeup_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .wakeup = 0};
205 return TRY_GET_DT(dt, invalid)->ext.wakeup_src[idx];
206}
207
209 return 2;
210}
211
213 dt_pwrmgr_reset_req_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .reset_req = 0};
214 return TRY_GET_DT(dt, invalid)->ext.rst_reqs[idx];
215}
216