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 englishbreakfast.
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 dt_clock_t clock[kDtClkmgrClockCount]; /**< Clock signal connected to each clock port */
25 dt_reset_t reset[kDtClkmgrResetCount]; /**< Reset signal connected to each reset port */
26 struct {
27 dt_instance_id_t sw_clks[4]; /**< List of gateable clocks, in the order of the register fields */
28 dt_instance_id_t hint_clks[1]; /**< List of hintable clocks, in the order of the register fields */
29 } clkmgr_ext; /**< Extension */
31
32
33
34
35static const dt_desc_clkmgr_t clkmgr_desc[kDtClkmgrCount] = {
36 [kDtClkmgrAon] = {
37 .inst_id = kDtInstanceIdClkmgrAon,
38 .base_addr = {
39 [kDtClkmgrRegBlockCore] = 0x40420000,
40 },
41 .clock = {
47 },
48 .reset = {
62 },
63 .clkmgr_ext = {
64 .sw_clks = {
69 },
70 .hint_clks = {
71 [0] = kDtInstanceIdAes,
72 },
73 },
74 },
75};
76
77/**
78 * Return a pointer to the `dt_clkmgr_desc_t` structure of the requested
79 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
80 * the function) with the provided default value.
81 */
82#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_clkmgr_t)0 || (dt) >= kDtClkmgrCount) return (default); &clkmgr_desc[dt]; })
83
85 if (inst_id >= kDtInstanceIdClkmgrAon && inst_id <= kDtInstanceIdClkmgrAon) {
86 return (dt_clkmgr_t)(inst_id - kDtInstanceIdClkmgrAon);
87 }
88 return (dt_clkmgr_t)0;
89}
90
95
97 dt_clkmgr_t dt,
98 dt_clkmgr_reg_block_t reg_block) {
99 // Return a recognizable address in case of wrong argument.
100 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
101}
102
103
104
105
107 dt_clkmgr_t dt,
108 dt_clkmgr_clock_t clk) {
109 // Return the first clock in case of invalid argument.
110 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
111}
112
114 dt_clkmgr_t dt,
115 dt_clkmgr_reset_t rst) {
116 const dt_clkmgr_reset_t count = kDtClkmgrResetCount;
117 if (rst >= count) {
118 return kDtResetUnknown;
119 }
120 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
121}
122
123
124
126 return 4;
127}
128
130 return TRY_GET_DT(dt, kDtInstanceIdUnknown)->clkmgr_ext.sw_clks[idx];
131}
132
134 return 1;
135}
136
138 return TRY_GET_DT(dt, kDtInstanceIdUnknown)->clkmgr_ext.hint_clks[idx];
139}
140
141