Software APIs
dt_pinmux.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 pinmux and top earlgrey.
10
*/
11
12
#include "hw/top/dt/dt_pinmux.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_pinmux
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
reg_addr
[kDtPinmuxRegBlockCount];
/**< Base address of each register block */
22
uint32_t
mem_addr
[kDtPinmuxMemoryCount];
/**< Base address of each memory */
23
uint32_t
mem_size
[kDtPinmuxMemoryCount];
/**< Size in bytes of each memory */
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
*/
29
top_earlgrey_alert_id_t
first_alert
;
30
dt_clock_t
clock
[kDtPinmuxClockCount];
/**< Clock signal connected to each clock port */
31
dt_reset_t
reset
[kDtPinmuxResetCount];
/**< Reset signal connected to each reset port */
32
}
dt_desc_pinmux_t
;
33
34
35
36
37
static
const
dt_desc_pinmux_t
pinmux_desc[kDtPinmuxCount] = {
38
[
kDtPinmuxAon
] = {
39
.inst_id =
kDtInstanceIdPinmuxAon
,
40
.reg_addr = {
41
[kDtPinmuxRegBlockCore] = 0x40460000,
42
},
43
.mem_addr = {
44
},
45
.mem_size = {
46
},
47
.first_alert =
kTopEarlgreyAlertIdPinmuxAonFatalFault
,
48
.clock = {
49
[
kDtPinmuxClockClk
] =
kDtClockIoDiv4
,
50
[
kDtPinmuxClockAon
] =
kDtClockAon
,
51
},
52
.reset = {
53
[
kDtPinmuxResetRst
] =
kDtResetLcIoDiv4
,
54
[
kDtPinmuxResetAon
] =
kDtResetLcAon
,
55
[
kDtPinmuxResetSys
] =
kDtResetSysIoDiv4
,
56
},
57
},
58
};
59
60
/**
61
* Return a pointer to the `dt_pinmux_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_pinmux_t)0 || (dt) >= kDtPinmuxCount) return (default); &pinmux_desc[dt]; })
66
67
dt_pinmux_t
dt_pinmux_from_instance_id
(
dt_instance_id_t
inst_id) {
68
if
(inst_id >=
kDtInstanceIdPinmuxAon
&& inst_id <=
kDtInstanceIdPinmuxAon
) {
69
return
(
dt_pinmux_t
)(inst_id -
kDtInstanceIdPinmuxAon
);
70
}
71
return
(
dt_pinmux_t
)0;
72
}
73
74
dt_instance_id_t
dt_pinmux_instance_id
(
75
dt_pinmux_t
dt) {
76
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
77
}
78
79
uint32_t
dt_pinmux_reg_block
(
80
dt_pinmux_t
dt,
81
dt_pinmux_reg_block_t
reg_block) {
82
// Return a recognizable address in case of wrong argument.
83
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
84
}
85
86
uint32_t
dt_pinmux_memory_base
(
87
dt_pinmux_t
dt,
88
dt_pinmux_memory_t
mem) {
89
// Return a recognizable address in case of wrong argument.
90
return
TRY_GET_DT
(dt, 0xdeadbeef)->mem_addr[mem];
91
}
92
93
uint32_t
dt_pinmux_memory_size
(
94
dt_pinmux_t
dt,
95
dt_pinmux_memory_t
mem) {
96
// Return an empty size in case of wrong argument.
97
return
TRY_GET_DT
(dt, 0)->mem_size[mem];
98
}
99
100
101
dt_alert_id_t
dt_pinmux_alert_to_alert_id
(
102
dt_pinmux_t
dt,
103
dt_pinmux_alert_t
alert) {
104
return
(
dt_alert_id_t
)((uint32_t)pinmux_desc[dt].first_alert + (uint32_t)alert);
105
}
106
107
dt_pinmux_alert_t
dt_pinmux_alert_from_alert_id
(
108
dt_pinmux_t
dt,
109
dt_alert_id_t
alert) {
110
dt_pinmux_alert_t
count = kDtPinmuxAlertCount;
111
if
(alert < pinmux_desc[dt].first_alert || alert >= pinmux_desc[dt].first_alert + (
dt_alert_id_t
)count) {
112
return
count;
113
}
114
return
(
dt_pinmux_alert_t
)(alert - pinmux_desc[dt].first_alert);
115
}
116
117
118
119
dt_clock_t
dt_pinmux_clock
(
120
dt_pinmux_t
dt,
121
dt_pinmux_clock_t
clk) {
122
// Return the first clock in case of invalid argument.
123
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
124
}
125
126
dt_reset_t
dt_pinmux_reset
(
127
dt_pinmux_t
dt,
128
dt_pinmux_reset_t
rst) {
129
const
dt_pinmux_reset_t
count = kDtPinmuxResetCount;
130
if
(rst >= count) {
131
return
kDtResetUnknown
;
132
}
133
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
134
}
135
136
(earlgrey)
hw
top
dt
dt_pinmux.c
Return to
OpenTitan Documentation