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 darjeeling.
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[2]; /**< 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] = 0x30420000,
44 },
46 .clock = {
51 },
52 .reset = {
64 },
65 .ext = {
66 .sw_clks = {
69 },
70 .hint_clks = {
71 [0] = kDtInstanceIdAes,
75 },
76 },
77 },
78};
79
80/**
81 * Return a pointer to the `dt_clkmgr_desc_t` structure of the requested
82 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
83 * the function) with the provided default value.
84 */
85#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_clkmgr_t)0 || (dt) >= kDtClkmgrCount) return (default); &clkmgr_desc[dt]; })
86
88 if (inst_id >= kDtInstanceIdClkmgrAon && inst_id <= kDtInstanceIdClkmgrAon) {
89 return (dt_clkmgr_t)(inst_id - kDtInstanceIdClkmgrAon);
90 }
91 return (dt_clkmgr_t)0;
92}
93
98
100 dt_clkmgr_t dt,
101 dt_clkmgr_reg_block_t reg_block) {
102 // Return a recognizable address in case of wrong argument.
103 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
104}
105
106
108 dt_clkmgr_t dt,
109 dt_clkmgr_alert_t alert) {
110 return (dt_alert_id_t)((uint32_t)clkmgr_desc[dt].first_alert + (uint32_t)alert);
111}
112
114 dt_clkmgr_t dt,
115 dt_alert_id_t alert) {
116 dt_clkmgr_alert_t count = kDtClkmgrAlertCount;
117 if (alert < clkmgr_desc[dt].first_alert || alert >= clkmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
118 return count;
119 }
120 return (dt_clkmgr_alert_t)(alert - clkmgr_desc[dt].first_alert);
121}
122
123
124
126 dt_clkmgr_t dt,
127 dt_clkmgr_clock_t clk) {
128 // Return the first clock in case of invalid argument.
129 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
130}
131
133 dt_clkmgr_t dt,
134 dt_clkmgr_reset_t rst) {
135 const dt_clkmgr_reset_t count = kDtClkmgrResetCount;
136 if (rst >= count) {
137 return kDtResetUnknown;
138 }
139 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
140}
141
142
144 return 2;
145}
146
148 return TRY_GET_DT(dt, kDtInstanceIdUnknown)->ext.sw_clks[idx];
149}
150
152 return 4;
153}
154
156 return TRY_GET_DT(dt, kDtInstanceIdUnknown)->ext.hint_clks[idx];
157}
158