Software APIs
dt_otp_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 otp_ctrl and top earlgrey.
10
*/
11
12
#include "dt/dt_otp_ctrl.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_otp_ctrl
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtOtpCtrlRegBlockCount];
/**< Base address of each register block */
22
/**
23
* PLIC ID of the first IRQ of this instance
24
*
25
* This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
26
*/
27
top_earlgrey_plic_irq_id_t
first_irq
;
28
/**
29
* Alert ID of the first Alert of this instance.
30
*
31
* This value is undefined if the block is not connected to the Alert Handler.
32
*/
33
top_earlgrey_alert_id_t
first_alert
;
34
dt_clock_t
clock
[kDtOtpCtrlClockCount];
/**< Clock signal connected to each clock port */
35
dt_reset_t
reset
[kDtOtpCtrlResetCount];
/**< Reset signal connected to each reset port */
36
}
dt_desc_otp_ctrl_t
;
37
38
39
40
41
static
const
dt_desc_otp_ctrl_t
otp_ctrl_desc[kDtOtpCtrlCount] = {
42
[
kDtOtpCtrl
] = {
43
.inst_id =
kDtInstanceIdOtpCtrl
,
44
.base_addr = {
45
[kDtOtpCtrlRegBlockCore] = 0x40130000,
46
},
47
.first_irq =
kTopEarlgreyPlicIrqIdOtpCtrlOtpOperationDone
,
48
.first_alert =
kTopEarlgreyAlertIdOtpCtrlFatalMacroError
,
49
.clock = {
50
[
kDtOtpCtrlClockClk
] =
kDtClockIoDiv4
,
51
[
kDtOtpCtrlClockEdn
] =
kDtClockMain
,
52
},
53
.reset = {
54
[
kDtOtpCtrlResetRst
] =
kDtResetLcIoDiv4
,
55
[
kDtOtpCtrlResetEdn
] =
kDtResetLc
,
56
},
57
},
58
};
59
60
/**
61
* Return a pointer to the `dt_otp_ctrl_desc_t` structure of the requested
62
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
63
* the function) with the provided default value.
64
*/
65
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_otp_ctrl_t)0 || (dt) >= kDtOtpCtrlCount) return (default); &otp_ctrl_desc[dt]; })
66
67
dt_otp_ctrl_t
dt_otp_ctrl_from_instance_id
(
dt_instance_id_t
inst_id) {
68
if
(inst_id >=
kDtInstanceIdOtpCtrl
&& inst_id <=
kDtInstanceIdOtpCtrl
) {
69
return
(
dt_otp_ctrl_t
)(inst_id -
kDtInstanceIdOtpCtrl
);
70
}
71
return
(
dt_otp_ctrl_t
)0;
72
}
73
74
dt_instance_id_t
dt_otp_ctrl_instance_id
(
75
dt_otp_ctrl_t
dt) {
76
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
77
}
78
79
uint32_t
dt_otp_ctrl_reg_block
(
80
dt_otp_ctrl_t
dt,
81
dt_otp_ctrl_reg_block_t
reg_block) {
82
// Return a recognizable address in case of wrong argument.
83
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
84
}
85
86
dt_plic_irq_id_t
dt_otp_ctrl_irq_to_plic_id
(
87
dt_otp_ctrl_t
dt,
88
dt_otp_ctrl_irq_t
irq) {
89
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
90
if
(first_irq == kDtPlicIrqIdNone) {
91
return
kDtPlicIrqIdNone;
92
}
93
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
94
}
95
96
dt_otp_ctrl_irq_t
dt_otp_ctrl_irq_from_plic_id
(
97
dt_otp_ctrl_t
dt,
98
dt_plic_irq_id_t
irq) {
99
dt_otp_ctrl_irq_t
count = kDtOtpCtrlIrqCount;
100
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
101
if
(first_irq == kDtPlicIrqIdNone) {
102
return
count;
103
}
104
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
105
return
count;
106
}
107
return
(
dt_otp_ctrl_irq_t
)(irq - first_irq);
108
}
109
110
111
dt_alert_id_t
dt_otp_ctrl_alert_to_alert_id
(
112
dt_otp_ctrl_t
dt,
113
dt_otp_ctrl_alert_t
alert) {
114
return
(
dt_alert_id_t
)((uint32_t)otp_ctrl_desc[dt].first_alert + (uint32_t)alert);
115
}
116
117
dt_otp_ctrl_alert_t
dt_otp_ctrl_alert_from_alert_id
(
118
dt_otp_ctrl_t
dt,
119
dt_alert_id_t
alert) {
120
dt_otp_ctrl_alert_t
count = kDtOtpCtrlAlertCount;
121
if
(alert < otp_ctrl_desc[dt].first_alert || alert >= otp_ctrl_desc[dt].first_alert + (
dt_alert_id_t
)count) {
122
return
count;
123
}
124
return
(
dt_otp_ctrl_alert_t
)(alert - otp_ctrl_desc[dt].first_alert);
125
}
126
127
128
129
dt_clock_t
dt_otp_ctrl_clock
(
130
dt_otp_ctrl_t
dt,
131
dt_otp_ctrl_clock_t
clk) {
132
// Return the first clock in case of invalid argument.
133
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
134
}
135
136
dt_reset_t
dt_otp_ctrl_reset
(
137
dt_otp_ctrl_t
dt,
138
dt_otp_ctrl_reset_t
rst) {
139
const
dt_otp_ctrl_reset_t
count = kDtOtpCtrlResetCount;
140
if
(rst >= count) {
141
return
kDtResetUnknown
;
142
}
143
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
144
}
145
146
(earlgrey)
hw
top
dt
dt_otp_ctrl.c
Return to
OpenTitan Documentation