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 */
19typedef 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 */
27
28
29
30
31static 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 = {
44 },
45 .reset = {
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
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
71
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
80 dt_pinmux_t dt,
82 // Return a recognizable address in case of wrong argument.
83 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
84}
85
87 dt_pinmux_t dt,
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
97 dt_pinmux_t dt,
99 // Return the first clock in case of invalid argument.
100 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
101}
102
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