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
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[2]; /**< 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] = 0x30420000,
46 },
48 .clock = {
53 },
54 .reset = {
66 },
67 .clkmgr_ext = {
68 .sw_clks = {
71 },
72 .hint_clks = {
73 [0] = kDtInstanceIdAes,
77 },
78 },
79 },
80};
81
82/**
83 * Return a pointer to the `dt_clkmgr_desc_t` structure of the requested
84 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
85 * the function) with the provided default value.
86 */
87#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_clkmgr_t)0 || (dt) >= kDtClkmgrCount) return (default); &clkmgr_desc[dt]; })
88
90 if (inst_id >= kDtInstanceIdClkmgrAon && inst_id <= kDtInstanceIdClkmgrAon) {
91 return (dt_clkmgr_t)(inst_id - kDtInstanceIdClkmgrAon);
92 }
93 return (dt_clkmgr_t)0;
94}
95
100
102 dt_clkmgr_t dt,
103 dt_clkmgr_reg_block_t reg_block) {
104 // Return a recognizable address in case of wrong argument.
105 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
106}
107
108
110 dt_clkmgr_t dt,
111 dt_clkmgr_alert_t alert) {
112 return (dt_alert_id_t)((uint32_t)clkmgr_desc[dt].first_alert + (uint32_t)alert);
113}
114
116 dt_clkmgr_t dt,
117 dt_alert_id_t alert) {
118 dt_clkmgr_alert_t count = kDtClkmgrAlertCount;
119 if (alert < clkmgr_desc[dt].first_alert || alert >= clkmgr_desc[dt].first_alert + (dt_alert_id_t)count) {
120 return count;
121 }
122 return (dt_clkmgr_alert_t)(alert - clkmgr_desc[dt].first_alert);
123}
124
125
126
128 dt_clkmgr_t dt,
129 dt_clkmgr_clock_t clk) {
130 // Return the first clock in case of invalid argument.
131 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
132}
133
135 dt_clkmgr_t dt,
136 dt_clkmgr_reset_t rst) {
137 const dt_clkmgr_reset_t count = kDtClkmgrResetCount;
138 if (rst >= count) {
139 return kDtResetUnknown;
140 }
141 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
142}
143
144
145
147 return 2;
148}
149
151 return TRY_GET_DT(dt, kDtInstanceIdUnknown)->clkmgr_ext.sw_clks[idx];
152}
153
155 return 4;
156}
157
159 return TRY_GET_DT(dt, kDtInstanceIdUnknown)->clkmgr_ext.hint_clks[idx];
160}
161
162