Software APIs
dt_usbdev.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 usbdev and top earlgrey.
10 */
11
12#include "hw/top/dt/dt_usbdev.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_usbdev {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtUsbdevRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtUsbdevMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtUsbdevMemoryCount]; /**< Size in bytes of each memory */
24 /**
25 * PLIC ID of the first IRQ of this instance
26 *
27 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
28 */
30 /**
31 * Alert ID of the first Alert of this instance.
32 *
33 * This value is undefined if the block is not connected to the Alert Handler.
34 */
36 dt_clock_t clock[kDtUsbdevClockCount]; /**< Clock signal connected to each clock port */
37 dt_reset_t reset[kDtUsbdevResetCount]; /**< Reset signal connected to each reset port */
38 dt_periph_io_t periph_io[kDtUsbdevPeriphIoCount]; /**< Description of each peripheral I/O */
40
41
42
43
44static const dt_desc_usbdev_t usbdev_desc[kDtUsbdevCount] = {
45 [kDtUsbdev] = {
46 .inst_id = kDtInstanceIdUsbdev,
47 .reg_addr = {
48 [kDtUsbdevRegBlockCore] = 0x40320000,
49 },
50 .mem_addr = {
51 },
52 .mem_size = {
53 },
56 .clock = {
59 },
60 .reset = {
63 },
64 .periph_io = {
65 [kDtUsbdevPeriphIoSense] = {
66 .__internal = {
67 .type = kDtPeriphIoTypeMio,
68 .dir = kDtPeriphIoDirIn,
69 .periph_input_or_direct_pad = kTopEarlgreyPinmuxPeripheralInUsbdevSense,
70 .outsel_or_dt_pad = 0,
71 },
72 },
73 [kDtUsbdevPeriphIoUsbDp] = {
74 .__internal = {
77 .periph_input_or_direct_pad = 0,
78 .outsel_or_dt_pad = 0,
79 },
80 },
81 [kDtUsbdevPeriphIoUsbDn] = {
82 .__internal = {
85 .periph_input_or_direct_pad = 0,
86 .outsel_or_dt_pad = 0,
87 },
88 },
89 },
90 },
91};
92
93/**
94 * Return a pointer to the `dt_usbdev_desc_t` structure of the requested
95 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
96 * the function) with the provided default value.
97 */
98#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_usbdev_t)0 || (dt) >= kDtUsbdevCount) return (default); &usbdev_desc[dt]; })
99
101 if (inst_id >= kDtInstanceIdUsbdev && inst_id <= kDtInstanceIdUsbdev) {
102 return (dt_usbdev_t)(inst_id - kDtInstanceIdUsbdev);
103 }
104 return (dt_usbdev_t)0;
105}
106
111
113 dt_usbdev_t dt,
114 dt_usbdev_reg_block_t reg_block) {
115 // Return a recognizable address in case of wrong argument.
116 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
117}
118
120 dt_usbdev_t dt,
121 dt_usbdev_memory_t mem) {
122 // Return a recognizable address in case of wrong argument.
123 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
124}
125
127 dt_usbdev_t dt,
128 dt_usbdev_memory_t mem) {
129 // Return an empty size in case of wrong argument.
130 return TRY_GET_DT(dt, 0)->mem_size[mem];
131}
132
134 dt_usbdev_t dt,
135 dt_usbdev_irq_t irq) {
136 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
137 if (first_irq == kDtPlicIrqIdNone) {
138 return kDtPlicIrqIdNone;
139 }
140 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
141}
142
144 dt_usbdev_t dt,
145 dt_plic_irq_id_t irq) {
146 dt_usbdev_irq_t count = kDtUsbdevIrqCount;
147 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
148 if (first_irq == kDtPlicIrqIdNone) {
149 return count;
150 }
151 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
152 return count;
153 }
154 return (dt_usbdev_irq_t)(irq - first_irq);
155}
156
157
159 dt_usbdev_t dt,
160 dt_usbdev_alert_t alert) {
161 return (dt_alert_id_t)((uint32_t)usbdev_desc[dt].first_alert + (uint32_t)alert);
162}
163
165 dt_usbdev_t dt,
166 dt_alert_id_t alert) {
167 dt_usbdev_alert_t count = kDtUsbdevAlertCount;
168 if (alert < usbdev_desc[dt].first_alert || alert >= usbdev_desc[dt].first_alert + (dt_alert_id_t)count) {
169 return count;
170 }
171 return (dt_usbdev_alert_t)(alert - usbdev_desc[dt].first_alert);
172}
173
174
176 dt_usbdev_t dt,
178 // Return a harmless value in case of wrong argument.
179 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
180}
181
183 dt_usbdev_t dt,
184 dt_usbdev_clock_t clk) {
185 // Return the first clock in case of invalid argument.
186 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
187}
188
190 dt_usbdev_t dt,
191 dt_usbdev_reset_t rst) {
192 const dt_usbdev_reset_t count = kDtUsbdevResetCount;
193 if (rst >= count) {
194 return kDtResetUnknown;
195 }
196 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
197}
198
199