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 englishbreakfast.
10 */
11
12#include "dt/dt_pwrmgr.h"
13
14#include "dt_pinmux.h"
15#include "dt_aon_timer.h"
16
17
18/**
19 * Description of instances.
20 */
21typedef struct dt_desc_pwrmgr {
22 dt_instance_id_t inst_id; /**< Instance ID */
23 uint32_t base_addr[kDtPwrmgrRegBlockCount]; /**< Base address of each register block */
24 /**
25 * PLIC ID of the first IRQ of this instance
26 *
27 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
28 */
30 dt_clock_t clock[kDtPwrmgrClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtPwrmgrResetCount]; /**< Reset signal connected to each reset port */
32 struct {
33 dt_pwrmgr_wakeup_src_t wakeup_src[3]; /**< List of wakeup sources, in the order of the register fields */
34 dt_pwrmgr_reset_req_src_t rst_reqs[1]; /**< List of reset requests, in the order of the register fields */
35 } ext; /**< Extension */
37
38
39
40
41static const dt_desc_pwrmgr_t pwrmgr_desc[kDtPwrmgrCount] = {
42 [kDtPwrmgrAon] = {
43 .inst_id = kDtInstanceIdPwrmgrAon,
44 .base_addr = {
45 [kDtPwrmgrRegBlockCore] = 0x40400000,
46 },
48 .clock = {
53 },
54 .reset = {
60 },
61 .ext = {
62 .wakeup_src = {
63 [0] = {
64 .inst_id = kDtInstanceIdPinmuxAon,
66 },
67 [1] = {
68 .inst_id = kDtInstanceIdPinmuxAon,
70 },
71 [2] = {
72 .inst_id = kDtInstanceIdAonTimerAon,
74 },
75 },
76 .rst_reqs = {
77 [0] = {
78 .inst_id = kDtInstanceIdAonTimerAon,
79 .reset_req = kDtAonTimerResetReqAonTimer,
80 },
81 },
82 },
83 },
84};
85
86/**
87 * Return a pointer to the `dt_pwrmgr_desc_t` structure of the requested
88 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
89 * the function) with the provided default value.
90 */
91#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_pwrmgr_t)0 || (dt) >= kDtPwrmgrCount) return (default); &pwrmgr_desc[dt]; })
92
94 if (inst_id >= kDtInstanceIdPwrmgrAon && inst_id <= kDtInstanceIdPwrmgrAon) {
95 return (dt_pwrmgr_t)(inst_id - kDtInstanceIdPwrmgrAon);
96 }
97 return (dt_pwrmgr_t)0;
98}
99
104
106 dt_pwrmgr_t dt,
107 dt_pwrmgr_reg_block_t reg_block) {
108 // Return a recognizable address in case of wrong argument.
109 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
110}
111
113 dt_pwrmgr_t dt,
114 dt_pwrmgr_irq_t irq) {
115 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
116 if (first_irq == kDtPlicIrqIdNone) {
117 return kDtPlicIrqIdNone;
118 }
119 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
120}
121
123 dt_pwrmgr_t dt,
124 dt_plic_irq_id_t irq) {
125 dt_pwrmgr_irq_t count = kDtPwrmgrIrqCount;
126 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
127 if (first_irq == kDtPlicIrqIdNone) {
128 return count;
129 }
130 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
131 return count;
132 }
133 return (dt_pwrmgr_irq_t)(irq - first_irq);
134}
135
136
137
138
140 dt_pwrmgr_t dt,
141 dt_pwrmgr_clock_t clk) {
142 // Return the first clock in case of invalid argument.
143 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
144}
145
147 dt_pwrmgr_t dt,
148 dt_pwrmgr_reset_t rst) {
149 const dt_pwrmgr_reset_t count = kDtPwrmgrResetCount;
150 if (rst >= count) {
151 return kDtResetUnknown;
152 }
153 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
154}
155
156
158 return 3;
159}
160
162 dt_pwrmgr_wakeup_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .wakeup = 0};
163 return TRY_GET_DT(dt, invalid)->ext.wakeup_src[idx];
164}
165
167 return 1;
168}
169
171 dt_pwrmgr_reset_req_src_t invalid = {.inst_id = kDtInstanceIdUnknown, .reset_req = 0};
172 return TRY_GET_DT(dt, invalid)->ext.rst_reqs[idx];
173}
174