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