Software APIs
dt_clkmgr.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 clkmgr and top earlgrey.
10 */
11
12#include "dt/dt_clkmgr.h"
13
14
15
16
17
18/**
19 * Description of instances.
20 */
21typedef struct dt_desc_clkmgr {
22 dt_instance_id_t inst_id; /**< Instance ID */
23 uint32_t base_addr[kDtClkmgrRegBlockCount]; /**< Base address of each register block */
24 /**
25 * Alert ID of the first Alert of this instance.
26 *
27 * This value is undefined if the block is not connected to the Alert Handler.
28 */
30 dt_clock_t clock[kDtClkmgrClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtClkmgrResetCount]; /**< Reset signal connected to each reset port */
32 struct {
33 dt_instance_id_t sw_clks[4]; /**< List of gateable clocks, in the order of the register fields */
34 dt_instance_id_t hint_clks[4]; /**< List of hintable clocks, in the order of the register fields */
35 } clkmgr_ext; /**< Extension */
37
38
39
40
41static const dt_desc_clkmgr_t clkmgr_desc[kDtClkmgrCount] = {
42 [kDtClkmgrAon] = {
43 .inst_id = kDtInstanceIdClkmgrAon,
44 .base_addr = {
45 [kDtClkmgrRegBlockCore] = 0x40420000,
46 },
48 .clock = {
54 },
55 .reset = {
69 },
70 .clkmgr_ext = {
71 .sw_clks = {
76 },
77 .hint_clks = {
78 [0] = kDtInstanceIdAes,
82 },
83 },
84 },
85};
86
87/**
88 * Return a pointer to the `dt_clkmgr_desc_t` structure of the requested
89 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
90 * the function) with the provided default value.
91 */
92#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_clkmgr_t)0 || (dt) >= kDtClkmgrCount) return (default); &clkmgr_desc[dt]; })
93
95 if (inst_id >= kDtInstanceIdClkmgrAon && inst_id <= kDtInstanceIdClkmgrAon) {
96 return (dt_clkmgr_t)(inst_id - kDtInstanceIdClkmgrAon);
97 }
98 return (dt_clkmgr_t)0;
99}
100
105
107 dt_clkmgr_t dt,
108 dt_clkmgr_reg_block_t reg_block) {
109 // Return a recognizable address in case of wrong argument.
110 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
111}
112
113
115 dt_clkmgr_t dt,
116 dt_clkmgr_alert_t alert) {
117 return (dt_alert_id_t)((uint32_t)clkmgr_desc[dt].first_alert + (uint32_t)alert);
118}
119
121 dt_clkmgr_t dt,
122 dt_alert_id_t alert) {
123 dt_clkmgr_alert_t count = kDtClkmgrAlertCount;
124 if (alert < clkmgr_desc[dt].first_alert || alert >= clkmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
125 return count;
126 }
127 return (dt_clkmgr_alert_t)(alert - clkmgr_desc[dt].first_alert);
128}
129
130
131
133 dt_clkmgr_t dt,
134 dt_clkmgr_clock_t clk) {
135 // Return the first clock in case of invalid argument.
136 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
137}
138
140 dt_clkmgr_t dt,
141 dt_clkmgr_reset_t rst) {
142 const dt_clkmgr_reset_t count = kDtClkmgrResetCount;
143 if (rst >= count) {
144 return kDtResetUnknown;
145 }
146 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
147}
148
149
150
152 return 4;
153}
154
156 return TRY_GET_DT(dt, kDtInstanceIdUnknown)->clkmgr_ext.sw_clks[idx];
157}
158
160 return 4;
161}
162
164 return TRY_GET_DT(dt, kDtInstanceIdUnknown)->clkmgr_ext.hint_clks[idx];
165}
166
167