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 darjeeling.
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_darjeeling_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] = 0x30460000,
42
},
43
.mem_addr = {
44
},
45
.mem_size = {
46
},
47
.first_alert =
kTopDarjeelingAlertIdPinmuxAonFatalFault
,
48
.clock = {
49
[
kDtPinmuxClockClk
] =
kDtClockIoDiv4
,
50
[
kDtPinmuxClockAon
] =
kDtClockAon
,
51
},
52
.reset = {
53
[
kDtPinmuxResetRst
] =
kDtResetLcIoDiv4
,
54
[
kDtPinmuxResetAon
] =
kDtResetLcAon
,
55
},
56
},
57
};
58
59
/**
60
* Return a pointer to the `dt_pinmux_desc_t` structure of the requested
61
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
62
* the function) with the provided default value.
63
*/
64
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_pinmux_t)0 || (dt) >= kDtPinmuxCount) return (default); &pinmux_desc[dt]; })
65
66
dt_pinmux_t
dt_pinmux_from_instance_id
(
dt_instance_id_t
inst_id) {
67
if
(inst_id >=
kDtInstanceIdPinmuxAon
&& inst_id <=
kDtInstanceIdPinmuxAon
) {
68
return
(
dt_pinmux_t
)(inst_id -
kDtInstanceIdPinmuxAon
);
69
}
70
return
(
dt_pinmux_t
)0;
71
}
72
73
dt_instance_id_t
dt_pinmux_instance_id
(
74
dt_pinmux_t
dt) {
75
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
76
}
77
78
uint32_t
dt_pinmux_reg_block
(
79
dt_pinmux_t
dt,
80
dt_pinmux_reg_block_t
reg_block) {
81
// Return a recognizable address in case of wrong argument.
82
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
83
}
84
85
uint32_t
dt_pinmux_memory_base
(
86
dt_pinmux_t
dt,
87
dt_pinmux_memory_t
mem) {
88
// Return a recognizable address in case of wrong argument.
89
return
TRY_GET_DT
(dt, 0xdeadbeef)->mem_addr[mem];
90
}
91
92
uint32_t
dt_pinmux_memory_size
(
93
dt_pinmux_t
dt,
94
dt_pinmux_memory_t
mem) {
95
// Return an empty size in case of wrong argument.
96
return
TRY_GET_DT
(dt, 0)->mem_size[mem];
97
}
98
99
100
dt_alert_id_t
dt_pinmux_alert_to_alert_id
(
101
dt_pinmux_t
dt,
102
dt_pinmux_alert_t
alert) {
103
return
(
dt_alert_id_t
)((uint32_t)pinmux_desc[dt].first_alert + (uint32_t)alert);
104
}
105
106
dt_pinmux_alert_t
dt_pinmux_alert_from_alert_id
(
107
dt_pinmux_t
dt,
108
dt_alert_id_t
alert) {
109
dt_pinmux_alert_t
count = kDtPinmuxAlertCount;
110
if
(alert < pinmux_desc[dt].first_alert || alert >= pinmux_desc[dt].first_alert + (
dt_alert_id_t
)count) {
111
return
count;
112
}
113
return
(
dt_pinmux_alert_t
)(alert - pinmux_desc[dt].first_alert);
114
}
115
116
117
118
dt_clock_t
dt_pinmux_clock
(
119
dt_pinmux_t
dt,
120
dt_pinmux_clock_t
clk) {
121
// Return the first clock in case of invalid argument.
122
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
123
}
124
125
dt_reset_t
dt_pinmux_reset
(
126
dt_pinmux_t
dt,
127
dt_pinmux_reset_t
rst) {
128
const
dt_pinmux_reset_t
count = kDtPinmuxResetCount;
129
if
(rst >= count) {
130
return
kDtResetUnknown
;
131
}
132
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
133
}
134
135
(darjeeling)
hw
top
dt
dt_pinmux.c
Return to
OpenTitan Documentation