Software APIs
dt_lc_ctrl.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 lc_ctrl and top earlgrey.
10
*/
11
12
#include "dt/dt_lc_ctrl.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_lc_ctrl
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtLcCtrlRegBlockCount];
/**< 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
*/
27
top_earlgrey_alert_id_t
first_alert
;
28
dt_clock_t
clock
[kDtLcCtrlClockCount];
/**< Clock signal connected to each clock port */
29
dt_reset_t
reset
[kDtLcCtrlResetCount];
/**< Reset signal connected to each reset port */
30
}
dt_desc_lc_ctrl_t
;
31
32
33
34
35
static
const
dt_desc_lc_ctrl_t
lc_ctrl_desc[kDtLcCtrlCount] = {
36
[
kDtLcCtrl
] = {
37
.inst_id =
kDtInstanceIdLcCtrl
,
38
.base_addr = {
39
[kDtLcCtrlRegBlockRegs] = 0x40140000,
40
[kDtLcCtrlRegBlockDmi] = 0x0,
41
},
42
.first_alert =
kTopEarlgreyAlertIdLcCtrlFatalProgError
,
43
.clock = {
44
[
kDtLcCtrlClockClk
] =
kDtClockIoDiv4
,
45
[
kDtLcCtrlClockKmac
] =
kDtClockMain
,
46
},
47
.reset = {
48
[
kDtLcCtrlResetRst
] =
kDtResetLcIoDiv4
,
49
[
kDtLcCtrlResetKmac
] =
kDtResetLc
,
50
},
51
},
52
};
53
54
/**
55
* Return a pointer to the `dt_lc_ctrl_desc_t` structure of the requested
56
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
57
* the function) with the provided default value.
58
*/
59
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_lc_ctrl_t)0 || (dt) >= kDtLcCtrlCount) return (default); &lc_ctrl_desc[dt]; })
60
61
dt_lc_ctrl_t
dt_lc_ctrl_from_instance_id
(
dt_instance_id_t
inst_id) {
62
if
(inst_id >=
kDtInstanceIdLcCtrl
&& inst_id <=
kDtInstanceIdLcCtrl
) {
63
return
(
dt_lc_ctrl_t
)(inst_id -
kDtInstanceIdLcCtrl
);
64
}
65
return
(
dt_lc_ctrl_t
)0;
66
}
67
68
dt_instance_id_t
dt_lc_ctrl_instance_id
(
69
dt_lc_ctrl_t
dt) {
70
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
71
}
72
73
uint32_t
dt_lc_ctrl_reg_block
(
74
dt_lc_ctrl_t
dt,
75
dt_lc_ctrl_reg_block_t
reg_block) {
76
// Return a recognizable address in case of wrong argument.
77
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
78
}
79
80
81
dt_alert_id_t
dt_lc_ctrl_alert_to_alert_id
(
82
dt_lc_ctrl_t
dt,
83
dt_lc_ctrl_alert_t
alert) {
84
return
(
dt_alert_id_t
)((uint32_t)lc_ctrl_desc[dt].first_alert + (uint32_t)alert);
85
}
86
87
dt_lc_ctrl_alert_t
dt_lc_ctrl_alert_from_alert_id
(
88
dt_lc_ctrl_t
dt,
89
dt_alert_id_t
alert) {
90
dt_lc_ctrl_alert_t
count = kDtLcCtrlAlertCount;
91
if
(alert < lc_ctrl_desc[dt].first_alert || alert >= lc_ctrl_desc[dt].first_alert + (
dt_alert_id_t
)count) {
92
return
count;
93
}
94
return
(
dt_lc_ctrl_alert_t
)(alert - lc_ctrl_desc[dt].first_alert);
95
}
96
97
98
99
dt_clock_t
dt_lc_ctrl_clock
(
100
dt_lc_ctrl_t
dt,
101
dt_lc_ctrl_clock_t
clk) {
102
// Return the first clock in case of invalid argument.
103
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
104
}
105
106
dt_reset_t
dt_lc_ctrl_reset
(
107
dt_lc_ctrl_t
dt,
108
dt_lc_ctrl_reset_t
rst) {
109
const
dt_lc_ctrl_reset_t
count = kDtLcCtrlResetCount;
110
if
(rst >= count) {
111
return
kDtResetUnknown
;
112
}
113
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
114
}
115
116
(earlgrey)
hw
top
dt
dt_lc_ctrl.c
Return to
OpenTitan Documentation