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 englishbreakfast.
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 dt_clock_t clock[kDtUsbdevClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtUsbdevResetCount]; /**< Reset signal connected to each reset port */
32 dt_periph_io_t periph_io[kDtUsbdevPeriphIoCount]; /**< Description of each peripheral I/O */
34
35
36
37
38static const dt_desc_usbdev_t usbdev_desc[kDtUsbdevCount] = {
39 [kDtUsbdev] = {
40 .inst_id = kDtInstanceIdUsbdev,
41 .reg_addr = {
42 [kDtUsbdevRegBlockCore] = 0x40320000,
43 },
44 .mem_addr = {
45 },
46 .mem_size = {
47 },
49 .clock = {
52 },
53 .reset = {
56 },
57 .periph_io = {
58 [kDtUsbdevPeriphIoSense] = {
59 .__internal = {
60 .type = kDtPeriphIoTypeMio,
61 .dir = kDtPeriphIoDirIn,
62 .periph_input_or_direct_pad = kTopEnglishbreakfastPinmuxPeripheralInUsbdevSense,
63 .outsel_or_dt_pad = 0,
64 },
65 },
66 [kDtUsbdevPeriphIoUsbDp] = {
67 .__internal = {
70 .periph_input_or_direct_pad = 0,
71 .outsel_or_dt_pad = 0,
72 },
73 },
74 [kDtUsbdevPeriphIoUsbDn] = {
75 .__internal = {
78 .periph_input_or_direct_pad = 0,
79 .outsel_or_dt_pad = 0,
80 },
81 },
82 },
83 },
84};
85
86/**
87 * Return a pointer to the `dt_usbdev_desc_t` structure of the requested
88 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
89 * the function) with the provided default value.
90 */
91#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_usbdev_t)0 || (dt) >= kDtUsbdevCount) return (default); &usbdev_desc[dt]; })
92
94 if (inst_id >= kDtInstanceIdUsbdev && inst_id <= kDtInstanceIdUsbdev) {
95 return (dt_usbdev_t)(inst_id - kDtInstanceIdUsbdev);
96 }
97 return (dt_usbdev_t)0;
98}
99
104
106 dt_usbdev_t dt,
107 dt_usbdev_reg_block_t reg_block) {
108 // Return a recognizable address in case of wrong argument.
109 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
110}
111
113 dt_usbdev_t dt,
114 dt_usbdev_memory_t mem) {
115 // Return a recognizable address in case of wrong argument.
116 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
117}
118
120 dt_usbdev_t dt,
121 dt_usbdev_memory_t mem) {
122 // Return an empty size in case of wrong argument.
123 return TRY_GET_DT(dt, 0)->mem_size[mem];
124}
125
127 dt_usbdev_t dt,
128 dt_usbdev_irq_t irq) {
129 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
130 if (first_irq == kDtPlicIrqIdNone) {
131 return kDtPlicIrqIdNone;
132 }
133 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
134}
135
137 dt_usbdev_t dt,
138 dt_plic_irq_id_t irq) {
139 dt_usbdev_irq_t count = kDtUsbdevIrqCount;
140 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
141 if (first_irq == kDtPlicIrqIdNone) {
142 return count;
143 }
144 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
145 return count;
146 }
147 return (dt_usbdev_irq_t)(irq - first_irq);
148}
149
150
151
153 dt_usbdev_t dt,
155 // Return a harmless value in case of wrong argument.
156 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
157}
158
160 dt_usbdev_t dt,
161 dt_usbdev_clock_t clk) {
162 // Return the first clock in case of invalid argument.
163 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
164}
165
167 dt_usbdev_t dt,
168 dt_usbdev_reset_t rst) {
169 const dt_usbdev_reset_t count = kDtUsbdevResetCount;
170 if (rst >= count) {
171 return kDtResetUnknown;
172 }
173 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
174}
175
176