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 * Description of instances.
18 */
19typedef struct dt_desc_clkmgr {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t base_addr[kDtClkmgrRegBlockCount]; /**< Base address of each register block */
22 /**
23 * Alert ID of the first Alert of this instance.
24 *
25 * This value is undefined if the block is not connected to the Alert Handler.
26 */
28 dt_clock_t clock[kDtClkmgrClockCount]; /**< Clock signal connected to each clock port */
29 dt_reset_t reset[kDtClkmgrResetCount]; /**< Reset signal connected to each reset port */
30 struct {
31 dt_instance_id_t sw_clks[4]; /**< List of gateable clocks, in the order of the register fields */
32 dt_instance_id_t hint_clks[4]; /**< List of hintable clocks, in the order of the register fields */
33 } ext; /**< Extension */
35
36
37
38
39static const dt_desc_clkmgr_t clkmgr_desc[kDtClkmgrCount] = {
40 [kDtClkmgrAon] = {
41 .inst_id = kDtInstanceIdClkmgrAon,
42 .base_addr = {
43 [kDtClkmgrRegBlockCore] = 0x40420000,
44 },
46 .clock = {
52 },
53 .reset = {
67 },
68 .ext = {
69 .sw_clks = {
74 },
75 .hint_clks = {
76 [0] = kDtInstanceIdAes,
80 },
81 },
82 },
83};
84
85/**
86 * Return a pointer to the `dt_clkmgr_desc_t` structure of the requested
87 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
88 * the function) with the provided default value.
89 */
90#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_clkmgr_t)0 || (dt) >= kDtClkmgrCount) return (default); &clkmgr_desc[dt]; })
91
93 if (inst_id >= kDtInstanceIdClkmgrAon && inst_id <= kDtInstanceIdClkmgrAon) {
94 return (dt_clkmgr_t)(inst_id - kDtInstanceIdClkmgrAon);
95 }
96 return (dt_clkmgr_t)0;
97}
98
103
105 dt_clkmgr_t dt,
106 dt_clkmgr_reg_block_t reg_block) {
107 // Return a recognizable address in case of wrong argument.
108 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
109}
110
111
113 dt_clkmgr_t dt,
114 dt_clkmgr_alert_t alert) {
115 return (dt_alert_id_t)((uint32_t)clkmgr_desc[dt].first_alert + (uint32_t)alert);
116}
117
119 dt_clkmgr_t dt,
120 dt_alert_id_t alert) {
121 dt_clkmgr_alert_t count = kDtClkmgrAlertCount;
122 if (alert < clkmgr_desc[dt].first_alert || alert >= clkmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
123 return count;
124 }
125 return (dt_clkmgr_alert_t)(alert - clkmgr_desc[dt].first_alert);
126}
127
128
129
131 dt_clkmgr_t dt,
132 dt_clkmgr_clock_t clk) {
133 // Return the first clock in case of invalid argument.
134 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
135}
136
138 dt_clkmgr_t dt,
139 dt_clkmgr_reset_t rst) {
140 const dt_clkmgr_reset_t count = kDtClkmgrResetCount;
141 if (rst >= count) {
142 return kDtResetUnknown;
143 }
144 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
145}
146
147
149 return 4;
150}
151
153 return TRY_GET_DT(dt, kDtInstanceIdUnknown)->ext.sw_clks[idx];
154}
155
157 return 4;
158}
159
161 return TRY_GET_DT(dt, kDtInstanceIdUnknown)->ext.hint_clks[idx];
162}
163