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 englishbreakfast.
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
dt_clock_t
clock
[kDtPinmuxClockCount];
/**< Clock signal connected to each clock port */
25
dt_reset_t
reset
[kDtPinmuxResetCount];
/**< Reset signal connected to each reset port */
26
}
dt_desc_pinmux_t
;
27
28
29
30
31
static
const
dt_desc_pinmux_t
pinmux_desc[kDtPinmuxCount] = {
32
[
kDtPinmuxAon
] = {
33
.inst_id =
kDtInstanceIdPinmuxAon
,
34
.reg_addr = {
35
[kDtPinmuxRegBlockCore] = 0x40460000,
36
},
37
.mem_addr = {
38
},
39
.mem_size = {
40
},
41
.clock = {
42
[
kDtPinmuxClockClk
] =
kDtClockIoDiv4
,
43
[
kDtPinmuxClockAon
] =
kDtClockAon
,
44
},
45
.reset = {
46
[
kDtPinmuxResetRst
] =
kDtResetLcIoDiv4
,
47
[
kDtPinmuxResetAon
] =
kDtResetSysAon
,
48
[
kDtPinmuxResetSys
] =
kDtResetSysIoDiv4
,
49
},
50
},
51
};
52
53
/**
54
* Return a pointer to the `dt_pinmux_desc_t` structure of the requested
55
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
56
* the function) with the provided default value.
57
*/
58
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_pinmux_t)0 || (dt) >= kDtPinmuxCount) return (default); &pinmux_desc[dt]; })
59
60
dt_pinmux_t
dt_pinmux_from_instance_id
(
dt_instance_id_t
inst_id) {
61
if
(inst_id >=
kDtInstanceIdPinmuxAon
&& inst_id <=
kDtInstanceIdPinmuxAon
) {
62
return
(
dt_pinmux_t
)(inst_id -
kDtInstanceIdPinmuxAon
);
63
}
64
return
(
dt_pinmux_t
)0;
65
}
66
67
dt_instance_id_t
dt_pinmux_instance_id
(
68
dt_pinmux_t
dt) {
69
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
70
}
71
72
uint32_t
dt_pinmux_reg_block
(
73
dt_pinmux_t
dt,
74
dt_pinmux_reg_block_t
reg_block) {
75
// Return a recognizable address in case of wrong argument.
76
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
77
}
78
79
uint32_t
dt_pinmux_memory_base
(
80
dt_pinmux_t
dt,
81
dt_pinmux_memory_t
mem) {
82
// Return a recognizable address in case of wrong argument.
83
return
TRY_GET_DT
(dt, 0xdeadbeef)->mem_addr[mem];
84
}
85
86
uint32_t
dt_pinmux_memory_size
(
87
dt_pinmux_t
dt,
88
dt_pinmux_memory_t
mem) {
89
// Return an empty size in case of wrong argument.
90
return
TRY_GET_DT
(dt, 0)->mem_size[mem];
91
}
92
93
94
95
96
dt_clock_t
dt_pinmux_clock
(
97
dt_pinmux_t
dt,
98
dt_pinmux_clock_t
clk) {
99
// Return the first clock in case of invalid argument.
100
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
101
}
102
103
dt_reset_t
dt_pinmux_reset
(
104
dt_pinmux_t
dt,
105
dt_pinmux_reset_t
rst) {
106
const
dt_pinmux_reset_t
count = kDtPinmuxResetCount;
107
if
(rst >= count) {
108
return
kDtResetUnknown
;
109
}
110
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
111
}
112
113
(englishbreakfast)
hw
top
dt
dt_pinmux.c
Return to
OpenTitan Documentation